1 SPDX-License-Identifier: GPL-2.0
2 aufs4.x-rcN kbuild patch
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index ac474a6..284cee9 100644
8 @@ -255,6 +255,7 @@ source "fs/pstore/Kconfig"
9 source "fs/sysv/Kconfig"
10 source "fs/ufs/Kconfig"
11 source "fs/exofs/Kconfig"
12 +source "fs/aufs/Kconfig"
14 endif # MISC_FILESYSTEMS
16 diff --git a/fs/Makefile b/fs/Makefile
17 index 293733f..12d19d0 100644
20 @@ -128,3 +128,4 @@ obj-y += exofs/ # Multiple modules
21 obj-$(CONFIG_CEPH_FS) += ceph/
22 obj-$(CONFIG_PSTORE) += pstore/
23 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
24 +obj-$(CONFIG_AUFS_FS) += aufs/
25 SPDX-License-Identifier: GPL-2.0
26 aufs4.x-rcN base patch
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index 0fe4228..52cedab 100644
32 @@ -2541,6 +2541,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 4cb1d1b..5678bf8 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -741,6 +741,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 0e8e5de..88de3b6 100644
85 @@ -1240,7 +1240,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 12273b6..545e686 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 8c86c80..af894e7 100644
120 @@ -1649,7 +1649,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 8ddd148..ee649e0 100644
133 @@ -846,6 +846,12 @@ static inline int check_mnt(struct mount *mnt)
134 return mnt->mnt_ns == current->nsproxy->mnt_ns;
137 +/* for aufs, CONFIG_AUFS_BR_FUSE */
138 +int is_current_mnt_ns(struct vfsmount *mnt)
140 + return check_mnt(real_mount(mnt));
144 * vfsmount lock must be held for write
146 diff --git a/fs/read_write.c b/fs/read_write.c
147 index 153f8f6..ccc5bc8 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 b3daa97..1dd7f96 100644
183 @@ -838,8 +838,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 @@ -855,9 +855,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
196 * Attempt to initiate a splice from a file to a pipe.
198 -static long do_splice_to(struct file *in, loff_t *ppos,
199 - struct pipe_inode_info *pipe, size_t len,
200 - unsigned int flags)
201 +long do_splice_to(struct file *in, loff_t *ppos,
202 + struct pipe_inode_info *pipe, size_t len,
203 + unsigned int flags)
205 ssize_t (*splice_read)(struct file *, loff_t *,
206 struct pipe_inode_info *, size_t, unsigned int);
207 diff --git a/fs/sync.c b/fs/sync.c
208 index b54e054..2860782 100644
212 * wait == 1 case since in that case write_inode() functions do
213 * sync_dirty_buffer() and thus effectively write one block at a time.
215 -static int __sync_filesystem(struct super_block *sb, int wait)
216 +int __sync_filesystem(struct super_block *sb, int wait)
220 diff --git a/include/linux/file.h b/include/linux/file.h
221 index 279720d..76e38ea 100644
222 --- a/include/linux/file.h
223 +++ b/include/linux/file.h
224 @@ -20,6 +20,7 @@ struct dentry;
226 extern struct file *alloc_file(const struct path *, fmode_t mode,
227 const struct file_operations *fop);
228 +extern struct file *get_empty_filp(void);
230 static inline void fput_light(struct file *file, int fput_needed)
232 diff --git a/include/linux/fs.h b/include/linux/fs.h
233 index 805bf22..0d0d247f 100644
234 --- a/include/linux/fs.h
235 +++ b/include/linux/fs.h
236 @@ -1273,6 +1273,7 @@ extern void fasync_free(struct fasync_struct *);
237 /* can be called from interrupts */
238 extern void kill_fasync(struct fasync_struct **, int, int);
240 +extern int setfl(int fd, struct file * filp, unsigned long arg);
241 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
242 extern int f_setown(struct file *filp, unsigned long arg, int force);
243 extern void f_delown(struct file *filp);
244 @@ -1733,6 +1734,7 @@ struct file_operations {
245 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
246 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
247 int (*check_flags)(int);
248 + int (*setfl)(struct file *, unsigned long);
249 int (*flock) (struct file *, int, struct file_lock *);
250 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
251 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
252 @@ -1803,6 +1805,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
253 struct iovec *fast_pointer,
254 struct iovec **ret_pointer);
256 +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *);
257 +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t,
259 +vfs_readf_t vfs_readf(struct file *file);
260 +vfs_writef_t vfs_writef(struct file *file);
262 extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
263 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
264 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
265 @@ -2218,6 +2226,7 @@ extern int current_umask(void);
266 extern void ihold(struct inode * inode);
267 extern void iput(struct inode *);
268 extern int generic_update_time(struct inode *, struct timespec64 *, int);
269 +extern int update_time(struct inode *, struct timespec64 *, int);
272 extern struct kobject *fs_kobj;
273 @@ -2505,6 +2514,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
277 +extern int __sync_filesystem(struct super_block *, int);
278 extern int sync_filesystem(struct super_block *);
279 extern const struct file_operations def_blk_fops;
280 extern const struct file_operations def_chr_fops;
281 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
282 index 6fc77d4..27e76f0 100644
283 --- a/include/linux/lockdep.h
284 +++ b/include/linux/lockdep.h
285 @@ -313,6 +313,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
286 return lock->key == key;
289 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
294 @@ -439,6 +441,7 @@ struct lockdep_map { };
296 #define lockdep_depth(tsk) (0)
298 +#define lockdep_is_held(lock) (1)
299 #define lockdep_is_held_type(l, r) (1)
301 #define lockdep_assert_held(l) do { (void)(l); } while (0)
302 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
303 index 3594208..24f5fd1 100644
304 --- a/include/linux/mnt_namespace.h
305 +++ b/include/linux/mnt_namespace.h
307 struct mnt_namespace;
309 struct user_namespace;
312 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
313 struct user_namespace *, struct fs_struct *);
314 extern void put_mnt_ns(struct mnt_namespace *ns);
316 +extern int is_current_mnt_ns(struct vfsmount *mnt);
318 extern const struct file_operations proc_mounts_operations;
319 extern const struct file_operations proc_mountinfo_operations;
320 extern const struct file_operations proc_mountstats_operations;
321 diff --git a/include/linux/splice.h b/include/linux/splice.h
322 index 74b4911..19789fb 100644
323 --- a/include/linux/splice.h
324 +++ b/include/linux/splice.h
325 @@ -87,4 +87,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
327 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
328 extern const struct pipe_buf_operations default_pipe_buf_ops;
330 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
331 + loff_t *ppos, size_t len, unsigned int flags);
332 +extern long do_splice_to(struct file *in, loff_t *ppos,
333 + struct pipe_inode_info *pipe, size_t len,
334 + unsigned int flags);
336 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
337 index 5fa4d31..720f070 100644
338 --- a/kernel/locking/lockdep.c
339 +++ b/kernel/locking/lockdep.c
340 @@ -140,7 +140,7 @@ static struct lock_list list_entries[MAX_LOCKDEP_ENTRIES];
341 unsigned long nr_lock_classes;
342 static struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
344 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
345 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
347 if (!hlock->class_idx) {
349 @@ -151,6 +151,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
351 return lock_classes + hlock->class_idx - 1;
353 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
355 #ifdef CONFIG_LOCK_STAT
356 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
357 SPDX-License-Identifier: GPL-2.0
358 aufs4.x-rcN mmap patch
360 diff --git a/fs/proc/base.c b/fs/proc/base.c
361 index aaffc0c..ab72941 100644
364 @@ -2004,7 +2004,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
365 down_read(&mm->mmap_sem);
366 vma = find_exact_vma(mm, vm_start, vm_end);
367 if (vma && vma->vm_file) {
368 - *path = vma->vm_file->f_path;
369 + *path = vma_pr_or_file(vma)->f_path;
373 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
374 index 3b63be6..fb9913b 100644
375 --- a/fs/proc/nommu.c
376 +++ b/fs/proc/nommu.c
377 @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
378 file = region->vm_file;
381 - struct inode *inode = file_inode(region->vm_file);
382 + struct inode *inode;
384 + file = vmr_pr_or_file(region);
385 + inode = file_inode(file);
386 dev = inode->i_sb->s_dev;
389 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
390 index dfd73a4..ed2ce10 100644
391 --- a/fs/proc/task_mmu.c
392 +++ b/fs/proc/task_mmu.c
393 @@ -306,7 +306,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
394 const char *name = NULL;
397 - struct inode *inode = file_inode(vma->vm_file);
398 + struct inode *inode;
400 + file = vma_pr_or_file(vma);
401 + inode = file_inode(file);
402 dev = inode->i_sb->s_dev;
404 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
405 @@ -1734,7 +1737,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
406 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
407 struct vm_area_struct *vma = v;
408 struct numa_maps *md = &numa_priv->md;
409 - struct file *file = vma->vm_file;
410 + struct file *file = vma_pr_or_file(vma);
411 struct mm_struct *mm = vma->vm_mm;
412 struct mm_walk walk = {
413 .hugetlb_entry = gather_hugetlb_stats,
414 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
415 index 5b62f57..dfb4a3b 100644
416 --- a/fs/proc/task_nommu.c
417 +++ b/fs/proc/task_nommu.c
418 @@ -156,7 +156,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
422 - struct inode *inode = file_inode(vma->vm_file);
423 + struct inode *inode;
425 + file = vma_pr_or_file(vma);
426 + inode = file_inode(file);
427 dev = inode->i_sb->s_dev;
429 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
430 diff --git a/include/linux/mm.h b/include/linux/mm.h
431 index d3a3842..c4664f2 100644
432 --- a/include/linux/mm.h
433 +++ b/include/linux/mm.h
434 @@ -1431,6 +1431,28 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
435 unmap_mapping_range(mapping, holebegin, holelen, 0);
438 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
439 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
441 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
442 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
444 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
446 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
448 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
449 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
452 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
453 +extern void vmr_do_fput(struct vm_region *, const char[], int);
455 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
457 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
458 +#endif /* !CONFIG_MMU */
460 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
461 void *buf, int len, unsigned int gup_flags);
462 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
463 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
464 index 99ce070..8babe35 100644
465 --- a/include/linux/mm_types.h
466 +++ b/include/linux/mm_types.h
467 @@ -236,6 +236,7 @@ struct vm_region {
468 unsigned long vm_top; /* region allocated to here */
469 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
470 struct file *vm_file; /* the backing file or NULL */
471 + struct file *vm_prfile; /* the virtual backing file or NULL */
473 int vm_usage; /* region usage count (access under nommu_region_sem) */
474 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
475 @@ -310,6 +311,7 @@ struct vm_area_struct {
476 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
478 struct file * vm_file; /* File we map to (can be NULL). */
479 + struct file *vm_prfile; /* shadow of vm_file */
480 void * vm_private_data; /* was vm_pte (shared mem) */
482 atomic_long_t swap_readahead_info;
483 diff --git a/kernel/fork.c b/kernel/fork.c
484 index a191c05..d88ee5a 100644
487 @@ -506,7 +506,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
488 struct inode *inode = file_inode(file);
489 struct address_space *mapping = file->f_mapping;
493 if (tmp->vm_flags & VM_DENYWRITE)
494 atomic_dec(&inode->i_writecount);
495 i_mmap_lock_write(mapping);
496 diff --git a/mm/Makefile b/mm/Makefile
497 index 8716bda..68afd6d 100644
500 @@ -39,7 +39,7 @@ obj-y := filemap.o mempool.o oom_kill.o \
501 mm_init.o mmu_context.o percpu.o slab_common.o \
502 compaction.o vmacache.o \
503 interval_tree.o list_lru.o workingset.o \
505 + prfile.o debug.o $(mmu-y)
509 diff --git a/mm/filemap.c b/mm/filemap.c
510 index 52517f2..250f675 100644
513 @@ -2700,7 +2700,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
514 vm_fault_t ret = VM_FAULT_LOCKED;
516 sb_start_pagefault(inode->i_sb);
517 - file_update_time(vmf->vma->vm_file);
518 + vma_file_update_time(vmf->vma);
520 if (page->mapping != inode->i_mapping) {
522 diff --git a/mm/mmap.c b/mm/mmap.c
523 index ff1944d..88abe2d 100644
526 @@ -180,7 +180,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
527 if (vma->vm_ops && vma->vm_ops->close)
528 vma->vm_ops->close(vma);
530 - fput(vma->vm_file);
532 mpol_put(vma_policy(vma));
535 @@ -905,7 +905,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
538 uprobe_munmap(next, next->vm_start, next->vm_end);
543 anon_vma_merge(vma, next);
544 @@ -1818,8 +1818,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
552 /* Undo any partial mapping done by a device driver. */
553 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
554 @@ -2638,7 +2638,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
558 - get_file(new->vm_file);
561 if (new->vm_ops && new->vm_ops->open)
562 new->vm_ops->open(new);
563 @@ -2657,7 +2657,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
564 if (new->vm_ops && new->vm_ops->close)
565 new->vm_ops->close(new);
567 - fput(new->vm_file);
569 unlink_anon_vmas(new);
571 mpol_put(vma_policy(new));
572 @@ -2819,7 +2819,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
573 struct vm_area_struct *vma;
574 unsigned long populate = 0;
575 unsigned long ret = -EINVAL;
577 + struct file *file, *prfile;
579 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n",
580 current->comm, current->pid);
581 @@ -2894,10 +2894,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
585 - file = get_file(vma->vm_file);
587 + file = vma->vm_file;
588 + prfile = vma->vm_prfile;
589 ret = do_mmap_pgoff(vma->vm_file, start, size,
590 prot, flags, pgoff, &populate, NULL);
591 + if (!IS_ERR_VALUE(ret) && file && prfile) {
592 + struct vm_area_struct *new_vma;
594 + new_vma = find_vma(mm, ret);
595 + if (!new_vma->vm_prfile)
596 + new_vma->vm_prfile = prfile;
597 + if (new_vma != vma)
601 + * two fput()s instead of vma_fput(vma),
602 + * coz vma may not be available anymore.
608 up_write(&mm->mmap_sem);
610 @@ -3204,7 +3221,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
611 if (anon_vma_clone(new_vma, vma))
612 goto out_free_mempol;
613 if (new_vma->vm_file)
614 - get_file(new_vma->vm_file);
615 + vma_get_file(new_vma);
616 if (new_vma->vm_ops && new_vma->vm_ops->open)
617 new_vma->vm_ops->open(new_vma);
618 vma_link(mm, new_vma, prev, rb_link, rb_parent);
619 diff --git a/mm/nommu.c b/mm/nommu.c
620 index 1d22fdb..2b608be 100644
623 @@ -629,7 +629,7 @@ static void __put_nommu_region(struct vm_region *region)
624 up_write(&nommu_region_sem);
627 - fput(region->vm_file);
630 /* IO memory and memory shared directly out of the pagecache
631 * from ramfs/tmpfs mustn't be released here */
632 @@ -767,7 +767,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
633 if (vma->vm_ops && vma->vm_ops->close)
634 vma->vm_ops->close(vma);
636 - fput(vma->vm_file);
638 put_nommu_region(vma->vm_region);
641 @@ -1288,7 +1288,7 @@ unsigned long do_mmap(struct file *file,
642 goto error_just_free;
645 - fput(region->vm_file);
647 kmem_cache_free(vm_region_jar, region);
650 @@ -1363,7 +1363,7 @@ unsigned long do_mmap(struct file *file,
651 up_write(&nommu_region_sem);
654 - fput(region->vm_file);
656 kmem_cache_free(vm_region_jar, region);
659 diff --git a/mm/prfile.c b/mm/prfile.c
661 index 0000000..a27ac36
665 +// SPDX-License-Identifier: GPL-2.0
667 + * Mainly for aufs which mmap(2) different file and wants to print different
668 + * path in /proc/PID/maps.
669 + * Call these functions via macros defined in linux/mm.h.
671 + * See Documentation/filesystems/aufs/design/06mmap.txt
673 + * Copyright (c) 2014-2018 Junjro R. Okajima
674 + * Copyright (c) 2014 Ian Campbell
677 +#include <linux/mm.h>
678 +#include <linux/file.h>
679 +#include <linux/fs.h>
681 +/* #define PRFILE_TRACE */
682 +static inline void prfile_trace(struct file *f, struct file *pr,
683 + const char func[], int line, const char func2[])
687 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
691 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
694 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
696 + prfile_trace(f, pr, func, line, __func__);
697 + file_update_time(f);
699 + file_update_time(pr);
702 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
705 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
707 + prfile_trace(f, pr, func, line, __func__);
708 + return (f && pr) ? pr : f;
711 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
713 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
715 + prfile_trace(f, pr, func, line, __func__);
721 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
723 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
725 + prfile_trace(f, pr, func, line, __func__);
732 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
735 + struct file *f = region->vm_file, *pr = region->vm_prfile;
737 + prfile_trace(f, pr, func, line, __func__);
738 + return (f && pr) ? pr : f;
741 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
743 + struct file *f = region->vm_file, *pr = region->vm_prfile;
745 + prfile_trace(f, pr, func, line, __func__);
750 +#endif /* !CONFIG_MMU */
751 SPDX-License-Identifier: GPL-2.0
752 aufs4.x-rcN standalone patch
754 diff --git a/fs/dcache.c b/fs/dcache.c
755 index 88de3b6..de0091a 100644
758 @@ -1345,6 +1345,7 @@ void d_walk(struct dentry *parent, void *data,
762 +EXPORT_SYMBOL_GPL(d_walk);
765 struct vfsmount *mnt;
766 @@ -2891,6 +2892,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
768 write_sequnlock(&rename_lock);
770 +EXPORT_SYMBOL_GPL(d_exchange);
773 * d_ancestor - search for an ancestor
774 diff --git a/fs/exec.c b/fs/exec.c
775 index 72e961a..adc7329 100644
778 @@ -109,6 +109,7 @@ bool path_noexec(const struct path *path)
779 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
780 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
782 +EXPORT_SYMBOL_GPL(path_noexec);
786 diff --git a/fs/fcntl.c b/fs/fcntl.c
787 index 545e686..0237ad7 100644
790 @@ -85,6 +85,7 @@ int setfl(int fd, struct file * filp, unsigned long arg)
794 +EXPORT_SYMBOL_GPL(setfl);
796 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
798 diff --git a/fs/file_table.c b/fs/file_table.c
799 index 7ec0b3e..819ee07 100644
800 --- a/fs/file_table.c
801 +++ b/fs/file_table.c
802 @@ -147,6 +147,7 @@ struct file *get_empty_filp(void)
804 return ERR_PTR(-ENFILE);
806 +EXPORT_SYMBOL_GPL(get_empty_filp);
809 * alloc_file - allocate and initialize a 'struct file'
810 @@ -257,6 +258,7 @@ void flush_delayed_fput(void)
814 +EXPORT_SYMBOL_GPL(flush_delayed_fput);
816 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
818 @@ -299,6 +301,7 @@ void __fput_sync(struct file *file)
822 +EXPORT_SYMBOL_GPL(__fput_sync);
824 void put_filp(struct file *file)
826 @@ -307,6 +310,7 @@ void put_filp(struct file *file)
830 +EXPORT_SYMBOL_GPL(put_filp);
832 void __init files_init(void)
834 diff --git a/fs/inode.c b/fs/inode.c
835 index af894e7..169811b 100644
838 @@ -1658,6 +1658,7 @@ int update_time(struct inode *inode, struct timespec64 *time, int flags)
840 return update_time(inode, time, flags);
842 +EXPORT_SYMBOL_GPL(update_time);
845 * touch_atime - update the access time
846 diff --git a/fs/namespace.c b/fs/namespace.c
847 index ee649e0..10923cb 100644
850 @@ -517,6 +517,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
851 mnt_dec_writers(real_mount(mnt));
854 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
857 * mnt_drop_write - give up write access to a mount
858 @@ -851,6 +852,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
860 return check_mnt(real_mount(mnt));
862 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
865 * vfsmount lock must be held for write
866 @@ -1893,6 +1895,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
870 +EXPORT_SYMBOL_GPL(iterate_mounts);
872 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
874 diff --git a/fs/notify/group.c b/fs/notify/group.c
875 index aa5468f2..b38d224 100644
876 --- a/fs/notify/group.c
877 +++ b/fs/notify/group.c
879 #include <linux/srcu.h>
880 #include <linux/rculist.h>
881 #include <linux/wait.h>
882 +#include <linux/module.h>
884 #include <linux/fsnotify_backend.h>
885 #include "fsnotify.h"
886 @@ -109,6 +110,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
888 refcount_inc(&group->refcnt);
890 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
893 * Drop a reference to a group. Free it if it's through.
894 @@ -118,6 +120,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
895 if (refcount_dec_and_test(&group->refcnt))
896 fsnotify_final_destroy_group(group);
898 +EXPORT_SYMBOL_GPL(fsnotify_put_group);
901 * Create a new fsnotify_group and hold a reference for the group returned.
902 @@ -147,6 +150,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
906 +EXPORT_SYMBOL_GPL(fsnotify_alloc_group);
908 int fsnotify_fasync(int fd, struct file *file, int on)
910 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
911 index 61f4c5f..855c655 100644
912 --- a/fs/notify/mark.c
913 +++ b/fs/notify/mark.c
914 @@ -245,6 +245,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
915 queue_delayed_work(system_unbound_wq, &reaper_work,
916 FSNOTIFY_REAPER_DELAY);
918 +EXPORT_SYMBOL_GPL(fsnotify_put_mark);
921 * Get mark reference when we found the mark via lockless traversal of object
922 @@ -399,6 +400,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
923 mutex_unlock(&group->mark_mutex);
924 fsnotify_free_mark(mark);
926 +EXPORT_SYMBOL_GPL(fsnotify_destroy_mark);
929 * Sorting function for lists of fsnotify marks.
930 @@ -624,6 +626,7 @@ int fsnotify_add_mark(struct fsnotify_mark *mark, struct inode *inode,
931 mutex_unlock(&group->mark_mutex);
934 +EXPORT_SYMBOL_GPL(fsnotify_add_mark);
937 * Given a list of marks, find the mark associated with given group. If found
938 @@ -747,6 +750,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
939 fsnotify_get_group(group);
942 +EXPORT_SYMBOL_GPL(fsnotify_init_mark);
945 * Destroy all marks in destroy_list, waits for SRCU period to finish before
946 diff --git a/fs/open.c b/fs/open.c
947 index d0e955b..527bc1a 100644
950 @@ -64,6 +64,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
951 inode_unlock(dentry->d_inode);
954 +EXPORT_SYMBOL_GPL(do_truncate);
956 long vfs_truncate(const struct path *path, loff_t length)
958 @@ -723,6 +724,7 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)
960 return ksys_fchown(fd, user, group);
962 +EXPORT_SYMBOL_GPL(open_check_o_direct);
964 int open_check_o_direct(struct file *f)
966 diff --git a/fs/read_write.c b/fs/read_write.c
967 index ccc5bc8..36f52f4 100644
968 --- a/fs/read_write.c
969 +++ b/fs/read_write.c
970 @@ -459,6 +459,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
974 +EXPORT_SYMBOL_GPL(vfs_read);
976 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
978 @@ -499,6 +500,7 @@ vfs_readf_t vfs_readf(struct file *file)
979 return new_sync_read;
980 return ERR_PTR(-ENOSYS);
982 +EXPORT_SYMBOL_GPL(vfs_readf);
984 vfs_writef_t vfs_writef(struct file *file)
986 @@ -510,6 +512,7 @@ vfs_writef_t vfs_writef(struct file *file)
987 return new_sync_write;
988 return ERR_PTR(-ENOSYS);
990 +EXPORT_SYMBOL_GPL(vfs_writef);
992 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
994 @@ -579,6 +582,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
998 +EXPORT_SYMBOL_GPL(vfs_write);
1000 static inline loff_t file_pos_read(struct file *file)
1002 diff --git a/fs/splice.c b/fs/splice.c
1003 index 1dd7f96..a5e3bcb 100644
1006 @@ -851,6 +851,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
1008 return splice_write(pipe, out, ppos, len, flags);
1010 +EXPORT_SYMBOL_GPL(do_splice_from);
1013 * Attempt to initiate a splice from a file to a pipe.
1014 @@ -880,6 +881,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
1016 return splice_read(in, ppos, pipe, len, flags);
1018 +EXPORT_SYMBOL_GPL(do_splice_to);
1021 * splice_direct_to_actor - splices data directly between two non-pipes
1022 diff --git a/fs/sync.c b/fs/sync.c
1023 index 2860782..ffd7ea4 100644
1026 @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
1027 sb->s_op->sync_fs(sb, wait);
1028 return __sync_blockdev(sb->s_bdev, wait);
1030 +EXPORT_SYMBOL_GPL(__sync_filesystem);
1033 * Write out and wait upon all dirty data associated with this
1034 diff --git a/fs/xattr.c b/fs/xattr.c
1035 index f9cb1db..000b62b 100644
1038 @@ -296,6 +296,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
1039 *xattr_value = value;
1042 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
1045 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
1046 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
1047 index 720f070..4f58215 100644
1048 --- a/kernel/locking/lockdep.c
1049 +++ b/kernel/locking/lockdep.c
1050 @@ -151,6 +151,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
1052 return lock_classes + hlock->class_idx - 1;
1054 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
1055 #define hlock_class(hlock) lockdep_hlock_class(hlock)
1057 #ifdef CONFIG_LOCK_STAT
1058 diff --git a/kernel/task_work.c b/kernel/task_work.c
1059 index 0fef395..83fb1ec 100644
1060 --- a/kernel/task_work.c
1061 +++ b/kernel/task_work.c
1062 @@ -116,3 +116,4 @@ void task_work_run(void)
1066 +EXPORT_SYMBOL_GPL(task_work_run);
1067 diff --git a/security/commoncap.c b/security/commoncap.c
1068 index f4c33ab..70563f1 100644
1069 --- a/security/commoncap.c
1070 +++ b/security/commoncap.c
1071 @@ -1336,12 +1336,14 @@ int cap_mmap_addr(unsigned long addr)
1075 +EXPORT_SYMBOL_GPL(cap_mmap_addr);
1077 int cap_mmap_file(struct file *file, unsigned long reqprot,
1078 unsigned long prot, unsigned long flags)
1082 +EXPORT_SYMBOL_GPL(cap_mmap_file);
1084 #ifdef CONFIG_SECURITY
1086 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
1087 index cd97929..424fd23 100644
1088 --- a/security/device_cgroup.c
1089 +++ b/security/device_cgroup.c
1091 #include <linux/device_cgroup.h>
1092 #include <linux/cgroup.h>
1093 #include <linux/ctype.h>
1094 +#include <linux/export.h>
1095 #include <linux/list.h>
1096 #include <linux/uaccess.h>
1097 #include <linux/seq_file.h>
1098 @@ -824,3 +825,4 @@ int __devcgroup_check_permission(short type, u32 major, u32 minor,
1102 +EXPORT_SYMBOL_GPL(__devcgroup_check_permission);
1103 diff --git a/security/security.c b/security/security.c
1104 index 68f46d8..3bc1348 100644
1105 --- a/security/security.c
1106 +++ b/security/security.c
1107 @@ -537,6 +537,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
1109 return call_int_hook(path_rmdir, 0, dir, dentry);
1111 +EXPORT_SYMBOL_GPL(security_path_rmdir);
1113 int security_path_unlink(const struct path *dir, struct dentry *dentry)
1115 @@ -553,6 +554,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
1117 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
1119 +EXPORT_SYMBOL_GPL(security_path_symlink);
1121 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1122 struct dentry *new_dentry)
1123 @@ -561,6 +563,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1125 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
1127 +EXPORT_SYMBOL_GPL(security_path_link);
1129 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1130 const struct path *new_dir, struct dentry *new_dentry,
1131 @@ -588,6 +591,7 @@ int security_path_truncate(const struct path *path)
1133 return call_int_hook(path_truncate, 0, path);
1135 +EXPORT_SYMBOL_GPL(security_path_truncate);
1137 int security_path_chmod(const struct path *path, umode_t mode)
1139 @@ -595,6 +599,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1141 return call_int_hook(path_chmod, 0, path, mode);
1143 +EXPORT_SYMBOL_GPL(security_path_chmod);
1145 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1147 @@ -602,6 +607,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1149 return call_int_hook(path_chown, 0, path, uid, gid);
1151 +EXPORT_SYMBOL_GPL(security_path_chown);
1153 int security_path_chroot(const struct path *path)
1155 @@ -687,6 +693,7 @@ int security_inode_readlink(struct dentry *dentry)
1157 return call_int_hook(inode_readlink, 0, dentry);
1159 +EXPORT_SYMBOL_GPL(security_inode_readlink);
1161 int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
1163 @@ -702,6 +709,7 @@ int security_inode_permission(struct inode *inode, int mask)
1165 return call_int_hook(inode_permission, 0, inode, mask);
1167 +EXPORT_SYMBOL_GPL(security_inode_permission);
1169 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1171 @@ -873,6 +881,7 @@ int security_file_permission(struct file *file, int mask)
1173 return fsnotify_perm(file, mask);
1175 +EXPORT_SYMBOL_GPL(security_file_permission);
1177 int security_file_alloc(struct file *file)
1179 @@ -932,6 +941,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
1181 return ima_file_mmap(file, prot);
1183 +EXPORT_SYMBOL_GPL(security_mmap_file);
1185 int security_mmap_addr(unsigned long addr)
1187 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1188 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1189 +++ linux/Documentation/ABI/testing/debugfs-aufs 2018-08-12 23:43:05.450124426 +0200
1191 +What: /debug/aufs/si_<id>/
1193 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1195 + Under /debug/aufs, a directory named si_<id> is created
1196 + per aufs mount, where <id> is a unique id generated
1199 +What: /debug/aufs/si_<id>/plink
1201 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1203 + It has three lines and shows the information about the
1204 + pseudo-link. The first line is a single number
1205 + representing a number of buckets. The second line is a
1206 + number of pseudo-links per buckets (separated by a
1207 + blank). The last line is a single number representing a
1208 + total number of psedo-links.
1209 + When the aufs mount option 'noplink' is specified, it
1210 + will show "1\n0\n0\n".
1212 +What: /debug/aufs/si_<id>/xib
1214 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1216 + It shows the consumed blocks by xib (External Inode Number
1217 + Bitmap), its block size and file size.
1218 + When the aufs mount option 'noxino' is specified, it
1219 + will be empty. About XINO files, see the aufs manual.
1221 +What: /debug/aufs/si_<id>/xi0, xi1 ... xiN and xiN-N
1223 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1225 + It shows the consumed blocks by xino (External Inode Number
1226 + Translation Table), its link count, block size and file
1228 + Due to the file size limit, there may exist multiple
1229 + xino files per branch. In this case, "-N" is added to
1230 + the filename and it corresponds to the index of the
1231 + internal xino array. "-0" is omitted.
1232 + When the aufs mount option 'noxino' is specified, Those
1233 + entries won't exist. About XINO files, see the aufs
1236 +What: /debug/aufs/si_<id>/xigen
1238 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1240 + It shows the consumed blocks by xigen (External Inode
1241 + Generation Table), its block size and file size.
1242 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1244 + When the aufs mount option 'noxino' is specified, it
1245 + will be empty. About XINO files, see the aufs manual.
1246 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1247 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1248 +++ linux/Documentation/ABI/testing/sysfs-aufs 2017-07-29 12:14:25.893041746 +0200
1250 +What: /sys/fs/aufs/si_<id>/
1252 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1254 + Under /sys/fs/aufs, a directory named si_<id> is created
1255 + per aufs mount, where <id> is a unique id generated
1258 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1260 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1262 + It shows the abolute path of a member directory (which
1263 + is called branch) in aufs, and its permission.
1265 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1267 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1269 + It shows the id of a member directory (which is called
1272 +What: /sys/fs/aufs/si_<id>/xi_path
1274 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1276 + It shows the abolute path of XINO (External Inode Number
1277 + Bitmap, Translation Table and Generation Table) file
1278 + even if it is the default path.
1279 + When the aufs mount option 'noxino' is specified, it
1280 + will be empty. About XINO files, see the aufs manual.
1281 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1282 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1283 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2018-04-15 08:49:13.394483860 +0200
1286 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1288 +# This program is free software; you can redistribute it and/or modify
1289 +# it under the terms of the GNU General Public License as published by
1290 +# the Free Software Foundation; either version 2 of the License, or
1291 +# (at your option) any later version.
1293 +# This program is distributed in the hope that it will be useful,
1294 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1295 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1296 +# GNU General Public License for more details.
1298 +# You should have received a copy of the GNU General Public License
1299 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1302 +----------------------------------------
1304 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1305 +1. abbrev. for "advanced multi-layered unification filesystem".
1306 +2. abbrev. for "another unionfs".
1307 +3. abbrev. for "auf das" in German which means "on the" in English.
1308 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1309 + But "Filesystem aufs Filesystem" is hard to understand.
1310 +4. abbrev. for "African Urban Fashion Show".
1312 +AUFS is a filesystem with features:
1313 +- multi layered stackable unification filesystem, the member directory
1314 + is called as a branch.
1315 +- branch permission and attribute, 'readonly', 'real-readonly',
1316 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1318 +- internal "file copy-on-write".
1319 +- logical deletion, whiteout.
1320 +- dynamic branch manipulation, adding, deleting and changing permission.
1321 +- allow bypassing aufs, user's direct branch access.
1322 +- external inode number translation table and bitmap which maintains the
1323 + persistent aufs inode number.
1324 +- seekable directory, including NFS readdir.
1325 +- file mapping, mmap and sharing pages.
1326 +- pseudo-link, hardlink over branches.
1327 +- loopback mounted filesystem as a branch.
1328 +- several policies to select one among multiple writable branches.
1329 +- revert a single systemcall when an error occurs in aufs.
1333 +Multi Layered Stackable Unification Filesystem
1334 +----------------------------------------------------------------------
1335 +Most people already knows what it is.
1336 +It is a filesystem which unifies several directories and provides a
1337 +merged single directory. When users access a file, the access will be
1338 +passed/re-directed/converted (sorry, I am not sure which English word is
1339 +correct) to the real file on the member filesystem. The member
1340 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1341 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1342 +readonly branch is handled by creating 'whiteout' on the upper writable
1345 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1346 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1347 +different approaches to implement the merged-view.
1348 +The former tries putting it into VFS, and the latter implements as a
1349 +separate filesystem.
1350 +(If I misunderstand about these implementations, please let me know and
1351 +I shall correct it. Because it is a long time ago when I read their
1352 +source files last time).
1354 +UnionMount's approach will be able to small, but may be hard to share
1355 +branches between several UnionMount since the whiteout in it is
1356 +implemented in the inode on branch filesystem and always
1357 +shared. According to Bharata's post, readdir does not seems to be
1359 +There are several missing features known in this implementations such as
1360 +- for users, the inode number may change silently. eg. copy-up.
1361 +- link(2) may break by copy-up.
1362 +- read(2) may get an obsoleted filedata (fstat(2) too).
1363 +- fcntl(F_SETLK) may be broken by copy-up.
1364 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1367 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1368 +merged into mainline. This is another implementation of UnionMount as a
1369 +separated filesystem. All the limitations and known problems which
1370 +UnionMount are equally inherited to "overlay" filesystem.
1372 +Unionfs has a longer history. When I started implementing a stackable
1373 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1374 +inode, dentry and file objects and they have an array pointing lower
1375 +same kind objects. After contributing many patches for Unionfs, I
1376 +re-started my project AUFS (Jun 2006).
1378 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1379 +implemented my own ideas, approaches and enhancements and it became
1380 +totally different one.
1382 +Comparing DM snapshot and fs based implementation
1383 +- the number of bytes to be copied between devices is much smaller.
1384 +- the type of filesystem must be one and only.
1385 +- the fs must be writable, no readonly fs, even for the lower original
1386 + device. so the compression fs will not be usable. but if we use
1387 + loopback mount, we may address this issue.
1389 + mount /cdrom/squashfs.img /sq
1390 + losetup /sq/ext2.img
1391 + losetup /somewhere/cow
1392 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1393 +- it will be difficult (or needs more operations) to extract the
1394 + difference between the original device and COW.
1395 +- DM snapshot-merge may help a lot when users try merging. in the
1396 + fs-layer union, users will use rsync(1).
1398 +You may want to read my old paper "Filesystems in LiveCD"
1399 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1402 +Several characters/aspects/persona of aufs
1403 +----------------------------------------------------------------------
1405 +Aufs has several characters, aspects or persona.
1406 +1. a filesystem, callee of VFS helper
1407 +2. sub-VFS, caller of VFS helper for branches
1408 +3. a virtual filesystem which maintains persistent inode number
1409 +4. reader/writer of files on branches such like an application
1411 +1. Callee of VFS Helper
1412 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1413 +unlink(2) from an application reaches sys_unlink() kernel function and
1414 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1415 +calls filesystem specific unlink operation. Actually aufs implements the
1416 +unlink operation but it behaves like a redirector.
1418 +2. Caller of VFS Helper for Branches
1419 +aufs_unlink() passes the unlink request to the branch filesystem as if
1420 +it were called from VFS. So the called unlink operation of the branch
1421 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1422 +every necessary pre/post operation for the branch filesystem.
1423 +- acquire the lock for the parent dir on a branch
1424 +- lookup in a branch
1425 +- revalidate dentry on a branch
1426 +- mnt_want_write() for a branch
1427 +- vfs_unlink() for a branch
1428 +- mnt_drop_write() for a branch
1429 +- release the lock on a branch
1431 +3. Persistent Inode Number
1432 +One of the most important issue for a filesystem is to maintain inode
1433 +numbers. This is particularly important to support exporting a
1434 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1435 +backend block device for its own. But some storage is necessary to
1436 +keep and maintain the inode numbers. It may be a large space and may not
1437 +suit to keep in memory. Aufs rents some space from its first writable
1438 +branch filesystem (by default) and creates file(s) on it. These files
1439 +are created by aufs internally and removed soon (currently) keeping
1441 +Note: Because these files are removed, they are totally gone after
1442 + unmounting aufs. It means the inode numbers are not persistent
1443 + across unmount or reboot. I have a plan to make them really
1444 + persistent which will be important for aufs on NFS server.
1446 +4. Read/Write Files Internally (copy-on-write)
1447 +Because a branch can be readonly, when you write a file on it, aufs will
1448 +"copy-up" it to the upper writable branch internally. And then write the
1449 +originally requested thing to the file. Generally kernel doesn't
1450 +open/read/write file actively. In aufs, even a single write may cause a
1451 +internal "file copy". This behaviour is very similar to cp(1) command.
1453 +Some people may think it is better to pass such work to user space
1454 +helper, instead of doing in kernel space. Actually I am still thinking
1455 +about it. But currently I have implemented it in kernel space.
1456 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1457 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1458 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2018-04-15 08:49:13.394483860 +0200
1461 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1463 +# This program is free software; you can redistribute it and/or modify
1464 +# it under the terms of the GNU General Public License as published by
1465 +# the Free Software Foundation; either version 2 of the License, or
1466 +# (at your option) any later version.
1468 +# This program is distributed in the hope that it will be useful,
1469 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1470 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1471 +# GNU General Public License for more details.
1473 +# You should have received a copy of the GNU General Public License
1474 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1476 +Basic Aufs Internal Structure
1478 +Superblock/Inode/Dentry/File Objects
1479 +----------------------------------------------------------------------
1480 +As like an ordinary filesystem, aufs has its own
1481 +superblock/inode/dentry/file objects. All these objects have a
1482 +dynamically allocated array and store the same kind of pointers to the
1483 +lower filesystem, branch.
1484 +For example, when you build a union with one readwrite branch and one
1485 +readonly, mounted /au, /rw and /ro respectively.
1487 +- /ro/fileA exists but /rw/fileA
1489 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1490 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1491 +- [0] = NULL (because /rw/fileA doesn't exist)
1494 +This style of an array is essentially same to the aufs
1495 +superblock/inode/dentry/file objects.
1497 +Because aufs supports manipulating branches, ie. add/delete/change
1498 +branches dynamically, these objects has its own generation. When
1499 +branches are changed, the generation in aufs superblock is
1500 +incremented. And a generation in other object are compared when it is
1501 +accessed. When a generation in other objects are obsoleted, aufs
1502 +refreshes the internal array.
1506 +----------------------------------------------------------------------
1507 +Additionally aufs superblock has some data for policies to select one
1508 +among multiple writable branches, XIB files, pseudo-links and kobject.
1509 +See below in detail.
1510 +About the policies which supports copy-down a directory, see
1511 +wbr_policy.txt too.
1514 +Branch and XINO(External Inode Number Translation Table)
1515 +----------------------------------------------------------------------
1516 +Every branch has its own xino (external inode number translation table)
1517 +file. The xino file is created and unlinked by aufs internally. When two
1518 +members of a union exist on the same filesystem, they share the single
1520 +The struct of a xino file is simple, just a sequence of aufs inode
1521 +numbers which is indexed by the lower inode number.
1522 +In the above sample, assume the inode number of /ro/fileA is i111 and
1523 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1524 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1526 +When the inode numbers are not contiguous, the xino file will be sparse
1527 +which has a hole in it and doesn't consume as much disk space as it
1528 +might appear. If your branch filesystem consumes disk space for such
1529 +holes, then you should specify 'xino=' option at mounting aufs.
1531 +Aufs has a mount option to free the disk blocks for such holes in XINO
1532 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1533 +meet a problem of disk shortage due to XINO files, then you should try
1534 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1535 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1536 +the holes in XINO files.
1538 +Also a writable branch has three kinds of "whiteout bases". All these
1539 +are existed when the branch is joined to aufs, and their names are
1540 +whiteout-ed doubly, so that users will never see their names in aufs
1542 +1. a regular file which will be hardlinked to all whiteouts.
1543 +2. a directory to store a pseudo-link.
1544 +3. a directory to store an "orphan"-ed file temporary.
1547 + When you remove a file on a readonly branch, aufs handles it as a
1548 + logical deletion and creates a whiteout on the upper writable branch
1549 + as a hardlink of this file in order not to consume inode on the
1552 + See below, Pseudo-link.
1554 + When "fileC" exists on the lower readonly branch only and it is
1555 + opened and removed with its parent dir, and then user writes
1556 + something into it, then aufs copies-up fileC to this
1557 + directory. Because there is no other dir to store fileC. After
1558 + creating a file under this dir, the file is unlinked.
1560 +Because aufs supports manipulating branches, ie. add/delete/change
1561 +dynamically, a branch has its own id. When the branch order changes,
1562 +aufs finds the new index by searching the branch id.
1566 +----------------------------------------------------------------------
1567 +Assume "fileA" exists on the lower readonly branch only and it is
1568 +hardlinked to "fileB" on the branch. When you write something to fileA,
1569 +aufs copies-up it to the upper writable branch. Additionally aufs
1570 +creates a hardlink under the Pseudo-link Directory of the writable
1571 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1572 +simple list. If fileB is read after unlinking fileA, aufs returns
1573 +filedata from the pseudo-link instead of the lower readonly
1574 +branch. Because the pseudo-link is based upon the inode, to keep the
1575 +inode number by xino (see above) is essentially necessary.
1577 +All the hardlinks under the Pseudo-link Directory of the writable branch
1578 +should be restored in a proper location later. Aufs provides a utility
1579 +to do this. The userspace helpers executed at remounting and unmounting
1581 +During this utility is running, it puts aufs into the pseudo-link
1582 +maintenance mode. In this mode, only the process which began the
1583 +maintenance mode (and its child processes) is allowed to operate in
1584 +aufs. Some other processes which are not related to the pseudo-link will
1585 +be allowed to run too, but the rest have to return an error or wait
1586 +until the maintenance mode ends. If a process already acquires an inode
1587 +mutex (in VFS), it has to return an error.
1590 +XIB(external inode number bitmap)
1591 +----------------------------------------------------------------------
1592 +Addition to the xino file per a branch, aufs has an external inode number
1593 +bitmap in a superblock object. It is also an internal file such like a
1595 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1597 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1599 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1600 +reduce the number of consumed disk blocks for these files.
1603 +Virtual or Vertical Dir, and Readdir in Userspace
1604 +----------------------------------------------------------------------
1605 +In order to support multiple layers (branches), aufs readdir operation
1606 +constructs a virtual dir block on memory. For readdir, aufs calls
1607 +vfs_readdir() internally for each dir on branches, merges their entries
1608 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1609 +object. So the file object has its entry list until it is closed. The
1610 +entry list will be updated when the file position is zero and becomes
1611 +obsoleted. This decision is made in aufs automatically.
1613 +The dynamically allocated memory block for the name of entries has a
1614 +unit of 512 bytes (by default) and stores the names contiguously (no
1615 +padding). Another block for each entry is handled by kmem_cache too.
1616 +During building dir blocks, aufs creates hash list and judging whether
1617 +the entry is whiteouted by its upper branch or already listed.
1618 +The merged result is cached in the corresponding inode object and
1619 +maintained by a customizable life-time option.
1621 +Some people may call it can be a security hole or invite DoS attack
1622 +since the opened and once readdir-ed dir (file object) holds its entry
1623 +list and becomes a pressure for system memory. But I'd say it is similar
1624 +to files under /proc or /sys. The virtual files in them also holds a
1625 +memory page (generally) while they are opened. When an idea to reduce
1626 +memory for them is introduced, it will be applied to aufs too.
1627 +For those who really hate this situation, I've developed readdir(3)
1628 +library which operates this merging in userspace. You just need to set
1629 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1630 +kernel space for readdir(3).
1634 +----------------------------------------------------------------------
1635 +Aufs sometimes requires privilege access to a branch. For instance,
1636 +in copy-up/down operation. When a user process is going to make changes
1637 +to a file which exists in the lower readonly branch only, and the mode
1638 +of one of ancestor directories may not be writable by a user
1639 +process. Here aufs copy-up the file with its ancestors and they may
1640 +require privilege to set its owner/group/mode/etc.
1641 +This is a typical case of a application character of aufs (see
1644 +Aufs uses workqueue synchronously for this case. It creates its own
1645 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1646 +passes the request to call mkdir or write (for example), and wait for
1647 +its completion. This approach solves a problem of a signal handler
1649 +If aufs didn't adopt the workqueue and changed the privilege of the
1650 +process, then the process may receive the unexpected SIGXFSZ or other
1653 +Also aufs uses the system global workqueue ("events" kernel thread) too
1654 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1655 +whiteout base and etc. This is unrelated to a privilege.
1656 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1657 +superblock at the beginning, at the same time waits for the completion
1658 +of all queued asynchronous tasks.
1662 +----------------------------------------------------------------------
1663 +The whiteout in aufs is very similar to Unionfs's. That is represented
1664 +by its filename. UnionMount takes an approach of a file mode, but I am
1665 +afraid several utilities (find(1) or something) will have to support it.
1667 +Basically the whiteout represents "logical deletion" which stops aufs to
1668 +lookup further, but also it represents "dir is opaque" which also stop
1671 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1672 +In order to make several functions in a single systemcall to be
1673 +revertible, aufs adopts an approach to rename a directory to a temporary
1674 +unique whiteouted name.
1675 +For example, in rename(2) dir where the target dir already existed, aufs
1676 +renames the target dir to a temporary unique whiteouted name before the
1677 +actual rename on a branch, and then handles other actions (make it opaque,
1678 +update the attributes, etc). If an error happens in these actions, aufs
1679 +simply renames the whiteouted name back and returns an error. If all are
1680 +succeeded, aufs registers a function to remove the whiteouted unique
1681 +temporary name completely and asynchronously to the system global
1686 +----------------------------------------------------------------------
1687 +It is a well-known feature or concept.
1688 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1689 +internally and makes change to the new file on the upper writable branch.
1690 +When the trigger systemcall does not update the timestamps of the parent
1691 +dir, aufs reverts it after copy-up.
1694 +Move-down (aufs3.9 and later)
1695 +----------------------------------------------------------------------
1696 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1697 +the lower readonly branch to the upper writable branch when a user
1698 +changes something about the file.
1699 +"Move-down" is an opposite action of copy-up. Basically this action is
1700 +ran manually instead of automatically and internally.
1701 +For desgin and implementation, aufs has to consider these issues.
1702 +- whiteout for the file may exist on the lower branch.
1703 +- ancestor directories may not exist on the lower branch.
1704 +- diropq for the ancestor directories may exist on the upper branch.
1705 +- free space on the lower branch will reduce.
1706 +- another access to the file may happen during moving-down, including
1707 + UDBA (see "Revalidate Dentry and UDBA").
1708 +- the file should not be hard-linked nor pseudo-linked. they should be
1709 + handled by auplink utility later.
1711 +Sometimes users want to move-down a file from the upper writable branch
1712 +to the lower readonly or writable branch. For instance,
1713 +- the free space of the upper writable branch is going to run out.
1714 +- create a new intermediate branch between the upper and lower branch.
1717 +For this purpose, use "aumvdown" command in aufs-util.git.
1718 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1719 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1720 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2018-04-15 08:49:13.394483860 +0200
1723 +# Copyright (C) 2015-2018 Junjiro R. Okajima
1725 +# This program is free software; you can redistribute it and/or modify
1726 +# it under the terms of the GNU General Public License as published by
1727 +# the Free Software Foundation; either version 2 of the License, or
1728 +# (at your option) any later version.
1730 +# This program is distributed in the hope that it will be useful,
1731 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1732 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1733 +# GNU General Public License for more details.
1735 +# You should have received a copy of the GNU General Public License
1736 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1738 +Support for a branch who has its ->atomic_open()
1739 +----------------------------------------------------------------------
1740 +The filesystems who implement its ->atomic_open() are not majority. For
1741 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1742 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1743 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1744 +sure whether all filesystems who have ->atomic_open() behave like this,
1745 +but NFSv4 surely returns the error.
1747 +In order to support ->atomic_open() for aufs, there are a few
1750 +A. Introduce aufs_atomic_open()
1751 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1753 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1754 + an aufs user Pip Cet's approach
1755 + - calls aufs_create(), VFS finish_open() and notify_change().
1756 + - pass fake-mode to finish_open(), and then correct the mode by
1758 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1759 + - no aufs_atomic_open().
1760 + - aufs_lookup() registers the TID to an aufs internal object.
1761 + - aufs_create() does nothing when the matching TID is registered, but
1762 + registers the mode.
1763 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1764 + TID is registered.
1765 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1767 + - no aufs_atomic_open().
1768 + - aufs_create() registers the TID to an internal object. this info
1769 + represents "this process created this file just now."
1770 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1771 + registered TID and re-try open() with superuser's credential.
1773 +Pros and cons for each approach.
1776 + - straightforward but highly depends upon VFS internal.
1777 + - the atomic behavaiour is kept.
1778 + - some of parameters such as nameidata are hard to reproduce for
1782 + - easy to implement.
1783 + - the atomic behavaiour is lost.
1785 + - the atomic behavaiour is kept.
1786 + - dirty and tricky.
1787 + - VFS checks whether the file is created correctly after calling
1788 + ->create(), which means this approach doesn't work.
1790 + - easy to implement.
1791 + - the atomic behavaiour is lost.
1792 + - to open a file with superuser's credential and give it to a user
1793 + process is a bad idea, since the file object keeps the credential
1794 + in it. It may affect LSM or something. This approach doesn't work
1797 +The approach A is ideal, but it hard to implement. So here is a
1798 +variation of A, which is to be implemented.
1800 +A-1. Introduce aufs_atomic_open()
1801 + - calls branch fs ->atomic_open() if exists. otherwise calls
1802 + vfs_create() and finish_open().
1803 + - the demerit is that the several checks after branch fs
1804 + ->atomic_open() are lost. in the ordinary case, the checks are
1805 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1806 + be implemented in aufs, but not all I am afraid.
1807 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1808 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1809 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2018-04-15 08:49:13.394483860 +0200
1812 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1814 +# This program is free software; you can redistribute it and/or modify
1815 +# it under the terms of the GNU General Public License as published by
1816 +# the Free Software Foundation; either version 2 of the License, or
1817 +# (at your option) any later version.
1819 +# This program is distributed in the hope that it will be useful,
1820 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1821 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1822 +# GNU General Public License for more details.
1824 +# You should have received a copy of the GNU General Public License
1825 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1828 +----------------------------------------------------------------------
1829 +Since aufs has a character of sub-VFS (see Introduction), it operates
1830 +lookup for branches as VFS does. It may be a heavy work. But almost all
1831 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1832 +directly connected to its parent. Digging down the directory hierarchy
1833 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1836 +When a branch is a remote filesystem, aufs basically relies upon its
1837 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1839 +For d_revalidate, aufs implements three levels of revalidate tests. See
1840 +"Revalidate Dentry and UDBA" in detail.
1843 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1844 +----------------------------------------------------------------------
1845 +Let's try case study.
1846 +- aufs has two branches, upper readwrite and lower readonly.
1848 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1849 +- user invoked "chmod a+rx /au/dirA"
1850 +- the internal copy-up is activated and "/rw/dirA" is created and its
1851 + permission bits are set to world readable.
1852 +- then "/au/dirA" becomes world readable?
1854 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1855 +or it may be a natively readonly filesystem. If aufs respects the lower
1856 +branch, it should not respond readdir request from other users. But user
1857 +allowed it by chmod. Should really aufs rejects showing the entries
1860 +To be honest, I don't have a good solution for this case. So aufs
1861 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1863 +When dirperm1 is specified, aufs checks only the highest one for the
1864 +directory permission, and shows the entries. Otherwise, as usual, checks
1865 +every dir existing on all branches and rejects the request.
1867 +As a side effect, dirperm1 option improves the performance of aufs
1868 +because the number of permission check is reduced when the number of
1872 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1873 +----------------------------------------------------------------------
1874 +Generally VFS helpers re-validate a dentry as a part of lookup.
1875 +0. digging down the directory hierarchy.
1876 +1. lock the parent dir by its i_mutex.
1877 +2. lookup the final (child) entry.
1879 +4. call the actual operation (create, unlink, etc.)
1880 +5. unlock the parent dir
1882 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1883 +called. Actually aufs implements it and checks the dentry on a branch is
1885 +But it is not enough. Because aufs has to release the lock for the
1886 +parent dir on a branch at the end of ->lookup() (step 2) and
1887 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1889 +If the file on a branch is changed directly, eg. bypassing aufs, after
1890 +aufs released the lock, then the subsequent operation may cause
1891 +something unpleasant result.
1893 +This situation is a result of VFS architecture, ->lookup() and
1894 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1895 +design from VFS's point of view. It is just not suitable for sub-VFS
1898 +Aufs supports such case by three level of revalidation which is
1899 +selectable by user.
1900 +1. Simple Revalidate
1901 + Addition to the native flow in VFS's, confirm the child-parent
1902 + relationship on the branch just after locking the parent dir on the
1903 + branch in the "actual operation" (step 4). When this validation
1904 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1905 + checks the validation of the dentry on branches.
1906 +2. Monitor Changes Internally by Inotify/Fsnotify
1907 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1908 + the dentry on the branch, and returns EBUSY if it finds different
1910 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1911 + during it is in cache. When the event is notified, aufs registers a
1912 + function to kernel 'events' thread by schedule_work(). And the
1913 + function sets some special status to the cached aufs dentry and inode
1914 + private data. If they are not cached, then aufs has nothing to
1915 + do. When the same file is accessed through aufs (step 0-3) later,
1916 + aufs will detect the status and refresh all necessary data.
1917 + In this mode, aufs has to ignore the event which is fired by aufs
1919 +3. No Extra Validation
1920 + This is the simplest test and doesn't add any additional revalidation
1921 + test, and skip the revalidation in step 4. It is useful and improves
1922 + aufs performance when system surely hide the aufs branches from user,
1923 + by over-mounting something (or another method).
1924 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1925 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1926 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2018-04-15 08:49:13.394483860 +0200
1929 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1931 +# This program is free software; you can redistribute it and/or modify
1932 +# it under the terms of the GNU General Public License as published by
1933 +# the Free Software Foundation; either version 2 of the License, or
1934 +# (at your option) any later version.
1936 +# This program is distributed in the hope that it will be useful,
1937 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1938 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1939 +# GNU General Public License for more details.
1941 +# You should have received a copy of the GNU General Public License
1942 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1944 +Branch Manipulation
1946 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1947 +and changing its permission/attribute, there are a lot of works to do.
1951 +----------------------------------------------------------------------
1952 +o Confirm the adding dir exists outside of aufs, including loopback
1953 + mount, and its various attributes.
1954 +o Initialize the xino file and whiteout bases if necessary.
1957 +o Check the owner/group/mode of the directory
1958 + When the owner/group/mode of the adding directory differs from the
1959 + existing branch, aufs issues a warning because it may impose a
1961 + For example, when a upper writable branch has a world writable empty
1962 + top directory, a malicious user can create any files on the writable
1963 + branch directly, like copy-up and modify manually. If something like
1964 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1965 + writable branch, and the writable branch is world-writable, then a
1966 + malicious guy may create /etc/passwd on the writable branch directly
1967 + and the infected file will be valid in aufs.
1968 + I am afraid it can be a security issue, but aufs can do nothing except
1969 + producing a warning.
1973 +----------------------------------------------------------------------
1974 +o Confirm the deleting branch is not busy
1975 + To be general, there is one merit to adopt "remount" interface to
1976 + manipulate branches. It is to discard caches. At deleting a branch,
1977 + aufs checks the still cached (and connected) dentries and inodes. If
1978 + there are any, then they are all in-use. An inode without its
1979 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1981 + For the cached one, aufs checks whether the same named entry exists on
1983 + If the cached one is a directory, because aufs provides a merged view
1984 + to users, as long as one dir is left on any branch aufs can show the
1985 + dir to users. In this case, the branch can be removed from aufs.
1986 + Otherwise aufs rejects deleting the branch.
1988 + If any file on the deleting branch is opened by aufs, then aufs
1992 +Modify the Permission of a Branch
1993 +----------------------------------------------------------------------
1994 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1997 +o rw --> ro: Confirm the modifying branch is not busy
1998 + Aufs rejects the request if any of these conditions are true.
1999 + - a file on the branch is mmap-ed.
2000 + - a regular file on the branch is opened for write and there is no
2001 + same named entry on the upper branch.
2002 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
2003 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
2004 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2018-04-15 08:49:13.394483860 +0200
2007 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2009 +# This program is free software; you can redistribute it and/or modify
2010 +# it under the terms of the GNU General Public License as published by
2011 +# the Free Software Foundation; either version 2 of the License, or
2012 +# (at your option) any later version.
2014 +# This program is distributed in the hope that it will be useful,
2015 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2016 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2017 +# GNU General Public License for more details.
2019 +# You should have received a copy of the GNU General Public License
2020 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2022 +Policies to Select One among Multiple Writable Branches
2023 +----------------------------------------------------------------------
2024 +When the number of writable branch is more than one, aufs has to decide
2025 +the target branch for file creation or copy-up. By default, the highest
2026 +writable branch which has the parent (or ancestor) dir of the target
2027 +file is chosen (top-down-parent policy).
2028 +By user's request, aufs implements some other policies to select the
2029 +writable branch, for file creation several policies, round-robin,
2030 +most-free-space, and other policies. For copy-up, top-down-parent,
2031 +bottom-up-parent, bottom-up and others.
2033 +As expected, the round-robin policy selects the branch in circular. When
2034 +you have two writable branches and creates 10 new files, 5 files will be
2035 +created for each branch. mkdir(2) systemcall is an exception. When you
2036 +create 10 new directories, all will be created on the same branch.
2037 +And the most-free-space policy selects the one which has most free
2038 +space among the writable branches. The amount of free space will be
2039 +checked by aufs internally, and users can specify its time interval.
2041 +The policies for copy-up is more simple,
2042 +top-down-parent is equivalent to the same named on in create policy,
2043 +bottom-up-parent selects the writable branch where the parent dir
2044 +exists and the nearest upper one from the copyup-source,
2045 +bottom-up selects the nearest upper writable branch from the
2046 +copyup-source, regardless the existence of the parent dir.
2048 +There are some rules or exceptions to apply these policies.
2049 +- If there is a readonly branch above the policy-selected branch and
2050 + the parent dir is marked as opaque (a variation of whiteout), or the
2051 + target (creating) file is whiteout-ed on the upper readonly branch,
2052 + then the result of the policy is ignored and the target file will be
2053 + created on the nearest upper writable branch than the readonly branch.
2054 +- If there is a writable branch above the policy-selected branch and
2055 + the parent dir is marked as opaque or the target file is whiteouted
2056 + on the branch, then the result of the policy is ignored and the target
2057 + file will be created on the highest one among the upper writable
2058 + branches who has diropq or whiteout. In case of whiteout, aufs removes
2060 +- link(2) and rename(2) systemcalls are exceptions in every policy.
2061 + They try selecting the branch where the source exists as possible
2062 + since copyup a large file will take long time. If it can't be,
2063 + ie. the branch where the source exists is readonly, then they will
2064 + follow the copyup policy.
2065 +- There is an exception for rename(2) when the target exists.
2066 + If the rename target exists, aufs compares the index of the branches
2067 + where the source and the target exists and selects the higher
2068 + one. If the selected branch is readonly, then aufs follows the
2070 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
2071 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
2072 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2018-04-15 08:49:13.394483860 +0200
2075 +// to view this graph, run dot(1) command in GRAPHVIZ.
2079 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
2083 +aufs_rename -> whinfo [label="store/remove"];
2086 +inode_list [label="h_inum list in branch\ncache"];
2089 +whinode [label="h_inum list file"];
2092 +brmgmt [label="br_add/del/mod/umount"];
2094 +brmgmt -> inode_list [label="create/remove"];
2095 +brmgmt -> whinode [label="load/store"];
2097 +inode_list -> whinode [style=dashed,dir=both];
2099 +aufs_rename -> inode_list [label="add/del"];
2101 +aufs_lookup -> inode_list [label="search"];
2103 +aufs_lookup -> whinfo [label="load/remove"];
2105 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
2106 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
2107 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2018-04-15 08:49:13.394483860 +0200
2110 +# Copyright (C) 2017-2018 Junjiro R. Okajima
2112 +# This program is free software; you can redistribute it and/or modify
2113 +# it under the terms of the GNU General Public License as published by
2114 +# the Free Software Foundation; either version 2 of the License, or
2115 +# (at your option) any later version.
2117 +# This program is distributed in the hope that it will be useful,
2118 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2119 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2120 +# GNU General Public License for more details.
2122 +# You should have received a copy of the GNU General Public License
2123 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2125 +Special handling for renaming a directory (DIRREN)
2126 +----------------------------------------------------------------------
2127 +First, let's assume we have a simple usecase.
2131 +- /ro/dirA and /ro/dirA/file exist too
2132 +- there is no dirB on both branches
2133 +- a user issues rename("dirA", "dirB")
2135 +Now, what should aufs behave against this rename(2)?
2136 +There are a few possible cases.
2139 + since dirA exists on a readonly branch which cannot be renamed.
2141 + it is possible to copy-up dirA (only the dir itself), but the child
2142 + entries ("file" in this case) should not be. it must be a bad
2143 + approach to copy-up recursively.
2144 +C. returns a success.
2145 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
2146 + is a violation of aufs' policy.
2147 +D. construct an extra information which indicates that /ro/dirA should
2148 + be handled as the name of dirB.
2149 + overlayfs has a similar feature called REDIRECT.
2151 +Until now, aufs implements the case B only which returns EXDEV, and
2152 +expects the userspace application behaves like mv(1) which tries
2153 +issueing rename(2) recursively.
2155 +A new aufs feature called DIRREN is introduced which implements the case
2156 +D. There are several "extra information" added.
2158 +1. detailed info per renamed directory
2159 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
2160 +2. the inode-number list of directories on a branch
2161 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
2163 +The filename of "detailed info per directory" represents the lower
2164 +branch, and its format is
2165 +- a type of the branch id
2167 + + uuid (not implemented yet)
2170 +- the inode-number of the branch root dir
2172 +And it contains these info in a single regular file.
2174 +- branch's inode-number of the logically renamed dir
2175 +- the name of the before-renamed dir
2177 +The "detailed info per directory" file is created in aufs rename(2), and
2178 +loaded in any lookup.
2179 +The info is considered in lookup for the matching case only. Here
2180 +"matching" means that the root of branch (in the info filename) is same
2181 +to the current looking-up branch. After looking-up the before-renamed
2182 +name, the inode-number is compared. And the matched dentry is used.
2184 +The "inode-number list of directories" is a regular file which contains
2185 +simply the inode-numbers on the branch. The file is created or updated
2186 +in removing the branch, and loaded in adding the branch. Its lifetime is
2187 +equal to the branch.
2188 +The list is refered in lookup, and when the current target inode is
2189 +found in the list, the aufs tries loading the "detailed info per
2190 +directory" and get the changed and valid name of the dir.
2192 +Theoretically these "extra informaiton" may be able to be put into XATTR
2193 +in the dir inode. But aufs doesn't choose this way because
2194 +1. XATTR may not be supported by the branch (or its configuration)
2195 +2. XATTR may have its size limit.
2196 +3. XATTR may be less easy to convert than a regular file, when the
2197 + format of the info is changed in the future.
2198 +At the same time, I agree that the regular file approach is much slower
2199 +than XATTR approach. So, in the future, aufs may take the XATTR or other
2202 +This DIRREN feature is enabled by aufs configuration, and is activated
2203 +by a new mount option.
2205 +For the more complicated case, there is a work with UDBA option, which
2206 +is to dected the direct access to the branches (by-passing aufs) and to
2207 +maintain the cashes in aufs. Since a single cached aufs dentry may
2208 +contains two names, before- and after-rename, the name comparision in
2209 +UDBA handler may not work correctly. In this case, the behaviour will be
2210 +equivalen to udba=reval case.
2211 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
2212 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
2213 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2018-04-15 08:49:13.394483860 +0200
2216 +# Copyright (C) 2011-2018 Junjiro R. Okajima
2218 +# This program is free software; you can redistribute it and/or modify
2219 +# it under the terms of the GNU General Public License as published by
2220 +# the Free Software Foundation; either version 2 of the License, or
2221 +# (at your option) any later version.
2223 +# This program is distributed in the hope that it will be useful,
2224 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2225 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2226 +# GNU General Public License for more details.
2228 +# You should have received a copy of the GNU General Public License
2229 +# along with this program; if not, write to the Free Software
2230 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2233 +File-based Hierarchical Storage Management (FHSM)
2234 +----------------------------------------------------------------------
2235 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2236 +storage world. Aufs provides this feature as file-based with multiple
2237 +writable branches, based upon the principle of "Colder, the Lower".
2238 +Here the word "colder" means that the less used files, and "lower" means
2239 +that the position in the order of the stacked branches vertically.
2240 +These multiple writable branches are prioritized, ie. the topmost one
2241 +should be the fastest drive and be used heavily.
2243 +o Characters in aufs FHSM story
2244 +- aufs itself and a new branch attribute.
2245 +- a new ioctl interface to move-down and to establish a connection with
2246 + the daemon ("move-down" is a converse of "copy-up").
2247 +- userspace tool and daemon.
2249 +The userspace daemon establishes a connection with aufs and waits for
2250 +the notification. The notified information is very similar to struct
2251 +statfs containing the number of consumed blocks and inodes.
2252 +When the consumed blocks/inodes of a branch exceeds the user-specified
2253 +upper watermark, the daemon activates its move-down process until the
2254 +consumed blocks/inodes reaches the user-specified lower watermark.
2256 +The actual move-down is done by aufs based upon the request from
2257 +user-space since we need to maintain the inode number and the internal
2258 +pointer arrays in aufs.
2260 +Currently aufs FHSM handles the regular files only. Additionally they
2261 +must not be hard-linked nor pseudo-linked.
2264 +o Cowork of aufs and the user-space daemon
2265 + During the userspace daemon established the connection, aufs sends a
2266 + small notification to it whenever aufs writes something into the
2267 + writable branch. But it may cost high since aufs issues statfs(2)
2268 + internally. So user can specify a new option to cache the
2269 + info. Actually the notification is controlled by these factors.
2270 + + the specified cache time.
2271 + + classified as "force" by aufs internally.
2272 + Until the specified time expires, aufs doesn't send the info
2273 + except the forced cases. When aufs decide forcing, the info is always
2274 + notified to userspace.
2275 + For example, the number of free inodes is generally large enough and
2276 + the shortage of it happens rarely. So aufs doesn't force the
2277 + notification when creating a new file, directory and others. This is
2278 + the typical case which aufs doesn't force.
2279 + When aufs writes the actual filedata and the files consumes any of new
2280 + blocks, the aufs forces notifying.
2283 +o Interfaces in aufs
2284 +- New branch attribute.
2286 + Specifies that the branch is managed by FHSM feature. In other word,
2287 + participant in the FHSM.
2288 + When nofhsm is set to the branch, it will not be the source/target
2289 + branch of the move-down operation. This attribute is set
2290 + independently from coo and moo attributes, and if you want full
2291 + FHSM, you should specify them as well.
2292 +- New mount option.
2294 + Specifies a second to suppress many less important info to be
2297 + + AUFS_CTL_FHSM_FD
2298 + create a new file descriptor which userspace can read the notification
2299 + (a subset of struct statfs) from aufs.
2300 +- Module parameter 'brs'
2301 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2303 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2304 + When there are two or more branches with fhsm attributes,
2305 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2306 + terminates it. As a result of remounting and branch-manipulation, the
2307 + number of branches with fhsm attribute can be one. In this case,
2308 + /sbin/mount.aufs will terminate the user-space daemon.
2311 +Finally the operation is done as these steps in kernel-space.
2313 + + no one else is using the file.
2314 + + the file is not hard-linked.
2315 + + the file is not pseudo-linked.
2316 + + the file is a regular file.
2317 + + the parent dir is not opaqued.
2318 +- find the target writable branch.
2319 +- make sure the file is not whiteout-ed by the upper (than the target)
2321 +- make the parent dir on the target branch.
2322 +- mutex lock the inode on the branch.
2323 +- unlink the whiteout on the target branch (if exists).
2324 +- lookup and create the whiteout-ed temporary name on the target branch.
2325 +- copy the file as the whiteout-ed temporary name on the target branch.
2326 +- rename the whiteout-ed temporary name to the original name.
2327 +- unlink the file on the source branch.
2328 +- maintain the internal pointer array and the external inode number
2330 +- maintain the timestamps and other attributes of the parent dir and the
2333 +And of course, in every step, an error may happen. So the operation
2334 +should restore the original file state after an error happens.
2335 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2336 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2337 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2018-04-15 08:49:13.394483860 +0200
2340 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2342 +# This program is free software; you can redistribute it and/or modify
2343 +# it under the terms of the GNU General Public License as published by
2344 +# the Free Software Foundation; either version 2 of the License, or
2345 +# (at your option) any later version.
2347 +# This program is distributed in the hope that it will be useful,
2348 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2349 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2350 +# GNU General Public License for more details.
2352 +# You should have received a copy of the GNU General Public License
2353 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2355 +mmap(2) -- File Memory Mapping
2356 +----------------------------------------------------------------------
2357 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2358 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2360 +This approach is simple and good, but there is one problem.
2361 +Under /proc, several entries show the mmapped files by its path (with
2362 +device and inode number), and the printed path will be the path on the
2363 +branch fs's instead of virtual aufs's.
2364 +This is not a problem in most cases, but some utilities lsof(1) (and its
2365 +user) may expect the path on aufs.
2367 +To address this issue, aufs adds a new member called vm_prfile in struct
2368 +vm_area_struct (and struct vm_region). The original vm_file points to
2369 +the file on the branch fs in order to handle everything correctly as
2370 +usual. The new vm_prfile points to a virtual file in aufs, and the
2371 +show-functions in procfs refers to vm_prfile if it is set.
2372 +Also we need to maintain several other places where touching vm_file
2374 +- fork()/clone() copies vma and the reference count of vm_file is
2376 +- merging vma maintains the ref count too.
2378 +This is not a good approach. It just fakes the printed path. But it
2379 +leaves all behaviour around f_mapping unchanged. This is surely an
2381 +Actually aufs had adopted another complicated approach which calls
2382 +generic_file_mmap() and handles struct vm_operations_struct. In this
2383 +approach, aufs met a hard problem and I could not solve it without
2384 +switching the approach.
2386 +There may be one more another approach which is
2387 +- bind-mount the branch-root onto the aufs-root internally
2388 +- grab the new vfsmount (ie. struct mount)
2389 +- lazy-umount the branch-root internally
2390 +- in open(2) the aufs-file, open the branch-file with the hidden
2391 + vfsmount (instead of the original branch's vfsmount)
2392 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2393 + but it may be possible from userspace by the mount helper.
2395 +Adding the internal hidden vfsmount and using it in opening a file, the
2396 +file path under /proc will be printed correctly. This approach looks
2397 +smarter, but is not possible I am afraid.
2398 +- aufs-root may be bind-mount later. when it happens, another hidden
2399 + vfsmount will be required.
2400 +- it is hard to get the chance to bind-mount and lazy-umount
2401 + + in kernel-space, FS can have vfsmount in open(2) via
2402 + file->f_path, and aufs can know its vfsmount. But several locks are
2403 + already acquired, and if aufs tries to bind-mount and lazy-umount
2404 + here, then it may cause a deadlock.
2405 + + in user-space, bind-mount doesn't invoke the mount helper.
2406 +- since /proc shows dev and ino, aufs has to give vma these info. it
2407 + means a new member vm_prinode will be necessary. this is essentially
2408 + equivalent to vm_prfile described above.
2410 +I have to give up this "looks-smater" approach.
2411 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2412 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2413 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2018-04-15 08:49:13.394483860 +0200
2416 +# Copyright (C) 2014-2018 Junjiro R. Okajima
2418 +# This program is free software; you can redistribute it and/or modify
2419 +# it under the terms of the GNU General Public License as published by
2420 +# the Free Software Foundation; either version 2 of the License, or
2421 +# (at your option) any later version.
2423 +# This program is distributed in the hope that it will be useful,
2424 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2425 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2426 +# GNU General Public License for more details.
2428 +# You should have received a copy of the GNU General Public License
2429 +# along with this program; if not, write to the Free Software
2430 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2433 +Listing XATTR/EA and getting the value
2434 +----------------------------------------------------------------------
2435 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2436 +shows the values from the topmost existing file. This behaviour is good
2437 +for the non-dir entries since the bahaviour exactly matches the shown
2438 +information. But for the directories, aufs considers all the same named
2439 +entries on the lower branches. Which means, if one of the lower entry
2440 +rejects readdir call, then aufs returns an error even if the topmost
2441 +entry allows it. This behaviour is necessary to respect the branch fs's
2442 +security, but can make users confused since the user-visible standard
2443 +attributes don't match the behaviour.
2444 +To address this issue, aufs has a mount option called dirperm1 which
2445 +checks the permission for the topmost entry only, and ignores the lower
2446 +entry's permission.
2448 +A similar issue can happen around XATTR.
2449 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2450 +always set. Otherwise these very unpleasant situation would happen.
2451 +- listxattr(2) may return the duplicated entries.
2452 +- users may not be able to remove or reset the XATTR forever,
2455 +XATTR/EA support in the internal (copy,move)-(up,down)
2456 +----------------------------------------------------------------------
2457 +Generally the extended attributes of inode are categorized as these.
2458 +- "security" for LSM and capability.
2459 +- "system" for posix ACL, 'acl' mount option is required for the branch
2461 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2462 +- "user" for userspace, 'user_xattr' mount option is required for the
2463 + branch fs generally.
2465 +Moreover there are some other categories. Aufs handles these rather
2466 +unpopular categories as the ordinary ones, ie. there is no special
2467 +condition nor exception.
2469 +In copy-up, the support for XATTR on the dst branch may differ from the
2470 +src branch. In this case, the copy-up operation will get an error and
2471 +the original user operation which triggered the copy-up will fail. It
2472 +can happen that even all copy-up will fail.
2473 +When both of src and dst branches support XATTR and if an error occurs
2474 +during copying XATTR, then the copy-up should fail obviously. That is a
2475 +good reason and aufs should return an error to userspace. But when only
2476 +the src branch support that XATTR, aufs should not return an error.
2477 +For example, the src branch supports ACL but the dst branch doesn't
2478 +because the dst branch may natively un-support it or temporary
2479 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2480 +may NOT return an error even if the XATTR is not supported. It is
2481 +totally up to the branch fs.
2483 +Anyway when the aufs internal copy-up gets an error from the dst branch
2484 +fs, then aufs tries removing the just copied entry and returns the error
2485 +to the userspace. The worst case of this situation will be all copy-up
2488 +For the copy-up operation, there two basic approaches.
2489 +- copy the specified XATTR only (by category above), and return the
2490 + error unconditionally if it happens.
2491 +- copy all XATTR, and ignore the error on the specified category only.
2493 +In order to support XATTR and to implement the correct behaviour, aufs
2494 +chooses the latter approach and introduces some new branch attributes,
2495 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2496 +They correspond to the XATTR namespaces (see above). Additionally, to be
2497 +convenient, "icex" is also provided which means all "icex*" attributes
2498 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2500 +The meaning of these attributes is to ignore the error from setting
2501 +XATTR on that branch.
2502 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2503 +error from the dst branch according to the specified attributes.
2505 +Some XATTR may have its default value. The default value may come from
2506 +the parent dir or the environment. If the default value is set at the
2507 +file creating-time, it will be overwritten by copy-up.
2508 +Some contradiction may happen I am afraid.
2509 +Do we need another attribute to stop copying XATTR? I am unsure. For
2510 +now, aufs implements the branch attributes to ignore the error.
2511 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2512 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2513 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2018-04-15 08:49:13.394483860 +0200
2516 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2518 +# This program is free software; you can redistribute it and/or modify
2519 +# it under the terms of the GNU General Public License as published by
2520 +# the Free Software Foundation; either version 2 of the License, or
2521 +# (at your option) any later version.
2523 +# This program is distributed in the hope that it will be useful,
2524 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2525 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2526 +# GNU General Public License for more details.
2528 +# You should have received a copy of the GNU General Public License
2529 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2531 +Export Aufs via NFS
2532 +----------------------------------------------------------------------
2533 +Here is an approach.
2534 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2536 +- iget_locked(): initialize aufs inode generation for a new inode, and
2537 + store it in xigen file.
2538 +- destroy_inode(): increment aufs inode generation and store it in xigen
2539 + file. it is necessary even if it is not unlinked, because any data of
2540 + inode may be changed by UDBA.
2541 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2542 + build file handle by
2543 + + branch id (4 bytes)
2544 + + superblock generation (4 bytes)
2545 + + inode number (4 or 8 bytes)
2546 + + parent dir inode number (4 or 8 bytes)
2547 + + inode generation (4 bytes))
2548 + + return value of exportfs_encode_fh() for the parent on a branch (4
2550 + + file handle for a branch (by exportfs_encode_fh())
2552 + + find the index of a branch from its id in handle, and check it is
2553 + still exist in aufs.
2554 + + 1st level: get the inode number from handle and search it in cache.
2555 + + 2nd level: if not found in cache, get the parent inode number from
2556 + the handle and search it in cache. and then open the found parent
2557 + dir, find the matching inode number by vfs_readdir() and get its
2558 + name, and call lookup_one_len() for the target dentry.
2559 + + 3rd level: if the parent dir is not cached, call
2560 + exportfs_decode_fh() for a branch and get the parent on a branch,
2561 + build a pathname of it, convert it a pathname in aufs, call
2562 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2564 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2565 + for every branch, but not itself. to get this, (currently) aufs
2566 + searches in current->nsproxy->mnt_ns list. it may not be a good
2567 + idea, but I didn't get other approach.
2568 + + test the generation of the gotten inode.
2569 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2570 + convert it into ESTALE for NFSD.
2571 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2572 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2573 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2574 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2575 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2018-04-15 08:49:13.394483860 +0200
2578 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2580 +# This program is free software; you can redistribute it and/or modify
2581 +# it under the terms of the GNU General Public License as published by
2582 +# the Free Software Foundation; either version 2 of the License, or
2583 +# (at your option) any later version.
2585 +# This program is distributed in the hope that it will be useful,
2586 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2587 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2588 +# GNU General Public License for more details.
2590 +# You should have received a copy of the GNU General Public License
2591 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2593 +Show Whiteout Mode (shwh)
2594 +----------------------------------------------------------------------
2595 +Generally aufs hides the name of whiteouts. But in some cases, to show
2596 +them is very useful for users. For instance, creating a new middle layer
2597 +(branch) by merging existing layers.
2599 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2600 +When you have three branches,
2601 +- Bottom: 'system', squashfs (underlying base system), read-only
2602 +- Middle: 'mods', squashfs, read-only
2603 +- Top: 'overlay', ram (tmpfs), read-write
2605 +The top layer is loaded at boot time and saved at shutdown, to preserve
2606 +the changes made to the system during the session.
2607 +When larger changes have been made, or smaller changes have accumulated,
2608 +the size of the saved top layer data grows. At this point, it would be
2609 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2610 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2611 +restoring save and load speed.
2613 +This merging is simplified by the use of another aufs mount, of just the
2614 +two overlay branches using the 'shwh' option.
2615 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2616 + aufs /livesys/merge_union
2618 +A merged view of these two branches is then available at
2619 +/livesys/merge_union, and the new feature is that the whiteouts are
2621 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2622 +writing to all branches. Also the default mode for all branches is 'ro'.
2623 +It is now possible to save the combined contents of the two overlay
2624 +branches to a new squashfs, e.g.:
2625 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2627 +This new squashfs archive can be stored on the boot device and the
2628 +initramfs will use it to replace the old one at the next boot.
2629 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2630 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2631 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2018-04-15 08:49:13.394483860 +0200
2634 +# Copyright (C) 2010-2018 Junjiro R. Okajima
2636 +# This program is free software; you can redistribute it and/or modify
2637 +# it under the terms of the GNU General Public License as published by
2638 +# the Free Software Foundation; either version 2 of the License, or
2639 +# (at your option) any later version.
2641 +# This program is distributed in the hope that it will be useful,
2642 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2643 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2644 +# GNU General Public License for more details.
2646 +# You should have received a copy of the GNU General Public License
2647 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2649 +Dynamically customizable FS operations
2650 +----------------------------------------------------------------------
2651 +Generally FS operations (struct inode_operations, struct
2652 +address_space_operations, struct file_operations, etc.) are defined as
2653 +"static const", but it never means that FS have only one set of
2654 +operation. Some FS have multiple sets of them. For instance, ext2 has
2655 +three sets, one for XIP, for NOBH, and for normal.
2656 +Since aufs overrides and redirects these operations, sometimes aufs has
2657 +to change its behaviour according to the branch FS type. More importantly
2658 +VFS acts differently if a function (member in the struct) is set or
2659 +not. It means aufs should have several sets of operations and select one
2660 +among them according to the branch FS definition.
2662 +In order to solve this problem and not to affect the behaviour of VFS,
2663 +aufs defines these operations dynamically. For instance, aufs defines
2664 +dummy direct_IO function for struct address_space_operations, but it may
2665 +not be set to the address_space_operations actually. When the branch FS
2666 +doesn't have it, aufs doesn't set it to its address_space_operations
2667 +while the function definition itself is still alive. So the behaviour
2668 +itself will not change, and it will return an error when direct_IO is
2671 +The lifetime of these dynamically generated operation object is
2672 +maintained by aufs branch object. When the branch is removed from aufs,
2673 +the reference counter of the object is decremented. When it reaches
2674 +zero, the dynamically generated operation object will be freed.
2676 +This approach is designed to support AIO (io_submit), Direct I/O and
2678 +Currently this approach is applied to address_space_operations for
2679 +regular files only.
2680 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2681 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2682 +++ linux/Documentation/filesystems/aufs/README 2018-06-15 11:15:15.400449109 +0200
2685 +Aufs4 -- advanced multi layered unification filesystem version 4.x
2691 +----------------------------------------
2692 +In the early days, aufs was entirely re-designed and re-implemented
2693 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2694 +improvements and implementations, it becomes totally different from
2695 +Unionfs while keeping the basic features.
2696 +Recently, Unionfs Version 2.x series begin taking some of the same
2697 +approaches to aufs1's.
2698 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2699 +University and his team.
2701 +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3.
2702 +If you want older kernel version support, try aufs2-2.6.git or
2703 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2705 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2706 + According to Christoph Hellwig, linux rejects all union-type
2707 + filesystems but UnionMount.
2708 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2710 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2711 + UnionMount, and he pointed out an issue around a directory mutex
2712 + lock and aufs addressed it. But it is still unsure whether aufs will
2713 + be merged (or any other union solution).
2714 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2718 +----------------------------------------
2719 +- unite several directories into a single virtual filesystem. The member
2720 + directory is called as a branch.
2721 +- you can specify the permission flags to the branch, which are 'readonly',
2722 + 'readwrite' and 'whiteout-able.'
2723 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2724 + readonly branch are modifiable logically.
2725 +- dynamic branch manipulation, add, del.
2728 +Also there are many enhancements in aufs, such as:
2729 +- test only the highest one for the directory permission (dirperm1)
2730 +- copyup on open (coo=)
2731 +- 'move' policy for copy-up between two writable branches, after
2732 + checking free space.
2734 +- readdir(3) in userspace.
2735 +- keep inode number by external inode number table
2736 +- keep the timestamps of file/dir in internal copyup operation
2737 +- seekable directory, supporting NFS readdir.
2738 +- whiteout is hardlinked in order to reduce the consumption of inodes
2740 +- do not copyup, nor create a whiteout when it is unnecessary
2741 +- revert a single systemcall when an error occurs in aufs
2742 +- remount interface instead of ioctl
2743 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2744 +- loopback mounted filesystem as a branch
2745 +- kernel thread for removing the dir who has a plenty of whiteouts
2746 +- support copyup sparse file (a file which has a 'hole' in it)
2747 +- default permission flags for branches
2748 +- selectable permission flags for ro branch, whether whiteout can
2751 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2752 +- support multiple writable branches, some policies to select one
2753 + among multiple writable branches.
2754 +- a new semantics for link(2) and rename(2) to support multiple
2755 + writable branches.
2756 +- no glibc changes are required.
2757 +- pseudo hardlink (hardlink over branches)
2758 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2759 + including NFS or remote filesystem branch.
2760 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2763 +Currently these features are dropped temporary from aufs4.
2764 +See design/08plan.txt in detail.
2765 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2767 +- statistics of aufs thread (/sys/fs/aufs/stat)
2769 +Features or just an idea in the future (see also design/*.txt),
2770 +- reorder the branch index without del/re-add.
2771 +- permanent xino files for NFSD
2772 +- an option for refreshing the opened files after add/del branches
2773 +- light version, without branch manipulation. (unnecessary?)
2774 +- copyup in userspace
2775 +- inotify in userspace
2780 +----------------------------------------
2781 +There are three GIT trees for aufs4, aufs4-linux.git,
2782 +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in
2784 +While the aufs-util is always necessary, you need either of aufs4-linux
2785 +or aufs4-standalone.
2787 +The aufs4-linux tree includes the whole linux mainline GIT tree,
2788 +git://git.kernel.org/.../torvalds/linux.git.
2789 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2790 +build aufs4 as an external kernel module.
2791 +Several extra patches are not included in this tree. Only
2792 +aufs4-standalone tree contains them. They are described in the later
2793 +section "Configuration and Compilation."
2795 +On the other hand, the aufs4-standalone tree has only aufs source files
2796 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2797 +But you need to apply all aufs patches manually.
2799 +You will find GIT branches whose name is in form of "aufs4.x" where "x"
2800 +represents the linux kernel version, "linux-4.x". For instance,
2801 +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use
2802 +"aufs4.x-rcN" branch.
2805 +$ git clone --reference /your/linux/git/tree \
2806 + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git
2807 +- if you don't have linux GIT tree, then remove "--reference ..."
2808 +$ cd aufs4-linux.git
2809 +$ git checkout origin/aufs4.0
2811 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2812 +leave the patch-work to GIT.
2813 +$ cd /your/linux/git/tree
2814 +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git
2816 +$ git checkout -b my4.0 v4.0
2817 +$ (add your local change...)
2818 +$ git pull aufs4 aufs4.0
2819 +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch.
2820 +- you may need to solve some conflicts between your_changes and
2821 + aufs4.0. in this case, git-rerere is recommended so that you can
2822 + solve the similar conflicts automatically when you upgrade to 4.1 or
2823 + later in the future.
2825 +o aufs4-standalone tree
2826 +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git
2827 +$ cd aufs4-standalone.git
2828 +$ git checkout origin/aufs4.0
2831 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2832 +- note that the public aufs-util.git is on SourceForge instead of
2835 +$ git checkout origin/aufs4.0
2837 +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY.
2838 +The minor version number, 'x' in '4.x', of aufs may not always
2839 +follow the minor version number of the kernel.
2840 +Because changes in the kernel that cause the use of a new
2841 +minor version number do not always require changes to aufs-util.
2843 +Since aufs-util has its own minor version number, you may not be
2844 +able to find a GIT branch in aufs-util for your kernel's
2845 +exact minor version number.
2846 +In this case, you should git-checkout the branch for the
2847 +nearest lower number.
2849 +For (an unreleased) example:
2850 +If you are using "linux-4.10" and the "aufs4.10" branch
2851 +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8"
2852 +or something numerically smaller is the branch for your kernel.
2854 +Also you can view all branches by
2858 +3. Configuration and Compilation
2859 +----------------------------------------
2860 +Make sure you have git-checkout'ed the correct branch.
2862 +For aufs4-linux tree,
2863 +- enable CONFIG_AUFS_FS.
2864 +- set other aufs configurations if necessary.
2866 +For aufs4-standalone tree,
2867 +There are several ways to build.
2870 +- apply ./aufs4-kbuild.patch to your kernel source files.
2871 +- apply ./aufs4-base.patch too.
2872 +- apply ./aufs4-mmap.patch too.
2873 +- apply ./aufs4-standalone.patch too, if you have a plan to set
2874 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch.
2875 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2876 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2877 +- enable CONFIG_AUFS_FS, you can select either
2879 +- and build your kernel as usual.
2880 +- install the built kernel.
2881 + Note: Since linux-3.9, every filesystem module requires an alias
2882 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2883 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2884 +- install the header files too by "make headers_install" to the
2885 + directory where you specify. By default, it is $PWD/usr.
2886 + "make help" shows a brief note for headers_install.
2887 +- and reboot your system.
2890 +- module only (CONFIG_AUFS_FS=m).
2891 +- apply ./aufs4-base.patch to your kernel source files.
2892 +- apply ./aufs4-mmap.patch too.
2893 +- apply ./aufs4-standalone.patch too.
2894 +- build your kernel, don't forget "make headers_install", and reboot.
2895 +- edit ./config.mk and set other aufs configurations if necessary.
2896 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2897 + every aufs configurations.
2898 +- build the module by simple "make".
2899 + Note: Since linux-3.9, every filesystem module requires an alias
2900 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2901 + modules.aliases file.
2902 +- you can specify ${KDIR} make variable which points to your kernel
2904 +- install the files
2905 + + run "make install" to install the aufs module, or copy the built
2906 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2907 + + run "make install_headers" (instead of headers_install) to install
2908 + the modified aufs header file (you can specify DESTDIR which is
2909 + available in aufs standalone version's Makefile only), or copy
2910 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2911 + you like manually. By default, the target directory is $PWD/usr.
2912 +- no need to apply aufs4-kbuild.patch, nor copying source files to your
2913 + kernel source tree.
2915 +Note: The header file aufs_type.h is necessary to build aufs-util
2916 + as well as "make headers_install" in the kernel source tree.
2917 + headers_install is subject to be forgotten, but it is essentially
2918 + necessary, not only for building aufs-util.
2919 + You may not meet problems without headers_install in some older
2923 +- read README in aufs-util, build and install it
2924 +- note that your distribution may contain an obsoleted version of
2925 + aufs_type.h in /usr/include/linux or something. When you build aufs
2926 + utilities, make sure that your compiler refers the correct aufs header
2927 + file which is built by "make headers_install."
2928 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2929 + then run "make install_ulib" too. And refer to the aufs manual in
2932 +There several other patches in aufs4-standalone.git. They are all
2933 +optional. When you meet some problems, they will help you.
2934 +- aufs4-loopback.patch
2935 + Supports a nested loopback mount in a branch-fs. This patch is
2936 + unnecessary until aufs produces a message like "you may want to try
2937 + another patch for loopback file".
2939 + Modifies a system global kernel internal function get_next_ino() in
2940 + order to stop assigning 0 for an inode-number. Not directly related to
2941 + aufs, but recommended generally.
2943 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2944 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2945 + duplication of inode number, which is important for backup tools and
2946 + other utilities. When you find aufs XINO files for tmpfs branch
2947 + growing too much, try this patch.
2948 +- lockdep-debug.patch
2949 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2950 + also a caller of VFS functions for branch filesystems, subclassing of
2951 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2952 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2953 + need to apply this debug patch to expand several constant values.
2954 + If don't know what LOCKDEP, then you don't have apply this patch.
2958 +----------------------------------------
2959 +At first, make sure aufs-util are installed, and please read the aufs
2960 +manual, aufs.5 in aufs-util.git tree.
2964 +$ mkdir /tmp/rw /tmp/aufs
2965 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2967 +Here is another example. The result is equivalent.
2968 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2970 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2971 +# mount -o remount,append:${HOME} /tmp/aufs
2973 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2974 +you modify a file under /tmp/aufs, the one on your home directory is
2975 +not affected, instead the same named file will be newly created under
2976 +/tmp/rw. And all of your modification to a file will be applied to
2977 +the one under /tmp/rw. This is called the file based Copy on Write
2979 +Aufs mount options are described in aufs.5.
2980 +If you run chroot or something and make your aufs as a root directory,
2981 +then you need to customize the shutdown script. See the aufs manual in
2984 +Additionally, there are some sample usages of aufs which are a
2985 +diskless system with network booting, and LiveCD over NFS.
2986 +See sample dir in CVS tree on SourceForge.
2990 +----------------------------------------
2991 +When you have any problems or strange behaviour in aufs, please let me
2993 +- /proc/mounts (instead of the output of mount(8))
2994 +- /sys/module/aufs/*
2995 +- /sys/fs/aufs/* (if you have them)
2996 +- /debug/aufs/* (if you have them)
2997 +- linux kernel version
2998 + if your kernel is not plain, for example modified by distributor,
2999 + the url where i can download its source is necessary too.
3000 +- aufs version which was printed at loading the module or booting the
3001 + system, instead of the date you downloaded.
3002 +- configuration (define/undefine CONFIG_AUFS_xxx)
3003 +- kernel configuration or /proc/config.gz (if you have it)
3004 +- behaviour which you think to be incorrect
3005 +- actual operation, reproducible one is better
3006 +- mailto: aufs-users at lists.sourceforge.net
3008 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
3009 +and Feature Requests) on SourceForge. Please join and write to
3013 +6. Acknowledgements
3014 +----------------------------------------
3015 +Thanks to everyone who have tried and are using aufs, whoever
3016 +have reported a bug or any feedback.
3018 +Especially donators:
3019 +Tomas Matejicek(slax.org) made a donation (much more than once).
3020 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
3021 + scripts) is making "doubling" donations.
3022 + Unfortunately I cannot list all of the donators, but I really
3024 + It ends Aug 2010, but the ordinary donation URL is still available.
3025 + <http://sourceforge.net/donate/index.php?group_id=167503>
3026 +Dai Itasaka made a donation (2007/8).
3027 +Chuck Smith made a donation (2008/4, 10 and 12).
3028 +Henk Schoneveld made a donation (2008/9).
3029 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
3030 +Francois Dupoux made a donation (2008/11).
3031 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
3032 + aufs2 GIT tree (2009/2).
3033 +William Grant made a donation (2009/3).
3034 +Patrick Lane made a donation (2009/4).
3035 +The Mail Archive (mail-archive.com) made donations (2009/5).
3036 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
3037 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
3038 +Pavel Pronskiy made a donation (2011/2).
3039 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
3040 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
3041 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
3043 +Sam Liddicott made a donation (2011/9).
3044 +Era Scarecrow made a donation (2013/4).
3045 +Bor Ratajc made a donation (2013/4).
3046 +Alessandro Gorreta made a donation (2013/4).
3047 +POIRETTE Marc made a donation (2013/4).
3048 +Alessandro Gorreta made a donation (2013/4).
3049 +lauri kasvandik made a donation (2013/5).
3050 +"pemasu from Finland" made a donation (2013/7).
3051 +The Parted Magic Project made a donation (2013/9 and 11).
3052 +Pavel Barta made a donation (2013/10).
3053 +Nikolay Pertsev made a donation (2014/5).
3054 +James B made a donation (2014/7 and 2015/7).
3055 +Stefano Di Biase made a donation (2014/8).
3056 +Daniel Epellei made a donation (2015/1).
3057 +OmegaPhil made a donation (2016/1, 2018/4).
3058 +Tomasz Szewczyk made a donation (2016/4).
3059 +James Burry made a donation (2016/12).
3061 +Thank you very much.
3062 +Donations are always, including future donations, very important and
3063 +helpful for me to keep on developing aufs.
3067 +----------------------------------------
3068 +If you are an experienced user, no explanation is needed. Aufs is
3069 +just a linux filesystem.
3074 +# Local variables: ;
3077 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
3078 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
3079 +++ linux/fs/aufs/aufs.h 2018-08-12 23:43:05.450124426 +0200
3081 +/* SPDX-License-Identifier: GPL-2.0 */
3083 + * Copyright (C) 2005-2018 Junjiro R. Okajima
3085 + * This program, aufs is free software; you can redistribute it and/or modify
3086 + * it under the terms of the GNU General Public License as published by
3087 + * the Free Software Foundation; either version 2 of the License, or
3088 + * (at your option) any later version.
3090 + * This program is distributed in the hope that it will be useful,
3091 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3092 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3093 + * GNU General Public License for more details.
3095 + * You should have received a copy of the GNU General Public License
3096 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3100 + * all header files
3108 +#define AuStub(type, name, body, ...) \
3109 + static inline type name(__VA_ARGS__) { body; }
3111 +#define AuStubVoid(name, ...) \
3112 + AuStub(void, name, , __VA_ARGS__)
3113 +#define AuStubInt0(name, ...) \
3114 + AuStub(int, name, return 0, __VA_ARGS__)
3118 +#include "branch.h"
3121 +#include "dbgaufs.h"
3122 +#include "dentry.h"
3124 +#include "dirren.h"
3127 +#include "fstype.h"
3131 +#include "module.h"
3135 +#include "sysaufs.h"
3140 +#endif /* __KERNEL__ */
3141 +#endif /* __AUFS_H__ */
3142 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
3143 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
3144 +++ linux/fs/aufs/branch.c 2018-08-12 23:43:05.450124426 +0200
3146 +// SPDX-License-Identifier: GPL-2.0
3148 + * Copyright (C) 2005-2018 Junjiro R. Okajima
3150 + * This program, aufs is free software; you can redistribute it and/or modify
3151 + * it under the terms of the GNU General Public License as published by
3152 + * the Free Software Foundation; either version 2 of the License, or
3153 + * (at your option) any later version.
3155 + * This program is distributed in the hope that it will be useful,
3156 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3157 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3158 + * GNU General Public License for more details.
3160 + * You should have received a copy of the GNU General Public License
3161 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3165 + * branch management
3168 +#include <linux/compat.h>
3169 +#include <linux/statfs.h>
3173 + * free a single branch
3175 +static void au_br_do_free(struct au_branch *br)
3178 + struct au_wbr *wbr;
3179 + struct au_dykey **key;
3181 + au_hnotify_fin_br(br);
3182 + /* always, regardless the mount option */
3183 + au_dr_hino_free(&br->br_dirren);
3186 + AuDebugOn(au_br_count(br));
3187 + au_br_count_fin(br);
3191 + for (i = 0; i < AuBrWh_Last; i++)
3192 + dput(wbr->wbr_wh[i]);
3193 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
3194 + AuRwDestroy(&wbr->wbr_wh_rwsem);
3197 + if (br->br_fhsm) {
3198 + au_br_fhsm_fin(br->br_fhsm);
3199 + kfree(br->br_fhsm);
3202 + key = br->br_dykey;
3203 + for (i = 0; i < AuBrDynOp; i++, key++)
3209 + /* recursive lock, s_umount of branch's */
3211 + path_put(&br->br_path);
3218 + * frees all branches
3220 +void au_br_free(struct au_sbinfo *sbinfo)
3222 + aufs_bindex_t bmax;
3223 + struct au_branch **br;
3225 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3227 + bmax = sbinfo->si_bbot + 1;
3228 + br = sbinfo->si_branch;
3230 + au_br_do_free(*br++);
3234 + * find the index of a branch which is specified by @br_id.
3236 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3238 + aufs_bindex_t bindex, bbot;
3240 + bbot = au_sbbot(sb);
3241 + for (bindex = 0; bindex <= bbot; bindex++)
3242 + if (au_sbr_id(sb, bindex) == br_id)
3247 +/* ---------------------------------------------------------------------- */
3253 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3254 + struct dentry *h_root)
3256 + if (unlikely(h_adding == h_root
3257 + || au_test_loopback_overlap(sb, h_adding)))
3259 + if (h_adding->d_sb != h_root->d_sb)
3261 + return au_test_subdir(h_adding, h_root)
3262 + || au_test_subdir(h_root, h_adding);
3266 + * returns a newly allocated branch. @new_nbranch is a number of branches
3267 + * after adding a branch.
3269 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3272 + struct au_branch *add_branch;
3273 + struct dentry *root;
3274 + struct inode *inode;
3278 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3279 + if (unlikely(!add_branch))
3281 + add_branch->br_xino = au_xino_alloc();
3282 + if (unlikely(!add_branch->br_xino))
3284 + err = au_hnotify_init_br(add_branch, perm);
3285 + if (unlikely(err))
3288 + if (au_br_writable(perm)) {
3289 + /* may be freed separately at changing the branch permission */
3290 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3292 + if (unlikely(!add_branch->br_wbr))
3296 + if (au_br_fhsm(perm)) {
3297 + err = au_fhsm_br_alloc(add_branch);
3298 + if (unlikely(err))
3302 + root = sb->s_root;
3303 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3305 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3307 + inode = d_inode(root);
3308 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3312 + return add_branch; /* success */
3315 + kfree(add_branch->br_wbr);
3317 + au_hnotify_fin_br(add_branch);
3319 + au_xino_put(add_branch);
3321 + kfree(add_branch);
3323 + return ERR_PTR(err);
3327 + * test if the branch permission is legal or not.
3329 +static int test_br(struct inode *inode, int brperm, char *path)
3333 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3338 + pr_err("write permission for readonly mount or inode, %s\n", path);
3346 + * 0: success, the caller will add it
3347 + * plus: success, it is already unified, the caller should ignore it
3350 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3353 + aufs_bindex_t bbot, bindex;
3354 + struct dentry *root, *h_dentry;
3355 + struct inode *inode, *h_inode;
3357 + root = sb->s_root;
3358 + bbot = au_sbbot(sb);
3359 + if (unlikely(bbot >= 0
3360 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3364 + pr_err("%s duplicated\n", add->pathname);
3369 + err = -ENOSPC; /* -E2BIG; */
3370 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3371 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3372 + pr_err("number of branches exceeded %s\n", add->pathname);
3377 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3378 + pr_err("bad index %d\n", add->bindex);
3382 + inode = d_inode(add->path.dentry);
3384 + if (unlikely(!inode->i_nlink)) {
3385 + pr_err("no existence %s\n", add->pathname);
3390 + if (unlikely(inode->i_sb == sb)) {
3391 + pr_err("%s must be outside\n", add->pathname);
3395 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3396 + pr_err("unsupported filesystem, %s (%s)\n",
3397 + add->pathname, au_sbtype(inode->i_sb));
3401 + if (unlikely(inode->i_sb->s_stack_depth)) {
3402 + pr_err("already stacked, %s (%s)\n",
3403 + add->pathname, au_sbtype(inode->i_sb));
3407 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3408 + if (unlikely(err))
3412 + return 0; /* success */
3415 + for (bindex = 0; bindex <= bbot; bindex++)
3416 + if (unlikely(test_overlap(sb, add->path.dentry,
3417 + au_h_dptr(root, bindex)))) {
3418 + pr_err("%s is overlapped\n", add->pathname);
3423 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3424 + h_dentry = au_h_dptr(root, 0);
3425 + h_inode = d_inode(h_dentry);
3426 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3427 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3428 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3429 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3431 + i_uid_read(inode), i_gid_read(inode),
3432 + (inode->i_mode & S_IALLUGO),
3433 + i_uid_read(h_inode), i_gid_read(h_inode),
3434 + (h_inode->i_mode & S_IALLUGO));
3442 + * initialize or clean the whiteouts for an adding branch
3444 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3447 + int err, old_perm;
3448 + aufs_bindex_t bindex;
3449 + struct inode *h_inode;
3450 + struct au_wbr *wbr;
3451 + struct au_hinode *hdir;
3452 + struct dentry *h_dentry;
3454 + err = vfsub_mnt_want_write(au_br_mnt(br));
3455 + if (unlikely(err))
3459 + old_perm = br->br_perm;
3460 + br->br_perm = new_perm;
3463 + bindex = au_br_index(sb, br->br_id);
3464 + if (0 <= bindex) {
3465 + hdir = au_hi(d_inode(sb->s_root), bindex);
3466 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3468 + h_dentry = au_br_dentry(br);
3469 + h_inode = d_inode(h_dentry);
3470 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3473 + err = au_wh_init(br, sb);
3475 + wbr_wh_write_lock(wbr);
3476 + err = au_wh_init(br, sb);
3477 + wbr_wh_write_unlock(wbr);
3480 + au_hn_inode_unlock(hdir);
3482 + inode_unlock(h_inode);
3483 + vfsub_mnt_drop_write(au_br_mnt(br));
3484 + br->br_perm = old_perm;
3486 + if (!err && wbr && !au_br_writable(new_perm)) {
3488 + br->br_wbr = NULL;
3495 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3499 + struct kstatfs kst;
3500 + struct au_wbr *wbr;
3503 + au_rw_init(&wbr->wbr_wh_rwsem);
3504 + atomic_set(&wbr->wbr_wh_running, 0);
3507 + * a limit for rmdir/rename a dir
3508 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3510 + err = vfs_statfs(&br->br_path, &kst);
3511 + if (unlikely(err))
3514 + if (kst.f_namelen >= NAME_MAX)
3515 + err = au_br_init_wh(sb, br, perm);
3517 + pr_err("%pd(%s), unsupported namelen %ld\n",
3519 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3525 +/* initialize a new branch */
3526 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3527 + struct au_opt_add *add)
3530 + struct au_branch *brbase;
3532 + struct inode *h_inode;
3535 + br->br_perm = add->perm;
3536 + br->br_path = add->path; /* set first, path_get() later */
3537 + spin_lock_init(&br->br_dykey_lock);
3538 + au_br_count_init(br);
3539 + br->br_id = au_new_br_id(sb);
3540 + AuDebugOn(br->br_id < 0);
3542 + /* always, regardless the given option */
3543 + err = au_dr_br_init(sb, br, &add->path);
3544 + if (unlikely(err))
3547 + if (au_br_writable(add->perm)) {
3548 + err = au_wbr_init(br, sb, add->perm);
3549 + if (unlikely(err))
3553 + if (au_opt_test(au_mntflags(sb), XINO)) {
3554 + brbase = au_sbr(sb, 0);
3555 + xf = au_xino_file(brbase);
3557 + h_inode = d_inode(add->path.dentry);
3558 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3559 + if (unlikely(err)) {
3560 + AuDebugOn(au_xino_file(br));
3565 + sysaufs_br_init(br);
3566 + path_get(&br->br_path);
3567 + goto out; /* success */
3570 + memset(&br->br_path, 0, sizeof(br->br_path));
3575 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3576 + struct au_branch *br, aufs_bindex_t bbot,
3577 + aufs_bindex_t amount)
3579 + struct au_branch **brp;
3581 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3583 + brp = sbinfo->si_branch + bindex;
3584 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3586 + sbinfo->si_bbot++;
3587 + if (unlikely(bbot < 0))
3588 + sbinfo->si_bbot = 0;
3591 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3592 + aufs_bindex_t bbot, aufs_bindex_t amount)
3594 + struct au_hdentry *hdp;
3596 + AuRwMustWriteLock(&dinfo->di_rwsem);
3598 + hdp = au_hdentry(dinfo, bindex);
3599 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3600 + au_h_dentry_init(hdp);
3602 + if (unlikely(bbot < 0))
3603 + dinfo->di_btop = 0;
3606 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3607 + aufs_bindex_t bbot, aufs_bindex_t amount)
3609 + struct au_hinode *hip;
3611 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3613 + hip = au_hinode(iinfo, bindex);
3614 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3615 + au_hinode_init(hip);
3617 + if (unlikely(bbot < 0))
3618 + iinfo->ii_btop = 0;
3621 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3622 + aufs_bindex_t bindex)
3624 + struct dentry *root, *h_dentry;
3625 + struct inode *root_inode, *h_inode;
3626 + aufs_bindex_t bbot, amount;
3628 + root = sb->s_root;
3629 + root_inode = d_inode(root);
3630 + bbot = au_sbbot(sb);
3631 + amount = bbot + 1 - bindex;
3632 + h_dentry = au_br_dentry(br);
3633 + au_sbilist_lock();
3634 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3635 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3636 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3637 + au_set_h_dptr(root, bindex, dget(h_dentry));
3638 + h_inode = d_inode(h_dentry);
3639 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3640 + au_sbilist_unlock();
3643 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3646 + aufs_bindex_t bbot, add_bindex;
3647 + struct dentry *root, *h_dentry;
3648 + struct inode *root_inode;
3649 + struct au_branch *add_branch;
3652 + root = sb->s_root;
3653 + root_inode = d_inode(root);
3654 + IMustLock(root_inode);
3655 + IiMustWriteLock(root_inode);
3656 + err = test_add(sb, add, remount);
3657 + if (unlikely(err < 0))
3661 + goto out; /* success */
3664 + bbot = au_sbbot(sb);
3665 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3666 + err = PTR_ERR(add_branch);
3667 + if (IS_ERR(add_branch))
3670 + err = au_br_init(add_branch, sb, add);
3671 + if (unlikely(err)) {
3672 + au_br_do_free(add_branch);
3676 + add_bindex = add->bindex;
3677 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3678 + au_br_do_add(sb, add_branch, add_bindex);
3679 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3680 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3682 + h_dentry = add->path.dentry;
3683 + if (!add_bindex) {
3684 + au_cpup_attr_all(root_inode, /*force*/1);
3685 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3687 + au_add_nlink(root_inode, d_inode(h_dentry));
3690 + * this test/set prevents aufs from handling unnecessary notify events
3691 + * of xino files, in case of re-adding a writable branch which was
3692 + * once detached from aufs.
3694 + if (au_xino_brid(sb) < 0
3695 + && au_br_writable(add_branch->br_perm)
3696 + && !au_test_fs_bad_xino(h_dentry->d_sb)) {
3697 + xf = au_xino_file(add_branch);
3698 + if (xf && xf->f_path.dentry->d_parent == h_dentry)
3699 + au_xino_brid_set(sb, add_branch->br_id);
3706 +/* ---------------------------------------------------------------------- */
3708 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3709 + unsigned long long max __maybe_unused,
3712 + unsigned long long n;
3713 + struct file **p, *f;
3714 + struct hlist_bl_head *files;
3715 + struct hlist_bl_node *pos;
3716 + struct au_finfo *finfo;
3720 + files = &au_sbi(sb)->si_files;
3721 + hlist_bl_lock(files);
3722 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3723 + f = finfo->fi_file;
3725 + && !special_file(file_inode(f)->i_mode)) {
3729 + AuDebugOn(n > max);
3732 + hlist_bl_unlock(files);
3737 +static struct file **au_farray_alloc(struct super_block *sb,
3738 + unsigned long long *max)
3740 + *max = au_nfiles(sb);
3741 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3744 +static void au_farray_free(struct file **a, unsigned long long max)
3746 + unsigned long long ull;
3748 + for (ull = 0; ull < max; ull++)
3754 +/* ---------------------------------------------------------------------- */
3760 +/* to show the line number, do not make it inlined function */
3761 +#define AuVerbose(do_info, fmt, ...) do { \
3763 + pr_info(fmt, ##__VA_ARGS__); \
3766 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3767 + aufs_bindex_t bbot)
3769 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3772 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3773 + aufs_bindex_t bbot)
3775 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3779 + * test if the branch is deletable or not.
3781 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3782 + unsigned int sigen, const unsigned int verbose)
3784 + int err, i, j, ndentry;
3785 + aufs_bindex_t btop, bbot;
3786 + struct au_dcsub_pages dpages;
3787 + struct au_dpage *dpage;
3790 + err = au_dpages_init(&dpages, GFP_NOFS);
3791 + if (unlikely(err))
3793 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3794 + if (unlikely(err))
3797 + for (i = 0; !err && i < dpages.ndpage; i++) {
3798 + dpage = dpages.dpages + i;
3799 + ndentry = dpage->ndentry;
3800 + for (j = 0; !err && j < ndentry; j++) {
3801 + d = dpage->dentries[j];
3802 + AuDebugOn(au_dcount(d) <= 0);
3803 + if (!au_digen_test(d, sigen)) {
3804 + di_read_lock_child(d, AuLock_IR);
3805 + if (unlikely(au_dbrange_test(d))) {
3806 + di_read_unlock(d, AuLock_IR);
3810 + di_write_lock_child(d);
3811 + if (unlikely(au_dbrange_test(d))) {
3812 + di_write_unlock(d);
3815 + err = au_reval_dpath(d, sigen);
3817 + di_downgrade_lock(d, AuLock_IR);
3819 + di_write_unlock(d);
3824 + /* AuDbgDentry(d); */
3825 + btop = au_dbtop(d);
3826 + bbot = au_dbbot(d);
3827 + if (btop <= bindex
3829 + && au_h_dptr(d, bindex)
3830 + && au_test_dbusy(d, btop, bbot)) {
3832 + AuVerbose(verbose, "busy %pd\n", d);
3835 + di_read_unlock(d, AuLock_IR);
3840 + au_dpages_free(&dpages);
3845 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3846 + unsigned int sigen, const unsigned int verbose)
3849 + unsigned long long max, ull;
3850 + struct inode *i, **array;
3851 + aufs_bindex_t btop, bbot;
3853 + array = au_iarray_alloc(sb, &max);
3854 + err = PTR_ERR(array);
3855 + if (IS_ERR(array))
3859 + AuDbg("b%d\n", bindex);
3860 + for (ull = 0; !err && ull < max; ull++) {
3864 + if (i->i_ino == AUFS_ROOT_INO)
3867 + /* AuDbgInode(i); */
3868 + if (au_iigen(i, NULL) == sigen)
3869 + ii_read_lock_child(i);
3871 + ii_write_lock_child(i);
3872 + err = au_refresh_hinode_self(i);
3875 + ii_downgrade_lock(i);
3877 + ii_write_unlock(i);
3882 + btop = au_ibtop(i);
3883 + bbot = au_ibbot(i);
3884 + if (btop <= bindex
3886 + && au_h_iptr(i, bindex)
3887 + && au_test_ibusy(i, btop, bbot)) {
3889 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3892 + ii_read_unlock(i);
3894 + au_iarray_free(array, max);
3900 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3901 + const unsigned int verbose)
3904 + unsigned int sigen;
3906 + sigen = au_sigen(root->d_sb);
3907 + DiMustNoWaiters(root);
3908 + IiMustNoWaiters(d_inode(root));
3909 + di_write_unlock(root);
3910 + err = test_dentry_busy(root, bindex, sigen, verbose);
3912 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3913 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3918 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3919 + struct file **to_free, int *idx)
3922 + unsigned char matched, root;
3923 + aufs_bindex_t bindex, bbot;
3924 + struct au_fidir *fidir;
3925 + struct au_hfile *hfile;
3928 + root = IS_ROOT(file->f_path.dentry);
3931 + to_free[*idx] = file;
3937 + fidir = au_fi(file)->fi_hdir;
3938 + AuDebugOn(!fidir);
3939 + bbot = au_fbbot_dir(file);
3940 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3941 + hfile = fidir->fd_hfile + bindex;
3942 + if (!hfile->hf_file)
3945 + if (hfile->hf_br->br_id == br_id) {
3957 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3958 + struct file **to_free, int opened)
3961 + unsigned long long ull, max;
3962 + aufs_bindex_t btop;
3963 + struct file *file, **array;
3964 + struct dentry *root;
3965 + struct au_hfile *hfile;
3967 + array = au_farray_alloc(sb, &max);
3968 + err = PTR_ERR(array);
3969 + if (IS_ERR(array))
3974 + root = sb->s_root;
3975 + di_write_unlock(root);
3976 + for (ull = 0; ull < max; ull++) {
3977 + file = array[ull];
3978 + if (unlikely(!file))
3981 + /* AuDbg("%pD\n", file); */
3982 + fi_read_lock(file);
3983 + btop = au_fbtop(file);
3984 + if (!d_is_dir(file->f_path.dentry)) {
3985 + hfile = &au_fi(file)->fi_htop;
3986 + if (hfile->hf_br->br_id == br_id)
3989 + err = test_dir_busy(file, br_id, to_free, &idx);
3990 + fi_read_unlock(file);
3991 + if (unlikely(err))
3994 + di_write_lock_child(root);
3995 + au_farray_free(array, max);
3996 + AuDebugOn(idx > opened);
4002 +static void br_del_file(struct file **to_free, unsigned long long opened,
4003 + aufs_bindex_t br_id)
4005 + unsigned long long ull;
4006 + aufs_bindex_t bindex, btop, bbot, bfound;
4007 + struct file *file;
4008 + struct au_fidir *fidir;
4009 + struct au_hfile *hfile;
4011 + for (ull = 0; ull < opened; ull++) {
4012 + file = to_free[ull];
4013 + if (unlikely(!file))
4016 + /* AuDbg("%pD\n", file); */
4017 + AuDebugOn(!d_is_dir(file->f_path.dentry));
4019 + fidir = au_fi(file)->fi_hdir;
4020 + AuDebugOn(!fidir);
4021 + fi_write_lock(file);
4022 + btop = au_fbtop(file);
4023 + bbot = au_fbbot_dir(file);
4024 + for (bindex = btop; bindex <= bbot; bindex++) {
4025 + hfile = fidir->fd_hfile + bindex;
4026 + if (!hfile->hf_file)
4029 + if (hfile->hf_br->br_id == br_id) {
4034 + AuDebugOn(bfound < 0);
4035 + au_set_h_fptr(file, bfound, NULL);
4036 + if (bfound == btop) {
4037 + for (btop++; btop <= bbot; btop++)
4038 + if (au_hf_dir(file, btop)) {
4039 + au_set_fbtop(file, btop);
4043 + fi_write_unlock(file);
4047 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
4048 + const aufs_bindex_t bindex,
4049 + const aufs_bindex_t bbot)
4051 + struct au_branch **brp, **p;
4053 + AuRwMustWriteLock(&sbinfo->si_rwsem);
4055 + brp = sbinfo->si_branch + bindex;
4056 + if (bindex < bbot)
4057 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
4058 + sbinfo->si_branch[0 + bbot] = NULL;
4059 + sbinfo->si_bbot--;
4061 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
4064 + sbinfo->si_branch = p;
4065 + /* harmless error */
4068 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
4069 + const aufs_bindex_t bbot)
4071 + struct au_hdentry *hdp, *p;
4073 + AuRwMustWriteLock(&dinfo->di_rwsem);
4075 + hdp = au_hdentry(dinfo, bindex);
4076 + if (bindex < bbot)
4077 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
4078 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
4081 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
4084 + dinfo->di_hdentry = p;
4085 + /* harmless error */
4088 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
4089 + const aufs_bindex_t bbot)
4091 + struct au_hinode *hip, *p;
4093 + AuRwMustWriteLock(&iinfo->ii_rwsem);
4095 + hip = au_hinode(iinfo, bindex);
4096 + if (bindex < bbot)
4097 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
4098 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
4101 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
4104 + iinfo->ii_hinode = p;
4105 + /* harmless error */
4108 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
4109 + struct au_branch *br)
4111 + aufs_bindex_t bbot;
4112 + struct au_sbinfo *sbinfo;
4113 + struct dentry *root, *h_root;
4114 + struct inode *inode, *h_inode;
4115 + struct au_hinode *hinode;
4117 + SiMustWriteLock(sb);
4119 + root = sb->s_root;
4120 + inode = d_inode(root);
4121 + sbinfo = au_sbi(sb);
4122 + bbot = sbinfo->si_bbot;
4124 + h_root = au_h_dptr(root, bindex);
4125 + hinode = au_hi(inode, bindex);
4126 + h_inode = au_igrab(hinode->hi_inode);
4129 + au_sbilist_lock();
4130 + au_br_do_del_brp(sbinfo, bindex, bbot);
4131 + au_br_do_del_hdp(au_di(root), bindex, bbot);
4132 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
4133 + au_sbilist_unlock();
4135 + /* ignore an error */
4136 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
4140 + au_br_do_free(br);
4143 +static unsigned long long empty_cb(struct super_block *sb, void *array,
4144 + unsigned long long max, void *arg)
4149 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
4152 + unsigned long long opened;
4153 + unsigned int mnt_flags;
4154 + aufs_bindex_t bindex, bbot, br_id;
4155 + unsigned char do_wh, verbose;
4156 + struct au_branch *br;
4157 + struct au_wbr *wbr;
4158 + struct dentry *root;
4159 + struct file **to_free;
4164 + root = sb->s_root;
4165 + bindex = au_find_dbindex(root, del->h_path.dentry);
4168 + goto out; /* success */
4170 + pr_err("%s no such branch\n", del->pathname);
4173 + AuDbg("bindex b%d\n", bindex);
4176 + mnt_flags = au_mntflags(sb);
4177 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4178 + bbot = au_sbbot(sb);
4179 + if (unlikely(!bbot)) {
4180 + AuVerbose(verbose, "no more branches left\n");
4183 + br = au_sbr(sb, bindex);
4184 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
4186 + br_id = br->br_id;
4187 + opened = au_br_count(br);
4188 + if (unlikely(opened)) {
4189 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
4190 + err = PTR_ERR(to_free);
4191 + if (IS_ERR(to_free))
4194 + err = test_file_busy(sb, br_id, to_free, opened);
4195 + if (unlikely(err)) {
4196 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
4202 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4204 + /* instead of WbrWhMustWriteLock(wbr) */
4205 + SiMustWriteLock(sb);
4206 + for (i = 0; i < AuBrWh_Last; i++) {
4207 + dput(wbr->wbr_wh[i]);
4208 + wbr->wbr_wh[i] = NULL;
4212 + err = test_children_busy(root, bindex, verbose);
4213 + if (unlikely(err)) {
4222 + * now we confirmed the branch is deletable.
4223 + * let's free the remaining opened dirs on the branch.
4225 + di_write_unlock(root);
4226 + br_del_file(to_free, opened, br_id);
4227 + di_write_lock_child(root);
4230 + sysaufs_brs_del(sb, bindex); /* remove successors */
4231 + dbgaufs_xino_del(br); /* remove one */
4232 + au_br_do_del(sb, bindex, br);
4233 + sysaufs_brs_add(sb, bindex); /* append successors */
4234 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4237 + au_cpup_attr_all(d_inode(root), /*force*/1);
4238 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4240 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4241 + if (au_opt_test(mnt_flags, PLINK))
4242 + au_plink_half_refresh(sb, br_id);
4244 + if (au_xino_brid(sb) == br_id)
4245 + au_xino_brid_set(sb, -1);
4246 + goto out; /* success */
4250 + rerr = au_br_init_wh(sb, br, br->br_perm);
4252 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4253 + del->pathname, rerr);
4256 + au_farray_free(to_free, opened);
4260 +/* ---------------------------------------------------------------------- */
4262 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4265 + aufs_bindex_t btop, bbot;
4266 + struct aufs_ibusy ibusy;
4267 + struct inode *inode, *h_inode;
4270 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4273 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4275 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
4276 + if (unlikely(err)) {
4283 + si_read_lock(sb, AuLock_FLUSH);
4284 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4288 + ibusy.h_ino = 0; /* invalid */
4289 + inode = ilookup(sb, ibusy.ino);
4291 + || inode->i_ino == AUFS_ROOT_INO
4292 + || au_is_bad_inode(inode))
4295 + ii_read_lock_child(inode);
4296 + btop = au_ibtop(inode);
4297 + bbot = au_ibbot(inode);
4298 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4299 + h_inode = au_h_iptr(inode, ibusy.bindex);
4300 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4301 + ibusy.h_ino = h_inode->i_ino;
4303 + ii_read_unlock(inode);
4307 + si_read_unlock(sb);
4309 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4310 + if (unlikely(err)) {
4319 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4321 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4324 +#ifdef CONFIG_COMPAT
4325 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4327 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4331 +/* ---------------------------------------------------------------------- */
4334 + * change a branch permission
4337 +static void au_warn_ima(void)
4340 + /* since it doesn't support mark_files_ro() */
4341 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4345 +static int do_need_sigen_inc(int a, int b)
4347 + return au_br_whable(a) && !au_br_whable(b);
4350 +static int need_sigen_inc(int old, int new)
4352 + return do_need_sigen_inc(old, new)
4353 + || do_need_sigen_inc(new, old);
4356 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4359 + unsigned int mnt_flags;
4360 + unsigned long long ull, max;
4361 + aufs_bindex_t br_id;
4362 + unsigned char verbose, writer;
4363 + struct file *file, *hf, **array;
4364 + struct au_hfile *hfile;
4366 + mnt_flags = au_mntflags(sb);
4367 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4369 + array = au_farray_alloc(sb, &max);
4370 + err = PTR_ERR(array);
4371 + if (IS_ERR(array))
4375 + br_id = au_sbr_id(sb, bindex);
4376 + for (ull = 0; ull < max; ull++) {
4377 + file = array[ull];
4378 + if (unlikely(!file))
4381 + /* AuDbg("%pD\n", file); */
4382 + fi_read_lock(file);
4383 + if (unlikely(au_test_mmapped(file))) {
4385 + AuVerbose(verbose, "mmapped %pD\n", file);
4387 + FiMustNoWaiters(file);
4388 + fi_read_unlock(file);
4392 + hfile = &au_fi(file)->fi_htop;
4393 + hf = hfile->hf_file;
4394 + if (!d_is_reg(file->f_path.dentry)
4395 + || !(file->f_mode & FMODE_WRITE)
4396 + || hfile->hf_br->br_id != br_id
4397 + || !(hf->f_mode & FMODE_WRITE))
4398 + array[ull] = NULL;
4404 + FiMustNoWaiters(file);
4405 + fi_read_unlock(file);
4413 + for (ull = 0; ull < max; ull++) {
4414 + file = array[ull];
4418 + /* todo: already flushed? */
4420 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4421 + * approach which resets f_mode and calls mnt_drop_write() and
4422 + * file_release_write() for each file, because the branch
4423 + * attribute in aufs world is totally different from the native
4426 + /* fi_read_lock(file); */
4427 + hfile = &au_fi(file)->fi_htop;
4428 + hf = hfile->hf_file;
4429 + /* fi_read_unlock(file); */
4430 + spin_lock(&hf->f_lock);
4431 + writer = !!(hf->f_mode & FMODE_WRITER);
4432 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4433 + spin_unlock(&hf->f_lock);
4435 + put_write_access(file_inode(hf));
4436 + __mnt_drop_write(hf->f_path.mnt);
4441 + au_farray_free(array, max);
4447 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4451 + aufs_bindex_t bindex;
4452 + struct dentry *root;
4453 + struct au_branch *br;
4454 + struct au_br_fhsm *bf;
4456 + root = sb->s_root;
4457 + bindex = au_find_dbindex(root, mod->h_root);
4460 + return 0; /* success */
4462 + pr_err("%s no such branch\n", mod->path);
4465 + AuDbg("bindex b%d\n", bindex);
4467 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4468 + if (unlikely(err))
4471 + br = au_sbr(sb, bindex);
4472 + AuDebugOn(mod->h_root != au_br_dentry(br));
4473 + if (br->br_perm == mod->perm)
4474 + return 0; /* success */
4476 + /* pre-allocate for non-fhsm --> fhsm */
4478 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4479 + err = au_fhsm_br_alloc(br);
4480 + if (unlikely(err))
4483 + br->br_fhsm = NULL;
4486 + if (au_br_writable(br->br_perm)) {
4487 + /* remove whiteout base */
4488 + err = au_br_init_wh(sb, br, mod->perm);
4489 + if (unlikely(err))
4492 + if (!au_br_writable(mod->perm)) {
4493 + /* rw --> ro, file might be mmapped */
4494 + DiMustNoWaiters(root);
4495 + IiMustNoWaiters(d_inode(root));
4496 + di_write_unlock(root);
4497 + err = au_br_mod_files_ro(sb, bindex);
4498 + /* aufs_write_lock() calls ..._child() */
4499 + di_write_lock_child(root);
4501 + if (unlikely(err)) {
4503 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4506 + rerr = au_wbr_init(br, sb, br->br_perm);
4507 + if (unlikely(rerr)) {
4508 + AuIOErr("nested error %d (%d)\n",
4510 + br->br_perm = mod->perm;
4514 + } else if (au_br_writable(mod->perm)) {
4517 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4519 + err = au_wbr_init(br, sb, mod->perm);
4520 + if (unlikely(err)) {
4521 + kfree(br->br_wbr);
4522 + br->br_wbr = NULL;
4526 + if (unlikely(err))
4529 + if (au_br_fhsm(br->br_perm)) {
4530 + if (!au_br_fhsm(mod->perm)) {
4531 + /* fhsm --> non-fhsm */
4532 + au_br_fhsm_fin(br->br_fhsm);
4533 + kfree(br->br_fhsm);
4534 + br->br_fhsm = NULL;
4536 + } else if (au_br_fhsm(mod->perm))
4537 + /* non-fhsm --> fhsm */
4540 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4541 + br->br_perm = mod->perm;
4542 + goto out; /* success */
4551 +/* ---------------------------------------------------------------------- */
4553 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4556 + struct kstatfs kstfs;
4558 + err = vfs_statfs(&br->br_path, &kstfs);
4560 + stfs->f_blocks = kstfs.f_blocks;
4561 + stfs->f_bavail = kstfs.f_bavail;
4562 + stfs->f_files = kstfs.f_files;
4563 + stfs->f_ffree = kstfs.f_ffree;
4568 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4569 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4570 +++ linux/fs/aufs/branch.h 2018-08-12 23:43:05.453457863 +0200
4572 +/* SPDX-License-Identifier: GPL-2.0 */
4574 + * Copyright (C) 2005-2018 Junjiro R. Okajima
4576 + * This program, aufs is free software; you can redistribute it and/or modify
4577 + * it under the terms of the GNU General Public License as published by
4578 + * the Free Software Foundation; either version 2 of the License, or
4579 + * (at your option) any later version.
4581 + * This program is distributed in the hope that it will be useful,
4582 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4583 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4584 + * GNU General Public License for more details.
4586 + * You should have received a copy of the GNU General Public License
4587 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4591 + * branch filesystems and xino for them
4594 +#ifndef __AUFS_BRANCH_H__
4595 +#define __AUFS_BRANCH_H__
4599 +#include <linux/mount.h>
4600 +#include "dirren.h"
4605 +/* ---------------------------------------------------------------------- */
4609 + struct file *xi_file;
4614 + /* reserved for future use */
4615 + /* unsigned long *bitmap; */
4616 + wait_queue_head_t wqh;
4619 + atomic_t xi_truncating;
4621 + struct kref xi_kref;
4623 + /* todo: make xino files an array to support huge inode number */
4626 +/* File-based Hierarchical Storage Management */
4627 +struct au_br_fhsm {
4628 +#ifdef CONFIG_AUFS_FHSM
4629 + struct mutex bf_lock;
4630 + unsigned long bf_jiffy;
4631 + struct aufs_stfs bf_stfs;
4636 +/* members for writable branch only */
4637 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4639 + struct au_rwsem wbr_wh_rwsem;
4640 + struct dentry *wbr_wh[AuBrWh_Last];
4641 + atomic_t wbr_wh_running;
4642 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4643 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4644 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4647 + unsigned long long wbr_bytes;
4650 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4651 +#define AuBrDynOp (AuDyLast * 4)
4653 +#ifdef CONFIG_AUFS_HFSNOTIFY
4654 +/* support for asynchronous destruction */
4655 +struct au_br_hfsnotify {
4656 + struct fsnotify_group *hfsn_group;
4660 +/* sysfs entries */
4661 +struct au_brsysfs {
4663 + struct attribute attr;
4672 +/* protected by superblock rwsem */
4674 + struct au_xino *br_xino;
4676 + aufs_bindex_t br_id;
4679 + struct path br_path;
4680 + spinlock_t br_dykey_lock;
4681 + struct au_dykey *br_dykey[AuBrDynOp];
4682 + struct percpu_counter br_count;
4684 + struct au_wbr *br_wbr;
4685 + struct au_br_fhsm *br_fhsm;
4687 +#ifdef CONFIG_AUFS_HFSNOTIFY
4688 + struct au_br_hfsnotify *br_hfsn;
4691 +#ifdef CONFIG_SYSFS
4692 + /* entries under sysfs per mount-point */
4693 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4696 +#ifdef CONFIG_DEBUG_FS
4697 + struct dentry *br_dbgaufs; /* xino */
4700 + struct au_dr_br br_dirren;
4703 +/* ---------------------------------------------------------------------- */
4705 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4707 + return br->br_path.mnt;
4710 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4712 + return br->br_path.dentry;
4715 +static inline struct super_block *au_br_sb(struct au_branch *br)
4717 + return au_br_mnt(br)->mnt_sb;
4720 +static inline void au_br_get(struct au_branch *br)
4722 + percpu_counter_inc(&br->br_count);
4725 +static inline void au_br_put(struct au_branch *br)
4727 + percpu_counter_dec(&br->br_count);
4730 +static inline s64 au_br_count(struct au_branch *br)
4732 + return percpu_counter_sum(&br->br_count);
4735 +static inline void au_br_count_init(struct au_branch *br)
4737 + percpu_counter_init(&br->br_count, 0, GFP_NOFS);
4740 +static inline void au_br_count_fin(struct au_branch *br)
4742 + percpu_counter_destroy(&br->br_count);
4745 +static inline int au_br_rdonly(struct au_branch *br)
4747 + return (sb_rdonly(au_br_sb(br))
4748 + || !au_br_writable(br->br_perm))
4752 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4754 +#ifdef CONFIG_AUFS_HNOTIFY
4755 + return !(brperm & AuBrPerm_RR);
4761 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4763 + int err, exec_flag;
4766 + exec_flag = oflag & __FMODE_EXEC;
4767 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4773 +static inline void au_xino_get(struct au_branch *br)
4775 + struct au_xino *xi;
4779 + kref_get(&xi->xi_kref);
4782 +static inline int au_xino_count(struct au_branch *br)
4785 + struct au_xino *xi;
4790 + v = kref_read(&xi->xi_kref);
4795 +static inline struct file *au_xino_file(struct au_branch *br)
4797 + struct au_xino *xi;
4800 + return xi ? xi->xi_file : NULL;
4803 +/* ---------------------------------------------------------------------- */
4807 +void au_br_free(struct au_sbinfo *sinfo);
4808 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4810 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4812 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4813 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4814 +#ifdef CONFIG_COMPAT
4815 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4818 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4821 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4824 +static const loff_t au_loff_max = LLONG_MAX;
4826 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent);
4827 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4828 + struct file *copy_src);
4830 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4832 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4834 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4836 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4837 + size_t size, loff_t *pos);
4839 +int au_xib_trunc(struct super_block *sb);
4840 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4842 +struct au_xino *au_xino_alloc(void);
4843 +int au_xino_put(struct au_branch *br);
4844 +void au_xino_file_set(struct au_branch *br, struct file *file);
4846 +struct au_opt_xino;
4847 +void au_xino_clr(struct super_block *sb);
4848 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4849 +struct file *au_xino_def(struct super_block *sb);
4850 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4851 + struct path *base);
4853 +ino_t au_xino_new_ino(struct super_block *sb);
4854 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4856 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4857 + ino_t h_ino, int idx);
4858 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4861 +int au_xino_path(struct seq_file *seq, struct file *file);
4863 +/* ---------------------------------------------------------------------- */
4865 +/* Superblock to branch */
4867 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4869 + return au_sbr(sb, bindex)->br_id;
4873 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4875 + return au_br_mnt(au_sbr(sb, bindex));
4879 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4881 + return au_br_sb(au_sbr(sb, bindex));
4884 +static inline void au_sbr_get(struct super_block *sb, aufs_bindex_t bindex)
4886 + au_br_get(au_sbr(sb, bindex));
4889 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4891 + au_br_put(au_sbr(sb, bindex));
4894 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4896 + return au_sbr(sb, bindex)->br_perm;
4899 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4901 + return au_br_whable(au_sbr_perm(sb, bindex));
4904 +/* ---------------------------------------------------------------------- */
4906 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4907 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4908 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4909 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4911 +#define wbr_wh_read_trylock_nested(wbr) \
4912 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4913 +#define wbr_wh_write_trylock_nested(wbr) \
4914 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4917 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4918 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4919 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4921 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4922 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4923 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4925 +/* ---------------------------------------------------------------------- */
4927 +#ifdef CONFIG_AUFS_FHSM
4928 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4930 + mutex_init(&brfhsm->bf_lock);
4931 + brfhsm->bf_jiffy = 0;
4932 + brfhsm->bf_readable = 0;
4935 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4937 + mutex_destroy(&brfhsm->bf_lock);
4940 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4941 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4944 +#endif /* __KERNEL__ */
4945 +#endif /* __AUFS_BRANCH_H__ */
4946 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4947 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4948 +++ linux/fs/aufs/conf.mk 2018-06-04 09:08:09.181412645 +0200
4950 +# SPDX-License-Identifier: GPL-2.0
4952 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4956 +AuConfStr += ${1}=${${1}}
4960 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4962 + HNOTIFY HFSNOTIFY \
4974 +$(foreach i, ${AuConfAll}, \
4975 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4977 +AuConfName = ${obj}/conf.str
4978 +${AuConfName}.tmp: FORCE
4979 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4980 +${AuConfName}: ${AuConfName}.tmp
4981 + @diff -q $< $@ > /dev/null 2>&1 || { \
4982 + echo ' GEN ' $@; \
4986 +clean-files += ${AuConfName} ${AuConfName}.tmp
4987 +${obj}/sysfs.o: ${AuConfName}
4989 +-include ${srctree}/${src}/conf_priv.mk
4990 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4991 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4992 +++ linux/fs/aufs/cpup.c 2018-08-12 23:43:05.453457863 +0200
4994 +// SPDX-License-Identifier: GPL-2.0
4996 + * Copyright (C) 2005-2018 Junjiro R. Okajima
4998 + * This program, aufs is free software; you can redistribute it and/or modify
4999 + * it under the terms of the GNU General Public License as published by
5000 + * the Free Software Foundation; either version 2 of the License, or
5001 + * (at your option) any later version.
5003 + * This program is distributed in the hope that it will be useful,
5004 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5005 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5006 + * GNU General Public License for more details.
5008 + * You should have received a copy of the GNU General Public License
5009 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5013 + * copy-up functions, see wbr_policy.c for copy-down
5016 +#include <linux/fs_stack.h>
5017 +#include <linux/mm.h>
5018 +#include <linux/task_work.h>
5021 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
5023 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
5024 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
5026 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
5028 + dst->i_flags |= iflags & ~mask;
5029 + if (au_test_fs_notime(dst->i_sb))
5030 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
5033 +void au_cpup_attr_timesizes(struct inode *inode)
5035 + struct inode *h_inode;
5037 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5038 + fsstack_copy_attr_times(inode, h_inode);
5039 + fsstack_copy_inode_size(inode, h_inode);
5042 +void au_cpup_attr_nlink(struct inode *inode, int force)
5044 + struct inode *h_inode;
5045 + struct super_block *sb;
5046 + aufs_bindex_t bindex, bbot;
5049 + bindex = au_ibtop(inode);
5050 + h_inode = au_h_iptr(inode, bindex);
5052 + && !S_ISDIR(h_inode->i_mode)
5053 + && au_opt_test(au_mntflags(sb), PLINK)
5054 + && au_plink_test(inode))
5058 + * 0 can happen in revalidating.
5059 + * h_inode->i_mutex may not be held here, but it is harmless since once
5060 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
5062 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
5063 + * the incorrect link count.
5065 + set_nlink(inode, h_inode->i_nlink);
5068 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
5069 + * it may includes whplink directory.
5071 + if (S_ISDIR(h_inode->i_mode)) {
5072 + bbot = au_ibbot(inode);
5073 + for (bindex++; bindex <= bbot; bindex++) {
5074 + h_inode = au_h_iptr(inode, bindex);
5076 + au_add_nlink(inode, h_inode);
5081 +void au_cpup_attr_changeable(struct inode *inode)
5083 + struct inode *h_inode;
5085 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5086 + inode->i_mode = h_inode->i_mode;
5087 + inode->i_uid = h_inode->i_uid;
5088 + inode->i_gid = h_inode->i_gid;
5089 + au_cpup_attr_timesizes(inode);
5090 + au_cpup_attr_flags(inode, h_inode->i_flags);
5093 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
5095 + struct au_iinfo *iinfo = au_ii(inode);
5097 + IiMustWriteLock(inode);
5099 + iinfo->ii_higen = h_inode->i_generation;
5100 + iinfo->ii_hsb1 = h_inode->i_sb;
5103 +void au_cpup_attr_all(struct inode *inode, int force)
5105 + struct inode *h_inode;
5107 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5108 + au_cpup_attr_changeable(inode);
5109 + if (inode->i_nlink > 0)
5110 + au_cpup_attr_nlink(inode, force);
5111 + inode->i_rdev = h_inode->i_rdev;
5112 + inode->i_blkbits = h_inode->i_blkbits;
5113 + au_cpup_igen(inode, h_inode);
5116 +/* ---------------------------------------------------------------------- */
5118 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
5120 +/* keep the timestamps of the parent dir when cpup */
5121 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5122 + struct path *h_path)
5124 + struct inode *h_inode;
5126 + dt->dt_dentry = dentry;
5127 + dt->dt_h_path = *h_path;
5128 + h_inode = d_inode(h_path->dentry);
5129 + dt->dt_atime = h_inode->i_atime;
5130 + dt->dt_mtime = h_inode->i_mtime;
5134 +void au_dtime_revert(struct au_dtime *dt)
5136 + struct iattr attr;
5139 + attr.ia_atime = dt->dt_atime;
5140 + attr.ia_mtime = dt->dt_mtime;
5141 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
5142 + | ATTR_ATIME | ATTR_ATIME_SET;
5144 + /* no delegation since this is a directory */
5145 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
5146 + if (unlikely(err))
5147 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
5150 +/* ---------------------------------------------------------------------- */
5152 +/* internal use only */
5153 +struct au_cpup_reg_attr {
5156 + unsigned int iflags; /* inode->i_flags */
5159 +static noinline_for_stack
5160 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
5161 + struct au_cpup_reg_attr *h_src_attr)
5163 + int err, sbits, icex;
5164 + unsigned int mnt_flags;
5165 + unsigned char verbose;
5167 + struct path h_path;
5168 + struct inode *h_isrc, *h_idst;
5169 + struct kstat *h_st;
5170 + struct au_branch *br;
5172 + h_path.dentry = au_h_dptr(dst, bindex);
5173 + h_idst = d_inode(h_path.dentry);
5174 + br = au_sbr(dst->d_sb, bindex);
5175 + h_path.mnt = au_br_mnt(br);
5176 + h_isrc = d_inode(h_src);
5177 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
5178 + | ATTR_ATIME | ATTR_MTIME
5179 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
5180 + if (h_src_attr && h_src_attr->valid) {
5181 + h_st = &h_src_attr->st;
5182 + ia.ia_uid = h_st->uid;
5183 + ia.ia_gid = h_st->gid;
5184 + ia.ia_atime = h_st->atime;
5185 + ia.ia_mtime = h_st->mtime;
5186 + if (h_idst->i_mode != h_st->mode
5187 + && !S_ISLNK(h_idst->i_mode)) {
5188 + ia.ia_valid |= ATTR_MODE;
5189 + ia.ia_mode = h_st->mode;
5191 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
5192 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
5194 + ia.ia_uid = h_isrc->i_uid;
5195 + ia.ia_gid = h_isrc->i_gid;
5196 + ia.ia_atime = h_isrc->i_atime;
5197 + ia.ia_mtime = h_isrc->i_mtime;
5198 + if (h_idst->i_mode != h_isrc->i_mode
5199 + && !S_ISLNK(h_idst->i_mode)) {
5200 + ia.ia_valid |= ATTR_MODE;
5201 + ia.ia_mode = h_isrc->i_mode;
5203 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5204 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5206 + /* no delegation since it is just created */
5207 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5209 + /* is this nfs only? */
5210 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5211 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5212 + ia.ia_mode = h_isrc->i_mode;
5213 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5216 + icex = br->br_perm & AuBrAttr_ICEX;
5218 + mnt_flags = au_mntflags(dst->d_sb);
5219 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5220 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5226 +/* ---------------------------------------------------------------------- */
5228 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5229 + char *buf, unsigned long blksize)
5232 + size_t sz, rbytes, wbytes;
5233 + unsigned char all_zero;
5235 + struct inode *h_inode;
5236 + /* reduce stack usage */
5239 + zp = page_address(ZERO_PAGE(0));
5240 + if (unlikely(!zp))
5241 + return -ENOMEM; /* possible? */
5246 + AuDbg("len %lld\n", len);
5248 + if (len < blksize)
5252 + /* todo: signal_pending? */
5253 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5254 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5257 + if (unlikely(err < 0))
5261 + if (len >= rbytes && rbytes == blksize)
5262 + all_zero = !memcmp(buf, zp, rbytes);
5269 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5271 + /* todo: signal_pending? */
5272 + if (unlikely(err == -EAGAIN || err == -EINTR))
5274 + if (unlikely(err < 0))
5279 + if (unlikely(err < 0))
5285 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5287 + if (unlikely(res < 0))
5294 + /* the last block may be a hole */
5295 + if (!err && all_zero) {
5296 + AuLabel(last hole);
5299 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5300 + /* nfs requires this step to make last hole */
5301 + /* is this only nfs? */
5303 + /* todo: signal_pending? */
5304 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5305 + } while (err == -EAGAIN || err == -EINTR);
5312 + ia->ia_size = dst->f_pos;
5313 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5314 + ia->ia_file = dst;
5315 + h_inode = file_inode(dst);
5316 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5317 + /* no delegation since it is just created */
5318 + err = vfsub_notify_change(&dst->f_path, ia,
5319 + /*delegated*/NULL);
5320 + inode_unlock(h_inode);
5327 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5330 + unsigned long blksize;
5331 + unsigned char do_kfree;
5335 + blksize = dst->f_path.dentry->d_sb->s_blocksize;
5336 + if (!blksize || PAGE_SIZE < blksize)
5337 + blksize = PAGE_SIZE;
5338 + AuDbg("blksize %lu\n", blksize);
5339 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5341 + buf = kmalloc(blksize, GFP_NOFS);
5343 + buf = (void *)__get_free_page(GFP_NOFS);
5344 + if (unlikely(!buf))
5347 + if (len > (1 << 22))
5348 + AuDbg("copying a large file %lld\n", (long long)len);
5352 + err = au_do_copy_file(dst, src, len, buf, blksize);
5356 + free_page((unsigned long)buf);
5362 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5365 + struct super_block *h_src_sb;
5366 + struct inode *h_src_inode;
5368 + h_src_inode = file_inode(src);
5369 + h_src_sb = h_src_inode->i_sb;
5371 + /* XFS acquires inode_lock */
5372 + if (!au_test_xfs(h_src_sb))
5373 + err = au_copy_file(dst, src, len);
5375 + inode_unlock_shared(h_src_inode);
5376 + err = au_copy_file(dst, src, len);
5377 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5383 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5386 + struct super_block *h_src_sb;
5387 + struct inode *h_src_inode;
5389 + h_src_inode = file_inode(src);
5390 + h_src_sb = h_src_inode->i_sb;
5391 + if (h_src_sb != file_inode(dst)->i_sb
5392 + || !dst->f_op->clone_file_range) {
5393 + err = au_do_copy(dst, src, len);
5397 + if (!au_test_nfs(h_src_sb)) {
5398 + inode_unlock_shared(h_src_inode);
5399 + err = vfsub_clone_file_range(src, dst, len);
5400 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5402 + err = vfsub_clone_file_range(src, dst, len);
5403 + /* older XFS has a condition in cloning */
5404 + if (unlikely(err != -EOPNOTSUPP))
5407 + /* the backend fs on NFS may not support cloning */
5408 + err = au_do_copy(dst, src, len);
5416 + * to support a sparse file which is opened with O_APPEND,
5417 + * we need to close the file.
5419 +static int au_cp_regular(struct au_cp_generic *cpg)
5422 + enum { SRC, DST };
5424 + aufs_bindex_t bindex;
5425 + unsigned int flags;
5426 + struct dentry *dentry;
5428 + struct file *file;
5432 + .bindex = cpg->bsrc,
5433 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5437 + .bindex = cpg->bdst,
5438 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5439 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5440 + .label = &&out_src
5443 + struct super_block *sb, *h_src_sb;
5444 + struct inode *h_src_inode;
5445 + struct task_struct *tsk = current;
5447 + /* bsrc branch can be ro/rw. */
5448 + sb = cpg->dentry->d_sb;
5450 + for (i = 0; i < 2; i++, f++) {
5451 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5452 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5453 + /*file*/NULL, f->force_wr);
5454 + err = PTR_ERR(f->file);
5455 + if (IS_ERR(f->file))
5459 + /* try stopping to update while we copyup */
5460 + h_src_inode = d_inode(file[SRC].dentry);
5461 + h_src_sb = h_src_inode->i_sb;
5462 + if (!au_test_nfs(h_src_sb))
5463 + IMustLock(h_src_inode);
5464 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5466 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5467 + if (tsk->flags & PF_KTHREAD)
5468 + __fput_sync(file[DST].file);
5470 + /* it happened actually */
5471 + fput(file[DST].file);
5474 + * we have to call both since we don't know which place the file
5478 + flush_delayed_fput();
5480 + au_sbr_put(sb, file[DST].bindex);
5483 + fput(file[SRC].file);
5484 + au_sbr_put(sb, file[SRC].bindex);
5489 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5490 + struct au_cpup_reg_attr *h_src_attr)
5494 + struct path h_path;
5495 + struct inode *h_src_inode, *h_dst_inode;
5498 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5499 + l = i_size_read(h_src_inode);
5500 + if (cpg->len == -1 || l < cpg->len)
5503 + /* try stopping to update while we are referencing */
5504 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5505 + au_pin_hdir_unlock(cpg->pin);
5507 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5508 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5509 + h_src_attr->iflags = h_src_inode->i_flags;
5510 + if (!au_test_nfs(h_src_inode->i_sb))
5511 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5513 + inode_unlock_shared(h_src_inode);
5514 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5515 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5517 + if (unlikely(err)) {
5518 + inode_unlock_shared(h_src_inode);
5521 + h_src_attr->valid = 1;
5522 + if (!au_test_nfs(h_src_inode->i_sb)) {
5523 + err = au_cp_regular(cpg);
5524 + inode_unlock_shared(h_src_inode);
5526 + inode_unlock_shared(h_src_inode);
5527 + err = au_cp_regular(cpg);
5529 + rerr = au_pin_hdir_relock(cpg->pin);
5533 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5534 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5535 + h_dst_inode = d_inode(h_path.dentry);
5536 + spin_lock(&h_dst_inode->i_lock);
5537 + h_dst_inode->i_state |= I_LINKABLE;
5538 + spin_unlock(&h_dst_inode->i_lock);
5545 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5546 + struct inode *h_dir)
5549 + mm_segment_t old_fs;
5556 + sym.k = (void *)__get_free_page(GFP_NOFS);
5557 + if (unlikely(!sym.k))
5560 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5561 + old_fs = get_fs();
5562 + set_fs(KERNEL_DS);
5563 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5568 + sym.k[symlen] = 0;
5569 + err = vfsub_symlink(h_dir, h_path, sym.k);
5571 + free_page((unsigned long)sym.k);
5578 + * regardless 'acl' option, reset all ACL.
5579 + * All ACL will be copied up later from the original entry on the lower branch.
5581 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5584 + struct dentry *h_dentry;
5585 + struct inode *h_inode;
5587 + h_dentry = h_path->dentry;
5588 + h_inode = d_inode(h_dentry);
5589 + /* forget_all_cached_acls(h_inode)); */
5590 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5592 + if (err == -EOPNOTSUPP)
5595 + err = vfsub_acl_chmod(h_inode, mode);
5601 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5602 + struct inode *h_dir, struct path *h_path)
5605 + struct inode *dir, *inode;
5607 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5609 + if (err == -EOPNOTSUPP)
5611 + if (unlikely(err))
5615 + * strange behaviour from the users view,
5616 + * particularry setattr case
5618 + dir = d_inode(dst_parent);
5619 + if (au_ibtop(dir) == cpg->bdst)
5620 + au_cpup_attr_nlink(dir, /*force*/1);
5621 + inode = d_inode(cpg->dentry);
5622 + au_cpup_attr_nlink(inode, /*force*/1);
5628 +static noinline_for_stack
5629 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5630 + struct au_cpup_reg_attr *h_src_attr)
5634 + unsigned int mnt_flags;
5635 + unsigned char isdir, isreg, force;
5636 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5637 + struct au_dtime dt;
5638 + struct path h_path;
5639 + struct dentry *h_src, *h_dst, *h_parent;
5640 + struct inode *h_inode, *h_dir;
5641 + struct super_block *sb;
5643 + /* bsrc branch can be ro/rw. */
5644 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5645 + h_inode = d_inode(h_src);
5646 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5648 + /* try stopping to be referenced while we are creating */
5649 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5650 + if (au_ftest_cpup(cpg->flags, RENAME))
5651 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5652 + AUFS_WH_PFX_LEN));
5653 + h_parent = h_dst->d_parent; /* dir inode is locked */
5654 + h_dir = d_inode(h_parent);
5656 + AuDebugOn(h_parent != h_dst->d_parent);
5658 + sb = cpg->dentry->d_sb;
5659 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5661 + h_path.dentry = h_parent;
5662 + au_dtime_store(&dt, dst_parent, &h_path);
5664 + h_path.dentry = h_dst;
5668 + mode = h_inode->i_mode;
5669 + switch (mode & S_IFMT) {
5672 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5674 + err = au_do_cpup_regular(cpg, h_src_attr);
5678 + err = vfsub_mkdir(h_dir, &h_path, mode);
5680 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5683 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5687 + AuDebugOn(!capable(CAP_MKNOD));
5691 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5694 + AuIOErr("Unknown inode type 0%o\n", mode);
5698 + err = au_reset_acl(h_dir, &h_path, mode);
5700 + mnt_flags = au_mntflags(sb);
5701 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5703 + && au_opt_test(mnt_flags, XINO)
5704 + && (h_inode->i_nlink == 1
5705 + || (h_inode->i_state & I_LINKABLE))
5706 + /* todo: unnecessary? */
5707 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5708 + && cpg->bdst < cpg->bsrc
5709 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5710 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5711 + /* ignore this error */
5716 + force = !!cpg->len;
5717 + if (cpg->len == -1)
5718 + force = !!i_size_read(h_inode);
5720 + au_fhsm_wrote(sb, cpg->bdst, force);
5724 + au_dtime_revert(&dt);
5728 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5731 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5732 + struct inode *h_dir;
5733 + aufs_bindex_t bdst;
5735 + dentry = cpg->dentry;
5737 + h_dentry = au_h_dptr(dentry, bdst);
5738 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5740 + au_set_h_dptr(dentry, bdst, NULL);
5741 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5743 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5744 + au_set_h_dptr(dentry, bdst, h_dentry);
5747 + parent = dget_parent(dentry);
5748 + h_parent = au_h_dptr(parent, bdst);
5750 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5751 + if (IS_ERR(h_path->dentry))
5752 + err = PTR_ERR(h_path->dentry);
5754 + if (unlikely(err))
5757 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5758 + h_dir = d_inode(h_parent);
5760 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5761 + /* no delegation since it is just created */
5762 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5764 + dput(h_path->dentry);
5771 + * copyup the @dentry from @bsrc to @bdst.
5772 + * the caller must set the both of lower dentries.
5773 + * @len is for truncating when it is -1 copyup the entire file.
5774 + * in link/rename cases, @dst_parent may be different from the real one.
5775 + * basic->bsrc can be larger than basic->bdst.
5776 + * aufs doesn't touch the credential so
5777 + * security_inode_copy_up{,_xattr}() are unnecrssary.
5779 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5782 + aufs_bindex_t old_ibtop;
5783 + unsigned char isdir, plink;
5784 + struct dentry *h_src, *h_dst, *h_parent;
5785 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5786 + struct super_block *sb;
5787 + struct au_branch *br;
5788 + /* to reuduce stack size */
5790 + struct au_dtime dt;
5791 + struct path h_path;
5792 + struct au_cpup_reg_attr h_src_attr;
5796 + a = kmalloc(sizeof(*a), GFP_NOFS);
5799 + a->h_src_attr.valid = 0;
5801 + sb = cpg->dentry->d_sb;
5802 + br = au_sbr(sb, cpg->bdst);
5803 + a->h_path.mnt = au_br_mnt(br);
5804 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5805 + h_parent = h_dst->d_parent; /* dir inode is locked */
5806 + h_dir = d_inode(h_parent);
5809 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5810 + inode = d_inode(cpg->dentry);
5813 + dst_parent = dget_parent(cpg->dentry);
5817 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5818 + dst_inode = au_h_iptr(inode, cpg->bdst);
5820 + if (unlikely(!plink)) {
5822 + AuIOErr("hi%lu(i%lu) exists on b%d "
5823 + "but plink is disabled\n",
5824 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5828 + if (dst_inode->i_nlink) {
5829 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5831 + h_src = au_plink_lkup(inode, cpg->bdst);
5832 + err = PTR_ERR(h_src);
5833 + if (IS_ERR(h_src))
5835 + if (unlikely(d_is_negative(h_src))) {
5837 + AuIOErr("i%lu exists on b%d "
5838 + "but not pseudo-linked\n",
5839 + inode->i_ino, cpg->bdst);
5845 + a->h_path.dentry = h_parent;
5846 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5849 + a->h_path.dentry = h_dst;
5851 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5852 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5853 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5855 + au_dtime_revert(&a->dt);
5856 + if (unlikely(err == -EWOULDBLOCK)) {
5857 + pr_warn("cannot retry for NFSv4 delegation"
5858 + " for an internal link\n");
5864 + /* todo: cpup_wh_file? */
5866 + au_update_ibrange(inode, /*do_put_zero*/1);
5869 + isdir = S_ISDIR(inode->i_mode);
5870 + old_ibtop = au_ibtop(inode);
5871 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5872 + if (unlikely(err))
5874 + dst_inode = d_inode(h_dst);
5875 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5876 + /* todo: necessary? */
5877 + /* au_pin_hdir_unlock(cpg->pin); */
5879 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5880 + if (unlikely(err)) {
5881 + /* todo: necessary? */
5882 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5883 + inode_unlock(dst_inode);
5887 + if (cpg->bdst < old_ibtop) {
5888 + if (S_ISREG(inode->i_mode)) {
5889 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5890 + if (unlikely(err)) {
5891 + /* ignore an error */
5892 + /* au_pin_hdir_relock(cpg->pin); */
5893 + inode_unlock(dst_inode);
5897 + au_set_ibtop(inode, cpg->bdst);
5899 + au_set_ibbot(inode, cpg->bdst);
5900 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5901 + au_hi_flags(inode, isdir));
5903 + /* todo: necessary? */
5904 + /* err = au_pin_hdir_relock(cpg->pin); */
5905 + inode_unlock(dst_inode);
5906 + if (unlikely(err))
5909 + src_inode = d_inode(h_src);
5911 + && (src_inode->i_nlink > 1
5912 + || src_inode->i_state & I_LINKABLE)
5914 + au_plink_append(inode, cpg->bdst, h_dst);
5916 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5917 + a->h_path.dentry = h_dst;
5918 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5921 + goto out_parent; /* success */
5925 + a->h_path.dentry = h_parent;
5926 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5927 + a->h_path.dentry = h_dst;
5929 + if (d_is_positive(h_dst)) {
5931 + /* no delegation since it is just created */
5932 + rerr = vfsub_unlink(h_dir, &a->h_path,
5933 + /*delegated*/NULL, /*force*/0);
5935 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5937 + au_dtime_revert(&a->dt);
5939 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5949 +#if 0 /* reserved */
5950 +struct au_cpup_single_args {
5952 + struct au_cp_generic *cpg;
5953 + struct dentry *dst_parent;
5956 +static void au_call_cpup_single(void *args)
5958 + struct au_cpup_single_args *a = args;
5960 + au_pin_hdir_acquire_nest(a->cpg->pin);
5961 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5962 + au_pin_hdir_release(a->cpg->pin);
5967 + * prevent SIGXFSZ in copy-up.
5968 + * testing CAP_MKNOD is for generic fs,
5969 + * but CAP_FSETID is for xfs only, currently.
5971 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5974 + struct super_block *sb;
5975 + struct inode *h_dir;
5978 + sb = au_pinned_parent(pin)->d_sb;
5979 + if (!au_wkq_test()
5980 + && (!au_sbi(sb)->si_plink_maint_pid
5981 + || au_plink_maint(sb, AuLock_NOPLM))) {
5982 + switch (mode & S_IFMT) {
5984 + /* no condition about RLIMIT_FSIZE and the file size */
5989 + do_sio = !capable(CAP_MKNOD);
5993 + do_sio = ((mode & (S_ISUID | S_ISGID))
5994 + && !capable(CAP_FSETID));
5995 + /* this workaround may be removed in the future */
5997 + h_dir = au_pinned_h_dir(pin);
5998 + do_sio = h_dir->i_mode & S_ISVTX;
6005 +#if 0 /* reserved */
6006 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
6009 + struct dentry *h_dentry;
6011 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
6012 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
6013 + err = au_cpup_single(cpg, dst_parent);
6015 + struct au_cpup_single_args args = {
6018 + .dst_parent = dst_parent
6020 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
6021 + if (unlikely(wkq_err))
6030 + * copyup the @dentry from the first active lower branch to @bdst,
6031 + * using au_cpup_single().
6033 +static int au_cpup_simple(struct au_cp_generic *cpg)
6036 + unsigned int flags_orig;
6037 + struct dentry *dentry;
6039 + AuDebugOn(cpg->bsrc < 0);
6041 + dentry = cpg->dentry;
6042 + DiMustWriteLock(dentry);
6044 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
6046 + flags_orig = cpg->flags;
6047 + au_fset_cpup(cpg->flags, RENAME);
6048 + err = au_cpup_single(cpg, NULL);
6049 + cpg->flags = flags_orig;
6051 + return 0; /* success */
6054 + au_set_h_dptr(dentry, cpg->bdst, NULL);
6055 + au_set_dbtop(dentry, cpg->bsrc);
6061 +struct au_cpup_simple_args {
6063 + struct au_cp_generic *cpg;
6066 +static void au_call_cpup_simple(void *args)
6068 + struct au_cpup_simple_args *a = args;
6070 + au_pin_hdir_acquire_nest(a->cpg->pin);
6071 + *a->errp = au_cpup_simple(a->cpg);
6072 + au_pin_hdir_release(a->cpg->pin);
6075 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
6078 + struct dentry *dentry, *parent;
6079 + struct file *h_file;
6080 + struct inode *h_dir;
6082 + dentry = cpg->dentry;
6084 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
6085 + AuDebugOn(cpg->bsrc < 0);
6086 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
6087 + err = PTR_ERR(h_file);
6088 + if (IS_ERR(h_file))
6092 + parent = dget_parent(dentry);
6093 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
6094 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
6095 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6096 + err = au_cpup_simple(cpg);
6098 + struct au_cpup_simple_args args = {
6102 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
6103 + if (unlikely(wkq_err))
6109 + au_h_open_post(dentry, cpg->bsrc, h_file);
6115 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
6117 + aufs_bindex_t bsrc, bbot;
6118 + struct dentry *dentry, *h_dentry;
6120 + if (cpg->bsrc < 0) {
6121 + dentry = cpg->dentry;
6122 + bbot = au_dbbot(dentry);
6123 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
6124 + h_dentry = au_h_dptr(dentry, bsrc);
6126 + AuDebugOn(d_is_negative(h_dentry));
6130 + AuDebugOn(bsrc > bbot);
6133 + AuDebugOn(cpg->bsrc <= cpg->bdst);
6134 + return au_do_sio_cpup_simple(cpg);
6137 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
6139 + AuDebugOn(cpg->bdst <= cpg->bsrc);
6140 + return au_do_sio_cpup_simple(cpg);
6143 +/* ---------------------------------------------------------------------- */
6146 + * copyup the deleted file for writing.
6148 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
6149 + struct file *file)
6152 + unsigned int flags_orig;
6153 + aufs_bindex_t bsrc_orig;
6154 + struct au_dinfo *dinfo;
6156 + struct au_hdentry *hd;
6157 + struct dentry *h_dentry;
6160 + dinfo = au_di(cpg->dentry);
6161 + AuRwMustWriteLock(&dinfo->di_rwsem);
6163 + bsrc_orig = cpg->bsrc;
6164 + cpg->bsrc = dinfo->di_btop;
6165 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
6166 + hdst.h_dentry = hdst.hd->hd_dentry;
6167 + hdst.hd->hd_dentry = wh_dentry;
6168 + dinfo->di_btop = cpg->bdst;
6170 + hsrc.h_dentry = NULL;
6172 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
6173 + hsrc.h_dentry = hsrc.hd->hd_dentry;
6174 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
6176 + flags_orig = cpg->flags;
6177 + cpg->flags = !AuCpup_DTIME;
6178 + err = au_cpup_single(cpg, /*h_parent*/NULL);
6179 + cpg->flags = flags_orig;
6182 + err = au_reopen_nondir(file);
6183 + hsrc.hd->hd_dentry = hsrc.h_dentry;
6185 + hdst.hd->hd_dentry = hdst.h_dentry;
6186 + dinfo->di_btop = cpg->bsrc;
6187 + cpg->bsrc = bsrc_orig;
6192 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6195 + aufs_bindex_t bdst;
6196 + struct au_dtime dt;
6197 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6198 + struct au_branch *br;
6199 + struct path h_path;
6201 + dentry = cpg->dentry;
6203 + br = au_sbr(dentry->d_sb, bdst);
6204 + parent = dget_parent(dentry);
6205 + h_parent = au_h_dptr(parent, bdst);
6206 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6207 + err = PTR_ERR(wh_dentry);
6208 + if (IS_ERR(wh_dentry))
6211 + h_path.dentry = h_parent;
6212 + h_path.mnt = au_br_mnt(br);
6213 + au_dtime_store(&dt, parent, &h_path);
6214 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6215 + if (unlikely(err))
6219 + h_path.dentry = wh_dentry;
6220 + if (!d_is_dir(wh_dentry)) {
6221 + /* no delegation since it is just created */
6222 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6223 + /*delegated*/NULL, /*force*/0);
6225 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6226 + if (unlikely(err)) {
6227 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6231 + au_dtime_revert(&dt);
6232 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6241 +struct au_cpup_wh_args {
6243 + struct au_cp_generic *cpg;
6244 + struct file *file;
6247 +static void au_call_cpup_wh(void *args)
6249 + struct au_cpup_wh_args *a = args;
6251 + au_pin_hdir_acquire_nest(a->cpg->pin);
6252 + *a->errp = au_cpup_wh(a->cpg, a->file);
6253 + au_pin_hdir_release(a->cpg->pin);
6256 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6259 + aufs_bindex_t bdst;
6260 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6261 + struct inode *dir, *h_dir, *h_tmpdir;
6262 + struct au_wbr *wbr;
6263 + struct au_pin wh_pin, *pin_orig;
6265 + dentry = cpg->dentry;
6267 + parent = dget_parent(dentry);
6268 + dir = d_inode(parent);
6271 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6274 + if (!h_dir->i_nlink) {
6275 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6276 + h_orph = wbr->wbr_orph;
6278 + h_parent = dget(au_h_dptr(parent, bdst));
6279 + au_set_h_dptr(parent, bdst, dget(h_orph));
6280 + h_tmpdir = d_inode(h_orph);
6281 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6283 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6284 + /* todo: au_h_open_pre()? */
6286 + pin_orig = cpg->pin;
6287 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6288 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6289 + cpg->pin = &wh_pin;
6292 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6293 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6294 + err = au_cpup_wh(cpg, file);
6296 + struct au_cpup_wh_args args = {
6301 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6302 + if (unlikely(wkq_err))
6307 + inode_unlock(h_tmpdir);
6308 + /* todo: au_h_open_post()? */
6309 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6310 + au_set_h_dptr(parent, bdst, h_parent);
6311 + AuDebugOn(!pin_orig);
6312 + cpg->pin = pin_orig;
6320 +/* ---------------------------------------------------------------------- */
6323 + * generic routine for both of copy-up and copy-down.
6325 +/* cf. revalidate function in file.c */
6326 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6327 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6328 + struct au_pin *pin,
6329 + struct dentry *h_parent, void *arg),
6333 + struct au_pin pin;
6334 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6337 + parent = dget_parent(dentry);
6338 + if (IS_ROOT(parent))
6341 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6342 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6344 + /* do not use au_dpage */
6345 + real_parent = parent;
6348 + parent = dget_parent(dentry);
6349 + h_parent = au_h_dptr(parent, bdst);
6351 + goto out; /* success */
6353 + /* find top dir which is necessary to cpup */
6357 + parent = dget_parent(d);
6358 + di_read_lock_parent3(parent, !AuLock_IR);
6359 + h_parent = au_h_dptr(parent, bdst);
6360 + di_read_unlock(parent, !AuLock_IR);
6361 + } while (!h_parent);
6363 + if (d != real_parent)
6364 + di_write_lock_child3(d);
6366 + /* somebody else might create while we were sleeping */
6367 + h_dentry = au_h_dptr(d, bdst);
6368 + if (!h_dentry || d_is_negative(h_dentry)) {
6370 + au_update_dbtop(d);
6372 + au_pin_set_dentry(&pin, d);
6373 + err = au_do_pin(&pin);
6375 + err = cp(d, bdst, &pin, h_parent, arg);
6380 + if (d != real_parent)
6381 + di_write_unlock(d);
6382 + if (unlikely(err))
6391 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6392 + struct au_pin *pin,
6393 + struct dentry *h_parent __maybe_unused,
6394 + void *arg __maybe_unused)
6396 + struct au_cp_generic cpg = {
6402 + .flags = AuCpup_DTIME
6404 + return au_sio_cpup_simple(&cpg);
6407 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6409 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6412 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6415 + struct dentry *parent;
6416 + struct inode *dir;
6418 + parent = dget_parent(dentry);
6419 + dir = d_inode(parent);
6421 + if (au_h_iptr(dir, bdst))
6424 + di_read_unlock(parent, AuLock_IR);
6425 + di_write_lock_parent(parent);
6426 + /* someone else might change our inode while we were sleeping */
6427 + if (!au_h_iptr(dir, bdst))
6428 + err = au_cpup_dirs(dentry, bdst);
6429 + di_downgrade_lock(parent, AuLock_IR);
6435 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6436 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6437 +++ linux/fs/aufs/cpup.h 2018-08-12 23:43:05.453457863 +0200
6439 +/* SPDX-License-Identifier: GPL-2.0 */
6441 + * Copyright (C) 2005-2018 Junjiro R. Okajima
6443 + * This program, aufs is free software; you can redistribute it and/or modify
6444 + * it under the terms of the GNU General Public License as published by
6445 + * the Free Software Foundation; either version 2 of the License, or
6446 + * (at your option) any later version.
6448 + * This program is distributed in the hope that it will be useful,
6449 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6450 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6451 + * GNU General Public License for more details.
6453 + * You should have received a copy of the GNU General Public License
6454 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6458 + * copy-up/down functions
6461 +#ifndef __AUFS_CPUP_H__
6462 +#define __AUFS_CPUP_H__
6466 +#include <linux/path.h>
6472 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6473 +void au_cpup_attr_timesizes(struct inode *inode);
6474 +void au_cpup_attr_nlink(struct inode *inode, int force);
6475 +void au_cpup_attr_changeable(struct inode *inode);
6476 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6477 +void au_cpup_attr_all(struct inode *inode, int force);
6479 +/* ---------------------------------------------------------------------- */
6481 +struct au_cp_generic {
6482 + struct dentry *dentry;
6483 + aufs_bindex_t bdst, bsrc;
6485 + struct au_pin *pin;
6486 + unsigned int flags;
6490 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6491 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6493 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6494 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6496 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6498 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6499 + the branch is marked as RO */
6501 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6502 +#undef AuCpup_HOPEN
6503 +#define AuCpup_HOPEN 0
6506 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6507 +#define au_fset_cpup(flags, name) \
6508 + do { (flags) |= AuCpup_##name; } while (0)
6509 +#define au_fclr_cpup(flags, name) \
6510 + do { (flags) &= ~AuCpup_##name; } while (0)
6512 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6513 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6514 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6515 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6517 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6518 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6519 + struct au_pin *pin,
6520 + struct dentry *h_parent, void *arg),
6522 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6523 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6525 +/* ---------------------------------------------------------------------- */
6527 +/* keep timestamps when copyup */
6529 + struct dentry *dt_dentry;
6530 + struct path dt_h_path;
6531 + struct timespec64 dt_atime, dt_mtime;
6533 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6534 + struct path *h_path);
6535 +void au_dtime_revert(struct au_dtime *dt);
6537 +#endif /* __KERNEL__ */
6538 +#endif /* __AUFS_CPUP_H__ */
6539 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6540 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6541 +++ linux/fs/aufs/dbgaufs.c 2018-08-12 23:43:05.453457863 +0200
6543 +// SPDX-License-Identifier: GPL-2.0
6545 + * Copyright (C) 2005-2018 Junjiro R. Okajima
6547 + * This program, aufs is free software; you can redistribute it and/or modify
6548 + * it under the terms of the GNU General Public License as published by
6549 + * the Free Software Foundation; either version 2 of the License, or
6550 + * (at your option) any later version.
6552 + * This program is distributed in the hope that it will be useful,
6553 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6554 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6555 + * GNU General Public License for more details.
6557 + * You should have received a copy of the GNU General Public License
6558 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6562 + * debugfs interface
6565 +#include <linux/debugfs.h>
6568 +#ifndef CONFIG_SYSFS
6569 +#error DEBUG_FS depends upon SYSFS
6572 +static struct dentry *dbgaufs;
6573 +static const mode_t dbgaufs_mode = 0444;
6575 +/* 20 is max digits length of ulong 64 */
6576 +struct dbgaufs_arg {
6582 + * common function for all XINO files
6584 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6585 + struct file *file)
6587 + kfree(file->private_data);
6591 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6596 + struct dbgaufs_arg *p;
6599 + p = kmalloc(sizeof(*p), GFP_NOFS);
6605 + file->private_data = p;
6609 + err = vfsub_getattr(&xf->f_path, &st);
6613 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6614 + cnt, st.blocks, st.blksize,
6615 + (long long)st.size);
6617 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6618 + st.blocks, st.blksize,
6619 + (long long)st.size);
6620 + AuDebugOn(p->n >= sizeof(p->a));
6622 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6631 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6632 + size_t count, loff_t *ppos)
6634 + struct dbgaufs_arg *p;
6636 + p = file->private_data;
6637 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6640 +/* ---------------------------------------------------------------------- */
6642 +struct dbgaufs_plink_arg {
6647 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6648 + struct file *file)
6650 + free_page((unsigned long)file->private_data);
6654 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6656 + int err, i, limit;
6657 + unsigned long n, sum;
6658 + struct dbgaufs_plink_arg *p;
6659 + struct au_sbinfo *sbinfo;
6660 + struct super_block *sb;
6661 + struct hlist_bl_head *hbl;
6664 + p = (void *)get_zeroed_page(GFP_NOFS);
6669 + sbinfo = inode->i_private;
6670 + sb = sbinfo->si_sb;
6671 + si_noflush_read_lock(sb);
6672 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6673 + limit = PAGE_SIZE - sizeof(p->n);
6675 + /* the number of buckets */
6676 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6681 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6683 + n = au_hbl_count(hbl);
6686 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6689 + if (unlikely(limit <= 0))
6692 + p->a[p->n - 1] = '\n';
6694 + /* the sum of plinks */
6695 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6698 + if (unlikely(limit <= 0))
6701 +#define str "1\n0\n0\n"
6702 + p->n = sizeof(str) - 1;
6703 + strcpy(p->a, str);
6706 + si_read_unlock(sb);
6709 + file->private_data = p;
6710 + goto out; /* success */
6713 + free_page((unsigned long)p);
6718 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6719 + size_t count, loff_t *ppos)
6721 + struct dbgaufs_plink_arg *p;
6723 + p = file->private_data;
6724 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6727 +static const struct file_operations dbgaufs_plink_fop = {
6728 + .owner = THIS_MODULE,
6729 + .open = dbgaufs_plink_open,
6730 + .release = dbgaufs_plink_release,
6731 + .read = dbgaufs_plink_read
6734 +/* ---------------------------------------------------------------------- */
6736 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6739 + struct au_sbinfo *sbinfo;
6740 + struct super_block *sb;
6742 + sbinfo = inode->i_private;
6743 + sb = sbinfo->si_sb;
6744 + si_noflush_read_lock(sb);
6745 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6746 + si_read_unlock(sb);
6750 +static const struct file_operations dbgaufs_xib_fop = {
6751 + .owner = THIS_MODULE,
6752 + .open = dbgaufs_xib_open,
6753 + .release = dbgaufs_xi_release,
6754 + .read = dbgaufs_xi_read
6757 +/* ---------------------------------------------------------------------- */
6759 +#define DbgaufsXi_PREFIX "xi"
6761 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6765 + struct au_sbinfo *sbinfo;
6766 + struct super_block *sb;
6768 + struct qstr *name;
6769 + struct au_branch *br;
6773 + name = &file->f_path.dentry->d_name;
6774 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6775 + || memcmp(name->name, DbgaufsXi_PREFIX,
6776 + sizeof(DbgaufsXi_PREFIX) - 1)))
6778 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6779 + if (unlikely(err))
6782 + sbinfo = inode->i_private;
6783 + sb = sbinfo->si_sb;
6784 + si_noflush_read_lock(sb);
6785 + if (l <= au_sbbot(sb)) {
6786 + br = au_sbr(sb, (aufs_bindex_t)l);
6787 + xf = au_xino_file(br);
6788 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6789 + au_xino_count(br));
6792 + si_read_unlock(sb);
6798 +static const struct file_operations dbgaufs_xino_fop = {
6799 + .owner = THIS_MODULE,
6800 + .open = dbgaufs_xino_open,
6801 + .release = dbgaufs_xi_release,
6802 + .read = dbgaufs_xi_read
6805 +void dbgaufs_xino_del(struct au_branch *br)
6807 + struct dentry *dbgaufs;
6809 + dbgaufs = br->br_dbgaufs;
6813 + br->br_dbgaufs = NULL;
6814 + /* debugfs acquires the parent i_mutex */
6816 + debugfs_remove(dbgaufs);
6820 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6822 + aufs_bindex_t bbot;
6823 + struct au_branch *br;
6825 + if (!au_sbi(sb)->si_dbgaufs)
6828 + bbot = au_sbbot(sb);
6829 + for (; bindex <= bbot; bindex++) {
6830 + br = au_sbr(sb, bindex);
6831 + dbgaufs_xino_del(br);
6835 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6836 + struct dentry *parent, struct au_sbinfo *sbinfo)
6838 + struct au_branch *br;
6840 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
6842 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6843 + br = au_sbr(sb, bindex);
6844 + if (br->br_dbgaufs) {
6845 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6847 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6848 + /* debugfs acquires the parent i_mutex */
6850 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6854 + pr_warn("failed renaming %pd/%s, ignored.\n",
6859 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6860 + sbinfo, &dbgaufs_xino_fop);
6862 + if (unlikely(!br->br_dbgaufs))
6863 + pr_warn("failed creaiting %pd/%s, ignored.\n",
6868 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6870 + struct au_sbinfo *sbinfo;
6871 + struct dentry *parent;
6872 + aufs_bindex_t bbot;
6874 + if (!au_opt_test(au_mntflags(sb), XINO))
6877 + sbinfo = au_sbi(sb);
6878 + parent = sbinfo->si_dbgaufs;
6882 + bbot = au_sbbot(sb);
6884 + for (; bindex <= bbot; bindex++)
6885 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6887 + for (; bbot >= bindex; bbot--)
6888 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6891 +/* ---------------------------------------------------------------------- */
6893 +#ifdef CONFIG_AUFS_EXPORT
6894 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6897 + struct au_sbinfo *sbinfo;
6898 + struct super_block *sb;
6900 + sbinfo = inode->i_private;
6901 + sb = sbinfo->si_sb;
6902 + si_noflush_read_lock(sb);
6903 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6904 + si_read_unlock(sb);
6908 +static const struct file_operations dbgaufs_xigen_fop = {
6909 + .owner = THIS_MODULE,
6910 + .open = dbgaufs_xigen_open,
6911 + .release = dbgaufs_xi_release,
6912 + .read = dbgaufs_xi_read
6915 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6920 + * This function is a dynamic '__init' function actually,
6921 + * so the tiny check for si_rwsem is unnecessary.
6923 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6926 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6927 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6928 + &dbgaufs_xigen_fop);
6929 + if (sbinfo->si_dbgaufs_xigen)
6935 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6939 +#endif /* CONFIG_AUFS_EXPORT */
6941 +/* ---------------------------------------------------------------------- */
6943 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6946 + * This function is a dynamic '__fin' function actually,
6947 + * so the tiny check for si_rwsem is unnecessary.
6949 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6951 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6952 + sbinfo->si_dbgaufs = NULL;
6955 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6958 + char name[SysaufsSiNameLen];
6961 + * This function is a dynamic '__init' function actually,
6962 + * so the tiny check for si_rwsem is unnecessary.
6964 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6968 + AuErr1("/debug/aufs is uninitialized\n");
6973 + sysaufs_name(sbinfo, name);
6974 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6975 + if (unlikely(!sbinfo->si_dbgaufs))
6978 + /* regardless plink/noplink option */
6979 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6980 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6981 + &dbgaufs_plink_fop);
6982 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6985 + /* regardless xino/noxino option */
6986 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6987 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6988 + &dbgaufs_xib_fop);
6989 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6992 + err = dbgaufs_xigen_init(sbinfo);
6994 + goto out; /* success */
6997 + dbgaufs_si_fin(sbinfo);
6999 + if (unlikely(err))
7000 + pr_err("debugfs/aufs failed\n");
7004 +/* ---------------------------------------------------------------------- */
7006 +void dbgaufs_fin(void)
7008 + debugfs_remove(dbgaufs);
7011 +int __init dbgaufs_init(void)
7016 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
7021 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
7022 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
7023 +++ linux/fs/aufs/dbgaufs.h 2018-08-12 23:43:05.453457863 +0200
7025 +/* SPDX-License-Identifier: GPL-2.0 */
7027 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7029 + * This program, aufs is free software; you can redistribute it and/or modify
7030 + * it under the terms of the GNU General Public License as published by
7031 + * the Free Software Foundation; either version 2 of the License, or
7032 + * (at your option) any later version.
7034 + * This program is distributed in the hope that it will be useful,
7035 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7036 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7037 + * GNU General Public License for more details.
7039 + * You should have received a copy of the GNU General Public License
7040 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7044 + * debugfs interface
7047 +#ifndef __DBGAUFS_H__
7048 +#define __DBGAUFS_H__
7052 +struct super_block;
7056 +#ifdef CONFIG_DEBUG_FS
7058 +void dbgaufs_xino_del(struct au_branch *br);
7059 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
7060 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
7061 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
7062 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
7063 +void dbgaufs_fin(void);
7064 +int __init dbgaufs_init(void);
7066 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
7067 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
7068 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
7070 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
7071 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
7072 +AuStubVoid(dbgaufs_fin, void)
7073 +AuStubInt0(__init dbgaufs_init, void)
7074 +#endif /* CONFIG_DEBUG_FS */
7076 +#endif /* __KERNEL__ */
7077 +#endif /* __DBGAUFS_H__ */
7078 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
7079 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
7080 +++ linux/fs/aufs/dcsub.c 2018-08-12 23:43:05.453457863 +0200
7082 +// SPDX-License-Identifier: GPL-2.0
7084 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7086 + * This program, aufs is free software; you can redistribute it and/or modify
7087 + * it under the terms of the GNU General Public License as published by
7088 + * the Free Software Foundation; either version 2 of the License, or
7089 + * (at your option) any later version.
7091 + * This program is distributed in the hope that it will be useful,
7092 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7093 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7094 + * GNU General Public License for more details.
7096 + * You should have received a copy of the GNU General Public License
7097 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7101 + * sub-routines for dentry cache
7106 +static void au_dpage_free(struct au_dpage *dpage)
7109 + struct dentry **p;
7111 + p = dpage->dentries;
7112 + for (i = 0; i < dpage->ndentry; i++)
7114 + free_page((unsigned long)dpage->dentries);
7117 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
7123 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
7124 + if (unlikely(!dpages->dpages))
7127 + p = (void *)__get_free_page(gfp);
7131 + dpages->dpages[0].ndentry = 0;
7132 + dpages->dpages[0].dentries = p;
7133 + dpages->ndpage = 1;
7134 + return 0; /* success */
7137 + kfree(dpages->dpages);
7142 +void au_dpages_free(struct au_dcsub_pages *dpages)
7145 + struct au_dpage *p;
7147 + p = dpages->dpages;
7148 + for (i = 0; i < dpages->ndpage; i++)
7149 + au_dpage_free(p++);
7150 + kfree(dpages->dpages);
7153 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7154 + struct dentry *dentry, gfp_t gfp)
7157 + struct au_dpage *dpage;
7160 + dpage = dpages->dpages + dpages->ndpage - 1;
7161 + sz = PAGE_SIZE / sizeof(dentry);
7162 + if (unlikely(dpage->ndentry >= sz)) {
7163 + AuLabel(new dpage);
7165 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7166 + p = au_kzrealloc(dpages->dpages, sz,
7167 + sz + sizeof(*dpages->dpages), gfp,
7172 + dpages->dpages = p;
7173 + dpage = dpages->dpages + dpages->ndpage;
7174 + p = (void *)__get_free_page(gfp);
7178 + dpage->ndentry = 0;
7179 + dpage->dentries = p;
7183 + AuDebugOn(au_dcount(dentry) <= 0);
7184 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7185 + return 0; /* success */
7191 +/* todo: BAD approach */
7192 +/* copied from linux/fs/dcache.c */
7200 +extern void d_walk(struct dentry *parent, void *data,
7201 + enum d_walk_ret (*enter)(void *, struct dentry *));
7203 +struct ac_dpages_arg {
7205 + struct au_dcsub_pages *dpages;
7206 + struct super_block *sb;
7207 + au_dpages_test test;
7211 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7213 + enum d_walk_ret ret;
7214 + struct ac_dpages_arg *arg = _arg;
7216 + ret = D_WALK_CONTINUE;
7217 + if (dentry->d_sb == arg->sb
7218 + && !IS_ROOT(dentry)
7219 + && au_dcount(dentry) > 0
7221 + && (!arg->test || arg->test(dentry, arg->arg))) {
7222 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7223 + if (unlikely(arg->err))
7224 + ret = D_WALK_QUIT;
7230 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7231 + au_dpages_test test, void *arg)
7233 + struct ac_dpages_arg args = {
7241 + d_walk(root, &args, au_call_dpages_append);
7246 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7247 + int do_include, au_dpages_test test, void *arg)
7252 + write_seqlock(&rename_lock);
7253 + spin_lock(&dentry->d_lock);
7255 + && au_dcount(dentry) > 0
7256 + && (!test || test(dentry, arg)))
7257 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7258 + spin_unlock(&dentry->d_lock);
7259 + if (unlikely(err))
7263 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7266 + while (!IS_ROOT(dentry)) {
7267 + dentry = dentry->d_parent; /* rename_lock is locked */
7268 + spin_lock(&dentry->d_lock);
7269 + if (au_dcount(dentry) > 0
7270 + && (!test || test(dentry, arg)))
7271 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7272 + spin_unlock(&dentry->d_lock);
7273 + if (unlikely(err))
7278 + write_sequnlock(&rename_lock);
7282 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7284 + return au_di(dentry) && dentry->d_sb == arg;
7287 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7288 + struct dentry *dentry, int do_include)
7290 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7291 + au_dcsub_dpages_aufs, dentry->d_sb);
7294 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7296 + struct path path[2] = {
7305 + return path_is_under(path + 0, path + 1);
7307 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7308 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7309 +++ linux/fs/aufs/dcsub.h 2018-08-12 23:43:05.453457863 +0200
7311 +/* SPDX-License-Identifier: GPL-2.0 */
7313 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7315 + * This program, aufs is free software; you can redistribute it and/or modify
7316 + * it under the terms of the GNU General Public License as published by
7317 + * the Free Software Foundation; either version 2 of the License, or
7318 + * (at your option) any later version.
7320 + * This program is distributed in the hope that it will be useful,
7321 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7322 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7323 + * GNU General Public License for more details.
7325 + * You should have received a copy of the GNU General Public License
7326 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7330 + * sub-routines for dentry cache
7333 +#ifndef __AUFS_DCSUB_H__
7334 +#define __AUFS_DCSUB_H__
7338 +#include <linux/dcache.h>
7339 +#include <linux/fs.h>
7343 + struct dentry **dentries;
7346 +struct au_dcsub_pages {
7348 + struct au_dpage *dpages;
7351 +/* ---------------------------------------------------------------------- */
7354 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7355 +void au_dpages_free(struct au_dcsub_pages *dpages);
7356 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7357 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7358 + au_dpages_test test, void *arg);
7359 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7360 + int do_include, au_dpages_test test, void *arg);
7361 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7362 + struct dentry *dentry, int do_include);
7363 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7365 +/* ---------------------------------------------------------------------- */
7368 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7369 + * include/linux/dcache.h. Try them (in the future).
7372 +static inline int au_d_hashed_positive(struct dentry *d)
7375 + struct inode *inode = d_inode(d);
7378 + if (unlikely(d_unhashed(d)
7379 + || d_is_negative(d)
7380 + || !inode->i_nlink))
7385 +static inline int au_d_linkable(struct dentry *d)
7388 + struct inode *inode = d_inode(d);
7390 + err = au_d_hashed_positive(d);
7392 + && d_is_positive(d)
7393 + && (inode->i_state & I_LINKABLE))
7398 +static inline int au_d_alive(struct dentry *d)
7401 + struct inode *inode;
7405 + err = au_d_hashed_positive(d);
7407 + inode = d_inode(d);
7408 + if (unlikely(d_unlinked(d)
7409 + || d_is_negative(d)
7410 + || !inode->i_nlink))
7416 +static inline int au_alive_dir(struct dentry *d)
7420 + err = au_d_alive(d);
7421 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7426 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7428 + return a->len == b->len
7429 + && !memcmp(a->name, b->name, a->len);
7434 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7436 + * the type of d_lockref.count became int, but the inlined function d_count()
7437 + * still returns unsigned int.
7438 + * I don't know why. Maybe it is for every d_count() users?
7439 + * Anyway au_dcount() lives on.
7441 +static inline int au_dcount(struct dentry *d)
7443 + return (int)d_count(d);
7446 +#endif /* __KERNEL__ */
7447 +#endif /* __AUFS_DCSUB_H__ */
7448 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7449 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7450 +++ linux/fs/aufs/debug.c 2018-08-12 23:43:05.453457863 +0200
7452 +// SPDX-License-Identifier: GPL-2.0
7454 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7456 + * This program, aufs is free software; you can redistribute it and/or modify
7457 + * it under the terms of the GNU General Public License as published by
7458 + * the Free Software Foundation; either version 2 of the License, or
7459 + * (at your option) any later version.
7461 + * This program is distributed in the hope that it will be useful,
7462 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7463 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7464 + * GNU General Public License for more details.
7466 + * You should have received a copy of the GNU General Public License
7467 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7471 + * debug print functions
7476 +/* Returns 0, or -errno. arg is in kp->arg. */
7477 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7481 + err = kstrtoint(val, 0, &n);
7491 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7492 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7497 + return sprintf(buffer, "%d", atomic_read(a));
7500 +static struct kernel_param_ops param_ops_atomic_t = {
7501 + .set = param_atomic_t_set,
7502 + .get = param_atomic_t_get
7503 + /* void (*free)(void *arg) */
7506 +atomic_t aufs_debug = ATOMIC_INIT(0);
7507 +MODULE_PARM_DESC(debug, "debug print");
7508 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7510 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7511 +char *au_plevel = KERN_DEBUG;
7512 +#define dpri(fmt, ...) do { \
7514 + && strcmp(au_plevel, KERN_DEBUG)) \
7515 + || au_debug_test()) \
7516 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7519 +/* ---------------------------------------------------------------------- */
7521 +void au_dpri_whlist(struct au_nhash *whlist)
7523 + unsigned long ul, n;
7524 + struct hlist_head *head;
7525 + struct au_vdir_wh *pos;
7527 + n = whlist->nh_num;
7528 + head = whlist->nh_head;
7529 + for (ul = 0; ul < n; ul++) {
7530 + hlist_for_each_entry(pos, head, wh_hash)
7531 + dpri("b%d, %.*s, %d\n",
7533 + pos->wh_str.len, pos->wh_str.name,
7539 +void au_dpri_vdir(struct au_vdir *vdir)
7542 + union au_vdir_deblk_p p;
7545 + if (!vdir || IS_ERR(vdir)) {
7546 + dpri("err %ld\n", PTR_ERR(vdir));
7550 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7551 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7552 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7553 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7554 + p.deblk = vdir->vd_deblk[ul];
7556 + dpri("[%lu]: %p\n", ul, o);
7560 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7561 + struct dentry *wh)
7566 + if (!inode || IS_ERR(inode)) {
7567 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7571 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7572 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7573 + && sizeof(inode->i_blocks) != sizeof(u64));
7575 + n = (void *)wh->d_name.name;
7576 + l = wh->d_name.len;
7579 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7580 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7582 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7583 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7584 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7585 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7586 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7587 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7588 + inode->i_generation,
7589 + l ? ", wh " : "", l, n);
7593 +void au_dpri_inode(struct inode *inode)
7595 + struct au_iinfo *iinfo;
7596 + struct au_hinode *hi;
7597 + aufs_bindex_t bindex;
7600 + err = do_pri_inode(-1, inode, -1, NULL);
7601 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7604 + iinfo = au_ii(inode);
7605 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7606 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7607 + if (iinfo->ii_btop < 0)
7610 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7611 + hi = au_hinode(iinfo, bindex);
7613 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7617 +void au_dpri_dalias(struct inode *inode)
7621 + spin_lock(&inode->i_lock);
7622 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7623 + au_dpri_dentry(d);
7624 + spin_unlock(&inode->i_lock);
7627 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7629 + struct dentry *wh = NULL;
7631 + struct inode *inode;
7632 + struct au_iinfo *iinfo;
7633 + struct au_hinode *hi;
7635 + if (!dentry || IS_ERR(dentry)) {
7636 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7639 + /* do not call dget_parent() here */
7640 + /* note: access d_xxx without d_lock */
7641 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7642 + bindex, dentry, dentry,
7643 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7644 + au_dcount(dentry), dentry->d_flags,
7645 + d_unhashed(dentry) ? "un" : "");
7648 + if (d_is_positive(dentry))
7649 + inode = d_inode(dentry);
7651 + && au_test_aufs(dentry->d_sb)
7653 + && !au_is_bad_inode(inode)) {
7654 + iinfo = au_ii(inode);
7655 + hi = au_hinode(iinfo, bindex);
7657 + wh = hi->hi_whdentry;
7659 + do_pri_inode(bindex, inode, hn, wh);
7663 +void au_dpri_dentry(struct dentry *dentry)
7665 + struct au_dinfo *dinfo;
7666 + aufs_bindex_t bindex;
7669 + err = do_pri_dentry(-1, dentry);
7670 + if (err || !au_test_aufs(dentry->d_sb))
7673 + dinfo = au_di(dentry);
7676 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7677 + dinfo->di_btop, dinfo->di_bbot,
7678 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7679 + dinfo->di_tmpfile);
7680 + if (dinfo->di_btop < 0)
7682 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7683 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7686 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7690 + if (!file || IS_ERR(file)) {
7691 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7696 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7697 + && au_test_aufs(file->f_path.dentry->d_sb)
7699 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7700 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7701 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7702 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7703 + file->f_version, file->f_pos, a);
7704 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7705 + do_pri_dentry(bindex, file->f_path.dentry);
7709 +void au_dpri_file(struct file *file)
7711 + struct au_finfo *finfo;
7712 + struct au_fidir *fidir;
7713 + struct au_hfile *hfile;
7714 + aufs_bindex_t bindex;
7717 + err = do_pri_file(-1, file);
7719 + || IS_ERR_OR_NULL(file->f_path.dentry)
7720 + || !au_test_aufs(file->f_path.dentry->d_sb))
7723 + finfo = au_fi(file);
7726 + if (finfo->fi_btop < 0)
7728 + fidir = finfo->fi_hdir;
7730 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7732 + for (bindex = finfo->fi_btop;
7733 + bindex >= 0 && bindex <= fidir->fd_bbot;
7735 + hfile = fidir->fd_hfile + bindex;
7736 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7740 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7742 + struct vfsmount *mnt;
7743 + struct super_block *sb;
7745 + if (!br || IS_ERR(br))
7747 + mnt = au_br_mnt(br);
7748 + if (!mnt || IS_ERR(mnt))
7751 + if (!sb || IS_ERR(sb))
7754 + dpri("s%d: {perm 0x%x, id %d, cnt %lld, wbr %p}, "
7755 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7757 + bindex, br->br_perm, br->br_id, au_br_count(br),
7758 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7759 + sb->s_flags, sb->s_count,
7760 + atomic_read(&sb->s_active), !!au_xino_file(br));
7764 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7768 +void au_dpri_sb(struct super_block *sb)
7770 + struct au_sbinfo *sbinfo;
7771 + aufs_bindex_t bindex;
7773 + /* to reuduce stack size */
7775 + struct vfsmount mnt;
7776 + struct au_branch fake;
7779 + /* this function can be called from magic sysrq */
7780 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7781 + if (unlikely(!a)) {
7782 + dpri("no memory\n");
7786 + a->mnt.mnt_sb = sb;
7787 + a->fake.br_path.mnt = &a->mnt;
7788 + au_br_count_init(&a->fake);
7789 + err = do_pri_br(-1, &a->fake);
7790 + au_br_count_fin(&a->fake);
7792 + dpri("dev 0x%x\n", sb->s_dev);
7793 + if (err || !au_test_aufs(sb))
7796 + sbinfo = au_sbi(sb);
7799 + dpri("nw %d, gen %u, kobj %d\n",
7800 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7801 + kref_read(&sbinfo->si_kobj.kref));
7802 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7803 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7806 +/* ---------------------------------------------------------------------- */
7808 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7810 + struct inode *h_inode, *inode = d_inode(dentry);
7811 + struct dentry *h_dentry;
7812 + aufs_bindex_t bindex, bbot, bi;
7814 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7817 + bbot = au_dbbot(dentry);
7818 + bi = au_ibbot(inode);
7821 + bindex = au_dbtop(dentry);
7822 + bi = au_ibtop(inode);
7826 + for (; bindex <= bbot; bindex++) {
7827 + h_dentry = au_h_dptr(dentry, bindex);
7830 + h_inode = au_h_iptr(inode, bindex);
7831 + if (unlikely(h_inode != d_inode(h_dentry))) {
7833 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7834 + AuDbgDentry(dentry);
7835 + AuDbgInode(inode);
7842 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7845 + struct au_dcsub_pages dpages;
7846 + struct au_dpage *dpage;
7847 + struct dentry **dentries;
7849 + err = au_dpages_init(&dpages, GFP_NOFS);
7851 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7853 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7854 + dpage = dpages.dpages + i;
7855 + dentries = dpage->dentries;
7856 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7857 + AuDebugOn(au_digen_test(dentries[j], sigen));
7859 + au_dpages_free(&dpages);
7862 +void au_dbg_verify_kthread(void)
7864 + if (au_wkq_test()) {
7867 + * It may be recursive, but udba=notify between two aufs mounts,
7868 + * where a single ro branch is shared, is not a problem.
7874 +/* ---------------------------------------------------------------------- */
7876 +int __init au_debug_init(void)
7878 + aufs_bindex_t bindex;
7879 + struct au_vdir_destr destr;
7882 + AuDebugOn(bindex >= 0);
7885 + AuDebugOn(destr.len < NAME_MAX);
7887 +#ifdef CONFIG_4KSTACKS
7888 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7893 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7894 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7895 +++ linux/fs/aufs/debug.h 2018-08-12 23:43:05.453457863 +0200
7897 +/* SPDX-License-Identifier: GPL-2.0 */
7899 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7901 + * This program, aufs is free software; you can redistribute it and/or modify
7902 + * it under the terms of the GNU General Public License as published by
7903 + * the Free Software Foundation; either version 2 of the License, or
7904 + * (at your option) any later version.
7906 + * This program is distributed in the hope that it will be useful,
7907 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7908 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7909 + * GNU General Public License for more details.
7911 + * You should have received a copy of the GNU General Public License
7912 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7916 + * debug print functions
7919 +#ifndef __AUFS_DEBUG_H__
7920 +#define __AUFS_DEBUG_H__
7924 +#include <linux/atomic.h>
7925 +#include <linux/module.h>
7926 +#include <linux/kallsyms.h>
7927 +#include <linux/sysrq.h>
7929 +#ifdef CONFIG_AUFS_DEBUG
7930 +#define AuDebugOn(a) BUG_ON(a)
7932 +/* module parameter */
7933 +extern atomic_t aufs_debug;
7934 +static inline void au_debug_on(void)
7936 + atomic_inc(&aufs_debug);
7938 +static inline void au_debug_off(void)
7940 + atomic_dec_if_positive(&aufs_debug);
7943 +static inline int au_debug_test(void)
7945 + return atomic_read(&aufs_debug) > 0;
7948 +#define AuDebugOn(a) do {} while (0)
7949 +AuStubVoid(au_debug_on, void)
7950 +AuStubVoid(au_debug_off, void)
7951 +AuStubInt0(au_debug_test, void)
7952 +#endif /* CONFIG_AUFS_DEBUG */
7954 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7956 +/* ---------------------------------------------------------------------- */
7960 +#define AuDbg(fmt, ...) do { \
7961 + if (au_debug_test()) \
7962 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7964 +#define AuLabel(l) AuDbg(#l "\n")
7965 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7966 +#define AuWarn1(fmt, ...) do { \
7967 + static unsigned char _c; \
7969 + pr_warn(fmt, ##__VA_ARGS__); \
7972 +#define AuErr1(fmt, ...) do { \
7973 + static unsigned char _c; \
7975 + pr_err(fmt, ##__VA_ARGS__); \
7978 +#define AuIOErr1(fmt, ...) do { \
7979 + static unsigned char _c; \
7981 + AuIOErr(fmt, ##__VA_ARGS__); \
7984 +#define AuUnsupportMsg "This operation is not supported." \
7985 + " Please report this application to aufs-users ML."
7986 +#define AuUnsupport(fmt, ...) do { \
7987 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7991 +#define AuTraceErr(e) do { \
7992 + if (unlikely((e) < 0)) \
7993 + AuDbg("err %d\n", (int)(e)); \
7996 +#define AuTraceErrPtr(p) do { \
7998 + AuDbg("err %ld\n", PTR_ERR(p)); \
8001 +/* dirty macros for debug print, use with "%.*s" and caution */
8002 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
8004 +/* ---------------------------------------------------------------------- */
8007 +#ifdef CONFIG_AUFS_DEBUG
8008 +extern struct mutex au_dbg_mtx;
8009 +extern char *au_plevel;
8011 +void au_dpri_whlist(struct au_nhash *whlist);
8013 +void au_dpri_vdir(struct au_vdir *vdir);
8015 +void au_dpri_inode(struct inode *inode);
8016 +void au_dpri_dalias(struct inode *inode);
8017 +void au_dpri_dentry(struct dentry *dentry);
8019 +void au_dpri_file(struct file *filp);
8020 +struct super_block;
8021 +void au_dpri_sb(struct super_block *sb);
8023 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
8024 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
8025 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
8026 +void au_dbg_verify_kthread(void);
8028 +int __init au_debug_init(void);
8030 +#define AuDbgWhlist(w) do { \
8031 + mutex_lock(&au_dbg_mtx); \
8033 + au_dpri_whlist(w); \
8034 + mutex_unlock(&au_dbg_mtx); \
8037 +#define AuDbgVdir(v) do { \
8038 + mutex_lock(&au_dbg_mtx); \
8040 + au_dpri_vdir(v); \
8041 + mutex_unlock(&au_dbg_mtx); \
8044 +#define AuDbgInode(i) do { \
8045 + mutex_lock(&au_dbg_mtx); \
8047 + au_dpri_inode(i); \
8048 + mutex_unlock(&au_dbg_mtx); \
8051 +#define AuDbgDAlias(i) do { \
8052 + mutex_lock(&au_dbg_mtx); \
8054 + au_dpri_dalias(i); \
8055 + mutex_unlock(&au_dbg_mtx); \
8058 +#define AuDbgDentry(d) do { \
8059 + mutex_lock(&au_dbg_mtx); \
8061 + au_dpri_dentry(d); \
8062 + mutex_unlock(&au_dbg_mtx); \
8065 +#define AuDbgFile(f) do { \
8066 + mutex_lock(&au_dbg_mtx); \
8068 + au_dpri_file(f); \
8069 + mutex_unlock(&au_dbg_mtx); \
8072 +#define AuDbgSb(sb) do { \
8073 + mutex_lock(&au_dbg_mtx); \
8074 + AuDbg(#sb "\n"); \
8076 + mutex_unlock(&au_dbg_mtx); \
8079 +#define AuDbgSym(addr) do { \
8080 + char sym[KSYM_SYMBOL_LEN]; \
8081 + sprint_symbol(sym, (unsigned long)addr); \
8082 + AuDbg("%s\n", sym); \
8085 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
8086 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
8087 +AuStubVoid(au_dbg_verify_kthread, void)
8088 +AuStubInt0(__init au_debug_init, void)
8090 +#define AuDbgWhlist(w) do {} while (0)
8091 +#define AuDbgVdir(v) do {} while (0)
8092 +#define AuDbgInode(i) do {} while (0)
8093 +#define AuDbgDAlias(i) do {} while (0)
8094 +#define AuDbgDentry(d) do {} while (0)
8095 +#define AuDbgFile(f) do {} while (0)
8096 +#define AuDbgSb(sb) do {} while (0)
8097 +#define AuDbgSym(addr) do {} while (0)
8098 +#endif /* CONFIG_AUFS_DEBUG */
8100 +/* ---------------------------------------------------------------------- */
8102 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
8103 +int __init au_sysrq_init(void);
8104 +void au_sysrq_fin(void);
8106 +#ifdef CONFIG_HW_CONSOLE
8107 +#define au_dbg_blocked() do { \
8109 + handle_sysrq('w'); \
8112 +AuStubVoid(au_dbg_blocked, void)
8116 +AuStubInt0(__init au_sysrq_init, void)
8117 +AuStubVoid(au_sysrq_fin, void)
8118 +AuStubVoid(au_dbg_blocked, void)
8119 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
8121 +#endif /* __KERNEL__ */
8122 +#endif /* __AUFS_DEBUG_H__ */
8123 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
8124 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
8125 +++ linux/fs/aufs/dentry.c 2018-08-12 23:43:05.453457863 +0200
8127 +// SPDX-License-Identifier: GPL-2.0
8129 + * Copyright (C) 2005-2018 Junjiro R. Okajima
8131 + * This program, aufs is free software; you can redistribute it and/or modify
8132 + * it under the terms of the GNU General Public License as published by
8133 + * the Free Software Foundation; either version 2 of the License, or
8134 + * (at your option) any later version.
8136 + * This program is distributed in the hope that it will be useful,
8137 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8138 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8139 + * GNU General Public License for more details.
8141 + * You should have received a copy of the GNU General Public License
8142 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8146 + * lookup and dentry operations
8149 +#include <linux/namei.h>
8153 + * returns positive/negative dentry, NULL or an error.
8154 + * NULL means whiteout-ed or not-found.
8156 +static struct dentry*
8157 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8158 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8160 + struct dentry *h_dentry;
8161 + struct inode *h_inode;
8162 + struct au_branch *br;
8163 + int wh_found, opq;
8164 + unsigned char wh_able;
8165 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8166 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8170 + br = au_sbr(dentry->d_sb, bindex);
8171 + wh_able = !!au_br_whable(br->br_perm);
8173 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8174 + h_dentry = ERR_PTR(wh_found);
8177 + if (unlikely(wh_found < 0))
8180 + /* We found a whiteout */
8181 + /* au_set_dbbot(dentry, bindex); */
8182 + au_set_dbwh(dentry, bindex);
8184 + return NULL; /* success */
8188 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8190 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8191 + if (IS_ERR(h_dentry)) {
8192 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8198 + h_inode = d_inode(h_dentry);
8199 + if (d_is_negative(h_dentry)) {
8202 + } else if (wh_found
8203 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8205 + else if (au_ftest_lkup(args->flags, DIRREN)
8207 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8208 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8209 + (unsigned long long)h_inode->i_ino);
8213 + if (au_dbbot(dentry) <= bindex)
8214 + au_set_dbbot(dentry, bindex);
8215 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8216 + au_set_dbtop(dentry, bindex);
8217 + au_set_h_dptr(dentry, bindex, h_dentry);
8219 + if (!d_is_dir(h_dentry)
8221 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8222 + goto out; /* success */
8224 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8225 + opq = au_diropq_test(h_dentry);
8226 + inode_unlock_shared(h_inode);
8228 + au_set_dbdiropq(dentry, bindex);
8229 + else if (unlikely(opq < 0)) {
8230 + au_set_h_dptr(dentry, bindex, NULL);
8231 + h_dentry = ERR_PTR(opq);
8242 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8244 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8245 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8251 + * returns the number of lower positive dentries,
8252 + * otherwise an error.
8253 + * can be called at unlinking with @type is zero.
8255 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8256 + unsigned int flags)
8258 + int npositive, err;
8259 + aufs_bindex_t bindex, btail, bdiropq;
8260 + unsigned char isdir, dirperm1, dirren;
8261 + struct au_do_lookup_args args = {
8263 + .name = &dentry->d_name
8265 + struct dentry *parent;
8266 + struct super_block *sb;
8268 + sb = dentry->d_sb;
8269 + err = au_test_shwh(sb, args.name);
8270 + if (unlikely(err))
8273 + err = au_wh_name_alloc(&args.whname, args.name);
8274 + if (unlikely(err))
8277 + isdir = !!d_is_dir(dentry);
8278 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8279 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8281 + au_fset_lkup(args.flags, DIRREN);
8284 + parent = dget_parent(dentry);
8285 + btail = au_dbtaildir(parent);
8286 + for (bindex = btop; bindex <= btail; bindex++) {
8287 + struct dentry *h_parent, *h_dentry;
8288 + struct inode *h_inode, *h_dir;
8289 + struct au_branch *br;
8291 + h_dentry = au_h_dptr(dentry, bindex);
8293 + if (d_is_positive(h_dentry))
8297 + h_parent = au_h_dptr(parent, bindex);
8298 + if (!h_parent || !d_is_dir(h_parent))
8302 + /* if the inum matches, then use the prepared name */
8303 + err = au_dr_lkup_name(&args, bindex);
8304 + if (unlikely(err))
8308 + h_dir = d_inode(h_parent);
8309 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8310 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8311 + inode_unlock_shared(h_dir);
8312 + err = PTR_ERR(h_dentry);
8313 + if (IS_ERR(h_dentry))
8316 + au_fclr_lkup(args.flags, ALLOW_NEG);
8318 + au_fset_lkup(args.flags, IGNORE_PERM);
8320 + if (au_dbwh(dentry) == bindex)
8324 + if (d_is_negative(h_dentry))
8326 + h_inode = d_inode(h_dentry);
8329 + args.type = h_inode->i_mode & S_IFMT;
8330 + if (args.type != S_IFDIR)
8333 + /* the type of lower may be different */
8334 + bdiropq = au_dbdiropq(dentry);
8335 + if (bdiropq >= 0 && bdiropq <= bindex)
8338 + br = au_sbr(sb, bindex);
8340 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8341 + /*add_ent*/NULL)) {
8342 + /* prepare next name to lookup */
8343 + err = au_dr_lkup(&args, dentry, bindex);
8344 + if (unlikely(err))
8350 + AuLabel(positive);
8351 + au_update_dbtop(dentry);
8354 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8355 + && au_dbtop(dentry) < 0)) {
8357 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8363 + kfree(args.whname.name);
8365 + au_dr_lkup_fin(&args);
8370 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8372 + struct dentry *dentry;
8375 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8376 + dentry = vfsub_lkup_one(name, parent);
8378 + struct vfsub_lkup_one_args args = {
8384 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8385 + if (unlikely(wkq_err))
8386 + dentry = ERR_PTR(wkq_err);
8393 + * lookup @dentry on @bindex which should be negative.
8395 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8398 + struct dentry *parent, *h_parent, *h_dentry;
8399 + struct au_branch *br;
8401 + parent = dget_parent(dentry);
8402 + h_parent = au_h_dptr(parent, bindex);
8403 + br = au_sbr(dentry->d_sb, bindex);
8405 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8407 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8408 + err = PTR_ERR(h_dentry);
8409 + if (IS_ERR(h_dentry))
8411 + if (unlikely(d_is_positive(h_dentry))) {
8413 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8419 + if (bindex < au_dbtop(dentry))
8420 + au_set_dbtop(dentry, bindex);
8421 + if (au_dbbot(dentry) < bindex)
8422 + au_set_dbbot(dentry, bindex);
8423 + au_set_h_dptr(dentry, bindex, h_dentry);
8430 +/* ---------------------------------------------------------------------- */
8432 +/* subset of struct inode */
8434 + unsigned long i_ino;
8435 + /* unsigned int i_nlink; */
8441 + blkcnt_t i_blocks;
8446 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8448 + ia->i_ino = h_inode->i_ino;
8449 + /* ia->i_nlink = h_inode->i_nlink; */
8450 + ia->i_uid = h_inode->i_uid;
8451 + ia->i_gid = h_inode->i_gid;
8452 + ia->i_version = inode_query_iversion(h_inode);
8454 + ia->i_size = h_inode->i_size;
8455 + ia->i_blocks = h_inode->i_blocks;
8457 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8460 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8462 + return ia->i_ino != h_inode->i_ino
8463 + /* || ia->i_nlink != h_inode->i_nlink */
8464 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8465 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8466 + || !inode_eq_iversion(h_inode, ia->i_version)
8468 + || ia->i_size != h_inode->i_size
8469 + || ia->i_blocks != h_inode->i_blocks
8471 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8474 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8475 + struct au_branch *br)
8478 + struct au_iattr ia;
8479 + struct inode *h_inode;
8480 + struct dentry *h_d;
8481 + struct super_block *h_sb;
8484 + memset(&ia, -1, sizeof(ia));
8485 + h_sb = h_dentry->d_sb;
8487 + if (d_is_positive(h_dentry)) {
8488 + h_inode = d_inode(h_dentry);
8489 + au_iattr_save(&ia, h_inode);
8490 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8491 + /* nfs d_revalidate may return 0 for negative dentry */
8492 + /* fuse d_revalidate always return 0 for negative dentry */
8495 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8496 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8497 + err = PTR_ERR(h_d);
8502 + if (unlikely(h_d != h_dentry
8503 + || d_inode(h_d) != h_inode
8504 + || (h_inode && au_iattr_test(&ia, h_inode))))
8505 + err = au_busy_or_stale();
8513 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8514 + struct dentry *h_parent, struct au_branch *br)
8519 + if (udba == AuOpt_UDBA_REVAL
8520 + && !au_test_fs_remote(h_dentry->d_sb)) {
8522 + err = (d_inode(h_dentry->d_parent) != h_dir);
8523 + } else if (udba != AuOpt_UDBA_NONE)
8524 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8529 +/* ---------------------------------------------------------------------- */
8531 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8534 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8535 + struct au_hdentry tmp, *p, *q;
8536 + struct au_dinfo *dinfo;
8537 + struct super_block *sb;
8539 + DiMustWriteLock(dentry);
8541 + sb = dentry->d_sb;
8542 + dinfo = au_di(dentry);
8543 + bbot = dinfo->di_bbot;
8544 + bwh = dinfo->di_bwh;
8545 + bdiropq = dinfo->di_bdiropq;
8546 + bindex = dinfo->di_btop;
8547 + p = au_hdentry(dinfo, bindex);
8548 + for (; bindex <= bbot; bindex++, p++) {
8549 + if (!p->hd_dentry)
8552 + new_bindex = au_br_index(sb, p->hd_id);
8553 + if (new_bindex == bindex)
8556 + if (dinfo->di_bwh == bindex)
8558 + if (dinfo->di_bdiropq == bindex)
8559 + bdiropq = new_bindex;
8560 + if (new_bindex < 0) {
8562 + p->hd_dentry = NULL;
8566 + /* swap two lower dentries, and loop again */
8567 + q = au_hdentry(dinfo, new_bindex);
8571 + if (tmp.hd_dentry) {
8577 + dinfo->di_bwh = -1;
8578 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8579 + dinfo->di_bwh = bwh;
8581 + dinfo->di_bdiropq = -1;
8583 + && bdiropq <= au_sbbot(sb)
8584 + && au_sbr_whable(sb, bdiropq))
8585 + dinfo->di_bdiropq = bdiropq;
8588 + dinfo->di_btop = -1;
8589 + dinfo->di_bbot = -1;
8590 + bbot = au_dbbot(parent);
8592 + p = au_hdentry(dinfo, bindex);
8593 + for (; bindex <= bbot; bindex++, p++)
8594 + if (p->hd_dentry) {
8595 + dinfo->di_btop = bindex;
8599 + if (dinfo->di_btop >= 0) {
8601 + p = au_hdentry(dinfo, bindex);
8602 + for (; bindex >= 0; bindex--, p--)
8603 + if (p->hd_dentry) {
8604 + dinfo->di_bbot = bindex;
8613 +static void au_do_hide(struct dentry *dentry)
8615 + struct inode *inode;
8617 + if (d_really_is_positive(dentry)) {
8618 + inode = d_inode(dentry);
8619 + if (!d_is_dir(dentry)) {
8620 + if (inode->i_nlink && !d_unhashed(dentry))
8621 + drop_nlink(inode);
8623 + clear_nlink(inode);
8624 + /* stop next lookup */
8625 + inode->i_flags |= S_DEAD;
8627 + smp_mb(); /* necessary? */
8632 +static int au_hide_children(struct dentry *parent)
8634 + int err, i, j, ndentry;
8635 + struct au_dcsub_pages dpages;
8636 + struct au_dpage *dpage;
8637 + struct dentry *dentry;
8639 + err = au_dpages_init(&dpages, GFP_NOFS);
8640 + if (unlikely(err))
8642 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8643 + if (unlikely(err))
8646 + /* in reverse order */
8647 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8648 + dpage = dpages.dpages + i;
8649 + ndentry = dpage->ndentry;
8650 + for (j = ndentry - 1; j >= 0; j--) {
8651 + dentry = dpage->dentries[j];
8652 + if (dentry != parent)
8653 + au_do_hide(dentry);
8658 + au_dpages_free(&dpages);
8663 +static void au_hide(struct dentry *dentry)
8667 + AuDbgDentry(dentry);
8668 + if (d_is_dir(dentry)) {
8669 + /* shrink_dcache_parent(dentry); */
8670 + err = au_hide_children(dentry);
8671 + if (unlikely(err))
8672 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8675 + au_do_hide(dentry);
8679 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8681 + * a dirty branch is added
8682 + * - on the top of layers
8683 + * - in the middle of layers
8684 + * - to the bottom of layers
8686 + * on the added branch there exists
8689 + * - a same named entry
8691 + * * negative --> positive
8692 + * * positive --> positive
8693 + * - type is unchanged
8694 + * - type is changed
8696 + * * negative --> negative
8697 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8700 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8701 + struct au_dinfo *tmp)
8704 + aufs_bindex_t bindex, bbot;
8706 + struct dentry *dentry;
8707 + struct inode *inode;
8709 + } orig_h, tmp_h = {
8712 + struct au_hdentry *hd;
8713 + struct inode *inode, *h_inode;
8714 + struct dentry *h_dentry;
8717 + AuDebugOn(dinfo->di_btop < 0);
8719 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8720 + orig_h.inode = NULL;
8721 + if (d_is_positive(orig_h.dentry)) {
8722 + orig_h.inode = d_inode(orig_h.dentry);
8723 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8725 + if (tmp->di_btop >= 0) {
8726 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8727 + if (d_is_positive(tmp_h.dentry)) {
8728 + tmp_h.inode = d_inode(tmp_h.dentry);
8729 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8734 + if (d_really_is_positive(dentry))
8735 + inode = d_inode(dentry);
8736 + if (!orig_h.inode) {
8737 + AuDbg("nagative originally\n");
8743 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8744 + AuDebugOn(dinfo->di_bdiropq != -1);
8746 + if (!tmp_h.inode) {
8747 + AuDbg("negative --> negative\n");
8748 + /* should have only one negative lower */
8749 + if (tmp->di_btop >= 0
8750 + && tmp->di_btop < dinfo->di_btop) {
8751 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8752 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8753 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8754 + au_di_cp(dinfo, tmp);
8755 + hd = au_hdentry(tmp, tmp->di_btop);
8756 + au_set_h_dptr(dentry, tmp->di_btop,
8757 + dget(hd->hd_dentry));
8759 + au_dbg_verify_dinode(dentry);
8761 + AuDbg("negative --> positive\n");
8763 + * similar to the behaviour of creating with bypassing
8765 + * unhash it in order to force an error in the
8766 + * succeeding create operation.
8767 + * we should not set S_DEAD here.
8770 + /* au_di_swap(tmp, dinfo); */
8771 + au_dbg_verify_dinode(dentry);
8774 + AuDbg("positive originally\n");
8775 + /* inode may be NULL */
8776 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8777 + if (!tmp_h.inode) {
8778 + AuDbg("positive --> negative\n");
8779 + /* or bypassing aufs */
8781 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8782 + dinfo->di_bwh = tmp->di_bwh;
8784 + err = au_refresh_hinode_self(inode);
8785 + au_dbg_verify_dinode(dentry);
8786 + } else if (orig_h.mode == tmp_h.mode) {
8787 + AuDbg("positive --> positive, same type\n");
8788 + if (!S_ISDIR(orig_h.mode)
8789 + && dinfo->di_btop > tmp->di_btop) {
8791 + * similar to the behaviour of removing and
8796 + err = au_refresh_hinode_self(inode);
8797 + au_dbg_verify_dinode(dentry);
8799 + /* fill empty slots */
8800 + if (dinfo->di_btop > tmp->di_btop)
8801 + dinfo->di_btop = tmp->di_btop;
8802 + if (dinfo->di_bbot < tmp->di_bbot)
8803 + dinfo->di_bbot = tmp->di_bbot;
8804 + dinfo->di_bwh = tmp->di_bwh;
8805 + dinfo->di_bdiropq = tmp->di_bdiropq;
8806 + bbot = dinfo->di_bbot;
8807 + bindex = tmp->di_btop;
8808 + hd = au_hdentry(tmp, bindex);
8809 + for (; bindex <= bbot; bindex++, hd++) {
8810 + if (au_h_dptr(dentry, bindex))
8812 + h_dentry = hd->hd_dentry;
8815 + AuDebugOn(d_is_negative(h_dentry));
8816 + h_inode = d_inode(h_dentry);
8817 + AuDebugOn(orig_h.mode
8818 + != (h_inode->i_mode
8820 + au_set_h_dptr(dentry, bindex,
8824 + err = au_refresh_hinode(inode, dentry);
8825 + au_dbg_verify_dinode(dentry);
8828 + AuDbg("positive --> positive, different type\n");
8829 + /* similar to the behaviour of removing and creating */
8832 + err = au_refresh_hinode_self(inode);
8833 + au_dbg_verify_dinode(dentry);
8841 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8843 + const struct dentry_operations *dop
8844 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8845 + static const unsigned int mask
8846 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8848 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8850 + if (dentry->d_op == dop)
8853 + AuDbg("%pd\n", dentry);
8854 + spin_lock(&dentry->d_lock);
8855 + if (dop == &aufs_dop)
8856 + dentry->d_flags |= mask;
8858 + dentry->d_flags &= ~mask;
8859 + dentry->d_op = dop;
8860 + spin_unlock(&dentry->d_lock);
8863 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8865 + int err, ebrange, nbr;
8866 + unsigned int sigen;
8867 + struct au_dinfo *dinfo, *tmp;
8868 + struct super_block *sb;
8869 + struct inode *inode;
8871 + DiMustWriteLock(dentry);
8872 + AuDebugOn(IS_ROOT(dentry));
8873 + AuDebugOn(d_really_is_negative(parent));
8875 + sb = dentry->d_sb;
8876 + sigen = au_sigen(sb);
8877 + err = au_digen_test(parent, sigen);
8878 + if (unlikely(err))
8881 + nbr = au_sbbot(sb) + 1;
8882 + dinfo = au_di(dentry);
8883 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8884 + if (unlikely(err))
8886 + ebrange = au_dbrange_test(dentry);
8888 + ebrange = au_do_refresh_hdentry(dentry, parent);
8890 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8891 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8892 + if (d_really_is_positive(dentry)) {
8893 + inode = d_inode(dentry);
8894 + err = au_refresh_hinode_self(inode);
8896 + au_dbg_verify_dinode(dentry);
8898 + goto out_dgen; /* success */
8902 + /* temporary dinfo */
8903 + AuDbgDentry(dentry);
8905 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8906 + if (unlikely(!tmp))
8908 + au_di_swap(tmp, dinfo);
8909 + /* returns the number of positive dentries */
8911 + * if current working dir is removed, it returns an error.
8912 + * but the dentry is legal.
8914 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8915 + AuDbgDentry(dentry);
8916 + au_di_swap(tmp, dinfo);
8917 + if (err == -ENOENT)
8920 + /* compare/refresh by dinfo */
8921 + AuDbgDentry(dentry);
8922 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8923 + au_dbg_verify_dinode(dentry);
8926 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8927 + au_rw_write_unlock(&tmp->di_rwsem);
8929 + if (unlikely(err))
8933 + au_update_digen(dentry);
8935 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8936 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8937 + AuDbgDentry(dentry);
8943 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8944 + struct dentry *dentry, aufs_bindex_t bindex)
8949 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8952 + AuDbg("b%d\n", bindex);
8954 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8955 + * due to whiteout and branch permission.
8957 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8958 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8959 + /* it may return tri-state */
8960 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8962 + if (unlikely(valid < 0))
8972 +/* todo: remove this */
8973 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8974 + unsigned int flags, int do_udba, int dirren)
8977 + umode_t mode, h_mode;
8978 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8979 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8980 + struct inode *h_inode, *h_cached_inode;
8981 + struct dentry *h_dentry;
8982 + struct qstr *name, *h_name;
8989 + unhashed = !!d_unhashed(dentry);
8990 + is_root = !!IS_ROOT(dentry);
8991 + name = &dentry->d_name;
8992 + tmpfile = au_di(dentry)->di_tmpfile;
8995 + * Theoretically, REVAL test should be unnecessary in case of
8997 + * But {fs,i}notify doesn't fire some necessary events,
8998 + * IN_ATTRIB for atime/nlink/pageio
8999 + * Let's do REVAL test too.
9001 + if (do_udba && inode) {
9002 + mode = (inode->i_mode & S_IFMT);
9003 + plus = (inode->i_nlink > 0);
9004 + ibs = au_ibtop(inode);
9005 + ibe = au_ibbot(inode);
9008 + btop = au_dbtop(dentry);
9010 + if (inode && S_ISDIR(inode->i_mode))
9011 + btail = au_dbtaildir(dentry);
9012 + for (bindex = btop; bindex <= btail; bindex++) {
9013 + h_dentry = au_h_dptr(dentry, bindex);
9017 + AuDbg("b%d, %pd\n", bindex, h_dentry);
9018 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
9019 + spin_lock(&h_dentry->d_lock);
9020 + h_name = &h_dentry->d_name;
9021 + if (unlikely(do_udba
9024 + && (unhashed != !!d_unhashed(h_dentry)
9025 + || (!tmpfile && !dirren
9026 + && !au_qstreq(name, h_name))
9029 + && !(flags & LOOKUP_OPEN)
9030 + && (h_dentry->d_flags
9031 + & DCACHE_NFSFS_RENAMED)))
9035 + h_unhashed = d_unhashed(h_dentry);
9036 + spin_unlock(&h_dentry->d_lock);
9037 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
9038 + unhashed, h_unhashed, dentry, h_dentry);
9041 + spin_unlock(&h_dentry->d_lock);
9043 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
9044 + if (unlikely(err))
9045 + /* do not goto err, to keep the errno */
9048 + /* todo: plink too? */
9053 + if (unlikely(!!inode != d_is_positive(h_dentry)))
9057 + if (d_is_positive(h_dentry))
9058 + h_inode = d_inode(h_dentry);
9061 + h_cached_inode = h_inode;
9063 + h_mode = (h_inode->i_mode & S_IFMT);
9064 + h_plus = (h_inode->i_nlink > 0);
9066 + if (inode && ibs <= bindex && bindex <= ibe)
9067 + h_cached_inode = au_h_iptr(inode, bindex);
9070 + if (unlikely(plus != h_plus && !tmpfile))
9073 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
9075 + && !IS_ROOT(h_dentry)
9076 + && unhashed != d_unhashed(h_dentry)))
9079 + if (unlikely(mode != h_mode
9080 + || h_cached_inode != h_inode))
9093 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
9094 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
9097 + struct dentry *parent;
9099 + if (!au_digen_test(dentry, sigen))
9102 + parent = dget_parent(dentry);
9103 + di_read_lock_parent(parent, AuLock_IR);
9104 + AuDebugOn(au_digen_test(parent, sigen));
9105 + au_dbg_verify_gen(parent, sigen);
9106 + err = au_refresh_dentry(dentry, parent);
9107 + di_read_unlock(parent, AuLock_IR);
9113 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
9116 + struct dentry *d, *parent;
9118 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
9119 + return simple_reval_dpath(dentry, sigen);
9121 + /* slow loop, keep it simple and stupid */
9122 + /* cf: au_cpup_dirs() */
9125 + while (au_digen_test(dentry, sigen)) {
9129 + parent = dget_parent(d);
9130 + if (!au_digen_test(parent, sigen))
9136 + di_write_lock_child2(d);
9138 + /* someone might update our dentry while we were sleeping */
9139 + if (au_digen_test(d, sigen)) {
9141 + * todo: consolidate with simple_reval_dpath(),
9142 + * do_refresh() and au_reval_for_attr().
9144 + di_read_lock_parent(parent, AuLock_IR);
9145 + err = au_refresh_dentry(d, parent);
9146 + di_read_unlock(parent, AuLock_IR);
9150 + di_write_unlock(d);
9152 + if (unlikely(err))
9160 + * if valid returns 1, otherwise 0.
9162 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9165 + unsigned int sigen;
9166 + unsigned char do_udba, dirren;
9167 + struct super_block *sb;
9168 + struct inode *inode;
9170 + /* todo: support rcu-walk? */
9171 + if (flags & LOOKUP_RCU)
9175 + if (unlikely(!au_di(dentry)))
9179 + sb = dentry->d_sb;
9182 + * i_mutex of parent dir may be held,
9183 + * but we should not return 'invalid' due to busy.
9185 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9186 + if (unlikely(err)) {
9192 + if (d_really_is_positive(dentry))
9193 + inode = d_inode(dentry);
9194 + if (unlikely(inode && au_is_bad_inode(inode))) {
9199 + if (unlikely(au_dbrange_test(dentry))) {
9205 + sigen = au_sigen(sb);
9206 + if (au_digen_test(dentry, sigen)) {
9207 + AuDebugOn(IS_ROOT(dentry));
9208 + err = au_reval_dpath(dentry, sigen);
9209 + if (unlikely(err)) {
9214 + di_downgrade_lock(dentry, AuLock_IR);
9217 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9219 + && !(inode->i_state && I_LINKABLE)
9220 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9225 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9226 + if (do_udba && inode) {
9227 + aufs_bindex_t btop = au_ibtop(inode);
9228 + struct inode *h_inode;
9231 + h_inode = au_h_iptr(inode, btop);
9232 + if (h_inode && au_test_higen(inode, h_inode)) {
9239 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9240 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9241 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9243 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9249 + di_downgrade_lock(dentry, AuLock_IR);
9251 + aufs_read_unlock(dentry, AuLock_IR);
9256 + AuDbg("%pd invalid, %d\n", dentry, valid);
9262 +static void aufs_d_release(struct dentry *dentry)
9264 + if (au_di(dentry)) {
9265 + au_di_fin(dentry);
9266 + au_hn_di_reinit(dentry);
9270 +const struct dentry_operations aufs_dop = {
9271 + .d_revalidate = aufs_d_revalidate,
9272 + .d_weak_revalidate = aufs_d_revalidate,
9273 + .d_release = aufs_d_release
9276 +/* aufs_dop without d_revalidate */
9277 +const struct dentry_operations aufs_dop_noreval = {
9278 + .d_release = aufs_d_release
9280 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9281 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9282 +++ linux/fs/aufs/dentry.h 2018-08-12 23:43:05.453457863 +0200
9284 +/* SPDX-License-Identifier: GPL-2.0 */
9286 + * Copyright (C) 2005-2018 Junjiro R. Okajima
9288 + * This program, aufs is free software; you can redistribute it and/or modify
9289 + * it under the terms of the GNU General Public License as published by
9290 + * the Free Software Foundation; either version 2 of the License, or
9291 + * (at your option) any later version.
9293 + * This program is distributed in the hope that it will be useful,
9294 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9295 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9296 + * GNU General Public License for more details.
9298 + * You should have received a copy of the GNU General Public License
9299 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9303 + * lookup and dentry operations
9306 +#ifndef __AUFS_DENTRY_H__
9307 +#define __AUFS_DENTRY_H__
9311 +#include <linux/dcache.h>
9312 +#include "dirren.h"
9315 +struct au_hdentry {
9316 + struct dentry *hd_dentry;
9317 + aufs_bindex_t hd_id;
9321 + atomic_t di_generation;
9323 + struct au_rwsem di_rwsem;
9324 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9325 + unsigned char di_tmpfile; /* to allow the different name */
9326 + struct au_hdentry *di_hdentry;
9327 +} ____cacheline_aligned_in_smp;
9329 +/* ---------------------------------------------------------------------- */
9331 +/* flags for au_lkup_dentry() */
9332 +#define AuLkup_ALLOW_NEG 1
9333 +#define AuLkup_IGNORE_PERM (1 << 1)
9334 +#define AuLkup_DIRREN (1 << 2)
9335 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9336 +#define au_fset_lkup(flags, name) \
9337 + do { (flags) |= AuLkup_##name; } while (0)
9338 +#define au_fclr_lkup(flags, name) \
9339 + do { (flags) &= ~AuLkup_##name; } while (0)
9341 +#ifndef CONFIG_AUFS_DIRREN
9342 +#undef AuLkup_DIRREN
9343 +#define AuLkup_DIRREN 0
9346 +struct au_do_lookup_args {
9347 + unsigned int flags;
9349 + struct qstr whname, *name;
9350 + struct au_dr_lookup dirren;
9353 +/* ---------------------------------------------------------------------- */
9356 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9358 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9359 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9360 + struct dentry *h_parent, struct au_branch *br);
9362 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9363 + unsigned int flags);
9364 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9365 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9366 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9367 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9370 +void au_di_init_once(void *_di);
9371 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9372 +void au_di_free(struct au_dinfo *dinfo);
9373 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9374 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9375 +int au_di_init(struct dentry *dentry);
9376 +void au_di_fin(struct dentry *dentry);
9377 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9379 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9380 +void di_read_unlock(struct dentry *d, int flags);
9381 +void di_downgrade_lock(struct dentry *d, int flags);
9382 +void di_write_lock(struct dentry *d, unsigned int lsc);
9383 +void di_write_unlock(struct dentry *d);
9384 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9385 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9386 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9388 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9389 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9390 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9391 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9393 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9394 + struct dentry *h_dentry);
9395 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9396 +int au_dbrange_test(struct dentry *dentry);
9397 +void au_update_digen(struct dentry *dentry);
9398 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9399 +void au_update_dbtop(struct dentry *dentry);
9400 +void au_update_dbbot(struct dentry *dentry);
9401 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9403 +/* ---------------------------------------------------------------------- */
9405 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9407 + return dentry->d_fsdata;
9410 +/* ---------------------------------------------------------------------- */
9412 +/* lock subclass for dinfo */
9414 + AuLsc_DI_CHILD, /* child first */
9415 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9416 + AuLsc_DI_CHILD3, /* copyup dirs */
9420 + AuLsc_DI_TMP /* temp for replacing dinfo */
9424 + * di_read_lock_child, di_write_lock_child,
9425 + * di_read_lock_child2, di_write_lock_child2,
9426 + * di_read_lock_child3, di_write_lock_child3,
9427 + * di_read_lock_parent, di_write_lock_parent,
9428 + * di_read_lock_parent2, di_write_lock_parent2,
9429 + * di_read_lock_parent3, di_write_lock_parent3,
9431 +#define AuReadLockFunc(name, lsc) \
9432 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9433 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9435 +#define AuWriteLockFunc(name, lsc) \
9436 +static inline void di_write_lock_##name(struct dentry *d) \
9437 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9439 +#define AuRWLockFuncs(name, lsc) \
9440 + AuReadLockFunc(name, lsc) \
9441 + AuWriteLockFunc(name, lsc)
9443 +AuRWLockFuncs(child, CHILD);
9444 +AuRWLockFuncs(child2, CHILD2);
9445 +AuRWLockFuncs(child3, CHILD3);
9446 +AuRWLockFuncs(parent, PARENT);
9447 +AuRWLockFuncs(parent2, PARENT2);
9448 +AuRWLockFuncs(parent3, PARENT3);
9450 +#undef AuReadLockFunc
9451 +#undef AuWriteLockFunc
9452 +#undef AuRWLockFuncs
9454 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9455 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9456 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9458 +/* ---------------------------------------------------------------------- */
9460 +/* todo: memory barrier? */
9461 +static inline unsigned int au_digen(struct dentry *d)
9463 + return atomic_read(&au_di(d)->di_generation);
9466 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9468 + hdentry->hd_dentry = NULL;
9471 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9472 + aufs_bindex_t bindex)
9474 + return di->di_hdentry + bindex;
9477 +static inline void au_hdput(struct au_hdentry *hd)
9480 + dput(hd->hd_dentry);
9483 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9485 + DiMustAnyLock(dentry);
9486 + return au_di(dentry)->di_btop;
9489 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9491 + DiMustAnyLock(dentry);
9492 + return au_di(dentry)->di_bbot;
9495 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9497 + DiMustAnyLock(dentry);
9498 + return au_di(dentry)->di_bwh;
9501 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9503 + DiMustAnyLock(dentry);
9504 + return au_di(dentry)->di_bdiropq;
9507 +/* todo: hard/soft set? */
9508 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9510 + DiMustWriteLock(dentry);
9511 + au_di(dentry)->di_btop = bindex;
9514 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9516 + DiMustWriteLock(dentry);
9517 + au_di(dentry)->di_bbot = bindex;
9520 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9522 + DiMustWriteLock(dentry);
9523 + /* dbwh can be outside of btop - bbot range */
9524 + au_di(dentry)->di_bwh = bindex;
9527 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9529 + DiMustWriteLock(dentry);
9530 + au_di(dentry)->di_bdiropq = bindex;
9533 +/* ---------------------------------------------------------------------- */
9535 +#ifdef CONFIG_AUFS_HNOTIFY
9536 +static inline void au_digen_dec(struct dentry *d)
9538 + atomic_dec(&au_di(d)->di_generation);
9541 +static inline void au_hn_di_reinit(struct dentry *dentry)
9543 + dentry->d_fsdata = NULL;
9546 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9547 +#endif /* CONFIG_AUFS_HNOTIFY */
9549 +#endif /* __KERNEL__ */
9550 +#endif /* __AUFS_DENTRY_H__ */
9551 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9552 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9553 +++ linux/fs/aufs/dinfo.c 2018-08-12 23:43:05.453457863 +0200
9555 +// SPDX-License-Identifier: GPL-2.0
9557 + * Copyright (C) 2005-2018 Junjiro R. Okajima
9559 + * This program, aufs is free software; you can redistribute it and/or modify
9560 + * it under the terms of the GNU General Public License as published by
9561 + * the Free Software Foundation; either version 2 of the License, or
9562 + * (at your option) any later version.
9564 + * This program is distributed in the hope that it will be useful,
9565 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9566 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9567 + * GNU General Public License for more details.
9569 + * You should have received a copy of the GNU General Public License
9570 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9574 + * dentry private data
9579 +void au_di_init_once(void *_dinfo)
9581 + struct au_dinfo *dinfo = _dinfo;
9583 + au_rw_init(&dinfo->di_rwsem);
9586 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9588 + struct au_dinfo *dinfo;
9591 + dinfo = au_cache_alloc_dinfo();
9592 + if (unlikely(!dinfo))
9595 + nbr = au_sbbot(sb) + 1;
9598 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9599 + if (dinfo->di_hdentry) {
9600 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9601 + dinfo->di_btop = -1;
9602 + dinfo->di_bbot = -1;
9603 + dinfo->di_bwh = -1;
9604 + dinfo->di_bdiropq = -1;
9605 + dinfo->di_tmpfile = 0;
9606 + for (i = 0; i < nbr; i++)
9607 + dinfo->di_hdentry[i].hd_id = -1;
9611 + au_cache_free_dinfo(dinfo);
9618 +void au_di_free(struct au_dinfo *dinfo)
9620 + struct au_hdentry *p;
9621 + aufs_bindex_t bbot, bindex;
9623 + /* dentry may not be revalidated */
9624 + bindex = dinfo->di_btop;
9625 + if (bindex >= 0) {
9626 + bbot = dinfo->di_bbot;
9627 + p = au_hdentry(dinfo, bindex);
9628 + while (bindex++ <= bbot)
9631 + kfree(dinfo->di_hdentry);
9632 + au_cache_free_dinfo(dinfo);
9635 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9637 + struct au_hdentry *p;
9640 + AuRwMustWriteLock(&a->di_rwsem);
9641 + AuRwMustWriteLock(&b->di_rwsem);
9643 +#define DiSwap(v, name) \
9645 + v = a->di_##name; \
9646 + a->di_##name = b->di_##name; \
9647 + b->di_##name = v; \
9650 + DiSwap(p, hdentry);
9654 + DiSwap(bi, bdiropq);
9660 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9662 + AuRwMustWriteLock(&dst->di_rwsem);
9663 + AuRwMustWriteLock(&src->di_rwsem);
9665 + dst->di_btop = src->di_btop;
9666 + dst->di_bbot = src->di_bbot;
9667 + dst->di_bwh = src->di_bwh;
9668 + dst->di_bdiropq = src->di_bdiropq;
9672 +int au_di_init(struct dentry *dentry)
9675 + struct super_block *sb;
9676 + struct au_dinfo *dinfo;
9679 + sb = dentry->d_sb;
9680 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9682 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9683 + /* smp_mb(); */ /* atomic_set */
9684 + dentry->d_fsdata = dinfo;
9691 +void au_di_fin(struct dentry *dentry)
9693 + struct au_dinfo *dinfo;
9695 + dinfo = au_di(dentry);
9696 + AuRwDestroy(&dinfo->di_rwsem);
9697 + au_di_free(dinfo);
9700 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9703 + struct au_hdentry *hdp;
9705 + AuRwMustWriteLock(&dinfo->di_rwsem);
9708 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9710 + sz = sizeof(*hdp);
9711 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9714 + dinfo->di_hdentry = hdp;
9721 +/* ---------------------------------------------------------------------- */
9723 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9726 + case AuLsc_DI_CHILD:
9727 + ii_write_lock_child(inode);
9729 + case AuLsc_DI_CHILD2:
9730 + ii_write_lock_child2(inode);
9732 + case AuLsc_DI_CHILD3:
9733 + ii_write_lock_child3(inode);
9735 + case AuLsc_DI_PARENT:
9736 + ii_write_lock_parent(inode);
9738 + case AuLsc_DI_PARENT2:
9739 + ii_write_lock_parent2(inode);
9741 + case AuLsc_DI_PARENT3:
9742 + ii_write_lock_parent3(inode);
9749 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9752 + case AuLsc_DI_CHILD:
9753 + ii_read_lock_child(inode);
9755 + case AuLsc_DI_CHILD2:
9756 + ii_read_lock_child2(inode);
9758 + case AuLsc_DI_CHILD3:
9759 + ii_read_lock_child3(inode);
9761 + case AuLsc_DI_PARENT:
9762 + ii_read_lock_parent(inode);
9764 + case AuLsc_DI_PARENT2:
9765 + ii_read_lock_parent2(inode);
9767 + case AuLsc_DI_PARENT3:
9768 + ii_read_lock_parent3(inode);
9775 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9777 + struct inode *inode;
9779 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9780 + if (d_really_is_positive(d)) {
9781 + inode = d_inode(d);
9782 + if (au_ftest_lock(flags, IW))
9783 + do_ii_write_lock(inode, lsc);
9784 + else if (au_ftest_lock(flags, IR))
9785 + do_ii_read_lock(inode, lsc);
9789 +void di_read_unlock(struct dentry *d, int flags)
9791 + struct inode *inode;
9793 + if (d_really_is_positive(d)) {
9794 + inode = d_inode(d);
9795 + if (au_ftest_lock(flags, IW)) {
9796 + au_dbg_verify_dinode(d);
9797 + ii_write_unlock(inode);
9798 + } else if (au_ftest_lock(flags, IR)) {
9799 + au_dbg_verify_dinode(d);
9800 + ii_read_unlock(inode);
9803 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9806 +void di_downgrade_lock(struct dentry *d, int flags)
9808 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9809 + ii_downgrade_lock(d_inode(d));
9810 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9813 +void di_write_lock(struct dentry *d, unsigned int lsc)
9815 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9816 + if (d_really_is_positive(d))
9817 + do_ii_write_lock(d_inode(d), lsc);
9820 +void di_write_unlock(struct dentry *d)
9822 + au_dbg_verify_dinode(d);
9823 + if (d_really_is_positive(d))
9824 + ii_write_unlock(d_inode(d));
9825 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9828 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9830 + AuDebugOn(d1 == d2
9831 + || d_inode(d1) == d_inode(d2)
9832 + || d1->d_sb != d2->d_sb);
9834 + if ((isdir && au_test_subdir(d1, d2))
9836 + di_write_lock_child(d1);
9837 + di_write_lock_child2(d2);
9839 + di_write_lock_child(d2);
9840 + di_write_lock_child2(d1);
9844 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9846 + AuDebugOn(d1 == d2
9847 + || d_inode(d1) == d_inode(d2)
9848 + || d1->d_sb != d2->d_sb);
9850 + if ((isdir && au_test_subdir(d1, d2))
9852 + di_write_lock_parent(d1);
9853 + di_write_lock_parent2(d2);
9855 + di_write_lock_parent(d2);
9856 + di_write_lock_parent2(d1);
9860 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9862 + di_write_unlock(d1);
9863 + if (d_inode(d1) == d_inode(d2))
9864 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9866 + di_write_unlock(d2);
9869 +/* ---------------------------------------------------------------------- */
9871 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9875 + DiMustAnyLock(dentry);
9877 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9879 + AuDebugOn(bindex < 0);
9880 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9881 + AuDebugOn(d && au_dcount(d) <= 0);
9886 + * extended version of au_h_dptr().
9887 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9890 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9892 + struct dentry *h_dentry;
9893 + struct inode *inode, *h_inode;
9895 + AuDebugOn(d_really_is_negative(dentry));
9898 + if (au_dbtop(dentry) <= bindex
9899 + && bindex <= au_dbbot(dentry))
9900 + h_dentry = au_h_dptr(dentry, bindex);
9901 + if (h_dentry && !au_d_linkable(h_dentry)) {
9903 + goto out; /* success */
9906 + inode = d_inode(dentry);
9907 + AuDebugOn(bindex < au_ibtop(inode));
9908 + AuDebugOn(au_ibbot(inode) < bindex);
9909 + h_inode = au_h_iptr(inode, bindex);
9910 + h_dentry = d_find_alias(h_inode);
9912 + if (!IS_ERR(h_dentry)) {
9913 + if (!au_d_linkable(h_dentry))
9914 + goto out; /* success */
9920 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9921 + h_dentry = au_plink_lkup(inode, bindex);
9922 + AuDebugOn(!h_dentry);
9923 + if (!IS_ERR(h_dentry)) {
9924 + if (!au_d_hashed_positive(h_dentry))
9925 + goto out; /* success */
9932 + AuDbgDentry(h_dentry);
9936 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9938 + aufs_bindex_t bbot, bwh;
9940 + bbot = au_dbbot(dentry);
9942 + bwh = au_dbwh(dentry);
9945 + if (0 < bwh && bwh < bbot)
9951 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9953 + aufs_bindex_t bbot, bopq;
9955 + bbot = au_dbtail(dentry);
9957 + bopq = au_dbdiropq(dentry);
9958 + if (0 <= bopq && bopq < bbot)
9964 +/* ---------------------------------------------------------------------- */
9966 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9967 + struct dentry *h_dentry)
9969 + struct au_dinfo *dinfo;
9970 + struct au_hdentry *hd;
9971 + struct au_branch *br;
9973 + DiMustWriteLock(dentry);
9975 + dinfo = au_di(dentry);
9976 + hd = au_hdentry(dinfo, bindex);
9978 + hd->hd_dentry = h_dentry;
9980 + br = au_sbr(dentry->d_sb, bindex);
9981 + hd->hd_id = br->br_id;
9985 +int au_dbrange_test(struct dentry *dentry)
9988 + aufs_bindex_t btop, bbot;
9991 + btop = au_dbtop(dentry);
9992 + bbot = au_dbbot(dentry);
9994 + AuDebugOn(bbot < 0 && btop > bbot);
9997 + AuDebugOn(bbot >= 0);
10003 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
10008 + if (unlikely(au_digen(dentry) != sigen
10009 + || au_iigen_test(d_inode(dentry), sigen)))
10015 +void au_update_digen(struct dentry *dentry)
10017 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
10018 + /* smp_mb(); */ /* atomic_set */
10021 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
10023 + struct au_dinfo *dinfo;
10024 + struct dentry *h_d;
10025 + struct au_hdentry *hdp;
10026 + aufs_bindex_t bindex, bbot;
10028 + DiMustWriteLock(dentry);
10030 + dinfo = au_di(dentry);
10031 + if (!dinfo || dinfo->di_btop < 0)
10034 + if (do_put_zero) {
10035 + bbot = dinfo->di_bbot;
10036 + bindex = dinfo->di_btop;
10037 + hdp = au_hdentry(dinfo, bindex);
10038 + for (; bindex <= bbot; bindex++, hdp++) {
10039 + h_d = hdp->hd_dentry;
10040 + if (h_d && d_is_negative(h_d))
10041 + au_set_h_dptr(dentry, bindex, NULL);
10045 + dinfo->di_btop = 0;
10046 + hdp = au_hdentry(dinfo, dinfo->di_btop);
10047 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
10048 + if (hdp->hd_dentry)
10050 + if (dinfo->di_btop > dinfo->di_bbot) {
10051 + dinfo->di_btop = -1;
10052 + dinfo->di_bbot = -1;
10056 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
10057 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
10058 + if (hdp->hd_dentry)
10060 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
10063 +void au_update_dbtop(struct dentry *dentry)
10065 + aufs_bindex_t bindex, bbot;
10066 + struct dentry *h_dentry;
10068 + bbot = au_dbbot(dentry);
10069 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
10070 + h_dentry = au_h_dptr(dentry, bindex);
10073 + if (d_is_positive(h_dentry)) {
10074 + au_set_dbtop(dentry, bindex);
10077 + au_set_h_dptr(dentry, bindex, NULL);
10081 +void au_update_dbbot(struct dentry *dentry)
10083 + aufs_bindex_t bindex, btop;
10084 + struct dentry *h_dentry;
10086 + btop = au_dbtop(dentry);
10087 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
10088 + h_dentry = au_h_dptr(dentry, bindex);
10091 + if (d_is_positive(h_dentry)) {
10092 + au_set_dbbot(dentry, bindex);
10095 + au_set_h_dptr(dentry, bindex, NULL);
10099 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
10101 + aufs_bindex_t bindex, bbot;
10103 + bbot = au_dbbot(dentry);
10104 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
10105 + if (au_h_dptr(dentry, bindex) == h_dentry)
10109 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
10110 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
10111 +++ linux/fs/aufs/dir.c 2018-08-12 23:43:05.453457863 +0200
10113 +// SPDX-License-Identifier: GPL-2.0
10115 + * Copyright (C) 2005-2018 Junjiro R. Okajima
10117 + * This program, aufs is free software; you can redistribute it and/or modify
10118 + * it under the terms of the GNU General Public License as published by
10119 + * the Free Software Foundation; either version 2 of the License, or
10120 + * (at your option) any later version.
10122 + * This program is distributed in the hope that it will be useful,
10123 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10124 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10125 + * GNU General Public License for more details.
10127 + * You should have received a copy of the GNU General Public License
10128 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10132 + * directory operations
10135 +#include <linux/fs_stack.h>
10138 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10140 + unsigned int nlink;
10142 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10144 + nlink = dir->i_nlink;
10145 + nlink += h_dir->i_nlink - 2;
10146 + if (h_dir->i_nlink < 2)
10148 + smp_mb(); /* for i_nlink */
10149 + /* 0 can happen in revaliding */
10150 + set_nlink(dir, nlink);
10153 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10155 + unsigned int nlink;
10157 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10159 + nlink = dir->i_nlink;
10160 + nlink -= h_dir->i_nlink - 2;
10161 + if (h_dir->i_nlink < 2)
10163 + smp_mb(); /* for i_nlink */
10164 + /* nlink == 0 means the branch-fs is broken */
10165 + set_nlink(dir, nlink);
10168 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10171 + aufs_bindex_t bindex, bbot;
10172 + struct file *h_file;
10173 + struct dentry *h_dentry;
10177 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10179 + bbot = au_fbbot_dir(file);
10180 + for (bindex = au_fbtop(file);
10181 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10183 + h_file = au_hf_dir(file, bindex);
10184 + if (h_file && file_inode(h_file))
10185 + sz += vfsub_f_size_read(h_file);
10188 + AuDebugOn(!dentry);
10189 + AuDebugOn(!d_is_dir(dentry));
10191 + bbot = au_dbtaildir(dentry);
10192 + for (bindex = au_dbtop(dentry);
10193 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10195 + h_dentry = au_h_dptr(dentry, bindex);
10196 + if (h_dentry && d_is_positive(h_dentry))
10197 + sz += i_size_read(d_inode(h_dentry));
10200 + if (sz < KMALLOC_MAX_SIZE)
10201 + sz = roundup_pow_of_two(sz);
10202 + if (sz > KMALLOC_MAX_SIZE)
10203 + sz = KMALLOC_MAX_SIZE;
10204 + else if (sz < NAME_MAX) {
10205 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10206 + sz = AUFS_RDBLK_DEF;
10211 +struct au_dir_ts_arg {
10212 + struct dentry *dentry;
10213 + aufs_bindex_t brid;
10216 +static void au_do_dir_ts(void *arg)
10218 + struct au_dir_ts_arg *a = arg;
10219 + struct au_dtime dt;
10220 + struct path h_path;
10221 + struct inode *dir, *h_dir;
10222 + struct super_block *sb;
10223 + struct au_branch *br;
10224 + struct au_hinode *hdir;
10226 + aufs_bindex_t btop, bindex;
10228 + sb = a->dentry->d_sb;
10229 + if (d_really_is_negative(a->dentry))
10231 + /* no dir->i_mutex lock */
10232 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10234 + dir = d_inode(a->dentry);
10235 + btop = au_ibtop(dir);
10236 + bindex = au_br_index(sb, a->brid);
10237 + if (bindex < btop)
10240 + br = au_sbr(sb, bindex);
10241 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10242 + if (!h_path.dentry)
10244 + h_path.mnt = au_br_mnt(br);
10245 + au_dtime_store(&dt, a->dentry, &h_path);
10247 + br = au_sbr(sb, btop);
10248 + if (!au_br_writable(br->br_perm))
10250 + h_path.dentry = au_h_dptr(a->dentry, btop);
10251 + h_path.mnt = au_br_mnt(br);
10252 + err = vfsub_mnt_want_write(h_path.mnt);
10255 + hdir = au_hi(dir, btop);
10256 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10257 + h_dir = au_h_iptr(dir, btop);
10258 + if (h_dir->i_nlink
10259 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10260 + dt.dt_h_path = h_path;
10261 + au_dtime_revert(&dt);
10263 + au_hn_inode_unlock(hdir);
10264 + vfsub_mnt_drop_write(h_path.mnt);
10265 + au_cpup_attr_timesizes(dir);
10268 + aufs_read_unlock(a->dentry, AuLock_DW);
10271 + au_nwt_done(&au_sbi(sb)->si_nowait);
10275 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10277 + int perm, wkq_err;
10278 + aufs_bindex_t btop;
10279 + struct au_dir_ts_arg *arg;
10280 + struct dentry *dentry;
10281 + struct super_block *sb;
10285 + dentry = d_find_any_alias(dir);
10286 + AuDebugOn(!dentry);
10287 + sb = dentry->d_sb;
10288 + btop = au_ibtop(dir);
10289 + if (btop == bindex) {
10290 + au_cpup_attr_timesizes(dir);
10294 + perm = au_sbr_perm(sb, btop);
10295 + if (!au_br_writable(perm))
10298 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10302 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10303 + arg->brid = au_sbr_id(sb, bindex);
10304 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10305 + if (unlikely(wkq_err)) {
10306 + pr_err("wkq %d\n", wkq_err);
10315 +/* ---------------------------------------------------------------------- */
10317 +static int reopen_dir(struct file *file)
10320 + unsigned int flags;
10321 + aufs_bindex_t bindex, btail, btop;
10322 + struct dentry *dentry, *h_dentry;
10323 + struct file *h_file;
10325 + /* open all lower dirs */
10326 + dentry = file->f_path.dentry;
10327 + btop = au_dbtop(dentry);
10328 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10329 + au_set_h_fptr(file, bindex, NULL);
10330 + au_set_fbtop(file, btop);
10332 + btail = au_dbtaildir(dentry);
10333 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10334 + au_set_h_fptr(file, bindex, NULL);
10335 + au_set_fbbot_dir(file, btail);
10337 + flags = vfsub_file_flags(file);
10338 + for (bindex = btop; bindex <= btail; bindex++) {
10339 + h_dentry = au_h_dptr(dentry, bindex);
10342 + h_file = au_hf_dir(file, bindex);
10346 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10347 + err = PTR_ERR(h_file);
10348 + if (IS_ERR(h_file))
10349 + goto out; /* close all? */
10350 + au_set_h_fptr(file, bindex, h_file);
10352 + au_update_figen(file);
10353 + /* todo: necessary? */
10354 + /* file->f_ra = h_file->f_ra; */
10361 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10364 + aufs_bindex_t bindex, btail;
10365 + struct dentry *dentry, *h_dentry;
10366 + struct vfsmount *mnt;
10368 + FiMustWriteLock(file);
10369 + AuDebugOn(h_file);
10372 + mnt = file->f_path.mnt;
10373 + dentry = file->f_path.dentry;
10374 + file->f_version = inode_query_iversion(d_inode(dentry));
10375 + bindex = au_dbtop(dentry);
10376 + au_set_fbtop(file, bindex);
10377 + btail = au_dbtaildir(dentry);
10378 + au_set_fbbot_dir(file, btail);
10379 + for (; !err && bindex <= btail; bindex++) {
10380 + h_dentry = au_h_dptr(dentry, bindex);
10384 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10385 + if (unlikely(err))
10387 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10388 + if (IS_ERR(h_file)) {
10389 + err = PTR_ERR(h_file);
10392 + au_set_h_fptr(file, bindex, h_file);
10394 + au_update_figen(file);
10395 + /* todo: necessary? */
10396 + /* file->f_ra = h_file->f_ra; */
10398 + return 0; /* success */
10401 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10402 + au_set_h_fptr(file, bindex, NULL);
10403 + au_set_fbtop(file, -1);
10404 + au_set_fbbot_dir(file, -1);
10409 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10410 + struct file *file)
10413 + struct super_block *sb;
10414 + struct au_fidir *fidir;
10417 + sb = file->f_path.dentry->d_sb;
10418 + si_read_lock(sb, AuLock_FLUSH);
10419 + fidir = au_fidir_alloc(sb);
10421 + struct au_do_open_args args = {
10422 + .open = do_open_dir,
10425 + err = au_do_open(file, &args);
10426 + if (unlikely(err))
10429 + si_read_unlock(sb);
10433 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10434 + struct file *file)
10436 + struct au_vdir *vdir_cache;
10437 + struct au_finfo *finfo;
10438 + struct au_fidir *fidir;
10439 + struct au_hfile *hf;
10440 + aufs_bindex_t bindex, bbot;
10442 + finfo = au_fi(file);
10443 + fidir = finfo->fi_hdir;
10445 + au_hbl_del(&finfo->fi_hlist,
10446 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10447 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10449 + au_vdir_free(vdir_cache);
10451 + bindex = finfo->fi_btop;
10452 + if (bindex >= 0) {
10453 + hf = fidir->fd_hfile + bindex;
10455 + * calls fput() instead of filp_close(),
10456 + * since no dnotify or lock for the lower file.
10458 + bbot = fidir->fd_bbot;
10459 + for (; bindex <= bbot; bindex++, hf++)
10461 + au_hfput(hf, /*execed*/0);
10464 + finfo->fi_hdir = NULL;
10466 + au_finfo_fin(file);
10470 +/* ---------------------------------------------------------------------- */
10472 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10475 + aufs_bindex_t bindex, bbot;
10476 + struct file *h_file;
10479 + bbot = au_fbbot_dir(file);
10480 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10481 + h_file = au_hf_dir(file, bindex);
10483 + err = vfsub_flush(h_file, id);
10488 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10490 + return au_do_flush(file, id, au_do_flush_dir);
10493 +/* ---------------------------------------------------------------------- */
10495 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10498 + aufs_bindex_t bbot, bindex;
10499 + struct inode *inode;
10500 + struct super_block *sb;
10503 + sb = dentry->d_sb;
10504 + inode = d_inode(dentry);
10505 + IMustLock(inode);
10506 + bbot = au_dbbot(dentry);
10507 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10508 + struct path h_path;
10510 + if (au_test_ro(sb, bindex, inode))
10512 + h_path.dentry = au_h_dptr(dentry, bindex);
10513 + if (!h_path.dentry)
10516 + h_path.mnt = au_sbr_mnt(sb, bindex);
10517 + err = vfsub_fsync(NULL, &h_path, datasync);
10523 +static int au_do_fsync_dir(struct file *file, int datasync)
10526 + aufs_bindex_t bbot, bindex;
10527 + struct file *h_file;
10528 + struct super_block *sb;
10529 + struct inode *inode;
10531 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10532 + if (unlikely(err))
10535 + inode = file_inode(file);
10536 + sb = inode->i_sb;
10537 + bbot = au_fbbot_dir(file);
10538 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10539 + h_file = au_hf_dir(file, bindex);
10540 + if (!h_file || au_test_ro(sb, bindex, inode))
10543 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10551 + * @file may be NULL
10553 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10557 + struct dentry *dentry;
10558 + struct inode *inode;
10559 + struct super_block *sb;
10562 + dentry = file->f_path.dentry;
10563 + inode = d_inode(dentry);
10564 + inode_lock(inode);
10565 + sb = dentry->d_sb;
10566 + si_noflush_read_lock(sb);
10568 + err = au_do_fsync_dir(file, datasync);
10570 + di_write_lock_child(dentry);
10571 + err = au_do_fsync_dir_no_file(dentry, datasync);
10573 + au_cpup_attr_timesizes(inode);
10574 + di_write_unlock(dentry);
10576 + fi_write_unlock(file);
10578 + si_read_unlock(sb);
10579 + inode_unlock(inode);
10583 +/* ---------------------------------------------------------------------- */
10585 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10588 + struct dentry *dentry;
10589 + struct inode *inode, *h_inode;
10590 + struct super_block *sb;
10592 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10594 + dentry = file->f_path.dentry;
10595 + inode = d_inode(dentry);
10596 + IMustLock(inode);
10598 + sb = dentry->d_sb;
10599 + si_read_lock(sb, AuLock_FLUSH);
10600 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10601 + if (unlikely(err))
10603 + err = au_alive_dir(dentry);
10605 + err = au_vdir_init(file);
10606 + di_downgrade_lock(dentry, AuLock_IR);
10607 + if (unlikely(err))
10610 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10611 + if (!au_test_nfsd()) {
10612 + err = au_vdir_fill_de(file, ctx);
10613 + fsstack_copy_attr_atime(inode, h_inode);
10616 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10617 + * encode_fh() and others.
10619 + atomic_inc(&h_inode->i_count);
10620 + di_read_unlock(dentry, AuLock_IR);
10621 + si_read_unlock(sb);
10622 + err = au_vdir_fill_de(file, ctx);
10623 + fsstack_copy_attr_atime(inode, h_inode);
10624 + fi_write_unlock(file);
10632 + di_read_unlock(dentry, AuLock_IR);
10633 + fi_write_unlock(file);
10635 + si_read_unlock(sb);
10639 +/* ---------------------------------------------------------------------- */
10641 +#define AuTestEmpty_WHONLY 1
10642 +#define AuTestEmpty_CALLED (1 << 1)
10643 +#define AuTestEmpty_SHWH (1 << 2)
10644 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10645 +#define au_fset_testempty(flags, name) \
10646 + do { (flags) |= AuTestEmpty_##name; } while (0)
10647 +#define au_fclr_testempty(flags, name) \
10648 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10650 +#ifndef CONFIG_AUFS_SHWH
10651 +#undef AuTestEmpty_SHWH
10652 +#define AuTestEmpty_SHWH 0
10655 +struct test_empty_arg {
10656 + struct dir_context ctx;
10657 + struct au_nhash *whlist;
10658 + unsigned int flags;
10660 + aufs_bindex_t bindex;
10663 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10664 + int namelen, loff_t offset __maybe_unused, u64 ino,
10665 + unsigned int d_type)
10667 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10669 + char *name = (void *)__name;
10672 + au_fset_testempty(arg->flags, CALLED);
10674 + if (name[0] == '.'
10675 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10676 + goto out; /* success */
10678 + if (namelen <= AUFS_WH_PFX_LEN
10679 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10680 + if (au_ftest_testempty(arg->flags, WHONLY)
10681 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10682 + arg->err = -ENOTEMPTY;
10686 + name += AUFS_WH_PFX_LEN;
10687 + namelen -= AUFS_WH_PFX_LEN;
10688 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10689 + arg->err = au_nhash_append_wh
10690 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10691 + au_ftest_testempty(arg->flags, SHWH));
10695 + AuTraceErr(arg->err);
10699 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10702 + struct file *h_file;
10704 + h_file = au_h_open(dentry, arg->bindex,
10705 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10706 + /*file*/NULL, /*force_wr*/0);
10707 + err = PTR_ERR(h_file);
10708 + if (IS_ERR(h_file))
10712 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10713 + && !file_inode(h_file)->i_nlink)
10718 + au_fclr_testempty(arg->flags, CALLED);
10720 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10723 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10727 + au_sbr_put(dentry->d_sb, arg->bindex);
10732 +struct do_test_empty_args {
10734 + struct dentry *dentry;
10735 + struct test_empty_arg *arg;
10738 +static void call_do_test_empty(void *args)
10740 + struct do_test_empty_args *a = args;
10741 + *a->errp = do_test_empty(a->dentry, a->arg);
10744 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10746 + int err, wkq_err;
10747 + struct dentry *h_dentry;
10748 + struct inode *h_inode;
10750 + h_dentry = au_h_dptr(dentry, arg->bindex);
10751 + h_inode = d_inode(h_dentry);
10752 + /* todo: i_mode changes anytime? */
10753 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10754 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10755 + inode_unlock_shared(h_inode);
10757 + err = do_test_empty(dentry, arg);
10759 + struct do_test_empty_args args = {
10761 + .dentry = dentry,
10764 + unsigned int flags = arg->flags;
10766 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10767 + if (unlikely(wkq_err))
10769 + arg->flags = flags;
10775 +int au_test_empty_lower(struct dentry *dentry)
10778 + unsigned int rdhash;
10779 + aufs_bindex_t bindex, btop, btail;
10780 + struct au_nhash whlist;
10781 + struct test_empty_arg arg = {
10783 + .actor = test_empty_cb
10786 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10788 + SiMustAnyLock(dentry->d_sb);
10790 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10792 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10793 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10794 + if (unlikely(err))
10798 + arg.whlist = &whlist;
10799 + btop = au_dbtop(dentry);
10800 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10801 + au_fset_testempty(arg.flags, SHWH);
10802 + test_empty = do_test_empty;
10803 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10804 + test_empty = sio_test_empty;
10805 + arg.bindex = btop;
10806 + err = test_empty(dentry, &arg);
10807 + if (unlikely(err))
10810 + au_fset_testempty(arg.flags, WHONLY);
10811 + btail = au_dbtaildir(dentry);
10812 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10813 + struct dentry *h_dentry;
10815 + h_dentry = au_h_dptr(dentry, bindex);
10816 + if (h_dentry && d_is_positive(h_dentry)) {
10817 + arg.bindex = bindex;
10818 + err = test_empty(dentry, &arg);
10823 + au_nhash_wh_free(&whlist);
10828 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10831 + struct test_empty_arg arg = {
10833 + .actor = test_empty_cb
10836 + aufs_bindex_t bindex, btail;
10839 + arg.whlist = whlist;
10840 + arg.flags = AuTestEmpty_WHONLY;
10841 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10842 + au_fset_testempty(arg.flags, SHWH);
10843 + btail = au_dbtaildir(dentry);
10844 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10845 + struct dentry *h_dentry;
10847 + h_dentry = au_h_dptr(dentry, bindex);
10848 + if (h_dentry && d_is_positive(h_dentry)) {
10849 + arg.bindex = bindex;
10850 + err = sio_test_empty(dentry, &arg);
10857 +/* ---------------------------------------------------------------------- */
10859 +const struct file_operations aufs_dir_fop = {
10860 + .owner = THIS_MODULE,
10861 + .llseek = default_llseek,
10862 + .read = generic_read_dir,
10863 + .iterate_shared = aufs_iterate_shared,
10864 + .unlocked_ioctl = aufs_ioctl_dir,
10865 +#ifdef CONFIG_COMPAT
10866 + .compat_ioctl = aufs_compat_ioctl_dir,
10868 + .open = aufs_open_dir,
10869 + .release = aufs_release_dir,
10870 + .flush = aufs_flush_dir,
10871 + .fsync = aufs_fsync_dir
10873 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10874 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10875 +++ linux/fs/aufs/dir.h 2018-08-12 23:43:05.453457863 +0200
10877 +/* SPDX-License-Identifier: GPL-2.0 */
10879 + * Copyright (C) 2005-2018 Junjiro R. Okajima
10881 + * This program, aufs is free software; you can redistribute it and/or modify
10882 + * it under the terms of the GNU General Public License as published by
10883 + * the Free Software Foundation; either version 2 of the License, or
10884 + * (at your option) any later version.
10886 + * This program is distributed in the hope that it will be useful,
10887 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10888 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10889 + * GNU General Public License for more details.
10891 + * You should have received a copy of the GNU General Public License
10892 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10896 + * directory operations
10899 +#ifndef __AUFS_DIR_H__
10900 +#define __AUFS_DIR_H__
10904 +#include <linux/fs.h>
10906 +/* ---------------------------------------------------------------------- */
10908 +/* need to be faster and smaller */
10911 + unsigned int nh_num;
10912 + struct hlist_head *nh_head;
10915 +struct au_vdir_destr {
10916 + unsigned char len;
10917 + unsigned char name[0];
10920 +struct au_vdir_dehstr {
10921 + struct hlist_node hash;
10922 + struct au_vdir_destr *str;
10923 +} ____cacheline_aligned_in_smp;
10925 +struct au_vdir_de {
10927 + unsigned char de_type;
10928 + /* caution: packed */
10929 + struct au_vdir_destr de_str;
10932 +struct au_vdir_wh {
10933 + struct hlist_node wh_hash;
10934 +#ifdef CONFIG_AUFS_SHWH
10936 + aufs_bindex_t wh_bindex;
10937 + unsigned char wh_type;
10939 + aufs_bindex_t wh_bindex;
10941 + /* caution: packed */
10942 + struct au_vdir_destr wh_str;
10945 +union au_vdir_deblk_p {
10946 + unsigned char *deblk;
10947 + struct au_vdir_de *de;
10951 + unsigned char **vd_deblk;
10952 + unsigned long vd_nblk;
10954 + unsigned long ul;
10955 + union au_vdir_deblk_p p;
10959 + unsigned int vd_deblk_sz;
10960 + unsigned long vd_jiffy;
10961 +} ____cacheline_aligned_in_smp;
10963 +/* ---------------------------------------------------------------------- */
10966 +extern const struct file_operations aufs_dir_fop;
10967 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10968 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10969 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10970 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10971 +int au_test_empty_lower(struct dentry *dentry);
10972 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10975 +unsigned int au_rdhash_est(loff_t sz);
10976 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10977 +void au_nhash_wh_free(struct au_nhash *whlist);
10978 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10980 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10981 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10982 + unsigned int d_type, aufs_bindex_t bindex,
10983 + unsigned char shwh);
10984 +void au_vdir_free(struct au_vdir *vdir);
10985 +int au_vdir_init(struct file *file);
10986 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10989 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10991 +#ifdef CONFIG_AUFS_RDU
10993 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10994 +#ifdef CONFIG_COMPAT
10995 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10996 + unsigned long arg);
10999 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
11000 + unsigned int cmd, unsigned long arg)
11001 +#ifdef CONFIG_COMPAT
11002 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
11003 + unsigned int cmd, unsigned long arg)
11007 +#endif /* __KERNEL__ */
11008 +#endif /* __AUFS_DIR_H__ */
11009 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
11010 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
11011 +++ linux/fs/aufs/dirren.c 2018-08-12 23:43:05.453457863 +0200
11013 +// SPDX-License-Identifier: GPL-2.0
11015 + * Copyright (C) 2017-2018 Junjiro R. Okajima
11017 + * This program, aufs is free software; you can redistribute it and/or modify
11018 + * it under the terms of the GNU General Public License as published by
11019 + * the Free Software Foundation; either version 2 of the License, or
11020 + * (at your option) any later version.
11022 + * This program is distributed in the hope that it will be useful,
11023 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11024 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11025 + * GNU General Public License for more details.
11027 + * You should have received a copy of the GNU General Public License
11028 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11032 + * special handling in renaming a directoy
11033 + * in order to support looking-up the before-renamed name on the lower readonly
11037 +#include <linux/byteorder/generic.h>
11040 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
11044 + idx = au_dr_ihash(ent->dr_h_ino);
11045 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
11048 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
11051 + struct hlist_bl_head *hbl;
11054 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
11055 + hbl = dr->dr_h_ino + i;
11056 + hlist_bl_lock(hbl);
11057 + ret &= hlist_bl_empty(hbl);
11058 + hlist_bl_unlock(hbl);
11064 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
11066 + struct au_dr_hino *found, *ent;
11067 + struct hlist_bl_head *hbl;
11068 + struct hlist_bl_node *pos;
11072 + idx = au_dr_ihash(ino);
11073 + hbl = dr->dr_h_ino + idx;
11074 + hlist_bl_lock(hbl);
11075 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11076 + if (ent->dr_h_ino == ino) {
11080 + hlist_bl_unlock(hbl);
11085 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
11086 + struct au_dr_hino *add_ent)
11089 + struct hlist_bl_head *hbl;
11090 + struct hlist_bl_node *pos;
11091 + struct au_dr_hino *ent;
11094 + idx = au_dr_ihash(ino);
11095 + hbl = dr->dr_h_ino + idx;
11098 + struct hlist_bl_node *tmp;
11100 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11101 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
11104 + hlist_bl_lock(hbl);
11105 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11106 + if (ent->dr_h_ino == ino) {
11110 + if (!found && add_ent)
11111 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
11112 + hlist_bl_unlock(hbl);
11114 + if (!found && add_ent)
11115 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
11120 +void au_dr_hino_free(struct au_dr_br *dr)
11123 + struct hlist_bl_head *hbl;
11124 + struct hlist_bl_node *pos, *tmp;
11125 + struct au_dr_hino *ent;
11127 + /* SiMustWriteLock(sb); */
11129 + for (i = 0; i < AuDirren_NHASH; i++) {
11130 + hbl = dr->dr_h_ino + i;
11131 + /* no spinlock since sbinfo must be write-locked */
11132 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11134 + INIT_HLIST_BL_HEAD(hbl);
11138 +/* returns the number of inodes or an error */
11139 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11140 + struct file *hinofile)
11144 + loff_t pos, oldsize;
11146 + struct inode *hinoinode;
11147 + struct hlist_bl_head *hbl;
11148 + struct hlist_bl_node *n1, *n2;
11149 + struct au_dr_hino *ent;
11151 + SiMustWriteLock(sb);
11152 + AuDebugOn(!au_br_writable(br->br_perm));
11154 + hinoinode = file_inode(hinofile);
11155 + oldsize = i_size_read(hinoinode);
11159 + hbl = br->br_dirren.dr_h_ino;
11160 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11161 + /* no bit-lock since sbinfo must be write-locked */
11162 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11163 + AuDbg("hi%llu, %pD2\n",
11164 + (unsigned long long)ent->dr_h_ino, hinofile);
11165 + u64 = cpu_to_be64(ent->dr_h_ino);
11166 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11167 + if (ssz == sizeof(u64))
11170 + /* write error */
11171 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11178 + /* regardless the error */
11179 + if (pos < oldsize) {
11180 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11188 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11195 + struct au_dr_hino *ent;
11196 + struct inode *hinoinode;
11197 + struct hlist_bl_head *hbl;
11201 + hbl = dr->dr_h_ino;
11202 + hinoinode = file_inode(hinofile);
11203 + sz = i_size_read(hinoinode);
11204 + AuDebugOn(sz % sizeof(u64));
11205 + n = sz / sizeof(u64);
11207 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11208 + if (unlikely(ssz != sizeof(u64))) {
11209 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11216 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11222 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11223 + AuDbg("hi%llu, %pD2\n",
11224 + (unsigned long long)ent->dr_h_ino, hinofile);
11225 + hidx = au_dr_ihash(ent->dr_h_ino);
11226 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11228 + goto out; /* success */
11231 + au_dr_hino_free(dr);
11238 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11239 + * @path is a switch to distinguish load and store.
11241 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11242 + struct au_branch *br, const struct path *path)
11245 + unsigned char load, suspend;
11246 + struct file *hinofile;
11247 + struct au_hinode *hdir;
11248 + struct inode *dir, *delegated;
11249 + struct path hinopath;
11250 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11251 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11253 + AuDebugOn(bindex < 0 && !br);
11254 + AuDebugOn(bindex >= 0 && br);
11259 + br = au_sbr(sb, bindex);
11262 + path = &br->br_path;
11263 + AuDebugOn(!au_br_writable(br->br_perm));
11264 + if (unlikely(!au_br_writable(br->br_perm)))
11270 + dir = d_inode(sb->s_root);
11271 + hdir = au_hinode(au_ii(dir), bindex);
11272 + dir = hdir->hi_inode;
11273 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11275 + dir = d_inode(path->dentry);
11276 + inode_lock_nested(dir, AuLsc_I_CHILD);
11278 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11279 + err = PTR_ERR(hinopath.dentry);
11280 + if (IS_ERR(hinopath.dentry))
11284 + flags = O_RDONLY;
11286 + if (d_is_negative(hinopath.dentry))
11287 + goto out_dput; /* success */
11289 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11290 + if (d_is_positive(hinopath.dentry)) {
11291 + delegated = NULL;
11292 + err = vfsub_unlink(dir, &hinopath, &delegated,
11295 + if (unlikely(err))
11296 + pr_err("ignored err %d, %pd2\n",
11297 + err, hinopath.dentry);
11298 + if (unlikely(err == -EWOULDBLOCK))
11303 + } else if (!d_is_positive(hinopath.dentry)) {
11304 + err = vfsub_create(dir, &hinopath, 0600,
11305 + /*want_excl*/false);
11307 + if (unlikely(err))
11310 + flags = O_WRONLY;
11312 + hinopath.mnt = path->mnt;
11313 + hinofile = vfsub_dentry_open(&hinopath, flags);
11315 + au_hn_inode_unlock(hdir);
11317 + inode_unlock(dir);
11318 + dput(hinopath.dentry);
11319 + AuTraceErrPtr(hinofile);
11320 + if (IS_ERR(hinofile)) {
11321 + err = PTR_ERR(hinofile);
11326 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11328 + err = au_dr_hino_store(sb, br, hinofile);
11333 + dput(hinopath.dentry);
11336 + au_hn_inode_unlock(hdir);
11338 + inode_unlock(dir);
11344 +/* ---------------------------------------------------------------------- */
11346 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11349 + struct kstatfs kstfs;
11351 + struct dentry *dentry;
11352 + struct super_block *sb;
11354 + err = vfs_statfs((void *)path, &kstfs);
11356 + if (unlikely(err))
11359 + /* todo: support for UUID */
11361 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11362 + brid->type = AuBrid_FSID;
11363 + brid->fsid = kstfs.f_fsid;
11365 + dentry = path->dentry;
11366 + sb = dentry->d_sb;
11369 + brid->type = AuBrid_DEV;
11378 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11379 + const struct path *path)
11382 + struct au_dr_br *dr;
11383 + struct hlist_bl_head *hbl;
11385 + dr = &br->br_dirren;
11386 + hbl = dr->dr_h_ino;
11387 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11388 + INIT_HLIST_BL_HEAD(hbl);
11390 + err = au_dr_brid_init(&dr->dr_brid, path);
11391 + if (unlikely(err))
11394 + if (au_opt_test(au_mntflags(sb), DIRREN))
11395 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11402 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11407 + if (au_br_writable(br->br_perm))
11408 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11410 + au_dr_hino_free(&br->br_dirren);
11415 +/* ---------------------------------------------------------------------- */
11417 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11418 + char *buf, size_t sz)
11421 + unsigned int major, minor;
11425 + err = snprintf(p, sz, "%d_", brid->type);
11426 + AuDebugOn(err > sz);
11429 + switch (brid->type) {
11430 + case AuBrid_Unset:
11432 + case AuBrid_UUID:
11433 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11435 + case AuBrid_FSID:
11436 + err = snprintf(p, sz, "%08x-%08x",
11437 + brid->fsid.val[0], brid->fsid.val[1]);
11440 + major = MAJOR(brid->dev);
11441 + minor = MINOR(brid->dev);
11442 + if (major <= 0xff && minor <= 0xff)
11443 + err = snprintf(p, sz, "%02x%02x", major, minor);
11445 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11448 + AuDebugOn(err > sz);
11451 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11452 + AuDebugOn(err > sz);
11459 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11462 + struct dentry *br_dentry;
11463 + struct inode *br_inode;
11465 + br_dentry = au_br_dentry(br);
11466 + br_inode = d_inode(br_dentry);
11467 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11468 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11469 + AuDebugOn(rlen > len);
11474 +/* ---------------------------------------------------------------------- */
11477 + * from the given @h_dentry, construct drinfo at @*fdata.
11478 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11481 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11482 + struct dentry *h_dentry,
11483 + unsigned char *allocated)
11486 + struct au_drinfo_fdata *f, *p;
11487 + struct au_drinfo *drinfo;
11488 + struct inode *h_inode;
11489 + struct qstr *qname;
11493 + h_inode = d_inode(h_dentry);
11494 + qname = &h_dentry->d_name;
11495 + drinfo = &f->drinfo;
11496 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11497 + drinfo->oldnamelen = qname->len;
11498 + if (*allocated < sizeof(*f) + qname->len) {
11499 + v = roundup_pow_of_two(*allocated + qname->len);
11500 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11501 + if (unlikely(!p)) {
11509 + drinfo = &f->drinfo;
11511 + memcpy(drinfo->oldname, qname->name, qname->len);
11512 + AuDbg("i%llu, %.*s\n",
11513 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11514 + drinfo->oldname);
11521 +/* callers have to free the return value */
11522 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11524 + struct au_drinfo *ret, *drinfo;
11525 + struct au_drinfo_fdata fdata;
11530 + ret = ERR_PTR(-EIO);
11532 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11533 + if (unlikely(ssz != sizeof(fdata))) {
11534 + AuIOErr("ssz %zd, %u, %pD2\n",
11535 + ssz, (unsigned int)sizeof(fdata), file);
11539 + fdata.magic = ntohl((__force __be32)fdata.magic);
11540 + switch (fdata.magic) {
11541 + case AUFS_DRINFO_MAGIC_V1:
11544 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11545 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11549 + drinfo = &fdata.drinfo;
11550 + len = drinfo->oldnamelen;
11552 + AuIOErr("broken drinfo %pD2\n", file);
11557 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11558 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11559 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11560 + (unsigned long long)drinfo->ino,
11561 + (unsigned long long)h_ino, file);
11562 + goto out; /* success */
11565 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11566 + if (unlikely(!ret)) {
11567 + ret = ERR_PTR(-ENOMEM);
11568 + AuTraceErrPtr(ret);
11573 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11574 + if (unlikely(ssz != len)) {
11576 + ret = ERR_PTR(-EIO);
11577 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11581 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11587 +/* ---------------------------------------------------------------------- */
11589 +/* in order to be revertible */
11590 +struct au_drinfo_rev_elm {
11592 + struct dentry *info_dentry;
11593 + struct au_drinfo *info_last;
11596 +struct au_drinfo_rev {
11597 + unsigned char already;
11598 + aufs_bindex_t nelm;
11599 + struct au_drinfo_rev_elm elm[0];
11602 +/* todo: isn't it too large? */
11603 +struct au_drinfo_store {
11604 + struct path h_ppath;
11605 + struct dentry *h_dentry;
11606 + struct au_drinfo_fdata *fdata;
11607 + char *infoname; /* inside of whname, just after PFX */
11608 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11609 + aufs_bindex_t btgt, btail;
11610 + unsigned char no_sio,
11611 + allocated, /* current size of *fdata */
11612 + infonamelen, /* room size for p */
11613 + whnamelen, /* length of the genarated name */
11614 + renameback; /* renamed back */
11617 +/* on rename(2) error, the caller should revert it using @elm */
11618 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11619 + struct au_drinfo_rev_elm *elm)
11624 + struct path infopath = {
11625 + .mnt = w->h_ppath.mnt
11627 + struct inode *h_dir, *h_inode, *delegated;
11628 + struct file *infofile;
11629 + struct qstr *qname;
11632 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11634 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11636 + AuTraceErrPtr(infopath.dentry);
11637 + if (IS_ERR(infopath.dentry)) {
11638 + err = PTR_ERR(infopath.dentry);
11643 + h_dir = d_inode(w->h_ppath.dentry);
11644 + if (elm && d_is_negative(infopath.dentry)) {
11645 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11647 + if (unlikely(err))
11649 + elm->created = 1;
11650 + elm->info_dentry = dget(infopath.dentry);
11653 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11654 + AuTraceErrPtr(infofile);
11655 + if (IS_ERR(infofile)) {
11656 + err = PTR_ERR(infofile);
11660 + h_inode = d_inode(infopath.dentry);
11661 + if (elm && i_size_read(h_inode)) {
11662 + h_inode = d_inode(w->h_dentry);
11663 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11664 + AuTraceErrPtr(elm->info_last);
11665 + if (IS_ERR(elm->info_last)) {
11666 + err = PTR_ERR(elm->info_last);
11667 + elm->info_last = NULL;
11668 + AuDebugOn(elm->info_dentry);
11673 + if (elm && w->renameback) {
11674 + delegated = NULL;
11675 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11677 + if (unlikely(err == -EWOULDBLOCK))
11683 + qname = &w->h_dentry->d_name;
11684 + len = sizeof(*w->fdata) + qname->len;
11686 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11687 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11688 + if (ssz == len) {
11689 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11690 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11691 + goto out_fput; /* success */
11696 + /* the caller should revert it using @elm */
11702 + dput(infopath.dentry);
11708 +struct au_call_drinfo_do_store_args {
11710 + struct au_drinfo_store *w;
11711 + struct au_drinfo_rev_elm *elm;
11714 +static void au_call_drinfo_do_store(void *args)
11716 + struct au_call_drinfo_do_store_args *a = args;
11718 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11721 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11722 + struct au_drinfo_rev_elm *elm)
11724 + int err, wkq_err;
11727 + err = au_drinfo_do_store(w, elm);
11729 + struct au_call_drinfo_do_store_args a = {
11734 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11735 + if (unlikely(wkq_err))
11743 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11744 + aufs_bindex_t btgt)
11748 + memset(w, 0, sizeof(*w));
11749 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11750 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11751 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11752 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11754 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11757 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11758 + if (unlikely(!w->fdata)) {
11762 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11769 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11774 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11775 + struct au_drinfo_store *w)
11777 + struct au_drinfo_rev_elm *elm;
11778 + struct inode *h_dir, *delegated;
11780 + struct path infopath = {
11781 + .mnt = w->h_ppath.mnt
11784 + h_dir = d_inode(w->h_ppath.dentry);
11785 + IMustLock(h_dir);
11789 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11790 + AuDebugOn(elm->created && elm->info_last);
11791 + if (elm->created) {
11793 + delegated = NULL;
11794 + infopath.dentry = elm->info_dentry;
11795 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11798 + if (unlikely(err == -EWOULDBLOCK))
11800 + dput(elm->info_dentry);
11801 + } else if (elm->info_last) {
11803 + w->fdata->drinfo = *elm->info_last;
11804 + memcpy(w->fdata->drinfo.oldname,
11805 + elm->info_last->oldname,
11806 + elm->info_last->oldnamelen);
11807 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11808 + kfree(elm->info_last);
11810 + if (unlikely(err))
11811 + AuIOErr("%d, %s\n", err, w->whname);
11812 + /* go on even if err */
11816 +/* caller has to call au_dr_rename_fin() later */
11817 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11818 + struct qstr *dst_name, void *_rev)
11820 + int err, sz, nelm;
11821 + aufs_bindex_t bindex, btail;
11822 + struct au_drinfo_store work;
11823 + struct au_drinfo_rev *rev, **p;
11824 + struct au_drinfo_rev_elm *elm;
11825 + struct super_block *sb;
11826 + struct au_branch *br;
11827 + struct au_hinode *hdir;
11829 + err = au_drinfo_store_work_init(&work, btgt);
11831 + if (unlikely(err))
11835 + btail = au_dbtaildir(dentry);
11836 + nelm = btail - btgt;
11837 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11838 + rev = kcalloc(1, sz, GFP_NOFS);
11839 + if (unlikely(!rev)) {
11843 + rev->nelm = nelm;
11849 + sb = dentry->d_sb;
11850 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11851 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11852 + hdir = au_hi(d_inode(dentry), btgt);
11853 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11854 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11855 + work.h_dentry = au_h_dptr(dentry, bindex);
11856 + if (!work.h_dentry)
11859 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11860 + &work.allocated);
11862 + if (unlikely(err))
11865 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11866 + br = au_sbr(sb, bindex);
11867 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11868 + work.whnamelen += au_drinfo_name(br, work.infoname,
11869 + work.infonamelen);
11870 + AuDbg("whname %.*s, i%llu, %.*s\n",
11871 + work.whnamelen, work.whname,
11872 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11873 + work.fdata->drinfo.oldnamelen,
11874 + work.fdata->drinfo.oldname);
11876 + err = au_drinfo_store_sio(&work, elm);
11878 + if (unlikely(err))
11881 + if (unlikely(err)) {
11882 + /* revert all drinfo */
11883 + au_drinfo_store_rev(rev, &work);
11887 + au_hn_inode_unlock(hdir);
11890 + au_drinfo_store_work_fin(&work);
11895 +/* ---------------------------------------------------------------------- */
11897 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11898 + struct qstr *dst_name, void *_rev)
11900 + int err, already;
11902 + struct super_block *sb;
11903 + struct au_branch *br;
11904 + struct au_dr_br *dr;
11905 + struct dentry *h_dentry;
11906 + struct inode *h_inode;
11907 + struct au_dr_hino *ent;
11908 + struct au_drinfo_rev *rev, **p;
11910 + AuDbg("bindex %d\n", bindex);
11913 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11914 + if (unlikely(!ent))
11918 + br = au_sbr(sb, bindex);
11919 + dr = &br->br_dirren;
11920 + h_dentry = au_h_dptr(src, bindex);
11921 + h_inode = d_inode(h_dentry);
11922 + ino = h_inode->i_ino;
11923 + ent->dr_h_ino = ino;
11924 + already = au_dr_hino_test_add(dr, ino, ent);
11925 + AuDbg("b%d, hi%llu, already %d\n",
11926 + bindex, (unsigned long long)ino, already);
11928 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11933 + rev->already = already;
11934 + goto out; /* success */
11939 + au_dr_hino_del(dr, ent);
11947 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11949 + struct au_drinfo_rev *rev;
11950 + struct au_drinfo_rev_elm *elm;
11955 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11956 + dput(elm->info_dentry);
11957 + kfree(elm->info_last);
11962 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11965 + struct au_drinfo_store work;
11966 + struct au_drinfo_rev *rev = _rev;
11967 + struct super_block *sb;
11968 + struct au_branch *br;
11969 + struct inode *h_inode;
11970 + struct au_dr_br *dr;
11971 + struct au_dr_hino *ent;
11973 + err = au_drinfo_store_work_init(&work, btgt);
11974 + if (unlikely(err))
11978 + br = au_sbr(sb, btgt);
11979 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11980 + work.h_ppath.mnt = au_br_mnt(br);
11981 + au_drinfo_store_rev(rev, &work);
11982 + au_drinfo_store_work_fin(&work);
11983 + if (rev->already)
11986 + dr = &br->br_dirren;
11987 + h_inode = d_inode(work.h_ppath.dentry);
11988 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11990 + au_dr_hino_del(dr, ent);
11995 + if (unlikely(err))
11996 + pr_err("failed to remove dirren info\n");
11999 +/* ---------------------------------------------------------------------- */
12001 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
12002 + char *whname, int whnamelen,
12003 + struct dentry **info_dentry)
12005 + struct au_drinfo *drinfo;
12007 + struct inode *h_dir;
12008 + struct path infopath;
12011 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
12013 + *info_dentry = NULL;
12016 + h_dir = d_inode(h_ppath->dentry);
12017 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
12018 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
12020 + if (IS_ERR(infopath.dentry)) {
12021 + drinfo = (void *)infopath.dentry;
12025 + if (d_is_negative(infopath.dentry))
12026 + goto out_dput; /* success */
12028 + infopath.mnt = h_ppath->mnt;
12029 + f = vfsub_dentry_open(&infopath, O_RDONLY);
12030 + inode_unlock_shared(h_dir);
12033 + drinfo = (void *)f;
12037 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
12038 + if (IS_ERR_OR_NULL(drinfo))
12041 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
12042 + *info_dentry = dget(infopath.dentry); /* keep it alive */
12047 + dput(infopath.dentry);
12050 + inode_unlock_shared(h_dir);
12051 + AuTraceErrPtr(drinfo);
12055 +struct au_drinfo_do_load_args {
12056 + struct au_drinfo **drinfop;
12057 + struct path *h_ppath;
12060 + struct dentry **info_dentry;
12063 +static void au_call_drinfo_do_load(void *args)
12065 + struct au_drinfo_do_load_args *a = args;
12067 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
12071 +struct au_drinfo_load {
12072 + struct path h_ppath;
12073 + struct qstr *qname;
12074 + unsigned char no_sio;
12076 + aufs_bindex_t ninfo;
12077 + struct au_drinfo **drinfo;
12080 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
12081 + struct au_branch *br)
12083 + int err, wkq_err, whnamelen, e;
12084 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
12085 + = AUFS_WH_DR_INFO_PFX;
12086 + struct au_drinfo *drinfo;
12087 + struct qstr oldname;
12088 + struct inode *h_dir, *delegated;
12089 + struct dentry *info_dentry;
12090 + struct path infopath;
12092 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
12093 + whnamelen += au_drinfo_name(br, whname + whnamelen,
12094 + sizeof(whname) - whnamelen);
12096 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
12099 + struct au_drinfo_do_load_args args = {
12100 + .drinfop = &drinfo,
12101 + .h_ppath = &w->h_ppath,
12102 + .whname = whname,
12103 + .whnamelen = whnamelen,
12104 + .info_dentry = &info_dentry
12106 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
12107 + if (unlikely(wkq_err))
12108 + drinfo = ERR_PTR(wkq_err);
12110 + err = PTR_ERR(drinfo);
12111 + if (IS_ERR_OR_NULL(drinfo))
12115 + oldname.len = drinfo->oldnamelen;
12116 + oldname.name = drinfo->oldname;
12117 + if (au_qstreq(w->qname, &oldname)) {
12118 + /* the name is renamed back */
12122 + infopath.dentry = info_dentry;
12123 + infopath.mnt = w->h_ppath.mnt;
12124 + h_dir = d_inode(w->h_ppath.dentry);
12125 + delegated = NULL;
12126 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
12127 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
12128 + inode_unlock(h_dir);
12130 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
12131 + if (unlikely(e == -EWOULDBLOCK))
12134 + kfree(w->drinfo[bindex]);
12135 + w->drinfo[bindex] = drinfo;
12136 + dput(info_dentry);
12143 +/* ---------------------------------------------------------------------- */
12145 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12147 + struct au_drinfo **p = drinfo;
12150 + kfree(*drinfo++);
12154 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12155 + aufs_bindex_t btgt)
12158 + struct au_drinfo_load w;
12159 + aufs_bindex_t bindex, bbot;
12160 + struct au_branch *br;
12161 + struct inode *h_dir;
12162 + struct au_dr_hino *ent;
12163 + struct super_block *sb;
12165 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12166 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12167 + AuLNPair(&lkup->whname), btgt);
12169 + sb = dentry->d_sb;
12170 + bbot = au_sbbot(sb);
12171 + w.ninfo = bbot + 1;
12172 + if (!lkup->dirren.drinfo) {
12173 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12174 + sizeof(*lkup->dirren.drinfo),
12176 + if (unlikely(!lkup->dirren.drinfo)) {
12180 + lkup->dirren.ninfo = w.ninfo;
12182 + w.drinfo = lkup->dirren.drinfo;
12183 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12184 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12185 + AuDebugOn(!w.h_ppath.dentry);
12186 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12187 + w.qname = &dentry->d_name;
12190 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12191 + br = au_sbr(sb, bindex);
12192 + err = au_drinfo_load(&w, bindex, br);
12193 + if (unlikely(err))
12195 + if (w.drinfo[bindex])
12199 + br = au_sbr(sb, btgt);
12200 + h_dir = d_inode(w.h_ppath.dentry);
12201 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12203 + au_dr_hino_del(&br->br_dirren, ent);
12206 + goto out; /* success */
12209 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12210 + lkup->dirren.ninfo = 0;
12211 + lkup->dirren.drinfo = NULL;
12217 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12219 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12222 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12225 + struct au_drinfo *drinfo;
12228 + if (!lkup->dirren.drinfo)
12230 + AuDebugOn(lkup->dirren.ninfo < btgt + 1);
12231 + drinfo = lkup->dirren.drinfo[btgt + 1];
12235 + kfree(lkup->whname.name);
12236 + lkup->whname.name = NULL;
12237 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12238 + lkup->dirren.dr_name.name = drinfo->oldname;
12239 + lkup->name = &lkup->dirren.dr_name;
12240 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12242 + AuDbg("name %.*s, whname %.*s, b%d\n",
12243 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12251 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12255 + struct au_drinfo *drinfo;
12258 + if (!lkup->dirren.drinfo)
12260 + AuDebugOn(lkup->dirren.ninfo < bindex + 1);
12261 + drinfo = lkup->dirren.drinfo[bindex + 1];
12265 + match = (drinfo->ino == h_ino);
12266 + AuDbg("match %d\n", match);
12272 +/* ---------------------------------------------------------------------- */
12274 +int au_dr_opt_set(struct super_block *sb)
12277 + aufs_bindex_t bindex, bbot;
12278 + struct au_branch *br;
12281 + bbot = au_sbbot(sb);
12282 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12283 + br = au_sbr(sb, bindex);
12284 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12290 +int au_dr_opt_flush(struct super_block *sb)
12293 + aufs_bindex_t bindex, bbot;
12294 + struct au_branch *br;
12297 + bbot = au_sbbot(sb);
12298 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12299 + br = au_sbr(sb, bindex);
12300 + if (au_br_writable(br->br_perm))
12301 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12307 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12310 + aufs_bindex_t bindex, bbot;
12311 + struct au_branch *br;
12315 + err = au_dr_opt_flush(sb);
12316 + if (unlikely(err))
12320 + bbot = au_sbbot(sb);
12321 + for (bindex = 0; bindex <= bbot; bindex++) {
12322 + br = au_sbr(sb, bindex);
12323 + au_dr_hino_free(&br->br_dirren);
12329 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12330 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12331 +++ linux/fs/aufs/dirren.h 2018-08-12 23:43:05.453457863 +0200
12333 +/* SPDX-License-Identifier: GPL-2.0 */
12335 + * Copyright (C) 2017-2018 Junjiro R. Okajima
12337 + * This program, aufs is free software; you can redistribute it and/or modify
12338 + * it under the terms of the GNU General Public License as published by
12339 + * the Free Software Foundation; either version 2 of the License, or
12340 + * (at your option) any later version.
12342 + * This program is distributed in the hope that it will be useful,
12343 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12344 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12345 + * GNU General Public License for more details.
12347 + * You should have received a copy of the GNU General Public License
12348 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12352 + * renamed dir info
12355 +#ifndef __AUFS_DIRREN_H__
12356 +#define __AUFS_DIRREN_H__
12360 +#include <linux/dcache.h>
12361 +#include <linux/statfs.h>
12362 +#include <linux/uuid.h>
12365 +#define AuDirren_NHASH 100
12367 +#ifdef CONFIG_AUFS_DIRREN
12368 +enum au_brid_type {
12375 +struct au_dr_brid {
12376 + enum au_brid_type type;
12378 + uuid_t uuid; /* unimplemented yet */
12384 +/* 20 is the max digits length of ulong 64 */
12385 +/* brid-type "_" uuid "_" inum */
12386 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12387 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12389 +struct au_dr_hino {
12390 + struct hlist_bl_node dr_hnode;
12395 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12396 + struct au_dr_brid dr_brid;
12399 +struct au_dr_lookup {
12400 + /* dr_name is pointed by struct au_do_lookup_args.name */
12401 + struct qstr dr_name; /* subset of dr_info */
12402 + aufs_bindex_t ninfo;
12403 + struct au_drinfo **drinfo;
12406 +struct au_dr_hino;
12408 +struct au_dr_br { };
12409 +struct au_dr_lookup { };
12412 +/* ---------------------------------------------------------------------- */
12415 +struct au_do_lookup_args;
12417 +#ifdef CONFIG_AUFS_DIRREN
12418 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12419 + struct au_dr_hino *add_ent);
12420 +void au_dr_hino_free(struct au_dr_br *dr);
12421 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12422 + const struct path *path);
12423 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12424 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12425 + struct qstr *dst_name, void *_rev);
12426 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12427 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12428 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12429 + aufs_bindex_t bindex);
12430 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12431 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12433 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12434 +int au_dr_opt_set(struct super_block *sb);
12435 +int au_dr_opt_flush(struct super_block *sb);
12436 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12438 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12439 + struct au_dr_hino *add_ent);
12440 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12441 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12442 + const struct path *path);
12443 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12444 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12445 + struct qstr *dst_name, void *_rev);
12446 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12447 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12449 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12450 + aufs_bindex_t bindex);
12451 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12452 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12453 + aufs_bindex_t bindex, ino_t h_ino);
12454 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12455 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12456 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12457 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12460 +/* ---------------------------------------------------------------------- */
12462 +#ifdef CONFIG_AUFS_DIRREN
12463 +static inline int au_dr_ihash(ino_t h_ino)
12465 + return h_ino % AuDirren_NHASH;
12468 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12471 +#endif /* __KERNEL__ */
12472 +#endif /* __AUFS_DIRREN_H__ */
12473 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12474 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12475 +++ linux/fs/aufs/dynop.c 2018-08-12 23:43:05.456791299 +0200
12477 +// SPDX-License-Identifier: GPL-2.0
12479 + * Copyright (C) 2010-2018 Junjiro R. Okajima
12481 + * This program, aufs is free software; you can redistribute it and/or modify
12482 + * it under the terms of the GNU General Public License as published by
12483 + * the Free Software Foundation; either version 2 of the License, or
12484 + * (at your option) any later version.
12486 + * This program is distributed in the hope that it will be useful,
12487 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12488 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12489 + * GNU General Public License for more details.
12491 + * You should have received a copy of the GNU General Public License
12492 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12496 + * dynamically customizable operations for regular files
12501 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12504 + * How large will these lists be?
12505 + * Usually just a few elements, 20-30 at most for each, I guess.
12507 +static struct hlist_bl_head dynop[AuDyLast];
12509 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12510 + const void *h_op)
12512 + struct au_dykey *key, *tmp;
12513 + struct hlist_bl_node *pos;
12516 + hlist_bl_lock(hbl);
12517 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12518 + if (tmp->dk_op.dy_hop == h_op) {
12520 + kref_get(&key->dk_kref);
12523 + hlist_bl_unlock(hbl);
12528 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12530 + struct au_dykey **k, *found;
12531 + const void *h_op = key->dk_op.dy_hop;
12535 + k = br->br_dykey;
12536 + for (i = 0; i < AuBrDynOp; i++)
12538 + if (k[i]->dk_op.dy_hop == h_op) {
12545 + spin_lock(&br->br_dykey_lock);
12546 + for (; i < AuBrDynOp; i++)
12548 + if (k[i]->dk_op.dy_hop == h_op) {
12556 + spin_unlock(&br->br_dykey_lock);
12557 + BUG_ON(i == AuBrDynOp); /* expand the array */
12563 +/* kref_get() if @key is already added */
12564 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12566 + struct au_dykey *tmp, *found;
12567 + struct hlist_bl_node *pos;
12568 + const void *h_op = key->dk_op.dy_hop;
12571 + hlist_bl_lock(hbl);
12572 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12573 + if (tmp->dk_op.dy_hop == h_op) {
12574 + kref_get(&tmp->dk_kref);
12579 + hlist_bl_add_head(&key->dk_hnode, hbl);
12580 + hlist_bl_unlock(hbl);
12587 +static void dy_free_rcu(struct rcu_head *rcu)
12589 + struct au_dykey *key;
12591 + key = container_of(rcu, struct au_dykey, dk_rcu);
12596 +static void dy_free(struct kref *kref)
12598 + struct au_dykey *key;
12599 + struct hlist_bl_head *hbl;
12601 + key = container_of(kref, struct au_dykey, dk_kref);
12602 + hbl = dynop + key->dk_op.dy_type;
12603 + au_hbl_del(&key->dk_hnode, hbl);
12604 + call_rcu(&key->dk_rcu, dy_free_rcu);
12607 +void au_dy_put(struct au_dykey *key)
12609 + kref_put(&key->dk_kref, dy_free);
12612 +/* ---------------------------------------------------------------------- */
12614 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12616 +#ifdef CONFIG_AUFS_DEBUG
12617 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12618 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12620 +#define DyDbgDeclare(cnt) do {} while (0)
12621 +#define DyDbgInc(cnt) do {} while (0)
12624 +#define DySet(func, dst, src, h_op, h_sb) do { \
12626 + if (h_op->func) { \
12628 + dst.func = src.func; \
12630 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12634 +#define DySetForce(func, dst, src) do { \
12635 + AuDebugOn(!src.func); \
12637 + dst.func = src.func; \
12640 +#define DySetAop(func) \
12641 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12642 +#define DySetAopForce(func) \
12643 + DySetForce(func, dyaop->da_op, aufs_aop)
12645 +static void dy_aop(struct au_dykey *key, const void *h_op,
12646 + struct super_block *h_sb __maybe_unused)
12648 + struct au_dyaop *dyaop = (void *)key;
12649 + const struct address_space_operations *h_aop = h_op;
12650 + DyDbgDeclare(cnt);
12652 + AuDbg("%s\n", au_sbtype(h_sb));
12654 + DySetAop(writepage);
12655 + DySetAopForce(readpage); /* force */
12656 + DySetAop(writepages);
12657 + DySetAop(set_page_dirty);
12658 + DySetAop(readpages);
12659 + DySetAop(write_begin);
12660 + DySetAop(write_end);
12662 + DySetAop(invalidatepage);
12663 + DySetAop(releasepage);
12664 + DySetAop(freepage);
12665 + /* this one will be changed according to an aufs mount option */
12666 + DySetAop(direct_IO);
12667 + DySetAop(migratepage);
12668 + DySetAop(isolate_page);
12669 + DySetAop(putback_page);
12670 + DySetAop(launder_page);
12671 + DySetAop(is_partially_uptodate);
12672 + DySetAop(is_dirty_writeback);
12673 + DySetAop(error_remove_page);
12674 + DySetAop(swap_activate);
12675 + DySetAop(swap_deactivate);
12677 + DyDbgSize(cnt, *h_aop);
12680 +/* ---------------------------------------------------------------------- */
12682 +static void dy_bug(struct kref *kref)
12687 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12689 + struct au_dykey *key, *old;
12690 + struct hlist_bl_head *hbl;
12693 + void (*set)(struct au_dykey *key, const void *h_op,
12694 + struct super_block *h_sb __maybe_unused);
12696 + static const struct op a[] = {
12698 + .sz = sizeof(struct au_dyaop),
12702 + const struct op *p;
12704 + hbl = dynop + op->dy_type;
12705 + key = dy_gfind_get(hbl, op->dy_hop);
12707 + goto out_add; /* success */
12709 + p = a + op->dy_type;
12710 + key = kzalloc(p->sz, GFP_NOFS);
12711 + if (unlikely(!key)) {
12712 + key = ERR_PTR(-ENOMEM);
12716 + key->dk_op.dy_hop = op->dy_hop;
12717 + kref_init(&key->dk_kref);
12718 + p->set(key, op->dy_hop, au_br_sb(br));
12719 + old = dy_gadd(hbl, key);
12726 + old = dy_bradd(br, key);
12728 + /* its ref-count should never be zero here */
12729 + kref_put(&key->dk_kref, dy_bug);
12734 +/* ---------------------------------------------------------------------- */
12736 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
12737 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12738 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12739 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12740 + * See the aufs manual in detail.
12742 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12745 + dyaop->da_op.direct_IO = NULL;
12747 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12750 +static struct au_dyaop *dy_aget(struct au_branch *br,
12751 + const struct address_space_operations *h_aop,
12754 + struct au_dyaop *dyaop;
12755 + struct au_dynop op;
12757 + op.dy_type = AuDy_AOP;
12758 + op.dy_haop = h_aop;
12759 + dyaop = (void *)dy_get(&op, br);
12760 + if (IS_ERR(dyaop))
12762 + dy_adx(dyaop, do_dx);
12768 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12769 + struct inode *h_inode)
12772 + struct super_block *sb;
12773 + struct au_branch *br;
12774 + struct au_dyaop *dyaop;
12776 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12777 + IiMustWriteLock(inode);
12779 + sb = inode->i_sb;
12780 + br = au_sbr(sb, bindex);
12781 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12782 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12783 + err = PTR_ERR(dyaop);
12784 + if (IS_ERR(dyaop))
12785 + /* unnecessary to call dy_fput() */
12789 + inode->i_mapping->a_ops = &dyaop->da_op;
12796 + * Is it safe to replace a_ops during the inode/file is in operation?
12797 + * Yes, I hope so.
12799 +int au_dy_irefresh(struct inode *inode)
12802 + aufs_bindex_t btop;
12803 + struct inode *h_inode;
12806 + if (S_ISREG(inode->i_mode)) {
12807 + btop = au_ibtop(inode);
12808 + h_inode = au_h_iptr(inode, btop);
12809 + err = au_dy_iaop(inode, btop, h_inode);
12814 +void au_dy_arefresh(int do_dx)
12816 + struct hlist_bl_head *hbl;
12817 + struct hlist_bl_node *pos;
12818 + struct au_dykey *key;
12820 + hbl = dynop + AuDy_AOP;
12821 + hlist_bl_lock(hbl);
12822 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12823 + dy_adx((void *)key, do_dx);
12824 + hlist_bl_unlock(hbl);
12827 +/* ---------------------------------------------------------------------- */
12829 +void __init au_dy_init(void)
12833 + /* make sure that 'struct au_dykey *' can be any type */
12834 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
12836 + for (i = 0; i < AuDyLast; i++)
12837 + INIT_HLIST_BL_HEAD(dynop + i);
12840 +void au_dy_fin(void)
12844 + for (i = 0; i < AuDyLast; i++)
12845 + WARN_ON(!hlist_bl_empty(dynop + i));
12847 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12848 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12849 +++ linux/fs/aufs/dynop.h 2018-08-12 23:43:05.456791299 +0200
12851 +/* SPDX-License-Identifier: GPL-2.0 */
12853 + * Copyright (C) 2010-2018 Junjiro R. Okajima
12855 + * This program, aufs is free software; you can redistribute it and/or modify
12856 + * it under the terms of the GNU General Public License as published by
12857 + * the Free Software Foundation; either version 2 of the License, or
12858 + * (at your option) any later version.
12860 + * This program is distributed in the hope that it will be useful,
12861 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12862 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12863 + * GNU General Public License for more details.
12865 + * You should have received a copy of the GNU General Public License
12866 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12870 + * dynamically customizable operations (for regular files only)
12873 +#ifndef __AUFS_DYNOP_H__
12874 +#define __AUFS_DYNOP_H__
12878 +#include <linux/fs.h>
12879 +#include <linux/kref.h>
12881 +enum {AuDy_AOP, AuDyLast};
12886 + const void *dy_hop;
12887 + const struct address_space_operations *dy_haop;
12893 + struct hlist_bl_node dk_hnode;
12894 + struct rcu_head dk_rcu;
12896 + struct au_dynop dk_op;
12899 + * during I am in the branch local array, kref is gotten. when the
12900 + * branch is removed, kref is put.
12902 + struct kref dk_kref;
12905 +/* stop unioning since their sizes are very different from each other */
12907 + struct au_dykey da_key;
12908 + struct address_space_operations da_op; /* not const */
12911 +/* ---------------------------------------------------------------------- */
12915 +void au_dy_put(struct au_dykey *key);
12916 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12917 + struct inode *h_inode);
12918 +int au_dy_irefresh(struct inode *inode);
12919 +void au_dy_arefresh(int do_dio);
12921 +void __init au_dy_init(void);
12922 +void au_dy_fin(void);
12924 +#endif /* __KERNEL__ */
12925 +#endif /* __AUFS_DYNOP_H__ */
12926 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12927 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12928 +++ linux/fs/aufs/export.c 2018-08-12 23:43:05.456791299 +0200
12930 +// SPDX-License-Identifier: GPL-2.0
12932 + * Copyright (C) 2005-2018 Junjiro R. Okajima
12934 + * This program, aufs is free software; you can redistribute it and/or modify
12935 + * it under the terms of the GNU General Public License as published by
12936 + * the Free Software Foundation; either version 2 of the License, or
12937 + * (at your option) any later version.
12939 + * This program is distributed in the hope that it will be useful,
12940 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12941 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12942 + * GNU General Public License for more details.
12944 + * You should have received a copy of the GNU General Public License
12945 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12952 +#include <linux/exportfs.h>
12953 +#include <linux/fs_struct.h>
12954 +#include <linux/namei.h>
12955 +#include <linux/nsproxy.h>
12956 +#include <linux/random.h>
12957 +#include <linux/writeback.h>
12961 +#ifdef CONFIG_AUFS_INO_T_64
12969 +static ino_t decode_ino(__u32 *a)
12973 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12975 +#ifdef CONFIG_AUFS_INO_T_64
12981 +static void encode_ino(__u32 *a, ino_t ino)
12987 +#ifdef CONFIG_AUFS_INO_T_64
12992 +/* NFS file handle */
12996 +#ifdef CONFIG_AUFS_INO_T_64
12997 + /* support 64bit inode number */
13010 + Fh_ino = Fh_ino1,
13011 + Fh_dir_ino = Fh_dir_ino1
13014 +static int au_test_anon(struct dentry *dentry)
13016 + /* note: read d_flags without d_lock */
13017 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
13020 +int au_test_nfsd(void)
13023 + struct task_struct *tsk = current;
13024 + char comm[sizeof(tsk->comm)];
13027 + if (tsk->flags & PF_KTHREAD) {
13028 + get_task_comm(comm, tsk);
13029 + ret = !strcmp(comm, "nfsd");
13035 +/* ---------------------------------------------------------------------- */
13036 +/* inode generation external table */
13038 +void au_xigen_inc(struct inode *inode)
13043 + struct super_block *sb;
13044 + struct au_sbinfo *sbinfo;
13046 + sb = inode->i_sb;
13047 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
13049 + sbinfo = au_sbi(sb);
13050 + pos = inode->i_ino;
13051 + pos *= sizeof(igen);
13052 + igen = inode->i_generation + 1;
13053 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
13054 + sizeof(igen), &pos);
13055 + if (sz == sizeof(igen))
13056 + return; /* success */
13058 + if (unlikely(sz >= 0))
13059 + AuIOErr("xigen error (%zd)\n", sz);
13062 +int au_xigen_new(struct inode *inode)
13067 + struct super_block *sb;
13068 + struct au_sbinfo *sbinfo;
13069 + struct file *file;
13072 + /* todo: dirty, at mount time */
13073 + if (inode->i_ino == AUFS_ROOT_INO)
13075 + sb = inode->i_sb;
13076 + SiMustAnyLock(sb);
13077 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13081 + pos = inode->i_ino;
13082 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
13083 + AuIOErr1("too large i%lld\n", pos);
13086 + pos *= sizeof(inode->i_generation);
13089 + sbinfo = au_sbi(sb);
13090 + file = sbinfo->si_xigen;
13093 + if (vfsub_f_size_read(file)
13094 + < pos + sizeof(inode->i_generation)) {
13095 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
13096 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
13097 + sizeof(inode->i_generation), &pos);
13099 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
13100 + sizeof(inode->i_generation), &pos);
13101 + if (sz == sizeof(inode->i_generation))
13102 + goto out; /* success */
13105 + if (unlikely(sz >= 0)) {
13107 + AuIOErr("xigen error (%zd)\n", sz);
13114 +int au_xigen_set(struct super_block *sb, struct path *path)
13117 + struct au_sbinfo *sbinfo;
13118 + struct file *file;
13120 + SiMustWriteLock(sb);
13122 + sbinfo = au_sbi(sb);
13123 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
13124 + err = PTR_ERR(file);
13125 + if (IS_ERR(file))
13128 + if (sbinfo->si_xigen)
13129 + fput(sbinfo->si_xigen);
13130 + sbinfo->si_xigen = file;
13137 +void au_xigen_clr(struct super_block *sb)
13139 + struct au_sbinfo *sbinfo;
13141 + SiMustWriteLock(sb);
13143 + sbinfo = au_sbi(sb);
13144 + if (sbinfo->si_xigen) {
13145 + fput(sbinfo->si_xigen);
13146 + sbinfo->si_xigen = NULL;
13150 +/* ---------------------------------------------------------------------- */
13152 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13155 + struct dentry *dentry, *d;
13156 + struct inode *inode;
13157 + unsigned int sigen;
13160 + inode = ilookup(sb, ino);
13164 + dentry = ERR_PTR(-ESTALE);
13165 + sigen = au_sigen(sb);
13166 + if (unlikely(au_is_bad_inode(inode)
13167 + || IS_DEADDIR(inode)
13168 + || sigen != au_iigen(inode, NULL)))
13172 + if (!dir_ino || S_ISDIR(inode->i_mode))
13173 + dentry = d_find_alias(inode);
13175 + spin_lock(&inode->i_lock);
13176 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13177 + spin_lock(&d->d_lock);
13178 + if (!au_test_anon(d)
13179 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13180 + dentry = dget_dlock(d);
13181 + spin_unlock(&d->d_lock);
13184 + spin_unlock(&d->d_lock);
13186 + spin_unlock(&inode->i_lock);
13188 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13189 + /* need to refresh */
13197 + AuTraceErrPtr(dentry);
13201 +/* ---------------------------------------------------------------------- */
13203 +/* todo: dirty? */
13204 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13206 +struct au_compare_mnt_args {
13208 + struct super_block *sb;
13211 + struct vfsmount *mnt;
13214 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13216 + struct au_compare_mnt_args *a = arg;
13218 + if (mnt->mnt_sb != a->sb)
13220 + a->mnt = mntget(mnt);
13224 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13227 + struct path root;
13228 + struct au_compare_mnt_args args = {
13232 + get_fs_root(current->fs, &root);
13234 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13235 + rcu_read_unlock();
13238 + AuDebugOn(!args.mnt);
13242 +struct au_nfsd_si_lock {
13243 + unsigned int sigen;
13244 + aufs_bindex_t bindex, br_id;
13245 + unsigned char force_lock;
13248 +static int si_nfsd_read_lock(struct super_block *sb,
13249 + struct au_nfsd_si_lock *nsi_lock)
13252 + aufs_bindex_t bindex;
13254 + si_read_lock(sb, AuLock_FLUSH);
13256 + /* branch id may be wrapped around */
13258 + bindex = au_br_index(sb, nsi_lock->br_id);
13259 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13260 + goto out; /* success */
13264 + if (!nsi_lock->force_lock)
13265 + si_read_unlock(sb);
13268 + nsi_lock->bindex = bindex;
13272 +struct find_name_by_ino {
13273 + struct dir_context ctx;
13274 + int called, found;
13281 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13282 + loff_t offset, u64 ino, unsigned int d_type)
13284 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13288 + if (a->ino != ino)
13291 + memcpy(a->name, name, namelen);
13292 + a->namelen = namelen;
13297 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13298 + struct au_nfsd_si_lock *nsi_lock)
13300 + struct dentry *dentry, *parent;
13301 + struct file *file;
13302 + struct inode *dir;
13303 + struct find_name_by_ino arg = {
13305 + .actor = find_name_by_ino
13310 + parent = path->dentry;
13312 + si_read_unlock(parent->d_sb);
13313 + file = vfsub_dentry_open(path, au_dir_roflags);
13314 + dentry = (void *)file;
13315 + if (IS_ERR(file))
13318 + dentry = ERR_PTR(-ENOMEM);
13319 + arg.name = (void *)__get_free_page(GFP_NOFS);
13320 + if (unlikely(!arg.name))
13327 + err = vfsub_iterate_dir(file, &arg.ctx);
13328 + } while (!err && !arg.found && arg.called);
13329 + dentry = ERR_PTR(err);
13330 + if (unlikely(err))
13332 + /* instead of ENOENT */
13333 + dentry = ERR_PTR(-ESTALE);
13337 + /* do not call vfsub_lkup_one() */
13338 + dir = d_inode(parent);
13339 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13340 + AuTraceErrPtr(dentry);
13341 + if (IS_ERR(dentry))
13343 + AuDebugOn(au_test_anon(dentry));
13344 + if (unlikely(d_really_is_negative(dentry))) {
13346 + dentry = ERR_PTR(-ENOENT);
13350 + free_page((unsigned long)arg.name);
13354 + if (unlikely(nsi_lock
13355 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13356 + if (!IS_ERR(dentry)) {
13358 + dentry = ERR_PTR(-ESTALE);
13360 + AuTraceErrPtr(dentry);
13364 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13366 + struct au_nfsd_si_lock *nsi_lock)
13368 + struct dentry *dentry;
13369 + struct path path;
13371 + if (dir_ino != AUFS_ROOT_INO) {
13372 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13373 + dentry = path.dentry;
13374 + if (!path.dentry || IS_ERR(path.dentry))
13376 + AuDebugOn(au_test_anon(path.dentry));
13378 + path.dentry = dget(sb->s_root);
13380 + path.mnt = au_mnt_get(sb);
13381 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13385 + AuTraceErrPtr(dentry);
13389 +/* ---------------------------------------------------------------------- */
13391 +static int h_acceptable(void *expv, struct dentry *dentry)
13396 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13397 + char *buf, int len, struct super_block *sb)
13401 + struct path path;
13403 + p = d_path(h_rootpath, buf, len);
13408 + path.mnt = h_rootpath->mnt;
13409 + path.dentry = h_parent;
13410 + p = d_path(&path, buf, len);
13416 + path.mnt = au_mnt_get(sb);
13417 + path.dentry = sb->s_root;
13418 + p = d_path(&path, buf, len - strlen(p));
13419 + mntput(path.mnt);
13423 + p[strlen(p)] = '/';
13426 + AuTraceErrPtr(p);
13431 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13432 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13434 + struct dentry *dentry, *h_parent, *root;
13435 + struct super_block *h_sb;
13436 + char *pathname, *p;
13437 + struct vfsmount *h_mnt;
13438 + struct au_branch *br;
13440 + struct path path;
13442 + br = au_sbr(sb, nsi_lock->bindex);
13443 + h_mnt = au_br_mnt(br);
13444 + h_sb = h_mnt->mnt_sb;
13445 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13447 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13448 + fh_len - Fh_tail, fh[Fh_h_type],
13449 + h_acceptable, /*context*/NULL);
13451 + dentry = h_parent;
13452 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13453 + AuWarn1("%s decode_fh failed, %ld\n",
13454 + au_sbtype(h_sb), PTR_ERR(h_parent));
13458 + if (unlikely(au_test_anon(h_parent))) {
13459 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13460 + au_sbtype(h_sb));
13461 + goto out_h_parent;
13464 + dentry = ERR_PTR(-ENOMEM);
13465 + pathname = (void *)__get_free_page(GFP_NOFS);
13466 + if (unlikely(!pathname))
13467 + goto out_h_parent;
13469 + root = sb->s_root;
13470 + path.mnt = h_mnt;
13471 + di_read_lock_parent(root, !AuLock_IR);
13472 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13473 + di_read_unlock(root, !AuLock_IR);
13474 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13475 + dentry = (void *)p;
13477 + goto out_pathname;
13479 + si_read_unlock(sb);
13480 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13481 + dentry = ERR_PTR(err);
13482 + if (unlikely(err))
13485 + dentry = ERR_PTR(-ENOENT);
13486 + AuDebugOn(au_test_anon(path.dentry));
13487 + if (unlikely(d_really_is_negative(path.dentry)))
13490 + if (ino != d_inode(path.dentry)->i_ino)
13491 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13493 + dentry = dget(path.dentry);
13498 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13499 + if (!IS_ERR(dentry)) {
13501 + dentry = ERR_PTR(-ESTALE);
13504 + free_page((unsigned long)pathname);
13508 + AuTraceErrPtr(dentry);
13512 +/* ---------------------------------------------------------------------- */
13514 +static struct dentry *
13515 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13518 + struct dentry *dentry;
13519 + __u32 *fh = fid->raw;
13520 + struct au_branch *br;
13521 + ino_t ino, dir_ino;
13522 + struct au_nfsd_si_lock nsi_lock = {
13526 + dentry = ERR_PTR(-ESTALE);
13527 + /* it should never happen, but the file handle is unreliable */
13528 + if (unlikely(fh_len < Fh_tail))
13530 + nsi_lock.sigen = fh[Fh_sigen];
13531 + nsi_lock.br_id = fh[Fh_br_id];
13533 + /* branch id may be wrapped around */
13535 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13537 + nsi_lock.force_lock = 1;
13539 + /* is this inode still cached? */
13540 + ino = decode_ino(fh + Fh_ino);
13541 + /* it should never happen */
13542 + if (unlikely(ino == AUFS_ROOT_INO))
13545 + dir_ino = decode_ino(fh + Fh_dir_ino);
13546 + dentry = decode_by_ino(sb, ino, dir_ino);
13547 + if (IS_ERR(dentry))
13552 + /* is the parent dir cached? */
13553 + br = au_sbr(sb, nsi_lock.bindex);
13555 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13556 + if (IS_ERR(dentry))
13561 + /* lookup path */
13562 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13563 + if (IS_ERR(dentry))
13565 + if (unlikely(!dentry))
13566 + /* todo?: make it ESTALE */
13570 + if (!au_digen_test(dentry, au_sigen(sb))
13571 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13572 + goto out_unlock; /* success */
13575 + dentry = ERR_PTR(-ESTALE);
13579 + si_read_unlock(sb);
13581 + AuTraceErrPtr(dentry);
13585 +#if 0 /* reserved for future use */
13586 +/* support subtreecheck option */
13587 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13588 + int fh_len, int fh_type)
13590 + struct dentry *parent;
13591 + __u32 *fh = fid->raw;
13594 + dir_ino = decode_ino(fh + Fh_dir_ino);
13595 + parent = decode_by_ino(sb, dir_ino, 0);
13596 + if (IS_ERR(parent))
13599 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13600 + dir_ino, fh, fh_len);
13603 + AuTraceErrPtr(parent);
13608 +/* ---------------------------------------------------------------------- */
13610 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13611 + struct inode *dir)
13614 + aufs_bindex_t bindex;
13615 + struct super_block *sb, *h_sb;
13616 + struct dentry *dentry, *parent, *h_parent;
13617 + struct inode *h_dir;
13618 + struct au_branch *br;
13621 + if (unlikely(*max_len <= Fh_tail)) {
13622 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13626 + err = FILEID_ROOT;
13627 + if (inode->i_ino == AUFS_ROOT_INO) {
13628 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13633 + sb = inode->i_sb;
13634 + err = si_read_lock(sb, AuLock_FLUSH);
13635 + if (unlikely(err))
13638 +#ifdef CONFIG_AUFS_DEBUG
13639 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13640 + AuWarn1("NFS-exporting requires xino\n");
13644 + ii_read_lock_child(inode);
13645 + bindex = au_ibtop(inode);
13647 + dentry = d_find_any_alias(inode);
13648 + if (unlikely(!dentry))
13650 + AuDebugOn(au_test_anon(dentry));
13651 + parent = dget_parent(dentry);
13653 + if (unlikely(!parent))
13655 + if (d_really_is_positive(parent))
13656 + dir = d_inode(parent);
13659 + ii_read_lock_parent(dir);
13660 + h_dir = au_h_iptr(dir, bindex);
13661 + ii_read_unlock(dir);
13662 + if (unlikely(!h_dir))
13664 + h_parent = d_find_any_alias(h_dir);
13665 + if (unlikely(!h_parent))
13666 + goto out_hparent;
13669 + br = au_sbr(sb, bindex);
13670 + h_sb = au_br_sb(br);
13671 + if (unlikely(!h_sb->s_export_op)) {
13672 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13673 + goto out_hparent;
13676 + fh[Fh_br_id] = br->br_id;
13677 + fh[Fh_sigen] = au_sigen(sb);
13678 + encode_ino(fh + Fh_ino, inode->i_ino);
13679 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13680 + fh[Fh_igen] = inode->i_generation;
13682 + *max_len -= Fh_tail;
13683 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13685 + /*connectable or subtreecheck*/0);
13686 + err = fh[Fh_h_type];
13687 + *max_len += Fh_tail;
13688 + /* todo: macros? */
13689 + if (err != FILEID_INVALID)
13692 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13699 + ii_read_unlock(inode);
13700 + si_read_unlock(sb);
13702 + if (unlikely(err < 0))
13703 + err = FILEID_INVALID;
13707 +/* ---------------------------------------------------------------------- */
13709 +static int aufs_commit_metadata(struct inode *inode)
13712 + aufs_bindex_t bindex;
13713 + struct super_block *sb;
13714 + struct inode *h_inode;
13715 + int (*f)(struct inode *inode);
13717 + sb = inode->i_sb;
13718 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13719 + ii_write_lock_child(inode);
13720 + bindex = au_ibtop(inode);
13721 + AuDebugOn(bindex < 0);
13722 + h_inode = au_h_iptr(inode, bindex);
13724 + f = h_inode->i_sb->s_export_op->commit_metadata;
13726 + err = f(h_inode);
13728 + struct writeback_control wbc = {
13729 + .sync_mode = WB_SYNC_ALL,
13730 + .nr_to_write = 0 /* metadata only */
13733 + err = sync_inode(h_inode, &wbc);
13736 + au_cpup_attr_timesizes(inode);
13737 + ii_write_unlock(inode);
13738 + si_read_unlock(sb);
13742 +/* ---------------------------------------------------------------------- */
13744 +static struct export_operations aufs_export_op = {
13745 + .fh_to_dentry = aufs_fh_to_dentry,
13746 + /* .fh_to_parent = aufs_fh_to_parent, */
13747 + .encode_fh = aufs_encode_fh,
13748 + .commit_metadata = aufs_commit_metadata
13751 +void au_export_init(struct super_block *sb)
13753 + struct au_sbinfo *sbinfo;
13756 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13757 + && IS_MODULE(CONFIG_EXPORTFS),
13758 + AUFS_NAME ": unsupported configuration "
13759 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13761 + sb->s_export_op = &aufs_export_op;
13762 + sbinfo = au_sbi(sb);
13763 + sbinfo->si_xigen = NULL;
13764 + get_random_bytes(&u, sizeof(u));
13765 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13766 + atomic_set(&sbinfo->si_xigen_next, u);
13768 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13769 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13770 +++ linux/fs/aufs/fhsm.c 2018-08-12 23:43:05.456791299 +0200
13772 +// SPDX-License-Identifier: GPL-2.0
13774 + * Copyright (C) 2011-2018 Junjiro R. Okajima
13776 + * This program, aufs is free software; you can redistribute it and/or modify
13777 + * it under the terms of the GNU General Public License as published by
13778 + * the Free Software Foundation; either version 2 of the License, or
13779 + * (at your option) any later version.
13781 + * This program is distributed in the hope that it will be useful,
13782 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13783 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13784 + * GNU General Public License for more details.
13786 + * You should have received a copy of the GNU General Public License
13787 + * along with this program; if not, write to the Free Software
13788 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13792 + * File-based Hierarchy Storage Management
13795 +#include <linux/anon_inodes.h>
13796 +#include <linux/poll.h>
13797 +#include <linux/seq_file.h>
13798 +#include <linux/statfs.h>
13801 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13803 + struct au_sbinfo *sbinfo;
13804 + struct au_fhsm *fhsm;
13806 + SiMustAnyLock(sb);
13808 + sbinfo = au_sbi(sb);
13809 + fhsm = &sbinfo->si_fhsm;
13810 + AuDebugOn(!fhsm);
13811 + return fhsm->fhsm_bottom;
13814 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13816 + struct au_sbinfo *sbinfo;
13817 + struct au_fhsm *fhsm;
13819 + SiMustWriteLock(sb);
13821 + sbinfo = au_sbi(sb);
13822 + fhsm = &sbinfo->si_fhsm;
13823 + AuDebugOn(!fhsm);
13824 + fhsm->fhsm_bottom = bindex;
13827 +/* ---------------------------------------------------------------------- */
13829 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13831 + struct au_br_fhsm *bf;
13833 + bf = br->br_fhsm;
13834 + MtxMustLock(&bf->bf_lock);
13836 + return !bf->bf_readable
13837 + || time_after(jiffies,
13838 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13841 +/* ---------------------------------------------------------------------- */
13843 +static void au_fhsm_notify(struct super_block *sb, int val)
13845 + struct au_sbinfo *sbinfo;
13846 + struct au_fhsm *fhsm;
13848 + SiMustAnyLock(sb);
13850 + sbinfo = au_sbi(sb);
13851 + fhsm = &sbinfo->si_fhsm;
13852 + if (au_fhsm_pid(fhsm)
13853 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13854 + atomic_set(&fhsm->fhsm_readable, val);
13856 + wake_up(&fhsm->fhsm_wqh);
13860 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13861 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13864 + struct au_branch *br;
13865 + struct au_br_fhsm *bf;
13867 + br = au_sbr(sb, bindex);
13868 + AuDebugOn(au_br_rdonly(br));
13869 + bf = br->br_fhsm;
13873 + mutex_lock(&bf->bf_lock);
13875 + MtxMustLock(&bf->bf_lock);
13877 + /* sb->s_root for NFS is unreliable */
13878 + err = au_br_stfs(br, &bf->bf_stfs);
13879 + if (unlikely(err)) {
13880 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13884 + bf->bf_jiffy = jiffies;
13885 + bf->bf_readable = 1;
13887 + au_fhsm_notify(sb, /*val*/1);
13889 + *rstfs = bf->bf_stfs;
13893 + mutex_unlock(&bf->bf_lock);
13894 + au_fhsm_notify(sb, /*val*/1);
13899 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13902 + struct au_sbinfo *sbinfo;
13903 + struct au_fhsm *fhsm;
13904 + struct au_branch *br;
13905 + struct au_br_fhsm *bf;
13907 + AuDbg("b%d, force %d\n", bindex, force);
13908 + SiMustAnyLock(sb);
13910 + sbinfo = au_sbi(sb);
13911 + fhsm = &sbinfo->si_fhsm;
13912 + if (!au_ftest_si(sbinfo, FHSM)
13913 + || fhsm->fhsm_bottom == bindex)
13916 + br = au_sbr(sb, bindex);
13917 + bf = br->br_fhsm;
13919 + mutex_lock(&bf->bf_lock);
13921 + || au_fhsm_pid(fhsm)
13922 + || au_fhsm_test_jiffy(sbinfo, br))
13923 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13925 + mutex_unlock(&bf->bf_lock);
13928 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13930 + aufs_bindex_t bindex, bbot;
13931 + struct au_branch *br;
13933 + /* exclude the bottom */
13934 + bbot = au_fhsm_bottom(sb);
13935 + for (bindex = 0; bindex < bbot; bindex++) {
13936 + br = au_sbr(sb, bindex);
13937 + if (au_br_fhsm(br->br_perm))
13938 + au_fhsm_wrote(sb, bindex, force);
13942 +/* ---------------------------------------------------------------------- */
13944 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13947 + struct au_sbinfo *sbinfo;
13948 + struct au_fhsm *fhsm;
13951 + sbinfo = file->private_data;
13952 + fhsm = &sbinfo->si_fhsm;
13953 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13954 + if (atomic_read(&fhsm->fhsm_readable))
13955 + mask = EPOLLIN /* | EPOLLRDNORM */;
13958 + AuDbg("mask 0x%x\n", mask);
13962 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13963 + struct aufs_stfs *stfs, __s16 brid)
13967 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13969 + err = __put_user(brid, &stbr->brid);
13970 + if (unlikely(err))
13976 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13977 + struct aufs_stbr __user *stbr, size_t count)
13981 + aufs_bindex_t bindex, bbot;
13982 + struct au_branch *br;
13983 + struct au_br_fhsm *bf;
13985 + /* except the bottom branch */
13988 + bbot = au_fhsm_bottom(sb);
13989 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13990 + br = au_sbr(sb, bindex);
13991 + if (!au_br_fhsm(br->br_perm))
13994 + bf = br->br_fhsm;
13995 + mutex_lock(&bf->bf_lock);
13996 + if (bf->bf_readable) {
13998 + if (count >= sizeof(*stbr))
13999 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
14002 + bf->bf_readable = 0;
14003 + count -= sizeof(*stbr);
14007 + mutex_unlock(&bf->bf_lock);
14010 + err = sizeof(*stbr) * nstbr;
14015 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
14020 + aufs_bindex_t nfhsm, bindex, bbot;
14021 + struct au_sbinfo *sbinfo;
14022 + struct au_fhsm *fhsm;
14023 + struct au_branch *br;
14024 + struct super_block *sb;
14027 + sbinfo = file->private_data;
14028 + fhsm = &sbinfo->si_fhsm;
14030 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
14031 + if (!atomic_read(&fhsm->fhsm_readable)) {
14032 + if (vfsub_file_flags(file) & O_NONBLOCK)
14035 + err = wait_event_interruptible_locked_irq
14037 + atomic_read(&fhsm->fhsm_readable));
14039 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
14040 + if (unlikely(err))
14043 + /* sb may already be dead */
14044 + au_rw_read_lock(&sbinfo->si_rwsem);
14045 + readable = atomic_read(&fhsm->fhsm_readable);
14046 + if (readable > 0) {
14047 + sb = sbinfo->si_sb;
14049 + /* exclude the bottom branch */
14051 + bbot = au_fhsm_bottom(sb);
14052 + for (bindex = 0; bindex < bbot; bindex++) {
14053 + br = au_sbr(sb, bindex);
14054 + if (au_br_fhsm(br->br_perm))
14058 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
14059 + atomic_set(&fhsm->fhsm_readable, 0);
14060 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
14064 + au_rw_read_unlock(&sbinfo->si_rwsem);
14072 +static int au_fhsm_release(struct inode *inode, struct file *file)
14074 + struct au_sbinfo *sbinfo;
14075 + struct au_fhsm *fhsm;
14077 + /* sb may already be dead */
14078 + sbinfo = file->private_data;
14079 + fhsm = &sbinfo->si_fhsm;
14080 + spin_lock(&fhsm->fhsm_spin);
14081 + fhsm->fhsm_pid = 0;
14082 + spin_unlock(&fhsm->fhsm_spin);
14083 + kobject_put(&sbinfo->si_kobj);
14088 +static const struct file_operations au_fhsm_fops = {
14089 + .owner = THIS_MODULE,
14090 + .llseek = noop_llseek,
14091 + .read = au_fhsm_read,
14092 + .poll = au_fhsm_poll,
14093 + .release = au_fhsm_release
14096 +int au_fhsm_fd(struct super_block *sb, int oflags)
14099 + struct au_sbinfo *sbinfo;
14100 + struct au_fhsm *fhsm;
14103 + if (unlikely(!capable(CAP_SYS_ADMIN)))
14107 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
14111 + sbinfo = au_sbi(sb);
14112 + fhsm = &sbinfo->si_fhsm;
14113 + spin_lock(&fhsm->fhsm_spin);
14114 + if (!fhsm->fhsm_pid)
14115 + fhsm->fhsm_pid = current->pid;
14118 + spin_unlock(&fhsm->fhsm_spin);
14119 + if (unlikely(err))
14122 + oflags |= O_RDONLY;
14123 + /* oflags |= FMODE_NONOTIFY; */
14124 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
14126 + if (unlikely(fd < 0))
14129 + /* succeed reglardless 'fhsm' status */
14130 + kobject_get(&sbinfo->si_kobj);
14131 + si_noflush_read_lock(sb);
14132 + if (au_ftest_si(sbinfo, FHSM))
14133 + au_fhsm_wrote_all(sb, /*force*/0);
14134 + si_read_unlock(sb);
14135 + goto out; /* success */
14138 + spin_lock(&fhsm->fhsm_spin);
14139 + fhsm->fhsm_pid = 0;
14140 + spin_unlock(&fhsm->fhsm_spin);
14146 +/* ---------------------------------------------------------------------- */
14148 +int au_fhsm_br_alloc(struct au_branch *br)
14153 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14155 + au_br_fhsm_init(br->br_fhsm);
14162 +/* ---------------------------------------------------------------------- */
14164 +void au_fhsm_fin(struct super_block *sb)
14166 + au_fhsm_notify(sb, /*val*/-1);
14169 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14171 + struct au_fhsm *fhsm;
14173 + fhsm = &sbinfo->si_fhsm;
14174 + spin_lock_init(&fhsm->fhsm_spin);
14175 + init_waitqueue_head(&fhsm->fhsm_wqh);
14176 + atomic_set(&fhsm->fhsm_readable, 0);
14177 + fhsm->fhsm_expire
14178 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14179 + fhsm->fhsm_bottom = -1;
14182 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14184 + sbinfo->si_fhsm.fhsm_expire
14185 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14188 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14192 + if (!au_ftest_si(sbinfo, FHSM))
14195 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14196 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14197 + seq_printf(seq, ",fhsm_sec=%u", u);
14199 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14200 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14201 +++ linux/fs/aufs/file.c 2018-08-12 23:43:05.456791299 +0200
14203 +// SPDX-License-Identifier: GPL-2.0
14205 + * Copyright (C) 2005-2018 Junjiro R. Okajima
14207 + * This program, aufs is free software; you can redistribute it and/or modify
14208 + * it under the terms of the GNU General Public License as published by
14209 + * the Free Software Foundation; either version 2 of the License, or
14210 + * (at your option) any later version.
14212 + * This program is distributed in the hope that it will be useful,
14213 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14214 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14215 + * GNU General Public License for more details.
14217 + * You should have received a copy of the GNU General Public License
14218 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14222 + * handling file/dir, and address_space operation
14225 +#ifdef CONFIG_AUFS_DEBUG
14226 +#include <linux/migrate.h>
14228 +#include <linux/pagemap.h>
14231 +/* drop flags for writing */
14232 +unsigned int au_file_roflags(unsigned int flags)
14234 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14235 + flags |= O_RDONLY | O_NOATIME;
14239 +/* common functions to regular file and dir */
14240 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14241 + struct file *file, int force_wr)
14243 + struct file *h_file;
14244 + struct dentry *h_dentry;
14245 + struct inode *h_inode;
14246 + struct super_block *sb;
14247 + struct au_branch *br;
14248 + struct path h_path;
14251 + /* a race condition can happen between open and unlink/rmdir */
14252 + h_file = ERR_PTR(-ENOENT);
14253 + h_dentry = au_h_dptr(dentry, bindex);
14254 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14256 + h_inode = d_inode(h_dentry);
14257 + spin_lock(&h_dentry->d_lock);
14258 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14259 + /* || !d_inode(dentry)->i_nlink */
14261 + spin_unlock(&h_dentry->d_lock);
14262 + if (unlikely(err))
14265 + sb = dentry->d_sb;
14266 + br = au_sbr(sb, bindex);
14267 + err = au_br_test_oflag(flags, br);
14268 + h_file = ERR_PTR(err);
14269 + if (unlikely(err))
14272 + /* drop flags for writing */
14273 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14274 + if (force_wr && !(flags & O_WRONLY))
14276 + flags = au_file_roflags(flags);
14278 + h_file = ERR_PTR(-EROFS);
14279 + flags = au_file_roflags(flags);
14280 + if (unlikely(vfsub_native_ro(h_inode)
14281 + || IS_APPEND(h_inode)))
14283 + flags &= ~O_ACCMODE;
14284 + flags |= O_WRONLY;
14287 + flags &= ~O_CREAT;
14289 + h_path.dentry = h_dentry;
14290 + h_path.mnt = au_br_mnt(br);
14291 + h_file = vfsub_dentry_open(&h_path, flags);
14292 + if (IS_ERR(h_file))
14295 + if (flags & __FMODE_EXEC) {
14296 + err = deny_write_access(h_file);
14297 + if (unlikely(err)) {
14299 + h_file = ERR_PTR(err);
14303 + fsnotify_open(h_file);
14304 + goto out; /* success */
14312 +static int au_cmoo(struct dentry *dentry)
14314 + int err, cmoo, matched;
14315 + unsigned int udba;
14316 + struct path h_path;
14317 + struct au_pin pin;
14318 + struct au_cp_generic cpg = {
14319 + .dentry = dentry,
14324 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14326 + struct inode *delegated;
14327 + struct super_block *sb;
14328 + struct au_sbinfo *sbinfo;
14329 + struct au_fhsm *fhsm;
14331 + struct au_branch *br;
14332 + struct dentry *parent;
14333 + struct au_hinode *hdir;
14335 + DiMustWriteLock(dentry);
14336 + IiMustWriteLock(d_inode(dentry));
14339 + if (IS_ROOT(dentry))
14341 + cpg.bsrc = au_dbtop(dentry);
14345 + sb = dentry->d_sb;
14346 + sbinfo = au_sbi(sb);
14347 + fhsm = &sbinfo->si_fhsm;
14348 + pid = au_fhsm_pid(fhsm);
14351 + && (current->pid == pid
14352 + || rcu_dereference(current->real_parent)->pid == pid));
14353 + rcu_read_unlock();
14357 + br = au_sbr(sb, cpg.bsrc);
14358 + cmoo = au_br_cmoo(br->br_perm);
14361 + if (!d_is_reg(dentry))
14362 + cmoo &= AuBrAttr_COO_ALL;
14366 + parent = dget_parent(dentry);
14367 + di_write_lock_parent(parent);
14368 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14370 + if (unlikely(err < 0)) {
14371 + err = 0; /* there is no upper writable branch */
14374 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14376 + /* do not respect the coo attrib for the target branch */
14377 + err = au_cpup_dirs(dentry, cpg.bdst);
14378 + if (unlikely(err))
14381 + di_downgrade_lock(parent, AuLock_IR);
14382 + udba = au_opt_udba(sb);
14383 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14384 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14385 + if (unlikely(err))
14388 + err = au_sio_cpup_simple(&cpg);
14390 + if (unlikely(err))
14392 + if (!(cmoo & AuBrWAttr_MOO))
14393 + goto out_parent; /* success */
14395 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14396 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14397 + if (unlikely(err))
14400 + h_path.mnt = au_br_mnt(br);
14401 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14402 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14403 + delegated = NULL;
14404 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14406 + /* todo: keep h_dentry or not? */
14407 + if (unlikely(err == -EWOULDBLOCK)) {
14408 + pr_warn("cannot retry for NFSv4 delegation"
14409 + " for an internal unlink\n");
14412 + if (unlikely(err)) {
14413 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14417 + goto out_parent; /* success */
14420 + di_downgrade_lock(parent, AuLock_IR);
14422 + di_read_unlock(parent, AuLock_IR);
14429 +int au_do_open(struct file *file, struct au_do_open_args *args)
14431 + int err, aopen = args->aopen;
14432 + struct dentry *dentry;
14433 + struct au_finfo *finfo;
14436 + err = au_finfo_init(file, args->fidir);
14439 + err = au_finfo_init(file, args->fidir);
14442 + if (unlikely(err))
14445 + dentry = file->f_path.dentry;
14446 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14447 + di_write_lock_child(dentry);
14448 + err = au_cmoo(dentry);
14449 + di_downgrade_lock(dentry, AuLock_IR);
14452 + err = args->open(file, vfsub_file_flags(file), NULL);
14455 + err = args->open(file, vfsub_file_flags(file), NULL);
14459 + di_read_unlock(dentry, AuLock_IR);
14461 + finfo = au_fi(file);
14463 + finfo->fi_file = file;
14464 + au_hbl_add(&finfo->fi_hlist,
14465 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14468 + fi_write_unlock(file);
14471 + fi_write_unlock(file);
14474 + if (unlikely(err)) {
14475 + finfo->fi_hdir = NULL;
14476 + au_finfo_fin(file);
14484 +int au_reopen_nondir(struct file *file)
14487 + aufs_bindex_t btop;
14488 + struct dentry *dentry;
14489 + struct file *h_file, *h_file_tmp;
14491 + dentry = file->f_path.dentry;
14492 + btop = au_dbtop(dentry);
14493 + h_file_tmp = NULL;
14494 + if (au_fbtop(file) == btop) {
14495 + h_file = au_hf_top(file);
14496 + if (file->f_mode == h_file->f_mode)
14497 + return 0; /* success */
14498 + h_file_tmp = h_file;
14499 + get_file(h_file_tmp);
14500 + au_set_h_fptr(file, btop, NULL);
14502 + AuDebugOn(au_fi(file)->fi_hdir);
14505 + * file exists on both of rw and ro
14506 + * open --> dbtop and fbtop are both 0
14507 + * prepend a branch as rw, "rw" become ro
14509 + * delete the top branch, "rw" becomes rw again
14510 + * --> dbtop is 1, fbtop is still 0
14511 + * write --> fbtop is 0 but dbtop is 1
14513 + /* AuDebugOn(au_fbtop(file) < btop); */
14515 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14516 + file, /*force_wr*/0);
14517 + err = PTR_ERR(h_file);
14518 + if (IS_ERR(h_file)) {
14519 + if (h_file_tmp) {
14520 + au_sbr_get(dentry->d_sb, btop);
14521 + au_set_h_fptr(file, btop, h_file_tmp);
14522 + h_file_tmp = NULL;
14524 + goto out; /* todo: close all? */
14528 + au_set_fbtop(file, btop);
14529 + au_set_h_fptr(file, btop, h_file);
14530 + au_update_figen(file);
14531 + /* todo: necessary? */
14532 + /* file->f_ra = h_file->f_ra; */
14536 + fput(h_file_tmp);
14540 +/* ---------------------------------------------------------------------- */
14542 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14543 + struct dentry *hi_wh)
14546 + aufs_bindex_t btop;
14547 + struct au_dinfo *dinfo;
14548 + struct dentry *h_dentry;
14549 + struct au_hdentry *hdp;
14551 + dinfo = au_di(file->f_path.dentry);
14552 + AuRwMustWriteLock(&dinfo->di_rwsem);
14554 + btop = dinfo->di_btop;
14555 + dinfo->di_btop = btgt;
14556 + hdp = au_hdentry(dinfo, btgt);
14557 + h_dentry = hdp->hd_dentry;
14558 + hdp->hd_dentry = hi_wh;
14559 + err = au_reopen_nondir(file);
14560 + hdp->hd_dentry = h_dentry;
14561 + dinfo->di_btop = btop;
14566 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14567 + aufs_bindex_t bcpup, struct au_pin *pin)
14570 + struct inode *inode, *h_inode;
14571 + struct dentry *h_dentry, *hi_wh;
14572 + struct au_cp_generic cpg = {
14573 + .dentry = file->f_path.dentry,
14580 + au_update_dbtop(cpg.dentry);
14581 + inode = d_inode(cpg.dentry);
14583 + if (au_dbtop(cpg.dentry) <= bcpup
14584 + && au_dbbot(cpg.dentry) >= bcpup) {
14585 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14586 + if (h_dentry && d_is_positive(h_dentry))
14587 + h_inode = d_inode(h_dentry);
14589 + hi_wh = au_hi_wh(inode, bcpup);
14590 + if (!hi_wh && !h_inode)
14591 + err = au_sio_cpup_wh(&cpg, file);
14593 + /* already copied-up after unlink */
14594 + err = au_reopen_wh(file, bcpup, hi_wh);
14597 + && (inode->i_nlink > 1
14598 + || (inode->i_state & I_LINKABLE))
14599 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14600 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14606 + * prepare the @file for writing.
14608 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14611 + aufs_bindex_t dbtop;
14612 + struct dentry *parent;
14613 + struct inode *inode;
14614 + struct super_block *sb;
14615 + struct file *h_file;
14616 + struct au_cp_generic cpg = {
14617 + .dentry = file->f_path.dentry,
14622 + .flags = AuCpup_DTIME
14625 + sb = cpg.dentry->d_sb;
14626 + inode = d_inode(cpg.dentry);
14627 + cpg.bsrc = au_fbtop(file);
14628 + err = au_test_ro(sb, cpg.bsrc, inode);
14629 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14630 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14635 + /* need to cpup or reopen */
14636 + parent = dget_parent(cpg.dentry);
14637 + di_write_lock_parent(parent);
14638 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14640 + if (unlikely(err < 0))
14644 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14645 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14646 + if (unlikely(err))
14650 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14651 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14652 + if (unlikely(err))
14655 + dbtop = au_dbtop(cpg.dentry);
14656 + if (dbtop <= cpg.bdst)
14657 + cpg.bsrc = cpg.bdst;
14659 + if (dbtop <= cpg.bdst /* just reopen */
14660 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14662 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14663 + if (IS_ERR(h_file))
14664 + err = PTR_ERR(h_file);
14666 + di_downgrade_lock(parent, AuLock_IR);
14667 + if (dbtop > cpg.bdst)
14668 + err = au_sio_cpup_simple(&cpg);
14670 + err = au_reopen_nondir(file);
14671 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14673 + } else { /* copyup as wh and reopen */
14675 + * since writable hfsplus branch is not supported,
14676 + * h_open_pre/post() are unnecessary.
14678 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14679 + di_downgrade_lock(parent, AuLock_IR);
14683 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14684 + goto out_dput; /* success */
14690 + di_downgrade_lock(parent, AuLock_IR);
14692 + di_read_unlock(parent, AuLock_IR);
14699 +/* ---------------------------------------------------------------------- */
14701 +int au_do_flush(struct file *file, fl_owner_t id,
14702 + int (*flush)(struct file *file, fl_owner_t id))
14705 + struct super_block *sb;
14706 + struct inode *inode;
14708 + inode = file_inode(file);
14709 + sb = inode->i_sb;
14710 + si_noflush_read_lock(sb);
14711 + fi_read_lock(file);
14712 + ii_read_lock_child(inode);
14714 + err = flush(file, id);
14715 + au_cpup_attr_timesizes(inode);
14717 + ii_read_unlock(inode);
14718 + fi_read_unlock(file);
14719 + si_read_unlock(sb);
14723 +/* ---------------------------------------------------------------------- */
14725 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14728 + struct au_pin pin;
14729 + struct au_finfo *finfo;
14730 + struct dentry *parent, *hi_wh;
14731 + struct inode *inode;
14732 + struct super_block *sb;
14733 + struct au_cp_generic cpg = {
14734 + .dentry = file->f_path.dentry,
14739 + .flags = AuCpup_DTIME
14742 + FiMustWriteLock(file);
14745 + finfo = au_fi(file);
14746 + sb = cpg.dentry->d_sb;
14747 + inode = d_inode(cpg.dentry);
14748 + cpg.bdst = au_ibtop(inode);
14749 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14752 + parent = dget_parent(cpg.dentry);
14753 + if (au_test_ro(sb, cpg.bdst, inode)) {
14754 + di_read_lock_parent(parent, !AuLock_IR);
14755 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14757 + di_read_unlock(parent, !AuLock_IR);
14758 + if (unlikely(err < 0))
14763 + di_read_lock_parent(parent, AuLock_IR);
14764 + hi_wh = au_hi_wh(inode, cpg.bdst);
14765 + if (!S_ISDIR(inode->i_mode)
14766 + && au_opt_test(au_mntflags(sb), PLINK)
14767 + && au_plink_test(inode)
14768 + && !d_unhashed(cpg.dentry)
14769 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14770 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14771 + if (unlikely(err))
14774 + /* always superio. */
14775 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14776 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14778 + err = au_sio_cpup_simple(&cpg);
14781 + } else if (hi_wh) {
14782 + /* already copied-up after unlink */
14783 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14784 + *need_reopen = 0;
14788 + di_read_unlock(parent, AuLock_IR);
14795 +static void au_do_refresh_dir(struct file *file)
14797 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14798 + struct au_hfile *p, tmp, *q;
14799 + struct au_finfo *finfo;
14800 + struct super_block *sb;
14801 + struct au_fidir *fidir;
14803 + FiMustWriteLock(file);
14805 + sb = file->f_path.dentry->d_sb;
14806 + finfo = au_fi(file);
14807 + fidir = finfo->fi_hdir;
14808 + AuDebugOn(!fidir);
14809 + p = fidir->fd_hfile + finfo->fi_btop;
14810 + brid = p->hf_br->br_id;
14811 + bbot = fidir->fd_bbot;
14812 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14816 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14817 + if (new_bindex == bindex)
14819 + if (new_bindex < 0) {
14820 + au_set_h_fptr(file, bindex, NULL);
14824 + /* swap two lower inode, and loop again */
14825 + q = fidir->fd_hfile + new_bindex;
14829 + if (tmp.hf_file) {
14835 + p = fidir->fd_hfile;
14836 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14837 + bbot = au_sbbot(sb);
14838 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14839 + finfo->fi_btop++, p++)
14840 + if (p->hf_file) {
14841 + if (file_inode(p->hf_file))
14843 + au_hfput(p, /*execed*/0);
14846 + bbot = au_br_index(sb, brid);
14847 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14848 + finfo->fi_btop++, p++)
14850 + au_hfput(p, /*execed*/0);
14851 + bbot = au_sbbot(sb);
14854 + p = fidir->fd_hfile + bbot;
14855 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14856 + fidir->fd_bbot--, p--)
14857 + if (p->hf_file) {
14858 + if (file_inode(p->hf_file))
14860 + au_hfput(p, /*execed*/0);
14862 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14866 + * after branch manipulating, refresh the file.
14868 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14870 + int err, need_reopen, nbr;
14871 + aufs_bindex_t bbot, bindex;
14872 + struct dentry *dentry;
14873 + struct super_block *sb;
14874 + struct au_finfo *finfo;
14875 + struct au_hfile *hfile;
14877 + dentry = file->f_path.dentry;
14878 + sb = dentry->d_sb;
14879 + nbr = au_sbbot(sb) + 1;
14880 + finfo = au_fi(file);
14881 + if (!finfo->fi_hdir) {
14882 + hfile = &finfo->fi_htop;
14883 + AuDebugOn(!hfile->hf_file);
14884 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14885 + AuDebugOn(bindex < 0);
14886 + if (bindex != finfo->fi_btop)
14887 + au_set_fbtop(file, bindex);
14889 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14890 + if (unlikely(err))
14892 + au_do_refresh_dir(file);
14897 + if (!au_test_mmapped(file))
14898 + err = au_file_refresh_by_inode(file, &need_reopen);
14899 + if (finfo->fi_hdir)
14900 + /* harmless if err */
14901 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14902 + if (!err && need_reopen && !d_unlinked(dentry))
14903 + err = reopen(file);
14905 + au_update_figen(file);
14906 + goto out; /* success */
14909 + /* error, close all lower files */
14910 + if (finfo->fi_hdir) {
14911 + bbot = au_fbbot_dir(file);
14912 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14913 + au_set_h_fptr(file, bindex, NULL);
14920 +/* common function to regular file and dir */
14921 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14922 + int wlock, unsigned int fi_lsc)
14925 + unsigned int sigen, figen;
14926 + aufs_bindex_t btop;
14927 + unsigned char pseudo_link;
14928 + struct dentry *dentry;
14929 + struct inode *inode;
14932 + dentry = file->f_path.dentry;
14933 + inode = d_inode(dentry);
14934 + sigen = au_sigen(dentry->d_sb);
14935 + fi_write_lock_nested(file, fi_lsc);
14936 + figen = au_figen(file);
14938 + di_write_lock_child(dentry);
14940 + di_write_lock_child2(dentry);
14941 + btop = au_dbtop(dentry);
14942 + pseudo_link = (btop != au_ibtop(inode));
14943 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14945 + di_downgrade_lock(dentry, AuLock_IR);
14946 + fi_downgrade_lock(file);
14948 + goto out; /* success */
14951 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14952 + if (au_digen_test(dentry, sigen)) {
14953 + err = au_reval_dpath(dentry, sigen);
14954 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14958 + err = refresh_file(file, reopen);
14961 + di_downgrade_lock(dentry, AuLock_IR);
14962 + fi_downgrade_lock(file);
14965 + di_write_unlock(dentry);
14966 + fi_write_unlock(file);
14973 +/* ---------------------------------------------------------------------- */
14975 +/* cf. aufs_nopage() */
14976 +/* for madvise(2) */
14977 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14979 + unlock_page(page);
14983 +/* it will never be called, but necessary to support O_DIRECT */
14984 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14985 +{ BUG(); return 0; }
14987 +/* they will never be called. */
14988 +#ifdef CONFIG_AUFS_DEBUG
14989 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14990 + loff_t pos, unsigned len, unsigned flags,
14991 + struct page **pagep, void **fsdata)
14992 +{ AuUnsupport(); return 0; }
14993 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14994 + loff_t pos, unsigned len, unsigned copied,
14995 + struct page *page, void *fsdata)
14996 +{ AuUnsupport(); return 0; }
14997 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14998 +{ AuUnsupport(); return 0; }
15000 +static int aufs_set_page_dirty(struct page *page)
15001 +{ AuUnsupport(); return 0; }
15002 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
15003 + unsigned int length)
15004 +{ AuUnsupport(); }
15005 +static int aufs_releasepage(struct page *page, gfp_t gfp)
15006 +{ AuUnsupport(); return 0; }
15007 +#if 0 /* called by memory compaction regardless file */
15008 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
15009 + struct page *page, enum migrate_mode mode)
15010 +{ AuUnsupport(); return 0; }
15012 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
15013 +{ AuUnsupport(); return true; }
15014 +static void aufs_putback_page(struct page *page)
15015 +{ AuUnsupport(); }
15016 +static int aufs_launder_page(struct page *page)
15017 +{ AuUnsupport(); return 0; }
15018 +static int aufs_is_partially_uptodate(struct page *page,
15019 + unsigned long from,
15020 + unsigned long count)
15021 +{ AuUnsupport(); return 0; }
15022 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
15024 +{ AuUnsupport(); }
15025 +static int aufs_error_remove_page(struct address_space *mapping,
15026 + struct page *page)
15027 +{ AuUnsupport(); return 0; }
15028 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
15030 +{ AuUnsupport(); return 0; }
15031 +static void aufs_swap_deactivate(struct file *file)
15032 +{ AuUnsupport(); }
15033 +#endif /* CONFIG_AUFS_DEBUG */
15035 +const struct address_space_operations aufs_aop = {
15036 + .readpage = aufs_readpage,
15037 + .direct_IO = aufs_direct_IO,
15038 +#ifdef CONFIG_AUFS_DEBUG
15039 + .writepage = aufs_writepage,
15040 + /* no writepages, because of writepage */
15041 + .set_page_dirty = aufs_set_page_dirty,
15042 + /* no readpages, because of readpage */
15043 + .write_begin = aufs_write_begin,
15044 + .write_end = aufs_write_end,
15045 + /* no bmap, no block device */
15046 + .invalidatepage = aufs_invalidatepage,
15047 + .releasepage = aufs_releasepage,
15048 + /* is fallback_migrate_page ok? */
15049 + /* .migratepage = aufs_migratepage, */
15050 + .isolate_page = aufs_isolate_page,
15051 + .putback_page = aufs_putback_page,
15052 + .launder_page = aufs_launder_page,
15053 + .is_partially_uptodate = aufs_is_partially_uptodate,
15054 + .is_dirty_writeback = aufs_is_dirty_writeback,
15055 + .error_remove_page = aufs_error_remove_page,
15056 + .swap_activate = aufs_swap_activate,
15057 + .swap_deactivate = aufs_swap_deactivate
15058 +#endif /* CONFIG_AUFS_DEBUG */
15060 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
15061 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
15062 +++ linux/fs/aufs/file.h 2018-08-12 23:43:05.456791299 +0200
15064 +/* SPDX-License-Identifier: GPL-2.0 */
15066 + * Copyright (C) 2005-2018 Junjiro R. Okajima
15068 + * This program, aufs is free software; you can redistribute it and/or modify
15069 + * it under the terms of the GNU General Public License as published by
15070 + * the Free Software Foundation; either version 2 of the License, or
15071 + * (at your option) any later version.
15073 + * This program is distributed in the hope that it will be useful,
15074 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15075 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15076 + * GNU General Public License for more details.
15078 + * You should have received a copy of the GNU General Public License
15079 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15083 + * file operations
15086 +#ifndef __AUFS_FILE_H__
15087 +#define __AUFS_FILE_H__
15091 +#include <linux/file.h>
15092 +#include <linux/fs.h>
15093 +#include <linux/mm_types.h>
15094 +#include <linux/poll.h>
15095 +#include "rwsem.h"
15099 + struct file *hf_file;
15100 + struct au_branch *hf_br;
15105 + aufs_bindex_t fd_bbot;
15106 + aufs_bindex_t fd_nent;
15107 + struct au_vdir *fd_vdir_cache;
15108 + struct au_hfile fd_hfile[];
15111 +static inline int au_fidir_sz(int nent)
15113 + AuDebugOn(nent < 0);
15114 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
15118 + atomic_t fi_generation;
15120 + struct au_rwsem fi_rwsem;
15121 + aufs_bindex_t fi_btop;
15123 + /* do not union them */
15124 + struct { /* for non-dir */
15125 + struct au_hfile fi_htop;
15126 + atomic_t fi_mmapped;
15128 + struct au_fidir *fi_hdir; /* for dir only */
15130 + struct hlist_bl_node fi_hlist;
15131 + struct file *fi_file; /* very ugly */
15132 +} ____cacheline_aligned_in_smp;
15134 +/* ---------------------------------------------------------------------- */
15137 +extern const struct address_space_operations aufs_aop;
15138 +unsigned int au_file_roflags(unsigned int flags);
15139 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15140 + struct file *file, int force_wr);
15141 +struct au_do_open_args {
15143 + int (*open)(struct file *file, int flags,
15144 + struct file *h_file);
15145 + struct au_fidir *fidir;
15146 + struct file *h_file;
15148 +int au_do_open(struct file *file, struct au_do_open_args *args);
15149 +int au_reopen_nondir(struct file *file);
15151 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15152 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15153 + int wlock, unsigned int fi_lsc);
15154 +int au_do_flush(struct file *file, fl_owner_t id,
15155 + int (*flush)(struct file *file, fl_owner_t id));
15158 +#ifdef CONFIG_AUFS_POLL
15159 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15162 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15164 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15166 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15167 + struct file *h_file);
15169 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15170 + aufs_bindex_t bindex, int force_wr)
15171 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15172 + struct file *h_file);
15176 +extern const struct file_operations aufs_file_fop;
15177 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15178 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15179 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15182 +void au_hfput(struct au_hfile *hf, int execed);
15183 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15184 + struct file *h_file);
15186 +void au_update_figen(struct file *file);
15187 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15188 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15190 +void au_fi_init_once(void *_fi);
15191 +void au_finfo_fin(struct file *file);
15192 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15195 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15196 +#ifdef CONFIG_COMPAT
15197 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15198 + unsigned long arg);
15199 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15200 + unsigned long arg);
15203 +/* ---------------------------------------------------------------------- */
15205 +static inline struct au_finfo *au_fi(struct file *file)
15207 + return file->private_data;
15210 +/* ---------------------------------------------------------------------- */
15212 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15213 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15214 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15215 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15217 +#define fi_read_trylock_nested(f) \
15218 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15219 +#define fi_write_trylock_nested(f) \
15220 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15223 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15224 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15225 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15227 +/* lock subclass for finfo */
15233 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15235 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15238 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15240 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15244 + * fi_read_lock_1, fi_write_lock_1,
15245 + * fi_read_lock_2, fi_write_lock_2
15247 +#define AuReadLockFunc(name) \
15248 +static inline void fi_read_lock_##name(struct file *f) \
15249 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15251 +#define AuWriteLockFunc(name) \
15252 +static inline void fi_write_lock_##name(struct file *f) \
15253 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15255 +#define AuRWLockFuncs(name) \
15256 + AuReadLockFunc(name) \
15257 + AuWriteLockFunc(name)
15262 +#undef AuReadLockFunc
15263 +#undef AuWriteLockFunc
15264 +#undef AuRWLockFuncs
15266 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15267 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15268 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15270 +/* ---------------------------------------------------------------------- */
15272 +/* todo: hard/soft set? */
15273 +static inline aufs_bindex_t au_fbtop(struct file *file)
15275 + FiMustAnyLock(file);
15276 + return au_fi(file)->fi_btop;
15279 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15281 + FiMustAnyLock(file);
15282 + AuDebugOn(!au_fi(file)->fi_hdir);
15283 + return au_fi(file)->fi_hdir->fd_bbot;
15286 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15288 + FiMustAnyLock(file);
15289 + AuDebugOn(!au_fi(file)->fi_hdir);
15290 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15293 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15295 + FiMustWriteLock(file);
15296 + au_fi(file)->fi_btop = bindex;
15299 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15301 + FiMustWriteLock(file);
15302 + AuDebugOn(!au_fi(file)->fi_hdir);
15303 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15306 +static inline void au_set_fvdir_cache(struct file *file,
15307 + struct au_vdir *vdir_cache)
15309 + FiMustWriteLock(file);
15310 + AuDebugOn(!au_fi(file)->fi_hdir);
15311 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15314 +static inline struct file *au_hf_top(struct file *file)
15316 + FiMustAnyLock(file);
15317 + AuDebugOn(au_fi(file)->fi_hdir);
15318 + return au_fi(file)->fi_htop.hf_file;
15321 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15323 + FiMustAnyLock(file);
15324 + AuDebugOn(!au_fi(file)->fi_hdir);
15325 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15328 +/* todo: memory barrier? */
15329 +static inline unsigned int au_figen(struct file *f)
15331 + return atomic_read(&au_fi(f)->fi_generation);
15334 +static inline void au_set_mmapped(struct file *f)
15336 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15338 + pr_warn("fi_mmapped wrapped around\n");
15339 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15343 +static inline void au_unset_mmapped(struct file *f)
15345 + atomic_dec(&au_fi(f)->fi_mmapped);
15348 +static inline int au_test_mmapped(struct file *f)
15350 + return atomic_read(&au_fi(f)->fi_mmapped);
15353 +/* customize vma->vm_file */
15355 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15356 + struct file *file)
15360 + f = vma->vm_file;
15362 + vma->vm_file = file;
15367 +#define AuDbgVmRegion(file, vma) do {} while (0)
15369 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15370 + struct file *file)
15372 + au_do_vm_file_reset(vma, file);
15375 +#define AuDbgVmRegion(file, vma) \
15376 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15378 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15379 + struct file *file)
15383 + au_do_vm_file_reset(vma, file);
15384 + f = vma->vm_region->vm_file;
15386 + vma->vm_region->vm_file = file;
15389 +#endif /* CONFIG_MMU */
15391 +/* handle vma->vm_prfile */
15392 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15393 + struct file *file)
15396 + vma->vm_prfile = file;
15397 +#ifndef CONFIG_MMU
15399 + vma->vm_region->vm_prfile = file;
15403 +#endif /* __KERNEL__ */
15404 +#endif /* __AUFS_FILE_H__ */
15405 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15406 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15407 +++ linux/fs/aufs/finfo.c 2018-08-12 23:43:05.456791299 +0200
15409 +// SPDX-License-Identifier: GPL-2.0
15411 + * Copyright (C) 2005-2018 Junjiro R. Okajima
15413 + * This program, aufs is free software; you can redistribute it and/or modify
15414 + * it under the terms of the GNU General Public License as published by
15415 + * the Free Software Foundation; either version 2 of the License, or
15416 + * (at your option) any later version.
15418 + * This program is distributed in the hope that it will be useful,
15419 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15420 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15421 + * GNU General Public License for more details.
15423 + * You should have received a copy of the GNU General Public License
15424 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15428 + * file private data
15433 +void au_hfput(struct au_hfile *hf, int execed)
15436 + allow_write_access(hf->hf_file);
15437 + fput(hf->hf_file);
15438 + hf->hf_file = NULL;
15439 + au_br_put(hf->hf_br);
15440 + hf->hf_br = NULL;
15443 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15445 + struct au_finfo *finfo = au_fi(file);
15446 + struct au_hfile *hf;
15447 + struct au_fidir *fidir;
15449 + fidir = finfo->fi_hdir;
15451 + AuDebugOn(finfo->fi_btop != bindex);
15452 + hf = &finfo->fi_htop;
15454 + hf = fidir->fd_hfile + bindex;
15456 + if (hf && hf->hf_file)
15457 + au_hfput(hf, vfsub_file_execed(file));
15459 + FiMustWriteLock(file);
15460 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15461 + hf->hf_file = val;
15462 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15466 +void au_update_figen(struct file *file)
15468 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15469 + /* smp_mb(); */ /* atomic_set */
15472 +/* ---------------------------------------------------------------------- */
15474 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15476 + struct au_fidir *fidir;
15479 + nbr = au_sbbot(sb) + 1;
15481 + nbr = 2; /* initial allocate for 2 branches */
15482 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15484 + fidir->fd_bbot = -1;
15485 + fidir->fd_nent = nbr;
15491 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15494 + struct au_fidir *fidir, *p;
15496 + AuRwMustWriteLock(&finfo->fi_rwsem);
15497 + fidir = finfo->fi_hdir;
15498 + AuDebugOn(!fidir);
15501 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15502 + GFP_NOFS, may_shrink);
15504 + p->fd_nent = nbr;
15505 + finfo->fi_hdir = p;
15512 +/* ---------------------------------------------------------------------- */
15514 +void au_finfo_fin(struct file *file)
15516 + struct au_finfo *finfo;
15518 + au_nfiles_dec(file->f_path.dentry->d_sb);
15520 + finfo = au_fi(file);
15521 + AuDebugOn(finfo->fi_hdir);
15522 + AuRwDestroy(&finfo->fi_rwsem);
15523 + au_cache_free_finfo(finfo);
15526 +void au_fi_init_once(void *_finfo)
15528 + struct au_finfo *finfo = _finfo;
15530 + au_rw_init(&finfo->fi_rwsem);
15533 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15536 + struct au_finfo *finfo;
15537 + struct dentry *dentry;
15540 + dentry = file->f_path.dentry;
15541 + finfo = au_cache_alloc_finfo();
15542 + if (unlikely(!finfo))
15546 + au_nfiles_inc(dentry->d_sb);
15547 + au_rw_write_lock(&finfo->fi_rwsem);
15548 + finfo->fi_btop = -1;
15549 + finfo->fi_hdir = fidir;
15550 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15551 + /* smp_mb(); */ /* atomic_set */
15553 + file->private_data = finfo;
15558 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15559 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15560 +++ linux/fs/aufs/f_op.c 2018-08-12 23:43:05.456791299 +0200
15562 +// SPDX-License-Identifier: GPL-2.0
15564 + * Copyright (C) 2005-2018 Junjiro R. Okajima
15566 + * This program, aufs is free software; you can redistribute it and/or modify
15567 + * it under the terms of the GNU General Public License as published by
15568 + * the Free Software Foundation; either version 2 of the License, or
15569 + * (at your option) any later version.
15571 + * This program is distributed in the hope that it will be useful,
15572 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15573 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15574 + * GNU General Public License for more details.
15576 + * You should have received a copy of the GNU General Public License
15577 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15581 + * file and vm operations
15584 +#include <linux/aio.h>
15585 +#include <linux/fs_stack.h>
15586 +#include <linux/mman.h>
15587 +#include <linux/security.h>
15590 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15593 + aufs_bindex_t bindex;
15594 + struct dentry *dentry, *h_dentry;
15595 + struct au_finfo *finfo;
15596 + struct inode *h_inode;
15598 + FiMustWriteLock(file);
15601 + dentry = file->f_path.dentry;
15602 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15603 + finfo = au_fi(file);
15604 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15605 + atomic_set(&finfo->fi_mmapped, 0);
15606 + bindex = au_dbtop(dentry);
15608 + h_dentry = au_h_dptr(dentry, bindex);
15609 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15610 + if (unlikely(err))
15612 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15614 + h_dentry = h_file->f_path.dentry;
15615 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15616 + if (unlikely(err))
15618 + get_file(h_file);
15620 + if (IS_ERR(h_file))
15621 + err = PTR_ERR(h_file);
15623 + if ((flags & __O_TMPFILE)
15624 + && !(flags & O_EXCL)) {
15625 + h_inode = file_inode(h_file);
15626 + spin_lock(&h_inode->i_lock);
15627 + h_inode->i_state |= I_LINKABLE;
15628 + spin_unlock(&h_inode->i_lock);
15630 + au_set_fbtop(file, bindex);
15631 + au_set_h_fptr(file, bindex, h_file);
15632 + au_update_figen(file);
15633 + /* todo: necessary? */
15634 + /* file->f_ra = h_file->f_ra; */
15641 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15642 + struct file *file)
15645 + struct super_block *sb;
15646 + struct au_do_open_args args = {
15647 + .open = au_do_open_nondir
15650 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15651 + file, vfsub_file_flags(file), file->f_mode);
15653 + sb = file->f_path.dentry->d_sb;
15654 + si_read_lock(sb, AuLock_FLUSH);
15655 + err = au_do_open(file, &args);
15656 + si_read_unlock(sb);
15660 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15662 + struct au_finfo *finfo;
15663 + aufs_bindex_t bindex;
15665 + finfo = au_fi(file);
15666 + au_hbl_del(&finfo->fi_hlist,
15667 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15668 + bindex = finfo->fi_btop;
15670 + au_set_h_fptr(file, bindex, NULL);
15672 + au_finfo_fin(file);
15676 +/* ---------------------------------------------------------------------- */
15678 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15681 + struct file *h_file;
15684 + h_file = au_hf_top(file);
15686 + err = vfsub_flush(h_file, id);
15690 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15692 + return au_do_flush(file, id, au_do_flush_nondir);
15695 +/* ---------------------------------------------------------------------- */
15697 + * read and write functions acquire [fdi]_rwsem once, but release before
15698 + * mmap_sem. This is because to stop a race condition between mmap(2).
15699 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
15700 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15701 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15704 +/* Callers should call au_read_post() or fput() in the end */
15705 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15707 + struct file *h_file;
15710 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15712 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15713 + h_file = au_hf_top(file);
15714 + get_file(h_file);
15716 + fi_read_unlock(file);
15718 + h_file = ERR_PTR(err);
15723 +static void au_read_post(struct inode *inode, struct file *h_file)
15725 + /* update without lock, I don't think it a problem */
15726 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15730 +struct au_write_pre {
15732 + unsigned int lsc;
15736 + aufs_bindex_t btop;
15740 + * return with iinfo is write-locked
15741 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15744 +static struct file *au_write_pre(struct file *file, int do_ready,
15745 + struct au_write_pre *wpre)
15747 + struct file *h_file;
15748 + struct dentry *dentry;
15750 + unsigned int lsc;
15751 + struct au_pin pin;
15756 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15757 + h_file = ERR_PTR(err);
15758 + if (unlikely(err))
15761 + dentry = file->f_path.dentry;
15763 + err = au_ready_to_write(file, -1, &pin);
15764 + if (unlikely(err)) {
15765 + h_file = ERR_PTR(err);
15766 + di_write_unlock(dentry);
15771 + di_downgrade_lock(dentry, /*flags*/0);
15773 + wpre->btop = au_fbtop(file);
15774 + h_file = au_hf_top(file);
15775 + get_file(h_file);
15777 + wpre->blks = file_inode(h_file)->i_blocks;
15780 + di_read_unlock(dentry, /*flags*/0);
15783 + fi_write_unlock(file);
15788 +static void au_write_post(struct inode *inode, struct file *h_file,
15789 + struct au_write_pre *wpre, ssize_t written)
15791 + struct inode *h_inode;
15793 + au_cpup_attr_timesizes(inode);
15794 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15795 + h_inode = file_inode(h_file);
15796 + inode->i_mode = h_inode->i_mode;
15797 + ii_write_unlock(inode);
15798 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15800 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15801 + /*force*/h_inode->i_blocks > wpre->blks);
15805 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
15809 + struct inode *inode;
15810 + struct file *h_file;
15811 + struct super_block *sb;
15813 + inode = file_inode(file);
15814 + sb = inode->i_sb;
15815 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15817 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15818 + err = PTR_ERR(h_file);
15819 + if (IS_ERR(h_file))
15822 + /* filedata may be obsoleted by concurrent copyup, but no problem */
15823 + err = vfsub_read_u(h_file, buf, count, ppos);
15824 + /* todo: necessary? */
15825 + /* file->f_ra = h_file->f_ra; */
15826 + au_read_post(inode, h_file);
15829 + si_read_unlock(sb);
15834 + * todo: very ugly
15835 + * it locks both of i_mutex and si_rwsem for read in safe.
15836 + * if the plink maintenance mode continues forever (that is the problem),
15837 + * may loop forever.
15839 +static void au_mtx_and_read_lock(struct inode *inode)
15842 + struct super_block *sb = inode->i_sb;
15845 + inode_lock(inode);
15846 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15849 + inode_unlock(inode);
15850 + si_read_lock(sb, AuLock_NOPLMW);
15851 + si_read_unlock(sb);
15855 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
15856 + size_t count, loff_t *ppos)
15859 + struct au_write_pre wpre;
15860 + struct inode *inode;
15861 + struct file *h_file;
15862 + char __user *buf = (char __user *)ubuf;
15864 + inode = file_inode(file);
15865 + au_mtx_and_read_lock(inode);
15868 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15869 + err = PTR_ERR(h_file);
15870 + if (IS_ERR(h_file))
15873 + err = vfsub_write_u(h_file, buf, count, ppos);
15874 + au_write_post(inode, h_file, &wpre, err);
15877 + si_read_unlock(inode->i_sb);
15878 + inode_unlock(inode);
15882 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15883 + struct iov_iter *iov_iter)
15886 + struct file *file;
15887 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15889 + err = security_file_permission(h_file, rw);
15890 + if (unlikely(err))
15895 + if (rw == MAY_READ)
15896 + iter = h_file->f_op->read_iter;
15897 + else if (rw == MAY_WRITE)
15898 + iter = h_file->f_op->write_iter;
15900 + file = kio->ki_filp;
15901 + kio->ki_filp = h_file;
15904 + err = iter(kio, iov_iter);
15907 + /* currently there is no such fs */
15909 + kio->ki_filp = file;
15915 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15918 + struct file *file, *h_file;
15919 + struct inode *inode;
15920 + struct super_block *sb;
15922 + file = kio->ki_filp;
15923 + inode = file_inode(file);
15924 + sb = inode->i_sb;
15925 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15927 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15928 + err = PTR_ERR(h_file);
15929 + if (IS_ERR(h_file))
15932 + if (au_test_loopback_kthread()) {
15933 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15934 + if (file->f_mapping != h_file->f_mapping) {
15935 + file->f_mapping = h_file->f_mapping;
15936 + smp_mb(); /* unnecessary? */
15939 + fi_read_unlock(file);
15941 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15942 + /* todo: necessary? */
15943 + /* file->f_ra = h_file->f_ra; */
15944 + au_read_post(inode, h_file);
15947 + si_read_unlock(sb);
15951 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15954 + struct au_write_pre wpre;
15955 + struct inode *inode;
15956 + struct file *file, *h_file;
15958 + file = kio->ki_filp;
15959 + inode = file_inode(file);
15960 + au_mtx_and_read_lock(inode);
15963 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15964 + err = PTR_ERR(h_file);
15965 + if (IS_ERR(h_file))
15968 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15969 + au_write_post(inode, h_file, &wpre, err);
15972 + si_read_unlock(inode->i_sb);
15973 + inode_unlock(inode);
15977 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15978 + struct pipe_inode_info *pipe, size_t len,
15979 + unsigned int flags)
15982 + struct file *h_file;
15983 + struct inode *inode;
15984 + struct super_block *sb;
15986 + inode = file_inode(file);
15987 + sb = inode->i_sb;
15988 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15990 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15991 + err = PTR_ERR(h_file);
15992 + if (IS_ERR(h_file))
15995 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15996 + /* todo: necessasry? */
15997 + /* file->f_ra = h_file->f_ra; */
15998 + au_read_post(inode, h_file);
16001 + si_read_unlock(sb);
16006 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
16007 + size_t len, unsigned int flags)
16010 + struct au_write_pre wpre;
16011 + struct inode *inode;
16012 + struct file *h_file;
16014 + inode = file_inode(file);
16015 + au_mtx_and_read_lock(inode);
16018 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16019 + err = PTR_ERR(h_file);
16020 + if (IS_ERR(h_file))
16023 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
16024 + au_write_post(inode, h_file, &wpre, err);
16027 + si_read_unlock(inode->i_sb);
16028 + inode_unlock(inode);
16032 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
16036 + struct au_write_pre wpre;
16037 + struct inode *inode;
16038 + struct file *h_file;
16040 + inode = file_inode(file);
16041 + au_mtx_and_read_lock(inode);
16044 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16045 + err = PTR_ERR(h_file);
16046 + if (IS_ERR(h_file))
16050 + err = vfs_fallocate(h_file, mode, offset, len);
16052 + au_write_post(inode, h_file, &wpre, /*written*/1);
16055 + si_read_unlock(inode->i_sb);
16056 + inode_unlock(inode);
16060 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
16061 + struct file *dst, loff_t dst_pos,
16062 + size_t len, unsigned int flags)
16065 + struct au_write_pre wpre;
16066 + enum { SRC, DST };
16068 + struct inode *inode;
16069 + struct file *h_file;
16070 + struct super_block *h_sb;
16072 +#define a_src a[SRC]
16073 +#define a_dst a[DST]
16076 + a_src.inode = file_inode(src);
16077 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
16079 + a_dst.inode = file_inode(dst);
16080 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
16083 + au_mtx_and_read_lock(a_dst.inode);
16085 + * in order to match the order in di_write_lock2_{child,parent}(),
16086 + * use f_path.dentry for this comparision.
16088 + if (src->f_path.dentry < dst->f_path.dentry) {
16089 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
16090 + err = PTR_ERR(a_src.h_file);
16091 + if (IS_ERR(a_src.h_file))
16094 + wpre.lsc = AuLsc_FI_2;
16095 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16096 + err = PTR_ERR(a_dst.h_file);
16097 + if (IS_ERR(a_dst.h_file)) {
16098 + au_read_post(a_src.inode, a_src.h_file);
16102 + wpre.lsc = AuLsc_FI_1;
16103 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16104 + err = PTR_ERR(a_dst.h_file);
16105 + if (IS_ERR(a_dst.h_file))
16108 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
16109 + err = PTR_ERR(a_src.h_file);
16110 + if (IS_ERR(a_src.h_file)) {
16111 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
16118 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
16119 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
16120 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
16126 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
16127 + dst_pos, len, flags);
16130 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
16131 + fi_read_unlock(src);
16132 + au_read_post(a_src.inode, a_src.h_file);
16134 + si_read_unlock(a_dst.inode->i_sb);
16135 + inode_unlock(a_dst.inode);
16142 +/* ---------------------------------------------------------------------- */
16145 + * The locking order around current->mmap_sem.
16146 + * - in most and regular cases
16147 + * file I/O syscall -- aufs_read() or something
16148 + * -- si_rwsem for read -- mmap_sem
16149 + * (Note that [fdi]i_rwsem are released before mmap_sem).
16151 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
16152 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
16153 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
16154 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
16155 + * It means that when aufs acquires si_rwsem for write, the process should never
16156 + * acquire mmap_sem.
16158 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
16159 + * problem either since any directory is not able to be mmap-ed.
16160 + * The similar scenario is applied to aufs_readlink() too.
16163 +#if 0 /* stop calling security_file_mmap() */
16164 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
16165 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
16167 +static unsigned long au_arch_prot_conv(unsigned long flags)
16169 + /* currently ppc64 only */
16170 +#ifdef CONFIG_PPC64
16171 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16172 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16173 + return AuConv_VM_PROT(flags, SAO);
16175 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16180 +static unsigned long au_prot_conv(unsigned long flags)
16182 + return AuConv_VM_PROT(flags, READ)
16183 + | AuConv_VM_PROT(flags, WRITE)
16184 + | AuConv_VM_PROT(flags, EXEC)
16185 + | au_arch_prot_conv(flags);
16188 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16189 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16191 +static unsigned long au_flag_conv(unsigned long flags)
16193 + return AuConv_VM_MAP(flags, GROWSDOWN)
16194 + | AuConv_VM_MAP(flags, DENYWRITE)
16195 + | AuConv_VM_MAP(flags, LOCKED);
16199 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16202 + const unsigned char wlock
16203 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16204 + struct super_block *sb;
16205 + struct file *h_file;
16206 + struct inode *inode;
16208 + AuDbgVmRegion(file, vma);
16210 + inode = file_inode(file);
16211 + sb = inode->i_sb;
16213 + si_read_lock(sb, AuLock_NOPLMW);
16215 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16217 + err = PTR_ERR(h_file);
16218 + if (IS_ERR(h_file))
16222 + au_set_mmapped(file);
16223 + au_vm_file_reset(vma, h_file);
16225 + * we cannot call security_mmap_file() here since it may acquire
16226 + * mmap_sem or i_mutex.
16228 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16229 + * au_flag_conv(vma->vm_flags));
16232 + err = call_mmap(h_file, vma);
16234 + au_vm_prfile_set(vma, file);
16235 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16236 + goto out_fput; /* success */
16238 + au_unset_mmapped(file);
16239 + au_vm_file_reset(vma, file);
16243 + ii_write_unlock(inode);
16248 + si_read_unlock(sb);
16254 +/* ---------------------------------------------------------------------- */
16256 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16260 + struct au_write_pre wpre;
16261 + struct inode *inode;
16262 + struct file *h_file;
16264 + err = 0; /* -EBADF; */ /* posix? */
16265 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16268 + inode = file_inode(file);
16269 + au_mtx_and_read_lock(inode);
16272 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16273 + err = PTR_ERR(h_file);
16274 + if (IS_ERR(h_file))
16277 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16278 + au_write_post(inode, h_file, &wpre, /*written*/0);
16281 + si_read_unlock(inode->i_sb);
16282 + inode_unlock(inode);
16287 +static int aufs_fasync(int fd, struct file *file, int flag)
16290 + struct file *h_file;
16291 + struct super_block *sb;
16293 + sb = file->f_path.dentry->d_sb;
16294 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16296 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16297 + err = PTR_ERR(h_file);
16298 + if (IS_ERR(h_file))
16301 + if (h_file->f_op->fasync)
16302 + err = h_file->f_op->fasync(fd, h_file, flag);
16303 + fput(h_file); /* instead of au_read_post() */
16306 + si_read_unlock(sb);
16310 +static int aufs_setfl(struct file *file, unsigned long arg)
16313 + struct file *h_file;
16314 + struct super_block *sb;
16316 + sb = file->f_path.dentry->d_sb;
16317 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16319 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16320 + err = PTR_ERR(h_file);
16321 + if (IS_ERR(h_file))
16324 + /* stop calling h_file->fasync */
16325 + arg |= vfsub_file_flags(file) & FASYNC;
16326 + err = setfl(/*unused fd*/-1, h_file, arg);
16327 + fput(h_file); /* instead of au_read_post() */
16330 + si_read_unlock(sb);
16334 +/* ---------------------------------------------------------------------- */
16336 +/* no one supports this operation, currently */
16338 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16339 + size_t len, loff_t *pos, int more)
16344 +/* ---------------------------------------------------------------------- */
16346 +const struct file_operations aufs_file_fop = {
16347 + .owner = THIS_MODULE,
16349 + .llseek = default_llseek,
16351 + .read = aufs_read,
16352 + .write = aufs_write,
16353 + .read_iter = aufs_read_iter,
16354 + .write_iter = aufs_write_iter,
16356 +#ifdef CONFIG_AUFS_POLL
16357 + .poll = aufs_poll,
16359 + .unlocked_ioctl = aufs_ioctl_nondir,
16360 +#ifdef CONFIG_COMPAT
16361 + .compat_ioctl = aufs_compat_ioctl_nondir,
16363 + .mmap = aufs_mmap,
16364 + .open = aufs_open_nondir,
16365 + .flush = aufs_flush_nondir,
16366 + .release = aufs_release_nondir,
16367 + .fsync = aufs_fsync_nondir,
16368 + .fasync = aufs_fasync,
16369 + /* .sendpage = aufs_sendpage, */
16370 + .setfl = aufs_setfl,
16371 + .splice_write = aufs_splice_write,
16372 + .splice_read = aufs_splice_read,
16374 + .aio_splice_write = aufs_aio_splice_write,
16375 + .aio_splice_read = aufs_aio_splice_read,
16377 + .fallocate = aufs_fallocate,
16378 + .copy_file_range = aufs_copy_file_range
16380 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16381 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16382 +++ linux/fs/aufs/fstype.h 2018-08-12 23:43:05.456791299 +0200
16384 +/* SPDX-License-Identifier: GPL-2.0 */
16386 + * Copyright (C) 2005-2018 Junjiro R. Okajima
16388 + * This program, aufs is free software; you can redistribute it and/or modify
16389 + * it under the terms of the GNU General Public License as published by
16390 + * the Free Software Foundation; either version 2 of the License, or
16391 + * (at your option) any later version.
16393 + * This program is distributed in the hope that it will be useful,
16394 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16395 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16396 + * GNU General Public License for more details.
16398 + * You should have received a copy of the GNU General Public License
16399 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16403 + * judging filesystem type
16406 +#ifndef __AUFS_FSTYPE_H__
16407 +#define __AUFS_FSTYPE_H__
16411 +#include <linux/fs.h>
16412 +#include <linux/magic.h>
16413 +#include <linux/nfs_fs.h>
16414 +#include <linux/romfs_fs.h>
16416 +static inline int au_test_aufs(struct super_block *sb)
16418 + return sb->s_magic == AUFS_SUPER_MAGIC;
16421 +static inline const char *au_sbtype(struct super_block *sb)
16423 + return sb->s_type->name;
16426 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16428 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16429 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16435 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16437 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16438 + return sb->s_magic == ROMFS_MAGIC;
16444 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16446 +#if IS_ENABLED(CONFIG_CRAMFS)
16447 + return sb->s_magic == CRAMFS_MAGIC;
16452 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16454 +#if IS_ENABLED(CONFIG_NFS_FS)
16455 + return sb->s_magic == NFS_SUPER_MAGIC;
16461 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16463 +#if IS_ENABLED(CONFIG_FUSE_FS)
16464 + return sb->s_magic == FUSE_SUPER_MAGIC;
16470 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16472 +#if IS_ENABLED(CONFIG_XFS_FS)
16473 + return sb->s_magic == XFS_SB_MAGIC;
16479 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16481 +#ifdef CONFIG_TMPFS
16482 + return sb->s_magic == TMPFS_MAGIC;
16488 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16490 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16491 + return !strcmp(au_sbtype(sb), "ecryptfs");
16497 +static inline int au_test_ramfs(struct super_block *sb)
16499 + return sb->s_magic == RAMFS_MAGIC;
16502 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16504 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16505 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16511 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16513 +#ifdef CONFIG_PROC_FS
16514 + return sb->s_magic == PROC_SUPER_MAGIC;
16520 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16522 +#ifdef CONFIG_SYSFS
16523 + return sb->s_magic == SYSFS_MAGIC;
16529 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16531 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16532 + return sb->s_magic == CONFIGFS_MAGIC;
16538 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16540 +#if IS_ENABLED(CONFIG_MINIX_FS)
16541 + return sb->s_magic == MINIX3_SUPER_MAGIC
16542 + || sb->s_magic == MINIX2_SUPER_MAGIC
16543 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16544 + || sb->s_magic == MINIX_SUPER_MAGIC
16545 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16551 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16553 +#if IS_ENABLED(CONFIG_FAT_FS)
16554 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16560 +static inline int au_test_msdos(struct super_block *sb)
16562 + return au_test_fat(sb);
16565 +static inline int au_test_vfat(struct super_block *sb)
16567 + return au_test_fat(sb);
16570 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16572 +#ifdef CONFIG_SECURITYFS
16573 + return sb->s_magic == SECURITYFS_MAGIC;
16579 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16581 +#if IS_ENABLED(CONFIG_SQUASHFS)
16582 + return sb->s_magic == SQUASHFS_MAGIC;
16588 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16590 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16591 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16597 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16599 +#if IS_ENABLED(CONFIG_XENFS)
16600 + return sb->s_magic == XENFS_SUPER_MAGIC;
16606 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16608 +#ifdef CONFIG_DEBUG_FS
16609 + return sb->s_magic == DEBUGFS_MAGIC;
16615 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16617 +#if IS_ENABLED(CONFIG_NILFS)
16618 + return sb->s_magic == NILFS_SUPER_MAGIC;
16624 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16626 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16627 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16633 +/* ---------------------------------------------------------------------- */
16635 + * they can't be an aufs branch.
16637 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16640 +#ifndef CONFIG_AUFS_BR_RAMFS
16641 + au_test_ramfs(sb) ||
16643 + au_test_procfs(sb)
16644 + || au_test_sysfs(sb)
16645 + || au_test_configfs(sb)
16646 + || au_test_debugfs(sb)
16647 + || au_test_securityfs(sb)
16648 + || au_test_xenfs(sb)
16649 + || au_test_ecryptfs(sb)
16650 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16651 + || au_test_aufs(sb); /* will be supported in next version */
16654 +static inline int au_test_fs_remote(struct super_block *sb)
16656 + return !au_test_tmpfs(sb)
16657 +#ifdef CONFIG_AUFS_BR_RAMFS
16658 + && !au_test_ramfs(sb)
16660 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16663 +/* ---------------------------------------------------------------------- */
16666 + * Note: these functions (below) are created after reading ->getattr() in all
16667 + * filesystems under linux/fs. it means we have to do so in every update...
16671 + * some filesystems require getattr to refresh the inode attributes before
16673 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16674 + * and leave the work for d_revalidate()
16676 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16678 + return au_test_nfs(sb)
16679 + || au_test_fuse(sb)
16680 + /* || au_test_btrfs(sb) */ /* untested */
16685 + * filesystems which don't maintain i_size or i_blocks.
16687 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16689 + return au_test_xfs(sb)
16690 + || au_test_btrfs(sb)
16691 + || au_test_ubifs(sb)
16692 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16693 + /* || au_test_minix(sb) */ /* untested */
16698 + * filesystems which don't store the correct value in some of their inode
16701 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16703 + return au_test_fs_bad_iattr_size(sb)
16704 + || au_test_fat(sb)
16705 + || au_test_msdos(sb)
16706 + || au_test_vfat(sb);
16709 +/* they don't check i_nlink in link(2) */
16710 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16712 + return au_test_tmpfs(sb)
16713 +#ifdef CONFIG_AUFS_BR_RAMFS
16714 + || au_test_ramfs(sb)
16716 + || au_test_ubifs(sb)
16717 + || au_test_hfsplus(sb);
16721 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16723 +static inline int au_test_fs_notime(struct super_block *sb)
16725 + return au_test_nfs(sb)
16726 + || au_test_fuse(sb)
16727 + || au_test_ubifs(sb)
16731 +/* temporary support for i#1 in cramfs */
16732 +static inline int au_test_fs_unique_ino(struct inode *inode)
16734 + if (au_test_cramfs(inode->i_sb))
16735 + return inode->i_ino != 1;
16739 +/* ---------------------------------------------------------------------- */
16742 + * the filesystem where the xino files placed must support i/o after unlink and
16743 + * maintain i_size and i_blocks.
16745 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16747 + return au_test_fs_remote(sb)
16748 + || au_test_fs_bad_iattr_size(sb)
16749 + /* don't want unnecessary work for xino */
16750 + || au_test_aufs(sb)
16751 + || au_test_ecryptfs(sb)
16752 + || au_test_nilfs(sb);
16755 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16757 + return au_test_tmpfs(sb)
16758 + || au_test_ramfs(sb);
16762 + * test if the @sb is real-readonly.
16764 +static inline int au_test_fs_rr(struct super_block *sb)
16766 + return au_test_squashfs(sb)
16767 + || au_test_iso9660(sb)
16768 + || au_test_cramfs(sb)
16769 + || au_test_romfs(sb);
16773 + * test if the @inode is nfs with 'noacl' option
16774 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16776 +static inline int au_test_nfs_noacl(struct inode *inode)
16778 + return au_test_nfs(inode->i_sb)
16779 + /* && IS_POSIXACL(inode) */
16780 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16783 +#endif /* __KERNEL__ */
16784 +#endif /* __AUFS_FSTYPE_H__ */
16785 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16786 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16787 +++ linux/fs/aufs/hbl.h 2018-08-12 23:43:05.456791299 +0200
16789 +/* SPDX-License-Identifier: GPL-2.0 */
16791 + * Copyright (C) 2017-2018 Junjiro R. Okajima
16793 + * This program, aufs is free software; you can redistribute it and/or modify
16794 + * it under the terms of the GNU General Public License as published by
16795 + * the Free Software Foundation; either version 2 of the License, or
16796 + * (at your option) any later version.
16798 + * This program is distributed in the hope that it will be useful,
16799 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16800 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16801 + * GNU General Public License for more details.
16803 + * You should have received a copy of the GNU General Public License
16804 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16808 + * helpers for hlist_bl.h
16811 +#ifndef __AUFS_HBL_H__
16812 +#define __AUFS_HBL_H__
16816 +#include <linux/list_bl.h>
16818 +static inline void au_hbl_add(struct hlist_bl_node *node,
16819 + struct hlist_bl_head *hbl)
16821 + hlist_bl_lock(hbl);
16822 + hlist_bl_add_head(node, hbl);
16823 + hlist_bl_unlock(hbl);
16826 +static inline void au_hbl_del(struct hlist_bl_node *node,
16827 + struct hlist_bl_head *hbl)
16829 + hlist_bl_lock(hbl);
16830 + hlist_bl_del(node);
16831 + hlist_bl_unlock(hbl);
16834 +#define au_hbl_for_each(pos, head) \
16835 + for (pos = hlist_bl_first(head); \
16839 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16841 + unsigned long cnt;
16842 + struct hlist_bl_node *pos;
16845 + hlist_bl_lock(hbl);
16846 + au_hbl_for_each(pos, hbl)
16848 + hlist_bl_unlock(hbl);
16852 +#endif /* __KERNEL__ */
16853 +#endif /* __AUFS_HBL_H__ */
16854 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16855 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16856 +++ linux/fs/aufs/hfsnotify.c 2018-08-12 23:43:05.456791299 +0200
16858 +// SPDX-License-Identifier: GPL-2.0
16860 + * Copyright (C) 2005-2018 Junjiro R. Okajima
16862 + * This program, aufs is free software; you can redistribute it and/or modify
16863 + * it under the terms of the GNU General Public License as published by
16864 + * the Free Software Foundation; either version 2 of the License, or
16865 + * (at your option) any later version.
16867 + * This program is distributed in the hope that it will be useful,
16868 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16869 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16870 + * GNU General Public License for more details.
16872 + * You should have received a copy of the GNU General Public License
16873 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16877 + * fsnotify for the lower directories
16882 +/* FS_IN_IGNORED is unnecessary */
16883 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16884 + | FS_CREATE | FS_EVENT_ON_CHILD);
16885 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16886 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16888 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16890 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16892 + /* AuDbg("here\n"); */
16893 + au_cache_free_hnotify(hn);
16894 + smp_mb__before_atomic(); /* for atomic64_dec */
16895 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16896 + wake_up(&au_hfsn_wq);
16899 +static int au_hfsn_alloc(struct au_hinode *hinode)
16902 + struct au_hnotify *hn;
16903 + struct super_block *sb;
16904 + struct au_branch *br;
16905 + struct fsnotify_mark *mark;
16906 + aufs_bindex_t bindex;
16908 + hn = hinode->hi_notify;
16909 + sb = hn->hn_aufs_inode->i_sb;
16910 + bindex = au_br_index(sb, hinode->hi_id);
16911 + br = au_sbr(sb, bindex);
16912 + AuDebugOn(!br->br_hfsn);
16914 + mark = &hn->hn_mark;
16915 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16916 + mark->mask = AuHfsnMask;
16918 + * by udba rename or rmdir, aufs assign a new inode to the known
16919 + * h_inode, so specify 1 to allow dups.
16922 + err = fsnotify_add_mark(mark, hinode->hi_inode, /*mnt*/NULL,
16923 + /*allow_dups*/1);
16929 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16931 + struct fsnotify_mark *mark;
16932 + unsigned long long ull;
16933 + struct fsnotify_group *group;
16935 + ull = atomic64_inc_return(&au_hfsn_ifree);
16938 + mark = &hn->hn_mark;
16939 + spin_lock(&mark->lock);
16940 + group = mark->group;
16941 + fsnotify_get_group(group);
16942 + spin_unlock(&mark->lock);
16944 + fsnotify_destroy_mark(mark, group);
16945 + fsnotify_put_mark(mark);
16946 + fsnotify_put_group(group);
16949 + /* free hn by myself */
16953 +/* ---------------------------------------------------------------------- */
16955 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16957 + struct fsnotify_mark *mark;
16959 + mark = &hinode->hi_notify->hn_mark;
16960 + spin_lock(&mark->lock);
16962 + AuDebugOn(mark->mask & AuHfsnMask);
16963 + mark->mask |= AuHfsnMask;
16965 + AuDebugOn(!(mark->mask & AuHfsnMask));
16966 + mark->mask &= ~AuHfsnMask;
16968 + spin_unlock(&mark->lock);
16969 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16972 +/* ---------------------------------------------------------------------- */
16974 +/* #define AuDbgHnotify */
16975 +#ifdef AuDbgHnotify
16976 +static char *au_hfsn_name(u32 mask)
16978 +#ifdef CONFIG_AUFS_DEBUG
16979 +#define test_ret(flag) \
16981 + if (mask & flag) \
16984 + test_ret(FS_ACCESS);
16985 + test_ret(FS_MODIFY);
16986 + test_ret(FS_ATTRIB);
16987 + test_ret(FS_CLOSE_WRITE);
16988 + test_ret(FS_CLOSE_NOWRITE);
16989 + test_ret(FS_OPEN);
16990 + test_ret(FS_MOVED_FROM);
16991 + test_ret(FS_MOVED_TO);
16992 + test_ret(FS_CREATE);
16993 + test_ret(FS_DELETE);
16994 + test_ret(FS_DELETE_SELF);
16995 + test_ret(FS_MOVE_SELF);
16996 + test_ret(FS_UNMOUNT);
16997 + test_ret(FS_Q_OVERFLOW);
16998 + test_ret(FS_IN_IGNORED);
16999 + test_ret(FS_ISDIR);
17000 + test_ret(FS_IN_ONESHOT);
17001 + test_ret(FS_EVENT_ON_CHILD);
17010 +/* ---------------------------------------------------------------------- */
17012 +static void au_hfsn_free_group(struct fsnotify_group *group)
17014 + struct au_br_hfsnotify *hfsn = group->private;
17016 + /* AuDbg("here\n"); */
17020 +static int au_hfsn_handle_event(struct fsnotify_group *group,
17021 + struct inode *inode,
17022 + u32 mask, const void *data, int data_type,
17023 + const unsigned char *file_name, u32 cookie,
17024 + struct fsnotify_iter_info *iter_info)
17027 + struct au_hnotify *hnotify;
17028 + struct inode *h_dir, *h_inode;
17029 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
17030 + struct fsnotify_mark *inode_mark;
17032 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
17035 + /* if FS_UNMOUNT happens, there must be another bug */
17036 + AuDebugOn(mask & FS_UNMOUNT);
17037 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
17042 +#ifdef AuDbgHnotify
17044 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
17045 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
17046 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
17047 + h_dir->i_ino, mask, au_hfsn_name(mask),
17048 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
17049 + /* WARN_ON(1); */
17054 + inode_mark = fsnotify_iter_inode_mark(iter_info);
17055 + AuDebugOn(!inode_mark);
17056 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
17057 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
17063 +static struct fsnotify_ops au_hfsn_ops = {
17064 + .handle_event = au_hfsn_handle_event,
17065 + .free_group_priv = au_hfsn_free_group,
17066 + .free_mark = au_hfsn_free_mark
17069 +/* ---------------------------------------------------------------------- */
17071 +static void au_hfsn_fin_br(struct au_branch *br)
17073 + struct au_br_hfsnotify *hfsn;
17075 + hfsn = br->br_hfsn;
17078 + fsnotify_put_group(hfsn->hfsn_group);
17083 +static int au_hfsn_init_br(struct au_branch *br, int perm)
17086 + struct fsnotify_group *group;
17087 + struct au_br_hfsnotify *hfsn;
17090 + br->br_hfsn = NULL;
17091 + if (!au_br_hnotifyable(perm))
17095 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
17096 + if (unlikely(!hfsn))
17100 + group = fsnotify_alloc_group(&au_hfsn_ops);
17101 + if (IS_ERR(group)) {
17102 + err = PTR_ERR(group);
17103 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
17107 + group->private = hfsn;
17108 + hfsn->hfsn_group = group;
17109 + br->br_hfsn = hfsn;
17110 + goto out; /* success */
17118 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
17123 + if (!br->br_hfsn)
17124 + err = au_hfsn_init_br(br, perm);
17129 +/* ---------------------------------------------------------------------- */
17131 +static void au_hfsn_fin(void)
17133 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
17134 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
17137 +const struct au_hnotify_op au_hnotify_op = {
17138 + .ctl = au_hfsn_ctl,
17139 + .alloc = au_hfsn_alloc,
17140 + .free = au_hfsn_free,
17142 + .fin = au_hfsn_fin,
17144 + .reset_br = au_hfsn_reset_br,
17145 + .fin_br = au_hfsn_fin_br,
17146 + .init_br = au_hfsn_init_br
17148 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
17149 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
17150 +++ linux/fs/aufs/hfsplus.c 2018-08-12 23:43:05.456791299 +0200
17152 +// SPDX-License-Identifier: GPL-2.0
17154 + * Copyright (C) 2010-2018 Junjiro R. Okajima
17156 + * This program, aufs is free software; you can redistribute it and/or modify
17157 + * it under the terms of the GNU General Public License as published by
17158 + * the Free Software Foundation; either version 2 of the License, or
17159 + * (at your option) any later version.
17161 + * This program is distributed in the hope that it will be useful,
17162 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17163 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17164 + * GNU General Public License for more details.
17166 + * You should have received a copy of the GNU General Public License
17167 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17171 + * special support for filesystems which aqucires an inode mutex
17172 + * at final closing a file, eg, hfsplus.
17174 + * This trick is very simple and stupid, just to open the file before really
17175 + * neceeary open to tell hfsplus that this is not the final closing.
17176 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
17177 + * and au_h_open_post() after releasing it.
17182 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
17185 + struct file *h_file;
17186 + struct dentry *h_dentry;
17188 + h_dentry = au_h_dptr(dentry, bindex);
17189 + AuDebugOn(!h_dentry);
17190 + AuDebugOn(d_is_negative(h_dentry));
17193 + if (au_test_hfsplus(h_dentry->d_sb)
17194 + && d_is_reg(h_dentry))
17195 + h_file = au_h_open(dentry, bindex,
17196 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17197 + /*file*/NULL, force_wr);
17201 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17202 + struct file *h_file)
17206 + au_sbr_put(dentry->d_sb, bindex);
17209 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17210 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17211 +++ linux/fs/aufs/hnotify.c 2018-08-12 23:43:05.456791299 +0200
17213 +// SPDX-License-Identifier: GPL-2.0
17215 + * Copyright (C) 2005-2018 Junjiro R. Okajima
17217 + * This program, aufs is free software; you can redistribute it and/or modify
17218 + * it under the terms of the GNU General Public License as published by
17219 + * the Free Software Foundation; either version 2 of the License, or
17220 + * (at your option) any later version.
17222 + * This program is distributed in the hope that it will be useful,
17223 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17224 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17225 + * GNU General Public License for more details.
17227 + * You should have received a copy of the GNU General Public License
17228 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17232 + * abstraction to notify the direct changes on lower directories
17237 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17240 + struct au_hnotify *hn;
17243 + hn = au_cache_alloc_hnotify();
17245 + hn->hn_aufs_inode = inode;
17246 + hinode->hi_notify = hn;
17247 + err = au_hnotify_op.alloc(hinode);
17249 + if (unlikely(err)) {
17250 + hinode->hi_notify = NULL;
17251 + au_cache_free_hnotify(hn);
17253 + * The upper dir was removed by udba, but the same named
17254 + * dir left. In this case, aufs assignes a new inode
17255 + * number and set the monitor again.
17256 + * For the lower dir, the old monitnor is still left.
17258 + if (err == -EEXIST)
17267 +void au_hn_free(struct au_hinode *hinode)
17269 + struct au_hnotify *hn;
17271 + hn = hinode->hi_notify;
17273 + hinode->hi_notify = NULL;
17274 + if (au_hnotify_op.free(hinode, hn))
17275 + au_cache_free_hnotify(hn);
17279 +/* ---------------------------------------------------------------------- */
17281 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17283 + if (hinode->hi_notify)
17284 + au_hnotify_op.ctl(hinode, do_set);
17287 +void au_hn_reset(struct inode *inode, unsigned int flags)
17289 + aufs_bindex_t bindex, bbot;
17290 + struct inode *hi;
17291 + struct dentry *iwhdentry;
17293 + bbot = au_ibbot(inode);
17294 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17295 + hi = au_h_iptr(inode, bindex);
17299 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17300 + iwhdentry = au_hi_wh(inode, bindex);
17304 + au_set_h_iptr(inode, bindex, NULL, 0);
17305 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17306 + flags & ~AuHi_XINO);
17309 + /* inode_unlock(hi); */
17313 +/* ---------------------------------------------------------------------- */
17315 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17318 + aufs_bindex_t bindex, bbot, bfound, btop;
17319 + struct inode *h_i;
17322 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17323 + pr_warn("branch root dir was changed\n");
17328 + bbot = au_ibbot(inode);
17329 + btop = au_ibtop(inode);
17330 +#if 0 /* reserved for future use */
17331 + if (bindex == bbot) {
17332 + /* keep this ino in rename case */
17336 + for (bindex = btop; bindex <= bbot; bindex++)
17337 + if (au_h_iptr(inode, bindex) == h_inode) {
17344 + for (bindex = btop; bindex <= bbot; bindex++) {
17345 + h_i = au_h_iptr(inode, bindex);
17349 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17350 + /* ignore this error */
17351 + /* bad action? */
17354 + /* children inode number will be broken */
17361 +static int hn_gen_tree(struct dentry *dentry)
17363 + int err, i, j, ndentry;
17364 + struct au_dcsub_pages dpages;
17365 + struct au_dpage *dpage;
17366 + struct dentry **dentries;
17368 + err = au_dpages_init(&dpages, GFP_NOFS);
17369 + if (unlikely(err))
17371 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17372 + if (unlikely(err))
17375 + for (i = 0; i < dpages.ndpage; i++) {
17376 + dpage = dpages.dpages + i;
17377 + dentries = dpage->dentries;
17378 + ndentry = dpage->ndentry;
17379 + for (j = 0; j < ndentry; j++) {
17380 + struct dentry *d;
17387 + if (d_really_is_positive(d))
17388 + /* todo: reset children xino?
17389 + cached children only? */
17390 + au_iigen_dec(d_inode(d));
17395 + au_dpages_free(&dpages);
17398 + /* discard children */
17399 + dentry_unhash(dentry);
17407 + * return 0 if processed.
17409 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17410 + const unsigned int isdir)
17413 + struct dentry *d;
17414 + struct qstr *dname;
17417 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17418 + pr_warn("branch root dir was changed\n");
17424 + AuDebugOn(!name);
17425 + au_iigen_dec(inode);
17426 + spin_lock(&inode->i_lock);
17427 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17428 + spin_lock(&d->d_lock);
17429 + dname = &d->d_name;
17430 + if (dname->len != nlen
17431 + && memcmp(dname->name, name, nlen)) {
17432 + spin_unlock(&d->d_lock);
17437 + spin_unlock(&d->d_lock);
17440 + spin_unlock(&inode->i_lock);
17442 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17443 + d = d_find_any_alias(inode);
17445 + au_iigen_dec(inode);
17449 + spin_lock(&d->d_lock);
17450 + dname = &d->d_name;
17451 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17452 + spin_unlock(&d->d_lock);
17453 + err = hn_gen_tree(d);
17454 + spin_lock(&d->d_lock);
17456 + spin_unlock(&d->d_lock);
17465 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17469 + if (IS_ROOT(dentry)) {
17470 + pr_warn("branch root dir was changed\n");
17476 + au_digen_dec(dentry);
17477 + if (d_really_is_positive(dentry))
17478 + au_iigen_dec(d_inode(dentry));
17480 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17481 + if (d_really_is_positive(dentry))
17482 + err = hn_gen_tree(dentry);
17489 +/* ---------------------------------------------------------------------- */
17491 +/* hnotify job flags */
17492 +#define AuHnJob_XINO0 1
17493 +#define AuHnJob_GEN (1 << 1)
17494 +#define AuHnJob_DIRENT (1 << 2)
17495 +#define AuHnJob_ISDIR (1 << 3)
17496 +#define AuHnJob_TRYXINO0 (1 << 4)
17497 +#define AuHnJob_MNTPNT (1 << 5)
17498 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17499 +#define au_fset_hnjob(flags, name) \
17500 + do { (flags) |= AuHnJob_##name; } while (0)
17501 +#define au_fclr_hnjob(flags, name) \
17502 + do { (flags) &= ~AuHnJob_##name; } while (0)
17510 +struct au_hnotify_args {
17511 + struct inode *h_dir, *dir, *h_child_inode;
17513 + unsigned int flags[AuHnLast];
17514 + unsigned int h_child_nlen;
17515 + char h_child_name[];
17518 +struct hn_job_args {
17519 + unsigned int flags;
17520 + struct inode *inode, *h_inode, *dir, *h_dir;
17521 + struct dentry *dentry;
17526 +static int hn_job(struct hn_job_args *a)
17528 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17532 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17533 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17535 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17538 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17539 + if (!a->h_inode->i_nlink
17540 + && !(a->h_inode->i_state & I_LINKABLE))
17541 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17542 + inode_unlock_shared(a->h_inode);
17545 + /* make the generation obsolete */
17546 + if (au_ftest_hnjob(a->flags, GEN)) {
17549 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17551 + if (e && a->dentry)
17552 + hn_gen_by_name(a->dentry, isdir);
17553 + /* ignore this error */
17556 + /* make dir entries obsolete */
17557 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17558 + struct au_vdir *vdir;
17560 + vdir = au_ivdir(a->inode);
17562 + vdir->vd_jiffy = 0;
17563 + /* IMustLock(a->inode); */
17564 + /* inode_inc_iversion(a->inode); */
17567 + /* can do nothing but warn */
17568 + if (au_ftest_hnjob(a->flags, MNTPNT)
17570 + && d_mountpoint(a->dentry))
17571 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17576 +/* ---------------------------------------------------------------------- */
17578 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17579 + struct inode *dir)
17581 + struct dentry *dentry, *d, *parent;
17582 + struct qstr *dname;
17584 + parent = d_find_any_alias(dir);
17589 + spin_lock(&parent->d_lock);
17590 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17591 + /* AuDbg("%pd\n", d); */
17592 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17593 + dname = &d->d_name;
17594 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17595 + goto cont_unlock;
17599 + goto cont_unlock;
17600 + if (au_dcount(d) > 0) {
17601 + dentry = dget_dlock(d);
17602 + spin_unlock(&d->d_lock);
17607 + spin_unlock(&d->d_lock);
17609 + spin_unlock(&parent->d_lock);
17613 + di_write_lock_child(dentry);
17618 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17619 + aufs_bindex_t bindex, ino_t h_ino)
17621 + struct inode *inode;
17626 + err = au_xino_read(sb, bindex, h_ino, &ino);
17628 + inode = ilookup(sb, ino);
17632 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17633 + pr_warn("wrong root branch\n");
17639 + ii_write_lock_child(inode);
17645 +static void au_hn_bh(void *_args)
17647 + struct au_hnotify_args *a = _args;
17648 + struct super_block *sb;
17649 + aufs_bindex_t bindex, bbot, bfound;
17650 + unsigned char xino, try_iput;
17652 + struct inode *inode;
17654 + struct hn_job_args args;
17655 + struct dentry *dentry;
17656 + struct au_sbinfo *sbinfo;
17658 + AuDebugOn(!_args);
17659 + AuDebugOn(!a->h_dir);
17660 + AuDebugOn(!a->dir);
17661 + AuDebugOn(!a->mask);
17662 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17663 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17664 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17669 + * do not lock a->dir->i_mutex here
17670 + * because of d_revalidate() may cause a deadlock.
17672 + sb = a->dir->i_sb;
17674 + sbinfo = au_sbi(sb);
17675 + AuDebugOn(!sbinfo);
17676 + si_write_lock(sb, AuLock_NOPLMW);
17678 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17679 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17680 + case FS_MOVED_FROM:
17681 + case FS_MOVED_TO:
17682 + AuWarn1("DIRREN with UDBA may not work correctly "
17683 + "for the direct rename(2)\n");
17686 + ii_read_lock_parent(a->dir);
17688 + bbot = au_ibbot(a->dir);
17689 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17690 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17694 + ii_read_unlock(a->dir);
17695 + if (unlikely(bfound < 0))
17698 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17700 + if (a->h_child_inode)
17701 + h_ino = a->h_child_inode->i_ino;
17703 + if (a->h_child_nlen
17704 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17705 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17706 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17709 + if (dentry && d_really_is_positive(dentry))
17710 + inode = d_inode(dentry);
17711 + if (xino && !inode && h_ino
17712 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17713 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17714 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17715 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17719 + args.flags = a->flags[AuHn_CHILD];
17720 + args.dentry = dentry;
17721 + args.inode = inode;
17722 + args.h_inode = a->h_child_inode;
17723 + args.dir = a->dir;
17724 + args.h_dir = a->h_dir;
17725 + args.h_name = a->h_child_name;
17726 + args.h_nlen = a->h_child_nlen;
17727 + err = hn_job(&args);
17729 + if (au_di(dentry))
17730 + di_write_unlock(dentry);
17733 + if (inode && try_iput) {
17734 + ii_write_unlock(inode);
17738 + ii_write_lock_parent(a->dir);
17739 + args.flags = a->flags[AuHn_PARENT];
17740 + args.dentry = NULL;
17741 + args.inode = a->dir;
17742 + args.h_inode = a->h_dir;
17744 + args.h_dir = NULL;
17745 + args.h_name = NULL;
17747 + err = hn_job(&args);
17748 + ii_write_unlock(a->dir);
17751 + iput(a->h_child_inode);
17754 + si_write_unlock(sb);
17755 + au_nwt_done(&sbinfo->si_nowait);
17759 +/* ---------------------------------------------------------------------- */
17761 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17762 + struct qstr *h_child_qstr, struct inode *h_child_inode)
17765 + unsigned int flags[AuHnLast], f;
17766 + unsigned char isdir, isroot, wh;
17767 + struct inode *dir;
17768 + struct au_hnotify_args *args;
17769 + char *p, *h_child_name;
17772 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17773 + dir = igrab(hnotify->hn_aufs_inode);
17777 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17779 + h_child_name = (void *)h_child_qstr->name;
17780 + len = h_child_qstr->len;
17781 + if (h_child_name) {
17782 + if (len > AUFS_WH_PFX_LEN
17783 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17784 + h_child_name += AUFS_WH_PFX_LEN;
17785 + len -= AUFS_WH_PFX_LEN;
17791 + if (h_child_inode)
17792 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17793 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17794 + flags[AuHn_CHILD] = 0;
17796 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17797 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17798 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17799 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
17800 + case FS_MOVED_FROM:
17801 + case FS_MOVED_TO:
17802 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17803 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17806 + AuDebugOn(!h_child_name);
17811 + * aufs never be able to get this child inode.
17812 + * revalidation should be in d_revalidate()
17813 + * by checking i_nlink, i_generation or d_unhashed().
17815 + AuDebugOn(!h_child_name);
17816 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17817 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17825 + h_child_inode = NULL;
17828 + /* iput() and kfree() will be called in au_hnotify() */
17829 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17830 + if (unlikely(!args)) {
17831 + AuErr1("no memory\n");
17835 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17836 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17837 + args->mask = mask;
17839 + args->h_dir = igrab(h_dir);
17840 + if (h_child_inode)
17841 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17842 + args->h_child_inode = h_child_inode;
17843 + args->h_child_nlen = len;
17845 + p = (void *)args;
17846 + p += sizeof(*args);
17847 + memcpy(p, h_child_name, len);
17851 + /* NFS fires the event for silly-renamed one from kworker */
17853 + if (!dir->i_nlink
17854 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17856 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17857 + if (unlikely(err)) {
17858 + pr_err("wkq %d\n", err);
17859 + iput(args->h_child_inode);
17860 + iput(args->h_dir);
17869 +/* ---------------------------------------------------------------------- */
17871 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17875 + AuDebugOn(!(udba & AuOptMask_UDBA));
17878 + if (au_hnotify_op.reset_br)
17879 + err = au_hnotify_op.reset_br(udba, br, perm);
17884 +int au_hnotify_init_br(struct au_branch *br, int perm)
17889 + if (au_hnotify_op.init_br)
17890 + err = au_hnotify_op.init_br(br, perm);
17895 +void au_hnotify_fin_br(struct au_branch *br)
17897 + if (au_hnotify_op.fin_br)
17898 + au_hnotify_op.fin_br(br);
17901 +static void au_hn_destroy_cache(void)
17903 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17904 + au_cache[AuCache_HNOTIFY] = NULL;
17907 +int __init au_hnotify_init(void)
17912 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17913 + if (au_cache[AuCache_HNOTIFY]) {
17915 + if (au_hnotify_op.init)
17916 + err = au_hnotify_op.init();
17917 + if (unlikely(err))
17918 + au_hn_destroy_cache();
17924 +void au_hnotify_fin(void)
17926 + if (au_hnotify_op.fin)
17927 + au_hnotify_op.fin();
17929 + /* cf. au_cache_fin() */
17930 + if (au_cache[AuCache_HNOTIFY])
17931 + au_hn_destroy_cache();
17933 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17934 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17935 +++ linux/fs/aufs/iinfo.c 2018-08-12 23:43:05.460124736 +0200
17937 +// SPDX-License-Identifier: GPL-2.0
17939 + * Copyright (C) 2005-2018 Junjiro R. Okajima
17941 + * This program, aufs is free software; you can redistribute it and/or modify
17942 + * it under the terms of the GNU General Public License as published by
17943 + * the Free Software Foundation; either version 2 of the License, or
17944 + * (at your option) any later version.
17946 + * This program is distributed in the hope that it will be useful,
17947 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17948 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17949 + * GNU General Public License for more details.
17951 + * You should have received a copy of the GNU General Public License
17952 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17956 + * inode private data
17961 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17963 + struct inode *h_inode;
17964 + struct au_hinode *hinode;
17966 + IiMustAnyLock(inode);
17968 + hinode = au_hinode(au_ii(inode), bindex);
17969 + h_inode = hinode->hi_inode;
17970 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17974 +/* todo: hard/soft set? */
17975 +void au_hiput(struct au_hinode *hinode)
17977 + au_hn_free(hinode);
17978 + dput(hinode->hi_whdentry);
17979 + iput(hinode->hi_inode);
17982 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17984 + unsigned int flags;
17985 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17988 + if (au_opt_test(mnt_flags, XINO))
17989 + au_fset_hi(flags, XINO);
17990 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17991 + au_fset_hi(flags, HNOTIFY);
17995 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17996 + struct inode *h_inode, unsigned int flags)
17998 + struct au_hinode *hinode;
17999 + struct inode *hi;
18000 + struct au_iinfo *iinfo = au_ii(inode);
18002 + IiMustWriteLock(inode);
18004 + hinode = au_hinode(iinfo, bindex);
18005 + hi = hinode->hi_inode;
18006 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
18009 + au_hiput(hinode);
18010 + hinode->hi_inode = h_inode;
18013 + struct super_block *sb = inode->i_sb;
18014 + struct au_branch *br;
18016 + AuDebugOn(inode->i_mode
18017 + && (h_inode->i_mode & S_IFMT)
18018 + != (inode->i_mode & S_IFMT));
18019 + if (bindex == iinfo->ii_btop)
18020 + au_cpup_igen(inode, h_inode);
18021 + br = au_sbr(sb, bindex);
18022 + hinode->hi_id = br->br_id;
18023 + if (au_ftest_hi(flags, XINO)) {
18024 + err = au_xino_write(sb, bindex, h_inode->i_ino,
18026 + if (unlikely(err))
18027 + AuIOErr1("failed au_xino_write() %d\n", err);
18030 + if (au_ftest_hi(flags, HNOTIFY)
18031 + && au_br_hnotifyable(br->br_perm)) {
18032 + err = au_hn_alloc(hinode, inode);
18033 + if (unlikely(err))
18034 + AuIOErr1("au_hn_alloc() %d\n", err);
18039 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18040 + struct dentry *h_wh)
18042 + struct au_hinode *hinode;
18044 + IiMustWriteLock(inode);
18046 + hinode = au_hinode(au_ii(inode), bindex);
18047 + AuDebugOn(hinode->hi_whdentry);
18048 + hinode->hi_whdentry = h_wh;
18051 +void au_update_iigen(struct inode *inode, int half)
18053 + struct au_iinfo *iinfo;
18054 + struct au_iigen *iigen;
18055 + unsigned int sigen;
18057 + sigen = au_sigen(inode->i_sb);
18058 + iinfo = au_ii(inode);
18059 + iigen = &iinfo->ii_generation;
18060 + spin_lock(&iigen->ig_spin);
18061 + iigen->ig_generation = sigen;
18063 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
18065 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
18066 + spin_unlock(&iigen->ig_spin);
18069 +/* it may be called at remount time, too */
18070 +void au_update_ibrange(struct inode *inode, int do_put_zero)
18072 + struct au_iinfo *iinfo;
18073 + aufs_bindex_t bindex, bbot;
18075 + AuDebugOn(au_is_bad_inode(inode));
18076 + IiMustWriteLock(inode);
18078 + iinfo = au_ii(inode);
18079 + if (do_put_zero && iinfo->ii_btop >= 0) {
18080 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18082 + struct inode *h_i;
18084 + h_i = au_hinode(iinfo, bindex)->hi_inode;
18087 + && !(h_i->i_state & I_LINKABLE))
18088 + au_set_h_iptr(inode, bindex, NULL, 0);
18092 + iinfo->ii_btop = -1;
18093 + iinfo->ii_bbot = -1;
18094 + bbot = au_sbbot(inode->i_sb);
18095 + for (bindex = 0; bindex <= bbot; bindex++)
18096 + if (au_hinode(iinfo, bindex)->hi_inode) {
18097 + iinfo->ii_btop = bindex;
18100 + if (iinfo->ii_btop >= 0)
18101 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
18102 + if (au_hinode(iinfo, bindex)->hi_inode) {
18103 + iinfo->ii_bbot = bindex;
18106 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
18109 +/* ---------------------------------------------------------------------- */
18111 +void au_icntnr_init_once(void *_c)
18113 + struct au_icntnr *c = _c;
18114 + struct au_iinfo *iinfo = &c->iinfo;
18116 + spin_lock_init(&iinfo->ii_generation.ig_spin);
18117 + au_rw_init(&iinfo->ii_rwsem);
18118 + inode_init_once(&c->vfs_inode);
18121 +void au_hinode_init(struct au_hinode *hinode)
18123 + hinode->hi_inode = NULL;
18124 + hinode->hi_id = -1;
18125 + au_hn_init(hinode);
18126 + hinode->hi_whdentry = NULL;
18129 +int au_iinfo_init(struct inode *inode)
18131 + struct au_iinfo *iinfo;
18132 + struct super_block *sb;
18133 + struct au_hinode *hi;
18136 + sb = inode->i_sb;
18137 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18138 + nbr = au_sbbot(sb) + 1;
18139 + if (unlikely(nbr <= 0))
18141 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
18143 + au_ninodes_inc(sb);
18145 + iinfo->ii_hinode = hi;
18146 + for (i = 0; i < nbr; i++, hi++)
18147 + au_hinode_init(hi);
18149 + iinfo->ii_generation.ig_generation = au_sigen(sb);
18150 + iinfo->ii_btop = -1;
18151 + iinfo->ii_bbot = -1;
18152 + iinfo->ii_vdir = NULL;
18158 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
18161 + struct au_hinode *hip;
18163 + AuRwMustWriteLock(&iinfo->ii_rwsem);
18166 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
18169 + iinfo->ii_hinode = hip;
18170 + i = iinfo->ii_bbot + 1;
18172 + for (; i < nbr; i++, hip++)
18173 + au_hinode_init(hip);
18180 +void au_iinfo_fin(struct inode *inode)
18182 + struct au_iinfo *iinfo;
18183 + struct au_hinode *hi;
18184 + struct super_block *sb;
18185 + aufs_bindex_t bindex, bbot;
18186 + const unsigned char unlinked = !inode->i_nlink;
18188 + AuDebugOn(au_is_bad_inode(inode));
18190 + sb = inode->i_sb;
18191 + au_ninodes_dec(sb);
18192 + if (si_pid_test(sb))
18193 + au_xino_delete_inode(inode, unlinked);
18196 + * it is safe to hide the dependency between sbinfo and
18200 + si_noflush_read_lock(sb);
18201 + au_xino_delete_inode(inode, unlinked);
18202 + si_read_unlock(sb);
18206 + iinfo = au_ii(inode);
18207 + if (iinfo->ii_vdir)
18208 + au_vdir_free(iinfo->ii_vdir);
18210 + bindex = iinfo->ii_btop;
18211 + if (bindex >= 0) {
18212 + hi = au_hinode(iinfo, bindex);
18213 + bbot = iinfo->ii_bbot;
18214 + while (bindex++ <= bbot) {
18215 + if (hi->hi_inode)
18220 + kfree(iinfo->ii_hinode);
18221 + AuRwDestroy(&iinfo->ii_rwsem);
18223 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18224 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18225 +++ linux/fs/aufs/inode.c 2018-08-12 23:43:05.460124736 +0200
18227 +// SPDX-License-Identifier: GPL-2.0
18229 + * Copyright (C) 2005-2018 Junjiro R. Okajima
18231 + * This program, aufs is free software; you can redistribute it and/or modify
18232 + * it under the terms of the GNU General Public License as published by
18233 + * the Free Software Foundation; either version 2 of the License, or
18234 + * (at your option) any later version.
18236 + * This program is distributed in the hope that it will be useful,
18237 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18238 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18239 + * GNU General Public License for more details.
18241 + * You should have received a copy of the GNU General Public License
18242 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18246 + * inode functions
18251 +struct inode *au_igrab(struct inode *inode)
18254 + AuDebugOn(!atomic_read(&inode->i_count));
18260 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18262 + au_cpup_attr_all(inode, /*force*/0);
18263 + au_update_iigen(inode, /*half*/1);
18265 + inode_inc_iversion(inode);
18268 +static int au_ii_refresh(struct inode *inode, int *update)
18272 + aufs_bindex_t bindex, new_bindex;
18273 + struct super_block *sb;
18274 + struct au_iinfo *iinfo;
18275 + struct au_hinode *p, *q, tmp;
18277 + AuDebugOn(au_is_bad_inode(inode));
18278 + IiMustWriteLock(inode);
18281 + sb = inode->i_sb;
18282 + nbr = au_sbbot(sb) + 1;
18283 + type = inode->i_mode & S_IFMT;
18284 + iinfo = au_ii(inode);
18285 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18286 + if (unlikely(err))
18289 + AuDebugOn(iinfo->ii_btop < 0);
18290 + p = au_hinode(iinfo, iinfo->ii_btop);
18291 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18293 + if (!p->hi_inode)
18296 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18297 + new_bindex = au_br_index(sb, p->hi_id);
18298 + if (new_bindex == bindex)
18301 + if (new_bindex < 0) {
18304 + p->hi_inode = NULL;
18308 + if (new_bindex < iinfo->ii_btop)
18309 + iinfo->ii_btop = new_bindex;
18310 + if (iinfo->ii_bbot < new_bindex)
18311 + iinfo->ii_bbot = new_bindex;
18312 + /* swap two lower inode, and loop again */
18313 + q = au_hinode(iinfo, new_bindex);
18317 + if (tmp.hi_inode) {
18322 + au_update_ibrange(inode, /*do_put_zero*/0);
18323 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18324 + e = au_dy_irefresh(inode);
18325 + if (unlikely(e && !err))
18333 +void au_refresh_iop(struct inode *inode, int force_getattr)
18336 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18337 + const struct inode_operations *iop
18338 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18340 + if (inode->i_op == iop)
18343 + switch (inode->i_mode & S_IFMT) {
18345 + type = AuIop_DIR;
18348 + type = AuIop_SYMLINK;
18351 + type = AuIop_OTHER;
18355 + inode->i_op = iop + type;
18356 + /* unnecessary smp_wmb() */
18359 +int au_refresh_hinode_self(struct inode *inode)
18363 + err = au_ii_refresh(inode, &update);
18365 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18371 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18373 + int err, e, update;
18374 + unsigned int flags;
18376 + aufs_bindex_t bindex, bbot;
18377 + unsigned char isdir;
18378 + struct au_hinode *p;
18379 + struct au_iinfo *iinfo;
18381 + err = au_ii_refresh(inode, &update);
18382 + if (unlikely(err))
18386 + iinfo = au_ii(inode);
18387 + p = au_hinode(iinfo, iinfo->ii_btop);
18388 + mode = (inode->i_mode & S_IFMT);
18389 + isdir = S_ISDIR(mode);
18390 + flags = au_hi_flags(inode, isdir);
18391 + bbot = au_dbbot(dentry);
18392 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18393 + struct inode *h_i, *h_inode;
18394 + struct dentry *h_d;
18396 + h_d = au_h_dptr(dentry, bindex);
18397 + if (!h_d || d_is_negative(h_d))
18400 + h_inode = d_inode(h_d);
18401 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18402 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18403 + h_i = au_h_iptr(inode, bindex);
18405 + if (h_i == h_inode)
18411 + if (bindex < iinfo->ii_btop)
18412 + iinfo->ii_btop = bindex;
18413 + if (iinfo->ii_bbot < bindex)
18414 + iinfo->ii_bbot = bindex;
18415 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18418 + au_update_ibrange(inode, /*do_put_zero*/0);
18419 + e = au_dy_irefresh(inode);
18420 + if (unlikely(e && !err))
18423 + au_refresh_hinode_attr(inode, update && isdir);
18430 +static int set_inode(struct inode *inode, struct dentry *dentry)
18433 + unsigned int flags;
18435 + aufs_bindex_t bindex, btop, btail;
18436 + unsigned char isdir;
18437 + struct dentry *h_dentry;
18438 + struct inode *h_inode;
18439 + struct au_iinfo *iinfo;
18440 + struct inode_operations *iop;
18442 + IiMustWriteLock(inode);
18446 + iop = au_sbi(inode->i_sb)->si_iop_array;
18447 + btop = au_dbtop(dentry);
18448 + h_dentry = au_h_dptr(dentry, btop);
18449 + h_inode = d_inode(h_dentry);
18450 + mode = h_inode->i_mode;
18451 + switch (mode & S_IFMT) {
18453 + btail = au_dbtail(dentry);
18454 + inode->i_op = iop + AuIop_OTHER;
18455 + inode->i_fop = &aufs_file_fop;
18456 + err = au_dy_iaop(inode, btop, h_inode);
18457 + if (unlikely(err))
18462 + btail = au_dbtaildir(dentry);
18463 + inode->i_op = iop + AuIop_DIR;
18464 + inode->i_fop = &aufs_dir_fop;
18467 + btail = au_dbtail(dentry);
18468 + inode->i_op = iop + AuIop_SYMLINK;
18474 + btail = au_dbtail(dentry);
18475 + inode->i_op = iop + AuIop_OTHER;
18476 + init_special_inode(inode, mode, h_inode->i_rdev);
18479 + AuIOErr("Unknown file type 0%o\n", mode);
18484 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18485 + flags = au_hi_flags(inode, isdir);
18486 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18487 + && au_ftest_hi(flags, HNOTIFY)
18488 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18489 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18490 + au_fclr_hi(flags, HNOTIFY);
18491 + iinfo = au_ii(inode);
18492 + iinfo->ii_btop = btop;
18493 + iinfo->ii_bbot = btail;
18494 + for (bindex = btop; bindex <= btail; bindex++) {
18495 + h_dentry = au_h_dptr(dentry, bindex);
18497 + au_set_h_iptr(inode, bindex,
18498 + au_igrab(d_inode(h_dentry)), flags);
18500 + au_cpup_attr_all(inode, /*force*/1);
18502 + * to force calling aufs_get_acl() every time,
18503 + * do not call cache_no_acl() for aufs inode.
18511 + * successful returns with iinfo write_locked
18513 + * zero: success, matched
18514 + * plus: no error, but unmatched
18516 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18519 + unsigned int gen, igflags;
18520 + aufs_bindex_t bindex, bbot;
18521 + struct inode *h_inode, *h_dinode;
18522 + struct dentry *h_dentry;
18525 + * before this function, if aufs got any iinfo lock, it must be only
18526 + * one, the parent dir.
18527 + * it can happen by UDBA and the obsoleted inode number.
18530 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18534 + ii_write_lock_new_child(inode);
18535 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18536 + h_dinode = d_inode(h_dentry);
18537 + bbot = au_ibbot(inode);
18538 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18539 + h_inode = au_h_iptr(inode, bindex);
18540 + if (!h_inode || h_inode != h_dinode)
18544 + gen = au_iigen(inode, &igflags);
18545 + if (gen == au_digen(dentry)
18546 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18549 + /* fully refresh inode using dentry */
18550 + err = au_refresh_hinode(inode, dentry);
18552 + au_update_iigen(inode, /*half*/0);
18556 + if (unlikely(err))
18557 + ii_write_unlock(inode);
18562 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18563 + unsigned int d_type, ino_t *ino)
18566 + const int isnondir = d_type != DT_DIR;
18568 + /* prevent hardlinked inode number from race condition */
18570 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18571 + if (unlikely(err))
18575 + err = au_xino_read(sb, bindex, h_ino, ino);
18576 + if (unlikely(err))
18577 + goto out_xinondir;
18581 + *ino = au_xino_new_ino(sb);
18582 + if (unlikely(!*ino))
18583 + goto out_xinondir;
18584 + err = au_xino_write(sb, bindex, h_ino, *ino);
18585 + if (unlikely(err))
18586 + goto out_xinondir;
18590 + if (isnondir && idx >= 0)
18591 + au_xinondir_leave(sb, bindex, h_ino, idx);
18596 +/* successful returns with iinfo write_locked */
18597 +/* todo: return with unlocked? */
18598 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18600 + struct inode *inode, *h_inode;
18601 + struct dentry *h_dentry;
18602 + struct super_block *sb;
18603 + ino_t h_ino, ino;
18604 + int err, idx, hlinked;
18605 + aufs_bindex_t btop;
18607 + sb = dentry->d_sb;
18608 + btop = au_dbtop(dentry);
18609 + h_dentry = au_h_dptr(dentry, btop);
18610 + h_inode = d_inode(h_dentry);
18611 + h_ino = h_inode->i_ino;
18612 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18616 + * stop 'race'-ing between hardlinks under different
18620 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18621 + inode = ERR_PTR(err);
18622 + if (unlikely(err))
18626 + err = au_xino_read(sb, btop, h_ino, &ino);
18627 + inode = ERR_PTR(err);
18628 + if (unlikely(err))
18629 + goto out_xinondir;
18632 + ino = au_xino_new_ino(sb);
18633 + if (unlikely(!ino)) {
18634 + inode = ERR_PTR(-EIO);
18635 + goto out_xinondir;
18639 + AuDbg("i%lu\n", (unsigned long)ino);
18640 + inode = au_iget_locked(sb, ino);
18641 + err = PTR_ERR(inode);
18642 + if (IS_ERR(inode))
18643 + goto out_xinondir;
18645 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18646 + if (inode->i_state & I_NEW) {
18647 + ii_write_lock_new_child(inode);
18648 + err = set_inode(inode, dentry);
18650 + unlock_new_inode(inode);
18651 + goto out_xinondir; /* success */
18655 + * iget_failed() calls iput(), but we need to call
18656 + * ii_write_unlock() after iget_failed(). so dirty hack for
18659 + atomic_inc(&inode->i_count);
18660 + iget_failed(inode);
18661 + ii_write_unlock(inode);
18662 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18663 + /* ignore this error */
18665 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18667 + * horrible race condition between lookup, readdir and copyup
18668 + * (or something).
18670 + if (hlinked && idx >= 0)
18671 + au_xinondir_leave(sb, btop, h_ino, idx);
18672 + err = reval_inode(inode, dentry);
18673 + if (unlikely(err < 0)) {
18678 + goto out; /* success */
18679 + else if (hlinked && idx >= 0) {
18680 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18681 + if (unlikely(err)) {
18683 + inode = ERR_PTR(err);
18689 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18690 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18691 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18692 + btop, au_sbtype(h_dentry->d_sb), dentry,
18693 + (unsigned long)h_ino, (unsigned long)ino);
18695 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18698 + if (hlinked && idx >= 0)
18699 + au_xinondir_leave(sb, btop, h_ino, idx);
18705 + inode = ERR_PTR(err);
18707 + if (hlinked && idx >= 0)
18708 + au_xinondir_leave(sb, btop, h_ino, idx);
18713 +/* ---------------------------------------------------------------------- */
18715 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18716 + struct inode *inode)
18719 + struct inode *hi;
18721 + err = au_br_rdonly(au_sbr(sb, bindex));
18723 + /* pseudo-link after flushed may happen out of bounds */
18726 + && au_ibtop(inode) <= bindex
18727 + && bindex <= au_ibbot(inode)) {
18729 + * permission check is unnecessary since vfsub routine
18730 + * will be called later
18732 + hi = au_h_iptr(inode, bindex);
18734 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18740 +int au_test_h_perm(struct inode *h_inode, int mask)
18742 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18744 + return inode_permission(h_inode, mask);
18747 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18749 + if (au_test_nfs(h_inode->i_sb)
18750 + && (mask & MAY_WRITE)
18751 + && S_ISDIR(h_inode->i_mode))
18752 + mask |= MAY_READ; /* force permission check */
18753 + return au_test_h_perm(h_inode, mask);
18755 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18756 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18757 +++ linux/fs/aufs/inode.h 2018-08-12 23:43:05.460124736 +0200
18759 +/* SPDX-License-Identifier: GPL-2.0 */
18761 + * Copyright (C) 2005-2018 Junjiro R. Okajima
18763 + * This program, aufs is free software; you can redistribute it and/or modify
18764 + * it under the terms of the GNU General Public License as published by
18765 + * the Free Software Foundation; either version 2 of the License, or
18766 + * (at your option) any later version.
18768 + * This program is distributed in the hope that it will be useful,
18769 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18770 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18771 + * GNU General Public License for more details.
18773 + * You should have received a copy of the GNU General Public License
18774 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18778 + * inode operations
18781 +#ifndef __AUFS_INODE_H__
18782 +#define __AUFS_INODE_H__
18786 +#include <linux/fsnotify.h>
18787 +#include "rwsem.h"
18791 +struct au_hnotify {
18792 +#ifdef CONFIG_AUFS_HNOTIFY
18793 +#ifdef CONFIG_AUFS_HFSNOTIFY
18794 + /* never use fsnotify_add_vfsmount_mark() */
18795 + struct fsnotify_mark hn_mark;
18797 + struct inode *hn_aufs_inode; /* no get/put */
18799 +} ____cacheline_aligned_in_smp;
18801 +struct au_hinode {
18802 + struct inode *hi_inode;
18803 + aufs_bindex_t hi_id;
18804 +#ifdef CONFIG_AUFS_HNOTIFY
18805 + struct au_hnotify *hi_notify;
18808 + /* reference to the copied-up whiteout with get/put */
18809 + struct dentry *hi_whdentry;
18813 +#define AuIG_HALF_REFRESHED 1
18814 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18815 +#define au_ig_fset(flags, name) \
18816 + do { (flags) |= AuIG_##name; } while (0)
18817 +#define au_ig_fclr(flags, name) \
18818 + do { (flags) &= ~AuIG_##name; } while (0)
18821 + spinlock_t ig_spin;
18822 + __u32 ig_generation, ig_flags;
18827 + struct au_iigen ii_generation;
18828 + struct super_block *ii_hsb1; /* no get/put */
18830 + struct au_rwsem ii_rwsem;
18831 + aufs_bindex_t ii_btop, ii_bbot;
18833 + struct au_hinode *ii_hinode;
18834 + struct au_vdir *ii_vdir;
18837 +struct au_icntnr {
18838 + struct au_iinfo iinfo;
18839 + struct inode vfs_inode;
18840 + struct hlist_bl_node plink;
18841 +} ____cacheline_aligned_in_smp;
18843 +/* au_pin flags */
18844 +#define AuPin_DI_LOCKED 1
18845 +#define AuPin_MNT_WRITE (1 << 1)
18846 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18847 +#define au_fset_pin(flags, name) \
18848 + do { (flags) |= AuPin_##name; } while (0)
18849 +#define au_fclr_pin(flags, name) \
18850 + do { (flags) &= ~AuPin_##name; } while (0)
18854 + struct dentry *dentry;
18855 + unsigned int udba;
18856 + unsigned char lsc_di, lsc_hi, flags;
18857 + aufs_bindex_t bindex;
18860 + struct dentry *parent;
18861 + struct au_hinode *hdir;
18862 + struct vfsmount *h_mnt;
18864 + /* temporary unlock/relock for copyup */
18865 + struct dentry *h_dentry, *h_parent;
18866 + struct au_branch *br;
18867 + struct task_struct *task;
18870 +void au_pin_hdir_unlock(struct au_pin *p);
18871 +int au_pin_hdir_lock(struct au_pin *p);
18872 +int au_pin_hdir_relock(struct au_pin *p);
18873 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18874 +void au_pin_hdir_release(struct au_pin *p);
18876 +/* ---------------------------------------------------------------------- */
18878 +static inline struct au_iinfo *au_ii(struct inode *inode)
18880 + BUG_ON(is_bad_inode(inode));
18881 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18884 +/* ---------------------------------------------------------------------- */
18887 +struct inode *au_igrab(struct inode *inode);
18888 +void au_refresh_iop(struct inode *inode, int force_getattr);
18889 +int au_refresh_hinode_self(struct inode *inode);
18890 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18891 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18892 + unsigned int d_type, ino_t *ino);
18893 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18894 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18895 + struct inode *inode);
18896 +int au_test_h_perm(struct inode *h_inode, int mask);
18897 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18899 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18900 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18902 +#ifdef CONFIG_AUFS_SHWH
18903 + return au_ino(sb, bindex, h_ino, d_type, ino);
18916 +extern struct inode_operations aufs_iop[AuIop_Last],
18917 + aufs_iop_nogetattr[AuIop_Last];
18919 +/* au_wr_dir flags */
18920 +#define AuWrDir_ADD_ENTRY 1
18921 +#define AuWrDir_ISDIR (1 << 1)
18922 +#define AuWrDir_TMPFILE (1 << 2)
18923 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18924 +#define au_fset_wrdir(flags, name) \
18925 + do { (flags) |= AuWrDir_##name; } while (0)
18926 +#define au_fclr_wrdir(flags, name) \
18927 + do { (flags) &= ~AuWrDir_##name; } while (0)
18929 +struct au_wr_dir_args {
18930 + aufs_bindex_t force_btgt;
18931 + unsigned char flags;
18933 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18934 + struct au_wr_dir_args *args);
18936 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18937 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18938 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18939 + unsigned int udba, unsigned char flags);
18940 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18941 + unsigned int udba, unsigned char flags) __must_check;
18942 +int au_do_pin(struct au_pin *pin) __must_check;
18943 +void au_unpin(struct au_pin *pin);
18944 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18946 +#define AuIcpup_DID_CPUP 1
18947 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18948 +#define au_fset_icpup(flags, name) \
18949 + do { (flags) |= AuIcpup_##name; } while (0)
18950 +#define au_fclr_icpup(flags, name) \
18951 + do { (flags) &= ~AuIcpup_##name; } while (0)
18953 +struct au_icpup_args {
18954 + unsigned char flags;
18955 + unsigned char pin_flags;
18956 + aufs_bindex_t btgt;
18957 + unsigned int udba;
18958 + struct au_pin pin;
18959 + struct path h_path;
18960 + struct inode *h_inode;
18963 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18964 + struct au_icpup_args *a);
18966 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
18970 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18971 + struct dentry *h_parent, int isdir);
18972 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18974 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
18975 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18977 +struct vfsub_aopen_args;
18978 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18979 + struct vfsub_aopen_args *args);
18980 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
18981 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18982 + struct dentry *dentry);
18983 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
18986 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18987 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18988 + struct dentry *h_parent, int isdir);
18989 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18990 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
18993 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
18994 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
18995 + struct inode *dir, struct dentry *dentry,
18996 + unsigned int flags);
18999 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
19000 +void au_hiput(struct au_hinode *hinode);
19001 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19002 + struct dentry *h_wh);
19003 +unsigned int au_hi_flags(struct inode *inode, int isdir);
19005 +/* hinode flags */
19006 +#define AuHi_XINO 1
19007 +#define AuHi_HNOTIFY (1 << 1)
19008 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
19009 +#define au_fset_hi(flags, name) \
19010 + do { (flags) |= AuHi_##name; } while (0)
19011 +#define au_fclr_hi(flags, name) \
19012 + do { (flags) &= ~AuHi_##name; } while (0)
19014 +#ifndef CONFIG_AUFS_HNOTIFY
19015 +#undef AuHi_HNOTIFY
19016 +#define AuHi_HNOTIFY 0
19019 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19020 + struct inode *h_inode, unsigned int flags);
19022 +void au_update_iigen(struct inode *inode, int half);
19023 +void au_update_ibrange(struct inode *inode, int do_put_zero);
19025 +void au_icntnr_init_once(void *_c);
19026 +void au_hinode_init(struct au_hinode *hinode);
19027 +int au_iinfo_init(struct inode *inode);
19028 +void au_iinfo_fin(struct inode *inode);
19029 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
19031 +#ifdef CONFIG_PROC_FS
19033 +int au_plink_maint(struct super_block *sb, int flags);
19035 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
19036 +int au_plink_maint_enter(struct super_block *sb);
19037 +#ifdef CONFIG_AUFS_DEBUG
19038 +void au_plink_list(struct super_block *sb);
19040 +AuStubVoid(au_plink_list, struct super_block *sb)
19042 +int au_plink_test(struct inode *inode);
19043 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
19044 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
19045 + struct dentry *h_dentry);
19046 +void au_plink_put(struct super_block *sb, int verbose);
19047 +void au_plink_clean(struct super_block *sb, int verbose);
19048 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
19050 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
19051 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
19052 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
19053 +AuStubVoid(au_plink_list, struct super_block *sb);
19054 +AuStubInt0(au_plink_test, struct inode *inode);
19055 +AuStub(struct dentry *, au_plink_lkup, return NULL,
19056 + struct inode *inode, aufs_bindex_t bindex);
19057 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
19058 + struct dentry *h_dentry);
19059 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
19060 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
19061 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
19062 +#endif /* CONFIG_PROC_FS */
19064 +#ifdef CONFIG_AUFS_XATTR
19066 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
19067 + unsigned int verbose);
19068 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
19069 +void au_xattr_init(struct super_block *sb);
19071 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
19072 + int ignore_flags, unsigned int verbose);
19073 +AuStubVoid(au_xattr_init, struct super_block *sb);
19076 +#ifdef CONFIG_FS_POSIX_ACL
19077 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
19078 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
19081 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19087 +struct au_sxattr {
19091 + const char *name;
19092 + const void *value;
19097 + struct posix_acl *acl;
19102 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19103 + struct au_sxattr *arg);
19106 +/* ---------------------------------------------------------------------- */
19108 +/* lock subclass for iinfo */
19110 + AuLsc_II_CHILD, /* child first */
19111 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
19112 + AuLsc_II_CHILD3, /* copyup dirs */
19113 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
19114 + AuLsc_II_PARENT2,
19115 + AuLsc_II_PARENT3, /* copyup dirs */
19116 + AuLsc_II_NEW_CHILD
19120 + * ii_read_lock_child, ii_write_lock_child,
19121 + * ii_read_lock_child2, ii_write_lock_child2,
19122 + * ii_read_lock_child3, ii_write_lock_child3,
19123 + * ii_read_lock_parent, ii_write_lock_parent,
19124 + * ii_read_lock_parent2, ii_write_lock_parent2,
19125 + * ii_read_lock_parent3, ii_write_lock_parent3,
19126 + * ii_read_lock_new_child, ii_write_lock_new_child,
19128 +#define AuReadLockFunc(name, lsc) \
19129 +static inline void ii_read_lock_##name(struct inode *i) \
19131 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19134 +#define AuWriteLockFunc(name, lsc) \
19135 +static inline void ii_write_lock_##name(struct inode *i) \
19137 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19140 +#define AuRWLockFuncs(name, lsc) \
19141 + AuReadLockFunc(name, lsc) \
19142 + AuWriteLockFunc(name, lsc)
19144 +AuRWLockFuncs(child, CHILD);
19145 +AuRWLockFuncs(child2, CHILD2);
19146 +AuRWLockFuncs(child3, CHILD3);
19147 +AuRWLockFuncs(parent, PARENT);
19148 +AuRWLockFuncs(parent2, PARENT2);
19149 +AuRWLockFuncs(parent3, PARENT3);
19150 +AuRWLockFuncs(new_child, NEW_CHILD);
19152 +#undef AuReadLockFunc
19153 +#undef AuWriteLockFunc
19154 +#undef AuRWLockFuncs
19156 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
19157 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
19158 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
19160 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
19161 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
19162 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
19164 +/* ---------------------------------------------------------------------- */
19166 +static inline void au_icntnr_init(struct au_icntnr *c)
19168 +#ifdef CONFIG_AUFS_DEBUG
19169 + c->vfs_inode.i_mode = 0;
19173 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
19175 + unsigned int gen;
19176 + struct au_iinfo *iinfo;
19177 + struct au_iigen *iigen;
19179 + iinfo = au_ii(inode);
19180 + iigen = &iinfo->ii_generation;
19181 + spin_lock(&iigen->ig_spin);
19183 + *igflags = iigen->ig_flags;
19184 + gen = iigen->ig_generation;
19185 + spin_unlock(&iigen->ig_spin);
19190 +/* tiny test for inode number */
19191 +/* tmpfs generation is too rough */
19192 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19194 + struct au_iinfo *iinfo;
19196 + iinfo = au_ii(inode);
19197 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19198 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19199 + && iinfo->ii_higen == h_inode->i_generation);
19202 +static inline void au_iigen_dec(struct inode *inode)
19204 + struct au_iinfo *iinfo;
19205 + struct au_iigen *iigen;
19207 + iinfo = au_ii(inode);
19208 + iigen = &iinfo->ii_generation;
19209 + spin_lock(&iigen->ig_spin);
19210 + iigen->ig_generation--;
19211 + spin_unlock(&iigen->ig_spin);
19214 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19219 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19225 +/* ---------------------------------------------------------------------- */
19227 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19228 + aufs_bindex_t bindex)
19230 + return iinfo->ii_hinode + bindex;
19233 +static inline int au_is_bad_inode(struct inode *inode)
19235 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19238 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19239 + aufs_bindex_t bindex)
19241 + IiMustAnyLock(inode);
19242 + return au_hinode(au_ii(inode), bindex)->hi_id;
19245 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19247 + IiMustAnyLock(inode);
19248 + return au_ii(inode)->ii_btop;
19251 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19253 + IiMustAnyLock(inode);
19254 + return au_ii(inode)->ii_bbot;
19257 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19259 + IiMustAnyLock(inode);
19260 + return au_ii(inode)->ii_vdir;
19263 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19265 + IiMustAnyLock(inode);
19266 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19269 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19271 + IiMustWriteLock(inode);
19272 + au_ii(inode)->ii_btop = bindex;
19275 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19277 + IiMustWriteLock(inode);
19278 + au_ii(inode)->ii_bbot = bindex;
19281 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19283 + IiMustWriteLock(inode);
19284 + au_ii(inode)->ii_vdir = vdir;
19287 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19289 + IiMustAnyLock(inode);
19290 + return au_hinode(au_ii(inode), bindex);
19293 +/* ---------------------------------------------------------------------- */
19295 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19298 + return pin->parent;
19302 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19304 + if (pin && pin->hdir)
19305 + return pin->hdir->hi_inode;
19309 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19312 + return pin->hdir;
19316 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19319 + pin->dentry = dentry;
19322 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19323 + unsigned char lflag)
19327 + au_fset_pin(pin->flags, DI_LOCKED);
19329 + au_fclr_pin(pin->flags, DI_LOCKED);
19333 +#if 0 /* reserved */
19334 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19337 + dput(pin->parent);
19338 + pin->parent = dget(parent);
19343 +/* ---------------------------------------------------------------------- */
19346 +#ifdef CONFIG_AUFS_HNOTIFY
19347 +struct au_hnotify_op {
19348 + void (*ctl)(struct au_hinode *hinode, int do_set);
19349 + int (*alloc)(struct au_hinode *hinode);
19352 + * if it returns true, the the caller should free hinode->hi_notify,
19353 + * otherwise ->free() frees it.
19355 + int (*free)(struct au_hinode *hinode,
19356 + struct au_hnotify *hn) __must_check;
19358 + void (*fin)(void);
19359 + int (*init)(void);
19361 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19362 + void (*fin_br)(struct au_branch *br);
19363 + int (*init_br)(struct au_branch *br, int perm);
19367 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19368 +void au_hn_free(struct au_hinode *hinode);
19369 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19370 +void au_hn_reset(struct inode *inode, unsigned int flags);
19371 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19372 + struct qstr *h_child_qstr, struct inode *h_child_inode);
19373 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19374 +int au_hnotify_init_br(struct au_branch *br, int perm);
19375 +void au_hnotify_fin_br(struct au_branch *br);
19376 +int __init au_hnotify_init(void);
19377 +void au_hnotify_fin(void);
19380 +extern const struct au_hnotify_op au_hnotify_op;
19383 +void au_hn_init(struct au_hinode *hinode)
19385 + hinode->hi_notify = NULL;
19388 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19390 + return hinode->hi_notify;
19394 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19395 + struct au_hinode *hinode __maybe_unused,
19396 + struct inode *inode __maybe_unused)
19397 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19398 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19399 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19400 + int do_set __maybe_unused)
19401 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19402 + unsigned int flags __maybe_unused)
19403 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19404 + struct au_branch *br __maybe_unused,
19405 + int perm __maybe_unused)
19406 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19407 + int perm __maybe_unused)
19408 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19409 +AuStubInt0(__init au_hnotify_init, void)
19410 +AuStubVoid(au_hnotify_fin, void)
19411 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19412 +#endif /* CONFIG_AUFS_HNOTIFY */
19414 +static inline void au_hn_suspend(struct au_hinode *hdir)
19416 + au_hn_ctl(hdir, /*do_set*/0);
19419 +static inline void au_hn_resume(struct au_hinode *hdir)
19421 + au_hn_ctl(hdir, /*do_set*/1);
19424 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19426 + inode_lock(hdir->hi_inode);
19427 + au_hn_suspend(hdir);
19430 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19431 + unsigned int sc __maybe_unused)
19433 + inode_lock_nested(hdir->hi_inode, sc);
19434 + au_hn_suspend(hdir);
19437 +#if 0 /* unused */
19438 +#include "vfsub.h"
19439 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19442 + inode_lock_shared_nested(hdir->hi_inode, sc);
19443 + au_hn_suspend(hdir);
19447 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19449 + au_hn_resume(hdir);
19450 + inode_unlock(hdir->hi_inode);
19453 +#endif /* __KERNEL__ */
19454 +#endif /* __AUFS_INODE_H__ */
19455 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19456 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19457 +++ linux/fs/aufs/ioctl.c 2018-08-12 23:43:05.460124736 +0200
19459 +// SPDX-License-Identifier: GPL-2.0
19461 + * Copyright (C) 2005-2018 Junjiro R. Okajima
19463 + * This program, aufs is free software; you can redistribute it and/or modify
19464 + * it under the terms of the GNU General Public License as published by
19465 + * the Free Software Foundation; either version 2 of the License, or
19466 + * (at your option) any later version.
19468 + * This program is distributed in the hope that it will be useful,
19469 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19470 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19471 + * GNU General Public License for more details.
19473 + * You should have received a copy of the GNU General Public License
19474 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19479 + * plink-management and readdir in userspace.
19480 + * assist the pathconf(3) wrapper library.
19482 + * File-based Hierarchical Storage Management.
19485 +#include <linux/compat.h>
19486 +#include <linux/file.h>
19489 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19492 + aufs_bindex_t wbi, bindex, bbot;
19493 + struct file *h_file;
19494 + struct super_block *sb;
19495 + struct dentry *root;
19496 + struct au_branch *br;
19497 + struct aufs_wbr_fd wbrfd = {
19498 + .oflags = au_dir_roflags,
19501 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19502 + | O_NOATIME | O_CLOEXEC;
19504 + AuDebugOn(wbrfd.oflags & ~valid);
19507 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19508 + if (unlikely(err)) {
19514 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19515 + wbrfd.oflags |= au_dir_roflags;
19516 + AuDbg("0%o\n", wbrfd.oflags);
19517 + if (unlikely(wbrfd.oflags & ~valid))
19521 + fd = get_unused_fd_flags(0);
19523 + if (unlikely(fd < 0))
19526 + h_file = ERR_PTR(-EINVAL);
19529 + sb = path->dentry->d_sb;
19530 + root = sb->s_root;
19531 + aufs_read_lock(root, AuLock_IR);
19532 + bbot = au_sbbot(sb);
19533 + if (wbrfd.brid >= 0) {
19534 + wbi = au_br_index(sb, wbrfd.brid);
19535 + if (unlikely(wbi < 0 || wbi > bbot))
19539 + h_file = ERR_PTR(-ENOENT);
19540 + br = au_sbr(sb, wbi);
19541 + if (!au_br_writable(br->br_perm)) {
19545 + bindex = wbi + 1;
19547 + for (; bindex <= bbot; bindex++) {
19548 + br = au_sbr(sb, bindex);
19549 + if (au_br_writable(br->br_perm)) {
19551 + br = au_sbr(sb, wbi);
19556 + AuDbg("wbi %d\n", wbi);
19558 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19562 + aufs_read_unlock(root, AuLock_IR);
19563 + err = PTR_ERR(h_file);
19564 + if (IS_ERR(h_file))
19567 + au_br_put(br); /* cf. au_h_open() */
19568 + fd_install(fd, h_file);
19570 + goto out; /* success */
19573 + put_unused_fd(fd);
19579 +/* ---------------------------------------------------------------------- */
19581 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19584 + struct dentry *dentry;
19587 + case AUFS_CTL_RDU:
19588 + case AUFS_CTL_RDU_INO:
19589 + err = au_rdu_ioctl(file, cmd, arg);
19592 + case AUFS_CTL_WBR_FD:
19593 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19596 + case AUFS_CTL_IBUSY:
19597 + err = au_ibusy_ioctl(file, arg);
19600 + case AUFS_CTL_BRINFO:
19601 + err = au_brinfo_ioctl(file, arg);
19604 + case AUFS_CTL_FHSM_FD:
19605 + dentry = file->f_path.dentry;
19606 + if (IS_ROOT(dentry))
19607 + err = au_fhsm_fd(dentry->d_sb, arg);
19613 + /* do not call the lower */
19614 + AuDbg("0x%x\n", cmd);
19622 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19627 + case AUFS_CTL_MVDOWN:
19628 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19631 + case AUFS_CTL_WBR_FD:
19632 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19636 + /* do not call the lower */
19637 + AuDbg("0x%x\n", cmd);
19645 +#ifdef CONFIG_COMPAT
19646 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19647 + unsigned long arg)
19652 + case AUFS_CTL_RDU:
19653 + case AUFS_CTL_RDU_INO:
19654 + err = au_rdu_compat_ioctl(file, cmd, arg);
19657 + case AUFS_CTL_IBUSY:
19658 + err = au_ibusy_compat_ioctl(file, arg);
19661 + case AUFS_CTL_BRINFO:
19662 + err = au_brinfo_compat_ioctl(file, arg);
19666 + err = aufs_ioctl_dir(file, cmd, arg);
19673 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19674 + unsigned long arg)
19676 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19679 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19680 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19681 +++ linux/fs/aufs/i_op_add.c 2018-08-12 23:43:05.456791299 +0200
19683 +// SPDX-License-Identifier: GPL-2.0
19685 + * Copyright (C) 2005-2018 Junjiro R. Okajima
19687 + * This program, aufs is free software; you can redistribute it and/or modify
19688 + * it under the terms of the GNU General Public License as published by
19689 + * the Free Software Foundation; either version 2 of the License, or
19690 + * (at your option) any later version.
19692 + * This program is distributed in the hope that it will be useful,
19693 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19694 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19695 + * GNU General Public License for more details.
19697 + * You should have received a copy of the GNU General Public License
19698 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19702 + * inode operations (add entry)
19708 + * final procedure of adding a new entry, except link(2).
19709 + * remove whiteout, instantiate, copyup the parent dir's times and size
19710 + * and update version.
19711 + * if it failed, re-create the removed whiteout.
19713 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19714 + struct dentry *wh_dentry, struct dentry *dentry)
19717 + aufs_bindex_t bwh;
19718 + struct path h_path;
19719 + struct super_block *sb;
19720 + struct inode *inode, *h_dir;
19721 + struct dentry *wh;
19726 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19727 + IMustLock(h_dir);
19728 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19729 + bwh = au_dbwh(dentry);
19730 + h_path.dentry = wh_dentry;
19731 + h_path.mnt = au_sbr_mnt(sb, bindex);
19732 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19734 + if (unlikely(err))
19738 + inode = au_new_inode(dentry, /*must_new*/1);
19739 + if (!IS_ERR(inode)) {
19740 + d_instantiate(dentry, inode);
19741 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19743 + au_dir_ts(dir, bindex);
19744 + inode_inc_iversion(dir);
19745 + au_fhsm_wrote(sb, bindex, /*force*/0);
19746 + return 0; /* success */
19749 + err = PTR_ERR(inode);
19754 + /* dir inode is locked */
19755 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19756 + rerr = PTR_ERR(wh);
19757 + if (IS_ERR(wh)) {
19758 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19759 + dentry, err, rerr);
19768 +static int au_d_may_add(struct dentry *dentry)
19773 + if (unlikely(d_unhashed(dentry)))
19775 + if (unlikely(d_really_is_positive(dentry)))
19781 + * simple tests for the adding inode operations.
19782 + * following the checks in vfs, plus the parent-child relationship.
19784 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19785 + struct dentry *h_parent, int isdir)
19789 + struct dentry *h_dentry;
19790 + struct inode *h_inode;
19792 + err = -ENAMETOOLONG;
19793 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19796 + h_dentry = au_h_dptr(dentry, bindex);
19797 + if (d_really_is_negative(dentry)) {
19799 + if (unlikely(d_is_positive(h_dentry)))
19802 + /* rename(2) case */
19804 + if (unlikely(d_is_negative(h_dentry)))
19806 + h_inode = d_inode(h_dentry);
19807 + if (unlikely(!h_inode->i_nlink))
19810 + h_mode = h_inode->i_mode;
19813 + if (unlikely(S_ISDIR(h_mode)))
19815 + } else if (unlikely(!S_ISDIR(h_mode))) {
19822 + /* expected parent dir is locked */
19823 + if (unlikely(h_parent != h_dentry->d_parent))
19832 + * initial procedure of adding a new entry.
19833 + * prepare writable branch and the parent dir, lock it,
19834 + * and lookup whiteout for the new entry.
19836 +static struct dentry*
19837 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19838 + struct dentry *src_dentry, struct au_pin *pin,
19839 + struct au_wr_dir_args *wr_dir_args)
19841 + struct dentry *wh_dentry, *h_parent;
19842 + struct super_block *sb;
19843 + struct au_branch *br;
19845 + unsigned int udba;
19846 + aufs_bindex_t bcpup;
19848 + AuDbg("%pd\n", dentry);
19850 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19852 + wh_dentry = ERR_PTR(err);
19853 + if (unlikely(err < 0))
19856 + sb = dentry->d_sb;
19857 + udba = au_opt_udba(sb);
19858 + err = au_pin(pin, dentry, bcpup, udba,
19859 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19860 + wh_dentry = ERR_PTR(err);
19861 + if (unlikely(err))
19864 + h_parent = au_pinned_h_parent(pin);
19865 + if (udba != AuOpt_UDBA_NONE
19866 + && au_dbtop(dentry) == bcpup)
19867 + err = au_may_add(dentry, bcpup, h_parent,
19868 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19869 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19870 + err = -ENAMETOOLONG;
19871 + wh_dentry = ERR_PTR(err);
19872 + if (unlikely(err))
19875 + br = au_sbr(sb, bcpup);
19877 + struct path tmp = {
19878 + .dentry = h_parent,
19879 + .mnt = au_br_mnt(br)
19881 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19884 + wh_dentry = NULL;
19885 + if (bcpup != au_dbwh(dentry))
19886 + goto out; /* success */
19889 + * ENAMETOOLONG here means that if we allowed create such name, then it
19890 + * would not be able to removed in the future. So we don't allow such
19891 + * name here and we don't handle ENAMETOOLONG differently here.
19893 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19896 + if (IS_ERR(wh_dentry))
19899 + return wh_dentry;
19902 +/* ---------------------------------------------------------------------- */
19904 +enum { Mknod, Symlink, Creat };
19905 +struct simple_arg {
19912 + struct vfsub_aopen_args *aopen;
19915 + const char *symname;
19924 +static int add_simple(struct inode *dir, struct dentry *dentry,
19925 + struct simple_arg *arg)
19928 + aufs_bindex_t btop;
19929 + unsigned char created;
19930 + const unsigned char try_aopen
19931 + = (arg->type == Creat && arg->u.c.try_aopen);
19932 + struct dentry *wh_dentry, *parent;
19933 + struct inode *h_dir;
19934 + struct super_block *sb;
19935 + struct au_branch *br;
19936 + /* to reuduce stack size */
19938 + struct au_dtime dt;
19939 + struct au_pin pin;
19940 + struct path h_path;
19941 + struct au_wr_dir_args wr_dir_args;
19944 + AuDbg("%pd\n", dentry);
19948 + a = kmalloc(sizeof(*a), GFP_NOFS);
19949 + if (unlikely(!a))
19951 + a->wr_dir_args.force_btgt = -1;
19952 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19954 + parent = dentry->d_parent; /* dir inode is locked */
19955 + if (!try_aopen) {
19956 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19957 + if (unlikely(err))
19960 + err = au_d_may_add(dentry);
19961 + if (unlikely(err))
19964 + di_write_lock_parent(parent);
19965 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19966 + &a->pin, &a->wr_dir_args);
19967 + err = PTR_ERR(wh_dentry);
19968 + if (IS_ERR(wh_dentry))
19971 + btop = au_dbtop(dentry);
19972 + sb = dentry->d_sb;
19973 + br = au_sbr(sb, btop);
19974 + a->h_path.dentry = au_h_dptr(dentry, btop);
19975 + a->h_path.mnt = au_br_mnt(br);
19976 + h_dir = au_pinned_h_dir(&a->pin);
19977 + switch (arg->type) {
19980 + if (!try_aopen || !h_dir->i_op->atomic_open)
19981 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19982 + arg->u.c.want_excl);
19984 + err = vfsub_atomic_open(h_dir, a->h_path.dentry,
19985 + arg->u.c.aopen, br);
19988 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
19991 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
19999 + err = epilog(dir, btop, wh_dentry, dentry);
20002 + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) {
20003 + /* no delegation since it is just created */
20004 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
20007 + AuIOErr("%pd revert failure(%d, %d)\n",
20008 + dentry, err, rerr);
20011 + au_dtime_revert(&a->dt);
20014 + if (!err && try_aopen && !h_dir->i_op->atomic_open)
20015 + *arg->u.c.aopen->opened |= FILE_CREATED;
20017 + au_unpin(&a->pin);
20022 + di_write_unlock(parent);
20024 + if (unlikely(err)) {
20025 + au_update_dbtop(dentry);
20029 + aufs_read_unlock(dentry, AuLock_DW);
20036 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
20039 + struct simple_arg arg = {
20046 + return add_simple(dir, dentry, &arg);
20049 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
20051 + struct simple_arg arg = {
20053 + .u.s.symname = symname
20055 + return add_simple(dir, dentry, &arg);
20058 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
20061 + struct simple_arg arg = {
20065 + .want_excl = want_excl
20068 + return add_simple(dir, dentry, &arg);
20071 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20072 + struct vfsub_aopen_args *aopen_args)
20074 + struct simple_arg arg = {
20077 + .mode = aopen_args->create_mode,
20078 + .want_excl = aopen_args->open_flag & O_EXCL,
20079 + .try_aopen = true,
20080 + .aopen = aopen_args
20083 + return add_simple(dir, dentry, &arg);
20086 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
20089 + aufs_bindex_t bindex;
20090 + struct super_block *sb;
20091 + struct dentry *parent, *h_parent, *h_dentry;
20092 + struct inode *h_dir, *inode;
20093 + struct vfsmount *h_mnt;
20094 + struct au_wr_dir_args wr_dir_args = {
20095 + .force_btgt = -1,
20096 + .flags = AuWrDir_TMPFILE
20099 + /* copy-up may happen */
20103 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20104 + if (unlikely(err))
20107 + err = au_di_init(dentry);
20108 + if (unlikely(err))
20112 + parent = d_find_any_alias(dir);
20113 + AuDebugOn(!parent);
20114 + di_write_lock_parent(parent);
20115 + if (unlikely(d_inode(parent) != dir))
20118 + err = au_digen_test(parent, au_sigen(sb));
20119 + if (unlikely(err))
20122 + bindex = au_dbtop(parent);
20123 + au_set_dbtop(dentry, bindex);
20124 + au_set_dbbot(dentry, bindex);
20125 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
20127 + if (unlikely(err < 0))
20130 + err = -EOPNOTSUPP;
20131 + h_dir = au_h_iptr(dir, bindex);
20132 + if (unlikely(!h_dir->i_op->tmpfile))
20135 + h_mnt = au_sbr_mnt(sb, bindex);
20136 + err = vfsub_mnt_want_write(h_mnt);
20137 + if (unlikely(err))
20140 + h_parent = au_h_dptr(parent, bindex);
20141 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
20142 + if (IS_ERR(h_dentry)) {
20143 + err = PTR_ERR(h_dentry);
20147 + au_set_dbtop(dentry, bindex);
20148 + au_set_dbbot(dentry, bindex);
20149 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
20150 + inode = au_new_inode(dentry, /*must_new*/1);
20151 + if (IS_ERR(inode)) {
20152 + err = PTR_ERR(inode);
20153 + au_set_h_dptr(dentry, bindex, NULL);
20154 + au_set_dbtop(dentry, -1);
20155 + au_set_dbbot(dentry, -1);
20157 + if (!inode->i_nlink)
20158 + set_nlink(inode, 1);
20159 + d_tmpfile(dentry, inode);
20160 + au_di(dentry)->di_tmpfile = 1;
20162 + /* update without i_mutex */
20163 + if (au_ibtop(dir) == au_dbtop(dentry))
20164 + au_cpup_attr_timesizes(dir);
20169 + vfsub_mnt_drop_write(h_mnt);
20171 + di_write_unlock(parent);
20173 + di_write_unlock(dentry);
20174 + if (unlikely(err)) {
20175 + au_di_fin(dentry);
20176 + dentry->d_fsdata = NULL;
20179 + si_read_unlock(sb);
20181 + inode_unlock(dir);
20185 +/* ---------------------------------------------------------------------- */
20187 +struct au_link_args {
20188 + aufs_bindex_t bdst, bsrc;
20189 + struct au_pin pin;
20190 + struct path h_path;
20191 + struct dentry *src_parent, *parent;
20194 +static int au_cpup_before_link(struct dentry *src_dentry,
20195 + struct au_link_args *a)
20198 + struct dentry *h_src_dentry;
20199 + struct au_cp_generic cpg = {
20200 + .dentry = src_dentry,
20205 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20208 + di_read_lock_parent(a->src_parent, AuLock_IR);
20209 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20210 + if (unlikely(err))
20213 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20214 + err = au_pin(&a->pin, src_dentry, a->bdst,
20215 + au_opt_udba(src_dentry->d_sb),
20216 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20217 + if (unlikely(err))
20220 + err = au_sio_cpup_simple(&cpg);
20221 + au_unpin(&a->pin);
20224 + di_read_unlock(a->src_parent, AuLock_IR);
20228 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20229 + struct au_link_args *a)
20232 + unsigned char plink;
20233 + aufs_bindex_t bbot;
20234 + struct dentry *h_src_dentry;
20235 + struct inode *h_inode, *inode, *delegated;
20236 + struct super_block *sb;
20237 + struct file *h_file;
20241 + sb = src_dentry->d_sb;
20242 + inode = d_inode(src_dentry);
20243 + if (au_ibtop(inode) <= a->bdst)
20244 + h_inode = au_h_iptr(inode, a->bdst);
20245 + if (!h_inode || !h_inode->i_nlink) {
20246 + /* copyup src_dentry as the name of dentry. */
20247 + bbot = au_dbbot(dentry);
20248 + if (bbot < a->bsrc)
20249 + au_set_dbbot(dentry, a->bsrc);
20250 + au_set_h_dptr(dentry, a->bsrc,
20251 + dget(au_h_dptr(src_dentry, a->bsrc)));
20252 + dget(a->h_path.dentry);
20253 + au_set_h_dptr(dentry, a->bdst, NULL);
20254 + AuDbg("temporary d_inode...\n");
20255 + spin_lock(&dentry->d_lock);
20256 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20257 + spin_unlock(&dentry->d_lock);
20258 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20259 + if (IS_ERR(h_file))
20260 + err = PTR_ERR(h_file);
20262 + struct au_cp_generic cpg = {
20263 + .dentry = dentry,
20268 + .flags = AuCpup_KEEPLINO
20270 + err = au_sio_cpup_simple(&cpg);
20271 + au_h_open_post(dentry, a->bsrc, h_file);
20273 + dput(a->h_path.dentry);
20274 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20276 + au_set_h_dptr(dentry, a->bdst,
20277 + a->h_path.dentry);
20279 + spin_lock(&dentry->d_lock);
20280 + dentry->d_inode = NULL; /* restore */
20281 + spin_unlock(&dentry->d_lock);
20282 + AuDbg("temporary d_inode...done\n");
20283 + au_set_h_dptr(dentry, a->bsrc, NULL);
20284 + au_set_dbbot(dentry, bbot);
20286 + /* the inode of src_dentry already exists on a.bdst branch */
20287 + h_src_dentry = d_find_alias(h_inode);
20288 + if (!h_src_dentry && au_plink_test(inode)) {
20290 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20291 + err = PTR_ERR(h_src_dentry);
20292 + if (IS_ERR(h_src_dentry))
20295 + if (unlikely(d_is_negative(h_src_dentry))) {
20296 + dput(h_src_dentry);
20297 + h_src_dentry = NULL;
20301 + if (h_src_dentry) {
20302 + delegated = NULL;
20303 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20304 + &a->h_path, &delegated);
20305 + if (unlikely(err == -EWOULDBLOCK)) {
20306 + pr_warn("cannot retry for NFSv4 delegation"
20307 + " for an internal link\n");
20310 + dput(h_src_dentry);
20312 + AuIOErr("no dentry found for hi%lu on b%d\n",
20313 + h_inode->i_ino, a->bdst);
20318 + if (!err && !plink)
20319 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20326 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20327 + struct dentry *dentry)
20330 + struct au_dtime dt;
20331 + struct au_link_args *a;
20332 + struct dentry *wh_dentry, *h_src_dentry;
20333 + struct inode *inode, *delegated;
20334 + struct super_block *sb;
20335 + struct au_wr_dir_args wr_dir_args = {
20336 + /* .force_btgt = -1, */
20337 + .flags = AuWrDir_ADD_ENTRY
20341 + inode = d_inode(src_dentry);
20342 + IMustLock(inode);
20345 + a = kzalloc(sizeof(*a), GFP_NOFS);
20346 + if (unlikely(!a))
20349 + a->parent = dentry->d_parent; /* dir inode is locked */
20350 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20351 + AuLock_NOPLM | AuLock_GEN);
20352 + if (unlikely(err))
20354 + err = au_d_linkable(src_dentry);
20355 + if (unlikely(err))
20357 + err = au_d_may_add(dentry);
20358 + if (unlikely(err))
20361 + a->src_parent = dget_parent(src_dentry);
20362 + wr_dir_args.force_btgt = au_ibtop(inode);
20364 + di_write_lock_parent(a->parent);
20365 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20366 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20368 + err = PTR_ERR(wh_dentry);
20369 + if (IS_ERR(wh_dentry))
20373 + sb = dentry->d_sb;
20374 + a->bdst = au_dbtop(dentry);
20375 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20376 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20377 + a->bsrc = au_ibtop(inode);
20378 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20379 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20380 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20381 + if (!h_src_dentry) {
20382 + a->bsrc = au_dbtop(src_dentry);
20383 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20384 + AuDebugOn(!h_src_dentry);
20385 + } else if (IS_ERR(h_src_dentry)) {
20386 + err = PTR_ERR(h_src_dentry);
20391 + * aufs doesn't touch the credential so
20392 + * security_dentry_create_files_as() is unnecrssary.
20394 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20395 + if (a->bdst < a->bsrc
20396 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20397 + err = au_cpup_or_link(src_dentry, dentry, a);
20399 + delegated = NULL;
20400 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20401 + &a->h_path, &delegated);
20402 + if (unlikely(err == -EWOULDBLOCK)) {
20403 + pr_warn("cannot retry for NFSv4 delegation"
20404 + " for an internal link\n");
20408 + dput(h_src_dentry);
20411 + * copyup src_dentry to the branch we process,
20412 + * and then link(2) to it.
20414 + dput(h_src_dentry);
20415 + if (a->bdst < a->bsrc
20416 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20417 + au_unpin(&a->pin);
20418 + di_write_unlock(a->parent);
20419 + err = au_cpup_before_link(src_dentry, a);
20420 + di_write_lock_parent(a->parent);
20422 + err = au_pin(&a->pin, dentry, a->bdst,
20424 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20425 + if (unlikely(err))
20429 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20431 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20432 + delegated = NULL;
20433 + err = vfsub_link(h_src_dentry,
20434 + au_pinned_h_dir(&a->pin),
20435 + &a->h_path, &delegated);
20436 + if (unlikely(err == -EWOULDBLOCK)) {
20437 + pr_warn("cannot retry"
20438 + " for NFSv4 delegation"
20439 + " for an internal link\n");
20445 + if (unlikely(err))
20449 + a->h_path.dentry = wh_dentry;
20450 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20452 + if (unlikely(err))
20456 + au_dir_ts(dir, a->bdst);
20457 + inode_inc_iversion(dir);
20458 + inc_nlink(inode);
20459 + inode->i_ctime = dir->i_ctime;
20460 + d_instantiate(dentry, au_igrab(inode));
20461 + if (d_unhashed(a->h_path.dentry))
20462 + /* some filesystem calls d_drop() */
20464 + /* some filesystems consume an inode even hardlink */
20465 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20466 + goto out_unpin; /* success */
20469 + /* no delegation since it is just created */
20470 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20471 + /*delegated*/NULL, /*force*/0);
20472 + if (unlikely(rerr)) {
20473 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20476 + au_dtime_revert(&dt);
20478 + au_unpin(&a->pin);
20482 + di_write_unlock(a->parent);
20483 + dput(a->src_parent);
20485 + if (unlikely(err)) {
20486 + au_update_dbtop(dentry);
20489 + aufs_read_and_write_unlock2(dentry, src_dentry);
20497 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20500 + aufs_bindex_t bindex;
20501 + unsigned char diropq;
20502 + struct path h_path;
20503 + struct dentry *wh_dentry, *parent, *opq_dentry;
20504 + struct inode *h_inode;
20505 + struct super_block *sb;
20507 + struct au_pin pin;
20508 + struct au_dtime dt;
20509 + } *a; /* reduce the stack usage */
20510 + struct au_wr_dir_args wr_dir_args = {
20511 + .force_btgt = -1,
20512 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20518 + a = kmalloc(sizeof(*a), GFP_NOFS);
20519 + if (unlikely(!a))
20522 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20523 + if (unlikely(err))
20525 + err = au_d_may_add(dentry);
20526 + if (unlikely(err))
20529 + parent = dentry->d_parent; /* dir inode is locked */
20530 + di_write_lock_parent(parent);
20531 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20532 + &a->pin, &wr_dir_args);
20533 + err = PTR_ERR(wh_dentry);
20534 + if (IS_ERR(wh_dentry))
20537 + sb = dentry->d_sb;
20538 + bindex = au_dbtop(dentry);
20539 + h_path.dentry = au_h_dptr(dentry, bindex);
20540 + h_path.mnt = au_sbr_mnt(sb, bindex);
20541 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20542 + if (unlikely(err))
20545 + /* make the dir opaque */
20547 + h_inode = d_inode(h_path.dentry);
20549 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20550 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20551 + opq_dentry = au_diropq_create(dentry, bindex);
20552 + inode_unlock(h_inode);
20553 + err = PTR_ERR(opq_dentry);
20554 + if (IS_ERR(opq_dentry))
20556 + dput(opq_dentry);
20560 + err = epilog(dir, bindex, wh_dentry, dentry);
20563 + goto out_unpin; /* success */
20568 + AuLabel(revert opq);
20569 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20570 + rerr = au_diropq_remove(dentry, bindex);
20571 + inode_unlock(h_inode);
20573 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20574 + dentry, err, rerr);
20580 + AuLabel(revert dir);
20581 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20583 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20584 + dentry, err, rerr);
20587 + au_dtime_revert(&a->dt);
20589 + au_unpin(&a->pin);
20592 + di_write_unlock(parent);
20594 + if (unlikely(err)) {
20595 + au_update_dbtop(dentry);
20598 + aufs_read_unlock(dentry, AuLock_DW);
20604 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20605 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20606 +++ linux/fs/aufs/i_op.c 2018-08-12 23:43:05.456791299 +0200
20608 +// SPDX-License-Identifier: GPL-2.0
20610 + * Copyright (C) 2005-2018 Junjiro R. Okajima
20612 + * This program, aufs is free software; you can redistribute it and/or modify
20613 + * it under the terms of the GNU General Public License as published by
20614 + * the Free Software Foundation; either version 2 of the License, or
20615 + * (at your option) any later version.
20617 + * This program is distributed in the hope that it will be useful,
20618 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20619 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20620 + * GNU General Public License for more details.
20622 + * You should have received a copy of the GNU General Public License
20623 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20627 + * inode operations (except add/del/rename)
20630 +#include <linux/device_cgroup.h>
20631 +#include <linux/fs_stack.h>
20632 +#include <linux/namei.h>
20633 +#include <linux/security.h>
20636 +static int h_permission(struct inode *h_inode, int mask,
20637 + struct path *h_path, int brperm)
20640 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20643 + if (write_mask && IS_IMMUTABLE(h_inode))
20647 + if (((mask & MAY_EXEC)
20648 + && S_ISREG(h_inode->i_mode)
20649 + && (path_noexec(h_path)
20650 + || !(h_inode->i_mode & 0111))))
20654 + * - skip the lower fs test in the case of write to ro branch.
20655 + * - nfs dir permission write check is optimized, but a policy for
20656 + * link/rename requires a real check.
20657 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20658 + * in this case, generic_permission() returns -EOPNOTSUPP.
20660 + if ((write_mask && !au_br_writable(brperm))
20661 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20662 + && write_mask && !(mask & MAY_READ))
20663 + || !h_inode->i_op->permission) {
20664 + /* AuLabel(generic_permission); */
20665 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20666 + err = generic_permission(h_inode, mask);
20667 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20668 + err = h_inode->i_op->permission(h_inode, mask);
20671 + /* AuLabel(h_inode->permission); */
20672 + err = h_inode->i_op->permission(h_inode, mask);
20677 + err = devcgroup_inode_permission(h_inode, mask);
20679 + err = security_inode_permission(h_inode, mask);
20683 + /* todo: do we need to call ima_path_check()? */
20684 + struct path h_path = {
20688 + err = ima_path_check(&h_path,
20689 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
20690 + IMA_COUNT_LEAVE);
20698 +static int aufs_permission(struct inode *inode, int mask)
20701 + aufs_bindex_t bindex, bbot;
20702 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20703 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20704 + struct inode *h_inode;
20705 + struct super_block *sb;
20706 + struct au_branch *br;
20708 + /* todo: support rcu-walk? */
20709 + if (mask & MAY_NOT_BLOCK)
20712 + sb = inode->i_sb;
20713 + si_read_lock(sb, AuLock_FLUSH);
20714 + ii_read_lock_child(inode);
20716 + err = au_iigen_test(inode, au_sigen(sb));
20717 + if (unlikely(err))
20723 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20724 + err = au_busy_or_stale();
20725 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20726 + if (unlikely(!h_inode
20727 + || (h_inode->i_mode & S_IFMT)
20728 + != (inode->i_mode & S_IFMT)))
20732 + bindex = au_ibtop(inode);
20733 + br = au_sbr(sb, bindex);
20734 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20737 + && !special_file(h_inode->i_mode)) {
20738 + /* test whether the upper writable branch exists */
20740 + for (; bindex >= 0; bindex--)
20741 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20749 + /* non-write to dir */
20751 + bbot = au_ibbot(inode);
20752 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20753 + h_inode = au_h_iptr(inode, bindex);
20755 + err = au_busy_or_stale();
20756 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20759 + br = au_sbr(sb, bindex);
20760 + err = h_permission(h_inode, mask, &br->br_path,
20766 + ii_read_unlock(inode);
20767 + si_read_unlock(sb);
20771 +/* ---------------------------------------------------------------------- */
20773 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20774 + unsigned int flags)
20776 + struct dentry *ret, *parent;
20777 + struct inode *inode;
20778 + struct super_block *sb;
20779 + int err, npositive;
20783 + /* todo: support rcu-walk? */
20784 + ret = ERR_PTR(-ECHILD);
20785 + if (flags & LOOKUP_RCU)
20788 + ret = ERR_PTR(-ENAMETOOLONG);
20789 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20793 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20794 + ret = ERR_PTR(err);
20795 + if (unlikely(err))
20798 + err = au_di_init(dentry);
20799 + ret = ERR_PTR(err);
20800 + if (unlikely(err))
20804 + npositive = 0; /* suppress a warning */
20805 + parent = dentry->d_parent; /* dir inode is locked */
20806 + di_read_lock_parent(parent, AuLock_IR);
20807 + err = au_alive_dir(parent);
20809 + err = au_digen_test(parent, au_sigen(sb));
20811 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20812 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20813 + AuLkup_ALLOW_NEG);
20816 + di_read_unlock(parent, AuLock_IR);
20817 + ret = ERR_PTR(err);
20818 + if (unlikely(err < 0))
20822 + inode = au_new_inode(dentry, /*must_new*/0);
20823 + if (IS_ERR(inode)) {
20824 + ret = (void *)inode;
20831 + atomic_inc(&inode->i_count);
20832 + ret = d_splice_alias(inode, dentry);
20834 + if (unlikely(d_need_lookup(dentry))) {
20835 + spin_lock(&dentry->d_lock);
20836 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20837 + spin_unlock(&dentry->d_lock);
20841 + if (!IS_ERR(ret)) {
20843 + if (ret && ret != dentry)
20844 + ii_write_unlock(inode);
20846 + ii_write_unlock(inode);
20853 + di_write_unlock(dentry);
20855 + si_read_unlock(sb);
20860 +/* ---------------------------------------------------------------------- */
20862 +struct aopen_node {
20863 + struct hlist_bl_node hblist;
20864 + struct file *file, *h_file;
20867 +static int au_do_aopen(struct inode *inode, struct file *file)
20869 + struct hlist_bl_head *aopen;
20870 + struct hlist_bl_node *pos;
20871 + struct aopen_node *node;
20872 + struct au_do_open_args args = {
20874 + .open = au_do_open_nondir
20877 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20878 + hlist_bl_lock(aopen);
20879 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20880 + if (node->file == file) {
20881 + args.h_file = node->h_file;
20884 + hlist_bl_unlock(aopen);
20885 + /* AuDebugOn(!args.h_file); */
20887 + return au_do_open(file, &args);
20890 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20891 + struct file *file, unsigned int open_flag,
20892 + umode_t create_mode, int *opened)
20894 + int err, unlocked, h_opened = *opened;
20895 + unsigned int lkup_flags;
20896 + struct dentry *parent, *d;
20897 + struct hlist_bl_head *aopen;
20898 + struct vfsub_aopen_args args = {
20899 + .open_flag = open_flag,
20900 + .create_mode = create_mode,
20901 + .opened = &h_opened
20903 + struct aopen_node aopen_node = {
20908 + AuDbg("open_flag 0%o\n", open_flag);
20909 + AuDbgDentry(dentry);
20912 + if (!au_di(dentry)) {
20913 + lkup_flags = LOOKUP_OPEN;
20914 + if (open_flag & O_CREAT)
20915 + lkup_flags |= LOOKUP_CREATE;
20916 + d = aufs_lookup(dir, dentry, lkup_flags);
20918 + err = PTR_ERR(d);
20923 + * obsoleted dentry found.
20924 + * another error will be returned later.
20930 + AuDbgDentry(dentry);
20933 + if (d_is_positive(dentry)
20934 + || d_unhashed(dentry)
20935 + || d_unlinked(dentry)
20936 + || !(open_flag & O_CREAT))
20937 + goto out_no_open;
20940 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20941 + if (unlikely(err))
20944 + parent = dentry->d_parent; /* dir is locked */
20945 + di_write_lock_parent(parent);
20946 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
20947 + if (unlikely(err))
20950 + AuDbgDentry(dentry);
20951 + if (d_is_positive(dentry))
20954 + args.file = get_empty_filp();
20955 + err = PTR_ERR(args.file);
20956 + if (IS_ERR(args.file))
20959 + args.file->f_flags = file->f_flags;
20960 + err = au_aopen_or_create(dir, dentry, &args);
20962 + AuDbgFile(args.file);
20963 + if (unlikely(err < 0)) {
20964 + if (h_opened & FILE_OPENED)
20967 + put_filp(args.file);
20970 + di_write_unlock(parent);
20971 + di_write_unlock(dentry);
20974 + /* some filesystems don't set FILE_CREATED while succeeded? */
20975 + *opened |= FILE_CREATED;
20976 + if (h_opened & FILE_OPENED)
20977 + aopen_node.h_file = args.file;
20979 + put_filp(args.file);
20980 + args.file = NULL;
20982 + aopen = &au_sbi(dir->i_sb)->si_aopen;
20983 + au_hbl_add(&aopen_node.hblist, aopen);
20984 + err = finish_open(file, dentry, au_do_aopen, opened);
20985 + au_hbl_del(&aopen_node.hblist, aopen);
20988 + if (aopen_node.h_file)
20989 + fput(aopen_node.h_file);
20993 + si_read_unlock(dentry->d_sb);
20995 + di_write_unlock(parent);
20996 + aufs_read_unlock(dentry, AuLock_DW);
20998 + AuDbgDentry(dentry);
20999 + if (unlikely(err < 0))
21002 + if (err >= 0 && !(*opened & FILE_CREATED)) {
21003 + AuLabel(out_no_open);
21005 + err = finish_no_open(file, dentry);
21008 + AuDbg("%pd%s%s\n", dentry,
21009 + (*opened & FILE_CREATED) ? " created" : "",
21010 + (*opened & FILE_OPENED) ? " opened" : "");
21016 +/* ---------------------------------------------------------------------- */
21018 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
21019 + const unsigned char add_entry, aufs_bindex_t bcpup,
21020 + aufs_bindex_t btop)
21023 + struct dentry *h_parent;
21024 + struct inode *h_dir;
21027 + IMustLock(d_inode(parent));
21029 + di_write_lock_parent(parent);
21032 + if (!au_h_dptr(parent, bcpup)) {
21033 + if (btop > bcpup)
21034 + err = au_cpup_dirs(dentry, bcpup);
21035 + else if (btop < bcpup)
21036 + err = au_cpdown_dirs(dentry, bcpup);
21040 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
21041 + h_parent = au_h_dptr(parent, bcpup);
21042 + h_dir = d_inode(h_parent);
21043 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
21044 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
21045 + /* todo: no unlock here */
21046 + inode_unlock_shared(h_dir);
21048 + AuDbg("bcpup %d\n", bcpup);
21050 + if (d_really_is_negative(dentry))
21051 + au_set_h_dptr(dentry, btop, NULL);
21052 + au_update_dbrange(dentry, /*do_put_zero*/0);
21057 + di_write_unlock(parent);
21059 + err = bcpup; /* success */
21066 + * decide the branch and the parent dir where we will create a new entry.
21067 + * returns new bindex or an error.
21068 + * copyup the parent dir if needed.
21070 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
21071 + struct au_wr_dir_args *args)
21074 + unsigned int flags;
21075 + aufs_bindex_t bcpup, btop, src_btop;
21076 + const unsigned char add_entry
21077 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
21078 + | au_ftest_wrdir(args->flags, TMPFILE);
21079 + struct super_block *sb;
21080 + struct dentry *parent;
21081 + struct au_sbinfo *sbinfo;
21083 + sb = dentry->d_sb;
21084 + sbinfo = au_sbi(sb);
21085 + parent = dget_parent(dentry);
21086 + btop = au_dbtop(dentry);
21088 + if (args->force_btgt < 0) {
21089 + if (src_dentry) {
21090 + src_btop = au_dbtop(src_dentry);
21091 + if (src_btop < btop)
21092 + bcpup = src_btop;
21093 + } else if (add_entry) {
21095 + if (au_ftest_wrdir(args->flags, ISDIR))
21096 + au_fset_wbr(flags, DIR);
21097 + err = AuWbrCreate(sbinfo, dentry, flags);
21101 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
21103 + err = AuWbrCopyup(sbinfo, dentry);
21105 + if (!IS_ROOT(dentry)) {
21106 + di_read_lock_parent(parent, !AuLock_IR);
21107 + err = AuWbrCopyup(sbinfo, dentry);
21108 + di_read_unlock(parent, !AuLock_IR);
21110 + err = AuWbrCopyup(sbinfo, dentry);
21113 + if (unlikely(err < 0))
21117 + bcpup = args->force_btgt;
21118 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21121 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21123 + if (bcpup == btop)
21124 + goto out; /* success */
21126 + /* copyup the new parent into the branch we process */
21127 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21129 + if (d_really_is_negative(dentry)) {
21130 + au_set_h_dptr(dentry, btop, NULL);
21131 + au_set_dbtop(dentry, bcpup);
21132 + au_set_dbbot(dentry, bcpup);
21134 + AuDebugOn(add_entry
21135 + && !au_ftest_wrdir(args->flags, TMPFILE)
21136 + && !au_h_dptr(dentry, bcpup));
21144 +/* ---------------------------------------------------------------------- */
21146 +void au_pin_hdir_unlock(struct au_pin *p)
21149 + au_hn_inode_unlock(p->hdir);
21152 +int au_pin_hdir_lock(struct au_pin *p)
21160 + /* even if an error happens later, keep this lock */
21161 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21164 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21169 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21170 + p->h_parent, p->br);
21176 +int au_pin_hdir_relock(struct au_pin *p)
21179 + struct inode *h_i;
21180 + struct dentry *h_d[] = {
21185 + err = au_pin_hdir_lock(p);
21186 + if (unlikely(err))
21189 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21192 + if (d_is_positive(h_d[i])) {
21193 + h_i = d_inode(h_d[i]);
21194 + err = !h_i->i_nlink;
21202 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21204 +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER)
21205 + p->hdir->hi_inode->i_rwsem.owner = task;
21209 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21212 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21213 + p->lsc_hi, 0, NULL, _RET_IP_);
21214 + au_pin_hdir_set_owner(p, current);
21218 +void au_pin_hdir_release(struct au_pin *p)
21221 + au_pin_hdir_set_owner(p, p->task);
21222 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
21226 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21228 + if (pin && pin->parent)
21229 + return au_h_dptr(pin->parent, pin->bindex);
21233 +void au_unpin(struct au_pin *p)
21236 + au_pin_hdir_unlock(p);
21237 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21238 + vfsub_mnt_drop_write(p->h_mnt);
21242 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21243 + di_read_unlock(p->parent, AuLock_IR);
21244 + iput(p->hdir->hi_inode);
21246 + p->parent = NULL;
21249 + /* do not clear p->task */
21252 +int au_do_pin(struct au_pin *p)
21255 + struct super_block *sb;
21256 + struct inode *h_dir;
21259 + sb = p->dentry->d_sb;
21260 + p->br = au_sbr(sb, p->bindex);
21261 + if (IS_ROOT(p->dentry)) {
21262 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21263 + p->h_mnt = au_br_mnt(p->br);
21264 + err = vfsub_mnt_want_write(p->h_mnt);
21265 + if (unlikely(err)) {
21266 + au_fclr_pin(p->flags, MNT_WRITE);
21273 + p->h_dentry = NULL;
21274 + if (p->bindex <= au_dbbot(p->dentry))
21275 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21277 + p->parent = dget_parent(p->dentry);
21278 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21279 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21282 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21283 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21285 + h_dir = p->hdir->hi_inode;
21289 + * if DI_LOCKED is not set, then p->parent may be different
21290 + * and h_parent can be NULL.
21292 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21294 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21295 + di_read_unlock(p->parent, AuLock_IR);
21297 + p->parent = NULL;
21301 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21302 + p->h_mnt = au_br_mnt(p->br);
21303 + err = vfsub_mnt_want_write(p->h_mnt);
21304 + if (unlikely(err)) {
21305 + au_fclr_pin(p->flags, MNT_WRITE);
21306 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21307 + di_read_unlock(p->parent, AuLock_IR);
21309 + p->parent = NULL;
21315 + err = au_pin_hdir_lock(p);
21317 + goto out; /* success */
21322 + pr_err("err %d\n", err);
21323 + err = au_busy_or_stale();
21328 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21329 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21330 + unsigned int udba, unsigned char flags)
21332 + p->dentry = dentry;
21334 + p->lsc_di = lsc_di;
21335 + p->lsc_hi = lsc_hi;
21336 + p->flags = flags;
21337 + p->bindex = bindex;
21339 + p->parent = NULL;
21343 + p->h_dentry = NULL;
21344 + p->h_parent = NULL;
21346 + p->task = current;
21349 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21350 + unsigned int udba, unsigned char flags)
21352 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21354 + return au_do_pin(pin);
21357 +/* ---------------------------------------------------------------------- */
21360 + * ->setattr() and ->getattr() are called in various cases.
21361 + * chmod, stat: dentry is revalidated.
21362 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21364 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21366 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21367 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21370 + struct dentry *parent;
21373 + if (au_digen_test(dentry, sigen)) {
21374 + parent = dget_parent(dentry);
21375 + di_read_lock_parent(parent, AuLock_IR);
21376 + err = au_refresh_dentry(dentry, parent);
21377 + di_read_unlock(parent, AuLock_IR);
21385 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21386 + struct au_icpup_args *a)
21390 + aufs_bindex_t btop, ibtop;
21391 + struct dentry *hi_wh, *parent;
21392 + struct inode *inode;
21393 + struct au_wr_dir_args wr_dir_args = {
21394 + .force_btgt = -1,
21398 + if (d_is_dir(dentry))
21399 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21400 + /* plink or hi_wh() case */
21401 + btop = au_dbtop(dentry);
21402 + inode = d_inode(dentry);
21403 + ibtop = au_ibtop(inode);
21404 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21405 + wr_dir_args.force_btgt = ibtop;
21406 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21407 + if (unlikely(err < 0))
21411 + au_fset_icpup(a->flags, DID_CPUP);
21414 + a->pin_flags = AuPin_MNT_WRITE;
21416 + if (!IS_ROOT(dentry)) {
21417 + au_fset_pin(a->pin_flags, DI_LOCKED);
21418 + parent = dget_parent(dentry);
21419 + di_write_lock_parent(parent);
21422 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21423 + if (unlikely(err))
21427 + a->h_path.dentry = au_h_dptr(dentry, btop);
21428 + a->h_inode = d_inode(a->h_path.dentry);
21429 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21430 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21431 + if (ia->ia_size < i_size_read(a->h_inode))
21432 + sz = ia->ia_size;
21433 + inode_unlock_shared(a->h_inode);
21437 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21438 + hi_wh = au_hi_wh(inode, a->btgt);
21440 + struct au_cp_generic cpg = {
21441 + .dentry = dentry,
21447 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21448 + if (unlikely(err))
21450 + hi_wh = au_hi_wh(inode, a->btgt);
21451 + /* todo: revalidate hi_wh? */
21456 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21457 + di_downgrade_lock(parent, AuLock_IR);
21461 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21462 + goto out; /* success */
21464 + if (!d_unhashed(dentry)) {
21465 + struct au_cp_generic cpg = {
21466 + .dentry = dentry,
21471 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21473 + err = au_sio_cpup_simple(&cpg);
21475 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21476 + } else if (!hi_wh)
21477 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21479 + a->h_path.dentry = hi_wh; /* do not dget here */
21482 + a->h_inode = d_inode(a->h_path.dentry);
21484 + goto out; /* success */
21485 + au_unpin(&a->pin);
21488 + di_write_unlock(parent);
21493 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21497 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21500 + struct inode *inode, *delegated;
21501 + struct super_block *sb;
21502 + struct file *file;
21503 + struct au_icpup_args *a;
21505 + inode = d_inode(dentry);
21506 + IMustLock(inode);
21508 + err = setattr_prepare(dentry, ia);
21509 + if (unlikely(err))
21513 + a = kzalloc(sizeof(*a), GFP_NOFS);
21514 + if (unlikely(!a))
21517 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21518 + ia->ia_valid &= ~ATTR_MODE;
21521 + sb = dentry->d_sb;
21522 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21523 + if (unlikely(err))
21526 + if (ia->ia_valid & ATTR_FILE) {
21527 + /* currently ftruncate(2) only */
21528 + AuDebugOn(!d_is_reg(dentry));
21529 + file = ia->ia_file;
21530 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21532 + if (unlikely(err))
21534 + ia->ia_file = au_hf_top(file);
21535 + a->udba = AuOpt_UDBA_NONE;
21537 + /* fchmod() doesn't pass ia_file */
21538 + a->udba = au_opt_udba(sb);
21539 + di_write_lock_child(dentry);
21540 + /* no d_unlinked(), to set UDBA_NONE for root */
21541 + if (d_unhashed(dentry))
21542 + a->udba = AuOpt_UDBA_NONE;
21543 + if (a->udba != AuOpt_UDBA_NONE) {
21544 + AuDebugOn(IS_ROOT(dentry));
21545 + err = au_reval_for_attr(dentry, au_sigen(sb));
21546 + if (unlikely(err))
21551 + err = au_pin_and_icpup(dentry, ia, a);
21552 + if (unlikely(err < 0))
21554 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21555 + ia->ia_file = NULL;
21556 + ia->ia_valid &= ~ATTR_FILE;
21559 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21560 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21561 + == (ATTR_MODE | ATTR_CTIME)) {
21562 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21563 + if (unlikely(err))
21565 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21566 + && (ia->ia_valid & ATTR_CTIME)) {
21567 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21568 + if (unlikely(err))
21572 + if (ia->ia_valid & ATTR_SIZE) {
21575 + if (ia->ia_size < i_size_read(inode))
21577 + truncate_setsize(inode, ia->ia_size);
21580 + if (ia->ia_valid & ATTR_FILE)
21582 + inode_unlock(a->h_inode);
21583 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21584 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21586 + delegated = NULL;
21588 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21590 + err = break_deleg_wait(&delegated);
21598 + * regardless aufs 'acl' option setting.
21599 + * why don't all acl-aware fs call this func from their ->setattr()?
21601 + if (!err && (ia->ia_valid & ATTR_MODE))
21602 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21604 + au_cpup_attr_changeable(inode);
21607 + inode_unlock(a->h_inode);
21608 + au_unpin(&a->pin);
21609 + if (unlikely(err))
21610 + au_update_dbtop(dentry);
21612 + di_write_unlock(dentry);
21614 + fi_write_unlock(file);
21615 + ia->ia_file = file;
21616 + ia->ia_valid |= ATTR_FILE;
21619 + si_read_unlock(sb);
21627 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21628 +static int au_h_path_to_set_attr(struct dentry *dentry,
21629 + struct au_icpup_args *a, struct path *h_path)
21632 + struct super_block *sb;
21634 + sb = dentry->d_sb;
21635 + a->udba = au_opt_udba(sb);
21636 + /* no d_unlinked(), to set UDBA_NONE for root */
21637 + if (d_unhashed(dentry))
21638 + a->udba = AuOpt_UDBA_NONE;
21639 + if (a->udba != AuOpt_UDBA_NONE) {
21640 + AuDebugOn(IS_ROOT(dentry));
21641 + err = au_reval_for_attr(dentry, au_sigen(sb));
21642 + if (unlikely(err))
21645 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21646 + if (unlikely(err < 0))
21649 + h_path->dentry = a->h_path.dentry;
21650 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21656 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21657 + struct au_sxattr *arg)
21660 + struct path h_path;
21661 + struct super_block *sb;
21662 + struct au_icpup_args *a;
21663 + struct inode *h_inode;
21665 + IMustLock(inode);
21668 + a = kzalloc(sizeof(*a), GFP_NOFS);
21669 + if (unlikely(!a))
21672 + sb = dentry->d_sb;
21673 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21674 + if (unlikely(err))
21677 + h_path.dentry = NULL; /* silence gcc */
21678 + di_write_lock_child(dentry);
21679 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21680 + if (unlikely(err))
21683 + inode_unlock(a->h_inode);
21684 + switch (arg->type) {
21685 + case AU_XATTR_SET:
21686 + AuDebugOn(d_is_negative(h_path.dentry));
21687 + err = vfsub_setxattr(h_path.dentry,
21688 + arg->u.set.name, arg->u.set.value,
21689 + arg->u.set.size, arg->u.set.flags);
21692 + err = -EOPNOTSUPP;
21693 + h_inode = d_inode(h_path.dentry);
21694 + if (h_inode->i_op->set_acl)
21695 + /* this will call posix_acl_update_mode */
21696 + err = h_inode->i_op->set_acl(h_inode,
21697 + arg->u.acl_set.acl,
21698 + arg->u.acl_set.type);
21702 + au_cpup_attr_timesizes(inode);
21704 + au_unpin(&a->pin);
21705 + if (unlikely(err))
21706 + au_update_dbtop(dentry);
21709 + di_write_unlock(dentry);
21710 + si_read_unlock(sb);
21719 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21720 + unsigned int nlink)
21724 + inode->i_mode = st->mode;
21725 + /* don't i_[ug]id_write() here */
21726 + inode->i_uid = st->uid;
21727 + inode->i_gid = st->gid;
21728 + inode->i_atime = st->atime;
21729 + inode->i_mtime = st->mtime;
21730 + inode->i_ctime = st->ctime;
21732 + au_cpup_attr_nlink(inode, /*force*/0);
21733 + if (S_ISDIR(inode->i_mode)) {
21734 + n = inode->i_nlink;
21737 + smp_mb(); /* for i_nlink */
21738 + /* 0 can happen */
21739 + set_nlink(inode, n);
21742 + spin_lock(&inode->i_lock);
21743 + inode->i_blocks = st->blocks;
21744 + i_size_write(inode, st->size);
21745 + spin_unlock(&inode->i_lock);
21749 + * common routine for aufs_getattr() and au_getxattr().
21750 + * returns zero or negative (an error).
21751 + * @dentry will be read-locked in success.
21753 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
21757 + unsigned int mnt_flags, sigen;
21758 + unsigned char udba_none;
21759 + aufs_bindex_t bindex;
21760 + struct super_block *sb, *h_sb;
21761 + struct inode *inode;
21763 + h_path->mnt = NULL;
21764 + h_path->dentry = NULL;
21767 + sb = dentry->d_sb;
21768 + mnt_flags = au_mntflags(sb);
21769 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21771 + if (unlikely(locked))
21772 + goto body; /* skip locking dinfo */
21774 + /* support fstat(2) */
21775 + if (!d_unlinked(dentry) && !udba_none) {
21776 + sigen = au_sigen(sb);
21777 + err = au_digen_test(dentry, sigen);
21779 + di_read_lock_child(dentry, AuLock_IR);
21780 + err = au_dbrange_test(dentry);
21781 + if (unlikely(err)) {
21782 + di_read_unlock(dentry, AuLock_IR);
21786 + AuDebugOn(IS_ROOT(dentry));
21787 + di_write_lock_child(dentry);
21788 + err = au_dbrange_test(dentry);
21790 + err = au_reval_for_attr(dentry, sigen);
21792 + di_downgrade_lock(dentry, AuLock_IR);
21794 + di_write_unlock(dentry);
21799 + di_read_lock_child(dentry, AuLock_IR);
21802 + inode = d_inode(dentry);
21803 + bindex = au_ibtop(inode);
21804 + h_path->mnt = au_sbr_mnt(sb, bindex);
21805 + h_sb = h_path->mnt->mnt_sb;
21807 + && !au_test_fs_bad_iattr(h_sb)
21809 + goto out; /* success */
21811 + if (au_dbtop(dentry) == bindex)
21812 + h_path->dentry = au_h_dptr(dentry, bindex);
21813 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21814 + h_path->dentry = au_plink_lkup(inode, bindex);
21815 + if (IS_ERR(h_path->dentry))
21816 + /* pretending success */
21817 + h_path->dentry = NULL;
21819 + dput(h_path->dentry);
21826 +static int aufs_getattr(const struct path *path, struct kstat *st,
21827 + u32 request, unsigned int query)
21830 + unsigned char positive;
21831 + struct path h_path;
21832 + struct dentry *dentry;
21833 + struct inode *inode;
21834 + struct super_block *sb;
21836 + dentry = path->dentry;
21837 + inode = d_inode(dentry);
21838 + sb = dentry->d_sb;
21839 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21840 + if (unlikely(err))
21842 + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
21843 + if (unlikely(err))
21845 + if (unlikely(!h_path.dentry))
21846 + /* illegally overlapped or something */
21847 + goto out_fill; /* pretending success */
21849 + positive = d_is_positive(h_path.dentry);
21851 + /* no vfsub version */
21852 + err = vfs_getattr(&h_path, st, request, query);
21855 + au_refresh_iattr(inode, st,
21856 + d_inode(h_path.dentry)->i_nlink);
21857 + goto out_fill; /* success */
21863 + generic_fillattr(inode, st);
21865 + di_read_unlock(dentry, AuLock_IR);
21867 + si_read_unlock(sb);
21873 +/* ---------------------------------------------------------------------- */
21875 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21876 + struct delayed_call *done)
21879 + struct dentry *h_dentry;
21880 + struct inode *h_inode;
21882 + aufs_bindex_t bindex;
21884 + ret = NULL; /* suppress a warning */
21889 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21890 + if (unlikely(err))
21893 + err = au_d_hashed_positive(dentry);
21894 + if (unlikely(err))
21898 + inode = d_inode(dentry);
21899 + bindex = au_ibtop(inode);
21900 + h_inode = au_h_iptr(inode, bindex);
21901 + if (unlikely(!h_inode->i_op->get_link))
21906 + if (au_dbtop(dentry) <= bindex) {
21907 + h_dentry = au_h_dptr(dentry, bindex);
21912 + h_dentry = d_find_any_alias(h_inode);
21913 + if (IS_ERR(h_dentry)) {
21914 + err = PTR_ERR(h_dentry);
21918 + if (unlikely(!h_dentry))
21922 + AuDbg("%ps\n", h_inode->i_op->get_link);
21923 + AuDbgDentry(h_dentry);
21924 + ret = vfs_get_link(h_dentry, done);
21927 + err = PTR_ERR(ret);
21930 + aufs_read_unlock(dentry, AuLock_IR);
21932 + if (unlikely(err))
21933 + ret = ERR_PTR(err);
21934 + AuTraceErrPtr(ret);
21938 +/* ---------------------------------------------------------------------- */
21940 +static int au_is_special(struct inode *inode)
21942 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
21945 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts, int flags)
21948 + aufs_bindex_t bindex;
21949 + struct super_block *sb;
21950 + struct inode *h_inode;
21951 + struct vfsmount *h_mnt;
21953 + sb = inode->i_sb;
21954 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
21955 + "unexpected s_flags 0x%lx", sb->s_flags);
21957 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
21959 + si_read_lock(sb, AuLock_FLUSH);
21960 + ii_write_lock_child(inode);
21963 + bindex = au_ibtop(inode);
21964 + h_inode = au_h_iptr(inode, bindex);
21965 + if (!au_test_ro(sb, bindex, inode)) {
21966 + h_mnt = au_sbr_mnt(sb, bindex);
21967 + err = vfsub_mnt_want_write(h_mnt);
21969 + err = vfsub_update_time(h_inode, ts, flags);
21970 + vfsub_mnt_drop_write(h_mnt);
21972 + } else if (au_is_special(h_inode)) {
21974 + * Never copy-up here.
21975 + * These special files may already be opened and used for
21976 + * communicating. If we copied it up, then the communication
21977 + * would be corrupted.
21979 + AuWarn1("timestamps for i%lu are ignored "
21980 + "since it is on readonly branch (hi%lu).\n",
21981 + inode->i_ino, h_inode->i_ino);
21982 + } else if (flags & ~S_ATIME) {
21984 + AuIOErr1("unexpected flags 0x%x\n", flags);
21989 + au_cpup_attr_timesizes(inode);
21990 + ii_write_unlock(inode);
21991 + si_read_unlock(sb);
21994 + if (!err && (flags & S_VERSION))
21995 + inode_inc_iversion(inode);
22000 +/* ---------------------------------------------------------------------- */
22002 +/* no getattr version will be set by module.c:aufs_init() */
22003 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
22005 + [AuIop_SYMLINK] = {
22006 + .permission = aufs_permission,
22007 +#ifdef CONFIG_FS_POSIX_ACL
22008 + .get_acl = aufs_get_acl,
22009 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
22012 + .setattr = aufs_setattr,
22013 + .getattr = aufs_getattr,
22015 +#ifdef CONFIG_AUFS_XATTR
22016 + .listxattr = aufs_listxattr,
22019 + .get_link = aufs_get_link,
22021 + /* .update_time = aufs_update_time */
22024 + .create = aufs_create,
22025 + .lookup = aufs_lookup,
22026 + .link = aufs_link,
22027 + .unlink = aufs_unlink,
22028 + .symlink = aufs_symlink,
22029 + .mkdir = aufs_mkdir,
22030 + .rmdir = aufs_rmdir,
22031 + .mknod = aufs_mknod,
22032 + .rename = aufs_rename,
22034 + .permission = aufs_permission,
22035 +#ifdef CONFIG_FS_POSIX_ACL
22036 + .get_acl = aufs_get_acl,
22037 + .set_acl = aufs_set_acl,
22040 + .setattr = aufs_setattr,
22041 + .getattr = aufs_getattr,
22043 +#ifdef CONFIG_AUFS_XATTR
22044 + .listxattr = aufs_listxattr,
22047 + .update_time = aufs_update_time,
22048 + .atomic_open = aufs_atomic_open,
22049 + .tmpfile = aufs_tmpfile
22051 + [AuIop_OTHER] = {
22052 + .permission = aufs_permission,
22053 +#ifdef CONFIG_FS_POSIX_ACL
22054 + .get_acl = aufs_get_acl,
22055 + .set_acl = aufs_set_acl,
22058 + .setattr = aufs_setattr,
22059 + .getattr = aufs_getattr,
22061 +#ifdef CONFIG_AUFS_XATTR
22062 + .listxattr = aufs_listxattr,
22065 + .update_time = aufs_update_time
22068 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
22069 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
22070 +++ linux/fs/aufs/i_op_del.c 2018-08-12 23:43:05.456791299 +0200
22072 +// SPDX-License-Identifier: GPL-2.0
22074 + * Copyright (C) 2005-2018 Junjiro R. Okajima
22076 + * This program, aufs is free software; you can redistribute it and/or modify
22077 + * it under the terms of the GNU General Public License as published by
22078 + * the Free Software Foundation; either version 2 of the License, or
22079 + * (at your option) any later version.
22081 + * This program is distributed in the hope that it will be useful,
22082 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22083 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22084 + * GNU General Public License for more details.
22086 + * You should have received a copy of the GNU General Public License
22087 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22091 + * inode operations (del entry)
22097 + * decide if a new whiteout for @dentry is necessary or not.
22098 + * when it is necessary, prepare the parent dir for the upper branch whose
22099 + * branch index is @bcpup for creation. the actual creation of the whiteout will
22100 + * be done by caller.
22102 + * 0: wh is unnecessary
22103 + * plus: wh is necessary
22106 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
22108 + int need_wh, err;
22109 + aufs_bindex_t btop;
22110 + struct super_block *sb;
22112 + sb = dentry->d_sb;
22113 + btop = au_dbtop(dentry);
22114 + if (*bcpup < 0) {
22116 + if (au_test_ro(sb, btop, d_inode(dentry))) {
22117 + err = AuWbrCopyup(au_sbi(sb), dentry);
22119 + if (unlikely(err < 0))
22123 + AuDebugOn(btop < *bcpup
22124 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22125 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22127 + if (*bcpup != btop) {
22128 + err = au_cpup_dirs(dentry, *bcpup);
22129 + if (unlikely(err))
22133 + struct au_dinfo *dinfo, *tmp;
22135 + need_wh = -ENOMEM;
22136 + dinfo = au_di(dentry);
22137 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22139 + au_di_cp(tmp, dinfo);
22140 + au_di_swap(tmp, dinfo);
22141 + /* returns the number of positive dentries */
22142 + need_wh = au_lkup_dentry(dentry, btop + 1,
22143 + /* AuLkup_IGNORE_PERM */ 0);
22144 + au_di_swap(tmp, dinfo);
22145 + au_rw_write_unlock(&tmp->di_rwsem);
22149 + AuDbg("need_wh %d\n", need_wh);
22157 + * simple tests for the del-entry operations.
22158 + * following the checks in vfs, plus the parent-child relationship.
22160 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22161 + struct dentry *h_parent, int isdir)
22165 + struct dentry *h_dentry, *h_latest;
22166 + struct inode *h_inode;
22168 + h_dentry = au_h_dptr(dentry, bindex);
22169 + if (d_really_is_positive(dentry)) {
22171 + if (unlikely(d_is_negative(h_dentry)))
22173 + h_inode = d_inode(h_dentry);
22174 + if (unlikely(!h_inode->i_nlink))
22177 + h_mode = h_inode->i_mode;
22180 + if (unlikely(S_ISDIR(h_mode)))
22182 + } else if (unlikely(!S_ISDIR(h_mode))) {
22187 + /* rename(2) case */
22189 + if (unlikely(d_is_positive(h_dentry)))
22194 + /* expected parent dir is locked */
22195 + if (unlikely(h_parent != h_dentry->d_parent))
22200 + * rmdir a dir may break the consistency on some filesystem.
22201 + * let's try heavy test.
22204 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22205 + && au_test_h_perm(d_inode(h_parent),
22206 + MAY_EXEC | MAY_WRITE)))
22209 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
22211 + if (IS_ERR(h_latest))
22213 + if (h_latest == h_dentry)
22222 + * decide the branch where we operate for @dentry. the branch index will be set
22223 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
22224 + * dir for reverting.
22225 + * when a new whiteout is necessary, create it.
22227 +static struct dentry*
22228 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22229 + struct au_dtime *dt, struct au_pin *pin)
22231 + struct dentry *wh_dentry;
22232 + struct super_block *sb;
22233 + struct path h_path;
22234 + int err, need_wh;
22235 + unsigned int udba;
22236 + aufs_bindex_t bcpup;
22238 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22239 + wh_dentry = ERR_PTR(need_wh);
22240 + if (unlikely(need_wh < 0))
22243 + sb = dentry->d_sb;
22244 + udba = au_opt_udba(sb);
22246 + err = au_pin(pin, dentry, bcpup, udba,
22247 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22248 + wh_dentry = ERR_PTR(err);
22249 + if (unlikely(err))
22252 + h_path.dentry = au_pinned_h_parent(pin);
22253 + if (udba != AuOpt_UDBA_NONE
22254 + && au_dbtop(dentry) == bcpup) {
22255 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22256 + wh_dentry = ERR_PTR(err);
22257 + if (unlikely(err))
22261 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22262 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22263 + wh_dentry = NULL;
22265 + goto out; /* success, no need to create whiteout */
22267 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22268 + if (IS_ERR(wh_dentry))
22271 + /* returns with the parent is locked and wh_dentry is dget-ed */
22272 + goto out; /* success */
22277 + return wh_dentry;
22281 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22282 + * in order to be revertible and save time for removing many child whiteouts
22284 + * returns 1 when there are too many child whiteout and caller should remove
22285 + * them asynchronously. returns 0 when the number of children is enough small to
22286 + * remove now or the branch fs is a remote fs.
22287 + * otherwise return an error.
22289 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22290 + struct au_nhash *whlist, struct inode *dir)
22292 + int rmdir_later, err, dirwh;
22293 + struct dentry *h_dentry;
22294 + struct super_block *sb;
22295 + struct inode *inode;
22297 + sb = dentry->d_sb;
22298 + SiMustAnyLock(sb);
22299 + h_dentry = au_h_dptr(dentry, bindex);
22300 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22301 + if (unlikely(err))
22304 + /* stop monitoring */
22305 + inode = d_inode(dentry);
22306 + au_hn_free(au_hi(inode, bindex));
22308 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22309 + dirwh = au_sbi(sb)->si_dirwh;
22310 + rmdir_later = (dirwh <= 1);
22311 + if (!rmdir_later)
22312 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22315 + return rmdir_later;
22318 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22319 + if (unlikely(err)) {
22320 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22321 + h_dentry, bindex, err);
22331 + * final procedure for deleting a entry.
22332 + * maintain dentry and iattr.
22334 +static void epilog(struct inode *dir, struct dentry *dentry,
22335 + aufs_bindex_t bindex)
22337 + struct inode *inode;
22339 + inode = d_inode(dentry);
22341 + inode->i_ctime = dir->i_ctime;
22343 + au_dir_ts(dir, bindex);
22344 + inode_inc_iversion(dir);
22348 + * when an error happened, remove the created whiteout and revert everything.
22350 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22351 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22352 + struct dentry *dentry, struct au_dtime *dt)
22355 + struct path h_path = {
22356 + .dentry = wh_dentry,
22357 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22360 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22362 + au_set_dbwh(dentry, bwh);
22363 + au_dtime_revert(dt);
22367 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22371 +/* ---------------------------------------------------------------------- */
22373 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22376 + aufs_bindex_t bwh, bindex, btop;
22377 + struct inode *inode, *h_dir, *delegated;
22378 + struct dentry *parent, *wh_dentry;
22379 + /* to reuduce stack size */
22381 + struct au_dtime dt;
22382 + struct au_pin pin;
22383 + struct path h_path;
22389 + a = kmalloc(sizeof(*a), GFP_NOFS);
22390 + if (unlikely(!a))
22393 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22394 + if (unlikely(err))
22396 + err = au_d_hashed_positive(dentry);
22397 + if (unlikely(err))
22399 + inode = d_inode(dentry);
22400 + IMustLock(inode);
22402 + if (unlikely(d_is_dir(dentry)))
22403 + goto out_unlock; /* possible? */
22405 + btop = au_dbtop(dentry);
22406 + bwh = au_dbwh(dentry);
22408 + parent = dentry->d_parent; /* dir inode is locked */
22409 + di_write_lock_parent(parent);
22410 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22412 + err = PTR_ERR(wh_dentry);
22413 + if (IS_ERR(wh_dentry))
22416 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22417 + a->h_path.dentry = au_h_dptr(dentry, btop);
22418 + dget(a->h_path.dentry);
22419 + if (bindex == btop) {
22420 + h_dir = au_pinned_h_dir(&a->pin);
22421 + delegated = NULL;
22422 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22423 + if (unlikely(err == -EWOULDBLOCK)) {
22424 + pr_warn("cannot retry for NFSv4 delegation"
22425 + " for an internal unlink\n");
22429 + /* dir inode is locked */
22430 + h_dir = d_inode(wh_dentry->d_parent);
22431 + IMustLock(h_dir);
22436 + vfsub_drop_nlink(inode);
22437 + epilog(dir, dentry, bindex);
22439 + /* update target timestamps */
22440 + if (bindex == btop) {
22441 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22443 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22445 + /* todo: this timestamp may be reverted later */
22446 + inode->i_ctime = h_dir->i_ctime;
22447 + goto out_unpin; /* success */
22454 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22461 + au_unpin(&a->pin);
22463 + dput(a->h_path.dentry);
22465 + di_write_unlock(parent);
22467 + aufs_read_unlock(dentry, AuLock_DW);
22474 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22476 + int err, rmdir_later;
22477 + aufs_bindex_t bwh, bindex, btop;
22478 + struct inode *inode;
22479 + struct dentry *parent, *wh_dentry, *h_dentry;
22480 + struct au_whtmp_rmdir *args;
22481 + /* to reuduce stack size */
22483 + struct au_dtime dt;
22484 + struct au_pin pin;
22490 + a = kmalloc(sizeof(*a), GFP_NOFS);
22491 + if (unlikely(!a))
22494 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22495 + if (unlikely(err))
22497 + err = au_alive_dir(dentry);
22498 + if (unlikely(err))
22500 + inode = d_inode(dentry);
22501 + IMustLock(inode);
22503 + if (unlikely(!d_is_dir(dentry)))
22504 + goto out_unlock; /* possible? */
22507 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22508 + if (unlikely(!args))
22511 + parent = dentry->d_parent; /* dir inode is locked */
22512 + di_write_lock_parent(parent);
22513 + err = au_test_empty(dentry, &args->whlist);
22514 + if (unlikely(err))
22517 + btop = au_dbtop(dentry);
22518 + bwh = au_dbwh(dentry);
22520 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22522 + err = PTR_ERR(wh_dentry);
22523 + if (IS_ERR(wh_dentry))
22526 + h_dentry = au_h_dptr(dentry, btop);
22529 + if (bindex == btop) {
22530 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22532 + rmdir_later = err;
22536 + /* stop monitoring */
22537 + au_hn_free(au_hi(inode, btop));
22539 + /* dir inode is locked */
22540 + IMustLock(d_inode(wh_dentry->d_parent));
22545 + vfsub_dead_dir(inode);
22546 + au_set_dbdiropq(dentry, -1);
22547 + epilog(dir, dentry, bindex);
22549 + if (rmdir_later) {
22550 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22554 + goto out_unpin; /* success */
22562 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22569 + au_unpin(&a->pin);
22573 + di_write_unlock(parent);
22575 + au_whtmp_rmdir_free(args);
22577 + aufs_read_unlock(dentry, AuLock_DW);
22584 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22585 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22586 +++ linux/fs/aufs/i_op_ren.c 2018-08-12 23:43:05.460124736 +0200
22588 +// SPDX-License-Identifier: GPL-2.0
22590 + * Copyright (C) 2005-2018 Junjiro R. Okajima
22592 + * This program, aufs is free software; you can redistribute it and/or modify
22593 + * it under the terms of the GNU General Public License as published by
22594 + * the Free Software Foundation; either version 2 of the License, or
22595 + * (at your option) any later version.
22597 + * This program is distributed in the hope that it will be useful,
22598 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22599 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22600 + * GNU General Public License for more details.
22602 + * You should have received a copy of the GNU General Public License
22603 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22607 + * inode operation (rename entry)
22608 + * todo: this is crazy monster
22613 +enum { AuSRC, AuDST, AuSrcDst };
22614 +enum { AuPARENT, AuCHILD, AuParentChild };
22616 +#define AuRen_ISDIR_SRC 1
22617 +#define AuRen_ISDIR_DST (1 << 1)
22618 +#define AuRen_ISSAMEDIR (1 << 2)
22619 +#define AuRen_WHSRC (1 << 3)
22620 +#define AuRen_WHDST (1 << 4)
22621 +#define AuRen_MNT_WRITE (1 << 5)
22622 +#define AuRen_DT_DSTDIR (1 << 6)
22623 +#define AuRen_DIROPQ_SRC (1 << 7)
22624 +#define AuRen_DIROPQ_DST (1 << 8)
22625 +#define AuRen_DIRREN (1 << 9)
22626 +#define AuRen_DROPPED_SRC (1 << 10)
22627 +#define AuRen_DROPPED_DST (1 << 11)
22628 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22629 +#define au_fset_ren(flags, name) \
22630 + do { (flags) |= AuRen_##name; } while (0)
22631 +#define au_fclr_ren(flags, name) \
22632 + do { (flags) &= ~AuRen_##name; } while (0)
22634 +#ifndef CONFIG_AUFS_DIRREN
22635 +#undef AuRen_DIRREN
22636 +#define AuRen_DIRREN 0
22639 +struct au_ren_args {
22641 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22643 + struct inode *dir, *inode;
22644 + struct au_hinode *hdir, *hinode;
22645 + struct au_dtime dt[AuParentChild];
22646 + aufs_bindex_t btop, bdiropq;
22649 +#define src_dentry sd[AuSRC].dentry
22650 +#define src_dir sd[AuSRC].dir
22651 +#define src_inode sd[AuSRC].inode
22652 +#define src_h_dentry sd[AuSRC].h_dentry
22653 +#define src_parent sd[AuSRC].parent
22654 +#define src_h_parent sd[AuSRC].h_parent
22655 +#define src_wh_dentry sd[AuSRC].wh_dentry
22656 +#define src_hdir sd[AuSRC].hdir
22657 +#define src_hinode sd[AuSRC].hinode
22658 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22659 +#define src_dt sd[AuSRC].dt
22660 +#define src_btop sd[AuSRC].btop
22661 +#define src_bdiropq sd[AuSRC].bdiropq
22663 +#define dst_dentry sd[AuDST].dentry
22664 +#define dst_dir sd[AuDST].dir
22665 +#define dst_inode sd[AuDST].inode
22666 +#define dst_h_dentry sd[AuDST].h_dentry
22667 +#define dst_parent sd[AuDST].parent
22668 +#define dst_h_parent sd[AuDST].h_parent
22669 +#define dst_wh_dentry sd[AuDST].wh_dentry
22670 +#define dst_hdir sd[AuDST].hdir
22671 +#define dst_hinode sd[AuDST].hinode
22672 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22673 +#define dst_dt sd[AuDST].dt
22674 +#define dst_btop sd[AuDST].btop
22675 +#define dst_bdiropq sd[AuDST].bdiropq
22677 + struct dentry *h_trap;
22678 + struct au_branch *br;
22679 + struct path h_path;
22680 + struct au_nhash whlist;
22681 + aufs_bindex_t btgt, src_bwh;
22684 + unsigned short auren_flags;
22685 + unsigned char flags; /* syscall parameter */
22686 + unsigned char exchange;
22689 + struct au_whtmp_rmdir *thargs;
22690 + struct dentry *h_dst;
22691 + struct au_hinode *h_root;
22694 +/* ---------------------------------------------------------------------- */
22697 + * functions for reverting.
22698 + * when an error happened in a single rename systemcall, we should revert
22699 + * everything as if nothing happened.
22700 + * we don't need to revert the copied-up/down the parent dir since they are
22704 +#define RevertFailure(fmt, ...) do { \
22705 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22706 + ##__VA_ARGS__, err, rerr); \
22710 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22713 + struct dentry *d;
22714 +#define src_or_dst(member) a->sd[idx].member
22716 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22717 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22718 + rerr = au_diropq_remove(d, a->btgt);
22719 + au_hn_inode_unlock(src_or_dst(hinode));
22720 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22722 + RevertFailure("remove diropq %pd", d);
22724 +#undef src_or_dst_
22727 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22729 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22730 + au_ren_do_rev_diropq(err, a, AuSRC);
22731 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22732 + au_ren_do_rev_diropq(err, a, AuDST);
22735 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22738 + struct inode *delegated;
22740 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22741 + a->src_h_parent);
22742 + rerr = PTR_ERR(a->h_path.dentry);
22743 + if (IS_ERR(a->h_path.dentry)) {
22744 + RevertFailure("lkup one %pd", a->src_dentry);
22748 + delegated = NULL;
22749 + rerr = vfsub_rename(a->dst_h_dir,
22750 + au_h_dptr(a->src_dentry, a->btgt),
22751 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22752 + if (unlikely(rerr == -EWOULDBLOCK)) {
22753 + pr_warn("cannot retry for NFSv4 delegation"
22754 + " for an internal rename\n");
22757 + d_drop(a->h_path.dentry);
22758 + dput(a->h_path.dentry);
22759 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22761 + RevertFailure("rename %pd", a->src_dentry);
22764 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22767 + struct inode *delegated;
22769 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22770 + a->dst_h_parent);
22771 + rerr = PTR_ERR(a->h_path.dentry);
22772 + if (IS_ERR(a->h_path.dentry)) {
22773 + RevertFailure("lkup one %pd", a->dst_dentry);
22776 + if (d_is_positive(a->h_path.dentry)) {
22777 + d_drop(a->h_path.dentry);
22778 + dput(a->h_path.dentry);
22782 + delegated = NULL;
22783 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22784 + &delegated, a->flags);
22785 + if (unlikely(rerr == -EWOULDBLOCK)) {
22786 + pr_warn("cannot retry for NFSv4 delegation"
22787 + " for an internal rename\n");
22790 + d_drop(a->h_path.dentry);
22791 + dput(a->h_path.dentry);
22793 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22795 + RevertFailure("rename %pd", a->h_dst);
22798 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22802 + a->h_path.dentry = a->src_wh_dentry;
22803 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22804 + au_set_dbwh(a->src_dentry, a->src_bwh);
22806 + RevertFailure("unlink %pd", a->src_wh_dentry);
22808 +#undef RevertFailure
22810 +/* ---------------------------------------------------------------------- */
22813 + * when we have to copyup the renaming entry, do it with the rename-target name
22814 + * in order to minimize the cost (the later actual rename is unnecessary).
22815 + * otherwise rename it on the target branch.
22817 +static int au_ren_or_cpup(struct au_ren_args *a)
22820 + struct dentry *d;
22821 + struct inode *delegated;
22823 + d = a->src_dentry;
22824 + if (au_dbtop(d) == a->btgt) {
22825 + a->h_path.dentry = a->dst_h_dentry;
22826 + AuDebugOn(au_dbtop(d) != a->btgt);
22827 + delegated = NULL;
22828 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22829 + a->dst_h_dir, &a->h_path, &delegated,
22831 + if (unlikely(err == -EWOULDBLOCK)) {
22832 + pr_warn("cannot retry for NFSv4 delegation"
22833 + " for an internal rename\n");
22839 + if (!err && a->h_dst)
22840 + /* it will be set to dinfo later */
22846 +/* cf. aufs_rmdir() */
22847 +static int au_ren_del_whtmp(struct au_ren_args *a)
22850 + struct inode *dir;
22852 + dir = a->dst_dir;
22853 + SiMustAnyLock(dir->i_sb);
22854 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22855 + au_sbi(dir->i_sb)->si_dirwh)
22856 + || au_test_fs_remote(a->h_dst->d_sb)) {
22857 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22858 + if (unlikely(err))
22859 + pr_warn("failed removing whtmp dir %pd (%d), "
22860 + "ignored.\n", a->h_dst, err);
22862 + au_nhash_wh_free(&a->thargs->whlist);
22863 + a->thargs->whlist = a->whlist;
22864 + a->whlist.nh_num = 0;
22865 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22867 + a->thargs = NULL;
22873 +/* make it 'opaque' dir. */
22874 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22877 + struct dentry *d, *diropq;
22878 +#define src_or_dst(member) a->sd[idx].member
22881 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22882 + src_or_dst(bdiropq) = au_dbdiropq(d);
22883 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22884 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22885 + diropq = au_diropq_create(d, a->btgt);
22886 + au_hn_inode_unlock(src_or_dst(hinode));
22887 + if (IS_ERR(diropq))
22888 + err = PTR_ERR(diropq);
22892 +#undef src_or_dst_
22896 +static int au_ren_diropq(struct au_ren_args *a)
22899 + unsigned char always;
22900 + struct dentry *d;
22903 + d = a->dst_dentry; /* already renamed on the branch */
22904 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22905 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22906 + && !au_ftest_ren(a->auren_flags, DIRREN)
22907 + && a->btgt != au_dbdiropq(a->src_dentry)
22908 + && (a->dst_wh_dentry
22909 + || a->btgt <= au_dbdiropq(d)
22910 + /* hide the lower to keep xino */
22911 + /* the lowers may not be a dir, but we hide them anyway */
22912 + || a->btgt < au_dbbot(d)
22915 + err = au_ren_do_diropq(a, AuSRC);
22916 + if (unlikely(err))
22918 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22920 + if (!a->exchange)
22921 + goto out; /* success */
22923 + d = a->src_dentry; /* already renamed on the branch */
22924 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22925 + && a->btgt != au_dbdiropq(a->dst_dentry)
22926 + && (a->btgt < au_dbdiropq(d)
22927 + || a->btgt < au_dbbot(d)
22929 + AuDbgDentry(a->src_dentry);
22930 + AuDbgDentry(a->dst_dentry);
22931 + err = au_ren_do_diropq(a, AuDST);
22932 + if (unlikely(err))
22933 + goto out_rev_src;
22934 + au_fset_ren(a->auren_flags, DIROPQ_DST);
22936 + goto out; /* success */
22939 + AuDbg("err %d, reverting src\n", err);
22940 + au_ren_rev_diropq(err, a);
22945 +static int do_rename(struct au_ren_args *a)
22948 + struct dentry *d, *h_d;
22950 + if (!a->exchange) {
22951 + /* prepare workqueue args for asynchronous rmdir */
22952 + h_d = a->dst_h_dentry;
22953 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22954 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
22955 + && d_is_positive(h_d)) {
22957 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
22959 + if (unlikely(!a->thargs))
22961 + a->h_dst = dget(h_d);
22964 + /* create whiteout for src_dentry */
22965 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
22966 + a->src_bwh = au_dbwh(a->src_dentry);
22967 + AuDebugOn(a->src_bwh >= 0);
22968 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
22969 + a->src_h_parent);
22970 + err = PTR_ERR(a->src_wh_dentry);
22971 + if (IS_ERR(a->src_wh_dentry))
22975 + /* lookup whiteout for dentry */
22976 + if (au_ftest_ren(a->auren_flags, WHDST)) {
22977 + h_d = au_wh_lkup(a->dst_h_parent,
22978 + &a->dst_dentry->d_name, a->br);
22979 + err = PTR_ERR(h_d);
22982 + if (d_is_negative(h_d))
22985 + a->dst_wh_dentry = h_d;
22988 + /* rename dentry to tmpwh */
22990 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
22991 + if (unlikely(err))
22994 + d = a->dst_dentry;
22995 + au_set_h_dptr(d, a->btgt, NULL);
22996 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
22997 + if (unlikely(err))
22999 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
23003 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
23005 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
23006 + && d_is_positive(a->dst_h_dentry)
23007 + && a->src_btop != a->btgt);
23010 + /* rename by vfs_rename or cpup */
23011 + err = au_ren_or_cpup(a);
23012 + if (unlikely(err))
23013 + /* leave the copied-up one */
23016 + /* make dir opaque */
23017 + err = au_ren_diropq(a);
23018 + if (unlikely(err))
23021 + /* update target timestamps */
23022 + if (a->exchange) {
23023 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
23024 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
23025 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23026 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23028 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
23029 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
23030 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23031 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23033 + if (!a->exchange) {
23034 + /* remove whiteout for dentry */
23035 + if (a->dst_wh_dentry) {
23036 + a->h_path.dentry = a->dst_wh_dentry;
23037 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
23039 + if (unlikely(err))
23043 + /* remove whtmp */
23045 + au_ren_del_whtmp(a); /* ignore this error */
23047 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
23050 + goto out_success;
23053 + au_ren_rev_diropq(err, a);
23055 + au_ren_rev_rename(err, a);
23059 + au_ren_rev_whtmp(err, a);
23061 + dput(a->dst_wh_dentry);
23062 + a->dst_wh_dentry = NULL;
23064 + if (a->src_wh_dentry)
23065 + au_ren_rev_whsrc(err, a);
23067 + dput(a->src_wh_dentry);
23068 + dput(a->dst_wh_dentry);
23072 + au_whtmp_rmdir_free(a->thargs);
23073 + a->thargs = NULL;
23079 +/* ---------------------------------------------------------------------- */
23082 + * test if @dentry dir can be rename destination or not.
23083 + * success means, it is a logically empty dir.
23085 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
23087 + return au_test_empty(dentry, whlist);
23091 + * test if @a->src_dentry dir can be rename source or not.
23092 + * if it can, return 0.
23094 + * - it is a logically empty dir.
23095 + * - or, it exists on writable branch and has no children including whiteouts
23096 + * on the lower branch unless DIRREN is on.
23098 +static int may_rename_srcdir(struct au_ren_args *a)
23101 + unsigned int rdhash;
23102 + aufs_bindex_t btop, btgt;
23103 + struct dentry *dentry;
23104 + struct super_block *sb;
23105 + struct au_sbinfo *sbinfo;
23107 + dentry = a->src_dentry;
23108 + sb = dentry->d_sb;
23109 + sbinfo = au_sbi(sb);
23110 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
23111 + au_fset_ren(a->auren_flags, DIRREN);
23114 + btop = au_dbtop(dentry);
23115 + if (btop != btgt) {
23116 + struct au_nhash whlist;
23118 + SiMustAnyLock(sb);
23119 + rdhash = sbinfo->si_rdhash;
23121 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23123 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23124 + if (unlikely(err))
23126 + err = au_test_empty(dentry, &whlist);
23127 + au_nhash_wh_free(&whlist);
23131 + if (btop == au_dbtaildir(dentry))
23132 + return 0; /* success */
23134 + err = au_test_empty_lower(dentry);
23137 + if (err == -ENOTEMPTY) {
23138 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23141 + AuWarn1("renaming dir who has child(ren) on multiple "
23142 + "branches, is not supported\n");
23149 +/* side effect: sets whlist and h_dentry */
23150 +static int au_ren_may_dir(struct au_ren_args *a)
23153 + unsigned int rdhash;
23154 + struct dentry *d;
23156 + d = a->dst_dentry;
23157 + SiMustAnyLock(d->d_sb);
23160 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23161 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23163 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23164 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23165 + if (unlikely(err))
23168 + if (!a->exchange) {
23169 + au_set_dbtop(d, a->dst_btop);
23170 + err = may_rename_dstdir(d, &a->whlist);
23171 + au_set_dbtop(d, a->btgt);
23173 + err = may_rename_srcdir(a);
23175 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23176 + if (unlikely(err))
23179 + d = a->src_dentry;
23180 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23181 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23182 + err = may_rename_srcdir(a);
23183 + if (unlikely(err)) {
23184 + au_nhash_wh_free(&a->whlist);
23185 + a->whlist.nh_num = 0;
23192 +/* ---------------------------------------------------------------------- */
23195 + * simple tests for rename.
23196 + * following the checks in vfs, plus the parent-child relationship.
23198 +static int au_may_ren(struct au_ren_args *a)
23201 + struct inode *h_inode;
23203 + if (a->src_btop == a->btgt) {
23204 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23205 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23206 + if (unlikely(err))
23209 + if (unlikely(a->src_h_dentry == a->h_trap))
23214 + if (a->dst_btop != a->btgt)
23217 + err = -ENOTEMPTY;
23218 + if (unlikely(a->dst_h_dentry == a->h_trap))
23222 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23223 + if (d_really_is_negative(a->dst_dentry)) {
23224 + if (d_is_negative(a->dst_h_dentry))
23225 + err = au_may_add(a->dst_dentry, a->btgt,
23226 + a->dst_h_parent, isdir);
23228 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23230 + h_inode = d_inode(a->dst_h_dentry);
23231 + if (h_inode->i_nlink)
23232 + err = au_may_del(a->dst_dentry, a->btgt,
23233 + a->dst_h_parent, isdir);
23237 + if (unlikely(err == -ENOENT || err == -EEXIST))
23243 +/* ---------------------------------------------------------------------- */
23248 + * - src_dir and dir by lock_rename()
23249 + * - inode if exitsts
23252 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23254 + * + di_write_lock2_child()
23255 + * + di_write_lock_child()
23256 + * + ii_write_lock_child()
23257 + * + di_write_lock_child2()
23258 + * + ii_write_lock_child2()
23259 + * + src_parent and parent
23260 + * + di_write_lock_parent()
23261 + * + ii_write_lock_parent()
23262 + * + di_write_lock_parent2()
23263 + * + ii_write_lock_parent2()
23264 + * + lower src_dir and dir by vfsub_lock_rename()
23265 + * + verify the every relationships between child and parent. if any
23266 + * of them failed, unlock all and return -EBUSY.
23268 +static void au_ren_unlock(struct au_ren_args *a)
23270 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23271 + a->dst_h_parent, a->dst_hdir);
23272 + if (au_ftest_ren(a->auren_flags, DIRREN)
23274 + au_hn_inode_unlock(a->h_root);
23275 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23276 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23279 +static int au_ren_lock(struct au_ren_args *a)
23282 + unsigned int udba;
23285 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23286 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23287 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23288 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23290 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23291 + if (unlikely(err))
23293 + au_fset_ren(a->auren_flags, MNT_WRITE);
23294 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23295 + struct dentry *root;
23296 + struct inode *dir;
23299 + * sbinfo is already locked, so this ii_read_lock is
23300 + * unnecessary. but our debugging feature checks it.
23302 + root = a->src_inode->i_sb->s_root;
23303 + if (root != a->src_parent && root != a->dst_parent) {
23304 + dir = d_inode(root);
23305 + ii_read_lock_parent3(dir);
23306 + a->h_root = au_hi(dir, a->btgt);
23307 + ii_read_unlock(dir);
23308 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23311 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23312 + a->dst_h_parent, a->dst_hdir);
23313 + udba = au_opt_udba(a->src_dentry->d_sb);
23314 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23315 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23316 + err = au_busy_or_stale();
23317 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23318 + err = au_h_verify(a->src_h_dentry, udba,
23319 + d_inode(a->src_h_parent), a->src_h_parent,
23321 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23322 + err = au_h_verify(a->dst_h_dentry, udba,
23323 + d_inode(a->dst_h_parent), a->dst_h_parent,
23326 + goto out; /* success */
23328 + err = au_busy_or_stale();
23329 + au_ren_unlock(a);
23335 +/* ---------------------------------------------------------------------- */
23337 +static void au_ren_refresh_dir(struct au_ren_args *a)
23339 + struct inode *dir;
23341 + dir = a->dst_dir;
23342 + inode_inc_iversion(dir);
23343 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23344 + /* is this updating defined in POSIX? */
23345 + au_cpup_attr_timesizes(a->src_inode);
23346 + au_cpup_attr_nlink(dir, /*force*/1);
23348 + au_dir_ts(dir, a->btgt);
23350 + if (a->exchange) {
23351 + dir = a->src_dir;
23352 + inode_inc_iversion(dir);
23353 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23354 + /* is this updating defined in POSIX? */
23355 + au_cpup_attr_timesizes(a->dst_inode);
23356 + au_cpup_attr_nlink(dir, /*force*/1);
23358 + au_dir_ts(dir, a->btgt);
23361 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23364 + dir = a->src_dir;
23365 + inode_inc_iversion(dir);
23366 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23367 + au_cpup_attr_nlink(dir, /*force*/1);
23368 + au_dir_ts(dir, a->btgt);
23371 +static void au_ren_refresh(struct au_ren_args *a)
23373 + aufs_bindex_t bbot, bindex;
23374 + struct dentry *d, *h_d;
23375 + struct inode *i, *h_i;
23376 + struct super_block *sb;
23378 + d = a->dst_dentry;
23381 + /* already dget-ed by au_ren_or_cpup() */
23382 + au_set_h_dptr(d, a->btgt, a->h_dst);
23384 + i = a->dst_inode;
23386 + if (!a->exchange) {
23387 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23388 + vfsub_drop_nlink(i);
23390 + vfsub_dead_dir(i);
23391 + au_cpup_attr_timesizes(i);
23393 + au_update_dbrange(d, /*do_put_zero*/1);
23395 + au_cpup_attr_nlink(i, /*force*/1);
23398 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23399 + au_set_h_dptr(d, bindex, NULL);
23400 + bbot = au_dbbot(d);
23401 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23402 + au_set_h_dptr(d, bindex, NULL);
23403 + au_update_dbrange(d, /*do_put_zero*/0);
23407 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23408 + d_drop(a->src_dentry);
23409 + if (au_ftest_ren(a->auren_flags, DIRREN))
23410 + au_set_dbwh(a->src_dentry, -1);
23414 + d = a->src_dentry;
23415 + au_set_dbwh(d, -1);
23416 + bbot = au_dbbot(d);
23417 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23418 + h_d = au_h_dptr(d, bindex);
23420 + au_set_h_dptr(d, bindex, NULL);
23422 + au_set_dbbot(d, a->btgt);
23425 + i = a->src_inode;
23426 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23427 + return; /* success */
23429 + bbot = au_ibbot(i);
23430 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23431 + h_i = au_h_iptr(i, bindex);
23433 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23434 + /* ignore this error */
23435 + au_set_h_iptr(i, bindex, NULL, 0);
23438 + au_set_ibbot(i, a->btgt);
23441 +/* ---------------------------------------------------------------------- */
23443 +/* mainly for link(2) and rename(2) */
23444 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23446 + aufs_bindex_t bdiropq, bwh;
23447 + struct dentry *parent;
23448 + struct au_branch *br;
23450 + parent = dentry->d_parent;
23451 + IMustLock(d_inode(parent)); /* dir is locked */
23453 + bdiropq = au_dbdiropq(parent);
23454 + bwh = au_dbwh(dentry);
23455 + br = au_sbr(dentry->d_sb, btgt);
23456 + if (au_br_rdonly(br)
23457 + || (0 <= bdiropq && bdiropq < btgt)
23458 + || (0 <= bwh && bwh < btgt))
23461 + AuDbg("btgt %d\n", btgt);
23465 +/* sets src_btop, dst_btop and btgt */
23466 +static int au_ren_wbr(struct au_ren_args *a)
23469 + struct au_wr_dir_args wr_dir_args = {
23470 + /* .force_btgt = -1, */
23471 + .flags = AuWrDir_ADD_ENTRY
23474 + a->src_btop = au_dbtop(a->src_dentry);
23475 + a->dst_btop = au_dbtop(a->dst_dentry);
23476 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23477 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23478 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23479 + wr_dir_args.force_btgt = a->src_btop;
23480 + if (a->dst_inode && a->dst_btop < a->src_btop)
23481 + wr_dir_args.force_btgt = a->dst_btop;
23482 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23483 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23486 + au_update_dbtop(a->dst_dentry);
23491 +static void au_ren_dt(struct au_ren_args *a)
23493 + a->h_path.dentry = a->src_h_parent;
23494 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23495 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23496 + a->h_path.dentry = a->dst_h_parent;
23497 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23500 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23501 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23505 + a->h_path.dentry = a->src_h_dentry;
23506 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23507 + if (d_is_positive(a->dst_h_dentry)) {
23508 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23509 + a->h_path.dentry = a->dst_h_dentry;
23510 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23514 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23516 + struct dentry *h_d;
23517 + struct inode *h_inode;
23519 + au_dtime_revert(a->src_dt + AuPARENT);
23520 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23521 + au_dtime_revert(a->dst_dt + AuPARENT);
23523 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23524 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23525 + h_inode = d_inode(h_d);
23526 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23527 + au_dtime_revert(a->src_dt + AuCHILD);
23528 + inode_unlock(h_inode);
23530 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23531 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23532 + h_inode = d_inode(h_d);
23533 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23534 + au_dtime_revert(a->dst_dt + AuCHILD);
23535 + inode_unlock(h_inode);
23540 +/* ---------------------------------------------------------------------- */
23542 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23543 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23544 + unsigned int _flags)
23546 + int err, lock_flags;
23548 + /* reduce stack space */
23549 + struct au_ren_args *a;
23550 + struct au_pin pin;
23552 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23553 + IMustLock(_src_dir);
23554 + IMustLock(_dst_dir);
23557 + if (unlikely(_flags & RENAME_WHITEOUT))
23561 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23562 + a = kzalloc(sizeof(*a), GFP_NOFS);
23563 + if (unlikely(!a))
23566 + a->flags = _flags;
23567 + a->exchange = _flags & RENAME_EXCHANGE;
23568 + a->src_dir = _src_dir;
23569 + a->src_dentry = _src_dentry;
23570 + a->src_inode = NULL;
23571 + if (d_really_is_positive(a->src_dentry))
23572 + a->src_inode = d_inode(a->src_dentry);
23573 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23574 + a->dst_dir = _dst_dir;
23575 + a->dst_dentry = _dst_dentry;
23576 + a->dst_inode = NULL;
23577 + if (d_really_is_positive(a->dst_dentry))
23578 + a->dst_inode = d_inode(a->dst_dentry);
23579 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23580 + if (a->dst_inode) {
23582 + * if EXCHANGE && src is non-dir && dst is dir,
23583 + * dst is not locked.
23585 + /* IMustLock(a->dst_inode); */
23586 + au_igrab(a->dst_inode);
23590 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23591 + if (d_is_dir(a->src_dentry)) {
23592 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23593 + if (unlikely(!a->exchange
23594 + && d_really_is_positive(a->dst_dentry)
23595 + && !d_is_dir(a->dst_dentry)))
23597 + lock_flags |= AuLock_DIRS;
23599 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23600 + au_fset_ren(a->auren_flags, ISDIR_DST);
23601 + if (unlikely(!a->exchange
23602 + && d_really_is_positive(a->src_dentry)
23603 + && !d_is_dir(a->src_dentry)))
23605 + lock_flags |= AuLock_DIRS;
23607 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23609 + if (unlikely(err))
23612 + err = au_d_hashed_positive(a->src_dentry);
23613 + if (unlikely(err))
23616 + if (a->dst_inode) {
23618 + * If it is a dir, VFS unhash it before this
23619 + * function. It means we cannot rely upon d_unhashed().
23621 + if (unlikely(!a->dst_inode->i_nlink))
23623 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23624 + err = au_d_hashed_positive(a->dst_dentry);
23625 + if (unlikely(err && !a->exchange))
23627 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23629 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23633 + * is it possible?
23634 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23635 + * there may exist a problem somewhere else.
23638 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23641 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23642 + di_write_lock_parent(a->dst_parent);
23644 + /* which branch we process */
23645 + err = au_ren_wbr(a);
23646 + if (unlikely(err < 0))
23648 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23649 + a->h_path.mnt = au_br_mnt(a->br);
23651 + /* are they available to be renamed */
23652 + err = au_ren_may_dir(a);
23653 + if (unlikely(err))
23654 + goto out_children;
23656 + /* prepare the writable parent dir on the same branch */
23657 + if (a->dst_btop == a->btgt) {
23658 + au_fset_ren(a->auren_flags, WHDST);
23660 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23661 + if (unlikely(err))
23662 + goto out_children;
23666 + if (!a->exchange) {
23667 + if (a->src_dir != a->dst_dir) {
23669 + * this temporary unlock is safe,
23670 + * because both dir->i_mutex are locked.
23672 + di_write_unlock(a->dst_parent);
23673 + di_write_lock_parent(a->src_parent);
23674 + err = au_wr_dir_need_wh(a->src_dentry,
23675 + au_ftest_ren(a->auren_flags,
23678 + di_write_unlock(a->src_parent);
23679 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23681 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23683 + err = au_wr_dir_need_wh(a->src_dentry,
23684 + au_ftest_ren(a->auren_flags,
23688 + if (unlikely(err < 0))
23689 + goto out_children;
23691 + au_fset_ren(a->auren_flags, WHSRC);
23694 + if (a->src_btop != a->btgt) {
23695 + err = au_pin(&pin, a->src_dentry, a->btgt,
23696 + au_opt_udba(a->src_dentry->d_sb),
23697 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23699 + struct au_cp_generic cpg = {
23700 + .dentry = a->src_dentry,
23702 + .bsrc = a->src_btop,
23705 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23707 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23708 + err = au_sio_cpup_simple(&cpg);
23711 + if (unlikely(err))
23712 + goto out_children;
23713 + a->src_btop = a->btgt;
23714 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23715 + if (!a->exchange)
23716 + au_fset_ren(a->auren_flags, WHSRC);
23720 + if (a->exchange && a->dst_inode
23721 + && a->dst_btop != a->btgt) {
23722 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23723 + au_opt_udba(a->dst_dentry->d_sb),
23724 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23726 + struct au_cp_generic cpg = {
23727 + .dentry = a->dst_dentry,
23729 + .bsrc = a->dst_btop,
23732 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23734 + err = au_sio_cpup_simple(&cpg);
23737 + if (unlikely(err))
23738 + goto out_children;
23739 + a->dst_btop = a->btgt;
23740 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23743 + /* lock them all */
23744 + err = au_ren_lock(a);
23745 + if (unlikely(err))
23746 + /* leave the copied-up one */
23747 + goto out_children;
23749 + if (!a->exchange) {
23750 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23751 + err = au_may_ren(a);
23752 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23753 + err = -ENAMETOOLONG;
23754 + if (unlikely(err))
23758 + /* store timestamps to be revertible */
23761 + /* store dirren info */
23762 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23763 + err = au_dr_rename(a->src_dentry, a->btgt,
23764 + &a->dst_dentry->d_name, &rev);
23766 + if (unlikely(err))
23771 + err = do_rename(a);
23772 + if (unlikely(err))
23775 + if (au_ftest_ren(a->auren_flags, DIRREN))
23776 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23778 + /* update dir attributes */
23779 + au_ren_refresh_dir(a);
23781 + /* dput/iput all lower dentries */
23782 + au_ren_refresh(a);
23784 + goto out_hdir; /* success */
23787 + if (au_ftest_ren(a->auren_flags, DIRREN))
23788 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23790 + au_ren_rev_dt(err, a);
23792 + au_ren_unlock(a);
23794 + au_nhash_wh_free(&a->whlist);
23795 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23796 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23797 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23798 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23802 + if (d_unhashed(a->src_dentry))
23803 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23804 + if (d_unhashed(a->dst_dentry))
23805 + au_fset_ren(a->auren_flags, DROPPED_DST);
23806 + if (!a->exchange)
23807 + d_move(a->src_dentry, a->dst_dentry);
23809 + d_exchange(a->src_dentry, a->dst_dentry);
23810 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23811 + d_drop(a->dst_dentry);
23813 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23814 + d_drop(a->src_dentry);
23816 + au_update_dbtop(a->dst_dentry);
23817 + if (!a->dst_inode)
23818 + d_drop(a->dst_dentry);
23820 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23821 + di_write_unlock(a->dst_parent);
23823 + di_write_unlock2(a->src_parent, a->dst_parent);
23825 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23827 + iput(a->dst_inode);
23829 + au_whtmp_rmdir_free(a->thargs);
23835 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23836 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23837 +++ linux/fs/aufs/Kconfig 2018-06-04 09:08:09.181412645 +0200
23839 +# SPDX-License-Identifier: GPL-2.0
23841 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23843 + Aufs is a stackable unification filesystem such as Unionfs,
23844 + which unifies several directories and provides a merged single
23846 + In the early days, aufs was entirely re-designed and
23847 + re-implemented Unionfs Version 1.x series. Introducing many
23848 + original ideas, approaches and improvements, it becomes totally
23849 + different from Unionfs while keeping the basic features.
23853 + prompt "Maximum number of branches"
23854 + default AUFS_BRANCH_MAX_127
23856 + Specifies the maximum number of branches (or member directories)
23857 + in a single aufs. The larger value consumes more system
23858 + resources and has a minor impact to performance.
23859 +config AUFS_BRANCH_MAX_127
23862 + Specifies the maximum number of branches (or member directories)
23863 + in a single aufs. The larger value consumes more system
23864 + resources and has a minor impact to performance.
23865 +config AUFS_BRANCH_MAX_511
23868 + Specifies the maximum number of branches (or member directories)
23869 + in a single aufs. The larger value consumes more system
23870 + resources and has a minor impact to performance.
23871 +config AUFS_BRANCH_MAX_1023
23874 + Specifies the maximum number of branches (or member directories)
23875 + in a single aufs. The larger value consumes more system
23876 + resources and has a minor impact to performance.
23877 +config AUFS_BRANCH_MAX_32767
23880 + Specifies the maximum number of branches (or member directories)
23881 + in a single aufs. The larger value consumes more system
23882 + resources and has a minor impact to performance.
23885 +config AUFS_SBILIST
23887 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23890 + Automatic configuration for internal use.
23891 + When aufs supports Magic SysRq or /proc, enabled automatically.
23893 +config AUFS_HNOTIFY
23894 + bool "Detect direct branch access (bypassing aufs)"
23896 + If you want to modify files on branches directly, eg. bypassing aufs,
23897 + and want aufs to detect the changes of them fully, then enable this
23898 + option and use 'udba=notify' mount option.
23899 + Currently there is only one available configuration, "fsnotify".
23900 + It will have a negative impact to the performance.
23901 + See detail in aufs.5.
23904 + prompt "method" if AUFS_HNOTIFY
23905 + default AUFS_HFSNOTIFY
23906 +config AUFS_HFSNOTIFY
23911 +config AUFS_EXPORT
23912 + bool "NFS-exportable aufs"
23913 + depends on EXPORTFS
23915 + If you want to export your mounted aufs via NFS, then enable this
23916 + option. There are several requirements for this configuration.
23917 + See detail in aufs.5.
23919 +config AUFS_INO_T_64
23921 + depends on AUFS_EXPORT
23922 + depends on 64BIT && !(ALPHA || S390)
23925 + Automatic configuration for internal use.
23926 + /* typedef unsigned long/int __kernel_ino_t */
23927 + /* alpha and s390x are int */
23930 + bool "support for XATTR/EA (including Security Labels)"
23932 + If your branch fs supports XATTR/EA and you want to make them
23933 + available in aufs too, then enable this opsion and specify the
23934 + branch attributes for EA.
23935 + See detail in aufs.5.
23938 + bool "File-based Hierarchical Storage Management"
23940 + Hierarchical Storage Management (or HSM) is a well-known feature
23941 + in the storage world. Aufs provides this feature as file-based.
23942 + with multiple branches.
23943 + These multiple branches are prioritized, ie. the topmost one
23944 + should be the fastest drive and be used heavily.
23947 + bool "Readdir in userspace"
23949 + Aufs has two methods to provide a merged view for a directory,
23950 + by a user-space library and by kernel-space natively. The latter
23951 + is always enabled but sometimes large and slow.
23952 + If you enable this option, install the library in aufs2-util
23953 + package, and set some environment variables for your readdir(3),
23954 + then the work will be handled in user-space which generally
23955 + shows better performance in most cases.
23956 + See detail in aufs.5.
23958 +config AUFS_DIRREN
23959 + bool "Workaround for rename(2)-ing a directory"
23961 + By default, aufs returns EXDEV error in renameing a dir who has
23962 + his child on the lower branch, since it is a bad idea to issue
23963 + rename(2) internally for every lower branch. But user may not
23964 + accept this behaviour. So here is a workaround to allow such
23965 + rename(2) and store some extra infromation on the writable
23966 + branch. Obviously this costs high (and I don't like it).
23967 + To use this feature, you need to enable this configuration AND
23968 + to specify the mount option `dirren.'
23969 + See details in aufs.5 and the design documents.
23972 + bool "Show whiteouts"
23974 + If you want to make the whiteouts in aufs visible, then enable
23975 + this option and specify 'shwh' mount option. Although it may
23976 + sounds like philosophy or something, but in technically it
23977 + simply shows the name of whiteout with keeping its behaviour.
23979 +config AUFS_BR_RAMFS
23980 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
23982 + If you want to use ramfs as an aufs branch fs, then enable this
23983 + option. Generally tmpfs is recommended.
23984 + Aufs prohibited them to be a branch fs by default, because
23985 + initramfs becomes unusable after switch_root or something
23986 + generally. If you sets initramfs as an aufs branch and boot your
23987 + system by switch_root, you will meet a problem easily since the
23988 + files in initramfs may be inaccessible.
23989 + Unless you are going to use ramfs as an aufs branch fs without
23990 + switch_root or something, leave it N.
23992 +config AUFS_BR_FUSE
23993 + bool "Fuse fs as an aufs branch"
23994 + depends on FUSE_FS
23997 + If you want to use fuse-based userspace filesystem as an aufs
23998 + branch fs, then enable this option.
23999 + It implements the internal poll(2) operation which is
24000 + implemented by fuse only (curretnly).
24005 + Automatic configuration for internal use.
24007 +config AUFS_BR_HFSPLUS
24008 + bool "Hfsplus as an aufs branch"
24009 + depends on HFSPLUS_FS
24012 + If you want to use hfsplus fs as an aufs branch fs, then enable
24013 + this option. This option introduces a small overhead at
24014 + copying-up a file on hfsplus.
24016 +config AUFS_BDEV_LOOP
24018 + depends on BLK_DEV_LOOP
24021 + Automatic configuration for internal use.
24022 + Convert =[ym] into =y.
24025 + bool "Debug aufs"
24027 + Enable this to compile aufs internal debug code.
24028 + It will have a negative impact to the performance.
24030 +config AUFS_MAGIC_SYSRQ
24032 + depends on AUFS_DEBUG && MAGIC_SYSRQ
24035 + Automatic configuration for internal use.
24036 + When aufs supports Magic SysRq, enabled automatically.
24038 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24039 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24040 +++ linux/fs/aufs/loop.c 2018-08-12 23:43:05.460124736 +0200
24042 +// SPDX-License-Identifier: GPL-2.0
24044 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24046 + * This program, aufs is free software; you can redistribute it and/or modify
24047 + * it under the terms of the GNU General Public License as published by
24048 + * the Free Software Foundation; either version 2 of the License, or
24049 + * (at your option) any later version.
24051 + * This program is distributed in the hope that it will be useful,
24052 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24053 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24054 + * GNU General Public License for more details.
24056 + * You should have received a copy of the GNU General Public License
24057 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24061 + * support for loopback block device as a branch
24066 +/* added into drivers/block/loop.c */
24067 +static struct file *(*backing_file_func)(struct super_block *sb);
24070 + * test if two lower dentries have overlapping branches.
24072 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24074 + struct super_block *h_sb;
24075 + struct file *backing_file;
24077 + if (unlikely(!backing_file_func)) {
24078 + /* don't load "loop" module here */
24079 + backing_file_func = symbol_get(loop_backing_file);
24080 + if (unlikely(!backing_file_func))
24081 + /* "loop" module is not loaded */
24085 + h_sb = h_adding->d_sb;
24086 + backing_file = backing_file_func(h_sb);
24087 + if (!backing_file)
24090 + h_adding = backing_file->f_path.dentry;
24092 + * h_adding can be local NFS.
24093 + * in this case aufs cannot detect the loop.
24095 + if (unlikely(h_adding->d_sb == sb))
24097 + return !!au_test_subdir(h_adding, sb->s_root);
24100 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24101 +int au_test_loopback_kthread(void)
24104 + struct task_struct *tsk = current;
24105 + char c, comm[sizeof(tsk->comm)];
24108 + if (tsk->flags & PF_KTHREAD) {
24109 + get_task_comm(comm, tsk);
24111 + ret = ('0' <= c && c <= '9'
24112 + && !strncmp(comm, "loop", 4));
24118 +/* ---------------------------------------------------------------------- */
24120 +#define au_warn_loopback_step 16
24121 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24122 +static unsigned long *au_warn_loopback_array;
24124 +void au_warn_loopback(struct super_block *h_sb)
24126 + int i, new_nelem;
24127 + unsigned long *a, magic;
24128 + static DEFINE_SPINLOCK(spin);
24130 + magic = h_sb->s_magic;
24131 + spin_lock(&spin);
24132 + a = au_warn_loopback_array;
24133 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24134 + if (a[i] == magic) {
24135 + spin_unlock(&spin);
24139 + /* h_sb is new to us, print it */
24140 + if (i < au_warn_loopback_nelem) {
24145 + /* expand the array */
24146 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24147 + a = au_kzrealloc(au_warn_loopback_array,
24148 + au_warn_loopback_nelem * sizeof(unsigned long),
24149 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24150 + /*may_shrink*/0);
24152 + au_warn_loopback_nelem = new_nelem;
24153 + au_warn_loopback_array = a;
24158 + spin_unlock(&spin);
24159 + AuWarn1("realloc failed, ignored\n");
24163 + spin_unlock(&spin);
24164 + pr_warn("you may want to try another patch for loopback file "
24165 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24168 +int au_loopback_init(void)
24171 + struct super_block *sb __maybe_unused;
24173 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
24176 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24177 + sizeof(unsigned long), GFP_NOFS);
24178 + if (unlikely(!au_warn_loopback_array))
24184 +void au_loopback_fin(void)
24186 + if (backing_file_func)
24187 + symbol_put(loop_backing_file);
24188 + kfree(au_warn_loopback_array);
24190 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24191 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24192 +++ linux/fs/aufs/loop.h 2018-08-12 23:43:05.460124736 +0200
24194 +/* SPDX-License-Identifier: GPL-2.0 */
24196 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24198 + * This program, aufs is free software; you can redistribute it and/or modify
24199 + * it under the terms of the GNU General Public License as published by
24200 + * the Free Software Foundation; either version 2 of the License, or
24201 + * (at your option) any later version.
24203 + * This program is distributed in the hope that it will be useful,
24204 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24205 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24206 + * GNU General Public License for more details.
24208 + * You should have received a copy of the GNU General Public License
24209 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24213 + * support for loopback mount as a branch
24216 +#ifndef __AUFS_LOOP_H__
24217 +#define __AUFS_LOOP_H__
24222 +struct super_block;
24224 +#ifdef CONFIG_AUFS_BDEV_LOOP
24225 +/* drivers/block/loop.c */
24226 +struct file *loop_backing_file(struct super_block *sb);
24229 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24230 +int au_test_loopback_kthread(void);
24231 +void au_warn_loopback(struct super_block *h_sb);
24233 +int au_loopback_init(void);
24234 +void au_loopback_fin(void);
24236 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24237 + struct dentry *h_adding)
24238 +AuStubInt0(au_test_loopback_kthread, void)
24239 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24241 +AuStubInt0(au_loopback_init, void)
24242 +AuStubVoid(au_loopback_fin, void)
24243 +#endif /* BLK_DEV_LOOP */
24245 +#endif /* __KERNEL__ */
24246 +#endif /* __AUFS_LOOP_H__ */
24247 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24248 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24249 +++ linux/fs/aufs/magic.mk 2018-06-04 09:08:09.188079511 +0200
24251 +# SPDX-License-Identifier: GPL-2.0
24253 +# defined in ${srctree}/fs/fuse/inode.c
24255 +ifdef CONFIG_FUSE_FS
24256 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24259 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24261 +ifdef CONFIG_XFS_FS
24262 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24265 +# defined in ${srctree}/fs/configfs/mount.c
24267 +ifdef CONFIG_CONFIGFS_FS
24268 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24271 +# defined in ${srctree}/fs/ubifs/ubifs.h
24273 +ifdef CONFIG_UBIFS_FS
24274 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24277 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24279 +ifdef CONFIG_HFSPLUS_FS
24280 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24282 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24283 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24284 +++ linux/fs/aufs/Makefile 2018-06-04 09:08:09.181412645 +0200
24286 +# SPDX-License-Identifier: GPL-2.0
24288 +include ${src}/magic.mk
24289 +ifeq (${CONFIG_AUFS_FS},m)
24290 +include ${src}/conf.mk
24292 +-include ${src}/priv_def.mk
24294 +# cf. include/linux/kernel.h
24296 +ccflags-y += -DDEBUG
24297 +# sparse requires the full pathname
24299 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24301 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24304 +obj-$(CONFIG_AUFS_FS) += aufs.o
24305 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24306 + wkq.o vfsub.o dcsub.o \
24307 + cpup.o whout.o wbr_policy.o \
24308 + dinfo.o dentry.o \
24310 + finfo.o file.o f_op.o \
24312 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24316 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24317 +aufs-$(CONFIG_SYSFS) += sysfs.o
24318 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24319 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24320 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24321 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24322 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24323 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24324 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24325 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24326 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24327 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24328 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24329 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24330 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24331 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24332 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24333 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24334 +++ linux/fs/aufs/module.c 2018-08-12 23:43:05.460124736 +0200
24336 +// SPDX-License-Identifier: GPL-2.0
24338 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24340 + * This program, aufs is free software; you can redistribute it and/or modify
24341 + * it under the terms of the GNU General Public License as published by
24342 + * the Free Software Foundation; either version 2 of the License, or
24343 + * (at your option) any later version.
24345 + * This program is distributed in the hope that it will be useful,
24346 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24347 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24348 + * GNU General Public License for more details.
24350 + * You should have received a copy of the GNU General Public License
24351 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24355 + * module global variables and operations
24358 +#include <linux/module.h>
24359 +#include <linux/seq_file.h>
24362 +/* shrinkable realloc */
24363 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24371 +#if 0 /* unused */
24378 + AuDebugOn(!new_sz);
24381 + diff = au_kmidx_sub(sz, new_sz);
24387 + /* expand or SLOB */
24388 + p = krealloc(p, new_sz, gfp);
24389 + else if (new_sz < sz && may_shrink) {
24393 + q = kmalloc(new_sz, gfp);
24396 + memcpy(q, p, new_sz);
24408 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24411 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24412 + if (p && new_sz > nused)
24413 + memset(p + nused, 0, new_sz - nused);
24417 +/* ---------------------------------------------------------------------- */
24421 +struct kmem_cache *au_cache[AuCache_Last];
24423 +static void au_cache_fin(void)
24428 + * Make sure all delayed rcu free inodes are flushed before we
24433 + /* excluding AuCache_HNOTIFY */
24434 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24435 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24436 + kmem_cache_destroy(au_cache[i]);
24437 + au_cache[i] = NULL;
24441 +static int __init au_cache_init(void)
24443 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24444 + if (au_cache[AuCache_DINFO])
24445 + /* SLAB_DESTROY_BY_RCU */
24446 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24447 + au_icntnr_init_once);
24448 + if (au_cache[AuCache_ICNTNR])
24449 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24450 + au_fi_init_once);
24451 + if (au_cache[AuCache_FINFO])
24452 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24453 + if (au_cache[AuCache_VDIR])
24454 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24455 + if (au_cache[AuCache_DEHSTR])
24462 +/* ---------------------------------------------------------------------- */
24464 +int au_dir_roflags;
24466 +#ifdef CONFIG_AUFS_SBILIST
24468 + * iterate_supers_type() doesn't protect us from
24469 + * remounting (branch management)
24471 +struct hlist_bl_head au_sbilist;
24475 + * functions for module interface.
24477 +MODULE_LICENSE("GPL");
24478 +/* MODULE_LICENSE("GPL v2"); */
24479 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24480 +MODULE_DESCRIPTION(AUFS_NAME
24481 + " -- Advanced multi layered unification filesystem");
24482 +MODULE_VERSION(AUFS_VERSION);
24483 +MODULE_ALIAS_FS(AUFS_NAME);
24485 +/* this module parameter has no meaning when SYSFS is disabled */
24486 +int sysaufs_brs = 1;
24487 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24488 +module_param_named(brs, sysaufs_brs, int, 0444);
24490 +/* this module parameter has no meaning when USER_NS is disabled */
24492 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24493 +module_param_named(allow_userns, au_userns, bool, 0444);
24495 +/* ---------------------------------------------------------------------- */
24497 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24499 +int au_seq_path(struct seq_file *seq, struct path *path)
24503 + err = seq_path(seq, path, au_esc_chars);
24512 +/* ---------------------------------------------------------------------- */
24514 +static int __init aufs_init(void)
24519 + p = au_esc_chars;
24520 + for (i = 1; i <= ' '; i++)
24526 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24528 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24529 + for (i = 0; i < AuIop_Last; i++)
24530 + aufs_iop_nogetattr[i].getattr = NULL;
24532 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24534 + au_sbilist_init();
24535 + sysaufs_brs_init();
24538 + err = sysaufs_init();
24539 + if (unlikely(err))
24541 + err = dbgaufs_init();
24542 + if (unlikely(err))
24543 + goto out_sysaufs;
24544 + err = au_procfs_init();
24545 + if (unlikely(err))
24546 + goto out_dbgaufs;
24547 + err = au_wkq_init();
24548 + if (unlikely(err))
24550 + err = au_loopback_init();
24551 + if (unlikely(err))
24553 + err = au_hnotify_init();
24554 + if (unlikely(err))
24555 + goto out_loopback;
24556 + err = au_sysrq_init();
24557 + if (unlikely(err))
24559 + err = au_cache_init();
24560 + if (unlikely(err))
24563 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24564 + err = register_filesystem(&aufs_fs_type);
24565 + if (unlikely(err))
24568 + /* since we define pr_fmt, call printk directly */
24569 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24570 + goto out; /* success */
24577 + au_hnotify_fin();
24579 + au_loopback_fin();
24593 +static void __exit aufs_exit(void)
24595 + unregister_filesystem(&aufs_fs_type);
24598 + au_hnotify_fin();
24599 + au_loopback_fin();
24607 +module_init(aufs_init);
24608 +module_exit(aufs_exit);
24609 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24610 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24611 +++ linux/fs/aufs/module.h 2018-08-12 23:43:05.460124736 +0200
24613 +/* SPDX-License-Identifier: GPL-2.0 */
24615 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24617 + * This program, aufs is free software; you can redistribute it and/or modify
24618 + * it under the terms of the GNU General Public License as published by
24619 + * the Free Software Foundation; either version 2 of the License, or
24620 + * (at your option) any later version.
24622 + * This program is distributed in the hope that it will be useful,
24623 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24624 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24625 + * GNU General Public License for more details.
24627 + * You should have received a copy of the GNU General Public License
24628 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24632 + * module initialization and module-global
24635 +#ifndef __AUFS_MODULE_H__
24636 +#define __AUFS_MODULE_H__
24640 +#include <linux/slab.h>
24645 +/* module parameters */
24646 +extern int sysaufs_brs;
24647 +extern bool au_userns;
24649 +/* ---------------------------------------------------------------------- */
24651 +extern int au_dir_roflags;
24653 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24654 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24657 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24659 +#ifndef CONFIG_SLOB
24660 + return kmalloc_index(sz) - kmalloc_index(new_sz);
24662 + return -1; /* SLOB is untested */
24666 +int au_seq_path(struct seq_file *seq, struct path *path);
24668 +#ifdef CONFIG_PROC_FS
24670 +int __init au_procfs_init(void);
24671 +void au_procfs_fin(void);
24673 +AuStubInt0(au_procfs_init, void);
24674 +AuStubVoid(au_procfs_fin, void);
24677 +/* ---------------------------------------------------------------------- */
24686 + AuCache_HNOTIFY, /* must be last */
24690 +extern struct kmem_cache *au_cache[AuCache_Last];
24692 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24693 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24694 +#define AuCacheCtor(type, ctor) \
24695 + kmem_cache_create(#type, sizeof(struct type), \
24696 + __alignof__(struct type), AuCacheFlags, ctor)
24698 +#define AuCacheFuncs(name, index) \
24699 +static inline struct au_##name *au_cache_alloc_##name(void) \
24700 +{ return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24701 +static inline void au_cache_free_##name(struct au_##name *p) \
24702 +{ kmem_cache_free(au_cache[AuCache_##index], p); }
24704 +AuCacheFuncs(dinfo, DINFO);
24705 +AuCacheFuncs(icntnr, ICNTNR);
24706 +AuCacheFuncs(finfo, FINFO);
24707 +AuCacheFuncs(vdir, VDIR);
24708 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24709 +#ifdef CONFIG_AUFS_HNOTIFY
24710 +AuCacheFuncs(hnotify, HNOTIFY);
24713 +#endif /* __KERNEL__ */
24714 +#endif /* __AUFS_MODULE_H__ */
24715 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24716 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24717 +++ linux/fs/aufs/mvdown.c 2018-08-12 23:43:05.460124736 +0200
24719 +// SPDX-License-Identifier: GPL-2.0
24721 + * Copyright (C) 2011-2018 Junjiro R. Okajima
24723 + * This program, aufs is free software; you can redistribute it and/or modify
24724 + * it under the terms of the GNU General Public License as published by
24725 + * the Free Software Foundation; either version 2 of the License, or
24726 + * (at your option) any later version.
24728 + * This program is distributed in the hope that it will be useful,
24729 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24730 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24731 + * GNU General Public License for more details.
24733 + * You should have received a copy of the GNU General Public License
24734 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24738 + * move-down, opposite of copy-up
24743 +struct au_mvd_args {
24745 + struct super_block *h_sb;
24746 + struct dentry *h_parent;
24747 + struct au_hinode *hdir;
24748 + struct inode *h_dir, *h_inode;
24749 + struct au_pin pin;
24750 + } info[AUFS_MVDOWN_NARRAY];
24752 + struct aufs_mvdown mvdown;
24753 + struct dentry *dentry, *parent;
24754 + struct inode *inode, *dir;
24755 + struct super_block *sb;
24756 + aufs_bindex_t bopq, bwh, bfound;
24757 + unsigned char rename_lock;
24760 +#define mvd_errno mvdown.au_errno
24761 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
24762 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
24763 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
24764 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
24766 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
24767 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
24768 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
24769 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
24770 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
24771 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
24773 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
24774 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
24775 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
24776 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
24777 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
24778 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
24780 +#define AU_MVD_PR(flag, ...) do { \
24782 + pr_err(__VA_ARGS__); \
24785 +static int find_lower_writable(struct au_mvd_args *a)
24787 + struct super_block *sb;
24788 + aufs_bindex_t bindex, bbot;
24789 + struct au_branch *br;
24792 + bindex = a->mvd_bsrc;
24793 + bbot = au_sbbot(sb);
24794 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
24795 + for (bindex++; bindex <= bbot; bindex++) {
24796 + br = au_sbr(sb, bindex);
24797 + if (au_br_fhsm(br->br_perm)
24798 + && !sb_rdonly(au_br_sb(br)))
24801 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
24802 + for (bindex++; bindex <= bbot; bindex++) {
24803 + br = au_sbr(sb, bindex);
24804 + if (!au_br_rdonly(br))
24808 + for (bindex++; bindex <= bbot; bindex++) {
24809 + br = au_sbr(sb, bindex);
24810 + if (!sb_rdonly(au_br_sb(br))) {
24811 + if (au_br_rdonly(br))
24813 + |= AUFS_MVDOWN_ROLOWER_R;
24821 +/* make the parent dir on bdst */
24822 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
24827 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
24828 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
24829 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
24830 + a->mvd_h_dst_parent = NULL;
24831 + if (au_dbbot(a->parent) >= a->mvd_bdst)
24832 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24833 + if (!a->mvd_h_dst_parent) {
24834 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
24835 + if (unlikely(err)) {
24836 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
24839 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24847 +/* lock them all */
24848 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
24851 + struct dentry *h_trap;
24853 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
24854 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
24855 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
24856 + au_opt_udba(a->sb),
24857 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24859 + if (unlikely(err)) {
24860 + AU_MVD_PR(dmsg, "pin_dst failed\n");
24864 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
24865 + a->rename_lock = 0;
24866 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
24867 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
24868 + au_opt_udba(a->sb),
24869 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24870 + err = au_do_pin(&a->mvd_pin_src);
24872 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
24873 + if (unlikely(err)) {
24874 + AU_MVD_PR(dmsg, "pin_src failed\n");
24877 + goto out; /* success */
24880 + a->rename_lock = 1;
24881 + au_pin_hdir_unlock(&a->mvd_pin_dst);
24882 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
24883 + au_opt_udba(a->sb),
24884 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24886 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
24887 + if (unlikely(err)) {
24888 + AU_MVD_PR(dmsg, "pin_src failed\n");
24889 + au_pin_hdir_lock(&a->mvd_pin_dst);
24892 + au_pin_hdir_unlock(&a->mvd_pin_src);
24893 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
24894 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
24896 + err = (h_trap != a->mvd_h_src_parent);
24898 + err = (h_trap != a->mvd_h_dst_parent);
24900 + BUG_ON(err); /* it should never happen */
24901 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
24904 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
24905 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
24906 + au_pin_hdir_lock(&a->mvd_pin_src);
24907 + au_unpin(&a->mvd_pin_src);
24908 + au_pin_hdir_lock(&a->mvd_pin_dst);
24911 + goto out; /* success */
24914 + au_unpin(&a->mvd_pin_dst);
24920 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
24922 + if (!a->rename_lock)
24923 + au_unpin(&a->mvd_pin_src);
24925 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
24926 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
24927 + au_pin_hdir_lock(&a->mvd_pin_src);
24928 + au_unpin(&a->mvd_pin_src);
24929 + au_pin_hdir_lock(&a->mvd_pin_dst);
24931 + au_unpin(&a->mvd_pin_dst);
24934 +/* copy-down the file */
24935 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
24938 + struct au_cp_generic cpg = {
24939 + .dentry = a->dentry,
24940 + .bdst = a->mvd_bdst,
24941 + .bsrc = a->mvd_bsrc,
24943 + .pin = &a->mvd_pin_dst,
24944 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24947 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
24948 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
24949 + au_fset_cpup(cpg.flags, OVERWRITE);
24950 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
24951 + au_fset_cpup(cpg.flags, RWDST);
24952 + err = au_sio_cpdown_simple(&cpg);
24953 + if (unlikely(err))
24954 + AU_MVD_PR(dmsg, "cpdown failed\n");
24961 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
24964 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
24967 + struct path h_path;
24968 + struct au_branch *br;
24969 + struct inode *delegated;
24971 + br = au_sbr(a->sb, a->mvd_bdst);
24972 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
24973 + err = PTR_ERR(h_path.dentry);
24974 + if (IS_ERR(h_path.dentry)) {
24975 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
24980 + if (d_is_positive(h_path.dentry)) {
24981 + h_path.mnt = au_br_mnt(br);
24982 + delegated = NULL;
24983 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
24984 + &delegated, /*force*/0);
24985 + if (unlikely(err == -EWOULDBLOCK)) {
24986 + pr_warn("cannot retry for NFSv4 delegation"
24987 + " for an internal unlink\n");
24990 + if (unlikely(err))
24991 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
24993 + dput(h_path.dentry);
25001 + * unlink the topmost h_dentry
25003 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25006 + struct path h_path;
25007 + struct inode *delegated;
25009 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25010 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25011 + delegated = NULL;
25012 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25013 + if (unlikely(err == -EWOULDBLOCK)) {
25014 + pr_warn("cannot retry for NFSv4 delegation"
25015 + " for an internal unlink\n");
25018 + if (unlikely(err))
25019 + AU_MVD_PR(dmsg, "unlink failed\n");
25025 +/* Since mvdown succeeded, we ignore an error of this function */
25026 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25029 + struct au_branch *br;
25031 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25032 + br = au_sbr(a->sb, a->mvd_bsrc);
25033 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25035 + br = au_sbr(a->sb, a->mvd_bdst);
25036 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25037 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25040 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25042 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25046 + * copy-down the file and unlink the bsrc file.
25047 + * - unlink the bdst whout if exist
25048 + * - copy-down the file (with whtmp name and rename)
25049 + * - unlink the bsrc file
25051 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25055 + err = au_do_mkdir(dmsg, a);
25057 + err = au_do_lock(dmsg, a);
25058 + if (unlikely(err))
25062 + * do not revert the activities we made on bdst since they should be
25063 + * harmless in aufs.
25066 + err = au_do_cpdown(dmsg, a);
25068 + err = au_do_unlink_wh(dmsg, a);
25069 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25070 + err = au_do_unlink(dmsg, a);
25071 + if (unlikely(err))
25074 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25075 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25076 + if (find_lower_writable(a) < 0)
25077 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25079 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25080 + au_do_stfs(dmsg, a);
25082 + /* maintain internal array */
25083 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25084 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25085 + au_set_dbtop(a->dentry, a->mvd_bdst);
25086 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25087 + au_set_ibtop(a->inode, a->mvd_bdst);
25089 + /* hide the lower */
25090 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25091 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25092 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25093 + au_set_ibbot(a->inode, a->mvd_bsrc);
25095 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25096 + au_set_dbbot(a->dentry, a->mvd_bdst);
25097 + if (au_ibbot(a->inode) < a->mvd_bdst)
25098 + au_set_ibbot(a->inode, a->mvd_bdst);
25101 + au_do_unlock(dmsg, a);
25107 +/* ---------------------------------------------------------------------- */
25109 +/* make sure the file is idle */
25110 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25112 + int err, plinked;
25115 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25116 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25117 + && au_dcount(a->dentry) == 1
25118 + && atomic_read(&a->inode->i_count) == 1
25119 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25120 + && (!plinked || !au_plink_test(a->inode))
25121 + && a->inode->i_nlink == 1)
25126 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25127 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25128 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25129 + a->mvd_h_src_inode->i_nlink,
25130 + plinked, plinked ? au_plink_test(a->inode) : 0);
25137 +/* make sure the parent dir is fine */
25138 +static int au_mvd_args_parent(const unsigned char dmsg,
25139 + struct au_mvd_args *a)
25142 + aufs_bindex_t bindex;
25145 + if (unlikely(au_alive_dir(a->parent))) {
25147 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25151 + a->bopq = au_dbdiropq(a->parent);
25152 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25153 + AuDbg("b%d\n", bindex);
25154 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25155 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25157 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25158 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25159 + a->bopq, a->mvd_bdst);
25167 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25168 + struct au_mvd_args *a)
25171 + struct au_dinfo *dinfo, *tmp;
25173 + /* lookup the next lower positive entry */
25175 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25176 + if (unlikely(!tmp))
25181 + dinfo = au_di(a->dentry);
25182 + au_di_cp(tmp, dinfo);
25183 + au_di_swap(tmp, dinfo);
25185 + /* returns the number of positive dentries */
25186 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25187 + /* AuLkup_IGNORE_PERM */ 0);
25189 + a->bwh = au_dbwh(a->dentry);
25190 + else if (err > 0)
25191 + a->bfound = au_dbtop(a->dentry);
25193 + au_di_swap(tmp, dinfo);
25194 + au_rw_write_unlock(&tmp->di_rwsem);
25196 + if (unlikely(err < 0))
25197 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25200 + * here, we have these cases.
25202 + * no positive dentry under bsrc. there are more sub-cases.
25204 + * there no whiteout, we can safely move-down.
25207 + * bsrc < bwh && bwh < bdst
25208 + * there is a whiteout on RO branch. cannot proceed.
25210 + * there is a whiteout on the RW target branch. it should
25213 + * there is a whiteout somewhere unrelated branch.
25214 + * -1 < bfound && bfound <= bsrc
25217 + * found, but it is on RO branch between bsrc and bdst. cannot
25220 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25223 + * found, after we create the file on bdst, it will be hidden.
25226 + AuDebugOn(a->bfound == -1
25228 + && a->bwh <= a->mvd_bsrc);
25229 + AuDebugOn(-1 < a->bfound
25230 + && a->bfound <= a->mvd_bsrc);
25233 + if (a->bfound == -1
25234 + && a->mvd_bsrc < a->bwh
25236 + && a->bwh < a->mvd_bdst) {
25237 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25238 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25239 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25241 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25242 + a->mvd_errno = EAU_MVDOWN_UPPER;
25243 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25244 + a->mvd_bdst, a->bfound);
25248 + err = 0; /* success */
25255 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25260 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25261 + && a->bfound == a->mvd_bdst)
25267 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25270 + struct au_branch *br;
25273 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25277 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25278 + a->mvd_bsrc = au_ibtop(a->inode);
25280 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25281 + if (unlikely(a->mvd_bsrc < 0
25282 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25283 + || au_dbbot(a->dentry) < a->mvd_bsrc
25284 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25285 + || (a->mvd_bsrc < au_ibtop(a->inode)
25286 + || au_ibbot(a->inode) < a->mvd_bsrc
25287 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25288 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25289 + AU_MVD_PR(dmsg, "no upper\n");
25293 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25294 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25295 + AU_MVD_PR(dmsg, "on the bottom\n");
25298 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25299 + br = au_sbr(a->sb, a->mvd_bsrc);
25300 + err = au_br_rdonly(br);
25301 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25302 + if (unlikely(err))
25304 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25305 + || IS_APPEND(a->mvd_h_src_inode))) {
25307 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25313 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25314 + a->mvd_bdst = find_lower_writable(a);
25315 + if (unlikely(a->mvd_bdst < 0)) {
25316 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25317 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25321 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25322 + if (unlikely(a->mvd_bdst < 0
25323 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25324 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25325 + AU_MVD_PR(dmsg, "no lower brid\n");
25330 + err = au_mvd_args_busy(dmsg, a);
25332 + err = au_mvd_args_parent(dmsg, a);
25334 + err = au_mvd_args_intermediate(dmsg, a);
25336 + err = au_mvd_args_exist(dmsg, a);
25338 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25345 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25348 + unsigned char dmsg;
25349 + struct au_mvd_args *args;
25350 + struct inode *inode;
25352 + inode = d_inode(dentry);
25354 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25358 + args = kmalloc(sizeof(*args), GFP_NOFS);
25359 + if (unlikely(!args))
25362 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25364 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
25365 + if (unlikely(err)) {
25370 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25371 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25372 + args->mvdown.au_errno = 0;
25373 + args->dentry = dentry;
25374 + args->inode = inode;
25375 + args->sb = dentry->d_sb;
25378 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25379 + args->parent = dget_parent(dentry);
25380 + args->dir = d_inode(args->parent);
25381 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25382 + dput(args->parent);
25383 + if (unlikely(args->parent != dentry->d_parent)) {
25384 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25388 + inode_lock_nested(inode, I_MUTEX_CHILD);
25389 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25390 + if (unlikely(err))
25393 + di_write_lock_parent(args->parent);
25394 + err = au_mvd_args(dmsg, args);
25395 + if (unlikely(err))
25398 + err = au_do_mvdown(dmsg, args);
25399 + if (unlikely(err))
25402 + au_cpup_attr_timesizes(args->dir);
25403 + au_cpup_attr_timesizes(inode);
25404 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25405 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25406 + /* au_digen_dec(dentry); */
25409 + di_write_unlock(args->parent);
25410 + aufs_read_unlock(dentry, AuLock_DW);
25412 + inode_unlock(inode);
25414 + inode_unlock(args->dir);
25416 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25424 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25425 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25426 +++ linux/fs/aufs/opts.c 2018-08-12 23:43:05.460124736 +0200
25428 +// SPDX-License-Identifier: GPL-2.0
25430 + * Copyright (C) 2005-2018 Junjiro R. Okajima
25432 + * This program, aufs is free software; you can redistribute it and/or modify
25433 + * it under the terms of the GNU General Public License as published by
25434 + * the Free Software Foundation; either version 2 of the License, or
25435 + * (at your option) any later version.
25437 + * This program is distributed in the hope that it will be useful,
25438 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25439 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25440 + * GNU General Public License for more details.
25442 + * You should have received a copy of the GNU General Public License
25443 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25447 + * mount options/flags
25450 +#include <linux/namei.h>
25451 +#include <linux/types.h> /* a distribution requires */
25452 +#include <linux/parser.h>
25455 +/* ---------------------------------------------------------------------- */
25459 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25460 + Opt_idel, Opt_imod,
25461 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25462 + Opt_rdblk_def, Opt_rdhash_def,
25463 + Opt_xino, Opt_noxino,
25464 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25465 + Opt_trunc_xino_path, Opt_itrunc_xino,
25466 + Opt_trunc_xib, Opt_notrunc_xib,
25467 + Opt_shwh, Opt_noshwh,
25468 + Opt_plink, Opt_noplink, Opt_list_plink,
25470 + Opt_dio, Opt_nodio,
25471 + Opt_diropq_a, Opt_diropq_w,
25472 + Opt_warn_perm, Opt_nowarn_perm,
25473 + Opt_wbr_copyup, Opt_wbr_create,
25475 + Opt_verbose, Opt_noverbose,
25476 + Opt_sum, Opt_nosum, Opt_wsum,
25477 + Opt_dirperm1, Opt_nodirperm1,
25478 + Opt_dirren, Opt_nodirren,
25479 + Opt_acl, Opt_noacl,
25480 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25483 +static match_table_t options = {
25484 + {Opt_br, "br=%s"},
25485 + {Opt_br, "br:%s"},
25487 + {Opt_add, "add=%d:%s"},
25488 + {Opt_add, "add:%d:%s"},
25489 + {Opt_add, "ins=%d:%s"},
25490 + {Opt_add, "ins:%d:%s"},
25491 + {Opt_append, "append=%s"},
25492 + {Opt_append, "append:%s"},
25493 + {Opt_prepend, "prepend=%s"},
25494 + {Opt_prepend, "prepend:%s"},
25496 + {Opt_del, "del=%s"},
25497 + {Opt_del, "del:%s"},
25498 + /* {Opt_idel, "idel:%d"}, */
25499 + {Opt_mod, "mod=%s"},
25500 + {Opt_mod, "mod:%s"},
25501 + /* {Opt_imod, "imod:%d:%s"}, */
25503 + {Opt_dirwh, "dirwh=%d"},
25505 + {Opt_xino, "xino=%s"},
25506 + {Opt_noxino, "noxino"},
25507 + {Opt_trunc_xino, "trunc_xino"},
25508 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25509 + {Opt_notrunc_xino, "notrunc_xino"},
25510 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25511 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25512 + /* {Opt_zxino, "zxino=%s"}, */
25513 + {Opt_trunc_xib, "trunc_xib"},
25514 + {Opt_notrunc_xib, "notrunc_xib"},
25516 +#ifdef CONFIG_PROC_FS
25517 + {Opt_plink, "plink"},
25519 + {Opt_ignore_silent, "plink"},
25522 + {Opt_noplink, "noplink"},
25524 +#ifdef CONFIG_AUFS_DEBUG
25525 + {Opt_list_plink, "list_plink"},
25528 + {Opt_udba, "udba=%s"},
25530 + {Opt_dio, "dio"},
25531 + {Opt_nodio, "nodio"},
25533 +#ifdef CONFIG_AUFS_DIRREN
25534 + {Opt_dirren, "dirren"},
25535 + {Opt_nodirren, "nodirren"},
25537 + {Opt_ignore, "dirren"},
25538 + {Opt_ignore_silent, "nodirren"},
25541 +#ifdef CONFIG_AUFS_FHSM
25542 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25544 + {Opt_ignore, "fhsm_sec=%d"},
25547 + {Opt_diropq_a, "diropq=always"},
25548 + {Opt_diropq_a, "diropq=a"},
25549 + {Opt_diropq_w, "diropq=whiteouted"},
25550 + {Opt_diropq_w, "diropq=w"},
25552 + {Opt_warn_perm, "warn_perm"},
25553 + {Opt_nowarn_perm, "nowarn_perm"},
25555 + /* keep them temporary */
25556 + {Opt_ignore_silent, "nodlgt"},
25557 + {Opt_ignore, "clean_plink"},
25559 +#ifdef CONFIG_AUFS_SHWH
25560 + {Opt_shwh, "shwh"},
25562 + {Opt_noshwh, "noshwh"},
25564 + {Opt_dirperm1, "dirperm1"},
25565 + {Opt_nodirperm1, "nodirperm1"},
25567 + {Opt_verbose, "verbose"},
25568 + {Opt_verbose, "v"},
25569 + {Opt_noverbose, "noverbose"},
25570 + {Opt_noverbose, "quiet"},
25571 + {Opt_noverbose, "q"},
25572 + {Opt_noverbose, "silent"},
25574 + {Opt_sum, "sum"},
25575 + {Opt_nosum, "nosum"},
25576 + {Opt_wsum, "wsum"},
25578 + {Opt_rdcache, "rdcache=%d"},
25579 + {Opt_rdblk, "rdblk=%d"},
25580 + {Opt_rdblk_def, "rdblk=def"},
25581 + {Opt_rdhash, "rdhash=%d"},
25582 + {Opt_rdhash_def, "rdhash=def"},
25584 + {Opt_wbr_create, "create=%s"},
25585 + {Opt_wbr_create, "create_policy=%s"},
25586 + {Opt_wbr_copyup, "cpup=%s"},
25587 + {Opt_wbr_copyup, "copyup=%s"},
25588 + {Opt_wbr_copyup, "copyup_policy=%s"},
25590 + /* generic VFS flag */
25591 +#ifdef CONFIG_FS_POSIX_ACL
25592 + {Opt_acl, "acl"},
25593 + {Opt_noacl, "noacl"},
25595 + {Opt_ignore, "acl"},
25596 + {Opt_ignore_silent, "noacl"},
25599 + /* internal use for the scripts */
25600 + {Opt_ignore_silent, "si=%s"},
25602 + {Opt_br, "dirs=%s"},
25603 + {Opt_ignore, "debug=%d"},
25604 + {Opt_ignore, "delete=whiteout"},
25605 + {Opt_ignore, "delete=all"},
25606 + {Opt_ignore, "imap=%s"},
25608 + /* temporary workaround, due to old mount(8)? */
25609 + {Opt_ignore_silent, "relatime"},
25614 +/* ---------------------------------------------------------------------- */
25616 +static const char *au_parser_pattern(int val, match_table_t tbl)
25618 + struct match_token *p;
25621 + while (p->pattern) {
25622 + if (p->token == val)
25623 + return p->pattern;
25630 +static const char *au_optstr(int *val, match_table_t tbl)
25632 + struct match_token *p;
25639 + while (p->pattern) {
25641 + && (v & p->token) == p->token) {
25642 + *val &= ~p->token;
25643 + return p->pattern;
25652 +/* ---------------------------------------------------------------------- */
25654 +static match_table_t brperm = {
25655 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25656 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25657 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25661 +static match_table_t brattr = {
25663 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25664 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25665 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25666 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25667 +#ifdef CONFIG_AUFS_FHSM
25668 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25670 +#ifdef CONFIG_AUFS_XATTR
25671 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25672 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25673 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25674 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25675 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25676 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25679 + /* ro/rr branch */
25680 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25683 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25684 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25689 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25696 + p = strchr(str, '+');
25699 + v = match_token(str, table, args);
25701 + if (v & AuBrAttr_CMOO_Mask)
25702 + attr &= ~AuBrAttr_CMOO_Mask;
25707 + pr_warn("ignored branch attribute %s\n", str);
25717 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25725 + p = au_optstr(&perm, brattr);
25728 + memcpy(q, p, sz + 1);
25734 + p = au_optstr(&perm, brattr);
25738 + memcpy(q, p, sz + 1);
25744 + return q - str->a;
25747 +static int noinline_for_stack br_perm_val(char *perm)
25749 + int val, bad, sz;
25751 + substring_t args[MAX_OPT_ARGS];
25752 + au_br_perm_str_t attr;
25754 + p = strchr(perm, '+');
25757 + val = match_token(perm, brperm, args);
25761 + pr_warn("ignored branch permission %s\n", perm);
25762 + val = AuBrPerm_RO;
25768 + val |= br_attr_val(p + 1, brattr, args);
25771 + switch (val & AuBrPerm_Mask) {
25772 + case AuBrPerm_RO:
25773 + case AuBrPerm_RR:
25774 + bad = val & AuBrWAttr_Mask;
25775 + val &= ~AuBrWAttr_Mask;
25777 + case AuBrPerm_RW:
25778 + bad = val & AuBrRAttr_Mask;
25779 + val &= ~AuBrRAttr_Mask;
25784 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
25785 + * does not treat it as an error, just warning.
25786 + * this is a tiny guard for the user operation.
25788 + if (val & AuBrAttr_UNPIN) {
25789 + bad |= AuBrAttr_UNPIN;
25790 + val &= ~AuBrAttr_UNPIN;
25793 + if (unlikely(bad)) {
25794 + sz = au_do_optstr_br_attr(&attr, bad);
25796 + pr_warn("ignored branch attribute %s\n", attr.a);
25803 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
25805 + au_br_perm_str_t attr;
25811 + p = au_optstr(&perm, brperm);
25812 + AuDebugOn(!p || !*p);
25814 + memcpy(q, p, sz + 1);
25817 + sz = au_do_optstr_br_attr(&attr, perm);
25820 + memcpy(q, attr.a, sz + 1);
25823 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
25826 +/* ---------------------------------------------------------------------- */
25828 +static match_table_t udbalevel = {
25829 + {AuOpt_UDBA_REVAL, "reval"},
25830 + {AuOpt_UDBA_NONE, "none"},
25831 +#ifdef CONFIG_AUFS_HNOTIFY
25832 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
25833 +#ifdef CONFIG_AUFS_HFSNOTIFY
25834 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
25840 +static int noinline_for_stack udba_val(char *str)
25842 + substring_t args[MAX_OPT_ARGS];
25844 + return match_token(str, udbalevel, args);
25847 +const char *au_optstr_udba(int udba)
25849 + return au_parser_pattern(udba, udbalevel);
25852 +/* ---------------------------------------------------------------------- */
25854 +static match_table_t au_wbr_create_policy = {
25855 + {AuWbrCreate_TDP, "tdp"},
25856 + {AuWbrCreate_TDP, "top-down-parent"},
25857 + {AuWbrCreate_RR, "rr"},
25858 + {AuWbrCreate_RR, "round-robin"},
25859 + {AuWbrCreate_MFS, "mfs"},
25860 + {AuWbrCreate_MFS, "most-free-space"},
25861 + {AuWbrCreate_MFSV, "mfs:%d"},
25862 + {AuWbrCreate_MFSV, "most-free-space:%d"},
25864 + /* top-down regardless the parent, and then mfs */
25865 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
25866 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
25868 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
25869 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
25870 + {AuWbrCreate_PMFS, "pmfs"},
25871 + {AuWbrCreate_PMFSV, "pmfs:%d"},
25872 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
25873 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
25878 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
25879 + struct au_opt_wbr_create *create)
25882 + unsigned long long ull;
25885 + if (!match_u64(arg, &ull))
25886 + create->mfsrr_watermark = ull;
25888 + pr_err("bad integer in %s\n", str);
25895 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
25896 + struct au_opt_wbr_create *create)
25901 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
25902 + create->mfs_second = n;
25904 + pr_err("bad integer in %s\n", str);
25911 +static int noinline_for_stack
25912 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
25915 + substring_t args[MAX_OPT_ARGS];
25917 + err = match_token(str, au_wbr_create_policy, args);
25918 + create->wbr_create = err;
25920 + case AuWbrCreate_MFSRRV:
25921 + case AuWbrCreate_TDMFSV:
25922 + case AuWbrCreate_PMFSRRV:
25923 + e = au_wbr_mfs_wmark(&args[0], str, create);
25925 + e = au_wbr_mfs_sec(&args[1], str, create);
25929 + case AuWbrCreate_MFSRR:
25930 + case AuWbrCreate_TDMFS:
25931 + case AuWbrCreate_PMFSRR:
25932 + e = au_wbr_mfs_wmark(&args[0], str, create);
25933 + if (unlikely(e)) {
25938 + case AuWbrCreate_MFS:
25939 + case AuWbrCreate_PMFS:
25940 + create->mfs_second = AUFS_MFS_DEF_SEC;
25942 + case AuWbrCreate_MFSV:
25943 + case AuWbrCreate_PMFSV:
25944 + e = au_wbr_mfs_sec(&args[0], str, create);
25953 +const char *au_optstr_wbr_create(int wbr_create)
25955 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
25958 +static match_table_t au_wbr_copyup_policy = {
25959 + {AuWbrCopyup_TDP, "tdp"},
25960 + {AuWbrCopyup_TDP, "top-down-parent"},
25961 + {AuWbrCopyup_BUP, "bup"},
25962 + {AuWbrCopyup_BUP, "bottom-up-parent"},
25963 + {AuWbrCopyup_BU, "bu"},
25964 + {AuWbrCopyup_BU, "bottom-up"},
25968 +static int noinline_for_stack au_wbr_copyup_val(char *str)
25970 + substring_t args[MAX_OPT_ARGS];
25972 + return match_token(str, au_wbr_copyup_policy, args);
25975 +const char *au_optstr_wbr_copyup(int wbr_copyup)
25977 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
25980 +/* ---------------------------------------------------------------------- */
25982 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
25984 +static void dump_opts(struct au_opts *opts)
25986 +#ifdef CONFIG_AUFS_DEBUG
25987 + /* reduce stack space */
25989 + struct au_opt_add *add;
25990 + struct au_opt_del *del;
25991 + struct au_opt_mod *mod;
25992 + struct au_opt_xino *xino;
25993 + struct au_opt_xino_itrunc *xino_itrunc;
25994 + struct au_opt_wbr_create *create;
25996 + struct au_opt *opt;
25999 + while (opt->type != Opt_tail) {
26000 + switch (opt->type) {
26002 + u.add = &opt->add;
26003 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26004 + u.add->bindex, u.add->pathname, u.add->perm,
26005 + u.add->path.dentry);
26009 + u.del = &opt->del;
26010 + AuDbg("del {%s, %p}\n",
26011 + u.del->pathname, u.del->h_path.dentry);
26015 + u.mod = &opt->mod;
26016 + AuDbg("mod {%s, 0x%x, %p}\n",
26017 + u.mod->path, u.mod->perm, u.mod->h_root);
26020 + u.add = &opt->add;
26021 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26022 + u.add->bindex, u.add->pathname, u.add->perm,
26023 + u.add->path.dentry);
26025 + case Opt_prepend:
26026 + u.add = &opt->add;
26027 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26028 + u.add->bindex, u.add->pathname, u.add->perm,
26029 + u.add->path.dentry);
26032 + AuDbg("dirwh %d\n", opt->dirwh);
26034 + case Opt_rdcache:
26035 + AuDbg("rdcache %d\n", opt->rdcache);
26038 + AuDbg("rdblk %u\n", opt->rdblk);
26040 + case Opt_rdblk_def:
26041 + AuDbg("rdblk_def\n");
26044 + AuDbg("rdhash %u\n", opt->rdhash);
26046 + case Opt_rdhash_def:
26047 + AuDbg("rdhash_def\n");
26050 + u.xino = &opt->xino;
26051 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26053 + case Opt_trunc_xino:
26054 + AuLabel(trunc_xino);
26056 + case Opt_notrunc_xino:
26057 + AuLabel(notrunc_xino);
26059 + case Opt_trunc_xino_path:
26060 + case Opt_itrunc_xino:
26061 + u.xino_itrunc = &opt->xino_itrunc;
26062 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26067 + case Opt_trunc_xib:
26068 + AuLabel(trunc_xib);
26070 + case Opt_notrunc_xib:
26071 + AuLabel(notrunc_xib);
26079 + case Opt_dirperm1:
26080 + AuLabel(dirperm1);
26082 + case Opt_nodirperm1:
26083 + AuLabel(nodirperm1);
26088 + case Opt_noplink:
26089 + AuLabel(noplink);
26091 + case Opt_list_plink:
26092 + AuLabel(list_plink);
26095 + AuDbg("udba %d, %s\n",
26096 + opt->udba, au_optstr_udba(opt->udba));
26104 + case Opt_diropq_a:
26105 + AuLabel(diropq_a);
26107 + case Opt_diropq_w:
26108 + AuLabel(diropq_w);
26110 + case Opt_warn_perm:
26111 + AuLabel(warn_perm);
26113 + case Opt_nowarn_perm:
26114 + AuLabel(nowarn_perm);
26116 + case Opt_verbose:
26117 + AuLabel(verbose);
26119 + case Opt_noverbose:
26120 + AuLabel(noverbose);
26131 + case Opt_wbr_create:
26132 + u.create = &opt->wbr_create;
26133 + AuDbg("create %d, %s\n", u.create->wbr_create,
26134 + au_optstr_wbr_create(u.create->wbr_create));
26135 + switch (u.create->wbr_create) {
26136 + case AuWbrCreate_MFSV:
26137 + case AuWbrCreate_PMFSV:
26138 + AuDbg("%d sec\n", u.create->mfs_second);
26140 + case AuWbrCreate_MFSRR:
26141 + case AuWbrCreate_TDMFS:
26142 + AuDbg("%llu watermark\n",
26143 + u.create->mfsrr_watermark);
26145 + case AuWbrCreate_MFSRRV:
26146 + case AuWbrCreate_TDMFSV:
26147 + case AuWbrCreate_PMFSRRV:
26148 + AuDbg("%llu watermark, %d sec\n",
26149 + u.create->mfsrr_watermark,
26150 + u.create->mfs_second);
26154 + case Opt_wbr_copyup:
26155 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26156 + au_optstr_wbr_copyup(opt->wbr_copyup));
26158 + case Opt_fhsm_sec:
26159 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26164 + case Opt_nodirren:
26165 + AuLabel(nodirren);
26181 +void au_opts_free(struct au_opts *opts)
26183 + struct au_opt *opt;
26186 + while (opt->type != Opt_tail) {
26187 + switch (opt->type) {
26190 + case Opt_prepend:
26191 + path_put(&opt->add.path);
26195 + path_put(&opt->del.h_path);
26199 + dput(opt->mod.h_root);
26202 + fput(opt->xino.file);
26209 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26210 + aufs_bindex_t bindex)
26213 + struct au_opt_add *add = &opt->add;
26216 + add->bindex = bindex;
26217 + add->perm = AuBrPerm_RO;
26218 + add->pathname = opt_str;
26219 + p = strchr(opt_str, '=');
26223 + add->perm = br_perm_val(p);
26226 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26229 + add->perm = AuBrPerm_RO;
26230 + if (au_test_fs_rr(add->path.dentry->d_sb))
26231 + add->perm = AuBrPerm_RR;
26232 + else if (!bindex && !(sb_flags & SB_RDONLY))
26233 + add->perm = AuBrPerm_RW;
26235 + opt->type = Opt_add;
26238 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26245 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26249 + del->pathname = args[0].from;
26250 + AuDbg("del path %s\n", del->pathname);
26252 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26253 + if (unlikely(err))
26254 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26259 +#if 0 /* reserved for future use */
26260 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26261 + struct au_opt_del *del, substring_t args[])
26264 + struct dentry *root;
26267 + root = sb->s_root;
26268 + aufs_read_lock(root, AuLock_FLUSH);
26269 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26270 + pr_err("out of bounds, %d\n", bindex);
26275 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26276 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26279 + aufs_read_unlock(root, !AuLock_IR);
26284 +static int noinline_for_stack
26285 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26288 + struct path path;
26292 + mod->path = args[0].from;
26293 + p = strchr(mod->path, '=');
26294 + if (unlikely(!p)) {
26295 + pr_err("no permssion %s\n", args[0].from);
26300 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26301 + if (unlikely(err)) {
26302 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26306 + mod->perm = br_perm_val(p);
26307 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26308 + mod->h_root = dget(path.dentry);
26315 +#if 0 /* reserved for future use */
26316 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26317 + struct au_opt_mod *mod, substring_t args[])
26320 + struct dentry *root;
26323 + root = sb->s_root;
26324 + aufs_read_lock(root, AuLock_FLUSH);
26325 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26326 + pr_err("out of bounds, %d\n", bindex);
26331 + mod->perm = br_perm_val(args[1].from);
26332 + AuDbg("mod path %s, perm 0x%x, %s\n",
26333 + mod->path, mod->perm, args[1].from);
26334 + mod->h_root = dget(au_h_dptr(root, bindex));
26337 + aufs_read_unlock(root, !AuLock_IR);
26342 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26343 + substring_t args[])
26346 + struct file *file;
26348 + file = au_xino_create(sb, args[0].from, /*silent*/0);
26349 + err = PTR_ERR(file);
26350 + if (IS_ERR(file))
26354 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26356 + pr_err("%s must be outside\n", args[0].from);
26361 + xino->file = file;
26362 + xino->path = args[0].from;
26368 +static int noinline_for_stack
26369 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26370 + struct au_opt_xino_itrunc *xino_itrunc,
26371 + substring_t args[])
26374 + aufs_bindex_t bbot, bindex;
26375 + struct path path;
26376 + struct dentry *root;
26378 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26379 + if (unlikely(err)) {
26380 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26384 + xino_itrunc->bindex = -1;
26385 + root = sb->s_root;
26386 + aufs_read_lock(root, AuLock_FLUSH);
26387 + bbot = au_sbbot(sb);
26388 + for (bindex = 0; bindex <= bbot; bindex++) {
26389 + if (au_h_dptr(root, bindex) == path.dentry) {
26390 + xino_itrunc->bindex = bindex;
26394 + aufs_read_unlock(root, !AuLock_IR);
26397 + if (unlikely(xino_itrunc->bindex < 0)) {
26398 + pr_err("no such branch %s\n", args[0].from);
26406 +/* called without aufs lock */
26407 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26409 + int err, n, token;
26410 + aufs_bindex_t bindex;
26411 + unsigned char skipped;
26412 + struct dentry *root;
26413 + struct au_opt *opt, *opt_tail;
26415 + /* reduce the stack space */
26417 + struct au_opt_xino_itrunc *xino_itrunc;
26418 + struct au_opt_wbr_create *create;
26421 + substring_t args[MAX_OPT_ARGS];
26425 + a = kmalloc(sizeof(*a), GFP_NOFS);
26426 + if (unlikely(!a))
26429 + root = sb->s_root;
26433 + opt_tail = opt + opts->max_opt - 1;
26434 + opt->type = Opt_tail;
26435 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26438 + token = match_token(opt_str, options, a->args);
26442 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26444 + err = opt_add(opt, opt_str, opts->sb_flags,
26446 + if (unlikely(!err && ++opt > opt_tail)) {
26450 + opt->type = Opt_tail;
26455 + if (unlikely(match_int(&a->args[0], &n))) {
26456 + pr_err("bad integer in %s\n", opt_str);
26460 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26463 + opt->type = token;
26466 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26467 + /*dummy bindex*/1);
26469 + opt->type = token;
26471 + case Opt_prepend:
26472 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26475 + opt->type = token;
26478 + err = au_opts_parse_del(&opt->del, a->args);
26480 + opt->type = token;
26482 +#if 0 /* reserved for future use */
26484 + del->pathname = "(indexed)";
26485 + if (unlikely(match_int(&args[0], &n))) {
26486 + pr_err("bad integer in %s\n", opt_str);
26489 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26491 + opt->type = token;
26495 + err = au_opts_parse_mod(&opt->mod, a->args);
26497 + opt->type = token;
26499 +#ifdef IMOD /* reserved for future use */
26501 + u.mod->path = "(indexed)";
26502 + if (unlikely(match_int(&a->args[0], &n))) {
26503 + pr_err("bad integer in %s\n", opt_str);
26506 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26508 + opt->type = token;
26512 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26514 + opt->type = token;
26517 + case Opt_trunc_xino_path:
26518 + err = au_opts_parse_xino_itrunc_path
26519 + (sb, &opt->xino_itrunc, a->args);
26521 + opt->type = token;
26524 + case Opt_itrunc_xino:
26525 + u.xino_itrunc = &opt->xino_itrunc;
26526 + if (unlikely(match_int(&a->args[0], &n))) {
26527 + pr_err("bad integer in %s\n", opt_str);
26530 + u.xino_itrunc->bindex = n;
26531 + aufs_read_lock(root, AuLock_FLUSH);
26532 + if (n < 0 || au_sbbot(sb) < n) {
26533 + pr_err("out of bounds, %d\n", n);
26534 + aufs_read_unlock(root, !AuLock_IR);
26537 + aufs_read_unlock(root, !AuLock_IR);
26539 + opt->type = token;
26543 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26546 + opt->type = token;
26549 + case Opt_rdcache:
26550 + if (unlikely(match_int(&a->args[0], &n))) {
26551 + pr_err("bad integer in %s\n", opt_str);
26554 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26555 + pr_err("rdcache must be smaller than %d\n",
26556 + AUFS_RDCACHE_MAX);
26559 + opt->rdcache = n;
26561 + opt->type = token;
26564 + if (unlikely(match_int(&a->args[0], &n)
26566 + || n > KMALLOC_MAX_SIZE)) {
26567 + pr_err("bad integer in %s\n", opt_str);
26570 + if (unlikely(n && n < NAME_MAX)) {
26571 + pr_err("rdblk must be larger than %d\n",
26577 + opt->type = token;
26580 + if (unlikely(match_int(&a->args[0], &n)
26582 + || n * sizeof(struct hlist_head)
26583 + > KMALLOC_MAX_SIZE)) {
26584 + pr_err("bad integer in %s\n", opt_str);
26589 + opt->type = token;
26592 + case Opt_trunc_xino:
26593 + case Opt_notrunc_xino:
26595 + case Opt_trunc_xib:
26596 + case Opt_notrunc_xib:
26599 + case Opt_dirperm1:
26600 + case Opt_nodirperm1:
26602 + case Opt_noplink:
26603 + case Opt_list_plink:
26606 + case Opt_diropq_a:
26607 + case Opt_diropq_w:
26608 + case Opt_warn_perm:
26609 + case Opt_nowarn_perm:
26610 + case Opt_verbose:
26611 + case Opt_noverbose:
26615 + case Opt_rdblk_def:
26616 + case Opt_rdhash_def:
26618 + case Opt_nodirren:
26622 + opt->type = token;
26626 + opt->udba = udba_val(a->args[0].from);
26627 + if (opt->udba >= 0) {
26629 + opt->type = token;
26631 + pr_err("wrong value, %s\n", opt_str);
26634 + case Opt_wbr_create:
26635 + u.create = &opt->wbr_create;
26636 + u.create->wbr_create
26637 + = au_wbr_create_val(a->args[0].from, u.create);
26638 + if (u.create->wbr_create >= 0) {
26640 + opt->type = token;
26642 + pr_err("wrong value, %s\n", opt_str);
26644 + case Opt_wbr_copyup:
26645 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26646 + if (opt->wbr_copyup >= 0) {
26648 + opt->type = token;
26650 + pr_err("wrong value, %s\n", opt_str);
26653 + case Opt_fhsm_sec:
26654 + if (unlikely(match_int(&a->args[0], &n)
26656 + pr_err("bad integer in %s\n", opt_str);
26659 + if (sysaufs_brs) {
26660 + opt->fhsm_second = n;
26661 + opt->type = token;
26663 + pr_warn("ignored %s\n", opt_str);
26668 + pr_warn("ignored %s\n", opt_str);
26670 + case Opt_ignore_silent:
26675 + pr_err("unknown option %s\n", opt_str);
26679 + if (!err && !skipped) {
26680 + if (unlikely(++opt > opt_tail)) {
26683 + opt->type = Opt_tail;
26686 + opt->type = Opt_tail;
26692 + if (unlikely(err))
26693 + au_opts_free(opts);
26699 +static int au_opt_wbr_create(struct super_block *sb,
26700 + struct au_opt_wbr_create *create)
26703 + struct au_sbinfo *sbinfo;
26705 + SiMustWriteLock(sb);
26707 + err = 1; /* handled */
26708 + sbinfo = au_sbi(sb);
26709 + if (sbinfo->si_wbr_create_ops->fin) {
26710 + err = sbinfo->si_wbr_create_ops->fin(sb);
26715 + sbinfo->si_wbr_create = create->wbr_create;
26716 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26717 + switch (create->wbr_create) {
26718 + case AuWbrCreate_MFSRRV:
26719 + case AuWbrCreate_MFSRR:
26720 + case AuWbrCreate_TDMFS:
26721 + case AuWbrCreate_TDMFSV:
26722 + case AuWbrCreate_PMFSRR:
26723 + case AuWbrCreate_PMFSRRV:
26724 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26726 + case AuWbrCreate_MFS:
26727 + case AuWbrCreate_MFSV:
26728 + case AuWbrCreate_PMFS:
26729 + case AuWbrCreate_PMFSV:
26730 + sbinfo->si_wbr_mfs.mfs_expire
26731 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
26735 + if (sbinfo->si_wbr_create_ops->init)
26736 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
26743 + * plus: processed without an error
26744 + * zero: unprocessed
26746 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
26747 + struct au_opts *opts)
26750 + struct au_sbinfo *sbinfo;
26752 + SiMustWriteLock(sb);
26754 + err = 1; /* handled */
26755 + sbinfo = au_sbi(sb);
26756 + switch (opt->type) {
26758 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
26759 + sbinfo->si_mntflags |= opt->udba;
26760 + opts->given_udba |= opt->udba;
26764 + au_opt_set(sbinfo->si_mntflags, PLINK);
26766 + case Opt_noplink:
26767 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26768 + au_plink_put(sb, /*verbose*/1);
26769 + au_opt_clr(sbinfo->si_mntflags, PLINK);
26771 + case Opt_list_plink:
26772 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26773 + au_plink_list(sb);
26777 + au_opt_set(sbinfo->si_mntflags, DIO);
26778 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26781 + au_opt_clr(sbinfo->si_mntflags, DIO);
26782 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26785 + case Opt_fhsm_sec:
26786 + au_fhsm_set(sbinfo, opt->fhsm_second);
26789 + case Opt_diropq_a:
26790 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26792 + case Opt_diropq_w:
26793 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26796 + case Opt_warn_perm:
26797 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
26799 + case Opt_nowarn_perm:
26800 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
26803 + case Opt_verbose:
26804 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
26806 + case Opt_noverbose:
26807 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
26811 + au_opt_set(sbinfo->si_mntflags, SUM);
26814 + au_opt_clr(sbinfo->si_mntflags, SUM);
26815 + au_opt_set(sbinfo->si_mntflags, SUM_W);
26817 + au_opt_clr(sbinfo->si_mntflags, SUM);
26818 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
26821 + case Opt_wbr_create:
26822 + err = au_opt_wbr_create(sb, &opt->wbr_create);
26824 + case Opt_wbr_copyup:
26825 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
26826 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
26830 + sbinfo->si_dirwh = opt->dirwh;
26833 + case Opt_rdcache:
26834 + sbinfo->si_rdcache
26835 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
26838 + sbinfo->si_rdblk = opt->rdblk;
26840 + case Opt_rdblk_def:
26841 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26844 + sbinfo->si_rdhash = opt->rdhash;
26846 + case Opt_rdhash_def:
26847 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26851 + au_opt_set(sbinfo->si_mntflags, SHWH);
26854 + au_opt_clr(sbinfo->si_mntflags, SHWH);
26857 + case Opt_dirperm1:
26858 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
26860 + case Opt_nodirperm1:
26861 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
26864 + case Opt_trunc_xino:
26865 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
26867 + case Opt_notrunc_xino:
26868 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
26871 + case Opt_trunc_xino_path:
26872 + case Opt_itrunc_xino:
26873 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
26878 + case Opt_trunc_xib:
26879 + au_fset_opts(opts->flags, TRUNC_XIB);
26881 + case Opt_notrunc_xib:
26882 + au_fclr_opts(opts->flags, TRUNC_XIB);
26887 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
26888 + err = au_dr_opt_set(sb);
26893 + au_opt_set(sbinfo->si_mntflags, DIRREN);
26895 + case Opt_nodirren:
26897 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
26898 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
26904 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
26908 + sb->s_flags |= SB_POSIXACL;
26911 + sb->s_flags &= ~SB_POSIXACL;
26923 + * returns tri-state.
26924 + * plus: processed without an error
26925 + * zero: unprocessed
26928 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
26929 + struct au_opts *opts)
26931 + int err, do_refresh;
26934 + switch (opt->type) {
26936 + opt->add.bindex = au_sbbot(sb) + 1;
26937 + if (opt->add.bindex < 0)
26938 + opt->add.bindex = 0;
26940 + case Opt_prepend:
26941 + opt->add.bindex = 0;
26942 + add: /* indented label */
26944 + err = au_br_add(sb, &opt->add,
26945 + au_ftest_opts(opts->flags, REMOUNT));
26948 + au_fset_opts(opts->flags, REFRESH);
26954 + err = au_br_del(sb, &opt->del,
26955 + au_ftest_opts(opts->flags, REMOUNT));
26958 + au_fset_opts(opts->flags, TRUNC_XIB);
26959 + au_fset_opts(opts->flags, REFRESH);
26965 + err = au_br_mod(sb, &opt->mod,
26966 + au_ftest_opts(opts->flags, REMOUNT),
26971 + au_fset_opts(opts->flags, REFRESH);
26978 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
26979 + struct au_opt_xino **opt_xino,
26980 + struct au_opts *opts)
26983 + aufs_bindex_t bbot, bindex;
26984 + struct dentry *root, *parent, *h_root;
26987 + switch (opt->type) {
26989 + au_xino_brid_set(sb, -1);
26990 + /* safe d_parent access */
26991 + parent = opt->xino.file->f_path.dentry->d_parent;
26992 + root = sb->s_root;
26993 + bbot = au_sbbot(sb);
26994 + for (bindex = 0; bindex <= bbot; bindex++) {
26995 + h_root = au_h_dptr(root, bindex);
26996 + if (h_root == parent) {
26997 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
27002 + err = au_xino_set(sb, &opt->xino,
27003 + !!au_ftest_opts(opts->flags, REMOUNT));
27004 + if (unlikely(err))
27007 + *opt_xino = &opt->xino;
27012 + *opt_xino = (void *)-1;
27019 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27020 + unsigned int pending)
27023 + aufs_bindex_t bindex, bbot;
27024 + unsigned char do_plink, skip, do_free, can_no_dreval;
27025 + struct au_branch *br;
27026 + struct au_wbr *wbr;
27027 + struct dentry *root, *dentry;
27028 + struct inode *dir, *h_dir;
27029 + struct au_sbinfo *sbinfo;
27030 + struct au_hinode *hdir;
27032 + SiMustAnyLock(sb);
27034 + sbinfo = au_sbi(sb);
27035 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27037 + if (!(sb_flags & SB_RDONLY)) {
27038 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27039 + pr_warn("first branch should be rw\n");
27040 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27041 + pr_warn_once("shwh should be used with ro\n");
27044 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27045 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27046 + pr_warn_once("udba=*notify requires xino\n");
27048 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27049 + pr_warn_once("dirperm1 breaks the protection"
27050 + " by the permission bits on the lower branch\n");
27054 + root = sb->s_root;
27055 + dir = d_inode(root);
27056 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27057 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27059 + bbot = au_sbbot(sb);
27060 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27062 + h_dir = au_h_iptr(dir, bindex);
27063 + br = au_sbr(sb, bindex);
27065 + if ((br->br_perm & AuBrAttr_ICEX)
27066 + && !h_dir->i_op->listxattr)
27067 + br->br_perm &= ~AuBrAttr_ICEX;
27069 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27070 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27071 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27075 + wbr = br->br_wbr;
27077 + wbr_wh_read_lock(wbr);
27079 + if (!au_br_writable(br->br_perm)) {
27082 + || (!wbr->wbr_whbase
27083 + && !wbr->wbr_plink
27084 + && !wbr->wbr_orph));
27085 + } else if (!au_br_wh_linkable(br->br_perm)) {
27086 + /* skip = (!br->br_whbase && !br->br_orph); */
27087 + skip = (!wbr || !wbr->wbr_whbase);
27088 + if (skip && wbr) {
27090 + skip = !!wbr->wbr_plink;
27092 + skip = !wbr->wbr_plink;
27095 + /* skip = (br->br_whbase && br->br_ohph); */
27096 + skip = (wbr && wbr->wbr_whbase);
27099 + skip = !!wbr->wbr_plink;
27101 + skip = !wbr->wbr_plink;
27105 + wbr_wh_read_unlock(wbr);
27107 + if (can_no_dreval) {
27108 + dentry = br->br_path.dentry;
27109 + spin_lock(&dentry->d_lock);
27110 + if (dentry->d_flags &
27111 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27112 + can_no_dreval = 0;
27113 + spin_unlock(&dentry->d_lock);
27116 + if (au_br_fhsm(br->br_perm)) {
27118 + AuDebugOn(!br->br_fhsm);
27124 + hdir = au_hi(dir, bindex);
27125 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27127 + wbr_wh_write_lock(wbr);
27128 + err = au_wh_init(br, sb);
27130 + wbr_wh_write_unlock(wbr);
27131 + au_hn_inode_unlock(hdir);
27133 + if (!err && do_free) {
27135 + br->br_wbr = NULL;
27139 + if (can_no_dreval)
27140 + au_fset_si(sbinfo, NO_DREVAL);
27142 + au_fclr_si(sbinfo, NO_DREVAL);
27145 + au_fset_si(sbinfo, FHSM);
27146 + for (bindex = bbot; bindex >= 0; bindex--) {
27147 + br = au_sbr(sb, bindex);
27148 + if (au_br_fhsm(br->br_perm)) {
27149 + au_fhsm_set_bottom(sb, bindex);
27154 + au_fclr_si(sbinfo, FHSM);
27155 + au_fhsm_set_bottom(sb, -1);
27161 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27164 + unsigned int tmp;
27165 + aufs_bindex_t bindex, bbot;
27166 + struct au_opt *opt;
27167 + struct au_opt_xino *opt_xino, xino;
27168 + struct au_sbinfo *sbinfo;
27169 + struct au_branch *br;
27170 + struct inode *dir;
27172 + SiMustWriteLock(sb);
27177 + while (err >= 0 && opt->type != Opt_tail)
27178 + err = au_opt_simple(sb, opt++, opts);
27181 + else if (unlikely(err < 0))
27184 + /* disable xino and udba temporary */
27185 + sbinfo = au_sbi(sb);
27186 + tmp = sbinfo->si_mntflags;
27187 + au_opt_clr(sbinfo->si_mntflags, XINO);
27188 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27191 + while (err >= 0 && opt->type != Opt_tail)
27192 + err = au_opt_br(sb, opt++, opts);
27195 + else if (unlikely(err < 0))
27198 + bbot = au_sbbot(sb);
27199 + if (unlikely(bbot < 0)) {
27201 + pr_err("no branches\n");
27205 + if (au_opt_test(tmp, XINO))
27206 + au_opt_set(sbinfo->si_mntflags, XINO);
27208 + while (!err && opt->type != Opt_tail)
27209 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27210 + if (unlikely(err))
27213 + err = au_opts_verify(sb, sb->s_flags, tmp);
27214 + if (unlikely(err))
27217 + /* restore xino */
27218 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27219 + xino.file = au_xino_def(sb);
27220 + err = PTR_ERR(xino.file);
27221 + if (IS_ERR(xino.file))
27224 + err = au_xino_set(sb, &xino, /*remount*/0);
27226 + if (unlikely(err))
27230 + /* restore udba */
27231 + tmp &= AuOptMask_UDBA;
27232 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27233 + sbinfo->si_mntflags |= tmp;
27234 + bbot = au_sbbot(sb);
27235 + for (bindex = 0; bindex <= bbot; bindex++) {
27236 + br = au_sbr(sb, bindex);
27237 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27238 + if (unlikely(err))
27239 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27241 + /* go on even if err */
27243 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27244 + dir = d_inode(sb->s_root);
27245 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27252 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27255 + unsigned char no_dreval;
27256 + struct inode *dir;
27257 + struct au_opt_xino *opt_xino;
27258 + struct au_opt *opt;
27259 + struct au_sbinfo *sbinfo;
27261 + SiMustWriteLock(sb);
27263 + err = au_dr_opt_flush(sb);
27264 + if (unlikely(err))
27266 + au_fset_opts(opts->flags, DR_FLUSHED);
27268 + dir = d_inode(sb->s_root);
27269 + sbinfo = au_sbi(sb);
27272 + while (err >= 0 && opt->type != Opt_tail) {
27273 + err = au_opt_simple(sb, opt, opts);
27275 + err = au_opt_br(sb, opt, opts);
27277 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27283 + /* go on even err */
27285 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27286 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27287 + if (unlikely(rerr && !err))
27290 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27291 + au_fset_opts(opts->flags, REFRESH_IDOP);
27293 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27294 + rerr = au_xib_trunc(sb);
27295 + if (unlikely(rerr && !err))
27299 + /* will be handled by the caller */
27300 + if (!au_ftest_opts(opts->flags, REFRESH)
27301 + && (opts->given_udba
27302 + || au_opt_test(sbinfo->si_mntflags, XINO)
27303 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27305 + au_fset_opts(opts->flags, REFRESH);
27307 + AuDbg("status 0x%x\n", opts->flags);
27313 +/* ---------------------------------------------------------------------- */
27315 +unsigned int au_opt_udba(struct super_block *sb)
27317 + return au_mntflags(sb) & AuOptMask_UDBA;
27319 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27320 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27321 +++ linux/fs/aufs/opts.h 2018-08-12 23:43:05.460124736 +0200
27323 +/* SPDX-License-Identifier: GPL-2.0 */
27325 + * Copyright (C) 2005-2018 Junjiro R. Okajima
27327 + * This program, aufs is free software; you can redistribute it and/or modify
27328 + * it under the terms of the GNU General Public License as published by
27329 + * the Free Software Foundation; either version 2 of the License, or
27330 + * (at your option) any later version.
27332 + * This program is distributed in the hope that it will be useful,
27333 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27334 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27335 + * GNU General Public License for more details.
27337 + * You should have received a copy of the GNU General Public License
27338 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27342 + * mount options/flags
27345 +#ifndef __AUFS_OPTS_H__
27346 +#define __AUFS_OPTS_H__
27350 +#include <linux/path.h>
27354 +/* ---------------------------------------------------------------------- */
27357 +#define AuOpt_XINO 1 /* external inode number bitmap
27358 + and translation table */
27359 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27360 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27361 +#define AuOpt_UDBA_REVAL (1 << 3)
27362 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27363 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27364 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27365 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27367 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27368 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27369 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27370 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27371 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
27372 +#define AuOpt_DIO (1 << 14) /* direct io */
27373 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27375 +#ifndef CONFIG_AUFS_HNOTIFY
27376 +#undef AuOpt_UDBA_HNOTIFY
27377 +#define AuOpt_UDBA_HNOTIFY 0
27379 +#ifndef CONFIG_AUFS_DIRREN
27380 +#undef AuOpt_DIRREN
27381 +#define AuOpt_DIRREN 0
27383 +#ifndef CONFIG_AUFS_SHWH
27385 +#define AuOpt_SHWH 0
27388 +#define AuOpt_Def (AuOpt_XINO \
27389 + | AuOpt_UDBA_REVAL \
27391 + /* | AuOpt_DIRPERM1 */ \
27392 + | AuOpt_WARN_PERM)
27393 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27394 + | AuOpt_UDBA_REVAL \
27395 + | AuOpt_UDBA_HNOTIFY)
27397 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27398 +#define au_opt_set(flags, name) do { \
27399 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27400 + ((flags) |= AuOpt_##name); \
27402 +#define au_opt_set_udba(flags, name) do { \
27403 + (flags) &= ~AuOptMask_UDBA; \
27404 + ((flags) |= AuOpt_##name); \
27406 +#define au_opt_clr(flags, name) do { \
27407 + ((flags) &= ~AuOpt_##name); \
27410 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27412 +#ifdef CONFIG_PROC_FS
27415 + return mntflags & ~AuOpt_PLINK;
27419 +/* ---------------------------------------------------------------------- */
27421 +/* policies to select one among multiple writable branches */
27423 + AuWbrCreate_TDP, /* top down parent */
27424 + AuWbrCreate_RR, /* round robin */
27425 + AuWbrCreate_MFS, /* most free space */
27426 + AuWbrCreate_MFSV, /* mfs with seconds */
27427 + AuWbrCreate_MFSRR, /* mfs then rr */
27428 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27429 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27430 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27431 + AuWbrCreate_PMFS, /* parent and mfs */
27432 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27433 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27434 + AuWbrCreate_PMFSRRV, /* plus seconds */
27436 + AuWbrCreate_Def = AuWbrCreate_TDP
27440 + AuWbrCopyup_TDP, /* top down parent */
27441 + AuWbrCopyup_BUP, /* bottom up parent */
27442 + AuWbrCopyup_BU, /* bottom up */
27444 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27447 +/* ---------------------------------------------------------------------- */
27449 +struct au_opt_add {
27450 + aufs_bindex_t bindex;
27453 + struct path path;
27456 +struct au_opt_del {
27458 + struct path h_path;
27461 +struct au_opt_mod {
27464 + struct dentry *h_root;
27467 +struct au_opt_xino {
27469 + struct file *file;
27472 +struct au_opt_xino_itrunc {
27473 + aufs_bindex_t bindex;
27476 +struct au_opt_wbr_create {
27479 + unsigned long long mfsrr_watermark;
27485 + struct au_opt_xino xino;
27486 + struct au_opt_xino_itrunc xino_itrunc;
27487 + struct au_opt_add add;
27488 + struct au_opt_del del;
27489 + struct au_opt_mod mod;
27492 + unsigned int rdblk;
27493 + unsigned int rdhash;
27495 + struct au_opt_wbr_create wbr_create;
27497 + unsigned int fhsm_second;
27502 +#define AuOpts_REMOUNT 1
27503 +#define AuOpts_REFRESH (1 << 1)
27504 +#define AuOpts_TRUNC_XIB (1 << 2)
27505 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27506 +#define AuOpts_REFRESH_IDOP (1 << 4)
27507 +#define AuOpts_DR_FLUSHED (1 << 5)
27508 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27509 +#define au_fset_opts(flags, name) \
27510 + do { (flags) |= AuOpts_##name; } while (0)
27511 +#define au_fclr_opts(flags, name) \
27512 + do { (flags) &= ~AuOpts_##name; } while (0)
27514 +#ifndef CONFIG_AUFS_DIRREN
27515 +#undef AuOpts_DR_FLUSHED
27516 +#define AuOpts_DR_FLUSHED 0
27520 + struct au_opt *opt;
27523 + unsigned int given_udba;
27524 + unsigned int flags;
27525 + unsigned long sb_flags;
27528 +/* ---------------------------------------------------------------------- */
27531 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27532 +const char *au_optstr_udba(int udba);
27533 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27534 +const char *au_optstr_wbr_create(int wbr_create);
27536 +void au_opts_free(struct au_opts *opts);
27537 +struct super_block;
27538 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27539 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27540 + unsigned int pending);
27541 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27542 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27544 +unsigned int au_opt_udba(struct super_block *sb);
27546 +#endif /* __KERNEL__ */
27547 +#endif /* __AUFS_OPTS_H__ */
27548 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27549 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27550 +++ linux/fs/aufs/plink.c 2018-08-12 23:43:05.460124736 +0200
27552 +// SPDX-License-Identifier: GPL-2.0
27554 + * Copyright (C) 2005-2018 Junjiro R. Okajima
27556 + * This program, aufs is free software; you can redistribute it and/or modify
27557 + * it under the terms of the GNU General Public License as published by
27558 + * the Free Software Foundation; either version 2 of the License, or
27559 + * (at your option) any later version.
27561 + * This program is distributed in the hope that it will be useful,
27562 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27563 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27564 + * GNU General Public License for more details.
27566 + * You should have received a copy of the GNU General Public License
27567 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27577 + * the pseudo-link maintenance mode.
27578 + * during a user process maintains the pseudo-links,
27579 + * prohibit adding a new plink and branch manipulation.
27583 + * For entry functions which will handle plink, and i_mutex is already held
27585 + * They cannot wait and should return an error at once.
27586 + * Callers has to check the error.
27588 + * For entry functions which will handle plink, but i_mutex is not held
27590 + * They can wait the plink maintenance mode to finish.
27592 + * They behave like F_SETLK and F_SETLKW.
27593 + * If the caller never handle plink, then both flags are unnecessary.
27596 +int au_plink_maint(struct super_block *sb, int flags)
27600 + struct task_struct *parent, *prev;
27601 + struct au_sbinfo *sbi;
27603 + SiMustAnyLock(sb);
27606 + if (!au_opt_test(au_mntflags(sb), PLINK))
27609 + sbi = au_sbi(sb);
27610 + pid = sbi->si_plink_maint_pid;
27611 + if (!pid || pid == current->pid)
27614 + /* todo: it highly depends upon /sbin/mount.aufs */
27616 + parent = current;
27620 + parent = rcu_dereference(parent->real_parent);
27621 + if (parent == prev)
27623 + ppid = task_pid_vnr(parent);
27624 + if (pid == ppid) {
27625 + rcu_read_unlock();
27630 + rcu_read_unlock();
27632 + if (au_ftest_lock(flags, NOPLMW)) {
27633 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27634 + /* AuDebugOn(!lockdep_depth(current)); */
27635 + while (sbi->si_plink_maint_pid) {
27636 + si_read_unlock(sb);
27637 + /* gave up wake_up_bit() */
27638 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27640 + if (au_ftest_lock(flags, FLUSH))
27641 + au_nwt_flush(&sbi->si_nowait);
27642 + si_noflush_read_lock(sb);
27644 + } else if (au_ftest_lock(flags, NOPLM)) {
27645 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27653 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27655 + spin_lock(&sbinfo->si_plink_maint_lock);
27656 + sbinfo->si_plink_maint_pid = 0;
27657 + spin_unlock(&sbinfo->si_plink_maint_lock);
27658 + wake_up_all(&sbinfo->si_plink_wq);
27661 +int au_plink_maint_enter(struct super_block *sb)
27664 + struct au_sbinfo *sbinfo;
27667 + sbinfo = au_sbi(sb);
27668 + /* make sure i am the only one in this fs */
27669 + si_write_lock(sb, AuLock_FLUSH);
27670 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27671 + spin_lock(&sbinfo->si_plink_maint_lock);
27672 + if (!sbinfo->si_plink_maint_pid)
27673 + sbinfo->si_plink_maint_pid = current->pid;
27676 + spin_unlock(&sbinfo->si_plink_maint_lock);
27678 + si_write_unlock(sb);
27683 +/* ---------------------------------------------------------------------- */
27685 +#ifdef CONFIG_AUFS_DEBUG
27686 +void au_plink_list(struct super_block *sb)
27689 + struct au_sbinfo *sbinfo;
27690 + struct hlist_bl_head *hbl;
27691 + struct hlist_bl_node *pos;
27692 + struct au_icntnr *icntnr;
27694 + SiMustAnyLock(sb);
27696 + sbinfo = au_sbi(sb);
27697 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27698 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27700 + for (i = 0; i < AuPlink_NHASH; i++) {
27701 + hbl = sbinfo->si_plink + i;
27702 + hlist_bl_lock(hbl);
27703 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27704 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27705 + hlist_bl_unlock(hbl);
27710 +/* is the inode pseudo-linked? */
27711 +int au_plink_test(struct inode *inode)
27714 + struct au_sbinfo *sbinfo;
27715 + struct hlist_bl_head *hbl;
27716 + struct hlist_bl_node *pos;
27717 + struct au_icntnr *icntnr;
27719 + sbinfo = au_sbi(inode->i_sb);
27720 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27721 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27722 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27725 + i = au_plink_hash(inode->i_ino);
27726 + hbl = sbinfo->si_plink + i;
27727 + hlist_bl_lock(hbl);
27728 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27729 + if (&icntnr->vfs_inode == inode) {
27733 + hlist_bl_unlock(hbl);
27737 +/* ---------------------------------------------------------------------- */
27740 + * generate a name for plink.
27741 + * the file will be stored under AUFS_WH_PLINKDIR.
27743 +/* 20 is max digits length of ulong 64 */
27744 +#define PLINK_NAME_LEN ((20 + 1) * 2)
27746 +static int plink_name(char *name, int len, struct inode *inode,
27747 + aufs_bindex_t bindex)
27750 + struct inode *h_inode;
27752 + h_inode = au_h_iptr(inode, bindex);
27753 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
27757 +struct au_do_plink_lkup_args {
27758 + struct dentry **errp;
27759 + struct qstr *tgtname;
27760 + struct dentry *h_parent;
27761 + struct au_branch *br;
27764 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
27765 + struct dentry *h_parent,
27766 + struct au_branch *br)
27768 + struct dentry *h_dentry;
27769 + struct inode *h_inode;
27771 + h_inode = d_inode(h_parent);
27772 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
27773 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
27774 + inode_unlock_shared(h_inode);
27778 +static void au_call_do_plink_lkup(void *args)
27780 + struct au_do_plink_lkup_args *a = args;
27781 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
27784 +/* lookup the plink-ed @inode under the branch at @bindex */
27785 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
27787 + struct dentry *h_dentry, *h_parent;
27788 + struct au_branch *br;
27790 + char a[PLINK_NAME_LEN];
27791 + struct qstr tgtname = QSTR_INIT(a, 0);
27793 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27795 + br = au_sbr(inode->i_sb, bindex);
27796 + h_parent = br->br_wbr->wbr_plink;
27797 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27799 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27800 + struct au_do_plink_lkup_args args = {
27801 + .errp = &h_dentry,
27802 + .tgtname = &tgtname,
27803 + .h_parent = h_parent,
27807 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
27808 + if (unlikely(wkq_err))
27809 + h_dentry = ERR_PTR(wkq_err);
27811 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
27816 +/* create a pseudo-link */
27817 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
27818 + struct dentry *h_dentry, struct au_branch *br)
27821 + struct path h_path = {
27822 + .mnt = au_br_mnt(br)
27824 + struct inode *h_dir, *delegated;
27826 + h_dir = d_inode(h_parent);
27827 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
27829 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
27830 + err = PTR_ERR(h_path.dentry);
27831 + if (IS_ERR(h_path.dentry))
27835 + /* wh.plink dir is not monitored */
27836 + /* todo: is it really safe? */
27837 + if (d_is_positive(h_path.dentry)
27838 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
27839 + delegated = NULL;
27840 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
27841 + if (unlikely(err == -EWOULDBLOCK)) {
27842 + pr_warn("cannot retry for NFSv4 delegation"
27843 + " for an internal unlink\n");
27846 + dput(h_path.dentry);
27847 + h_path.dentry = NULL;
27851 + if (!err && d_is_negative(h_path.dentry)) {
27852 + delegated = NULL;
27853 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
27854 + if (unlikely(err == -EWOULDBLOCK)) {
27855 + pr_warn("cannot retry for NFSv4 delegation"
27856 + " for an internal link\n");
27860 + dput(h_path.dentry);
27863 + inode_unlock(h_dir);
27867 +struct do_whplink_args {
27869 + struct qstr *tgt;
27870 + struct dentry *h_parent;
27871 + struct dentry *h_dentry;
27872 + struct au_branch *br;
27875 +static void call_do_whplink(void *args)
27877 + struct do_whplink_args *a = args;
27878 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
27881 +static int whplink(struct dentry *h_dentry, struct inode *inode,
27882 + aufs_bindex_t bindex, struct au_branch *br)
27884 + int err, wkq_err;
27885 + struct au_wbr *wbr;
27886 + struct dentry *h_parent;
27887 + char a[PLINK_NAME_LEN];
27888 + struct qstr tgtname = QSTR_INIT(a, 0);
27890 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
27891 + h_parent = wbr->wbr_plink;
27892 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27894 + /* always superio. */
27895 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27896 + struct do_whplink_args args = {
27899 + .h_parent = h_parent,
27900 + .h_dentry = h_dentry,
27903 + wkq_err = au_wkq_wait(call_do_whplink, &args);
27904 + if (unlikely(wkq_err))
27907 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
27913 + * create a new pseudo-link for @h_dentry on @bindex.
27914 + * the linked inode is held in aufs @inode.
27916 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
27917 + struct dentry *h_dentry)
27919 + struct super_block *sb;
27920 + struct au_sbinfo *sbinfo;
27921 + struct hlist_bl_head *hbl;
27922 + struct hlist_bl_node *pos;
27923 + struct au_icntnr *icntnr;
27924 + int found, err, cnt, i;
27926 + sb = inode->i_sb;
27927 + sbinfo = au_sbi(sb);
27928 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27929 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27931 + found = au_plink_test(inode);
27935 + i = au_plink_hash(inode->i_ino);
27936 + hbl = sbinfo->si_plink + i;
27939 + hlist_bl_lock(hbl);
27940 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
27941 + if (&icntnr->vfs_inode == inode) {
27947 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
27948 + hlist_bl_add_head(&icntnr->plink, hbl);
27950 + hlist_bl_unlock(hbl);
27952 + cnt = au_hbl_count(hbl);
27953 +#define msg "unexpectedly unblanced or too many pseudo-links"
27954 + if (cnt > AUFS_PLINK_WARN)
27955 + AuWarn1(msg ", %d\n", cnt);
27957 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
27958 + if (unlikely(err)) {
27959 + pr_warn("err %d, damaged pseudo link.\n", err);
27960 + au_hbl_del(&icntnr->plink, hbl);
27961 + iput(&icntnr->vfs_inode);
27964 + iput(&icntnr->vfs_inode);
27967 +/* free all plinks */
27968 +void au_plink_put(struct super_block *sb, int verbose)
27971 + struct au_sbinfo *sbinfo;
27972 + struct hlist_bl_head *hbl;
27973 + struct hlist_bl_node *pos, *tmp;
27974 + struct au_icntnr *icntnr;
27976 + SiMustWriteLock(sb);
27978 + sbinfo = au_sbi(sb);
27979 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27980 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27982 + /* no spin_lock since sbinfo is write-locked */
27984 + for (i = 0; i < AuPlink_NHASH; i++) {
27985 + hbl = sbinfo->si_plink + i;
27986 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
27987 + pr_warn("pseudo-link is not flushed");
27990 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
27991 + iput(&icntnr->vfs_inode);
27992 + INIT_HLIST_BL_HEAD(hbl);
27996 +void au_plink_clean(struct super_block *sb, int verbose)
27998 + struct dentry *root;
28000 + root = sb->s_root;
28001 + aufs_write_lock(root);
28002 + if (au_opt_test(au_mntflags(sb), PLINK))
28003 + au_plink_put(sb, verbose);
28004 + aufs_write_unlock(root);
28007 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28010 + aufs_bindex_t btop, bbot, bindex;
28013 + btop = au_ibtop(inode);
28014 + bbot = au_ibbot(inode);
28016 + for (bindex = btop; bindex <= bbot; bindex++) {
28017 + if (!au_h_iptr(inode, bindex)
28018 + || au_ii_br_id(inode, bindex) != br_id)
28020 + au_set_h_iptr(inode, bindex, NULL, 0);
28025 + for (bindex = btop; bindex <= bbot; bindex++)
28026 + if (au_h_iptr(inode, bindex)) {
28036 +/* free the plinks on a branch specified by @br_id */
28037 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28039 + struct au_sbinfo *sbinfo;
28040 + struct hlist_bl_head *hbl;
28041 + struct hlist_bl_node *pos, *tmp;
28042 + struct au_icntnr *icntnr;
28043 + struct inode *inode;
28046 + SiMustWriteLock(sb);
28048 + sbinfo = au_sbi(sb);
28049 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28050 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28052 + /* no bit_lock since sbinfo is write-locked */
28053 + for (i = 0; i < AuPlink_NHASH; i++) {
28054 + hbl = sbinfo->si_plink + i;
28055 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28056 + inode = au_igrab(&icntnr->vfs_inode);
28057 + ii_write_lock_child(inode);
28058 + do_put = au_plink_do_half_refresh(inode, br_id);
28060 + hlist_bl_del(&icntnr->plink);
28063 + ii_write_unlock(inode);
28068 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28069 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28070 +++ linux/fs/aufs/poll.c 2018-08-12 23:43:05.460124736 +0200
28072 +// SPDX-License-Identifier: GPL-2.0
28074 + * Copyright (C) 2005-2018 Junjiro R. Okajima
28076 + * This program, aufs is free software; you can redistribute it and/or modify
28077 + * it under the terms of the GNU General Public License as published by
28078 + * the Free Software Foundation; either version 2 of the License, or
28079 + * (at your option) any later version.
28081 + * This program is distributed in the hope that it will be useful,
28082 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28083 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28084 + * GNU General Public License for more details.
28086 + * You should have received a copy of the GNU General Public License
28087 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28092 + * There is only one filesystem which implements ->poll operation, currently.
28097 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28100 + struct file *h_file;
28101 + struct super_block *sb;
28103 + /* We should pretend an error happened. */
28104 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28105 + sb = file->f_path.dentry->d_sb;
28106 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28108 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28109 + if (IS_ERR(h_file)) {
28110 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28114 + mask = vfs_poll(h_file, pt);
28115 + fput(h_file); /* instead of au_read_post() */
28118 + si_read_unlock(sb);
28119 + if (mask & EPOLLERR)
28120 + AuDbg("mask 0x%x\n", mask);
28123 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28124 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28125 +++ linux/fs/aufs/posix_acl.c 2018-08-12 23:43:05.460124736 +0200
28127 +// SPDX-License-Identifier: GPL-2.0
28129 + * Copyright (C) 2014-2018 Junjiro R. Okajima
28131 + * This program, aufs is free software; you can redistribute it and/or modify
28132 + * it under the terms of the GNU General Public License as published by
28133 + * the Free Software Foundation; either version 2 of the License, or
28134 + * (at your option) any later version.
28136 + * This program is distributed in the hope that it will be useful,
28137 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28138 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28139 + * GNU General Public License for more details.
28141 + * You should have received a copy of the GNU General Public License
28142 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28146 + * posix acl operations
28149 +#include <linux/fs.h>
28152 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28154 + struct posix_acl *acl;
28156 + aufs_bindex_t bindex;
28157 + struct inode *h_inode;
28158 + struct super_block *sb;
28161 + sb = inode->i_sb;
28162 + si_read_lock(sb, AuLock_FLUSH);
28163 + ii_read_lock_child(inode);
28164 + if (!(sb->s_flags & SB_POSIXACL))
28167 + bindex = au_ibtop(inode);
28168 + h_inode = au_h_iptr(inode, bindex);
28169 + if (unlikely(!h_inode
28170 + || ((h_inode->i_mode & S_IFMT)
28171 + != (inode->i_mode & S_IFMT)))) {
28172 + err = au_busy_or_stale();
28173 + acl = ERR_PTR(err);
28177 + /* always topmost only */
28178 + acl = get_acl(h_inode, type);
28179 + if (!IS_ERR_OR_NULL(acl))
28180 + set_cached_acl(inode, type, acl);
28183 + ii_read_unlock(inode);
28184 + si_read_unlock(sb);
28186 + AuTraceErrPtr(acl);
28190 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28194 + struct dentry *dentry;
28195 + struct au_sxattr arg = {
28196 + .type = AU_ACL_SET,
28203 + IMustLock(inode);
28205 + if (inode->i_ino == AUFS_ROOT_INO)
28206 + dentry = dget(inode->i_sb->s_root);
28208 + dentry = d_find_alias(inode);
28210 + dentry = d_find_any_alias(inode);
28212 + pr_warn("cannot handle this inode, "
28213 + "please report to aufs-users ML\n");
28219 + ssz = au_sxattr(dentry, inode, &arg);
28224 + set_cached_acl(inode, type, acl);
28230 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28231 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28232 +++ linux/fs/aufs/procfs.c 2018-08-12 23:43:05.460124736 +0200
28234 +// SPDX-License-Identifier: GPL-2.0
28236 + * Copyright (C) 2010-2018 Junjiro R. Okajima
28238 + * This program, aufs is free software; you can redistribute it and/or modify
28239 + * it under the terms of the GNU General Public License as published by
28240 + * the Free Software Foundation; either version 2 of the License, or
28241 + * (at your option) any later version.
28243 + * This program is distributed in the hope that it will be useful,
28244 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28245 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28246 + * GNU General Public License for more details.
28248 + * You should have received a copy of the GNU General Public License
28249 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28253 + * procfs interfaces
28256 +#include <linux/proc_fs.h>
28259 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28261 + struct au_sbinfo *sbinfo;
28263 + sbinfo = file->private_data;
28265 + au_plink_maint_leave(sbinfo);
28266 + kobject_put(&sbinfo->si_kobj);
28272 +static void au_procfs_plm_write_clean(struct file *file)
28274 + struct au_sbinfo *sbinfo;
28276 + sbinfo = file->private_data;
28278 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28281 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28284 + struct super_block *sb;
28285 + struct au_sbinfo *sbinfo;
28286 + struct hlist_bl_node *pos;
28289 + if (unlikely(file->private_data))
28293 + /* don't use au_sbilist_lock() here */
28294 + hlist_bl_lock(&au_sbilist);
28295 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28296 + if (id == sysaufs_si_id(sbinfo)) {
28297 + kobject_get(&sbinfo->si_kobj);
28298 + sb = sbinfo->si_sb;
28301 + hlist_bl_unlock(&au_sbilist);
28304 + if (unlikely(!sb))
28307 + err = au_plink_maint_enter(sb);
28309 + /* keep kobject_get() */
28310 + file->private_data = sbinfo;
28312 + kobject_put(&sbinfo->si_kobj);
28318 + * Accept a valid "si=xxxx" only.
28319 + * Once it is accepted successfully, accept "clean" too.
28321 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28322 + size_t count, loff_t *ppos)
28325 + unsigned long id;
28326 + /* last newline is allowed */
28327 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28330 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28334 + if (unlikely(count > sizeof(buf)))
28337 + err = copy_from_user(buf, ubuf, count);
28338 + if (unlikely(err)) {
28345 + if (!strcmp("clean", buf)) {
28346 + au_procfs_plm_write_clean(file);
28347 + goto out_success;
28348 + } else if (unlikely(strncmp("si=", buf, 3)))
28351 + err = kstrtoul(buf + 3, 16, &id);
28352 + if (unlikely(err))
28355 + err = au_procfs_plm_write_si(file, id);
28356 + if (unlikely(err))
28360 + err = count; /* success */
28365 +static const struct file_operations au_procfs_plm_fop = {
28366 + .write = au_procfs_plm_write,
28367 + .release = au_procfs_plm_release,
28368 + .owner = THIS_MODULE
28371 +/* ---------------------------------------------------------------------- */
28373 +static struct proc_dir_entry *au_procfs_dir;
28375 +void au_procfs_fin(void)
28377 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28378 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28381 +int __init au_procfs_init(void)
28384 + struct proc_dir_entry *entry;
28387 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28388 + if (unlikely(!au_procfs_dir))
28391 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28392 + au_procfs_dir, &au_procfs_plm_fop);
28393 + if (unlikely(!entry))
28397 + goto out; /* success */
28401 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28405 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28406 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28407 +++ linux/fs/aufs/rdu.c 2018-08-12 23:43:05.463458173 +0200
28409 +// SPDX-License-Identifier: GPL-2.0
28411 + * Copyright (C) 2005-2018 Junjiro R. Okajima
28413 + * This program, aufs is free software; you can redistribute it and/or modify
28414 + * it under the terms of the GNU General Public License as published by
28415 + * the Free Software Foundation; either version 2 of the License, or
28416 + * (at your option) any later version.
28418 + * This program is distributed in the hope that it will be useful,
28419 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28420 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28421 + * GNU General Public License for more details.
28423 + * You should have received a copy of the GNU General Public License
28424 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28428 + * readdir in userspace.
28431 +#include <linux/compat.h>
28432 +#include <linux/fs_stack.h>
28433 +#include <linux/security.h>
28436 +/* bits for struct aufs_rdu.flags */
28437 +#define AuRdu_CALLED 1
28438 +#define AuRdu_CONT (1 << 1)
28439 +#define AuRdu_FULL (1 << 2)
28440 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28441 +#define au_fset_rdu(flags, name) \
28442 + do { (flags) |= AuRdu_##name; } while (0)
28443 +#define au_fclr_rdu(flags, name) \
28444 + do { (flags) &= ~AuRdu_##name; } while (0)
28446 +struct au_rdu_arg {
28447 + struct dir_context ctx;
28448 + struct aufs_rdu *rdu;
28449 + union au_rdu_ent_ul ent;
28450 + unsigned long end;
28452 + struct super_block *sb;
28456 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28457 + loff_t offset, u64 h_ino, unsigned int d_type)
28460 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28461 + struct aufs_rdu *rdu = arg->rdu;
28462 + struct au_rdu_ent ent;
28466 + au_fset_rdu(rdu->cookie.flags, CALLED);
28467 + len = au_rdu_len(nlen);
28468 + if (arg->ent.ul + len < arg->end) {
28470 + ent.bindex = rdu->cookie.bindex;
28471 + ent.type = d_type;
28473 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28474 + ent.type = DT_UNKNOWN;
28476 + /* unnecessary to support mmap_sem since this is a dir */
28478 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28480 + if (copy_to_user(arg->ent.e->name, name, nlen))
28482 + /* the terminating NULL */
28483 + if (__put_user(0, arg->ent.e->name + nlen))
28486 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28487 + arg->ent.ul += len;
28491 + au_fset_rdu(rdu->cookie.flags, FULL);
28493 + rdu->tail = arg->ent;
28497 + /* AuTraceErr(err); */
28501 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28505 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28507 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28508 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28510 + if (unlikely(offset != cookie->h_pos))
28516 + au_fclr_rdu(cookie->flags, CALLED);
28518 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28522 + && au_ftest_rdu(cookie->flags, CALLED)
28523 + && !au_ftest_rdu(cookie->flags, FULL));
28524 + cookie->h_pos = h_file->f_pos;
28531 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28534 + aufs_bindex_t bbot;
28535 + struct au_rdu_arg arg = {
28537 + .actor = au_rdu_fill
28540 + struct dentry *dentry;
28541 + struct inode *inode;
28542 + struct file *h_file;
28543 + struct au_rdu_cookie *cookie = &rdu->cookie;
28545 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
28546 + if (unlikely(err)) {
28552 + rdu->tail = rdu->ent;
28555 + arg.ent = rdu->ent;
28556 + arg.end = arg.ent.ul;
28557 + arg.end += rdu->sz;
28560 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28563 + err = security_file_permission(file, MAY_READ);
28565 + if (unlikely(err))
28568 + dentry = file->f_path.dentry;
28569 + inode = d_inode(dentry);
28570 + inode_lock_shared(inode);
28572 + arg.sb = inode->i_sb;
28573 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28574 + if (unlikely(err))
28576 + err = au_alive_dir(dentry);
28577 + if (unlikely(err))
28579 + /* todo: reval? */
28580 + fi_read_lock(file);
28583 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28584 + && cookie->generation != au_figen(file)))
28589 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28591 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28593 + bbot = au_fbtop(file);
28594 + if (cookie->bindex < bbot)
28595 + cookie->bindex = bbot;
28596 + bbot = au_fbbot_dir(file);
28597 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28598 + for (; !err && cookie->bindex <= bbot;
28599 + cookie->bindex++, cookie->h_pos = 0) {
28600 + h_file = au_hf_dir(file, cookie->bindex);
28604 + au_fclr_rdu(cookie->flags, FULL);
28605 + err = au_rdu_do(h_file, &arg);
28607 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28610 + AuDbg("rent %llu\n", rdu->rent);
28612 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28613 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28614 + au_fset_rdu(cookie->flags, CONT);
28615 + cookie->generation = au_figen(file);
28618 + ii_read_lock_child(inode);
28619 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28620 + ii_read_unlock(inode);
28623 + fi_read_unlock(file);
28625 + si_read_unlock(arg.sb);
28627 + inode_unlock_shared(inode);
28633 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28637 + unsigned long long nent;
28638 + union au_rdu_ent_ul *u;
28639 + struct au_rdu_ent ent;
28640 + struct super_block *sb;
28643 + nent = rdu->nent;
28645 + sb = file->f_path.dentry->d_sb;
28646 + si_read_lock(sb, AuLock_FLUSH);
28647 + while (nent-- > 0) {
28648 + /* unnecessary to support mmap_sem since this is a dir */
28649 + err = copy_from_user(&ent, u->e, sizeof(ent));
28651 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
28652 + if (unlikely(err)) {
28658 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28660 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28662 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28664 + if (unlikely(err)) {
28669 + err = __put_user(ino, &u->e->ino);
28670 + if (unlikely(err)) {
28675 + u->ul += au_rdu_len(ent.nlen);
28677 + si_read_unlock(sb);
28682 +/* ---------------------------------------------------------------------- */
28684 +static int au_rdu_verify(struct aufs_rdu *rdu)
28686 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28687 + "%llu, b%d, 0x%x, g%u}\n",
28688 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28690 + rdu->rent, rdu->shwh, rdu->full,
28691 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28692 + rdu->cookie.generation);
28694 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28698 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28702 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28705 + struct aufs_rdu rdu;
28706 + void __user *p = (void __user *)arg;
28708 + err = copy_from_user(&rdu, p, sizeof(rdu));
28709 + if (unlikely(err)) {
28714 + err = au_rdu_verify(&rdu);
28715 + if (unlikely(err))
28719 + case AUFS_CTL_RDU:
28720 + err = au_rdu(file, &rdu);
28721 + if (unlikely(err))
28724 + e = copy_to_user(p, &rdu, sizeof(rdu));
28725 + if (unlikely(e)) {
28730 + case AUFS_CTL_RDU_INO:
28731 + err = au_rdu_ino(file, &rdu);
28735 + /* err = -ENOTTY; */
28744 +#ifdef CONFIG_COMPAT
28745 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28748 + struct aufs_rdu rdu;
28749 + void __user *p = compat_ptr(arg);
28751 + /* todo: get_user()? */
28752 + err = copy_from_user(&rdu, p, sizeof(rdu));
28753 + if (unlikely(err)) {
28758 + rdu.ent.e = compat_ptr(rdu.ent.ul);
28759 + err = au_rdu_verify(&rdu);
28760 + if (unlikely(err))
28764 + case AUFS_CTL_RDU:
28765 + err = au_rdu(file, &rdu);
28766 + if (unlikely(err))
28769 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
28770 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
28771 + e = copy_to_user(p, &rdu, sizeof(rdu));
28772 + if (unlikely(e)) {
28777 + case AUFS_CTL_RDU_INO:
28778 + err = au_rdu_ino(file, &rdu);
28782 + /* err = -ENOTTY; */
28791 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
28792 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
28793 +++ linux/fs/aufs/rwsem.h 2018-08-12 23:43:05.463458173 +0200
28795 +/* SPDX-License-Identifier: GPL-2.0 */
28797 + * Copyright (C) 2005-2018 Junjiro R. Okajima
28799 + * This program, aufs is free software; you can redistribute it and/or modify
28800 + * it under the terms of the GNU General Public License as published by
28801 + * the Free Software Foundation; either version 2 of the License, or
28802 + * (at your option) any later version.
28804 + * This program is distributed in the hope that it will be useful,
28805 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28806 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28807 + * GNU General Public License for more details.
28809 + * You should have received a copy of the GNU General Public License
28810 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28814 + * simple read-write semaphore wrappers
28817 +#ifndef __AUFS_RWSEM_H__
28818 +#define __AUFS_RWSEM_H__
28822 +#include "debug.h"
28824 +/* in the futre, the name 'au_rwsem' will be totally gone */
28825 +#define au_rwsem rw_semaphore
28827 +/* to debug easier, do not make them inlined functions */
28828 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
28829 +/* rwsem_is_locked() is unusable */
28830 +#define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \
28832 + && !lockdep_is_held_type(rw, 1))
28833 +#define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \
28835 + && !lockdep_is_held_type(rw, 0))
28836 +#define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \
28838 + && !lockdep_is_held(rw))
28839 +#define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \
28841 + && lockdep_is_held(rw))
28843 +#define au_rw_init(rw) init_rwsem(rw)
28845 +#define au_rw_init_wlock(rw) do { \
28846 + au_rw_init(rw); \
28847 + down_write(rw); \
28850 +#define au_rw_init_wlock_nested(rw, lsc) do { \
28851 + au_rw_init(rw); \
28852 + down_write_nested(rw, lsc); \
28855 +#define au_rw_read_lock(rw) down_read(rw)
28856 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
28857 +#define au_rw_read_unlock(rw) up_read(rw)
28858 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
28859 +#define au_rw_write_lock(rw) down_write(rw)
28860 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
28861 +#define au_rw_write_unlock(rw) up_write(rw)
28862 +/* why is not _nested version defined? */
28863 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
28864 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
28866 +#endif /* __KERNEL__ */
28867 +#endif /* __AUFS_RWSEM_H__ */
28868 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
28869 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
28870 +++ linux/fs/aufs/sbinfo.c 2018-08-12 23:43:05.463458173 +0200
28872 +// SPDX-License-Identifier: GPL-2.0
28874 + * Copyright (C) 2005-2018 Junjiro R. Okajima
28876 + * This program, aufs is free software; you can redistribute it and/or modify
28877 + * it under the terms of the GNU General Public License as published by
28878 + * the Free Software Foundation; either version 2 of the License, or
28879 + * (at your option) any later version.
28881 + * This program is distributed in the hope that it will be useful,
28882 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28883 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28884 + * GNU General Public License for more details.
28886 + * You should have received a copy of the GNU General Public License
28887 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28891 + * superblock private data
28897 + * they are necessary regardless sysfs is disabled.
28899 +void au_si_free(struct kobject *kobj)
28902 + struct au_sbinfo *sbinfo;
28903 + char *locked __maybe_unused; /* debug only */
28905 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
28906 + for (i = 0; i < AuPlink_NHASH; i++)
28907 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
28908 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
28910 + AuDebugOn(percpu_counter_sum(&sbinfo->si_ninodes));
28911 + percpu_counter_destroy(&sbinfo->si_ninodes);
28912 + AuDebugOn(percpu_counter_sum(&sbinfo->si_nfiles));
28913 + percpu_counter_destroy(&sbinfo->si_nfiles);
28915 + dbgaufs_si_fin(sbinfo);
28916 + au_rw_write_lock(&sbinfo->si_rwsem);
28917 + au_br_free(sbinfo);
28918 + au_rw_write_unlock(&sbinfo->si_rwsem);
28920 + kfree(sbinfo->si_branch);
28921 + mutex_destroy(&sbinfo->si_xib_mtx);
28922 + AuRwDestroy(&sbinfo->si_rwsem);
28927 +int au_si_alloc(struct super_block *sb)
28930 + struct au_sbinfo *sbinfo;
28933 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
28934 + if (unlikely(!sbinfo))
28937 + /* will be reallocated separately */
28938 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
28939 + if (unlikely(!sbinfo->si_branch))
28942 + err = sysaufs_si_init(sbinfo);
28944 + dbgaufs_si_null(sbinfo);
28945 + err = dbgaufs_si_init(sbinfo);
28946 + if (unlikely(err))
28947 + kobject_put(&sbinfo->si_kobj);
28949 + if (unlikely(err))
28952 + au_nwt_init(&sbinfo->si_nowait);
28953 + au_rw_init_wlock(&sbinfo->si_rwsem);
28955 + percpu_counter_init(&sbinfo->si_ninodes, 0, GFP_NOFS);
28956 + percpu_counter_init(&sbinfo->si_nfiles, 0, GFP_NOFS);
28958 + sbinfo->si_bbot = -1;
28959 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
28961 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
28962 + sbinfo->si_wbr_create = AuWbrCreate_Def;
28963 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
28964 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
28966 + au_fhsm_init(sbinfo);
28968 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
28970 + sbinfo->si_xino_jiffy = jiffies;
28971 + sbinfo->si_xino_expire
28972 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
28973 + mutex_init(&sbinfo->si_xib_mtx);
28974 + sbinfo->si_xino_brid = -1;
28975 + /* leave si_xib_last_pindex and si_xib_next_bit */
28977 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
28979 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
28980 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
28981 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
28982 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
28984 + for (i = 0; i < AuPlink_NHASH; i++)
28985 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
28986 + init_waitqueue_head(&sbinfo->si_plink_wq);
28987 + spin_lock_init(&sbinfo->si_plink_maint_lock);
28989 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
28991 + /* with getattr by default */
28992 + sbinfo->si_iop_array = aufs_iop;
28994 + /* leave other members for sysaufs and si_mnt. */
28995 + sbinfo->si_sb = sb;
28996 + sb->s_fs_info = sbinfo;
28998 + return 0; /* success */
29001 + kfree(sbinfo->si_branch);
29008 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29011 + struct au_branch **brp;
29013 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29016 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29017 + if (unlikely(!sz))
29018 + sz = sizeof(*brp);
29019 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29022 + sbinfo->si_branch = brp;
29029 +/* ---------------------------------------------------------------------- */
29031 +unsigned int au_sigen_inc(struct super_block *sb)
29033 + unsigned int gen;
29034 + struct inode *inode;
29036 + SiMustWriteLock(sb);
29038 + gen = ++au_sbi(sb)->si_generation;
29039 + au_update_digen(sb->s_root);
29040 + inode = d_inode(sb->s_root);
29041 + au_update_iigen(inode, /*half*/0);
29042 + inode_inc_iversion(inode);
29046 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29048 + aufs_bindex_t br_id;
29050 + struct au_sbinfo *sbinfo;
29052 + SiMustWriteLock(sb);
29054 + sbinfo = au_sbi(sb);
29055 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29056 + br_id = ++sbinfo->si_last_br_id;
29057 + AuDebugOn(br_id < 0);
29058 + if (br_id && au_br_index(sb, br_id) < 0)
29065 +/* ---------------------------------------------------------------------- */
29067 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29068 +int si_read_lock(struct super_block *sb, int flags)
29073 + if (au_ftest_lock(flags, FLUSH))
29074 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29076 + si_noflush_read_lock(sb);
29077 + err = au_plink_maint(sb, flags);
29078 + if (unlikely(err))
29079 + si_read_unlock(sb);
29084 +int si_write_lock(struct super_block *sb, int flags)
29088 + if (au_ftest_lock(flags, FLUSH))
29089 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29091 + si_noflush_write_lock(sb);
29092 + err = au_plink_maint(sb, flags);
29093 + if (unlikely(err))
29094 + si_write_unlock(sb);
29099 +/* dentry and super_block lock. call at entry point */
29100 +int aufs_read_lock(struct dentry *dentry, int flags)
29103 + struct super_block *sb;
29105 + sb = dentry->d_sb;
29106 + err = si_read_lock(sb, flags);
29107 + if (unlikely(err))
29110 + if (au_ftest_lock(flags, DW))
29111 + di_write_lock_child(dentry);
29113 + di_read_lock_child(dentry, flags);
29115 + if (au_ftest_lock(flags, GEN)) {
29116 + err = au_digen_test(dentry, au_sigen(sb));
29117 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29118 + AuDebugOn(!err && au_dbrange_test(dentry));
29120 + err = au_dbrange_test(dentry);
29121 + if (unlikely(err))
29122 + aufs_read_unlock(dentry, flags);
29129 +void aufs_read_unlock(struct dentry *dentry, int flags)
29131 + if (au_ftest_lock(flags, DW))
29132 + di_write_unlock(dentry);
29134 + di_read_unlock(dentry, flags);
29135 + si_read_unlock(dentry->d_sb);
29138 +void aufs_write_lock(struct dentry *dentry)
29140 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29141 + di_write_lock_child(dentry);
29144 +void aufs_write_unlock(struct dentry *dentry)
29146 + di_write_unlock(dentry);
29147 + si_write_unlock(dentry->d_sb);
29150 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29153 + unsigned int sigen;
29154 + struct super_block *sb;
29157 + err = si_read_lock(sb, flags);
29158 + if (unlikely(err))
29161 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29163 + if (au_ftest_lock(flags, GEN)) {
29164 + sigen = au_sigen(sb);
29165 + err = au_digen_test(d1, sigen);
29166 + AuDebugOn(!err && au_dbrange_test(d1));
29168 + err = au_digen_test(d2, sigen);
29169 + AuDebugOn(!err && au_dbrange_test(d2));
29171 + if (unlikely(err))
29172 + aufs_read_and_write_unlock2(d1, d2);
29179 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29181 + di_write_unlock2(d1, d2);
29182 + si_read_unlock(d1->d_sb);
29184 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29185 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29186 +++ linux/fs/aufs/super.c 2018-08-12 23:43:05.463458173 +0200
29188 +// SPDX-License-Identifier: GPL-2.0
29190 + * Copyright (C) 2005-2018 Junjiro R. Okajima
29192 + * This program, aufs is free software; you can redistribute it and/or modify
29193 + * it under the terms of the GNU General Public License as published by
29194 + * the Free Software Foundation; either version 2 of the License, or
29195 + * (at your option) any later version.
29197 + * This program is distributed in the hope that it will be useful,
29198 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29199 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29200 + * GNU General Public License for more details.
29202 + * You should have received a copy of the GNU General Public License
29203 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29207 + * mount and super_block operations
29210 +#include <linux/mm.h>
29211 +#include <linux/seq_file.h>
29212 +#include <linux/statfs.h>
29213 +#include <linux/vmalloc.h>
29217 + * super_operations
29219 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29221 + struct au_icntnr *c;
29223 + c = au_cache_alloc_icntnr();
29225 + au_icntnr_init(c);
29226 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29227 + c->iinfo.ii_hinode = NULL;
29228 + return &c->vfs_inode;
29233 +static void aufs_destroy_inode_cb(struct rcu_head *head)
29235 + struct inode *inode = container_of(head, struct inode, i_rcu);
29237 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29240 +static void aufs_destroy_inode(struct inode *inode)
29242 + if (!au_is_bad_inode(inode))
29243 + au_iinfo_fin(inode);
29244 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
29247 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29249 + struct inode *inode;
29252 + inode = iget_locked(sb, ino);
29253 + if (unlikely(!inode)) {
29254 + inode = ERR_PTR(-ENOMEM);
29257 + if (!(inode->i_state & I_NEW))
29260 + err = au_xigen_new(inode);
29262 + err = au_iinfo_init(inode);
29264 + inode_inc_iversion(inode);
29266 + iget_failed(inode);
29267 + inode = ERR_PTR(err);
29271 + /* never return NULL */
29272 + AuDebugOn(!inode);
29273 + AuTraceErrPtr(inode);
29277 +/* lock free root dinfo */
29278 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29281 + aufs_bindex_t bindex, bbot;
29282 + struct path path;
29283 + struct au_hdentry *hdp;
29284 + struct au_branch *br;
29285 + au_br_perm_str_t perm;
29288 + bbot = au_sbbot(sb);
29290 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29291 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29292 + br = au_sbr(sb, bindex);
29293 + path.mnt = au_br_mnt(br);
29294 + path.dentry = hdp->hd_dentry;
29295 + err = au_seq_path(seq, &path);
29297 + au_optstr_br_perm(&perm, br->br_perm);
29298 + seq_printf(seq, "=%s", perm.a);
29299 + if (bindex != bbot)
29300 + seq_putc(seq, ':');
29303 + if (unlikely(err || seq_has_overflowed(seq)))
29309 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29310 + const char *append)
29315 + while (*pat != ':')
29318 + strcpy(p, append);
29319 + AuDebugOn(strlen(fmt) >= len);
29322 +static void au_show_wbr_create(struct seq_file *m, int v,
29323 + struct au_sbinfo *sbinfo)
29327 + struct au_wbr_mfs *mfs;
29329 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29331 + seq_puts(m, ",create=");
29332 + pat = au_optstr_wbr_create(v);
29333 + mfs = &sbinfo->si_wbr_mfs;
29335 + case AuWbrCreate_TDP:
29336 + case AuWbrCreate_RR:
29337 + case AuWbrCreate_MFS:
29338 + case AuWbrCreate_PMFS:
29339 + seq_puts(m, pat);
29341 + case AuWbrCreate_MFSRR:
29342 + case AuWbrCreate_TDMFS:
29343 + case AuWbrCreate_PMFSRR:
29344 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29345 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29347 + case AuWbrCreate_MFSV:
29348 + case AuWbrCreate_PMFSV:
29349 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29350 + seq_printf(m, fmt,
29351 + jiffies_to_msecs(mfs->mfs_expire)
29354 + case AuWbrCreate_MFSRRV:
29355 + case AuWbrCreate_TDMFSV:
29356 + case AuWbrCreate_PMFSRRV:
29357 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29358 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29359 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29366 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29368 +#ifdef CONFIG_SYSFS
29372 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29373 + aufs_bindex_t bindex, brid;
29374 + struct qstr *name;
29376 + struct dentry *d, *h_root;
29378 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29381 + f = au_sbi(sb)->si_xib;
29385 + /* stop printing the default xino path on the first writable branch */
29387 + brid = au_xino_brid(sb);
29389 + bindex = au_br_index(sb, brid);
29390 + h_root = au_hdentry(au_di(sb->s_root), bindex)->hd_dentry;
29392 + d = f->f_path.dentry;
29393 + name = &d->d_name;
29394 + /* safe ->d_parent because the file is unlinked */
29395 + if (d->d_parent == h_root
29396 + && name->len == len
29397 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29400 + seq_puts(seq, ",xino=");
29401 + err = au_xino_path(seq, f);
29408 +/* seq_file will re-call me in case of too long string */
29409 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29412 + unsigned int mnt_flags, v;
29413 + struct super_block *sb;
29414 + struct au_sbinfo *sbinfo;
29416 +#define AuBool(name, str) do { \
29417 + v = au_opt_test(mnt_flags, name); \
29418 + if (v != au_opt_test(AuOpt_Def, name)) \
29419 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29422 +#define AuStr(name, str) do { \
29423 + v = mnt_flags & AuOptMask_##name; \
29424 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29425 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29428 +#define AuUInt(name, str, val) do { \
29429 + if (val != AUFS_##name##_DEF) \
29430 + seq_printf(m, "," #str "=%u", val); \
29433 + sb = dentry->d_sb;
29434 + if (sb->s_flags & SB_POSIXACL)
29435 + seq_puts(m, ",acl");
29437 + if (sb->s_flags & SB_I_VERSION)
29438 + seq_puts(m, ",i_version");
29441 + /* lock free root dinfo */
29442 + si_noflush_read_lock(sb);
29443 + sbinfo = au_sbi(sb);
29444 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29446 + mnt_flags = au_mntflags(sb);
29447 + if (au_opt_test(mnt_flags, XINO)) {
29448 + err = au_show_xino(m, sb);
29449 + if (unlikely(err))
29452 + seq_puts(m, ",noxino");
29454 + AuBool(TRUNC_XINO, trunc_xino);
29455 + AuStr(UDBA, udba);
29456 + AuBool(SHWH, shwh);
29457 + AuBool(PLINK, plink);
29458 + AuBool(DIO, dio);
29459 + AuBool(DIRPERM1, dirperm1);
29461 + v = sbinfo->si_wbr_create;
29462 + if (v != AuWbrCreate_Def)
29463 + au_show_wbr_create(m, v, sbinfo);
29465 + v = sbinfo->si_wbr_copyup;
29466 + if (v != AuWbrCopyup_Def)
29467 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29469 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29470 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29471 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29473 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29475 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29476 + AuUInt(RDCACHE, rdcache, v);
29478 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29479 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29481 + au_fhsm_show(m, sbinfo);
29483 + AuBool(DIRREN, dirren);
29484 + AuBool(SUM, sum);
29485 + /* AuBool(SUM_W, wsum); */
29486 + AuBool(WARN_PERM, warn_perm);
29487 + AuBool(VERBOSE, verbose);
29490 + /* be sure to print "br:" last */
29491 + if (!sysaufs_brs) {
29492 + seq_puts(m, ",br:");
29493 + au_show_brs(m, sb);
29495 + si_read_unlock(sb);
29503 +/* ---------------------------------------------------------------------- */
29505 +/* sum mode which returns the summation for statfs(2) */
29507 +static u64 au_add_till_max(u64 a, u64 b)
29515 + return ULLONG_MAX;
29518 +static u64 au_mul_till_max(u64 a, long mul)
29526 + return ULLONG_MAX;
29529 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29532 + long bsize, factor;
29533 + u64 blocks, bfree, bavail, files, ffree;
29534 + aufs_bindex_t bbot, bindex, i;
29535 + unsigned char shared;
29536 + struct path h_path;
29537 + struct super_block *h_sb;
29540 + bsize = LONG_MAX;
29546 + bbot = au_sbbot(sb);
29547 + for (bindex = 0; bindex <= bbot; bindex++) {
29548 + h_path.mnt = au_sbr_mnt(sb, bindex);
29549 + h_sb = h_path.mnt->mnt_sb;
29551 + for (i = 0; !shared && i < bindex; i++)
29552 + shared = (au_sbr_sb(sb, i) == h_sb);
29556 + /* sb->s_root for NFS is unreliable */
29557 + h_path.dentry = h_path.mnt->mnt_root;
29558 + err = vfs_statfs(&h_path, buf);
29559 + if (unlikely(err))
29562 + if (bsize > buf->f_bsize) {
29564 + * we will reduce bsize, so we have to expand blocks
29565 + * etc. to match them again
29567 + factor = (bsize / buf->f_bsize);
29568 + blocks = au_mul_till_max(blocks, factor);
29569 + bfree = au_mul_till_max(bfree, factor);
29570 + bavail = au_mul_till_max(bavail, factor);
29571 + bsize = buf->f_bsize;
29574 + factor = (buf->f_bsize / bsize);
29575 + blocks = au_add_till_max(blocks,
29576 + au_mul_till_max(buf->f_blocks, factor));
29577 + bfree = au_add_till_max(bfree,
29578 + au_mul_till_max(buf->f_bfree, factor));
29579 + bavail = au_add_till_max(bavail,
29580 + au_mul_till_max(buf->f_bavail, factor));
29581 + files = au_add_till_max(files, buf->f_files);
29582 + ffree = au_add_till_max(ffree, buf->f_ffree);
29585 + buf->f_bsize = bsize;
29586 + buf->f_blocks = blocks;
29587 + buf->f_bfree = bfree;
29588 + buf->f_bavail = bavail;
29589 + buf->f_files = files;
29590 + buf->f_ffree = ffree;
29591 + buf->f_frsize = 0;
29597 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29600 + struct path h_path;
29601 + struct super_block *sb;
29603 + /* lock free root dinfo */
29604 + sb = dentry->d_sb;
29605 + si_noflush_read_lock(sb);
29606 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29607 + /* sb->s_root for NFS is unreliable */
29608 + h_path.mnt = au_sbr_mnt(sb, 0);
29609 + h_path.dentry = h_path.mnt->mnt_root;
29610 + err = vfs_statfs(&h_path, buf);
29612 + err = au_statfs_sum(sb, buf);
29613 + si_read_unlock(sb);
29616 + buf->f_type = AUFS_SUPER_MAGIC;
29617 + buf->f_namelen = AUFS_MAX_NAMELEN;
29618 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29620 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29625 +/* ---------------------------------------------------------------------- */
29627 +static int aufs_sync_fs(struct super_block *sb, int wait)
29630 + aufs_bindex_t bbot, bindex;
29631 + struct au_branch *br;
29632 + struct super_block *h_sb;
29635 + si_noflush_read_lock(sb);
29636 + bbot = au_sbbot(sb);
29637 + for (bindex = 0; bindex <= bbot; bindex++) {
29638 + br = au_sbr(sb, bindex);
29639 + if (!au_br_writable(br->br_perm))
29642 + h_sb = au_sbr_sb(sb, bindex);
29643 + e = vfsub_sync_filesystem(h_sb, wait);
29644 + if (unlikely(e && !err))
29646 + /* go on even if an error happens */
29648 + si_read_unlock(sb);
29653 +/* ---------------------------------------------------------------------- */
29655 +/* final actions when unmounting a file system */
29656 +static void aufs_put_super(struct super_block *sb)
29658 + struct au_sbinfo *sbinfo;
29660 + sbinfo = au_sbi(sb);
29662 + kobject_put(&sbinfo->si_kobj);
29665 +/* ---------------------------------------------------------------------- */
29667 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29668 + struct super_block *sb, void *arg)
29671 + unsigned long long n, sz;
29678 + if (*hint > ULLONG_MAX / sizeof(array)) {
29679 + array = ERR_PTR(-EMFILE);
29680 + pr_err("hint %llu\n", *hint);
29684 + sz = sizeof(array) * *hint;
29685 + array = kzalloc(sz, GFP_NOFS);
29686 + if (unlikely(!array))
29687 + array = vzalloc(sz);
29688 + if (unlikely(!array)) {
29689 + array = ERR_PTR(-ENOMEM);
29693 + n = cb(sb, array, *hint, arg);
29694 + AuDebugOn(n > *hint);
29701 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29702 + unsigned long long max __maybe_unused,
29705 + unsigned long long n;
29706 + struct inode **p, *inode;
29707 + struct list_head *head;
29712 + spin_lock(&sb->s_inode_list_lock);
29713 + list_for_each_entry(inode, head, i_sb_list) {
29714 + if (!au_is_bad_inode(inode)
29715 + && au_ii(inode)->ii_btop >= 0) {
29716 + spin_lock(&inode->i_lock);
29717 + if (atomic_read(&inode->i_count)) {
29721 + AuDebugOn(n > max);
29723 + spin_unlock(&inode->i_lock);
29726 + spin_unlock(&sb->s_inode_list_lock);
29731 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
29733 + *max = au_ninodes(sb);
29734 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
29737 +void au_iarray_free(struct inode **a, unsigned long long max)
29739 + unsigned long long ull;
29741 + for (ull = 0; ull < max; ull++)
29746 +/* ---------------------------------------------------------------------- */
29749 + * refresh dentry and inode at remount time.
29751 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
29752 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
29753 + struct dentry *parent)
29757 + di_write_lock_child(dentry);
29758 + di_read_lock_parent(parent, AuLock_IR);
29759 + err = au_refresh_dentry(dentry, parent);
29760 + if (!err && dir_flags)
29761 + au_hn_reset(d_inode(dentry), dir_flags);
29762 + di_read_unlock(parent, AuLock_IR);
29763 + di_write_unlock(dentry);
29768 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
29769 + struct au_sbinfo *sbinfo,
29770 + const unsigned int dir_flags, unsigned int do_idop)
29773 + struct dentry *parent;
29776 + parent = dget_parent(dentry);
29777 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
29778 + if (d_really_is_positive(dentry)) {
29779 + if (!d_is_dir(dentry))
29780 + err = au_do_refresh(dentry, /*dir_flags*/0,
29783 + err = au_do_refresh(dentry, dir_flags, parent);
29784 + if (unlikely(err))
29785 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
29788 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
29789 + AuDbgDentry(dentry);
29795 + au_refresh_dop(dentry, /*force_reval*/0);
29797 + au_refresh_dop(dentry, /*force_reval*/1);
29803 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
29805 + int err, i, j, ndentry, e;
29806 + unsigned int sigen;
29807 + struct au_dcsub_pages dpages;
29808 + struct au_dpage *dpage;
29809 + struct dentry **dentries, *d;
29810 + struct au_sbinfo *sbinfo;
29811 + struct dentry *root = sb->s_root;
29812 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
29815 + au_refresh_dop(root, /*force_reval*/0);
29817 + err = au_dpages_init(&dpages, GFP_NOFS);
29818 + if (unlikely(err))
29820 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
29821 + if (unlikely(err))
29824 + sigen = au_sigen(sb);
29825 + sbinfo = au_sbi(sb);
29826 + for (i = 0; i < dpages.ndpage; i++) {
29827 + dpage = dpages.dpages + i;
29828 + dentries = dpage->dentries;
29829 + ndentry = dpage->ndentry;
29830 + for (j = 0; j < ndentry; j++) {
29832 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
29834 + if (unlikely(e && !err))
29836 + /* go on even err */
29841 + au_dpages_free(&dpages);
29846 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
29849 + unsigned int sigen;
29850 + unsigned long long max, ull;
29851 + struct inode *inode, **array;
29853 + array = au_iarray_alloc(sb, &max);
29854 + err = PTR_ERR(array);
29855 + if (IS_ERR(array))
29859 + sigen = au_sigen(sb);
29860 + for (ull = 0; ull < max; ull++) {
29861 + inode = array[ull];
29862 + if (unlikely(!inode))
29866 + ii_write_lock_child(inode);
29867 + if (au_iigen(inode, NULL) != sigen) {
29868 + e = au_refresh_hinode_self(inode);
29869 + if (unlikely(e)) {
29870 + au_refresh_iop(inode, /*force_getattr*/1);
29871 + pr_err("error %d, i%lu\n", e, inode->i_ino);
29874 + /* go on even if err */
29877 + if (!e && do_idop)
29878 + au_refresh_iop(inode, /*force_getattr*/0);
29879 + ii_write_unlock(inode);
29882 + au_iarray_free(array, max);
29888 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
29891 + unsigned int udba;
29892 + aufs_bindex_t bindex, bbot;
29893 + struct dentry *root;
29894 + struct inode *inode;
29895 + struct au_branch *br;
29896 + struct au_sbinfo *sbi;
29898 + au_sigen_inc(sb);
29899 + sbi = au_sbi(sb);
29900 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
29902 + root = sb->s_root;
29903 + DiMustNoWaiters(root);
29904 + inode = d_inode(root);
29905 + IiMustNoWaiters(inode);
29907 + udba = au_opt_udba(sb);
29908 + bbot = au_sbbot(sb);
29909 + for (bindex = 0; bindex <= bbot; bindex++) {
29910 + br = au_sbr(sb, bindex);
29911 + err = au_hnotify_reset_br(udba, br, br->br_perm);
29912 + if (unlikely(err))
29913 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
29915 + /* go on even if err */
29917 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
29920 + if (au_ftest_si(sbi, NO_DREVAL)) {
29921 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
29922 + sb->s_d_op = &aufs_dop_noreval;
29923 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
29924 + sbi->si_iop_array = aufs_iop_nogetattr;
29926 + AuDebugOn(sb->s_d_op == &aufs_dop);
29927 + sb->s_d_op = &aufs_dop;
29928 + AuDebugOn(sbi->si_iop_array == aufs_iop);
29929 + sbi->si_iop_array = aufs_iop;
29931 + pr_info("reset to %ps and %ps\n",
29932 + sb->s_d_op, sbi->si_iop_array);
29935 + di_write_unlock(root);
29936 + err = au_refresh_d(sb, do_idop);
29937 + e = au_refresh_i(sb, do_idop);
29938 + if (unlikely(e && !err))
29940 + /* aufs_write_lock() calls ..._child() */
29941 + di_write_lock_child(root);
29943 + au_cpup_attr_all(inode, /*force*/1);
29945 + if (unlikely(err))
29946 + AuIOErr("refresh failed, ignored, %d\n", err);
29949 +/* stop extra interpretation of errno in mount(8), and strange error messages */
29950 +static int cvt_err(int err)
29964 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
29967 + unsigned int mntflags;
29968 + struct au_opts opts = {
29971 + struct dentry *root;
29972 + struct inode *inode;
29973 + struct au_sbinfo *sbinfo;
29976 + root = sb->s_root;
29977 + if (!data || !*data) {
29978 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
29980 + di_write_lock_child(root);
29981 + err = au_opts_verify(sb, *flags, /*pending*/0);
29982 + aufs_write_unlock(root);
29988 + opts.opt = (void *)__get_free_page(GFP_NOFS);
29989 + if (unlikely(!opts.opt))
29991 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
29992 + opts.flags = AuOpts_REMOUNT;
29993 + opts.sb_flags = *flags;
29995 + /* parse it before aufs lock */
29996 + err = au_opts_parse(sb, data, &opts);
29997 + if (unlikely(err))
30000 + sbinfo = au_sbi(sb);
30001 + inode = d_inode(root);
30002 + inode_lock(inode);
30003 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30004 + if (unlikely(err))
30006 + di_write_lock_child(root);
30008 + /* au_opts_remount() may return an error */
30009 + err = au_opts_remount(sb, &opts);
30010 + au_opts_free(&opts);
30012 + if (au_ftest_opts(opts.flags, REFRESH))
30013 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30015 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30016 + mntflags = au_mntflags(sb);
30017 + do_dx = !!au_opt_test(mntflags, DIO);
30018 + au_dy_arefresh(do_dx);
30021 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30022 + aufs_write_unlock(root);
30025 + inode_unlock(inode);
30027 + free_page((unsigned long)opts.opt);
30029 + err = cvt_err(err);
30034 +static const struct super_operations aufs_sop = {
30035 + .alloc_inode = aufs_alloc_inode,
30036 + .destroy_inode = aufs_destroy_inode,
30037 + /* always deleting, no clearing */
30038 + .drop_inode = generic_delete_inode,
30039 + .show_options = aufs_show_options,
30040 + .statfs = aufs_statfs,
30041 + .put_super = aufs_put_super,
30042 + .sync_fs = aufs_sync_fs,
30043 + .remount_fs = aufs_remount_fs
30046 +/* ---------------------------------------------------------------------- */
30048 +static int alloc_root(struct super_block *sb)
30051 + struct inode *inode;
30052 + struct dentry *root;
30055 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30056 + err = PTR_ERR(inode);
30057 + if (IS_ERR(inode))
30060 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30061 + inode->i_fop = &aufs_dir_fop;
30062 + inode->i_mode = S_IFDIR;
30063 + set_nlink(inode, 2);
30064 + unlock_new_inode(inode);
30066 + root = d_make_root(inode);
30067 + if (unlikely(!root))
30069 + err = PTR_ERR(root);
30070 + if (IS_ERR(root))
30073 + err = au_di_init(root);
30075 + sb->s_root = root;
30076 + return 0; /* success */
30084 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30085 + int silent __maybe_unused)
30088 + struct au_opts opts = {
30091 + struct au_sbinfo *sbinfo;
30092 + struct dentry *root;
30093 + struct inode *inode;
30094 + char *arg = raw_data;
30096 + if (unlikely(!arg || !*arg)) {
30098 + pr_err("no arg\n");
30103 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30104 + if (unlikely(!opts.opt))
30106 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30107 + opts.sb_flags = sb->s_flags;
30109 + err = au_si_alloc(sb);
30110 + if (unlikely(err))
30112 + sbinfo = au_sbi(sb);
30114 + /* all timestamps always follow the ones on the branch */
30115 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30116 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30117 + sb->s_op = &aufs_sop;
30118 + sb->s_d_op = &aufs_dop;
30119 + sb->s_magic = AUFS_SUPER_MAGIC;
30120 + sb->s_maxbytes = 0;
30121 + sb->s_stack_depth = 1;
30122 + au_export_init(sb);
30123 + au_xattr_init(sb);
30125 + err = alloc_root(sb);
30126 + if (unlikely(err)) {
30127 + si_write_unlock(sb);
30130 + root = sb->s_root;
30131 + inode = d_inode(root);
30134 + * actually we can parse options regardless aufs lock here.
30135 + * but at remount time, parsing must be done before aufs lock.
30136 + * so we follow the same rule.
30138 + ii_write_lock_parent(inode);
30139 + aufs_write_unlock(root);
30140 + err = au_opts_parse(sb, arg, &opts);
30141 + if (unlikely(err))
30144 + /* lock vfs_inode first, then aufs. */
30145 + inode_lock(inode);
30146 + aufs_write_lock(root);
30147 + err = au_opts_mount(sb, &opts);
30148 + au_opts_free(&opts);
30149 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30150 + sb->s_d_op = &aufs_dop_noreval;
30151 + pr_info("%ps\n", sb->s_d_op);
30152 + au_refresh_dop(root, /*force_reval*/0);
30153 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30154 + au_refresh_iop(inode, /*force_getattr*/0);
30156 + aufs_write_unlock(root);
30157 + inode_unlock(inode);
30159 + goto out_opts; /* success */
30163 + sb->s_root = NULL;
30165 + kobject_put(&sbinfo->si_kobj);
30166 + sb->s_fs_info = NULL;
30168 + free_page((unsigned long)opts.opt);
30171 + err = cvt_err(err);
30176 +/* ---------------------------------------------------------------------- */
30178 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30179 + const char *dev_name __maybe_unused,
30182 + struct dentry *root;
30184 + /* all timestamps always follow the ones on the branch */
30185 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30186 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30187 + if (IS_ERR(root))
30190 + au_sbilist_add(root->d_sb);
30196 +static void aufs_kill_sb(struct super_block *sb)
30198 + struct au_sbinfo *sbinfo;
30200 + sbinfo = au_sbi(sb);
30202 + au_sbilist_del(sb);
30203 + aufs_write_lock(sb->s_root);
30205 + if (sbinfo->si_wbr_create_ops->fin)
30206 + sbinfo->si_wbr_create_ops->fin(sb);
30207 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30208 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30209 + au_remount_refresh(sb, /*do_idop*/0);
30211 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30212 + au_plink_put(sb, /*verbose*/1);
30214 + au_dr_opt_flush(sb);
30215 + sbinfo->si_sb = NULL;
30216 + aufs_write_unlock(sb->s_root);
30217 + au_nwt_flush(&sbinfo->si_nowait);
30219 + kill_anon_super(sb);
30222 +struct file_system_type aufs_fs_type = {
30223 + .name = AUFS_FSTYPE,
30224 + /* a race between rename and others */
30225 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30226 + .mount = aufs_mount,
30227 + .kill_sb = aufs_kill_sb,
30228 + /* no need to __module_get() and module_put(). */
30229 + .owner = THIS_MODULE,
30231 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30232 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30233 +++ linux/fs/aufs/super.h 2018-08-12 23:43:05.463458173 +0200
30235 +/* SPDX-License-Identifier: GPL-2.0 */
30237 + * Copyright (C) 2005-2018 Junjiro R. Okajima
30239 + * This program, aufs is free software; you can redistribute it and/or modify
30240 + * it under the terms of the GNU General Public License as published by
30241 + * the Free Software Foundation; either version 2 of the License, or
30242 + * (at your option) any later version.
30244 + * This program is distributed in the hope that it will be useful,
30245 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30246 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30247 + * GNU General Public License for more details.
30249 + * You should have received a copy of the GNU General Public License
30250 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30254 + * super_block operations
30257 +#ifndef __AUFS_SUPER_H__
30258 +#define __AUFS_SUPER_H__
30262 +#include <linux/fs.h>
30263 +#include <linux/kobject.h>
30265 +#include "rwsem.h"
30268 +/* policies to select one among multiple writable branches */
30269 +struct au_wbr_copyup_operations {
30270 + int (*copyup)(struct dentry *dentry);
30273 +#define AuWbr_DIR 1 /* target is a dir */
30274 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30276 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30277 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30278 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30280 +struct au_wbr_create_operations {
30281 + int (*create)(struct dentry *dentry, unsigned int flags);
30282 + int (*init)(struct super_block *sb);
30283 + int (*fin)(struct super_block *sb);
30286 +struct au_wbr_mfs {
30287 + struct mutex mfs_lock; /* protect this structure */
30288 + unsigned long mfs_jiffy;
30289 + unsigned long mfs_expire;
30290 + aufs_bindex_t mfs_bindex;
30292 + unsigned long long mfsrr_bytes;
30293 + unsigned long long mfsrr_watermark;
30296 +#define AuPlink_NHASH 100
30297 +static inline int au_plink_hash(ino_t ino)
30299 + return ino % AuPlink_NHASH;
30302 +/* File-based Hierarchical Storage Management */
30304 +#ifdef CONFIG_AUFS_FHSM
30305 + /* allow only one process who can receive the notification */
30306 + spinlock_t fhsm_spin;
30308 + wait_queue_head_t fhsm_wqh;
30309 + atomic_t fhsm_readable;
30311 + /* these are protected by si_rwsem */
30312 + unsigned long fhsm_expire;
30313 + aufs_bindex_t fhsm_bottom;
30318 +struct au_sbinfo {
30319 + /* nowait tasks in the system-wide workqueue */
30320 + struct au_nowait_tasks si_nowait;
30323 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
30324 + * rwsem for au_sbinfo is necessary.
30326 + struct au_rwsem si_rwsem;
30329 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30332 + struct percpu_counter si_ninodes, si_nfiles;
30334 + /* branch management */
30335 + unsigned int si_generation;
30337 + /* see AuSi_ flags */
30338 + unsigned char au_si_status;
30340 + aufs_bindex_t si_bbot;
30342 + /* dirty trick to keep br_id plus */
30343 + unsigned int si_last_br_id :
30344 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30345 + struct au_branch **si_branch;
30347 + /* policy to select a writable branch */
30348 + unsigned char si_wbr_copyup;
30349 + unsigned char si_wbr_create;
30350 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30351 + struct au_wbr_create_operations *si_wbr_create_ops;
30353 + /* round robin */
30354 + atomic_t si_wbr_rr_next;
30356 + /* most free space */
30357 + struct au_wbr_mfs si_wbr_mfs;
30359 + /* File-based Hierarchical Storage Management */
30360 + struct au_fhsm si_fhsm;
30362 + /* mount flags */
30363 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30364 + unsigned int si_mntflags;
30366 + /* external inode number (bitmap and translation table) */
30367 + vfs_readf_t si_xread;
30368 + vfs_writef_t si_xwrite;
30369 + struct file *si_xib;
30370 + struct mutex si_xib_mtx; /* protect xib members */
30371 + unsigned long *si_xib_buf;
30372 + unsigned long si_xib_last_pindex;
30373 + int si_xib_next_bit;
30374 + aufs_bindex_t si_xino_brid;
30375 + unsigned long si_xino_jiffy;
30376 + unsigned long si_xino_expire;
30377 + /* reserved for future use */
30378 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30380 +#ifdef CONFIG_AUFS_EXPORT
30381 + /* i_generation */
30382 + struct file *si_xigen;
30383 + atomic_t si_xigen_next;
30386 + /* dirty trick to suppoer atomic_open */
30387 + struct hlist_bl_head si_aopen;
30389 + /* vdir parameters */
30390 + unsigned long si_rdcache; /* max cache time in jiffies */
30391 + unsigned int si_rdblk; /* deblk size */
30392 + unsigned int si_rdhash; /* hash size */
30395 + * If the number of whiteouts are larger than si_dirwh, leave all of
30396 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30397 + * future fsck.aufs or kernel thread will remove them later.
30398 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30400 + unsigned int si_dirwh;
30402 + /* pseudo_link list */
30403 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30404 + wait_queue_head_t si_plink_wq;
30405 + spinlock_t si_plink_maint_lock;
30406 + pid_t si_plink_maint_pid;
30409 + struct hlist_bl_head si_files;
30411 + /* with/without getattr, brother of sb->s_d_op */
30412 + struct inode_operations *si_iop_array;
30415 + * sysfs and lifetime management.
30416 + * this is not a small structure and it may be a waste of memory in case
30417 + * of sysfs is disabled, particulary when many aufs-es are mounted.
30418 + * but using sysfs is majority.
30420 + struct kobject si_kobj;
30421 +#ifdef CONFIG_DEBUG_FS
30422 + struct dentry *si_dbgaufs;
30423 + struct dentry *si_dbgaufs_plink;
30424 + struct dentry *si_dbgaufs_xib;
30425 +#ifdef CONFIG_AUFS_EXPORT
30426 + struct dentry *si_dbgaufs_xigen;
30430 +#ifdef CONFIG_AUFS_SBILIST
30431 + struct hlist_bl_node si_list;
30434 + /* dirty, necessary for unmounting, sysfs and sysrq */
30435 + struct super_block *si_sb;
30438 +/* sbinfo status flags */
30440 + * set true when refresh_dirs() failed at remount time.
30441 + * then try refreshing dirs at access time again.
30442 + * if it is false, refreshing dirs at access time is unnecessary
30444 +#define AuSi_FAILED_REFRESH_DIR 1
30445 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30446 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30448 +#ifndef CONFIG_AUFS_FHSM
30450 +#define AuSi_FHSM 0
30453 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30454 + unsigned int flag)
30456 + AuRwMustAnyLock(&sbi->si_rwsem);
30457 + return sbi->au_si_status & flag;
30459 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30460 +#define au_fset_si(sbinfo, name) do { \
30461 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30462 + (sbinfo)->au_si_status |= AuSi_##name; \
30464 +#define au_fclr_si(sbinfo, name) do { \
30465 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30466 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30469 +/* ---------------------------------------------------------------------- */
30471 +/* policy to select one among writable branches */
30472 +#define AuWbrCopyup(sbinfo, ...) \
30473 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30474 +#define AuWbrCreate(sbinfo, ...) \
30475 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30477 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30478 +#define AuLock_DW 1 /* write-lock dentry */
30479 +#define AuLock_IR (1 << 1) /* read-lock inode */
30480 +#define AuLock_IW (1 << 2) /* write-lock inode */
30481 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30482 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30483 + /* except RENAME_EXCHANGE */
30484 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30485 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30486 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30487 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30488 +#define au_fset_lock(flags, name) \
30489 + do { (flags) |= AuLock_##name; } while (0)
30490 +#define au_fclr_lock(flags, name) \
30491 + do { (flags) &= ~AuLock_##name; } while (0)
30493 +/* ---------------------------------------------------------------------- */
30496 +extern struct file_system_type aufs_fs_type;
30497 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30498 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30499 + unsigned long long max, void *arg);
30500 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30501 + struct super_block *sb, void *arg);
30502 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30503 +void au_iarray_free(struct inode **a, unsigned long long max);
30506 +void au_si_free(struct kobject *kobj);
30507 +int au_si_alloc(struct super_block *sb);
30508 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30510 +unsigned int au_sigen_inc(struct super_block *sb);
30511 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30513 +int si_read_lock(struct super_block *sb, int flags);
30514 +int si_write_lock(struct super_block *sb, int flags);
30515 +int aufs_read_lock(struct dentry *dentry, int flags);
30516 +void aufs_read_unlock(struct dentry *dentry, int flags);
30517 +void aufs_write_lock(struct dentry *dentry);
30518 +void aufs_write_unlock(struct dentry *dentry);
30519 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30520 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30522 +/* wbr_policy.c */
30523 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30524 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30525 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30526 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30527 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30530 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30532 +#ifdef CONFIG_AUFS_FHSM
30535 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30539 + spin_lock(&fhsm->fhsm_spin);
30540 + pid = fhsm->fhsm_pid;
30541 + spin_unlock(&fhsm->fhsm_spin);
30546 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30547 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30548 +int au_fhsm_fd(struct super_block *sb, int oflags);
30549 +int au_fhsm_br_alloc(struct au_branch *br);
30550 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30551 +void au_fhsm_fin(struct super_block *sb);
30552 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30553 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30554 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30556 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30558 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30559 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30560 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30561 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30562 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30563 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30564 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30565 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30566 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30569 +/* ---------------------------------------------------------------------- */
30571 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30573 + return sb->s_fs_info;
30576 +/* ---------------------------------------------------------------------- */
30578 +#ifdef CONFIG_AUFS_EXPORT
30579 +int au_test_nfsd(void);
30580 +void au_export_init(struct super_block *sb);
30581 +void au_xigen_inc(struct inode *inode);
30582 +int au_xigen_new(struct inode *inode);
30583 +int au_xigen_set(struct super_block *sb, struct path *path);
30584 +void au_xigen_clr(struct super_block *sb);
30586 +static inline int au_busy_or_stale(void)
30588 + if (!au_test_nfsd())
30593 +AuStubInt0(au_test_nfsd, void)
30594 +AuStubVoid(au_export_init, struct super_block *sb)
30595 +AuStubVoid(au_xigen_inc, struct inode *inode)
30596 +AuStubInt0(au_xigen_new, struct inode *inode)
30597 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30598 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30599 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30600 +#endif /* CONFIG_AUFS_EXPORT */
30602 +/* ---------------------------------------------------------------------- */
30604 +#ifdef CONFIG_AUFS_SBILIST
30606 +extern struct hlist_bl_head au_sbilist;
30608 +static inline void au_sbilist_init(void)
30610 + INIT_HLIST_BL_HEAD(&au_sbilist);
30613 +static inline void au_sbilist_add(struct super_block *sb)
30615 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30618 +static inline void au_sbilist_del(struct super_block *sb)
30620 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30623 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30624 +static inline void au_sbilist_lock(void)
30626 + hlist_bl_lock(&au_sbilist);
30629 +static inline void au_sbilist_unlock(void)
30631 + hlist_bl_unlock(&au_sbilist);
30633 +#define AuGFP_SBILIST GFP_ATOMIC
30635 +AuStubVoid(au_sbilist_lock, void)
30636 +AuStubVoid(au_sbilist_unlock, void)
30637 +#define AuGFP_SBILIST GFP_NOFS
30638 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30640 +AuStubVoid(au_sbilist_init, void)
30641 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30642 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30643 +AuStubVoid(au_sbilist_lock, void)
30644 +AuStubVoid(au_sbilist_unlock, void)
30645 +#define AuGFP_SBILIST GFP_NOFS
30648 +/* ---------------------------------------------------------------------- */
30650 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30653 + * This function is a dynamic '__init' function actually,
30654 + * so the tiny check for si_rwsem is unnecessary.
30656 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30657 +#ifdef CONFIG_DEBUG_FS
30658 + sbinfo->si_dbgaufs = NULL;
30659 + sbinfo->si_dbgaufs_plink = NULL;
30660 + sbinfo->si_dbgaufs_xib = NULL;
30661 +#ifdef CONFIG_AUFS_EXPORT
30662 + sbinfo->si_dbgaufs_xigen = NULL;
30667 +/* ---------------------------------------------------------------------- */
30669 +/* current->atomic_flags */
30670 +/* this value should never corrupt the ones defined in linux/sched.h */
30671 +#define PFA_AUFS 7
30673 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30674 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30675 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30677 +static inline int si_pid_test(struct super_block *sb)
30679 + return !!task_test_aufs(current);
30682 +static inline void si_pid_clr(struct super_block *sb)
30684 + AuDebugOn(!task_test_aufs(current));
30685 + task_clear_aufs(current);
30688 +static inline void si_pid_set(struct super_block *sb)
30690 + AuDebugOn(task_test_aufs(current));
30691 + task_set_aufs(current);
30694 +/* ---------------------------------------------------------------------- */
30696 +/* lock superblock. mainly for entry point functions */
30697 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
30698 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
30699 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
30700 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
30702 +#define __si_read_trylock_nested(sb) \
30703 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
30704 +#define __si_write_trylock_nested(sb) \
30705 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
30708 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
30709 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
30710 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
30712 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30713 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30714 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30716 +static inline void si_noflush_read_lock(struct super_block *sb)
30718 + __si_read_lock(sb);
30722 +static inline int si_noflush_read_trylock(struct super_block *sb)
30726 + locked = __si_read_trylock(sb);
30732 +static inline void si_noflush_write_lock(struct super_block *sb)
30734 + __si_write_lock(sb);
30738 +static inline int si_noflush_write_trylock(struct super_block *sb)
30742 + locked = __si_write_trylock(sb);
30748 +#if 0 /* reserved */
30749 +static inline int si_read_trylock(struct super_block *sb, int flags)
30751 + if (au_ftest_lock(flags, FLUSH))
30752 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30753 + return si_noflush_read_trylock(sb);
30757 +static inline void si_read_unlock(struct super_block *sb)
30760 + __si_read_unlock(sb);
30763 +#if 0 /* reserved */
30764 +static inline int si_write_trylock(struct super_block *sb, int flags)
30766 + if (au_ftest_lock(flags, FLUSH))
30767 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30768 + return si_noflush_write_trylock(sb);
30772 +static inline void si_write_unlock(struct super_block *sb)
30775 + __si_write_unlock(sb);
30778 +#if 0 /* reserved */
30779 +static inline void si_downgrade_lock(struct super_block *sb)
30781 + __si_downgrade_lock(sb);
30785 +/* ---------------------------------------------------------------------- */
30787 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
30789 + SiMustAnyLock(sb);
30790 + return au_sbi(sb)->si_bbot;
30793 +static inline unsigned int au_mntflags(struct super_block *sb)
30795 + SiMustAnyLock(sb);
30796 + return au_sbi(sb)->si_mntflags;
30799 +static inline unsigned int au_sigen(struct super_block *sb)
30801 + SiMustAnyLock(sb);
30802 + return au_sbi(sb)->si_generation;
30805 +static inline unsigned long long au_ninodes(struct super_block *sb)
30807 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_ninodes);
30813 +static inline void au_ninodes_inc(struct super_block *sb)
30815 + percpu_counter_inc(&au_sbi(sb)->si_ninodes);
30818 +static inline void au_ninodes_dec(struct super_block *sb)
30820 + percpu_counter_dec(&au_sbi(sb)->si_ninodes);
30823 +static inline unsigned long long au_nfiles(struct super_block *sb)
30825 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_nfiles);
30831 +static inline void au_nfiles_inc(struct super_block *sb)
30833 + percpu_counter_inc(&au_sbi(sb)->si_nfiles);
30836 +static inline void au_nfiles_dec(struct super_block *sb)
30838 + percpu_counter_dec(&au_sbi(sb)->si_nfiles);
30841 +static inline struct au_branch *au_sbr(struct super_block *sb,
30842 + aufs_bindex_t bindex)
30844 + SiMustAnyLock(sb);
30845 + return au_sbi(sb)->si_branch[0 + bindex];
30848 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
30850 + SiMustWriteLock(sb);
30851 + au_sbi(sb)->si_xino_brid = brid;
30854 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
30856 + SiMustAnyLock(sb);
30857 + return au_sbi(sb)->si_xino_brid;
30860 +#endif /* __KERNEL__ */
30861 +#endif /* __AUFS_SUPER_H__ */
30862 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
30863 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
30864 +++ linux/fs/aufs/sysaufs.c 2018-08-12 23:43:05.463458173 +0200
30866 +// SPDX-License-Identifier: GPL-2.0
30868 + * Copyright (C) 2005-2018 Junjiro R. Okajima
30870 + * This program, aufs is free software; you can redistribute it and/or modify
30871 + * it under the terms of the GNU General Public License as published by
30872 + * the Free Software Foundation; either version 2 of the License, or
30873 + * (at your option) any later version.
30875 + * This program is distributed in the hope that it will be useful,
30876 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30877 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30878 + * GNU General Public License for more details.
30880 + * You should have received a copy of the GNU General Public License
30881 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30885 + * sysfs interface and lifetime management
30886 + * they are necessary regardless sysfs is disabled.
30889 +#include <linux/random.h>
30892 +unsigned long sysaufs_si_mask;
30893 +struct kset *sysaufs_kset;
30895 +#define AuSiAttr(_name) { \
30896 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
30897 + .show = sysaufs_si_##_name, \
30900 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
30901 +struct attribute *sysaufs_si_attrs[] = {
30902 + &sysaufs_si_attr_xi_path.attr,
30906 +static const struct sysfs_ops au_sbi_ops = {
30907 + .show = sysaufs_si_show
30910 +static struct kobj_type au_sbi_ktype = {
30911 + .release = au_si_free,
30912 + .sysfs_ops = &au_sbi_ops,
30913 + .default_attrs = sysaufs_si_attrs
30916 +/* ---------------------------------------------------------------------- */
30918 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
30922 + sbinfo->si_kobj.kset = sysaufs_kset;
30923 + /* cf. sysaufs_name() */
30924 + err = kobject_init_and_add
30925 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
30926 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
30931 +void sysaufs_fin(void)
30933 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
30934 + kset_unregister(sysaufs_kset);
30937 +int __init sysaufs_init(void)
30942 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
30943 + } while (!sysaufs_si_mask);
30946 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
30947 + if (unlikely(!sysaufs_kset))
30949 + err = PTR_ERR(sysaufs_kset);
30950 + if (IS_ERR(sysaufs_kset))
30952 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
30953 + if (unlikely(err))
30954 + kset_unregister(sysaufs_kset);
30959 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
30960 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
30961 +++ linux/fs/aufs/sysaufs.h 2018-08-12 23:43:05.463458173 +0200
30963 +/* SPDX-License-Identifier: GPL-2.0 */
30965 + * Copyright (C) 2005-2018 Junjiro R. Okajima
30967 + * This program, aufs is free software; you can redistribute it and/or modify
30968 + * it under the terms of the GNU General Public License as published by
30969 + * the Free Software Foundation; either version 2 of the License, or
30970 + * (at your option) any later version.
30972 + * This program is distributed in the hope that it will be useful,
30973 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30974 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30975 + * GNU General Public License for more details.
30977 + * You should have received a copy of the GNU General Public License
30978 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30982 + * sysfs interface and mount lifetime management
30985 +#ifndef __SYSAUFS_H__
30986 +#define __SYSAUFS_H__
30990 +#include <linux/sysfs.h>
30991 +#include "module.h"
30993 +struct super_block;
30996 +struct sysaufs_si_attr {
30997 + struct attribute attr;
30998 + int (*show)(struct seq_file *seq, struct super_block *sb);
31001 +/* ---------------------------------------------------------------------- */
31004 +extern unsigned long sysaufs_si_mask;
31005 +extern struct kset *sysaufs_kset;
31006 +extern struct attribute *sysaufs_si_attrs[];
31007 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31008 +int __init sysaufs_init(void);
31009 +void sysaufs_fin(void);
31011 +/* ---------------------------------------------------------------------- */
31013 +/* some people doesn't like to show a pointer in kernel */
31014 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31016 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31019 +#define SysaufsSiNamePrefix "si_"
31020 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31021 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31023 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31024 + sysaufs_si_id(sbinfo));
31028 +#ifdef CONFIG_SYSFS
31030 +extern struct attribute_group *sysaufs_attr_group;
31032 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31033 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31035 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31036 +#ifdef CONFIG_COMPAT
31037 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31040 +void sysaufs_br_init(struct au_branch *br);
31041 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31042 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31044 +#define sysaufs_brs_init() do {} while (0)
31047 +#define sysaufs_attr_group NULL
31049 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31050 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31051 + struct attribute *attr, char *buf)
31052 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31053 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31054 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31056 +static inline void sysaufs_brs_init(void)
31061 +#endif /* CONFIG_SYSFS */
31063 +#endif /* __KERNEL__ */
31064 +#endif /* __SYSAUFS_H__ */
31065 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31066 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31067 +++ linux/fs/aufs/sysfs.c 2018-08-12 23:43:05.463458173 +0200
31069 +// SPDX-License-Identifier: GPL-2.0
31071 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31073 + * This program, aufs is free software; you can redistribute it and/or modify
31074 + * it under the terms of the GNU General Public License as published by
31075 + * the Free Software Foundation; either version 2 of the License, or
31076 + * (at your option) any later version.
31078 + * This program is distributed in the hope that it will be useful,
31079 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31080 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31081 + * GNU General Public License for more details.
31083 + * You should have received a copy of the GNU General Public License
31084 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31088 + * sysfs interface
31091 +#include <linux/compat.h>
31092 +#include <linux/seq_file.h>
31095 +#ifdef CONFIG_AUFS_FS_MODULE
31096 +/* this entry violates the "one line per file" policy of sysfs */
31097 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31101 + static char *conf =
31102 +/* this file is generated at compiling */
31103 +#include "conf.str"
31106 + err = snprintf(buf, PAGE_SIZE, conf);
31107 + if (unlikely(err >= PAGE_SIZE))
31112 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31115 +static struct attribute *au_attr[] = {
31116 +#ifdef CONFIG_AUFS_FS_MODULE
31117 + &au_config_attr.attr,
31119 + NULL, /* need to NULL terminate the list of attributes */
31122 +static struct attribute_group sysaufs_attr_group_body = {
31126 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31128 +/* ---------------------------------------------------------------------- */
31130 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31134 + SiMustAnyLock(sb);
31137 + if (au_opt_test(au_mntflags(sb), XINO)) {
31138 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31139 + seq_putc(seq, '\n');
31145 + * the lifetime of branch is independent from the entry under sysfs.
31146 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31149 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31150 + aufs_bindex_t bindex, int idx)
31153 + struct path path;
31154 + struct dentry *root;
31155 + struct au_branch *br;
31156 + au_br_perm_str_t perm;
31158 + AuDbg("b%d\n", bindex);
31161 + root = sb->s_root;
31162 + di_read_lock_parent(root, !AuLock_IR);
31163 + br = au_sbr(sb, bindex);
31166 + case AuBrSysfs_BR:
31167 + path.mnt = au_br_mnt(br);
31168 + path.dentry = au_h_dptr(root, bindex);
31169 + err = au_seq_path(seq, &path);
31171 + au_optstr_br_perm(&perm, br->br_perm);
31172 + seq_printf(seq, "=%s\n", perm.a);
31175 + case AuBrSysfs_BRID:
31176 + seq_printf(seq, "%d\n", br->br_id);
31179 + di_read_unlock(root, !AuLock_IR);
31180 + if (unlikely(err || seq_has_overflowed(seq)))
31186 +/* ---------------------------------------------------------------------- */
31188 +static struct seq_file *au_seq(char *p, ssize_t len)
31190 + struct seq_file *seq;
31192 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31194 + /* mutex_init(&seq.lock); */
31197 + return seq; /* success */
31200 + seq = ERR_PTR(-ENOMEM);
31204 +#define SysaufsBr_PREFIX "br"
31205 +#define SysaufsBrid_PREFIX "brid"
31207 +/* todo: file size may exceed PAGE_SIZE */
31208 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31214 + aufs_bindex_t bbot;
31215 + struct au_sbinfo *sbinfo;
31216 + struct super_block *sb;
31217 + struct seq_file *seq;
31219 + struct attribute **cattr;
31221 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31222 + sb = sbinfo->si_sb;
31225 + * prevent a race condition between sysfs and aufs.
31226 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31227 + * prohibits maintaining the sysfs entries.
31228 + * hew we acquire read lock after sysfs_get_active_two().
31229 + * on the other hand, the remount process may maintain the sysfs/aufs
31230 + * entries after acquiring write lock.
31231 + * it can cause a deadlock.
31232 + * simply we gave up processing read here.
31235 + if (unlikely(!si_noflush_read_trylock(sb)))
31238 + seq = au_seq(buf, PAGE_SIZE);
31239 + err = PTR_ERR(seq);
31243 + name = (void *)attr->name;
31244 + cattr = sysaufs_si_attrs;
31246 + if (!strcmp(name, (*cattr)->name)) {
31247 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31254 + if (!strncmp(name, SysaufsBrid_PREFIX,
31255 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31256 + idx = AuBrSysfs_BRID;
31257 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31258 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31259 + sizeof(SysaufsBr_PREFIX) - 1)) {
31260 + idx = AuBrSysfs_BR;
31261 + name += sizeof(SysaufsBr_PREFIX) - 1;
31265 + err = kstrtol(name, 10, &l);
31267 + bbot = au_sbbot(sb);
31269 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31276 + err = seq->count;
31277 + /* sysfs limit */
31278 + if (unlikely(err == PAGE_SIZE))
31283 + si_read_unlock(sb);
31288 +/* ---------------------------------------------------------------------- */
31290 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31294 + aufs_bindex_t bindex, bbot;
31297 + struct seq_file *seq;
31298 + struct au_branch *br;
31300 + si_read_lock(sb, AuLock_FLUSH);
31301 + bbot = au_sbbot(sb);
31307 + buf = (void *)__get_free_page(GFP_NOFS);
31308 + if (unlikely(!buf))
31311 + seq = au_seq(buf, PAGE_SIZE);
31312 + err = PTR_ERR(seq);
31316 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31317 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31318 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
31319 + if (unlikely(err))
31322 + br = au_sbr(sb, bindex);
31323 + brid = br->br_id;
31324 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31325 + err = __put_user(brid, &arg->id);
31326 + if (unlikely(err))
31329 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31330 + err = __put_user(br->br_perm, &arg->perm);
31331 + if (unlikely(err))
31334 + err = au_seq_path(seq, &br->br_path);
31335 + if (unlikely(err))
31337 + seq_putc(seq, '\0');
31338 + if (!seq_has_overflowed(seq)) {
31339 + err = copy_to_user(arg->path, seq->buf, seq->count);
31341 + if (unlikely(err))
31348 + if (unlikely(err))
31354 + free_page((unsigned long)buf);
31356 + si_read_unlock(sb);
31360 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31362 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31365 +#ifdef CONFIG_COMPAT
31366 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31368 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31372 +/* ---------------------------------------------------------------------- */
31374 +void sysaufs_br_init(struct au_branch *br)
31377 + struct au_brsysfs *br_sysfs;
31378 + struct attribute *attr;
31380 + br_sysfs = br->br_sysfs;
31381 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31382 + attr = &br_sysfs->attr;
31383 + sysfs_attr_init(attr);
31384 + attr->name = br_sysfs->name;
31385 + attr->mode = 0444;
31390 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31392 + struct au_branch *br;
31393 + struct kobject *kobj;
31394 + struct au_brsysfs *br_sysfs;
31396 + aufs_bindex_t bbot;
31398 + if (!sysaufs_brs)
31401 + kobj = &au_sbi(sb)->si_kobj;
31402 + bbot = au_sbbot(sb);
31403 + for (; bindex <= bbot; bindex++) {
31404 + br = au_sbr(sb, bindex);
31405 + br_sysfs = br->br_sysfs;
31406 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31407 + sysfs_remove_file(kobj, &br_sysfs->attr);
31413 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31416 + aufs_bindex_t bbot;
31417 + struct kobject *kobj;
31418 + struct au_branch *br;
31419 + struct au_brsysfs *br_sysfs;
31421 + if (!sysaufs_brs)
31424 + kobj = &au_sbi(sb)->si_kobj;
31425 + bbot = au_sbbot(sb);
31426 + for (; bindex <= bbot; bindex++) {
31427 + br = au_sbr(sb, bindex);
31428 + br_sysfs = br->br_sysfs;
31429 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31430 + SysaufsBr_PREFIX "%d", bindex);
31431 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31432 + SysaufsBrid_PREFIX "%d", bindex);
31433 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31434 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31435 + if (unlikely(err))
31436 + pr_warn("failed %s under sysfs(%d)\n",
31437 + br_sysfs->name, err);
31442 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31443 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31444 +++ linux/fs/aufs/sysrq.c 2018-08-12 23:43:05.463458173 +0200
31446 +// SPDX-License-Identifier: GPL-2.0
31448 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31450 + * This program, aufs is free software; you can redistribute it and/or modify
31451 + * it under the terms of the GNU General Public License as published by
31452 + * the Free Software Foundation; either version 2 of the License, or
31453 + * (at your option) any later version.
31455 + * This program is distributed in the hope that it will be useful,
31456 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31457 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31458 + * GNU General Public License for more details.
31460 + * You should have received a copy of the GNU General Public License
31461 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31465 + * magic sysrq hanlder
31468 +/* #include <linux/sysrq.h> */
31469 +#include <linux/writeback.h>
31472 +/* ---------------------------------------------------------------------- */
31474 +static void sysrq_sb(struct super_block *sb)
31477 + struct au_sbinfo *sbinfo;
31478 + struct file *file;
31479 + struct hlist_bl_head *files;
31480 + struct hlist_bl_node *pos;
31481 + struct au_finfo *finfo;
31483 + plevel = au_plevel;
31484 + au_plevel = KERN_WARNING;
31486 + /* since we define pr_fmt, call printk directly */
31487 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31489 + sbinfo = au_sbi(sb);
31490 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31491 + pr("superblock\n");
31495 + pr("root dentry\n");
31496 + au_dpri_dentry(sb->s_root);
31497 + pr("root inode\n");
31498 + au_dpri_inode(d_inode(sb->s_root));
31503 + int err, i, j, ndentry;
31504 + struct au_dcsub_pages dpages;
31505 + struct au_dpage *dpage;
31507 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31508 + if (unlikely(err))
31510 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31512 + for (i = 0; i < dpages.ndpage; i++) {
31513 + dpage = dpages.dpages + i;
31514 + ndentry = dpage->ndentry;
31515 + for (j = 0; j < ndentry; j++)
31516 + au_dpri_dentry(dpage->dentries[j]);
31518 + au_dpages_free(&dpages);
31526 + pr("isolated inode\n");
31527 + spin_lock(&sb->s_inode_list_lock);
31528 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31529 + spin_lock(&i->i_lock);
31530 + if (1 || hlist_empty(&i->i_dentry))
31531 + au_dpri_inode(i);
31532 + spin_unlock(&i->i_lock);
31534 + spin_unlock(&sb->s_inode_list_lock);
31538 + files = &au_sbi(sb)->si_files;
31539 + hlist_bl_lock(files);
31540 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31543 + file = finfo->fi_file;
31544 + mode = file_inode(file)->i_mode;
31545 + if (!special_file(mode))
31546 + au_dpri_file(file);
31548 + hlist_bl_unlock(files);
31552 + au_plevel = plevel;
31555 +/* ---------------------------------------------------------------------- */
31557 +/* module parameter */
31558 +static char *aufs_sysrq_key = "a";
31559 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31560 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31562 +static void au_sysrq(int key __maybe_unused)
31564 + struct au_sbinfo *sbinfo;
31565 + struct hlist_bl_node *pos;
31568 + au_sbilist_lock();
31569 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31570 + sysrq_sb(sbinfo->si_sb);
31571 + au_sbilist_unlock();
31575 +static struct sysrq_key_op au_sysrq_op = {
31576 + .handler = au_sysrq,
31577 + .help_msg = "Aufs",
31578 + .action_msg = "Aufs",
31579 + .enable_mask = SYSRQ_ENABLE_DUMP
31582 +/* ---------------------------------------------------------------------- */
31584 +int __init au_sysrq_init(void)
31590 + key = *aufs_sysrq_key;
31591 + if ('a' <= key && key <= 'z')
31592 + err = register_sysrq_key(key, &au_sysrq_op);
31593 + if (unlikely(err))
31594 + pr_err("err %d, sysrq=%c\n", err, key);
31598 +void au_sysrq_fin(void)
31602 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31603 + if (unlikely(err))
31604 + pr_err("err %d (ignored)\n", err);
31606 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31607 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31608 +++ linux/fs/aufs/vdir.c 2018-08-12 23:43:05.463458173 +0200
31610 +// SPDX-License-Identifier: GPL-2.0
31612 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31614 + * This program, aufs is free software; you can redistribute it and/or modify
31615 + * it under the terms of the GNU General Public License as published by
31616 + * the Free Software Foundation; either version 2 of the License, or
31617 + * (at your option) any later version.
31619 + * This program is distributed in the hope that it will be useful,
31620 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31621 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31622 + * GNU General Public License for more details.
31624 + * You should have received a copy of the GNU General Public License
31625 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31629 + * virtual or vertical directory
31634 +static unsigned int calc_size(int nlen)
31636 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31639 +static int set_deblk_end(union au_vdir_deblk_p *p,
31640 + union au_vdir_deblk_p *deblk_end)
31642 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31643 + p->de->de_str.len = 0;
31647 + return -1; /* error */
31650 +/* returns true or false */
31651 +static int is_deblk_end(union au_vdir_deblk_p *p,
31652 + union au_vdir_deblk_p *deblk_end)
31654 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31655 + return !p->de->de_str.len;
31659 +static unsigned char *last_deblk(struct au_vdir *vdir)
31661 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31664 +/* ---------------------------------------------------------------------- */
31666 +/* estimate the appropriate size for name hash table */
31667 +unsigned int au_rdhash_est(loff_t sz)
31675 + if (sz < AUFS_RDHASH_DEF)
31676 + n = AUFS_RDHASH_DEF;
31677 + /* pr_info("n %u\n", n); */
31682 + * the allocated memory has to be freed by
31683 + * au_nhash_wh_free() or au_nhash_de_free().
31685 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31687 + struct hlist_head *head;
31691 + sz = sizeof(*nhash->nh_head) * num_hash;
31692 + head = kmalloc(sz, gfp);
31694 + nhash->nh_num = num_hash;
31695 + nhash->nh_head = head;
31696 + for (u = 0; u < num_hash; u++)
31697 + INIT_HLIST_HEAD(head++);
31698 + return 0; /* success */
31704 +static void nhash_count(struct hlist_head *head)
31708 + struct hlist_node *pos;
31711 + hlist_for_each(pos, head)
31713 + pr_info("%lu\n", n);
31717 +static void au_nhash_wh_do_free(struct hlist_head *head)
31719 + struct au_vdir_wh *pos;
31720 + struct hlist_node *node;
31722 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31726 +static void au_nhash_de_do_free(struct hlist_head *head)
31728 + struct au_vdir_dehstr *pos;
31729 + struct hlist_node *node;
31731 + hlist_for_each_entry_safe(pos, node, head, hash)
31732 + au_cache_free_vdir_dehstr(pos);
31735 +static void au_nhash_do_free(struct au_nhash *nhash,
31736 + void (*free)(struct hlist_head *head))
31739 + struct hlist_head *head;
31741 + n = nhash->nh_num;
31745 + head = nhash->nh_head;
31746 + while (n-- > 0) {
31747 + nhash_count(head);
31750 + kfree(nhash->nh_head);
31753 +void au_nhash_wh_free(struct au_nhash *whlist)
31755 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31758 +static void au_nhash_de_free(struct au_nhash *delist)
31760 + au_nhash_do_free(delist, au_nhash_de_do_free);
31763 +/* ---------------------------------------------------------------------- */
31765 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
31769 + unsigned int u, n;
31770 + struct hlist_head *head;
31771 + struct au_vdir_wh *pos;
31774 + n = whlist->nh_num;
31775 + head = whlist->nh_head;
31776 + for (u = 0; u < n; u++, head++)
31777 + hlist_for_each_entry(pos, head, wh_hash)
31778 + if (pos->wh_bindex == btgt && ++num > limit)
31783 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
31784 + unsigned char *name,
31785 + unsigned int len)
31788 + /* const unsigned int magic_bit = 12; */
31790 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
31797 + /* v = hash_long(v, magic_bit); */
31798 + v %= nhash->nh_num;
31799 + return nhash->nh_head + v;
31802 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
31805 + return str->len == nlen && !memcmp(str->name, name, nlen);
31808 +/* returns found or not */
31809 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
31811 + struct hlist_head *head;
31812 + struct au_vdir_wh *pos;
31813 + struct au_vdir_destr *str;
31815 + head = au_name_hash(whlist, name, nlen);
31816 + hlist_for_each_entry(pos, head, wh_hash) {
31817 + str = &pos->wh_str;
31818 + AuDbg("%.*s\n", str->len, str->name);
31819 + if (au_nhash_test_name(str, name, nlen))
31825 +/* returns found(true) or not */
31826 +static int test_known(struct au_nhash *delist, char *name, int nlen)
31828 + struct hlist_head *head;
31829 + struct au_vdir_dehstr *pos;
31830 + struct au_vdir_destr *str;
31832 + head = au_name_hash(delist, name, nlen);
31833 + hlist_for_each_entry(pos, head, hash) {
31835 + AuDbg("%.*s\n", str->len, str->name);
31836 + if (au_nhash_test_name(str, name, nlen))
31842 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
31843 + unsigned char d_type)
31845 +#ifdef CONFIG_AUFS_SHWH
31846 + wh->wh_ino = ino;
31847 + wh->wh_type = d_type;
31851 +/* ---------------------------------------------------------------------- */
31853 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
31854 + unsigned int d_type, aufs_bindex_t bindex,
31855 + unsigned char shwh)
31858 + struct au_vdir_destr *str;
31859 + struct au_vdir_wh *wh;
31861 + AuDbg("%.*s\n", nlen, name);
31862 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
31865 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
31866 + if (unlikely(!wh))
31870 + wh->wh_bindex = bindex;
31872 + au_shwh_init_wh(wh, ino, d_type);
31873 + str = &wh->wh_str;
31875 + memcpy(str->name, name, nlen);
31876 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
31883 +static int append_deblk(struct au_vdir *vdir)
31886 + unsigned long ul;
31887 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
31888 + union au_vdir_deblk_p p, deblk_end;
31889 + unsigned char **o;
31892 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
31893 + GFP_NOFS, /*may_shrink*/0);
31894 + if (unlikely(!o))
31897 + vdir->vd_deblk = o;
31898 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
31900 + ul = vdir->vd_nblk++;
31901 + vdir->vd_deblk[ul] = p.deblk;
31902 + vdir->vd_last.ul = ul;
31903 + vdir->vd_last.p.deblk = p.deblk;
31904 + deblk_end.deblk = p.deblk + deblk_sz;
31905 + err = set_deblk_end(&p, &deblk_end);
31912 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
31913 + unsigned int d_type, struct au_nhash *delist)
31917 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
31918 + union au_vdir_deblk_p p, *room, deblk_end;
31919 + struct au_vdir_dehstr *dehstr;
31921 + p.deblk = last_deblk(vdir);
31922 + deblk_end.deblk = p.deblk + deblk_sz;
31923 + room = &vdir->vd_last.p;
31924 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
31925 + || !is_deblk_end(room, &deblk_end));
31927 + sz = calc_size(nlen);
31928 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
31929 + err = append_deblk(vdir);
31930 + if (unlikely(err))
31933 + p.deblk = last_deblk(vdir);
31934 + deblk_end.deblk = p.deblk + deblk_sz;
31936 + AuDebugOn(room->deblk != p.deblk);
31940 + dehstr = au_cache_alloc_vdir_dehstr();
31941 + if (unlikely(!dehstr))
31944 + dehstr->str = &room->de->de_str;
31945 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
31946 + room->de->de_ino = ino;
31947 + room->de->de_type = d_type;
31948 + room->de->de_str.len = nlen;
31949 + memcpy(room->de->de_str.name, name, nlen);
31952 + room->deblk += sz;
31953 + if (unlikely(set_deblk_end(room, &deblk_end)))
31954 + err = append_deblk(vdir);
31961 +/* ---------------------------------------------------------------------- */
31963 +void au_vdir_free(struct au_vdir *vdir)
31965 + unsigned char **deblk;
31967 + deblk = vdir->vd_deblk;
31968 + while (vdir->vd_nblk--)
31970 + kfree(vdir->vd_deblk);
31971 + au_cache_free_vdir(vdir);
31974 +static struct au_vdir *alloc_vdir(struct file *file)
31976 + struct au_vdir *vdir;
31977 + struct super_block *sb;
31980 + sb = file->f_path.dentry->d_sb;
31981 + SiMustAnyLock(sb);
31984 + vdir = au_cache_alloc_vdir();
31985 + if (unlikely(!vdir))
31988 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
31989 + if (unlikely(!vdir->vd_deblk))
31992 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
31993 + if (!vdir->vd_deblk_sz) {
31994 + /* estimate the appropriate size for deblk */
31995 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
31996 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
31998 + vdir->vd_nblk = 0;
31999 + vdir->vd_version = 0;
32000 + vdir->vd_jiffy = 0;
32001 + err = append_deblk(vdir);
32003 + return vdir; /* success */
32005 + kfree(vdir->vd_deblk);
32008 + au_cache_free_vdir(vdir);
32010 + vdir = ERR_PTR(err);
32014 +static int reinit_vdir(struct au_vdir *vdir)
32017 + union au_vdir_deblk_p p, deblk_end;
32019 + while (vdir->vd_nblk > 1) {
32020 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
32021 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32024 + p.deblk = vdir->vd_deblk[0];
32025 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32026 + err = set_deblk_end(&p, &deblk_end);
32027 + /* keep vd_dblk_sz */
32028 + vdir->vd_last.ul = 0;
32029 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32030 + vdir->vd_version = 0;
32031 + vdir->vd_jiffy = 0;
32036 +/* ---------------------------------------------------------------------- */
32038 +#define AuFillVdir_CALLED 1
32039 +#define AuFillVdir_WHABLE (1 << 1)
32040 +#define AuFillVdir_SHWH (1 << 2)
32041 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32042 +#define au_fset_fillvdir(flags, name) \
32043 + do { (flags) |= AuFillVdir_##name; } while (0)
32044 +#define au_fclr_fillvdir(flags, name) \
32045 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32047 +#ifndef CONFIG_AUFS_SHWH
32048 +#undef AuFillVdir_SHWH
32049 +#define AuFillVdir_SHWH 0
32052 +struct fillvdir_arg {
32053 + struct dir_context ctx;
32054 + struct file *file;
32055 + struct au_vdir *vdir;
32056 + struct au_nhash delist;
32057 + struct au_nhash whlist;
32058 + aufs_bindex_t bindex;
32059 + unsigned int flags;
32063 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32064 + loff_t offset __maybe_unused, u64 h_ino,
32065 + unsigned int d_type)
32067 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32068 + char *name = (void *)__name;
32069 + struct super_block *sb;
32071 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32074 + sb = arg->file->f_path.dentry->d_sb;
32075 + au_fset_fillvdir(arg->flags, CALLED);
32077 + if (nlen <= AUFS_WH_PFX_LEN
32078 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32079 + if (test_known(&arg->delist, name, nlen)
32080 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32081 + goto out; /* already exists or whiteouted */
32083 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32085 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32086 + d_type = DT_UNKNOWN;
32087 + arg->err = append_de(arg->vdir, name, nlen, ino,
32088 + d_type, &arg->delist);
32090 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32091 + name += AUFS_WH_PFX_LEN;
32092 + nlen -= AUFS_WH_PFX_LEN;
32093 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32094 + goto out; /* already whiteouted */
32097 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32100 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32101 + d_type = DT_UNKNOWN;
32102 + arg->err = au_nhash_append_wh
32103 + (&arg->whlist, name, nlen, ino, d_type,
32104 + arg->bindex, shwh);
32110 + arg->vdir->vd_jiffy = jiffies;
32112 + AuTraceErr(arg->err);
32116 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32117 + struct au_nhash *whlist, struct au_nhash *delist)
32119 +#ifdef CONFIG_AUFS_SHWH
32121 + unsigned int nh, u;
32122 + struct hlist_head *head;
32123 + struct au_vdir_wh *pos;
32124 + struct hlist_node *n;
32126 + struct au_vdir_destr *destr;
32128 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32131 + o = p = (void *)__get_free_page(GFP_NOFS);
32132 + if (unlikely(!p))
32136 + nh = whlist->nh_num;
32137 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32138 + p += AUFS_WH_PFX_LEN;
32139 + for (u = 0; u < nh; u++) {
32140 + head = whlist->nh_head + u;
32141 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32142 + destr = &pos->wh_str;
32143 + memcpy(p, destr->name, destr->len);
32144 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32145 + pos->wh_ino, pos->wh_type, delist);
32146 + if (unlikely(err))
32151 + free_page((unsigned long)o);
32161 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32164 + unsigned int rdhash;
32166 + aufs_bindex_t bbot, bindex, btop;
32167 + unsigned char shwh;
32168 + struct file *hf, *file;
32169 + struct super_block *sb;
32171 + file = arg->file;
32172 + sb = file->f_path.dentry->d_sb;
32173 + SiMustAnyLock(sb);
32175 + rdhash = au_sbi(sb)->si_rdhash;
32177 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32178 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32179 + if (unlikely(err))
32181 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32182 + if (unlikely(err))
32188 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32190 + au_fset_fillvdir(arg->flags, SHWH);
32192 + btop = au_fbtop(file);
32193 + bbot = au_fbbot_dir(file);
32194 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32195 + hf = au_hf_dir(file, bindex);
32199 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32201 + if (unlikely(offset))
32204 + arg->bindex = bindex;
32205 + au_fclr_fillvdir(arg->flags, WHABLE);
32207 + || (bindex != bbot
32208 + && au_br_whable(au_sbr_perm(sb, bindex))))
32209 + au_fset_fillvdir(arg->flags, WHABLE);
32212 + au_fclr_fillvdir(arg->flags, CALLED);
32214 + err = vfsub_iterate_dir(hf, &arg->ctx);
32217 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32220 + * dir_relax() may be good for concurrency, but aufs should not
32221 + * use it since it will cause a lockdep problem.
32225 + if (!err && shwh)
32226 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32228 + au_nhash_wh_free(&arg->whlist);
32231 + au_nhash_de_free(&arg->delist);
32236 +static int read_vdir(struct file *file, int may_read)
32239 + unsigned long expire;
32240 + unsigned char do_read;
32241 + struct fillvdir_arg arg = {
32243 + .actor = fillvdir
32246 + struct inode *inode;
32247 + struct au_vdir *vdir, *allocated;
32250 + inode = file_inode(file);
32251 + IMustLock(inode);
32252 + IiMustWriteLock(inode);
32253 + SiMustAnyLock(inode->i_sb);
32255 + allocated = NULL;
32257 + expire = au_sbi(inode->i_sb)->si_rdcache;
32258 + vdir = au_ivdir(inode);
32261 + vdir = alloc_vdir(file);
32262 + err = PTR_ERR(vdir);
32263 + if (IS_ERR(vdir))
32266 + allocated = vdir;
32267 + } else if (may_read
32268 + && (!inode_eq_iversion(inode, vdir->vd_version)
32269 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32271 + err = reinit_vdir(vdir);
32272 + if (unlikely(err))
32277 + return 0; /* success */
32281 + err = au_do_read_vdir(&arg);
32283 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32284 + vdir->vd_version = inode_query_iversion(inode);
32285 + vdir->vd_last.ul = 0;
32286 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32288 + au_set_ivdir(inode, allocated);
32289 + } else if (allocated)
32290 + au_vdir_free(allocated);
32296 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32299 + unsigned long ul, n;
32300 + const unsigned int deblk_sz = src->vd_deblk_sz;
32302 + AuDebugOn(tgt->vd_nblk != 1);
32305 + if (tgt->vd_nblk < src->vd_nblk) {
32306 + unsigned char **p;
32308 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32309 + GFP_NOFS, /*may_shrink*/0);
32310 + if (unlikely(!p))
32312 + tgt->vd_deblk = p;
32315 + if (tgt->vd_deblk_sz != deblk_sz) {
32316 + unsigned char *p;
32318 + tgt->vd_deblk_sz = deblk_sz;
32319 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32320 + /*may_shrink*/1);
32321 + if (unlikely(!p))
32323 + tgt->vd_deblk[0] = p;
32325 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32326 + tgt->vd_version = src->vd_version;
32327 + tgt->vd_jiffy = src->vd_jiffy;
32329 + n = src->vd_nblk;
32330 + for (ul = 1; ul < n; ul++) {
32331 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32333 + if (unlikely(!tgt->vd_deblk[ul]))
32337 + tgt->vd_nblk = n;
32338 + tgt->vd_last.ul = tgt->vd_last.ul;
32339 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32340 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32341 + - src->vd_deblk[src->vd_last.ul];
32343 + return 0; /* success */
32346 + rerr = reinit_vdir(tgt);
32351 +int au_vdir_init(struct file *file)
32354 + struct inode *inode;
32355 + struct au_vdir *vdir_cache, *allocated;
32357 + /* test file->f_pos here instead of ctx->pos */
32358 + err = read_vdir(file, !file->f_pos);
32359 + if (unlikely(err))
32362 + allocated = NULL;
32363 + vdir_cache = au_fvdir_cache(file);
32364 + if (!vdir_cache) {
32365 + vdir_cache = alloc_vdir(file);
32366 + err = PTR_ERR(vdir_cache);
32367 + if (IS_ERR(vdir_cache))
32369 + allocated = vdir_cache;
32370 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32371 + /* test file->f_pos here instead of ctx->pos */
32372 + err = reinit_vdir(vdir_cache);
32373 + if (unlikely(err))
32376 + return 0; /* success */
32378 + inode = file_inode(file);
32379 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32381 + file->f_version = inode_query_iversion(inode);
32383 + au_set_fvdir_cache(file, allocated);
32384 + } else if (allocated)
32385 + au_vdir_free(allocated);
32391 +static loff_t calc_offset(struct au_vdir *vdir)
32394 + union au_vdir_deblk_p p;
32396 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32397 + offset = vdir->vd_last.p.deblk - p.deblk;
32398 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32402 +/* returns true or false */
32403 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32406 + unsigned int deblk_sz;
32407 + unsigned long ul, n;
32409 + union au_vdir_deblk_p p, deblk_end;
32410 + struct au_vdir *vdir_cache;
32413 + vdir_cache = au_fvdir_cache(file);
32414 + offset = calc_offset(vdir_cache);
32415 + AuDbg("offset %lld\n", offset);
32416 + if (ctx->pos == offset)
32419 + vdir_cache->vd_last.ul = 0;
32420 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32425 + deblk_sz = vdir_cache->vd_deblk_sz;
32426 + ul = div64_u64(ctx->pos, deblk_sz);
32427 + AuDbg("ul %lu\n", ul);
32428 + if (ul >= vdir_cache->vd_nblk)
32431 + n = vdir_cache->vd_nblk;
32432 + for (; ul < n; ul++) {
32433 + p.deblk = vdir_cache->vd_deblk[ul];
32434 + deblk_end.deblk = p.deblk + deblk_sz;
32436 + offset *= deblk_sz;
32437 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32440 + l = calc_size(p.de->de_str.len);
32444 + if (!is_deblk_end(&p, &deblk_end)) {
32446 + vdir_cache->vd_last.ul = ul;
32447 + vdir_cache->vd_last.p = p;
32455 + AuDbg("valid %d\n", !valid);
32459 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32461 + unsigned int l, deblk_sz;
32462 + union au_vdir_deblk_p deblk_end;
32463 + struct au_vdir *vdir_cache;
32464 + struct au_vdir_de *de;
32466 + vdir_cache = au_fvdir_cache(file);
32467 + if (!seek_vdir(file, ctx))
32470 + deblk_sz = vdir_cache->vd_deblk_sz;
32472 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32473 + deblk_end.deblk += deblk_sz;
32474 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32475 + de = vdir_cache->vd_last.p.de;
32476 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32477 + de->de_str.len, de->de_str.name, ctx->pos,
32478 + (unsigned long)de->de_ino, de->de_type);
32479 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32480 + de->de_str.len, de->de_ino,
32482 + /* todo: ignore the error caused by udba? */
32483 + /* return err; */
32487 + l = calc_size(de->de_str.len);
32488 + vdir_cache->vd_last.p.deblk += l;
32491 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32492 + vdir_cache->vd_last.ul++;
32493 + vdir_cache->vd_last.p.deblk
32494 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32495 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32504 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32505 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32506 +++ linux/fs/aufs/vfsub.c 2018-08-12 23:43:05.463458173 +0200
32508 +// SPDX-License-Identifier: GPL-2.0
32510 + * Copyright (C) 2005-2018 Junjiro R. Okajima
32512 + * This program, aufs is free software; you can redistribute it and/or modify
32513 + * it under the terms of the GNU General Public License as published by
32514 + * the Free Software Foundation; either version 2 of the License, or
32515 + * (at your option) any later version.
32517 + * This program is distributed in the hope that it will be useful,
32518 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32519 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32520 + * GNU General Public License for more details.
32522 + * You should have received a copy of the GNU General Public License
32523 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32527 + * sub-routines for VFS
32530 +#include <linux/mnt_namespace.h>
32531 +#include <linux/namei.h>
32532 +#include <linux/nsproxy.h>
32533 +#include <linux/security.h>
32534 +#include <linux/splice.h>
32537 +#ifdef CONFIG_AUFS_BR_FUSE
32538 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32540 + if (!au_test_fuse(h_sb) || !au_userns)
32543 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32547 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32552 + down_read(&h_sb->s_umount);
32553 + err = __sync_filesystem(h_sb, wait);
32554 + up_read(&h_sb->s_umount);
32560 +/* ---------------------------------------------------------------------- */
32562 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32566 + struct super_block *h_sb;
32568 + /* for remote fs, leave work for its getattr or d_revalidate */
32569 + /* for bad i_attr fs, handle them in aufs_getattr() */
32570 + /* still some fs may acquire i_mutex. we need to skip them */
32574 + h_sb = h_path->dentry->d_sb;
32575 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32577 + err = vfsub_getattr(h_path, &st);
32582 +/* ---------------------------------------------------------------------- */
32584 +struct file *vfsub_dentry_open(struct path *path, int flags)
32586 + struct file *file;
32588 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32590 + if (!IS_ERR_OR_NULL(file)
32591 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
32592 + i_readcount_inc(d_inode(path->dentry));
32597 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32599 + struct file *file;
32602 + file = filp_open(path,
32603 + oflags /* | __FMODE_NONOTIFY */,
32606 + if (IS_ERR(file))
32608 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32615 + * Ideally this function should call VFS:do_last() in order to keep all its
32616 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32617 + * structure such as nameidata. This is a second (or third) best approach.
32618 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32620 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32621 + struct vfsub_aopen_args *args, struct au_branch *br)
32624 + struct file *file = args->file;
32625 + /* copied from linux/fs/namei.c:atomic_open() */
32626 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32629 + AuDebugOn(!dir->i_op->atomic_open);
32631 + err = au_br_test_oflag(args->open_flag, br);
32632 + if (unlikely(err))
32635 + args->file->f_path.dentry = DENTRY_NOT_SET;
32636 + args->file->f_path.mnt = au_br_mnt(br);
32637 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32638 + args->create_mode, args->opened);
32640 + /* some filesystems don't set FILE_CREATED while succeeded? */
32641 + if (*args->opened & FILE_CREATED)
32642 + fsnotify_create(dir, dentry);
32648 + /* todo: call VFS:may_open() here */
32649 + err = open_check_o_direct(file);
32650 + /* todo: ima_file_check() too? */
32651 + if (!err && (args->open_flag & __FMODE_EXEC))
32652 + err = deny_write_access(file);
32653 + if (unlikely(err))
32654 + /* note that the file is created and still opened */
32659 + fsnotify_open(file);
32665 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32669 + err = kern_path(name, flags, path);
32670 + if (!err && d_is_positive(path->dentry))
32671 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32675 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32676 + struct dentry *parent, int len)
32678 + struct path path = {
32682 + path.dentry = lookup_one_len_unlocked(name, parent, len);
32683 + if (IS_ERR(path.dentry))
32685 + if (d_is_positive(path.dentry))
32686 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32689 + AuTraceErrPtr(path.dentry);
32690 + return path.dentry;
32693 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
32696 + struct path path = {
32700 + /* VFS checks it too, but by WARN_ON_ONCE() */
32701 + IMustLock(d_inode(parent));
32703 + path.dentry = lookup_one_len(name, parent, len);
32704 + if (IS_ERR(path.dentry))
32706 + if (d_is_positive(path.dentry))
32707 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32710 + AuTraceErrPtr(path.dentry);
32711 + return path.dentry;
32714 +void vfsub_call_lkup_one(void *args)
32716 + struct vfsub_lkup_one_args *a = args;
32717 + *a->errp = vfsub_lkup_one(a->name, a->parent);
32720 +/* ---------------------------------------------------------------------- */
32722 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32723 + struct dentry *d2, struct au_hinode *hdir2)
32725 + struct dentry *d;
32728 + d = lock_rename(d1, d2);
32730 + au_hn_suspend(hdir1);
32731 + if (hdir1 != hdir2)
32732 + au_hn_suspend(hdir2);
32737 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32738 + struct dentry *d2, struct au_hinode *hdir2)
32740 + au_hn_resume(hdir1);
32741 + if (hdir1 != hdir2)
32742 + au_hn_resume(hdir2);
32744 + unlock_rename(d1, d2);
32748 +/* ---------------------------------------------------------------------- */
32750 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32753 + struct dentry *d;
32757 + d = path->dentry;
32758 + path->dentry = d->d_parent;
32759 + err = security_path_mknod(path, d, mode, 0);
32760 + path->dentry = d;
32761 + if (unlikely(err))
32765 + err = vfs_create(dir, path->dentry, mode, want_excl);
32768 + struct path tmp = *path;
32771 + vfsub_update_h_iattr(&tmp, &did);
32773 + tmp.dentry = path->dentry->d_parent;
32774 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32783 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
32786 + struct dentry *d;
32790 + d = path->dentry;
32791 + path->dentry = d->d_parent;
32792 + err = security_path_symlink(path, d, symname);
32793 + path->dentry = d;
32794 + if (unlikely(err))
32798 + err = vfs_symlink(dir, path->dentry, symname);
32801 + struct path tmp = *path;
32804 + vfsub_update_h_iattr(&tmp, &did);
32806 + tmp.dentry = path->dentry->d_parent;
32807 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32816 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
32819 + struct dentry *d;
32823 + d = path->dentry;
32824 + path->dentry = d->d_parent;
32825 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
32826 + path->dentry = d;
32827 + if (unlikely(err))
32831 + err = vfs_mknod(dir, path->dentry, mode, dev);
32834 + struct path tmp = *path;
32837 + vfsub_update_h_iattr(&tmp, &did);
32839 + tmp.dentry = path->dentry->d_parent;
32840 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32849 +static int au_test_nlink(struct inode *inode)
32851 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
32853 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
32854 + || inode->i_nlink < link_max)
32859 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
32860 + struct inode **delegated_inode)
32863 + struct dentry *d;
32867 + err = au_test_nlink(d_inode(src_dentry));
32868 + if (unlikely(err))
32871 + /* we don't call may_linkat() */
32872 + d = path->dentry;
32873 + path->dentry = d->d_parent;
32874 + err = security_path_link(src_dentry, path, d);
32875 + path->dentry = d;
32876 + if (unlikely(err))
32880 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
32883 + struct path tmp = *path;
32886 + /* fuse has different memory inode for the same inumber */
32887 + vfsub_update_h_iattr(&tmp, &did);
32889 + tmp.dentry = path->dentry->d_parent;
32890 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32891 + tmp.dentry = src_dentry;
32892 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32901 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
32902 + struct inode *dir, struct path *path,
32903 + struct inode **delegated_inode, unsigned int flags)
32906 + struct path tmp = {
32909 + struct dentry *d;
32912 + IMustLock(src_dir);
32914 + d = path->dentry;
32915 + path->dentry = d->d_parent;
32916 + tmp.dentry = src_dentry->d_parent;
32917 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
32918 + path->dentry = d;
32919 + if (unlikely(err))
32923 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
32924 + delegated_inode, flags);
32929 + tmp.dentry = d->d_parent;
32930 + vfsub_update_h_iattr(&tmp, &did);
32932 + tmp.dentry = src_dentry;
32933 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32934 + tmp.dentry = src_dentry->d_parent;
32935 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32944 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
32947 + struct dentry *d;
32951 + d = path->dentry;
32952 + path->dentry = d->d_parent;
32953 + err = security_path_mkdir(path, d, mode);
32954 + path->dentry = d;
32955 + if (unlikely(err))
32959 + err = vfs_mkdir(dir, path->dentry, mode);
32962 + struct path tmp = *path;
32965 + vfsub_update_h_iattr(&tmp, &did);
32967 + tmp.dentry = path->dentry->d_parent;
32968 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32977 +int vfsub_rmdir(struct inode *dir, struct path *path)
32980 + struct dentry *d;
32984 + d = path->dentry;
32985 + path->dentry = d->d_parent;
32986 + err = security_path_rmdir(path, d);
32987 + path->dentry = d;
32988 + if (unlikely(err))
32992 + err = vfs_rmdir(dir, path->dentry);
32995 + struct path tmp = {
32996 + .dentry = path->dentry->d_parent,
33000 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33007 +/* ---------------------------------------------------------------------- */
33009 +/* todo: support mmap_sem? */
33010 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33016 + err = vfs_read(file, ubuf, count, ppos);
33019 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33023 +/* todo: kernel_read()? */
33024 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33028 + mm_segment_t oldfs;
33035 + oldfs = get_fs();
33036 + set_fs(KERNEL_DS);
33037 + err = vfsub_read_u(file, buf.u, count, ppos);
33042 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33048 + err = vfs_write(file, ubuf, count, ppos);
33051 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33055 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33058 + mm_segment_t oldfs;
33061 + const char __user *u;
33065 + oldfs = get_fs();
33066 + set_fs(KERNEL_DS);
33067 + err = vfsub_write_u(file, buf.u, count, ppos);
33072 +int vfsub_flush(struct file *file, fl_owner_t id)
33077 + if (file->f_op->flush) {
33078 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33079 + err = file->f_op->flush(file, id);
33082 + err = file->f_op->flush(file, id);
33086 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33092 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33096 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33099 + err = iterate_dir(file, ctx);
33102 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33107 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33108 + struct pipe_inode_info *pipe, size_t len,
33109 + unsigned int flags)
33114 + err = do_splice_to(in, ppos, pipe, len, flags);
33116 + file_accessed(in);
33118 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33122 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33123 + loff_t *ppos, size_t len, unsigned int flags)
33128 + err = do_splice_from(pipe, out, ppos, len, flags);
33131 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33135 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33139 + /* file can be NULL */
33141 + err = vfs_fsync(file, datasync);
33145 + AuDebugOn(!file);
33146 + path = &file->f_path;
33148 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33153 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33154 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33155 + struct file *h_file)
33158 + struct inode *h_inode;
33159 + struct super_block *h_sb;
33162 + err = vfsub_truncate(h_path, length);
33166 + h_inode = d_inode(h_path->dentry);
33167 + h_sb = h_inode->i_sb;
33169 + sb_start_write(h_sb);
33171 + err = locks_verify_truncate(h_inode, h_file, length);
33173 + err = security_path_truncate(h_path);
33176 + err = do_truncate(h_path->dentry, length, attr, h_file);
33180 + sb_end_write(h_sb);
33187 +/* ---------------------------------------------------------------------- */
33189 +struct au_vfsub_mkdir_args {
33191 + struct inode *dir;
33192 + struct path *path;
33196 +static void au_call_vfsub_mkdir(void *args)
33198 + struct au_vfsub_mkdir_args *a = args;
33199 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33202 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33204 + int err, do_sio, wkq_err;
33206 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33209 + err = vfsub_mkdir(dir, path, mode);
33212 + struct au_vfsub_mkdir_args args = {
33218 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33219 + if (unlikely(wkq_err))
33226 +struct au_vfsub_rmdir_args {
33228 + struct inode *dir;
33229 + struct path *path;
33232 +static void au_call_vfsub_rmdir(void *args)
33234 + struct au_vfsub_rmdir_args *a = args;
33235 + *a->errp = vfsub_rmdir(a->dir, a->path);
33238 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33240 + int err, do_sio, wkq_err;
33242 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33245 + err = vfsub_rmdir(dir, path);
33248 + struct au_vfsub_rmdir_args args = {
33253 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33254 + if (unlikely(wkq_err))
33261 +/* ---------------------------------------------------------------------- */
33263 +struct notify_change_args {
33265 + struct path *path;
33266 + struct iattr *ia;
33267 + struct inode **delegated_inode;
33270 +static void call_notify_change(void *args)
33272 + struct notify_change_args *a = args;
33273 + struct inode *h_inode;
33275 + h_inode = d_inode(a->path->dentry);
33276 + IMustLock(h_inode);
33278 + *a->errp = -EPERM;
33279 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33281 + *a->errp = notify_change(a->path->dentry, a->ia,
33282 + a->delegated_inode);
33285 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33287 + AuTraceErr(*a->errp);
33290 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33291 + struct inode **delegated_inode)
33294 + struct notify_change_args args = {
33298 + .delegated_inode = delegated_inode
33301 + call_notify_change(&args);
33306 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33307 + struct inode **delegated_inode)
33309 + int err, wkq_err;
33310 + struct notify_change_args args = {
33314 + .delegated_inode = delegated_inode
33317 + wkq_err = au_wkq_wait(call_notify_change, &args);
33318 + if (unlikely(wkq_err))
33324 +/* ---------------------------------------------------------------------- */
33326 +struct unlink_args {
33328 + struct inode *dir;
33329 + struct path *path;
33330 + struct inode **delegated_inode;
33333 +static void call_unlink(void *args)
33335 + struct unlink_args *a = args;
33336 + struct dentry *d = a->path->dentry;
33337 + struct inode *h_inode;
33338 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33339 + && au_dcount(d) == 1);
33341 + IMustLock(a->dir);
33343 + a->path->dentry = d->d_parent;
33344 + *a->errp = security_path_unlink(a->path, d);
33345 + a->path->dentry = d;
33346 + if (unlikely(*a->errp))
33349 + if (!stop_sillyrename)
33352 + if (d_is_positive(d)) {
33353 + h_inode = d_inode(d);
33358 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33361 + struct path tmp = {
33362 + .dentry = d->d_parent,
33363 + .mnt = a->path->mnt
33365 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33368 + if (!stop_sillyrename)
33373 + AuTraceErr(*a->errp);
33377 + * @dir: must be locked.
33378 + * @dentry: target dentry.
33380 +int vfsub_unlink(struct inode *dir, struct path *path,
33381 + struct inode **delegated_inode, int force)
33384 + struct unlink_args args = {
33388 + .delegated_inode = delegated_inode
33392 + call_unlink(&args);
33396 + wkq_err = au_wkq_wait(call_unlink, &args);
33397 + if (unlikely(wkq_err))
33403 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33404 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33405 +++ linux/fs/aufs/vfsub.h 2018-08-12 23:43:05.463458173 +0200
33407 +/* SPDX-License-Identifier: GPL-2.0 */
33409 + * Copyright (C) 2005-2018 Junjiro R. Okajima
33411 + * This program, aufs is free software; you can redistribute it and/or modify
33412 + * it under the terms of the GNU General Public License as published by
33413 + * the Free Software Foundation; either version 2 of the License, or
33414 + * (at your option) any later version.
33416 + * This program is distributed in the hope that it will be useful,
33417 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33418 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33419 + * GNU General Public License for more details.
33421 + * You should have received a copy of the GNU General Public License
33422 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33426 + * sub-routines for VFS
33429 +#ifndef __AUFS_VFSUB_H__
33430 +#define __AUFS_VFSUB_H__
33434 +#include <linux/fs.h>
33435 +#include <linux/iversion.h>
33436 +#include <linux/mount.h>
33437 +#include <linux/posix_acl.h>
33438 +#include <linux/xattr.h>
33439 +#include "debug.h"
33441 +/* copied from linux/fs/internal.h */
33442 +/* todo: BAD approach!! */
33443 +extern void __mnt_drop_write(struct vfsmount *);
33444 +extern int open_check_o_direct(struct file *f);
33446 +/* ---------------------------------------------------------------------- */
33448 +/* lock subclass for lower inode */
33449 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33450 +/* reduce? gave up. */
33452 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33453 + AuLsc_I_PARENT, /* lower inode, parent first */
33454 + AuLsc_I_PARENT2, /* copyup dirs */
33455 + AuLsc_I_PARENT3, /* copyup wh */
33461 +/* to debug easier, do not make them inlined functions */
33462 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33463 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33465 +/* ---------------------------------------------------------------------- */
33467 +static inline void vfsub_drop_nlink(struct inode *inode)
33469 + AuDebugOn(!inode->i_nlink);
33470 + drop_nlink(inode);
33473 +static inline void vfsub_dead_dir(struct inode *inode)
33475 + AuDebugOn(!S_ISDIR(inode->i_mode));
33476 + inode->i_flags |= S_DEAD;
33477 + clear_nlink(inode);
33480 +static inline int vfsub_native_ro(struct inode *inode)
33482 + return sb_rdonly(inode->i_sb)
33483 + || IS_RDONLY(inode)
33484 + /* || IS_APPEND(inode) */
33485 + || IS_IMMUTABLE(inode);
33488 +#ifdef CONFIG_AUFS_BR_FUSE
33489 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33491 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33494 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33496 +/* ---------------------------------------------------------------------- */
33498 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33499 +struct file *vfsub_dentry_open(struct path *path, int flags);
33500 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33501 +struct vfsub_aopen_args {
33502 + struct file *file;
33503 + unsigned int open_flag;
33504 + umode_t create_mode;
33508 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33509 + struct vfsub_aopen_args *args, struct au_branch *br);
33510 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33512 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33513 + struct dentry *parent, int len);
33514 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33517 +struct vfsub_lkup_one_args {
33518 + struct dentry **errp;
33519 + struct qstr *name;
33520 + struct dentry *parent;
33523 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33524 + struct dentry *parent)
33526 + return vfsub_lookup_one_len(name->name, parent, name->len);
33529 +void vfsub_call_lkup_one(void *args);
33531 +/* ---------------------------------------------------------------------- */
33533 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33538 + err = mnt_want_write(mnt);
33543 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33546 + mnt_drop_write(mnt);
33550 +#if 0 /* reserved */
33551 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33554 + mnt_drop_write_file(file);
33559 +/* ---------------------------------------------------------------------- */
33562 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33563 + struct dentry *d2, struct au_hinode *hdir2);
33564 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33565 + struct dentry *d2, struct au_hinode *hdir2);
33567 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33569 +int vfsub_symlink(struct inode *dir, struct path *path,
33570 + const char *symname);
33571 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33572 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33573 + struct path *path, struct inode **delegated_inode);
33574 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33575 + struct inode *hdir, struct path *path,
33576 + struct inode **delegated_inode, unsigned int flags);
33577 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33578 +int vfsub_rmdir(struct inode *dir, struct path *path);
33580 +/* ---------------------------------------------------------------------- */
33582 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33584 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33586 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33588 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33590 +int vfsub_flush(struct file *file, fl_owner_t id);
33591 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33593 +static inline loff_t vfsub_f_size_read(struct file *file)
33595 + return i_size_read(file_inode(file));
33598 +static inline unsigned int vfsub_file_flags(struct file *file)
33600 + unsigned int flags;
33602 + spin_lock(&file->f_lock);
33603 + flags = file->f_flags;
33604 + spin_unlock(&file->f_lock);
33609 +static inline int vfsub_file_execed(struct file *file)
33611 + /* todo: direct access f_flags */
33612 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33615 +#if 0 /* reserved */
33616 +static inline void vfsub_file_accessed(struct file *h_file)
33618 + file_accessed(h_file);
33619 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33623 +#if 0 /* reserved */
33624 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33625 + struct dentry *h_dentry)
33627 + struct path h_path = {
33628 + .dentry = h_dentry,
33631 + touch_atime(&h_path);
33632 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33636 +static inline int vfsub_update_time(struct inode *h_inode,
33637 + struct timespec64 *ts, int flags)
33639 + return update_time(h_inode, ts, flags);
33640 + /* no vfsub_update_h_iattr() since we don't have struct path */
33643 +#ifdef CONFIG_FS_POSIX_ACL
33644 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33648 + err = posix_acl_chmod(h_inode, h_mode);
33649 + if (err == -EOPNOTSUPP)
33654 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33657 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33658 + struct pipe_inode_info *pipe, size_t len,
33659 + unsigned int flags);
33660 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33661 + loff_t *ppos, size_t len, unsigned int flags);
33663 +static inline long vfsub_truncate(struct path *path, loff_t length)
33668 + err = vfs_truncate(path, length);
33673 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33674 + struct file *h_file);
33675 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33678 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33681 +static inline int vfsub_clone_file_range(struct file *src, struct file *dst,
33687 + err = vfs_clone_file_range(src, 0, dst, 0, len);
33693 +/* copy_file_range(2) is a systemcall */
33694 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33695 + struct file *dst, loff_t dst_pos,
33696 + size_t len, unsigned int flags)
33701 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33707 +/* ---------------------------------------------------------------------- */
33709 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33714 + err = vfs_llseek(file, offset, origin);
33719 +/* ---------------------------------------------------------------------- */
33721 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33722 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33723 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33724 + struct inode **delegated_inode);
33725 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33726 + struct inode **delegated_inode);
33727 +int vfsub_unlink(struct inode *dir, struct path *path,
33728 + struct inode **delegated_inode, int force);
33730 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
33732 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
33735 +/* ---------------------------------------------------------------------- */
33737 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
33738 + const void *value, size_t size, int flags)
33743 + err = vfs_setxattr(dentry, name, value, size, flags);
33749 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
33754 + err = vfs_removexattr(dentry, name);
33760 +#endif /* __KERNEL__ */
33761 +#endif /* __AUFS_VFSUB_H__ */
33762 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
33763 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
33764 +++ linux/fs/aufs/wbr_policy.c 2018-08-12 23:43:05.463458173 +0200
33766 +// SPDX-License-Identifier: GPL-2.0
33768 + * Copyright (C) 2005-2018 Junjiro R. Okajima
33770 + * This program, aufs is free software; you can redistribute it and/or modify
33771 + * it under the terms of the GNU General Public License as published by
33772 + * the Free Software Foundation; either version 2 of the License, or
33773 + * (at your option) any later version.
33775 + * This program is distributed in the hope that it will be useful,
33776 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33777 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33778 + * GNU General Public License for more details.
33780 + * You should have received a copy of the GNU General Public License
33781 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33785 + * policies for selecting one among multiple writable branches
33788 +#include <linux/statfs.h>
33791 +/* subset of cpup_attr() */
33792 +static noinline_for_stack
33793 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
33797 + struct inode *h_isrc;
33799 + h_isrc = d_inode(h_src);
33800 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
33801 + ia.ia_mode = h_isrc->i_mode;
33802 + ia.ia_uid = h_isrc->i_uid;
33803 + ia.ia_gid = h_isrc->i_gid;
33804 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
33805 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
33806 + /* no delegation since it is just created */
33807 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33809 + /* is this nfs only? */
33810 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
33811 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
33812 + ia.ia_mode = h_isrc->i_mode;
33813 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33819 +#define AuCpdown_PARENT_OPQ 1
33820 +#define AuCpdown_WHED (1 << 1)
33821 +#define AuCpdown_MADE_DIR (1 << 2)
33822 +#define AuCpdown_DIROPQ (1 << 3)
33823 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
33824 +#define au_fset_cpdown(flags, name) \
33825 + do { (flags) |= AuCpdown_##name; } while (0)
33826 +#define au_fclr_cpdown(flags, name) \
33827 + do { (flags) &= ~AuCpdown_##name; } while (0)
33829 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
33830 + unsigned int *flags)
33833 + struct dentry *opq_dentry;
33835 + opq_dentry = au_diropq_create(dentry, bdst);
33836 + err = PTR_ERR(opq_dentry);
33837 + if (IS_ERR(opq_dentry))
33839 + dput(opq_dentry);
33840 + au_fset_cpdown(*flags, DIROPQ);
33846 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
33847 + struct inode *dir, aufs_bindex_t bdst)
33850 + struct path h_path;
33851 + struct au_branch *br;
33853 + br = au_sbr(dentry->d_sb, bdst);
33854 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
33855 + err = PTR_ERR(h_path.dentry);
33856 + if (IS_ERR(h_path.dentry))
33860 + if (d_is_positive(h_path.dentry)) {
33861 + h_path.mnt = au_br_mnt(br);
33862 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
33865 + dput(h_path.dentry);
33871 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
33872 + struct au_pin *pin,
33873 + struct dentry *h_parent, void *arg)
33876 + aufs_bindex_t bopq, btop;
33877 + struct path h_path;
33878 + struct dentry *parent;
33879 + struct inode *h_dir, *h_inode, *inode, *dir;
33880 + unsigned int *flags = arg;
33882 + btop = au_dbtop(dentry);
33883 + /* dentry is di-locked */
33884 + parent = dget_parent(dentry);
33885 + dir = d_inode(parent);
33886 + h_dir = d_inode(h_parent);
33887 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
33888 + IMustLock(h_dir);
33890 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
33891 + if (unlikely(err < 0))
33893 + h_path.dentry = au_h_dptr(dentry, bdst);
33894 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
33895 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
33896 + if (unlikely(err))
33898 + au_fset_cpdown(*flags, MADE_DIR);
33900 + bopq = au_dbdiropq(dentry);
33901 + au_fclr_cpdown(*flags, WHED);
33902 + au_fclr_cpdown(*flags, DIROPQ);
33903 + if (au_dbwh(dentry) == bdst)
33904 + au_fset_cpdown(*flags, WHED);
33905 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
33906 + au_fset_cpdown(*flags, PARENT_OPQ);
33907 + h_inode = d_inode(h_path.dentry);
33908 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
33909 + if (au_ftest_cpdown(*flags, WHED)) {
33910 + err = au_cpdown_dir_opq(dentry, bdst, flags);
33911 + if (unlikely(err)) {
33912 + inode_unlock(h_inode);
33917 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
33918 + inode_unlock(h_inode);
33919 + if (unlikely(err))
33922 + if (au_ftest_cpdown(*flags, WHED)) {
33923 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
33924 + if (unlikely(err))
33928 + inode = d_inode(dentry);
33929 + if (au_ibbot(inode) < bdst)
33930 + au_set_ibbot(inode, bdst);
33931 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
33932 + au_hi_flags(inode, /*isdir*/1));
33933 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
33934 + goto out; /* success */
33938 + if (au_ftest_cpdown(*flags, DIROPQ)) {
33939 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
33940 + rerr = au_diropq_remove(dentry, bdst);
33941 + inode_unlock(h_inode);
33942 + if (unlikely(rerr)) {
33943 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
33944 + dentry, bdst, rerr);
33950 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
33951 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
33952 + if (unlikely(rerr)) {
33953 + AuIOErr("failed removing %pd b%d (%d)\n",
33954 + dentry, bdst, rerr);
33959 + au_set_h_dptr(dentry, bdst, NULL);
33960 + if (au_dbbot(dentry) == bdst)
33961 + au_update_dbbot(dentry);
33967 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
33970 + unsigned int flags;
33973 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
33978 +/* ---------------------------------------------------------------------- */
33980 +/* policies for create */
33982 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
33984 + int err, i, j, ndentry;
33985 + aufs_bindex_t bopq;
33986 + struct au_dcsub_pages dpages;
33987 + struct au_dpage *dpage;
33988 + struct dentry **dentries, *parent, *d;
33990 + err = au_dpages_init(&dpages, GFP_NOFS);
33991 + if (unlikely(err))
33993 + parent = dget_parent(dentry);
33994 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
33995 + if (unlikely(err))
33999 + for (i = 0; i < dpages.ndpage; i++) {
34000 + dpage = dpages.dpages + i;
34001 + dentries = dpage->dentries;
34002 + ndentry = dpage->ndentry;
34003 + for (j = 0; j < ndentry; j++) {
34005 + di_read_lock_parent2(d, !AuLock_IR);
34006 + bopq = au_dbdiropq(d);
34007 + di_read_unlock(d, !AuLock_IR);
34008 + if (bopq >= 0 && bopq < err)
34015 + au_dpages_free(&dpages);
34020 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34022 + for (; bindex >= 0; bindex--)
34023 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34028 +/* top down parent */
34029 +static int au_wbr_create_tdp(struct dentry *dentry,
34030 + unsigned int flags __maybe_unused)
34033 + aufs_bindex_t btop, bindex;
34034 + struct super_block *sb;
34035 + struct dentry *parent, *h_parent;
34037 + sb = dentry->d_sb;
34038 + btop = au_dbtop(dentry);
34040 + if (!au_br_rdonly(au_sbr(sb, btop)))
34044 + parent = dget_parent(dentry);
34045 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34046 + h_parent = au_h_dptr(parent, bindex);
34047 + if (!h_parent || d_is_negative(h_parent))
34050 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34057 + /* bottom up here */
34058 + if (unlikely(err < 0)) {
34059 + err = au_wbr_bu(sb, btop - 1);
34061 + err = au_wbr_nonopq(dentry, err);
34065 + AuDbg("b%d\n", err);
34069 +/* ---------------------------------------------------------------------- */
34071 +/* an exception for the policy other than tdp */
34072 +static int au_wbr_create_exp(struct dentry *dentry)
34075 + aufs_bindex_t bwh, bdiropq;
34076 + struct dentry *parent;
34079 + bwh = au_dbwh(dentry);
34080 + parent = dget_parent(dentry);
34081 + bdiropq = au_dbdiropq(parent);
34083 + if (bdiropq >= 0)
34084 + err = min(bdiropq, bwh);
34087 + AuDbg("%d\n", err);
34088 + } else if (bdiropq >= 0) {
34090 + AuDbg("%d\n", err);
34095 + err = au_wbr_nonopq(dentry, err);
34097 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34100 + AuDbg("%d\n", err);
34104 +/* ---------------------------------------------------------------------- */
34107 +static int au_wbr_create_init_rr(struct super_block *sb)
34111 + err = au_wbr_bu(sb, au_sbbot(sb));
34112 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34115 + AuDbg("b%d\n", err);
34119 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34123 + aufs_bindex_t bindex, bbot;
34124 + struct super_block *sb;
34127 + err = au_wbr_create_exp(dentry);
34131 + sb = dentry->d_sb;
34132 + next = &au_sbi(sb)->si_wbr_rr_next;
34133 + bbot = au_sbbot(sb);
34135 + for (bindex = 0; bindex <= bbot; bindex++) {
34136 + if (!au_ftest_wbr(flags, DIR)) {
34137 + err = atomic_dec_return(next) + 1;
34138 + /* modulo for 0 is meaningless */
34139 + if (unlikely(!err))
34140 + err = atomic_dec_return(next) + 1;
34142 + err = atomic_read(next);
34143 + AuDbg("%d\n", err);
34146 + AuDbg("%d\n", err);
34147 + if (!au_br_rdonly(au_sbr(sb, err)))
34153 + err = au_wbr_nonopq(dentry, err);
34156 + AuDbg("%d\n", err);
34160 +/* ---------------------------------------------------------------------- */
34162 +/* most free space */
34163 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34165 + struct super_block *sb;
34166 + struct au_branch *br;
34167 + struct au_wbr_mfs *mfs;
34168 + struct dentry *h_parent;
34169 + aufs_bindex_t bindex, bbot;
34171 + unsigned long long b, bavail;
34172 + struct path h_path;
34173 + /* reduce the stack usage */
34174 + struct kstatfs *st;
34176 + st = kmalloc(sizeof(*st), GFP_NOFS);
34177 + if (unlikely(!st)) {
34178 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34183 + sb = dentry->d_sb;
34184 + mfs = &au_sbi(sb)->si_wbr_mfs;
34185 + MtxMustLock(&mfs->mfs_lock);
34186 + mfs->mfs_bindex = -EROFS;
34187 + mfs->mfsrr_bytes = 0;
34190 + bbot = au_sbbot(sb);
34192 + bindex = au_dbtop(parent);
34193 + bbot = au_dbtaildir(parent);
34196 + for (; bindex <= bbot; bindex++) {
34198 + h_parent = au_h_dptr(parent, bindex);
34199 + if (!h_parent || d_is_negative(h_parent))
34202 + br = au_sbr(sb, bindex);
34203 + if (au_br_rdonly(br))
34206 + /* sb->s_root for NFS is unreliable */
34207 + h_path.mnt = au_br_mnt(br);
34208 + h_path.dentry = h_path.mnt->mnt_root;
34209 + err = vfs_statfs(&h_path, st);
34210 + if (unlikely(err)) {
34211 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34215 + /* when the available size is equal, select the lower one */
34216 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34217 + || sizeof(b) < sizeof(st->f_bsize));
34218 + b = st->f_bavail * st->f_bsize;
34219 + br->br_wbr->wbr_bytes = b;
34220 + if (b >= bavail) {
34222 + mfs->mfs_bindex = bindex;
34223 + mfs->mfs_jiffy = jiffies;
34227 + mfs->mfsrr_bytes = bavail;
34228 + AuDbg("b%d\n", mfs->mfs_bindex);
34232 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34235 + struct dentry *parent;
34236 + struct super_block *sb;
34237 + struct au_wbr_mfs *mfs;
34239 + err = au_wbr_create_exp(dentry);
34243 + sb = dentry->d_sb;
34245 + if (au_ftest_wbr(flags, PARENT))
34246 + parent = dget_parent(dentry);
34247 + mfs = &au_sbi(sb)->si_wbr_mfs;
34248 + mutex_lock(&mfs->mfs_lock);
34249 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34250 + || mfs->mfs_bindex < 0
34251 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34252 + au_mfs(dentry, parent);
34253 + mutex_unlock(&mfs->mfs_lock);
34254 + err = mfs->mfs_bindex;
34258 + err = au_wbr_nonopq(dentry, err);
34261 + AuDbg("b%d\n", err);
34265 +static int au_wbr_create_init_mfs(struct super_block *sb)
34267 + struct au_wbr_mfs *mfs;
34269 + mfs = &au_sbi(sb)->si_wbr_mfs;
34270 + mutex_init(&mfs->mfs_lock);
34271 + mfs->mfs_jiffy = 0;
34272 + mfs->mfs_bindex = -EROFS;
34277 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34279 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34283 +/* ---------------------------------------------------------------------- */
34285 +/* top down regardless parent, and then mfs */
34286 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34287 + unsigned int flags __maybe_unused)
34290 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34291 + unsigned long long watermark;
34292 + struct super_block *sb;
34293 + struct au_wbr_mfs *mfs;
34294 + struct au_branch *br;
34295 + struct dentry *parent;
34297 + sb = dentry->d_sb;
34298 + mfs = &au_sbi(sb)->si_wbr_mfs;
34299 + mutex_lock(&mfs->mfs_lock);
34300 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34301 + || mfs->mfs_bindex < 0)
34302 + au_mfs(dentry, /*parent*/NULL);
34303 + watermark = mfs->mfsrr_watermark;
34304 + bmfs = mfs->mfs_bindex;
34305 + mutex_unlock(&mfs->mfs_lock);
34307 + /* another style of au_wbr_create_exp() */
34308 + bwh = au_dbwh(dentry);
34309 + parent = dget_parent(dentry);
34310 + btail = au_dbtaildir(parent);
34311 + if (bwh >= 0 && bwh < btail)
34314 + err = au_wbr_nonopq(dentry, btail);
34315 + if (unlikely(err < 0))
34319 + for (bindex = 0; bindex <= btail; bindex++) {
34320 + br = au_sbr(sb, bindex);
34321 + if (au_br_rdonly(br))
34323 + if (br->br_wbr->wbr_bytes > watermark) {
34334 + AuDbg("b%d\n", err);
34338 +/* ---------------------------------------------------------------------- */
34340 +/* most free space and then round robin */
34341 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34344 + struct au_wbr_mfs *mfs;
34346 + err = au_wbr_create_mfs(dentry, flags);
34348 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34349 + mutex_lock(&mfs->mfs_lock);
34350 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34351 + err = au_wbr_create_rr(dentry, flags);
34352 + mutex_unlock(&mfs->mfs_lock);
34355 + AuDbg("b%d\n", err);
34359 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34363 + au_wbr_create_init_mfs(sb); /* ignore */
34364 + err = au_wbr_create_init_rr(sb);
34369 +/* ---------------------------------------------------------------------- */
34371 +/* top down parent and most free space */
34372 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34375 + unsigned long long b;
34376 + aufs_bindex_t bindex, btop, bbot;
34377 + struct super_block *sb;
34378 + struct dentry *parent, *h_parent;
34379 + struct au_branch *br;
34381 + err = au_wbr_create_tdp(dentry, flags);
34382 + if (unlikely(err < 0))
34384 + parent = dget_parent(dentry);
34385 + btop = au_dbtop(parent);
34386 + bbot = au_dbtaildir(parent);
34387 + if (btop == bbot)
34388 + goto out_parent; /* success */
34390 + e2 = au_wbr_create_mfs(dentry, flags);
34392 + goto out_parent; /* success */
34394 + /* when the available size is equal, select upper one */
34395 + sb = dentry->d_sb;
34396 + br = au_sbr(sb, err);
34397 + b = br->br_wbr->wbr_bytes;
34398 + AuDbg("b%d, %llu\n", err, b);
34400 + for (bindex = btop; bindex <= bbot; bindex++) {
34401 + h_parent = au_h_dptr(parent, bindex);
34402 + if (!h_parent || d_is_negative(h_parent))
34405 + br = au_sbr(sb, bindex);
34406 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34407 + b = br->br_wbr->wbr_bytes;
34409 + AuDbg("b%d, %llu\n", err, b);
34414 + err = au_wbr_nonopq(dentry, err);
34419 + AuDbg("b%d\n", err);
34423 +/* ---------------------------------------------------------------------- */
34426 + * - top down parent
34427 + * - most free space with parent
34428 + * - most free space round-robin regardless parent
34430 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34433 + unsigned long long watermark;
34434 + struct super_block *sb;
34435 + struct au_branch *br;
34436 + struct au_wbr_mfs *mfs;
34438 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34439 + if (unlikely(err < 0))
34442 + sb = dentry->d_sb;
34443 + br = au_sbr(sb, err);
34444 + mfs = &au_sbi(sb)->si_wbr_mfs;
34445 + mutex_lock(&mfs->mfs_lock);
34446 + watermark = mfs->mfsrr_watermark;
34447 + mutex_unlock(&mfs->mfs_lock);
34448 + if (br->br_wbr->wbr_bytes < watermark)
34449 + /* regardless the parent dir */
34450 + err = au_wbr_create_mfsrr(dentry, flags);
34453 + AuDbg("b%d\n", err);
34457 +/* ---------------------------------------------------------------------- */
34459 +/* policies for copyup */
34461 +/* top down parent */
34462 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34464 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34467 +/* bottom up parent */
34468 +static int au_wbr_copyup_bup(struct dentry *dentry)
34471 + aufs_bindex_t bindex, btop;
34472 + struct dentry *parent, *h_parent;
34473 + struct super_block *sb;
34476 + sb = dentry->d_sb;
34477 + parent = dget_parent(dentry);
34478 + btop = au_dbtop(parent);
34479 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34480 + h_parent = au_h_dptr(parent, bindex);
34481 + if (!h_parent || d_is_negative(h_parent))
34484 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34491 + /* bottom up here */
34492 + if (unlikely(err < 0))
34493 + err = au_wbr_bu(sb, btop - 1);
34495 + AuDbg("b%d\n", err);
34500 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34504 + err = au_wbr_bu(dentry->d_sb, btop);
34505 + AuDbg("b%d\n", err);
34507 + err = au_wbr_nonopq(dentry, err);
34509 + AuDbg("b%d\n", err);
34513 +static int au_wbr_copyup_bu(struct dentry *dentry)
34516 + aufs_bindex_t btop;
34518 + btop = au_dbtop(dentry);
34519 + err = au_wbr_do_copyup_bu(dentry, btop);
34523 +/* ---------------------------------------------------------------------- */
34525 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34526 + [AuWbrCopyup_TDP] = {
34527 + .copyup = au_wbr_copyup_tdp
34529 + [AuWbrCopyup_BUP] = {
34530 + .copyup = au_wbr_copyup_bup
34532 + [AuWbrCopyup_BU] = {
34533 + .copyup = au_wbr_copyup_bu
34537 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34538 + [AuWbrCreate_TDP] = {
34539 + .create = au_wbr_create_tdp
34541 + [AuWbrCreate_RR] = {
34542 + .create = au_wbr_create_rr,
34543 + .init = au_wbr_create_init_rr
34545 + [AuWbrCreate_MFS] = {
34546 + .create = au_wbr_create_mfs,
34547 + .init = au_wbr_create_init_mfs,
34548 + .fin = au_wbr_create_fin_mfs
34550 + [AuWbrCreate_MFSV] = {
34551 + .create = au_wbr_create_mfs,
34552 + .init = au_wbr_create_init_mfs,
34553 + .fin = au_wbr_create_fin_mfs
34555 + [AuWbrCreate_MFSRR] = {
34556 + .create = au_wbr_create_mfsrr,
34557 + .init = au_wbr_create_init_mfsrr,
34558 + .fin = au_wbr_create_fin_mfs
34560 + [AuWbrCreate_MFSRRV] = {
34561 + .create = au_wbr_create_mfsrr,
34562 + .init = au_wbr_create_init_mfsrr,
34563 + .fin = au_wbr_create_fin_mfs
34565 + [AuWbrCreate_TDMFS] = {
34566 + .create = au_wbr_create_tdmfs,
34567 + .init = au_wbr_create_init_mfs,
34568 + .fin = au_wbr_create_fin_mfs
34570 + [AuWbrCreate_TDMFSV] = {
34571 + .create = au_wbr_create_tdmfs,
34572 + .init = au_wbr_create_init_mfs,
34573 + .fin = au_wbr_create_fin_mfs
34575 + [AuWbrCreate_PMFS] = {
34576 + .create = au_wbr_create_pmfs,
34577 + .init = au_wbr_create_init_mfs,
34578 + .fin = au_wbr_create_fin_mfs
34580 + [AuWbrCreate_PMFSV] = {
34581 + .create = au_wbr_create_pmfs,
34582 + .init = au_wbr_create_init_mfs,
34583 + .fin = au_wbr_create_fin_mfs
34585 + [AuWbrCreate_PMFSRR] = {
34586 + .create = au_wbr_create_pmfsrr,
34587 + .init = au_wbr_create_init_mfsrr,
34588 + .fin = au_wbr_create_fin_mfs
34590 + [AuWbrCreate_PMFSRRV] = {
34591 + .create = au_wbr_create_pmfsrr,
34592 + .init = au_wbr_create_init_mfsrr,
34593 + .fin = au_wbr_create_fin_mfs
34596 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34597 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34598 +++ linux/fs/aufs/whout.c 2018-08-12 23:43:05.463458173 +0200
34600 +// SPDX-License-Identifier: GPL-2.0
34602 + * Copyright (C) 2005-2018 Junjiro R. Okajima
34604 + * This program, aufs is free software; you can redistribute it and/or modify
34605 + * it under the terms of the GNU General Public License as published by
34606 + * the Free Software Foundation; either version 2 of the License, or
34607 + * (at your option) any later version.
34609 + * This program is distributed in the hope that it will be useful,
34610 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34611 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34612 + * GNU General Public License for more details.
34614 + * You should have received a copy of the GNU General Public License
34615 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34619 + * whiteout for logical deletion and opaque directory
34624 +#define WH_MASK 0444
34627 + * If a directory contains this file, then it is opaque. We start with the
34628 + * .wh. flag so that it is blocked by lookup.
34630 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34631 + sizeof(AUFS_WH_DIROPQ) - 1);
34634 + * generate whiteout name, which is NOT terminated by NULL.
34635 + * @name: original d_name.name
34636 + * @len: original d_name.len
34637 + * @wh: whiteout qstr
34638 + * returns zero when succeeds, otherwise error.
34639 + * succeeded value as wh->name should be freed by kfree().
34641 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34645 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34646 + return -ENAMETOOLONG;
34648 + wh->len = name->len + AUFS_WH_PFX_LEN;
34649 + p = kmalloc(wh->len, GFP_NOFS);
34652 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34653 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34660 +/* ---------------------------------------------------------------------- */
34663 + * test if the @wh_name exists under @h_parent.
34664 + * @try_sio specifies the necessary of super-io.
34666 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
34669 + struct dentry *wh_dentry;
34672 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34674 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
34675 + err = PTR_ERR(wh_dentry);
34676 + if (IS_ERR(wh_dentry)) {
34677 + if (err == -ENAMETOOLONG)
34683 + if (d_is_negative(wh_dentry))
34684 + goto out_wh; /* success */
34687 + if (d_is_reg(wh_dentry))
34688 + goto out_wh; /* success */
34691 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34692 + wh_dentry, d_inode(wh_dentry)->i_mode);
34701 + * test if the @h_dentry sets opaque or not.
34703 +int au_diropq_test(struct dentry *h_dentry)
34706 + struct inode *h_dir;
34708 + h_dir = d_inode(h_dentry);
34709 + err = au_wh_test(h_dentry, &diropq_name,
34710 + au_test_h_perm_sio(h_dir, MAY_EXEC));
34715 + * returns a negative dentry whose name is unique and temporary.
34717 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34718 + struct qstr *prefix)
34720 + struct dentry *dentry;
34722 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34724 + /* strict atomic_t is unnecessary here */
34725 + static unsigned short cnt;
34728 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34731 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34732 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34733 + dentry = ERR_PTR(-ENAMETOOLONG);
34734 + if (unlikely(qs.len > NAME_MAX))
34736 + dentry = ERR_PTR(-ENOMEM);
34737 + name = kmalloc(qs.len + 1, GFP_NOFS);
34738 + if (unlikely(!name))
34742 + /* doubly whiteout-ed */
34743 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34744 + p = name + AUFS_WH_PFX_LEN * 2;
34745 + memcpy(p, prefix->name, prefix->len);
34746 + p += prefix->len;
34748 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34751 + for (i = 0; i < 3; i++) {
34752 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34753 + dentry = au_sio_lkup_one(&qs, h_parent);
34754 + if (IS_ERR(dentry) || d_is_negative(dentry))
34758 + /* pr_warn("could not get random name\n"); */
34759 + dentry = ERR_PTR(-EEXIST);
34760 + AuDbg("%.*s\n", AuLNPair(&qs));
34764 + if (name != defname)
34767 + AuTraceErrPtr(dentry);
34772 + * rename the @h_dentry on @br to the whiteouted temporary name.
34774 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
34777 + struct path h_path = {
34778 + .mnt = au_br_mnt(br)
34780 + struct inode *h_dir, *delegated;
34781 + struct dentry *h_parent;
34783 + h_parent = h_dentry->d_parent; /* dir inode is locked */
34784 + h_dir = d_inode(h_parent);
34785 + IMustLock(h_dir);
34787 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
34788 + err = PTR_ERR(h_path.dentry);
34789 + if (IS_ERR(h_path.dentry))
34792 + /* under the same dir, no need to lock_rename() */
34793 + delegated = NULL;
34794 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
34797 + if (unlikely(err == -EWOULDBLOCK)) {
34798 + pr_warn("cannot retry for NFSv4 delegation"
34799 + " for an internal rename\n");
34802 + dput(h_path.dentry);
34809 +/* ---------------------------------------------------------------------- */
34811 + * functions for removing a whiteout
34814 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
34817 + struct inode *delegated;
34820 + * forces superio when the dir has a sticky bit.
34821 + * this may be a violation of unix fs semantics.
34823 + force = (h_dir->i_mode & S_ISVTX)
34824 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
34825 + delegated = NULL;
34826 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
34827 + if (unlikely(err == -EWOULDBLOCK)) {
34828 + pr_warn("cannot retry for NFSv4 delegation"
34829 + " for an internal unlink\n");
34835 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
34836 + struct dentry *dentry)
34840 + err = do_unlink_wh(h_dir, h_path);
34841 + if (!err && dentry)
34842 + au_set_dbwh(dentry, -1);
34847 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
34848 + struct au_branch *br)
34851 + struct path h_path = {
34852 + .mnt = au_br_mnt(br)
34856 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
34857 + if (IS_ERR(h_path.dentry))
34858 + err = PTR_ERR(h_path.dentry);
34860 + if (d_is_reg(h_path.dentry))
34861 + err = do_unlink_wh(d_inode(h_parent), &h_path);
34862 + dput(h_path.dentry);
34868 +/* ---------------------------------------------------------------------- */
34870 + * initialize/clean whiteout for a branch
34873 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
34877 + struct inode *delegated;
34879 + if (d_is_negative(whpath->dentry))
34883 + err = vfsub_rmdir(h_dir, whpath);
34885 + delegated = NULL;
34886 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
34887 + if (unlikely(err == -EWOULDBLOCK)) {
34888 + pr_warn("cannot retry for NFSv4 delegation"
34889 + " for an internal unlink\n");
34893 + if (unlikely(err))
34894 + pr_warn("failed removing %pd (%d), ignored.\n",
34895 + whpath->dentry, err);
34898 +static int test_linkable(struct dentry *h_root)
34900 + struct inode *h_dir = d_inode(h_root);
34902 + if (h_dir->i_op->link)
34905 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
34906 + h_root, au_sbtype(h_root->d_sb));
34910 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
34911 +static int au_whdir(struct inode *h_dir, struct path *path)
34916 + if (d_is_negative(path->dentry)) {
34919 + if (au_test_nfs(path->dentry->d_sb))
34921 + err = vfsub_mkdir(h_dir, path, mode);
34922 + } else if (d_is_dir(path->dentry))
34925 + pr_err("unknown %pd exists\n", path->dentry);
34930 +struct au_wh_base {
34931 + const struct qstr *name;
34932 + struct dentry *dentry;
34935 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
34936 + struct path *h_path)
34938 + h_path->dentry = base[AuBrWh_BASE].dentry;
34939 + au_wh_clean(h_dir, h_path, /*isdir*/0);
34940 + h_path->dentry = base[AuBrWh_PLINK].dentry;
34941 + au_wh_clean(h_dir, h_path, /*isdir*/1);
34942 + h_path->dentry = base[AuBrWh_ORPH].dentry;
34943 + au_wh_clean(h_dir, h_path, /*isdir*/1);
34947 + * returns tri-state,
34948 + * minus: error, caller should print the message
34950 + * plus: error, caller should NOT print the message
34952 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
34953 + int do_plink, struct au_wh_base base[],
34954 + struct path *h_path)
34957 + struct inode *h_dir;
34959 + h_dir = d_inode(h_root);
34960 + h_path->dentry = base[AuBrWh_BASE].dentry;
34961 + au_wh_clean(h_dir, h_path, /*isdir*/0);
34962 + h_path->dentry = base[AuBrWh_PLINK].dentry;
34964 + err = test_linkable(h_root);
34965 + if (unlikely(err)) {
34970 + err = au_whdir(h_dir, h_path);
34971 + if (unlikely(err))
34973 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
34975 + au_wh_clean(h_dir, h_path, /*isdir*/1);
34976 + h_path->dentry = base[AuBrWh_ORPH].dentry;
34977 + err = au_whdir(h_dir, h_path);
34978 + if (unlikely(err))
34980 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
34987 + * for the moment, aufs supports the branch filesystem which does not support
34988 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
34989 + * copyup failed. finally, such filesystem will not be used as the writable
34992 + * returns tri-state, see above.
34994 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
34995 + int do_plink, struct au_wh_base base[],
34996 + struct path *h_path)
34999 + struct inode *h_dir;
35001 + WbrWhMustWriteLock(wbr);
35003 + err = test_linkable(h_root);
35004 + if (unlikely(err)) {
35010 + * todo: should this create be done in /sbin/mount.aufs helper?
35013 + h_dir = d_inode(h_root);
35014 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35015 + h_path->dentry = base[AuBrWh_BASE].dentry;
35016 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35017 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35020 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35021 + if (unlikely(err))
35024 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35026 + err = au_whdir(h_dir, h_path);
35027 + if (unlikely(err))
35029 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35031 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35032 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35034 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35035 + err = au_whdir(h_dir, h_path);
35036 + if (unlikely(err))
35038 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35045 + * initialize the whiteout base file/dir for @br.
35047 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35050 + const unsigned char do_plink
35051 + = !!au_opt_test(au_mntflags(sb), PLINK);
35052 + struct inode *h_dir;
35053 + struct path path = br->br_path;
35054 + struct dentry *h_root = path.dentry;
35055 + struct au_wbr *wbr = br->br_wbr;
35056 + static const struct qstr base_name[] = {
35057 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35058 + sizeof(AUFS_BASE_NAME) - 1),
35059 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35060 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35061 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35062 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35064 + struct au_wh_base base[] = {
35065 + [AuBrWh_BASE] = {
35066 + .name = base_name + AuBrWh_BASE,
35069 + [AuBrWh_PLINK] = {
35070 + .name = base_name + AuBrWh_PLINK,
35073 + [AuBrWh_ORPH] = {
35074 + .name = base_name + AuBrWh_ORPH,
35080 + WbrWhMustWriteLock(wbr);
35082 + for (i = 0; i < AuBrWh_Last; i++) {
35083 + /* doubly whiteouted */
35084 + struct dentry *d;
35086 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35087 + err = PTR_ERR(d);
35091 + base[i].dentry = d;
35093 + && wbr->wbr_wh[i]
35094 + && wbr->wbr_wh[i] != base[i].dentry);
35098 + for (i = 0; i < AuBrWh_Last; i++) {
35099 + dput(wbr->wbr_wh[i]);
35100 + wbr->wbr_wh[i] = NULL;
35104 + if (!au_br_writable(br->br_perm)) {
35105 + h_dir = d_inode(h_root);
35106 + au_wh_init_ro(h_dir, base, &path);
35107 + } else if (!au_br_wh_linkable(br->br_perm)) {
35108 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35114 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35120 + goto out; /* success */
35123 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35124 + err, h_root, au_sbtype(h_root->d_sb));
35126 + for (i = 0; i < AuBrWh_Last; i++)
35127 + dput(base[i].dentry);
35131 +/* ---------------------------------------------------------------------- */
35133 + * whiteouts are all hard-linked usually.
35134 + * when its link count reaches a ceiling, we create a new whiteout base
35135 + * asynchronously.
35138 +struct reinit_br_wh {
35139 + struct super_block *sb;
35140 + struct au_branch *br;
35143 +static void reinit_br_wh(void *arg)
35146 + aufs_bindex_t bindex;
35147 + struct path h_path;
35148 + struct reinit_br_wh *a = arg;
35149 + struct au_wbr *wbr;
35150 + struct inode *dir, *delegated;
35151 + struct dentry *h_root;
35152 + struct au_hinode *hdir;
35155 + wbr = a->br->br_wbr;
35156 + /* big aufs lock */
35157 + si_noflush_write_lock(a->sb);
35158 + if (!au_br_writable(a->br->br_perm))
35160 + bindex = au_br_index(a->sb, a->br->br_id);
35161 + if (unlikely(bindex < 0))
35164 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35165 + dir = d_inode(a->sb->s_root);
35166 + hdir = au_hi(dir, bindex);
35167 + h_root = au_h_dptr(a->sb->s_root, bindex);
35168 + AuDebugOn(h_root != au_br_dentry(a->br));
35170 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35171 + wbr_wh_write_lock(wbr);
35172 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35175 + h_path.dentry = wbr->wbr_whbase;
35176 + h_path.mnt = au_br_mnt(a->br);
35177 + delegated = NULL;
35178 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35180 + if (unlikely(err == -EWOULDBLOCK)) {
35181 + pr_warn("cannot retry for NFSv4 delegation"
35182 + " for an internal unlink\n");
35186 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35189 + dput(wbr->wbr_whbase);
35190 + wbr->wbr_whbase = NULL;
35192 + err = au_wh_init(a->br, a->sb);
35193 + wbr_wh_write_unlock(wbr);
35194 + au_hn_inode_unlock(hdir);
35195 + di_read_unlock(a->sb->s_root, AuLock_IR);
35197 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35201 + atomic_dec(&wbr->wbr_wh_running);
35202 + au_br_put(a->br);
35203 + si_write_unlock(a->sb);
35204 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35206 + if (unlikely(err))
35207 + AuIOErr("err %d\n", err);
35210 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35212 + int do_dec, wkq_err;
35213 + struct reinit_br_wh *arg;
35216 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35219 + /* ignore ENOMEM */
35220 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35223 + * dec(wh_running), kfree(arg) and dec(br_count)
35224 + * in reinit function
35229 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35230 + if (unlikely(wkq_err)) {
35231 + atomic_dec(&br->br_wbr->wbr_wh_running);
35240 + atomic_dec(&br->br_wbr->wbr_wh_running);
35243 +/* ---------------------------------------------------------------------- */
35246 + * create the whiteout @wh.
35248 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35249 + struct dentry *wh)
35252 + struct path h_path = {
35255 + struct au_branch *br;
35256 + struct au_wbr *wbr;
35257 + struct dentry *h_parent;
35258 + struct inode *h_dir, *delegated;
35260 + h_parent = wh->d_parent; /* dir inode is locked */
35261 + h_dir = d_inode(h_parent);
35262 + IMustLock(h_dir);
35264 + br = au_sbr(sb, bindex);
35265 + h_path.mnt = au_br_mnt(br);
35266 + wbr = br->br_wbr;
35267 + wbr_wh_read_lock(wbr);
35268 + if (wbr->wbr_whbase) {
35269 + delegated = NULL;
35270 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35271 + if (unlikely(err == -EWOULDBLOCK)) {
35272 + pr_warn("cannot retry for NFSv4 delegation"
35273 + " for an internal link\n");
35276 + if (!err || err != -EMLINK)
35279 + /* link count full. re-initialize br_whbase. */
35280 + kick_reinit_br_wh(sb, br);
35283 + /* return this error in this context */
35284 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35286 + au_fhsm_wrote(sb, bindex, /*force*/0);
35289 + wbr_wh_read_unlock(wbr);
35293 +/* ---------------------------------------------------------------------- */
35296 + * create or remove the diropq.
35298 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35299 + unsigned int flags)
35301 + struct dentry *opq_dentry, *h_dentry;
35302 + struct super_block *sb;
35303 + struct au_branch *br;
35306 + sb = dentry->d_sb;
35307 + br = au_sbr(sb, bindex);
35308 + h_dentry = au_h_dptr(dentry, bindex);
35309 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35310 + if (IS_ERR(opq_dentry))
35313 + if (au_ftest_diropq(flags, CREATE)) {
35314 + err = link_or_create_wh(sb, bindex, opq_dentry);
35316 + au_set_dbdiropq(dentry, bindex);
35317 + goto out; /* success */
35320 + struct path tmp = {
35321 + .dentry = opq_dentry,
35322 + .mnt = au_br_mnt(br)
35324 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35326 + au_set_dbdiropq(dentry, -1);
35328 + dput(opq_dentry);
35329 + opq_dentry = ERR_PTR(err);
35332 + return opq_dentry;
35335 +struct do_diropq_args {
35336 + struct dentry **errp;
35337 + struct dentry *dentry;
35338 + aufs_bindex_t bindex;
35339 + unsigned int flags;
35342 +static void call_do_diropq(void *args)
35344 + struct do_diropq_args *a = args;
35345 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35348 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35349 + unsigned int flags)
35351 + struct dentry *diropq, *h_dentry;
35353 + h_dentry = au_h_dptr(dentry, bindex);
35354 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35355 + diropq = do_diropq(dentry, bindex, flags);
35358 + struct do_diropq_args args = {
35360 + .dentry = dentry,
35361 + .bindex = bindex,
35365 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35366 + if (unlikely(wkq_err))
35367 + diropq = ERR_PTR(wkq_err);
35373 +/* ---------------------------------------------------------------------- */
35376 + * lookup whiteout dentry.
35377 + * @h_parent: lower parent dentry which must exist and be locked
35378 + * @base_name: name of dentry which will be whiteouted
35379 + * returns dentry for whiteout.
35381 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35382 + struct au_branch *br)
35385 + struct qstr wh_name;
35386 + struct dentry *wh_dentry;
35388 + err = au_wh_name_alloc(&wh_name, base_name);
35389 + wh_dentry = ERR_PTR(err);
35391 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35392 + kfree(wh_name.name);
35394 + return wh_dentry;
35398 + * link/create a whiteout for @dentry on @bindex.
35400 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35401 + struct dentry *h_parent)
35403 + struct dentry *wh_dentry;
35404 + struct super_block *sb;
35407 + sb = dentry->d_sb;
35408 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35409 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35410 + err = link_or_create_wh(sb, bindex, wh_dentry);
35412 + au_set_dbwh(dentry, bindex);
35413 + au_fhsm_wrote(sb, bindex, /*force*/0);
35416 + wh_dentry = ERR_PTR(err);
35420 + return wh_dentry;
35423 +/* ---------------------------------------------------------------------- */
35425 +/* Delete all whiteouts in this directory on branch bindex. */
35426 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35427 + aufs_bindex_t bindex, struct au_branch *br)
35430 + unsigned long ul, n;
35431 + struct qstr wh_name;
35433 + struct hlist_head *head;
35434 + struct au_vdir_wh *pos;
35435 + struct au_vdir_destr *str;
35438 + p = (void *)__get_free_page(GFP_NOFS);
35439 + wh_name.name = p;
35440 + if (unlikely(!wh_name.name))
35444 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35445 + p += AUFS_WH_PFX_LEN;
35446 + n = whlist->nh_num;
35447 + head = whlist->nh_head;
35448 + for (ul = 0; !err && ul < n; ul++, head++) {
35449 + hlist_for_each_entry(pos, head, wh_hash) {
35450 + if (pos->wh_bindex != bindex)
35453 + str = &pos->wh_str;
35454 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35455 + memcpy(p, str->name, str->len);
35456 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35457 + err = unlink_wh_name(h_dentry, &wh_name, br);
35462 + AuIOErr("whiteout name too long %.*s\n",
35463 + str->len, str->name);
35468 + free_page((unsigned long)wh_name.name);
35474 +struct del_wh_children_args {
35476 + struct dentry *h_dentry;
35477 + struct au_nhash *whlist;
35478 + aufs_bindex_t bindex;
35479 + struct au_branch *br;
35482 +static void call_del_wh_children(void *args)
35484 + struct del_wh_children_args *a = args;
35485 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35488 +/* ---------------------------------------------------------------------- */
35490 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35492 + struct au_whtmp_rmdir *whtmp;
35494 + unsigned int rdhash;
35496 + SiMustAnyLock(sb);
35498 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35499 + if (unlikely(!whtmp)) {
35500 + whtmp = ERR_PTR(-ENOMEM);
35504 + /* no estimation for dir size */
35505 + rdhash = au_sbi(sb)->si_rdhash;
35507 + rdhash = AUFS_RDHASH_DEF;
35508 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35509 + if (unlikely(err)) {
35511 + whtmp = ERR_PTR(err);
35518 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35521 + au_br_put(whtmp->br);
35522 + dput(whtmp->wh_dentry);
35523 + iput(whtmp->dir);
35524 + au_nhash_wh_free(&whtmp->whlist);
35529 + * rmdir the whiteouted temporary named dir @h_dentry.
35530 + * @whlist: whiteouted children.
35532 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35533 + struct dentry *wh_dentry, struct au_nhash *whlist)
35536 + unsigned int h_nlink;
35537 + struct path h_tmp;
35538 + struct inode *wh_inode, *h_dir;
35539 + struct au_branch *br;
35541 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35542 + IMustLock(h_dir);
35544 + br = au_sbr(dir->i_sb, bindex);
35545 + wh_inode = d_inode(wh_dentry);
35546 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35549 + * someone else might change some whiteouts while we were sleeping.
35550 + * it means this whlist may have an obsoleted entry.
35552 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35553 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35556 + struct del_wh_children_args args = {
35558 + .h_dentry = wh_dentry,
35559 + .whlist = whlist,
35560 + .bindex = bindex,
35564 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35565 + if (unlikely(wkq_err))
35568 + inode_unlock(wh_inode);
35571 + h_tmp.dentry = wh_dentry;
35572 + h_tmp.mnt = au_br_mnt(br);
35573 + h_nlink = h_dir->i_nlink;
35574 + err = vfsub_rmdir(h_dir, &h_tmp);
35575 + /* some fs doesn't change the parent nlink in some cases */
35576 + h_nlink -= h_dir->i_nlink;
35580 + if (au_ibtop(dir) == bindex) {
35581 + /* todo: dir->i_mutex is necessary */
35582 + au_cpup_attr_timesizes(dir);
35584 + vfsub_drop_nlink(dir);
35586 + return 0; /* success */
35589 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35593 +static void call_rmdir_whtmp(void *args)
35596 + aufs_bindex_t bindex;
35597 + struct au_whtmp_rmdir *a = args;
35598 + struct super_block *sb;
35599 + struct dentry *h_parent;
35600 + struct inode *h_dir;
35601 + struct au_hinode *hdir;
35603 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35604 + /* inode_lock(a->dir); */
35606 + sb = a->dir->i_sb;
35607 + si_read_lock(sb, !AuLock_FLUSH);
35608 + if (!au_br_writable(a->br->br_perm))
35610 + bindex = au_br_index(sb, a->br->br_id);
35611 + if (unlikely(bindex < 0))
35615 + ii_write_lock_parent(a->dir);
35616 + h_parent = dget_parent(a->wh_dentry);
35617 + h_dir = d_inode(h_parent);
35618 + hdir = au_hi(a->dir, bindex);
35619 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35620 + if (unlikely(err))
35622 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35623 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35626 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35627 + au_hn_inode_unlock(hdir);
35628 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35632 + ii_write_unlock(a->dir);
35634 + /* inode_unlock(a->dir); */
35635 + au_whtmp_rmdir_free(a);
35636 + si_read_unlock(sb);
35637 + au_nwt_done(&au_sbi(sb)->si_nowait);
35638 + if (unlikely(err))
35639 + AuIOErr("err %d\n", err);
35642 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35643 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35646 + struct super_block *sb;
35650 + /* all post-process will be done in do_rmdir_whtmp(). */
35652 + args->dir = au_igrab(dir);
35653 + args->br = au_sbr(sb, bindex);
35654 + au_br_get(args->br);
35655 + args->wh_dentry = dget(wh_dentry);
35656 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35657 + if (unlikely(wkq_err)) {
35658 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35659 + au_whtmp_rmdir_free(args);
35662 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35663 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35664 +++ linux/fs/aufs/whout.h 2018-08-12 23:43:05.463458173 +0200
35666 +/* SPDX-License-Identifier: GPL-2.0 */
35668 + * Copyright (C) 2005-2018 Junjiro R. Okajima
35670 + * This program, aufs is free software; you can redistribute it and/or modify
35671 + * it under the terms of the GNU General Public License as published by
35672 + * the Free Software Foundation; either version 2 of the License, or
35673 + * (at your option) any later version.
35675 + * This program is distributed in the hope that it will be useful,
35676 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35677 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35678 + * GNU General Public License for more details.
35680 + * You should have received a copy of the GNU General Public License
35681 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35685 + * whiteout for logical deletion and opaque directory
35688 +#ifndef __AUFS_WHOUT_H__
35689 +#define __AUFS_WHOUT_H__
35696 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35697 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
35698 +int au_diropq_test(struct dentry *h_dentry);
35700 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35701 + struct qstr *prefix);
35702 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35703 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35704 + struct dentry *dentry);
35705 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35707 +/* diropq flags */
35708 +#define AuDiropq_CREATE 1
35709 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35710 +#define au_fset_diropq(flags, name) \
35711 + do { (flags) |= AuDiropq_##name; } while (0)
35712 +#define au_fclr_diropq(flags, name) \
35713 + do { (flags) &= ~AuDiropq_##name; } while (0)
35715 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35716 + unsigned int flags);
35717 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35718 + struct au_branch *br);
35719 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35720 + struct dentry *h_parent);
35722 +/* real rmdir for the whiteout-ed dir */
35723 +struct au_whtmp_rmdir {
35724 + struct inode *dir;
35725 + struct au_branch *br;
35726 + struct dentry *wh_dentry;
35727 + struct au_nhash whlist;
35730 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35731 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35732 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35733 + struct dentry *wh_dentry, struct au_nhash *whlist);
35734 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35735 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35737 +/* ---------------------------------------------------------------------- */
35739 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35740 + aufs_bindex_t bindex)
35742 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35745 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35747 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35750 +#endif /* __KERNEL__ */
35751 +#endif /* __AUFS_WHOUT_H__ */
35752 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35753 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35754 +++ linux/fs/aufs/wkq.c 2018-08-12 23:43:05.463458173 +0200
35756 +// SPDX-License-Identifier: GPL-2.0
35758 + * Copyright (C) 2005-2018 Junjiro R. Okajima
35760 + * This program, aufs is free software; you can redistribute it and/or modify
35761 + * it under the terms of the GNU General Public License as published by
35762 + * the Free Software Foundation; either version 2 of the License, or
35763 + * (at your option) any later version.
35765 + * This program is distributed in the hope that it will be useful,
35766 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35767 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35768 + * GNU General Public License for more details.
35770 + * You should have received a copy of the GNU General Public License
35771 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35775 + * workqueue for asynchronous/super-io operations
35776 + * todo: try new dredential scheme
35779 +#include <linux/module.h>
35782 +/* internal workqueue named AUFS_WKQ_NAME */
35784 +static struct workqueue_struct *au_wkq;
35786 +struct au_wkinfo {
35787 + struct work_struct wk;
35788 + struct kobject *kobj;
35790 + unsigned int flags; /* see wkq.h */
35792 + au_wkq_func_t func;
35795 +#ifdef CONFIG_LOCKDEP
35797 + struct held_lock **hlock;
35800 + struct completion *comp;
35803 +/* ---------------------------------------------------------------------- */
35805 + * Aufs passes some operations to the workqueue such as the internal copyup.
35806 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
35807 + * job run by workqueue depends upon the locks acquired in the other task.
35808 + * Delegating a small operation to the workqueue, aufs passes its lockdep
35809 + * information too. And the job in the workqueue restores the info in order to
35810 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
35811 + * correctly and expectedly.
35814 +#ifndef CONFIG_LOCKDEP
35815 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
35816 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
35817 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
35818 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
35819 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
35821 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
35823 + wkinfo->hlock = NULL;
35824 + wkinfo->dont_check = 0;
35831 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
35833 + static DEFINE_SPINLOCK(spin);
35836 + struct lock_class_key *key;
35838 + { .name = "&sbinfo->si_rwsem" },
35839 + { .name = "&finfo->fi_rwsem" },
35840 + { .name = "&dinfo->di_rwsem" },
35841 + { .name = "&iinfo->ii_rwsem" }
35846 + /* lockless read from 'set.' see below */
35847 + if (set == ARRAY_SIZE(a)) {
35848 + for (i = 0; i < ARRAY_SIZE(a); i++)
35849 + if (a[i].key == key)
35854 + spin_lock(&spin);
35856 + for (i = 0; i < ARRAY_SIZE(a); i++)
35857 + if (a[i].key == key) {
35858 + spin_unlock(&spin);
35861 + for (i = 0; i < ARRAY_SIZE(a); i++) {
35863 + if (unlikely(a[i].key == key)) { /* rare but possible */
35864 + spin_unlock(&spin);
35869 + if (strstr(a[i].name, name)) {
35871 + * the order of these three lines is important for the
35872 + * lockless read above.
35875 + spin_unlock(&spin);
35877 + /* AuDbg("%d, %s\n", set, name); */
35881 + spin_unlock(&spin);
35890 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
35893 + struct task_struct *curr;
35894 + struct held_lock **hl, *held_locks, *p;
35898 + wkinfo->dont_check = lockdep_recursing(curr);
35899 + if (wkinfo->dont_check)
35901 + n = curr->lockdep_depth;
35906 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
35907 + if (unlikely(!wkinfo->hlock))
35912 + if (0 && au_debug_test()) /* left for debugging */
35913 + lockdep_print_held_locks(curr);
35915 + held_locks = curr->held_locks;
35916 + hl = wkinfo->hlock;
35918 + p = held_locks++;
35919 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
35928 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
35930 + kfree(wkinfo->hlock);
35933 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
35935 + struct held_lock *p, **hl = wkinfo->hlock;
35938 + if (wkinfo->dont_check)
35942 + while ((p = *hl++)) { /* assignment */
35943 + subclass = lockdep_hlock_class(p)->subclass;
35944 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
35946 + rwsem_acquire_read(p->instance, subclass, 0,
35947 + /*p->acquire_ip*/_RET_IP_);
35949 + rwsem_acquire(p->instance, subclass, 0,
35950 + /*p->acquire_ip*/_RET_IP_);
35954 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
35956 + struct held_lock *p, **hl = wkinfo->hlock;
35958 + if (wkinfo->dont_check)
35962 + while ((p = *hl++)) /* assignment */
35963 + rwsem_release(p->instance, 0, /*p->acquire_ip*/_RET_IP_);
35967 +static void wkq_func(struct work_struct *wk)
35969 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
35971 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
35972 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
35974 + au_wkq_lockdep_pre(wkinfo);
35975 + wkinfo->func(wkinfo->args);
35976 + au_wkq_lockdep_post(wkinfo);
35977 + if (au_ftest_wkq(wkinfo->flags, WAIT))
35978 + complete(wkinfo->comp);
35980 + kobject_put(wkinfo->kobj);
35981 + module_put(THIS_MODULE); /* todo: ?? */
35987 + * Since struct completion is large, try allocating it dynamically.
35989 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
35990 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
35992 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
35994 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
35996 + init_completion(*comp);
35997 + wkinfo->comp = *comp;
36003 +static void au_wkq_comp_free(struct completion *comp)
36011 +#define AuWkqCompDeclare(name) \
36012 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
36013 + struct completion *comp = &_ ## name
36015 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36017 + wkinfo->comp = *comp;
36021 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
36025 +#endif /* 4KSTACKS */
36027 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36029 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36030 + if (au_wkq_test()) {
36031 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36032 + " due to a dead dir by UDBA?\n");
36033 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36036 + au_dbg_verify_kthread();
36038 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36039 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36040 + queue_work(au_wkq, &wkinfo->wk);
36042 + INIT_WORK(&wkinfo->wk, wkq_func);
36043 + schedule_work(&wkinfo->wk);
36048 + * Be careful. It is easy to make deadlock happen.
36049 + * processA: lock, wkq and wait
36050 + * processB: wkq and wait, lock in wkq
36053 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36056 + AuWkqCompDeclare(comp);
36057 + struct au_wkinfo wkinfo = {
36063 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36064 + if (unlikely(err))
36066 + err = au_wkq_lockdep_alloc(&wkinfo);
36067 + if (unlikely(err))
36070 + au_wkq_run(&wkinfo);
36071 + /* no timeout, no interrupt */
36072 + wait_for_completion(wkinfo.comp);
36074 + au_wkq_lockdep_free(&wkinfo);
36077 + au_wkq_comp_free(comp);
36079 + destroy_work_on_stack(&wkinfo.wk);
36084 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36085 + * problem in a concurrent umounting.
36087 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36088 + unsigned int flags)
36091 + struct au_wkinfo *wkinfo;
36093 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36096 + * wkq_func() must free this wkinfo.
36097 + * it highly depends upon the implementation of workqueue.
36100 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36102 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36103 + wkinfo->flags = flags & ~AuWkq_WAIT;
36104 + wkinfo->func = func;
36105 + wkinfo->args = args;
36106 + wkinfo->comp = NULL;
36107 + au_wkq_lockdep_init(wkinfo);
36108 + kobject_get(wkinfo->kobj);
36109 + __module_get(THIS_MODULE); /* todo: ?? */
36111 + au_wkq_run(wkinfo);
36114 + au_nwt_done(&au_sbi(sb)->si_nowait);
36120 +/* ---------------------------------------------------------------------- */
36122 +void au_nwt_init(struct au_nowait_tasks *nwt)
36124 + atomic_set(&nwt->nw_len, 0);
36125 + /* smp_mb(); */ /* atomic_set */
36126 + init_waitqueue_head(&nwt->nw_wq);
36129 +void au_wkq_fin(void)
36131 + destroy_workqueue(au_wkq);
36134 +int __init au_wkq_init(void)
36139 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36140 + if (IS_ERR(au_wkq))
36141 + err = PTR_ERR(au_wkq);
36142 + else if (!au_wkq)
36147 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36148 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36149 +++ linux/fs/aufs/wkq.h 2018-08-12 23:43:05.463458173 +0200
36151 +/* SPDX-License-Identifier: GPL-2.0 */
36153 + * Copyright (C) 2005-2018 Junjiro R. Okajima
36155 + * This program, aufs is free software; you can redistribute it and/or modify
36156 + * it under the terms of the GNU General Public License as published by
36157 + * the Free Software Foundation; either version 2 of the License, or
36158 + * (at your option) any later version.
36160 + * This program is distributed in the hope that it will be useful,
36161 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36162 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36163 + * GNU General Public License for more details.
36165 + * You should have received a copy of the GNU General Public License
36166 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36170 + * workqueue for asynchronous/super-io operations
36171 + * todo: try new credentials management scheme
36174 +#ifndef __AUFS_WKQ_H__
36175 +#define __AUFS_WKQ_H__
36179 +#include <linux/wait.h>
36181 +struct super_block;
36183 +/* ---------------------------------------------------------------------- */
36186 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36188 +struct au_nowait_tasks {
36190 + wait_queue_head_t nw_wq;
36193 +/* ---------------------------------------------------------------------- */
36195 +typedef void (*au_wkq_func_t)(void *args);
36198 +#define AuWkq_WAIT 1
36199 +#define AuWkq_NEST (1 << 1)
36200 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36201 +#define au_fset_wkq(flags, name) \
36202 + do { (flags) |= AuWkq_##name; } while (0)
36203 +#define au_fclr_wkq(flags, name) \
36204 + do { (flags) &= ~AuWkq_##name; } while (0)
36206 +#ifndef CONFIG_AUFS_HNOTIFY
36208 +#define AuWkq_NEST 0
36212 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36213 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36214 + unsigned int flags);
36215 +void au_nwt_init(struct au_nowait_tasks *nwt);
36216 +int __init au_wkq_init(void);
36217 +void au_wkq_fin(void);
36219 +/* ---------------------------------------------------------------------- */
36221 +static inline int au_wkq_test(void)
36223 + return current->flags & PF_WQ_WORKER;
36226 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36228 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36231 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36233 + if (atomic_dec_and_test(&nwt->nw_len))
36234 + wake_up_all(&nwt->nw_wq);
36237 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36239 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36243 +#endif /* __KERNEL__ */
36244 +#endif /* __AUFS_WKQ_H__ */
36245 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36246 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36247 +++ linux/fs/aufs/xattr.c 2018-08-12 23:43:05.466791610 +0200
36249 +// SPDX-License-Identifier: GPL-2.0
36251 + * Copyright (C) 2014-2018 Junjiro R. Okajima
36253 + * This program, aufs is free software; you can redistribute it and/or modify
36254 + * it under the terms of the GNU General Public License as published by
36255 + * the Free Software Foundation; either version 2 of the License, or
36256 + * (at your option) any later version.
36258 + * This program is distributed in the hope that it will be useful,
36259 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36260 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36261 + * GNU General Public License for more details.
36263 + * You should have received a copy of the GNU General Public License
36264 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36268 + * handling xattr functions
36271 +#include <linux/fs.h>
36272 +#include <linux/posix_acl_xattr.h>
36273 +#include <linux/xattr.h>
36276 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36278 + if (!ignore_flags)
36286 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36291 +#define cmp(brattr, prefix) do { \
36292 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36293 + XATTR_##prefix##_PREFIX_LEN)) { \
36294 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36300 + cmp(SEC, SECURITY);
36301 + cmp(SYS, SYSTEM);
36302 + cmp(TR, TRUSTED);
36306 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36313 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36315 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36316 + char *name, char **buf, unsigned int ignore_flags,
36317 + unsigned int verbose)
36321 + struct inode *h_idst;
36323 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36325 + if (unlikely(err <= 0)) {
36326 + if (err == -ENODATA
36327 + || (err == -EOPNOTSUPP
36328 + && ((ignore_flags & au_xattr_out_of_list)
36329 + || (au_test_nfs_noacl(d_inode(h_src))
36330 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36332 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36335 + if (err && (verbose || au_debug_test()))
36336 + pr_err("%s, err %d\n", name, err);
36340 + /* unlock it temporary */
36341 + h_idst = d_inode(h_dst);
36342 + inode_unlock(h_idst);
36343 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36344 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36345 + if (unlikely(err)) {
36346 + if (verbose || au_debug_test())
36347 + pr_err("%s, err %d\n", name, err);
36348 + err = au_xattr_ignore(err, name, ignore_flags);
36355 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36356 + unsigned int verbose)
36358 + int err, unlocked, acl_access, acl_default;
36360 + struct inode *h_isrc, *h_idst;
36361 + char *value, *p, *o, *e;
36363 + /* try stopping to update the source inode while we are referencing */
36364 + /* there should not be the parent-child relationship between them */
36365 + h_isrc = d_inode(h_src);
36366 + h_idst = d_inode(h_dst);
36367 + inode_unlock(h_idst);
36368 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36369 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36372 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36373 + ssz = vfs_listxattr(h_src, NULL, 0);
36375 + if (unlikely(err < 0)) {
36377 + if (err == -ENODATA
36378 + || err == -EOPNOTSUPP)
36379 + err = 0; /* ignore */
36388 + p = kmalloc(ssz, GFP_NOFS);
36390 + if (unlikely(!p))
36392 + err = vfs_listxattr(h_src, p, ssz);
36394 + inode_unlock_shared(h_isrc);
36396 + AuDbg("err %d, ssz %zd\n", err, ssz);
36397 + if (unlikely(err < 0))
36405 + while (!err && p < e) {
36406 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36407 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36408 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36409 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36411 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36413 + p += strlen(p) + 1;
36416 + ignore_flags |= au_xattr_out_of_list;
36417 + if (!err && !acl_access) {
36418 + err = au_do_cpup_xattr(h_dst, h_src,
36419 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36420 + ignore_flags, verbose);
36423 + if (!err && !acl_default) {
36424 + err = au_do_cpup_xattr(h_dst, h_src,
36425 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36426 + ignore_flags, verbose);
36436 + inode_unlock_shared(h_isrc);
36441 +/* ---------------------------------------------------------------------- */
36443 +static int au_smack_reentering(struct super_block *sb)
36445 +#if IS_ENABLED(CONFIG_SECURITY_SMACK)
36447 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36448 + * i_op->getxattr(). ouch.
36450 + return si_pid_test(sb);
36461 +struct au_lgxattr {
36469 + const char *name;
36476 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
36480 + struct path h_path;
36481 + struct super_block *sb;
36483 + sb = dentry->d_sb;
36484 + reenter = au_smack_reentering(sb);
36486 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36487 + if (unlikely(err))
36490 + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
36491 + if (unlikely(err))
36493 + if (unlikely(!h_path.dentry))
36494 + /* illegally overlapped or something */
36495 + goto out_di; /* pretending success */
36497 + /* always topmost entry only */
36498 + switch (arg->type) {
36499 + case AU_XATTR_LIST:
36500 + err = vfs_listxattr(h_path.dentry,
36501 + arg->u.list.list, arg->u.list.size);
36503 + case AU_XATTR_GET:
36504 + AuDebugOn(d_is_negative(h_path.dentry));
36505 + err = vfs_getxattr(h_path.dentry,
36506 + arg->u.get.name, arg->u.get.value,
36507 + arg->u.get.size);
36513 + di_read_unlock(dentry, AuLock_IR);
36516 + si_read_unlock(sb);
36522 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36524 + struct au_lgxattr arg = {
36525 + .type = AU_XATTR_LIST,
36532 + return au_lgxattr(dentry, &arg);
36535 +static ssize_t au_getxattr(struct dentry *dentry,
36536 + struct inode *inode __maybe_unused,
36537 + const char *name, void *value, size_t size)
36539 + struct au_lgxattr arg = {
36540 + .type = AU_XATTR_GET,
36548 + return au_lgxattr(dentry, &arg);
36551 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36552 + const char *name, const void *value, size_t size,
36555 + struct au_sxattr arg = {
36556 + .type = AU_XATTR_SET,
36565 + return au_sxattr(dentry, inode, &arg);
36568 +/* ---------------------------------------------------------------------- */
36570 +static int au_xattr_get(const struct xattr_handler *handler,
36571 + struct dentry *dentry, struct inode *inode,
36572 + const char *name, void *buffer, size_t size)
36574 + return au_getxattr(dentry, inode, name, buffer, size);
36577 +static int au_xattr_set(const struct xattr_handler *handler,
36578 + struct dentry *dentry, struct inode *inode,
36579 + const char *name, const void *value, size_t size,
36582 + return au_setxattr(dentry, inode, name, value, size, flags);
36585 +static const struct xattr_handler au_xattr_handler = {
36588 + .get = au_xattr_get,
36589 + .set = au_xattr_set
36592 +static const struct xattr_handler *au_xattr_handlers[] = {
36593 +#ifdef CONFIG_FS_POSIX_ACL
36594 + &posix_acl_access_xattr_handler,
36595 + &posix_acl_default_xattr_handler,
36597 + &au_xattr_handler, /* must be last */
36601 +void au_xattr_init(struct super_block *sb)
36603 + sb->s_xattr = au_xattr_handlers;
36605 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36606 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36607 +++ linux/fs/aufs/xino.c 2018-08-12 23:43:05.466791610 +0200
36609 +// SPDX-License-Identifier: GPL-2.0
36611 + * Copyright (C) 2005-2018 Junjiro R. Okajima
36613 + * This program, aufs is free software; you can redistribute it and/or modify
36614 + * it under the terms of the GNU General Public License as published by
36615 + * the Free Software Foundation; either version 2 of the License, or
36616 + * (at your option) any later version.
36618 + * This program is distributed in the hope that it will be useful,
36619 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36620 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36621 + * GNU General Public License for more details.
36623 + * You should have received a copy of the GNU General Public License
36624 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36628 + * external inode number translation table and bitmap
36630 + * things to consider
36632 + * + au_xino object
36633 + * + XINO files (xino, xib, xigen)
36634 + * + dynamic debugfs entries (xiN)
36635 + * + static debugfs entries (xib, xigen)
36636 + * + static sysfs entry (xi_path)
36637 + * - several entry points to handle them.
36638 + * + mount(2) without xino option (default)
36639 + * + mount(2) with xino option
36640 + * + mount(2) with noxino option
36642 + * + remount with add/del branches
36643 + * + remount with xino/noxino options
36646 +#include <linux/seq_file.h>
36647 +#include <linux/statfs.h>
36650 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36651 + aufs_bindex_t bbot,
36652 + struct super_block *h_sb)
36654 + /* todo: try binary-search if the branches are many */
36655 + for (; btop <= bbot; btop++)
36656 + if (h_sb == au_sbr_sb(sb, btop))
36662 + * find another branch who is on the same filesystem of the specified
36663 + * branch{@btgt}. search until @bbot.
36665 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36666 + aufs_bindex_t bbot)
36668 + aufs_bindex_t bindex;
36669 + struct super_block *tgt_sb;
36671 + tgt_sb = au_sbr_sb(sb, btgt);
36672 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36674 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36679 +/* ---------------------------------------------------------------------- */
36682 + * stop unnecessary notify events at creating xino files
36684 +struct au_xino_lock_dir {
36685 + struct au_hinode *hdir;
36686 + struct dentry *parent;
36687 + struct inode *dir;
36690 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
36691 + unsigned int lsc)
36693 + struct dentry *parent;
36694 + struct inode *dir;
36696 + parent = dget_parent(dentry);
36697 + dir = d_inode(parent);
36698 + inode_lock_nested(dir, lsc);
36699 +#if 0 /* it should not happen */
36700 + spin_lock(&dentry->d_lock);
36701 + if (unlikely(dentry->d_parent != parent)) {
36702 + spin_unlock(&dentry->d_lock);
36703 + inode_unlock(dir);
36708 + spin_unlock(&dentry->d_lock);
36715 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
36716 + struct au_xino_lock_dir *ldir)
36718 + aufs_bindex_t brid, bindex;
36720 + ldir->hdir = NULL;
36722 + brid = au_xino_brid(sb);
36724 + bindex = au_br_index(sb, brid);
36725 + if (bindex >= 0) {
36726 + /* rw branch root */
36727 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36728 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36731 + ldir->parent = au_dget_parent_lock(xipath->dentry,
36733 + ldir->dir = d_inode(ldir->parent);
36737 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36740 + au_hn_inode_unlock(ldir->hdir);
36742 + inode_unlock(ldir->dir);
36743 + dput(ldir->parent);
36747 +/* ---------------------------------------------------------------------- */
36750 + * create and set a new xino file
36752 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent)
36754 + struct file *file;
36755 + struct dentry *h_parent, *d;
36756 + struct inode *h_dir, *inode;
36760 + * at mount-time, and the xino file is the default path,
36761 + * hnotify is disabled so we have no notify events to ignore.
36762 + * when a user specified the xino, we cannot get au_hdir to be ignored.
36764 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36765 + /* | __FMODE_NONOTIFY */,
36767 + if (IS_ERR(file)) {
36769 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
36773 + /* keep file count */
36775 + d = file->f_path.dentry;
36776 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
36777 + /* mnt_want_write() is unnecessary here */
36778 + h_dir = d_inode(h_parent);
36779 + inode = file_inode(file);
36780 + /* no delegation since it is just created */
36781 + if (inode->i_nlink)
36782 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
36784 + inode_unlock(h_dir);
36786 + if (unlikely(err)) {
36788 + pr_err("unlink %s(%d)\n", fpath, err);
36793 + if (unlikely(sb == d->d_sb)) {
36795 + pr_err("%s must be outside\n", fpath);
36798 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
36800 + pr_err("xino doesn't support %s(%s)\n",
36801 + fpath, au_sbtype(d->d_sb));
36804 + return file; /* success */
36808 + file = ERR_PTR(err);
36813 + * create a new xinofile at the same place/path as @base.
36815 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
36816 + struct file *copy_src)
36818 + struct file *file;
36819 + struct dentry *dentry, *parent;
36820 + struct inode *dir, *delegated;
36821 + struct qstr *name;
36822 + struct path path;
36823 + int err, do_unlock;
36824 + struct au_xino_lock_dir ldir;
36827 + au_xino_lock_dir(sb, base, &ldir);
36828 + dentry = base->dentry;
36829 + parent = dentry->d_parent; /* dir inode is locked */
36830 + dir = d_inode(parent);
36833 + name = &dentry->d_name;
36834 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
36835 + if (IS_ERR(path.dentry)) {
36836 + file = (void *)path.dentry;
36837 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
36841 + /* no need to mnt_want_write() since we call dentry_open() later */
36842 + err = vfs_create(dir, path.dentry, 0666, NULL);
36843 + if (unlikely(err)) {
36844 + file = ERR_PTR(err);
36845 + pr_err("%pd create err %d\n", dentry, err);
36849 + path.mnt = base->mnt;
36850 + file = vfsub_dentry_open(&path,
36851 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36852 + /* | __FMODE_NONOTIFY */);
36853 + if (IS_ERR(file)) {
36854 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
36858 + delegated = NULL;
36859 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
36860 + au_xino_unlock_dir(&ldir);
36862 + if (unlikely(err == -EWOULDBLOCK)) {
36863 + pr_warn("cannot retry for NFSv4 delegation"
36864 + " for an internal unlink\n");
36867 + if (unlikely(err)) {
36868 + pr_err("%pd unlink err %d\n", dentry, err);
36873 + /* no one can touch copy_src xino */
36874 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
36875 + if (unlikely(err)) {
36876 + pr_err("%pd copy err %d\n", dentry, err);
36880 + goto out_dput; /* success */
36884 + file = ERR_PTR(err);
36886 + dput(path.dentry);
36889 + au_xino_unlock_dir(&ldir);
36893 +/* ---------------------------------------------------------------------- */
36896 + * truncate xino files
36898 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
36901 + unsigned long jiffy;
36903 + aufs_bindex_t bbot;
36904 + struct kstatfs *st;
36905 + struct au_branch *br;
36906 + struct file *new_xino, *file;
36907 + struct path *path;
36910 + st = kmalloc(sizeof(*st), GFP_NOFS);
36911 + if (unlikely(!st))
36915 + bbot = au_sbbot(sb);
36916 + if (unlikely(bindex < 0 || bbot < bindex))
36918 + br = au_sbr(sb, bindex);
36919 + file = au_xino_file(br);
36923 + path = &file->f_path;
36924 + err = vfs_statfs(path, st);
36925 + if (unlikely(err))
36926 + AuErr1("statfs err %d, ignored\n", err);
36928 + blocks = file_inode(file)->i_blocks;
36929 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
36930 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
36932 + new_xino = au_xino_create2(sb, path, file);
36933 + err = PTR_ERR(new_xino);
36934 + if (IS_ERR(new_xino)) {
36935 + pr_err("err %d, ignored\n", err);
36939 + au_xino_file_set(br, new_xino);
36941 + err = vfs_statfs(&new_xino->f_path, st);
36943 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
36944 + bindex, (u64)file_inode(new_xino)->i_blocks,
36945 + st->f_bfree, st->f_blocks);
36946 + if (file_inode(new_xino)->i_blocks < blocks)
36947 + au_sbi(sb)->si_xino_jiffy = jiffy;
36949 + AuErr1("statfs err %d, ignored\n", err);
36958 +struct xino_do_trunc_args {
36959 + struct super_block *sb;
36960 + struct au_branch *br;
36963 +static void xino_do_trunc(void *_args)
36965 + struct xino_do_trunc_args *args = _args;
36966 + struct super_block *sb;
36967 + struct au_branch *br;
36968 + struct inode *dir;
36970 + aufs_bindex_t bindex;
36974 + dir = d_inode(sb->s_root);
36977 + si_noflush_write_lock(sb);
36978 + ii_read_lock_parent(dir);
36979 + bindex = au_br_index(sb, br->br_id);
36980 + err = au_xino_trunc(sb, bindex);
36981 + ii_read_unlock(dir);
36982 + if (unlikely(err))
36983 + pr_warn("err b%d, (%d)\n", bindex, err);
36984 + atomic_dec(&br->br_xino->xi_truncating);
36986 + si_write_unlock(sb);
36987 + au_nwt_done(&au_sbi(sb)->si_nowait);
36991 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
36994 + struct kstatfs st;
36995 + struct au_sbinfo *sbinfo;
36996 + struct file *file;
36998 + /* todo: si_xino_expire and the ratio should be customizable */
36999 + sbinfo = au_sbi(sb);
37000 + if (time_before(jiffies,
37001 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37004 + /* truncation border */
37005 + file = au_xino_file(br);
37006 + AuDebugOn(!file);
37007 + err = vfs_statfs(&file->f_path, &st);
37008 + if (unlikely(err)) {
37009 + AuErr1("statfs err %d, ignored\n", err);
37012 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
37018 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37020 + struct xino_do_trunc_args *args;
37023 + if (!xino_trunc_test(sb, br))
37026 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37029 + /* lock and kfree() will be called in trunc_xino() */
37030 + args = kmalloc(sizeof(*args), GFP_NOFS);
37031 + if (unlikely(!args)) {
37032 + AuErr1("no memory\n");
37039 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37041 + return; /* success */
37043 + pr_err("wkq %d\n", wkq_err);
37048 + atomic_dec(&br->br_xino->xi_truncating);
37051 +/* ---------------------------------------------------------------------- */
37054 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37055 + * at the position of @h_ino.
37057 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37063 + struct au_branch *br;
37064 + struct file *file;
37065 + struct au_sbinfo *sbinfo;
37068 + if (!au_opt_test(au_mntflags(sb), XINO))
37069 + return 0; /* no xino */
37072 + sbinfo = au_sbi(sb);
37074 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
37075 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
37078 + pos *= sizeof(*ino);
37080 + br = au_sbr(sb, bindex);
37081 + file = au_xino_file(br);
37082 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
37083 + return 0; /* no ino */
37085 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
37086 + if (sz == sizeof(*ino))
37087 + return 0; /* success */
37090 + if (unlikely(sz >= 0)) {
37092 + AuIOErr("xino read error (%zd)\n", sz);
37098 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37099 + ino_t h_ino, ino_t ino)
37105 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
37106 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
37109 + pos *= sizeof(ino);
37110 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
37111 + if (sz == sizeof(ino))
37112 + return 0; /* success */
37114 + AuIOErr("write failed (%zd)\n", sz);
37119 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37120 + * at the position of @h_ino.
37121 + * even if @ino is zero, it is written to the xinofile and means no entry.
37122 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37123 + * try truncating it.
37125 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37129 + unsigned int mnt_flags;
37130 + struct au_branch *br;
37132 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
37133 + || ((loff_t)-1) > 0);
37134 + SiMustAnyLock(sb);
37136 + mnt_flags = au_mntflags(sb);
37137 + if (!au_opt_test(mnt_flags, XINO))
37140 + br = au_sbr(sb, bindex);
37141 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, au_xino_file(br), h_ino,
37144 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37145 + && au_test_fs_trunc_xino(au_br_sb(br)))
37146 + xino_try_trunc(sb, br);
37147 + return 0; /* success */
37150 + AuIOErr("write failed (%d)\n", err);
37154 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37155 + size_t size, loff_t *pos);
37157 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37158 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
37162 + mm_segment_t oldfs;
37168 + const int prevent_endless = 10;
37172 + oldfs = get_fs();
37173 + set_fs(KERNEL_DS);
37175 + err = func(file, buf.u, size, pos);
37176 + if (err == -EINTR
37177 + && !au_wkq_test()
37178 + && fatal_signal_pending(current)) {
37180 + err = xino_fread_wkq(func, file, kbuf, size, pos);
37181 + BUG_ON(err == -EINTR);
37182 + oldfs = get_fs();
37183 + set_fs(KERNEL_DS);
37185 + } while (i++ < prevent_endless
37186 + && (err == -EAGAIN || err == -EINTR));
37189 +#if 0 /* reserved for future use */
37191 + fsnotify_access(file->f_path.dentry);
37197 +struct xino_fread_args {
37199 + vfs_readf_t func;
37200 + struct file *file;
37206 +static void call_xino_fread(void *args)
37208 + struct xino_fread_args *a = args;
37209 + *a->errp = xino_fread(a->func, a->file, a->buf, a->size, a->pos);
37212 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37213 + size_t size, loff_t *pos)
37217 + struct xino_fread_args args = {
37226 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37227 + if (unlikely(wkq_err))
37233 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37234 + size_t size, loff_t *pos);
37236 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
37237 + size_t size, loff_t *pos)
37240 + mm_segment_t oldfs;
37243 + const char __user *u;
37246 + const int prevent_endless = 10;
37250 + oldfs = get_fs();
37251 + set_fs(KERNEL_DS);
37253 + err = func(file, buf.u, size, pos);
37254 + if (err == -EINTR
37255 + && !au_wkq_test()
37256 + && fatal_signal_pending(current)) {
37258 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
37259 + BUG_ON(err == -EINTR);
37260 + oldfs = get_fs();
37261 + set_fs(KERNEL_DS);
37263 + } while (i++ < prevent_endless
37264 + && (err == -EAGAIN || err == -EINTR));
37267 +#if 0 /* reserved for future use */
37269 + fsnotify_modify(file->f_path.dentry);
37275 +struct do_xino_fwrite_args {
37277 + vfs_writef_t func;
37278 + struct file *file;
37284 +static void call_do_xino_fwrite(void *args)
37286 + struct do_xino_fwrite_args *a = args;
37287 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
37290 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37291 + size_t size, loff_t *pos)
37295 + struct do_xino_fwrite_args args = {
37305 + * it breaks RLIMIT_FSIZE and normal user's limit,
37306 + * users should care about quota and real 'filesystem full.'
37308 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37309 + if (unlikely(wkq_err))
37315 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
37316 + size_t size, loff_t *pos)
37320 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37322 + err = do_xino_fwrite(func, file, buf, size, pos);
37326 + err = xino_fwrite_wkq(func, file, buf, size, pos);
37333 +/* ---------------------------------------------------------------------- */
37336 + * inode number bitmap
37338 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37339 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37343 + AuDebugOn(bit < 0 || page_bits <= bit);
37344 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37348 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37350 + AuDebugOn(ino < AUFS_FIRST_INO);
37351 + ino -= AUFS_FIRST_INO;
37352 + *pindex = ino / page_bits;
37353 + *bit = ino % page_bits;
37356 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37361 + struct au_sbinfo *sbinfo;
37362 + struct file *xib;
37363 + unsigned long *p;
37365 + sbinfo = au_sbi(sb);
37366 + MtxMustLock(&sbinfo->si_xib_mtx);
37367 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37368 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37370 + if (pindex == sbinfo->si_xib_last_pindex)
37373 + xib = sbinfo->si_xib;
37374 + p = sbinfo->si_xib_buf;
37375 + pos = sbinfo->si_xib_last_pindex;
37376 + pos *= PAGE_SIZE;
37377 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37378 + if (unlikely(sz != PAGE_SIZE))
37382 + pos *= PAGE_SIZE;
37383 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37384 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
37386 + memset(p, 0, PAGE_SIZE);
37387 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37389 + if (sz == PAGE_SIZE) {
37390 + sbinfo->si_xib_last_pindex = pindex;
37391 + return 0; /* success */
37395 + AuIOErr1("write failed (%zd)\n", sz);
37402 +static void au_xib_clear_bit(struct inode *inode)
37405 + unsigned long pindex;
37406 + struct super_block *sb;
37407 + struct au_sbinfo *sbinfo;
37409 + AuDebugOn(inode->i_nlink);
37411 + sb = inode->i_sb;
37412 + xib_calc_bit(inode->i_ino, &pindex, &bit);
37413 + AuDebugOn(page_bits <= bit);
37414 + sbinfo = au_sbi(sb);
37415 + mutex_lock(&sbinfo->si_xib_mtx);
37416 + err = xib_pindex(sb, pindex);
37418 + clear_bit(bit, sbinfo->si_xib_buf);
37419 + sbinfo->si_xib_next_bit = bit;
37421 + mutex_unlock(&sbinfo->si_xib_mtx);
37424 +/* ---------------------------------------------------------------------- */
37427 + * truncate a xino bitmap file
37431 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
37435 + unsigned long pindex;
37436 + loff_t pos, pend;
37437 + struct au_sbinfo *sbinfo;
37438 + vfs_readf_t func;
37440 + unsigned long *p;
37443 + sbinfo = au_sbi(sb);
37444 + MtxMustLock(&sbinfo->si_xib_mtx);
37445 + p = sbinfo->si_xib_buf;
37446 + func = sbinfo->si_xread;
37447 + pend = vfsub_f_size_read(file);
37449 + while (pos < pend) {
37450 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
37452 + if (unlikely(sz <= 0))
37456 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
37457 + if (unlikely(*ino < AUFS_FIRST_INO))
37460 + xib_calc_bit(*ino, &pindex, &bit);
37461 + AuDebugOn(page_bits <= bit);
37462 + err = xib_pindex(sb, pindex);
37474 +static int xib_restore(struct super_block *sb)
37477 + aufs_bindex_t bindex, bbot;
37479 + struct au_branch *br;
37482 + page = (void *)__get_free_page(GFP_NOFS);
37483 + if (unlikely(!page))
37487 + bbot = au_sbbot(sb);
37488 + for (bindex = 0; !err && bindex <= bbot; bindex++)
37489 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
37490 + br = au_sbr(sb, bindex);
37491 + err = do_xib_restore(sb, au_xino_file(br), page);
37493 + AuDbg("skip shared b%d\n", bindex);
37494 + free_page((unsigned long)page);
37500 +int au_xib_trunc(struct super_block *sb)
37505 + struct au_sbinfo *sbinfo;
37506 + unsigned long *p;
37507 + struct file *file;
37509 + SiMustWriteLock(sb);
37512 + sbinfo = au_sbi(sb);
37513 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
37516 + file = sbinfo->si_xib;
37517 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
37520 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
37521 + err = PTR_ERR(file);
37522 + if (IS_ERR(file))
37524 + fput(sbinfo->si_xib);
37525 + sbinfo->si_xib = file;
37527 + p = sbinfo->si_xib_buf;
37528 + memset(p, 0, PAGE_SIZE);
37530 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
37531 + if (unlikely(sz != PAGE_SIZE)) {
37533 + AuIOErr("err %d\n", err);
37539 + mutex_lock(&sbinfo->si_xib_mtx);
37540 + /* mnt_want_write() is unnecessary here */
37541 + err = xib_restore(sb);
37542 + mutex_unlock(&sbinfo->si_xib_mtx);
37548 +/* ---------------------------------------------------------------------- */
37550 +struct au_xino *au_xino_alloc(void)
37552 + struct au_xino *xi;
37554 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
37555 + if (unlikely(!xi))
37558 + xi->xi_nondir.total = 8; /* initial size */
37559 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
37561 + if (unlikely(!xi->xi_nondir.array))
37564 + spin_lock_init(&xi->xi_nondir.spin);
37565 + init_waitqueue_head(&xi->xi_nondir.wqh);
37566 + atomic_set(&xi->xi_truncating, 0);
37567 + kref_init(&xi->xi_kref);
37568 + goto out; /* success */
37577 +static int au_xino_init(struct au_branch *br, struct file *file)
37580 + struct au_xino *xi;
37583 + xi = au_xino_alloc();
37584 + if (unlikely(!xi)) {
37590 + xi->xi_file = file;
37591 + AuDebugOn(br->br_xino);
37592 + br->br_xino = xi;
37598 +static void au_xino_release(struct kref *kref)
37600 + struct au_xino *xi;
37603 + xi = container_of(kref, struct au_xino, xi_kref);
37605 + fput(xi->xi_file);
37606 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
37607 + AuDebugOn(xi->xi_nondir.array[i]);
37608 + kfree(xi->xi_nondir.array);
37612 +int au_xino_put(struct au_branch *br)
37615 + struct au_xino *xi;
37618 + xi = br->br_xino;
37620 + br->br_xino = NULL;
37621 + ret = kref_put(&xi->xi_kref, au_xino_release);
37627 +void au_xino_file_set(struct au_branch *br, struct file *file)
37629 + struct au_xino *xi;
37634 + xi = br->br_xino;
37639 + xi->xi_file = file;
37642 +/* ---------------------------------------------------------------------- */
37645 + * xino mount option handlers
37649 +static void xino_clear_xib(struct super_block *sb)
37651 + struct au_sbinfo *sbinfo;
37653 + SiMustWriteLock(sb);
37655 + sbinfo = au_sbi(sb);
37656 + /* unnecessary to clear sbinfo->si_xread and ->si_xwrite */
37657 + if (sbinfo->si_xib)
37658 + fput(sbinfo->si_xib);
37659 + sbinfo->si_xib = NULL;
37660 + if (sbinfo->si_xib_buf)
37661 + free_page((unsigned long)sbinfo->si_xib_buf);
37662 + sbinfo->si_xib_buf = NULL;
37665 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
37669 + struct au_sbinfo *sbinfo;
37670 + struct file *file;
37672 + SiMustWriteLock(sb);
37674 + sbinfo = au_sbi(sb);
37675 + file = au_xino_create2(sb, path, sbinfo->si_xib);
37676 + err = PTR_ERR(file);
37677 + if (IS_ERR(file))
37679 + if (sbinfo->si_xib)
37680 + fput(sbinfo->si_xib);
37681 + sbinfo->si_xib = file;
37682 + sbinfo->si_xread = vfs_readf(file);
37683 + sbinfo->si_xwrite = vfs_writef(file);
37686 + if (!sbinfo->si_xib_buf)
37687 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
37688 + if (unlikely(!sbinfo->si_xib_buf))
37691 + sbinfo->si_xib_last_pindex = 0;
37692 + sbinfo->si_xib_next_bit = 0;
37693 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
37695 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
37696 + PAGE_SIZE, &pos);
37697 + if (unlikely(err != PAGE_SIZE))
37701 + goto out; /* success */
37704 + if (sbinfo->si_xib_buf)
37705 + free_page((unsigned long)sbinfo->si_xib_buf);
37706 + sbinfo->si_xib_buf = NULL;
37710 + fput(sbinfo->si_xib);
37711 + sbinfo->si_xib = NULL;
37717 +/* xino for each branch */
37718 +static void xino_clear_br(struct super_block *sb)
37720 + aufs_bindex_t bindex, bbot;
37721 + struct au_branch *br;
37723 + bbot = au_sbbot(sb);
37724 + for (bindex = 0; bindex <= bbot; bindex++) {
37725 + br = au_sbr(sb, bindex);
37731 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
37732 + aufs_bindex_t bshared)
37734 + struct au_branch *brshared;
37736 + brshared = au_sbr(sb, bshared);
37737 + AuDebugOn(!brshared->br_xino);
37738 + AuDebugOn(!brshared->br_xino->xi_file);
37739 + if (br->br_xino != brshared->br_xino) {
37740 + au_xino_get(brshared);
37742 + br->br_xino = brshared->br_xino;
37746 +struct au_xino_do_set_br {
37747 + vfs_writef_t writef;
37748 + struct au_branch *br;
37750 + aufs_bindex_t bshared;
37753 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
37754 + struct au_xino_do_set_br *args)
37757 + struct file *file;
37759 + if (args->bshared >= 0) {
37760 + /* shared xino */
37761 + au_xino_set_br_shared(sb, args->br, args->bshared);
37762 + file = au_xino_file(args->br);
37763 + goto out_ino; /* success */
37767 + file = au_xino_create2(sb, path, au_xino_file(args->br));
37768 + err = PTR_ERR(file);
37769 + if (IS_ERR(file))
37771 + if (!args->br->br_xino) {
37772 + err = au_xino_init(args->br, file);
37774 + if (unlikely(err))
37777 + au_xino_file_set(args->br, file);
37782 + err = au_xino_do_write(args->writef, file, args->h_ino, AUFS_ROOT_INO);
37788 +static int au_xino_set_br(struct super_block *sb, struct path *path)
37791 + aufs_bindex_t bindex, bbot;
37792 + struct au_xino_do_set_br args;
37793 + struct inode *inode;
37795 + SiMustWriteLock(sb);
37797 + bbot = au_sbbot(sb);
37798 + inode = d_inode(sb->s_root);
37799 + args.writef = au_sbi(sb)->si_xwrite;
37800 + for (bindex = 0; bindex <= bbot; bindex++) {
37801 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
37802 + args.br = au_sbr(sb, bindex);
37803 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
37804 + err = au_xino_do_set_br(sb, path, &args);
37805 + if (unlikely(err))
37813 +void au_xino_clr(struct super_block *sb)
37815 + struct au_sbinfo *sbinfo;
37817 + au_xigen_clr(sb);
37818 + xino_clear_xib(sb);
37819 + xino_clear_br(sb);
37820 + dbgaufs_brs_del(sb, 0);
37821 + au_xino_brid_set(sb, -1);
37822 + sbinfo = au_sbi(sb);
37823 + /* lvalue, do not call au_mntflags() */
37824 + au_opt_clr(sbinfo->si_mntflags, XINO);
37827 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
37830 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
37831 + struct qstr *dname, *cur_name;
37832 + struct file *cur_xino;
37833 + struct au_sbinfo *sbinfo;
37834 + struct path *path, *cur_path;
37836 + SiMustWriteLock(sb);
37839 + sbinfo = au_sbi(sb);
37840 + path = &xiopt->file->f_path;
37841 + dentry = path->dentry;
37842 + parent = dget_parent(dentry);
37845 + cur_xino = sbinfo->si_xib;
37847 + cur_path = &cur_xino->f_path;
37848 + cur_dentry = cur_path->dentry;
37849 + cur_parent = dget_parent(cur_dentry);
37850 + cur_name = &cur_dentry->d_name;
37851 + dname = &dentry->d_name;
37852 + skip = (cur_parent == parent
37853 + && au_qstreq(dname, cur_name));
37854 + dput(cur_parent);
37860 + au_opt_set(sbinfo->si_mntflags, XINO);
37861 + err = au_xino_set_xib(sb, path);
37862 + /* si_x{read,write} are set */
37864 + err = au_xigen_set(sb, path);
37866 + err = au_xino_set_br(sb, path);
37868 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
37869 + goto out; /* success */
37873 + AuIOErr("failed setting xino(%d).\n", err);
37882 + * create a xinofile at the default place/path.
37884 +struct file *au_xino_def(struct super_block *sb)
37886 + struct file *file;
37888 + struct au_branch *br;
37889 + struct super_block *h_sb;
37890 + struct path path;
37891 + aufs_bindex_t bbot, bindex, bwr;
37894 + bbot = au_sbbot(sb);
37896 + for (bindex = 0; bindex <= bbot; bindex++) {
37897 + br = au_sbr(sb, bindex);
37898 + if (au_br_writable(br->br_perm)
37899 + && !au_test_fs_bad_xino(au_br_sb(br))) {
37906 + file = ERR_PTR(-ENOMEM);
37907 + page = (void *)__get_free_page(GFP_NOFS);
37908 + if (unlikely(!page))
37910 + path.mnt = au_br_mnt(br);
37911 + path.dentry = au_h_dptr(sb->s_root, bwr);
37912 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
37913 + file = (void *)p;
37914 + if (!IS_ERR(p)) {
37915 + strcat(p, "/" AUFS_XINO_FNAME);
37916 + AuDbg("%s\n", p);
37917 + file = au_xino_create(sb, p, /*silent*/0);
37918 + if (!IS_ERR(file))
37919 + au_xino_brid_set(sb, br->br_id);
37921 + free_page((unsigned long)page);
37923 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
37924 + if (IS_ERR(file))
37926 + h_sb = file->f_path.dentry->d_sb;
37927 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
37928 + pr_err("xino doesn't support %s(%s)\n",
37929 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
37931 + file = ERR_PTR(-EINVAL);
37933 + if (!IS_ERR(file))
37934 + au_xino_brid_set(sb, -1);
37941 +/* ---------------------------------------------------------------------- */
37944 + * initialize the xinofile for the specified branch @br
37945 + * at the place/path where @base_file indicates.
37946 + * test whether another branch is on the same filesystem or not,
37947 + * if found then share the xinofile with another branch.
37949 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
37950 + struct path *base)
37953 + struct au_xino_do_set_br args = {
37958 + args.writef = au_sbi(sb)->si_xwrite;
37959 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
37961 + err = au_xino_do_set_br(sb, base, &args);
37962 + if (unlikely(err))
37968 +/* ---------------------------------------------------------------------- */
37971 + * get an unused inode number from bitmap
37973 +ino_t au_xino_new_ino(struct super_block *sb)
37976 + unsigned long *p, pindex, ul, pend;
37977 + struct au_sbinfo *sbinfo;
37978 + struct file *file;
37979 + int free_bit, err;
37981 + if (!au_opt_test(au_mntflags(sb), XINO))
37982 + return iunique(sb, AUFS_FIRST_INO);
37984 + sbinfo = au_sbi(sb);
37985 + mutex_lock(&sbinfo->si_xib_mtx);
37986 + p = sbinfo->si_xib_buf;
37987 + free_bit = sbinfo->si_xib_next_bit;
37988 + if (free_bit < page_bits && !test_bit(free_bit, p))
37989 + goto out; /* success */
37990 + free_bit = find_first_zero_bit(p, page_bits);
37991 + if (free_bit < page_bits)
37992 + goto out; /* success */
37994 + pindex = sbinfo->si_xib_last_pindex;
37995 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
37996 + err = xib_pindex(sb, ul);
37997 + if (unlikely(err))
37999 + free_bit = find_first_zero_bit(p, page_bits);
38000 + if (free_bit < page_bits)
38001 + goto out; /* success */
38004 + file = sbinfo->si_xib;
38005 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38006 + for (ul = pindex + 1; ul <= pend; ul++) {
38007 + err = xib_pindex(sb, ul);
38008 + if (unlikely(err))
38010 + free_bit = find_first_zero_bit(p, page_bits);
38011 + if (free_bit < page_bits)
38012 + goto out; /* success */
38017 + set_bit(free_bit, p);
38018 + sbinfo->si_xib_next_bit = free_bit + 1;
38019 + pindex = sbinfo->si_xib_last_pindex;
38020 + mutex_unlock(&sbinfo->si_xib_mtx);
38021 + ino = xib_calc_ino(pindex, free_bit);
38022 + AuDbg("i%lu\n", (unsigned long)ino);
38025 + mutex_unlock(&sbinfo->si_xib_mtx);
38030 +/* for s_op->delete_inode() */
38031 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38034 + unsigned int mnt_flags;
38035 + aufs_bindex_t bindex, bbot, bi;
38036 + unsigned char try_trunc;
38037 + struct au_iinfo *iinfo;
38038 + struct super_block *sb;
38039 + struct au_hinode *hi;
38040 + struct inode *h_inode;
38041 + struct au_branch *br;
38042 + vfs_writef_t xwrite;
38044 + AuDebugOn(au_is_bad_inode(inode));
38046 + sb = inode->i_sb;
38047 + mnt_flags = au_mntflags(sb);
38048 + if (!au_opt_test(mnt_flags, XINO)
38049 + || inode->i_ino == AUFS_ROOT_INO)
38053 + au_xigen_inc(inode);
38054 + au_xib_clear_bit(inode);
38057 + iinfo = au_ii(inode);
38058 + bindex = iinfo->ii_btop;
38062 + xwrite = au_sbi(sb)->si_xwrite;
38063 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38064 + hi = au_hinode(iinfo, bindex);
38065 + bbot = iinfo->ii_bbot;
38066 + for (; bindex <= bbot; bindex++, hi++) {
38067 + h_inode = hi->hi_inode;
38069 + || (!unlinked && h_inode->i_nlink))
38072 + /* inode may not be revalidated */
38073 + bi = au_br_index(sb, hi->hi_id);
38077 + br = au_sbr(sb, bi);
38078 + err = au_xino_do_write(xwrite, au_xino_file(br),
38079 + h_inode->i_ino, /*ino*/0);
38080 + if (!err && try_trunc
38081 + && au_test_fs_trunc_xino(au_br_sb(br)))
38082 + xino_try_trunc(sb, br);
38086 +/* ---------------------------------------------------------------------- */
38088 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38090 + int found, total, i;
38093 + total = xi->xi_nondir.total;
38094 + for (i = 0; i < total; i++) {
38095 + if (xi->xi_nondir.array[i] != h_ino)
38104 +static int au_xinondir_expand(struct au_xino *xi)
38109 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38112 + sz = xi->xi_nondir.total * sizeof(ino_t);
38113 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38115 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38116 + /*may_shrink*/0);
38118 + xi->xi_nondir.array = p;
38119 + xi->xi_nondir.total <<= 1;
38120 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38128 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38129 + ino_t h_ino, int idx)
38131 + struct au_xino *xi;
38133 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38134 + xi = au_sbr(sb, bindex)->br_xino;
38135 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38137 + spin_lock(&xi->xi_nondir.spin);
38138 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38139 + xi->xi_nondir.array[idx] = 0;
38140 + spin_unlock(&xi->xi_nondir.spin);
38141 + wake_up_all(&xi->xi_nondir.wqh);
38144 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38147 + int err, found, empty;
38148 + struct au_xino *xi;
38152 + if (!au_opt_test(au_mntflags(sb), XINO))
38153 + goto out; /* no xino */
38155 + xi = au_sbr(sb, bindex)->br_xino;
38158 + spin_lock(&xi->xi_nondir.spin);
38159 + found = au_xinondir_find(xi, h_ino);
38160 + if (found == -1) {
38161 + empty = au_xinondir_find(xi, /*h_ino*/0);
38162 + if (empty == -1) {
38163 + empty = xi->xi_nondir.total;
38164 + err = au_xinondir_expand(xi);
38165 + if (unlikely(err))
38168 + xi->xi_nondir.array[empty] = h_ino;
38171 + spin_unlock(&xi->xi_nondir.spin);
38172 + wait_event(xi->xi_nondir.wqh,
38173 + xi->xi_nondir.array[found] != h_ino);
38178 + spin_unlock(&xi->xi_nondir.spin);
38183 +/* ---------------------------------------------------------------------- */
38185 +int au_xino_path(struct seq_file *seq, struct file *file)
38189 + err = au_seq_path(seq, &file->f_path);
38190 + if (unlikely(err))
38193 +#define Deleted "\\040(deleted)"
38194 + seq->count -= sizeof(Deleted) - 1;
38195 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38196 + sizeof(Deleted) - 1));
38202 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38203 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38204 +++ linux/include/uapi/linux/aufs_type.h 2018-08-12 23:43:05.466791610 +0200
38206 +/* SPDX-License-Identifier: GPL-2.0 */
38208 + * Copyright (C) 2005-2018 Junjiro R. Okajima
38210 + * This program, aufs is free software; you can redistribute it and/or modify
38211 + * it under the terms of the GNU General Public License as published by
38212 + * the Free Software Foundation; either version 2 of the License, or
38213 + * (at your option) any later version.
38215 + * This program is distributed in the hope that it will be useful,
38216 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38217 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38218 + * GNU General Public License for more details.
38220 + * You should have received a copy of the GNU General Public License
38221 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38224 +#ifndef __AUFS_TYPE_H__
38225 +#define __AUFS_TYPE_H__
38227 +#define AUFS_NAME "aufs"
38231 + * define it before including all other headers.
38232 + * sched.h may use pr_* macros before defining "current", so define the
38233 + * no-current version first, and re-define later.
38235 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38236 +#include <linux/sched.h>
38238 +#define pr_fmt(fmt) \
38239 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38240 + (int)sizeof(current->comm), current->comm, current->pid
38242 +#include <stdint.h>
38243 +#include <sys/types.h>
38244 +#endif /* __KERNEL__ */
38246 +#include <linux/limits.h>
38248 +#define AUFS_VERSION "4.x-rcN-20180730"
38250 +/* todo? move this to linux-2.6.19/include/magic.h */
38251 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38253 +/* ---------------------------------------------------------------------- */
38255 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38256 +typedef int8_t aufs_bindex_t;
38257 +#define AUFS_BRANCH_MAX 127
38259 +typedef int16_t aufs_bindex_t;
38260 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38261 +#define AUFS_BRANCH_MAX 511
38262 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38263 +#define AUFS_BRANCH_MAX 1023
38264 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38265 +#define AUFS_BRANCH_MAX 32767
38270 +#ifndef AUFS_BRANCH_MAX
38271 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38273 +#endif /* __KERNEL__ */
38275 +/* ---------------------------------------------------------------------- */
38277 +#define AUFS_FSTYPE AUFS_NAME
38279 +#define AUFS_ROOT_INO 2
38280 +#define AUFS_FIRST_INO 11
38282 +#define AUFS_WH_PFX ".wh."
38283 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38284 +#define AUFS_WH_TMP_LEN 4
38285 +/* a limit for rmdir/rename a dir and copyup */
38286 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38287 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38289 + - AUFS_WH_TMP_LEN) /* hex */
38290 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38291 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38292 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38293 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38294 +#define AUFS_DIRWH_DEF 3
38295 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38296 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38297 +#define AUFS_RDBLK_DEF 512 /* bytes */
38298 +#define AUFS_RDHASH_DEF 32
38299 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38300 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38301 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38302 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38303 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38305 +/* pseudo-link maintenace under /proc */
38306 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38307 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38308 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38310 +/* dirren, renamed dir */
38311 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38312 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38313 +/* whiteouted doubly */
38314 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38315 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38317 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38318 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38320 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38321 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38322 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38324 +/* doubly whiteouted */
38325 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38326 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38327 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38329 +/* branch permissions and attributes */
38330 +#define AUFS_BRPERM_RW "rw"
38331 +#define AUFS_BRPERM_RO "ro"
38332 +#define AUFS_BRPERM_RR "rr"
38333 +#define AUFS_BRATTR_COO_REG "coo_reg"
38334 +#define AUFS_BRATTR_COO_ALL "coo_all"
38335 +#define AUFS_BRATTR_FHSM "fhsm"
38336 +#define AUFS_BRATTR_UNPIN "unpin"
38337 +#define AUFS_BRATTR_ICEX "icex"
38338 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38339 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38340 +#define AUFS_BRATTR_ICEX_TR "icextr"
38341 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38342 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38343 +#define AUFS_BRRATTR_WH "wh"
38344 +#define AUFS_BRWATTR_NLWH "nolwh"
38345 +#define AUFS_BRWATTR_MOO "moo"
38347 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38348 +#define AuBrPerm_RO (1 << 1) /* readonly */
38349 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38350 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38352 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38353 +#define AuBrAttr_COO_ALL (1 << 4)
38354 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38356 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38357 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38358 + branch. meaningless since
38359 + linux-3.18-rc1 */
38361 +/* ignore error in copying XATTR */
38362 +#define AuBrAttr_ICEX_SEC (1 << 7)
38363 +#define AuBrAttr_ICEX_SYS (1 << 8)
38364 +#define AuBrAttr_ICEX_TR (1 << 9)
38365 +#define AuBrAttr_ICEX_USR (1 << 10)
38366 +#define AuBrAttr_ICEX_OTH (1 << 11)
38367 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38368 + | AuBrAttr_ICEX_SYS \
38369 + | AuBrAttr_ICEX_TR \
38370 + | AuBrAttr_ICEX_USR \
38371 + | AuBrAttr_ICEX_OTH)
38373 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
38374 +#define AuBrRAttr_Mask AuBrRAttr_WH
38376 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
38377 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
38378 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
38380 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
38382 +/* #warning test userspace */
38384 +#ifndef CONFIG_AUFS_FHSM
38385 +#undef AuBrAttr_FHSM
38386 +#define AuBrAttr_FHSM 0
38388 +#ifndef CONFIG_AUFS_XATTR
38389 +#undef AuBrAttr_ICEX
38390 +#define AuBrAttr_ICEX 0
38391 +#undef AuBrAttr_ICEX_SEC
38392 +#define AuBrAttr_ICEX_SEC 0
38393 +#undef AuBrAttr_ICEX_SYS
38394 +#define AuBrAttr_ICEX_SYS 0
38395 +#undef AuBrAttr_ICEX_TR
38396 +#define AuBrAttr_ICEX_TR 0
38397 +#undef AuBrAttr_ICEX_USR
38398 +#define AuBrAttr_ICEX_USR 0
38399 +#undef AuBrAttr_ICEX_OTH
38400 +#define AuBrAttr_ICEX_OTH 0
38404 +/* the longest combination */
38405 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
38406 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
38407 + "+" AUFS_BRATTR_COO_REG \
38408 + "+" AUFS_BRATTR_FHSM \
38409 + "+" AUFS_BRATTR_UNPIN \
38410 + "+" AUFS_BRATTR_ICEX_SEC \
38411 + "+" AUFS_BRATTR_ICEX_SYS \
38412 + "+" AUFS_BRATTR_ICEX_USR \
38413 + "+" AUFS_BRATTR_ICEX_OTH \
38414 + "+" AUFS_BRWATTR_NLWH)
38417 + char a[AuBrPermStrSz];
38418 +} au_br_perm_str_t;
38420 +static inline int au_br_writable(int brperm)
38422 + return brperm & AuBrPerm_RW;
38425 +static inline int au_br_whable(int brperm)
38427 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
38430 +static inline int au_br_wh_linkable(int brperm)
38432 + return !(brperm & AuBrWAttr_NoLinkWH);
38435 +static inline int au_br_cmoo(int brperm)
38437 + return brperm & AuBrAttr_CMOO_Mask;
38440 +static inline int au_br_fhsm(int brperm)
38442 + return brperm & AuBrAttr_FHSM;
38445 +/* ---------------------------------------------------------------------- */
38449 + /* readdir in userspace */
38453 + AuCtl_WBR_FD, /* pathconf wrapper */
38454 + AuCtl_IBUSY, /* busy inode */
38455 + AuCtl_MVDOWN, /* move-down */
38456 + AuCtl_BR, /* info about branches */
38457 + AuCtl_FHSM_FD /* connection for fhsm */
38460 +/* borrowed from linux/include/linux/kernel.h */
38462 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
38463 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
38466 +/* borrowed from linux/include/linux/compiler-gcc3.h */
38468 +#define __aligned(x) __attribute__((aligned(x)))
38473 +#define __packed __attribute__((packed))
38477 +struct au_rdu_cookie {
38482 + uint32_t generation;
38485 +struct au_rdu_ent {
38494 +static inline int au_rdu_len(int nlen)
38496 + /* include the terminating NULL */
38497 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
38498 + sizeof(uint64_t));
38501 +union au_rdu_ent_ul {
38502 + struct au_rdu_ent __user *e;
38514 + uint64_t sz; /* AuCtl_RDU */
38515 + uint64_t nent; /* AuCtl_RDU_INO */
38517 + union au_rdu_ent_ul ent;
38518 + uint16_t verify[AufsCtlRduV_End];
38520 + /* input/output */
38524 + union au_rdu_ent_ul tail;
38525 + /* number of entries which were added in a single call */
38530 + struct au_rdu_cookie cookie;
38533 +/* ---------------------------------------------------------------------- */
38535 +/* dirren. the branch is identified by the filename who contains this */
38536 +struct au_drinfo {
38539 + uint8_t oldnamelen;
38540 + uint64_t _padding;
38542 + uint8_t oldname[0];
38545 +struct au_drinfo_fdata {
38547 + struct au_drinfo drinfo;
38550 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
38552 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
38554 +/* ---------------------------------------------------------------------- */
38556 +struct aufs_wbr_fd {
38561 +/* ---------------------------------------------------------------------- */
38563 +struct aufs_ibusy {
38564 + uint64_t ino, h_ino;
38568 +/* ---------------------------------------------------------------------- */
38570 +/* error code for move-down */
38571 +/* the actual message strings are implemented in aufs-util.git */
38573 + EAU_MVDOWN_OPAQUE = 1,
38574 + EAU_MVDOWN_WHITEOUT,
38575 + EAU_MVDOWN_UPPER,
38576 + EAU_MVDOWN_BOTTOM,
38577 + EAU_MVDOWN_NOUPPER,
38578 + EAU_MVDOWN_NOLOWERBR,
38582 +/* flags for move-down */
38583 +#define AUFS_MVDOWN_DMSG 1
38584 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
38585 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
38586 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
38587 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
38588 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
38589 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
38590 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
38591 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
38592 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
38593 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
38594 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
38595 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
38597 +/* index for move-down */
38599 + AUFS_MVDOWN_UPPER,
38600 + AUFS_MVDOWN_LOWER,
38601 + AUFS_MVDOWN_NARRAY
38605 + * additional info of move-down
38606 + * number of free blocks and inodes.
38607 + * subset of struct kstatfs, but smaller and always 64bit.
38609 +struct aufs_stfs {
38610 + uint64_t f_blocks;
38611 + uint64_t f_bavail;
38612 + uint64_t f_files;
38613 + uint64_t f_ffree;
38616 +struct aufs_stbr {
38617 + int16_t brid; /* optional input */
38618 + int16_t bindex; /* output */
38619 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
38622 +struct aufs_mvdown {
38623 + uint32_t flags; /* input/output */
38624 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
38625 + int8_t au_errno; /* output */
38628 +/* ---------------------------------------------------------------------- */
38630 +union aufs_brinfo {
38631 + /* PATH_MAX may differ between kernel-space and user-space */
38632 + char _spacer[4096];
38640 +/* ---------------------------------------------------------------------- */
38642 +#define AuCtlType 'A'
38643 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
38644 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
38645 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
38646 + struct aufs_wbr_fd)
38647 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
38648 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
38649 + struct aufs_mvdown)
38650 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
38651 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
38653 +#endif /* __AUFS_TYPE_H__ */
38654 SPDX-License-Identifier: GPL-2.0
38655 aufs4.x-rcN loopback patch
38657 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38658 index 5678bf8..ec9c4fb 100644
38659 --- a/drivers/block/loop.c
38660 +++ b/drivers/block/loop.c
38661 @@ -626,6 +626,15 @@ static inline void loop_update_dio(struct loop_device *lo)
38665 +static struct file *loop_real_file(struct file *file)
38667 + struct file *f = NULL;
38669 + if (file->f_path.dentry->d_sb->s_op->real_loop)
38670 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
38674 static void loop_reread_partitions(struct loop_device *lo,
38675 struct block_device *bdev)
38677 @@ -690,6 +699,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
38680 struct file *file, *old_file;
38681 + struct file *f, *virt_file = NULL, *old_virt_file;
38682 struct inode *inode;
38685 @@ -706,6 +716,12 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
38689 + f = loop_real_file(file);
38691 + virt_file = file;
38696 error = loop_validate_file(file, bdev);
38698 @@ -713,6 +729,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
38700 inode = file->f_mapping->host;
38701 old_file = lo->lo_backing_file;
38702 + old_virt_file = lo->lo_backing_virt_file;
38706 @@ -724,6 +741,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
38707 blk_mq_freeze_queue(lo->lo_queue);
38708 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
38709 lo->lo_backing_file = file;
38710 + lo->lo_backing_virt_file = virt_file;
38711 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
38712 mapping_set_gfp_mask(file->f_mapping,
38713 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
38714 @@ -731,12 +749,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
38715 blk_mq_unfreeze_queue(lo->lo_queue);
38718 + if (old_virt_file)
38719 + fput(old_virt_file);
38720 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
38721 loop_reread_partitions(lo, bdev);
38731 @@ -924,7 +946,7 @@ static int loop_prepare_queue(struct loop_device *lo)
38732 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
38733 struct block_device *bdev, unsigned int arg)
38735 - struct file *file;
38736 + struct file *file, *f, *virt_file = NULL;
38737 struct inode *inode;
38738 struct address_space *mapping;
38740 @@ -938,6 +960,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
38744 + f = loop_real_file(file);
38746 + virt_file = file;
38752 if (lo->lo_state != Lo_unbound)
38753 @@ -970,6 +998,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
38754 lo->lo_device = bdev;
38755 lo->lo_flags = lo_flags;
38756 lo->lo_backing_file = file;
38757 + lo->lo_backing_virt_file = virt_file;
38758 lo->transfer = NULL;
38760 lo->lo_sizelimit = 0;
38761 @@ -1003,6 +1032,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
38768 /* This is safe: open() is still holding a reference. */
38769 module_put(THIS_MODULE);
38770 @@ -1049,6 +1080,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
38771 static int loop_clr_fd(struct loop_device *lo)
38773 struct file *filp = lo->lo_backing_file;
38774 + struct file *virt_filp = lo->lo_backing_virt_file;
38775 gfp_t gfp = lo->old_gfp_mask;
38776 struct block_device *bdev = lo->lo_device;
38778 @@ -1080,6 +1112,7 @@ static int loop_clr_fd(struct loop_device *lo)
38779 spin_lock_irq(&lo->lo_lock);
38780 lo->lo_state = Lo_rundown;
38781 lo->lo_backing_file = NULL;
38782 + lo->lo_backing_virt_file = NULL;
38783 spin_unlock_irq(&lo->lo_lock);
38785 loop_release_xfer(lo);
38786 @@ -1128,6 +1161,8 @@ static int loop_clr_fd(struct loop_device *lo)
38787 * bd_mutex which is usually taken before lo_ctl_mutex.
38795 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
38796 index 4d42c7a..a4974ee 100644
38797 --- a/drivers/block/loop.h
38798 +++ b/drivers/block/loop.h
38799 @@ -46,7 +46,7 @@ struct loop_device {
38800 int (*ioctl)(struct loop_device *, int cmd,
38801 unsigned long arg);
38803 - struct file * lo_backing_file;
38804 + struct file * lo_backing_file, *lo_backing_virt_file;
38805 struct block_device *lo_device;
38808 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
38809 index 937a20d..1355656 100644
38810 --- a/fs/aufs/f_op.c
38811 +++ b/fs/aufs/f_op.c
38812 @@ -358,7 +358,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
38813 if (IS_ERR(h_file))
38816 - if (au_test_loopback_kthread()) {
38817 + if (0 && au_test_loopback_kthread()) {
38818 au_warn_loopback(h_file->f_path.dentry->d_sb);
38819 if (file->f_mapping != h_file->f_mapping) {
38820 file->f_mapping = h_file->f_mapping;
38821 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
38822 index 3d84349..a642de5 100644
38823 --- a/fs/aufs/loop.c
38824 +++ b/fs/aufs/loop.c
38825 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
38826 symbol_put(loop_backing_file);
38827 kfree(au_warn_loopback_array);
38830 +/* ---------------------------------------------------------------------- */
38832 +/* support the loopback block device insude aufs */
38834 +struct file *aufs_real_loop(struct file *file)
38838 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
38839 + fi_read_lock(file);
38840 + f = au_hf_top(file);
38841 + fi_read_unlock(file);
38845 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
38846 index 05d703d..6bb23c8 100644
38847 --- a/fs/aufs/loop.h
38848 +++ b/fs/aufs/loop.h
38849 @@ -26,7 +26,11 @@ void au_warn_loopback(struct super_block *h_sb);
38851 int au_loopback_init(void);
38852 void au_loopback_fin(void);
38854 +struct file *aufs_real_loop(struct file *file);
38856 +AuStub(struct file *, loop_backing_file, return NULL)
38858 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
38859 struct dentry *h_adding)
38860 AuStubInt0(au_test_loopback_kthread, void)
38861 @@ -34,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
38863 AuStubInt0(au_loopback_init, void)
38864 AuStubVoid(au_loopback_fin, void)
38866 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
38867 #endif /* BLK_DEV_LOOP */
38869 #endif /* __KERNEL__ */
38870 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
38871 index 4020639..13e315f 100644
38872 --- a/fs/aufs/super.c
38873 +++ b/fs/aufs/super.c
38874 @@ -840,7 +840,10 @@ static const struct super_operations aufs_sop = {
38875 .statfs = aufs_statfs,
38876 .put_super = aufs_put_super,
38877 .sync_fs = aufs_sync_fs,
38878 - .remount_fs = aufs_remount_fs
38879 + .remount_fs = aufs_remount_fs,
38880 +#ifdef CONFIG_AUFS_BDEV_LOOP
38881 + .real_loop = aufs_real_loop
38885 /* ---------------------------------------------------------------------- */
38886 diff --git a/include/linux/fs.h b/include/linux/fs.h
38887 index 0d0d247f..50d77f8 100644
38888 --- a/include/linux/fs.h
38889 +++ b/include/linux/fs.h
38890 @@ -1861,6 +1861,10 @@ struct super_operations {
38891 struct shrink_control *);
38892 long (*free_cached_objects)(struct super_block *,
38893 struct shrink_control *);
38894 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
38896 + struct file *(*real_loop)(struct file *);