1 SPDX-License-Identifier: GPL-2.0
2 aufs4.x-rcN kbuild patch
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index ac474a6..284cee9 100644
8 @@ -255,6 +255,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 293733f..12d19d0 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
26 aufs4.x-rcN base patch
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index 8119141..5e84420 100644
32 @@ -2590,6 +2590,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>
52 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
53 index cb0cc86..470dd02 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -738,6 +738,24 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
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 2593153..6369b30 100644
85 @@ -1224,7 +1224,7 @@ enum d_walk_ret {
87 * The @enter() 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 *))
93 struct dentry *this_parent;
94 diff --git a/fs/fcntl.c b/fs/fcntl.c
95 index 0831851..78234ee 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 35d2108..d2395eb 100644
120 @@ -1660,7 +1660,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 timespec64 *time, int flags)
125 +int update_time(struct inode *inode, struct timespec64 *time, int flags)
127 int (*update_time)(struct inode *, struct timespec64 *, int);
129 diff --git a/fs/namespace.c b/fs/namespace.c
130 index a7f9126..46ed643 100644
133 @@ -770,6 +770,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 58f3053..a2a55ea 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 de2ede0..5dcf77b 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/fs.h b/include/linux/fs.h
221 index c95c080..0e44705 100644
222 --- a/include/linux/fs.h
223 +++ b/include/linux/fs.h
224 @@ -1305,6 +1305,7 @@ extern void fasync_free(struct fasync_struct *);
225 /* can be called from interrupts */
226 extern void kill_fasync(struct fasync_struct **, int, int);
228 +extern int setfl(int fd, struct file * filp, unsigned long arg);
229 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
230 extern int f_setown(struct file *filp, unsigned long arg, int force);
231 extern void f_delown(struct file *filp);
232 @@ -1797,6 +1798,7 @@ struct file_operations {
233 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
234 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
235 int (*check_flags)(int);
236 + int (*setfl)(struct file *, unsigned long);
237 int (*flock) (struct file *, int, struct file_lock *);
238 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
239 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
240 @@ -1867,6 +1869,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
241 struct iovec *fast_pointer,
242 struct iovec **ret_pointer);
244 +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *);
245 +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t,
247 +vfs_readf_t vfs_readf(struct file *file);
248 +vfs_writef_t vfs_writef(struct file *file);
250 extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
251 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
252 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
253 @@ -2292,6 +2300,7 @@ extern int current_umask(void);
254 extern void ihold(struct inode * inode);
255 extern void iput(struct inode *);
256 extern int generic_update_time(struct inode *, struct timespec64 *, int);
257 +extern int update_time(struct inode *, struct timespec64 *, int);
260 extern struct kobject *fs_kobj;
261 @@ -2579,6 +2588,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
265 +extern int __sync_filesystem(struct super_block *, int);
266 extern int sync_filesystem(struct super_block *);
267 extern const struct file_operations def_blk_fops;
268 extern const struct file_operations def_chr_fops;
269 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
270 index 1fd82ff..a5ccac5 100644
271 --- a/include/linux/lockdep.h
272 +++ b/include/linux/lockdep.h
273 @@ -308,6 +308,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
274 return lock->key == key;
277 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
282 @@ -434,6 +436,7 @@ struct lockdep_map { };
284 #define lockdep_depth(tsk) (0)
286 +#define lockdep_is_held(lock) (1)
287 #define lockdep_is_held_type(l, r) (1)
289 #define lockdep_assert_held(l) do { (void)(l); } while (0)
290 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
291 index 3594208..24f5fd1 100644
292 --- a/include/linux/mnt_namespace.h
293 +++ b/include/linux/mnt_namespace.h
295 struct mnt_namespace;
297 struct user_namespace;
300 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
301 struct user_namespace *, struct fs_struct *);
302 extern void put_mnt_ns(struct mnt_namespace *ns);
304 +extern int is_current_mnt_ns(struct vfsmount *mnt);
306 extern const struct file_operations proc_mounts_operations;
307 extern const struct file_operations proc_mountinfo_operations;
308 extern const struct file_operations proc_mountstats_operations;
309 diff --git a/include/linux/splice.h b/include/linux/splice.h
310 index 74b4911..19789fb 100644
311 --- a/include/linux/splice.h
312 +++ b/include/linux/splice.h
313 @@ -87,4 +87,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
315 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
316 extern const struct pipe_buf_operations default_pipe_buf_ops;
318 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
319 + loff_t *ppos, size_t len, unsigned int flags);
320 +extern long do_splice_to(struct file *in, loff_t *ppos,
321 + struct pipe_inode_info *pipe, size_t len,
322 + unsigned int flags);
324 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
325 index 1efada2..447bc0b 100644
326 --- a/kernel/locking/lockdep.c
327 +++ b/kernel/locking/lockdep.c
328 @@ -140,7 +140,7 @@ static struct lock_list list_entries[MAX_LOCKDEP_ENTRIES];
329 unsigned long nr_lock_classes;
330 struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
332 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
333 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
335 if (!hlock->class_idx) {
337 @@ -151,6 +151,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
339 return lock_classes + hlock->class_idx - 1;
341 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
343 #ifdef CONFIG_LOCK_STAT
344 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
345 SPDX-License-Identifier: GPL-2.0
346 aufs4.x-rcN mmap patch
348 diff --git a/fs/proc/base.c b/fs/proc/base.c
349 index ce34654..28508b1 100644
352 @@ -2016,7 +2016,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
353 down_read(&mm->mmap_sem);
354 vma = find_exact_vma(mm, vm_start, vm_end);
355 if (vma && vma->vm_file) {
356 - *path = vma->vm_file->f_path;
357 + *path = vma_pr_or_file(vma)->f_path;
361 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
362 index 3b63be6..fb9913b 100644
363 --- a/fs/proc/nommu.c
364 +++ b/fs/proc/nommu.c
365 @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
366 file = region->vm_file;
369 - struct inode *inode = file_inode(region->vm_file);
370 + struct inode *inode;
372 + file = vmr_pr_or_file(region);
373 + inode = file_inode(file);
374 dev = inode->i_sb->s_dev;
377 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
378 index 47c3764..e37e4b5 100644
379 --- a/fs/proc/task_mmu.c
380 +++ b/fs/proc/task_mmu.c
381 @@ -305,7 +305,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
382 const char *name = NULL;
385 - struct inode *inode = file_inode(vma->vm_file);
386 + struct inode *inode;
388 + file = vma_pr_or_file(vma);
389 + inode = file_inode(file);
390 dev = inode->i_sb->s_dev;
392 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
393 @@ -1729,7 +1732,7 @@ static int show_numa_map(struct seq_file *m, void *v)
394 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
395 struct vm_area_struct *vma = v;
396 struct numa_maps *md = &numa_priv->md;
397 - struct file *file = vma->vm_file;
398 + struct file *file = vma_pr_or_file(vma);
399 struct mm_struct *mm = vma->vm_mm;
400 struct mm_walk walk = {
401 .hugetlb_entry = gather_hugetlb_stats,
402 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
403 index 0b63d68..400d1c5 100644
404 --- a/fs/proc/task_nommu.c
405 +++ b/fs/proc/task_nommu.c
406 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
410 - struct inode *inode = file_inode(vma->vm_file);
411 + struct inode *inode;
413 + file = vma_pr_or_file(vma);
414 + inode = file_inode(file);
415 dev = inode->i_sb->s_dev;
417 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
418 diff --git a/include/linux/mm.h b/include/linux/mm.h
419 index 5411de9..b3cd025 100644
420 --- a/include/linux/mm.h
421 +++ b/include/linux/mm.h
422 @@ -1460,6 +1460,28 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
423 unmap_mapping_range(mapping, holebegin, holelen, 0);
426 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
427 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
429 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
430 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
432 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
434 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
436 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
437 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
440 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
441 +extern void vmr_do_fput(struct vm_region *, const char[], int);
443 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
445 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
446 +#endif /* !CONFIG_MMU */
448 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
449 void *buf, int len, unsigned int gup_flags);
450 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
451 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
452 index 5ed8f62..0122975 100644
453 --- a/include/linux/mm_types.h
454 +++ b/include/linux/mm_types.h
455 @@ -239,6 +239,7 @@ struct vm_region {
456 unsigned long vm_top; /* region allocated to here */
457 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
458 struct file *vm_file; /* the backing file or NULL */
459 + struct file *vm_prfile; /* the virtual backing file or NULL */
461 int vm_usage; /* region usage count (access under nommu_region_sem) */
462 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
463 @@ -313,6 +314,7 @@ struct vm_area_struct {
464 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
466 struct file * vm_file; /* File we map to (can be NULL). */
467 + struct file *vm_prfile; /* shadow of vm_file */
468 void * vm_private_data; /* was vm_pte (shared mem) */
470 atomic_long_t swap_readahead_info;
471 diff --git a/kernel/fork.c b/kernel/fork.c
472 index 07cddff..d837e55 100644
475 @@ -546,7 +546,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
476 struct inode *inode = file_inode(file);
477 struct address_space *mapping = file->f_mapping;
481 if (tmp->vm_flags & VM_DENYWRITE)
482 atomic_dec(&inode->i_writecount);
483 i_mmap_lock_write(mapping);
484 diff --git a/mm/Makefile b/mm/Makefile
485 index d210cc9..e77e80c 100644
488 @@ -39,7 +39,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \
489 mm_init.o mmu_context.o percpu.o slab_common.o \
490 compaction.o vmacache.o \
491 interval_tree.o list_lru.o workingset.o \
493 + prfile.o debug.o $(mmu-y)
497 diff --git a/mm/filemap.c b/mm/filemap.c
498 index 81adec8..8507cec 100644
501 @@ -2609,7 +2609,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
502 vm_fault_t ret = VM_FAULT_LOCKED;
504 sb_start_pagefault(inode->i_sb);
505 - file_update_time(vmf->vma->vm_file);
506 + vma_file_update_time(vmf->vma);
508 if (page->mapping != inode->i_mapping) {
510 diff --git a/mm/mmap.c b/mm/mmap.c
511 index 6c04292..f3629c1 100644
514 @@ -180,7 +180,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
515 if (vma->vm_ops && vma->vm_ops->close)
516 vma->vm_ops->close(vma);
518 - fput(vma->vm_file);
520 mpol_put(vma_policy(vma));
523 @@ -929,7 +929,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
526 uprobe_munmap(next, next->vm_start, next->vm_end);
531 anon_vma_merge(vma, next);
532 @@ -1845,8 +1845,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
540 /* Undo any partial mapping done by a device driver. */
541 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
542 @@ -2665,7 +2665,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
546 - get_file(new->vm_file);
549 if (new->vm_ops && new->vm_ops->open)
550 new->vm_ops->open(new);
551 @@ -2684,7 +2684,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
552 if (new->vm_ops && new->vm_ops->close)
553 new->vm_ops->close(new);
555 - fput(new->vm_file);
557 unlink_anon_vmas(new);
559 mpol_put(vma_policy(new));
560 @@ -2874,7 +2874,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
561 struct vm_area_struct *vma;
562 unsigned long populate = 0;
563 unsigned long ret = -EINVAL;
565 + struct file *file, *prfile;
567 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n",
568 current->comm, current->pid);
569 @@ -2949,10 +2949,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
573 - file = get_file(vma->vm_file);
575 + file = vma->vm_file;
576 + prfile = vma->vm_prfile;
577 ret = do_mmap_pgoff(vma->vm_file, start, size,
578 prot, flags, pgoff, &populate, NULL);
579 + if (!IS_ERR_VALUE(ret) && file && prfile) {
580 + struct vm_area_struct *new_vma;
582 + new_vma = find_vma(mm, ret);
583 + if (!new_vma->vm_prfile)
584 + new_vma->vm_prfile = prfile;
585 + if (new_vma != vma)
589 + * two fput()s instead of vma_fput(vma),
590 + * coz vma may not be available anymore.
596 up_write(&mm->mmap_sem);
598 @@ -3258,7 +3275,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
599 if (anon_vma_clone(new_vma, vma))
600 goto out_free_mempol;
601 if (new_vma->vm_file)
602 - get_file(new_vma->vm_file);
603 + vma_get_file(new_vma);
604 if (new_vma->vm_ops && new_vma->vm_ops->open)
605 new_vma->vm_ops->open(new_vma);
606 vma_link(mm, new_vma, prev, rb_link, rb_parent);
607 diff --git a/mm/nommu.c b/mm/nommu.c
608 index 749276b..d56f8f2 100644
611 @@ -625,7 +625,7 @@ static void __put_nommu_region(struct vm_region *region)
612 up_write(&nommu_region_sem);
615 - fput(region->vm_file);
618 /* IO memory and memory shared directly out of the pagecache
619 * from ramfs/tmpfs mustn't be released here */
620 @@ -763,7 +763,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
621 if (vma->vm_ops && vma->vm_ops->close)
622 vma->vm_ops->close(vma);
624 - fput(vma->vm_file);
626 put_nommu_region(vma->vm_region);
629 @@ -1286,7 +1286,7 @@ unsigned long do_mmap(struct file *file,
630 goto error_just_free;
633 - fput(region->vm_file);
635 kmem_cache_free(vm_region_jar, region);
638 @@ -1361,7 +1361,7 @@ unsigned long do_mmap(struct file *file,
639 up_write(&nommu_region_sem);
642 - fput(region->vm_file);
644 kmem_cache_free(vm_region_jar, region);
647 diff --git a/mm/prfile.c b/mm/prfile.c
649 index 0000000..a27ac36
653 +// SPDX-License-Identifier: GPL-2.0
655 + * Mainly for aufs which mmap(2) different file and wants to print different
656 + * path in /proc/PID/maps.
657 + * Call these functions via macros defined in linux/mm.h.
659 + * See Documentation/filesystems/aufs/design/06mmap.txt
661 + * Copyright (c) 2014-2018 Junjro R. Okajima
662 + * Copyright (c) 2014 Ian Campbell
665 +#include <linux/mm.h>
666 +#include <linux/file.h>
667 +#include <linux/fs.h>
669 +/* #define PRFILE_TRACE */
670 +static inline void prfile_trace(struct file *f, struct file *pr,
671 + const char func[], int line, const char func2[])
675 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
679 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
682 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
684 + prfile_trace(f, pr, func, line, __func__);
685 + file_update_time(f);
687 + file_update_time(pr);
690 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
693 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
695 + prfile_trace(f, pr, func, line, __func__);
696 + return (f && pr) ? pr : f;
699 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
701 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
703 + prfile_trace(f, pr, func, line, __func__);
709 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
711 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
713 + prfile_trace(f, pr, func, line, __func__);
720 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
723 + struct file *f = region->vm_file, *pr = region->vm_prfile;
725 + prfile_trace(f, pr, func, line, __func__);
726 + return (f && pr) ? pr : f;
729 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
731 + struct file *f = region->vm_file, *pr = region->vm_prfile;
733 + prfile_trace(f, pr, func, line, __func__);
738 +#endif /* !CONFIG_MMU */
739 SPDX-License-Identifier: GPL-2.0
740 aufs4.x-rcN standalone patch
742 diff --git a/fs/dcache.c b/fs/dcache.c
743 index 6369b30..df4a5fe 100644
746 @@ -1329,6 +1329,7 @@ void d_walk(struct dentry *parent, void *data,
750 +EXPORT_SYMBOL_GPL(d_walk);
753 struct vfsmount *mnt;
754 @@ -2817,6 +2818,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
756 write_sequnlock(&rename_lock);
758 +EXPORT_SYMBOL_GPL(d_exchange);
761 * d_ancestor - search for an ancestor
762 diff --git a/fs/exec.c b/fs/exec.c
763 index fc281b7..65eaaca 100644
766 @@ -109,6 +109,7 @@ bool path_noexec(const struct path *path)
767 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
768 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
770 +EXPORT_SYMBOL_GPL(path_noexec);
774 diff --git a/fs/fcntl.c b/fs/fcntl.c
775 index 78234ee..2072f69 100644
778 @@ -85,6 +85,7 @@ int setfl(int fd, struct file * filp, unsigned long arg)
782 +EXPORT_SYMBOL_GPL(setfl);
784 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
786 diff --git a/fs/file_table.c b/fs/file_table.c
787 index e49af4c..569020f 100644
788 --- a/fs/file_table.c
789 +++ b/fs/file_table.c
790 @@ -161,6 +161,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
792 return ERR_PTR(-ENFILE);
794 +EXPORT_SYMBOL_GPL(alloc_empty_file);
797 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
798 @@ -323,6 +324,7 @@ void flush_delayed_fput(void)
802 +EXPORT_SYMBOL_GPL(flush_delayed_fput);
804 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
806 @@ -365,6 +367,7 @@ void __fput_sync(struct file *file)
810 +EXPORT_SYMBOL_GPL(__fput_sync);
812 void __init files_init(void)
814 diff --git a/fs/inode.c b/fs/inode.c
815 index d2395eb..b8be7be 100644
818 @@ -1669,6 +1669,7 @@ int update_time(struct inode *inode, struct timespec64 *time, int flags)
820 return update_time(inode, time, flags);
822 +EXPORT_SYMBOL_GPL(update_time);
825 * touch_atime - update the access time
826 diff --git a/fs/namespace.c b/fs/namespace.c
827 index 46ed643..44502c2 100644
830 @@ -437,6 +437,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
831 mnt_dec_writers(real_mount(mnt));
834 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
837 * mnt_drop_write - give up write access to a mount
838 @@ -775,6 +776,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
840 return check_mnt(real_mount(mnt));
842 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
845 * vfsmount lock must be held for write
846 @@ -1844,6 +1846,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
850 +EXPORT_SYMBOL_GPL(iterate_mounts);
852 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
854 diff --git a/fs/notify/group.c b/fs/notify/group.c
855 index c03b836..817f22c 100644
856 --- a/fs/notify/group.c
857 +++ b/fs/notify/group.c
859 #include <linux/rculist.h>
860 #include <linux/wait.h>
861 #include <linux/memcontrol.h>
862 +#include <linux/module.h>
864 #include <linux/fsnotify_backend.h>
865 #include "fsnotify.h"
866 @@ -112,6 +113,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
868 refcount_inc(&group->refcnt);
870 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
873 * Drop a reference to a group. Free it if it's through.
874 @@ -121,6 +123,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
875 if (refcount_dec_and_test(&group->refcnt))
876 fsnotify_final_destroy_group(group);
878 +EXPORT_SYMBOL_GPL(fsnotify_put_group);
881 * Create a new fsnotify_group and hold a reference for the group returned.
882 @@ -150,6 +153,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
886 +EXPORT_SYMBOL_GPL(fsnotify_alloc_group);
888 int fsnotify_fasync(int fd, struct file *file, int on)
890 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
891 index d2dd16c..cf709b7 100644
892 --- a/fs/notify/mark.c
893 +++ b/fs/notify/mark.c
894 @@ -289,6 +289,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
895 queue_delayed_work(system_unbound_wq, &reaper_work,
896 FSNOTIFY_REAPER_DELAY);
898 +EXPORT_SYMBOL_GPL(fsnotify_put_mark);
901 * Get mark reference when we found the mark via lockless traversal of object
902 @@ -443,6 +444,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
903 mutex_unlock(&group->mark_mutex);
904 fsnotify_free_mark(mark);
906 +EXPORT_SYMBOL_GPL(fsnotify_destroy_mark);
909 * Sorting function for lists of fsnotify marks.
910 @@ -658,6 +660,7 @@ int fsnotify_add_mark(struct fsnotify_mark *mark, fsnotify_connp_t *connp,
911 mutex_unlock(&group->mark_mutex);
914 +EXPORT_SYMBOL_GPL(fsnotify_add_mark);
917 * Given a list of marks, find the mark associated with given group. If found
918 @@ -781,6 +784,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
919 fsnotify_get_group(group);
922 +EXPORT_SYMBOL_GPL(fsnotify_init_mark);
925 * Destroy all marks in destroy_list, waits for SRCU period to finish before
926 diff --git a/fs/open.c b/fs/open.c
927 index 0285ce7..cb81623 100644
930 @@ -64,6 +64,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
931 inode_unlock(dentry->d_inode);
934 +EXPORT_SYMBOL_GPL(do_truncate);
936 long vfs_truncate(const struct path *path, loff_t length)
938 diff --git a/fs/read_write.c b/fs/read_write.c
939 index a2a55ea..a1366ed 100644
940 --- a/fs/read_write.c
941 +++ b/fs/read_write.c
942 @@ -459,6 +459,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
946 +EXPORT_SYMBOL_GPL(vfs_read);
948 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
950 @@ -499,6 +500,7 @@ vfs_readf_t vfs_readf(struct file *file)
951 return new_sync_read;
952 return ERR_PTR(-ENOSYS);
954 +EXPORT_SYMBOL_GPL(vfs_readf);
956 vfs_writef_t vfs_writef(struct file *file)
958 @@ -510,6 +512,7 @@ vfs_writef_t vfs_writef(struct file *file)
959 return new_sync_write;
960 return ERR_PTR(-ENOSYS);
962 +EXPORT_SYMBOL_GPL(vfs_writef);
964 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
966 @@ -579,6 +582,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
970 +EXPORT_SYMBOL_GPL(vfs_write);
972 static inline loff_t file_pos_read(struct file *file)
974 diff --git a/fs/splice.c b/fs/splice.c
975 index 5dcf77b..63fe265 100644
978 @@ -850,6 +850,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
980 return splice_write(pipe, out, ppos, len, flags);
982 +EXPORT_SYMBOL_GPL(do_splice_from);
985 * Attempt to initiate a splice from a file to a pipe.
986 @@ -879,6 +880,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
988 return splice_read(in, ppos, pipe, len, flags);
990 +EXPORT_SYMBOL_GPL(do_splice_to);
993 * splice_direct_to_actor - splices data directly between two non-pipes
994 diff --git a/fs/sync.c b/fs/sync.c
995 index 2860782..ffd7ea4 100644
998 @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
999 sb->s_op->sync_fs(sb, wait);
1000 return __sync_blockdev(sb->s_bdev, wait);
1002 +EXPORT_SYMBOL_GPL(__sync_filesystem);
1005 * Write out and wait upon all dirty data associated with this
1006 diff --git a/fs/xattr.c b/fs/xattr.c
1007 index 0d6a6a4..7ce4701 100644
1010 @@ -295,6 +295,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
1011 *xattr_value = value;
1014 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
1017 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
1018 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
1019 index 447bc0b..4e7581c 100644
1020 --- a/kernel/locking/lockdep.c
1021 +++ b/kernel/locking/lockdep.c
1022 @@ -151,6 +151,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
1024 return lock_classes + hlock->class_idx - 1;
1026 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
1027 #define hlock_class(hlock) lockdep_hlock_class(hlock)
1029 #ifdef CONFIG_LOCK_STAT
1030 diff --git a/kernel/task_work.c b/kernel/task_work.c
1031 index 0fef395..83fb1ec 100644
1032 --- a/kernel/task_work.c
1033 +++ b/kernel/task_work.c
1034 @@ -116,3 +116,4 @@ void task_work_run(void)
1038 +EXPORT_SYMBOL_GPL(task_work_run);
1039 diff --git a/security/commoncap.c b/security/commoncap.c
1040 index 18a4fdf..e49f723 100644
1041 --- a/security/commoncap.c
1042 +++ b/security/commoncap.c
1043 @@ -1333,12 +1333,14 @@ int cap_mmap_addr(unsigned long addr)
1047 +EXPORT_SYMBOL_GPL(cap_mmap_addr);
1049 int cap_mmap_file(struct file *file, unsigned long reqprot,
1050 unsigned long prot, unsigned long flags)
1054 +EXPORT_SYMBOL_GPL(cap_mmap_file);
1056 #ifdef CONFIG_SECURITY
1058 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
1059 index cd97929..424fd23 100644
1060 --- a/security/device_cgroup.c
1061 +++ b/security/device_cgroup.c
1063 #include <linux/device_cgroup.h>
1064 #include <linux/cgroup.h>
1065 #include <linux/ctype.h>
1066 +#include <linux/export.h>
1067 #include <linux/list.h>
1068 #include <linux/uaccess.h>
1069 #include <linux/seq_file.h>
1070 @@ -824,3 +825,4 @@ int __devcgroup_check_permission(short type, u32 major, u32 minor,
1074 +EXPORT_SYMBOL_GPL(__devcgroup_check_permission);
1075 diff --git a/security/security.c b/security/security.c
1076 index 04d173e..470af62 100644
1077 --- a/security/security.c
1078 +++ b/security/security.c
1079 @@ -553,6 +553,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
1081 return call_int_hook(path_rmdir, 0, dir, dentry);
1083 +EXPORT_SYMBOL_GPL(security_path_rmdir);
1085 int security_path_unlink(const struct path *dir, struct dentry *dentry)
1087 @@ -569,6 +570,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
1089 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
1091 +EXPORT_SYMBOL_GPL(security_path_symlink);
1093 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1094 struct dentry *new_dentry)
1095 @@ -577,6 +579,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1097 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
1099 +EXPORT_SYMBOL_GPL(security_path_link);
1101 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1102 const struct path *new_dir, struct dentry *new_dentry,
1103 @@ -604,6 +607,7 @@ int security_path_truncate(const struct path *path)
1105 return call_int_hook(path_truncate, 0, path);
1107 +EXPORT_SYMBOL_GPL(security_path_truncate);
1109 int security_path_chmod(const struct path *path, umode_t mode)
1111 @@ -611,6 +615,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1113 return call_int_hook(path_chmod, 0, path, mode);
1115 +EXPORT_SYMBOL_GPL(security_path_chmod);
1117 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1119 @@ -618,6 +623,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1121 return call_int_hook(path_chown, 0, path, uid, gid);
1123 +EXPORT_SYMBOL_GPL(security_path_chown);
1125 int security_path_chroot(const struct path *path)
1127 @@ -703,6 +709,7 @@ int security_inode_readlink(struct dentry *dentry)
1129 return call_int_hook(inode_readlink, 0, dentry);
1131 +EXPORT_SYMBOL_GPL(security_inode_readlink);
1133 int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
1135 @@ -718,6 +725,7 @@ int security_inode_permission(struct inode *inode, int mask)
1137 return call_int_hook(inode_permission, 0, inode, mask);
1139 +EXPORT_SYMBOL_GPL(security_inode_permission);
1141 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1143 @@ -889,6 +897,7 @@ int security_file_permission(struct file *file, int mask)
1145 return fsnotify_perm(file, mask);
1147 +EXPORT_SYMBOL_GPL(security_file_permission);
1149 int security_file_alloc(struct file *file)
1151 @@ -948,6 +957,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
1153 return ima_file_mmap(file, prot);
1155 +EXPORT_SYMBOL_GPL(security_mmap_file);
1157 int security_mmap_addr(unsigned long addr)
1159 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1160 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1161 +++ linux/Documentation/ABI/testing/debugfs-aufs 2018-08-12 23:43:05.450124426 +0200
1163 +What: /debug/aufs/si_<id>/
1165 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1167 + Under /debug/aufs, a directory named si_<id> is created
1168 + per aufs mount, where <id> is a unique id generated
1171 +What: /debug/aufs/si_<id>/plink
1173 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1175 + It has three lines and shows the information about the
1176 + pseudo-link. The first line is a single number
1177 + representing a number of buckets. The second line is a
1178 + number of pseudo-links per buckets (separated by a
1179 + blank). The last line is a single number representing a
1180 + total number of psedo-links.
1181 + When the aufs mount option 'noplink' is specified, it
1182 + will show "1\n0\n0\n".
1184 +What: /debug/aufs/si_<id>/xib
1186 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1188 + It shows the consumed blocks by xib (External Inode Number
1189 + Bitmap), its block size and file size.
1190 + When the aufs mount option 'noxino' is specified, it
1191 + will be empty. About XINO files, see the aufs manual.
1193 +What: /debug/aufs/si_<id>/xi0, xi1 ... xiN and xiN-N
1195 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1197 + It shows the consumed blocks by xino (External Inode Number
1198 + Translation Table), its link count, block size and file
1200 + Due to the file size limit, there may exist multiple
1201 + xino files per branch. In this case, "-N" is added to
1202 + the filename and it corresponds to the index of the
1203 + internal xino array. "-0" is omitted.
1204 + When the aufs mount option 'noxino' is specified, Those
1205 + entries won't exist. About XINO files, see the aufs
1208 +What: /debug/aufs/si_<id>/xigen
1210 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1212 + It shows the consumed blocks by xigen (External Inode
1213 + Generation Table), its block size and file size.
1214 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1216 + When the aufs mount option 'noxino' is specified, it
1217 + will be empty. About XINO files, see the aufs manual.
1218 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1219 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1220 +++ linux/Documentation/ABI/testing/sysfs-aufs 2017-07-29 12:14:25.893041746 +0200
1222 +What: /sys/fs/aufs/si_<id>/
1224 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1226 + Under /sys/fs/aufs, a directory named si_<id> is created
1227 + per aufs mount, where <id> is a unique id generated
1230 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1232 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1234 + It shows the abolute path of a member directory (which
1235 + is called branch) in aufs, and its permission.
1237 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1239 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1241 + It shows the id of a member directory (which is called
1244 +What: /sys/fs/aufs/si_<id>/xi_path
1246 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1248 + It shows the abolute path of XINO (External Inode Number
1249 + Bitmap, Translation Table and Generation Table) file
1250 + even if it is the default path.
1251 + When the aufs mount option 'noxino' is specified, it
1252 + will be empty. About XINO files, see the aufs manual.
1253 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1254 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1255 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2018-04-15 08:49:13.394483860 +0200
1258 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1260 +# This program is free software; you can redistribute it and/or modify
1261 +# it under the terms of the GNU General Public License as published by
1262 +# the Free Software Foundation; either version 2 of the License, or
1263 +# (at your option) any later version.
1265 +# This program is distributed in the hope that it will be useful,
1266 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1267 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1268 +# GNU General Public License for more details.
1270 +# You should have received a copy of the GNU General Public License
1271 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1274 +----------------------------------------
1276 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1277 +1. abbrev. for "advanced multi-layered unification filesystem".
1278 +2. abbrev. for "another unionfs".
1279 +3. abbrev. for "auf das" in German which means "on the" in English.
1280 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1281 + But "Filesystem aufs Filesystem" is hard to understand.
1282 +4. abbrev. for "African Urban Fashion Show".
1284 +AUFS is a filesystem with features:
1285 +- multi layered stackable unification filesystem, the member directory
1286 + is called as a branch.
1287 +- branch permission and attribute, 'readonly', 'real-readonly',
1288 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1290 +- internal "file copy-on-write".
1291 +- logical deletion, whiteout.
1292 +- dynamic branch manipulation, adding, deleting and changing permission.
1293 +- allow bypassing aufs, user's direct branch access.
1294 +- external inode number translation table and bitmap which maintains the
1295 + persistent aufs inode number.
1296 +- seekable directory, including NFS readdir.
1297 +- file mapping, mmap and sharing pages.
1298 +- pseudo-link, hardlink over branches.
1299 +- loopback mounted filesystem as a branch.
1300 +- several policies to select one among multiple writable branches.
1301 +- revert a single systemcall when an error occurs in aufs.
1305 +Multi Layered Stackable Unification Filesystem
1306 +----------------------------------------------------------------------
1307 +Most people already knows what it is.
1308 +It is a filesystem which unifies several directories and provides a
1309 +merged single directory. When users access a file, the access will be
1310 +passed/re-directed/converted (sorry, I am not sure which English word is
1311 +correct) to the real file on the member filesystem. The member
1312 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1313 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1314 +readonly branch is handled by creating 'whiteout' on the upper writable
1317 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1318 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1319 +different approaches to implement the merged-view.
1320 +The former tries putting it into VFS, and the latter implements as a
1321 +separate filesystem.
1322 +(If I misunderstand about these implementations, please let me know and
1323 +I shall correct it. Because it is a long time ago when I read their
1324 +source files last time).
1326 +UnionMount's approach will be able to small, but may be hard to share
1327 +branches between several UnionMount since the whiteout in it is
1328 +implemented in the inode on branch filesystem and always
1329 +shared. According to Bharata's post, readdir does not seems to be
1331 +There are several missing features known in this implementations such as
1332 +- for users, the inode number may change silently. eg. copy-up.
1333 +- link(2) may break by copy-up.
1334 +- read(2) may get an obsoleted filedata (fstat(2) too).
1335 +- fcntl(F_SETLK) may be broken by copy-up.
1336 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1339 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1340 +merged into mainline. This is another implementation of UnionMount as a
1341 +separated filesystem. All the limitations and known problems which
1342 +UnionMount are equally inherited to "overlay" filesystem.
1344 +Unionfs has a longer history. When I started implementing a stackable
1345 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1346 +inode, dentry and file objects and they have an array pointing lower
1347 +same kind objects. After contributing many patches for Unionfs, I
1348 +re-started my project AUFS (Jun 2006).
1350 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1351 +implemented my own ideas, approaches and enhancements and it became
1352 +totally different one.
1354 +Comparing DM snapshot and fs based implementation
1355 +- the number of bytes to be copied between devices is much smaller.
1356 +- the type of filesystem must be one and only.
1357 +- the fs must be writable, no readonly fs, even for the lower original
1358 + device. so the compression fs will not be usable. but if we use
1359 + loopback mount, we may address this issue.
1361 + mount /cdrom/squashfs.img /sq
1362 + losetup /sq/ext2.img
1363 + losetup /somewhere/cow
1364 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1365 +- it will be difficult (or needs more operations) to extract the
1366 + difference between the original device and COW.
1367 +- DM snapshot-merge may help a lot when users try merging. in the
1368 + fs-layer union, users will use rsync(1).
1370 +You may want to read my old paper "Filesystems in LiveCD"
1371 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1374 +Several characters/aspects/persona of aufs
1375 +----------------------------------------------------------------------
1377 +Aufs has several characters, aspects or persona.
1378 +1. a filesystem, callee of VFS helper
1379 +2. sub-VFS, caller of VFS helper for branches
1380 +3. a virtual filesystem which maintains persistent inode number
1381 +4. reader/writer of files on branches such like an application
1383 +1. Callee of VFS Helper
1384 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1385 +unlink(2) from an application reaches sys_unlink() kernel function and
1386 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1387 +calls filesystem specific unlink operation. Actually aufs implements the
1388 +unlink operation but it behaves like a redirector.
1390 +2. Caller of VFS Helper for Branches
1391 +aufs_unlink() passes the unlink request to the branch filesystem as if
1392 +it were called from VFS. So the called unlink operation of the branch
1393 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1394 +every necessary pre/post operation for the branch filesystem.
1395 +- acquire the lock for the parent dir on a branch
1396 +- lookup in a branch
1397 +- revalidate dentry on a branch
1398 +- mnt_want_write() for a branch
1399 +- vfs_unlink() for a branch
1400 +- mnt_drop_write() for a branch
1401 +- release the lock on a branch
1403 +3. Persistent Inode Number
1404 +One of the most important issue for a filesystem is to maintain inode
1405 +numbers. This is particularly important to support exporting a
1406 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1407 +backend block device for its own. But some storage is necessary to
1408 +keep and maintain the inode numbers. It may be a large space and may not
1409 +suit to keep in memory. Aufs rents some space from its first writable
1410 +branch filesystem (by default) and creates file(s) on it. These files
1411 +are created by aufs internally and removed soon (currently) keeping
1413 +Note: Because these files are removed, they are totally gone after
1414 + unmounting aufs. It means the inode numbers are not persistent
1415 + across unmount or reboot. I have a plan to make them really
1416 + persistent which will be important for aufs on NFS server.
1418 +4. Read/Write Files Internally (copy-on-write)
1419 +Because a branch can be readonly, when you write a file on it, aufs will
1420 +"copy-up" it to the upper writable branch internally. And then write the
1421 +originally requested thing to the file. Generally kernel doesn't
1422 +open/read/write file actively. In aufs, even a single write may cause a
1423 +internal "file copy". This behaviour is very similar to cp(1) command.
1425 +Some people may think it is better to pass such work to user space
1426 +helper, instead of doing in kernel space. Actually I am still thinking
1427 +about it. But currently I have implemented it in kernel space.
1428 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1429 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1430 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2018-04-15 08:49:13.394483860 +0200
1433 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1435 +# This program is free software; you can redistribute it and/or modify
1436 +# it under the terms of the GNU General Public License as published by
1437 +# the Free Software Foundation; either version 2 of the License, or
1438 +# (at your option) any later version.
1440 +# This program is distributed in the hope that it will be useful,
1441 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1442 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1443 +# GNU General Public License for more details.
1445 +# You should have received a copy of the GNU General Public License
1446 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1448 +Basic Aufs Internal Structure
1450 +Superblock/Inode/Dentry/File Objects
1451 +----------------------------------------------------------------------
1452 +As like an ordinary filesystem, aufs has its own
1453 +superblock/inode/dentry/file objects. All these objects have a
1454 +dynamically allocated array and store the same kind of pointers to the
1455 +lower filesystem, branch.
1456 +For example, when you build a union with one readwrite branch and one
1457 +readonly, mounted /au, /rw and /ro respectively.
1459 +- /ro/fileA exists but /rw/fileA
1461 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1462 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1463 +- [0] = NULL (because /rw/fileA doesn't exist)
1466 +This style of an array is essentially same to the aufs
1467 +superblock/inode/dentry/file objects.
1469 +Because aufs supports manipulating branches, ie. add/delete/change
1470 +branches dynamically, these objects has its own generation. When
1471 +branches are changed, the generation in aufs superblock is
1472 +incremented. And a generation in other object are compared when it is
1473 +accessed. When a generation in other objects are obsoleted, aufs
1474 +refreshes the internal array.
1478 +----------------------------------------------------------------------
1479 +Additionally aufs superblock has some data for policies to select one
1480 +among multiple writable branches, XIB files, pseudo-links and kobject.
1481 +See below in detail.
1482 +About the policies which supports copy-down a directory, see
1483 +wbr_policy.txt too.
1486 +Branch and XINO(External Inode Number Translation Table)
1487 +----------------------------------------------------------------------
1488 +Every branch has its own xino (external inode number translation table)
1489 +file. The xino file is created and unlinked by aufs internally. When two
1490 +members of a union exist on the same filesystem, they share the single
1492 +The struct of a xino file is simple, just a sequence of aufs inode
1493 +numbers which is indexed by the lower inode number.
1494 +In the above sample, assume the inode number of /ro/fileA is i111 and
1495 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1496 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1498 +When the inode numbers are not contiguous, the xino file will be sparse
1499 +which has a hole in it and doesn't consume as much disk space as it
1500 +might appear. If your branch filesystem consumes disk space for such
1501 +holes, then you should specify 'xino=' option at mounting aufs.
1503 +Aufs has a mount option to free the disk blocks for such holes in XINO
1504 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1505 +meet a problem of disk shortage due to XINO files, then you should try
1506 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1507 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1508 +the holes in XINO files.
1510 +Also a writable branch has three kinds of "whiteout bases". All these
1511 +are existed when the branch is joined to aufs, and their names are
1512 +whiteout-ed doubly, so that users will never see their names in aufs
1514 +1. a regular file which will be hardlinked to all whiteouts.
1515 +2. a directory to store a pseudo-link.
1516 +3. a directory to store an "orphan"-ed file temporary.
1519 + When you remove a file on a readonly branch, aufs handles it as a
1520 + logical deletion and creates a whiteout on the upper writable branch
1521 + as a hardlink of this file in order not to consume inode on the
1524 + See below, Pseudo-link.
1526 + When "fileC" exists on the lower readonly branch only and it is
1527 + opened and removed with its parent dir, and then user writes
1528 + something into it, then aufs copies-up fileC to this
1529 + directory. Because there is no other dir to store fileC. After
1530 + creating a file under this dir, the file is unlinked.
1532 +Because aufs supports manipulating branches, ie. add/delete/change
1533 +dynamically, a branch has its own id. When the branch order changes,
1534 +aufs finds the new index by searching the branch id.
1538 +----------------------------------------------------------------------
1539 +Assume "fileA" exists on the lower readonly branch only and it is
1540 +hardlinked to "fileB" on the branch. When you write something to fileA,
1541 +aufs copies-up it to the upper writable branch. Additionally aufs
1542 +creates a hardlink under the Pseudo-link Directory of the writable
1543 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1544 +simple list. If fileB is read after unlinking fileA, aufs returns
1545 +filedata from the pseudo-link instead of the lower readonly
1546 +branch. Because the pseudo-link is based upon the inode, to keep the
1547 +inode number by xino (see above) is essentially necessary.
1549 +All the hardlinks under the Pseudo-link Directory of the writable branch
1550 +should be restored in a proper location later. Aufs provides a utility
1551 +to do this. The userspace helpers executed at remounting and unmounting
1553 +During this utility is running, it puts aufs into the pseudo-link
1554 +maintenance mode. In this mode, only the process which began the
1555 +maintenance mode (and its child processes) is allowed to operate in
1556 +aufs. Some other processes which are not related to the pseudo-link will
1557 +be allowed to run too, but the rest have to return an error or wait
1558 +until the maintenance mode ends. If a process already acquires an inode
1559 +mutex (in VFS), it has to return an error.
1562 +XIB(external inode number bitmap)
1563 +----------------------------------------------------------------------
1564 +Addition to the xino file per a branch, aufs has an external inode number
1565 +bitmap in a superblock object. It is also an internal file such like a
1567 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1569 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1571 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1572 +reduce the number of consumed disk blocks for these files.
1575 +Virtual or Vertical Dir, and Readdir in Userspace
1576 +----------------------------------------------------------------------
1577 +In order to support multiple layers (branches), aufs readdir operation
1578 +constructs a virtual dir block on memory. For readdir, aufs calls
1579 +vfs_readdir() internally for each dir on branches, merges their entries
1580 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1581 +object. So the file object has its entry list until it is closed. The
1582 +entry list will be updated when the file position is zero and becomes
1583 +obsoleted. This decision is made in aufs automatically.
1585 +The dynamically allocated memory block for the name of entries has a
1586 +unit of 512 bytes (by default) and stores the names contiguously (no
1587 +padding). Another block for each entry is handled by kmem_cache too.
1588 +During building dir blocks, aufs creates hash list and judging whether
1589 +the entry is whiteouted by its upper branch or already listed.
1590 +The merged result is cached in the corresponding inode object and
1591 +maintained by a customizable life-time option.
1593 +Some people may call it can be a security hole or invite DoS attack
1594 +since the opened and once readdir-ed dir (file object) holds its entry
1595 +list and becomes a pressure for system memory. But I'd say it is similar
1596 +to files under /proc or /sys. The virtual files in them also holds a
1597 +memory page (generally) while they are opened. When an idea to reduce
1598 +memory for them is introduced, it will be applied to aufs too.
1599 +For those who really hate this situation, I've developed readdir(3)
1600 +library which operates this merging in userspace. You just need to set
1601 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1602 +kernel space for readdir(3).
1606 +----------------------------------------------------------------------
1607 +Aufs sometimes requires privilege access to a branch. For instance,
1608 +in copy-up/down operation. When a user process is going to make changes
1609 +to a file which exists in the lower readonly branch only, and the mode
1610 +of one of ancestor directories may not be writable by a user
1611 +process. Here aufs copy-up the file with its ancestors and they may
1612 +require privilege to set its owner/group/mode/etc.
1613 +This is a typical case of a application character of aufs (see
1616 +Aufs uses workqueue synchronously for this case. It creates its own
1617 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1618 +passes the request to call mkdir or write (for example), and wait for
1619 +its completion. This approach solves a problem of a signal handler
1621 +If aufs didn't adopt the workqueue and changed the privilege of the
1622 +process, then the process may receive the unexpected SIGXFSZ or other
1625 +Also aufs uses the system global workqueue ("events" kernel thread) too
1626 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1627 +whiteout base and etc. This is unrelated to a privilege.
1628 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1629 +superblock at the beginning, at the same time waits for the completion
1630 +of all queued asynchronous tasks.
1634 +----------------------------------------------------------------------
1635 +The whiteout in aufs is very similar to Unionfs's. That is represented
1636 +by its filename. UnionMount takes an approach of a file mode, but I am
1637 +afraid several utilities (find(1) or something) will have to support it.
1639 +Basically the whiteout represents "logical deletion" which stops aufs to
1640 +lookup further, but also it represents "dir is opaque" which also stop
1643 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1644 +In order to make several functions in a single systemcall to be
1645 +revertible, aufs adopts an approach to rename a directory to a temporary
1646 +unique whiteouted name.
1647 +For example, in rename(2) dir where the target dir already existed, aufs
1648 +renames the target dir to a temporary unique whiteouted name before the
1649 +actual rename on a branch, and then handles other actions (make it opaque,
1650 +update the attributes, etc). If an error happens in these actions, aufs
1651 +simply renames the whiteouted name back and returns an error. If all are
1652 +succeeded, aufs registers a function to remove the whiteouted unique
1653 +temporary name completely and asynchronously to the system global
1658 +----------------------------------------------------------------------
1659 +It is a well-known feature or concept.
1660 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1661 +internally and makes change to the new file on the upper writable branch.
1662 +When the trigger systemcall does not update the timestamps of the parent
1663 +dir, aufs reverts it after copy-up.
1666 +Move-down (aufs3.9 and later)
1667 +----------------------------------------------------------------------
1668 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1669 +the lower readonly branch to the upper writable branch when a user
1670 +changes something about the file.
1671 +"Move-down" is an opposite action of copy-up. Basically this action is
1672 +ran manually instead of automatically and internally.
1673 +For desgin and implementation, aufs has to consider these issues.
1674 +- whiteout for the file may exist on the lower branch.
1675 +- ancestor directories may not exist on the lower branch.
1676 +- diropq for the ancestor directories may exist on the upper branch.
1677 +- free space on the lower branch will reduce.
1678 +- another access to the file may happen during moving-down, including
1679 + UDBA (see "Revalidate Dentry and UDBA").
1680 +- the file should not be hard-linked nor pseudo-linked. they should be
1681 + handled by auplink utility later.
1683 +Sometimes users want to move-down a file from the upper writable branch
1684 +to the lower readonly or writable branch. For instance,
1685 +- the free space of the upper writable branch is going to run out.
1686 +- create a new intermediate branch between the upper and lower branch.
1689 +For this purpose, use "aumvdown" command in aufs-util.git.
1690 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1691 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1692 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2018-04-15 08:49:13.394483860 +0200
1695 +# Copyright (C) 2015-2018 Junjiro R. Okajima
1697 +# This program is free software; you can redistribute it and/or modify
1698 +# it under the terms of the GNU General Public License as published by
1699 +# the Free Software Foundation; either version 2 of the License, or
1700 +# (at your option) any later version.
1702 +# This program is distributed in the hope that it will be useful,
1703 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1704 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1705 +# GNU General Public License for more details.
1707 +# You should have received a copy of the GNU General Public License
1708 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1710 +Support for a branch who has its ->atomic_open()
1711 +----------------------------------------------------------------------
1712 +The filesystems who implement its ->atomic_open() are not majority. For
1713 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1714 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1715 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1716 +sure whether all filesystems who have ->atomic_open() behave like this,
1717 +but NFSv4 surely returns the error.
1719 +In order to support ->atomic_open() for aufs, there are a few
1722 +A. Introduce aufs_atomic_open()
1723 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1725 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1726 + an aufs user Pip Cet's approach
1727 + - calls aufs_create(), VFS finish_open() and notify_change().
1728 + - pass fake-mode to finish_open(), and then correct the mode by
1730 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1731 + - no aufs_atomic_open().
1732 + - aufs_lookup() registers the TID to an aufs internal object.
1733 + - aufs_create() does nothing when the matching TID is registered, but
1734 + registers the mode.
1735 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1736 + TID is registered.
1737 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1739 + - no aufs_atomic_open().
1740 + - aufs_create() registers the TID to an internal object. this info
1741 + represents "this process created this file just now."
1742 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1743 + registered TID and re-try open() with superuser's credential.
1745 +Pros and cons for each approach.
1748 + - straightforward but highly depends upon VFS internal.
1749 + - the atomic behavaiour is kept.
1750 + - some of parameters such as nameidata are hard to reproduce for
1754 + - easy to implement.
1755 + - the atomic behavaiour is lost.
1757 + - the atomic behavaiour is kept.
1758 + - dirty and tricky.
1759 + - VFS checks whether the file is created correctly after calling
1760 + ->create(), which means this approach doesn't work.
1762 + - easy to implement.
1763 + - the atomic behavaiour is lost.
1764 + - to open a file with superuser's credential and give it to a user
1765 + process is a bad idea, since the file object keeps the credential
1766 + in it. It may affect LSM or something. This approach doesn't work
1769 +The approach A is ideal, but it hard to implement. So here is a
1770 +variation of A, which is to be implemented.
1772 +A-1. Introduce aufs_atomic_open()
1773 + - calls branch fs ->atomic_open() if exists. otherwise calls
1774 + vfs_create() and finish_open().
1775 + - the demerit is that the several checks after branch fs
1776 + ->atomic_open() are lost. in the ordinary case, the checks are
1777 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1778 + be implemented in aufs, but not all I am afraid.
1779 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1780 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1781 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2018-04-15 08:49:13.394483860 +0200
1784 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1786 +# This program is free software; you can redistribute it and/or modify
1787 +# it under the terms of the GNU General Public License as published by
1788 +# the Free Software Foundation; either version 2 of the License, or
1789 +# (at your option) any later version.
1791 +# This program is distributed in the hope that it will be useful,
1792 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1793 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1794 +# GNU General Public License for more details.
1796 +# You should have received a copy of the GNU General Public License
1797 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1800 +----------------------------------------------------------------------
1801 +Since aufs has a character of sub-VFS (see Introduction), it operates
1802 +lookup for branches as VFS does. It may be a heavy work. But almost all
1803 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1804 +directly connected to its parent. Digging down the directory hierarchy
1805 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1808 +When a branch is a remote filesystem, aufs basically relies upon its
1809 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1811 +For d_revalidate, aufs implements three levels of revalidate tests. See
1812 +"Revalidate Dentry and UDBA" in detail.
1815 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1816 +----------------------------------------------------------------------
1817 +Let's try case study.
1818 +- aufs has two branches, upper readwrite and lower readonly.
1820 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1821 +- user invoked "chmod a+rx /au/dirA"
1822 +- the internal copy-up is activated and "/rw/dirA" is created and its
1823 + permission bits are set to world readable.
1824 +- then "/au/dirA" becomes world readable?
1826 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1827 +or it may be a natively readonly filesystem. If aufs respects the lower
1828 +branch, it should not respond readdir request from other users. But user
1829 +allowed it by chmod. Should really aufs rejects showing the entries
1832 +To be honest, I don't have a good solution for this case. So aufs
1833 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1835 +When dirperm1 is specified, aufs checks only the highest one for the
1836 +directory permission, and shows the entries. Otherwise, as usual, checks
1837 +every dir existing on all branches and rejects the request.
1839 +As a side effect, dirperm1 option improves the performance of aufs
1840 +because the number of permission check is reduced when the number of
1844 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1845 +----------------------------------------------------------------------
1846 +Generally VFS helpers re-validate a dentry as a part of lookup.
1847 +0. digging down the directory hierarchy.
1848 +1. lock the parent dir by its i_mutex.
1849 +2. lookup the final (child) entry.
1851 +4. call the actual operation (create, unlink, etc.)
1852 +5. unlock the parent dir
1854 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1855 +called. Actually aufs implements it and checks the dentry on a branch is
1857 +But it is not enough. Because aufs has to release the lock for the
1858 +parent dir on a branch at the end of ->lookup() (step 2) and
1859 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1861 +If the file on a branch is changed directly, eg. bypassing aufs, after
1862 +aufs released the lock, then the subsequent operation may cause
1863 +something unpleasant result.
1865 +This situation is a result of VFS architecture, ->lookup() and
1866 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1867 +design from VFS's point of view. It is just not suitable for sub-VFS
1870 +Aufs supports such case by three level of revalidation which is
1871 +selectable by user.
1872 +1. Simple Revalidate
1873 + Addition to the native flow in VFS's, confirm the child-parent
1874 + relationship on the branch just after locking the parent dir on the
1875 + branch in the "actual operation" (step 4). When this validation
1876 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1877 + checks the validation of the dentry on branches.
1878 +2. Monitor Changes Internally by Inotify/Fsnotify
1879 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1880 + the dentry on the branch, and returns EBUSY if it finds different
1882 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1883 + during it is in cache. When the event is notified, aufs registers a
1884 + function to kernel 'events' thread by schedule_work(). And the
1885 + function sets some special status to the cached aufs dentry and inode
1886 + private data. If they are not cached, then aufs has nothing to
1887 + do. When the same file is accessed through aufs (step 0-3) later,
1888 + aufs will detect the status and refresh all necessary data.
1889 + In this mode, aufs has to ignore the event which is fired by aufs
1891 +3. No Extra Validation
1892 + This is the simplest test and doesn't add any additional revalidation
1893 + test, and skip the revalidation in step 4. It is useful and improves
1894 + aufs performance when system surely hide the aufs branches from user,
1895 + by over-mounting something (or another method).
1896 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1897 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1898 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2018-04-15 08:49:13.394483860 +0200
1901 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1903 +# This program is free software; you can redistribute it and/or modify
1904 +# it under the terms of the GNU General Public License as published by
1905 +# the Free Software Foundation; either version 2 of the License, or
1906 +# (at your option) any later version.
1908 +# This program is distributed in the hope that it will be useful,
1909 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1910 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1911 +# GNU General Public License for more details.
1913 +# You should have received a copy of the GNU General Public License
1914 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1916 +Branch Manipulation
1918 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1919 +and changing its permission/attribute, there are a lot of works to do.
1923 +----------------------------------------------------------------------
1924 +o Confirm the adding dir exists outside of aufs, including loopback
1925 + mount, and its various attributes.
1926 +o Initialize the xino file and whiteout bases if necessary.
1929 +o Check the owner/group/mode of the directory
1930 + When the owner/group/mode of the adding directory differs from the
1931 + existing branch, aufs issues a warning because it may impose a
1933 + For example, when a upper writable branch has a world writable empty
1934 + top directory, a malicious user can create any files on the writable
1935 + branch directly, like copy-up and modify manually. If something like
1936 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1937 + writable branch, and the writable branch is world-writable, then a
1938 + malicious guy may create /etc/passwd on the writable branch directly
1939 + and the infected file will be valid in aufs.
1940 + I am afraid it can be a security issue, but aufs can do nothing except
1941 + producing a warning.
1945 +----------------------------------------------------------------------
1946 +o Confirm the deleting branch is not busy
1947 + To be general, there is one merit to adopt "remount" interface to
1948 + manipulate branches. It is to discard caches. At deleting a branch,
1949 + aufs checks the still cached (and connected) dentries and inodes. If
1950 + there are any, then they are all in-use. An inode without its
1951 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1953 + For the cached one, aufs checks whether the same named entry exists on
1955 + If the cached one is a directory, because aufs provides a merged view
1956 + to users, as long as one dir is left on any branch aufs can show the
1957 + dir to users. In this case, the branch can be removed from aufs.
1958 + Otherwise aufs rejects deleting the branch.
1960 + If any file on the deleting branch is opened by aufs, then aufs
1964 +Modify the Permission of a Branch
1965 +----------------------------------------------------------------------
1966 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1969 +o rw --> ro: Confirm the modifying branch is not busy
1970 + Aufs rejects the request if any of these conditions are true.
1971 + - a file on the branch is mmap-ed.
1972 + - a regular file on the branch is opened for write and there is no
1973 + same named entry on the upper branch.
1974 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1975 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1976 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2018-04-15 08:49:13.394483860 +0200
1979 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1981 +# This program is free software; you can redistribute it and/or modify
1982 +# it under the terms of the GNU General Public License as published by
1983 +# the Free Software Foundation; either version 2 of the License, or
1984 +# (at your option) any later version.
1986 +# This program is distributed in the hope that it will be useful,
1987 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1988 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1989 +# GNU General Public License for more details.
1991 +# You should have received a copy of the GNU General Public License
1992 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1994 +Policies to Select One among Multiple Writable Branches
1995 +----------------------------------------------------------------------
1996 +When the number of writable branch is more than one, aufs has to decide
1997 +the target branch for file creation or copy-up. By default, the highest
1998 +writable branch which has the parent (or ancestor) dir of the target
1999 +file is chosen (top-down-parent policy).
2000 +By user's request, aufs implements some other policies to select the
2001 +writable branch, for file creation several policies, round-robin,
2002 +most-free-space, and other policies. For copy-up, top-down-parent,
2003 +bottom-up-parent, bottom-up and others.
2005 +As expected, the round-robin policy selects the branch in circular. When
2006 +you have two writable branches and creates 10 new files, 5 files will be
2007 +created for each branch. mkdir(2) systemcall is an exception. When you
2008 +create 10 new directories, all will be created on the same branch.
2009 +And the most-free-space policy selects the one which has most free
2010 +space among the writable branches. The amount of free space will be
2011 +checked by aufs internally, and users can specify its time interval.
2013 +The policies for copy-up is more simple,
2014 +top-down-parent is equivalent to the same named on in create policy,
2015 +bottom-up-parent selects the writable branch where the parent dir
2016 +exists and the nearest upper one from the copyup-source,
2017 +bottom-up selects the nearest upper writable branch from the
2018 +copyup-source, regardless the existence of the parent dir.
2020 +There are some rules or exceptions to apply these policies.
2021 +- If there is a readonly branch above the policy-selected branch and
2022 + the parent dir is marked as opaque (a variation of whiteout), or the
2023 + target (creating) file is whiteout-ed on the upper readonly branch,
2024 + then the result of the policy is ignored and the target file will be
2025 + created on the nearest upper writable branch than the readonly branch.
2026 +- If there is a writable branch above the policy-selected branch and
2027 + the parent dir is marked as opaque or the target file is whiteouted
2028 + on the branch, then the result of the policy is ignored and the target
2029 + file will be created on the highest one among the upper writable
2030 + branches who has diropq or whiteout. In case of whiteout, aufs removes
2032 +- link(2) and rename(2) systemcalls are exceptions in every policy.
2033 + They try selecting the branch where the source exists as possible
2034 + since copyup a large file will take long time. If it can't be,
2035 + ie. the branch where the source exists is readonly, then they will
2036 + follow the copyup policy.
2037 +- There is an exception for rename(2) when the target exists.
2038 + If the rename target exists, aufs compares the index of the branches
2039 + where the source and the target exists and selects the higher
2040 + one. If the selected branch is readonly, then aufs follows the
2042 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
2043 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
2044 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2018-04-15 08:49:13.394483860 +0200
2047 +// to view this graph, run dot(1) command in GRAPHVIZ.
2051 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
2055 +aufs_rename -> whinfo [label="store/remove"];
2058 +inode_list [label="h_inum list in branch\ncache"];
2061 +whinode [label="h_inum list file"];
2064 +brmgmt [label="br_add/del/mod/umount"];
2066 +brmgmt -> inode_list [label="create/remove"];
2067 +brmgmt -> whinode [label="load/store"];
2069 +inode_list -> whinode [style=dashed,dir=both];
2071 +aufs_rename -> inode_list [label="add/del"];
2073 +aufs_lookup -> inode_list [label="search"];
2075 +aufs_lookup -> whinfo [label="load/remove"];
2077 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
2078 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
2079 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2018-04-15 08:49:13.394483860 +0200
2082 +# Copyright (C) 2017-2018 Junjiro R. Okajima
2084 +# This program is free software; you can redistribute it and/or modify
2085 +# it under the terms of the GNU General Public License as published by
2086 +# the Free Software Foundation; either version 2 of the License, or
2087 +# (at your option) any later version.
2089 +# This program is distributed in the hope that it will be useful,
2090 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2091 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2092 +# GNU General Public License for more details.
2094 +# You should have received a copy of the GNU General Public License
2095 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2097 +Special handling for renaming a directory (DIRREN)
2098 +----------------------------------------------------------------------
2099 +First, let's assume we have a simple usecase.
2103 +- /ro/dirA and /ro/dirA/file exist too
2104 +- there is no dirB on both branches
2105 +- a user issues rename("dirA", "dirB")
2107 +Now, what should aufs behave against this rename(2)?
2108 +There are a few possible cases.
2111 + since dirA exists on a readonly branch which cannot be renamed.
2113 + it is possible to copy-up dirA (only the dir itself), but the child
2114 + entries ("file" in this case) should not be. it must be a bad
2115 + approach to copy-up recursively.
2116 +C. returns a success.
2117 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
2118 + is a violation of aufs' policy.
2119 +D. construct an extra information which indicates that /ro/dirA should
2120 + be handled as the name of dirB.
2121 + overlayfs has a similar feature called REDIRECT.
2123 +Until now, aufs implements the case B only which returns EXDEV, and
2124 +expects the userspace application behaves like mv(1) which tries
2125 +issueing rename(2) recursively.
2127 +A new aufs feature called DIRREN is introduced which implements the case
2128 +D. There are several "extra information" added.
2130 +1. detailed info per renamed directory
2131 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
2132 +2. the inode-number list of directories on a branch
2133 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
2135 +The filename of "detailed info per directory" represents the lower
2136 +branch, and its format is
2137 +- a type of the branch id
2139 + + uuid (not implemented yet)
2142 +- the inode-number of the branch root dir
2144 +And it contains these info in a single regular file.
2146 +- branch's inode-number of the logically renamed dir
2147 +- the name of the before-renamed dir
2149 +The "detailed info per directory" file is created in aufs rename(2), and
2150 +loaded in any lookup.
2151 +The info is considered in lookup for the matching case only. Here
2152 +"matching" means that the root of branch (in the info filename) is same
2153 +to the current looking-up branch. After looking-up the before-renamed
2154 +name, the inode-number is compared. And the matched dentry is used.
2156 +The "inode-number list of directories" is a regular file which contains
2157 +simply the inode-numbers on the branch. The file is created or updated
2158 +in removing the branch, and loaded in adding the branch. Its lifetime is
2159 +equal to the branch.
2160 +The list is refered in lookup, and when the current target inode is
2161 +found in the list, the aufs tries loading the "detailed info per
2162 +directory" and get the changed and valid name of the dir.
2164 +Theoretically these "extra informaiton" may be able to be put into XATTR
2165 +in the dir inode. But aufs doesn't choose this way because
2166 +1. XATTR may not be supported by the branch (or its configuration)
2167 +2. XATTR may have its size limit.
2168 +3. XATTR may be less easy to convert than a regular file, when the
2169 + format of the info is changed in the future.
2170 +At the same time, I agree that the regular file approach is much slower
2171 +than XATTR approach. So, in the future, aufs may take the XATTR or other
2174 +This DIRREN feature is enabled by aufs configuration, and is activated
2175 +by a new mount option.
2177 +For the more complicated case, there is a work with UDBA option, which
2178 +is to dected the direct access to the branches (by-passing aufs) and to
2179 +maintain the cashes in aufs. Since a single cached aufs dentry may
2180 +contains two names, before- and after-rename, the name comparision in
2181 +UDBA handler may not work correctly. In this case, the behaviour will be
2182 +equivalen to udba=reval case.
2183 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
2184 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
2185 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2018-04-15 08:49:13.394483860 +0200
2188 +# Copyright (C) 2011-2018 Junjiro R. Okajima
2190 +# This program is free software; you can redistribute it and/or modify
2191 +# it under the terms of the GNU General Public License as published by
2192 +# the Free Software Foundation; either version 2 of the License, or
2193 +# (at your option) any later version.
2195 +# This program is distributed in the hope that it will be useful,
2196 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2197 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2198 +# GNU General Public License for more details.
2200 +# You should have received a copy of the GNU General Public License
2201 +# along with this program; if not, write to the Free Software
2202 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2205 +File-based Hierarchical Storage Management (FHSM)
2206 +----------------------------------------------------------------------
2207 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2208 +storage world. Aufs provides this feature as file-based with multiple
2209 +writable branches, based upon the principle of "Colder, the Lower".
2210 +Here the word "colder" means that the less used files, and "lower" means
2211 +that the position in the order of the stacked branches vertically.
2212 +These multiple writable branches are prioritized, ie. the topmost one
2213 +should be the fastest drive and be used heavily.
2215 +o Characters in aufs FHSM story
2216 +- aufs itself and a new branch attribute.
2217 +- a new ioctl interface to move-down and to establish a connection with
2218 + the daemon ("move-down" is a converse of "copy-up").
2219 +- userspace tool and daemon.
2221 +The userspace daemon establishes a connection with aufs and waits for
2222 +the notification. The notified information is very similar to struct
2223 +statfs containing the number of consumed blocks and inodes.
2224 +When the consumed blocks/inodes of a branch exceeds the user-specified
2225 +upper watermark, the daemon activates its move-down process until the
2226 +consumed blocks/inodes reaches the user-specified lower watermark.
2228 +The actual move-down is done by aufs based upon the request from
2229 +user-space since we need to maintain the inode number and the internal
2230 +pointer arrays in aufs.
2232 +Currently aufs FHSM handles the regular files only. Additionally they
2233 +must not be hard-linked nor pseudo-linked.
2236 +o Cowork of aufs and the user-space daemon
2237 + During the userspace daemon established the connection, aufs sends a
2238 + small notification to it whenever aufs writes something into the
2239 + writable branch. But it may cost high since aufs issues statfs(2)
2240 + internally. So user can specify a new option to cache the
2241 + info. Actually the notification is controlled by these factors.
2242 + + the specified cache time.
2243 + + classified as "force" by aufs internally.
2244 + Until the specified time expires, aufs doesn't send the info
2245 + except the forced cases. When aufs decide forcing, the info is always
2246 + notified to userspace.
2247 + For example, the number of free inodes is generally large enough and
2248 + the shortage of it happens rarely. So aufs doesn't force the
2249 + notification when creating a new file, directory and others. This is
2250 + the typical case which aufs doesn't force.
2251 + When aufs writes the actual filedata and the files consumes any of new
2252 + blocks, the aufs forces notifying.
2255 +o Interfaces in aufs
2256 +- New branch attribute.
2258 + Specifies that the branch is managed by FHSM feature. In other word,
2259 + participant in the FHSM.
2260 + When nofhsm is set to the branch, it will not be the source/target
2261 + branch of the move-down operation. This attribute is set
2262 + independently from coo and moo attributes, and if you want full
2263 + FHSM, you should specify them as well.
2264 +- New mount option.
2266 + Specifies a second to suppress many less important info to be
2269 + + AUFS_CTL_FHSM_FD
2270 + create a new file descriptor which userspace can read the notification
2271 + (a subset of struct statfs) from aufs.
2272 +- Module parameter 'brs'
2273 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2275 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2276 + When there are two or more branches with fhsm attributes,
2277 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2278 + terminates it. As a result of remounting and branch-manipulation, the
2279 + number of branches with fhsm attribute can be one. In this case,
2280 + /sbin/mount.aufs will terminate the user-space daemon.
2283 +Finally the operation is done as these steps in kernel-space.
2285 + + no one else is using the file.
2286 + + the file is not hard-linked.
2287 + + the file is not pseudo-linked.
2288 + + the file is a regular file.
2289 + + the parent dir is not opaqued.
2290 +- find the target writable branch.
2291 +- make sure the file is not whiteout-ed by the upper (than the target)
2293 +- make the parent dir on the target branch.
2294 +- mutex lock the inode on the branch.
2295 +- unlink the whiteout on the target branch (if exists).
2296 +- lookup and create the whiteout-ed temporary name on the target branch.
2297 +- copy the file as the whiteout-ed temporary name on the target branch.
2298 +- rename the whiteout-ed temporary name to the original name.
2299 +- unlink the file on the source branch.
2300 +- maintain the internal pointer array and the external inode number
2302 +- maintain the timestamps and other attributes of the parent dir and the
2305 +And of course, in every step, an error may happen. So the operation
2306 +should restore the original file state after an error happens.
2307 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2308 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2309 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2018-04-15 08:49:13.394483860 +0200
2312 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2314 +# This program is free software; you can redistribute it and/or modify
2315 +# it under the terms of the GNU General Public License as published by
2316 +# the Free Software Foundation; either version 2 of the License, or
2317 +# (at your option) any later version.
2319 +# This program is distributed in the hope that it will be useful,
2320 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2321 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2322 +# GNU General Public License for more details.
2324 +# You should have received a copy of the GNU General Public License
2325 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2327 +mmap(2) -- File Memory Mapping
2328 +----------------------------------------------------------------------
2329 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2330 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2332 +This approach is simple and good, but there is one problem.
2333 +Under /proc, several entries show the mmapped files by its path (with
2334 +device and inode number), and the printed path will be the path on the
2335 +branch fs's instead of virtual aufs's.
2336 +This is not a problem in most cases, but some utilities lsof(1) (and its
2337 +user) may expect the path on aufs.
2339 +To address this issue, aufs adds a new member called vm_prfile in struct
2340 +vm_area_struct (and struct vm_region). The original vm_file points to
2341 +the file on the branch fs in order to handle everything correctly as
2342 +usual. The new vm_prfile points to a virtual file in aufs, and the
2343 +show-functions in procfs refers to vm_prfile if it is set.
2344 +Also we need to maintain several other places where touching vm_file
2346 +- fork()/clone() copies vma and the reference count of vm_file is
2348 +- merging vma maintains the ref count too.
2350 +This is not a good approach. It just fakes the printed path. But it
2351 +leaves all behaviour around f_mapping unchanged. This is surely an
2353 +Actually aufs had adopted another complicated approach which calls
2354 +generic_file_mmap() and handles struct vm_operations_struct. In this
2355 +approach, aufs met a hard problem and I could not solve it without
2356 +switching the approach.
2358 +There may be one more another approach which is
2359 +- bind-mount the branch-root onto the aufs-root internally
2360 +- grab the new vfsmount (ie. struct mount)
2361 +- lazy-umount the branch-root internally
2362 +- in open(2) the aufs-file, open the branch-file with the hidden
2363 + vfsmount (instead of the original branch's vfsmount)
2364 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2365 + but it may be possible from userspace by the mount helper.
2367 +Adding the internal hidden vfsmount and using it in opening a file, the
2368 +file path under /proc will be printed correctly. This approach looks
2369 +smarter, but is not possible I am afraid.
2370 +- aufs-root may be bind-mount later. when it happens, another hidden
2371 + vfsmount will be required.
2372 +- it is hard to get the chance to bind-mount and lazy-umount
2373 + + in kernel-space, FS can have vfsmount in open(2) via
2374 + file->f_path, and aufs can know its vfsmount. But several locks are
2375 + already acquired, and if aufs tries to bind-mount and lazy-umount
2376 + here, then it may cause a deadlock.
2377 + + in user-space, bind-mount doesn't invoke the mount helper.
2378 +- since /proc shows dev and ino, aufs has to give vma these info. it
2379 + means a new member vm_prinode will be necessary. this is essentially
2380 + equivalent to vm_prfile described above.
2382 +I have to give up this "looks-smater" approach.
2383 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2384 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2385 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2018-04-15 08:49:13.394483860 +0200
2388 +# Copyright (C) 2014-2018 Junjiro R. Okajima
2390 +# This program is free software; you can redistribute it and/or modify
2391 +# it under the terms of the GNU General Public License as published by
2392 +# the Free Software Foundation; either version 2 of the License, or
2393 +# (at your option) any later version.
2395 +# This program is distributed in the hope that it will be useful,
2396 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2397 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2398 +# GNU General Public License for more details.
2400 +# You should have received a copy of the GNU General Public License
2401 +# along with this program; if not, write to the Free Software
2402 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2405 +Listing XATTR/EA and getting the value
2406 +----------------------------------------------------------------------
2407 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2408 +shows the values from the topmost existing file. This behaviour is good
2409 +for the non-dir entries since the bahaviour exactly matches the shown
2410 +information. But for the directories, aufs considers all the same named
2411 +entries on the lower branches. Which means, if one of the lower entry
2412 +rejects readdir call, then aufs returns an error even if the topmost
2413 +entry allows it. This behaviour is necessary to respect the branch fs's
2414 +security, but can make users confused since the user-visible standard
2415 +attributes don't match the behaviour.
2416 +To address this issue, aufs has a mount option called dirperm1 which
2417 +checks the permission for the topmost entry only, and ignores the lower
2418 +entry's permission.
2420 +A similar issue can happen around XATTR.
2421 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2422 +always set. Otherwise these very unpleasant situation would happen.
2423 +- listxattr(2) may return the duplicated entries.
2424 +- users may not be able to remove or reset the XATTR forever,
2427 +XATTR/EA support in the internal (copy,move)-(up,down)
2428 +----------------------------------------------------------------------
2429 +Generally the extended attributes of inode are categorized as these.
2430 +- "security" for LSM and capability.
2431 +- "system" for posix ACL, 'acl' mount option is required for the branch
2433 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2434 +- "user" for userspace, 'user_xattr' mount option is required for the
2435 + branch fs generally.
2437 +Moreover there are some other categories. Aufs handles these rather
2438 +unpopular categories as the ordinary ones, ie. there is no special
2439 +condition nor exception.
2441 +In copy-up, the support for XATTR on the dst branch may differ from the
2442 +src branch. In this case, the copy-up operation will get an error and
2443 +the original user operation which triggered the copy-up will fail. It
2444 +can happen that even all copy-up will fail.
2445 +When both of src and dst branches support XATTR and if an error occurs
2446 +during copying XATTR, then the copy-up should fail obviously. That is a
2447 +good reason and aufs should return an error to userspace. But when only
2448 +the src branch support that XATTR, aufs should not return an error.
2449 +For example, the src branch supports ACL but the dst branch doesn't
2450 +because the dst branch may natively un-support it or temporary
2451 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2452 +may NOT return an error even if the XATTR is not supported. It is
2453 +totally up to the branch fs.
2455 +Anyway when the aufs internal copy-up gets an error from the dst branch
2456 +fs, then aufs tries removing the just copied entry and returns the error
2457 +to the userspace. The worst case of this situation will be all copy-up
2460 +For the copy-up operation, there two basic approaches.
2461 +- copy the specified XATTR only (by category above), and return the
2462 + error unconditionally if it happens.
2463 +- copy all XATTR, and ignore the error on the specified category only.
2465 +In order to support XATTR and to implement the correct behaviour, aufs
2466 +chooses the latter approach and introduces some new branch attributes,
2467 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2468 +They correspond to the XATTR namespaces (see above). Additionally, to be
2469 +convenient, "icex" is also provided which means all "icex*" attributes
2470 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2472 +The meaning of these attributes is to ignore the error from setting
2473 +XATTR on that branch.
2474 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2475 +error from the dst branch according to the specified attributes.
2477 +Some XATTR may have its default value. The default value may come from
2478 +the parent dir or the environment. If the default value is set at the
2479 +file creating-time, it will be overwritten by copy-up.
2480 +Some contradiction may happen I am afraid.
2481 +Do we need another attribute to stop copying XATTR? I am unsure. For
2482 +now, aufs implements the branch attributes to ignore the error.
2483 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2484 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2485 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2018-04-15 08:49:13.394483860 +0200
2488 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2490 +# This program is free software; you can redistribute it and/or modify
2491 +# it under the terms of the GNU General Public License as published by
2492 +# the Free Software Foundation; either version 2 of the License, or
2493 +# (at your option) any later version.
2495 +# This program is distributed in the hope that it will be useful,
2496 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2497 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2498 +# GNU General Public License for more details.
2500 +# You should have received a copy of the GNU General Public License
2501 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2503 +Export Aufs via NFS
2504 +----------------------------------------------------------------------
2505 +Here is an approach.
2506 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2508 +- iget_locked(): initialize aufs inode generation for a new inode, and
2509 + store it in xigen file.
2510 +- destroy_inode(): increment aufs inode generation and store it in xigen
2511 + file. it is necessary even if it is not unlinked, because any data of
2512 + inode may be changed by UDBA.
2513 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2514 + build file handle by
2515 + + branch id (4 bytes)
2516 + + superblock generation (4 bytes)
2517 + + inode number (4 or 8 bytes)
2518 + + parent dir inode number (4 or 8 bytes)
2519 + + inode generation (4 bytes))
2520 + + return value of exportfs_encode_fh() for the parent on a branch (4
2522 + + file handle for a branch (by exportfs_encode_fh())
2524 + + find the index of a branch from its id in handle, and check it is
2525 + still exist in aufs.
2526 + + 1st level: get the inode number from handle and search it in cache.
2527 + + 2nd level: if not found in cache, get the parent inode number from
2528 + the handle and search it in cache. and then open the found parent
2529 + dir, find the matching inode number by vfs_readdir() and get its
2530 + name, and call lookup_one_len() for the target dentry.
2531 + + 3rd level: if the parent dir is not cached, call
2532 + exportfs_decode_fh() for a branch and get the parent on a branch,
2533 + build a pathname of it, convert it a pathname in aufs, call
2534 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2536 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2537 + for every branch, but not itself. to get this, (currently) aufs
2538 + searches in current->nsproxy->mnt_ns list. it may not be a good
2539 + idea, but I didn't get other approach.
2540 + + test the generation of the gotten inode.
2541 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2542 + convert it into ESTALE for NFSD.
2543 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2544 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2545 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2546 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2547 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2018-04-15 08:49:13.394483860 +0200
2550 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2552 +# This program is free software; you can redistribute it and/or modify
2553 +# it under the terms of the GNU General Public License as published by
2554 +# the Free Software Foundation; either version 2 of the License, or
2555 +# (at your option) any later version.
2557 +# This program is distributed in the hope that it will be useful,
2558 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2559 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2560 +# GNU General Public License for more details.
2562 +# You should have received a copy of the GNU General Public License
2563 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2565 +Show Whiteout Mode (shwh)
2566 +----------------------------------------------------------------------
2567 +Generally aufs hides the name of whiteouts. But in some cases, to show
2568 +them is very useful for users. For instance, creating a new middle layer
2569 +(branch) by merging existing layers.
2571 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2572 +When you have three branches,
2573 +- Bottom: 'system', squashfs (underlying base system), read-only
2574 +- Middle: 'mods', squashfs, read-only
2575 +- Top: 'overlay', ram (tmpfs), read-write
2577 +The top layer is loaded at boot time and saved at shutdown, to preserve
2578 +the changes made to the system during the session.
2579 +When larger changes have been made, or smaller changes have accumulated,
2580 +the size of the saved top layer data grows. At this point, it would be
2581 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2582 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2583 +restoring save and load speed.
2585 +This merging is simplified by the use of another aufs mount, of just the
2586 +two overlay branches using the 'shwh' option.
2587 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2588 + aufs /livesys/merge_union
2590 +A merged view of these two branches is then available at
2591 +/livesys/merge_union, and the new feature is that the whiteouts are
2593 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2594 +writing to all branches. Also the default mode for all branches is 'ro'.
2595 +It is now possible to save the combined contents of the two overlay
2596 +branches to a new squashfs, e.g.:
2597 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2599 +This new squashfs archive can be stored on the boot device and the
2600 +initramfs will use it to replace the old one at the next boot.
2601 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2602 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2603 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2018-04-15 08:49:13.394483860 +0200
2606 +# Copyright (C) 2010-2018 Junjiro R. Okajima
2608 +# This program is free software; you can redistribute it and/or modify
2609 +# it under the terms of the GNU General Public License as published by
2610 +# the Free Software Foundation; either version 2 of the License, or
2611 +# (at your option) any later version.
2613 +# This program is distributed in the hope that it will be useful,
2614 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2615 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2616 +# GNU General Public License for more details.
2618 +# You should have received a copy of the GNU General Public License
2619 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2621 +Dynamically customizable FS operations
2622 +----------------------------------------------------------------------
2623 +Generally FS operations (struct inode_operations, struct
2624 +address_space_operations, struct file_operations, etc.) are defined as
2625 +"static const", but it never means that FS have only one set of
2626 +operation. Some FS have multiple sets of them. For instance, ext2 has
2627 +three sets, one for XIP, for NOBH, and for normal.
2628 +Since aufs overrides and redirects these operations, sometimes aufs has
2629 +to change its behaviour according to the branch FS type. More importantly
2630 +VFS acts differently if a function (member in the struct) is set or
2631 +not. It means aufs should have several sets of operations and select one
2632 +among them according to the branch FS definition.
2634 +In order to solve this problem and not to affect the behaviour of VFS,
2635 +aufs defines these operations dynamically. For instance, aufs defines
2636 +dummy direct_IO function for struct address_space_operations, but it may
2637 +not be set to the address_space_operations actually. When the branch FS
2638 +doesn't have it, aufs doesn't set it to its address_space_operations
2639 +while the function definition itself is still alive. So the behaviour
2640 +itself will not change, and it will return an error when direct_IO is
2643 +The lifetime of these dynamically generated operation object is
2644 +maintained by aufs branch object. When the branch is removed from aufs,
2645 +the reference counter of the object is decremented. When it reaches
2646 +zero, the dynamically generated operation object will be freed.
2648 +This approach is designed to support AIO (io_submit), Direct I/O and
2650 +Currently this approach is applied to address_space_operations for
2651 +regular files only.
2652 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2653 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2654 +++ linux/Documentation/filesystems/aufs/README 2018-12-27 13:19:17.705082621 +0100
2657 +Aufs4 -- advanced multi layered unification filesystem version 4.x
2663 +----------------------------------------
2664 +In the early days, aufs was entirely re-designed and re-implemented
2665 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2666 +improvements and implementations, it becomes totally different from
2667 +Unionfs while keeping the basic features.
2668 +Recently, Unionfs Version 2.x series begin taking some of the same
2669 +approaches to aufs1's.
2670 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2671 +University and his team.
2673 +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3.
2674 +If you want older kernel version support, try aufs2-2.6.git or
2675 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2677 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2678 + According to Christoph Hellwig, linux rejects all union-type
2679 + filesystems but UnionMount.
2680 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2682 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2683 + UnionMount, and he pointed out an issue around a directory mutex
2684 + lock and aufs addressed it. But it is still unsure whether aufs will
2685 + be merged (or any other union solution).
2686 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2690 +----------------------------------------
2691 +- unite several directories into a single virtual filesystem. The member
2692 + directory is called as a branch.
2693 +- you can specify the permission flags to the branch, which are 'readonly',
2694 + 'readwrite' and 'whiteout-able.'
2695 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2696 + readonly branch are modifiable logically.
2697 +- dynamic branch manipulation, add, del.
2700 +Also there are many enhancements in aufs, such as:
2701 +- test only the highest one for the directory permission (dirperm1)
2702 +- copyup on open (coo=)
2703 +- 'move' policy for copy-up between two writable branches, after
2704 + checking free space.
2706 +- readdir(3) in userspace.
2707 +- keep inode number by external inode number table
2708 +- keep the timestamps of file/dir in internal copyup operation
2709 +- seekable directory, supporting NFS readdir.
2710 +- whiteout is hardlinked in order to reduce the consumption of inodes
2712 +- do not copyup, nor create a whiteout when it is unnecessary
2713 +- revert a single systemcall when an error occurs in aufs
2714 +- remount interface instead of ioctl
2715 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2716 +- loopback mounted filesystem as a branch
2717 +- kernel thread for removing the dir who has a plenty of whiteouts
2718 +- support copyup sparse file (a file which has a 'hole' in it)
2719 +- default permission flags for branches
2720 +- selectable permission flags for ro branch, whether whiteout can
2723 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2724 +- support multiple writable branches, some policies to select one
2725 + among multiple writable branches.
2726 +- a new semantics for link(2) and rename(2) to support multiple
2727 + writable branches.
2728 +- no glibc changes are required.
2729 +- pseudo hardlink (hardlink over branches)
2730 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2731 + including NFS or remote filesystem branch.
2732 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2735 +Currently these features are dropped temporary from aufs4.
2736 +See design/08plan.txt in detail.
2737 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2739 +- statistics of aufs thread (/sys/fs/aufs/stat)
2741 +Features or just an idea in the future (see also design/*.txt),
2742 +- reorder the branch index without del/re-add.
2743 +- permanent xino files for NFSD
2744 +- an option for refreshing the opened files after add/del branches
2745 +- light version, without branch manipulation. (unnecessary?)
2746 +- copyup in userspace
2747 +- inotify in userspace
2752 +----------------------------------------
2753 +There are three GIT trees for aufs4, aufs4-linux.git,
2754 +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in
2756 +While the aufs-util is always necessary, you need either of aufs4-linux
2757 +or aufs4-standalone.
2759 +The aufs4-linux tree includes the whole linux mainline GIT tree,
2760 +git://git.kernel.org/.../torvalds/linux.git.
2761 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2762 +build aufs4 as an external kernel module.
2763 +Several extra patches are not included in this tree. Only
2764 +aufs4-standalone tree contains them. They are described in the later
2765 +section "Configuration and Compilation."
2767 +On the other hand, the aufs4-standalone tree has only aufs source files
2768 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2769 +But you need to apply all aufs patches manually.
2771 +You will find GIT branches whose name is in form of "aufs4.x" where "x"
2772 +represents the linux kernel version, "linux-4.x". For instance,
2773 +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use
2774 +"aufs4.x-rcN" branch.
2777 +$ git clone --reference /your/linux/git/tree \
2778 + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git
2779 +- if you don't have linux GIT tree, then remove "--reference ..."
2780 +$ cd aufs4-linux.git
2781 +$ git checkout origin/aufs4.0
2783 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2784 +leave the patch-work to GIT.
2785 +$ cd /your/linux/git/tree
2786 +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git
2788 +$ git checkout -b my4.0 v4.0
2789 +$ (add your local change...)
2790 +$ git pull aufs4 aufs4.0
2791 +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch.
2792 +- you may need to solve some conflicts between your_changes and
2793 + aufs4.0. in this case, git-rerere is recommended so that you can
2794 + solve the similar conflicts automatically when you upgrade to 4.1 or
2795 + later in the future.
2797 +o aufs4-standalone tree
2798 +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git
2799 +$ cd aufs4-standalone.git
2800 +$ git checkout origin/aufs4.0
2803 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2804 +- note that the public aufs-util.git is on SourceForge instead of
2807 +$ git checkout origin/aufs4.0
2809 +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY.
2810 +The minor version number, 'x' in '4.x', of aufs may not always
2811 +follow the minor version number of the kernel.
2812 +Because changes in the kernel that cause the use of a new
2813 +minor version number do not always require changes to aufs-util.
2815 +Since aufs-util has its own minor version number, you may not be
2816 +able to find a GIT branch in aufs-util for your kernel's
2817 +exact minor version number.
2818 +In this case, you should git-checkout the branch for the
2819 +nearest lower number.
2821 +For (an unreleased) example:
2822 +If you are using "linux-4.10" and the "aufs4.10" branch
2823 +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8"
2824 +or something numerically smaller is the branch for your kernel.
2826 +Also you can view all branches by
2830 +3. Configuration and Compilation
2831 +----------------------------------------
2832 +Make sure you have git-checkout'ed the correct branch.
2834 +For aufs4-linux tree,
2835 +- enable CONFIG_AUFS_FS.
2836 +- set other aufs configurations if necessary.
2838 +For aufs4-standalone tree,
2839 +There are several ways to build.
2842 +- apply ./aufs4-kbuild.patch to your kernel source files.
2843 +- apply ./aufs4-base.patch too.
2844 +- apply ./aufs4-mmap.patch too.
2845 +- apply ./aufs4-standalone.patch too, if you have a plan to set
2846 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch.
2847 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2848 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2849 +- enable CONFIG_AUFS_FS, you can select either
2851 +- and build your kernel as usual.
2852 +- install the built kernel.
2853 + Note: Since linux-3.9, every filesystem module requires an alias
2854 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2855 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2856 +- install the header files too by "make headers_install" to the
2857 + directory where you specify. By default, it is $PWD/usr.
2858 + "make help" shows a brief note for headers_install.
2859 +- and reboot your system.
2862 +- module only (CONFIG_AUFS_FS=m).
2863 +- apply ./aufs4-base.patch to your kernel source files.
2864 +- apply ./aufs4-mmap.patch too.
2865 +- apply ./aufs4-standalone.patch too.
2866 +- build your kernel, don't forget "make headers_install", and reboot.
2867 +- edit ./config.mk and set other aufs configurations if necessary.
2868 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2869 + every aufs configurations.
2870 +- build the module by simple "make".
2871 + Note: Since linux-3.9, every filesystem module requires an alias
2872 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2873 + modules.aliases file.
2874 +- you can specify ${KDIR} make variable which points to your kernel
2876 +- install the files
2877 + + run "make install" to install the aufs module, or copy the built
2878 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2879 + + run "make install_headers" (instead of headers_install) to install
2880 + the modified aufs header file (you can specify DESTDIR which is
2881 + available in aufs standalone version's Makefile only), or copy
2882 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2883 + you like manually. By default, the target directory is $PWD/usr.
2884 +- no need to apply aufs4-kbuild.patch, nor copying source files to your
2885 + kernel source tree.
2887 +Note: The header file aufs_type.h is necessary to build aufs-util
2888 + as well as "make headers_install" in the kernel source tree.
2889 + headers_install is subject to be forgotten, but it is essentially
2890 + necessary, not only for building aufs-util.
2891 + You may not meet problems without headers_install in some older
2895 +- read README in aufs-util, build and install it
2896 +- note that your distribution may contain an obsoleted version of
2897 + aufs_type.h in /usr/include/linux or something. When you build aufs
2898 + utilities, make sure that your compiler refers the correct aufs header
2899 + file which is built by "make headers_install."
2900 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2901 + then run "make install_ulib" too. And refer to the aufs manual in
2904 +There several other patches in aufs4-standalone.git. They are all
2905 +optional. When you meet some problems, they will help you.
2906 +- aufs4-loopback.patch
2907 + Supports a nested loopback mount in a branch-fs. This patch is
2908 + unnecessary until aufs produces a message like "you may want to try
2909 + another patch for loopback file".
2911 + Modifies a system global kernel internal function get_next_ino() in
2912 + order to stop assigning 0 for an inode-number. Not directly related to
2913 + aufs, but recommended generally.
2915 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2916 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2917 + duplication of inode number, which is important for backup tools and
2918 + other utilities. When you find aufs XINO files for tmpfs branch
2919 + growing too much, try this patch.
2920 +- lockdep-debug.patch
2921 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2922 + also a caller of VFS functions for branch filesystems, subclassing of
2923 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2924 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2925 + need to apply this debug patch to expand several constant values.
2926 + If don't know what LOCKDEP, then you don't have apply this patch.
2930 +----------------------------------------
2931 +At first, make sure aufs-util are installed, and please read the aufs
2932 +manual, aufs.5 in aufs-util.git tree.
2936 +$ mkdir /tmp/rw /tmp/aufs
2937 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2939 +Here is another example. The result is equivalent.
2940 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2942 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2943 +# mount -o remount,append:${HOME} /tmp/aufs
2945 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2946 +you modify a file under /tmp/aufs, the one on your home directory is
2947 +not affected, instead the same named file will be newly created under
2948 +/tmp/rw. And all of your modification to a file will be applied to
2949 +the one under /tmp/rw. This is called the file based Copy on Write
2951 +Aufs mount options are described in aufs.5.
2952 +If you run chroot or something and make your aufs as a root directory,
2953 +then you need to customize the shutdown script. See the aufs manual in
2956 +Additionally, there are some sample usages of aufs which are a
2957 +diskless system with network booting, and LiveCD over NFS.
2958 +See sample dir in CVS tree on SourceForge.
2962 +----------------------------------------
2963 +When you have any problems or strange behaviour in aufs, please let me
2965 +- /proc/mounts (instead of the output of mount(8))
2966 +- /sys/module/aufs/*
2967 +- /sys/fs/aufs/* (if you have them)
2968 +- /debug/aufs/* (if you have them)
2969 +- linux kernel version
2970 + if your kernel is not plain, for example modified by distributor,
2971 + the url where i can download its source is necessary too.
2972 +- aufs version which was printed at loading the module or booting the
2973 + system, instead of the date you downloaded.
2974 +- configuration (define/undefine CONFIG_AUFS_xxx)
2975 +- kernel configuration or /proc/config.gz (if you have it)
2976 +- behaviour which you think to be incorrect
2977 +- actual operation, reproducible one is better
2978 +- mailto: aufs-users at lists.sourceforge.net
2980 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2981 +and Feature Requests) on SourceForge. Please join and write to
2985 +6. Acknowledgements
2986 +----------------------------------------
2987 +Thanks to everyone who have tried and are using aufs, whoever
2988 +have reported a bug or any feedback.
2990 +Especially donators:
2991 +Tomas Matejicek(slax.org) made a donation (much more than once).
2992 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2993 + scripts) is making "doubling" donations.
2994 + Unfortunately I cannot list all of the donators, but I really
2996 + It ends Aug 2010, but the ordinary donation URL is still available.
2997 + <http://sourceforge.net/donate/index.php?group_id=167503>
2998 +Dai Itasaka made a donation (2007/8).
2999 +Chuck Smith made a donation (2008/4, 10 and 12).
3000 +Henk Schoneveld made a donation (2008/9).
3001 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
3002 +Francois Dupoux made a donation (2008/11).
3003 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
3004 + aufs2 GIT tree (2009/2).
3005 +William Grant made a donation (2009/3).
3006 +Patrick Lane made a donation (2009/4).
3007 +The Mail Archive (mail-archive.com) made donations (2009/5).
3008 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
3009 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
3010 +Pavel Pronskiy made a donation (2011/2).
3011 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
3012 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
3013 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
3015 +Sam Liddicott made a donation (2011/9).
3016 +Era Scarecrow made a donation (2013/4).
3017 +Bor Ratajc made a donation (2013/4).
3018 +Alessandro Gorreta made a donation (2013/4).
3019 +POIRETTE Marc made a donation (2013/4).
3020 +Alessandro Gorreta made a donation (2013/4).
3021 +lauri kasvandik made a donation (2013/5).
3022 +"pemasu from Finland" made a donation (2013/7).
3023 +The Parted Magic Project made a donation (2013/9 and 11).
3024 +Pavel Barta made a donation (2013/10).
3025 +Nikolay Pertsev made a donation (2014/5).
3026 +James B made a donation (2014/7 and 2015/7).
3027 +Stefano Di Biase made a donation (2014/8).
3028 +Daniel Epellei made a donation (2015/1).
3029 +OmegaPhil made a donation (2016/1, 2018/4).
3030 +Tomasz Szewczyk made a donation (2016/4).
3031 +James Burry made a donation (2016/12).
3032 +Carsten Rose made a donation (2018/9).
3033 +Porteus Kiosk made a donation (2018/10).
3035 +Thank you very much.
3036 +Donations are always, including future donations, very important and
3037 +helpful for me to keep on developing aufs.
3041 +----------------------------------------
3042 +If you are an experienced user, no explanation is needed. Aufs is
3043 +just a linux filesystem.
3048 +# Local variables: ;
3051 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
3052 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
3053 +++ linux/fs/aufs/aufs.h 2018-10-23 12:33:35.592708932 +0200
3055 +/* SPDX-License-Identifier: GPL-2.0 */
3057 + * Copyright (C) 2005-2018 Junjiro R. Okajima
3059 + * This program, aufs is free software; you can redistribute it and/or modify
3060 + * it under the terms of the GNU General Public License as published by
3061 + * the Free Software Foundation; either version 2 of the License, or
3062 + * (at your option) any later version.
3064 + * This program is distributed in the hope that it will be useful,
3065 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3066 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3067 + * GNU General Public License for more details.
3069 + * You should have received a copy of the GNU General Public License
3070 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3074 + * all header files
3082 +#define AuStub(type, name, body, ...) \
3083 + static inline type name(__VA_ARGS__) { body; }
3085 +#define AuStubVoid(name, ...) \
3086 + AuStub(void, name, , __VA_ARGS__)
3087 +#define AuStubInt0(name, ...) \
3088 + AuStub(int, name, return 0, __VA_ARGS__)
3092 +#include "branch.h"
3095 +#include "dbgaufs.h"
3096 +#include "dentry.h"
3098 +#include "dirren.h"
3101 +#include "fstype.h"
3106 +#include "module.h"
3110 +#include "sysaufs.h"
3115 +#endif /* __KERNEL__ */
3116 +#endif /* __AUFS_H__ */
3117 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
3118 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
3119 +++ linux/fs/aufs/branch.c 2018-12-27 13:19:17.708416053 +0100
3121 +// SPDX-License-Identifier: GPL-2.0
3123 + * Copyright (C) 2005-2018 Junjiro R. Okajima
3125 + * This program, aufs is free software; you can redistribute it and/or modify
3126 + * it under the terms of the GNU General Public License as published by
3127 + * the Free Software Foundation; either version 2 of the License, or
3128 + * (at your option) any later version.
3130 + * This program is distributed in the hope that it will be useful,
3131 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3132 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3133 + * GNU General Public License for more details.
3135 + * You should have received a copy of the GNU General Public License
3136 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3140 + * branch management
3143 +#include <linux/compat.h>
3144 +#include <linux/statfs.h>
3148 + * free a single branch
3150 +static void au_br_do_free(struct au_branch *br)
3153 + struct au_wbr *wbr;
3154 + struct au_dykey **key;
3156 + au_hnotify_fin_br(br);
3157 + /* always, regardless the mount option */
3158 + au_dr_hino_free(&br->br_dirren);
3161 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
3162 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
3163 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
3164 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
3168 + for (i = 0; i < AuBrWh_Last; i++)
3169 + dput(wbr->wbr_wh[i]);
3170 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
3171 + AuRwDestroy(&wbr->wbr_wh_rwsem);
3174 + if (br->br_fhsm) {
3175 + au_br_fhsm_fin(br->br_fhsm);
3176 + au_kfree_try_rcu(br->br_fhsm);
3179 + key = br->br_dykey;
3180 + for (i = 0; i < AuBrDynOp; i++, key++)
3186 + /* recursive lock, s_umount of branch's */
3187 + /* synchronize_rcu(); */ /* why? */
3189 + path_put(&br->br_path);
3191 + au_kfree_rcu(wbr);
3192 + au_lcnt_wait_for_fin(&br->br_nfiles);
3193 + au_lcnt_wait_for_fin(&br->br_count);
3194 + /* I don't know why, but percpu_refcount requires this */
3195 + /* synchronize_rcu(); */
3200 + * frees all branches
3202 +void au_br_free(struct au_sbinfo *sbinfo)
3204 + aufs_bindex_t bmax;
3205 + struct au_branch **br;
3207 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3209 + bmax = sbinfo->si_bbot + 1;
3210 + br = sbinfo->si_branch;
3212 + au_br_do_free(*br++);
3216 + * find the index of a branch which is specified by @br_id.
3218 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3220 + aufs_bindex_t bindex, bbot;
3222 + bbot = au_sbbot(sb);
3223 + for (bindex = 0; bindex <= bbot; bindex++)
3224 + if (au_sbr_id(sb, bindex) == br_id)
3229 +/* ---------------------------------------------------------------------- */
3235 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3236 + struct dentry *h_root)
3238 + if (unlikely(h_adding == h_root
3239 + || au_test_loopback_overlap(sb, h_adding)))
3241 + if (h_adding->d_sb != h_root->d_sb)
3243 + return au_test_subdir(h_adding, h_root)
3244 + || au_test_subdir(h_root, h_adding);
3248 + * returns a newly allocated branch. @new_nbranch is a number of branches
3249 + * after adding a branch.
3251 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3254 + struct au_branch *add_branch;
3255 + struct dentry *root;
3256 + struct inode *inode;
3260 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3261 + if (unlikely(!add_branch))
3263 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3264 + if (unlikely(!add_branch->br_xino))
3266 + err = au_hnotify_init_br(add_branch, perm);
3267 + if (unlikely(err))
3270 + if (au_br_writable(perm)) {
3271 + /* may be freed separately at changing the branch permission */
3272 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3274 + if (unlikely(!add_branch->br_wbr))
3278 + if (au_br_fhsm(perm)) {
3279 + err = au_fhsm_br_alloc(add_branch);
3280 + if (unlikely(err))
3284 + root = sb->s_root;
3285 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3287 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3289 + inode = d_inode(root);
3290 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3294 + return add_branch; /* success */
3297 + au_kfree_rcu(add_branch->br_wbr);
3299 + au_hnotify_fin_br(add_branch);
3301 + au_xino_put(add_branch);
3303 + au_kfree_rcu(add_branch);
3305 + return ERR_PTR(err);
3309 + * test if the branch permission is legal or not.
3311 +static int test_br(struct inode *inode, int brperm, char *path)
3315 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3320 + pr_err("write permission for readonly mount or inode, %s\n", path);
3328 + * 0: success, the caller will add it
3329 + * plus: success, it is already unified, the caller should ignore it
3332 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3335 + aufs_bindex_t bbot, bindex;
3336 + struct dentry *root, *h_dentry;
3337 + struct inode *inode, *h_inode;
3339 + root = sb->s_root;
3340 + bbot = au_sbbot(sb);
3341 + if (unlikely(bbot >= 0
3342 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3346 + pr_err("%s duplicated\n", add->pathname);
3351 + err = -ENOSPC; /* -E2BIG; */
3352 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3353 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3354 + pr_err("number of branches exceeded %s\n", add->pathname);
3359 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3360 + pr_err("bad index %d\n", add->bindex);
3364 + inode = d_inode(add->path.dentry);
3366 + if (unlikely(!inode->i_nlink)) {
3367 + pr_err("no existence %s\n", add->pathname);
3372 + if (unlikely(inode->i_sb == sb)) {
3373 + pr_err("%s must be outside\n", add->pathname);
3377 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3378 + pr_err("unsupported filesystem, %s (%s)\n",
3379 + add->pathname, au_sbtype(inode->i_sb));
3383 + if (unlikely(inode->i_sb->s_stack_depth)) {
3384 + pr_err("already stacked, %s (%s)\n",
3385 + add->pathname, au_sbtype(inode->i_sb));
3389 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3390 + if (unlikely(err))
3394 + return 0; /* success */
3397 + for (bindex = 0; bindex <= bbot; bindex++)
3398 + if (unlikely(test_overlap(sb, add->path.dentry,
3399 + au_h_dptr(root, bindex)))) {
3400 + pr_err("%s is overlapped\n", add->pathname);
3405 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3406 + h_dentry = au_h_dptr(root, 0);
3407 + h_inode = d_inode(h_dentry);
3408 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3409 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3410 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3411 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3413 + i_uid_read(inode), i_gid_read(inode),
3414 + (inode->i_mode & S_IALLUGO),
3415 + i_uid_read(h_inode), i_gid_read(h_inode),
3416 + (h_inode->i_mode & S_IALLUGO));
3424 + * initialize or clean the whiteouts for an adding branch
3426 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3429 + int err, old_perm;
3430 + aufs_bindex_t bindex;
3431 + struct inode *h_inode;
3432 + struct au_wbr *wbr;
3433 + struct au_hinode *hdir;
3434 + struct dentry *h_dentry;
3436 + err = vfsub_mnt_want_write(au_br_mnt(br));
3437 + if (unlikely(err))
3441 + old_perm = br->br_perm;
3442 + br->br_perm = new_perm;
3445 + bindex = au_br_index(sb, br->br_id);
3446 + if (0 <= bindex) {
3447 + hdir = au_hi(d_inode(sb->s_root), bindex);
3448 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3450 + h_dentry = au_br_dentry(br);
3451 + h_inode = d_inode(h_dentry);
3452 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3455 + err = au_wh_init(br, sb);
3457 + wbr_wh_write_lock(wbr);
3458 + err = au_wh_init(br, sb);
3459 + wbr_wh_write_unlock(wbr);
3462 + au_hn_inode_unlock(hdir);
3464 + inode_unlock(h_inode);
3465 + vfsub_mnt_drop_write(au_br_mnt(br));
3466 + br->br_perm = old_perm;
3468 + if (!err && wbr && !au_br_writable(new_perm)) {
3469 + au_kfree_rcu(wbr);
3470 + br->br_wbr = NULL;
3477 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3481 + struct kstatfs kst;
3482 + struct au_wbr *wbr;
3485 + au_rw_init(&wbr->wbr_wh_rwsem);
3486 + atomic_set(&wbr->wbr_wh_running, 0);
3489 + * a limit for rmdir/rename a dir
3490 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3492 + err = vfs_statfs(&br->br_path, &kst);
3493 + if (unlikely(err))
3496 + if (kst.f_namelen >= NAME_MAX)
3497 + err = au_br_init_wh(sb, br, perm);
3499 + pr_err("%pd(%s), unsupported namelen %ld\n",
3501 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3507 +/* initialize a new branch */
3508 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3509 + struct au_opt_add *add)
3512 + struct au_branch *brbase;
3514 + struct inode *h_inode;
3517 + br->br_perm = add->perm;
3518 + br->br_path = add->path; /* set first, path_get() later */
3519 + spin_lock_init(&br->br_dykey_lock);
3520 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3521 + au_lcnt_init(&br->br_count, /*release*/NULL);
3522 + br->br_id = au_new_br_id(sb);
3523 + AuDebugOn(br->br_id < 0);
3525 + /* always, regardless the given option */
3526 + err = au_dr_br_init(sb, br, &add->path);
3527 + if (unlikely(err))
3530 + if (au_br_writable(add->perm)) {
3531 + err = au_wbr_init(br, sb, add->perm);
3532 + if (unlikely(err))
3536 + if (au_opt_test(au_mntflags(sb), XINO)) {
3537 + brbase = au_sbr(sb, 0);
3538 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3540 + h_inode = d_inode(add->path.dentry);
3541 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3542 + if (unlikely(err)) {
3543 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3548 + sysaufs_br_init(br);
3549 + path_get(&br->br_path);
3550 + goto out; /* success */
3553 + memset(&br->br_path, 0, sizeof(br->br_path));
3558 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3559 + struct au_branch *br, aufs_bindex_t bbot,
3560 + aufs_bindex_t amount)
3562 + struct au_branch **brp;
3564 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3566 + brp = sbinfo->si_branch + bindex;
3567 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3569 + sbinfo->si_bbot++;
3570 + if (unlikely(bbot < 0))
3571 + sbinfo->si_bbot = 0;
3574 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3575 + aufs_bindex_t bbot, aufs_bindex_t amount)
3577 + struct au_hdentry *hdp;
3579 + AuRwMustWriteLock(&dinfo->di_rwsem);
3581 + hdp = au_hdentry(dinfo, bindex);
3582 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3583 + au_h_dentry_init(hdp);
3585 + if (unlikely(bbot < 0))
3586 + dinfo->di_btop = 0;
3589 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3590 + aufs_bindex_t bbot, aufs_bindex_t amount)
3592 + struct au_hinode *hip;
3594 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3596 + hip = au_hinode(iinfo, bindex);
3597 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3598 + au_hinode_init(hip);
3600 + if (unlikely(bbot < 0))
3601 + iinfo->ii_btop = 0;
3604 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3605 + aufs_bindex_t bindex)
3607 + struct dentry *root, *h_dentry;
3608 + struct inode *root_inode, *h_inode;
3609 + aufs_bindex_t bbot, amount;
3611 + root = sb->s_root;
3612 + root_inode = d_inode(root);
3613 + bbot = au_sbbot(sb);
3614 + amount = bbot + 1 - bindex;
3615 + h_dentry = au_br_dentry(br);
3616 + au_sbilist_lock();
3617 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3618 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3619 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3620 + au_set_h_dptr(root, bindex, dget(h_dentry));
3621 + h_inode = d_inode(h_dentry);
3622 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3623 + au_sbilist_unlock();
3626 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3629 + aufs_bindex_t bbot, add_bindex;
3630 + struct dentry *root, *h_dentry;
3631 + struct inode *root_inode;
3632 + struct au_branch *add_branch;
3634 + root = sb->s_root;
3635 + root_inode = d_inode(root);
3636 + IMustLock(root_inode);
3637 + IiMustWriteLock(root_inode);
3638 + err = test_add(sb, add, remount);
3639 + if (unlikely(err < 0))
3643 + goto out; /* success */
3646 + bbot = au_sbbot(sb);
3647 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3648 + err = PTR_ERR(add_branch);
3649 + if (IS_ERR(add_branch))
3652 + err = au_br_init(add_branch, sb, add);
3653 + if (unlikely(err)) {
3654 + au_br_do_free(add_branch);
3658 + add_bindex = add->bindex;
3659 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3660 + au_br_do_add(sb, add_branch, add_bindex);
3661 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3662 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3664 + h_dentry = add->path.dentry;
3665 + if (!add_bindex) {
3666 + au_cpup_attr_all(root_inode, /*force*/1);
3667 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3669 + au_add_nlink(root_inode, d_inode(h_dentry));
3675 +/* ---------------------------------------------------------------------- */
3677 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3678 + unsigned long long max __maybe_unused,
3681 + unsigned long long n;
3682 + struct file **p, *f;
3683 + struct hlist_bl_head *files;
3684 + struct hlist_bl_node *pos;
3685 + struct au_finfo *finfo;
3689 + files = &au_sbi(sb)->si_files;
3690 + hlist_bl_lock(files);
3691 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3692 + f = finfo->fi_file;
3694 + && !special_file(file_inode(f)->i_mode)) {
3698 + AuDebugOn(n > max);
3701 + hlist_bl_unlock(files);
3706 +static struct file **au_farray_alloc(struct super_block *sb,
3707 + unsigned long long *max)
3709 + struct au_sbinfo *sbi;
3712 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3713 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3716 +static void au_farray_free(struct file **a, unsigned long long max)
3718 + unsigned long long ull;
3720 + for (ull = 0; ull < max; ull++)
3726 +/* ---------------------------------------------------------------------- */
3732 +/* to show the line number, do not make it inlined function */
3733 +#define AuVerbose(do_info, fmt, ...) do { \
3735 + pr_info(fmt, ##__VA_ARGS__); \
3738 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3739 + aufs_bindex_t bbot)
3741 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3744 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3745 + aufs_bindex_t bbot)
3747 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3751 + * test if the branch is deletable or not.
3753 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3754 + unsigned int sigen, const unsigned int verbose)
3756 + int err, i, j, ndentry;
3757 + aufs_bindex_t btop, bbot;
3758 + struct au_dcsub_pages dpages;
3759 + struct au_dpage *dpage;
3762 + err = au_dpages_init(&dpages, GFP_NOFS);
3763 + if (unlikely(err))
3765 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3766 + if (unlikely(err))
3769 + for (i = 0; !err && i < dpages.ndpage; i++) {
3770 + dpage = dpages.dpages + i;
3771 + ndentry = dpage->ndentry;
3772 + for (j = 0; !err && j < ndentry; j++) {
3773 + d = dpage->dentries[j];
3774 + AuDebugOn(au_dcount(d) <= 0);
3775 + if (!au_digen_test(d, sigen)) {
3776 + di_read_lock_child(d, AuLock_IR);
3777 + if (unlikely(au_dbrange_test(d))) {
3778 + di_read_unlock(d, AuLock_IR);
3782 + di_write_lock_child(d);
3783 + if (unlikely(au_dbrange_test(d))) {
3784 + di_write_unlock(d);
3787 + err = au_reval_dpath(d, sigen);
3789 + di_downgrade_lock(d, AuLock_IR);
3791 + di_write_unlock(d);
3796 + /* AuDbgDentry(d); */
3797 + btop = au_dbtop(d);
3798 + bbot = au_dbbot(d);
3799 + if (btop <= bindex
3801 + && au_h_dptr(d, bindex)
3802 + && au_test_dbusy(d, btop, bbot)) {
3804 + AuVerbose(verbose, "busy %pd\n", d);
3807 + di_read_unlock(d, AuLock_IR);
3812 + au_dpages_free(&dpages);
3817 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3818 + unsigned int sigen, const unsigned int verbose)
3821 + unsigned long long max, ull;
3822 + struct inode *i, **array;
3823 + aufs_bindex_t btop, bbot;
3825 + array = au_iarray_alloc(sb, &max);
3826 + err = PTR_ERR(array);
3827 + if (IS_ERR(array))
3831 + AuDbg("b%d\n", bindex);
3832 + for (ull = 0; !err && ull < max; ull++) {
3836 + if (i->i_ino == AUFS_ROOT_INO)
3839 + /* AuDbgInode(i); */
3840 + if (au_iigen(i, NULL) == sigen)
3841 + ii_read_lock_child(i);
3843 + ii_write_lock_child(i);
3844 + err = au_refresh_hinode_self(i);
3847 + ii_downgrade_lock(i);
3849 + ii_write_unlock(i);
3854 + btop = au_ibtop(i);
3855 + bbot = au_ibbot(i);
3856 + if (btop <= bindex
3858 + && au_h_iptr(i, bindex)
3859 + && au_test_ibusy(i, btop, bbot)) {
3861 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3864 + ii_read_unlock(i);
3866 + au_iarray_free(array, max);
3872 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3873 + const unsigned int verbose)
3876 + unsigned int sigen;
3878 + sigen = au_sigen(root->d_sb);
3879 + DiMustNoWaiters(root);
3880 + IiMustNoWaiters(d_inode(root));
3881 + di_write_unlock(root);
3882 + err = test_dentry_busy(root, bindex, sigen, verbose);
3884 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3885 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3890 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3891 + struct file **to_free, int *idx)
3894 + unsigned char matched, root;
3895 + aufs_bindex_t bindex, bbot;
3896 + struct au_fidir *fidir;
3897 + struct au_hfile *hfile;
3900 + root = IS_ROOT(file->f_path.dentry);
3903 + to_free[*idx] = file;
3909 + fidir = au_fi(file)->fi_hdir;
3910 + AuDebugOn(!fidir);
3911 + bbot = au_fbbot_dir(file);
3912 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3913 + hfile = fidir->fd_hfile + bindex;
3914 + if (!hfile->hf_file)
3917 + if (hfile->hf_br->br_id == br_id) {
3929 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3930 + struct file **to_free, int opened)
3933 + unsigned long long ull, max;
3934 + aufs_bindex_t btop;
3935 + struct file *file, **array;
3936 + struct dentry *root;
3937 + struct au_hfile *hfile;
3939 + array = au_farray_alloc(sb, &max);
3940 + err = PTR_ERR(array);
3941 + if (IS_ERR(array))
3946 + root = sb->s_root;
3947 + di_write_unlock(root);
3948 + for (ull = 0; ull < max; ull++) {
3949 + file = array[ull];
3950 + if (unlikely(!file))
3953 + /* AuDbg("%pD\n", file); */
3954 + fi_read_lock(file);
3955 + btop = au_fbtop(file);
3956 + if (!d_is_dir(file->f_path.dentry)) {
3957 + hfile = &au_fi(file)->fi_htop;
3958 + if (hfile->hf_br->br_id == br_id)
3961 + err = test_dir_busy(file, br_id, to_free, &idx);
3962 + fi_read_unlock(file);
3963 + if (unlikely(err))
3966 + di_write_lock_child(root);
3967 + au_farray_free(array, max);
3968 + AuDebugOn(idx > opened);
3974 +static void br_del_file(struct file **to_free, unsigned long long opened,
3975 + aufs_bindex_t br_id)
3977 + unsigned long long ull;
3978 + aufs_bindex_t bindex, btop, bbot, bfound;
3979 + struct file *file;
3980 + struct au_fidir *fidir;
3981 + struct au_hfile *hfile;
3983 + for (ull = 0; ull < opened; ull++) {
3984 + file = to_free[ull];
3985 + if (unlikely(!file))
3988 + /* AuDbg("%pD\n", file); */
3989 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3991 + fidir = au_fi(file)->fi_hdir;
3992 + AuDebugOn(!fidir);
3993 + fi_write_lock(file);
3994 + btop = au_fbtop(file);
3995 + bbot = au_fbbot_dir(file);
3996 + for (bindex = btop; bindex <= bbot; bindex++) {
3997 + hfile = fidir->fd_hfile + bindex;
3998 + if (!hfile->hf_file)
4001 + if (hfile->hf_br->br_id == br_id) {
4006 + AuDebugOn(bfound < 0);
4007 + au_set_h_fptr(file, bfound, NULL);
4008 + if (bfound == btop) {
4009 + for (btop++; btop <= bbot; btop++)
4010 + if (au_hf_dir(file, btop)) {
4011 + au_set_fbtop(file, btop);
4015 + fi_write_unlock(file);
4019 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
4020 + const aufs_bindex_t bindex,
4021 + const aufs_bindex_t bbot)
4023 + struct au_branch **brp, **p;
4025 + AuRwMustWriteLock(&sbinfo->si_rwsem);
4027 + brp = sbinfo->si_branch + bindex;
4028 + if (bindex < bbot)
4029 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
4030 + sbinfo->si_branch[0 + bbot] = NULL;
4031 + sbinfo->si_bbot--;
4033 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
4036 + sbinfo->si_branch = p;
4037 + /* harmless error */
4040 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
4041 + const aufs_bindex_t bbot)
4043 + struct au_hdentry *hdp, *p;
4045 + AuRwMustWriteLock(&dinfo->di_rwsem);
4047 + hdp = au_hdentry(dinfo, bindex);
4048 + if (bindex < bbot)
4049 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
4050 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
4053 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
4056 + dinfo->di_hdentry = p;
4057 + /* harmless error */
4060 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
4061 + const aufs_bindex_t bbot)
4063 + struct au_hinode *hip, *p;
4065 + AuRwMustWriteLock(&iinfo->ii_rwsem);
4067 + hip = au_hinode(iinfo, bindex);
4068 + if (bindex < bbot)
4069 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
4070 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
4073 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
4076 + iinfo->ii_hinode = p;
4077 + /* harmless error */
4080 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
4081 + struct au_branch *br)
4083 + aufs_bindex_t bbot;
4084 + struct au_sbinfo *sbinfo;
4085 + struct dentry *root, *h_root;
4086 + struct inode *inode, *h_inode;
4087 + struct au_hinode *hinode;
4089 + SiMustWriteLock(sb);
4091 + root = sb->s_root;
4092 + inode = d_inode(root);
4093 + sbinfo = au_sbi(sb);
4094 + bbot = sbinfo->si_bbot;
4096 + h_root = au_h_dptr(root, bindex);
4097 + hinode = au_hi(inode, bindex);
4098 + h_inode = au_igrab(hinode->hi_inode);
4101 + au_sbilist_lock();
4102 + au_br_do_del_brp(sbinfo, bindex, bbot);
4103 + au_br_do_del_hdp(au_di(root), bindex, bbot);
4104 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
4105 + au_sbilist_unlock();
4107 + /* ignore an error */
4108 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
4112 + au_br_do_free(br);
4115 +static unsigned long long empty_cb(struct super_block *sb, void *array,
4116 + unsigned long long max, void *arg)
4121 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
4124 + unsigned long long opened;
4125 + unsigned int mnt_flags;
4126 + aufs_bindex_t bindex, bbot, br_id;
4127 + unsigned char do_wh, verbose;
4128 + struct au_branch *br;
4129 + struct au_wbr *wbr;
4130 + struct dentry *root;
4131 + struct file **to_free;
4136 + root = sb->s_root;
4137 + bindex = au_find_dbindex(root, del->h_path.dentry);
4140 + goto out; /* success */
4142 + pr_err("%s no such branch\n", del->pathname);
4145 + AuDbg("bindex b%d\n", bindex);
4148 + mnt_flags = au_mntflags(sb);
4149 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4150 + bbot = au_sbbot(sb);
4151 + if (unlikely(!bbot)) {
4152 + AuVerbose(verbose, "no more branches left\n");
4156 + br = au_sbr(sb, bindex);
4157 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
4158 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
4159 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
4163 + br_id = br->br_id;
4164 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
4165 + if (unlikely(opened)) {
4166 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
4167 + err = PTR_ERR(to_free);
4168 + if (IS_ERR(to_free))
4171 + err = test_file_busy(sb, br_id, to_free, opened);
4172 + if (unlikely(err)) {
4173 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
4179 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4181 + /* instead of WbrWhMustWriteLock(wbr) */
4182 + SiMustWriteLock(sb);
4183 + for (i = 0; i < AuBrWh_Last; i++) {
4184 + dput(wbr->wbr_wh[i]);
4185 + wbr->wbr_wh[i] = NULL;
4189 + err = test_children_busy(root, bindex, verbose);
4190 + if (unlikely(err)) {
4199 + * now we confirmed the branch is deletable.
4200 + * let's free the remaining opened dirs on the branch.
4202 + di_write_unlock(root);
4203 + br_del_file(to_free, opened, br_id);
4204 + di_write_lock_child(root);
4207 + sysaufs_brs_del(sb, bindex); /* remove successors */
4208 + dbgaufs_xino_del(br); /* remove one */
4209 + au_br_do_del(sb, bindex, br);
4210 + sysaufs_brs_add(sb, bindex); /* append successors */
4211 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4214 + au_cpup_attr_all(d_inode(root), /*force*/1);
4215 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4217 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4218 + if (au_opt_test(mnt_flags, PLINK))
4219 + au_plink_half_refresh(sb, br_id);
4221 + goto out; /* success */
4225 + rerr = au_br_init_wh(sb, br, br->br_perm);
4227 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4228 + del->pathname, rerr);
4231 + au_farray_free(to_free, opened);
4235 +/* ---------------------------------------------------------------------- */
4237 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4240 + aufs_bindex_t btop, bbot;
4241 + struct aufs_ibusy ibusy;
4242 + struct inode *inode, *h_inode;
4245 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4248 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4250 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
4251 + if (unlikely(err)) {
4258 + si_read_lock(sb, AuLock_FLUSH);
4259 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4263 + ibusy.h_ino = 0; /* invalid */
4264 + inode = ilookup(sb, ibusy.ino);
4266 + || inode->i_ino == AUFS_ROOT_INO
4267 + || au_is_bad_inode(inode))
4270 + ii_read_lock_child(inode);
4271 + btop = au_ibtop(inode);
4272 + bbot = au_ibbot(inode);
4273 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4274 + h_inode = au_h_iptr(inode, ibusy.bindex);
4275 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4276 + ibusy.h_ino = h_inode->i_ino;
4278 + ii_read_unlock(inode);
4282 + si_read_unlock(sb);
4284 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4285 + if (unlikely(err)) {
4294 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4296 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4299 +#ifdef CONFIG_COMPAT
4300 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4302 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4306 +/* ---------------------------------------------------------------------- */
4309 + * change a branch permission
4312 +static void au_warn_ima(void)
4315 + /* since it doesn't support mark_files_ro() */
4316 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4320 +static int do_need_sigen_inc(int a, int b)
4322 + return au_br_whable(a) && !au_br_whable(b);
4325 +static int need_sigen_inc(int old, int new)
4327 + return do_need_sigen_inc(old, new)
4328 + || do_need_sigen_inc(new, old);
4331 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4334 + unsigned int mnt_flags;
4335 + unsigned long long ull, max;
4336 + aufs_bindex_t br_id;
4337 + unsigned char verbose, writer;
4338 + struct file *file, *hf, **array;
4339 + struct au_hfile *hfile;
4341 + mnt_flags = au_mntflags(sb);
4342 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4344 + array = au_farray_alloc(sb, &max);
4345 + err = PTR_ERR(array);
4346 + if (IS_ERR(array))
4350 + br_id = au_sbr_id(sb, bindex);
4351 + for (ull = 0; ull < max; ull++) {
4352 + file = array[ull];
4353 + if (unlikely(!file))
4356 + /* AuDbg("%pD\n", file); */
4357 + fi_read_lock(file);
4358 + if (unlikely(au_test_mmapped(file))) {
4360 + AuVerbose(verbose, "mmapped %pD\n", file);
4362 + FiMustNoWaiters(file);
4363 + fi_read_unlock(file);
4367 + hfile = &au_fi(file)->fi_htop;
4368 + hf = hfile->hf_file;
4369 + if (!d_is_reg(file->f_path.dentry)
4370 + || !(file->f_mode & FMODE_WRITE)
4371 + || hfile->hf_br->br_id != br_id
4372 + || !(hf->f_mode & FMODE_WRITE))
4373 + array[ull] = NULL;
4379 + FiMustNoWaiters(file);
4380 + fi_read_unlock(file);
4388 + for (ull = 0; ull < max; ull++) {
4389 + file = array[ull];
4393 + /* todo: already flushed? */
4395 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4396 + * approach which resets f_mode and calls mnt_drop_write() and
4397 + * file_release_write() for each file, because the branch
4398 + * attribute in aufs world is totally different from the native
4401 + /* fi_read_lock(file); */
4402 + hfile = &au_fi(file)->fi_htop;
4403 + hf = hfile->hf_file;
4404 + /* fi_read_unlock(file); */
4405 + spin_lock(&hf->f_lock);
4406 + writer = !!(hf->f_mode & FMODE_WRITER);
4407 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4408 + spin_unlock(&hf->f_lock);
4410 + put_write_access(file_inode(hf));
4411 + __mnt_drop_write(hf->f_path.mnt);
4416 + au_farray_free(array, max);
4422 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4426 + aufs_bindex_t bindex;
4427 + struct dentry *root;
4428 + struct au_branch *br;
4429 + struct au_br_fhsm *bf;
4431 + root = sb->s_root;
4432 + bindex = au_find_dbindex(root, mod->h_root);
4435 + return 0; /* success */
4437 + pr_err("%s no such branch\n", mod->path);
4440 + AuDbg("bindex b%d\n", bindex);
4442 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4443 + if (unlikely(err))
4446 + br = au_sbr(sb, bindex);
4447 + AuDebugOn(mod->h_root != au_br_dentry(br));
4448 + if (br->br_perm == mod->perm)
4449 + return 0; /* success */
4451 + /* pre-allocate for non-fhsm --> fhsm */
4453 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4454 + err = au_fhsm_br_alloc(br);
4455 + if (unlikely(err))
4458 + br->br_fhsm = NULL;
4461 + if (au_br_writable(br->br_perm)) {
4462 + /* remove whiteout base */
4463 + err = au_br_init_wh(sb, br, mod->perm);
4464 + if (unlikely(err))
4467 + if (!au_br_writable(mod->perm)) {
4468 + /* rw --> ro, file might be mmapped */
4469 + DiMustNoWaiters(root);
4470 + IiMustNoWaiters(d_inode(root));
4471 + di_write_unlock(root);
4472 + err = au_br_mod_files_ro(sb, bindex);
4473 + /* aufs_write_lock() calls ..._child() */
4474 + di_write_lock_child(root);
4476 + if (unlikely(err)) {
4478 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4481 + rerr = au_wbr_init(br, sb, br->br_perm);
4482 + if (unlikely(rerr)) {
4483 + AuIOErr("nested error %d (%d)\n",
4485 + br->br_perm = mod->perm;
4489 + } else if (au_br_writable(mod->perm)) {
4492 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4494 + err = au_wbr_init(br, sb, mod->perm);
4495 + if (unlikely(err)) {
4496 + au_kfree_rcu(br->br_wbr);
4497 + br->br_wbr = NULL;
4501 + if (unlikely(err))
4504 + if (au_br_fhsm(br->br_perm)) {
4505 + if (!au_br_fhsm(mod->perm)) {
4506 + /* fhsm --> non-fhsm */
4507 + au_br_fhsm_fin(br->br_fhsm);
4508 + au_kfree_rcu(br->br_fhsm);
4509 + br->br_fhsm = NULL;
4511 + } else if (au_br_fhsm(mod->perm))
4512 + /* non-fhsm --> fhsm */
4515 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4516 + br->br_perm = mod->perm;
4517 + goto out; /* success */
4520 + au_kfree_try_rcu(bf);
4526 +/* ---------------------------------------------------------------------- */
4528 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4531 + struct kstatfs kstfs;
4533 + err = vfs_statfs(&br->br_path, &kstfs);
4535 + stfs->f_blocks = kstfs.f_blocks;
4536 + stfs->f_bavail = kstfs.f_bavail;
4537 + stfs->f_files = kstfs.f_files;
4538 + stfs->f_ffree = kstfs.f_ffree;
4543 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4544 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4545 +++ linux/fs/aufs/branch.h 2018-12-27 13:19:17.708416053 +0100
4547 +/* SPDX-License-Identifier: GPL-2.0 */
4549 + * Copyright (C) 2005-2018 Junjiro R. Okajima
4551 + * This program, aufs is free software; you can redistribute it and/or modify
4552 + * it under the terms of the GNU General Public License as published by
4553 + * the Free Software Foundation; either version 2 of the License, or
4554 + * (at your option) any later version.
4556 + * This program is distributed in the hope that it will be useful,
4557 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4558 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4559 + * GNU General Public License for more details.
4561 + * You should have received a copy of the GNU General Public License
4562 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4566 + * branch filesystems and xino for them
4569 +#ifndef __AUFS_BRANCH_H__
4570 +#define __AUFS_BRANCH_H__
4574 +#include <linux/mount.h>
4575 +#include "dirren.h"
4581 +/* ---------------------------------------------------------------------- */
4585 + struct file **xi_file;
4586 + unsigned int xi_nfile;
4592 + /* reserved for future use */
4593 + /* unsigned long *bitmap; */
4594 + wait_queue_head_t wqh;
4597 + struct mutex xi_mtx; /* protects xi_file array */
4598 + struct hlist_bl_head xi_writing;
4600 + atomic_t xi_truncating;
4602 + struct kref xi_kref;
4605 +/* File-based Hierarchical Storage Management */
4606 +struct au_br_fhsm {
4607 +#ifdef CONFIG_AUFS_FHSM
4608 + struct mutex bf_lock;
4609 + unsigned long bf_jiffy;
4610 + struct aufs_stfs bf_stfs;
4615 +/* members for writable branch only */
4616 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4618 + struct au_rwsem wbr_wh_rwsem;
4619 + struct dentry *wbr_wh[AuBrWh_Last];
4620 + atomic_t wbr_wh_running;
4621 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4622 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4623 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4626 + unsigned long long wbr_bytes;
4629 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4630 +#define AuBrDynOp (AuDyLast * 4)
4632 +#ifdef CONFIG_AUFS_HFSNOTIFY
4633 +/* support for asynchronous destruction */
4634 +struct au_br_hfsnotify {
4635 + struct fsnotify_group *hfsn_group;
4639 +/* sysfs entries */
4640 +struct au_brsysfs {
4642 + struct attribute attr;
4651 +/* protected by superblock rwsem */
4653 + struct au_xino *br_xino;
4655 + aufs_bindex_t br_id;
4658 + struct path br_path;
4659 + spinlock_t br_dykey_lock;
4660 + struct au_dykey *br_dykey[AuBrDynOp];
4661 + au_lcnt_t br_nfiles; /* opened files */
4662 + au_lcnt_t br_count; /* in-use for other */
4664 + struct au_wbr *br_wbr;
4665 + struct au_br_fhsm *br_fhsm;
4667 +#ifdef CONFIG_AUFS_HFSNOTIFY
4668 + struct au_br_hfsnotify *br_hfsn;
4671 +#ifdef CONFIG_SYSFS
4672 + /* entries under sysfs per mount-point */
4673 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4676 +#ifdef CONFIG_DEBUG_FS
4677 + struct dentry *br_dbgaufs; /* xino */
4680 + struct au_dr_br br_dirren;
4683 +/* ---------------------------------------------------------------------- */
4685 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4687 + return br->br_path.mnt;
4690 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4692 + return br->br_path.dentry;
4695 +static inline struct super_block *au_br_sb(struct au_branch *br)
4697 + return au_br_mnt(br)->mnt_sb;
4700 +static inline int au_br_rdonly(struct au_branch *br)
4702 + return (sb_rdonly(au_br_sb(br))
4703 + || !au_br_writable(br->br_perm))
4707 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4709 +#ifdef CONFIG_AUFS_HNOTIFY
4710 + return !(brperm & AuBrPerm_RR);
4716 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4718 + int err, exec_flag;
4721 + exec_flag = oflag & __FMODE_EXEC;
4722 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4728 +static inline void au_xino_get(struct au_branch *br)
4730 + struct au_xino *xi;
4734 + kref_get(&xi->xi_kref);
4737 +static inline int au_xino_count(struct au_branch *br)
4740 + struct au_xino *xi;
4745 + v = kref_read(&xi->xi_kref);
4750 +/* ---------------------------------------------------------------------- */
4754 +void au_br_free(struct au_sbinfo *sinfo);
4755 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4757 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4759 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4760 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4761 +#ifdef CONFIG_COMPAT
4762 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4765 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4768 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4771 +static const loff_t au_loff_max = LLONG_MAX;
4773 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4774 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent);
4775 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4776 + struct file *copy_src);
4778 + struct au_xino *xi; /* switch between xino and xigen */
4780 + struct path *base;
4781 + struct file *copy_src;
4783 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4785 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4787 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4789 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4791 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4792 + size_t size, loff_t *pos);
4794 +int au_xib_trunc(struct super_block *sb);
4795 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4797 +struct au_xino *au_xino_alloc(unsigned int nfile);
4798 +int au_xino_put(struct au_branch *br);
4799 +struct file *au_xino_file1(struct au_xino *xi);
4801 +struct au_opt_xino;
4802 +void au_xino_clr(struct super_block *sb);
4803 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4804 +struct file *au_xino_def(struct super_block *sb);
4805 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4806 + struct path *base);
4808 +ino_t au_xino_new_ino(struct super_block *sb);
4809 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4811 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4812 + ino_t h_ino, int idx);
4813 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4816 +int au_xino_path(struct seq_file *seq, struct file *file);
4818 +/* ---------------------------------------------------------------------- */
4820 +/* @idx is signed to accept -1 meaning the first file */
4821 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4823 + struct file *file;
4830 + if (idx < xi->xi_nfile)
4831 + file = xi->xi_file[idx];
4833 + file = au_xino_file1(xi);
4839 +/* ---------------------------------------------------------------------- */
4841 +/* Superblock to branch */
4843 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4845 + return au_sbr(sb, bindex)->br_id;
4849 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4851 + return au_br_mnt(au_sbr(sb, bindex));
4855 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4857 + return au_br_sb(au_sbr(sb, bindex));
4860 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4862 + return au_sbr(sb, bindex)->br_perm;
4865 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4867 + return au_br_whable(au_sbr_perm(sb, bindex));
4870 +/* ---------------------------------------------------------------------- */
4872 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4873 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4874 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4875 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4877 +#define wbr_wh_read_trylock_nested(wbr) \
4878 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4879 +#define wbr_wh_write_trylock_nested(wbr) \
4880 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4883 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4884 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4885 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4887 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4888 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4889 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4891 +/* ---------------------------------------------------------------------- */
4893 +#ifdef CONFIG_AUFS_FHSM
4894 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4896 + mutex_init(&brfhsm->bf_lock);
4897 + brfhsm->bf_jiffy = 0;
4898 + brfhsm->bf_readable = 0;
4901 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4903 + mutex_destroy(&brfhsm->bf_lock);
4906 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4907 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4910 +#endif /* __KERNEL__ */
4911 +#endif /* __AUFS_BRANCH_H__ */
4912 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4913 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4914 +++ linux/fs/aufs/conf.mk 2018-06-04 09:08:09.181412645 +0200
4916 +# SPDX-License-Identifier: GPL-2.0
4918 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4922 +AuConfStr += ${1}=${${1}}
4926 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4928 + HNOTIFY HFSNOTIFY \
4940 +$(foreach i, ${AuConfAll}, \
4941 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4943 +AuConfName = ${obj}/conf.str
4944 +${AuConfName}.tmp: FORCE
4945 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4946 +${AuConfName}: ${AuConfName}.tmp
4947 + @diff -q $< $@ > /dev/null 2>&1 || { \
4948 + echo ' GEN ' $@; \
4952 +clean-files += ${AuConfName} ${AuConfName}.tmp
4953 +${obj}/sysfs.o: ${AuConfName}
4955 +-include ${srctree}/${src}/conf_priv.mk
4956 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4957 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4958 +++ linux/fs/aufs/cpup.c 2018-12-27 13:19:17.708416053 +0100
4960 +// SPDX-License-Identifier: GPL-2.0
4962 + * Copyright (C) 2005-2018 Junjiro R. Okajima
4964 + * This program, aufs is free software; you can redistribute it and/or modify
4965 + * it under the terms of the GNU General Public License as published by
4966 + * the Free Software Foundation; either version 2 of the License, or
4967 + * (at your option) any later version.
4969 + * This program is distributed in the hope that it will be useful,
4970 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4971 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4972 + * GNU General Public License for more details.
4974 + * You should have received a copy of the GNU General Public License
4975 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4979 + * copy-up functions, see wbr_policy.c for copy-down
4982 +#include <linux/fs_stack.h>
4983 +#include <linux/mm.h>
4984 +#include <linux/task_work.h>
4987 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4989 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4990 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4992 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4994 + dst->i_flags |= iflags & ~mask;
4995 + if (au_test_fs_notime(dst->i_sb))
4996 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4999 +void au_cpup_attr_timesizes(struct inode *inode)
5001 + struct inode *h_inode;
5003 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5004 + fsstack_copy_attr_times(inode, h_inode);
5005 + fsstack_copy_inode_size(inode, h_inode);
5008 +void au_cpup_attr_nlink(struct inode *inode, int force)
5010 + struct inode *h_inode;
5011 + struct super_block *sb;
5012 + aufs_bindex_t bindex, bbot;
5015 + bindex = au_ibtop(inode);
5016 + h_inode = au_h_iptr(inode, bindex);
5018 + && !S_ISDIR(h_inode->i_mode)
5019 + && au_opt_test(au_mntflags(sb), PLINK)
5020 + && au_plink_test(inode))
5024 + * 0 can happen in revalidating.
5025 + * h_inode->i_mutex may not be held here, but it is harmless since once
5026 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
5028 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
5029 + * the incorrect link count.
5031 + set_nlink(inode, h_inode->i_nlink);
5034 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
5035 + * it may includes whplink directory.
5037 + if (S_ISDIR(h_inode->i_mode)) {
5038 + bbot = au_ibbot(inode);
5039 + for (bindex++; bindex <= bbot; bindex++) {
5040 + h_inode = au_h_iptr(inode, bindex);
5042 + au_add_nlink(inode, h_inode);
5047 +void au_cpup_attr_changeable(struct inode *inode)
5049 + struct inode *h_inode;
5051 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5052 + inode->i_mode = h_inode->i_mode;
5053 + inode->i_uid = h_inode->i_uid;
5054 + inode->i_gid = h_inode->i_gid;
5055 + au_cpup_attr_timesizes(inode);
5056 + au_cpup_attr_flags(inode, h_inode->i_flags);
5059 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
5061 + struct au_iinfo *iinfo = au_ii(inode);
5063 + IiMustWriteLock(inode);
5065 + iinfo->ii_higen = h_inode->i_generation;
5066 + iinfo->ii_hsb1 = h_inode->i_sb;
5069 +void au_cpup_attr_all(struct inode *inode, int force)
5071 + struct inode *h_inode;
5073 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5074 + au_cpup_attr_changeable(inode);
5075 + if (inode->i_nlink > 0)
5076 + au_cpup_attr_nlink(inode, force);
5077 + inode->i_rdev = h_inode->i_rdev;
5078 + inode->i_blkbits = h_inode->i_blkbits;
5079 + au_cpup_igen(inode, h_inode);
5082 +/* ---------------------------------------------------------------------- */
5084 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
5086 +/* keep the timestamps of the parent dir when cpup */
5087 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5088 + struct path *h_path)
5090 + struct inode *h_inode;
5092 + dt->dt_dentry = dentry;
5093 + dt->dt_h_path = *h_path;
5094 + h_inode = d_inode(h_path->dentry);
5095 + dt->dt_atime = h_inode->i_atime;
5096 + dt->dt_mtime = h_inode->i_mtime;
5100 +void au_dtime_revert(struct au_dtime *dt)
5102 + struct iattr attr;
5105 + attr.ia_atime = dt->dt_atime;
5106 + attr.ia_mtime = dt->dt_mtime;
5107 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
5108 + | ATTR_ATIME | ATTR_ATIME_SET;
5110 + /* no delegation since this is a directory */
5111 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
5112 + if (unlikely(err))
5113 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
5116 +/* ---------------------------------------------------------------------- */
5118 +/* internal use only */
5119 +struct au_cpup_reg_attr {
5122 + unsigned int iflags; /* inode->i_flags */
5125 +static noinline_for_stack
5126 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
5127 + struct au_cpup_reg_attr *h_src_attr)
5129 + int err, sbits, icex;
5130 + unsigned int mnt_flags;
5131 + unsigned char verbose;
5133 + struct path h_path;
5134 + struct inode *h_isrc, *h_idst;
5135 + struct kstat *h_st;
5136 + struct au_branch *br;
5138 + h_path.dentry = au_h_dptr(dst, bindex);
5139 + h_idst = d_inode(h_path.dentry);
5140 + br = au_sbr(dst->d_sb, bindex);
5141 + h_path.mnt = au_br_mnt(br);
5142 + h_isrc = d_inode(h_src);
5143 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
5144 + | ATTR_ATIME | ATTR_MTIME
5145 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
5146 + if (h_src_attr && h_src_attr->valid) {
5147 + h_st = &h_src_attr->st;
5148 + ia.ia_uid = h_st->uid;
5149 + ia.ia_gid = h_st->gid;
5150 + ia.ia_atime = h_st->atime;
5151 + ia.ia_mtime = h_st->mtime;
5152 + if (h_idst->i_mode != h_st->mode
5153 + && !S_ISLNK(h_idst->i_mode)) {
5154 + ia.ia_valid |= ATTR_MODE;
5155 + ia.ia_mode = h_st->mode;
5157 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
5158 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
5160 + ia.ia_uid = h_isrc->i_uid;
5161 + ia.ia_gid = h_isrc->i_gid;
5162 + ia.ia_atime = h_isrc->i_atime;
5163 + ia.ia_mtime = h_isrc->i_mtime;
5164 + if (h_idst->i_mode != h_isrc->i_mode
5165 + && !S_ISLNK(h_idst->i_mode)) {
5166 + ia.ia_valid |= ATTR_MODE;
5167 + ia.ia_mode = h_isrc->i_mode;
5169 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5170 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5172 + /* no delegation since it is just created */
5173 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5175 + /* is this nfs only? */
5176 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5177 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5178 + ia.ia_mode = h_isrc->i_mode;
5179 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5182 + icex = br->br_perm & AuBrAttr_ICEX;
5184 + mnt_flags = au_mntflags(dst->d_sb);
5185 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5186 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5192 +/* ---------------------------------------------------------------------- */
5194 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5195 + char *buf, unsigned long blksize)
5198 + size_t sz, rbytes, wbytes;
5199 + unsigned char all_zero;
5201 + struct inode *h_inode;
5202 + /* reduce stack usage */
5205 + zp = page_address(ZERO_PAGE(0));
5206 + if (unlikely(!zp))
5207 + return -ENOMEM; /* possible? */
5212 + AuDbg("len %lld\n", len);
5214 + if (len < blksize)
5218 + /* todo: signal_pending? */
5219 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5220 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5223 + if (unlikely(err < 0))
5227 + if (len >= rbytes && rbytes == blksize)
5228 + all_zero = !memcmp(buf, zp, rbytes);
5235 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5237 + /* todo: signal_pending? */
5238 + if (unlikely(err == -EAGAIN || err == -EINTR))
5240 + if (unlikely(err < 0))
5245 + if (unlikely(err < 0))
5251 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5253 + if (unlikely(res < 0))
5260 + /* the last block may be a hole */
5261 + if (!err && all_zero) {
5262 + AuLabel(last hole);
5265 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5266 + /* nfs requires this step to make last hole */
5267 + /* is this only nfs? */
5269 + /* todo: signal_pending? */
5270 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5271 + } while (err == -EAGAIN || err == -EINTR);
5278 + ia->ia_size = dst->f_pos;
5279 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5280 + ia->ia_file = dst;
5281 + h_inode = file_inode(dst);
5282 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5283 + /* no delegation since it is just created */
5284 + err = vfsub_notify_change(&dst->f_path, ia,
5285 + /*delegated*/NULL);
5286 + inode_unlock(h_inode);
5293 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5296 + unsigned long blksize;
5297 + unsigned char do_kfree;
5299 + struct super_block *h_sb;
5302 + h_sb = file_inode(dst)->i_sb;
5303 + blksize = h_sb->s_blocksize;
5304 + if (!blksize || PAGE_SIZE < blksize)
5305 + blksize = PAGE_SIZE;
5306 + AuDbg("blksize %lu\n", blksize);
5307 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5309 + buf = kmalloc(blksize, GFP_NOFS);
5311 + buf = (void *)__get_free_page(GFP_NOFS);
5312 + if (unlikely(!buf))
5315 + if (len > (1 << 22))
5316 + AuDbg("copying a large file %lld\n", (long long)len);
5320 + err = au_do_copy_file(dst, src, len, buf, blksize);
5322 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5323 + au_kfree_do_rcu(buf);
5325 + free_page((unsigned long)buf);
5331 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5334 + struct super_block *h_src_sb;
5335 + struct inode *h_src_inode;
5337 + h_src_inode = file_inode(src);
5338 + h_src_sb = h_src_inode->i_sb;
5340 + /* XFS acquires inode_lock */
5341 + if (!au_test_xfs(h_src_sb))
5342 + err = au_copy_file(dst, src, len);
5344 + inode_unlock_shared(h_src_inode);
5345 + err = au_copy_file(dst, src, len);
5346 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5352 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5356 + struct super_block *h_src_sb;
5357 + struct inode *h_src_inode;
5359 + h_src_inode = file_inode(src);
5360 + h_src_sb = h_src_inode->i_sb;
5361 + if (h_src_sb != file_inode(dst)->i_sb
5362 + || !dst->f_op->remap_file_range) {
5363 + err = au_do_copy(dst, src, len);
5367 + if (!au_test_nfs(h_src_sb)) {
5368 + inode_unlock_shared(h_src_inode);
5369 + lo = vfsub_clone_file_range(src, dst, len);
5370 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5372 + lo = vfsub_clone_file_range(src, dst, len);
5375 + goto out; /* success */
5376 + } else if (lo >= 0)
5377 + /* todo: possible? */
5378 + /* paritially succeeded */
5379 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5380 + else if (lo != -EOPNOTSUPP) {
5381 + /* older XFS has a condition in cloning */
5386 + /* the backend fs on NFS may not support cloning */
5387 + err = au_do_copy(dst, src, len);
5395 + * to support a sparse file which is opened with O_APPEND,
5396 + * we need to close the file.
5398 +static int au_cp_regular(struct au_cp_generic *cpg)
5401 + enum { SRC, DST };
5403 + aufs_bindex_t bindex;
5404 + unsigned int flags;
5405 + struct dentry *dentry;
5407 + struct file *file;
5410 + .bindex = cpg->bsrc,
5411 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5414 + .bindex = cpg->bdst,
5415 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5416 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5419 + struct au_branch *br;
5420 + struct super_block *sb, *h_src_sb;
5421 + struct inode *h_src_inode;
5422 + struct task_struct *tsk = current;
5424 + /* bsrc branch can be ro/rw. */
5425 + sb = cpg->dentry->d_sb;
5427 + for (i = 0; i < 2; i++, f++) {
5428 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5429 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5430 + /*file*/NULL, f->force_wr);
5431 + if (IS_ERR(f->file)) {
5432 + err = PTR_ERR(f->file);
5440 + /* try stopping to update while we copyup */
5441 + h_src_inode = d_inode(file[SRC].dentry);
5442 + h_src_sb = h_src_inode->i_sb;
5443 + if (!au_test_nfs(h_src_sb))
5444 + IMustLock(h_src_inode);
5445 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5447 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5448 + if (tsk->flags & PF_KTHREAD)
5449 + __fput_sync(file[DST].file);
5451 + /* it happened actually */
5452 + fput(file[DST].file);
5455 + * we have to call both since we don't know which place the file
5459 + flush_delayed_fput();
5461 + br = au_sbr(sb, file[DST].bindex);
5462 + au_lcnt_dec(&br->br_nfiles);
5465 + fput(file[SRC].file);
5466 + br = au_sbr(sb, file[SRC].bindex);
5467 + au_lcnt_dec(&br->br_nfiles);
5472 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5473 + struct au_cpup_reg_attr *h_src_attr)
5477 + struct path h_path;
5478 + struct inode *h_src_inode, *h_dst_inode;
5481 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5482 + l = i_size_read(h_src_inode);
5483 + if (cpg->len == -1 || l < cpg->len)
5486 + /* try stopping to update while we are referencing */
5487 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5488 + au_pin_hdir_unlock(cpg->pin);
5490 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5491 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5492 + h_src_attr->iflags = h_src_inode->i_flags;
5493 + if (!au_test_nfs(h_src_inode->i_sb))
5494 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5496 + inode_unlock_shared(h_src_inode);
5497 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5498 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5500 + if (unlikely(err)) {
5501 + inode_unlock_shared(h_src_inode);
5504 + h_src_attr->valid = 1;
5505 + if (!au_test_nfs(h_src_inode->i_sb)) {
5506 + err = au_cp_regular(cpg);
5507 + inode_unlock_shared(h_src_inode);
5509 + inode_unlock_shared(h_src_inode);
5510 + err = au_cp_regular(cpg);
5512 + rerr = au_pin_hdir_relock(cpg->pin);
5516 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5517 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5518 + h_dst_inode = d_inode(h_path.dentry);
5519 + spin_lock(&h_dst_inode->i_lock);
5520 + h_dst_inode->i_state |= I_LINKABLE;
5521 + spin_unlock(&h_dst_inode->i_lock);
5528 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5529 + struct inode *h_dir)
5532 + mm_segment_t old_fs;
5539 + sym.k = (void *)__get_free_page(GFP_NOFS);
5540 + if (unlikely(!sym.k))
5543 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5544 + old_fs = get_fs();
5545 + set_fs(KERNEL_DS);
5546 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5551 + sym.k[symlen] = 0;
5552 + err = vfsub_symlink(h_dir, h_path, sym.k);
5554 + free_page((unsigned long)sym.k);
5561 + * regardless 'acl' option, reset all ACL.
5562 + * All ACL will be copied up later from the original entry on the lower branch.
5564 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5567 + struct dentry *h_dentry;
5568 + struct inode *h_inode;
5570 + h_dentry = h_path->dentry;
5571 + h_inode = d_inode(h_dentry);
5572 + /* forget_all_cached_acls(h_inode)); */
5573 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5575 + if (err == -EOPNOTSUPP)
5578 + err = vfsub_acl_chmod(h_inode, mode);
5584 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5585 + struct inode *h_dir, struct path *h_path)
5588 + struct inode *dir, *inode;
5590 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5592 + if (err == -EOPNOTSUPP)
5594 + if (unlikely(err))
5598 + * strange behaviour from the users view,
5599 + * particularly setattr case
5601 + dir = d_inode(dst_parent);
5602 + if (au_ibtop(dir) == cpg->bdst)
5603 + au_cpup_attr_nlink(dir, /*force*/1);
5604 + inode = d_inode(cpg->dentry);
5605 + au_cpup_attr_nlink(inode, /*force*/1);
5611 +static noinline_for_stack
5612 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5613 + struct au_cpup_reg_attr *h_src_attr)
5617 + unsigned int mnt_flags;
5618 + unsigned char isdir, isreg, force;
5619 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5620 + struct au_dtime dt;
5621 + struct path h_path;
5622 + struct dentry *h_src, *h_dst, *h_parent;
5623 + struct inode *h_inode, *h_dir;
5624 + struct super_block *sb;
5626 + /* bsrc branch can be ro/rw. */
5627 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5628 + h_inode = d_inode(h_src);
5629 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5631 + /* try stopping to be referenced while we are creating */
5632 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5633 + if (au_ftest_cpup(cpg->flags, RENAME))
5634 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5635 + AUFS_WH_PFX_LEN));
5636 + h_parent = h_dst->d_parent; /* dir inode is locked */
5637 + h_dir = d_inode(h_parent);
5639 + AuDebugOn(h_parent != h_dst->d_parent);
5641 + sb = cpg->dentry->d_sb;
5642 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5644 + h_path.dentry = h_parent;
5645 + au_dtime_store(&dt, dst_parent, &h_path);
5647 + h_path.dentry = h_dst;
5651 + mode = h_inode->i_mode;
5652 + switch (mode & S_IFMT) {
5655 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5657 + err = au_do_cpup_regular(cpg, h_src_attr);
5661 + err = vfsub_mkdir(h_dir, &h_path, mode);
5663 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5666 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5670 + AuDebugOn(!capable(CAP_MKNOD));
5674 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5677 + AuIOErr("Unknown inode type 0%o\n", mode);
5681 + err = au_reset_acl(h_dir, &h_path, mode);
5683 + mnt_flags = au_mntflags(sb);
5684 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5686 + && au_opt_test(mnt_flags, XINO)
5687 + && (h_inode->i_nlink == 1
5688 + || (h_inode->i_state & I_LINKABLE))
5689 + /* todo: unnecessary? */
5690 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5691 + && cpg->bdst < cpg->bsrc
5692 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5693 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5694 + /* ignore this error */
5699 + force = !!cpg->len;
5700 + if (cpg->len == -1)
5701 + force = !!i_size_read(h_inode);
5703 + au_fhsm_wrote(sb, cpg->bdst, force);
5707 + au_dtime_revert(&dt);
5711 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5714 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5715 + struct inode *h_dir;
5716 + aufs_bindex_t bdst;
5718 + dentry = cpg->dentry;
5720 + h_dentry = au_h_dptr(dentry, bdst);
5721 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5723 + au_set_h_dptr(dentry, bdst, NULL);
5724 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5726 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5727 + au_set_h_dptr(dentry, bdst, h_dentry);
5730 + parent = dget_parent(dentry);
5731 + h_parent = au_h_dptr(parent, bdst);
5733 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5734 + if (IS_ERR(h_path->dentry))
5735 + err = PTR_ERR(h_path->dentry);
5737 + if (unlikely(err))
5740 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5741 + h_dir = d_inode(h_parent);
5743 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5744 + /* no delegation since it is just created */
5745 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5747 + dput(h_path->dentry);
5754 + * copyup the @dentry from @bsrc to @bdst.
5755 + * the caller must set the both of lower dentries.
5756 + * @len is for truncating when it is -1 copyup the entire file.
5757 + * in link/rename cases, @dst_parent may be different from the real one.
5758 + * basic->bsrc can be larger than basic->bdst.
5759 + * aufs doesn't touch the credential so
5760 + * security_inode_copy_up{,_xattr}() are unnecessary.
5762 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5765 + aufs_bindex_t old_ibtop;
5766 + unsigned char isdir, plink;
5767 + struct dentry *h_src, *h_dst, *h_parent;
5768 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5769 + struct super_block *sb;
5770 + struct au_branch *br;
5771 + /* to reduce stack size */
5773 + struct au_dtime dt;
5774 + struct path h_path;
5775 + struct au_cpup_reg_attr h_src_attr;
5779 + a = kmalloc(sizeof(*a), GFP_NOFS);
5782 + a->h_src_attr.valid = 0;
5784 + sb = cpg->dentry->d_sb;
5785 + br = au_sbr(sb, cpg->bdst);
5786 + a->h_path.mnt = au_br_mnt(br);
5787 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5788 + h_parent = h_dst->d_parent; /* dir inode is locked */
5789 + h_dir = d_inode(h_parent);
5792 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5793 + inode = d_inode(cpg->dentry);
5796 + dst_parent = dget_parent(cpg->dentry);
5800 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5801 + dst_inode = au_h_iptr(inode, cpg->bdst);
5803 + if (unlikely(!plink)) {
5805 + AuIOErr("hi%lu(i%lu) exists on b%d "
5806 + "but plink is disabled\n",
5807 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5811 + if (dst_inode->i_nlink) {
5812 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5814 + h_src = au_plink_lkup(inode, cpg->bdst);
5815 + err = PTR_ERR(h_src);
5816 + if (IS_ERR(h_src))
5818 + if (unlikely(d_is_negative(h_src))) {
5820 + AuIOErr("i%lu exists on b%d "
5821 + "but not pseudo-linked\n",
5822 + inode->i_ino, cpg->bdst);
5828 + a->h_path.dentry = h_parent;
5829 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5832 + a->h_path.dentry = h_dst;
5834 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5835 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5836 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5838 + au_dtime_revert(&a->dt);
5839 + if (unlikely(err == -EWOULDBLOCK)) {
5840 + pr_warn("cannot retry for NFSv4 delegation"
5841 + " for an internal link\n");
5847 + /* todo: cpup_wh_file? */
5849 + au_update_ibrange(inode, /*do_put_zero*/1);
5852 + isdir = S_ISDIR(inode->i_mode);
5853 + old_ibtop = au_ibtop(inode);
5854 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5855 + if (unlikely(err))
5857 + dst_inode = d_inode(h_dst);
5858 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5859 + /* todo: necessary? */
5860 + /* au_pin_hdir_unlock(cpg->pin); */
5862 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5863 + if (unlikely(err)) {
5864 + /* todo: necessary? */
5865 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5866 + inode_unlock(dst_inode);
5870 + if (cpg->bdst < old_ibtop) {
5871 + if (S_ISREG(inode->i_mode)) {
5872 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5873 + if (unlikely(err)) {
5874 + /* ignore an error */
5875 + /* au_pin_hdir_relock(cpg->pin); */
5876 + inode_unlock(dst_inode);
5880 + au_set_ibtop(inode, cpg->bdst);
5882 + au_set_ibbot(inode, cpg->bdst);
5883 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5884 + au_hi_flags(inode, isdir));
5886 + /* todo: necessary? */
5887 + /* err = au_pin_hdir_relock(cpg->pin); */
5888 + inode_unlock(dst_inode);
5889 + if (unlikely(err))
5892 + src_inode = d_inode(h_src);
5894 + && (src_inode->i_nlink > 1
5895 + || src_inode->i_state & I_LINKABLE)
5897 + au_plink_append(inode, cpg->bdst, h_dst);
5899 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5900 + a->h_path.dentry = h_dst;
5901 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5904 + goto out_parent; /* success */
5908 + a->h_path.dentry = h_parent;
5909 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5910 + a->h_path.dentry = h_dst;
5912 + if (d_is_positive(h_dst)) {
5914 + /* no delegation since it is just created */
5915 + rerr = vfsub_unlink(h_dir, &a->h_path,
5916 + /*delegated*/NULL, /*force*/0);
5918 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5920 + au_dtime_revert(&a->dt);
5922 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5932 +#if 0 /* reserved */
5933 +struct au_cpup_single_args {
5935 + struct au_cp_generic *cpg;
5936 + struct dentry *dst_parent;
5939 +static void au_call_cpup_single(void *args)
5941 + struct au_cpup_single_args *a = args;
5943 + au_pin_hdir_acquire_nest(a->cpg->pin);
5944 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5945 + au_pin_hdir_release(a->cpg->pin);
5950 + * prevent SIGXFSZ in copy-up.
5951 + * testing CAP_MKNOD is for generic fs,
5952 + * but CAP_FSETID is for xfs only, currently.
5954 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5957 + struct super_block *sb;
5958 + struct inode *h_dir;
5961 + sb = au_pinned_parent(pin)->d_sb;
5962 + if (!au_wkq_test()
5963 + && (!au_sbi(sb)->si_plink_maint_pid
5964 + || au_plink_maint(sb, AuLock_NOPLM))) {
5965 + switch (mode & S_IFMT) {
5967 + /* no condition about RLIMIT_FSIZE and the file size */
5972 + do_sio = !capable(CAP_MKNOD);
5976 + do_sio = ((mode & (S_ISUID | S_ISGID))
5977 + && !capable(CAP_FSETID));
5978 + /* this workaround may be removed in the future */
5980 + h_dir = au_pinned_h_dir(pin);
5981 + do_sio = h_dir->i_mode & S_ISVTX;
5988 +#if 0 /* reserved */
5989 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5992 + struct dentry *h_dentry;
5994 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5995 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5996 + err = au_cpup_single(cpg, dst_parent);
5998 + struct au_cpup_single_args args = {
6001 + .dst_parent = dst_parent
6003 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
6004 + if (unlikely(wkq_err))
6013 + * copyup the @dentry from the first active lower branch to @bdst,
6014 + * using au_cpup_single().
6016 +static int au_cpup_simple(struct au_cp_generic *cpg)
6019 + unsigned int flags_orig;
6020 + struct dentry *dentry;
6022 + AuDebugOn(cpg->bsrc < 0);
6024 + dentry = cpg->dentry;
6025 + DiMustWriteLock(dentry);
6027 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
6029 + flags_orig = cpg->flags;
6030 + au_fset_cpup(cpg->flags, RENAME);
6031 + err = au_cpup_single(cpg, NULL);
6032 + cpg->flags = flags_orig;
6034 + return 0; /* success */
6037 + au_set_h_dptr(dentry, cpg->bdst, NULL);
6038 + au_set_dbtop(dentry, cpg->bsrc);
6044 +struct au_cpup_simple_args {
6046 + struct au_cp_generic *cpg;
6049 +static void au_call_cpup_simple(void *args)
6051 + struct au_cpup_simple_args *a = args;
6053 + au_pin_hdir_acquire_nest(a->cpg->pin);
6054 + *a->errp = au_cpup_simple(a->cpg);
6055 + au_pin_hdir_release(a->cpg->pin);
6058 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
6061 + struct dentry *dentry, *parent;
6062 + struct file *h_file;
6063 + struct inode *h_dir;
6065 + dentry = cpg->dentry;
6067 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
6068 + AuDebugOn(cpg->bsrc < 0);
6069 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
6070 + err = PTR_ERR(h_file);
6071 + if (IS_ERR(h_file))
6075 + parent = dget_parent(dentry);
6076 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
6077 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
6078 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6079 + err = au_cpup_simple(cpg);
6081 + struct au_cpup_simple_args args = {
6085 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
6086 + if (unlikely(wkq_err))
6092 + au_h_open_post(dentry, cpg->bsrc, h_file);
6098 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
6100 + aufs_bindex_t bsrc, bbot;
6101 + struct dentry *dentry, *h_dentry;
6103 + if (cpg->bsrc < 0) {
6104 + dentry = cpg->dentry;
6105 + bbot = au_dbbot(dentry);
6106 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
6107 + h_dentry = au_h_dptr(dentry, bsrc);
6109 + AuDebugOn(d_is_negative(h_dentry));
6113 + AuDebugOn(bsrc > bbot);
6116 + AuDebugOn(cpg->bsrc <= cpg->bdst);
6117 + return au_do_sio_cpup_simple(cpg);
6120 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
6122 + AuDebugOn(cpg->bdst <= cpg->bsrc);
6123 + return au_do_sio_cpup_simple(cpg);
6126 +/* ---------------------------------------------------------------------- */
6129 + * copyup the deleted file for writing.
6131 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
6132 + struct file *file)
6135 + unsigned int flags_orig;
6136 + aufs_bindex_t bsrc_orig;
6137 + struct au_dinfo *dinfo;
6139 + struct au_hdentry *hd;
6140 + struct dentry *h_dentry;
6143 + dinfo = au_di(cpg->dentry);
6144 + AuRwMustWriteLock(&dinfo->di_rwsem);
6146 + bsrc_orig = cpg->bsrc;
6147 + cpg->bsrc = dinfo->di_btop;
6148 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
6149 + hdst.h_dentry = hdst.hd->hd_dentry;
6150 + hdst.hd->hd_dentry = wh_dentry;
6151 + dinfo->di_btop = cpg->bdst;
6153 + hsrc.h_dentry = NULL;
6155 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
6156 + hsrc.h_dentry = hsrc.hd->hd_dentry;
6157 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
6159 + flags_orig = cpg->flags;
6160 + cpg->flags = !AuCpup_DTIME;
6161 + err = au_cpup_single(cpg, /*h_parent*/NULL);
6162 + cpg->flags = flags_orig;
6165 + err = au_reopen_nondir(file);
6166 + hsrc.hd->hd_dentry = hsrc.h_dentry;
6168 + hdst.hd->hd_dentry = hdst.h_dentry;
6169 + dinfo->di_btop = cpg->bsrc;
6170 + cpg->bsrc = bsrc_orig;
6175 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6178 + aufs_bindex_t bdst;
6179 + struct au_dtime dt;
6180 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6181 + struct au_branch *br;
6182 + struct path h_path;
6184 + dentry = cpg->dentry;
6186 + br = au_sbr(dentry->d_sb, bdst);
6187 + parent = dget_parent(dentry);
6188 + h_parent = au_h_dptr(parent, bdst);
6189 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6190 + err = PTR_ERR(wh_dentry);
6191 + if (IS_ERR(wh_dentry))
6194 + h_path.dentry = h_parent;
6195 + h_path.mnt = au_br_mnt(br);
6196 + au_dtime_store(&dt, parent, &h_path);
6197 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6198 + if (unlikely(err))
6202 + h_path.dentry = wh_dentry;
6203 + if (!d_is_dir(wh_dentry)) {
6204 + /* no delegation since it is just created */
6205 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6206 + /*delegated*/NULL, /*force*/0);
6208 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6209 + if (unlikely(err)) {
6210 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6214 + au_dtime_revert(&dt);
6215 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6224 +struct au_cpup_wh_args {
6226 + struct au_cp_generic *cpg;
6227 + struct file *file;
6230 +static void au_call_cpup_wh(void *args)
6232 + struct au_cpup_wh_args *a = args;
6234 + au_pin_hdir_acquire_nest(a->cpg->pin);
6235 + *a->errp = au_cpup_wh(a->cpg, a->file);
6236 + au_pin_hdir_release(a->cpg->pin);
6239 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6242 + aufs_bindex_t bdst;
6243 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6244 + struct inode *dir, *h_dir, *h_tmpdir;
6245 + struct au_wbr *wbr;
6246 + struct au_pin wh_pin, *pin_orig;
6248 + dentry = cpg->dentry;
6250 + parent = dget_parent(dentry);
6251 + dir = d_inode(parent);
6254 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6257 + if (!h_dir->i_nlink) {
6258 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6259 + h_orph = wbr->wbr_orph;
6261 + h_parent = dget(au_h_dptr(parent, bdst));
6262 + au_set_h_dptr(parent, bdst, dget(h_orph));
6263 + h_tmpdir = d_inode(h_orph);
6264 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6266 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6267 + /* todo: au_h_open_pre()? */
6269 + pin_orig = cpg->pin;
6270 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6271 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6272 + cpg->pin = &wh_pin;
6275 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6276 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6277 + err = au_cpup_wh(cpg, file);
6279 + struct au_cpup_wh_args args = {
6284 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6285 + if (unlikely(wkq_err))
6290 + inode_unlock(h_tmpdir);
6291 + /* todo: au_h_open_post()? */
6292 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6293 + au_set_h_dptr(parent, bdst, h_parent);
6294 + AuDebugOn(!pin_orig);
6295 + cpg->pin = pin_orig;
6303 +/* ---------------------------------------------------------------------- */
6306 + * generic routine for both of copy-up and copy-down.
6308 +/* cf. revalidate function in file.c */
6309 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6310 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6311 + struct au_pin *pin,
6312 + struct dentry *h_parent, void *arg),
6316 + struct au_pin pin;
6317 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6320 + parent = dget_parent(dentry);
6321 + if (IS_ROOT(parent))
6324 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6325 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6327 + /* do not use au_dpage */
6328 + real_parent = parent;
6331 + parent = dget_parent(dentry);
6332 + h_parent = au_h_dptr(parent, bdst);
6334 + goto out; /* success */
6336 + /* find top dir which is necessary to cpup */
6340 + parent = dget_parent(d);
6341 + di_read_lock_parent3(parent, !AuLock_IR);
6342 + h_parent = au_h_dptr(parent, bdst);
6343 + di_read_unlock(parent, !AuLock_IR);
6344 + } while (!h_parent);
6346 + if (d != real_parent)
6347 + di_write_lock_child3(d);
6349 + /* somebody else might create while we were sleeping */
6350 + h_dentry = au_h_dptr(d, bdst);
6351 + if (!h_dentry || d_is_negative(h_dentry)) {
6353 + au_update_dbtop(d);
6355 + au_pin_set_dentry(&pin, d);
6356 + err = au_do_pin(&pin);
6358 + err = cp(d, bdst, &pin, h_parent, arg);
6363 + if (d != real_parent)
6364 + di_write_unlock(d);
6365 + if (unlikely(err))
6374 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6375 + struct au_pin *pin,
6376 + struct dentry *h_parent __maybe_unused,
6377 + void *arg __maybe_unused)
6379 + struct au_cp_generic cpg = {
6385 + .flags = AuCpup_DTIME
6387 + return au_sio_cpup_simple(&cpg);
6390 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6392 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6395 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6398 + struct dentry *parent;
6399 + struct inode *dir;
6401 + parent = dget_parent(dentry);
6402 + dir = d_inode(parent);
6404 + if (au_h_iptr(dir, bdst))
6407 + di_read_unlock(parent, AuLock_IR);
6408 + di_write_lock_parent(parent);
6409 + /* someone else might change our inode while we were sleeping */
6410 + if (!au_h_iptr(dir, bdst))
6411 + err = au_cpup_dirs(dentry, bdst);
6412 + di_downgrade_lock(parent, AuLock_IR);
6418 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6419 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6420 +++ linux/fs/aufs/cpup.h 2018-08-12 23:43:05.453457863 +0200
6422 +/* SPDX-License-Identifier: GPL-2.0 */
6424 + * Copyright (C) 2005-2018 Junjiro R. Okajima
6426 + * This program, aufs is free software; you can redistribute it and/or modify
6427 + * it under the terms of the GNU General Public License as published by
6428 + * the Free Software Foundation; either version 2 of the License, or
6429 + * (at your option) any later version.
6431 + * This program is distributed in the hope that it will be useful,
6432 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6433 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6434 + * GNU General Public License for more details.
6436 + * You should have received a copy of the GNU General Public License
6437 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6441 + * copy-up/down functions
6444 +#ifndef __AUFS_CPUP_H__
6445 +#define __AUFS_CPUP_H__
6449 +#include <linux/path.h>
6455 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6456 +void au_cpup_attr_timesizes(struct inode *inode);
6457 +void au_cpup_attr_nlink(struct inode *inode, int force);
6458 +void au_cpup_attr_changeable(struct inode *inode);
6459 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6460 +void au_cpup_attr_all(struct inode *inode, int force);
6462 +/* ---------------------------------------------------------------------- */
6464 +struct au_cp_generic {
6465 + struct dentry *dentry;
6466 + aufs_bindex_t bdst, bsrc;
6468 + struct au_pin *pin;
6469 + unsigned int flags;
6473 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6474 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6476 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6477 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6479 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6481 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6482 + the branch is marked as RO */
6484 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6485 +#undef AuCpup_HOPEN
6486 +#define AuCpup_HOPEN 0
6489 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6490 +#define au_fset_cpup(flags, name) \
6491 + do { (flags) |= AuCpup_##name; } while (0)
6492 +#define au_fclr_cpup(flags, name) \
6493 + do { (flags) &= ~AuCpup_##name; } while (0)
6495 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6496 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6497 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6498 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6500 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6501 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6502 + struct au_pin *pin,
6503 + struct dentry *h_parent, void *arg),
6505 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6506 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6508 +/* ---------------------------------------------------------------------- */
6510 +/* keep timestamps when copyup */
6512 + struct dentry *dt_dentry;
6513 + struct path dt_h_path;
6514 + struct timespec64 dt_atime, dt_mtime;
6516 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6517 + struct path *h_path);
6518 +void au_dtime_revert(struct au_dtime *dt);
6520 +#endif /* __KERNEL__ */
6521 +#endif /* __AUFS_CPUP_H__ */
6522 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6523 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6524 +++ linux/fs/aufs/dbgaufs.c 2018-12-27 13:19:17.708416053 +0100
6526 +// SPDX-License-Identifier: GPL-2.0
6528 + * Copyright (C) 2005-2018 Junjiro R. Okajima
6530 + * This program, aufs is free software; you can redistribute it and/or modify
6531 + * it under the terms of the GNU General Public License as published by
6532 + * the Free Software Foundation; either version 2 of the License, or
6533 + * (at your option) any later version.
6535 + * This program is distributed in the hope that it will be useful,
6536 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6537 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6538 + * GNU General Public License for more details.
6540 + * You should have received a copy of the GNU General Public License
6541 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6545 + * debugfs interface
6548 +#include <linux/debugfs.h>
6551 +#ifndef CONFIG_SYSFS
6552 +#error DEBUG_FS depends upon SYSFS
6555 +static struct dentry *dbgaufs;
6556 +static const mode_t dbgaufs_mode = 0444;
6558 +/* 20 is max digits length of ulong 64 */
6559 +struct dbgaufs_arg {
6565 + * common function for all XINO files
6567 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6568 + struct file *file)
6572 + p = file->private_data;
6574 + /* this is struct dbgaufs_arg */
6575 + AuDebugOn(!au_kfree_sz_test(p));
6576 + au_kfree_do_rcu(p);
6581 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6586 + struct dbgaufs_arg *p;
6589 + p = kmalloc(sizeof(*p), GFP_NOFS);
6595 + file->private_data = p;
6599 + err = vfsub_getattr(&xf->f_path, &st);
6603 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6604 + cnt, st.blocks, st.blksize,
6605 + (long long)st.size);
6607 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6608 + st.blocks, st.blksize,
6609 + (long long)st.size);
6610 + AuDebugOn(p->n >= sizeof(p->a));
6612 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6620 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6621 + size_t count, loff_t *ppos)
6623 + struct dbgaufs_arg *p;
6625 + p = file->private_data;
6626 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6629 +/* ---------------------------------------------------------------------- */
6631 +struct dbgaufs_plink_arg {
6636 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6637 + struct file *file)
6639 + free_page((unsigned long)file->private_data);
6643 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6645 + int err, i, limit;
6646 + unsigned long n, sum;
6647 + struct dbgaufs_plink_arg *p;
6648 + struct au_sbinfo *sbinfo;
6649 + struct super_block *sb;
6650 + struct hlist_bl_head *hbl;
6653 + p = (void *)get_zeroed_page(GFP_NOFS);
6658 + sbinfo = inode->i_private;
6659 + sb = sbinfo->si_sb;
6660 + si_noflush_read_lock(sb);
6661 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6662 + limit = PAGE_SIZE - sizeof(p->n);
6664 + /* the number of buckets */
6665 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6670 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6672 + n = au_hbl_count(hbl);
6675 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6678 + if (unlikely(limit <= 0))
6681 + p->a[p->n - 1] = '\n';
6683 + /* the sum of plinks */
6684 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6687 + if (unlikely(limit <= 0))
6690 +#define str "1\n0\n0\n"
6691 + p->n = sizeof(str) - 1;
6692 + strcpy(p->a, str);
6695 + si_read_unlock(sb);
6698 + file->private_data = p;
6699 + goto out; /* success */
6702 + free_page((unsigned long)p);
6707 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6708 + size_t count, loff_t *ppos)
6710 + struct dbgaufs_plink_arg *p;
6712 + p = file->private_data;
6713 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6716 +static const struct file_operations dbgaufs_plink_fop = {
6717 + .owner = THIS_MODULE,
6718 + .open = dbgaufs_plink_open,
6719 + .release = dbgaufs_plink_release,
6720 + .read = dbgaufs_plink_read
6723 +/* ---------------------------------------------------------------------- */
6725 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6728 + struct au_sbinfo *sbinfo;
6729 + struct super_block *sb;
6731 + sbinfo = inode->i_private;
6732 + sb = sbinfo->si_sb;
6733 + si_noflush_read_lock(sb);
6734 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6735 + si_read_unlock(sb);
6739 +static const struct file_operations dbgaufs_xib_fop = {
6740 + .owner = THIS_MODULE,
6741 + .open = dbgaufs_xib_open,
6742 + .release = dbgaufs_xi_release,
6743 + .read = dbgaufs_xi_read
6746 +/* ---------------------------------------------------------------------- */
6748 +#define DbgaufsXi_PREFIX "xi"
6750 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6754 + aufs_bindex_t bindex;
6755 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6756 + struct au_sbinfo *sbinfo;
6757 + struct super_block *sb;
6758 + struct au_xino *xi;
6760 + struct qstr *name;
6761 + struct au_branch *br;
6764 + name = &file->f_path.dentry->d_name;
6765 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6766 + || memcmp(name->name, DbgaufsXi_PREFIX,
6767 + sizeof(DbgaufsXi_PREFIX) - 1)))
6770 + AuDebugOn(name->len >= sizeof(a));
6771 + memcpy(a, name->name, name->len);
6772 + a[name->len] = '\0';
6773 + p = strchr(a, '-');
6776 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6777 + if (unlikely(err))
6782 + err = kstrtol(p + 1, 10, &l);
6783 + if (unlikely(err))
6789 + sbinfo = inode->i_private;
6790 + sb = sbinfo->si_sb;
6791 + si_noflush_read_lock(sb);
6792 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6794 + br = au_sbr(sb, bindex);
6796 + if (unlikely(idx >= xi->xi_nfile))
6798 + xf = au_xino_file(xi, idx);
6800 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6801 + au_xino_count(br));
6804 + si_read_unlock(sb);
6810 +static const struct file_operations dbgaufs_xino_fop = {
6811 + .owner = THIS_MODULE,
6812 + .open = dbgaufs_xino_open,
6813 + .release = dbgaufs_xi_release,
6814 + .read = dbgaufs_xi_read
6817 +void dbgaufs_xino_del(struct au_branch *br)
6819 + struct dentry *dbgaufs;
6821 + dbgaufs = br->br_dbgaufs;
6825 + br->br_dbgaufs = NULL;
6826 + /* debugfs acquires the parent i_mutex */
6828 + debugfs_remove(dbgaufs);
6832 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6834 + aufs_bindex_t bbot;
6835 + struct au_branch *br;
6837 + if (!au_sbi(sb)->si_dbgaufs)
6840 + bbot = au_sbbot(sb);
6841 + for (; bindex <= bbot; bindex++) {
6842 + br = au_sbr(sb, bindex);
6843 + dbgaufs_xino_del(br);
6847 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6848 + unsigned int idx, struct dentry *parent,
6849 + struct au_sbinfo *sbinfo)
6851 + struct au_branch *br;
6853 + /* "xi" bindex(5) "-" idx(2) NULL */
6854 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6857 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6859 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6861 + br = au_sbr(sb, bindex);
6862 + if (br->br_dbgaufs) {
6863 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6865 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6866 + /* debugfs acquires the parent i_mutex */
6868 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6872 + pr_warn("failed renaming %pd/%s, ignored.\n",
6877 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6878 + sbinfo, &dbgaufs_xino_fop);
6880 + if (unlikely(!br->br_dbgaufs))
6881 + pr_warn("failed creating %pd/%s, ignored.\n",
6886 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6887 + struct dentry *parent, struct au_sbinfo *sbinfo)
6889 + struct au_branch *br;
6890 + struct au_xino *xi;
6893 + br = au_sbr(sb, bindex);
6895 + for (u = 0; u < xi->xi_nfile; u++)
6896 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6899 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6901 + struct au_sbinfo *sbinfo;
6902 + struct dentry *parent;
6903 + aufs_bindex_t bbot;
6905 + if (!au_opt_test(au_mntflags(sb), XINO))
6908 + sbinfo = au_sbi(sb);
6909 + parent = sbinfo->si_dbgaufs;
6913 + bbot = au_sbbot(sb);
6915 + for (; bindex <= bbot; bindex++)
6916 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6918 + for (; bbot >= bindex; bbot--)
6919 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6922 +/* ---------------------------------------------------------------------- */
6924 +#ifdef CONFIG_AUFS_EXPORT
6925 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6928 + struct au_sbinfo *sbinfo;
6929 + struct super_block *sb;
6931 + sbinfo = inode->i_private;
6932 + sb = sbinfo->si_sb;
6933 + si_noflush_read_lock(sb);
6934 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6935 + si_read_unlock(sb);
6939 +static const struct file_operations dbgaufs_xigen_fop = {
6940 + .owner = THIS_MODULE,
6941 + .open = dbgaufs_xigen_open,
6942 + .release = dbgaufs_xi_release,
6943 + .read = dbgaufs_xi_read
6946 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6951 + * This function is a dynamic '__init' function actually,
6952 + * so the tiny check for si_rwsem is unnecessary.
6954 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6957 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6958 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6959 + &dbgaufs_xigen_fop);
6960 + if (sbinfo->si_dbgaufs_xigen)
6966 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6970 +#endif /* CONFIG_AUFS_EXPORT */
6972 +/* ---------------------------------------------------------------------- */
6974 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6977 + * This function is a dynamic '__fin' function actually,
6978 + * so the tiny check for si_rwsem is unnecessary.
6980 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6982 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6983 + sbinfo->si_dbgaufs = NULL;
6986 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6989 + char name[SysaufsSiNameLen];
6992 + * This function is a dynamic '__init' function actually,
6993 + * so the tiny check for si_rwsem is unnecessary.
6995 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6999 + AuErr1("/debug/aufs is uninitialized\n");
7004 + sysaufs_name(sbinfo, name);
7005 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
7006 + if (unlikely(!sbinfo->si_dbgaufs))
7009 + /* regardless plink/noplink option */
7010 + sbinfo->si_dbgaufs_plink = debugfs_create_file
7011 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
7012 + &dbgaufs_plink_fop);
7013 + if (unlikely(!sbinfo->si_dbgaufs_plink))
7016 + /* regardless xino/noxino option */
7017 + sbinfo->si_dbgaufs_xib = debugfs_create_file
7018 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
7019 + &dbgaufs_xib_fop);
7020 + if (unlikely(!sbinfo->si_dbgaufs_xib))
7023 + err = dbgaufs_xigen_init(sbinfo);
7025 + goto out; /* success */
7028 + dbgaufs_si_fin(sbinfo);
7030 + if (unlikely(err))
7031 + pr_err("debugfs/aufs failed\n");
7035 +/* ---------------------------------------------------------------------- */
7037 +void dbgaufs_fin(void)
7039 + debugfs_remove(dbgaufs);
7042 +int __init dbgaufs_init(void)
7047 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
7052 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
7053 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
7054 +++ linux/fs/aufs/dbgaufs.h 2018-08-12 23:43:05.453457863 +0200
7056 +/* SPDX-License-Identifier: GPL-2.0 */
7058 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7060 + * This program, aufs is free software; you can redistribute it and/or modify
7061 + * it under the terms of the GNU General Public License as published by
7062 + * the Free Software Foundation; either version 2 of the License, or
7063 + * (at your option) any later version.
7065 + * This program is distributed in the hope that it will be useful,
7066 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7067 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7068 + * GNU General Public License for more details.
7070 + * You should have received a copy of the GNU General Public License
7071 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7075 + * debugfs interface
7078 +#ifndef __DBGAUFS_H__
7079 +#define __DBGAUFS_H__
7083 +struct super_block;
7087 +#ifdef CONFIG_DEBUG_FS
7089 +void dbgaufs_xino_del(struct au_branch *br);
7090 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
7091 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
7092 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
7093 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
7094 +void dbgaufs_fin(void);
7095 +int __init dbgaufs_init(void);
7097 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
7098 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
7099 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
7101 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
7102 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
7103 +AuStubVoid(dbgaufs_fin, void)
7104 +AuStubInt0(__init dbgaufs_init, void)
7105 +#endif /* CONFIG_DEBUG_FS */
7107 +#endif /* __KERNEL__ */
7108 +#endif /* __DBGAUFS_H__ */
7109 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
7110 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
7111 +++ linux/fs/aufs/dcsub.c 2018-12-27 13:19:17.708416053 +0100
7113 +// SPDX-License-Identifier: GPL-2.0
7115 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7117 + * This program, aufs is free software; you can redistribute it and/or modify
7118 + * it under the terms of the GNU General Public License as published by
7119 + * the Free Software Foundation; either version 2 of the License, or
7120 + * (at your option) any later version.
7122 + * This program is distributed in the hope that it will be useful,
7123 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7124 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7125 + * GNU General Public License for more details.
7127 + * You should have received a copy of the GNU General Public License
7128 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7132 + * sub-routines for dentry cache
7137 +static void au_dpage_free(struct au_dpage *dpage)
7140 + struct dentry **p;
7142 + p = dpage->dentries;
7143 + for (i = 0; i < dpage->ndentry; i++)
7145 + free_page((unsigned long)dpage->dentries);
7148 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
7154 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
7155 + if (unlikely(!dpages->dpages))
7158 + p = (void *)__get_free_page(gfp);
7162 + dpages->dpages[0].ndentry = 0;
7163 + dpages->dpages[0].dentries = p;
7164 + dpages->ndpage = 1;
7165 + return 0; /* success */
7168 + au_kfree_try_rcu(dpages->dpages);
7173 +void au_dpages_free(struct au_dcsub_pages *dpages)
7176 + struct au_dpage *p;
7178 + p = dpages->dpages;
7179 + for (i = 0; i < dpages->ndpage; i++)
7180 + au_dpage_free(p++);
7181 + au_kfree_try_rcu(dpages->dpages);
7184 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7185 + struct dentry *dentry, gfp_t gfp)
7188 + struct au_dpage *dpage;
7191 + dpage = dpages->dpages + dpages->ndpage - 1;
7192 + sz = PAGE_SIZE / sizeof(dentry);
7193 + if (unlikely(dpage->ndentry >= sz)) {
7194 + AuLabel(new dpage);
7196 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7197 + p = au_kzrealloc(dpages->dpages, sz,
7198 + sz + sizeof(*dpages->dpages), gfp,
7203 + dpages->dpages = p;
7204 + dpage = dpages->dpages + dpages->ndpage;
7205 + p = (void *)__get_free_page(gfp);
7209 + dpage->ndentry = 0;
7210 + dpage->dentries = p;
7214 + AuDebugOn(au_dcount(dentry) <= 0);
7215 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7216 + return 0; /* success */
7222 +/* todo: BAD approach */
7223 +/* copied from linux/fs/dcache.c */
7231 +extern void d_walk(struct dentry *parent, void *data,
7232 + enum d_walk_ret (*enter)(void *, struct dentry *));
7234 +struct ac_dpages_arg {
7236 + struct au_dcsub_pages *dpages;
7237 + struct super_block *sb;
7238 + au_dpages_test test;
7242 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7244 + enum d_walk_ret ret;
7245 + struct ac_dpages_arg *arg = _arg;
7247 + ret = D_WALK_CONTINUE;
7248 + if (dentry->d_sb == arg->sb
7249 + && !IS_ROOT(dentry)
7250 + && au_dcount(dentry) > 0
7252 + && (!arg->test || arg->test(dentry, arg->arg))) {
7253 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7254 + if (unlikely(arg->err))
7255 + ret = D_WALK_QUIT;
7261 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7262 + au_dpages_test test, void *arg)
7264 + struct ac_dpages_arg args = {
7272 + d_walk(root, &args, au_call_dpages_append);
7277 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7278 + int do_include, au_dpages_test test, void *arg)
7283 + write_seqlock(&rename_lock);
7284 + spin_lock(&dentry->d_lock);
7286 + && au_dcount(dentry) > 0
7287 + && (!test || test(dentry, arg)))
7288 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7289 + spin_unlock(&dentry->d_lock);
7290 + if (unlikely(err))
7294 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7297 + while (!IS_ROOT(dentry)) {
7298 + dentry = dentry->d_parent; /* rename_lock is locked */
7299 + spin_lock(&dentry->d_lock);
7300 + if (au_dcount(dentry) > 0
7301 + && (!test || test(dentry, arg)))
7302 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7303 + spin_unlock(&dentry->d_lock);
7304 + if (unlikely(err))
7309 + write_sequnlock(&rename_lock);
7313 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7315 + return au_di(dentry) && dentry->d_sb == arg;
7318 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7319 + struct dentry *dentry, int do_include)
7321 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7322 + au_dcsub_dpages_aufs, dentry->d_sb);
7325 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7327 + struct path path[2] = {
7336 + return path_is_under(path + 0, path + 1);
7338 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7339 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7340 +++ linux/fs/aufs/dcsub.h 2018-08-12 23:43:05.453457863 +0200
7342 +/* SPDX-License-Identifier: GPL-2.0 */
7344 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7346 + * This program, aufs is free software; you can redistribute it and/or modify
7347 + * it under the terms of the GNU General Public License as published by
7348 + * the Free Software Foundation; either version 2 of the License, or
7349 + * (at your option) any later version.
7351 + * This program is distributed in the hope that it will be useful,
7352 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7353 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7354 + * GNU General Public License for more details.
7356 + * You should have received a copy of the GNU General Public License
7357 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7361 + * sub-routines for dentry cache
7364 +#ifndef __AUFS_DCSUB_H__
7365 +#define __AUFS_DCSUB_H__
7369 +#include <linux/dcache.h>
7370 +#include <linux/fs.h>
7374 + struct dentry **dentries;
7377 +struct au_dcsub_pages {
7379 + struct au_dpage *dpages;
7382 +/* ---------------------------------------------------------------------- */
7385 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7386 +void au_dpages_free(struct au_dcsub_pages *dpages);
7387 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7388 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7389 + au_dpages_test test, void *arg);
7390 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7391 + int do_include, au_dpages_test test, void *arg);
7392 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7393 + struct dentry *dentry, int do_include);
7394 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7396 +/* ---------------------------------------------------------------------- */
7399 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7400 + * include/linux/dcache.h. Try them (in the future).
7403 +static inline int au_d_hashed_positive(struct dentry *d)
7406 + struct inode *inode = d_inode(d);
7409 + if (unlikely(d_unhashed(d)
7410 + || d_is_negative(d)
7411 + || !inode->i_nlink))
7416 +static inline int au_d_linkable(struct dentry *d)
7419 + struct inode *inode = d_inode(d);
7421 + err = au_d_hashed_positive(d);
7423 + && d_is_positive(d)
7424 + && (inode->i_state & I_LINKABLE))
7429 +static inline int au_d_alive(struct dentry *d)
7432 + struct inode *inode;
7436 + err = au_d_hashed_positive(d);
7438 + inode = d_inode(d);
7439 + if (unlikely(d_unlinked(d)
7440 + || d_is_negative(d)
7441 + || !inode->i_nlink))
7447 +static inline int au_alive_dir(struct dentry *d)
7451 + err = au_d_alive(d);
7452 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7457 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7459 + return a->len == b->len
7460 + && !memcmp(a->name, b->name, a->len);
7465 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7467 + * the type of d_lockref.count became int, but the inlined function d_count()
7468 + * still returns unsigned int.
7469 + * I don't know why. Maybe it is for every d_count() users?
7470 + * Anyway au_dcount() lives on.
7472 +static inline int au_dcount(struct dentry *d)
7474 + return (int)d_count(d);
7477 +#endif /* __KERNEL__ */
7478 +#endif /* __AUFS_DCSUB_H__ */
7479 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7480 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7481 +++ linux/fs/aufs/debug.c 2018-12-27 13:19:17.708416053 +0100
7483 +// SPDX-License-Identifier: GPL-2.0
7485 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7487 + * This program, aufs is free software; you can redistribute it and/or modify
7488 + * it under the terms of the GNU General Public License as published by
7489 + * the Free Software Foundation; either version 2 of the License, or
7490 + * (at your option) any later version.
7492 + * This program is distributed in the hope that it will be useful,
7493 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7494 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7495 + * GNU General Public License for more details.
7497 + * You should have received a copy of the GNU General Public License
7498 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7502 + * debug print functions
7507 +/* Returns 0, or -errno. arg is in kp->arg. */
7508 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7512 + err = kstrtoint(val, 0, &n);
7522 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7523 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7528 + return sprintf(buffer, "%d", atomic_read(a));
7531 +static struct kernel_param_ops param_ops_atomic_t = {
7532 + .set = param_atomic_t_set,
7533 + .get = param_atomic_t_get
7534 + /* void (*free)(void *arg) */
7537 +atomic_t aufs_debug = ATOMIC_INIT(0);
7538 +MODULE_PARM_DESC(debug, "debug print");
7539 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7541 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7542 +char *au_plevel = KERN_DEBUG;
7543 +#define dpri(fmt, ...) do { \
7545 + && strcmp(au_plevel, KERN_DEBUG)) \
7546 + || au_debug_test()) \
7547 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7550 +/* ---------------------------------------------------------------------- */
7552 +void au_dpri_whlist(struct au_nhash *whlist)
7554 + unsigned long ul, n;
7555 + struct hlist_head *head;
7556 + struct au_vdir_wh *pos;
7558 + n = whlist->nh_num;
7559 + head = whlist->nh_head;
7560 + for (ul = 0; ul < n; ul++) {
7561 + hlist_for_each_entry(pos, head, wh_hash)
7562 + dpri("b%d, %.*s, %d\n",
7564 + pos->wh_str.len, pos->wh_str.name,
7570 +void au_dpri_vdir(struct au_vdir *vdir)
7573 + union au_vdir_deblk_p p;
7576 + if (!vdir || IS_ERR(vdir)) {
7577 + dpri("err %ld\n", PTR_ERR(vdir));
7581 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7582 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7583 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7584 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7585 + p.deblk = vdir->vd_deblk[ul];
7587 + dpri("[%lu]: %p\n", ul, o);
7591 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7592 + struct dentry *wh)
7597 + if (!inode || IS_ERR(inode)) {
7598 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7602 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7603 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7604 + && sizeof(inode->i_blocks) != sizeof(u64));
7606 + n = (void *)wh->d_name.name;
7607 + l = wh->d_name.len;
7610 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7611 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7613 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7614 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7615 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7616 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7617 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7618 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7619 + inode->i_generation,
7620 + l ? ", wh " : "", l, n);
7624 +void au_dpri_inode(struct inode *inode)
7626 + struct au_iinfo *iinfo;
7627 + struct au_hinode *hi;
7628 + aufs_bindex_t bindex;
7631 + err = do_pri_inode(-1, inode, -1, NULL);
7632 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7635 + iinfo = au_ii(inode);
7636 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7637 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7638 + if (iinfo->ii_btop < 0)
7641 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7642 + hi = au_hinode(iinfo, bindex);
7644 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7648 +void au_dpri_dalias(struct inode *inode)
7652 + spin_lock(&inode->i_lock);
7653 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7654 + au_dpri_dentry(d);
7655 + spin_unlock(&inode->i_lock);
7658 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7660 + struct dentry *wh = NULL;
7662 + struct inode *inode;
7663 + struct au_iinfo *iinfo;
7664 + struct au_hinode *hi;
7666 + if (!dentry || IS_ERR(dentry)) {
7667 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7670 + /* do not call dget_parent() here */
7671 + /* note: access d_xxx without d_lock */
7672 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7673 + bindex, dentry, dentry,
7674 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7675 + au_dcount(dentry), dentry->d_flags,
7676 + d_unhashed(dentry) ? "un" : "");
7679 + if (d_is_positive(dentry))
7680 + inode = d_inode(dentry);
7682 + && au_test_aufs(dentry->d_sb)
7684 + && !au_is_bad_inode(inode)) {
7685 + iinfo = au_ii(inode);
7686 + hi = au_hinode(iinfo, bindex);
7688 + wh = hi->hi_whdentry;
7690 + do_pri_inode(bindex, inode, hn, wh);
7694 +void au_dpri_dentry(struct dentry *dentry)
7696 + struct au_dinfo *dinfo;
7697 + aufs_bindex_t bindex;
7700 + err = do_pri_dentry(-1, dentry);
7701 + if (err || !au_test_aufs(dentry->d_sb))
7704 + dinfo = au_di(dentry);
7707 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7708 + dinfo->di_btop, dinfo->di_bbot,
7709 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7710 + dinfo->di_tmpfile);
7711 + if (dinfo->di_btop < 0)
7713 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7714 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7717 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7721 + if (!file || IS_ERR(file)) {
7722 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7727 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7728 + && au_test_aufs(file->f_path.dentry->d_sb)
7730 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7731 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7732 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7733 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7734 + file->f_version, file->f_pos, a);
7735 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7736 + do_pri_dentry(bindex, file->f_path.dentry);
7740 +void au_dpri_file(struct file *file)
7742 + struct au_finfo *finfo;
7743 + struct au_fidir *fidir;
7744 + struct au_hfile *hfile;
7745 + aufs_bindex_t bindex;
7748 + err = do_pri_file(-1, file);
7750 + || IS_ERR_OR_NULL(file->f_path.dentry)
7751 + || !au_test_aufs(file->f_path.dentry->d_sb))
7754 + finfo = au_fi(file);
7757 + if (finfo->fi_btop < 0)
7759 + fidir = finfo->fi_hdir;
7761 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7763 + for (bindex = finfo->fi_btop;
7764 + bindex >= 0 && bindex <= fidir->fd_bbot;
7766 + hfile = fidir->fd_hfile + bindex;
7767 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7771 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7773 + struct vfsmount *mnt;
7774 + struct super_block *sb;
7776 + if (!br || IS_ERR(br))
7778 + mnt = au_br_mnt(br);
7779 + if (!mnt || IS_ERR(mnt))
7782 + if (!sb || IS_ERR(sb))
7785 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7786 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7788 + bindex, br->br_perm, br->br_id, br->br_wbr,
7789 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7790 + sb->s_flags, sb->s_count,
7791 + atomic_read(&sb->s_active),
7792 + !!au_xino_file(br->br_xino, /*idx*/-1));
7796 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7800 +void au_dpri_sb(struct super_block *sb)
7802 + struct au_sbinfo *sbinfo;
7803 + aufs_bindex_t bindex;
7805 + /* to reduce stack size */
7807 + struct vfsmount mnt;
7808 + struct au_branch fake;
7811 + /* this function can be called from magic sysrq */
7812 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7813 + if (unlikely(!a)) {
7814 + dpri("no memory\n");
7818 + a->mnt.mnt_sb = sb;
7819 + a->fake.br_path.mnt = &a->mnt;
7820 + err = do_pri_br(-1, &a->fake);
7822 + dpri("dev 0x%x\n", sb->s_dev);
7823 + if (err || !au_test_aufs(sb))
7826 + sbinfo = au_sbi(sb);
7829 + dpri("nw %d, gen %u, kobj %d\n",
7830 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7831 + kref_read(&sbinfo->si_kobj.kref));
7832 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7833 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7836 +/* ---------------------------------------------------------------------- */
7838 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7840 + struct inode *h_inode, *inode = d_inode(dentry);
7841 + struct dentry *h_dentry;
7842 + aufs_bindex_t bindex, bbot, bi;
7844 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7847 + bbot = au_dbbot(dentry);
7848 + bi = au_ibbot(inode);
7851 + bindex = au_dbtop(dentry);
7852 + bi = au_ibtop(inode);
7856 + for (; bindex <= bbot; bindex++) {
7857 + h_dentry = au_h_dptr(dentry, bindex);
7860 + h_inode = au_h_iptr(inode, bindex);
7861 + if (unlikely(h_inode != d_inode(h_dentry))) {
7863 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7864 + AuDbgDentry(dentry);
7865 + AuDbgInode(inode);
7872 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7875 + struct au_dcsub_pages dpages;
7876 + struct au_dpage *dpage;
7877 + struct dentry **dentries;
7879 + err = au_dpages_init(&dpages, GFP_NOFS);
7881 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7883 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7884 + dpage = dpages.dpages + i;
7885 + dentries = dpage->dentries;
7886 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7887 + AuDebugOn(au_digen_test(dentries[j], sigen));
7889 + au_dpages_free(&dpages);
7892 +void au_dbg_verify_kthread(void)
7894 + if (au_wkq_test()) {
7897 + * It may be recursive, but udba=notify between two aufs mounts,
7898 + * where a single ro branch is shared, is not a problem.
7904 +/* ---------------------------------------------------------------------- */
7906 +int __init au_debug_init(void)
7908 + aufs_bindex_t bindex;
7909 + struct au_vdir_destr destr;
7912 + AuDebugOn(bindex >= 0);
7915 + AuDebugOn(destr.len < NAME_MAX);
7917 +#ifdef CONFIG_4KSTACKS
7918 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7923 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7924 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7925 +++ linux/fs/aufs/debug.h 2018-08-12 23:43:05.453457863 +0200
7927 +/* SPDX-License-Identifier: GPL-2.0 */
7929 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7931 + * This program, aufs is free software; you can redistribute it and/or modify
7932 + * it under the terms of the GNU General Public License as published by
7933 + * the Free Software Foundation; either version 2 of the License, or
7934 + * (at your option) any later version.
7936 + * This program is distributed in the hope that it will be useful,
7937 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7938 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7939 + * GNU General Public License for more details.
7941 + * You should have received a copy of the GNU General Public License
7942 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7946 + * debug print functions
7949 +#ifndef __AUFS_DEBUG_H__
7950 +#define __AUFS_DEBUG_H__
7954 +#include <linux/atomic.h>
7955 +#include <linux/module.h>
7956 +#include <linux/kallsyms.h>
7957 +#include <linux/sysrq.h>
7959 +#ifdef CONFIG_AUFS_DEBUG
7960 +#define AuDebugOn(a) BUG_ON(a)
7962 +/* module parameter */
7963 +extern atomic_t aufs_debug;
7964 +static inline void au_debug_on(void)
7966 + atomic_inc(&aufs_debug);
7968 +static inline void au_debug_off(void)
7970 + atomic_dec_if_positive(&aufs_debug);
7973 +static inline int au_debug_test(void)
7975 + return atomic_read(&aufs_debug) > 0;
7978 +#define AuDebugOn(a) do {} while (0)
7979 +AuStubVoid(au_debug_on, void)
7980 +AuStubVoid(au_debug_off, void)
7981 +AuStubInt0(au_debug_test, void)
7982 +#endif /* CONFIG_AUFS_DEBUG */
7984 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7986 +/* ---------------------------------------------------------------------- */
7990 +#define AuDbg(fmt, ...) do { \
7991 + if (au_debug_test()) \
7992 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7994 +#define AuLabel(l) AuDbg(#l "\n")
7995 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7996 +#define AuWarn1(fmt, ...) do { \
7997 + static unsigned char _c; \
7999 + pr_warn(fmt, ##__VA_ARGS__); \
8002 +#define AuErr1(fmt, ...) do { \
8003 + static unsigned char _c; \
8005 + pr_err(fmt, ##__VA_ARGS__); \
8008 +#define AuIOErr1(fmt, ...) do { \
8009 + static unsigned char _c; \
8011 + AuIOErr(fmt, ##__VA_ARGS__); \
8014 +#define AuUnsupportMsg "This operation is not supported." \
8015 + " Please report this application to aufs-users ML."
8016 +#define AuUnsupport(fmt, ...) do { \
8017 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
8021 +#define AuTraceErr(e) do { \
8022 + if (unlikely((e) < 0)) \
8023 + AuDbg("err %d\n", (int)(e)); \
8026 +#define AuTraceErrPtr(p) do { \
8028 + AuDbg("err %ld\n", PTR_ERR(p)); \
8031 +/* dirty macros for debug print, use with "%.*s" and caution */
8032 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
8034 +/* ---------------------------------------------------------------------- */
8037 +#ifdef CONFIG_AUFS_DEBUG
8038 +extern struct mutex au_dbg_mtx;
8039 +extern char *au_plevel;
8041 +void au_dpri_whlist(struct au_nhash *whlist);
8043 +void au_dpri_vdir(struct au_vdir *vdir);
8045 +void au_dpri_inode(struct inode *inode);
8046 +void au_dpri_dalias(struct inode *inode);
8047 +void au_dpri_dentry(struct dentry *dentry);
8049 +void au_dpri_file(struct file *filp);
8050 +struct super_block;
8051 +void au_dpri_sb(struct super_block *sb);
8053 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
8054 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
8055 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
8056 +void au_dbg_verify_kthread(void);
8058 +int __init au_debug_init(void);
8060 +#define AuDbgWhlist(w) do { \
8061 + mutex_lock(&au_dbg_mtx); \
8063 + au_dpri_whlist(w); \
8064 + mutex_unlock(&au_dbg_mtx); \
8067 +#define AuDbgVdir(v) do { \
8068 + mutex_lock(&au_dbg_mtx); \
8070 + au_dpri_vdir(v); \
8071 + mutex_unlock(&au_dbg_mtx); \
8074 +#define AuDbgInode(i) do { \
8075 + mutex_lock(&au_dbg_mtx); \
8077 + au_dpri_inode(i); \
8078 + mutex_unlock(&au_dbg_mtx); \
8081 +#define AuDbgDAlias(i) do { \
8082 + mutex_lock(&au_dbg_mtx); \
8084 + au_dpri_dalias(i); \
8085 + mutex_unlock(&au_dbg_mtx); \
8088 +#define AuDbgDentry(d) do { \
8089 + mutex_lock(&au_dbg_mtx); \
8091 + au_dpri_dentry(d); \
8092 + mutex_unlock(&au_dbg_mtx); \
8095 +#define AuDbgFile(f) do { \
8096 + mutex_lock(&au_dbg_mtx); \
8098 + au_dpri_file(f); \
8099 + mutex_unlock(&au_dbg_mtx); \
8102 +#define AuDbgSb(sb) do { \
8103 + mutex_lock(&au_dbg_mtx); \
8104 + AuDbg(#sb "\n"); \
8106 + mutex_unlock(&au_dbg_mtx); \
8109 +#define AuDbgSym(addr) do { \
8110 + char sym[KSYM_SYMBOL_LEN]; \
8111 + sprint_symbol(sym, (unsigned long)addr); \
8112 + AuDbg("%s\n", sym); \
8115 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
8116 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
8117 +AuStubVoid(au_dbg_verify_kthread, void)
8118 +AuStubInt0(__init au_debug_init, void)
8120 +#define AuDbgWhlist(w) do {} while (0)
8121 +#define AuDbgVdir(v) do {} while (0)
8122 +#define AuDbgInode(i) do {} while (0)
8123 +#define AuDbgDAlias(i) do {} while (0)
8124 +#define AuDbgDentry(d) do {} while (0)
8125 +#define AuDbgFile(f) do {} while (0)
8126 +#define AuDbgSb(sb) do {} while (0)
8127 +#define AuDbgSym(addr) do {} while (0)
8128 +#endif /* CONFIG_AUFS_DEBUG */
8130 +/* ---------------------------------------------------------------------- */
8132 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
8133 +int __init au_sysrq_init(void);
8134 +void au_sysrq_fin(void);
8136 +#ifdef CONFIG_HW_CONSOLE
8137 +#define au_dbg_blocked() do { \
8139 + handle_sysrq('w'); \
8142 +AuStubVoid(au_dbg_blocked, void)
8146 +AuStubInt0(__init au_sysrq_init, void)
8147 +AuStubVoid(au_sysrq_fin, void)
8148 +AuStubVoid(au_dbg_blocked, void)
8149 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
8151 +#endif /* __KERNEL__ */
8152 +#endif /* __AUFS_DEBUG_H__ */
8153 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
8154 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
8155 +++ linux/fs/aufs/dentry.c 2018-12-27 13:19:17.708416053 +0100
8157 +// SPDX-License-Identifier: GPL-2.0
8159 + * Copyright (C) 2005-2018 Junjiro R. Okajima
8161 + * This program, aufs is free software; you can redistribute it and/or modify
8162 + * it under the terms of the GNU General Public License as published by
8163 + * the Free Software Foundation; either version 2 of the License, or
8164 + * (at your option) any later version.
8166 + * This program is distributed in the hope that it will be useful,
8167 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8168 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8169 + * GNU General Public License for more details.
8171 + * You should have received a copy of the GNU General Public License
8172 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8176 + * lookup and dentry operations
8179 +#include <linux/namei.h>
8183 + * returns positive/negative dentry, NULL or an error.
8184 + * NULL means whiteout-ed or not-found.
8186 +static struct dentry*
8187 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8188 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8190 + struct dentry *h_dentry;
8191 + struct inode *h_inode;
8192 + struct au_branch *br;
8193 + int wh_found, opq;
8194 + unsigned char wh_able;
8195 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8196 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8200 + br = au_sbr(dentry->d_sb, bindex);
8201 + wh_able = !!au_br_whable(br->br_perm);
8203 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8204 + h_dentry = ERR_PTR(wh_found);
8207 + if (unlikely(wh_found < 0))
8210 + /* We found a whiteout */
8211 + /* au_set_dbbot(dentry, bindex); */
8212 + au_set_dbwh(dentry, bindex);
8214 + return NULL; /* success */
8218 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8220 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8221 + if (IS_ERR(h_dentry)) {
8222 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8228 + h_inode = d_inode(h_dentry);
8229 + if (d_is_negative(h_dentry)) {
8232 + } else if (wh_found
8233 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8235 + else if (au_ftest_lkup(args->flags, DIRREN)
8237 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8238 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8239 + (unsigned long long)h_inode->i_ino);
8243 + if (au_dbbot(dentry) <= bindex)
8244 + au_set_dbbot(dentry, bindex);
8245 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8246 + au_set_dbtop(dentry, bindex);
8247 + au_set_h_dptr(dentry, bindex, h_dentry);
8249 + if (!d_is_dir(h_dentry)
8251 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8252 + goto out; /* success */
8254 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8255 + opq = au_diropq_test(h_dentry);
8256 + inode_unlock_shared(h_inode);
8258 + au_set_dbdiropq(dentry, bindex);
8259 + else if (unlikely(opq < 0)) {
8260 + au_set_h_dptr(dentry, bindex, NULL);
8261 + h_dentry = ERR_PTR(opq);
8272 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8274 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8275 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8281 + * returns the number of lower positive dentries,
8282 + * otherwise an error.
8283 + * can be called at unlinking with @type is zero.
8285 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8286 + unsigned int flags)
8288 + int npositive, err;
8289 + aufs_bindex_t bindex, btail, bdiropq;
8290 + unsigned char isdir, dirperm1, dirren;
8291 + struct au_do_lookup_args args = {
8293 + .name = &dentry->d_name
8295 + struct dentry *parent;
8296 + struct super_block *sb;
8298 + sb = dentry->d_sb;
8299 + err = au_test_shwh(sb, args.name);
8300 + if (unlikely(err))
8303 + err = au_wh_name_alloc(&args.whname, args.name);
8304 + if (unlikely(err))
8307 + isdir = !!d_is_dir(dentry);
8308 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8309 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8311 + au_fset_lkup(args.flags, DIRREN);
8314 + parent = dget_parent(dentry);
8315 + btail = au_dbtaildir(parent);
8316 + for (bindex = btop; bindex <= btail; bindex++) {
8317 + struct dentry *h_parent, *h_dentry;
8318 + struct inode *h_inode, *h_dir;
8319 + struct au_branch *br;
8321 + h_dentry = au_h_dptr(dentry, bindex);
8323 + if (d_is_positive(h_dentry))
8327 + h_parent = au_h_dptr(parent, bindex);
8328 + if (!h_parent || !d_is_dir(h_parent))
8332 + /* if the inum matches, then use the prepared name */
8333 + err = au_dr_lkup_name(&args, bindex);
8334 + if (unlikely(err))
8338 + h_dir = d_inode(h_parent);
8339 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8340 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8341 + inode_unlock_shared(h_dir);
8342 + err = PTR_ERR(h_dentry);
8343 + if (IS_ERR(h_dentry))
8346 + au_fclr_lkup(args.flags, ALLOW_NEG);
8348 + au_fset_lkup(args.flags, IGNORE_PERM);
8350 + if (au_dbwh(dentry) == bindex)
8354 + if (d_is_negative(h_dentry))
8356 + h_inode = d_inode(h_dentry);
8359 + args.type = h_inode->i_mode & S_IFMT;
8360 + if (args.type != S_IFDIR)
8363 + /* the type of lower may be different */
8364 + bdiropq = au_dbdiropq(dentry);
8365 + if (bdiropq >= 0 && bdiropq <= bindex)
8368 + br = au_sbr(sb, bindex);
8370 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8371 + /*add_ent*/NULL)) {
8372 + /* prepare next name to lookup */
8373 + err = au_dr_lkup(&args, dentry, bindex);
8374 + if (unlikely(err))
8380 + AuLabel(positive);
8381 + au_update_dbtop(dentry);
8384 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8385 + && au_dbtop(dentry) < 0)) {
8387 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8393 + au_kfree_try_rcu(args.whname.name);
8395 + au_dr_lkup_fin(&args);
8400 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8402 + struct dentry *dentry;
8405 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8406 + dentry = vfsub_lkup_one(name, parent);
8408 + struct vfsub_lkup_one_args args = {
8414 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8415 + if (unlikely(wkq_err))
8416 + dentry = ERR_PTR(wkq_err);
8423 + * lookup @dentry on @bindex which should be negative.
8425 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8428 + struct dentry *parent, *h_parent, *h_dentry;
8429 + struct au_branch *br;
8431 + parent = dget_parent(dentry);
8432 + h_parent = au_h_dptr(parent, bindex);
8433 + br = au_sbr(dentry->d_sb, bindex);
8435 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8437 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8438 + err = PTR_ERR(h_dentry);
8439 + if (IS_ERR(h_dentry))
8441 + if (unlikely(d_is_positive(h_dentry))) {
8443 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8449 + if (bindex < au_dbtop(dentry))
8450 + au_set_dbtop(dentry, bindex);
8451 + if (au_dbbot(dentry) < bindex)
8452 + au_set_dbbot(dentry, bindex);
8453 + au_set_h_dptr(dentry, bindex, h_dentry);
8460 +/* ---------------------------------------------------------------------- */
8462 +/* subset of struct inode */
8464 + unsigned long i_ino;
8465 + /* unsigned int i_nlink; */
8471 + blkcnt_t i_blocks;
8476 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8478 + ia->i_ino = h_inode->i_ino;
8479 + /* ia->i_nlink = h_inode->i_nlink; */
8480 + ia->i_uid = h_inode->i_uid;
8481 + ia->i_gid = h_inode->i_gid;
8482 + ia->i_version = inode_query_iversion(h_inode);
8484 + ia->i_size = h_inode->i_size;
8485 + ia->i_blocks = h_inode->i_blocks;
8487 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8490 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8492 + return ia->i_ino != h_inode->i_ino
8493 + /* || ia->i_nlink != h_inode->i_nlink */
8494 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8495 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8496 + || !inode_eq_iversion(h_inode, ia->i_version)
8498 + || ia->i_size != h_inode->i_size
8499 + || ia->i_blocks != h_inode->i_blocks
8501 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8504 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8505 + struct au_branch *br)
8508 + struct au_iattr ia;
8509 + struct inode *h_inode;
8510 + struct dentry *h_d;
8511 + struct super_block *h_sb;
8514 + memset(&ia, -1, sizeof(ia));
8515 + h_sb = h_dentry->d_sb;
8517 + if (d_is_positive(h_dentry)) {
8518 + h_inode = d_inode(h_dentry);
8519 + au_iattr_save(&ia, h_inode);
8520 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8521 + /* nfs d_revalidate may return 0 for negative dentry */
8522 + /* fuse d_revalidate always return 0 for negative dentry */
8525 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8526 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8527 + err = PTR_ERR(h_d);
8532 + if (unlikely(h_d != h_dentry
8533 + || d_inode(h_d) != h_inode
8534 + || (h_inode && au_iattr_test(&ia, h_inode))))
8535 + err = au_busy_or_stale();
8543 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8544 + struct dentry *h_parent, struct au_branch *br)
8549 + if (udba == AuOpt_UDBA_REVAL
8550 + && !au_test_fs_remote(h_dentry->d_sb)) {
8552 + err = (d_inode(h_dentry->d_parent) != h_dir);
8553 + } else if (udba != AuOpt_UDBA_NONE)
8554 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8559 +/* ---------------------------------------------------------------------- */
8561 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8564 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8565 + struct au_hdentry tmp, *p, *q;
8566 + struct au_dinfo *dinfo;
8567 + struct super_block *sb;
8569 + DiMustWriteLock(dentry);
8571 + sb = dentry->d_sb;
8572 + dinfo = au_di(dentry);
8573 + bbot = dinfo->di_bbot;
8574 + bwh = dinfo->di_bwh;
8575 + bdiropq = dinfo->di_bdiropq;
8576 + bindex = dinfo->di_btop;
8577 + p = au_hdentry(dinfo, bindex);
8578 + for (; bindex <= bbot; bindex++, p++) {
8579 + if (!p->hd_dentry)
8582 + new_bindex = au_br_index(sb, p->hd_id);
8583 + if (new_bindex == bindex)
8586 + if (dinfo->di_bwh == bindex)
8588 + if (dinfo->di_bdiropq == bindex)
8589 + bdiropq = new_bindex;
8590 + if (new_bindex < 0) {
8592 + p->hd_dentry = NULL;
8596 + /* swap two lower dentries, and loop again */
8597 + q = au_hdentry(dinfo, new_bindex);
8601 + if (tmp.hd_dentry) {
8607 + dinfo->di_bwh = -1;
8608 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8609 + dinfo->di_bwh = bwh;
8611 + dinfo->di_bdiropq = -1;
8613 + && bdiropq <= au_sbbot(sb)
8614 + && au_sbr_whable(sb, bdiropq))
8615 + dinfo->di_bdiropq = bdiropq;
8618 + dinfo->di_btop = -1;
8619 + dinfo->di_bbot = -1;
8620 + bbot = au_dbbot(parent);
8622 + p = au_hdentry(dinfo, bindex);
8623 + for (; bindex <= bbot; bindex++, p++)
8624 + if (p->hd_dentry) {
8625 + dinfo->di_btop = bindex;
8629 + if (dinfo->di_btop >= 0) {
8631 + p = au_hdentry(dinfo, bindex);
8632 + for (; bindex >= 0; bindex--, p--)
8633 + if (p->hd_dentry) {
8634 + dinfo->di_bbot = bindex;
8643 +static void au_do_hide(struct dentry *dentry)
8645 + struct inode *inode;
8647 + if (d_really_is_positive(dentry)) {
8648 + inode = d_inode(dentry);
8649 + if (!d_is_dir(dentry)) {
8650 + if (inode->i_nlink && !d_unhashed(dentry))
8651 + drop_nlink(inode);
8653 + clear_nlink(inode);
8654 + /* stop next lookup */
8655 + inode->i_flags |= S_DEAD;
8657 + smp_mb(); /* necessary? */
8662 +static int au_hide_children(struct dentry *parent)
8664 + int err, i, j, ndentry;
8665 + struct au_dcsub_pages dpages;
8666 + struct au_dpage *dpage;
8667 + struct dentry *dentry;
8669 + err = au_dpages_init(&dpages, GFP_NOFS);
8670 + if (unlikely(err))
8672 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8673 + if (unlikely(err))
8676 + /* in reverse order */
8677 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8678 + dpage = dpages.dpages + i;
8679 + ndentry = dpage->ndentry;
8680 + for (j = ndentry - 1; j >= 0; j--) {
8681 + dentry = dpage->dentries[j];
8682 + if (dentry != parent)
8683 + au_do_hide(dentry);
8688 + au_dpages_free(&dpages);
8693 +static void au_hide(struct dentry *dentry)
8697 + AuDbgDentry(dentry);
8698 + if (d_is_dir(dentry)) {
8699 + /* shrink_dcache_parent(dentry); */
8700 + err = au_hide_children(dentry);
8701 + if (unlikely(err))
8702 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8705 + au_do_hide(dentry);
8709 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8711 + * a dirty branch is added
8712 + * - on the top of layers
8713 + * - in the middle of layers
8714 + * - to the bottom of layers
8716 + * on the added branch there exists
8719 + * - a same named entry
8721 + * * negative --> positive
8722 + * * positive --> positive
8723 + * - type is unchanged
8724 + * - type is changed
8726 + * * negative --> negative
8727 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8730 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8731 + struct au_dinfo *tmp)
8734 + aufs_bindex_t bindex, bbot;
8736 + struct dentry *dentry;
8737 + struct inode *inode;
8739 + } orig_h, tmp_h = {
8742 + struct au_hdentry *hd;
8743 + struct inode *inode, *h_inode;
8744 + struct dentry *h_dentry;
8747 + AuDebugOn(dinfo->di_btop < 0);
8749 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8750 + orig_h.inode = NULL;
8751 + if (d_is_positive(orig_h.dentry)) {
8752 + orig_h.inode = d_inode(orig_h.dentry);
8753 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8755 + if (tmp->di_btop >= 0) {
8756 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8757 + if (d_is_positive(tmp_h.dentry)) {
8758 + tmp_h.inode = d_inode(tmp_h.dentry);
8759 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8764 + if (d_really_is_positive(dentry))
8765 + inode = d_inode(dentry);
8766 + if (!orig_h.inode) {
8767 + AuDbg("negative originally\n");
8773 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8774 + AuDebugOn(dinfo->di_bdiropq != -1);
8776 + if (!tmp_h.inode) {
8777 + AuDbg("negative --> negative\n");
8778 + /* should have only one negative lower */
8779 + if (tmp->di_btop >= 0
8780 + && tmp->di_btop < dinfo->di_btop) {
8781 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8782 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8783 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8784 + au_di_cp(dinfo, tmp);
8785 + hd = au_hdentry(tmp, tmp->di_btop);
8786 + au_set_h_dptr(dentry, tmp->di_btop,
8787 + dget(hd->hd_dentry));
8789 + au_dbg_verify_dinode(dentry);
8791 + AuDbg("negative --> positive\n");
8793 + * similar to the behaviour of creating with bypassing
8795 + * unhash it in order to force an error in the
8796 + * succeeding create operation.
8797 + * we should not set S_DEAD here.
8800 + /* au_di_swap(tmp, dinfo); */
8801 + au_dbg_verify_dinode(dentry);
8804 + AuDbg("positive originally\n");
8805 + /* inode may be NULL */
8806 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8807 + if (!tmp_h.inode) {
8808 + AuDbg("positive --> negative\n");
8809 + /* or bypassing aufs */
8811 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8812 + dinfo->di_bwh = tmp->di_bwh;
8814 + err = au_refresh_hinode_self(inode);
8815 + au_dbg_verify_dinode(dentry);
8816 + } else if (orig_h.mode == tmp_h.mode) {
8817 + AuDbg("positive --> positive, same type\n");
8818 + if (!S_ISDIR(orig_h.mode)
8819 + && dinfo->di_btop > tmp->di_btop) {
8821 + * similar to the behaviour of removing and
8826 + err = au_refresh_hinode_self(inode);
8827 + au_dbg_verify_dinode(dentry);
8829 + /* fill empty slots */
8830 + if (dinfo->di_btop > tmp->di_btop)
8831 + dinfo->di_btop = tmp->di_btop;
8832 + if (dinfo->di_bbot < tmp->di_bbot)
8833 + dinfo->di_bbot = tmp->di_bbot;
8834 + dinfo->di_bwh = tmp->di_bwh;
8835 + dinfo->di_bdiropq = tmp->di_bdiropq;
8836 + bbot = dinfo->di_bbot;
8837 + bindex = tmp->di_btop;
8838 + hd = au_hdentry(tmp, bindex);
8839 + for (; bindex <= bbot; bindex++, hd++) {
8840 + if (au_h_dptr(dentry, bindex))
8842 + h_dentry = hd->hd_dentry;
8845 + AuDebugOn(d_is_negative(h_dentry));
8846 + h_inode = d_inode(h_dentry);
8847 + AuDebugOn(orig_h.mode
8848 + != (h_inode->i_mode
8850 + au_set_h_dptr(dentry, bindex,
8854 + err = au_refresh_hinode(inode, dentry);
8855 + au_dbg_verify_dinode(dentry);
8858 + AuDbg("positive --> positive, different type\n");
8859 + /* similar to the behaviour of removing and creating */
8862 + err = au_refresh_hinode_self(inode);
8863 + au_dbg_verify_dinode(dentry);
8871 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8873 + const struct dentry_operations *dop
8874 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8875 + static const unsigned int mask
8876 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8878 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8880 + if (dentry->d_op == dop)
8883 + AuDbg("%pd\n", dentry);
8884 + spin_lock(&dentry->d_lock);
8885 + if (dop == &aufs_dop)
8886 + dentry->d_flags |= mask;
8888 + dentry->d_flags &= ~mask;
8889 + dentry->d_op = dop;
8890 + spin_unlock(&dentry->d_lock);
8893 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8895 + int err, ebrange, nbr;
8896 + unsigned int sigen;
8897 + struct au_dinfo *dinfo, *tmp;
8898 + struct super_block *sb;
8899 + struct inode *inode;
8901 + DiMustWriteLock(dentry);
8902 + AuDebugOn(IS_ROOT(dentry));
8903 + AuDebugOn(d_really_is_negative(parent));
8905 + sb = dentry->d_sb;
8906 + sigen = au_sigen(sb);
8907 + err = au_digen_test(parent, sigen);
8908 + if (unlikely(err))
8911 + nbr = au_sbbot(sb) + 1;
8912 + dinfo = au_di(dentry);
8913 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8914 + if (unlikely(err))
8916 + ebrange = au_dbrange_test(dentry);
8918 + ebrange = au_do_refresh_hdentry(dentry, parent);
8920 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8921 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8922 + if (d_really_is_positive(dentry)) {
8923 + inode = d_inode(dentry);
8924 + err = au_refresh_hinode_self(inode);
8926 + au_dbg_verify_dinode(dentry);
8928 + goto out_dgen; /* success */
8932 + /* temporary dinfo */
8933 + AuDbgDentry(dentry);
8935 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8936 + if (unlikely(!tmp))
8938 + au_di_swap(tmp, dinfo);
8939 + /* returns the number of positive dentries */
8941 + * if current working dir is removed, it returns an error.
8942 + * but the dentry is legal.
8944 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8945 + AuDbgDentry(dentry);
8946 + au_di_swap(tmp, dinfo);
8947 + if (err == -ENOENT)
8950 + /* compare/refresh by dinfo */
8951 + AuDbgDentry(dentry);
8952 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8953 + au_dbg_verify_dinode(dentry);
8956 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8957 + au_rw_write_unlock(&tmp->di_rwsem);
8959 + if (unlikely(err))
8963 + au_update_digen(dentry);
8965 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8966 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8967 + AuDbgDentry(dentry);
8973 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8974 + struct dentry *dentry, aufs_bindex_t bindex)
8979 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8982 + AuDbg("b%d\n", bindex);
8984 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8985 + * due to whiteout and branch permission.
8987 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8988 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8989 + /* it may return tri-state */
8990 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8992 + if (unlikely(valid < 0))
9002 +/* todo: remove this */
9003 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
9004 + unsigned int flags, int do_udba, int dirren)
9007 + umode_t mode, h_mode;
9008 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
9009 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
9010 + struct inode *h_inode, *h_cached_inode;
9011 + struct dentry *h_dentry;
9012 + struct qstr *name, *h_name;
9019 + unhashed = !!d_unhashed(dentry);
9020 + is_root = !!IS_ROOT(dentry);
9021 + name = &dentry->d_name;
9022 + tmpfile = au_di(dentry)->di_tmpfile;
9025 + * Theoretically, REVAL test should be unnecessary in case of
9027 + * But {fs,i}notify doesn't fire some necessary events,
9028 + * IN_ATTRIB for atime/nlink/pageio
9029 + * Let's do REVAL test too.
9031 + if (do_udba && inode) {
9032 + mode = (inode->i_mode & S_IFMT);
9033 + plus = (inode->i_nlink > 0);
9034 + ibs = au_ibtop(inode);
9035 + ibe = au_ibbot(inode);
9038 + btop = au_dbtop(dentry);
9040 + if (inode && S_ISDIR(inode->i_mode))
9041 + btail = au_dbtaildir(dentry);
9042 + for (bindex = btop; bindex <= btail; bindex++) {
9043 + h_dentry = au_h_dptr(dentry, bindex);
9047 + AuDbg("b%d, %pd\n", bindex, h_dentry);
9048 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
9049 + spin_lock(&h_dentry->d_lock);
9050 + h_name = &h_dentry->d_name;
9051 + if (unlikely(do_udba
9054 + && (unhashed != !!d_unhashed(h_dentry)
9055 + || (!tmpfile && !dirren
9056 + && !au_qstreq(name, h_name))
9059 + && !(flags & LOOKUP_OPEN)
9060 + && (h_dentry->d_flags
9061 + & DCACHE_NFSFS_RENAMED)))
9065 + h_unhashed = d_unhashed(h_dentry);
9066 + spin_unlock(&h_dentry->d_lock);
9067 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
9068 + unhashed, h_unhashed, dentry, h_dentry);
9071 + spin_unlock(&h_dentry->d_lock);
9073 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
9074 + if (unlikely(err))
9075 + /* do not goto err, to keep the errno */
9078 + /* todo: plink too? */
9083 + if (unlikely(!!inode != d_is_positive(h_dentry)))
9087 + if (d_is_positive(h_dentry))
9088 + h_inode = d_inode(h_dentry);
9091 + h_cached_inode = h_inode;
9093 + h_mode = (h_inode->i_mode & S_IFMT);
9094 + h_plus = (h_inode->i_nlink > 0);
9096 + if (inode && ibs <= bindex && bindex <= ibe)
9097 + h_cached_inode = au_h_iptr(inode, bindex);
9100 + if (unlikely(plus != h_plus && !tmpfile))
9103 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
9105 + && !IS_ROOT(h_dentry)
9106 + && unhashed != d_unhashed(h_dentry)))
9109 + if (unlikely(mode != h_mode
9110 + || h_cached_inode != h_inode))
9123 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
9124 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
9127 + struct dentry *parent;
9129 + if (!au_digen_test(dentry, sigen))
9132 + parent = dget_parent(dentry);
9133 + di_read_lock_parent(parent, AuLock_IR);
9134 + AuDebugOn(au_digen_test(parent, sigen));
9135 + au_dbg_verify_gen(parent, sigen);
9136 + err = au_refresh_dentry(dentry, parent);
9137 + di_read_unlock(parent, AuLock_IR);
9143 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
9146 + struct dentry *d, *parent;
9148 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
9149 + return simple_reval_dpath(dentry, sigen);
9151 + /* slow loop, keep it simple and stupid */
9152 + /* cf: au_cpup_dirs() */
9155 + while (au_digen_test(dentry, sigen)) {
9159 + parent = dget_parent(d);
9160 + if (!au_digen_test(parent, sigen))
9166 + di_write_lock_child2(d);
9168 + /* someone might update our dentry while we were sleeping */
9169 + if (au_digen_test(d, sigen)) {
9171 + * todo: consolidate with simple_reval_dpath(),
9172 + * do_refresh() and au_reval_for_attr().
9174 + di_read_lock_parent(parent, AuLock_IR);
9175 + err = au_refresh_dentry(d, parent);
9176 + di_read_unlock(parent, AuLock_IR);
9180 + di_write_unlock(d);
9182 + if (unlikely(err))
9190 + * if valid returns 1, otherwise 0.
9192 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9195 + unsigned int sigen;
9196 + unsigned char do_udba, dirren;
9197 + struct super_block *sb;
9198 + struct inode *inode;
9200 + /* todo: support rcu-walk? */
9201 + if (flags & LOOKUP_RCU)
9205 + if (unlikely(!au_di(dentry)))
9209 + sb = dentry->d_sb;
9212 + * i_mutex of parent dir may be held,
9213 + * but we should not return 'invalid' due to busy.
9215 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9216 + if (unlikely(err)) {
9222 + if (d_really_is_positive(dentry))
9223 + inode = d_inode(dentry);
9224 + if (unlikely(inode && au_is_bad_inode(inode))) {
9229 + if (unlikely(au_dbrange_test(dentry))) {
9235 + sigen = au_sigen(sb);
9236 + if (au_digen_test(dentry, sigen)) {
9237 + AuDebugOn(IS_ROOT(dentry));
9238 + err = au_reval_dpath(dentry, sigen);
9239 + if (unlikely(err)) {
9244 + di_downgrade_lock(dentry, AuLock_IR);
9247 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9249 + && !(inode->i_state && I_LINKABLE)
9250 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9255 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9256 + if (do_udba && inode) {
9257 + aufs_bindex_t btop = au_ibtop(inode);
9258 + struct inode *h_inode;
9261 + h_inode = au_h_iptr(inode, btop);
9262 + if (h_inode && au_test_higen(inode, h_inode)) {
9269 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9270 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9271 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9273 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9279 + di_downgrade_lock(dentry, AuLock_IR);
9281 + aufs_read_unlock(dentry, AuLock_IR);
9286 + AuDbg("%pd invalid, %d\n", dentry, valid);
9292 +static void aufs_d_release(struct dentry *dentry)
9294 + if (au_di(dentry)) {
9295 + au_di_fin(dentry);
9296 + au_hn_di_reinit(dentry);
9300 +const struct dentry_operations aufs_dop = {
9301 + .d_revalidate = aufs_d_revalidate,
9302 + .d_weak_revalidate = aufs_d_revalidate,
9303 + .d_release = aufs_d_release
9306 +/* aufs_dop without d_revalidate */
9307 +const struct dentry_operations aufs_dop_noreval = {
9308 + .d_release = aufs_d_release
9310 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9311 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9312 +++ linux/fs/aufs/dentry.h 2018-12-27 13:19:17.708416053 +0100
9314 +/* SPDX-License-Identifier: GPL-2.0 */
9316 + * Copyright (C) 2005-2018 Junjiro R. Okajima
9318 + * This program, aufs is free software; you can redistribute it and/or modify
9319 + * it under the terms of the GNU General Public License as published by
9320 + * the Free Software Foundation; either version 2 of the License, or
9321 + * (at your option) any later version.
9323 + * This program is distributed in the hope that it will be useful,
9324 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9325 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9326 + * GNU General Public License for more details.
9328 + * You should have received a copy of the GNU General Public License
9329 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9333 + * lookup and dentry operations
9336 +#ifndef __AUFS_DENTRY_H__
9337 +#define __AUFS_DENTRY_H__
9341 +#include <linux/dcache.h>
9342 +#include "dirren.h"
9345 +struct au_hdentry {
9346 + struct dentry *hd_dentry;
9347 + aufs_bindex_t hd_id;
9351 + atomic_t di_generation;
9353 + struct au_rwsem di_rwsem;
9354 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9355 + unsigned char di_tmpfile; /* to allow the different name */
9356 + struct au_hdentry *di_hdentry;
9357 + struct rcu_head rcu;
9358 +} ____cacheline_aligned_in_smp;
9360 +/* ---------------------------------------------------------------------- */
9362 +/* flags for au_lkup_dentry() */
9363 +#define AuLkup_ALLOW_NEG 1
9364 +#define AuLkup_IGNORE_PERM (1 << 1)
9365 +#define AuLkup_DIRREN (1 << 2)
9366 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9367 +#define au_fset_lkup(flags, name) \
9368 + do { (flags) |= AuLkup_##name; } while (0)
9369 +#define au_fclr_lkup(flags, name) \
9370 + do { (flags) &= ~AuLkup_##name; } while (0)
9372 +#ifndef CONFIG_AUFS_DIRREN
9373 +#undef AuLkup_DIRREN
9374 +#define AuLkup_DIRREN 0
9377 +struct au_do_lookup_args {
9378 + unsigned int flags;
9380 + struct qstr whname, *name;
9381 + struct au_dr_lookup dirren;
9384 +/* ---------------------------------------------------------------------- */
9387 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9389 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9390 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9391 + struct dentry *h_parent, struct au_branch *br);
9393 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9394 + unsigned int flags);
9395 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9396 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9397 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9398 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9401 +void au_di_init_once(void *_di);
9402 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9403 +void au_di_free(struct au_dinfo *dinfo);
9404 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9405 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9406 +int au_di_init(struct dentry *dentry);
9407 +void au_di_fin(struct dentry *dentry);
9408 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9410 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9411 +void di_read_unlock(struct dentry *d, int flags);
9412 +void di_downgrade_lock(struct dentry *d, int flags);
9413 +void di_write_lock(struct dentry *d, unsigned int lsc);
9414 +void di_write_unlock(struct dentry *d);
9415 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9416 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9417 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9419 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9420 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9421 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9422 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9424 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9425 + struct dentry *h_dentry);
9426 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9427 +int au_dbrange_test(struct dentry *dentry);
9428 +void au_update_digen(struct dentry *dentry);
9429 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9430 +void au_update_dbtop(struct dentry *dentry);
9431 +void au_update_dbbot(struct dentry *dentry);
9432 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9434 +/* ---------------------------------------------------------------------- */
9436 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9438 + return dentry->d_fsdata;
9441 +/* ---------------------------------------------------------------------- */
9443 +/* lock subclass for dinfo */
9445 + AuLsc_DI_CHILD, /* child first */
9446 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9447 + AuLsc_DI_CHILD3, /* copyup dirs */
9451 + AuLsc_DI_TMP /* temp for replacing dinfo */
9455 + * di_read_lock_child, di_write_lock_child,
9456 + * di_read_lock_child2, di_write_lock_child2,
9457 + * di_read_lock_child3, di_write_lock_child3,
9458 + * di_read_lock_parent, di_write_lock_parent,
9459 + * di_read_lock_parent2, di_write_lock_parent2,
9460 + * di_read_lock_parent3, di_write_lock_parent3,
9462 +#define AuReadLockFunc(name, lsc) \
9463 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9464 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9466 +#define AuWriteLockFunc(name, lsc) \
9467 +static inline void di_write_lock_##name(struct dentry *d) \
9468 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9470 +#define AuRWLockFuncs(name, lsc) \
9471 + AuReadLockFunc(name, lsc) \
9472 + AuWriteLockFunc(name, lsc)
9474 +AuRWLockFuncs(child, CHILD);
9475 +AuRWLockFuncs(child2, CHILD2);
9476 +AuRWLockFuncs(child3, CHILD3);
9477 +AuRWLockFuncs(parent, PARENT);
9478 +AuRWLockFuncs(parent2, PARENT2);
9479 +AuRWLockFuncs(parent3, PARENT3);
9481 +#undef AuReadLockFunc
9482 +#undef AuWriteLockFunc
9483 +#undef AuRWLockFuncs
9485 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9486 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9487 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9489 +/* ---------------------------------------------------------------------- */
9491 +/* todo: memory barrier? */
9492 +static inline unsigned int au_digen(struct dentry *d)
9494 + return atomic_read(&au_di(d)->di_generation);
9497 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9499 + hdentry->hd_dentry = NULL;
9502 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9503 + aufs_bindex_t bindex)
9505 + return di->di_hdentry + bindex;
9508 +static inline void au_hdput(struct au_hdentry *hd)
9511 + dput(hd->hd_dentry);
9514 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9516 + DiMustAnyLock(dentry);
9517 + return au_di(dentry)->di_btop;
9520 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9522 + DiMustAnyLock(dentry);
9523 + return au_di(dentry)->di_bbot;
9526 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9528 + DiMustAnyLock(dentry);
9529 + return au_di(dentry)->di_bwh;
9532 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9534 + DiMustAnyLock(dentry);
9535 + return au_di(dentry)->di_bdiropq;
9538 +/* todo: hard/soft set? */
9539 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9541 + DiMustWriteLock(dentry);
9542 + au_di(dentry)->di_btop = bindex;
9545 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9547 + DiMustWriteLock(dentry);
9548 + au_di(dentry)->di_bbot = bindex;
9551 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9553 + DiMustWriteLock(dentry);
9554 + /* dbwh can be outside of btop - bbot range */
9555 + au_di(dentry)->di_bwh = bindex;
9558 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9560 + DiMustWriteLock(dentry);
9561 + au_di(dentry)->di_bdiropq = bindex;
9564 +/* ---------------------------------------------------------------------- */
9566 +#ifdef CONFIG_AUFS_HNOTIFY
9567 +static inline void au_digen_dec(struct dentry *d)
9569 + atomic_dec(&au_di(d)->di_generation);
9572 +static inline void au_hn_di_reinit(struct dentry *dentry)
9574 + dentry->d_fsdata = NULL;
9577 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9578 +#endif /* CONFIG_AUFS_HNOTIFY */
9580 +#endif /* __KERNEL__ */
9581 +#endif /* __AUFS_DENTRY_H__ */
9582 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9583 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9584 +++ linux/fs/aufs/dinfo.c 2018-12-27 13:19:17.708416053 +0100
9586 +// SPDX-License-Identifier: GPL-2.0
9588 + * Copyright (C) 2005-2018 Junjiro R. Okajima
9590 + * This program, aufs is free software; you can redistribute it and/or modify
9591 + * it under the terms of the GNU General Public License as published by
9592 + * the Free Software Foundation; either version 2 of the License, or
9593 + * (at your option) any later version.
9595 + * This program is distributed in the hope that it will be useful,
9596 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9597 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9598 + * GNU General Public License for more details.
9600 + * You should have received a copy of the GNU General Public License
9601 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9605 + * dentry private data
9610 +void au_di_init_once(void *_dinfo)
9612 + struct au_dinfo *dinfo = _dinfo;
9614 + au_rw_init(&dinfo->di_rwsem);
9617 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9619 + struct au_dinfo *dinfo;
9622 + dinfo = au_cache_alloc_dinfo();
9623 + if (unlikely(!dinfo))
9626 + nbr = au_sbbot(sb) + 1;
9629 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9630 + if (dinfo->di_hdentry) {
9631 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9632 + dinfo->di_btop = -1;
9633 + dinfo->di_bbot = -1;
9634 + dinfo->di_bwh = -1;
9635 + dinfo->di_bdiropq = -1;
9636 + dinfo->di_tmpfile = 0;
9637 + for (i = 0; i < nbr; i++)
9638 + dinfo->di_hdentry[i].hd_id = -1;
9642 + au_cache_free_dinfo(dinfo);
9649 +void au_di_free(struct au_dinfo *dinfo)
9651 + struct au_hdentry *p;
9652 + aufs_bindex_t bbot, bindex;
9654 + /* dentry may not be revalidated */
9655 + bindex = dinfo->di_btop;
9656 + if (bindex >= 0) {
9657 + bbot = dinfo->di_bbot;
9658 + p = au_hdentry(dinfo, bindex);
9659 + while (bindex++ <= bbot)
9662 + au_kfree_try_rcu(dinfo->di_hdentry);
9663 + au_cache_free_dinfo(dinfo);
9666 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9668 + struct au_hdentry *p;
9671 + AuRwMustWriteLock(&a->di_rwsem);
9672 + AuRwMustWriteLock(&b->di_rwsem);
9674 +#define DiSwap(v, name) \
9676 + v = a->di_##name; \
9677 + a->di_##name = b->di_##name; \
9678 + b->di_##name = v; \
9681 + DiSwap(p, hdentry);
9685 + DiSwap(bi, bdiropq);
9691 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9693 + AuRwMustWriteLock(&dst->di_rwsem);
9694 + AuRwMustWriteLock(&src->di_rwsem);
9696 + dst->di_btop = src->di_btop;
9697 + dst->di_bbot = src->di_bbot;
9698 + dst->di_bwh = src->di_bwh;
9699 + dst->di_bdiropq = src->di_bdiropq;
9703 +int au_di_init(struct dentry *dentry)
9706 + struct super_block *sb;
9707 + struct au_dinfo *dinfo;
9710 + sb = dentry->d_sb;
9711 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9713 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9714 + /* smp_mb(); */ /* atomic_set */
9715 + dentry->d_fsdata = dinfo;
9722 +void au_di_fin(struct dentry *dentry)
9724 + struct au_dinfo *dinfo;
9726 + dinfo = au_di(dentry);
9727 + AuRwDestroy(&dinfo->di_rwsem);
9728 + au_di_free(dinfo);
9731 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9734 + struct au_hdentry *hdp;
9736 + AuRwMustWriteLock(&dinfo->di_rwsem);
9739 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9741 + sz = sizeof(*hdp);
9742 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9745 + dinfo->di_hdentry = hdp;
9752 +/* ---------------------------------------------------------------------- */
9754 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9757 + case AuLsc_DI_CHILD:
9758 + ii_write_lock_child(inode);
9760 + case AuLsc_DI_CHILD2:
9761 + ii_write_lock_child2(inode);
9763 + case AuLsc_DI_CHILD3:
9764 + ii_write_lock_child3(inode);
9766 + case AuLsc_DI_PARENT:
9767 + ii_write_lock_parent(inode);
9769 + case AuLsc_DI_PARENT2:
9770 + ii_write_lock_parent2(inode);
9772 + case AuLsc_DI_PARENT3:
9773 + ii_write_lock_parent3(inode);
9780 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9783 + case AuLsc_DI_CHILD:
9784 + ii_read_lock_child(inode);
9786 + case AuLsc_DI_CHILD2:
9787 + ii_read_lock_child2(inode);
9789 + case AuLsc_DI_CHILD3:
9790 + ii_read_lock_child3(inode);
9792 + case AuLsc_DI_PARENT:
9793 + ii_read_lock_parent(inode);
9795 + case AuLsc_DI_PARENT2:
9796 + ii_read_lock_parent2(inode);
9798 + case AuLsc_DI_PARENT3:
9799 + ii_read_lock_parent3(inode);
9806 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9808 + struct inode *inode;
9810 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9811 + if (d_really_is_positive(d)) {
9812 + inode = d_inode(d);
9813 + if (au_ftest_lock(flags, IW))
9814 + do_ii_write_lock(inode, lsc);
9815 + else if (au_ftest_lock(flags, IR))
9816 + do_ii_read_lock(inode, lsc);
9820 +void di_read_unlock(struct dentry *d, int flags)
9822 + struct inode *inode;
9824 + if (d_really_is_positive(d)) {
9825 + inode = d_inode(d);
9826 + if (au_ftest_lock(flags, IW)) {
9827 + au_dbg_verify_dinode(d);
9828 + ii_write_unlock(inode);
9829 + } else if (au_ftest_lock(flags, IR)) {
9830 + au_dbg_verify_dinode(d);
9831 + ii_read_unlock(inode);
9834 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9837 +void di_downgrade_lock(struct dentry *d, int flags)
9839 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9840 + ii_downgrade_lock(d_inode(d));
9841 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9844 +void di_write_lock(struct dentry *d, unsigned int lsc)
9846 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9847 + if (d_really_is_positive(d))
9848 + do_ii_write_lock(d_inode(d), lsc);
9851 +void di_write_unlock(struct dentry *d)
9853 + au_dbg_verify_dinode(d);
9854 + if (d_really_is_positive(d))
9855 + ii_write_unlock(d_inode(d));
9856 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9859 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9861 + AuDebugOn(d1 == d2
9862 + || d_inode(d1) == d_inode(d2)
9863 + || d1->d_sb != d2->d_sb);
9865 + if ((isdir && au_test_subdir(d1, d2))
9867 + di_write_lock_child(d1);
9868 + di_write_lock_child2(d2);
9870 + di_write_lock_child(d2);
9871 + di_write_lock_child2(d1);
9875 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9877 + AuDebugOn(d1 == d2
9878 + || d_inode(d1) == d_inode(d2)
9879 + || d1->d_sb != d2->d_sb);
9881 + if ((isdir && au_test_subdir(d1, d2))
9883 + di_write_lock_parent(d1);
9884 + di_write_lock_parent2(d2);
9886 + di_write_lock_parent(d2);
9887 + di_write_lock_parent2(d1);
9891 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9893 + di_write_unlock(d1);
9894 + if (d_inode(d1) == d_inode(d2))
9895 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9897 + di_write_unlock(d2);
9900 +/* ---------------------------------------------------------------------- */
9902 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9906 + DiMustAnyLock(dentry);
9908 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9910 + AuDebugOn(bindex < 0);
9911 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9912 + AuDebugOn(d && au_dcount(d) <= 0);
9917 + * extended version of au_h_dptr().
9918 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9921 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9923 + struct dentry *h_dentry;
9924 + struct inode *inode, *h_inode;
9926 + AuDebugOn(d_really_is_negative(dentry));
9929 + if (au_dbtop(dentry) <= bindex
9930 + && bindex <= au_dbbot(dentry))
9931 + h_dentry = au_h_dptr(dentry, bindex);
9932 + if (h_dentry && !au_d_linkable(h_dentry)) {
9934 + goto out; /* success */
9937 + inode = d_inode(dentry);
9938 + AuDebugOn(bindex < au_ibtop(inode));
9939 + AuDebugOn(au_ibbot(inode) < bindex);
9940 + h_inode = au_h_iptr(inode, bindex);
9941 + h_dentry = d_find_alias(h_inode);
9943 + if (!IS_ERR(h_dentry)) {
9944 + if (!au_d_linkable(h_dentry))
9945 + goto out; /* success */
9951 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9952 + h_dentry = au_plink_lkup(inode, bindex);
9953 + AuDebugOn(!h_dentry);
9954 + if (!IS_ERR(h_dentry)) {
9955 + if (!au_d_hashed_positive(h_dentry))
9956 + goto out; /* success */
9963 + AuDbgDentry(h_dentry);
9967 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9969 + aufs_bindex_t bbot, bwh;
9971 + bbot = au_dbbot(dentry);
9973 + bwh = au_dbwh(dentry);
9976 + if (0 < bwh && bwh < bbot)
9982 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9984 + aufs_bindex_t bbot, bopq;
9986 + bbot = au_dbtail(dentry);
9988 + bopq = au_dbdiropq(dentry);
9989 + if (0 <= bopq && bopq < bbot)
9995 +/* ---------------------------------------------------------------------- */
9997 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9998 + struct dentry *h_dentry)
10000 + struct au_dinfo *dinfo;
10001 + struct au_hdentry *hd;
10002 + struct au_branch *br;
10004 + DiMustWriteLock(dentry);
10006 + dinfo = au_di(dentry);
10007 + hd = au_hdentry(dinfo, bindex);
10009 + hd->hd_dentry = h_dentry;
10011 + br = au_sbr(dentry->d_sb, bindex);
10012 + hd->hd_id = br->br_id;
10016 +int au_dbrange_test(struct dentry *dentry)
10019 + aufs_bindex_t btop, bbot;
10022 + btop = au_dbtop(dentry);
10023 + bbot = au_dbbot(dentry);
10025 + AuDebugOn(bbot < 0 && btop > bbot);
10028 + AuDebugOn(bbot >= 0);
10034 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
10039 + if (unlikely(au_digen(dentry) != sigen
10040 + || au_iigen_test(d_inode(dentry), sigen)))
10046 +void au_update_digen(struct dentry *dentry)
10048 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
10049 + /* smp_mb(); */ /* atomic_set */
10052 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
10054 + struct au_dinfo *dinfo;
10055 + struct dentry *h_d;
10056 + struct au_hdentry *hdp;
10057 + aufs_bindex_t bindex, bbot;
10059 + DiMustWriteLock(dentry);
10061 + dinfo = au_di(dentry);
10062 + if (!dinfo || dinfo->di_btop < 0)
10065 + if (do_put_zero) {
10066 + bbot = dinfo->di_bbot;
10067 + bindex = dinfo->di_btop;
10068 + hdp = au_hdentry(dinfo, bindex);
10069 + for (; bindex <= bbot; bindex++, hdp++) {
10070 + h_d = hdp->hd_dentry;
10071 + if (h_d && d_is_negative(h_d))
10072 + au_set_h_dptr(dentry, bindex, NULL);
10076 + dinfo->di_btop = 0;
10077 + hdp = au_hdentry(dinfo, dinfo->di_btop);
10078 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
10079 + if (hdp->hd_dentry)
10081 + if (dinfo->di_btop > dinfo->di_bbot) {
10082 + dinfo->di_btop = -1;
10083 + dinfo->di_bbot = -1;
10087 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
10088 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
10089 + if (hdp->hd_dentry)
10091 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
10094 +void au_update_dbtop(struct dentry *dentry)
10096 + aufs_bindex_t bindex, bbot;
10097 + struct dentry *h_dentry;
10099 + bbot = au_dbbot(dentry);
10100 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
10101 + h_dentry = au_h_dptr(dentry, bindex);
10104 + if (d_is_positive(h_dentry)) {
10105 + au_set_dbtop(dentry, bindex);
10108 + au_set_h_dptr(dentry, bindex, NULL);
10112 +void au_update_dbbot(struct dentry *dentry)
10114 + aufs_bindex_t bindex, btop;
10115 + struct dentry *h_dentry;
10117 + btop = au_dbtop(dentry);
10118 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
10119 + h_dentry = au_h_dptr(dentry, bindex);
10122 + if (d_is_positive(h_dentry)) {
10123 + au_set_dbbot(dentry, bindex);
10126 + au_set_h_dptr(dentry, bindex, NULL);
10130 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
10132 + aufs_bindex_t bindex, bbot;
10134 + bbot = au_dbbot(dentry);
10135 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
10136 + if (au_h_dptr(dentry, bindex) == h_dentry)
10140 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
10141 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
10142 +++ linux/fs/aufs/dir.c 2018-12-27 13:19:17.708416053 +0100
10144 +// SPDX-License-Identifier: GPL-2.0
10146 + * Copyright (C) 2005-2018 Junjiro R. Okajima
10148 + * This program, aufs is free software; you can redistribute it and/or modify
10149 + * it under the terms of the GNU General Public License as published by
10150 + * the Free Software Foundation; either version 2 of the License, or
10151 + * (at your option) any later version.
10153 + * This program is distributed in the hope that it will be useful,
10154 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10155 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10156 + * GNU General Public License for more details.
10158 + * You should have received a copy of the GNU General Public License
10159 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10163 + * directory operations
10166 +#include <linux/fs_stack.h>
10169 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10171 + unsigned int nlink;
10173 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10175 + nlink = dir->i_nlink;
10176 + nlink += h_dir->i_nlink - 2;
10177 + if (h_dir->i_nlink < 2)
10179 + smp_mb(); /* for i_nlink */
10180 + /* 0 can happen in revaliding */
10181 + set_nlink(dir, nlink);
10184 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10186 + unsigned int nlink;
10188 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10190 + nlink = dir->i_nlink;
10191 + nlink -= h_dir->i_nlink - 2;
10192 + if (h_dir->i_nlink < 2)
10194 + smp_mb(); /* for i_nlink */
10195 + /* nlink == 0 means the branch-fs is broken */
10196 + set_nlink(dir, nlink);
10199 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10202 + aufs_bindex_t bindex, bbot;
10203 + struct file *h_file;
10204 + struct dentry *h_dentry;
10208 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10210 + bbot = au_fbbot_dir(file);
10211 + for (bindex = au_fbtop(file);
10212 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10214 + h_file = au_hf_dir(file, bindex);
10215 + if (h_file && file_inode(h_file))
10216 + sz += vfsub_f_size_read(h_file);
10219 + AuDebugOn(!dentry);
10220 + AuDebugOn(!d_is_dir(dentry));
10222 + bbot = au_dbtaildir(dentry);
10223 + for (bindex = au_dbtop(dentry);
10224 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10226 + h_dentry = au_h_dptr(dentry, bindex);
10227 + if (h_dentry && d_is_positive(h_dentry))
10228 + sz += i_size_read(d_inode(h_dentry));
10231 + if (sz < KMALLOC_MAX_SIZE)
10232 + sz = roundup_pow_of_two(sz);
10233 + if (sz > KMALLOC_MAX_SIZE)
10234 + sz = KMALLOC_MAX_SIZE;
10235 + else if (sz < NAME_MAX) {
10236 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10237 + sz = AUFS_RDBLK_DEF;
10242 +struct au_dir_ts_arg {
10243 + struct dentry *dentry;
10244 + aufs_bindex_t brid;
10247 +static void au_do_dir_ts(void *arg)
10249 + struct au_dir_ts_arg *a = arg;
10250 + struct au_dtime dt;
10251 + struct path h_path;
10252 + struct inode *dir, *h_dir;
10253 + struct super_block *sb;
10254 + struct au_branch *br;
10255 + struct au_hinode *hdir;
10257 + aufs_bindex_t btop, bindex;
10259 + sb = a->dentry->d_sb;
10260 + if (d_really_is_negative(a->dentry))
10262 + /* no dir->i_mutex lock */
10263 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10265 + dir = d_inode(a->dentry);
10266 + btop = au_ibtop(dir);
10267 + bindex = au_br_index(sb, a->brid);
10268 + if (bindex < btop)
10271 + br = au_sbr(sb, bindex);
10272 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10273 + if (!h_path.dentry)
10275 + h_path.mnt = au_br_mnt(br);
10276 + au_dtime_store(&dt, a->dentry, &h_path);
10278 + br = au_sbr(sb, btop);
10279 + if (!au_br_writable(br->br_perm))
10281 + h_path.dentry = au_h_dptr(a->dentry, btop);
10282 + h_path.mnt = au_br_mnt(br);
10283 + err = vfsub_mnt_want_write(h_path.mnt);
10286 + hdir = au_hi(dir, btop);
10287 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10288 + h_dir = au_h_iptr(dir, btop);
10289 + if (h_dir->i_nlink
10290 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10291 + dt.dt_h_path = h_path;
10292 + au_dtime_revert(&dt);
10294 + au_hn_inode_unlock(hdir);
10295 + vfsub_mnt_drop_write(h_path.mnt);
10296 + au_cpup_attr_timesizes(dir);
10299 + aufs_read_unlock(a->dentry, AuLock_DW);
10302 + au_nwt_done(&au_sbi(sb)->si_nowait);
10303 + au_kfree_try_rcu(arg);
10306 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10308 + int perm, wkq_err;
10309 + aufs_bindex_t btop;
10310 + struct au_dir_ts_arg *arg;
10311 + struct dentry *dentry;
10312 + struct super_block *sb;
10316 + dentry = d_find_any_alias(dir);
10317 + AuDebugOn(!dentry);
10318 + sb = dentry->d_sb;
10319 + btop = au_ibtop(dir);
10320 + if (btop == bindex) {
10321 + au_cpup_attr_timesizes(dir);
10325 + perm = au_sbr_perm(sb, btop);
10326 + if (!au_br_writable(perm))
10329 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10333 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10334 + arg->brid = au_sbr_id(sb, bindex);
10335 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10336 + if (unlikely(wkq_err)) {
10337 + pr_err("wkq %d\n", wkq_err);
10339 + au_kfree_try_rcu(arg);
10346 +/* ---------------------------------------------------------------------- */
10348 +static int reopen_dir(struct file *file)
10351 + unsigned int flags;
10352 + aufs_bindex_t bindex, btail, btop;
10353 + struct dentry *dentry, *h_dentry;
10354 + struct file *h_file;
10356 + /* open all lower dirs */
10357 + dentry = file->f_path.dentry;
10358 + btop = au_dbtop(dentry);
10359 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10360 + au_set_h_fptr(file, bindex, NULL);
10361 + au_set_fbtop(file, btop);
10363 + btail = au_dbtaildir(dentry);
10364 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10365 + au_set_h_fptr(file, bindex, NULL);
10366 + au_set_fbbot_dir(file, btail);
10368 + flags = vfsub_file_flags(file);
10369 + for (bindex = btop; bindex <= btail; bindex++) {
10370 + h_dentry = au_h_dptr(dentry, bindex);
10373 + h_file = au_hf_dir(file, bindex);
10377 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10378 + err = PTR_ERR(h_file);
10379 + if (IS_ERR(h_file))
10380 + goto out; /* close all? */
10381 + au_set_h_fptr(file, bindex, h_file);
10383 + au_update_figen(file);
10384 + /* todo: necessary? */
10385 + /* file->f_ra = h_file->f_ra; */
10392 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10395 + aufs_bindex_t bindex, btail;
10396 + struct dentry *dentry, *h_dentry;
10397 + struct vfsmount *mnt;
10399 + FiMustWriteLock(file);
10400 + AuDebugOn(h_file);
10403 + mnt = file->f_path.mnt;
10404 + dentry = file->f_path.dentry;
10405 + file->f_version = inode_query_iversion(d_inode(dentry));
10406 + bindex = au_dbtop(dentry);
10407 + au_set_fbtop(file, bindex);
10408 + btail = au_dbtaildir(dentry);
10409 + au_set_fbbot_dir(file, btail);
10410 + for (; !err && bindex <= btail; bindex++) {
10411 + h_dentry = au_h_dptr(dentry, bindex);
10415 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10416 + if (unlikely(err))
10418 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10419 + if (IS_ERR(h_file)) {
10420 + err = PTR_ERR(h_file);
10423 + au_set_h_fptr(file, bindex, h_file);
10425 + au_update_figen(file);
10426 + /* todo: necessary? */
10427 + /* file->f_ra = h_file->f_ra; */
10429 + return 0; /* success */
10432 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10433 + au_set_h_fptr(file, bindex, NULL);
10434 + au_set_fbtop(file, -1);
10435 + au_set_fbbot_dir(file, -1);
10440 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10441 + struct file *file)
10444 + struct super_block *sb;
10445 + struct au_fidir *fidir;
10448 + sb = file->f_path.dentry->d_sb;
10449 + si_read_lock(sb, AuLock_FLUSH);
10450 + fidir = au_fidir_alloc(sb);
10452 + struct au_do_open_args args = {
10453 + .open = do_open_dir,
10456 + err = au_do_open(file, &args);
10457 + if (unlikely(err))
10458 + au_kfree_rcu(fidir);
10460 + si_read_unlock(sb);
10464 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10465 + struct file *file)
10467 + struct au_vdir *vdir_cache;
10468 + struct au_finfo *finfo;
10469 + struct au_fidir *fidir;
10470 + struct au_hfile *hf;
10471 + aufs_bindex_t bindex, bbot;
10473 + finfo = au_fi(file);
10474 + fidir = finfo->fi_hdir;
10476 + au_hbl_del(&finfo->fi_hlist,
10477 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10478 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10480 + au_vdir_free(vdir_cache);
10482 + bindex = finfo->fi_btop;
10483 + if (bindex >= 0) {
10484 + hf = fidir->fd_hfile + bindex;
10486 + * calls fput() instead of filp_close(),
10487 + * since no dnotify or lock for the lower file.
10489 + bbot = fidir->fd_bbot;
10490 + for (; bindex <= bbot; bindex++, hf++)
10492 + au_hfput(hf, /*execed*/0);
10494 + au_kfree_rcu(fidir);
10495 + finfo->fi_hdir = NULL;
10497 + au_finfo_fin(file);
10501 +/* ---------------------------------------------------------------------- */
10503 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10506 + aufs_bindex_t bindex, bbot;
10507 + struct file *h_file;
10510 + bbot = au_fbbot_dir(file);
10511 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10512 + h_file = au_hf_dir(file, bindex);
10514 + err = vfsub_flush(h_file, id);
10519 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10521 + return au_do_flush(file, id, au_do_flush_dir);
10524 +/* ---------------------------------------------------------------------- */
10526 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10529 + aufs_bindex_t bbot, bindex;
10530 + struct inode *inode;
10531 + struct super_block *sb;
10534 + sb = dentry->d_sb;
10535 + inode = d_inode(dentry);
10536 + IMustLock(inode);
10537 + bbot = au_dbbot(dentry);
10538 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10539 + struct path h_path;
10541 + if (au_test_ro(sb, bindex, inode))
10543 + h_path.dentry = au_h_dptr(dentry, bindex);
10544 + if (!h_path.dentry)
10547 + h_path.mnt = au_sbr_mnt(sb, bindex);
10548 + err = vfsub_fsync(NULL, &h_path, datasync);
10554 +static int au_do_fsync_dir(struct file *file, int datasync)
10557 + aufs_bindex_t bbot, bindex;
10558 + struct file *h_file;
10559 + struct super_block *sb;
10560 + struct inode *inode;
10562 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10563 + if (unlikely(err))
10566 + inode = file_inode(file);
10567 + sb = inode->i_sb;
10568 + bbot = au_fbbot_dir(file);
10569 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10570 + h_file = au_hf_dir(file, bindex);
10571 + if (!h_file || au_test_ro(sb, bindex, inode))
10574 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10582 + * @file may be NULL
10584 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10588 + struct dentry *dentry;
10589 + struct inode *inode;
10590 + struct super_block *sb;
10593 + dentry = file->f_path.dentry;
10594 + inode = d_inode(dentry);
10595 + inode_lock(inode);
10596 + sb = dentry->d_sb;
10597 + si_noflush_read_lock(sb);
10599 + err = au_do_fsync_dir(file, datasync);
10601 + di_write_lock_child(dentry);
10602 + err = au_do_fsync_dir_no_file(dentry, datasync);
10604 + au_cpup_attr_timesizes(inode);
10605 + di_write_unlock(dentry);
10607 + fi_write_unlock(file);
10609 + si_read_unlock(sb);
10610 + inode_unlock(inode);
10614 +/* ---------------------------------------------------------------------- */
10616 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10619 + struct dentry *dentry;
10620 + struct inode *inode, *h_inode;
10621 + struct super_block *sb;
10623 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10625 + dentry = file->f_path.dentry;
10626 + inode = d_inode(dentry);
10627 + IMustLock(inode);
10629 + sb = dentry->d_sb;
10630 + si_read_lock(sb, AuLock_FLUSH);
10631 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10632 + if (unlikely(err))
10634 + err = au_alive_dir(dentry);
10636 + err = au_vdir_init(file);
10637 + di_downgrade_lock(dentry, AuLock_IR);
10638 + if (unlikely(err))
10641 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10642 + if (!au_test_nfsd()) {
10643 + err = au_vdir_fill_de(file, ctx);
10644 + fsstack_copy_attr_atime(inode, h_inode);
10647 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10648 + * encode_fh() and others.
10650 + atomic_inc(&h_inode->i_count);
10651 + di_read_unlock(dentry, AuLock_IR);
10652 + si_read_unlock(sb);
10653 + err = au_vdir_fill_de(file, ctx);
10654 + fsstack_copy_attr_atime(inode, h_inode);
10655 + fi_write_unlock(file);
10663 + di_read_unlock(dentry, AuLock_IR);
10664 + fi_write_unlock(file);
10666 + si_read_unlock(sb);
10670 +/* ---------------------------------------------------------------------- */
10672 +#define AuTestEmpty_WHONLY 1
10673 +#define AuTestEmpty_CALLED (1 << 1)
10674 +#define AuTestEmpty_SHWH (1 << 2)
10675 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10676 +#define au_fset_testempty(flags, name) \
10677 + do { (flags) |= AuTestEmpty_##name; } while (0)
10678 +#define au_fclr_testempty(flags, name) \
10679 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10681 +#ifndef CONFIG_AUFS_SHWH
10682 +#undef AuTestEmpty_SHWH
10683 +#define AuTestEmpty_SHWH 0
10686 +struct test_empty_arg {
10687 + struct dir_context ctx;
10688 + struct au_nhash *whlist;
10689 + unsigned int flags;
10691 + aufs_bindex_t bindex;
10694 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10695 + int namelen, loff_t offset __maybe_unused, u64 ino,
10696 + unsigned int d_type)
10698 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10700 + char *name = (void *)__name;
10703 + au_fset_testempty(arg->flags, CALLED);
10705 + if (name[0] == '.'
10706 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10707 + goto out; /* success */
10709 + if (namelen <= AUFS_WH_PFX_LEN
10710 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10711 + if (au_ftest_testempty(arg->flags, WHONLY)
10712 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10713 + arg->err = -ENOTEMPTY;
10717 + name += AUFS_WH_PFX_LEN;
10718 + namelen -= AUFS_WH_PFX_LEN;
10719 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10720 + arg->err = au_nhash_append_wh
10721 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10722 + au_ftest_testempty(arg->flags, SHWH));
10726 + AuTraceErr(arg->err);
10730 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10733 + struct file *h_file;
10734 + struct au_branch *br;
10736 + h_file = au_h_open(dentry, arg->bindex,
10737 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10738 + /*file*/NULL, /*force_wr*/0);
10739 + err = PTR_ERR(h_file);
10740 + if (IS_ERR(h_file))
10744 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10745 + && !file_inode(h_file)->i_nlink)
10750 + au_fclr_testempty(arg->flags, CALLED);
10752 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10755 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10759 + br = au_sbr(dentry->d_sb, arg->bindex);
10760 + au_lcnt_dec(&br->br_nfiles);
10765 +struct do_test_empty_args {
10767 + struct dentry *dentry;
10768 + struct test_empty_arg *arg;
10771 +static void call_do_test_empty(void *args)
10773 + struct do_test_empty_args *a = args;
10774 + *a->errp = do_test_empty(a->dentry, a->arg);
10777 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10779 + int err, wkq_err;
10780 + struct dentry *h_dentry;
10781 + struct inode *h_inode;
10783 + h_dentry = au_h_dptr(dentry, arg->bindex);
10784 + h_inode = d_inode(h_dentry);
10785 + /* todo: i_mode changes anytime? */
10786 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10787 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10788 + inode_unlock_shared(h_inode);
10790 + err = do_test_empty(dentry, arg);
10792 + struct do_test_empty_args args = {
10794 + .dentry = dentry,
10797 + unsigned int flags = arg->flags;
10799 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10800 + if (unlikely(wkq_err))
10802 + arg->flags = flags;
10808 +int au_test_empty_lower(struct dentry *dentry)
10811 + unsigned int rdhash;
10812 + aufs_bindex_t bindex, btop, btail;
10813 + struct au_nhash whlist;
10814 + struct test_empty_arg arg = {
10816 + .actor = test_empty_cb
10819 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10821 + SiMustAnyLock(dentry->d_sb);
10823 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10825 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10826 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10827 + if (unlikely(err))
10831 + arg.whlist = &whlist;
10832 + btop = au_dbtop(dentry);
10833 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10834 + au_fset_testempty(arg.flags, SHWH);
10835 + test_empty = do_test_empty;
10836 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10837 + test_empty = sio_test_empty;
10838 + arg.bindex = btop;
10839 + err = test_empty(dentry, &arg);
10840 + if (unlikely(err))
10843 + au_fset_testempty(arg.flags, WHONLY);
10844 + btail = au_dbtaildir(dentry);
10845 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10846 + struct dentry *h_dentry;
10848 + h_dentry = au_h_dptr(dentry, bindex);
10849 + if (h_dentry && d_is_positive(h_dentry)) {
10850 + arg.bindex = bindex;
10851 + err = test_empty(dentry, &arg);
10856 + au_nhash_wh_free(&whlist);
10861 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10864 + struct test_empty_arg arg = {
10866 + .actor = test_empty_cb
10869 + aufs_bindex_t bindex, btail;
10872 + arg.whlist = whlist;
10873 + arg.flags = AuTestEmpty_WHONLY;
10874 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10875 + au_fset_testempty(arg.flags, SHWH);
10876 + btail = au_dbtaildir(dentry);
10877 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10878 + struct dentry *h_dentry;
10880 + h_dentry = au_h_dptr(dentry, bindex);
10881 + if (h_dentry && d_is_positive(h_dentry)) {
10882 + arg.bindex = bindex;
10883 + err = sio_test_empty(dentry, &arg);
10890 +/* ---------------------------------------------------------------------- */
10892 +const struct file_operations aufs_dir_fop = {
10893 + .owner = THIS_MODULE,
10894 + .llseek = default_llseek,
10895 + .read = generic_read_dir,
10896 + .iterate_shared = aufs_iterate_shared,
10897 + .unlocked_ioctl = aufs_ioctl_dir,
10898 +#ifdef CONFIG_COMPAT
10899 + .compat_ioctl = aufs_compat_ioctl_dir,
10901 + .open = aufs_open_dir,
10902 + .release = aufs_release_dir,
10903 + .flush = aufs_flush_dir,
10904 + .fsync = aufs_fsync_dir
10906 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10907 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10908 +++ linux/fs/aufs/dir.h 2018-12-27 13:19:17.708416053 +0100
10910 +/* SPDX-License-Identifier: GPL-2.0 */
10912 + * Copyright (C) 2005-2018 Junjiro R. Okajima
10914 + * This program, aufs is free software; you can redistribute it and/or modify
10915 + * it under the terms of the GNU General Public License as published by
10916 + * the Free Software Foundation; either version 2 of the License, or
10917 + * (at your option) any later version.
10919 + * This program is distributed in the hope that it will be useful,
10920 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10921 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10922 + * GNU General Public License for more details.
10924 + * You should have received a copy of the GNU General Public License
10925 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10929 + * directory operations
10932 +#ifndef __AUFS_DIR_H__
10933 +#define __AUFS_DIR_H__
10937 +#include <linux/fs.h>
10939 +/* ---------------------------------------------------------------------- */
10941 +/* need to be faster and smaller */
10944 + unsigned int nh_num;
10945 + struct hlist_head *nh_head;
10948 +struct au_vdir_destr {
10949 + unsigned char len;
10950 + unsigned char name[0];
10953 +struct au_vdir_dehstr {
10954 + struct hlist_node hash;
10955 + struct au_vdir_destr *str;
10956 + struct rcu_head rcu;
10957 +} ____cacheline_aligned_in_smp;
10959 +struct au_vdir_de {
10961 + unsigned char de_type;
10962 + /* caution: packed */
10963 + struct au_vdir_destr de_str;
10966 +struct au_vdir_wh {
10967 + struct hlist_node wh_hash;
10968 +#ifdef CONFIG_AUFS_SHWH
10970 + aufs_bindex_t wh_bindex;
10971 + unsigned char wh_type;
10973 + aufs_bindex_t wh_bindex;
10975 + /* caution: packed */
10976 + struct au_vdir_destr wh_str;
10979 +union au_vdir_deblk_p {
10980 + unsigned char *deblk;
10981 + struct au_vdir_de *de;
10985 + unsigned char **vd_deblk;
10986 + unsigned long vd_nblk;
10988 + unsigned long ul;
10989 + union au_vdir_deblk_p p;
10993 + unsigned int vd_deblk_sz;
10994 + unsigned long vd_jiffy;
10995 + struct rcu_head rcu;
10996 +} ____cacheline_aligned_in_smp;
10998 +/* ---------------------------------------------------------------------- */
11001 +extern const struct file_operations aufs_dir_fop;
11002 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
11003 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
11004 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
11005 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
11006 +int au_test_empty_lower(struct dentry *dentry);
11007 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
11010 +unsigned int au_rdhash_est(loff_t sz);
11011 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
11012 +void au_nhash_wh_free(struct au_nhash *whlist);
11013 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
11015 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
11016 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
11017 + unsigned int d_type, aufs_bindex_t bindex,
11018 + unsigned char shwh);
11019 +void au_vdir_free(struct au_vdir *vdir);
11020 +int au_vdir_init(struct file *file);
11021 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
11024 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
11026 +#ifdef CONFIG_AUFS_RDU
11028 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
11029 +#ifdef CONFIG_COMPAT
11030 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
11031 + unsigned long arg);
11034 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
11035 + unsigned int cmd, unsigned long arg)
11036 +#ifdef CONFIG_COMPAT
11037 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
11038 + unsigned int cmd, unsigned long arg)
11042 +#endif /* __KERNEL__ */
11043 +#endif /* __AUFS_DIR_H__ */
11044 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
11045 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
11046 +++ linux/fs/aufs/dirren.c 2018-12-27 13:19:17.708416053 +0100
11048 +// SPDX-License-Identifier: GPL-2.0
11050 + * Copyright (C) 2017-2018 Junjiro R. Okajima
11052 + * This program, aufs is free software; you can redistribute it and/or modify
11053 + * it under the terms of the GNU General Public License as published by
11054 + * the Free Software Foundation; either version 2 of the License, or
11055 + * (at your option) any later version.
11057 + * This program is distributed in the hope that it will be useful,
11058 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11059 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11060 + * GNU General Public License for more details.
11062 + * You should have received a copy of the GNU General Public License
11063 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11067 + * special handling in renaming a directory
11068 + * in order to support looking-up the before-renamed name on the lower readonly
11072 +#include <linux/byteorder/generic.h>
11075 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
11079 + idx = au_dr_ihash(ent->dr_h_ino);
11080 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
11083 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
11086 + struct hlist_bl_head *hbl;
11089 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
11090 + hbl = dr->dr_h_ino + i;
11091 + hlist_bl_lock(hbl);
11092 + ret &= hlist_bl_empty(hbl);
11093 + hlist_bl_unlock(hbl);
11099 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
11101 + struct au_dr_hino *found, *ent;
11102 + struct hlist_bl_head *hbl;
11103 + struct hlist_bl_node *pos;
11107 + idx = au_dr_ihash(ino);
11108 + hbl = dr->dr_h_ino + idx;
11109 + hlist_bl_lock(hbl);
11110 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11111 + if (ent->dr_h_ino == ino) {
11115 + hlist_bl_unlock(hbl);
11120 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
11121 + struct au_dr_hino *add_ent)
11124 + struct hlist_bl_head *hbl;
11125 + struct hlist_bl_node *pos;
11126 + struct au_dr_hino *ent;
11129 + idx = au_dr_ihash(ino);
11130 + hbl = dr->dr_h_ino + idx;
11133 + struct hlist_bl_node *tmp;
11135 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11136 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
11139 + hlist_bl_lock(hbl);
11140 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11141 + if (ent->dr_h_ino == ino) {
11145 + if (!found && add_ent)
11146 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
11147 + hlist_bl_unlock(hbl);
11149 + if (!found && add_ent)
11150 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
11155 +void au_dr_hino_free(struct au_dr_br *dr)
11158 + struct hlist_bl_head *hbl;
11159 + struct hlist_bl_node *pos, *tmp;
11160 + struct au_dr_hino *ent;
11162 + /* SiMustWriteLock(sb); */
11164 + for (i = 0; i < AuDirren_NHASH; i++) {
11165 + hbl = dr->dr_h_ino + i;
11166 + /* no spinlock since sbinfo must be write-locked */
11167 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11168 + au_kfree_rcu(ent);
11169 + INIT_HLIST_BL_HEAD(hbl);
11173 +/* returns the number of inodes or an error */
11174 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11175 + struct file *hinofile)
11179 + loff_t pos, oldsize;
11181 + struct inode *hinoinode;
11182 + struct hlist_bl_head *hbl;
11183 + struct hlist_bl_node *n1, *n2;
11184 + struct au_dr_hino *ent;
11186 + SiMustWriteLock(sb);
11187 + AuDebugOn(!au_br_writable(br->br_perm));
11189 + hinoinode = file_inode(hinofile);
11190 + oldsize = i_size_read(hinoinode);
11194 + hbl = br->br_dirren.dr_h_ino;
11195 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11196 + /* no bit-lock since sbinfo must be write-locked */
11197 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11198 + AuDbg("hi%llu, %pD2\n",
11199 + (unsigned long long)ent->dr_h_ino, hinofile);
11200 + u64 = cpu_to_be64(ent->dr_h_ino);
11201 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11202 + if (ssz == sizeof(u64))
11205 + /* write error */
11206 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11213 + /* regardless the error */
11214 + if (pos < oldsize) {
11215 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11223 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11230 + struct au_dr_hino *ent;
11231 + struct inode *hinoinode;
11232 + struct hlist_bl_head *hbl;
11236 + hbl = dr->dr_h_ino;
11237 + hinoinode = file_inode(hinofile);
11238 + sz = i_size_read(hinoinode);
11239 + AuDebugOn(sz % sizeof(u64));
11240 + n = sz / sizeof(u64);
11242 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11243 + if (unlikely(ssz != sizeof(u64))) {
11244 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11251 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11257 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11258 + AuDbg("hi%llu, %pD2\n",
11259 + (unsigned long long)ent->dr_h_ino, hinofile);
11260 + hidx = au_dr_ihash(ent->dr_h_ino);
11261 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11263 + goto out; /* success */
11266 + au_dr_hino_free(dr);
11273 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11274 + * @path is a switch to distinguish load and store.
11276 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11277 + struct au_branch *br, const struct path *path)
11280 + unsigned char load, suspend;
11281 + struct file *hinofile;
11282 + struct au_hinode *hdir;
11283 + struct inode *dir, *delegated;
11284 + struct path hinopath;
11285 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11286 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11288 + AuDebugOn(bindex < 0 && !br);
11289 + AuDebugOn(bindex >= 0 && br);
11294 + br = au_sbr(sb, bindex);
11297 + path = &br->br_path;
11298 + AuDebugOn(!au_br_writable(br->br_perm));
11299 + if (unlikely(!au_br_writable(br->br_perm)))
11305 + dir = d_inode(sb->s_root);
11306 + hdir = au_hinode(au_ii(dir), bindex);
11307 + dir = hdir->hi_inode;
11308 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11310 + dir = d_inode(path->dentry);
11311 + inode_lock_nested(dir, AuLsc_I_CHILD);
11313 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11314 + err = PTR_ERR(hinopath.dentry);
11315 + if (IS_ERR(hinopath.dentry))
11319 + flags = O_RDONLY;
11321 + if (d_is_negative(hinopath.dentry))
11322 + goto out_dput; /* success */
11324 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11325 + if (d_is_positive(hinopath.dentry)) {
11326 + delegated = NULL;
11327 + err = vfsub_unlink(dir, &hinopath, &delegated,
11330 + if (unlikely(err))
11331 + pr_err("ignored err %d, %pd2\n",
11332 + err, hinopath.dentry);
11333 + if (unlikely(err == -EWOULDBLOCK))
11338 + } else if (!d_is_positive(hinopath.dentry)) {
11339 + err = vfsub_create(dir, &hinopath, 0600,
11340 + /*want_excl*/false);
11342 + if (unlikely(err))
11345 + flags = O_WRONLY;
11347 + hinopath.mnt = path->mnt;
11348 + hinofile = vfsub_dentry_open(&hinopath, flags);
11350 + au_hn_inode_unlock(hdir);
11352 + inode_unlock(dir);
11353 + dput(hinopath.dentry);
11354 + AuTraceErrPtr(hinofile);
11355 + if (IS_ERR(hinofile)) {
11356 + err = PTR_ERR(hinofile);
11361 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11363 + err = au_dr_hino_store(sb, br, hinofile);
11368 + dput(hinopath.dentry);
11371 + au_hn_inode_unlock(hdir);
11373 + inode_unlock(dir);
11379 +/* ---------------------------------------------------------------------- */
11381 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11384 + struct kstatfs kstfs;
11386 + struct dentry *dentry;
11387 + struct super_block *sb;
11389 + err = vfs_statfs((void *)path, &kstfs);
11391 + if (unlikely(err))
11394 + /* todo: support for UUID */
11396 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11397 + brid->type = AuBrid_FSID;
11398 + brid->fsid = kstfs.f_fsid;
11400 + dentry = path->dentry;
11401 + sb = dentry->d_sb;
11404 + brid->type = AuBrid_DEV;
11413 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11414 + const struct path *path)
11417 + struct au_dr_br *dr;
11418 + struct hlist_bl_head *hbl;
11420 + dr = &br->br_dirren;
11421 + hbl = dr->dr_h_ino;
11422 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11423 + INIT_HLIST_BL_HEAD(hbl);
11425 + err = au_dr_brid_init(&dr->dr_brid, path);
11426 + if (unlikely(err))
11429 + if (au_opt_test(au_mntflags(sb), DIRREN))
11430 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11437 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11442 + if (au_br_writable(br->br_perm))
11443 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11445 + au_dr_hino_free(&br->br_dirren);
11450 +/* ---------------------------------------------------------------------- */
11452 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11453 + char *buf, size_t sz)
11456 + unsigned int major, minor;
11460 + err = snprintf(p, sz, "%d_", brid->type);
11461 + AuDebugOn(err > sz);
11464 + switch (brid->type) {
11465 + case AuBrid_Unset:
11467 + case AuBrid_UUID:
11468 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11470 + case AuBrid_FSID:
11471 + err = snprintf(p, sz, "%08x-%08x",
11472 + brid->fsid.val[0], brid->fsid.val[1]);
11475 + major = MAJOR(brid->dev);
11476 + minor = MINOR(brid->dev);
11477 + if (major <= 0xff && minor <= 0xff)
11478 + err = snprintf(p, sz, "%02x%02x", major, minor);
11480 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11483 + AuDebugOn(err > sz);
11486 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11487 + AuDebugOn(err > sz);
11494 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11497 + struct dentry *br_dentry;
11498 + struct inode *br_inode;
11500 + br_dentry = au_br_dentry(br);
11501 + br_inode = d_inode(br_dentry);
11502 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11503 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11504 + AuDebugOn(rlen > len);
11509 +/* ---------------------------------------------------------------------- */
11512 + * from the given @h_dentry, construct drinfo at @*fdata.
11513 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11516 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11517 + struct dentry *h_dentry,
11518 + unsigned char *allocated)
11521 + struct au_drinfo_fdata *f, *p;
11522 + struct au_drinfo *drinfo;
11523 + struct inode *h_inode;
11524 + struct qstr *qname;
11528 + h_inode = d_inode(h_dentry);
11529 + qname = &h_dentry->d_name;
11530 + drinfo = &f->drinfo;
11531 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11532 + drinfo->oldnamelen = qname->len;
11533 + if (*allocated < sizeof(*f) + qname->len) {
11534 + v = roundup_pow_of_two(*allocated + qname->len);
11535 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11536 + if (unlikely(!p)) {
11544 + drinfo = &f->drinfo;
11546 + memcpy(drinfo->oldname, qname->name, qname->len);
11547 + AuDbg("i%llu, %.*s\n",
11548 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11549 + drinfo->oldname);
11556 +/* callers have to free the return value */
11557 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11559 + struct au_drinfo *ret, *drinfo;
11560 + struct au_drinfo_fdata fdata;
11565 + ret = ERR_PTR(-EIO);
11567 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11568 + if (unlikely(ssz != sizeof(fdata))) {
11569 + AuIOErr("ssz %zd, %u, %pD2\n",
11570 + ssz, (unsigned int)sizeof(fdata), file);
11574 + fdata.magic = ntohl((__force __be32)fdata.magic);
11575 + switch (fdata.magic) {
11576 + case AUFS_DRINFO_MAGIC_V1:
11579 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11580 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11584 + drinfo = &fdata.drinfo;
11585 + len = drinfo->oldnamelen;
11587 + AuIOErr("broken drinfo %pD2\n", file);
11592 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11593 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11594 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11595 + (unsigned long long)drinfo->ino,
11596 + (unsigned long long)h_ino, file);
11597 + goto out; /* success */
11600 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11601 + if (unlikely(!ret)) {
11602 + ret = ERR_PTR(-ENOMEM);
11603 + AuTraceErrPtr(ret);
11608 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11609 + if (unlikely(ssz != len)) {
11610 + au_kfree_rcu(ret);
11611 + ret = ERR_PTR(-EIO);
11612 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11616 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11622 +/* ---------------------------------------------------------------------- */
11624 +/* in order to be revertible */
11625 +struct au_drinfo_rev_elm {
11627 + struct dentry *info_dentry;
11628 + struct au_drinfo *info_last;
11631 +struct au_drinfo_rev {
11632 + unsigned char already;
11633 + aufs_bindex_t nelm;
11634 + struct au_drinfo_rev_elm elm[0];
11637 +/* todo: isn't it too large? */
11638 +struct au_drinfo_store {
11639 + struct path h_ppath;
11640 + struct dentry *h_dentry;
11641 + struct au_drinfo_fdata *fdata;
11642 + char *infoname; /* inside of whname, just after PFX */
11643 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11644 + aufs_bindex_t btgt, btail;
11645 + unsigned char no_sio,
11646 + allocated, /* current size of *fdata */
11647 + infonamelen, /* room size for p */
11648 + whnamelen, /* length of the generated name */
11649 + renameback; /* renamed back */
11652 +/* on rename(2) error, the caller should revert it using @elm */
11653 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11654 + struct au_drinfo_rev_elm *elm)
11659 + struct path infopath = {
11660 + .mnt = w->h_ppath.mnt
11662 + struct inode *h_dir, *h_inode, *delegated;
11663 + struct file *infofile;
11664 + struct qstr *qname;
11667 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11669 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11671 + AuTraceErrPtr(infopath.dentry);
11672 + if (IS_ERR(infopath.dentry)) {
11673 + err = PTR_ERR(infopath.dentry);
11678 + h_dir = d_inode(w->h_ppath.dentry);
11679 + if (elm && d_is_negative(infopath.dentry)) {
11680 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11682 + if (unlikely(err))
11684 + elm->created = 1;
11685 + elm->info_dentry = dget(infopath.dentry);
11688 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11689 + AuTraceErrPtr(infofile);
11690 + if (IS_ERR(infofile)) {
11691 + err = PTR_ERR(infofile);
11695 + h_inode = d_inode(infopath.dentry);
11696 + if (elm && i_size_read(h_inode)) {
11697 + h_inode = d_inode(w->h_dentry);
11698 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11699 + AuTraceErrPtr(elm->info_last);
11700 + if (IS_ERR(elm->info_last)) {
11701 + err = PTR_ERR(elm->info_last);
11702 + elm->info_last = NULL;
11703 + AuDebugOn(elm->info_dentry);
11708 + if (elm && w->renameback) {
11709 + delegated = NULL;
11710 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11712 + if (unlikely(err == -EWOULDBLOCK))
11718 + qname = &w->h_dentry->d_name;
11719 + len = sizeof(*w->fdata) + qname->len;
11721 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11722 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11723 + if (ssz == len) {
11724 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11725 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11726 + goto out_fput; /* success */
11731 + /* the caller should revert it using @elm */
11737 + dput(infopath.dentry);
11743 +struct au_call_drinfo_do_store_args {
11745 + struct au_drinfo_store *w;
11746 + struct au_drinfo_rev_elm *elm;
11749 +static void au_call_drinfo_do_store(void *args)
11751 + struct au_call_drinfo_do_store_args *a = args;
11753 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11756 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11757 + struct au_drinfo_rev_elm *elm)
11759 + int err, wkq_err;
11762 + err = au_drinfo_do_store(w, elm);
11764 + struct au_call_drinfo_do_store_args a = {
11769 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11770 + if (unlikely(wkq_err))
11778 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11779 + aufs_bindex_t btgt)
11783 + memset(w, 0, sizeof(*w));
11784 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11785 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11786 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11787 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11789 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11792 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11793 + if (unlikely(!w->fdata)) {
11797 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11804 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11806 + au_kfree_rcu(w->fdata);
11809 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11810 + struct au_drinfo_store *w)
11812 + struct au_drinfo_rev_elm *elm;
11813 + struct inode *h_dir, *delegated;
11815 + struct path infopath = {
11816 + .mnt = w->h_ppath.mnt
11819 + h_dir = d_inode(w->h_ppath.dentry);
11820 + IMustLock(h_dir);
11824 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11825 + AuDebugOn(elm->created && elm->info_last);
11826 + if (elm->created) {
11828 + delegated = NULL;
11829 + infopath.dentry = elm->info_dentry;
11830 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11833 + if (unlikely(err == -EWOULDBLOCK))
11835 + dput(elm->info_dentry);
11836 + } else if (elm->info_last) {
11838 + w->fdata->drinfo = *elm->info_last;
11839 + memcpy(w->fdata->drinfo.oldname,
11840 + elm->info_last->oldname,
11841 + elm->info_last->oldnamelen);
11842 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11843 + au_kfree_rcu(elm->info_last);
11845 + if (unlikely(err))
11846 + AuIOErr("%d, %s\n", err, w->whname);
11847 + /* go on even if err */
11851 +/* caller has to call au_dr_rename_fin() later */
11852 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11853 + struct qstr *dst_name, void *_rev)
11855 + int err, sz, nelm;
11856 + aufs_bindex_t bindex, btail;
11857 + struct au_drinfo_store work;
11858 + struct au_drinfo_rev *rev, **p;
11859 + struct au_drinfo_rev_elm *elm;
11860 + struct super_block *sb;
11861 + struct au_branch *br;
11862 + struct au_hinode *hdir;
11864 + err = au_drinfo_store_work_init(&work, btgt);
11866 + if (unlikely(err))
11870 + btail = au_dbtaildir(dentry);
11871 + nelm = btail - btgt;
11872 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11873 + rev = kcalloc(1, sz, GFP_NOFS);
11874 + if (unlikely(!rev)) {
11878 + rev->nelm = nelm;
11884 + sb = dentry->d_sb;
11885 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11886 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11887 + hdir = au_hi(d_inode(dentry), btgt);
11888 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11889 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11890 + work.h_dentry = au_h_dptr(dentry, bindex);
11891 + if (!work.h_dentry)
11894 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11895 + &work.allocated);
11897 + if (unlikely(err))
11900 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11901 + br = au_sbr(sb, bindex);
11902 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11903 + work.whnamelen += au_drinfo_name(br, work.infoname,
11904 + work.infonamelen);
11905 + AuDbg("whname %.*s, i%llu, %.*s\n",
11906 + work.whnamelen, work.whname,
11907 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11908 + work.fdata->drinfo.oldnamelen,
11909 + work.fdata->drinfo.oldname);
11911 + err = au_drinfo_store_sio(&work, elm);
11913 + if (unlikely(err))
11916 + if (unlikely(err)) {
11917 + /* revert all drinfo */
11918 + au_drinfo_store_rev(rev, &work);
11919 + au_kfree_try_rcu(rev);
11922 + au_hn_inode_unlock(hdir);
11925 + au_drinfo_store_work_fin(&work);
11930 +/* ---------------------------------------------------------------------- */
11932 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11933 + struct qstr *dst_name, void *_rev)
11935 + int err, already;
11937 + struct super_block *sb;
11938 + struct au_branch *br;
11939 + struct au_dr_br *dr;
11940 + struct dentry *h_dentry;
11941 + struct inode *h_inode;
11942 + struct au_dr_hino *ent;
11943 + struct au_drinfo_rev *rev, **p;
11945 + AuDbg("bindex %d\n", bindex);
11948 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11949 + if (unlikely(!ent))
11953 + br = au_sbr(sb, bindex);
11954 + dr = &br->br_dirren;
11955 + h_dentry = au_h_dptr(src, bindex);
11956 + h_inode = d_inode(h_dentry);
11957 + ino = h_inode->i_ino;
11958 + ent->dr_h_ino = ino;
11959 + already = au_dr_hino_test_add(dr, ino, ent);
11960 + AuDbg("b%d, hi%llu, already %d\n",
11961 + bindex, (unsigned long long)ino, already);
11963 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11968 + rev->already = already;
11969 + goto out; /* success */
11974 + au_dr_hino_del(dr, ent);
11975 + au_kfree_rcu(ent);
11982 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11984 + struct au_drinfo_rev *rev;
11985 + struct au_drinfo_rev_elm *elm;
11990 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11991 + dput(elm->info_dentry);
11992 + au_kfree_rcu(elm->info_last);
11994 + au_kfree_try_rcu(rev);
11997 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
12000 + struct au_drinfo_store work;
12001 + struct au_drinfo_rev *rev = _rev;
12002 + struct super_block *sb;
12003 + struct au_branch *br;
12004 + struct inode *h_inode;
12005 + struct au_dr_br *dr;
12006 + struct au_dr_hino *ent;
12008 + err = au_drinfo_store_work_init(&work, btgt);
12009 + if (unlikely(err))
12013 + br = au_sbr(sb, btgt);
12014 + work.h_ppath.dentry = au_h_dptr(src, btgt);
12015 + work.h_ppath.mnt = au_br_mnt(br);
12016 + au_drinfo_store_rev(rev, &work);
12017 + au_drinfo_store_work_fin(&work);
12018 + if (rev->already)
12021 + dr = &br->br_dirren;
12022 + h_inode = d_inode(work.h_ppath.dentry);
12023 + ent = au_dr_hino_find(dr, h_inode->i_ino);
12025 + au_dr_hino_del(dr, ent);
12026 + au_kfree_rcu(ent);
12029 + au_kfree_try_rcu(rev);
12030 + if (unlikely(err))
12031 + pr_err("failed to remove dirren info\n");
12034 +/* ---------------------------------------------------------------------- */
12036 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
12037 + char *whname, int whnamelen,
12038 + struct dentry **info_dentry)
12040 + struct au_drinfo *drinfo;
12042 + struct inode *h_dir;
12043 + struct path infopath;
12046 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
12048 + *info_dentry = NULL;
12051 + h_dir = d_inode(h_ppath->dentry);
12052 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
12053 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
12055 + if (IS_ERR(infopath.dentry)) {
12056 + drinfo = (void *)infopath.dentry;
12060 + if (d_is_negative(infopath.dentry))
12061 + goto out_dput; /* success */
12063 + infopath.mnt = h_ppath->mnt;
12064 + f = vfsub_dentry_open(&infopath, O_RDONLY);
12065 + inode_unlock_shared(h_dir);
12068 + drinfo = (void *)f;
12072 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
12073 + if (IS_ERR_OR_NULL(drinfo))
12076 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
12077 + *info_dentry = dget(infopath.dentry); /* keep it alive */
12082 + dput(infopath.dentry);
12085 + inode_unlock_shared(h_dir);
12086 + AuTraceErrPtr(drinfo);
12090 +struct au_drinfo_do_load_args {
12091 + struct au_drinfo **drinfop;
12092 + struct path *h_ppath;
12095 + struct dentry **info_dentry;
12098 +static void au_call_drinfo_do_load(void *args)
12100 + struct au_drinfo_do_load_args *a = args;
12102 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
12106 +struct au_drinfo_load {
12107 + struct path h_ppath;
12108 + struct qstr *qname;
12109 + unsigned char no_sio;
12111 + aufs_bindex_t ninfo;
12112 + struct au_drinfo **drinfo;
12115 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
12116 + struct au_branch *br)
12118 + int err, wkq_err, whnamelen, e;
12119 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
12120 + = AUFS_WH_DR_INFO_PFX;
12121 + struct au_drinfo *drinfo;
12122 + struct qstr oldname;
12123 + struct inode *h_dir, *delegated;
12124 + struct dentry *info_dentry;
12125 + struct path infopath;
12127 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
12128 + whnamelen += au_drinfo_name(br, whname + whnamelen,
12129 + sizeof(whname) - whnamelen);
12131 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
12134 + struct au_drinfo_do_load_args args = {
12135 + .drinfop = &drinfo,
12136 + .h_ppath = &w->h_ppath,
12137 + .whname = whname,
12138 + .whnamelen = whnamelen,
12139 + .info_dentry = &info_dentry
12141 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
12142 + if (unlikely(wkq_err))
12143 + drinfo = ERR_PTR(wkq_err);
12145 + err = PTR_ERR(drinfo);
12146 + if (IS_ERR_OR_NULL(drinfo))
12150 + oldname.len = drinfo->oldnamelen;
12151 + oldname.name = drinfo->oldname;
12152 + if (au_qstreq(w->qname, &oldname)) {
12153 + /* the name is renamed back */
12154 + au_kfree_rcu(drinfo);
12157 + infopath.dentry = info_dentry;
12158 + infopath.mnt = w->h_ppath.mnt;
12159 + h_dir = d_inode(w->h_ppath.dentry);
12160 + delegated = NULL;
12161 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
12162 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
12163 + inode_unlock(h_dir);
12165 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
12166 + if (unlikely(e == -EWOULDBLOCK))
12169 + au_kfree_rcu(w->drinfo[bindex]);
12170 + w->drinfo[bindex] = drinfo;
12171 + dput(info_dentry);
12178 +/* ---------------------------------------------------------------------- */
12180 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12182 + struct au_drinfo **p = drinfo;
12185 + au_kfree_rcu(*drinfo++);
12186 + au_kfree_try_rcu(p);
12189 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12190 + aufs_bindex_t btgt)
12193 + struct au_drinfo_load w;
12194 + aufs_bindex_t bindex, bbot;
12195 + struct au_branch *br;
12196 + struct inode *h_dir;
12197 + struct au_dr_hino *ent;
12198 + struct super_block *sb;
12200 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12201 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12202 + AuLNPair(&lkup->whname), btgt);
12204 + sb = dentry->d_sb;
12205 + bbot = au_sbbot(sb);
12206 + w.ninfo = bbot + 1;
12207 + if (!lkup->dirren.drinfo) {
12208 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12209 + sizeof(*lkup->dirren.drinfo),
12211 + if (unlikely(!lkup->dirren.drinfo)) {
12215 + lkup->dirren.ninfo = w.ninfo;
12217 + w.drinfo = lkup->dirren.drinfo;
12218 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12219 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12220 + AuDebugOn(!w.h_ppath.dentry);
12221 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12222 + w.qname = &dentry->d_name;
12225 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12226 + br = au_sbr(sb, bindex);
12227 + err = au_drinfo_load(&w, bindex, br);
12228 + if (unlikely(err))
12230 + if (w.drinfo[bindex])
12234 + br = au_sbr(sb, btgt);
12235 + h_dir = d_inode(w.h_ppath.dentry);
12236 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12238 + au_dr_hino_del(&br->br_dirren, ent);
12239 + au_kfree_rcu(ent);
12241 + goto out; /* success */
12244 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12245 + lkup->dirren.ninfo = 0;
12246 + lkup->dirren.drinfo = NULL;
12252 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12254 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12257 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12260 + struct au_drinfo *drinfo;
12263 + if (!lkup->dirren.drinfo)
12265 + AuDebugOn(lkup->dirren.ninfo < btgt + 1);
12266 + drinfo = lkup->dirren.drinfo[btgt + 1];
12270 + au_kfree_try_rcu(lkup->whname.name);
12271 + lkup->whname.name = NULL;
12272 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12273 + lkup->dirren.dr_name.name = drinfo->oldname;
12274 + lkup->name = &lkup->dirren.dr_name;
12275 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12277 + AuDbg("name %.*s, whname %.*s, b%d\n",
12278 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12286 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12290 + struct au_drinfo *drinfo;
12293 + if (!lkup->dirren.drinfo)
12295 + AuDebugOn(lkup->dirren.ninfo < bindex + 1);
12296 + drinfo = lkup->dirren.drinfo[bindex + 1];
12300 + match = (drinfo->ino == h_ino);
12301 + AuDbg("match %d\n", match);
12307 +/* ---------------------------------------------------------------------- */
12309 +int au_dr_opt_set(struct super_block *sb)
12312 + aufs_bindex_t bindex, bbot;
12313 + struct au_branch *br;
12316 + bbot = au_sbbot(sb);
12317 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12318 + br = au_sbr(sb, bindex);
12319 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12325 +int au_dr_opt_flush(struct super_block *sb)
12328 + aufs_bindex_t bindex, bbot;
12329 + struct au_branch *br;
12332 + bbot = au_sbbot(sb);
12333 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12334 + br = au_sbr(sb, bindex);
12335 + if (au_br_writable(br->br_perm))
12336 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12342 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12345 + aufs_bindex_t bindex, bbot;
12346 + struct au_branch *br;
12350 + err = au_dr_opt_flush(sb);
12351 + if (unlikely(err))
12355 + bbot = au_sbbot(sb);
12356 + for (bindex = 0; bindex <= bbot; bindex++) {
12357 + br = au_sbr(sb, bindex);
12358 + au_dr_hino_free(&br->br_dirren);
12364 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12365 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12366 +++ linux/fs/aufs/dirren.h 2018-08-12 23:43:05.453457863 +0200
12368 +/* SPDX-License-Identifier: GPL-2.0 */
12370 + * Copyright (C) 2017-2018 Junjiro R. Okajima
12372 + * This program, aufs is free software; you can redistribute it and/or modify
12373 + * it under the terms of the GNU General Public License as published by
12374 + * the Free Software Foundation; either version 2 of the License, or
12375 + * (at your option) any later version.
12377 + * This program is distributed in the hope that it will be useful,
12378 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12379 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12380 + * GNU General Public License for more details.
12382 + * You should have received a copy of the GNU General Public License
12383 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12387 + * renamed dir info
12390 +#ifndef __AUFS_DIRREN_H__
12391 +#define __AUFS_DIRREN_H__
12395 +#include <linux/dcache.h>
12396 +#include <linux/statfs.h>
12397 +#include <linux/uuid.h>
12400 +#define AuDirren_NHASH 100
12402 +#ifdef CONFIG_AUFS_DIRREN
12403 +enum au_brid_type {
12410 +struct au_dr_brid {
12411 + enum au_brid_type type;
12413 + uuid_t uuid; /* unimplemented yet */
12419 +/* 20 is the max digits length of ulong 64 */
12420 +/* brid-type "_" uuid "_" inum */
12421 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12422 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12424 +struct au_dr_hino {
12425 + struct hlist_bl_node dr_hnode;
12430 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12431 + struct au_dr_brid dr_brid;
12434 +struct au_dr_lookup {
12435 + /* dr_name is pointed by struct au_do_lookup_args.name */
12436 + struct qstr dr_name; /* subset of dr_info */
12437 + aufs_bindex_t ninfo;
12438 + struct au_drinfo **drinfo;
12441 +struct au_dr_hino;
12443 +struct au_dr_br { };
12444 +struct au_dr_lookup { };
12447 +/* ---------------------------------------------------------------------- */
12450 +struct au_do_lookup_args;
12452 +#ifdef CONFIG_AUFS_DIRREN
12453 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12454 + struct au_dr_hino *add_ent);
12455 +void au_dr_hino_free(struct au_dr_br *dr);
12456 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12457 + const struct path *path);
12458 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12459 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12460 + struct qstr *dst_name, void *_rev);
12461 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12462 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12463 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12464 + aufs_bindex_t bindex);
12465 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12466 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12468 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12469 +int au_dr_opt_set(struct super_block *sb);
12470 +int au_dr_opt_flush(struct super_block *sb);
12471 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12473 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12474 + struct au_dr_hino *add_ent);
12475 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12476 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12477 + const struct path *path);
12478 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12479 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12480 + struct qstr *dst_name, void *_rev);
12481 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12482 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12484 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12485 + aufs_bindex_t bindex);
12486 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12487 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12488 + aufs_bindex_t bindex, ino_t h_ino);
12489 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12490 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12491 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12492 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12495 +/* ---------------------------------------------------------------------- */
12497 +#ifdef CONFIG_AUFS_DIRREN
12498 +static inline int au_dr_ihash(ino_t h_ino)
12500 + return h_ino % AuDirren_NHASH;
12503 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12506 +#endif /* __KERNEL__ */
12507 +#endif /* __AUFS_DIRREN_H__ */
12508 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12509 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12510 +++ linux/fs/aufs/dynop.c 2018-12-27 13:19:17.708416053 +0100
12512 +// SPDX-License-Identifier: GPL-2.0
12514 + * Copyright (C) 2010-2018 Junjiro R. Okajima
12516 + * This program, aufs is free software; you can redistribute it and/or modify
12517 + * it under the terms of the GNU General Public License as published by
12518 + * the Free Software Foundation; either version 2 of the License, or
12519 + * (at your option) any later version.
12521 + * This program is distributed in the hope that it will be useful,
12522 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12523 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12524 + * GNU General Public License for more details.
12526 + * You should have received a copy of the GNU General Public License
12527 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12531 + * dynamically customizable operations for regular files
12536 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12539 + * How large will these lists be?
12540 + * Usually just a few elements, 20-30 at most for each, I guess.
12542 +static struct hlist_bl_head dynop[AuDyLast];
12544 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12545 + const void *h_op)
12547 + struct au_dykey *key, *tmp;
12548 + struct hlist_bl_node *pos;
12551 + hlist_bl_lock(hbl);
12552 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12553 + if (tmp->dk_op.dy_hop == h_op) {
12555 + kref_get(&key->dk_kref);
12558 + hlist_bl_unlock(hbl);
12563 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12565 + struct au_dykey **k, *found;
12566 + const void *h_op = key->dk_op.dy_hop;
12570 + k = br->br_dykey;
12571 + for (i = 0; i < AuBrDynOp; i++)
12573 + if (k[i]->dk_op.dy_hop == h_op) {
12580 + spin_lock(&br->br_dykey_lock);
12581 + for (; i < AuBrDynOp; i++)
12583 + if (k[i]->dk_op.dy_hop == h_op) {
12591 + spin_unlock(&br->br_dykey_lock);
12592 + BUG_ON(i == AuBrDynOp); /* expand the array */
12598 +/* kref_get() if @key is already added */
12599 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12601 + struct au_dykey *tmp, *found;
12602 + struct hlist_bl_node *pos;
12603 + const void *h_op = key->dk_op.dy_hop;
12606 + hlist_bl_lock(hbl);
12607 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12608 + if (tmp->dk_op.dy_hop == h_op) {
12609 + kref_get(&tmp->dk_kref);
12614 + hlist_bl_add_head(&key->dk_hnode, hbl);
12615 + hlist_bl_unlock(hbl);
12622 +static void dy_free_rcu(struct rcu_head *rcu)
12624 + struct au_dykey *key;
12626 + key = container_of(rcu, struct au_dykey, dk_rcu);
12628 + au_kfree_rcu(key);
12631 +static void dy_free(struct kref *kref)
12633 + struct au_dykey *key;
12634 + struct hlist_bl_head *hbl;
12636 + key = container_of(kref, struct au_dykey, dk_kref);
12637 + hbl = dynop + key->dk_op.dy_type;
12638 + au_hbl_del(&key->dk_hnode, hbl);
12639 + call_rcu(&key->dk_rcu, dy_free_rcu);
12642 +void au_dy_put(struct au_dykey *key)
12644 + kref_put(&key->dk_kref, dy_free);
12647 +/* ---------------------------------------------------------------------- */
12649 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12651 +#ifdef CONFIG_AUFS_DEBUG
12652 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12653 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12655 +#define DyDbgDeclare(cnt) do {} while (0)
12656 +#define DyDbgInc(cnt) do {} while (0)
12659 +#define DySet(func, dst, src, h_op, h_sb) do { \
12661 + if (h_op->func) { \
12663 + dst.func = src.func; \
12665 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12669 +#define DySetForce(func, dst, src) do { \
12670 + AuDebugOn(!src.func); \
12672 + dst.func = src.func; \
12675 +#define DySetAop(func) \
12676 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12677 +#define DySetAopForce(func) \
12678 + DySetForce(func, dyaop->da_op, aufs_aop)
12680 +static void dy_aop(struct au_dykey *key, const void *h_op,
12681 + struct super_block *h_sb __maybe_unused)
12683 + struct au_dyaop *dyaop = (void *)key;
12684 + const struct address_space_operations *h_aop = h_op;
12685 + DyDbgDeclare(cnt);
12687 + AuDbg("%s\n", au_sbtype(h_sb));
12689 + DySetAop(writepage);
12690 + DySetAopForce(readpage); /* force */
12691 + DySetAop(writepages);
12692 + DySetAop(set_page_dirty);
12693 + DySetAop(readpages);
12694 + DySetAop(write_begin);
12695 + DySetAop(write_end);
12697 + DySetAop(invalidatepage);
12698 + DySetAop(releasepage);
12699 + DySetAop(freepage);
12700 + /* this one will be changed according to an aufs mount option */
12701 + DySetAop(direct_IO);
12702 + DySetAop(migratepage);
12703 + DySetAop(isolate_page);
12704 + DySetAop(putback_page);
12705 + DySetAop(launder_page);
12706 + DySetAop(is_partially_uptodate);
12707 + DySetAop(is_dirty_writeback);
12708 + DySetAop(error_remove_page);
12709 + DySetAop(swap_activate);
12710 + DySetAop(swap_deactivate);
12712 + DyDbgSize(cnt, *h_aop);
12715 +/* ---------------------------------------------------------------------- */
12717 +static void dy_bug(struct kref *kref)
12722 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12724 + struct au_dykey *key, *old;
12725 + struct hlist_bl_head *hbl;
12728 + void (*set)(struct au_dykey *key, const void *h_op,
12729 + struct super_block *h_sb __maybe_unused);
12731 + static const struct op a[] = {
12733 + .sz = sizeof(struct au_dyaop),
12737 + const struct op *p;
12739 + hbl = dynop + op->dy_type;
12740 + key = dy_gfind_get(hbl, op->dy_hop);
12742 + goto out_add; /* success */
12744 + p = a + op->dy_type;
12745 + key = kzalloc(p->sz, GFP_NOFS);
12746 + if (unlikely(!key)) {
12747 + key = ERR_PTR(-ENOMEM);
12751 + key->dk_op.dy_hop = op->dy_hop;
12752 + kref_init(&key->dk_kref);
12753 + p->set(key, op->dy_hop, au_br_sb(br));
12754 + old = dy_gadd(hbl, key);
12756 + au_kfree_rcu(key);
12761 + old = dy_bradd(br, key);
12763 + /* its ref-count should never be zero here */
12764 + kref_put(&key->dk_kref, dy_bug);
12769 +/* ---------------------------------------------------------------------- */
12771 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12772 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12773 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12774 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12775 + * See the aufs manual in detail.
12777 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12780 + dyaop->da_op.direct_IO = NULL;
12782 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12785 +static struct au_dyaop *dy_aget(struct au_branch *br,
12786 + const struct address_space_operations *h_aop,
12789 + struct au_dyaop *dyaop;
12790 + struct au_dynop op;
12792 + op.dy_type = AuDy_AOP;
12793 + op.dy_haop = h_aop;
12794 + dyaop = (void *)dy_get(&op, br);
12795 + if (IS_ERR(dyaop))
12797 + dy_adx(dyaop, do_dx);
12803 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12804 + struct inode *h_inode)
12807 + struct super_block *sb;
12808 + struct au_branch *br;
12809 + struct au_dyaop *dyaop;
12811 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12812 + IiMustWriteLock(inode);
12814 + sb = inode->i_sb;
12815 + br = au_sbr(sb, bindex);
12816 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12817 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12818 + err = PTR_ERR(dyaop);
12819 + if (IS_ERR(dyaop))
12820 + /* unnecessary to call dy_fput() */
12824 + inode->i_mapping->a_ops = &dyaop->da_op;
12831 + * Is it safe to replace a_ops during the inode/file is in operation?
12832 + * Yes, I hope so.
12834 +int au_dy_irefresh(struct inode *inode)
12837 + aufs_bindex_t btop;
12838 + struct inode *h_inode;
12841 + if (S_ISREG(inode->i_mode)) {
12842 + btop = au_ibtop(inode);
12843 + h_inode = au_h_iptr(inode, btop);
12844 + err = au_dy_iaop(inode, btop, h_inode);
12849 +void au_dy_arefresh(int do_dx)
12851 + struct hlist_bl_head *hbl;
12852 + struct hlist_bl_node *pos;
12853 + struct au_dykey *key;
12855 + hbl = dynop + AuDy_AOP;
12856 + hlist_bl_lock(hbl);
12857 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12858 + dy_adx((void *)key, do_dx);
12859 + hlist_bl_unlock(hbl);
12862 +/* ---------------------------------------------------------------------- */
12864 +void __init au_dy_init(void)
12868 + /* make sure that 'struct au_dykey *' can be any type */
12869 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
12871 + for (i = 0; i < AuDyLast; i++)
12872 + INIT_HLIST_BL_HEAD(dynop + i);
12875 +void au_dy_fin(void)
12879 + for (i = 0; i < AuDyLast; i++)
12880 + WARN_ON(!hlist_bl_empty(dynop + i));
12882 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12883 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12884 +++ linux/fs/aufs/dynop.h 2018-08-12 23:43:05.456791299 +0200
12886 +/* SPDX-License-Identifier: GPL-2.0 */
12888 + * Copyright (C) 2010-2018 Junjiro R. Okajima
12890 + * This program, aufs is free software; you can redistribute it and/or modify
12891 + * it under the terms of the GNU General Public License as published by
12892 + * the Free Software Foundation; either version 2 of the License, or
12893 + * (at your option) any later version.
12895 + * This program is distributed in the hope that it will be useful,
12896 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12897 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12898 + * GNU General Public License for more details.
12900 + * You should have received a copy of the GNU General Public License
12901 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12905 + * dynamically customizable operations (for regular files only)
12908 +#ifndef __AUFS_DYNOP_H__
12909 +#define __AUFS_DYNOP_H__
12913 +#include <linux/fs.h>
12914 +#include <linux/kref.h>
12916 +enum {AuDy_AOP, AuDyLast};
12921 + const void *dy_hop;
12922 + const struct address_space_operations *dy_haop;
12928 + struct hlist_bl_node dk_hnode;
12929 + struct rcu_head dk_rcu;
12931 + struct au_dynop dk_op;
12934 + * during I am in the branch local array, kref is gotten. when the
12935 + * branch is removed, kref is put.
12937 + struct kref dk_kref;
12940 +/* stop unioning since their sizes are very different from each other */
12942 + struct au_dykey da_key;
12943 + struct address_space_operations da_op; /* not const */
12946 +/* ---------------------------------------------------------------------- */
12950 +void au_dy_put(struct au_dykey *key);
12951 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12952 + struct inode *h_inode);
12953 +int au_dy_irefresh(struct inode *inode);
12954 +void au_dy_arefresh(int do_dio);
12956 +void __init au_dy_init(void);
12957 +void au_dy_fin(void);
12959 +#endif /* __KERNEL__ */
12960 +#endif /* __AUFS_DYNOP_H__ */
12961 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12962 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12963 +++ linux/fs/aufs/export.c 2018-10-23 12:33:35.596042364 +0200
12965 +// SPDX-License-Identifier: GPL-2.0
12967 + * Copyright (C) 2005-2018 Junjiro R. Okajima
12969 + * This program, aufs is free software; you can redistribute it and/or modify
12970 + * it under the terms of the GNU General Public License as published by
12971 + * the Free Software Foundation; either version 2 of the License, or
12972 + * (at your option) any later version.
12974 + * This program is distributed in the hope that it will be useful,
12975 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12976 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12977 + * GNU General Public License for more details.
12979 + * You should have received a copy of the GNU General Public License
12980 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12987 +#include <linux/exportfs.h>
12988 +#include <linux/fs_struct.h>
12989 +#include <linux/namei.h>
12990 +#include <linux/nsproxy.h>
12991 +#include <linux/random.h>
12992 +#include <linux/writeback.h>
12996 +#ifdef CONFIG_AUFS_INO_T_64
13004 +static ino_t decode_ino(__u32 *a)
13008 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
13010 +#ifdef CONFIG_AUFS_INO_T_64
13016 +static void encode_ino(__u32 *a, ino_t ino)
13022 +#ifdef CONFIG_AUFS_INO_T_64
13027 +/* NFS file handle */
13031 +#ifdef CONFIG_AUFS_INO_T_64
13032 + /* support 64bit inode number */
13045 + Fh_ino = Fh_ino1,
13046 + Fh_dir_ino = Fh_dir_ino1
13049 +static int au_test_anon(struct dentry *dentry)
13051 + /* note: read d_flags without d_lock */
13052 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
13055 +int au_test_nfsd(void)
13058 + struct task_struct *tsk = current;
13059 + char comm[sizeof(tsk->comm)];
13062 + if (tsk->flags & PF_KTHREAD) {
13063 + get_task_comm(comm, tsk);
13064 + ret = !strcmp(comm, "nfsd");
13070 +/* ---------------------------------------------------------------------- */
13071 +/* inode generation external table */
13073 +void au_xigen_inc(struct inode *inode)
13078 + struct super_block *sb;
13079 + struct au_sbinfo *sbinfo;
13081 + sb = inode->i_sb;
13082 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
13084 + sbinfo = au_sbi(sb);
13085 + pos = inode->i_ino;
13086 + pos *= sizeof(igen);
13087 + igen = inode->i_generation + 1;
13088 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
13089 + sizeof(igen), &pos);
13090 + if (sz == sizeof(igen))
13091 + return; /* success */
13093 + if (unlikely(sz >= 0))
13094 + AuIOErr("xigen error (%zd)\n", sz);
13097 +int au_xigen_new(struct inode *inode)
13102 + struct super_block *sb;
13103 + struct au_sbinfo *sbinfo;
13104 + struct file *file;
13107 + /* todo: dirty, at mount time */
13108 + if (inode->i_ino == AUFS_ROOT_INO)
13110 + sb = inode->i_sb;
13111 + SiMustAnyLock(sb);
13112 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13116 + pos = inode->i_ino;
13117 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
13118 + AuIOErr1("too large i%lld\n", pos);
13121 + pos *= sizeof(inode->i_generation);
13124 + sbinfo = au_sbi(sb);
13125 + file = sbinfo->si_xigen;
13128 + if (vfsub_f_size_read(file)
13129 + < pos + sizeof(inode->i_generation)) {
13130 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
13131 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
13132 + sizeof(inode->i_generation), &pos);
13134 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
13135 + sizeof(inode->i_generation), &pos);
13136 + if (sz == sizeof(inode->i_generation))
13137 + goto out; /* success */
13140 + if (unlikely(sz >= 0)) {
13142 + AuIOErr("xigen error (%zd)\n", sz);
13149 +int au_xigen_set(struct super_block *sb, struct path *path)
13152 + struct au_sbinfo *sbinfo;
13153 + struct file *file;
13155 + SiMustWriteLock(sb);
13157 + sbinfo = au_sbi(sb);
13158 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
13159 + err = PTR_ERR(file);
13160 + if (IS_ERR(file))
13163 + if (sbinfo->si_xigen)
13164 + fput(sbinfo->si_xigen);
13165 + sbinfo->si_xigen = file;
13172 +void au_xigen_clr(struct super_block *sb)
13174 + struct au_sbinfo *sbinfo;
13176 + SiMustWriteLock(sb);
13178 + sbinfo = au_sbi(sb);
13179 + if (sbinfo->si_xigen) {
13180 + fput(sbinfo->si_xigen);
13181 + sbinfo->si_xigen = NULL;
13185 +/* ---------------------------------------------------------------------- */
13187 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13190 + struct dentry *dentry, *d;
13191 + struct inode *inode;
13192 + unsigned int sigen;
13195 + inode = ilookup(sb, ino);
13199 + dentry = ERR_PTR(-ESTALE);
13200 + sigen = au_sigen(sb);
13201 + if (unlikely(au_is_bad_inode(inode)
13202 + || IS_DEADDIR(inode)
13203 + || sigen != au_iigen(inode, NULL)))
13207 + if (!dir_ino || S_ISDIR(inode->i_mode))
13208 + dentry = d_find_alias(inode);
13210 + spin_lock(&inode->i_lock);
13211 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13212 + spin_lock(&d->d_lock);
13213 + if (!au_test_anon(d)
13214 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13215 + dentry = dget_dlock(d);
13216 + spin_unlock(&d->d_lock);
13219 + spin_unlock(&d->d_lock);
13221 + spin_unlock(&inode->i_lock);
13223 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13224 + /* need to refresh */
13232 + AuTraceErrPtr(dentry);
13236 +/* ---------------------------------------------------------------------- */
13238 +/* todo: dirty? */
13239 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13241 +struct au_compare_mnt_args {
13243 + struct super_block *sb;
13246 + struct vfsmount *mnt;
13249 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13251 + struct au_compare_mnt_args *a = arg;
13253 + if (mnt->mnt_sb != a->sb)
13255 + a->mnt = mntget(mnt);
13259 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13262 + struct path root;
13263 + struct au_compare_mnt_args args = {
13267 + get_fs_root(current->fs, &root);
13269 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13270 + rcu_read_unlock();
13273 + AuDebugOn(!args.mnt);
13277 +struct au_nfsd_si_lock {
13278 + unsigned int sigen;
13279 + aufs_bindex_t bindex, br_id;
13280 + unsigned char force_lock;
13283 +static int si_nfsd_read_lock(struct super_block *sb,
13284 + struct au_nfsd_si_lock *nsi_lock)
13287 + aufs_bindex_t bindex;
13289 + si_read_lock(sb, AuLock_FLUSH);
13291 + /* branch id may be wrapped around */
13293 + bindex = au_br_index(sb, nsi_lock->br_id);
13294 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13295 + goto out; /* success */
13299 + if (!nsi_lock->force_lock)
13300 + si_read_unlock(sb);
13303 + nsi_lock->bindex = bindex;
13307 +struct find_name_by_ino {
13308 + struct dir_context ctx;
13309 + int called, found;
13316 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13317 + loff_t offset, u64 ino, unsigned int d_type)
13319 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13323 + if (a->ino != ino)
13326 + memcpy(a->name, name, namelen);
13327 + a->namelen = namelen;
13332 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13333 + struct au_nfsd_si_lock *nsi_lock)
13335 + struct dentry *dentry, *parent;
13336 + struct file *file;
13337 + struct inode *dir;
13338 + struct find_name_by_ino arg = {
13340 + .actor = find_name_by_ino
13345 + parent = path->dentry;
13347 + si_read_unlock(parent->d_sb);
13348 + file = vfsub_dentry_open(path, au_dir_roflags);
13349 + dentry = (void *)file;
13350 + if (IS_ERR(file))
13353 + dentry = ERR_PTR(-ENOMEM);
13354 + arg.name = (void *)__get_free_page(GFP_NOFS);
13355 + if (unlikely(!arg.name))
13362 + err = vfsub_iterate_dir(file, &arg.ctx);
13363 + } while (!err && !arg.found && arg.called);
13364 + dentry = ERR_PTR(err);
13365 + if (unlikely(err))
13367 + /* instead of ENOENT */
13368 + dentry = ERR_PTR(-ESTALE);
13372 + /* do not call vfsub_lkup_one() */
13373 + dir = d_inode(parent);
13374 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13375 + AuTraceErrPtr(dentry);
13376 + if (IS_ERR(dentry))
13378 + AuDebugOn(au_test_anon(dentry));
13379 + if (unlikely(d_really_is_negative(dentry))) {
13381 + dentry = ERR_PTR(-ENOENT);
13385 + free_page((unsigned long)arg.name);
13389 + if (unlikely(nsi_lock
13390 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13391 + if (!IS_ERR(dentry)) {
13393 + dentry = ERR_PTR(-ESTALE);
13395 + AuTraceErrPtr(dentry);
13399 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13401 + struct au_nfsd_si_lock *nsi_lock)
13403 + struct dentry *dentry;
13404 + struct path path;
13406 + if (dir_ino != AUFS_ROOT_INO) {
13407 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13408 + dentry = path.dentry;
13409 + if (!path.dentry || IS_ERR(path.dentry))
13411 + AuDebugOn(au_test_anon(path.dentry));
13413 + path.dentry = dget(sb->s_root);
13415 + path.mnt = au_mnt_get(sb);
13416 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13420 + AuTraceErrPtr(dentry);
13424 +/* ---------------------------------------------------------------------- */
13426 +static int h_acceptable(void *expv, struct dentry *dentry)
13431 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13432 + char *buf, int len, struct super_block *sb)
13436 + struct path path;
13438 + p = d_path(h_rootpath, buf, len);
13443 + path.mnt = h_rootpath->mnt;
13444 + path.dentry = h_parent;
13445 + p = d_path(&path, buf, len);
13451 + path.mnt = au_mnt_get(sb);
13452 + path.dentry = sb->s_root;
13453 + p = d_path(&path, buf, len - strlen(p));
13454 + mntput(path.mnt);
13458 + p[strlen(p)] = '/';
13461 + AuTraceErrPtr(p);
13466 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13467 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13469 + struct dentry *dentry, *h_parent, *root;
13470 + struct super_block *h_sb;
13471 + char *pathname, *p;
13472 + struct vfsmount *h_mnt;
13473 + struct au_branch *br;
13475 + struct path path;
13477 + br = au_sbr(sb, nsi_lock->bindex);
13478 + h_mnt = au_br_mnt(br);
13479 + h_sb = h_mnt->mnt_sb;
13480 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13482 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13483 + fh_len - Fh_tail, fh[Fh_h_type],
13484 + h_acceptable, /*context*/NULL);
13486 + dentry = h_parent;
13487 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13488 + AuWarn1("%s decode_fh failed, %ld\n",
13489 + au_sbtype(h_sb), PTR_ERR(h_parent));
13493 + if (unlikely(au_test_anon(h_parent))) {
13494 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13495 + au_sbtype(h_sb));
13496 + goto out_h_parent;
13499 + dentry = ERR_PTR(-ENOMEM);
13500 + pathname = (void *)__get_free_page(GFP_NOFS);
13501 + if (unlikely(!pathname))
13502 + goto out_h_parent;
13504 + root = sb->s_root;
13505 + path.mnt = h_mnt;
13506 + di_read_lock_parent(root, !AuLock_IR);
13507 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13508 + di_read_unlock(root, !AuLock_IR);
13509 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13510 + dentry = (void *)p;
13512 + goto out_pathname;
13514 + si_read_unlock(sb);
13515 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13516 + dentry = ERR_PTR(err);
13517 + if (unlikely(err))
13520 + dentry = ERR_PTR(-ENOENT);
13521 + AuDebugOn(au_test_anon(path.dentry));
13522 + if (unlikely(d_really_is_negative(path.dentry)))
13525 + if (ino != d_inode(path.dentry)->i_ino)
13526 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13528 + dentry = dget(path.dentry);
13533 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13534 + if (!IS_ERR(dentry)) {
13536 + dentry = ERR_PTR(-ESTALE);
13539 + free_page((unsigned long)pathname);
13543 + AuTraceErrPtr(dentry);
13547 +/* ---------------------------------------------------------------------- */
13549 +static struct dentry *
13550 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13553 + struct dentry *dentry;
13554 + __u32 *fh = fid->raw;
13555 + struct au_branch *br;
13556 + ino_t ino, dir_ino;
13557 + struct au_nfsd_si_lock nsi_lock = {
13561 + dentry = ERR_PTR(-ESTALE);
13562 + /* it should never happen, but the file handle is unreliable */
13563 + if (unlikely(fh_len < Fh_tail))
13565 + nsi_lock.sigen = fh[Fh_sigen];
13566 + nsi_lock.br_id = fh[Fh_br_id];
13568 + /* branch id may be wrapped around */
13570 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13572 + nsi_lock.force_lock = 1;
13574 + /* is this inode still cached? */
13575 + ino = decode_ino(fh + Fh_ino);
13576 + /* it should never happen */
13577 + if (unlikely(ino == AUFS_ROOT_INO))
13580 + dir_ino = decode_ino(fh + Fh_dir_ino);
13581 + dentry = decode_by_ino(sb, ino, dir_ino);
13582 + if (IS_ERR(dentry))
13587 + /* is the parent dir cached? */
13588 + br = au_sbr(sb, nsi_lock.bindex);
13589 + au_lcnt_inc(&br->br_nfiles);
13590 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13591 + if (IS_ERR(dentry))
13596 + /* lookup path */
13597 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13598 + if (IS_ERR(dentry))
13600 + if (unlikely(!dentry))
13601 + /* todo?: make it ESTALE */
13605 + if (!au_digen_test(dentry, au_sigen(sb))
13606 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13607 + goto out_unlock; /* success */
13610 + dentry = ERR_PTR(-ESTALE);
13613 + au_lcnt_dec(&br->br_nfiles);
13614 + si_read_unlock(sb);
13616 + AuTraceErrPtr(dentry);
13620 +#if 0 /* reserved for future use */
13621 +/* support subtreecheck option */
13622 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13623 + int fh_len, int fh_type)
13625 + struct dentry *parent;
13626 + __u32 *fh = fid->raw;
13629 + dir_ino = decode_ino(fh + Fh_dir_ino);
13630 + parent = decode_by_ino(sb, dir_ino, 0);
13631 + if (IS_ERR(parent))
13634 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13635 + dir_ino, fh, fh_len);
13638 + AuTraceErrPtr(parent);
13643 +/* ---------------------------------------------------------------------- */
13645 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13646 + struct inode *dir)
13649 + aufs_bindex_t bindex;
13650 + struct super_block *sb, *h_sb;
13651 + struct dentry *dentry, *parent, *h_parent;
13652 + struct inode *h_dir;
13653 + struct au_branch *br;
13656 + if (unlikely(*max_len <= Fh_tail)) {
13657 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13661 + err = FILEID_ROOT;
13662 + if (inode->i_ino == AUFS_ROOT_INO) {
13663 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13668 + sb = inode->i_sb;
13669 + err = si_read_lock(sb, AuLock_FLUSH);
13670 + if (unlikely(err))
13673 +#ifdef CONFIG_AUFS_DEBUG
13674 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13675 + AuWarn1("NFS-exporting requires xino\n");
13679 + ii_read_lock_child(inode);
13680 + bindex = au_ibtop(inode);
13682 + dentry = d_find_any_alias(inode);
13683 + if (unlikely(!dentry))
13685 + AuDebugOn(au_test_anon(dentry));
13686 + parent = dget_parent(dentry);
13688 + if (unlikely(!parent))
13690 + if (d_really_is_positive(parent))
13691 + dir = d_inode(parent);
13694 + ii_read_lock_parent(dir);
13695 + h_dir = au_h_iptr(dir, bindex);
13696 + ii_read_unlock(dir);
13697 + if (unlikely(!h_dir))
13699 + h_parent = d_find_any_alias(h_dir);
13700 + if (unlikely(!h_parent))
13701 + goto out_hparent;
13704 + br = au_sbr(sb, bindex);
13705 + h_sb = au_br_sb(br);
13706 + if (unlikely(!h_sb->s_export_op)) {
13707 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13708 + goto out_hparent;
13711 + fh[Fh_br_id] = br->br_id;
13712 + fh[Fh_sigen] = au_sigen(sb);
13713 + encode_ino(fh + Fh_ino, inode->i_ino);
13714 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13715 + fh[Fh_igen] = inode->i_generation;
13717 + *max_len -= Fh_tail;
13718 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13720 + /*connectable or subtreecheck*/0);
13721 + err = fh[Fh_h_type];
13722 + *max_len += Fh_tail;
13723 + /* todo: macros? */
13724 + if (err != FILEID_INVALID)
13727 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13734 + ii_read_unlock(inode);
13735 + si_read_unlock(sb);
13737 + if (unlikely(err < 0))
13738 + err = FILEID_INVALID;
13742 +/* ---------------------------------------------------------------------- */
13744 +static int aufs_commit_metadata(struct inode *inode)
13747 + aufs_bindex_t bindex;
13748 + struct super_block *sb;
13749 + struct inode *h_inode;
13750 + int (*f)(struct inode *inode);
13752 + sb = inode->i_sb;
13753 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13754 + ii_write_lock_child(inode);
13755 + bindex = au_ibtop(inode);
13756 + AuDebugOn(bindex < 0);
13757 + h_inode = au_h_iptr(inode, bindex);
13759 + f = h_inode->i_sb->s_export_op->commit_metadata;
13761 + err = f(h_inode);
13763 + struct writeback_control wbc = {
13764 + .sync_mode = WB_SYNC_ALL,
13765 + .nr_to_write = 0 /* metadata only */
13768 + err = sync_inode(h_inode, &wbc);
13771 + au_cpup_attr_timesizes(inode);
13772 + ii_write_unlock(inode);
13773 + si_read_unlock(sb);
13777 +/* ---------------------------------------------------------------------- */
13779 +static struct export_operations aufs_export_op = {
13780 + .fh_to_dentry = aufs_fh_to_dentry,
13781 + /* .fh_to_parent = aufs_fh_to_parent, */
13782 + .encode_fh = aufs_encode_fh,
13783 + .commit_metadata = aufs_commit_metadata
13786 +void au_export_init(struct super_block *sb)
13788 + struct au_sbinfo *sbinfo;
13791 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13792 + && IS_MODULE(CONFIG_EXPORTFS),
13793 + AUFS_NAME ": unsupported configuration "
13794 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13796 + sb->s_export_op = &aufs_export_op;
13797 + sbinfo = au_sbi(sb);
13798 + sbinfo->si_xigen = NULL;
13799 + get_random_bytes(&u, sizeof(u));
13800 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13801 + atomic_set(&sbinfo->si_xigen_next, u);
13803 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13804 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13805 +++ linux/fs/aufs/fhsm.c 2018-10-23 12:33:35.596042364 +0200
13807 +// SPDX-License-Identifier: GPL-2.0
13809 + * Copyright (C) 2011-2018 Junjiro R. Okajima
13811 + * This program, aufs is free software; you can redistribute it and/or modify
13812 + * it under the terms of the GNU General Public License as published by
13813 + * the Free Software Foundation; either version 2 of the License, or
13814 + * (at your option) any later version.
13816 + * This program is distributed in the hope that it will be useful,
13817 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13818 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13819 + * GNU General Public License for more details.
13821 + * You should have received a copy of the GNU General Public License
13822 + * along with this program; if not, write to the Free Software
13823 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13827 + * File-based Hierarchy Storage Management
13830 +#include <linux/anon_inodes.h>
13831 +#include <linux/poll.h>
13832 +#include <linux/seq_file.h>
13833 +#include <linux/statfs.h>
13836 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13838 + struct au_sbinfo *sbinfo;
13839 + struct au_fhsm *fhsm;
13841 + SiMustAnyLock(sb);
13843 + sbinfo = au_sbi(sb);
13844 + fhsm = &sbinfo->si_fhsm;
13845 + AuDebugOn(!fhsm);
13846 + return fhsm->fhsm_bottom;
13849 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13851 + struct au_sbinfo *sbinfo;
13852 + struct au_fhsm *fhsm;
13854 + SiMustWriteLock(sb);
13856 + sbinfo = au_sbi(sb);
13857 + fhsm = &sbinfo->si_fhsm;
13858 + AuDebugOn(!fhsm);
13859 + fhsm->fhsm_bottom = bindex;
13862 +/* ---------------------------------------------------------------------- */
13864 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13866 + struct au_br_fhsm *bf;
13868 + bf = br->br_fhsm;
13869 + MtxMustLock(&bf->bf_lock);
13871 + return !bf->bf_readable
13872 + || time_after(jiffies,
13873 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13876 +/* ---------------------------------------------------------------------- */
13878 +static void au_fhsm_notify(struct super_block *sb, int val)
13880 + struct au_sbinfo *sbinfo;
13881 + struct au_fhsm *fhsm;
13883 + SiMustAnyLock(sb);
13885 + sbinfo = au_sbi(sb);
13886 + fhsm = &sbinfo->si_fhsm;
13887 + if (au_fhsm_pid(fhsm)
13888 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13889 + atomic_set(&fhsm->fhsm_readable, val);
13891 + wake_up(&fhsm->fhsm_wqh);
13895 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13896 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13899 + struct au_branch *br;
13900 + struct au_br_fhsm *bf;
13902 + br = au_sbr(sb, bindex);
13903 + AuDebugOn(au_br_rdonly(br));
13904 + bf = br->br_fhsm;
13908 + mutex_lock(&bf->bf_lock);
13910 + MtxMustLock(&bf->bf_lock);
13912 + /* sb->s_root for NFS is unreliable */
13913 + err = au_br_stfs(br, &bf->bf_stfs);
13914 + if (unlikely(err)) {
13915 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13919 + bf->bf_jiffy = jiffies;
13920 + bf->bf_readable = 1;
13922 + au_fhsm_notify(sb, /*val*/1);
13924 + *rstfs = bf->bf_stfs;
13928 + mutex_unlock(&bf->bf_lock);
13929 + au_fhsm_notify(sb, /*val*/1);
13934 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13937 + struct au_sbinfo *sbinfo;
13938 + struct au_fhsm *fhsm;
13939 + struct au_branch *br;
13940 + struct au_br_fhsm *bf;
13942 + AuDbg("b%d, force %d\n", bindex, force);
13943 + SiMustAnyLock(sb);
13945 + sbinfo = au_sbi(sb);
13946 + fhsm = &sbinfo->si_fhsm;
13947 + if (!au_ftest_si(sbinfo, FHSM)
13948 + || fhsm->fhsm_bottom == bindex)
13951 + br = au_sbr(sb, bindex);
13952 + bf = br->br_fhsm;
13954 + mutex_lock(&bf->bf_lock);
13956 + || au_fhsm_pid(fhsm)
13957 + || au_fhsm_test_jiffy(sbinfo, br))
13958 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13960 + mutex_unlock(&bf->bf_lock);
13963 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13965 + aufs_bindex_t bindex, bbot;
13966 + struct au_branch *br;
13968 + /* exclude the bottom */
13969 + bbot = au_fhsm_bottom(sb);
13970 + for (bindex = 0; bindex < bbot; bindex++) {
13971 + br = au_sbr(sb, bindex);
13972 + if (au_br_fhsm(br->br_perm))
13973 + au_fhsm_wrote(sb, bindex, force);
13977 +/* ---------------------------------------------------------------------- */
13979 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13982 + struct au_sbinfo *sbinfo;
13983 + struct au_fhsm *fhsm;
13986 + sbinfo = file->private_data;
13987 + fhsm = &sbinfo->si_fhsm;
13988 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13989 + if (atomic_read(&fhsm->fhsm_readable))
13990 + mask = EPOLLIN /* | EPOLLRDNORM */;
13993 + AuDbg("mask 0x%x\n", mask);
13997 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13998 + struct aufs_stfs *stfs, __s16 brid)
14002 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
14004 + err = __put_user(brid, &stbr->brid);
14005 + if (unlikely(err))
14011 +static ssize_t au_fhsm_do_read(struct super_block *sb,
14012 + struct aufs_stbr __user *stbr, size_t count)
14016 + aufs_bindex_t bindex, bbot;
14017 + struct au_branch *br;
14018 + struct au_br_fhsm *bf;
14020 + /* except the bottom branch */
14023 + bbot = au_fhsm_bottom(sb);
14024 + for (bindex = 0; !err && bindex < bbot; bindex++) {
14025 + br = au_sbr(sb, bindex);
14026 + if (!au_br_fhsm(br->br_perm))
14029 + bf = br->br_fhsm;
14030 + mutex_lock(&bf->bf_lock);
14031 + if (bf->bf_readable) {
14033 + if (count >= sizeof(*stbr))
14034 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
14037 + bf->bf_readable = 0;
14038 + count -= sizeof(*stbr);
14042 + mutex_unlock(&bf->bf_lock);
14045 + err = sizeof(*stbr) * nstbr;
14050 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
14055 + aufs_bindex_t nfhsm, bindex, bbot;
14056 + struct au_sbinfo *sbinfo;
14057 + struct au_fhsm *fhsm;
14058 + struct au_branch *br;
14059 + struct super_block *sb;
14062 + sbinfo = file->private_data;
14063 + fhsm = &sbinfo->si_fhsm;
14065 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
14066 + if (!atomic_read(&fhsm->fhsm_readable)) {
14067 + if (vfsub_file_flags(file) & O_NONBLOCK)
14070 + err = wait_event_interruptible_locked_irq
14072 + atomic_read(&fhsm->fhsm_readable));
14074 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
14075 + if (unlikely(err))
14078 + /* sb may already be dead */
14079 + au_rw_read_lock(&sbinfo->si_rwsem);
14080 + readable = atomic_read(&fhsm->fhsm_readable);
14081 + if (readable > 0) {
14082 + sb = sbinfo->si_sb;
14084 + /* exclude the bottom branch */
14086 + bbot = au_fhsm_bottom(sb);
14087 + for (bindex = 0; bindex < bbot; bindex++) {
14088 + br = au_sbr(sb, bindex);
14089 + if (au_br_fhsm(br->br_perm))
14093 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
14094 + atomic_set(&fhsm->fhsm_readable, 0);
14095 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
14099 + au_rw_read_unlock(&sbinfo->si_rwsem);
14107 +static int au_fhsm_release(struct inode *inode, struct file *file)
14109 + struct au_sbinfo *sbinfo;
14110 + struct au_fhsm *fhsm;
14112 + /* sb may already be dead */
14113 + sbinfo = file->private_data;
14114 + fhsm = &sbinfo->si_fhsm;
14115 + spin_lock(&fhsm->fhsm_spin);
14116 + fhsm->fhsm_pid = 0;
14117 + spin_unlock(&fhsm->fhsm_spin);
14118 + kobject_put(&sbinfo->si_kobj);
14123 +static const struct file_operations au_fhsm_fops = {
14124 + .owner = THIS_MODULE,
14125 + .llseek = noop_llseek,
14126 + .read = au_fhsm_read,
14127 + .poll = au_fhsm_poll,
14128 + .release = au_fhsm_release
14131 +int au_fhsm_fd(struct super_block *sb, int oflags)
14134 + struct au_sbinfo *sbinfo;
14135 + struct au_fhsm *fhsm;
14138 + if (unlikely(!capable(CAP_SYS_ADMIN)))
14142 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
14146 + sbinfo = au_sbi(sb);
14147 + fhsm = &sbinfo->si_fhsm;
14148 + spin_lock(&fhsm->fhsm_spin);
14149 + if (!fhsm->fhsm_pid)
14150 + fhsm->fhsm_pid = current->pid;
14153 + spin_unlock(&fhsm->fhsm_spin);
14154 + if (unlikely(err))
14157 + oflags |= O_RDONLY;
14158 + /* oflags |= FMODE_NONOTIFY; */
14159 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
14161 + if (unlikely(fd < 0))
14164 + /* succeed regardless 'fhsm' status */
14165 + kobject_get(&sbinfo->si_kobj);
14166 + si_noflush_read_lock(sb);
14167 + if (au_ftest_si(sbinfo, FHSM))
14168 + au_fhsm_wrote_all(sb, /*force*/0);
14169 + si_read_unlock(sb);
14170 + goto out; /* success */
14173 + spin_lock(&fhsm->fhsm_spin);
14174 + fhsm->fhsm_pid = 0;
14175 + spin_unlock(&fhsm->fhsm_spin);
14181 +/* ---------------------------------------------------------------------- */
14183 +int au_fhsm_br_alloc(struct au_branch *br)
14188 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14190 + au_br_fhsm_init(br->br_fhsm);
14197 +/* ---------------------------------------------------------------------- */
14199 +void au_fhsm_fin(struct super_block *sb)
14201 + au_fhsm_notify(sb, /*val*/-1);
14204 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14206 + struct au_fhsm *fhsm;
14208 + fhsm = &sbinfo->si_fhsm;
14209 + spin_lock_init(&fhsm->fhsm_spin);
14210 + init_waitqueue_head(&fhsm->fhsm_wqh);
14211 + atomic_set(&fhsm->fhsm_readable, 0);
14212 + fhsm->fhsm_expire
14213 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14214 + fhsm->fhsm_bottom = -1;
14217 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14219 + sbinfo->si_fhsm.fhsm_expire
14220 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14223 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14227 + if (!au_ftest_si(sbinfo, FHSM))
14230 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14231 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14232 + seq_printf(seq, ",fhsm_sec=%u", u);
14234 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14235 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14236 +++ linux/fs/aufs/file.c 2018-10-23 12:33:35.596042364 +0200
14238 +// SPDX-License-Identifier: GPL-2.0
14240 + * Copyright (C) 2005-2018 Junjiro R. Okajima
14242 + * This program, aufs is free software; you can redistribute it and/or modify
14243 + * it under the terms of the GNU General Public License as published by
14244 + * the Free Software Foundation; either version 2 of the License, or
14245 + * (at your option) any later version.
14247 + * This program is distributed in the hope that it will be useful,
14248 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14249 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14250 + * GNU General Public License for more details.
14252 + * You should have received a copy of the GNU General Public License
14253 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14257 + * handling file/dir, and address_space operation
14260 +#ifdef CONFIG_AUFS_DEBUG
14261 +#include <linux/migrate.h>
14263 +#include <linux/pagemap.h>
14266 +/* drop flags for writing */
14267 +unsigned int au_file_roflags(unsigned int flags)
14269 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14270 + flags |= O_RDONLY | O_NOATIME;
14274 +/* common functions to regular file and dir */
14275 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14276 + struct file *file, int force_wr)
14278 + struct file *h_file;
14279 + struct dentry *h_dentry;
14280 + struct inode *h_inode;
14281 + struct super_block *sb;
14282 + struct au_branch *br;
14283 + struct path h_path;
14286 + /* a race condition can happen between open and unlink/rmdir */
14287 + h_file = ERR_PTR(-ENOENT);
14288 + h_dentry = au_h_dptr(dentry, bindex);
14289 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14291 + h_inode = d_inode(h_dentry);
14292 + spin_lock(&h_dentry->d_lock);
14293 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14294 + /* || !d_inode(dentry)->i_nlink */
14296 + spin_unlock(&h_dentry->d_lock);
14297 + if (unlikely(err))
14300 + sb = dentry->d_sb;
14301 + br = au_sbr(sb, bindex);
14302 + err = au_br_test_oflag(flags, br);
14303 + h_file = ERR_PTR(err);
14304 + if (unlikely(err))
14307 + /* drop flags for writing */
14308 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14309 + if (force_wr && !(flags & O_WRONLY))
14311 + flags = au_file_roflags(flags);
14313 + h_file = ERR_PTR(-EROFS);
14314 + flags = au_file_roflags(flags);
14315 + if (unlikely(vfsub_native_ro(h_inode)
14316 + || IS_APPEND(h_inode)))
14318 + flags &= ~O_ACCMODE;
14319 + flags |= O_WRONLY;
14322 + flags &= ~O_CREAT;
14323 + au_lcnt_inc(&br->br_nfiles);
14324 + h_path.dentry = h_dentry;
14325 + h_path.mnt = au_br_mnt(br);
14326 + h_file = vfsub_dentry_open(&h_path, flags);
14327 + if (IS_ERR(h_file))
14330 + if (flags & __FMODE_EXEC) {
14331 + err = deny_write_access(h_file);
14332 + if (unlikely(err)) {
14334 + h_file = ERR_PTR(err);
14338 + fsnotify_open(h_file);
14339 + goto out; /* success */
14342 + au_lcnt_dec(&br->br_nfiles);
14347 +static int au_cmoo(struct dentry *dentry)
14349 + int err, cmoo, matched;
14350 + unsigned int udba;
14351 + struct path h_path;
14352 + struct au_pin pin;
14353 + struct au_cp_generic cpg = {
14354 + .dentry = dentry,
14359 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14361 + struct inode *delegated;
14362 + struct super_block *sb;
14363 + struct au_sbinfo *sbinfo;
14364 + struct au_fhsm *fhsm;
14366 + struct au_branch *br;
14367 + struct dentry *parent;
14368 + struct au_hinode *hdir;
14370 + DiMustWriteLock(dentry);
14371 + IiMustWriteLock(d_inode(dentry));
14374 + if (IS_ROOT(dentry))
14376 + cpg.bsrc = au_dbtop(dentry);
14380 + sb = dentry->d_sb;
14381 + sbinfo = au_sbi(sb);
14382 + fhsm = &sbinfo->si_fhsm;
14383 + pid = au_fhsm_pid(fhsm);
14386 + && (current->pid == pid
14387 + || rcu_dereference(current->real_parent)->pid == pid));
14388 + rcu_read_unlock();
14392 + br = au_sbr(sb, cpg.bsrc);
14393 + cmoo = au_br_cmoo(br->br_perm);
14396 + if (!d_is_reg(dentry))
14397 + cmoo &= AuBrAttr_COO_ALL;
14401 + parent = dget_parent(dentry);
14402 + di_write_lock_parent(parent);
14403 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14405 + if (unlikely(err < 0)) {
14406 + err = 0; /* there is no upper writable branch */
14409 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14411 + /* do not respect the coo attrib for the target branch */
14412 + err = au_cpup_dirs(dentry, cpg.bdst);
14413 + if (unlikely(err))
14416 + di_downgrade_lock(parent, AuLock_IR);
14417 + udba = au_opt_udba(sb);
14418 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14419 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14420 + if (unlikely(err))
14423 + err = au_sio_cpup_simple(&cpg);
14425 + if (unlikely(err))
14427 + if (!(cmoo & AuBrWAttr_MOO))
14428 + goto out_parent; /* success */
14430 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14431 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14432 + if (unlikely(err))
14435 + h_path.mnt = au_br_mnt(br);
14436 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14437 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14438 + delegated = NULL;
14439 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14441 + /* todo: keep h_dentry or not? */
14442 + if (unlikely(err == -EWOULDBLOCK)) {
14443 + pr_warn("cannot retry for NFSv4 delegation"
14444 + " for an internal unlink\n");
14447 + if (unlikely(err)) {
14448 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14452 + goto out_parent; /* success */
14455 + di_downgrade_lock(parent, AuLock_IR);
14457 + di_read_unlock(parent, AuLock_IR);
14464 +int au_do_open(struct file *file, struct au_do_open_args *args)
14466 + int err, aopen = args->aopen;
14467 + struct dentry *dentry;
14468 + struct au_finfo *finfo;
14471 + err = au_finfo_init(file, args->fidir);
14474 + err = au_finfo_init(file, args->fidir);
14477 + if (unlikely(err))
14480 + dentry = file->f_path.dentry;
14481 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14482 + di_write_lock_child(dentry);
14483 + err = au_cmoo(dentry);
14484 + di_downgrade_lock(dentry, AuLock_IR);
14487 + err = args->open(file, vfsub_file_flags(file), NULL);
14490 + err = args->open(file, vfsub_file_flags(file),
14495 + di_read_unlock(dentry, AuLock_IR);
14497 + finfo = au_fi(file);
14499 + finfo->fi_file = file;
14500 + au_hbl_add(&finfo->fi_hlist,
14501 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14504 + fi_write_unlock(file);
14507 + fi_write_unlock(file);
14510 + if (unlikely(err)) {
14511 + finfo->fi_hdir = NULL;
14512 + au_finfo_fin(file);
14520 +int au_reopen_nondir(struct file *file)
14523 + aufs_bindex_t btop;
14524 + struct dentry *dentry;
14525 + struct au_branch *br;
14526 + struct file *h_file, *h_file_tmp;
14528 + dentry = file->f_path.dentry;
14529 + btop = au_dbtop(dentry);
14530 + br = au_sbr(dentry->d_sb, btop);
14531 + h_file_tmp = NULL;
14532 + if (au_fbtop(file) == btop) {
14533 + h_file = au_hf_top(file);
14534 + if (file->f_mode == h_file->f_mode)
14535 + return 0; /* success */
14536 + h_file_tmp = h_file;
14537 + get_file(h_file_tmp);
14538 + au_lcnt_inc(&br->br_nfiles);
14539 + au_set_h_fptr(file, btop, NULL);
14541 + AuDebugOn(au_fi(file)->fi_hdir);
14544 + * file exists on both of rw and ro
14545 + * open --> dbtop and fbtop are both 0
14546 + * prepend a branch as rw, "rw" become ro
14548 + * delete the top branch, "rw" becomes rw again
14549 + * --> dbtop is 1, fbtop is still 0
14550 + * write --> fbtop is 0 but dbtop is 1
14552 + /* AuDebugOn(au_fbtop(file) < btop); */
14554 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14555 + file, /*force_wr*/0);
14556 + err = PTR_ERR(h_file);
14557 + if (IS_ERR(h_file)) {
14558 + if (h_file_tmp) {
14560 + au_set_h_fptr(file, btop, h_file_tmp);
14561 + h_file_tmp = NULL;
14563 + goto out; /* todo: close all? */
14567 + au_set_fbtop(file, btop);
14568 + au_set_h_fptr(file, btop, h_file);
14569 + au_update_figen(file);
14570 + /* todo: necessary? */
14571 + /* file->f_ra = h_file->f_ra; */
14574 + if (h_file_tmp) {
14575 + fput(h_file_tmp);
14576 + au_lcnt_dec(&br->br_nfiles);
14581 +/* ---------------------------------------------------------------------- */
14583 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14584 + struct dentry *hi_wh)
14587 + aufs_bindex_t btop;
14588 + struct au_dinfo *dinfo;
14589 + struct dentry *h_dentry;
14590 + struct au_hdentry *hdp;
14592 + dinfo = au_di(file->f_path.dentry);
14593 + AuRwMustWriteLock(&dinfo->di_rwsem);
14595 + btop = dinfo->di_btop;
14596 + dinfo->di_btop = btgt;
14597 + hdp = au_hdentry(dinfo, btgt);
14598 + h_dentry = hdp->hd_dentry;
14599 + hdp->hd_dentry = hi_wh;
14600 + err = au_reopen_nondir(file);
14601 + hdp->hd_dentry = h_dentry;
14602 + dinfo->di_btop = btop;
14607 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14608 + aufs_bindex_t bcpup, struct au_pin *pin)
14611 + struct inode *inode, *h_inode;
14612 + struct dentry *h_dentry, *hi_wh;
14613 + struct au_cp_generic cpg = {
14614 + .dentry = file->f_path.dentry,
14621 + au_update_dbtop(cpg.dentry);
14622 + inode = d_inode(cpg.dentry);
14624 + if (au_dbtop(cpg.dentry) <= bcpup
14625 + && au_dbbot(cpg.dentry) >= bcpup) {
14626 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14627 + if (h_dentry && d_is_positive(h_dentry))
14628 + h_inode = d_inode(h_dentry);
14630 + hi_wh = au_hi_wh(inode, bcpup);
14631 + if (!hi_wh && !h_inode)
14632 + err = au_sio_cpup_wh(&cpg, file);
14634 + /* already copied-up after unlink */
14635 + err = au_reopen_wh(file, bcpup, hi_wh);
14638 + && (inode->i_nlink > 1
14639 + || (inode->i_state & I_LINKABLE))
14640 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14641 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14647 + * prepare the @file for writing.
14649 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14652 + aufs_bindex_t dbtop;
14653 + struct dentry *parent;
14654 + struct inode *inode;
14655 + struct super_block *sb;
14656 + struct file *h_file;
14657 + struct au_cp_generic cpg = {
14658 + .dentry = file->f_path.dentry,
14663 + .flags = AuCpup_DTIME
14666 + sb = cpg.dentry->d_sb;
14667 + inode = d_inode(cpg.dentry);
14668 + cpg.bsrc = au_fbtop(file);
14669 + err = au_test_ro(sb, cpg.bsrc, inode);
14670 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14671 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14676 + /* need to cpup or reopen */
14677 + parent = dget_parent(cpg.dentry);
14678 + di_write_lock_parent(parent);
14679 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14681 + if (unlikely(err < 0))
14685 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14686 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14687 + if (unlikely(err))
14691 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14692 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14693 + if (unlikely(err))
14696 + dbtop = au_dbtop(cpg.dentry);
14697 + if (dbtop <= cpg.bdst)
14698 + cpg.bsrc = cpg.bdst;
14700 + if (dbtop <= cpg.bdst /* just reopen */
14701 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14703 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14704 + if (IS_ERR(h_file))
14705 + err = PTR_ERR(h_file);
14707 + di_downgrade_lock(parent, AuLock_IR);
14708 + if (dbtop > cpg.bdst)
14709 + err = au_sio_cpup_simple(&cpg);
14711 + err = au_reopen_nondir(file);
14712 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14714 + } else { /* copyup as wh and reopen */
14716 + * since writable hfsplus branch is not supported,
14717 + * h_open_pre/post() are unnecessary.
14719 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14720 + di_downgrade_lock(parent, AuLock_IR);
14724 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14725 + goto out_dput; /* success */
14731 + di_downgrade_lock(parent, AuLock_IR);
14733 + di_read_unlock(parent, AuLock_IR);
14740 +/* ---------------------------------------------------------------------- */
14742 +int au_do_flush(struct file *file, fl_owner_t id,
14743 + int (*flush)(struct file *file, fl_owner_t id))
14746 + struct super_block *sb;
14747 + struct inode *inode;
14749 + inode = file_inode(file);
14750 + sb = inode->i_sb;
14751 + si_noflush_read_lock(sb);
14752 + fi_read_lock(file);
14753 + ii_read_lock_child(inode);
14755 + err = flush(file, id);
14756 + au_cpup_attr_timesizes(inode);
14758 + ii_read_unlock(inode);
14759 + fi_read_unlock(file);
14760 + si_read_unlock(sb);
14764 +/* ---------------------------------------------------------------------- */
14766 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14769 + struct au_pin pin;
14770 + struct au_finfo *finfo;
14771 + struct dentry *parent, *hi_wh;
14772 + struct inode *inode;
14773 + struct super_block *sb;
14774 + struct au_cp_generic cpg = {
14775 + .dentry = file->f_path.dentry,
14780 + .flags = AuCpup_DTIME
14783 + FiMustWriteLock(file);
14786 + finfo = au_fi(file);
14787 + sb = cpg.dentry->d_sb;
14788 + inode = d_inode(cpg.dentry);
14789 + cpg.bdst = au_ibtop(inode);
14790 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14793 + parent = dget_parent(cpg.dentry);
14794 + if (au_test_ro(sb, cpg.bdst, inode)) {
14795 + di_read_lock_parent(parent, !AuLock_IR);
14796 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14798 + di_read_unlock(parent, !AuLock_IR);
14799 + if (unlikely(err < 0))
14804 + di_read_lock_parent(parent, AuLock_IR);
14805 + hi_wh = au_hi_wh(inode, cpg.bdst);
14806 + if (!S_ISDIR(inode->i_mode)
14807 + && au_opt_test(au_mntflags(sb), PLINK)
14808 + && au_plink_test(inode)
14809 + && !d_unhashed(cpg.dentry)
14810 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14811 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14812 + if (unlikely(err))
14815 + /* always superio. */
14816 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14817 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14819 + err = au_sio_cpup_simple(&cpg);
14822 + } else if (hi_wh) {
14823 + /* already copied-up after unlink */
14824 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14825 + *need_reopen = 0;
14829 + di_read_unlock(parent, AuLock_IR);
14836 +static void au_do_refresh_dir(struct file *file)
14838 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14839 + struct au_hfile *p, tmp, *q;
14840 + struct au_finfo *finfo;
14841 + struct super_block *sb;
14842 + struct au_fidir *fidir;
14844 + FiMustWriteLock(file);
14846 + sb = file->f_path.dentry->d_sb;
14847 + finfo = au_fi(file);
14848 + fidir = finfo->fi_hdir;
14849 + AuDebugOn(!fidir);
14850 + p = fidir->fd_hfile + finfo->fi_btop;
14851 + brid = p->hf_br->br_id;
14852 + bbot = fidir->fd_bbot;
14853 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14857 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14858 + if (new_bindex == bindex)
14860 + if (new_bindex < 0) {
14861 + au_set_h_fptr(file, bindex, NULL);
14865 + /* swap two lower inode, and loop again */
14866 + q = fidir->fd_hfile + new_bindex;
14870 + if (tmp.hf_file) {
14876 + p = fidir->fd_hfile;
14877 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14878 + bbot = au_sbbot(sb);
14879 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14880 + finfo->fi_btop++, p++)
14881 + if (p->hf_file) {
14882 + if (file_inode(p->hf_file))
14884 + au_hfput(p, /*execed*/0);
14887 + bbot = au_br_index(sb, brid);
14888 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14889 + finfo->fi_btop++, p++)
14891 + au_hfput(p, /*execed*/0);
14892 + bbot = au_sbbot(sb);
14895 + p = fidir->fd_hfile + bbot;
14896 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14897 + fidir->fd_bbot--, p--)
14898 + if (p->hf_file) {
14899 + if (file_inode(p->hf_file))
14901 + au_hfput(p, /*execed*/0);
14903 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14907 + * after branch manipulating, refresh the file.
14909 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14911 + int err, need_reopen, nbr;
14912 + aufs_bindex_t bbot, bindex;
14913 + struct dentry *dentry;
14914 + struct super_block *sb;
14915 + struct au_finfo *finfo;
14916 + struct au_hfile *hfile;
14918 + dentry = file->f_path.dentry;
14919 + sb = dentry->d_sb;
14920 + nbr = au_sbbot(sb) + 1;
14921 + finfo = au_fi(file);
14922 + if (!finfo->fi_hdir) {
14923 + hfile = &finfo->fi_htop;
14924 + AuDebugOn(!hfile->hf_file);
14925 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14926 + AuDebugOn(bindex < 0);
14927 + if (bindex != finfo->fi_btop)
14928 + au_set_fbtop(file, bindex);
14930 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14931 + if (unlikely(err))
14933 + au_do_refresh_dir(file);
14938 + if (!au_test_mmapped(file))
14939 + err = au_file_refresh_by_inode(file, &need_reopen);
14940 + if (finfo->fi_hdir)
14941 + /* harmless if err */
14942 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14943 + if (!err && need_reopen && !d_unlinked(dentry))
14944 + err = reopen(file);
14946 + au_update_figen(file);
14947 + goto out; /* success */
14950 + /* error, close all lower files */
14951 + if (finfo->fi_hdir) {
14952 + bbot = au_fbbot_dir(file);
14953 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14954 + au_set_h_fptr(file, bindex, NULL);
14961 +/* common function to regular file and dir */
14962 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14963 + int wlock, unsigned int fi_lsc)
14966 + unsigned int sigen, figen;
14967 + aufs_bindex_t btop;
14968 + unsigned char pseudo_link;
14969 + struct dentry *dentry;
14970 + struct inode *inode;
14973 + dentry = file->f_path.dentry;
14974 + inode = d_inode(dentry);
14975 + sigen = au_sigen(dentry->d_sb);
14976 + fi_write_lock_nested(file, fi_lsc);
14977 + figen = au_figen(file);
14979 + di_write_lock_child(dentry);
14981 + di_write_lock_child2(dentry);
14982 + btop = au_dbtop(dentry);
14983 + pseudo_link = (btop != au_ibtop(inode));
14984 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14986 + di_downgrade_lock(dentry, AuLock_IR);
14987 + fi_downgrade_lock(file);
14989 + goto out; /* success */
14992 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14993 + if (au_digen_test(dentry, sigen)) {
14994 + err = au_reval_dpath(dentry, sigen);
14995 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14999 + err = refresh_file(file, reopen);
15002 + di_downgrade_lock(dentry, AuLock_IR);
15003 + fi_downgrade_lock(file);
15006 + di_write_unlock(dentry);
15007 + fi_write_unlock(file);
15014 +/* ---------------------------------------------------------------------- */
15016 +/* cf. aufs_nopage() */
15017 +/* for madvise(2) */
15018 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
15020 + unlock_page(page);
15024 +/* it will never be called, but necessary to support O_DIRECT */
15025 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
15026 +{ BUG(); return 0; }
15028 +/* they will never be called. */
15029 +#ifdef CONFIG_AUFS_DEBUG
15030 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
15031 + loff_t pos, unsigned len, unsigned flags,
15032 + struct page **pagep, void **fsdata)
15033 +{ AuUnsupport(); return 0; }
15034 +static int aufs_write_end(struct file *file, struct address_space *mapping,
15035 + loff_t pos, unsigned len, unsigned copied,
15036 + struct page *page, void *fsdata)
15037 +{ AuUnsupport(); return 0; }
15038 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
15039 +{ AuUnsupport(); return 0; }
15041 +static int aufs_set_page_dirty(struct page *page)
15042 +{ AuUnsupport(); return 0; }
15043 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
15044 + unsigned int length)
15045 +{ AuUnsupport(); }
15046 +static int aufs_releasepage(struct page *page, gfp_t gfp)
15047 +{ AuUnsupport(); return 0; }
15048 +#if 0 /* called by memory compaction regardless file */
15049 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
15050 + struct page *page, enum migrate_mode mode)
15051 +{ AuUnsupport(); return 0; }
15053 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
15054 +{ AuUnsupport(); return true; }
15055 +static void aufs_putback_page(struct page *page)
15056 +{ AuUnsupport(); }
15057 +static int aufs_launder_page(struct page *page)
15058 +{ AuUnsupport(); return 0; }
15059 +static int aufs_is_partially_uptodate(struct page *page,
15060 + unsigned long from,
15061 + unsigned long count)
15062 +{ AuUnsupport(); return 0; }
15063 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
15065 +{ AuUnsupport(); }
15066 +static int aufs_error_remove_page(struct address_space *mapping,
15067 + struct page *page)
15068 +{ AuUnsupport(); return 0; }
15069 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
15071 +{ AuUnsupport(); return 0; }
15072 +static void aufs_swap_deactivate(struct file *file)
15073 +{ AuUnsupport(); }
15074 +#endif /* CONFIG_AUFS_DEBUG */
15076 +const struct address_space_operations aufs_aop = {
15077 + .readpage = aufs_readpage,
15078 + .direct_IO = aufs_direct_IO,
15079 +#ifdef CONFIG_AUFS_DEBUG
15080 + .writepage = aufs_writepage,
15081 + /* no writepages, because of writepage */
15082 + .set_page_dirty = aufs_set_page_dirty,
15083 + /* no readpages, because of readpage */
15084 + .write_begin = aufs_write_begin,
15085 + .write_end = aufs_write_end,
15086 + /* no bmap, no block device */
15087 + .invalidatepage = aufs_invalidatepage,
15088 + .releasepage = aufs_releasepage,
15089 + /* is fallback_migrate_page ok? */
15090 + /* .migratepage = aufs_migratepage, */
15091 + .isolate_page = aufs_isolate_page,
15092 + .putback_page = aufs_putback_page,
15093 + .launder_page = aufs_launder_page,
15094 + .is_partially_uptodate = aufs_is_partially_uptodate,
15095 + .is_dirty_writeback = aufs_is_dirty_writeback,
15096 + .error_remove_page = aufs_error_remove_page,
15097 + .swap_activate = aufs_swap_activate,
15098 + .swap_deactivate = aufs_swap_deactivate
15099 +#endif /* CONFIG_AUFS_DEBUG */
15101 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
15102 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
15103 +++ linux/fs/aufs/file.h 2018-12-27 13:19:17.708416053 +0100
15105 +/* SPDX-License-Identifier: GPL-2.0 */
15107 + * Copyright (C) 2005-2018 Junjiro R. Okajima
15109 + * This program, aufs is free software; you can redistribute it and/or modify
15110 + * it under the terms of the GNU General Public License as published by
15111 + * the Free Software Foundation; either version 2 of the License, or
15112 + * (at your option) any later version.
15114 + * This program is distributed in the hope that it will be useful,
15115 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15116 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15117 + * GNU General Public License for more details.
15119 + * You should have received a copy of the GNU General Public License
15120 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15124 + * file operations
15127 +#ifndef __AUFS_FILE_H__
15128 +#define __AUFS_FILE_H__
15132 +#include <linux/file.h>
15133 +#include <linux/fs.h>
15134 +#include <linux/mm_types.h>
15135 +#include <linux/poll.h>
15136 +#include "rwsem.h"
15140 + struct file *hf_file;
15141 + struct au_branch *hf_br;
15146 + aufs_bindex_t fd_bbot;
15147 + aufs_bindex_t fd_nent;
15148 + struct au_vdir *fd_vdir_cache;
15149 + struct au_hfile fd_hfile[];
15152 +static inline int au_fidir_sz(int nent)
15154 + AuDebugOn(nent < 0);
15155 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
15159 + atomic_t fi_generation;
15161 + struct au_rwsem fi_rwsem;
15162 + aufs_bindex_t fi_btop;
15164 + /* do not union them */
15165 + struct { /* for non-dir */
15166 + struct au_hfile fi_htop;
15167 + atomic_t fi_mmapped;
15169 + struct au_fidir *fi_hdir; /* for dir only */
15171 + struct hlist_bl_node fi_hlist;
15172 + struct file *fi_file; /* very ugly */
15173 + struct rcu_head rcu;
15174 +} ____cacheline_aligned_in_smp;
15176 +/* ---------------------------------------------------------------------- */
15179 +extern const struct address_space_operations aufs_aop;
15180 +unsigned int au_file_roflags(unsigned int flags);
15181 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15182 + struct file *file, int force_wr);
15183 +struct au_do_open_args {
15185 + int (*open)(struct file *file, int flags,
15186 + struct file *h_file);
15187 + struct au_fidir *fidir;
15188 + struct file *h_file;
15190 +int au_do_open(struct file *file, struct au_do_open_args *args);
15191 +int au_reopen_nondir(struct file *file);
15193 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15194 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15195 + int wlock, unsigned int fi_lsc);
15196 +int au_do_flush(struct file *file, fl_owner_t id,
15197 + int (*flush)(struct file *file, fl_owner_t id));
15200 +#ifdef CONFIG_AUFS_POLL
15201 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15204 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15206 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15208 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15209 + struct file *h_file);
15211 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15212 + aufs_bindex_t bindex, int force_wr)
15213 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15214 + struct file *h_file);
15218 +extern const struct file_operations aufs_file_fop;
15219 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15220 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15221 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15224 +void au_hfput(struct au_hfile *hf, int execed);
15225 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15226 + struct file *h_file);
15228 +void au_update_figen(struct file *file);
15229 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15230 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15232 +void au_fi_init_once(void *_fi);
15233 +void au_finfo_fin(struct file *file);
15234 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15237 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15238 +#ifdef CONFIG_COMPAT
15239 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15240 + unsigned long arg);
15241 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15242 + unsigned long arg);
15245 +/* ---------------------------------------------------------------------- */
15247 +static inline struct au_finfo *au_fi(struct file *file)
15249 + return file->private_data;
15252 +/* ---------------------------------------------------------------------- */
15254 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15255 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15256 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15257 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15259 +#define fi_read_trylock_nested(f) \
15260 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15261 +#define fi_write_trylock_nested(f) \
15262 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15265 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15266 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15267 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15269 +/* lock subclass for finfo */
15275 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15277 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15280 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15282 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15286 + * fi_read_lock_1, fi_write_lock_1,
15287 + * fi_read_lock_2, fi_write_lock_2
15289 +#define AuReadLockFunc(name) \
15290 +static inline void fi_read_lock_##name(struct file *f) \
15291 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15293 +#define AuWriteLockFunc(name) \
15294 +static inline void fi_write_lock_##name(struct file *f) \
15295 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15297 +#define AuRWLockFuncs(name) \
15298 + AuReadLockFunc(name) \
15299 + AuWriteLockFunc(name)
15304 +#undef AuReadLockFunc
15305 +#undef AuWriteLockFunc
15306 +#undef AuRWLockFuncs
15308 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15309 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15310 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15312 +/* ---------------------------------------------------------------------- */
15314 +/* todo: hard/soft set? */
15315 +static inline aufs_bindex_t au_fbtop(struct file *file)
15317 + FiMustAnyLock(file);
15318 + return au_fi(file)->fi_btop;
15321 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15323 + FiMustAnyLock(file);
15324 + AuDebugOn(!au_fi(file)->fi_hdir);
15325 + return au_fi(file)->fi_hdir->fd_bbot;
15328 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15330 + FiMustAnyLock(file);
15331 + AuDebugOn(!au_fi(file)->fi_hdir);
15332 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15335 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15337 + FiMustWriteLock(file);
15338 + au_fi(file)->fi_btop = bindex;
15341 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15343 + FiMustWriteLock(file);
15344 + AuDebugOn(!au_fi(file)->fi_hdir);
15345 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15348 +static inline void au_set_fvdir_cache(struct file *file,
15349 + struct au_vdir *vdir_cache)
15351 + FiMustWriteLock(file);
15352 + AuDebugOn(!au_fi(file)->fi_hdir);
15353 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15356 +static inline struct file *au_hf_top(struct file *file)
15358 + FiMustAnyLock(file);
15359 + AuDebugOn(au_fi(file)->fi_hdir);
15360 + return au_fi(file)->fi_htop.hf_file;
15363 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15365 + FiMustAnyLock(file);
15366 + AuDebugOn(!au_fi(file)->fi_hdir);
15367 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15370 +/* todo: memory barrier? */
15371 +static inline unsigned int au_figen(struct file *f)
15373 + return atomic_read(&au_fi(f)->fi_generation);
15376 +static inline void au_set_mmapped(struct file *f)
15378 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15380 + pr_warn("fi_mmapped wrapped around\n");
15381 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15385 +static inline void au_unset_mmapped(struct file *f)
15387 + atomic_dec(&au_fi(f)->fi_mmapped);
15390 +static inline int au_test_mmapped(struct file *f)
15392 + return atomic_read(&au_fi(f)->fi_mmapped);
15395 +/* customize vma->vm_file */
15397 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15398 + struct file *file)
15402 + f = vma->vm_file;
15404 + vma->vm_file = file;
15409 +#define AuDbgVmRegion(file, vma) do {} while (0)
15411 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15412 + struct file *file)
15414 + au_do_vm_file_reset(vma, file);
15417 +#define AuDbgVmRegion(file, vma) \
15418 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15420 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15421 + struct file *file)
15425 + au_do_vm_file_reset(vma, file);
15426 + f = vma->vm_region->vm_file;
15428 + vma->vm_region->vm_file = file;
15431 +#endif /* CONFIG_MMU */
15433 +/* handle vma->vm_prfile */
15434 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15435 + struct file *file)
15438 + vma->vm_prfile = file;
15439 +#ifndef CONFIG_MMU
15441 + vma->vm_region->vm_prfile = file;
15445 +#endif /* __KERNEL__ */
15446 +#endif /* __AUFS_FILE_H__ */
15447 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15448 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15449 +++ linux/fs/aufs/finfo.c 2018-10-23 12:33:35.596042364 +0200
15451 +// SPDX-License-Identifier: GPL-2.0
15453 + * Copyright (C) 2005-2018 Junjiro R. Okajima
15455 + * This program, aufs is free software; you can redistribute it and/or modify
15456 + * it under the terms of the GNU General Public License as published by
15457 + * the Free Software Foundation; either version 2 of the License, or
15458 + * (at your option) any later version.
15460 + * This program is distributed in the hope that it will be useful,
15461 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15462 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15463 + * GNU General Public License for more details.
15465 + * You should have received a copy of the GNU General Public License
15466 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15470 + * file private data
15475 +void au_hfput(struct au_hfile *hf, int execed)
15478 + allow_write_access(hf->hf_file);
15479 + fput(hf->hf_file);
15480 + hf->hf_file = NULL;
15481 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15482 + hf->hf_br = NULL;
15485 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15487 + struct au_finfo *finfo = au_fi(file);
15488 + struct au_hfile *hf;
15489 + struct au_fidir *fidir;
15491 + fidir = finfo->fi_hdir;
15493 + AuDebugOn(finfo->fi_btop != bindex);
15494 + hf = &finfo->fi_htop;
15496 + hf = fidir->fd_hfile + bindex;
15498 + if (hf && hf->hf_file)
15499 + au_hfput(hf, vfsub_file_execed(file));
15501 + FiMustWriteLock(file);
15502 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15503 + hf->hf_file = val;
15504 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15508 +void au_update_figen(struct file *file)
15510 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15511 + /* smp_mb(); */ /* atomic_set */
15514 +/* ---------------------------------------------------------------------- */
15516 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15518 + struct au_fidir *fidir;
15521 + nbr = au_sbbot(sb) + 1;
15523 + nbr = 2; /* initial allocate for 2 branches */
15524 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15526 + fidir->fd_bbot = -1;
15527 + fidir->fd_nent = nbr;
15533 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15536 + struct au_fidir *fidir, *p;
15538 + AuRwMustWriteLock(&finfo->fi_rwsem);
15539 + fidir = finfo->fi_hdir;
15540 + AuDebugOn(!fidir);
15543 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15544 + GFP_NOFS, may_shrink);
15546 + p->fd_nent = nbr;
15547 + finfo->fi_hdir = p;
15554 +/* ---------------------------------------------------------------------- */
15556 +void au_finfo_fin(struct file *file)
15558 + struct au_finfo *finfo;
15560 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15562 + finfo = au_fi(file);
15563 + AuDebugOn(finfo->fi_hdir);
15564 + AuRwDestroy(&finfo->fi_rwsem);
15565 + au_cache_free_finfo(finfo);
15568 +void au_fi_init_once(void *_finfo)
15570 + struct au_finfo *finfo = _finfo;
15572 + au_rw_init(&finfo->fi_rwsem);
15575 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15578 + struct au_finfo *finfo;
15579 + struct dentry *dentry;
15582 + dentry = file->f_path.dentry;
15583 + finfo = au_cache_alloc_finfo();
15584 + if (unlikely(!finfo))
15588 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15589 + au_rw_write_lock(&finfo->fi_rwsem);
15590 + finfo->fi_btop = -1;
15591 + finfo->fi_hdir = fidir;
15592 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15593 + /* smp_mb(); */ /* atomic_set */
15595 + file->private_data = finfo;
15600 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15601 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15602 +++ linux/fs/aufs/f_op.c 2018-10-23 12:33:35.596042364 +0200
15604 +// SPDX-License-Identifier: GPL-2.0
15606 + * Copyright (C) 2005-2018 Junjiro R. Okajima
15608 + * This program, aufs is free software; you can redistribute it and/or modify
15609 + * it under the terms of the GNU General Public License as published by
15610 + * the Free Software Foundation; either version 2 of the License, or
15611 + * (at your option) any later version.
15613 + * This program is distributed in the hope that it will be useful,
15614 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15615 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15616 + * GNU General Public License for more details.
15618 + * You should have received a copy of the GNU General Public License
15619 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15623 + * file and vm operations
15626 +#include <linux/aio.h>
15627 +#include <linux/fs_stack.h>
15628 +#include <linux/mman.h>
15629 +#include <linux/security.h>
15632 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15635 + aufs_bindex_t bindex;
15636 + struct dentry *dentry, *h_dentry;
15637 + struct au_finfo *finfo;
15638 + struct inode *h_inode;
15640 + FiMustWriteLock(file);
15643 + dentry = file->f_path.dentry;
15644 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15645 + finfo = au_fi(file);
15646 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15647 + atomic_set(&finfo->fi_mmapped, 0);
15648 + bindex = au_dbtop(dentry);
15650 + h_dentry = au_h_dptr(dentry, bindex);
15651 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15652 + if (unlikely(err))
15654 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15655 + if (IS_ERR(h_file)) {
15656 + err = PTR_ERR(h_file);
15660 + h_dentry = h_file->f_path.dentry;
15661 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15662 + if (unlikely(err))
15664 + /* br ref is already inc-ed */
15667 + if ((flags & __O_TMPFILE)
15668 + && !(flags & O_EXCL)) {
15669 + h_inode = file_inode(h_file);
15670 + spin_lock(&h_inode->i_lock);
15671 + h_inode->i_state |= I_LINKABLE;
15672 + spin_unlock(&h_inode->i_lock);
15674 + au_set_fbtop(file, bindex);
15675 + au_set_h_fptr(file, bindex, h_file);
15676 + au_update_figen(file);
15677 + /* todo: necessary? */
15678 + /* file->f_ra = h_file->f_ra; */
15684 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15685 + struct file *file)
15688 + struct super_block *sb;
15689 + struct au_do_open_args args = {
15690 + .open = au_do_open_nondir
15693 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15694 + file, vfsub_file_flags(file), file->f_mode);
15696 + sb = file->f_path.dentry->d_sb;
15697 + si_read_lock(sb, AuLock_FLUSH);
15698 + err = au_do_open(file, &args);
15699 + si_read_unlock(sb);
15703 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15705 + struct au_finfo *finfo;
15706 + aufs_bindex_t bindex;
15708 + finfo = au_fi(file);
15709 + au_hbl_del(&finfo->fi_hlist,
15710 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15711 + bindex = finfo->fi_btop;
15713 + au_set_h_fptr(file, bindex, NULL);
15715 + au_finfo_fin(file);
15719 +/* ---------------------------------------------------------------------- */
15721 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15724 + struct file *h_file;
15727 + h_file = au_hf_top(file);
15729 + err = vfsub_flush(h_file, id);
15733 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15735 + return au_do_flush(file, id, au_do_flush_nondir);
15738 +/* ---------------------------------------------------------------------- */
15740 + * read and write functions acquire [fdi]_rwsem once, but release before
15741 + * mmap_sem. This is because to stop a race condition between mmap(2).
15742 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15743 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15744 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15747 +/* Callers should call au_read_post() or fput() in the end */
15748 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15750 + struct file *h_file;
15753 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15755 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15756 + h_file = au_hf_top(file);
15757 + get_file(h_file);
15759 + fi_read_unlock(file);
15761 + h_file = ERR_PTR(err);
15766 +static void au_read_post(struct inode *inode, struct file *h_file)
15768 + /* update without lock, I don't think it a problem */
15769 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15773 +struct au_write_pre {
15775 + unsigned int lsc;
15779 + aufs_bindex_t btop;
15783 + * return with iinfo is write-locked
15784 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15787 +static struct file *au_write_pre(struct file *file, int do_ready,
15788 + struct au_write_pre *wpre)
15790 + struct file *h_file;
15791 + struct dentry *dentry;
15793 + unsigned int lsc;
15794 + struct au_pin pin;
15799 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15800 + h_file = ERR_PTR(err);
15801 + if (unlikely(err))
15804 + dentry = file->f_path.dentry;
15806 + err = au_ready_to_write(file, -1, &pin);
15807 + if (unlikely(err)) {
15808 + h_file = ERR_PTR(err);
15809 + di_write_unlock(dentry);
15814 + di_downgrade_lock(dentry, /*flags*/0);
15816 + wpre->btop = au_fbtop(file);
15817 + h_file = au_hf_top(file);
15818 + get_file(h_file);
15820 + wpre->blks = file_inode(h_file)->i_blocks;
15823 + di_read_unlock(dentry, /*flags*/0);
15826 + fi_write_unlock(file);
15831 +static void au_write_post(struct inode *inode, struct file *h_file,
15832 + struct au_write_pre *wpre, ssize_t written)
15834 + struct inode *h_inode;
15836 + au_cpup_attr_timesizes(inode);
15837 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15838 + h_inode = file_inode(h_file);
15839 + inode->i_mode = h_inode->i_mode;
15840 + ii_write_unlock(inode);
15841 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15843 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15844 + /*force*/h_inode->i_blocks > wpre->blks);
15848 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
15852 + struct inode *inode;
15853 + struct file *h_file;
15854 + struct super_block *sb;
15856 + inode = file_inode(file);
15857 + sb = inode->i_sb;
15858 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15860 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15861 + err = PTR_ERR(h_file);
15862 + if (IS_ERR(h_file))
15865 + /* filedata may be obsoleted by concurrent copyup, but no problem */
15866 + err = vfsub_read_u(h_file, buf, count, ppos);
15867 + /* todo: necessary? */
15868 + /* file->f_ra = h_file->f_ra; */
15869 + au_read_post(inode, h_file);
15872 + si_read_unlock(sb);
15877 + * todo: very ugly
15878 + * it locks both of i_mutex and si_rwsem for read in safe.
15879 + * if the plink maintenance mode continues forever (that is the problem),
15880 + * may loop forever.
15882 +static void au_mtx_and_read_lock(struct inode *inode)
15885 + struct super_block *sb = inode->i_sb;
15888 + inode_lock(inode);
15889 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15892 + inode_unlock(inode);
15893 + si_read_lock(sb, AuLock_NOPLMW);
15894 + si_read_unlock(sb);
15898 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
15899 + size_t count, loff_t *ppos)
15902 + struct au_write_pre wpre;
15903 + struct inode *inode;
15904 + struct file *h_file;
15905 + char __user *buf = (char __user *)ubuf;
15907 + inode = file_inode(file);
15908 + au_mtx_and_read_lock(inode);
15911 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15912 + err = PTR_ERR(h_file);
15913 + if (IS_ERR(h_file))
15916 + err = vfsub_write_u(h_file, buf, count, ppos);
15917 + au_write_post(inode, h_file, &wpre, err);
15920 + si_read_unlock(inode->i_sb);
15921 + inode_unlock(inode);
15925 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15926 + struct iov_iter *iov_iter)
15929 + struct file *file;
15930 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15932 + err = security_file_permission(h_file, rw);
15933 + if (unlikely(err))
15938 + if (rw == MAY_READ)
15939 + iter = h_file->f_op->read_iter;
15940 + else if (rw == MAY_WRITE)
15941 + iter = h_file->f_op->write_iter;
15943 + file = kio->ki_filp;
15944 + kio->ki_filp = h_file;
15947 + err = iter(kio, iov_iter);
15950 + /* currently there is no such fs */
15952 + kio->ki_filp = file;
15958 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15961 + struct file *file, *h_file;
15962 + struct inode *inode;
15963 + struct super_block *sb;
15965 + file = kio->ki_filp;
15966 + inode = file_inode(file);
15967 + sb = inode->i_sb;
15968 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15970 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15971 + err = PTR_ERR(h_file);
15972 + if (IS_ERR(h_file))
15975 + if (au_test_loopback_kthread()) {
15976 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15977 + if (file->f_mapping != h_file->f_mapping) {
15978 + file->f_mapping = h_file->f_mapping;
15979 + smp_mb(); /* unnecessary? */
15982 + fi_read_unlock(file);
15984 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15985 + /* todo: necessary? */
15986 + /* file->f_ra = h_file->f_ra; */
15987 + au_read_post(inode, h_file);
15990 + si_read_unlock(sb);
15994 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15997 + struct au_write_pre wpre;
15998 + struct inode *inode;
15999 + struct file *file, *h_file;
16001 + file = kio->ki_filp;
16002 + inode = file_inode(file);
16003 + au_mtx_and_read_lock(inode);
16006 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16007 + err = PTR_ERR(h_file);
16008 + if (IS_ERR(h_file))
16011 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
16012 + au_write_post(inode, h_file, &wpre, err);
16015 + si_read_unlock(inode->i_sb);
16016 + inode_unlock(inode);
16020 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
16021 + struct pipe_inode_info *pipe, size_t len,
16022 + unsigned int flags)
16025 + struct file *h_file;
16026 + struct inode *inode;
16027 + struct super_block *sb;
16029 + inode = file_inode(file);
16030 + sb = inode->i_sb;
16031 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16033 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16034 + err = PTR_ERR(h_file);
16035 + if (IS_ERR(h_file))
16038 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
16039 + /* todo: necessary? */
16040 + /* file->f_ra = h_file->f_ra; */
16041 + au_read_post(inode, h_file);
16044 + si_read_unlock(sb);
16049 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
16050 + size_t len, unsigned int flags)
16053 + struct au_write_pre wpre;
16054 + struct inode *inode;
16055 + struct file *h_file;
16057 + inode = file_inode(file);
16058 + au_mtx_and_read_lock(inode);
16061 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16062 + err = PTR_ERR(h_file);
16063 + if (IS_ERR(h_file))
16066 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
16067 + au_write_post(inode, h_file, &wpre, err);
16070 + si_read_unlock(inode->i_sb);
16071 + inode_unlock(inode);
16075 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
16079 + struct au_write_pre wpre;
16080 + struct inode *inode;
16081 + struct file *h_file;
16083 + inode = file_inode(file);
16084 + au_mtx_and_read_lock(inode);
16087 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16088 + err = PTR_ERR(h_file);
16089 + if (IS_ERR(h_file))
16093 + err = vfs_fallocate(h_file, mode, offset, len);
16095 + au_write_post(inode, h_file, &wpre, /*written*/1);
16098 + si_read_unlock(inode->i_sb);
16099 + inode_unlock(inode);
16103 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
16104 + struct file *dst, loff_t dst_pos,
16105 + size_t len, unsigned int flags)
16108 + struct au_write_pre wpre;
16109 + enum { SRC, DST };
16111 + struct inode *inode;
16112 + struct file *h_file;
16113 + struct super_block *h_sb;
16115 +#define a_src a[SRC]
16116 +#define a_dst a[DST]
16119 + a_src.inode = file_inode(src);
16120 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
16122 + a_dst.inode = file_inode(dst);
16123 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
16126 + au_mtx_and_read_lock(a_dst.inode);
16128 + * in order to match the order in di_write_lock2_{child,parent}(),
16129 + * use f_path.dentry for this comparison.
16131 + if (src->f_path.dentry < dst->f_path.dentry) {
16132 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
16133 + err = PTR_ERR(a_src.h_file);
16134 + if (IS_ERR(a_src.h_file))
16137 + wpre.lsc = AuLsc_FI_2;
16138 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16139 + err = PTR_ERR(a_dst.h_file);
16140 + if (IS_ERR(a_dst.h_file)) {
16141 + au_read_post(a_src.inode, a_src.h_file);
16145 + wpre.lsc = AuLsc_FI_1;
16146 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16147 + err = PTR_ERR(a_dst.h_file);
16148 + if (IS_ERR(a_dst.h_file))
16151 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
16152 + err = PTR_ERR(a_src.h_file);
16153 + if (IS_ERR(a_src.h_file)) {
16154 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
16161 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
16162 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
16163 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
16169 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
16170 + dst_pos, len, flags);
16173 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
16174 + fi_read_unlock(src);
16175 + au_read_post(a_src.inode, a_src.h_file);
16177 + si_read_unlock(a_dst.inode->i_sb);
16178 + inode_unlock(a_dst.inode);
16185 +/* ---------------------------------------------------------------------- */
16188 + * The locking order around current->mmap_sem.
16189 + * - in most and regular cases
16190 + * file I/O syscall -- aufs_read() or something
16191 + * -- si_rwsem for read -- mmap_sem
16192 + * (Note that [fdi]i_rwsem are released before mmap_sem).
16194 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
16195 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
16196 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
16197 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
16198 + * It means that when aufs acquires si_rwsem for write, the process should never
16199 + * acquire mmap_sem.
16201 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
16202 + * problem either since any directory is not able to be mmap-ed.
16203 + * The similar scenario is applied to aufs_readlink() too.
16206 +#if 0 /* stop calling security_file_mmap() */
16207 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
16208 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
16210 +static unsigned long au_arch_prot_conv(unsigned long flags)
16212 + /* currently ppc64 only */
16213 +#ifdef CONFIG_PPC64
16214 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16215 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16216 + return AuConv_VM_PROT(flags, SAO);
16218 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16223 +static unsigned long au_prot_conv(unsigned long flags)
16225 + return AuConv_VM_PROT(flags, READ)
16226 + | AuConv_VM_PROT(flags, WRITE)
16227 + | AuConv_VM_PROT(flags, EXEC)
16228 + | au_arch_prot_conv(flags);
16231 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16232 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16234 +static unsigned long au_flag_conv(unsigned long flags)
16236 + return AuConv_VM_MAP(flags, GROWSDOWN)
16237 + | AuConv_VM_MAP(flags, DENYWRITE)
16238 + | AuConv_VM_MAP(flags, LOCKED);
16242 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16245 + const unsigned char wlock
16246 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16247 + struct super_block *sb;
16248 + struct file *h_file;
16249 + struct inode *inode;
16251 + AuDbgVmRegion(file, vma);
16253 + inode = file_inode(file);
16254 + sb = inode->i_sb;
16256 + si_read_lock(sb, AuLock_NOPLMW);
16258 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16260 + err = PTR_ERR(h_file);
16261 + if (IS_ERR(h_file))
16265 + au_set_mmapped(file);
16266 + au_vm_file_reset(vma, h_file);
16268 + * we cannot call security_mmap_file() here since it may acquire
16269 + * mmap_sem or i_mutex.
16271 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16272 + * au_flag_conv(vma->vm_flags));
16275 + err = call_mmap(h_file, vma);
16277 + au_vm_prfile_set(vma, file);
16278 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16279 + goto out_fput; /* success */
16281 + au_unset_mmapped(file);
16282 + au_vm_file_reset(vma, file);
16286 + ii_write_unlock(inode);
16291 + si_read_unlock(sb);
16297 +/* ---------------------------------------------------------------------- */
16299 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16303 + struct au_write_pre wpre;
16304 + struct inode *inode;
16305 + struct file *h_file;
16307 + err = 0; /* -EBADF; */ /* posix? */
16308 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16311 + inode = file_inode(file);
16312 + au_mtx_and_read_lock(inode);
16315 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16316 + err = PTR_ERR(h_file);
16317 + if (IS_ERR(h_file))
16320 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16321 + au_write_post(inode, h_file, &wpre, /*written*/0);
16324 + si_read_unlock(inode->i_sb);
16325 + inode_unlock(inode);
16330 +static int aufs_fasync(int fd, struct file *file, int flag)
16333 + struct file *h_file;
16334 + struct super_block *sb;
16336 + sb = file->f_path.dentry->d_sb;
16337 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16339 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16340 + err = PTR_ERR(h_file);
16341 + if (IS_ERR(h_file))
16344 + if (h_file->f_op->fasync)
16345 + err = h_file->f_op->fasync(fd, h_file, flag);
16346 + fput(h_file); /* instead of au_read_post() */
16349 + si_read_unlock(sb);
16353 +static int aufs_setfl(struct file *file, unsigned long arg)
16356 + struct file *h_file;
16357 + struct super_block *sb;
16359 + sb = file->f_path.dentry->d_sb;
16360 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16362 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16363 + err = PTR_ERR(h_file);
16364 + if (IS_ERR(h_file))
16367 + /* stop calling h_file->fasync */
16368 + arg |= vfsub_file_flags(file) & FASYNC;
16369 + err = setfl(/*unused fd*/-1, h_file, arg);
16370 + fput(h_file); /* instead of au_read_post() */
16373 + si_read_unlock(sb);
16377 +/* ---------------------------------------------------------------------- */
16379 +/* no one supports this operation, currently */
16381 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16382 + size_t len, loff_t *pos, int more)
16387 +/* ---------------------------------------------------------------------- */
16389 +const struct file_operations aufs_file_fop = {
16390 + .owner = THIS_MODULE,
16392 + .llseek = default_llseek,
16394 + .read = aufs_read,
16395 + .write = aufs_write,
16396 + .read_iter = aufs_read_iter,
16397 + .write_iter = aufs_write_iter,
16399 +#ifdef CONFIG_AUFS_POLL
16400 + .poll = aufs_poll,
16402 + .unlocked_ioctl = aufs_ioctl_nondir,
16403 +#ifdef CONFIG_COMPAT
16404 + .compat_ioctl = aufs_compat_ioctl_nondir,
16406 + .mmap = aufs_mmap,
16407 + .open = aufs_open_nondir,
16408 + .flush = aufs_flush_nondir,
16409 + .release = aufs_release_nondir,
16410 + .fsync = aufs_fsync_nondir,
16411 + .fasync = aufs_fasync,
16412 + /* .sendpage = aufs_sendpage, */
16413 + .setfl = aufs_setfl,
16414 + .splice_write = aufs_splice_write,
16415 + .splice_read = aufs_splice_read,
16417 + .aio_splice_write = aufs_aio_splice_write,
16418 + .aio_splice_read = aufs_aio_splice_read,
16420 + .fallocate = aufs_fallocate,
16421 + .copy_file_range = aufs_copy_file_range
16423 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16424 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16425 +++ linux/fs/aufs/fstype.h 2018-08-12 23:43:05.456791299 +0200
16427 +/* SPDX-License-Identifier: GPL-2.0 */
16429 + * Copyright (C) 2005-2018 Junjiro R. Okajima
16431 + * This program, aufs is free software; you can redistribute it and/or modify
16432 + * it under the terms of the GNU General Public License as published by
16433 + * the Free Software Foundation; either version 2 of the License, or
16434 + * (at your option) any later version.
16436 + * This program is distributed in the hope that it will be useful,
16437 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16438 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16439 + * GNU General Public License for more details.
16441 + * You should have received a copy of the GNU General Public License
16442 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16446 + * judging filesystem type
16449 +#ifndef __AUFS_FSTYPE_H__
16450 +#define __AUFS_FSTYPE_H__
16454 +#include <linux/fs.h>
16455 +#include <linux/magic.h>
16456 +#include <linux/nfs_fs.h>
16457 +#include <linux/romfs_fs.h>
16459 +static inline int au_test_aufs(struct super_block *sb)
16461 + return sb->s_magic == AUFS_SUPER_MAGIC;
16464 +static inline const char *au_sbtype(struct super_block *sb)
16466 + return sb->s_type->name;
16469 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16471 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16472 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16478 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16480 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16481 + return sb->s_magic == ROMFS_MAGIC;
16487 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16489 +#if IS_ENABLED(CONFIG_CRAMFS)
16490 + return sb->s_magic == CRAMFS_MAGIC;
16495 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16497 +#if IS_ENABLED(CONFIG_NFS_FS)
16498 + return sb->s_magic == NFS_SUPER_MAGIC;
16504 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16506 +#if IS_ENABLED(CONFIG_FUSE_FS)
16507 + return sb->s_magic == FUSE_SUPER_MAGIC;
16513 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16515 +#if IS_ENABLED(CONFIG_XFS_FS)
16516 + return sb->s_magic == XFS_SB_MAGIC;
16522 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16524 +#ifdef CONFIG_TMPFS
16525 + return sb->s_magic == TMPFS_MAGIC;
16531 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16533 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16534 + return !strcmp(au_sbtype(sb), "ecryptfs");
16540 +static inline int au_test_ramfs(struct super_block *sb)
16542 + return sb->s_magic == RAMFS_MAGIC;
16545 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16547 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16548 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16554 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16556 +#ifdef CONFIG_PROC_FS
16557 + return sb->s_magic == PROC_SUPER_MAGIC;
16563 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16565 +#ifdef CONFIG_SYSFS
16566 + return sb->s_magic == SYSFS_MAGIC;
16572 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16574 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16575 + return sb->s_magic == CONFIGFS_MAGIC;
16581 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16583 +#if IS_ENABLED(CONFIG_MINIX_FS)
16584 + return sb->s_magic == MINIX3_SUPER_MAGIC
16585 + || sb->s_magic == MINIX2_SUPER_MAGIC
16586 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16587 + || sb->s_magic == MINIX_SUPER_MAGIC
16588 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16594 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16596 +#if IS_ENABLED(CONFIG_FAT_FS)
16597 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16603 +static inline int au_test_msdos(struct super_block *sb)
16605 + return au_test_fat(sb);
16608 +static inline int au_test_vfat(struct super_block *sb)
16610 + return au_test_fat(sb);
16613 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16615 +#ifdef CONFIG_SECURITYFS
16616 + return sb->s_magic == SECURITYFS_MAGIC;
16622 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16624 +#if IS_ENABLED(CONFIG_SQUASHFS)
16625 + return sb->s_magic == SQUASHFS_MAGIC;
16631 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16633 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16634 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16640 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16642 +#if IS_ENABLED(CONFIG_XENFS)
16643 + return sb->s_magic == XENFS_SUPER_MAGIC;
16649 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16651 +#ifdef CONFIG_DEBUG_FS
16652 + return sb->s_magic == DEBUGFS_MAGIC;
16658 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16660 +#if IS_ENABLED(CONFIG_NILFS)
16661 + return sb->s_magic == NILFS_SUPER_MAGIC;
16667 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16669 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16670 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16676 +/* ---------------------------------------------------------------------- */
16678 + * they can't be an aufs branch.
16680 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16683 +#ifndef CONFIG_AUFS_BR_RAMFS
16684 + au_test_ramfs(sb) ||
16686 + au_test_procfs(sb)
16687 + || au_test_sysfs(sb)
16688 + || au_test_configfs(sb)
16689 + || au_test_debugfs(sb)
16690 + || au_test_securityfs(sb)
16691 + || au_test_xenfs(sb)
16692 + || au_test_ecryptfs(sb)
16693 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16694 + || au_test_aufs(sb); /* will be supported in next version */
16697 +static inline int au_test_fs_remote(struct super_block *sb)
16699 + return !au_test_tmpfs(sb)
16700 +#ifdef CONFIG_AUFS_BR_RAMFS
16701 + && !au_test_ramfs(sb)
16703 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16706 +/* ---------------------------------------------------------------------- */
16709 + * Note: these functions (below) are created after reading ->getattr() in all
16710 + * filesystems under linux/fs. it means we have to do so in every update...
16714 + * some filesystems require getattr to refresh the inode attributes before
16716 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16717 + * and leave the work for d_revalidate()
16719 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16721 + return au_test_nfs(sb)
16722 + || au_test_fuse(sb)
16723 + /* || au_test_btrfs(sb) */ /* untested */
16728 + * filesystems which don't maintain i_size or i_blocks.
16730 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16732 + return au_test_xfs(sb)
16733 + || au_test_btrfs(sb)
16734 + || au_test_ubifs(sb)
16735 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16736 + /* || au_test_minix(sb) */ /* untested */
16741 + * filesystems which don't store the correct value in some of their inode
16744 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16746 + return au_test_fs_bad_iattr_size(sb)
16747 + || au_test_fat(sb)
16748 + || au_test_msdos(sb)
16749 + || au_test_vfat(sb);
16752 +/* they don't check i_nlink in link(2) */
16753 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16755 + return au_test_tmpfs(sb)
16756 +#ifdef CONFIG_AUFS_BR_RAMFS
16757 + || au_test_ramfs(sb)
16759 + || au_test_ubifs(sb)
16760 + || au_test_hfsplus(sb);
16764 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16766 +static inline int au_test_fs_notime(struct super_block *sb)
16768 + return au_test_nfs(sb)
16769 + || au_test_fuse(sb)
16770 + || au_test_ubifs(sb)
16774 +/* temporary support for i#1 in cramfs */
16775 +static inline int au_test_fs_unique_ino(struct inode *inode)
16777 + if (au_test_cramfs(inode->i_sb))
16778 + return inode->i_ino != 1;
16782 +/* ---------------------------------------------------------------------- */
16785 + * the filesystem where the xino files placed must support i/o after unlink and
16786 + * maintain i_size and i_blocks.
16788 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16790 + return au_test_fs_remote(sb)
16791 + || au_test_fs_bad_iattr_size(sb)
16792 + /* don't want unnecessary work for xino */
16793 + || au_test_aufs(sb)
16794 + || au_test_ecryptfs(sb)
16795 + || au_test_nilfs(sb);
16798 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16800 + return au_test_tmpfs(sb)
16801 + || au_test_ramfs(sb);
16805 + * test if the @sb is real-readonly.
16807 +static inline int au_test_fs_rr(struct super_block *sb)
16809 + return au_test_squashfs(sb)
16810 + || au_test_iso9660(sb)
16811 + || au_test_cramfs(sb)
16812 + || au_test_romfs(sb);
16816 + * test if the @inode is nfs with 'noacl' option
16817 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16819 +static inline int au_test_nfs_noacl(struct inode *inode)
16821 + return au_test_nfs(inode->i_sb)
16822 + /* && IS_POSIXACL(inode) */
16823 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16826 +#endif /* __KERNEL__ */
16827 +#endif /* __AUFS_FSTYPE_H__ */
16828 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16829 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16830 +++ linux/fs/aufs/hbl.h 2018-08-12 23:43:05.456791299 +0200
16832 +/* SPDX-License-Identifier: GPL-2.0 */
16834 + * Copyright (C) 2017-2018 Junjiro R. Okajima
16836 + * This program, aufs is free software; you can redistribute it and/or modify
16837 + * it under the terms of the GNU General Public License as published by
16838 + * the Free Software Foundation; either version 2 of the License, or
16839 + * (at your option) any later version.
16841 + * This program is distributed in the hope that it will be useful,
16842 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16843 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16844 + * GNU General Public License for more details.
16846 + * You should have received a copy of the GNU General Public License
16847 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16851 + * helpers for hlist_bl.h
16854 +#ifndef __AUFS_HBL_H__
16855 +#define __AUFS_HBL_H__
16859 +#include <linux/list_bl.h>
16861 +static inline void au_hbl_add(struct hlist_bl_node *node,
16862 + struct hlist_bl_head *hbl)
16864 + hlist_bl_lock(hbl);
16865 + hlist_bl_add_head(node, hbl);
16866 + hlist_bl_unlock(hbl);
16869 +static inline void au_hbl_del(struct hlist_bl_node *node,
16870 + struct hlist_bl_head *hbl)
16872 + hlist_bl_lock(hbl);
16873 + hlist_bl_del(node);
16874 + hlist_bl_unlock(hbl);
16877 +#define au_hbl_for_each(pos, head) \
16878 + for (pos = hlist_bl_first(head); \
16882 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16884 + unsigned long cnt;
16885 + struct hlist_bl_node *pos;
16888 + hlist_bl_lock(hbl);
16889 + au_hbl_for_each(pos, hbl)
16891 + hlist_bl_unlock(hbl);
16895 +#endif /* __KERNEL__ */
16896 +#endif /* __AUFS_HBL_H__ */
16897 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16898 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16899 +++ linux/fs/aufs/hfsnotify.c 2018-12-27 13:19:17.708416053 +0100
16901 +// SPDX-License-Identifier: GPL-2.0
16903 + * Copyright (C) 2005-2018 Junjiro R. Okajima
16905 + * This program, aufs is free software; you can redistribute it and/or modify
16906 + * it under the terms of the GNU General Public License as published by
16907 + * the Free Software Foundation; either version 2 of the License, or
16908 + * (at your option) any later version.
16910 + * This program is distributed in the hope that it will be useful,
16911 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16912 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16913 + * GNU General Public License for more details.
16915 + * You should have received a copy of the GNU General Public License
16916 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16920 + * fsnotify for the lower directories
16925 +/* FS_IN_IGNORED is unnecessary */
16926 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16927 + | FS_CREATE | FS_EVENT_ON_CHILD);
16928 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16929 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16931 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16933 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16935 + /* AuDbg("here\n"); */
16936 + au_cache_free_hnotify(hn);
16937 + smp_mb__before_atomic(); /* for atomic64_dec */
16938 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16939 + wake_up(&au_hfsn_wq);
16942 +static int au_hfsn_alloc(struct au_hinode *hinode)
16945 + struct au_hnotify *hn;
16946 + struct super_block *sb;
16947 + struct au_branch *br;
16948 + struct fsnotify_mark *mark;
16949 + aufs_bindex_t bindex;
16951 + hn = hinode->hi_notify;
16952 + sb = hn->hn_aufs_inode->i_sb;
16953 + bindex = au_br_index(sb, hinode->hi_id);
16954 + br = au_sbr(sb, bindex);
16955 + AuDebugOn(!br->br_hfsn);
16957 + mark = &hn->hn_mark;
16958 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16959 + mark->mask = AuHfsnMask;
16961 + * by udba rename or rmdir, aufs assign a new inode to the known
16962 + * h_inode, so specify 1 to allow dups.
16965 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16971 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16973 + struct fsnotify_mark *mark;
16974 + unsigned long long ull;
16975 + struct fsnotify_group *group;
16977 + ull = atomic64_inc_return(&au_hfsn_ifree);
16980 + mark = &hn->hn_mark;
16981 + spin_lock(&mark->lock);
16982 + group = mark->group;
16983 + fsnotify_get_group(group);
16984 + spin_unlock(&mark->lock);
16986 + fsnotify_destroy_mark(mark, group);
16987 + fsnotify_put_mark(mark);
16988 + fsnotify_put_group(group);
16991 + /* free hn by myself */
16995 +/* ---------------------------------------------------------------------- */
16997 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16999 + struct fsnotify_mark *mark;
17001 + mark = &hinode->hi_notify->hn_mark;
17002 + spin_lock(&mark->lock);
17004 + AuDebugOn(mark->mask & AuHfsnMask);
17005 + mark->mask |= AuHfsnMask;
17007 + AuDebugOn(!(mark->mask & AuHfsnMask));
17008 + mark->mask &= ~AuHfsnMask;
17010 + spin_unlock(&mark->lock);
17011 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
17014 +/* ---------------------------------------------------------------------- */
17016 +/* #define AuDbgHnotify */
17017 +#ifdef AuDbgHnotify
17018 +static char *au_hfsn_name(u32 mask)
17020 +#ifdef CONFIG_AUFS_DEBUG
17021 +#define test_ret(flag) \
17023 + if (mask & flag) \
17026 + test_ret(FS_ACCESS);
17027 + test_ret(FS_MODIFY);
17028 + test_ret(FS_ATTRIB);
17029 + test_ret(FS_CLOSE_WRITE);
17030 + test_ret(FS_CLOSE_NOWRITE);
17031 + test_ret(FS_OPEN);
17032 + test_ret(FS_MOVED_FROM);
17033 + test_ret(FS_MOVED_TO);
17034 + test_ret(FS_CREATE);
17035 + test_ret(FS_DELETE);
17036 + test_ret(FS_DELETE_SELF);
17037 + test_ret(FS_MOVE_SELF);
17038 + test_ret(FS_UNMOUNT);
17039 + test_ret(FS_Q_OVERFLOW);
17040 + test_ret(FS_IN_IGNORED);
17041 + test_ret(FS_ISDIR);
17042 + test_ret(FS_IN_ONESHOT);
17043 + test_ret(FS_EVENT_ON_CHILD);
17052 +/* ---------------------------------------------------------------------- */
17054 +static void au_hfsn_free_group(struct fsnotify_group *group)
17056 + struct au_br_hfsnotify *hfsn = group->private;
17058 + /* AuDbg("here\n"); */
17059 + au_kfree_try_rcu(hfsn);
17062 +static int au_hfsn_handle_event(struct fsnotify_group *group,
17063 + struct inode *inode,
17064 + u32 mask, const void *data, int data_type,
17065 + const unsigned char *file_name, u32 cookie,
17066 + struct fsnotify_iter_info *iter_info)
17069 + struct au_hnotify *hnotify;
17070 + struct inode *h_dir, *h_inode;
17071 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
17072 + struct fsnotify_mark *inode_mark;
17074 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
17077 + /* if FS_UNMOUNT happens, there must be another bug */
17078 + AuDebugOn(mask & FS_UNMOUNT);
17079 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
17084 +#ifdef AuDbgHnotify
17086 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
17087 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
17088 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
17089 + h_dir->i_ino, mask, au_hfsn_name(mask),
17090 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
17091 + /* WARN_ON(1); */
17096 + inode_mark = fsnotify_iter_inode_mark(iter_info);
17097 + AuDebugOn(!inode_mark);
17098 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
17099 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
17105 +static struct fsnotify_ops au_hfsn_ops = {
17106 + .handle_event = au_hfsn_handle_event,
17107 + .free_group_priv = au_hfsn_free_group,
17108 + .free_mark = au_hfsn_free_mark
17111 +/* ---------------------------------------------------------------------- */
17113 +static void au_hfsn_fin_br(struct au_branch *br)
17115 + struct au_br_hfsnotify *hfsn;
17117 + hfsn = br->br_hfsn;
17120 + fsnotify_put_group(hfsn->hfsn_group);
17125 +static int au_hfsn_init_br(struct au_branch *br, int perm)
17128 + struct fsnotify_group *group;
17129 + struct au_br_hfsnotify *hfsn;
17132 + br->br_hfsn = NULL;
17133 + if (!au_br_hnotifyable(perm))
17137 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
17138 + if (unlikely(!hfsn))
17142 + group = fsnotify_alloc_group(&au_hfsn_ops);
17143 + if (IS_ERR(group)) {
17144 + err = PTR_ERR(group);
17145 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
17149 + group->private = hfsn;
17150 + hfsn->hfsn_group = group;
17151 + br->br_hfsn = hfsn;
17152 + goto out; /* success */
17155 + au_kfree_try_rcu(hfsn);
17160 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
17165 + if (!br->br_hfsn)
17166 + err = au_hfsn_init_br(br, perm);
17171 +/* ---------------------------------------------------------------------- */
17173 +static void au_hfsn_fin(void)
17175 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
17176 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
17179 +const struct au_hnotify_op au_hnotify_op = {
17180 + .ctl = au_hfsn_ctl,
17181 + .alloc = au_hfsn_alloc,
17182 + .free = au_hfsn_free,
17184 + .fin = au_hfsn_fin,
17186 + .reset_br = au_hfsn_reset_br,
17187 + .fin_br = au_hfsn_fin_br,
17188 + .init_br = au_hfsn_init_br
17190 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
17191 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
17192 +++ linux/fs/aufs/hfsplus.c 2018-10-23 12:33:35.596042364 +0200
17194 +// SPDX-License-Identifier: GPL-2.0
17196 + * Copyright (C) 2010-2018 Junjiro R. Okajima
17198 + * This program, aufs is free software; you can redistribute it and/or modify
17199 + * it under the terms of the GNU General Public License as published by
17200 + * the Free Software Foundation; either version 2 of the License, or
17201 + * (at your option) any later version.
17203 + * This program is distributed in the hope that it will be useful,
17204 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17205 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17206 + * GNU General Public License for more details.
17208 + * You should have received a copy of the GNU General Public License
17209 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17213 + * special support for filesystems which acquires an inode mutex
17214 + * at final closing a file, eg, hfsplus.
17216 + * This trick is very simple and stupid, just to open the file before really
17217 + * necessary open to tell hfsplus that this is not the final closing.
17218 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
17219 + * and au_h_open_post() after releasing it.
17224 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
17227 + struct file *h_file;
17228 + struct dentry *h_dentry;
17230 + h_dentry = au_h_dptr(dentry, bindex);
17231 + AuDebugOn(!h_dentry);
17232 + AuDebugOn(d_is_negative(h_dentry));
17235 + if (au_test_hfsplus(h_dentry->d_sb)
17236 + && d_is_reg(h_dentry))
17237 + h_file = au_h_open(dentry, bindex,
17238 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17239 + /*file*/NULL, force_wr);
17243 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17244 + struct file *h_file)
17246 + struct au_branch *br;
17250 + br = au_sbr(dentry->d_sb, bindex);
17251 + au_lcnt_dec(&br->br_nfiles);
17254 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17255 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17256 +++ linux/fs/aufs/hnotify.c 2018-12-27 13:19:17.708416053 +0100
17258 +// SPDX-License-Identifier: GPL-2.0
17260 + * Copyright (C) 2005-2018 Junjiro R. Okajima
17262 + * This program, aufs is free software; you can redistribute it and/or modify
17263 + * it under the terms of the GNU General Public License as published by
17264 + * the Free Software Foundation; either version 2 of the License, or
17265 + * (at your option) any later version.
17267 + * This program is distributed in the hope that it will be useful,
17268 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17269 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17270 + * GNU General Public License for more details.
17272 + * You should have received a copy of the GNU General Public License
17273 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17277 + * abstraction to notify the direct changes on lower directories
17282 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17285 + struct au_hnotify *hn;
17288 + hn = au_cache_alloc_hnotify();
17290 + hn->hn_aufs_inode = inode;
17291 + hinode->hi_notify = hn;
17292 + err = au_hnotify_op.alloc(hinode);
17294 + if (unlikely(err)) {
17295 + hinode->hi_notify = NULL;
17296 + au_cache_free_hnotify(hn);
17298 + * The upper dir was removed by udba, but the same named
17299 + * dir left. In this case, aufs assigns a new inode
17300 + * number and set the monitor again.
17301 + * For the lower dir, the old monitor is still left.
17303 + if (err == -EEXIST)
17312 +void au_hn_free(struct au_hinode *hinode)
17314 + struct au_hnotify *hn;
17316 + hn = hinode->hi_notify;
17318 + hinode->hi_notify = NULL;
17319 + if (au_hnotify_op.free(hinode, hn))
17320 + au_cache_free_hnotify(hn);
17324 +/* ---------------------------------------------------------------------- */
17326 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17328 + if (hinode->hi_notify)
17329 + au_hnotify_op.ctl(hinode, do_set);
17332 +void au_hn_reset(struct inode *inode, unsigned int flags)
17334 + aufs_bindex_t bindex, bbot;
17335 + struct inode *hi;
17336 + struct dentry *iwhdentry;
17338 + bbot = au_ibbot(inode);
17339 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17340 + hi = au_h_iptr(inode, bindex);
17344 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17345 + iwhdentry = au_hi_wh(inode, bindex);
17349 + au_set_h_iptr(inode, bindex, NULL, 0);
17350 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17351 + flags & ~AuHi_XINO);
17354 + /* inode_unlock(hi); */
17358 +/* ---------------------------------------------------------------------- */
17360 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17363 + aufs_bindex_t bindex, bbot, bfound, btop;
17364 + struct inode *h_i;
17367 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17368 + pr_warn("branch root dir was changed\n");
17373 + bbot = au_ibbot(inode);
17374 + btop = au_ibtop(inode);
17375 +#if 0 /* reserved for future use */
17376 + if (bindex == bbot) {
17377 + /* keep this ino in rename case */
17381 + for (bindex = btop; bindex <= bbot; bindex++)
17382 + if (au_h_iptr(inode, bindex) == h_inode) {
17389 + for (bindex = btop; bindex <= bbot; bindex++) {
17390 + h_i = au_h_iptr(inode, bindex);
17394 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17395 + /* ignore this error */
17396 + /* bad action? */
17399 + /* children inode number will be broken */
17406 +static int hn_gen_tree(struct dentry *dentry)
17408 + int err, i, j, ndentry;
17409 + struct au_dcsub_pages dpages;
17410 + struct au_dpage *dpage;
17411 + struct dentry **dentries;
17413 + err = au_dpages_init(&dpages, GFP_NOFS);
17414 + if (unlikely(err))
17416 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17417 + if (unlikely(err))
17420 + for (i = 0; i < dpages.ndpage; i++) {
17421 + dpage = dpages.dpages + i;
17422 + dentries = dpage->dentries;
17423 + ndentry = dpage->ndentry;
17424 + for (j = 0; j < ndentry; j++) {
17425 + struct dentry *d;
17432 + if (d_really_is_positive(d))
17433 + /* todo: reset children xino?
17434 + cached children only? */
17435 + au_iigen_dec(d_inode(d));
17440 + au_dpages_free(&dpages);
17443 + /* discard children */
17444 + dentry_unhash(dentry);
17452 + * return 0 if processed.
17454 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17455 + const unsigned int isdir)
17458 + struct dentry *d;
17459 + struct qstr *dname;
17462 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17463 + pr_warn("branch root dir was changed\n");
17469 + AuDebugOn(!name);
17470 + au_iigen_dec(inode);
17471 + spin_lock(&inode->i_lock);
17472 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17473 + spin_lock(&d->d_lock);
17474 + dname = &d->d_name;
17475 + if (dname->len != nlen
17476 + && memcmp(dname->name, name, nlen)) {
17477 + spin_unlock(&d->d_lock);
17482 + spin_unlock(&d->d_lock);
17485 + spin_unlock(&inode->i_lock);
17487 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17488 + d = d_find_any_alias(inode);
17490 + au_iigen_dec(inode);
17494 + spin_lock(&d->d_lock);
17495 + dname = &d->d_name;
17496 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17497 + spin_unlock(&d->d_lock);
17498 + err = hn_gen_tree(d);
17499 + spin_lock(&d->d_lock);
17501 + spin_unlock(&d->d_lock);
17510 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17514 + if (IS_ROOT(dentry)) {
17515 + pr_warn("branch root dir was changed\n");
17521 + au_digen_dec(dentry);
17522 + if (d_really_is_positive(dentry))
17523 + au_iigen_dec(d_inode(dentry));
17525 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17526 + if (d_really_is_positive(dentry))
17527 + err = hn_gen_tree(dentry);
17534 +/* ---------------------------------------------------------------------- */
17536 +/* hnotify job flags */
17537 +#define AuHnJob_XINO0 1
17538 +#define AuHnJob_GEN (1 << 1)
17539 +#define AuHnJob_DIRENT (1 << 2)
17540 +#define AuHnJob_ISDIR (1 << 3)
17541 +#define AuHnJob_TRYXINO0 (1 << 4)
17542 +#define AuHnJob_MNTPNT (1 << 5)
17543 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17544 +#define au_fset_hnjob(flags, name) \
17545 + do { (flags) |= AuHnJob_##name; } while (0)
17546 +#define au_fclr_hnjob(flags, name) \
17547 + do { (flags) &= ~AuHnJob_##name; } while (0)
17555 +struct au_hnotify_args {
17556 + struct inode *h_dir, *dir, *h_child_inode;
17558 + unsigned int flags[AuHnLast];
17559 + unsigned int h_child_nlen;
17560 + char h_child_name[];
17563 +struct hn_job_args {
17564 + unsigned int flags;
17565 + struct inode *inode, *h_inode, *dir, *h_dir;
17566 + struct dentry *dentry;
17571 +static int hn_job(struct hn_job_args *a)
17573 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17577 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17578 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17580 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17583 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17584 + if (!a->h_inode->i_nlink
17585 + && !(a->h_inode->i_state & I_LINKABLE))
17586 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17587 + inode_unlock_shared(a->h_inode);
17590 + /* make the generation obsolete */
17591 + if (au_ftest_hnjob(a->flags, GEN)) {
17594 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17596 + if (e && a->dentry)
17597 + hn_gen_by_name(a->dentry, isdir);
17598 + /* ignore this error */
17601 + /* make dir entries obsolete */
17602 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17603 + struct au_vdir *vdir;
17605 + vdir = au_ivdir(a->inode);
17607 + vdir->vd_jiffy = 0;
17608 + /* IMustLock(a->inode); */
17609 + /* inode_inc_iversion(a->inode); */
17612 + /* can do nothing but warn */
17613 + if (au_ftest_hnjob(a->flags, MNTPNT)
17615 + && d_mountpoint(a->dentry))
17616 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17621 +/* ---------------------------------------------------------------------- */
17623 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17624 + struct inode *dir)
17626 + struct dentry *dentry, *d, *parent;
17627 + struct qstr *dname;
17629 + parent = d_find_any_alias(dir);
17634 + spin_lock(&parent->d_lock);
17635 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17636 + /* AuDbg("%pd\n", d); */
17637 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17638 + dname = &d->d_name;
17639 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17640 + goto cont_unlock;
17644 + goto cont_unlock;
17645 + if (au_dcount(d) > 0) {
17646 + dentry = dget_dlock(d);
17647 + spin_unlock(&d->d_lock);
17652 + spin_unlock(&d->d_lock);
17654 + spin_unlock(&parent->d_lock);
17658 + di_write_lock_child(dentry);
17663 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17664 + aufs_bindex_t bindex, ino_t h_ino)
17666 + struct inode *inode;
17671 + err = au_xino_read(sb, bindex, h_ino, &ino);
17673 + inode = ilookup(sb, ino);
17677 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17678 + pr_warn("wrong root branch\n");
17684 + ii_write_lock_child(inode);
17690 +static void au_hn_bh(void *_args)
17692 + struct au_hnotify_args *a = _args;
17693 + struct super_block *sb;
17694 + aufs_bindex_t bindex, bbot, bfound;
17695 + unsigned char xino, try_iput;
17697 + struct inode *inode;
17699 + struct hn_job_args args;
17700 + struct dentry *dentry;
17701 + struct au_sbinfo *sbinfo;
17703 + AuDebugOn(!_args);
17704 + AuDebugOn(!a->h_dir);
17705 + AuDebugOn(!a->dir);
17706 + AuDebugOn(!a->mask);
17707 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17708 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17709 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17714 + * do not lock a->dir->i_mutex here
17715 + * because of d_revalidate() may cause a deadlock.
17717 + sb = a->dir->i_sb;
17719 + sbinfo = au_sbi(sb);
17720 + AuDebugOn(!sbinfo);
17721 + si_write_lock(sb, AuLock_NOPLMW);
17723 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17724 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17725 + case FS_MOVED_FROM:
17726 + case FS_MOVED_TO:
17727 + AuWarn1("DIRREN with UDBA may not work correctly "
17728 + "for the direct rename(2)\n");
17731 + ii_read_lock_parent(a->dir);
17733 + bbot = au_ibbot(a->dir);
17734 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17735 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17739 + ii_read_unlock(a->dir);
17740 + if (unlikely(bfound < 0))
17743 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17745 + if (a->h_child_inode)
17746 + h_ino = a->h_child_inode->i_ino;
17748 + if (a->h_child_nlen
17749 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17750 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17751 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17754 + if (dentry && d_really_is_positive(dentry))
17755 + inode = d_inode(dentry);
17756 + if (xino && !inode && h_ino
17757 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17758 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17759 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17760 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17764 + args.flags = a->flags[AuHn_CHILD];
17765 + args.dentry = dentry;
17766 + args.inode = inode;
17767 + args.h_inode = a->h_child_inode;
17768 + args.dir = a->dir;
17769 + args.h_dir = a->h_dir;
17770 + args.h_name = a->h_child_name;
17771 + args.h_nlen = a->h_child_nlen;
17772 + err = hn_job(&args);
17774 + if (au_di(dentry))
17775 + di_write_unlock(dentry);
17778 + if (inode && try_iput) {
17779 + ii_write_unlock(inode);
17783 + ii_write_lock_parent(a->dir);
17784 + args.flags = a->flags[AuHn_PARENT];
17785 + args.dentry = NULL;
17786 + args.inode = a->dir;
17787 + args.h_inode = a->h_dir;
17789 + args.h_dir = NULL;
17790 + args.h_name = NULL;
17792 + err = hn_job(&args);
17793 + ii_write_unlock(a->dir);
17796 + iput(a->h_child_inode);
17799 + si_write_unlock(sb);
17800 + au_nwt_done(&sbinfo->si_nowait);
17804 +/* ---------------------------------------------------------------------- */
17806 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17807 + struct qstr *h_child_qstr, struct inode *h_child_inode)
17810 + unsigned int flags[AuHnLast], f;
17811 + unsigned char isdir, isroot, wh;
17812 + struct inode *dir;
17813 + struct au_hnotify_args *args;
17814 + char *p, *h_child_name;
17817 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17818 + dir = igrab(hnotify->hn_aufs_inode);
17822 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17824 + h_child_name = (void *)h_child_qstr->name;
17825 + len = h_child_qstr->len;
17826 + if (h_child_name) {
17827 + if (len > AUFS_WH_PFX_LEN
17828 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17829 + h_child_name += AUFS_WH_PFX_LEN;
17830 + len -= AUFS_WH_PFX_LEN;
17836 + if (h_child_inode)
17837 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17838 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17839 + flags[AuHn_CHILD] = 0;
17841 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17842 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17843 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17844 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
17845 + case FS_MOVED_FROM:
17846 + case FS_MOVED_TO:
17847 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17848 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17851 + AuDebugOn(!h_child_name);
17856 + * aufs never be able to get this child inode.
17857 + * revalidation should be in d_revalidate()
17858 + * by checking i_nlink, i_generation or d_unhashed().
17860 + AuDebugOn(!h_child_name);
17861 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17862 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17870 + h_child_inode = NULL;
17873 + /* iput() and kfree() will be called in au_hnotify() */
17874 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17875 + if (unlikely(!args)) {
17876 + AuErr1("no memory\n");
17880 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17881 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17882 + args->mask = mask;
17884 + args->h_dir = igrab(h_dir);
17885 + if (h_child_inode)
17886 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17887 + args->h_child_inode = h_child_inode;
17888 + args->h_child_nlen = len;
17890 + p = (void *)args;
17891 + p += sizeof(*args);
17892 + memcpy(p, h_child_name, len);
17896 + /* NFS fires the event for silly-renamed one from kworker */
17898 + if (!dir->i_nlink
17899 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17901 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17902 + if (unlikely(err)) {
17903 + pr_err("wkq %d\n", err);
17904 + iput(args->h_child_inode);
17905 + iput(args->h_dir);
17907 + au_kfree_rcu(args);
17914 +/* ---------------------------------------------------------------------- */
17916 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17920 + AuDebugOn(!(udba & AuOptMask_UDBA));
17923 + if (au_hnotify_op.reset_br)
17924 + err = au_hnotify_op.reset_br(udba, br, perm);
17929 +int au_hnotify_init_br(struct au_branch *br, int perm)
17934 + if (au_hnotify_op.init_br)
17935 + err = au_hnotify_op.init_br(br, perm);
17940 +void au_hnotify_fin_br(struct au_branch *br)
17942 + if (au_hnotify_op.fin_br)
17943 + au_hnotify_op.fin_br(br);
17946 +static void au_hn_destroy_cache(void)
17948 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17949 + au_cache[AuCache_HNOTIFY] = NULL;
17952 +int __init au_hnotify_init(void)
17957 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17958 + if (au_cache[AuCache_HNOTIFY]) {
17960 + if (au_hnotify_op.init)
17961 + err = au_hnotify_op.init();
17962 + if (unlikely(err))
17963 + au_hn_destroy_cache();
17969 +void au_hnotify_fin(void)
17971 + if (au_hnotify_op.fin)
17972 + au_hnotify_op.fin();
17974 + /* cf. au_cache_fin() */
17975 + if (au_cache[AuCache_HNOTIFY])
17976 + au_hn_destroy_cache();
17978 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17979 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17980 +++ linux/fs/aufs/iinfo.c 2018-12-27 13:19:17.711749485 +0100
17982 +// SPDX-License-Identifier: GPL-2.0
17984 + * Copyright (C) 2005-2018 Junjiro R. Okajima
17986 + * This program, aufs is free software; you can redistribute it and/or modify
17987 + * it under the terms of the GNU General Public License as published by
17988 + * the Free Software Foundation; either version 2 of the License, or
17989 + * (at your option) any later version.
17991 + * This program is distributed in the hope that it will be useful,
17992 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17993 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17994 + * GNU General Public License for more details.
17996 + * You should have received a copy of the GNU General Public License
17997 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18001 + * inode private data
18006 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
18008 + struct inode *h_inode;
18009 + struct au_hinode *hinode;
18011 + IiMustAnyLock(inode);
18013 + hinode = au_hinode(au_ii(inode), bindex);
18014 + h_inode = hinode->hi_inode;
18015 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
18019 +/* todo: hard/soft set? */
18020 +void au_hiput(struct au_hinode *hinode)
18022 + au_hn_free(hinode);
18023 + dput(hinode->hi_whdentry);
18024 + iput(hinode->hi_inode);
18027 +unsigned int au_hi_flags(struct inode *inode, int isdir)
18029 + unsigned int flags;
18030 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
18033 + if (au_opt_test(mnt_flags, XINO))
18034 + au_fset_hi(flags, XINO);
18035 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
18036 + au_fset_hi(flags, HNOTIFY);
18040 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18041 + struct inode *h_inode, unsigned int flags)
18043 + struct au_hinode *hinode;
18044 + struct inode *hi;
18045 + struct au_iinfo *iinfo = au_ii(inode);
18047 + IiMustWriteLock(inode);
18049 + hinode = au_hinode(iinfo, bindex);
18050 + hi = hinode->hi_inode;
18051 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
18054 + au_hiput(hinode);
18055 + hinode->hi_inode = h_inode;
18058 + struct super_block *sb = inode->i_sb;
18059 + struct au_branch *br;
18061 + AuDebugOn(inode->i_mode
18062 + && (h_inode->i_mode & S_IFMT)
18063 + != (inode->i_mode & S_IFMT));
18064 + if (bindex == iinfo->ii_btop)
18065 + au_cpup_igen(inode, h_inode);
18066 + br = au_sbr(sb, bindex);
18067 + hinode->hi_id = br->br_id;
18068 + if (au_ftest_hi(flags, XINO)) {
18069 + err = au_xino_write(sb, bindex, h_inode->i_ino,
18071 + if (unlikely(err))
18072 + AuIOErr1("failed au_xino_write() %d\n", err);
18075 + if (au_ftest_hi(flags, HNOTIFY)
18076 + && au_br_hnotifyable(br->br_perm)) {
18077 + err = au_hn_alloc(hinode, inode);
18078 + if (unlikely(err))
18079 + AuIOErr1("au_hn_alloc() %d\n", err);
18084 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18085 + struct dentry *h_wh)
18087 + struct au_hinode *hinode;
18089 + IiMustWriteLock(inode);
18091 + hinode = au_hinode(au_ii(inode), bindex);
18092 + AuDebugOn(hinode->hi_whdentry);
18093 + hinode->hi_whdentry = h_wh;
18096 +void au_update_iigen(struct inode *inode, int half)
18098 + struct au_iinfo *iinfo;
18099 + struct au_iigen *iigen;
18100 + unsigned int sigen;
18102 + sigen = au_sigen(inode->i_sb);
18103 + iinfo = au_ii(inode);
18104 + iigen = &iinfo->ii_generation;
18105 + spin_lock(&iigen->ig_spin);
18106 + iigen->ig_generation = sigen;
18108 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
18110 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
18111 + spin_unlock(&iigen->ig_spin);
18114 +/* it may be called at remount time, too */
18115 +void au_update_ibrange(struct inode *inode, int do_put_zero)
18117 + struct au_iinfo *iinfo;
18118 + aufs_bindex_t bindex, bbot;
18120 + AuDebugOn(au_is_bad_inode(inode));
18121 + IiMustWriteLock(inode);
18123 + iinfo = au_ii(inode);
18124 + if (do_put_zero && iinfo->ii_btop >= 0) {
18125 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18127 + struct inode *h_i;
18129 + h_i = au_hinode(iinfo, bindex)->hi_inode;
18132 + && !(h_i->i_state & I_LINKABLE))
18133 + au_set_h_iptr(inode, bindex, NULL, 0);
18137 + iinfo->ii_btop = -1;
18138 + iinfo->ii_bbot = -1;
18139 + bbot = au_sbbot(inode->i_sb);
18140 + for (bindex = 0; bindex <= bbot; bindex++)
18141 + if (au_hinode(iinfo, bindex)->hi_inode) {
18142 + iinfo->ii_btop = bindex;
18145 + if (iinfo->ii_btop >= 0)
18146 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
18147 + if (au_hinode(iinfo, bindex)->hi_inode) {
18148 + iinfo->ii_bbot = bindex;
18151 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
18154 +/* ---------------------------------------------------------------------- */
18156 +void au_icntnr_init_once(void *_c)
18158 + struct au_icntnr *c = _c;
18159 + struct au_iinfo *iinfo = &c->iinfo;
18161 + spin_lock_init(&iinfo->ii_generation.ig_spin);
18162 + au_rw_init(&iinfo->ii_rwsem);
18163 + inode_init_once(&c->vfs_inode);
18166 +void au_hinode_init(struct au_hinode *hinode)
18168 + hinode->hi_inode = NULL;
18169 + hinode->hi_id = -1;
18170 + au_hn_init(hinode);
18171 + hinode->hi_whdentry = NULL;
18174 +int au_iinfo_init(struct inode *inode)
18176 + struct au_iinfo *iinfo;
18177 + struct super_block *sb;
18178 + struct au_hinode *hi;
18181 + sb = inode->i_sb;
18182 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18183 + nbr = au_sbbot(sb) + 1;
18184 + if (unlikely(nbr <= 0))
18186 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
18188 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
18190 + iinfo->ii_hinode = hi;
18191 + for (i = 0; i < nbr; i++, hi++)
18192 + au_hinode_init(hi);
18194 + iinfo->ii_generation.ig_generation = au_sigen(sb);
18195 + iinfo->ii_btop = -1;
18196 + iinfo->ii_bbot = -1;
18197 + iinfo->ii_vdir = NULL;
18203 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
18206 + struct au_hinode *hip;
18208 + AuRwMustWriteLock(&iinfo->ii_rwsem);
18211 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
18214 + iinfo->ii_hinode = hip;
18215 + i = iinfo->ii_bbot + 1;
18217 + for (; i < nbr; i++, hip++)
18218 + au_hinode_init(hip);
18225 +void au_iinfo_fin(struct inode *inode)
18227 + struct au_iinfo *iinfo;
18228 + struct au_hinode *hi;
18229 + struct super_block *sb;
18230 + aufs_bindex_t bindex, bbot;
18231 + const unsigned char unlinked = !inode->i_nlink;
18233 + AuDebugOn(au_is_bad_inode(inode));
18235 + sb = inode->i_sb;
18236 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
18237 + if (si_pid_test(sb))
18238 + au_xino_delete_inode(inode, unlinked);
18241 + * it is safe to hide the dependency between sbinfo and
18245 + si_noflush_read_lock(sb);
18246 + au_xino_delete_inode(inode, unlinked);
18247 + si_read_unlock(sb);
18251 + iinfo = au_ii(inode);
18252 + if (iinfo->ii_vdir)
18253 + au_vdir_free(iinfo->ii_vdir);
18255 + bindex = iinfo->ii_btop;
18256 + if (bindex >= 0) {
18257 + hi = au_hinode(iinfo, bindex);
18258 + bbot = iinfo->ii_bbot;
18259 + while (bindex++ <= bbot) {
18260 + if (hi->hi_inode)
18265 + au_kfree_rcu(iinfo->ii_hinode);
18266 + AuRwDestroy(&iinfo->ii_rwsem);
18268 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18269 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18270 +++ linux/fs/aufs/inode.c 2018-08-12 23:43:05.460124736 +0200
18272 +// SPDX-License-Identifier: GPL-2.0
18274 + * Copyright (C) 2005-2018 Junjiro R. Okajima
18276 + * This program, aufs is free software; you can redistribute it and/or modify
18277 + * it under the terms of the GNU General Public License as published by
18278 + * the Free Software Foundation; either version 2 of the License, or
18279 + * (at your option) any later version.
18281 + * This program is distributed in the hope that it will be useful,
18282 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18283 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18284 + * GNU General Public License for more details.
18286 + * You should have received a copy of the GNU General Public License
18287 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18291 + * inode functions
18296 +struct inode *au_igrab(struct inode *inode)
18299 + AuDebugOn(!atomic_read(&inode->i_count));
18305 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18307 + au_cpup_attr_all(inode, /*force*/0);
18308 + au_update_iigen(inode, /*half*/1);
18310 + inode_inc_iversion(inode);
18313 +static int au_ii_refresh(struct inode *inode, int *update)
18317 + aufs_bindex_t bindex, new_bindex;
18318 + struct super_block *sb;
18319 + struct au_iinfo *iinfo;
18320 + struct au_hinode *p, *q, tmp;
18322 + AuDebugOn(au_is_bad_inode(inode));
18323 + IiMustWriteLock(inode);
18326 + sb = inode->i_sb;
18327 + nbr = au_sbbot(sb) + 1;
18328 + type = inode->i_mode & S_IFMT;
18329 + iinfo = au_ii(inode);
18330 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18331 + if (unlikely(err))
18334 + AuDebugOn(iinfo->ii_btop < 0);
18335 + p = au_hinode(iinfo, iinfo->ii_btop);
18336 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18338 + if (!p->hi_inode)
18341 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18342 + new_bindex = au_br_index(sb, p->hi_id);
18343 + if (new_bindex == bindex)
18346 + if (new_bindex < 0) {
18349 + p->hi_inode = NULL;
18353 + if (new_bindex < iinfo->ii_btop)
18354 + iinfo->ii_btop = new_bindex;
18355 + if (iinfo->ii_bbot < new_bindex)
18356 + iinfo->ii_bbot = new_bindex;
18357 + /* swap two lower inode, and loop again */
18358 + q = au_hinode(iinfo, new_bindex);
18362 + if (tmp.hi_inode) {
18367 + au_update_ibrange(inode, /*do_put_zero*/0);
18368 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18369 + e = au_dy_irefresh(inode);
18370 + if (unlikely(e && !err))
18378 +void au_refresh_iop(struct inode *inode, int force_getattr)
18381 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18382 + const struct inode_operations *iop
18383 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18385 + if (inode->i_op == iop)
18388 + switch (inode->i_mode & S_IFMT) {
18390 + type = AuIop_DIR;
18393 + type = AuIop_SYMLINK;
18396 + type = AuIop_OTHER;
18400 + inode->i_op = iop + type;
18401 + /* unnecessary smp_wmb() */
18404 +int au_refresh_hinode_self(struct inode *inode)
18408 + err = au_ii_refresh(inode, &update);
18410 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18416 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18418 + int err, e, update;
18419 + unsigned int flags;
18421 + aufs_bindex_t bindex, bbot;
18422 + unsigned char isdir;
18423 + struct au_hinode *p;
18424 + struct au_iinfo *iinfo;
18426 + err = au_ii_refresh(inode, &update);
18427 + if (unlikely(err))
18431 + iinfo = au_ii(inode);
18432 + p = au_hinode(iinfo, iinfo->ii_btop);
18433 + mode = (inode->i_mode & S_IFMT);
18434 + isdir = S_ISDIR(mode);
18435 + flags = au_hi_flags(inode, isdir);
18436 + bbot = au_dbbot(dentry);
18437 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18438 + struct inode *h_i, *h_inode;
18439 + struct dentry *h_d;
18441 + h_d = au_h_dptr(dentry, bindex);
18442 + if (!h_d || d_is_negative(h_d))
18445 + h_inode = d_inode(h_d);
18446 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18447 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18448 + h_i = au_h_iptr(inode, bindex);
18450 + if (h_i == h_inode)
18456 + if (bindex < iinfo->ii_btop)
18457 + iinfo->ii_btop = bindex;
18458 + if (iinfo->ii_bbot < bindex)
18459 + iinfo->ii_bbot = bindex;
18460 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18463 + au_update_ibrange(inode, /*do_put_zero*/0);
18464 + e = au_dy_irefresh(inode);
18465 + if (unlikely(e && !err))
18468 + au_refresh_hinode_attr(inode, update && isdir);
18475 +static int set_inode(struct inode *inode, struct dentry *dentry)
18478 + unsigned int flags;
18480 + aufs_bindex_t bindex, btop, btail;
18481 + unsigned char isdir;
18482 + struct dentry *h_dentry;
18483 + struct inode *h_inode;
18484 + struct au_iinfo *iinfo;
18485 + struct inode_operations *iop;
18487 + IiMustWriteLock(inode);
18491 + iop = au_sbi(inode->i_sb)->si_iop_array;
18492 + btop = au_dbtop(dentry);
18493 + h_dentry = au_h_dptr(dentry, btop);
18494 + h_inode = d_inode(h_dentry);
18495 + mode = h_inode->i_mode;
18496 + switch (mode & S_IFMT) {
18498 + btail = au_dbtail(dentry);
18499 + inode->i_op = iop + AuIop_OTHER;
18500 + inode->i_fop = &aufs_file_fop;
18501 + err = au_dy_iaop(inode, btop, h_inode);
18502 + if (unlikely(err))
18507 + btail = au_dbtaildir(dentry);
18508 + inode->i_op = iop + AuIop_DIR;
18509 + inode->i_fop = &aufs_dir_fop;
18512 + btail = au_dbtail(dentry);
18513 + inode->i_op = iop + AuIop_SYMLINK;
18519 + btail = au_dbtail(dentry);
18520 + inode->i_op = iop + AuIop_OTHER;
18521 + init_special_inode(inode, mode, h_inode->i_rdev);
18524 + AuIOErr("Unknown file type 0%o\n", mode);
18529 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18530 + flags = au_hi_flags(inode, isdir);
18531 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18532 + && au_ftest_hi(flags, HNOTIFY)
18533 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18534 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18535 + au_fclr_hi(flags, HNOTIFY);
18536 + iinfo = au_ii(inode);
18537 + iinfo->ii_btop = btop;
18538 + iinfo->ii_bbot = btail;
18539 + for (bindex = btop; bindex <= btail; bindex++) {
18540 + h_dentry = au_h_dptr(dentry, bindex);
18542 + au_set_h_iptr(inode, bindex,
18543 + au_igrab(d_inode(h_dentry)), flags);
18545 + au_cpup_attr_all(inode, /*force*/1);
18547 + * to force calling aufs_get_acl() every time,
18548 + * do not call cache_no_acl() for aufs inode.
18556 + * successful returns with iinfo write_locked
18558 + * zero: success, matched
18559 + * plus: no error, but unmatched
18561 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18564 + unsigned int gen, igflags;
18565 + aufs_bindex_t bindex, bbot;
18566 + struct inode *h_inode, *h_dinode;
18567 + struct dentry *h_dentry;
18570 + * before this function, if aufs got any iinfo lock, it must be only
18571 + * one, the parent dir.
18572 + * it can happen by UDBA and the obsoleted inode number.
18575 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18579 + ii_write_lock_new_child(inode);
18580 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18581 + h_dinode = d_inode(h_dentry);
18582 + bbot = au_ibbot(inode);
18583 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18584 + h_inode = au_h_iptr(inode, bindex);
18585 + if (!h_inode || h_inode != h_dinode)
18589 + gen = au_iigen(inode, &igflags);
18590 + if (gen == au_digen(dentry)
18591 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18594 + /* fully refresh inode using dentry */
18595 + err = au_refresh_hinode(inode, dentry);
18597 + au_update_iigen(inode, /*half*/0);
18601 + if (unlikely(err))
18602 + ii_write_unlock(inode);
18607 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18608 + unsigned int d_type, ino_t *ino)
18611 + const int isnondir = d_type != DT_DIR;
18613 + /* prevent hardlinked inode number from race condition */
18615 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18616 + if (unlikely(err))
18620 + err = au_xino_read(sb, bindex, h_ino, ino);
18621 + if (unlikely(err))
18622 + goto out_xinondir;
18626 + *ino = au_xino_new_ino(sb);
18627 + if (unlikely(!*ino))
18628 + goto out_xinondir;
18629 + err = au_xino_write(sb, bindex, h_ino, *ino);
18630 + if (unlikely(err))
18631 + goto out_xinondir;
18635 + if (isnondir && idx >= 0)
18636 + au_xinondir_leave(sb, bindex, h_ino, idx);
18641 +/* successful returns with iinfo write_locked */
18642 +/* todo: return with unlocked? */
18643 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18645 + struct inode *inode, *h_inode;
18646 + struct dentry *h_dentry;
18647 + struct super_block *sb;
18648 + ino_t h_ino, ino;
18649 + int err, idx, hlinked;
18650 + aufs_bindex_t btop;
18652 + sb = dentry->d_sb;
18653 + btop = au_dbtop(dentry);
18654 + h_dentry = au_h_dptr(dentry, btop);
18655 + h_inode = d_inode(h_dentry);
18656 + h_ino = h_inode->i_ino;
18657 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18661 + * stop 'race'-ing between hardlinks under different
18665 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18666 + inode = ERR_PTR(err);
18667 + if (unlikely(err))
18671 + err = au_xino_read(sb, btop, h_ino, &ino);
18672 + inode = ERR_PTR(err);
18673 + if (unlikely(err))
18674 + goto out_xinondir;
18677 + ino = au_xino_new_ino(sb);
18678 + if (unlikely(!ino)) {
18679 + inode = ERR_PTR(-EIO);
18680 + goto out_xinondir;
18684 + AuDbg("i%lu\n", (unsigned long)ino);
18685 + inode = au_iget_locked(sb, ino);
18686 + err = PTR_ERR(inode);
18687 + if (IS_ERR(inode))
18688 + goto out_xinondir;
18690 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18691 + if (inode->i_state & I_NEW) {
18692 + ii_write_lock_new_child(inode);
18693 + err = set_inode(inode, dentry);
18695 + unlock_new_inode(inode);
18696 + goto out_xinondir; /* success */
18700 + * iget_failed() calls iput(), but we need to call
18701 + * ii_write_unlock() after iget_failed(). so dirty hack for
18704 + atomic_inc(&inode->i_count);
18705 + iget_failed(inode);
18706 + ii_write_unlock(inode);
18707 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18708 + /* ignore this error */
18710 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18712 + * horrible race condition between lookup, readdir and copyup
18713 + * (or something).
18715 + if (hlinked && idx >= 0)
18716 + au_xinondir_leave(sb, btop, h_ino, idx);
18717 + err = reval_inode(inode, dentry);
18718 + if (unlikely(err < 0)) {
18723 + goto out; /* success */
18724 + else if (hlinked && idx >= 0) {
18725 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18726 + if (unlikely(err)) {
18728 + inode = ERR_PTR(err);
18734 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18735 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18736 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18737 + btop, au_sbtype(h_dentry->d_sb), dentry,
18738 + (unsigned long)h_ino, (unsigned long)ino);
18740 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18743 + if (hlinked && idx >= 0)
18744 + au_xinondir_leave(sb, btop, h_ino, idx);
18750 + inode = ERR_PTR(err);
18752 + if (hlinked && idx >= 0)
18753 + au_xinondir_leave(sb, btop, h_ino, idx);
18758 +/* ---------------------------------------------------------------------- */
18760 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18761 + struct inode *inode)
18764 + struct inode *hi;
18766 + err = au_br_rdonly(au_sbr(sb, bindex));
18768 + /* pseudo-link after flushed may happen out of bounds */
18771 + && au_ibtop(inode) <= bindex
18772 + && bindex <= au_ibbot(inode)) {
18774 + * permission check is unnecessary since vfsub routine
18775 + * will be called later
18777 + hi = au_h_iptr(inode, bindex);
18779 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18785 +int au_test_h_perm(struct inode *h_inode, int mask)
18787 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18789 + return inode_permission(h_inode, mask);
18792 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18794 + if (au_test_nfs(h_inode->i_sb)
18795 + && (mask & MAY_WRITE)
18796 + && S_ISDIR(h_inode->i_mode))
18797 + mask |= MAY_READ; /* force permission check */
18798 + return au_test_h_perm(h_inode, mask);
18800 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18801 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18802 +++ linux/fs/aufs/inode.h 2018-12-27 13:19:17.711749485 +0100
18804 +/* SPDX-License-Identifier: GPL-2.0 */
18806 + * Copyright (C) 2005-2018 Junjiro R. Okajima
18808 + * This program, aufs is free software; you can redistribute it and/or modify
18809 + * it under the terms of the GNU General Public License as published by
18810 + * the Free Software Foundation; either version 2 of the License, or
18811 + * (at your option) any later version.
18813 + * This program is distributed in the hope that it will be useful,
18814 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18815 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18816 + * GNU General Public License for more details.
18818 + * You should have received a copy of the GNU General Public License
18819 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18823 + * inode operations
18826 +#ifndef __AUFS_INODE_H__
18827 +#define __AUFS_INODE_H__
18831 +#include <linux/fsnotify.h>
18832 +#include "rwsem.h"
18836 +struct au_hnotify {
18837 +#ifdef CONFIG_AUFS_HNOTIFY
18838 +#ifdef CONFIG_AUFS_HFSNOTIFY
18839 + /* never use fsnotify_add_vfsmount_mark() */
18840 + struct fsnotify_mark hn_mark;
18842 + struct inode *hn_aufs_inode; /* no get/put */
18843 + struct rcu_head rcu;
18845 +} ____cacheline_aligned_in_smp;
18847 +struct au_hinode {
18848 + struct inode *hi_inode;
18849 + aufs_bindex_t hi_id;
18850 +#ifdef CONFIG_AUFS_HNOTIFY
18851 + struct au_hnotify *hi_notify;
18854 + /* reference to the copied-up whiteout with get/put */
18855 + struct dentry *hi_whdentry;
18859 +#define AuIG_HALF_REFRESHED 1
18860 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18861 +#define au_ig_fset(flags, name) \
18862 + do { (flags) |= AuIG_##name; } while (0)
18863 +#define au_ig_fclr(flags, name) \
18864 + do { (flags) &= ~AuIG_##name; } while (0)
18867 + spinlock_t ig_spin;
18868 + __u32 ig_generation, ig_flags;
18873 + struct au_iigen ii_generation;
18874 + struct super_block *ii_hsb1; /* no get/put */
18876 + struct au_rwsem ii_rwsem;
18877 + aufs_bindex_t ii_btop, ii_bbot;
18879 + struct au_hinode *ii_hinode;
18880 + struct au_vdir *ii_vdir;
18883 +struct au_icntnr {
18884 + struct au_iinfo iinfo;
18885 + struct inode vfs_inode;
18886 + struct hlist_bl_node plink;
18887 + struct rcu_head rcu;
18888 +} ____cacheline_aligned_in_smp;
18890 +/* au_pin flags */
18891 +#define AuPin_DI_LOCKED 1
18892 +#define AuPin_MNT_WRITE (1 << 1)
18893 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18894 +#define au_fset_pin(flags, name) \
18895 + do { (flags) |= AuPin_##name; } while (0)
18896 +#define au_fclr_pin(flags, name) \
18897 + do { (flags) &= ~AuPin_##name; } while (0)
18901 + struct dentry *dentry;
18902 + unsigned int udba;
18903 + unsigned char lsc_di, lsc_hi, flags;
18904 + aufs_bindex_t bindex;
18907 + struct dentry *parent;
18908 + struct au_hinode *hdir;
18909 + struct vfsmount *h_mnt;
18911 + /* temporary unlock/relock for copyup */
18912 + struct dentry *h_dentry, *h_parent;
18913 + struct au_branch *br;
18914 + struct task_struct *task;
18917 +void au_pin_hdir_unlock(struct au_pin *p);
18918 +int au_pin_hdir_lock(struct au_pin *p);
18919 +int au_pin_hdir_relock(struct au_pin *p);
18920 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18921 +void au_pin_hdir_release(struct au_pin *p);
18923 +/* ---------------------------------------------------------------------- */
18925 +static inline struct au_iinfo *au_ii(struct inode *inode)
18927 + BUG_ON(is_bad_inode(inode));
18928 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18931 +/* ---------------------------------------------------------------------- */
18934 +struct inode *au_igrab(struct inode *inode);
18935 +void au_refresh_iop(struct inode *inode, int force_getattr);
18936 +int au_refresh_hinode_self(struct inode *inode);
18937 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18938 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18939 + unsigned int d_type, ino_t *ino);
18940 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18941 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18942 + struct inode *inode);
18943 +int au_test_h_perm(struct inode *h_inode, int mask);
18944 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18946 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18947 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18949 +#ifdef CONFIG_AUFS_SHWH
18950 + return au_ino(sb, bindex, h_ino, d_type, ino);
18963 +extern struct inode_operations aufs_iop[AuIop_Last],
18964 + aufs_iop_nogetattr[AuIop_Last];
18966 +/* au_wr_dir flags */
18967 +#define AuWrDir_ADD_ENTRY 1
18968 +#define AuWrDir_ISDIR (1 << 1)
18969 +#define AuWrDir_TMPFILE (1 << 2)
18970 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18971 +#define au_fset_wrdir(flags, name) \
18972 + do { (flags) |= AuWrDir_##name; } while (0)
18973 +#define au_fclr_wrdir(flags, name) \
18974 + do { (flags) &= ~AuWrDir_##name; } while (0)
18976 +struct au_wr_dir_args {
18977 + aufs_bindex_t force_btgt;
18978 + unsigned char flags;
18980 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18981 + struct au_wr_dir_args *args);
18983 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18984 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18985 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18986 + unsigned int udba, unsigned char flags);
18987 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18988 + unsigned int udba, unsigned char flags) __must_check;
18989 +int au_do_pin(struct au_pin *pin) __must_check;
18990 +void au_unpin(struct au_pin *pin);
18991 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18993 +#define AuIcpup_DID_CPUP 1
18994 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18995 +#define au_fset_icpup(flags, name) \
18996 + do { (flags) |= AuIcpup_##name; } while (0)
18997 +#define au_fclr_icpup(flags, name) \
18998 + do { (flags) &= ~AuIcpup_##name; } while (0)
19000 +struct au_icpup_args {
19001 + unsigned char flags;
19002 + unsigned char pin_flags;
19003 + aufs_bindex_t btgt;
19004 + unsigned int udba;
19005 + struct au_pin pin;
19006 + struct path h_path;
19007 + struct inode *h_inode;
19010 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
19011 + struct au_icpup_args *a);
19013 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
19017 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19018 + struct dentry *h_parent, int isdir);
19019 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
19021 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
19022 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
19024 +struct vfsub_aopen_args;
19025 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
19026 + struct vfsub_aopen_args *args);
19027 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
19028 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
19029 + struct dentry *dentry);
19030 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
19033 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
19034 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
19035 + struct dentry *h_parent, int isdir);
19036 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
19037 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
19040 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
19041 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
19042 + struct inode *dir, struct dentry *dentry,
19043 + unsigned int flags);
19046 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
19047 +void au_hiput(struct au_hinode *hinode);
19048 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19049 + struct dentry *h_wh);
19050 +unsigned int au_hi_flags(struct inode *inode, int isdir);
19052 +/* hinode flags */
19053 +#define AuHi_XINO 1
19054 +#define AuHi_HNOTIFY (1 << 1)
19055 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
19056 +#define au_fset_hi(flags, name) \
19057 + do { (flags) |= AuHi_##name; } while (0)
19058 +#define au_fclr_hi(flags, name) \
19059 + do { (flags) &= ~AuHi_##name; } while (0)
19061 +#ifndef CONFIG_AUFS_HNOTIFY
19062 +#undef AuHi_HNOTIFY
19063 +#define AuHi_HNOTIFY 0
19066 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19067 + struct inode *h_inode, unsigned int flags);
19069 +void au_update_iigen(struct inode *inode, int half);
19070 +void au_update_ibrange(struct inode *inode, int do_put_zero);
19072 +void au_icntnr_init_once(void *_c);
19073 +void au_hinode_init(struct au_hinode *hinode);
19074 +int au_iinfo_init(struct inode *inode);
19075 +void au_iinfo_fin(struct inode *inode);
19076 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
19078 +#ifdef CONFIG_PROC_FS
19080 +int au_plink_maint(struct super_block *sb, int flags);
19082 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
19083 +int au_plink_maint_enter(struct super_block *sb);
19084 +#ifdef CONFIG_AUFS_DEBUG
19085 +void au_plink_list(struct super_block *sb);
19087 +AuStubVoid(au_plink_list, struct super_block *sb)
19089 +int au_plink_test(struct inode *inode);
19090 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
19091 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
19092 + struct dentry *h_dentry);
19093 +void au_plink_put(struct super_block *sb, int verbose);
19094 +void au_plink_clean(struct super_block *sb, int verbose);
19095 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
19097 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
19098 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
19099 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
19100 +AuStubVoid(au_plink_list, struct super_block *sb);
19101 +AuStubInt0(au_plink_test, struct inode *inode);
19102 +AuStub(struct dentry *, au_plink_lkup, return NULL,
19103 + struct inode *inode, aufs_bindex_t bindex);
19104 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
19105 + struct dentry *h_dentry);
19106 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
19107 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
19108 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
19109 +#endif /* CONFIG_PROC_FS */
19111 +#ifdef CONFIG_AUFS_XATTR
19113 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
19114 + unsigned int verbose);
19115 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
19116 +void au_xattr_init(struct super_block *sb);
19118 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
19119 + int ignore_flags, unsigned int verbose);
19120 +AuStubVoid(au_xattr_init, struct super_block *sb);
19123 +#ifdef CONFIG_FS_POSIX_ACL
19124 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
19125 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
19128 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19134 +struct au_sxattr {
19138 + const char *name;
19139 + const void *value;
19144 + struct posix_acl *acl;
19149 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19150 + struct au_sxattr *arg);
19153 +/* ---------------------------------------------------------------------- */
19155 +/* lock subclass for iinfo */
19157 + AuLsc_II_CHILD, /* child first */
19158 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
19159 + AuLsc_II_CHILD3, /* copyup dirs */
19160 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
19161 + AuLsc_II_PARENT2,
19162 + AuLsc_II_PARENT3, /* copyup dirs */
19163 + AuLsc_II_NEW_CHILD
19167 + * ii_read_lock_child, ii_write_lock_child,
19168 + * ii_read_lock_child2, ii_write_lock_child2,
19169 + * ii_read_lock_child3, ii_write_lock_child3,
19170 + * ii_read_lock_parent, ii_write_lock_parent,
19171 + * ii_read_lock_parent2, ii_write_lock_parent2,
19172 + * ii_read_lock_parent3, ii_write_lock_parent3,
19173 + * ii_read_lock_new_child, ii_write_lock_new_child,
19175 +#define AuReadLockFunc(name, lsc) \
19176 +static inline void ii_read_lock_##name(struct inode *i) \
19178 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19181 +#define AuWriteLockFunc(name, lsc) \
19182 +static inline void ii_write_lock_##name(struct inode *i) \
19184 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19187 +#define AuRWLockFuncs(name, lsc) \
19188 + AuReadLockFunc(name, lsc) \
19189 + AuWriteLockFunc(name, lsc)
19191 +AuRWLockFuncs(child, CHILD);
19192 +AuRWLockFuncs(child2, CHILD2);
19193 +AuRWLockFuncs(child3, CHILD3);
19194 +AuRWLockFuncs(parent, PARENT);
19195 +AuRWLockFuncs(parent2, PARENT2);
19196 +AuRWLockFuncs(parent3, PARENT3);
19197 +AuRWLockFuncs(new_child, NEW_CHILD);
19199 +#undef AuReadLockFunc
19200 +#undef AuWriteLockFunc
19201 +#undef AuRWLockFuncs
19203 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
19204 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
19205 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
19207 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
19208 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
19209 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
19211 +/* ---------------------------------------------------------------------- */
19213 +static inline void au_icntnr_init(struct au_icntnr *c)
19215 +#ifdef CONFIG_AUFS_DEBUG
19216 + c->vfs_inode.i_mode = 0;
19220 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
19222 + unsigned int gen;
19223 + struct au_iinfo *iinfo;
19224 + struct au_iigen *iigen;
19226 + iinfo = au_ii(inode);
19227 + iigen = &iinfo->ii_generation;
19228 + spin_lock(&iigen->ig_spin);
19230 + *igflags = iigen->ig_flags;
19231 + gen = iigen->ig_generation;
19232 + spin_unlock(&iigen->ig_spin);
19237 +/* tiny test for inode number */
19238 +/* tmpfs generation is too rough */
19239 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19241 + struct au_iinfo *iinfo;
19243 + iinfo = au_ii(inode);
19244 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19245 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19246 + && iinfo->ii_higen == h_inode->i_generation);
19249 +static inline void au_iigen_dec(struct inode *inode)
19251 + struct au_iinfo *iinfo;
19252 + struct au_iigen *iigen;
19254 + iinfo = au_ii(inode);
19255 + iigen = &iinfo->ii_generation;
19256 + spin_lock(&iigen->ig_spin);
19257 + iigen->ig_generation--;
19258 + spin_unlock(&iigen->ig_spin);
19261 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19266 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19272 +/* ---------------------------------------------------------------------- */
19274 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19275 + aufs_bindex_t bindex)
19277 + return iinfo->ii_hinode + bindex;
19280 +static inline int au_is_bad_inode(struct inode *inode)
19282 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19285 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19286 + aufs_bindex_t bindex)
19288 + IiMustAnyLock(inode);
19289 + return au_hinode(au_ii(inode), bindex)->hi_id;
19292 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19294 + IiMustAnyLock(inode);
19295 + return au_ii(inode)->ii_btop;
19298 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19300 + IiMustAnyLock(inode);
19301 + return au_ii(inode)->ii_bbot;
19304 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19306 + IiMustAnyLock(inode);
19307 + return au_ii(inode)->ii_vdir;
19310 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19312 + IiMustAnyLock(inode);
19313 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19316 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19318 + IiMustWriteLock(inode);
19319 + au_ii(inode)->ii_btop = bindex;
19322 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19324 + IiMustWriteLock(inode);
19325 + au_ii(inode)->ii_bbot = bindex;
19328 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19330 + IiMustWriteLock(inode);
19331 + au_ii(inode)->ii_vdir = vdir;
19334 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19336 + IiMustAnyLock(inode);
19337 + return au_hinode(au_ii(inode), bindex);
19340 +/* ---------------------------------------------------------------------- */
19342 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19345 + return pin->parent;
19349 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19351 + if (pin && pin->hdir)
19352 + return pin->hdir->hi_inode;
19356 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19359 + return pin->hdir;
19363 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19366 + pin->dentry = dentry;
19369 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19370 + unsigned char lflag)
19374 + au_fset_pin(pin->flags, DI_LOCKED);
19376 + au_fclr_pin(pin->flags, DI_LOCKED);
19380 +#if 0 /* reserved */
19381 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19384 + dput(pin->parent);
19385 + pin->parent = dget(parent);
19390 +/* ---------------------------------------------------------------------- */
19393 +#ifdef CONFIG_AUFS_HNOTIFY
19394 +struct au_hnotify_op {
19395 + void (*ctl)(struct au_hinode *hinode, int do_set);
19396 + int (*alloc)(struct au_hinode *hinode);
19399 + * if it returns true, the the caller should free hinode->hi_notify,
19400 + * otherwise ->free() frees it.
19402 + int (*free)(struct au_hinode *hinode,
19403 + struct au_hnotify *hn) __must_check;
19405 + void (*fin)(void);
19406 + int (*init)(void);
19408 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19409 + void (*fin_br)(struct au_branch *br);
19410 + int (*init_br)(struct au_branch *br, int perm);
19414 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19415 +void au_hn_free(struct au_hinode *hinode);
19416 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19417 +void au_hn_reset(struct inode *inode, unsigned int flags);
19418 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19419 + struct qstr *h_child_qstr, struct inode *h_child_inode);
19420 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19421 +int au_hnotify_init_br(struct au_branch *br, int perm);
19422 +void au_hnotify_fin_br(struct au_branch *br);
19423 +int __init au_hnotify_init(void);
19424 +void au_hnotify_fin(void);
19427 +extern const struct au_hnotify_op au_hnotify_op;
19430 +void au_hn_init(struct au_hinode *hinode)
19432 + hinode->hi_notify = NULL;
19435 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19437 + return hinode->hi_notify;
19441 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19442 + struct au_hinode *hinode __maybe_unused,
19443 + struct inode *inode __maybe_unused)
19444 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19445 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19446 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19447 + int do_set __maybe_unused)
19448 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19449 + unsigned int flags __maybe_unused)
19450 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19451 + struct au_branch *br __maybe_unused,
19452 + int perm __maybe_unused)
19453 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19454 + int perm __maybe_unused)
19455 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19456 +AuStubInt0(__init au_hnotify_init, void)
19457 +AuStubVoid(au_hnotify_fin, void)
19458 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19459 +#endif /* CONFIG_AUFS_HNOTIFY */
19461 +static inline void au_hn_suspend(struct au_hinode *hdir)
19463 + au_hn_ctl(hdir, /*do_set*/0);
19466 +static inline void au_hn_resume(struct au_hinode *hdir)
19468 + au_hn_ctl(hdir, /*do_set*/1);
19471 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19473 + inode_lock(hdir->hi_inode);
19474 + au_hn_suspend(hdir);
19477 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19478 + unsigned int sc __maybe_unused)
19480 + inode_lock_nested(hdir->hi_inode, sc);
19481 + au_hn_suspend(hdir);
19484 +#if 0 /* unused */
19485 +#include "vfsub.h"
19486 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19489 + inode_lock_shared_nested(hdir->hi_inode, sc);
19490 + au_hn_suspend(hdir);
19494 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19496 + au_hn_resume(hdir);
19497 + inode_unlock(hdir->hi_inode);
19500 +#endif /* __KERNEL__ */
19501 +#endif /* __AUFS_INODE_H__ */
19502 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19503 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19504 +++ linux/fs/aufs/ioctl.c 2018-10-23 12:33:35.599375796 +0200
19506 +// SPDX-License-Identifier: GPL-2.0
19508 + * Copyright (C) 2005-2018 Junjiro R. Okajima
19510 + * This program, aufs is free software; you can redistribute it and/or modify
19511 + * it under the terms of the GNU General Public License as published by
19512 + * the Free Software Foundation; either version 2 of the License, or
19513 + * (at your option) any later version.
19515 + * This program is distributed in the hope that it will be useful,
19516 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19517 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19518 + * GNU General Public License for more details.
19520 + * You should have received a copy of the GNU General Public License
19521 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19526 + * plink-management and readdir in userspace.
19527 + * assist the pathconf(3) wrapper library.
19529 + * File-based Hierarchical Storage Management.
19532 +#include <linux/compat.h>
19533 +#include <linux/file.h>
19536 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19539 + aufs_bindex_t wbi, bindex, bbot;
19540 + struct file *h_file;
19541 + struct super_block *sb;
19542 + struct dentry *root;
19543 + struct au_branch *br;
19544 + struct aufs_wbr_fd wbrfd = {
19545 + .oflags = au_dir_roflags,
19548 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19549 + | O_NOATIME | O_CLOEXEC;
19551 + AuDebugOn(wbrfd.oflags & ~valid);
19554 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19555 + if (unlikely(err)) {
19561 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19562 + wbrfd.oflags |= au_dir_roflags;
19563 + AuDbg("0%o\n", wbrfd.oflags);
19564 + if (unlikely(wbrfd.oflags & ~valid))
19568 + fd = get_unused_fd_flags(0);
19570 + if (unlikely(fd < 0))
19573 + h_file = ERR_PTR(-EINVAL);
19576 + sb = path->dentry->d_sb;
19577 + root = sb->s_root;
19578 + aufs_read_lock(root, AuLock_IR);
19579 + bbot = au_sbbot(sb);
19580 + if (wbrfd.brid >= 0) {
19581 + wbi = au_br_index(sb, wbrfd.brid);
19582 + if (unlikely(wbi < 0 || wbi > bbot))
19586 + h_file = ERR_PTR(-ENOENT);
19587 + br = au_sbr(sb, wbi);
19588 + if (!au_br_writable(br->br_perm)) {
19592 + bindex = wbi + 1;
19594 + for (; bindex <= bbot; bindex++) {
19595 + br = au_sbr(sb, bindex);
19596 + if (au_br_writable(br->br_perm)) {
19598 + br = au_sbr(sb, wbi);
19603 + AuDbg("wbi %d\n", wbi);
19605 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19609 + aufs_read_unlock(root, AuLock_IR);
19610 + err = PTR_ERR(h_file);
19611 + if (IS_ERR(h_file))
19614 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19615 + fd_install(fd, h_file);
19617 + goto out; /* success */
19620 + put_unused_fd(fd);
19626 +/* ---------------------------------------------------------------------- */
19628 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19631 + struct dentry *dentry;
19634 + case AUFS_CTL_RDU:
19635 + case AUFS_CTL_RDU_INO:
19636 + err = au_rdu_ioctl(file, cmd, arg);
19639 + case AUFS_CTL_WBR_FD:
19640 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19643 + case AUFS_CTL_IBUSY:
19644 + err = au_ibusy_ioctl(file, arg);
19647 + case AUFS_CTL_BRINFO:
19648 + err = au_brinfo_ioctl(file, arg);
19651 + case AUFS_CTL_FHSM_FD:
19652 + dentry = file->f_path.dentry;
19653 + if (IS_ROOT(dentry))
19654 + err = au_fhsm_fd(dentry->d_sb, arg);
19660 + /* do not call the lower */
19661 + AuDbg("0x%x\n", cmd);
19669 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19674 + case AUFS_CTL_MVDOWN:
19675 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19678 + case AUFS_CTL_WBR_FD:
19679 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19683 + /* do not call the lower */
19684 + AuDbg("0x%x\n", cmd);
19692 +#ifdef CONFIG_COMPAT
19693 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19694 + unsigned long arg)
19699 + case AUFS_CTL_RDU:
19700 + case AUFS_CTL_RDU_INO:
19701 + err = au_rdu_compat_ioctl(file, cmd, arg);
19704 + case AUFS_CTL_IBUSY:
19705 + err = au_ibusy_compat_ioctl(file, arg);
19708 + case AUFS_CTL_BRINFO:
19709 + err = au_brinfo_compat_ioctl(file, arg);
19713 + err = aufs_ioctl_dir(file, cmd, arg);
19720 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19721 + unsigned long arg)
19723 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19726 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19727 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19728 +++ linux/fs/aufs/i_op_add.c 2018-12-27 13:19:17.711749485 +0100
19730 +// SPDX-License-Identifier: GPL-2.0
19732 + * Copyright (C) 2005-2018 Junjiro R. Okajima
19734 + * This program, aufs is free software; you can redistribute it and/or modify
19735 + * it under the terms of the GNU General Public License as published by
19736 + * the Free Software Foundation; either version 2 of the License, or
19737 + * (at your option) any later version.
19739 + * This program is distributed in the hope that it will be useful,
19740 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19741 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19742 + * GNU General Public License for more details.
19744 + * You should have received a copy of the GNU General Public License
19745 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19749 + * inode operations (add entry)
19755 + * final procedure of adding a new entry, except link(2).
19756 + * remove whiteout, instantiate, copyup the parent dir's times and size
19757 + * and update version.
19758 + * if it failed, re-create the removed whiteout.
19760 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19761 + struct dentry *wh_dentry, struct dentry *dentry)
19764 + aufs_bindex_t bwh;
19765 + struct path h_path;
19766 + struct super_block *sb;
19767 + struct inode *inode, *h_dir;
19768 + struct dentry *wh;
19773 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19774 + IMustLock(h_dir);
19775 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19776 + bwh = au_dbwh(dentry);
19777 + h_path.dentry = wh_dentry;
19778 + h_path.mnt = au_sbr_mnt(sb, bindex);
19779 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19781 + if (unlikely(err))
19785 + inode = au_new_inode(dentry, /*must_new*/1);
19786 + if (!IS_ERR(inode)) {
19787 + d_instantiate(dentry, inode);
19788 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19790 + au_dir_ts(dir, bindex);
19791 + inode_inc_iversion(dir);
19792 + au_fhsm_wrote(sb, bindex, /*force*/0);
19793 + return 0; /* success */
19796 + err = PTR_ERR(inode);
19801 + /* dir inode is locked */
19802 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19803 + rerr = PTR_ERR(wh);
19804 + if (IS_ERR(wh)) {
19805 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19806 + dentry, err, rerr);
19815 +static int au_d_may_add(struct dentry *dentry)
19820 + if (unlikely(d_unhashed(dentry)))
19822 + if (unlikely(d_really_is_positive(dentry)))
19828 + * simple tests for the adding inode operations.
19829 + * following the checks in vfs, plus the parent-child relationship.
19831 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19832 + struct dentry *h_parent, int isdir)
19836 + struct dentry *h_dentry;
19837 + struct inode *h_inode;
19839 + err = -ENAMETOOLONG;
19840 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19843 + h_dentry = au_h_dptr(dentry, bindex);
19844 + if (d_really_is_negative(dentry)) {
19846 + if (unlikely(d_is_positive(h_dentry)))
19849 + /* rename(2) case */
19851 + if (unlikely(d_is_negative(h_dentry)))
19853 + h_inode = d_inode(h_dentry);
19854 + if (unlikely(!h_inode->i_nlink))
19857 + h_mode = h_inode->i_mode;
19860 + if (unlikely(S_ISDIR(h_mode)))
19862 + } else if (unlikely(!S_ISDIR(h_mode))) {
19869 + /* expected parent dir is locked */
19870 + if (unlikely(h_parent != h_dentry->d_parent))
19879 + * initial procedure of adding a new entry.
19880 + * prepare writable branch and the parent dir, lock it,
19881 + * and lookup whiteout for the new entry.
19883 +static struct dentry*
19884 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19885 + struct dentry *src_dentry, struct au_pin *pin,
19886 + struct au_wr_dir_args *wr_dir_args)
19888 + struct dentry *wh_dentry, *h_parent;
19889 + struct super_block *sb;
19890 + struct au_branch *br;
19892 + unsigned int udba;
19893 + aufs_bindex_t bcpup;
19895 + AuDbg("%pd\n", dentry);
19897 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19899 + wh_dentry = ERR_PTR(err);
19900 + if (unlikely(err < 0))
19903 + sb = dentry->d_sb;
19904 + udba = au_opt_udba(sb);
19905 + err = au_pin(pin, dentry, bcpup, udba,
19906 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19907 + wh_dentry = ERR_PTR(err);
19908 + if (unlikely(err))
19911 + h_parent = au_pinned_h_parent(pin);
19912 + if (udba != AuOpt_UDBA_NONE
19913 + && au_dbtop(dentry) == bcpup)
19914 + err = au_may_add(dentry, bcpup, h_parent,
19915 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19916 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19917 + err = -ENAMETOOLONG;
19918 + wh_dentry = ERR_PTR(err);
19919 + if (unlikely(err))
19922 + br = au_sbr(sb, bcpup);
19924 + struct path tmp = {
19925 + .dentry = h_parent,
19926 + .mnt = au_br_mnt(br)
19928 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19931 + wh_dentry = NULL;
19932 + if (bcpup != au_dbwh(dentry))
19933 + goto out; /* success */
19936 + * ENAMETOOLONG here means that if we allowed create such name, then it
19937 + * would not be able to removed in the future. So we don't allow such
19938 + * name here and we don't handle ENAMETOOLONG differently here.
19940 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19943 + if (IS_ERR(wh_dentry))
19946 + return wh_dentry;
19949 +/* ---------------------------------------------------------------------- */
19951 +enum { Mknod, Symlink, Creat };
19952 +struct simple_arg {
19959 + struct vfsub_aopen_args *aopen;
19962 + const char *symname;
19971 +static int add_simple(struct inode *dir, struct dentry *dentry,
19972 + struct simple_arg *arg)
19975 + aufs_bindex_t btop;
19976 + unsigned char created;
19977 + const unsigned char try_aopen
19978 + = (arg->type == Creat && arg->u.c.try_aopen);
19979 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19980 + struct dentry *wh_dentry, *parent;
19981 + struct inode *h_dir;
19982 + struct super_block *sb;
19983 + struct au_branch *br;
19984 + /* to reduce stack size */
19986 + struct au_dtime dt;
19987 + struct au_pin pin;
19988 + struct path h_path;
19989 + struct au_wr_dir_args wr_dir_args;
19992 + AuDbg("%pd\n", dentry);
19996 + a = kmalloc(sizeof(*a), GFP_NOFS);
19997 + if (unlikely(!a))
19999 + a->wr_dir_args.force_btgt = -1;
20000 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
20002 + parent = dentry->d_parent; /* dir inode is locked */
20003 + if (!try_aopen) {
20004 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20005 + if (unlikely(err))
20008 + err = au_d_may_add(dentry);
20009 + if (unlikely(err))
20012 + di_write_lock_parent(parent);
20013 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20014 + &a->pin, &a->wr_dir_args);
20015 + err = PTR_ERR(wh_dentry);
20016 + if (IS_ERR(wh_dentry))
20019 + btop = au_dbtop(dentry);
20020 + sb = dentry->d_sb;
20021 + br = au_sbr(sb, btop);
20022 + a->h_path.dentry = au_h_dptr(dentry, btop);
20023 + a->h_path.mnt = au_br_mnt(br);
20024 + h_dir = au_pinned_h_dir(&a->pin);
20025 + switch (arg->type) {
20027 + if (!try_aopen || !h_dir->i_op->atomic_open) {
20028 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
20029 + arg->u.c.want_excl);
20031 + if (!err && try_aopen)
20032 + aopen->file->f_mode |= FMODE_CREATED;
20035 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
20036 + AuDbg("err %d\n", err);
20037 + AuDbgFile(aopen->file);
20038 + created = err >= 0
20039 + && !!(aopen->file->f_mode & FMODE_CREATED);
20043 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
20047 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
20054 + if (unlikely(err < 0))
20057 + err = epilog(dir, btop, wh_dentry, dentry);
20059 + goto out_unpin; /* success */
20062 + if (created /* && d_is_positive(a->h_path.dentry) */) {
20063 + /* no delegation since it is just created */
20064 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
20067 + AuIOErr("%pd revert failure(%d, %d)\n",
20068 + dentry, err, rerr);
20071 + au_dtime_revert(&a->dt);
20073 + if (try_aopen && h_dir->i_op->atomic_open
20074 + && (aopen->file->f_mode & FMODE_OPENED))
20075 + /* aopen->file is still opened */
20076 + au_lcnt_dec(&aopen->br->br_nfiles);
20079 + au_unpin(&a->pin);
20083 + di_write_unlock(parent);
20085 + if (unlikely(err)) {
20086 + au_update_dbtop(dentry);
20090 + aufs_read_unlock(dentry, AuLock_DW);
20097 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
20100 + struct simple_arg arg = {
20107 + return add_simple(dir, dentry, &arg);
20110 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
20112 + struct simple_arg arg = {
20114 + .u.s.symname = symname
20116 + return add_simple(dir, dentry, &arg);
20119 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
20122 + struct simple_arg arg = {
20126 + .want_excl = want_excl
20129 + return add_simple(dir, dentry, &arg);
20132 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20133 + struct vfsub_aopen_args *aopen_args)
20135 + struct simple_arg arg = {
20138 + .mode = aopen_args->create_mode,
20139 + .want_excl = aopen_args->open_flag & O_EXCL,
20140 + .try_aopen = true,
20141 + .aopen = aopen_args
20144 + return add_simple(dir, dentry, &arg);
20147 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
20150 + aufs_bindex_t bindex;
20151 + struct super_block *sb;
20152 + struct dentry *parent, *h_parent, *h_dentry;
20153 + struct inode *h_dir, *inode;
20154 + struct vfsmount *h_mnt;
20155 + struct au_wr_dir_args wr_dir_args = {
20156 + .force_btgt = -1,
20157 + .flags = AuWrDir_TMPFILE
20160 + /* copy-up may happen */
20164 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20165 + if (unlikely(err))
20168 + err = au_di_init(dentry);
20169 + if (unlikely(err))
20173 + parent = d_find_any_alias(dir);
20174 + AuDebugOn(!parent);
20175 + di_write_lock_parent(parent);
20176 + if (unlikely(d_inode(parent) != dir))
20179 + err = au_digen_test(parent, au_sigen(sb));
20180 + if (unlikely(err))
20183 + bindex = au_dbtop(parent);
20184 + au_set_dbtop(dentry, bindex);
20185 + au_set_dbbot(dentry, bindex);
20186 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
20188 + if (unlikely(err < 0))
20191 + err = -EOPNOTSUPP;
20192 + h_dir = au_h_iptr(dir, bindex);
20193 + if (unlikely(!h_dir->i_op->tmpfile))
20196 + h_mnt = au_sbr_mnt(sb, bindex);
20197 + err = vfsub_mnt_want_write(h_mnt);
20198 + if (unlikely(err))
20201 + h_parent = au_h_dptr(parent, bindex);
20202 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
20203 + if (IS_ERR(h_dentry)) {
20204 + err = PTR_ERR(h_dentry);
20208 + au_set_dbtop(dentry, bindex);
20209 + au_set_dbbot(dentry, bindex);
20210 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
20211 + inode = au_new_inode(dentry, /*must_new*/1);
20212 + if (IS_ERR(inode)) {
20213 + err = PTR_ERR(inode);
20214 + au_set_h_dptr(dentry, bindex, NULL);
20215 + au_set_dbtop(dentry, -1);
20216 + au_set_dbbot(dentry, -1);
20218 + if (!inode->i_nlink)
20219 + set_nlink(inode, 1);
20220 + d_tmpfile(dentry, inode);
20221 + au_di(dentry)->di_tmpfile = 1;
20223 + /* update without i_mutex */
20224 + if (au_ibtop(dir) == au_dbtop(dentry))
20225 + au_cpup_attr_timesizes(dir);
20230 + vfsub_mnt_drop_write(h_mnt);
20232 + di_write_unlock(parent);
20234 + di_write_unlock(dentry);
20235 + if (unlikely(err)) {
20236 + au_di_fin(dentry);
20237 + dentry->d_fsdata = NULL;
20240 + si_read_unlock(sb);
20242 + inode_unlock(dir);
20246 +/* ---------------------------------------------------------------------- */
20248 +struct au_link_args {
20249 + aufs_bindex_t bdst, bsrc;
20250 + struct au_pin pin;
20251 + struct path h_path;
20252 + struct dentry *src_parent, *parent;
20255 +static int au_cpup_before_link(struct dentry *src_dentry,
20256 + struct au_link_args *a)
20259 + struct dentry *h_src_dentry;
20260 + struct au_cp_generic cpg = {
20261 + .dentry = src_dentry,
20266 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20269 + di_read_lock_parent(a->src_parent, AuLock_IR);
20270 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20271 + if (unlikely(err))
20274 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20275 + err = au_pin(&a->pin, src_dentry, a->bdst,
20276 + au_opt_udba(src_dentry->d_sb),
20277 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20278 + if (unlikely(err))
20281 + err = au_sio_cpup_simple(&cpg);
20282 + au_unpin(&a->pin);
20285 + di_read_unlock(a->src_parent, AuLock_IR);
20289 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20290 + struct au_link_args *a)
20293 + unsigned char plink;
20294 + aufs_bindex_t bbot;
20295 + struct dentry *h_src_dentry;
20296 + struct inode *h_inode, *inode, *delegated;
20297 + struct super_block *sb;
20298 + struct file *h_file;
20302 + sb = src_dentry->d_sb;
20303 + inode = d_inode(src_dentry);
20304 + if (au_ibtop(inode) <= a->bdst)
20305 + h_inode = au_h_iptr(inode, a->bdst);
20306 + if (!h_inode || !h_inode->i_nlink) {
20307 + /* copyup src_dentry as the name of dentry. */
20308 + bbot = au_dbbot(dentry);
20309 + if (bbot < a->bsrc)
20310 + au_set_dbbot(dentry, a->bsrc);
20311 + au_set_h_dptr(dentry, a->bsrc,
20312 + dget(au_h_dptr(src_dentry, a->bsrc)));
20313 + dget(a->h_path.dentry);
20314 + au_set_h_dptr(dentry, a->bdst, NULL);
20315 + AuDbg("temporary d_inode...\n");
20316 + spin_lock(&dentry->d_lock);
20317 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20318 + spin_unlock(&dentry->d_lock);
20319 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20320 + if (IS_ERR(h_file))
20321 + err = PTR_ERR(h_file);
20323 + struct au_cp_generic cpg = {
20324 + .dentry = dentry,
20329 + .flags = AuCpup_KEEPLINO
20331 + err = au_sio_cpup_simple(&cpg);
20332 + au_h_open_post(dentry, a->bsrc, h_file);
20334 + dput(a->h_path.dentry);
20335 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20337 + au_set_h_dptr(dentry, a->bdst,
20338 + a->h_path.dentry);
20340 + spin_lock(&dentry->d_lock);
20341 + dentry->d_inode = NULL; /* restore */
20342 + spin_unlock(&dentry->d_lock);
20343 + AuDbg("temporary d_inode...done\n");
20344 + au_set_h_dptr(dentry, a->bsrc, NULL);
20345 + au_set_dbbot(dentry, bbot);
20347 + /* the inode of src_dentry already exists on a.bdst branch */
20348 + h_src_dentry = d_find_alias(h_inode);
20349 + if (!h_src_dentry && au_plink_test(inode)) {
20351 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20352 + err = PTR_ERR(h_src_dentry);
20353 + if (IS_ERR(h_src_dentry))
20356 + if (unlikely(d_is_negative(h_src_dentry))) {
20357 + dput(h_src_dentry);
20358 + h_src_dentry = NULL;
20362 + if (h_src_dentry) {
20363 + delegated = NULL;
20364 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20365 + &a->h_path, &delegated);
20366 + if (unlikely(err == -EWOULDBLOCK)) {
20367 + pr_warn("cannot retry for NFSv4 delegation"
20368 + " for an internal link\n");
20371 + dput(h_src_dentry);
20373 + AuIOErr("no dentry found for hi%lu on b%d\n",
20374 + h_inode->i_ino, a->bdst);
20379 + if (!err && !plink)
20380 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20387 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20388 + struct dentry *dentry)
20391 + struct au_dtime dt;
20392 + struct au_link_args *a;
20393 + struct dentry *wh_dentry, *h_src_dentry;
20394 + struct inode *inode, *delegated;
20395 + struct super_block *sb;
20396 + struct au_wr_dir_args wr_dir_args = {
20397 + /* .force_btgt = -1, */
20398 + .flags = AuWrDir_ADD_ENTRY
20402 + inode = d_inode(src_dentry);
20403 + IMustLock(inode);
20406 + a = kzalloc(sizeof(*a), GFP_NOFS);
20407 + if (unlikely(!a))
20410 + a->parent = dentry->d_parent; /* dir inode is locked */
20411 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20412 + AuLock_NOPLM | AuLock_GEN);
20413 + if (unlikely(err))
20415 + err = au_d_linkable(src_dentry);
20416 + if (unlikely(err))
20418 + err = au_d_may_add(dentry);
20419 + if (unlikely(err))
20422 + a->src_parent = dget_parent(src_dentry);
20423 + wr_dir_args.force_btgt = au_ibtop(inode);
20425 + di_write_lock_parent(a->parent);
20426 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20427 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20429 + err = PTR_ERR(wh_dentry);
20430 + if (IS_ERR(wh_dentry))
20434 + sb = dentry->d_sb;
20435 + a->bdst = au_dbtop(dentry);
20436 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20437 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20438 + a->bsrc = au_ibtop(inode);
20439 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20440 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20441 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20442 + if (!h_src_dentry) {
20443 + a->bsrc = au_dbtop(src_dentry);
20444 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20445 + AuDebugOn(!h_src_dentry);
20446 + } else if (IS_ERR(h_src_dentry)) {
20447 + err = PTR_ERR(h_src_dentry);
20452 + * aufs doesn't touch the credential so
20453 + * security_dentry_create_files_as() is unnecessary.
20455 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20456 + if (a->bdst < a->bsrc
20457 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20458 + err = au_cpup_or_link(src_dentry, dentry, a);
20460 + delegated = NULL;
20461 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20462 + &a->h_path, &delegated);
20463 + if (unlikely(err == -EWOULDBLOCK)) {
20464 + pr_warn("cannot retry for NFSv4 delegation"
20465 + " for an internal link\n");
20469 + dput(h_src_dentry);
20472 + * copyup src_dentry to the branch we process,
20473 + * and then link(2) to it.
20475 + dput(h_src_dentry);
20476 + if (a->bdst < a->bsrc
20477 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20478 + au_unpin(&a->pin);
20479 + di_write_unlock(a->parent);
20480 + err = au_cpup_before_link(src_dentry, a);
20481 + di_write_lock_parent(a->parent);
20483 + err = au_pin(&a->pin, dentry, a->bdst,
20485 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20486 + if (unlikely(err))
20490 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20492 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20493 + delegated = NULL;
20494 + err = vfsub_link(h_src_dentry,
20495 + au_pinned_h_dir(&a->pin),
20496 + &a->h_path, &delegated);
20497 + if (unlikely(err == -EWOULDBLOCK)) {
20498 + pr_warn("cannot retry"
20499 + " for NFSv4 delegation"
20500 + " for an internal link\n");
20506 + if (unlikely(err))
20510 + a->h_path.dentry = wh_dentry;
20511 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20513 + if (unlikely(err))
20517 + au_dir_ts(dir, a->bdst);
20518 + inode_inc_iversion(dir);
20519 + inc_nlink(inode);
20520 + inode->i_ctime = dir->i_ctime;
20521 + d_instantiate(dentry, au_igrab(inode));
20522 + if (d_unhashed(a->h_path.dentry))
20523 + /* some filesystem calls d_drop() */
20525 + /* some filesystems consume an inode even hardlink */
20526 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20527 + goto out_unpin; /* success */
20530 + /* no delegation since it is just created */
20531 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20532 + /*delegated*/NULL, /*force*/0);
20533 + if (unlikely(rerr)) {
20534 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20537 + au_dtime_revert(&dt);
20539 + au_unpin(&a->pin);
20543 + di_write_unlock(a->parent);
20544 + dput(a->src_parent);
20546 + if (unlikely(err)) {
20547 + au_update_dbtop(dentry);
20550 + aufs_read_and_write_unlock2(dentry, src_dentry);
20558 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20561 + aufs_bindex_t bindex;
20562 + unsigned char diropq;
20563 + struct path h_path;
20564 + struct dentry *wh_dentry, *parent, *opq_dentry;
20565 + struct inode *h_inode;
20566 + struct super_block *sb;
20568 + struct au_pin pin;
20569 + struct au_dtime dt;
20570 + } *a; /* reduce the stack usage */
20571 + struct au_wr_dir_args wr_dir_args = {
20572 + .force_btgt = -1,
20573 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20579 + a = kmalloc(sizeof(*a), GFP_NOFS);
20580 + if (unlikely(!a))
20583 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20584 + if (unlikely(err))
20586 + err = au_d_may_add(dentry);
20587 + if (unlikely(err))
20590 + parent = dentry->d_parent; /* dir inode is locked */
20591 + di_write_lock_parent(parent);
20592 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20593 + &a->pin, &wr_dir_args);
20594 + err = PTR_ERR(wh_dentry);
20595 + if (IS_ERR(wh_dentry))
20598 + sb = dentry->d_sb;
20599 + bindex = au_dbtop(dentry);
20600 + h_path.dentry = au_h_dptr(dentry, bindex);
20601 + h_path.mnt = au_sbr_mnt(sb, bindex);
20602 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20603 + if (unlikely(err))
20606 + /* make the dir opaque */
20608 + h_inode = d_inode(h_path.dentry);
20610 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20611 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20612 + opq_dentry = au_diropq_create(dentry, bindex);
20613 + inode_unlock(h_inode);
20614 + err = PTR_ERR(opq_dentry);
20615 + if (IS_ERR(opq_dentry))
20617 + dput(opq_dentry);
20621 + err = epilog(dir, bindex, wh_dentry, dentry);
20624 + goto out_unpin; /* success */
20629 + AuLabel(revert opq);
20630 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20631 + rerr = au_diropq_remove(dentry, bindex);
20632 + inode_unlock(h_inode);
20634 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20635 + dentry, err, rerr);
20641 + AuLabel(revert dir);
20642 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20644 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20645 + dentry, err, rerr);
20648 + au_dtime_revert(&a->dt);
20650 + au_unpin(&a->pin);
20653 + di_write_unlock(parent);
20655 + if (unlikely(err)) {
20656 + au_update_dbtop(dentry);
20659 + aufs_read_unlock(dentry, AuLock_DW);
20665 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20666 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20667 +++ linux/fs/aufs/i_op.c 2018-12-27 13:19:17.708416053 +0100
20669 +// SPDX-License-Identifier: GPL-2.0
20671 + * Copyright (C) 2005-2018 Junjiro R. Okajima
20673 + * This program, aufs is free software; you can redistribute it and/or modify
20674 + * it under the terms of the GNU General Public License as published by
20675 + * the Free Software Foundation; either version 2 of the License, or
20676 + * (at your option) any later version.
20678 + * This program is distributed in the hope that it will be useful,
20679 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20680 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20681 + * GNU General Public License for more details.
20683 + * You should have received a copy of the GNU General Public License
20684 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20688 + * inode operations (except add/del/rename)
20691 +#include <linux/device_cgroup.h>
20692 +#include <linux/fs_stack.h>
20693 +#include <linux/namei.h>
20694 +#include <linux/security.h>
20697 +static int h_permission(struct inode *h_inode, int mask,
20698 + struct path *h_path, int brperm)
20701 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20704 + if (write_mask && IS_IMMUTABLE(h_inode))
20708 + if (((mask & MAY_EXEC)
20709 + && S_ISREG(h_inode->i_mode)
20710 + && (path_noexec(h_path)
20711 + || !(h_inode->i_mode & 0111))))
20715 + * - skip the lower fs test in the case of write to ro branch.
20716 + * - nfs dir permission write check is optimized, but a policy for
20717 + * link/rename requires a real check.
20718 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20719 + * in this case, generic_permission() returns -EOPNOTSUPP.
20721 + if ((write_mask && !au_br_writable(brperm))
20722 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20723 + && write_mask && !(mask & MAY_READ))
20724 + || !h_inode->i_op->permission) {
20725 + /* AuLabel(generic_permission); */
20726 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20727 + err = generic_permission(h_inode, mask);
20728 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20729 + err = h_inode->i_op->permission(h_inode, mask);
20732 + /* AuLabel(h_inode->permission); */
20733 + err = h_inode->i_op->permission(h_inode, mask);
20738 + err = devcgroup_inode_permission(h_inode, mask);
20740 + err = security_inode_permission(h_inode, mask);
20744 + /* todo: do we need to call ima_path_check()? */
20745 + struct path h_path = {
20749 + err = ima_path_check(&h_path,
20750 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
20751 + IMA_COUNT_LEAVE);
20759 +static int aufs_permission(struct inode *inode, int mask)
20762 + aufs_bindex_t bindex, bbot;
20763 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20764 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20765 + struct inode *h_inode;
20766 + struct super_block *sb;
20767 + struct au_branch *br;
20769 + /* todo: support rcu-walk? */
20770 + if (mask & MAY_NOT_BLOCK)
20773 + sb = inode->i_sb;
20774 + si_read_lock(sb, AuLock_FLUSH);
20775 + ii_read_lock_child(inode);
20777 + err = au_iigen_test(inode, au_sigen(sb));
20778 + if (unlikely(err))
20784 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20785 + err = au_busy_or_stale();
20786 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20787 + if (unlikely(!h_inode
20788 + || (h_inode->i_mode & S_IFMT)
20789 + != (inode->i_mode & S_IFMT)))
20793 + bindex = au_ibtop(inode);
20794 + br = au_sbr(sb, bindex);
20795 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20798 + && !special_file(h_inode->i_mode)) {
20799 + /* test whether the upper writable branch exists */
20801 + for (; bindex >= 0; bindex--)
20802 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20810 + /* non-write to dir */
20812 + bbot = au_ibbot(inode);
20813 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20814 + h_inode = au_h_iptr(inode, bindex);
20816 + err = au_busy_or_stale();
20817 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20820 + br = au_sbr(sb, bindex);
20821 + err = h_permission(h_inode, mask, &br->br_path,
20827 + ii_read_unlock(inode);
20828 + si_read_unlock(sb);
20832 +/* ---------------------------------------------------------------------- */
20834 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20835 + unsigned int flags)
20837 + struct dentry *ret, *parent;
20838 + struct inode *inode;
20839 + struct super_block *sb;
20840 + int err, npositive;
20844 + /* todo: support rcu-walk? */
20845 + ret = ERR_PTR(-ECHILD);
20846 + if (flags & LOOKUP_RCU)
20849 + ret = ERR_PTR(-ENAMETOOLONG);
20850 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20854 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20855 + ret = ERR_PTR(err);
20856 + if (unlikely(err))
20859 + err = au_di_init(dentry);
20860 + ret = ERR_PTR(err);
20861 + if (unlikely(err))
20865 + npositive = 0; /* suppress a warning */
20866 + parent = dentry->d_parent; /* dir inode is locked */
20867 + di_read_lock_parent(parent, AuLock_IR);
20868 + err = au_alive_dir(parent);
20870 + err = au_digen_test(parent, au_sigen(sb));
20872 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20873 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20874 + AuLkup_ALLOW_NEG);
20877 + di_read_unlock(parent, AuLock_IR);
20878 + ret = ERR_PTR(err);
20879 + if (unlikely(err < 0))
20883 + inode = au_new_inode(dentry, /*must_new*/0);
20884 + if (IS_ERR(inode)) {
20885 + ret = (void *)inode;
20892 + atomic_inc(&inode->i_count);
20893 + ret = d_splice_alias(inode, dentry);
20895 + if (unlikely(d_need_lookup(dentry))) {
20896 + spin_lock(&dentry->d_lock);
20897 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20898 + spin_unlock(&dentry->d_lock);
20902 + if (!IS_ERR(ret)) {
20904 + if (ret && ret != dentry)
20905 + ii_write_unlock(inode);
20907 + ii_write_unlock(inode);
20914 + di_write_unlock(dentry);
20916 + si_read_unlock(sb);
20921 +/* ---------------------------------------------------------------------- */
20924 + * very dirty and complicated aufs ->atomic_open().
20925 + * aufs_atomic_open()
20926 + * + au_aopen_or_create()
20928 + * + vfsub_atomic_open()
20929 + * + branch fs ->atomic_open()
20930 + * may call the actual 'open' for h_file
20931 + * + inc br_nfiles only if opened
20932 + * + au_aopen_no_open() or au_aopen_do_open()
20934 + * au_aopen_do_open()
20935 + * + finish_open()
20936 + * + au_do_aopen()
20937 + * + au_do_open() the body of all 'open'
20938 + * + au_do_open_nondir()
20939 + * set the passed h_file
20941 + * au_aopen_no_open()
20942 + * + finish_no_open()
20945 +struct aopen_node {
20946 + struct hlist_bl_node hblist;
20947 + struct file *file, *h_file;
20950 +static int au_do_aopen(struct inode *inode, struct file *file)
20952 + struct hlist_bl_head *aopen;
20953 + struct hlist_bl_node *pos;
20954 + struct aopen_node *node;
20955 + struct au_do_open_args args = {
20957 + .open = au_do_open_nondir
20960 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20961 + hlist_bl_lock(aopen);
20962 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20963 + if (node->file == file) {
20964 + args.h_file = node->h_file;
20967 + hlist_bl_unlock(aopen);
20968 + /* AuDebugOn(!args.h_file); */
20970 + return au_do_open(file, &args);
20973 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20974 + struct aopen_node *aopen_node)
20977 + struct hlist_bl_head *aopen;
20980 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20981 + au_hbl_add(&aopen_node->hblist, aopen);
20982 + err = finish_open(file, dentry, au_do_aopen);
20983 + au_hbl_del(&aopen_node->hblist, aopen);
20984 + /* AuDbgFile(file); */
20985 + AuDbg("%pd%s%s\n", dentry,
20986 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20987 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20993 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20999 + err = finish_no_open(file, dentry);
21005 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
21006 + struct file *file, unsigned int open_flag,
21007 + umode_t create_mode)
21009 + int err, did_open;
21010 + unsigned int lkup_flags;
21011 + aufs_bindex_t bindex;
21012 + struct super_block *sb;
21013 + struct dentry *parent, *d;
21014 + struct vfsub_aopen_args args = {
21015 + .open_flag = open_flag,
21016 + .create_mode = create_mode
21018 + struct aopen_node aopen_node = {
21023 + AuDbg("open_flag 0%o\n", open_flag);
21024 + AuDbgDentry(dentry);
21027 + if (!au_di(dentry)) {
21028 + lkup_flags = LOOKUP_OPEN;
21029 + if (open_flag & O_CREAT)
21030 + lkup_flags |= LOOKUP_CREATE;
21031 + d = aufs_lookup(dir, dentry, lkup_flags);
21033 + err = PTR_ERR(d);
21038 + * obsoleted dentry found.
21039 + * another error will be returned later.
21045 + AuDbgDentry(dentry);
21048 + if (d_is_positive(dentry)
21049 + || d_unhashed(dentry)
21050 + || d_unlinked(dentry)
21051 + || !(open_flag & O_CREAT)) {
21052 + err = au_aopen_no_open(file, dentry);
21053 + goto out; /* success */
21056 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
21057 + if (unlikely(err))
21060 + sb = dentry->d_sb;
21061 + parent = dentry->d_parent; /* dir is locked */
21062 + di_write_lock_parent(parent);
21063 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
21064 + if (unlikely(err < 0))
21067 + AuDbgDentry(dentry);
21068 + if (d_is_positive(dentry)) {
21069 + err = au_aopen_no_open(file, dentry);
21070 + goto out_parent; /* success */
21073 + args.file = alloc_empty_file(file->f_flags, current_cred());
21074 + err = PTR_ERR(args.file);
21075 + if (IS_ERR(args.file))
21078 + bindex = au_dbtop(dentry);
21079 + err = au_aopen_or_create(dir, dentry, &args);
21081 + AuDbgFile(args.file);
21082 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
21083 + did_open = !!(args.file->f_mode & FMODE_OPENED);
21086 + args.file = NULL;
21088 + di_write_unlock(parent);
21089 + di_write_unlock(dentry);
21090 + if (unlikely(err < 0)) {
21097 + err = au_aopen_no_open(file, dentry);
21099 + aopen_node.h_file = args.file;
21100 + err = au_aopen_do_open(file, dentry, &aopen_node);
21102 + if (unlikely(err < 0)) {
21106 + au_lcnt_dec(&args.br->br_nfiles);
21108 + goto out_sb; /* success */
21111 + di_write_unlock(parent);
21112 + di_write_unlock(dentry);
21114 + si_read_unlock(sb);
21122 +/* ---------------------------------------------------------------------- */
21124 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
21125 + const unsigned char add_entry, aufs_bindex_t bcpup,
21126 + aufs_bindex_t btop)
21129 + struct dentry *h_parent;
21130 + struct inode *h_dir;
21133 + IMustLock(d_inode(parent));
21135 + di_write_lock_parent(parent);
21138 + if (!au_h_dptr(parent, bcpup)) {
21139 + if (btop > bcpup)
21140 + err = au_cpup_dirs(dentry, bcpup);
21141 + else if (btop < bcpup)
21142 + err = au_cpdown_dirs(dentry, bcpup);
21146 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
21147 + h_parent = au_h_dptr(parent, bcpup);
21148 + h_dir = d_inode(h_parent);
21149 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
21150 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
21151 + /* todo: no unlock here */
21152 + inode_unlock_shared(h_dir);
21154 + AuDbg("bcpup %d\n", bcpup);
21156 + if (d_really_is_negative(dentry))
21157 + au_set_h_dptr(dentry, btop, NULL);
21158 + au_update_dbrange(dentry, /*do_put_zero*/0);
21163 + di_write_unlock(parent);
21165 + err = bcpup; /* success */
21172 + * decide the branch and the parent dir where we will create a new entry.
21173 + * returns new bindex or an error.
21174 + * copyup the parent dir if needed.
21176 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
21177 + struct au_wr_dir_args *args)
21180 + unsigned int flags;
21181 + aufs_bindex_t bcpup, btop, src_btop;
21182 + const unsigned char add_entry
21183 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
21184 + | au_ftest_wrdir(args->flags, TMPFILE);
21185 + struct super_block *sb;
21186 + struct dentry *parent;
21187 + struct au_sbinfo *sbinfo;
21189 + sb = dentry->d_sb;
21190 + sbinfo = au_sbi(sb);
21191 + parent = dget_parent(dentry);
21192 + btop = au_dbtop(dentry);
21194 + if (args->force_btgt < 0) {
21195 + if (src_dentry) {
21196 + src_btop = au_dbtop(src_dentry);
21197 + if (src_btop < btop)
21198 + bcpup = src_btop;
21199 + } else if (add_entry) {
21201 + if (au_ftest_wrdir(args->flags, ISDIR))
21202 + au_fset_wbr(flags, DIR);
21203 + err = AuWbrCreate(sbinfo, dentry, flags);
21207 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
21209 + err = AuWbrCopyup(sbinfo, dentry);
21211 + if (!IS_ROOT(dentry)) {
21212 + di_read_lock_parent(parent, !AuLock_IR);
21213 + err = AuWbrCopyup(sbinfo, dentry);
21214 + di_read_unlock(parent, !AuLock_IR);
21216 + err = AuWbrCopyup(sbinfo, dentry);
21219 + if (unlikely(err < 0))
21223 + bcpup = args->force_btgt;
21224 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21227 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21229 + if (bcpup == btop)
21230 + goto out; /* success */
21232 + /* copyup the new parent into the branch we process */
21233 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21235 + if (d_really_is_negative(dentry)) {
21236 + au_set_h_dptr(dentry, btop, NULL);
21237 + au_set_dbtop(dentry, bcpup);
21238 + au_set_dbbot(dentry, bcpup);
21240 + AuDebugOn(add_entry
21241 + && !au_ftest_wrdir(args->flags, TMPFILE)
21242 + && !au_h_dptr(dentry, bcpup));
21250 +/* ---------------------------------------------------------------------- */
21252 +void au_pin_hdir_unlock(struct au_pin *p)
21255 + au_hn_inode_unlock(p->hdir);
21258 +int au_pin_hdir_lock(struct au_pin *p)
21266 + /* even if an error happens later, keep this lock */
21267 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21270 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21275 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21276 + p->h_parent, p->br);
21282 +int au_pin_hdir_relock(struct au_pin *p)
21285 + struct inode *h_i;
21286 + struct dentry *h_d[] = {
21291 + err = au_pin_hdir_lock(p);
21292 + if (unlikely(err))
21295 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21298 + if (d_is_positive(h_d[i])) {
21299 + h_i = d_inode(h_d[i]);
21300 + err = !h_i->i_nlink;
21308 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21310 +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER)
21311 + p->hdir->hi_inode->i_rwsem.owner = task;
21315 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21318 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21319 + p->lsc_hi, 0, NULL, _RET_IP_);
21320 + au_pin_hdir_set_owner(p, current);
21324 +void au_pin_hdir_release(struct au_pin *p)
21327 + au_pin_hdir_set_owner(p, p->task);
21328 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
21332 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21334 + if (pin && pin->parent)
21335 + return au_h_dptr(pin->parent, pin->bindex);
21339 +void au_unpin(struct au_pin *p)
21342 + au_pin_hdir_unlock(p);
21343 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21344 + vfsub_mnt_drop_write(p->h_mnt);
21348 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21349 + di_read_unlock(p->parent, AuLock_IR);
21350 + iput(p->hdir->hi_inode);
21352 + p->parent = NULL;
21355 + /* do not clear p->task */
21358 +int au_do_pin(struct au_pin *p)
21361 + struct super_block *sb;
21362 + struct inode *h_dir;
21365 + sb = p->dentry->d_sb;
21366 + p->br = au_sbr(sb, p->bindex);
21367 + if (IS_ROOT(p->dentry)) {
21368 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21369 + p->h_mnt = au_br_mnt(p->br);
21370 + err = vfsub_mnt_want_write(p->h_mnt);
21371 + if (unlikely(err)) {
21372 + au_fclr_pin(p->flags, MNT_WRITE);
21379 + p->h_dentry = NULL;
21380 + if (p->bindex <= au_dbbot(p->dentry))
21381 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21383 + p->parent = dget_parent(p->dentry);
21384 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21385 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21388 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21389 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21391 + h_dir = p->hdir->hi_inode;
21395 + * if DI_LOCKED is not set, then p->parent may be different
21396 + * and h_parent can be NULL.
21398 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21400 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21401 + di_read_unlock(p->parent, AuLock_IR);
21403 + p->parent = NULL;
21407 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21408 + p->h_mnt = au_br_mnt(p->br);
21409 + err = vfsub_mnt_want_write(p->h_mnt);
21410 + if (unlikely(err)) {
21411 + au_fclr_pin(p->flags, MNT_WRITE);
21412 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21413 + di_read_unlock(p->parent, AuLock_IR);
21415 + p->parent = NULL;
21421 + err = au_pin_hdir_lock(p);
21423 + goto out; /* success */
21428 + pr_err("err %d\n", err);
21429 + err = au_busy_or_stale();
21434 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21435 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21436 + unsigned int udba, unsigned char flags)
21438 + p->dentry = dentry;
21440 + p->lsc_di = lsc_di;
21441 + p->lsc_hi = lsc_hi;
21442 + p->flags = flags;
21443 + p->bindex = bindex;
21445 + p->parent = NULL;
21449 + p->h_dentry = NULL;
21450 + p->h_parent = NULL;
21452 + p->task = current;
21455 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21456 + unsigned int udba, unsigned char flags)
21458 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21460 + return au_do_pin(pin);
21463 +/* ---------------------------------------------------------------------- */
21466 + * ->setattr() and ->getattr() are called in various cases.
21467 + * chmod, stat: dentry is revalidated.
21468 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21470 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21472 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21473 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21476 + struct dentry *parent;
21479 + if (au_digen_test(dentry, sigen)) {
21480 + parent = dget_parent(dentry);
21481 + di_read_lock_parent(parent, AuLock_IR);
21482 + err = au_refresh_dentry(dentry, parent);
21483 + di_read_unlock(parent, AuLock_IR);
21491 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21492 + struct au_icpup_args *a)
21496 + aufs_bindex_t btop, ibtop;
21497 + struct dentry *hi_wh, *parent;
21498 + struct inode *inode;
21499 + struct au_wr_dir_args wr_dir_args = {
21500 + .force_btgt = -1,
21504 + if (d_is_dir(dentry))
21505 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21506 + /* plink or hi_wh() case */
21507 + btop = au_dbtop(dentry);
21508 + inode = d_inode(dentry);
21509 + ibtop = au_ibtop(inode);
21510 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21511 + wr_dir_args.force_btgt = ibtop;
21512 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21513 + if (unlikely(err < 0))
21517 + au_fset_icpup(a->flags, DID_CPUP);
21520 + a->pin_flags = AuPin_MNT_WRITE;
21522 + if (!IS_ROOT(dentry)) {
21523 + au_fset_pin(a->pin_flags, DI_LOCKED);
21524 + parent = dget_parent(dentry);
21525 + di_write_lock_parent(parent);
21528 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21529 + if (unlikely(err))
21533 + a->h_path.dentry = au_h_dptr(dentry, btop);
21534 + a->h_inode = d_inode(a->h_path.dentry);
21535 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21536 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21537 + if (ia->ia_size < i_size_read(a->h_inode))
21538 + sz = ia->ia_size;
21539 + inode_unlock_shared(a->h_inode);
21543 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21544 + hi_wh = au_hi_wh(inode, a->btgt);
21546 + struct au_cp_generic cpg = {
21547 + .dentry = dentry,
21553 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21554 + if (unlikely(err))
21556 + hi_wh = au_hi_wh(inode, a->btgt);
21557 + /* todo: revalidate hi_wh? */
21562 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21563 + di_downgrade_lock(parent, AuLock_IR);
21567 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21568 + goto out; /* success */
21570 + if (!d_unhashed(dentry)) {
21571 + struct au_cp_generic cpg = {
21572 + .dentry = dentry,
21577 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21579 + err = au_sio_cpup_simple(&cpg);
21581 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21582 + } else if (!hi_wh)
21583 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21585 + a->h_path.dentry = hi_wh; /* do not dget here */
21588 + a->h_inode = d_inode(a->h_path.dentry);
21590 + goto out; /* success */
21591 + au_unpin(&a->pin);
21594 + di_write_unlock(parent);
21599 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21603 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21606 + struct inode *inode, *delegated;
21607 + struct super_block *sb;
21608 + struct file *file;
21609 + struct au_icpup_args *a;
21611 + inode = d_inode(dentry);
21612 + IMustLock(inode);
21614 + err = setattr_prepare(dentry, ia);
21615 + if (unlikely(err))
21619 + a = kzalloc(sizeof(*a), GFP_NOFS);
21620 + if (unlikely(!a))
21623 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21624 + ia->ia_valid &= ~ATTR_MODE;
21627 + sb = dentry->d_sb;
21628 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21629 + if (unlikely(err))
21632 + if (ia->ia_valid & ATTR_FILE) {
21633 + /* currently ftruncate(2) only */
21634 + AuDebugOn(!d_is_reg(dentry));
21635 + file = ia->ia_file;
21636 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21638 + if (unlikely(err))
21640 + ia->ia_file = au_hf_top(file);
21641 + a->udba = AuOpt_UDBA_NONE;
21643 + /* fchmod() doesn't pass ia_file */
21644 + a->udba = au_opt_udba(sb);
21645 + di_write_lock_child(dentry);
21646 + /* no d_unlinked(), to set UDBA_NONE for root */
21647 + if (d_unhashed(dentry))
21648 + a->udba = AuOpt_UDBA_NONE;
21649 + if (a->udba != AuOpt_UDBA_NONE) {
21650 + AuDebugOn(IS_ROOT(dentry));
21651 + err = au_reval_for_attr(dentry, au_sigen(sb));
21652 + if (unlikely(err))
21657 + err = au_pin_and_icpup(dentry, ia, a);
21658 + if (unlikely(err < 0))
21660 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21661 + ia->ia_file = NULL;
21662 + ia->ia_valid &= ~ATTR_FILE;
21665 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21666 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21667 + == (ATTR_MODE | ATTR_CTIME)) {
21668 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21669 + if (unlikely(err))
21671 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21672 + && (ia->ia_valid & ATTR_CTIME)) {
21673 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21674 + if (unlikely(err))
21678 + if (ia->ia_valid & ATTR_SIZE) {
21681 + if (ia->ia_size < i_size_read(inode))
21683 + truncate_setsize(inode, ia->ia_size);
21686 + if (ia->ia_valid & ATTR_FILE)
21688 + inode_unlock(a->h_inode);
21689 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21690 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21692 + delegated = NULL;
21694 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21696 + err = break_deleg_wait(&delegated);
21704 + * regardless aufs 'acl' option setting.
21705 + * why don't all acl-aware fs call this func from their ->setattr()?
21707 + if (!err && (ia->ia_valid & ATTR_MODE))
21708 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21710 + au_cpup_attr_changeable(inode);
21713 + inode_unlock(a->h_inode);
21714 + au_unpin(&a->pin);
21715 + if (unlikely(err))
21716 + au_update_dbtop(dentry);
21718 + di_write_unlock(dentry);
21720 + fi_write_unlock(file);
21721 + ia->ia_file = file;
21722 + ia->ia_valid |= ATTR_FILE;
21725 + si_read_unlock(sb);
21733 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21734 +static int au_h_path_to_set_attr(struct dentry *dentry,
21735 + struct au_icpup_args *a, struct path *h_path)
21738 + struct super_block *sb;
21740 + sb = dentry->d_sb;
21741 + a->udba = au_opt_udba(sb);
21742 + /* no d_unlinked(), to set UDBA_NONE for root */
21743 + if (d_unhashed(dentry))
21744 + a->udba = AuOpt_UDBA_NONE;
21745 + if (a->udba != AuOpt_UDBA_NONE) {
21746 + AuDebugOn(IS_ROOT(dentry));
21747 + err = au_reval_for_attr(dentry, au_sigen(sb));
21748 + if (unlikely(err))
21751 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21752 + if (unlikely(err < 0))
21755 + h_path->dentry = a->h_path.dentry;
21756 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21762 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21763 + struct au_sxattr *arg)
21766 + struct path h_path;
21767 + struct super_block *sb;
21768 + struct au_icpup_args *a;
21769 + struct inode *h_inode;
21771 + IMustLock(inode);
21774 + a = kzalloc(sizeof(*a), GFP_NOFS);
21775 + if (unlikely(!a))
21778 + sb = dentry->d_sb;
21779 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21780 + if (unlikely(err))
21783 + h_path.dentry = NULL; /* silence gcc */
21784 + di_write_lock_child(dentry);
21785 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21786 + if (unlikely(err))
21789 + inode_unlock(a->h_inode);
21790 + switch (arg->type) {
21791 + case AU_XATTR_SET:
21792 + AuDebugOn(d_is_negative(h_path.dentry));
21793 + err = vfsub_setxattr(h_path.dentry,
21794 + arg->u.set.name, arg->u.set.value,
21795 + arg->u.set.size, arg->u.set.flags);
21798 + err = -EOPNOTSUPP;
21799 + h_inode = d_inode(h_path.dentry);
21800 + if (h_inode->i_op->set_acl)
21801 + /* this will call posix_acl_update_mode */
21802 + err = h_inode->i_op->set_acl(h_inode,
21803 + arg->u.acl_set.acl,
21804 + arg->u.acl_set.type);
21808 + au_cpup_attr_timesizes(inode);
21810 + au_unpin(&a->pin);
21811 + if (unlikely(err))
21812 + au_update_dbtop(dentry);
21815 + di_write_unlock(dentry);
21816 + si_read_unlock(sb);
21825 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21826 + unsigned int nlink)
21830 + inode->i_mode = st->mode;
21831 + /* don't i_[ug]id_write() here */
21832 + inode->i_uid = st->uid;
21833 + inode->i_gid = st->gid;
21834 + inode->i_atime = st->atime;
21835 + inode->i_mtime = st->mtime;
21836 + inode->i_ctime = st->ctime;
21838 + au_cpup_attr_nlink(inode, /*force*/0);
21839 + if (S_ISDIR(inode->i_mode)) {
21840 + n = inode->i_nlink;
21843 + smp_mb(); /* for i_nlink */
21844 + /* 0 can happen */
21845 + set_nlink(inode, n);
21848 + spin_lock(&inode->i_lock);
21849 + inode->i_blocks = st->blocks;
21850 + i_size_write(inode, st->size);
21851 + spin_unlock(&inode->i_lock);
21855 + * common routine for aufs_getattr() and au_getxattr().
21856 + * returns zero or negative (an error).
21857 + * @dentry will be read-locked in success.
21859 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
21863 + unsigned int mnt_flags, sigen;
21864 + unsigned char udba_none;
21865 + aufs_bindex_t bindex;
21866 + struct super_block *sb, *h_sb;
21867 + struct inode *inode;
21869 + h_path->mnt = NULL;
21870 + h_path->dentry = NULL;
21873 + sb = dentry->d_sb;
21874 + mnt_flags = au_mntflags(sb);
21875 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21877 + if (unlikely(locked))
21878 + goto body; /* skip locking dinfo */
21880 + /* support fstat(2) */
21881 + if (!d_unlinked(dentry) && !udba_none) {
21882 + sigen = au_sigen(sb);
21883 + err = au_digen_test(dentry, sigen);
21885 + di_read_lock_child(dentry, AuLock_IR);
21886 + err = au_dbrange_test(dentry);
21887 + if (unlikely(err)) {
21888 + di_read_unlock(dentry, AuLock_IR);
21892 + AuDebugOn(IS_ROOT(dentry));
21893 + di_write_lock_child(dentry);
21894 + err = au_dbrange_test(dentry);
21896 + err = au_reval_for_attr(dentry, sigen);
21898 + di_downgrade_lock(dentry, AuLock_IR);
21900 + di_write_unlock(dentry);
21905 + di_read_lock_child(dentry, AuLock_IR);
21908 + inode = d_inode(dentry);
21909 + bindex = au_ibtop(inode);
21910 + h_path->mnt = au_sbr_mnt(sb, bindex);
21911 + h_sb = h_path->mnt->mnt_sb;
21913 + && !au_test_fs_bad_iattr(h_sb)
21915 + goto out; /* success */
21917 + if (au_dbtop(dentry) == bindex)
21918 + h_path->dentry = au_h_dptr(dentry, bindex);
21919 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21920 + h_path->dentry = au_plink_lkup(inode, bindex);
21921 + if (IS_ERR(h_path->dentry))
21922 + /* pretending success */
21923 + h_path->dentry = NULL;
21925 + dput(h_path->dentry);
21932 +static int aufs_getattr(const struct path *path, struct kstat *st,
21933 + u32 request, unsigned int query)
21936 + unsigned char positive;
21937 + struct path h_path;
21938 + struct dentry *dentry;
21939 + struct inode *inode;
21940 + struct super_block *sb;
21942 + dentry = path->dentry;
21943 + inode = d_inode(dentry);
21944 + sb = dentry->d_sb;
21945 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21946 + if (unlikely(err))
21948 + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
21949 + if (unlikely(err))
21951 + if (unlikely(!h_path.dentry))
21952 + /* illegally overlapped or something */
21953 + goto out_fill; /* pretending success */
21955 + positive = d_is_positive(h_path.dentry);
21957 + /* no vfsub version */
21958 + err = vfs_getattr(&h_path, st, request, query);
21961 + au_refresh_iattr(inode, st,
21962 + d_inode(h_path.dentry)->i_nlink);
21963 + goto out_fill; /* success */
21969 + generic_fillattr(inode, st);
21971 + di_read_unlock(dentry, AuLock_IR);
21973 + si_read_unlock(sb);
21979 +/* ---------------------------------------------------------------------- */
21981 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21982 + struct delayed_call *done)
21985 + struct dentry *h_dentry;
21986 + struct inode *h_inode;
21988 + aufs_bindex_t bindex;
21990 + ret = NULL; /* suppress a warning */
21995 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21996 + if (unlikely(err))
21999 + err = au_d_hashed_positive(dentry);
22000 + if (unlikely(err))
22004 + inode = d_inode(dentry);
22005 + bindex = au_ibtop(inode);
22006 + h_inode = au_h_iptr(inode, bindex);
22007 + if (unlikely(!h_inode->i_op->get_link))
22012 + if (au_dbtop(dentry) <= bindex) {
22013 + h_dentry = au_h_dptr(dentry, bindex);
22018 + h_dentry = d_find_any_alias(h_inode);
22019 + if (IS_ERR(h_dentry)) {
22020 + err = PTR_ERR(h_dentry);
22024 + if (unlikely(!h_dentry))
22028 + AuDbg("%ps\n", h_inode->i_op->get_link);
22029 + AuDbgDentry(h_dentry);
22030 + ret = vfs_get_link(h_dentry, done);
22033 + err = PTR_ERR(ret);
22036 + aufs_read_unlock(dentry, AuLock_IR);
22038 + if (unlikely(err))
22039 + ret = ERR_PTR(err);
22040 + AuTraceErrPtr(ret);
22044 +/* ---------------------------------------------------------------------- */
22046 +static int au_is_special(struct inode *inode)
22048 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
22051 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
22055 + aufs_bindex_t bindex;
22056 + struct super_block *sb;
22057 + struct inode *h_inode;
22058 + struct vfsmount *h_mnt;
22060 + sb = inode->i_sb;
22061 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
22062 + "unexpected s_flags 0x%lx", sb->s_flags);
22064 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
22066 + si_read_lock(sb, AuLock_FLUSH);
22067 + ii_write_lock_child(inode);
22070 + bindex = au_ibtop(inode);
22071 + h_inode = au_h_iptr(inode, bindex);
22072 + if (!au_test_ro(sb, bindex, inode)) {
22073 + h_mnt = au_sbr_mnt(sb, bindex);
22074 + err = vfsub_mnt_want_write(h_mnt);
22076 + err = vfsub_update_time(h_inode, ts, flags);
22077 + vfsub_mnt_drop_write(h_mnt);
22079 + } else if (au_is_special(h_inode)) {
22081 + * Never copy-up here.
22082 + * These special files may already be opened and used for
22083 + * communicating. If we copied it up, then the communication
22084 + * would be corrupted.
22086 + AuWarn1("timestamps for i%lu are ignored "
22087 + "since it is on readonly branch (hi%lu).\n",
22088 + inode->i_ino, h_inode->i_ino);
22089 + } else if (flags & ~S_ATIME) {
22091 + AuIOErr1("unexpected flags 0x%x\n", flags);
22096 + au_cpup_attr_timesizes(inode);
22097 + ii_write_unlock(inode);
22098 + si_read_unlock(sb);
22101 + if (!err && (flags & S_VERSION))
22102 + inode_inc_iversion(inode);
22107 +/* ---------------------------------------------------------------------- */
22109 +/* no getattr version will be set by module.c:aufs_init() */
22110 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
22112 + [AuIop_SYMLINK] = {
22113 + .permission = aufs_permission,
22114 +#ifdef CONFIG_FS_POSIX_ACL
22115 + .get_acl = aufs_get_acl,
22116 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
22119 + .setattr = aufs_setattr,
22120 + .getattr = aufs_getattr,
22122 +#ifdef CONFIG_AUFS_XATTR
22123 + .listxattr = aufs_listxattr,
22126 + .get_link = aufs_get_link,
22128 + /* .update_time = aufs_update_time */
22131 + .create = aufs_create,
22132 + .lookup = aufs_lookup,
22133 + .link = aufs_link,
22134 + .unlink = aufs_unlink,
22135 + .symlink = aufs_symlink,
22136 + .mkdir = aufs_mkdir,
22137 + .rmdir = aufs_rmdir,
22138 + .mknod = aufs_mknod,
22139 + .rename = aufs_rename,
22141 + .permission = aufs_permission,
22142 +#ifdef CONFIG_FS_POSIX_ACL
22143 + .get_acl = aufs_get_acl,
22144 + .set_acl = aufs_set_acl,
22147 + .setattr = aufs_setattr,
22148 + .getattr = aufs_getattr,
22150 +#ifdef CONFIG_AUFS_XATTR
22151 + .listxattr = aufs_listxattr,
22154 + .update_time = aufs_update_time,
22155 + .atomic_open = aufs_atomic_open,
22156 + .tmpfile = aufs_tmpfile
22158 + [AuIop_OTHER] = {
22159 + .permission = aufs_permission,
22160 +#ifdef CONFIG_FS_POSIX_ACL
22161 + .get_acl = aufs_get_acl,
22162 + .set_acl = aufs_set_acl,
22165 + .setattr = aufs_setattr,
22166 + .getattr = aufs_getattr,
22168 +#ifdef CONFIG_AUFS_XATTR
22169 + .listxattr = aufs_listxattr,
22172 + .update_time = aufs_update_time
22175 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
22176 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
22177 +++ linux/fs/aufs/i_op_del.c 2018-12-27 13:19:17.711749485 +0100
22179 +// SPDX-License-Identifier: GPL-2.0
22181 + * Copyright (C) 2005-2018 Junjiro R. Okajima
22183 + * This program, aufs is free software; you can redistribute it and/or modify
22184 + * it under the terms of the GNU General Public License as published by
22185 + * the Free Software Foundation; either version 2 of the License, or
22186 + * (at your option) any later version.
22188 + * This program is distributed in the hope that it will be useful,
22189 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22190 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22191 + * GNU General Public License for more details.
22193 + * You should have received a copy of the GNU General Public License
22194 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22198 + * inode operations (del entry)
22204 + * decide if a new whiteout for @dentry is necessary or not.
22205 + * when it is necessary, prepare the parent dir for the upper branch whose
22206 + * branch index is @bcpup for creation. the actual creation of the whiteout will
22207 + * be done by caller.
22209 + * 0: wh is unnecessary
22210 + * plus: wh is necessary
22213 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
22215 + int need_wh, err;
22216 + aufs_bindex_t btop;
22217 + struct super_block *sb;
22219 + sb = dentry->d_sb;
22220 + btop = au_dbtop(dentry);
22221 + if (*bcpup < 0) {
22223 + if (au_test_ro(sb, btop, d_inode(dentry))) {
22224 + err = AuWbrCopyup(au_sbi(sb), dentry);
22226 + if (unlikely(err < 0))
22230 + AuDebugOn(btop < *bcpup
22231 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22232 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22234 + if (*bcpup != btop) {
22235 + err = au_cpup_dirs(dentry, *bcpup);
22236 + if (unlikely(err))
22240 + struct au_dinfo *dinfo, *tmp;
22242 + need_wh = -ENOMEM;
22243 + dinfo = au_di(dentry);
22244 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22246 + au_di_cp(tmp, dinfo);
22247 + au_di_swap(tmp, dinfo);
22248 + /* returns the number of positive dentries */
22249 + need_wh = au_lkup_dentry(dentry, btop + 1,
22250 + /* AuLkup_IGNORE_PERM */ 0);
22251 + au_di_swap(tmp, dinfo);
22252 + au_rw_write_unlock(&tmp->di_rwsem);
22256 + AuDbg("need_wh %d\n", need_wh);
22264 + * simple tests for the del-entry operations.
22265 + * following the checks in vfs, plus the parent-child relationship.
22267 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22268 + struct dentry *h_parent, int isdir)
22272 + struct dentry *h_dentry, *h_latest;
22273 + struct inode *h_inode;
22275 + h_dentry = au_h_dptr(dentry, bindex);
22276 + if (d_really_is_positive(dentry)) {
22278 + if (unlikely(d_is_negative(h_dentry)))
22280 + h_inode = d_inode(h_dentry);
22281 + if (unlikely(!h_inode->i_nlink))
22284 + h_mode = h_inode->i_mode;
22287 + if (unlikely(S_ISDIR(h_mode)))
22289 + } else if (unlikely(!S_ISDIR(h_mode))) {
22294 + /* rename(2) case */
22296 + if (unlikely(d_is_positive(h_dentry)))
22301 + /* expected parent dir is locked */
22302 + if (unlikely(h_parent != h_dentry->d_parent))
22307 + * rmdir a dir may break the consistency on some filesystem.
22308 + * let's try heavy test.
22311 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22312 + && au_test_h_perm(d_inode(h_parent),
22313 + MAY_EXEC | MAY_WRITE)))
22316 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
22318 + if (IS_ERR(h_latest))
22320 + if (h_latest == h_dentry)
22329 + * decide the branch where we operate for @dentry. the branch index will be set
22330 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22331 + * dir for reverting.
22332 + * when a new whiteout is necessary, create it.
22334 +static struct dentry*
22335 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22336 + struct au_dtime *dt, struct au_pin *pin)
22338 + struct dentry *wh_dentry;
22339 + struct super_block *sb;
22340 + struct path h_path;
22341 + int err, need_wh;
22342 + unsigned int udba;
22343 + aufs_bindex_t bcpup;
22345 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22346 + wh_dentry = ERR_PTR(need_wh);
22347 + if (unlikely(need_wh < 0))
22350 + sb = dentry->d_sb;
22351 + udba = au_opt_udba(sb);
22353 + err = au_pin(pin, dentry, bcpup, udba,
22354 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22355 + wh_dentry = ERR_PTR(err);
22356 + if (unlikely(err))
22359 + h_path.dentry = au_pinned_h_parent(pin);
22360 + if (udba != AuOpt_UDBA_NONE
22361 + && au_dbtop(dentry) == bcpup) {
22362 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22363 + wh_dentry = ERR_PTR(err);
22364 + if (unlikely(err))
22368 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22369 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22370 + wh_dentry = NULL;
22372 + goto out; /* success, no need to create whiteout */
22374 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22375 + if (IS_ERR(wh_dentry))
22378 + /* returns with the parent is locked and wh_dentry is dget-ed */
22379 + goto out; /* success */
22384 + return wh_dentry;
22388 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22389 + * in order to be revertible and save time for removing many child whiteouts
22391 + * returns 1 when there are too many child whiteout and caller should remove
22392 + * them asynchronously. returns 0 when the number of children is enough small to
22393 + * remove now or the branch fs is a remote fs.
22394 + * otherwise return an error.
22396 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22397 + struct au_nhash *whlist, struct inode *dir)
22399 + int rmdir_later, err, dirwh;
22400 + struct dentry *h_dentry;
22401 + struct super_block *sb;
22402 + struct inode *inode;
22404 + sb = dentry->d_sb;
22405 + SiMustAnyLock(sb);
22406 + h_dentry = au_h_dptr(dentry, bindex);
22407 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22408 + if (unlikely(err))
22411 + /* stop monitoring */
22412 + inode = d_inode(dentry);
22413 + au_hn_free(au_hi(inode, bindex));
22415 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22416 + dirwh = au_sbi(sb)->si_dirwh;
22417 + rmdir_later = (dirwh <= 1);
22418 + if (!rmdir_later)
22419 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22422 + return rmdir_later;
22425 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22426 + if (unlikely(err)) {
22427 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22428 + h_dentry, bindex, err);
22438 + * final procedure for deleting a entry.
22439 + * maintain dentry and iattr.
22441 +static void epilog(struct inode *dir, struct dentry *dentry,
22442 + aufs_bindex_t bindex)
22444 + struct inode *inode;
22446 + inode = d_inode(dentry);
22448 + inode->i_ctime = dir->i_ctime;
22450 + au_dir_ts(dir, bindex);
22451 + inode_inc_iversion(dir);
22455 + * when an error happened, remove the created whiteout and revert everything.
22457 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22458 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22459 + struct dentry *dentry, struct au_dtime *dt)
22462 + struct path h_path = {
22463 + .dentry = wh_dentry,
22464 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22467 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22469 + au_set_dbwh(dentry, bwh);
22470 + au_dtime_revert(dt);
22474 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22478 +/* ---------------------------------------------------------------------- */
22480 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22483 + aufs_bindex_t bwh, bindex, btop;
22484 + struct inode *inode, *h_dir, *delegated;
22485 + struct dentry *parent, *wh_dentry;
22486 + /* to reduce stack size */
22488 + struct au_dtime dt;
22489 + struct au_pin pin;
22490 + struct path h_path;
22496 + a = kmalloc(sizeof(*a), GFP_NOFS);
22497 + if (unlikely(!a))
22500 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22501 + if (unlikely(err))
22503 + err = au_d_hashed_positive(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? */
22512 + btop = au_dbtop(dentry);
22513 + bwh = au_dbwh(dentry);
22515 + parent = dentry->d_parent; /* dir inode is locked */
22516 + di_write_lock_parent(parent);
22517 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22519 + err = PTR_ERR(wh_dentry);
22520 + if (IS_ERR(wh_dentry))
22523 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22524 + a->h_path.dentry = au_h_dptr(dentry, btop);
22525 + dget(a->h_path.dentry);
22526 + if (bindex == btop) {
22527 + h_dir = au_pinned_h_dir(&a->pin);
22528 + delegated = NULL;
22529 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22530 + if (unlikely(err == -EWOULDBLOCK)) {
22531 + pr_warn("cannot retry for NFSv4 delegation"
22532 + " for an internal unlink\n");
22536 + /* dir inode is locked */
22537 + h_dir = d_inode(wh_dentry->d_parent);
22538 + IMustLock(h_dir);
22543 + vfsub_drop_nlink(inode);
22544 + epilog(dir, dentry, bindex);
22546 + /* update target timestamps */
22547 + if (bindex == btop) {
22548 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22550 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22552 + /* todo: this timestamp may be reverted later */
22553 + inode->i_ctime = h_dir->i_ctime;
22554 + goto out_unpin; /* success */
22561 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22568 + au_unpin(&a->pin);
22570 + dput(a->h_path.dentry);
22572 + di_write_unlock(parent);
22574 + aufs_read_unlock(dentry, AuLock_DW);
22581 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22583 + int err, rmdir_later;
22584 + aufs_bindex_t bwh, bindex, btop;
22585 + struct inode *inode;
22586 + struct dentry *parent, *wh_dentry, *h_dentry;
22587 + struct au_whtmp_rmdir *args;
22588 + /* to reduce stack size */
22590 + struct au_dtime dt;
22591 + struct au_pin pin;
22597 + a = kmalloc(sizeof(*a), GFP_NOFS);
22598 + if (unlikely(!a))
22601 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22602 + if (unlikely(err))
22604 + err = au_alive_dir(dentry);
22605 + if (unlikely(err))
22607 + inode = d_inode(dentry);
22608 + IMustLock(inode);
22610 + if (unlikely(!d_is_dir(dentry)))
22611 + goto out_unlock; /* possible? */
22614 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22615 + if (unlikely(!args))
22618 + parent = dentry->d_parent; /* dir inode is locked */
22619 + di_write_lock_parent(parent);
22620 + err = au_test_empty(dentry, &args->whlist);
22621 + if (unlikely(err))
22624 + btop = au_dbtop(dentry);
22625 + bwh = au_dbwh(dentry);
22627 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22629 + err = PTR_ERR(wh_dentry);
22630 + if (IS_ERR(wh_dentry))
22633 + h_dentry = au_h_dptr(dentry, btop);
22636 + if (bindex == btop) {
22637 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22639 + rmdir_later = err;
22643 + /* stop monitoring */
22644 + au_hn_free(au_hi(inode, btop));
22646 + /* dir inode is locked */
22647 + IMustLock(d_inode(wh_dentry->d_parent));
22652 + vfsub_dead_dir(inode);
22653 + au_set_dbdiropq(dentry, -1);
22654 + epilog(dir, dentry, bindex);
22656 + if (rmdir_later) {
22657 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22661 + goto out_unpin; /* success */
22669 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22676 + au_unpin(&a->pin);
22680 + di_write_unlock(parent);
22682 + au_whtmp_rmdir_free(args);
22684 + aufs_read_unlock(dentry, AuLock_DW);
22691 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22692 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22693 +++ linux/fs/aufs/i_op_ren.c 2018-12-27 13:19:17.711749485 +0100
22695 +// SPDX-License-Identifier: GPL-2.0
22697 + * Copyright (C) 2005-2018 Junjiro R. Okajima
22699 + * This program, aufs is free software; you can redistribute it and/or modify
22700 + * it under the terms of the GNU General Public License as published by
22701 + * the Free Software Foundation; either version 2 of the License, or
22702 + * (at your option) any later version.
22704 + * This program is distributed in the hope that it will be useful,
22705 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22706 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22707 + * GNU General Public License for more details.
22709 + * You should have received a copy of the GNU General Public License
22710 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22714 + * inode operation (rename entry)
22715 + * todo: this is crazy monster
22720 +enum { AuSRC, AuDST, AuSrcDst };
22721 +enum { AuPARENT, AuCHILD, AuParentChild };
22723 +#define AuRen_ISDIR_SRC 1
22724 +#define AuRen_ISDIR_DST (1 << 1)
22725 +#define AuRen_ISSAMEDIR (1 << 2)
22726 +#define AuRen_WHSRC (1 << 3)
22727 +#define AuRen_WHDST (1 << 4)
22728 +#define AuRen_MNT_WRITE (1 << 5)
22729 +#define AuRen_DT_DSTDIR (1 << 6)
22730 +#define AuRen_DIROPQ_SRC (1 << 7)
22731 +#define AuRen_DIROPQ_DST (1 << 8)
22732 +#define AuRen_DIRREN (1 << 9)
22733 +#define AuRen_DROPPED_SRC (1 << 10)
22734 +#define AuRen_DROPPED_DST (1 << 11)
22735 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22736 +#define au_fset_ren(flags, name) \
22737 + do { (flags) |= AuRen_##name; } while (0)
22738 +#define au_fclr_ren(flags, name) \
22739 + do { (flags) &= ~AuRen_##name; } while (0)
22741 +#ifndef CONFIG_AUFS_DIRREN
22742 +#undef AuRen_DIRREN
22743 +#define AuRen_DIRREN 0
22746 +struct au_ren_args {
22748 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22750 + struct inode *dir, *inode;
22751 + struct au_hinode *hdir, *hinode;
22752 + struct au_dtime dt[AuParentChild];
22753 + aufs_bindex_t btop, bdiropq;
22756 +#define src_dentry sd[AuSRC].dentry
22757 +#define src_dir sd[AuSRC].dir
22758 +#define src_inode sd[AuSRC].inode
22759 +#define src_h_dentry sd[AuSRC].h_dentry
22760 +#define src_parent sd[AuSRC].parent
22761 +#define src_h_parent sd[AuSRC].h_parent
22762 +#define src_wh_dentry sd[AuSRC].wh_dentry
22763 +#define src_hdir sd[AuSRC].hdir
22764 +#define src_hinode sd[AuSRC].hinode
22765 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22766 +#define src_dt sd[AuSRC].dt
22767 +#define src_btop sd[AuSRC].btop
22768 +#define src_bdiropq sd[AuSRC].bdiropq
22770 +#define dst_dentry sd[AuDST].dentry
22771 +#define dst_dir sd[AuDST].dir
22772 +#define dst_inode sd[AuDST].inode
22773 +#define dst_h_dentry sd[AuDST].h_dentry
22774 +#define dst_parent sd[AuDST].parent
22775 +#define dst_h_parent sd[AuDST].h_parent
22776 +#define dst_wh_dentry sd[AuDST].wh_dentry
22777 +#define dst_hdir sd[AuDST].hdir
22778 +#define dst_hinode sd[AuDST].hinode
22779 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22780 +#define dst_dt sd[AuDST].dt
22781 +#define dst_btop sd[AuDST].btop
22782 +#define dst_bdiropq sd[AuDST].bdiropq
22784 + struct dentry *h_trap;
22785 + struct au_branch *br;
22786 + struct path h_path;
22787 + struct au_nhash whlist;
22788 + aufs_bindex_t btgt, src_bwh;
22791 + unsigned short auren_flags;
22792 + unsigned char flags; /* syscall parameter */
22793 + unsigned char exchange;
22796 + struct au_whtmp_rmdir *thargs;
22797 + struct dentry *h_dst;
22798 + struct au_hinode *h_root;
22801 +/* ---------------------------------------------------------------------- */
22804 + * functions for reverting.
22805 + * when an error happened in a single rename systemcall, we should revert
22806 + * everything as if nothing happened.
22807 + * we don't need to revert the copied-up/down the parent dir since they are
22811 +#define RevertFailure(fmt, ...) do { \
22812 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22813 + ##__VA_ARGS__, err, rerr); \
22817 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22820 + struct dentry *d;
22821 +#define src_or_dst(member) a->sd[idx].member
22823 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22824 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22825 + rerr = au_diropq_remove(d, a->btgt);
22826 + au_hn_inode_unlock(src_or_dst(hinode));
22827 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22829 + RevertFailure("remove diropq %pd", d);
22831 +#undef src_or_dst_
22834 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22836 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22837 + au_ren_do_rev_diropq(err, a, AuSRC);
22838 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22839 + au_ren_do_rev_diropq(err, a, AuDST);
22842 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22845 + struct inode *delegated;
22847 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22848 + a->src_h_parent);
22849 + rerr = PTR_ERR(a->h_path.dentry);
22850 + if (IS_ERR(a->h_path.dentry)) {
22851 + RevertFailure("lkup one %pd", a->src_dentry);
22855 + delegated = NULL;
22856 + rerr = vfsub_rename(a->dst_h_dir,
22857 + au_h_dptr(a->src_dentry, a->btgt),
22858 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22859 + if (unlikely(rerr == -EWOULDBLOCK)) {
22860 + pr_warn("cannot retry for NFSv4 delegation"
22861 + " for an internal rename\n");
22864 + d_drop(a->h_path.dentry);
22865 + dput(a->h_path.dentry);
22866 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22868 + RevertFailure("rename %pd", a->src_dentry);
22871 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22874 + struct inode *delegated;
22876 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22877 + a->dst_h_parent);
22878 + rerr = PTR_ERR(a->h_path.dentry);
22879 + if (IS_ERR(a->h_path.dentry)) {
22880 + RevertFailure("lkup one %pd", a->dst_dentry);
22883 + if (d_is_positive(a->h_path.dentry)) {
22884 + d_drop(a->h_path.dentry);
22885 + dput(a->h_path.dentry);
22889 + delegated = NULL;
22890 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22891 + &delegated, a->flags);
22892 + if (unlikely(rerr == -EWOULDBLOCK)) {
22893 + pr_warn("cannot retry for NFSv4 delegation"
22894 + " for an internal rename\n");
22897 + d_drop(a->h_path.dentry);
22898 + dput(a->h_path.dentry);
22900 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22902 + RevertFailure("rename %pd", a->h_dst);
22905 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22909 + a->h_path.dentry = a->src_wh_dentry;
22910 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22911 + au_set_dbwh(a->src_dentry, a->src_bwh);
22913 + RevertFailure("unlink %pd", a->src_wh_dentry);
22915 +#undef RevertFailure
22917 +/* ---------------------------------------------------------------------- */
22920 + * when we have to copyup the renaming entry, do it with the rename-target name
22921 + * in order to minimize the cost (the later actual rename is unnecessary).
22922 + * otherwise rename it on the target branch.
22924 +static int au_ren_or_cpup(struct au_ren_args *a)
22927 + struct dentry *d;
22928 + struct inode *delegated;
22930 + d = a->src_dentry;
22931 + if (au_dbtop(d) == a->btgt) {
22932 + a->h_path.dentry = a->dst_h_dentry;
22933 + AuDebugOn(au_dbtop(d) != a->btgt);
22934 + delegated = NULL;
22935 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22936 + a->dst_h_dir, &a->h_path, &delegated,
22938 + if (unlikely(err == -EWOULDBLOCK)) {
22939 + pr_warn("cannot retry for NFSv4 delegation"
22940 + " for an internal rename\n");
22946 + if (!err && a->h_dst)
22947 + /* it will be set to dinfo later */
22953 +/* cf. aufs_rmdir() */
22954 +static int au_ren_del_whtmp(struct au_ren_args *a)
22957 + struct inode *dir;
22959 + dir = a->dst_dir;
22960 + SiMustAnyLock(dir->i_sb);
22961 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22962 + au_sbi(dir->i_sb)->si_dirwh)
22963 + || au_test_fs_remote(a->h_dst->d_sb)) {
22964 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22965 + if (unlikely(err))
22966 + pr_warn("failed removing whtmp dir %pd (%d), "
22967 + "ignored.\n", a->h_dst, err);
22969 + au_nhash_wh_free(&a->thargs->whlist);
22970 + a->thargs->whlist = a->whlist;
22971 + a->whlist.nh_num = 0;
22972 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22974 + a->thargs = NULL;
22980 +/* make it 'opaque' dir. */
22981 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22984 + struct dentry *d, *diropq;
22985 +#define src_or_dst(member) a->sd[idx].member
22988 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22989 + src_or_dst(bdiropq) = au_dbdiropq(d);
22990 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22991 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22992 + diropq = au_diropq_create(d, a->btgt);
22993 + au_hn_inode_unlock(src_or_dst(hinode));
22994 + if (IS_ERR(diropq))
22995 + err = PTR_ERR(diropq);
22999 +#undef src_or_dst_
23003 +static int au_ren_diropq(struct au_ren_args *a)
23006 + unsigned char always;
23007 + struct dentry *d;
23010 + d = a->dst_dentry; /* already renamed on the branch */
23011 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
23012 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23013 + && !au_ftest_ren(a->auren_flags, DIRREN)
23014 + && a->btgt != au_dbdiropq(a->src_dentry)
23015 + && (a->dst_wh_dentry
23016 + || a->btgt <= au_dbdiropq(d)
23017 + /* hide the lower to keep xino */
23018 + /* the lowers may not be a dir, but we hide them anyway */
23019 + || a->btgt < au_dbbot(d)
23022 + err = au_ren_do_diropq(a, AuSRC);
23023 + if (unlikely(err))
23025 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
23027 + if (!a->exchange)
23028 + goto out; /* success */
23030 + d = a->src_dentry; /* already renamed on the branch */
23031 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
23032 + && a->btgt != au_dbdiropq(a->dst_dentry)
23033 + && (a->btgt < au_dbdiropq(d)
23034 + || a->btgt < au_dbbot(d)
23036 + AuDbgDentry(a->src_dentry);
23037 + AuDbgDentry(a->dst_dentry);
23038 + err = au_ren_do_diropq(a, AuDST);
23039 + if (unlikely(err))
23040 + goto out_rev_src;
23041 + au_fset_ren(a->auren_flags, DIROPQ_DST);
23043 + goto out; /* success */
23046 + AuDbg("err %d, reverting src\n", err);
23047 + au_ren_rev_diropq(err, a);
23052 +static int do_rename(struct au_ren_args *a)
23055 + struct dentry *d, *h_d;
23057 + if (!a->exchange) {
23058 + /* prepare workqueue args for asynchronous rmdir */
23059 + h_d = a->dst_h_dentry;
23060 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
23061 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
23062 + && d_is_positive(h_d)) {
23064 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
23066 + if (unlikely(!a->thargs))
23068 + a->h_dst = dget(h_d);
23071 + /* create whiteout for src_dentry */
23072 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
23073 + a->src_bwh = au_dbwh(a->src_dentry);
23074 + AuDebugOn(a->src_bwh >= 0);
23075 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
23076 + a->src_h_parent);
23077 + err = PTR_ERR(a->src_wh_dentry);
23078 + if (IS_ERR(a->src_wh_dentry))
23082 + /* lookup whiteout for dentry */
23083 + if (au_ftest_ren(a->auren_flags, WHDST)) {
23084 + h_d = au_wh_lkup(a->dst_h_parent,
23085 + &a->dst_dentry->d_name, a->br);
23086 + err = PTR_ERR(h_d);
23089 + if (d_is_negative(h_d))
23092 + a->dst_wh_dentry = h_d;
23095 + /* rename dentry to tmpwh */
23097 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
23098 + if (unlikely(err))
23101 + d = a->dst_dentry;
23102 + au_set_h_dptr(d, a->btgt, NULL);
23103 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
23104 + if (unlikely(err))
23106 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
23110 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
23112 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
23113 + && d_is_positive(a->dst_h_dentry)
23114 + && a->src_btop != a->btgt);
23117 + /* rename by vfs_rename or cpup */
23118 + err = au_ren_or_cpup(a);
23119 + if (unlikely(err))
23120 + /* leave the copied-up one */
23123 + /* make dir opaque */
23124 + err = au_ren_diropq(a);
23125 + if (unlikely(err))
23128 + /* update target timestamps */
23129 + if (a->exchange) {
23130 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
23131 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
23132 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23133 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23135 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
23136 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
23137 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23138 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23140 + if (!a->exchange) {
23141 + /* remove whiteout for dentry */
23142 + if (a->dst_wh_dentry) {
23143 + a->h_path.dentry = a->dst_wh_dentry;
23144 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
23146 + if (unlikely(err))
23150 + /* remove whtmp */
23152 + au_ren_del_whtmp(a); /* ignore this error */
23154 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
23157 + goto out_success;
23160 + au_ren_rev_diropq(err, a);
23162 + au_ren_rev_rename(err, a);
23166 + au_ren_rev_whtmp(err, a);
23168 + dput(a->dst_wh_dentry);
23169 + a->dst_wh_dentry = NULL;
23171 + if (a->src_wh_dentry)
23172 + au_ren_rev_whsrc(err, a);
23174 + dput(a->src_wh_dentry);
23175 + dput(a->dst_wh_dentry);
23179 + au_whtmp_rmdir_free(a->thargs);
23180 + a->thargs = NULL;
23186 +/* ---------------------------------------------------------------------- */
23189 + * test if @dentry dir can be rename destination or not.
23190 + * success means, it is a logically empty dir.
23192 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
23194 + return au_test_empty(dentry, whlist);
23198 + * test if @a->src_dentry dir can be rename source or not.
23199 + * if it can, return 0.
23201 + * - it is a logically empty dir.
23202 + * - or, it exists on writable branch and has no children including whiteouts
23203 + * on the lower branch unless DIRREN is on.
23205 +static int may_rename_srcdir(struct au_ren_args *a)
23208 + unsigned int rdhash;
23209 + aufs_bindex_t btop, btgt;
23210 + struct dentry *dentry;
23211 + struct super_block *sb;
23212 + struct au_sbinfo *sbinfo;
23214 + dentry = a->src_dentry;
23215 + sb = dentry->d_sb;
23216 + sbinfo = au_sbi(sb);
23217 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
23218 + au_fset_ren(a->auren_flags, DIRREN);
23221 + btop = au_dbtop(dentry);
23222 + if (btop != btgt) {
23223 + struct au_nhash whlist;
23225 + SiMustAnyLock(sb);
23226 + rdhash = sbinfo->si_rdhash;
23228 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23230 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23231 + if (unlikely(err))
23233 + err = au_test_empty(dentry, &whlist);
23234 + au_nhash_wh_free(&whlist);
23238 + if (btop == au_dbtaildir(dentry))
23239 + return 0; /* success */
23241 + err = au_test_empty_lower(dentry);
23244 + if (err == -ENOTEMPTY) {
23245 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23248 + AuWarn1("renaming dir who has child(ren) on multiple "
23249 + "branches, is not supported\n");
23256 +/* side effect: sets whlist and h_dentry */
23257 +static int au_ren_may_dir(struct au_ren_args *a)
23260 + unsigned int rdhash;
23261 + struct dentry *d;
23263 + d = a->dst_dentry;
23264 + SiMustAnyLock(d->d_sb);
23267 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23268 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23270 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23271 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23272 + if (unlikely(err))
23275 + if (!a->exchange) {
23276 + au_set_dbtop(d, a->dst_btop);
23277 + err = may_rename_dstdir(d, &a->whlist);
23278 + au_set_dbtop(d, a->btgt);
23280 + err = may_rename_srcdir(a);
23282 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23283 + if (unlikely(err))
23286 + d = a->src_dentry;
23287 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23288 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23289 + err = may_rename_srcdir(a);
23290 + if (unlikely(err)) {
23291 + au_nhash_wh_free(&a->whlist);
23292 + a->whlist.nh_num = 0;
23299 +/* ---------------------------------------------------------------------- */
23302 + * simple tests for rename.
23303 + * following the checks in vfs, plus the parent-child relationship.
23305 +static int au_may_ren(struct au_ren_args *a)
23308 + struct inode *h_inode;
23310 + if (a->src_btop == a->btgt) {
23311 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23312 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23313 + if (unlikely(err))
23316 + if (unlikely(a->src_h_dentry == a->h_trap))
23321 + if (a->dst_btop != a->btgt)
23324 + err = -ENOTEMPTY;
23325 + if (unlikely(a->dst_h_dentry == a->h_trap))
23329 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23330 + if (d_really_is_negative(a->dst_dentry)) {
23331 + if (d_is_negative(a->dst_h_dentry))
23332 + err = au_may_add(a->dst_dentry, a->btgt,
23333 + a->dst_h_parent, isdir);
23335 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23337 + h_inode = d_inode(a->dst_h_dentry);
23338 + if (h_inode->i_nlink)
23339 + err = au_may_del(a->dst_dentry, a->btgt,
23340 + a->dst_h_parent, isdir);
23344 + if (unlikely(err == -ENOENT || err == -EEXIST))
23350 +/* ---------------------------------------------------------------------- */
23355 + * - src_dir and dir by lock_rename()
23356 + * - inode if exists
23359 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23361 + * + di_write_lock2_child()
23362 + * + di_write_lock_child()
23363 + * + ii_write_lock_child()
23364 + * + di_write_lock_child2()
23365 + * + ii_write_lock_child2()
23366 + * + src_parent and parent
23367 + * + di_write_lock_parent()
23368 + * + ii_write_lock_parent()
23369 + * + di_write_lock_parent2()
23370 + * + ii_write_lock_parent2()
23371 + * + lower src_dir and dir by vfsub_lock_rename()
23372 + * + verify the every relationships between child and parent. if any
23373 + * of them failed, unlock all and return -EBUSY.
23375 +static void au_ren_unlock(struct au_ren_args *a)
23377 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23378 + a->dst_h_parent, a->dst_hdir);
23379 + if (au_ftest_ren(a->auren_flags, DIRREN)
23381 + au_hn_inode_unlock(a->h_root);
23382 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23383 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23386 +static int au_ren_lock(struct au_ren_args *a)
23389 + unsigned int udba;
23392 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23393 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23394 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23395 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23397 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23398 + if (unlikely(err))
23400 + au_fset_ren(a->auren_flags, MNT_WRITE);
23401 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23402 + struct dentry *root;
23403 + struct inode *dir;
23406 + * sbinfo is already locked, so this ii_read_lock is
23407 + * unnecessary. but our debugging feature checks it.
23409 + root = a->src_inode->i_sb->s_root;
23410 + if (root != a->src_parent && root != a->dst_parent) {
23411 + dir = d_inode(root);
23412 + ii_read_lock_parent3(dir);
23413 + a->h_root = au_hi(dir, a->btgt);
23414 + ii_read_unlock(dir);
23415 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23418 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23419 + a->dst_h_parent, a->dst_hdir);
23420 + udba = au_opt_udba(a->src_dentry->d_sb);
23421 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23422 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23423 + err = au_busy_or_stale();
23424 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23425 + err = au_h_verify(a->src_h_dentry, udba,
23426 + d_inode(a->src_h_parent), a->src_h_parent,
23428 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23429 + err = au_h_verify(a->dst_h_dentry, udba,
23430 + d_inode(a->dst_h_parent), a->dst_h_parent,
23433 + goto out; /* success */
23435 + err = au_busy_or_stale();
23436 + au_ren_unlock(a);
23442 +/* ---------------------------------------------------------------------- */
23444 +static void au_ren_refresh_dir(struct au_ren_args *a)
23446 + struct inode *dir;
23448 + dir = a->dst_dir;
23449 + inode_inc_iversion(dir);
23450 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23451 + /* is this updating defined in POSIX? */
23452 + au_cpup_attr_timesizes(a->src_inode);
23453 + au_cpup_attr_nlink(dir, /*force*/1);
23455 + au_dir_ts(dir, a->btgt);
23457 + if (a->exchange) {
23458 + dir = a->src_dir;
23459 + inode_inc_iversion(dir);
23460 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23461 + /* is this updating defined in POSIX? */
23462 + au_cpup_attr_timesizes(a->dst_inode);
23463 + au_cpup_attr_nlink(dir, /*force*/1);
23465 + au_dir_ts(dir, a->btgt);
23468 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23471 + dir = a->src_dir;
23472 + inode_inc_iversion(dir);
23473 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23474 + au_cpup_attr_nlink(dir, /*force*/1);
23475 + au_dir_ts(dir, a->btgt);
23478 +static void au_ren_refresh(struct au_ren_args *a)
23480 + aufs_bindex_t bbot, bindex;
23481 + struct dentry *d, *h_d;
23482 + struct inode *i, *h_i;
23483 + struct super_block *sb;
23485 + d = a->dst_dentry;
23488 + /* already dget-ed by au_ren_or_cpup() */
23489 + au_set_h_dptr(d, a->btgt, a->h_dst);
23491 + i = a->dst_inode;
23493 + if (!a->exchange) {
23494 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23495 + vfsub_drop_nlink(i);
23497 + vfsub_dead_dir(i);
23498 + au_cpup_attr_timesizes(i);
23500 + au_update_dbrange(d, /*do_put_zero*/1);
23502 + au_cpup_attr_nlink(i, /*force*/1);
23505 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23506 + au_set_h_dptr(d, bindex, NULL);
23507 + bbot = au_dbbot(d);
23508 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23509 + au_set_h_dptr(d, bindex, NULL);
23510 + au_update_dbrange(d, /*do_put_zero*/0);
23514 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23515 + d_drop(a->src_dentry);
23516 + if (au_ftest_ren(a->auren_flags, DIRREN))
23517 + au_set_dbwh(a->src_dentry, -1);
23521 + d = a->src_dentry;
23522 + au_set_dbwh(d, -1);
23523 + bbot = au_dbbot(d);
23524 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23525 + h_d = au_h_dptr(d, bindex);
23527 + au_set_h_dptr(d, bindex, NULL);
23529 + au_set_dbbot(d, a->btgt);
23532 + i = a->src_inode;
23533 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23534 + return; /* success */
23536 + bbot = au_ibbot(i);
23537 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23538 + h_i = au_h_iptr(i, bindex);
23540 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23541 + /* ignore this error */
23542 + au_set_h_iptr(i, bindex, NULL, 0);
23545 + au_set_ibbot(i, a->btgt);
23548 +/* ---------------------------------------------------------------------- */
23550 +/* mainly for link(2) and rename(2) */
23551 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23553 + aufs_bindex_t bdiropq, bwh;
23554 + struct dentry *parent;
23555 + struct au_branch *br;
23557 + parent = dentry->d_parent;
23558 + IMustLock(d_inode(parent)); /* dir is locked */
23560 + bdiropq = au_dbdiropq(parent);
23561 + bwh = au_dbwh(dentry);
23562 + br = au_sbr(dentry->d_sb, btgt);
23563 + if (au_br_rdonly(br)
23564 + || (0 <= bdiropq && bdiropq < btgt)
23565 + || (0 <= bwh && bwh < btgt))
23568 + AuDbg("btgt %d\n", btgt);
23572 +/* sets src_btop, dst_btop and btgt */
23573 +static int au_ren_wbr(struct au_ren_args *a)
23576 + struct au_wr_dir_args wr_dir_args = {
23577 + /* .force_btgt = -1, */
23578 + .flags = AuWrDir_ADD_ENTRY
23581 + a->src_btop = au_dbtop(a->src_dentry);
23582 + a->dst_btop = au_dbtop(a->dst_dentry);
23583 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23584 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23585 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23586 + wr_dir_args.force_btgt = a->src_btop;
23587 + if (a->dst_inode && a->dst_btop < a->src_btop)
23588 + wr_dir_args.force_btgt = a->dst_btop;
23589 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23590 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23593 + au_update_dbtop(a->dst_dentry);
23598 +static void au_ren_dt(struct au_ren_args *a)
23600 + a->h_path.dentry = a->src_h_parent;
23601 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23602 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23603 + a->h_path.dentry = a->dst_h_parent;
23604 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23607 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23608 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23612 + a->h_path.dentry = a->src_h_dentry;
23613 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23614 + if (d_is_positive(a->dst_h_dentry)) {
23615 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23616 + a->h_path.dentry = a->dst_h_dentry;
23617 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23621 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23623 + struct dentry *h_d;
23624 + struct inode *h_inode;
23626 + au_dtime_revert(a->src_dt + AuPARENT);
23627 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23628 + au_dtime_revert(a->dst_dt + AuPARENT);
23630 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23631 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23632 + h_inode = d_inode(h_d);
23633 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23634 + au_dtime_revert(a->src_dt + AuCHILD);
23635 + inode_unlock(h_inode);
23637 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23638 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23639 + h_inode = d_inode(h_d);
23640 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23641 + au_dtime_revert(a->dst_dt + AuCHILD);
23642 + inode_unlock(h_inode);
23647 +/* ---------------------------------------------------------------------- */
23649 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23650 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23651 + unsigned int _flags)
23653 + int err, lock_flags;
23655 + /* reduce stack space */
23656 + struct au_ren_args *a;
23657 + struct au_pin pin;
23659 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23660 + IMustLock(_src_dir);
23661 + IMustLock(_dst_dir);
23664 + if (unlikely(_flags & RENAME_WHITEOUT))
23668 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23669 + a = kzalloc(sizeof(*a), GFP_NOFS);
23670 + if (unlikely(!a))
23673 + a->flags = _flags;
23674 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23675 + && RENAME_EXCHANGE > U8_MAX);
23676 + a->exchange = _flags & RENAME_EXCHANGE;
23677 + a->src_dir = _src_dir;
23678 + a->src_dentry = _src_dentry;
23679 + a->src_inode = NULL;
23680 + if (d_really_is_positive(a->src_dentry))
23681 + a->src_inode = d_inode(a->src_dentry);
23682 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23683 + a->dst_dir = _dst_dir;
23684 + a->dst_dentry = _dst_dentry;
23685 + a->dst_inode = NULL;
23686 + if (d_really_is_positive(a->dst_dentry))
23687 + a->dst_inode = d_inode(a->dst_dentry);
23688 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23689 + if (a->dst_inode) {
23691 + * if EXCHANGE && src is non-dir && dst is dir,
23692 + * dst is not locked.
23694 + /* IMustLock(a->dst_inode); */
23695 + au_igrab(a->dst_inode);
23699 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23700 + if (d_is_dir(a->src_dentry)) {
23701 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23702 + if (unlikely(!a->exchange
23703 + && d_really_is_positive(a->dst_dentry)
23704 + && !d_is_dir(a->dst_dentry)))
23706 + lock_flags |= AuLock_DIRS;
23708 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23709 + au_fset_ren(a->auren_flags, ISDIR_DST);
23710 + if (unlikely(!a->exchange
23711 + && d_really_is_positive(a->src_dentry)
23712 + && !d_is_dir(a->src_dentry)))
23714 + lock_flags |= AuLock_DIRS;
23716 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23718 + if (unlikely(err))
23721 + err = au_d_hashed_positive(a->src_dentry);
23722 + if (unlikely(err))
23725 + if (a->dst_inode) {
23727 + * If it is a dir, VFS unhash it before this
23728 + * function. It means we cannot rely upon d_unhashed().
23730 + if (unlikely(!a->dst_inode->i_nlink))
23732 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23733 + err = au_d_hashed_positive(a->dst_dentry);
23734 + if (unlikely(err && !a->exchange))
23736 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23738 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23742 + * is it possible?
23743 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23744 + * there may exist a problem somewhere else.
23747 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23750 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23751 + di_write_lock_parent(a->dst_parent);
23753 + /* which branch we process */
23754 + err = au_ren_wbr(a);
23755 + if (unlikely(err < 0))
23757 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23758 + a->h_path.mnt = au_br_mnt(a->br);
23760 + /* are they available to be renamed */
23761 + err = au_ren_may_dir(a);
23762 + if (unlikely(err))
23763 + goto out_children;
23765 + /* prepare the writable parent dir on the same branch */
23766 + if (a->dst_btop == a->btgt) {
23767 + au_fset_ren(a->auren_flags, WHDST);
23769 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23770 + if (unlikely(err))
23771 + goto out_children;
23775 + if (!a->exchange) {
23776 + if (a->src_dir != a->dst_dir) {
23778 + * this temporary unlock is safe,
23779 + * because both dir->i_mutex are locked.
23781 + di_write_unlock(a->dst_parent);
23782 + di_write_lock_parent(a->src_parent);
23783 + err = au_wr_dir_need_wh(a->src_dentry,
23784 + au_ftest_ren(a->auren_flags,
23787 + di_write_unlock(a->src_parent);
23788 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23790 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23792 + err = au_wr_dir_need_wh(a->src_dentry,
23793 + au_ftest_ren(a->auren_flags,
23797 + if (unlikely(err < 0))
23798 + goto out_children;
23800 + au_fset_ren(a->auren_flags, WHSRC);
23803 + if (a->src_btop != a->btgt) {
23804 + err = au_pin(&pin, a->src_dentry, a->btgt,
23805 + au_opt_udba(a->src_dentry->d_sb),
23806 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23808 + struct au_cp_generic cpg = {
23809 + .dentry = a->src_dentry,
23811 + .bsrc = a->src_btop,
23814 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23816 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23817 + err = au_sio_cpup_simple(&cpg);
23820 + if (unlikely(err))
23821 + goto out_children;
23822 + a->src_btop = a->btgt;
23823 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23824 + if (!a->exchange)
23825 + au_fset_ren(a->auren_flags, WHSRC);
23829 + if (a->exchange && a->dst_inode
23830 + && a->dst_btop != a->btgt) {
23831 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23832 + au_opt_udba(a->dst_dentry->d_sb),
23833 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23835 + struct au_cp_generic cpg = {
23836 + .dentry = a->dst_dentry,
23838 + .bsrc = a->dst_btop,
23841 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23843 + err = au_sio_cpup_simple(&cpg);
23846 + if (unlikely(err))
23847 + goto out_children;
23848 + a->dst_btop = a->btgt;
23849 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23852 + /* lock them all */
23853 + err = au_ren_lock(a);
23854 + if (unlikely(err))
23855 + /* leave the copied-up one */
23856 + goto out_children;
23858 + if (!a->exchange) {
23859 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23860 + err = au_may_ren(a);
23861 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23862 + err = -ENAMETOOLONG;
23863 + if (unlikely(err))
23867 + /* store timestamps to be revertible */
23870 + /* store dirren info */
23871 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23872 + err = au_dr_rename(a->src_dentry, a->btgt,
23873 + &a->dst_dentry->d_name, &rev);
23875 + if (unlikely(err))
23880 + err = do_rename(a);
23881 + if (unlikely(err))
23884 + if (au_ftest_ren(a->auren_flags, DIRREN))
23885 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23887 + /* update dir attributes */
23888 + au_ren_refresh_dir(a);
23890 + /* dput/iput all lower dentries */
23891 + au_ren_refresh(a);
23893 + goto out_hdir; /* success */
23896 + if (au_ftest_ren(a->auren_flags, DIRREN))
23897 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23899 + au_ren_rev_dt(err, a);
23901 + au_ren_unlock(a);
23903 + au_nhash_wh_free(&a->whlist);
23904 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23905 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23906 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23907 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23911 + if (d_unhashed(a->src_dentry))
23912 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23913 + if (d_unhashed(a->dst_dentry))
23914 + au_fset_ren(a->auren_flags, DROPPED_DST);
23915 + if (!a->exchange)
23916 + d_move(a->src_dentry, a->dst_dentry);
23918 + d_exchange(a->src_dentry, a->dst_dentry);
23919 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23920 + d_drop(a->dst_dentry);
23922 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23923 + d_drop(a->src_dentry);
23925 + au_update_dbtop(a->dst_dentry);
23926 + if (!a->dst_inode)
23927 + d_drop(a->dst_dentry);
23929 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23930 + di_write_unlock(a->dst_parent);
23932 + di_write_unlock2(a->src_parent, a->dst_parent);
23934 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23936 + iput(a->dst_inode);
23938 + au_whtmp_rmdir_free(a->thargs);
23944 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23945 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23946 +++ linux/fs/aufs/Kconfig 2018-06-04 09:08:09.181412645 +0200
23948 +# SPDX-License-Identifier: GPL-2.0
23950 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23952 + Aufs is a stackable unification filesystem such as Unionfs,
23953 + which unifies several directories and provides a merged single
23955 + In the early days, aufs was entirely re-designed and
23956 + re-implemented Unionfs Version 1.x series. Introducing many
23957 + original ideas, approaches and improvements, it becomes totally
23958 + different from Unionfs while keeping the basic features.
23962 + prompt "Maximum number of branches"
23963 + default AUFS_BRANCH_MAX_127
23965 + Specifies the maximum number of branches (or member directories)
23966 + in a single aufs. The larger value consumes more system
23967 + resources and has a minor impact to performance.
23968 +config AUFS_BRANCH_MAX_127
23971 + Specifies the maximum number of branches (or member directories)
23972 + in a single aufs. The larger value consumes more system
23973 + resources and has a minor impact to performance.
23974 +config AUFS_BRANCH_MAX_511
23977 + Specifies the maximum number of branches (or member directories)
23978 + in a single aufs. The larger value consumes more system
23979 + resources and has a minor impact to performance.
23980 +config AUFS_BRANCH_MAX_1023
23983 + Specifies the maximum number of branches (or member directories)
23984 + in a single aufs. The larger value consumes more system
23985 + resources and has a minor impact to performance.
23986 +config AUFS_BRANCH_MAX_32767
23989 + Specifies the maximum number of branches (or member directories)
23990 + in a single aufs. The larger value consumes more system
23991 + resources and has a minor impact to performance.
23994 +config AUFS_SBILIST
23996 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23999 + Automatic configuration for internal use.
24000 + When aufs supports Magic SysRq or /proc, enabled automatically.
24002 +config AUFS_HNOTIFY
24003 + bool "Detect direct branch access (bypassing aufs)"
24005 + If you want to modify files on branches directly, eg. bypassing aufs,
24006 + and want aufs to detect the changes of them fully, then enable this
24007 + option and use 'udba=notify' mount option.
24008 + Currently there is only one available configuration, "fsnotify".
24009 + It will have a negative impact to the performance.
24010 + See detail in aufs.5.
24013 + prompt "method" if AUFS_HNOTIFY
24014 + default AUFS_HFSNOTIFY
24015 +config AUFS_HFSNOTIFY
24020 +config AUFS_EXPORT
24021 + bool "NFS-exportable aufs"
24022 + depends on EXPORTFS
24024 + If you want to export your mounted aufs via NFS, then enable this
24025 + option. There are several requirements for this configuration.
24026 + See detail in aufs.5.
24028 +config AUFS_INO_T_64
24030 + depends on AUFS_EXPORT
24031 + depends on 64BIT && !(ALPHA || S390)
24034 + Automatic configuration for internal use.
24035 + /* typedef unsigned long/int __kernel_ino_t */
24036 + /* alpha and s390x are int */
24039 + bool "support for XATTR/EA (including Security Labels)"
24041 + If your branch fs supports XATTR/EA and you want to make them
24042 + available in aufs too, then enable this opsion and specify the
24043 + branch attributes for EA.
24044 + See detail in aufs.5.
24047 + bool "File-based Hierarchical Storage Management"
24049 + Hierarchical Storage Management (or HSM) is a well-known feature
24050 + in the storage world. Aufs provides this feature as file-based.
24051 + with multiple branches.
24052 + These multiple branches are prioritized, ie. the topmost one
24053 + should be the fastest drive and be used heavily.
24056 + bool "Readdir in userspace"
24058 + Aufs has two methods to provide a merged view for a directory,
24059 + by a user-space library and by kernel-space natively. The latter
24060 + is always enabled but sometimes large and slow.
24061 + If you enable this option, install the library in aufs2-util
24062 + package, and set some environment variables for your readdir(3),
24063 + then the work will be handled in user-space which generally
24064 + shows better performance in most cases.
24065 + See detail in aufs.5.
24067 +config AUFS_DIRREN
24068 + bool "Workaround for rename(2)-ing a directory"
24070 + By default, aufs returns EXDEV error in renameing a dir who has
24071 + his child on the lower branch, since it is a bad idea to issue
24072 + rename(2) internally for every lower branch. But user may not
24073 + accept this behaviour. So here is a workaround to allow such
24074 + rename(2) and store some extra infromation on the writable
24075 + branch. Obviously this costs high (and I don't like it).
24076 + To use this feature, you need to enable this configuration AND
24077 + to specify the mount option `dirren.'
24078 + See details in aufs.5 and the design documents.
24081 + bool "Show whiteouts"
24083 + If you want to make the whiteouts in aufs visible, then enable
24084 + this option and specify 'shwh' mount option. Although it may
24085 + sounds like philosophy or something, but in technically it
24086 + simply shows the name of whiteout with keeping its behaviour.
24088 +config AUFS_BR_RAMFS
24089 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
24091 + If you want to use ramfs as an aufs branch fs, then enable this
24092 + option. Generally tmpfs is recommended.
24093 + Aufs prohibited them to be a branch fs by default, because
24094 + initramfs becomes unusable after switch_root or something
24095 + generally. If you sets initramfs as an aufs branch and boot your
24096 + system by switch_root, you will meet a problem easily since the
24097 + files in initramfs may be inaccessible.
24098 + Unless you are going to use ramfs as an aufs branch fs without
24099 + switch_root or something, leave it N.
24101 +config AUFS_BR_FUSE
24102 + bool "Fuse fs as an aufs branch"
24103 + depends on FUSE_FS
24106 + If you want to use fuse-based userspace filesystem as an aufs
24107 + branch fs, then enable this option.
24108 + It implements the internal poll(2) operation which is
24109 + implemented by fuse only (curretnly).
24114 + Automatic configuration for internal use.
24116 +config AUFS_BR_HFSPLUS
24117 + bool "Hfsplus as an aufs branch"
24118 + depends on HFSPLUS_FS
24121 + If you want to use hfsplus fs as an aufs branch fs, then enable
24122 + this option. This option introduces a small overhead at
24123 + copying-up a file on hfsplus.
24125 +config AUFS_BDEV_LOOP
24127 + depends on BLK_DEV_LOOP
24130 + Automatic configuration for internal use.
24131 + Convert =[ym] into =y.
24134 + bool "Debug aufs"
24136 + Enable this to compile aufs internal debug code.
24137 + It will have a negative impact to the performance.
24139 +config AUFS_MAGIC_SYSRQ
24141 + depends on AUFS_DEBUG && MAGIC_SYSRQ
24144 + Automatic configuration for internal use.
24145 + When aufs supports Magic SysRq, enabled automatically.
24147 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
24148 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
24149 +++ linux/fs/aufs/lcnt.h 2018-10-23 12:33:35.599375796 +0200
24151 +/* SPDX-License-Identifier: GPL-2.0 */
24153 + * Copyright (C) 2018 Junjiro R. Okajima
24155 + * This program, aufs is free software; you can redistribute it and/or modify
24156 + * it under the terms of the GNU General Public License as published by
24157 + * the Free Software Foundation; either version 2 of the License, or
24158 + * (at your option) any later version.
24160 + * This program is distributed in the hope that it will be useful,
24161 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24162 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24163 + * GNU General Public License for more details.
24165 + * You should have received a copy of the GNU General Public License
24166 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24170 + * simple long counter wrapper
24173 +#ifndef __AUFS_LCNT_H__
24174 +#define __AUFS_LCNT_H__
24178 +#include "debug.h"
24180 +#define AuLCntATOMIC 1
24181 +#define AuLCntPCPUCNT 2
24183 + * why does percpu_refcount require extra synchronize_rcu()s in
24184 + * au_br_do_free()
24186 +#define AuLCntPCPUREF 3
24188 +/* #define AuLCntChosen AuLCntATOMIC */
24189 +#define AuLCntChosen AuLCntPCPUCNT
24190 +/* #define AuLCntChosen AuLCntPCPUREF */
24192 +#if AuLCntChosen == AuLCntATOMIC
24193 +#include <linux/atomic.h>
24195 +typedef atomic_long_t au_lcnt_t;
24197 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24199 + atomic_long_set(cnt, 0);
24203 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24208 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
24209 + int do_sync __maybe_unused)
24214 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24216 + atomic_long_inc(cnt);
24219 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24221 + atomic_long_dec(cnt);
24224 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24226 + return atomic_long_read(cnt);
24230 +#if AuLCntChosen == AuLCntPCPUCNT
24231 +#include <linux/percpu_counter.h>
24233 +typedef struct percpu_counter au_lcnt_t;
24235 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24237 + return percpu_counter_init(cnt, 0, GFP_NOFS);
24240 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24245 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
24247 + percpu_counter_destroy(cnt);
24250 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24252 + percpu_counter_inc(cnt);
24255 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24257 + percpu_counter_dec(cnt);
24260 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24264 + n = percpu_counter_sum(cnt);
24266 + if (LONG_MAX != LLONG_MAX
24268 + AuWarn1("%s\n", "wrap-around");
24274 +#if AuLCntChosen == AuLCntPCPUREF
24275 +#include <linux/percpu-refcount.h>
24277 +typedef struct percpu_ref au_lcnt_t;
24279 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24282 + release = percpu_ref_exit;
24283 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24286 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24288 + synchronize_rcu();
24291 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24293 + percpu_ref_kill(cnt);
24295 + au_lcnt_wait_for_fin(cnt);
24298 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24300 + percpu_ref_get(cnt);
24303 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24305 + percpu_ref_put(cnt);
24309 + * avoid calling this func as possible.
24311 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24315 + percpu_ref_switch_to_atomic_sync(cnt);
24316 + l = atomic_long_read(&cnt->count);
24318 + percpu_ref_switch_to_percpu(cnt);
24320 + /* percpu_ref is initialized by 1 instead of 0 */
24325 +#ifdef CONFIG_AUFS_DEBUG
24326 +#define AuLCntZero(val) do { \
24329 + AuDbg("%s = %ld\n", #val, l); \
24332 +#define AuLCntZero(val) do {} while (0)
24335 +#endif /* __KERNEL__ */
24336 +#endif /* __AUFS_LCNT_H__ */
24337 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24338 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24339 +++ linux/fs/aufs/loop.c 2018-12-27 13:19:17.711749485 +0100
24341 +// SPDX-License-Identifier: GPL-2.0
24343 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24345 + * This program, aufs is free software; you can redistribute it and/or modify
24346 + * it under the terms of the GNU General Public License as published by
24347 + * the Free Software Foundation; either version 2 of the License, or
24348 + * (at your option) any later version.
24350 + * This program is distributed in the hope that it will be useful,
24351 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24352 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24353 + * GNU General Public License for more details.
24355 + * You should have received a copy of the GNU General Public License
24356 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24360 + * support for loopback block device as a branch
24365 +/* added into drivers/block/loop.c */
24366 +static struct file *(*backing_file_func)(struct super_block *sb);
24369 + * test if two lower dentries have overlapping branches.
24371 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24373 + struct super_block *h_sb;
24374 + struct file *backing_file;
24376 + if (unlikely(!backing_file_func)) {
24377 + /* don't load "loop" module here */
24378 + backing_file_func = symbol_get(loop_backing_file);
24379 + if (unlikely(!backing_file_func))
24380 + /* "loop" module is not loaded */
24384 + h_sb = h_adding->d_sb;
24385 + backing_file = backing_file_func(h_sb);
24386 + if (!backing_file)
24389 + h_adding = backing_file->f_path.dentry;
24391 + * h_adding can be local NFS.
24392 + * in this case aufs cannot detect the loop.
24394 + if (unlikely(h_adding->d_sb == sb))
24396 + return !!au_test_subdir(h_adding, sb->s_root);
24399 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24400 +int au_test_loopback_kthread(void)
24403 + struct task_struct *tsk = current;
24404 + char c, comm[sizeof(tsk->comm)];
24407 + if (tsk->flags & PF_KTHREAD) {
24408 + get_task_comm(comm, tsk);
24410 + ret = ('0' <= c && c <= '9'
24411 + && !strncmp(comm, "loop", 4));
24417 +/* ---------------------------------------------------------------------- */
24419 +#define au_warn_loopback_step 16
24420 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24421 +static unsigned long *au_warn_loopback_array;
24423 +void au_warn_loopback(struct super_block *h_sb)
24425 + int i, new_nelem;
24426 + unsigned long *a, magic;
24427 + static DEFINE_SPINLOCK(spin);
24429 + magic = h_sb->s_magic;
24430 + spin_lock(&spin);
24431 + a = au_warn_loopback_array;
24432 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24433 + if (a[i] == magic) {
24434 + spin_unlock(&spin);
24438 + /* h_sb is new to us, print it */
24439 + if (i < au_warn_loopback_nelem) {
24444 + /* expand the array */
24445 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24446 + a = au_kzrealloc(au_warn_loopback_array,
24447 + au_warn_loopback_nelem * sizeof(unsigned long),
24448 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24449 + /*may_shrink*/0);
24451 + au_warn_loopback_nelem = new_nelem;
24452 + au_warn_loopback_array = a;
24457 + spin_unlock(&spin);
24458 + AuWarn1("realloc failed, ignored\n");
24462 + spin_unlock(&spin);
24463 + pr_warn("you may want to try another patch for loopback file "
24464 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24467 +int au_loopback_init(void)
24470 + struct super_block *sb __maybe_unused;
24472 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
24475 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24476 + sizeof(unsigned long), GFP_NOFS);
24477 + if (unlikely(!au_warn_loopback_array))
24483 +void au_loopback_fin(void)
24485 + if (backing_file_func)
24486 + symbol_put(loop_backing_file);
24487 + au_kfree_try_rcu(au_warn_loopback_array);
24489 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24490 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24491 +++ linux/fs/aufs/loop.h 2018-08-12 23:43:05.460124736 +0200
24493 +/* SPDX-License-Identifier: GPL-2.0 */
24495 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24497 + * This program, aufs is free software; you can redistribute it and/or modify
24498 + * it under the terms of the GNU General Public License as published by
24499 + * the Free Software Foundation; either version 2 of the License, or
24500 + * (at your option) any later version.
24502 + * This program is distributed in the hope that it will be useful,
24503 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24504 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24505 + * GNU General Public License for more details.
24507 + * You should have received a copy of the GNU General Public License
24508 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24512 + * support for loopback mount as a branch
24515 +#ifndef __AUFS_LOOP_H__
24516 +#define __AUFS_LOOP_H__
24521 +struct super_block;
24523 +#ifdef CONFIG_AUFS_BDEV_LOOP
24524 +/* drivers/block/loop.c */
24525 +struct file *loop_backing_file(struct super_block *sb);
24528 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24529 +int au_test_loopback_kthread(void);
24530 +void au_warn_loopback(struct super_block *h_sb);
24532 +int au_loopback_init(void);
24533 +void au_loopback_fin(void);
24535 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24536 + struct dentry *h_adding)
24537 +AuStubInt0(au_test_loopback_kthread, void)
24538 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24540 +AuStubInt0(au_loopback_init, void)
24541 +AuStubVoid(au_loopback_fin, void)
24542 +#endif /* BLK_DEV_LOOP */
24544 +#endif /* __KERNEL__ */
24545 +#endif /* __AUFS_LOOP_H__ */
24546 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24547 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24548 +++ linux/fs/aufs/magic.mk 2018-06-04 09:08:09.188079511 +0200
24550 +# SPDX-License-Identifier: GPL-2.0
24552 +# defined in ${srctree}/fs/fuse/inode.c
24554 +ifdef CONFIG_FUSE_FS
24555 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24558 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24560 +ifdef CONFIG_XFS_FS
24561 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24564 +# defined in ${srctree}/fs/configfs/mount.c
24566 +ifdef CONFIG_CONFIGFS_FS
24567 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24570 +# defined in ${srctree}/fs/ubifs/ubifs.h
24572 +ifdef CONFIG_UBIFS_FS
24573 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24576 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24578 +ifdef CONFIG_HFSPLUS_FS
24579 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24581 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24582 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24583 +++ linux/fs/aufs/Makefile 2018-06-04 09:08:09.181412645 +0200
24585 +# SPDX-License-Identifier: GPL-2.0
24587 +include ${src}/magic.mk
24588 +ifeq (${CONFIG_AUFS_FS},m)
24589 +include ${src}/conf.mk
24591 +-include ${src}/priv_def.mk
24593 +# cf. include/linux/kernel.h
24595 +ccflags-y += -DDEBUG
24596 +# sparse requires the full pathname
24598 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24600 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24603 +obj-$(CONFIG_AUFS_FS) += aufs.o
24604 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24605 + wkq.o vfsub.o dcsub.o \
24606 + cpup.o whout.o wbr_policy.o \
24607 + dinfo.o dentry.o \
24609 + finfo.o file.o f_op.o \
24611 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24615 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24616 +aufs-$(CONFIG_SYSFS) += sysfs.o
24617 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24618 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24619 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24620 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24621 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24622 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24623 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24624 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24625 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24626 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24627 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24628 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24629 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24630 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24631 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24632 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24633 +++ linux/fs/aufs/module.c 2018-12-27 13:19:17.711749485 +0100
24635 +// SPDX-License-Identifier: GPL-2.0
24637 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24639 + * This program, aufs is free software; you can redistribute it and/or modify
24640 + * it under the terms of the GNU General Public License as published by
24641 + * the Free Software Foundation; either version 2 of the License, or
24642 + * (at your option) any later version.
24644 + * This program is distributed in the hope that it will be useful,
24645 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24646 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24647 + * GNU General Public License for more details.
24649 + * You should have received a copy of the GNU General Public License
24650 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24654 + * module global variables and operations
24657 +#include <linux/module.h>
24658 +#include <linux/seq_file.h>
24661 +/* shrinkable realloc */
24662 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24670 +#if 0 /* unused */
24677 + AuDebugOn(!new_sz);
24680 + diff = au_kmidx_sub(sz, new_sz);
24686 + /* expand or SLOB */
24687 + p = krealloc(p, new_sz, gfp);
24688 + else if (new_sz < sz && may_shrink) {
24692 + q = kmalloc(new_sz, gfp);
24695 + memcpy(q, p, new_sz);
24696 + au_kfree_try_rcu(p);
24707 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24710 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24711 + if (p && new_sz > nused)
24712 + memset(p + nused, 0, new_sz - nused);
24716 +/* ---------------------------------------------------------------------- */
24720 +struct kmem_cache *au_cache[AuCache_Last];
24722 +static void au_cache_fin(void)
24727 + * Make sure all delayed rcu free inodes are flushed before we
24732 + /* excluding AuCache_HNOTIFY */
24733 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24734 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24735 + kmem_cache_destroy(au_cache[i]);
24736 + au_cache[i] = NULL;
24740 +static int __init au_cache_init(void)
24742 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24743 + if (au_cache[AuCache_DINFO])
24744 + /* SLAB_DESTROY_BY_RCU */
24745 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24746 + au_icntnr_init_once);
24747 + if (au_cache[AuCache_ICNTNR])
24748 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24749 + au_fi_init_once);
24750 + if (au_cache[AuCache_FINFO])
24751 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24752 + if (au_cache[AuCache_VDIR])
24753 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24754 + if (au_cache[AuCache_DEHSTR])
24761 +/* ---------------------------------------------------------------------- */
24763 +int au_dir_roflags;
24765 +#ifdef CONFIG_AUFS_SBILIST
24767 + * iterate_supers_type() doesn't protect us from
24768 + * remounting (branch management)
24770 +struct hlist_bl_head au_sbilist;
24774 + * functions for module interface.
24776 +MODULE_LICENSE("GPL");
24777 +/* MODULE_LICENSE("GPL v2"); */
24778 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24779 +MODULE_DESCRIPTION(AUFS_NAME
24780 + " -- Advanced multi layered unification filesystem");
24781 +MODULE_VERSION(AUFS_VERSION);
24782 +MODULE_ALIAS_FS(AUFS_NAME);
24784 +/* this module parameter has no meaning when SYSFS is disabled */
24785 +int sysaufs_brs = 1;
24786 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24787 +module_param_named(brs, sysaufs_brs, int, 0444);
24789 +/* this module parameter has no meaning when USER_NS is disabled */
24791 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24792 +module_param_named(allow_userns, au_userns, bool, 0444);
24794 +/* ---------------------------------------------------------------------- */
24796 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24798 +int au_seq_path(struct seq_file *seq, struct path *path)
24802 + err = seq_path(seq, path, au_esc_chars);
24811 +/* ---------------------------------------------------------------------- */
24813 +static int __init aufs_init(void)
24818 + p = au_esc_chars;
24819 + for (i = 1; i <= ' '; i++)
24825 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24827 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24828 + for (i = 0; i < AuIop_Last; i++)
24829 + aufs_iop_nogetattr[i].getattr = NULL;
24831 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24833 + au_sbilist_init();
24834 + sysaufs_brs_init();
24837 + err = sysaufs_init();
24838 + if (unlikely(err))
24840 + err = dbgaufs_init();
24841 + if (unlikely(err))
24842 + goto out_sysaufs;
24843 + err = au_procfs_init();
24844 + if (unlikely(err))
24845 + goto out_dbgaufs;
24846 + err = au_wkq_init();
24847 + if (unlikely(err))
24849 + err = au_loopback_init();
24850 + if (unlikely(err))
24852 + err = au_hnotify_init();
24853 + if (unlikely(err))
24854 + goto out_loopback;
24855 + err = au_sysrq_init();
24856 + if (unlikely(err))
24858 + err = au_cache_init();
24859 + if (unlikely(err))
24862 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24863 + err = register_filesystem(&aufs_fs_type);
24864 + if (unlikely(err))
24867 + /* since we define pr_fmt, call printk directly */
24868 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24869 + goto out; /* success */
24876 + au_hnotify_fin();
24878 + au_loopback_fin();
24892 +static void __exit aufs_exit(void)
24894 + unregister_filesystem(&aufs_fs_type);
24897 + au_hnotify_fin();
24898 + au_loopback_fin();
24906 +module_init(aufs_init);
24907 +module_exit(aufs_exit);
24908 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24909 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24910 +++ linux/fs/aufs/module.h 2018-12-27 13:19:17.711749485 +0100
24912 +/* SPDX-License-Identifier: GPL-2.0 */
24914 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24916 + * This program, aufs is free software; you can redistribute it and/or modify
24917 + * it under the terms of the GNU General Public License as published by
24918 + * the Free Software Foundation; either version 2 of the License, or
24919 + * (at your option) any later version.
24921 + * This program is distributed in the hope that it will be useful,
24922 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24923 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24924 + * GNU General Public License for more details.
24926 + * You should have received a copy of the GNU General Public License
24927 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24931 + * module initialization and module-global
24934 +#ifndef __AUFS_MODULE_H__
24935 +#define __AUFS_MODULE_H__
24939 +#include <linux/slab.h>
24940 +#include "debug.h"
24941 +#include "dentry.h"
24944 +#include "inode.h"
24949 +/* module parameters */
24950 +extern int sysaufs_brs;
24951 +extern bool au_userns;
24953 +/* ---------------------------------------------------------------------- */
24955 +extern int au_dir_roflags;
24957 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24958 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24962 + * Comparing the size of the object with sizeof(struct rcu_head)
24963 + * case 1: object is always larger
24964 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24965 + * case 2: object is always smaller
24966 + * --> au_kfree_small()
24967 + * case 3: object can be any size
24968 + * --> au_kfree_try_rcu()
24971 +static inline void au_kfree_do_rcu(const void *p)
24974 + struct rcu_head rcu;
24975 + } *a = (void *)p;
24977 + kfree_rcu(a, rcu);
24980 +#define au_kfree_rcu(_p) do { \
24981 + typeof(_p) p = (_p); \
24982 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24984 + au_kfree_do_rcu(p); \
24987 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
24988 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
24990 +static inline void au_kfree_try_rcu(const void *p)
24994 + if (au_kfree_sz_test(p))
24995 + au_kfree_do_rcu(p);
25000 +static inline void au_kfree_small(const void *p)
25004 + AuDebugOn(au_kfree_sz_test(p));
25008 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
25010 +#ifndef CONFIG_SLOB
25011 + return kmalloc_index(sz) - kmalloc_index(new_sz);
25013 + return -1; /* SLOB is untested */
25017 +int au_seq_path(struct seq_file *seq, struct path *path);
25019 +#ifdef CONFIG_PROC_FS
25021 +int __init au_procfs_init(void);
25022 +void au_procfs_fin(void);
25024 +AuStubInt0(au_procfs_init, void);
25025 +AuStubVoid(au_procfs_fin, void);
25028 +/* ---------------------------------------------------------------------- */
25037 + AuCache_HNOTIFY, /* must be last */
25041 +extern struct kmem_cache *au_cache[AuCache_Last];
25043 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
25044 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
25045 +#define AuCacheCtor(type, ctor) \
25046 + kmem_cache_create(#type, sizeof(struct type), \
25047 + __alignof__(struct type), AuCacheFlags, ctor)
25049 +#define AuCacheFuncs(name, index) \
25050 + static inline struct au_##name *au_cache_alloc_##name(void) \
25051 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
25052 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
25053 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
25055 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
25056 + { void *p = rcu; \
25057 + p -= offsetof(struct au_##name, rcu); \
25058 + kmem_cache_free(au_cache[AuCache_##index], p); } \
25059 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
25060 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
25061 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
25063 + static inline void au_cache_free_##name(struct au_##name *p) \
25064 + { /* au_cache_free_##name##_norcu(p); */ \
25065 + au_cache_free_##name##_rcu(p); }
25067 +AuCacheFuncs(dinfo, DINFO);
25068 +AuCacheFuncs(icntnr, ICNTNR);
25069 +AuCacheFuncs(finfo, FINFO);
25070 +AuCacheFuncs(vdir, VDIR);
25071 +AuCacheFuncs(vdir_dehstr, DEHSTR);
25072 +#ifdef CONFIG_AUFS_HNOTIFY
25073 +AuCacheFuncs(hnotify, HNOTIFY);
25076 +#endif /* __KERNEL__ */
25077 +#endif /* __AUFS_MODULE_H__ */
25078 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
25079 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
25080 +++ linux/fs/aufs/mvdown.c 2018-12-27 13:19:17.711749485 +0100
25082 +// SPDX-License-Identifier: GPL-2.0
25084 + * Copyright (C) 2011-2018 Junjiro R. Okajima
25086 + * This program, aufs is free software; you can redistribute it and/or modify
25087 + * it under the terms of the GNU General Public License as published by
25088 + * the Free Software Foundation; either version 2 of the License, or
25089 + * (at your option) any later version.
25091 + * This program is distributed in the hope that it will be useful,
25092 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25093 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25094 + * GNU General Public License for more details.
25096 + * You should have received a copy of the GNU General Public License
25097 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25101 + * move-down, opposite of copy-up
25106 +struct au_mvd_args {
25108 + struct super_block *h_sb;
25109 + struct dentry *h_parent;
25110 + struct au_hinode *hdir;
25111 + struct inode *h_dir, *h_inode;
25112 + struct au_pin pin;
25113 + } info[AUFS_MVDOWN_NARRAY];
25115 + struct aufs_mvdown mvdown;
25116 + struct dentry *dentry, *parent;
25117 + struct inode *inode, *dir;
25118 + struct super_block *sb;
25119 + aufs_bindex_t bopq, bwh, bfound;
25120 + unsigned char rename_lock;
25123 +#define mvd_errno mvdown.au_errno
25124 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
25125 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
25126 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
25127 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
25129 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
25130 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
25131 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
25132 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
25133 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
25134 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
25136 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
25137 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
25138 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
25139 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
25140 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
25141 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
25143 +#define AU_MVD_PR(flag, ...) do { \
25145 + pr_err(__VA_ARGS__); \
25148 +static int find_lower_writable(struct au_mvd_args *a)
25150 + struct super_block *sb;
25151 + aufs_bindex_t bindex, bbot;
25152 + struct au_branch *br;
25155 + bindex = a->mvd_bsrc;
25156 + bbot = au_sbbot(sb);
25157 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
25158 + for (bindex++; bindex <= bbot; bindex++) {
25159 + br = au_sbr(sb, bindex);
25160 + if (au_br_fhsm(br->br_perm)
25161 + && !sb_rdonly(au_br_sb(br)))
25164 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
25165 + for (bindex++; bindex <= bbot; bindex++) {
25166 + br = au_sbr(sb, bindex);
25167 + if (!au_br_rdonly(br))
25171 + for (bindex++; bindex <= bbot; bindex++) {
25172 + br = au_sbr(sb, bindex);
25173 + if (!sb_rdonly(au_br_sb(br))) {
25174 + if (au_br_rdonly(br))
25176 + |= AUFS_MVDOWN_ROLOWER_R;
25184 +/* make the parent dir on bdst */
25185 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
25190 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
25191 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
25192 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
25193 + a->mvd_h_dst_parent = NULL;
25194 + if (au_dbbot(a->parent) >= a->mvd_bdst)
25195 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25196 + if (!a->mvd_h_dst_parent) {
25197 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
25198 + if (unlikely(err)) {
25199 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
25202 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25210 +/* lock them all */
25211 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
25214 + struct dentry *h_trap;
25216 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
25217 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
25218 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
25219 + au_opt_udba(a->sb),
25220 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25222 + if (unlikely(err)) {
25223 + AU_MVD_PR(dmsg, "pin_dst failed\n");
25227 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
25228 + a->rename_lock = 0;
25229 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25230 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
25231 + au_opt_udba(a->sb),
25232 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25233 + err = au_do_pin(&a->mvd_pin_src);
25235 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25236 + if (unlikely(err)) {
25237 + AU_MVD_PR(dmsg, "pin_src failed\n");
25240 + goto out; /* success */
25243 + a->rename_lock = 1;
25244 + au_pin_hdir_unlock(&a->mvd_pin_dst);
25245 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25246 + au_opt_udba(a->sb),
25247 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25249 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25250 + if (unlikely(err)) {
25251 + AU_MVD_PR(dmsg, "pin_src failed\n");
25252 + au_pin_hdir_lock(&a->mvd_pin_dst);
25255 + au_pin_hdir_unlock(&a->mvd_pin_src);
25256 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25257 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25259 + err = (h_trap != a->mvd_h_src_parent);
25261 + err = (h_trap != a->mvd_h_dst_parent);
25263 + BUG_ON(err); /* it should never happen */
25264 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25267 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25268 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25269 + au_pin_hdir_lock(&a->mvd_pin_src);
25270 + au_unpin(&a->mvd_pin_src);
25271 + au_pin_hdir_lock(&a->mvd_pin_dst);
25274 + goto out; /* success */
25277 + au_unpin(&a->mvd_pin_dst);
25283 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25285 + if (!a->rename_lock)
25286 + au_unpin(&a->mvd_pin_src);
25288 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25289 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25290 + au_pin_hdir_lock(&a->mvd_pin_src);
25291 + au_unpin(&a->mvd_pin_src);
25292 + au_pin_hdir_lock(&a->mvd_pin_dst);
25294 + au_unpin(&a->mvd_pin_dst);
25297 +/* copy-down the file */
25298 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25301 + struct au_cp_generic cpg = {
25302 + .dentry = a->dentry,
25303 + .bdst = a->mvd_bdst,
25304 + .bsrc = a->mvd_bsrc,
25306 + .pin = &a->mvd_pin_dst,
25307 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25310 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25311 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25312 + au_fset_cpup(cpg.flags, OVERWRITE);
25313 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25314 + au_fset_cpup(cpg.flags, RWDST);
25315 + err = au_sio_cpdown_simple(&cpg);
25316 + if (unlikely(err))
25317 + AU_MVD_PR(dmsg, "cpdown failed\n");
25324 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25327 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25330 + struct path h_path;
25331 + struct au_branch *br;
25332 + struct inode *delegated;
25334 + br = au_sbr(a->sb, a->mvd_bdst);
25335 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25336 + err = PTR_ERR(h_path.dentry);
25337 + if (IS_ERR(h_path.dentry)) {
25338 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25343 + if (d_is_positive(h_path.dentry)) {
25344 + h_path.mnt = au_br_mnt(br);
25345 + delegated = NULL;
25346 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25347 + &delegated, /*force*/0);
25348 + if (unlikely(err == -EWOULDBLOCK)) {
25349 + pr_warn("cannot retry for NFSv4 delegation"
25350 + " for an internal unlink\n");
25353 + if (unlikely(err))
25354 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25356 + dput(h_path.dentry);
25364 + * unlink the topmost h_dentry
25366 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25369 + struct path h_path;
25370 + struct inode *delegated;
25372 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25373 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25374 + delegated = NULL;
25375 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25376 + if (unlikely(err == -EWOULDBLOCK)) {
25377 + pr_warn("cannot retry for NFSv4 delegation"
25378 + " for an internal unlink\n");
25381 + if (unlikely(err))
25382 + AU_MVD_PR(dmsg, "unlink failed\n");
25388 +/* Since mvdown succeeded, we ignore an error of this function */
25389 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25392 + struct au_branch *br;
25394 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25395 + br = au_sbr(a->sb, a->mvd_bsrc);
25396 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25398 + br = au_sbr(a->sb, a->mvd_bdst);
25399 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25400 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25403 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25405 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25409 + * copy-down the file and unlink the bsrc file.
25410 + * - unlink the bdst whout if exist
25411 + * - copy-down the file (with whtmp name and rename)
25412 + * - unlink the bsrc file
25414 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25418 + err = au_do_mkdir(dmsg, a);
25420 + err = au_do_lock(dmsg, a);
25421 + if (unlikely(err))
25425 + * do not revert the activities we made on bdst since they should be
25426 + * harmless in aufs.
25429 + err = au_do_cpdown(dmsg, a);
25431 + err = au_do_unlink_wh(dmsg, a);
25432 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25433 + err = au_do_unlink(dmsg, a);
25434 + if (unlikely(err))
25437 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25438 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25439 + if (find_lower_writable(a) < 0)
25440 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25442 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25443 + au_do_stfs(dmsg, a);
25445 + /* maintain internal array */
25446 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25447 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25448 + au_set_dbtop(a->dentry, a->mvd_bdst);
25449 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25450 + au_set_ibtop(a->inode, a->mvd_bdst);
25452 + /* hide the lower */
25453 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25454 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25455 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25456 + au_set_ibbot(a->inode, a->mvd_bsrc);
25458 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25459 + au_set_dbbot(a->dentry, a->mvd_bdst);
25460 + if (au_ibbot(a->inode) < a->mvd_bdst)
25461 + au_set_ibbot(a->inode, a->mvd_bdst);
25464 + au_do_unlock(dmsg, a);
25470 +/* ---------------------------------------------------------------------- */
25472 +/* make sure the file is idle */
25473 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25475 + int err, plinked;
25478 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25479 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25480 + && au_dcount(a->dentry) == 1
25481 + && atomic_read(&a->inode->i_count) == 1
25482 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25483 + && (!plinked || !au_plink_test(a->inode))
25484 + && a->inode->i_nlink == 1)
25489 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25490 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25491 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25492 + a->mvd_h_src_inode->i_nlink,
25493 + plinked, plinked ? au_plink_test(a->inode) : 0);
25500 +/* make sure the parent dir is fine */
25501 +static int au_mvd_args_parent(const unsigned char dmsg,
25502 + struct au_mvd_args *a)
25505 + aufs_bindex_t bindex;
25508 + if (unlikely(au_alive_dir(a->parent))) {
25510 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25514 + a->bopq = au_dbdiropq(a->parent);
25515 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25516 + AuDbg("b%d\n", bindex);
25517 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25518 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25520 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25521 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25522 + a->bopq, a->mvd_bdst);
25530 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25531 + struct au_mvd_args *a)
25534 + struct au_dinfo *dinfo, *tmp;
25536 + /* lookup the next lower positive entry */
25538 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25539 + if (unlikely(!tmp))
25544 + dinfo = au_di(a->dentry);
25545 + au_di_cp(tmp, dinfo);
25546 + au_di_swap(tmp, dinfo);
25548 + /* returns the number of positive dentries */
25549 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25550 + /* AuLkup_IGNORE_PERM */ 0);
25552 + a->bwh = au_dbwh(a->dentry);
25553 + else if (err > 0)
25554 + a->bfound = au_dbtop(a->dentry);
25556 + au_di_swap(tmp, dinfo);
25557 + au_rw_write_unlock(&tmp->di_rwsem);
25559 + if (unlikely(err < 0))
25560 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25563 + * here, we have these cases.
25565 + * no positive dentry under bsrc. there are more sub-cases.
25567 + * there no whiteout, we can safely move-down.
25570 + * bsrc < bwh && bwh < bdst
25571 + * there is a whiteout on RO branch. cannot proceed.
25573 + * there is a whiteout on the RW target branch. it should
25576 + * there is a whiteout somewhere unrelated branch.
25577 + * -1 < bfound && bfound <= bsrc
25580 + * found, but it is on RO branch between bsrc and bdst. cannot
25583 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25586 + * found, after we create the file on bdst, it will be hidden.
25589 + AuDebugOn(a->bfound == -1
25591 + && a->bwh <= a->mvd_bsrc);
25592 + AuDebugOn(-1 < a->bfound
25593 + && a->bfound <= a->mvd_bsrc);
25596 + if (a->bfound == -1
25597 + && a->mvd_bsrc < a->bwh
25599 + && a->bwh < a->mvd_bdst) {
25600 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25601 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25602 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25604 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25605 + a->mvd_errno = EAU_MVDOWN_UPPER;
25606 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25607 + a->mvd_bdst, a->bfound);
25611 + err = 0; /* success */
25618 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25623 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25624 + && a->bfound == a->mvd_bdst)
25630 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25633 + struct au_branch *br;
25636 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25640 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25641 + a->mvd_bsrc = au_ibtop(a->inode);
25643 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25644 + if (unlikely(a->mvd_bsrc < 0
25645 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25646 + || au_dbbot(a->dentry) < a->mvd_bsrc
25647 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25648 + || (a->mvd_bsrc < au_ibtop(a->inode)
25649 + || au_ibbot(a->inode) < a->mvd_bsrc
25650 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25651 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25652 + AU_MVD_PR(dmsg, "no upper\n");
25656 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25657 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25658 + AU_MVD_PR(dmsg, "on the bottom\n");
25661 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25662 + br = au_sbr(a->sb, a->mvd_bsrc);
25663 + err = au_br_rdonly(br);
25664 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25665 + if (unlikely(err))
25667 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25668 + || IS_APPEND(a->mvd_h_src_inode))) {
25670 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25676 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25677 + a->mvd_bdst = find_lower_writable(a);
25678 + if (unlikely(a->mvd_bdst < 0)) {
25679 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25680 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25684 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25685 + if (unlikely(a->mvd_bdst < 0
25686 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25687 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25688 + AU_MVD_PR(dmsg, "no lower brid\n");
25693 + err = au_mvd_args_busy(dmsg, a);
25695 + err = au_mvd_args_parent(dmsg, a);
25697 + err = au_mvd_args_intermediate(dmsg, a);
25699 + err = au_mvd_args_exist(dmsg, a);
25701 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25708 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25711 + unsigned char dmsg;
25712 + struct au_mvd_args *args;
25713 + struct inode *inode;
25715 + inode = d_inode(dentry);
25717 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25721 + args = kmalloc(sizeof(*args), GFP_NOFS);
25722 + if (unlikely(!args))
25725 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25727 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
25728 + if (unlikely(err)) {
25733 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25734 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25735 + args->mvdown.au_errno = 0;
25736 + args->dentry = dentry;
25737 + args->inode = inode;
25738 + args->sb = dentry->d_sb;
25741 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25742 + args->parent = dget_parent(dentry);
25743 + args->dir = d_inode(args->parent);
25744 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25745 + dput(args->parent);
25746 + if (unlikely(args->parent != dentry->d_parent)) {
25747 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25751 + inode_lock_nested(inode, I_MUTEX_CHILD);
25752 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25753 + if (unlikely(err))
25756 + di_write_lock_parent(args->parent);
25757 + err = au_mvd_args(dmsg, args);
25758 + if (unlikely(err))
25761 + err = au_do_mvdown(dmsg, args);
25762 + if (unlikely(err))
25765 + au_cpup_attr_timesizes(args->dir);
25766 + au_cpup_attr_timesizes(inode);
25767 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25768 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25769 + /* au_digen_dec(dentry); */
25772 + di_write_unlock(args->parent);
25773 + aufs_read_unlock(dentry, AuLock_DW);
25775 + inode_unlock(inode);
25777 + inode_unlock(args->dir);
25779 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25782 + au_kfree_rcu(args);
25787 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25788 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25789 +++ linux/fs/aufs/opts.c 2018-12-27 13:19:17.711749485 +0100
25791 +// SPDX-License-Identifier: GPL-2.0
25793 + * Copyright (C) 2005-2018 Junjiro R. Okajima
25795 + * This program, aufs is free software; you can redistribute it and/or modify
25796 + * it under the terms of the GNU General Public License as published by
25797 + * the Free Software Foundation; either version 2 of the License, or
25798 + * (at your option) any later version.
25800 + * This program is distributed in the hope that it will be useful,
25801 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25802 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25803 + * GNU General Public License for more details.
25805 + * You should have received a copy of the GNU General Public License
25806 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25810 + * mount options/flags
25813 +#include <linux/namei.h>
25814 +#include <linux/types.h> /* a distribution requires */
25815 +#include <linux/parser.h>
25818 +/* ---------------------------------------------------------------------- */
25822 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25823 + Opt_idel, Opt_imod,
25824 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25825 + Opt_rdblk_def, Opt_rdhash_def,
25826 + Opt_xino, Opt_noxino,
25827 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25828 + Opt_trunc_xino_path, Opt_itrunc_xino,
25829 + Opt_trunc_xib, Opt_notrunc_xib,
25830 + Opt_shwh, Opt_noshwh,
25831 + Opt_plink, Opt_noplink, Opt_list_plink,
25833 + Opt_dio, Opt_nodio,
25834 + Opt_diropq_a, Opt_diropq_w,
25835 + Opt_warn_perm, Opt_nowarn_perm,
25836 + Opt_wbr_copyup, Opt_wbr_create,
25838 + Opt_verbose, Opt_noverbose,
25839 + Opt_sum, Opt_nosum, Opt_wsum,
25840 + Opt_dirperm1, Opt_nodirperm1,
25841 + Opt_dirren, Opt_nodirren,
25842 + Opt_acl, Opt_noacl,
25843 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25846 +static match_table_t options = {
25847 + {Opt_br, "br=%s"},
25848 + {Opt_br, "br:%s"},
25850 + {Opt_add, "add=%d:%s"},
25851 + {Opt_add, "add:%d:%s"},
25852 + {Opt_add, "ins=%d:%s"},
25853 + {Opt_add, "ins:%d:%s"},
25854 + {Opt_append, "append=%s"},
25855 + {Opt_append, "append:%s"},
25856 + {Opt_prepend, "prepend=%s"},
25857 + {Opt_prepend, "prepend:%s"},
25859 + {Opt_del, "del=%s"},
25860 + {Opt_del, "del:%s"},
25861 + /* {Opt_idel, "idel:%d"}, */
25862 + {Opt_mod, "mod=%s"},
25863 + {Opt_mod, "mod:%s"},
25864 + /* {Opt_imod, "imod:%d:%s"}, */
25866 + {Opt_dirwh, "dirwh=%d"},
25868 + {Opt_xino, "xino=%s"},
25869 + {Opt_noxino, "noxino"},
25870 + {Opt_trunc_xino, "trunc_xino"},
25871 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25872 + {Opt_notrunc_xino, "notrunc_xino"},
25873 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25874 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25875 + /* {Opt_zxino, "zxino=%s"}, */
25876 + {Opt_trunc_xib, "trunc_xib"},
25877 + {Opt_notrunc_xib, "notrunc_xib"},
25879 +#ifdef CONFIG_PROC_FS
25880 + {Opt_plink, "plink"},
25882 + {Opt_ignore_silent, "plink"},
25885 + {Opt_noplink, "noplink"},
25887 +#ifdef CONFIG_AUFS_DEBUG
25888 + {Opt_list_plink, "list_plink"},
25891 + {Opt_udba, "udba=%s"},
25893 + {Opt_dio, "dio"},
25894 + {Opt_nodio, "nodio"},
25896 +#ifdef CONFIG_AUFS_DIRREN
25897 + {Opt_dirren, "dirren"},
25898 + {Opt_nodirren, "nodirren"},
25900 + {Opt_ignore, "dirren"},
25901 + {Opt_ignore_silent, "nodirren"},
25904 +#ifdef CONFIG_AUFS_FHSM
25905 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25907 + {Opt_ignore, "fhsm_sec=%d"},
25910 + {Opt_diropq_a, "diropq=always"},
25911 + {Opt_diropq_a, "diropq=a"},
25912 + {Opt_diropq_w, "diropq=whiteouted"},
25913 + {Opt_diropq_w, "diropq=w"},
25915 + {Opt_warn_perm, "warn_perm"},
25916 + {Opt_nowarn_perm, "nowarn_perm"},
25918 + /* keep them temporary */
25919 + {Opt_ignore_silent, "nodlgt"},
25920 + {Opt_ignore, "clean_plink"},
25922 +#ifdef CONFIG_AUFS_SHWH
25923 + {Opt_shwh, "shwh"},
25925 + {Opt_noshwh, "noshwh"},
25927 + {Opt_dirperm1, "dirperm1"},
25928 + {Opt_nodirperm1, "nodirperm1"},
25930 + {Opt_verbose, "verbose"},
25931 + {Opt_verbose, "v"},
25932 + {Opt_noverbose, "noverbose"},
25933 + {Opt_noverbose, "quiet"},
25934 + {Opt_noverbose, "q"},
25935 + {Opt_noverbose, "silent"},
25937 + {Opt_sum, "sum"},
25938 + {Opt_nosum, "nosum"},
25939 + {Opt_wsum, "wsum"},
25941 + {Opt_rdcache, "rdcache=%d"},
25942 + {Opt_rdblk, "rdblk=%d"},
25943 + {Opt_rdblk_def, "rdblk=def"},
25944 + {Opt_rdhash, "rdhash=%d"},
25945 + {Opt_rdhash_def, "rdhash=def"},
25947 + {Opt_wbr_create, "create=%s"},
25948 + {Opt_wbr_create, "create_policy=%s"},
25949 + {Opt_wbr_copyup, "cpup=%s"},
25950 + {Opt_wbr_copyup, "copyup=%s"},
25951 + {Opt_wbr_copyup, "copyup_policy=%s"},
25953 + /* generic VFS flag */
25954 +#ifdef CONFIG_FS_POSIX_ACL
25955 + {Opt_acl, "acl"},
25956 + {Opt_noacl, "noacl"},
25958 + {Opt_ignore, "acl"},
25959 + {Opt_ignore_silent, "noacl"},
25962 + /* internal use for the scripts */
25963 + {Opt_ignore_silent, "si=%s"},
25965 + {Opt_br, "dirs=%s"},
25966 + {Opt_ignore, "debug=%d"},
25967 + {Opt_ignore, "delete=whiteout"},
25968 + {Opt_ignore, "delete=all"},
25969 + {Opt_ignore, "imap=%s"},
25971 + /* temporary workaround, due to old mount(8)? */
25972 + {Opt_ignore_silent, "relatime"},
25977 +/* ---------------------------------------------------------------------- */
25979 +static const char *au_parser_pattern(int val, match_table_t tbl)
25981 + struct match_token *p;
25984 + while (p->pattern) {
25985 + if (p->token == val)
25986 + return p->pattern;
25993 +static const char *au_optstr(int *val, match_table_t tbl)
25995 + struct match_token *p;
26002 + while (p->pattern) {
26004 + && (v & p->token) == p->token) {
26005 + *val &= ~p->token;
26006 + return p->pattern;
26015 +/* ---------------------------------------------------------------------- */
26017 +static match_table_t brperm = {
26018 + {AuBrPerm_RO, AUFS_BRPERM_RO},
26019 + {AuBrPerm_RR, AUFS_BRPERM_RR},
26020 + {AuBrPerm_RW, AUFS_BRPERM_RW},
26024 +static match_table_t brattr = {
26026 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
26027 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
26028 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
26029 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
26030 +#ifdef CONFIG_AUFS_FHSM
26031 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
26033 +#ifdef CONFIG_AUFS_XATTR
26034 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
26035 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
26036 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
26037 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
26038 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
26039 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
26042 + /* ro/rr branch */
26043 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
26046 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
26047 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
26052 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
26059 + p = strchr(str, '+');
26062 + v = match_token(str, table, args);
26064 + if (v & AuBrAttr_CMOO_Mask)
26065 + attr &= ~AuBrAttr_CMOO_Mask;
26070 + pr_warn("ignored branch attribute %s\n", str);
26080 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
26088 + p = au_optstr(&perm, brattr);
26091 + memcpy(q, p, sz + 1);
26097 + p = au_optstr(&perm, brattr);
26101 + memcpy(q, p, sz + 1);
26107 + return q - str->a;
26110 +static int noinline_for_stack br_perm_val(char *perm)
26112 + int val, bad, sz;
26114 + substring_t args[MAX_OPT_ARGS];
26115 + au_br_perm_str_t attr;
26117 + p = strchr(perm, '+');
26120 + val = match_token(perm, brperm, args);
26124 + pr_warn("ignored branch permission %s\n", perm);
26125 + val = AuBrPerm_RO;
26131 + val |= br_attr_val(p + 1, brattr, args);
26134 + switch (val & AuBrPerm_Mask) {
26135 + case AuBrPerm_RO:
26136 + case AuBrPerm_RR:
26137 + bad = val & AuBrWAttr_Mask;
26138 + val &= ~AuBrWAttr_Mask;
26140 + case AuBrPerm_RW:
26141 + bad = val & AuBrRAttr_Mask;
26142 + val &= ~AuBrRAttr_Mask;
26147 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
26148 + * does not treat it as an error, just warning.
26149 + * this is a tiny guard for the user operation.
26151 + if (val & AuBrAttr_UNPIN) {
26152 + bad |= AuBrAttr_UNPIN;
26153 + val &= ~AuBrAttr_UNPIN;
26156 + if (unlikely(bad)) {
26157 + sz = au_do_optstr_br_attr(&attr, bad);
26159 + pr_warn("ignored branch attribute %s\n", attr.a);
26166 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
26168 + au_br_perm_str_t attr;
26174 + p = au_optstr(&perm, brperm);
26175 + AuDebugOn(!p || !*p);
26177 + memcpy(q, p, sz + 1);
26180 + sz = au_do_optstr_br_attr(&attr, perm);
26183 + memcpy(q, attr.a, sz + 1);
26186 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
26189 +/* ---------------------------------------------------------------------- */
26191 +static match_table_t udbalevel = {
26192 + {AuOpt_UDBA_REVAL, "reval"},
26193 + {AuOpt_UDBA_NONE, "none"},
26194 +#ifdef CONFIG_AUFS_HNOTIFY
26195 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
26196 +#ifdef CONFIG_AUFS_HFSNOTIFY
26197 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
26203 +static int noinline_for_stack udba_val(char *str)
26205 + substring_t args[MAX_OPT_ARGS];
26207 + return match_token(str, udbalevel, args);
26210 +const char *au_optstr_udba(int udba)
26212 + return au_parser_pattern(udba, udbalevel);
26215 +/* ---------------------------------------------------------------------- */
26217 +static match_table_t au_wbr_create_policy = {
26218 + {AuWbrCreate_TDP, "tdp"},
26219 + {AuWbrCreate_TDP, "top-down-parent"},
26220 + {AuWbrCreate_RR, "rr"},
26221 + {AuWbrCreate_RR, "round-robin"},
26222 + {AuWbrCreate_MFS, "mfs"},
26223 + {AuWbrCreate_MFS, "most-free-space"},
26224 + {AuWbrCreate_MFSV, "mfs:%d"},
26225 + {AuWbrCreate_MFSV, "most-free-space:%d"},
26227 + /* top-down regardless the parent, and then mfs */
26228 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
26229 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
26231 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
26232 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
26233 + {AuWbrCreate_PMFS, "pmfs"},
26234 + {AuWbrCreate_PMFSV, "pmfs:%d"},
26235 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
26236 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26241 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26242 + struct au_opt_wbr_create *create)
26245 + unsigned long long ull;
26248 + if (!match_u64(arg, &ull))
26249 + create->mfsrr_watermark = ull;
26251 + pr_err("bad integer in %s\n", str);
26258 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26259 + struct au_opt_wbr_create *create)
26264 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26265 + create->mfs_second = n;
26267 + pr_err("bad integer in %s\n", str);
26274 +static int noinline_for_stack
26275 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26278 + substring_t args[MAX_OPT_ARGS];
26280 + err = match_token(str, au_wbr_create_policy, args);
26281 + create->wbr_create = err;
26283 + case AuWbrCreate_MFSRRV:
26284 + case AuWbrCreate_TDMFSV:
26285 + case AuWbrCreate_PMFSRRV:
26286 + e = au_wbr_mfs_wmark(&args[0], str, create);
26288 + e = au_wbr_mfs_sec(&args[1], str, create);
26292 + case AuWbrCreate_MFSRR:
26293 + case AuWbrCreate_TDMFS:
26294 + case AuWbrCreate_PMFSRR:
26295 + e = au_wbr_mfs_wmark(&args[0], str, create);
26296 + if (unlikely(e)) {
26301 + case AuWbrCreate_MFS:
26302 + case AuWbrCreate_PMFS:
26303 + create->mfs_second = AUFS_MFS_DEF_SEC;
26305 + case AuWbrCreate_MFSV:
26306 + case AuWbrCreate_PMFSV:
26307 + e = au_wbr_mfs_sec(&args[0], str, create);
26316 +const char *au_optstr_wbr_create(int wbr_create)
26318 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26321 +static match_table_t au_wbr_copyup_policy = {
26322 + {AuWbrCopyup_TDP, "tdp"},
26323 + {AuWbrCopyup_TDP, "top-down-parent"},
26324 + {AuWbrCopyup_BUP, "bup"},
26325 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26326 + {AuWbrCopyup_BU, "bu"},
26327 + {AuWbrCopyup_BU, "bottom-up"},
26331 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26333 + substring_t args[MAX_OPT_ARGS];
26335 + return match_token(str, au_wbr_copyup_policy, args);
26338 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26340 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26343 +/* ---------------------------------------------------------------------- */
26345 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26347 +static void dump_opts(struct au_opts *opts)
26349 +#ifdef CONFIG_AUFS_DEBUG
26350 + /* reduce stack space */
26352 + struct au_opt_add *add;
26353 + struct au_opt_del *del;
26354 + struct au_opt_mod *mod;
26355 + struct au_opt_xino *xino;
26356 + struct au_opt_xino_itrunc *xino_itrunc;
26357 + struct au_opt_wbr_create *create;
26359 + struct au_opt *opt;
26362 + while (opt->type != Opt_tail) {
26363 + switch (opt->type) {
26365 + u.add = &opt->add;
26366 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26367 + u.add->bindex, u.add->pathname, u.add->perm,
26368 + u.add->path.dentry);
26372 + u.del = &opt->del;
26373 + AuDbg("del {%s, %p}\n",
26374 + u.del->pathname, u.del->h_path.dentry);
26378 + u.mod = &opt->mod;
26379 + AuDbg("mod {%s, 0x%x, %p}\n",
26380 + u.mod->path, u.mod->perm, u.mod->h_root);
26383 + u.add = &opt->add;
26384 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26385 + u.add->bindex, u.add->pathname, u.add->perm,
26386 + u.add->path.dentry);
26388 + case Opt_prepend:
26389 + u.add = &opt->add;
26390 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26391 + u.add->bindex, u.add->pathname, u.add->perm,
26392 + u.add->path.dentry);
26395 + AuDbg("dirwh %d\n", opt->dirwh);
26397 + case Opt_rdcache:
26398 + AuDbg("rdcache %d\n", opt->rdcache);
26401 + AuDbg("rdblk %u\n", opt->rdblk);
26403 + case Opt_rdblk_def:
26404 + AuDbg("rdblk_def\n");
26407 + AuDbg("rdhash %u\n", opt->rdhash);
26409 + case Opt_rdhash_def:
26410 + AuDbg("rdhash_def\n");
26413 + u.xino = &opt->xino;
26414 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26416 + case Opt_trunc_xino:
26417 + AuLabel(trunc_xino);
26419 + case Opt_notrunc_xino:
26420 + AuLabel(notrunc_xino);
26422 + case Opt_trunc_xino_path:
26423 + case Opt_itrunc_xino:
26424 + u.xino_itrunc = &opt->xino_itrunc;
26425 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26430 + case Opt_trunc_xib:
26431 + AuLabel(trunc_xib);
26433 + case Opt_notrunc_xib:
26434 + AuLabel(notrunc_xib);
26442 + case Opt_dirperm1:
26443 + AuLabel(dirperm1);
26445 + case Opt_nodirperm1:
26446 + AuLabel(nodirperm1);
26451 + case Opt_noplink:
26452 + AuLabel(noplink);
26454 + case Opt_list_plink:
26455 + AuLabel(list_plink);
26458 + AuDbg("udba %d, %s\n",
26459 + opt->udba, au_optstr_udba(opt->udba));
26467 + case Opt_diropq_a:
26468 + AuLabel(diropq_a);
26470 + case Opt_diropq_w:
26471 + AuLabel(diropq_w);
26473 + case Opt_warn_perm:
26474 + AuLabel(warn_perm);
26476 + case Opt_nowarn_perm:
26477 + AuLabel(nowarn_perm);
26479 + case Opt_verbose:
26480 + AuLabel(verbose);
26482 + case Opt_noverbose:
26483 + AuLabel(noverbose);
26494 + case Opt_wbr_create:
26495 + u.create = &opt->wbr_create;
26496 + AuDbg("create %d, %s\n", u.create->wbr_create,
26497 + au_optstr_wbr_create(u.create->wbr_create));
26498 + switch (u.create->wbr_create) {
26499 + case AuWbrCreate_MFSV:
26500 + case AuWbrCreate_PMFSV:
26501 + AuDbg("%d sec\n", u.create->mfs_second);
26503 + case AuWbrCreate_MFSRR:
26504 + case AuWbrCreate_TDMFS:
26505 + AuDbg("%llu watermark\n",
26506 + u.create->mfsrr_watermark);
26508 + case AuWbrCreate_MFSRRV:
26509 + case AuWbrCreate_TDMFSV:
26510 + case AuWbrCreate_PMFSRRV:
26511 + AuDbg("%llu watermark, %d sec\n",
26512 + u.create->mfsrr_watermark,
26513 + u.create->mfs_second);
26517 + case Opt_wbr_copyup:
26518 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26519 + au_optstr_wbr_copyup(opt->wbr_copyup));
26521 + case Opt_fhsm_sec:
26522 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26527 + case Opt_nodirren:
26528 + AuLabel(nodirren);
26544 +void au_opts_free(struct au_opts *opts)
26546 + struct au_opt *opt;
26549 + while (opt->type != Opt_tail) {
26550 + switch (opt->type) {
26553 + case Opt_prepend:
26554 + path_put(&opt->add.path);
26558 + path_put(&opt->del.h_path);
26562 + dput(opt->mod.h_root);
26565 + fput(opt->xino.file);
26572 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26573 + aufs_bindex_t bindex)
26576 + struct au_opt_add *add = &opt->add;
26579 + add->bindex = bindex;
26580 + add->perm = AuBrPerm_RO;
26581 + add->pathname = opt_str;
26582 + p = strchr(opt_str, '=');
26586 + add->perm = br_perm_val(p);
26589 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26592 + add->perm = AuBrPerm_RO;
26593 + if (au_test_fs_rr(add->path.dentry->d_sb))
26594 + add->perm = AuBrPerm_RR;
26595 + else if (!bindex && !(sb_flags & SB_RDONLY))
26596 + add->perm = AuBrPerm_RW;
26598 + opt->type = Opt_add;
26601 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26608 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26612 + del->pathname = args[0].from;
26613 + AuDbg("del path %s\n", del->pathname);
26615 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26616 + if (unlikely(err))
26617 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26622 +#if 0 /* reserved for future use */
26623 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26624 + struct au_opt_del *del, substring_t args[])
26627 + struct dentry *root;
26630 + root = sb->s_root;
26631 + aufs_read_lock(root, AuLock_FLUSH);
26632 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26633 + pr_err("out of bounds, %d\n", bindex);
26638 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26639 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26642 + aufs_read_unlock(root, !AuLock_IR);
26647 +static int noinline_for_stack
26648 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26651 + struct path path;
26655 + mod->path = args[0].from;
26656 + p = strchr(mod->path, '=');
26657 + if (unlikely(!p)) {
26658 + pr_err("no permission %s\n", args[0].from);
26663 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26664 + if (unlikely(err)) {
26665 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26669 + mod->perm = br_perm_val(p);
26670 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26671 + mod->h_root = dget(path.dentry);
26678 +#if 0 /* reserved for future use */
26679 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26680 + struct au_opt_mod *mod, substring_t args[])
26683 + struct dentry *root;
26686 + root = sb->s_root;
26687 + aufs_read_lock(root, AuLock_FLUSH);
26688 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26689 + pr_err("out of bounds, %d\n", bindex);
26694 + mod->perm = br_perm_val(args[1].from);
26695 + AuDbg("mod path %s, perm 0x%x, %s\n",
26696 + mod->path, mod->perm, args[1].from);
26697 + mod->h_root = dget(au_h_dptr(root, bindex));
26700 + aufs_read_unlock(root, !AuLock_IR);
26705 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26706 + substring_t args[])
26709 + struct file *file;
26711 + file = au_xino_create(sb, args[0].from, /*silent*/0);
26712 + err = PTR_ERR(file);
26713 + if (IS_ERR(file))
26717 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26719 + pr_err("%s must be outside\n", args[0].from);
26724 + xino->file = file;
26725 + xino->path = args[0].from;
26731 +static int noinline_for_stack
26732 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26733 + struct au_opt_xino_itrunc *xino_itrunc,
26734 + substring_t args[])
26737 + aufs_bindex_t bbot, bindex;
26738 + struct path path;
26739 + struct dentry *root;
26741 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26742 + if (unlikely(err)) {
26743 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26747 + xino_itrunc->bindex = -1;
26748 + root = sb->s_root;
26749 + aufs_read_lock(root, AuLock_FLUSH);
26750 + bbot = au_sbbot(sb);
26751 + for (bindex = 0; bindex <= bbot; bindex++) {
26752 + if (au_h_dptr(root, bindex) == path.dentry) {
26753 + xino_itrunc->bindex = bindex;
26757 + aufs_read_unlock(root, !AuLock_IR);
26760 + if (unlikely(xino_itrunc->bindex < 0)) {
26761 + pr_err("no such branch %s\n", args[0].from);
26769 +/* called without aufs lock */
26770 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26772 + int err, n, token;
26773 + aufs_bindex_t bindex;
26774 + unsigned char skipped;
26775 + struct dentry *root;
26776 + struct au_opt *opt, *opt_tail;
26778 + /* reduce the stack space */
26780 + struct au_opt_xino_itrunc *xino_itrunc;
26781 + struct au_opt_wbr_create *create;
26784 + substring_t args[MAX_OPT_ARGS];
26788 + a = kmalloc(sizeof(*a), GFP_NOFS);
26789 + if (unlikely(!a))
26792 + root = sb->s_root;
26796 + opt_tail = opt + opts->max_opt - 1;
26797 + opt->type = Opt_tail;
26798 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26801 + token = match_token(opt_str, options, a->args);
26805 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26807 + err = opt_add(opt, opt_str, opts->sb_flags,
26809 + if (unlikely(!err && ++opt > opt_tail)) {
26813 + opt->type = Opt_tail;
26818 + if (unlikely(match_int(&a->args[0], &n))) {
26819 + pr_err("bad integer in %s\n", opt_str);
26823 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26826 + opt->type = token;
26829 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26830 + /*dummy bindex*/1);
26832 + opt->type = token;
26834 + case Opt_prepend:
26835 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26838 + opt->type = token;
26841 + err = au_opts_parse_del(&opt->del, a->args);
26843 + opt->type = token;
26845 +#if 0 /* reserved for future use */
26847 + del->pathname = "(indexed)";
26848 + if (unlikely(match_int(&args[0], &n))) {
26849 + pr_err("bad integer in %s\n", opt_str);
26852 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26854 + opt->type = token;
26858 + err = au_opts_parse_mod(&opt->mod, a->args);
26860 + opt->type = token;
26862 +#ifdef IMOD /* reserved for future use */
26864 + u.mod->path = "(indexed)";
26865 + if (unlikely(match_int(&a->args[0], &n))) {
26866 + pr_err("bad integer in %s\n", opt_str);
26869 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26871 + opt->type = token;
26875 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26877 + opt->type = token;
26880 + case Opt_trunc_xino_path:
26881 + err = au_opts_parse_xino_itrunc_path
26882 + (sb, &opt->xino_itrunc, a->args);
26884 + opt->type = token;
26887 + case Opt_itrunc_xino:
26888 + u.xino_itrunc = &opt->xino_itrunc;
26889 + if (unlikely(match_int(&a->args[0], &n))) {
26890 + pr_err("bad integer in %s\n", opt_str);
26893 + u.xino_itrunc->bindex = n;
26894 + aufs_read_lock(root, AuLock_FLUSH);
26895 + if (n < 0 || au_sbbot(sb) < n) {
26896 + pr_err("out of bounds, %d\n", n);
26897 + aufs_read_unlock(root, !AuLock_IR);
26900 + aufs_read_unlock(root, !AuLock_IR);
26902 + opt->type = token;
26906 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26909 + opt->type = token;
26912 + case Opt_rdcache:
26913 + if (unlikely(match_int(&a->args[0], &n))) {
26914 + pr_err("bad integer in %s\n", opt_str);
26917 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26918 + pr_err("rdcache must be smaller than %d\n",
26919 + AUFS_RDCACHE_MAX);
26922 + opt->rdcache = n;
26924 + opt->type = token;
26927 + if (unlikely(match_int(&a->args[0], &n)
26929 + || n > KMALLOC_MAX_SIZE)) {
26930 + pr_err("bad integer in %s\n", opt_str);
26933 + if (unlikely(n && n < NAME_MAX)) {
26934 + pr_err("rdblk must be larger than %d\n",
26940 + opt->type = token;
26943 + if (unlikely(match_int(&a->args[0], &n)
26945 + || n * sizeof(struct hlist_head)
26946 + > KMALLOC_MAX_SIZE)) {
26947 + pr_err("bad integer in %s\n", opt_str);
26952 + opt->type = token;
26955 + case Opt_trunc_xino:
26956 + case Opt_notrunc_xino:
26958 + case Opt_trunc_xib:
26959 + case Opt_notrunc_xib:
26962 + case Opt_dirperm1:
26963 + case Opt_nodirperm1:
26965 + case Opt_noplink:
26966 + case Opt_list_plink:
26969 + case Opt_diropq_a:
26970 + case Opt_diropq_w:
26971 + case Opt_warn_perm:
26972 + case Opt_nowarn_perm:
26973 + case Opt_verbose:
26974 + case Opt_noverbose:
26978 + case Opt_rdblk_def:
26979 + case Opt_rdhash_def:
26981 + case Opt_nodirren:
26985 + opt->type = token;
26989 + opt->udba = udba_val(a->args[0].from);
26990 + if (opt->udba >= 0) {
26992 + opt->type = token;
26994 + pr_err("wrong value, %s\n", opt_str);
26997 + case Opt_wbr_create:
26998 + u.create = &opt->wbr_create;
26999 + u.create->wbr_create
27000 + = au_wbr_create_val(a->args[0].from, u.create);
27001 + if (u.create->wbr_create >= 0) {
27003 + opt->type = token;
27005 + pr_err("wrong value, %s\n", opt_str);
27007 + case Opt_wbr_copyup:
27008 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
27009 + if (opt->wbr_copyup >= 0) {
27011 + opt->type = token;
27013 + pr_err("wrong value, %s\n", opt_str);
27016 + case Opt_fhsm_sec:
27017 + if (unlikely(match_int(&a->args[0], &n)
27019 + pr_err("bad integer in %s\n", opt_str);
27022 + if (sysaufs_brs) {
27023 + opt->fhsm_second = n;
27024 + opt->type = token;
27026 + pr_warn("ignored %s\n", opt_str);
27031 + pr_warn("ignored %s\n", opt_str);
27033 + case Opt_ignore_silent:
27038 + pr_err("unknown option %s\n", opt_str);
27042 + if (!err && !skipped) {
27043 + if (unlikely(++opt > opt_tail)) {
27046 + opt->type = Opt_tail;
27049 + opt->type = Opt_tail;
27055 + if (unlikely(err))
27056 + au_opts_free(opts);
27062 +static int au_opt_wbr_create(struct super_block *sb,
27063 + struct au_opt_wbr_create *create)
27066 + struct au_sbinfo *sbinfo;
27068 + SiMustWriteLock(sb);
27070 + err = 1; /* handled */
27071 + sbinfo = au_sbi(sb);
27072 + if (sbinfo->si_wbr_create_ops->fin) {
27073 + err = sbinfo->si_wbr_create_ops->fin(sb);
27078 + sbinfo->si_wbr_create = create->wbr_create;
27079 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
27080 + switch (create->wbr_create) {
27081 + case AuWbrCreate_MFSRRV:
27082 + case AuWbrCreate_MFSRR:
27083 + case AuWbrCreate_TDMFS:
27084 + case AuWbrCreate_TDMFSV:
27085 + case AuWbrCreate_PMFSRR:
27086 + case AuWbrCreate_PMFSRRV:
27087 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
27089 + case AuWbrCreate_MFS:
27090 + case AuWbrCreate_MFSV:
27091 + case AuWbrCreate_PMFS:
27092 + case AuWbrCreate_PMFSV:
27093 + sbinfo->si_wbr_mfs.mfs_expire
27094 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
27098 + if (sbinfo->si_wbr_create_ops->init)
27099 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27106 + * plus: processed without an error
27107 + * zero: unprocessed
27109 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27110 + struct au_opts *opts)
27113 + struct au_sbinfo *sbinfo;
27115 + SiMustWriteLock(sb);
27117 + err = 1; /* handled */
27118 + sbinfo = au_sbi(sb);
27119 + switch (opt->type) {
27121 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27122 + sbinfo->si_mntflags |= opt->udba;
27123 + opts->given_udba |= opt->udba;
27127 + au_opt_set(sbinfo->si_mntflags, PLINK);
27129 + case Opt_noplink:
27130 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27131 + au_plink_put(sb, /*verbose*/1);
27132 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27134 + case Opt_list_plink:
27135 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27136 + au_plink_list(sb);
27140 + au_opt_set(sbinfo->si_mntflags, DIO);
27141 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27144 + au_opt_clr(sbinfo->si_mntflags, DIO);
27145 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27148 + case Opt_fhsm_sec:
27149 + au_fhsm_set(sbinfo, opt->fhsm_second);
27152 + case Opt_diropq_a:
27153 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27155 + case Opt_diropq_w:
27156 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27159 + case Opt_warn_perm:
27160 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27162 + case Opt_nowarn_perm:
27163 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27166 + case Opt_verbose:
27167 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27169 + case Opt_noverbose:
27170 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27174 + au_opt_set(sbinfo->si_mntflags, SUM);
27177 + au_opt_clr(sbinfo->si_mntflags, SUM);
27178 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27180 + au_opt_clr(sbinfo->si_mntflags, SUM);
27181 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27184 + case Opt_wbr_create:
27185 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27187 + case Opt_wbr_copyup:
27188 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27189 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27193 + sbinfo->si_dirwh = opt->dirwh;
27196 + case Opt_rdcache:
27197 + sbinfo->si_rdcache
27198 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27201 + sbinfo->si_rdblk = opt->rdblk;
27203 + case Opt_rdblk_def:
27204 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
27207 + sbinfo->si_rdhash = opt->rdhash;
27209 + case Opt_rdhash_def:
27210 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
27214 + au_opt_set(sbinfo->si_mntflags, SHWH);
27217 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27220 + case Opt_dirperm1:
27221 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27223 + case Opt_nodirperm1:
27224 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27227 + case Opt_trunc_xino:
27228 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27230 + case Opt_notrunc_xino:
27231 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27234 + case Opt_trunc_xino_path:
27235 + case Opt_itrunc_xino:
27236 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27242 + case Opt_trunc_xib:
27243 + au_fset_opts(opts->flags, TRUNC_XIB);
27245 + case Opt_notrunc_xib:
27246 + au_fclr_opts(opts->flags, TRUNC_XIB);
27251 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27252 + err = au_dr_opt_set(sb);
27257 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27259 + case Opt_nodirren:
27261 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27262 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27268 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27272 + sb->s_flags |= SB_POSIXACL;
27275 + sb->s_flags &= ~SB_POSIXACL;
27287 + * returns tri-state.
27288 + * plus: processed without an error
27289 + * zero: unprocessed
27292 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27293 + struct au_opts *opts)
27295 + int err, do_refresh;
27298 + switch (opt->type) {
27300 + opt->add.bindex = au_sbbot(sb) + 1;
27301 + if (opt->add.bindex < 0)
27302 + opt->add.bindex = 0;
27304 + case Opt_prepend:
27305 + opt->add.bindex = 0;
27306 + add: /* indented label */
27308 + err = au_br_add(sb, &opt->add,
27309 + au_ftest_opts(opts->flags, REMOUNT));
27312 + au_fset_opts(opts->flags, REFRESH);
27318 + err = au_br_del(sb, &opt->del,
27319 + au_ftest_opts(opts->flags, REMOUNT));
27322 + au_fset_opts(opts->flags, TRUNC_XIB);
27323 + au_fset_opts(opts->flags, REFRESH);
27329 + err = au_br_mod(sb, &opt->mod,
27330 + au_ftest_opts(opts->flags, REMOUNT),
27335 + au_fset_opts(opts->flags, REFRESH);
27342 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27343 + struct au_opt_xino **opt_xino,
27344 + struct au_opts *opts)
27349 + switch (opt->type) {
27351 + err = au_xino_set(sb, &opt->xino,
27352 + !!au_ftest_opts(opts->flags, REMOUNT));
27353 + if (unlikely(err))
27356 + *opt_xino = &opt->xino;
27361 + *opt_xino = (void *)-1;
27368 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27369 + unsigned int pending)
27372 + aufs_bindex_t bindex, bbot;
27373 + unsigned char do_plink, skip, do_free, can_no_dreval;
27374 + struct au_branch *br;
27375 + struct au_wbr *wbr;
27376 + struct dentry *root, *dentry;
27377 + struct inode *dir, *h_dir;
27378 + struct au_sbinfo *sbinfo;
27379 + struct au_hinode *hdir;
27381 + SiMustAnyLock(sb);
27383 + sbinfo = au_sbi(sb);
27384 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27386 + if (!(sb_flags & SB_RDONLY)) {
27387 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27388 + pr_warn("first branch should be rw\n");
27389 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27390 + pr_warn_once("shwh should be used with ro\n");
27393 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27394 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27395 + pr_warn_once("udba=*notify requires xino\n");
27397 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27398 + pr_warn_once("dirperm1 breaks the protection"
27399 + " by the permission bits on the lower branch\n");
27403 + root = sb->s_root;
27404 + dir = d_inode(root);
27405 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27406 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27408 + bbot = au_sbbot(sb);
27409 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27411 + h_dir = au_h_iptr(dir, bindex);
27412 + br = au_sbr(sb, bindex);
27414 + if ((br->br_perm & AuBrAttr_ICEX)
27415 + && !h_dir->i_op->listxattr)
27416 + br->br_perm &= ~AuBrAttr_ICEX;
27418 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27419 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27420 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27424 + wbr = br->br_wbr;
27426 + wbr_wh_read_lock(wbr);
27428 + if (!au_br_writable(br->br_perm)) {
27431 + || (!wbr->wbr_whbase
27432 + && !wbr->wbr_plink
27433 + && !wbr->wbr_orph));
27434 + } else if (!au_br_wh_linkable(br->br_perm)) {
27435 + /* skip = (!br->br_whbase && !br->br_orph); */
27436 + skip = (!wbr || !wbr->wbr_whbase);
27437 + if (skip && wbr) {
27439 + skip = !!wbr->wbr_plink;
27441 + skip = !wbr->wbr_plink;
27444 + /* skip = (br->br_whbase && br->br_ohph); */
27445 + skip = (wbr && wbr->wbr_whbase);
27448 + skip = !!wbr->wbr_plink;
27450 + skip = !wbr->wbr_plink;
27454 + wbr_wh_read_unlock(wbr);
27456 + if (can_no_dreval) {
27457 + dentry = br->br_path.dentry;
27458 + spin_lock(&dentry->d_lock);
27459 + if (dentry->d_flags &
27460 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27461 + can_no_dreval = 0;
27462 + spin_unlock(&dentry->d_lock);
27465 + if (au_br_fhsm(br->br_perm)) {
27467 + AuDebugOn(!br->br_fhsm);
27473 + hdir = au_hi(dir, bindex);
27474 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27476 + wbr_wh_write_lock(wbr);
27477 + err = au_wh_init(br, sb);
27479 + wbr_wh_write_unlock(wbr);
27480 + au_hn_inode_unlock(hdir);
27482 + if (!err && do_free) {
27483 + au_kfree_rcu(wbr);
27484 + br->br_wbr = NULL;
27488 + if (can_no_dreval)
27489 + au_fset_si(sbinfo, NO_DREVAL);
27491 + au_fclr_si(sbinfo, NO_DREVAL);
27494 + au_fset_si(sbinfo, FHSM);
27495 + for (bindex = bbot; bindex >= 0; bindex--) {
27496 + br = au_sbr(sb, bindex);
27497 + if (au_br_fhsm(br->br_perm)) {
27498 + au_fhsm_set_bottom(sb, bindex);
27503 + au_fclr_si(sbinfo, FHSM);
27504 + au_fhsm_set_bottom(sb, -1);
27510 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27513 + unsigned int tmp;
27514 + aufs_bindex_t bindex, bbot;
27515 + struct au_opt *opt;
27516 + struct au_opt_xino *opt_xino, xino;
27517 + struct au_sbinfo *sbinfo;
27518 + struct au_branch *br;
27519 + struct inode *dir;
27521 + SiMustWriteLock(sb);
27526 + while (err >= 0 && opt->type != Opt_tail)
27527 + err = au_opt_simple(sb, opt++, opts);
27530 + else if (unlikely(err < 0))
27533 + /* disable xino and udba temporary */
27534 + sbinfo = au_sbi(sb);
27535 + tmp = sbinfo->si_mntflags;
27536 + au_opt_clr(sbinfo->si_mntflags, XINO);
27537 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27540 + while (err >= 0 && opt->type != Opt_tail)
27541 + err = au_opt_br(sb, opt++, opts);
27544 + else if (unlikely(err < 0))
27547 + bbot = au_sbbot(sb);
27548 + if (unlikely(bbot < 0)) {
27550 + pr_err("no branches\n");
27554 + if (au_opt_test(tmp, XINO))
27555 + au_opt_set(sbinfo->si_mntflags, XINO);
27557 + while (!err && opt->type != Opt_tail)
27558 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27559 + if (unlikely(err))
27562 + err = au_opts_verify(sb, sb->s_flags, tmp);
27563 + if (unlikely(err))
27566 + /* restore xino */
27567 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27568 + xino.file = au_xino_def(sb);
27569 + err = PTR_ERR(xino.file);
27570 + if (IS_ERR(xino.file))
27573 + err = au_xino_set(sb, &xino, /*remount*/0);
27575 + if (unlikely(err))
27579 + /* restore udba */
27580 + tmp &= AuOptMask_UDBA;
27581 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27582 + sbinfo->si_mntflags |= tmp;
27583 + bbot = au_sbbot(sb);
27584 + for (bindex = 0; bindex <= bbot; bindex++) {
27585 + br = au_sbr(sb, bindex);
27586 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27587 + if (unlikely(err))
27588 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27590 + /* go on even if err */
27592 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27593 + dir = d_inode(sb->s_root);
27594 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27601 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27604 + unsigned char no_dreval;
27605 + struct inode *dir;
27606 + struct au_opt_xino *opt_xino;
27607 + struct au_opt *opt;
27608 + struct au_sbinfo *sbinfo;
27610 + SiMustWriteLock(sb);
27612 + err = au_dr_opt_flush(sb);
27613 + if (unlikely(err))
27615 + au_fset_opts(opts->flags, DR_FLUSHED);
27617 + dir = d_inode(sb->s_root);
27618 + sbinfo = au_sbi(sb);
27621 + while (err >= 0 && opt->type != Opt_tail) {
27622 + err = au_opt_simple(sb, opt, opts);
27624 + err = au_opt_br(sb, opt, opts);
27626 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27632 + /* go on even err */
27634 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27635 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27636 + if (unlikely(rerr && !err))
27639 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27640 + au_fset_opts(opts->flags, REFRESH_IDOP);
27642 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27643 + rerr = au_xib_trunc(sb);
27644 + if (unlikely(rerr && !err))
27648 + /* will be handled by the caller */
27649 + if (!au_ftest_opts(opts->flags, REFRESH)
27650 + && (opts->given_udba
27651 + || au_opt_test(sbinfo->si_mntflags, XINO)
27652 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27654 + au_fset_opts(opts->flags, REFRESH);
27656 + AuDbg("status 0x%x\n", opts->flags);
27662 +/* ---------------------------------------------------------------------- */
27664 +unsigned int au_opt_udba(struct super_block *sb)
27666 + return au_mntflags(sb) & AuOptMask_UDBA;
27668 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27669 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27670 +++ linux/fs/aufs/opts.h 2018-08-12 23:43:05.460124736 +0200
27672 +/* SPDX-License-Identifier: GPL-2.0 */
27674 + * Copyright (C) 2005-2018 Junjiro R. Okajima
27676 + * This program, aufs is free software; you can redistribute it and/or modify
27677 + * it under the terms of the GNU General Public License as published by
27678 + * the Free Software Foundation; either version 2 of the License, or
27679 + * (at your option) any later version.
27681 + * This program is distributed in the hope that it will be useful,
27682 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27683 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27684 + * GNU General Public License for more details.
27686 + * You should have received a copy of the GNU General Public License
27687 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27691 + * mount options/flags
27694 +#ifndef __AUFS_OPTS_H__
27695 +#define __AUFS_OPTS_H__
27699 +#include <linux/path.h>
27703 +/* ---------------------------------------------------------------------- */
27706 +#define AuOpt_XINO 1 /* external inode number bitmap
27707 + and translation table */
27708 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27709 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27710 +#define AuOpt_UDBA_REVAL (1 << 3)
27711 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27712 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27713 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27714 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27716 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27717 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27718 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27719 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27720 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
27721 +#define AuOpt_DIO (1 << 14) /* direct io */
27722 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27724 +#ifndef CONFIG_AUFS_HNOTIFY
27725 +#undef AuOpt_UDBA_HNOTIFY
27726 +#define AuOpt_UDBA_HNOTIFY 0
27728 +#ifndef CONFIG_AUFS_DIRREN
27729 +#undef AuOpt_DIRREN
27730 +#define AuOpt_DIRREN 0
27732 +#ifndef CONFIG_AUFS_SHWH
27734 +#define AuOpt_SHWH 0
27737 +#define AuOpt_Def (AuOpt_XINO \
27738 + | AuOpt_UDBA_REVAL \
27740 + /* | AuOpt_DIRPERM1 */ \
27741 + | AuOpt_WARN_PERM)
27742 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27743 + | AuOpt_UDBA_REVAL \
27744 + | AuOpt_UDBA_HNOTIFY)
27746 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27747 +#define au_opt_set(flags, name) do { \
27748 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27749 + ((flags) |= AuOpt_##name); \
27751 +#define au_opt_set_udba(flags, name) do { \
27752 + (flags) &= ~AuOptMask_UDBA; \
27753 + ((flags) |= AuOpt_##name); \
27755 +#define au_opt_clr(flags, name) do { \
27756 + ((flags) &= ~AuOpt_##name); \
27759 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27761 +#ifdef CONFIG_PROC_FS
27764 + return mntflags & ~AuOpt_PLINK;
27768 +/* ---------------------------------------------------------------------- */
27770 +/* policies to select one among multiple writable branches */
27772 + AuWbrCreate_TDP, /* top down parent */
27773 + AuWbrCreate_RR, /* round robin */
27774 + AuWbrCreate_MFS, /* most free space */
27775 + AuWbrCreate_MFSV, /* mfs with seconds */
27776 + AuWbrCreate_MFSRR, /* mfs then rr */
27777 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27778 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27779 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27780 + AuWbrCreate_PMFS, /* parent and mfs */
27781 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27782 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27783 + AuWbrCreate_PMFSRRV, /* plus seconds */
27785 + AuWbrCreate_Def = AuWbrCreate_TDP
27789 + AuWbrCopyup_TDP, /* top down parent */
27790 + AuWbrCopyup_BUP, /* bottom up parent */
27791 + AuWbrCopyup_BU, /* bottom up */
27793 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27796 +/* ---------------------------------------------------------------------- */
27798 +struct au_opt_add {
27799 + aufs_bindex_t bindex;
27802 + struct path path;
27805 +struct au_opt_del {
27807 + struct path h_path;
27810 +struct au_opt_mod {
27813 + struct dentry *h_root;
27816 +struct au_opt_xino {
27818 + struct file *file;
27821 +struct au_opt_xino_itrunc {
27822 + aufs_bindex_t bindex;
27825 +struct au_opt_wbr_create {
27828 + unsigned long long mfsrr_watermark;
27834 + struct au_opt_xino xino;
27835 + struct au_opt_xino_itrunc xino_itrunc;
27836 + struct au_opt_add add;
27837 + struct au_opt_del del;
27838 + struct au_opt_mod mod;
27841 + unsigned int rdblk;
27842 + unsigned int rdhash;
27844 + struct au_opt_wbr_create wbr_create;
27846 + unsigned int fhsm_second;
27851 +#define AuOpts_REMOUNT 1
27852 +#define AuOpts_REFRESH (1 << 1)
27853 +#define AuOpts_TRUNC_XIB (1 << 2)
27854 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27855 +#define AuOpts_REFRESH_IDOP (1 << 4)
27856 +#define AuOpts_DR_FLUSHED (1 << 5)
27857 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27858 +#define au_fset_opts(flags, name) \
27859 + do { (flags) |= AuOpts_##name; } while (0)
27860 +#define au_fclr_opts(flags, name) \
27861 + do { (flags) &= ~AuOpts_##name; } while (0)
27863 +#ifndef CONFIG_AUFS_DIRREN
27864 +#undef AuOpts_DR_FLUSHED
27865 +#define AuOpts_DR_FLUSHED 0
27869 + struct au_opt *opt;
27872 + unsigned int given_udba;
27873 + unsigned int flags;
27874 + unsigned long sb_flags;
27877 +/* ---------------------------------------------------------------------- */
27880 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27881 +const char *au_optstr_udba(int udba);
27882 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27883 +const char *au_optstr_wbr_create(int wbr_create);
27885 +void au_opts_free(struct au_opts *opts);
27886 +struct super_block;
27887 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27888 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27889 + unsigned int pending);
27890 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27891 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27893 +unsigned int au_opt_udba(struct super_block *sb);
27895 +#endif /* __KERNEL__ */
27896 +#endif /* __AUFS_OPTS_H__ */
27897 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27898 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27899 +++ linux/fs/aufs/plink.c 2018-10-23 12:33:35.599375796 +0200
27901 +// SPDX-License-Identifier: GPL-2.0
27903 + * Copyright (C) 2005-2018 Junjiro R. Okajima
27905 + * This program, aufs is free software; you can redistribute it and/or modify
27906 + * it under the terms of the GNU General Public License as published by
27907 + * the Free Software Foundation; either version 2 of the License, or
27908 + * (at your option) any later version.
27910 + * This program is distributed in the hope that it will be useful,
27911 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27912 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27913 + * GNU General Public License for more details.
27915 + * You should have received a copy of the GNU General Public License
27916 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27926 + * the pseudo-link maintenance mode.
27927 + * during a user process maintains the pseudo-links,
27928 + * prohibit adding a new plink and branch manipulation.
27932 + * For entry functions which will handle plink, and i_mutex is already held
27934 + * They cannot wait and should return an error at once.
27935 + * Callers has to check the error.
27937 + * For entry functions which will handle plink, but i_mutex is not held
27939 + * They can wait the plink maintenance mode to finish.
27941 + * They behave like F_SETLK and F_SETLKW.
27942 + * If the caller never handle plink, then both flags are unnecessary.
27945 +int au_plink_maint(struct super_block *sb, int flags)
27949 + struct task_struct *parent, *prev;
27950 + struct au_sbinfo *sbi;
27952 + SiMustAnyLock(sb);
27955 + if (!au_opt_test(au_mntflags(sb), PLINK))
27958 + sbi = au_sbi(sb);
27959 + pid = sbi->si_plink_maint_pid;
27960 + if (!pid || pid == current->pid)
27963 + /* todo: it highly depends upon /sbin/mount.aufs */
27965 + parent = current;
27969 + parent = rcu_dereference(parent->real_parent);
27970 + if (parent == prev)
27972 + ppid = task_pid_vnr(parent);
27973 + if (pid == ppid) {
27974 + rcu_read_unlock();
27979 + rcu_read_unlock();
27981 + if (au_ftest_lock(flags, NOPLMW)) {
27982 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27983 + /* AuDebugOn(!lockdep_depth(current)); */
27984 + while (sbi->si_plink_maint_pid) {
27985 + si_read_unlock(sb);
27986 + /* gave up wake_up_bit() */
27987 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27989 + if (au_ftest_lock(flags, FLUSH))
27990 + au_nwt_flush(&sbi->si_nowait);
27991 + si_noflush_read_lock(sb);
27993 + } else if (au_ftest_lock(flags, NOPLM)) {
27994 + AuDbg("ppid %d, pid %d\n", ppid, pid);
28002 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
28004 + spin_lock(&sbinfo->si_plink_maint_lock);
28005 + sbinfo->si_plink_maint_pid = 0;
28006 + spin_unlock(&sbinfo->si_plink_maint_lock);
28007 + wake_up_all(&sbinfo->si_plink_wq);
28010 +int au_plink_maint_enter(struct super_block *sb)
28013 + struct au_sbinfo *sbinfo;
28016 + sbinfo = au_sbi(sb);
28017 + /* make sure i am the only one in this fs */
28018 + si_write_lock(sb, AuLock_FLUSH);
28019 + if (au_opt_test(au_mntflags(sb), PLINK)) {
28020 + spin_lock(&sbinfo->si_plink_maint_lock);
28021 + if (!sbinfo->si_plink_maint_pid)
28022 + sbinfo->si_plink_maint_pid = current->pid;
28025 + spin_unlock(&sbinfo->si_plink_maint_lock);
28027 + si_write_unlock(sb);
28032 +/* ---------------------------------------------------------------------- */
28034 +#ifdef CONFIG_AUFS_DEBUG
28035 +void au_plink_list(struct super_block *sb)
28038 + struct au_sbinfo *sbinfo;
28039 + struct hlist_bl_head *hbl;
28040 + struct hlist_bl_node *pos;
28041 + struct au_icntnr *icntnr;
28043 + SiMustAnyLock(sb);
28045 + sbinfo = au_sbi(sb);
28046 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28047 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28049 + for (i = 0; i < AuPlink_NHASH; i++) {
28050 + hbl = sbinfo->si_plink + i;
28051 + hlist_bl_lock(hbl);
28052 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28053 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
28054 + hlist_bl_unlock(hbl);
28059 +/* is the inode pseudo-linked? */
28060 +int au_plink_test(struct inode *inode)
28063 + struct au_sbinfo *sbinfo;
28064 + struct hlist_bl_head *hbl;
28065 + struct hlist_bl_node *pos;
28066 + struct au_icntnr *icntnr;
28068 + sbinfo = au_sbi(inode->i_sb);
28069 + AuRwMustAnyLock(&sbinfo->si_rwsem);
28070 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
28071 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28074 + i = au_plink_hash(inode->i_ino);
28075 + hbl = sbinfo->si_plink + i;
28076 + hlist_bl_lock(hbl);
28077 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28078 + if (&icntnr->vfs_inode == inode) {
28082 + hlist_bl_unlock(hbl);
28086 +/* ---------------------------------------------------------------------- */
28089 + * generate a name for plink.
28090 + * the file will be stored under AUFS_WH_PLINKDIR.
28092 +/* 20 is max digits length of ulong 64 */
28093 +#define PLINK_NAME_LEN ((20 + 1) * 2)
28095 +static int plink_name(char *name, int len, struct inode *inode,
28096 + aufs_bindex_t bindex)
28099 + struct inode *h_inode;
28101 + h_inode = au_h_iptr(inode, bindex);
28102 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28106 +struct au_do_plink_lkup_args {
28107 + struct dentry **errp;
28108 + struct qstr *tgtname;
28109 + struct dentry *h_parent;
28110 + struct au_branch *br;
28113 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28114 + struct dentry *h_parent,
28115 + struct au_branch *br)
28117 + struct dentry *h_dentry;
28118 + struct inode *h_inode;
28120 + h_inode = d_inode(h_parent);
28121 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28122 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
28123 + inode_unlock_shared(h_inode);
28127 +static void au_call_do_plink_lkup(void *args)
28129 + struct au_do_plink_lkup_args *a = args;
28130 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
28133 +/* lookup the plink-ed @inode under the branch at @bindex */
28134 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28136 + struct dentry *h_dentry, *h_parent;
28137 + struct au_branch *br;
28139 + char a[PLINK_NAME_LEN];
28140 + struct qstr tgtname = QSTR_INIT(a, 0);
28142 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28144 + br = au_sbr(inode->i_sb, bindex);
28145 + h_parent = br->br_wbr->wbr_plink;
28146 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28148 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28149 + struct au_do_plink_lkup_args args = {
28150 + .errp = &h_dentry,
28151 + .tgtname = &tgtname,
28152 + .h_parent = h_parent,
28156 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28157 + if (unlikely(wkq_err))
28158 + h_dentry = ERR_PTR(wkq_err);
28160 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
28165 +/* create a pseudo-link */
28166 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
28167 + struct dentry *h_dentry, struct au_branch *br)
28170 + struct path h_path = {
28171 + .mnt = au_br_mnt(br)
28173 + struct inode *h_dir, *delegated;
28175 + h_dir = d_inode(h_parent);
28176 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28178 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
28179 + err = PTR_ERR(h_path.dentry);
28180 + if (IS_ERR(h_path.dentry))
28184 + /* wh.plink dir is not monitored */
28185 + /* todo: is it really safe? */
28186 + if (d_is_positive(h_path.dentry)
28187 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28188 + delegated = NULL;
28189 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28190 + if (unlikely(err == -EWOULDBLOCK)) {
28191 + pr_warn("cannot retry for NFSv4 delegation"
28192 + " for an internal unlink\n");
28195 + dput(h_path.dentry);
28196 + h_path.dentry = NULL;
28200 + if (!err && d_is_negative(h_path.dentry)) {
28201 + delegated = NULL;
28202 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28203 + if (unlikely(err == -EWOULDBLOCK)) {
28204 + pr_warn("cannot retry for NFSv4 delegation"
28205 + " for an internal link\n");
28209 + dput(h_path.dentry);
28212 + inode_unlock(h_dir);
28216 +struct do_whplink_args {
28218 + struct qstr *tgt;
28219 + struct dentry *h_parent;
28220 + struct dentry *h_dentry;
28221 + struct au_branch *br;
28224 +static void call_do_whplink(void *args)
28226 + struct do_whplink_args *a = args;
28227 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
28230 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28231 + aufs_bindex_t bindex, struct au_branch *br)
28233 + int err, wkq_err;
28234 + struct au_wbr *wbr;
28235 + struct dentry *h_parent;
28236 + char a[PLINK_NAME_LEN];
28237 + struct qstr tgtname = QSTR_INIT(a, 0);
28239 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
28240 + h_parent = wbr->wbr_plink;
28241 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28243 + /* always superio. */
28244 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28245 + struct do_whplink_args args = {
28248 + .h_parent = h_parent,
28249 + .h_dentry = h_dentry,
28252 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28253 + if (unlikely(wkq_err))
28256 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
28262 + * create a new pseudo-link for @h_dentry on @bindex.
28263 + * the linked inode is held in aufs @inode.
28265 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28266 + struct dentry *h_dentry)
28268 + struct super_block *sb;
28269 + struct au_sbinfo *sbinfo;
28270 + struct hlist_bl_head *hbl;
28271 + struct hlist_bl_node *pos;
28272 + struct au_icntnr *icntnr;
28273 + int found, err, cnt, i;
28275 + sb = inode->i_sb;
28276 + sbinfo = au_sbi(sb);
28277 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28278 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28280 + found = au_plink_test(inode);
28284 + i = au_plink_hash(inode->i_ino);
28285 + hbl = sbinfo->si_plink + i;
28288 + hlist_bl_lock(hbl);
28289 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28290 + if (&icntnr->vfs_inode == inode) {
28296 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28297 + hlist_bl_add_head(&icntnr->plink, hbl);
28299 + hlist_bl_unlock(hbl);
28301 + cnt = au_hbl_count(hbl);
28302 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28303 + if (cnt > AUFS_PLINK_WARN)
28304 + AuWarn1(msg ", %d\n", cnt);
28306 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
28307 + if (unlikely(err)) {
28308 + pr_warn("err %d, damaged pseudo link.\n", err);
28309 + au_hbl_del(&icntnr->plink, hbl);
28310 + iput(&icntnr->vfs_inode);
28313 + iput(&icntnr->vfs_inode);
28316 +/* free all plinks */
28317 +void au_plink_put(struct super_block *sb, int verbose)
28320 + struct au_sbinfo *sbinfo;
28321 + struct hlist_bl_head *hbl;
28322 + struct hlist_bl_node *pos, *tmp;
28323 + struct au_icntnr *icntnr;
28325 + SiMustWriteLock(sb);
28327 + sbinfo = au_sbi(sb);
28328 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28329 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28331 + /* no spin_lock since sbinfo is write-locked */
28333 + for (i = 0; i < AuPlink_NHASH; i++) {
28334 + hbl = sbinfo->si_plink + i;
28335 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28336 + pr_warn("pseudo-link is not flushed");
28339 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28340 + iput(&icntnr->vfs_inode);
28341 + INIT_HLIST_BL_HEAD(hbl);
28345 +void au_plink_clean(struct super_block *sb, int verbose)
28347 + struct dentry *root;
28349 + root = sb->s_root;
28350 + aufs_write_lock(root);
28351 + if (au_opt_test(au_mntflags(sb), PLINK))
28352 + au_plink_put(sb, verbose);
28353 + aufs_write_unlock(root);
28356 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28359 + aufs_bindex_t btop, bbot, bindex;
28362 + btop = au_ibtop(inode);
28363 + bbot = au_ibbot(inode);
28365 + for (bindex = btop; bindex <= bbot; bindex++) {
28366 + if (!au_h_iptr(inode, bindex)
28367 + || au_ii_br_id(inode, bindex) != br_id)
28369 + au_set_h_iptr(inode, bindex, NULL, 0);
28374 + for (bindex = btop; bindex <= bbot; bindex++)
28375 + if (au_h_iptr(inode, bindex)) {
28385 +/* free the plinks on a branch specified by @br_id */
28386 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28388 + struct au_sbinfo *sbinfo;
28389 + struct hlist_bl_head *hbl;
28390 + struct hlist_bl_node *pos, *tmp;
28391 + struct au_icntnr *icntnr;
28392 + struct inode *inode;
28395 + SiMustWriteLock(sb);
28397 + sbinfo = au_sbi(sb);
28398 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28399 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28401 + /* no bit_lock since sbinfo is write-locked */
28402 + for (i = 0; i < AuPlink_NHASH; i++) {
28403 + hbl = sbinfo->si_plink + i;
28404 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28405 + inode = au_igrab(&icntnr->vfs_inode);
28406 + ii_write_lock_child(inode);
28407 + do_put = au_plink_do_half_refresh(inode, br_id);
28409 + hlist_bl_del(&icntnr->plink);
28412 + ii_write_unlock(inode);
28417 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28418 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28419 +++ linux/fs/aufs/poll.c 2018-08-12 23:43:05.460124736 +0200
28421 +// SPDX-License-Identifier: GPL-2.0
28423 + * Copyright (C) 2005-2018 Junjiro R. Okajima
28425 + * This program, aufs is free software; you can redistribute it and/or modify
28426 + * it under the terms of the GNU General Public License as published by
28427 + * the Free Software Foundation; either version 2 of the License, or
28428 + * (at your option) any later version.
28430 + * This program is distributed in the hope that it will be useful,
28431 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28432 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28433 + * GNU General Public License for more details.
28435 + * You should have received a copy of the GNU General Public License
28436 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28441 + * There is only one filesystem which implements ->poll operation, currently.
28446 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28449 + struct file *h_file;
28450 + struct super_block *sb;
28452 + /* We should pretend an error happened. */
28453 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28454 + sb = file->f_path.dentry->d_sb;
28455 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28457 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28458 + if (IS_ERR(h_file)) {
28459 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28463 + mask = vfs_poll(h_file, pt);
28464 + fput(h_file); /* instead of au_read_post() */
28467 + si_read_unlock(sb);
28468 + if (mask & EPOLLERR)
28469 + AuDbg("mask 0x%x\n", mask);
28472 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28473 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28474 +++ linux/fs/aufs/posix_acl.c 2018-08-12 23:43:05.460124736 +0200
28476 +// SPDX-License-Identifier: GPL-2.0
28478 + * Copyright (C) 2014-2018 Junjiro R. Okajima
28480 + * This program, aufs is free software; you can redistribute it and/or modify
28481 + * it under the terms of the GNU General Public License as published by
28482 + * the Free Software Foundation; either version 2 of the License, or
28483 + * (at your option) any later version.
28485 + * This program is distributed in the hope that it will be useful,
28486 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28487 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28488 + * GNU General Public License for more details.
28490 + * You should have received a copy of the GNU General Public License
28491 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28495 + * posix acl operations
28498 +#include <linux/fs.h>
28501 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28503 + struct posix_acl *acl;
28505 + aufs_bindex_t bindex;
28506 + struct inode *h_inode;
28507 + struct super_block *sb;
28510 + sb = inode->i_sb;
28511 + si_read_lock(sb, AuLock_FLUSH);
28512 + ii_read_lock_child(inode);
28513 + if (!(sb->s_flags & SB_POSIXACL))
28516 + bindex = au_ibtop(inode);
28517 + h_inode = au_h_iptr(inode, bindex);
28518 + if (unlikely(!h_inode
28519 + || ((h_inode->i_mode & S_IFMT)
28520 + != (inode->i_mode & S_IFMT)))) {
28521 + err = au_busy_or_stale();
28522 + acl = ERR_PTR(err);
28526 + /* always topmost only */
28527 + acl = get_acl(h_inode, type);
28528 + if (!IS_ERR_OR_NULL(acl))
28529 + set_cached_acl(inode, type, acl);
28532 + ii_read_unlock(inode);
28533 + si_read_unlock(sb);
28535 + AuTraceErrPtr(acl);
28539 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28543 + struct dentry *dentry;
28544 + struct au_sxattr arg = {
28545 + .type = AU_ACL_SET,
28552 + IMustLock(inode);
28554 + if (inode->i_ino == AUFS_ROOT_INO)
28555 + dentry = dget(inode->i_sb->s_root);
28557 + dentry = d_find_alias(inode);
28559 + dentry = d_find_any_alias(inode);
28561 + pr_warn("cannot handle this inode, "
28562 + "please report to aufs-users ML\n");
28568 + ssz = au_sxattr(dentry, inode, &arg);
28573 + set_cached_acl(inode, type, acl);
28579 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28580 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28581 +++ linux/fs/aufs/procfs.c 2018-08-12 23:43:05.460124736 +0200
28583 +// SPDX-License-Identifier: GPL-2.0
28585 + * Copyright (C) 2010-2018 Junjiro R. Okajima
28587 + * This program, aufs is free software; you can redistribute it and/or modify
28588 + * it under the terms of the GNU General Public License as published by
28589 + * the Free Software Foundation; either version 2 of the License, or
28590 + * (at your option) any later version.
28592 + * This program is distributed in the hope that it will be useful,
28593 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28594 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28595 + * GNU General Public License for more details.
28597 + * You should have received a copy of the GNU General Public License
28598 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28602 + * procfs interfaces
28605 +#include <linux/proc_fs.h>
28608 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28610 + struct au_sbinfo *sbinfo;
28612 + sbinfo = file->private_data;
28614 + au_plink_maint_leave(sbinfo);
28615 + kobject_put(&sbinfo->si_kobj);
28621 +static void au_procfs_plm_write_clean(struct file *file)
28623 + struct au_sbinfo *sbinfo;
28625 + sbinfo = file->private_data;
28627 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28630 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28633 + struct super_block *sb;
28634 + struct au_sbinfo *sbinfo;
28635 + struct hlist_bl_node *pos;
28638 + if (unlikely(file->private_data))
28642 + /* don't use au_sbilist_lock() here */
28643 + hlist_bl_lock(&au_sbilist);
28644 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28645 + if (id == sysaufs_si_id(sbinfo)) {
28646 + kobject_get(&sbinfo->si_kobj);
28647 + sb = sbinfo->si_sb;
28650 + hlist_bl_unlock(&au_sbilist);
28653 + if (unlikely(!sb))
28656 + err = au_plink_maint_enter(sb);
28658 + /* keep kobject_get() */
28659 + file->private_data = sbinfo;
28661 + kobject_put(&sbinfo->si_kobj);
28667 + * Accept a valid "si=xxxx" only.
28668 + * Once it is accepted successfully, accept "clean" too.
28670 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28671 + size_t count, loff_t *ppos)
28674 + unsigned long id;
28675 + /* last newline is allowed */
28676 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28679 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28683 + if (unlikely(count > sizeof(buf)))
28686 + err = copy_from_user(buf, ubuf, count);
28687 + if (unlikely(err)) {
28694 + if (!strcmp("clean", buf)) {
28695 + au_procfs_plm_write_clean(file);
28696 + goto out_success;
28697 + } else if (unlikely(strncmp("si=", buf, 3)))
28700 + err = kstrtoul(buf + 3, 16, &id);
28701 + if (unlikely(err))
28704 + err = au_procfs_plm_write_si(file, id);
28705 + if (unlikely(err))
28709 + err = count; /* success */
28714 +static const struct file_operations au_procfs_plm_fop = {
28715 + .write = au_procfs_plm_write,
28716 + .release = au_procfs_plm_release,
28717 + .owner = THIS_MODULE
28720 +/* ---------------------------------------------------------------------- */
28722 +static struct proc_dir_entry *au_procfs_dir;
28724 +void au_procfs_fin(void)
28726 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28727 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28730 +int __init au_procfs_init(void)
28733 + struct proc_dir_entry *entry;
28736 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28737 + if (unlikely(!au_procfs_dir))
28740 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28741 + au_procfs_dir, &au_procfs_plm_fop);
28742 + if (unlikely(!entry))
28746 + goto out; /* success */
28750 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28754 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28755 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28756 +++ linux/fs/aufs/rdu.c 2018-08-12 23:43:05.463458173 +0200
28758 +// SPDX-License-Identifier: GPL-2.0
28760 + * Copyright (C) 2005-2018 Junjiro R. Okajima
28762 + * This program, aufs is free software; you can redistribute it and/or modify
28763 + * it under the terms of the GNU General Public License as published by
28764 + * the Free Software Foundation; either version 2 of the License, or
28765 + * (at your option) any later version.
28767 + * This program is distributed in the hope that it will be useful,
28768 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28769 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28770 + * GNU General Public License for more details.
28772 + * You should have received a copy of the GNU General Public License
28773 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28777 + * readdir in userspace.
28780 +#include <linux/compat.h>
28781 +#include <linux/fs_stack.h>
28782 +#include <linux/security.h>
28785 +/* bits for struct aufs_rdu.flags */
28786 +#define AuRdu_CALLED 1
28787 +#define AuRdu_CONT (1 << 1)
28788 +#define AuRdu_FULL (1 << 2)
28789 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28790 +#define au_fset_rdu(flags, name) \
28791 + do { (flags) |= AuRdu_##name; } while (0)
28792 +#define au_fclr_rdu(flags, name) \
28793 + do { (flags) &= ~AuRdu_##name; } while (0)
28795 +struct au_rdu_arg {
28796 + struct dir_context ctx;
28797 + struct aufs_rdu *rdu;
28798 + union au_rdu_ent_ul ent;
28799 + unsigned long end;
28801 + struct super_block *sb;
28805 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28806 + loff_t offset, u64 h_ino, unsigned int d_type)
28809 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28810 + struct aufs_rdu *rdu = arg->rdu;
28811 + struct au_rdu_ent ent;
28815 + au_fset_rdu(rdu->cookie.flags, CALLED);
28816 + len = au_rdu_len(nlen);
28817 + if (arg->ent.ul + len < arg->end) {
28819 + ent.bindex = rdu->cookie.bindex;
28820 + ent.type = d_type;
28822 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28823 + ent.type = DT_UNKNOWN;
28825 + /* unnecessary to support mmap_sem since this is a dir */
28827 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28829 + if (copy_to_user(arg->ent.e->name, name, nlen))
28831 + /* the terminating NULL */
28832 + if (__put_user(0, arg->ent.e->name + nlen))
28835 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28836 + arg->ent.ul += len;
28840 + au_fset_rdu(rdu->cookie.flags, FULL);
28842 + rdu->tail = arg->ent;
28846 + /* AuTraceErr(err); */
28850 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28854 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28856 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28857 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28859 + if (unlikely(offset != cookie->h_pos))
28865 + au_fclr_rdu(cookie->flags, CALLED);
28867 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28871 + && au_ftest_rdu(cookie->flags, CALLED)
28872 + && !au_ftest_rdu(cookie->flags, FULL));
28873 + cookie->h_pos = h_file->f_pos;
28880 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28883 + aufs_bindex_t bbot;
28884 + struct au_rdu_arg arg = {
28886 + .actor = au_rdu_fill
28889 + struct dentry *dentry;
28890 + struct inode *inode;
28891 + struct file *h_file;
28892 + struct au_rdu_cookie *cookie = &rdu->cookie;
28894 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
28895 + if (unlikely(err)) {
28901 + rdu->tail = rdu->ent;
28904 + arg.ent = rdu->ent;
28905 + arg.end = arg.ent.ul;
28906 + arg.end += rdu->sz;
28909 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28912 + err = security_file_permission(file, MAY_READ);
28914 + if (unlikely(err))
28917 + dentry = file->f_path.dentry;
28918 + inode = d_inode(dentry);
28919 + inode_lock_shared(inode);
28921 + arg.sb = inode->i_sb;
28922 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28923 + if (unlikely(err))
28925 + err = au_alive_dir(dentry);
28926 + if (unlikely(err))
28928 + /* todo: reval? */
28929 + fi_read_lock(file);
28932 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28933 + && cookie->generation != au_figen(file)))
28938 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28940 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28942 + bbot = au_fbtop(file);
28943 + if (cookie->bindex < bbot)
28944 + cookie->bindex = bbot;
28945 + bbot = au_fbbot_dir(file);
28946 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28947 + for (; !err && cookie->bindex <= bbot;
28948 + cookie->bindex++, cookie->h_pos = 0) {
28949 + h_file = au_hf_dir(file, cookie->bindex);
28953 + au_fclr_rdu(cookie->flags, FULL);
28954 + err = au_rdu_do(h_file, &arg);
28956 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28959 + AuDbg("rent %llu\n", rdu->rent);
28961 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28962 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28963 + au_fset_rdu(cookie->flags, CONT);
28964 + cookie->generation = au_figen(file);
28967 + ii_read_lock_child(inode);
28968 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28969 + ii_read_unlock(inode);
28972 + fi_read_unlock(file);
28974 + si_read_unlock(arg.sb);
28976 + inode_unlock_shared(inode);
28982 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28986 + unsigned long long nent;
28987 + union au_rdu_ent_ul *u;
28988 + struct au_rdu_ent ent;
28989 + struct super_block *sb;
28992 + nent = rdu->nent;
28994 + sb = file->f_path.dentry->d_sb;
28995 + si_read_lock(sb, AuLock_FLUSH);
28996 + while (nent-- > 0) {
28997 + /* unnecessary to support mmap_sem since this is a dir */
28998 + err = copy_from_user(&ent, u->e, sizeof(ent));
29000 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
29001 + if (unlikely(err)) {
29007 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
29009 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
29011 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
29013 + if (unlikely(err)) {
29018 + err = __put_user(ino, &u->e->ino);
29019 + if (unlikely(err)) {
29024 + u->ul += au_rdu_len(ent.nlen);
29026 + si_read_unlock(sb);
29031 +/* ---------------------------------------------------------------------- */
29033 +static int au_rdu_verify(struct aufs_rdu *rdu)
29035 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
29036 + "%llu, b%d, 0x%x, g%u}\n",
29037 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
29039 + rdu->rent, rdu->shwh, rdu->full,
29040 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
29041 + rdu->cookie.generation);
29043 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
29047 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
29051 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29054 + struct aufs_rdu rdu;
29055 + void __user *p = (void __user *)arg;
29057 + err = copy_from_user(&rdu, p, sizeof(rdu));
29058 + if (unlikely(err)) {
29063 + err = au_rdu_verify(&rdu);
29064 + if (unlikely(err))
29068 + case AUFS_CTL_RDU:
29069 + err = au_rdu(file, &rdu);
29070 + if (unlikely(err))
29073 + e = copy_to_user(p, &rdu, sizeof(rdu));
29074 + if (unlikely(e)) {
29079 + case AUFS_CTL_RDU_INO:
29080 + err = au_rdu_ino(file, &rdu);
29084 + /* err = -ENOTTY; */
29093 +#ifdef CONFIG_COMPAT
29094 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29097 + struct aufs_rdu rdu;
29098 + void __user *p = compat_ptr(arg);
29100 + /* todo: get_user()? */
29101 + err = copy_from_user(&rdu, p, sizeof(rdu));
29102 + if (unlikely(err)) {
29107 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29108 + err = au_rdu_verify(&rdu);
29109 + if (unlikely(err))
29113 + case AUFS_CTL_RDU:
29114 + err = au_rdu(file, &rdu);
29115 + if (unlikely(err))
29118 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29119 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29120 + e = copy_to_user(p, &rdu, sizeof(rdu));
29121 + if (unlikely(e)) {
29126 + case AUFS_CTL_RDU_INO:
29127 + err = au_rdu_ino(file, &rdu);
29131 + /* err = -ENOTTY; */
29140 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29141 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29142 +++ linux/fs/aufs/rwsem.h 2018-10-23 12:33:35.599375796 +0200
29144 +/* SPDX-License-Identifier: GPL-2.0 */
29146 + * Copyright (C) 2005-2018 Junjiro R. Okajima
29148 + * This program, aufs is free software; you can redistribute it and/or modify
29149 + * it under the terms of the GNU General Public License as published by
29150 + * the Free Software Foundation; either version 2 of the License, or
29151 + * (at your option) any later version.
29153 + * This program is distributed in the hope that it will be useful,
29154 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29155 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29156 + * GNU General Public License for more details.
29158 + * You should have received a copy of the GNU General Public License
29159 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29163 + * simple read-write semaphore wrappers
29166 +#ifndef __AUFS_RWSEM_H__
29167 +#define __AUFS_RWSEM_H__
29171 +#include "debug.h"
29173 +/* in the future, the name 'au_rwsem' will be totally gone */
29174 +#define au_rwsem rw_semaphore
29176 +/* to debug easier, do not make them inlined functions */
29177 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29178 +/* rwsem_is_locked() is unusable */
29179 +#define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \
29181 + && !lockdep_is_held_type(rw, 1))
29182 +#define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \
29184 + && !lockdep_is_held_type(rw, 0))
29185 +#define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \
29187 + && !lockdep_is_held(rw))
29188 +#define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \
29190 + && lockdep_is_held(rw))
29192 +#define au_rw_init(rw) init_rwsem(rw)
29194 +#define au_rw_init_wlock(rw) do { \
29195 + au_rw_init(rw); \
29196 + down_write(rw); \
29199 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29200 + au_rw_init(rw); \
29201 + down_write_nested(rw, lsc); \
29204 +#define au_rw_read_lock(rw) down_read(rw)
29205 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29206 +#define au_rw_read_unlock(rw) up_read(rw)
29207 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29208 +#define au_rw_write_lock(rw) down_write(rw)
29209 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29210 +#define au_rw_write_unlock(rw) up_write(rw)
29211 +/* why is not _nested version defined? */
29212 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29213 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29215 +#endif /* __KERNEL__ */
29216 +#endif /* __AUFS_RWSEM_H__ */
29217 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29218 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29219 +++ linux/fs/aufs/sbinfo.c 2018-12-27 13:19:17.711749485 +0100
29221 +// SPDX-License-Identifier: GPL-2.0
29223 + * Copyright (C) 2005-2018 Junjiro R. Okajima
29225 + * This program, aufs is free software; you can redistribute it and/or modify
29226 + * it under the terms of the GNU General Public License as published by
29227 + * the Free Software Foundation; either version 2 of the License, or
29228 + * (at your option) any later version.
29230 + * This program is distributed in the hope that it will be useful,
29231 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29232 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29233 + * GNU General Public License for more details.
29235 + * You should have received a copy of the GNU General Public License
29236 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29240 + * superblock private data
29246 + * they are necessary regardless sysfs is disabled.
29248 +void au_si_free(struct kobject *kobj)
29251 + struct au_sbinfo *sbinfo;
29252 + char *locked __maybe_unused; /* debug only */
29254 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29255 + for (i = 0; i < AuPlink_NHASH; i++)
29256 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29257 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29259 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29260 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29261 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29262 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29264 + dbgaufs_si_fin(sbinfo);
29265 + au_rw_write_lock(&sbinfo->si_rwsem);
29266 + au_br_free(sbinfo);
29267 + au_rw_write_unlock(&sbinfo->si_rwsem);
29269 + au_kfree_try_rcu(sbinfo->si_branch);
29270 + mutex_destroy(&sbinfo->si_xib_mtx);
29271 + AuRwDestroy(&sbinfo->si_rwsem);
29273 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29274 + /* si_nfiles is waited too */
29275 + au_kfree_rcu(sbinfo);
29278 +int au_si_alloc(struct super_block *sb)
29281 + struct au_sbinfo *sbinfo;
29284 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29285 + if (unlikely(!sbinfo))
29288 + /* will be reallocated separately */
29289 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29290 + if (unlikely(!sbinfo->si_branch))
29293 + err = sysaufs_si_init(sbinfo);
29295 + dbgaufs_si_null(sbinfo);
29296 + err = dbgaufs_si_init(sbinfo);
29297 + if (unlikely(err))
29298 + kobject_put(&sbinfo->si_kobj);
29300 + if (unlikely(err))
29303 + au_nwt_init(&sbinfo->si_nowait);
29304 + au_rw_init_wlock(&sbinfo->si_rwsem);
29306 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29307 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29309 + sbinfo->si_bbot = -1;
29310 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29312 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29313 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29314 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29315 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29317 + au_fhsm_init(sbinfo);
29319 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29321 + sbinfo->si_xino_jiffy = jiffies;
29322 + sbinfo->si_xino_expire
29323 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29324 + mutex_init(&sbinfo->si_xib_mtx);
29325 + /* leave si_xib_last_pindex and si_xib_next_bit */
29327 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29329 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29330 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29331 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29332 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29334 + for (i = 0; i < AuPlink_NHASH; i++)
29335 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29336 + init_waitqueue_head(&sbinfo->si_plink_wq);
29337 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29339 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29341 + /* with getattr by default */
29342 + sbinfo->si_iop_array = aufs_iop;
29344 + /* leave other members for sysaufs and si_mnt. */
29345 + sbinfo->si_sb = sb;
29346 + sb->s_fs_info = sbinfo;
29348 + return 0; /* success */
29351 + au_kfree_try_rcu(sbinfo->si_branch);
29353 + au_kfree_rcu(sbinfo);
29358 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29361 + struct au_branch **brp;
29363 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29366 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29367 + if (unlikely(!sz))
29368 + sz = sizeof(*brp);
29369 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29372 + sbinfo->si_branch = brp;
29379 +/* ---------------------------------------------------------------------- */
29381 +unsigned int au_sigen_inc(struct super_block *sb)
29383 + unsigned int gen;
29384 + struct inode *inode;
29386 + SiMustWriteLock(sb);
29388 + gen = ++au_sbi(sb)->si_generation;
29389 + au_update_digen(sb->s_root);
29390 + inode = d_inode(sb->s_root);
29391 + au_update_iigen(inode, /*half*/0);
29392 + inode_inc_iversion(inode);
29396 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29398 + aufs_bindex_t br_id;
29400 + struct au_sbinfo *sbinfo;
29402 + SiMustWriteLock(sb);
29404 + sbinfo = au_sbi(sb);
29405 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29406 + br_id = ++sbinfo->si_last_br_id;
29407 + AuDebugOn(br_id < 0);
29408 + if (br_id && au_br_index(sb, br_id) < 0)
29415 +/* ---------------------------------------------------------------------- */
29417 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29418 +int si_read_lock(struct super_block *sb, int flags)
29423 + if (au_ftest_lock(flags, FLUSH))
29424 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29426 + si_noflush_read_lock(sb);
29427 + err = au_plink_maint(sb, flags);
29428 + if (unlikely(err))
29429 + si_read_unlock(sb);
29434 +int si_write_lock(struct super_block *sb, int flags)
29438 + if (au_ftest_lock(flags, FLUSH))
29439 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29441 + si_noflush_write_lock(sb);
29442 + err = au_plink_maint(sb, flags);
29443 + if (unlikely(err))
29444 + si_write_unlock(sb);
29449 +/* dentry and super_block lock. call at entry point */
29450 +int aufs_read_lock(struct dentry *dentry, int flags)
29453 + struct super_block *sb;
29455 + sb = dentry->d_sb;
29456 + err = si_read_lock(sb, flags);
29457 + if (unlikely(err))
29460 + if (au_ftest_lock(flags, DW))
29461 + di_write_lock_child(dentry);
29463 + di_read_lock_child(dentry, flags);
29465 + if (au_ftest_lock(flags, GEN)) {
29466 + err = au_digen_test(dentry, au_sigen(sb));
29467 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29468 + AuDebugOn(!err && au_dbrange_test(dentry));
29470 + err = au_dbrange_test(dentry);
29471 + if (unlikely(err))
29472 + aufs_read_unlock(dentry, flags);
29479 +void aufs_read_unlock(struct dentry *dentry, int flags)
29481 + if (au_ftest_lock(flags, DW))
29482 + di_write_unlock(dentry);
29484 + di_read_unlock(dentry, flags);
29485 + si_read_unlock(dentry->d_sb);
29488 +void aufs_write_lock(struct dentry *dentry)
29490 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29491 + di_write_lock_child(dentry);
29494 +void aufs_write_unlock(struct dentry *dentry)
29496 + di_write_unlock(dentry);
29497 + si_write_unlock(dentry->d_sb);
29500 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29503 + unsigned int sigen;
29504 + struct super_block *sb;
29507 + err = si_read_lock(sb, flags);
29508 + if (unlikely(err))
29511 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29513 + if (au_ftest_lock(flags, GEN)) {
29514 + sigen = au_sigen(sb);
29515 + err = au_digen_test(d1, sigen);
29516 + AuDebugOn(!err && au_dbrange_test(d1));
29518 + err = au_digen_test(d2, sigen);
29519 + AuDebugOn(!err && au_dbrange_test(d2));
29521 + if (unlikely(err))
29522 + aufs_read_and_write_unlock2(d1, d2);
29529 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29531 + di_write_unlock2(d1, d2);
29532 + si_read_unlock(d1->d_sb);
29534 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29535 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29536 +++ linux/fs/aufs/super.c 2018-10-23 12:33:35.599375796 +0200
29538 +// SPDX-License-Identifier: GPL-2.0
29540 + * Copyright (C) 2005-2018 Junjiro R. Okajima
29542 + * This program, aufs is free software; you can redistribute it and/or modify
29543 + * it under the terms of the GNU General Public License as published by
29544 + * the Free Software Foundation; either version 2 of the License, or
29545 + * (at your option) any later version.
29547 + * This program is distributed in the hope that it will be useful,
29548 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29549 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29550 + * GNU General Public License for more details.
29552 + * You should have received a copy of the GNU General Public License
29553 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29557 + * mount and super_block operations
29560 +#include <linux/mm.h>
29561 +#include <linux/seq_file.h>
29562 +#include <linux/statfs.h>
29563 +#include <linux/vmalloc.h>
29567 + * super_operations
29569 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29571 + struct au_icntnr *c;
29573 + c = au_cache_alloc_icntnr();
29575 + au_icntnr_init(c);
29576 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29577 + c->iinfo.ii_hinode = NULL;
29578 + return &c->vfs_inode;
29583 +static void aufs_destroy_inode_cb(struct rcu_head *head)
29585 + struct inode *inode = container_of(head, struct inode, i_rcu);
29587 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29590 +static void aufs_destroy_inode(struct inode *inode)
29592 + if (!au_is_bad_inode(inode))
29593 + au_iinfo_fin(inode);
29594 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
29597 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29599 + struct inode *inode;
29602 + inode = iget_locked(sb, ino);
29603 + if (unlikely(!inode)) {
29604 + inode = ERR_PTR(-ENOMEM);
29607 + if (!(inode->i_state & I_NEW))
29610 + err = au_xigen_new(inode);
29612 + err = au_iinfo_init(inode);
29614 + inode_inc_iversion(inode);
29616 + iget_failed(inode);
29617 + inode = ERR_PTR(err);
29621 + /* never return NULL */
29622 + AuDebugOn(!inode);
29623 + AuTraceErrPtr(inode);
29627 +/* lock free root dinfo */
29628 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29631 + aufs_bindex_t bindex, bbot;
29632 + struct path path;
29633 + struct au_hdentry *hdp;
29634 + struct au_branch *br;
29635 + au_br_perm_str_t perm;
29638 + bbot = au_sbbot(sb);
29640 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29641 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29642 + br = au_sbr(sb, bindex);
29643 + path.mnt = au_br_mnt(br);
29644 + path.dentry = hdp->hd_dentry;
29645 + err = au_seq_path(seq, &path);
29647 + au_optstr_br_perm(&perm, br->br_perm);
29648 + seq_printf(seq, "=%s", perm.a);
29649 + if (bindex != bbot)
29650 + seq_putc(seq, ':');
29653 + if (unlikely(err || seq_has_overflowed(seq)))
29659 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29660 + const char *append)
29665 + while (*pat != ':')
29668 + strcpy(p, append);
29669 + AuDebugOn(strlen(fmt) >= len);
29672 +static void au_show_wbr_create(struct seq_file *m, int v,
29673 + struct au_sbinfo *sbinfo)
29677 + struct au_wbr_mfs *mfs;
29679 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29681 + seq_puts(m, ",create=");
29682 + pat = au_optstr_wbr_create(v);
29683 + mfs = &sbinfo->si_wbr_mfs;
29685 + case AuWbrCreate_TDP:
29686 + case AuWbrCreate_RR:
29687 + case AuWbrCreate_MFS:
29688 + case AuWbrCreate_PMFS:
29689 + seq_puts(m, pat);
29691 + case AuWbrCreate_MFSRR:
29692 + case AuWbrCreate_TDMFS:
29693 + case AuWbrCreate_PMFSRR:
29694 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29695 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29697 + case AuWbrCreate_MFSV:
29698 + case AuWbrCreate_PMFSV:
29699 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29700 + seq_printf(m, fmt,
29701 + jiffies_to_msecs(mfs->mfs_expire)
29704 + case AuWbrCreate_MFSRRV:
29705 + case AuWbrCreate_TDMFSV:
29706 + case AuWbrCreate_PMFSRRV:
29707 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29708 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29709 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29716 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29718 +#ifdef CONFIG_SYSFS
29722 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29723 + aufs_bindex_t bindex, brid;
29724 + struct qstr *name;
29726 + struct dentry *d, *h_root;
29727 + struct au_branch *br;
29729 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29732 + f = au_sbi(sb)->si_xib;
29736 + /* stop printing the default xino path on the first writable branch */
29738 + bindex = au_xi_root(sb, f->f_path.dentry);
29739 + if (bindex >= 0) {
29740 + br = au_sbr_sb(sb, bindex);
29741 + h_root = au_br_dentry(br);
29744 + d = f->f_path.dentry;
29745 + name = &d->d_name;
29746 + /* safe ->d_parent because the file is unlinked */
29747 + if (d->d_parent == h_root
29748 + && name->len == len
29749 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29752 + seq_puts(seq, ",xino=");
29753 + err = au_xino_path(seq, f);
29760 +/* seq_file will re-call me in case of too long string */
29761 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29764 + unsigned int mnt_flags, v;
29765 + struct super_block *sb;
29766 + struct au_sbinfo *sbinfo;
29768 +#define AuBool(name, str) do { \
29769 + v = au_opt_test(mnt_flags, name); \
29770 + if (v != au_opt_test(AuOpt_Def, name)) \
29771 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29774 +#define AuStr(name, str) do { \
29775 + v = mnt_flags & AuOptMask_##name; \
29776 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29777 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29780 +#define AuUInt(name, str, val) do { \
29781 + if (val != AUFS_##name##_DEF) \
29782 + seq_printf(m, "," #str "=%u", val); \
29785 + sb = dentry->d_sb;
29786 + if (sb->s_flags & SB_POSIXACL)
29787 + seq_puts(m, ",acl");
29789 + if (sb->s_flags & SB_I_VERSION)
29790 + seq_puts(m, ",i_version");
29793 + /* lock free root dinfo */
29794 + si_noflush_read_lock(sb);
29795 + sbinfo = au_sbi(sb);
29796 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29798 + mnt_flags = au_mntflags(sb);
29799 + if (au_opt_test(mnt_flags, XINO)) {
29800 + err = au_show_xino(m, sb);
29801 + if (unlikely(err))
29804 + seq_puts(m, ",noxino");
29806 + AuBool(TRUNC_XINO, trunc_xino);
29807 + AuStr(UDBA, udba);
29808 + AuBool(SHWH, shwh);
29809 + AuBool(PLINK, plink);
29810 + AuBool(DIO, dio);
29811 + AuBool(DIRPERM1, dirperm1);
29813 + v = sbinfo->si_wbr_create;
29814 + if (v != AuWbrCreate_Def)
29815 + au_show_wbr_create(m, v, sbinfo);
29817 + v = sbinfo->si_wbr_copyup;
29818 + if (v != AuWbrCopyup_Def)
29819 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29821 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29822 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29823 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29825 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29827 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29828 + AuUInt(RDCACHE, rdcache, v);
29830 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29831 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29833 + au_fhsm_show(m, sbinfo);
29835 + AuBool(DIRREN, dirren);
29836 + AuBool(SUM, sum);
29837 + /* AuBool(SUM_W, wsum); */
29838 + AuBool(WARN_PERM, warn_perm);
29839 + AuBool(VERBOSE, verbose);
29842 + /* be sure to print "br:" last */
29843 + if (!sysaufs_brs) {
29844 + seq_puts(m, ",br:");
29845 + au_show_brs(m, sb);
29847 + si_read_unlock(sb);
29855 +/* ---------------------------------------------------------------------- */
29857 +/* sum mode which returns the summation for statfs(2) */
29859 +static u64 au_add_till_max(u64 a, u64 b)
29867 + return ULLONG_MAX;
29870 +static u64 au_mul_till_max(u64 a, long mul)
29878 + return ULLONG_MAX;
29881 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29884 + long bsize, factor;
29885 + u64 blocks, bfree, bavail, files, ffree;
29886 + aufs_bindex_t bbot, bindex, i;
29887 + unsigned char shared;
29888 + struct path h_path;
29889 + struct super_block *h_sb;
29892 + bsize = LONG_MAX;
29898 + bbot = au_sbbot(sb);
29899 + for (bindex = 0; bindex <= bbot; bindex++) {
29900 + h_path.mnt = au_sbr_mnt(sb, bindex);
29901 + h_sb = h_path.mnt->mnt_sb;
29903 + for (i = 0; !shared && i < bindex; i++)
29904 + shared = (au_sbr_sb(sb, i) == h_sb);
29908 + /* sb->s_root for NFS is unreliable */
29909 + h_path.dentry = h_path.mnt->mnt_root;
29910 + err = vfs_statfs(&h_path, buf);
29911 + if (unlikely(err))
29914 + if (bsize > buf->f_bsize) {
29916 + * we will reduce bsize, so we have to expand blocks
29917 + * etc. to match them again
29919 + factor = (bsize / buf->f_bsize);
29920 + blocks = au_mul_till_max(blocks, factor);
29921 + bfree = au_mul_till_max(bfree, factor);
29922 + bavail = au_mul_till_max(bavail, factor);
29923 + bsize = buf->f_bsize;
29926 + factor = (buf->f_bsize / bsize);
29927 + blocks = au_add_till_max(blocks,
29928 + au_mul_till_max(buf->f_blocks, factor));
29929 + bfree = au_add_till_max(bfree,
29930 + au_mul_till_max(buf->f_bfree, factor));
29931 + bavail = au_add_till_max(bavail,
29932 + au_mul_till_max(buf->f_bavail, factor));
29933 + files = au_add_till_max(files, buf->f_files);
29934 + ffree = au_add_till_max(ffree, buf->f_ffree);
29937 + buf->f_bsize = bsize;
29938 + buf->f_blocks = blocks;
29939 + buf->f_bfree = bfree;
29940 + buf->f_bavail = bavail;
29941 + buf->f_files = files;
29942 + buf->f_ffree = ffree;
29943 + buf->f_frsize = 0;
29949 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29952 + struct path h_path;
29953 + struct super_block *sb;
29955 + /* lock free root dinfo */
29956 + sb = dentry->d_sb;
29957 + si_noflush_read_lock(sb);
29958 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29959 + /* sb->s_root for NFS is unreliable */
29960 + h_path.mnt = au_sbr_mnt(sb, 0);
29961 + h_path.dentry = h_path.mnt->mnt_root;
29962 + err = vfs_statfs(&h_path, buf);
29964 + err = au_statfs_sum(sb, buf);
29965 + si_read_unlock(sb);
29968 + buf->f_type = AUFS_SUPER_MAGIC;
29969 + buf->f_namelen = AUFS_MAX_NAMELEN;
29970 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29972 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29977 +/* ---------------------------------------------------------------------- */
29979 +static int aufs_sync_fs(struct super_block *sb, int wait)
29982 + aufs_bindex_t bbot, bindex;
29983 + struct au_branch *br;
29984 + struct super_block *h_sb;
29987 + si_noflush_read_lock(sb);
29988 + bbot = au_sbbot(sb);
29989 + for (bindex = 0; bindex <= bbot; bindex++) {
29990 + br = au_sbr(sb, bindex);
29991 + if (!au_br_writable(br->br_perm))
29994 + h_sb = au_sbr_sb(sb, bindex);
29995 + e = vfsub_sync_filesystem(h_sb, wait);
29996 + if (unlikely(e && !err))
29998 + /* go on even if an error happens */
30000 + si_read_unlock(sb);
30005 +/* ---------------------------------------------------------------------- */
30007 +/* final actions when unmounting a file system */
30008 +static void aufs_put_super(struct super_block *sb)
30010 + struct au_sbinfo *sbinfo;
30012 + sbinfo = au_sbi(sb);
30014 + kobject_put(&sbinfo->si_kobj);
30017 +/* ---------------------------------------------------------------------- */
30019 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30020 + struct super_block *sb, void *arg)
30023 + unsigned long long n, sz;
30030 + if (*hint > ULLONG_MAX / sizeof(array)) {
30031 + array = ERR_PTR(-EMFILE);
30032 + pr_err("hint %llu\n", *hint);
30036 + sz = sizeof(array) * *hint;
30037 + array = kzalloc(sz, GFP_NOFS);
30038 + if (unlikely(!array))
30039 + array = vzalloc(sz);
30040 + if (unlikely(!array)) {
30041 + array = ERR_PTR(-ENOMEM);
30045 + n = cb(sb, array, *hint, arg);
30046 + AuDebugOn(n > *hint);
30053 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
30054 + unsigned long long max __maybe_unused,
30057 + unsigned long long n;
30058 + struct inode **p, *inode;
30059 + struct list_head *head;
30064 + spin_lock(&sb->s_inode_list_lock);
30065 + list_for_each_entry(inode, head, i_sb_list) {
30066 + if (!au_is_bad_inode(inode)
30067 + && au_ii(inode)->ii_btop >= 0) {
30068 + spin_lock(&inode->i_lock);
30069 + if (atomic_read(&inode->i_count)) {
30073 + AuDebugOn(n > max);
30075 + spin_unlock(&inode->i_lock);
30078 + spin_unlock(&sb->s_inode_list_lock);
30083 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
30085 + struct au_sbinfo *sbi;
30087 + sbi = au_sbi(sb);
30088 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
30089 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
30092 +void au_iarray_free(struct inode **a, unsigned long long max)
30094 + unsigned long long ull;
30096 + for (ull = 0; ull < max; ull++)
30101 +/* ---------------------------------------------------------------------- */
30104 + * refresh dentry and inode at remount time.
30106 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30107 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30108 + struct dentry *parent)
30112 + di_write_lock_child(dentry);
30113 + di_read_lock_parent(parent, AuLock_IR);
30114 + err = au_refresh_dentry(dentry, parent);
30115 + if (!err && dir_flags)
30116 + au_hn_reset(d_inode(dentry), dir_flags);
30117 + di_read_unlock(parent, AuLock_IR);
30118 + di_write_unlock(dentry);
30123 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30124 + struct au_sbinfo *sbinfo,
30125 + const unsigned int dir_flags, unsigned int do_idop)
30128 + struct dentry *parent;
30131 + parent = dget_parent(dentry);
30132 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30133 + if (d_really_is_positive(dentry)) {
30134 + if (!d_is_dir(dentry))
30135 + err = au_do_refresh(dentry, /*dir_flags*/0,
30138 + err = au_do_refresh(dentry, dir_flags, parent);
30139 + if (unlikely(err))
30140 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30143 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30144 + AuDbgDentry(dentry);
30150 + au_refresh_dop(dentry, /*force_reval*/0);
30152 + au_refresh_dop(dentry, /*force_reval*/1);
30158 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30160 + int err, i, j, ndentry, e;
30161 + unsigned int sigen;
30162 + struct au_dcsub_pages dpages;
30163 + struct au_dpage *dpage;
30164 + struct dentry **dentries, *d;
30165 + struct au_sbinfo *sbinfo;
30166 + struct dentry *root = sb->s_root;
30167 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30170 + au_refresh_dop(root, /*force_reval*/0);
30172 + err = au_dpages_init(&dpages, GFP_NOFS);
30173 + if (unlikely(err))
30175 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30176 + if (unlikely(err))
30179 + sigen = au_sigen(sb);
30180 + sbinfo = au_sbi(sb);
30181 + for (i = 0; i < dpages.ndpage; i++) {
30182 + dpage = dpages.dpages + i;
30183 + dentries = dpage->dentries;
30184 + ndentry = dpage->ndentry;
30185 + for (j = 0; j < ndentry; j++) {
30187 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30189 + if (unlikely(e && !err))
30191 + /* go on even err */
30196 + au_dpages_free(&dpages);
30201 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30204 + unsigned int sigen;
30205 + unsigned long long max, ull;
30206 + struct inode *inode, **array;
30208 + array = au_iarray_alloc(sb, &max);
30209 + err = PTR_ERR(array);
30210 + if (IS_ERR(array))
30214 + sigen = au_sigen(sb);
30215 + for (ull = 0; ull < max; ull++) {
30216 + inode = array[ull];
30217 + if (unlikely(!inode))
30221 + ii_write_lock_child(inode);
30222 + if (au_iigen(inode, NULL) != sigen) {
30223 + e = au_refresh_hinode_self(inode);
30224 + if (unlikely(e)) {
30225 + au_refresh_iop(inode, /*force_getattr*/1);
30226 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30229 + /* go on even if err */
30232 + if (!e && do_idop)
30233 + au_refresh_iop(inode, /*force_getattr*/0);
30234 + ii_write_unlock(inode);
30237 + au_iarray_free(array, max);
30243 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30246 + unsigned int udba;
30247 + aufs_bindex_t bindex, bbot;
30248 + struct dentry *root;
30249 + struct inode *inode;
30250 + struct au_branch *br;
30251 + struct au_sbinfo *sbi;
30253 + au_sigen_inc(sb);
30254 + sbi = au_sbi(sb);
30255 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30257 + root = sb->s_root;
30258 + DiMustNoWaiters(root);
30259 + inode = d_inode(root);
30260 + IiMustNoWaiters(inode);
30262 + udba = au_opt_udba(sb);
30263 + bbot = au_sbbot(sb);
30264 + for (bindex = 0; bindex <= bbot; bindex++) {
30265 + br = au_sbr(sb, bindex);
30266 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30267 + if (unlikely(err))
30268 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30270 + /* go on even if err */
30272 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30275 + if (au_ftest_si(sbi, NO_DREVAL)) {
30276 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30277 + sb->s_d_op = &aufs_dop_noreval;
30278 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30279 + sbi->si_iop_array = aufs_iop_nogetattr;
30281 + AuDebugOn(sb->s_d_op == &aufs_dop);
30282 + sb->s_d_op = &aufs_dop;
30283 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30284 + sbi->si_iop_array = aufs_iop;
30286 + pr_info("reset to %ps and %ps\n",
30287 + sb->s_d_op, sbi->si_iop_array);
30290 + di_write_unlock(root);
30291 + err = au_refresh_d(sb, do_idop);
30292 + e = au_refresh_i(sb, do_idop);
30293 + if (unlikely(e && !err))
30295 + /* aufs_write_lock() calls ..._child() */
30296 + di_write_lock_child(root);
30298 + au_cpup_attr_all(inode, /*force*/1);
30300 + if (unlikely(err))
30301 + AuIOErr("refresh failed, ignored, %d\n", err);
30304 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30305 +static int cvt_err(int err)
30319 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30322 + unsigned int mntflags;
30323 + struct au_opts opts = {
30326 + struct dentry *root;
30327 + struct inode *inode;
30328 + struct au_sbinfo *sbinfo;
30331 + root = sb->s_root;
30332 + if (!data || !*data) {
30333 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30335 + di_write_lock_child(root);
30336 + err = au_opts_verify(sb, *flags, /*pending*/0);
30337 + aufs_write_unlock(root);
30343 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30344 + if (unlikely(!opts.opt))
30346 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30347 + opts.flags = AuOpts_REMOUNT;
30348 + opts.sb_flags = *flags;
30350 + /* parse it before aufs lock */
30351 + err = au_opts_parse(sb, data, &opts);
30352 + if (unlikely(err))
30355 + sbinfo = au_sbi(sb);
30356 + inode = d_inode(root);
30357 + inode_lock(inode);
30358 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30359 + if (unlikely(err))
30361 + di_write_lock_child(root);
30363 + /* au_opts_remount() may return an error */
30364 + err = au_opts_remount(sb, &opts);
30365 + au_opts_free(&opts);
30367 + if (au_ftest_opts(opts.flags, REFRESH))
30368 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30370 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30371 + mntflags = au_mntflags(sb);
30372 + do_dx = !!au_opt_test(mntflags, DIO);
30373 + au_dy_arefresh(do_dx);
30376 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30377 + aufs_write_unlock(root);
30380 + inode_unlock(inode);
30382 + free_page((unsigned long)opts.opt);
30384 + err = cvt_err(err);
30389 +static const struct super_operations aufs_sop = {
30390 + .alloc_inode = aufs_alloc_inode,
30391 + .destroy_inode = aufs_destroy_inode,
30392 + /* always deleting, no clearing */
30393 + .drop_inode = generic_delete_inode,
30394 + .show_options = aufs_show_options,
30395 + .statfs = aufs_statfs,
30396 + .put_super = aufs_put_super,
30397 + .sync_fs = aufs_sync_fs,
30398 + .remount_fs = aufs_remount_fs
30401 +/* ---------------------------------------------------------------------- */
30403 +static int alloc_root(struct super_block *sb)
30406 + struct inode *inode;
30407 + struct dentry *root;
30410 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30411 + err = PTR_ERR(inode);
30412 + if (IS_ERR(inode))
30415 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30416 + inode->i_fop = &aufs_dir_fop;
30417 + inode->i_mode = S_IFDIR;
30418 + set_nlink(inode, 2);
30419 + unlock_new_inode(inode);
30421 + root = d_make_root(inode);
30422 + if (unlikely(!root))
30424 + err = PTR_ERR(root);
30425 + if (IS_ERR(root))
30428 + err = au_di_init(root);
30430 + sb->s_root = root;
30431 + return 0; /* success */
30439 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30440 + int silent __maybe_unused)
30443 + struct au_opts opts = {
30446 + struct au_sbinfo *sbinfo;
30447 + struct dentry *root;
30448 + struct inode *inode;
30449 + char *arg = raw_data;
30451 + if (unlikely(!arg || !*arg)) {
30453 + pr_err("no arg\n");
30458 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30459 + if (unlikely(!opts.opt))
30461 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30462 + opts.sb_flags = sb->s_flags;
30464 + err = au_si_alloc(sb);
30465 + if (unlikely(err))
30467 + sbinfo = au_sbi(sb);
30469 + /* all timestamps always follow the ones on the branch */
30470 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30471 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30472 + sb->s_op = &aufs_sop;
30473 + sb->s_d_op = &aufs_dop;
30474 + sb->s_magic = AUFS_SUPER_MAGIC;
30475 + sb->s_maxbytes = 0;
30476 + sb->s_stack_depth = 1;
30477 + au_export_init(sb);
30478 + au_xattr_init(sb);
30480 + err = alloc_root(sb);
30481 + if (unlikely(err)) {
30482 + si_write_unlock(sb);
30485 + root = sb->s_root;
30486 + inode = d_inode(root);
30489 + * actually we can parse options regardless aufs lock here.
30490 + * but at remount time, parsing must be done before aufs lock.
30491 + * so we follow the same rule.
30493 + ii_write_lock_parent(inode);
30494 + aufs_write_unlock(root);
30495 + err = au_opts_parse(sb, arg, &opts);
30496 + if (unlikely(err))
30499 + /* lock vfs_inode first, then aufs. */
30500 + inode_lock(inode);
30501 + aufs_write_lock(root);
30502 + err = au_opts_mount(sb, &opts);
30503 + au_opts_free(&opts);
30504 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30505 + sb->s_d_op = &aufs_dop_noreval;
30506 + pr_info("%ps\n", sb->s_d_op);
30507 + au_refresh_dop(root, /*force_reval*/0);
30508 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30509 + au_refresh_iop(inode, /*force_getattr*/0);
30511 + aufs_write_unlock(root);
30512 + inode_unlock(inode);
30514 + goto out_opts; /* success */
30518 + sb->s_root = NULL;
30520 + kobject_put(&sbinfo->si_kobj);
30521 + sb->s_fs_info = NULL;
30523 + free_page((unsigned long)opts.opt);
30526 + err = cvt_err(err);
30531 +/* ---------------------------------------------------------------------- */
30533 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30534 + const char *dev_name __maybe_unused,
30537 + struct dentry *root;
30539 + /* all timestamps always follow the ones on the branch */
30540 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30541 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30542 + if (IS_ERR(root))
30545 + au_sbilist_add(root->d_sb);
30551 +static void aufs_kill_sb(struct super_block *sb)
30553 + struct au_sbinfo *sbinfo;
30555 + sbinfo = au_sbi(sb);
30557 + au_sbilist_del(sb);
30558 + aufs_write_lock(sb->s_root);
30560 + if (sbinfo->si_wbr_create_ops->fin)
30561 + sbinfo->si_wbr_create_ops->fin(sb);
30562 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30563 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30564 + au_remount_refresh(sb, /*do_idop*/0);
30566 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30567 + au_plink_put(sb, /*verbose*/1);
30569 + au_dr_opt_flush(sb);
30570 + sbinfo->si_sb = NULL;
30571 + aufs_write_unlock(sb->s_root);
30572 + au_nwt_flush(&sbinfo->si_nowait);
30574 + kill_anon_super(sb);
30577 +struct file_system_type aufs_fs_type = {
30578 + .name = AUFS_FSTYPE,
30579 + /* a race between rename and others */
30580 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30581 + .mount = aufs_mount,
30582 + .kill_sb = aufs_kill_sb,
30583 + /* no need to __module_get() and module_put(). */
30584 + .owner = THIS_MODULE,
30586 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30587 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30588 +++ linux/fs/aufs/super.h 2018-10-23 12:33:35.599375796 +0200
30590 +/* SPDX-License-Identifier: GPL-2.0 */
30592 + * Copyright (C) 2005-2018 Junjiro R. Okajima
30594 + * This program, aufs is free software; you can redistribute it and/or modify
30595 + * it under the terms of the GNU General Public License as published by
30596 + * the Free Software Foundation; either version 2 of the License, or
30597 + * (at your option) any later version.
30599 + * This program is distributed in the hope that it will be useful,
30600 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30601 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30602 + * GNU General Public License for more details.
30604 + * You should have received a copy of the GNU General Public License
30605 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30609 + * super_block operations
30612 +#ifndef __AUFS_SUPER_H__
30613 +#define __AUFS_SUPER_H__
30617 +#include <linux/fs.h>
30618 +#include <linux/kobject.h>
30621 +#include "rwsem.h"
30624 +/* policies to select one among multiple writable branches */
30625 +struct au_wbr_copyup_operations {
30626 + int (*copyup)(struct dentry *dentry);
30629 +#define AuWbr_DIR 1 /* target is a dir */
30630 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30632 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30633 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30634 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30636 +struct au_wbr_create_operations {
30637 + int (*create)(struct dentry *dentry, unsigned int flags);
30638 + int (*init)(struct super_block *sb);
30639 + int (*fin)(struct super_block *sb);
30642 +struct au_wbr_mfs {
30643 + struct mutex mfs_lock; /* protect this structure */
30644 + unsigned long mfs_jiffy;
30645 + unsigned long mfs_expire;
30646 + aufs_bindex_t mfs_bindex;
30648 + unsigned long long mfsrr_bytes;
30649 + unsigned long long mfsrr_watermark;
30652 +#define AuPlink_NHASH 100
30653 +static inline int au_plink_hash(ino_t ino)
30655 + return ino % AuPlink_NHASH;
30658 +/* File-based Hierarchical Storage Management */
30660 +#ifdef CONFIG_AUFS_FHSM
30661 + /* allow only one process who can receive the notification */
30662 + spinlock_t fhsm_spin;
30664 + wait_queue_head_t fhsm_wqh;
30665 + atomic_t fhsm_readable;
30667 + /* these are protected by si_rwsem */
30668 + unsigned long fhsm_expire;
30669 + aufs_bindex_t fhsm_bottom;
30674 +struct au_sbinfo {
30675 + /* nowait tasks in the system-wide workqueue */
30676 + struct au_nowait_tasks si_nowait;
30679 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30680 + * rwsem for au_sbinfo is necessary.
30682 + struct au_rwsem si_rwsem;
30685 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30688 + au_lcnt_t si_ninodes, si_nfiles;
30690 + /* branch management */
30691 + unsigned int si_generation;
30693 + /* see AuSi_ flags */
30694 + unsigned char au_si_status;
30696 + aufs_bindex_t si_bbot;
30698 + /* dirty trick to keep br_id plus */
30699 + unsigned int si_last_br_id :
30700 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30701 + struct au_branch **si_branch;
30703 + /* policy to select a writable branch */
30704 + unsigned char si_wbr_copyup;
30705 + unsigned char si_wbr_create;
30706 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30707 + struct au_wbr_create_operations *si_wbr_create_ops;
30709 + /* round robin */
30710 + atomic_t si_wbr_rr_next;
30712 + /* most free space */
30713 + struct au_wbr_mfs si_wbr_mfs;
30715 + /* File-based Hierarchical Storage Management */
30716 + struct au_fhsm si_fhsm;
30718 + /* mount flags */
30719 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30720 + unsigned int si_mntflags;
30722 + /* external inode number (bitmap and translation table) */
30723 + vfs_readf_t si_xread;
30724 + vfs_writef_t si_xwrite;
30725 + loff_t si_ximaxent; /* max entries in a xino */
30727 + struct file *si_xib;
30728 + struct mutex si_xib_mtx; /* protect xib members */
30729 + unsigned long *si_xib_buf;
30730 + unsigned long si_xib_last_pindex;
30731 + int si_xib_next_bit;
30733 + unsigned long si_xino_jiffy;
30734 + unsigned long si_xino_expire;
30735 + /* reserved for future use */
30736 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30738 +#ifdef CONFIG_AUFS_EXPORT
30739 + /* i_generation */
30740 + /* todo: make xigen file an array to support many inode numbers */
30741 + struct file *si_xigen;
30742 + atomic_t si_xigen_next;
30745 + /* dirty trick to support atomic_open */
30746 + struct hlist_bl_head si_aopen;
30748 + /* vdir parameters */
30749 + unsigned long si_rdcache; /* max cache time in jiffies */
30750 + unsigned int si_rdblk; /* deblk size */
30751 + unsigned int si_rdhash; /* hash size */
30754 + * If the number of whiteouts are larger than si_dirwh, leave all of
30755 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30756 + * future fsck.aufs or kernel thread will remove them later.
30757 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30759 + unsigned int si_dirwh;
30761 + /* pseudo_link list */
30762 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30763 + wait_queue_head_t si_plink_wq;
30764 + spinlock_t si_plink_maint_lock;
30765 + pid_t si_plink_maint_pid;
30768 + struct hlist_bl_head si_files;
30770 + /* with/without getattr, brother of sb->s_d_op */
30771 + struct inode_operations *si_iop_array;
30774 + * sysfs and lifetime management.
30775 + * this is not a small structure and it may be a waste of memory in case
30776 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30777 + * but using sysfs is majority.
30779 + struct kobject si_kobj;
30780 +#ifdef CONFIG_DEBUG_FS
30781 + struct dentry *si_dbgaufs;
30782 + struct dentry *si_dbgaufs_plink;
30783 + struct dentry *si_dbgaufs_xib;
30784 +#ifdef CONFIG_AUFS_EXPORT
30785 + struct dentry *si_dbgaufs_xigen;
30789 +#ifdef CONFIG_AUFS_SBILIST
30790 + struct hlist_bl_node si_list;
30793 + /* dirty, necessary for unmounting, sysfs and sysrq */
30794 + struct super_block *si_sb;
30797 +/* sbinfo status flags */
30799 + * set true when refresh_dirs() failed at remount time.
30800 + * then try refreshing dirs at access time again.
30801 + * if it is false, refreshing dirs at access time is unnecessary
30803 +#define AuSi_FAILED_REFRESH_DIR 1
30804 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30805 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30807 +#ifndef CONFIG_AUFS_FHSM
30809 +#define AuSi_FHSM 0
30812 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30813 + unsigned int flag)
30815 + AuRwMustAnyLock(&sbi->si_rwsem);
30816 + return sbi->au_si_status & flag;
30818 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30819 +#define au_fset_si(sbinfo, name) do { \
30820 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30821 + (sbinfo)->au_si_status |= AuSi_##name; \
30823 +#define au_fclr_si(sbinfo, name) do { \
30824 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30825 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30828 +/* ---------------------------------------------------------------------- */
30830 +/* policy to select one among writable branches */
30831 +#define AuWbrCopyup(sbinfo, ...) \
30832 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30833 +#define AuWbrCreate(sbinfo, ...) \
30834 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30836 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30837 +#define AuLock_DW 1 /* write-lock dentry */
30838 +#define AuLock_IR (1 << 1) /* read-lock inode */
30839 +#define AuLock_IW (1 << 2) /* write-lock inode */
30840 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30841 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30842 + /* except RENAME_EXCHANGE */
30843 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30844 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30845 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30846 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30847 +#define au_fset_lock(flags, name) \
30848 + do { (flags) |= AuLock_##name; } while (0)
30849 +#define au_fclr_lock(flags, name) \
30850 + do { (flags) &= ~AuLock_##name; } while (0)
30852 +/* ---------------------------------------------------------------------- */
30855 +extern struct file_system_type aufs_fs_type;
30856 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30857 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30858 + unsigned long long max, void *arg);
30859 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30860 + struct super_block *sb, void *arg);
30861 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30862 +void au_iarray_free(struct inode **a, unsigned long long max);
30865 +void au_si_free(struct kobject *kobj);
30866 +int au_si_alloc(struct super_block *sb);
30867 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30869 +unsigned int au_sigen_inc(struct super_block *sb);
30870 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30872 +int si_read_lock(struct super_block *sb, int flags);
30873 +int si_write_lock(struct super_block *sb, int flags);
30874 +int aufs_read_lock(struct dentry *dentry, int flags);
30875 +void aufs_read_unlock(struct dentry *dentry, int flags);
30876 +void aufs_write_lock(struct dentry *dentry);
30877 +void aufs_write_unlock(struct dentry *dentry);
30878 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30879 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30881 +/* wbr_policy.c */
30882 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30883 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30884 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30885 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30886 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30889 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30891 +#ifdef CONFIG_AUFS_FHSM
30894 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30898 + spin_lock(&fhsm->fhsm_spin);
30899 + pid = fhsm->fhsm_pid;
30900 + spin_unlock(&fhsm->fhsm_spin);
30905 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30906 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30907 +int au_fhsm_fd(struct super_block *sb, int oflags);
30908 +int au_fhsm_br_alloc(struct au_branch *br);
30909 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30910 +void au_fhsm_fin(struct super_block *sb);
30911 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30912 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30913 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30915 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30917 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30918 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30919 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30920 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30921 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30922 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30923 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30924 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30925 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30928 +/* ---------------------------------------------------------------------- */
30930 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30932 + return sb->s_fs_info;
30935 +/* ---------------------------------------------------------------------- */
30937 +#ifdef CONFIG_AUFS_EXPORT
30938 +int au_test_nfsd(void);
30939 +void au_export_init(struct super_block *sb);
30940 +void au_xigen_inc(struct inode *inode);
30941 +int au_xigen_new(struct inode *inode);
30942 +int au_xigen_set(struct super_block *sb, struct path *path);
30943 +void au_xigen_clr(struct super_block *sb);
30945 +static inline int au_busy_or_stale(void)
30947 + if (!au_test_nfsd())
30952 +AuStubInt0(au_test_nfsd, void)
30953 +AuStubVoid(au_export_init, struct super_block *sb)
30954 +AuStubVoid(au_xigen_inc, struct inode *inode)
30955 +AuStubInt0(au_xigen_new, struct inode *inode)
30956 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30957 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30958 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30959 +#endif /* CONFIG_AUFS_EXPORT */
30961 +/* ---------------------------------------------------------------------- */
30963 +#ifdef CONFIG_AUFS_SBILIST
30965 +extern struct hlist_bl_head au_sbilist;
30967 +static inline void au_sbilist_init(void)
30969 + INIT_HLIST_BL_HEAD(&au_sbilist);
30972 +static inline void au_sbilist_add(struct super_block *sb)
30974 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30977 +static inline void au_sbilist_del(struct super_block *sb)
30979 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30982 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30983 +static inline void au_sbilist_lock(void)
30985 + hlist_bl_lock(&au_sbilist);
30988 +static inline void au_sbilist_unlock(void)
30990 + hlist_bl_unlock(&au_sbilist);
30992 +#define AuGFP_SBILIST GFP_ATOMIC
30994 +AuStubVoid(au_sbilist_lock, void)
30995 +AuStubVoid(au_sbilist_unlock, void)
30996 +#define AuGFP_SBILIST GFP_NOFS
30997 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30999 +AuStubVoid(au_sbilist_init, void)
31000 +AuStubVoid(au_sbilist_add, struct super_block *sb)
31001 +AuStubVoid(au_sbilist_del, struct super_block *sb)
31002 +AuStubVoid(au_sbilist_lock, void)
31003 +AuStubVoid(au_sbilist_unlock, void)
31004 +#define AuGFP_SBILIST GFP_NOFS
31007 +/* ---------------------------------------------------------------------- */
31009 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
31012 + * This function is a dynamic '__init' function actually,
31013 + * so the tiny check for si_rwsem is unnecessary.
31015 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
31016 +#ifdef CONFIG_DEBUG_FS
31017 + sbinfo->si_dbgaufs = NULL;
31018 + sbinfo->si_dbgaufs_plink = NULL;
31019 + sbinfo->si_dbgaufs_xib = NULL;
31020 +#ifdef CONFIG_AUFS_EXPORT
31021 + sbinfo->si_dbgaufs_xigen = NULL;
31026 +/* ---------------------------------------------------------------------- */
31028 +/* current->atomic_flags */
31029 +/* this value should never corrupt the ones defined in linux/sched.h */
31030 +#define PFA_AUFS 7
31032 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
31033 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
31034 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
31036 +static inline int si_pid_test(struct super_block *sb)
31038 + return !!task_test_aufs(current);
31041 +static inline void si_pid_clr(struct super_block *sb)
31043 + AuDebugOn(!task_test_aufs(current));
31044 + task_clear_aufs(current);
31047 +static inline void si_pid_set(struct super_block *sb)
31049 + AuDebugOn(task_test_aufs(current));
31050 + task_set_aufs(current);
31053 +/* ---------------------------------------------------------------------- */
31055 +/* lock superblock. mainly for entry point functions */
31056 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
31057 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
31058 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
31059 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
31061 +#define __si_read_trylock_nested(sb) \
31062 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
31063 +#define __si_write_trylock_nested(sb) \
31064 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
31067 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
31068 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
31069 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
31071 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
31072 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
31073 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
31075 +static inline void si_noflush_read_lock(struct super_block *sb)
31077 + __si_read_lock(sb);
31081 +static inline int si_noflush_read_trylock(struct super_block *sb)
31085 + locked = __si_read_trylock(sb);
31091 +static inline void si_noflush_write_lock(struct super_block *sb)
31093 + __si_write_lock(sb);
31097 +static inline int si_noflush_write_trylock(struct super_block *sb)
31101 + locked = __si_write_trylock(sb);
31107 +#if 0 /* reserved */
31108 +static inline int si_read_trylock(struct super_block *sb, int flags)
31110 + if (au_ftest_lock(flags, FLUSH))
31111 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31112 + return si_noflush_read_trylock(sb);
31116 +static inline void si_read_unlock(struct super_block *sb)
31119 + __si_read_unlock(sb);
31122 +#if 0 /* reserved */
31123 +static inline int si_write_trylock(struct super_block *sb, int flags)
31125 + if (au_ftest_lock(flags, FLUSH))
31126 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31127 + return si_noflush_write_trylock(sb);
31131 +static inline void si_write_unlock(struct super_block *sb)
31134 + __si_write_unlock(sb);
31137 +#if 0 /* reserved */
31138 +static inline void si_downgrade_lock(struct super_block *sb)
31140 + __si_downgrade_lock(sb);
31144 +/* ---------------------------------------------------------------------- */
31146 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31148 + SiMustAnyLock(sb);
31149 + return au_sbi(sb)->si_bbot;
31152 +static inline unsigned int au_mntflags(struct super_block *sb)
31154 + SiMustAnyLock(sb);
31155 + return au_sbi(sb)->si_mntflags;
31158 +static inline unsigned int au_sigen(struct super_block *sb)
31160 + SiMustAnyLock(sb);
31161 + return au_sbi(sb)->si_generation;
31164 +static inline struct au_branch *au_sbr(struct super_block *sb,
31165 + aufs_bindex_t bindex)
31167 + SiMustAnyLock(sb);
31168 + return au_sbi(sb)->si_branch[0 + bindex];
31171 +static inline loff_t au_xi_maxent(struct super_block *sb)
31173 + SiMustAnyLock(sb);
31174 + return au_sbi(sb)->si_ximaxent;
31177 +#endif /* __KERNEL__ */
31178 +#endif /* __AUFS_SUPER_H__ */
31179 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31180 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31181 +++ linux/fs/aufs/sysaufs.c 2018-08-12 23:43:05.463458173 +0200
31183 +// SPDX-License-Identifier: GPL-2.0
31185 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31187 + * This program, aufs is free software; you can redistribute it and/or modify
31188 + * it under the terms of the GNU General Public License as published by
31189 + * the Free Software Foundation; either version 2 of the License, or
31190 + * (at your option) any later version.
31192 + * This program is distributed in the hope that it will be useful,
31193 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31194 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31195 + * GNU General Public License for more details.
31197 + * You should have received a copy of the GNU General Public License
31198 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31202 + * sysfs interface and lifetime management
31203 + * they are necessary regardless sysfs is disabled.
31206 +#include <linux/random.h>
31209 +unsigned long sysaufs_si_mask;
31210 +struct kset *sysaufs_kset;
31212 +#define AuSiAttr(_name) { \
31213 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31214 + .show = sysaufs_si_##_name, \
31217 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31218 +struct attribute *sysaufs_si_attrs[] = {
31219 + &sysaufs_si_attr_xi_path.attr,
31223 +static const struct sysfs_ops au_sbi_ops = {
31224 + .show = sysaufs_si_show
31227 +static struct kobj_type au_sbi_ktype = {
31228 + .release = au_si_free,
31229 + .sysfs_ops = &au_sbi_ops,
31230 + .default_attrs = sysaufs_si_attrs
31233 +/* ---------------------------------------------------------------------- */
31235 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31239 + sbinfo->si_kobj.kset = sysaufs_kset;
31240 + /* cf. sysaufs_name() */
31241 + err = kobject_init_and_add
31242 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31243 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31248 +void sysaufs_fin(void)
31250 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31251 + kset_unregister(sysaufs_kset);
31254 +int __init sysaufs_init(void)
31259 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31260 + } while (!sysaufs_si_mask);
31263 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31264 + if (unlikely(!sysaufs_kset))
31266 + err = PTR_ERR(sysaufs_kset);
31267 + if (IS_ERR(sysaufs_kset))
31269 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31270 + if (unlikely(err))
31271 + kset_unregister(sysaufs_kset);
31276 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31277 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31278 +++ linux/fs/aufs/sysaufs.h 2018-08-12 23:43:05.463458173 +0200
31280 +/* SPDX-License-Identifier: GPL-2.0 */
31282 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31284 + * This program, aufs is free software; you can redistribute it and/or modify
31285 + * it under the terms of the GNU General Public License as published by
31286 + * the Free Software Foundation; either version 2 of the License, or
31287 + * (at your option) any later version.
31289 + * This program is distributed in the hope that it will be useful,
31290 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31291 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31292 + * GNU General Public License for more details.
31294 + * You should have received a copy of the GNU General Public License
31295 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31299 + * sysfs interface and mount lifetime management
31302 +#ifndef __SYSAUFS_H__
31303 +#define __SYSAUFS_H__
31307 +#include <linux/sysfs.h>
31308 +#include "module.h"
31310 +struct super_block;
31313 +struct sysaufs_si_attr {
31314 + struct attribute attr;
31315 + int (*show)(struct seq_file *seq, struct super_block *sb);
31318 +/* ---------------------------------------------------------------------- */
31321 +extern unsigned long sysaufs_si_mask;
31322 +extern struct kset *sysaufs_kset;
31323 +extern struct attribute *sysaufs_si_attrs[];
31324 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31325 +int __init sysaufs_init(void);
31326 +void sysaufs_fin(void);
31328 +/* ---------------------------------------------------------------------- */
31330 +/* some people doesn't like to show a pointer in kernel */
31331 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31333 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31336 +#define SysaufsSiNamePrefix "si_"
31337 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31338 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31340 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31341 + sysaufs_si_id(sbinfo));
31345 +#ifdef CONFIG_SYSFS
31347 +extern struct attribute_group *sysaufs_attr_group;
31349 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31350 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31352 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31353 +#ifdef CONFIG_COMPAT
31354 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31357 +void sysaufs_br_init(struct au_branch *br);
31358 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31359 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31361 +#define sysaufs_brs_init() do {} while (0)
31364 +#define sysaufs_attr_group NULL
31366 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31367 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31368 + struct attribute *attr, char *buf)
31369 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31370 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31371 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31373 +static inline void sysaufs_brs_init(void)
31378 +#endif /* CONFIG_SYSFS */
31380 +#endif /* __KERNEL__ */
31381 +#endif /* __SYSAUFS_H__ */
31382 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31383 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31384 +++ linux/fs/aufs/sysfs.c 2018-12-27 13:19:17.711749485 +0100
31386 +// SPDX-License-Identifier: GPL-2.0
31388 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31390 + * This program, aufs is free software; you can redistribute it and/or modify
31391 + * it under the terms of the GNU General Public License as published by
31392 + * the Free Software Foundation; either version 2 of the License, or
31393 + * (at your option) any later version.
31395 + * This program is distributed in the hope that it will be useful,
31396 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31397 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31398 + * GNU General Public License for more details.
31400 + * You should have received a copy of the GNU General Public License
31401 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31405 + * sysfs interface
31408 +#include <linux/compat.h>
31409 +#include <linux/seq_file.h>
31412 +#ifdef CONFIG_AUFS_FS_MODULE
31413 +/* this entry violates the "one line per file" policy of sysfs */
31414 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31418 + static char *conf =
31419 +/* this file is generated at compiling */
31420 +#include "conf.str"
31423 + err = snprintf(buf, PAGE_SIZE, conf);
31424 + if (unlikely(err >= PAGE_SIZE))
31429 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31432 +static struct attribute *au_attr[] = {
31433 +#ifdef CONFIG_AUFS_FS_MODULE
31434 + &au_config_attr.attr,
31436 + NULL, /* need to NULL terminate the list of attributes */
31439 +static struct attribute_group sysaufs_attr_group_body = {
31443 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31445 +/* ---------------------------------------------------------------------- */
31447 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31451 + SiMustAnyLock(sb);
31454 + if (au_opt_test(au_mntflags(sb), XINO)) {
31455 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31456 + seq_putc(seq, '\n');
31462 + * the lifetime of branch is independent from the entry under sysfs.
31463 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31466 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31467 + aufs_bindex_t bindex, int idx)
31470 + struct path path;
31471 + struct dentry *root;
31472 + struct au_branch *br;
31473 + au_br_perm_str_t perm;
31475 + AuDbg("b%d\n", bindex);
31478 + root = sb->s_root;
31479 + di_read_lock_parent(root, !AuLock_IR);
31480 + br = au_sbr(sb, bindex);
31483 + case AuBrSysfs_BR:
31484 + path.mnt = au_br_mnt(br);
31485 + path.dentry = au_h_dptr(root, bindex);
31486 + err = au_seq_path(seq, &path);
31488 + au_optstr_br_perm(&perm, br->br_perm);
31489 + seq_printf(seq, "=%s\n", perm.a);
31492 + case AuBrSysfs_BRID:
31493 + seq_printf(seq, "%d\n", br->br_id);
31496 + di_read_unlock(root, !AuLock_IR);
31497 + if (unlikely(err || seq_has_overflowed(seq)))
31503 +/* ---------------------------------------------------------------------- */
31505 +static struct seq_file *au_seq(char *p, ssize_t len)
31507 + struct seq_file *seq;
31509 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31511 + /* mutex_init(&seq.lock); */
31514 + return seq; /* success */
31517 + seq = ERR_PTR(-ENOMEM);
31521 +#define SysaufsBr_PREFIX "br"
31522 +#define SysaufsBrid_PREFIX "brid"
31524 +/* todo: file size may exceed PAGE_SIZE */
31525 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31531 + aufs_bindex_t bbot;
31532 + struct au_sbinfo *sbinfo;
31533 + struct super_block *sb;
31534 + struct seq_file *seq;
31536 + struct attribute **cattr;
31538 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31539 + sb = sbinfo->si_sb;
31542 + * prevent a race condition between sysfs and aufs.
31543 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31544 + * prohibits maintaining the sysfs entries.
31545 + * hew we acquire read lock after sysfs_get_active_two().
31546 + * on the other hand, the remount process may maintain the sysfs/aufs
31547 + * entries after acquiring write lock.
31548 + * it can cause a deadlock.
31549 + * simply we gave up processing read here.
31552 + if (unlikely(!si_noflush_read_trylock(sb)))
31555 + seq = au_seq(buf, PAGE_SIZE);
31556 + err = PTR_ERR(seq);
31560 + name = (void *)attr->name;
31561 + cattr = sysaufs_si_attrs;
31563 + if (!strcmp(name, (*cattr)->name)) {
31564 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31571 + if (!strncmp(name, SysaufsBrid_PREFIX,
31572 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31573 + idx = AuBrSysfs_BRID;
31574 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31575 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31576 + sizeof(SysaufsBr_PREFIX) - 1)) {
31577 + idx = AuBrSysfs_BR;
31578 + name += sizeof(SysaufsBr_PREFIX) - 1;
31582 + err = kstrtol(name, 10, &l);
31584 + bbot = au_sbbot(sb);
31586 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31593 + err = seq->count;
31594 + /* sysfs limit */
31595 + if (unlikely(err == PAGE_SIZE))
31598 + au_kfree_rcu(seq);
31600 + si_read_unlock(sb);
31605 +/* ---------------------------------------------------------------------- */
31607 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31611 + aufs_bindex_t bindex, bbot;
31614 + struct seq_file *seq;
31615 + struct au_branch *br;
31617 + si_read_lock(sb, AuLock_FLUSH);
31618 + bbot = au_sbbot(sb);
31624 + buf = (void *)__get_free_page(GFP_NOFS);
31625 + if (unlikely(!buf))
31628 + seq = au_seq(buf, PAGE_SIZE);
31629 + err = PTR_ERR(seq);
31633 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31634 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31635 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
31636 + if (unlikely(err))
31639 + br = au_sbr(sb, bindex);
31640 + brid = br->br_id;
31641 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31642 + err = __put_user(brid, &arg->id);
31643 + if (unlikely(err))
31646 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31647 + err = __put_user(br->br_perm, &arg->perm);
31648 + if (unlikely(err))
31651 + err = au_seq_path(seq, &br->br_path);
31652 + if (unlikely(err))
31654 + seq_putc(seq, '\0');
31655 + if (!seq_has_overflowed(seq)) {
31656 + err = copy_to_user(arg->path, seq->buf, seq->count);
31658 + if (unlikely(err))
31665 + if (unlikely(err))
31669 + au_kfree_rcu(seq);
31671 + free_page((unsigned long)buf);
31673 + si_read_unlock(sb);
31677 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31679 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31682 +#ifdef CONFIG_COMPAT
31683 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31685 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31689 +/* ---------------------------------------------------------------------- */
31691 +void sysaufs_br_init(struct au_branch *br)
31694 + struct au_brsysfs *br_sysfs;
31695 + struct attribute *attr;
31697 + br_sysfs = br->br_sysfs;
31698 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31699 + attr = &br_sysfs->attr;
31700 + sysfs_attr_init(attr);
31701 + attr->name = br_sysfs->name;
31702 + attr->mode = 0444;
31707 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31709 + struct au_branch *br;
31710 + struct kobject *kobj;
31711 + struct au_brsysfs *br_sysfs;
31713 + aufs_bindex_t bbot;
31715 + if (!sysaufs_brs)
31718 + kobj = &au_sbi(sb)->si_kobj;
31719 + bbot = au_sbbot(sb);
31720 + for (; bindex <= bbot; bindex++) {
31721 + br = au_sbr(sb, bindex);
31722 + br_sysfs = br->br_sysfs;
31723 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31724 + sysfs_remove_file(kobj, &br_sysfs->attr);
31730 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31733 + aufs_bindex_t bbot;
31734 + struct kobject *kobj;
31735 + struct au_branch *br;
31736 + struct au_brsysfs *br_sysfs;
31738 + if (!sysaufs_brs)
31741 + kobj = &au_sbi(sb)->si_kobj;
31742 + bbot = au_sbbot(sb);
31743 + for (; bindex <= bbot; bindex++) {
31744 + br = au_sbr(sb, bindex);
31745 + br_sysfs = br->br_sysfs;
31746 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31747 + SysaufsBr_PREFIX "%d", bindex);
31748 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31749 + SysaufsBrid_PREFIX "%d", bindex);
31750 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31751 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31752 + if (unlikely(err))
31753 + pr_warn("failed %s under sysfs(%d)\n",
31754 + br_sysfs->name, err);
31759 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31760 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31761 +++ linux/fs/aufs/sysrq.c 2018-10-23 12:33:35.599375796 +0200
31763 +// SPDX-License-Identifier: GPL-2.0
31765 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31767 + * This program, aufs is free software; you can redistribute it and/or modify
31768 + * it under the terms of the GNU General Public License as published by
31769 + * the Free Software Foundation; either version 2 of the License, or
31770 + * (at your option) any later version.
31772 + * This program is distributed in the hope that it will be useful,
31773 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31774 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31775 + * GNU General Public License for more details.
31777 + * You should have received a copy of the GNU General Public License
31778 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31782 + * magic sysrq handler
31785 +/* #include <linux/sysrq.h> */
31786 +#include <linux/writeback.h>
31789 +/* ---------------------------------------------------------------------- */
31791 +static void sysrq_sb(struct super_block *sb)
31794 + struct au_sbinfo *sbinfo;
31795 + struct file *file;
31796 + struct hlist_bl_head *files;
31797 + struct hlist_bl_node *pos;
31798 + struct au_finfo *finfo;
31800 + plevel = au_plevel;
31801 + au_plevel = KERN_WARNING;
31803 + /* since we define pr_fmt, call printk directly */
31804 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31806 + sbinfo = au_sbi(sb);
31807 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31808 + pr("superblock\n");
31812 + pr("root dentry\n");
31813 + au_dpri_dentry(sb->s_root);
31814 + pr("root inode\n");
31815 + au_dpri_inode(d_inode(sb->s_root));
31820 + int err, i, j, ndentry;
31821 + struct au_dcsub_pages dpages;
31822 + struct au_dpage *dpage;
31824 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31825 + if (unlikely(err))
31827 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31829 + for (i = 0; i < dpages.ndpage; i++) {
31830 + dpage = dpages.dpages + i;
31831 + ndentry = dpage->ndentry;
31832 + for (j = 0; j < ndentry; j++)
31833 + au_dpri_dentry(dpage->dentries[j]);
31835 + au_dpages_free(&dpages);
31843 + pr("isolated inode\n");
31844 + spin_lock(&sb->s_inode_list_lock);
31845 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31846 + spin_lock(&i->i_lock);
31847 + if (1 || hlist_empty(&i->i_dentry))
31848 + au_dpri_inode(i);
31849 + spin_unlock(&i->i_lock);
31851 + spin_unlock(&sb->s_inode_list_lock);
31855 + files = &au_sbi(sb)->si_files;
31856 + hlist_bl_lock(files);
31857 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31860 + file = finfo->fi_file;
31861 + mode = file_inode(file)->i_mode;
31862 + if (!special_file(mode))
31863 + au_dpri_file(file);
31865 + hlist_bl_unlock(files);
31869 + au_plevel = plevel;
31872 +/* ---------------------------------------------------------------------- */
31874 +/* module parameter */
31875 +static char *aufs_sysrq_key = "a";
31876 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31877 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31879 +static void au_sysrq(int key __maybe_unused)
31881 + struct au_sbinfo *sbinfo;
31882 + struct hlist_bl_node *pos;
31885 + au_sbilist_lock();
31886 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31887 + sysrq_sb(sbinfo->si_sb);
31888 + au_sbilist_unlock();
31892 +static struct sysrq_key_op au_sysrq_op = {
31893 + .handler = au_sysrq,
31894 + .help_msg = "Aufs",
31895 + .action_msg = "Aufs",
31896 + .enable_mask = SYSRQ_ENABLE_DUMP
31899 +/* ---------------------------------------------------------------------- */
31901 +int __init au_sysrq_init(void)
31907 + key = *aufs_sysrq_key;
31908 + if ('a' <= key && key <= 'z')
31909 + err = register_sysrq_key(key, &au_sysrq_op);
31910 + if (unlikely(err))
31911 + pr_err("err %d, sysrq=%c\n", err, key);
31915 +void au_sysrq_fin(void)
31919 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31920 + if (unlikely(err))
31921 + pr_err("err %d (ignored)\n", err);
31923 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31924 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31925 +++ linux/fs/aufs/vdir.c 2018-12-27 13:19:17.711749485 +0100
31927 +// SPDX-License-Identifier: GPL-2.0
31929 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31931 + * This program, aufs is free software; you can redistribute it and/or modify
31932 + * it under the terms of the GNU General Public License as published by
31933 + * the Free Software Foundation; either version 2 of the License, or
31934 + * (at your option) any later version.
31936 + * This program is distributed in the hope that it will be useful,
31937 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31938 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31939 + * GNU General Public License for more details.
31941 + * You should have received a copy of the GNU General Public License
31942 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31946 + * virtual or vertical directory
31951 +static unsigned int calc_size(int nlen)
31953 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31956 +static int set_deblk_end(union au_vdir_deblk_p *p,
31957 + union au_vdir_deblk_p *deblk_end)
31959 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31960 + p->de->de_str.len = 0;
31964 + return -1; /* error */
31967 +/* returns true or false */
31968 +static int is_deblk_end(union au_vdir_deblk_p *p,
31969 + union au_vdir_deblk_p *deblk_end)
31971 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31972 + return !p->de->de_str.len;
31976 +static unsigned char *last_deblk(struct au_vdir *vdir)
31978 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31981 +/* ---------------------------------------------------------------------- */
31983 +/* estimate the appropriate size for name hash table */
31984 +unsigned int au_rdhash_est(loff_t sz)
31992 + if (sz < AUFS_RDHASH_DEF)
31993 + n = AUFS_RDHASH_DEF;
31994 + /* pr_info("n %u\n", n); */
31999 + * the allocated memory has to be freed by
32000 + * au_nhash_wh_free() or au_nhash_de_free().
32002 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
32004 + struct hlist_head *head;
32008 + sz = sizeof(*nhash->nh_head) * num_hash;
32009 + head = kmalloc(sz, gfp);
32011 + nhash->nh_num = num_hash;
32012 + nhash->nh_head = head;
32013 + for (u = 0; u < num_hash; u++)
32014 + INIT_HLIST_HEAD(head++);
32015 + return 0; /* success */
32021 +static void nhash_count(struct hlist_head *head)
32025 + struct hlist_node *pos;
32028 + hlist_for_each(pos, head)
32030 + pr_info("%lu\n", n);
32034 +static void au_nhash_wh_do_free(struct hlist_head *head)
32036 + struct au_vdir_wh *pos;
32037 + struct hlist_node *node;
32039 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
32040 + au_kfree_rcu(pos);
32043 +static void au_nhash_de_do_free(struct hlist_head *head)
32045 + struct au_vdir_dehstr *pos;
32046 + struct hlist_node *node;
32048 + hlist_for_each_entry_safe(pos, node, head, hash)
32049 + au_cache_free_vdir_dehstr(pos);
32052 +static void au_nhash_do_free(struct au_nhash *nhash,
32053 + void (*free)(struct hlist_head *head))
32056 + struct hlist_head *head;
32058 + n = nhash->nh_num;
32062 + head = nhash->nh_head;
32063 + while (n-- > 0) {
32064 + nhash_count(head);
32067 + au_kfree_try_rcu(nhash->nh_head);
32070 +void au_nhash_wh_free(struct au_nhash *whlist)
32072 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
32075 +static void au_nhash_de_free(struct au_nhash *delist)
32077 + au_nhash_do_free(delist, au_nhash_de_do_free);
32080 +/* ---------------------------------------------------------------------- */
32082 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
32086 + unsigned int u, n;
32087 + struct hlist_head *head;
32088 + struct au_vdir_wh *pos;
32091 + n = whlist->nh_num;
32092 + head = whlist->nh_head;
32093 + for (u = 0; u < n; u++, head++)
32094 + hlist_for_each_entry(pos, head, wh_hash)
32095 + if (pos->wh_bindex == btgt && ++num > limit)
32100 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
32101 + unsigned char *name,
32102 + unsigned int len)
32105 + /* const unsigned int magic_bit = 12; */
32107 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32114 + /* v = hash_long(v, magic_bit); */
32115 + v %= nhash->nh_num;
32116 + return nhash->nh_head + v;
32119 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32122 + return str->len == nlen && !memcmp(str->name, name, nlen);
32125 +/* returns found or not */
32126 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32128 + struct hlist_head *head;
32129 + struct au_vdir_wh *pos;
32130 + struct au_vdir_destr *str;
32132 + head = au_name_hash(whlist, name, nlen);
32133 + hlist_for_each_entry(pos, head, wh_hash) {
32134 + str = &pos->wh_str;
32135 + AuDbg("%.*s\n", str->len, str->name);
32136 + if (au_nhash_test_name(str, name, nlen))
32142 +/* returns found(true) or not */
32143 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32145 + struct hlist_head *head;
32146 + struct au_vdir_dehstr *pos;
32147 + struct au_vdir_destr *str;
32149 + head = au_name_hash(delist, name, nlen);
32150 + hlist_for_each_entry(pos, head, hash) {
32152 + AuDbg("%.*s\n", str->len, str->name);
32153 + if (au_nhash_test_name(str, name, nlen))
32159 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32160 + unsigned char d_type)
32162 +#ifdef CONFIG_AUFS_SHWH
32163 + wh->wh_ino = ino;
32164 + wh->wh_type = d_type;
32168 +/* ---------------------------------------------------------------------- */
32170 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32171 + unsigned int d_type, aufs_bindex_t bindex,
32172 + unsigned char shwh)
32175 + struct au_vdir_destr *str;
32176 + struct au_vdir_wh *wh;
32178 + AuDbg("%.*s\n", nlen, name);
32179 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32182 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32183 + if (unlikely(!wh))
32187 + wh->wh_bindex = bindex;
32189 + au_shwh_init_wh(wh, ino, d_type);
32190 + str = &wh->wh_str;
32192 + memcpy(str->name, name, nlen);
32193 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32200 +static int append_deblk(struct au_vdir *vdir)
32203 + unsigned long ul;
32204 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32205 + union au_vdir_deblk_p p, deblk_end;
32206 + unsigned char **o;
32209 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32210 + GFP_NOFS, /*may_shrink*/0);
32211 + if (unlikely(!o))
32214 + vdir->vd_deblk = o;
32215 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32217 + ul = vdir->vd_nblk++;
32218 + vdir->vd_deblk[ul] = p.deblk;
32219 + vdir->vd_last.ul = ul;
32220 + vdir->vd_last.p.deblk = p.deblk;
32221 + deblk_end.deblk = p.deblk + deblk_sz;
32222 + err = set_deblk_end(&p, &deblk_end);
32229 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32230 + unsigned int d_type, struct au_nhash *delist)
32234 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32235 + union au_vdir_deblk_p p, *room, deblk_end;
32236 + struct au_vdir_dehstr *dehstr;
32238 + p.deblk = last_deblk(vdir);
32239 + deblk_end.deblk = p.deblk + deblk_sz;
32240 + room = &vdir->vd_last.p;
32241 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32242 + || !is_deblk_end(room, &deblk_end));
32244 + sz = calc_size(nlen);
32245 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32246 + err = append_deblk(vdir);
32247 + if (unlikely(err))
32250 + p.deblk = last_deblk(vdir);
32251 + deblk_end.deblk = p.deblk + deblk_sz;
32253 + AuDebugOn(room->deblk != p.deblk);
32257 + dehstr = au_cache_alloc_vdir_dehstr();
32258 + if (unlikely(!dehstr))
32261 + dehstr->str = &room->de->de_str;
32262 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32263 + room->de->de_ino = ino;
32264 + room->de->de_type = d_type;
32265 + room->de->de_str.len = nlen;
32266 + memcpy(room->de->de_str.name, name, nlen);
32269 + room->deblk += sz;
32270 + if (unlikely(set_deblk_end(room, &deblk_end)))
32271 + err = append_deblk(vdir);
32278 +/* ---------------------------------------------------------------------- */
32280 +void au_vdir_free(struct au_vdir *vdir)
32282 + unsigned char **deblk;
32284 + deblk = vdir->vd_deblk;
32285 + while (vdir->vd_nblk--)
32286 + au_kfree_try_rcu(*deblk++);
32287 + au_kfree_try_rcu(vdir->vd_deblk);
32288 + au_cache_free_vdir(vdir);
32291 +static struct au_vdir *alloc_vdir(struct file *file)
32293 + struct au_vdir *vdir;
32294 + struct super_block *sb;
32297 + sb = file->f_path.dentry->d_sb;
32298 + SiMustAnyLock(sb);
32301 + vdir = au_cache_alloc_vdir();
32302 + if (unlikely(!vdir))
32305 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32306 + if (unlikely(!vdir->vd_deblk))
32309 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32310 + if (!vdir->vd_deblk_sz) {
32311 + /* estimate the appropriate size for deblk */
32312 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32313 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32315 + vdir->vd_nblk = 0;
32316 + vdir->vd_version = 0;
32317 + vdir->vd_jiffy = 0;
32318 + err = append_deblk(vdir);
32320 + return vdir; /* success */
32322 + au_kfree_try_rcu(vdir->vd_deblk);
32325 + au_cache_free_vdir(vdir);
32327 + vdir = ERR_PTR(err);
32331 +static int reinit_vdir(struct au_vdir *vdir)
32334 + union au_vdir_deblk_p p, deblk_end;
32336 + while (vdir->vd_nblk > 1) {
32337 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32338 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32341 + p.deblk = vdir->vd_deblk[0];
32342 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32343 + err = set_deblk_end(&p, &deblk_end);
32344 + /* keep vd_dblk_sz */
32345 + vdir->vd_last.ul = 0;
32346 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32347 + vdir->vd_version = 0;
32348 + vdir->vd_jiffy = 0;
32353 +/* ---------------------------------------------------------------------- */
32355 +#define AuFillVdir_CALLED 1
32356 +#define AuFillVdir_WHABLE (1 << 1)
32357 +#define AuFillVdir_SHWH (1 << 2)
32358 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32359 +#define au_fset_fillvdir(flags, name) \
32360 + do { (flags) |= AuFillVdir_##name; } while (0)
32361 +#define au_fclr_fillvdir(flags, name) \
32362 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32364 +#ifndef CONFIG_AUFS_SHWH
32365 +#undef AuFillVdir_SHWH
32366 +#define AuFillVdir_SHWH 0
32369 +struct fillvdir_arg {
32370 + struct dir_context ctx;
32371 + struct file *file;
32372 + struct au_vdir *vdir;
32373 + struct au_nhash delist;
32374 + struct au_nhash whlist;
32375 + aufs_bindex_t bindex;
32376 + unsigned int flags;
32380 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32381 + loff_t offset __maybe_unused, u64 h_ino,
32382 + unsigned int d_type)
32384 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32385 + char *name = (void *)__name;
32386 + struct super_block *sb;
32388 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32391 + sb = arg->file->f_path.dentry->d_sb;
32392 + au_fset_fillvdir(arg->flags, CALLED);
32394 + if (nlen <= AUFS_WH_PFX_LEN
32395 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32396 + if (test_known(&arg->delist, name, nlen)
32397 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32398 + goto out; /* already exists or whiteouted */
32400 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32402 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32403 + d_type = DT_UNKNOWN;
32404 + arg->err = append_de(arg->vdir, name, nlen, ino,
32405 + d_type, &arg->delist);
32407 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32408 + name += AUFS_WH_PFX_LEN;
32409 + nlen -= AUFS_WH_PFX_LEN;
32410 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32411 + goto out; /* already whiteouted */
32413 + ino = 0; /* just to suppress a warning */
32415 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32418 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32419 + d_type = DT_UNKNOWN;
32420 + arg->err = au_nhash_append_wh
32421 + (&arg->whlist, name, nlen, ino, d_type,
32422 + arg->bindex, shwh);
32428 + arg->vdir->vd_jiffy = jiffies;
32430 + AuTraceErr(arg->err);
32434 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32435 + struct au_nhash *whlist, struct au_nhash *delist)
32437 +#ifdef CONFIG_AUFS_SHWH
32439 + unsigned int nh, u;
32440 + struct hlist_head *head;
32441 + struct au_vdir_wh *pos;
32442 + struct hlist_node *n;
32444 + struct au_vdir_destr *destr;
32446 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32449 + o = p = (void *)__get_free_page(GFP_NOFS);
32450 + if (unlikely(!p))
32454 + nh = whlist->nh_num;
32455 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32456 + p += AUFS_WH_PFX_LEN;
32457 + for (u = 0; u < nh; u++) {
32458 + head = whlist->nh_head + u;
32459 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32460 + destr = &pos->wh_str;
32461 + memcpy(p, destr->name, destr->len);
32462 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32463 + pos->wh_ino, pos->wh_type, delist);
32464 + if (unlikely(err))
32469 + free_page((unsigned long)o);
32479 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32482 + unsigned int rdhash;
32484 + aufs_bindex_t bbot, bindex, btop;
32485 + unsigned char shwh;
32486 + struct file *hf, *file;
32487 + struct super_block *sb;
32489 + file = arg->file;
32490 + sb = file->f_path.dentry->d_sb;
32491 + SiMustAnyLock(sb);
32493 + rdhash = au_sbi(sb)->si_rdhash;
32495 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32496 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32497 + if (unlikely(err))
32499 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32500 + if (unlikely(err))
32506 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32508 + au_fset_fillvdir(arg->flags, SHWH);
32510 + btop = au_fbtop(file);
32511 + bbot = au_fbbot_dir(file);
32512 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32513 + hf = au_hf_dir(file, bindex);
32517 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32519 + if (unlikely(offset))
32522 + arg->bindex = bindex;
32523 + au_fclr_fillvdir(arg->flags, WHABLE);
32525 + || (bindex != bbot
32526 + && au_br_whable(au_sbr_perm(sb, bindex))))
32527 + au_fset_fillvdir(arg->flags, WHABLE);
32530 + au_fclr_fillvdir(arg->flags, CALLED);
32532 + err = vfsub_iterate_dir(hf, &arg->ctx);
32535 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32538 + * dir_relax() may be good for concurrency, but aufs should not
32539 + * use it since it will cause a lockdep problem.
32543 + if (!err && shwh)
32544 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32546 + au_nhash_wh_free(&arg->whlist);
32549 + au_nhash_de_free(&arg->delist);
32554 +static int read_vdir(struct file *file, int may_read)
32557 + unsigned long expire;
32558 + unsigned char do_read;
32559 + struct fillvdir_arg arg = {
32561 + .actor = fillvdir
32564 + struct inode *inode;
32565 + struct au_vdir *vdir, *allocated;
32568 + inode = file_inode(file);
32569 + IMustLock(inode);
32570 + IiMustWriteLock(inode);
32571 + SiMustAnyLock(inode->i_sb);
32573 + allocated = NULL;
32575 + expire = au_sbi(inode->i_sb)->si_rdcache;
32576 + vdir = au_ivdir(inode);
32579 + vdir = alloc_vdir(file);
32580 + err = PTR_ERR(vdir);
32581 + if (IS_ERR(vdir))
32584 + allocated = vdir;
32585 + } else if (may_read
32586 + && (!inode_eq_iversion(inode, vdir->vd_version)
32587 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32589 + err = reinit_vdir(vdir);
32590 + if (unlikely(err))
32595 + return 0; /* success */
32599 + err = au_do_read_vdir(&arg);
32601 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32602 + vdir->vd_version = inode_query_iversion(inode);
32603 + vdir->vd_last.ul = 0;
32604 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32606 + au_set_ivdir(inode, allocated);
32607 + } else if (allocated)
32608 + au_vdir_free(allocated);
32614 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32617 + unsigned long ul, n;
32618 + const unsigned int deblk_sz = src->vd_deblk_sz;
32620 + AuDebugOn(tgt->vd_nblk != 1);
32623 + if (tgt->vd_nblk < src->vd_nblk) {
32624 + unsigned char **p;
32626 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32627 + GFP_NOFS, /*may_shrink*/0);
32628 + if (unlikely(!p))
32630 + tgt->vd_deblk = p;
32633 + if (tgt->vd_deblk_sz != deblk_sz) {
32634 + unsigned char *p;
32636 + tgt->vd_deblk_sz = deblk_sz;
32637 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32638 + /*may_shrink*/1);
32639 + if (unlikely(!p))
32641 + tgt->vd_deblk[0] = p;
32643 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32644 + tgt->vd_version = src->vd_version;
32645 + tgt->vd_jiffy = src->vd_jiffy;
32647 + n = src->vd_nblk;
32648 + for (ul = 1; ul < n; ul++) {
32649 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32651 + if (unlikely(!tgt->vd_deblk[ul]))
32655 + tgt->vd_nblk = n;
32656 + tgt->vd_last.ul = tgt->vd_last.ul;
32657 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32658 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32659 + - src->vd_deblk[src->vd_last.ul];
32661 + return 0; /* success */
32664 + rerr = reinit_vdir(tgt);
32669 +int au_vdir_init(struct file *file)
32672 + struct inode *inode;
32673 + struct au_vdir *vdir_cache, *allocated;
32675 + /* test file->f_pos here instead of ctx->pos */
32676 + err = read_vdir(file, !file->f_pos);
32677 + if (unlikely(err))
32680 + allocated = NULL;
32681 + vdir_cache = au_fvdir_cache(file);
32682 + if (!vdir_cache) {
32683 + vdir_cache = alloc_vdir(file);
32684 + err = PTR_ERR(vdir_cache);
32685 + if (IS_ERR(vdir_cache))
32687 + allocated = vdir_cache;
32688 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32689 + /* test file->f_pos here instead of ctx->pos */
32690 + err = reinit_vdir(vdir_cache);
32691 + if (unlikely(err))
32694 + return 0; /* success */
32696 + inode = file_inode(file);
32697 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32699 + file->f_version = inode_query_iversion(inode);
32701 + au_set_fvdir_cache(file, allocated);
32702 + } else if (allocated)
32703 + au_vdir_free(allocated);
32709 +static loff_t calc_offset(struct au_vdir *vdir)
32712 + union au_vdir_deblk_p p;
32714 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32715 + offset = vdir->vd_last.p.deblk - p.deblk;
32716 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32720 +/* returns true or false */
32721 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32724 + unsigned int deblk_sz;
32725 + unsigned long ul, n;
32727 + union au_vdir_deblk_p p, deblk_end;
32728 + struct au_vdir *vdir_cache;
32731 + vdir_cache = au_fvdir_cache(file);
32732 + offset = calc_offset(vdir_cache);
32733 + AuDbg("offset %lld\n", offset);
32734 + if (ctx->pos == offset)
32737 + vdir_cache->vd_last.ul = 0;
32738 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32743 + deblk_sz = vdir_cache->vd_deblk_sz;
32744 + ul = div64_u64(ctx->pos, deblk_sz);
32745 + AuDbg("ul %lu\n", ul);
32746 + if (ul >= vdir_cache->vd_nblk)
32749 + n = vdir_cache->vd_nblk;
32750 + for (; ul < n; ul++) {
32751 + p.deblk = vdir_cache->vd_deblk[ul];
32752 + deblk_end.deblk = p.deblk + deblk_sz;
32754 + offset *= deblk_sz;
32755 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32758 + l = calc_size(p.de->de_str.len);
32762 + if (!is_deblk_end(&p, &deblk_end)) {
32764 + vdir_cache->vd_last.ul = ul;
32765 + vdir_cache->vd_last.p = p;
32773 + AuDbg("valid %d\n", !valid);
32777 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32779 + unsigned int l, deblk_sz;
32780 + union au_vdir_deblk_p deblk_end;
32781 + struct au_vdir *vdir_cache;
32782 + struct au_vdir_de *de;
32784 + if (!seek_vdir(file, ctx))
32787 + vdir_cache = au_fvdir_cache(file);
32788 + deblk_sz = vdir_cache->vd_deblk_sz;
32790 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32791 + deblk_end.deblk += deblk_sz;
32792 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32793 + de = vdir_cache->vd_last.p.de;
32794 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32795 + de->de_str.len, de->de_str.name, ctx->pos,
32796 + (unsigned long)de->de_ino, de->de_type);
32797 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32798 + de->de_str.len, de->de_ino,
32800 + /* todo: ignore the error caused by udba? */
32801 + /* return err; */
32805 + l = calc_size(de->de_str.len);
32806 + vdir_cache->vd_last.p.deblk += l;
32809 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32810 + vdir_cache->vd_last.ul++;
32811 + vdir_cache->vd_last.p.deblk
32812 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32813 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32822 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32823 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32824 +++ linux/fs/aufs/vfsub.c 2018-10-23 12:33:35.599375796 +0200
32826 +// SPDX-License-Identifier: GPL-2.0
32828 + * Copyright (C) 2005-2018 Junjiro R. Okajima
32830 + * This program, aufs is free software; you can redistribute it and/or modify
32831 + * it under the terms of the GNU General Public License as published by
32832 + * the Free Software Foundation; either version 2 of the License, or
32833 + * (at your option) any later version.
32835 + * This program is distributed in the hope that it will be useful,
32836 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32837 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32838 + * GNU General Public License for more details.
32840 + * You should have received a copy of the GNU General Public License
32841 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32845 + * sub-routines for VFS
32848 +#include <linux/mnt_namespace.h>
32849 +#include <linux/namei.h>
32850 +#include <linux/nsproxy.h>
32851 +#include <linux/security.h>
32852 +#include <linux/splice.h>
32855 +#ifdef CONFIG_AUFS_BR_FUSE
32856 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32858 + if (!au_test_fuse(h_sb) || !au_userns)
32861 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32865 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32870 + down_read(&h_sb->s_umount);
32871 + err = __sync_filesystem(h_sb, wait);
32872 + up_read(&h_sb->s_umount);
32878 +/* ---------------------------------------------------------------------- */
32880 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32884 + struct super_block *h_sb;
32886 + /* for remote fs, leave work for its getattr or d_revalidate */
32887 + /* for bad i_attr fs, handle them in aufs_getattr() */
32888 + /* still some fs may acquire i_mutex. we need to skip them */
32892 + h_sb = h_path->dentry->d_sb;
32893 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32895 + err = vfsub_getattr(h_path, &st);
32900 +/* ---------------------------------------------------------------------- */
32902 +struct file *vfsub_dentry_open(struct path *path, int flags)
32904 + struct file *file;
32906 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32908 + if (!IS_ERR_OR_NULL(file)
32909 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
32910 + i_readcount_inc(d_inode(path->dentry));
32915 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32917 + struct file *file;
32920 + file = filp_open(path,
32921 + oflags /* | __FMODE_NONOTIFY */,
32924 + if (IS_ERR(file))
32926 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32933 + * Ideally this function should call VFS:do_last() in order to keep all its
32934 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32935 + * structure such as nameidata. This is a second (or third) best approach.
32936 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32938 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32939 + struct vfsub_aopen_args *args)
32942 + struct au_branch *br = args->br;
32943 + struct file *file = args->file;
32944 + /* copied from linux/fs/namei.c:atomic_open() */
32945 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32948 + AuDebugOn(!dir->i_op->atomic_open);
32950 + err = au_br_test_oflag(args->open_flag, br);
32951 + if (unlikely(err))
32954 + au_lcnt_inc(&br->br_nfiles);
32955 + file->f_path.dentry = DENTRY_NOT_SET;
32956 + file->f_path.mnt = au_br_mnt(br);
32957 + AuDbg("%ps\n", dir->i_op->atomic_open);
32958 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32959 + args->create_mode);
32960 + if (unlikely(err < 0)) {
32961 + au_lcnt_dec(&br->br_nfiles);
32965 + /* temporary workaround for nfsv4 branch */
32966 + if (au_test_nfs(dir->i_sb))
32967 + nfs_mark_for_revalidate(dir);
32969 + if (file->f_mode & FMODE_CREATED)
32970 + fsnotify_create(dir, dentry);
32971 + if (!(file->f_mode & FMODE_OPENED)) {
32972 + au_lcnt_dec(&br->br_nfiles);
32976 + /* todo: call VFS:may_open() here */
32977 + /* todo: ima_file_check() too? */
32978 + if (!err && (args->open_flag & __FMODE_EXEC))
32979 + err = deny_write_access(file);
32981 + fsnotify_open(file);
32983 + au_lcnt_dec(&br->br_nfiles);
32984 + /* note that the file is created and still opened */
32990 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32994 + err = kern_path(name, flags, path);
32995 + if (!err && d_is_positive(path->dentry))
32996 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33000 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33001 + struct dentry *parent, int len)
33003 + struct path path = {
33007 + path.dentry = lookup_one_len_unlocked(name, parent, len);
33008 + if (IS_ERR(path.dentry))
33010 + if (d_is_positive(path.dentry))
33011 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33014 + AuTraceErrPtr(path.dentry);
33015 + return path.dentry;
33018 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33021 + struct path path = {
33025 + /* VFS checks it too, but by WARN_ON_ONCE() */
33026 + IMustLock(d_inode(parent));
33028 + path.dentry = lookup_one_len(name, parent, len);
33029 + if (IS_ERR(path.dentry))
33031 + if (d_is_positive(path.dentry))
33032 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33035 + AuTraceErrPtr(path.dentry);
33036 + return path.dentry;
33039 +void vfsub_call_lkup_one(void *args)
33041 + struct vfsub_lkup_one_args *a = args;
33042 + *a->errp = vfsub_lkup_one(a->name, a->parent);
33045 +/* ---------------------------------------------------------------------- */
33047 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33048 + struct dentry *d2, struct au_hinode *hdir2)
33050 + struct dentry *d;
33053 + d = lock_rename(d1, d2);
33055 + au_hn_suspend(hdir1);
33056 + if (hdir1 != hdir2)
33057 + au_hn_suspend(hdir2);
33062 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33063 + struct dentry *d2, struct au_hinode *hdir2)
33065 + au_hn_resume(hdir1);
33066 + if (hdir1 != hdir2)
33067 + au_hn_resume(hdir2);
33069 + unlock_rename(d1, d2);
33073 +/* ---------------------------------------------------------------------- */
33075 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
33078 + struct dentry *d;
33082 + d = path->dentry;
33083 + path->dentry = d->d_parent;
33084 + err = security_path_mknod(path, d, mode, 0);
33085 + path->dentry = d;
33086 + if (unlikely(err))
33090 + err = vfs_create(dir, path->dentry, mode, want_excl);
33093 + struct path tmp = *path;
33096 + vfsub_update_h_iattr(&tmp, &did);
33098 + tmp.dentry = path->dentry->d_parent;
33099 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33108 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33111 + struct dentry *d;
33115 + d = path->dentry;
33116 + path->dentry = d->d_parent;
33117 + err = security_path_symlink(path, d, symname);
33118 + path->dentry = d;
33119 + if (unlikely(err))
33123 + err = vfs_symlink(dir, path->dentry, symname);
33126 + struct path tmp = *path;
33129 + vfsub_update_h_iattr(&tmp, &did);
33131 + tmp.dentry = path->dentry->d_parent;
33132 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33141 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33144 + struct dentry *d;
33148 + d = path->dentry;
33149 + path->dentry = d->d_parent;
33150 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33151 + path->dentry = d;
33152 + if (unlikely(err))
33156 + err = vfs_mknod(dir, path->dentry, mode, dev);
33159 + struct path tmp = *path;
33162 + vfsub_update_h_iattr(&tmp, &did);
33164 + tmp.dentry = path->dentry->d_parent;
33165 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33174 +static int au_test_nlink(struct inode *inode)
33176 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33178 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33179 + || inode->i_nlink < link_max)
33184 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33185 + struct inode **delegated_inode)
33188 + struct dentry *d;
33192 + err = au_test_nlink(d_inode(src_dentry));
33193 + if (unlikely(err))
33196 + /* we don't call may_linkat() */
33197 + d = path->dentry;
33198 + path->dentry = d->d_parent;
33199 + err = security_path_link(src_dentry, path, d);
33200 + path->dentry = d;
33201 + if (unlikely(err))
33205 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
33208 + struct path tmp = *path;
33211 + /* fuse has different memory inode for the same inumber */
33212 + vfsub_update_h_iattr(&tmp, &did);
33214 + tmp.dentry = path->dentry->d_parent;
33215 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33216 + tmp.dentry = src_dentry;
33217 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33226 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33227 + struct inode *dir, struct path *path,
33228 + struct inode **delegated_inode, unsigned int flags)
33231 + struct path tmp = {
33234 + struct dentry *d;
33237 + IMustLock(src_dir);
33239 + d = path->dentry;
33240 + path->dentry = d->d_parent;
33241 + tmp.dentry = src_dentry->d_parent;
33242 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33243 + path->dentry = d;
33244 + if (unlikely(err))
33248 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
33249 + delegated_inode, flags);
33254 + tmp.dentry = d->d_parent;
33255 + vfsub_update_h_iattr(&tmp, &did);
33257 + tmp.dentry = src_dentry;
33258 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33259 + tmp.dentry = src_dentry->d_parent;
33260 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33269 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33272 + struct dentry *d;
33276 + d = path->dentry;
33277 + path->dentry = d->d_parent;
33278 + err = security_path_mkdir(path, d, mode);
33279 + path->dentry = d;
33280 + if (unlikely(err))
33284 + err = vfs_mkdir(dir, path->dentry, mode);
33287 + struct path tmp = *path;
33290 + vfsub_update_h_iattr(&tmp, &did);
33292 + tmp.dentry = path->dentry->d_parent;
33293 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33302 +int vfsub_rmdir(struct inode *dir, struct path *path)
33305 + struct dentry *d;
33309 + d = path->dentry;
33310 + path->dentry = d->d_parent;
33311 + err = security_path_rmdir(path, d);
33312 + path->dentry = d;
33313 + if (unlikely(err))
33317 + err = vfs_rmdir(dir, path->dentry);
33320 + struct path tmp = {
33321 + .dentry = path->dentry->d_parent,
33325 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33332 +/* ---------------------------------------------------------------------- */
33334 +/* todo: support mmap_sem? */
33335 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33341 + err = vfs_read(file, ubuf, count, ppos);
33344 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33348 +/* todo: kernel_read()? */
33349 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33353 + mm_segment_t oldfs;
33360 + oldfs = get_fs();
33361 + set_fs(KERNEL_DS);
33362 + err = vfsub_read_u(file, buf.u, count, ppos);
33367 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33373 + err = vfs_write(file, ubuf, count, ppos);
33376 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33380 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33383 + mm_segment_t oldfs;
33386 + const char __user *u;
33390 + oldfs = get_fs();
33391 + set_fs(KERNEL_DS);
33392 + err = vfsub_write_u(file, buf.u, count, ppos);
33397 +int vfsub_flush(struct file *file, fl_owner_t id)
33402 + if (file->f_op->flush) {
33403 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33404 + err = file->f_op->flush(file, id);
33407 + err = file->f_op->flush(file, id);
33411 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33417 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33421 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33424 + err = iterate_dir(file, ctx);
33427 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33432 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33433 + struct pipe_inode_info *pipe, size_t len,
33434 + unsigned int flags)
33439 + err = do_splice_to(in, ppos, pipe, len, flags);
33441 + file_accessed(in);
33443 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33447 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33448 + loff_t *ppos, size_t len, unsigned int flags)
33453 + err = do_splice_from(pipe, out, ppos, len, flags);
33456 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33460 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33464 + /* file can be NULL */
33466 + err = vfs_fsync(file, datasync);
33470 + AuDebugOn(!file);
33471 + path = &file->f_path;
33473 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33478 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33479 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33480 + struct file *h_file)
33483 + struct inode *h_inode;
33484 + struct super_block *h_sb;
33487 + err = vfsub_truncate(h_path, length);
33491 + h_inode = d_inode(h_path->dentry);
33492 + h_sb = h_inode->i_sb;
33494 + sb_start_write(h_sb);
33496 + err = locks_verify_truncate(h_inode, h_file, length);
33498 + err = security_path_truncate(h_path);
33501 + err = do_truncate(h_path->dentry, length, attr, h_file);
33505 + sb_end_write(h_sb);
33512 +/* ---------------------------------------------------------------------- */
33514 +struct au_vfsub_mkdir_args {
33516 + struct inode *dir;
33517 + struct path *path;
33521 +static void au_call_vfsub_mkdir(void *args)
33523 + struct au_vfsub_mkdir_args *a = args;
33524 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33527 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33529 + int err, do_sio, wkq_err;
33531 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33534 + err = vfsub_mkdir(dir, path, mode);
33537 + struct au_vfsub_mkdir_args args = {
33543 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33544 + if (unlikely(wkq_err))
33551 +struct au_vfsub_rmdir_args {
33553 + struct inode *dir;
33554 + struct path *path;
33557 +static void au_call_vfsub_rmdir(void *args)
33559 + struct au_vfsub_rmdir_args *a = args;
33560 + *a->errp = vfsub_rmdir(a->dir, a->path);
33563 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33565 + int err, do_sio, wkq_err;
33567 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33570 + err = vfsub_rmdir(dir, path);
33573 + struct au_vfsub_rmdir_args args = {
33578 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33579 + if (unlikely(wkq_err))
33586 +/* ---------------------------------------------------------------------- */
33588 +struct notify_change_args {
33590 + struct path *path;
33591 + struct iattr *ia;
33592 + struct inode **delegated_inode;
33595 +static void call_notify_change(void *args)
33597 + struct notify_change_args *a = args;
33598 + struct inode *h_inode;
33600 + h_inode = d_inode(a->path->dentry);
33601 + IMustLock(h_inode);
33603 + *a->errp = -EPERM;
33604 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33606 + *a->errp = notify_change(a->path->dentry, a->ia,
33607 + a->delegated_inode);
33610 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33612 + AuTraceErr(*a->errp);
33615 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33616 + struct inode **delegated_inode)
33619 + struct notify_change_args args = {
33623 + .delegated_inode = delegated_inode
33626 + call_notify_change(&args);
33631 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33632 + struct inode **delegated_inode)
33634 + int err, wkq_err;
33635 + struct notify_change_args args = {
33639 + .delegated_inode = delegated_inode
33642 + wkq_err = au_wkq_wait(call_notify_change, &args);
33643 + if (unlikely(wkq_err))
33649 +/* ---------------------------------------------------------------------- */
33651 +struct unlink_args {
33653 + struct inode *dir;
33654 + struct path *path;
33655 + struct inode **delegated_inode;
33658 +static void call_unlink(void *args)
33660 + struct unlink_args *a = args;
33661 + struct dentry *d = a->path->dentry;
33662 + struct inode *h_inode;
33663 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33664 + && au_dcount(d) == 1);
33666 + IMustLock(a->dir);
33668 + a->path->dentry = d->d_parent;
33669 + *a->errp = security_path_unlink(a->path, d);
33670 + a->path->dentry = d;
33671 + if (unlikely(*a->errp))
33674 + if (!stop_sillyrename)
33677 + if (d_is_positive(d)) {
33678 + h_inode = d_inode(d);
33683 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33686 + struct path tmp = {
33687 + .dentry = d->d_parent,
33688 + .mnt = a->path->mnt
33690 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33693 + if (!stop_sillyrename)
33698 + AuTraceErr(*a->errp);
33702 + * @dir: must be locked.
33703 + * @dentry: target dentry.
33705 +int vfsub_unlink(struct inode *dir, struct path *path,
33706 + struct inode **delegated_inode, int force)
33709 + struct unlink_args args = {
33713 + .delegated_inode = delegated_inode
33717 + call_unlink(&args);
33721 + wkq_err = au_wkq_wait(call_unlink, &args);
33722 + if (unlikely(wkq_err))
33728 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33729 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33730 +++ linux/fs/aufs/vfsub.h 2018-12-27 13:19:17.711749485 +0100
33732 +/* SPDX-License-Identifier: GPL-2.0 */
33734 + * Copyright (C) 2005-2018 Junjiro R. Okajima
33736 + * This program, aufs is free software; you can redistribute it and/or modify
33737 + * it under the terms of the GNU General Public License as published by
33738 + * the Free Software Foundation; either version 2 of the License, or
33739 + * (at your option) any later version.
33741 + * This program is distributed in the hope that it will be useful,
33742 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33743 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33744 + * GNU General Public License for more details.
33746 + * You should have received a copy of the GNU General Public License
33747 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33751 + * sub-routines for VFS
33754 +#ifndef __AUFS_VFSUB_H__
33755 +#define __AUFS_VFSUB_H__
33759 +#include <linux/fs.h>
33760 +#include <linux/iversion.h>
33761 +#include <linux/mount.h>
33762 +#include <linux/posix_acl.h>
33763 +#include <linux/xattr.h>
33764 +#include "debug.h"
33766 +/* copied from linux/fs/internal.h */
33767 +/* todo: BAD approach!! */
33768 +extern void __mnt_drop_write(struct vfsmount *);
33769 +extern struct file *alloc_empty_file(int, const struct cred *);
33771 +/* ---------------------------------------------------------------------- */
33773 +/* lock subclass for lower inode */
33774 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33775 +/* reduce? gave up. */
33777 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33778 + AuLsc_I_PARENT, /* lower inode, parent first */
33779 + AuLsc_I_PARENT2, /* copyup dirs */
33780 + AuLsc_I_PARENT3, /* copyup wh */
33786 +/* to debug easier, do not make them inlined functions */
33787 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33788 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33790 +/* ---------------------------------------------------------------------- */
33792 +static inline void vfsub_drop_nlink(struct inode *inode)
33794 + AuDebugOn(!inode->i_nlink);
33795 + drop_nlink(inode);
33798 +static inline void vfsub_dead_dir(struct inode *inode)
33800 + AuDebugOn(!S_ISDIR(inode->i_mode));
33801 + inode->i_flags |= S_DEAD;
33802 + clear_nlink(inode);
33805 +static inline int vfsub_native_ro(struct inode *inode)
33807 + return sb_rdonly(inode->i_sb)
33808 + || IS_RDONLY(inode)
33809 + /* || IS_APPEND(inode) */
33810 + || IS_IMMUTABLE(inode);
33813 +#ifdef CONFIG_AUFS_BR_FUSE
33814 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33816 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33819 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33821 +/* ---------------------------------------------------------------------- */
33823 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33824 +struct file *vfsub_dentry_open(struct path *path, int flags);
33825 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33827 +struct vfsub_aopen_args {
33828 + struct file *file;
33829 + unsigned int open_flag;
33830 + umode_t create_mode;
33831 + struct au_branch *br;
33833 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33834 + struct vfsub_aopen_args *args);
33835 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33837 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33838 + struct dentry *parent, int len);
33839 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33842 +struct vfsub_lkup_one_args {
33843 + struct dentry **errp;
33844 + struct qstr *name;
33845 + struct dentry *parent;
33848 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33849 + struct dentry *parent)
33851 + return vfsub_lookup_one_len(name->name, parent, name->len);
33854 +void vfsub_call_lkup_one(void *args);
33856 +/* ---------------------------------------------------------------------- */
33858 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33863 + err = mnt_want_write(mnt);
33868 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33871 + mnt_drop_write(mnt);
33875 +#if 0 /* reserved */
33876 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33879 + mnt_drop_write_file(file);
33884 +/* ---------------------------------------------------------------------- */
33887 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33888 + struct dentry *d2, struct au_hinode *hdir2);
33889 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33890 + struct dentry *d2, struct au_hinode *hdir2);
33892 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33894 +int vfsub_symlink(struct inode *dir, struct path *path,
33895 + const char *symname);
33896 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33897 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33898 + struct path *path, struct inode **delegated_inode);
33899 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33900 + struct inode *hdir, struct path *path,
33901 + struct inode **delegated_inode, unsigned int flags);
33902 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33903 +int vfsub_rmdir(struct inode *dir, struct path *path);
33905 +/* ---------------------------------------------------------------------- */
33907 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33909 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33911 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33913 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33915 +int vfsub_flush(struct file *file, fl_owner_t id);
33916 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33918 +static inline loff_t vfsub_f_size_read(struct file *file)
33920 + return i_size_read(file_inode(file));
33923 +static inline unsigned int vfsub_file_flags(struct file *file)
33925 + unsigned int flags;
33927 + spin_lock(&file->f_lock);
33928 + flags = file->f_flags;
33929 + spin_unlock(&file->f_lock);
33934 +static inline int vfsub_file_execed(struct file *file)
33936 + /* todo: direct access f_flags */
33937 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33940 +#if 0 /* reserved */
33941 +static inline void vfsub_file_accessed(struct file *h_file)
33943 + file_accessed(h_file);
33944 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33948 +#if 0 /* reserved */
33949 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33950 + struct dentry *h_dentry)
33952 + struct path h_path = {
33953 + .dentry = h_dentry,
33956 + touch_atime(&h_path);
33957 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33961 +static inline int vfsub_update_time(struct inode *h_inode,
33962 + struct timespec64 *ts, int flags)
33964 + return update_time(h_inode, ts, flags);
33965 + /* no vfsub_update_h_iattr() since we don't have struct path */
33968 +#ifdef CONFIG_FS_POSIX_ACL
33969 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33973 + err = posix_acl_chmod(h_inode, h_mode);
33974 + if (err == -EOPNOTSUPP)
33979 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33982 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33983 + struct pipe_inode_info *pipe, size_t len,
33984 + unsigned int flags);
33985 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33986 + loff_t *ppos, size_t len, unsigned int flags);
33988 +static inline long vfsub_truncate(struct path *path, loff_t length)
33993 + err = vfs_truncate(path, length);
33998 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33999 + struct file *h_file);
34000 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
34003 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
34006 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
34012 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
34018 +/* copy_file_range(2) is a systemcall */
34019 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
34020 + struct file *dst, loff_t dst_pos,
34021 + size_t len, unsigned int flags)
34026 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
34032 +/* ---------------------------------------------------------------------- */
34034 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
34039 + err = vfs_llseek(file, offset, origin);
34044 +/* ---------------------------------------------------------------------- */
34046 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
34047 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
34048 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
34049 + struct inode **delegated_inode);
34050 +int vfsub_notify_change(struct path *path, struct iattr *ia,
34051 + struct inode **delegated_inode);
34052 +int vfsub_unlink(struct inode *dir, struct path *path,
34053 + struct inode **delegated_inode, int force);
34055 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
34057 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
34060 +/* ---------------------------------------------------------------------- */
34062 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
34063 + const void *value, size_t size, int flags)
34068 + err = vfs_setxattr(dentry, name, value, size, flags);
34074 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
34079 + err = vfs_removexattr(dentry, name);
34085 +#endif /* __KERNEL__ */
34086 +#endif /* __AUFS_VFSUB_H__ */
34087 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
34088 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
34089 +++ linux/fs/aufs/wbr_policy.c 2018-12-27 13:19:17.711749485 +0100
34091 +// SPDX-License-Identifier: GPL-2.0
34093 + * Copyright (C) 2005-2018 Junjiro R. Okajima
34095 + * This program, aufs is free software; you can redistribute it and/or modify
34096 + * it under the terms of the GNU General Public License as published by
34097 + * the Free Software Foundation; either version 2 of the License, or
34098 + * (at your option) any later version.
34100 + * This program is distributed in the hope that it will be useful,
34101 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34102 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34103 + * GNU General Public License for more details.
34105 + * You should have received a copy of the GNU General Public License
34106 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34110 + * policies for selecting one among multiple writable branches
34113 +#include <linux/statfs.h>
34116 +/* subset of cpup_attr() */
34117 +static noinline_for_stack
34118 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34122 + struct inode *h_isrc;
34124 + h_isrc = d_inode(h_src);
34125 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34126 + ia.ia_mode = h_isrc->i_mode;
34127 + ia.ia_uid = h_isrc->i_uid;
34128 + ia.ia_gid = h_isrc->i_gid;
34129 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34130 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34131 + /* no delegation since it is just created */
34132 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34134 + /* is this nfs only? */
34135 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34136 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34137 + ia.ia_mode = h_isrc->i_mode;
34138 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34144 +#define AuCpdown_PARENT_OPQ 1
34145 +#define AuCpdown_WHED (1 << 1)
34146 +#define AuCpdown_MADE_DIR (1 << 2)
34147 +#define AuCpdown_DIROPQ (1 << 3)
34148 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34149 +#define au_fset_cpdown(flags, name) \
34150 + do { (flags) |= AuCpdown_##name; } while (0)
34151 +#define au_fclr_cpdown(flags, name) \
34152 + do { (flags) &= ~AuCpdown_##name; } while (0)
34154 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34155 + unsigned int *flags)
34158 + struct dentry *opq_dentry;
34160 + opq_dentry = au_diropq_create(dentry, bdst);
34161 + err = PTR_ERR(opq_dentry);
34162 + if (IS_ERR(opq_dentry))
34164 + dput(opq_dentry);
34165 + au_fset_cpdown(*flags, DIROPQ);
34171 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34172 + struct inode *dir, aufs_bindex_t bdst)
34175 + struct path h_path;
34176 + struct au_branch *br;
34178 + br = au_sbr(dentry->d_sb, bdst);
34179 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34180 + err = PTR_ERR(h_path.dentry);
34181 + if (IS_ERR(h_path.dentry))
34185 + if (d_is_positive(h_path.dentry)) {
34186 + h_path.mnt = au_br_mnt(br);
34187 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34190 + dput(h_path.dentry);
34196 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34197 + struct au_pin *pin,
34198 + struct dentry *h_parent, void *arg)
34201 + aufs_bindex_t bopq, btop;
34202 + struct path h_path;
34203 + struct dentry *parent;
34204 + struct inode *h_dir, *h_inode, *inode, *dir;
34205 + unsigned int *flags = arg;
34207 + btop = au_dbtop(dentry);
34208 + /* dentry is di-locked */
34209 + parent = dget_parent(dentry);
34210 + dir = d_inode(parent);
34211 + h_dir = d_inode(h_parent);
34212 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34213 + IMustLock(h_dir);
34215 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34216 + if (unlikely(err < 0))
34218 + h_path.dentry = au_h_dptr(dentry, bdst);
34219 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34220 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34221 + if (unlikely(err))
34223 + au_fset_cpdown(*flags, MADE_DIR);
34225 + bopq = au_dbdiropq(dentry);
34226 + au_fclr_cpdown(*flags, WHED);
34227 + au_fclr_cpdown(*flags, DIROPQ);
34228 + if (au_dbwh(dentry) == bdst)
34229 + au_fset_cpdown(*flags, WHED);
34230 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34231 + au_fset_cpdown(*flags, PARENT_OPQ);
34232 + h_inode = d_inode(h_path.dentry);
34233 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34234 + if (au_ftest_cpdown(*flags, WHED)) {
34235 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34236 + if (unlikely(err)) {
34237 + inode_unlock(h_inode);
34242 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34243 + inode_unlock(h_inode);
34244 + if (unlikely(err))
34247 + if (au_ftest_cpdown(*flags, WHED)) {
34248 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34249 + if (unlikely(err))
34253 + inode = d_inode(dentry);
34254 + if (au_ibbot(inode) < bdst)
34255 + au_set_ibbot(inode, bdst);
34256 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34257 + au_hi_flags(inode, /*isdir*/1));
34258 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34259 + goto out; /* success */
34263 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34264 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34265 + rerr = au_diropq_remove(dentry, bdst);
34266 + inode_unlock(h_inode);
34267 + if (unlikely(rerr)) {
34268 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34269 + dentry, bdst, rerr);
34275 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34276 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34277 + if (unlikely(rerr)) {
34278 + AuIOErr("failed removing %pd b%d (%d)\n",
34279 + dentry, bdst, rerr);
34284 + au_set_h_dptr(dentry, bdst, NULL);
34285 + if (au_dbbot(dentry) == bdst)
34286 + au_update_dbbot(dentry);
34292 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34295 + unsigned int flags;
34298 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34303 +/* ---------------------------------------------------------------------- */
34305 +/* policies for create */
34307 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34309 + int err, i, j, ndentry;
34310 + aufs_bindex_t bopq;
34311 + struct au_dcsub_pages dpages;
34312 + struct au_dpage *dpage;
34313 + struct dentry **dentries, *parent, *d;
34315 + err = au_dpages_init(&dpages, GFP_NOFS);
34316 + if (unlikely(err))
34318 + parent = dget_parent(dentry);
34319 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34320 + if (unlikely(err))
34324 + for (i = 0; i < dpages.ndpage; i++) {
34325 + dpage = dpages.dpages + i;
34326 + dentries = dpage->dentries;
34327 + ndentry = dpage->ndentry;
34328 + for (j = 0; j < ndentry; j++) {
34330 + di_read_lock_parent2(d, !AuLock_IR);
34331 + bopq = au_dbdiropq(d);
34332 + di_read_unlock(d, !AuLock_IR);
34333 + if (bopq >= 0 && bopq < err)
34340 + au_dpages_free(&dpages);
34345 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34347 + for (; bindex >= 0; bindex--)
34348 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34353 +/* top down parent */
34354 +static int au_wbr_create_tdp(struct dentry *dentry,
34355 + unsigned int flags __maybe_unused)
34358 + aufs_bindex_t btop, bindex;
34359 + struct super_block *sb;
34360 + struct dentry *parent, *h_parent;
34362 + sb = dentry->d_sb;
34363 + btop = au_dbtop(dentry);
34365 + if (!au_br_rdonly(au_sbr(sb, btop)))
34369 + parent = dget_parent(dentry);
34370 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34371 + h_parent = au_h_dptr(parent, bindex);
34372 + if (!h_parent || d_is_negative(h_parent))
34375 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34382 + /* bottom up here */
34383 + if (unlikely(err < 0)) {
34384 + err = au_wbr_bu(sb, btop - 1);
34386 + err = au_wbr_nonopq(dentry, err);
34390 + AuDbg("b%d\n", err);
34394 +/* ---------------------------------------------------------------------- */
34396 +/* an exception for the policy other than tdp */
34397 +static int au_wbr_create_exp(struct dentry *dentry)
34400 + aufs_bindex_t bwh, bdiropq;
34401 + struct dentry *parent;
34404 + bwh = au_dbwh(dentry);
34405 + parent = dget_parent(dentry);
34406 + bdiropq = au_dbdiropq(parent);
34408 + if (bdiropq >= 0)
34409 + err = min(bdiropq, bwh);
34412 + AuDbg("%d\n", err);
34413 + } else if (bdiropq >= 0) {
34415 + AuDbg("%d\n", err);
34420 + err = au_wbr_nonopq(dentry, err);
34422 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34425 + AuDbg("%d\n", err);
34429 +/* ---------------------------------------------------------------------- */
34432 +static int au_wbr_create_init_rr(struct super_block *sb)
34436 + err = au_wbr_bu(sb, au_sbbot(sb));
34437 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34440 + AuDbg("b%d\n", err);
34444 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34448 + aufs_bindex_t bindex, bbot;
34449 + struct super_block *sb;
34452 + err = au_wbr_create_exp(dentry);
34456 + sb = dentry->d_sb;
34457 + next = &au_sbi(sb)->si_wbr_rr_next;
34458 + bbot = au_sbbot(sb);
34460 + for (bindex = 0; bindex <= bbot; bindex++) {
34461 + if (!au_ftest_wbr(flags, DIR)) {
34462 + err = atomic_dec_return(next) + 1;
34463 + /* modulo for 0 is meaningless */
34464 + if (unlikely(!err))
34465 + err = atomic_dec_return(next) + 1;
34467 + err = atomic_read(next);
34468 + AuDbg("%d\n", err);
34471 + AuDbg("%d\n", err);
34472 + if (!au_br_rdonly(au_sbr(sb, err)))
34478 + err = au_wbr_nonopq(dentry, err);
34481 + AuDbg("%d\n", err);
34485 +/* ---------------------------------------------------------------------- */
34487 +/* most free space */
34488 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34490 + struct super_block *sb;
34491 + struct au_branch *br;
34492 + struct au_wbr_mfs *mfs;
34493 + struct dentry *h_parent;
34494 + aufs_bindex_t bindex, bbot;
34496 + unsigned long long b, bavail;
34497 + struct path h_path;
34498 + /* reduce the stack usage */
34499 + struct kstatfs *st;
34501 + st = kmalloc(sizeof(*st), GFP_NOFS);
34502 + if (unlikely(!st)) {
34503 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34508 + sb = dentry->d_sb;
34509 + mfs = &au_sbi(sb)->si_wbr_mfs;
34510 + MtxMustLock(&mfs->mfs_lock);
34511 + mfs->mfs_bindex = -EROFS;
34512 + mfs->mfsrr_bytes = 0;
34515 + bbot = au_sbbot(sb);
34517 + bindex = au_dbtop(parent);
34518 + bbot = au_dbtaildir(parent);
34521 + for (; bindex <= bbot; bindex++) {
34523 + h_parent = au_h_dptr(parent, bindex);
34524 + if (!h_parent || d_is_negative(h_parent))
34527 + br = au_sbr(sb, bindex);
34528 + if (au_br_rdonly(br))
34531 + /* sb->s_root for NFS is unreliable */
34532 + h_path.mnt = au_br_mnt(br);
34533 + h_path.dentry = h_path.mnt->mnt_root;
34534 + err = vfs_statfs(&h_path, st);
34535 + if (unlikely(err)) {
34536 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34540 + /* when the available size is equal, select the lower one */
34541 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34542 + || sizeof(b) < sizeof(st->f_bsize));
34543 + b = st->f_bavail * st->f_bsize;
34544 + br->br_wbr->wbr_bytes = b;
34545 + if (b >= bavail) {
34547 + mfs->mfs_bindex = bindex;
34548 + mfs->mfs_jiffy = jiffies;
34552 + mfs->mfsrr_bytes = bavail;
34553 + AuDbg("b%d\n", mfs->mfs_bindex);
34554 + au_kfree_rcu(st);
34557 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34560 + struct dentry *parent;
34561 + struct super_block *sb;
34562 + struct au_wbr_mfs *mfs;
34564 + err = au_wbr_create_exp(dentry);
34568 + sb = dentry->d_sb;
34570 + if (au_ftest_wbr(flags, PARENT))
34571 + parent = dget_parent(dentry);
34572 + mfs = &au_sbi(sb)->si_wbr_mfs;
34573 + mutex_lock(&mfs->mfs_lock);
34574 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34575 + || mfs->mfs_bindex < 0
34576 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34577 + au_mfs(dentry, parent);
34578 + mutex_unlock(&mfs->mfs_lock);
34579 + err = mfs->mfs_bindex;
34583 + err = au_wbr_nonopq(dentry, err);
34586 + AuDbg("b%d\n", err);
34590 +static int au_wbr_create_init_mfs(struct super_block *sb)
34592 + struct au_wbr_mfs *mfs;
34594 + mfs = &au_sbi(sb)->si_wbr_mfs;
34595 + mutex_init(&mfs->mfs_lock);
34596 + mfs->mfs_jiffy = 0;
34597 + mfs->mfs_bindex = -EROFS;
34602 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34604 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34608 +/* ---------------------------------------------------------------------- */
34610 +/* top down regardless parent, and then mfs */
34611 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34612 + unsigned int flags __maybe_unused)
34615 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34616 + unsigned long long watermark;
34617 + struct super_block *sb;
34618 + struct au_wbr_mfs *mfs;
34619 + struct au_branch *br;
34620 + struct dentry *parent;
34622 + sb = dentry->d_sb;
34623 + mfs = &au_sbi(sb)->si_wbr_mfs;
34624 + mutex_lock(&mfs->mfs_lock);
34625 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34626 + || mfs->mfs_bindex < 0)
34627 + au_mfs(dentry, /*parent*/NULL);
34628 + watermark = mfs->mfsrr_watermark;
34629 + bmfs = mfs->mfs_bindex;
34630 + mutex_unlock(&mfs->mfs_lock);
34632 + /* another style of au_wbr_create_exp() */
34633 + bwh = au_dbwh(dentry);
34634 + parent = dget_parent(dentry);
34635 + btail = au_dbtaildir(parent);
34636 + if (bwh >= 0 && bwh < btail)
34639 + err = au_wbr_nonopq(dentry, btail);
34640 + if (unlikely(err < 0))
34644 + for (bindex = 0; bindex <= btail; bindex++) {
34645 + br = au_sbr(sb, bindex);
34646 + if (au_br_rdonly(br))
34648 + if (br->br_wbr->wbr_bytes > watermark) {
34659 + AuDbg("b%d\n", err);
34663 +/* ---------------------------------------------------------------------- */
34665 +/* most free space and then round robin */
34666 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34669 + struct au_wbr_mfs *mfs;
34671 + err = au_wbr_create_mfs(dentry, flags);
34673 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34674 + mutex_lock(&mfs->mfs_lock);
34675 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34676 + err = au_wbr_create_rr(dentry, flags);
34677 + mutex_unlock(&mfs->mfs_lock);
34680 + AuDbg("b%d\n", err);
34684 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34688 + au_wbr_create_init_mfs(sb); /* ignore */
34689 + err = au_wbr_create_init_rr(sb);
34694 +/* ---------------------------------------------------------------------- */
34696 +/* top down parent and most free space */
34697 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34700 + unsigned long long b;
34701 + aufs_bindex_t bindex, btop, bbot;
34702 + struct super_block *sb;
34703 + struct dentry *parent, *h_parent;
34704 + struct au_branch *br;
34706 + err = au_wbr_create_tdp(dentry, flags);
34707 + if (unlikely(err < 0))
34709 + parent = dget_parent(dentry);
34710 + btop = au_dbtop(parent);
34711 + bbot = au_dbtaildir(parent);
34712 + if (btop == bbot)
34713 + goto out_parent; /* success */
34715 + e2 = au_wbr_create_mfs(dentry, flags);
34717 + goto out_parent; /* success */
34719 + /* when the available size is equal, select upper one */
34720 + sb = dentry->d_sb;
34721 + br = au_sbr(sb, err);
34722 + b = br->br_wbr->wbr_bytes;
34723 + AuDbg("b%d, %llu\n", err, b);
34725 + for (bindex = btop; bindex <= bbot; bindex++) {
34726 + h_parent = au_h_dptr(parent, bindex);
34727 + if (!h_parent || d_is_negative(h_parent))
34730 + br = au_sbr(sb, bindex);
34731 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34732 + b = br->br_wbr->wbr_bytes;
34734 + AuDbg("b%d, %llu\n", err, b);
34739 + err = au_wbr_nonopq(dentry, err);
34744 + AuDbg("b%d\n", err);
34748 +/* ---------------------------------------------------------------------- */
34751 + * - top down parent
34752 + * - most free space with parent
34753 + * - most free space round-robin regardless parent
34755 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34758 + unsigned long long watermark;
34759 + struct super_block *sb;
34760 + struct au_branch *br;
34761 + struct au_wbr_mfs *mfs;
34763 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34764 + if (unlikely(err < 0))
34767 + sb = dentry->d_sb;
34768 + br = au_sbr(sb, err);
34769 + mfs = &au_sbi(sb)->si_wbr_mfs;
34770 + mutex_lock(&mfs->mfs_lock);
34771 + watermark = mfs->mfsrr_watermark;
34772 + mutex_unlock(&mfs->mfs_lock);
34773 + if (br->br_wbr->wbr_bytes < watermark)
34774 + /* regardless the parent dir */
34775 + err = au_wbr_create_mfsrr(dentry, flags);
34778 + AuDbg("b%d\n", err);
34782 +/* ---------------------------------------------------------------------- */
34784 +/* policies for copyup */
34786 +/* top down parent */
34787 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34789 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34792 +/* bottom up parent */
34793 +static int au_wbr_copyup_bup(struct dentry *dentry)
34796 + aufs_bindex_t bindex, btop;
34797 + struct dentry *parent, *h_parent;
34798 + struct super_block *sb;
34801 + sb = dentry->d_sb;
34802 + parent = dget_parent(dentry);
34803 + btop = au_dbtop(parent);
34804 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34805 + h_parent = au_h_dptr(parent, bindex);
34806 + if (!h_parent || d_is_negative(h_parent))
34809 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34816 + /* bottom up here */
34817 + if (unlikely(err < 0))
34818 + err = au_wbr_bu(sb, btop - 1);
34820 + AuDbg("b%d\n", err);
34825 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34829 + err = au_wbr_bu(dentry->d_sb, btop);
34830 + AuDbg("b%d\n", err);
34832 + err = au_wbr_nonopq(dentry, err);
34834 + AuDbg("b%d\n", err);
34838 +static int au_wbr_copyup_bu(struct dentry *dentry)
34841 + aufs_bindex_t btop;
34843 + btop = au_dbtop(dentry);
34844 + err = au_wbr_do_copyup_bu(dentry, btop);
34848 +/* ---------------------------------------------------------------------- */
34850 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34851 + [AuWbrCopyup_TDP] = {
34852 + .copyup = au_wbr_copyup_tdp
34854 + [AuWbrCopyup_BUP] = {
34855 + .copyup = au_wbr_copyup_bup
34857 + [AuWbrCopyup_BU] = {
34858 + .copyup = au_wbr_copyup_bu
34862 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34863 + [AuWbrCreate_TDP] = {
34864 + .create = au_wbr_create_tdp
34866 + [AuWbrCreate_RR] = {
34867 + .create = au_wbr_create_rr,
34868 + .init = au_wbr_create_init_rr
34870 + [AuWbrCreate_MFS] = {
34871 + .create = au_wbr_create_mfs,
34872 + .init = au_wbr_create_init_mfs,
34873 + .fin = au_wbr_create_fin_mfs
34875 + [AuWbrCreate_MFSV] = {
34876 + .create = au_wbr_create_mfs,
34877 + .init = au_wbr_create_init_mfs,
34878 + .fin = au_wbr_create_fin_mfs
34880 + [AuWbrCreate_MFSRR] = {
34881 + .create = au_wbr_create_mfsrr,
34882 + .init = au_wbr_create_init_mfsrr,
34883 + .fin = au_wbr_create_fin_mfs
34885 + [AuWbrCreate_MFSRRV] = {
34886 + .create = au_wbr_create_mfsrr,
34887 + .init = au_wbr_create_init_mfsrr,
34888 + .fin = au_wbr_create_fin_mfs
34890 + [AuWbrCreate_TDMFS] = {
34891 + .create = au_wbr_create_tdmfs,
34892 + .init = au_wbr_create_init_mfs,
34893 + .fin = au_wbr_create_fin_mfs
34895 + [AuWbrCreate_TDMFSV] = {
34896 + .create = au_wbr_create_tdmfs,
34897 + .init = au_wbr_create_init_mfs,
34898 + .fin = au_wbr_create_fin_mfs
34900 + [AuWbrCreate_PMFS] = {
34901 + .create = au_wbr_create_pmfs,
34902 + .init = au_wbr_create_init_mfs,
34903 + .fin = au_wbr_create_fin_mfs
34905 + [AuWbrCreate_PMFSV] = {
34906 + .create = au_wbr_create_pmfs,
34907 + .init = au_wbr_create_init_mfs,
34908 + .fin = au_wbr_create_fin_mfs
34910 + [AuWbrCreate_PMFSRR] = {
34911 + .create = au_wbr_create_pmfsrr,
34912 + .init = au_wbr_create_init_mfsrr,
34913 + .fin = au_wbr_create_fin_mfs
34915 + [AuWbrCreate_PMFSRRV] = {
34916 + .create = au_wbr_create_pmfsrr,
34917 + .init = au_wbr_create_init_mfsrr,
34918 + .fin = au_wbr_create_fin_mfs
34921 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34922 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34923 +++ linux/fs/aufs/whout.c 2018-12-27 13:19:17.711749485 +0100
34925 +// SPDX-License-Identifier: GPL-2.0
34927 + * Copyright (C) 2005-2018 Junjiro R. Okajima
34929 + * This program, aufs is free software; you can redistribute it and/or modify
34930 + * it under the terms of the GNU General Public License as published by
34931 + * the Free Software Foundation; either version 2 of the License, or
34932 + * (at your option) any later version.
34934 + * This program is distributed in the hope that it will be useful,
34935 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34936 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34937 + * GNU General Public License for more details.
34939 + * You should have received a copy of the GNU General Public License
34940 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34944 + * whiteout for logical deletion and opaque directory
34949 +#define WH_MASK 0444
34952 + * If a directory contains this file, then it is opaque. We start with the
34953 + * .wh. flag so that it is blocked by lookup.
34955 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34956 + sizeof(AUFS_WH_DIROPQ) - 1);
34959 + * generate whiteout name, which is NOT terminated by NULL.
34960 + * @name: original d_name.name
34961 + * @len: original d_name.len
34962 + * @wh: whiteout qstr
34963 + * returns zero when succeeds, otherwise error.
34964 + * succeeded value as wh->name should be freed by kfree().
34966 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34970 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34971 + return -ENAMETOOLONG;
34973 + wh->len = name->len + AUFS_WH_PFX_LEN;
34974 + p = kmalloc(wh->len, GFP_NOFS);
34977 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34978 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34985 +/* ---------------------------------------------------------------------- */
34988 + * test if the @wh_name exists under @h_parent.
34989 + * @try_sio specifies the necessary of super-io.
34991 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
34994 + struct dentry *wh_dentry;
34997 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34999 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
35000 + err = PTR_ERR(wh_dentry);
35001 + if (IS_ERR(wh_dentry)) {
35002 + if (err == -ENAMETOOLONG)
35008 + if (d_is_negative(wh_dentry))
35009 + goto out_wh; /* success */
35012 + if (d_is_reg(wh_dentry))
35013 + goto out_wh; /* success */
35016 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
35017 + wh_dentry, d_inode(wh_dentry)->i_mode);
35026 + * test if the @h_dentry sets opaque or not.
35028 +int au_diropq_test(struct dentry *h_dentry)
35031 + struct inode *h_dir;
35033 + h_dir = d_inode(h_dentry);
35034 + err = au_wh_test(h_dentry, &diropq_name,
35035 + au_test_h_perm_sio(h_dir, MAY_EXEC));
35040 + * returns a negative dentry whose name is unique and temporary.
35042 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35043 + struct qstr *prefix)
35045 + struct dentry *dentry;
35047 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
35049 + /* strict atomic_t is unnecessary here */
35050 + static unsigned short cnt;
35053 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
35056 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
35057 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
35058 + dentry = ERR_PTR(-ENAMETOOLONG);
35059 + if (unlikely(qs.len > NAME_MAX))
35061 + dentry = ERR_PTR(-ENOMEM);
35062 + name = kmalloc(qs.len + 1, GFP_NOFS);
35063 + if (unlikely(!name))
35067 + /* doubly whiteout-ed */
35068 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
35069 + p = name + AUFS_WH_PFX_LEN * 2;
35070 + memcpy(p, prefix->name, prefix->len);
35071 + p += prefix->len;
35073 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
35076 + for (i = 0; i < 3; i++) {
35077 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
35078 + dentry = au_sio_lkup_one(&qs, h_parent);
35079 + if (IS_ERR(dentry) || d_is_negative(dentry))
35083 + /* pr_warn("could not get random name\n"); */
35084 + dentry = ERR_PTR(-EEXIST);
35085 + AuDbg("%.*s\n", AuLNPair(&qs));
35089 + if (name != defname)
35090 + au_kfree_try_rcu(name);
35092 + AuTraceErrPtr(dentry);
35097 + * rename the @h_dentry on @br to the whiteouted temporary name.
35099 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
35102 + struct path h_path = {
35103 + .mnt = au_br_mnt(br)
35105 + struct inode *h_dir, *delegated;
35106 + struct dentry *h_parent;
35108 + h_parent = h_dentry->d_parent; /* dir inode is locked */
35109 + h_dir = d_inode(h_parent);
35110 + IMustLock(h_dir);
35112 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35113 + err = PTR_ERR(h_path.dentry);
35114 + if (IS_ERR(h_path.dentry))
35117 + /* under the same dir, no need to lock_rename() */
35118 + delegated = NULL;
35119 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35122 + if (unlikely(err == -EWOULDBLOCK)) {
35123 + pr_warn("cannot retry for NFSv4 delegation"
35124 + " for an internal rename\n");
35127 + dput(h_path.dentry);
35134 +/* ---------------------------------------------------------------------- */
35136 + * functions for removing a whiteout
35139 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35142 + struct inode *delegated;
35145 + * forces superio when the dir has a sticky bit.
35146 + * this may be a violation of unix fs semantics.
35148 + force = (h_dir->i_mode & S_ISVTX)
35149 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35150 + delegated = NULL;
35151 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35152 + if (unlikely(err == -EWOULDBLOCK)) {
35153 + pr_warn("cannot retry for NFSv4 delegation"
35154 + " for an internal unlink\n");
35160 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35161 + struct dentry *dentry)
35165 + err = do_unlink_wh(h_dir, h_path);
35166 + if (!err && dentry)
35167 + au_set_dbwh(dentry, -1);
35172 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
35173 + struct au_branch *br)
35176 + struct path h_path = {
35177 + .mnt = au_br_mnt(br)
35181 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
35182 + if (IS_ERR(h_path.dentry))
35183 + err = PTR_ERR(h_path.dentry);
35185 + if (d_is_reg(h_path.dentry))
35186 + err = do_unlink_wh(d_inode(h_parent), &h_path);
35187 + dput(h_path.dentry);
35193 +/* ---------------------------------------------------------------------- */
35195 + * initialize/clean whiteout for a branch
35198 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35202 + struct inode *delegated;
35204 + if (d_is_negative(whpath->dentry))
35208 + err = vfsub_rmdir(h_dir, whpath);
35210 + delegated = NULL;
35211 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35212 + if (unlikely(err == -EWOULDBLOCK)) {
35213 + pr_warn("cannot retry for NFSv4 delegation"
35214 + " for an internal unlink\n");
35218 + if (unlikely(err))
35219 + pr_warn("failed removing %pd (%d), ignored.\n",
35220 + whpath->dentry, err);
35223 +static int test_linkable(struct dentry *h_root)
35225 + struct inode *h_dir = d_inode(h_root);
35227 + if (h_dir->i_op->link)
35230 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35231 + h_root, au_sbtype(h_root->d_sb));
35235 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35236 +static int au_whdir(struct inode *h_dir, struct path *path)
35241 + if (d_is_negative(path->dentry)) {
35244 + if (au_test_nfs(path->dentry->d_sb))
35246 + err = vfsub_mkdir(h_dir, path, mode);
35247 + } else if (d_is_dir(path->dentry))
35250 + pr_err("unknown %pd exists\n", path->dentry);
35255 +struct au_wh_base {
35256 + const struct qstr *name;
35257 + struct dentry *dentry;
35260 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35261 + struct path *h_path)
35263 + h_path->dentry = base[AuBrWh_BASE].dentry;
35264 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35265 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35266 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35267 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35268 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35272 + * returns tri-state,
35273 + * minus: error, caller should print the message
35275 + * plus: error, caller should NOT print the message
35277 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35278 + int do_plink, struct au_wh_base base[],
35279 + struct path *h_path)
35282 + struct inode *h_dir;
35284 + h_dir = d_inode(h_root);
35285 + h_path->dentry = base[AuBrWh_BASE].dentry;
35286 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35287 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35289 + err = test_linkable(h_root);
35290 + if (unlikely(err)) {
35295 + err = au_whdir(h_dir, h_path);
35296 + if (unlikely(err))
35298 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35300 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35301 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35302 + err = au_whdir(h_dir, h_path);
35303 + if (unlikely(err))
35305 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35312 + * for the moment, aufs supports the branch filesystem which does not support
35313 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35314 + * copyup failed. finally, such filesystem will not be used as the writable
35317 + * returns tri-state, see above.
35319 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35320 + int do_plink, struct au_wh_base base[],
35321 + struct path *h_path)
35324 + struct inode *h_dir;
35326 + WbrWhMustWriteLock(wbr);
35328 + err = test_linkable(h_root);
35329 + if (unlikely(err)) {
35335 + * todo: should this create be done in /sbin/mount.aufs helper?
35338 + h_dir = d_inode(h_root);
35339 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35340 + h_path->dentry = base[AuBrWh_BASE].dentry;
35341 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35342 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35345 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35346 + if (unlikely(err))
35349 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35351 + err = au_whdir(h_dir, h_path);
35352 + if (unlikely(err))
35354 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35356 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35357 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35359 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35360 + err = au_whdir(h_dir, h_path);
35361 + if (unlikely(err))
35363 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35370 + * initialize the whiteout base file/dir for @br.
35372 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35375 + const unsigned char do_plink
35376 + = !!au_opt_test(au_mntflags(sb), PLINK);
35377 + struct inode *h_dir;
35378 + struct path path = br->br_path;
35379 + struct dentry *h_root = path.dentry;
35380 + struct au_wbr *wbr = br->br_wbr;
35381 + static const struct qstr base_name[] = {
35382 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35383 + sizeof(AUFS_BASE_NAME) - 1),
35384 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35385 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35386 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35387 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35389 + struct au_wh_base base[] = {
35390 + [AuBrWh_BASE] = {
35391 + .name = base_name + AuBrWh_BASE,
35394 + [AuBrWh_PLINK] = {
35395 + .name = base_name + AuBrWh_PLINK,
35398 + [AuBrWh_ORPH] = {
35399 + .name = base_name + AuBrWh_ORPH,
35405 + WbrWhMustWriteLock(wbr);
35407 + for (i = 0; i < AuBrWh_Last; i++) {
35408 + /* doubly whiteouted */
35409 + struct dentry *d;
35411 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35412 + err = PTR_ERR(d);
35416 + base[i].dentry = d;
35418 + && wbr->wbr_wh[i]
35419 + && wbr->wbr_wh[i] != base[i].dentry);
35423 + for (i = 0; i < AuBrWh_Last; i++) {
35424 + dput(wbr->wbr_wh[i]);
35425 + wbr->wbr_wh[i] = NULL;
35429 + if (!au_br_writable(br->br_perm)) {
35430 + h_dir = d_inode(h_root);
35431 + au_wh_init_ro(h_dir, base, &path);
35432 + } else if (!au_br_wh_linkable(br->br_perm)) {
35433 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35439 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35445 + goto out; /* success */
35448 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35449 + err, h_root, au_sbtype(h_root->d_sb));
35451 + for (i = 0; i < AuBrWh_Last; i++)
35452 + dput(base[i].dentry);
35456 +/* ---------------------------------------------------------------------- */
35458 + * whiteouts are all hard-linked usually.
35459 + * when its link count reaches a ceiling, we create a new whiteout base
35460 + * asynchronously.
35463 +struct reinit_br_wh {
35464 + struct super_block *sb;
35465 + struct au_branch *br;
35468 +static void reinit_br_wh(void *arg)
35471 + aufs_bindex_t bindex;
35472 + struct path h_path;
35473 + struct reinit_br_wh *a = arg;
35474 + struct au_wbr *wbr;
35475 + struct inode *dir, *delegated;
35476 + struct dentry *h_root;
35477 + struct au_hinode *hdir;
35480 + wbr = a->br->br_wbr;
35481 + /* big aufs lock */
35482 + si_noflush_write_lock(a->sb);
35483 + if (!au_br_writable(a->br->br_perm))
35485 + bindex = au_br_index(a->sb, a->br->br_id);
35486 + if (unlikely(bindex < 0))
35489 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35490 + dir = d_inode(a->sb->s_root);
35491 + hdir = au_hi(dir, bindex);
35492 + h_root = au_h_dptr(a->sb->s_root, bindex);
35493 + AuDebugOn(h_root != au_br_dentry(a->br));
35495 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35496 + wbr_wh_write_lock(wbr);
35497 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35500 + h_path.dentry = wbr->wbr_whbase;
35501 + h_path.mnt = au_br_mnt(a->br);
35502 + delegated = NULL;
35503 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35505 + if (unlikely(err == -EWOULDBLOCK)) {
35506 + pr_warn("cannot retry for NFSv4 delegation"
35507 + " for an internal unlink\n");
35511 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35514 + dput(wbr->wbr_whbase);
35515 + wbr->wbr_whbase = NULL;
35517 + err = au_wh_init(a->br, a->sb);
35518 + wbr_wh_write_unlock(wbr);
35519 + au_hn_inode_unlock(hdir);
35520 + di_read_unlock(a->sb->s_root, AuLock_IR);
35522 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35526 + atomic_dec(&wbr->wbr_wh_running);
35527 + au_lcnt_dec(&a->br->br_count);
35528 + si_write_unlock(a->sb);
35529 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35531 + if (unlikely(err))
35532 + AuIOErr("err %d\n", err);
35535 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35537 + int do_dec, wkq_err;
35538 + struct reinit_br_wh *arg;
35541 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35544 + /* ignore ENOMEM */
35545 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35548 + * dec(wh_running), kfree(arg) and dec(br_count)
35549 + * in reinit function
35553 + au_lcnt_inc(&br->br_count);
35554 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35555 + if (unlikely(wkq_err)) {
35556 + atomic_dec(&br->br_wbr->wbr_wh_running);
35557 + au_lcnt_dec(&br->br_count);
35558 + au_kfree_rcu(arg);
35565 + atomic_dec(&br->br_wbr->wbr_wh_running);
35568 +/* ---------------------------------------------------------------------- */
35571 + * create the whiteout @wh.
35573 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35574 + struct dentry *wh)
35577 + struct path h_path = {
35580 + struct au_branch *br;
35581 + struct au_wbr *wbr;
35582 + struct dentry *h_parent;
35583 + struct inode *h_dir, *delegated;
35585 + h_parent = wh->d_parent; /* dir inode is locked */
35586 + h_dir = d_inode(h_parent);
35587 + IMustLock(h_dir);
35589 + br = au_sbr(sb, bindex);
35590 + h_path.mnt = au_br_mnt(br);
35591 + wbr = br->br_wbr;
35592 + wbr_wh_read_lock(wbr);
35593 + if (wbr->wbr_whbase) {
35594 + delegated = NULL;
35595 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35596 + if (unlikely(err == -EWOULDBLOCK)) {
35597 + pr_warn("cannot retry for NFSv4 delegation"
35598 + " for an internal link\n");
35601 + if (!err || err != -EMLINK)
35604 + /* link count full. re-initialize br_whbase. */
35605 + kick_reinit_br_wh(sb, br);
35608 + /* return this error in this context */
35609 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35611 + au_fhsm_wrote(sb, bindex, /*force*/0);
35614 + wbr_wh_read_unlock(wbr);
35618 +/* ---------------------------------------------------------------------- */
35621 + * create or remove the diropq.
35623 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35624 + unsigned int flags)
35626 + struct dentry *opq_dentry, *h_dentry;
35627 + struct super_block *sb;
35628 + struct au_branch *br;
35631 + sb = dentry->d_sb;
35632 + br = au_sbr(sb, bindex);
35633 + h_dentry = au_h_dptr(dentry, bindex);
35634 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35635 + if (IS_ERR(opq_dentry))
35638 + if (au_ftest_diropq(flags, CREATE)) {
35639 + err = link_or_create_wh(sb, bindex, opq_dentry);
35641 + au_set_dbdiropq(dentry, bindex);
35642 + goto out; /* success */
35645 + struct path tmp = {
35646 + .dentry = opq_dentry,
35647 + .mnt = au_br_mnt(br)
35649 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35651 + au_set_dbdiropq(dentry, -1);
35653 + dput(opq_dentry);
35654 + opq_dentry = ERR_PTR(err);
35657 + return opq_dentry;
35660 +struct do_diropq_args {
35661 + struct dentry **errp;
35662 + struct dentry *dentry;
35663 + aufs_bindex_t bindex;
35664 + unsigned int flags;
35667 +static void call_do_diropq(void *args)
35669 + struct do_diropq_args *a = args;
35670 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35673 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35674 + unsigned int flags)
35676 + struct dentry *diropq, *h_dentry;
35678 + h_dentry = au_h_dptr(dentry, bindex);
35679 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35680 + diropq = do_diropq(dentry, bindex, flags);
35683 + struct do_diropq_args args = {
35685 + .dentry = dentry,
35686 + .bindex = bindex,
35690 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35691 + if (unlikely(wkq_err))
35692 + diropq = ERR_PTR(wkq_err);
35698 +/* ---------------------------------------------------------------------- */
35701 + * lookup whiteout dentry.
35702 + * @h_parent: lower parent dentry which must exist and be locked
35703 + * @base_name: name of dentry which will be whiteouted
35704 + * returns dentry for whiteout.
35706 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35707 + struct au_branch *br)
35710 + struct qstr wh_name;
35711 + struct dentry *wh_dentry;
35713 + err = au_wh_name_alloc(&wh_name, base_name);
35714 + wh_dentry = ERR_PTR(err);
35716 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35717 + au_kfree_try_rcu(wh_name.name);
35719 + return wh_dentry;
35723 + * link/create a whiteout for @dentry on @bindex.
35725 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35726 + struct dentry *h_parent)
35728 + struct dentry *wh_dentry;
35729 + struct super_block *sb;
35732 + sb = dentry->d_sb;
35733 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35734 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35735 + err = link_or_create_wh(sb, bindex, wh_dentry);
35737 + au_set_dbwh(dentry, bindex);
35738 + au_fhsm_wrote(sb, bindex, /*force*/0);
35741 + wh_dentry = ERR_PTR(err);
35745 + return wh_dentry;
35748 +/* ---------------------------------------------------------------------- */
35750 +/* Delete all whiteouts in this directory on branch bindex. */
35751 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35752 + aufs_bindex_t bindex, struct au_branch *br)
35755 + unsigned long ul, n;
35756 + struct qstr wh_name;
35758 + struct hlist_head *head;
35759 + struct au_vdir_wh *pos;
35760 + struct au_vdir_destr *str;
35763 + p = (void *)__get_free_page(GFP_NOFS);
35764 + wh_name.name = p;
35765 + if (unlikely(!wh_name.name))
35769 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35770 + p += AUFS_WH_PFX_LEN;
35771 + n = whlist->nh_num;
35772 + head = whlist->nh_head;
35773 + for (ul = 0; !err && ul < n; ul++, head++) {
35774 + hlist_for_each_entry(pos, head, wh_hash) {
35775 + if (pos->wh_bindex != bindex)
35778 + str = &pos->wh_str;
35779 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35780 + memcpy(p, str->name, str->len);
35781 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35782 + err = unlink_wh_name(h_dentry, &wh_name, br);
35787 + AuIOErr("whiteout name too long %.*s\n",
35788 + str->len, str->name);
35793 + free_page((unsigned long)wh_name.name);
35799 +struct del_wh_children_args {
35801 + struct dentry *h_dentry;
35802 + struct au_nhash *whlist;
35803 + aufs_bindex_t bindex;
35804 + struct au_branch *br;
35807 +static void call_del_wh_children(void *args)
35809 + struct del_wh_children_args *a = args;
35810 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35813 +/* ---------------------------------------------------------------------- */
35815 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35817 + struct au_whtmp_rmdir *whtmp;
35819 + unsigned int rdhash;
35821 + SiMustAnyLock(sb);
35823 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35824 + if (unlikely(!whtmp)) {
35825 + whtmp = ERR_PTR(-ENOMEM);
35829 + /* no estimation for dir size */
35830 + rdhash = au_sbi(sb)->si_rdhash;
35832 + rdhash = AUFS_RDHASH_DEF;
35833 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35834 + if (unlikely(err)) {
35835 + au_kfree_rcu(whtmp);
35836 + whtmp = ERR_PTR(err);
35843 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35846 + au_lcnt_dec(&whtmp->br->br_count);
35847 + dput(whtmp->wh_dentry);
35848 + iput(whtmp->dir);
35849 + au_nhash_wh_free(&whtmp->whlist);
35850 + au_kfree_rcu(whtmp);
35854 + * rmdir the whiteouted temporary named dir @h_dentry.
35855 + * @whlist: whiteouted children.
35857 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35858 + struct dentry *wh_dentry, struct au_nhash *whlist)
35861 + unsigned int h_nlink;
35862 + struct path h_tmp;
35863 + struct inode *wh_inode, *h_dir;
35864 + struct au_branch *br;
35866 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35867 + IMustLock(h_dir);
35869 + br = au_sbr(dir->i_sb, bindex);
35870 + wh_inode = d_inode(wh_dentry);
35871 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35874 + * someone else might change some whiteouts while we were sleeping.
35875 + * it means this whlist may have an obsoleted entry.
35877 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35878 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35881 + struct del_wh_children_args args = {
35883 + .h_dentry = wh_dentry,
35884 + .whlist = whlist,
35885 + .bindex = bindex,
35889 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35890 + if (unlikely(wkq_err))
35893 + inode_unlock(wh_inode);
35896 + h_tmp.dentry = wh_dentry;
35897 + h_tmp.mnt = au_br_mnt(br);
35898 + h_nlink = h_dir->i_nlink;
35899 + err = vfsub_rmdir(h_dir, &h_tmp);
35900 + /* some fs doesn't change the parent nlink in some cases */
35901 + h_nlink -= h_dir->i_nlink;
35905 + if (au_ibtop(dir) == bindex) {
35906 + /* todo: dir->i_mutex is necessary */
35907 + au_cpup_attr_timesizes(dir);
35909 + vfsub_drop_nlink(dir);
35911 + return 0; /* success */
35914 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35918 +static void call_rmdir_whtmp(void *args)
35921 + aufs_bindex_t bindex;
35922 + struct au_whtmp_rmdir *a = args;
35923 + struct super_block *sb;
35924 + struct dentry *h_parent;
35925 + struct inode *h_dir;
35926 + struct au_hinode *hdir;
35928 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35929 + /* inode_lock(a->dir); */
35931 + sb = a->dir->i_sb;
35932 + si_read_lock(sb, !AuLock_FLUSH);
35933 + if (!au_br_writable(a->br->br_perm))
35935 + bindex = au_br_index(sb, a->br->br_id);
35936 + if (unlikely(bindex < 0))
35940 + ii_write_lock_parent(a->dir);
35941 + h_parent = dget_parent(a->wh_dentry);
35942 + h_dir = d_inode(h_parent);
35943 + hdir = au_hi(a->dir, bindex);
35944 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35945 + if (unlikely(err))
35947 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35948 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35951 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35952 + au_hn_inode_unlock(hdir);
35953 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35957 + ii_write_unlock(a->dir);
35959 + /* inode_unlock(a->dir); */
35960 + au_whtmp_rmdir_free(a);
35961 + si_read_unlock(sb);
35962 + au_nwt_done(&au_sbi(sb)->si_nowait);
35963 + if (unlikely(err))
35964 + AuIOErr("err %d\n", err);
35967 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35968 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35971 + struct super_block *sb;
35975 + /* all post-process will be done in do_rmdir_whtmp(). */
35977 + args->dir = au_igrab(dir);
35978 + args->br = au_sbr(sb, bindex);
35979 + au_lcnt_inc(&args->br->br_count);
35980 + args->wh_dentry = dget(wh_dentry);
35981 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35982 + if (unlikely(wkq_err)) {
35983 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35984 + au_whtmp_rmdir_free(args);
35987 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35988 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35989 +++ linux/fs/aufs/whout.h 2018-08-12 23:43:05.463458173 +0200
35991 +/* SPDX-License-Identifier: GPL-2.0 */
35993 + * Copyright (C) 2005-2018 Junjiro R. Okajima
35995 + * This program, aufs is free software; you can redistribute it and/or modify
35996 + * it under the terms of the GNU General Public License as published by
35997 + * the Free Software Foundation; either version 2 of the License, or
35998 + * (at your option) any later version.
36000 + * This program is distributed in the hope that it will be useful,
36001 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36002 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36003 + * GNU General Public License for more details.
36005 + * You should have received a copy of the GNU General Public License
36006 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36010 + * whiteout for logical deletion and opaque directory
36013 +#ifndef __AUFS_WHOUT_H__
36014 +#define __AUFS_WHOUT_H__
36021 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
36022 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
36023 +int au_diropq_test(struct dentry *h_dentry);
36025 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
36026 + struct qstr *prefix);
36027 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
36028 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
36029 + struct dentry *dentry);
36030 +int au_wh_init(struct au_branch *br, struct super_block *sb);
36032 +/* diropq flags */
36033 +#define AuDiropq_CREATE 1
36034 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
36035 +#define au_fset_diropq(flags, name) \
36036 + do { (flags) |= AuDiropq_##name; } while (0)
36037 +#define au_fclr_diropq(flags, name) \
36038 + do { (flags) &= ~AuDiropq_##name; } while (0)
36040 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
36041 + unsigned int flags);
36042 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
36043 + struct au_branch *br);
36044 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
36045 + struct dentry *h_parent);
36047 +/* real rmdir for the whiteout-ed dir */
36048 +struct au_whtmp_rmdir {
36049 + struct inode *dir;
36050 + struct au_branch *br;
36051 + struct dentry *wh_dentry;
36052 + struct au_nhash whlist;
36055 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
36056 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
36057 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36058 + struct dentry *wh_dentry, struct au_nhash *whlist);
36059 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36060 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
36062 +/* ---------------------------------------------------------------------- */
36064 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
36065 + aufs_bindex_t bindex)
36067 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
36070 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
36072 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
36075 +#endif /* __KERNEL__ */
36076 +#endif /* __AUFS_WHOUT_H__ */
36077 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
36078 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
36079 +++ linux/fs/aufs/wkq.c 2018-12-27 13:19:17.711749485 +0100
36081 +// SPDX-License-Identifier: GPL-2.0
36083 + * Copyright (C) 2005-2018 Junjiro R. Okajima
36085 + * This program, aufs is free software; you can redistribute it and/or modify
36086 + * it under the terms of the GNU General Public License as published by
36087 + * the Free Software Foundation; either version 2 of the License, or
36088 + * (at your option) any later version.
36090 + * This program is distributed in the hope that it will be useful,
36091 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36092 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36093 + * GNU General Public License for more details.
36095 + * You should have received a copy of the GNU General Public License
36096 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36100 + * workqueue for asynchronous/super-io operations
36101 + * todo: try new credential scheme
36104 +#include <linux/module.h>
36107 +/* internal workqueue named AUFS_WKQ_NAME */
36109 +static struct workqueue_struct *au_wkq;
36111 +struct au_wkinfo {
36112 + struct work_struct wk;
36113 + struct kobject *kobj;
36115 + unsigned int flags; /* see wkq.h */
36117 + au_wkq_func_t func;
36120 +#ifdef CONFIG_LOCKDEP
36122 + struct held_lock **hlock;
36125 + struct completion *comp;
36128 +/* ---------------------------------------------------------------------- */
36130 + * Aufs passes some operations to the workqueue such as the internal copyup.
36131 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36132 + * job run by workqueue depends upon the locks acquired in the other task.
36133 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36134 + * information too. And the job in the workqueue restores the info in order to
36135 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36136 + * correctly and expectedly.
36139 +#ifndef CONFIG_LOCKDEP
36140 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36141 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36142 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36143 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36144 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36146 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36148 + wkinfo->hlock = NULL;
36149 + wkinfo->dont_check = 0;
36156 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36158 + static DEFINE_SPINLOCK(spin);
36161 + struct lock_class_key *key;
36163 + { .name = "&sbinfo->si_rwsem" },
36164 + { .name = "&finfo->fi_rwsem" },
36165 + { .name = "&dinfo->di_rwsem" },
36166 + { .name = "&iinfo->ii_rwsem" }
36171 + /* lockless read from 'set.' see below */
36172 + if (set == ARRAY_SIZE(a)) {
36173 + for (i = 0; i < ARRAY_SIZE(a); i++)
36174 + if (a[i].key == key)
36179 + spin_lock(&spin);
36181 + for (i = 0; i < ARRAY_SIZE(a); i++)
36182 + if (a[i].key == key) {
36183 + spin_unlock(&spin);
36186 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36188 + if (unlikely(a[i].key == key)) { /* rare but possible */
36189 + spin_unlock(&spin);
36194 + if (strstr(a[i].name, name)) {
36196 + * the order of these three lines is important for the
36197 + * lockless read above.
36200 + spin_unlock(&spin);
36202 + /* AuDbg("%d, %s\n", set, name); */
36206 + spin_unlock(&spin);
36215 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36218 + struct task_struct *curr;
36219 + struct held_lock **hl, *held_locks, *p;
36223 + wkinfo->dont_check = lockdep_recursing(curr);
36224 + if (wkinfo->dont_check)
36226 + n = curr->lockdep_depth;
36231 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36232 + if (unlikely(!wkinfo->hlock))
36237 + if (0 && au_debug_test()) /* left for debugging */
36238 + lockdep_print_held_locks(curr);
36240 + held_locks = curr->held_locks;
36241 + hl = wkinfo->hlock;
36243 + p = held_locks++;
36244 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36253 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36255 + au_kfree_try_rcu(wkinfo->hlock);
36258 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36260 + struct held_lock *p, **hl = wkinfo->hlock;
36263 + if (wkinfo->dont_check)
36267 + while ((p = *hl++)) { /* assignment */
36268 + subclass = lockdep_hlock_class(p)->subclass;
36269 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36271 + rwsem_acquire_read(p->instance, subclass, 0,
36272 + /*p->acquire_ip*/_RET_IP_);
36274 + rwsem_acquire(p->instance, subclass, 0,
36275 + /*p->acquire_ip*/_RET_IP_);
36279 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36281 + struct held_lock *p, **hl = wkinfo->hlock;
36283 + if (wkinfo->dont_check)
36287 + while ((p = *hl++)) /* assignment */
36288 + rwsem_release(p->instance, 0, /*p->acquire_ip*/_RET_IP_);
36292 +static void wkq_func(struct work_struct *wk)
36294 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36296 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36297 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36299 + au_wkq_lockdep_pre(wkinfo);
36300 + wkinfo->func(wkinfo->args);
36301 + au_wkq_lockdep_post(wkinfo);
36302 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36303 + complete(wkinfo->comp);
36305 + kobject_put(wkinfo->kobj);
36306 + module_put(THIS_MODULE); /* todo: ?? */
36307 + au_kfree_rcu(wkinfo);
36312 + * Since struct completion is large, try allocating it dynamically.
36314 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
36315 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36317 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36319 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36321 + init_completion(*comp);
36322 + wkinfo->comp = *comp;
36328 +static void au_wkq_comp_free(struct completion *comp)
36330 + au_kfree_rcu(comp);
36336 +#define AuWkqCompDeclare(name) \
36337 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
36338 + struct completion *comp = &_ ## name
36340 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36342 + wkinfo->comp = *comp;
36346 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
36350 +#endif /* 4KSTACKS */
36352 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36354 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36355 + if (au_wkq_test()) {
36356 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36357 + " due to a dead dir by UDBA,"
36358 + " or async xino write?\n");
36359 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36362 + au_dbg_verify_kthread();
36364 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36365 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36366 + queue_work(au_wkq, &wkinfo->wk);
36368 + INIT_WORK(&wkinfo->wk, wkq_func);
36369 + schedule_work(&wkinfo->wk);
36374 + * Be careful. It is easy to make deadlock happen.
36375 + * processA: lock, wkq and wait
36376 + * processB: wkq and wait, lock in wkq
36379 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36382 + AuWkqCompDeclare(comp);
36383 + struct au_wkinfo wkinfo = {
36389 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36390 + if (unlikely(err))
36392 + err = au_wkq_lockdep_alloc(&wkinfo);
36393 + if (unlikely(err))
36396 + au_wkq_run(&wkinfo);
36397 + /* no timeout, no interrupt */
36398 + wait_for_completion(wkinfo.comp);
36400 + au_wkq_lockdep_free(&wkinfo);
36403 + au_wkq_comp_free(comp);
36405 + destroy_work_on_stack(&wkinfo.wk);
36410 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36411 + * problem in a concurrent umounting.
36413 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36414 + unsigned int flags)
36417 + struct au_wkinfo *wkinfo;
36419 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36422 + * wkq_func() must free this wkinfo.
36423 + * it highly depends upon the implementation of workqueue.
36426 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36428 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36429 + wkinfo->flags = flags & ~AuWkq_WAIT;
36430 + wkinfo->func = func;
36431 + wkinfo->args = args;
36432 + wkinfo->comp = NULL;
36433 + au_wkq_lockdep_init(wkinfo);
36434 + kobject_get(wkinfo->kobj);
36435 + __module_get(THIS_MODULE); /* todo: ?? */
36437 + au_wkq_run(wkinfo);
36440 + au_nwt_done(&au_sbi(sb)->si_nowait);
36446 +/* ---------------------------------------------------------------------- */
36448 +void au_nwt_init(struct au_nowait_tasks *nwt)
36450 + atomic_set(&nwt->nw_len, 0);
36451 + /* smp_mb(); */ /* atomic_set */
36452 + init_waitqueue_head(&nwt->nw_wq);
36455 +void au_wkq_fin(void)
36457 + destroy_workqueue(au_wkq);
36460 +int __init au_wkq_init(void)
36465 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36466 + if (IS_ERR(au_wkq))
36467 + err = PTR_ERR(au_wkq);
36468 + else if (!au_wkq)
36473 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36474 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36475 +++ linux/fs/aufs/wkq.h 2018-10-23 12:33:35.599375796 +0200
36477 +/* SPDX-License-Identifier: GPL-2.0 */
36479 + * Copyright (C) 2005-2018 Junjiro R. Okajima
36481 + * This program, aufs is free software; you can redistribute it and/or modify
36482 + * it under the terms of the GNU General Public License as published by
36483 + * the Free Software Foundation; either version 2 of the License, or
36484 + * (at your option) any later version.
36486 + * This program is distributed in the hope that it will be useful,
36487 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36488 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36489 + * GNU General Public License for more details.
36491 + * You should have received a copy of the GNU General Public License
36492 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36496 + * workqueue for asynchronous/super-io operations
36497 + * todo: try new credentials management scheme
36500 +#ifndef __AUFS_WKQ_H__
36501 +#define __AUFS_WKQ_H__
36505 +#include <linux/wait.h>
36507 +struct super_block;
36509 +/* ---------------------------------------------------------------------- */
36512 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36514 +struct au_nowait_tasks {
36516 + wait_queue_head_t nw_wq;
36519 +/* ---------------------------------------------------------------------- */
36521 +typedef void (*au_wkq_func_t)(void *args);
36524 +#define AuWkq_WAIT 1
36525 +#define AuWkq_NEST (1 << 1)
36526 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36527 +#define au_fset_wkq(flags, name) \
36528 + do { (flags) |= AuWkq_##name; } while (0)
36529 +#define au_fclr_wkq(flags, name) \
36530 + do { (flags) &= ~AuWkq_##name; } while (0)
36533 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36534 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36535 + unsigned int flags);
36536 +void au_nwt_init(struct au_nowait_tasks *nwt);
36537 +int __init au_wkq_init(void);
36538 +void au_wkq_fin(void);
36540 +/* ---------------------------------------------------------------------- */
36542 +static inline int au_wkq_test(void)
36544 + return current->flags & PF_WQ_WORKER;
36547 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36549 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36552 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36554 + if (atomic_dec_and_test(&nwt->nw_len))
36555 + wake_up_all(&nwt->nw_wq);
36558 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36560 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36564 +#endif /* __KERNEL__ */
36565 +#endif /* __AUFS_WKQ_H__ */
36566 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36567 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36568 +++ linux/fs/aufs/xattr.c 2018-12-27 13:19:17.711749485 +0100
36570 +// SPDX-License-Identifier: GPL-2.0
36572 + * Copyright (C) 2014-2018 Junjiro R. Okajima
36574 + * This program, aufs is free software; you can redistribute it and/or modify
36575 + * it under the terms of the GNU General Public License as published by
36576 + * the Free Software Foundation; either version 2 of the License, or
36577 + * (at your option) any later version.
36579 + * This program is distributed in the hope that it will be useful,
36580 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36581 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36582 + * GNU General Public License for more details.
36584 + * You should have received a copy of the GNU General Public License
36585 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36589 + * handling xattr functions
36592 +#include <linux/fs.h>
36593 +#include <linux/posix_acl_xattr.h>
36594 +#include <linux/xattr.h>
36597 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36599 + if (!ignore_flags)
36607 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36612 +#define cmp(brattr, prefix) do { \
36613 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36614 + XATTR_##prefix##_PREFIX_LEN)) { \
36615 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36621 + cmp(SEC, SECURITY);
36622 + cmp(SYS, SYSTEM);
36623 + cmp(TR, TRUSTED);
36627 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36634 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36636 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36637 + char *name, char **buf, unsigned int ignore_flags,
36638 + unsigned int verbose)
36642 + struct inode *h_idst;
36644 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36646 + if (unlikely(err <= 0)) {
36647 + if (err == -ENODATA
36648 + || (err == -EOPNOTSUPP
36649 + && ((ignore_flags & au_xattr_out_of_list)
36650 + || (au_test_nfs_noacl(d_inode(h_src))
36651 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36653 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36656 + if (err && (verbose || au_debug_test()))
36657 + pr_err("%s, err %d\n", name, err);
36661 + /* unlock it temporary */
36662 + h_idst = d_inode(h_dst);
36663 + inode_unlock(h_idst);
36664 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36665 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36666 + if (unlikely(err)) {
36667 + if (verbose || au_debug_test())
36668 + pr_err("%s, err %d\n", name, err);
36669 + err = au_xattr_ignore(err, name, ignore_flags);
36676 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36677 + unsigned int verbose)
36679 + int err, unlocked, acl_access, acl_default;
36681 + struct inode *h_isrc, *h_idst;
36682 + char *value, *p, *o, *e;
36684 + /* try stopping to update the source inode while we are referencing */
36685 + /* there should not be the parent-child relationship between them */
36686 + h_isrc = d_inode(h_src);
36687 + h_idst = d_inode(h_dst);
36688 + inode_unlock(h_idst);
36689 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36690 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36693 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36694 + ssz = vfs_listxattr(h_src, NULL, 0);
36696 + if (unlikely(err < 0)) {
36698 + if (err == -ENODATA
36699 + || err == -EOPNOTSUPP)
36700 + err = 0; /* ignore */
36709 + p = kmalloc(ssz, GFP_NOFS);
36711 + if (unlikely(!p))
36713 + err = vfs_listxattr(h_src, p, ssz);
36715 + inode_unlock_shared(h_isrc);
36717 + AuDbg("err %d, ssz %zd\n", err, ssz);
36718 + if (unlikely(err < 0))
36726 + while (!err && p < e) {
36727 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36728 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36729 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36730 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36732 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36734 + p += strlen(p) + 1;
36737 + ignore_flags |= au_xattr_out_of_list;
36738 + if (!err && !acl_access) {
36739 + err = au_do_cpup_xattr(h_dst, h_src,
36740 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36741 + ignore_flags, verbose);
36744 + if (!err && !acl_default) {
36745 + err = au_do_cpup_xattr(h_dst, h_src,
36746 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36747 + ignore_flags, verbose);
36751 + au_kfree_try_rcu(value);
36754 + au_kfree_try_rcu(o);
36757 + inode_unlock_shared(h_isrc);
36762 +/* ---------------------------------------------------------------------- */
36764 +static int au_smack_reentering(struct super_block *sb)
36766 +#if IS_ENABLED(CONFIG_SECURITY_SMACK)
36768 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36769 + * i_op->getxattr(). ouch.
36771 + return si_pid_test(sb);
36782 +struct au_lgxattr {
36790 + const char *name;
36797 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
36801 + struct path h_path;
36802 + struct super_block *sb;
36804 + sb = dentry->d_sb;
36805 + reenter = au_smack_reentering(sb);
36807 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36808 + if (unlikely(err))
36811 + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
36812 + if (unlikely(err))
36814 + if (unlikely(!h_path.dentry))
36815 + /* illegally overlapped or something */
36816 + goto out_di; /* pretending success */
36818 + /* always topmost entry only */
36819 + switch (arg->type) {
36820 + case AU_XATTR_LIST:
36821 + err = vfs_listxattr(h_path.dentry,
36822 + arg->u.list.list, arg->u.list.size);
36824 + case AU_XATTR_GET:
36825 + AuDebugOn(d_is_negative(h_path.dentry));
36826 + err = vfs_getxattr(h_path.dentry,
36827 + arg->u.get.name, arg->u.get.value,
36828 + arg->u.get.size);
36834 + di_read_unlock(dentry, AuLock_IR);
36837 + si_read_unlock(sb);
36843 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36845 + struct au_lgxattr arg = {
36846 + .type = AU_XATTR_LIST,
36853 + return au_lgxattr(dentry, &arg);
36856 +static ssize_t au_getxattr(struct dentry *dentry,
36857 + struct inode *inode __maybe_unused,
36858 + const char *name, void *value, size_t size)
36860 + struct au_lgxattr arg = {
36861 + .type = AU_XATTR_GET,
36869 + return au_lgxattr(dentry, &arg);
36872 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36873 + const char *name, const void *value, size_t size,
36876 + struct au_sxattr arg = {
36877 + .type = AU_XATTR_SET,
36886 + return au_sxattr(dentry, inode, &arg);
36889 +/* ---------------------------------------------------------------------- */
36891 +static int au_xattr_get(const struct xattr_handler *handler,
36892 + struct dentry *dentry, struct inode *inode,
36893 + const char *name, void *buffer, size_t size)
36895 + return au_getxattr(dentry, inode, name, buffer, size);
36898 +static int au_xattr_set(const struct xattr_handler *handler,
36899 + struct dentry *dentry, struct inode *inode,
36900 + const char *name, const void *value, size_t size,
36903 + return au_setxattr(dentry, inode, name, value, size, flags);
36906 +static const struct xattr_handler au_xattr_handler = {
36909 + .get = au_xattr_get,
36910 + .set = au_xattr_set
36913 +static const struct xattr_handler *au_xattr_handlers[] = {
36914 +#ifdef CONFIG_FS_POSIX_ACL
36915 + &posix_acl_access_xattr_handler,
36916 + &posix_acl_default_xattr_handler,
36918 + &au_xattr_handler, /* must be last */
36922 +void au_xattr_init(struct super_block *sb)
36924 + sb->s_xattr = au_xattr_handlers;
36926 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36927 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36928 +++ linux/fs/aufs/xino.c 2018-12-27 13:19:17.715082917 +0100
36930 +// SPDX-License-Identifier: GPL-2.0
36932 + * Copyright (C) 2005-2018 Junjiro R. Okajima
36934 + * This program, aufs is free software; you can redistribute it and/or modify
36935 + * it under the terms of the GNU General Public License as published by
36936 + * the Free Software Foundation; either version 2 of the License, or
36937 + * (at your option) any later version.
36939 + * This program is distributed in the hope that it will be useful,
36940 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36941 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36942 + * GNU General Public License for more details.
36944 + * You should have received a copy of the GNU General Public License
36945 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36949 + * external inode number translation table and bitmap
36951 + * things to consider
36953 + * + au_xino object
36954 + * + XINO files (xino, xib, xigen)
36955 + * + dynamic debugfs entries (xiN)
36956 + * + static debugfs entries (xib, xigen)
36957 + * + static sysfs entry (xi_path)
36958 + * - several entry points to handle them.
36959 + * + mount(2) without xino option (default)
36960 + * + mount(2) with xino option
36961 + * + mount(2) with noxino option
36963 + * + remount with add/del branches
36964 + * + remount with xino/noxino options
36967 +#include <linux/seq_file.h>
36968 +#include <linux/statfs.h>
36971 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36972 + aufs_bindex_t bbot,
36973 + struct super_block *h_sb)
36975 + /* todo: try binary-search if the branches are many */
36976 + for (; btop <= bbot; btop++)
36977 + if (h_sb == au_sbr_sb(sb, btop))
36983 + * find another branch who is on the same filesystem of the specified
36984 + * branch{@btgt}. search until @bbot.
36986 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36987 + aufs_bindex_t bbot)
36989 + aufs_bindex_t bindex;
36990 + struct super_block *tgt_sb;
36992 + tgt_sb = au_sbr_sb(sb, btgt);
36993 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36995 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
37000 +/* ---------------------------------------------------------------------- */
37003 + * stop unnecessary notify events at creating xino files
37006 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
37008 + aufs_bindex_t bfound, bindex, bbot;
37009 + struct dentry *parent;
37010 + struct au_branch *br;
37013 + parent = dentry->d_parent; /* safe d_parent access */
37014 + bbot = au_sbbot(sb);
37015 + for (bindex = 0; bindex <= bbot; bindex++) {
37016 + br = au_sbr(sb, bindex);
37017 + if (au_br_dentry(br) == parent) {
37023 + AuDbg("bfound b%d\n", bfound);
37027 +struct au_xino_lock_dir {
37028 + struct au_hinode *hdir;
37029 + struct dentry *parent;
37030 + struct inode *dir;
37033 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
37034 + unsigned int lsc)
37036 + struct dentry *parent;
37037 + struct inode *dir;
37039 + parent = dget_parent(dentry);
37040 + dir = d_inode(parent);
37041 + inode_lock_nested(dir, lsc);
37042 +#if 0 /* it should not happen */
37043 + spin_lock(&dentry->d_lock);
37044 + if (unlikely(dentry->d_parent != parent)) {
37045 + spin_unlock(&dentry->d_lock);
37046 + inode_unlock(dir);
37051 + spin_unlock(&dentry->d_lock);
37058 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
37059 + struct au_xino_lock_dir *ldir)
37061 + aufs_bindex_t bindex;
37063 + ldir->hdir = NULL;
37064 + bindex = au_xi_root(sb, xipath->dentry);
37065 + if (bindex >= 0) {
37066 + /* rw branch root */
37067 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
37068 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
37071 + ldir->parent = au_dget_parent_lock(xipath->dentry,
37073 + ldir->dir = d_inode(ldir->parent);
37077 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
37080 + au_hn_inode_unlock(ldir->hdir);
37082 + inode_unlock(ldir->dir);
37083 + dput(ldir->parent);
37087 +/* ---------------------------------------------------------------------- */
37090 + * create and set a new xino file
37092 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent)
37094 + struct file *file;
37095 + struct dentry *h_parent, *d;
37096 + struct inode *h_dir, *inode;
37100 + * at mount-time, and the xino file is the default path,
37101 + * hnotify is disabled so we have no notify events to ignore.
37102 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37104 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37105 + /* | __FMODE_NONOTIFY */,
37107 + if (IS_ERR(file)) {
37109 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
37113 + /* keep file count */
37115 + d = file->f_path.dentry;
37116 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
37117 + /* mnt_want_write() is unnecessary here */
37118 + h_dir = d_inode(h_parent);
37119 + inode = file_inode(file);
37120 + /* no delegation since it is just created */
37121 + if (inode->i_nlink)
37122 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37124 + inode_unlock(h_dir);
37126 + if (unlikely(err)) {
37128 + pr_err("unlink %s(%d)\n", fpath, err);
37133 + if (unlikely(sb == d->d_sb)) {
37135 + pr_err("%s must be outside\n", fpath);
37138 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37140 + pr_err("xino doesn't support %s(%s)\n",
37141 + fpath, au_sbtype(d->d_sb));
37144 + return file; /* success */
37148 + file = ERR_PTR(err);
37153 + * create a new xinofile at the same place/path as @base.
37155 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37156 + struct file *copy_src)
37158 + struct file *file;
37159 + struct dentry *dentry, *parent;
37160 + struct inode *dir, *delegated;
37161 + struct qstr *name;
37162 + struct path path;
37163 + int err, do_unlock;
37164 + struct au_xino_lock_dir ldir;
37167 + au_xino_lock_dir(sb, base, &ldir);
37168 + dentry = base->dentry;
37169 + parent = dentry->d_parent; /* dir inode is locked */
37170 + dir = d_inode(parent);
37173 + name = &dentry->d_name;
37174 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
37175 + if (IS_ERR(path.dentry)) {
37176 + file = (void *)path.dentry;
37177 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37181 + /* no need to mnt_want_write() since we call dentry_open() later */
37182 + err = vfs_create(dir, path.dentry, 0666, NULL);
37183 + if (unlikely(err)) {
37184 + file = ERR_PTR(err);
37185 + pr_err("%pd create err %d\n", dentry, err);
37189 + path.mnt = base->mnt;
37190 + file = vfsub_dentry_open(&path,
37191 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37192 + /* | __FMODE_NONOTIFY */);
37193 + if (IS_ERR(file)) {
37194 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37198 + delegated = NULL;
37199 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37200 + au_xino_unlock_dir(&ldir);
37202 + if (unlikely(err == -EWOULDBLOCK)) {
37203 + pr_warn("cannot retry for NFSv4 delegation"
37204 + " for an internal unlink\n");
37207 + if (unlikely(err)) {
37208 + pr_err("%pd unlink err %d\n", dentry, err);
37213 + /* no one can touch copy_src xino */
37214 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37215 + if (unlikely(err)) {
37216 + pr_err("%pd copy err %d\n", dentry, err);
37220 + goto out_dput; /* success */
37224 + file = ERR_PTR(err);
37226 + dput(path.dentry);
37229 + au_xino_unlock_dir(&ldir);
37233 +struct file *au_xino_file1(struct au_xino *xi)
37235 + struct file *file;
37236 + unsigned int u, nfile;
37239 + nfile = xi->xi_nfile;
37240 + for (u = 0; u < nfile; u++) {
37241 + file = xi->xi_file[u];
37249 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37260 + if (idx < xi->xi_nfile) {
37261 + f = xi->xi_file[idx];
37265 + p = au_kzrealloc(xi->xi_file,
37266 + sizeof(*xi->xi_file) * xi->xi_nfile,
37267 + sizeof(*xi->xi_file) * (idx + 1),
37268 + GFP_NOFS, /*may_shrink*/0);
37270 + MtxMustLock(&xi->xi_mtx);
37272 + xi->xi_nfile = idx + 1;
37280 + xi->xi_file[idx] = file;
37287 + * if @xinew->xi is not set, then create new xigen file.
37289 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37291 + struct file *file;
37294 + SiMustAnyLock(sb);
37296 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37297 + if (IS_ERR(file)) {
37298 + err = PTR_ERR(file);
37299 + pr_err("%s[%d], err %d\n",
37300 + xinew->xi ? "xino" : "xigen",
37301 + xinew->idx, err);
37306 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37309 + /* todo: make xigen file an array */
37310 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37313 + if (unlikely(err))
37314 + file = ERR_PTR(err);
37320 +/* ---------------------------------------------------------------------- */
37323 + * truncate xino files
37325 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37326 + int idx, struct kstatfs *st)
37330 + struct file *file, *new_xino;
37331 + struct au_xi_new xinew = {
37336 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37337 + file = au_xino_file(xinew.xi, idx);
37341 + xinew.base = &file->f_path;
37342 + err = vfs_statfs(xinew.base, st);
37343 + if (unlikely(err)) {
37344 + AuErr1("statfs err %d, ignored\n", err);
37349 + blocks = file_inode(file)->i_blocks;
37350 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37351 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37353 + xinew.copy_src = file;
37354 + new_xino = au_xi_new(sb, &xinew);
37355 + if (IS_ERR(new_xino)) {
37356 + err = PTR_ERR(new_xino);
37357 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37361 + err = vfs_statfs(&new_xino->f_path, st);
37363 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37364 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37365 + st->f_bfree, st->f_blocks);
37367 + AuErr1("statfs err %d, ignored\n", err);
37375 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37378 + unsigned long jiffy;
37379 + aufs_bindex_t bbot;
37380 + struct kstatfs *st;
37381 + struct au_branch *br;
37382 + struct au_xino *xi;
37385 + st = kmalloc(sizeof(*st), GFP_NOFS);
37386 + if (unlikely(!st))
37390 + bbot = au_sbbot(sb);
37391 + if (unlikely(bindex < 0 || bbot < bindex))
37396 + br = au_sbr(sb, bindex);
37397 + xi = br->br_xino;
37398 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37399 + err = au_xino_do_trunc(sb, bindex, i, st);
37401 + au_sbi(sb)->si_xino_jiffy = jiffy;
37404 + au_kfree_rcu(st);
37409 +struct xino_do_trunc_args {
37410 + struct super_block *sb;
37411 + struct au_branch *br;
37415 +static void xino_do_trunc(void *_args)
37417 + struct xino_do_trunc_args *args = _args;
37418 + struct super_block *sb;
37419 + struct au_branch *br;
37420 + struct inode *dir;
37422 + aufs_bindex_t bindex;
37426 + dir = d_inode(sb->s_root);
37430 + si_noflush_write_lock(sb);
37431 + ii_read_lock_parent(dir);
37432 + bindex = au_br_index(sb, br->br_id);
37433 + err = au_xino_trunc(sb, bindex, idx);
37434 + ii_read_unlock(dir);
37435 + if (unlikely(err))
37436 + pr_warn("err b%d, (%d)\n", bindex, err);
37437 + atomic_dec(&br->br_xino->xi_truncating);
37438 + au_lcnt_dec(&br->br_count);
37439 + si_write_unlock(sb);
37440 + au_nwt_done(&au_sbi(sb)->si_nowait);
37441 + au_kfree_rcu(args);
37445 + * returns the index in the xi_file array whose corresponding file is necessary
37446 + * to truncate, or -1 which means no need to truncate.
37448 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37452 + struct kstatfs st;
37453 + struct au_sbinfo *sbinfo;
37454 + struct au_xino *xi;
37455 + struct file *file;
37457 + /* todo: si_xino_expire and the ratio should be customizable */
37458 + sbinfo = au_sbi(sb);
37459 + if (time_before(jiffies,
37460 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37463 + /* truncation border */
37464 + xi = br->br_xino;
37465 + for (u = 0; u < xi->xi_nfile; u++) {
37466 + file = au_xino_file(xi, u);
37470 + err = vfs_statfs(&file->f_path, &st);
37471 + if (unlikely(err)) {
37472 + AuErr1("statfs err %d, ignored\n", err);
37475 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37476 + >= AUFS_XINO_DEF_TRUNC)
37483 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37486 + struct xino_do_trunc_args *args;
37489 + idx = xino_trunc_test(sb, br);
37493 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37496 + /* lock and kfree() will be called in trunc_xino() */
37497 + args = kmalloc(sizeof(*args), GFP_NOFS);
37498 + if (unlikely(!args)) {
37499 + AuErr1("no memory\n");
37503 + au_lcnt_inc(&br->br_count);
37507 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37509 + return; /* success */
37511 + pr_err("wkq %d\n", wkq_err);
37512 + au_lcnt_dec(&br->br_count);
37513 + au_kfree_rcu(args);
37516 + atomic_dec(&br->br_xino->xi_truncating);
37519 +/* ---------------------------------------------------------------------- */
37521 +struct au_xi_calc {
37526 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37527 + struct au_xi_calc *calc)
37531 + maxent = au_xi_maxent(sb);
37532 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37533 + calc->pos *= sizeof(ino_t);
37536 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37537 + struct au_xi_calc *calc)
37540 + struct file *file;
37541 + struct au_xino *xi = br->br_xino;
37542 + struct au_xi_new xinew = {
37546 + SiMustAnyLock(sb);
37552 + mutex_lock(&xi->xi_mtx);
37553 + file = au_xino_file(xi, calc->idx);
37557 + file = au_xino_file(xi, /*idx*/-1);
37558 + AuDebugOn(!file);
37559 + xinew.idx = calc->idx;
37560 + xinew.base = &file->f_path;
37561 + /* xinew.copy_src = NULL; */
37562 + file = au_xi_new(sb, &xinew);
37563 + if (IS_ERR(file))
37564 + err = PTR_ERR(file);
37567 + mutex_unlock(&xi->xi_mtx);
37572 +struct au_xino_do_new_async_args {
37573 + struct super_block *sb;
37574 + struct au_branch *br;
37575 + struct au_xi_calc calc;
37579 +struct au_xi_writing {
37580 + struct hlist_bl_node node;
37581 + ino_t h_ino, ino;
37584 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37585 + struct au_xi_calc *calc, ino_t ino);
37587 +static void au_xino_call_do_new_async(void *args)
37589 + struct au_xino_do_new_async_args *a = args;
37590 + struct au_branch *br;
37591 + struct super_block *sb;
37592 + struct au_sbinfo *sbi;
37593 + struct inode *root;
37594 + struct file *file;
37595 + struct au_xi_writing *del, *p;
37596 + struct hlist_bl_head *hbl;
37597 + struct hlist_bl_node *pos;
37602 + sbi = au_sbi(sb);
37603 + si_noflush_read_lock(sb);
37604 + root = d_inode(sb->s_root);
37605 + ii_read_lock_child(root);
37606 + err = au_xino_do_new_async(sb, br, &a->calc);
37607 + if (unlikely(err)) {
37608 + AuIOErr("err %d\n", err);
37612 + file = au_xino_file(br->br_xino, a->calc.idx);
37613 + AuDebugOn(!file);
37614 + err = au_xino_do_write(sbi->si_xwrite, file, &a->calc, a->ino);
37615 + if (unlikely(err)) {
37616 + AuIOErr("err %d\n", err);
37621 + hbl = &br->br_xino->xi_writing;
37622 + hlist_bl_lock(hbl);
37623 + au_hbl_for_each(pos, hbl) {
37624 + p = container_of(pos, struct au_xi_writing, node);
37625 + if (p->ino == a->ino) {
37627 + hlist_bl_del(&p->node);
37631 + hlist_bl_unlock(hbl);
37632 + au_kfree_rcu(del);
37635 + au_lcnt_dec(&br->br_count);
37636 + ii_read_unlock(root);
37637 + si_read_unlock(sb);
37638 + au_nwt_done(&sbi->si_nowait);
37643 + * create a new xino file asynchronously
37645 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37646 + struct au_xi_calc *calc, ino_t ino)
37649 + struct au_xino_do_new_async_args *arg;
37652 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37653 + if (unlikely(!arg))
37658 + arg->calc = *calc;
37660 + au_lcnt_inc(&br->br_count);
37661 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37662 + if (unlikely(err)) {
37663 + pr_err("wkq %d\n", err);
37664 + au_lcnt_dec(&br->br_count);
37665 + au_kfree_rcu(arg);
37673 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37674 + * at the position of @h_ino.
37676 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37681 + struct au_xi_calc calc;
37682 + struct au_sbinfo *sbinfo;
37683 + struct file *file;
37684 + struct au_xino *xi;
37685 + struct hlist_bl_head *hbl;
37686 + struct hlist_bl_node *pos;
37687 + struct au_xi_writing *p;
37690 + if (!au_opt_test(au_mntflags(sb), XINO))
37691 + return 0; /* no xino */
37694 + au_xi_calc(sb, h_ino, &calc);
37695 + xi = au_sbr(sb, bindex)->br_xino;
37696 + file = au_xino_file(xi, calc.idx);
37698 + hbl = &xi->xi_writing;
37699 + hlist_bl_lock(hbl);
37700 + au_hbl_for_each(pos, hbl) {
37701 + p = container_of(pos, struct au_xi_writing, node);
37702 + if (p->h_ino == h_ino) {
37703 + AuDbg("hi%llu, i%llu, found\n",
37704 + (u64)p->h_ino, (u64)p->ino);
37709 + hlist_bl_unlock(hbl);
37711 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37712 + return 0; /* no xino */
37714 + sbinfo = au_sbi(sb);
37715 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &calc.pos);
37716 + if (sz == sizeof(*ino))
37717 + return 0; /* success */
37720 + if (unlikely(sz >= 0)) {
37722 + AuIOErr("xino read error (%zd)\n", sz);
37727 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37728 + struct au_xi_calc *calc, ino_t ino)
37732 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &calc->pos);
37733 + if (sz == sizeof(ino))
37734 + return 0; /* success */
37736 + AuIOErr("write failed (%zd)\n", sz);
37741 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37742 + * at the position of @h_ino.
37743 + * even if @ino is zero, it is written to the xinofile and means no entry.
37744 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37745 + * try truncating it.
37747 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37751 + unsigned int mnt_flags;
37752 + struct au_xi_calc calc;
37753 + struct file *file;
37754 + struct au_branch *br;
37755 + struct au_xino *xi;
37756 + struct au_xi_writing *p;
37758 + SiMustAnyLock(sb);
37760 + mnt_flags = au_mntflags(sb);
37761 + if (!au_opt_test(mnt_flags, XINO))
37764 + au_xi_calc(sb, h_ino, &calc);
37765 + br = au_sbr(sb, bindex);
37766 + xi = br->br_xino;
37767 + file = au_xino_file(xi, calc.idx);
37769 + /* store the inum pair into the list */
37770 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37771 + p->h_ino = h_ino;
37773 + au_hbl_add(&p->node, &xi->xi_writing);
37775 + /* create and write a new xino file asynchronously */
37776 + err = au_xino_new_async(sb, br, &calc, ino);
37778 + return 0; /* success */
37782 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, file, &calc, ino);
37784 + br = au_sbr(sb, bindex);
37785 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37786 + && au_test_fs_trunc_xino(au_br_sb(br)))
37787 + xino_try_trunc(sb, br);
37788 + return 0; /* success */
37792 + AuIOErr("write failed (%d)\n", err);
37796 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37797 + size_t size, loff_t *pos);
37799 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37800 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
37804 + mm_segment_t oldfs;
37810 + const int prevent_endless = 10;
37814 + oldfs = get_fs();
37815 + set_fs(KERNEL_DS);
37817 + err = func(file, buf.u, size, pos);
37818 + if (err == -EINTR
37819 + && !au_wkq_test()
37820 + && fatal_signal_pending(current)) {
37822 + err = xino_fread_wkq(func, file, kbuf, size, pos);
37823 + BUG_ON(err == -EINTR);
37824 + oldfs = get_fs();
37825 + set_fs(KERNEL_DS);
37827 + } while (i++ < prevent_endless
37828 + && (err == -EAGAIN || err == -EINTR));
37831 +#if 0 /* reserved for future use */
37833 + fsnotify_access(file->f_path.dentry);
37839 +struct xino_fread_args {
37841 + vfs_readf_t func;
37842 + struct file *file;
37848 +static void call_xino_fread(void *args)
37850 + struct xino_fread_args *a = args;
37851 + *a->errp = xino_fread(a->func, a->file, a->buf, a->size, a->pos);
37854 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37855 + size_t size, loff_t *pos)
37859 + struct xino_fread_args args = {
37868 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37869 + if (unlikely(wkq_err))
37875 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37876 + size_t size, loff_t *pos);
37878 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
37879 + size_t size, loff_t *pos)
37882 + mm_segment_t oldfs;
37885 + const char __user *u;
37888 + const int prevent_endless = 10;
37892 + oldfs = get_fs();
37893 + set_fs(KERNEL_DS);
37895 + err = func(file, buf.u, size, pos);
37896 + if (err == -EINTR
37897 + && !au_wkq_test()
37898 + && fatal_signal_pending(current)) {
37900 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
37901 + BUG_ON(err == -EINTR);
37902 + oldfs = get_fs();
37903 + set_fs(KERNEL_DS);
37905 + } while (i++ < prevent_endless
37906 + && (err == -EAGAIN || err == -EINTR));
37909 +#if 0 /* reserved for future use */
37911 + fsnotify_modify(file->f_path.dentry);
37917 +struct do_xino_fwrite_args {
37919 + vfs_writef_t func;
37920 + struct file *file;
37926 +static void call_do_xino_fwrite(void *args)
37928 + struct do_xino_fwrite_args *a = args;
37929 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
37932 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37933 + size_t size, loff_t *pos)
37937 + struct do_xino_fwrite_args args = {
37947 + * it breaks RLIMIT_FSIZE and normal user's limit,
37948 + * users should care about quota and real 'filesystem full.'
37950 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37951 + if (unlikely(wkq_err))
37957 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
37958 + size_t size, loff_t *pos)
37962 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37964 + err = do_xino_fwrite(func, file, buf, size, pos);
37968 + err = xino_fwrite_wkq(func, file, buf, size, pos);
37975 +/* ---------------------------------------------------------------------- */
37978 + * inode number bitmap
37980 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37981 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37985 + AuDebugOn(bit < 0 || page_bits <= bit);
37986 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37990 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37992 + AuDebugOn(ino < AUFS_FIRST_INO);
37993 + ino -= AUFS_FIRST_INO;
37994 + *pindex = ino / page_bits;
37995 + *bit = ino % page_bits;
37998 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
38003 + struct au_sbinfo *sbinfo;
38004 + struct file *xib;
38005 + unsigned long *p;
38007 + sbinfo = au_sbi(sb);
38008 + MtxMustLock(&sbinfo->si_xib_mtx);
38009 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
38010 + || !au_opt_test(sbinfo->si_mntflags, XINO));
38012 + if (pindex == sbinfo->si_xib_last_pindex)
38015 + xib = sbinfo->si_xib;
38016 + p = sbinfo->si_xib_buf;
38017 + pos = sbinfo->si_xib_last_pindex;
38018 + pos *= PAGE_SIZE;
38019 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
38020 + if (unlikely(sz != PAGE_SIZE))
38024 + pos *= PAGE_SIZE;
38025 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
38026 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
38028 + memset(p, 0, PAGE_SIZE);
38029 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
38031 + if (sz == PAGE_SIZE) {
38032 + sbinfo->si_xib_last_pindex = pindex;
38033 + return 0; /* success */
38037 + AuIOErr1("write failed (%zd)\n", sz);
38044 +static void au_xib_clear_bit(struct inode *inode)
38047 + unsigned long pindex;
38048 + struct super_block *sb;
38049 + struct au_sbinfo *sbinfo;
38051 + AuDebugOn(inode->i_nlink);
38053 + sb = inode->i_sb;
38054 + xib_calc_bit(inode->i_ino, &pindex, &bit);
38055 + AuDebugOn(page_bits <= bit);
38056 + sbinfo = au_sbi(sb);
38057 + mutex_lock(&sbinfo->si_xib_mtx);
38058 + err = xib_pindex(sb, pindex);
38060 + clear_bit(bit, sbinfo->si_xib_buf);
38061 + sbinfo->si_xib_next_bit = bit;
38063 + mutex_unlock(&sbinfo->si_xib_mtx);
38066 +/* ---------------------------------------------------------------------- */
38069 + * truncate a xino bitmap file
38073 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
38077 + unsigned long pindex;
38078 + loff_t pos, pend;
38079 + struct au_sbinfo *sbinfo;
38080 + vfs_readf_t func;
38082 + unsigned long *p;
38085 + sbinfo = au_sbi(sb);
38086 + MtxMustLock(&sbinfo->si_xib_mtx);
38087 + p = sbinfo->si_xib_buf;
38088 + func = sbinfo->si_xread;
38089 + pend = vfsub_f_size_read(file);
38091 + while (pos < pend) {
38092 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
38094 + if (unlikely(sz <= 0))
38098 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
38099 + if (unlikely(*ino < AUFS_FIRST_INO))
38102 + xib_calc_bit(*ino, &pindex, &bit);
38103 + AuDebugOn(page_bits <= bit);
38104 + err = xib_pindex(sb, pindex);
38116 +static int xib_restore(struct super_block *sb)
38119 + unsigned int nfile;
38120 + aufs_bindex_t bindex, bbot;
38122 + struct au_branch *br;
38123 + struct au_xino *xi;
38124 + struct file *file;
38127 + page = (void *)__get_free_page(GFP_NOFS);
38128 + if (unlikely(!page))
38132 + bbot = au_sbbot(sb);
38133 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38134 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38135 + br = au_sbr(sb, bindex);
38136 + xi = br->br_xino;
38137 + nfile = xi->xi_nfile;
38138 + for (i = 0; i < nfile; i++) {
38139 + file = au_xino_file(xi, i);
38141 + err = do_xib_restore(sb, file, page);
38144 + AuDbg("skip shared b%d\n", bindex);
38145 + free_page((unsigned long)page);
38151 +int au_xib_trunc(struct super_block *sb)
38156 + struct au_sbinfo *sbinfo;
38157 + unsigned long *p;
38158 + struct file *file;
38160 + SiMustWriteLock(sb);
38163 + sbinfo = au_sbi(sb);
38164 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38167 + file = sbinfo->si_xib;
38168 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38171 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38172 + err = PTR_ERR(file);
38173 + if (IS_ERR(file))
38175 + fput(sbinfo->si_xib);
38176 + sbinfo->si_xib = file;
38178 + p = sbinfo->si_xib_buf;
38179 + memset(p, 0, PAGE_SIZE);
38181 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
38182 + if (unlikely(sz != PAGE_SIZE)) {
38184 + AuIOErr("err %d\n", err);
38190 + mutex_lock(&sbinfo->si_xib_mtx);
38191 + /* mnt_want_write() is unnecessary here */
38192 + err = xib_restore(sb);
38193 + mutex_unlock(&sbinfo->si_xib_mtx);
38199 +/* ---------------------------------------------------------------------- */
38201 +struct au_xino *au_xino_alloc(unsigned int nfile)
38203 + struct au_xino *xi;
38205 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38206 + if (unlikely(!xi))
38208 + xi->xi_nfile = nfile;
38209 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38210 + if (unlikely(!xi->xi_file))
38213 + xi->xi_nondir.total = 8; /* initial size */
38214 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38216 + if (unlikely(!xi->xi_nondir.array))
38219 + spin_lock_init(&xi->xi_nondir.spin);
38220 + init_waitqueue_head(&xi->xi_nondir.wqh);
38221 + mutex_init(&xi->xi_mtx);
38222 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38223 + atomic_set(&xi->xi_truncating, 0);
38224 + kref_init(&xi->xi_kref);
38225 + goto out; /* success */
38228 + au_kfree_try_rcu(xi->xi_file);
38230 + au_kfree_rcu(xi);
38236 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38239 + struct au_xino *xi;
38242 + xi = au_xino_alloc(idx + 1);
38243 + if (unlikely(!xi)) {
38250 + xi->xi_file[idx] = file;
38251 + AuDebugOn(br->br_xino);
38252 + br->br_xino = xi;
38258 +static void au_xino_release(struct kref *kref)
38260 + struct au_xino *xi;
38262 + unsigned long ul;
38263 + struct hlist_bl_head *hbl;
38264 + struct hlist_bl_node *pos, *n;
38265 + struct au_xi_writing *p;
38267 + xi = container_of(kref, struct au_xino, xi_kref);
38268 + for (i = 0; i < xi->xi_nfile; i++)
38269 + if (xi->xi_file[i])
38270 + fput(xi->xi_file[i]);
38271 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38272 + AuDebugOn(xi->xi_nondir.array[i]);
38273 + mutex_destroy(&xi->xi_mtx);
38274 + hbl = &xi->xi_writing;
38275 + ul = au_hbl_count(hbl);
38276 + if (unlikely(ul)) {
38277 + pr_warn("xi_writing %lu\n", ul);
38278 + hlist_bl_lock(hbl);
38279 + hlist_bl_for_each_entry_safe (p, pos, n, hbl, node) {
38280 + hlist_bl_del(&p->node);
38283 + hlist_bl_unlock(hbl);
38285 + au_kfree_try_rcu(xi->xi_file);
38286 + au_kfree_try_rcu(xi->xi_nondir.array);
38287 + au_kfree_rcu(xi);
38290 +int au_xino_put(struct au_branch *br)
38293 + struct au_xino *xi;
38296 + xi = br->br_xino;
38298 + br->br_xino = NULL;
38299 + ret = kref_put(&xi->xi_kref, au_xino_release);
38305 +/* ---------------------------------------------------------------------- */
38308 + * xino mount option handlers
38312 +static void xino_clear_xib(struct super_block *sb)
38314 + struct au_sbinfo *sbinfo;
38316 + SiMustWriteLock(sb);
38318 + sbinfo = au_sbi(sb);
38319 + /* unnecessary to clear sbinfo->si_xread and ->si_xwrite */
38320 + if (sbinfo->si_xib)
38321 + fput(sbinfo->si_xib);
38322 + sbinfo->si_xib = NULL;
38323 + if (sbinfo->si_xib_buf)
38324 + free_page((unsigned long)sbinfo->si_xib_buf);
38325 + sbinfo->si_xib_buf = NULL;
38328 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38332 + struct au_sbinfo *sbinfo;
38333 + struct file *file;
38334 + struct super_block *xi_sb;
38336 + SiMustWriteLock(sb);
38338 + sbinfo = au_sbi(sb);
38339 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38340 + err = PTR_ERR(file);
38341 + if (IS_ERR(file))
38343 + if (sbinfo->si_xib)
38344 + fput(sbinfo->si_xib);
38345 + sbinfo->si_xib = file;
38346 + sbinfo->si_xread = vfs_readf(file);
38347 + sbinfo->si_xwrite = vfs_writef(file);
38348 + xi_sb = file_inode(file)->i_sb;
38349 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38350 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38352 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38353 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38356 + sbinfo->si_ximaxent /= sizeof(ino_t);
38359 + if (!sbinfo->si_xib_buf)
38360 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38361 + if (unlikely(!sbinfo->si_xib_buf))
38364 + sbinfo->si_xib_last_pindex = 0;
38365 + sbinfo->si_xib_next_bit = 0;
38366 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38368 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
38369 + PAGE_SIZE, &pos);
38370 + if (unlikely(err != PAGE_SIZE))
38374 + goto out; /* success */
38377 + if (sbinfo->si_xib_buf)
38378 + free_page((unsigned long)sbinfo->si_xib_buf);
38379 + sbinfo->si_xib_buf = NULL;
38383 + fput(sbinfo->si_xib);
38384 + sbinfo->si_xib = NULL;
38390 +/* xino for each branch */
38391 +static void xino_clear_br(struct super_block *sb)
38393 + aufs_bindex_t bindex, bbot;
38394 + struct au_branch *br;
38396 + bbot = au_sbbot(sb);
38397 + for (bindex = 0; bindex <= bbot; bindex++) {
38398 + br = au_sbr(sb, bindex);
38404 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38405 + aufs_bindex_t bshared)
38407 + struct au_branch *brshared;
38409 + brshared = au_sbr(sb, bshared);
38410 + AuDebugOn(!brshared->br_xino);
38411 + AuDebugOn(!brshared->br_xino->xi_file);
38412 + if (br->br_xino != brshared->br_xino) {
38413 + au_xino_get(brshared);
38415 + br->br_xino = brshared->br_xino;
38419 +struct au_xino_do_set_br {
38420 + vfs_writef_t writef;
38421 + struct au_branch *br;
38423 + aufs_bindex_t bshared;
38426 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38427 + struct au_xino_do_set_br *args)
38430 + struct au_xi_calc calc;
38431 + struct file *file;
38432 + struct au_branch *br;
38433 + struct au_xi_new xinew = {
38438 + xinew.xi = br->br_xino;
38439 + au_xi_calc(sb, args->h_ino, &calc);
38440 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38441 + if (args->bshared >= 0)
38442 + /* shared xino */
38443 + au_xino_set_br_shared(sb, br, args->bshared);
38444 + else if (!xinew.xi) {
38446 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38447 + if (unlikely(err))
38451 + /* force re-creating */
38452 + xinew.xi = br->br_xino;
38453 + xinew.idx = calc.idx;
38454 + mutex_lock(&xinew.xi->xi_mtx);
38455 + file = au_xi_new(sb, &xinew);
38456 + mutex_unlock(&xinew.xi->xi_mtx);
38457 + err = PTR_ERR(file);
38458 + if (IS_ERR(file))
38460 + AuDebugOn(!file);
38462 + err = au_xino_do_write(args->writef, file, &calc, AUFS_ROOT_INO);
38463 + if (unlikely(err))
38471 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38474 + aufs_bindex_t bindex, bbot;
38475 + struct au_xino_do_set_br args;
38476 + struct inode *inode;
38478 + SiMustWriteLock(sb);
38480 + bbot = au_sbbot(sb);
38481 + inode = d_inode(sb->s_root);
38482 + args.writef = au_sbi(sb)->si_xwrite;
38483 + for (bindex = 0; bindex <= bbot; bindex++) {
38484 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38485 + args.br = au_sbr(sb, bindex);
38486 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38487 + err = au_xino_do_set_br(sb, path, &args);
38488 + if (unlikely(err))
38496 +void au_xino_clr(struct super_block *sb)
38498 + struct au_sbinfo *sbinfo;
38500 + au_xigen_clr(sb);
38501 + xino_clear_xib(sb);
38502 + xino_clear_br(sb);
38503 + dbgaufs_brs_del(sb, 0);
38504 + sbinfo = au_sbi(sb);
38505 + /* lvalue, do not call au_mntflags() */
38506 + au_opt_clr(sbinfo->si_mntflags, XINO);
38509 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38512 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38513 + struct qstr *dname, *cur_name;
38514 + struct file *cur_xino;
38515 + struct au_sbinfo *sbinfo;
38516 + struct path *path, *cur_path;
38518 + SiMustWriteLock(sb);
38521 + sbinfo = au_sbi(sb);
38522 + path = &xiopt->file->f_path;
38523 + dentry = path->dentry;
38524 + parent = dget_parent(dentry);
38527 + cur_xino = sbinfo->si_xib;
38529 + cur_path = &cur_xino->f_path;
38530 + cur_dentry = cur_path->dentry;
38531 + cur_parent = dget_parent(cur_dentry);
38532 + cur_name = &cur_dentry->d_name;
38533 + dname = &dentry->d_name;
38534 + skip = (cur_parent == parent
38535 + && au_qstreq(dname, cur_name));
38536 + dput(cur_parent);
38542 + au_opt_set(sbinfo->si_mntflags, XINO);
38543 + err = au_xino_set_xib(sb, path);
38544 + /* si_x{read,write} are set */
38546 + err = au_xigen_set(sb, path);
38548 + err = au_xino_set_br(sb, path);
38550 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38551 + goto out; /* success */
38555 + AuIOErr("failed setting xino(%d).\n", err);
38564 + * create a xinofile at the default place/path.
38566 +struct file *au_xino_def(struct super_block *sb)
38568 + struct file *file;
38570 + struct au_branch *br;
38571 + struct super_block *h_sb;
38572 + struct path path;
38573 + aufs_bindex_t bbot, bindex, bwr;
38576 + bbot = au_sbbot(sb);
38578 + for (bindex = 0; bindex <= bbot; bindex++) {
38579 + br = au_sbr(sb, bindex);
38580 + if (au_br_writable(br->br_perm)
38581 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38588 + file = ERR_PTR(-ENOMEM);
38589 + page = (void *)__get_free_page(GFP_NOFS);
38590 + if (unlikely(!page))
38592 + path.mnt = au_br_mnt(br);
38593 + path.dentry = au_h_dptr(sb->s_root, bwr);
38594 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38595 + file = (void *)p;
38596 + if (!IS_ERR(p)) {
38597 + strcat(p, "/" AUFS_XINO_FNAME);
38598 + AuDbg("%s\n", p);
38599 + file = au_xino_create(sb, p, /*silent*/0);
38601 + free_page((unsigned long)page);
38603 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
38604 + if (IS_ERR(file))
38606 + h_sb = file->f_path.dentry->d_sb;
38607 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38608 + pr_err("xino doesn't support %s(%s)\n",
38609 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38611 + file = ERR_PTR(-EINVAL);
38619 +/* ---------------------------------------------------------------------- */
38622 + * initialize the xinofile for the specified branch @br
38623 + * at the place/path where @base_file indicates.
38624 + * test whether another branch is on the same filesystem or not,
38625 + * if found then share the xinofile with another branch.
38627 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38628 + struct path *base)
38631 + struct au_xino_do_set_br args = {
38636 + args.writef = au_sbi(sb)->si_xwrite;
38637 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38639 + err = au_xino_do_set_br(sb, base, &args);
38640 + if (unlikely(err))
38646 +/* ---------------------------------------------------------------------- */
38649 + * get an unused inode number from bitmap
38651 +ino_t au_xino_new_ino(struct super_block *sb)
38654 + unsigned long *p, pindex, ul, pend;
38655 + struct au_sbinfo *sbinfo;
38656 + struct file *file;
38657 + int free_bit, err;
38659 + if (!au_opt_test(au_mntflags(sb), XINO))
38660 + return iunique(sb, AUFS_FIRST_INO);
38662 + sbinfo = au_sbi(sb);
38663 + mutex_lock(&sbinfo->si_xib_mtx);
38664 + p = sbinfo->si_xib_buf;
38665 + free_bit = sbinfo->si_xib_next_bit;
38666 + if (free_bit < page_bits && !test_bit(free_bit, p))
38667 + goto out; /* success */
38668 + free_bit = find_first_zero_bit(p, page_bits);
38669 + if (free_bit < page_bits)
38670 + goto out; /* success */
38672 + pindex = sbinfo->si_xib_last_pindex;
38673 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38674 + err = xib_pindex(sb, ul);
38675 + if (unlikely(err))
38677 + free_bit = find_first_zero_bit(p, page_bits);
38678 + if (free_bit < page_bits)
38679 + goto out; /* success */
38682 + file = sbinfo->si_xib;
38683 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38684 + for (ul = pindex + 1; ul <= pend; ul++) {
38685 + err = xib_pindex(sb, ul);
38686 + if (unlikely(err))
38688 + free_bit = find_first_zero_bit(p, page_bits);
38689 + if (free_bit < page_bits)
38690 + goto out; /* success */
38695 + set_bit(free_bit, p);
38696 + sbinfo->si_xib_next_bit = free_bit + 1;
38697 + pindex = sbinfo->si_xib_last_pindex;
38698 + mutex_unlock(&sbinfo->si_xib_mtx);
38699 + ino = xib_calc_ino(pindex, free_bit);
38700 + AuDbg("i%lu\n", (unsigned long)ino);
38703 + mutex_unlock(&sbinfo->si_xib_mtx);
38708 +/* for s_op->delete_inode() */
38709 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38712 + unsigned int mnt_flags;
38713 + aufs_bindex_t bindex, bbot, bi;
38714 + unsigned char try_trunc;
38715 + struct au_iinfo *iinfo;
38716 + struct super_block *sb;
38717 + struct au_hinode *hi;
38718 + struct inode *h_inode;
38719 + struct au_branch *br;
38720 + vfs_writef_t xwrite;
38721 + struct au_xi_calc calc;
38722 + struct file *file;
38724 + AuDebugOn(au_is_bad_inode(inode));
38726 + sb = inode->i_sb;
38727 + mnt_flags = au_mntflags(sb);
38728 + if (!au_opt_test(mnt_flags, XINO)
38729 + || inode->i_ino == AUFS_ROOT_INO)
38733 + au_xigen_inc(inode);
38734 + au_xib_clear_bit(inode);
38737 + iinfo = au_ii(inode);
38738 + bindex = iinfo->ii_btop;
38742 + xwrite = au_sbi(sb)->si_xwrite;
38743 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38744 + hi = au_hinode(iinfo, bindex);
38745 + bbot = iinfo->ii_bbot;
38746 + for (; bindex <= bbot; bindex++, hi++) {
38747 + h_inode = hi->hi_inode;
38749 + || (!unlinked && h_inode->i_nlink))
38752 + /* inode may not be revalidated */
38753 + bi = au_br_index(sb, hi->hi_id);
38757 + br = au_sbr(sb, bi);
38758 + au_xi_calc(sb, h_inode->i_ino, &calc);
38759 + file = au_xino_file(br->br_xino, calc.idx);
38760 + if (IS_ERR_OR_NULL(file))
38763 + err = au_xino_do_write(xwrite, file, &calc, /*ino*/0);
38764 + if (!err && try_trunc
38765 + && au_test_fs_trunc_xino(au_br_sb(br)))
38766 + xino_try_trunc(sb, br);
38770 +/* ---------------------------------------------------------------------- */
38772 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38774 + int found, total, i;
38777 + total = xi->xi_nondir.total;
38778 + for (i = 0; i < total; i++) {
38779 + if (xi->xi_nondir.array[i] != h_ino)
38788 +static int au_xinondir_expand(struct au_xino *xi)
38793 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38796 + sz = xi->xi_nondir.total * sizeof(ino_t);
38797 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38799 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38800 + /*may_shrink*/0);
38802 + xi->xi_nondir.array = p;
38803 + xi->xi_nondir.total <<= 1;
38804 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38812 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38813 + ino_t h_ino, int idx)
38815 + struct au_xino *xi;
38817 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38818 + xi = au_sbr(sb, bindex)->br_xino;
38819 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38821 + spin_lock(&xi->xi_nondir.spin);
38822 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38823 + xi->xi_nondir.array[idx] = 0;
38824 + spin_unlock(&xi->xi_nondir.spin);
38825 + wake_up_all(&xi->xi_nondir.wqh);
38828 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38831 + int err, found, empty;
38832 + struct au_xino *xi;
38836 + if (!au_opt_test(au_mntflags(sb), XINO))
38837 + goto out; /* no xino */
38839 + xi = au_sbr(sb, bindex)->br_xino;
38842 + spin_lock(&xi->xi_nondir.spin);
38843 + found = au_xinondir_find(xi, h_ino);
38844 + if (found == -1) {
38845 + empty = au_xinondir_find(xi, /*h_ino*/0);
38846 + if (empty == -1) {
38847 + empty = xi->xi_nondir.total;
38848 + err = au_xinondir_expand(xi);
38849 + if (unlikely(err))
38852 + xi->xi_nondir.array[empty] = h_ino;
38855 + spin_unlock(&xi->xi_nondir.spin);
38856 + wait_event(xi->xi_nondir.wqh,
38857 + xi->xi_nondir.array[found] != h_ino);
38862 + spin_unlock(&xi->xi_nondir.spin);
38867 +/* ---------------------------------------------------------------------- */
38869 +int au_xino_path(struct seq_file *seq, struct file *file)
38873 + err = au_seq_path(seq, &file->f_path);
38874 + if (unlikely(err))
38877 +#define Deleted "\\040(deleted)"
38878 + seq->count -= sizeof(Deleted) - 1;
38879 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38880 + sizeof(Deleted) - 1));
38886 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38887 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38888 +++ linux/include/uapi/linux/aufs_type.h 2018-12-27 13:19:17.715082917 +0100
38890 +/* SPDX-License-Identifier: GPL-2.0 */
38892 + * Copyright (C) 2005-2018 Junjiro R. Okajima
38894 + * This program, aufs is free software; you can redistribute it and/or modify
38895 + * it under the terms of the GNU General Public License as published by
38896 + * the Free Software Foundation; either version 2 of the License, or
38897 + * (at your option) any later version.
38899 + * This program is distributed in the hope that it will be useful,
38900 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38901 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38902 + * GNU General Public License for more details.
38904 + * You should have received a copy of the GNU General Public License
38905 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38908 +#ifndef __AUFS_TYPE_H__
38909 +#define __AUFS_TYPE_H__
38911 +#define AUFS_NAME "aufs"
38915 + * define it before including all other headers.
38916 + * sched.h may use pr_* macros before defining "current", so define the
38917 + * no-current version first, and re-define later.
38919 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38920 +#include <linux/sched.h>
38922 +#define pr_fmt(fmt) \
38923 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38924 + (int)sizeof(current->comm), current->comm, current->pid
38926 +#include <stdint.h>
38927 +#include <sys/types.h>
38928 +#endif /* __KERNEL__ */
38930 +#include <linux/limits.h>
38932 +#define AUFS_VERSION "4.x-rcN-20181217"
38934 +/* todo? move this to linux-2.6.19/include/magic.h */
38935 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38937 +/* ---------------------------------------------------------------------- */
38939 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38940 +typedef int8_t aufs_bindex_t;
38941 +#define AUFS_BRANCH_MAX 127
38943 +typedef int16_t aufs_bindex_t;
38944 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38945 +#define AUFS_BRANCH_MAX 511
38946 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38947 +#define AUFS_BRANCH_MAX 1023
38948 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38949 +#define AUFS_BRANCH_MAX 32767
38954 +#ifndef AUFS_BRANCH_MAX
38955 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38957 +#endif /* __KERNEL__ */
38959 +/* ---------------------------------------------------------------------- */
38961 +#define AUFS_FSTYPE AUFS_NAME
38963 +#define AUFS_ROOT_INO 2
38964 +#define AUFS_FIRST_INO 11
38966 +#define AUFS_WH_PFX ".wh."
38967 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38968 +#define AUFS_WH_TMP_LEN 4
38969 +/* a limit for rmdir/rename a dir and copyup */
38970 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38971 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38973 + - AUFS_WH_TMP_LEN) /* hex */
38974 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38975 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38976 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38977 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38978 +#define AUFS_DIRWH_DEF 3
38979 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38980 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38981 +#define AUFS_RDBLK_DEF 512 /* bytes */
38982 +#define AUFS_RDHASH_DEF 32
38983 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38984 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38985 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38986 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38987 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38989 +/* pseudo-link maintenace under /proc */
38990 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38991 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38992 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38994 +/* dirren, renamed dir */
38995 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38996 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38997 +/* whiteouted doubly */
38998 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38999 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
39001 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
39002 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
39004 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
39005 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
39006 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
39008 +/* doubly whiteouted */
39009 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
39010 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
39011 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
39013 +/* branch permissions and attributes */
39014 +#define AUFS_BRPERM_RW "rw"
39015 +#define AUFS_BRPERM_RO "ro"
39016 +#define AUFS_BRPERM_RR "rr"
39017 +#define AUFS_BRATTR_COO_REG "coo_reg"
39018 +#define AUFS_BRATTR_COO_ALL "coo_all"
39019 +#define AUFS_BRATTR_FHSM "fhsm"
39020 +#define AUFS_BRATTR_UNPIN "unpin"
39021 +#define AUFS_BRATTR_ICEX "icex"
39022 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
39023 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
39024 +#define AUFS_BRATTR_ICEX_TR "icextr"
39025 +#define AUFS_BRATTR_ICEX_USR "icexusr"
39026 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
39027 +#define AUFS_BRRATTR_WH "wh"
39028 +#define AUFS_BRWATTR_NLWH "nolwh"
39029 +#define AUFS_BRWATTR_MOO "moo"
39031 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
39032 +#define AuBrPerm_RO (1 << 1) /* readonly */
39033 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
39034 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
39036 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
39037 +#define AuBrAttr_COO_ALL (1 << 4)
39038 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
39040 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
39041 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
39042 + branch. meaningless since
39043 + linux-3.18-rc1 */
39045 +/* ignore error in copying XATTR */
39046 +#define AuBrAttr_ICEX_SEC (1 << 7)
39047 +#define AuBrAttr_ICEX_SYS (1 << 8)
39048 +#define AuBrAttr_ICEX_TR (1 << 9)
39049 +#define AuBrAttr_ICEX_USR (1 << 10)
39050 +#define AuBrAttr_ICEX_OTH (1 << 11)
39051 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
39052 + | AuBrAttr_ICEX_SYS \
39053 + | AuBrAttr_ICEX_TR \
39054 + | AuBrAttr_ICEX_USR \
39055 + | AuBrAttr_ICEX_OTH)
39057 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
39058 +#define AuBrRAttr_Mask AuBrRAttr_WH
39060 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
39061 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
39062 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
39064 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
39066 +/* #warning test userspace */
39068 +#ifndef CONFIG_AUFS_FHSM
39069 +#undef AuBrAttr_FHSM
39070 +#define AuBrAttr_FHSM 0
39072 +#ifndef CONFIG_AUFS_XATTR
39073 +#undef AuBrAttr_ICEX
39074 +#define AuBrAttr_ICEX 0
39075 +#undef AuBrAttr_ICEX_SEC
39076 +#define AuBrAttr_ICEX_SEC 0
39077 +#undef AuBrAttr_ICEX_SYS
39078 +#define AuBrAttr_ICEX_SYS 0
39079 +#undef AuBrAttr_ICEX_TR
39080 +#define AuBrAttr_ICEX_TR 0
39081 +#undef AuBrAttr_ICEX_USR
39082 +#define AuBrAttr_ICEX_USR 0
39083 +#undef AuBrAttr_ICEX_OTH
39084 +#define AuBrAttr_ICEX_OTH 0
39088 +/* the longest combination */
39089 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
39090 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
39091 + "+" AUFS_BRATTR_COO_REG \
39092 + "+" AUFS_BRATTR_FHSM \
39093 + "+" AUFS_BRATTR_UNPIN \
39094 + "+" AUFS_BRATTR_ICEX_SEC \
39095 + "+" AUFS_BRATTR_ICEX_SYS \
39096 + "+" AUFS_BRATTR_ICEX_USR \
39097 + "+" AUFS_BRATTR_ICEX_OTH \
39098 + "+" AUFS_BRWATTR_NLWH)
39101 + char a[AuBrPermStrSz];
39102 +} au_br_perm_str_t;
39104 +static inline int au_br_writable(int brperm)
39106 + return brperm & AuBrPerm_RW;
39109 +static inline int au_br_whable(int brperm)
39111 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
39114 +static inline int au_br_wh_linkable(int brperm)
39116 + return !(brperm & AuBrWAttr_NoLinkWH);
39119 +static inline int au_br_cmoo(int brperm)
39121 + return brperm & AuBrAttr_CMOO_Mask;
39124 +static inline int au_br_fhsm(int brperm)
39126 + return brperm & AuBrAttr_FHSM;
39129 +/* ---------------------------------------------------------------------- */
39133 + /* readdir in userspace */
39137 + AuCtl_WBR_FD, /* pathconf wrapper */
39138 + AuCtl_IBUSY, /* busy inode */
39139 + AuCtl_MVDOWN, /* move-down */
39140 + AuCtl_BR, /* info about branches */
39141 + AuCtl_FHSM_FD /* connection for fhsm */
39144 +/* borrowed from linux/include/linux/kernel.h */
39146 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39147 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39150 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39152 +#define __aligned(x) __attribute__((aligned(x)))
39157 +#define __packed __attribute__((packed))
39161 +struct au_rdu_cookie {
39166 + uint32_t generation;
39169 +struct au_rdu_ent {
39178 +static inline int au_rdu_len(int nlen)
39180 + /* include the terminating NULL */
39181 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39182 + sizeof(uint64_t));
39185 +union au_rdu_ent_ul {
39186 + struct au_rdu_ent __user *e;
39198 + uint64_t sz; /* AuCtl_RDU */
39199 + uint64_t nent; /* AuCtl_RDU_INO */
39201 + union au_rdu_ent_ul ent;
39202 + uint16_t verify[AufsCtlRduV_End];
39204 + /* input/output */
39208 + union au_rdu_ent_ul tail;
39209 + /* number of entries which were added in a single call */
39214 + struct au_rdu_cookie cookie;
39217 +/* ---------------------------------------------------------------------- */
39219 +/* dirren. the branch is identified by the filename who contains this */
39220 +struct au_drinfo {
39223 + uint8_t oldnamelen;
39224 + uint64_t _padding;
39226 + uint8_t oldname[0];
39229 +struct au_drinfo_fdata {
39231 + struct au_drinfo drinfo;
39234 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39236 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39238 +/* ---------------------------------------------------------------------- */
39240 +struct aufs_wbr_fd {
39245 +/* ---------------------------------------------------------------------- */
39247 +struct aufs_ibusy {
39248 + uint64_t ino, h_ino;
39252 +/* ---------------------------------------------------------------------- */
39254 +/* error code for move-down */
39255 +/* the actual message strings are implemented in aufs-util.git */
39257 + EAU_MVDOWN_OPAQUE = 1,
39258 + EAU_MVDOWN_WHITEOUT,
39259 + EAU_MVDOWN_UPPER,
39260 + EAU_MVDOWN_BOTTOM,
39261 + EAU_MVDOWN_NOUPPER,
39262 + EAU_MVDOWN_NOLOWERBR,
39266 +/* flags for move-down */
39267 +#define AUFS_MVDOWN_DMSG 1
39268 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39269 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39270 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39271 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39272 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39273 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39274 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39275 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39276 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39277 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39278 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39279 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39281 +/* index for move-down */
39283 + AUFS_MVDOWN_UPPER,
39284 + AUFS_MVDOWN_LOWER,
39285 + AUFS_MVDOWN_NARRAY
39289 + * additional info of move-down
39290 + * number of free blocks and inodes.
39291 + * subset of struct kstatfs, but smaller and always 64bit.
39293 +struct aufs_stfs {
39294 + uint64_t f_blocks;
39295 + uint64_t f_bavail;
39296 + uint64_t f_files;
39297 + uint64_t f_ffree;
39300 +struct aufs_stbr {
39301 + int16_t brid; /* optional input */
39302 + int16_t bindex; /* output */
39303 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39306 +struct aufs_mvdown {
39307 + uint32_t flags; /* input/output */
39308 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39309 + int8_t au_errno; /* output */
39312 +/* ---------------------------------------------------------------------- */
39314 +union aufs_brinfo {
39315 + /* PATH_MAX may differ between kernel-space and user-space */
39316 + char _spacer[4096];
39324 +/* ---------------------------------------------------------------------- */
39326 +#define AuCtlType 'A'
39327 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39328 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39329 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39330 + struct aufs_wbr_fd)
39331 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39332 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39333 + struct aufs_mvdown)
39334 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39335 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39337 +#endif /* __AUFS_TYPE_H__ */
39338 SPDX-License-Identifier: GPL-2.0
39339 aufs4.x-rcN loopback patch
39341 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39342 index 470dd02..20dc3ec 100644
39343 --- a/drivers/block/loop.c
39344 +++ b/drivers/block/loop.c
39345 @@ -625,6 +625,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39349 +static struct file *loop_real_file(struct file *file)
39351 + struct file *f = NULL;
39353 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39354 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39358 static void loop_reread_partitions(struct loop_device *lo,
39359 struct block_device *bdev)
39361 @@ -689,6 +698,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39364 struct file *file, *old_file;
39365 + struct file *f, *virt_file = NULL, *old_virt_file;
39369 @@ -704,12 +714,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39373 + f = loop_real_file(file);
39375 + virt_file = file;
39380 error = loop_validate_file(file, bdev);
39384 old_file = lo->lo_backing_file;
39385 + old_virt_file = lo->lo_backing_virt_file;
39389 @@ -721,6 +738,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39390 blk_mq_freeze_queue(lo->lo_queue);
39391 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39392 lo->lo_backing_file = file;
39393 + lo->lo_backing_virt_file = virt_file;
39394 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39395 mapping_set_gfp_mask(file->f_mapping,
39396 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39397 @@ -728,12 +746,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39398 blk_mq_unfreeze_queue(lo->lo_queue);
39401 + if (old_virt_file)
39402 + fput(old_virt_file);
39403 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
39404 loop_reread_partitions(lo, bdev);
39414 @@ -921,7 +943,7 @@ static int loop_prepare_queue(struct loop_device *lo)
39415 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39416 struct block_device *bdev, unsigned int arg)
39418 - struct file *file;
39419 + struct file *file, *f, *virt_file = NULL;
39420 struct inode *inode;
39421 struct address_space *mapping;
39423 @@ -935,6 +957,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39427 + f = loop_real_file(file);
39429 + virt_file = file;
39435 if (lo->lo_state != Lo_unbound)
39436 @@ -967,6 +995,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39437 lo->lo_device = bdev;
39438 lo->lo_flags = lo_flags;
39439 lo->lo_backing_file = file;
39440 + lo->lo_backing_virt_file = virt_file;
39441 lo->transfer = NULL;
39443 lo->lo_sizelimit = 0;
39444 @@ -1000,6 +1029,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39451 /* This is safe: open() is still holding a reference. */
39452 module_put(THIS_MODULE);
39453 @@ -1046,6 +1077,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
39454 static int loop_clr_fd(struct loop_device *lo)
39456 struct file *filp = lo->lo_backing_file;
39457 + struct file *virt_filp = lo->lo_backing_virt_file;
39458 gfp_t gfp = lo->old_gfp_mask;
39459 struct block_device *bdev = lo->lo_device;
39461 @@ -1077,6 +1109,7 @@ static int loop_clr_fd(struct loop_device *lo)
39462 spin_lock_irq(&lo->lo_lock);
39463 lo->lo_state = Lo_rundown;
39464 lo->lo_backing_file = NULL;
39465 + lo->lo_backing_virt_file = NULL;
39466 spin_unlock_irq(&lo->lo_lock);
39468 loop_release_xfer(lo);
39469 @@ -1125,6 +1158,8 @@ static int loop_clr_fd(struct loop_device *lo)
39470 * bd_mutex which is usually taken before lo_ctl_mutex.
39478 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39479 index 4d42c7a..a4974ee 100644
39480 --- a/drivers/block/loop.h
39481 +++ b/drivers/block/loop.h
39482 @@ -46,7 +46,7 @@ struct loop_device {
39483 int (*ioctl)(struct loop_device *, int cmd,
39484 unsigned long arg);
39486 - struct file * lo_backing_file;
39487 + struct file * lo_backing_file, *lo_backing_virt_file;
39488 struct block_device *lo_device;
39491 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39492 index 5309874..1a334cf 100644
39493 --- a/fs/aufs/f_op.c
39494 +++ b/fs/aufs/f_op.c
39495 @@ -359,7 +359,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39496 if (IS_ERR(h_file))
39499 - if (au_test_loopback_kthread()) {
39500 + if (0 && au_test_loopback_kthread()) {
39501 au_warn_loopback(h_file->f_path.dentry->d_sb);
39502 if (file->f_mapping != h_file->f_mapping) {
39503 file->f_mapping = h_file->f_mapping;
39504 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39505 index 3f3577d..3b44158 100644
39506 --- a/fs/aufs/loop.c
39507 +++ b/fs/aufs/loop.c
39508 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39509 symbol_put(loop_backing_file);
39510 au_kfree_try_rcu(au_warn_loopback_array);
39513 +/* ---------------------------------------------------------------------- */
39515 +/* support the loopback block device insude aufs */
39517 +struct file *aufs_real_loop(struct file *file)
39521 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39522 + fi_read_lock(file);
39523 + f = au_hf_top(file);
39524 + fi_read_unlock(file);
39528 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39529 index 05d703d..6bb23c8 100644
39530 --- a/fs/aufs/loop.h
39531 +++ b/fs/aufs/loop.h
39532 @@ -26,7 +26,11 @@ void au_warn_loopback(struct super_block *h_sb);
39534 int au_loopback_init(void);
39535 void au_loopback_fin(void);
39537 +struct file *aufs_real_loop(struct file *file);
39539 +AuStub(struct file *, loop_backing_file, return NULL)
39541 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
39542 struct dentry *h_adding)
39543 AuStubInt0(au_test_loopback_kthread, void)
39544 @@ -34,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39546 AuStubInt0(au_loopback_init, void)
39547 AuStubVoid(au_loopback_fin, void)
39549 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39550 #endif /* BLK_DEV_LOOP */
39552 #endif /* __KERNEL__ */
39553 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39554 index 777503e..7130061 100644
39555 --- a/fs/aufs/super.c
39556 +++ b/fs/aufs/super.c
39557 @@ -845,7 +845,10 @@ static const struct super_operations aufs_sop = {
39558 .statfs = aufs_statfs,
39559 .put_super = aufs_put_super,
39560 .sync_fs = aufs_sync_fs,
39561 - .remount_fs = aufs_remount_fs
39562 + .remount_fs = aufs_remount_fs,
39563 +#ifdef CONFIG_AUFS_BDEV_LOOP
39564 + .real_loop = aufs_real_loop
39568 /* ---------------------------------------------------------------------- */
39569 diff --git a/include/linux/fs.h b/include/linux/fs.h
39570 index 0e44705..59fb8ae 100644
39571 --- a/include/linux/fs.h
39572 +++ b/include/linux/fs.h
39573 @@ -1931,6 +1931,10 @@ struct super_operations {
39574 struct shrink_control *);
39575 long (*free_cached_objects)(struct super_block *,
39576 struct shrink_control *);
39577 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
39579 + struct file *(*real_loop)(struct file *);