1 SPDX-License-Identifier: GPL-2.0
2 aufs4.x-rcN kbuild patch
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index ac474a61be37..284cee954591 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 293733f61594..12d19d0de07a 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 8c68de3cfd80..c08e5dd95b5f 100644
32 @@ -2636,6 +2636,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 cf5538942834..a271e17e4b10 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 aac41adf4743..fc18967c2522 100644
85 @@ -1247,7 +1247,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 083185174c6d..78234ee16784 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 0cd47fe0dbe5..117e6d16c3a1 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 a677b59efd74..c3af16d31a75 100644
133 @@ -768,6 +768,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 ff3c5e6f87cf..5c18a9e51f37 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 de2ede048473..5dcf77b8e1b2 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 b54e0541ad89..28607828e96f 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 29d8e2cfed0e..5db265e7d35a 100644
222 --- a/include/linux/fs.h
223 +++ b/include/linux/fs.h
224 @@ -1310,6 +1310,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 @@ -1803,6 +1804,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 @@ -1873,6 +1875,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 @@ -2298,6 +2306,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 @@ -2585,6 +2594,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 c5335df2372f..4e48a5059536 100644
271 --- a/include/linux/lockdep.h
272 +++ b/include/linux/lockdep.h
273 @@ -306,6 +306,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 @@ -432,6 +434,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 35942084cd40..24f5fd1a789d 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 74b4911ac16d..19789fbea567 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 95932333a48b..516ab7da26fb 100644
326 --- a/kernel/locking/lockdep.c
327 +++ b/kernel/locking/lockdep.c
328 @@ -143,7 +143,7 @@ static
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 @@ -154,6 +154,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 633a63462573..cb290f06bd7e 100644
352 @@ -2018,7 +2018,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 3b63be64e436..fb9913bf3d10 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 f0ec9edab2f3..35e9e2a9cc15 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 @@ -1734,7 +1737,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 0b63d68dedb2..400d1c594ceb 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 80bb6408fe73..59a1ea611ba7 100644
420 --- a/include/linux/mm.h
421 +++ b/include/linux/mm.h
422 @@ -1518,6 +1518,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 2c471a2c43fa..c6e7aa6996ff 100644
453 --- a/include/linux/mm_types.h
454 +++ b/include/linux/mm_types.h
455 @@ -244,6 +244,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 @@ -318,6 +319,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 b69248e6f0e0..099b89978dd3 100644
475 @@ -547,7 +547,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 d210cc9d6f80..e77e80ce7298 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 9f5e323e883e..90db684a7cf4 100644
501 @@ -2677,7 +2677,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 f901065c4c64..1089a8328a53 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 @@ -2676,7 +2676,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 @@ -2695,7 +2695,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 @@ -2885,7 +2885,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 @@ -2960,10 +2960,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 @@ -3253,7 +3270,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 749276beb109..d56f8f2bbd24 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 000000000000..024cdcfae1b1
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-2019 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 fc18967c2522..50eb587c1253 100644
746 @@ -1352,6 +1352,7 @@ void d_walk(struct dentry *parent, void *data,
750 +EXPORT_SYMBOL_GPL(d_walk);
753 struct vfsmount *mnt;
754 @@ -2845,6 +2846,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 fb72d36f7823..7ce68004cbf8 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 78234ee16784..2072f690b121 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 5679e7fcb6b0..961eec3df1eb 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 117e6d16c3a1..63a31af2f9d8 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 c3af16d31a75..f9fc947a6600 100644
830 @@ -434,6 +434,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 @@ -773,6 +774,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 @@ -1842,6 +1844,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 c03b83662876..817f22c6e191 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 d2dd16cb5989..cf709b7d611a 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 0285ce7dbd51..cb81623a8b09 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 5c18a9e51f37..542e59cd8d27 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 5dcf77b8e1b2..63fe2652c67d 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 28607828e96f..ffd7ea43831e 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 0d6a6a4af861..7ce4701b7289 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 516ab7da26fb..c4f72e461d28 100644
1020 --- a/kernel/locking/lockdep.c
1021 +++ b/kernel/locking/lockdep.c
1022 @@ -154,6 +154,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 0fef395662a6..83fb1ecfc33d 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 232db019f051..a402a5b72bf4 100644
1041 --- a/security/commoncap.c
1042 +++ b/security/commoncap.c
1043 @@ -1332,12 +1332,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 cd97929fac66..424fd230866d 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 55bc49027ba9..870eaa8ebedc 100644
1077 --- a/security/security.c
1078 +++ b/security/security.c
1079 @@ -566,6 +566,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 @@ -582,6 +583,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 @@ -590,6 +592,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 @@ -617,6 +620,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 @@ -624,6 +628,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 @@ -631,6 +636,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 @@ -716,6 +722,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 @@ -731,6 +738,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 @@ -902,6 +910,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 @@ -961,6 +970,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 2019-03-05 12:13:00.132557473 +0100
1258 +# Copyright (C) 2005-2019 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 2019-03-05 12:13:00.132557473 +0100
1433 +# Copyright (C) 2005-2019 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 2019-03-05 12:13:00.132557473 +0100
1695 +# Copyright (C) 2015-2019 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 2019-03-05 12:13:00.132557473 +0100
1784 +# Copyright (C) 2005-2019 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 2019-03-05 12:13:00.132557473 +0100
1901 +# Copyright (C) 2005-2019 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 2019-03-05 12:13:00.132557473 +0100
1979 +# Copyright (C) 2005-2019 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 2019-03-05 12:13:00.132557473 +0100
2082 +# Copyright (C) 2017-2019 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 2019-03-05 12:13:00.132557473 +0100
2188 +# Copyright (C) 2011-2019 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 2019-03-05 12:13:00.132557473 +0100
2312 +# Copyright (C) 2005-2019 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 2019-03-05 12:13:00.132557473 +0100
2388 +# Copyright (C) 2014-2019 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 2019-03-05 12:13:00.132557473 +0100
2488 +# Copyright (C) 2005-2019 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 2019-03-05 12:13:00.135890907 +0100
2550 +# Copyright (C) 2005-2019 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 2019-03-05 12:13:00.135890907 +0100
2606 +# Copyright (C) 2010-2019 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 2019-03-05 12:13:00.135890907 +0100
3055 +/* SPDX-License-Identifier: GPL-2.0 */
3057 + * Copyright (C) 2005-2019 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 2019-03-05 12:13:00.135890907 +0100
3121 +// SPDX-License-Identifier: GPL-2.0
3123 + * Copyright (C) 2005-2019 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 + /* VERIFY_WRITE */
4251 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4252 + if (unlikely(err)) {
4259 + si_read_lock(sb, AuLock_FLUSH);
4260 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4264 + ibusy.h_ino = 0; /* invalid */
4265 + inode = ilookup(sb, ibusy.ino);
4267 + || inode->i_ino == AUFS_ROOT_INO
4268 + || au_is_bad_inode(inode))
4271 + ii_read_lock_child(inode);
4272 + btop = au_ibtop(inode);
4273 + bbot = au_ibbot(inode);
4274 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4275 + h_inode = au_h_iptr(inode, ibusy.bindex);
4276 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4277 + ibusy.h_ino = h_inode->i_ino;
4279 + ii_read_unlock(inode);
4283 + si_read_unlock(sb);
4285 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4286 + if (unlikely(err)) {
4295 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4297 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4300 +#ifdef CONFIG_COMPAT
4301 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4303 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4307 +/* ---------------------------------------------------------------------- */
4310 + * change a branch permission
4313 +static void au_warn_ima(void)
4316 + /* since it doesn't support mark_files_ro() */
4317 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4321 +static int do_need_sigen_inc(int a, int b)
4323 + return au_br_whable(a) && !au_br_whable(b);
4326 +static int need_sigen_inc(int old, int new)
4328 + return do_need_sigen_inc(old, new)
4329 + || do_need_sigen_inc(new, old);
4332 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4335 + unsigned int mnt_flags;
4336 + unsigned long long ull, max;
4337 + aufs_bindex_t br_id;
4338 + unsigned char verbose, writer;
4339 + struct file *file, *hf, **array;
4340 + struct au_hfile *hfile;
4342 + mnt_flags = au_mntflags(sb);
4343 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4345 + array = au_farray_alloc(sb, &max);
4346 + err = PTR_ERR(array);
4347 + if (IS_ERR(array))
4351 + br_id = au_sbr_id(sb, bindex);
4352 + for (ull = 0; ull < max; ull++) {
4353 + file = array[ull];
4354 + if (unlikely(!file))
4357 + /* AuDbg("%pD\n", file); */
4358 + fi_read_lock(file);
4359 + if (unlikely(au_test_mmapped(file))) {
4361 + AuVerbose(verbose, "mmapped %pD\n", file);
4363 + FiMustNoWaiters(file);
4364 + fi_read_unlock(file);
4368 + hfile = &au_fi(file)->fi_htop;
4369 + hf = hfile->hf_file;
4370 + if (!d_is_reg(file->f_path.dentry)
4371 + || !(file->f_mode & FMODE_WRITE)
4372 + || hfile->hf_br->br_id != br_id
4373 + || !(hf->f_mode & FMODE_WRITE))
4374 + array[ull] = NULL;
4380 + FiMustNoWaiters(file);
4381 + fi_read_unlock(file);
4389 + for (ull = 0; ull < max; ull++) {
4390 + file = array[ull];
4394 + /* todo: already flushed? */
4396 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4397 + * approach which resets f_mode and calls mnt_drop_write() and
4398 + * file_release_write() for each file, because the branch
4399 + * attribute in aufs world is totally different from the native
4402 + /* fi_read_lock(file); */
4403 + hfile = &au_fi(file)->fi_htop;
4404 + hf = hfile->hf_file;
4405 + /* fi_read_unlock(file); */
4406 + spin_lock(&hf->f_lock);
4407 + writer = !!(hf->f_mode & FMODE_WRITER);
4408 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4409 + spin_unlock(&hf->f_lock);
4411 + put_write_access(file_inode(hf));
4412 + __mnt_drop_write(hf->f_path.mnt);
4417 + au_farray_free(array, max);
4423 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4427 + aufs_bindex_t bindex;
4428 + struct dentry *root;
4429 + struct au_branch *br;
4430 + struct au_br_fhsm *bf;
4432 + root = sb->s_root;
4433 + bindex = au_find_dbindex(root, mod->h_root);
4436 + return 0; /* success */
4438 + pr_err("%s no such branch\n", mod->path);
4441 + AuDbg("bindex b%d\n", bindex);
4443 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4444 + if (unlikely(err))
4447 + br = au_sbr(sb, bindex);
4448 + AuDebugOn(mod->h_root != au_br_dentry(br));
4449 + if (br->br_perm == mod->perm)
4450 + return 0; /* success */
4452 + /* pre-allocate for non-fhsm --> fhsm */
4454 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4455 + err = au_fhsm_br_alloc(br);
4456 + if (unlikely(err))
4459 + br->br_fhsm = NULL;
4462 + if (au_br_writable(br->br_perm)) {
4463 + /* remove whiteout base */
4464 + err = au_br_init_wh(sb, br, mod->perm);
4465 + if (unlikely(err))
4468 + if (!au_br_writable(mod->perm)) {
4469 + /* rw --> ro, file might be mmapped */
4470 + DiMustNoWaiters(root);
4471 + IiMustNoWaiters(d_inode(root));
4472 + di_write_unlock(root);
4473 + err = au_br_mod_files_ro(sb, bindex);
4474 + /* aufs_write_lock() calls ..._child() */
4475 + di_write_lock_child(root);
4477 + if (unlikely(err)) {
4479 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4482 + rerr = au_wbr_init(br, sb, br->br_perm);
4483 + if (unlikely(rerr)) {
4484 + AuIOErr("nested error %d (%d)\n",
4486 + br->br_perm = mod->perm;
4490 + } else if (au_br_writable(mod->perm)) {
4493 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4495 + err = au_wbr_init(br, sb, mod->perm);
4496 + if (unlikely(err)) {
4497 + au_kfree_rcu(br->br_wbr);
4498 + br->br_wbr = NULL;
4502 + if (unlikely(err))
4505 + if (au_br_fhsm(br->br_perm)) {
4506 + if (!au_br_fhsm(mod->perm)) {
4507 + /* fhsm --> non-fhsm */
4508 + au_br_fhsm_fin(br->br_fhsm);
4509 + au_kfree_rcu(br->br_fhsm);
4510 + br->br_fhsm = NULL;
4512 + } else if (au_br_fhsm(mod->perm))
4513 + /* non-fhsm --> fhsm */
4516 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4517 + br->br_perm = mod->perm;
4518 + goto out; /* success */
4521 + au_kfree_try_rcu(bf);
4527 +/* ---------------------------------------------------------------------- */
4529 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4532 + struct kstatfs kstfs;
4534 + err = vfs_statfs(&br->br_path, &kstfs);
4536 + stfs->f_blocks = kstfs.f_blocks;
4537 + stfs->f_bavail = kstfs.f_bavail;
4538 + stfs->f_files = kstfs.f_files;
4539 + stfs->f_ffree = kstfs.f_ffree;
4544 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4545 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4546 +++ linux/fs/aufs/branch.h 2019-03-05 12:13:00.135890907 +0100
4548 +/* SPDX-License-Identifier: GPL-2.0 */
4550 + * Copyright (C) 2005-2019 Junjiro R. Okajima
4552 + * This program, aufs is free software; you can redistribute it and/or modify
4553 + * it under the terms of the GNU General Public License as published by
4554 + * the Free Software Foundation; either version 2 of the License, or
4555 + * (at your option) any later version.
4557 + * This program is distributed in the hope that it will be useful,
4558 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4559 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4560 + * GNU General Public License for more details.
4562 + * You should have received a copy of the GNU General Public License
4563 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4567 + * branch filesystems and xino for them
4570 +#ifndef __AUFS_BRANCH_H__
4571 +#define __AUFS_BRANCH_H__
4575 +#include <linux/mount.h>
4576 +#include "dirren.h"
4582 +/* ---------------------------------------------------------------------- */
4586 + struct file **xi_file;
4587 + unsigned int xi_nfile;
4593 + /* reserved for future use */
4594 + /* unsigned long *bitmap; */
4595 + wait_queue_head_t wqh;
4598 + struct mutex xi_mtx; /* protects xi_file array */
4599 + struct hlist_bl_head xi_writing;
4601 + atomic_t xi_truncating;
4603 + struct kref xi_kref;
4606 +/* File-based Hierarchical Storage Management */
4607 +struct au_br_fhsm {
4608 +#ifdef CONFIG_AUFS_FHSM
4609 + struct mutex bf_lock;
4610 + unsigned long bf_jiffy;
4611 + struct aufs_stfs bf_stfs;
4616 +/* members for writable branch only */
4617 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4619 + struct au_rwsem wbr_wh_rwsem;
4620 + struct dentry *wbr_wh[AuBrWh_Last];
4621 + atomic_t wbr_wh_running;
4622 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4623 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4624 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4627 + unsigned long long wbr_bytes;
4630 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4631 +#define AuBrDynOp (AuDyLast * 4)
4633 +#ifdef CONFIG_AUFS_HFSNOTIFY
4634 +/* support for asynchronous destruction */
4635 +struct au_br_hfsnotify {
4636 + struct fsnotify_group *hfsn_group;
4640 +/* sysfs entries */
4641 +struct au_brsysfs {
4643 + struct attribute attr;
4652 +/* protected by superblock rwsem */
4654 + struct au_xino *br_xino;
4656 + aufs_bindex_t br_id;
4659 + struct path br_path;
4660 + spinlock_t br_dykey_lock;
4661 + struct au_dykey *br_dykey[AuBrDynOp];
4662 + au_lcnt_t br_nfiles; /* opened files */
4663 + au_lcnt_t br_count; /* in-use for other */
4665 + struct au_wbr *br_wbr;
4666 + struct au_br_fhsm *br_fhsm;
4668 +#ifdef CONFIG_AUFS_HFSNOTIFY
4669 + struct au_br_hfsnotify *br_hfsn;
4672 +#ifdef CONFIG_SYSFS
4673 + /* entries under sysfs per mount-point */
4674 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4677 +#ifdef CONFIG_DEBUG_FS
4678 + struct dentry *br_dbgaufs; /* xino */
4681 + struct au_dr_br br_dirren;
4684 +/* ---------------------------------------------------------------------- */
4686 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4688 + return br->br_path.mnt;
4691 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4693 + return br->br_path.dentry;
4696 +static inline struct super_block *au_br_sb(struct au_branch *br)
4698 + return au_br_mnt(br)->mnt_sb;
4701 +static inline int au_br_rdonly(struct au_branch *br)
4703 + return (sb_rdonly(au_br_sb(br))
4704 + || !au_br_writable(br->br_perm))
4708 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4710 +#ifdef CONFIG_AUFS_HNOTIFY
4711 + return !(brperm & AuBrPerm_RR);
4717 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4719 + int err, exec_flag;
4722 + exec_flag = oflag & __FMODE_EXEC;
4723 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4729 +static inline void au_xino_get(struct au_branch *br)
4731 + struct au_xino *xi;
4735 + kref_get(&xi->xi_kref);
4738 +static inline int au_xino_count(struct au_branch *br)
4741 + struct au_xino *xi;
4746 + v = kref_read(&xi->xi_kref);
4751 +/* ---------------------------------------------------------------------- */
4755 +void au_br_free(struct au_sbinfo *sinfo);
4756 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4758 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4760 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4761 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4762 +#ifdef CONFIG_COMPAT
4763 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4766 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4769 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4772 +static const loff_t au_loff_max = LLONG_MAX;
4774 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4775 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent);
4776 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4777 + struct file *copy_src);
4779 + struct au_xino *xi; /* switch between xino and xigen */
4781 + struct path *base;
4782 + struct file *copy_src;
4784 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4786 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4788 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4790 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4792 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4793 + size_t size, loff_t *pos);
4795 +int au_xib_trunc(struct super_block *sb);
4796 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4798 +struct au_xino *au_xino_alloc(unsigned int nfile);
4799 +int au_xino_put(struct au_branch *br);
4800 +struct file *au_xino_file1(struct au_xino *xi);
4802 +struct au_opt_xino;
4803 +void au_xino_clr(struct super_block *sb);
4804 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4805 +struct file *au_xino_def(struct super_block *sb);
4806 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4807 + struct path *base);
4809 +ino_t au_xino_new_ino(struct super_block *sb);
4810 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4812 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4813 + ino_t h_ino, int idx);
4814 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4817 +int au_xino_path(struct seq_file *seq, struct file *file);
4819 +/* ---------------------------------------------------------------------- */
4821 +/* @idx is signed to accept -1 meaning the first file */
4822 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4824 + struct file *file;
4831 + if (idx < xi->xi_nfile)
4832 + file = xi->xi_file[idx];
4834 + file = au_xino_file1(xi);
4840 +/* ---------------------------------------------------------------------- */
4842 +/* Superblock to branch */
4844 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4846 + return au_sbr(sb, bindex)->br_id;
4850 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4852 + return au_br_mnt(au_sbr(sb, bindex));
4856 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4858 + return au_br_sb(au_sbr(sb, bindex));
4861 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4863 + return au_sbr(sb, bindex)->br_perm;
4866 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4868 + return au_br_whable(au_sbr_perm(sb, bindex));
4871 +/* ---------------------------------------------------------------------- */
4873 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4874 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4875 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4876 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4878 +#define wbr_wh_read_trylock_nested(wbr) \
4879 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4880 +#define wbr_wh_write_trylock_nested(wbr) \
4881 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4884 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4885 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4886 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4888 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4889 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4890 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4892 +/* ---------------------------------------------------------------------- */
4894 +#ifdef CONFIG_AUFS_FHSM
4895 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4897 + mutex_init(&brfhsm->bf_lock);
4898 + brfhsm->bf_jiffy = 0;
4899 + brfhsm->bf_readable = 0;
4902 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4904 + mutex_destroy(&brfhsm->bf_lock);
4907 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4908 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4911 +#endif /* __KERNEL__ */
4912 +#endif /* __AUFS_BRANCH_H__ */
4913 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4914 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4915 +++ linux/fs/aufs/conf.mk 2018-06-04 09:08:09.181412645 +0200
4917 +# SPDX-License-Identifier: GPL-2.0
4919 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4923 +AuConfStr += ${1}=${${1}}
4927 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4929 + HNOTIFY HFSNOTIFY \
4941 +$(foreach i, ${AuConfAll}, \
4942 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4944 +AuConfName = ${obj}/conf.str
4945 +${AuConfName}.tmp: FORCE
4946 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4947 +${AuConfName}: ${AuConfName}.tmp
4948 + @diff -q $< $@ > /dev/null 2>&1 || { \
4949 + echo ' GEN ' $@; \
4953 +clean-files += ${AuConfName} ${AuConfName}.tmp
4954 +${obj}/sysfs.o: ${AuConfName}
4956 +-include ${srctree}/${src}/conf_priv.mk
4957 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4958 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4959 +++ linux/fs/aufs/cpup.c 2019-03-05 12:13:00.135890907 +0100
4961 +// SPDX-License-Identifier: GPL-2.0
4963 + * Copyright (C) 2005-2019 Junjiro R. Okajima
4965 + * This program, aufs is free software; you can redistribute it and/or modify
4966 + * it under the terms of the GNU General Public License as published by
4967 + * the Free Software Foundation; either version 2 of the License, or
4968 + * (at your option) any later version.
4970 + * This program is distributed in the hope that it will be useful,
4971 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4972 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4973 + * GNU General Public License for more details.
4975 + * You should have received a copy of the GNU General Public License
4976 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4980 + * copy-up functions, see wbr_policy.c for copy-down
4983 +#include <linux/fs_stack.h>
4984 +#include <linux/mm.h>
4985 +#include <linux/task_work.h>
4988 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4990 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4991 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4993 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4995 + dst->i_flags |= iflags & ~mask;
4996 + if (au_test_fs_notime(dst->i_sb))
4997 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
5000 +void au_cpup_attr_timesizes(struct inode *inode)
5002 + struct inode *h_inode;
5004 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5005 + fsstack_copy_attr_times(inode, h_inode);
5006 + fsstack_copy_inode_size(inode, h_inode);
5009 +void au_cpup_attr_nlink(struct inode *inode, int force)
5011 + struct inode *h_inode;
5012 + struct super_block *sb;
5013 + aufs_bindex_t bindex, bbot;
5016 + bindex = au_ibtop(inode);
5017 + h_inode = au_h_iptr(inode, bindex);
5019 + && !S_ISDIR(h_inode->i_mode)
5020 + && au_opt_test(au_mntflags(sb), PLINK)
5021 + && au_plink_test(inode))
5025 + * 0 can happen in revalidating.
5026 + * h_inode->i_mutex may not be held here, but it is harmless since once
5027 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
5029 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
5030 + * the incorrect link count.
5032 + set_nlink(inode, h_inode->i_nlink);
5035 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
5036 + * it may includes whplink directory.
5038 + if (S_ISDIR(h_inode->i_mode)) {
5039 + bbot = au_ibbot(inode);
5040 + for (bindex++; bindex <= bbot; bindex++) {
5041 + h_inode = au_h_iptr(inode, bindex);
5043 + au_add_nlink(inode, h_inode);
5048 +void au_cpup_attr_changeable(struct inode *inode)
5050 + struct inode *h_inode;
5052 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5053 + inode->i_mode = h_inode->i_mode;
5054 + inode->i_uid = h_inode->i_uid;
5055 + inode->i_gid = h_inode->i_gid;
5056 + au_cpup_attr_timesizes(inode);
5057 + au_cpup_attr_flags(inode, h_inode->i_flags);
5060 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
5062 + struct au_iinfo *iinfo = au_ii(inode);
5064 + IiMustWriteLock(inode);
5066 + iinfo->ii_higen = h_inode->i_generation;
5067 + iinfo->ii_hsb1 = h_inode->i_sb;
5070 +void au_cpup_attr_all(struct inode *inode, int force)
5072 + struct inode *h_inode;
5074 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5075 + au_cpup_attr_changeable(inode);
5076 + if (inode->i_nlink > 0)
5077 + au_cpup_attr_nlink(inode, force);
5078 + inode->i_rdev = h_inode->i_rdev;
5079 + inode->i_blkbits = h_inode->i_blkbits;
5080 + au_cpup_igen(inode, h_inode);
5083 +/* ---------------------------------------------------------------------- */
5085 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
5087 +/* keep the timestamps of the parent dir when cpup */
5088 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5089 + struct path *h_path)
5091 + struct inode *h_inode;
5093 + dt->dt_dentry = dentry;
5094 + dt->dt_h_path = *h_path;
5095 + h_inode = d_inode(h_path->dentry);
5096 + dt->dt_atime = h_inode->i_atime;
5097 + dt->dt_mtime = h_inode->i_mtime;
5101 +void au_dtime_revert(struct au_dtime *dt)
5103 + struct iattr attr;
5106 + attr.ia_atime = dt->dt_atime;
5107 + attr.ia_mtime = dt->dt_mtime;
5108 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
5109 + | ATTR_ATIME | ATTR_ATIME_SET;
5111 + /* no delegation since this is a directory */
5112 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
5113 + if (unlikely(err))
5114 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
5117 +/* ---------------------------------------------------------------------- */
5119 +/* internal use only */
5120 +struct au_cpup_reg_attr {
5123 + unsigned int iflags; /* inode->i_flags */
5126 +static noinline_for_stack
5127 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
5128 + struct au_cpup_reg_attr *h_src_attr)
5130 + int err, sbits, icex;
5131 + unsigned int mnt_flags;
5132 + unsigned char verbose;
5134 + struct path h_path;
5135 + struct inode *h_isrc, *h_idst;
5136 + struct kstat *h_st;
5137 + struct au_branch *br;
5139 + h_path.dentry = au_h_dptr(dst, bindex);
5140 + h_idst = d_inode(h_path.dentry);
5141 + br = au_sbr(dst->d_sb, bindex);
5142 + h_path.mnt = au_br_mnt(br);
5143 + h_isrc = d_inode(h_src);
5144 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
5145 + | ATTR_ATIME | ATTR_MTIME
5146 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
5147 + if (h_src_attr && h_src_attr->valid) {
5148 + h_st = &h_src_attr->st;
5149 + ia.ia_uid = h_st->uid;
5150 + ia.ia_gid = h_st->gid;
5151 + ia.ia_atime = h_st->atime;
5152 + ia.ia_mtime = h_st->mtime;
5153 + if (h_idst->i_mode != h_st->mode
5154 + && !S_ISLNK(h_idst->i_mode)) {
5155 + ia.ia_valid |= ATTR_MODE;
5156 + ia.ia_mode = h_st->mode;
5158 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
5159 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
5161 + ia.ia_uid = h_isrc->i_uid;
5162 + ia.ia_gid = h_isrc->i_gid;
5163 + ia.ia_atime = h_isrc->i_atime;
5164 + ia.ia_mtime = h_isrc->i_mtime;
5165 + if (h_idst->i_mode != h_isrc->i_mode
5166 + && !S_ISLNK(h_idst->i_mode)) {
5167 + ia.ia_valid |= ATTR_MODE;
5168 + ia.ia_mode = h_isrc->i_mode;
5170 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5171 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5173 + /* no delegation since it is just created */
5174 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5176 + /* is this nfs only? */
5177 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5178 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5179 + ia.ia_mode = h_isrc->i_mode;
5180 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5183 + icex = br->br_perm & AuBrAttr_ICEX;
5185 + mnt_flags = au_mntflags(dst->d_sb);
5186 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5187 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5193 +/* ---------------------------------------------------------------------- */
5195 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5196 + char *buf, unsigned long blksize)
5199 + size_t sz, rbytes, wbytes;
5200 + unsigned char all_zero;
5202 + struct inode *h_inode;
5203 + /* reduce stack usage */
5206 + zp = page_address(ZERO_PAGE(0));
5207 + if (unlikely(!zp))
5208 + return -ENOMEM; /* possible? */
5213 + AuDbg("len %lld\n", len);
5215 + if (len < blksize)
5219 + /* todo: signal_pending? */
5220 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5221 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5224 + if (unlikely(err < 0))
5228 + if (len >= rbytes && rbytes == blksize)
5229 + all_zero = !memcmp(buf, zp, rbytes);
5236 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5238 + /* todo: signal_pending? */
5239 + if (unlikely(err == -EAGAIN || err == -EINTR))
5241 + if (unlikely(err < 0))
5246 + if (unlikely(err < 0))
5252 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5254 + if (unlikely(res < 0))
5261 + /* the last block may be a hole */
5262 + if (!err && all_zero) {
5263 + AuLabel(last hole);
5266 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5267 + /* nfs requires this step to make last hole */
5268 + /* is this only nfs? */
5270 + /* todo: signal_pending? */
5271 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5272 + } while (err == -EAGAIN || err == -EINTR);
5279 + ia->ia_size = dst->f_pos;
5280 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5281 + ia->ia_file = dst;
5282 + h_inode = file_inode(dst);
5283 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5284 + /* no delegation since it is just created */
5285 + err = vfsub_notify_change(&dst->f_path, ia,
5286 + /*delegated*/NULL);
5287 + inode_unlock(h_inode);
5294 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5297 + unsigned long blksize;
5298 + unsigned char do_kfree;
5300 + struct super_block *h_sb;
5303 + h_sb = file_inode(dst)->i_sb;
5304 + blksize = h_sb->s_blocksize;
5305 + if (!blksize || PAGE_SIZE < blksize)
5306 + blksize = PAGE_SIZE;
5307 + AuDbg("blksize %lu\n", blksize);
5308 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5310 + buf = kmalloc(blksize, GFP_NOFS);
5312 + buf = (void *)__get_free_page(GFP_NOFS);
5313 + if (unlikely(!buf))
5316 + if (len > (1 << 22))
5317 + AuDbg("copying a large file %lld\n", (long long)len);
5321 + err = au_do_copy_file(dst, src, len, buf, blksize);
5323 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5324 + au_kfree_do_rcu(buf);
5326 + free_page((unsigned long)buf);
5332 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5335 + struct super_block *h_src_sb;
5336 + struct inode *h_src_inode;
5338 + h_src_inode = file_inode(src);
5339 + h_src_sb = h_src_inode->i_sb;
5341 + /* XFS acquires inode_lock */
5342 + if (!au_test_xfs(h_src_sb))
5343 + err = au_copy_file(dst, src, len);
5345 + inode_unlock_shared(h_src_inode);
5346 + err = au_copy_file(dst, src, len);
5347 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5353 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5357 + struct super_block *h_src_sb;
5358 + struct inode *h_src_inode;
5360 + h_src_inode = file_inode(src);
5361 + h_src_sb = h_src_inode->i_sb;
5362 + if (h_src_sb != file_inode(dst)->i_sb
5363 + || !dst->f_op->remap_file_range) {
5364 + err = au_do_copy(dst, src, len);
5368 + if (!au_test_nfs(h_src_sb)) {
5369 + inode_unlock_shared(h_src_inode);
5370 + lo = vfsub_clone_file_range(src, dst, len);
5371 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5373 + lo = vfsub_clone_file_range(src, dst, len);
5376 + goto out; /* success */
5377 + } else if (lo >= 0)
5378 + /* todo: possible? */
5379 + /* paritially succeeded */
5380 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5381 + else if (lo != -EOPNOTSUPP) {
5382 + /* older XFS has a condition in cloning */
5387 + /* the backend fs on NFS may not support cloning */
5388 + err = au_do_copy(dst, src, len);
5396 + * to support a sparse file which is opened with O_APPEND,
5397 + * we need to close the file.
5399 +static int au_cp_regular(struct au_cp_generic *cpg)
5402 + enum { SRC, DST };
5404 + aufs_bindex_t bindex;
5405 + unsigned int flags;
5406 + struct dentry *dentry;
5408 + struct file *file;
5411 + .bindex = cpg->bsrc,
5412 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5415 + .bindex = cpg->bdst,
5416 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5417 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5420 + struct au_branch *br;
5421 + struct super_block *sb, *h_src_sb;
5422 + struct inode *h_src_inode;
5423 + struct task_struct *tsk = current;
5425 + /* bsrc branch can be ro/rw. */
5426 + sb = cpg->dentry->d_sb;
5428 + for (i = 0; i < 2; i++, f++) {
5429 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5430 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5431 + /*file*/NULL, f->force_wr);
5432 + if (IS_ERR(f->file)) {
5433 + err = PTR_ERR(f->file);
5441 + /* try stopping to update while we copyup */
5442 + h_src_inode = d_inode(file[SRC].dentry);
5443 + h_src_sb = h_src_inode->i_sb;
5444 + if (!au_test_nfs(h_src_sb))
5445 + IMustLock(h_src_inode);
5446 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5448 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5449 + if (tsk->flags & PF_KTHREAD)
5450 + __fput_sync(file[DST].file);
5452 + /* it happened actually */
5453 + fput(file[DST].file);
5456 + * we have to call both since we don't know which place the file
5460 + flush_delayed_fput();
5462 + br = au_sbr(sb, file[DST].bindex);
5463 + au_lcnt_dec(&br->br_nfiles);
5466 + fput(file[SRC].file);
5467 + br = au_sbr(sb, file[SRC].bindex);
5468 + au_lcnt_dec(&br->br_nfiles);
5473 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5474 + struct au_cpup_reg_attr *h_src_attr)
5478 + struct path h_path;
5479 + struct inode *h_src_inode, *h_dst_inode;
5482 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5483 + l = i_size_read(h_src_inode);
5484 + if (cpg->len == -1 || l < cpg->len)
5487 + /* try stopping to update while we are referencing */
5488 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5489 + au_pin_hdir_unlock(cpg->pin);
5491 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5492 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5493 + h_src_attr->iflags = h_src_inode->i_flags;
5494 + if (!au_test_nfs(h_src_inode->i_sb))
5495 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5497 + inode_unlock_shared(h_src_inode);
5498 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5499 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5501 + if (unlikely(err)) {
5502 + inode_unlock_shared(h_src_inode);
5505 + h_src_attr->valid = 1;
5506 + if (!au_test_nfs(h_src_inode->i_sb)) {
5507 + err = au_cp_regular(cpg);
5508 + inode_unlock_shared(h_src_inode);
5510 + inode_unlock_shared(h_src_inode);
5511 + err = au_cp_regular(cpg);
5513 + rerr = au_pin_hdir_relock(cpg->pin);
5517 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5518 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5519 + h_dst_inode = d_inode(h_path.dentry);
5520 + spin_lock(&h_dst_inode->i_lock);
5521 + h_dst_inode->i_state |= I_LINKABLE;
5522 + spin_unlock(&h_dst_inode->i_lock);
5529 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5530 + struct inode *h_dir)
5533 + mm_segment_t old_fs;
5540 + sym.k = (void *)__get_free_page(GFP_NOFS);
5541 + if (unlikely(!sym.k))
5544 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5545 + old_fs = get_fs();
5546 + set_fs(KERNEL_DS);
5547 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5552 + sym.k[symlen] = 0;
5553 + err = vfsub_symlink(h_dir, h_path, sym.k);
5555 + free_page((unsigned long)sym.k);
5562 + * regardless 'acl' option, reset all ACL.
5563 + * All ACL will be copied up later from the original entry on the lower branch.
5565 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5568 + struct dentry *h_dentry;
5569 + struct inode *h_inode;
5571 + h_dentry = h_path->dentry;
5572 + h_inode = d_inode(h_dentry);
5573 + /* forget_all_cached_acls(h_inode)); */
5574 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5576 + if (err == -EOPNOTSUPP)
5579 + err = vfsub_acl_chmod(h_inode, mode);
5585 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5586 + struct inode *h_dir, struct path *h_path)
5589 + struct inode *dir, *inode;
5591 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5593 + if (err == -EOPNOTSUPP)
5595 + if (unlikely(err))
5599 + * strange behaviour from the users view,
5600 + * particularly setattr case
5602 + dir = d_inode(dst_parent);
5603 + if (au_ibtop(dir) == cpg->bdst)
5604 + au_cpup_attr_nlink(dir, /*force*/1);
5605 + inode = d_inode(cpg->dentry);
5606 + au_cpup_attr_nlink(inode, /*force*/1);
5612 +static noinline_for_stack
5613 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5614 + struct au_cpup_reg_attr *h_src_attr)
5618 + unsigned int mnt_flags;
5619 + unsigned char isdir, isreg, force;
5620 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5621 + struct au_dtime dt;
5622 + struct path h_path;
5623 + struct dentry *h_src, *h_dst, *h_parent;
5624 + struct inode *h_inode, *h_dir;
5625 + struct super_block *sb;
5627 + /* bsrc branch can be ro/rw. */
5628 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5629 + h_inode = d_inode(h_src);
5630 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5632 + /* try stopping to be referenced while we are creating */
5633 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5634 + if (au_ftest_cpup(cpg->flags, RENAME))
5635 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5636 + AUFS_WH_PFX_LEN));
5637 + h_parent = h_dst->d_parent; /* dir inode is locked */
5638 + h_dir = d_inode(h_parent);
5640 + AuDebugOn(h_parent != h_dst->d_parent);
5642 + sb = cpg->dentry->d_sb;
5643 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5645 + h_path.dentry = h_parent;
5646 + au_dtime_store(&dt, dst_parent, &h_path);
5648 + h_path.dentry = h_dst;
5652 + mode = h_inode->i_mode;
5653 + switch (mode & S_IFMT) {
5656 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5658 + err = au_do_cpup_regular(cpg, h_src_attr);
5662 + err = vfsub_mkdir(h_dir, &h_path, mode);
5664 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5667 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5671 + AuDebugOn(!capable(CAP_MKNOD));
5675 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5678 + AuIOErr("Unknown inode type 0%o\n", mode);
5682 + err = au_reset_acl(h_dir, &h_path, mode);
5684 + mnt_flags = au_mntflags(sb);
5685 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5687 + && au_opt_test(mnt_flags, XINO)
5688 + && (h_inode->i_nlink == 1
5689 + || (h_inode->i_state & I_LINKABLE))
5690 + /* todo: unnecessary? */
5691 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5692 + && cpg->bdst < cpg->bsrc
5693 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5694 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5695 + /* ignore this error */
5700 + force = !!cpg->len;
5701 + if (cpg->len == -1)
5702 + force = !!i_size_read(h_inode);
5704 + au_fhsm_wrote(sb, cpg->bdst, force);
5708 + au_dtime_revert(&dt);
5712 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5715 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5716 + struct inode *h_dir;
5717 + aufs_bindex_t bdst;
5719 + dentry = cpg->dentry;
5721 + h_dentry = au_h_dptr(dentry, bdst);
5722 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5724 + au_set_h_dptr(dentry, bdst, NULL);
5725 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5727 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5728 + au_set_h_dptr(dentry, bdst, h_dentry);
5731 + parent = dget_parent(dentry);
5732 + h_parent = au_h_dptr(parent, bdst);
5734 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5735 + if (IS_ERR(h_path->dentry))
5736 + err = PTR_ERR(h_path->dentry);
5738 + if (unlikely(err))
5741 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5742 + h_dir = d_inode(h_parent);
5744 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5745 + /* no delegation since it is just created */
5746 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5748 + dput(h_path->dentry);
5755 + * copyup the @dentry from @bsrc to @bdst.
5756 + * the caller must set the both of lower dentries.
5757 + * @len is for truncating when it is -1 copyup the entire file.
5758 + * in link/rename cases, @dst_parent may be different from the real one.
5759 + * basic->bsrc can be larger than basic->bdst.
5760 + * aufs doesn't touch the credential so
5761 + * security_inode_copy_up{,_xattr}() are unnecessary.
5763 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5766 + aufs_bindex_t old_ibtop;
5767 + unsigned char isdir, plink;
5768 + struct dentry *h_src, *h_dst, *h_parent;
5769 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5770 + struct super_block *sb;
5771 + struct au_branch *br;
5772 + /* to reduce stack size */
5774 + struct au_dtime dt;
5775 + struct path h_path;
5776 + struct au_cpup_reg_attr h_src_attr;
5780 + a = kmalloc(sizeof(*a), GFP_NOFS);
5783 + a->h_src_attr.valid = 0;
5785 + sb = cpg->dentry->d_sb;
5786 + br = au_sbr(sb, cpg->bdst);
5787 + a->h_path.mnt = au_br_mnt(br);
5788 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5789 + h_parent = h_dst->d_parent; /* dir inode is locked */
5790 + h_dir = d_inode(h_parent);
5793 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5794 + inode = d_inode(cpg->dentry);
5797 + dst_parent = dget_parent(cpg->dentry);
5801 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5802 + dst_inode = au_h_iptr(inode, cpg->bdst);
5804 + if (unlikely(!plink)) {
5806 + AuIOErr("hi%lu(i%lu) exists on b%d "
5807 + "but plink is disabled\n",
5808 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5812 + if (dst_inode->i_nlink) {
5813 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5815 + h_src = au_plink_lkup(inode, cpg->bdst);
5816 + err = PTR_ERR(h_src);
5817 + if (IS_ERR(h_src))
5819 + if (unlikely(d_is_negative(h_src))) {
5821 + AuIOErr("i%lu exists on b%d "
5822 + "but not pseudo-linked\n",
5823 + inode->i_ino, cpg->bdst);
5829 + a->h_path.dentry = h_parent;
5830 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5833 + a->h_path.dentry = h_dst;
5835 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5836 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5837 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5839 + au_dtime_revert(&a->dt);
5840 + if (unlikely(err == -EWOULDBLOCK)) {
5841 + pr_warn("cannot retry for NFSv4 delegation"
5842 + " for an internal link\n");
5848 + /* todo: cpup_wh_file? */
5850 + au_update_ibrange(inode, /*do_put_zero*/1);
5853 + isdir = S_ISDIR(inode->i_mode);
5854 + old_ibtop = au_ibtop(inode);
5855 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5856 + if (unlikely(err))
5858 + dst_inode = d_inode(h_dst);
5859 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5860 + /* todo: necessary? */
5861 + /* au_pin_hdir_unlock(cpg->pin); */
5863 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5864 + if (unlikely(err)) {
5865 + /* todo: necessary? */
5866 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5867 + inode_unlock(dst_inode);
5871 + if (cpg->bdst < old_ibtop) {
5872 + if (S_ISREG(inode->i_mode)) {
5873 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5874 + if (unlikely(err)) {
5875 + /* ignore an error */
5876 + /* au_pin_hdir_relock(cpg->pin); */
5877 + inode_unlock(dst_inode);
5881 + au_set_ibtop(inode, cpg->bdst);
5883 + au_set_ibbot(inode, cpg->bdst);
5884 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5885 + au_hi_flags(inode, isdir));
5887 + /* todo: necessary? */
5888 + /* err = au_pin_hdir_relock(cpg->pin); */
5889 + inode_unlock(dst_inode);
5890 + if (unlikely(err))
5893 + src_inode = d_inode(h_src);
5895 + && (src_inode->i_nlink > 1
5896 + || src_inode->i_state & I_LINKABLE)
5898 + au_plink_append(inode, cpg->bdst, h_dst);
5900 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5901 + a->h_path.dentry = h_dst;
5902 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5905 + goto out_parent; /* success */
5909 + a->h_path.dentry = h_parent;
5910 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5911 + a->h_path.dentry = h_dst;
5913 + if (d_is_positive(h_dst)) {
5915 + /* no delegation since it is just created */
5916 + rerr = vfsub_unlink(h_dir, &a->h_path,
5917 + /*delegated*/NULL, /*force*/0);
5919 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5921 + au_dtime_revert(&a->dt);
5923 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5933 +#if 0 /* reserved */
5934 +struct au_cpup_single_args {
5936 + struct au_cp_generic *cpg;
5937 + struct dentry *dst_parent;
5940 +static void au_call_cpup_single(void *args)
5942 + struct au_cpup_single_args *a = args;
5944 + au_pin_hdir_acquire_nest(a->cpg->pin);
5945 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5946 + au_pin_hdir_release(a->cpg->pin);
5951 + * prevent SIGXFSZ in copy-up.
5952 + * testing CAP_MKNOD is for generic fs,
5953 + * but CAP_FSETID is for xfs only, currently.
5955 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5958 + struct super_block *sb;
5959 + struct inode *h_dir;
5962 + sb = au_pinned_parent(pin)->d_sb;
5963 + if (!au_wkq_test()
5964 + && (!au_sbi(sb)->si_plink_maint_pid
5965 + || au_plink_maint(sb, AuLock_NOPLM))) {
5966 + switch (mode & S_IFMT) {
5968 + /* no condition about RLIMIT_FSIZE and the file size */
5973 + do_sio = !capable(CAP_MKNOD);
5977 + do_sio = ((mode & (S_ISUID | S_ISGID))
5978 + && !capable(CAP_FSETID));
5979 + /* this workaround may be removed in the future */
5981 + h_dir = au_pinned_h_dir(pin);
5982 + do_sio = h_dir->i_mode & S_ISVTX;
5989 +#if 0 /* reserved */
5990 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5993 + struct dentry *h_dentry;
5995 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5996 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5997 + err = au_cpup_single(cpg, dst_parent);
5999 + struct au_cpup_single_args args = {
6002 + .dst_parent = dst_parent
6004 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
6005 + if (unlikely(wkq_err))
6014 + * copyup the @dentry from the first active lower branch to @bdst,
6015 + * using au_cpup_single().
6017 +static int au_cpup_simple(struct au_cp_generic *cpg)
6020 + unsigned int flags_orig;
6021 + struct dentry *dentry;
6023 + AuDebugOn(cpg->bsrc < 0);
6025 + dentry = cpg->dentry;
6026 + DiMustWriteLock(dentry);
6028 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
6030 + flags_orig = cpg->flags;
6031 + au_fset_cpup(cpg->flags, RENAME);
6032 + err = au_cpup_single(cpg, NULL);
6033 + cpg->flags = flags_orig;
6035 + return 0; /* success */
6038 + au_set_h_dptr(dentry, cpg->bdst, NULL);
6039 + au_set_dbtop(dentry, cpg->bsrc);
6045 +struct au_cpup_simple_args {
6047 + struct au_cp_generic *cpg;
6050 +static void au_call_cpup_simple(void *args)
6052 + struct au_cpup_simple_args *a = args;
6054 + au_pin_hdir_acquire_nest(a->cpg->pin);
6055 + *a->errp = au_cpup_simple(a->cpg);
6056 + au_pin_hdir_release(a->cpg->pin);
6059 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
6062 + struct dentry *dentry, *parent;
6063 + struct file *h_file;
6064 + struct inode *h_dir;
6066 + dentry = cpg->dentry;
6068 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
6069 + AuDebugOn(cpg->bsrc < 0);
6070 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
6071 + err = PTR_ERR(h_file);
6072 + if (IS_ERR(h_file))
6076 + parent = dget_parent(dentry);
6077 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
6078 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
6079 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6080 + err = au_cpup_simple(cpg);
6082 + struct au_cpup_simple_args args = {
6086 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
6087 + if (unlikely(wkq_err))
6093 + au_h_open_post(dentry, cpg->bsrc, h_file);
6099 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
6101 + aufs_bindex_t bsrc, bbot;
6102 + struct dentry *dentry, *h_dentry;
6104 + if (cpg->bsrc < 0) {
6105 + dentry = cpg->dentry;
6106 + bbot = au_dbbot(dentry);
6107 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
6108 + h_dentry = au_h_dptr(dentry, bsrc);
6110 + AuDebugOn(d_is_negative(h_dentry));
6114 + AuDebugOn(bsrc > bbot);
6117 + AuDebugOn(cpg->bsrc <= cpg->bdst);
6118 + return au_do_sio_cpup_simple(cpg);
6121 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
6123 + AuDebugOn(cpg->bdst <= cpg->bsrc);
6124 + return au_do_sio_cpup_simple(cpg);
6127 +/* ---------------------------------------------------------------------- */
6130 + * copyup the deleted file for writing.
6132 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
6133 + struct file *file)
6136 + unsigned int flags_orig;
6137 + aufs_bindex_t bsrc_orig;
6138 + struct au_dinfo *dinfo;
6140 + struct au_hdentry *hd;
6141 + struct dentry *h_dentry;
6144 + dinfo = au_di(cpg->dentry);
6145 + AuRwMustWriteLock(&dinfo->di_rwsem);
6147 + bsrc_orig = cpg->bsrc;
6148 + cpg->bsrc = dinfo->di_btop;
6149 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
6150 + hdst.h_dentry = hdst.hd->hd_dentry;
6151 + hdst.hd->hd_dentry = wh_dentry;
6152 + dinfo->di_btop = cpg->bdst;
6154 + hsrc.h_dentry = NULL;
6156 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
6157 + hsrc.h_dentry = hsrc.hd->hd_dentry;
6158 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
6160 + flags_orig = cpg->flags;
6161 + cpg->flags = !AuCpup_DTIME;
6162 + err = au_cpup_single(cpg, /*h_parent*/NULL);
6163 + cpg->flags = flags_orig;
6166 + err = au_reopen_nondir(file);
6167 + hsrc.hd->hd_dentry = hsrc.h_dentry;
6169 + hdst.hd->hd_dentry = hdst.h_dentry;
6170 + dinfo->di_btop = cpg->bsrc;
6171 + cpg->bsrc = bsrc_orig;
6176 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6179 + aufs_bindex_t bdst;
6180 + struct au_dtime dt;
6181 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6182 + struct au_branch *br;
6183 + struct path h_path;
6185 + dentry = cpg->dentry;
6187 + br = au_sbr(dentry->d_sb, bdst);
6188 + parent = dget_parent(dentry);
6189 + h_parent = au_h_dptr(parent, bdst);
6190 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6191 + err = PTR_ERR(wh_dentry);
6192 + if (IS_ERR(wh_dentry))
6195 + h_path.dentry = h_parent;
6196 + h_path.mnt = au_br_mnt(br);
6197 + au_dtime_store(&dt, parent, &h_path);
6198 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6199 + if (unlikely(err))
6203 + h_path.dentry = wh_dentry;
6204 + if (!d_is_dir(wh_dentry)) {
6205 + /* no delegation since it is just created */
6206 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6207 + /*delegated*/NULL, /*force*/0);
6209 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6210 + if (unlikely(err)) {
6211 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6215 + au_dtime_revert(&dt);
6216 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6225 +struct au_cpup_wh_args {
6227 + struct au_cp_generic *cpg;
6228 + struct file *file;
6231 +static void au_call_cpup_wh(void *args)
6233 + struct au_cpup_wh_args *a = args;
6235 + au_pin_hdir_acquire_nest(a->cpg->pin);
6236 + *a->errp = au_cpup_wh(a->cpg, a->file);
6237 + au_pin_hdir_release(a->cpg->pin);
6240 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6243 + aufs_bindex_t bdst;
6244 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6245 + struct inode *dir, *h_dir, *h_tmpdir;
6246 + struct au_wbr *wbr;
6247 + struct au_pin wh_pin, *pin_orig;
6249 + dentry = cpg->dentry;
6251 + parent = dget_parent(dentry);
6252 + dir = d_inode(parent);
6255 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6258 + if (!h_dir->i_nlink) {
6259 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6260 + h_orph = wbr->wbr_orph;
6262 + h_parent = dget(au_h_dptr(parent, bdst));
6263 + au_set_h_dptr(parent, bdst, dget(h_orph));
6264 + h_tmpdir = d_inode(h_orph);
6265 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6267 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6268 + /* todo: au_h_open_pre()? */
6270 + pin_orig = cpg->pin;
6271 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6272 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6273 + cpg->pin = &wh_pin;
6276 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6277 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6278 + err = au_cpup_wh(cpg, file);
6280 + struct au_cpup_wh_args args = {
6285 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6286 + if (unlikely(wkq_err))
6291 + inode_unlock(h_tmpdir);
6292 + /* todo: au_h_open_post()? */
6293 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6294 + au_set_h_dptr(parent, bdst, h_parent);
6295 + AuDebugOn(!pin_orig);
6296 + cpg->pin = pin_orig;
6304 +/* ---------------------------------------------------------------------- */
6307 + * generic routine for both of copy-up and copy-down.
6309 +/* cf. revalidate function in file.c */
6310 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6311 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6312 + struct au_pin *pin,
6313 + struct dentry *h_parent, void *arg),
6317 + struct au_pin pin;
6318 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6321 + parent = dget_parent(dentry);
6322 + if (IS_ROOT(parent))
6325 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6326 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6328 + /* do not use au_dpage */
6329 + real_parent = parent;
6332 + parent = dget_parent(dentry);
6333 + h_parent = au_h_dptr(parent, bdst);
6335 + goto out; /* success */
6337 + /* find top dir which is necessary to cpup */
6341 + parent = dget_parent(d);
6342 + di_read_lock_parent3(parent, !AuLock_IR);
6343 + h_parent = au_h_dptr(parent, bdst);
6344 + di_read_unlock(parent, !AuLock_IR);
6345 + } while (!h_parent);
6347 + if (d != real_parent)
6348 + di_write_lock_child3(d);
6350 + /* somebody else might create while we were sleeping */
6351 + h_dentry = au_h_dptr(d, bdst);
6352 + if (!h_dentry || d_is_negative(h_dentry)) {
6354 + au_update_dbtop(d);
6356 + au_pin_set_dentry(&pin, d);
6357 + err = au_do_pin(&pin);
6359 + err = cp(d, bdst, &pin, h_parent, arg);
6364 + if (d != real_parent)
6365 + di_write_unlock(d);
6366 + if (unlikely(err))
6375 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6376 + struct au_pin *pin,
6377 + struct dentry *h_parent __maybe_unused,
6378 + void *arg __maybe_unused)
6380 + struct au_cp_generic cpg = {
6386 + .flags = AuCpup_DTIME
6388 + return au_sio_cpup_simple(&cpg);
6391 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6393 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6396 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6399 + struct dentry *parent;
6400 + struct inode *dir;
6402 + parent = dget_parent(dentry);
6403 + dir = d_inode(parent);
6405 + if (au_h_iptr(dir, bdst))
6408 + di_read_unlock(parent, AuLock_IR);
6409 + di_write_lock_parent(parent);
6410 + /* someone else might change our inode while we were sleeping */
6411 + if (!au_h_iptr(dir, bdst))
6412 + err = au_cpup_dirs(dentry, bdst);
6413 + di_downgrade_lock(parent, AuLock_IR);
6419 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6420 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6421 +++ linux/fs/aufs/cpup.h 2019-03-05 12:13:00.135890907 +0100
6423 +/* SPDX-License-Identifier: GPL-2.0 */
6425 + * Copyright (C) 2005-2019 Junjiro R. Okajima
6427 + * This program, aufs is free software; you can redistribute it and/or modify
6428 + * it under the terms of the GNU General Public License as published by
6429 + * the Free Software Foundation; either version 2 of the License, or
6430 + * (at your option) any later version.
6432 + * This program is distributed in the hope that it will be useful,
6433 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6434 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6435 + * GNU General Public License for more details.
6437 + * You should have received a copy of the GNU General Public License
6438 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6442 + * copy-up/down functions
6445 +#ifndef __AUFS_CPUP_H__
6446 +#define __AUFS_CPUP_H__
6450 +#include <linux/path.h>
6456 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6457 +void au_cpup_attr_timesizes(struct inode *inode);
6458 +void au_cpup_attr_nlink(struct inode *inode, int force);
6459 +void au_cpup_attr_changeable(struct inode *inode);
6460 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6461 +void au_cpup_attr_all(struct inode *inode, int force);
6463 +/* ---------------------------------------------------------------------- */
6465 +struct au_cp_generic {
6466 + struct dentry *dentry;
6467 + aufs_bindex_t bdst, bsrc;
6469 + struct au_pin *pin;
6470 + unsigned int flags;
6474 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6475 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6477 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6478 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6480 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6482 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6483 + the branch is marked as RO */
6485 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6486 +#undef AuCpup_HOPEN
6487 +#define AuCpup_HOPEN 0
6490 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6491 +#define au_fset_cpup(flags, name) \
6492 + do { (flags) |= AuCpup_##name; } while (0)
6493 +#define au_fclr_cpup(flags, name) \
6494 + do { (flags) &= ~AuCpup_##name; } while (0)
6496 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6497 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6498 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6499 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6501 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6502 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6503 + struct au_pin *pin,
6504 + struct dentry *h_parent, void *arg),
6506 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6507 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6509 +/* ---------------------------------------------------------------------- */
6511 +/* keep timestamps when copyup */
6513 + struct dentry *dt_dentry;
6514 + struct path dt_h_path;
6515 + struct timespec64 dt_atime, dt_mtime;
6517 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6518 + struct path *h_path);
6519 +void au_dtime_revert(struct au_dtime *dt);
6521 +#endif /* __KERNEL__ */
6522 +#endif /* __AUFS_CPUP_H__ */
6523 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6524 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6525 +++ linux/fs/aufs/dbgaufs.c 2019-03-05 12:13:00.135890907 +0100
6527 +// SPDX-License-Identifier: GPL-2.0
6529 + * Copyright (C) 2005-2019 Junjiro R. Okajima
6531 + * This program, aufs is free software; you can redistribute it and/or modify
6532 + * it under the terms of the GNU General Public License as published by
6533 + * the Free Software Foundation; either version 2 of the License, or
6534 + * (at your option) any later version.
6536 + * This program is distributed in the hope that it will be useful,
6537 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6538 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6539 + * GNU General Public License for more details.
6541 + * You should have received a copy of the GNU General Public License
6542 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6546 + * debugfs interface
6549 +#include <linux/debugfs.h>
6552 +#ifndef CONFIG_SYSFS
6553 +#error DEBUG_FS depends upon SYSFS
6556 +static struct dentry *dbgaufs;
6557 +static const mode_t dbgaufs_mode = 0444;
6559 +/* 20 is max digits length of ulong 64 */
6560 +struct dbgaufs_arg {
6566 + * common function for all XINO files
6568 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6569 + struct file *file)
6573 + p = file->private_data;
6575 + /* this is struct dbgaufs_arg */
6576 + AuDebugOn(!au_kfree_sz_test(p));
6577 + au_kfree_do_rcu(p);
6582 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6587 + struct dbgaufs_arg *p;
6590 + p = kmalloc(sizeof(*p), GFP_NOFS);
6596 + file->private_data = p;
6600 + err = vfsub_getattr(&xf->f_path, &st);
6604 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6605 + cnt, st.blocks, st.blksize,
6606 + (long long)st.size);
6608 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6609 + st.blocks, st.blksize,
6610 + (long long)st.size);
6611 + AuDebugOn(p->n >= sizeof(p->a));
6613 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6621 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6622 + size_t count, loff_t *ppos)
6624 + struct dbgaufs_arg *p;
6626 + p = file->private_data;
6627 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6630 +/* ---------------------------------------------------------------------- */
6632 +struct dbgaufs_plink_arg {
6637 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6638 + struct file *file)
6640 + free_page((unsigned long)file->private_data);
6644 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6646 + int err, i, limit;
6647 + unsigned long n, sum;
6648 + struct dbgaufs_plink_arg *p;
6649 + struct au_sbinfo *sbinfo;
6650 + struct super_block *sb;
6651 + struct hlist_bl_head *hbl;
6654 + p = (void *)get_zeroed_page(GFP_NOFS);
6659 + sbinfo = inode->i_private;
6660 + sb = sbinfo->si_sb;
6661 + si_noflush_read_lock(sb);
6662 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6663 + limit = PAGE_SIZE - sizeof(p->n);
6665 + /* the number of buckets */
6666 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6671 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6673 + n = au_hbl_count(hbl);
6676 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6679 + if (unlikely(limit <= 0))
6682 + p->a[p->n - 1] = '\n';
6684 + /* the sum of plinks */
6685 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6688 + if (unlikely(limit <= 0))
6691 +#define str "1\n0\n0\n"
6692 + p->n = sizeof(str) - 1;
6693 + strcpy(p->a, str);
6696 + si_read_unlock(sb);
6699 + file->private_data = p;
6700 + goto out; /* success */
6703 + free_page((unsigned long)p);
6708 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6709 + size_t count, loff_t *ppos)
6711 + struct dbgaufs_plink_arg *p;
6713 + p = file->private_data;
6714 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6717 +static const struct file_operations dbgaufs_plink_fop = {
6718 + .owner = THIS_MODULE,
6719 + .open = dbgaufs_plink_open,
6720 + .release = dbgaufs_plink_release,
6721 + .read = dbgaufs_plink_read
6724 +/* ---------------------------------------------------------------------- */
6726 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6729 + struct au_sbinfo *sbinfo;
6730 + struct super_block *sb;
6732 + sbinfo = inode->i_private;
6733 + sb = sbinfo->si_sb;
6734 + si_noflush_read_lock(sb);
6735 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6736 + si_read_unlock(sb);
6740 +static const struct file_operations dbgaufs_xib_fop = {
6741 + .owner = THIS_MODULE,
6742 + .open = dbgaufs_xib_open,
6743 + .release = dbgaufs_xi_release,
6744 + .read = dbgaufs_xi_read
6747 +/* ---------------------------------------------------------------------- */
6749 +#define DbgaufsXi_PREFIX "xi"
6751 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6755 + aufs_bindex_t bindex;
6756 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6757 + struct au_sbinfo *sbinfo;
6758 + struct super_block *sb;
6759 + struct au_xino *xi;
6761 + struct qstr *name;
6762 + struct au_branch *br;
6765 + name = &file->f_path.dentry->d_name;
6766 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6767 + || memcmp(name->name, DbgaufsXi_PREFIX,
6768 + sizeof(DbgaufsXi_PREFIX) - 1)))
6771 + AuDebugOn(name->len >= sizeof(a));
6772 + memcpy(a, name->name, name->len);
6773 + a[name->len] = '\0';
6774 + p = strchr(a, '-');
6777 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6778 + if (unlikely(err))
6783 + err = kstrtol(p + 1, 10, &l);
6784 + if (unlikely(err))
6790 + sbinfo = inode->i_private;
6791 + sb = sbinfo->si_sb;
6792 + si_noflush_read_lock(sb);
6793 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6795 + br = au_sbr(sb, bindex);
6797 + if (unlikely(idx >= xi->xi_nfile))
6799 + xf = au_xino_file(xi, idx);
6801 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6802 + au_xino_count(br));
6805 + si_read_unlock(sb);
6811 +static const struct file_operations dbgaufs_xino_fop = {
6812 + .owner = THIS_MODULE,
6813 + .open = dbgaufs_xino_open,
6814 + .release = dbgaufs_xi_release,
6815 + .read = dbgaufs_xi_read
6818 +void dbgaufs_xino_del(struct au_branch *br)
6820 + struct dentry *dbgaufs;
6822 + dbgaufs = br->br_dbgaufs;
6826 + br->br_dbgaufs = NULL;
6827 + /* debugfs acquires the parent i_mutex */
6829 + debugfs_remove(dbgaufs);
6833 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6835 + aufs_bindex_t bbot;
6836 + struct au_branch *br;
6838 + if (!au_sbi(sb)->si_dbgaufs)
6841 + bbot = au_sbbot(sb);
6842 + for (; bindex <= bbot; bindex++) {
6843 + br = au_sbr(sb, bindex);
6844 + dbgaufs_xino_del(br);
6848 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6849 + unsigned int idx, struct dentry *parent,
6850 + struct au_sbinfo *sbinfo)
6852 + struct au_branch *br;
6854 + /* "xi" bindex(5) "-" idx(2) NULL */
6855 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6858 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6860 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6862 + br = au_sbr(sb, bindex);
6863 + if (br->br_dbgaufs) {
6864 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6866 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6867 + /* debugfs acquires the parent i_mutex */
6869 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6873 + pr_warn("failed renaming %pd/%s, ignored.\n",
6878 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6879 + sbinfo, &dbgaufs_xino_fop);
6881 + if (unlikely(!br->br_dbgaufs))
6882 + pr_warn("failed creating %pd/%s, ignored.\n",
6887 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6888 + struct dentry *parent, struct au_sbinfo *sbinfo)
6890 + struct au_branch *br;
6891 + struct au_xino *xi;
6894 + br = au_sbr(sb, bindex);
6896 + for (u = 0; u < xi->xi_nfile; u++)
6897 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6900 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6902 + struct au_sbinfo *sbinfo;
6903 + struct dentry *parent;
6904 + aufs_bindex_t bbot;
6906 + if (!au_opt_test(au_mntflags(sb), XINO))
6909 + sbinfo = au_sbi(sb);
6910 + parent = sbinfo->si_dbgaufs;
6914 + bbot = au_sbbot(sb);
6916 + for (; bindex <= bbot; bindex++)
6917 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6919 + for (; bbot >= bindex; bbot--)
6920 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6923 +/* ---------------------------------------------------------------------- */
6925 +#ifdef CONFIG_AUFS_EXPORT
6926 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6929 + struct au_sbinfo *sbinfo;
6930 + struct super_block *sb;
6932 + sbinfo = inode->i_private;
6933 + sb = sbinfo->si_sb;
6934 + si_noflush_read_lock(sb);
6935 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6936 + si_read_unlock(sb);
6940 +static const struct file_operations dbgaufs_xigen_fop = {
6941 + .owner = THIS_MODULE,
6942 + .open = dbgaufs_xigen_open,
6943 + .release = dbgaufs_xi_release,
6944 + .read = dbgaufs_xi_read
6947 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6952 + * This function is a dynamic '__init' function actually,
6953 + * so the tiny check for si_rwsem is unnecessary.
6955 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6958 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6959 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6960 + &dbgaufs_xigen_fop);
6961 + if (sbinfo->si_dbgaufs_xigen)
6967 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6971 +#endif /* CONFIG_AUFS_EXPORT */
6973 +/* ---------------------------------------------------------------------- */
6975 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6978 + * This function is a dynamic '__fin' function actually,
6979 + * so the tiny check for si_rwsem is unnecessary.
6981 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6983 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6984 + sbinfo->si_dbgaufs = NULL;
6987 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6990 + char name[SysaufsSiNameLen];
6993 + * This function is a dynamic '__init' function actually,
6994 + * so the tiny check for si_rwsem is unnecessary.
6996 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
7000 + AuErr1("/debug/aufs is uninitialized\n");
7005 + sysaufs_name(sbinfo, name);
7006 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
7007 + if (unlikely(!sbinfo->si_dbgaufs))
7010 + /* regardless plink/noplink option */
7011 + sbinfo->si_dbgaufs_plink = debugfs_create_file
7012 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
7013 + &dbgaufs_plink_fop);
7014 + if (unlikely(!sbinfo->si_dbgaufs_plink))
7017 + /* regardless xino/noxino option */
7018 + sbinfo->si_dbgaufs_xib = debugfs_create_file
7019 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
7020 + &dbgaufs_xib_fop);
7021 + if (unlikely(!sbinfo->si_dbgaufs_xib))
7024 + err = dbgaufs_xigen_init(sbinfo);
7026 + goto out; /* success */
7029 + dbgaufs_si_fin(sbinfo);
7031 + if (unlikely(err))
7032 + pr_err("debugfs/aufs failed\n");
7036 +/* ---------------------------------------------------------------------- */
7038 +void dbgaufs_fin(void)
7040 + debugfs_remove(dbgaufs);
7043 +int __init dbgaufs_init(void)
7048 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
7053 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
7054 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
7055 +++ linux/fs/aufs/dbgaufs.h 2019-03-05 12:13:00.135890907 +0100
7057 +/* SPDX-License-Identifier: GPL-2.0 */
7059 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7061 + * This program, aufs is free software; you can redistribute it and/or modify
7062 + * it under the terms of the GNU General Public License as published by
7063 + * the Free Software Foundation; either version 2 of the License, or
7064 + * (at your option) any later version.
7066 + * This program is distributed in the hope that it will be useful,
7067 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7068 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7069 + * GNU General Public License for more details.
7071 + * You should have received a copy of the GNU General Public License
7072 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7076 + * debugfs interface
7079 +#ifndef __DBGAUFS_H__
7080 +#define __DBGAUFS_H__
7084 +struct super_block;
7088 +#ifdef CONFIG_DEBUG_FS
7090 +void dbgaufs_xino_del(struct au_branch *br);
7091 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
7092 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
7093 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
7094 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
7095 +void dbgaufs_fin(void);
7096 +int __init dbgaufs_init(void);
7098 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
7099 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
7100 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
7102 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
7103 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
7104 +AuStubVoid(dbgaufs_fin, void)
7105 +AuStubInt0(__init dbgaufs_init, void)
7106 +#endif /* CONFIG_DEBUG_FS */
7108 +#endif /* __KERNEL__ */
7109 +#endif /* __DBGAUFS_H__ */
7110 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
7111 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
7112 +++ linux/fs/aufs/dcsub.c 2019-03-05 12:13:00.135890907 +0100
7114 +// SPDX-License-Identifier: GPL-2.0
7116 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7118 + * This program, aufs is free software; you can redistribute it and/or modify
7119 + * it under the terms of the GNU General Public License as published by
7120 + * the Free Software Foundation; either version 2 of the License, or
7121 + * (at your option) any later version.
7123 + * This program is distributed in the hope that it will be useful,
7124 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7125 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7126 + * GNU General Public License for more details.
7128 + * You should have received a copy of the GNU General Public License
7129 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7133 + * sub-routines for dentry cache
7138 +static void au_dpage_free(struct au_dpage *dpage)
7141 + struct dentry **p;
7143 + p = dpage->dentries;
7144 + for (i = 0; i < dpage->ndentry; i++)
7146 + free_page((unsigned long)dpage->dentries);
7149 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
7155 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
7156 + if (unlikely(!dpages->dpages))
7159 + p = (void *)__get_free_page(gfp);
7163 + dpages->dpages[0].ndentry = 0;
7164 + dpages->dpages[0].dentries = p;
7165 + dpages->ndpage = 1;
7166 + return 0; /* success */
7169 + au_kfree_try_rcu(dpages->dpages);
7174 +void au_dpages_free(struct au_dcsub_pages *dpages)
7177 + struct au_dpage *p;
7179 + p = dpages->dpages;
7180 + for (i = 0; i < dpages->ndpage; i++)
7181 + au_dpage_free(p++);
7182 + au_kfree_try_rcu(dpages->dpages);
7185 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7186 + struct dentry *dentry, gfp_t gfp)
7189 + struct au_dpage *dpage;
7192 + dpage = dpages->dpages + dpages->ndpage - 1;
7193 + sz = PAGE_SIZE / sizeof(dentry);
7194 + if (unlikely(dpage->ndentry >= sz)) {
7195 + AuLabel(new dpage);
7197 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7198 + p = au_kzrealloc(dpages->dpages, sz,
7199 + sz + sizeof(*dpages->dpages), gfp,
7204 + dpages->dpages = p;
7205 + dpage = dpages->dpages + dpages->ndpage;
7206 + p = (void *)__get_free_page(gfp);
7210 + dpage->ndentry = 0;
7211 + dpage->dentries = p;
7215 + AuDebugOn(au_dcount(dentry) <= 0);
7216 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7217 + return 0; /* success */
7223 +/* todo: BAD approach */
7224 +/* copied from linux/fs/dcache.c */
7232 +extern void d_walk(struct dentry *parent, void *data,
7233 + enum d_walk_ret (*enter)(void *, struct dentry *));
7235 +struct ac_dpages_arg {
7237 + struct au_dcsub_pages *dpages;
7238 + struct super_block *sb;
7239 + au_dpages_test test;
7243 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7245 + enum d_walk_ret ret;
7246 + struct ac_dpages_arg *arg = _arg;
7248 + ret = D_WALK_CONTINUE;
7249 + if (dentry->d_sb == arg->sb
7250 + && !IS_ROOT(dentry)
7251 + && au_dcount(dentry) > 0
7253 + && (!arg->test || arg->test(dentry, arg->arg))) {
7254 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7255 + if (unlikely(arg->err))
7256 + ret = D_WALK_QUIT;
7262 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7263 + au_dpages_test test, void *arg)
7265 + struct ac_dpages_arg args = {
7273 + d_walk(root, &args, au_call_dpages_append);
7278 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7279 + int do_include, au_dpages_test test, void *arg)
7284 + write_seqlock(&rename_lock);
7285 + spin_lock(&dentry->d_lock);
7287 + && au_dcount(dentry) > 0
7288 + && (!test || test(dentry, arg)))
7289 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7290 + spin_unlock(&dentry->d_lock);
7291 + if (unlikely(err))
7295 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7298 + while (!IS_ROOT(dentry)) {
7299 + dentry = dentry->d_parent; /* rename_lock is locked */
7300 + spin_lock(&dentry->d_lock);
7301 + if (au_dcount(dentry) > 0
7302 + && (!test || test(dentry, arg)))
7303 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7304 + spin_unlock(&dentry->d_lock);
7305 + if (unlikely(err))
7310 + write_sequnlock(&rename_lock);
7314 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7316 + return au_di(dentry) && dentry->d_sb == arg;
7319 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7320 + struct dentry *dentry, int do_include)
7322 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7323 + au_dcsub_dpages_aufs, dentry->d_sb);
7326 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7328 + struct path path[2] = {
7337 + return path_is_under(path + 0, path + 1);
7339 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7340 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7341 +++ linux/fs/aufs/dcsub.h 2019-03-05 12:13:00.135890907 +0100
7343 +/* SPDX-License-Identifier: GPL-2.0 */
7345 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7347 + * This program, aufs is free software; you can redistribute it and/or modify
7348 + * it under the terms of the GNU General Public License as published by
7349 + * the Free Software Foundation; either version 2 of the License, or
7350 + * (at your option) any later version.
7352 + * This program is distributed in the hope that it will be useful,
7353 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7354 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7355 + * GNU General Public License for more details.
7357 + * You should have received a copy of the GNU General Public License
7358 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7362 + * sub-routines for dentry cache
7365 +#ifndef __AUFS_DCSUB_H__
7366 +#define __AUFS_DCSUB_H__
7370 +#include <linux/dcache.h>
7371 +#include <linux/fs.h>
7375 + struct dentry **dentries;
7378 +struct au_dcsub_pages {
7380 + struct au_dpage *dpages;
7383 +/* ---------------------------------------------------------------------- */
7386 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7387 +void au_dpages_free(struct au_dcsub_pages *dpages);
7388 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7389 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7390 + au_dpages_test test, void *arg);
7391 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7392 + int do_include, au_dpages_test test, void *arg);
7393 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7394 + struct dentry *dentry, int do_include);
7395 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7397 +/* ---------------------------------------------------------------------- */
7400 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7401 + * include/linux/dcache.h. Try them (in the future).
7404 +static inline int au_d_hashed_positive(struct dentry *d)
7407 + struct inode *inode = d_inode(d);
7410 + if (unlikely(d_unhashed(d)
7411 + || d_is_negative(d)
7412 + || !inode->i_nlink))
7417 +static inline int au_d_linkable(struct dentry *d)
7420 + struct inode *inode = d_inode(d);
7422 + err = au_d_hashed_positive(d);
7424 + && d_is_positive(d)
7425 + && (inode->i_state & I_LINKABLE))
7430 +static inline int au_d_alive(struct dentry *d)
7433 + struct inode *inode;
7437 + err = au_d_hashed_positive(d);
7439 + inode = d_inode(d);
7440 + if (unlikely(d_unlinked(d)
7441 + || d_is_negative(d)
7442 + || !inode->i_nlink))
7448 +static inline int au_alive_dir(struct dentry *d)
7452 + err = au_d_alive(d);
7453 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7458 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7460 + return a->len == b->len
7461 + && !memcmp(a->name, b->name, a->len);
7466 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7468 + * the type of d_lockref.count became int, but the inlined function d_count()
7469 + * still returns unsigned int.
7470 + * I don't know why. Maybe it is for every d_count() users?
7471 + * Anyway au_dcount() lives on.
7473 +static inline int au_dcount(struct dentry *d)
7475 + return (int)d_count(d);
7478 +#endif /* __KERNEL__ */
7479 +#endif /* __AUFS_DCSUB_H__ */
7480 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7481 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7482 +++ linux/fs/aufs/debug.c 2019-03-05 12:13:00.135890907 +0100
7484 +// SPDX-License-Identifier: GPL-2.0
7486 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7488 + * This program, aufs is free software; you can redistribute it and/or modify
7489 + * it under the terms of the GNU General Public License as published by
7490 + * the Free Software Foundation; either version 2 of the License, or
7491 + * (at your option) any later version.
7493 + * This program is distributed in the hope that it will be useful,
7494 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7495 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7496 + * GNU General Public License for more details.
7498 + * You should have received a copy of the GNU General Public License
7499 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7503 + * debug print functions
7508 +/* Returns 0, or -errno. arg is in kp->arg. */
7509 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7513 + err = kstrtoint(val, 0, &n);
7523 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7524 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7529 + return sprintf(buffer, "%d", atomic_read(a));
7532 +static struct kernel_param_ops param_ops_atomic_t = {
7533 + .set = param_atomic_t_set,
7534 + .get = param_atomic_t_get
7535 + /* void (*free)(void *arg) */
7538 +atomic_t aufs_debug = ATOMIC_INIT(0);
7539 +MODULE_PARM_DESC(debug, "debug print");
7540 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7542 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7543 +char *au_plevel = KERN_DEBUG;
7544 +#define dpri(fmt, ...) do { \
7546 + && strcmp(au_plevel, KERN_DEBUG)) \
7547 + || au_debug_test()) \
7548 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7551 +/* ---------------------------------------------------------------------- */
7553 +void au_dpri_whlist(struct au_nhash *whlist)
7555 + unsigned long ul, n;
7556 + struct hlist_head *head;
7557 + struct au_vdir_wh *pos;
7559 + n = whlist->nh_num;
7560 + head = whlist->nh_head;
7561 + for (ul = 0; ul < n; ul++) {
7562 + hlist_for_each_entry(pos, head, wh_hash)
7563 + dpri("b%d, %.*s, %d\n",
7565 + pos->wh_str.len, pos->wh_str.name,
7571 +void au_dpri_vdir(struct au_vdir *vdir)
7574 + union au_vdir_deblk_p p;
7577 + if (!vdir || IS_ERR(vdir)) {
7578 + dpri("err %ld\n", PTR_ERR(vdir));
7582 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7583 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7584 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7585 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7586 + p.deblk = vdir->vd_deblk[ul];
7588 + dpri("[%lu]: %p\n", ul, o);
7592 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7593 + struct dentry *wh)
7598 + if (!inode || IS_ERR(inode)) {
7599 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7603 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7604 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7605 + && sizeof(inode->i_blocks) != sizeof(u64));
7607 + n = (void *)wh->d_name.name;
7608 + l = wh->d_name.len;
7611 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7612 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7614 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7615 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7616 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7617 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7618 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7619 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7620 + inode->i_generation,
7621 + l ? ", wh " : "", l, n);
7625 +void au_dpri_inode(struct inode *inode)
7627 + struct au_iinfo *iinfo;
7628 + struct au_hinode *hi;
7629 + aufs_bindex_t bindex;
7632 + err = do_pri_inode(-1, inode, -1, NULL);
7633 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7636 + iinfo = au_ii(inode);
7637 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7638 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7639 + if (iinfo->ii_btop < 0)
7642 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7643 + hi = au_hinode(iinfo, bindex);
7645 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7649 +void au_dpri_dalias(struct inode *inode)
7653 + spin_lock(&inode->i_lock);
7654 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7655 + au_dpri_dentry(d);
7656 + spin_unlock(&inode->i_lock);
7659 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7661 + struct dentry *wh = NULL;
7663 + struct inode *inode;
7664 + struct au_iinfo *iinfo;
7665 + struct au_hinode *hi;
7667 + if (!dentry || IS_ERR(dentry)) {
7668 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7671 + /* do not call dget_parent() here */
7672 + /* note: access d_xxx without d_lock */
7673 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7674 + bindex, dentry, dentry,
7675 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7676 + au_dcount(dentry), dentry->d_flags,
7677 + d_unhashed(dentry) ? "un" : "");
7680 + if (d_is_positive(dentry))
7681 + inode = d_inode(dentry);
7683 + && au_test_aufs(dentry->d_sb)
7685 + && !au_is_bad_inode(inode)) {
7686 + iinfo = au_ii(inode);
7687 + hi = au_hinode(iinfo, bindex);
7689 + wh = hi->hi_whdentry;
7691 + do_pri_inode(bindex, inode, hn, wh);
7695 +void au_dpri_dentry(struct dentry *dentry)
7697 + struct au_dinfo *dinfo;
7698 + aufs_bindex_t bindex;
7701 + err = do_pri_dentry(-1, dentry);
7702 + if (err || !au_test_aufs(dentry->d_sb))
7705 + dinfo = au_di(dentry);
7708 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7709 + dinfo->di_btop, dinfo->di_bbot,
7710 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7711 + dinfo->di_tmpfile);
7712 + if (dinfo->di_btop < 0)
7714 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7715 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7718 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7722 + if (!file || IS_ERR(file)) {
7723 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7728 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7729 + && au_test_aufs(file->f_path.dentry->d_sb)
7731 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7732 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7733 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7734 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7735 + file->f_version, file->f_pos, a);
7736 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7737 + do_pri_dentry(bindex, file->f_path.dentry);
7741 +void au_dpri_file(struct file *file)
7743 + struct au_finfo *finfo;
7744 + struct au_fidir *fidir;
7745 + struct au_hfile *hfile;
7746 + aufs_bindex_t bindex;
7749 + err = do_pri_file(-1, file);
7751 + || IS_ERR_OR_NULL(file->f_path.dentry)
7752 + || !au_test_aufs(file->f_path.dentry->d_sb))
7755 + finfo = au_fi(file);
7758 + if (finfo->fi_btop < 0)
7760 + fidir = finfo->fi_hdir;
7762 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7764 + for (bindex = finfo->fi_btop;
7765 + bindex >= 0 && bindex <= fidir->fd_bbot;
7767 + hfile = fidir->fd_hfile + bindex;
7768 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7772 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7774 + struct vfsmount *mnt;
7775 + struct super_block *sb;
7777 + if (!br || IS_ERR(br))
7779 + mnt = au_br_mnt(br);
7780 + if (!mnt || IS_ERR(mnt))
7783 + if (!sb || IS_ERR(sb))
7786 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7787 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7789 + bindex, br->br_perm, br->br_id, br->br_wbr,
7790 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7791 + sb->s_flags, sb->s_count,
7792 + atomic_read(&sb->s_active),
7793 + !!au_xino_file(br->br_xino, /*idx*/-1));
7797 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7801 +void au_dpri_sb(struct super_block *sb)
7803 + struct au_sbinfo *sbinfo;
7804 + aufs_bindex_t bindex;
7806 + /* to reduce stack size */
7808 + struct vfsmount mnt;
7809 + struct au_branch fake;
7812 + /* this function can be called from magic sysrq */
7813 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7814 + if (unlikely(!a)) {
7815 + dpri("no memory\n");
7819 + a->mnt.mnt_sb = sb;
7820 + a->fake.br_path.mnt = &a->mnt;
7821 + err = do_pri_br(-1, &a->fake);
7823 + dpri("dev 0x%x\n", sb->s_dev);
7824 + if (err || !au_test_aufs(sb))
7827 + sbinfo = au_sbi(sb);
7830 + dpri("nw %d, gen %u, kobj %d\n",
7831 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7832 + kref_read(&sbinfo->si_kobj.kref));
7833 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7834 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7837 +/* ---------------------------------------------------------------------- */
7839 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7841 + struct inode *h_inode, *inode = d_inode(dentry);
7842 + struct dentry *h_dentry;
7843 + aufs_bindex_t bindex, bbot, bi;
7845 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7848 + bbot = au_dbbot(dentry);
7849 + bi = au_ibbot(inode);
7852 + bindex = au_dbtop(dentry);
7853 + bi = au_ibtop(inode);
7857 + for (; bindex <= bbot; bindex++) {
7858 + h_dentry = au_h_dptr(dentry, bindex);
7861 + h_inode = au_h_iptr(inode, bindex);
7862 + if (unlikely(h_inode != d_inode(h_dentry))) {
7864 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7865 + AuDbgDentry(dentry);
7866 + AuDbgInode(inode);
7873 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7876 + struct au_dcsub_pages dpages;
7877 + struct au_dpage *dpage;
7878 + struct dentry **dentries;
7880 + err = au_dpages_init(&dpages, GFP_NOFS);
7882 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7884 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7885 + dpage = dpages.dpages + i;
7886 + dentries = dpage->dentries;
7887 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7888 + AuDebugOn(au_digen_test(dentries[j], sigen));
7890 + au_dpages_free(&dpages);
7893 +void au_dbg_verify_kthread(void)
7895 + if (au_wkq_test()) {
7898 + * It may be recursive, but udba=notify between two aufs mounts,
7899 + * where a single ro branch is shared, is not a problem.
7905 +/* ---------------------------------------------------------------------- */
7907 +int __init au_debug_init(void)
7909 + aufs_bindex_t bindex;
7910 + struct au_vdir_destr destr;
7913 + AuDebugOn(bindex >= 0);
7916 + AuDebugOn(destr.len < NAME_MAX);
7918 +#ifdef CONFIG_4KSTACKS
7919 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7924 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7925 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7926 +++ linux/fs/aufs/debug.h 2019-03-05 12:13:00.135890907 +0100
7928 +/* SPDX-License-Identifier: GPL-2.0 */
7930 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7932 + * This program, aufs is free software; you can redistribute it and/or modify
7933 + * it under the terms of the GNU General Public License as published by
7934 + * the Free Software Foundation; either version 2 of the License, or
7935 + * (at your option) any later version.
7937 + * This program is distributed in the hope that it will be useful,
7938 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7939 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7940 + * GNU General Public License for more details.
7942 + * You should have received a copy of the GNU General Public License
7943 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7947 + * debug print functions
7950 +#ifndef __AUFS_DEBUG_H__
7951 +#define __AUFS_DEBUG_H__
7955 +#include <linux/atomic.h>
7956 +#include <linux/module.h>
7957 +#include <linux/kallsyms.h>
7958 +#include <linux/sysrq.h>
7960 +#ifdef CONFIG_AUFS_DEBUG
7961 +#define AuDebugOn(a) BUG_ON(a)
7963 +/* module parameter */
7964 +extern atomic_t aufs_debug;
7965 +static inline void au_debug_on(void)
7967 + atomic_inc(&aufs_debug);
7969 +static inline void au_debug_off(void)
7971 + atomic_dec_if_positive(&aufs_debug);
7974 +static inline int au_debug_test(void)
7976 + return atomic_read(&aufs_debug) > 0;
7979 +#define AuDebugOn(a) do {} while (0)
7980 +AuStubVoid(au_debug_on, void)
7981 +AuStubVoid(au_debug_off, void)
7982 +AuStubInt0(au_debug_test, void)
7983 +#endif /* CONFIG_AUFS_DEBUG */
7985 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7987 +/* ---------------------------------------------------------------------- */
7991 +#define AuDbg(fmt, ...) do { \
7992 + if (au_debug_test()) \
7993 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7995 +#define AuLabel(l) AuDbg(#l "\n")
7996 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7997 +#define AuWarn1(fmt, ...) do { \
7998 + static unsigned char _c; \
8000 + pr_warn(fmt, ##__VA_ARGS__); \
8003 +#define AuErr1(fmt, ...) do { \
8004 + static unsigned char _c; \
8006 + pr_err(fmt, ##__VA_ARGS__); \
8009 +#define AuIOErr1(fmt, ...) do { \
8010 + static unsigned char _c; \
8012 + AuIOErr(fmt, ##__VA_ARGS__); \
8015 +#define AuUnsupportMsg "This operation is not supported." \
8016 + " Please report this application to aufs-users ML."
8017 +#define AuUnsupport(fmt, ...) do { \
8018 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
8022 +#define AuTraceErr(e) do { \
8023 + if (unlikely((e) < 0)) \
8024 + AuDbg("err %d\n", (int)(e)); \
8027 +#define AuTraceErrPtr(p) do { \
8029 + AuDbg("err %ld\n", PTR_ERR(p)); \
8032 +/* dirty macros for debug print, use with "%.*s" and caution */
8033 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
8035 +/* ---------------------------------------------------------------------- */
8038 +#ifdef CONFIG_AUFS_DEBUG
8039 +extern struct mutex au_dbg_mtx;
8040 +extern char *au_plevel;
8042 +void au_dpri_whlist(struct au_nhash *whlist);
8044 +void au_dpri_vdir(struct au_vdir *vdir);
8046 +void au_dpri_inode(struct inode *inode);
8047 +void au_dpri_dalias(struct inode *inode);
8048 +void au_dpri_dentry(struct dentry *dentry);
8050 +void au_dpri_file(struct file *filp);
8051 +struct super_block;
8052 +void au_dpri_sb(struct super_block *sb);
8054 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
8055 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
8056 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
8057 +void au_dbg_verify_kthread(void);
8059 +int __init au_debug_init(void);
8061 +#define AuDbgWhlist(w) do { \
8062 + mutex_lock(&au_dbg_mtx); \
8064 + au_dpri_whlist(w); \
8065 + mutex_unlock(&au_dbg_mtx); \
8068 +#define AuDbgVdir(v) do { \
8069 + mutex_lock(&au_dbg_mtx); \
8071 + au_dpri_vdir(v); \
8072 + mutex_unlock(&au_dbg_mtx); \
8075 +#define AuDbgInode(i) do { \
8076 + mutex_lock(&au_dbg_mtx); \
8078 + au_dpri_inode(i); \
8079 + mutex_unlock(&au_dbg_mtx); \
8082 +#define AuDbgDAlias(i) do { \
8083 + mutex_lock(&au_dbg_mtx); \
8085 + au_dpri_dalias(i); \
8086 + mutex_unlock(&au_dbg_mtx); \
8089 +#define AuDbgDentry(d) do { \
8090 + mutex_lock(&au_dbg_mtx); \
8092 + au_dpri_dentry(d); \
8093 + mutex_unlock(&au_dbg_mtx); \
8096 +#define AuDbgFile(f) do { \
8097 + mutex_lock(&au_dbg_mtx); \
8099 + au_dpri_file(f); \
8100 + mutex_unlock(&au_dbg_mtx); \
8103 +#define AuDbgSb(sb) do { \
8104 + mutex_lock(&au_dbg_mtx); \
8105 + AuDbg(#sb "\n"); \
8107 + mutex_unlock(&au_dbg_mtx); \
8110 +#define AuDbgSym(addr) do { \
8111 + char sym[KSYM_SYMBOL_LEN]; \
8112 + sprint_symbol(sym, (unsigned long)addr); \
8113 + AuDbg("%s\n", sym); \
8116 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
8117 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
8118 +AuStubVoid(au_dbg_verify_kthread, void)
8119 +AuStubInt0(__init au_debug_init, void)
8121 +#define AuDbgWhlist(w) do {} while (0)
8122 +#define AuDbgVdir(v) do {} while (0)
8123 +#define AuDbgInode(i) do {} while (0)
8124 +#define AuDbgDAlias(i) do {} while (0)
8125 +#define AuDbgDentry(d) do {} while (0)
8126 +#define AuDbgFile(f) do {} while (0)
8127 +#define AuDbgSb(sb) do {} while (0)
8128 +#define AuDbgSym(addr) do {} while (0)
8129 +#endif /* CONFIG_AUFS_DEBUG */
8131 +/* ---------------------------------------------------------------------- */
8133 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
8134 +int __init au_sysrq_init(void);
8135 +void au_sysrq_fin(void);
8137 +#ifdef CONFIG_HW_CONSOLE
8138 +#define au_dbg_blocked() do { \
8140 + handle_sysrq('w'); \
8143 +AuStubVoid(au_dbg_blocked, void)
8147 +AuStubInt0(__init au_sysrq_init, void)
8148 +AuStubVoid(au_sysrq_fin, void)
8149 +AuStubVoid(au_dbg_blocked, void)
8150 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
8152 +#endif /* __KERNEL__ */
8153 +#endif /* __AUFS_DEBUG_H__ */
8154 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
8155 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
8156 +++ linux/fs/aufs/dentry.c 2019-03-05 12:13:00.135890907 +0100
8158 +// SPDX-License-Identifier: GPL-2.0
8160 + * Copyright (C) 2005-2019 Junjiro R. Okajima
8162 + * This program, aufs is free software; you can redistribute it and/or modify
8163 + * it under the terms of the GNU General Public License as published by
8164 + * the Free Software Foundation; either version 2 of the License, or
8165 + * (at your option) any later version.
8167 + * This program is distributed in the hope that it will be useful,
8168 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8169 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8170 + * GNU General Public License for more details.
8172 + * You should have received a copy of the GNU General Public License
8173 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8177 + * lookup and dentry operations
8180 +#include <linux/namei.h>
8184 + * returns positive/negative dentry, NULL or an error.
8185 + * NULL means whiteout-ed or not-found.
8187 +static struct dentry*
8188 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8189 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8191 + struct dentry *h_dentry;
8192 + struct inode *h_inode;
8193 + struct au_branch *br;
8194 + int wh_found, opq;
8195 + unsigned char wh_able;
8196 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8197 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8201 + br = au_sbr(dentry->d_sb, bindex);
8202 + wh_able = !!au_br_whable(br->br_perm);
8204 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8205 + h_dentry = ERR_PTR(wh_found);
8208 + if (unlikely(wh_found < 0))
8211 + /* We found a whiteout */
8212 + /* au_set_dbbot(dentry, bindex); */
8213 + au_set_dbwh(dentry, bindex);
8215 + return NULL; /* success */
8219 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8221 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8222 + if (IS_ERR(h_dentry)) {
8223 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8229 + h_inode = d_inode(h_dentry);
8230 + if (d_is_negative(h_dentry)) {
8233 + } else if (wh_found
8234 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8236 + else if (au_ftest_lkup(args->flags, DIRREN)
8238 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8239 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8240 + (unsigned long long)h_inode->i_ino);
8244 + if (au_dbbot(dentry) <= bindex)
8245 + au_set_dbbot(dentry, bindex);
8246 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8247 + au_set_dbtop(dentry, bindex);
8248 + au_set_h_dptr(dentry, bindex, h_dentry);
8250 + if (!d_is_dir(h_dentry)
8252 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8253 + goto out; /* success */
8255 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8256 + opq = au_diropq_test(h_dentry);
8257 + inode_unlock_shared(h_inode);
8259 + au_set_dbdiropq(dentry, bindex);
8260 + else if (unlikely(opq < 0)) {
8261 + au_set_h_dptr(dentry, bindex, NULL);
8262 + h_dentry = ERR_PTR(opq);
8273 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8275 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8276 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8282 + * returns the number of lower positive dentries,
8283 + * otherwise an error.
8284 + * can be called at unlinking with @type is zero.
8286 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8287 + unsigned int flags)
8289 + int npositive, err;
8290 + aufs_bindex_t bindex, btail, bdiropq;
8291 + unsigned char isdir, dirperm1, dirren;
8292 + struct au_do_lookup_args args = {
8294 + .name = &dentry->d_name
8296 + struct dentry *parent;
8297 + struct super_block *sb;
8299 + sb = dentry->d_sb;
8300 + err = au_test_shwh(sb, args.name);
8301 + if (unlikely(err))
8304 + err = au_wh_name_alloc(&args.whname, args.name);
8305 + if (unlikely(err))
8308 + isdir = !!d_is_dir(dentry);
8309 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8310 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8312 + au_fset_lkup(args.flags, DIRREN);
8315 + parent = dget_parent(dentry);
8316 + btail = au_dbtaildir(parent);
8317 + for (bindex = btop; bindex <= btail; bindex++) {
8318 + struct dentry *h_parent, *h_dentry;
8319 + struct inode *h_inode, *h_dir;
8320 + struct au_branch *br;
8322 + h_dentry = au_h_dptr(dentry, bindex);
8324 + if (d_is_positive(h_dentry))
8328 + h_parent = au_h_dptr(parent, bindex);
8329 + if (!h_parent || !d_is_dir(h_parent))
8333 + /* if the inum matches, then use the prepared name */
8334 + err = au_dr_lkup_name(&args, bindex);
8335 + if (unlikely(err))
8339 + h_dir = d_inode(h_parent);
8340 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8341 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8342 + inode_unlock_shared(h_dir);
8343 + err = PTR_ERR(h_dentry);
8344 + if (IS_ERR(h_dentry))
8347 + au_fclr_lkup(args.flags, ALLOW_NEG);
8349 + au_fset_lkup(args.flags, IGNORE_PERM);
8351 + if (au_dbwh(dentry) == bindex)
8355 + if (d_is_negative(h_dentry))
8357 + h_inode = d_inode(h_dentry);
8360 + args.type = h_inode->i_mode & S_IFMT;
8361 + if (args.type != S_IFDIR)
8364 + /* the type of lower may be different */
8365 + bdiropq = au_dbdiropq(dentry);
8366 + if (bdiropq >= 0 && bdiropq <= bindex)
8369 + br = au_sbr(sb, bindex);
8371 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8372 + /*add_ent*/NULL)) {
8373 + /* prepare next name to lookup */
8374 + err = au_dr_lkup(&args, dentry, bindex);
8375 + if (unlikely(err))
8381 + AuLabel(positive);
8382 + au_update_dbtop(dentry);
8385 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8386 + && au_dbtop(dentry) < 0)) {
8388 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8394 + au_kfree_try_rcu(args.whname.name);
8396 + au_dr_lkup_fin(&args);
8401 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8403 + struct dentry *dentry;
8406 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8407 + dentry = vfsub_lkup_one(name, parent);
8409 + struct vfsub_lkup_one_args args = {
8415 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8416 + if (unlikely(wkq_err))
8417 + dentry = ERR_PTR(wkq_err);
8424 + * lookup @dentry on @bindex which should be negative.
8426 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8429 + struct dentry *parent, *h_parent, *h_dentry;
8430 + struct au_branch *br;
8432 + parent = dget_parent(dentry);
8433 + h_parent = au_h_dptr(parent, bindex);
8434 + br = au_sbr(dentry->d_sb, bindex);
8436 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8438 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8439 + err = PTR_ERR(h_dentry);
8440 + if (IS_ERR(h_dentry))
8442 + if (unlikely(d_is_positive(h_dentry))) {
8444 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8450 + if (bindex < au_dbtop(dentry))
8451 + au_set_dbtop(dentry, bindex);
8452 + if (au_dbbot(dentry) < bindex)
8453 + au_set_dbbot(dentry, bindex);
8454 + au_set_h_dptr(dentry, bindex, h_dentry);
8461 +/* ---------------------------------------------------------------------- */
8463 +/* subset of struct inode */
8465 + unsigned long i_ino;
8466 + /* unsigned int i_nlink; */
8472 + blkcnt_t i_blocks;
8477 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8479 + ia->i_ino = h_inode->i_ino;
8480 + /* ia->i_nlink = h_inode->i_nlink; */
8481 + ia->i_uid = h_inode->i_uid;
8482 + ia->i_gid = h_inode->i_gid;
8483 + ia->i_version = inode_query_iversion(h_inode);
8485 + ia->i_size = h_inode->i_size;
8486 + ia->i_blocks = h_inode->i_blocks;
8488 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8491 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8493 + return ia->i_ino != h_inode->i_ino
8494 + /* || ia->i_nlink != h_inode->i_nlink */
8495 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8496 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8497 + || !inode_eq_iversion(h_inode, ia->i_version)
8499 + || ia->i_size != h_inode->i_size
8500 + || ia->i_blocks != h_inode->i_blocks
8502 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8505 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8506 + struct au_branch *br)
8509 + struct au_iattr ia;
8510 + struct inode *h_inode;
8511 + struct dentry *h_d;
8512 + struct super_block *h_sb;
8515 + memset(&ia, -1, sizeof(ia));
8516 + h_sb = h_dentry->d_sb;
8518 + if (d_is_positive(h_dentry)) {
8519 + h_inode = d_inode(h_dentry);
8520 + au_iattr_save(&ia, h_inode);
8521 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8522 + /* nfs d_revalidate may return 0 for negative dentry */
8523 + /* fuse d_revalidate always return 0 for negative dentry */
8526 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8527 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8528 + err = PTR_ERR(h_d);
8533 + if (unlikely(h_d != h_dentry
8534 + || d_inode(h_d) != h_inode
8535 + || (h_inode && au_iattr_test(&ia, h_inode))))
8536 + err = au_busy_or_stale();
8544 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8545 + struct dentry *h_parent, struct au_branch *br)
8550 + if (udba == AuOpt_UDBA_REVAL
8551 + && !au_test_fs_remote(h_dentry->d_sb)) {
8553 + err = (d_inode(h_dentry->d_parent) != h_dir);
8554 + } else if (udba != AuOpt_UDBA_NONE)
8555 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8560 +/* ---------------------------------------------------------------------- */
8562 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8565 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8566 + struct au_hdentry tmp, *p, *q;
8567 + struct au_dinfo *dinfo;
8568 + struct super_block *sb;
8570 + DiMustWriteLock(dentry);
8572 + sb = dentry->d_sb;
8573 + dinfo = au_di(dentry);
8574 + bbot = dinfo->di_bbot;
8575 + bwh = dinfo->di_bwh;
8576 + bdiropq = dinfo->di_bdiropq;
8577 + bindex = dinfo->di_btop;
8578 + p = au_hdentry(dinfo, bindex);
8579 + for (; bindex <= bbot; bindex++, p++) {
8580 + if (!p->hd_dentry)
8583 + new_bindex = au_br_index(sb, p->hd_id);
8584 + if (new_bindex == bindex)
8587 + if (dinfo->di_bwh == bindex)
8589 + if (dinfo->di_bdiropq == bindex)
8590 + bdiropq = new_bindex;
8591 + if (new_bindex < 0) {
8593 + p->hd_dentry = NULL;
8597 + /* swap two lower dentries, and loop again */
8598 + q = au_hdentry(dinfo, new_bindex);
8602 + if (tmp.hd_dentry) {
8608 + dinfo->di_bwh = -1;
8609 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8610 + dinfo->di_bwh = bwh;
8612 + dinfo->di_bdiropq = -1;
8614 + && bdiropq <= au_sbbot(sb)
8615 + && au_sbr_whable(sb, bdiropq))
8616 + dinfo->di_bdiropq = bdiropq;
8619 + dinfo->di_btop = -1;
8620 + dinfo->di_bbot = -1;
8621 + bbot = au_dbbot(parent);
8623 + p = au_hdentry(dinfo, bindex);
8624 + for (; bindex <= bbot; bindex++, p++)
8625 + if (p->hd_dentry) {
8626 + dinfo->di_btop = bindex;
8630 + if (dinfo->di_btop >= 0) {
8632 + p = au_hdentry(dinfo, bindex);
8633 + for (; bindex >= 0; bindex--, p--)
8634 + if (p->hd_dentry) {
8635 + dinfo->di_bbot = bindex;
8644 +static void au_do_hide(struct dentry *dentry)
8646 + struct inode *inode;
8648 + if (d_really_is_positive(dentry)) {
8649 + inode = d_inode(dentry);
8650 + if (!d_is_dir(dentry)) {
8651 + if (inode->i_nlink && !d_unhashed(dentry))
8652 + drop_nlink(inode);
8654 + clear_nlink(inode);
8655 + /* stop next lookup */
8656 + inode->i_flags |= S_DEAD;
8658 + smp_mb(); /* necessary? */
8663 +static int au_hide_children(struct dentry *parent)
8665 + int err, i, j, ndentry;
8666 + struct au_dcsub_pages dpages;
8667 + struct au_dpage *dpage;
8668 + struct dentry *dentry;
8670 + err = au_dpages_init(&dpages, GFP_NOFS);
8671 + if (unlikely(err))
8673 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8674 + if (unlikely(err))
8677 + /* in reverse order */
8678 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8679 + dpage = dpages.dpages + i;
8680 + ndentry = dpage->ndentry;
8681 + for (j = ndentry - 1; j >= 0; j--) {
8682 + dentry = dpage->dentries[j];
8683 + if (dentry != parent)
8684 + au_do_hide(dentry);
8689 + au_dpages_free(&dpages);
8694 +static void au_hide(struct dentry *dentry)
8698 + AuDbgDentry(dentry);
8699 + if (d_is_dir(dentry)) {
8700 + /* shrink_dcache_parent(dentry); */
8701 + err = au_hide_children(dentry);
8702 + if (unlikely(err))
8703 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8706 + au_do_hide(dentry);
8710 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8712 + * a dirty branch is added
8713 + * - on the top of layers
8714 + * - in the middle of layers
8715 + * - to the bottom of layers
8717 + * on the added branch there exists
8720 + * - a same named entry
8722 + * * negative --> positive
8723 + * * positive --> positive
8724 + * - type is unchanged
8725 + * - type is changed
8727 + * * negative --> negative
8728 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8731 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8732 + struct au_dinfo *tmp)
8735 + aufs_bindex_t bindex, bbot;
8737 + struct dentry *dentry;
8738 + struct inode *inode;
8740 + } orig_h, tmp_h = {
8743 + struct au_hdentry *hd;
8744 + struct inode *inode, *h_inode;
8745 + struct dentry *h_dentry;
8748 + AuDebugOn(dinfo->di_btop < 0);
8750 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8751 + orig_h.inode = NULL;
8752 + if (d_is_positive(orig_h.dentry)) {
8753 + orig_h.inode = d_inode(orig_h.dentry);
8754 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8756 + if (tmp->di_btop >= 0) {
8757 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8758 + if (d_is_positive(tmp_h.dentry)) {
8759 + tmp_h.inode = d_inode(tmp_h.dentry);
8760 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8765 + if (d_really_is_positive(dentry))
8766 + inode = d_inode(dentry);
8767 + if (!orig_h.inode) {
8768 + AuDbg("negative originally\n");
8774 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8775 + AuDebugOn(dinfo->di_bdiropq != -1);
8777 + if (!tmp_h.inode) {
8778 + AuDbg("negative --> negative\n");
8779 + /* should have only one negative lower */
8780 + if (tmp->di_btop >= 0
8781 + && tmp->di_btop < dinfo->di_btop) {
8782 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8783 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8784 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8785 + au_di_cp(dinfo, tmp);
8786 + hd = au_hdentry(tmp, tmp->di_btop);
8787 + au_set_h_dptr(dentry, tmp->di_btop,
8788 + dget(hd->hd_dentry));
8790 + au_dbg_verify_dinode(dentry);
8792 + AuDbg("negative --> positive\n");
8794 + * similar to the behaviour of creating with bypassing
8796 + * unhash it in order to force an error in the
8797 + * succeeding create operation.
8798 + * we should not set S_DEAD here.
8801 + /* au_di_swap(tmp, dinfo); */
8802 + au_dbg_verify_dinode(dentry);
8805 + AuDbg("positive originally\n");
8806 + /* inode may be NULL */
8807 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8808 + if (!tmp_h.inode) {
8809 + AuDbg("positive --> negative\n");
8810 + /* or bypassing aufs */
8812 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8813 + dinfo->di_bwh = tmp->di_bwh;
8815 + err = au_refresh_hinode_self(inode);
8816 + au_dbg_verify_dinode(dentry);
8817 + } else if (orig_h.mode == tmp_h.mode) {
8818 + AuDbg("positive --> positive, same type\n");
8819 + if (!S_ISDIR(orig_h.mode)
8820 + && dinfo->di_btop > tmp->di_btop) {
8822 + * similar to the behaviour of removing and
8827 + err = au_refresh_hinode_self(inode);
8828 + au_dbg_verify_dinode(dentry);
8830 + /* fill empty slots */
8831 + if (dinfo->di_btop > tmp->di_btop)
8832 + dinfo->di_btop = tmp->di_btop;
8833 + if (dinfo->di_bbot < tmp->di_bbot)
8834 + dinfo->di_bbot = tmp->di_bbot;
8835 + dinfo->di_bwh = tmp->di_bwh;
8836 + dinfo->di_bdiropq = tmp->di_bdiropq;
8837 + bbot = dinfo->di_bbot;
8838 + bindex = tmp->di_btop;
8839 + hd = au_hdentry(tmp, bindex);
8840 + for (; bindex <= bbot; bindex++, hd++) {
8841 + if (au_h_dptr(dentry, bindex))
8843 + h_dentry = hd->hd_dentry;
8846 + AuDebugOn(d_is_negative(h_dentry));
8847 + h_inode = d_inode(h_dentry);
8848 + AuDebugOn(orig_h.mode
8849 + != (h_inode->i_mode
8851 + au_set_h_dptr(dentry, bindex,
8855 + err = au_refresh_hinode(inode, dentry);
8856 + au_dbg_verify_dinode(dentry);
8859 + AuDbg("positive --> positive, different type\n");
8860 + /* similar to the behaviour of removing and creating */
8863 + err = au_refresh_hinode_self(inode);
8864 + au_dbg_verify_dinode(dentry);
8872 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8874 + const struct dentry_operations *dop
8875 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8876 + static const unsigned int mask
8877 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8879 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8881 + if (dentry->d_op == dop)
8884 + AuDbg("%pd\n", dentry);
8885 + spin_lock(&dentry->d_lock);
8886 + if (dop == &aufs_dop)
8887 + dentry->d_flags |= mask;
8889 + dentry->d_flags &= ~mask;
8890 + dentry->d_op = dop;
8891 + spin_unlock(&dentry->d_lock);
8894 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8896 + int err, ebrange, nbr;
8897 + unsigned int sigen;
8898 + struct au_dinfo *dinfo, *tmp;
8899 + struct super_block *sb;
8900 + struct inode *inode;
8902 + DiMustWriteLock(dentry);
8903 + AuDebugOn(IS_ROOT(dentry));
8904 + AuDebugOn(d_really_is_negative(parent));
8906 + sb = dentry->d_sb;
8907 + sigen = au_sigen(sb);
8908 + err = au_digen_test(parent, sigen);
8909 + if (unlikely(err))
8912 + nbr = au_sbbot(sb) + 1;
8913 + dinfo = au_di(dentry);
8914 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8915 + if (unlikely(err))
8917 + ebrange = au_dbrange_test(dentry);
8919 + ebrange = au_do_refresh_hdentry(dentry, parent);
8921 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8922 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8923 + if (d_really_is_positive(dentry)) {
8924 + inode = d_inode(dentry);
8925 + err = au_refresh_hinode_self(inode);
8927 + au_dbg_verify_dinode(dentry);
8929 + goto out_dgen; /* success */
8933 + /* temporary dinfo */
8934 + AuDbgDentry(dentry);
8936 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8937 + if (unlikely(!tmp))
8939 + au_di_swap(tmp, dinfo);
8940 + /* returns the number of positive dentries */
8942 + * if current working dir is removed, it returns an error.
8943 + * but the dentry is legal.
8945 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8946 + AuDbgDentry(dentry);
8947 + au_di_swap(tmp, dinfo);
8948 + if (err == -ENOENT)
8951 + /* compare/refresh by dinfo */
8952 + AuDbgDentry(dentry);
8953 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8954 + au_dbg_verify_dinode(dentry);
8957 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8958 + au_rw_write_unlock(&tmp->di_rwsem);
8960 + if (unlikely(err))
8964 + au_update_digen(dentry);
8966 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8967 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8968 + AuDbgDentry(dentry);
8974 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8975 + struct dentry *dentry, aufs_bindex_t bindex)
8980 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8983 + AuDbg("b%d\n", bindex);
8985 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8986 + * due to whiteout and branch permission.
8988 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8989 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8990 + /* it may return tri-state */
8991 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8993 + if (unlikely(valid < 0))
9003 +/* todo: remove this */
9004 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
9005 + unsigned int flags, int do_udba, int dirren)
9008 + umode_t mode, h_mode;
9009 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
9010 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
9011 + struct inode *h_inode, *h_cached_inode;
9012 + struct dentry *h_dentry;
9013 + struct qstr *name, *h_name;
9020 + unhashed = !!d_unhashed(dentry);
9021 + is_root = !!IS_ROOT(dentry);
9022 + name = &dentry->d_name;
9023 + tmpfile = au_di(dentry)->di_tmpfile;
9026 + * Theoretically, REVAL test should be unnecessary in case of
9028 + * But {fs,i}notify doesn't fire some necessary events,
9029 + * IN_ATTRIB for atime/nlink/pageio
9030 + * Let's do REVAL test too.
9032 + if (do_udba && inode) {
9033 + mode = (inode->i_mode & S_IFMT);
9034 + plus = (inode->i_nlink > 0);
9035 + ibs = au_ibtop(inode);
9036 + ibe = au_ibbot(inode);
9039 + btop = au_dbtop(dentry);
9041 + if (inode && S_ISDIR(inode->i_mode))
9042 + btail = au_dbtaildir(dentry);
9043 + for (bindex = btop; bindex <= btail; bindex++) {
9044 + h_dentry = au_h_dptr(dentry, bindex);
9048 + AuDbg("b%d, %pd\n", bindex, h_dentry);
9049 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
9050 + spin_lock(&h_dentry->d_lock);
9051 + h_name = &h_dentry->d_name;
9052 + if (unlikely(do_udba
9055 + && (unhashed != !!d_unhashed(h_dentry)
9056 + || (!tmpfile && !dirren
9057 + && !au_qstreq(name, h_name))
9060 + && !(flags & LOOKUP_OPEN)
9061 + && (h_dentry->d_flags
9062 + & DCACHE_NFSFS_RENAMED)))
9066 + h_unhashed = d_unhashed(h_dentry);
9067 + spin_unlock(&h_dentry->d_lock);
9068 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
9069 + unhashed, h_unhashed, dentry, h_dentry);
9072 + spin_unlock(&h_dentry->d_lock);
9074 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
9075 + if (unlikely(err))
9076 + /* do not goto err, to keep the errno */
9079 + /* todo: plink too? */
9084 + if (unlikely(!!inode != d_is_positive(h_dentry)))
9088 + if (d_is_positive(h_dentry))
9089 + h_inode = d_inode(h_dentry);
9092 + h_cached_inode = h_inode;
9094 + h_mode = (h_inode->i_mode & S_IFMT);
9095 + h_plus = (h_inode->i_nlink > 0);
9097 + if (inode && ibs <= bindex && bindex <= ibe)
9098 + h_cached_inode = au_h_iptr(inode, bindex);
9101 + if (unlikely(plus != h_plus && !tmpfile))
9104 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
9106 + && !IS_ROOT(h_dentry)
9107 + && unhashed != d_unhashed(h_dentry)))
9110 + if (unlikely(mode != h_mode
9111 + || h_cached_inode != h_inode))
9124 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
9125 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
9128 + struct dentry *parent;
9130 + if (!au_digen_test(dentry, sigen))
9133 + parent = dget_parent(dentry);
9134 + di_read_lock_parent(parent, AuLock_IR);
9135 + AuDebugOn(au_digen_test(parent, sigen));
9136 + au_dbg_verify_gen(parent, sigen);
9137 + err = au_refresh_dentry(dentry, parent);
9138 + di_read_unlock(parent, AuLock_IR);
9144 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
9147 + struct dentry *d, *parent;
9149 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
9150 + return simple_reval_dpath(dentry, sigen);
9152 + /* slow loop, keep it simple and stupid */
9153 + /* cf: au_cpup_dirs() */
9156 + while (au_digen_test(dentry, sigen)) {
9160 + parent = dget_parent(d);
9161 + if (!au_digen_test(parent, sigen))
9167 + di_write_lock_child2(d);
9169 + /* someone might update our dentry while we were sleeping */
9170 + if (au_digen_test(d, sigen)) {
9172 + * todo: consolidate with simple_reval_dpath(),
9173 + * do_refresh() and au_reval_for_attr().
9175 + di_read_lock_parent(parent, AuLock_IR);
9176 + err = au_refresh_dentry(d, parent);
9177 + di_read_unlock(parent, AuLock_IR);
9181 + di_write_unlock(d);
9183 + if (unlikely(err))
9191 + * if valid returns 1, otherwise 0.
9193 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9196 + unsigned int sigen;
9197 + unsigned char do_udba, dirren;
9198 + struct super_block *sb;
9199 + struct inode *inode;
9201 + /* todo: support rcu-walk? */
9202 + if (flags & LOOKUP_RCU)
9206 + if (unlikely(!au_di(dentry)))
9210 + sb = dentry->d_sb;
9213 + * i_mutex of parent dir may be held,
9214 + * but we should not return 'invalid' due to busy.
9216 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9217 + if (unlikely(err)) {
9223 + if (d_really_is_positive(dentry))
9224 + inode = d_inode(dentry);
9225 + if (unlikely(inode && au_is_bad_inode(inode))) {
9230 + if (unlikely(au_dbrange_test(dentry))) {
9236 + sigen = au_sigen(sb);
9237 + if (au_digen_test(dentry, sigen)) {
9238 + AuDebugOn(IS_ROOT(dentry));
9239 + err = au_reval_dpath(dentry, sigen);
9240 + if (unlikely(err)) {
9245 + di_downgrade_lock(dentry, AuLock_IR);
9248 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9250 + && !(inode->i_state && I_LINKABLE)
9251 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9256 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9257 + if (do_udba && inode) {
9258 + aufs_bindex_t btop = au_ibtop(inode);
9259 + struct inode *h_inode;
9262 + h_inode = au_h_iptr(inode, btop);
9263 + if (h_inode && au_test_higen(inode, h_inode)) {
9270 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9271 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9272 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9274 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9280 + di_downgrade_lock(dentry, AuLock_IR);
9282 + aufs_read_unlock(dentry, AuLock_IR);
9287 + AuDbg("%pd invalid, %d\n", dentry, valid);
9293 +static void aufs_d_release(struct dentry *dentry)
9295 + if (au_di(dentry)) {
9296 + au_di_fin(dentry);
9297 + au_hn_di_reinit(dentry);
9301 +const struct dentry_operations aufs_dop = {
9302 + .d_revalidate = aufs_d_revalidate,
9303 + .d_weak_revalidate = aufs_d_revalidate,
9304 + .d_release = aufs_d_release
9307 +/* aufs_dop without d_revalidate */
9308 +const struct dentry_operations aufs_dop_noreval = {
9309 + .d_release = aufs_d_release
9311 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9312 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9313 +++ linux/fs/aufs/dentry.h 2019-03-05 12:13:00.135890907 +0100
9315 +/* SPDX-License-Identifier: GPL-2.0 */
9317 + * Copyright (C) 2005-2019 Junjiro R. Okajima
9319 + * This program, aufs is free software; you can redistribute it and/or modify
9320 + * it under the terms of the GNU General Public License as published by
9321 + * the Free Software Foundation; either version 2 of the License, or
9322 + * (at your option) any later version.
9324 + * This program is distributed in the hope that it will be useful,
9325 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9326 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9327 + * GNU General Public License for more details.
9329 + * You should have received a copy of the GNU General Public License
9330 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9334 + * lookup and dentry operations
9337 +#ifndef __AUFS_DENTRY_H__
9338 +#define __AUFS_DENTRY_H__
9342 +#include <linux/dcache.h>
9343 +#include "dirren.h"
9346 +struct au_hdentry {
9347 + struct dentry *hd_dentry;
9348 + aufs_bindex_t hd_id;
9352 + atomic_t di_generation;
9354 + struct au_rwsem di_rwsem;
9355 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9356 + unsigned char di_tmpfile; /* to allow the different name */
9357 + struct au_hdentry *di_hdentry;
9358 + struct rcu_head rcu;
9359 +} ____cacheline_aligned_in_smp;
9361 +/* ---------------------------------------------------------------------- */
9363 +/* flags for au_lkup_dentry() */
9364 +#define AuLkup_ALLOW_NEG 1
9365 +#define AuLkup_IGNORE_PERM (1 << 1)
9366 +#define AuLkup_DIRREN (1 << 2)
9367 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9368 +#define au_fset_lkup(flags, name) \
9369 + do { (flags) |= AuLkup_##name; } while (0)
9370 +#define au_fclr_lkup(flags, name) \
9371 + do { (flags) &= ~AuLkup_##name; } while (0)
9373 +#ifndef CONFIG_AUFS_DIRREN
9374 +#undef AuLkup_DIRREN
9375 +#define AuLkup_DIRREN 0
9378 +struct au_do_lookup_args {
9379 + unsigned int flags;
9381 + struct qstr whname, *name;
9382 + struct au_dr_lookup dirren;
9385 +/* ---------------------------------------------------------------------- */
9388 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9390 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9391 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9392 + struct dentry *h_parent, struct au_branch *br);
9394 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9395 + unsigned int flags);
9396 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9397 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9398 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9399 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9402 +void au_di_init_once(void *_di);
9403 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9404 +void au_di_free(struct au_dinfo *dinfo);
9405 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9406 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9407 +int au_di_init(struct dentry *dentry);
9408 +void au_di_fin(struct dentry *dentry);
9409 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9411 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9412 +void di_read_unlock(struct dentry *d, int flags);
9413 +void di_downgrade_lock(struct dentry *d, int flags);
9414 +void di_write_lock(struct dentry *d, unsigned int lsc);
9415 +void di_write_unlock(struct dentry *d);
9416 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9417 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9418 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9420 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9421 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9422 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9423 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9425 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9426 + struct dentry *h_dentry);
9427 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9428 +int au_dbrange_test(struct dentry *dentry);
9429 +void au_update_digen(struct dentry *dentry);
9430 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9431 +void au_update_dbtop(struct dentry *dentry);
9432 +void au_update_dbbot(struct dentry *dentry);
9433 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9435 +/* ---------------------------------------------------------------------- */
9437 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9439 + return dentry->d_fsdata;
9442 +/* ---------------------------------------------------------------------- */
9444 +/* lock subclass for dinfo */
9446 + AuLsc_DI_CHILD, /* child first */
9447 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9448 + AuLsc_DI_CHILD3, /* copyup dirs */
9452 + AuLsc_DI_TMP /* temp for replacing dinfo */
9456 + * di_read_lock_child, di_write_lock_child,
9457 + * di_read_lock_child2, di_write_lock_child2,
9458 + * di_read_lock_child3, di_write_lock_child3,
9459 + * di_read_lock_parent, di_write_lock_parent,
9460 + * di_read_lock_parent2, di_write_lock_parent2,
9461 + * di_read_lock_parent3, di_write_lock_parent3,
9463 +#define AuReadLockFunc(name, lsc) \
9464 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9465 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9467 +#define AuWriteLockFunc(name, lsc) \
9468 +static inline void di_write_lock_##name(struct dentry *d) \
9469 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9471 +#define AuRWLockFuncs(name, lsc) \
9472 + AuReadLockFunc(name, lsc) \
9473 + AuWriteLockFunc(name, lsc)
9475 +AuRWLockFuncs(child, CHILD);
9476 +AuRWLockFuncs(child2, CHILD2);
9477 +AuRWLockFuncs(child3, CHILD3);
9478 +AuRWLockFuncs(parent, PARENT);
9479 +AuRWLockFuncs(parent2, PARENT2);
9480 +AuRWLockFuncs(parent3, PARENT3);
9482 +#undef AuReadLockFunc
9483 +#undef AuWriteLockFunc
9484 +#undef AuRWLockFuncs
9486 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9487 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9488 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9490 +/* ---------------------------------------------------------------------- */
9492 +/* todo: memory barrier? */
9493 +static inline unsigned int au_digen(struct dentry *d)
9495 + return atomic_read(&au_di(d)->di_generation);
9498 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9500 + hdentry->hd_dentry = NULL;
9503 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9504 + aufs_bindex_t bindex)
9506 + return di->di_hdentry + bindex;
9509 +static inline void au_hdput(struct au_hdentry *hd)
9512 + dput(hd->hd_dentry);
9515 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9517 + DiMustAnyLock(dentry);
9518 + return au_di(dentry)->di_btop;
9521 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9523 + DiMustAnyLock(dentry);
9524 + return au_di(dentry)->di_bbot;
9527 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9529 + DiMustAnyLock(dentry);
9530 + return au_di(dentry)->di_bwh;
9533 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9535 + DiMustAnyLock(dentry);
9536 + return au_di(dentry)->di_bdiropq;
9539 +/* todo: hard/soft set? */
9540 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9542 + DiMustWriteLock(dentry);
9543 + au_di(dentry)->di_btop = bindex;
9546 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9548 + DiMustWriteLock(dentry);
9549 + au_di(dentry)->di_bbot = bindex;
9552 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9554 + DiMustWriteLock(dentry);
9555 + /* dbwh can be outside of btop - bbot range */
9556 + au_di(dentry)->di_bwh = bindex;
9559 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9561 + DiMustWriteLock(dentry);
9562 + au_di(dentry)->di_bdiropq = bindex;
9565 +/* ---------------------------------------------------------------------- */
9567 +#ifdef CONFIG_AUFS_HNOTIFY
9568 +static inline void au_digen_dec(struct dentry *d)
9570 + atomic_dec(&au_di(d)->di_generation);
9573 +static inline void au_hn_di_reinit(struct dentry *dentry)
9575 + dentry->d_fsdata = NULL;
9578 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9579 +#endif /* CONFIG_AUFS_HNOTIFY */
9581 +#endif /* __KERNEL__ */
9582 +#endif /* __AUFS_DENTRY_H__ */
9583 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9584 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9585 +++ linux/fs/aufs/dinfo.c 2019-03-05 12:13:00.135890907 +0100
9587 +// SPDX-License-Identifier: GPL-2.0
9589 + * Copyright (C) 2005-2019 Junjiro R. Okajima
9591 + * This program, aufs is free software; you can redistribute it and/or modify
9592 + * it under the terms of the GNU General Public License as published by
9593 + * the Free Software Foundation; either version 2 of the License, or
9594 + * (at your option) any later version.
9596 + * This program is distributed in the hope that it will be useful,
9597 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9598 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9599 + * GNU General Public License for more details.
9601 + * You should have received a copy of the GNU General Public License
9602 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9606 + * dentry private data
9611 +void au_di_init_once(void *_dinfo)
9613 + struct au_dinfo *dinfo = _dinfo;
9615 + au_rw_init(&dinfo->di_rwsem);
9618 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9620 + struct au_dinfo *dinfo;
9623 + dinfo = au_cache_alloc_dinfo();
9624 + if (unlikely(!dinfo))
9627 + nbr = au_sbbot(sb) + 1;
9630 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9631 + if (dinfo->di_hdentry) {
9632 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9633 + dinfo->di_btop = -1;
9634 + dinfo->di_bbot = -1;
9635 + dinfo->di_bwh = -1;
9636 + dinfo->di_bdiropq = -1;
9637 + dinfo->di_tmpfile = 0;
9638 + for (i = 0; i < nbr; i++)
9639 + dinfo->di_hdentry[i].hd_id = -1;
9643 + au_cache_free_dinfo(dinfo);
9650 +void au_di_free(struct au_dinfo *dinfo)
9652 + struct au_hdentry *p;
9653 + aufs_bindex_t bbot, bindex;
9655 + /* dentry may not be revalidated */
9656 + bindex = dinfo->di_btop;
9657 + if (bindex >= 0) {
9658 + bbot = dinfo->di_bbot;
9659 + p = au_hdentry(dinfo, bindex);
9660 + while (bindex++ <= bbot)
9663 + au_kfree_try_rcu(dinfo->di_hdentry);
9664 + au_cache_free_dinfo(dinfo);
9667 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9669 + struct au_hdentry *p;
9672 + AuRwMustWriteLock(&a->di_rwsem);
9673 + AuRwMustWriteLock(&b->di_rwsem);
9675 +#define DiSwap(v, name) \
9677 + v = a->di_##name; \
9678 + a->di_##name = b->di_##name; \
9679 + b->di_##name = v; \
9682 + DiSwap(p, hdentry);
9686 + DiSwap(bi, bdiropq);
9692 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9694 + AuRwMustWriteLock(&dst->di_rwsem);
9695 + AuRwMustWriteLock(&src->di_rwsem);
9697 + dst->di_btop = src->di_btop;
9698 + dst->di_bbot = src->di_bbot;
9699 + dst->di_bwh = src->di_bwh;
9700 + dst->di_bdiropq = src->di_bdiropq;
9704 +int au_di_init(struct dentry *dentry)
9707 + struct super_block *sb;
9708 + struct au_dinfo *dinfo;
9711 + sb = dentry->d_sb;
9712 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9714 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9715 + /* smp_mb(); */ /* atomic_set */
9716 + dentry->d_fsdata = dinfo;
9723 +void au_di_fin(struct dentry *dentry)
9725 + struct au_dinfo *dinfo;
9727 + dinfo = au_di(dentry);
9728 + AuRwDestroy(&dinfo->di_rwsem);
9729 + au_di_free(dinfo);
9732 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9735 + struct au_hdentry *hdp;
9737 + AuRwMustWriteLock(&dinfo->di_rwsem);
9740 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9742 + sz = sizeof(*hdp);
9743 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9746 + dinfo->di_hdentry = hdp;
9753 +/* ---------------------------------------------------------------------- */
9755 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9758 + case AuLsc_DI_CHILD:
9759 + ii_write_lock_child(inode);
9761 + case AuLsc_DI_CHILD2:
9762 + ii_write_lock_child2(inode);
9764 + case AuLsc_DI_CHILD3:
9765 + ii_write_lock_child3(inode);
9767 + case AuLsc_DI_PARENT:
9768 + ii_write_lock_parent(inode);
9770 + case AuLsc_DI_PARENT2:
9771 + ii_write_lock_parent2(inode);
9773 + case AuLsc_DI_PARENT3:
9774 + ii_write_lock_parent3(inode);
9781 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9784 + case AuLsc_DI_CHILD:
9785 + ii_read_lock_child(inode);
9787 + case AuLsc_DI_CHILD2:
9788 + ii_read_lock_child2(inode);
9790 + case AuLsc_DI_CHILD3:
9791 + ii_read_lock_child3(inode);
9793 + case AuLsc_DI_PARENT:
9794 + ii_read_lock_parent(inode);
9796 + case AuLsc_DI_PARENT2:
9797 + ii_read_lock_parent2(inode);
9799 + case AuLsc_DI_PARENT3:
9800 + ii_read_lock_parent3(inode);
9807 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9809 + struct inode *inode;
9811 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9812 + if (d_really_is_positive(d)) {
9813 + inode = d_inode(d);
9814 + if (au_ftest_lock(flags, IW))
9815 + do_ii_write_lock(inode, lsc);
9816 + else if (au_ftest_lock(flags, IR))
9817 + do_ii_read_lock(inode, lsc);
9821 +void di_read_unlock(struct dentry *d, int flags)
9823 + struct inode *inode;
9825 + if (d_really_is_positive(d)) {
9826 + inode = d_inode(d);
9827 + if (au_ftest_lock(flags, IW)) {
9828 + au_dbg_verify_dinode(d);
9829 + ii_write_unlock(inode);
9830 + } else if (au_ftest_lock(flags, IR)) {
9831 + au_dbg_verify_dinode(d);
9832 + ii_read_unlock(inode);
9835 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9838 +void di_downgrade_lock(struct dentry *d, int flags)
9840 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9841 + ii_downgrade_lock(d_inode(d));
9842 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9845 +void di_write_lock(struct dentry *d, unsigned int lsc)
9847 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9848 + if (d_really_is_positive(d))
9849 + do_ii_write_lock(d_inode(d), lsc);
9852 +void di_write_unlock(struct dentry *d)
9854 + au_dbg_verify_dinode(d);
9855 + if (d_really_is_positive(d))
9856 + ii_write_unlock(d_inode(d));
9857 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9860 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9862 + AuDebugOn(d1 == d2
9863 + || d_inode(d1) == d_inode(d2)
9864 + || d1->d_sb != d2->d_sb);
9866 + if ((isdir && au_test_subdir(d1, d2))
9868 + di_write_lock_child(d1);
9869 + di_write_lock_child2(d2);
9871 + di_write_lock_child(d2);
9872 + di_write_lock_child2(d1);
9876 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9878 + AuDebugOn(d1 == d2
9879 + || d_inode(d1) == d_inode(d2)
9880 + || d1->d_sb != d2->d_sb);
9882 + if ((isdir && au_test_subdir(d1, d2))
9884 + di_write_lock_parent(d1);
9885 + di_write_lock_parent2(d2);
9887 + di_write_lock_parent(d2);
9888 + di_write_lock_parent2(d1);
9892 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9894 + di_write_unlock(d1);
9895 + if (d_inode(d1) == d_inode(d2))
9896 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9898 + di_write_unlock(d2);
9901 +/* ---------------------------------------------------------------------- */
9903 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9907 + DiMustAnyLock(dentry);
9909 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9911 + AuDebugOn(bindex < 0);
9912 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9913 + AuDebugOn(d && au_dcount(d) <= 0);
9918 + * extended version of au_h_dptr().
9919 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9922 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9924 + struct dentry *h_dentry;
9925 + struct inode *inode, *h_inode;
9927 + AuDebugOn(d_really_is_negative(dentry));
9930 + if (au_dbtop(dentry) <= bindex
9931 + && bindex <= au_dbbot(dentry))
9932 + h_dentry = au_h_dptr(dentry, bindex);
9933 + if (h_dentry && !au_d_linkable(h_dentry)) {
9935 + goto out; /* success */
9938 + inode = d_inode(dentry);
9939 + AuDebugOn(bindex < au_ibtop(inode));
9940 + AuDebugOn(au_ibbot(inode) < bindex);
9941 + h_inode = au_h_iptr(inode, bindex);
9942 + h_dentry = d_find_alias(h_inode);
9944 + if (!IS_ERR(h_dentry)) {
9945 + if (!au_d_linkable(h_dentry))
9946 + goto out; /* success */
9952 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9953 + h_dentry = au_plink_lkup(inode, bindex);
9954 + AuDebugOn(!h_dentry);
9955 + if (!IS_ERR(h_dentry)) {
9956 + if (!au_d_hashed_positive(h_dentry))
9957 + goto out; /* success */
9964 + AuDbgDentry(h_dentry);
9968 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9970 + aufs_bindex_t bbot, bwh;
9972 + bbot = au_dbbot(dentry);
9974 + bwh = au_dbwh(dentry);
9977 + if (0 < bwh && bwh < bbot)
9983 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9985 + aufs_bindex_t bbot, bopq;
9987 + bbot = au_dbtail(dentry);
9989 + bopq = au_dbdiropq(dentry);
9990 + if (0 <= bopq && bopq < bbot)
9996 +/* ---------------------------------------------------------------------- */
9998 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9999 + struct dentry *h_dentry)
10001 + struct au_dinfo *dinfo;
10002 + struct au_hdentry *hd;
10003 + struct au_branch *br;
10005 + DiMustWriteLock(dentry);
10007 + dinfo = au_di(dentry);
10008 + hd = au_hdentry(dinfo, bindex);
10010 + hd->hd_dentry = h_dentry;
10012 + br = au_sbr(dentry->d_sb, bindex);
10013 + hd->hd_id = br->br_id;
10017 +int au_dbrange_test(struct dentry *dentry)
10020 + aufs_bindex_t btop, bbot;
10023 + btop = au_dbtop(dentry);
10024 + bbot = au_dbbot(dentry);
10026 + AuDebugOn(bbot < 0 && btop > bbot);
10029 + AuDebugOn(bbot >= 0);
10035 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
10040 + if (unlikely(au_digen(dentry) != sigen
10041 + || au_iigen_test(d_inode(dentry), sigen)))
10047 +void au_update_digen(struct dentry *dentry)
10049 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
10050 + /* smp_mb(); */ /* atomic_set */
10053 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
10055 + struct au_dinfo *dinfo;
10056 + struct dentry *h_d;
10057 + struct au_hdentry *hdp;
10058 + aufs_bindex_t bindex, bbot;
10060 + DiMustWriteLock(dentry);
10062 + dinfo = au_di(dentry);
10063 + if (!dinfo || dinfo->di_btop < 0)
10066 + if (do_put_zero) {
10067 + bbot = dinfo->di_bbot;
10068 + bindex = dinfo->di_btop;
10069 + hdp = au_hdentry(dinfo, bindex);
10070 + for (; bindex <= bbot; bindex++, hdp++) {
10071 + h_d = hdp->hd_dentry;
10072 + if (h_d && d_is_negative(h_d))
10073 + au_set_h_dptr(dentry, bindex, NULL);
10077 + dinfo->di_btop = 0;
10078 + hdp = au_hdentry(dinfo, dinfo->di_btop);
10079 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
10080 + if (hdp->hd_dentry)
10082 + if (dinfo->di_btop > dinfo->di_bbot) {
10083 + dinfo->di_btop = -1;
10084 + dinfo->di_bbot = -1;
10088 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
10089 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
10090 + if (hdp->hd_dentry)
10092 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
10095 +void au_update_dbtop(struct dentry *dentry)
10097 + aufs_bindex_t bindex, bbot;
10098 + struct dentry *h_dentry;
10100 + bbot = au_dbbot(dentry);
10101 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
10102 + h_dentry = au_h_dptr(dentry, bindex);
10105 + if (d_is_positive(h_dentry)) {
10106 + au_set_dbtop(dentry, bindex);
10109 + au_set_h_dptr(dentry, bindex, NULL);
10113 +void au_update_dbbot(struct dentry *dentry)
10115 + aufs_bindex_t bindex, btop;
10116 + struct dentry *h_dentry;
10118 + btop = au_dbtop(dentry);
10119 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
10120 + h_dentry = au_h_dptr(dentry, bindex);
10123 + if (d_is_positive(h_dentry)) {
10124 + au_set_dbbot(dentry, bindex);
10127 + au_set_h_dptr(dentry, bindex, NULL);
10131 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
10133 + aufs_bindex_t bindex, bbot;
10135 + bbot = au_dbbot(dentry);
10136 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
10137 + if (au_h_dptr(dentry, bindex) == h_dentry)
10141 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
10142 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
10143 +++ linux/fs/aufs/dir.c 2019-03-05 12:13:00.135890907 +0100
10145 +// SPDX-License-Identifier: GPL-2.0
10147 + * Copyright (C) 2005-2019 Junjiro R. Okajima
10149 + * This program, aufs is free software; you can redistribute it and/or modify
10150 + * it under the terms of the GNU General Public License as published by
10151 + * the Free Software Foundation; either version 2 of the License, or
10152 + * (at your option) any later version.
10154 + * This program is distributed in the hope that it will be useful,
10155 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10156 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10157 + * GNU General Public License for more details.
10159 + * You should have received a copy of the GNU General Public License
10160 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10164 + * directory operations
10167 +#include <linux/fs_stack.h>
10170 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10172 + unsigned int nlink;
10174 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10176 + nlink = dir->i_nlink;
10177 + nlink += h_dir->i_nlink - 2;
10178 + if (h_dir->i_nlink < 2)
10180 + smp_mb(); /* for i_nlink */
10181 + /* 0 can happen in revaliding */
10182 + set_nlink(dir, nlink);
10185 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10187 + unsigned int nlink;
10189 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10191 + nlink = dir->i_nlink;
10192 + nlink -= h_dir->i_nlink - 2;
10193 + if (h_dir->i_nlink < 2)
10195 + smp_mb(); /* for i_nlink */
10196 + /* nlink == 0 means the branch-fs is broken */
10197 + set_nlink(dir, nlink);
10200 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10203 + aufs_bindex_t bindex, bbot;
10204 + struct file *h_file;
10205 + struct dentry *h_dentry;
10209 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10211 + bbot = au_fbbot_dir(file);
10212 + for (bindex = au_fbtop(file);
10213 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10215 + h_file = au_hf_dir(file, bindex);
10216 + if (h_file && file_inode(h_file))
10217 + sz += vfsub_f_size_read(h_file);
10220 + AuDebugOn(!dentry);
10221 + AuDebugOn(!d_is_dir(dentry));
10223 + bbot = au_dbtaildir(dentry);
10224 + for (bindex = au_dbtop(dentry);
10225 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10227 + h_dentry = au_h_dptr(dentry, bindex);
10228 + if (h_dentry && d_is_positive(h_dentry))
10229 + sz += i_size_read(d_inode(h_dentry));
10232 + if (sz < KMALLOC_MAX_SIZE)
10233 + sz = roundup_pow_of_two(sz);
10234 + if (sz > KMALLOC_MAX_SIZE)
10235 + sz = KMALLOC_MAX_SIZE;
10236 + else if (sz < NAME_MAX) {
10237 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10238 + sz = AUFS_RDBLK_DEF;
10243 +struct au_dir_ts_arg {
10244 + struct dentry *dentry;
10245 + aufs_bindex_t brid;
10248 +static void au_do_dir_ts(void *arg)
10250 + struct au_dir_ts_arg *a = arg;
10251 + struct au_dtime dt;
10252 + struct path h_path;
10253 + struct inode *dir, *h_dir;
10254 + struct super_block *sb;
10255 + struct au_branch *br;
10256 + struct au_hinode *hdir;
10258 + aufs_bindex_t btop, bindex;
10260 + sb = a->dentry->d_sb;
10261 + if (d_really_is_negative(a->dentry))
10263 + /* no dir->i_mutex lock */
10264 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10266 + dir = d_inode(a->dentry);
10267 + btop = au_ibtop(dir);
10268 + bindex = au_br_index(sb, a->brid);
10269 + if (bindex < btop)
10272 + br = au_sbr(sb, bindex);
10273 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10274 + if (!h_path.dentry)
10276 + h_path.mnt = au_br_mnt(br);
10277 + au_dtime_store(&dt, a->dentry, &h_path);
10279 + br = au_sbr(sb, btop);
10280 + if (!au_br_writable(br->br_perm))
10282 + h_path.dentry = au_h_dptr(a->dentry, btop);
10283 + h_path.mnt = au_br_mnt(br);
10284 + err = vfsub_mnt_want_write(h_path.mnt);
10287 + hdir = au_hi(dir, btop);
10288 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10289 + h_dir = au_h_iptr(dir, btop);
10290 + if (h_dir->i_nlink
10291 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10292 + dt.dt_h_path = h_path;
10293 + au_dtime_revert(&dt);
10295 + au_hn_inode_unlock(hdir);
10296 + vfsub_mnt_drop_write(h_path.mnt);
10297 + au_cpup_attr_timesizes(dir);
10300 + aufs_read_unlock(a->dentry, AuLock_DW);
10303 + au_nwt_done(&au_sbi(sb)->si_nowait);
10304 + au_kfree_try_rcu(arg);
10307 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10309 + int perm, wkq_err;
10310 + aufs_bindex_t btop;
10311 + struct au_dir_ts_arg *arg;
10312 + struct dentry *dentry;
10313 + struct super_block *sb;
10317 + dentry = d_find_any_alias(dir);
10318 + AuDebugOn(!dentry);
10319 + sb = dentry->d_sb;
10320 + btop = au_ibtop(dir);
10321 + if (btop == bindex) {
10322 + au_cpup_attr_timesizes(dir);
10326 + perm = au_sbr_perm(sb, btop);
10327 + if (!au_br_writable(perm))
10330 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10334 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10335 + arg->brid = au_sbr_id(sb, bindex);
10336 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10337 + if (unlikely(wkq_err)) {
10338 + pr_err("wkq %d\n", wkq_err);
10340 + au_kfree_try_rcu(arg);
10347 +/* ---------------------------------------------------------------------- */
10349 +static int reopen_dir(struct file *file)
10352 + unsigned int flags;
10353 + aufs_bindex_t bindex, btail, btop;
10354 + struct dentry *dentry, *h_dentry;
10355 + struct file *h_file;
10357 + /* open all lower dirs */
10358 + dentry = file->f_path.dentry;
10359 + btop = au_dbtop(dentry);
10360 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10361 + au_set_h_fptr(file, bindex, NULL);
10362 + au_set_fbtop(file, btop);
10364 + btail = au_dbtaildir(dentry);
10365 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10366 + au_set_h_fptr(file, bindex, NULL);
10367 + au_set_fbbot_dir(file, btail);
10369 + flags = vfsub_file_flags(file);
10370 + for (bindex = btop; bindex <= btail; bindex++) {
10371 + h_dentry = au_h_dptr(dentry, bindex);
10374 + h_file = au_hf_dir(file, bindex);
10378 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10379 + err = PTR_ERR(h_file);
10380 + if (IS_ERR(h_file))
10381 + goto out; /* close all? */
10382 + au_set_h_fptr(file, bindex, h_file);
10384 + au_update_figen(file);
10385 + /* todo: necessary? */
10386 + /* file->f_ra = h_file->f_ra; */
10393 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10396 + aufs_bindex_t bindex, btail;
10397 + struct dentry *dentry, *h_dentry;
10398 + struct vfsmount *mnt;
10400 + FiMustWriteLock(file);
10401 + AuDebugOn(h_file);
10404 + mnt = file->f_path.mnt;
10405 + dentry = file->f_path.dentry;
10406 + file->f_version = inode_query_iversion(d_inode(dentry));
10407 + bindex = au_dbtop(dentry);
10408 + au_set_fbtop(file, bindex);
10409 + btail = au_dbtaildir(dentry);
10410 + au_set_fbbot_dir(file, btail);
10411 + for (; !err && bindex <= btail; bindex++) {
10412 + h_dentry = au_h_dptr(dentry, bindex);
10416 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10417 + if (unlikely(err))
10419 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10420 + if (IS_ERR(h_file)) {
10421 + err = PTR_ERR(h_file);
10424 + au_set_h_fptr(file, bindex, h_file);
10426 + au_update_figen(file);
10427 + /* todo: necessary? */
10428 + /* file->f_ra = h_file->f_ra; */
10430 + return 0; /* success */
10433 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10434 + au_set_h_fptr(file, bindex, NULL);
10435 + au_set_fbtop(file, -1);
10436 + au_set_fbbot_dir(file, -1);
10441 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10442 + struct file *file)
10445 + struct super_block *sb;
10446 + struct au_fidir *fidir;
10449 + sb = file->f_path.dentry->d_sb;
10450 + si_read_lock(sb, AuLock_FLUSH);
10451 + fidir = au_fidir_alloc(sb);
10453 + struct au_do_open_args args = {
10454 + .open = do_open_dir,
10457 + err = au_do_open(file, &args);
10458 + if (unlikely(err))
10459 + au_kfree_rcu(fidir);
10461 + si_read_unlock(sb);
10465 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10466 + struct file *file)
10468 + struct au_vdir *vdir_cache;
10469 + struct au_finfo *finfo;
10470 + struct au_fidir *fidir;
10471 + struct au_hfile *hf;
10472 + aufs_bindex_t bindex, bbot;
10474 + finfo = au_fi(file);
10475 + fidir = finfo->fi_hdir;
10477 + au_hbl_del(&finfo->fi_hlist,
10478 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10479 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10481 + au_vdir_free(vdir_cache);
10483 + bindex = finfo->fi_btop;
10484 + if (bindex >= 0) {
10485 + hf = fidir->fd_hfile + bindex;
10487 + * calls fput() instead of filp_close(),
10488 + * since no dnotify or lock for the lower file.
10490 + bbot = fidir->fd_bbot;
10491 + for (; bindex <= bbot; bindex++, hf++)
10493 + au_hfput(hf, /*execed*/0);
10495 + au_kfree_rcu(fidir);
10496 + finfo->fi_hdir = NULL;
10498 + au_finfo_fin(file);
10502 +/* ---------------------------------------------------------------------- */
10504 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10507 + aufs_bindex_t bindex, bbot;
10508 + struct file *h_file;
10511 + bbot = au_fbbot_dir(file);
10512 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10513 + h_file = au_hf_dir(file, bindex);
10515 + err = vfsub_flush(h_file, id);
10520 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10522 + return au_do_flush(file, id, au_do_flush_dir);
10525 +/* ---------------------------------------------------------------------- */
10527 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10530 + aufs_bindex_t bbot, bindex;
10531 + struct inode *inode;
10532 + struct super_block *sb;
10535 + sb = dentry->d_sb;
10536 + inode = d_inode(dentry);
10537 + IMustLock(inode);
10538 + bbot = au_dbbot(dentry);
10539 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10540 + struct path h_path;
10542 + if (au_test_ro(sb, bindex, inode))
10544 + h_path.dentry = au_h_dptr(dentry, bindex);
10545 + if (!h_path.dentry)
10548 + h_path.mnt = au_sbr_mnt(sb, bindex);
10549 + err = vfsub_fsync(NULL, &h_path, datasync);
10555 +static int au_do_fsync_dir(struct file *file, int datasync)
10558 + aufs_bindex_t bbot, bindex;
10559 + struct file *h_file;
10560 + struct super_block *sb;
10561 + struct inode *inode;
10563 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10564 + if (unlikely(err))
10567 + inode = file_inode(file);
10568 + sb = inode->i_sb;
10569 + bbot = au_fbbot_dir(file);
10570 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10571 + h_file = au_hf_dir(file, bindex);
10572 + if (!h_file || au_test_ro(sb, bindex, inode))
10575 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10583 + * @file may be NULL
10585 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10589 + struct dentry *dentry;
10590 + struct inode *inode;
10591 + struct super_block *sb;
10594 + dentry = file->f_path.dentry;
10595 + inode = d_inode(dentry);
10596 + inode_lock(inode);
10597 + sb = dentry->d_sb;
10598 + si_noflush_read_lock(sb);
10600 + err = au_do_fsync_dir(file, datasync);
10602 + di_write_lock_child(dentry);
10603 + err = au_do_fsync_dir_no_file(dentry, datasync);
10605 + au_cpup_attr_timesizes(inode);
10606 + di_write_unlock(dentry);
10608 + fi_write_unlock(file);
10610 + si_read_unlock(sb);
10611 + inode_unlock(inode);
10615 +/* ---------------------------------------------------------------------- */
10617 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10620 + struct dentry *dentry;
10621 + struct inode *inode, *h_inode;
10622 + struct super_block *sb;
10624 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10626 + dentry = file->f_path.dentry;
10627 + inode = d_inode(dentry);
10628 + IMustLock(inode);
10630 + sb = dentry->d_sb;
10631 + si_read_lock(sb, AuLock_FLUSH);
10632 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10633 + if (unlikely(err))
10635 + err = au_alive_dir(dentry);
10637 + err = au_vdir_init(file);
10638 + di_downgrade_lock(dentry, AuLock_IR);
10639 + if (unlikely(err))
10642 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10643 + if (!au_test_nfsd()) {
10644 + err = au_vdir_fill_de(file, ctx);
10645 + fsstack_copy_attr_atime(inode, h_inode);
10648 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10649 + * encode_fh() and others.
10651 + atomic_inc(&h_inode->i_count);
10652 + di_read_unlock(dentry, AuLock_IR);
10653 + si_read_unlock(sb);
10654 + err = au_vdir_fill_de(file, ctx);
10655 + fsstack_copy_attr_atime(inode, h_inode);
10656 + fi_write_unlock(file);
10664 + di_read_unlock(dentry, AuLock_IR);
10665 + fi_write_unlock(file);
10667 + si_read_unlock(sb);
10671 +/* ---------------------------------------------------------------------- */
10673 +#define AuTestEmpty_WHONLY 1
10674 +#define AuTestEmpty_CALLED (1 << 1)
10675 +#define AuTestEmpty_SHWH (1 << 2)
10676 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10677 +#define au_fset_testempty(flags, name) \
10678 + do { (flags) |= AuTestEmpty_##name; } while (0)
10679 +#define au_fclr_testempty(flags, name) \
10680 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10682 +#ifndef CONFIG_AUFS_SHWH
10683 +#undef AuTestEmpty_SHWH
10684 +#define AuTestEmpty_SHWH 0
10687 +struct test_empty_arg {
10688 + struct dir_context ctx;
10689 + struct au_nhash *whlist;
10690 + unsigned int flags;
10692 + aufs_bindex_t bindex;
10695 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10696 + int namelen, loff_t offset __maybe_unused, u64 ino,
10697 + unsigned int d_type)
10699 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10701 + char *name = (void *)__name;
10704 + au_fset_testempty(arg->flags, CALLED);
10706 + if (name[0] == '.'
10707 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10708 + goto out; /* success */
10710 + if (namelen <= AUFS_WH_PFX_LEN
10711 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10712 + if (au_ftest_testempty(arg->flags, WHONLY)
10713 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10714 + arg->err = -ENOTEMPTY;
10718 + name += AUFS_WH_PFX_LEN;
10719 + namelen -= AUFS_WH_PFX_LEN;
10720 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10721 + arg->err = au_nhash_append_wh
10722 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10723 + au_ftest_testempty(arg->flags, SHWH));
10727 + AuTraceErr(arg->err);
10731 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10734 + struct file *h_file;
10735 + struct au_branch *br;
10737 + h_file = au_h_open(dentry, arg->bindex,
10738 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10739 + /*file*/NULL, /*force_wr*/0);
10740 + err = PTR_ERR(h_file);
10741 + if (IS_ERR(h_file))
10745 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10746 + && !file_inode(h_file)->i_nlink)
10751 + au_fclr_testempty(arg->flags, CALLED);
10753 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10756 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10760 + br = au_sbr(dentry->d_sb, arg->bindex);
10761 + au_lcnt_dec(&br->br_nfiles);
10766 +struct do_test_empty_args {
10768 + struct dentry *dentry;
10769 + struct test_empty_arg *arg;
10772 +static void call_do_test_empty(void *args)
10774 + struct do_test_empty_args *a = args;
10775 + *a->errp = do_test_empty(a->dentry, a->arg);
10778 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10780 + int err, wkq_err;
10781 + struct dentry *h_dentry;
10782 + struct inode *h_inode;
10784 + h_dentry = au_h_dptr(dentry, arg->bindex);
10785 + h_inode = d_inode(h_dentry);
10786 + /* todo: i_mode changes anytime? */
10787 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10788 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10789 + inode_unlock_shared(h_inode);
10791 + err = do_test_empty(dentry, arg);
10793 + struct do_test_empty_args args = {
10795 + .dentry = dentry,
10798 + unsigned int flags = arg->flags;
10800 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10801 + if (unlikely(wkq_err))
10803 + arg->flags = flags;
10809 +int au_test_empty_lower(struct dentry *dentry)
10812 + unsigned int rdhash;
10813 + aufs_bindex_t bindex, btop, btail;
10814 + struct au_nhash whlist;
10815 + struct test_empty_arg arg = {
10817 + .actor = test_empty_cb
10820 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10822 + SiMustAnyLock(dentry->d_sb);
10824 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10826 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10827 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10828 + if (unlikely(err))
10832 + arg.whlist = &whlist;
10833 + btop = au_dbtop(dentry);
10834 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10835 + au_fset_testempty(arg.flags, SHWH);
10836 + test_empty = do_test_empty;
10837 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10838 + test_empty = sio_test_empty;
10839 + arg.bindex = btop;
10840 + err = test_empty(dentry, &arg);
10841 + if (unlikely(err))
10844 + au_fset_testempty(arg.flags, WHONLY);
10845 + btail = au_dbtaildir(dentry);
10846 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10847 + struct dentry *h_dentry;
10849 + h_dentry = au_h_dptr(dentry, bindex);
10850 + if (h_dentry && d_is_positive(h_dentry)) {
10851 + arg.bindex = bindex;
10852 + err = test_empty(dentry, &arg);
10857 + au_nhash_wh_free(&whlist);
10862 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10865 + struct test_empty_arg arg = {
10867 + .actor = test_empty_cb
10870 + aufs_bindex_t bindex, btail;
10873 + arg.whlist = whlist;
10874 + arg.flags = AuTestEmpty_WHONLY;
10875 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10876 + au_fset_testempty(arg.flags, SHWH);
10877 + btail = au_dbtaildir(dentry);
10878 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10879 + struct dentry *h_dentry;
10881 + h_dentry = au_h_dptr(dentry, bindex);
10882 + if (h_dentry && d_is_positive(h_dentry)) {
10883 + arg.bindex = bindex;
10884 + err = sio_test_empty(dentry, &arg);
10891 +/* ---------------------------------------------------------------------- */
10893 +const struct file_operations aufs_dir_fop = {
10894 + .owner = THIS_MODULE,
10895 + .llseek = default_llseek,
10896 + .read = generic_read_dir,
10897 + .iterate_shared = aufs_iterate_shared,
10898 + .unlocked_ioctl = aufs_ioctl_dir,
10899 +#ifdef CONFIG_COMPAT
10900 + .compat_ioctl = aufs_compat_ioctl_dir,
10902 + .open = aufs_open_dir,
10903 + .release = aufs_release_dir,
10904 + .flush = aufs_flush_dir,
10905 + .fsync = aufs_fsync_dir
10907 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10908 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10909 +++ linux/fs/aufs/dir.h 2019-03-05 12:13:00.139224339 +0100
10911 +/* SPDX-License-Identifier: GPL-2.0 */
10913 + * Copyright (C) 2005-2019 Junjiro R. Okajima
10915 + * This program, aufs is free software; you can redistribute it and/or modify
10916 + * it under the terms of the GNU General Public License as published by
10917 + * the Free Software Foundation; either version 2 of the License, or
10918 + * (at your option) any later version.
10920 + * This program is distributed in the hope that it will be useful,
10921 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10922 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10923 + * GNU General Public License for more details.
10925 + * You should have received a copy of the GNU General Public License
10926 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10930 + * directory operations
10933 +#ifndef __AUFS_DIR_H__
10934 +#define __AUFS_DIR_H__
10938 +#include <linux/fs.h>
10940 +/* ---------------------------------------------------------------------- */
10942 +/* need to be faster and smaller */
10945 + unsigned int nh_num;
10946 + struct hlist_head *nh_head;
10949 +struct au_vdir_destr {
10950 + unsigned char len;
10951 + unsigned char name[0];
10954 +struct au_vdir_dehstr {
10955 + struct hlist_node hash;
10956 + struct au_vdir_destr *str;
10957 + struct rcu_head rcu;
10958 +} ____cacheline_aligned_in_smp;
10960 +struct au_vdir_de {
10962 + unsigned char de_type;
10963 + /* caution: packed */
10964 + struct au_vdir_destr de_str;
10967 +struct au_vdir_wh {
10968 + struct hlist_node wh_hash;
10969 +#ifdef CONFIG_AUFS_SHWH
10971 + aufs_bindex_t wh_bindex;
10972 + unsigned char wh_type;
10974 + aufs_bindex_t wh_bindex;
10976 + /* caution: packed */
10977 + struct au_vdir_destr wh_str;
10980 +union au_vdir_deblk_p {
10981 + unsigned char *deblk;
10982 + struct au_vdir_de *de;
10986 + unsigned char **vd_deblk;
10987 + unsigned long vd_nblk;
10989 + unsigned long ul;
10990 + union au_vdir_deblk_p p;
10994 + unsigned int vd_deblk_sz;
10995 + unsigned long vd_jiffy;
10996 + struct rcu_head rcu;
10997 +} ____cacheline_aligned_in_smp;
10999 +/* ---------------------------------------------------------------------- */
11002 +extern const struct file_operations aufs_dir_fop;
11003 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
11004 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
11005 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
11006 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
11007 +int au_test_empty_lower(struct dentry *dentry);
11008 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
11011 +unsigned int au_rdhash_est(loff_t sz);
11012 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
11013 +void au_nhash_wh_free(struct au_nhash *whlist);
11014 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
11016 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
11017 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
11018 + unsigned int d_type, aufs_bindex_t bindex,
11019 + unsigned char shwh);
11020 +void au_vdir_free(struct au_vdir *vdir);
11021 +int au_vdir_init(struct file *file);
11022 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
11025 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
11027 +#ifdef CONFIG_AUFS_RDU
11029 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
11030 +#ifdef CONFIG_COMPAT
11031 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
11032 + unsigned long arg);
11035 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
11036 + unsigned int cmd, unsigned long arg)
11037 +#ifdef CONFIG_COMPAT
11038 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
11039 + unsigned int cmd, unsigned long arg)
11043 +#endif /* __KERNEL__ */
11044 +#endif /* __AUFS_DIR_H__ */
11045 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
11046 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
11047 +++ linux/fs/aufs/dirren.c 2019-03-05 12:13:00.139224339 +0100
11049 +// SPDX-License-Identifier: GPL-2.0
11051 + * Copyright (C) 2017-2019 Junjiro R. Okajima
11053 + * This program, aufs is free software; you can redistribute it and/or modify
11054 + * it under the terms of the GNU General Public License as published by
11055 + * the Free Software Foundation; either version 2 of the License, or
11056 + * (at your option) any later version.
11058 + * This program is distributed in the hope that it will be useful,
11059 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11060 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11061 + * GNU General Public License for more details.
11063 + * You should have received a copy of the GNU General Public License
11064 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11068 + * special handling in renaming a directory
11069 + * in order to support looking-up the before-renamed name on the lower readonly
11073 +#include <linux/byteorder/generic.h>
11076 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
11080 + idx = au_dr_ihash(ent->dr_h_ino);
11081 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
11084 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
11087 + struct hlist_bl_head *hbl;
11090 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
11091 + hbl = dr->dr_h_ino + i;
11092 + hlist_bl_lock(hbl);
11093 + ret &= hlist_bl_empty(hbl);
11094 + hlist_bl_unlock(hbl);
11100 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
11102 + struct au_dr_hino *found, *ent;
11103 + struct hlist_bl_head *hbl;
11104 + struct hlist_bl_node *pos;
11108 + idx = au_dr_ihash(ino);
11109 + hbl = dr->dr_h_ino + idx;
11110 + hlist_bl_lock(hbl);
11111 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11112 + if (ent->dr_h_ino == ino) {
11116 + hlist_bl_unlock(hbl);
11121 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
11122 + struct au_dr_hino *add_ent)
11125 + struct hlist_bl_head *hbl;
11126 + struct hlist_bl_node *pos;
11127 + struct au_dr_hino *ent;
11130 + idx = au_dr_ihash(ino);
11131 + hbl = dr->dr_h_ino + idx;
11134 + struct hlist_bl_node *tmp;
11136 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11137 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
11140 + hlist_bl_lock(hbl);
11141 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11142 + if (ent->dr_h_ino == ino) {
11146 + if (!found && add_ent)
11147 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
11148 + hlist_bl_unlock(hbl);
11150 + if (!found && add_ent)
11151 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
11156 +void au_dr_hino_free(struct au_dr_br *dr)
11159 + struct hlist_bl_head *hbl;
11160 + struct hlist_bl_node *pos, *tmp;
11161 + struct au_dr_hino *ent;
11163 + /* SiMustWriteLock(sb); */
11165 + for (i = 0; i < AuDirren_NHASH; i++) {
11166 + hbl = dr->dr_h_ino + i;
11167 + /* no spinlock since sbinfo must be write-locked */
11168 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11169 + au_kfree_rcu(ent);
11170 + INIT_HLIST_BL_HEAD(hbl);
11174 +/* returns the number of inodes or an error */
11175 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11176 + struct file *hinofile)
11180 + loff_t pos, oldsize;
11182 + struct inode *hinoinode;
11183 + struct hlist_bl_head *hbl;
11184 + struct hlist_bl_node *n1, *n2;
11185 + struct au_dr_hino *ent;
11187 + SiMustWriteLock(sb);
11188 + AuDebugOn(!au_br_writable(br->br_perm));
11190 + hinoinode = file_inode(hinofile);
11191 + oldsize = i_size_read(hinoinode);
11195 + hbl = br->br_dirren.dr_h_ino;
11196 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11197 + /* no bit-lock since sbinfo must be write-locked */
11198 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11199 + AuDbg("hi%llu, %pD2\n",
11200 + (unsigned long long)ent->dr_h_ino, hinofile);
11201 + u64 = cpu_to_be64(ent->dr_h_ino);
11202 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11203 + if (ssz == sizeof(u64))
11206 + /* write error */
11207 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11214 + /* regardless the error */
11215 + if (pos < oldsize) {
11216 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11224 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11231 + struct au_dr_hino *ent;
11232 + struct inode *hinoinode;
11233 + struct hlist_bl_head *hbl;
11237 + hbl = dr->dr_h_ino;
11238 + hinoinode = file_inode(hinofile);
11239 + sz = i_size_read(hinoinode);
11240 + AuDebugOn(sz % sizeof(u64));
11241 + n = sz / sizeof(u64);
11243 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11244 + if (unlikely(ssz != sizeof(u64))) {
11245 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11252 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11258 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11259 + AuDbg("hi%llu, %pD2\n",
11260 + (unsigned long long)ent->dr_h_ino, hinofile);
11261 + hidx = au_dr_ihash(ent->dr_h_ino);
11262 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11264 + goto out; /* success */
11267 + au_dr_hino_free(dr);
11274 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11275 + * @path is a switch to distinguish load and store.
11277 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11278 + struct au_branch *br, const struct path *path)
11281 + unsigned char load, suspend;
11282 + struct file *hinofile;
11283 + struct au_hinode *hdir;
11284 + struct inode *dir, *delegated;
11285 + struct path hinopath;
11286 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11287 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11289 + AuDebugOn(bindex < 0 && !br);
11290 + AuDebugOn(bindex >= 0 && br);
11295 + br = au_sbr(sb, bindex);
11298 + path = &br->br_path;
11299 + AuDebugOn(!au_br_writable(br->br_perm));
11300 + if (unlikely(!au_br_writable(br->br_perm)))
11306 + dir = d_inode(sb->s_root);
11307 + hdir = au_hinode(au_ii(dir), bindex);
11308 + dir = hdir->hi_inode;
11309 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11311 + dir = d_inode(path->dentry);
11312 + inode_lock_nested(dir, AuLsc_I_CHILD);
11314 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11315 + err = PTR_ERR(hinopath.dentry);
11316 + if (IS_ERR(hinopath.dentry))
11320 + flags = O_RDONLY;
11322 + if (d_is_negative(hinopath.dentry))
11323 + goto out_dput; /* success */
11325 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11326 + if (d_is_positive(hinopath.dentry)) {
11327 + delegated = NULL;
11328 + err = vfsub_unlink(dir, &hinopath, &delegated,
11331 + if (unlikely(err))
11332 + pr_err("ignored err %d, %pd2\n",
11333 + err, hinopath.dentry);
11334 + if (unlikely(err == -EWOULDBLOCK))
11339 + } else if (!d_is_positive(hinopath.dentry)) {
11340 + err = vfsub_create(dir, &hinopath, 0600,
11341 + /*want_excl*/false);
11343 + if (unlikely(err))
11346 + flags = O_WRONLY;
11348 + hinopath.mnt = path->mnt;
11349 + hinofile = vfsub_dentry_open(&hinopath, flags);
11351 + au_hn_inode_unlock(hdir);
11353 + inode_unlock(dir);
11354 + dput(hinopath.dentry);
11355 + AuTraceErrPtr(hinofile);
11356 + if (IS_ERR(hinofile)) {
11357 + err = PTR_ERR(hinofile);
11362 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11364 + err = au_dr_hino_store(sb, br, hinofile);
11369 + dput(hinopath.dentry);
11372 + au_hn_inode_unlock(hdir);
11374 + inode_unlock(dir);
11380 +/* ---------------------------------------------------------------------- */
11382 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11385 + struct kstatfs kstfs;
11387 + struct dentry *dentry;
11388 + struct super_block *sb;
11390 + err = vfs_statfs((void *)path, &kstfs);
11392 + if (unlikely(err))
11395 + /* todo: support for UUID */
11397 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11398 + brid->type = AuBrid_FSID;
11399 + brid->fsid = kstfs.f_fsid;
11401 + dentry = path->dentry;
11402 + sb = dentry->d_sb;
11405 + brid->type = AuBrid_DEV;
11414 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11415 + const struct path *path)
11418 + struct au_dr_br *dr;
11419 + struct hlist_bl_head *hbl;
11421 + dr = &br->br_dirren;
11422 + hbl = dr->dr_h_ino;
11423 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11424 + INIT_HLIST_BL_HEAD(hbl);
11426 + err = au_dr_brid_init(&dr->dr_brid, path);
11427 + if (unlikely(err))
11430 + if (au_opt_test(au_mntflags(sb), DIRREN))
11431 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11438 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11443 + if (au_br_writable(br->br_perm))
11444 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11446 + au_dr_hino_free(&br->br_dirren);
11451 +/* ---------------------------------------------------------------------- */
11453 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11454 + char *buf, size_t sz)
11457 + unsigned int major, minor;
11461 + err = snprintf(p, sz, "%d_", brid->type);
11462 + AuDebugOn(err > sz);
11465 + switch (brid->type) {
11466 + case AuBrid_Unset:
11468 + case AuBrid_UUID:
11469 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11471 + case AuBrid_FSID:
11472 + err = snprintf(p, sz, "%08x-%08x",
11473 + brid->fsid.val[0], brid->fsid.val[1]);
11476 + major = MAJOR(brid->dev);
11477 + minor = MINOR(brid->dev);
11478 + if (major <= 0xff && minor <= 0xff)
11479 + err = snprintf(p, sz, "%02x%02x", major, minor);
11481 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11484 + AuDebugOn(err > sz);
11487 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11488 + AuDebugOn(err > sz);
11495 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11498 + struct dentry *br_dentry;
11499 + struct inode *br_inode;
11501 + br_dentry = au_br_dentry(br);
11502 + br_inode = d_inode(br_dentry);
11503 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11504 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11505 + AuDebugOn(rlen > len);
11510 +/* ---------------------------------------------------------------------- */
11513 + * from the given @h_dentry, construct drinfo at @*fdata.
11514 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11517 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11518 + struct dentry *h_dentry,
11519 + unsigned char *allocated)
11522 + struct au_drinfo_fdata *f, *p;
11523 + struct au_drinfo *drinfo;
11524 + struct inode *h_inode;
11525 + struct qstr *qname;
11529 + h_inode = d_inode(h_dentry);
11530 + qname = &h_dentry->d_name;
11531 + drinfo = &f->drinfo;
11532 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11533 + drinfo->oldnamelen = qname->len;
11534 + if (*allocated < sizeof(*f) + qname->len) {
11535 + v = roundup_pow_of_two(*allocated + qname->len);
11536 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11537 + if (unlikely(!p)) {
11545 + drinfo = &f->drinfo;
11547 + memcpy(drinfo->oldname, qname->name, qname->len);
11548 + AuDbg("i%llu, %.*s\n",
11549 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11550 + drinfo->oldname);
11557 +/* callers have to free the return value */
11558 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11560 + struct au_drinfo *ret, *drinfo;
11561 + struct au_drinfo_fdata fdata;
11566 + ret = ERR_PTR(-EIO);
11568 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11569 + if (unlikely(ssz != sizeof(fdata))) {
11570 + AuIOErr("ssz %zd, %u, %pD2\n",
11571 + ssz, (unsigned int)sizeof(fdata), file);
11575 + fdata.magic = ntohl((__force __be32)fdata.magic);
11576 + switch (fdata.magic) {
11577 + case AUFS_DRINFO_MAGIC_V1:
11580 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11581 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11585 + drinfo = &fdata.drinfo;
11586 + len = drinfo->oldnamelen;
11588 + AuIOErr("broken drinfo %pD2\n", file);
11593 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11594 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11595 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11596 + (unsigned long long)drinfo->ino,
11597 + (unsigned long long)h_ino, file);
11598 + goto out; /* success */
11601 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11602 + if (unlikely(!ret)) {
11603 + ret = ERR_PTR(-ENOMEM);
11604 + AuTraceErrPtr(ret);
11609 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11610 + if (unlikely(ssz != len)) {
11611 + au_kfree_rcu(ret);
11612 + ret = ERR_PTR(-EIO);
11613 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11617 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11623 +/* ---------------------------------------------------------------------- */
11625 +/* in order to be revertible */
11626 +struct au_drinfo_rev_elm {
11628 + struct dentry *info_dentry;
11629 + struct au_drinfo *info_last;
11632 +struct au_drinfo_rev {
11633 + unsigned char already;
11634 + aufs_bindex_t nelm;
11635 + struct au_drinfo_rev_elm elm[0];
11638 +/* todo: isn't it too large? */
11639 +struct au_drinfo_store {
11640 + struct path h_ppath;
11641 + struct dentry *h_dentry;
11642 + struct au_drinfo_fdata *fdata;
11643 + char *infoname; /* inside of whname, just after PFX */
11644 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11645 + aufs_bindex_t btgt, btail;
11646 + unsigned char no_sio,
11647 + allocated, /* current size of *fdata */
11648 + infonamelen, /* room size for p */
11649 + whnamelen, /* length of the generated name */
11650 + renameback; /* renamed back */
11653 +/* on rename(2) error, the caller should revert it using @elm */
11654 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11655 + struct au_drinfo_rev_elm *elm)
11660 + struct path infopath = {
11661 + .mnt = w->h_ppath.mnt
11663 + struct inode *h_dir, *h_inode, *delegated;
11664 + struct file *infofile;
11665 + struct qstr *qname;
11668 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11670 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11672 + AuTraceErrPtr(infopath.dentry);
11673 + if (IS_ERR(infopath.dentry)) {
11674 + err = PTR_ERR(infopath.dentry);
11679 + h_dir = d_inode(w->h_ppath.dentry);
11680 + if (elm && d_is_negative(infopath.dentry)) {
11681 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11683 + if (unlikely(err))
11685 + elm->created = 1;
11686 + elm->info_dentry = dget(infopath.dentry);
11689 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11690 + AuTraceErrPtr(infofile);
11691 + if (IS_ERR(infofile)) {
11692 + err = PTR_ERR(infofile);
11696 + h_inode = d_inode(infopath.dentry);
11697 + if (elm && i_size_read(h_inode)) {
11698 + h_inode = d_inode(w->h_dentry);
11699 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11700 + AuTraceErrPtr(elm->info_last);
11701 + if (IS_ERR(elm->info_last)) {
11702 + err = PTR_ERR(elm->info_last);
11703 + elm->info_last = NULL;
11704 + AuDebugOn(elm->info_dentry);
11709 + if (elm && w->renameback) {
11710 + delegated = NULL;
11711 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11713 + if (unlikely(err == -EWOULDBLOCK))
11719 + qname = &w->h_dentry->d_name;
11720 + len = sizeof(*w->fdata) + qname->len;
11722 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11723 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11724 + if (ssz == len) {
11725 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11726 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11727 + goto out_fput; /* success */
11732 + /* the caller should revert it using @elm */
11738 + dput(infopath.dentry);
11744 +struct au_call_drinfo_do_store_args {
11746 + struct au_drinfo_store *w;
11747 + struct au_drinfo_rev_elm *elm;
11750 +static void au_call_drinfo_do_store(void *args)
11752 + struct au_call_drinfo_do_store_args *a = args;
11754 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11757 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11758 + struct au_drinfo_rev_elm *elm)
11760 + int err, wkq_err;
11763 + err = au_drinfo_do_store(w, elm);
11765 + struct au_call_drinfo_do_store_args a = {
11770 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11771 + if (unlikely(wkq_err))
11779 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11780 + aufs_bindex_t btgt)
11784 + memset(w, 0, sizeof(*w));
11785 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11786 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11787 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11788 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11790 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11793 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11794 + if (unlikely(!w->fdata)) {
11798 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11805 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11807 + au_kfree_rcu(w->fdata);
11810 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11811 + struct au_drinfo_store *w)
11813 + struct au_drinfo_rev_elm *elm;
11814 + struct inode *h_dir, *delegated;
11816 + struct path infopath = {
11817 + .mnt = w->h_ppath.mnt
11820 + h_dir = d_inode(w->h_ppath.dentry);
11821 + IMustLock(h_dir);
11825 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11826 + AuDebugOn(elm->created && elm->info_last);
11827 + if (elm->created) {
11829 + delegated = NULL;
11830 + infopath.dentry = elm->info_dentry;
11831 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11834 + if (unlikely(err == -EWOULDBLOCK))
11836 + dput(elm->info_dentry);
11837 + } else if (elm->info_last) {
11839 + w->fdata->drinfo = *elm->info_last;
11840 + memcpy(w->fdata->drinfo.oldname,
11841 + elm->info_last->oldname,
11842 + elm->info_last->oldnamelen);
11843 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11844 + au_kfree_rcu(elm->info_last);
11846 + if (unlikely(err))
11847 + AuIOErr("%d, %s\n", err, w->whname);
11848 + /* go on even if err */
11852 +/* caller has to call au_dr_rename_fin() later */
11853 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11854 + struct qstr *dst_name, void *_rev)
11856 + int err, sz, nelm;
11857 + aufs_bindex_t bindex, btail;
11858 + struct au_drinfo_store work;
11859 + struct au_drinfo_rev *rev, **p;
11860 + struct au_drinfo_rev_elm *elm;
11861 + struct super_block *sb;
11862 + struct au_branch *br;
11863 + struct au_hinode *hdir;
11865 + err = au_drinfo_store_work_init(&work, btgt);
11867 + if (unlikely(err))
11871 + btail = au_dbtaildir(dentry);
11872 + nelm = btail - btgt;
11873 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11874 + rev = kcalloc(1, sz, GFP_NOFS);
11875 + if (unlikely(!rev)) {
11879 + rev->nelm = nelm;
11885 + sb = dentry->d_sb;
11886 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11887 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11888 + hdir = au_hi(d_inode(dentry), btgt);
11889 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11890 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11891 + work.h_dentry = au_h_dptr(dentry, bindex);
11892 + if (!work.h_dentry)
11895 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11896 + &work.allocated);
11898 + if (unlikely(err))
11901 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11902 + br = au_sbr(sb, bindex);
11903 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11904 + work.whnamelen += au_drinfo_name(br, work.infoname,
11905 + work.infonamelen);
11906 + AuDbg("whname %.*s, i%llu, %.*s\n",
11907 + work.whnamelen, work.whname,
11908 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11909 + work.fdata->drinfo.oldnamelen,
11910 + work.fdata->drinfo.oldname);
11912 + err = au_drinfo_store_sio(&work, elm);
11914 + if (unlikely(err))
11917 + if (unlikely(err)) {
11918 + /* revert all drinfo */
11919 + au_drinfo_store_rev(rev, &work);
11920 + au_kfree_try_rcu(rev);
11923 + au_hn_inode_unlock(hdir);
11926 + au_drinfo_store_work_fin(&work);
11931 +/* ---------------------------------------------------------------------- */
11933 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11934 + struct qstr *dst_name, void *_rev)
11936 + int err, already;
11938 + struct super_block *sb;
11939 + struct au_branch *br;
11940 + struct au_dr_br *dr;
11941 + struct dentry *h_dentry;
11942 + struct inode *h_inode;
11943 + struct au_dr_hino *ent;
11944 + struct au_drinfo_rev *rev, **p;
11946 + AuDbg("bindex %d\n", bindex);
11949 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11950 + if (unlikely(!ent))
11954 + br = au_sbr(sb, bindex);
11955 + dr = &br->br_dirren;
11956 + h_dentry = au_h_dptr(src, bindex);
11957 + h_inode = d_inode(h_dentry);
11958 + ino = h_inode->i_ino;
11959 + ent->dr_h_ino = ino;
11960 + already = au_dr_hino_test_add(dr, ino, ent);
11961 + AuDbg("b%d, hi%llu, already %d\n",
11962 + bindex, (unsigned long long)ino, already);
11964 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11969 + rev->already = already;
11970 + goto out; /* success */
11975 + au_dr_hino_del(dr, ent);
11976 + au_kfree_rcu(ent);
11983 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11985 + struct au_drinfo_rev *rev;
11986 + struct au_drinfo_rev_elm *elm;
11991 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11992 + dput(elm->info_dentry);
11993 + au_kfree_rcu(elm->info_last);
11995 + au_kfree_try_rcu(rev);
11998 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
12001 + struct au_drinfo_store work;
12002 + struct au_drinfo_rev *rev = _rev;
12003 + struct super_block *sb;
12004 + struct au_branch *br;
12005 + struct inode *h_inode;
12006 + struct au_dr_br *dr;
12007 + struct au_dr_hino *ent;
12009 + err = au_drinfo_store_work_init(&work, btgt);
12010 + if (unlikely(err))
12014 + br = au_sbr(sb, btgt);
12015 + work.h_ppath.dentry = au_h_dptr(src, btgt);
12016 + work.h_ppath.mnt = au_br_mnt(br);
12017 + au_drinfo_store_rev(rev, &work);
12018 + au_drinfo_store_work_fin(&work);
12019 + if (rev->already)
12022 + dr = &br->br_dirren;
12023 + h_inode = d_inode(work.h_ppath.dentry);
12024 + ent = au_dr_hino_find(dr, h_inode->i_ino);
12026 + au_dr_hino_del(dr, ent);
12027 + au_kfree_rcu(ent);
12030 + au_kfree_try_rcu(rev);
12031 + if (unlikely(err))
12032 + pr_err("failed to remove dirren info\n");
12035 +/* ---------------------------------------------------------------------- */
12037 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
12038 + char *whname, int whnamelen,
12039 + struct dentry **info_dentry)
12041 + struct au_drinfo *drinfo;
12043 + struct inode *h_dir;
12044 + struct path infopath;
12047 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
12049 + *info_dentry = NULL;
12052 + h_dir = d_inode(h_ppath->dentry);
12053 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
12054 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
12056 + if (IS_ERR(infopath.dentry)) {
12057 + drinfo = (void *)infopath.dentry;
12061 + if (d_is_negative(infopath.dentry))
12062 + goto out_dput; /* success */
12064 + infopath.mnt = h_ppath->mnt;
12065 + f = vfsub_dentry_open(&infopath, O_RDONLY);
12066 + inode_unlock_shared(h_dir);
12069 + drinfo = (void *)f;
12073 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
12074 + if (IS_ERR_OR_NULL(drinfo))
12077 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
12078 + *info_dentry = dget(infopath.dentry); /* keep it alive */
12083 + dput(infopath.dentry);
12086 + inode_unlock_shared(h_dir);
12087 + AuTraceErrPtr(drinfo);
12091 +struct au_drinfo_do_load_args {
12092 + struct au_drinfo **drinfop;
12093 + struct path *h_ppath;
12096 + struct dentry **info_dentry;
12099 +static void au_call_drinfo_do_load(void *args)
12101 + struct au_drinfo_do_load_args *a = args;
12103 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
12107 +struct au_drinfo_load {
12108 + struct path h_ppath;
12109 + struct qstr *qname;
12110 + unsigned char no_sio;
12112 + aufs_bindex_t ninfo;
12113 + struct au_drinfo **drinfo;
12116 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
12117 + struct au_branch *br)
12119 + int err, wkq_err, whnamelen, e;
12120 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
12121 + = AUFS_WH_DR_INFO_PFX;
12122 + struct au_drinfo *drinfo;
12123 + struct qstr oldname;
12124 + struct inode *h_dir, *delegated;
12125 + struct dentry *info_dentry;
12126 + struct path infopath;
12128 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
12129 + whnamelen += au_drinfo_name(br, whname + whnamelen,
12130 + sizeof(whname) - whnamelen);
12132 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
12135 + struct au_drinfo_do_load_args args = {
12136 + .drinfop = &drinfo,
12137 + .h_ppath = &w->h_ppath,
12138 + .whname = whname,
12139 + .whnamelen = whnamelen,
12140 + .info_dentry = &info_dentry
12142 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
12143 + if (unlikely(wkq_err))
12144 + drinfo = ERR_PTR(wkq_err);
12146 + err = PTR_ERR(drinfo);
12147 + if (IS_ERR_OR_NULL(drinfo))
12151 + oldname.len = drinfo->oldnamelen;
12152 + oldname.name = drinfo->oldname;
12153 + if (au_qstreq(w->qname, &oldname)) {
12154 + /* the name is renamed back */
12155 + au_kfree_rcu(drinfo);
12158 + infopath.dentry = info_dentry;
12159 + infopath.mnt = w->h_ppath.mnt;
12160 + h_dir = d_inode(w->h_ppath.dentry);
12161 + delegated = NULL;
12162 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
12163 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
12164 + inode_unlock(h_dir);
12166 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
12167 + if (unlikely(e == -EWOULDBLOCK))
12170 + au_kfree_rcu(w->drinfo[bindex]);
12171 + w->drinfo[bindex] = drinfo;
12172 + dput(info_dentry);
12179 +/* ---------------------------------------------------------------------- */
12181 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12183 + struct au_drinfo **p = drinfo;
12186 + au_kfree_rcu(*drinfo++);
12187 + au_kfree_try_rcu(p);
12190 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12191 + aufs_bindex_t btgt)
12194 + struct au_drinfo_load w;
12195 + aufs_bindex_t bindex, bbot;
12196 + struct au_branch *br;
12197 + struct inode *h_dir;
12198 + struct au_dr_hino *ent;
12199 + struct super_block *sb;
12201 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12202 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12203 + AuLNPair(&lkup->whname), btgt);
12205 + sb = dentry->d_sb;
12206 + bbot = au_sbbot(sb);
12207 + w.ninfo = bbot + 1;
12208 + if (!lkup->dirren.drinfo) {
12209 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12210 + sizeof(*lkup->dirren.drinfo),
12212 + if (unlikely(!lkup->dirren.drinfo)) {
12216 + lkup->dirren.ninfo = w.ninfo;
12218 + w.drinfo = lkup->dirren.drinfo;
12219 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12220 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12221 + AuDebugOn(!w.h_ppath.dentry);
12222 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12223 + w.qname = &dentry->d_name;
12226 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12227 + br = au_sbr(sb, bindex);
12228 + err = au_drinfo_load(&w, bindex, br);
12229 + if (unlikely(err))
12231 + if (w.drinfo[bindex])
12235 + br = au_sbr(sb, btgt);
12236 + h_dir = d_inode(w.h_ppath.dentry);
12237 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12239 + au_dr_hino_del(&br->br_dirren, ent);
12240 + au_kfree_rcu(ent);
12242 + goto out; /* success */
12245 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12246 + lkup->dirren.ninfo = 0;
12247 + lkup->dirren.drinfo = NULL;
12253 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12255 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12258 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12261 + struct au_drinfo *drinfo;
12264 + if (!lkup->dirren.drinfo)
12266 + AuDebugOn(lkup->dirren.ninfo < btgt + 1);
12267 + drinfo = lkup->dirren.drinfo[btgt + 1];
12271 + au_kfree_try_rcu(lkup->whname.name);
12272 + lkup->whname.name = NULL;
12273 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12274 + lkup->dirren.dr_name.name = drinfo->oldname;
12275 + lkup->name = &lkup->dirren.dr_name;
12276 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12278 + AuDbg("name %.*s, whname %.*s, b%d\n",
12279 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12287 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12291 + struct au_drinfo *drinfo;
12294 + if (!lkup->dirren.drinfo)
12296 + AuDebugOn(lkup->dirren.ninfo < bindex + 1);
12297 + drinfo = lkup->dirren.drinfo[bindex + 1];
12301 + match = (drinfo->ino == h_ino);
12302 + AuDbg("match %d\n", match);
12308 +/* ---------------------------------------------------------------------- */
12310 +int au_dr_opt_set(struct super_block *sb)
12313 + aufs_bindex_t bindex, bbot;
12314 + struct au_branch *br;
12317 + bbot = au_sbbot(sb);
12318 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12319 + br = au_sbr(sb, bindex);
12320 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12326 +int au_dr_opt_flush(struct super_block *sb)
12329 + aufs_bindex_t bindex, bbot;
12330 + struct au_branch *br;
12333 + bbot = au_sbbot(sb);
12334 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12335 + br = au_sbr(sb, bindex);
12336 + if (au_br_writable(br->br_perm))
12337 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12343 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12346 + aufs_bindex_t bindex, bbot;
12347 + struct au_branch *br;
12351 + err = au_dr_opt_flush(sb);
12352 + if (unlikely(err))
12356 + bbot = au_sbbot(sb);
12357 + for (bindex = 0; bindex <= bbot; bindex++) {
12358 + br = au_sbr(sb, bindex);
12359 + au_dr_hino_free(&br->br_dirren);
12365 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12366 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12367 +++ linux/fs/aufs/dirren.h 2019-03-05 12:13:00.139224339 +0100
12369 +/* SPDX-License-Identifier: GPL-2.0 */
12371 + * Copyright (C) 2017-2019 Junjiro R. Okajima
12373 + * This program, aufs is free software; you can redistribute it and/or modify
12374 + * it under the terms of the GNU General Public License as published by
12375 + * the Free Software Foundation; either version 2 of the License, or
12376 + * (at your option) any later version.
12378 + * This program is distributed in the hope that it will be useful,
12379 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12380 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12381 + * GNU General Public License for more details.
12383 + * You should have received a copy of the GNU General Public License
12384 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12388 + * renamed dir info
12391 +#ifndef __AUFS_DIRREN_H__
12392 +#define __AUFS_DIRREN_H__
12396 +#include <linux/dcache.h>
12397 +#include <linux/statfs.h>
12398 +#include <linux/uuid.h>
12401 +#define AuDirren_NHASH 100
12403 +#ifdef CONFIG_AUFS_DIRREN
12404 +enum au_brid_type {
12411 +struct au_dr_brid {
12412 + enum au_brid_type type;
12414 + uuid_t uuid; /* unimplemented yet */
12420 +/* 20 is the max digits length of ulong 64 */
12421 +/* brid-type "_" uuid "_" inum */
12422 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12423 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12425 +struct au_dr_hino {
12426 + struct hlist_bl_node dr_hnode;
12431 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12432 + struct au_dr_brid dr_brid;
12435 +struct au_dr_lookup {
12436 + /* dr_name is pointed by struct au_do_lookup_args.name */
12437 + struct qstr dr_name; /* subset of dr_info */
12438 + aufs_bindex_t ninfo;
12439 + struct au_drinfo **drinfo;
12442 +struct au_dr_hino;
12444 +struct au_dr_br { };
12445 +struct au_dr_lookup { };
12448 +/* ---------------------------------------------------------------------- */
12451 +struct au_do_lookup_args;
12453 +#ifdef CONFIG_AUFS_DIRREN
12454 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12455 + struct au_dr_hino *add_ent);
12456 +void au_dr_hino_free(struct au_dr_br *dr);
12457 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12458 + const struct path *path);
12459 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12460 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12461 + struct qstr *dst_name, void *_rev);
12462 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12463 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12464 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12465 + aufs_bindex_t bindex);
12466 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12467 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12469 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12470 +int au_dr_opt_set(struct super_block *sb);
12471 +int au_dr_opt_flush(struct super_block *sb);
12472 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12474 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12475 + struct au_dr_hino *add_ent);
12476 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12477 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12478 + const struct path *path);
12479 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12480 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12481 + struct qstr *dst_name, void *_rev);
12482 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12483 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12485 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12486 + aufs_bindex_t bindex);
12487 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12488 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12489 + aufs_bindex_t bindex, ino_t h_ino);
12490 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12491 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12492 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12493 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12496 +/* ---------------------------------------------------------------------- */
12498 +#ifdef CONFIG_AUFS_DIRREN
12499 +static inline int au_dr_ihash(ino_t h_ino)
12501 + return h_ino % AuDirren_NHASH;
12504 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12507 +#endif /* __KERNEL__ */
12508 +#endif /* __AUFS_DIRREN_H__ */
12509 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12510 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12511 +++ linux/fs/aufs/dynop.c 2019-03-05 12:13:00.139224339 +0100
12513 +// SPDX-License-Identifier: GPL-2.0
12515 + * Copyright (C) 2010-2019 Junjiro R. Okajima
12517 + * This program, aufs is free software; you can redistribute it and/or modify
12518 + * it under the terms of the GNU General Public License as published by
12519 + * the Free Software Foundation; either version 2 of the License, or
12520 + * (at your option) any later version.
12522 + * This program is distributed in the hope that it will be useful,
12523 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12524 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12525 + * GNU General Public License for more details.
12527 + * You should have received a copy of the GNU General Public License
12528 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12532 + * dynamically customizable operations for regular files
12537 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12540 + * How large will these lists be?
12541 + * Usually just a few elements, 20-30 at most for each, I guess.
12543 +static struct hlist_bl_head dynop[AuDyLast];
12545 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12546 + const void *h_op)
12548 + struct au_dykey *key, *tmp;
12549 + struct hlist_bl_node *pos;
12552 + hlist_bl_lock(hbl);
12553 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12554 + if (tmp->dk_op.dy_hop == h_op) {
12556 + kref_get(&key->dk_kref);
12559 + hlist_bl_unlock(hbl);
12564 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12566 + struct au_dykey **k, *found;
12567 + const void *h_op = key->dk_op.dy_hop;
12571 + k = br->br_dykey;
12572 + for (i = 0; i < AuBrDynOp; i++)
12574 + if (k[i]->dk_op.dy_hop == h_op) {
12581 + spin_lock(&br->br_dykey_lock);
12582 + for (; i < AuBrDynOp; i++)
12584 + if (k[i]->dk_op.dy_hop == h_op) {
12592 + spin_unlock(&br->br_dykey_lock);
12593 + BUG_ON(i == AuBrDynOp); /* expand the array */
12599 +/* kref_get() if @key is already added */
12600 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12602 + struct au_dykey *tmp, *found;
12603 + struct hlist_bl_node *pos;
12604 + const void *h_op = key->dk_op.dy_hop;
12607 + hlist_bl_lock(hbl);
12608 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12609 + if (tmp->dk_op.dy_hop == h_op) {
12610 + kref_get(&tmp->dk_kref);
12615 + hlist_bl_add_head(&key->dk_hnode, hbl);
12616 + hlist_bl_unlock(hbl);
12623 +static void dy_free_rcu(struct rcu_head *rcu)
12625 + struct au_dykey *key;
12627 + key = container_of(rcu, struct au_dykey, dk_rcu);
12629 + au_kfree_rcu(key);
12632 +static void dy_free(struct kref *kref)
12634 + struct au_dykey *key;
12635 + struct hlist_bl_head *hbl;
12637 + key = container_of(kref, struct au_dykey, dk_kref);
12638 + hbl = dynop + key->dk_op.dy_type;
12639 + au_hbl_del(&key->dk_hnode, hbl);
12640 + call_rcu(&key->dk_rcu, dy_free_rcu);
12643 +void au_dy_put(struct au_dykey *key)
12645 + kref_put(&key->dk_kref, dy_free);
12648 +/* ---------------------------------------------------------------------- */
12650 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12652 +#ifdef CONFIG_AUFS_DEBUG
12653 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12654 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12656 +#define DyDbgDeclare(cnt) do {} while (0)
12657 +#define DyDbgInc(cnt) do {} while (0)
12660 +#define DySet(func, dst, src, h_op, h_sb) do { \
12662 + if (h_op->func) { \
12664 + dst.func = src.func; \
12666 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12670 +#define DySetForce(func, dst, src) do { \
12671 + AuDebugOn(!src.func); \
12673 + dst.func = src.func; \
12676 +#define DySetAop(func) \
12677 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12678 +#define DySetAopForce(func) \
12679 + DySetForce(func, dyaop->da_op, aufs_aop)
12681 +static void dy_aop(struct au_dykey *key, const void *h_op,
12682 + struct super_block *h_sb __maybe_unused)
12684 + struct au_dyaop *dyaop = (void *)key;
12685 + const struct address_space_operations *h_aop = h_op;
12686 + DyDbgDeclare(cnt);
12688 + AuDbg("%s\n", au_sbtype(h_sb));
12690 + DySetAop(writepage);
12691 + DySetAopForce(readpage); /* force */
12692 + DySetAop(writepages);
12693 + DySetAop(set_page_dirty);
12694 + DySetAop(readpages);
12695 + DySetAop(write_begin);
12696 + DySetAop(write_end);
12698 + DySetAop(invalidatepage);
12699 + DySetAop(releasepage);
12700 + DySetAop(freepage);
12701 + /* this one will be changed according to an aufs mount option */
12702 + DySetAop(direct_IO);
12703 + DySetAop(migratepage);
12704 + DySetAop(isolate_page);
12705 + DySetAop(putback_page);
12706 + DySetAop(launder_page);
12707 + DySetAop(is_partially_uptodate);
12708 + DySetAop(is_dirty_writeback);
12709 + DySetAop(error_remove_page);
12710 + DySetAop(swap_activate);
12711 + DySetAop(swap_deactivate);
12713 + DyDbgSize(cnt, *h_aop);
12716 +/* ---------------------------------------------------------------------- */
12718 +static void dy_bug(struct kref *kref)
12723 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12725 + struct au_dykey *key, *old;
12726 + struct hlist_bl_head *hbl;
12729 + void (*set)(struct au_dykey *key, const void *h_op,
12730 + struct super_block *h_sb __maybe_unused);
12732 + static const struct op a[] = {
12734 + .sz = sizeof(struct au_dyaop),
12738 + const struct op *p;
12740 + hbl = dynop + op->dy_type;
12741 + key = dy_gfind_get(hbl, op->dy_hop);
12743 + goto out_add; /* success */
12745 + p = a + op->dy_type;
12746 + key = kzalloc(p->sz, GFP_NOFS);
12747 + if (unlikely(!key)) {
12748 + key = ERR_PTR(-ENOMEM);
12752 + key->dk_op.dy_hop = op->dy_hop;
12753 + kref_init(&key->dk_kref);
12754 + p->set(key, op->dy_hop, au_br_sb(br));
12755 + old = dy_gadd(hbl, key);
12757 + au_kfree_rcu(key);
12762 + old = dy_bradd(br, key);
12764 + /* its ref-count should never be zero here */
12765 + kref_put(&key->dk_kref, dy_bug);
12770 +/* ---------------------------------------------------------------------- */
12772 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12773 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12774 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12775 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12776 + * See the aufs manual in detail.
12778 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12781 + dyaop->da_op.direct_IO = NULL;
12783 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12786 +static struct au_dyaop *dy_aget(struct au_branch *br,
12787 + const struct address_space_operations *h_aop,
12790 + struct au_dyaop *dyaop;
12791 + struct au_dynop op;
12793 + op.dy_type = AuDy_AOP;
12794 + op.dy_haop = h_aop;
12795 + dyaop = (void *)dy_get(&op, br);
12796 + if (IS_ERR(dyaop))
12798 + dy_adx(dyaop, do_dx);
12804 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12805 + struct inode *h_inode)
12808 + struct super_block *sb;
12809 + struct au_branch *br;
12810 + struct au_dyaop *dyaop;
12812 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12813 + IiMustWriteLock(inode);
12815 + sb = inode->i_sb;
12816 + br = au_sbr(sb, bindex);
12817 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12818 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12819 + err = PTR_ERR(dyaop);
12820 + if (IS_ERR(dyaop))
12821 + /* unnecessary to call dy_fput() */
12825 + inode->i_mapping->a_ops = &dyaop->da_op;
12832 + * Is it safe to replace a_ops during the inode/file is in operation?
12833 + * Yes, I hope so.
12835 +int au_dy_irefresh(struct inode *inode)
12838 + aufs_bindex_t btop;
12839 + struct inode *h_inode;
12842 + if (S_ISREG(inode->i_mode)) {
12843 + btop = au_ibtop(inode);
12844 + h_inode = au_h_iptr(inode, btop);
12845 + err = au_dy_iaop(inode, btop, h_inode);
12850 +void au_dy_arefresh(int do_dx)
12852 + struct hlist_bl_head *hbl;
12853 + struct hlist_bl_node *pos;
12854 + struct au_dykey *key;
12856 + hbl = dynop + AuDy_AOP;
12857 + hlist_bl_lock(hbl);
12858 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12859 + dy_adx((void *)key, do_dx);
12860 + hlist_bl_unlock(hbl);
12863 +/* ---------------------------------------------------------------------- */
12865 +void __init au_dy_init(void)
12869 + /* make sure that 'struct au_dykey *' can be any type */
12870 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
12872 + for (i = 0; i < AuDyLast; i++)
12873 + INIT_HLIST_BL_HEAD(dynop + i);
12876 +void au_dy_fin(void)
12880 + for (i = 0; i < AuDyLast; i++)
12881 + WARN_ON(!hlist_bl_empty(dynop + i));
12883 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12884 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12885 +++ linux/fs/aufs/dynop.h 2019-03-05 12:13:00.139224339 +0100
12887 +/* SPDX-License-Identifier: GPL-2.0 */
12889 + * Copyright (C) 2010-2019 Junjiro R. Okajima
12891 + * This program, aufs is free software; you can redistribute it and/or modify
12892 + * it under the terms of the GNU General Public License as published by
12893 + * the Free Software Foundation; either version 2 of the License, or
12894 + * (at your option) any later version.
12896 + * This program is distributed in the hope that it will be useful,
12897 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12898 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12899 + * GNU General Public License for more details.
12901 + * You should have received a copy of the GNU General Public License
12902 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12906 + * dynamically customizable operations (for regular files only)
12909 +#ifndef __AUFS_DYNOP_H__
12910 +#define __AUFS_DYNOP_H__
12914 +#include <linux/fs.h>
12915 +#include <linux/kref.h>
12917 +enum {AuDy_AOP, AuDyLast};
12922 + const void *dy_hop;
12923 + const struct address_space_operations *dy_haop;
12929 + struct hlist_bl_node dk_hnode;
12930 + struct rcu_head dk_rcu;
12932 + struct au_dynop dk_op;
12935 + * during I am in the branch local array, kref is gotten. when the
12936 + * branch is removed, kref is put.
12938 + struct kref dk_kref;
12941 +/* stop unioning since their sizes are very different from each other */
12943 + struct au_dykey da_key;
12944 + struct address_space_operations da_op; /* not const */
12947 +/* ---------------------------------------------------------------------- */
12951 +void au_dy_put(struct au_dykey *key);
12952 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12953 + struct inode *h_inode);
12954 +int au_dy_irefresh(struct inode *inode);
12955 +void au_dy_arefresh(int do_dio);
12957 +void __init au_dy_init(void);
12958 +void au_dy_fin(void);
12960 +#endif /* __KERNEL__ */
12961 +#endif /* __AUFS_DYNOP_H__ */
12962 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12963 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12964 +++ linux/fs/aufs/export.c 2019-03-05 12:13:00.139224339 +0100
12966 +// SPDX-License-Identifier: GPL-2.0
12968 + * Copyright (C) 2005-2019 Junjiro R. Okajima
12970 + * This program, aufs is free software; you can redistribute it and/or modify
12971 + * it under the terms of the GNU General Public License as published by
12972 + * the Free Software Foundation; either version 2 of the License, or
12973 + * (at your option) any later version.
12975 + * This program is distributed in the hope that it will be useful,
12976 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12977 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12978 + * GNU General Public License for more details.
12980 + * You should have received a copy of the GNU General Public License
12981 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12988 +#include <linux/exportfs.h>
12989 +#include <linux/fs_struct.h>
12990 +#include <linux/namei.h>
12991 +#include <linux/nsproxy.h>
12992 +#include <linux/random.h>
12993 +#include <linux/writeback.h>
12997 +#ifdef CONFIG_AUFS_INO_T_64
13005 +static ino_t decode_ino(__u32 *a)
13009 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
13011 +#ifdef CONFIG_AUFS_INO_T_64
13017 +static void encode_ino(__u32 *a, ino_t ino)
13023 +#ifdef CONFIG_AUFS_INO_T_64
13028 +/* NFS file handle */
13032 +#ifdef CONFIG_AUFS_INO_T_64
13033 + /* support 64bit inode number */
13046 + Fh_ino = Fh_ino1,
13047 + Fh_dir_ino = Fh_dir_ino1
13050 +static int au_test_anon(struct dentry *dentry)
13052 + /* note: read d_flags without d_lock */
13053 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
13056 +int au_test_nfsd(void)
13059 + struct task_struct *tsk = current;
13060 + char comm[sizeof(tsk->comm)];
13063 + if (tsk->flags & PF_KTHREAD) {
13064 + get_task_comm(comm, tsk);
13065 + ret = !strcmp(comm, "nfsd");
13071 +/* ---------------------------------------------------------------------- */
13072 +/* inode generation external table */
13074 +void au_xigen_inc(struct inode *inode)
13079 + struct super_block *sb;
13080 + struct au_sbinfo *sbinfo;
13082 + sb = inode->i_sb;
13083 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
13085 + sbinfo = au_sbi(sb);
13086 + pos = inode->i_ino;
13087 + pos *= sizeof(igen);
13088 + igen = inode->i_generation + 1;
13089 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
13090 + sizeof(igen), &pos);
13091 + if (sz == sizeof(igen))
13092 + return; /* success */
13094 + if (unlikely(sz >= 0))
13095 + AuIOErr("xigen error (%zd)\n", sz);
13098 +int au_xigen_new(struct inode *inode)
13103 + struct super_block *sb;
13104 + struct au_sbinfo *sbinfo;
13105 + struct file *file;
13108 + /* todo: dirty, at mount time */
13109 + if (inode->i_ino == AUFS_ROOT_INO)
13111 + sb = inode->i_sb;
13112 + SiMustAnyLock(sb);
13113 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13117 + pos = inode->i_ino;
13118 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
13119 + AuIOErr1("too large i%lld\n", pos);
13122 + pos *= sizeof(inode->i_generation);
13125 + sbinfo = au_sbi(sb);
13126 + file = sbinfo->si_xigen;
13129 + if (vfsub_f_size_read(file)
13130 + < pos + sizeof(inode->i_generation)) {
13131 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
13132 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
13133 + sizeof(inode->i_generation), &pos);
13135 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
13136 + sizeof(inode->i_generation), &pos);
13137 + if (sz == sizeof(inode->i_generation))
13138 + goto out; /* success */
13141 + if (unlikely(sz >= 0)) {
13143 + AuIOErr("xigen error (%zd)\n", sz);
13150 +int au_xigen_set(struct super_block *sb, struct path *path)
13153 + struct au_sbinfo *sbinfo;
13154 + struct file *file;
13156 + SiMustWriteLock(sb);
13158 + sbinfo = au_sbi(sb);
13159 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
13160 + err = PTR_ERR(file);
13161 + if (IS_ERR(file))
13164 + if (sbinfo->si_xigen)
13165 + fput(sbinfo->si_xigen);
13166 + sbinfo->si_xigen = file;
13173 +void au_xigen_clr(struct super_block *sb)
13175 + struct au_sbinfo *sbinfo;
13177 + SiMustWriteLock(sb);
13179 + sbinfo = au_sbi(sb);
13180 + if (sbinfo->si_xigen) {
13181 + fput(sbinfo->si_xigen);
13182 + sbinfo->si_xigen = NULL;
13186 +/* ---------------------------------------------------------------------- */
13188 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13191 + struct dentry *dentry, *d;
13192 + struct inode *inode;
13193 + unsigned int sigen;
13196 + inode = ilookup(sb, ino);
13200 + dentry = ERR_PTR(-ESTALE);
13201 + sigen = au_sigen(sb);
13202 + if (unlikely(au_is_bad_inode(inode)
13203 + || IS_DEADDIR(inode)
13204 + || sigen != au_iigen(inode, NULL)))
13208 + if (!dir_ino || S_ISDIR(inode->i_mode))
13209 + dentry = d_find_alias(inode);
13211 + spin_lock(&inode->i_lock);
13212 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13213 + spin_lock(&d->d_lock);
13214 + if (!au_test_anon(d)
13215 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13216 + dentry = dget_dlock(d);
13217 + spin_unlock(&d->d_lock);
13220 + spin_unlock(&d->d_lock);
13222 + spin_unlock(&inode->i_lock);
13224 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13225 + /* need to refresh */
13233 + AuTraceErrPtr(dentry);
13237 +/* ---------------------------------------------------------------------- */
13239 +/* todo: dirty? */
13240 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13242 +struct au_compare_mnt_args {
13244 + struct super_block *sb;
13247 + struct vfsmount *mnt;
13250 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13252 + struct au_compare_mnt_args *a = arg;
13254 + if (mnt->mnt_sb != a->sb)
13256 + a->mnt = mntget(mnt);
13260 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13263 + struct path root;
13264 + struct au_compare_mnt_args args = {
13268 + get_fs_root(current->fs, &root);
13270 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13271 + rcu_read_unlock();
13274 + AuDebugOn(!args.mnt);
13278 +struct au_nfsd_si_lock {
13279 + unsigned int sigen;
13280 + aufs_bindex_t bindex, br_id;
13281 + unsigned char force_lock;
13284 +static int si_nfsd_read_lock(struct super_block *sb,
13285 + struct au_nfsd_si_lock *nsi_lock)
13288 + aufs_bindex_t bindex;
13290 + si_read_lock(sb, AuLock_FLUSH);
13292 + /* branch id may be wrapped around */
13294 + bindex = au_br_index(sb, nsi_lock->br_id);
13295 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13296 + goto out; /* success */
13300 + if (!nsi_lock->force_lock)
13301 + si_read_unlock(sb);
13304 + nsi_lock->bindex = bindex;
13308 +struct find_name_by_ino {
13309 + struct dir_context ctx;
13310 + int called, found;
13317 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13318 + loff_t offset, u64 ino, unsigned int d_type)
13320 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13324 + if (a->ino != ino)
13327 + memcpy(a->name, name, namelen);
13328 + a->namelen = namelen;
13333 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13334 + struct au_nfsd_si_lock *nsi_lock)
13336 + struct dentry *dentry, *parent;
13337 + struct file *file;
13338 + struct inode *dir;
13339 + struct find_name_by_ino arg = {
13341 + .actor = find_name_by_ino
13346 + parent = path->dentry;
13348 + si_read_unlock(parent->d_sb);
13349 + file = vfsub_dentry_open(path, au_dir_roflags);
13350 + dentry = (void *)file;
13351 + if (IS_ERR(file))
13354 + dentry = ERR_PTR(-ENOMEM);
13355 + arg.name = (void *)__get_free_page(GFP_NOFS);
13356 + if (unlikely(!arg.name))
13363 + err = vfsub_iterate_dir(file, &arg.ctx);
13364 + } while (!err && !arg.found && arg.called);
13365 + dentry = ERR_PTR(err);
13366 + if (unlikely(err))
13368 + /* instead of ENOENT */
13369 + dentry = ERR_PTR(-ESTALE);
13373 + /* do not call vfsub_lkup_one() */
13374 + dir = d_inode(parent);
13375 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13376 + AuTraceErrPtr(dentry);
13377 + if (IS_ERR(dentry))
13379 + AuDebugOn(au_test_anon(dentry));
13380 + if (unlikely(d_really_is_negative(dentry))) {
13382 + dentry = ERR_PTR(-ENOENT);
13386 + free_page((unsigned long)arg.name);
13390 + if (unlikely(nsi_lock
13391 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13392 + if (!IS_ERR(dentry)) {
13394 + dentry = ERR_PTR(-ESTALE);
13396 + AuTraceErrPtr(dentry);
13400 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13402 + struct au_nfsd_si_lock *nsi_lock)
13404 + struct dentry *dentry;
13405 + struct path path;
13407 + if (dir_ino != AUFS_ROOT_INO) {
13408 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13409 + dentry = path.dentry;
13410 + if (!path.dentry || IS_ERR(path.dentry))
13412 + AuDebugOn(au_test_anon(path.dentry));
13414 + path.dentry = dget(sb->s_root);
13416 + path.mnt = au_mnt_get(sb);
13417 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13421 + AuTraceErrPtr(dentry);
13425 +/* ---------------------------------------------------------------------- */
13427 +static int h_acceptable(void *expv, struct dentry *dentry)
13432 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13433 + char *buf, int len, struct super_block *sb)
13437 + struct path path;
13439 + p = d_path(h_rootpath, buf, len);
13444 + path.mnt = h_rootpath->mnt;
13445 + path.dentry = h_parent;
13446 + p = d_path(&path, buf, len);
13452 + path.mnt = au_mnt_get(sb);
13453 + path.dentry = sb->s_root;
13454 + p = d_path(&path, buf, len - strlen(p));
13455 + mntput(path.mnt);
13459 + p[strlen(p)] = '/';
13462 + AuTraceErrPtr(p);
13467 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13468 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13470 + struct dentry *dentry, *h_parent, *root;
13471 + struct super_block *h_sb;
13472 + char *pathname, *p;
13473 + struct vfsmount *h_mnt;
13474 + struct au_branch *br;
13476 + struct path path;
13478 + br = au_sbr(sb, nsi_lock->bindex);
13479 + h_mnt = au_br_mnt(br);
13480 + h_sb = h_mnt->mnt_sb;
13481 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13483 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13484 + fh_len - Fh_tail, fh[Fh_h_type],
13485 + h_acceptable, /*context*/NULL);
13487 + dentry = h_parent;
13488 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13489 + AuWarn1("%s decode_fh failed, %ld\n",
13490 + au_sbtype(h_sb), PTR_ERR(h_parent));
13494 + if (unlikely(au_test_anon(h_parent))) {
13495 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13496 + au_sbtype(h_sb));
13497 + goto out_h_parent;
13500 + dentry = ERR_PTR(-ENOMEM);
13501 + pathname = (void *)__get_free_page(GFP_NOFS);
13502 + if (unlikely(!pathname))
13503 + goto out_h_parent;
13505 + root = sb->s_root;
13506 + path.mnt = h_mnt;
13507 + di_read_lock_parent(root, !AuLock_IR);
13508 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13509 + di_read_unlock(root, !AuLock_IR);
13510 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13511 + dentry = (void *)p;
13513 + goto out_pathname;
13515 + si_read_unlock(sb);
13516 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13517 + dentry = ERR_PTR(err);
13518 + if (unlikely(err))
13521 + dentry = ERR_PTR(-ENOENT);
13522 + AuDebugOn(au_test_anon(path.dentry));
13523 + if (unlikely(d_really_is_negative(path.dentry)))
13526 + if (ino != d_inode(path.dentry)->i_ino)
13527 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13529 + dentry = dget(path.dentry);
13534 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13535 + if (!IS_ERR(dentry)) {
13537 + dentry = ERR_PTR(-ESTALE);
13540 + free_page((unsigned long)pathname);
13544 + AuTraceErrPtr(dentry);
13548 +/* ---------------------------------------------------------------------- */
13550 +static struct dentry *
13551 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13554 + struct dentry *dentry;
13555 + __u32 *fh = fid->raw;
13556 + struct au_branch *br;
13557 + ino_t ino, dir_ino;
13558 + struct au_nfsd_si_lock nsi_lock = {
13562 + dentry = ERR_PTR(-ESTALE);
13563 + /* it should never happen, but the file handle is unreliable */
13564 + if (unlikely(fh_len < Fh_tail))
13566 + nsi_lock.sigen = fh[Fh_sigen];
13567 + nsi_lock.br_id = fh[Fh_br_id];
13569 + /* branch id may be wrapped around */
13571 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13573 + nsi_lock.force_lock = 1;
13575 + /* is this inode still cached? */
13576 + ino = decode_ino(fh + Fh_ino);
13577 + /* it should never happen */
13578 + if (unlikely(ino == AUFS_ROOT_INO))
13581 + dir_ino = decode_ino(fh + Fh_dir_ino);
13582 + dentry = decode_by_ino(sb, ino, dir_ino);
13583 + if (IS_ERR(dentry))
13588 + /* is the parent dir cached? */
13589 + br = au_sbr(sb, nsi_lock.bindex);
13590 + au_lcnt_inc(&br->br_nfiles);
13591 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13592 + if (IS_ERR(dentry))
13597 + /* lookup path */
13598 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13599 + if (IS_ERR(dentry))
13601 + if (unlikely(!dentry))
13602 + /* todo?: make it ESTALE */
13606 + if (!au_digen_test(dentry, au_sigen(sb))
13607 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13608 + goto out_unlock; /* success */
13611 + dentry = ERR_PTR(-ESTALE);
13614 + au_lcnt_dec(&br->br_nfiles);
13615 + si_read_unlock(sb);
13617 + AuTraceErrPtr(dentry);
13621 +#if 0 /* reserved for future use */
13622 +/* support subtreecheck option */
13623 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13624 + int fh_len, int fh_type)
13626 + struct dentry *parent;
13627 + __u32 *fh = fid->raw;
13630 + dir_ino = decode_ino(fh + Fh_dir_ino);
13631 + parent = decode_by_ino(sb, dir_ino, 0);
13632 + if (IS_ERR(parent))
13635 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13636 + dir_ino, fh, fh_len);
13639 + AuTraceErrPtr(parent);
13644 +/* ---------------------------------------------------------------------- */
13646 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13647 + struct inode *dir)
13650 + aufs_bindex_t bindex;
13651 + struct super_block *sb, *h_sb;
13652 + struct dentry *dentry, *parent, *h_parent;
13653 + struct inode *h_dir;
13654 + struct au_branch *br;
13657 + if (unlikely(*max_len <= Fh_tail)) {
13658 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13662 + err = FILEID_ROOT;
13663 + if (inode->i_ino == AUFS_ROOT_INO) {
13664 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13669 + sb = inode->i_sb;
13670 + err = si_read_lock(sb, AuLock_FLUSH);
13671 + if (unlikely(err))
13674 +#ifdef CONFIG_AUFS_DEBUG
13675 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13676 + AuWarn1("NFS-exporting requires xino\n");
13680 + ii_read_lock_child(inode);
13681 + bindex = au_ibtop(inode);
13683 + dentry = d_find_any_alias(inode);
13684 + if (unlikely(!dentry))
13686 + AuDebugOn(au_test_anon(dentry));
13687 + parent = dget_parent(dentry);
13689 + if (unlikely(!parent))
13691 + if (d_really_is_positive(parent))
13692 + dir = d_inode(parent);
13695 + ii_read_lock_parent(dir);
13696 + h_dir = au_h_iptr(dir, bindex);
13697 + ii_read_unlock(dir);
13698 + if (unlikely(!h_dir))
13700 + h_parent = d_find_any_alias(h_dir);
13701 + if (unlikely(!h_parent))
13702 + goto out_hparent;
13705 + br = au_sbr(sb, bindex);
13706 + h_sb = au_br_sb(br);
13707 + if (unlikely(!h_sb->s_export_op)) {
13708 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13709 + goto out_hparent;
13712 + fh[Fh_br_id] = br->br_id;
13713 + fh[Fh_sigen] = au_sigen(sb);
13714 + encode_ino(fh + Fh_ino, inode->i_ino);
13715 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13716 + fh[Fh_igen] = inode->i_generation;
13718 + *max_len -= Fh_tail;
13719 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13721 + /*connectable or subtreecheck*/0);
13722 + err = fh[Fh_h_type];
13723 + *max_len += Fh_tail;
13724 + /* todo: macros? */
13725 + if (err != FILEID_INVALID)
13728 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13735 + ii_read_unlock(inode);
13736 + si_read_unlock(sb);
13738 + if (unlikely(err < 0))
13739 + err = FILEID_INVALID;
13743 +/* ---------------------------------------------------------------------- */
13745 +static int aufs_commit_metadata(struct inode *inode)
13748 + aufs_bindex_t bindex;
13749 + struct super_block *sb;
13750 + struct inode *h_inode;
13751 + int (*f)(struct inode *inode);
13753 + sb = inode->i_sb;
13754 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13755 + ii_write_lock_child(inode);
13756 + bindex = au_ibtop(inode);
13757 + AuDebugOn(bindex < 0);
13758 + h_inode = au_h_iptr(inode, bindex);
13760 + f = h_inode->i_sb->s_export_op->commit_metadata;
13762 + err = f(h_inode);
13764 + struct writeback_control wbc = {
13765 + .sync_mode = WB_SYNC_ALL,
13766 + .nr_to_write = 0 /* metadata only */
13769 + err = sync_inode(h_inode, &wbc);
13772 + au_cpup_attr_timesizes(inode);
13773 + ii_write_unlock(inode);
13774 + si_read_unlock(sb);
13778 +/* ---------------------------------------------------------------------- */
13780 +static struct export_operations aufs_export_op = {
13781 + .fh_to_dentry = aufs_fh_to_dentry,
13782 + /* .fh_to_parent = aufs_fh_to_parent, */
13783 + .encode_fh = aufs_encode_fh,
13784 + .commit_metadata = aufs_commit_metadata
13787 +void au_export_init(struct super_block *sb)
13789 + struct au_sbinfo *sbinfo;
13792 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13793 + && IS_MODULE(CONFIG_EXPORTFS),
13794 + AUFS_NAME ": unsupported configuration "
13795 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13797 + sb->s_export_op = &aufs_export_op;
13798 + sbinfo = au_sbi(sb);
13799 + sbinfo->si_xigen = NULL;
13800 + get_random_bytes(&u, sizeof(u));
13801 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13802 + atomic_set(&sbinfo->si_xigen_next, u);
13804 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13805 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13806 +++ linux/fs/aufs/fhsm.c 2019-03-05 12:13:00.139224339 +0100
13808 +// SPDX-License-Identifier: GPL-2.0
13810 + * Copyright (C) 2011-2019 Junjiro R. Okajima
13812 + * This program, aufs is free software; you can redistribute it and/or modify
13813 + * it under the terms of the GNU General Public License as published by
13814 + * the Free Software Foundation; either version 2 of the License, or
13815 + * (at your option) any later version.
13817 + * This program is distributed in the hope that it will be useful,
13818 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13819 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13820 + * GNU General Public License for more details.
13822 + * You should have received a copy of the GNU General Public License
13823 + * along with this program; if not, write to the Free Software
13824 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13828 + * File-based Hierarchy Storage Management
13831 +#include <linux/anon_inodes.h>
13832 +#include <linux/poll.h>
13833 +#include <linux/seq_file.h>
13834 +#include <linux/statfs.h>
13837 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13839 + struct au_sbinfo *sbinfo;
13840 + struct au_fhsm *fhsm;
13842 + SiMustAnyLock(sb);
13844 + sbinfo = au_sbi(sb);
13845 + fhsm = &sbinfo->si_fhsm;
13846 + AuDebugOn(!fhsm);
13847 + return fhsm->fhsm_bottom;
13850 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13852 + struct au_sbinfo *sbinfo;
13853 + struct au_fhsm *fhsm;
13855 + SiMustWriteLock(sb);
13857 + sbinfo = au_sbi(sb);
13858 + fhsm = &sbinfo->si_fhsm;
13859 + AuDebugOn(!fhsm);
13860 + fhsm->fhsm_bottom = bindex;
13863 +/* ---------------------------------------------------------------------- */
13865 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13867 + struct au_br_fhsm *bf;
13869 + bf = br->br_fhsm;
13870 + MtxMustLock(&bf->bf_lock);
13872 + return !bf->bf_readable
13873 + || time_after(jiffies,
13874 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13877 +/* ---------------------------------------------------------------------- */
13879 +static void au_fhsm_notify(struct super_block *sb, int val)
13881 + struct au_sbinfo *sbinfo;
13882 + struct au_fhsm *fhsm;
13884 + SiMustAnyLock(sb);
13886 + sbinfo = au_sbi(sb);
13887 + fhsm = &sbinfo->si_fhsm;
13888 + if (au_fhsm_pid(fhsm)
13889 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13890 + atomic_set(&fhsm->fhsm_readable, val);
13892 + wake_up(&fhsm->fhsm_wqh);
13896 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13897 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13900 + struct au_branch *br;
13901 + struct au_br_fhsm *bf;
13903 + br = au_sbr(sb, bindex);
13904 + AuDebugOn(au_br_rdonly(br));
13905 + bf = br->br_fhsm;
13909 + mutex_lock(&bf->bf_lock);
13911 + MtxMustLock(&bf->bf_lock);
13913 + /* sb->s_root for NFS is unreliable */
13914 + err = au_br_stfs(br, &bf->bf_stfs);
13915 + if (unlikely(err)) {
13916 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13920 + bf->bf_jiffy = jiffies;
13921 + bf->bf_readable = 1;
13923 + au_fhsm_notify(sb, /*val*/1);
13925 + *rstfs = bf->bf_stfs;
13929 + mutex_unlock(&bf->bf_lock);
13930 + au_fhsm_notify(sb, /*val*/1);
13935 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13938 + struct au_sbinfo *sbinfo;
13939 + struct au_fhsm *fhsm;
13940 + struct au_branch *br;
13941 + struct au_br_fhsm *bf;
13943 + AuDbg("b%d, force %d\n", bindex, force);
13944 + SiMustAnyLock(sb);
13946 + sbinfo = au_sbi(sb);
13947 + fhsm = &sbinfo->si_fhsm;
13948 + if (!au_ftest_si(sbinfo, FHSM)
13949 + || fhsm->fhsm_bottom == bindex)
13952 + br = au_sbr(sb, bindex);
13953 + bf = br->br_fhsm;
13955 + mutex_lock(&bf->bf_lock);
13957 + || au_fhsm_pid(fhsm)
13958 + || au_fhsm_test_jiffy(sbinfo, br))
13959 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13961 + mutex_unlock(&bf->bf_lock);
13964 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13966 + aufs_bindex_t bindex, bbot;
13967 + struct au_branch *br;
13969 + /* exclude the bottom */
13970 + bbot = au_fhsm_bottom(sb);
13971 + for (bindex = 0; bindex < bbot; bindex++) {
13972 + br = au_sbr(sb, bindex);
13973 + if (au_br_fhsm(br->br_perm))
13974 + au_fhsm_wrote(sb, bindex, force);
13978 +/* ---------------------------------------------------------------------- */
13980 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13983 + struct au_sbinfo *sbinfo;
13984 + struct au_fhsm *fhsm;
13987 + sbinfo = file->private_data;
13988 + fhsm = &sbinfo->si_fhsm;
13989 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13990 + if (atomic_read(&fhsm->fhsm_readable))
13991 + mask = EPOLLIN /* | EPOLLRDNORM */;
13994 + AuDbg("mask 0x%x\n", mask);
13998 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13999 + struct aufs_stfs *stfs, __s16 brid)
14003 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
14005 + err = __put_user(brid, &stbr->brid);
14006 + if (unlikely(err))
14012 +static ssize_t au_fhsm_do_read(struct super_block *sb,
14013 + struct aufs_stbr __user *stbr, size_t count)
14017 + aufs_bindex_t bindex, bbot;
14018 + struct au_branch *br;
14019 + struct au_br_fhsm *bf;
14021 + /* except the bottom branch */
14024 + bbot = au_fhsm_bottom(sb);
14025 + for (bindex = 0; !err && bindex < bbot; bindex++) {
14026 + br = au_sbr(sb, bindex);
14027 + if (!au_br_fhsm(br->br_perm))
14030 + bf = br->br_fhsm;
14031 + mutex_lock(&bf->bf_lock);
14032 + if (bf->bf_readable) {
14034 + if (count >= sizeof(*stbr))
14035 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
14038 + bf->bf_readable = 0;
14039 + count -= sizeof(*stbr);
14043 + mutex_unlock(&bf->bf_lock);
14046 + err = sizeof(*stbr) * nstbr;
14051 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
14056 + aufs_bindex_t nfhsm, bindex, bbot;
14057 + struct au_sbinfo *sbinfo;
14058 + struct au_fhsm *fhsm;
14059 + struct au_branch *br;
14060 + struct super_block *sb;
14063 + sbinfo = file->private_data;
14064 + fhsm = &sbinfo->si_fhsm;
14066 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
14067 + if (!atomic_read(&fhsm->fhsm_readable)) {
14068 + if (vfsub_file_flags(file) & O_NONBLOCK)
14071 + err = wait_event_interruptible_locked_irq
14073 + atomic_read(&fhsm->fhsm_readable));
14075 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
14076 + if (unlikely(err))
14079 + /* sb may already be dead */
14080 + au_rw_read_lock(&sbinfo->si_rwsem);
14081 + readable = atomic_read(&fhsm->fhsm_readable);
14082 + if (readable > 0) {
14083 + sb = sbinfo->si_sb;
14085 + /* exclude the bottom branch */
14087 + bbot = au_fhsm_bottom(sb);
14088 + for (bindex = 0; bindex < bbot; bindex++) {
14089 + br = au_sbr(sb, bindex);
14090 + if (au_br_fhsm(br->br_perm))
14094 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
14095 + atomic_set(&fhsm->fhsm_readable, 0);
14096 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
14100 + au_rw_read_unlock(&sbinfo->si_rwsem);
14108 +static int au_fhsm_release(struct inode *inode, struct file *file)
14110 + struct au_sbinfo *sbinfo;
14111 + struct au_fhsm *fhsm;
14113 + /* sb may already be dead */
14114 + sbinfo = file->private_data;
14115 + fhsm = &sbinfo->si_fhsm;
14116 + spin_lock(&fhsm->fhsm_spin);
14117 + fhsm->fhsm_pid = 0;
14118 + spin_unlock(&fhsm->fhsm_spin);
14119 + kobject_put(&sbinfo->si_kobj);
14124 +static const struct file_operations au_fhsm_fops = {
14125 + .owner = THIS_MODULE,
14126 + .llseek = noop_llseek,
14127 + .read = au_fhsm_read,
14128 + .poll = au_fhsm_poll,
14129 + .release = au_fhsm_release
14132 +int au_fhsm_fd(struct super_block *sb, int oflags)
14135 + struct au_sbinfo *sbinfo;
14136 + struct au_fhsm *fhsm;
14139 + if (unlikely(!capable(CAP_SYS_ADMIN)))
14143 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
14147 + sbinfo = au_sbi(sb);
14148 + fhsm = &sbinfo->si_fhsm;
14149 + spin_lock(&fhsm->fhsm_spin);
14150 + if (!fhsm->fhsm_pid)
14151 + fhsm->fhsm_pid = current->pid;
14154 + spin_unlock(&fhsm->fhsm_spin);
14155 + if (unlikely(err))
14158 + oflags |= O_RDONLY;
14159 + /* oflags |= FMODE_NONOTIFY; */
14160 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
14162 + if (unlikely(fd < 0))
14165 + /* succeed regardless 'fhsm' status */
14166 + kobject_get(&sbinfo->si_kobj);
14167 + si_noflush_read_lock(sb);
14168 + if (au_ftest_si(sbinfo, FHSM))
14169 + au_fhsm_wrote_all(sb, /*force*/0);
14170 + si_read_unlock(sb);
14171 + goto out; /* success */
14174 + spin_lock(&fhsm->fhsm_spin);
14175 + fhsm->fhsm_pid = 0;
14176 + spin_unlock(&fhsm->fhsm_spin);
14182 +/* ---------------------------------------------------------------------- */
14184 +int au_fhsm_br_alloc(struct au_branch *br)
14189 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14191 + au_br_fhsm_init(br->br_fhsm);
14198 +/* ---------------------------------------------------------------------- */
14200 +void au_fhsm_fin(struct super_block *sb)
14202 + au_fhsm_notify(sb, /*val*/-1);
14205 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14207 + struct au_fhsm *fhsm;
14209 + fhsm = &sbinfo->si_fhsm;
14210 + spin_lock_init(&fhsm->fhsm_spin);
14211 + init_waitqueue_head(&fhsm->fhsm_wqh);
14212 + atomic_set(&fhsm->fhsm_readable, 0);
14213 + fhsm->fhsm_expire
14214 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14215 + fhsm->fhsm_bottom = -1;
14218 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14220 + sbinfo->si_fhsm.fhsm_expire
14221 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14224 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14228 + if (!au_ftest_si(sbinfo, FHSM))
14231 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14232 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14233 + seq_printf(seq, ",fhsm_sec=%u", u);
14235 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14236 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14237 +++ linux/fs/aufs/file.c 2019-03-05 12:13:00.139224339 +0100
14239 +// SPDX-License-Identifier: GPL-2.0
14241 + * Copyright (C) 2005-2019 Junjiro R. Okajima
14243 + * This program, aufs is free software; you can redistribute it and/or modify
14244 + * it under the terms of the GNU General Public License as published by
14245 + * the Free Software Foundation; either version 2 of the License, or
14246 + * (at your option) any later version.
14248 + * This program is distributed in the hope that it will be useful,
14249 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14250 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14251 + * GNU General Public License for more details.
14253 + * You should have received a copy of the GNU General Public License
14254 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14258 + * handling file/dir, and address_space operation
14261 +#ifdef CONFIG_AUFS_DEBUG
14262 +#include <linux/migrate.h>
14264 +#include <linux/pagemap.h>
14267 +/* drop flags for writing */
14268 +unsigned int au_file_roflags(unsigned int flags)
14270 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14271 + flags |= O_RDONLY | O_NOATIME;
14275 +/* common functions to regular file and dir */
14276 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14277 + struct file *file, int force_wr)
14279 + struct file *h_file;
14280 + struct dentry *h_dentry;
14281 + struct inode *h_inode;
14282 + struct super_block *sb;
14283 + struct au_branch *br;
14284 + struct path h_path;
14287 + /* a race condition can happen between open and unlink/rmdir */
14288 + h_file = ERR_PTR(-ENOENT);
14289 + h_dentry = au_h_dptr(dentry, bindex);
14290 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14292 + h_inode = d_inode(h_dentry);
14293 + spin_lock(&h_dentry->d_lock);
14294 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14295 + /* || !d_inode(dentry)->i_nlink */
14297 + spin_unlock(&h_dentry->d_lock);
14298 + if (unlikely(err))
14301 + sb = dentry->d_sb;
14302 + br = au_sbr(sb, bindex);
14303 + err = au_br_test_oflag(flags, br);
14304 + h_file = ERR_PTR(err);
14305 + if (unlikely(err))
14308 + /* drop flags for writing */
14309 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14310 + if (force_wr && !(flags & O_WRONLY))
14312 + flags = au_file_roflags(flags);
14314 + h_file = ERR_PTR(-EROFS);
14315 + flags = au_file_roflags(flags);
14316 + if (unlikely(vfsub_native_ro(h_inode)
14317 + || IS_APPEND(h_inode)))
14319 + flags &= ~O_ACCMODE;
14320 + flags |= O_WRONLY;
14323 + flags &= ~O_CREAT;
14324 + au_lcnt_inc(&br->br_nfiles);
14325 + h_path.dentry = h_dentry;
14326 + h_path.mnt = au_br_mnt(br);
14327 + h_file = vfsub_dentry_open(&h_path, flags);
14328 + if (IS_ERR(h_file))
14331 + if (flags & __FMODE_EXEC) {
14332 + err = deny_write_access(h_file);
14333 + if (unlikely(err)) {
14335 + h_file = ERR_PTR(err);
14339 + fsnotify_open(h_file);
14340 + goto out; /* success */
14343 + au_lcnt_dec(&br->br_nfiles);
14348 +static int au_cmoo(struct dentry *dentry)
14350 + int err, cmoo, matched;
14351 + unsigned int udba;
14352 + struct path h_path;
14353 + struct au_pin pin;
14354 + struct au_cp_generic cpg = {
14355 + .dentry = dentry,
14360 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14362 + struct inode *delegated;
14363 + struct super_block *sb;
14364 + struct au_sbinfo *sbinfo;
14365 + struct au_fhsm *fhsm;
14367 + struct au_branch *br;
14368 + struct dentry *parent;
14369 + struct au_hinode *hdir;
14371 + DiMustWriteLock(dentry);
14372 + IiMustWriteLock(d_inode(dentry));
14375 + if (IS_ROOT(dentry))
14377 + cpg.bsrc = au_dbtop(dentry);
14381 + sb = dentry->d_sb;
14382 + sbinfo = au_sbi(sb);
14383 + fhsm = &sbinfo->si_fhsm;
14384 + pid = au_fhsm_pid(fhsm);
14387 + && (current->pid == pid
14388 + || rcu_dereference(current->real_parent)->pid == pid));
14389 + rcu_read_unlock();
14393 + br = au_sbr(sb, cpg.bsrc);
14394 + cmoo = au_br_cmoo(br->br_perm);
14397 + if (!d_is_reg(dentry))
14398 + cmoo &= AuBrAttr_COO_ALL;
14402 + parent = dget_parent(dentry);
14403 + di_write_lock_parent(parent);
14404 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14406 + if (unlikely(err < 0)) {
14407 + err = 0; /* there is no upper writable branch */
14410 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14412 + /* do not respect the coo attrib for the target branch */
14413 + err = au_cpup_dirs(dentry, cpg.bdst);
14414 + if (unlikely(err))
14417 + di_downgrade_lock(parent, AuLock_IR);
14418 + udba = au_opt_udba(sb);
14419 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14420 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14421 + if (unlikely(err))
14424 + err = au_sio_cpup_simple(&cpg);
14426 + if (unlikely(err))
14428 + if (!(cmoo & AuBrWAttr_MOO))
14429 + goto out_parent; /* success */
14431 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14432 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14433 + if (unlikely(err))
14436 + h_path.mnt = au_br_mnt(br);
14437 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14438 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14439 + delegated = NULL;
14440 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14442 + /* todo: keep h_dentry or not? */
14443 + if (unlikely(err == -EWOULDBLOCK)) {
14444 + pr_warn("cannot retry for NFSv4 delegation"
14445 + " for an internal unlink\n");
14448 + if (unlikely(err)) {
14449 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14453 + goto out_parent; /* success */
14456 + di_downgrade_lock(parent, AuLock_IR);
14458 + di_read_unlock(parent, AuLock_IR);
14465 +int au_do_open(struct file *file, struct au_do_open_args *args)
14467 + int err, aopen = args->aopen;
14468 + struct dentry *dentry;
14469 + struct au_finfo *finfo;
14472 + err = au_finfo_init(file, args->fidir);
14475 + err = au_finfo_init(file, args->fidir);
14478 + if (unlikely(err))
14481 + dentry = file->f_path.dentry;
14482 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14483 + di_write_lock_child(dentry);
14484 + err = au_cmoo(dentry);
14485 + di_downgrade_lock(dentry, AuLock_IR);
14488 + err = args->open(file, vfsub_file_flags(file), NULL);
14491 + err = args->open(file, vfsub_file_flags(file),
14496 + di_read_unlock(dentry, AuLock_IR);
14498 + finfo = au_fi(file);
14500 + finfo->fi_file = file;
14501 + au_hbl_add(&finfo->fi_hlist,
14502 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14505 + fi_write_unlock(file);
14508 + fi_write_unlock(file);
14511 + if (unlikely(err)) {
14512 + finfo->fi_hdir = NULL;
14513 + au_finfo_fin(file);
14521 +int au_reopen_nondir(struct file *file)
14524 + aufs_bindex_t btop;
14525 + struct dentry *dentry;
14526 + struct au_branch *br;
14527 + struct file *h_file, *h_file_tmp;
14529 + dentry = file->f_path.dentry;
14530 + btop = au_dbtop(dentry);
14531 + br = au_sbr(dentry->d_sb, btop);
14532 + h_file_tmp = NULL;
14533 + if (au_fbtop(file) == btop) {
14534 + h_file = au_hf_top(file);
14535 + if (file->f_mode == h_file->f_mode)
14536 + return 0; /* success */
14537 + h_file_tmp = h_file;
14538 + get_file(h_file_tmp);
14539 + au_lcnt_inc(&br->br_nfiles);
14540 + au_set_h_fptr(file, btop, NULL);
14542 + AuDebugOn(au_fi(file)->fi_hdir);
14545 + * file exists on both of rw and ro
14546 + * open --> dbtop and fbtop are both 0
14547 + * prepend a branch as rw, "rw" become ro
14549 + * delete the top branch, "rw" becomes rw again
14550 + * --> dbtop is 1, fbtop is still 0
14551 + * write --> fbtop is 0 but dbtop is 1
14553 + /* AuDebugOn(au_fbtop(file) < btop); */
14555 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14556 + file, /*force_wr*/0);
14557 + err = PTR_ERR(h_file);
14558 + if (IS_ERR(h_file)) {
14559 + if (h_file_tmp) {
14561 + au_set_h_fptr(file, btop, h_file_tmp);
14562 + h_file_tmp = NULL;
14564 + goto out; /* todo: close all? */
14568 + au_set_fbtop(file, btop);
14569 + au_set_h_fptr(file, btop, h_file);
14570 + au_update_figen(file);
14571 + /* todo: necessary? */
14572 + /* file->f_ra = h_file->f_ra; */
14575 + if (h_file_tmp) {
14576 + fput(h_file_tmp);
14577 + au_lcnt_dec(&br->br_nfiles);
14582 +/* ---------------------------------------------------------------------- */
14584 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14585 + struct dentry *hi_wh)
14588 + aufs_bindex_t btop;
14589 + struct au_dinfo *dinfo;
14590 + struct dentry *h_dentry;
14591 + struct au_hdentry *hdp;
14593 + dinfo = au_di(file->f_path.dentry);
14594 + AuRwMustWriteLock(&dinfo->di_rwsem);
14596 + btop = dinfo->di_btop;
14597 + dinfo->di_btop = btgt;
14598 + hdp = au_hdentry(dinfo, btgt);
14599 + h_dentry = hdp->hd_dentry;
14600 + hdp->hd_dentry = hi_wh;
14601 + err = au_reopen_nondir(file);
14602 + hdp->hd_dentry = h_dentry;
14603 + dinfo->di_btop = btop;
14608 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14609 + aufs_bindex_t bcpup, struct au_pin *pin)
14612 + struct inode *inode, *h_inode;
14613 + struct dentry *h_dentry, *hi_wh;
14614 + struct au_cp_generic cpg = {
14615 + .dentry = file->f_path.dentry,
14622 + au_update_dbtop(cpg.dentry);
14623 + inode = d_inode(cpg.dentry);
14625 + if (au_dbtop(cpg.dentry) <= bcpup
14626 + && au_dbbot(cpg.dentry) >= bcpup) {
14627 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14628 + if (h_dentry && d_is_positive(h_dentry))
14629 + h_inode = d_inode(h_dentry);
14631 + hi_wh = au_hi_wh(inode, bcpup);
14632 + if (!hi_wh && !h_inode)
14633 + err = au_sio_cpup_wh(&cpg, file);
14635 + /* already copied-up after unlink */
14636 + err = au_reopen_wh(file, bcpup, hi_wh);
14639 + && (inode->i_nlink > 1
14640 + || (inode->i_state & I_LINKABLE))
14641 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14642 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14648 + * prepare the @file for writing.
14650 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14653 + aufs_bindex_t dbtop;
14654 + struct dentry *parent;
14655 + struct inode *inode;
14656 + struct super_block *sb;
14657 + struct file *h_file;
14658 + struct au_cp_generic cpg = {
14659 + .dentry = file->f_path.dentry,
14664 + .flags = AuCpup_DTIME
14667 + sb = cpg.dentry->d_sb;
14668 + inode = d_inode(cpg.dentry);
14669 + cpg.bsrc = au_fbtop(file);
14670 + err = au_test_ro(sb, cpg.bsrc, inode);
14671 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14672 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14677 + /* need to cpup or reopen */
14678 + parent = dget_parent(cpg.dentry);
14679 + di_write_lock_parent(parent);
14680 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14682 + if (unlikely(err < 0))
14686 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14687 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14688 + if (unlikely(err))
14692 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14693 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14694 + if (unlikely(err))
14697 + dbtop = au_dbtop(cpg.dentry);
14698 + if (dbtop <= cpg.bdst)
14699 + cpg.bsrc = cpg.bdst;
14701 + if (dbtop <= cpg.bdst /* just reopen */
14702 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14704 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14705 + if (IS_ERR(h_file))
14706 + err = PTR_ERR(h_file);
14708 + di_downgrade_lock(parent, AuLock_IR);
14709 + if (dbtop > cpg.bdst)
14710 + err = au_sio_cpup_simple(&cpg);
14712 + err = au_reopen_nondir(file);
14713 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14715 + } else { /* copyup as wh and reopen */
14717 + * since writable hfsplus branch is not supported,
14718 + * h_open_pre/post() are unnecessary.
14720 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14721 + di_downgrade_lock(parent, AuLock_IR);
14725 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14726 + goto out_dput; /* success */
14732 + di_downgrade_lock(parent, AuLock_IR);
14734 + di_read_unlock(parent, AuLock_IR);
14741 +/* ---------------------------------------------------------------------- */
14743 +int au_do_flush(struct file *file, fl_owner_t id,
14744 + int (*flush)(struct file *file, fl_owner_t id))
14747 + struct super_block *sb;
14748 + struct inode *inode;
14750 + inode = file_inode(file);
14751 + sb = inode->i_sb;
14752 + si_noflush_read_lock(sb);
14753 + fi_read_lock(file);
14754 + ii_read_lock_child(inode);
14756 + err = flush(file, id);
14757 + au_cpup_attr_timesizes(inode);
14759 + ii_read_unlock(inode);
14760 + fi_read_unlock(file);
14761 + si_read_unlock(sb);
14765 +/* ---------------------------------------------------------------------- */
14767 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14770 + struct au_pin pin;
14771 + struct au_finfo *finfo;
14772 + struct dentry *parent, *hi_wh;
14773 + struct inode *inode;
14774 + struct super_block *sb;
14775 + struct au_cp_generic cpg = {
14776 + .dentry = file->f_path.dentry,
14781 + .flags = AuCpup_DTIME
14784 + FiMustWriteLock(file);
14787 + finfo = au_fi(file);
14788 + sb = cpg.dentry->d_sb;
14789 + inode = d_inode(cpg.dentry);
14790 + cpg.bdst = au_ibtop(inode);
14791 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14794 + parent = dget_parent(cpg.dentry);
14795 + if (au_test_ro(sb, cpg.bdst, inode)) {
14796 + di_read_lock_parent(parent, !AuLock_IR);
14797 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14799 + di_read_unlock(parent, !AuLock_IR);
14800 + if (unlikely(err < 0))
14805 + di_read_lock_parent(parent, AuLock_IR);
14806 + hi_wh = au_hi_wh(inode, cpg.bdst);
14807 + if (!S_ISDIR(inode->i_mode)
14808 + && au_opt_test(au_mntflags(sb), PLINK)
14809 + && au_plink_test(inode)
14810 + && !d_unhashed(cpg.dentry)
14811 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14812 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14813 + if (unlikely(err))
14816 + /* always superio. */
14817 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14818 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14820 + err = au_sio_cpup_simple(&cpg);
14823 + } else if (hi_wh) {
14824 + /* already copied-up after unlink */
14825 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14826 + *need_reopen = 0;
14830 + di_read_unlock(parent, AuLock_IR);
14837 +static void au_do_refresh_dir(struct file *file)
14839 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14840 + struct au_hfile *p, tmp, *q;
14841 + struct au_finfo *finfo;
14842 + struct super_block *sb;
14843 + struct au_fidir *fidir;
14845 + FiMustWriteLock(file);
14847 + sb = file->f_path.dentry->d_sb;
14848 + finfo = au_fi(file);
14849 + fidir = finfo->fi_hdir;
14850 + AuDebugOn(!fidir);
14851 + p = fidir->fd_hfile + finfo->fi_btop;
14852 + brid = p->hf_br->br_id;
14853 + bbot = fidir->fd_bbot;
14854 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14858 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14859 + if (new_bindex == bindex)
14861 + if (new_bindex < 0) {
14862 + au_set_h_fptr(file, bindex, NULL);
14866 + /* swap two lower inode, and loop again */
14867 + q = fidir->fd_hfile + new_bindex;
14871 + if (tmp.hf_file) {
14877 + p = fidir->fd_hfile;
14878 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14879 + bbot = au_sbbot(sb);
14880 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14881 + finfo->fi_btop++, p++)
14882 + if (p->hf_file) {
14883 + if (file_inode(p->hf_file))
14885 + au_hfput(p, /*execed*/0);
14888 + bbot = au_br_index(sb, brid);
14889 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14890 + finfo->fi_btop++, p++)
14892 + au_hfput(p, /*execed*/0);
14893 + bbot = au_sbbot(sb);
14896 + p = fidir->fd_hfile + bbot;
14897 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14898 + fidir->fd_bbot--, p--)
14899 + if (p->hf_file) {
14900 + if (file_inode(p->hf_file))
14902 + au_hfput(p, /*execed*/0);
14904 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14908 + * after branch manipulating, refresh the file.
14910 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14912 + int err, need_reopen, nbr;
14913 + aufs_bindex_t bbot, bindex;
14914 + struct dentry *dentry;
14915 + struct super_block *sb;
14916 + struct au_finfo *finfo;
14917 + struct au_hfile *hfile;
14919 + dentry = file->f_path.dentry;
14920 + sb = dentry->d_sb;
14921 + nbr = au_sbbot(sb) + 1;
14922 + finfo = au_fi(file);
14923 + if (!finfo->fi_hdir) {
14924 + hfile = &finfo->fi_htop;
14925 + AuDebugOn(!hfile->hf_file);
14926 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14927 + AuDebugOn(bindex < 0);
14928 + if (bindex != finfo->fi_btop)
14929 + au_set_fbtop(file, bindex);
14931 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14932 + if (unlikely(err))
14934 + au_do_refresh_dir(file);
14939 + if (!au_test_mmapped(file))
14940 + err = au_file_refresh_by_inode(file, &need_reopen);
14941 + if (finfo->fi_hdir)
14942 + /* harmless if err */
14943 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14944 + if (!err && need_reopen && !d_unlinked(dentry))
14945 + err = reopen(file);
14947 + au_update_figen(file);
14948 + goto out; /* success */
14951 + /* error, close all lower files */
14952 + if (finfo->fi_hdir) {
14953 + bbot = au_fbbot_dir(file);
14954 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14955 + au_set_h_fptr(file, bindex, NULL);
14962 +/* common function to regular file and dir */
14963 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14964 + int wlock, unsigned int fi_lsc)
14967 + unsigned int sigen, figen;
14968 + aufs_bindex_t btop;
14969 + unsigned char pseudo_link;
14970 + struct dentry *dentry;
14971 + struct inode *inode;
14974 + dentry = file->f_path.dentry;
14975 + inode = d_inode(dentry);
14976 + sigen = au_sigen(dentry->d_sb);
14977 + fi_write_lock_nested(file, fi_lsc);
14978 + figen = au_figen(file);
14980 + di_write_lock_child(dentry);
14982 + di_write_lock_child2(dentry);
14983 + btop = au_dbtop(dentry);
14984 + pseudo_link = (btop != au_ibtop(inode));
14985 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14987 + di_downgrade_lock(dentry, AuLock_IR);
14988 + fi_downgrade_lock(file);
14990 + goto out; /* success */
14993 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14994 + if (au_digen_test(dentry, sigen)) {
14995 + err = au_reval_dpath(dentry, sigen);
14996 + AuDebugOn(!err && au_digen_test(dentry, sigen));
15000 + err = refresh_file(file, reopen);
15003 + di_downgrade_lock(dentry, AuLock_IR);
15004 + fi_downgrade_lock(file);
15007 + di_write_unlock(dentry);
15008 + fi_write_unlock(file);
15015 +/* ---------------------------------------------------------------------- */
15017 +/* cf. aufs_nopage() */
15018 +/* for madvise(2) */
15019 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
15021 + unlock_page(page);
15025 +/* it will never be called, but necessary to support O_DIRECT */
15026 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
15027 +{ BUG(); return 0; }
15029 +/* they will never be called. */
15030 +#ifdef CONFIG_AUFS_DEBUG
15031 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
15032 + loff_t pos, unsigned len, unsigned flags,
15033 + struct page **pagep, void **fsdata)
15034 +{ AuUnsupport(); return 0; }
15035 +static int aufs_write_end(struct file *file, struct address_space *mapping,
15036 + loff_t pos, unsigned len, unsigned copied,
15037 + struct page *page, void *fsdata)
15038 +{ AuUnsupport(); return 0; }
15039 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
15040 +{ AuUnsupport(); return 0; }
15042 +static int aufs_set_page_dirty(struct page *page)
15043 +{ AuUnsupport(); return 0; }
15044 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
15045 + unsigned int length)
15046 +{ AuUnsupport(); }
15047 +static int aufs_releasepage(struct page *page, gfp_t gfp)
15048 +{ AuUnsupport(); return 0; }
15049 +#if 0 /* called by memory compaction regardless file */
15050 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
15051 + struct page *page, enum migrate_mode mode)
15052 +{ AuUnsupport(); return 0; }
15054 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
15055 +{ AuUnsupport(); return true; }
15056 +static void aufs_putback_page(struct page *page)
15057 +{ AuUnsupport(); }
15058 +static int aufs_launder_page(struct page *page)
15059 +{ AuUnsupport(); return 0; }
15060 +static int aufs_is_partially_uptodate(struct page *page,
15061 + unsigned long from,
15062 + unsigned long count)
15063 +{ AuUnsupport(); return 0; }
15064 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
15066 +{ AuUnsupport(); }
15067 +static int aufs_error_remove_page(struct address_space *mapping,
15068 + struct page *page)
15069 +{ AuUnsupport(); return 0; }
15070 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
15072 +{ AuUnsupport(); return 0; }
15073 +static void aufs_swap_deactivate(struct file *file)
15074 +{ AuUnsupport(); }
15075 +#endif /* CONFIG_AUFS_DEBUG */
15077 +const struct address_space_operations aufs_aop = {
15078 + .readpage = aufs_readpage,
15079 + .direct_IO = aufs_direct_IO,
15080 +#ifdef CONFIG_AUFS_DEBUG
15081 + .writepage = aufs_writepage,
15082 + /* no writepages, because of writepage */
15083 + .set_page_dirty = aufs_set_page_dirty,
15084 + /* no readpages, because of readpage */
15085 + .write_begin = aufs_write_begin,
15086 + .write_end = aufs_write_end,
15087 + /* no bmap, no block device */
15088 + .invalidatepage = aufs_invalidatepage,
15089 + .releasepage = aufs_releasepage,
15090 + /* is fallback_migrate_page ok? */
15091 + /* .migratepage = aufs_migratepage, */
15092 + .isolate_page = aufs_isolate_page,
15093 + .putback_page = aufs_putback_page,
15094 + .launder_page = aufs_launder_page,
15095 + .is_partially_uptodate = aufs_is_partially_uptodate,
15096 + .is_dirty_writeback = aufs_is_dirty_writeback,
15097 + .error_remove_page = aufs_error_remove_page,
15098 + .swap_activate = aufs_swap_activate,
15099 + .swap_deactivate = aufs_swap_deactivate
15100 +#endif /* CONFIG_AUFS_DEBUG */
15102 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
15103 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
15104 +++ linux/fs/aufs/file.h 2019-03-05 12:13:00.139224339 +0100
15106 +/* SPDX-License-Identifier: GPL-2.0 */
15108 + * Copyright (C) 2005-2019 Junjiro R. Okajima
15110 + * This program, aufs is free software; you can redistribute it and/or modify
15111 + * it under the terms of the GNU General Public License as published by
15112 + * the Free Software Foundation; either version 2 of the License, or
15113 + * (at your option) any later version.
15115 + * This program is distributed in the hope that it will be useful,
15116 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15117 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15118 + * GNU General Public License for more details.
15120 + * You should have received a copy of the GNU General Public License
15121 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15125 + * file operations
15128 +#ifndef __AUFS_FILE_H__
15129 +#define __AUFS_FILE_H__
15133 +#include <linux/file.h>
15134 +#include <linux/fs.h>
15135 +#include <linux/mm_types.h>
15136 +#include <linux/poll.h>
15137 +#include "rwsem.h"
15141 + struct file *hf_file;
15142 + struct au_branch *hf_br;
15147 + aufs_bindex_t fd_bbot;
15148 + aufs_bindex_t fd_nent;
15149 + struct au_vdir *fd_vdir_cache;
15150 + struct au_hfile fd_hfile[];
15153 +static inline int au_fidir_sz(int nent)
15155 + AuDebugOn(nent < 0);
15156 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
15160 + atomic_t fi_generation;
15162 + struct au_rwsem fi_rwsem;
15163 + aufs_bindex_t fi_btop;
15165 + /* do not union them */
15166 + struct { /* for non-dir */
15167 + struct au_hfile fi_htop;
15168 + atomic_t fi_mmapped;
15170 + struct au_fidir *fi_hdir; /* for dir only */
15172 + struct hlist_bl_node fi_hlist;
15173 + struct file *fi_file; /* very ugly */
15174 + struct rcu_head rcu;
15175 +} ____cacheline_aligned_in_smp;
15177 +/* ---------------------------------------------------------------------- */
15180 +extern const struct address_space_operations aufs_aop;
15181 +unsigned int au_file_roflags(unsigned int flags);
15182 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15183 + struct file *file, int force_wr);
15184 +struct au_do_open_args {
15186 + int (*open)(struct file *file, int flags,
15187 + struct file *h_file);
15188 + struct au_fidir *fidir;
15189 + struct file *h_file;
15191 +int au_do_open(struct file *file, struct au_do_open_args *args);
15192 +int au_reopen_nondir(struct file *file);
15194 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15195 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15196 + int wlock, unsigned int fi_lsc);
15197 +int au_do_flush(struct file *file, fl_owner_t id,
15198 + int (*flush)(struct file *file, fl_owner_t id));
15201 +#ifdef CONFIG_AUFS_POLL
15202 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15205 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15207 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15209 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15210 + struct file *h_file);
15212 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15213 + aufs_bindex_t bindex, int force_wr)
15214 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15215 + struct file *h_file);
15219 +extern const struct file_operations aufs_file_fop;
15220 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15221 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15222 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15225 +void au_hfput(struct au_hfile *hf, int execed);
15226 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15227 + struct file *h_file);
15229 +void au_update_figen(struct file *file);
15230 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15231 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15233 +void au_fi_init_once(void *_fi);
15234 +void au_finfo_fin(struct file *file);
15235 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15238 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15239 +#ifdef CONFIG_COMPAT
15240 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15241 + unsigned long arg);
15242 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15243 + unsigned long arg);
15246 +/* ---------------------------------------------------------------------- */
15248 +static inline struct au_finfo *au_fi(struct file *file)
15250 + return file->private_data;
15253 +/* ---------------------------------------------------------------------- */
15255 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15256 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15257 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15258 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15260 +#define fi_read_trylock_nested(f) \
15261 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15262 +#define fi_write_trylock_nested(f) \
15263 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15266 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15267 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15268 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15270 +/* lock subclass for finfo */
15276 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15278 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15281 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15283 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15287 + * fi_read_lock_1, fi_write_lock_1,
15288 + * fi_read_lock_2, fi_write_lock_2
15290 +#define AuReadLockFunc(name) \
15291 +static inline void fi_read_lock_##name(struct file *f) \
15292 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15294 +#define AuWriteLockFunc(name) \
15295 +static inline void fi_write_lock_##name(struct file *f) \
15296 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15298 +#define AuRWLockFuncs(name) \
15299 + AuReadLockFunc(name) \
15300 + AuWriteLockFunc(name)
15305 +#undef AuReadLockFunc
15306 +#undef AuWriteLockFunc
15307 +#undef AuRWLockFuncs
15309 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15310 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15311 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15313 +/* ---------------------------------------------------------------------- */
15315 +/* todo: hard/soft set? */
15316 +static inline aufs_bindex_t au_fbtop(struct file *file)
15318 + FiMustAnyLock(file);
15319 + return au_fi(file)->fi_btop;
15322 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15324 + FiMustAnyLock(file);
15325 + AuDebugOn(!au_fi(file)->fi_hdir);
15326 + return au_fi(file)->fi_hdir->fd_bbot;
15329 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15331 + FiMustAnyLock(file);
15332 + AuDebugOn(!au_fi(file)->fi_hdir);
15333 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15336 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15338 + FiMustWriteLock(file);
15339 + au_fi(file)->fi_btop = bindex;
15342 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15344 + FiMustWriteLock(file);
15345 + AuDebugOn(!au_fi(file)->fi_hdir);
15346 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15349 +static inline void au_set_fvdir_cache(struct file *file,
15350 + struct au_vdir *vdir_cache)
15352 + FiMustWriteLock(file);
15353 + AuDebugOn(!au_fi(file)->fi_hdir);
15354 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15357 +static inline struct file *au_hf_top(struct file *file)
15359 + FiMustAnyLock(file);
15360 + AuDebugOn(au_fi(file)->fi_hdir);
15361 + return au_fi(file)->fi_htop.hf_file;
15364 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15366 + FiMustAnyLock(file);
15367 + AuDebugOn(!au_fi(file)->fi_hdir);
15368 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15371 +/* todo: memory barrier? */
15372 +static inline unsigned int au_figen(struct file *f)
15374 + return atomic_read(&au_fi(f)->fi_generation);
15377 +static inline void au_set_mmapped(struct file *f)
15379 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15381 + pr_warn("fi_mmapped wrapped around\n");
15382 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15386 +static inline void au_unset_mmapped(struct file *f)
15388 + atomic_dec(&au_fi(f)->fi_mmapped);
15391 +static inline int au_test_mmapped(struct file *f)
15393 + return atomic_read(&au_fi(f)->fi_mmapped);
15396 +/* customize vma->vm_file */
15398 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15399 + struct file *file)
15403 + f = vma->vm_file;
15405 + vma->vm_file = file;
15410 +#define AuDbgVmRegion(file, vma) do {} while (0)
15412 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15413 + struct file *file)
15415 + au_do_vm_file_reset(vma, file);
15418 +#define AuDbgVmRegion(file, vma) \
15419 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15421 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15422 + struct file *file)
15426 + au_do_vm_file_reset(vma, file);
15427 + f = vma->vm_region->vm_file;
15429 + vma->vm_region->vm_file = file;
15432 +#endif /* CONFIG_MMU */
15434 +/* handle vma->vm_prfile */
15435 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15436 + struct file *file)
15439 + vma->vm_prfile = file;
15440 +#ifndef CONFIG_MMU
15442 + vma->vm_region->vm_prfile = file;
15446 +#endif /* __KERNEL__ */
15447 +#endif /* __AUFS_FILE_H__ */
15448 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15449 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15450 +++ linux/fs/aufs/finfo.c 2019-03-05 12:13:00.139224339 +0100
15452 +// SPDX-License-Identifier: GPL-2.0
15454 + * Copyright (C) 2005-2019 Junjiro R. Okajima
15456 + * This program, aufs is free software; you can redistribute it and/or modify
15457 + * it under the terms of the GNU General Public License as published by
15458 + * the Free Software Foundation; either version 2 of the License, or
15459 + * (at your option) any later version.
15461 + * This program is distributed in the hope that it will be useful,
15462 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15463 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15464 + * GNU General Public License for more details.
15466 + * You should have received a copy of the GNU General Public License
15467 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15471 + * file private data
15476 +void au_hfput(struct au_hfile *hf, int execed)
15479 + allow_write_access(hf->hf_file);
15480 + fput(hf->hf_file);
15481 + hf->hf_file = NULL;
15482 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15483 + hf->hf_br = NULL;
15486 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15488 + struct au_finfo *finfo = au_fi(file);
15489 + struct au_hfile *hf;
15490 + struct au_fidir *fidir;
15492 + fidir = finfo->fi_hdir;
15494 + AuDebugOn(finfo->fi_btop != bindex);
15495 + hf = &finfo->fi_htop;
15497 + hf = fidir->fd_hfile + bindex;
15499 + if (hf && hf->hf_file)
15500 + au_hfput(hf, vfsub_file_execed(file));
15502 + FiMustWriteLock(file);
15503 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15504 + hf->hf_file = val;
15505 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15509 +void au_update_figen(struct file *file)
15511 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15512 + /* smp_mb(); */ /* atomic_set */
15515 +/* ---------------------------------------------------------------------- */
15517 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15519 + struct au_fidir *fidir;
15522 + nbr = au_sbbot(sb) + 1;
15524 + nbr = 2; /* initial allocate for 2 branches */
15525 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15527 + fidir->fd_bbot = -1;
15528 + fidir->fd_nent = nbr;
15534 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15537 + struct au_fidir *fidir, *p;
15539 + AuRwMustWriteLock(&finfo->fi_rwsem);
15540 + fidir = finfo->fi_hdir;
15541 + AuDebugOn(!fidir);
15544 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15545 + GFP_NOFS, may_shrink);
15547 + p->fd_nent = nbr;
15548 + finfo->fi_hdir = p;
15555 +/* ---------------------------------------------------------------------- */
15557 +void au_finfo_fin(struct file *file)
15559 + struct au_finfo *finfo;
15561 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15563 + finfo = au_fi(file);
15564 + AuDebugOn(finfo->fi_hdir);
15565 + AuRwDestroy(&finfo->fi_rwsem);
15566 + au_cache_free_finfo(finfo);
15569 +void au_fi_init_once(void *_finfo)
15571 + struct au_finfo *finfo = _finfo;
15573 + au_rw_init(&finfo->fi_rwsem);
15576 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15579 + struct au_finfo *finfo;
15580 + struct dentry *dentry;
15583 + dentry = file->f_path.dentry;
15584 + finfo = au_cache_alloc_finfo();
15585 + if (unlikely(!finfo))
15589 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15590 + au_rw_write_lock(&finfo->fi_rwsem);
15591 + finfo->fi_btop = -1;
15592 + finfo->fi_hdir = fidir;
15593 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15594 + /* smp_mb(); */ /* atomic_set */
15596 + file->private_data = finfo;
15601 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15602 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15603 +++ linux/fs/aufs/f_op.c 2019-03-05 12:13:00.139224339 +0100
15605 +// SPDX-License-Identifier: GPL-2.0
15607 + * Copyright (C) 2005-2019 Junjiro R. Okajima
15609 + * This program, aufs is free software; you can redistribute it and/or modify
15610 + * it under the terms of the GNU General Public License as published by
15611 + * the Free Software Foundation; either version 2 of the License, or
15612 + * (at your option) any later version.
15614 + * This program is distributed in the hope that it will be useful,
15615 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15616 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15617 + * GNU General Public License for more details.
15619 + * You should have received a copy of the GNU General Public License
15620 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15624 + * file and vm operations
15627 +#include <linux/aio.h>
15628 +#include <linux/fs_stack.h>
15629 +#include <linux/mman.h>
15630 +#include <linux/security.h>
15633 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15636 + aufs_bindex_t bindex;
15637 + struct dentry *dentry, *h_dentry;
15638 + struct au_finfo *finfo;
15639 + struct inode *h_inode;
15641 + FiMustWriteLock(file);
15644 + dentry = file->f_path.dentry;
15645 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15646 + finfo = au_fi(file);
15647 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15648 + atomic_set(&finfo->fi_mmapped, 0);
15649 + bindex = au_dbtop(dentry);
15651 + h_dentry = au_h_dptr(dentry, bindex);
15652 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15653 + if (unlikely(err))
15655 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15656 + if (IS_ERR(h_file)) {
15657 + err = PTR_ERR(h_file);
15661 + h_dentry = h_file->f_path.dentry;
15662 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15663 + if (unlikely(err))
15665 + /* br ref is already inc-ed */
15668 + if ((flags & __O_TMPFILE)
15669 + && !(flags & O_EXCL)) {
15670 + h_inode = file_inode(h_file);
15671 + spin_lock(&h_inode->i_lock);
15672 + h_inode->i_state |= I_LINKABLE;
15673 + spin_unlock(&h_inode->i_lock);
15675 + au_set_fbtop(file, bindex);
15676 + au_set_h_fptr(file, bindex, h_file);
15677 + au_update_figen(file);
15678 + /* todo: necessary? */
15679 + /* file->f_ra = h_file->f_ra; */
15685 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15686 + struct file *file)
15689 + struct super_block *sb;
15690 + struct au_do_open_args args = {
15691 + .open = au_do_open_nondir
15694 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15695 + file, vfsub_file_flags(file), file->f_mode);
15697 + sb = file->f_path.dentry->d_sb;
15698 + si_read_lock(sb, AuLock_FLUSH);
15699 + err = au_do_open(file, &args);
15700 + si_read_unlock(sb);
15704 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15706 + struct au_finfo *finfo;
15707 + aufs_bindex_t bindex;
15709 + finfo = au_fi(file);
15710 + au_hbl_del(&finfo->fi_hlist,
15711 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15712 + bindex = finfo->fi_btop;
15714 + au_set_h_fptr(file, bindex, NULL);
15716 + au_finfo_fin(file);
15720 +/* ---------------------------------------------------------------------- */
15722 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15725 + struct file *h_file;
15728 + h_file = au_hf_top(file);
15730 + err = vfsub_flush(h_file, id);
15734 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15736 + return au_do_flush(file, id, au_do_flush_nondir);
15739 +/* ---------------------------------------------------------------------- */
15741 + * read and write functions acquire [fdi]_rwsem once, but release before
15742 + * mmap_sem. This is because to stop a race condition between mmap(2).
15743 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15744 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15745 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15748 +/* Callers should call au_read_post() or fput() in the end */
15749 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15751 + struct file *h_file;
15754 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15756 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15757 + h_file = au_hf_top(file);
15758 + get_file(h_file);
15760 + fi_read_unlock(file);
15762 + h_file = ERR_PTR(err);
15767 +static void au_read_post(struct inode *inode, struct file *h_file)
15769 + /* update without lock, I don't think it a problem */
15770 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15774 +struct au_write_pre {
15776 + unsigned int lsc;
15780 + aufs_bindex_t btop;
15784 + * return with iinfo is write-locked
15785 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15788 +static struct file *au_write_pre(struct file *file, int do_ready,
15789 + struct au_write_pre *wpre)
15791 + struct file *h_file;
15792 + struct dentry *dentry;
15794 + unsigned int lsc;
15795 + struct au_pin pin;
15800 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15801 + h_file = ERR_PTR(err);
15802 + if (unlikely(err))
15805 + dentry = file->f_path.dentry;
15807 + err = au_ready_to_write(file, -1, &pin);
15808 + if (unlikely(err)) {
15809 + h_file = ERR_PTR(err);
15810 + di_write_unlock(dentry);
15815 + di_downgrade_lock(dentry, /*flags*/0);
15817 + wpre->btop = au_fbtop(file);
15818 + h_file = au_hf_top(file);
15819 + get_file(h_file);
15821 + wpre->blks = file_inode(h_file)->i_blocks;
15824 + di_read_unlock(dentry, /*flags*/0);
15827 + fi_write_unlock(file);
15832 +static void au_write_post(struct inode *inode, struct file *h_file,
15833 + struct au_write_pre *wpre, ssize_t written)
15835 + struct inode *h_inode;
15837 + au_cpup_attr_timesizes(inode);
15838 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15839 + h_inode = file_inode(h_file);
15840 + inode->i_mode = h_inode->i_mode;
15841 + ii_write_unlock(inode);
15842 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15844 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15845 + /*force*/h_inode->i_blocks > wpre->blks);
15849 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
15853 + struct inode *inode;
15854 + struct file *h_file;
15855 + struct super_block *sb;
15857 + inode = file_inode(file);
15858 + sb = inode->i_sb;
15859 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15861 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15862 + err = PTR_ERR(h_file);
15863 + if (IS_ERR(h_file))
15866 + /* filedata may be obsoleted by concurrent copyup, but no problem */
15867 + err = vfsub_read_u(h_file, buf, count, ppos);
15868 + /* todo: necessary? */
15869 + /* file->f_ra = h_file->f_ra; */
15870 + au_read_post(inode, h_file);
15873 + si_read_unlock(sb);
15878 + * todo: very ugly
15879 + * it locks both of i_mutex and si_rwsem for read in safe.
15880 + * if the plink maintenance mode continues forever (that is the problem),
15881 + * may loop forever.
15883 +static void au_mtx_and_read_lock(struct inode *inode)
15886 + struct super_block *sb = inode->i_sb;
15889 + inode_lock(inode);
15890 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15893 + inode_unlock(inode);
15894 + si_read_lock(sb, AuLock_NOPLMW);
15895 + si_read_unlock(sb);
15899 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
15900 + size_t count, loff_t *ppos)
15903 + struct au_write_pre wpre;
15904 + struct inode *inode;
15905 + struct file *h_file;
15906 + char __user *buf = (char __user *)ubuf;
15908 + inode = file_inode(file);
15909 + au_mtx_and_read_lock(inode);
15912 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15913 + err = PTR_ERR(h_file);
15914 + if (IS_ERR(h_file))
15917 + err = vfsub_write_u(h_file, buf, count, ppos);
15918 + au_write_post(inode, h_file, &wpre, err);
15921 + si_read_unlock(inode->i_sb);
15922 + inode_unlock(inode);
15926 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15927 + struct iov_iter *iov_iter)
15930 + struct file *file;
15931 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15933 + err = security_file_permission(h_file, rw);
15934 + if (unlikely(err))
15939 + if (rw == MAY_READ)
15940 + iter = h_file->f_op->read_iter;
15941 + else if (rw == MAY_WRITE)
15942 + iter = h_file->f_op->write_iter;
15944 + file = kio->ki_filp;
15945 + kio->ki_filp = h_file;
15948 + err = iter(kio, iov_iter);
15951 + /* currently there is no such fs */
15953 + kio->ki_filp = file;
15959 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15962 + struct file *file, *h_file;
15963 + struct inode *inode;
15964 + struct super_block *sb;
15966 + file = kio->ki_filp;
15967 + inode = file_inode(file);
15968 + sb = inode->i_sb;
15969 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15971 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15972 + err = PTR_ERR(h_file);
15973 + if (IS_ERR(h_file))
15976 + if (au_test_loopback_kthread()) {
15977 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15978 + if (file->f_mapping != h_file->f_mapping) {
15979 + file->f_mapping = h_file->f_mapping;
15980 + smp_mb(); /* unnecessary? */
15983 + fi_read_unlock(file);
15985 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15986 + /* todo: necessary? */
15987 + /* file->f_ra = h_file->f_ra; */
15988 + au_read_post(inode, h_file);
15991 + si_read_unlock(sb);
15995 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15998 + struct au_write_pre wpre;
15999 + struct inode *inode;
16000 + struct file *file, *h_file;
16002 + file = kio->ki_filp;
16003 + inode = file_inode(file);
16004 + au_mtx_and_read_lock(inode);
16007 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16008 + err = PTR_ERR(h_file);
16009 + if (IS_ERR(h_file))
16012 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
16013 + au_write_post(inode, h_file, &wpre, err);
16016 + si_read_unlock(inode->i_sb);
16017 + inode_unlock(inode);
16021 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
16022 + struct pipe_inode_info *pipe, size_t len,
16023 + unsigned int flags)
16026 + struct file *h_file;
16027 + struct inode *inode;
16028 + struct super_block *sb;
16030 + inode = file_inode(file);
16031 + sb = inode->i_sb;
16032 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16034 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16035 + err = PTR_ERR(h_file);
16036 + if (IS_ERR(h_file))
16039 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
16040 + /* todo: necessary? */
16041 + /* file->f_ra = h_file->f_ra; */
16042 + au_read_post(inode, h_file);
16045 + si_read_unlock(sb);
16050 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
16051 + size_t len, unsigned int flags)
16054 + struct au_write_pre wpre;
16055 + struct inode *inode;
16056 + struct file *h_file;
16058 + inode = file_inode(file);
16059 + au_mtx_and_read_lock(inode);
16062 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16063 + err = PTR_ERR(h_file);
16064 + if (IS_ERR(h_file))
16067 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
16068 + au_write_post(inode, h_file, &wpre, err);
16071 + si_read_unlock(inode->i_sb);
16072 + inode_unlock(inode);
16076 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
16080 + struct au_write_pre wpre;
16081 + struct inode *inode;
16082 + struct file *h_file;
16084 + inode = file_inode(file);
16085 + au_mtx_and_read_lock(inode);
16088 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16089 + err = PTR_ERR(h_file);
16090 + if (IS_ERR(h_file))
16094 + err = vfs_fallocate(h_file, mode, offset, len);
16096 + au_write_post(inode, h_file, &wpre, /*written*/1);
16099 + si_read_unlock(inode->i_sb);
16100 + inode_unlock(inode);
16104 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
16105 + struct file *dst, loff_t dst_pos,
16106 + size_t len, unsigned int flags)
16109 + struct au_write_pre wpre;
16110 + enum { SRC, DST };
16112 + struct inode *inode;
16113 + struct file *h_file;
16114 + struct super_block *h_sb;
16116 +#define a_src a[SRC]
16117 +#define a_dst a[DST]
16120 + a_src.inode = file_inode(src);
16121 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
16123 + a_dst.inode = file_inode(dst);
16124 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
16127 + au_mtx_and_read_lock(a_dst.inode);
16129 + * in order to match the order in di_write_lock2_{child,parent}(),
16130 + * use f_path.dentry for this comparison.
16132 + if (src->f_path.dentry < dst->f_path.dentry) {
16133 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
16134 + err = PTR_ERR(a_src.h_file);
16135 + if (IS_ERR(a_src.h_file))
16138 + wpre.lsc = AuLsc_FI_2;
16139 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16140 + err = PTR_ERR(a_dst.h_file);
16141 + if (IS_ERR(a_dst.h_file)) {
16142 + au_read_post(a_src.inode, a_src.h_file);
16146 + wpre.lsc = AuLsc_FI_1;
16147 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16148 + err = PTR_ERR(a_dst.h_file);
16149 + if (IS_ERR(a_dst.h_file))
16152 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
16153 + err = PTR_ERR(a_src.h_file);
16154 + if (IS_ERR(a_src.h_file)) {
16155 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
16162 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
16163 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
16164 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
16170 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
16171 + dst_pos, len, flags);
16174 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
16175 + fi_read_unlock(src);
16176 + au_read_post(a_src.inode, a_src.h_file);
16178 + si_read_unlock(a_dst.inode->i_sb);
16179 + inode_unlock(a_dst.inode);
16186 +/* ---------------------------------------------------------------------- */
16189 + * The locking order around current->mmap_sem.
16190 + * - in most and regular cases
16191 + * file I/O syscall -- aufs_read() or something
16192 + * -- si_rwsem for read -- mmap_sem
16193 + * (Note that [fdi]i_rwsem are released before mmap_sem).
16195 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
16196 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
16197 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
16198 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
16199 + * It means that when aufs acquires si_rwsem for write, the process should never
16200 + * acquire mmap_sem.
16202 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
16203 + * problem either since any directory is not able to be mmap-ed.
16204 + * The similar scenario is applied to aufs_readlink() too.
16207 +#if 0 /* stop calling security_file_mmap() */
16208 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
16209 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
16211 +static unsigned long au_arch_prot_conv(unsigned long flags)
16213 + /* currently ppc64 only */
16214 +#ifdef CONFIG_PPC64
16215 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16216 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16217 + return AuConv_VM_PROT(flags, SAO);
16219 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16224 +static unsigned long au_prot_conv(unsigned long flags)
16226 + return AuConv_VM_PROT(flags, READ)
16227 + | AuConv_VM_PROT(flags, WRITE)
16228 + | AuConv_VM_PROT(flags, EXEC)
16229 + | au_arch_prot_conv(flags);
16232 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16233 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16235 +static unsigned long au_flag_conv(unsigned long flags)
16237 + return AuConv_VM_MAP(flags, GROWSDOWN)
16238 + | AuConv_VM_MAP(flags, DENYWRITE)
16239 + | AuConv_VM_MAP(flags, LOCKED);
16243 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16246 + const unsigned char wlock
16247 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16248 + struct super_block *sb;
16249 + struct file *h_file;
16250 + struct inode *inode;
16252 + AuDbgVmRegion(file, vma);
16254 + inode = file_inode(file);
16255 + sb = inode->i_sb;
16257 + si_read_lock(sb, AuLock_NOPLMW);
16259 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16261 + err = PTR_ERR(h_file);
16262 + if (IS_ERR(h_file))
16266 + au_set_mmapped(file);
16267 + au_vm_file_reset(vma, h_file);
16269 + * we cannot call security_mmap_file() here since it may acquire
16270 + * mmap_sem or i_mutex.
16272 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16273 + * au_flag_conv(vma->vm_flags));
16276 + err = call_mmap(h_file, vma);
16278 + au_vm_prfile_set(vma, file);
16279 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16280 + goto out_fput; /* success */
16282 + au_unset_mmapped(file);
16283 + au_vm_file_reset(vma, file);
16287 + ii_write_unlock(inode);
16292 + si_read_unlock(sb);
16298 +/* ---------------------------------------------------------------------- */
16300 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16304 + struct au_write_pre wpre;
16305 + struct inode *inode;
16306 + struct file *h_file;
16308 + err = 0; /* -EBADF; */ /* posix? */
16309 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16312 + inode = file_inode(file);
16313 + au_mtx_and_read_lock(inode);
16316 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16317 + err = PTR_ERR(h_file);
16318 + if (IS_ERR(h_file))
16321 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16322 + au_write_post(inode, h_file, &wpre, /*written*/0);
16325 + si_read_unlock(inode->i_sb);
16326 + inode_unlock(inode);
16331 +static int aufs_fasync(int fd, struct file *file, int flag)
16334 + struct file *h_file;
16335 + struct super_block *sb;
16337 + sb = file->f_path.dentry->d_sb;
16338 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16340 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16341 + err = PTR_ERR(h_file);
16342 + if (IS_ERR(h_file))
16345 + if (h_file->f_op->fasync)
16346 + err = h_file->f_op->fasync(fd, h_file, flag);
16347 + fput(h_file); /* instead of au_read_post() */
16350 + si_read_unlock(sb);
16354 +static int aufs_setfl(struct file *file, unsigned long arg)
16357 + struct file *h_file;
16358 + struct super_block *sb;
16360 + sb = file->f_path.dentry->d_sb;
16361 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16363 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16364 + err = PTR_ERR(h_file);
16365 + if (IS_ERR(h_file))
16368 + /* stop calling h_file->fasync */
16369 + arg |= vfsub_file_flags(file) & FASYNC;
16370 + err = setfl(/*unused fd*/-1, h_file, arg);
16371 + fput(h_file); /* instead of au_read_post() */
16374 + si_read_unlock(sb);
16378 +/* ---------------------------------------------------------------------- */
16380 +/* no one supports this operation, currently */
16382 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16383 + size_t len, loff_t *pos, int more)
16388 +/* ---------------------------------------------------------------------- */
16390 +const struct file_operations aufs_file_fop = {
16391 + .owner = THIS_MODULE,
16393 + .llseek = default_llseek,
16395 + .read = aufs_read,
16396 + .write = aufs_write,
16397 + .read_iter = aufs_read_iter,
16398 + .write_iter = aufs_write_iter,
16400 +#ifdef CONFIG_AUFS_POLL
16401 + .poll = aufs_poll,
16403 + .unlocked_ioctl = aufs_ioctl_nondir,
16404 +#ifdef CONFIG_COMPAT
16405 + .compat_ioctl = aufs_compat_ioctl_nondir,
16407 + .mmap = aufs_mmap,
16408 + .open = aufs_open_nondir,
16409 + .flush = aufs_flush_nondir,
16410 + .release = aufs_release_nondir,
16411 + .fsync = aufs_fsync_nondir,
16412 + .fasync = aufs_fasync,
16413 + /* .sendpage = aufs_sendpage, */
16414 + .setfl = aufs_setfl,
16415 + .splice_write = aufs_splice_write,
16416 + .splice_read = aufs_splice_read,
16418 + .aio_splice_write = aufs_aio_splice_write,
16419 + .aio_splice_read = aufs_aio_splice_read,
16421 + .fallocate = aufs_fallocate,
16422 + .copy_file_range = aufs_copy_file_range
16424 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16425 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16426 +++ linux/fs/aufs/fstype.h 2019-03-05 12:13:00.139224339 +0100
16428 +/* SPDX-License-Identifier: GPL-2.0 */
16430 + * Copyright (C) 2005-2019 Junjiro R. Okajima
16432 + * This program, aufs is free software; you can redistribute it and/or modify
16433 + * it under the terms of the GNU General Public License as published by
16434 + * the Free Software Foundation; either version 2 of the License, or
16435 + * (at your option) any later version.
16437 + * This program is distributed in the hope that it will be useful,
16438 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16439 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16440 + * GNU General Public License for more details.
16442 + * You should have received a copy of the GNU General Public License
16443 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16447 + * judging filesystem type
16450 +#ifndef __AUFS_FSTYPE_H__
16451 +#define __AUFS_FSTYPE_H__
16455 +#include <linux/fs.h>
16456 +#include <linux/magic.h>
16457 +#include <linux/nfs_fs.h>
16458 +#include <linux/romfs_fs.h>
16460 +static inline int au_test_aufs(struct super_block *sb)
16462 + return sb->s_magic == AUFS_SUPER_MAGIC;
16465 +static inline const char *au_sbtype(struct super_block *sb)
16467 + return sb->s_type->name;
16470 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16472 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16473 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16479 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16481 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16482 + return sb->s_magic == ROMFS_MAGIC;
16488 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16490 +#if IS_ENABLED(CONFIG_CRAMFS)
16491 + return sb->s_magic == CRAMFS_MAGIC;
16496 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16498 +#if IS_ENABLED(CONFIG_NFS_FS)
16499 + return sb->s_magic == NFS_SUPER_MAGIC;
16505 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16507 +#if IS_ENABLED(CONFIG_FUSE_FS)
16508 + return sb->s_magic == FUSE_SUPER_MAGIC;
16514 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16516 +#if IS_ENABLED(CONFIG_XFS_FS)
16517 + return sb->s_magic == XFS_SB_MAGIC;
16523 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16525 +#ifdef CONFIG_TMPFS
16526 + return sb->s_magic == TMPFS_MAGIC;
16532 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16534 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16535 + return !strcmp(au_sbtype(sb), "ecryptfs");
16541 +static inline int au_test_ramfs(struct super_block *sb)
16543 + return sb->s_magic == RAMFS_MAGIC;
16546 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16548 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16549 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16555 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16557 +#ifdef CONFIG_PROC_FS
16558 + return sb->s_magic == PROC_SUPER_MAGIC;
16564 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16566 +#ifdef CONFIG_SYSFS
16567 + return sb->s_magic == SYSFS_MAGIC;
16573 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16575 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16576 + return sb->s_magic == CONFIGFS_MAGIC;
16582 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16584 +#if IS_ENABLED(CONFIG_MINIX_FS)
16585 + return sb->s_magic == MINIX3_SUPER_MAGIC
16586 + || sb->s_magic == MINIX2_SUPER_MAGIC
16587 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16588 + || sb->s_magic == MINIX_SUPER_MAGIC
16589 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16595 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16597 +#if IS_ENABLED(CONFIG_FAT_FS)
16598 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16604 +static inline int au_test_msdos(struct super_block *sb)
16606 + return au_test_fat(sb);
16609 +static inline int au_test_vfat(struct super_block *sb)
16611 + return au_test_fat(sb);
16614 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16616 +#ifdef CONFIG_SECURITYFS
16617 + return sb->s_magic == SECURITYFS_MAGIC;
16623 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16625 +#if IS_ENABLED(CONFIG_SQUASHFS)
16626 + return sb->s_magic == SQUASHFS_MAGIC;
16632 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16634 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16635 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16641 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16643 +#if IS_ENABLED(CONFIG_XENFS)
16644 + return sb->s_magic == XENFS_SUPER_MAGIC;
16650 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16652 +#ifdef CONFIG_DEBUG_FS
16653 + return sb->s_magic == DEBUGFS_MAGIC;
16659 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16661 +#if IS_ENABLED(CONFIG_NILFS)
16662 + return sb->s_magic == NILFS_SUPER_MAGIC;
16668 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16670 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16671 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16677 +/* ---------------------------------------------------------------------- */
16679 + * they can't be an aufs branch.
16681 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16684 +#ifndef CONFIG_AUFS_BR_RAMFS
16685 + au_test_ramfs(sb) ||
16687 + au_test_procfs(sb)
16688 + || au_test_sysfs(sb)
16689 + || au_test_configfs(sb)
16690 + || au_test_debugfs(sb)
16691 + || au_test_securityfs(sb)
16692 + || au_test_xenfs(sb)
16693 + || au_test_ecryptfs(sb)
16694 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16695 + || au_test_aufs(sb); /* will be supported in next version */
16698 +static inline int au_test_fs_remote(struct super_block *sb)
16700 + return !au_test_tmpfs(sb)
16701 +#ifdef CONFIG_AUFS_BR_RAMFS
16702 + && !au_test_ramfs(sb)
16704 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16707 +/* ---------------------------------------------------------------------- */
16710 + * Note: these functions (below) are created after reading ->getattr() in all
16711 + * filesystems under linux/fs. it means we have to do so in every update...
16715 + * some filesystems require getattr to refresh the inode attributes before
16717 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16718 + * and leave the work for d_revalidate()
16720 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16722 + return au_test_nfs(sb)
16723 + || au_test_fuse(sb)
16724 + /* || au_test_btrfs(sb) */ /* untested */
16729 + * filesystems which don't maintain i_size or i_blocks.
16731 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16733 + return au_test_xfs(sb)
16734 + || au_test_btrfs(sb)
16735 + || au_test_ubifs(sb)
16736 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16737 + /* || au_test_minix(sb) */ /* untested */
16742 + * filesystems which don't store the correct value in some of their inode
16745 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16747 + return au_test_fs_bad_iattr_size(sb)
16748 + || au_test_fat(sb)
16749 + || au_test_msdos(sb)
16750 + || au_test_vfat(sb);
16753 +/* they don't check i_nlink in link(2) */
16754 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16756 + return au_test_tmpfs(sb)
16757 +#ifdef CONFIG_AUFS_BR_RAMFS
16758 + || au_test_ramfs(sb)
16760 + || au_test_ubifs(sb)
16761 + || au_test_hfsplus(sb);
16765 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16767 +static inline int au_test_fs_notime(struct super_block *sb)
16769 + return au_test_nfs(sb)
16770 + || au_test_fuse(sb)
16771 + || au_test_ubifs(sb)
16775 +/* temporary support for i#1 in cramfs */
16776 +static inline int au_test_fs_unique_ino(struct inode *inode)
16778 + if (au_test_cramfs(inode->i_sb))
16779 + return inode->i_ino != 1;
16783 +/* ---------------------------------------------------------------------- */
16786 + * the filesystem where the xino files placed must support i/o after unlink and
16787 + * maintain i_size and i_blocks.
16789 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16791 + return au_test_fs_remote(sb)
16792 + || au_test_fs_bad_iattr_size(sb)
16793 + /* don't want unnecessary work for xino */
16794 + || au_test_aufs(sb)
16795 + || au_test_ecryptfs(sb)
16796 + || au_test_nilfs(sb);
16799 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16801 + return au_test_tmpfs(sb)
16802 + || au_test_ramfs(sb);
16806 + * test if the @sb is real-readonly.
16808 +static inline int au_test_fs_rr(struct super_block *sb)
16810 + return au_test_squashfs(sb)
16811 + || au_test_iso9660(sb)
16812 + || au_test_cramfs(sb)
16813 + || au_test_romfs(sb);
16817 + * test if the @inode is nfs with 'noacl' option
16818 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16820 +static inline int au_test_nfs_noacl(struct inode *inode)
16822 + return au_test_nfs(inode->i_sb)
16823 + /* && IS_POSIXACL(inode) */
16824 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16827 +#endif /* __KERNEL__ */
16828 +#endif /* __AUFS_FSTYPE_H__ */
16829 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16830 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16831 +++ linux/fs/aufs/hbl.h 2019-03-05 12:13:00.139224339 +0100
16833 +/* SPDX-License-Identifier: GPL-2.0 */
16835 + * Copyright (C) 2017-2019 Junjiro R. Okajima
16837 + * This program, aufs is free software; you can redistribute it and/or modify
16838 + * it under the terms of the GNU General Public License as published by
16839 + * the Free Software Foundation; either version 2 of the License, or
16840 + * (at your option) any later version.
16842 + * This program is distributed in the hope that it will be useful,
16843 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16844 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16845 + * GNU General Public License for more details.
16847 + * You should have received a copy of the GNU General Public License
16848 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16852 + * helpers for hlist_bl.h
16855 +#ifndef __AUFS_HBL_H__
16856 +#define __AUFS_HBL_H__
16860 +#include <linux/list_bl.h>
16862 +static inline void au_hbl_add(struct hlist_bl_node *node,
16863 + struct hlist_bl_head *hbl)
16865 + hlist_bl_lock(hbl);
16866 + hlist_bl_add_head(node, hbl);
16867 + hlist_bl_unlock(hbl);
16870 +static inline void au_hbl_del(struct hlist_bl_node *node,
16871 + struct hlist_bl_head *hbl)
16873 + hlist_bl_lock(hbl);
16874 + hlist_bl_del(node);
16875 + hlist_bl_unlock(hbl);
16878 +#define au_hbl_for_each(pos, head) \
16879 + for (pos = hlist_bl_first(head); \
16883 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16885 + unsigned long cnt;
16886 + struct hlist_bl_node *pos;
16889 + hlist_bl_lock(hbl);
16890 + au_hbl_for_each(pos, hbl)
16892 + hlist_bl_unlock(hbl);
16896 +#endif /* __KERNEL__ */
16897 +#endif /* __AUFS_HBL_H__ */
16898 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16899 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16900 +++ linux/fs/aufs/hfsnotify.c 2019-03-05 12:13:00.139224339 +0100
16902 +// SPDX-License-Identifier: GPL-2.0
16904 + * Copyright (C) 2005-2019 Junjiro R. Okajima
16906 + * This program, aufs is free software; you can redistribute it and/or modify
16907 + * it under the terms of the GNU General Public License as published by
16908 + * the Free Software Foundation; either version 2 of the License, or
16909 + * (at your option) any later version.
16911 + * This program is distributed in the hope that it will be useful,
16912 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16913 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16914 + * GNU General Public License for more details.
16916 + * You should have received a copy of the GNU General Public License
16917 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16921 + * fsnotify for the lower directories
16926 +/* FS_IN_IGNORED is unnecessary */
16927 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16928 + | FS_CREATE | FS_EVENT_ON_CHILD);
16929 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16930 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16932 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16934 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16936 + /* AuDbg("here\n"); */
16937 + au_cache_free_hnotify(hn);
16938 + smp_mb__before_atomic(); /* for atomic64_dec */
16939 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16940 + wake_up(&au_hfsn_wq);
16943 +static int au_hfsn_alloc(struct au_hinode *hinode)
16946 + struct au_hnotify *hn;
16947 + struct super_block *sb;
16948 + struct au_branch *br;
16949 + struct fsnotify_mark *mark;
16950 + aufs_bindex_t bindex;
16952 + hn = hinode->hi_notify;
16953 + sb = hn->hn_aufs_inode->i_sb;
16954 + bindex = au_br_index(sb, hinode->hi_id);
16955 + br = au_sbr(sb, bindex);
16956 + AuDebugOn(!br->br_hfsn);
16958 + mark = &hn->hn_mark;
16959 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16960 + mark->mask = AuHfsnMask;
16962 + * by udba rename or rmdir, aufs assign a new inode to the known
16963 + * h_inode, so specify 1 to allow dups.
16966 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16972 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16974 + struct fsnotify_mark *mark;
16975 + unsigned long long ull;
16976 + struct fsnotify_group *group;
16978 + ull = atomic64_inc_return(&au_hfsn_ifree);
16981 + mark = &hn->hn_mark;
16982 + spin_lock(&mark->lock);
16983 + group = mark->group;
16984 + fsnotify_get_group(group);
16985 + spin_unlock(&mark->lock);
16987 + fsnotify_destroy_mark(mark, group);
16988 + fsnotify_put_mark(mark);
16989 + fsnotify_put_group(group);
16992 + /* free hn by myself */
16996 +/* ---------------------------------------------------------------------- */
16998 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
17000 + struct fsnotify_mark *mark;
17002 + mark = &hinode->hi_notify->hn_mark;
17003 + spin_lock(&mark->lock);
17005 + AuDebugOn(mark->mask & AuHfsnMask);
17006 + mark->mask |= AuHfsnMask;
17008 + AuDebugOn(!(mark->mask & AuHfsnMask));
17009 + mark->mask &= ~AuHfsnMask;
17011 + spin_unlock(&mark->lock);
17012 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
17015 +/* ---------------------------------------------------------------------- */
17017 +/* #define AuDbgHnotify */
17018 +#ifdef AuDbgHnotify
17019 +static char *au_hfsn_name(u32 mask)
17021 +#ifdef CONFIG_AUFS_DEBUG
17022 +#define test_ret(flag) \
17024 + if (mask & flag) \
17027 + test_ret(FS_ACCESS);
17028 + test_ret(FS_MODIFY);
17029 + test_ret(FS_ATTRIB);
17030 + test_ret(FS_CLOSE_WRITE);
17031 + test_ret(FS_CLOSE_NOWRITE);
17032 + test_ret(FS_OPEN);
17033 + test_ret(FS_MOVED_FROM);
17034 + test_ret(FS_MOVED_TO);
17035 + test_ret(FS_CREATE);
17036 + test_ret(FS_DELETE);
17037 + test_ret(FS_DELETE_SELF);
17038 + test_ret(FS_MOVE_SELF);
17039 + test_ret(FS_UNMOUNT);
17040 + test_ret(FS_Q_OVERFLOW);
17041 + test_ret(FS_IN_IGNORED);
17042 + test_ret(FS_ISDIR);
17043 + test_ret(FS_IN_ONESHOT);
17044 + test_ret(FS_EVENT_ON_CHILD);
17053 +/* ---------------------------------------------------------------------- */
17055 +static void au_hfsn_free_group(struct fsnotify_group *group)
17057 + struct au_br_hfsnotify *hfsn = group->private;
17059 + /* AuDbg("here\n"); */
17060 + au_kfree_try_rcu(hfsn);
17063 +static int au_hfsn_handle_event(struct fsnotify_group *group,
17064 + struct inode *inode,
17065 + u32 mask, const void *data, int data_type,
17066 + const unsigned char *file_name, u32 cookie,
17067 + struct fsnotify_iter_info *iter_info)
17070 + struct au_hnotify *hnotify;
17071 + struct inode *h_dir, *h_inode;
17072 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
17073 + struct fsnotify_mark *inode_mark;
17075 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
17078 + /* if FS_UNMOUNT happens, there must be another bug */
17079 + AuDebugOn(mask & FS_UNMOUNT);
17080 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
17085 +#ifdef AuDbgHnotify
17087 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
17088 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
17089 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
17090 + h_dir->i_ino, mask, au_hfsn_name(mask),
17091 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
17092 + /* WARN_ON(1); */
17097 + inode_mark = fsnotify_iter_inode_mark(iter_info);
17098 + AuDebugOn(!inode_mark);
17099 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
17100 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
17106 +static struct fsnotify_ops au_hfsn_ops = {
17107 + .handle_event = au_hfsn_handle_event,
17108 + .free_group_priv = au_hfsn_free_group,
17109 + .free_mark = au_hfsn_free_mark
17112 +/* ---------------------------------------------------------------------- */
17114 +static void au_hfsn_fin_br(struct au_branch *br)
17116 + struct au_br_hfsnotify *hfsn;
17118 + hfsn = br->br_hfsn;
17121 + fsnotify_put_group(hfsn->hfsn_group);
17126 +static int au_hfsn_init_br(struct au_branch *br, int perm)
17129 + struct fsnotify_group *group;
17130 + struct au_br_hfsnotify *hfsn;
17133 + br->br_hfsn = NULL;
17134 + if (!au_br_hnotifyable(perm))
17138 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
17139 + if (unlikely(!hfsn))
17143 + group = fsnotify_alloc_group(&au_hfsn_ops);
17144 + if (IS_ERR(group)) {
17145 + err = PTR_ERR(group);
17146 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
17150 + group->private = hfsn;
17151 + hfsn->hfsn_group = group;
17152 + br->br_hfsn = hfsn;
17153 + goto out; /* success */
17156 + au_kfree_try_rcu(hfsn);
17161 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
17166 + if (!br->br_hfsn)
17167 + err = au_hfsn_init_br(br, perm);
17172 +/* ---------------------------------------------------------------------- */
17174 +static void au_hfsn_fin(void)
17176 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
17177 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
17180 +const struct au_hnotify_op au_hnotify_op = {
17181 + .ctl = au_hfsn_ctl,
17182 + .alloc = au_hfsn_alloc,
17183 + .free = au_hfsn_free,
17185 + .fin = au_hfsn_fin,
17187 + .reset_br = au_hfsn_reset_br,
17188 + .fin_br = au_hfsn_fin_br,
17189 + .init_br = au_hfsn_init_br
17191 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
17192 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
17193 +++ linux/fs/aufs/hfsplus.c 2019-03-05 12:13:00.139224339 +0100
17195 +// SPDX-License-Identifier: GPL-2.0
17197 + * Copyright (C) 2010-2019 Junjiro R. Okajima
17199 + * This program, aufs is free software; you can redistribute it and/or modify
17200 + * it under the terms of the GNU General Public License as published by
17201 + * the Free Software Foundation; either version 2 of the License, or
17202 + * (at your option) any later version.
17204 + * This program is distributed in the hope that it will be useful,
17205 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17206 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17207 + * GNU General Public License for more details.
17209 + * You should have received a copy of the GNU General Public License
17210 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17214 + * special support for filesystems which acquires an inode mutex
17215 + * at final closing a file, eg, hfsplus.
17217 + * This trick is very simple and stupid, just to open the file before really
17218 + * necessary open to tell hfsplus that this is not the final closing.
17219 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
17220 + * and au_h_open_post() after releasing it.
17225 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
17228 + struct file *h_file;
17229 + struct dentry *h_dentry;
17231 + h_dentry = au_h_dptr(dentry, bindex);
17232 + AuDebugOn(!h_dentry);
17233 + AuDebugOn(d_is_negative(h_dentry));
17236 + if (au_test_hfsplus(h_dentry->d_sb)
17237 + && d_is_reg(h_dentry))
17238 + h_file = au_h_open(dentry, bindex,
17239 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17240 + /*file*/NULL, force_wr);
17244 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17245 + struct file *h_file)
17247 + struct au_branch *br;
17251 + br = au_sbr(dentry->d_sb, bindex);
17252 + au_lcnt_dec(&br->br_nfiles);
17255 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17256 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17257 +++ linux/fs/aufs/hnotify.c 2019-03-05 12:13:00.139224339 +0100
17259 +// SPDX-License-Identifier: GPL-2.0
17261 + * Copyright (C) 2005-2019 Junjiro R. Okajima
17263 + * This program, aufs is free software; you can redistribute it and/or modify
17264 + * it under the terms of the GNU General Public License as published by
17265 + * the Free Software Foundation; either version 2 of the License, or
17266 + * (at your option) any later version.
17268 + * This program is distributed in the hope that it will be useful,
17269 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17270 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17271 + * GNU General Public License for more details.
17273 + * You should have received a copy of the GNU General Public License
17274 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17278 + * abstraction to notify the direct changes on lower directories
17283 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17286 + struct au_hnotify *hn;
17289 + hn = au_cache_alloc_hnotify();
17291 + hn->hn_aufs_inode = inode;
17292 + hinode->hi_notify = hn;
17293 + err = au_hnotify_op.alloc(hinode);
17295 + if (unlikely(err)) {
17296 + hinode->hi_notify = NULL;
17297 + au_cache_free_hnotify(hn);
17299 + * The upper dir was removed by udba, but the same named
17300 + * dir left. In this case, aufs assigns a new inode
17301 + * number and set the monitor again.
17302 + * For the lower dir, the old monitor is still left.
17304 + if (err == -EEXIST)
17313 +void au_hn_free(struct au_hinode *hinode)
17315 + struct au_hnotify *hn;
17317 + hn = hinode->hi_notify;
17319 + hinode->hi_notify = NULL;
17320 + if (au_hnotify_op.free(hinode, hn))
17321 + au_cache_free_hnotify(hn);
17325 +/* ---------------------------------------------------------------------- */
17327 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17329 + if (hinode->hi_notify)
17330 + au_hnotify_op.ctl(hinode, do_set);
17333 +void au_hn_reset(struct inode *inode, unsigned int flags)
17335 + aufs_bindex_t bindex, bbot;
17336 + struct inode *hi;
17337 + struct dentry *iwhdentry;
17339 + bbot = au_ibbot(inode);
17340 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17341 + hi = au_h_iptr(inode, bindex);
17345 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17346 + iwhdentry = au_hi_wh(inode, bindex);
17350 + au_set_h_iptr(inode, bindex, NULL, 0);
17351 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17352 + flags & ~AuHi_XINO);
17355 + /* inode_unlock(hi); */
17359 +/* ---------------------------------------------------------------------- */
17361 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17364 + aufs_bindex_t bindex, bbot, bfound, btop;
17365 + struct inode *h_i;
17368 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17369 + pr_warn("branch root dir was changed\n");
17374 + bbot = au_ibbot(inode);
17375 + btop = au_ibtop(inode);
17376 +#if 0 /* reserved for future use */
17377 + if (bindex == bbot) {
17378 + /* keep this ino in rename case */
17382 + for (bindex = btop; bindex <= bbot; bindex++)
17383 + if (au_h_iptr(inode, bindex) == h_inode) {
17390 + for (bindex = btop; bindex <= bbot; bindex++) {
17391 + h_i = au_h_iptr(inode, bindex);
17395 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17396 + /* ignore this error */
17397 + /* bad action? */
17400 + /* children inode number will be broken */
17407 +static int hn_gen_tree(struct dentry *dentry)
17409 + int err, i, j, ndentry;
17410 + struct au_dcsub_pages dpages;
17411 + struct au_dpage *dpage;
17412 + struct dentry **dentries;
17414 + err = au_dpages_init(&dpages, GFP_NOFS);
17415 + if (unlikely(err))
17417 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17418 + if (unlikely(err))
17421 + for (i = 0; i < dpages.ndpage; i++) {
17422 + dpage = dpages.dpages + i;
17423 + dentries = dpage->dentries;
17424 + ndentry = dpage->ndentry;
17425 + for (j = 0; j < ndentry; j++) {
17426 + struct dentry *d;
17433 + if (d_really_is_positive(d))
17434 + /* todo: reset children xino?
17435 + cached children only? */
17436 + au_iigen_dec(d_inode(d));
17441 + au_dpages_free(&dpages);
17444 + /* discard children */
17445 + dentry_unhash(dentry);
17453 + * return 0 if processed.
17455 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17456 + const unsigned int isdir)
17459 + struct dentry *d;
17460 + struct qstr *dname;
17463 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17464 + pr_warn("branch root dir was changed\n");
17470 + AuDebugOn(!name);
17471 + au_iigen_dec(inode);
17472 + spin_lock(&inode->i_lock);
17473 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17474 + spin_lock(&d->d_lock);
17475 + dname = &d->d_name;
17476 + if (dname->len != nlen
17477 + && memcmp(dname->name, name, nlen)) {
17478 + spin_unlock(&d->d_lock);
17483 + spin_unlock(&d->d_lock);
17486 + spin_unlock(&inode->i_lock);
17488 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17489 + d = d_find_any_alias(inode);
17491 + au_iigen_dec(inode);
17495 + spin_lock(&d->d_lock);
17496 + dname = &d->d_name;
17497 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17498 + spin_unlock(&d->d_lock);
17499 + err = hn_gen_tree(d);
17500 + spin_lock(&d->d_lock);
17502 + spin_unlock(&d->d_lock);
17511 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17515 + if (IS_ROOT(dentry)) {
17516 + pr_warn("branch root dir was changed\n");
17522 + au_digen_dec(dentry);
17523 + if (d_really_is_positive(dentry))
17524 + au_iigen_dec(d_inode(dentry));
17526 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17527 + if (d_really_is_positive(dentry))
17528 + err = hn_gen_tree(dentry);
17535 +/* ---------------------------------------------------------------------- */
17537 +/* hnotify job flags */
17538 +#define AuHnJob_XINO0 1
17539 +#define AuHnJob_GEN (1 << 1)
17540 +#define AuHnJob_DIRENT (1 << 2)
17541 +#define AuHnJob_ISDIR (1 << 3)
17542 +#define AuHnJob_TRYXINO0 (1 << 4)
17543 +#define AuHnJob_MNTPNT (1 << 5)
17544 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17545 +#define au_fset_hnjob(flags, name) \
17546 + do { (flags) |= AuHnJob_##name; } while (0)
17547 +#define au_fclr_hnjob(flags, name) \
17548 + do { (flags) &= ~AuHnJob_##name; } while (0)
17556 +struct au_hnotify_args {
17557 + struct inode *h_dir, *dir, *h_child_inode;
17559 + unsigned int flags[AuHnLast];
17560 + unsigned int h_child_nlen;
17561 + char h_child_name[];
17564 +struct hn_job_args {
17565 + unsigned int flags;
17566 + struct inode *inode, *h_inode, *dir, *h_dir;
17567 + struct dentry *dentry;
17572 +static int hn_job(struct hn_job_args *a)
17574 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17578 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17579 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17581 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17584 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17585 + if (!a->h_inode->i_nlink
17586 + && !(a->h_inode->i_state & I_LINKABLE))
17587 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17588 + inode_unlock_shared(a->h_inode);
17591 + /* make the generation obsolete */
17592 + if (au_ftest_hnjob(a->flags, GEN)) {
17595 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17597 + if (e && a->dentry)
17598 + hn_gen_by_name(a->dentry, isdir);
17599 + /* ignore this error */
17602 + /* make dir entries obsolete */
17603 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17604 + struct au_vdir *vdir;
17606 + vdir = au_ivdir(a->inode);
17608 + vdir->vd_jiffy = 0;
17609 + /* IMustLock(a->inode); */
17610 + /* inode_inc_iversion(a->inode); */
17613 + /* can do nothing but warn */
17614 + if (au_ftest_hnjob(a->flags, MNTPNT)
17616 + && d_mountpoint(a->dentry))
17617 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17622 +/* ---------------------------------------------------------------------- */
17624 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17625 + struct inode *dir)
17627 + struct dentry *dentry, *d, *parent;
17628 + struct qstr *dname;
17630 + parent = d_find_any_alias(dir);
17635 + spin_lock(&parent->d_lock);
17636 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17637 + /* AuDbg("%pd\n", d); */
17638 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17639 + dname = &d->d_name;
17640 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17641 + goto cont_unlock;
17645 + goto cont_unlock;
17646 + if (au_dcount(d) > 0) {
17647 + dentry = dget_dlock(d);
17648 + spin_unlock(&d->d_lock);
17653 + spin_unlock(&d->d_lock);
17655 + spin_unlock(&parent->d_lock);
17659 + di_write_lock_child(dentry);
17664 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17665 + aufs_bindex_t bindex, ino_t h_ino)
17667 + struct inode *inode;
17672 + err = au_xino_read(sb, bindex, h_ino, &ino);
17674 + inode = ilookup(sb, ino);
17678 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17679 + pr_warn("wrong root branch\n");
17685 + ii_write_lock_child(inode);
17691 +static void au_hn_bh(void *_args)
17693 + struct au_hnotify_args *a = _args;
17694 + struct super_block *sb;
17695 + aufs_bindex_t bindex, bbot, bfound;
17696 + unsigned char xino, try_iput;
17698 + struct inode *inode;
17700 + struct hn_job_args args;
17701 + struct dentry *dentry;
17702 + struct au_sbinfo *sbinfo;
17704 + AuDebugOn(!_args);
17705 + AuDebugOn(!a->h_dir);
17706 + AuDebugOn(!a->dir);
17707 + AuDebugOn(!a->mask);
17708 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17709 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17710 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17715 + * do not lock a->dir->i_mutex here
17716 + * because of d_revalidate() may cause a deadlock.
17718 + sb = a->dir->i_sb;
17720 + sbinfo = au_sbi(sb);
17721 + AuDebugOn(!sbinfo);
17722 + si_write_lock(sb, AuLock_NOPLMW);
17724 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17725 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17726 + case FS_MOVED_FROM:
17727 + case FS_MOVED_TO:
17728 + AuWarn1("DIRREN with UDBA may not work correctly "
17729 + "for the direct rename(2)\n");
17732 + ii_read_lock_parent(a->dir);
17734 + bbot = au_ibbot(a->dir);
17735 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17736 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17740 + ii_read_unlock(a->dir);
17741 + if (unlikely(bfound < 0))
17744 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17746 + if (a->h_child_inode)
17747 + h_ino = a->h_child_inode->i_ino;
17749 + if (a->h_child_nlen
17750 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17751 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17752 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17755 + if (dentry && d_really_is_positive(dentry))
17756 + inode = d_inode(dentry);
17757 + if (xino && !inode && h_ino
17758 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17759 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17760 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17761 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17765 + args.flags = a->flags[AuHn_CHILD];
17766 + args.dentry = dentry;
17767 + args.inode = inode;
17768 + args.h_inode = a->h_child_inode;
17769 + args.dir = a->dir;
17770 + args.h_dir = a->h_dir;
17771 + args.h_name = a->h_child_name;
17772 + args.h_nlen = a->h_child_nlen;
17773 + err = hn_job(&args);
17775 + if (au_di(dentry))
17776 + di_write_unlock(dentry);
17779 + if (inode && try_iput) {
17780 + ii_write_unlock(inode);
17784 + ii_write_lock_parent(a->dir);
17785 + args.flags = a->flags[AuHn_PARENT];
17786 + args.dentry = NULL;
17787 + args.inode = a->dir;
17788 + args.h_inode = a->h_dir;
17790 + args.h_dir = NULL;
17791 + args.h_name = NULL;
17793 + err = hn_job(&args);
17794 + ii_write_unlock(a->dir);
17797 + iput(a->h_child_inode);
17800 + si_write_unlock(sb);
17801 + au_nwt_done(&sbinfo->si_nowait);
17805 +/* ---------------------------------------------------------------------- */
17807 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17808 + struct qstr *h_child_qstr, struct inode *h_child_inode)
17811 + unsigned int flags[AuHnLast], f;
17812 + unsigned char isdir, isroot, wh;
17813 + struct inode *dir;
17814 + struct au_hnotify_args *args;
17815 + char *p, *h_child_name;
17818 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17819 + dir = igrab(hnotify->hn_aufs_inode);
17823 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17825 + h_child_name = (void *)h_child_qstr->name;
17826 + len = h_child_qstr->len;
17827 + if (h_child_name) {
17828 + if (len > AUFS_WH_PFX_LEN
17829 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17830 + h_child_name += AUFS_WH_PFX_LEN;
17831 + len -= AUFS_WH_PFX_LEN;
17837 + if (h_child_inode)
17838 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17839 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17840 + flags[AuHn_CHILD] = 0;
17842 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17843 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17844 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17845 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
17846 + case FS_MOVED_FROM:
17847 + case FS_MOVED_TO:
17848 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17849 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17852 + AuDebugOn(!h_child_name);
17857 + * aufs never be able to get this child inode.
17858 + * revalidation should be in d_revalidate()
17859 + * by checking i_nlink, i_generation or d_unhashed().
17861 + AuDebugOn(!h_child_name);
17862 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17863 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17871 + h_child_inode = NULL;
17874 + /* iput() and kfree() will be called in au_hnotify() */
17875 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17876 + if (unlikely(!args)) {
17877 + AuErr1("no memory\n");
17881 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17882 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17883 + args->mask = mask;
17885 + args->h_dir = igrab(h_dir);
17886 + if (h_child_inode)
17887 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17888 + args->h_child_inode = h_child_inode;
17889 + args->h_child_nlen = len;
17891 + p = (void *)args;
17892 + p += sizeof(*args);
17893 + memcpy(p, h_child_name, len);
17897 + /* NFS fires the event for silly-renamed one from kworker */
17899 + if (!dir->i_nlink
17900 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17902 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17903 + if (unlikely(err)) {
17904 + pr_err("wkq %d\n", err);
17905 + iput(args->h_child_inode);
17906 + iput(args->h_dir);
17908 + au_kfree_rcu(args);
17915 +/* ---------------------------------------------------------------------- */
17917 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17921 + AuDebugOn(!(udba & AuOptMask_UDBA));
17924 + if (au_hnotify_op.reset_br)
17925 + err = au_hnotify_op.reset_br(udba, br, perm);
17930 +int au_hnotify_init_br(struct au_branch *br, int perm)
17935 + if (au_hnotify_op.init_br)
17936 + err = au_hnotify_op.init_br(br, perm);
17941 +void au_hnotify_fin_br(struct au_branch *br)
17943 + if (au_hnotify_op.fin_br)
17944 + au_hnotify_op.fin_br(br);
17947 +static void au_hn_destroy_cache(void)
17949 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17950 + au_cache[AuCache_HNOTIFY] = NULL;
17953 +int __init au_hnotify_init(void)
17958 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17959 + if (au_cache[AuCache_HNOTIFY]) {
17961 + if (au_hnotify_op.init)
17962 + err = au_hnotify_op.init();
17963 + if (unlikely(err))
17964 + au_hn_destroy_cache();
17970 +void au_hnotify_fin(void)
17972 + if (au_hnotify_op.fin)
17973 + au_hnotify_op.fin();
17975 + /* cf. au_cache_fin() */
17976 + if (au_cache[AuCache_HNOTIFY])
17977 + au_hn_destroy_cache();
17979 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17980 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17981 +++ linux/fs/aufs/iinfo.c 2019-03-05 12:13:00.139224339 +0100
17983 +// SPDX-License-Identifier: GPL-2.0
17985 + * Copyright (C) 2005-2019 Junjiro R. Okajima
17987 + * This program, aufs is free software; you can redistribute it and/or modify
17988 + * it under the terms of the GNU General Public License as published by
17989 + * the Free Software Foundation; either version 2 of the License, or
17990 + * (at your option) any later version.
17992 + * This program is distributed in the hope that it will be useful,
17993 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17994 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17995 + * GNU General Public License for more details.
17997 + * You should have received a copy of the GNU General Public License
17998 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18002 + * inode private data
18007 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
18009 + struct inode *h_inode;
18010 + struct au_hinode *hinode;
18012 + IiMustAnyLock(inode);
18014 + hinode = au_hinode(au_ii(inode), bindex);
18015 + h_inode = hinode->hi_inode;
18016 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
18020 +/* todo: hard/soft set? */
18021 +void au_hiput(struct au_hinode *hinode)
18023 + au_hn_free(hinode);
18024 + dput(hinode->hi_whdentry);
18025 + iput(hinode->hi_inode);
18028 +unsigned int au_hi_flags(struct inode *inode, int isdir)
18030 + unsigned int flags;
18031 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
18034 + if (au_opt_test(mnt_flags, XINO))
18035 + au_fset_hi(flags, XINO);
18036 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
18037 + au_fset_hi(flags, HNOTIFY);
18041 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18042 + struct inode *h_inode, unsigned int flags)
18044 + struct au_hinode *hinode;
18045 + struct inode *hi;
18046 + struct au_iinfo *iinfo = au_ii(inode);
18048 + IiMustWriteLock(inode);
18050 + hinode = au_hinode(iinfo, bindex);
18051 + hi = hinode->hi_inode;
18052 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
18055 + au_hiput(hinode);
18056 + hinode->hi_inode = h_inode;
18059 + struct super_block *sb = inode->i_sb;
18060 + struct au_branch *br;
18062 + AuDebugOn(inode->i_mode
18063 + && (h_inode->i_mode & S_IFMT)
18064 + != (inode->i_mode & S_IFMT));
18065 + if (bindex == iinfo->ii_btop)
18066 + au_cpup_igen(inode, h_inode);
18067 + br = au_sbr(sb, bindex);
18068 + hinode->hi_id = br->br_id;
18069 + if (au_ftest_hi(flags, XINO)) {
18070 + err = au_xino_write(sb, bindex, h_inode->i_ino,
18072 + if (unlikely(err))
18073 + AuIOErr1("failed au_xino_write() %d\n", err);
18076 + if (au_ftest_hi(flags, HNOTIFY)
18077 + && au_br_hnotifyable(br->br_perm)) {
18078 + err = au_hn_alloc(hinode, inode);
18079 + if (unlikely(err))
18080 + AuIOErr1("au_hn_alloc() %d\n", err);
18085 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18086 + struct dentry *h_wh)
18088 + struct au_hinode *hinode;
18090 + IiMustWriteLock(inode);
18092 + hinode = au_hinode(au_ii(inode), bindex);
18093 + AuDebugOn(hinode->hi_whdentry);
18094 + hinode->hi_whdentry = h_wh;
18097 +void au_update_iigen(struct inode *inode, int half)
18099 + struct au_iinfo *iinfo;
18100 + struct au_iigen *iigen;
18101 + unsigned int sigen;
18103 + sigen = au_sigen(inode->i_sb);
18104 + iinfo = au_ii(inode);
18105 + iigen = &iinfo->ii_generation;
18106 + spin_lock(&iigen->ig_spin);
18107 + iigen->ig_generation = sigen;
18109 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
18111 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
18112 + spin_unlock(&iigen->ig_spin);
18115 +/* it may be called at remount time, too */
18116 +void au_update_ibrange(struct inode *inode, int do_put_zero)
18118 + struct au_iinfo *iinfo;
18119 + aufs_bindex_t bindex, bbot;
18121 + AuDebugOn(au_is_bad_inode(inode));
18122 + IiMustWriteLock(inode);
18124 + iinfo = au_ii(inode);
18125 + if (do_put_zero && iinfo->ii_btop >= 0) {
18126 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18128 + struct inode *h_i;
18130 + h_i = au_hinode(iinfo, bindex)->hi_inode;
18133 + && !(h_i->i_state & I_LINKABLE))
18134 + au_set_h_iptr(inode, bindex, NULL, 0);
18138 + iinfo->ii_btop = -1;
18139 + iinfo->ii_bbot = -1;
18140 + bbot = au_sbbot(inode->i_sb);
18141 + for (bindex = 0; bindex <= bbot; bindex++)
18142 + if (au_hinode(iinfo, bindex)->hi_inode) {
18143 + iinfo->ii_btop = bindex;
18146 + if (iinfo->ii_btop >= 0)
18147 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
18148 + if (au_hinode(iinfo, bindex)->hi_inode) {
18149 + iinfo->ii_bbot = bindex;
18152 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
18155 +/* ---------------------------------------------------------------------- */
18157 +void au_icntnr_init_once(void *_c)
18159 + struct au_icntnr *c = _c;
18160 + struct au_iinfo *iinfo = &c->iinfo;
18162 + spin_lock_init(&iinfo->ii_generation.ig_spin);
18163 + au_rw_init(&iinfo->ii_rwsem);
18164 + inode_init_once(&c->vfs_inode);
18167 +void au_hinode_init(struct au_hinode *hinode)
18169 + hinode->hi_inode = NULL;
18170 + hinode->hi_id = -1;
18171 + au_hn_init(hinode);
18172 + hinode->hi_whdentry = NULL;
18175 +int au_iinfo_init(struct inode *inode)
18177 + struct au_iinfo *iinfo;
18178 + struct super_block *sb;
18179 + struct au_hinode *hi;
18182 + sb = inode->i_sb;
18183 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18184 + nbr = au_sbbot(sb) + 1;
18185 + if (unlikely(nbr <= 0))
18187 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
18189 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
18191 + iinfo->ii_hinode = hi;
18192 + for (i = 0; i < nbr; i++, hi++)
18193 + au_hinode_init(hi);
18195 + iinfo->ii_generation.ig_generation = au_sigen(sb);
18196 + iinfo->ii_btop = -1;
18197 + iinfo->ii_bbot = -1;
18198 + iinfo->ii_vdir = NULL;
18204 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
18207 + struct au_hinode *hip;
18209 + AuRwMustWriteLock(&iinfo->ii_rwsem);
18212 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
18215 + iinfo->ii_hinode = hip;
18216 + i = iinfo->ii_bbot + 1;
18218 + for (; i < nbr; i++, hip++)
18219 + au_hinode_init(hip);
18226 +void au_iinfo_fin(struct inode *inode)
18228 + struct au_iinfo *iinfo;
18229 + struct au_hinode *hi;
18230 + struct super_block *sb;
18231 + aufs_bindex_t bindex, bbot;
18232 + const unsigned char unlinked = !inode->i_nlink;
18234 + AuDebugOn(au_is_bad_inode(inode));
18236 + sb = inode->i_sb;
18237 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
18238 + if (si_pid_test(sb))
18239 + au_xino_delete_inode(inode, unlinked);
18242 + * it is safe to hide the dependency between sbinfo and
18246 + si_noflush_read_lock(sb);
18247 + au_xino_delete_inode(inode, unlinked);
18248 + si_read_unlock(sb);
18252 + iinfo = au_ii(inode);
18253 + if (iinfo->ii_vdir)
18254 + au_vdir_free(iinfo->ii_vdir);
18256 + bindex = iinfo->ii_btop;
18257 + if (bindex >= 0) {
18258 + hi = au_hinode(iinfo, bindex);
18259 + bbot = iinfo->ii_bbot;
18260 + while (bindex++ <= bbot) {
18261 + if (hi->hi_inode)
18266 + au_kfree_rcu(iinfo->ii_hinode);
18267 + AuRwDestroy(&iinfo->ii_rwsem);
18269 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18270 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18271 +++ linux/fs/aufs/inode.c 2019-03-05 12:13:00.139224339 +0100
18273 +// SPDX-License-Identifier: GPL-2.0
18275 + * Copyright (C) 2005-2019 Junjiro R. Okajima
18277 + * This program, aufs is free software; you can redistribute it and/or modify
18278 + * it under the terms of the GNU General Public License as published by
18279 + * the Free Software Foundation; either version 2 of the License, or
18280 + * (at your option) any later version.
18282 + * This program is distributed in the hope that it will be useful,
18283 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18284 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18285 + * GNU General Public License for more details.
18287 + * You should have received a copy of the GNU General Public License
18288 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18292 + * inode functions
18297 +struct inode *au_igrab(struct inode *inode)
18300 + AuDebugOn(!atomic_read(&inode->i_count));
18306 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18308 + au_cpup_attr_all(inode, /*force*/0);
18309 + au_update_iigen(inode, /*half*/1);
18311 + inode_inc_iversion(inode);
18314 +static int au_ii_refresh(struct inode *inode, int *update)
18318 + aufs_bindex_t bindex, new_bindex;
18319 + struct super_block *sb;
18320 + struct au_iinfo *iinfo;
18321 + struct au_hinode *p, *q, tmp;
18323 + AuDebugOn(au_is_bad_inode(inode));
18324 + IiMustWriteLock(inode);
18327 + sb = inode->i_sb;
18328 + nbr = au_sbbot(sb) + 1;
18329 + type = inode->i_mode & S_IFMT;
18330 + iinfo = au_ii(inode);
18331 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18332 + if (unlikely(err))
18335 + AuDebugOn(iinfo->ii_btop < 0);
18336 + p = au_hinode(iinfo, iinfo->ii_btop);
18337 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18339 + if (!p->hi_inode)
18342 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18343 + new_bindex = au_br_index(sb, p->hi_id);
18344 + if (new_bindex == bindex)
18347 + if (new_bindex < 0) {
18350 + p->hi_inode = NULL;
18354 + if (new_bindex < iinfo->ii_btop)
18355 + iinfo->ii_btop = new_bindex;
18356 + if (iinfo->ii_bbot < new_bindex)
18357 + iinfo->ii_bbot = new_bindex;
18358 + /* swap two lower inode, and loop again */
18359 + q = au_hinode(iinfo, new_bindex);
18363 + if (tmp.hi_inode) {
18368 + au_update_ibrange(inode, /*do_put_zero*/0);
18369 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18370 + e = au_dy_irefresh(inode);
18371 + if (unlikely(e && !err))
18379 +void au_refresh_iop(struct inode *inode, int force_getattr)
18382 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18383 + const struct inode_operations *iop
18384 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18386 + if (inode->i_op == iop)
18389 + switch (inode->i_mode & S_IFMT) {
18391 + type = AuIop_DIR;
18394 + type = AuIop_SYMLINK;
18397 + type = AuIop_OTHER;
18401 + inode->i_op = iop + type;
18402 + /* unnecessary smp_wmb() */
18405 +int au_refresh_hinode_self(struct inode *inode)
18409 + err = au_ii_refresh(inode, &update);
18411 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18417 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18419 + int err, e, update;
18420 + unsigned int flags;
18422 + aufs_bindex_t bindex, bbot;
18423 + unsigned char isdir;
18424 + struct au_hinode *p;
18425 + struct au_iinfo *iinfo;
18427 + err = au_ii_refresh(inode, &update);
18428 + if (unlikely(err))
18432 + iinfo = au_ii(inode);
18433 + p = au_hinode(iinfo, iinfo->ii_btop);
18434 + mode = (inode->i_mode & S_IFMT);
18435 + isdir = S_ISDIR(mode);
18436 + flags = au_hi_flags(inode, isdir);
18437 + bbot = au_dbbot(dentry);
18438 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18439 + struct inode *h_i, *h_inode;
18440 + struct dentry *h_d;
18442 + h_d = au_h_dptr(dentry, bindex);
18443 + if (!h_d || d_is_negative(h_d))
18446 + h_inode = d_inode(h_d);
18447 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18448 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18449 + h_i = au_h_iptr(inode, bindex);
18451 + if (h_i == h_inode)
18457 + if (bindex < iinfo->ii_btop)
18458 + iinfo->ii_btop = bindex;
18459 + if (iinfo->ii_bbot < bindex)
18460 + iinfo->ii_bbot = bindex;
18461 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18464 + au_update_ibrange(inode, /*do_put_zero*/0);
18465 + e = au_dy_irefresh(inode);
18466 + if (unlikely(e && !err))
18469 + au_refresh_hinode_attr(inode, update && isdir);
18476 +static int set_inode(struct inode *inode, struct dentry *dentry)
18479 + unsigned int flags;
18481 + aufs_bindex_t bindex, btop, btail;
18482 + unsigned char isdir;
18483 + struct dentry *h_dentry;
18484 + struct inode *h_inode;
18485 + struct au_iinfo *iinfo;
18486 + struct inode_operations *iop;
18488 + IiMustWriteLock(inode);
18492 + iop = au_sbi(inode->i_sb)->si_iop_array;
18493 + btop = au_dbtop(dentry);
18494 + h_dentry = au_h_dptr(dentry, btop);
18495 + h_inode = d_inode(h_dentry);
18496 + mode = h_inode->i_mode;
18497 + switch (mode & S_IFMT) {
18499 + btail = au_dbtail(dentry);
18500 + inode->i_op = iop + AuIop_OTHER;
18501 + inode->i_fop = &aufs_file_fop;
18502 + err = au_dy_iaop(inode, btop, h_inode);
18503 + if (unlikely(err))
18508 + btail = au_dbtaildir(dentry);
18509 + inode->i_op = iop + AuIop_DIR;
18510 + inode->i_fop = &aufs_dir_fop;
18513 + btail = au_dbtail(dentry);
18514 + inode->i_op = iop + AuIop_SYMLINK;
18520 + btail = au_dbtail(dentry);
18521 + inode->i_op = iop + AuIop_OTHER;
18522 + init_special_inode(inode, mode, h_inode->i_rdev);
18525 + AuIOErr("Unknown file type 0%o\n", mode);
18530 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18531 + flags = au_hi_flags(inode, isdir);
18532 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18533 + && au_ftest_hi(flags, HNOTIFY)
18534 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18535 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18536 + au_fclr_hi(flags, HNOTIFY);
18537 + iinfo = au_ii(inode);
18538 + iinfo->ii_btop = btop;
18539 + iinfo->ii_bbot = btail;
18540 + for (bindex = btop; bindex <= btail; bindex++) {
18541 + h_dentry = au_h_dptr(dentry, bindex);
18543 + au_set_h_iptr(inode, bindex,
18544 + au_igrab(d_inode(h_dentry)), flags);
18546 + au_cpup_attr_all(inode, /*force*/1);
18548 + * to force calling aufs_get_acl() every time,
18549 + * do not call cache_no_acl() for aufs inode.
18557 + * successful returns with iinfo write_locked
18559 + * zero: success, matched
18560 + * plus: no error, but unmatched
18562 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18565 + unsigned int gen, igflags;
18566 + aufs_bindex_t bindex, bbot;
18567 + struct inode *h_inode, *h_dinode;
18568 + struct dentry *h_dentry;
18571 + * before this function, if aufs got any iinfo lock, it must be only
18572 + * one, the parent dir.
18573 + * it can happen by UDBA and the obsoleted inode number.
18576 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18580 + ii_write_lock_new_child(inode);
18581 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18582 + h_dinode = d_inode(h_dentry);
18583 + bbot = au_ibbot(inode);
18584 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18585 + h_inode = au_h_iptr(inode, bindex);
18586 + if (!h_inode || h_inode != h_dinode)
18590 + gen = au_iigen(inode, &igflags);
18591 + if (gen == au_digen(dentry)
18592 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18595 + /* fully refresh inode using dentry */
18596 + err = au_refresh_hinode(inode, dentry);
18598 + au_update_iigen(inode, /*half*/0);
18602 + if (unlikely(err))
18603 + ii_write_unlock(inode);
18608 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18609 + unsigned int d_type, ino_t *ino)
18612 + const int isnondir = d_type != DT_DIR;
18614 + /* prevent hardlinked inode number from race condition */
18616 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18617 + if (unlikely(err))
18621 + err = au_xino_read(sb, bindex, h_ino, ino);
18622 + if (unlikely(err))
18623 + goto out_xinondir;
18627 + *ino = au_xino_new_ino(sb);
18628 + if (unlikely(!*ino))
18629 + goto out_xinondir;
18630 + err = au_xino_write(sb, bindex, h_ino, *ino);
18631 + if (unlikely(err))
18632 + goto out_xinondir;
18636 + if (isnondir && idx >= 0)
18637 + au_xinondir_leave(sb, bindex, h_ino, idx);
18642 +/* successful returns with iinfo write_locked */
18643 +/* todo: return with unlocked? */
18644 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18646 + struct inode *inode, *h_inode;
18647 + struct dentry *h_dentry;
18648 + struct super_block *sb;
18649 + ino_t h_ino, ino;
18650 + int err, idx, hlinked;
18651 + aufs_bindex_t btop;
18653 + sb = dentry->d_sb;
18654 + btop = au_dbtop(dentry);
18655 + h_dentry = au_h_dptr(dentry, btop);
18656 + h_inode = d_inode(h_dentry);
18657 + h_ino = h_inode->i_ino;
18658 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18662 + * stop 'race'-ing between hardlinks under different
18666 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18667 + inode = ERR_PTR(err);
18668 + if (unlikely(err))
18672 + err = au_xino_read(sb, btop, h_ino, &ino);
18673 + inode = ERR_PTR(err);
18674 + if (unlikely(err))
18675 + goto out_xinondir;
18678 + ino = au_xino_new_ino(sb);
18679 + if (unlikely(!ino)) {
18680 + inode = ERR_PTR(-EIO);
18681 + goto out_xinondir;
18685 + AuDbg("i%lu\n", (unsigned long)ino);
18686 + inode = au_iget_locked(sb, ino);
18687 + err = PTR_ERR(inode);
18688 + if (IS_ERR(inode))
18689 + goto out_xinondir;
18691 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18692 + if (inode->i_state & I_NEW) {
18693 + ii_write_lock_new_child(inode);
18694 + err = set_inode(inode, dentry);
18696 + unlock_new_inode(inode);
18697 + goto out_xinondir; /* success */
18701 + * iget_failed() calls iput(), but we need to call
18702 + * ii_write_unlock() after iget_failed(). so dirty hack for
18705 + atomic_inc(&inode->i_count);
18706 + iget_failed(inode);
18707 + ii_write_unlock(inode);
18708 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18709 + /* ignore this error */
18711 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18713 + * horrible race condition between lookup, readdir and copyup
18714 + * (or something).
18716 + if (hlinked && idx >= 0)
18717 + au_xinondir_leave(sb, btop, h_ino, idx);
18718 + err = reval_inode(inode, dentry);
18719 + if (unlikely(err < 0)) {
18724 + goto out; /* success */
18725 + else if (hlinked && idx >= 0) {
18726 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18727 + if (unlikely(err)) {
18729 + inode = ERR_PTR(err);
18735 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18736 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18737 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18738 + btop, au_sbtype(h_dentry->d_sb), dentry,
18739 + (unsigned long)h_ino, (unsigned long)ino);
18741 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18744 + if (hlinked && idx >= 0)
18745 + au_xinondir_leave(sb, btop, h_ino, idx);
18751 + inode = ERR_PTR(err);
18753 + if (hlinked && idx >= 0)
18754 + au_xinondir_leave(sb, btop, h_ino, idx);
18759 +/* ---------------------------------------------------------------------- */
18761 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18762 + struct inode *inode)
18765 + struct inode *hi;
18767 + err = au_br_rdonly(au_sbr(sb, bindex));
18769 + /* pseudo-link after flushed may happen out of bounds */
18772 + && au_ibtop(inode) <= bindex
18773 + && bindex <= au_ibbot(inode)) {
18775 + * permission check is unnecessary since vfsub routine
18776 + * will be called later
18778 + hi = au_h_iptr(inode, bindex);
18780 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18786 +int au_test_h_perm(struct inode *h_inode, int mask)
18788 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18790 + return inode_permission(h_inode, mask);
18793 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18795 + if (au_test_nfs(h_inode->i_sb)
18796 + && (mask & MAY_WRITE)
18797 + && S_ISDIR(h_inode->i_mode))
18798 + mask |= MAY_READ; /* force permission check */
18799 + return au_test_h_perm(h_inode, mask);
18801 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18802 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18803 +++ linux/fs/aufs/inode.h 2019-03-05 12:13:00.142557771 +0100
18805 +/* SPDX-License-Identifier: GPL-2.0 */
18807 + * Copyright (C) 2005-2019 Junjiro R. Okajima
18809 + * This program, aufs is free software; you can redistribute it and/or modify
18810 + * it under the terms of the GNU General Public License as published by
18811 + * the Free Software Foundation; either version 2 of the License, or
18812 + * (at your option) any later version.
18814 + * This program is distributed in the hope that it will be useful,
18815 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18816 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18817 + * GNU General Public License for more details.
18819 + * You should have received a copy of the GNU General Public License
18820 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18824 + * inode operations
18827 +#ifndef __AUFS_INODE_H__
18828 +#define __AUFS_INODE_H__
18832 +#include <linux/fsnotify.h>
18833 +#include "rwsem.h"
18837 +struct au_hnotify {
18838 +#ifdef CONFIG_AUFS_HNOTIFY
18839 +#ifdef CONFIG_AUFS_HFSNOTIFY
18840 + /* never use fsnotify_add_vfsmount_mark() */
18841 + struct fsnotify_mark hn_mark;
18843 + struct inode *hn_aufs_inode; /* no get/put */
18844 + struct rcu_head rcu;
18846 +} ____cacheline_aligned_in_smp;
18848 +struct au_hinode {
18849 + struct inode *hi_inode;
18850 + aufs_bindex_t hi_id;
18851 +#ifdef CONFIG_AUFS_HNOTIFY
18852 + struct au_hnotify *hi_notify;
18855 + /* reference to the copied-up whiteout with get/put */
18856 + struct dentry *hi_whdentry;
18860 +#define AuIG_HALF_REFRESHED 1
18861 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18862 +#define au_ig_fset(flags, name) \
18863 + do { (flags) |= AuIG_##name; } while (0)
18864 +#define au_ig_fclr(flags, name) \
18865 + do { (flags) &= ~AuIG_##name; } while (0)
18868 + spinlock_t ig_spin;
18869 + __u32 ig_generation, ig_flags;
18874 + struct au_iigen ii_generation;
18875 + struct super_block *ii_hsb1; /* no get/put */
18877 + struct au_rwsem ii_rwsem;
18878 + aufs_bindex_t ii_btop, ii_bbot;
18880 + struct au_hinode *ii_hinode;
18881 + struct au_vdir *ii_vdir;
18884 +struct au_icntnr {
18885 + struct au_iinfo iinfo;
18886 + struct inode vfs_inode;
18887 + struct hlist_bl_node plink;
18888 + struct rcu_head rcu;
18889 +} ____cacheline_aligned_in_smp;
18891 +/* au_pin flags */
18892 +#define AuPin_DI_LOCKED 1
18893 +#define AuPin_MNT_WRITE (1 << 1)
18894 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18895 +#define au_fset_pin(flags, name) \
18896 + do { (flags) |= AuPin_##name; } while (0)
18897 +#define au_fclr_pin(flags, name) \
18898 + do { (flags) &= ~AuPin_##name; } while (0)
18902 + struct dentry *dentry;
18903 + unsigned int udba;
18904 + unsigned char lsc_di, lsc_hi, flags;
18905 + aufs_bindex_t bindex;
18908 + struct dentry *parent;
18909 + struct au_hinode *hdir;
18910 + struct vfsmount *h_mnt;
18912 + /* temporary unlock/relock for copyup */
18913 + struct dentry *h_dentry, *h_parent;
18914 + struct au_branch *br;
18915 + struct task_struct *task;
18918 +void au_pin_hdir_unlock(struct au_pin *p);
18919 +int au_pin_hdir_lock(struct au_pin *p);
18920 +int au_pin_hdir_relock(struct au_pin *p);
18921 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18922 +void au_pin_hdir_release(struct au_pin *p);
18924 +/* ---------------------------------------------------------------------- */
18926 +static inline struct au_iinfo *au_ii(struct inode *inode)
18928 + BUG_ON(is_bad_inode(inode));
18929 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18932 +/* ---------------------------------------------------------------------- */
18935 +struct inode *au_igrab(struct inode *inode);
18936 +void au_refresh_iop(struct inode *inode, int force_getattr);
18937 +int au_refresh_hinode_self(struct inode *inode);
18938 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18939 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18940 + unsigned int d_type, ino_t *ino);
18941 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18942 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18943 + struct inode *inode);
18944 +int au_test_h_perm(struct inode *h_inode, int mask);
18945 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18947 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18948 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18950 +#ifdef CONFIG_AUFS_SHWH
18951 + return au_ino(sb, bindex, h_ino, d_type, ino);
18964 +extern struct inode_operations aufs_iop[AuIop_Last],
18965 + aufs_iop_nogetattr[AuIop_Last];
18967 +/* au_wr_dir flags */
18968 +#define AuWrDir_ADD_ENTRY 1
18969 +#define AuWrDir_ISDIR (1 << 1)
18970 +#define AuWrDir_TMPFILE (1 << 2)
18971 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18972 +#define au_fset_wrdir(flags, name) \
18973 + do { (flags) |= AuWrDir_##name; } while (0)
18974 +#define au_fclr_wrdir(flags, name) \
18975 + do { (flags) &= ~AuWrDir_##name; } while (0)
18977 +struct au_wr_dir_args {
18978 + aufs_bindex_t force_btgt;
18979 + unsigned char flags;
18981 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18982 + struct au_wr_dir_args *args);
18984 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18985 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18986 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18987 + unsigned int udba, unsigned char flags);
18988 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18989 + unsigned int udba, unsigned char flags) __must_check;
18990 +int au_do_pin(struct au_pin *pin) __must_check;
18991 +void au_unpin(struct au_pin *pin);
18992 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18994 +#define AuIcpup_DID_CPUP 1
18995 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18996 +#define au_fset_icpup(flags, name) \
18997 + do { (flags) |= AuIcpup_##name; } while (0)
18998 +#define au_fclr_icpup(flags, name) \
18999 + do { (flags) &= ~AuIcpup_##name; } while (0)
19001 +struct au_icpup_args {
19002 + unsigned char flags;
19003 + unsigned char pin_flags;
19004 + aufs_bindex_t btgt;
19005 + unsigned int udba;
19006 + struct au_pin pin;
19007 + struct path h_path;
19008 + struct inode *h_inode;
19011 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
19012 + struct au_icpup_args *a);
19014 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
19018 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19019 + struct dentry *h_parent, int isdir);
19020 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
19022 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
19023 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
19025 +struct vfsub_aopen_args;
19026 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
19027 + struct vfsub_aopen_args *args);
19028 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
19029 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
19030 + struct dentry *dentry);
19031 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
19034 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
19035 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
19036 + struct dentry *h_parent, int isdir);
19037 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
19038 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
19041 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
19042 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
19043 + struct inode *dir, struct dentry *dentry,
19044 + unsigned int flags);
19047 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
19048 +void au_hiput(struct au_hinode *hinode);
19049 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19050 + struct dentry *h_wh);
19051 +unsigned int au_hi_flags(struct inode *inode, int isdir);
19053 +/* hinode flags */
19054 +#define AuHi_XINO 1
19055 +#define AuHi_HNOTIFY (1 << 1)
19056 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
19057 +#define au_fset_hi(flags, name) \
19058 + do { (flags) |= AuHi_##name; } while (0)
19059 +#define au_fclr_hi(flags, name) \
19060 + do { (flags) &= ~AuHi_##name; } while (0)
19062 +#ifndef CONFIG_AUFS_HNOTIFY
19063 +#undef AuHi_HNOTIFY
19064 +#define AuHi_HNOTIFY 0
19067 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19068 + struct inode *h_inode, unsigned int flags);
19070 +void au_update_iigen(struct inode *inode, int half);
19071 +void au_update_ibrange(struct inode *inode, int do_put_zero);
19073 +void au_icntnr_init_once(void *_c);
19074 +void au_hinode_init(struct au_hinode *hinode);
19075 +int au_iinfo_init(struct inode *inode);
19076 +void au_iinfo_fin(struct inode *inode);
19077 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
19079 +#ifdef CONFIG_PROC_FS
19081 +int au_plink_maint(struct super_block *sb, int flags);
19083 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
19084 +int au_plink_maint_enter(struct super_block *sb);
19085 +#ifdef CONFIG_AUFS_DEBUG
19086 +void au_plink_list(struct super_block *sb);
19088 +AuStubVoid(au_plink_list, struct super_block *sb)
19090 +int au_plink_test(struct inode *inode);
19091 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
19092 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
19093 + struct dentry *h_dentry);
19094 +void au_plink_put(struct super_block *sb, int verbose);
19095 +void au_plink_clean(struct super_block *sb, int verbose);
19096 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
19098 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
19099 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
19100 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
19101 +AuStubVoid(au_plink_list, struct super_block *sb);
19102 +AuStubInt0(au_plink_test, struct inode *inode);
19103 +AuStub(struct dentry *, au_plink_lkup, return NULL,
19104 + struct inode *inode, aufs_bindex_t bindex);
19105 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
19106 + struct dentry *h_dentry);
19107 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
19108 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
19109 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
19110 +#endif /* CONFIG_PROC_FS */
19112 +#ifdef CONFIG_AUFS_XATTR
19114 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
19115 + unsigned int verbose);
19116 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
19117 +void au_xattr_init(struct super_block *sb);
19119 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
19120 + int ignore_flags, unsigned int verbose);
19121 +AuStubVoid(au_xattr_init, struct super_block *sb);
19124 +#ifdef CONFIG_FS_POSIX_ACL
19125 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
19126 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
19129 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19135 +struct au_sxattr {
19139 + const char *name;
19140 + const void *value;
19145 + struct posix_acl *acl;
19150 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19151 + struct au_sxattr *arg);
19154 +/* ---------------------------------------------------------------------- */
19156 +/* lock subclass for iinfo */
19158 + AuLsc_II_CHILD, /* child first */
19159 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
19160 + AuLsc_II_CHILD3, /* copyup dirs */
19161 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
19162 + AuLsc_II_PARENT2,
19163 + AuLsc_II_PARENT3, /* copyup dirs */
19164 + AuLsc_II_NEW_CHILD
19168 + * ii_read_lock_child, ii_write_lock_child,
19169 + * ii_read_lock_child2, ii_write_lock_child2,
19170 + * ii_read_lock_child3, ii_write_lock_child3,
19171 + * ii_read_lock_parent, ii_write_lock_parent,
19172 + * ii_read_lock_parent2, ii_write_lock_parent2,
19173 + * ii_read_lock_parent3, ii_write_lock_parent3,
19174 + * ii_read_lock_new_child, ii_write_lock_new_child,
19176 +#define AuReadLockFunc(name, lsc) \
19177 +static inline void ii_read_lock_##name(struct inode *i) \
19179 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19182 +#define AuWriteLockFunc(name, lsc) \
19183 +static inline void ii_write_lock_##name(struct inode *i) \
19185 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19188 +#define AuRWLockFuncs(name, lsc) \
19189 + AuReadLockFunc(name, lsc) \
19190 + AuWriteLockFunc(name, lsc)
19192 +AuRWLockFuncs(child, CHILD);
19193 +AuRWLockFuncs(child2, CHILD2);
19194 +AuRWLockFuncs(child3, CHILD3);
19195 +AuRWLockFuncs(parent, PARENT);
19196 +AuRWLockFuncs(parent2, PARENT2);
19197 +AuRWLockFuncs(parent3, PARENT3);
19198 +AuRWLockFuncs(new_child, NEW_CHILD);
19200 +#undef AuReadLockFunc
19201 +#undef AuWriteLockFunc
19202 +#undef AuRWLockFuncs
19204 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
19205 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
19206 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
19208 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
19209 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
19210 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
19212 +/* ---------------------------------------------------------------------- */
19214 +static inline void au_icntnr_init(struct au_icntnr *c)
19216 +#ifdef CONFIG_AUFS_DEBUG
19217 + c->vfs_inode.i_mode = 0;
19221 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
19223 + unsigned int gen;
19224 + struct au_iinfo *iinfo;
19225 + struct au_iigen *iigen;
19227 + iinfo = au_ii(inode);
19228 + iigen = &iinfo->ii_generation;
19229 + spin_lock(&iigen->ig_spin);
19231 + *igflags = iigen->ig_flags;
19232 + gen = iigen->ig_generation;
19233 + spin_unlock(&iigen->ig_spin);
19238 +/* tiny test for inode number */
19239 +/* tmpfs generation is too rough */
19240 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19242 + struct au_iinfo *iinfo;
19244 + iinfo = au_ii(inode);
19245 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19246 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19247 + && iinfo->ii_higen == h_inode->i_generation);
19250 +static inline void au_iigen_dec(struct inode *inode)
19252 + struct au_iinfo *iinfo;
19253 + struct au_iigen *iigen;
19255 + iinfo = au_ii(inode);
19256 + iigen = &iinfo->ii_generation;
19257 + spin_lock(&iigen->ig_spin);
19258 + iigen->ig_generation--;
19259 + spin_unlock(&iigen->ig_spin);
19262 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19267 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19273 +/* ---------------------------------------------------------------------- */
19275 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19276 + aufs_bindex_t bindex)
19278 + return iinfo->ii_hinode + bindex;
19281 +static inline int au_is_bad_inode(struct inode *inode)
19283 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19286 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19287 + aufs_bindex_t bindex)
19289 + IiMustAnyLock(inode);
19290 + return au_hinode(au_ii(inode), bindex)->hi_id;
19293 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19295 + IiMustAnyLock(inode);
19296 + return au_ii(inode)->ii_btop;
19299 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19301 + IiMustAnyLock(inode);
19302 + return au_ii(inode)->ii_bbot;
19305 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19307 + IiMustAnyLock(inode);
19308 + return au_ii(inode)->ii_vdir;
19311 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19313 + IiMustAnyLock(inode);
19314 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19317 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19319 + IiMustWriteLock(inode);
19320 + au_ii(inode)->ii_btop = bindex;
19323 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19325 + IiMustWriteLock(inode);
19326 + au_ii(inode)->ii_bbot = bindex;
19329 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19331 + IiMustWriteLock(inode);
19332 + au_ii(inode)->ii_vdir = vdir;
19335 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19337 + IiMustAnyLock(inode);
19338 + return au_hinode(au_ii(inode), bindex);
19341 +/* ---------------------------------------------------------------------- */
19343 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19346 + return pin->parent;
19350 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19352 + if (pin && pin->hdir)
19353 + return pin->hdir->hi_inode;
19357 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19360 + return pin->hdir;
19364 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19367 + pin->dentry = dentry;
19370 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19371 + unsigned char lflag)
19375 + au_fset_pin(pin->flags, DI_LOCKED);
19377 + au_fclr_pin(pin->flags, DI_LOCKED);
19381 +#if 0 /* reserved */
19382 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19385 + dput(pin->parent);
19386 + pin->parent = dget(parent);
19391 +/* ---------------------------------------------------------------------- */
19394 +#ifdef CONFIG_AUFS_HNOTIFY
19395 +struct au_hnotify_op {
19396 + void (*ctl)(struct au_hinode *hinode, int do_set);
19397 + int (*alloc)(struct au_hinode *hinode);
19400 + * if it returns true, the the caller should free hinode->hi_notify,
19401 + * otherwise ->free() frees it.
19403 + int (*free)(struct au_hinode *hinode,
19404 + struct au_hnotify *hn) __must_check;
19406 + void (*fin)(void);
19407 + int (*init)(void);
19409 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19410 + void (*fin_br)(struct au_branch *br);
19411 + int (*init_br)(struct au_branch *br, int perm);
19415 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19416 +void au_hn_free(struct au_hinode *hinode);
19417 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19418 +void au_hn_reset(struct inode *inode, unsigned int flags);
19419 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19420 + struct qstr *h_child_qstr, struct inode *h_child_inode);
19421 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19422 +int au_hnotify_init_br(struct au_branch *br, int perm);
19423 +void au_hnotify_fin_br(struct au_branch *br);
19424 +int __init au_hnotify_init(void);
19425 +void au_hnotify_fin(void);
19428 +extern const struct au_hnotify_op au_hnotify_op;
19431 +void au_hn_init(struct au_hinode *hinode)
19433 + hinode->hi_notify = NULL;
19436 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19438 + return hinode->hi_notify;
19442 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19443 + struct au_hinode *hinode __maybe_unused,
19444 + struct inode *inode __maybe_unused)
19445 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19446 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19447 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19448 + int do_set __maybe_unused)
19449 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19450 + unsigned int flags __maybe_unused)
19451 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19452 + struct au_branch *br __maybe_unused,
19453 + int perm __maybe_unused)
19454 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19455 + int perm __maybe_unused)
19456 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19457 +AuStubInt0(__init au_hnotify_init, void)
19458 +AuStubVoid(au_hnotify_fin, void)
19459 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19460 +#endif /* CONFIG_AUFS_HNOTIFY */
19462 +static inline void au_hn_suspend(struct au_hinode *hdir)
19464 + au_hn_ctl(hdir, /*do_set*/0);
19467 +static inline void au_hn_resume(struct au_hinode *hdir)
19469 + au_hn_ctl(hdir, /*do_set*/1);
19472 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19474 + inode_lock(hdir->hi_inode);
19475 + au_hn_suspend(hdir);
19478 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19479 + unsigned int sc __maybe_unused)
19481 + inode_lock_nested(hdir->hi_inode, sc);
19482 + au_hn_suspend(hdir);
19485 +#if 0 /* unused */
19486 +#include "vfsub.h"
19487 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19490 + inode_lock_shared_nested(hdir->hi_inode, sc);
19491 + au_hn_suspend(hdir);
19495 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19497 + au_hn_resume(hdir);
19498 + inode_unlock(hdir->hi_inode);
19501 +#endif /* __KERNEL__ */
19502 +#endif /* __AUFS_INODE_H__ */
19503 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19504 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19505 +++ linux/fs/aufs/ioctl.c 2019-03-05 12:13:00.142557771 +0100
19507 +// SPDX-License-Identifier: GPL-2.0
19509 + * Copyright (C) 2005-2019 Junjiro R. Okajima
19511 + * This program, aufs is free software; you can redistribute it and/or modify
19512 + * it under the terms of the GNU General Public License as published by
19513 + * the Free Software Foundation; either version 2 of the License, or
19514 + * (at your option) any later version.
19516 + * This program is distributed in the hope that it will be useful,
19517 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19518 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19519 + * GNU General Public License for more details.
19521 + * You should have received a copy of the GNU General Public License
19522 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19527 + * plink-management and readdir in userspace.
19528 + * assist the pathconf(3) wrapper library.
19530 + * File-based Hierarchical Storage Management.
19533 +#include <linux/compat.h>
19534 +#include <linux/file.h>
19537 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19540 + aufs_bindex_t wbi, bindex, bbot;
19541 + struct file *h_file;
19542 + struct super_block *sb;
19543 + struct dentry *root;
19544 + struct au_branch *br;
19545 + struct aufs_wbr_fd wbrfd = {
19546 + .oflags = au_dir_roflags,
19549 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19550 + | O_NOATIME | O_CLOEXEC;
19552 + AuDebugOn(wbrfd.oflags & ~valid);
19555 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19556 + if (unlikely(err)) {
19562 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19563 + wbrfd.oflags |= au_dir_roflags;
19564 + AuDbg("0%o\n", wbrfd.oflags);
19565 + if (unlikely(wbrfd.oflags & ~valid))
19569 + fd = get_unused_fd_flags(0);
19571 + if (unlikely(fd < 0))
19574 + h_file = ERR_PTR(-EINVAL);
19577 + sb = path->dentry->d_sb;
19578 + root = sb->s_root;
19579 + aufs_read_lock(root, AuLock_IR);
19580 + bbot = au_sbbot(sb);
19581 + if (wbrfd.brid >= 0) {
19582 + wbi = au_br_index(sb, wbrfd.brid);
19583 + if (unlikely(wbi < 0 || wbi > bbot))
19587 + h_file = ERR_PTR(-ENOENT);
19588 + br = au_sbr(sb, wbi);
19589 + if (!au_br_writable(br->br_perm)) {
19593 + bindex = wbi + 1;
19595 + for (; bindex <= bbot; bindex++) {
19596 + br = au_sbr(sb, bindex);
19597 + if (au_br_writable(br->br_perm)) {
19599 + br = au_sbr(sb, wbi);
19604 + AuDbg("wbi %d\n", wbi);
19606 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19610 + aufs_read_unlock(root, AuLock_IR);
19611 + err = PTR_ERR(h_file);
19612 + if (IS_ERR(h_file))
19615 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19616 + fd_install(fd, h_file);
19618 + goto out; /* success */
19621 + put_unused_fd(fd);
19627 +/* ---------------------------------------------------------------------- */
19629 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19632 + struct dentry *dentry;
19635 + case AUFS_CTL_RDU:
19636 + case AUFS_CTL_RDU_INO:
19637 + err = au_rdu_ioctl(file, cmd, arg);
19640 + case AUFS_CTL_WBR_FD:
19641 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19644 + case AUFS_CTL_IBUSY:
19645 + err = au_ibusy_ioctl(file, arg);
19648 + case AUFS_CTL_BRINFO:
19649 + err = au_brinfo_ioctl(file, arg);
19652 + case AUFS_CTL_FHSM_FD:
19653 + dentry = file->f_path.dentry;
19654 + if (IS_ROOT(dentry))
19655 + err = au_fhsm_fd(dentry->d_sb, arg);
19661 + /* do not call the lower */
19662 + AuDbg("0x%x\n", cmd);
19670 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19675 + case AUFS_CTL_MVDOWN:
19676 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19679 + case AUFS_CTL_WBR_FD:
19680 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19684 + /* do not call the lower */
19685 + AuDbg("0x%x\n", cmd);
19693 +#ifdef CONFIG_COMPAT
19694 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19695 + unsigned long arg)
19700 + case AUFS_CTL_RDU:
19701 + case AUFS_CTL_RDU_INO:
19702 + err = au_rdu_compat_ioctl(file, cmd, arg);
19705 + case AUFS_CTL_IBUSY:
19706 + err = au_ibusy_compat_ioctl(file, arg);
19709 + case AUFS_CTL_BRINFO:
19710 + err = au_brinfo_compat_ioctl(file, arg);
19714 + err = aufs_ioctl_dir(file, cmd, arg);
19721 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19722 + unsigned long arg)
19724 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19727 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19728 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19729 +++ linux/fs/aufs/i_op_add.c 2019-03-05 12:13:00.139224339 +0100
19731 +// SPDX-License-Identifier: GPL-2.0
19733 + * Copyright (C) 2005-2019 Junjiro R. Okajima
19735 + * This program, aufs is free software; you can redistribute it and/or modify
19736 + * it under the terms of the GNU General Public License as published by
19737 + * the Free Software Foundation; either version 2 of the License, or
19738 + * (at your option) any later version.
19740 + * This program is distributed in the hope that it will be useful,
19741 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19742 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19743 + * GNU General Public License for more details.
19745 + * You should have received a copy of the GNU General Public License
19746 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19750 + * inode operations (add entry)
19756 + * final procedure of adding a new entry, except link(2).
19757 + * remove whiteout, instantiate, copyup the parent dir's times and size
19758 + * and update version.
19759 + * if it failed, re-create the removed whiteout.
19761 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19762 + struct dentry *wh_dentry, struct dentry *dentry)
19765 + aufs_bindex_t bwh;
19766 + struct path h_path;
19767 + struct super_block *sb;
19768 + struct inode *inode, *h_dir;
19769 + struct dentry *wh;
19774 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19775 + IMustLock(h_dir);
19776 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19777 + bwh = au_dbwh(dentry);
19778 + h_path.dentry = wh_dentry;
19779 + h_path.mnt = au_sbr_mnt(sb, bindex);
19780 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19782 + if (unlikely(err))
19786 + inode = au_new_inode(dentry, /*must_new*/1);
19787 + if (!IS_ERR(inode)) {
19788 + d_instantiate(dentry, inode);
19789 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19791 + au_dir_ts(dir, bindex);
19792 + inode_inc_iversion(dir);
19793 + au_fhsm_wrote(sb, bindex, /*force*/0);
19794 + return 0; /* success */
19797 + err = PTR_ERR(inode);
19802 + /* dir inode is locked */
19803 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19804 + rerr = PTR_ERR(wh);
19805 + if (IS_ERR(wh)) {
19806 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19807 + dentry, err, rerr);
19816 +static int au_d_may_add(struct dentry *dentry)
19821 + if (unlikely(d_unhashed(dentry)))
19823 + if (unlikely(d_really_is_positive(dentry)))
19829 + * simple tests for the adding inode operations.
19830 + * following the checks in vfs, plus the parent-child relationship.
19832 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19833 + struct dentry *h_parent, int isdir)
19837 + struct dentry *h_dentry;
19838 + struct inode *h_inode;
19840 + err = -ENAMETOOLONG;
19841 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19844 + h_dentry = au_h_dptr(dentry, bindex);
19845 + if (d_really_is_negative(dentry)) {
19847 + if (unlikely(d_is_positive(h_dentry)))
19850 + /* rename(2) case */
19852 + if (unlikely(d_is_negative(h_dentry)))
19854 + h_inode = d_inode(h_dentry);
19855 + if (unlikely(!h_inode->i_nlink))
19858 + h_mode = h_inode->i_mode;
19861 + if (unlikely(S_ISDIR(h_mode)))
19863 + } else if (unlikely(!S_ISDIR(h_mode))) {
19870 + /* expected parent dir is locked */
19871 + if (unlikely(h_parent != h_dentry->d_parent))
19880 + * initial procedure of adding a new entry.
19881 + * prepare writable branch and the parent dir, lock it,
19882 + * and lookup whiteout for the new entry.
19884 +static struct dentry*
19885 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19886 + struct dentry *src_dentry, struct au_pin *pin,
19887 + struct au_wr_dir_args *wr_dir_args)
19889 + struct dentry *wh_dentry, *h_parent;
19890 + struct super_block *sb;
19891 + struct au_branch *br;
19893 + unsigned int udba;
19894 + aufs_bindex_t bcpup;
19896 + AuDbg("%pd\n", dentry);
19898 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19900 + wh_dentry = ERR_PTR(err);
19901 + if (unlikely(err < 0))
19904 + sb = dentry->d_sb;
19905 + udba = au_opt_udba(sb);
19906 + err = au_pin(pin, dentry, bcpup, udba,
19907 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19908 + wh_dentry = ERR_PTR(err);
19909 + if (unlikely(err))
19912 + h_parent = au_pinned_h_parent(pin);
19913 + if (udba != AuOpt_UDBA_NONE
19914 + && au_dbtop(dentry) == bcpup)
19915 + err = au_may_add(dentry, bcpup, h_parent,
19916 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19917 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19918 + err = -ENAMETOOLONG;
19919 + wh_dentry = ERR_PTR(err);
19920 + if (unlikely(err))
19923 + br = au_sbr(sb, bcpup);
19925 + struct path tmp = {
19926 + .dentry = h_parent,
19927 + .mnt = au_br_mnt(br)
19929 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19932 + wh_dentry = NULL;
19933 + if (bcpup != au_dbwh(dentry))
19934 + goto out; /* success */
19937 + * ENAMETOOLONG here means that if we allowed create such name, then it
19938 + * would not be able to removed in the future. So we don't allow such
19939 + * name here and we don't handle ENAMETOOLONG differently here.
19941 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19944 + if (IS_ERR(wh_dentry))
19947 + return wh_dentry;
19950 +/* ---------------------------------------------------------------------- */
19952 +enum { Mknod, Symlink, Creat };
19953 +struct simple_arg {
19960 + struct vfsub_aopen_args *aopen;
19963 + const char *symname;
19972 +static int add_simple(struct inode *dir, struct dentry *dentry,
19973 + struct simple_arg *arg)
19976 + aufs_bindex_t btop;
19977 + unsigned char created;
19978 + const unsigned char try_aopen
19979 + = (arg->type == Creat && arg->u.c.try_aopen);
19980 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19981 + struct dentry *wh_dentry, *parent;
19982 + struct inode *h_dir;
19983 + struct super_block *sb;
19984 + struct au_branch *br;
19985 + /* to reduce stack size */
19987 + struct au_dtime dt;
19988 + struct au_pin pin;
19989 + struct path h_path;
19990 + struct au_wr_dir_args wr_dir_args;
19993 + AuDbg("%pd\n", dentry);
19997 + a = kmalloc(sizeof(*a), GFP_NOFS);
19998 + if (unlikely(!a))
20000 + a->wr_dir_args.force_btgt = -1;
20001 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
20003 + parent = dentry->d_parent; /* dir inode is locked */
20004 + if (!try_aopen) {
20005 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20006 + if (unlikely(err))
20009 + err = au_d_may_add(dentry);
20010 + if (unlikely(err))
20013 + di_write_lock_parent(parent);
20014 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20015 + &a->pin, &a->wr_dir_args);
20016 + err = PTR_ERR(wh_dentry);
20017 + if (IS_ERR(wh_dentry))
20020 + btop = au_dbtop(dentry);
20021 + sb = dentry->d_sb;
20022 + br = au_sbr(sb, btop);
20023 + a->h_path.dentry = au_h_dptr(dentry, btop);
20024 + a->h_path.mnt = au_br_mnt(br);
20025 + h_dir = au_pinned_h_dir(&a->pin);
20026 + switch (arg->type) {
20028 + if (!try_aopen || !h_dir->i_op->atomic_open) {
20029 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
20030 + arg->u.c.want_excl);
20032 + if (!err && try_aopen)
20033 + aopen->file->f_mode |= FMODE_CREATED;
20036 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
20037 + AuDbg("err %d\n", err);
20038 + AuDbgFile(aopen->file);
20039 + created = err >= 0
20040 + && !!(aopen->file->f_mode & FMODE_CREATED);
20044 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
20048 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
20055 + if (unlikely(err < 0))
20058 + err = epilog(dir, btop, wh_dentry, dentry);
20060 + goto out_unpin; /* success */
20063 + if (created /* && d_is_positive(a->h_path.dentry) */) {
20064 + /* no delegation since it is just created */
20065 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
20068 + AuIOErr("%pd revert failure(%d, %d)\n",
20069 + dentry, err, rerr);
20072 + au_dtime_revert(&a->dt);
20074 + if (try_aopen && h_dir->i_op->atomic_open
20075 + && (aopen->file->f_mode & FMODE_OPENED))
20076 + /* aopen->file is still opened */
20077 + au_lcnt_dec(&aopen->br->br_nfiles);
20080 + au_unpin(&a->pin);
20084 + di_write_unlock(parent);
20086 + if (unlikely(err)) {
20087 + au_update_dbtop(dentry);
20091 + aufs_read_unlock(dentry, AuLock_DW);
20098 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
20101 + struct simple_arg arg = {
20108 + return add_simple(dir, dentry, &arg);
20111 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
20113 + struct simple_arg arg = {
20115 + .u.s.symname = symname
20117 + return add_simple(dir, dentry, &arg);
20120 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
20123 + struct simple_arg arg = {
20127 + .want_excl = want_excl
20130 + return add_simple(dir, dentry, &arg);
20133 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20134 + struct vfsub_aopen_args *aopen_args)
20136 + struct simple_arg arg = {
20139 + .mode = aopen_args->create_mode,
20140 + .want_excl = aopen_args->open_flag & O_EXCL,
20141 + .try_aopen = true,
20142 + .aopen = aopen_args
20145 + return add_simple(dir, dentry, &arg);
20148 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
20151 + aufs_bindex_t bindex;
20152 + struct super_block *sb;
20153 + struct dentry *parent, *h_parent, *h_dentry;
20154 + struct inode *h_dir, *inode;
20155 + struct vfsmount *h_mnt;
20156 + struct au_wr_dir_args wr_dir_args = {
20157 + .force_btgt = -1,
20158 + .flags = AuWrDir_TMPFILE
20161 + /* copy-up may happen */
20165 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20166 + if (unlikely(err))
20169 + err = au_di_init(dentry);
20170 + if (unlikely(err))
20174 + parent = d_find_any_alias(dir);
20175 + AuDebugOn(!parent);
20176 + di_write_lock_parent(parent);
20177 + if (unlikely(d_inode(parent) != dir))
20180 + err = au_digen_test(parent, au_sigen(sb));
20181 + if (unlikely(err))
20184 + bindex = au_dbtop(parent);
20185 + au_set_dbtop(dentry, bindex);
20186 + au_set_dbbot(dentry, bindex);
20187 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
20189 + if (unlikely(err < 0))
20192 + err = -EOPNOTSUPP;
20193 + h_dir = au_h_iptr(dir, bindex);
20194 + if (unlikely(!h_dir->i_op->tmpfile))
20197 + h_mnt = au_sbr_mnt(sb, bindex);
20198 + err = vfsub_mnt_want_write(h_mnt);
20199 + if (unlikely(err))
20202 + h_parent = au_h_dptr(parent, bindex);
20203 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
20204 + if (IS_ERR(h_dentry)) {
20205 + err = PTR_ERR(h_dentry);
20209 + au_set_dbtop(dentry, bindex);
20210 + au_set_dbbot(dentry, bindex);
20211 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
20212 + inode = au_new_inode(dentry, /*must_new*/1);
20213 + if (IS_ERR(inode)) {
20214 + err = PTR_ERR(inode);
20215 + au_set_h_dptr(dentry, bindex, NULL);
20216 + au_set_dbtop(dentry, -1);
20217 + au_set_dbbot(dentry, -1);
20219 + if (!inode->i_nlink)
20220 + set_nlink(inode, 1);
20221 + d_tmpfile(dentry, inode);
20222 + au_di(dentry)->di_tmpfile = 1;
20224 + /* update without i_mutex */
20225 + if (au_ibtop(dir) == au_dbtop(dentry))
20226 + au_cpup_attr_timesizes(dir);
20231 + vfsub_mnt_drop_write(h_mnt);
20233 + di_write_unlock(parent);
20235 + di_write_unlock(dentry);
20236 + if (unlikely(err)) {
20237 + au_di_fin(dentry);
20238 + dentry->d_fsdata = NULL;
20241 + si_read_unlock(sb);
20243 + inode_unlock(dir);
20247 +/* ---------------------------------------------------------------------- */
20249 +struct au_link_args {
20250 + aufs_bindex_t bdst, bsrc;
20251 + struct au_pin pin;
20252 + struct path h_path;
20253 + struct dentry *src_parent, *parent;
20256 +static int au_cpup_before_link(struct dentry *src_dentry,
20257 + struct au_link_args *a)
20260 + struct dentry *h_src_dentry;
20261 + struct au_cp_generic cpg = {
20262 + .dentry = src_dentry,
20267 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20270 + di_read_lock_parent(a->src_parent, AuLock_IR);
20271 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20272 + if (unlikely(err))
20275 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20276 + err = au_pin(&a->pin, src_dentry, a->bdst,
20277 + au_opt_udba(src_dentry->d_sb),
20278 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20279 + if (unlikely(err))
20282 + err = au_sio_cpup_simple(&cpg);
20283 + au_unpin(&a->pin);
20286 + di_read_unlock(a->src_parent, AuLock_IR);
20290 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20291 + struct au_link_args *a)
20294 + unsigned char plink;
20295 + aufs_bindex_t bbot;
20296 + struct dentry *h_src_dentry;
20297 + struct inode *h_inode, *inode, *delegated;
20298 + struct super_block *sb;
20299 + struct file *h_file;
20303 + sb = src_dentry->d_sb;
20304 + inode = d_inode(src_dentry);
20305 + if (au_ibtop(inode) <= a->bdst)
20306 + h_inode = au_h_iptr(inode, a->bdst);
20307 + if (!h_inode || !h_inode->i_nlink) {
20308 + /* copyup src_dentry as the name of dentry. */
20309 + bbot = au_dbbot(dentry);
20310 + if (bbot < a->bsrc)
20311 + au_set_dbbot(dentry, a->bsrc);
20312 + au_set_h_dptr(dentry, a->bsrc,
20313 + dget(au_h_dptr(src_dentry, a->bsrc)));
20314 + dget(a->h_path.dentry);
20315 + au_set_h_dptr(dentry, a->bdst, NULL);
20316 + AuDbg("temporary d_inode...\n");
20317 + spin_lock(&dentry->d_lock);
20318 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20319 + spin_unlock(&dentry->d_lock);
20320 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20321 + if (IS_ERR(h_file))
20322 + err = PTR_ERR(h_file);
20324 + struct au_cp_generic cpg = {
20325 + .dentry = dentry,
20330 + .flags = AuCpup_KEEPLINO
20332 + err = au_sio_cpup_simple(&cpg);
20333 + au_h_open_post(dentry, a->bsrc, h_file);
20335 + dput(a->h_path.dentry);
20336 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20338 + au_set_h_dptr(dentry, a->bdst,
20339 + a->h_path.dentry);
20341 + spin_lock(&dentry->d_lock);
20342 + dentry->d_inode = NULL; /* restore */
20343 + spin_unlock(&dentry->d_lock);
20344 + AuDbg("temporary d_inode...done\n");
20345 + au_set_h_dptr(dentry, a->bsrc, NULL);
20346 + au_set_dbbot(dentry, bbot);
20348 + /* the inode of src_dentry already exists on a.bdst branch */
20349 + h_src_dentry = d_find_alias(h_inode);
20350 + if (!h_src_dentry && au_plink_test(inode)) {
20352 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20353 + err = PTR_ERR(h_src_dentry);
20354 + if (IS_ERR(h_src_dentry))
20357 + if (unlikely(d_is_negative(h_src_dentry))) {
20358 + dput(h_src_dentry);
20359 + h_src_dentry = NULL;
20363 + if (h_src_dentry) {
20364 + delegated = NULL;
20365 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20366 + &a->h_path, &delegated);
20367 + if (unlikely(err == -EWOULDBLOCK)) {
20368 + pr_warn("cannot retry for NFSv4 delegation"
20369 + " for an internal link\n");
20372 + dput(h_src_dentry);
20374 + AuIOErr("no dentry found for hi%lu on b%d\n",
20375 + h_inode->i_ino, a->bdst);
20380 + if (!err && !plink)
20381 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20388 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20389 + struct dentry *dentry)
20392 + struct au_dtime dt;
20393 + struct au_link_args *a;
20394 + struct dentry *wh_dentry, *h_src_dentry;
20395 + struct inode *inode, *delegated;
20396 + struct super_block *sb;
20397 + struct au_wr_dir_args wr_dir_args = {
20398 + /* .force_btgt = -1, */
20399 + .flags = AuWrDir_ADD_ENTRY
20403 + inode = d_inode(src_dentry);
20404 + IMustLock(inode);
20407 + a = kzalloc(sizeof(*a), GFP_NOFS);
20408 + if (unlikely(!a))
20411 + a->parent = dentry->d_parent; /* dir inode is locked */
20412 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20413 + AuLock_NOPLM | AuLock_GEN);
20414 + if (unlikely(err))
20416 + err = au_d_linkable(src_dentry);
20417 + if (unlikely(err))
20419 + err = au_d_may_add(dentry);
20420 + if (unlikely(err))
20423 + a->src_parent = dget_parent(src_dentry);
20424 + wr_dir_args.force_btgt = au_ibtop(inode);
20426 + di_write_lock_parent(a->parent);
20427 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20428 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20430 + err = PTR_ERR(wh_dentry);
20431 + if (IS_ERR(wh_dentry))
20435 + sb = dentry->d_sb;
20436 + a->bdst = au_dbtop(dentry);
20437 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20438 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20439 + a->bsrc = au_ibtop(inode);
20440 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20441 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20442 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20443 + if (!h_src_dentry) {
20444 + a->bsrc = au_dbtop(src_dentry);
20445 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20446 + AuDebugOn(!h_src_dentry);
20447 + } else if (IS_ERR(h_src_dentry)) {
20448 + err = PTR_ERR(h_src_dentry);
20453 + * aufs doesn't touch the credential so
20454 + * security_dentry_create_files_as() is unnecessary.
20456 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20457 + if (a->bdst < a->bsrc
20458 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20459 + err = au_cpup_or_link(src_dentry, dentry, a);
20461 + delegated = NULL;
20462 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20463 + &a->h_path, &delegated);
20464 + if (unlikely(err == -EWOULDBLOCK)) {
20465 + pr_warn("cannot retry for NFSv4 delegation"
20466 + " for an internal link\n");
20470 + dput(h_src_dentry);
20473 + * copyup src_dentry to the branch we process,
20474 + * and then link(2) to it.
20476 + dput(h_src_dentry);
20477 + if (a->bdst < a->bsrc
20478 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20479 + au_unpin(&a->pin);
20480 + di_write_unlock(a->parent);
20481 + err = au_cpup_before_link(src_dentry, a);
20482 + di_write_lock_parent(a->parent);
20484 + err = au_pin(&a->pin, dentry, a->bdst,
20486 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20487 + if (unlikely(err))
20491 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20493 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20494 + delegated = NULL;
20495 + err = vfsub_link(h_src_dentry,
20496 + au_pinned_h_dir(&a->pin),
20497 + &a->h_path, &delegated);
20498 + if (unlikely(err == -EWOULDBLOCK)) {
20499 + pr_warn("cannot retry"
20500 + " for NFSv4 delegation"
20501 + " for an internal link\n");
20507 + if (unlikely(err))
20511 + a->h_path.dentry = wh_dentry;
20512 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20514 + if (unlikely(err))
20518 + au_dir_ts(dir, a->bdst);
20519 + inode_inc_iversion(dir);
20520 + inc_nlink(inode);
20521 + inode->i_ctime = dir->i_ctime;
20522 + d_instantiate(dentry, au_igrab(inode));
20523 + if (d_unhashed(a->h_path.dentry))
20524 + /* some filesystem calls d_drop() */
20526 + /* some filesystems consume an inode even hardlink */
20527 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20528 + goto out_unpin; /* success */
20531 + /* no delegation since it is just created */
20532 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20533 + /*delegated*/NULL, /*force*/0);
20534 + if (unlikely(rerr)) {
20535 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20538 + au_dtime_revert(&dt);
20540 + au_unpin(&a->pin);
20544 + di_write_unlock(a->parent);
20545 + dput(a->src_parent);
20547 + if (unlikely(err)) {
20548 + au_update_dbtop(dentry);
20551 + aufs_read_and_write_unlock2(dentry, src_dentry);
20559 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20562 + aufs_bindex_t bindex;
20563 + unsigned char diropq;
20564 + struct path h_path;
20565 + struct dentry *wh_dentry, *parent, *opq_dentry;
20566 + struct inode *h_inode;
20567 + struct super_block *sb;
20569 + struct au_pin pin;
20570 + struct au_dtime dt;
20571 + } *a; /* reduce the stack usage */
20572 + struct au_wr_dir_args wr_dir_args = {
20573 + .force_btgt = -1,
20574 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20580 + a = kmalloc(sizeof(*a), GFP_NOFS);
20581 + if (unlikely(!a))
20584 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20585 + if (unlikely(err))
20587 + err = au_d_may_add(dentry);
20588 + if (unlikely(err))
20591 + parent = dentry->d_parent; /* dir inode is locked */
20592 + di_write_lock_parent(parent);
20593 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20594 + &a->pin, &wr_dir_args);
20595 + err = PTR_ERR(wh_dentry);
20596 + if (IS_ERR(wh_dentry))
20599 + sb = dentry->d_sb;
20600 + bindex = au_dbtop(dentry);
20601 + h_path.dentry = au_h_dptr(dentry, bindex);
20602 + h_path.mnt = au_sbr_mnt(sb, bindex);
20603 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20604 + if (unlikely(err))
20607 + /* make the dir opaque */
20609 + h_inode = d_inode(h_path.dentry);
20611 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20612 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20613 + opq_dentry = au_diropq_create(dentry, bindex);
20614 + inode_unlock(h_inode);
20615 + err = PTR_ERR(opq_dentry);
20616 + if (IS_ERR(opq_dentry))
20618 + dput(opq_dentry);
20622 + err = epilog(dir, bindex, wh_dentry, dentry);
20625 + goto out_unpin; /* success */
20630 + AuLabel(revert opq);
20631 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20632 + rerr = au_diropq_remove(dentry, bindex);
20633 + inode_unlock(h_inode);
20635 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20636 + dentry, err, rerr);
20642 + AuLabel(revert dir);
20643 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20645 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20646 + dentry, err, rerr);
20649 + au_dtime_revert(&a->dt);
20651 + au_unpin(&a->pin);
20654 + di_write_unlock(parent);
20656 + if (unlikely(err)) {
20657 + au_update_dbtop(dentry);
20660 + aufs_read_unlock(dentry, AuLock_DW);
20666 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20667 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20668 +++ linux/fs/aufs/i_op.c 2019-03-05 12:13:00.139224339 +0100
20670 +// SPDX-License-Identifier: GPL-2.0
20672 + * Copyright (C) 2005-2019 Junjiro R. Okajima
20674 + * This program, aufs is free software; you can redistribute it and/or modify
20675 + * it under the terms of the GNU General Public License as published by
20676 + * the Free Software Foundation; either version 2 of the License, or
20677 + * (at your option) any later version.
20679 + * This program is distributed in the hope that it will be useful,
20680 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20681 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20682 + * GNU General Public License for more details.
20684 + * You should have received a copy of the GNU General Public License
20685 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20689 + * inode operations (except add/del/rename)
20692 +#include <linux/device_cgroup.h>
20693 +#include <linux/fs_stack.h>
20694 +#include <linux/namei.h>
20695 +#include <linux/security.h>
20698 +static int h_permission(struct inode *h_inode, int mask,
20699 + struct path *h_path, int brperm)
20702 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20705 + if (write_mask && IS_IMMUTABLE(h_inode))
20709 + if (((mask & MAY_EXEC)
20710 + && S_ISREG(h_inode->i_mode)
20711 + && (path_noexec(h_path)
20712 + || !(h_inode->i_mode & 0111))))
20716 + * - skip the lower fs test in the case of write to ro branch.
20717 + * - nfs dir permission write check is optimized, but a policy for
20718 + * link/rename requires a real check.
20719 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20720 + * in this case, generic_permission() returns -EOPNOTSUPP.
20722 + if ((write_mask && !au_br_writable(brperm))
20723 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20724 + && write_mask && !(mask & MAY_READ))
20725 + || !h_inode->i_op->permission) {
20726 + /* AuLabel(generic_permission); */
20727 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20728 + err = generic_permission(h_inode, mask);
20729 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20730 + err = h_inode->i_op->permission(h_inode, mask);
20733 + /* AuLabel(h_inode->permission); */
20734 + err = h_inode->i_op->permission(h_inode, mask);
20739 + err = devcgroup_inode_permission(h_inode, mask);
20741 + err = security_inode_permission(h_inode, mask);
20745 + /* todo: do we need to call ima_path_check()? */
20746 + struct path h_path = {
20750 + err = ima_path_check(&h_path,
20751 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
20752 + IMA_COUNT_LEAVE);
20760 +static int aufs_permission(struct inode *inode, int mask)
20763 + aufs_bindex_t bindex, bbot;
20764 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20765 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20766 + struct inode *h_inode;
20767 + struct super_block *sb;
20768 + struct au_branch *br;
20770 + /* todo: support rcu-walk? */
20771 + if (mask & MAY_NOT_BLOCK)
20774 + sb = inode->i_sb;
20775 + si_read_lock(sb, AuLock_FLUSH);
20776 + ii_read_lock_child(inode);
20778 + err = au_iigen_test(inode, au_sigen(sb));
20779 + if (unlikely(err))
20785 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20786 + err = au_busy_or_stale();
20787 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20788 + if (unlikely(!h_inode
20789 + || (h_inode->i_mode & S_IFMT)
20790 + != (inode->i_mode & S_IFMT)))
20794 + bindex = au_ibtop(inode);
20795 + br = au_sbr(sb, bindex);
20796 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20799 + && !special_file(h_inode->i_mode)) {
20800 + /* test whether the upper writable branch exists */
20802 + for (; bindex >= 0; bindex--)
20803 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20811 + /* non-write to dir */
20813 + bbot = au_ibbot(inode);
20814 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20815 + h_inode = au_h_iptr(inode, bindex);
20817 + err = au_busy_or_stale();
20818 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20821 + br = au_sbr(sb, bindex);
20822 + err = h_permission(h_inode, mask, &br->br_path,
20828 + ii_read_unlock(inode);
20829 + si_read_unlock(sb);
20833 +/* ---------------------------------------------------------------------- */
20835 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20836 + unsigned int flags)
20838 + struct dentry *ret, *parent;
20839 + struct inode *inode;
20840 + struct super_block *sb;
20841 + int err, npositive;
20845 + /* todo: support rcu-walk? */
20846 + ret = ERR_PTR(-ECHILD);
20847 + if (flags & LOOKUP_RCU)
20850 + ret = ERR_PTR(-ENAMETOOLONG);
20851 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20855 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20856 + ret = ERR_PTR(err);
20857 + if (unlikely(err))
20860 + err = au_di_init(dentry);
20861 + ret = ERR_PTR(err);
20862 + if (unlikely(err))
20866 + npositive = 0; /* suppress a warning */
20867 + parent = dentry->d_parent; /* dir inode is locked */
20868 + di_read_lock_parent(parent, AuLock_IR);
20869 + err = au_alive_dir(parent);
20871 + err = au_digen_test(parent, au_sigen(sb));
20873 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20874 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20875 + AuLkup_ALLOW_NEG);
20878 + di_read_unlock(parent, AuLock_IR);
20879 + ret = ERR_PTR(err);
20880 + if (unlikely(err < 0))
20884 + inode = au_new_inode(dentry, /*must_new*/0);
20885 + if (IS_ERR(inode)) {
20886 + ret = (void *)inode;
20893 + atomic_inc(&inode->i_count);
20894 + ret = d_splice_alias(inode, dentry);
20896 + if (unlikely(d_need_lookup(dentry))) {
20897 + spin_lock(&dentry->d_lock);
20898 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20899 + spin_unlock(&dentry->d_lock);
20903 + if (!IS_ERR(ret)) {
20905 + if (ret && ret != dentry)
20906 + ii_write_unlock(inode);
20908 + ii_write_unlock(inode);
20915 + di_write_unlock(dentry);
20917 + si_read_unlock(sb);
20922 +/* ---------------------------------------------------------------------- */
20925 + * very dirty and complicated aufs ->atomic_open().
20926 + * aufs_atomic_open()
20927 + * + au_aopen_or_create()
20929 + * + vfsub_atomic_open()
20930 + * + branch fs ->atomic_open()
20931 + * may call the actual 'open' for h_file
20932 + * + inc br_nfiles only if opened
20933 + * + au_aopen_no_open() or au_aopen_do_open()
20935 + * au_aopen_do_open()
20936 + * + finish_open()
20937 + * + au_do_aopen()
20938 + * + au_do_open() the body of all 'open'
20939 + * + au_do_open_nondir()
20940 + * set the passed h_file
20942 + * au_aopen_no_open()
20943 + * + finish_no_open()
20946 +struct aopen_node {
20947 + struct hlist_bl_node hblist;
20948 + struct file *file, *h_file;
20951 +static int au_do_aopen(struct inode *inode, struct file *file)
20953 + struct hlist_bl_head *aopen;
20954 + struct hlist_bl_node *pos;
20955 + struct aopen_node *node;
20956 + struct au_do_open_args args = {
20958 + .open = au_do_open_nondir
20961 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20962 + hlist_bl_lock(aopen);
20963 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20964 + if (node->file == file) {
20965 + args.h_file = node->h_file;
20968 + hlist_bl_unlock(aopen);
20969 + /* AuDebugOn(!args.h_file); */
20971 + return au_do_open(file, &args);
20974 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20975 + struct aopen_node *aopen_node)
20978 + struct hlist_bl_head *aopen;
20981 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20982 + au_hbl_add(&aopen_node->hblist, aopen);
20983 + err = finish_open(file, dentry, au_do_aopen);
20984 + au_hbl_del(&aopen_node->hblist, aopen);
20985 + /* AuDbgFile(file); */
20986 + AuDbg("%pd%s%s\n", dentry,
20987 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20988 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20994 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
21000 + err = finish_no_open(file, dentry);
21006 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
21007 + struct file *file, unsigned int open_flag,
21008 + umode_t create_mode)
21010 + int err, did_open;
21011 + unsigned int lkup_flags;
21012 + aufs_bindex_t bindex;
21013 + struct super_block *sb;
21014 + struct dentry *parent, *d;
21015 + struct vfsub_aopen_args args = {
21016 + .open_flag = open_flag,
21017 + .create_mode = create_mode
21019 + struct aopen_node aopen_node = {
21024 + AuDbg("open_flag 0%o\n", open_flag);
21025 + AuDbgDentry(dentry);
21028 + if (!au_di(dentry)) {
21029 + lkup_flags = LOOKUP_OPEN;
21030 + if (open_flag & O_CREAT)
21031 + lkup_flags |= LOOKUP_CREATE;
21032 + d = aufs_lookup(dir, dentry, lkup_flags);
21034 + err = PTR_ERR(d);
21039 + * obsoleted dentry found.
21040 + * another error will be returned later.
21046 + AuDbgDentry(dentry);
21049 + if (d_is_positive(dentry)
21050 + || d_unhashed(dentry)
21051 + || d_unlinked(dentry)
21052 + || !(open_flag & O_CREAT)) {
21053 + err = au_aopen_no_open(file, dentry);
21054 + goto out; /* success */
21057 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
21058 + if (unlikely(err))
21061 + sb = dentry->d_sb;
21062 + parent = dentry->d_parent; /* dir is locked */
21063 + di_write_lock_parent(parent);
21064 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
21065 + if (unlikely(err < 0))
21068 + AuDbgDentry(dentry);
21069 + if (d_is_positive(dentry)) {
21070 + err = au_aopen_no_open(file, dentry);
21071 + goto out_parent; /* success */
21074 + args.file = alloc_empty_file(file->f_flags, current_cred());
21075 + err = PTR_ERR(args.file);
21076 + if (IS_ERR(args.file))
21079 + bindex = au_dbtop(dentry);
21080 + err = au_aopen_or_create(dir, dentry, &args);
21082 + AuDbgFile(args.file);
21083 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
21084 + did_open = !!(args.file->f_mode & FMODE_OPENED);
21087 + args.file = NULL;
21089 + di_write_unlock(parent);
21090 + di_write_unlock(dentry);
21091 + if (unlikely(err < 0)) {
21098 + err = au_aopen_no_open(file, dentry);
21100 + aopen_node.h_file = args.file;
21101 + err = au_aopen_do_open(file, dentry, &aopen_node);
21103 + if (unlikely(err < 0)) {
21107 + au_lcnt_dec(&args.br->br_nfiles);
21109 + goto out_sb; /* success */
21112 + di_write_unlock(parent);
21113 + di_write_unlock(dentry);
21115 + si_read_unlock(sb);
21123 +/* ---------------------------------------------------------------------- */
21125 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
21126 + const unsigned char add_entry, aufs_bindex_t bcpup,
21127 + aufs_bindex_t btop)
21130 + struct dentry *h_parent;
21131 + struct inode *h_dir;
21134 + IMustLock(d_inode(parent));
21136 + di_write_lock_parent(parent);
21139 + if (!au_h_dptr(parent, bcpup)) {
21140 + if (btop > bcpup)
21141 + err = au_cpup_dirs(dentry, bcpup);
21142 + else if (btop < bcpup)
21143 + err = au_cpdown_dirs(dentry, bcpup);
21147 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
21148 + h_parent = au_h_dptr(parent, bcpup);
21149 + h_dir = d_inode(h_parent);
21150 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
21151 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
21152 + /* todo: no unlock here */
21153 + inode_unlock_shared(h_dir);
21155 + AuDbg("bcpup %d\n", bcpup);
21157 + if (d_really_is_negative(dentry))
21158 + au_set_h_dptr(dentry, btop, NULL);
21159 + au_update_dbrange(dentry, /*do_put_zero*/0);
21164 + di_write_unlock(parent);
21166 + err = bcpup; /* success */
21173 + * decide the branch and the parent dir where we will create a new entry.
21174 + * returns new bindex or an error.
21175 + * copyup the parent dir if needed.
21177 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
21178 + struct au_wr_dir_args *args)
21181 + unsigned int flags;
21182 + aufs_bindex_t bcpup, btop, src_btop;
21183 + const unsigned char add_entry
21184 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
21185 + | au_ftest_wrdir(args->flags, TMPFILE);
21186 + struct super_block *sb;
21187 + struct dentry *parent;
21188 + struct au_sbinfo *sbinfo;
21190 + sb = dentry->d_sb;
21191 + sbinfo = au_sbi(sb);
21192 + parent = dget_parent(dentry);
21193 + btop = au_dbtop(dentry);
21195 + if (args->force_btgt < 0) {
21196 + if (src_dentry) {
21197 + src_btop = au_dbtop(src_dentry);
21198 + if (src_btop < btop)
21199 + bcpup = src_btop;
21200 + } else if (add_entry) {
21202 + if (au_ftest_wrdir(args->flags, ISDIR))
21203 + au_fset_wbr(flags, DIR);
21204 + err = AuWbrCreate(sbinfo, dentry, flags);
21208 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
21210 + err = AuWbrCopyup(sbinfo, dentry);
21212 + if (!IS_ROOT(dentry)) {
21213 + di_read_lock_parent(parent, !AuLock_IR);
21214 + err = AuWbrCopyup(sbinfo, dentry);
21215 + di_read_unlock(parent, !AuLock_IR);
21217 + err = AuWbrCopyup(sbinfo, dentry);
21220 + if (unlikely(err < 0))
21224 + bcpup = args->force_btgt;
21225 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21228 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21230 + if (bcpup == btop)
21231 + goto out; /* success */
21233 + /* copyup the new parent into the branch we process */
21234 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21236 + if (d_really_is_negative(dentry)) {
21237 + au_set_h_dptr(dentry, btop, NULL);
21238 + au_set_dbtop(dentry, bcpup);
21239 + au_set_dbbot(dentry, bcpup);
21241 + AuDebugOn(add_entry
21242 + && !au_ftest_wrdir(args->flags, TMPFILE)
21243 + && !au_h_dptr(dentry, bcpup));
21251 +/* ---------------------------------------------------------------------- */
21253 +void au_pin_hdir_unlock(struct au_pin *p)
21256 + au_hn_inode_unlock(p->hdir);
21259 +int au_pin_hdir_lock(struct au_pin *p)
21267 + /* even if an error happens later, keep this lock */
21268 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21271 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21276 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21277 + p->h_parent, p->br);
21283 +int au_pin_hdir_relock(struct au_pin *p)
21286 + struct inode *h_i;
21287 + struct dentry *h_d[] = {
21292 + err = au_pin_hdir_lock(p);
21293 + if (unlikely(err))
21296 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21299 + if (d_is_positive(h_d[i])) {
21300 + h_i = d_inode(h_d[i]);
21301 + err = !h_i->i_nlink;
21309 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21311 +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER)
21312 + p->hdir->hi_inode->i_rwsem.owner = task;
21316 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21319 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21320 + p->lsc_hi, 0, NULL, _RET_IP_);
21321 + au_pin_hdir_set_owner(p, current);
21325 +void au_pin_hdir_release(struct au_pin *p)
21328 + au_pin_hdir_set_owner(p, p->task);
21329 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
21333 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21335 + if (pin && pin->parent)
21336 + return au_h_dptr(pin->parent, pin->bindex);
21340 +void au_unpin(struct au_pin *p)
21343 + au_pin_hdir_unlock(p);
21344 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21345 + vfsub_mnt_drop_write(p->h_mnt);
21349 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21350 + di_read_unlock(p->parent, AuLock_IR);
21351 + iput(p->hdir->hi_inode);
21353 + p->parent = NULL;
21356 + /* do not clear p->task */
21359 +int au_do_pin(struct au_pin *p)
21362 + struct super_block *sb;
21363 + struct inode *h_dir;
21366 + sb = p->dentry->d_sb;
21367 + p->br = au_sbr(sb, p->bindex);
21368 + if (IS_ROOT(p->dentry)) {
21369 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21370 + p->h_mnt = au_br_mnt(p->br);
21371 + err = vfsub_mnt_want_write(p->h_mnt);
21372 + if (unlikely(err)) {
21373 + au_fclr_pin(p->flags, MNT_WRITE);
21380 + p->h_dentry = NULL;
21381 + if (p->bindex <= au_dbbot(p->dentry))
21382 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21384 + p->parent = dget_parent(p->dentry);
21385 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21386 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21389 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21390 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21392 + h_dir = p->hdir->hi_inode;
21396 + * if DI_LOCKED is not set, then p->parent may be different
21397 + * and h_parent can be NULL.
21399 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21401 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21402 + di_read_unlock(p->parent, AuLock_IR);
21404 + p->parent = NULL;
21408 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21409 + p->h_mnt = au_br_mnt(p->br);
21410 + err = vfsub_mnt_want_write(p->h_mnt);
21411 + if (unlikely(err)) {
21412 + au_fclr_pin(p->flags, MNT_WRITE);
21413 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21414 + di_read_unlock(p->parent, AuLock_IR);
21416 + p->parent = NULL;
21422 + err = au_pin_hdir_lock(p);
21424 + goto out; /* success */
21429 + pr_err("err %d\n", err);
21430 + err = au_busy_or_stale();
21435 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21436 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21437 + unsigned int udba, unsigned char flags)
21439 + p->dentry = dentry;
21441 + p->lsc_di = lsc_di;
21442 + p->lsc_hi = lsc_hi;
21443 + p->flags = flags;
21444 + p->bindex = bindex;
21446 + p->parent = NULL;
21450 + p->h_dentry = NULL;
21451 + p->h_parent = NULL;
21453 + p->task = current;
21456 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21457 + unsigned int udba, unsigned char flags)
21459 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21461 + return au_do_pin(pin);
21464 +/* ---------------------------------------------------------------------- */
21467 + * ->setattr() and ->getattr() are called in various cases.
21468 + * chmod, stat: dentry is revalidated.
21469 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21471 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21473 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21474 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21477 + struct dentry *parent;
21480 + if (au_digen_test(dentry, sigen)) {
21481 + parent = dget_parent(dentry);
21482 + di_read_lock_parent(parent, AuLock_IR);
21483 + err = au_refresh_dentry(dentry, parent);
21484 + di_read_unlock(parent, AuLock_IR);
21492 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21493 + struct au_icpup_args *a)
21497 + aufs_bindex_t btop, ibtop;
21498 + struct dentry *hi_wh, *parent;
21499 + struct inode *inode;
21500 + struct au_wr_dir_args wr_dir_args = {
21501 + .force_btgt = -1,
21505 + if (d_is_dir(dentry))
21506 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21507 + /* plink or hi_wh() case */
21508 + btop = au_dbtop(dentry);
21509 + inode = d_inode(dentry);
21510 + ibtop = au_ibtop(inode);
21511 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21512 + wr_dir_args.force_btgt = ibtop;
21513 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21514 + if (unlikely(err < 0))
21518 + au_fset_icpup(a->flags, DID_CPUP);
21521 + a->pin_flags = AuPin_MNT_WRITE;
21523 + if (!IS_ROOT(dentry)) {
21524 + au_fset_pin(a->pin_flags, DI_LOCKED);
21525 + parent = dget_parent(dentry);
21526 + di_write_lock_parent(parent);
21529 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21530 + if (unlikely(err))
21534 + a->h_path.dentry = au_h_dptr(dentry, btop);
21535 + a->h_inode = d_inode(a->h_path.dentry);
21536 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21537 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21538 + if (ia->ia_size < i_size_read(a->h_inode))
21539 + sz = ia->ia_size;
21540 + inode_unlock_shared(a->h_inode);
21544 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21545 + hi_wh = au_hi_wh(inode, a->btgt);
21547 + struct au_cp_generic cpg = {
21548 + .dentry = dentry,
21554 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21555 + if (unlikely(err))
21557 + hi_wh = au_hi_wh(inode, a->btgt);
21558 + /* todo: revalidate hi_wh? */
21563 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21564 + di_downgrade_lock(parent, AuLock_IR);
21568 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21569 + goto out; /* success */
21571 + if (!d_unhashed(dentry)) {
21572 + struct au_cp_generic cpg = {
21573 + .dentry = dentry,
21578 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21580 + err = au_sio_cpup_simple(&cpg);
21582 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21583 + } else if (!hi_wh)
21584 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21586 + a->h_path.dentry = hi_wh; /* do not dget here */
21589 + a->h_inode = d_inode(a->h_path.dentry);
21591 + goto out; /* success */
21592 + au_unpin(&a->pin);
21595 + di_write_unlock(parent);
21600 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21604 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21607 + struct inode *inode, *delegated;
21608 + struct super_block *sb;
21609 + struct file *file;
21610 + struct au_icpup_args *a;
21612 + inode = d_inode(dentry);
21613 + IMustLock(inode);
21615 + err = setattr_prepare(dentry, ia);
21616 + if (unlikely(err))
21620 + a = kzalloc(sizeof(*a), GFP_NOFS);
21621 + if (unlikely(!a))
21624 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21625 + ia->ia_valid &= ~ATTR_MODE;
21628 + sb = dentry->d_sb;
21629 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21630 + if (unlikely(err))
21633 + if (ia->ia_valid & ATTR_FILE) {
21634 + /* currently ftruncate(2) only */
21635 + AuDebugOn(!d_is_reg(dentry));
21636 + file = ia->ia_file;
21637 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21639 + if (unlikely(err))
21641 + ia->ia_file = au_hf_top(file);
21642 + a->udba = AuOpt_UDBA_NONE;
21644 + /* fchmod() doesn't pass ia_file */
21645 + a->udba = au_opt_udba(sb);
21646 + di_write_lock_child(dentry);
21647 + /* no d_unlinked(), to set UDBA_NONE for root */
21648 + if (d_unhashed(dentry))
21649 + a->udba = AuOpt_UDBA_NONE;
21650 + if (a->udba != AuOpt_UDBA_NONE) {
21651 + AuDebugOn(IS_ROOT(dentry));
21652 + err = au_reval_for_attr(dentry, au_sigen(sb));
21653 + if (unlikely(err))
21658 + err = au_pin_and_icpup(dentry, ia, a);
21659 + if (unlikely(err < 0))
21661 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21662 + ia->ia_file = NULL;
21663 + ia->ia_valid &= ~ATTR_FILE;
21666 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21667 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21668 + == (ATTR_MODE | ATTR_CTIME)) {
21669 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21670 + if (unlikely(err))
21672 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21673 + && (ia->ia_valid & ATTR_CTIME)) {
21674 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21675 + if (unlikely(err))
21679 + if (ia->ia_valid & ATTR_SIZE) {
21682 + if (ia->ia_size < i_size_read(inode))
21684 + truncate_setsize(inode, ia->ia_size);
21687 + if (ia->ia_valid & ATTR_FILE)
21689 + inode_unlock(a->h_inode);
21690 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21691 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21693 + delegated = NULL;
21695 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21697 + err = break_deleg_wait(&delegated);
21705 + * regardless aufs 'acl' option setting.
21706 + * why don't all acl-aware fs call this func from their ->setattr()?
21708 + if (!err && (ia->ia_valid & ATTR_MODE))
21709 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21711 + au_cpup_attr_changeable(inode);
21714 + inode_unlock(a->h_inode);
21715 + au_unpin(&a->pin);
21716 + if (unlikely(err))
21717 + au_update_dbtop(dentry);
21719 + di_write_unlock(dentry);
21721 + fi_write_unlock(file);
21722 + ia->ia_file = file;
21723 + ia->ia_valid |= ATTR_FILE;
21726 + si_read_unlock(sb);
21734 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21735 +static int au_h_path_to_set_attr(struct dentry *dentry,
21736 + struct au_icpup_args *a, struct path *h_path)
21739 + struct super_block *sb;
21741 + sb = dentry->d_sb;
21742 + a->udba = au_opt_udba(sb);
21743 + /* no d_unlinked(), to set UDBA_NONE for root */
21744 + if (d_unhashed(dentry))
21745 + a->udba = AuOpt_UDBA_NONE;
21746 + if (a->udba != AuOpt_UDBA_NONE) {
21747 + AuDebugOn(IS_ROOT(dentry));
21748 + err = au_reval_for_attr(dentry, au_sigen(sb));
21749 + if (unlikely(err))
21752 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21753 + if (unlikely(err < 0))
21756 + h_path->dentry = a->h_path.dentry;
21757 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21763 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21764 + struct au_sxattr *arg)
21767 + struct path h_path;
21768 + struct super_block *sb;
21769 + struct au_icpup_args *a;
21770 + struct inode *h_inode;
21772 + IMustLock(inode);
21775 + a = kzalloc(sizeof(*a), GFP_NOFS);
21776 + if (unlikely(!a))
21779 + sb = dentry->d_sb;
21780 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21781 + if (unlikely(err))
21784 + h_path.dentry = NULL; /* silence gcc */
21785 + di_write_lock_child(dentry);
21786 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21787 + if (unlikely(err))
21790 + inode_unlock(a->h_inode);
21791 + switch (arg->type) {
21792 + case AU_XATTR_SET:
21793 + AuDebugOn(d_is_negative(h_path.dentry));
21794 + err = vfsub_setxattr(h_path.dentry,
21795 + arg->u.set.name, arg->u.set.value,
21796 + arg->u.set.size, arg->u.set.flags);
21799 + err = -EOPNOTSUPP;
21800 + h_inode = d_inode(h_path.dentry);
21801 + if (h_inode->i_op->set_acl)
21802 + /* this will call posix_acl_update_mode */
21803 + err = h_inode->i_op->set_acl(h_inode,
21804 + arg->u.acl_set.acl,
21805 + arg->u.acl_set.type);
21809 + au_cpup_attr_timesizes(inode);
21811 + au_unpin(&a->pin);
21812 + if (unlikely(err))
21813 + au_update_dbtop(dentry);
21816 + di_write_unlock(dentry);
21817 + si_read_unlock(sb);
21826 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21827 + unsigned int nlink)
21831 + inode->i_mode = st->mode;
21832 + /* don't i_[ug]id_write() here */
21833 + inode->i_uid = st->uid;
21834 + inode->i_gid = st->gid;
21835 + inode->i_atime = st->atime;
21836 + inode->i_mtime = st->mtime;
21837 + inode->i_ctime = st->ctime;
21839 + au_cpup_attr_nlink(inode, /*force*/0);
21840 + if (S_ISDIR(inode->i_mode)) {
21841 + n = inode->i_nlink;
21844 + smp_mb(); /* for i_nlink */
21845 + /* 0 can happen */
21846 + set_nlink(inode, n);
21849 + spin_lock(&inode->i_lock);
21850 + inode->i_blocks = st->blocks;
21851 + i_size_write(inode, st->size);
21852 + spin_unlock(&inode->i_lock);
21856 + * common routine for aufs_getattr() and au_getxattr().
21857 + * returns zero or negative (an error).
21858 + * @dentry will be read-locked in success.
21860 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
21864 + unsigned int mnt_flags, sigen;
21865 + unsigned char udba_none;
21866 + aufs_bindex_t bindex;
21867 + struct super_block *sb, *h_sb;
21868 + struct inode *inode;
21870 + h_path->mnt = NULL;
21871 + h_path->dentry = NULL;
21874 + sb = dentry->d_sb;
21875 + mnt_flags = au_mntflags(sb);
21876 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21878 + if (unlikely(locked))
21879 + goto body; /* skip locking dinfo */
21881 + /* support fstat(2) */
21882 + if (!d_unlinked(dentry) && !udba_none) {
21883 + sigen = au_sigen(sb);
21884 + err = au_digen_test(dentry, sigen);
21886 + di_read_lock_child(dentry, AuLock_IR);
21887 + err = au_dbrange_test(dentry);
21888 + if (unlikely(err)) {
21889 + di_read_unlock(dentry, AuLock_IR);
21893 + AuDebugOn(IS_ROOT(dentry));
21894 + di_write_lock_child(dentry);
21895 + err = au_dbrange_test(dentry);
21897 + err = au_reval_for_attr(dentry, sigen);
21899 + di_downgrade_lock(dentry, AuLock_IR);
21901 + di_write_unlock(dentry);
21906 + di_read_lock_child(dentry, AuLock_IR);
21909 + inode = d_inode(dentry);
21910 + bindex = au_ibtop(inode);
21911 + h_path->mnt = au_sbr_mnt(sb, bindex);
21912 + h_sb = h_path->mnt->mnt_sb;
21914 + && !au_test_fs_bad_iattr(h_sb)
21916 + goto out; /* success */
21918 + if (au_dbtop(dentry) == bindex)
21919 + h_path->dentry = au_h_dptr(dentry, bindex);
21920 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21921 + h_path->dentry = au_plink_lkup(inode, bindex);
21922 + if (IS_ERR(h_path->dentry))
21923 + /* pretending success */
21924 + h_path->dentry = NULL;
21926 + dput(h_path->dentry);
21933 +static int aufs_getattr(const struct path *path, struct kstat *st,
21934 + u32 request, unsigned int query)
21937 + unsigned char positive;
21938 + struct path h_path;
21939 + struct dentry *dentry;
21940 + struct inode *inode;
21941 + struct super_block *sb;
21943 + dentry = path->dentry;
21944 + inode = d_inode(dentry);
21945 + sb = dentry->d_sb;
21946 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21947 + if (unlikely(err))
21949 + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
21950 + if (unlikely(err))
21952 + if (unlikely(!h_path.dentry))
21953 + /* illegally overlapped or something */
21954 + goto out_fill; /* pretending success */
21956 + positive = d_is_positive(h_path.dentry);
21958 + /* no vfsub version */
21959 + err = vfs_getattr(&h_path, st, request, query);
21962 + au_refresh_iattr(inode, st,
21963 + d_inode(h_path.dentry)->i_nlink);
21964 + goto out_fill; /* success */
21970 + generic_fillattr(inode, st);
21972 + di_read_unlock(dentry, AuLock_IR);
21974 + si_read_unlock(sb);
21980 +/* ---------------------------------------------------------------------- */
21982 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21983 + struct delayed_call *done)
21986 + struct dentry *h_dentry;
21987 + struct inode *h_inode;
21989 + aufs_bindex_t bindex;
21991 + ret = NULL; /* suppress a warning */
21996 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21997 + if (unlikely(err))
22000 + err = au_d_hashed_positive(dentry);
22001 + if (unlikely(err))
22005 + inode = d_inode(dentry);
22006 + bindex = au_ibtop(inode);
22007 + h_inode = au_h_iptr(inode, bindex);
22008 + if (unlikely(!h_inode->i_op->get_link))
22013 + if (au_dbtop(dentry) <= bindex) {
22014 + h_dentry = au_h_dptr(dentry, bindex);
22019 + h_dentry = d_find_any_alias(h_inode);
22020 + if (IS_ERR(h_dentry)) {
22021 + err = PTR_ERR(h_dentry);
22025 + if (unlikely(!h_dentry))
22029 + AuDbg("%ps\n", h_inode->i_op->get_link);
22030 + AuDbgDentry(h_dentry);
22031 + ret = vfs_get_link(h_dentry, done);
22034 + err = PTR_ERR(ret);
22037 + aufs_read_unlock(dentry, AuLock_IR);
22039 + if (unlikely(err))
22040 + ret = ERR_PTR(err);
22041 + AuTraceErrPtr(ret);
22045 +/* ---------------------------------------------------------------------- */
22047 +static int au_is_special(struct inode *inode)
22049 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
22052 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
22056 + aufs_bindex_t bindex;
22057 + struct super_block *sb;
22058 + struct inode *h_inode;
22059 + struct vfsmount *h_mnt;
22061 + sb = inode->i_sb;
22062 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
22063 + "unexpected s_flags 0x%lx", sb->s_flags);
22065 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
22067 + si_read_lock(sb, AuLock_FLUSH);
22068 + ii_write_lock_child(inode);
22071 + bindex = au_ibtop(inode);
22072 + h_inode = au_h_iptr(inode, bindex);
22073 + if (!au_test_ro(sb, bindex, inode)) {
22074 + h_mnt = au_sbr_mnt(sb, bindex);
22075 + err = vfsub_mnt_want_write(h_mnt);
22077 + err = vfsub_update_time(h_inode, ts, flags);
22078 + vfsub_mnt_drop_write(h_mnt);
22080 + } else if (au_is_special(h_inode)) {
22082 + * Never copy-up here.
22083 + * These special files may already be opened and used for
22084 + * communicating. If we copied it up, then the communication
22085 + * would be corrupted.
22087 + AuWarn1("timestamps for i%lu are ignored "
22088 + "since it is on readonly branch (hi%lu).\n",
22089 + inode->i_ino, h_inode->i_ino);
22090 + } else if (flags & ~S_ATIME) {
22092 + AuIOErr1("unexpected flags 0x%x\n", flags);
22097 + au_cpup_attr_timesizes(inode);
22098 + ii_write_unlock(inode);
22099 + si_read_unlock(sb);
22102 + if (!err && (flags & S_VERSION))
22103 + inode_inc_iversion(inode);
22108 +/* ---------------------------------------------------------------------- */
22110 +/* no getattr version will be set by module.c:aufs_init() */
22111 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
22113 + [AuIop_SYMLINK] = {
22114 + .permission = aufs_permission,
22115 +#ifdef CONFIG_FS_POSIX_ACL
22116 + .get_acl = aufs_get_acl,
22117 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
22120 + .setattr = aufs_setattr,
22121 + .getattr = aufs_getattr,
22123 +#ifdef CONFIG_AUFS_XATTR
22124 + .listxattr = aufs_listxattr,
22127 + .get_link = aufs_get_link,
22129 + /* .update_time = aufs_update_time */
22132 + .create = aufs_create,
22133 + .lookup = aufs_lookup,
22134 + .link = aufs_link,
22135 + .unlink = aufs_unlink,
22136 + .symlink = aufs_symlink,
22137 + .mkdir = aufs_mkdir,
22138 + .rmdir = aufs_rmdir,
22139 + .mknod = aufs_mknod,
22140 + .rename = aufs_rename,
22142 + .permission = aufs_permission,
22143 +#ifdef CONFIG_FS_POSIX_ACL
22144 + .get_acl = aufs_get_acl,
22145 + .set_acl = aufs_set_acl,
22148 + .setattr = aufs_setattr,
22149 + .getattr = aufs_getattr,
22151 +#ifdef CONFIG_AUFS_XATTR
22152 + .listxattr = aufs_listxattr,
22155 + .update_time = aufs_update_time,
22156 + .atomic_open = aufs_atomic_open,
22157 + .tmpfile = aufs_tmpfile
22159 + [AuIop_OTHER] = {
22160 + .permission = aufs_permission,
22161 +#ifdef CONFIG_FS_POSIX_ACL
22162 + .get_acl = aufs_get_acl,
22163 + .set_acl = aufs_set_acl,
22166 + .setattr = aufs_setattr,
22167 + .getattr = aufs_getattr,
22169 +#ifdef CONFIG_AUFS_XATTR
22170 + .listxattr = aufs_listxattr,
22173 + .update_time = aufs_update_time
22176 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
22177 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
22178 +++ linux/fs/aufs/i_op_del.c 2019-03-05 12:13:00.139224339 +0100
22180 +// SPDX-License-Identifier: GPL-2.0
22182 + * Copyright (C) 2005-2019 Junjiro R. Okajima
22184 + * This program, aufs is free software; you can redistribute it and/or modify
22185 + * it under the terms of the GNU General Public License as published by
22186 + * the Free Software Foundation; either version 2 of the License, or
22187 + * (at your option) any later version.
22189 + * This program is distributed in the hope that it will be useful,
22190 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22191 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22192 + * GNU General Public License for more details.
22194 + * You should have received a copy of the GNU General Public License
22195 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22199 + * inode operations (del entry)
22205 + * decide if a new whiteout for @dentry is necessary or not.
22206 + * when it is necessary, prepare the parent dir for the upper branch whose
22207 + * branch index is @bcpup for creation. the actual creation of the whiteout will
22208 + * be done by caller.
22210 + * 0: wh is unnecessary
22211 + * plus: wh is necessary
22214 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
22216 + int need_wh, err;
22217 + aufs_bindex_t btop;
22218 + struct super_block *sb;
22220 + sb = dentry->d_sb;
22221 + btop = au_dbtop(dentry);
22222 + if (*bcpup < 0) {
22224 + if (au_test_ro(sb, btop, d_inode(dentry))) {
22225 + err = AuWbrCopyup(au_sbi(sb), dentry);
22227 + if (unlikely(err < 0))
22231 + AuDebugOn(btop < *bcpup
22232 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22233 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22235 + if (*bcpup != btop) {
22236 + err = au_cpup_dirs(dentry, *bcpup);
22237 + if (unlikely(err))
22241 + struct au_dinfo *dinfo, *tmp;
22243 + need_wh = -ENOMEM;
22244 + dinfo = au_di(dentry);
22245 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22247 + au_di_cp(tmp, dinfo);
22248 + au_di_swap(tmp, dinfo);
22249 + /* returns the number of positive dentries */
22250 + need_wh = au_lkup_dentry(dentry, btop + 1,
22251 + /* AuLkup_IGNORE_PERM */ 0);
22252 + au_di_swap(tmp, dinfo);
22253 + au_rw_write_unlock(&tmp->di_rwsem);
22257 + AuDbg("need_wh %d\n", need_wh);
22265 + * simple tests for the del-entry operations.
22266 + * following the checks in vfs, plus the parent-child relationship.
22268 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22269 + struct dentry *h_parent, int isdir)
22273 + struct dentry *h_dentry, *h_latest;
22274 + struct inode *h_inode;
22276 + h_dentry = au_h_dptr(dentry, bindex);
22277 + if (d_really_is_positive(dentry)) {
22279 + if (unlikely(d_is_negative(h_dentry)))
22281 + h_inode = d_inode(h_dentry);
22282 + if (unlikely(!h_inode->i_nlink))
22285 + h_mode = h_inode->i_mode;
22288 + if (unlikely(S_ISDIR(h_mode)))
22290 + } else if (unlikely(!S_ISDIR(h_mode))) {
22295 + /* rename(2) case */
22297 + if (unlikely(d_is_positive(h_dentry)))
22302 + /* expected parent dir is locked */
22303 + if (unlikely(h_parent != h_dentry->d_parent))
22308 + * rmdir a dir may break the consistency on some filesystem.
22309 + * let's try heavy test.
22312 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22313 + && au_test_h_perm(d_inode(h_parent),
22314 + MAY_EXEC | MAY_WRITE)))
22317 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
22319 + if (IS_ERR(h_latest))
22321 + if (h_latest == h_dentry)
22330 + * decide the branch where we operate for @dentry. the branch index will be set
22331 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22332 + * dir for reverting.
22333 + * when a new whiteout is necessary, create it.
22335 +static struct dentry*
22336 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22337 + struct au_dtime *dt, struct au_pin *pin)
22339 + struct dentry *wh_dentry;
22340 + struct super_block *sb;
22341 + struct path h_path;
22342 + int err, need_wh;
22343 + unsigned int udba;
22344 + aufs_bindex_t bcpup;
22346 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22347 + wh_dentry = ERR_PTR(need_wh);
22348 + if (unlikely(need_wh < 0))
22351 + sb = dentry->d_sb;
22352 + udba = au_opt_udba(sb);
22354 + err = au_pin(pin, dentry, bcpup, udba,
22355 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22356 + wh_dentry = ERR_PTR(err);
22357 + if (unlikely(err))
22360 + h_path.dentry = au_pinned_h_parent(pin);
22361 + if (udba != AuOpt_UDBA_NONE
22362 + && au_dbtop(dentry) == bcpup) {
22363 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22364 + wh_dentry = ERR_PTR(err);
22365 + if (unlikely(err))
22369 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22370 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22371 + wh_dentry = NULL;
22373 + goto out; /* success, no need to create whiteout */
22375 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22376 + if (IS_ERR(wh_dentry))
22379 + /* returns with the parent is locked and wh_dentry is dget-ed */
22380 + goto out; /* success */
22385 + return wh_dentry;
22389 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22390 + * in order to be revertible and save time for removing many child whiteouts
22392 + * returns 1 when there are too many child whiteout and caller should remove
22393 + * them asynchronously. returns 0 when the number of children is enough small to
22394 + * remove now or the branch fs is a remote fs.
22395 + * otherwise return an error.
22397 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22398 + struct au_nhash *whlist, struct inode *dir)
22400 + int rmdir_later, err, dirwh;
22401 + struct dentry *h_dentry;
22402 + struct super_block *sb;
22403 + struct inode *inode;
22405 + sb = dentry->d_sb;
22406 + SiMustAnyLock(sb);
22407 + h_dentry = au_h_dptr(dentry, bindex);
22408 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22409 + if (unlikely(err))
22412 + /* stop monitoring */
22413 + inode = d_inode(dentry);
22414 + au_hn_free(au_hi(inode, bindex));
22416 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22417 + dirwh = au_sbi(sb)->si_dirwh;
22418 + rmdir_later = (dirwh <= 1);
22419 + if (!rmdir_later)
22420 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22423 + return rmdir_later;
22426 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22427 + if (unlikely(err)) {
22428 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22429 + h_dentry, bindex, err);
22439 + * final procedure for deleting a entry.
22440 + * maintain dentry and iattr.
22442 +static void epilog(struct inode *dir, struct dentry *dentry,
22443 + aufs_bindex_t bindex)
22445 + struct inode *inode;
22447 + inode = d_inode(dentry);
22449 + inode->i_ctime = dir->i_ctime;
22451 + au_dir_ts(dir, bindex);
22452 + inode_inc_iversion(dir);
22456 + * when an error happened, remove the created whiteout and revert everything.
22458 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22459 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22460 + struct dentry *dentry, struct au_dtime *dt)
22463 + struct path h_path = {
22464 + .dentry = wh_dentry,
22465 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22468 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22470 + au_set_dbwh(dentry, bwh);
22471 + au_dtime_revert(dt);
22475 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22479 +/* ---------------------------------------------------------------------- */
22481 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22484 + aufs_bindex_t bwh, bindex, btop;
22485 + struct inode *inode, *h_dir, *delegated;
22486 + struct dentry *parent, *wh_dentry;
22487 + /* to reduce stack size */
22489 + struct au_dtime dt;
22490 + struct au_pin pin;
22491 + struct path h_path;
22497 + a = kmalloc(sizeof(*a), GFP_NOFS);
22498 + if (unlikely(!a))
22501 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22502 + if (unlikely(err))
22504 + err = au_d_hashed_positive(dentry);
22505 + if (unlikely(err))
22507 + inode = d_inode(dentry);
22508 + IMustLock(inode);
22510 + if (unlikely(d_is_dir(dentry)))
22511 + goto out_unlock; /* possible? */
22513 + btop = au_dbtop(dentry);
22514 + bwh = au_dbwh(dentry);
22516 + parent = dentry->d_parent; /* dir inode is locked */
22517 + di_write_lock_parent(parent);
22518 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22520 + err = PTR_ERR(wh_dentry);
22521 + if (IS_ERR(wh_dentry))
22524 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22525 + a->h_path.dentry = au_h_dptr(dentry, btop);
22526 + dget(a->h_path.dentry);
22527 + if (bindex == btop) {
22528 + h_dir = au_pinned_h_dir(&a->pin);
22529 + delegated = NULL;
22530 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22531 + if (unlikely(err == -EWOULDBLOCK)) {
22532 + pr_warn("cannot retry for NFSv4 delegation"
22533 + " for an internal unlink\n");
22537 + /* dir inode is locked */
22538 + h_dir = d_inode(wh_dentry->d_parent);
22539 + IMustLock(h_dir);
22544 + vfsub_drop_nlink(inode);
22545 + epilog(dir, dentry, bindex);
22547 + /* update target timestamps */
22548 + if (bindex == btop) {
22549 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22551 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22553 + /* todo: this timestamp may be reverted later */
22554 + inode->i_ctime = h_dir->i_ctime;
22555 + goto out_unpin; /* success */
22562 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22569 + au_unpin(&a->pin);
22571 + dput(a->h_path.dentry);
22573 + di_write_unlock(parent);
22575 + aufs_read_unlock(dentry, AuLock_DW);
22582 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22584 + int err, rmdir_later;
22585 + aufs_bindex_t bwh, bindex, btop;
22586 + struct inode *inode;
22587 + struct dentry *parent, *wh_dentry, *h_dentry;
22588 + struct au_whtmp_rmdir *args;
22589 + /* to reduce stack size */
22591 + struct au_dtime dt;
22592 + struct au_pin pin;
22598 + a = kmalloc(sizeof(*a), GFP_NOFS);
22599 + if (unlikely(!a))
22602 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22603 + if (unlikely(err))
22605 + err = au_alive_dir(dentry);
22606 + if (unlikely(err))
22608 + inode = d_inode(dentry);
22609 + IMustLock(inode);
22611 + if (unlikely(!d_is_dir(dentry)))
22612 + goto out_unlock; /* possible? */
22615 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22616 + if (unlikely(!args))
22619 + parent = dentry->d_parent; /* dir inode is locked */
22620 + di_write_lock_parent(parent);
22621 + err = au_test_empty(dentry, &args->whlist);
22622 + if (unlikely(err))
22625 + btop = au_dbtop(dentry);
22626 + bwh = au_dbwh(dentry);
22628 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22630 + err = PTR_ERR(wh_dentry);
22631 + if (IS_ERR(wh_dentry))
22634 + h_dentry = au_h_dptr(dentry, btop);
22637 + if (bindex == btop) {
22638 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22640 + rmdir_later = err;
22644 + /* stop monitoring */
22645 + au_hn_free(au_hi(inode, btop));
22647 + /* dir inode is locked */
22648 + IMustLock(d_inode(wh_dentry->d_parent));
22653 + vfsub_dead_dir(inode);
22654 + au_set_dbdiropq(dentry, -1);
22655 + epilog(dir, dentry, bindex);
22657 + if (rmdir_later) {
22658 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22662 + goto out_unpin; /* success */
22670 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22677 + au_unpin(&a->pin);
22681 + di_write_unlock(parent);
22683 + au_whtmp_rmdir_free(args);
22685 + aufs_read_unlock(dentry, AuLock_DW);
22692 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22693 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22694 +++ linux/fs/aufs/i_op_ren.c 2019-03-05 12:13:00.139224339 +0100
22696 +// SPDX-License-Identifier: GPL-2.0
22698 + * Copyright (C) 2005-2019 Junjiro R. Okajima
22700 + * This program, aufs is free software; you can redistribute it and/or modify
22701 + * it under the terms of the GNU General Public License as published by
22702 + * the Free Software Foundation; either version 2 of the License, or
22703 + * (at your option) any later version.
22705 + * This program is distributed in the hope that it will be useful,
22706 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22707 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22708 + * GNU General Public License for more details.
22710 + * You should have received a copy of the GNU General Public License
22711 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22715 + * inode operation (rename entry)
22716 + * todo: this is crazy monster
22721 +enum { AuSRC, AuDST, AuSrcDst };
22722 +enum { AuPARENT, AuCHILD, AuParentChild };
22724 +#define AuRen_ISDIR_SRC 1
22725 +#define AuRen_ISDIR_DST (1 << 1)
22726 +#define AuRen_ISSAMEDIR (1 << 2)
22727 +#define AuRen_WHSRC (1 << 3)
22728 +#define AuRen_WHDST (1 << 4)
22729 +#define AuRen_MNT_WRITE (1 << 5)
22730 +#define AuRen_DT_DSTDIR (1 << 6)
22731 +#define AuRen_DIROPQ_SRC (1 << 7)
22732 +#define AuRen_DIROPQ_DST (1 << 8)
22733 +#define AuRen_DIRREN (1 << 9)
22734 +#define AuRen_DROPPED_SRC (1 << 10)
22735 +#define AuRen_DROPPED_DST (1 << 11)
22736 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22737 +#define au_fset_ren(flags, name) \
22738 + do { (flags) |= AuRen_##name; } while (0)
22739 +#define au_fclr_ren(flags, name) \
22740 + do { (flags) &= ~AuRen_##name; } while (0)
22742 +#ifndef CONFIG_AUFS_DIRREN
22743 +#undef AuRen_DIRREN
22744 +#define AuRen_DIRREN 0
22747 +struct au_ren_args {
22749 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22751 + struct inode *dir, *inode;
22752 + struct au_hinode *hdir, *hinode;
22753 + struct au_dtime dt[AuParentChild];
22754 + aufs_bindex_t btop, bdiropq;
22757 +#define src_dentry sd[AuSRC].dentry
22758 +#define src_dir sd[AuSRC].dir
22759 +#define src_inode sd[AuSRC].inode
22760 +#define src_h_dentry sd[AuSRC].h_dentry
22761 +#define src_parent sd[AuSRC].parent
22762 +#define src_h_parent sd[AuSRC].h_parent
22763 +#define src_wh_dentry sd[AuSRC].wh_dentry
22764 +#define src_hdir sd[AuSRC].hdir
22765 +#define src_hinode sd[AuSRC].hinode
22766 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22767 +#define src_dt sd[AuSRC].dt
22768 +#define src_btop sd[AuSRC].btop
22769 +#define src_bdiropq sd[AuSRC].bdiropq
22771 +#define dst_dentry sd[AuDST].dentry
22772 +#define dst_dir sd[AuDST].dir
22773 +#define dst_inode sd[AuDST].inode
22774 +#define dst_h_dentry sd[AuDST].h_dentry
22775 +#define dst_parent sd[AuDST].parent
22776 +#define dst_h_parent sd[AuDST].h_parent
22777 +#define dst_wh_dentry sd[AuDST].wh_dentry
22778 +#define dst_hdir sd[AuDST].hdir
22779 +#define dst_hinode sd[AuDST].hinode
22780 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22781 +#define dst_dt sd[AuDST].dt
22782 +#define dst_btop sd[AuDST].btop
22783 +#define dst_bdiropq sd[AuDST].bdiropq
22785 + struct dentry *h_trap;
22786 + struct au_branch *br;
22787 + struct path h_path;
22788 + struct au_nhash whlist;
22789 + aufs_bindex_t btgt, src_bwh;
22792 + unsigned short auren_flags;
22793 + unsigned char flags; /* syscall parameter */
22794 + unsigned char exchange;
22797 + struct au_whtmp_rmdir *thargs;
22798 + struct dentry *h_dst;
22799 + struct au_hinode *h_root;
22802 +/* ---------------------------------------------------------------------- */
22805 + * functions for reverting.
22806 + * when an error happened in a single rename systemcall, we should revert
22807 + * everything as if nothing happened.
22808 + * we don't need to revert the copied-up/down the parent dir since they are
22812 +#define RevertFailure(fmt, ...) do { \
22813 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22814 + ##__VA_ARGS__, err, rerr); \
22818 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22821 + struct dentry *d;
22822 +#define src_or_dst(member) a->sd[idx].member
22824 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22825 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22826 + rerr = au_diropq_remove(d, a->btgt);
22827 + au_hn_inode_unlock(src_or_dst(hinode));
22828 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22830 + RevertFailure("remove diropq %pd", d);
22832 +#undef src_or_dst_
22835 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22837 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22838 + au_ren_do_rev_diropq(err, a, AuSRC);
22839 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22840 + au_ren_do_rev_diropq(err, a, AuDST);
22843 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22846 + struct inode *delegated;
22848 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22849 + a->src_h_parent);
22850 + rerr = PTR_ERR(a->h_path.dentry);
22851 + if (IS_ERR(a->h_path.dentry)) {
22852 + RevertFailure("lkup one %pd", a->src_dentry);
22856 + delegated = NULL;
22857 + rerr = vfsub_rename(a->dst_h_dir,
22858 + au_h_dptr(a->src_dentry, a->btgt),
22859 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22860 + if (unlikely(rerr == -EWOULDBLOCK)) {
22861 + pr_warn("cannot retry for NFSv4 delegation"
22862 + " for an internal rename\n");
22865 + d_drop(a->h_path.dentry);
22866 + dput(a->h_path.dentry);
22867 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22869 + RevertFailure("rename %pd", a->src_dentry);
22872 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22875 + struct inode *delegated;
22877 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22878 + a->dst_h_parent);
22879 + rerr = PTR_ERR(a->h_path.dentry);
22880 + if (IS_ERR(a->h_path.dentry)) {
22881 + RevertFailure("lkup one %pd", a->dst_dentry);
22884 + if (d_is_positive(a->h_path.dentry)) {
22885 + d_drop(a->h_path.dentry);
22886 + dput(a->h_path.dentry);
22890 + delegated = NULL;
22891 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22892 + &delegated, a->flags);
22893 + if (unlikely(rerr == -EWOULDBLOCK)) {
22894 + pr_warn("cannot retry for NFSv4 delegation"
22895 + " for an internal rename\n");
22898 + d_drop(a->h_path.dentry);
22899 + dput(a->h_path.dentry);
22901 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22903 + RevertFailure("rename %pd", a->h_dst);
22906 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22910 + a->h_path.dentry = a->src_wh_dentry;
22911 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22912 + au_set_dbwh(a->src_dentry, a->src_bwh);
22914 + RevertFailure("unlink %pd", a->src_wh_dentry);
22916 +#undef RevertFailure
22918 +/* ---------------------------------------------------------------------- */
22921 + * when we have to copyup the renaming entry, do it with the rename-target name
22922 + * in order to minimize the cost (the later actual rename is unnecessary).
22923 + * otherwise rename it on the target branch.
22925 +static int au_ren_or_cpup(struct au_ren_args *a)
22928 + struct dentry *d;
22929 + struct inode *delegated;
22931 + d = a->src_dentry;
22932 + if (au_dbtop(d) == a->btgt) {
22933 + a->h_path.dentry = a->dst_h_dentry;
22934 + AuDebugOn(au_dbtop(d) != a->btgt);
22935 + delegated = NULL;
22936 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22937 + a->dst_h_dir, &a->h_path, &delegated,
22939 + if (unlikely(err == -EWOULDBLOCK)) {
22940 + pr_warn("cannot retry for NFSv4 delegation"
22941 + " for an internal rename\n");
22947 + if (!err && a->h_dst)
22948 + /* it will be set to dinfo later */
22954 +/* cf. aufs_rmdir() */
22955 +static int au_ren_del_whtmp(struct au_ren_args *a)
22958 + struct inode *dir;
22960 + dir = a->dst_dir;
22961 + SiMustAnyLock(dir->i_sb);
22962 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22963 + au_sbi(dir->i_sb)->si_dirwh)
22964 + || au_test_fs_remote(a->h_dst->d_sb)) {
22965 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22966 + if (unlikely(err))
22967 + pr_warn("failed removing whtmp dir %pd (%d), "
22968 + "ignored.\n", a->h_dst, err);
22970 + au_nhash_wh_free(&a->thargs->whlist);
22971 + a->thargs->whlist = a->whlist;
22972 + a->whlist.nh_num = 0;
22973 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22975 + a->thargs = NULL;
22981 +/* make it 'opaque' dir. */
22982 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22985 + struct dentry *d, *diropq;
22986 +#define src_or_dst(member) a->sd[idx].member
22989 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22990 + src_or_dst(bdiropq) = au_dbdiropq(d);
22991 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22992 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22993 + diropq = au_diropq_create(d, a->btgt);
22994 + au_hn_inode_unlock(src_or_dst(hinode));
22995 + if (IS_ERR(diropq))
22996 + err = PTR_ERR(diropq);
23000 +#undef src_or_dst_
23004 +static int au_ren_diropq(struct au_ren_args *a)
23007 + unsigned char always;
23008 + struct dentry *d;
23011 + d = a->dst_dentry; /* already renamed on the branch */
23012 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
23013 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23014 + && !au_ftest_ren(a->auren_flags, DIRREN)
23015 + && a->btgt != au_dbdiropq(a->src_dentry)
23016 + && (a->dst_wh_dentry
23017 + || a->btgt <= au_dbdiropq(d)
23018 + /* hide the lower to keep xino */
23019 + /* the lowers may not be a dir, but we hide them anyway */
23020 + || a->btgt < au_dbbot(d)
23023 + err = au_ren_do_diropq(a, AuSRC);
23024 + if (unlikely(err))
23026 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
23028 + if (!a->exchange)
23029 + goto out; /* success */
23031 + d = a->src_dentry; /* already renamed on the branch */
23032 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
23033 + && a->btgt != au_dbdiropq(a->dst_dentry)
23034 + && (a->btgt < au_dbdiropq(d)
23035 + || a->btgt < au_dbbot(d)
23037 + AuDbgDentry(a->src_dentry);
23038 + AuDbgDentry(a->dst_dentry);
23039 + err = au_ren_do_diropq(a, AuDST);
23040 + if (unlikely(err))
23041 + goto out_rev_src;
23042 + au_fset_ren(a->auren_flags, DIROPQ_DST);
23044 + goto out; /* success */
23047 + AuDbg("err %d, reverting src\n", err);
23048 + au_ren_rev_diropq(err, a);
23053 +static int do_rename(struct au_ren_args *a)
23056 + struct dentry *d, *h_d;
23058 + if (!a->exchange) {
23059 + /* prepare workqueue args for asynchronous rmdir */
23060 + h_d = a->dst_h_dentry;
23061 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
23062 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
23063 + && d_is_positive(h_d)) {
23065 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
23067 + if (unlikely(!a->thargs))
23069 + a->h_dst = dget(h_d);
23072 + /* create whiteout for src_dentry */
23073 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
23074 + a->src_bwh = au_dbwh(a->src_dentry);
23075 + AuDebugOn(a->src_bwh >= 0);
23076 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
23077 + a->src_h_parent);
23078 + err = PTR_ERR(a->src_wh_dentry);
23079 + if (IS_ERR(a->src_wh_dentry))
23083 + /* lookup whiteout for dentry */
23084 + if (au_ftest_ren(a->auren_flags, WHDST)) {
23085 + h_d = au_wh_lkup(a->dst_h_parent,
23086 + &a->dst_dentry->d_name, a->br);
23087 + err = PTR_ERR(h_d);
23090 + if (d_is_negative(h_d))
23093 + a->dst_wh_dentry = h_d;
23096 + /* rename dentry to tmpwh */
23098 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
23099 + if (unlikely(err))
23102 + d = a->dst_dentry;
23103 + au_set_h_dptr(d, a->btgt, NULL);
23104 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
23105 + if (unlikely(err))
23107 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
23111 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
23113 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
23114 + && d_is_positive(a->dst_h_dentry)
23115 + && a->src_btop != a->btgt);
23118 + /* rename by vfs_rename or cpup */
23119 + err = au_ren_or_cpup(a);
23120 + if (unlikely(err))
23121 + /* leave the copied-up one */
23124 + /* make dir opaque */
23125 + err = au_ren_diropq(a);
23126 + if (unlikely(err))
23129 + /* update target timestamps */
23130 + if (a->exchange) {
23131 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
23132 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
23133 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23134 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23136 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
23137 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
23138 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23139 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23141 + if (!a->exchange) {
23142 + /* remove whiteout for dentry */
23143 + if (a->dst_wh_dentry) {
23144 + a->h_path.dentry = a->dst_wh_dentry;
23145 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
23147 + if (unlikely(err))
23151 + /* remove whtmp */
23153 + au_ren_del_whtmp(a); /* ignore this error */
23155 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
23158 + goto out_success;
23161 + au_ren_rev_diropq(err, a);
23163 + au_ren_rev_rename(err, a);
23167 + au_ren_rev_whtmp(err, a);
23169 + dput(a->dst_wh_dentry);
23170 + a->dst_wh_dentry = NULL;
23172 + if (a->src_wh_dentry)
23173 + au_ren_rev_whsrc(err, a);
23175 + dput(a->src_wh_dentry);
23176 + dput(a->dst_wh_dentry);
23180 + au_whtmp_rmdir_free(a->thargs);
23181 + a->thargs = NULL;
23187 +/* ---------------------------------------------------------------------- */
23190 + * test if @dentry dir can be rename destination or not.
23191 + * success means, it is a logically empty dir.
23193 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
23195 + return au_test_empty(dentry, whlist);
23199 + * test if @a->src_dentry dir can be rename source or not.
23200 + * if it can, return 0.
23202 + * - it is a logically empty dir.
23203 + * - or, it exists on writable branch and has no children including whiteouts
23204 + * on the lower branch unless DIRREN is on.
23206 +static int may_rename_srcdir(struct au_ren_args *a)
23209 + unsigned int rdhash;
23210 + aufs_bindex_t btop, btgt;
23211 + struct dentry *dentry;
23212 + struct super_block *sb;
23213 + struct au_sbinfo *sbinfo;
23215 + dentry = a->src_dentry;
23216 + sb = dentry->d_sb;
23217 + sbinfo = au_sbi(sb);
23218 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
23219 + au_fset_ren(a->auren_flags, DIRREN);
23222 + btop = au_dbtop(dentry);
23223 + if (btop != btgt) {
23224 + struct au_nhash whlist;
23226 + SiMustAnyLock(sb);
23227 + rdhash = sbinfo->si_rdhash;
23229 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23231 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23232 + if (unlikely(err))
23234 + err = au_test_empty(dentry, &whlist);
23235 + au_nhash_wh_free(&whlist);
23239 + if (btop == au_dbtaildir(dentry))
23240 + return 0; /* success */
23242 + err = au_test_empty_lower(dentry);
23245 + if (err == -ENOTEMPTY) {
23246 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23249 + AuWarn1("renaming dir who has child(ren) on multiple "
23250 + "branches, is not supported\n");
23257 +/* side effect: sets whlist and h_dentry */
23258 +static int au_ren_may_dir(struct au_ren_args *a)
23261 + unsigned int rdhash;
23262 + struct dentry *d;
23264 + d = a->dst_dentry;
23265 + SiMustAnyLock(d->d_sb);
23268 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23269 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23271 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23272 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23273 + if (unlikely(err))
23276 + if (!a->exchange) {
23277 + au_set_dbtop(d, a->dst_btop);
23278 + err = may_rename_dstdir(d, &a->whlist);
23279 + au_set_dbtop(d, a->btgt);
23281 + err = may_rename_srcdir(a);
23283 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23284 + if (unlikely(err))
23287 + d = a->src_dentry;
23288 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23289 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23290 + err = may_rename_srcdir(a);
23291 + if (unlikely(err)) {
23292 + au_nhash_wh_free(&a->whlist);
23293 + a->whlist.nh_num = 0;
23300 +/* ---------------------------------------------------------------------- */
23303 + * simple tests for rename.
23304 + * following the checks in vfs, plus the parent-child relationship.
23306 +static int au_may_ren(struct au_ren_args *a)
23309 + struct inode *h_inode;
23311 + if (a->src_btop == a->btgt) {
23312 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23313 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23314 + if (unlikely(err))
23317 + if (unlikely(a->src_h_dentry == a->h_trap))
23322 + if (a->dst_btop != a->btgt)
23325 + err = -ENOTEMPTY;
23326 + if (unlikely(a->dst_h_dentry == a->h_trap))
23330 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23331 + if (d_really_is_negative(a->dst_dentry)) {
23332 + if (d_is_negative(a->dst_h_dentry))
23333 + err = au_may_add(a->dst_dentry, a->btgt,
23334 + a->dst_h_parent, isdir);
23336 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23338 + h_inode = d_inode(a->dst_h_dentry);
23339 + if (h_inode->i_nlink)
23340 + err = au_may_del(a->dst_dentry, a->btgt,
23341 + a->dst_h_parent, isdir);
23345 + if (unlikely(err == -ENOENT || err == -EEXIST))
23351 +/* ---------------------------------------------------------------------- */
23356 + * - src_dir and dir by lock_rename()
23357 + * - inode if exists
23360 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23362 + * + di_write_lock2_child()
23363 + * + di_write_lock_child()
23364 + * + ii_write_lock_child()
23365 + * + di_write_lock_child2()
23366 + * + ii_write_lock_child2()
23367 + * + src_parent and parent
23368 + * + di_write_lock_parent()
23369 + * + ii_write_lock_parent()
23370 + * + di_write_lock_parent2()
23371 + * + ii_write_lock_parent2()
23372 + * + lower src_dir and dir by vfsub_lock_rename()
23373 + * + verify the every relationships between child and parent. if any
23374 + * of them failed, unlock all and return -EBUSY.
23376 +static void au_ren_unlock(struct au_ren_args *a)
23378 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23379 + a->dst_h_parent, a->dst_hdir);
23380 + if (au_ftest_ren(a->auren_flags, DIRREN)
23382 + au_hn_inode_unlock(a->h_root);
23383 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23384 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23387 +static int au_ren_lock(struct au_ren_args *a)
23390 + unsigned int udba;
23393 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23394 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23395 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23396 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23398 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23399 + if (unlikely(err))
23401 + au_fset_ren(a->auren_flags, MNT_WRITE);
23402 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23403 + struct dentry *root;
23404 + struct inode *dir;
23407 + * sbinfo is already locked, so this ii_read_lock is
23408 + * unnecessary. but our debugging feature checks it.
23410 + root = a->src_inode->i_sb->s_root;
23411 + if (root != a->src_parent && root != a->dst_parent) {
23412 + dir = d_inode(root);
23413 + ii_read_lock_parent3(dir);
23414 + a->h_root = au_hi(dir, a->btgt);
23415 + ii_read_unlock(dir);
23416 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23419 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23420 + a->dst_h_parent, a->dst_hdir);
23421 + udba = au_opt_udba(a->src_dentry->d_sb);
23422 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23423 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23424 + err = au_busy_or_stale();
23425 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23426 + err = au_h_verify(a->src_h_dentry, udba,
23427 + d_inode(a->src_h_parent), a->src_h_parent,
23429 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23430 + err = au_h_verify(a->dst_h_dentry, udba,
23431 + d_inode(a->dst_h_parent), a->dst_h_parent,
23434 + goto out; /* success */
23436 + err = au_busy_or_stale();
23437 + au_ren_unlock(a);
23443 +/* ---------------------------------------------------------------------- */
23445 +static void au_ren_refresh_dir(struct au_ren_args *a)
23447 + struct inode *dir;
23449 + dir = a->dst_dir;
23450 + inode_inc_iversion(dir);
23451 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23452 + /* is this updating defined in POSIX? */
23453 + au_cpup_attr_timesizes(a->src_inode);
23454 + au_cpup_attr_nlink(dir, /*force*/1);
23456 + au_dir_ts(dir, a->btgt);
23458 + if (a->exchange) {
23459 + dir = a->src_dir;
23460 + inode_inc_iversion(dir);
23461 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23462 + /* is this updating defined in POSIX? */
23463 + au_cpup_attr_timesizes(a->dst_inode);
23464 + au_cpup_attr_nlink(dir, /*force*/1);
23466 + au_dir_ts(dir, a->btgt);
23469 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23472 + dir = a->src_dir;
23473 + inode_inc_iversion(dir);
23474 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23475 + au_cpup_attr_nlink(dir, /*force*/1);
23476 + au_dir_ts(dir, a->btgt);
23479 +static void au_ren_refresh(struct au_ren_args *a)
23481 + aufs_bindex_t bbot, bindex;
23482 + struct dentry *d, *h_d;
23483 + struct inode *i, *h_i;
23484 + struct super_block *sb;
23486 + d = a->dst_dentry;
23489 + /* already dget-ed by au_ren_or_cpup() */
23490 + au_set_h_dptr(d, a->btgt, a->h_dst);
23492 + i = a->dst_inode;
23494 + if (!a->exchange) {
23495 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23496 + vfsub_drop_nlink(i);
23498 + vfsub_dead_dir(i);
23499 + au_cpup_attr_timesizes(i);
23501 + au_update_dbrange(d, /*do_put_zero*/1);
23503 + au_cpup_attr_nlink(i, /*force*/1);
23506 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23507 + au_set_h_dptr(d, bindex, NULL);
23508 + bbot = au_dbbot(d);
23509 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23510 + au_set_h_dptr(d, bindex, NULL);
23511 + au_update_dbrange(d, /*do_put_zero*/0);
23515 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23516 + d_drop(a->src_dentry);
23517 + if (au_ftest_ren(a->auren_flags, DIRREN))
23518 + au_set_dbwh(a->src_dentry, -1);
23522 + d = a->src_dentry;
23523 + au_set_dbwh(d, -1);
23524 + bbot = au_dbbot(d);
23525 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23526 + h_d = au_h_dptr(d, bindex);
23528 + au_set_h_dptr(d, bindex, NULL);
23530 + au_set_dbbot(d, a->btgt);
23533 + i = a->src_inode;
23534 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23535 + return; /* success */
23537 + bbot = au_ibbot(i);
23538 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23539 + h_i = au_h_iptr(i, bindex);
23541 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23542 + /* ignore this error */
23543 + au_set_h_iptr(i, bindex, NULL, 0);
23546 + au_set_ibbot(i, a->btgt);
23549 +/* ---------------------------------------------------------------------- */
23551 +/* mainly for link(2) and rename(2) */
23552 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23554 + aufs_bindex_t bdiropq, bwh;
23555 + struct dentry *parent;
23556 + struct au_branch *br;
23558 + parent = dentry->d_parent;
23559 + IMustLock(d_inode(parent)); /* dir is locked */
23561 + bdiropq = au_dbdiropq(parent);
23562 + bwh = au_dbwh(dentry);
23563 + br = au_sbr(dentry->d_sb, btgt);
23564 + if (au_br_rdonly(br)
23565 + || (0 <= bdiropq && bdiropq < btgt)
23566 + || (0 <= bwh && bwh < btgt))
23569 + AuDbg("btgt %d\n", btgt);
23573 +/* sets src_btop, dst_btop and btgt */
23574 +static int au_ren_wbr(struct au_ren_args *a)
23577 + struct au_wr_dir_args wr_dir_args = {
23578 + /* .force_btgt = -1, */
23579 + .flags = AuWrDir_ADD_ENTRY
23582 + a->src_btop = au_dbtop(a->src_dentry);
23583 + a->dst_btop = au_dbtop(a->dst_dentry);
23584 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23585 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23586 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23587 + wr_dir_args.force_btgt = a->src_btop;
23588 + if (a->dst_inode && a->dst_btop < a->src_btop)
23589 + wr_dir_args.force_btgt = a->dst_btop;
23590 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23591 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23594 + au_update_dbtop(a->dst_dentry);
23599 +static void au_ren_dt(struct au_ren_args *a)
23601 + a->h_path.dentry = a->src_h_parent;
23602 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23603 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23604 + a->h_path.dentry = a->dst_h_parent;
23605 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23608 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23609 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23613 + a->h_path.dentry = a->src_h_dentry;
23614 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23615 + if (d_is_positive(a->dst_h_dentry)) {
23616 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23617 + a->h_path.dentry = a->dst_h_dentry;
23618 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23622 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23624 + struct dentry *h_d;
23625 + struct inode *h_inode;
23627 + au_dtime_revert(a->src_dt + AuPARENT);
23628 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23629 + au_dtime_revert(a->dst_dt + AuPARENT);
23631 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23632 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23633 + h_inode = d_inode(h_d);
23634 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23635 + au_dtime_revert(a->src_dt + AuCHILD);
23636 + inode_unlock(h_inode);
23638 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23639 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23640 + h_inode = d_inode(h_d);
23641 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23642 + au_dtime_revert(a->dst_dt + AuCHILD);
23643 + inode_unlock(h_inode);
23648 +/* ---------------------------------------------------------------------- */
23650 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23651 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23652 + unsigned int _flags)
23654 + int err, lock_flags;
23656 + /* reduce stack space */
23657 + struct au_ren_args *a;
23658 + struct au_pin pin;
23660 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23661 + IMustLock(_src_dir);
23662 + IMustLock(_dst_dir);
23665 + if (unlikely(_flags & RENAME_WHITEOUT))
23669 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23670 + a = kzalloc(sizeof(*a), GFP_NOFS);
23671 + if (unlikely(!a))
23674 + a->flags = _flags;
23675 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23676 + && RENAME_EXCHANGE > U8_MAX);
23677 + a->exchange = _flags & RENAME_EXCHANGE;
23678 + a->src_dir = _src_dir;
23679 + a->src_dentry = _src_dentry;
23680 + a->src_inode = NULL;
23681 + if (d_really_is_positive(a->src_dentry))
23682 + a->src_inode = d_inode(a->src_dentry);
23683 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23684 + a->dst_dir = _dst_dir;
23685 + a->dst_dentry = _dst_dentry;
23686 + a->dst_inode = NULL;
23687 + if (d_really_is_positive(a->dst_dentry))
23688 + a->dst_inode = d_inode(a->dst_dentry);
23689 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23690 + if (a->dst_inode) {
23692 + * if EXCHANGE && src is non-dir && dst is dir,
23693 + * dst is not locked.
23695 + /* IMustLock(a->dst_inode); */
23696 + au_igrab(a->dst_inode);
23700 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23701 + if (d_is_dir(a->src_dentry)) {
23702 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23703 + if (unlikely(!a->exchange
23704 + && d_really_is_positive(a->dst_dentry)
23705 + && !d_is_dir(a->dst_dentry)))
23707 + lock_flags |= AuLock_DIRS;
23709 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23710 + au_fset_ren(a->auren_flags, ISDIR_DST);
23711 + if (unlikely(!a->exchange
23712 + && d_really_is_positive(a->src_dentry)
23713 + && !d_is_dir(a->src_dentry)))
23715 + lock_flags |= AuLock_DIRS;
23717 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23719 + if (unlikely(err))
23722 + err = au_d_hashed_positive(a->src_dentry);
23723 + if (unlikely(err))
23726 + if (a->dst_inode) {
23728 + * If it is a dir, VFS unhash it before this
23729 + * function. It means we cannot rely upon d_unhashed().
23731 + if (unlikely(!a->dst_inode->i_nlink))
23733 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23734 + err = au_d_hashed_positive(a->dst_dentry);
23735 + if (unlikely(err && !a->exchange))
23737 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23739 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23743 + * is it possible?
23744 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23745 + * there may exist a problem somewhere else.
23748 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23751 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23752 + di_write_lock_parent(a->dst_parent);
23754 + /* which branch we process */
23755 + err = au_ren_wbr(a);
23756 + if (unlikely(err < 0))
23758 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23759 + a->h_path.mnt = au_br_mnt(a->br);
23761 + /* are they available to be renamed */
23762 + err = au_ren_may_dir(a);
23763 + if (unlikely(err))
23764 + goto out_children;
23766 + /* prepare the writable parent dir on the same branch */
23767 + if (a->dst_btop == a->btgt) {
23768 + au_fset_ren(a->auren_flags, WHDST);
23770 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23771 + if (unlikely(err))
23772 + goto out_children;
23776 + if (!a->exchange) {
23777 + if (a->src_dir != a->dst_dir) {
23779 + * this temporary unlock is safe,
23780 + * because both dir->i_mutex are locked.
23782 + di_write_unlock(a->dst_parent);
23783 + di_write_lock_parent(a->src_parent);
23784 + err = au_wr_dir_need_wh(a->src_dentry,
23785 + au_ftest_ren(a->auren_flags,
23788 + di_write_unlock(a->src_parent);
23789 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23791 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23793 + err = au_wr_dir_need_wh(a->src_dentry,
23794 + au_ftest_ren(a->auren_flags,
23798 + if (unlikely(err < 0))
23799 + goto out_children;
23801 + au_fset_ren(a->auren_flags, WHSRC);
23804 + if (a->src_btop != a->btgt) {
23805 + err = au_pin(&pin, a->src_dentry, a->btgt,
23806 + au_opt_udba(a->src_dentry->d_sb),
23807 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23809 + struct au_cp_generic cpg = {
23810 + .dentry = a->src_dentry,
23812 + .bsrc = a->src_btop,
23815 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23817 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23818 + err = au_sio_cpup_simple(&cpg);
23821 + if (unlikely(err))
23822 + goto out_children;
23823 + a->src_btop = a->btgt;
23824 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23825 + if (!a->exchange)
23826 + au_fset_ren(a->auren_flags, WHSRC);
23830 + if (a->exchange && a->dst_inode
23831 + && a->dst_btop != a->btgt) {
23832 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23833 + au_opt_udba(a->dst_dentry->d_sb),
23834 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23836 + struct au_cp_generic cpg = {
23837 + .dentry = a->dst_dentry,
23839 + .bsrc = a->dst_btop,
23842 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23844 + err = au_sio_cpup_simple(&cpg);
23847 + if (unlikely(err))
23848 + goto out_children;
23849 + a->dst_btop = a->btgt;
23850 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23853 + /* lock them all */
23854 + err = au_ren_lock(a);
23855 + if (unlikely(err))
23856 + /* leave the copied-up one */
23857 + goto out_children;
23859 + if (!a->exchange) {
23860 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23861 + err = au_may_ren(a);
23862 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23863 + err = -ENAMETOOLONG;
23864 + if (unlikely(err))
23868 + /* store timestamps to be revertible */
23871 + /* store dirren info */
23872 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23873 + err = au_dr_rename(a->src_dentry, a->btgt,
23874 + &a->dst_dentry->d_name, &rev);
23876 + if (unlikely(err))
23881 + err = do_rename(a);
23882 + if (unlikely(err))
23885 + if (au_ftest_ren(a->auren_flags, DIRREN))
23886 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23888 + /* update dir attributes */
23889 + au_ren_refresh_dir(a);
23891 + /* dput/iput all lower dentries */
23892 + au_ren_refresh(a);
23894 + goto out_hdir; /* success */
23897 + if (au_ftest_ren(a->auren_flags, DIRREN))
23898 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23900 + au_ren_rev_dt(err, a);
23902 + au_ren_unlock(a);
23904 + au_nhash_wh_free(&a->whlist);
23905 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23906 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23907 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23908 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23912 + if (d_unhashed(a->src_dentry))
23913 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23914 + if (d_unhashed(a->dst_dentry))
23915 + au_fset_ren(a->auren_flags, DROPPED_DST);
23916 + if (!a->exchange)
23917 + d_move(a->src_dentry, a->dst_dentry);
23919 + d_exchange(a->src_dentry, a->dst_dentry);
23920 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23921 + d_drop(a->dst_dentry);
23923 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23924 + d_drop(a->src_dentry);
23926 + au_update_dbtop(a->dst_dentry);
23927 + if (!a->dst_inode)
23928 + d_drop(a->dst_dentry);
23930 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23931 + di_write_unlock(a->dst_parent);
23933 + di_write_unlock2(a->src_parent, a->dst_parent);
23935 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23937 + iput(a->dst_inode);
23939 + au_whtmp_rmdir_free(a->thargs);
23945 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23946 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23947 +++ linux/fs/aufs/Kconfig 2018-06-04 09:08:09.181412645 +0200
23949 +# SPDX-License-Identifier: GPL-2.0
23951 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23953 + Aufs is a stackable unification filesystem such as Unionfs,
23954 + which unifies several directories and provides a merged single
23956 + In the early days, aufs was entirely re-designed and
23957 + re-implemented Unionfs Version 1.x series. Introducing many
23958 + original ideas, approaches and improvements, it becomes totally
23959 + different from Unionfs while keeping the basic features.
23963 + prompt "Maximum number of branches"
23964 + default AUFS_BRANCH_MAX_127
23966 + Specifies the maximum number of branches (or member directories)
23967 + in a single aufs. The larger value consumes more system
23968 + resources and has a minor impact to performance.
23969 +config AUFS_BRANCH_MAX_127
23972 + Specifies the maximum number of branches (or member directories)
23973 + in a single aufs. The larger value consumes more system
23974 + resources and has a minor impact to performance.
23975 +config AUFS_BRANCH_MAX_511
23978 + Specifies the maximum number of branches (or member directories)
23979 + in a single aufs. The larger value consumes more system
23980 + resources and has a minor impact to performance.
23981 +config AUFS_BRANCH_MAX_1023
23984 + Specifies the maximum number of branches (or member directories)
23985 + in a single aufs. The larger value consumes more system
23986 + resources and has a minor impact to performance.
23987 +config AUFS_BRANCH_MAX_32767
23990 + Specifies the maximum number of branches (or member directories)
23991 + in a single aufs. The larger value consumes more system
23992 + resources and has a minor impact to performance.
23995 +config AUFS_SBILIST
23997 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
24000 + Automatic configuration for internal use.
24001 + When aufs supports Magic SysRq or /proc, enabled automatically.
24003 +config AUFS_HNOTIFY
24004 + bool "Detect direct branch access (bypassing aufs)"
24006 + If you want to modify files on branches directly, eg. bypassing aufs,
24007 + and want aufs to detect the changes of them fully, then enable this
24008 + option and use 'udba=notify' mount option.
24009 + Currently there is only one available configuration, "fsnotify".
24010 + It will have a negative impact to the performance.
24011 + See detail in aufs.5.
24014 + prompt "method" if AUFS_HNOTIFY
24015 + default AUFS_HFSNOTIFY
24016 +config AUFS_HFSNOTIFY
24021 +config AUFS_EXPORT
24022 + bool "NFS-exportable aufs"
24023 + depends on EXPORTFS
24025 + If you want to export your mounted aufs via NFS, then enable this
24026 + option. There are several requirements for this configuration.
24027 + See detail in aufs.5.
24029 +config AUFS_INO_T_64
24031 + depends on AUFS_EXPORT
24032 + depends on 64BIT && !(ALPHA || S390)
24035 + Automatic configuration for internal use.
24036 + /* typedef unsigned long/int __kernel_ino_t */
24037 + /* alpha and s390x are int */
24040 + bool "support for XATTR/EA (including Security Labels)"
24042 + If your branch fs supports XATTR/EA and you want to make them
24043 + available in aufs too, then enable this opsion and specify the
24044 + branch attributes for EA.
24045 + See detail in aufs.5.
24048 + bool "File-based Hierarchical Storage Management"
24050 + Hierarchical Storage Management (or HSM) is a well-known feature
24051 + in the storage world. Aufs provides this feature as file-based.
24052 + with multiple branches.
24053 + These multiple branches are prioritized, ie. the topmost one
24054 + should be the fastest drive and be used heavily.
24057 + bool "Readdir in userspace"
24059 + Aufs has two methods to provide a merged view for a directory,
24060 + by a user-space library and by kernel-space natively. The latter
24061 + is always enabled but sometimes large and slow.
24062 + If you enable this option, install the library in aufs2-util
24063 + package, and set some environment variables for your readdir(3),
24064 + then the work will be handled in user-space which generally
24065 + shows better performance in most cases.
24066 + See detail in aufs.5.
24068 +config AUFS_DIRREN
24069 + bool "Workaround for rename(2)-ing a directory"
24071 + By default, aufs returns EXDEV error in renameing a dir who has
24072 + his child on the lower branch, since it is a bad idea to issue
24073 + rename(2) internally for every lower branch. But user may not
24074 + accept this behaviour. So here is a workaround to allow such
24075 + rename(2) and store some extra infromation on the writable
24076 + branch. Obviously this costs high (and I don't like it).
24077 + To use this feature, you need to enable this configuration AND
24078 + to specify the mount option `dirren.'
24079 + See details in aufs.5 and the design documents.
24082 + bool "Show whiteouts"
24084 + If you want to make the whiteouts in aufs visible, then enable
24085 + this option and specify 'shwh' mount option. Although it may
24086 + sounds like philosophy or something, but in technically it
24087 + simply shows the name of whiteout with keeping its behaviour.
24089 +config AUFS_BR_RAMFS
24090 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
24092 + If you want to use ramfs as an aufs branch fs, then enable this
24093 + option. Generally tmpfs is recommended.
24094 + Aufs prohibited them to be a branch fs by default, because
24095 + initramfs becomes unusable after switch_root or something
24096 + generally. If you sets initramfs as an aufs branch and boot your
24097 + system by switch_root, you will meet a problem easily since the
24098 + files in initramfs may be inaccessible.
24099 + Unless you are going to use ramfs as an aufs branch fs without
24100 + switch_root or something, leave it N.
24102 +config AUFS_BR_FUSE
24103 + bool "Fuse fs as an aufs branch"
24104 + depends on FUSE_FS
24107 + If you want to use fuse-based userspace filesystem as an aufs
24108 + branch fs, then enable this option.
24109 + It implements the internal poll(2) operation which is
24110 + implemented by fuse only (curretnly).
24115 + Automatic configuration for internal use.
24117 +config AUFS_BR_HFSPLUS
24118 + bool "Hfsplus as an aufs branch"
24119 + depends on HFSPLUS_FS
24122 + If you want to use hfsplus fs as an aufs branch fs, then enable
24123 + this option. This option introduces a small overhead at
24124 + copying-up a file on hfsplus.
24126 +config AUFS_BDEV_LOOP
24128 + depends on BLK_DEV_LOOP
24131 + Automatic configuration for internal use.
24132 + Convert =[ym] into =y.
24135 + bool "Debug aufs"
24137 + Enable this to compile aufs internal debug code.
24138 + It will have a negative impact to the performance.
24140 +config AUFS_MAGIC_SYSRQ
24142 + depends on AUFS_DEBUG && MAGIC_SYSRQ
24145 + Automatic configuration for internal use.
24146 + When aufs supports Magic SysRq, enabled automatically.
24148 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
24149 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
24150 +++ linux/fs/aufs/lcnt.h 2019-03-05 12:13:00.142557771 +0100
24152 +/* SPDX-License-Identifier: GPL-2.0 */
24154 + * Copyright (C) 2018-2019 Junjiro R. Okajima
24156 + * This program, aufs is free software; you can redistribute it and/or modify
24157 + * it under the terms of the GNU General Public License as published by
24158 + * the Free Software Foundation; either version 2 of the License, or
24159 + * (at your option) any later version.
24161 + * This program is distributed in the hope that it will be useful,
24162 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24163 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24164 + * GNU General Public License for more details.
24166 + * You should have received a copy of the GNU General Public License
24167 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24171 + * simple long counter wrapper
24174 +#ifndef __AUFS_LCNT_H__
24175 +#define __AUFS_LCNT_H__
24179 +#include "debug.h"
24181 +#define AuLCntATOMIC 1
24182 +#define AuLCntPCPUCNT 2
24184 + * why does percpu_refcount require extra synchronize_rcu()s in
24185 + * au_br_do_free()
24187 +#define AuLCntPCPUREF 3
24189 +/* #define AuLCntChosen AuLCntATOMIC */
24190 +#define AuLCntChosen AuLCntPCPUCNT
24191 +/* #define AuLCntChosen AuLCntPCPUREF */
24193 +#if AuLCntChosen == AuLCntATOMIC
24194 +#include <linux/atomic.h>
24196 +typedef atomic_long_t au_lcnt_t;
24198 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24200 + atomic_long_set(cnt, 0);
24204 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24209 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
24210 + int do_sync __maybe_unused)
24215 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24217 + atomic_long_inc(cnt);
24220 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24222 + atomic_long_dec(cnt);
24225 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24227 + return atomic_long_read(cnt);
24231 +#if AuLCntChosen == AuLCntPCPUCNT
24232 +#include <linux/percpu_counter.h>
24234 +typedef struct percpu_counter au_lcnt_t;
24236 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24238 + return percpu_counter_init(cnt, 0, GFP_NOFS);
24241 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24246 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
24248 + percpu_counter_destroy(cnt);
24251 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24253 + percpu_counter_inc(cnt);
24256 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24258 + percpu_counter_dec(cnt);
24261 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24265 + n = percpu_counter_sum(cnt);
24267 + if (LONG_MAX != LLONG_MAX
24269 + AuWarn1("%s\n", "wrap-around");
24275 +#if AuLCntChosen == AuLCntPCPUREF
24276 +#include <linux/percpu-refcount.h>
24278 +typedef struct percpu_ref au_lcnt_t;
24280 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24283 + release = percpu_ref_exit;
24284 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24287 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24289 + synchronize_rcu();
24292 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24294 + percpu_ref_kill(cnt);
24296 + au_lcnt_wait_for_fin(cnt);
24299 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24301 + percpu_ref_get(cnt);
24304 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24306 + percpu_ref_put(cnt);
24310 + * avoid calling this func as possible.
24312 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24316 + percpu_ref_switch_to_atomic_sync(cnt);
24317 + l = atomic_long_read(&cnt->count);
24319 + percpu_ref_switch_to_percpu(cnt);
24321 + /* percpu_ref is initialized by 1 instead of 0 */
24326 +#ifdef CONFIG_AUFS_DEBUG
24327 +#define AuLCntZero(val) do { \
24330 + AuDbg("%s = %ld\n", #val, l); \
24333 +#define AuLCntZero(val) do {} while (0)
24336 +#endif /* __KERNEL__ */
24337 +#endif /* __AUFS_LCNT_H__ */
24338 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24339 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24340 +++ linux/fs/aufs/loop.c 2019-03-05 12:13:00.142557771 +0100
24342 +// SPDX-License-Identifier: GPL-2.0
24344 + * Copyright (C) 2005-2019 Junjiro R. Okajima
24346 + * This program, aufs is free software; you can redistribute it and/or modify
24347 + * it under the terms of the GNU General Public License as published by
24348 + * the Free Software Foundation; either version 2 of the License, or
24349 + * (at your option) any later version.
24351 + * This program is distributed in the hope that it will be useful,
24352 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24353 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24354 + * GNU General Public License for more details.
24356 + * You should have received a copy of the GNU General Public License
24357 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24361 + * support for loopback block device as a branch
24366 +/* added into drivers/block/loop.c */
24367 +static struct file *(*backing_file_func)(struct super_block *sb);
24370 + * test if two lower dentries have overlapping branches.
24372 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24374 + struct super_block *h_sb;
24375 + struct file *backing_file;
24377 + if (unlikely(!backing_file_func)) {
24378 + /* don't load "loop" module here */
24379 + backing_file_func = symbol_get(loop_backing_file);
24380 + if (unlikely(!backing_file_func))
24381 + /* "loop" module is not loaded */
24385 + h_sb = h_adding->d_sb;
24386 + backing_file = backing_file_func(h_sb);
24387 + if (!backing_file)
24390 + h_adding = backing_file->f_path.dentry;
24392 + * h_adding can be local NFS.
24393 + * in this case aufs cannot detect the loop.
24395 + if (unlikely(h_adding->d_sb == sb))
24397 + return !!au_test_subdir(h_adding, sb->s_root);
24400 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24401 +int au_test_loopback_kthread(void)
24404 + struct task_struct *tsk = current;
24405 + char c, comm[sizeof(tsk->comm)];
24408 + if (tsk->flags & PF_KTHREAD) {
24409 + get_task_comm(comm, tsk);
24411 + ret = ('0' <= c && c <= '9'
24412 + && !strncmp(comm, "loop", 4));
24418 +/* ---------------------------------------------------------------------- */
24420 +#define au_warn_loopback_step 16
24421 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24422 +static unsigned long *au_warn_loopback_array;
24424 +void au_warn_loopback(struct super_block *h_sb)
24426 + int i, new_nelem;
24427 + unsigned long *a, magic;
24428 + static DEFINE_SPINLOCK(spin);
24430 + magic = h_sb->s_magic;
24431 + spin_lock(&spin);
24432 + a = au_warn_loopback_array;
24433 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24434 + if (a[i] == magic) {
24435 + spin_unlock(&spin);
24439 + /* h_sb is new to us, print it */
24440 + if (i < au_warn_loopback_nelem) {
24445 + /* expand the array */
24446 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24447 + a = au_kzrealloc(au_warn_loopback_array,
24448 + au_warn_loopback_nelem * sizeof(unsigned long),
24449 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24450 + /*may_shrink*/0);
24452 + au_warn_loopback_nelem = new_nelem;
24453 + au_warn_loopback_array = a;
24458 + spin_unlock(&spin);
24459 + AuWarn1("realloc failed, ignored\n");
24463 + spin_unlock(&spin);
24464 + pr_warn("you may want to try another patch for loopback file "
24465 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24468 +int au_loopback_init(void)
24471 + struct super_block *sb __maybe_unused;
24473 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
24476 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24477 + sizeof(unsigned long), GFP_NOFS);
24478 + if (unlikely(!au_warn_loopback_array))
24484 +void au_loopback_fin(void)
24486 + if (backing_file_func)
24487 + symbol_put(loop_backing_file);
24488 + au_kfree_try_rcu(au_warn_loopback_array);
24490 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24491 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24492 +++ linux/fs/aufs/loop.h 2019-03-05 12:13:00.142557771 +0100
24494 +/* SPDX-License-Identifier: GPL-2.0 */
24496 + * Copyright (C) 2005-2019 Junjiro R. Okajima
24498 + * This program, aufs is free software; you can redistribute it and/or modify
24499 + * it under the terms of the GNU General Public License as published by
24500 + * the Free Software Foundation; either version 2 of the License, or
24501 + * (at your option) any later version.
24503 + * This program is distributed in the hope that it will be useful,
24504 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24505 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24506 + * GNU General Public License for more details.
24508 + * You should have received a copy of the GNU General Public License
24509 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24513 + * support for loopback mount as a branch
24516 +#ifndef __AUFS_LOOP_H__
24517 +#define __AUFS_LOOP_H__
24522 +struct super_block;
24524 +#ifdef CONFIG_AUFS_BDEV_LOOP
24525 +/* drivers/block/loop.c */
24526 +struct file *loop_backing_file(struct super_block *sb);
24529 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24530 +int au_test_loopback_kthread(void);
24531 +void au_warn_loopback(struct super_block *h_sb);
24533 +int au_loopback_init(void);
24534 +void au_loopback_fin(void);
24536 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24537 + struct dentry *h_adding)
24538 +AuStubInt0(au_test_loopback_kthread, void)
24539 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24541 +AuStubInt0(au_loopback_init, void)
24542 +AuStubVoid(au_loopback_fin, void)
24543 +#endif /* BLK_DEV_LOOP */
24545 +#endif /* __KERNEL__ */
24546 +#endif /* __AUFS_LOOP_H__ */
24547 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24548 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24549 +++ linux/fs/aufs/magic.mk 2018-06-04 09:08:09.188079511 +0200
24551 +# SPDX-License-Identifier: GPL-2.0
24553 +# defined in ${srctree}/fs/fuse/inode.c
24555 +ifdef CONFIG_FUSE_FS
24556 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24559 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24561 +ifdef CONFIG_XFS_FS
24562 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24565 +# defined in ${srctree}/fs/configfs/mount.c
24567 +ifdef CONFIG_CONFIGFS_FS
24568 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24571 +# defined in ${srctree}/fs/ubifs/ubifs.h
24573 +ifdef CONFIG_UBIFS_FS
24574 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24577 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24579 +ifdef CONFIG_HFSPLUS_FS
24580 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24582 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24583 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24584 +++ linux/fs/aufs/Makefile 2018-06-04 09:08:09.181412645 +0200
24586 +# SPDX-License-Identifier: GPL-2.0
24588 +include ${src}/magic.mk
24589 +ifeq (${CONFIG_AUFS_FS},m)
24590 +include ${src}/conf.mk
24592 +-include ${src}/priv_def.mk
24594 +# cf. include/linux/kernel.h
24596 +ccflags-y += -DDEBUG
24597 +# sparse requires the full pathname
24599 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24601 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24604 +obj-$(CONFIG_AUFS_FS) += aufs.o
24605 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24606 + wkq.o vfsub.o dcsub.o \
24607 + cpup.o whout.o wbr_policy.o \
24608 + dinfo.o dentry.o \
24610 + finfo.o file.o f_op.o \
24612 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24616 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24617 +aufs-$(CONFIG_SYSFS) += sysfs.o
24618 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24619 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24620 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24621 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24622 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24623 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24624 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24625 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24626 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24627 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24628 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24629 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24630 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24631 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24632 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24633 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24634 +++ linux/fs/aufs/module.c 2019-03-05 12:13:00.142557771 +0100
24636 +// SPDX-License-Identifier: GPL-2.0
24638 + * Copyright (C) 2005-2019 Junjiro R. Okajima
24640 + * This program, aufs is free software; you can redistribute it and/or modify
24641 + * it under the terms of the GNU General Public License as published by
24642 + * the Free Software Foundation; either version 2 of the License, or
24643 + * (at your option) any later version.
24645 + * This program is distributed in the hope that it will be useful,
24646 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24647 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24648 + * GNU General Public License for more details.
24650 + * You should have received a copy of the GNU General Public License
24651 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24655 + * module global variables and operations
24658 +#include <linux/module.h>
24659 +#include <linux/seq_file.h>
24662 +/* shrinkable realloc */
24663 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24671 +#if 0 /* unused */
24678 + AuDebugOn(!new_sz);
24681 + diff = au_kmidx_sub(sz, new_sz);
24687 + /* expand or SLOB */
24688 + p = krealloc(p, new_sz, gfp);
24689 + else if (new_sz < sz && may_shrink) {
24693 + q = kmalloc(new_sz, gfp);
24696 + memcpy(q, p, new_sz);
24697 + au_kfree_try_rcu(p);
24708 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24711 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24712 + if (p && new_sz > nused)
24713 + memset(p + nused, 0, new_sz - nused);
24717 +/* ---------------------------------------------------------------------- */
24721 +struct kmem_cache *au_cache[AuCache_Last];
24723 +static void au_cache_fin(void)
24728 + * Make sure all delayed rcu free inodes are flushed before we
24733 + /* excluding AuCache_HNOTIFY */
24734 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24735 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24736 + kmem_cache_destroy(au_cache[i]);
24737 + au_cache[i] = NULL;
24741 +static int __init au_cache_init(void)
24743 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24744 + if (au_cache[AuCache_DINFO])
24745 + /* SLAB_DESTROY_BY_RCU */
24746 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24747 + au_icntnr_init_once);
24748 + if (au_cache[AuCache_ICNTNR])
24749 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24750 + au_fi_init_once);
24751 + if (au_cache[AuCache_FINFO])
24752 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24753 + if (au_cache[AuCache_VDIR])
24754 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24755 + if (au_cache[AuCache_DEHSTR])
24762 +/* ---------------------------------------------------------------------- */
24764 +int au_dir_roflags;
24766 +#ifdef CONFIG_AUFS_SBILIST
24768 + * iterate_supers_type() doesn't protect us from
24769 + * remounting (branch management)
24771 +struct hlist_bl_head au_sbilist;
24775 + * functions for module interface.
24777 +MODULE_LICENSE("GPL");
24778 +/* MODULE_LICENSE("GPL v2"); */
24779 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24780 +MODULE_DESCRIPTION(AUFS_NAME
24781 + " -- Advanced multi layered unification filesystem");
24782 +MODULE_VERSION(AUFS_VERSION);
24783 +MODULE_ALIAS_FS(AUFS_NAME);
24785 +/* this module parameter has no meaning when SYSFS is disabled */
24786 +int sysaufs_brs = 1;
24787 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24788 +module_param_named(brs, sysaufs_brs, int, 0444);
24790 +/* this module parameter has no meaning when USER_NS is disabled */
24792 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24793 +module_param_named(allow_userns, au_userns, bool, 0444);
24795 +/* ---------------------------------------------------------------------- */
24797 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24799 +int au_seq_path(struct seq_file *seq, struct path *path)
24803 + err = seq_path(seq, path, au_esc_chars);
24812 +/* ---------------------------------------------------------------------- */
24814 +static int __init aufs_init(void)
24819 + p = au_esc_chars;
24820 + for (i = 1; i <= ' '; i++)
24826 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24828 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24829 + for (i = 0; i < AuIop_Last; i++)
24830 + aufs_iop_nogetattr[i].getattr = NULL;
24832 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24834 + au_sbilist_init();
24835 + sysaufs_brs_init();
24838 + err = sysaufs_init();
24839 + if (unlikely(err))
24841 + err = dbgaufs_init();
24842 + if (unlikely(err))
24843 + goto out_sysaufs;
24844 + err = au_procfs_init();
24845 + if (unlikely(err))
24846 + goto out_dbgaufs;
24847 + err = au_wkq_init();
24848 + if (unlikely(err))
24850 + err = au_loopback_init();
24851 + if (unlikely(err))
24853 + err = au_hnotify_init();
24854 + if (unlikely(err))
24855 + goto out_loopback;
24856 + err = au_sysrq_init();
24857 + if (unlikely(err))
24859 + err = au_cache_init();
24860 + if (unlikely(err))
24863 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24864 + err = register_filesystem(&aufs_fs_type);
24865 + if (unlikely(err))
24868 + /* since we define pr_fmt, call printk directly */
24869 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24870 + goto out; /* success */
24877 + au_hnotify_fin();
24879 + au_loopback_fin();
24893 +static void __exit aufs_exit(void)
24895 + unregister_filesystem(&aufs_fs_type);
24898 + au_hnotify_fin();
24899 + au_loopback_fin();
24907 +module_init(aufs_init);
24908 +module_exit(aufs_exit);
24909 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24910 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24911 +++ linux/fs/aufs/module.h 2019-03-05 12:13:00.142557771 +0100
24913 +/* SPDX-License-Identifier: GPL-2.0 */
24915 + * Copyright (C) 2005-2019 Junjiro R. Okajima
24917 + * This program, aufs is free software; you can redistribute it and/or modify
24918 + * it under the terms of the GNU General Public License as published by
24919 + * the Free Software Foundation; either version 2 of the License, or
24920 + * (at your option) any later version.
24922 + * This program is distributed in the hope that it will be useful,
24923 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24924 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24925 + * GNU General Public License for more details.
24927 + * You should have received a copy of the GNU General Public License
24928 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24932 + * module initialization and module-global
24935 +#ifndef __AUFS_MODULE_H__
24936 +#define __AUFS_MODULE_H__
24940 +#include <linux/slab.h>
24941 +#include "debug.h"
24942 +#include "dentry.h"
24945 +#include "inode.h"
24950 +/* module parameters */
24951 +extern int sysaufs_brs;
24952 +extern bool au_userns;
24954 +/* ---------------------------------------------------------------------- */
24956 +extern int au_dir_roflags;
24958 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24959 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24963 + * Comparing the size of the object with sizeof(struct rcu_head)
24964 + * case 1: object is always larger
24965 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24966 + * case 2: object is always smaller
24967 + * --> au_kfree_small()
24968 + * case 3: object can be any size
24969 + * --> au_kfree_try_rcu()
24972 +static inline void au_kfree_do_rcu(const void *p)
24975 + struct rcu_head rcu;
24976 + } *a = (void *)p;
24978 + kfree_rcu(a, rcu);
24981 +#define au_kfree_rcu(_p) do { \
24982 + typeof(_p) p = (_p); \
24983 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24985 + au_kfree_do_rcu(p); \
24988 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
24989 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
24991 +static inline void au_kfree_try_rcu(const void *p)
24995 + if (au_kfree_sz_test(p))
24996 + au_kfree_do_rcu(p);
25001 +static inline void au_kfree_small(const void *p)
25005 + AuDebugOn(au_kfree_sz_test(p));
25009 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
25011 +#ifndef CONFIG_SLOB
25012 + return kmalloc_index(sz) - kmalloc_index(new_sz);
25014 + return -1; /* SLOB is untested */
25018 +int au_seq_path(struct seq_file *seq, struct path *path);
25020 +#ifdef CONFIG_PROC_FS
25022 +int __init au_procfs_init(void);
25023 +void au_procfs_fin(void);
25025 +AuStubInt0(au_procfs_init, void);
25026 +AuStubVoid(au_procfs_fin, void);
25029 +/* ---------------------------------------------------------------------- */
25038 + AuCache_HNOTIFY, /* must be last */
25042 +extern struct kmem_cache *au_cache[AuCache_Last];
25044 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
25045 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
25046 +#define AuCacheCtor(type, ctor) \
25047 + kmem_cache_create(#type, sizeof(struct type), \
25048 + __alignof__(struct type), AuCacheFlags, ctor)
25050 +#define AuCacheFuncs(name, index) \
25051 + static inline struct au_##name *au_cache_alloc_##name(void) \
25052 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
25053 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
25054 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
25056 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
25057 + { void *p = rcu; \
25058 + p -= offsetof(struct au_##name, rcu); \
25059 + kmem_cache_free(au_cache[AuCache_##index], p); } \
25060 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
25061 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
25062 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
25064 + static inline void au_cache_free_##name(struct au_##name *p) \
25065 + { /* au_cache_free_##name##_norcu(p); */ \
25066 + au_cache_free_##name##_rcu(p); }
25068 +AuCacheFuncs(dinfo, DINFO);
25069 +AuCacheFuncs(icntnr, ICNTNR);
25070 +AuCacheFuncs(finfo, FINFO);
25071 +AuCacheFuncs(vdir, VDIR);
25072 +AuCacheFuncs(vdir_dehstr, DEHSTR);
25073 +#ifdef CONFIG_AUFS_HNOTIFY
25074 +AuCacheFuncs(hnotify, HNOTIFY);
25077 +#endif /* __KERNEL__ */
25078 +#endif /* __AUFS_MODULE_H__ */
25079 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
25080 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
25081 +++ linux/fs/aufs/mvdown.c 2019-03-05 12:13:00.142557771 +0100
25083 +// SPDX-License-Identifier: GPL-2.0
25085 + * Copyright (C) 2011-2019 Junjiro R. Okajima
25087 + * This program, aufs is free software; you can redistribute it and/or modify
25088 + * it under the terms of the GNU General Public License as published by
25089 + * the Free Software Foundation; either version 2 of the License, or
25090 + * (at your option) any later version.
25092 + * This program is distributed in the hope that it will be useful,
25093 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25094 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25095 + * GNU General Public License for more details.
25097 + * You should have received a copy of the GNU General Public License
25098 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25102 + * move-down, opposite of copy-up
25107 +struct au_mvd_args {
25109 + struct super_block *h_sb;
25110 + struct dentry *h_parent;
25111 + struct au_hinode *hdir;
25112 + struct inode *h_dir, *h_inode;
25113 + struct au_pin pin;
25114 + } info[AUFS_MVDOWN_NARRAY];
25116 + struct aufs_mvdown mvdown;
25117 + struct dentry *dentry, *parent;
25118 + struct inode *inode, *dir;
25119 + struct super_block *sb;
25120 + aufs_bindex_t bopq, bwh, bfound;
25121 + unsigned char rename_lock;
25124 +#define mvd_errno mvdown.au_errno
25125 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
25126 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
25127 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
25128 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
25130 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
25131 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
25132 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
25133 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
25134 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
25135 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
25137 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
25138 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
25139 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
25140 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
25141 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
25142 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
25144 +#define AU_MVD_PR(flag, ...) do { \
25146 + pr_err(__VA_ARGS__); \
25149 +static int find_lower_writable(struct au_mvd_args *a)
25151 + struct super_block *sb;
25152 + aufs_bindex_t bindex, bbot;
25153 + struct au_branch *br;
25156 + bindex = a->mvd_bsrc;
25157 + bbot = au_sbbot(sb);
25158 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
25159 + for (bindex++; bindex <= bbot; bindex++) {
25160 + br = au_sbr(sb, bindex);
25161 + if (au_br_fhsm(br->br_perm)
25162 + && !sb_rdonly(au_br_sb(br)))
25165 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
25166 + for (bindex++; bindex <= bbot; bindex++) {
25167 + br = au_sbr(sb, bindex);
25168 + if (!au_br_rdonly(br))
25172 + for (bindex++; bindex <= bbot; bindex++) {
25173 + br = au_sbr(sb, bindex);
25174 + if (!sb_rdonly(au_br_sb(br))) {
25175 + if (au_br_rdonly(br))
25177 + |= AUFS_MVDOWN_ROLOWER_R;
25185 +/* make the parent dir on bdst */
25186 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
25191 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
25192 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
25193 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
25194 + a->mvd_h_dst_parent = NULL;
25195 + if (au_dbbot(a->parent) >= a->mvd_bdst)
25196 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25197 + if (!a->mvd_h_dst_parent) {
25198 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
25199 + if (unlikely(err)) {
25200 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
25203 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25211 +/* lock them all */
25212 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
25215 + struct dentry *h_trap;
25217 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
25218 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
25219 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
25220 + au_opt_udba(a->sb),
25221 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25223 + if (unlikely(err)) {
25224 + AU_MVD_PR(dmsg, "pin_dst failed\n");
25228 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
25229 + a->rename_lock = 0;
25230 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25231 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
25232 + au_opt_udba(a->sb),
25233 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25234 + err = au_do_pin(&a->mvd_pin_src);
25236 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25237 + if (unlikely(err)) {
25238 + AU_MVD_PR(dmsg, "pin_src failed\n");
25241 + goto out; /* success */
25244 + a->rename_lock = 1;
25245 + au_pin_hdir_unlock(&a->mvd_pin_dst);
25246 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25247 + au_opt_udba(a->sb),
25248 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25250 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25251 + if (unlikely(err)) {
25252 + AU_MVD_PR(dmsg, "pin_src failed\n");
25253 + au_pin_hdir_lock(&a->mvd_pin_dst);
25256 + au_pin_hdir_unlock(&a->mvd_pin_src);
25257 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25258 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25260 + err = (h_trap != a->mvd_h_src_parent);
25262 + err = (h_trap != a->mvd_h_dst_parent);
25264 + BUG_ON(err); /* it should never happen */
25265 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25268 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25269 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25270 + au_pin_hdir_lock(&a->mvd_pin_src);
25271 + au_unpin(&a->mvd_pin_src);
25272 + au_pin_hdir_lock(&a->mvd_pin_dst);
25275 + goto out; /* success */
25278 + au_unpin(&a->mvd_pin_dst);
25284 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25286 + if (!a->rename_lock)
25287 + au_unpin(&a->mvd_pin_src);
25289 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25290 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25291 + au_pin_hdir_lock(&a->mvd_pin_src);
25292 + au_unpin(&a->mvd_pin_src);
25293 + au_pin_hdir_lock(&a->mvd_pin_dst);
25295 + au_unpin(&a->mvd_pin_dst);
25298 +/* copy-down the file */
25299 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25302 + struct au_cp_generic cpg = {
25303 + .dentry = a->dentry,
25304 + .bdst = a->mvd_bdst,
25305 + .bsrc = a->mvd_bsrc,
25307 + .pin = &a->mvd_pin_dst,
25308 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25311 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25312 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25313 + au_fset_cpup(cpg.flags, OVERWRITE);
25314 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25315 + au_fset_cpup(cpg.flags, RWDST);
25316 + err = au_sio_cpdown_simple(&cpg);
25317 + if (unlikely(err))
25318 + AU_MVD_PR(dmsg, "cpdown failed\n");
25325 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25328 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25331 + struct path h_path;
25332 + struct au_branch *br;
25333 + struct inode *delegated;
25335 + br = au_sbr(a->sb, a->mvd_bdst);
25336 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25337 + err = PTR_ERR(h_path.dentry);
25338 + if (IS_ERR(h_path.dentry)) {
25339 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25344 + if (d_is_positive(h_path.dentry)) {
25345 + h_path.mnt = au_br_mnt(br);
25346 + delegated = NULL;
25347 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25348 + &delegated, /*force*/0);
25349 + if (unlikely(err == -EWOULDBLOCK)) {
25350 + pr_warn("cannot retry for NFSv4 delegation"
25351 + " for an internal unlink\n");
25354 + if (unlikely(err))
25355 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25357 + dput(h_path.dentry);
25365 + * unlink the topmost h_dentry
25367 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25370 + struct path h_path;
25371 + struct inode *delegated;
25373 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25374 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25375 + delegated = NULL;
25376 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25377 + if (unlikely(err == -EWOULDBLOCK)) {
25378 + pr_warn("cannot retry for NFSv4 delegation"
25379 + " for an internal unlink\n");
25382 + if (unlikely(err))
25383 + AU_MVD_PR(dmsg, "unlink failed\n");
25389 +/* Since mvdown succeeded, we ignore an error of this function */
25390 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25393 + struct au_branch *br;
25395 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25396 + br = au_sbr(a->sb, a->mvd_bsrc);
25397 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25399 + br = au_sbr(a->sb, a->mvd_bdst);
25400 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25401 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25404 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25406 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25410 + * copy-down the file and unlink the bsrc file.
25411 + * - unlink the bdst whout if exist
25412 + * - copy-down the file (with whtmp name and rename)
25413 + * - unlink the bsrc file
25415 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25419 + err = au_do_mkdir(dmsg, a);
25421 + err = au_do_lock(dmsg, a);
25422 + if (unlikely(err))
25426 + * do not revert the activities we made on bdst since they should be
25427 + * harmless in aufs.
25430 + err = au_do_cpdown(dmsg, a);
25432 + err = au_do_unlink_wh(dmsg, a);
25433 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25434 + err = au_do_unlink(dmsg, a);
25435 + if (unlikely(err))
25438 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25439 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25440 + if (find_lower_writable(a) < 0)
25441 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25443 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25444 + au_do_stfs(dmsg, a);
25446 + /* maintain internal array */
25447 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25448 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25449 + au_set_dbtop(a->dentry, a->mvd_bdst);
25450 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25451 + au_set_ibtop(a->inode, a->mvd_bdst);
25453 + /* hide the lower */
25454 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25455 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25456 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25457 + au_set_ibbot(a->inode, a->mvd_bsrc);
25459 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25460 + au_set_dbbot(a->dentry, a->mvd_bdst);
25461 + if (au_ibbot(a->inode) < a->mvd_bdst)
25462 + au_set_ibbot(a->inode, a->mvd_bdst);
25465 + au_do_unlock(dmsg, a);
25471 +/* ---------------------------------------------------------------------- */
25473 +/* make sure the file is idle */
25474 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25476 + int err, plinked;
25479 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25480 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25481 + && au_dcount(a->dentry) == 1
25482 + && atomic_read(&a->inode->i_count) == 1
25483 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25484 + && (!plinked || !au_plink_test(a->inode))
25485 + && a->inode->i_nlink == 1)
25490 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25491 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25492 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25493 + a->mvd_h_src_inode->i_nlink,
25494 + plinked, plinked ? au_plink_test(a->inode) : 0);
25501 +/* make sure the parent dir is fine */
25502 +static int au_mvd_args_parent(const unsigned char dmsg,
25503 + struct au_mvd_args *a)
25506 + aufs_bindex_t bindex;
25509 + if (unlikely(au_alive_dir(a->parent))) {
25511 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25515 + a->bopq = au_dbdiropq(a->parent);
25516 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25517 + AuDbg("b%d\n", bindex);
25518 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25519 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25521 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25522 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25523 + a->bopq, a->mvd_bdst);
25531 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25532 + struct au_mvd_args *a)
25535 + struct au_dinfo *dinfo, *tmp;
25537 + /* lookup the next lower positive entry */
25539 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25540 + if (unlikely(!tmp))
25545 + dinfo = au_di(a->dentry);
25546 + au_di_cp(tmp, dinfo);
25547 + au_di_swap(tmp, dinfo);
25549 + /* returns the number of positive dentries */
25550 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25551 + /* AuLkup_IGNORE_PERM */ 0);
25553 + a->bwh = au_dbwh(a->dentry);
25554 + else if (err > 0)
25555 + a->bfound = au_dbtop(a->dentry);
25557 + au_di_swap(tmp, dinfo);
25558 + au_rw_write_unlock(&tmp->di_rwsem);
25560 + if (unlikely(err < 0))
25561 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25564 + * here, we have these cases.
25566 + * no positive dentry under bsrc. there are more sub-cases.
25568 + * there no whiteout, we can safely move-down.
25571 + * bsrc < bwh && bwh < bdst
25572 + * there is a whiteout on RO branch. cannot proceed.
25574 + * there is a whiteout on the RW target branch. it should
25577 + * there is a whiteout somewhere unrelated branch.
25578 + * -1 < bfound && bfound <= bsrc
25581 + * found, but it is on RO branch between bsrc and bdst. cannot
25584 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25587 + * found, after we create the file on bdst, it will be hidden.
25590 + AuDebugOn(a->bfound == -1
25592 + && a->bwh <= a->mvd_bsrc);
25593 + AuDebugOn(-1 < a->bfound
25594 + && a->bfound <= a->mvd_bsrc);
25597 + if (a->bfound == -1
25598 + && a->mvd_bsrc < a->bwh
25600 + && a->bwh < a->mvd_bdst) {
25601 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25602 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25603 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25605 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25606 + a->mvd_errno = EAU_MVDOWN_UPPER;
25607 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25608 + a->mvd_bdst, a->bfound);
25612 + err = 0; /* success */
25619 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25624 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25625 + && a->bfound == a->mvd_bdst)
25631 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25634 + struct au_branch *br;
25637 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25641 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25642 + a->mvd_bsrc = au_ibtop(a->inode);
25644 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25645 + if (unlikely(a->mvd_bsrc < 0
25646 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25647 + || au_dbbot(a->dentry) < a->mvd_bsrc
25648 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25649 + || (a->mvd_bsrc < au_ibtop(a->inode)
25650 + || au_ibbot(a->inode) < a->mvd_bsrc
25651 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25652 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25653 + AU_MVD_PR(dmsg, "no upper\n");
25657 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25658 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25659 + AU_MVD_PR(dmsg, "on the bottom\n");
25662 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25663 + br = au_sbr(a->sb, a->mvd_bsrc);
25664 + err = au_br_rdonly(br);
25665 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25666 + if (unlikely(err))
25668 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25669 + || IS_APPEND(a->mvd_h_src_inode))) {
25671 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25677 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25678 + a->mvd_bdst = find_lower_writable(a);
25679 + if (unlikely(a->mvd_bdst < 0)) {
25680 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25681 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25685 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25686 + if (unlikely(a->mvd_bdst < 0
25687 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25688 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25689 + AU_MVD_PR(dmsg, "no lower brid\n");
25694 + err = au_mvd_args_busy(dmsg, a);
25696 + err = au_mvd_args_parent(dmsg, a);
25698 + err = au_mvd_args_intermediate(dmsg, a);
25700 + err = au_mvd_args_exist(dmsg, a);
25702 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25709 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25712 + unsigned char dmsg;
25713 + struct au_mvd_args *args;
25714 + struct inode *inode;
25716 + inode = d_inode(dentry);
25718 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25722 + args = kmalloc(sizeof(*args), GFP_NOFS);
25723 + if (unlikely(!args))
25726 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25728 + /* VERIFY_WRITE */
25729 + err = !access_ok(uarg, sizeof(*uarg));
25730 + if (unlikely(err)) {
25735 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25736 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25737 + args->mvdown.au_errno = 0;
25738 + args->dentry = dentry;
25739 + args->inode = inode;
25740 + args->sb = dentry->d_sb;
25743 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25744 + args->parent = dget_parent(dentry);
25745 + args->dir = d_inode(args->parent);
25746 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25747 + dput(args->parent);
25748 + if (unlikely(args->parent != dentry->d_parent)) {
25749 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25753 + inode_lock_nested(inode, I_MUTEX_CHILD);
25754 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25755 + if (unlikely(err))
25758 + di_write_lock_parent(args->parent);
25759 + err = au_mvd_args(dmsg, args);
25760 + if (unlikely(err))
25763 + err = au_do_mvdown(dmsg, args);
25764 + if (unlikely(err))
25767 + au_cpup_attr_timesizes(args->dir);
25768 + au_cpup_attr_timesizes(inode);
25769 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25770 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25771 + /* au_digen_dec(dentry); */
25774 + di_write_unlock(args->parent);
25775 + aufs_read_unlock(dentry, AuLock_DW);
25777 + inode_unlock(inode);
25779 + inode_unlock(args->dir);
25781 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25784 + au_kfree_rcu(args);
25789 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25790 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25791 +++ linux/fs/aufs/opts.c 2019-03-05 12:13:00.142557771 +0100
25793 +// SPDX-License-Identifier: GPL-2.0
25795 + * Copyright (C) 2005-2019 Junjiro R. Okajima
25797 + * This program, aufs is free software; you can redistribute it and/or modify
25798 + * it under the terms of the GNU General Public License as published by
25799 + * the Free Software Foundation; either version 2 of the License, or
25800 + * (at your option) any later version.
25802 + * This program is distributed in the hope that it will be useful,
25803 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25804 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25805 + * GNU General Public License for more details.
25807 + * You should have received a copy of the GNU General Public License
25808 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25812 + * mount options/flags
25815 +#include <linux/namei.h>
25816 +#include <linux/types.h> /* a distribution requires */
25817 +#include <linux/parser.h>
25820 +/* ---------------------------------------------------------------------- */
25824 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25825 + Opt_idel, Opt_imod,
25826 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25827 + Opt_rdblk_def, Opt_rdhash_def,
25828 + Opt_xino, Opt_noxino,
25829 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25830 + Opt_trunc_xino_path, Opt_itrunc_xino,
25831 + Opt_trunc_xib, Opt_notrunc_xib,
25832 + Opt_shwh, Opt_noshwh,
25833 + Opt_plink, Opt_noplink, Opt_list_plink,
25835 + Opt_dio, Opt_nodio,
25836 + Opt_diropq_a, Opt_diropq_w,
25837 + Opt_warn_perm, Opt_nowarn_perm,
25838 + Opt_wbr_copyup, Opt_wbr_create,
25840 + Opt_verbose, Opt_noverbose,
25841 + Opt_sum, Opt_nosum, Opt_wsum,
25842 + Opt_dirperm1, Opt_nodirperm1,
25843 + Opt_dirren, Opt_nodirren,
25844 + Opt_acl, Opt_noacl,
25845 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25848 +static match_table_t options = {
25849 + {Opt_br, "br=%s"},
25850 + {Opt_br, "br:%s"},
25852 + {Opt_add, "add=%d:%s"},
25853 + {Opt_add, "add:%d:%s"},
25854 + {Opt_add, "ins=%d:%s"},
25855 + {Opt_add, "ins:%d:%s"},
25856 + {Opt_append, "append=%s"},
25857 + {Opt_append, "append:%s"},
25858 + {Opt_prepend, "prepend=%s"},
25859 + {Opt_prepend, "prepend:%s"},
25861 + {Opt_del, "del=%s"},
25862 + {Opt_del, "del:%s"},
25863 + /* {Opt_idel, "idel:%d"}, */
25864 + {Opt_mod, "mod=%s"},
25865 + {Opt_mod, "mod:%s"},
25866 + /* {Opt_imod, "imod:%d:%s"}, */
25868 + {Opt_dirwh, "dirwh=%d"},
25870 + {Opt_xino, "xino=%s"},
25871 + {Opt_noxino, "noxino"},
25872 + {Opt_trunc_xino, "trunc_xino"},
25873 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25874 + {Opt_notrunc_xino, "notrunc_xino"},
25875 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25876 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25877 + /* {Opt_zxino, "zxino=%s"}, */
25878 + {Opt_trunc_xib, "trunc_xib"},
25879 + {Opt_notrunc_xib, "notrunc_xib"},
25881 +#ifdef CONFIG_PROC_FS
25882 + {Opt_plink, "plink"},
25884 + {Opt_ignore_silent, "plink"},
25887 + {Opt_noplink, "noplink"},
25889 +#ifdef CONFIG_AUFS_DEBUG
25890 + {Opt_list_plink, "list_plink"},
25893 + {Opt_udba, "udba=%s"},
25895 + {Opt_dio, "dio"},
25896 + {Opt_nodio, "nodio"},
25898 +#ifdef CONFIG_AUFS_DIRREN
25899 + {Opt_dirren, "dirren"},
25900 + {Opt_nodirren, "nodirren"},
25902 + {Opt_ignore, "dirren"},
25903 + {Opt_ignore_silent, "nodirren"},
25906 +#ifdef CONFIG_AUFS_FHSM
25907 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25909 + {Opt_ignore, "fhsm_sec=%d"},
25912 + {Opt_diropq_a, "diropq=always"},
25913 + {Opt_diropq_a, "diropq=a"},
25914 + {Opt_diropq_w, "diropq=whiteouted"},
25915 + {Opt_diropq_w, "diropq=w"},
25917 + {Opt_warn_perm, "warn_perm"},
25918 + {Opt_nowarn_perm, "nowarn_perm"},
25920 + /* keep them temporary */
25921 + {Opt_ignore_silent, "nodlgt"},
25922 + {Opt_ignore, "clean_plink"},
25924 +#ifdef CONFIG_AUFS_SHWH
25925 + {Opt_shwh, "shwh"},
25927 + {Opt_noshwh, "noshwh"},
25929 + {Opt_dirperm1, "dirperm1"},
25930 + {Opt_nodirperm1, "nodirperm1"},
25932 + {Opt_verbose, "verbose"},
25933 + {Opt_verbose, "v"},
25934 + {Opt_noverbose, "noverbose"},
25935 + {Opt_noverbose, "quiet"},
25936 + {Opt_noverbose, "q"},
25937 + {Opt_noverbose, "silent"},
25939 + {Opt_sum, "sum"},
25940 + {Opt_nosum, "nosum"},
25941 + {Opt_wsum, "wsum"},
25943 + {Opt_rdcache, "rdcache=%d"},
25944 + {Opt_rdblk, "rdblk=%d"},
25945 + {Opt_rdblk_def, "rdblk=def"},
25946 + {Opt_rdhash, "rdhash=%d"},
25947 + {Opt_rdhash_def, "rdhash=def"},
25949 + {Opt_wbr_create, "create=%s"},
25950 + {Opt_wbr_create, "create_policy=%s"},
25951 + {Opt_wbr_copyup, "cpup=%s"},
25952 + {Opt_wbr_copyup, "copyup=%s"},
25953 + {Opt_wbr_copyup, "copyup_policy=%s"},
25955 + /* generic VFS flag */
25956 +#ifdef CONFIG_FS_POSIX_ACL
25957 + {Opt_acl, "acl"},
25958 + {Opt_noacl, "noacl"},
25960 + {Opt_ignore, "acl"},
25961 + {Opt_ignore_silent, "noacl"},
25964 + /* internal use for the scripts */
25965 + {Opt_ignore_silent, "si=%s"},
25967 + {Opt_br, "dirs=%s"},
25968 + {Opt_ignore, "debug=%d"},
25969 + {Opt_ignore, "delete=whiteout"},
25970 + {Opt_ignore, "delete=all"},
25971 + {Opt_ignore, "imap=%s"},
25973 + /* temporary workaround, due to old mount(8)? */
25974 + {Opt_ignore_silent, "relatime"},
25979 +/* ---------------------------------------------------------------------- */
25981 +static const char *au_parser_pattern(int val, match_table_t tbl)
25983 + struct match_token *p;
25986 + while (p->pattern) {
25987 + if (p->token == val)
25988 + return p->pattern;
25995 +static const char *au_optstr(int *val, match_table_t tbl)
25997 + struct match_token *p;
26004 + while (p->pattern) {
26006 + && (v & p->token) == p->token) {
26007 + *val &= ~p->token;
26008 + return p->pattern;
26017 +/* ---------------------------------------------------------------------- */
26019 +static match_table_t brperm = {
26020 + {AuBrPerm_RO, AUFS_BRPERM_RO},
26021 + {AuBrPerm_RR, AUFS_BRPERM_RR},
26022 + {AuBrPerm_RW, AUFS_BRPERM_RW},
26026 +static match_table_t brattr = {
26028 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
26029 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
26030 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
26031 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
26032 +#ifdef CONFIG_AUFS_FHSM
26033 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
26035 +#ifdef CONFIG_AUFS_XATTR
26036 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
26037 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
26038 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
26039 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
26040 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
26041 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
26044 + /* ro/rr branch */
26045 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
26048 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
26049 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
26054 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
26061 + p = strchr(str, '+');
26064 + v = match_token(str, table, args);
26066 + if (v & AuBrAttr_CMOO_Mask)
26067 + attr &= ~AuBrAttr_CMOO_Mask;
26072 + pr_warn("ignored branch attribute %s\n", str);
26082 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
26090 + p = au_optstr(&perm, brattr);
26093 + memcpy(q, p, sz + 1);
26099 + p = au_optstr(&perm, brattr);
26103 + memcpy(q, p, sz + 1);
26109 + return q - str->a;
26112 +static int noinline_for_stack br_perm_val(char *perm)
26114 + int val, bad, sz;
26116 + substring_t args[MAX_OPT_ARGS];
26117 + au_br_perm_str_t attr;
26119 + p = strchr(perm, '+');
26122 + val = match_token(perm, brperm, args);
26126 + pr_warn("ignored branch permission %s\n", perm);
26127 + val = AuBrPerm_RO;
26133 + val |= br_attr_val(p + 1, brattr, args);
26136 + switch (val & AuBrPerm_Mask) {
26137 + case AuBrPerm_RO:
26138 + case AuBrPerm_RR:
26139 + bad = val & AuBrWAttr_Mask;
26140 + val &= ~AuBrWAttr_Mask;
26142 + case AuBrPerm_RW:
26143 + bad = val & AuBrRAttr_Mask;
26144 + val &= ~AuBrRAttr_Mask;
26149 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
26150 + * does not treat it as an error, just warning.
26151 + * this is a tiny guard for the user operation.
26153 + if (val & AuBrAttr_UNPIN) {
26154 + bad |= AuBrAttr_UNPIN;
26155 + val &= ~AuBrAttr_UNPIN;
26158 + if (unlikely(bad)) {
26159 + sz = au_do_optstr_br_attr(&attr, bad);
26161 + pr_warn("ignored branch attribute %s\n", attr.a);
26168 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
26170 + au_br_perm_str_t attr;
26176 + p = au_optstr(&perm, brperm);
26177 + AuDebugOn(!p || !*p);
26179 + memcpy(q, p, sz + 1);
26182 + sz = au_do_optstr_br_attr(&attr, perm);
26185 + memcpy(q, attr.a, sz + 1);
26188 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
26191 +/* ---------------------------------------------------------------------- */
26193 +static match_table_t udbalevel = {
26194 + {AuOpt_UDBA_REVAL, "reval"},
26195 + {AuOpt_UDBA_NONE, "none"},
26196 +#ifdef CONFIG_AUFS_HNOTIFY
26197 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
26198 +#ifdef CONFIG_AUFS_HFSNOTIFY
26199 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
26205 +static int noinline_for_stack udba_val(char *str)
26207 + substring_t args[MAX_OPT_ARGS];
26209 + return match_token(str, udbalevel, args);
26212 +const char *au_optstr_udba(int udba)
26214 + return au_parser_pattern(udba, udbalevel);
26217 +/* ---------------------------------------------------------------------- */
26219 +static match_table_t au_wbr_create_policy = {
26220 + {AuWbrCreate_TDP, "tdp"},
26221 + {AuWbrCreate_TDP, "top-down-parent"},
26222 + {AuWbrCreate_RR, "rr"},
26223 + {AuWbrCreate_RR, "round-robin"},
26224 + {AuWbrCreate_MFS, "mfs"},
26225 + {AuWbrCreate_MFS, "most-free-space"},
26226 + {AuWbrCreate_MFSV, "mfs:%d"},
26227 + {AuWbrCreate_MFSV, "most-free-space:%d"},
26229 + /* top-down regardless the parent, and then mfs */
26230 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
26231 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
26233 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
26234 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
26235 + {AuWbrCreate_PMFS, "pmfs"},
26236 + {AuWbrCreate_PMFSV, "pmfs:%d"},
26237 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
26238 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26243 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26244 + struct au_opt_wbr_create *create)
26247 + unsigned long long ull;
26250 + if (!match_u64(arg, &ull))
26251 + create->mfsrr_watermark = ull;
26253 + pr_err("bad integer in %s\n", str);
26260 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26261 + struct au_opt_wbr_create *create)
26266 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26267 + create->mfs_second = n;
26269 + pr_err("bad integer in %s\n", str);
26276 +static int noinline_for_stack
26277 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26280 + substring_t args[MAX_OPT_ARGS];
26282 + err = match_token(str, au_wbr_create_policy, args);
26283 + create->wbr_create = err;
26285 + case AuWbrCreate_MFSRRV:
26286 + case AuWbrCreate_TDMFSV:
26287 + case AuWbrCreate_PMFSRRV:
26288 + e = au_wbr_mfs_wmark(&args[0], str, create);
26290 + e = au_wbr_mfs_sec(&args[1], str, create);
26294 + case AuWbrCreate_MFSRR:
26295 + case AuWbrCreate_TDMFS:
26296 + case AuWbrCreate_PMFSRR:
26297 + e = au_wbr_mfs_wmark(&args[0], str, create);
26298 + if (unlikely(e)) {
26303 + case AuWbrCreate_MFS:
26304 + case AuWbrCreate_PMFS:
26305 + create->mfs_second = AUFS_MFS_DEF_SEC;
26307 + case AuWbrCreate_MFSV:
26308 + case AuWbrCreate_PMFSV:
26309 + e = au_wbr_mfs_sec(&args[0], str, create);
26318 +const char *au_optstr_wbr_create(int wbr_create)
26320 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26323 +static match_table_t au_wbr_copyup_policy = {
26324 + {AuWbrCopyup_TDP, "tdp"},
26325 + {AuWbrCopyup_TDP, "top-down-parent"},
26326 + {AuWbrCopyup_BUP, "bup"},
26327 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26328 + {AuWbrCopyup_BU, "bu"},
26329 + {AuWbrCopyup_BU, "bottom-up"},
26333 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26335 + substring_t args[MAX_OPT_ARGS];
26337 + return match_token(str, au_wbr_copyup_policy, args);
26340 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26342 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26345 +/* ---------------------------------------------------------------------- */
26347 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26349 +static void dump_opts(struct au_opts *opts)
26351 +#ifdef CONFIG_AUFS_DEBUG
26352 + /* reduce stack space */
26354 + struct au_opt_add *add;
26355 + struct au_opt_del *del;
26356 + struct au_opt_mod *mod;
26357 + struct au_opt_xino *xino;
26358 + struct au_opt_xino_itrunc *xino_itrunc;
26359 + struct au_opt_wbr_create *create;
26361 + struct au_opt *opt;
26364 + while (opt->type != Opt_tail) {
26365 + switch (opt->type) {
26367 + u.add = &opt->add;
26368 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26369 + u.add->bindex, u.add->pathname, u.add->perm,
26370 + u.add->path.dentry);
26374 + u.del = &opt->del;
26375 + AuDbg("del {%s, %p}\n",
26376 + u.del->pathname, u.del->h_path.dentry);
26380 + u.mod = &opt->mod;
26381 + AuDbg("mod {%s, 0x%x, %p}\n",
26382 + u.mod->path, u.mod->perm, u.mod->h_root);
26385 + u.add = &opt->add;
26386 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26387 + u.add->bindex, u.add->pathname, u.add->perm,
26388 + u.add->path.dentry);
26390 + case Opt_prepend:
26391 + u.add = &opt->add;
26392 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26393 + u.add->bindex, u.add->pathname, u.add->perm,
26394 + u.add->path.dentry);
26397 + AuDbg("dirwh %d\n", opt->dirwh);
26399 + case Opt_rdcache:
26400 + AuDbg("rdcache %d\n", opt->rdcache);
26403 + AuDbg("rdblk %u\n", opt->rdblk);
26405 + case Opt_rdblk_def:
26406 + AuDbg("rdblk_def\n");
26409 + AuDbg("rdhash %u\n", opt->rdhash);
26411 + case Opt_rdhash_def:
26412 + AuDbg("rdhash_def\n");
26415 + u.xino = &opt->xino;
26416 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26418 + case Opt_trunc_xino:
26419 + AuLabel(trunc_xino);
26421 + case Opt_notrunc_xino:
26422 + AuLabel(notrunc_xino);
26424 + case Opt_trunc_xino_path:
26425 + case Opt_itrunc_xino:
26426 + u.xino_itrunc = &opt->xino_itrunc;
26427 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26432 + case Opt_trunc_xib:
26433 + AuLabel(trunc_xib);
26435 + case Opt_notrunc_xib:
26436 + AuLabel(notrunc_xib);
26444 + case Opt_dirperm1:
26445 + AuLabel(dirperm1);
26447 + case Opt_nodirperm1:
26448 + AuLabel(nodirperm1);
26453 + case Opt_noplink:
26454 + AuLabel(noplink);
26456 + case Opt_list_plink:
26457 + AuLabel(list_plink);
26460 + AuDbg("udba %d, %s\n",
26461 + opt->udba, au_optstr_udba(opt->udba));
26469 + case Opt_diropq_a:
26470 + AuLabel(diropq_a);
26472 + case Opt_diropq_w:
26473 + AuLabel(diropq_w);
26475 + case Opt_warn_perm:
26476 + AuLabel(warn_perm);
26478 + case Opt_nowarn_perm:
26479 + AuLabel(nowarn_perm);
26481 + case Opt_verbose:
26482 + AuLabel(verbose);
26484 + case Opt_noverbose:
26485 + AuLabel(noverbose);
26496 + case Opt_wbr_create:
26497 + u.create = &opt->wbr_create;
26498 + AuDbg("create %d, %s\n", u.create->wbr_create,
26499 + au_optstr_wbr_create(u.create->wbr_create));
26500 + switch (u.create->wbr_create) {
26501 + case AuWbrCreate_MFSV:
26502 + case AuWbrCreate_PMFSV:
26503 + AuDbg("%d sec\n", u.create->mfs_second);
26505 + case AuWbrCreate_MFSRR:
26506 + case AuWbrCreate_TDMFS:
26507 + AuDbg("%llu watermark\n",
26508 + u.create->mfsrr_watermark);
26510 + case AuWbrCreate_MFSRRV:
26511 + case AuWbrCreate_TDMFSV:
26512 + case AuWbrCreate_PMFSRRV:
26513 + AuDbg("%llu watermark, %d sec\n",
26514 + u.create->mfsrr_watermark,
26515 + u.create->mfs_second);
26519 + case Opt_wbr_copyup:
26520 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26521 + au_optstr_wbr_copyup(opt->wbr_copyup));
26523 + case Opt_fhsm_sec:
26524 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26529 + case Opt_nodirren:
26530 + AuLabel(nodirren);
26546 +void au_opts_free(struct au_opts *opts)
26548 + struct au_opt *opt;
26551 + while (opt->type != Opt_tail) {
26552 + switch (opt->type) {
26555 + case Opt_prepend:
26556 + path_put(&opt->add.path);
26560 + path_put(&opt->del.h_path);
26564 + dput(opt->mod.h_root);
26567 + fput(opt->xino.file);
26574 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26575 + aufs_bindex_t bindex)
26578 + struct au_opt_add *add = &opt->add;
26581 + add->bindex = bindex;
26582 + add->perm = AuBrPerm_RO;
26583 + add->pathname = opt_str;
26584 + p = strchr(opt_str, '=');
26588 + add->perm = br_perm_val(p);
26591 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26594 + add->perm = AuBrPerm_RO;
26595 + if (au_test_fs_rr(add->path.dentry->d_sb))
26596 + add->perm = AuBrPerm_RR;
26597 + else if (!bindex && !(sb_flags & SB_RDONLY))
26598 + add->perm = AuBrPerm_RW;
26600 + opt->type = Opt_add;
26603 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26610 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26614 + del->pathname = args[0].from;
26615 + AuDbg("del path %s\n", del->pathname);
26617 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26618 + if (unlikely(err))
26619 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26624 +#if 0 /* reserved for future use */
26625 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26626 + struct au_opt_del *del, substring_t args[])
26629 + struct dentry *root;
26632 + root = sb->s_root;
26633 + aufs_read_lock(root, AuLock_FLUSH);
26634 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26635 + pr_err("out of bounds, %d\n", bindex);
26640 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26641 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26644 + aufs_read_unlock(root, !AuLock_IR);
26649 +static int noinline_for_stack
26650 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26653 + struct path path;
26657 + mod->path = args[0].from;
26658 + p = strchr(mod->path, '=');
26659 + if (unlikely(!p)) {
26660 + pr_err("no permission %s\n", args[0].from);
26665 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26666 + if (unlikely(err)) {
26667 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26671 + mod->perm = br_perm_val(p);
26672 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26673 + mod->h_root = dget(path.dentry);
26680 +#if 0 /* reserved for future use */
26681 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26682 + struct au_opt_mod *mod, substring_t args[])
26685 + struct dentry *root;
26688 + root = sb->s_root;
26689 + aufs_read_lock(root, AuLock_FLUSH);
26690 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26691 + pr_err("out of bounds, %d\n", bindex);
26696 + mod->perm = br_perm_val(args[1].from);
26697 + AuDbg("mod path %s, perm 0x%x, %s\n",
26698 + mod->path, mod->perm, args[1].from);
26699 + mod->h_root = dget(au_h_dptr(root, bindex));
26702 + aufs_read_unlock(root, !AuLock_IR);
26707 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26708 + substring_t args[])
26711 + struct file *file;
26713 + file = au_xino_create(sb, args[0].from, /*silent*/0);
26714 + err = PTR_ERR(file);
26715 + if (IS_ERR(file))
26719 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26721 + pr_err("%s must be outside\n", args[0].from);
26726 + xino->file = file;
26727 + xino->path = args[0].from;
26733 +static int noinline_for_stack
26734 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26735 + struct au_opt_xino_itrunc *xino_itrunc,
26736 + substring_t args[])
26739 + aufs_bindex_t bbot, bindex;
26740 + struct path path;
26741 + struct dentry *root;
26743 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26744 + if (unlikely(err)) {
26745 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26749 + xino_itrunc->bindex = -1;
26750 + root = sb->s_root;
26751 + aufs_read_lock(root, AuLock_FLUSH);
26752 + bbot = au_sbbot(sb);
26753 + for (bindex = 0; bindex <= bbot; bindex++) {
26754 + if (au_h_dptr(root, bindex) == path.dentry) {
26755 + xino_itrunc->bindex = bindex;
26759 + aufs_read_unlock(root, !AuLock_IR);
26762 + if (unlikely(xino_itrunc->bindex < 0)) {
26763 + pr_err("no such branch %s\n", args[0].from);
26771 +/* called without aufs lock */
26772 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26774 + int err, n, token;
26775 + aufs_bindex_t bindex;
26776 + unsigned char skipped;
26777 + struct dentry *root;
26778 + struct au_opt *opt, *opt_tail;
26780 + /* reduce the stack space */
26782 + struct au_opt_xino_itrunc *xino_itrunc;
26783 + struct au_opt_wbr_create *create;
26786 + substring_t args[MAX_OPT_ARGS];
26790 + a = kmalloc(sizeof(*a), GFP_NOFS);
26791 + if (unlikely(!a))
26794 + root = sb->s_root;
26798 + opt_tail = opt + opts->max_opt - 1;
26799 + opt->type = Opt_tail;
26800 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26803 + token = match_token(opt_str, options, a->args);
26807 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26809 + err = opt_add(opt, opt_str, opts->sb_flags,
26811 + if (unlikely(!err && ++opt > opt_tail)) {
26815 + opt->type = Opt_tail;
26820 + if (unlikely(match_int(&a->args[0], &n))) {
26821 + pr_err("bad integer in %s\n", opt_str);
26825 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26828 + opt->type = token;
26831 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26832 + /*dummy bindex*/1);
26834 + opt->type = token;
26836 + case Opt_prepend:
26837 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26840 + opt->type = token;
26843 + err = au_opts_parse_del(&opt->del, a->args);
26845 + opt->type = token;
26847 +#if 0 /* reserved for future use */
26849 + del->pathname = "(indexed)";
26850 + if (unlikely(match_int(&args[0], &n))) {
26851 + pr_err("bad integer in %s\n", opt_str);
26854 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26856 + opt->type = token;
26860 + err = au_opts_parse_mod(&opt->mod, a->args);
26862 + opt->type = token;
26864 +#ifdef IMOD /* reserved for future use */
26866 + u.mod->path = "(indexed)";
26867 + if (unlikely(match_int(&a->args[0], &n))) {
26868 + pr_err("bad integer in %s\n", opt_str);
26871 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26873 + opt->type = token;
26877 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26879 + opt->type = token;
26882 + case Opt_trunc_xino_path:
26883 + err = au_opts_parse_xino_itrunc_path
26884 + (sb, &opt->xino_itrunc, a->args);
26886 + opt->type = token;
26889 + case Opt_itrunc_xino:
26890 + u.xino_itrunc = &opt->xino_itrunc;
26891 + if (unlikely(match_int(&a->args[0], &n))) {
26892 + pr_err("bad integer in %s\n", opt_str);
26895 + u.xino_itrunc->bindex = n;
26896 + aufs_read_lock(root, AuLock_FLUSH);
26897 + if (n < 0 || au_sbbot(sb) < n) {
26898 + pr_err("out of bounds, %d\n", n);
26899 + aufs_read_unlock(root, !AuLock_IR);
26902 + aufs_read_unlock(root, !AuLock_IR);
26904 + opt->type = token;
26908 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26911 + opt->type = token;
26914 + case Opt_rdcache:
26915 + if (unlikely(match_int(&a->args[0], &n))) {
26916 + pr_err("bad integer in %s\n", opt_str);
26919 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26920 + pr_err("rdcache must be smaller than %d\n",
26921 + AUFS_RDCACHE_MAX);
26924 + opt->rdcache = n;
26926 + opt->type = token;
26929 + if (unlikely(match_int(&a->args[0], &n)
26931 + || n > KMALLOC_MAX_SIZE)) {
26932 + pr_err("bad integer in %s\n", opt_str);
26935 + if (unlikely(n && n < NAME_MAX)) {
26936 + pr_err("rdblk must be larger than %d\n",
26942 + opt->type = token;
26945 + if (unlikely(match_int(&a->args[0], &n)
26947 + || n * sizeof(struct hlist_head)
26948 + > KMALLOC_MAX_SIZE)) {
26949 + pr_err("bad integer in %s\n", opt_str);
26954 + opt->type = token;
26957 + case Opt_trunc_xino:
26958 + case Opt_notrunc_xino:
26960 + case Opt_trunc_xib:
26961 + case Opt_notrunc_xib:
26964 + case Opt_dirperm1:
26965 + case Opt_nodirperm1:
26967 + case Opt_noplink:
26968 + case Opt_list_plink:
26971 + case Opt_diropq_a:
26972 + case Opt_diropq_w:
26973 + case Opt_warn_perm:
26974 + case Opt_nowarn_perm:
26975 + case Opt_verbose:
26976 + case Opt_noverbose:
26980 + case Opt_rdblk_def:
26981 + case Opt_rdhash_def:
26983 + case Opt_nodirren:
26987 + opt->type = token;
26991 + opt->udba = udba_val(a->args[0].from);
26992 + if (opt->udba >= 0) {
26994 + opt->type = token;
26996 + pr_err("wrong value, %s\n", opt_str);
26999 + case Opt_wbr_create:
27000 + u.create = &opt->wbr_create;
27001 + u.create->wbr_create
27002 + = au_wbr_create_val(a->args[0].from, u.create);
27003 + if (u.create->wbr_create >= 0) {
27005 + opt->type = token;
27007 + pr_err("wrong value, %s\n", opt_str);
27009 + case Opt_wbr_copyup:
27010 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
27011 + if (opt->wbr_copyup >= 0) {
27013 + opt->type = token;
27015 + pr_err("wrong value, %s\n", opt_str);
27018 + case Opt_fhsm_sec:
27019 + if (unlikely(match_int(&a->args[0], &n)
27021 + pr_err("bad integer in %s\n", opt_str);
27024 + if (sysaufs_brs) {
27025 + opt->fhsm_second = n;
27026 + opt->type = token;
27028 + pr_warn("ignored %s\n", opt_str);
27033 + pr_warn("ignored %s\n", opt_str);
27035 + case Opt_ignore_silent:
27040 + pr_err("unknown option %s\n", opt_str);
27044 + if (!err && !skipped) {
27045 + if (unlikely(++opt > opt_tail)) {
27048 + opt->type = Opt_tail;
27051 + opt->type = Opt_tail;
27057 + if (unlikely(err))
27058 + au_opts_free(opts);
27064 +static int au_opt_wbr_create(struct super_block *sb,
27065 + struct au_opt_wbr_create *create)
27068 + struct au_sbinfo *sbinfo;
27070 + SiMustWriteLock(sb);
27072 + err = 1; /* handled */
27073 + sbinfo = au_sbi(sb);
27074 + if (sbinfo->si_wbr_create_ops->fin) {
27075 + err = sbinfo->si_wbr_create_ops->fin(sb);
27080 + sbinfo->si_wbr_create = create->wbr_create;
27081 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
27082 + switch (create->wbr_create) {
27083 + case AuWbrCreate_MFSRRV:
27084 + case AuWbrCreate_MFSRR:
27085 + case AuWbrCreate_TDMFS:
27086 + case AuWbrCreate_TDMFSV:
27087 + case AuWbrCreate_PMFSRR:
27088 + case AuWbrCreate_PMFSRRV:
27089 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
27091 + case AuWbrCreate_MFS:
27092 + case AuWbrCreate_MFSV:
27093 + case AuWbrCreate_PMFS:
27094 + case AuWbrCreate_PMFSV:
27095 + sbinfo->si_wbr_mfs.mfs_expire
27096 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
27100 + if (sbinfo->si_wbr_create_ops->init)
27101 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27108 + * plus: processed without an error
27109 + * zero: unprocessed
27111 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27112 + struct au_opts *opts)
27115 + struct au_sbinfo *sbinfo;
27117 + SiMustWriteLock(sb);
27119 + err = 1; /* handled */
27120 + sbinfo = au_sbi(sb);
27121 + switch (opt->type) {
27123 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27124 + sbinfo->si_mntflags |= opt->udba;
27125 + opts->given_udba |= opt->udba;
27129 + au_opt_set(sbinfo->si_mntflags, PLINK);
27131 + case Opt_noplink:
27132 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27133 + au_plink_put(sb, /*verbose*/1);
27134 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27136 + case Opt_list_plink:
27137 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27138 + au_plink_list(sb);
27142 + au_opt_set(sbinfo->si_mntflags, DIO);
27143 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27146 + au_opt_clr(sbinfo->si_mntflags, DIO);
27147 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27150 + case Opt_fhsm_sec:
27151 + au_fhsm_set(sbinfo, opt->fhsm_second);
27154 + case Opt_diropq_a:
27155 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27157 + case Opt_diropq_w:
27158 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27161 + case Opt_warn_perm:
27162 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27164 + case Opt_nowarn_perm:
27165 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27168 + case Opt_verbose:
27169 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27171 + case Opt_noverbose:
27172 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27176 + au_opt_set(sbinfo->si_mntflags, SUM);
27179 + au_opt_clr(sbinfo->si_mntflags, SUM);
27180 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27182 + au_opt_clr(sbinfo->si_mntflags, SUM);
27183 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27186 + case Opt_wbr_create:
27187 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27189 + case Opt_wbr_copyup:
27190 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27191 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27195 + sbinfo->si_dirwh = opt->dirwh;
27198 + case Opt_rdcache:
27199 + sbinfo->si_rdcache
27200 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27203 + sbinfo->si_rdblk = opt->rdblk;
27205 + case Opt_rdblk_def:
27206 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
27209 + sbinfo->si_rdhash = opt->rdhash;
27211 + case Opt_rdhash_def:
27212 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
27216 + au_opt_set(sbinfo->si_mntflags, SHWH);
27219 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27222 + case Opt_dirperm1:
27223 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27225 + case Opt_nodirperm1:
27226 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27229 + case Opt_trunc_xino:
27230 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27232 + case Opt_notrunc_xino:
27233 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27236 + case Opt_trunc_xino_path:
27237 + case Opt_itrunc_xino:
27238 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27244 + case Opt_trunc_xib:
27245 + au_fset_opts(opts->flags, TRUNC_XIB);
27247 + case Opt_notrunc_xib:
27248 + au_fclr_opts(opts->flags, TRUNC_XIB);
27253 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27254 + err = au_dr_opt_set(sb);
27259 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27261 + case Opt_nodirren:
27263 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27264 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27270 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27274 + sb->s_flags |= SB_POSIXACL;
27277 + sb->s_flags &= ~SB_POSIXACL;
27289 + * returns tri-state.
27290 + * plus: processed without an error
27291 + * zero: unprocessed
27294 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27295 + struct au_opts *opts)
27297 + int err, do_refresh;
27300 + switch (opt->type) {
27302 + opt->add.bindex = au_sbbot(sb) + 1;
27303 + if (opt->add.bindex < 0)
27304 + opt->add.bindex = 0;
27306 + case Opt_prepend:
27307 + opt->add.bindex = 0;
27308 + add: /* indented label */
27310 + err = au_br_add(sb, &opt->add,
27311 + au_ftest_opts(opts->flags, REMOUNT));
27314 + au_fset_opts(opts->flags, REFRESH);
27320 + err = au_br_del(sb, &opt->del,
27321 + au_ftest_opts(opts->flags, REMOUNT));
27324 + au_fset_opts(opts->flags, TRUNC_XIB);
27325 + au_fset_opts(opts->flags, REFRESH);
27331 + err = au_br_mod(sb, &opt->mod,
27332 + au_ftest_opts(opts->flags, REMOUNT),
27337 + au_fset_opts(opts->flags, REFRESH);
27344 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27345 + struct au_opt_xino **opt_xino,
27346 + struct au_opts *opts)
27351 + switch (opt->type) {
27353 + err = au_xino_set(sb, &opt->xino,
27354 + !!au_ftest_opts(opts->flags, REMOUNT));
27355 + if (unlikely(err))
27358 + *opt_xino = &opt->xino;
27363 + *opt_xino = (void *)-1;
27370 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27371 + unsigned int pending)
27374 + aufs_bindex_t bindex, bbot;
27375 + unsigned char do_plink, skip, do_free, can_no_dreval;
27376 + struct au_branch *br;
27377 + struct au_wbr *wbr;
27378 + struct dentry *root, *dentry;
27379 + struct inode *dir, *h_dir;
27380 + struct au_sbinfo *sbinfo;
27381 + struct au_hinode *hdir;
27383 + SiMustAnyLock(sb);
27385 + sbinfo = au_sbi(sb);
27386 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27388 + if (!(sb_flags & SB_RDONLY)) {
27389 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27390 + pr_warn("first branch should be rw\n");
27391 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27392 + pr_warn_once("shwh should be used with ro\n");
27395 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27396 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27397 + pr_warn_once("udba=*notify requires xino\n");
27399 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27400 + pr_warn_once("dirperm1 breaks the protection"
27401 + " by the permission bits on the lower branch\n");
27405 + root = sb->s_root;
27406 + dir = d_inode(root);
27407 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27408 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27410 + bbot = au_sbbot(sb);
27411 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27413 + h_dir = au_h_iptr(dir, bindex);
27414 + br = au_sbr(sb, bindex);
27416 + if ((br->br_perm & AuBrAttr_ICEX)
27417 + && !h_dir->i_op->listxattr)
27418 + br->br_perm &= ~AuBrAttr_ICEX;
27420 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27421 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27422 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27426 + wbr = br->br_wbr;
27428 + wbr_wh_read_lock(wbr);
27430 + if (!au_br_writable(br->br_perm)) {
27433 + || (!wbr->wbr_whbase
27434 + && !wbr->wbr_plink
27435 + && !wbr->wbr_orph));
27436 + } else if (!au_br_wh_linkable(br->br_perm)) {
27437 + /* skip = (!br->br_whbase && !br->br_orph); */
27438 + skip = (!wbr || !wbr->wbr_whbase);
27439 + if (skip && wbr) {
27441 + skip = !!wbr->wbr_plink;
27443 + skip = !wbr->wbr_plink;
27446 + /* skip = (br->br_whbase && br->br_ohph); */
27447 + skip = (wbr && wbr->wbr_whbase);
27450 + skip = !!wbr->wbr_plink;
27452 + skip = !wbr->wbr_plink;
27456 + wbr_wh_read_unlock(wbr);
27458 + if (can_no_dreval) {
27459 + dentry = br->br_path.dentry;
27460 + spin_lock(&dentry->d_lock);
27461 + if (dentry->d_flags &
27462 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27463 + can_no_dreval = 0;
27464 + spin_unlock(&dentry->d_lock);
27467 + if (au_br_fhsm(br->br_perm)) {
27469 + AuDebugOn(!br->br_fhsm);
27475 + hdir = au_hi(dir, bindex);
27476 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27478 + wbr_wh_write_lock(wbr);
27479 + err = au_wh_init(br, sb);
27481 + wbr_wh_write_unlock(wbr);
27482 + au_hn_inode_unlock(hdir);
27484 + if (!err && do_free) {
27485 + au_kfree_rcu(wbr);
27486 + br->br_wbr = NULL;
27490 + if (can_no_dreval)
27491 + au_fset_si(sbinfo, NO_DREVAL);
27493 + au_fclr_si(sbinfo, NO_DREVAL);
27496 + au_fset_si(sbinfo, FHSM);
27497 + for (bindex = bbot; bindex >= 0; bindex--) {
27498 + br = au_sbr(sb, bindex);
27499 + if (au_br_fhsm(br->br_perm)) {
27500 + au_fhsm_set_bottom(sb, bindex);
27505 + au_fclr_si(sbinfo, FHSM);
27506 + au_fhsm_set_bottom(sb, -1);
27512 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27515 + unsigned int tmp;
27516 + aufs_bindex_t bindex, bbot;
27517 + struct au_opt *opt;
27518 + struct au_opt_xino *opt_xino, xino;
27519 + struct au_sbinfo *sbinfo;
27520 + struct au_branch *br;
27521 + struct inode *dir;
27523 + SiMustWriteLock(sb);
27528 + while (err >= 0 && opt->type != Opt_tail)
27529 + err = au_opt_simple(sb, opt++, opts);
27532 + else if (unlikely(err < 0))
27535 + /* disable xino and udba temporary */
27536 + sbinfo = au_sbi(sb);
27537 + tmp = sbinfo->si_mntflags;
27538 + au_opt_clr(sbinfo->si_mntflags, XINO);
27539 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27542 + while (err >= 0 && opt->type != Opt_tail)
27543 + err = au_opt_br(sb, opt++, opts);
27546 + else if (unlikely(err < 0))
27549 + bbot = au_sbbot(sb);
27550 + if (unlikely(bbot < 0)) {
27552 + pr_err("no branches\n");
27556 + if (au_opt_test(tmp, XINO))
27557 + au_opt_set(sbinfo->si_mntflags, XINO);
27559 + while (!err && opt->type != Opt_tail)
27560 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27561 + if (unlikely(err))
27564 + err = au_opts_verify(sb, sb->s_flags, tmp);
27565 + if (unlikely(err))
27568 + /* restore xino */
27569 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27570 + xino.file = au_xino_def(sb);
27571 + err = PTR_ERR(xino.file);
27572 + if (IS_ERR(xino.file))
27575 + err = au_xino_set(sb, &xino, /*remount*/0);
27577 + if (unlikely(err))
27581 + /* restore udba */
27582 + tmp &= AuOptMask_UDBA;
27583 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27584 + sbinfo->si_mntflags |= tmp;
27585 + bbot = au_sbbot(sb);
27586 + for (bindex = 0; bindex <= bbot; bindex++) {
27587 + br = au_sbr(sb, bindex);
27588 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27589 + if (unlikely(err))
27590 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27592 + /* go on even if err */
27594 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27595 + dir = d_inode(sb->s_root);
27596 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27603 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27606 + unsigned char no_dreval;
27607 + struct inode *dir;
27608 + struct au_opt_xino *opt_xino;
27609 + struct au_opt *opt;
27610 + struct au_sbinfo *sbinfo;
27612 + SiMustWriteLock(sb);
27614 + err = au_dr_opt_flush(sb);
27615 + if (unlikely(err))
27617 + au_fset_opts(opts->flags, DR_FLUSHED);
27619 + dir = d_inode(sb->s_root);
27620 + sbinfo = au_sbi(sb);
27623 + while (err >= 0 && opt->type != Opt_tail) {
27624 + err = au_opt_simple(sb, opt, opts);
27626 + err = au_opt_br(sb, opt, opts);
27628 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27634 + /* go on even err */
27636 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27637 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27638 + if (unlikely(rerr && !err))
27641 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27642 + au_fset_opts(opts->flags, REFRESH_IDOP);
27644 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27645 + rerr = au_xib_trunc(sb);
27646 + if (unlikely(rerr && !err))
27650 + /* will be handled by the caller */
27651 + if (!au_ftest_opts(opts->flags, REFRESH)
27652 + && (opts->given_udba
27653 + || au_opt_test(sbinfo->si_mntflags, XINO)
27654 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27656 + au_fset_opts(opts->flags, REFRESH);
27658 + AuDbg("status 0x%x\n", opts->flags);
27664 +/* ---------------------------------------------------------------------- */
27666 +unsigned int au_opt_udba(struct super_block *sb)
27668 + return au_mntflags(sb) & AuOptMask_UDBA;
27670 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27671 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27672 +++ linux/fs/aufs/opts.h 2019-03-05 12:13:00.142557771 +0100
27674 +/* SPDX-License-Identifier: GPL-2.0 */
27676 + * Copyright (C) 2005-2019 Junjiro R. Okajima
27678 + * This program, aufs is free software; you can redistribute it and/or modify
27679 + * it under the terms of the GNU General Public License as published by
27680 + * the Free Software Foundation; either version 2 of the License, or
27681 + * (at your option) any later version.
27683 + * This program is distributed in the hope that it will be useful,
27684 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27685 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27686 + * GNU General Public License for more details.
27688 + * You should have received a copy of the GNU General Public License
27689 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27693 + * mount options/flags
27696 +#ifndef __AUFS_OPTS_H__
27697 +#define __AUFS_OPTS_H__
27701 +#include <linux/path.h>
27705 +/* ---------------------------------------------------------------------- */
27708 +#define AuOpt_XINO 1 /* external inode number bitmap
27709 + and translation table */
27710 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27711 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27712 +#define AuOpt_UDBA_REVAL (1 << 3)
27713 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27714 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27715 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27716 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27718 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27719 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27720 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27721 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27722 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
27723 +#define AuOpt_DIO (1 << 14) /* direct io */
27724 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27726 +#ifndef CONFIG_AUFS_HNOTIFY
27727 +#undef AuOpt_UDBA_HNOTIFY
27728 +#define AuOpt_UDBA_HNOTIFY 0
27730 +#ifndef CONFIG_AUFS_DIRREN
27731 +#undef AuOpt_DIRREN
27732 +#define AuOpt_DIRREN 0
27734 +#ifndef CONFIG_AUFS_SHWH
27736 +#define AuOpt_SHWH 0
27739 +#define AuOpt_Def (AuOpt_XINO \
27740 + | AuOpt_UDBA_REVAL \
27742 + /* | AuOpt_DIRPERM1 */ \
27743 + | AuOpt_WARN_PERM)
27744 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27745 + | AuOpt_UDBA_REVAL \
27746 + | AuOpt_UDBA_HNOTIFY)
27748 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27749 +#define au_opt_set(flags, name) do { \
27750 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27751 + ((flags) |= AuOpt_##name); \
27753 +#define au_opt_set_udba(flags, name) do { \
27754 + (flags) &= ~AuOptMask_UDBA; \
27755 + ((flags) |= AuOpt_##name); \
27757 +#define au_opt_clr(flags, name) do { \
27758 + ((flags) &= ~AuOpt_##name); \
27761 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27763 +#ifdef CONFIG_PROC_FS
27766 + return mntflags & ~AuOpt_PLINK;
27770 +/* ---------------------------------------------------------------------- */
27772 +/* policies to select one among multiple writable branches */
27774 + AuWbrCreate_TDP, /* top down parent */
27775 + AuWbrCreate_RR, /* round robin */
27776 + AuWbrCreate_MFS, /* most free space */
27777 + AuWbrCreate_MFSV, /* mfs with seconds */
27778 + AuWbrCreate_MFSRR, /* mfs then rr */
27779 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27780 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27781 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27782 + AuWbrCreate_PMFS, /* parent and mfs */
27783 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27784 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27785 + AuWbrCreate_PMFSRRV, /* plus seconds */
27787 + AuWbrCreate_Def = AuWbrCreate_TDP
27791 + AuWbrCopyup_TDP, /* top down parent */
27792 + AuWbrCopyup_BUP, /* bottom up parent */
27793 + AuWbrCopyup_BU, /* bottom up */
27795 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27798 +/* ---------------------------------------------------------------------- */
27800 +struct au_opt_add {
27801 + aufs_bindex_t bindex;
27804 + struct path path;
27807 +struct au_opt_del {
27809 + struct path h_path;
27812 +struct au_opt_mod {
27815 + struct dentry *h_root;
27818 +struct au_opt_xino {
27820 + struct file *file;
27823 +struct au_opt_xino_itrunc {
27824 + aufs_bindex_t bindex;
27827 +struct au_opt_wbr_create {
27830 + unsigned long long mfsrr_watermark;
27836 + struct au_opt_xino xino;
27837 + struct au_opt_xino_itrunc xino_itrunc;
27838 + struct au_opt_add add;
27839 + struct au_opt_del del;
27840 + struct au_opt_mod mod;
27843 + unsigned int rdblk;
27844 + unsigned int rdhash;
27846 + struct au_opt_wbr_create wbr_create;
27848 + unsigned int fhsm_second;
27853 +#define AuOpts_REMOUNT 1
27854 +#define AuOpts_REFRESH (1 << 1)
27855 +#define AuOpts_TRUNC_XIB (1 << 2)
27856 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27857 +#define AuOpts_REFRESH_IDOP (1 << 4)
27858 +#define AuOpts_DR_FLUSHED (1 << 5)
27859 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27860 +#define au_fset_opts(flags, name) \
27861 + do { (flags) |= AuOpts_##name; } while (0)
27862 +#define au_fclr_opts(flags, name) \
27863 + do { (flags) &= ~AuOpts_##name; } while (0)
27865 +#ifndef CONFIG_AUFS_DIRREN
27866 +#undef AuOpts_DR_FLUSHED
27867 +#define AuOpts_DR_FLUSHED 0
27871 + struct au_opt *opt;
27874 + unsigned int given_udba;
27875 + unsigned int flags;
27876 + unsigned long sb_flags;
27879 +/* ---------------------------------------------------------------------- */
27882 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27883 +const char *au_optstr_udba(int udba);
27884 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27885 +const char *au_optstr_wbr_create(int wbr_create);
27887 +void au_opts_free(struct au_opts *opts);
27888 +struct super_block;
27889 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27890 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27891 + unsigned int pending);
27892 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27893 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27895 +unsigned int au_opt_udba(struct super_block *sb);
27897 +#endif /* __KERNEL__ */
27898 +#endif /* __AUFS_OPTS_H__ */
27899 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27900 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27901 +++ linux/fs/aufs/plink.c 2019-03-05 12:13:00.142557771 +0100
27903 +// SPDX-License-Identifier: GPL-2.0
27905 + * Copyright (C) 2005-2019 Junjiro R. Okajima
27907 + * This program, aufs is free software; you can redistribute it and/or modify
27908 + * it under the terms of the GNU General Public License as published by
27909 + * the Free Software Foundation; either version 2 of the License, or
27910 + * (at your option) any later version.
27912 + * This program is distributed in the hope that it will be useful,
27913 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27914 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27915 + * GNU General Public License for more details.
27917 + * You should have received a copy of the GNU General Public License
27918 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27928 + * the pseudo-link maintenance mode.
27929 + * during a user process maintains the pseudo-links,
27930 + * prohibit adding a new plink and branch manipulation.
27934 + * For entry functions which will handle plink, and i_mutex is already held
27936 + * They cannot wait and should return an error at once.
27937 + * Callers has to check the error.
27939 + * For entry functions which will handle plink, but i_mutex is not held
27941 + * They can wait the plink maintenance mode to finish.
27943 + * They behave like F_SETLK and F_SETLKW.
27944 + * If the caller never handle plink, then both flags are unnecessary.
27947 +int au_plink_maint(struct super_block *sb, int flags)
27951 + struct task_struct *parent, *prev;
27952 + struct au_sbinfo *sbi;
27954 + SiMustAnyLock(sb);
27957 + if (!au_opt_test(au_mntflags(sb), PLINK))
27960 + sbi = au_sbi(sb);
27961 + pid = sbi->si_plink_maint_pid;
27962 + if (!pid || pid == current->pid)
27965 + /* todo: it highly depends upon /sbin/mount.aufs */
27967 + parent = current;
27971 + parent = rcu_dereference(parent->real_parent);
27972 + if (parent == prev)
27974 + ppid = task_pid_vnr(parent);
27975 + if (pid == ppid) {
27976 + rcu_read_unlock();
27981 + rcu_read_unlock();
27983 + if (au_ftest_lock(flags, NOPLMW)) {
27984 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27985 + /* AuDebugOn(!lockdep_depth(current)); */
27986 + while (sbi->si_plink_maint_pid) {
27987 + si_read_unlock(sb);
27988 + /* gave up wake_up_bit() */
27989 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27991 + if (au_ftest_lock(flags, FLUSH))
27992 + au_nwt_flush(&sbi->si_nowait);
27993 + si_noflush_read_lock(sb);
27995 + } else if (au_ftest_lock(flags, NOPLM)) {
27996 + AuDbg("ppid %d, pid %d\n", ppid, pid);
28004 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
28006 + spin_lock(&sbinfo->si_plink_maint_lock);
28007 + sbinfo->si_plink_maint_pid = 0;
28008 + spin_unlock(&sbinfo->si_plink_maint_lock);
28009 + wake_up_all(&sbinfo->si_plink_wq);
28012 +int au_plink_maint_enter(struct super_block *sb)
28015 + struct au_sbinfo *sbinfo;
28018 + sbinfo = au_sbi(sb);
28019 + /* make sure i am the only one in this fs */
28020 + si_write_lock(sb, AuLock_FLUSH);
28021 + if (au_opt_test(au_mntflags(sb), PLINK)) {
28022 + spin_lock(&sbinfo->si_plink_maint_lock);
28023 + if (!sbinfo->si_plink_maint_pid)
28024 + sbinfo->si_plink_maint_pid = current->pid;
28027 + spin_unlock(&sbinfo->si_plink_maint_lock);
28029 + si_write_unlock(sb);
28034 +/* ---------------------------------------------------------------------- */
28036 +#ifdef CONFIG_AUFS_DEBUG
28037 +void au_plink_list(struct super_block *sb)
28040 + struct au_sbinfo *sbinfo;
28041 + struct hlist_bl_head *hbl;
28042 + struct hlist_bl_node *pos;
28043 + struct au_icntnr *icntnr;
28045 + SiMustAnyLock(sb);
28047 + sbinfo = au_sbi(sb);
28048 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28049 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28051 + for (i = 0; i < AuPlink_NHASH; i++) {
28052 + hbl = sbinfo->si_plink + i;
28053 + hlist_bl_lock(hbl);
28054 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28055 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
28056 + hlist_bl_unlock(hbl);
28061 +/* is the inode pseudo-linked? */
28062 +int au_plink_test(struct inode *inode)
28065 + struct au_sbinfo *sbinfo;
28066 + struct hlist_bl_head *hbl;
28067 + struct hlist_bl_node *pos;
28068 + struct au_icntnr *icntnr;
28070 + sbinfo = au_sbi(inode->i_sb);
28071 + AuRwMustAnyLock(&sbinfo->si_rwsem);
28072 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
28073 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28076 + i = au_plink_hash(inode->i_ino);
28077 + hbl = sbinfo->si_plink + i;
28078 + hlist_bl_lock(hbl);
28079 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28080 + if (&icntnr->vfs_inode == inode) {
28084 + hlist_bl_unlock(hbl);
28088 +/* ---------------------------------------------------------------------- */
28091 + * generate a name for plink.
28092 + * the file will be stored under AUFS_WH_PLINKDIR.
28094 +/* 20 is max digits length of ulong 64 */
28095 +#define PLINK_NAME_LEN ((20 + 1) * 2)
28097 +static int plink_name(char *name, int len, struct inode *inode,
28098 + aufs_bindex_t bindex)
28101 + struct inode *h_inode;
28103 + h_inode = au_h_iptr(inode, bindex);
28104 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28108 +struct au_do_plink_lkup_args {
28109 + struct dentry **errp;
28110 + struct qstr *tgtname;
28111 + struct dentry *h_parent;
28112 + struct au_branch *br;
28115 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28116 + struct dentry *h_parent,
28117 + struct au_branch *br)
28119 + struct dentry *h_dentry;
28120 + struct inode *h_inode;
28122 + h_inode = d_inode(h_parent);
28123 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28124 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
28125 + inode_unlock_shared(h_inode);
28129 +static void au_call_do_plink_lkup(void *args)
28131 + struct au_do_plink_lkup_args *a = args;
28132 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
28135 +/* lookup the plink-ed @inode under the branch at @bindex */
28136 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28138 + struct dentry *h_dentry, *h_parent;
28139 + struct au_branch *br;
28141 + char a[PLINK_NAME_LEN];
28142 + struct qstr tgtname = QSTR_INIT(a, 0);
28144 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28146 + br = au_sbr(inode->i_sb, bindex);
28147 + h_parent = br->br_wbr->wbr_plink;
28148 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28150 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28151 + struct au_do_plink_lkup_args args = {
28152 + .errp = &h_dentry,
28153 + .tgtname = &tgtname,
28154 + .h_parent = h_parent,
28158 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28159 + if (unlikely(wkq_err))
28160 + h_dentry = ERR_PTR(wkq_err);
28162 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
28167 +/* create a pseudo-link */
28168 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
28169 + struct dentry *h_dentry, struct au_branch *br)
28172 + struct path h_path = {
28173 + .mnt = au_br_mnt(br)
28175 + struct inode *h_dir, *delegated;
28177 + h_dir = d_inode(h_parent);
28178 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28180 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
28181 + err = PTR_ERR(h_path.dentry);
28182 + if (IS_ERR(h_path.dentry))
28186 + /* wh.plink dir is not monitored */
28187 + /* todo: is it really safe? */
28188 + if (d_is_positive(h_path.dentry)
28189 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28190 + delegated = NULL;
28191 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28192 + if (unlikely(err == -EWOULDBLOCK)) {
28193 + pr_warn("cannot retry for NFSv4 delegation"
28194 + " for an internal unlink\n");
28197 + dput(h_path.dentry);
28198 + h_path.dentry = NULL;
28202 + if (!err && d_is_negative(h_path.dentry)) {
28203 + delegated = NULL;
28204 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28205 + if (unlikely(err == -EWOULDBLOCK)) {
28206 + pr_warn("cannot retry for NFSv4 delegation"
28207 + " for an internal link\n");
28211 + dput(h_path.dentry);
28214 + inode_unlock(h_dir);
28218 +struct do_whplink_args {
28220 + struct qstr *tgt;
28221 + struct dentry *h_parent;
28222 + struct dentry *h_dentry;
28223 + struct au_branch *br;
28226 +static void call_do_whplink(void *args)
28228 + struct do_whplink_args *a = args;
28229 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
28232 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28233 + aufs_bindex_t bindex, struct au_branch *br)
28235 + int err, wkq_err;
28236 + struct au_wbr *wbr;
28237 + struct dentry *h_parent;
28238 + char a[PLINK_NAME_LEN];
28239 + struct qstr tgtname = QSTR_INIT(a, 0);
28241 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
28242 + h_parent = wbr->wbr_plink;
28243 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28245 + /* always superio. */
28246 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28247 + struct do_whplink_args args = {
28250 + .h_parent = h_parent,
28251 + .h_dentry = h_dentry,
28254 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28255 + if (unlikely(wkq_err))
28258 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
28264 + * create a new pseudo-link for @h_dentry on @bindex.
28265 + * the linked inode is held in aufs @inode.
28267 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28268 + struct dentry *h_dentry)
28270 + struct super_block *sb;
28271 + struct au_sbinfo *sbinfo;
28272 + struct hlist_bl_head *hbl;
28273 + struct hlist_bl_node *pos;
28274 + struct au_icntnr *icntnr;
28275 + int found, err, cnt, i;
28277 + sb = inode->i_sb;
28278 + sbinfo = au_sbi(sb);
28279 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28280 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28282 + found = au_plink_test(inode);
28286 + i = au_plink_hash(inode->i_ino);
28287 + hbl = sbinfo->si_plink + i;
28290 + hlist_bl_lock(hbl);
28291 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28292 + if (&icntnr->vfs_inode == inode) {
28298 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28299 + hlist_bl_add_head(&icntnr->plink, hbl);
28301 + hlist_bl_unlock(hbl);
28303 + cnt = au_hbl_count(hbl);
28304 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28305 + if (cnt > AUFS_PLINK_WARN)
28306 + AuWarn1(msg ", %d\n", cnt);
28308 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
28309 + if (unlikely(err)) {
28310 + pr_warn("err %d, damaged pseudo link.\n", err);
28311 + au_hbl_del(&icntnr->plink, hbl);
28312 + iput(&icntnr->vfs_inode);
28315 + iput(&icntnr->vfs_inode);
28318 +/* free all plinks */
28319 +void au_plink_put(struct super_block *sb, int verbose)
28322 + struct au_sbinfo *sbinfo;
28323 + struct hlist_bl_head *hbl;
28324 + struct hlist_bl_node *pos, *tmp;
28325 + struct au_icntnr *icntnr;
28327 + SiMustWriteLock(sb);
28329 + sbinfo = au_sbi(sb);
28330 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28331 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28333 + /* no spin_lock since sbinfo is write-locked */
28335 + for (i = 0; i < AuPlink_NHASH; i++) {
28336 + hbl = sbinfo->si_plink + i;
28337 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28338 + pr_warn("pseudo-link is not flushed");
28341 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28342 + iput(&icntnr->vfs_inode);
28343 + INIT_HLIST_BL_HEAD(hbl);
28347 +void au_plink_clean(struct super_block *sb, int verbose)
28349 + struct dentry *root;
28351 + root = sb->s_root;
28352 + aufs_write_lock(root);
28353 + if (au_opt_test(au_mntflags(sb), PLINK))
28354 + au_plink_put(sb, verbose);
28355 + aufs_write_unlock(root);
28358 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28361 + aufs_bindex_t btop, bbot, bindex;
28364 + btop = au_ibtop(inode);
28365 + bbot = au_ibbot(inode);
28367 + for (bindex = btop; bindex <= bbot; bindex++) {
28368 + if (!au_h_iptr(inode, bindex)
28369 + || au_ii_br_id(inode, bindex) != br_id)
28371 + au_set_h_iptr(inode, bindex, NULL, 0);
28376 + for (bindex = btop; bindex <= bbot; bindex++)
28377 + if (au_h_iptr(inode, bindex)) {
28387 +/* free the plinks on a branch specified by @br_id */
28388 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28390 + struct au_sbinfo *sbinfo;
28391 + struct hlist_bl_head *hbl;
28392 + struct hlist_bl_node *pos, *tmp;
28393 + struct au_icntnr *icntnr;
28394 + struct inode *inode;
28397 + SiMustWriteLock(sb);
28399 + sbinfo = au_sbi(sb);
28400 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28401 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28403 + /* no bit_lock since sbinfo is write-locked */
28404 + for (i = 0; i < AuPlink_NHASH; i++) {
28405 + hbl = sbinfo->si_plink + i;
28406 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28407 + inode = au_igrab(&icntnr->vfs_inode);
28408 + ii_write_lock_child(inode);
28409 + do_put = au_plink_do_half_refresh(inode, br_id);
28411 + hlist_bl_del(&icntnr->plink);
28414 + ii_write_unlock(inode);
28419 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28420 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28421 +++ linux/fs/aufs/poll.c 2019-03-05 12:13:00.142557771 +0100
28423 +// SPDX-License-Identifier: GPL-2.0
28425 + * Copyright (C) 2005-2019 Junjiro R. Okajima
28427 + * This program, aufs is free software; you can redistribute it and/or modify
28428 + * it under the terms of the GNU General Public License as published by
28429 + * the Free Software Foundation; either version 2 of the License, or
28430 + * (at your option) any later version.
28432 + * This program is distributed in the hope that it will be useful,
28433 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28434 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28435 + * GNU General Public License for more details.
28437 + * You should have received a copy of the GNU General Public License
28438 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28443 + * There is only one filesystem which implements ->poll operation, currently.
28448 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28451 + struct file *h_file;
28452 + struct super_block *sb;
28454 + /* We should pretend an error happened. */
28455 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28456 + sb = file->f_path.dentry->d_sb;
28457 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28459 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28460 + if (IS_ERR(h_file)) {
28461 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28465 + mask = vfs_poll(h_file, pt);
28466 + fput(h_file); /* instead of au_read_post() */
28469 + si_read_unlock(sb);
28470 + if (mask & EPOLLERR)
28471 + AuDbg("mask 0x%x\n", mask);
28474 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28475 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28476 +++ linux/fs/aufs/posix_acl.c 2019-03-05 12:13:00.142557771 +0100
28478 +// SPDX-License-Identifier: GPL-2.0
28480 + * Copyright (C) 2014-2019 Junjiro R. Okajima
28482 + * This program, aufs is free software; you can redistribute it and/or modify
28483 + * it under the terms of the GNU General Public License as published by
28484 + * the Free Software Foundation; either version 2 of the License, or
28485 + * (at your option) any later version.
28487 + * This program is distributed in the hope that it will be useful,
28488 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28489 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28490 + * GNU General Public License for more details.
28492 + * You should have received a copy of the GNU General Public License
28493 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28497 + * posix acl operations
28500 +#include <linux/fs.h>
28503 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28505 + struct posix_acl *acl;
28507 + aufs_bindex_t bindex;
28508 + struct inode *h_inode;
28509 + struct super_block *sb;
28512 + sb = inode->i_sb;
28513 + si_read_lock(sb, AuLock_FLUSH);
28514 + ii_read_lock_child(inode);
28515 + if (!(sb->s_flags & SB_POSIXACL))
28518 + bindex = au_ibtop(inode);
28519 + h_inode = au_h_iptr(inode, bindex);
28520 + if (unlikely(!h_inode
28521 + || ((h_inode->i_mode & S_IFMT)
28522 + != (inode->i_mode & S_IFMT)))) {
28523 + err = au_busy_or_stale();
28524 + acl = ERR_PTR(err);
28528 + /* always topmost only */
28529 + acl = get_acl(h_inode, type);
28530 + if (!IS_ERR_OR_NULL(acl))
28531 + set_cached_acl(inode, type, acl);
28534 + ii_read_unlock(inode);
28535 + si_read_unlock(sb);
28537 + AuTraceErrPtr(acl);
28541 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28545 + struct dentry *dentry;
28546 + struct au_sxattr arg = {
28547 + .type = AU_ACL_SET,
28554 + IMustLock(inode);
28556 + if (inode->i_ino == AUFS_ROOT_INO)
28557 + dentry = dget(inode->i_sb->s_root);
28559 + dentry = d_find_alias(inode);
28561 + dentry = d_find_any_alias(inode);
28563 + pr_warn("cannot handle this inode, "
28564 + "please report to aufs-users ML\n");
28570 + ssz = au_sxattr(dentry, inode, &arg);
28575 + set_cached_acl(inode, type, acl);
28581 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28582 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28583 +++ linux/fs/aufs/procfs.c 2019-03-05 12:13:00.142557771 +0100
28585 +// SPDX-License-Identifier: GPL-2.0
28587 + * Copyright (C) 2010-2019 Junjiro R. Okajima
28589 + * This program, aufs is free software; you can redistribute it and/or modify
28590 + * it under the terms of the GNU General Public License as published by
28591 + * the Free Software Foundation; either version 2 of the License, or
28592 + * (at your option) any later version.
28594 + * This program is distributed in the hope that it will be useful,
28595 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28596 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28597 + * GNU General Public License for more details.
28599 + * You should have received a copy of the GNU General Public License
28600 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28604 + * procfs interfaces
28607 +#include <linux/proc_fs.h>
28610 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28612 + struct au_sbinfo *sbinfo;
28614 + sbinfo = file->private_data;
28616 + au_plink_maint_leave(sbinfo);
28617 + kobject_put(&sbinfo->si_kobj);
28623 +static void au_procfs_plm_write_clean(struct file *file)
28625 + struct au_sbinfo *sbinfo;
28627 + sbinfo = file->private_data;
28629 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28632 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28635 + struct super_block *sb;
28636 + struct au_sbinfo *sbinfo;
28637 + struct hlist_bl_node *pos;
28640 + if (unlikely(file->private_data))
28644 + /* don't use au_sbilist_lock() here */
28645 + hlist_bl_lock(&au_sbilist);
28646 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28647 + if (id == sysaufs_si_id(sbinfo)) {
28648 + kobject_get(&sbinfo->si_kobj);
28649 + sb = sbinfo->si_sb;
28652 + hlist_bl_unlock(&au_sbilist);
28655 + if (unlikely(!sb))
28658 + err = au_plink_maint_enter(sb);
28660 + /* keep kobject_get() */
28661 + file->private_data = sbinfo;
28663 + kobject_put(&sbinfo->si_kobj);
28669 + * Accept a valid "si=xxxx" only.
28670 + * Once it is accepted successfully, accept "clean" too.
28672 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28673 + size_t count, loff_t *ppos)
28676 + unsigned long id;
28677 + /* last newline is allowed */
28678 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28681 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28685 + if (unlikely(count > sizeof(buf)))
28688 + err = copy_from_user(buf, ubuf, count);
28689 + if (unlikely(err)) {
28696 + if (!strcmp("clean", buf)) {
28697 + au_procfs_plm_write_clean(file);
28698 + goto out_success;
28699 + } else if (unlikely(strncmp("si=", buf, 3)))
28702 + err = kstrtoul(buf + 3, 16, &id);
28703 + if (unlikely(err))
28706 + err = au_procfs_plm_write_si(file, id);
28707 + if (unlikely(err))
28711 + err = count; /* success */
28716 +static const struct file_operations au_procfs_plm_fop = {
28717 + .write = au_procfs_plm_write,
28718 + .release = au_procfs_plm_release,
28719 + .owner = THIS_MODULE
28722 +/* ---------------------------------------------------------------------- */
28724 +static struct proc_dir_entry *au_procfs_dir;
28726 +void au_procfs_fin(void)
28728 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28729 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28732 +int __init au_procfs_init(void)
28735 + struct proc_dir_entry *entry;
28738 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28739 + if (unlikely(!au_procfs_dir))
28742 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28743 + au_procfs_dir, &au_procfs_plm_fop);
28744 + if (unlikely(!entry))
28748 + goto out; /* success */
28752 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28756 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28757 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28758 +++ linux/fs/aufs/rdu.c 2019-03-05 12:13:00.142557771 +0100
28760 +// SPDX-License-Identifier: GPL-2.0
28762 + * Copyright (C) 2005-2019 Junjiro R. Okajima
28764 + * This program, aufs is free software; you can redistribute it and/or modify
28765 + * it under the terms of the GNU General Public License as published by
28766 + * the Free Software Foundation; either version 2 of the License, or
28767 + * (at your option) any later version.
28769 + * This program is distributed in the hope that it will be useful,
28770 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28771 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28772 + * GNU General Public License for more details.
28774 + * You should have received a copy of the GNU General Public License
28775 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28779 + * readdir in userspace.
28782 +#include <linux/compat.h>
28783 +#include <linux/fs_stack.h>
28784 +#include <linux/security.h>
28787 +/* bits for struct aufs_rdu.flags */
28788 +#define AuRdu_CALLED 1
28789 +#define AuRdu_CONT (1 << 1)
28790 +#define AuRdu_FULL (1 << 2)
28791 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28792 +#define au_fset_rdu(flags, name) \
28793 + do { (flags) |= AuRdu_##name; } while (0)
28794 +#define au_fclr_rdu(flags, name) \
28795 + do { (flags) &= ~AuRdu_##name; } while (0)
28797 +struct au_rdu_arg {
28798 + struct dir_context ctx;
28799 + struct aufs_rdu *rdu;
28800 + union au_rdu_ent_ul ent;
28801 + unsigned long end;
28803 + struct super_block *sb;
28807 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28808 + loff_t offset, u64 h_ino, unsigned int d_type)
28811 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28812 + struct aufs_rdu *rdu = arg->rdu;
28813 + struct au_rdu_ent ent;
28817 + au_fset_rdu(rdu->cookie.flags, CALLED);
28818 + len = au_rdu_len(nlen);
28819 + if (arg->ent.ul + len < arg->end) {
28821 + ent.bindex = rdu->cookie.bindex;
28822 + ent.type = d_type;
28824 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28825 + ent.type = DT_UNKNOWN;
28827 + /* unnecessary to support mmap_sem since this is a dir */
28829 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28831 + if (copy_to_user(arg->ent.e->name, name, nlen))
28833 + /* the terminating NULL */
28834 + if (__put_user(0, arg->ent.e->name + nlen))
28837 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28838 + arg->ent.ul += len;
28842 + au_fset_rdu(rdu->cookie.flags, FULL);
28844 + rdu->tail = arg->ent;
28848 + /* AuTraceErr(err); */
28852 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28856 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28858 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28859 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28861 + if (unlikely(offset != cookie->h_pos))
28867 + au_fclr_rdu(cookie->flags, CALLED);
28869 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28873 + && au_ftest_rdu(cookie->flags, CALLED)
28874 + && !au_ftest_rdu(cookie->flags, FULL));
28875 + cookie->h_pos = h_file->f_pos;
28882 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28885 + aufs_bindex_t bbot;
28886 + struct au_rdu_arg arg = {
28888 + .actor = au_rdu_fill
28891 + struct dentry *dentry;
28892 + struct inode *inode;
28893 + struct file *h_file;
28894 + struct au_rdu_cookie *cookie = &rdu->cookie;
28896 + /* VERIFY_WRITE */
28897 + err = !access_ok(rdu->ent.e, rdu->sz);
28898 + if (unlikely(err)) {
28904 + rdu->tail = rdu->ent;
28907 + arg.ent = rdu->ent;
28908 + arg.end = arg.ent.ul;
28909 + arg.end += rdu->sz;
28912 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28915 + err = security_file_permission(file, MAY_READ);
28917 + if (unlikely(err))
28920 + dentry = file->f_path.dentry;
28921 + inode = d_inode(dentry);
28922 + inode_lock_shared(inode);
28924 + arg.sb = inode->i_sb;
28925 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28926 + if (unlikely(err))
28928 + err = au_alive_dir(dentry);
28929 + if (unlikely(err))
28931 + /* todo: reval? */
28932 + fi_read_lock(file);
28935 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28936 + && cookie->generation != au_figen(file)))
28941 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28943 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28945 + bbot = au_fbtop(file);
28946 + if (cookie->bindex < bbot)
28947 + cookie->bindex = bbot;
28948 + bbot = au_fbbot_dir(file);
28949 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28950 + for (; !err && cookie->bindex <= bbot;
28951 + cookie->bindex++, cookie->h_pos = 0) {
28952 + h_file = au_hf_dir(file, cookie->bindex);
28956 + au_fclr_rdu(cookie->flags, FULL);
28957 + err = au_rdu_do(h_file, &arg);
28959 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28962 + AuDbg("rent %llu\n", rdu->rent);
28964 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28965 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28966 + au_fset_rdu(cookie->flags, CONT);
28967 + cookie->generation = au_figen(file);
28970 + ii_read_lock_child(inode);
28971 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28972 + ii_read_unlock(inode);
28975 + fi_read_unlock(file);
28977 + si_read_unlock(arg.sb);
28979 + inode_unlock_shared(inode);
28985 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28989 + unsigned long long nent;
28990 + union au_rdu_ent_ul *u;
28991 + struct au_rdu_ent ent;
28992 + struct super_block *sb;
28995 + nent = rdu->nent;
28997 + sb = file->f_path.dentry->d_sb;
28998 + si_read_lock(sb, AuLock_FLUSH);
28999 + while (nent-- > 0) {
29000 + /* unnecessary to support mmap_sem since this is a dir */
29001 + err = copy_from_user(&ent, u->e, sizeof(ent));
29003 + /* VERIFY_WRITE */
29004 + err = !access_ok(&u->e->ino, sizeof(ino));
29005 + if (unlikely(err)) {
29011 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
29013 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
29015 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
29017 + if (unlikely(err)) {
29022 + err = __put_user(ino, &u->e->ino);
29023 + if (unlikely(err)) {
29028 + u->ul += au_rdu_len(ent.nlen);
29030 + si_read_unlock(sb);
29035 +/* ---------------------------------------------------------------------- */
29037 +static int au_rdu_verify(struct aufs_rdu *rdu)
29039 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
29040 + "%llu, b%d, 0x%x, g%u}\n",
29041 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
29043 + rdu->rent, rdu->shwh, rdu->full,
29044 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
29045 + rdu->cookie.generation);
29047 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
29051 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
29055 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29058 + struct aufs_rdu rdu;
29059 + void __user *p = (void __user *)arg;
29061 + err = copy_from_user(&rdu, p, sizeof(rdu));
29062 + if (unlikely(err)) {
29067 + err = au_rdu_verify(&rdu);
29068 + if (unlikely(err))
29072 + case AUFS_CTL_RDU:
29073 + err = au_rdu(file, &rdu);
29074 + if (unlikely(err))
29077 + e = copy_to_user(p, &rdu, sizeof(rdu));
29078 + if (unlikely(e)) {
29083 + case AUFS_CTL_RDU_INO:
29084 + err = au_rdu_ino(file, &rdu);
29088 + /* err = -ENOTTY; */
29097 +#ifdef CONFIG_COMPAT
29098 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29101 + struct aufs_rdu rdu;
29102 + void __user *p = compat_ptr(arg);
29104 + /* todo: get_user()? */
29105 + err = copy_from_user(&rdu, p, sizeof(rdu));
29106 + if (unlikely(err)) {
29111 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29112 + err = au_rdu_verify(&rdu);
29113 + if (unlikely(err))
29117 + case AUFS_CTL_RDU:
29118 + err = au_rdu(file, &rdu);
29119 + if (unlikely(err))
29122 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29123 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29124 + e = copy_to_user(p, &rdu, sizeof(rdu));
29125 + if (unlikely(e)) {
29130 + case AUFS_CTL_RDU_INO:
29131 + err = au_rdu_ino(file, &rdu);
29135 + /* err = -ENOTTY; */
29144 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29145 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29146 +++ linux/fs/aufs/rwsem.h 2019-03-05 12:13:00.142557771 +0100
29148 +/* SPDX-License-Identifier: GPL-2.0 */
29150 + * Copyright (C) 2005-2019 Junjiro R. Okajima
29152 + * This program, aufs is free software; you can redistribute it and/or modify
29153 + * it under the terms of the GNU General Public License as published by
29154 + * the Free Software Foundation; either version 2 of the License, or
29155 + * (at your option) any later version.
29157 + * This program is distributed in the hope that it will be useful,
29158 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29159 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29160 + * GNU General Public License for more details.
29162 + * You should have received a copy of the GNU General Public License
29163 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29167 + * simple read-write semaphore wrappers
29170 +#ifndef __AUFS_RWSEM_H__
29171 +#define __AUFS_RWSEM_H__
29175 +#include "debug.h"
29177 +/* in the future, the name 'au_rwsem' will be totally gone */
29178 +#define au_rwsem rw_semaphore
29180 +/* to debug easier, do not make them inlined functions */
29181 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29182 +/* rwsem_is_locked() is unusable */
29183 +#define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \
29185 + && !lockdep_is_held_type(rw, 1))
29186 +#define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \
29188 + && !lockdep_is_held_type(rw, 0))
29189 +#define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \
29191 + && !lockdep_is_held(rw))
29192 +#define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \
29194 + && lockdep_is_held(rw))
29196 +#define au_rw_init(rw) init_rwsem(rw)
29198 +#define au_rw_init_wlock(rw) do { \
29199 + au_rw_init(rw); \
29200 + down_write(rw); \
29203 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29204 + au_rw_init(rw); \
29205 + down_write_nested(rw, lsc); \
29208 +#define au_rw_read_lock(rw) down_read(rw)
29209 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29210 +#define au_rw_read_unlock(rw) up_read(rw)
29211 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29212 +#define au_rw_write_lock(rw) down_write(rw)
29213 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29214 +#define au_rw_write_unlock(rw) up_write(rw)
29215 +/* why is not _nested version defined? */
29216 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29217 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29219 +#endif /* __KERNEL__ */
29220 +#endif /* __AUFS_RWSEM_H__ */
29221 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29222 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29223 +++ linux/fs/aufs/sbinfo.c 2019-03-05 12:13:00.142557771 +0100
29225 +// SPDX-License-Identifier: GPL-2.0
29227 + * Copyright (C) 2005-2019 Junjiro R. Okajima
29229 + * This program, aufs is free software; you can redistribute it and/or modify
29230 + * it under the terms of the GNU General Public License as published by
29231 + * the Free Software Foundation; either version 2 of the License, or
29232 + * (at your option) any later version.
29234 + * This program is distributed in the hope that it will be useful,
29235 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29236 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29237 + * GNU General Public License for more details.
29239 + * You should have received a copy of the GNU General Public License
29240 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29244 + * superblock private data
29250 + * they are necessary regardless sysfs is disabled.
29252 +void au_si_free(struct kobject *kobj)
29255 + struct au_sbinfo *sbinfo;
29256 + char *locked __maybe_unused; /* debug only */
29258 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29259 + for (i = 0; i < AuPlink_NHASH; i++)
29260 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29261 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29263 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29264 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29265 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29266 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29268 + dbgaufs_si_fin(sbinfo);
29269 + au_rw_write_lock(&sbinfo->si_rwsem);
29270 + au_br_free(sbinfo);
29271 + au_rw_write_unlock(&sbinfo->si_rwsem);
29273 + au_kfree_try_rcu(sbinfo->si_branch);
29274 + mutex_destroy(&sbinfo->si_xib_mtx);
29275 + AuRwDestroy(&sbinfo->si_rwsem);
29277 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29278 + /* si_nfiles is waited too */
29279 + au_kfree_rcu(sbinfo);
29282 +int au_si_alloc(struct super_block *sb)
29285 + struct au_sbinfo *sbinfo;
29288 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29289 + if (unlikely(!sbinfo))
29292 + /* will be reallocated separately */
29293 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29294 + if (unlikely(!sbinfo->si_branch))
29297 + err = sysaufs_si_init(sbinfo);
29299 + dbgaufs_si_null(sbinfo);
29300 + err = dbgaufs_si_init(sbinfo);
29301 + if (unlikely(err))
29302 + kobject_put(&sbinfo->si_kobj);
29304 + if (unlikely(err))
29307 + au_nwt_init(&sbinfo->si_nowait);
29308 + au_rw_init_wlock(&sbinfo->si_rwsem);
29310 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29311 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29313 + sbinfo->si_bbot = -1;
29314 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29316 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29317 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29318 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29319 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29321 + au_fhsm_init(sbinfo);
29323 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29325 + sbinfo->si_xino_jiffy = jiffies;
29326 + sbinfo->si_xino_expire
29327 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29328 + mutex_init(&sbinfo->si_xib_mtx);
29329 + /* leave si_xib_last_pindex and si_xib_next_bit */
29331 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29333 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29334 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29335 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29336 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29338 + for (i = 0; i < AuPlink_NHASH; i++)
29339 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29340 + init_waitqueue_head(&sbinfo->si_plink_wq);
29341 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29343 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29345 + /* with getattr by default */
29346 + sbinfo->si_iop_array = aufs_iop;
29348 + /* leave other members for sysaufs and si_mnt. */
29349 + sbinfo->si_sb = sb;
29350 + sb->s_fs_info = sbinfo;
29352 + return 0; /* success */
29355 + au_kfree_try_rcu(sbinfo->si_branch);
29357 + au_kfree_rcu(sbinfo);
29362 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29365 + struct au_branch **brp;
29367 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29370 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29371 + if (unlikely(!sz))
29372 + sz = sizeof(*brp);
29373 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29376 + sbinfo->si_branch = brp;
29383 +/* ---------------------------------------------------------------------- */
29385 +unsigned int au_sigen_inc(struct super_block *sb)
29387 + unsigned int gen;
29388 + struct inode *inode;
29390 + SiMustWriteLock(sb);
29392 + gen = ++au_sbi(sb)->si_generation;
29393 + au_update_digen(sb->s_root);
29394 + inode = d_inode(sb->s_root);
29395 + au_update_iigen(inode, /*half*/0);
29396 + inode_inc_iversion(inode);
29400 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29402 + aufs_bindex_t br_id;
29404 + struct au_sbinfo *sbinfo;
29406 + SiMustWriteLock(sb);
29408 + sbinfo = au_sbi(sb);
29409 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29410 + br_id = ++sbinfo->si_last_br_id;
29411 + AuDebugOn(br_id < 0);
29412 + if (br_id && au_br_index(sb, br_id) < 0)
29419 +/* ---------------------------------------------------------------------- */
29421 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29422 +int si_read_lock(struct super_block *sb, int flags)
29427 + if (au_ftest_lock(flags, FLUSH))
29428 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29430 + si_noflush_read_lock(sb);
29431 + err = au_plink_maint(sb, flags);
29432 + if (unlikely(err))
29433 + si_read_unlock(sb);
29438 +int si_write_lock(struct super_block *sb, int flags)
29442 + if (au_ftest_lock(flags, FLUSH))
29443 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29445 + si_noflush_write_lock(sb);
29446 + err = au_plink_maint(sb, flags);
29447 + if (unlikely(err))
29448 + si_write_unlock(sb);
29453 +/* dentry and super_block lock. call at entry point */
29454 +int aufs_read_lock(struct dentry *dentry, int flags)
29457 + struct super_block *sb;
29459 + sb = dentry->d_sb;
29460 + err = si_read_lock(sb, flags);
29461 + if (unlikely(err))
29464 + if (au_ftest_lock(flags, DW))
29465 + di_write_lock_child(dentry);
29467 + di_read_lock_child(dentry, flags);
29469 + if (au_ftest_lock(flags, GEN)) {
29470 + err = au_digen_test(dentry, au_sigen(sb));
29471 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29472 + AuDebugOn(!err && au_dbrange_test(dentry));
29474 + err = au_dbrange_test(dentry);
29475 + if (unlikely(err))
29476 + aufs_read_unlock(dentry, flags);
29483 +void aufs_read_unlock(struct dentry *dentry, int flags)
29485 + if (au_ftest_lock(flags, DW))
29486 + di_write_unlock(dentry);
29488 + di_read_unlock(dentry, flags);
29489 + si_read_unlock(dentry->d_sb);
29492 +void aufs_write_lock(struct dentry *dentry)
29494 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29495 + di_write_lock_child(dentry);
29498 +void aufs_write_unlock(struct dentry *dentry)
29500 + di_write_unlock(dentry);
29501 + si_write_unlock(dentry->d_sb);
29504 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29507 + unsigned int sigen;
29508 + struct super_block *sb;
29511 + err = si_read_lock(sb, flags);
29512 + if (unlikely(err))
29515 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29517 + if (au_ftest_lock(flags, GEN)) {
29518 + sigen = au_sigen(sb);
29519 + err = au_digen_test(d1, sigen);
29520 + AuDebugOn(!err && au_dbrange_test(d1));
29522 + err = au_digen_test(d2, sigen);
29523 + AuDebugOn(!err && au_dbrange_test(d2));
29525 + if (unlikely(err))
29526 + aufs_read_and_write_unlock2(d1, d2);
29533 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29535 + di_write_unlock2(d1, d2);
29536 + si_read_unlock(d1->d_sb);
29538 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29539 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29540 +++ linux/fs/aufs/super.c 2019-03-05 12:13:00.142557771 +0100
29542 +// SPDX-License-Identifier: GPL-2.0
29544 + * Copyright (C) 2005-2019 Junjiro R. Okajima
29546 + * This program, aufs is free software; you can redistribute it and/or modify
29547 + * it under the terms of the GNU General Public License as published by
29548 + * the Free Software Foundation; either version 2 of the License, or
29549 + * (at your option) any later version.
29551 + * This program is distributed in the hope that it will be useful,
29552 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29553 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29554 + * GNU General Public License for more details.
29556 + * You should have received a copy of the GNU General Public License
29557 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29561 + * mount and super_block operations
29564 +#include <linux/mm.h>
29565 +#include <linux/seq_file.h>
29566 +#include <linux/statfs.h>
29567 +#include <linux/vmalloc.h>
29571 + * super_operations
29573 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29575 + struct au_icntnr *c;
29577 + c = au_cache_alloc_icntnr();
29579 + au_icntnr_init(c);
29580 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29581 + c->iinfo.ii_hinode = NULL;
29582 + return &c->vfs_inode;
29587 +static void aufs_destroy_inode_cb(struct rcu_head *head)
29589 + struct inode *inode = container_of(head, struct inode, i_rcu);
29591 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29594 +static void aufs_destroy_inode(struct inode *inode)
29596 + if (!au_is_bad_inode(inode))
29597 + au_iinfo_fin(inode);
29598 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
29601 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29603 + struct inode *inode;
29606 + inode = iget_locked(sb, ino);
29607 + if (unlikely(!inode)) {
29608 + inode = ERR_PTR(-ENOMEM);
29611 + if (!(inode->i_state & I_NEW))
29614 + err = au_xigen_new(inode);
29616 + err = au_iinfo_init(inode);
29618 + inode_inc_iversion(inode);
29620 + iget_failed(inode);
29621 + inode = ERR_PTR(err);
29625 + /* never return NULL */
29626 + AuDebugOn(!inode);
29627 + AuTraceErrPtr(inode);
29631 +/* lock free root dinfo */
29632 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29635 + aufs_bindex_t bindex, bbot;
29636 + struct path path;
29637 + struct au_hdentry *hdp;
29638 + struct au_branch *br;
29639 + au_br_perm_str_t perm;
29642 + bbot = au_sbbot(sb);
29644 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29645 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29646 + br = au_sbr(sb, bindex);
29647 + path.mnt = au_br_mnt(br);
29648 + path.dentry = hdp->hd_dentry;
29649 + err = au_seq_path(seq, &path);
29651 + au_optstr_br_perm(&perm, br->br_perm);
29652 + seq_printf(seq, "=%s", perm.a);
29653 + if (bindex != bbot)
29654 + seq_putc(seq, ':');
29657 + if (unlikely(err || seq_has_overflowed(seq)))
29663 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29664 + const char *append)
29669 + while (*pat != ':')
29672 + strcpy(p, append);
29673 + AuDebugOn(strlen(fmt) >= len);
29676 +static void au_show_wbr_create(struct seq_file *m, int v,
29677 + struct au_sbinfo *sbinfo)
29681 + struct au_wbr_mfs *mfs;
29683 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29685 + seq_puts(m, ",create=");
29686 + pat = au_optstr_wbr_create(v);
29687 + mfs = &sbinfo->si_wbr_mfs;
29689 + case AuWbrCreate_TDP:
29690 + case AuWbrCreate_RR:
29691 + case AuWbrCreate_MFS:
29692 + case AuWbrCreate_PMFS:
29693 + seq_puts(m, pat);
29695 + case AuWbrCreate_MFSRR:
29696 + case AuWbrCreate_TDMFS:
29697 + case AuWbrCreate_PMFSRR:
29698 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29699 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29701 + case AuWbrCreate_MFSV:
29702 + case AuWbrCreate_PMFSV:
29703 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29704 + seq_printf(m, fmt,
29705 + jiffies_to_msecs(mfs->mfs_expire)
29708 + case AuWbrCreate_MFSRRV:
29709 + case AuWbrCreate_TDMFSV:
29710 + case AuWbrCreate_PMFSRRV:
29711 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29712 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29713 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29720 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29722 +#ifdef CONFIG_SYSFS
29726 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29727 + aufs_bindex_t bindex, brid;
29728 + struct qstr *name;
29730 + struct dentry *d, *h_root;
29731 + struct au_branch *br;
29733 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29736 + f = au_sbi(sb)->si_xib;
29740 + /* stop printing the default xino path on the first writable branch */
29742 + bindex = au_xi_root(sb, f->f_path.dentry);
29743 + if (bindex >= 0) {
29744 + br = au_sbr_sb(sb, bindex);
29745 + h_root = au_br_dentry(br);
29748 + d = f->f_path.dentry;
29749 + name = &d->d_name;
29750 + /* safe ->d_parent because the file is unlinked */
29751 + if (d->d_parent == h_root
29752 + && name->len == len
29753 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29756 + seq_puts(seq, ",xino=");
29757 + err = au_xino_path(seq, f);
29764 +/* seq_file will re-call me in case of too long string */
29765 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29768 + unsigned int mnt_flags, v;
29769 + struct super_block *sb;
29770 + struct au_sbinfo *sbinfo;
29772 +#define AuBool(name, str) do { \
29773 + v = au_opt_test(mnt_flags, name); \
29774 + if (v != au_opt_test(AuOpt_Def, name)) \
29775 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29778 +#define AuStr(name, str) do { \
29779 + v = mnt_flags & AuOptMask_##name; \
29780 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29781 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29784 +#define AuUInt(name, str, val) do { \
29785 + if (val != AUFS_##name##_DEF) \
29786 + seq_printf(m, "," #str "=%u", val); \
29789 + sb = dentry->d_sb;
29790 + if (sb->s_flags & SB_POSIXACL)
29791 + seq_puts(m, ",acl");
29793 + if (sb->s_flags & SB_I_VERSION)
29794 + seq_puts(m, ",i_version");
29797 + /* lock free root dinfo */
29798 + si_noflush_read_lock(sb);
29799 + sbinfo = au_sbi(sb);
29800 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29802 + mnt_flags = au_mntflags(sb);
29803 + if (au_opt_test(mnt_flags, XINO)) {
29804 + err = au_show_xino(m, sb);
29805 + if (unlikely(err))
29808 + seq_puts(m, ",noxino");
29810 + AuBool(TRUNC_XINO, trunc_xino);
29811 + AuStr(UDBA, udba);
29812 + AuBool(SHWH, shwh);
29813 + AuBool(PLINK, plink);
29814 + AuBool(DIO, dio);
29815 + AuBool(DIRPERM1, dirperm1);
29817 + v = sbinfo->si_wbr_create;
29818 + if (v != AuWbrCreate_Def)
29819 + au_show_wbr_create(m, v, sbinfo);
29821 + v = sbinfo->si_wbr_copyup;
29822 + if (v != AuWbrCopyup_Def)
29823 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29825 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29826 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29827 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29829 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29831 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29832 + AuUInt(RDCACHE, rdcache, v);
29834 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29835 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29837 + au_fhsm_show(m, sbinfo);
29839 + AuBool(DIRREN, dirren);
29840 + AuBool(SUM, sum);
29841 + /* AuBool(SUM_W, wsum); */
29842 + AuBool(WARN_PERM, warn_perm);
29843 + AuBool(VERBOSE, verbose);
29846 + /* be sure to print "br:" last */
29847 + if (!sysaufs_brs) {
29848 + seq_puts(m, ",br:");
29849 + au_show_brs(m, sb);
29851 + si_read_unlock(sb);
29859 +/* ---------------------------------------------------------------------- */
29861 +/* sum mode which returns the summation for statfs(2) */
29863 +static u64 au_add_till_max(u64 a, u64 b)
29871 + return ULLONG_MAX;
29874 +static u64 au_mul_till_max(u64 a, long mul)
29882 + return ULLONG_MAX;
29885 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29888 + long bsize, factor;
29889 + u64 blocks, bfree, bavail, files, ffree;
29890 + aufs_bindex_t bbot, bindex, i;
29891 + unsigned char shared;
29892 + struct path h_path;
29893 + struct super_block *h_sb;
29896 + bsize = LONG_MAX;
29902 + bbot = au_sbbot(sb);
29903 + for (bindex = 0; bindex <= bbot; bindex++) {
29904 + h_path.mnt = au_sbr_mnt(sb, bindex);
29905 + h_sb = h_path.mnt->mnt_sb;
29907 + for (i = 0; !shared && i < bindex; i++)
29908 + shared = (au_sbr_sb(sb, i) == h_sb);
29912 + /* sb->s_root for NFS is unreliable */
29913 + h_path.dentry = h_path.mnt->mnt_root;
29914 + err = vfs_statfs(&h_path, buf);
29915 + if (unlikely(err))
29918 + if (bsize > buf->f_bsize) {
29920 + * we will reduce bsize, so we have to expand blocks
29921 + * etc. to match them again
29923 + factor = (bsize / buf->f_bsize);
29924 + blocks = au_mul_till_max(blocks, factor);
29925 + bfree = au_mul_till_max(bfree, factor);
29926 + bavail = au_mul_till_max(bavail, factor);
29927 + bsize = buf->f_bsize;
29930 + factor = (buf->f_bsize / bsize);
29931 + blocks = au_add_till_max(blocks,
29932 + au_mul_till_max(buf->f_blocks, factor));
29933 + bfree = au_add_till_max(bfree,
29934 + au_mul_till_max(buf->f_bfree, factor));
29935 + bavail = au_add_till_max(bavail,
29936 + au_mul_till_max(buf->f_bavail, factor));
29937 + files = au_add_till_max(files, buf->f_files);
29938 + ffree = au_add_till_max(ffree, buf->f_ffree);
29941 + buf->f_bsize = bsize;
29942 + buf->f_blocks = blocks;
29943 + buf->f_bfree = bfree;
29944 + buf->f_bavail = bavail;
29945 + buf->f_files = files;
29946 + buf->f_ffree = ffree;
29947 + buf->f_frsize = 0;
29953 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29956 + struct path h_path;
29957 + struct super_block *sb;
29959 + /* lock free root dinfo */
29960 + sb = dentry->d_sb;
29961 + si_noflush_read_lock(sb);
29962 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29963 + /* sb->s_root for NFS is unreliable */
29964 + h_path.mnt = au_sbr_mnt(sb, 0);
29965 + h_path.dentry = h_path.mnt->mnt_root;
29966 + err = vfs_statfs(&h_path, buf);
29968 + err = au_statfs_sum(sb, buf);
29969 + si_read_unlock(sb);
29972 + buf->f_type = AUFS_SUPER_MAGIC;
29973 + buf->f_namelen = AUFS_MAX_NAMELEN;
29974 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29976 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29981 +/* ---------------------------------------------------------------------- */
29983 +static int aufs_sync_fs(struct super_block *sb, int wait)
29986 + aufs_bindex_t bbot, bindex;
29987 + struct au_branch *br;
29988 + struct super_block *h_sb;
29991 + si_noflush_read_lock(sb);
29992 + bbot = au_sbbot(sb);
29993 + for (bindex = 0; bindex <= bbot; bindex++) {
29994 + br = au_sbr(sb, bindex);
29995 + if (!au_br_writable(br->br_perm))
29998 + h_sb = au_sbr_sb(sb, bindex);
29999 + e = vfsub_sync_filesystem(h_sb, wait);
30000 + if (unlikely(e && !err))
30002 + /* go on even if an error happens */
30004 + si_read_unlock(sb);
30009 +/* ---------------------------------------------------------------------- */
30011 +/* final actions when unmounting a file system */
30012 +static void aufs_put_super(struct super_block *sb)
30014 + struct au_sbinfo *sbinfo;
30016 + sbinfo = au_sbi(sb);
30018 + kobject_put(&sbinfo->si_kobj);
30021 +/* ---------------------------------------------------------------------- */
30023 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30024 + struct super_block *sb, void *arg)
30027 + unsigned long long n, sz;
30034 + if (*hint > ULLONG_MAX / sizeof(array)) {
30035 + array = ERR_PTR(-EMFILE);
30036 + pr_err("hint %llu\n", *hint);
30040 + sz = sizeof(array) * *hint;
30041 + array = kzalloc(sz, GFP_NOFS);
30042 + if (unlikely(!array))
30043 + array = vzalloc(sz);
30044 + if (unlikely(!array)) {
30045 + array = ERR_PTR(-ENOMEM);
30049 + n = cb(sb, array, *hint, arg);
30050 + AuDebugOn(n > *hint);
30057 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
30058 + unsigned long long max __maybe_unused,
30061 + unsigned long long n;
30062 + struct inode **p, *inode;
30063 + struct list_head *head;
30068 + spin_lock(&sb->s_inode_list_lock);
30069 + list_for_each_entry(inode, head, i_sb_list) {
30070 + if (!au_is_bad_inode(inode)
30071 + && au_ii(inode)->ii_btop >= 0) {
30072 + spin_lock(&inode->i_lock);
30073 + if (atomic_read(&inode->i_count)) {
30077 + AuDebugOn(n > max);
30079 + spin_unlock(&inode->i_lock);
30082 + spin_unlock(&sb->s_inode_list_lock);
30087 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
30089 + struct au_sbinfo *sbi;
30091 + sbi = au_sbi(sb);
30092 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
30093 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
30096 +void au_iarray_free(struct inode **a, unsigned long long max)
30098 + unsigned long long ull;
30100 + for (ull = 0; ull < max; ull++)
30105 +/* ---------------------------------------------------------------------- */
30108 + * refresh dentry and inode at remount time.
30110 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30111 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30112 + struct dentry *parent)
30116 + di_write_lock_child(dentry);
30117 + di_read_lock_parent(parent, AuLock_IR);
30118 + err = au_refresh_dentry(dentry, parent);
30119 + if (!err && dir_flags)
30120 + au_hn_reset(d_inode(dentry), dir_flags);
30121 + di_read_unlock(parent, AuLock_IR);
30122 + di_write_unlock(dentry);
30127 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30128 + struct au_sbinfo *sbinfo,
30129 + const unsigned int dir_flags, unsigned int do_idop)
30132 + struct dentry *parent;
30135 + parent = dget_parent(dentry);
30136 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30137 + if (d_really_is_positive(dentry)) {
30138 + if (!d_is_dir(dentry))
30139 + err = au_do_refresh(dentry, /*dir_flags*/0,
30142 + err = au_do_refresh(dentry, dir_flags, parent);
30143 + if (unlikely(err))
30144 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30147 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30148 + AuDbgDentry(dentry);
30154 + au_refresh_dop(dentry, /*force_reval*/0);
30156 + au_refresh_dop(dentry, /*force_reval*/1);
30162 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30164 + int err, i, j, ndentry, e;
30165 + unsigned int sigen;
30166 + struct au_dcsub_pages dpages;
30167 + struct au_dpage *dpage;
30168 + struct dentry **dentries, *d;
30169 + struct au_sbinfo *sbinfo;
30170 + struct dentry *root = sb->s_root;
30171 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30174 + au_refresh_dop(root, /*force_reval*/0);
30176 + err = au_dpages_init(&dpages, GFP_NOFS);
30177 + if (unlikely(err))
30179 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30180 + if (unlikely(err))
30183 + sigen = au_sigen(sb);
30184 + sbinfo = au_sbi(sb);
30185 + for (i = 0; i < dpages.ndpage; i++) {
30186 + dpage = dpages.dpages + i;
30187 + dentries = dpage->dentries;
30188 + ndentry = dpage->ndentry;
30189 + for (j = 0; j < ndentry; j++) {
30191 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30193 + if (unlikely(e && !err))
30195 + /* go on even err */
30200 + au_dpages_free(&dpages);
30205 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30208 + unsigned int sigen;
30209 + unsigned long long max, ull;
30210 + struct inode *inode, **array;
30212 + array = au_iarray_alloc(sb, &max);
30213 + err = PTR_ERR(array);
30214 + if (IS_ERR(array))
30218 + sigen = au_sigen(sb);
30219 + for (ull = 0; ull < max; ull++) {
30220 + inode = array[ull];
30221 + if (unlikely(!inode))
30225 + ii_write_lock_child(inode);
30226 + if (au_iigen(inode, NULL) != sigen) {
30227 + e = au_refresh_hinode_self(inode);
30228 + if (unlikely(e)) {
30229 + au_refresh_iop(inode, /*force_getattr*/1);
30230 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30233 + /* go on even if err */
30236 + if (!e && do_idop)
30237 + au_refresh_iop(inode, /*force_getattr*/0);
30238 + ii_write_unlock(inode);
30241 + au_iarray_free(array, max);
30247 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30250 + unsigned int udba;
30251 + aufs_bindex_t bindex, bbot;
30252 + struct dentry *root;
30253 + struct inode *inode;
30254 + struct au_branch *br;
30255 + struct au_sbinfo *sbi;
30257 + au_sigen_inc(sb);
30258 + sbi = au_sbi(sb);
30259 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30261 + root = sb->s_root;
30262 + DiMustNoWaiters(root);
30263 + inode = d_inode(root);
30264 + IiMustNoWaiters(inode);
30266 + udba = au_opt_udba(sb);
30267 + bbot = au_sbbot(sb);
30268 + for (bindex = 0; bindex <= bbot; bindex++) {
30269 + br = au_sbr(sb, bindex);
30270 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30271 + if (unlikely(err))
30272 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30274 + /* go on even if err */
30276 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30279 + if (au_ftest_si(sbi, NO_DREVAL)) {
30280 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30281 + sb->s_d_op = &aufs_dop_noreval;
30282 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30283 + sbi->si_iop_array = aufs_iop_nogetattr;
30285 + AuDebugOn(sb->s_d_op == &aufs_dop);
30286 + sb->s_d_op = &aufs_dop;
30287 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30288 + sbi->si_iop_array = aufs_iop;
30290 + pr_info("reset to %ps and %ps\n",
30291 + sb->s_d_op, sbi->si_iop_array);
30294 + di_write_unlock(root);
30295 + err = au_refresh_d(sb, do_idop);
30296 + e = au_refresh_i(sb, do_idop);
30297 + if (unlikely(e && !err))
30299 + /* aufs_write_lock() calls ..._child() */
30300 + di_write_lock_child(root);
30302 + au_cpup_attr_all(inode, /*force*/1);
30304 + if (unlikely(err))
30305 + AuIOErr("refresh failed, ignored, %d\n", err);
30308 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30309 +static int cvt_err(int err)
30323 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30326 + unsigned int mntflags;
30327 + struct au_opts opts = {
30330 + struct dentry *root;
30331 + struct inode *inode;
30332 + struct au_sbinfo *sbinfo;
30335 + root = sb->s_root;
30336 + if (!data || !*data) {
30337 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30339 + di_write_lock_child(root);
30340 + err = au_opts_verify(sb, *flags, /*pending*/0);
30341 + aufs_write_unlock(root);
30347 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30348 + if (unlikely(!opts.opt))
30350 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30351 + opts.flags = AuOpts_REMOUNT;
30352 + opts.sb_flags = *flags;
30354 + /* parse it before aufs lock */
30355 + err = au_opts_parse(sb, data, &opts);
30356 + if (unlikely(err))
30359 + sbinfo = au_sbi(sb);
30360 + inode = d_inode(root);
30361 + inode_lock(inode);
30362 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30363 + if (unlikely(err))
30365 + di_write_lock_child(root);
30367 + /* au_opts_remount() may return an error */
30368 + err = au_opts_remount(sb, &opts);
30369 + au_opts_free(&opts);
30371 + if (au_ftest_opts(opts.flags, REFRESH))
30372 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30374 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30375 + mntflags = au_mntflags(sb);
30376 + do_dx = !!au_opt_test(mntflags, DIO);
30377 + au_dy_arefresh(do_dx);
30380 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30381 + aufs_write_unlock(root);
30384 + inode_unlock(inode);
30386 + free_page((unsigned long)opts.opt);
30388 + err = cvt_err(err);
30393 +static const struct super_operations aufs_sop = {
30394 + .alloc_inode = aufs_alloc_inode,
30395 + .destroy_inode = aufs_destroy_inode,
30396 + /* always deleting, no clearing */
30397 + .drop_inode = generic_delete_inode,
30398 + .show_options = aufs_show_options,
30399 + .statfs = aufs_statfs,
30400 + .put_super = aufs_put_super,
30401 + .sync_fs = aufs_sync_fs,
30402 + .remount_fs = aufs_remount_fs
30405 +/* ---------------------------------------------------------------------- */
30407 +static int alloc_root(struct super_block *sb)
30410 + struct inode *inode;
30411 + struct dentry *root;
30414 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30415 + err = PTR_ERR(inode);
30416 + if (IS_ERR(inode))
30419 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30420 + inode->i_fop = &aufs_dir_fop;
30421 + inode->i_mode = S_IFDIR;
30422 + set_nlink(inode, 2);
30423 + unlock_new_inode(inode);
30425 + root = d_make_root(inode);
30426 + if (unlikely(!root))
30428 + err = PTR_ERR(root);
30429 + if (IS_ERR(root))
30432 + err = au_di_init(root);
30434 + sb->s_root = root;
30435 + return 0; /* success */
30443 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30444 + int silent __maybe_unused)
30447 + struct au_opts opts = {
30450 + struct au_sbinfo *sbinfo;
30451 + struct dentry *root;
30452 + struct inode *inode;
30453 + char *arg = raw_data;
30455 + if (unlikely(!arg || !*arg)) {
30457 + pr_err("no arg\n");
30462 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30463 + if (unlikely(!opts.opt))
30465 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30466 + opts.sb_flags = sb->s_flags;
30468 + err = au_si_alloc(sb);
30469 + if (unlikely(err))
30471 + sbinfo = au_sbi(sb);
30473 + /* all timestamps always follow the ones on the branch */
30474 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30475 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30476 + sb->s_op = &aufs_sop;
30477 + sb->s_d_op = &aufs_dop;
30478 + sb->s_magic = AUFS_SUPER_MAGIC;
30479 + sb->s_maxbytes = 0;
30480 + sb->s_stack_depth = 1;
30481 + au_export_init(sb);
30482 + au_xattr_init(sb);
30484 + err = alloc_root(sb);
30485 + if (unlikely(err)) {
30486 + si_write_unlock(sb);
30489 + root = sb->s_root;
30490 + inode = d_inode(root);
30493 + * actually we can parse options regardless aufs lock here.
30494 + * but at remount time, parsing must be done before aufs lock.
30495 + * so we follow the same rule.
30497 + ii_write_lock_parent(inode);
30498 + aufs_write_unlock(root);
30499 + err = au_opts_parse(sb, arg, &opts);
30500 + if (unlikely(err))
30503 + /* lock vfs_inode first, then aufs. */
30504 + inode_lock(inode);
30505 + aufs_write_lock(root);
30506 + err = au_opts_mount(sb, &opts);
30507 + au_opts_free(&opts);
30508 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30509 + sb->s_d_op = &aufs_dop_noreval;
30510 + pr_info("%ps\n", sb->s_d_op);
30511 + au_refresh_dop(root, /*force_reval*/0);
30512 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30513 + au_refresh_iop(inode, /*force_getattr*/0);
30515 + aufs_write_unlock(root);
30516 + inode_unlock(inode);
30518 + goto out_opts; /* success */
30522 + sb->s_root = NULL;
30524 + kobject_put(&sbinfo->si_kobj);
30525 + sb->s_fs_info = NULL;
30527 + free_page((unsigned long)opts.opt);
30530 + err = cvt_err(err);
30535 +/* ---------------------------------------------------------------------- */
30537 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30538 + const char *dev_name __maybe_unused,
30541 + struct dentry *root;
30543 + /* all timestamps always follow the ones on the branch */
30544 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30545 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30546 + if (IS_ERR(root))
30549 + au_sbilist_add(root->d_sb);
30555 +static void aufs_kill_sb(struct super_block *sb)
30557 + struct au_sbinfo *sbinfo;
30559 + sbinfo = au_sbi(sb);
30561 + au_sbilist_del(sb);
30562 + aufs_write_lock(sb->s_root);
30564 + if (sbinfo->si_wbr_create_ops->fin)
30565 + sbinfo->si_wbr_create_ops->fin(sb);
30566 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30567 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30568 + au_remount_refresh(sb, /*do_idop*/0);
30570 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30571 + au_plink_put(sb, /*verbose*/1);
30573 + au_dr_opt_flush(sb);
30574 + sbinfo->si_sb = NULL;
30575 + aufs_write_unlock(sb->s_root);
30576 + au_nwt_flush(&sbinfo->si_nowait);
30578 + kill_anon_super(sb);
30581 +struct file_system_type aufs_fs_type = {
30582 + .name = AUFS_FSTYPE,
30583 + /* a race between rename and others */
30584 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30585 + .mount = aufs_mount,
30586 + .kill_sb = aufs_kill_sb,
30587 + /* no need to __module_get() and module_put(). */
30588 + .owner = THIS_MODULE,
30590 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30591 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30592 +++ linux/fs/aufs/super.h 2019-03-05 12:13:00.142557771 +0100
30594 +/* SPDX-License-Identifier: GPL-2.0 */
30596 + * Copyright (C) 2005-2019 Junjiro R. Okajima
30598 + * This program, aufs is free software; you can redistribute it and/or modify
30599 + * it under the terms of the GNU General Public License as published by
30600 + * the Free Software Foundation; either version 2 of the License, or
30601 + * (at your option) any later version.
30603 + * This program is distributed in the hope that it will be useful,
30604 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30605 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30606 + * GNU General Public License for more details.
30608 + * You should have received a copy of the GNU General Public License
30609 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30613 + * super_block operations
30616 +#ifndef __AUFS_SUPER_H__
30617 +#define __AUFS_SUPER_H__
30621 +#include <linux/fs.h>
30622 +#include <linux/kobject.h>
30625 +#include "rwsem.h"
30628 +/* policies to select one among multiple writable branches */
30629 +struct au_wbr_copyup_operations {
30630 + int (*copyup)(struct dentry *dentry);
30633 +#define AuWbr_DIR 1 /* target is a dir */
30634 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30636 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30637 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30638 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30640 +struct au_wbr_create_operations {
30641 + int (*create)(struct dentry *dentry, unsigned int flags);
30642 + int (*init)(struct super_block *sb);
30643 + int (*fin)(struct super_block *sb);
30646 +struct au_wbr_mfs {
30647 + struct mutex mfs_lock; /* protect this structure */
30648 + unsigned long mfs_jiffy;
30649 + unsigned long mfs_expire;
30650 + aufs_bindex_t mfs_bindex;
30652 + unsigned long long mfsrr_bytes;
30653 + unsigned long long mfsrr_watermark;
30656 +#define AuPlink_NHASH 100
30657 +static inline int au_plink_hash(ino_t ino)
30659 + return ino % AuPlink_NHASH;
30662 +/* File-based Hierarchical Storage Management */
30664 +#ifdef CONFIG_AUFS_FHSM
30665 + /* allow only one process who can receive the notification */
30666 + spinlock_t fhsm_spin;
30668 + wait_queue_head_t fhsm_wqh;
30669 + atomic_t fhsm_readable;
30671 + /* these are protected by si_rwsem */
30672 + unsigned long fhsm_expire;
30673 + aufs_bindex_t fhsm_bottom;
30678 +struct au_sbinfo {
30679 + /* nowait tasks in the system-wide workqueue */
30680 + struct au_nowait_tasks si_nowait;
30683 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30684 + * rwsem for au_sbinfo is necessary.
30686 + struct au_rwsem si_rwsem;
30689 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30692 + au_lcnt_t si_ninodes, si_nfiles;
30694 + /* branch management */
30695 + unsigned int si_generation;
30697 + /* see AuSi_ flags */
30698 + unsigned char au_si_status;
30700 + aufs_bindex_t si_bbot;
30702 + /* dirty trick to keep br_id plus */
30703 + unsigned int si_last_br_id :
30704 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30705 + struct au_branch **si_branch;
30707 + /* policy to select a writable branch */
30708 + unsigned char si_wbr_copyup;
30709 + unsigned char si_wbr_create;
30710 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30711 + struct au_wbr_create_operations *si_wbr_create_ops;
30713 + /* round robin */
30714 + atomic_t si_wbr_rr_next;
30716 + /* most free space */
30717 + struct au_wbr_mfs si_wbr_mfs;
30719 + /* File-based Hierarchical Storage Management */
30720 + struct au_fhsm si_fhsm;
30722 + /* mount flags */
30723 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30724 + unsigned int si_mntflags;
30726 + /* external inode number (bitmap and translation table) */
30727 + vfs_readf_t si_xread;
30728 + vfs_writef_t si_xwrite;
30729 + loff_t si_ximaxent; /* max entries in a xino */
30731 + struct file *si_xib;
30732 + struct mutex si_xib_mtx; /* protect xib members */
30733 + unsigned long *si_xib_buf;
30734 + unsigned long si_xib_last_pindex;
30735 + int si_xib_next_bit;
30737 + unsigned long si_xino_jiffy;
30738 + unsigned long si_xino_expire;
30739 + /* reserved for future use */
30740 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30742 +#ifdef CONFIG_AUFS_EXPORT
30743 + /* i_generation */
30744 + /* todo: make xigen file an array to support many inode numbers */
30745 + struct file *si_xigen;
30746 + atomic_t si_xigen_next;
30749 + /* dirty trick to support atomic_open */
30750 + struct hlist_bl_head si_aopen;
30752 + /* vdir parameters */
30753 + unsigned long si_rdcache; /* max cache time in jiffies */
30754 + unsigned int si_rdblk; /* deblk size */
30755 + unsigned int si_rdhash; /* hash size */
30758 + * If the number of whiteouts are larger than si_dirwh, leave all of
30759 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30760 + * future fsck.aufs or kernel thread will remove them later.
30761 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30763 + unsigned int si_dirwh;
30765 + /* pseudo_link list */
30766 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30767 + wait_queue_head_t si_plink_wq;
30768 + spinlock_t si_plink_maint_lock;
30769 + pid_t si_plink_maint_pid;
30772 + struct hlist_bl_head si_files;
30774 + /* with/without getattr, brother of sb->s_d_op */
30775 + struct inode_operations *si_iop_array;
30778 + * sysfs and lifetime management.
30779 + * this is not a small structure and it may be a waste of memory in case
30780 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30781 + * but using sysfs is majority.
30783 + struct kobject si_kobj;
30784 +#ifdef CONFIG_DEBUG_FS
30785 + struct dentry *si_dbgaufs;
30786 + struct dentry *si_dbgaufs_plink;
30787 + struct dentry *si_dbgaufs_xib;
30788 +#ifdef CONFIG_AUFS_EXPORT
30789 + struct dentry *si_dbgaufs_xigen;
30793 +#ifdef CONFIG_AUFS_SBILIST
30794 + struct hlist_bl_node si_list;
30797 + /* dirty, necessary for unmounting, sysfs and sysrq */
30798 + struct super_block *si_sb;
30801 +/* sbinfo status flags */
30803 + * set true when refresh_dirs() failed at remount time.
30804 + * then try refreshing dirs at access time again.
30805 + * if it is false, refreshing dirs at access time is unnecessary
30807 +#define AuSi_FAILED_REFRESH_DIR 1
30808 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30809 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30811 +#ifndef CONFIG_AUFS_FHSM
30813 +#define AuSi_FHSM 0
30816 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30817 + unsigned int flag)
30819 + AuRwMustAnyLock(&sbi->si_rwsem);
30820 + return sbi->au_si_status & flag;
30822 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30823 +#define au_fset_si(sbinfo, name) do { \
30824 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30825 + (sbinfo)->au_si_status |= AuSi_##name; \
30827 +#define au_fclr_si(sbinfo, name) do { \
30828 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30829 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30832 +/* ---------------------------------------------------------------------- */
30834 +/* policy to select one among writable branches */
30835 +#define AuWbrCopyup(sbinfo, ...) \
30836 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30837 +#define AuWbrCreate(sbinfo, ...) \
30838 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30840 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30841 +#define AuLock_DW 1 /* write-lock dentry */
30842 +#define AuLock_IR (1 << 1) /* read-lock inode */
30843 +#define AuLock_IW (1 << 2) /* write-lock inode */
30844 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30845 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30846 + /* except RENAME_EXCHANGE */
30847 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30848 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30849 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30850 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30851 +#define au_fset_lock(flags, name) \
30852 + do { (flags) |= AuLock_##name; } while (0)
30853 +#define au_fclr_lock(flags, name) \
30854 + do { (flags) &= ~AuLock_##name; } while (0)
30856 +/* ---------------------------------------------------------------------- */
30859 +extern struct file_system_type aufs_fs_type;
30860 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30861 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30862 + unsigned long long max, void *arg);
30863 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30864 + struct super_block *sb, void *arg);
30865 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30866 +void au_iarray_free(struct inode **a, unsigned long long max);
30869 +void au_si_free(struct kobject *kobj);
30870 +int au_si_alloc(struct super_block *sb);
30871 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30873 +unsigned int au_sigen_inc(struct super_block *sb);
30874 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30876 +int si_read_lock(struct super_block *sb, int flags);
30877 +int si_write_lock(struct super_block *sb, int flags);
30878 +int aufs_read_lock(struct dentry *dentry, int flags);
30879 +void aufs_read_unlock(struct dentry *dentry, int flags);
30880 +void aufs_write_lock(struct dentry *dentry);
30881 +void aufs_write_unlock(struct dentry *dentry);
30882 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30883 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30885 +/* wbr_policy.c */
30886 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30887 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30888 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30889 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30890 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30893 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30895 +#ifdef CONFIG_AUFS_FHSM
30898 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30902 + spin_lock(&fhsm->fhsm_spin);
30903 + pid = fhsm->fhsm_pid;
30904 + spin_unlock(&fhsm->fhsm_spin);
30909 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30910 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30911 +int au_fhsm_fd(struct super_block *sb, int oflags);
30912 +int au_fhsm_br_alloc(struct au_branch *br);
30913 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30914 +void au_fhsm_fin(struct super_block *sb);
30915 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30916 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30917 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30919 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30921 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30922 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30923 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30924 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30925 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30926 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30927 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30928 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30929 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30932 +/* ---------------------------------------------------------------------- */
30934 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30936 + return sb->s_fs_info;
30939 +/* ---------------------------------------------------------------------- */
30941 +#ifdef CONFIG_AUFS_EXPORT
30942 +int au_test_nfsd(void);
30943 +void au_export_init(struct super_block *sb);
30944 +void au_xigen_inc(struct inode *inode);
30945 +int au_xigen_new(struct inode *inode);
30946 +int au_xigen_set(struct super_block *sb, struct path *path);
30947 +void au_xigen_clr(struct super_block *sb);
30949 +static inline int au_busy_or_stale(void)
30951 + if (!au_test_nfsd())
30956 +AuStubInt0(au_test_nfsd, void)
30957 +AuStubVoid(au_export_init, struct super_block *sb)
30958 +AuStubVoid(au_xigen_inc, struct inode *inode)
30959 +AuStubInt0(au_xigen_new, struct inode *inode)
30960 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30961 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30962 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30963 +#endif /* CONFIG_AUFS_EXPORT */
30965 +/* ---------------------------------------------------------------------- */
30967 +#ifdef CONFIG_AUFS_SBILIST
30969 +extern struct hlist_bl_head au_sbilist;
30971 +static inline void au_sbilist_init(void)
30973 + INIT_HLIST_BL_HEAD(&au_sbilist);
30976 +static inline void au_sbilist_add(struct super_block *sb)
30978 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30981 +static inline void au_sbilist_del(struct super_block *sb)
30983 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30986 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30987 +static inline void au_sbilist_lock(void)
30989 + hlist_bl_lock(&au_sbilist);
30992 +static inline void au_sbilist_unlock(void)
30994 + hlist_bl_unlock(&au_sbilist);
30996 +#define AuGFP_SBILIST GFP_ATOMIC
30998 +AuStubVoid(au_sbilist_lock, void)
30999 +AuStubVoid(au_sbilist_unlock, void)
31000 +#define AuGFP_SBILIST GFP_NOFS
31001 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
31003 +AuStubVoid(au_sbilist_init, void)
31004 +AuStubVoid(au_sbilist_add, struct super_block *sb)
31005 +AuStubVoid(au_sbilist_del, struct super_block *sb)
31006 +AuStubVoid(au_sbilist_lock, void)
31007 +AuStubVoid(au_sbilist_unlock, void)
31008 +#define AuGFP_SBILIST GFP_NOFS
31011 +/* ---------------------------------------------------------------------- */
31013 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
31016 + * This function is a dynamic '__init' function actually,
31017 + * so the tiny check for si_rwsem is unnecessary.
31019 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
31020 +#ifdef CONFIG_DEBUG_FS
31021 + sbinfo->si_dbgaufs = NULL;
31022 + sbinfo->si_dbgaufs_plink = NULL;
31023 + sbinfo->si_dbgaufs_xib = NULL;
31024 +#ifdef CONFIG_AUFS_EXPORT
31025 + sbinfo->si_dbgaufs_xigen = NULL;
31030 +/* ---------------------------------------------------------------------- */
31032 +/* current->atomic_flags */
31033 +/* this value should never corrupt the ones defined in linux/sched.h */
31034 +#define PFA_AUFS 7
31036 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
31037 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
31038 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
31040 +static inline int si_pid_test(struct super_block *sb)
31042 + return !!task_test_aufs(current);
31045 +static inline void si_pid_clr(struct super_block *sb)
31047 + AuDebugOn(!task_test_aufs(current));
31048 + task_clear_aufs(current);
31051 +static inline void si_pid_set(struct super_block *sb)
31053 + AuDebugOn(task_test_aufs(current));
31054 + task_set_aufs(current);
31057 +/* ---------------------------------------------------------------------- */
31059 +/* lock superblock. mainly for entry point functions */
31060 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
31061 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
31062 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
31063 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
31065 +#define __si_read_trylock_nested(sb) \
31066 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
31067 +#define __si_write_trylock_nested(sb) \
31068 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
31071 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
31072 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
31073 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
31075 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
31076 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
31077 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
31079 +static inline void si_noflush_read_lock(struct super_block *sb)
31081 + __si_read_lock(sb);
31085 +static inline int si_noflush_read_trylock(struct super_block *sb)
31089 + locked = __si_read_trylock(sb);
31095 +static inline void si_noflush_write_lock(struct super_block *sb)
31097 + __si_write_lock(sb);
31101 +static inline int si_noflush_write_trylock(struct super_block *sb)
31105 + locked = __si_write_trylock(sb);
31111 +#if 0 /* reserved */
31112 +static inline int si_read_trylock(struct super_block *sb, int flags)
31114 + if (au_ftest_lock(flags, FLUSH))
31115 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31116 + return si_noflush_read_trylock(sb);
31120 +static inline void si_read_unlock(struct super_block *sb)
31123 + __si_read_unlock(sb);
31126 +#if 0 /* reserved */
31127 +static inline int si_write_trylock(struct super_block *sb, int flags)
31129 + if (au_ftest_lock(flags, FLUSH))
31130 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31131 + return si_noflush_write_trylock(sb);
31135 +static inline void si_write_unlock(struct super_block *sb)
31138 + __si_write_unlock(sb);
31141 +#if 0 /* reserved */
31142 +static inline void si_downgrade_lock(struct super_block *sb)
31144 + __si_downgrade_lock(sb);
31148 +/* ---------------------------------------------------------------------- */
31150 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31152 + SiMustAnyLock(sb);
31153 + return au_sbi(sb)->si_bbot;
31156 +static inline unsigned int au_mntflags(struct super_block *sb)
31158 + SiMustAnyLock(sb);
31159 + return au_sbi(sb)->si_mntflags;
31162 +static inline unsigned int au_sigen(struct super_block *sb)
31164 + SiMustAnyLock(sb);
31165 + return au_sbi(sb)->si_generation;
31168 +static inline struct au_branch *au_sbr(struct super_block *sb,
31169 + aufs_bindex_t bindex)
31171 + SiMustAnyLock(sb);
31172 + return au_sbi(sb)->si_branch[0 + bindex];
31175 +static inline loff_t au_xi_maxent(struct super_block *sb)
31177 + SiMustAnyLock(sb);
31178 + return au_sbi(sb)->si_ximaxent;
31181 +#endif /* __KERNEL__ */
31182 +#endif /* __AUFS_SUPER_H__ */
31183 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31184 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31185 +++ linux/fs/aufs/sysaufs.c 2019-03-05 12:13:00.142557771 +0100
31187 +// SPDX-License-Identifier: GPL-2.0
31189 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31191 + * This program, aufs is free software; you can redistribute it and/or modify
31192 + * it under the terms of the GNU General Public License as published by
31193 + * the Free Software Foundation; either version 2 of the License, or
31194 + * (at your option) any later version.
31196 + * This program is distributed in the hope that it will be useful,
31197 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31198 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31199 + * GNU General Public License for more details.
31201 + * You should have received a copy of the GNU General Public License
31202 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31206 + * sysfs interface and lifetime management
31207 + * they are necessary regardless sysfs is disabled.
31210 +#include <linux/random.h>
31213 +unsigned long sysaufs_si_mask;
31214 +struct kset *sysaufs_kset;
31216 +#define AuSiAttr(_name) { \
31217 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31218 + .show = sysaufs_si_##_name, \
31221 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31222 +struct attribute *sysaufs_si_attrs[] = {
31223 + &sysaufs_si_attr_xi_path.attr,
31227 +static const struct sysfs_ops au_sbi_ops = {
31228 + .show = sysaufs_si_show
31231 +static struct kobj_type au_sbi_ktype = {
31232 + .release = au_si_free,
31233 + .sysfs_ops = &au_sbi_ops,
31234 + .default_attrs = sysaufs_si_attrs
31237 +/* ---------------------------------------------------------------------- */
31239 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31243 + sbinfo->si_kobj.kset = sysaufs_kset;
31244 + /* cf. sysaufs_name() */
31245 + err = kobject_init_and_add
31246 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31247 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31252 +void sysaufs_fin(void)
31254 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31255 + kset_unregister(sysaufs_kset);
31258 +int __init sysaufs_init(void)
31263 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31264 + } while (!sysaufs_si_mask);
31267 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31268 + if (unlikely(!sysaufs_kset))
31270 + err = PTR_ERR(sysaufs_kset);
31271 + if (IS_ERR(sysaufs_kset))
31273 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31274 + if (unlikely(err))
31275 + kset_unregister(sysaufs_kset);
31280 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31281 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31282 +++ linux/fs/aufs/sysaufs.h 2019-03-05 12:13:00.142557771 +0100
31284 +/* SPDX-License-Identifier: GPL-2.0 */
31286 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31288 + * This program, aufs is free software; you can redistribute it and/or modify
31289 + * it under the terms of the GNU General Public License as published by
31290 + * the Free Software Foundation; either version 2 of the License, or
31291 + * (at your option) any later version.
31293 + * This program is distributed in the hope that it will be useful,
31294 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31295 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31296 + * GNU General Public License for more details.
31298 + * You should have received a copy of the GNU General Public License
31299 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31303 + * sysfs interface and mount lifetime management
31306 +#ifndef __SYSAUFS_H__
31307 +#define __SYSAUFS_H__
31311 +#include <linux/sysfs.h>
31312 +#include "module.h"
31314 +struct super_block;
31317 +struct sysaufs_si_attr {
31318 + struct attribute attr;
31319 + int (*show)(struct seq_file *seq, struct super_block *sb);
31322 +/* ---------------------------------------------------------------------- */
31325 +extern unsigned long sysaufs_si_mask;
31326 +extern struct kset *sysaufs_kset;
31327 +extern struct attribute *sysaufs_si_attrs[];
31328 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31329 +int __init sysaufs_init(void);
31330 +void sysaufs_fin(void);
31332 +/* ---------------------------------------------------------------------- */
31334 +/* some people doesn't like to show a pointer in kernel */
31335 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31337 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31340 +#define SysaufsSiNamePrefix "si_"
31341 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31342 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31344 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31345 + sysaufs_si_id(sbinfo));
31349 +#ifdef CONFIG_SYSFS
31351 +extern struct attribute_group *sysaufs_attr_group;
31353 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31354 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31356 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31357 +#ifdef CONFIG_COMPAT
31358 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31361 +void sysaufs_br_init(struct au_branch *br);
31362 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31363 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31365 +#define sysaufs_brs_init() do {} while (0)
31368 +#define sysaufs_attr_group NULL
31370 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31371 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31372 + struct attribute *attr, char *buf)
31373 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31374 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31375 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31377 +static inline void sysaufs_brs_init(void)
31382 +#endif /* CONFIG_SYSFS */
31384 +#endif /* __KERNEL__ */
31385 +#endif /* __SYSAUFS_H__ */
31386 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31387 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31388 +++ linux/fs/aufs/sysfs.c 2019-03-05 12:13:00.142557771 +0100
31390 +// SPDX-License-Identifier: GPL-2.0
31392 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31394 + * This program, aufs is free software; you can redistribute it and/or modify
31395 + * it under the terms of the GNU General Public License as published by
31396 + * the Free Software Foundation; either version 2 of the License, or
31397 + * (at your option) any later version.
31399 + * This program is distributed in the hope that it will be useful,
31400 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31401 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31402 + * GNU General Public License for more details.
31404 + * You should have received a copy of the GNU General Public License
31405 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31409 + * sysfs interface
31412 +#include <linux/compat.h>
31413 +#include <linux/seq_file.h>
31416 +#ifdef CONFIG_AUFS_FS_MODULE
31417 +/* this entry violates the "one line per file" policy of sysfs */
31418 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31422 + static char *conf =
31423 +/* this file is generated at compiling */
31424 +#include "conf.str"
31427 + err = snprintf(buf, PAGE_SIZE, conf);
31428 + if (unlikely(err >= PAGE_SIZE))
31433 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31436 +static struct attribute *au_attr[] = {
31437 +#ifdef CONFIG_AUFS_FS_MODULE
31438 + &au_config_attr.attr,
31440 + NULL, /* need to NULL terminate the list of attributes */
31443 +static struct attribute_group sysaufs_attr_group_body = {
31447 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31449 +/* ---------------------------------------------------------------------- */
31451 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31455 + SiMustAnyLock(sb);
31458 + if (au_opt_test(au_mntflags(sb), XINO)) {
31459 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31460 + seq_putc(seq, '\n');
31466 + * the lifetime of branch is independent from the entry under sysfs.
31467 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31470 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31471 + aufs_bindex_t bindex, int idx)
31474 + struct path path;
31475 + struct dentry *root;
31476 + struct au_branch *br;
31477 + au_br_perm_str_t perm;
31479 + AuDbg("b%d\n", bindex);
31482 + root = sb->s_root;
31483 + di_read_lock_parent(root, !AuLock_IR);
31484 + br = au_sbr(sb, bindex);
31487 + case AuBrSysfs_BR:
31488 + path.mnt = au_br_mnt(br);
31489 + path.dentry = au_h_dptr(root, bindex);
31490 + err = au_seq_path(seq, &path);
31492 + au_optstr_br_perm(&perm, br->br_perm);
31493 + seq_printf(seq, "=%s\n", perm.a);
31496 + case AuBrSysfs_BRID:
31497 + seq_printf(seq, "%d\n", br->br_id);
31500 + di_read_unlock(root, !AuLock_IR);
31501 + if (unlikely(err || seq_has_overflowed(seq)))
31507 +/* ---------------------------------------------------------------------- */
31509 +static struct seq_file *au_seq(char *p, ssize_t len)
31511 + struct seq_file *seq;
31513 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31515 + /* mutex_init(&seq.lock); */
31518 + return seq; /* success */
31521 + seq = ERR_PTR(-ENOMEM);
31525 +#define SysaufsBr_PREFIX "br"
31526 +#define SysaufsBrid_PREFIX "brid"
31528 +/* todo: file size may exceed PAGE_SIZE */
31529 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31535 + aufs_bindex_t bbot;
31536 + struct au_sbinfo *sbinfo;
31537 + struct super_block *sb;
31538 + struct seq_file *seq;
31540 + struct attribute **cattr;
31542 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31543 + sb = sbinfo->si_sb;
31546 + * prevent a race condition between sysfs and aufs.
31547 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31548 + * prohibits maintaining the sysfs entries.
31549 + * hew we acquire read lock after sysfs_get_active_two().
31550 + * on the other hand, the remount process may maintain the sysfs/aufs
31551 + * entries after acquiring write lock.
31552 + * it can cause a deadlock.
31553 + * simply we gave up processing read here.
31556 + if (unlikely(!si_noflush_read_trylock(sb)))
31559 + seq = au_seq(buf, PAGE_SIZE);
31560 + err = PTR_ERR(seq);
31564 + name = (void *)attr->name;
31565 + cattr = sysaufs_si_attrs;
31567 + if (!strcmp(name, (*cattr)->name)) {
31568 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31575 + if (!strncmp(name, SysaufsBrid_PREFIX,
31576 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31577 + idx = AuBrSysfs_BRID;
31578 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31579 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31580 + sizeof(SysaufsBr_PREFIX) - 1)) {
31581 + idx = AuBrSysfs_BR;
31582 + name += sizeof(SysaufsBr_PREFIX) - 1;
31586 + err = kstrtol(name, 10, &l);
31588 + bbot = au_sbbot(sb);
31590 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31597 + err = seq->count;
31598 + /* sysfs limit */
31599 + if (unlikely(err == PAGE_SIZE))
31602 + au_kfree_rcu(seq);
31604 + si_read_unlock(sb);
31609 +/* ---------------------------------------------------------------------- */
31611 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31615 + aufs_bindex_t bindex, bbot;
31618 + struct seq_file *seq;
31619 + struct au_branch *br;
31621 + si_read_lock(sb, AuLock_FLUSH);
31622 + bbot = au_sbbot(sb);
31628 + buf = (void *)__get_free_page(GFP_NOFS);
31629 + if (unlikely(!buf))
31632 + seq = au_seq(buf, PAGE_SIZE);
31633 + err = PTR_ERR(seq);
31637 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31638 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31639 + /* VERIFY_WRITE */
31640 + err = !access_ok(arg, sizeof(*arg));
31641 + if (unlikely(err))
31644 + br = au_sbr(sb, bindex);
31645 + brid = br->br_id;
31646 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31647 + err = __put_user(brid, &arg->id);
31648 + if (unlikely(err))
31651 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31652 + err = __put_user(br->br_perm, &arg->perm);
31653 + if (unlikely(err))
31656 + err = au_seq_path(seq, &br->br_path);
31657 + if (unlikely(err))
31659 + seq_putc(seq, '\0');
31660 + if (!seq_has_overflowed(seq)) {
31661 + err = copy_to_user(arg->path, seq->buf, seq->count);
31663 + if (unlikely(err))
31670 + if (unlikely(err))
31674 + au_kfree_rcu(seq);
31676 + free_page((unsigned long)buf);
31678 + si_read_unlock(sb);
31682 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31684 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31687 +#ifdef CONFIG_COMPAT
31688 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31690 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31694 +/* ---------------------------------------------------------------------- */
31696 +void sysaufs_br_init(struct au_branch *br)
31699 + struct au_brsysfs *br_sysfs;
31700 + struct attribute *attr;
31702 + br_sysfs = br->br_sysfs;
31703 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31704 + attr = &br_sysfs->attr;
31705 + sysfs_attr_init(attr);
31706 + attr->name = br_sysfs->name;
31707 + attr->mode = 0444;
31712 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31714 + struct au_branch *br;
31715 + struct kobject *kobj;
31716 + struct au_brsysfs *br_sysfs;
31718 + aufs_bindex_t bbot;
31720 + if (!sysaufs_brs)
31723 + kobj = &au_sbi(sb)->si_kobj;
31724 + bbot = au_sbbot(sb);
31725 + for (; bindex <= bbot; bindex++) {
31726 + br = au_sbr(sb, bindex);
31727 + br_sysfs = br->br_sysfs;
31728 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31729 + sysfs_remove_file(kobj, &br_sysfs->attr);
31735 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31738 + aufs_bindex_t bbot;
31739 + struct kobject *kobj;
31740 + struct au_branch *br;
31741 + struct au_brsysfs *br_sysfs;
31743 + if (!sysaufs_brs)
31746 + kobj = &au_sbi(sb)->si_kobj;
31747 + bbot = au_sbbot(sb);
31748 + for (; bindex <= bbot; bindex++) {
31749 + br = au_sbr(sb, bindex);
31750 + br_sysfs = br->br_sysfs;
31751 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31752 + SysaufsBr_PREFIX "%d", bindex);
31753 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31754 + SysaufsBrid_PREFIX "%d", bindex);
31755 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31756 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31757 + if (unlikely(err))
31758 + pr_warn("failed %s under sysfs(%d)\n",
31759 + br_sysfs->name, err);
31764 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31765 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31766 +++ linux/fs/aufs/sysrq.c 2019-03-05 12:13:00.142557771 +0100
31768 +// SPDX-License-Identifier: GPL-2.0
31770 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31772 + * This program, aufs is free software; you can redistribute it and/or modify
31773 + * it under the terms of the GNU General Public License as published by
31774 + * the Free Software Foundation; either version 2 of the License, or
31775 + * (at your option) any later version.
31777 + * This program is distributed in the hope that it will be useful,
31778 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31779 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31780 + * GNU General Public License for more details.
31782 + * You should have received a copy of the GNU General Public License
31783 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31787 + * magic sysrq handler
31790 +/* #include <linux/sysrq.h> */
31791 +#include <linux/writeback.h>
31794 +/* ---------------------------------------------------------------------- */
31796 +static void sysrq_sb(struct super_block *sb)
31799 + struct au_sbinfo *sbinfo;
31800 + struct file *file;
31801 + struct hlist_bl_head *files;
31802 + struct hlist_bl_node *pos;
31803 + struct au_finfo *finfo;
31805 + plevel = au_plevel;
31806 + au_plevel = KERN_WARNING;
31808 + /* since we define pr_fmt, call printk directly */
31809 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31811 + sbinfo = au_sbi(sb);
31812 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31813 + pr("superblock\n");
31817 + pr("root dentry\n");
31818 + au_dpri_dentry(sb->s_root);
31819 + pr("root inode\n");
31820 + au_dpri_inode(d_inode(sb->s_root));
31825 + int err, i, j, ndentry;
31826 + struct au_dcsub_pages dpages;
31827 + struct au_dpage *dpage;
31829 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31830 + if (unlikely(err))
31832 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31834 + for (i = 0; i < dpages.ndpage; i++) {
31835 + dpage = dpages.dpages + i;
31836 + ndentry = dpage->ndentry;
31837 + for (j = 0; j < ndentry; j++)
31838 + au_dpri_dentry(dpage->dentries[j]);
31840 + au_dpages_free(&dpages);
31848 + pr("isolated inode\n");
31849 + spin_lock(&sb->s_inode_list_lock);
31850 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31851 + spin_lock(&i->i_lock);
31852 + if (1 || hlist_empty(&i->i_dentry))
31853 + au_dpri_inode(i);
31854 + spin_unlock(&i->i_lock);
31856 + spin_unlock(&sb->s_inode_list_lock);
31860 + files = &au_sbi(sb)->si_files;
31861 + hlist_bl_lock(files);
31862 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31865 + file = finfo->fi_file;
31866 + mode = file_inode(file)->i_mode;
31867 + if (!special_file(mode))
31868 + au_dpri_file(file);
31870 + hlist_bl_unlock(files);
31874 + au_plevel = plevel;
31877 +/* ---------------------------------------------------------------------- */
31879 +/* module parameter */
31880 +static char *aufs_sysrq_key = "a";
31881 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31882 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31884 +static void au_sysrq(int key __maybe_unused)
31886 + struct au_sbinfo *sbinfo;
31887 + struct hlist_bl_node *pos;
31890 + au_sbilist_lock();
31891 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31892 + sysrq_sb(sbinfo->si_sb);
31893 + au_sbilist_unlock();
31897 +static struct sysrq_key_op au_sysrq_op = {
31898 + .handler = au_sysrq,
31899 + .help_msg = "Aufs",
31900 + .action_msg = "Aufs",
31901 + .enable_mask = SYSRQ_ENABLE_DUMP
31904 +/* ---------------------------------------------------------------------- */
31906 +int __init au_sysrq_init(void)
31912 + key = *aufs_sysrq_key;
31913 + if ('a' <= key && key <= 'z')
31914 + err = register_sysrq_key(key, &au_sysrq_op);
31915 + if (unlikely(err))
31916 + pr_err("err %d, sysrq=%c\n", err, key);
31920 +void au_sysrq_fin(void)
31924 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31925 + if (unlikely(err))
31926 + pr_err("err %d (ignored)\n", err);
31928 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31929 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31930 +++ linux/fs/aufs/vdir.c 2019-03-05 12:13:00.145891204 +0100
31932 +// SPDX-License-Identifier: GPL-2.0
31934 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31936 + * This program, aufs is free software; you can redistribute it and/or modify
31937 + * it under the terms of the GNU General Public License as published by
31938 + * the Free Software Foundation; either version 2 of the License, or
31939 + * (at your option) any later version.
31941 + * This program is distributed in the hope that it will be useful,
31942 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31943 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31944 + * GNU General Public License for more details.
31946 + * You should have received a copy of the GNU General Public License
31947 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31951 + * virtual or vertical directory
31956 +static unsigned int calc_size(int nlen)
31958 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31961 +static int set_deblk_end(union au_vdir_deblk_p *p,
31962 + union au_vdir_deblk_p *deblk_end)
31964 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31965 + p->de->de_str.len = 0;
31969 + return -1; /* error */
31972 +/* returns true or false */
31973 +static int is_deblk_end(union au_vdir_deblk_p *p,
31974 + union au_vdir_deblk_p *deblk_end)
31976 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31977 + return !p->de->de_str.len;
31981 +static unsigned char *last_deblk(struct au_vdir *vdir)
31983 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31986 +/* ---------------------------------------------------------------------- */
31988 +/* estimate the appropriate size for name hash table */
31989 +unsigned int au_rdhash_est(loff_t sz)
31997 + if (sz < AUFS_RDHASH_DEF)
31998 + n = AUFS_RDHASH_DEF;
31999 + /* pr_info("n %u\n", n); */
32004 + * the allocated memory has to be freed by
32005 + * au_nhash_wh_free() or au_nhash_de_free().
32007 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
32009 + struct hlist_head *head;
32013 + sz = sizeof(*nhash->nh_head) * num_hash;
32014 + head = kmalloc(sz, gfp);
32016 + nhash->nh_num = num_hash;
32017 + nhash->nh_head = head;
32018 + for (u = 0; u < num_hash; u++)
32019 + INIT_HLIST_HEAD(head++);
32020 + return 0; /* success */
32026 +static void nhash_count(struct hlist_head *head)
32030 + struct hlist_node *pos;
32033 + hlist_for_each(pos, head)
32035 + pr_info("%lu\n", n);
32039 +static void au_nhash_wh_do_free(struct hlist_head *head)
32041 + struct au_vdir_wh *pos;
32042 + struct hlist_node *node;
32044 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
32045 + au_kfree_rcu(pos);
32048 +static void au_nhash_de_do_free(struct hlist_head *head)
32050 + struct au_vdir_dehstr *pos;
32051 + struct hlist_node *node;
32053 + hlist_for_each_entry_safe(pos, node, head, hash)
32054 + au_cache_free_vdir_dehstr(pos);
32057 +static void au_nhash_do_free(struct au_nhash *nhash,
32058 + void (*free)(struct hlist_head *head))
32061 + struct hlist_head *head;
32063 + n = nhash->nh_num;
32067 + head = nhash->nh_head;
32068 + while (n-- > 0) {
32069 + nhash_count(head);
32072 + au_kfree_try_rcu(nhash->nh_head);
32075 +void au_nhash_wh_free(struct au_nhash *whlist)
32077 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
32080 +static void au_nhash_de_free(struct au_nhash *delist)
32082 + au_nhash_do_free(delist, au_nhash_de_do_free);
32085 +/* ---------------------------------------------------------------------- */
32087 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
32091 + unsigned int u, n;
32092 + struct hlist_head *head;
32093 + struct au_vdir_wh *pos;
32096 + n = whlist->nh_num;
32097 + head = whlist->nh_head;
32098 + for (u = 0; u < n; u++, head++)
32099 + hlist_for_each_entry(pos, head, wh_hash)
32100 + if (pos->wh_bindex == btgt && ++num > limit)
32105 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
32106 + unsigned char *name,
32107 + unsigned int len)
32110 + /* const unsigned int magic_bit = 12; */
32112 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32119 + /* v = hash_long(v, magic_bit); */
32120 + v %= nhash->nh_num;
32121 + return nhash->nh_head + v;
32124 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32127 + return str->len == nlen && !memcmp(str->name, name, nlen);
32130 +/* returns found or not */
32131 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32133 + struct hlist_head *head;
32134 + struct au_vdir_wh *pos;
32135 + struct au_vdir_destr *str;
32137 + head = au_name_hash(whlist, name, nlen);
32138 + hlist_for_each_entry(pos, head, wh_hash) {
32139 + str = &pos->wh_str;
32140 + AuDbg("%.*s\n", str->len, str->name);
32141 + if (au_nhash_test_name(str, name, nlen))
32147 +/* returns found(true) or not */
32148 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32150 + struct hlist_head *head;
32151 + struct au_vdir_dehstr *pos;
32152 + struct au_vdir_destr *str;
32154 + head = au_name_hash(delist, name, nlen);
32155 + hlist_for_each_entry(pos, head, hash) {
32157 + AuDbg("%.*s\n", str->len, str->name);
32158 + if (au_nhash_test_name(str, name, nlen))
32164 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32165 + unsigned char d_type)
32167 +#ifdef CONFIG_AUFS_SHWH
32168 + wh->wh_ino = ino;
32169 + wh->wh_type = d_type;
32173 +/* ---------------------------------------------------------------------- */
32175 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32176 + unsigned int d_type, aufs_bindex_t bindex,
32177 + unsigned char shwh)
32180 + struct au_vdir_destr *str;
32181 + struct au_vdir_wh *wh;
32183 + AuDbg("%.*s\n", nlen, name);
32184 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32187 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32188 + if (unlikely(!wh))
32192 + wh->wh_bindex = bindex;
32194 + au_shwh_init_wh(wh, ino, d_type);
32195 + str = &wh->wh_str;
32197 + memcpy(str->name, name, nlen);
32198 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32205 +static int append_deblk(struct au_vdir *vdir)
32208 + unsigned long ul;
32209 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32210 + union au_vdir_deblk_p p, deblk_end;
32211 + unsigned char **o;
32214 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32215 + GFP_NOFS, /*may_shrink*/0);
32216 + if (unlikely(!o))
32219 + vdir->vd_deblk = o;
32220 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32222 + ul = vdir->vd_nblk++;
32223 + vdir->vd_deblk[ul] = p.deblk;
32224 + vdir->vd_last.ul = ul;
32225 + vdir->vd_last.p.deblk = p.deblk;
32226 + deblk_end.deblk = p.deblk + deblk_sz;
32227 + err = set_deblk_end(&p, &deblk_end);
32234 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32235 + unsigned int d_type, struct au_nhash *delist)
32239 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32240 + union au_vdir_deblk_p p, *room, deblk_end;
32241 + struct au_vdir_dehstr *dehstr;
32243 + p.deblk = last_deblk(vdir);
32244 + deblk_end.deblk = p.deblk + deblk_sz;
32245 + room = &vdir->vd_last.p;
32246 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32247 + || !is_deblk_end(room, &deblk_end));
32249 + sz = calc_size(nlen);
32250 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32251 + err = append_deblk(vdir);
32252 + if (unlikely(err))
32255 + p.deblk = last_deblk(vdir);
32256 + deblk_end.deblk = p.deblk + deblk_sz;
32258 + AuDebugOn(room->deblk != p.deblk);
32262 + dehstr = au_cache_alloc_vdir_dehstr();
32263 + if (unlikely(!dehstr))
32266 + dehstr->str = &room->de->de_str;
32267 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32268 + room->de->de_ino = ino;
32269 + room->de->de_type = d_type;
32270 + room->de->de_str.len = nlen;
32271 + memcpy(room->de->de_str.name, name, nlen);
32274 + room->deblk += sz;
32275 + if (unlikely(set_deblk_end(room, &deblk_end)))
32276 + err = append_deblk(vdir);
32283 +/* ---------------------------------------------------------------------- */
32285 +void au_vdir_free(struct au_vdir *vdir)
32287 + unsigned char **deblk;
32289 + deblk = vdir->vd_deblk;
32290 + while (vdir->vd_nblk--)
32291 + au_kfree_try_rcu(*deblk++);
32292 + au_kfree_try_rcu(vdir->vd_deblk);
32293 + au_cache_free_vdir(vdir);
32296 +static struct au_vdir *alloc_vdir(struct file *file)
32298 + struct au_vdir *vdir;
32299 + struct super_block *sb;
32302 + sb = file->f_path.dentry->d_sb;
32303 + SiMustAnyLock(sb);
32306 + vdir = au_cache_alloc_vdir();
32307 + if (unlikely(!vdir))
32310 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32311 + if (unlikely(!vdir->vd_deblk))
32314 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32315 + if (!vdir->vd_deblk_sz) {
32316 + /* estimate the appropriate size for deblk */
32317 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32318 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32320 + vdir->vd_nblk = 0;
32321 + vdir->vd_version = 0;
32322 + vdir->vd_jiffy = 0;
32323 + err = append_deblk(vdir);
32325 + return vdir; /* success */
32327 + au_kfree_try_rcu(vdir->vd_deblk);
32330 + au_cache_free_vdir(vdir);
32332 + vdir = ERR_PTR(err);
32336 +static int reinit_vdir(struct au_vdir *vdir)
32339 + union au_vdir_deblk_p p, deblk_end;
32341 + while (vdir->vd_nblk > 1) {
32342 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32343 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32346 + p.deblk = vdir->vd_deblk[0];
32347 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32348 + err = set_deblk_end(&p, &deblk_end);
32349 + /* keep vd_dblk_sz */
32350 + vdir->vd_last.ul = 0;
32351 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32352 + vdir->vd_version = 0;
32353 + vdir->vd_jiffy = 0;
32358 +/* ---------------------------------------------------------------------- */
32360 +#define AuFillVdir_CALLED 1
32361 +#define AuFillVdir_WHABLE (1 << 1)
32362 +#define AuFillVdir_SHWH (1 << 2)
32363 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32364 +#define au_fset_fillvdir(flags, name) \
32365 + do { (flags) |= AuFillVdir_##name; } while (0)
32366 +#define au_fclr_fillvdir(flags, name) \
32367 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32369 +#ifndef CONFIG_AUFS_SHWH
32370 +#undef AuFillVdir_SHWH
32371 +#define AuFillVdir_SHWH 0
32374 +struct fillvdir_arg {
32375 + struct dir_context ctx;
32376 + struct file *file;
32377 + struct au_vdir *vdir;
32378 + struct au_nhash delist;
32379 + struct au_nhash whlist;
32380 + aufs_bindex_t bindex;
32381 + unsigned int flags;
32385 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32386 + loff_t offset __maybe_unused, u64 h_ino,
32387 + unsigned int d_type)
32389 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32390 + char *name = (void *)__name;
32391 + struct super_block *sb;
32393 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32396 + sb = arg->file->f_path.dentry->d_sb;
32397 + au_fset_fillvdir(arg->flags, CALLED);
32399 + if (nlen <= AUFS_WH_PFX_LEN
32400 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32401 + if (test_known(&arg->delist, name, nlen)
32402 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32403 + goto out; /* already exists or whiteouted */
32405 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32407 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32408 + d_type = DT_UNKNOWN;
32409 + arg->err = append_de(arg->vdir, name, nlen, ino,
32410 + d_type, &arg->delist);
32412 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32413 + name += AUFS_WH_PFX_LEN;
32414 + nlen -= AUFS_WH_PFX_LEN;
32415 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32416 + goto out; /* already whiteouted */
32418 + ino = 0; /* just to suppress a warning */
32420 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32423 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32424 + d_type = DT_UNKNOWN;
32425 + arg->err = au_nhash_append_wh
32426 + (&arg->whlist, name, nlen, ino, d_type,
32427 + arg->bindex, shwh);
32433 + arg->vdir->vd_jiffy = jiffies;
32435 + AuTraceErr(arg->err);
32439 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32440 + struct au_nhash *whlist, struct au_nhash *delist)
32442 +#ifdef CONFIG_AUFS_SHWH
32444 + unsigned int nh, u;
32445 + struct hlist_head *head;
32446 + struct au_vdir_wh *pos;
32447 + struct hlist_node *n;
32449 + struct au_vdir_destr *destr;
32451 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32454 + o = p = (void *)__get_free_page(GFP_NOFS);
32455 + if (unlikely(!p))
32459 + nh = whlist->nh_num;
32460 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32461 + p += AUFS_WH_PFX_LEN;
32462 + for (u = 0; u < nh; u++) {
32463 + head = whlist->nh_head + u;
32464 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32465 + destr = &pos->wh_str;
32466 + memcpy(p, destr->name, destr->len);
32467 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32468 + pos->wh_ino, pos->wh_type, delist);
32469 + if (unlikely(err))
32474 + free_page((unsigned long)o);
32484 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32487 + unsigned int rdhash;
32489 + aufs_bindex_t bbot, bindex, btop;
32490 + unsigned char shwh;
32491 + struct file *hf, *file;
32492 + struct super_block *sb;
32494 + file = arg->file;
32495 + sb = file->f_path.dentry->d_sb;
32496 + SiMustAnyLock(sb);
32498 + rdhash = au_sbi(sb)->si_rdhash;
32500 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32501 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32502 + if (unlikely(err))
32504 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32505 + if (unlikely(err))
32511 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32513 + au_fset_fillvdir(arg->flags, SHWH);
32515 + btop = au_fbtop(file);
32516 + bbot = au_fbbot_dir(file);
32517 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32518 + hf = au_hf_dir(file, bindex);
32522 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32524 + if (unlikely(offset))
32527 + arg->bindex = bindex;
32528 + au_fclr_fillvdir(arg->flags, WHABLE);
32530 + || (bindex != bbot
32531 + && au_br_whable(au_sbr_perm(sb, bindex))))
32532 + au_fset_fillvdir(arg->flags, WHABLE);
32535 + au_fclr_fillvdir(arg->flags, CALLED);
32537 + err = vfsub_iterate_dir(hf, &arg->ctx);
32540 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32543 + * dir_relax() may be good for concurrency, but aufs should not
32544 + * use it since it will cause a lockdep problem.
32548 + if (!err && shwh)
32549 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32551 + au_nhash_wh_free(&arg->whlist);
32554 + au_nhash_de_free(&arg->delist);
32559 +static int read_vdir(struct file *file, int may_read)
32562 + unsigned long expire;
32563 + unsigned char do_read;
32564 + struct fillvdir_arg arg = {
32566 + .actor = fillvdir
32569 + struct inode *inode;
32570 + struct au_vdir *vdir, *allocated;
32573 + inode = file_inode(file);
32574 + IMustLock(inode);
32575 + IiMustWriteLock(inode);
32576 + SiMustAnyLock(inode->i_sb);
32578 + allocated = NULL;
32580 + expire = au_sbi(inode->i_sb)->si_rdcache;
32581 + vdir = au_ivdir(inode);
32584 + vdir = alloc_vdir(file);
32585 + err = PTR_ERR(vdir);
32586 + if (IS_ERR(vdir))
32589 + allocated = vdir;
32590 + } else if (may_read
32591 + && (!inode_eq_iversion(inode, vdir->vd_version)
32592 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32594 + err = reinit_vdir(vdir);
32595 + if (unlikely(err))
32600 + return 0; /* success */
32604 + err = au_do_read_vdir(&arg);
32606 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32607 + vdir->vd_version = inode_query_iversion(inode);
32608 + vdir->vd_last.ul = 0;
32609 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32611 + au_set_ivdir(inode, allocated);
32612 + } else if (allocated)
32613 + au_vdir_free(allocated);
32619 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32622 + unsigned long ul, n;
32623 + const unsigned int deblk_sz = src->vd_deblk_sz;
32625 + AuDebugOn(tgt->vd_nblk != 1);
32628 + if (tgt->vd_nblk < src->vd_nblk) {
32629 + unsigned char **p;
32631 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32632 + GFP_NOFS, /*may_shrink*/0);
32633 + if (unlikely(!p))
32635 + tgt->vd_deblk = p;
32638 + if (tgt->vd_deblk_sz != deblk_sz) {
32639 + unsigned char *p;
32641 + tgt->vd_deblk_sz = deblk_sz;
32642 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32643 + /*may_shrink*/1);
32644 + if (unlikely(!p))
32646 + tgt->vd_deblk[0] = p;
32648 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32649 + tgt->vd_version = src->vd_version;
32650 + tgt->vd_jiffy = src->vd_jiffy;
32652 + n = src->vd_nblk;
32653 + for (ul = 1; ul < n; ul++) {
32654 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32656 + if (unlikely(!tgt->vd_deblk[ul]))
32660 + tgt->vd_nblk = n;
32661 + tgt->vd_last.ul = tgt->vd_last.ul;
32662 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32663 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32664 + - src->vd_deblk[src->vd_last.ul];
32666 + return 0; /* success */
32669 + rerr = reinit_vdir(tgt);
32674 +int au_vdir_init(struct file *file)
32677 + struct inode *inode;
32678 + struct au_vdir *vdir_cache, *allocated;
32680 + /* test file->f_pos here instead of ctx->pos */
32681 + err = read_vdir(file, !file->f_pos);
32682 + if (unlikely(err))
32685 + allocated = NULL;
32686 + vdir_cache = au_fvdir_cache(file);
32687 + if (!vdir_cache) {
32688 + vdir_cache = alloc_vdir(file);
32689 + err = PTR_ERR(vdir_cache);
32690 + if (IS_ERR(vdir_cache))
32692 + allocated = vdir_cache;
32693 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32694 + /* test file->f_pos here instead of ctx->pos */
32695 + err = reinit_vdir(vdir_cache);
32696 + if (unlikely(err))
32699 + return 0; /* success */
32701 + inode = file_inode(file);
32702 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32704 + file->f_version = inode_query_iversion(inode);
32706 + au_set_fvdir_cache(file, allocated);
32707 + } else if (allocated)
32708 + au_vdir_free(allocated);
32714 +static loff_t calc_offset(struct au_vdir *vdir)
32717 + union au_vdir_deblk_p p;
32719 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32720 + offset = vdir->vd_last.p.deblk - p.deblk;
32721 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32725 +/* returns true or false */
32726 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32729 + unsigned int deblk_sz;
32730 + unsigned long ul, n;
32732 + union au_vdir_deblk_p p, deblk_end;
32733 + struct au_vdir *vdir_cache;
32736 + vdir_cache = au_fvdir_cache(file);
32737 + offset = calc_offset(vdir_cache);
32738 + AuDbg("offset %lld\n", offset);
32739 + if (ctx->pos == offset)
32742 + vdir_cache->vd_last.ul = 0;
32743 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32748 + deblk_sz = vdir_cache->vd_deblk_sz;
32749 + ul = div64_u64(ctx->pos, deblk_sz);
32750 + AuDbg("ul %lu\n", ul);
32751 + if (ul >= vdir_cache->vd_nblk)
32754 + n = vdir_cache->vd_nblk;
32755 + for (; ul < n; ul++) {
32756 + p.deblk = vdir_cache->vd_deblk[ul];
32757 + deblk_end.deblk = p.deblk + deblk_sz;
32759 + offset *= deblk_sz;
32760 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32763 + l = calc_size(p.de->de_str.len);
32767 + if (!is_deblk_end(&p, &deblk_end)) {
32769 + vdir_cache->vd_last.ul = ul;
32770 + vdir_cache->vd_last.p = p;
32778 + AuDbg("valid %d\n", !valid);
32782 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32784 + unsigned int l, deblk_sz;
32785 + union au_vdir_deblk_p deblk_end;
32786 + struct au_vdir *vdir_cache;
32787 + struct au_vdir_de *de;
32789 + if (!seek_vdir(file, ctx))
32792 + vdir_cache = au_fvdir_cache(file);
32793 + deblk_sz = vdir_cache->vd_deblk_sz;
32795 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32796 + deblk_end.deblk += deblk_sz;
32797 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32798 + de = vdir_cache->vd_last.p.de;
32799 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32800 + de->de_str.len, de->de_str.name, ctx->pos,
32801 + (unsigned long)de->de_ino, de->de_type);
32802 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32803 + de->de_str.len, de->de_ino,
32805 + /* todo: ignore the error caused by udba? */
32806 + /* return err; */
32810 + l = calc_size(de->de_str.len);
32811 + vdir_cache->vd_last.p.deblk += l;
32814 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32815 + vdir_cache->vd_last.ul++;
32816 + vdir_cache->vd_last.p.deblk
32817 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32818 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32827 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32828 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32829 +++ linux/fs/aufs/vfsub.c 2019-03-05 12:13:00.145891204 +0100
32831 +// SPDX-License-Identifier: GPL-2.0
32833 + * Copyright (C) 2005-2019 Junjiro R. Okajima
32835 + * This program, aufs is free software; you can redistribute it and/or modify
32836 + * it under the terms of the GNU General Public License as published by
32837 + * the Free Software Foundation; either version 2 of the License, or
32838 + * (at your option) any later version.
32840 + * This program is distributed in the hope that it will be useful,
32841 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32842 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32843 + * GNU General Public License for more details.
32845 + * You should have received a copy of the GNU General Public License
32846 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32850 + * sub-routines for VFS
32853 +#include <linux/mnt_namespace.h>
32854 +#include <linux/namei.h>
32855 +#include <linux/nsproxy.h>
32856 +#include <linux/security.h>
32857 +#include <linux/splice.h>
32860 +#ifdef CONFIG_AUFS_BR_FUSE
32861 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32863 + if (!au_test_fuse(h_sb) || !au_userns)
32866 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32870 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32875 + down_read(&h_sb->s_umount);
32876 + err = __sync_filesystem(h_sb, wait);
32877 + up_read(&h_sb->s_umount);
32883 +/* ---------------------------------------------------------------------- */
32885 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32889 + struct super_block *h_sb;
32891 + /* for remote fs, leave work for its getattr or d_revalidate */
32892 + /* for bad i_attr fs, handle them in aufs_getattr() */
32893 + /* still some fs may acquire i_mutex. we need to skip them */
32897 + h_sb = h_path->dentry->d_sb;
32898 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32900 + err = vfsub_getattr(h_path, &st);
32905 +/* ---------------------------------------------------------------------- */
32907 +struct file *vfsub_dentry_open(struct path *path, int flags)
32909 + struct file *file;
32911 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32913 + if (!IS_ERR_OR_NULL(file)
32914 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
32915 + i_readcount_inc(d_inode(path->dentry));
32920 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32922 + struct file *file;
32925 + file = filp_open(path,
32926 + oflags /* | __FMODE_NONOTIFY */,
32929 + if (IS_ERR(file))
32931 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32938 + * Ideally this function should call VFS:do_last() in order to keep all its
32939 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32940 + * structure such as nameidata. This is a second (or third) best approach.
32941 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32943 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32944 + struct vfsub_aopen_args *args)
32947 + struct au_branch *br = args->br;
32948 + struct file *file = args->file;
32949 + /* copied from linux/fs/namei.c:atomic_open() */
32950 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32953 + AuDebugOn(!dir->i_op->atomic_open);
32955 + err = au_br_test_oflag(args->open_flag, br);
32956 + if (unlikely(err))
32959 + au_lcnt_inc(&br->br_nfiles);
32960 + file->f_path.dentry = DENTRY_NOT_SET;
32961 + file->f_path.mnt = au_br_mnt(br);
32962 + AuDbg("%ps\n", dir->i_op->atomic_open);
32963 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32964 + args->create_mode);
32965 + if (unlikely(err < 0)) {
32966 + au_lcnt_dec(&br->br_nfiles);
32970 + /* temporary workaround for nfsv4 branch */
32971 + if (au_test_nfs(dir->i_sb))
32972 + nfs_mark_for_revalidate(dir);
32974 + if (file->f_mode & FMODE_CREATED)
32975 + fsnotify_create(dir, dentry);
32976 + if (!(file->f_mode & FMODE_OPENED)) {
32977 + au_lcnt_dec(&br->br_nfiles);
32981 + /* todo: call VFS:may_open() here */
32982 + /* todo: ima_file_check() too? */
32983 + if (!err && (args->open_flag & __FMODE_EXEC))
32984 + err = deny_write_access(file);
32986 + fsnotify_open(file);
32988 + au_lcnt_dec(&br->br_nfiles);
32989 + /* note that the file is created and still opened */
32995 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32999 + err = kern_path(name, flags, path);
33000 + if (!err && d_is_positive(path->dentry))
33001 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33005 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33006 + struct dentry *parent, int len)
33008 + struct path path = {
33012 + path.dentry = lookup_one_len_unlocked(name, parent, len);
33013 + if (IS_ERR(path.dentry))
33015 + if (d_is_positive(path.dentry))
33016 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33019 + AuTraceErrPtr(path.dentry);
33020 + return path.dentry;
33023 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33026 + struct path path = {
33030 + /* VFS checks it too, but by WARN_ON_ONCE() */
33031 + IMustLock(d_inode(parent));
33033 + path.dentry = lookup_one_len(name, parent, len);
33034 + if (IS_ERR(path.dentry))
33036 + if (d_is_positive(path.dentry))
33037 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33040 + AuTraceErrPtr(path.dentry);
33041 + return path.dentry;
33044 +void vfsub_call_lkup_one(void *args)
33046 + struct vfsub_lkup_one_args *a = args;
33047 + *a->errp = vfsub_lkup_one(a->name, a->parent);
33050 +/* ---------------------------------------------------------------------- */
33052 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33053 + struct dentry *d2, struct au_hinode *hdir2)
33055 + struct dentry *d;
33058 + d = lock_rename(d1, d2);
33060 + au_hn_suspend(hdir1);
33061 + if (hdir1 != hdir2)
33062 + au_hn_suspend(hdir2);
33067 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33068 + struct dentry *d2, struct au_hinode *hdir2)
33070 + au_hn_resume(hdir1);
33071 + if (hdir1 != hdir2)
33072 + au_hn_resume(hdir2);
33074 + unlock_rename(d1, d2);
33078 +/* ---------------------------------------------------------------------- */
33080 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
33083 + struct dentry *d;
33087 + d = path->dentry;
33088 + path->dentry = d->d_parent;
33089 + err = security_path_mknod(path, d, mode, 0);
33090 + path->dentry = d;
33091 + if (unlikely(err))
33095 + err = vfs_create(dir, path->dentry, mode, want_excl);
33098 + struct path tmp = *path;
33101 + vfsub_update_h_iattr(&tmp, &did);
33103 + tmp.dentry = path->dentry->d_parent;
33104 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33113 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33116 + struct dentry *d;
33120 + d = path->dentry;
33121 + path->dentry = d->d_parent;
33122 + err = security_path_symlink(path, d, symname);
33123 + path->dentry = d;
33124 + if (unlikely(err))
33128 + err = vfs_symlink(dir, path->dentry, symname);
33131 + struct path tmp = *path;
33134 + vfsub_update_h_iattr(&tmp, &did);
33136 + tmp.dentry = path->dentry->d_parent;
33137 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33146 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33149 + struct dentry *d;
33153 + d = path->dentry;
33154 + path->dentry = d->d_parent;
33155 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33156 + path->dentry = d;
33157 + if (unlikely(err))
33161 + err = vfs_mknod(dir, path->dentry, mode, dev);
33164 + struct path tmp = *path;
33167 + vfsub_update_h_iattr(&tmp, &did);
33169 + tmp.dentry = path->dentry->d_parent;
33170 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33179 +static int au_test_nlink(struct inode *inode)
33181 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33183 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33184 + || inode->i_nlink < link_max)
33189 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33190 + struct inode **delegated_inode)
33193 + struct dentry *d;
33197 + err = au_test_nlink(d_inode(src_dentry));
33198 + if (unlikely(err))
33201 + /* we don't call may_linkat() */
33202 + d = path->dentry;
33203 + path->dentry = d->d_parent;
33204 + err = security_path_link(src_dentry, path, d);
33205 + path->dentry = d;
33206 + if (unlikely(err))
33210 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
33213 + struct path tmp = *path;
33216 + /* fuse has different memory inode for the same inumber */
33217 + vfsub_update_h_iattr(&tmp, &did);
33219 + tmp.dentry = path->dentry->d_parent;
33220 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33221 + tmp.dentry = src_dentry;
33222 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33231 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33232 + struct inode *dir, struct path *path,
33233 + struct inode **delegated_inode, unsigned int flags)
33236 + struct path tmp = {
33239 + struct dentry *d;
33242 + IMustLock(src_dir);
33244 + d = path->dentry;
33245 + path->dentry = d->d_parent;
33246 + tmp.dentry = src_dentry->d_parent;
33247 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33248 + path->dentry = d;
33249 + if (unlikely(err))
33253 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
33254 + delegated_inode, flags);
33259 + tmp.dentry = d->d_parent;
33260 + vfsub_update_h_iattr(&tmp, &did);
33262 + tmp.dentry = src_dentry;
33263 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33264 + tmp.dentry = src_dentry->d_parent;
33265 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33274 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33277 + struct dentry *d;
33281 + d = path->dentry;
33282 + path->dentry = d->d_parent;
33283 + err = security_path_mkdir(path, d, mode);
33284 + path->dentry = d;
33285 + if (unlikely(err))
33289 + err = vfs_mkdir(dir, path->dentry, mode);
33292 + struct path tmp = *path;
33295 + vfsub_update_h_iattr(&tmp, &did);
33297 + tmp.dentry = path->dentry->d_parent;
33298 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33307 +int vfsub_rmdir(struct inode *dir, struct path *path)
33310 + struct dentry *d;
33314 + d = path->dentry;
33315 + path->dentry = d->d_parent;
33316 + err = security_path_rmdir(path, d);
33317 + path->dentry = d;
33318 + if (unlikely(err))
33322 + err = vfs_rmdir(dir, path->dentry);
33325 + struct path tmp = {
33326 + .dentry = path->dentry->d_parent,
33330 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33337 +/* ---------------------------------------------------------------------- */
33339 +/* todo: support mmap_sem? */
33340 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33346 + err = vfs_read(file, ubuf, count, ppos);
33349 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33353 +/* todo: kernel_read()? */
33354 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33358 + mm_segment_t oldfs;
33365 + oldfs = get_fs();
33366 + set_fs(KERNEL_DS);
33367 + err = vfsub_read_u(file, buf.u, count, ppos);
33372 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33378 + err = vfs_write(file, ubuf, count, ppos);
33381 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33385 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33388 + mm_segment_t oldfs;
33391 + const char __user *u;
33395 + oldfs = get_fs();
33396 + set_fs(KERNEL_DS);
33397 + err = vfsub_write_u(file, buf.u, count, ppos);
33402 +int vfsub_flush(struct file *file, fl_owner_t id)
33407 + if (file->f_op->flush) {
33408 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33409 + err = file->f_op->flush(file, id);
33412 + err = file->f_op->flush(file, id);
33416 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33422 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33426 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33429 + err = iterate_dir(file, ctx);
33432 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33437 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33438 + struct pipe_inode_info *pipe, size_t len,
33439 + unsigned int flags)
33444 + err = do_splice_to(in, ppos, pipe, len, flags);
33446 + file_accessed(in);
33448 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33452 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33453 + loff_t *ppos, size_t len, unsigned int flags)
33458 + err = do_splice_from(pipe, out, ppos, len, flags);
33461 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33465 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33469 + /* file can be NULL */
33471 + err = vfs_fsync(file, datasync);
33475 + AuDebugOn(!file);
33476 + path = &file->f_path;
33478 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33483 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33484 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33485 + struct file *h_file)
33488 + struct inode *h_inode;
33489 + struct super_block *h_sb;
33492 + err = vfsub_truncate(h_path, length);
33496 + h_inode = d_inode(h_path->dentry);
33497 + h_sb = h_inode->i_sb;
33499 + sb_start_write(h_sb);
33501 + err = locks_verify_truncate(h_inode, h_file, length);
33503 + err = security_path_truncate(h_path);
33506 + err = do_truncate(h_path->dentry, length, attr, h_file);
33510 + sb_end_write(h_sb);
33517 +/* ---------------------------------------------------------------------- */
33519 +struct au_vfsub_mkdir_args {
33521 + struct inode *dir;
33522 + struct path *path;
33526 +static void au_call_vfsub_mkdir(void *args)
33528 + struct au_vfsub_mkdir_args *a = args;
33529 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33532 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33534 + int err, do_sio, wkq_err;
33536 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33539 + err = vfsub_mkdir(dir, path, mode);
33542 + struct au_vfsub_mkdir_args args = {
33548 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33549 + if (unlikely(wkq_err))
33556 +struct au_vfsub_rmdir_args {
33558 + struct inode *dir;
33559 + struct path *path;
33562 +static void au_call_vfsub_rmdir(void *args)
33564 + struct au_vfsub_rmdir_args *a = args;
33565 + *a->errp = vfsub_rmdir(a->dir, a->path);
33568 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33570 + int err, do_sio, wkq_err;
33572 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33575 + err = vfsub_rmdir(dir, path);
33578 + struct au_vfsub_rmdir_args args = {
33583 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33584 + if (unlikely(wkq_err))
33591 +/* ---------------------------------------------------------------------- */
33593 +struct notify_change_args {
33595 + struct path *path;
33596 + struct iattr *ia;
33597 + struct inode **delegated_inode;
33600 +static void call_notify_change(void *args)
33602 + struct notify_change_args *a = args;
33603 + struct inode *h_inode;
33605 + h_inode = d_inode(a->path->dentry);
33606 + IMustLock(h_inode);
33608 + *a->errp = -EPERM;
33609 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33611 + *a->errp = notify_change(a->path->dentry, a->ia,
33612 + a->delegated_inode);
33615 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33617 + AuTraceErr(*a->errp);
33620 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33621 + struct inode **delegated_inode)
33624 + struct notify_change_args args = {
33628 + .delegated_inode = delegated_inode
33631 + call_notify_change(&args);
33636 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33637 + struct inode **delegated_inode)
33639 + int err, wkq_err;
33640 + struct notify_change_args args = {
33644 + .delegated_inode = delegated_inode
33647 + wkq_err = au_wkq_wait(call_notify_change, &args);
33648 + if (unlikely(wkq_err))
33654 +/* ---------------------------------------------------------------------- */
33656 +struct unlink_args {
33658 + struct inode *dir;
33659 + struct path *path;
33660 + struct inode **delegated_inode;
33663 +static void call_unlink(void *args)
33665 + struct unlink_args *a = args;
33666 + struct dentry *d = a->path->dentry;
33667 + struct inode *h_inode;
33668 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33669 + && au_dcount(d) == 1);
33671 + IMustLock(a->dir);
33673 + a->path->dentry = d->d_parent;
33674 + *a->errp = security_path_unlink(a->path, d);
33675 + a->path->dentry = d;
33676 + if (unlikely(*a->errp))
33679 + if (!stop_sillyrename)
33682 + if (d_is_positive(d)) {
33683 + h_inode = d_inode(d);
33688 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33691 + struct path tmp = {
33692 + .dentry = d->d_parent,
33693 + .mnt = a->path->mnt
33695 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33698 + if (!stop_sillyrename)
33703 + AuTraceErr(*a->errp);
33707 + * @dir: must be locked.
33708 + * @dentry: target dentry.
33710 +int vfsub_unlink(struct inode *dir, struct path *path,
33711 + struct inode **delegated_inode, int force)
33714 + struct unlink_args args = {
33718 + .delegated_inode = delegated_inode
33722 + call_unlink(&args);
33726 + wkq_err = au_wkq_wait(call_unlink, &args);
33727 + if (unlikely(wkq_err))
33733 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33734 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33735 +++ linux/fs/aufs/vfsub.h 2019-03-05 12:13:00.145891204 +0100
33737 +/* SPDX-License-Identifier: GPL-2.0 */
33739 + * Copyright (C) 2005-2019 Junjiro R. Okajima
33741 + * This program, aufs is free software; you can redistribute it and/or modify
33742 + * it under the terms of the GNU General Public License as published by
33743 + * the Free Software Foundation; either version 2 of the License, or
33744 + * (at your option) any later version.
33746 + * This program is distributed in the hope that it will be useful,
33747 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33748 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33749 + * GNU General Public License for more details.
33751 + * You should have received a copy of the GNU General Public License
33752 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33756 + * sub-routines for VFS
33759 +#ifndef __AUFS_VFSUB_H__
33760 +#define __AUFS_VFSUB_H__
33764 +#include <linux/fs.h>
33765 +#include <linux/iversion.h>
33766 +#include <linux/mount.h>
33767 +#include <linux/posix_acl.h>
33768 +#include <linux/xattr.h>
33769 +#include "debug.h"
33771 +/* copied from linux/fs/internal.h */
33772 +/* todo: BAD approach!! */
33773 +extern void __mnt_drop_write(struct vfsmount *);
33774 +extern struct file *alloc_empty_file(int, const struct cred *);
33776 +/* ---------------------------------------------------------------------- */
33778 +/* lock subclass for lower inode */
33779 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33780 +/* reduce? gave up. */
33782 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33783 + AuLsc_I_PARENT, /* lower inode, parent first */
33784 + AuLsc_I_PARENT2, /* copyup dirs */
33785 + AuLsc_I_PARENT3, /* copyup wh */
33791 +/* to debug easier, do not make them inlined functions */
33792 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33793 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33795 +/* ---------------------------------------------------------------------- */
33797 +static inline void vfsub_drop_nlink(struct inode *inode)
33799 + AuDebugOn(!inode->i_nlink);
33800 + drop_nlink(inode);
33803 +static inline void vfsub_dead_dir(struct inode *inode)
33805 + AuDebugOn(!S_ISDIR(inode->i_mode));
33806 + inode->i_flags |= S_DEAD;
33807 + clear_nlink(inode);
33810 +static inline int vfsub_native_ro(struct inode *inode)
33812 + return sb_rdonly(inode->i_sb)
33813 + || IS_RDONLY(inode)
33814 + /* || IS_APPEND(inode) */
33815 + || IS_IMMUTABLE(inode);
33818 +#ifdef CONFIG_AUFS_BR_FUSE
33819 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33821 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33824 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33826 +/* ---------------------------------------------------------------------- */
33828 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33829 +struct file *vfsub_dentry_open(struct path *path, int flags);
33830 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33832 +struct vfsub_aopen_args {
33833 + struct file *file;
33834 + unsigned int open_flag;
33835 + umode_t create_mode;
33836 + struct au_branch *br;
33838 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33839 + struct vfsub_aopen_args *args);
33840 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33842 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33843 + struct dentry *parent, int len);
33844 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33847 +struct vfsub_lkup_one_args {
33848 + struct dentry **errp;
33849 + struct qstr *name;
33850 + struct dentry *parent;
33853 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33854 + struct dentry *parent)
33856 + return vfsub_lookup_one_len(name->name, parent, name->len);
33859 +void vfsub_call_lkup_one(void *args);
33861 +/* ---------------------------------------------------------------------- */
33863 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33868 + err = mnt_want_write(mnt);
33873 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33876 + mnt_drop_write(mnt);
33880 +#if 0 /* reserved */
33881 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33884 + mnt_drop_write_file(file);
33889 +/* ---------------------------------------------------------------------- */
33892 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33893 + struct dentry *d2, struct au_hinode *hdir2);
33894 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33895 + struct dentry *d2, struct au_hinode *hdir2);
33897 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33899 +int vfsub_symlink(struct inode *dir, struct path *path,
33900 + const char *symname);
33901 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33902 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33903 + struct path *path, struct inode **delegated_inode);
33904 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33905 + struct inode *hdir, struct path *path,
33906 + struct inode **delegated_inode, unsigned int flags);
33907 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33908 +int vfsub_rmdir(struct inode *dir, struct path *path);
33910 +/* ---------------------------------------------------------------------- */
33912 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33914 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33916 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33918 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33920 +int vfsub_flush(struct file *file, fl_owner_t id);
33921 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33923 +static inline loff_t vfsub_f_size_read(struct file *file)
33925 + return i_size_read(file_inode(file));
33928 +static inline unsigned int vfsub_file_flags(struct file *file)
33930 + unsigned int flags;
33932 + spin_lock(&file->f_lock);
33933 + flags = file->f_flags;
33934 + spin_unlock(&file->f_lock);
33939 +static inline int vfsub_file_execed(struct file *file)
33941 + /* todo: direct access f_flags */
33942 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33945 +#if 0 /* reserved */
33946 +static inline void vfsub_file_accessed(struct file *h_file)
33948 + file_accessed(h_file);
33949 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33953 +#if 0 /* reserved */
33954 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33955 + struct dentry *h_dentry)
33957 + struct path h_path = {
33958 + .dentry = h_dentry,
33961 + touch_atime(&h_path);
33962 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33966 +static inline int vfsub_update_time(struct inode *h_inode,
33967 + struct timespec64 *ts, int flags)
33969 + return update_time(h_inode, ts, flags);
33970 + /* no vfsub_update_h_iattr() since we don't have struct path */
33973 +#ifdef CONFIG_FS_POSIX_ACL
33974 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33978 + err = posix_acl_chmod(h_inode, h_mode);
33979 + if (err == -EOPNOTSUPP)
33984 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33987 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33988 + struct pipe_inode_info *pipe, size_t len,
33989 + unsigned int flags);
33990 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33991 + loff_t *ppos, size_t len, unsigned int flags);
33993 +static inline long vfsub_truncate(struct path *path, loff_t length)
33998 + err = vfs_truncate(path, length);
34003 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
34004 + struct file *h_file);
34005 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
34008 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
34011 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
34017 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
34023 +/* copy_file_range(2) is a systemcall */
34024 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
34025 + struct file *dst, loff_t dst_pos,
34026 + size_t len, unsigned int flags)
34031 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
34037 +/* ---------------------------------------------------------------------- */
34039 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
34044 + err = vfs_llseek(file, offset, origin);
34049 +/* ---------------------------------------------------------------------- */
34051 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
34052 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
34053 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
34054 + struct inode **delegated_inode);
34055 +int vfsub_notify_change(struct path *path, struct iattr *ia,
34056 + struct inode **delegated_inode);
34057 +int vfsub_unlink(struct inode *dir, struct path *path,
34058 + struct inode **delegated_inode, int force);
34060 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
34062 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
34065 +/* ---------------------------------------------------------------------- */
34067 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
34068 + const void *value, size_t size, int flags)
34073 + err = vfs_setxattr(dentry, name, value, size, flags);
34079 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
34084 + err = vfs_removexattr(dentry, name);
34090 +#endif /* __KERNEL__ */
34091 +#endif /* __AUFS_VFSUB_H__ */
34092 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
34093 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
34094 +++ linux/fs/aufs/wbr_policy.c 2019-03-05 12:13:00.145891204 +0100
34096 +// SPDX-License-Identifier: GPL-2.0
34098 + * Copyright (C) 2005-2019 Junjiro R. Okajima
34100 + * This program, aufs is free software; you can redistribute it and/or modify
34101 + * it under the terms of the GNU General Public License as published by
34102 + * the Free Software Foundation; either version 2 of the License, or
34103 + * (at your option) any later version.
34105 + * This program is distributed in the hope that it will be useful,
34106 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34107 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34108 + * GNU General Public License for more details.
34110 + * You should have received a copy of the GNU General Public License
34111 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34115 + * policies for selecting one among multiple writable branches
34118 +#include <linux/statfs.h>
34121 +/* subset of cpup_attr() */
34122 +static noinline_for_stack
34123 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34127 + struct inode *h_isrc;
34129 + h_isrc = d_inode(h_src);
34130 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34131 + ia.ia_mode = h_isrc->i_mode;
34132 + ia.ia_uid = h_isrc->i_uid;
34133 + ia.ia_gid = h_isrc->i_gid;
34134 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34135 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34136 + /* no delegation since it is just created */
34137 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34139 + /* is this nfs only? */
34140 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34141 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34142 + ia.ia_mode = h_isrc->i_mode;
34143 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34149 +#define AuCpdown_PARENT_OPQ 1
34150 +#define AuCpdown_WHED (1 << 1)
34151 +#define AuCpdown_MADE_DIR (1 << 2)
34152 +#define AuCpdown_DIROPQ (1 << 3)
34153 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34154 +#define au_fset_cpdown(flags, name) \
34155 + do { (flags) |= AuCpdown_##name; } while (0)
34156 +#define au_fclr_cpdown(flags, name) \
34157 + do { (flags) &= ~AuCpdown_##name; } while (0)
34159 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34160 + unsigned int *flags)
34163 + struct dentry *opq_dentry;
34165 + opq_dentry = au_diropq_create(dentry, bdst);
34166 + err = PTR_ERR(opq_dentry);
34167 + if (IS_ERR(opq_dentry))
34169 + dput(opq_dentry);
34170 + au_fset_cpdown(*flags, DIROPQ);
34176 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34177 + struct inode *dir, aufs_bindex_t bdst)
34180 + struct path h_path;
34181 + struct au_branch *br;
34183 + br = au_sbr(dentry->d_sb, bdst);
34184 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34185 + err = PTR_ERR(h_path.dentry);
34186 + if (IS_ERR(h_path.dentry))
34190 + if (d_is_positive(h_path.dentry)) {
34191 + h_path.mnt = au_br_mnt(br);
34192 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34195 + dput(h_path.dentry);
34201 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34202 + struct au_pin *pin,
34203 + struct dentry *h_parent, void *arg)
34206 + aufs_bindex_t bopq, btop;
34207 + struct path h_path;
34208 + struct dentry *parent;
34209 + struct inode *h_dir, *h_inode, *inode, *dir;
34210 + unsigned int *flags = arg;
34212 + btop = au_dbtop(dentry);
34213 + /* dentry is di-locked */
34214 + parent = dget_parent(dentry);
34215 + dir = d_inode(parent);
34216 + h_dir = d_inode(h_parent);
34217 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34218 + IMustLock(h_dir);
34220 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34221 + if (unlikely(err < 0))
34223 + h_path.dentry = au_h_dptr(dentry, bdst);
34224 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34225 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34226 + if (unlikely(err))
34228 + au_fset_cpdown(*flags, MADE_DIR);
34230 + bopq = au_dbdiropq(dentry);
34231 + au_fclr_cpdown(*flags, WHED);
34232 + au_fclr_cpdown(*flags, DIROPQ);
34233 + if (au_dbwh(dentry) == bdst)
34234 + au_fset_cpdown(*flags, WHED);
34235 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34236 + au_fset_cpdown(*flags, PARENT_OPQ);
34237 + h_inode = d_inode(h_path.dentry);
34238 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34239 + if (au_ftest_cpdown(*flags, WHED)) {
34240 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34241 + if (unlikely(err)) {
34242 + inode_unlock(h_inode);
34247 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34248 + inode_unlock(h_inode);
34249 + if (unlikely(err))
34252 + if (au_ftest_cpdown(*flags, WHED)) {
34253 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34254 + if (unlikely(err))
34258 + inode = d_inode(dentry);
34259 + if (au_ibbot(inode) < bdst)
34260 + au_set_ibbot(inode, bdst);
34261 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34262 + au_hi_flags(inode, /*isdir*/1));
34263 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34264 + goto out; /* success */
34268 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34269 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34270 + rerr = au_diropq_remove(dentry, bdst);
34271 + inode_unlock(h_inode);
34272 + if (unlikely(rerr)) {
34273 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34274 + dentry, bdst, rerr);
34280 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34281 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34282 + if (unlikely(rerr)) {
34283 + AuIOErr("failed removing %pd b%d (%d)\n",
34284 + dentry, bdst, rerr);
34289 + au_set_h_dptr(dentry, bdst, NULL);
34290 + if (au_dbbot(dentry) == bdst)
34291 + au_update_dbbot(dentry);
34297 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34300 + unsigned int flags;
34303 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34308 +/* ---------------------------------------------------------------------- */
34310 +/* policies for create */
34312 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34314 + int err, i, j, ndentry;
34315 + aufs_bindex_t bopq;
34316 + struct au_dcsub_pages dpages;
34317 + struct au_dpage *dpage;
34318 + struct dentry **dentries, *parent, *d;
34320 + err = au_dpages_init(&dpages, GFP_NOFS);
34321 + if (unlikely(err))
34323 + parent = dget_parent(dentry);
34324 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34325 + if (unlikely(err))
34329 + for (i = 0; i < dpages.ndpage; i++) {
34330 + dpage = dpages.dpages + i;
34331 + dentries = dpage->dentries;
34332 + ndentry = dpage->ndentry;
34333 + for (j = 0; j < ndentry; j++) {
34335 + di_read_lock_parent2(d, !AuLock_IR);
34336 + bopq = au_dbdiropq(d);
34337 + di_read_unlock(d, !AuLock_IR);
34338 + if (bopq >= 0 && bopq < err)
34345 + au_dpages_free(&dpages);
34350 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34352 + for (; bindex >= 0; bindex--)
34353 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34358 +/* top down parent */
34359 +static int au_wbr_create_tdp(struct dentry *dentry,
34360 + unsigned int flags __maybe_unused)
34363 + aufs_bindex_t btop, bindex;
34364 + struct super_block *sb;
34365 + struct dentry *parent, *h_parent;
34367 + sb = dentry->d_sb;
34368 + btop = au_dbtop(dentry);
34370 + if (!au_br_rdonly(au_sbr(sb, btop)))
34374 + parent = dget_parent(dentry);
34375 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34376 + h_parent = au_h_dptr(parent, bindex);
34377 + if (!h_parent || d_is_negative(h_parent))
34380 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34387 + /* bottom up here */
34388 + if (unlikely(err < 0)) {
34389 + err = au_wbr_bu(sb, btop - 1);
34391 + err = au_wbr_nonopq(dentry, err);
34395 + AuDbg("b%d\n", err);
34399 +/* ---------------------------------------------------------------------- */
34401 +/* an exception for the policy other than tdp */
34402 +static int au_wbr_create_exp(struct dentry *dentry)
34405 + aufs_bindex_t bwh, bdiropq;
34406 + struct dentry *parent;
34409 + bwh = au_dbwh(dentry);
34410 + parent = dget_parent(dentry);
34411 + bdiropq = au_dbdiropq(parent);
34413 + if (bdiropq >= 0)
34414 + err = min(bdiropq, bwh);
34417 + AuDbg("%d\n", err);
34418 + } else if (bdiropq >= 0) {
34420 + AuDbg("%d\n", err);
34425 + err = au_wbr_nonopq(dentry, err);
34427 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34430 + AuDbg("%d\n", err);
34434 +/* ---------------------------------------------------------------------- */
34437 +static int au_wbr_create_init_rr(struct super_block *sb)
34441 + err = au_wbr_bu(sb, au_sbbot(sb));
34442 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34445 + AuDbg("b%d\n", err);
34449 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34453 + aufs_bindex_t bindex, bbot;
34454 + struct super_block *sb;
34457 + err = au_wbr_create_exp(dentry);
34461 + sb = dentry->d_sb;
34462 + next = &au_sbi(sb)->si_wbr_rr_next;
34463 + bbot = au_sbbot(sb);
34465 + for (bindex = 0; bindex <= bbot; bindex++) {
34466 + if (!au_ftest_wbr(flags, DIR)) {
34467 + err = atomic_dec_return(next) + 1;
34468 + /* modulo for 0 is meaningless */
34469 + if (unlikely(!err))
34470 + err = atomic_dec_return(next) + 1;
34472 + err = atomic_read(next);
34473 + AuDbg("%d\n", err);
34476 + AuDbg("%d\n", err);
34477 + if (!au_br_rdonly(au_sbr(sb, err)))
34483 + err = au_wbr_nonopq(dentry, err);
34486 + AuDbg("%d\n", err);
34490 +/* ---------------------------------------------------------------------- */
34492 +/* most free space */
34493 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34495 + struct super_block *sb;
34496 + struct au_branch *br;
34497 + struct au_wbr_mfs *mfs;
34498 + struct dentry *h_parent;
34499 + aufs_bindex_t bindex, bbot;
34501 + unsigned long long b, bavail;
34502 + struct path h_path;
34503 + /* reduce the stack usage */
34504 + struct kstatfs *st;
34506 + st = kmalloc(sizeof(*st), GFP_NOFS);
34507 + if (unlikely(!st)) {
34508 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34513 + sb = dentry->d_sb;
34514 + mfs = &au_sbi(sb)->si_wbr_mfs;
34515 + MtxMustLock(&mfs->mfs_lock);
34516 + mfs->mfs_bindex = -EROFS;
34517 + mfs->mfsrr_bytes = 0;
34520 + bbot = au_sbbot(sb);
34522 + bindex = au_dbtop(parent);
34523 + bbot = au_dbtaildir(parent);
34526 + for (; bindex <= bbot; bindex++) {
34528 + h_parent = au_h_dptr(parent, bindex);
34529 + if (!h_parent || d_is_negative(h_parent))
34532 + br = au_sbr(sb, bindex);
34533 + if (au_br_rdonly(br))
34536 + /* sb->s_root for NFS is unreliable */
34537 + h_path.mnt = au_br_mnt(br);
34538 + h_path.dentry = h_path.mnt->mnt_root;
34539 + err = vfs_statfs(&h_path, st);
34540 + if (unlikely(err)) {
34541 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34545 + /* when the available size is equal, select the lower one */
34546 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34547 + || sizeof(b) < sizeof(st->f_bsize));
34548 + b = st->f_bavail * st->f_bsize;
34549 + br->br_wbr->wbr_bytes = b;
34550 + if (b >= bavail) {
34552 + mfs->mfs_bindex = bindex;
34553 + mfs->mfs_jiffy = jiffies;
34557 + mfs->mfsrr_bytes = bavail;
34558 + AuDbg("b%d\n", mfs->mfs_bindex);
34559 + au_kfree_rcu(st);
34562 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34565 + struct dentry *parent;
34566 + struct super_block *sb;
34567 + struct au_wbr_mfs *mfs;
34569 + err = au_wbr_create_exp(dentry);
34573 + sb = dentry->d_sb;
34575 + if (au_ftest_wbr(flags, PARENT))
34576 + parent = dget_parent(dentry);
34577 + mfs = &au_sbi(sb)->si_wbr_mfs;
34578 + mutex_lock(&mfs->mfs_lock);
34579 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34580 + || mfs->mfs_bindex < 0
34581 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34582 + au_mfs(dentry, parent);
34583 + mutex_unlock(&mfs->mfs_lock);
34584 + err = mfs->mfs_bindex;
34588 + err = au_wbr_nonopq(dentry, err);
34591 + AuDbg("b%d\n", err);
34595 +static int au_wbr_create_init_mfs(struct super_block *sb)
34597 + struct au_wbr_mfs *mfs;
34599 + mfs = &au_sbi(sb)->si_wbr_mfs;
34600 + mutex_init(&mfs->mfs_lock);
34601 + mfs->mfs_jiffy = 0;
34602 + mfs->mfs_bindex = -EROFS;
34607 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34609 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34613 +/* ---------------------------------------------------------------------- */
34615 +/* top down regardless parent, and then mfs */
34616 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34617 + unsigned int flags __maybe_unused)
34620 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34621 + unsigned long long watermark;
34622 + struct super_block *sb;
34623 + struct au_wbr_mfs *mfs;
34624 + struct au_branch *br;
34625 + struct dentry *parent;
34627 + sb = dentry->d_sb;
34628 + mfs = &au_sbi(sb)->si_wbr_mfs;
34629 + mutex_lock(&mfs->mfs_lock);
34630 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34631 + || mfs->mfs_bindex < 0)
34632 + au_mfs(dentry, /*parent*/NULL);
34633 + watermark = mfs->mfsrr_watermark;
34634 + bmfs = mfs->mfs_bindex;
34635 + mutex_unlock(&mfs->mfs_lock);
34637 + /* another style of au_wbr_create_exp() */
34638 + bwh = au_dbwh(dentry);
34639 + parent = dget_parent(dentry);
34640 + btail = au_dbtaildir(parent);
34641 + if (bwh >= 0 && bwh < btail)
34644 + err = au_wbr_nonopq(dentry, btail);
34645 + if (unlikely(err < 0))
34649 + for (bindex = 0; bindex <= btail; bindex++) {
34650 + br = au_sbr(sb, bindex);
34651 + if (au_br_rdonly(br))
34653 + if (br->br_wbr->wbr_bytes > watermark) {
34664 + AuDbg("b%d\n", err);
34668 +/* ---------------------------------------------------------------------- */
34670 +/* most free space and then round robin */
34671 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34674 + struct au_wbr_mfs *mfs;
34676 + err = au_wbr_create_mfs(dentry, flags);
34678 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34679 + mutex_lock(&mfs->mfs_lock);
34680 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34681 + err = au_wbr_create_rr(dentry, flags);
34682 + mutex_unlock(&mfs->mfs_lock);
34685 + AuDbg("b%d\n", err);
34689 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34693 + au_wbr_create_init_mfs(sb); /* ignore */
34694 + err = au_wbr_create_init_rr(sb);
34699 +/* ---------------------------------------------------------------------- */
34701 +/* top down parent and most free space */
34702 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34705 + unsigned long long b;
34706 + aufs_bindex_t bindex, btop, bbot;
34707 + struct super_block *sb;
34708 + struct dentry *parent, *h_parent;
34709 + struct au_branch *br;
34711 + err = au_wbr_create_tdp(dentry, flags);
34712 + if (unlikely(err < 0))
34714 + parent = dget_parent(dentry);
34715 + btop = au_dbtop(parent);
34716 + bbot = au_dbtaildir(parent);
34717 + if (btop == bbot)
34718 + goto out_parent; /* success */
34720 + e2 = au_wbr_create_mfs(dentry, flags);
34722 + goto out_parent; /* success */
34724 + /* when the available size is equal, select upper one */
34725 + sb = dentry->d_sb;
34726 + br = au_sbr(sb, err);
34727 + b = br->br_wbr->wbr_bytes;
34728 + AuDbg("b%d, %llu\n", err, b);
34730 + for (bindex = btop; bindex <= bbot; bindex++) {
34731 + h_parent = au_h_dptr(parent, bindex);
34732 + if (!h_parent || d_is_negative(h_parent))
34735 + br = au_sbr(sb, bindex);
34736 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34737 + b = br->br_wbr->wbr_bytes;
34739 + AuDbg("b%d, %llu\n", err, b);
34744 + err = au_wbr_nonopq(dentry, err);
34749 + AuDbg("b%d\n", err);
34753 +/* ---------------------------------------------------------------------- */
34756 + * - top down parent
34757 + * - most free space with parent
34758 + * - most free space round-robin regardless parent
34760 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34763 + unsigned long long watermark;
34764 + struct super_block *sb;
34765 + struct au_branch *br;
34766 + struct au_wbr_mfs *mfs;
34768 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34769 + if (unlikely(err < 0))
34772 + sb = dentry->d_sb;
34773 + br = au_sbr(sb, err);
34774 + mfs = &au_sbi(sb)->si_wbr_mfs;
34775 + mutex_lock(&mfs->mfs_lock);
34776 + watermark = mfs->mfsrr_watermark;
34777 + mutex_unlock(&mfs->mfs_lock);
34778 + if (br->br_wbr->wbr_bytes < watermark)
34779 + /* regardless the parent dir */
34780 + err = au_wbr_create_mfsrr(dentry, flags);
34783 + AuDbg("b%d\n", err);
34787 +/* ---------------------------------------------------------------------- */
34789 +/* policies for copyup */
34791 +/* top down parent */
34792 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34794 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34797 +/* bottom up parent */
34798 +static int au_wbr_copyup_bup(struct dentry *dentry)
34801 + aufs_bindex_t bindex, btop;
34802 + struct dentry *parent, *h_parent;
34803 + struct super_block *sb;
34806 + sb = dentry->d_sb;
34807 + parent = dget_parent(dentry);
34808 + btop = au_dbtop(parent);
34809 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34810 + h_parent = au_h_dptr(parent, bindex);
34811 + if (!h_parent || d_is_negative(h_parent))
34814 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34821 + /* bottom up here */
34822 + if (unlikely(err < 0))
34823 + err = au_wbr_bu(sb, btop - 1);
34825 + AuDbg("b%d\n", err);
34830 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34834 + err = au_wbr_bu(dentry->d_sb, btop);
34835 + AuDbg("b%d\n", err);
34837 + err = au_wbr_nonopq(dentry, err);
34839 + AuDbg("b%d\n", err);
34843 +static int au_wbr_copyup_bu(struct dentry *dentry)
34846 + aufs_bindex_t btop;
34848 + btop = au_dbtop(dentry);
34849 + err = au_wbr_do_copyup_bu(dentry, btop);
34853 +/* ---------------------------------------------------------------------- */
34855 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34856 + [AuWbrCopyup_TDP] = {
34857 + .copyup = au_wbr_copyup_tdp
34859 + [AuWbrCopyup_BUP] = {
34860 + .copyup = au_wbr_copyup_bup
34862 + [AuWbrCopyup_BU] = {
34863 + .copyup = au_wbr_copyup_bu
34867 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34868 + [AuWbrCreate_TDP] = {
34869 + .create = au_wbr_create_tdp
34871 + [AuWbrCreate_RR] = {
34872 + .create = au_wbr_create_rr,
34873 + .init = au_wbr_create_init_rr
34875 + [AuWbrCreate_MFS] = {
34876 + .create = au_wbr_create_mfs,
34877 + .init = au_wbr_create_init_mfs,
34878 + .fin = au_wbr_create_fin_mfs
34880 + [AuWbrCreate_MFSV] = {
34881 + .create = au_wbr_create_mfs,
34882 + .init = au_wbr_create_init_mfs,
34883 + .fin = au_wbr_create_fin_mfs
34885 + [AuWbrCreate_MFSRR] = {
34886 + .create = au_wbr_create_mfsrr,
34887 + .init = au_wbr_create_init_mfsrr,
34888 + .fin = au_wbr_create_fin_mfs
34890 + [AuWbrCreate_MFSRRV] = {
34891 + .create = au_wbr_create_mfsrr,
34892 + .init = au_wbr_create_init_mfsrr,
34893 + .fin = au_wbr_create_fin_mfs
34895 + [AuWbrCreate_TDMFS] = {
34896 + .create = au_wbr_create_tdmfs,
34897 + .init = au_wbr_create_init_mfs,
34898 + .fin = au_wbr_create_fin_mfs
34900 + [AuWbrCreate_TDMFSV] = {
34901 + .create = au_wbr_create_tdmfs,
34902 + .init = au_wbr_create_init_mfs,
34903 + .fin = au_wbr_create_fin_mfs
34905 + [AuWbrCreate_PMFS] = {
34906 + .create = au_wbr_create_pmfs,
34907 + .init = au_wbr_create_init_mfs,
34908 + .fin = au_wbr_create_fin_mfs
34910 + [AuWbrCreate_PMFSV] = {
34911 + .create = au_wbr_create_pmfs,
34912 + .init = au_wbr_create_init_mfs,
34913 + .fin = au_wbr_create_fin_mfs
34915 + [AuWbrCreate_PMFSRR] = {
34916 + .create = au_wbr_create_pmfsrr,
34917 + .init = au_wbr_create_init_mfsrr,
34918 + .fin = au_wbr_create_fin_mfs
34920 + [AuWbrCreate_PMFSRRV] = {
34921 + .create = au_wbr_create_pmfsrr,
34922 + .init = au_wbr_create_init_mfsrr,
34923 + .fin = au_wbr_create_fin_mfs
34926 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34927 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34928 +++ linux/fs/aufs/whout.c 2019-03-05 12:13:00.145891204 +0100
34930 +// SPDX-License-Identifier: GPL-2.0
34932 + * Copyright (C) 2005-2019 Junjiro R. Okajima
34934 + * This program, aufs is free software; you can redistribute it and/or modify
34935 + * it under the terms of the GNU General Public License as published by
34936 + * the Free Software Foundation; either version 2 of the License, or
34937 + * (at your option) any later version.
34939 + * This program is distributed in the hope that it will be useful,
34940 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34941 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34942 + * GNU General Public License for more details.
34944 + * You should have received a copy of the GNU General Public License
34945 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34949 + * whiteout for logical deletion and opaque directory
34954 +#define WH_MASK 0444
34957 + * If a directory contains this file, then it is opaque. We start with the
34958 + * .wh. flag so that it is blocked by lookup.
34960 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34961 + sizeof(AUFS_WH_DIROPQ) - 1);
34964 + * generate whiteout name, which is NOT terminated by NULL.
34965 + * @name: original d_name.name
34966 + * @len: original d_name.len
34967 + * @wh: whiteout qstr
34968 + * returns zero when succeeds, otherwise error.
34969 + * succeeded value as wh->name should be freed by kfree().
34971 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34975 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34976 + return -ENAMETOOLONG;
34978 + wh->len = name->len + AUFS_WH_PFX_LEN;
34979 + p = kmalloc(wh->len, GFP_NOFS);
34982 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34983 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34990 +/* ---------------------------------------------------------------------- */
34993 + * test if the @wh_name exists under @h_parent.
34994 + * @try_sio specifies the necessary of super-io.
34996 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
34999 + struct dentry *wh_dentry;
35002 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
35004 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
35005 + err = PTR_ERR(wh_dentry);
35006 + if (IS_ERR(wh_dentry)) {
35007 + if (err == -ENAMETOOLONG)
35013 + if (d_is_negative(wh_dentry))
35014 + goto out_wh; /* success */
35017 + if (d_is_reg(wh_dentry))
35018 + goto out_wh; /* success */
35021 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
35022 + wh_dentry, d_inode(wh_dentry)->i_mode);
35031 + * test if the @h_dentry sets opaque or not.
35033 +int au_diropq_test(struct dentry *h_dentry)
35036 + struct inode *h_dir;
35038 + h_dir = d_inode(h_dentry);
35039 + err = au_wh_test(h_dentry, &diropq_name,
35040 + au_test_h_perm_sio(h_dir, MAY_EXEC));
35045 + * returns a negative dentry whose name is unique and temporary.
35047 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35048 + struct qstr *prefix)
35050 + struct dentry *dentry;
35052 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
35054 + /* strict atomic_t is unnecessary here */
35055 + static unsigned short cnt;
35058 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
35061 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
35062 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
35063 + dentry = ERR_PTR(-ENAMETOOLONG);
35064 + if (unlikely(qs.len > NAME_MAX))
35066 + dentry = ERR_PTR(-ENOMEM);
35067 + name = kmalloc(qs.len + 1, GFP_NOFS);
35068 + if (unlikely(!name))
35072 + /* doubly whiteout-ed */
35073 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
35074 + p = name + AUFS_WH_PFX_LEN * 2;
35075 + memcpy(p, prefix->name, prefix->len);
35076 + p += prefix->len;
35078 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
35081 + for (i = 0; i < 3; i++) {
35082 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
35083 + dentry = au_sio_lkup_one(&qs, h_parent);
35084 + if (IS_ERR(dentry) || d_is_negative(dentry))
35088 + /* pr_warn("could not get random name\n"); */
35089 + dentry = ERR_PTR(-EEXIST);
35090 + AuDbg("%.*s\n", AuLNPair(&qs));
35094 + if (name != defname)
35095 + au_kfree_try_rcu(name);
35097 + AuTraceErrPtr(dentry);
35102 + * rename the @h_dentry on @br to the whiteouted temporary name.
35104 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
35107 + struct path h_path = {
35108 + .mnt = au_br_mnt(br)
35110 + struct inode *h_dir, *delegated;
35111 + struct dentry *h_parent;
35113 + h_parent = h_dentry->d_parent; /* dir inode is locked */
35114 + h_dir = d_inode(h_parent);
35115 + IMustLock(h_dir);
35117 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35118 + err = PTR_ERR(h_path.dentry);
35119 + if (IS_ERR(h_path.dentry))
35122 + /* under the same dir, no need to lock_rename() */
35123 + delegated = NULL;
35124 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35127 + if (unlikely(err == -EWOULDBLOCK)) {
35128 + pr_warn("cannot retry for NFSv4 delegation"
35129 + " for an internal rename\n");
35132 + dput(h_path.dentry);
35139 +/* ---------------------------------------------------------------------- */
35141 + * functions for removing a whiteout
35144 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35147 + struct inode *delegated;
35150 + * forces superio when the dir has a sticky bit.
35151 + * this may be a violation of unix fs semantics.
35153 + force = (h_dir->i_mode & S_ISVTX)
35154 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35155 + delegated = NULL;
35156 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35157 + if (unlikely(err == -EWOULDBLOCK)) {
35158 + pr_warn("cannot retry for NFSv4 delegation"
35159 + " for an internal unlink\n");
35165 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35166 + struct dentry *dentry)
35170 + err = do_unlink_wh(h_dir, h_path);
35171 + if (!err && dentry)
35172 + au_set_dbwh(dentry, -1);
35177 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
35178 + struct au_branch *br)
35181 + struct path h_path = {
35182 + .mnt = au_br_mnt(br)
35186 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
35187 + if (IS_ERR(h_path.dentry))
35188 + err = PTR_ERR(h_path.dentry);
35190 + if (d_is_reg(h_path.dentry))
35191 + err = do_unlink_wh(d_inode(h_parent), &h_path);
35192 + dput(h_path.dentry);
35198 +/* ---------------------------------------------------------------------- */
35200 + * initialize/clean whiteout for a branch
35203 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35207 + struct inode *delegated;
35209 + if (d_is_negative(whpath->dentry))
35213 + err = vfsub_rmdir(h_dir, whpath);
35215 + delegated = NULL;
35216 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35217 + if (unlikely(err == -EWOULDBLOCK)) {
35218 + pr_warn("cannot retry for NFSv4 delegation"
35219 + " for an internal unlink\n");
35223 + if (unlikely(err))
35224 + pr_warn("failed removing %pd (%d), ignored.\n",
35225 + whpath->dentry, err);
35228 +static int test_linkable(struct dentry *h_root)
35230 + struct inode *h_dir = d_inode(h_root);
35232 + if (h_dir->i_op->link)
35235 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35236 + h_root, au_sbtype(h_root->d_sb));
35240 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35241 +static int au_whdir(struct inode *h_dir, struct path *path)
35246 + if (d_is_negative(path->dentry)) {
35249 + if (au_test_nfs(path->dentry->d_sb))
35251 + err = vfsub_mkdir(h_dir, path, mode);
35252 + } else if (d_is_dir(path->dentry))
35255 + pr_err("unknown %pd exists\n", path->dentry);
35260 +struct au_wh_base {
35261 + const struct qstr *name;
35262 + struct dentry *dentry;
35265 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35266 + struct path *h_path)
35268 + h_path->dentry = base[AuBrWh_BASE].dentry;
35269 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35270 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35271 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35272 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35273 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35277 + * returns tri-state,
35278 + * minus: error, caller should print the message
35280 + * plus: error, caller should NOT print the message
35282 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35283 + int do_plink, struct au_wh_base base[],
35284 + struct path *h_path)
35287 + struct inode *h_dir;
35289 + h_dir = d_inode(h_root);
35290 + h_path->dentry = base[AuBrWh_BASE].dentry;
35291 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35292 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35294 + err = test_linkable(h_root);
35295 + if (unlikely(err)) {
35300 + err = au_whdir(h_dir, h_path);
35301 + if (unlikely(err))
35303 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35305 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35306 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35307 + err = au_whdir(h_dir, h_path);
35308 + if (unlikely(err))
35310 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35317 + * for the moment, aufs supports the branch filesystem which does not support
35318 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35319 + * copyup failed. finally, such filesystem will not be used as the writable
35322 + * returns tri-state, see above.
35324 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35325 + int do_plink, struct au_wh_base base[],
35326 + struct path *h_path)
35329 + struct inode *h_dir;
35331 + WbrWhMustWriteLock(wbr);
35333 + err = test_linkable(h_root);
35334 + if (unlikely(err)) {
35340 + * todo: should this create be done in /sbin/mount.aufs helper?
35343 + h_dir = d_inode(h_root);
35344 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35345 + h_path->dentry = base[AuBrWh_BASE].dentry;
35346 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35347 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35350 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35351 + if (unlikely(err))
35354 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35356 + err = au_whdir(h_dir, h_path);
35357 + if (unlikely(err))
35359 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35361 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35362 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35364 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35365 + err = au_whdir(h_dir, h_path);
35366 + if (unlikely(err))
35368 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35375 + * initialize the whiteout base file/dir for @br.
35377 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35380 + const unsigned char do_plink
35381 + = !!au_opt_test(au_mntflags(sb), PLINK);
35382 + struct inode *h_dir;
35383 + struct path path = br->br_path;
35384 + struct dentry *h_root = path.dentry;
35385 + struct au_wbr *wbr = br->br_wbr;
35386 + static const struct qstr base_name[] = {
35387 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35388 + sizeof(AUFS_BASE_NAME) - 1),
35389 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35390 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35391 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35392 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35394 + struct au_wh_base base[] = {
35395 + [AuBrWh_BASE] = {
35396 + .name = base_name + AuBrWh_BASE,
35399 + [AuBrWh_PLINK] = {
35400 + .name = base_name + AuBrWh_PLINK,
35403 + [AuBrWh_ORPH] = {
35404 + .name = base_name + AuBrWh_ORPH,
35410 + WbrWhMustWriteLock(wbr);
35412 + for (i = 0; i < AuBrWh_Last; i++) {
35413 + /* doubly whiteouted */
35414 + struct dentry *d;
35416 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35417 + err = PTR_ERR(d);
35421 + base[i].dentry = d;
35423 + && wbr->wbr_wh[i]
35424 + && wbr->wbr_wh[i] != base[i].dentry);
35428 + for (i = 0; i < AuBrWh_Last; i++) {
35429 + dput(wbr->wbr_wh[i]);
35430 + wbr->wbr_wh[i] = NULL;
35434 + if (!au_br_writable(br->br_perm)) {
35435 + h_dir = d_inode(h_root);
35436 + au_wh_init_ro(h_dir, base, &path);
35437 + } else if (!au_br_wh_linkable(br->br_perm)) {
35438 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35444 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35450 + goto out; /* success */
35453 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35454 + err, h_root, au_sbtype(h_root->d_sb));
35456 + for (i = 0; i < AuBrWh_Last; i++)
35457 + dput(base[i].dentry);
35461 +/* ---------------------------------------------------------------------- */
35463 + * whiteouts are all hard-linked usually.
35464 + * when its link count reaches a ceiling, we create a new whiteout base
35465 + * asynchronously.
35468 +struct reinit_br_wh {
35469 + struct super_block *sb;
35470 + struct au_branch *br;
35473 +static void reinit_br_wh(void *arg)
35476 + aufs_bindex_t bindex;
35477 + struct path h_path;
35478 + struct reinit_br_wh *a = arg;
35479 + struct au_wbr *wbr;
35480 + struct inode *dir, *delegated;
35481 + struct dentry *h_root;
35482 + struct au_hinode *hdir;
35485 + wbr = a->br->br_wbr;
35486 + /* big aufs lock */
35487 + si_noflush_write_lock(a->sb);
35488 + if (!au_br_writable(a->br->br_perm))
35490 + bindex = au_br_index(a->sb, a->br->br_id);
35491 + if (unlikely(bindex < 0))
35494 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35495 + dir = d_inode(a->sb->s_root);
35496 + hdir = au_hi(dir, bindex);
35497 + h_root = au_h_dptr(a->sb->s_root, bindex);
35498 + AuDebugOn(h_root != au_br_dentry(a->br));
35500 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35501 + wbr_wh_write_lock(wbr);
35502 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35505 + h_path.dentry = wbr->wbr_whbase;
35506 + h_path.mnt = au_br_mnt(a->br);
35507 + delegated = NULL;
35508 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35510 + if (unlikely(err == -EWOULDBLOCK)) {
35511 + pr_warn("cannot retry for NFSv4 delegation"
35512 + " for an internal unlink\n");
35516 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35519 + dput(wbr->wbr_whbase);
35520 + wbr->wbr_whbase = NULL;
35522 + err = au_wh_init(a->br, a->sb);
35523 + wbr_wh_write_unlock(wbr);
35524 + au_hn_inode_unlock(hdir);
35525 + di_read_unlock(a->sb->s_root, AuLock_IR);
35527 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35531 + atomic_dec(&wbr->wbr_wh_running);
35532 + au_lcnt_dec(&a->br->br_count);
35533 + si_write_unlock(a->sb);
35534 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35536 + if (unlikely(err))
35537 + AuIOErr("err %d\n", err);
35540 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35542 + int do_dec, wkq_err;
35543 + struct reinit_br_wh *arg;
35546 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35549 + /* ignore ENOMEM */
35550 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35553 + * dec(wh_running), kfree(arg) and dec(br_count)
35554 + * in reinit function
35558 + au_lcnt_inc(&br->br_count);
35559 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35560 + if (unlikely(wkq_err)) {
35561 + atomic_dec(&br->br_wbr->wbr_wh_running);
35562 + au_lcnt_dec(&br->br_count);
35563 + au_kfree_rcu(arg);
35570 + atomic_dec(&br->br_wbr->wbr_wh_running);
35573 +/* ---------------------------------------------------------------------- */
35576 + * create the whiteout @wh.
35578 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35579 + struct dentry *wh)
35582 + struct path h_path = {
35585 + struct au_branch *br;
35586 + struct au_wbr *wbr;
35587 + struct dentry *h_parent;
35588 + struct inode *h_dir, *delegated;
35590 + h_parent = wh->d_parent; /* dir inode is locked */
35591 + h_dir = d_inode(h_parent);
35592 + IMustLock(h_dir);
35594 + br = au_sbr(sb, bindex);
35595 + h_path.mnt = au_br_mnt(br);
35596 + wbr = br->br_wbr;
35597 + wbr_wh_read_lock(wbr);
35598 + if (wbr->wbr_whbase) {
35599 + delegated = NULL;
35600 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35601 + if (unlikely(err == -EWOULDBLOCK)) {
35602 + pr_warn("cannot retry for NFSv4 delegation"
35603 + " for an internal link\n");
35606 + if (!err || err != -EMLINK)
35609 + /* link count full. re-initialize br_whbase. */
35610 + kick_reinit_br_wh(sb, br);
35613 + /* return this error in this context */
35614 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35616 + au_fhsm_wrote(sb, bindex, /*force*/0);
35619 + wbr_wh_read_unlock(wbr);
35623 +/* ---------------------------------------------------------------------- */
35626 + * create or remove the diropq.
35628 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35629 + unsigned int flags)
35631 + struct dentry *opq_dentry, *h_dentry;
35632 + struct super_block *sb;
35633 + struct au_branch *br;
35636 + sb = dentry->d_sb;
35637 + br = au_sbr(sb, bindex);
35638 + h_dentry = au_h_dptr(dentry, bindex);
35639 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35640 + if (IS_ERR(opq_dentry))
35643 + if (au_ftest_diropq(flags, CREATE)) {
35644 + err = link_or_create_wh(sb, bindex, opq_dentry);
35646 + au_set_dbdiropq(dentry, bindex);
35647 + goto out; /* success */
35650 + struct path tmp = {
35651 + .dentry = opq_dentry,
35652 + .mnt = au_br_mnt(br)
35654 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35656 + au_set_dbdiropq(dentry, -1);
35658 + dput(opq_dentry);
35659 + opq_dentry = ERR_PTR(err);
35662 + return opq_dentry;
35665 +struct do_diropq_args {
35666 + struct dentry **errp;
35667 + struct dentry *dentry;
35668 + aufs_bindex_t bindex;
35669 + unsigned int flags;
35672 +static void call_do_diropq(void *args)
35674 + struct do_diropq_args *a = args;
35675 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35678 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35679 + unsigned int flags)
35681 + struct dentry *diropq, *h_dentry;
35683 + h_dentry = au_h_dptr(dentry, bindex);
35684 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35685 + diropq = do_diropq(dentry, bindex, flags);
35688 + struct do_diropq_args args = {
35690 + .dentry = dentry,
35691 + .bindex = bindex,
35695 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35696 + if (unlikely(wkq_err))
35697 + diropq = ERR_PTR(wkq_err);
35703 +/* ---------------------------------------------------------------------- */
35706 + * lookup whiteout dentry.
35707 + * @h_parent: lower parent dentry which must exist and be locked
35708 + * @base_name: name of dentry which will be whiteouted
35709 + * returns dentry for whiteout.
35711 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35712 + struct au_branch *br)
35715 + struct qstr wh_name;
35716 + struct dentry *wh_dentry;
35718 + err = au_wh_name_alloc(&wh_name, base_name);
35719 + wh_dentry = ERR_PTR(err);
35721 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35722 + au_kfree_try_rcu(wh_name.name);
35724 + return wh_dentry;
35728 + * link/create a whiteout for @dentry on @bindex.
35730 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35731 + struct dentry *h_parent)
35733 + struct dentry *wh_dentry;
35734 + struct super_block *sb;
35737 + sb = dentry->d_sb;
35738 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35739 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35740 + err = link_or_create_wh(sb, bindex, wh_dentry);
35742 + au_set_dbwh(dentry, bindex);
35743 + au_fhsm_wrote(sb, bindex, /*force*/0);
35746 + wh_dentry = ERR_PTR(err);
35750 + return wh_dentry;
35753 +/* ---------------------------------------------------------------------- */
35755 +/* Delete all whiteouts in this directory on branch bindex. */
35756 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35757 + aufs_bindex_t bindex, struct au_branch *br)
35760 + unsigned long ul, n;
35761 + struct qstr wh_name;
35763 + struct hlist_head *head;
35764 + struct au_vdir_wh *pos;
35765 + struct au_vdir_destr *str;
35768 + p = (void *)__get_free_page(GFP_NOFS);
35769 + wh_name.name = p;
35770 + if (unlikely(!wh_name.name))
35774 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35775 + p += AUFS_WH_PFX_LEN;
35776 + n = whlist->nh_num;
35777 + head = whlist->nh_head;
35778 + for (ul = 0; !err && ul < n; ul++, head++) {
35779 + hlist_for_each_entry(pos, head, wh_hash) {
35780 + if (pos->wh_bindex != bindex)
35783 + str = &pos->wh_str;
35784 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35785 + memcpy(p, str->name, str->len);
35786 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35787 + err = unlink_wh_name(h_dentry, &wh_name, br);
35792 + AuIOErr("whiteout name too long %.*s\n",
35793 + str->len, str->name);
35798 + free_page((unsigned long)wh_name.name);
35804 +struct del_wh_children_args {
35806 + struct dentry *h_dentry;
35807 + struct au_nhash *whlist;
35808 + aufs_bindex_t bindex;
35809 + struct au_branch *br;
35812 +static void call_del_wh_children(void *args)
35814 + struct del_wh_children_args *a = args;
35815 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35818 +/* ---------------------------------------------------------------------- */
35820 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35822 + struct au_whtmp_rmdir *whtmp;
35824 + unsigned int rdhash;
35826 + SiMustAnyLock(sb);
35828 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35829 + if (unlikely(!whtmp)) {
35830 + whtmp = ERR_PTR(-ENOMEM);
35834 + /* no estimation for dir size */
35835 + rdhash = au_sbi(sb)->si_rdhash;
35837 + rdhash = AUFS_RDHASH_DEF;
35838 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35839 + if (unlikely(err)) {
35840 + au_kfree_rcu(whtmp);
35841 + whtmp = ERR_PTR(err);
35848 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35851 + au_lcnt_dec(&whtmp->br->br_count);
35852 + dput(whtmp->wh_dentry);
35853 + iput(whtmp->dir);
35854 + au_nhash_wh_free(&whtmp->whlist);
35855 + au_kfree_rcu(whtmp);
35859 + * rmdir the whiteouted temporary named dir @h_dentry.
35860 + * @whlist: whiteouted children.
35862 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35863 + struct dentry *wh_dentry, struct au_nhash *whlist)
35866 + unsigned int h_nlink;
35867 + struct path h_tmp;
35868 + struct inode *wh_inode, *h_dir;
35869 + struct au_branch *br;
35871 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35872 + IMustLock(h_dir);
35874 + br = au_sbr(dir->i_sb, bindex);
35875 + wh_inode = d_inode(wh_dentry);
35876 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35879 + * someone else might change some whiteouts while we were sleeping.
35880 + * it means this whlist may have an obsoleted entry.
35882 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35883 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35886 + struct del_wh_children_args args = {
35888 + .h_dentry = wh_dentry,
35889 + .whlist = whlist,
35890 + .bindex = bindex,
35894 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35895 + if (unlikely(wkq_err))
35898 + inode_unlock(wh_inode);
35901 + h_tmp.dentry = wh_dentry;
35902 + h_tmp.mnt = au_br_mnt(br);
35903 + h_nlink = h_dir->i_nlink;
35904 + err = vfsub_rmdir(h_dir, &h_tmp);
35905 + /* some fs doesn't change the parent nlink in some cases */
35906 + h_nlink -= h_dir->i_nlink;
35910 + if (au_ibtop(dir) == bindex) {
35911 + /* todo: dir->i_mutex is necessary */
35912 + au_cpup_attr_timesizes(dir);
35914 + vfsub_drop_nlink(dir);
35916 + return 0; /* success */
35919 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35923 +static void call_rmdir_whtmp(void *args)
35926 + aufs_bindex_t bindex;
35927 + struct au_whtmp_rmdir *a = args;
35928 + struct super_block *sb;
35929 + struct dentry *h_parent;
35930 + struct inode *h_dir;
35931 + struct au_hinode *hdir;
35933 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35934 + /* inode_lock(a->dir); */
35936 + sb = a->dir->i_sb;
35937 + si_read_lock(sb, !AuLock_FLUSH);
35938 + if (!au_br_writable(a->br->br_perm))
35940 + bindex = au_br_index(sb, a->br->br_id);
35941 + if (unlikely(bindex < 0))
35945 + ii_write_lock_parent(a->dir);
35946 + h_parent = dget_parent(a->wh_dentry);
35947 + h_dir = d_inode(h_parent);
35948 + hdir = au_hi(a->dir, bindex);
35949 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35950 + if (unlikely(err))
35952 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35953 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35956 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35957 + au_hn_inode_unlock(hdir);
35958 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35962 + ii_write_unlock(a->dir);
35964 + /* inode_unlock(a->dir); */
35965 + au_whtmp_rmdir_free(a);
35966 + si_read_unlock(sb);
35967 + au_nwt_done(&au_sbi(sb)->si_nowait);
35968 + if (unlikely(err))
35969 + AuIOErr("err %d\n", err);
35972 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35973 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35976 + struct super_block *sb;
35980 + /* all post-process will be done in do_rmdir_whtmp(). */
35982 + args->dir = au_igrab(dir);
35983 + args->br = au_sbr(sb, bindex);
35984 + au_lcnt_inc(&args->br->br_count);
35985 + args->wh_dentry = dget(wh_dentry);
35986 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35987 + if (unlikely(wkq_err)) {
35988 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35989 + au_whtmp_rmdir_free(args);
35992 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35993 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35994 +++ linux/fs/aufs/whout.h 2019-03-05 12:13:00.145891204 +0100
35996 +/* SPDX-License-Identifier: GPL-2.0 */
35998 + * Copyright (C) 2005-2019 Junjiro R. Okajima
36000 + * This program, aufs is free software; you can redistribute it and/or modify
36001 + * it under the terms of the GNU General Public License as published by
36002 + * the Free Software Foundation; either version 2 of the License, or
36003 + * (at your option) any later version.
36005 + * This program is distributed in the hope that it will be useful,
36006 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36007 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36008 + * GNU General Public License for more details.
36010 + * You should have received a copy of the GNU General Public License
36011 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36015 + * whiteout for logical deletion and opaque directory
36018 +#ifndef __AUFS_WHOUT_H__
36019 +#define __AUFS_WHOUT_H__
36026 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
36027 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
36028 +int au_diropq_test(struct dentry *h_dentry);
36030 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
36031 + struct qstr *prefix);
36032 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
36033 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
36034 + struct dentry *dentry);
36035 +int au_wh_init(struct au_branch *br, struct super_block *sb);
36037 +/* diropq flags */
36038 +#define AuDiropq_CREATE 1
36039 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
36040 +#define au_fset_diropq(flags, name) \
36041 + do { (flags) |= AuDiropq_##name; } while (0)
36042 +#define au_fclr_diropq(flags, name) \
36043 + do { (flags) &= ~AuDiropq_##name; } while (0)
36045 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
36046 + unsigned int flags);
36047 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
36048 + struct au_branch *br);
36049 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
36050 + struct dentry *h_parent);
36052 +/* real rmdir for the whiteout-ed dir */
36053 +struct au_whtmp_rmdir {
36054 + struct inode *dir;
36055 + struct au_branch *br;
36056 + struct dentry *wh_dentry;
36057 + struct au_nhash whlist;
36060 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
36061 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
36062 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36063 + struct dentry *wh_dentry, struct au_nhash *whlist);
36064 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36065 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
36067 +/* ---------------------------------------------------------------------- */
36069 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
36070 + aufs_bindex_t bindex)
36072 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
36075 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
36077 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
36080 +#endif /* __KERNEL__ */
36081 +#endif /* __AUFS_WHOUT_H__ */
36082 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
36083 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
36084 +++ linux/fs/aufs/wkq.c 2019-03-05 12:13:00.145891204 +0100
36086 +// SPDX-License-Identifier: GPL-2.0
36088 + * Copyright (C) 2005-2019 Junjiro R. Okajima
36090 + * This program, aufs is free software; you can redistribute it and/or modify
36091 + * it under the terms of the GNU General Public License as published by
36092 + * the Free Software Foundation; either version 2 of the License, or
36093 + * (at your option) any later version.
36095 + * This program is distributed in the hope that it will be useful,
36096 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36097 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36098 + * GNU General Public License for more details.
36100 + * You should have received a copy of the GNU General Public License
36101 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36105 + * workqueue for asynchronous/super-io operations
36106 + * todo: try new credential scheme
36109 +#include <linux/module.h>
36112 +/* internal workqueue named AUFS_WKQ_NAME */
36114 +static struct workqueue_struct *au_wkq;
36116 +struct au_wkinfo {
36117 + struct work_struct wk;
36118 + struct kobject *kobj;
36120 + unsigned int flags; /* see wkq.h */
36122 + au_wkq_func_t func;
36125 +#ifdef CONFIG_LOCKDEP
36127 + struct held_lock **hlock;
36130 + struct completion *comp;
36133 +/* ---------------------------------------------------------------------- */
36135 + * Aufs passes some operations to the workqueue such as the internal copyup.
36136 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36137 + * job run by workqueue depends upon the locks acquired in the other task.
36138 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36139 + * information too. And the job in the workqueue restores the info in order to
36140 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36141 + * correctly and expectedly.
36144 +#ifndef CONFIG_LOCKDEP
36145 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36146 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36147 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36148 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36149 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36151 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36153 + wkinfo->hlock = NULL;
36154 + wkinfo->dont_check = 0;
36161 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36163 + static DEFINE_SPINLOCK(spin);
36166 + struct lock_class_key *key;
36168 + { .name = "&sbinfo->si_rwsem" },
36169 + { .name = "&finfo->fi_rwsem" },
36170 + { .name = "&dinfo->di_rwsem" },
36171 + { .name = "&iinfo->ii_rwsem" }
36176 + /* lockless read from 'set.' see below */
36177 + if (set == ARRAY_SIZE(a)) {
36178 + for (i = 0; i < ARRAY_SIZE(a); i++)
36179 + if (a[i].key == key)
36184 + spin_lock(&spin);
36186 + for (i = 0; i < ARRAY_SIZE(a); i++)
36187 + if (a[i].key == key) {
36188 + spin_unlock(&spin);
36191 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36193 + if (unlikely(a[i].key == key)) { /* rare but possible */
36194 + spin_unlock(&spin);
36199 + if (strstr(a[i].name, name)) {
36201 + * the order of these three lines is important for the
36202 + * lockless read above.
36205 + spin_unlock(&spin);
36207 + /* AuDbg("%d, %s\n", set, name); */
36211 + spin_unlock(&spin);
36220 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36223 + struct task_struct *curr;
36224 + struct held_lock **hl, *held_locks, *p;
36228 + wkinfo->dont_check = lockdep_recursing(curr);
36229 + if (wkinfo->dont_check)
36231 + n = curr->lockdep_depth;
36236 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36237 + if (unlikely(!wkinfo->hlock))
36242 + if (0 && au_debug_test()) /* left for debugging */
36243 + lockdep_print_held_locks(curr);
36245 + held_locks = curr->held_locks;
36246 + hl = wkinfo->hlock;
36248 + p = held_locks++;
36249 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36258 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36260 + au_kfree_try_rcu(wkinfo->hlock);
36263 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36265 + struct held_lock *p, **hl = wkinfo->hlock;
36268 + if (wkinfo->dont_check)
36272 + while ((p = *hl++)) { /* assignment */
36273 + subclass = lockdep_hlock_class(p)->subclass;
36274 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36276 + rwsem_acquire_read(p->instance, subclass, 0,
36277 + /*p->acquire_ip*/_RET_IP_);
36279 + rwsem_acquire(p->instance, subclass, 0,
36280 + /*p->acquire_ip*/_RET_IP_);
36284 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36286 + struct held_lock *p, **hl = wkinfo->hlock;
36288 + if (wkinfo->dont_check)
36292 + while ((p = *hl++)) /* assignment */
36293 + rwsem_release(p->instance, 0, /*p->acquire_ip*/_RET_IP_);
36297 +static void wkq_func(struct work_struct *wk)
36299 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36301 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36302 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36304 + au_wkq_lockdep_pre(wkinfo);
36305 + wkinfo->func(wkinfo->args);
36306 + au_wkq_lockdep_post(wkinfo);
36307 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36308 + complete(wkinfo->comp);
36310 + kobject_put(wkinfo->kobj);
36311 + module_put(THIS_MODULE); /* todo: ?? */
36312 + au_kfree_rcu(wkinfo);
36317 + * Since struct completion is large, try allocating it dynamically.
36319 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
36320 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36322 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36324 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36326 + init_completion(*comp);
36327 + wkinfo->comp = *comp;
36333 +static void au_wkq_comp_free(struct completion *comp)
36335 + au_kfree_rcu(comp);
36341 +#define AuWkqCompDeclare(name) \
36342 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
36343 + struct completion *comp = &_ ## name
36345 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36347 + wkinfo->comp = *comp;
36351 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
36355 +#endif /* 4KSTACKS */
36357 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36359 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36360 + if (au_wkq_test()) {
36361 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36362 + " due to a dead dir by UDBA,"
36363 + " or async xino write?\n");
36364 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36367 + au_dbg_verify_kthread();
36369 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36370 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36371 + queue_work(au_wkq, &wkinfo->wk);
36373 + INIT_WORK(&wkinfo->wk, wkq_func);
36374 + schedule_work(&wkinfo->wk);
36379 + * Be careful. It is easy to make deadlock happen.
36380 + * processA: lock, wkq and wait
36381 + * processB: wkq and wait, lock in wkq
36384 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36387 + AuWkqCompDeclare(comp);
36388 + struct au_wkinfo wkinfo = {
36394 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36395 + if (unlikely(err))
36397 + err = au_wkq_lockdep_alloc(&wkinfo);
36398 + if (unlikely(err))
36401 + au_wkq_run(&wkinfo);
36402 + /* no timeout, no interrupt */
36403 + wait_for_completion(wkinfo.comp);
36405 + au_wkq_lockdep_free(&wkinfo);
36408 + au_wkq_comp_free(comp);
36410 + destroy_work_on_stack(&wkinfo.wk);
36415 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36416 + * problem in a concurrent umounting.
36418 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36419 + unsigned int flags)
36422 + struct au_wkinfo *wkinfo;
36424 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36427 + * wkq_func() must free this wkinfo.
36428 + * it highly depends upon the implementation of workqueue.
36431 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36433 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36434 + wkinfo->flags = flags & ~AuWkq_WAIT;
36435 + wkinfo->func = func;
36436 + wkinfo->args = args;
36437 + wkinfo->comp = NULL;
36438 + au_wkq_lockdep_init(wkinfo);
36439 + kobject_get(wkinfo->kobj);
36440 + __module_get(THIS_MODULE); /* todo: ?? */
36442 + au_wkq_run(wkinfo);
36445 + au_nwt_done(&au_sbi(sb)->si_nowait);
36451 +/* ---------------------------------------------------------------------- */
36453 +void au_nwt_init(struct au_nowait_tasks *nwt)
36455 + atomic_set(&nwt->nw_len, 0);
36456 + /* smp_mb(); */ /* atomic_set */
36457 + init_waitqueue_head(&nwt->nw_wq);
36460 +void au_wkq_fin(void)
36462 + destroy_workqueue(au_wkq);
36465 +int __init au_wkq_init(void)
36470 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36471 + if (IS_ERR(au_wkq))
36472 + err = PTR_ERR(au_wkq);
36473 + else if (!au_wkq)
36478 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36479 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36480 +++ linux/fs/aufs/wkq.h 2019-03-05 12:13:00.145891204 +0100
36482 +/* SPDX-License-Identifier: GPL-2.0 */
36484 + * Copyright (C) 2005-2019 Junjiro R. Okajima
36486 + * This program, aufs is free software; you can redistribute it and/or modify
36487 + * it under the terms of the GNU General Public License as published by
36488 + * the Free Software Foundation; either version 2 of the License, or
36489 + * (at your option) any later version.
36491 + * This program is distributed in the hope that it will be useful,
36492 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36493 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36494 + * GNU General Public License for more details.
36496 + * You should have received a copy of the GNU General Public License
36497 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36501 + * workqueue for asynchronous/super-io operations
36502 + * todo: try new credentials management scheme
36505 +#ifndef __AUFS_WKQ_H__
36506 +#define __AUFS_WKQ_H__
36510 +#include <linux/wait.h>
36512 +struct super_block;
36514 +/* ---------------------------------------------------------------------- */
36517 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36519 +struct au_nowait_tasks {
36521 + wait_queue_head_t nw_wq;
36524 +/* ---------------------------------------------------------------------- */
36526 +typedef void (*au_wkq_func_t)(void *args);
36529 +#define AuWkq_WAIT 1
36530 +#define AuWkq_NEST (1 << 1)
36531 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36532 +#define au_fset_wkq(flags, name) \
36533 + do { (flags) |= AuWkq_##name; } while (0)
36534 +#define au_fclr_wkq(flags, name) \
36535 + do { (flags) &= ~AuWkq_##name; } while (0)
36538 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36539 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36540 + unsigned int flags);
36541 +void au_nwt_init(struct au_nowait_tasks *nwt);
36542 +int __init au_wkq_init(void);
36543 +void au_wkq_fin(void);
36545 +/* ---------------------------------------------------------------------- */
36547 +static inline int au_wkq_test(void)
36549 + return current->flags & PF_WQ_WORKER;
36552 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36554 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36557 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36559 + if (atomic_dec_and_test(&nwt->nw_len))
36560 + wake_up_all(&nwt->nw_wq);
36563 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36565 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36569 +#endif /* __KERNEL__ */
36570 +#endif /* __AUFS_WKQ_H__ */
36571 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36572 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36573 +++ linux/fs/aufs/xattr.c 2019-03-05 12:13:00.145891204 +0100
36575 +// SPDX-License-Identifier: GPL-2.0
36577 + * Copyright (C) 2014-2019 Junjiro R. Okajima
36579 + * This program, aufs is free software; you can redistribute it and/or modify
36580 + * it under the terms of the GNU General Public License as published by
36581 + * the Free Software Foundation; either version 2 of the License, or
36582 + * (at your option) any later version.
36584 + * This program is distributed in the hope that it will be useful,
36585 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36586 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36587 + * GNU General Public License for more details.
36589 + * You should have received a copy of the GNU General Public License
36590 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36594 + * handling xattr functions
36597 +#include <linux/fs.h>
36598 +#include <linux/posix_acl_xattr.h>
36599 +#include <linux/xattr.h>
36602 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36604 + if (!ignore_flags)
36612 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36617 +#define cmp(brattr, prefix) do { \
36618 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36619 + XATTR_##prefix##_PREFIX_LEN)) { \
36620 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36626 + cmp(SEC, SECURITY);
36627 + cmp(SYS, SYSTEM);
36628 + cmp(TR, TRUSTED);
36632 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36639 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36641 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36642 + char *name, char **buf, unsigned int ignore_flags,
36643 + unsigned int verbose)
36647 + struct inode *h_idst;
36649 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36651 + if (unlikely(err <= 0)) {
36652 + if (err == -ENODATA
36653 + || (err == -EOPNOTSUPP
36654 + && ((ignore_flags & au_xattr_out_of_list)
36655 + || (au_test_nfs_noacl(d_inode(h_src))
36656 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36658 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36661 + if (err && (verbose || au_debug_test()))
36662 + pr_err("%s, err %d\n", name, err);
36666 + /* unlock it temporary */
36667 + h_idst = d_inode(h_dst);
36668 + inode_unlock(h_idst);
36669 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36670 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36671 + if (unlikely(err)) {
36672 + if (verbose || au_debug_test())
36673 + pr_err("%s, err %d\n", name, err);
36674 + err = au_xattr_ignore(err, name, ignore_flags);
36681 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36682 + unsigned int verbose)
36684 + int err, unlocked, acl_access, acl_default;
36686 + struct inode *h_isrc, *h_idst;
36687 + char *value, *p, *o, *e;
36689 + /* try stopping to update the source inode while we are referencing */
36690 + /* there should not be the parent-child relationship between them */
36691 + h_isrc = d_inode(h_src);
36692 + h_idst = d_inode(h_dst);
36693 + inode_unlock(h_idst);
36694 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36695 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36698 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36699 + ssz = vfs_listxattr(h_src, NULL, 0);
36701 + if (unlikely(err < 0)) {
36703 + if (err == -ENODATA
36704 + || err == -EOPNOTSUPP)
36705 + err = 0; /* ignore */
36714 + p = kmalloc(ssz, GFP_NOFS);
36716 + if (unlikely(!p))
36718 + err = vfs_listxattr(h_src, p, ssz);
36720 + inode_unlock_shared(h_isrc);
36722 + AuDbg("err %d, ssz %zd\n", err, ssz);
36723 + if (unlikely(err < 0))
36731 + while (!err && p < e) {
36732 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36733 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36734 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36735 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36737 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36739 + p += strlen(p) + 1;
36742 + ignore_flags |= au_xattr_out_of_list;
36743 + if (!err && !acl_access) {
36744 + err = au_do_cpup_xattr(h_dst, h_src,
36745 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36746 + ignore_flags, verbose);
36749 + if (!err && !acl_default) {
36750 + err = au_do_cpup_xattr(h_dst, h_src,
36751 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36752 + ignore_flags, verbose);
36756 + au_kfree_try_rcu(value);
36759 + au_kfree_try_rcu(o);
36762 + inode_unlock_shared(h_isrc);
36767 +/* ---------------------------------------------------------------------- */
36769 +static int au_smack_reentering(struct super_block *sb)
36771 +#if IS_ENABLED(CONFIG_SECURITY_SMACK)
36773 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36774 + * i_op->getxattr(). ouch.
36776 + return si_pid_test(sb);
36787 +struct au_lgxattr {
36795 + const char *name;
36802 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
36806 + struct path h_path;
36807 + struct super_block *sb;
36809 + sb = dentry->d_sb;
36810 + reenter = au_smack_reentering(sb);
36812 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36813 + if (unlikely(err))
36816 + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
36817 + if (unlikely(err))
36819 + if (unlikely(!h_path.dentry))
36820 + /* illegally overlapped or something */
36821 + goto out_di; /* pretending success */
36823 + /* always topmost entry only */
36824 + switch (arg->type) {
36825 + case AU_XATTR_LIST:
36826 + err = vfs_listxattr(h_path.dentry,
36827 + arg->u.list.list, arg->u.list.size);
36829 + case AU_XATTR_GET:
36830 + AuDebugOn(d_is_negative(h_path.dentry));
36831 + err = vfs_getxattr(h_path.dentry,
36832 + arg->u.get.name, arg->u.get.value,
36833 + arg->u.get.size);
36839 + di_read_unlock(dentry, AuLock_IR);
36842 + si_read_unlock(sb);
36848 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36850 + struct au_lgxattr arg = {
36851 + .type = AU_XATTR_LIST,
36858 + return au_lgxattr(dentry, &arg);
36861 +static ssize_t au_getxattr(struct dentry *dentry,
36862 + struct inode *inode __maybe_unused,
36863 + const char *name, void *value, size_t size)
36865 + struct au_lgxattr arg = {
36866 + .type = AU_XATTR_GET,
36874 + return au_lgxattr(dentry, &arg);
36877 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36878 + const char *name, const void *value, size_t size,
36881 + struct au_sxattr arg = {
36882 + .type = AU_XATTR_SET,
36891 + return au_sxattr(dentry, inode, &arg);
36894 +/* ---------------------------------------------------------------------- */
36896 +static int au_xattr_get(const struct xattr_handler *handler,
36897 + struct dentry *dentry, struct inode *inode,
36898 + const char *name, void *buffer, size_t size)
36900 + return au_getxattr(dentry, inode, name, buffer, size);
36903 +static int au_xattr_set(const struct xattr_handler *handler,
36904 + struct dentry *dentry, struct inode *inode,
36905 + const char *name, const void *value, size_t size,
36908 + return au_setxattr(dentry, inode, name, value, size, flags);
36911 +static const struct xattr_handler au_xattr_handler = {
36914 + .get = au_xattr_get,
36915 + .set = au_xattr_set
36918 +static const struct xattr_handler *au_xattr_handlers[] = {
36919 +#ifdef CONFIG_FS_POSIX_ACL
36920 + &posix_acl_access_xattr_handler,
36921 + &posix_acl_default_xattr_handler,
36923 + &au_xattr_handler, /* must be last */
36927 +void au_xattr_init(struct super_block *sb)
36929 + sb->s_xattr = au_xattr_handlers;
36931 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36932 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36933 +++ linux/fs/aufs/xino.c 2019-03-05 12:13:00.145891204 +0100
36935 +// SPDX-License-Identifier: GPL-2.0
36937 + * Copyright (C) 2005-2019 Junjiro R. Okajima
36939 + * This program, aufs is free software; you can redistribute it and/or modify
36940 + * it under the terms of the GNU General Public License as published by
36941 + * the Free Software Foundation; either version 2 of the License, or
36942 + * (at your option) any later version.
36944 + * This program is distributed in the hope that it will be useful,
36945 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36946 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36947 + * GNU General Public License for more details.
36949 + * You should have received a copy of the GNU General Public License
36950 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36954 + * external inode number translation table and bitmap
36956 + * things to consider
36958 + * + au_xino object
36959 + * + XINO files (xino, xib, xigen)
36960 + * + dynamic debugfs entries (xiN)
36961 + * + static debugfs entries (xib, xigen)
36962 + * + static sysfs entry (xi_path)
36963 + * - several entry points to handle them.
36964 + * + mount(2) without xino option (default)
36965 + * + mount(2) with xino option
36966 + * + mount(2) with noxino option
36968 + * + remount with add/del branches
36969 + * + remount with xino/noxino options
36972 +#include <linux/seq_file.h>
36973 +#include <linux/statfs.h>
36976 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36977 + aufs_bindex_t bbot,
36978 + struct super_block *h_sb)
36980 + /* todo: try binary-search if the branches are many */
36981 + for (; btop <= bbot; btop++)
36982 + if (h_sb == au_sbr_sb(sb, btop))
36988 + * find another branch who is on the same filesystem of the specified
36989 + * branch{@btgt}. search until @bbot.
36991 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36992 + aufs_bindex_t bbot)
36994 + aufs_bindex_t bindex;
36995 + struct super_block *tgt_sb;
36997 + tgt_sb = au_sbr_sb(sb, btgt);
36998 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
37000 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
37005 +/* ---------------------------------------------------------------------- */
37008 + * stop unnecessary notify events at creating xino files
37011 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
37013 + aufs_bindex_t bfound, bindex, bbot;
37014 + struct dentry *parent;
37015 + struct au_branch *br;
37018 + parent = dentry->d_parent; /* safe d_parent access */
37019 + bbot = au_sbbot(sb);
37020 + for (bindex = 0; bindex <= bbot; bindex++) {
37021 + br = au_sbr(sb, bindex);
37022 + if (au_br_dentry(br) == parent) {
37028 + AuDbg("bfound b%d\n", bfound);
37032 +struct au_xino_lock_dir {
37033 + struct au_hinode *hdir;
37034 + struct dentry *parent;
37035 + struct inode *dir;
37038 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
37039 + unsigned int lsc)
37041 + struct dentry *parent;
37042 + struct inode *dir;
37044 + parent = dget_parent(dentry);
37045 + dir = d_inode(parent);
37046 + inode_lock_nested(dir, lsc);
37047 +#if 0 /* it should not happen */
37048 + spin_lock(&dentry->d_lock);
37049 + if (unlikely(dentry->d_parent != parent)) {
37050 + spin_unlock(&dentry->d_lock);
37051 + inode_unlock(dir);
37056 + spin_unlock(&dentry->d_lock);
37063 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
37064 + struct au_xino_lock_dir *ldir)
37066 + aufs_bindex_t bindex;
37068 + ldir->hdir = NULL;
37069 + bindex = au_xi_root(sb, xipath->dentry);
37070 + if (bindex >= 0) {
37071 + /* rw branch root */
37072 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
37073 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
37076 + ldir->parent = au_dget_parent_lock(xipath->dentry,
37078 + ldir->dir = d_inode(ldir->parent);
37082 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
37085 + au_hn_inode_unlock(ldir->hdir);
37087 + inode_unlock(ldir->dir);
37088 + dput(ldir->parent);
37092 +/* ---------------------------------------------------------------------- */
37095 + * create and set a new xino file
37097 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent)
37099 + struct file *file;
37100 + struct dentry *h_parent, *d;
37101 + struct inode *h_dir, *inode;
37105 + * at mount-time, and the xino file is the default path,
37106 + * hnotify is disabled so we have no notify events to ignore.
37107 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37109 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37110 + /* | __FMODE_NONOTIFY */,
37112 + if (IS_ERR(file)) {
37114 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
37118 + /* keep file count */
37120 + d = file->f_path.dentry;
37121 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
37122 + /* mnt_want_write() is unnecessary here */
37123 + h_dir = d_inode(h_parent);
37124 + inode = file_inode(file);
37125 + /* no delegation since it is just created */
37126 + if (inode->i_nlink)
37127 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37129 + inode_unlock(h_dir);
37131 + if (unlikely(err)) {
37133 + pr_err("unlink %s(%d)\n", fpath, err);
37138 + if (unlikely(sb == d->d_sb)) {
37140 + pr_err("%s must be outside\n", fpath);
37143 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37145 + pr_err("xino doesn't support %s(%s)\n",
37146 + fpath, au_sbtype(d->d_sb));
37149 + return file; /* success */
37153 + file = ERR_PTR(err);
37158 + * create a new xinofile at the same place/path as @base.
37160 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37161 + struct file *copy_src)
37163 + struct file *file;
37164 + struct dentry *dentry, *parent;
37165 + struct inode *dir, *delegated;
37166 + struct qstr *name;
37167 + struct path path;
37168 + int err, do_unlock;
37169 + struct au_xino_lock_dir ldir;
37172 + au_xino_lock_dir(sb, base, &ldir);
37173 + dentry = base->dentry;
37174 + parent = dentry->d_parent; /* dir inode is locked */
37175 + dir = d_inode(parent);
37178 + name = &dentry->d_name;
37179 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
37180 + if (IS_ERR(path.dentry)) {
37181 + file = (void *)path.dentry;
37182 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37186 + /* no need to mnt_want_write() since we call dentry_open() later */
37187 + err = vfs_create(dir, path.dentry, 0666, NULL);
37188 + if (unlikely(err)) {
37189 + file = ERR_PTR(err);
37190 + pr_err("%pd create err %d\n", dentry, err);
37194 + path.mnt = base->mnt;
37195 + file = vfsub_dentry_open(&path,
37196 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37197 + /* | __FMODE_NONOTIFY */);
37198 + if (IS_ERR(file)) {
37199 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37203 + delegated = NULL;
37204 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37205 + au_xino_unlock_dir(&ldir);
37207 + if (unlikely(err == -EWOULDBLOCK)) {
37208 + pr_warn("cannot retry for NFSv4 delegation"
37209 + " for an internal unlink\n");
37212 + if (unlikely(err)) {
37213 + pr_err("%pd unlink err %d\n", dentry, err);
37218 + /* no one can touch copy_src xino */
37219 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37220 + if (unlikely(err)) {
37221 + pr_err("%pd copy err %d\n", dentry, err);
37225 + goto out_dput; /* success */
37229 + file = ERR_PTR(err);
37231 + dput(path.dentry);
37234 + au_xino_unlock_dir(&ldir);
37238 +struct file *au_xino_file1(struct au_xino *xi)
37240 + struct file *file;
37241 + unsigned int u, nfile;
37244 + nfile = xi->xi_nfile;
37245 + for (u = 0; u < nfile; u++) {
37246 + file = xi->xi_file[u];
37254 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37265 + if (idx < xi->xi_nfile) {
37266 + f = xi->xi_file[idx];
37270 + p = au_kzrealloc(xi->xi_file,
37271 + sizeof(*xi->xi_file) * xi->xi_nfile,
37272 + sizeof(*xi->xi_file) * (idx + 1),
37273 + GFP_NOFS, /*may_shrink*/0);
37275 + MtxMustLock(&xi->xi_mtx);
37277 + xi->xi_nfile = idx + 1;
37285 + xi->xi_file[idx] = file;
37292 + * if @xinew->xi is not set, then create new xigen file.
37294 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37296 + struct file *file;
37299 + SiMustAnyLock(sb);
37301 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37302 + if (IS_ERR(file)) {
37303 + err = PTR_ERR(file);
37304 + pr_err("%s[%d], err %d\n",
37305 + xinew->xi ? "xino" : "xigen",
37306 + xinew->idx, err);
37311 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37314 + /* todo: make xigen file an array */
37315 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37318 + if (unlikely(err))
37319 + file = ERR_PTR(err);
37325 +/* ---------------------------------------------------------------------- */
37328 + * truncate xino files
37330 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37331 + int idx, struct kstatfs *st)
37335 + struct file *file, *new_xino;
37336 + struct au_xi_new xinew = {
37341 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37342 + file = au_xino_file(xinew.xi, idx);
37346 + xinew.base = &file->f_path;
37347 + err = vfs_statfs(xinew.base, st);
37348 + if (unlikely(err)) {
37349 + AuErr1("statfs err %d, ignored\n", err);
37354 + blocks = file_inode(file)->i_blocks;
37355 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37356 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37358 + xinew.copy_src = file;
37359 + new_xino = au_xi_new(sb, &xinew);
37360 + if (IS_ERR(new_xino)) {
37361 + err = PTR_ERR(new_xino);
37362 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37366 + err = vfs_statfs(&new_xino->f_path, st);
37368 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37369 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37370 + st->f_bfree, st->f_blocks);
37372 + AuErr1("statfs err %d, ignored\n", err);
37380 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37383 + unsigned long jiffy;
37384 + aufs_bindex_t bbot;
37385 + struct kstatfs *st;
37386 + struct au_branch *br;
37387 + struct au_xino *xi;
37390 + st = kmalloc(sizeof(*st), GFP_NOFS);
37391 + if (unlikely(!st))
37395 + bbot = au_sbbot(sb);
37396 + if (unlikely(bindex < 0 || bbot < bindex))
37401 + br = au_sbr(sb, bindex);
37402 + xi = br->br_xino;
37403 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37404 + err = au_xino_do_trunc(sb, bindex, i, st);
37406 + au_sbi(sb)->si_xino_jiffy = jiffy;
37409 + au_kfree_rcu(st);
37414 +struct xino_do_trunc_args {
37415 + struct super_block *sb;
37416 + struct au_branch *br;
37420 +static void xino_do_trunc(void *_args)
37422 + struct xino_do_trunc_args *args = _args;
37423 + struct super_block *sb;
37424 + struct au_branch *br;
37425 + struct inode *dir;
37427 + aufs_bindex_t bindex;
37431 + dir = d_inode(sb->s_root);
37435 + si_noflush_write_lock(sb);
37436 + ii_read_lock_parent(dir);
37437 + bindex = au_br_index(sb, br->br_id);
37438 + err = au_xino_trunc(sb, bindex, idx);
37439 + ii_read_unlock(dir);
37440 + if (unlikely(err))
37441 + pr_warn("err b%d, (%d)\n", bindex, err);
37442 + atomic_dec(&br->br_xino->xi_truncating);
37443 + au_lcnt_dec(&br->br_count);
37444 + si_write_unlock(sb);
37445 + au_nwt_done(&au_sbi(sb)->si_nowait);
37446 + au_kfree_rcu(args);
37450 + * returns the index in the xi_file array whose corresponding file is necessary
37451 + * to truncate, or -1 which means no need to truncate.
37453 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37457 + struct kstatfs st;
37458 + struct au_sbinfo *sbinfo;
37459 + struct au_xino *xi;
37460 + struct file *file;
37462 + /* todo: si_xino_expire and the ratio should be customizable */
37463 + sbinfo = au_sbi(sb);
37464 + if (time_before(jiffies,
37465 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37468 + /* truncation border */
37469 + xi = br->br_xino;
37470 + for (u = 0; u < xi->xi_nfile; u++) {
37471 + file = au_xino_file(xi, u);
37475 + err = vfs_statfs(&file->f_path, &st);
37476 + if (unlikely(err)) {
37477 + AuErr1("statfs err %d, ignored\n", err);
37480 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37481 + >= AUFS_XINO_DEF_TRUNC)
37488 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37491 + struct xino_do_trunc_args *args;
37494 + idx = xino_trunc_test(sb, br);
37498 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37501 + /* lock and kfree() will be called in trunc_xino() */
37502 + args = kmalloc(sizeof(*args), GFP_NOFS);
37503 + if (unlikely(!args)) {
37504 + AuErr1("no memory\n");
37508 + au_lcnt_inc(&br->br_count);
37512 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37514 + return; /* success */
37516 + pr_err("wkq %d\n", wkq_err);
37517 + au_lcnt_dec(&br->br_count);
37518 + au_kfree_rcu(args);
37521 + atomic_dec(&br->br_xino->xi_truncating);
37524 +/* ---------------------------------------------------------------------- */
37526 +struct au_xi_calc {
37531 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37532 + struct au_xi_calc *calc)
37536 + maxent = au_xi_maxent(sb);
37537 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37538 + calc->pos *= sizeof(ino_t);
37541 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37542 + struct au_xi_calc *calc)
37545 + struct file *file;
37546 + struct au_xino *xi = br->br_xino;
37547 + struct au_xi_new xinew = {
37551 + SiMustAnyLock(sb);
37557 + mutex_lock(&xi->xi_mtx);
37558 + file = au_xino_file(xi, calc->idx);
37562 + file = au_xino_file(xi, /*idx*/-1);
37563 + AuDebugOn(!file);
37564 + xinew.idx = calc->idx;
37565 + xinew.base = &file->f_path;
37566 + /* xinew.copy_src = NULL; */
37567 + file = au_xi_new(sb, &xinew);
37568 + if (IS_ERR(file))
37569 + err = PTR_ERR(file);
37572 + mutex_unlock(&xi->xi_mtx);
37577 +struct au_xino_do_new_async_args {
37578 + struct super_block *sb;
37579 + struct au_branch *br;
37580 + struct au_xi_calc calc;
37584 +struct au_xi_writing {
37585 + struct hlist_bl_node node;
37586 + ino_t h_ino, ino;
37589 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37590 + struct au_xi_calc *calc, ino_t ino);
37592 +static void au_xino_call_do_new_async(void *args)
37594 + struct au_xino_do_new_async_args *a = args;
37595 + struct au_branch *br;
37596 + struct super_block *sb;
37597 + struct au_sbinfo *sbi;
37598 + struct inode *root;
37599 + struct file *file;
37600 + struct au_xi_writing *del, *p;
37601 + struct hlist_bl_head *hbl;
37602 + struct hlist_bl_node *pos;
37607 + sbi = au_sbi(sb);
37608 + si_noflush_read_lock(sb);
37609 + root = d_inode(sb->s_root);
37610 + ii_read_lock_child(root);
37611 + err = au_xino_do_new_async(sb, br, &a->calc);
37612 + if (unlikely(err)) {
37613 + AuIOErr("err %d\n", err);
37617 + file = au_xino_file(br->br_xino, a->calc.idx);
37618 + AuDebugOn(!file);
37619 + err = au_xino_do_write(sbi->si_xwrite, file, &a->calc, a->ino);
37620 + if (unlikely(err)) {
37621 + AuIOErr("err %d\n", err);
37626 + hbl = &br->br_xino->xi_writing;
37627 + hlist_bl_lock(hbl);
37628 + au_hbl_for_each(pos, hbl) {
37629 + p = container_of(pos, struct au_xi_writing, node);
37630 + if (p->ino == a->ino) {
37632 + hlist_bl_del(&p->node);
37636 + hlist_bl_unlock(hbl);
37637 + au_kfree_rcu(del);
37640 + au_lcnt_dec(&br->br_count);
37641 + ii_read_unlock(root);
37642 + si_read_unlock(sb);
37643 + au_nwt_done(&sbi->si_nowait);
37648 + * create a new xino file asynchronously
37650 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37651 + struct au_xi_calc *calc, ino_t ino)
37654 + struct au_xino_do_new_async_args *arg;
37657 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37658 + if (unlikely(!arg))
37663 + arg->calc = *calc;
37665 + au_lcnt_inc(&br->br_count);
37666 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37667 + if (unlikely(err)) {
37668 + pr_err("wkq %d\n", err);
37669 + au_lcnt_dec(&br->br_count);
37670 + au_kfree_rcu(arg);
37678 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37679 + * at the position of @h_ino.
37681 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37686 + struct au_xi_calc calc;
37687 + struct au_sbinfo *sbinfo;
37688 + struct file *file;
37689 + struct au_xino *xi;
37690 + struct hlist_bl_head *hbl;
37691 + struct hlist_bl_node *pos;
37692 + struct au_xi_writing *p;
37695 + if (!au_opt_test(au_mntflags(sb), XINO))
37696 + return 0; /* no xino */
37699 + au_xi_calc(sb, h_ino, &calc);
37700 + xi = au_sbr(sb, bindex)->br_xino;
37701 + file = au_xino_file(xi, calc.idx);
37703 + hbl = &xi->xi_writing;
37704 + hlist_bl_lock(hbl);
37705 + au_hbl_for_each(pos, hbl) {
37706 + p = container_of(pos, struct au_xi_writing, node);
37707 + if (p->h_ino == h_ino) {
37708 + AuDbg("hi%llu, i%llu, found\n",
37709 + (u64)p->h_ino, (u64)p->ino);
37714 + hlist_bl_unlock(hbl);
37716 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37717 + return 0; /* no xino */
37719 + sbinfo = au_sbi(sb);
37720 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &calc.pos);
37721 + if (sz == sizeof(*ino))
37722 + return 0; /* success */
37725 + if (unlikely(sz >= 0)) {
37727 + AuIOErr("xino read error (%zd)\n", sz);
37732 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37733 + struct au_xi_calc *calc, ino_t ino)
37737 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &calc->pos);
37738 + if (sz == sizeof(ino))
37739 + return 0; /* success */
37741 + AuIOErr("write failed (%zd)\n", sz);
37746 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37747 + * at the position of @h_ino.
37748 + * even if @ino is zero, it is written to the xinofile and means no entry.
37749 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37750 + * try truncating it.
37752 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37756 + unsigned int mnt_flags;
37757 + struct au_xi_calc calc;
37758 + struct file *file;
37759 + struct au_branch *br;
37760 + struct au_xino *xi;
37761 + struct au_xi_writing *p;
37763 + SiMustAnyLock(sb);
37765 + mnt_flags = au_mntflags(sb);
37766 + if (!au_opt_test(mnt_flags, XINO))
37769 + au_xi_calc(sb, h_ino, &calc);
37770 + br = au_sbr(sb, bindex);
37771 + xi = br->br_xino;
37772 + file = au_xino_file(xi, calc.idx);
37774 + /* store the inum pair into the list */
37775 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37776 + p->h_ino = h_ino;
37778 + au_hbl_add(&p->node, &xi->xi_writing);
37780 + /* create and write a new xino file asynchronously */
37781 + err = au_xino_new_async(sb, br, &calc, ino);
37783 + return 0; /* success */
37787 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, file, &calc, ino);
37789 + br = au_sbr(sb, bindex);
37790 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37791 + && au_test_fs_trunc_xino(au_br_sb(br)))
37792 + xino_try_trunc(sb, br);
37793 + return 0; /* success */
37797 + AuIOErr("write failed (%d)\n", err);
37801 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37802 + size_t size, loff_t *pos);
37804 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37805 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
37809 + mm_segment_t oldfs;
37815 + const int prevent_endless = 10;
37819 + oldfs = get_fs();
37820 + set_fs(KERNEL_DS);
37822 + err = func(file, buf.u, size, pos);
37823 + if (err == -EINTR
37824 + && !au_wkq_test()
37825 + && fatal_signal_pending(current)) {
37827 + err = xino_fread_wkq(func, file, kbuf, size, pos);
37828 + BUG_ON(err == -EINTR);
37829 + oldfs = get_fs();
37830 + set_fs(KERNEL_DS);
37832 + } while (i++ < prevent_endless
37833 + && (err == -EAGAIN || err == -EINTR));
37836 +#if 0 /* reserved for future use */
37838 + fsnotify_access(file->f_path.dentry);
37844 +struct xino_fread_args {
37846 + vfs_readf_t func;
37847 + struct file *file;
37853 +static void call_xino_fread(void *args)
37855 + struct xino_fread_args *a = args;
37856 + *a->errp = xino_fread(a->func, a->file, a->buf, a->size, a->pos);
37859 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37860 + size_t size, loff_t *pos)
37864 + struct xino_fread_args args = {
37873 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37874 + if (unlikely(wkq_err))
37880 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37881 + size_t size, loff_t *pos);
37883 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
37884 + size_t size, loff_t *pos)
37887 + mm_segment_t oldfs;
37890 + const char __user *u;
37893 + const int prevent_endless = 10;
37897 + oldfs = get_fs();
37898 + set_fs(KERNEL_DS);
37900 + err = func(file, buf.u, size, pos);
37901 + if (err == -EINTR
37902 + && !au_wkq_test()
37903 + && fatal_signal_pending(current)) {
37905 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
37906 + BUG_ON(err == -EINTR);
37907 + oldfs = get_fs();
37908 + set_fs(KERNEL_DS);
37910 + } while (i++ < prevent_endless
37911 + && (err == -EAGAIN || err == -EINTR));
37914 +#if 0 /* reserved for future use */
37916 + fsnotify_modify(file->f_path.dentry);
37922 +struct do_xino_fwrite_args {
37924 + vfs_writef_t func;
37925 + struct file *file;
37931 +static void call_do_xino_fwrite(void *args)
37933 + struct do_xino_fwrite_args *a = args;
37934 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
37937 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37938 + size_t size, loff_t *pos)
37942 + struct do_xino_fwrite_args args = {
37952 + * it breaks RLIMIT_FSIZE and normal user's limit,
37953 + * users should care about quota and real 'filesystem full.'
37955 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37956 + if (unlikely(wkq_err))
37962 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
37963 + size_t size, loff_t *pos)
37967 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37969 + err = do_xino_fwrite(func, file, buf, size, pos);
37973 + err = xino_fwrite_wkq(func, file, buf, size, pos);
37980 +/* ---------------------------------------------------------------------- */
37983 + * inode number bitmap
37985 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37986 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37990 + AuDebugOn(bit < 0 || page_bits <= bit);
37991 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37995 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37997 + AuDebugOn(ino < AUFS_FIRST_INO);
37998 + ino -= AUFS_FIRST_INO;
37999 + *pindex = ino / page_bits;
38000 + *bit = ino % page_bits;
38003 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
38008 + struct au_sbinfo *sbinfo;
38009 + struct file *xib;
38010 + unsigned long *p;
38012 + sbinfo = au_sbi(sb);
38013 + MtxMustLock(&sbinfo->si_xib_mtx);
38014 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
38015 + || !au_opt_test(sbinfo->si_mntflags, XINO));
38017 + if (pindex == sbinfo->si_xib_last_pindex)
38020 + xib = sbinfo->si_xib;
38021 + p = sbinfo->si_xib_buf;
38022 + pos = sbinfo->si_xib_last_pindex;
38023 + pos *= PAGE_SIZE;
38024 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
38025 + if (unlikely(sz != PAGE_SIZE))
38029 + pos *= PAGE_SIZE;
38030 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
38031 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
38033 + memset(p, 0, PAGE_SIZE);
38034 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
38036 + if (sz == PAGE_SIZE) {
38037 + sbinfo->si_xib_last_pindex = pindex;
38038 + return 0; /* success */
38042 + AuIOErr1("write failed (%zd)\n", sz);
38049 +static void au_xib_clear_bit(struct inode *inode)
38052 + unsigned long pindex;
38053 + struct super_block *sb;
38054 + struct au_sbinfo *sbinfo;
38056 + AuDebugOn(inode->i_nlink);
38058 + sb = inode->i_sb;
38059 + xib_calc_bit(inode->i_ino, &pindex, &bit);
38060 + AuDebugOn(page_bits <= bit);
38061 + sbinfo = au_sbi(sb);
38062 + mutex_lock(&sbinfo->si_xib_mtx);
38063 + err = xib_pindex(sb, pindex);
38065 + clear_bit(bit, sbinfo->si_xib_buf);
38066 + sbinfo->si_xib_next_bit = bit;
38068 + mutex_unlock(&sbinfo->si_xib_mtx);
38071 +/* ---------------------------------------------------------------------- */
38074 + * truncate a xino bitmap file
38078 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
38082 + unsigned long pindex;
38083 + loff_t pos, pend;
38084 + struct au_sbinfo *sbinfo;
38085 + vfs_readf_t func;
38087 + unsigned long *p;
38090 + sbinfo = au_sbi(sb);
38091 + MtxMustLock(&sbinfo->si_xib_mtx);
38092 + p = sbinfo->si_xib_buf;
38093 + func = sbinfo->si_xread;
38094 + pend = vfsub_f_size_read(file);
38096 + while (pos < pend) {
38097 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
38099 + if (unlikely(sz <= 0))
38103 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
38104 + if (unlikely(*ino < AUFS_FIRST_INO))
38107 + xib_calc_bit(*ino, &pindex, &bit);
38108 + AuDebugOn(page_bits <= bit);
38109 + err = xib_pindex(sb, pindex);
38121 +static int xib_restore(struct super_block *sb)
38124 + unsigned int nfile;
38125 + aufs_bindex_t bindex, bbot;
38127 + struct au_branch *br;
38128 + struct au_xino *xi;
38129 + struct file *file;
38132 + page = (void *)__get_free_page(GFP_NOFS);
38133 + if (unlikely(!page))
38137 + bbot = au_sbbot(sb);
38138 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38139 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38140 + br = au_sbr(sb, bindex);
38141 + xi = br->br_xino;
38142 + nfile = xi->xi_nfile;
38143 + for (i = 0; i < nfile; i++) {
38144 + file = au_xino_file(xi, i);
38146 + err = do_xib_restore(sb, file, page);
38149 + AuDbg("skip shared b%d\n", bindex);
38150 + free_page((unsigned long)page);
38156 +int au_xib_trunc(struct super_block *sb)
38161 + struct au_sbinfo *sbinfo;
38162 + unsigned long *p;
38163 + struct file *file;
38165 + SiMustWriteLock(sb);
38168 + sbinfo = au_sbi(sb);
38169 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38172 + file = sbinfo->si_xib;
38173 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38176 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38177 + err = PTR_ERR(file);
38178 + if (IS_ERR(file))
38180 + fput(sbinfo->si_xib);
38181 + sbinfo->si_xib = file;
38183 + p = sbinfo->si_xib_buf;
38184 + memset(p, 0, PAGE_SIZE);
38186 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
38187 + if (unlikely(sz != PAGE_SIZE)) {
38189 + AuIOErr("err %d\n", err);
38195 + mutex_lock(&sbinfo->si_xib_mtx);
38196 + /* mnt_want_write() is unnecessary here */
38197 + err = xib_restore(sb);
38198 + mutex_unlock(&sbinfo->si_xib_mtx);
38204 +/* ---------------------------------------------------------------------- */
38206 +struct au_xino *au_xino_alloc(unsigned int nfile)
38208 + struct au_xino *xi;
38210 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38211 + if (unlikely(!xi))
38213 + xi->xi_nfile = nfile;
38214 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38215 + if (unlikely(!xi->xi_file))
38218 + xi->xi_nondir.total = 8; /* initial size */
38219 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38221 + if (unlikely(!xi->xi_nondir.array))
38224 + spin_lock_init(&xi->xi_nondir.spin);
38225 + init_waitqueue_head(&xi->xi_nondir.wqh);
38226 + mutex_init(&xi->xi_mtx);
38227 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38228 + atomic_set(&xi->xi_truncating, 0);
38229 + kref_init(&xi->xi_kref);
38230 + goto out; /* success */
38233 + au_kfree_try_rcu(xi->xi_file);
38235 + au_kfree_rcu(xi);
38241 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38244 + struct au_xino *xi;
38247 + xi = au_xino_alloc(idx + 1);
38248 + if (unlikely(!xi)) {
38255 + xi->xi_file[idx] = file;
38256 + AuDebugOn(br->br_xino);
38257 + br->br_xino = xi;
38263 +static void au_xino_release(struct kref *kref)
38265 + struct au_xino *xi;
38267 + unsigned long ul;
38268 + struct hlist_bl_head *hbl;
38269 + struct hlist_bl_node *pos, *n;
38270 + struct au_xi_writing *p;
38272 + xi = container_of(kref, struct au_xino, xi_kref);
38273 + for (i = 0; i < xi->xi_nfile; i++)
38274 + if (xi->xi_file[i])
38275 + fput(xi->xi_file[i]);
38276 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38277 + AuDebugOn(xi->xi_nondir.array[i]);
38278 + mutex_destroy(&xi->xi_mtx);
38279 + hbl = &xi->xi_writing;
38280 + ul = au_hbl_count(hbl);
38281 + if (unlikely(ul)) {
38282 + pr_warn("xi_writing %lu\n", ul);
38283 + hlist_bl_lock(hbl);
38284 + hlist_bl_for_each_entry_safe (p, pos, n, hbl, node) {
38285 + hlist_bl_del(&p->node);
38288 + hlist_bl_unlock(hbl);
38290 + au_kfree_try_rcu(xi->xi_file);
38291 + au_kfree_try_rcu(xi->xi_nondir.array);
38292 + au_kfree_rcu(xi);
38295 +int au_xino_put(struct au_branch *br)
38298 + struct au_xino *xi;
38301 + xi = br->br_xino;
38303 + br->br_xino = NULL;
38304 + ret = kref_put(&xi->xi_kref, au_xino_release);
38310 +/* ---------------------------------------------------------------------- */
38313 + * xino mount option handlers
38317 +static void xino_clear_xib(struct super_block *sb)
38319 + struct au_sbinfo *sbinfo;
38321 + SiMustWriteLock(sb);
38323 + sbinfo = au_sbi(sb);
38324 + /* unnecessary to clear sbinfo->si_xread and ->si_xwrite */
38325 + if (sbinfo->si_xib)
38326 + fput(sbinfo->si_xib);
38327 + sbinfo->si_xib = NULL;
38328 + if (sbinfo->si_xib_buf)
38329 + free_page((unsigned long)sbinfo->si_xib_buf);
38330 + sbinfo->si_xib_buf = NULL;
38333 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38337 + struct au_sbinfo *sbinfo;
38338 + struct file *file;
38339 + struct super_block *xi_sb;
38341 + SiMustWriteLock(sb);
38343 + sbinfo = au_sbi(sb);
38344 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38345 + err = PTR_ERR(file);
38346 + if (IS_ERR(file))
38348 + if (sbinfo->si_xib)
38349 + fput(sbinfo->si_xib);
38350 + sbinfo->si_xib = file;
38351 + sbinfo->si_xread = vfs_readf(file);
38352 + sbinfo->si_xwrite = vfs_writef(file);
38353 + xi_sb = file_inode(file)->i_sb;
38354 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38355 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38357 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38358 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38361 + sbinfo->si_ximaxent /= sizeof(ino_t);
38364 + if (!sbinfo->si_xib_buf)
38365 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38366 + if (unlikely(!sbinfo->si_xib_buf))
38369 + sbinfo->si_xib_last_pindex = 0;
38370 + sbinfo->si_xib_next_bit = 0;
38371 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38373 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
38374 + PAGE_SIZE, &pos);
38375 + if (unlikely(err != PAGE_SIZE))
38379 + goto out; /* success */
38382 + if (sbinfo->si_xib_buf)
38383 + free_page((unsigned long)sbinfo->si_xib_buf);
38384 + sbinfo->si_xib_buf = NULL;
38388 + fput(sbinfo->si_xib);
38389 + sbinfo->si_xib = NULL;
38395 +/* xino for each branch */
38396 +static void xino_clear_br(struct super_block *sb)
38398 + aufs_bindex_t bindex, bbot;
38399 + struct au_branch *br;
38401 + bbot = au_sbbot(sb);
38402 + for (bindex = 0; bindex <= bbot; bindex++) {
38403 + br = au_sbr(sb, bindex);
38409 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38410 + aufs_bindex_t bshared)
38412 + struct au_branch *brshared;
38414 + brshared = au_sbr(sb, bshared);
38415 + AuDebugOn(!brshared->br_xino);
38416 + AuDebugOn(!brshared->br_xino->xi_file);
38417 + if (br->br_xino != brshared->br_xino) {
38418 + au_xino_get(brshared);
38420 + br->br_xino = brshared->br_xino;
38424 +struct au_xino_do_set_br {
38425 + vfs_writef_t writef;
38426 + struct au_branch *br;
38428 + aufs_bindex_t bshared;
38431 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38432 + struct au_xino_do_set_br *args)
38435 + struct au_xi_calc calc;
38436 + struct file *file;
38437 + struct au_branch *br;
38438 + struct au_xi_new xinew = {
38443 + xinew.xi = br->br_xino;
38444 + au_xi_calc(sb, args->h_ino, &calc);
38445 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38446 + if (args->bshared >= 0)
38447 + /* shared xino */
38448 + au_xino_set_br_shared(sb, br, args->bshared);
38449 + else if (!xinew.xi) {
38451 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38452 + if (unlikely(err))
38456 + /* force re-creating */
38457 + xinew.xi = br->br_xino;
38458 + xinew.idx = calc.idx;
38459 + mutex_lock(&xinew.xi->xi_mtx);
38460 + file = au_xi_new(sb, &xinew);
38461 + mutex_unlock(&xinew.xi->xi_mtx);
38462 + err = PTR_ERR(file);
38463 + if (IS_ERR(file))
38465 + AuDebugOn(!file);
38467 + err = au_xino_do_write(args->writef, file, &calc, AUFS_ROOT_INO);
38468 + if (unlikely(err))
38476 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38479 + aufs_bindex_t bindex, bbot;
38480 + struct au_xino_do_set_br args;
38481 + struct inode *inode;
38483 + SiMustWriteLock(sb);
38485 + bbot = au_sbbot(sb);
38486 + inode = d_inode(sb->s_root);
38487 + args.writef = au_sbi(sb)->si_xwrite;
38488 + for (bindex = 0; bindex <= bbot; bindex++) {
38489 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38490 + args.br = au_sbr(sb, bindex);
38491 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38492 + err = au_xino_do_set_br(sb, path, &args);
38493 + if (unlikely(err))
38501 +void au_xino_clr(struct super_block *sb)
38503 + struct au_sbinfo *sbinfo;
38505 + au_xigen_clr(sb);
38506 + xino_clear_xib(sb);
38507 + xino_clear_br(sb);
38508 + dbgaufs_brs_del(sb, 0);
38509 + sbinfo = au_sbi(sb);
38510 + /* lvalue, do not call au_mntflags() */
38511 + au_opt_clr(sbinfo->si_mntflags, XINO);
38514 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38517 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38518 + struct qstr *dname, *cur_name;
38519 + struct file *cur_xino;
38520 + struct au_sbinfo *sbinfo;
38521 + struct path *path, *cur_path;
38523 + SiMustWriteLock(sb);
38526 + sbinfo = au_sbi(sb);
38527 + path = &xiopt->file->f_path;
38528 + dentry = path->dentry;
38529 + parent = dget_parent(dentry);
38532 + cur_xino = sbinfo->si_xib;
38534 + cur_path = &cur_xino->f_path;
38535 + cur_dentry = cur_path->dentry;
38536 + cur_parent = dget_parent(cur_dentry);
38537 + cur_name = &cur_dentry->d_name;
38538 + dname = &dentry->d_name;
38539 + skip = (cur_parent == parent
38540 + && au_qstreq(dname, cur_name));
38541 + dput(cur_parent);
38547 + au_opt_set(sbinfo->si_mntflags, XINO);
38548 + err = au_xino_set_xib(sb, path);
38549 + /* si_x{read,write} are set */
38551 + err = au_xigen_set(sb, path);
38553 + err = au_xino_set_br(sb, path);
38555 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38556 + goto out; /* success */
38560 + AuIOErr("failed setting xino(%d).\n", err);
38569 + * create a xinofile at the default place/path.
38571 +struct file *au_xino_def(struct super_block *sb)
38573 + struct file *file;
38575 + struct au_branch *br;
38576 + struct super_block *h_sb;
38577 + struct path path;
38578 + aufs_bindex_t bbot, bindex, bwr;
38581 + bbot = au_sbbot(sb);
38583 + for (bindex = 0; bindex <= bbot; bindex++) {
38584 + br = au_sbr(sb, bindex);
38585 + if (au_br_writable(br->br_perm)
38586 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38593 + file = ERR_PTR(-ENOMEM);
38594 + page = (void *)__get_free_page(GFP_NOFS);
38595 + if (unlikely(!page))
38597 + path.mnt = au_br_mnt(br);
38598 + path.dentry = au_h_dptr(sb->s_root, bwr);
38599 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38600 + file = (void *)p;
38601 + if (!IS_ERR(p)) {
38602 + strcat(p, "/" AUFS_XINO_FNAME);
38603 + AuDbg("%s\n", p);
38604 + file = au_xino_create(sb, p, /*silent*/0);
38606 + free_page((unsigned long)page);
38608 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
38609 + if (IS_ERR(file))
38611 + h_sb = file->f_path.dentry->d_sb;
38612 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38613 + pr_err("xino doesn't support %s(%s)\n",
38614 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38616 + file = ERR_PTR(-EINVAL);
38624 +/* ---------------------------------------------------------------------- */
38627 + * initialize the xinofile for the specified branch @br
38628 + * at the place/path where @base_file indicates.
38629 + * test whether another branch is on the same filesystem or not,
38630 + * if found then share the xinofile with another branch.
38632 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38633 + struct path *base)
38636 + struct au_xino_do_set_br args = {
38641 + args.writef = au_sbi(sb)->si_xwrite;
38642 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38644 + err = au_xino_do_set_br(sb, base, &args);
38645 + if (unlikely(err))
38651 +/* ---------------------------------------------------------------------- */
38654 + * get an unused inode number from bitmap
38656 +ino_t au_xino_new_ino(struct super_block *sb)
38659 + unsigned long *p, pindex, ul, pend;
38660 + struct au_sbinfo *sbinfo;
38661 + struct file *file;
38662 + int free_bit, err;
38664 + if (!au_opt_test(au_mntflags(sb), XINO))
38665 + return iunique(sb, AUFS_FIRST_INO);
38667 + sbinfo = au_sbi(sb);
38668 + mutex_lock(&sbinfo->si_xib_mtx);
38669 + p = sbinfo->si_xib_buf;
38670 + free_bit = sbinfo->si_xib_next_bit;
38671 + if (free_bit < page_bits && !test_bit(free_bit, p))
38672 + goto out; /* success */
38673 + free_bit = find_first_zero_bit(p, page_bits);
38674 + if (free_bit < page_bits)
38675 + goto out; /* success */
38677 + pindex = sbinfo->si_xib_last_pindex;
38678 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38679 + err = xib_pindex(sb, ul);
38680 + if (unlikely(err))
38682 + free_bit = find_first_zero_bit(p, page_bits);
38683 + if (free_bit < page_bits)
38684 + goto out; /* success */
38687 + file = sbinfo->si_xib;
38688 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38689 + for (ul = pindex + 1; ul <= pend; ul++) {
38690 + err = xib_pindex(sb, ul);
38691 + if (unlikely(err))
38693 + free_bit = find_first_zero_bit(p, page_bits);
38694 + if (free_bit < page_bits)
38695 + goto out; /* success */
38700 + set_bit(free_bit, p);
38701 + sbinfo->si_xib_next_bit = free_bit + 1;
38702 + pindex = sbinfo->si_xib_last_pindex;
38703 + mutex_unlock(&sbinfo->si_xib_mtx);
38704 + ino = xib_calc_ino(pindex, free_bit);
38705 + AuDbg("i%lu\n", (unsigned long)ino);
38708 + mutex_unlock(&sbinfo->si_xib_mtx);
38713 +/* for s_op->delete_inode() */
38714 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38717 + unsigned int mnt_flags;
38718 + aufs_bindex_t bindex, bbot, bi;
38719 + unsigned char try_trunc;
38720 + struct au_iinfo *iinfo;
38721 + struct super_block *sb;
38722 + struct au_hinode *hi;
38723 + struct inode *h_inode;
38724 + struct au_branch *br;
38725 + vfs_writef_t xwrite;
38726 + struct au_xi_calc calc;
38727 + struct file *file;
38729 + AuDebugOn(au_is_bad_inode(inode));
38731 + sb = inode->i_sb;
38732 + mnt_flags = au_mntflags(sb);
38733 + if (!au_opt_test(mnt_flags, XINO)
38734 + || inode->i_ino == AUFS_ROOT_INO)
38738 + au_xigen_inc(inode);
38739 + au_xib_clear_bit(inode);
38742 + iinfo = au_ii(inode);
38743 + bindex = iinfo->ii_btop;
38747 + xwrite = au_sbi(sb)->si_xwrite;
38748 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38749 + hi = au_hinode(iinfo, bindex);
38750 + bbot = iinfo->ii_bbot;
38751 + for (; bindex <= bbot; bindex++, hi++) {
38752 + h_inode = hi->hi_inode;
38754 + || (!unlinked && h_inode->i_nlink))
38757 + /* inode may not be revalidated */
38758 + bi = au_br_index(sb, hi->hi_id);
38762 + br = au_sbr(sb, bi);
38763 + au_xi_calc(sb, h_inode->i_ino, &calc);
38764 + file = au_xino_file(br->br_xino, calc.idx);
38765 + if (IS_ERR_OR_NULL(file))
38768 + err = au_xino_do_write(xwrite, file, &calc, /*ino*/0);
38769 + if (!err && try_trunc
38770 + && au_test_fs_trunc_xino(au_br_sb(br)))
38771 + xino_try_trunc(sb, br);
38775 +/* ---------------------------------------------------------------------- */
38777 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38779 + int found, total, i;
38782 + total = xi->xi_nondir.total;
38783 + for (i = 0; i < total; i++) {
38784 + if (xi->xi_nondir.array[i] != h_ino)
38793 +static int au_xinondir_expand(struct au_xino *xi)
38798 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38801 + sz = xi->xi_nondir.total * sizeof(ino_t);
38802 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38804 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38805 + /*may_shrink*/0);
38807 + xi->xi_nondir.array = p;
38808 + xi->xi_nondir.total <<= 1;
38809 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38817 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38818 + ino_t h_ino, int idx)
38820 + struct au_xino *xi;
38822 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38823 + xi = au_sbr(sb, bindex)->br_xino;
38824 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38826 + spin_lock(&xi->xi_nondir.spin);
38827 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38828 + xi->xi_nondir.array[idx] = 0;
38829 + spin_unlock(&xi->xi_nondir.spin);
38830 + wake_up_all(&xi->xi_nondir.wqh);
38833 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38836 + int err, found, empty;
38837 + struct au_xino *xi;
38841 + if (!au_opt_test(au_mntflags(sb), XINO))
38842 + goto out; /* no xino */
38844 + xi = au_sbr(sb, bindex)->br_xino;
38847 + spin_lock(&xi->xi_nondir.spin);
38848 + found = au_xinondir_find(xi, h_ino);
38849 + if (found == -1) {
38850 + empty = au_xinondir_find(xi, /*h_ino*/0);
38851 + if (empty == -1) {
38852 + empty = xi->xi_nondir.total;
38853 + err = au_xinondir_expand(xi);
38854 + if (unlikely(err))
38857 + xi->xi_nondir.array[empty] = h_ino;
38860 + spin_unlock(&xi->xi_nondir.spin);
38861 + wait_event(xi->xi_nondir.wqh,
38862 + xi->xi_nondir.array[found] != h_ino);
38867 + spin_unlock(&xi->xi_nondir.spin);
38872 +/* ---------------------------------------------------------------------- */
38874 +int au_xino_path(struct seq_file *seq, struct file *file)
38878 + err = au_seq_path(seq, &file->f_path);
38879 + if (unlikely(err))
38882 +#define Deleted "\\040(deleted)"
38883 + seq->count -= sizeof(Deleted) - 1;
38884 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38885 + sizeof(Deleted) - 1));
38891 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38892 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38893 +++ linux/include/uapi/linux/aufs_type.h 2019-03-05 12:13:00.155891502 +0100
38895 +/* SPDX-License-Identifier: GPL-2.0 */
38897 + * Copyright (C) 2005-2019 Junjiro R. Okajima
38899 + * This program, aufs is free software; you can redistribute it and/or modify
38900 + * it under the terms of the GNU General Public License as published by
38901 + * the Free Software Foundation; either version 2 of the License, or
38902 + * (at your option) any later version.
38904 + * This program is distributed in the hope that it will be useful,
38905 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38906 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38907 + * GNU General Public License for more details.
38909 + * You should have received a copy of the GNU General Public License
38910 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38913 +#ifndef __AUFS_TYPE_H__
38914 +#define __AUFS_TYPE_H__
38916 +#define AUFS_NAME "aufs"
38920 + * define it before including all other headers.
38921 + * sched.h may use pr_* macros before defining "current", so define the
38922 + * no-current version first, and re-define later.
38924 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38925 +#include <linux/sched.h>
38927 +#define pr_fmt(fmt) \
38928 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38929 + (int)sizeof(current->comm), current->comm, current->pid
38931 +#include <stdint.h>
38932 +#include <sys/types.h>
38933 +#endif /* __KERNEL__ */
38935 +#include <linux/limits.h>
38937 +#define AUFS_VERSION "4.x-rcN-20190211"
38939 +/* todo? move this to linux-2.6.19/include/magic.h */
38940 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38942 +/* ---------------------------------------------------------------------- */
38944 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38945 +typedef int8_t aufs_bindex_t;
38946 +#define AUFS_BRANCH_MAX 127
38948 +typedef int16_t aufs_bindex_t;
38949 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38950 +#define AUFS_BRANCH_MAX 511
38951 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38952 +#define AUFS_BRANCH_MAX 1023
38953 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38954 +#define AUFS_BRANCH_MAX 32767
38959 +#ifndef AUFS_BRANCH_MAX
38960 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38962 +#endif /* __KERNEL__ */
38964 +/* ---------------------------------------------------------------------- */
38966 +#define AUFS_FSTYPE AUFS_NAME
38968 +#define AUFS_ROOT_INO 2
38969 +#define AUFS_FIRST_INO 11
38971 +#define AUFS_WH_PFX ".wh."
38972 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38973 +#define AUFS_WH_TMP_LEN 4
38974 +/* a limit for rmdir/rename a dir and copyup */
38975 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38976 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38978 + - AUFS_WH_TMP_LEN) /* hex */
38979 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38980 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38981 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38982 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38983 +#define AUFS_DIRWH_DEF 3
38984 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38985 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38986 +#define AUFS_RDBLK_DEF 512 /* bytes */
38987 +#define AUFS_RDHASH_DEF 32
38988 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38989 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38990 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38991 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38992 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38994 +/* pseudo-link maintenace under /proc */
38995 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38996 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38997 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38999 +/* dirren, renamed dir */
39000 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
39001 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
39002 +/* whiteouted doubly */
39003 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
39004 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
39006 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
39007 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
39009 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
39010 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
39011 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
39013 +/* doubly whiteouted */
39014 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
39015 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
39016 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
39018 +/* branch permissions and attributes */
39019 +#define AUFS_BRPERM_RW "rw"
39020 +#define AUFS_BRPERM_RO "ro"
39021 +#define AUFS_BRPERM_RR "rr"
39022 +#define AUFS_BRATTR_COO_REG "coo_reg"
39023 +#define AUFS_BRATTR_COO_ALL "coo_all"
39024 +#define AUFS_BRATTR_FHSM "fhsm"
39025 +#define AUFS_BRATTR_UNPIN "unpin"
39026 +#define AUFS_BRATTR_ICEX "icex"
39027 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
39028 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
39029 +#define AUFS_BRATTR_ICEX_TR "icextr"
39030 +#define AUFS_BRATTR_ICEX_USR "icexusr"
39031 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
39032 +#define AUFS_BRRATTR_WH "wh"
39033 +#define AUFS_BRWATTR_NLWH "nolwh"
39034 +#define AUFS_BRWATTR_MOO "moo"
39036 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
39037 +#define AuBrPerm_RO (1 << 1) /* readonly */
39038 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
39039 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
39041 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
39042 +#define AuBrAttr_COO_ALL (1 << 4)
39043 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
39045 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
39046 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
39047 + branch. meaningless since
39048 + linux-3.18-rc1 */
39050 +/* ignore error in copying XATTR */
39051 +#define AuBrAttr_ICEX_SEC (1 << 7)
39052 +#define AuBrAttr_ICEX_SYS (1 << 8)
39053 +#define AuBrAttr_ICEX_TR (1 << 9)
39054 +#define AuBrAttr_ICEX_USR (1 << 10)
39055 +#define AuBrAttr_ICEX_OTH (1 << 11)
39056 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
39057 + | AuBrAttr_ICEX_SYS \
39058 + | AuBrAttr_ICEX_TR \
39059 + | AuBrAttr_ICEX_USR \
39060 + | AuBrAttr_ICEX_OTH)
39062 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
39063 +#define AuBrRAttr_Mask AuBrRAttr_WH
39065 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
39066 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
39067 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
39069 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
39071 +/* #warning test userspace */
39073 +#ifndef CONFIG_AUFS_FHSM
39074 +#undef AuBrAttr_FHSM
39075 +#define AuBrAttr_FHSM 0
39077 +#ifndef CONFIG_AUFS_XATTR
39078 +#undef AuBrAttr_ICEX
39079 +#define AuBrAttr_ICEX 0
39080 +#undef AuBrAttr_ICEX_SEC
39081 +#define AuBrAttr_ICEX_SEC 0
39082 +#undef AuBrAttr_ICEX_SYS
39083 +#define AuBrAttr_ICEX_SYS 0
39084 +#undef AuBrAttr_ICEX_TR
39085 +#define AuBrAttr_ICEX_TR 0
39086 +#undef AuBrAttr_ICEX_USR
39087 +#define AuBrAttr_ICEX_USR 0
39088 +#undef AuBrAttr_ICEX_OTH
39089 +#define AuBrAttr_ICEX_OTH 0
39093 +/* the longest combination */
39094 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
39095 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
39096 + "+" AUFS_BRATTR_COO_REG \
39097 + "+" AUFS_BRATTR_FHSM \
39098 + "+" AUFS_BRATTR_UNPIN \
39099 + "+" AUFS_BRATTR_ICEX_SEC \
39100 + "+" AUFS_BRATTR_ICEX_SYS \
39101 + "+" AUFS_BRATTR_ICEX_USR \
39102 + "+" AUFS_BRATTR_ICEX_OTH \
39103 + "+" AUFS_BRWATTR_NLWH)
39106 + char a[AuBrPermStrSz];
39107 +} au_br_perm_str_t;
39109 +static inline int au_br_writable(int brperm)
39111 + return brperm & AuBrPerm_RW;
39114 +static inline int au_br_whable(int brperm)
39116 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
39119 +static inline int au_br_wh_linkable(int brperm)
39121 + return !(brperm & AuBrWAttr_NoLinkWH);
39124 +static inline int au_br_cmoo(int brperm)
39126 + return brperm & AuBrAttr_CMOO_Mask;
39129 +static inline int au_br_fhsm(int brperm)
39131 + return brperm & AuBrAttr_FHSM;
39134 +/* ---------------------------------------------------------------------- */
39138 + /* readdir in userspace */
39142 + AuCtl_WBR_FD, /* pathconf wrapper */
39143 + AuCtl_IBUSY, /* busy inode */
39144 + AuCtl_MVDOWN, /* move-down */
39145 + AuCtl_BR, /* info about branches */
39146 + AuCtl_FHSM_FD /* connection for fhsm */
39149 +/* borrowed from linux/include/linux/kernel.h */
39151 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39152 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39155 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39157 +#define __aligned(x) __attribute__((aligned(x)))
39162 +#define __packed __attribute__((packed))
39166 +struct au_rdu_cookie {
39171 + uint32_t generation;
39174 +struct au_rdu_ent {
39183 +static inline int au_rdu_len(int nlen)
39185 + /* include the terminating NULL */
39186 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39187 + sizeof(uint64_t));
39190 +union au_rdu_ent_ul {
39191 + struct au_rdu_ent __user *e;
39203 + uint64_t sz; /* AuCtl_RDU */
39204 + uint64_t nent; /* AuCtl_RDU_INO */
39206 + union au_rdu_ent_ul ent;
39207 + uint16_t verify[AufsCtlRduV_End];
39209 + /* input/output */
39213 + union au_rdu_ent_ul tail;
39214 + /* number of entries which were added in a single call */
39219 + struct au_rdu_cookie cookie;
39222 +/* ---------------------------------------------------------------------- */
39224 +/* dirren. the branch is identified by the filename who contains this */
39225 +struct au_drinfo {
39228 + uint8_t oldnamelen;
39229 + uint64_t _padding;
39231 + uint8_t oldname[0];
39234 +struct au_drinfo_fdata {
39236 + struct au_drinfo drinfo;
39239 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39241 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39243 +/* ---------------------------------------------------------------------- */
39245 +struct aufs_wbr_fd {
39250 +/* ---------------------------------------------------------------------- */
39252 +struct aufs_ibusy {
39253 + uint64_t ino, h_ino;
39257 +/* ---------------------------------------------------------------------- */
39259 +/* error code for move-down */
39260 +/* the actual message strings are implemented in aufs-util.git */
39262 + EAU_MVDOWN_OPAQUE = 1,
39263 + EAU_MVDOWN_WHITEOUT,
39264 + EAU_MVDOWN_UPPER,
39265 + EAU_MVDOWN_BOTTOM,
39266 + EAU_MVDOWN_NOUPPER,
39267 + EAU_MVDOWN_NOLOWERBR,
39271 +/* flags for move-down */
39272 +#define AUFS_MVDOWN_DMSG 1
39273 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39274 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39275 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39276 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39277 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39278 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39279 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39280 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39281 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39282 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39283 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39284 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39286 +/* index for move-down */
39288 + AUFS_MVDOWN_UPPER,
39289 + AUFS_MVDOWN_LOWER,
39290 + AUFS_MVDOWN_NARRAY
39294 + * additional info of move-down
39295 + * number of free blocks and inodes.
39296 + * subset of struct kstatfs, but smaller and always 64bit.
39298 +struct aufs_stfs {
39299 + uint64_t f_blocks;
39300 + uint64_t f_bavail;
39301 + uint64_t f_files;
39302 + uint64_t f_ffree;
39305 +struct aufs_stbr {
39306 + int16_t brid; /* optional input */
39307 + int16_t bindex; /* output */
39308 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39311 +struct aufs_mvdown {
39312 + uint32_t flags; /* input/output */
39313 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39314 + int8_t au_errno; /* output */
39317 +/* ---------------------------------------------------------------------- */
39319 +union aufs_brinfo {
39320 + /* PATH_MAX may differ between kernel-space and user-space */
39321 + char _spacer[4096];
39329 +/* ---------------------------------------------------------------------- */
39331 +#define AuCtlType 'A'
39332 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39333 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39334 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39335 + struct aufs_wbr_fd)
39336 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39337 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39338 + struct aufs_mvdown)
39339 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39340 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39342 +#endif /* __AUFS_TYPE_H__ */
39343 SPDX-License-Identifier: GPL-2.0
39344 aufs4.x-rcN loopback patch
39346 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39347 index a271e17e4b10..ee17c7577224 100644
39348 --- a/drivers/block/loop.c
39349 +++ b/drivers/block/loop.c
39350 @@ -625,6 +625,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39354 +static struct file *loop_real_file(struct file *file)
39356 + struct file *f = NULL;
39358 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39359 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39363 static void loop_reread_partitions(struct loop_device *lo,
39364 struct block_device *bdev)
39366 @@ -678,6 +687,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39369 struct file *file = NULL, *old_file;
39370 + struct file *f, *virt_file = NULL, *old_virt_file;
39374 @@ -697,12 +707,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39378 + f = loop_real_file(file);
39380 + virt_file = file;
39385 error = loop_validate_file(file, bdev);
39389 old_file = lo->lo_backing_file;
39390 + old_virt_file = lo->lo_backing_virt_file;
39394 @@ -714,6 +731,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39395 blk_mq_freeze_queue(lo->lo_queue);
39396 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39397 lo->lo_backing_file = file;
39398 + lo->lo_backing_virt_file = virt_file;
39399 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39400 mapping_set_gfp_mask(file->f_mapping,
39401 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39402 @@ -727,6 +745,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39406 + if (old_virt_file)
39407 + fput(old_virt_file);
39409 loop_reread_partitions(lo, bdev);
39411 @@ -735,6 +755,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39412 mutex_unlock(&loop_ctl_mutex);
39420 @@ -921,7 +943,7 @@ static int loop_prepare_queue(struct loop_device *lo)
39421 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39422 struct block_device *bdev, unsigned int arg)
39424 - struct file *file;
39425 + struct file *file, *f, *virt_file = NULL;
39426 struct inode *inode;
39427 struct address_space *mapping;
39429 @@ -936,6 +958,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39433 + f = loop_real_file(file);
39435 + virt_file = file;
39440 error = mutex_lock_killable(&loop_ctl_mutex);
39442 @@ -972,6 +1000,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39443 lo->lo_device = bdev;
39444 lo->lo_flags = lo_flags;
39445 lo->lo_backing_file = file;
39446 + lo->lo_backing_virt_file = virt_file;
39447 lo->transfer = NULL;
39449 lo->lo_sizelimit = 0;
39450 @@ -1009,6 +1038,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39451 mutex_unlock(&loop_ctl_mutex);
39457 /* This is safe: open() is still holding a reference. */
39458 module_put(THIS_MODULE);
39459 @@ -1055,6 +1086,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
39460 static int __loop_clr_fd(struct loop_device *lo, bool release)
39462 struct file *filp = NULL;
39463 + struct file *virt_filp = lo->lo_backing_virt_file;
39464 gfp_t gfp = lo->old_gfp_mask;
39465 struct block_device *bdev = lo->lo_device;
39467 @@ -1078,6 +1110,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39469 spin_lock_irq(&lo->lo_lock);
39470 lo->lo_backing_file = NULL;
39471 + lo->lo_backing_virt_file = NULL;
39472 spin_unlock_irq(&lo->lo_lock);
39474 loop_release_xfer(lo);
39475 @@ -1146,6 +1179,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39484 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39485 index af75a5ee4094..1e6ee5a4f623 100644
39486 --- a/drivers/block/loop.h
39487 +++ b/drivers/block/loop.h
39488 @@ -46,7 +46,7 @@ struct loop_device {
39489 int (*ioctl)(struct loop_device *, int cmd,
39490 unsigned long arg);
39492 - struct file * lo_backing_file;
39493 + struct file * lo_backing_file, *lo_backing_virt_file;
39494 struct block_device *lo_device;
39497 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39498 index 0309f0d502ff..19feb4f3cb5f 100644
39499 --- a/fs/aufs/f_op.c
39500 +++ b/fs/aufs/f_op.c
39501 @@ -359,7 +359,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39502 if (IS_ERR(h_file))
39505 - if (au_test_loopback_kthread()) {
39506 + if (0 && au_test_loopback_kthread()) {
39507 au_warn_loopback(h_file->f_path.dentry->d_sb);
39508 if (file->f_mapping != h_file->f_mapping) {
39509 file->f_mapping = h_file->f_mapping;
39510 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39511 index f05887d612fd..6f0505723cb4 100644
39512 --- a/fs/aufs/loop.c
39513 +++ b/fs/aufs/loop.c
39514 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39515 symbol_put(loop_backing_file);
39516 au_kfree_try_rcu(au_warn_loopback_array);
39519 +/* ---------------------------------------------------------------------- */
39521 +/* support the loopback block device insude aufs */
39523 +struct file *aufs_real_loop(struct file *file)
39527 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39528 + fi_read_lock(file);
39529 + f = au_hf_top(file);
39530 + fi_read_unlock(file);
39534 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39535 index a570730f5482..255e2d3763e7 100644
39536 --- a/fs/aufs/loop.h
39537 +++ b/fs/aufs/loop.h
39538 @@ -26,7 +26,11 @@ void au_warn_loopback(struct super_block *h_sb);
39540 int au_loopback_init(void);
39541 void au_loopback_fin(void);
39543 +struct file *aufs_real_loop(struct file *file);
39545 +AuStub(struct file *, loop_backing_file, return NULL)
39547 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
39548 struct dentry *h_adding)
39549 AuStubInt0(au_test_loopback_kthread, void)
39550 @@ -34,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39552 AuStubInt0(au_loopback_init, void)
39553 AuStubVoid(au_loopback_fin, void)
39555 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39556 #endif /* BLK_DEV_LOOP */
39558 #endif /* __KERNEL__ */
39559 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39560 index 7c270b14f8c9..61938c274f05 100644
39561 --- a/fs/aufs/super.c
39562 +++ b/fs/aufs/super.c
39563 @@ -845,7 +845,10 @@ static const struct super_operations aufs_sop = {
39564 .statfs = aufs_statfs,
39565 .put_super = aufs_put_super,
39566 .sync_fs = aufs_sync_fs,
39567 - .remount_fs = aufs_remount_fs
39568 + .remount_fs = aufs_remount_fs,
39569 +#ifdef CONFIG_AUFS_BDEV_LOOP
39570 + .real_loop = aufs_real_loop
39574 /* ---------------------------------------------------------------------- */
39575 diff --git a/include/linux/fs.h b/include/linux/fs.h
39576 index 5db265e7d35a..8895cd2343e3 100644
39577 --- a/include/linux/fs.h
39578 +++ b/include/linux/fs.h
39579 @@ -1937,6 +1937,10 @@ struct super_operations {
39580 struct shrink_control *);
39581 long (*free_cached_objects)(struct super_block *,
39582 struct shrink_control *);
39583 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
39585 + struct file *(*real_loop)(struct file *);