1 SPDX-License-Identifier: GPL-2.0
2 aufs5.x-rcN kbuild patch
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index f08fbbfafd9a0..1c597cddc351c 100644
8 @@ -267,6 +267,7 @@ source "fs/sysv/Kconfig"
9 source "fs/ufs/Kconfig"
10 source "fs/erofs/Kconfig"
11 source "fs/vboxsf/Kconfig"
12 +source "fs/aufs/Kconfig"
14 endif # MISC_FILESYSTEMS
16 diff --git a/fs/Makefile b/fs/Makefile
17 index 2ce5112b02c86..d9b4a51985538 100644
20 @@ -136,3 +136,4 @@ obj-$(CONFIG_EFIVAR_FS) += efivarfs/
21 obj-$(CONFIG_EROFS_FS) += erofs/
22 obj-$(CONFIG_VBOXSF_FS) += vboxsf/
23 obj-$(CONFIG_ZONEFS_FS) += zonefs/
24 +obj-$(CONFIG_AUFS_FS) += aufs/
25 SPDX-License-Identifier: GPL-2.0
26 aufs5.x-rcN base patch
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index 50659d76976b7..80f67140e4f70 100644
32 @@ -2946,6 +2946,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: aufs-users@lists.sourceforge.net (members only)
39 +L: linux-unionfs@vger.kernel.org
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 da693e6a834e5..0479902a0cd50 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -753,6 +753,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 b280e07e162b1..046000653e4d8 100644
85 @@ -1266,7 +1266,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 2e4c0fa2074b0..0b28a37f7e505 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 93d9252a00ab4..7700c5e4783b9 100644
120 @@ -1688,7 +1688,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 if (inode->i_op->update_time)
128 return inode->i_op->update_time(inode, time, flags);
129 diff --git a/fs/namespace.c b/fs/namespace.c
130 index a28e4db075ede..12e725e34c6ca 100644
133 @@ -776,6 +776,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 bbfa9b12b15eb..5d684d7d29207 100644
148 --- a/fs/read_write.c
149 +++ b/fs/read_write.c
150 @@ -499,6 +499,28 @@ static ssize_t __vfs_write(struct file *file, const char __user *p,
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); /* doesn't have ->read(|_iter)() op */
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); /* doesn't have ->write(|_iter)() op */
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 4e53efbd621db..9f230ee854e20 100644
183 @@ -849,8 +849,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 @@ -866,9 +866,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 4d1ff010bc5af..457f4e4a5cc1f 100644
212 * wait == 1 case since in that case write_inode() functions do
213 * sync_dirty_buffer() and thus effectively write one block at a time.
215 -static int __sync_filesystem(struct super_block *sb, int wait)
216 +int __sync_filesystem(struct super_block *sb, int wait)
220 diff --git a/include/linux/fs.h b/include/linux/fs.h
221 index 45cc10cdf6ddd..916efd7e612b3 100644
222 --- a/include/linux/fs.h
223 +++ b/include/linux/fs.h
224 @@ -1355,6 +1355,7 @@ extern void fasync_free(struct fasync_struct *);
225 /* can be called from interrupts */
226 extern void kill_fasync(struct fasync_struct **, int, int);
228 +extern int setfl(int fd, struct file *filp, unsigned long arg);
229 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
230 extern int f_setown(struct file *filp, unsigned long arg, int force);
231 extern void f_delown(struct file *filp);
232 @@ -1847,6 +1848,7 @@ struct file_operations {
233 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
234 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
235 int (*check_flags)(int);
236 + int (*setfl)(struct file *, unsigned long);
237 int (*flock) (struct file *, int, struct file_lock *);
238 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
239 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
240 @@ -1917,6 +1919,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
241 struct iovec *fast_pointer,
242 struct iovec **ret_pointer);
244 +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *);
245 +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t,
247 +vfs_readf_t vfs_readf(struct file *file);
248 +vfs_writef_t vfs_writef(struct file *file);
250 extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
251 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
252 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
253 @@ -2349,6 +2357,7 @@ extern int current_umask(void);
254 extern void ihold(struct inode * inode);
255 extern void iput(struct inode *);
256 extern int generic_update_time(struct inode *, struct timespec64 *, int);
257 +extern int update_time(struct inode *, struct timespec64 *, int);
260 extern struct kobject *fs_kobj;
261 @@ -2633,6 +2642,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
265 +extern int __sync_filesystem(struct super_block *, int);
266 extern int sync_filesystem(struct super_block *);
267 extern const struct file_operations def_blk_fops;
268 extern const struct file_operations def_chr_fops;
269 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
270 index 206774ac69460..e5eda5226fbc7 100644
271 --- a/include/linux/lockdep.h
272 +++ b/include/linux/lockdep.h
273 @@ -376,6 +376,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
274 return lock->key == key;
277 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
282 @@ -521,6 +523,7 @@ struct lockdep_map { };
284 #define lockdep_depth(tsk) (0)
286 +#define lockdep_is_held(lock) (1)
287 #define lockdep_is_held_type(l, r) (1)
289 #define lockdep_assert_held(l) do { (void)(l); } while (0)
290 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
291 index 35942084cd40d..24f5fd1a789de 100644
292 --- a/include/linux/mnt_namespace.h
293 +++ b/include/linux/mnt_namespace.h
295 struct mnt_namespace;
297 struct user_namespace;
300 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
301 struct user_namespace *, struct fs_struct *);
302 extern void put_mnt_ns(struct mnt_namespace *ns);
304 +extern int is_current_mnt_ns(struct vfsmount *mnt);
306 extern const struct file_operations proc_mounts_operations;
307 extern const struct file_operations proc_mountinfo_operations;
308 extern const struct file_operations proc_mountstats_operations;
309 diff --git a/include/linux/splice.h b/include/linux/splice.h
310 index ebbbfea48aa0b..d68d574250283 100644
311 --- a/include/linux/splice.h
312 +++ b/include/linux/splice.h
313 @@ -90,4 +90,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
315 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
316 extern const struct pipe_buf_operations default_pipe_buf_ops;
318 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
319 + loff_t *ppos, size_t len, unsigned int flags);
320 +extern long do_splice_to(struct file *in, loff_t *ppos,
321 + struct pipe_inode_info *pipe, size_t len,
322 + unsigned int flags);
324 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
325 index ac10db66cc63f..837a3358e77ca 100644
326 --- a/kernel/locking/lockdep.c
327 +++ b/kernel/locking/lockdep.c
328 @@ -169,7 +169,7 @@ static
329 struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
330 static DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS);
332 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
333 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
335 unsigned int class_idx = hlock->class_idx;
337 @@ -190,6 +190,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
339 return lock_classes + class_idx;
341 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
343 #ifdef CONFIG_LOCK_STAT
344 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
345 SPDX-License-Identifier: GPL-2.0
346 aufs5.x-rcN mmap patch
348 diff --git a/fs/proc/base.c b/fs/proc/base.c
349 index eb2255e95f62b..92f6062423c0c 100644
352 @@ -2162,7 +2162,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
354 vma = find_exact_vma(mm, vm_start, vm_end);
355 if (vma && vma->vm_file) {
356 - *path = vma->vm_file->f_path;
357 + *path = vma_pr_or_file(vma)->f_path;
361 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
362 index 14c2badb8fd93..65afe5287e43e 100644
363 --- a/fs/proc/nommu.c
364 +++ b/fs/proc/nommu.c
365 @@ -41,7 +41,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
366 file = region->vm_file;
369 - struct inode *inode = file_inode(region->vm_file);
370 + struct inode *inode;
372 + file = vmr_pr_or_file(region);
373 + inode = file_inode(file);
374 dev = inode->i_sb->s_dev;
377 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
378 index 8d382d4ec0672..93a768f754c91 100644
379 --- a/fs/proc/task_mmu.c
380 +++ b/fs/proc/task_mmu.c
381 @@ -280,7 +280,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
382 const char *name = NULL;
385 - struct inode *inode = file_inode(vma->vm_file);
386 + struct inode *inode;
388 + file = vma_pr_or_file(vma);
389 + inode = file_inode(file);
390 dev = inode->i_sb->s_dev;
392 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
393 @@ -1787,7 +1790,7 @@ static int show_numa_map(struct seq_file *m, void *v)
394 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
395 struct vm_area_struct *vma = v;
396 struct numa_maps *md = &numa_priv->md;
397 - struct file *file = vma->vm_file;
398 + struct file *file = vma_pr_or_file(vma);
399 struct mm_struct *mm = vma->vm_mm;
400 struct mempolicy *pol;
402 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
403 index 7907e6419e572..d17209cf52bc3 100644
404 --- a/fs/proc/task_nommu.c
405 +++ b/fs/proc/task_nommu.c
406 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
410 - struct inode *inode = file_inode(vma->vm_file);
411 + struct inode *inode;
413 + file = vma_pr_or_file(vma);
414 + inode = file_inode(file);
415 dev = inode->i_sb->s_dev;
417 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
418 diff --git a/include/linux/mm.h b/include/linux/mm.h
419 index f3fe7371855ce..a5b9751a5b331 100644
420 --- a/include/linux/mm.h
421 +++ b/include/linux/mm.h
422 @@ -1688,6 +1688,28 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
423 unmap_mapping_range(mapping, holebegin, holelen, 0);
426 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
427 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
429 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
430 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
432 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
434 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
436 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
437 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
440 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
441 +extern void vmr_do_fput(struct vm_region *, const char[], int);
443 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
445 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
446 +#endif /* !CONFIG_MMU */
448 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
449 void *buf, int len, unsigned int gup_flags);
450 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
451 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
452 index 4aba6c0c2ba80..974802987f69d 100644
453 --- a/include/linux/mm_types.h
454 +++ b/include/linux/mm_types.h
455 @@ -272,6 +272,7 @@ struct vm_region {
456 unsigned long vm_top; /* region allocated to here */
457 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
458 struct file *vm_file; /* the backing file or NULL */
459 + struct file *vm_prfile; /* the virtual backing file or NULL */
461 int vm_usage; /* region usage count (access under nommu_region_sem) */
462 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
463 @@ -351,6 +352,7 @@ struct vm_area_struct {
464 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
466 struct file * vm_file; /* File we map to (can be NULL). */
467 + struct file *vm_prfile; /* shadow of vm_file */
468 void * vm_private_data; /* was vm_pte (shared mem) */
471 diff --git a/kernel/fork.c b/kernel/fork.c
472 index 48ed22774efaa..d7439388c1c52 100644
475 @@ -568,7 +568,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
476 struct inode *inode = file_inode(file);
477 struct address_space *mapping = file->f_mapping;
481 if (tmp->vm_flags & VM_DENYWRITE)
482 atomic_dec(&inode->i_writecount);
483 i_mmap_lock_write(mapping);
484 diff --git a/mm/Makefile b/mm/Makefile
485 index fccd3756b25f0..51485ceec650a 100644
488 @@ -44,7 +44,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \
489 mm_init.o mmu_context.o percpu.o slab_common.o \
490 compaction.o vmacache.o \
491 interval_tree.o list_lru.o workingset.o \
492 - debug.o gup.o $(mmu-y)
493 + prfile.o debug.o gup.o $(mmu-y)
495 # Give 'page_alloc' its own module-parameter namespace
496 page-alloc-y := page_alloc.o
497 diff --git a/mm/filemap.c b/mm/filemap.c
498 index 23a051a7ef0fb..e2fe9132feb21 100644
501 @@ -2660,7 +2660,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
502 vm_fault_t ret = VM_FAULT_LOCKED;
504 sb_start_pagefault(inode->i_sb);
505 - file_update_time(vmf->vma->vm_file);
506 + vma_file_update_time(vmf->vma);
508 if (page->mapping != inode->i_mapping) {
510 diff --git a/mm/mmap.c b/mm/mmap.c
511 index f609e9ec4a253..d554b349c653c 100644
514 @@ -179,7 +179,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
515 if (vma->vm_ops && vma->vm_ops->close)
516 vma->vm_ops->close(vma);
518 - fput(vma->vm_file);
520 mpol_put(vma_policy(vma));
523 @@ -910,7 +910,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
526 uprobe_munmap(next, next->vm_start, next->vm_end);
531 anon_vma_merge(vma, next);
532 @@ -1831,8 +1831,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
540 /* Undo any partial mapping done by a device driver. */
541 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
542 @@ -2683,7 +2683,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
546 - get_file(new->vm_file);
549 if (new->vm_ops && new->vm_ops->open)
550 new->vm_ops->open(new);
551 @@ -2702,7 +2702,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
552 if (new->vm_ops && new->vm_ops->close)
553 new->vm_ops->close(new);
555 - fput(new->vm_file);
557 unlink_anon_vmas(new);
559 mpol_put(vma_policy(new));
560 @@ -2894,7 +2894,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
561 struct vm_area_struct *vma;
562 unsigned long populate = 0;
563 unsigned long ret = -EINVAL;
565 + struct file *file, *prfile;
567 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n",
568 current->comm, current->pid);
569 @@ -2969,10 +2969,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
573 - file = get_file(vma->vm_file);
575 + file = vma->vm_file;
576 + prfile = vma->vm_prfile;
577 ret = do_mmap_pgoff(vma->vm_file, start, size,
578 prot, flags, pgoff, &populate, NULL);
579 + if (!IS_ERR_VALUE(ret) && file && prfile) {
580 + struct vm_area_struct *new_vma;
582 + new_vma = find_vma(mm, ret);
583 + if (!new_vma->vm_prfile)
584 + new_vma->vm_prfile = prfile;
585 + if (new_vma != vma)
589 + * two fput()s instead of vma_fput(vma),
590 + * coz vma may not be available anymore.
596 up_write(&mm->mmap_sem);
598 @@ -3263,7 +3280,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
599 if (anon_vma_clone(new_vma, vma))
600 goto out_free_mempol;
601 if (new_vma->vm_file)
602 - get_file(new_vma->vm_file);
603 + vma_get_file(new_vma);
604 if (new_vma->vm_ops && new_vma->vm_ops->open)
605 new_vma->vm_ops->open(new_vma);
606 vma_link(mm, new_vma, prev, rb_link, rb_parent);
607 diff --git a/mm/nommu.c b/mm/nommu.c
608 index 318df4e236c99..7f051e86ea1dd 100644
611 @@ -567,7 +567,7 @@ static void __put_nommu_region(struct vm_region *region)
612 up_write(&nommu_region_sem);
615 - fput(region->vm_file);
618 /* IO memory and memory shared directly out of the pagecache
619 * from ramfs/tmpfs mustn't be released here */
620 @@ -699,7 +699,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
621 if (vma->vm_ops && vma->vm_ops->close)
622 vma->vm_ops->close(vma);
624 - fput(vma->vm_file);
626 put_nommu_region(vma->vm_region);
629 @@ -1222,7 +1222,7 @@ unsigned long do_mmap(struct file *file,
630 goto error_just_free;
633 - fput(region->vm_file);
635 kmem_cache_free(vm_region_jar, region);
638 @@ -1299,10 +1299,10 @@ unsigned long do_mmap(struct file *file,
639 up_write(&nommu_region_sem);
642 - fput(region->vm_file);
644 kmem_cache_free(vm_region_jar, region);
646 - fput(vma->vm_file);
651 diff --git a/mm/prfile.c b/mm/prfile.c
653 index 0000000000000..00d51187c3250
657 +// SPDX-License-Identifier: GPL-2.0
659 + * Mainly for aufs which mmap(2) different file and wants to print different
660 + * path in /proc/PID/maps.
661 + * Call these functions via macros defined in linux/mm.h.
663 + * See Documentation/filesystems/aufs/design/06mmap.txt
665 + * Copyright (c) 2014-2020 Junjro R. Okajima
666 + * Copyright (c) 2014 Ian Campbell
669 +#include <linux/mm.h>
670 +#include <linux/file.h>
671 +#include <linux/fs.h>
673 +/* #define PRFILE_TRACE */
674 +static inline void prfile_trace(struct file *f, struct file *pr,
675 + const char func[], int line, const char func2[])
679 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
683 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
686 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
688 + prfile_trace(f, pr, func, line, __func__);
689 + file_update_time(f);
691 + file_update_time(pr);
694 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
697 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
699 + prfile_trace(f, pr, func, line, __func__);
700 + return (f && pr) ? pr : f;
703 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
705 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
707 + prfile_trace(f, pr, func, line, __func__);
713 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
715 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
717 + prfile_trace(f, pr, func, line, __func__);
724 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
727 + struct file *f = region->vm_file, *pr = region->vm_prfile;
729 + prfile_trace(f, pr, func, line, __func__);
730 + return (f && pr) ? pr : f;
733 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
735 + struct file *f = region->vm_file, *pr = region->vm_prfile;
737 + prfile_trace(f, pr, func, line, __func__);
742 +#endif /* !CONFIG_MMU */
743 SPDX-License-Identifier: GPL-2.0
744 aufs5.x-rcN standalone patch
746 diff --git a/fs/dcache.c b/fs/dcache.c
747 index 046000653e4d8..15aa871d1b450 100644
750 @@ -1371,6 +1371,7 @@ void d_walk(struct dentry *parent, void *data,
754 +EXPORT_SYMBOL_GPL(d_walk);
757 struct vfsmount *mnt;
758 @@ -2916,6 +2917,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
760 write_sequnlock(&rename_lock);
762 +EXPORT_SYMBOL_GPL(d_exchange);
765 * d_ancestor - search for an ancestor
766 diff --git a/fs/exec.c b/fs/exec.c
767 index 2c465119affcc..239bcb8906e78 100644
770 @@ -109,6 +109,7 @@ bool path_noexec(const struct path *path)
771 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
772 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
774 +EXPORT_SYMBOL_GPL(path_noexec);
778 diff --git a/fs/fcntl.c b/fs/fcntl.c
779 index 0b28a37f7e505..f2c90a416b751 100644
782 @@ -85,6 +85,7 @@ int setfl(int fd, struct file *filp, unsigned long arg)
786 +EXPORT_SYMBOL_GPL(setfl);
788 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
790 diff --git a/fs/file_table.c b/fs/file_table.c
791 index 30d55c9a1744a..34b9bbf4c5566 100644
792 --- a/fs/file_table.c
793 +++ b/fs/file_table.c
794 @@ -162,6 +162,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
796 return ERR_PTR(-ENFILE);
798 +EXPORT_SYMBOL_GPL(alloc_empty_file);
801 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
802 @@ -375,6 +376,7 @@ void __fput_sync(struct file *file)
806 +EXPORT_SYMBOL_GPL(__fput_sync);
808 void __init files_init(void)
810 diff --git a/fs/inode.c b/fs/inode.c
811 index 7700c5e4783b9..6284b41fcf3f0 100644
814 @@ -1694,6 +1694,7 @@ int update_time(struct inode *inode, struct timespec64 *time, int flags)
815 return inode->i_op->update_time(inode, time, flags);
816 return generic_update_time(inode, time, flags);
818 +EXPORT_SYMBOL_GPL(update_time);
821 * touch_atime - update the access time
822 diff --git a/fs/namespace.c b/fs/namespace.c
823 index 12e725e34c6ca..fa17b9d5926ba 100644
826 @@ -431,6 +431,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
827 mnt_dec_writers(real_mount(mnt));
830 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
833 * mnt_drop_write - give up write access to a mount
834 @@ -781,6 +782,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
836 return check_mnt(real_mount(mnt));
838 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
841 * vfsmount lock must be held for write
842 @@ -1903,6 +1905,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
846 +EXPORT_SYMBOL_GPL(iterate_mounts);
848 static void lock_mnt_tree(struct mount *mnt)
850 diff --git a/fs/notify/group.c b/fs/notify/group.c
851 index 133f723aca070..0b9f7f6d8390f 100644
852 --- a/fs/notify/group.c
853 +++ b/fs/notify/group.c
854 @@ -99,6 +99,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
856 refcount_inc(&group->refcnt);
858 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
861 * Drop a reference to a group. Free it if it's through.
862 diff --git a/fs/open.c b/fs/open.c
863 index 719b320ede52b..f88ce55c1c998 100644
866 @@ -65,6 +65,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
867 inode_unlock(dentry->d_inode);
870 +EXPORT_SYMBOL_GPL(do_truncate);
872 long vfs_truncate(const struct path *path, loff_t length)
874 diff --git a/fs/read_write.c b/fs/read_write.c
875 index 5d684d7d29207..6f61c0b6aa664 100644
876 --- a/fs/read_write.c
877 +++ b/fs/read_write.c
878 @@ -469,6 +469,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
882 +EXPORT_SYMBOL_GPL(vfs_read);
884 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
886 @@ -509,6 +510,7 @@ vfs_readf_t vfs_readf(struct file *file)
887 return new_sync_read;
888 return ERR_PTR(-ENOSYS); /* doesn't have ->read(|_iter)() op */
890 +EXPORT_SYMBOL_GPL(vfs_readf);
892 vfs_writef_t vfs_writef(struct file *file)
894 @@ -520,6 +522,7 @@ vfs_writef_t vfs_writef(struct file *file)
895 return new_sync_write;
896 return ERR_PTR(-ENOSYS); /* doesn't have ->write(|_iter)() op */
898 +EXPORT_SYMBOL_GPL(vfs_writef);
900 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
902 @@ -589,6 +592,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
906 +EXPORT_SYMBOL_GPL(vfs_write);
908 /* file_ppos returns &file->f_pos or NULL if file is stream */
909 static inline loff_t *file_ppos(struct file *file)
910 diff --git a/fs/splice.c b/fs/splice.c
911 index 9f230ee854e20..a6bd05004433c 100644
914 @@ -862,6 +862,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
916 return splice_write(pipe, out, ppos, len, flags);
918 +EXPORT_SYMBOL_GPL(do_splice_from);
921 * Attempt to initiate a splice from a file to a pipe.
922 @@ -891,6 +892,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
924 return splice_read(in, ppos, pipe, len, flags);
926 +EXPORT_SYMBOL_GPL(do_splice_to);
929 * splice_direct_to_actor - splices data directly between two non-pipes
930 diff --git a/fs/sync.c b/fs/sync.c
931 index 457f4e4a5cc1f..67c66358f3fe4 100644
934 @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
935 sb->s_op->sync_fs(sb, wait);
936 return __sync_blockdev(sb->s_bdev, wait);
938 +EXPORT_SYMBOL_GPL(__sync_filesystem);
941 * Write out and wait upon all dirty data associated with this
942 diff --git a/fs/xattr.c b/fs/xattr.c
943 index 91608d9bfc6aa..02d19ab3ba540 100644
946 @@ -296,6 +296,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
947 *xattr_value = value;
950 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
953 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
954 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
955 index 837a3358e77ca..715ba9c1b91ae 100644
956 --- a/kernel/locking/lockdep.c
957 +++ b/kernel/locking/lockdep.c
958 @@ -190,6 +190,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
960 return lock_classes + class_idx;
962 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
963 #define hlock_class(hlock) lockdep_hlock_class(hlock)
965 #ifdef CONFIG_LOCK_STAT
966 diff --git a/kernel/task_work.c b/kernel/task_work.c
967 index 825f28259a19a..b77593b29c1a5 100644
968 --- a/kernel/task_work.c
969 +++ b/kernel/task_work.c
970 @@ -126,3 +126,4 @@ void task_work_run(void)
974 +EXPORT_SYMBOL_GPL(task_work_run);
975 diff --git a/security/security.c b/security/security.c
976 index 51de970fbb1ed..b21f1ffd90051 100644
977 --- a/security/security.c
978 +++ b/security/security.c
979 @@ -1087,6 +1087,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
981 return call_int_hook(path_rmdir, 0, dir, dentry);
983 +EXPORT_SYMBOL_GPL(security_path_rmdir);
985 int security_path_unlink(const struct path *dir, struct dentry *dentry)
987 @@ -1103,6 +1104,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
989 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
991 +EXPORT_SYMBOL_GPL(security_path_symlink);
993 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
994 struct dentry *new_dentry)
995 @@ -1111,6 +1113,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
997 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
999 +EXPORT_SYMBOL_GPL(security_path_link);
1001 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1002 const struct path *new_dir, struct dentry *new_dentry,
1003 @@ -1138,6 +1141,7 @@ int security_path_truncate(const struct path *path)
1005 return call_int_hook(path_truncate, 0, path);
1007 +EXPORT_SYMBOL_GPL(security_path_truncate);
1009 int security_path_chmod(const struct path *path, umode_t mode)
1011 @@ -1145,6 +1149,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1013 return call_int_hook(path_chmod, 0, path, mode);
1015 +EXPORT_SYMBOL_GPL(security_path_chmod);
1017 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1019 @@ -1152,6 +1157,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1021 return call_int_hook(path_chown, 0, path, uid, gid);
1023 +EXPORT_SYMBOL_GPL(security_path_chown);
1025 int security_path_chroot(const struct path *path)
1027 @@ -1252,6 +1258,7 @@ int security_inode_permission(struct inode *inode, int mask)
1029 return call_int_hook(inode_permission, 0, inode, mask);
1031 +EXPORT_SYMBOL_GPL(security_inode_permission);
1033 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1035 @@ -1429,6 +1436,7 @@ int security_file_permission(struct file *file, int mask)
1037 return fsnotify_perm(file, mask);
1039 +EXPORT_SYMBOL_GPL(security_file_permission);
1041 int security_file_alloc(struct file *file)
1043 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1044 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1045 +++ linux/Documentation/ABI/testing/debugfs-aufs 2019-07-11 15:42:14.455570938 +0200
1047 +What: /debug/aufs/si_<id>/
1049 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1051 + Under /debug/aufs, a directory named si_<id> is created
1052 + per aufs mount, where <id> is a unique id generated
1055 +What: /debug/aufs/si_<id>/plink
1057 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1059 + It has three lines and shows the information about the
1060 + pseudo-link. The first line is a single number
1061 + representing a number of buckets. The second line is a
1062 + number of pseudo-links per buckets (separated by a
1063 + blank). The last line is a single number representing a
1064 + total number of psedo-links.
1065 + When the aufs mount option 'noplink' is specified, it
1066 + will show "1\n0\n0\n".
1068 +What: /debug/aufs/si_<id>/xib
1070 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1072 + It shows the consumed blocks by xib (External Inode Number
1073 + Bitmap), its block size and file size.
1074 + When the aufs mount option 'noxino' is specified, it
1075 + will be empty. About XINO files, see the aufs manual.
1077 +What: /debug/aufs/si_<id>/xi0, xi1 ... xiN and xiN-N
1079 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1081 + It shows the consumed blocks by xino (External Inode Number
1082 + Translation Table), its link count, block size and file
1084 + Due to the file size limit, there may exist multiple
1085 + xino files per branch. In this case, "-N" is added to
1086 + the filename and it corresponds to the index of the
1087 + internal xino array. "-0" is omitted.
1088 + When the aufs mount option 'noxino' is specified, Those
1089 + entries won't exist. About XINO files, see the aufs
1092 +What: /debug/aufs/si_<id>/xigen
1094 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1096 + It shows the consumed blocks by xigen (External Inode
1097 + Generation Table), its block size and file size.
1098 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1100 + When the aufs mount option 'noxino' is specified, it
1101 + will be empty. About XINO files, see the aufs manual.
1102 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1103 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1104 +++ linux/Documentation/ABI/testing/sysfs-aufs 2019-07-11 15:42:14.455570938 +0200
1106 +What: /sys/fs/aufs/si_<id>/
1108 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1110 + Under /sys/fs/aufs, a directory named si_<id> is created
1111 + per aufs mount, where <id> is a unique id generated
1114 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1116 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1118 + It shows the abolute path of a member directory (which
1119 + is called branch) in aufs, and its permission.
1121 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1123 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1125 + It shows the id of a member directory (which is called
1128 +What: /sys/fs/aufs/si_<id>/xi_path
1130 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1132 + It shows the abolute path of XINO (External Inode Number
1133 + Bitmap, Translation Table and Generation Table) file
1134 + even if it is the default path.
1135 + When the aufs mount option 'noxino' is specified, it
1136 + will be empty. About XINO files, see the aufs manual.
1137 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1138 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1139 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2020-01-27 10:57:18.162204582 +0100
1142 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1144 +# This program is free software; you can redistribute it and/or modify
1145 +# it under the terms of the GNU General Public License as published by
1146 +# the Free Software Foundation; either version 2 of the License, or
1147 +# (at your option) any later version.
1149 +# This program is distributed in the hope that it will be useful,
1150 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1151 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1152 +# GNU General Public License for more details.
1154 +# You should have received a copy of the GNU General Public License
1155 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1158 +----------------------------------------
1160 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1161 +1. abbrev. for "advanced multi-layered unification filesystem".
1162 +2. abbrev. for "another unionfs".
1163 +3. abbrev. for "auf das" in German which means "on the" in English.
1164 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1165 + But "Filesystem aufs Filesystem" is hard to understand.
1166 +4. abbrev. for "African Urban Fashion Show".
1168 +AUFS is a filesystem with features:
1169 +- multi layered stackable unification filesystem, the member directory
1170 + is called as a branch.
1171 +- branch permission and attribute, 'readonly', 'real-readonly',
1172 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1174 +- internal "file copy-on-write".
1175 +- logical deletion, whiteout.
1176 +- dynamic branch manipulation, adding, deleting and changing permission.
1177 +- allow bypassing aufs, user's direct branch access.
1178 +- external inode number translation table and bitmap which maintains the
1179 + persistent aufs inode number.
1180 +- seekable directory, including NFS readdir.
1181 +- file mapping, mmap and sharing pages.
1182 +- pseudo-link, hardlink over branches.
1183 +- loopback mounted filesystem as a branch.
1184 +- several policies to select one among multiple writable branches.
1185 +- revert a single systemcall when an error occurs in aufs.
1189 +Multi Layered Stackable Unification Filesystem
1190 +----------------------------------------------------------------------
1191 +Most people already knows what it is.
1192 +It is a filesystem which unifies several directories and provides a
1193 +merged single directory. When users access a file, the access will be
1194 +passed/re-directed/converted (sorry, I am not sure which English word is
1195 +correct) to the real file on the member filesystem. The member
1196 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1197 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1198 +readonly branch is handled by creating 'whiteout' on the upper writable
1201 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1202 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1203 +different approaches to implement the merged-view.
1204 +The former tries putting it into VFS, and the latter implements as a
1205 +separate filesystem.
1206 +(If I misunderstand about these implementations, please let me know and
1207 +I shall correct it. Because it is a long time ago when I read their
1208 +source files last time).
1210 +UnionMount's approach will be able to small, but may be hard to share
1211 +branches between several UnionMount since the whiteout in it is
1212 +implemented in the inode on branch filesystem and always
1213 +shared. According to Bharata's post, readdir does not seems to be
1215 +There are several missing features known in this implementations such as
1216 +- for users, the inode number may change silently. eg. copy-up.
1217 +- link(2) may break by copy-up.
1218 +- read(2) may get an obsoleted filedata (fstat(2) too).
1219 +- fcntl(F_SETLK) may be broken by copy-up.
1220 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1223 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1224 +merged into mainline. This is another implementation of UnionMount as a
1225 +separated filesystem. All the limitations and known problems which
1226 +UnionMount are equally inherited to "overlay" filesystem.
1228 +Unionfs has a longer history. When I started implementing a stackable
1229 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1230 +inode, dentry and file objects and they have an array pointing lower
1231 +same kind objects. After contributing many patches for Unionfs, I
1232 +re-started my project AUFS (Jun 2006).
1234 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1235 +implemented my own ideas, approaches and enhancements and it became
1236 +totally different one.
1238 +Comparing DM snapshot and fs based implementation
1239 +- the number of bytes to be copied between devices is much smaller.
1240 +- the type of filesystem must be one and only.
1241 +- the fs must be writable, no readonly fs, even for the lower original
1242 + device. so the compression fs will not be usable. but if we use
1243 + loopback mount, we may address this issue.
1245 + mount /cdrom/squashfs.img /sq
1246 + losetup /sq/ext2.img
1247 + losetup /somewhere/cow
1248 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1249 +- it will be difficult (or needs more operations) to extract the
1250 + difference between the original device and COW.
1251 +- DM snapshot-merge may help a lot when users try merging. in the
1252 + fs-layer union, users will use rsync(1).
1254 +You may want to read my old paper "Filesystems in LiveCD"
1255 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1258 +Several characters/aspects/persona of aufs
1259 +----------------------------------------------------------------------
1261 +Aufs has several characters, aspects or persona.
1262 +1. a filesystem, callee of VFS helper
1263 +2. sub-VFS, caller of VFS helper for branches
1264 +3. a virtual filesystem which maintains persistent inode number
1265 +4. reader/writer of files on branches such like an application
1267 +1. Callee of VFS Helper
1268 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1269 +unlink(2) from an application reaches sys_unlink() kernel function and
1270 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1271 +calls filesystem specific unlink operation. Actually aufs implements the
1272 +unlink operation but it behaves like a redirector.
1274 +2. Caller of VFS Helper for Branches
1275 +aufs_unlink() passes the unlink request to the branch filesystem as if
1276 +it were called from VFS. So the called unlink operation of the branch
1277 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1278 +every necessary pre/post operation for the branch filesystem.
1279 +- acquire the lock for the parent dir on a branch
1280 +- lookup in a branch
1281 +- revalidate dentry on a branch
1282 +- mnt_want_write() for a branch
1283 +- vfs_unlink() for a branch
1284 +- mnt_drop_write() for a branch
1285 +- release the lock on a branch
1287 +3. Persistent Inode Number
1288 +One of the most important issue for a filesystem is to maintain inode
1289 +numbers. This is particularly important to support exporting a
1290 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1291 +backend block device for its own. But some storage is necessary to
1292 +keep and maintain the inode numbers. It may be a large space and may not
1293 +suit to keep in memory. Aufs rents some space from its first writable
1294 +branch filesystem (by default) and creates file(s) on it. These files
1295 +are created by aufs internally and removed soon (currently) keeping
1297 +Note: Because these files are removed, they are totally gone after
1298 + unmounting aufs. It means the inode numbers are not persistent
1299 + across unmount or reboot. I have a plan to make them really
1300 + persistent which will be important for aufs on NFS server.
1302 +4. Read/Write Files Internally (copy-on-write)
1303 +Because a branch can be readonly, when you write a file on it, aufs will
1304 +"copy-up" it to the upper writable branch internally. And then write the
1305 +originally requested thing to the file. Generally kernel doesn't
1306 +open/read/write file actively. In aufs, even a single write may cause a
1307 +internal "file copy". This behaviour is very similar to cp(1) command.
1309 +Some people may think it is better to pass such work to user space
1310 +helper, instead of doing in kernel space. Actually I am still thinking
1311 +about it. But currently I have implemented it in kernel space.
1312 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1313 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1314 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2020-01-27 10:57:18.162204582 +0100
1317 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1319 +# This program is free software; you can redistribute it and/or modify
1320 +# it under the terms of the GNU General Public License as published by
1321 +# the Free Software Foundation; either version 2 of the License, or
1322 +# (at your option) any later version.
1324 +# This program is distributed in the hope that it will be useful,
1325 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1326 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1327 +# GNU General Public License for more details.
1329 +# You should have received a copy of the GNU General Public License
1330 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1332 +Basic Aufs Internal Structure
1334 +Superblock/Inode/Dentry/File Objects
1335 +----------------------------------------------------------------------
1336 +As like an ordinary filesystem, aufs has its own
1337 +superblock/inode/dentry/file objects. All these objects have a
1338 +dynamically allocated array and store the same kind of pointers to the
1339 +lower filesystem, branch.
1340 +For example, when you build a union with one readwrite branch and one
1341 +readonly, mounted /au, /rw and /ro respectively.
1343 +- /ro/fileA exists but /rw/fileA
1345 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1346 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1347 +- [0] = NULL (because /rw/fileA doesn't exist)
1350 +This style of an array is essentially same to the aufs
1351 +superblock/inode/dentry/file objects.
1353 +Because aufs supports manipulating branches, ie. add/delete/change
1354 +branches dynamically, these objects has its own generation. When
1355 +branches are changed, the generation in aufs superblock is
1356 +incremented. And a generation in other object are compared when it is
1357 +accessed. When a generation in other objects are obsoleted, aufs
1358 +refreshes the internal array.
1362 +----------------------------------------------------------------------
1363 +Additionally aufs superblock has some data for policies to select one
1364 +among multiple writable branches, XIB files, pseudo-links and kobject.
1365 +See below in detail.
1366 +About the policies which supports copy-down a directory, see
1367 +wbr_policy.txt too.
1370 +Branch and XINO(External Inode Number Translation Table)
1371 +----------------------------------------------------------------------
1372 +Every branch has its own xino (external inode number translation table)
1373 +file. The xino file is created and unlinked by aufs internally. When two
1374 +members of a union exist on the same filesystem, they share the single
1376 +The struct of a xino file is simple, just a sequence of aufs inode
1377 +numbers which is indexed by the lower inode number.
1378 +In the above sample, assume the inode number of /ro/fileA is i111 and
1379 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1380 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1382 +When the inode numbers are not contiguous, the xino file will be sparse
1383 +which has a hole in it and doesn't consume as much disk space as it
1384 +might appear. If your branch filesystem consumes disk space for such
1385 +holes, then you should specify 'xino=' option at mounting aufs.
1387 +Aufs has a mount option to free the disk blocks for such holes in XINO
1388 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1389 +meet a problem of disk shortage due to XINO files, then you should try
1390 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1391 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1392 +the holes in XINO files.
1394 +Also a writable branch has three kinds of "whiteout bases". All these
1395 +are existed when the branch is joined to aufs, and their names are
1396 +whiteout-ed doubly, so that users will never see their names in aufs
1398 +1. a regular file which will be hardlinked to all whiteouts.
1399 +2. a directory to store a pseudo-link.
1400 +3. a directory to store an "orphan"-ed file temporary.
1403 + When you remove a file on a readonly branch, aufs handles it as a
1404 + logical deletion and creates a whiteout on the upper writable branch
1405 + as a hardlink of this file in order not to consume inode on the
1408 + See below, Pseudo-link.
1410 + When "fileC" exists on the lower readonly branch only and it is
1411 + opened and removed with its parent dir, and then user writes
1412 + something into it, then aufs copies-up fileC to this
1413 + directory. Because there is no other dir to store fileC. After
1414 + creating a file under this dir, the file is unlinked.
1416 +Because aufs supports manipulating branches, ie. add/delete/change
1417 +dynamically, a branch has its own id. When the branch order changes,
1418 +aufs finds the new index by searching the branch id.
1422 +----------------------------------------------------------------------
1423 +Assume "fileA" exists on the lower readonly branch only and it is
1424 +hardlinked to "fileB" on the branch. When you write something to fileA,
1425 +aufs copies-up it to the upper writable branch. Additionally aufs
1426 +creates a hardlink under the Pseudo-link Directory of the writable
1427 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1428 +simple list. If fileB is read after unlinking fileA, aufs returns
1429 +filedata from the pseudo-link instead of the lower readonly
1430 +branch. Because the pseudo-link is based upon the inode, to keep the
1431 +inode number by xino (see above) is essentially necessary.
1433 +All the hardlinks under the Pseudo-link Directory of the writable branch
1434 +should be restored in a proper location later. Aufs provides a utility
1435 +to do this. The userspace helpers executed at remounting and unmounting
1437 +During this utility is running, it puts aufs into the pseudo-link
1438 +maintenance mode. In this mode, only the process which began the
1439 +maintenance mode (and its child processes) is allowed to operate in
1440 +aufs. Some other processes which are not related to the pseudo-link will
1441 +be allowed to run too, but the rest have to return an error or wait
1442 +until the maintenance mode ends. If a process already acquires an inode
1443 +mutex (in VFS), it has to return an error.
1446 +XIB(external inode number bitmap)
1447 +----------------------------------------------------------------------
1448 +Addition to the xino file per a branch, aufs has an external inode number
1449 +bitmap in a superblock object. It is also an internal file such like a
1451 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1453 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1455 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1456 +reduce the number of consumed disk blocks for these files.
1459 +Virtual or Vertical Dir, and Readdir in Userspace
1460 +----------------------------------------------------------------------
1461 +In order to support multiple layers (branches), aufs readdir operation
1462 +constructs a virtual dir block on memory. For readdir, aufs calls
1463 +vfs_readdir() internally for each dir on branches, merges their entries
1464 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1465 +object. So the file object has its entry list until it is closed. The
1466 +entry list will be updated when the file position is zero and becomes
1467 +obsoleted. This decision is made in aufs automatically.
1469 +The dynamically allocated memory block for the name of entries has a
1470 +unit of 512 bytes (by default) and stores the names contiguously (no
1471 +padding). Another block for each entry is handled by kmem_cache too.
1472 +During building dir blocks, aufs creates hash list and judging whether
1473 +the entry is whiteouted by its upper branch or already listed.
1474 +The merged result is cached in the corresponding inode object and
1475 +maintained by a customizable life-time option.
1477 +Some people may call it can be a security hole or invite DoS attack
1478 +since the opened and once readdir-ed dir (file object) holds its entry
1479 +list and becomes a pressure for system memory. But I'd say it is similar
1480 +to files under /proc or /sys. The virtual files in them also holds a
1481 +memory page (generally) while they are opened. When an idea to reduce
1482 +memory for them is introduced, it will be applied to aufs too.
1483 +For those who really hate this situation, I've developed readdir(3)
1484 +library which operates this merging in userspace. You just need to set
1485 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1486 +kernel space for readdir(3).
1490 +----------------------------------------------------------------------
1491 +Aufs sometimes requires privilege access to a branch. For instance,
1492 +in copy-up/down operation. When a user process is going to make changes
1493 +to a file which exists in the lower readonly branch only, and the mode
1494 +of one of ancestor directories may not be writable by a user
1495 +process. Here aufs copy-up the file with its ancestors and they may
1496 +require privilege to set its owner/group/mode/etc.
1497 +This is a typical case of a application character of aufs (see
1500 +Aufs uses workqueue synchronously for this case. It creates its own
1501 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1502 +passes the request to call mkdir or write (for example), and wait for
1503 +its completion. This approach solves a problem of a signal handler
1505 +If aufs didn't adopt the workqueue and changed the privilege of the
1506 +process, then the process may receive the unexpected SIGXFSZ or other
1509 +Also aufs uses the system global workqueue ("events" kernel thread) too
1510 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1511 +whiteout base and etc. This is unrelated to a privilege.
1512 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1513 +superblock at the beginning, at the same time waits for the completion
1514 +of all queued asynchronous tasks.
1518 +----------------------------------------------------------------------
1519 +The whiteout in aufs is very similar to Unionfs's. That is represented
1520 +by its filename. UnionMount takes an approach of a file mode, but I am
1521 +afraid several utilities (find(1) or something) will have to support it.
1523 +Basically the whiteout represents "logical deletion" which stops aufs to
1524 +lookup further, but also it represents "dir is opaque" which also stop
1527 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1528 +In order to make several functions in a single systemcall to be
1529 +revertible, aufs adopts an approach to rename a directory to a temporary
1530 +unique whiteouted name.
1531 +For example, in rename(2) dir where the target dir already existed, aufs
1532 +renames the target dir to a temporary unique whiteouted name before the
1533 +actual rename on a branch, and then handles other actions (make it opaque,
1534 +update the attributes, etc). If an error happens in these actions, aufs
1535 +simply renames the whiteouted name back and returns an error. If all are
1536 +succeeded, aufs registers a function to remove the whiteouted unique
1537 +temporary name completely and asynchronously to the system global
1542 +----------------------------------------------------------------------
1543 +It is a well-known feature or concept.
1544 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1545 +internally and makes change to the new file on the upper writable branch.
1546 +When the trigger systemcall does not update the timestamps of the parent
1547 +dir, aufs reverts it after copy-up.
1550 +Move-down (aufs3.9 and later)
1551 +----------------------------------------------------------------------
1552 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1553 +the lower readonly branch to the upper writable branch when a user
1554 +changes something about the file.
1555 +"Move-down" is an opposite action of copy-up. Basically this action is
1556 +ran manually instead of automatically and internally.
1557 +For desgin and implementation, aufs has to consider these issues.
1558 +- whiteout for the file may exist on the lower branch.
1559 +- ancestor directories may not exist on the lower branch.
1560 +- diropq for the ancestor directories may exist on the upper branch.
1561 +- free space on the lower branch will reduce.
1562 +- another access to the file may happen during moving-down, including
1563 + UDBA (see "Revalidate Dentry and UDBA").
1564 +- the file should not be hard-linked nor pseudo-linked. they should be
1565 + handled by auplink utility later.
1567 +Sometimes users want to move-down a file from the upper writable branch
1568 +to the lower readonly or writable branch. For instance,
1569 +- the free space of the upper writable branch is going to run out.
1570 +- create a new intermediate branch between the upper and lower branch.
1573 +For this purpose, use "aumvdown" command in aufs-util.git.
1574 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1575 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1576 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2020-01-27 10:57:18.162204582 +0100
1579 +# Copyright (C) 2015-2020 Junjiro R. Okajima
1581 +# This program is free software; you can redistribute it and/or modify
1582 +# it under the terms of the GNU General Public License as published by
1583 +# the Free Software Foundation; either version 2 of the License, or
1584 +# (at your option) any later version.
1586 +# This program is distributed in the hope that it will be useful,
1587 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1588 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1589 +# GNU General Public License for more details.
1591 +# You should have received a copy of the GNU General Public License
1592 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1594 +Support for a branch who has its ->atomic_open()
1595 +----------------------------------------------------------------------
1596 +The filesystems who implement its ->atomic_open() are not majority. For
1597 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1598 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1599 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1600 +sure whether all filesystems who have ->atomic_open() behave like this,
1601 +but NFSv4 surely returns the error.
1603 +In order to support ->atomic_open() for aufs, there are a few
1606 +A. Introduce aufs_atomic_open()
1607 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1609 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1610 + an aufs user Pip Cet's approach
1611 + - calls aufs_create(), VFS finish_open() and notify_change().
1612 + - pass fake-mode to finish_open(), and then correct the mode by
1614 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1615 + - no aufs_atomic_open().
1616 + - aufs_lookup() registers the TID to an aufs internal object.
1617 + - aufs_create() does nothing when the matching TID is registered, but
1618 + registers the mode.
1619 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1620 + TID is registered.
1621 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1623 + - no aufs_atomic_open().
1624 + - aufs_create() registers the TID to an internal object. this info
1625 + represents "this process created this file just now."
1626 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1627 + registered TID and re-try open() with superuser's credential.
1629 +Pros and cons for each approach.
1632 + - straightforward but highly depends upon VFS internal.
1633 + - the atomic behavaiour is kept.
1634 + - some of parameters such as nameidata are hard to reproduce for
1638 + - easy to implement.
1639 + - the atomic behavaiour is lost.
1641 + - the atomic behavaiour is kept.
1642 + - dirty and tricky.
1643 + - VFS checks whether the file is created correctly after calling
1644 + ->create(), which means this approach doesn't work.
1646 + - easy to implement.
1647 + - the atomic behavaiour is lost.
1648 + - to open a file with superuser's credential and give it to a user
1649 + process is a bad idea, since the file object keeps the credential
1650 + in it. It may affect LSM or something. This approach doesn't work
1653 +The approach A is ideal, but it hard to implement. So here is a
1654 +variation of A, which is to be implemented.
1656 +A-1. Introduce aufs_atomic_open()
1657 + - calls branch fs ->atomic_open() if exists. otherwise calls
1658 + vfs_create() and finish_open().
1659 + - the demerit is that the several checks after branch fs
1660 + ->atomic_open() are lost. in the ordinary case, the checks are
1661 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1662 + be implemented in aufs, but not all I am afraid.
1663 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1664 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1665 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2020-01-27 10:57:18.165538015 +0100
1668 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1670 +# This program is free software; you can redistribute it and/or modify
1671 +# it under the terms of the GNU General Public License as published by
1672 +# the Free Software Foundation; either version 2 of the License, or
1673 +# (at your option) any later version.
1675 +# This program is distributed in the hope that it will be useful,
1676 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1677 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1678 +# GNU General Public License for more details.
1680 +# You should have received a copy of the GNU General Public License
1681 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1684 +----------------------------------------------------------------------
1685 +Since aufs has a character of sub-VFS (see Introduction), it operates
1686 +lookup for branches as VFS does. It may be a heavy work. But almost all
1687 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1688 +directly connected to its parent. Digging down the directory hierarchy
1689 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1692 +When a branch is a remote filesystem, aufs basically relies upon its
1693 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1695 +For d_revalidate, aufs implements three levels of revalidate tests. See
1696 +"Revalidate Dentry and UDBA" in detail.
1699 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1700 +----------------------------------------------------------------------
1701 +Let's try case study.
1702 +- aufs has two branches, upper readwrite and lower readonly.
1704 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1705 +- user invoked "chmod a+rx /au/dirA"
1706 +- the internal copy-up is activated and "/rw/dirA" is created and its
1707 + permission bits are set to world readable.
1708 +- then "/au/dirA" becomes world readable?
1710 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1711 +or it may be a natively readonly filesystem. If aufs respects the lower
1712 +branch, it should not respond readdir request from other users. But user
1713 +allowed it by chmod. Should really aufs rejects showing the entries
1716 +To be honest, I don't have a good solution for this case. So aufs
1717 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1719 +When dirperm1 is specified, aufs checks only the highest one for the
1720 +directory permission, and shows the entries. Otherwise, as usual, checks
1721 +every dir existing on all branches and rejects the request.
1723 +As a side effect, dirperm1 option improves the performance of aufs
1724 +because the number of permission check is reduced when the number of
1728 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1729 +----------------------------------------------------------------------
1730 +Generally VFS helpers re-validate a dentry as a part of lookup.
1731 +0. digging down the directory hierarchy.
1732 +1. lock the parent dir by its i_mutex.
1733 +2. lookup the final (child) entry.
1735 +4. call the actual operation (create, unlink, etc.)
1736 +5. unlock the parent dir
1738 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1739 +called. Actually aufs implements it and checks the dentry on a branch is
1741 +But it is not enough. Because aufs has to release the lock for the
1742 +parent dir on a branch at the end of ->lookup() (step 2) and
1743 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1745 +If the file on a branch is changed directly, eg. bypassing aufs, after
1746 +aufs released the lock, then the subsequent operation may cause
1747 +something unpleasant result.
1749 +This situation is a result of VFS architecture, ->lookup() and
1750 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1751 +design from VFS's point of view. It is just not suitable for sub-VFS
1754 +Aufs supports such case by three level of revalidation which is
1755 +selectable by user.
1756 +1. Simple Revalidate
1757 + Addition to the native flow in VFS's, confirm the child-parent
1758 + relationship on the branch just after locking the parent dir on the
1759 + branch in the "actual operation" (step 4). When this validation
1760 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1761 + checks the validation of the dentry on branches.
1762 +2. Monitor Changes Internally by Inotify/Fsnotify
1763 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1764 + the dentry on the branch, and returns EBUSY if it finds different
1766 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1767 + during it is in cache. When the event is notified, aufs registers a
1768 + function to kernel 'events' thread by schedule_work(). And the
1769 + function sets some special status to the cached aufs dentry and inode
1770 + private data. If they are not cached, then aufs has nothing to
1771 + do. When the same file is accessed through aufs (step 0-3) later,
1772 + aufs will detect the status and refresh all necessary data.
1773 + In this mode, aufs has to ignore the event which is fired by aufs
1775 +3. No Extra Validation
1776 + This is the simplest test and doesn't add any additional revalidation
1777 + test, and skip the revalidation in step 4. It is useful and improves
1778 + aufs performance when system surely hide the aufs branches from user,
1779 + by over-mounting something (or another method).
1780 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1781 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1782 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2020-01-27 10:57:18.165538015 +0100
1785 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1787 +# This program is free software; you can redistribute it and/or modify
1788 +# it under the terms of the GNU General Public License as published by
1789 +# the Free Software Foundation; either version 2 of the License, or
1790 +# (at your option) any later version.
1792 +# This program is distributed in the hope that it will be useful,
1793 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1794 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1795 +# GNU General Public License for more details.
1797 +# You should have received a copy of the GNU General Public License
1798 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1800 +Branch Manipulation
1802 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1803 +and changing its permission/attribute, there are a lot of works to do.
1807 +----------------------------------------------------------------------
1808 +o Confirm the adding dir exists outside of aufs, including loopback
1809 + mount, and its various attributes.
1810 +o Initialize the xino file and whiteout bases if necessary.
1813 +o Check the owner/group/mode of the directory
1814 + When the owner/group/mode of the adding directory differs from the
1815 + existing branch, aufs issues a warning because it may impose a
1817 + For example, when a upper writable branch has a world writable empty
1818 + top directory, a malicious user can create any files on the writable
1819 + branch directly, like copy-up and modify manually. If something like
1820 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1821 + writable branch, and the writable branch is world-writable, then a
1822 + malicious guy may create /etc/passwd on the writable branch directly
1823 + and the infected file will be valid in aufs.
1824 + I am afraid it can be a security issue, but aufs can do nothing except
1825 + producing a warning.
1829 +----------------------------------------------------------------------
1830 +o Confirm the deleting branch is not busy
1831 + To be general, there is one merit to adopt "remount" interface to
1832 + manipulate branches. It is to discard caches. At deleting a branch,
1833 + aufs checks the still cached (and connected) dentries and inodes. If
1834 + there are any, then they are all in-use. An inode without its
1835 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1837 + For the cached one, aufs checks whether the same named entry exists on
1839 + If the cached one is a directory, because aufs provides a merged view
1840 + to users, as long as one dir is left on any branch aufs can show the
1841 + dir to users. In this case, the branch can be removed from aufs.
1842 + Otherwise aufs rejects deleting the branch.
1844 + If any file on the deleting branch is opened by aufs, then aufs
1848 +Modify the Permission of a Branch
1849 +----------------------------------------------------------------------
1850 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1853 +o rw --> ro: Confirm the modifying branch is not busy
1854 + Aufs rejects the request if any of these conditions are true.
1855 + - a file on the branch is mmap-ed.
1856 + - a regular file on the branch is opened for write and there is no
1857 + same named entry on the upper branch.
1858 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1859 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1860 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2020-01-27 10:57:18.165538015 +0100
1863 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1865 +# This program is free software; you can redistribute it and/or modify
1866 +# it under the terms of the GNU General Public License as published by
1867 +# the Free Software Foundation; either version 2 of the License, or
1868 +# (at your option) any later version.
1870 +# This program is distributed in the hope that it will be useful,
1871 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1872 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1873 +# GNU General Public License for more details.
1875 +# You should have received a copy of the GNU General Public License
1876 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1878 +Policies to Select One among Multiple Writable Branches
1879 +----------------------------------------------------------------------
1880 +When the number of writable branch is more than one, aufs has to decide
1881 +the target branch for file creation or copy-up. By default, the highest
1882 +writable branch which has the parent (or ancestor) dir of the target
1883 +file is chosen (top-down-parent policy).
1884 +By user's request, aufs implements some other policies to select the
1885 +writable branch, for file creation several policies, round-robin,
1886 +most-free-space, and other policies. For copy-up, top-down-parent,
1887 +bottom-up-parent, bottom-up and others.
1889 +As expected, the round-robin policy selects the branch in circular. When
1890 +you have two writable branches and creates 10 new files, 5 files will be
1891 +created for each branch. mkdir(2) systemcall is an exception. When you
1892 +create 10 new directories, all will be created on the same branch.
1893 +And the most-free-space policy selects the one which has most free
1894 +space among the writable branches. The amount of free space will be
1895 +checked by aufs internally, and users can specify its time interval.
1897 +The policies for copy-up is more simple,
1898 +top-down-parent is equivalent to the same named on in create policy,
1899 +bottom-up-parent selects the writable branch where the parent dir
1900 +exists and the nearest upper one from the copyup-source,
1901 +bottom-up selects the nearest upper writable branch from the
1902 +copyup-source, regardless the existence of the parent dir.
1904 +There are some rules or exceptions to apply these policies.
1905 +- If there is a readonly branch above the policy-selected branch and
1906 + the parent dir is marked as opaque (a variation of whiteout), or the
1907 + target (creating) file is whiteout-ed on the upper readonly branch,
1908 + then the result of the policy is ignored and the target file will be
1909 + created on the nearest upper writable branch than the readonly branch.
1910 +- If there is a writable branch above the policy-selected branch and
1911 + the parent dir is marked as opaque or the target file is whiteouted
1912 + on the branch, then the result of the policy is ignored and the target
1913 + file will be created on the highest one among the upper writable
1914 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1916 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1917 + They try selecting the branch where the source exists as possible
1918 + since copyup a large file will take long time. If it can't be,
1919 + ie. the branch where the source exists is readonly, then they will
1920 + follow the copyup policy.
1921 +- There is an exception for rename(2) when the target exists.
1922 + If the rename target exists, aufs compares the index of the branches
1923 + where the source and the target exists and selects the higher
1924 + one. If the selected branch is readonly, then aufs follows the
1926 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1927 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1928 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2019-07-11 15:42:14.458904362 +0200
1931 +// to view this graph, run dot(1) command in GRAPHVIZ.
1935 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1939 +aufs_rename -> whinfo [label="store/remove"];
1942 +inode_list [label="h_inum list in branch\ncache"];
1945 +whinode [label="h_inum list file"];
1948 +brmgmt [label="br_add/del/mod/umount"];
1950 +brmgmt -> inode_list [label="create/remove"];
1951 +brmgmt -> whinode [label="load/store"];
1953 +inode_list -> whinode [style=dashed,dir=both];
1955 +aufs_rename -> inode_list [label="add/del"];
1957 +aufs_lookup -> inode_list [label="search"];
1959 +aufs_lookup -> whinfo [label="load/remove"];
1961 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1962 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1963 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2020-01-27 10:57:18.165538015 +0100
1966 +# Copyright (C) 2017-2020 Junjiro R. Okajima
1968 +# This program is free software; you can redistribute it and/or modify
1969 +# it under the terms of the GNU General Public License as published by
1970 +# the Free Software Foundation; either version 2 of the License, or
1971 +# (at your option) any later version.
1973 +# This program is distributed in the hope that it will be useful,
1974 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1975 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1976 +# GNU General Public License for more details.
1978 +# You should have received a copy of the GNU General Public License
1979 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1981 +Special handling for renaming a directory (DIRREN)
1982 +----------------------------------------------------------------------
1983 +First, let's assume we have a simple usecase.
1987 +- /ro/dirA and /ro/dirA/file exist too
1988 +- there is no dirB on both branches
1989 +- a user issues rename("dirA", "dirB")
1991 +Now, what should aufs behave against this rename(2)?
1992 +There are a few possible cases.
1995 + since dirA exists on a readonly branch which cannot be renamed.
1997 + it is possible to copy-up dirA (only the dir itself), but the child
1998 + entries ("file" in this case) should not be. it must be a bad
1999 + approach to copy-up recursively.
2000 +C. returns a success.
2001 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
2002 + is a violation of aufs' policy.
2003 +D. construct an extra information which indicates that /ro/dirA should
2004 + be handled as the name of dirB.
2005 + overlayfs has a similar feature called REDIRECT.
2007 +Until now, aufs implements the case B only which returns EXDEV, and
2008 +expects the userspace application behaves like mv(1) which tries
2009 +issueing rename(2) recursively.
2011 +A new aufs feature called DIRREN is introduced which implements the case
2012 +D. There are several "extra information" added.
2014 +1. detailed info per renamed directory
2015 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
2016 +2. the inode-number list of directories on a branch
2017 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
2019 +The filename of "detailed info per directory" represents the lower
2020 +branch, and its format is
2021 +- a type of the branch id
2023 + + uuid (not implemented yet)
2026 +- the inode-number of the branch root dir
2028 +And it contains these info in a single regular file.
2030 +- branch's inode-number of the logically renamed dir
2031 +- the name of the before-renamed dir
2033 +The "detailed info per directory" file is created in aufs rename(2), and
2034 +loaded in any lookup.
2035 +The info is considered in lookup for the matching case only. Here
2036 +"matching" means that the root of branch (in the info filename) is same
2037 +to the current looking-up branch. After looking-up the before-renamed
2038 +name, the inode-number is compared. And the matched dentry is used.
2040 +The "inode-number list of directories" is a regular file which contains
2041 +simply the inode-numbers on the branch. The file is created or updated
2042 +in removing the branch, and loaded in adding the branch. Its lifetime is
2043 +equal to the branch.
2044 +The list is refered in lookup, and when the current target inode is
2045 +found in the list, the aufs tries loading the "detailed info per
2046 +directory" and get the changed and valid name of the dir.
2048 +Theoretically these "extra informaiton" may be able to be put into XATTR
2049 +in the dir inode. But aufs doesn't choose this way because
2050 +1. XATTR may not be supported by the branch (or its configuration)
2051 +2. XATTR may have its size limit.
2052 +3. XATTR may be less easy to convert than a regular file, when the
2053 + format of the info is changed in the future.
2054 +At the same time, I agree that the regular file approach is much slower
2055 +than XATTR approach. So, in the future, aufs may take the XATTR or other
2058 +This DIRREN feature is enabled by aufs configuration, and is activated
2059 +by a new mount option.
2061 +For the more complicated case, there is a work with UDBA option, which
2062 +is to dected the direct access to the branches (by-passing aufs) and to
2063 +maintain the cashes in aufs. Since a single cached aufs dentry may
2064 +contains two names, before- and after-rename, the name comparision in
2065 +UDBA handler may not work correctly. In this case, the behaviour will be
2066 +equivalen to udba=reval case.
2067 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
2068 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
2069 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2020-01-27 10:57:18.165538015 +0100
2072 +# Copyright (C) 2011-2020 Junjiro R. Okajima
2074 +# This program is free software; you can redistribute it and/or modify
2075 +# it under the terms of the GNU General Public License as published by
2076 +# the Free Software Foundation; either version 2 of the License, or
2077 +# (at your option) any later version.
2079 +# This program is distributed in the hope that it will be useful,
2080 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2081 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2082 +# GNU General Public License for more details.
2084 +# You should have received a copy of the GNU General Public License
2085 +# along with this program; if not, write to the Free Software
2086 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2089 +File-based Hierarchical Storage Management (FHSM)
2090 +----------------------------------------------------------------------
2091 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2092 +storage world. Aufs provides this feature as file-based with multiple
2093 +writable branches, based upon the principle of "Colder, the Lower".
2094 +Here the word "colder" means that the less used files, and "lower" means
2095 +that the position in the order of the stacked branches vertically.
2096 +These multiple writable branches are prioritized, ie. the topmost one
2097 +should be the fastest drive and be used heavily.
2099 +o Characters in aufs FHSM story
2100 +- aufs itself and a new branch attribute.
2101 +- a new ioctl interface to move-down and to establish a connection with
2102 + the daemon ("move-down" is a converse of "copy-up").
2103 +- userspace tool and daemon.
2105 +The userspace daemon establishes a connection with aufs and waits for
2106 +the notification. The notified information is very similar to struct
2107 +statfs containing the number of consumed blocks and inodes.
2108 +When the consumed blocks/inodes of a branch exceeds the user-specified
2109 +upper watermark, the daemon activates its move-down process until the
2110 +consumed blocks/inodes reaches the user-specified lower watermark.
2112 +The actual move-down is done by aufs based upon the request from
2113 +user-space since we need to maintain the inode number and the internal
2114 +pointer arrays in aufs.
2116 +Currently aufs FHSM handles the regular files only. Additionally they
2117 +must not be hard-linked nor pseudo-linked.
2120 +o Cowork of aufs and the user-space daemon
2121 + During the userspace daemon established the connection, aufs sends a
2122 + small notification to it whenever aufs writes something into the
2123 + writable branch. But it may cost high since aufs issues statfs(2)
2124 + internally. So user can specify a new option to cache the
2125 + info. Actually the notification is controlled by these factors.
2126 + + the specified cache time.
2127 + + classified as "force" by aufs internally.
2128 + Until the specified time expires, aufs doesn't send the info
2129 + except the forced cases. When aufs decide forcing, the info is always
2130 + notified to userspace.
2131 + For example, the number of free inodes is generally large enough and
2132 + the shortage of it happens rarely. So aufs doesn't force the
2133 + notification when creating a new file, directory and others. This is
2134 + the typical case which aufs doesn't force.
2135 + When aufs writes the actual filedata and the files consumes any of new
2136 + blocks, the aufs forces notifying.
2139 +o Interfaces in aufs
2140 +- New branch attribute.
2142 + Specifies that the branch is managed by FHSM feature. In other word,
2143 + participant in the FHSM.
2144 + When nofhsm is set to the branch, it will not be the source/target
2145 + branch of the move-down operation. This attribute is set
2146 + independently from coo and moo attributes, and if you want full
2147 + FHSM, you should specify them as well.
2148 +- New mount option.
2150 + Specifies a second to suppress many less important info to be
2153 + + AUFS_CTL_FHSM_FD
2154 + create a new file descriptor which userspace can read the notification
2155 + (a subset of struct statfs) from aufs.
2156 +- Module parameter 'brs'
2157 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2159 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2160 + When there are two or more branches with fhsm attributes,
2161 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2162 + terminates it. As a result of remounting and branch-manipulation, the
2163 + number of branches with fhsm attribute can be one. In this case,
2164 + /sbin/mount.aufs will terminate the user-space daemon.
2167 +Finally the operation is done as these steps in kernel-space.
2169 + + no one else is using the file.
2170 + + the file is not hard-linked.
2171 + + the file is not pseudo-linked.
2172 + + the file is a regular file.
2173 + + the parent dir is not opaqued.
2174 +- find the target writable branch.
2175 +- make sure the file is not whiteout-ed by the upper (than the target)
2177 +- make the parent dir on the target branch.
2178 +- mutex lock the inode on the branch.
2179 +- unlink the whiteout on the target branch (if exists).
2180 +- lookup and create the whiteout-ed temporary name on the target branch.
2181 +- copy the file as the whiteout-ed temporary name on the target branch.
2182 +- rename the whiteout-ed temporary name to the original name.
2183 +- unlink the file on the source branch.
2184 +- maintain the internal pointer array and the external inode number
2186 +- maintain the timestamps and other attributes of the parent dir and the
2189 +And of course, in every step, an error may happen. So the operation
2190 +should restore the original file state after an error happens.
2191 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2192 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2193 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2020-01-27 10:57:18.165538015 +0100
2196 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2198 +# This program is free software; you can redistribute it and/or modify
2199 +# it under the terms of the GNU General Public License as published by
2200 +# the Free Software Foundation; either version 2 of the License, or
2201 +# (at your option) any later version.
2203 +# This program is distributed in the hope that it will be useful,
2204 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2205 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2206 +# GNU General Public License for more details.
2208 +# You should have received a copy of the GNU General Public License
2209 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2211 +mmap(2) -- File Memory Mapping
2212 +----------------------------------------------------------------------
2213 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2214 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2216 +This approach is simple and good, but there is one problem.
2217 +Under /proc, several entries show the mmapped files by its path (with
2218 +device and inode number), and the printed path will be the path on the
2219 +branch fs's instead of virtual aufs's.
2220 +This is not a problem in most cases, but some utilities lsof(1) (and its
2221 +user) may expect the path on aufs.
2223 +To address this issue, aufs adds a new member called vm_prfile in struct
2224 +vm_area_struct (and struct vm_region). The original vm_file points to
2225 +the file on the branch fs in order to handle everything correctly as
2226 +usual. The new vm_prfile points to a virtual file in aufs, and the
2227 +show-functions in procfs refers to vm_prfile if it is set.
2228 +Also we need to maintain several other places where touching vm_file
2230 +- fork()/clone() copies vma and the reference count of vm_file is
2232 +- merging vma maintains the ref count too.
2234 +This is not a good approach. It just fakes the printed path. But it
2235 +leaves all behaviour around f_mapping unchanged. This is surely an
2237 +Actually aufs had adopted another complicated approach which calls
2238 +generic_file_mmap() and handles struct vm_operations_struct. In this
2239 +approach, aufs met a hard problem and I could not solve it without
2240 +switching the approach.
2242 +There may be one more another approach which is
2243 +- bind-mount the branch-root onto the aufs-root internally
2244 +- grab the new vfsmount (ie. struct mount)
2245 +- lazy-umount the branch-root internally
2246 +- in open(2) the aufs-file, open the branch-file with the hidden
2247 + vfsmount (instead of the original branch's vfsmount)
2248 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2249 + but it may be possible from userspace by the mount helper.
2251 +Adding the internal hidden vfsmount and using it in opening a file, the
2252 +file path under /proc will be printed correctly. This approach looks
2253 +smarter, but is not possible I am afraid.
2254 +- aufs-root may be bind-mount later. when it happens, another hidden
2255 + vfsmount will be required.
2256 +- it is hard to get the chance to bind-mount and lazy-umount
2257 + + in kernel-space, FS can have vfsmount in open(2) via
2258 + file->f_path, and aufs can know its vfsmount. But several locks are
2259 + already acquired, and if aufs tries to bind-mount and lazy-umount
2260 + here, then it may cause a deadlock.
2261 + + in user-space, bind-mount doesn't invoke the mount helper.
2262 +- since /proc shows dev and ino, aufs has to give vma these info. it
2263 + means a new member vm_prinode will be necessary. this is essentially
2264 + equivalent to vm_prfile described above.
2266 +I have to give up this "looks-smater" approach.
2267 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2268 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2269 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2020-01-27 10:57:18.165538015 +0100
2272 +# Copyright (C) 2014-2020 Junjiro R. Okajima
2274 +# This program is free software; you can redistribute it and/or modify
2275 +# it under the terms of the GNU General Public License as published by
2276 +# the Free Software Foundation; either version 2 of the License, or
2277 +# (at your option) any later version.
2279 +# This program is distributed in the hope that it will be useful,
2280 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2281 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2282 +# GNU General Public License for more details.
2284 +# You should have received a copy of the GNU General Public License
2285 +# along with this program; if not, write to the Free Software
2286 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2289 +Listing XATTR/EA and getting the value
2290 +----------------------------------------------------------------------
2291 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2292 +shows the values from the topmost existing file. This behaviour is good
2293 +for the non-dir entries since the bahaviour exactly matches the shown
2294 +information. But for the directories, aufs considers all the same named
2295 +entries on the lower branches. Which means, if one of the lower entry
2296 +rejects readdir call, then aufs returns an error even if the topmost
2297 +entry allows it. This behaviour is necessary to respect the branch fs's
2298 +security, but can make users confused since the user-visible standard
2299 +attributes don't match the behaviour.
2300 +To address this issue, aufs has a mount option called dirperm1 which
2301 +checks the permission for the topmost entry only, and ignores the lower
2302 +entry's permission.
2304 +A similar issue can happen around XATTR.
2305 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2306 +always set. Otherwise these very unpleasant situation would happen.
2307 +- listxattr(2) may return the duplicated entries.
2308 +- users may not be able to remove or reset the XATTR forever,
2311 +XATTR/EA support in the internal (copy,move)-(up,down)
2312 +----------------------------------------------------------------------
2313 +Generally the extended attributes of inode are categorized as these.
2314 +- "security" for LSM and capability.
2315 +- "system" for posix ACL, 'acl' mount option is required for the branch
2317 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2318 +- "user" for userspace, 'user_xattr' mount option is required for the
2319 + branch fs generally.
2321 +Moreover there are some other categories. Aufs handles these rather
2322 +unpopular categories as the ordinary ones, ie. there is no special
2323 +condition nor exception.
2325 +In copy-up, the support for XATTR on the dst branch may differ from the
2326 +src branch. In this case, the copy-up operation will get an error and
2327 +the original user operation which triggered the copy-up will fail. It
2328 +can happen that even all copy-up will fail.
2329 +When both of src and dst branches support XATTR and if an error occurs
2330 +during copying XATTR, then the copy-up should fail obviously. That is a
2331 +good reason and aufs should return an error to userspace. But when only
2332 +the src branch support that XATTR, aufs should not return an error.
2333 +For example, the src branch supports ACL but the dst branch doesn't
2334 +because the dst branch may natively un-support it or temporary
2335 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2336 +may NOT return an error even if the XATTR is not supported. It is
2337 +totally up to the branch fs.
2339 +Anyway when the aufs internal copy-up gets an error from the dst branch
2340 +fs, then aufs tries removing the just copied entry and returns the error
2341 +to the userspace. The worst case of this situation will be all copy-up
2344 +For the copy-up operation, there two basic approaches.
2345 +- copy the specified XATTR only (by category above), and return the
2346 + error unconditionally if it happens.
2347 +- copy all XATTR, and ignore the error on the specified category only.
2349 +In order to support XATTR and to implement the correct behaviour, aufs
2350 +chooses the latter approach and introduces some new branch attributes,
2351 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2352 +They correspond to the XATTR namespaces (see above). Additionally, to be
2353 +convenient, "icex" is also provided which means all "icex*" attributes
2354 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2356 +The meaning of these attributes is to ignore the error from setting
2357 +XATTR on that branch.
2358 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2359 +error from the dst branch according to the specified attributes.
2361 +Some XATTR may have its default value. The default value may come from
2362 +the parent dir or the environment. If the default value is set at the
2363 +file creating-time, it will be overwritten by copy-up.
2364 +Some contradiction may happen I am afraid.
2365 +Do we need another attribute to stop copying XATTR? I am unsure. For
2366 +now, aufs implements the branch attributes to ignore the error.
2367 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2368 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2369 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2020-01-27 10:57:18.165538015 +0100
2372 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2374 +# This program is free software; you can redistribute it and/or modify
2375 +# it under the terms of the GNU General Public License as published by
2376 +# the Free Software Foundation; either version 2 of the License, or
2377 +# (at your option) any later version.
2379 +# This program is distributed in the hope that it will be useful,
2380 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2381 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2382 +# GNU General Public License for more details.
2384 +# You should have received a copy of the GNU General Public License
2385 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2387 +Export Aufs via NFS
2388 +----------------------------------------------------------------------
2389 +Here is an approach.
2390 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2392 +- iget_locked(): initialize aufs inode generation for a new inode, and
2393 + store it in xigen file.
2394 +- destroy_inode(): increment aufs inode generation and store it in xigen
2395 + file. it is necessary even if it is not unlinked, because any data of
2396 + inode may be changed by UDBA.
2397 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2398 + build file handle by
2399 + + branch id (4 bytes)
2400 + + superblock generation (4 bytes)
2401 + + inode number (4 or 8 bytes)
2402 + + parent dir inode number (4 or 8 bytes)
2403 + + inode generation (4 bytes))
2404 + + return value of exportfs_encode_fh() for the parent on a branch (4
2406 + + file handle for a branch (by exportfs_encode_fh())
2408 + + find the index of a branch from its id in handle, and check it is
2409 + still exist in aufs.
2410 + + 1st level: get the inode number from handle and search it in cache.
2411 + + 2nd level: if not found in cache, get the parent inode number from
2412 + the handle and search it in cache. and then open the found parent
2413 + dir, find the matching inode number by vfs_readdir() and get its
2414 + name, and call lookup_one_len() for the target dentry.
2415 + + 3rd level: if the parent dir is not cached, call
2416 + exportfs_decode_fh() for a branch and get the parent on a branch,
2417 + build a pathname of it, convert it a pathname in aufs, call
2418 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2420 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2421 + for every branch, but not itself. to get this, (currently) aufs
2422 + searches in current->nsproxy->mnt_ns list. it may not be a good
2423 + idea, but I didn't get other approach.
2424 + + test the generation of the gotten inode.
2425 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2426 + convert it into ESTALE for NFSD.
2427 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2428 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2429 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2430 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2431 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2020-01-27 10:57:18.165538015 +0100
2434 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2436 +# This program is free software; you can redistribute it and/or modify
2437 +# it under the terms of the GNU General Public License as published by
2438 +# the Free Software Foundation; either version 2 of the License, or
2439 +# (at your option) any later version.
2441 +# This program is distributed in the hope that it will be useful,
2442 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2443 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2444 +# GNU General Public License for more details.
2446 +# You should have received a copy of the GNU General Public License
2447 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2449 +Show Whiteout Mode (shwh)
2450 +----------------------------------------------------------------------
2451 +Generally aufs hides the name of whiteouts. But in some cases, to show
2452 +them is very useful for users. For instance, creating a new middle layer
2453 +(branch) by merging existing layers.
2455 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2456 +When you have three branches,
2457 +- Bottom: 'system', squashfs (underlying base system), read-only
2458 +- Middle: 'mods', squashfs, read-only
2459 +- Top: 'overlay', ram (tmpfs), read-write
2461 +The top layer is loaded at boot time and saved at shutdown, to preserve
2462 +the changes made to the system during the session.
2463 +When larger changes have been made, or smaller changes have accumulated,
2464 +the size of the saved top layer data grows. At this point, it would be
2465 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2466 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2467 +restoring save and load speed.
2469 +This merging is simplified by the use of another aufs mount, of just the
2470 +two overlay branches using the 'shwh' option.
2471 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2472 + aufs /livesys/merge_union
2474 +A merged view of these two branches is then available at
2475 +/livesys/merge_union, and the new feature is that the whiteouts are
2477 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2478 +writing to all branches. Also the default mode for all branches is 'ro'.
2479 +It is now possible to save the combined contents of the two overlay
2480 +branches to a new squashfs, e.g.:
2481 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2483 +This new squashfs archive can be stored on the boot device and the
2484 +initramfs will use it to replace the old one at the next boot.
2485 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2486 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2487 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2020-01-27 10:57:18.165538015 +0100
2490 +# Copyright (C) 2010-2020 Junjiro R. Okajima
2492 +# This program is free software; you can redistribute it and/or modify
2493 +# it under the terms of the GNU General Public License as published by
2494 +# the Free Software Foundation; either version 2 of the License, or
2495 +# (at your option) any later version.
2497 +# This program is distributed in the hope that it will be useful,
2498 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2499 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2500 +# GNU General Public License for more details.
2502 +# You should have received a copy of the GNU General Public License
2503 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2505 +Dynamically customizable FS operations
2506 +----------------------------------------------------------------------
2507 +Generally FS operations (struct inode_operations, struct
2508 +address_space_operations, struct file_operations, etc.) are defined as
2509 +"static const", but it never means that FS have only one set of
2510 +operation. Some FS have multiple sets of them. For instance, ext2 has
2511 +three sets, one for XIP, for NOBH, and for normal.
2512 +Since aufs overrides and redirects these operations, sometimes aufs has
2513 +to change its behaviour according to the branch FS type. More importantly
2514 +VFS acts differently if a function (member in the struct) is set or
2515 +not. It means aufs should have several sets of operations and select one
2516 +among them according to the branch FS definition.
2518 +In order to solve this problem and not to affect the behaviour of VFS,
2519 +aufs defines these operations dynamically. For instance, aufs defines
2520 +dummy direct_IO function for struct address_space_operations, but it may
2521 +not be set to the address_space_operations actually. When the branch FS
2522 +doesn't have it, aufs doesn't set it to its address_space_operations
2523 +while the function definition itself is still alive. So the behaviour
2524 +itself will not change, and it will return an error when direct_IO is
2527 +The lifetime of these dynamically generated operation object is
2528 +maintained by aufs branch object. When the branch is removed from aufs,
2529 +the reference counter of the object is decremented. When it reaches
2530 +zero, the dynamically generated operation object will be freed.
2532 +This approach is designed to support AIO (io_submit), Direct I/O and
2534 +Currently this approach is applied to address_space_operations for
2535 +regular files only.
2536 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2537 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2538 +++ linux/Documentation/filesystems/aufs/README 2020-01-23 09:59:36.748660743 +0100
2541 +Aufs5 -- advanced multi layered unification filesystem version 5.x
2547 +----------------------------------------
2548 +In the early days, aufs was entirely re-designed and re-implemented
2549 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2550 +improvements and implementations, it became totally different from
2551 +Unionfs while keeping the basic features.
2552 +Later, Unionfs Version 2.x series began taking some of the same
2553 +approaches to aufs1's.
2554 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2555 +University and his team.
2557 +Aufs5 supports linux-v5.0 and later, If you want older kernel version
2559 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2560 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2561 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2562 + or aufs1 from CVS on SourceForge.
2564 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2565 + According to Christoph Hellwig, linux rejects all union-type
2566 + filesystems but UnionMount.
2567 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2569 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2570 + UnionMount, and he pointed out an issue around a directory mutex
2571 + lock and aufs addressed it. But it is still unsure whether aufs will
2572 + be merged (or any other union solution).
2573 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2577 +----------------------------------------
2578 +- unite several directories into a single virtual filesystem. The member
2579 + directory is called as a branch.
2580 +- you can specify the permission flags to the branch, which are 'readonly',
2581 + 'readwrite' and 'whiteout-able.'
2582 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2583 + readonly branch are modifiable logically.
2584 +- dynamic branch manipulation, add, del.
2587 +Also there are many enhancements in aufs, such as:
2588 +- test only the highest one for the directory permission (dirperm1)
2589 +- copyup on open (coo=)
2590 +- 'move' policy for copy-up between two writable branches, after
2591 + checking free space.
2593 +- readdir(3) in userspace.
2594 +- keep inode number by external inode number table
2595 +- keep the timestamps of file/dir in internal copyup operation
2596 +- seekable directory, supporting NFS readdir.
2597 +- whiteout is hardlinked in order to reduce the consumption of inodes
2599 +- do not copyup, nor create a whiteout when it is unnecessary
2600 +- revert a single systemcall when an error occurs in aufs
2601 +- remount interface instead of ioctl
2602 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2603 +- loopback mounted filesystem as a branch
2604 +- kernel thread for removing the dir who has a plenty of whiteouts
2605 +- support copyup sparse file (a file which has a 'hole' in it)
2606 +- default permission flags for branches
2607 +- selectable permission flags for ro branch, whether whiteout can
2610 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2611 +- support multiple writable branches, some policies to select one
2612 + among multiple writable branches.
2613 +- a new semantics for link(2) and rename(2) to support multiple
2614 + writable branches.
2615 +- no glibc changes are required.
2616 +- pseudo hardlink (hardlink over branches)
2617 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2618 + including NFS or remote filesystem branch.
2619 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2622 +Currently these features are dropped temporary from aufs5.
2623 +See design/08plan.txt in detail.
2624 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2626 +- statistics of aufs thread (/sys/fs/aufs/stat)
2628 +Features or just an idea in the future (see also design/*.txt),
2629 +- reorder the branch index without del/re-add.
2630 +- permanent xino files for NFSD
2631 +- an option for refreshing the opened files after add/del branches
2632 +- light version, without branch manipulation. (unnecessary?)
2633 +- copyup in userspace
2634 +- inotify in userspace
2639 +----------------------------------------
2640 +There are three GIT trees for aufs5, aufs5-linux.git,
2641 +aufs5-standalone.git, and aufs-util.git. Note that there is no "5" in
2643 +While the aufs-util is always necessary, you need either of aufs5-linux
2644 +or aufs5-standalone.
2646 +The aufs5-linux tree includes the whole linux mainline GIT tree,
2647 +git://git.kernel.org/.../torvalds/linux.git.
2648 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2649 +build aufs5 as an external kernel module.
2650 +Several extra patches are not included in this tree. Only
2651 +aufs5-standalone tree contains them. They are described in the later
2652 +section "Configuration and Compilation."
2654 +On the other hand, the aufs5-standalone tree has only aufs source files
2655 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2656 +But you need to apply all aufs patches manually.
2658 +You will find GIT branches whose name is in form of "aufs5.x" where "x"
2659 +represents the linux kernel version, "linux-5.x". For instance,
2660 +"aufs5.0" is for linux-5.0. For latest "linux-5.x-rcN", use
2661 +"aufs5.x-rcN" branch.
2664 +$ git clone --reference /your/linux/git/tree \
2665 + git://github.com/sfjro/aufs5-linux.git aufs5-linux.git
2666 +- if you don't have linux GIT tree, then remove "--reference ..."
2667 +$ cd aufs5-linux.git
2668 +$ git checkout origin/aufs5.0
2670 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2671 +leave the patch-work to GIT.
2672 +$ cd /your/linux/git/tree
2673 +$ git remote add aufs5 git://github.com/sfjro/aufs5-linux.git
2675 +$ git checkout -b my5.0 v5.0
2676 +$ (add your local change...)
2677 +$ git pull aufs5 aufs5.0
2678 +- now you have v5.0 + your_changes + aufs5.0 in you my5.0 branch.
2679 +- you may need to solve some conflicts between your_changes and
2680 + aufs5.0. in this case, git-rerere is recommended so that you can
2681 + solve the similar conflicts automatically when you upgrade to 5.1 or
2682 + later in the future.
2684 +o aufs5-standalone tree
2685 +$ git clone git://github.com/sfjro/aufs5-standalone.git aufs5-standalone.git
2686 +$ cd aufs5-standalone.git
2687 +$ git checkout origin/aufs5.0
2690 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2691 +- note that the public aufs-util.git is on SourceForge instead of
2694 +$ git checkout origin/aufs5.0
2696 +Note: The 5.x-rcN branch is to be used with `rc' kernel versions ONLY.
2697 +The minor version number, 'x' in '5.x', of aufs may not always
2698 +follow the minor version number of the kernel.
2699 +Because changes in the kernel that cause the use of a new
2700 +minor version number do not always require changes to aufs-util.
2702 +Since aufs-util has its own minor version number, you may not be
2703 +able to find a GIT branch in aufs-util for your kernel's
2704 +exact minor version number.
2705 +In this case, you should git-checkout the branch for the
2706 +nearest lower number.
2708 +For (an unreleased) example:
2709 +If you are using "linux-5.10" and the "aufs5.10" branch
2710 +does not exist in aufs-util repository, then "aufs5.9", "aufs5.8"
2711 +or something numerically smaller is the branch for your kernel.
2713 +Also you can view all branches by
2717 +3. Configuration and Compilation
2718 +----------------------------------------
2719 +Make sure you have git-checkout'ed the correct branch.
2721 +For aufs5-linux tree,
2722 +- enable CONFIG_AUFS_FS.
2723 +- set other aufs configurations if necessary.
2725 +For aufs5-standalone tree,
2726 +There are several ways to build.
2729 +- apply ./aufs5-kbuild.patch to your kernel source files.
2730 +- apply ./aufs5-base.patch too.
2731 +- apply ./aufs5-mmap.patch too.
2732 +- apply ./aufs5-standalone.patch too, if you have a plan to set
2733 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch.
2734 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2735 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2736 +- enable CONFIG_AUFS_FS, you can select either
2738 +- and build your kernel as usual.
2739 +- install the built kernel.
2740 +- install the header files too by "make headers_install" to the
2741 + directory where you specify. By default, it is $PWD/usr.
2742 + "make help" shows a brief note for headers_install.
2743 +- and reboot your system.
2746 +- module only (CONFIG_AUFS_FS=m).
2747 +- apply ./aufs5-base.patch to your kernel source files.
2748 +- apply ./aufs5-mmap.patch too.
2749 +- apply ./aufs5-standalone.patch too.
2750 +- build your kernel, don't forget "make headers_install", and reboot.
2751 +- edit ./config.mk and set other aufs configurations if necessary.
2752 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2753 + every aufs configurations.
2754 +- build the module by simple "make".
2755 +- you can specify ${KDIR} make variable which points to your kernel
2757 +- install the files
2758 + + run "make install" to install the aufs module, or copy the built
2759 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2760 + + run "make install_headers" (instead of headers_install) to install
2761 + the modified aufs header file (you can specify DESTDIR which is
2762 + available in aufs standalone version's Makefile only), or copy
2763 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2764 + you like manually. By default, the target directory is $PWD/usr.
2765 +- no need to apply aufs5-kbuild.patch, nor copying source files to your
2766 + kernel source tree.
2768 +Note: The header file aufs_type.h is necessary to build aufs-util
2769 + as well as "make headers_install" in the kernel source tree.
2770 + headers_install is subject to be forgotten, but it is essentially
2771 + necessary, not only for building aufs-util.
2772 + You may not meet problems without headers_install in some older
2776 +- read README in aufs-util, build and install it
2777 +- note that your distribution may contain an obsoleted version of
2778 + aufs_type.h in /usr/include/linux or something. When you build aufs
2779 + utilities, make sure that your compiler refers the correct aufs header
2780 + file which is built by "make headers_install."
2781 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2782 + then run "make install_ulib" too. And refer to the aufs manual in
2785 +There several other patches in aufs5-standalone.git. They are all
2786 +optional. When you meet some problems, they will help you.
2787 +- aufs5-loopback.patch
2788 + Supports a nested loopback mount in a branch-fs. This patch is
2789 + unnecessary until aufs produces a message like "you may want to try
2790 + another patch for loopback file".
2791 +- proc_mounts.patch
2792 + When there are many mountpoints and many mount(2)/umount(2) are
2793 + running, then /proc/mounts may not show the all mountpoints. This
2794 + patch makes /proc/mounts always show the full mountpoints list.
2795 + If you don't want to apply this patch and meet such problem, then you
2796 + need to increase the value of 'ProcMounts_Times' make-variable in
2797 + aufs-util.git as a second best solution.
2799 + Modifies a system global kernel internal function get_next_ino() in
2800 + order to stop assigning 0 for an inode-number. Not directly related to
2801 + aufs, but recommended generally.
2803 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2804 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2805 + duplication of inode number, which is important for backup tools and
2806 + other utilities. When you find aufs XINO files for tmpfs branch
2807 + growing too much, try this patch.
2808 +- lockdep-debug.patch
2809 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2810 + also a caller of VFS functions for branch filesystems, subclassing of
2811 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2812 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2813 + need to apply this debug patch to expand several constant values.
2814 + If you don't know what LOCKDEP is, then you don't have apply this
2819 +----------------------------------------
2820 +At first, make sure aufs-util are installed, and please read the aufs
2821 +manual, aufs.5 in aufs-util.git tree.
2825 +$ mkdir /tmp/rw /tmp/aufs
2826 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2828 +Here is another example. The result is equivalent.
2829 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2831 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2832 +# mount -o remount,append:${HOME} /tmp/aufs
2834 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2835 +you modify a file under /tmp/aufs, the one on your home directory is
2836 +not affected, instead the same named file will be newly created under
2837 +/tmp/rw. And all of your modification to a file will be applied to
2838 +the one under /tmp/rw. This is called the file based Copy on Write
2840 +Aufs mount options are described in aufs.5.
2841 +If you run chroot or something and make your aufs as a root directory,
2842 +then you need to customize the shutdown script. See the aufs manual in
2845 +Additionally, there are some sample usages of aufs which are a
2846 +diskless system with network booting, and LiveCD over NFS.
2847 +See sample dir in CVS tree on SourceForge.
2851 +----------------------------------------
2852 +When you have any problems or strange behaviour in aufs, please let me
2854 +- /proc/mounts (instead of the output of mount(8))
2855 +- /sys/module/aufs/*
2856 +- /sys/fs/aufs/* (if you have them)
2857 +- /debug/aufs/* (if you have them)
2858 +- linux kernel version
2859 + if your kernel is not plain, for example modified by distributor,
2860 + the url where i can download its source is necessary too.
2861 +- aufs version which was printed at loading the module or booting the
2862 + system, instead of the date you downloaded.
2863 +- configuration (define/undefine CONFIG_AUFS_xxx)
2864 +- kernel configuration or /proc/config.gz (if you have it)
2865 +- LSM (linux security module, if you are using)
2866 +- behaviour which you think to be incorrect
2867 +- actual operation, reproducible one is better
2868 +- mailto: aufs-users at lists.sourceforge.net
2870 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2871 +and Feature Requests) on SourceForge. Please join and write to
2875 +6. Acknowledgements
2876 +----------------------------------------
2877 +Thanks to everyone who have tried and are using aufs, whoever
2878 +have reported a bug or any feedback.
2880 +Especially donators:
2881 +Tomas Matejicek(slax.org) made a donation (much more than once).
2882 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2883 + scripts) is making "doubling" donations.
2884 + Unfortunately I cannot list all of the donators, but I really
2886 + It ends Aug 2010, but the ordinary donation URL is still available.
2887 + <http://sourceforge.net/donate/index.php?group_id=167503>
2888 +Dai Itasaka made a donation (2007/8).
2889 +Chuck Smith made a donation (2008/4, 10 and 12).
2890 +Henk Schoneveld made a donation (2008/9).
2891 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2892 +Francois Dupoux made a donation (2008/11).
2893 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2894 + aufs2 GIT tree (2009/2).
2895 +William Grant made a donation (2009/3).
2896 +Patrick Lane made a donation (2009/4).
2897 +The Mail Archive (mail-archive.com) made donations (2009/5).
2898 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2899 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2900 +Pavel Pronskiy made a donation (2011/2).
2901 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2902 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2903 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2905 +Sam Liddicott made a donation (2011/9).
2906 +Era Scarecrow made a donation (2013/4).
2907 +Bor Ratajc made a donation (2013/4).
2908 +Alessandro Gorreta made a donation (2013/4).
2909 +POIRETTE Marc made a donation (2013/4).
2910 +Alessandro Gorreta made a donation (2013/4).
2911 +lauri kasvandik made a donation (2013/5).
2912 +"pemasu from Finland" made a donation (2013/7).
2913 +The Parted Magic Project made a donation (2013/9 and 11).
2914 +Pavel Barta made a donation (2013/10).
2915 +Nikolay Pertsev made a donation (2014/5).
2916 +James B made a donation (2014/7 and 2015/7).
2917 +Stefano Di Biase made a donation (2014/8).
2918 +Daniel Epellei made a donation (2015/1).
2919 +OmegaPhil made a donation (2016/1, 2018/4).
2920 +Tomasz Szewczyk made a donation (2016/4).
2921 +James Burry made a donation (2016/12).
2922 +Carsten Rose made a donation (2018/9).
2923 +Porteus Kiosk made a donation (2018/10).
2925 +Thank you very much.
2926 +Donations are always, including future donations, very important and
2927 +helpful for me to keep on developing aufs.
2931 +----------------------------------------
2932 +If you are an experienced user, no explanation is needed. Aufs is
2933 +just a linux filesystem.
2938 +# Local variables: ;
2941 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2942 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2943 +++ linux/fs/aufs/aufs.h 2020-01-27 10:57:18.165538015 +0100
2945 +/* SPDX-License-Identifier: GPL-2.0 */
2947 + * Copyright (C) 2005-2020 Junjiro R. Okajima
2949 + * This program, aufs is free software; you can redistribute it and/or modify
2950 + * it under the terms of the GNU General Public License as published by
2951 + * the Free Software Foundation; either version 2 of the License, or
2952 + * (at your option) any later version.
2954 + * This program is distributed in the hope that it will be useful,
2955 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2956 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2957 + * GNU General Public License for more details.
2959 + * You should have received a copy of the GNU General Public License
2960 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2964 + * all header files
2972 +#define AuStub(type, name, body, ...) \
2973 + static inline type name(__VA_ARGS__) { body; }
2975 +#define AuStubVoid(name, ...) \
2976 + AuStub(void, name, , __VA_ARGS__)
2977 +#define AuStubInt0(name, ...) \
2978 + AuStub(int, name, return 0, __VA_ARGS__)
2982 +#include "branch.h"
2985 +#include "dbgaufs.h"
2986 +#include "dentry.h"
2988 +#include "dirren.h"
2991 +#include "fstype.h"
2996 +#include "module.h"
3000 +#include "sysaufs.h"
3005 +#endif /* __KERNEL__ */
3006 +#endif /* __AUFS_H__ */
3007 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
3008 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
3009 +++ linux/fs/aufs/branch.c 2020-08-03 09:14:46.095748745 +0200
3011 +// SPDX-License-Identifier: GPL-2.0
3013 + * Copyright (C) 2005-2020 Junjiro R. Okajima
3015 + * This program, aufs is free software; you can redistribute it and/or modify
3016 + * it under the terms of the GNU General Public License as published by
3017 + * the Free Software Foundation; either version 2 of the License, or
3018 + * (at your option) any later version.
3020 + * This program is distributed in the hope that it will be useful,
3021 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3022 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3023 + * GNU General Public License for more details.
3025 + * You should have received a copy of the GNU General Public License
3026 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3030 + * branch management
3033 +#include <linux/compat.h>
3034 +#include <linux/statfs.h>
3038 + * free a single branch
3040 +static void au_br_do_free(struct au_branch *br)
3043 + struct au_wbr *wbr;
3044 + struct au_dykey **key;
3046 + au_hnotify_fin_br(br);
3047 + /* always, regardless the mount option */
3048 + au_dr_hino_free(&br->br_dirren);
3051 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
3052 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
3053 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
3054 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
3058 + for (i = 0; i < AuBrWh_Last; i++)
3059 + dput(wbr->wbr_wh[i]);
3060 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
3061 + AuRwDestroy(&wbr->wbr_wh_rwsem);
3064 + if (br->br_fhsm) {
3065 + au_br_fhsm_fin(br->br_fhsm);
3066 + au_kfree_try_rcu(br->br_fhsm);
3069 + key = br->br_dykey;
3070 + for (i = 0; i < AuBrDynOp; i++, key++)
3076 + /* recursive lock, s_umount of branch's */
3077 + /* synchronize_rcu(); */ /* why? */
3079 + path_put(&br->br_path);
3081 + au_kfree_rcu(wbr);
3082 + au_lcnt_wait_for_fin(&br->br_nfiles);
3083 + au_lcnt_wait_for_fin(&br->br_count);
3084 + /* I don't know why, but percpu_refcount requires this */
3085 + /* synchronize_rcu(); */
3090 + * frees all branches
3092 +void au_br_free(struct au_sbinfo *sbinfo)
3094 + aufs_bindex_t bmax;
3095 + struct au_branch **br;
3097 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3099 + bmax = sbinfo->si_bbot + 1;
3100 + br = sbinfo->si_branch;
3102 + au_br_do_free(*br++);
3106 + * find the index of a branch which is specified by @br_id.
3108 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3110 + aufs_bindex_t bindex, bbot;
3112 + bbot = au_sbbot(sb);
3113 + for (bindex = 0; bindex <= bbot; bindex++)
3114 + if (au_sbr_id(sb, bindex) == br_id)
3119 +/* ---------------------------------------------------------------------- */
3125 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3126 + struct dentry *h_root)
3128 + if (unlikely(h_adding == h_root
3129 + || au_test_loopback_overlap(sb, h_adding)))
3131 + if (h_adding->d_sb != h_root->d_sb)
3133 + return au_test_subdir(h_adding, h_root)
3134 + || au_test_subdir(h_root, h_adding);
3138 + * returns a newly allocated branch. @new_nbranch is a number of branches
3139 + * after adding a branch.
3141 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3144 + struct au_branch *add_branch;
3145 + struct dentry *root;
3146 + struct inode *inode;
3150 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3151 + if (unlikely(!add_branch))
3153 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3154 + if (unlikely(!add_branch->br_xino))
3156 + err = au_hnotify_init_br(add_branch, perm);
3157 + if (unlikely(err))
3160 + if (au_br_writable(perm)) {
3161 + /* may be freed separately at changing the branch permission */
3162 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3164 + if (unlikely(!add_branch->br_wbr))
3168 + if (au_br_fhsm(perm)) {
3169 + err = au_fhsm_br_alloc(add_branch);
3170 + if (unlikely(err))
3174 + root = sb->s_root;
3175 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3177 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3179 + inode = d_inode(root);
3180 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3184 + return add_branch; /* success */
3187 + au_kfree_rcu(add_branch->br_wbr);
3189 + au_hnotify_fin_br(add_branch);
3191 + au_xino_put(add_branch);
3193 + au_kfree_rcu(add_branch);
3195 + return ERR_PTR(err);
3199 + * test if the branch permission is legal or not.
3201 +static int test_br(struct inode *inode, int brperm, char *path)
3205 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3210 + pr_err("write permission for readonly mount or inode, %s\n", path);
3218 + * 0: success, the caller will add it
3219 + * plus: success, it is already unified, the caller should ignore it
3222 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3225 + aufs_bindex_t bbot, bindex;
3226 + struct dentry *root, *h_dentry;
3227 + struct inode *inode, *h_inode;
3229 + root = sb->s_root;
3230 + bbot = au_sbbot(sb);
3231 + if (unlikely(bbot >= 0
3232 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3236 + pr_err("%s duplicated\n", add->pathname);
3241 + err = -ENOSPC; /* -E2BIG; */
3242 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3243 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3244 + pr_err("number of branches exceeded %s\n", add->pathname);
3249 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3250 + pr_err("bad index %d\n", add->bindex);
3254 + inode = d_inode(add->path.dentry);
3256 + if (unlikely(!inode->i_nlink)) {
3257 + pr_err("no existence %s\n", add->pathname);
3262 + if (unlikely(inode->i_sb == sb)) {
3263 + pr_err("%s must be outside\n", add->pathname);
3267 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3268 + pr_err("unsupported filesystem, %s (%s)\n",
3269 + add->pathname, au_sbtype(inode->i_sb));
3273 + if (unlikely(inode->i_sb->s_stack_depth)) {
3274 + pr_err("already stacked, %s (%s)\n",
3275 + add->pathname, au_sbtype(inode->i_sb));
3279 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3280 + if (unlikely(err))
3284 + return 0; /* success */
3287 + for (bindex = 0; bindex <= bbot; bindex++)
3288 + if (unlikely(test_overlap(sb, add->path.dentry,
3289 + au_h_dptr(root, bindex)))) {
3290 + pr_err("%s is overlapped\n", add->pathname);
3295 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3296 + h_dentry = au_h_dptr(root, 0);
3297 + h_inode = d_inode(h_dentry);
3298 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3299 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3300 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3301 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3303 + i_uid_read(inode), i_gid_read(inode),
3304 + (inode->i_mode & S_IALLUGO),
3305 + i_uid_read(h_inode), i_gid_read(h_inode),
3306 + (h_inode->i_mode & S_IALLUGO));
3314 + * initialize or clean the whiteouts for an adding branch
3316 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3319 + int err, old_perm;
3320 + aufs_bindex_t bindex;
3321 + struct inode *h_inode;
3322 + struct au_wbr *wbr;
3323 + struct au_hinode *hdir;
3324 + struct dentry *h_dentry;
3326 + err = vfsub_mnt_want_write(au_br_mnt(br));
3327 + if (unlikely(err))
3331 + old_perm = br->br_perm;
3332 + br->br_perm = new_perm;
3335 + bindex = au_br_index(sb, br->br_id);
3336 + if (0 <= bindex) {
3337 + hdir = au_hi(d_inode(sb->s_root), bindex);
3338 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3340 + h_dentry = au_br_dentry(br);
3341 + h_inode = d_inode(h_dentry);
3342 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3345 + err = au_wh_init(br, sb);
3347 + wbr_wh_write_lock(wbr);
3348 + err = au_wh_init(br, sb);
3349 + wbr_wh_write_unlock(wbr);
3352 + au_hn_inode_unlock(hdir);
3354 + inode_unlock(h_inode);
3355 + vfsub_mnt_drop_write(au_br_mnt(br));
3356 + br->br_perm = old_perm;
3358 + if (!err && wbr && !au_br_writable(new_perm)) {
3359 + au_kfree_rcu(wbr);
3360 + br->br_wbr = NULL;
3367 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3371 + struct kstatfs kst;
3372 + struct au_wbr *wbr;
3375 + au_rw_init(&wbr->wbr_wh_rwsem);
3376 + atomic_set(&wbr->wbr_wh_running, 0);
3379 + * a limit for rmdir/rename a dir
3380 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3382 + err = vfs_statfs(&br->br_path, &kst);
3383 + if (unlikely(err))
3386 + if (kst.f_namelen >= NAME_MAX)
3387 + err = au_br_init_wh(sb, br, perm);
3389 + pr_err("%pd(%s), unsupported namelen %ld\n",
3391 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3397 +/* initialize a new branch */
3398 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3399 + struct au_opt_add *add)
3402 + struct au_branch *brbase;
3404 + struct inode *h_inode;
3407 + br->br_perm = add->perm;
3408 + br->br_path = add->path; /* set first, path_get() later */
3409 + spin_lock_init(&br->br_dykey_lock);
3410 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3411 + au_lcnt_init(&br->br_count, /*release*/NULL);
3412 + br->br_id = au_new_br_id(sb);
3413 + AuDebugOn(br->br_id < 0);
3415 + /* always, regardless the given option */
3416 + err = au_dr_br_init(sb, br, &add->path);
3417 + if (unlikely(err))
3420 + if (au_br_writable(add->perm)) {
3421 + err = au_wbr_init(br, sb, add->perm);
3422 + if (unlikely(err))
3426 + if (au_opt_test(au_mntflags(sb), XINO)) {
3427 + brbase = au_sbr(sb, 0);
3428 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3430 + h_inode = d_inode(add->path.dentry);
3431 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3432 + if (unlikely(err)) {
3433 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3438 + sysaufs_br_init(br);
3439 + path_get(&br->br_path);
3440 + goto out; /* success */
3443 + memset(&br->br_path, 0, sizeof(br->br_path));
3448 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3449 + struct au_branch *br, aufs_bindex_t bbot,
3450 + aufs_bindex_t amount)
3452 + struct au_branch **brp;
3454 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3456 + brp = sbinfo->si_branch + bindex;
3457 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3459 + sbinfo->si_bbot++;
3460 + if (unlikely(bbot < 0))
3461 + sbinfo->si_bbot = 0;
3464 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3465 + aufs_bindex_t bbot, aufs_bindex_t amount)
3467 + struct au_hdentry *hdp;
3469 + AuRwMustWriteLock(&dinfo->di_rwsem);
3471 + hdp = au_hdentry(dinfo, bindex);
3472 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3473 + au_h_dentry_init(hdp);
3475 + if (unlikely(bbot < 0))
3476 + dinfo->di_btop = 0;
3479 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3480 + aufs_bindex_t bbot, aufs_bindex_t amount)
3482 + struct au_hinode *hip;
3484 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3486 + hip = au_hinode(iinfo, bindex);
3487 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3488 + au_hinode_init(hip);
3490 + if (unlikely(bbot < 0))
3491 + iinfo->ii_btop = 0;
3494 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3495 + aufs_bindex_t bindex)
3497 + struct dentry *root, *h_dentry;
3498 + struct inode *root_inode, *h_inode;
3499 + aufs_bindex_t bbot, amount;
3501 + root = sb->s_root;
3502 + root_inode = d_inode(root);
3503 + bbot = au_sbbot(sb);
3504 + amount = bbot + 1 - bindex;
3505 + h_dentry = au_br_dentry(br);
3506 + au_sbilist_lock();
3507 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3508 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3509 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3510 + au_set_h_dptr(root, bindex, dget(h_dentry));
3511 + h_inode = d_inode(h_dentry);
3512 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3513 + au_sbilist_unlock();
3516 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3519 + aufs_bindex_t bbot, add_bindex;
3520 + struct dentry *root, *h_dentry;
3521 + struct inode *root_inode;
3522 + struct au_branch *add_branch;
3524 + root = sb->s_root;
3525 + root_inode = d_inode(root);
3526 + IMustLock(root_inode);
3527 + IiMustWriteLock(root_inode);
3528 + err = test_add(sb, add, remount);
3529 + if (unlikely(err < 0))
3533 + goto out; /* success */
3536 + bbot = au_sbbot(sb);
3537 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3538 + err = PTR_ERR(add_branch);
3539 + if (IS_ERR(add_branch))
3542 + err = au_br_init(add_branch, sb, add);
3543 + if (unlikely(err)) {
3544 + au_br_do_free(add_branch);
3548 + add_bindex = add->bindex;
3549 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3550 + au_br_do_add(sb, add_branch, add_bindex);
3551 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3552 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3554 + h_dentry = add->path.dentry;
3555 + if (!add_bindex) {
3556 + au_cpup_attr_all(root_inode, /*force*/1);
3557 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3559 + au_add_nlink(root_inode, d_inode(h_dentry));
3565 +/* ---------------------------------------------------------------------- */
3567 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3568 + unsigned long long max __maybe_unused,
3571 + unsigned long long n;
3572 + struct file **p, *f;
3573 + struct hlist_bl_head *files;
3574 + struct hlist_bl_node *pos;
3575 + struct au_finfo *finfo;
3579 + files = &au_sbi(sb)->si_files;
3580 + hlist_bl_lock(files);
3581 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3582 + f = finfo->fi_file;
3584 + && !special_file(file_inode(f)->i_mode)) {
3588 + AuDebugOn(n > max);
3591 + hlist_bl_unlock(files);
3596 +static struct file **au_farray_alloc(struct super_block *sb,
3597 + unsigned long long *max)
3599 + struct au_sbinfo *sbi;
3602 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3603 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3606 +static void au_farray_free(struct file **a, unsigned long long max)
3608 + unsigned long long ull;
3610 + for (ull = 0; ull < max; ull++)
3616 +/* ---------------------------------------------------------------------- */
3622 +/* to show the line number, do not make it inlined function */
3623 +#define AuVerbose(do_info, fmt, ...) do { \
3625 + pr_info(fmt, ##__VA_ARGS__); \
3628 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3629 + aufs_bindex_t bbot)
3631 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3634 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3635 + aufs_bindex_t bbot)
3637 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3641 + * test if the branch is deletable or not.
3643 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3644 + unsigned int sigen, const unsigned int verbose)
3646 + int err, i, j, ndentry;
3647 + aufs_bindex_t btop, bbot;
3648 + struct au_dcsub_pages dpages;
3649 + struct au_dpage *dpage;
3652 + err = au_dpages_init(&dpages, GFP_NOFS);
3653 + if (unlikely(err))
3655 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3656 + if (unlikely(err))
3659 + for (i = 0; !err && i < dpages.ndpage; i++) {
3660 + dpage = dpages.dpages + i;
3661 + ndentry = dpage->ndentry;
3662 + for (j = 0; !err && j < ndentry; j++) {
3663 + d = dpage->dentries[j];
3664 + AuDebugOn(au_dcount(d) <= 0);
3665 + if (!au_digen_test(d, sigen)) {
3666 + di_read_lock_child(d, AuLock_IR);
3667 + if (unlikely(au_dbrange_test(d))) {
3668 + di_read_unlock(d, AuLock_IR);
3672 + di_write_lock_child(d);
3673 + if (unlikely(au_dbrange_test(d))) {
3674 + di_write_unlock(d);
3677 + err = au_reval_dpath(d, sigen);
3679 + di_downgrade_lock(d, AuLock_IR);
3681 + di_write_unlock(d);
3686 + /* AuDbgDentry(d); */
3687 + btop = au_dbtop(d);
3688 + bbot = au_dbbot(d);
3689 + if (btop <= bindex
3691 + && au_h_dptr(d, bindex)
3692 + && au_test_dbusy(d, btop, bbot)) {
3694 + AuVerbose(verbose, "busy %pd\n", d);
3697 + di_read_unlock(d, AuLock_IR);
3702 + au_dpages_free(&dpages);
3707 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3708 + unsigned int sigen, const unsigned int verbose)
3711 + unsigned long long max, ull;
3712 + struct inode *i, **array;
3713 + aufs_bindex_t btop, bbot;
3715 + array = au_iarray_alloc(sb, &max);
3716 + err = PTR_ERR(array);
3717 + if (IS_ERR(array))
3721 + AuDbg("b%d\n", bindex);
3722 + for (ull = 0; !err && ull < max; ull++) {
3726 + if (i->i_ino == AUFS_ROOT_INO)
3729 + /* AuDbgInode(i); */
3730 + if (au_iigen(i, NULL) == sigen)
3731 + ii_read_lock_child(i);
3733 + ii_write_lock_child(i);
3734 + err = au_refresh_hinode_self(i);
3737 + ii_downgrade_lock(i);
3739 + ii_write_unlock(i);
3744 + btop = au_ibtop(i);
3745 + bbot = au_ibbot(i);
3746 + if (btop <= bindex
3748 + && au_h_iptr(i, bindex)
3749 + && au_test_ibusy(i, btop, bbot)) {
3751 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3754 + ii_read_unlock(i);
3756 + au_iarray_free(array, max);
3762 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3763 + const unsigned int verbose)
3766 + unsigned int sigen;
3768 + sigen = au_sigen(root->d_sb);
3769 + DiMustNoWaiters(root);
3770 + IiMustNoWaiters(d_inode(root));
3771 + di_write_unlock(root);
3772 + err = test_dentry_busy(root, bindex, sigen, verbose);
3774 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3775 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3780 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3781 + struct file **to_free, int *idx)
3784 + unsigned char matched, root;
3785 + aufs_bindex_t bindex, bbot;
3786 + struct au_fidir *fidir;
3787 + struct au_hfile *hfile;
3790 + root = IS_ROOT(file->f_path.dentry);
3793 + to_free[*idx] = file;
3799 + fidir = au_fi(file)->fi_hdir;
3800 + AuDebugOn(!fidir);
3801 + bbot = au_fbbot_dir(file);
3802 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3803 + hfile = fidir->fd_hfile + bindex;
3804 + if (!hfile->hf_file)
3807 + if (hfile->hf_br->br_id == br_id) {
3819 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3820 + struct file **to_free, int opened)
3823 + unsigned long long ull, max;
3824 + aufs_bindex_t btop;
3825 + struct file *file, **array;
3826 + struct dentry *root;
3827 + struct au_hfile *hfile;
3829 + array = au_farray_alloc(sb, &max);
3830 + err = PTR_ERR(array);
3831 + if (IS_ERR(array))
3836 + root = sb->s_root;
3837 + di_write_unlock(root);
3838 + for (ull = 0; ull < max; ull++) {
3839 + file = array[ull];
3840 + if (unlikely(!file))
3843 + /* AuDbg("%pD\n", file); */
3844 + fi_read_lock(file);
3845 + btop = au_fbtop(file);
3846 + if (!d_is_dir(file->f_path.dentry)) {
3847 + hfile = &au_fi(file)->fi_htop;
3848 + if (hfile->hf_br->br_id == br_id)
3851 + err = test_dir_busy(file, br_id, to_free, &idx);
3852 + fi_read_unlock(file);
3853 + if (unlikely(err))
3856 + di_write_lock_child(root);
3857 + au_farray_free(array, max);
3858 + AuDebugOn(idx > opened);
3864 +static void br_del_file(struct file **to_free, unsigned long long opened,
3865 + aufs_bindex_t br_id)
3867 + unsigned long long ull;
3868 + aufs_bindex_t bindex, btop, bbot, bfound;
3869 + struct file *file;
3870 + struct au_fidir *fidir;
3871 + struct au_hfile *hfile;
3873 + for (ull = 0; ull < opened; ull++) {
3874 + file = to_free[ull];
3875 + if (unlikely(!file))
3878 + /* AuDbg("%pD\n", file); */
3879 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3881 + fidir = au_fi(file)->fi_hdir;
3882 + AuDebugOn(!fidir);
3883 + fi_write_lock(file);
3884 + btop = au_fbtop(file);
3885 + bbot = au_fbbot_dir(file);
3886 + for (bindex = btop; bindex <= bbot; bindex++) {
3887 + hfile = fidir->fd_hfile + bindex;
3888 + if (!hfile->hf_file)
3891 + if (hfile->hf_br->br_id == br_id) {
3896 + AuDebugOn(bfound < 0);
3897 + au_set_h_fptr(file, bfound, NULL);
3898 + if (bfound == btop) {
3899 + for (btop++; btop <= bbot; btop++)
3900 + if (au_hf_dir(file, btop)) {
3901 + au_set_fbtop(file, btop);
3905 + fi_write_unlock(file);
3909 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3910 + const aufs_bindex_t bindex,
3911 + const aufs_bindex_t bbot)
3913 + struct au_branch **brp, **p;
3915 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3917 + brp = sbinfo->si_branch + bindex;
3918 + if (bindex < bbot)
3919 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3920 + sbinfo->si_branch[0 + bbot] = NULL;
3921 + sbinfo->si_bbot--;
3923 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3926 + sbinfo->si_branch = p;
3927 + /* harmless error */
3930 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3931 + const aufs_bindex_t bbot)
3933 + struct au_hdentry *hdp, *p;
3935 + AuRwMustWriteLock(&dinfo->di_rwsem);
3937 + hdp = au_hdentry(dinfo, bindex);
3938 + if (bindex < bbot)
3939 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3940 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3943 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3946 + dinfo->di_hdentry = p;
3947 + /* harmless error */
3950 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3951 + const aufs_bindex_t bbot)
3953 + struct au_hinode *hip, *p;
3955 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3957 + hip = au_hinode(iinfo, bindex);
3958 + if (bindex < bbot)
3959 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3960 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3963 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3966 + iinfo->ii_hinode = p;
3967 + /* harmless error */
3970 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3971 + struct au_branch *br)
3973 + aufs_bindex_t bbot;
3974 + struct au_sbinfo *sbinfo;
3975 + struct dentry *root, *h_root;
3976 + struct inode *inode, *h_inode;
3977 + struct au_hinode *hinode;
3979 + SiMustWriteLock(sb);
3981 + root = sb->s_root;
3982 + inode = d_inode(root);
3983 + sbinfo = au_sbi(sb);
3984 + bbot = sbinfo->si_bbot;
3986 + h_root = au_h_dptr(root, bindex);
3987 + hinode = au_hi(inode, bindex);
3988 + h_inode = au_igrab(hinode->hi_inode);
3991 + au_sbilist_lock();
3992 + au_br_do_del_brp(sbinfo, bindex, bbot);
3993 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3994 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3995 + au_sbilist_unlock();
3997 + /* ignore an error */
3998 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
4002 + au_br_do_free(br);
4005 +static unsigned long long empty_cb(struct super_block *sb, void *array,
4006 + unsigned long long max, void *arg)
4011 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
4014 + unsigned long long opened;
4015 + unsigned int mnt_flags;
4016 + aufs_bindex_t bindex, bbot, br_id;
4017 + unsigned char do_wh, verbose;
4018 + struct au_branch *br;
4019 + struct au_wbr *wbr;
4020 + struct dentry *root;
4021 + struct file **to_free;
4026 + root = sb->s_root;
4027 + bindex = au_find_dbindex(root, del->h_path.dentry);
4030 + goto out; /* success */
4032 + pr_err("%s no such branch\n", del->pathname);
4035 + AuDbg("bindex b%d\n", bindex);
4038 + mnt_flags = au_mntflags(sb);
4039 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4040 + bbot = au_sbbot(sb);
4041 + if (unlikely(!bbot)) {
4042 + AuVerbose(verbose, "no more branches left\n");
4046 + br = au_sbr(sb, bindex);
4047 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
4048 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
4049 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
4053 + br_id = br->br_id;
4054 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
4055 + if (unlikely(opened)) {
4056 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
4057 + err = PTR_ERR(to_free);
4058 + if (IS_ERR(to_free))
4061 + err = test_file_busy(sb, br_id, to_free, opened);
4062 + if (unlikely(err)) {
4063 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
4069 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4071 + /* instead of WbrWhMustWriteLock(wbr) */
4072 + SiMustWriteLock(sb);
4073 + for (i = 0; i < AuBrWh_Last; i++) {
4074 + dput(wbr->wbr_wh[i]);
4075 + wbr->wbr_wh[i] = NULL;
4079 + err = test_children_busy(root, bindex, verbose);
4080 + if (unlikely(err)) {
4089 + * now we confirmed the branch is deletable.
4090 + * let's free the remaining opened dirs on the branch.
4092 + di_write_unlock(root);
4093 + br_del_file(to_free, opened, br_id);
4094 + di_write_lock_child(root);
4097 + sysaufs_brs_del(sb, bindex); /* remove successors */
4098 + dbgaufs_xino_del(br); /* remove one */
4099 + au_br_do_del(sb, bindex, br);
4100 + sysaufs_brs_add(sb, bindex); /* append successors */
4101 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4104 + au_cpup_attr_all(d_inode(root), /*force*/1);
4105 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4107 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4108 + if (au_opt_test(mnt_flags, PLINK))
4109 + au_plink_half_refresh(sb, br_id);
4111 + goto out; /* success */
4115 + rerr = au_br_init_wh(sb, br, br->br_perm);
4117 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4118 + del->pathname, rerr);
4121 + au_farray_free(to_free, opened);
4125 +/* ---------------------------------------------------------------------- */
4127 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4130 + aufs_bindex_t btop, bbot;
4131 + struct aufs_ibusy ibusy;
4132 + struct inode *inode, *h_inode;
4135 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4138 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4140 + /* VERIFY_WRITE */
4141 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4142 + if (unlikely(err)) {
4149 + si_read_lock(sb, AuLock_FLUSH);
4150 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4154 + ibusy.h_ino = 0; /* invalid */
4155 + inode = ilookup(sb, ibusy.ino);
4157 + || inode->i_ino == AUFS_ROOT_INO
4158 + || au_is_bad_inode(inode))
4161 + ii_read_lock_child(inode);
4162 + btop = au_ibtop(inode);
4163 + bbot = au_ibbot(inode);
4164 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4165 + h_inode = au_h_iptr(inode, ibusy.bindex);
4166 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4167 + ibusy.h_ino = h_inode->i_ino;
4169 + ii_read_unlock(inode);
4173 + si_read_unlock(sb);
4175 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4176 + if (unlikely(err)) {
4185 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4187 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4190 +#ifdef CONFIG_COMPAT
4191 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4193 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4197 +/* ---------------------------------------------------------------------- */
4200 + * change a branch permission
4203 +static void au_warn_ima(void)
4206 + /* since it doesn't support mark_files_ro() */
4207 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4211 +static int do_need_sigen_inc(int a, int b)
4213 + return au_br_whable(a) && !au_br_whable(b);
4216 +static int need_sigen_inc(int old, int new)
4218 + return do_need_sigen_inc(old, new)
4219 + || do_need_sigen_inc(new, old);
4222 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4225 + unsigned int mnt_flags;
4226 + unsigned long long ull, max;
4227 + aufs_bindex_t br_id;
4228 + unsigned char verbose, writer;
4229 + struct file *file, *hf, **array;
4230 + struct au_hfile *hfile;
4231 + struct inode *h_inode;
4233 + mnt_flags = au_mntflags(sb);
4234 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4236 + array = au_farray_alloc(sb, &max);
4237 + err = PTR_ERR(array);
4238 + if (IS_ERR(array))
4242 + br_id = au_sbr_id(sb, bindex);
4243 + for (ull = 0; ull < max; ull++) {
4244 + file = array[ull];
4245 + if (unlikely(!file))
4248 + /* AuDbg("%pD\n", file); */
4249 + fi_read_lock(file);
4250 + if (unlikely(au_test_mmapped(file))) {
4252 + AuVerbose(verbose, "mmapped %pD\n", file);
4254 + FiMustNoWaiters(file);
4255 + fi_read_unlock(file);
4259 + hfile = &au_fi(file)->fi_htop;
4260 + hf = hfile->hf_file;
4261 + if (!d_is_reg(file->f_path.dentry)
4262 + || !(file->f_mode & FMODE_WRITE)
4263 + || hfile->hf_br->br_id != br_id
4264 + || !(hf->f_mode & FMODE_WRITE))
4265 + array[ull] = NULL;
4271 + FiMustNoWaiters(file);
4272 + fi_read_unlock(file);
4280 + for (ull = 0; ull < max; ull++) {
4281 + file = array[ull];
4285 + /* todo: already flushed? */
4287 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4288 + * approach which resets f_mode and calls mnt_drop_write() and
4289 + * file_release_write() for each file, because the branch
4290 + * attribute in aufs world is totally different from the native
4293 + /* fi_read_lock(file); */
4294 + hfile = &au_fi(file)->fi_htop;
4295 + hf = hfile->hf_file;
4296 + /* fi_read_unlock(file); */
4297 + spin_lock(&hf->f_lock);
4298 + writer = !!(hf->f_mode & FMODE_WRITER);
4299 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4300 + spin_unlock(&hf->f_lock);
4302 + h_inode = file_inode(hf);
4303 + if (hf->f_mode & FMODE_READ)
4304 + i_readcount_inc(h_inode);
4305 + put_write_access(h_inode);
4306 + __mnt_drop_write(hf->f_path.mnt);
4311 + au_farray_free(array, max);
4317 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4321 + aufs_bindex_t bindex;
4322 + struct dentry *root;
4323 + struct au_branch *br;
4324 + struct au_br_fhsm *bf;
4326 + root = sb->s_root;
4327 + bindex = au_find_dbindex(root, mod->h_root);
4330 + return 0; /* success */
4332 + pr_err("%s no such branch\n", mod->path);
4335 + AuDbg("bindex b%d\n", bindex);
4337 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4338 + if (unlikely(err))
4341 + br = au_sbr(sb, bindex);
4342 + AuDebugOn(mod->h_root != au_br_dentry(br));
4343 + if (br->br_perm == mod->perm)
4344 + return 0; /* success */
4346 + /* pre-allocate for non-fhsm --> fhsm */
4348 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4349 + err = au_fhsm_br_alloc(br);
4350 + if (unlikely(err))
4353 + br->br_fhsm = NULL;
4356 + if (au_br_writable(br->br_perm)) {
4357 + /* remove whiteout base */
4358 + err = au_br_init_wh(sb, br, mod->perm);
4359 + if (unlikely(err))
4362 + if (!au_br_writable(mod->perm)) {
4363 + /* rw --> ro, file might be mmapped */
4364 + DiMustNoWaiters(root);
4365 + IiMustNoWaiters(d_inode(root));
4366 + di_write_unlock(root);
4367 + err = au_br_mod_files_ro(sb, bindex);
4368 + /* aufs_write_lock() calls ..._child() */
4369 + di_write_lock_child(root);
4371 + if (unlikely(err)) {
4373 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4376 + rerr = au_wbr_init(br, sb, br->br_perm);
4377 + if (unlikely(rerr)) {
4378 + AuIOErr("nested error %d (%d)\n",
4380 + br->br_perm = mod->perm;
4384 + } else if (au_br_writable(mod->perm)) {
4387 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4389 + err = au_wbr_init(br, sb, mod->perm);
4390 + if (unlikely(err)) {
4391 + au_kfree_rcu(br->br_wbr);
4392 + br->br_wbr = NULL;
4396 + if (unlikely(err))
4399 + if (au_br_fhsm(br->br_perm)) {
4400 + if (!au_br_fhsm(mod->perm)) {
4401 + /* fhsm --> non-fhsm */
4402 + au_br_fhsm_fin(br->br_fhsm);
4403 + au_kfree_rcu(br->br_fhsm);
4404 + br->br_fhsm = NULL;
4406 + } else if (au_br_fhsm(mod->perm))
4407 + /* non-fhsm --> fhsm */
4410 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4411 + br->br_perm = mod->perm;
4412 + goto out; /* success */
4415 + au_kfree_try_rcu(bf);
4421 +/* ---------------------------------------------------------------------- */
4423 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4426 + struct kstatfs kstfs;
4428 + err = vfs_statfs(&br->br_path, &kstfs);
4430 + stfs->f_blocks = kstfs.f_blocks;
4431 + stfs->f_bavail = kstfs.f_bavail;
4432 + stfs->f_files = kstfs.f_files;
4433 + stfs->f_ffree = kstfs.f_ffree;
4438 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4439 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4440 +++ linux/fs/aufs/branch.h 2020-01-27 10:57:18.165538015 +0100
4442 +/* SPDX-License-Identifier: GPL-2.0 */
4444 + * Copyright (C) 2005-2020 Junjiro R. Okajima
4446 + * This program, aufs is free software; you can redistribute it and/or modify
4447 + * it under the terms of the GNU General Public License as published by
4448 + * the Free Software Foundation; either version 2 of the License, or
4449 + * (at your option) any later version.
4451 + * This program is distributed in the hope that it will be useful,
4452 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4453 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4454 + * GNU General Public License for more details.
4456 + * You should have received a copy of the GNU General Public License
4457 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4461 + * branch filesystems and xino for them
4464 +#ifndef __AUFS_BRANCH_H__
4465 +#define __AUFS_BRANCH_H__
4469 +#include <linux/mount.h>
4470 +#include "dirren.h"
4476 +/* ---------------------------------------------------------------------- */
4480 + struct file **xi_file;
4481 + unsigned int xi_nfile;
4487 + /* reserved for future use */
4488 + /* unsigned long *bitmap; */
4489 + wait_queue_head_t wqh;
4492 + struct mutex xi_mtx; /* protects xi_file array */
4493 + struct hlist_bl_head xi_writing;
4495 + atomic_t xi_truncating;
4497 + struct kref xi_kref;
4500 +/* File-based Hierarchical Storage Management */
4501 +struct au_br_fhsm {
4502 +#ifdef CONFIG_AUFS_FHSM
4503 + struct mutex bf_lock;
4504 + unsigned long bf_jiffy;
4505 + struct aufs_stfs bf_stfs;
4510 +/* members for writable branch only */
4511 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4513 + struct au_rwsem wbr_wh_rwsem;
4514 + struct dentry *wbr_wh[AuBrWh_Last];
4515 + atomic_t wbr_wh_running;
4516 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4517 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4518 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4521 + unsigned long long wbr_bytes;
4524 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4525 +#define AuBrDynOp (AuDyLast * 4)
4527 +#ifdef CONFIG_AUFS_HFSNOTIFY
4528 +/* support for asynchronous destruction */
4529 +struct au_br_hfsnotify {
4530 + struct fsnotify_group *hfsn_group;
4534 +/* sysfs entries */
4535 +struct au_brsysfs {
4537 + struct attribute attr;
4546 +/* protected by superblock rwsem */
4548 + struct au_xino *br_xino;
4550 + aufs_bindex_t br_id;
4553 + struct path br_path;
4554 + spinlock_t br_dykey_lock;
4555 + struct au_dykey *br_dykey[AuBrDynOp];
4556 + au_lcnt_t br_nfiles; /* opened files */
4557 + au_lcnt_t br_count; /* in-use for other */
4559 + struct au_wbr *br_wbr;
4560 + struct au_br_fhsm *br_fhsm;
4562 +#ifdef CONFIG_AUFS_HFSNOTIFY
4563 + struct au_br_hfsnotify *br_hfsn;
4566 +#ifdef CONFIG_SYSFS
4567 + /* entries under sysfs per mount-point */
4568 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4571 +#ifdef CONFIG_DEBUG_FS
4572 + struct dentry *br_dbgaufs; /* xino */
4575 + struct au_dr_br br_dirren;
4578 +/* ---------------------------------------------------------------------- */
4580 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4582 + return br->br_path.mnt;
4585 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4587 + return br->br_path.dentry;
4590 +static inline struct super_block *au_br_sb(struct au_branch *br)
4592 + return au_br_mnt(br)->mnt_sb;
4595 +static inline int au_br_rdonly(struct au_branch *br)
4597 + return (sb_rdonly(au_br_sb(br))
4598 + || !au_br_writable(br->br_perm))
4602 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4604 +#ifdef CONFIG_AUFS_HNOTIFY
4605 + return !(brperm & AuBrPerm_RR);
4611 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4613 + int err, exec_flag;
4616 + exec_flag = oflag & __FMODE_EXEC;
4617 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4623 +static inline void au_xino_get(struct au_branch *br)
4625 + struct au_xino *xi;
4629 + kref_get(&xi->xi_kref);
4632 +static inline int au_xino_count(struct au_branch *br)
4635 + struct au_xino *xi;
4640 + v = kref_read(&xi->xi_kref);
4645 +/* ---------------------------------------------------------------------- */
4649 +void au_br_free(struct au_sbinfo *sinfo);
4650 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4652 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4654 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4655 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4656 +#ifdef CONFIG_COMPAT
4657 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4660 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4663 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4666 +static const loff_t au_loff_max = LLONG_MAX;
4668 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4669 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4671 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4672 + struct file *copy_src);
4674 + struct au_xino *xi; /* switch between xino and xigen */
4676 + struct path *base;
4677 + struct file *copy_src;
4679 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4681 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4683 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4685 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4687 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4688 + size_t size, loff_t *pos);
4690 +int au_xib_trunc(struct super_block *sb);
4691 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4693 +struct au_xino *au_xino_alloc(unsigned int nfile);
4694 +int au_xino_put(struct au_branch *br);
4695 +struct file *au_xino_file1(struct au_xino *xi);
4697 +struct au_opt_xino;
4698 +void au_xino_clr(struct super_block *sb);
4699 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4700 +struct file *au_xino_def(struct super_block *sb);
4701 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4702 + struct path *base);
4704 +ino_t au_xino_new_ino(struct super_block *sb);
4705 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4707 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4708 + ino_t h_ino, int idx);
4709 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4712 +int au_xino_path(struct seq_file *seq, struct file *file);
4714 +/* ---------------------------------------------------------------------- */
4716 +/* @idx is signed to accept -1 meaning the first file */
4717 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4719 + struct file *file;
4726 + if (idx < xi->xi_nfile)
4727 + file = xi->xi_file[idx];
4729 + file = au_xino_file1(xi);
4735 +/* ---------------------------------------------------------------------- */
4737 +/* Superblock to branch */
4739 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4741 + return au_sbr(sb, bindex)->br_id;
4745 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4747 + return au_br_mnt(au_sbr(sb, bindex));
4751 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4753 + return au_br_sb(au_sbr(sb, bindex));
4756 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4758 + return au_sbr(sb, bindex)->br_perm;
4761 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4763 + return au_br_whable(au_sbr_perm(sb, bindex));
4766 +/* ---------------------------------------------------------------------- */
4768 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4769 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4770 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4771 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4773 +#define wbr_wh_read_trylock_nested(wbr) \
4774 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4775 +#define wbr_wh_write_trylock_nested(wbr) \
4776 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4779 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4780 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4781 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4783 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4784 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4785 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4787 +/* ---------------------------------------------------------------------- */
4789 +#ifdef CONFIG_AUFS_FHSM
4790 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4792 + mutex_init(&brfhsm->bf_lock);
4793 + brfhsm->bf_jiffy = 0;
4794 + brfhsm->bf_readable = 0;
4797 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4799 + mutex_destroy(&brfhsm->bf_lock);
4802 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4803 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4806 +#endif /* __KERNEL__ */
4807 +#endif /* __AUFS_BRANCH_H__ */
4808 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4809 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4810 +++ linux/fs/aufs/conf.mk 2019-07-11 15:42:14.462237786 +0200
4812 +# SPDX-License-Identifier: GPL-2.0
4814 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4818 +AuConfStr += ${1}=${${1}}
4822 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4824 + HNOTIFY HFSNOTIFY \
4836 +$(foreach i, ${AuConfAll}, \
4837 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4839 +AuConfName = ${obj}/conf.str
4840 +${AuConfName}.tmp: FORCE
4841 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4842 +${AuConfName}: ${AuConfName}.tmp
4843 + @diff -q $< $@ > /dev/null 2>&1 || { \
4844 + echo ' GEN ' $@; \
4848 +clean-files += ${AuConfName} ${AuConfName}.tmp
4849 +${obj}/sysfs.o: ${AuConfName}
4851 +-include ${srctree}/${src}/conf_priv.mk
4852 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4853 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4854 +++ linux/fs/aufs/cpup.c 2020-01-27 10:57:18.165538015 +0100
4856 +// SPDX-License-Identifier: GPL-2.0
4858 + * Copyright (C) 2005-2020 Junjiro R. Okajima
4860 + * This program, aufs is free software; you can redistribute it and/or modify
4861 + * it under the terms of the GNU General Public License as published by
4862 + * the Free Software Foundation; either version 2 of the License, or
4863 + * (at your option) any later version.
4865 + * This program is distributed in the hope that it will be useful,
4866 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4867 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4868 + * GNU General Public License for more details.
4870 + * You should have received a copy of the GNU General Public License
4871 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4875 + * copy-up functions, see wbr_policy.c for copy-down
4878 +#include <linux/fs_stack.h>
4879 +#include <linux/mm.h>
4880 +#include <linux/task_work.h>
4883 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4885 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4886 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4888 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4890 + dst->i_flags |= iflags & ~mask;
4891 + if (au_test_fs_notime(dst->i_sb))
4892 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4895 +void au_cpup_attr_timesizes(struct inode *inode)
4897 + struct inode *h_inode;
4899 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4900 + fsstack_copy_attr_times(inode, h_inode);
4901 + fsstack_copy_inode_size(inode, h_inode);
4904 +void au_cpup_attr_nlink(struct inode *inode, int force)
4906 + struct inode *h_inode;
4907 + struct super_block *sb;
4908 + aufs_bindex_t bindex, bbot;
4911 + bindex = au_ibtop(inode);
4912 + h_inode = au_h_iptr(inode, bindex);
4914 + && !S_ISDIR(h_inode->i_mode)
4915 + && au_opt_test(au_mntflags(sb), PLINK)
4916 + && au_plink_test(inode))
4920 + * 0 can happen in revalidating.
4921 + * h_inode->i_mutex may not be held here, but it is harmless since once
4922 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4924 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4925 + * the incorrect link count.
4927 + set_nlink(inode, h_inode->i_nlink);
4930 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4931 + * it may includes whplink directory.
4933 + if (S_ISDIR(h_inode->i_mode)) {
4934 + bbot = au_ibbot(inode);
4935 + for (bindex++; bindex <= bbot; bindex++) {
4936 + h_inode = au_h_iptr(inode, bindex);
4938 + au_add_nlink(inode, h_inode);
4943 +void au_cpup_attr_changeable(struct inode *inode)
4945 + struct inode *h_inode;
4947 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4948 + inode->i_mode = h_inode->i_mode;
4949 + inode->i_uid = h_inode->i_uid;
4950 + inode->i_gid = h_inode->i_gid;
4951 + au_cpup_attr_timesizes(inode);
4952 + au_cpup_attr_flags(inode, h_inode->i_flags);
4955 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4957 + struct au_iinfo *iinfo = au_ii(inode);
4959 + IiMustWriteLock(inode);
4961 + iinfo->ii_higen = h_inode->i_generation;
4962 + iinfo->ii_hsb1 = h_inode->i_sb;
4965 +void au_cpup_attr_all(struct inode *inode, int force)
4967 + struct inode *h_inode;
4969 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4970 + au_cpup_attr_changeable(inode);
4971 + if (inode->i_nlink > 0)
4972 + au_cpup_attr_nlink(inode, force);
4973 + inode->i_rdev = h_inode->i_rdev;
4974 + inode->i_blkbits = h_inode->i_blkbits;
4975 + au_cpup_igen(inode, h_inode);
4978 +/* ---------------------------------------------------------------------- */
4980 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4982 +/* keep the timestamps of the parent dir when cpup */
4983 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4984 + struct path *h_path)
4986 + struct inode *h_inode;
4988 + dt->dt_dentry = dentry;
4989 + dt->dt_h_path = *h_path;
4990 + h_inode = d_inode(h_path->dentry);
4991 + dt->dt_atime = h_inode->i_atime;
4992 + dt->dt_mtime = h_inode->i_mtime;
4996 +void au_dtime_revert(struct au_dtime *dt)
4998 + struct iattr attr;
5001 + attr.ia_atime = dt->dt_atime;
5002 + attr.ia_mtime = dt->dt_mtime;
5003 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
5004 + | ATTR_ATIME | ATTR_ATIME_SET;
5006 + /* no delegation since this is a directory */
5007 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
5008 + if (unlikely(err))
5009 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
5012 +/* ---------------------------------------------------------------------- */
5014 +/* internal use only */
5015 +struct au_cpup_reg_attr {
5018 + unsigned int iflags; /* inode->i_flags */
5021 +static noinline_for_stack
5022 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
5023 + struct au_cpup_reg_attr *h_src_attr)
5025 + int err, sbits, icex;
5026 + unsigned int mnt_flags;
5027 + unsigned char verbose;
5029 + struct path h_path;
5030 + struct inode *h_isrc, *h_idst;
5031 + struct kstat *h_st;
5032 + struct au_branch *br;
5034 + h_path.dentry = au_h_dptr(dst, bindex);
5035 + h_idst = d_inode(h_path.dentry);
5036 + br = au_sbr(dst->d_sb, bindex);
5037 + h_path.mnt = au_br_mnt(br);
5038 + h_isrc = d_inode(h_src);
5039 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
5040 + | ATTR_ATIME | ATTR_MTIME
5041 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
5042 + if (h_src_attr && h_src_attr->valid) {
5043 + h_st = &h_src_attr->st;
5044 + ia.ia_uid = h_st->uid;
5045 + ia.ia_gid = h_st->gid;
5046 + ia.ia_atime = h_st->atime;
5047 + ia.ia_mtime = h_st->mtime;
5048 + if (h_idst->i_mode != h_st->mode
5049 + && !S_ISLNK(h_idst->i_mode)) {
5050 + ia.ia_valid |= ATTR_MODE;
5051 + ia.ia_mode = h_st->mode;
5053 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
5054 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
5056 + ia.ia_uid = h_isrc->i_uid;
5057 + ia.ia_gid = h_isrc->i_gid;
5058 + ia.ia_atime = h_isrc->i_atime;
5059 + ia.ia_mtime = h_isrc->i_mtime;
5060 + if (h_idst->i_mode != h_isrc->i_mode
5061 + && !S_ISLNK(h_idst->i_mode)) {
5062 + ia.ia_valid |= ATTR_MODE;
5063 + ia.ia_mode = h_isrc->i_mode;
5065 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5066 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5068 + /* no delegation since it is just created */
5069 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5071 + /* is this nfs only? */
5072 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5073 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5074 + ia.ia_mode = h_isrc->i_mode;
5075 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5078 + icex = br->br_perm & AuBrAttr_ICEX;
5080 + mnt_flags = au_mntflags(dst->d_sb);
5081 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5082 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5088 +/* ---------------------------------------------------------------------- */
5090 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5091 + char *buf, unsigned long blksize)
5094 + size_t sz, rbytes, wbytes;
5095 + unsigned char all_zero;
5097 + struct inode *h_inode;
5098 + /* reduce stack usage */
5101 + zp = page_address(ZERO_PAGE(0));
5102 + if (unlikely(!zp))
5103 + return -ENOMEM; /* possible? */
5108 + AuDbg("len %lld\n", len);
5110 + if (len < blksize)
5114 + /* todo: signal_pending? */
5115 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5116 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5119 + if (unlikely(err < 0))
5123 + if (len >= rbytes && rbytes == blksize)
5124 + all_zero = !memcmp(buf, zp, rbytes);
5131 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5133 + /* todo: signal_pending? */
5134 + if (unlikely(err == -EAGAIN || err == -EINTR))
5136 + if (unlikely(err < 0))
5141 + if (unlikely(err < 0))
5147 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5149 + if (unlikely(res < 0))
5156 + /* the last block may be a hole */
5157 + if (!err && all_zero) {
5158 + AuLabel(last hole);
5161 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5162 + /* nfs requires this step to make last hole */
5163 + /* is this only nfs? */
5165 + /* todo: signal_pending? */
5166 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5167 + } while (err == -EAGAIN || err == -EINTR);
5174 + ia->ia_size = dst->f_pos;
5175 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5176 + ia->ia_file = dst;
5177 + h_inode = file_inode(dst);
5178 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5179 + /* no delegation since it is just created */
5180 + err = vfsub_notify_change(&dst->f_path, ia,
5181 + /*delegated*/NULL);
5182 + inode_unlock(h_inode);
5189 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5192 + unsigned long blksize;
5193 + unsigned char do_kfree;
5195 + struct super_block *h_sb;
5198 + h_sb = file_inode(dst)->i_sb;
5199 + blksize = h_sb->s_blocksize;
5200 + if (!blksize || PAGE_SIZE < blksize)
5201 + blksize = PAGE_SIZE;
5202 + AuDbg("blksize %lu\n", blksize);
5203 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5205 + buf = kmalloc(blksize, GFP_NOFS);
5207 + buf = (void *)__get_free_page(GFP_NOFS);
5208 + if (unlikely(!buf))
5211 + if (len > (1 << 22))
5212 + AuDbg("copying a large file %lld\n", (long long)len);
5216 + err = au_do_copy_file(dst, src, len, buf, blksize);
5218 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5219 + au_kfree_do_rcu(buf);
5221 + free_page((unsigned long)buf);
5227 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5230 + struct super_block *h_src_sb;
5231 + struct inode *h_src_inode;
5233 + h_src_inode = file_inode(src);
5234 + h_src_sb = h_src_inode->i_sb;
5236 + /* XFS acquires inode_lock */
5237 + if (!au_test_xfs(h_src_sb))
5238 + err = au_copy_file(dst, src, len);
5240 + inode_unlock_shared(h_src_inode);
5241 + err = au_copy_file(dst, src, len);
5242 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5248 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5252 + struct super_block *h_src_sb;
5253 + struct inode *h_src_inode;
5255 + h_src_inode = file_inode(src);
5256 + h_src_sb = h_src_inode->i_sb;
5257 + if (h_src_sb != file_inode(dst)->i_sb
5258 + || !dst->f_op->remap_file_range) {
5259 + err = au_do_copy(dst, src, len);
5263 + if (!au_test_nfs(h_src_sb)) {
5264 + inode_unlock_shared(h_src_inode);
5265 + lo = vfsub_clone_file_range(src, dst, len);
5266 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5268 + lo = vfsub_clone_file_range(src, dst, len);
5271 + goto out; /* success */
5272 + } else if (lo >= 0)
5273 + /* todo: possible? */
5274 + /* paritially succeeded */
5275 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5276 + else if (lo != -EOPNOTSUPP) {
5277 + /* older XFS has a condition in cloning */
5282 + /* the backend fs on NFS may not support cloning */
5283 + err = au_do_copy(dst, src, len);
5291 + * to support a sparse file which is opened with O_APPEND,
5292 + * we need to close the file.
5294 +static int au_cp_regular(struct au_cp_generic *cpg)
5297 + enum { SRC, DST };
5299 + aufs_bindex_t bindex;
5300 + unsigned int flags;
5301 + struct dentry *dentry;
5303 + struct file *file;
5306 + .bindex = cpg->bsrc,
5307 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5310 + .bindex = cpg->bdst,
5311 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5312 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5315 + struct au_branch *br;
5316 + struct super_block *sb, *h_src_sb;
5317 + struct inode *h_src_inode;
5318 + struct task_struct *tsk = current;
5320 + /* bsrc branch can be ro/rw. */
5321 + sb = cpg->dentry->d_sb;
5323 + for (i = 0; i < 2; i++, f++) {
5324 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5325 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5326 + /*file*/NULL, f->force_wr);
5327 + if (IS_ERR(f->file)) {
5328 + err = PTR_ERR(f->file);
5336 + /* try stopping to update while we copyup */
5337 + h_src_inode = d_inode(file[SRC].dentry);
5338 + h_src_sb = h_src_inode->i_sb;
5339 + if (!au_test_nfs(h_src_sb))
5340 + IMustLock(h_src_inode);
5341 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5343 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5344 + if (tsk->flags & PF_KTHREAD)
5345 + __fput_sync(file[DST].file);
5347 + /* it happened actually */
5348 + fput(file[DST].file);
5351 + * we have to call both since we don't know which place the file
5355 + flush_delayed_fput();
5357 + br = au_sbr(sb, file[DST].bindex);
5358 + au_lcnt_dec(&br->br_nfiles);
5361 + fput(file[SRC].file);
5362 + br = au_sbr(sb, file[SRC].bindex);
5363 + au_lcnt_dec(&br->br_nfiles);
5368 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5369 + struct au_cpup_reg_attr *h_src_attr)
5373 + struct path h_path;
5374 + struct inode *h_src_inode, *h_dst_inode;
5377 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5378 + l = i_size_read(h_src_inode);
5379 + if (cpg->len == -1 || l < cpg->len)
5382 + /* try stopping to update while we are referencing */
5383 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5384 + au_pin_hdir_unlock(cpg->pin);
5386 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5387 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5388 + h_src_attr->iflags = h_src_inode->i_flags;
5389 + if (!au_test_nfs(h_src_inode->i_sb))
5390 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5392 + inode_unlock_shared(h_src_inode);
5393 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5394 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5396 + if (unlikely(err)) {
5397 + inode_unlock_shared(h_src_inode);
5400 + h_src_attr->valid = 1;
5401 + if (!au_test_nfs(h_src_inode->i_sb)) {
5402 + err = au_cp_regular(cpg);
5403 + inode_unlock_shared(h_src_inode);
5405 + inode_unlock_shared(h_src_inode);
5406 + err = au_cp_regular(cpg);
5408 + rerr = au_pin_hdir_relock(cpg->pin);
5412 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5413 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5414 + h_dst_inode = d_inode(h_path.dentry);
5415 + spin_lock(&h_dst_inode->i_lock);
5416 + h_dst_inode->i_state |= I_LINKABLE;
5417 + spin_unlock(&h_dst_inode->i_lock);
5424 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5425 + struct inode *h_dir)
5428 + mm_segment_t old_fs;
5435 + sym.k = (void *)__get_free_page(GFP_NOFS);
5436 + if (unlikely(!sym.k))
5439 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5440 + old_fs = get_fs();
5441 + set_fs(KERNEL_DS);
5442 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5447 + sym.k[symlen] = 0;
5448 + err = vfsub_symlink(h_dir, h_path, sym.k);
5450 + free_page((unsigned long)sym.k);
5457 + * regardless 'acl' option, reset all ACL.
5458 + * All ACL will be copied up later from the original entry on the lower branch.
5460 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5463 + struct dentry *h_dentry;
5464 + struct inode *h_inode;
5466 + h_dentry = h_path->dentry;
5467 + h_inode = d_inode(h_dentry);
5468 + /* forget_all_cached_acls(h_inode)); */
5469 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5471 + if (err == -EOPNOTSUPP)
5474 + err = vfsub_acl_chmod(h_inode, mode);
5480 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5481 + struct inode *h_dir, struct path *h_path)
5484 + struct inode *dir, *inode;
5486 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5488 + if (err == -EOPNOTSUPP)
5490 + if (unlikely(err))
5494 + * strange behaviour from the users view,
5495 + * particularly setattr case
5497 + dir = d_inode(dst_parent);
5498 + if (au_ibtop(dir) == cpg->bdst)
5499 + au_cpup_attr_nlink(dir, /*force*/1);
5500 + inode = d_inode(cpg->dentry);
5501 + au_cpup_attr_nlink(inode, /*force*/1);
5507 +static noinline_for_stack
5508 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5509 + struct au_cpup_reg_attr *h_src_attr)
5513 + unsigned int mnt_flags;
5514 + unsigned char isdir, isreg, force;
5515 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5516 + struct au_dtime dt;
5517 + struct path h_path;
5518 + struct dentry *h_src, *h_dst, *h_parent;
5519 + struct inode *h_inode, *h_dir;
5520 + struct super_block *sb;
5522 + /* bsrc branch can be ro/rw. */
5523 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5524 + h_inode = d_inode(h_src);
5525 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5527 + /* try stopping to be referenced while we are creating */
5528 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5529 + if (au_ftest_cpup(cpg->flags, RENAME))
5530 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5531 + AUFS_WH_PFX_LEN));
5532 + h_parent = h_dst->d_parent; /* dir inode is locked */
5533 + h_dir = d_inode(h_parent);
5535 + AuDebugOn(h_parent != h_dst->d_parent);
5537 + sb = cpg->dentry->d_sb;
5538 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5540 + h_path.dentry = h_parent;
5541 + au_dtime_store(&dt, dst_parent, &h_path);
5543 + h_path.dentry = h_dst;
5547 + mode = h_inode->i_mode;
5548 + switch (mode & S_IFMT) {
5551 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5553 + err = au_do_cpup_regular(cpg, h_src_attr);
5557 + err = vfsub_mkdir(h_dir, &h_path, mode);
5559 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5562 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5566 + AuDebugOn(!capable(CAP_MKNOD));
5570 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5573 + AuIOErr("Unknown inode type 0%o\n", mode);
5577 + err = au_reset_acl(h_dir, &h_path, mode);
5579 + mnt_flags = au_mntflags(sb);
5580 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5582 + && au_opt_test(mnt_flags, XINO)
5583 + && (h_inode->i_nlink == 1
5584 + || (h_inode->i_state & I_LINKABLE))
5585 + /* todo: unnecessary? */
5586 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5587 + && cpg->bdst < cpg->bsrc
5588 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5589 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5590 + /* ignore this error */
5595 + force = !!cpg->len;
5596 + if (cpg->len == -1)
5597 + force = !!i_size_read(h_inode);
5599 + au_fhsm_wrote(sb, cpg->bdst, force);
5603 + au_dtime_revert(&dt);
5607 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5610 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5611 + struct inode *h_dir;
5612 + aufs_bindex_t bdst;
5614 + dentry = cpg->dentry;
5616 + h_dentry = au_h_dptr(dentry, bdst);
5617 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5619 + au_set_h_dptr(dentry, bdst, NULL);
5620 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5622 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5623 + au_set_h_dptr(dentry, bdst, h_dentry);
5626 + parent = dget_parent(dentry);
5627 + h_parent = au_h_dptr(parent, bdst);
5629 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5630 + if (IS_ERR(h_path->dentry))
5631 + err = PTR_ERR(h_path->dentry);
5633 + if (unlikely(err))
5636 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5637 + h_dir = d_inode(h_parent);
5639 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5640 + /* no delegation since it is just created */
5641 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5643 + dput(h_path->dentry);
5650 + * copyup the @dentry from @bsrc to @bdst.
5651 + * the caller must set the both of lower dentries.
5652 + * @len is for truncating when it is -1 copyup the entire file.
5653 + * in link/rename cases, @dst_parent may be different from the real one.
5654 + * basic->bsrc can be larger than basic->bdst.
5655 + * aufs doesn't touch the credential so
5656 + * security_inode_copy_up{,_xattr}() are unnecessary.
5658 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5661 + aufs_bindex_t old_ibtop;
5662 + unsigned char isdir, plink;
5663 + struct dentry *h_src, *h_dst, *h_parent;
5664 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5665 + struct super_block *sb;
5666 + struct au_branch *br;
5667 + /* to reduce stack size */
5669 + struct au_dtime dt;
5670 + struct path h_path;
5671 + struct au_cpup_reg_attr h_src_attr;
5675 + a = kmalloc(sizeof(*a), GFP_NOFS);
5678 + a->h_src_attr.valid = 0;
5680 + sb = cpg->dentry->d_sb;
5681 + br = au_sbr(sb, cpg->bdst);
5682 + a->h_path.mnt = au_br_mnt(br);
5683 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5684 + h_parent = h_dst->d_parent; /* dir inode is locked */
5685 + h_dir = d_inode(h_parent);
5688 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5689 + inode = d_inode(cpg->dentry);
5692 + dst_parent = dget_parent(cpg->dentry);
5696 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5697 + dst_inode = au_h_iptr(inode, cpg->bdst);
5699 + if (unlikely(!plink)) {
5701 + AuIOErr("hi%lu(i%lu) exists on b%d "
5702 + "but plink is disabled\n",
5703 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5707 + if (dst_inode->i_nlink) {
5708 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5710 + h_src = au_plink_lkup(inode, cpg->bdst);
5711 + err = PTR_ERR(h_src);
5712 + if (IS_ERR(h_src))
5714 + if (unlikely(d_is_negative(h_src))) {
5716 + AuIOErr("i%lu exists on b%d "
5717 + "but not pseudo-linked\n",
5718 + inode->i_ino, cpg->bdst);
5724 + a->h_path.dentry = h_parent;
5725 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5728 + a->h_path.dentry = h_dst;
5730 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5731 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5732 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5734 + au_dtime_revert(&a->dt);
5735 + if (unlikely(err == -EWOULDBLOCK)) {
5736 + pr_warn("cannot retry for NFSv4 delegation"
5737 + " for an internal link\n");
5743 + /* todo: cpup_wh_file? */
5745 + au_update_ibrange(inode, /*do_put_zero*/1);
5748 + isdir = S_ISDIR(inode->i_mode);
5749 + old_ibtop = au_ibtop(inode);
5750 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5751 + if (unlikely(err))
5753 + dst_inode = d_inode(h_dst);
5754 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5755 + /* todo: necessary? */
5756 + /* au_pin_hdir_unlock(cpg->pin); */
5758 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5759 + if (unlikely(err)) {
5760 + /* todo: necessary? */
5761 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5762 + inode_unlock(dst_inode);
5766 + if (cpg->bdst < old_ibtop) {
5767 + if (S_ISREG(inode->i_mode)) {
5768 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5769 + if (unlikely(err)) {
5770 + /* ignore an error */
5771 + /* au_pin_hdir_relock(cpg->pin); */
5772 + inode_unlock(dst_inode);
5776 + au_set_ibtop(inode, cpg->bdst);
5778 + au_set_ibbot(inode, cpg->bdst);
5779 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5780 + au_hi_flags(inode, isdir));
5782 + /* todo: necessary? */
5783 + /* err = au_pin_hdir_relock(cpg->pin); */
5784 + inode_unlock(dst_inode);
5785 + if (unlikely(err))
5788 + src_inode = d_inode(h_src);
5790 + && (src_inode->i_nlink > 1
5791 + || src_inode->i_state & I_LINKABLE)
5793 + au_plink_append(inode, cpg->bdst, h_dst);
5795 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5796 + a->h_path.dentry = h_dst;
5797 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5800 + goto out_parent; /* success */
5804 + a->h_path.dentry = h_parent;
5805 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5806 + a->h_path.dentry = h_dst;
5808 + if (d_is_positive(h_dst)) {
5810 + /* no delegation since it is just created */
5811 + rerr = vfsub_unlink(h_dir, &a->h_path,
5812 + /*delegated*/NULL, /*force*/0);
5814 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5816 + au_dtime_revert(&a->dt);
5818 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5828 +#if 0 /* reserved */
5829 +struct au_cpup_single_args {
5831 + struct au_cp_generic *cpg;
5832 + struct dentry *dst_parent;
5835 +static void au_call_cpup_single(void *args)
5837 + struct au_cpup_single_args *a = args;
5839 + au_pin_hdir_acquire_nest(a->cpg->pin);
5840 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5841 + au_pin_hdir_release(a->cpg->pin);
5846 + * prevent SIGXFSZ in copy-up.
5847 + * testing CAP_MKNOD is for generic fs,
5848 + * but CAP_FSETID is for xfs only, currently.
5850 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5853 + struct super_block *sb;
5854 + struct inode *h_dir;
5857 + sb = au_pinned_parent(pin)->d_sb;
5858 + if (!au_wkq_test()
5859 + && (!au_sbi(sb)->si_plink_maint_pid
5860 + || au_plink_maint(sb, AuLock_NOPLM))) {
5861 + switch (mode & S_IFMT) {
5863 + /* no condition about RLIMIT_FSIZE and the file size */
5868 + do_sio = !capable(CAP_MKNOD);
5872 + do_sio = ((mode & (S_ISUID | S_ISGID))
5873 + && !capable(CAP_FSETID));
5874 + /* this workaround may be removed in the future */
5876 + h_dir = au_pinned_h_dir(pin);
5877 + do_sio = h_dir->i_mode & S_ISVTX;
5884 +#if 0 /* reserved */
5885 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5888 + struct dentry *h_dentry;
5890 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5891 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5892 + err = au_cpup_single(cpg, dst_parent);
5894 + struct au_cpup_single_args args = {
5897 + .dst_parent = dst_parent
5899 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5900 + if (unlikely(wkq_err))
5909 + * copyup the @dentry from the first active lower branch to @bdst,
5910 + * using au_cpup_single().
5912 +static int au_cpup_simple(struct au_cp_generic *cpg)
5915 + unsigned int flags_orig;
5916 + struct dentry *dentry;
5918 + AuDebugOn(cpg->bsrc < 0);
5920 + dentry = cpg->dentry;
5921 + DiMustWriteLock(dentry);
5923 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5925 + flags_orig = cpg->flags;
5926 + au_fset_cpup(cpg->flags, RENAME);
5927 + err = au_cpup_single(cpg, NULL);
5928 + cpg->flags = flags_orig;
5930 + return 0; /* success */
5933 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5934 + au_set_dbtop(dentry, cpg->bsrc);
5940 +struct au_cpup_simple_args {
5942 + struct au_cp_generic *cpg;
5945 +static void au_call_cpup_simple(void *args)
5947 + struct au_cpup_simple_args *a = args;
5949 + au_pin_hdir_acquire_nest(a->cpg->pin);
5950 + *a->errp = au_cpup_simple(a->cpg);
5951 + au_pin_hdir_release(a->cpg->pin);
5954 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5957 + struct dentry *dentry, *parent;
5958 + struct file *h_file;
5959 + struct inode *h_dir;
5961 + dentry = cpg->dentry;
5963 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5964 + AuDebugOn(cpg->bsrc < 0);
5965 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5966 + err = PTR_ERR(h_file);
5967 + if (IS_ERR(h_file))
5971 + parent = dget_parent(dentry);
5972 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5973 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5974 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5975 + err = au_cpup_simple(cpg);
5977 + struct au_cpup_simple_args args = {
5981 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5982 + if (unlikely(wkq_err))
5988 + au_h_open_post(dentry, cpg->bsrc, h_file);
5994 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5996 + aufs_bindex_t bsrc, bbot;
5997 + struct dentry *dentry, *h_dentry;
5999 + if (cpg->bsrc < 0) {
6000 + dentry = cpg->dentry;
6001 + bbot = au_dbbot(dentry);
6002 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
6003 + h_dentry = au_h_dptr(dentry, bsrc);
6005 + AuDebugOn(d_is_negative(h_dentry));
6009 + AuDebugOn(bsrc > bbot);
6012 + AuDebugOn(cpg->bsrc <= cpg->bdst);
6013 + return au_do_sio_cpup_simple(cpg);
6016 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
6018 + AuDebugOn(cpg->bdst <= cpg->bsrc);
6019 + return au_do_sio_cpup_simple(cpg);
6022 +/* ---------------------------------------------------------------------- */
6025 + * copyup the deleted file for writing.
6027 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
6028 + struct file *file)
6031 + unsigned int flags_orig;
6032 + aufs_bindex_t bsrc_orig;
6033 + struct au_dinfo *dinfo;
6035 + struct au_hdentry *hd;
6036 + struct dentry *h_dentry;
6039 + dinfo = au_di(cpg->dentry);
6040 + AuRwMustWriteLock(&dinfo->di_rwsem);
6042 + bsrc_orig = cpg->bsrc;
6043 + cpg->bsrc = dinfo->di_btop;
6044 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
6045 + hdst.h_dentry = hdst.hd->hd_dentry;
6046 + hdst.hd->hd_dentry = wh_dentry;
6047 + dinfo->di_btop = cpg->bdst;
6049 + hsrc.h_dentry = NULL;
6051 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
6052 + hsrc.h_dentry = hsrc.hd->hd_dentry;
6053 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
6055 + flags_orig = cpg->flags;
6056 + cpg->flags = !AuCpup_DTIME;
6057 + err = au_cpup_single(cpg, /*h_parent*/NULL);
6058 + cpg->flags = flags_orig;
6061 + err = au_reopen_nondir(file);
6062 + hsrc.hd->hd_dentry = hsrc.h_dentry;
6064 + hdst.hd->hd_dentry = hdst.h_dentry;
6065 + dinfo->di_btop = cpg->bsrc;
6066 + cpg->bsrc = bsrc_orig;
6071 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6074 + aufs_bindex_t bdst;
6075 + struct au_dtime dt;
6076 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6077 + struct au_branch *br;
6078 + struct path h_path;
6080 + dentry = cpg->dentry;
6082 + br = au_sbr(dentry->d_sb, bdst);
6083 + parent = dget_parent(dentry);
6084 + h_parent = au_h_dptr(parent, bdst);
6085 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6086 + err = PTR_ERR(wh_dentry);
6087 + if (IS_ERR(wh_dentry))
6090 + h_path.dentry = h_parent;
6091 + h_path.mnt = au_br_mnt(br);
6092 + au_dtime_store(&dt, parent, &h_path);
6093 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6094 + if (unlikely(err))
6098 + h_path.dentry = wh_dentry;
6099 + if (!d_is_dir(wh_dentry)) {
6100 + /* no delegation since it is just created */
6101 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6102 + /*delegated*/NULL, /*force*/0);
6104 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6105 + if (unlikely(err)) {
6106 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6110 + au_dtime_revert(&dt);
6111 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6120 +struct au_cpup_wh_args {
6122 + struct au_cp_generic *cpg;
6123 + struct file *file;
6126 +static void au_call_cpup_wh(void *args)
6128 + struct au_cpup_wh_args *a = args;
6130 + au_pin_hdir_acquire_nest(a->cpg->pin);
6131 + *a->errp = au_cpup_wh(a->cpg, a->file);
6132 + au_pin_hdir_release(a->cpg->pin);
6135 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6138 + aufs_bindex_t bdst;
6139 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6140 + struct inode *dir, *h_dir, *h_tmpdir;
6141 + struct au_wbr *wbr;
6142 + struct au_pin wh_pin, *pin_orig;
6144 + dentry = cpg->dentry;
6146 + parent = dget_parent(dentry);
6147 + dir = d_inode(parent);
6150 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6153 + if (!h_dir->i_nlink) {
6154 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6155 + h_orph = wbr->wbr_orph;
6157 + h_parent = dget(au_h_dptr(parent, bdst));
6158 + au_set_h_dptr(parent, bdst, dget(h_orph));
6159 + h_tmpdir = d_inode(h_orph);
6160 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6162 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6163 + /* todo: au_h_open_pre()? */
6165 + pin_orig = cpg->pin;
6166 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6167 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6168 + cpg->pin = &wh_pin;
6171 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6172 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6173 + err = au_cpup_wh(cpg, file);
6175 + struct au_cpup_wh_args args = {
6180 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6181 + if (unlikely(wkq_err))
6186 + inode_unlock(h_tmpdir);
6187 + /* todo: au_h_open_post()? */
6188 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6189 + au_set_h_dptr(parent, bdst, h_parent);
6190 + AuDebugOn(!pin_orig);
6191 + cpg->pin = pin_orig;
6199 +/* ---------------------------------------------------------------------- */
6202 + * generic routine for both of copy-up and copy-down.
6204 +/* cf. revalidate function in file.c */
6205 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6206 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6207 + struct au_pin *pin,
6208 + struct dentry *h_parent, void *arg),
6212 + struct au_pin pin;
6213 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6216 + parent = dget_parent(dentry);
6217 + if (IS_ROOT(parent))
6220 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6221 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6223 + /* do not use au_dpage */
6224 + real_parent = parent;
6227 + parent = dget_parent(dentry);
6228 + h_parent = au_h_dptr(parent, bdst);
6230 + goto out; /* success */
6232 + /* find top dir which is necessary to cpup */
6236 + parent = dget_parent(d);
6237 + di_read_lock_parent3(parent, !AuLock_IR);
6238 + h_parent = au_h_dptr(parent, bdst);
6239 + di_read_unlock(parent, !AuLock_IR);
6240 + } while (!h_parent);
6242 + if (d != real_parent)
6243 + di_write_lock_child3(d);
6245 + /* somebody else might create while we were sleeping */
6246 + h_dentry = au_h_dptr(d, bdst);
6247 + if (!h_dentry || d_is_negative(h_dentry)) {
6249 + au_update_dbtop(d);
6251 + au_pin_set_dentry(&pin, d);
6252 + err = au_do_pin(&pin);
6254 + err = cp(d, bdst, &pin, h_parent, arg);
6259 + if (d != real_parent)
6260 + di_write_unlock(d);
6261 + if (unlikely(err))
6270 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6271 + struct au_pin *pin,
6272 + struct dentry *h_parent __maybe_unused,
6273 + void *arg __maybe_unused)
6275 + struct au_cp_generic cpg = {
6281 + .flags = AuCpup_DTIME
6283 + return au_sio_cpup_simple(&cpg);
6286 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6288 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6291 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6294 + struct dentry *parent;
6295 + struct inode *dir;
6297 + parent = dget_parent(dentry);
6298 + dir = d_inode(parent);
6300 + if (au_h_iptr(dir, bdst))
6303 + di_read_unlock(parent, AuLock_IR);
6304 + di_write_lock_parent(parent);
6305 + /* someone else might change our inode while we were sleeping */
6306 + if (!au_h_iptr(dir, bdst))
6307 + err = au_cpup_dirs(dentry, bdst);
6308 + di_downgrade_lock(parent, AuLock_IR);
6314 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6315 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6316 +++ linux/fs/aufs/cpup.h 2020-01-27 10:57:18.168871450 +0100
6318 +/* SPDX-License-Identifier: GPL-2.0 */
6320 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6322 + * This program, aufs is free software; you can redistribute it and/or modify
6323 + * it under the terms of the GNU General Public License as published by
6324 + * the Free Software Foundation; either version 2 of the License, or
6325 + * (at your option) any later version.
6327 + * This program is distributed in the hope that it will be useful,
6328 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6329 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6330 + * GNU General Public License for more details.
6332 + * You should have received a copy of the GNU General Public License
6333 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6337 + * copy-up/down functions
6340 +#ifndef __AUFS_CPUP_H__
6341 +#define __AUFS_CPUP_H__
6345 +#include <linux/path.h>
6351 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6352 +void au_cpup_attr_timesizes(struct inode *inode);
6353 +void au_cpup_attr_nlink(struct inode *inode, int force);
6354 +void au_cpup_attr_changeable(struct inode *inode);
6355 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6356 +void au_cpup_attr_all(struct inode *inode, int force);
6358 +/* ---------------------------------------------------------------------- */
6360 +struct au_cp_generic {
6361 + struct dentry *dentry;
6362 + aufs_bindex_t bdst, bsrc;
6364 + struct au_pin *pin;
6365 + unsigned int flags;
6369 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6370 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6372 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6373 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6375 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6377 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6378 + the branch is marked as RO */
6380 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6381 +#undef AuCpup_HOPEN
6382 +#define AuCpup_HOPEN 0
6385 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6386 +#define au_fset_cpup(flags, name) \
6387 + do { (flags) |= AuCpup_##name; } while (0)
6388 +#define au_fclr_cpup(flags, name) \
6389 + do { (flags) &= ~AuCpup_##name; } while (0)
6391 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6392 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6393 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6394 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6396 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6397 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6398 + struct au_pin *pin,
6399 + struct dentry *h_parent, void *arg),
6401 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6402 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6404 +/* ---------------------------------------------------------------------- */
6406 +/* keep timestamps when copyup */
6408 + struct dentry *dt_dentry;
6409 + struct path dt_h_path;
6410 + struct timespec64 dt_atime, dt_mtime;
6412 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6413 + struct path *h_path);
6414 +void au_dtime_revert(struct au_dtime *dt);
6416 +#endif /* __KERNEL__ */
6417 +#endif /* __AUFS_CPUP_H__ */
6418 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6419 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6420 +++ linux/fs/aufs/dbgaufs.c 2020-01-27 10:57:18.168871450 +0100
6422 +// SPDX-License-Identifier: GPL-2.0
6424 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6426 + * This program, aufs is free software; you can redistribute it and/or modify
6427 + * it under the terms of the GNU General Public License as published by
6428 + * the Free Software Foundation; either version 2 of the License, or
6429 + * (at your option) any later version.
6431 + * This program is distributed in the hope that it will be useful,
6432 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6433 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6434 + * GNU General Public License for more details.
6436 + * You should have received a copy of the GNU General Public License
6437 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6441 + * debugfs interface
6444 +#include <linux/debugfs.h>
6447 +#ifndef CONFIG_SYSFS
6448 +#error DEBUG_FS depends upon SYSFS
6451 +static struct dentry *dbgaufs;
6452 +static const mode_t dbgaufs_mode = 0444;
6454 +/* 20 is max digits length of ulong 64 */
6455 +struct dbgaufs_arg {
6461 + * common function for all XINO files
6463 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6464 + struct file *file)
6468 + p = file->private_data;
6470 + /* this is struct dbgaufs_arg */
6471 + AuDebugOn(!au_kfree_sz_test(p));
6472 + au_kfree_do_rcu(p);
6477 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6482 + struct dbgaufs_arg *p;
6485 + p = kmalloc(sizeof(*p), GFP_NOFS);
6491 + file->private_data = p;
6495 + err = vfsub_getattr(&xf->f_path, &st);
6499 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6500 + cnt, st.blocks, st.blksize,
6501 + (long long)st.size);
6503 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6504 + st.blocks, st.blksize,
6505 + (long long)st.size);
6506 + AuDebugOn(p->n >= sizeof(p->a));
6508 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6516 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6517 + size_t count, loff_t *ppos)
6519 + struct dbgaufs_arg *p;
6521 + p = file->private_data;
6522 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6525 +/* ---------------------------------------------------------------------- */
6527 +struct dbgaufs_plink_arg {
6532 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6533 + struct file *file)
6535 + free_page((unsigned long)file->private_data);
6539 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6541 + int err, i, limit;
6542 + unsigned long n, sum;
6543 + struct dbgaufs_plink_arg *p;
6544 + struct au_sbinfo *sbinfo;
6545 + struct super_block *sb;
6546 + struct hlist_bl_head *hbl;
6549 + p = (void *)get_zeroed_page(GFP_NOFS);
6554 + sbinfo = inode->i_private;
6555 + sb = sbinfo->si_sb;
6556 + si_noflush_read_lock(sb);
6557 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6558 + limit = PAGE_SIZE - sizeof(p->n);
6560 + /* the number of buckets */
6561 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6566 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6568 + n = au_hbl_count(hbl);
6571 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6574 + if (unlikely(limit <= 0))
6577 + p->a[p->n - 1] = '\n';
6579 + /* the sum of plinks */
6580 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6583 + if (unlikely(limit <= 0))
6586 +#define str "1\n0\n0\n"
6587 + p->n = sizeof(str) - 1;
6588 + strcpy(p->a, str);
6591 + si_read_unlock(sb);
6594 + file->private_data = p;
6595 + goto out; /* success */
6598 + free_page((unsigned long)p);
6603 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6604 + size_t count, loff_t *ppos)
6606 + struct dbgaufs_plink_arg *p;
6608 + p = file->private_data;
6609 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6612 +static const struct file_operations dbgaufs_plink_fop = {
6613 + .owner = THIS_MODULE,
6614 + .open = dbgaufs_plink_open,
6615 + .release = dbgaufs_plink_release,
6616 + .read = dbgaufs_plink_read
6619 +/* ---------------------------------------------------------------------- */
6621 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6624 + struct au_sbinfo *sbinfo;
6625 + struct super_block *sb;
6627 + sbinfo = inode->i_private;
6628 + sb = sbinfo->si_sb;
6629 + si_noflush_read_lock(sb);
6630 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6631 + si_read_unlock(sb);
6635 +static const struct file_operations dbgaufs_xib_fop = {
6636 + .owner = THIS_MODULE,
6637 + .open = dbgaufs_xib_open,
6638 + .release = dbgaufs_xi_release,
6639 + .read = dbgaufs_xi_read
6642 +/* ---------------------------------------------------------------------- */
6644 +#define DbgaufsXi_PREFIX "xi"
6646 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6650 + aufs_bindex_t bindex;
6651 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6652 + struct au_sbinfo *sbinfo;
6653 + struct super_block *sb;
6654 + struct au_xino *xi;
6656 + struct qstr *name;
6657 + struct au_branch *br;
6660 + name = &file->f_path.dentry->d_name;
6661 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6662 + || memcmp(name->name, DbgaufsXi_PREFIX,
6663 + sizeof(DbgaufsXi_PREFIX) - 1)))
6666 + AuDebugOn(name->len >= sizeof(a));
6667 + memcpy(a, name->name, name->len);
6668 + a[name->len] = '\0';
6669 + p = strchr(a, '-');
6672 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6673 + if (unlikely(err))
6678 + err = kstrtol(p + 1, 10, &l);
6679 + if (unlikely(err))
6685 + sbinfo = inode->i_private;
6686 + sb = sbinfo->si_sb;
6687 + si_noflush_read_lock(sb);
6688 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6690 + br = au_sbr(sb, bindex);
6692 + if (unlikely(idx >= xi->xi_nfile))
6694 + xf = au_xino_file(xi, idx);
6696 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6697 + au_xino_count(br));
6700 + si_read_unlock(sb);
6706 +static const struct file_operations dbgaufs_xino_fop = {
6707 + .owner = THIS_MODULE,
6708 + .open = dbgaufs_xino_open,
6709 + .release = dbgaufs_xi_release,
6710 + .read = dbgaufs_xi_read
6713 +void dbgaufs_xino_del(struct au_branch *br)
6715 + struct dentry *dbgaufs;
6717 + dbgaufs = br->br_dbgaufs;
6721 + br->br_dbgaufs = NULL;
6722 + /* debugfs acquires the parent i_mutex */
6724 + debugfs_remove(dbgaufs);
6728 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6730 + aufs_bindex_t bbot;
6731 + struct au_branch *br;
6733 + if (!au_sbi(sb)->si_dbgaufs)
6736 + bbot = au_sbbot(sb);
6737 + for (; bindex <= bbot; bindex++) {
6738 + br = au_sbr(sb, bindex);
6739 + dbgaufs_xino_del(br);
6743 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6744 + unsigned int idx, struct dentry *parent,
6745 + struct au_sbinfo *sbinfo)
6747 + struct au_branch *br;
6749 + /* "xi" bindex(5) "-" idx(2) NULL */
6750 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6753 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6755 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6757 + br = au_sbr(sb, bindex);
6758 + if (br->br_dbgaufs) {
6759 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6761 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6762 + /* debugfs acquires the parent i_mutex */
6764 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6768 + pr_warn("failed renaming %pd/%s, ignored.\n",
6773 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6774 + sbinfo, &dbgaufs_xino_fop);
6776 + if (unlikely(!br->br_dbgaufs))
6777 + pr_warn("failed creating %pd/%s, ignored.\n",
6782 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6783 + struct dentry *parent, struct au_sbinfo *sbinfo)
6785 + struct au_branch *br;
6786 + struct au_xino *xi;
6789 + br = au_sbr(sb, bindex);
6791 + for (u = 0; u < xi->xi_nfile; u++)
6792 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6795 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6797 + struct au_sbinfo *sbinfo;
6798 + struct dentry *parent;
6799 + aufs_bindex_t bbot;
6801 + if (!au_opt_test(au_mntflags(sb), XINO))
6804 + sbinfo = au_sbi(sb);
6805 + parent = sbinfo->si_dbgaufs;
6809 + bbot = au_sbbot(sb);
6811 + for (; bindex <= bbot; bindex++)
6812 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6814 + for (; bbot >= bindex; bbot--)
6815 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6818 +/* ---------------------------------------------------------------------- */
6820 +#ifdef CONFIG_AUFS_EXPORT
6821 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6824 + struct au_sbinfo *sbinfo;
6825 + struct super_block *sb;
6827 + sbinfo = inode->i_private;
6828 + sb = sbinfo->si_sb;
6829 + si_noflush_read_lock(sb);
6830 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6831 + si_read_unlock(sb);
6835 +static const struct file_operations dbgaufs_xigen_fop = {
6836 + .owner = THIS_MODULE,
6837 + .open = dbgaufs_xigen_open,
6838 + .release = dbgaufs_xi_release,
6839 + .read = dbgaufs_xi_read
6842 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6847 + * This function is a dynamic '__init' function actually,
6848 + * so the tiny check for si_rwsem is unnecessary.
6850 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6853 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6854 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6855 + &dbgaufs_xigen_fop);
6856 + if (sbinfo->si_dbgaufs_xigen)
6862 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6866 +#endif /* CONFIG_AUFS_EXPORT */
6868 +/* ---------------------------------------------------------------------- */
6870 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6873 + * This function is a dynamic '__fin' function actually,
6874 + * so the tiny check for si_rwsem is unnecessary.
6876 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6878 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6879 + sbinfo->si_dbgaufs = NULL;
6882 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6885 + char name[SysaufsSiNameLen];
6888 + * This function is a dynamic '__init' function actually,
6889 + * so the tiny check for si_rwsem is unnecessary.
6891 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6895 + AuErr1("/debug/aufs is uninitialized\n");
6900 + sysaufs_name(sbinfo, name);
6901 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6902 + if (unlikely(!sbinfo->si_dbgaufs))
6905 + /* regardless plink/noplink option */
6906 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6907 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6908 + &dbgaufs_plink_fop);
6909 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6912 + /* regardless xino/noxino option */
6913 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6914 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6915 + &dbgaufs_xib_fop);
6916 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6919 + err = dbgaufs_xigen_init(sbinfo);
6921 + goto out; /* success */
6924 + dbgaufs_si_fin(sbinfo);
6926 + if (unlikely(err))
6927 + pr_err("debugfs/aufs failed\n");
6931 +/* ---------------------------------------------------------------------- */
6933 +void dbgaufs_fin(void)
6935 + debugfs_remove(dbgaufs);
6938 +int __init dbgaufs_init(void)
6943 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6948 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6949 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6950 +++ linux/fs/aufs/dbgaufs.h 2020-01-27 10:57:18.168871450 +0100
6952 +/* SPDX-License-Identifier: GPL-2.0 */
6954 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6956 + * This program, aufs is free software; you can redistribute it and/or modify
6957 + * it under the terms of the GNU General Public License as published by
6958 + * the Free Software Foundation; either version 2 of the License, or
6959 + * (at your option) any later version.
6961 + * This program is distributed in the hope that it will be useful,
6962 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6963 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6964 + * GNU General Public License for more details.
6966 + * You should have received a copy of the GNU General Public License
6967 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6971 + * debugfs interface
6974 +#ifndef __DBGAUFS_H__
6975 +#define __DBGAUFS_H__
6979 +struct super_block;
6983 +#ifdef CONFIG_DEBUG_FS
6985 +void dbgaufs_xino_del(struct au_branch *br);
6986 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6987 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6988 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6989 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6990 +void dbgaufs_fin(void);
6991 +int __init dbgaufs_init(void);
6993 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6994 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6995 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6997 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6998 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6999 +AuStubVoid(dbgaufs_fin, void)
7000 +AuStubInt0(__init dbgaufs_init, void)
7001 +#endif /* CONFIG_DEBUG_FS */
7003 +#endif /* __KERNEL__ */
7004 +#endif /* __DBGAUFS_H__ */
7005 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
7006 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
7007 +++ linux/fs/aufs/dcsub.c 2020-01-27 10:57:18.168871450 +0100
7009 +// SPDX-License-Identifier: GPL-2.0
7011 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7013 + * This program, aufs is free software; you can redistribute it and/or modify
7014 + * it under the terms of the GNU General Public License as published by
7015 + * the Free Software Foundation; either version 2 of the License, or
7016 + * (at your option) any later version.
7018 + * This program is distributed in the hope that it will be useful,
7019 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7020 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7021 + * GNU General Public License for more details.
7023 + * You should have received a copy of the GNU General Public License
7024 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7028 + * sub-routines for dentry cache
7033 +static void au_dpage_free(struct au_dpage *dpage)
7036 + struct dentry **p;
7038 + p = dpage->dentries;
7039 + for (i = 0; i < dpage->ndentry; i++)
7041 + free_page((unsigned long)dpage->dentries);
7044 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
7050 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
7051 + if (unlikely(!dpages->dpages))
7054 + p = (void *)__get_free_page(gfp);
7058 + dpages->dpages[0].ndentry = 0;
7059 + dpages->dpages[0].dentries = p;
7060 + dpages->ndpage = 1;
7061 + return 0; /* success */
7064 + au_kfree_try_rcu(dpages->dpages);
7069 +void au_dpages_free(struct au_dcsub_pages *dpages)
7072 + struct au_dpage *p;
7074 + p = dpages->dpages;
7075 + for (i = 0; i < dpages->ndpage; i++)
7076 + au_dpage_free(p++);
7077 + au_kfree_try_rcu(dpages->dpages);
7080 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7081 + struct dentry *dentry, gfp_t gfp)
7084 + struct au_dpage *dpage;
7087 + dpage = dpages->dpages + dpages->ndpage - 1;
7088 + sz = PAGE_SIZE / sizeof(dentry);
7089 + if (unlikely(dpage->ndentry >= sz)) {
7090 + AuLabel(new dpage);
7092 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7093 + p = au_kzrealloc(dpages->dpages, sz,
7094 + sz + sizeof(*dpages->dpages), gfp,
7099 + dpages->dpages = p;
7100 + dpage = dpages->dpages + dpages->ndpage;
7101 + p = (void *)__get_free_page(gfp);
7105 + dpage->ndentry = 0;
7106 + dpage->dentries = p;
7110 + AuDebugOn(au_dcount(dentry) <= 0);
7111 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7112 + return 0; /* success */
7118 +/* todo: BAD approach */
7119 +/* copied from linux/fs/dcache.c */
7127 +extern void d_walk(struct dentry *parent, void *data,
7128 + enum d_walk_ret (*enter)(void *, struct dentry *));
7130 +struct ac_dpages_arg {
7132 + struct au_dcsub_pages *dpages;
7133 + struct super_block *sb;
7134 + au_dpages_test test;
7138 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7140 + enum d_walk_ret ret;
7141 + struct ac_dpages_arg *arg = _arg;
7143 + ret = D_WALK_CONTINUE;
7144 + if (dentry->d_sb == arg->sb
7145 + && !IS_ROOT(dentry)
7146 + && au_dcount(dentry) > 0
7148 + && (!arg->test || arg->test(dentry, arg->arg))) {
7149 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7150 + if (unlikely(arg->err))
7151 + ret = D_WALK_QUIT;
7157 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7158 + au_dpages_test test, void *arg)
7160 + struct ac_dpages_arg args = {
7168 + d_walk(root, &args, au_call_dpages_append);
7173 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7174 + int do_include, au_dpages_test test, void *arg)
7179 + write_seqlock(&rename_lock);
7180 + spin_lock(&dentry->d_lock);
7182 + && au_dcount(dentry) > 0
7183 + && (!test || test(dentry, arg)))
7184 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7185 + spin_unlock(&dentry->d_lock);
7186 + if (unlikely(err))
7190 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7193 + while (!IS_ROOT(dentry)) {
7194 + dentry = dentry->d_parent; /* rename_lock is locked */
7195 + spin_lock(&dentry->d_lock);
7196 + if (au_dcount(dentry) > 0
7197 + && (!test || test(dentry, arg)))
7198 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7199 + spin_unlock(&dentry->d_lock);
7200 + if (unlikely(err))
7205 + write_sequnlock(&rename_lock);
7209 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7211 + return au_di(dentry) && dentry->d_sb == arg;
7214 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7215 + struct dentry *dentry, int do_include)
7217 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7218 + au_dcsub_dpages_aufs, dentry->d_sb);
7221 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7223 + struct path path[2] = {
7232 + return path_is_under(path + 0, path + 1);
7234 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7235 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7236 +++ linux/fs/aufs/dcsub.h 2020-01-27 10:57:18.168871450 +0100
7238 +/* SPDX-License-Identifier: GPL-2.0 */
7240 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7242 + * This program, aufs is free software; you can redistribute it and/or modify
7243 + * it under the terms of the GNU General Public License as published by
7244 + * the Free Software Foundation; either version 2 of the License, or
7245 + * (at your option) any later version.
7247 + * This program is distributed in the hope that it will be useful,
7248 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7249 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7250 + * GNU General Public License for more details.
7252 + * You should have received a copy of the GNU General Public License
7253 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7257 + * sub-routines for dentry cache
7260 +#ifndef __AUFS_DCSUB_H__
7261 +#define __AUFS_DCSUB_H__
7265 +#include <linux/dcache.h>
7266 +#include <linux/fs.h>
7270 + struct dentry **dentries;
7273 +struct au_dcsub_pages {
7275 + struct au_dpage *dpages;
7278 +/* ---------------------------------------------------------------------- */
7281 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7282 +void au_dpages_free(struct au_dcsub_pages *dpages);
7283 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7284 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7285 + au_dpages_test test, void *arg);
7286 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7287 + int do_include, au_dpages_test test, void *arg);
7288 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7289 + struct dentry *dentry, int do_include);
7290 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7292 +/* ---------------------------------------------------------------------- */
7295 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7296 + * include/linux/dcache.h. Try them (in the future).
7299 +static inline int au_d_hashed_positive(struct dentry *d)
7302 + struct inode *inode = d_inode(d);
7305 + if (unlikely(d_unhashed(d)
7306 + || d_is_negative(d)
7307 + || !inode->i_nlink))
7312 +static inline int au_d_linkable(struct dentry *d)
7315 + struct inode *inode = d_inode(d);
7317 + err = au_d_hashed_positive(d);
7319 + && d_is_positive(d)
7320 + && (inode->i_state & I_LINKABLE))
7325 +static inline int au_d_alive(struct dentry *d)
7328 + struct inode *inode;
7332 + err = au_d_hashed_positive(d);
7334 + inode = d_inode(d);
7335 + if (unlikely(d_unlinked(d)
7336 + || d_is_negative(d)
7337 + || !inode->i_nlink))
7343 +static inline int au_alive_dir(struct dentry *d)
7347 + err = au_d_alive(d);
7348 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7353 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7355 + return a->len == b->len
7356 + && !memcmp(a->name, b->name, a->len);
7361 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7363 + * the type of d_lockref.count became int, but the inlined function d_count()
7364 + * still returns unsigned int.
7365 + * I don't know why. Maybe it is for every d_count() users?
7366 + * Anyway au_dcount() lives on.
7368 +static inline int au_dcount(struct dentry *d)
7370 + return (int)d_count(d);
7373 +#endif /* __KERNEL__ */
7374 +#endif /* __AUFS_DCSUB_H__ */
7375 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7376 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7377 +++ linux/fs/aufs/debug.c 2020-01-27 10:57:18.168871450 +0100
7379 +// SPDX-License-Identifier: GPL-2.0
7381 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7383 + * This program, aufs is free software; you can redistribute it and/or modify
7384 + * it under the terms of the GNU General Public License as published by
7385 + * the Free Software Foundation; either version 2 of the License, or
7386 + * (at your option) any later version.
7388 + * This program is distributed in the hope that it will be useful,
7389 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7390 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7391 + * GNU General Public License for more details.
7393 + * You should have received a copy of the GNU General Public License
7394 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7398 + * debug print functions
7401 +#include <linux/iversion.h>
7404 +/* Returns 0, or -errno. arg is in kp->arg. */
7405 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7409 + err = kstrtoint(val, 0, &n);
7419 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7420 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7425 + return sprintf(buffer, "%d", atomic_read(a));
7428 +static struct kernel_param_ops param_ops_atomic_t = {
7429 + .set = param_atomic_t_set,
7430 + .get = param_atomic_t_get
7431 + /* void (*free)(void *arg) */
7434 +atomic_t aufs_debug = ATOMIC_INIT(0);
7435 +MODULE_PARM_DESC(debug, "debug print");
7436 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7438 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7439 +char *au_plevel = KERN_DEBUG;
7440 +#define dpri(fmt, ...) do { \
7442 + && strcmp(au_plevel, KERN_DEBUG)) \
7443 + || au_debug_test()) \
7444 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7447 +/* ---------------------------------------------------------------------- */
7449 +void au_dpri_whlist(struct au_nhash *whlist)
7451 + unsigned long ul, n;
7452 + struct hlist_head *head;
7453 + struct au_vdir_wh *pos;
7455 + n = whlist->nh_num;
7456 + head = whlist->nh_head;
7457 + for (ul = 0; ul < n; ul++) {
7458 + hlist_for_each_entry(pos, head, wh_hash)
7459 + dpri("b%d, %.*s, %d\n",
7461 + pos->wh_str.len, pos->wh_str.name,
7467 +void au_dpri_vdir(struct au_vdir *vdir)
7470 + union au_vdir_deblk_p p;
7473 + if (!vdir || IS_ERR(vdir)) {
7474 + dpri("err %ld\n", PTR_ERR(vdir));
7478 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7479 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7480 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7481 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7482 + p.deblk = vdir->vd_deblk[ul];
7484 + dpri("[%lu]: %p\n", ul, o);
7488 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7489 + struct dentry *wh)
7494 + if (!inode || IS_ERR(inode)) {
7495 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7499 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7500 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7501 + && sizeof(inode->i_blocks) != sizeof(u64));
7503 + n = (void *)wh->d_name.name;
7504 + l = wh->d_name.len;
7507 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7508 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7510 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7511 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7512 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7513 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7514 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7515 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7516 + inode->i_generation,
7517 + l ? ", wh " : "", l, n);
7521 +void au_dpri_inode(struct inode *inode)
7523 + struct au_iinfo *iinfo;
7524 + struct au_hinode *hi;
7525 + aufs_bindex_t bindex;
7528 + err = do_pri_inode(-1, inode, -1, NULL);
7529 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7532 + iinfo = au_ii(inode);
7533 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7534 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7535 + if (iinfo->ii_btop < 0)
7538 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7539 + hi = au_hinode(iinfo, bindex);
7541 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7545 +void au_dpri_dalias(struct inode *inode)
7549 + spin_lock(&inode->i_lock);
7550 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7551 + au_dpri_dentry(d);
7552 + spin_unlock(&inode->i_lock);
7555 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7557 + struct dentry *wh = NULL;
7559 + struct inode *inode;
7560 + struct au_iinfo *iinfo;
7561 + struct au_hinode *hi;
7563 + if (!dentry || IS_ERR(dentry)) {
7564 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7567 + /* do not call dget_parent() here */
7568 + /* note: access d_xxx without d_lock */
7569 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7570 + bindex, dentry, dentry,
7571 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7572 + au_dcount(dentry), dentry->d_flags,
7573 + d_unhashed(dentry) ? "un" : "");
7576 + if (d_is_positive(dentry))
7577 + inode = d_inode(dentry);
7579 + && au_test_aufs(dentry->d_sb)
7581 + && !au_is_bad_inode(inode)) {
7582 + iinfo = au_ii(inode);
7583 + hi = au_hinode(iinfo, bindex);
7585 + wh = hi->hi_whdentry;
7587 + do_pri_inode(bindex, inode, hn, wh);
7591 +void au_dpri_dentry(struct dentry *dentry)
7593 + struct au_dinfo *dinfo;
7594 + aufs_bindex_t bindex;
7597 + err = do_pri_dentry(-1, dentry);
7598 + if (err || !au_test_aufs(dentry->d_sb))
7601 + dinfo = au_di(dentry);
7604 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7605 + dinfo->di_btop, dinfo->di_bbot,
7606 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7607 + dinfo->di_tmpfile);
7608 + if (dinfo->di_btop < 0)
7610 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7611 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7614 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7618 + if (!file || IS_ERR(file)) {
7619 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7624 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7625 + && au_test_aufs(file->f_path.dentry->d_sb)
7627 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7628 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7629 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7630 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7631 + file->f_version, file->f_pos, a);
7632 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7633 + do_pri_dentry(bindex, file->f_path.dentry);
7637 +void au_dpri_file(struct file *file)
7639 + struct au_finfo *finfo;
7640 + struct au_fidir *fidir;
7641 + struct au_hfile *hfile;
7642 + aufs_bindex_t bindex;
7645 + err = do_pri_file(-1, file);
7647 + || IS_ERR_OR_NULL(file->f_path.dentry)
7648 + || !au_test_aufs(file->f_path.dentry->d_sb))
7651 + finfo = au_fi(file);
7654 + if (finfo->fi_btop < 0)
7656 + fidir = finfo->fi_hdir;
7658 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7660 + for (bindex = finfo->fi_btop;
7661 + bindex >= 0 && bindex <= fidir->fd_bbot;
7663 + hfile = fidir->fd_hfile + bindex;
7664 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7668 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7670 + struct vfsmount *mnt;
7671 + struct super_block *sb;
7673 + if (!br || IS_ERR(br))
7675 + mnt = au_br_mnt(br);
7676 + if (!mnt || IS_ERR(mnt))
7679 + if (!sb || IS_ERR(sb))
7682 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7683 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7685 + bindex, br->br_perm, br->br_id, br->br_wbr,
7686 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7687 + sb->s_flags, sb->s_count,
7688 + atomic_read(&sb->s_active),
7689 + !!au_xino_file(br->br_xino, /*idx*/-1));
7693 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7697 +void au_dpri_sb(struct super_block *sb)
7699 + struct au_sbinfo *sbinfo;
7700 + aufs_bindex_t bindex;
7702 + /* to reduce stack size */
7704 + struct vfsmount mnt;
7705 + struct au_branch fake;
7708 + /* this function can be called from magic sysrq */
7709 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7710 + if (unlikely(!a)) {
7711 + dpri("no memory\n");
7715 + a->mnt.mnt_sb = sb;
7716 + a->fake.br_path.mnt = &a->mnt;
7717 + err = do_pri_br(-1, &a->fake);
7719 + dpri("dev 0x%x\n", sb->s_dev);
7720 + if (err || !au_test_aufs(sb))
7723 + sbinfo = au_sbi(sb);
7726 + dpri("nw %d, gen %u, kobj %d\n",
7727 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7728 + kref_read(&sbinfo->si_kobj.kref));
7729 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7730 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7733 +/* ---------------------------------------------------------------------- */
7735 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7737 + struct inode *h_inode, *inode = d_inode(dentry);
7738 + struct dentry *h_dentry;
7739 + aufs_bindex_t bindex, bbot, bi;
7741 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7744 + bbot = au_dbbot(dentry);
7745 + bi = au_ibbot(inode);
7748 + bindex = au_dbtop(dentry);
7749 + bi = au_ibtop(inode);
7753 + for (; bindex <= bbot; bindex++) {
7754 + h_dentry = au_h_dptr(dentry, bindex);
7757 + h_inode = au_h_iptr(inode, bindex);
7758 + if (unlikely(h_inode != d_inode(h_dentry))) {
7760 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7761 + AuDbgDentry(dentry);
7762 + AuDbgInode(inode);
7769 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7772 + struct au_dcsub_pages dpages;
7773 + struct au_dpage *dpage;
7774 + struct dentry **dentries;
7776 + err = au_dpages_init(&dpages, GFP_NOFS);
7778 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7780 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7781 + dpage = dpages.dpages + i;
7782 + dentries = dpage->dentries;
7783 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7784 + AuDebugOn(au_digen_test(dentries[j], sigen));
7786 + au_dpages_free(&dpages);
7789 +void au_dbg_verify_kthread(void)
7791 + if (au_wkq_test()) {
7794 + * It may be recursive, but udba=notify between two aufs mounts,
7795 + * where a single ro branch is shared, is not a problem.
7801 +/* ---------------------------------------------------------------------- */
7803 +int __init au_debug_init(void)
7805 + aufs_bindex_t bindex;
7806 + struct au_vdir_destr destr;
7809 + AuDebugOn(bindex >= 0);
7812 + AuDebugOn(destr.len < NAME_MAX);
7814 +#ifdef CONFIG_4KSTACKS
7815 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7820 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7821 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7822 +++ linux/fs/aufs/debug.h 2020-01-27 10:57:18.168871450 +0100
7824 +/* SPDX-License-Identifier: GPL-2.0 */
7826 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7828 + * This program, aufs is free software; you can redistribute it and/or modify
7829 + * it under the terms of the GNU General Public License as published by
7830 + * the Free Software Foundation; either version 2 of the License, or
7831 + * (at your option) any later version.
7833 + * This program is distributed in the hope that it will be useful,
7834 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7835 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7836 + * GNU General Public License for more details.
7838 + * You should have received a copy of the GNU General Public License
7839 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7843 + * debug print functions
7846 +#ifndef __AUFS_DEBUG_H__
7847 +#define __AUFS_DEBUG_H__
7851 +#include <linux/atomic.h>
7852 +#include <linux/module.h>
7853 +#include <linux/kallsyms.h>
7854 +#include <linux/sysrq.h>
7856 +#ifdef CONFIG_AUFS_DEBUG
7857 +#define AuDebugOn(a) BUG_ON(a)
7859 +/* module parameter */
7860 +extern atomic_t aufs_debug;
7861 +static inline void au_debug_on(void)
7863 + atomic_inc(&aufs_debug);
7865 +static inline void au_debug_off(void)
7867 + atomic_dec_if_positive(&aufs_debug);
7870 +static inline int au_debug_test(void)
7872 + return atomic_read(&aufs_debug) > 0;
7875 +#define AuDebugOn(a) do {} while (0)
7876 +AuStubVoid(au_debug_on, void)
7877 +AuStubVoid(au_debug_off, void)
7878 +AuStubInt0(au_debug_test, void)
7879 +#endif /* CONFIG_AUFS_DEBUG */
7881 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7883 +/* ---------------------------------------------------------------------- */
7887 +#define AuDbg(fmt, ...) do { \
7888 + if (au_debug_test()) \
7889 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7891 +#define AuLabel(l) AuDbg(#l "\n")
7892 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7893 +#define AuWarn1(fmt, ...) do { \
7894 + static unsigned char _c; \
7896 + pr_warn(fmt, ##__VA_ARGS__); \
7899 +#define AuErr1(fmt, ...) do { \
7900 + static unsigned char _c; \
7902 + pr_err(fmt, ##__VA_ARGS__); \
7905 +#define AuIOErr1(fmt, ...) do { \
7906 + static unsigned char _c; \
7908 + AuIOErr(fmt, ##__VA_ARGS__); \
7911 +#define AuUnsupportMsg "This operation is not supported." \
7912 + " Please report this application to aufs-users ML."
7913 +#define AuUnsupport(fmt, ...) do { \
7914 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7918 +#define AuTraceErr(e) do { \
7919 + if (unlikely((e) < 0)) \
7920 + AuDbg("err %d\n", (int)(e)); \
7923 +#define AuTraceErrPtr(p) do { \
7925 + AuDbg("err %ld\n", PTR_ERR(p)); \
7928 +/* dirty macros for debug print, use with "%.*s" and caution */
7929 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7931 +/* ---------------------------------------------------------------------- */
7934 +#ifdef CONFIG_AUFS_DEBUG
7935 +extern struct mutex au_dbg_mtx;
7936 +extern char *au_plevel;
7938 +void au_dpri_whlist(struct au_nhash *whlist);
7940 +void au_dpri_vdir(struct au_vdir *vdir);
7942 +void au_dpri_inode(struct inode *inode);
7943 +void au_dpri_dalias(struct inode *inode);
7944 +void au_dpri_dentry(struct dentry *dentry);
7946 +void au_dpri_file(struct file *filp);
7947 +struct super_block;
7948 +void au_dpri_sb(struct super_block *sb);
7950 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7951 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7952 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7953 +void au_dbg_verify_kthread(void);
7955 +int __init au_debug_init(void);
7957 +#define AuDbgWhlist(w) do { \
7958 + mutex_lock(&au_dbg_mtx); \
7960 + au_dpri_whlist(w); \
7961 + mutex_unlock(&au_dbg_mtx); \
7964 +#define AuDbgVdir(v) do { \
7965 + mutex_lock(&au_dbg_mtx); \
7967 + au_dpri_vdir(v); \
7968 + mutex_unlock(&au_dbg_mtx); \
7971 +#define AuDbgInode(i) do { \
7972 + mutex_lock(&au_dbg_mtx); \
7974 + au_dpri_inode(i); \
7975 + mutex_unlock(&au_dbg_mtx); \
7978 +#define AuDbgDAlias(i) do { \
7979 + mutex_lock(&au_dbg_mtx); \
7981 + au_dpri_dalias(i); \
7982 + mutex_unlock(&au_dbg_mtx); \
7985 +#define AuDbgDentry(d) do { \
7986 + mutex_lock(&au_dbg_mtx); \
7988 + au_dpri_dentry(d); \
7989 + mutex_unlock(&au_dbg_mtx); \
7992 +#define AuDbgFile(f) do { \
7993 + mutex_lock(&au_dbg_mtx); \
7995 + au_dpri_file(f); \
7996 + mutex_unlock(&au_dbg_mtx); \
7999 +#define AuDbgSb(sb) do { \
8000 + mutex_lock(&au_dbg_mtx); \
8001 + AuDbg(#sb "\n"); \
8003 + mutex_unlock(&au_dbg_mtx); \
8006 +#define AuDbgSym(addr) do { \
8007 + char sym[KSYM_SYMBOL_LEN]; \
8008 + sprint_symbol(sym, (unsigned long)addr); \
8009 + AuDbg("%s\n", sym); \
8012 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
8013 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
8014 +AuStubVoid(au_dbg_verify_kthread, void)
8015 +AuStubInt0(__init au_debug_init, void)
8017 +#define AuDbgWhlist(w) do {} while (0)
8018 +#define AuDbgVdir(v) do {} while (0)
8019 +#define AuDbgInode(i) do {} while (0)
8020 +#define AuDbgDAlias(i) do {} while (0)
8021 +#define AuDbgDentry(d) do {} while (0)
8022 +#define AuDbgFile(f) do {} while (0)
8023 +#define AuDbgSb(sb) do {} while (0)
8024 +#define AuDbgSym(addr) do {} while (0)
8025 +#endif /* CONFIG_AUFS_DEBUG */
8027 +/* ---------------------------------------------------------------------- */
8029 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
8030 +int __init au_sysrq_init(void);
8031 +void au_sysrq_fin(void);
8033 +#ifdef CONFIG_HW_CONSOLE
8034 +#define au_dbg_blocked() do { \
8036 + handle_sysrq('w'); \
8039 +AuStubVoid(au_dbg_blocked, void)
8043 +AuStubInt0(__init au_sysrq_init, void)
8044 +AuStubVoid(au_sysrq_fin, void)
8045 +AuStubVoid(au_dbg_blocked, void)
8046 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
8048 +#endif /* __KERNEL__ */
8049 +#endif /* __AUFS_DEBUG_H__ */
8050 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
8051 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
8052 +++ linux/fs/aufs/dentry.c 2020-01-27 10:57:18.168871450 +0100
8054 +// SPDX-License-Identifier: GPL-2.0
8056 + * Copyright (C) 2005-2020 Junjiro R. Okajima
8058 + * This program, aufs is free software; you can redistribute it and/or modify
8059 + * it under the terms of the GNU General Public License as published by
8060 + * the Free Software Foundation; either version 2 of the License, or
8061 + * (at your option) any later version.
8063 + * This program is distributed in the hope that it will be useful,
8064 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8065 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8066 + * GNU General Public License for more details.
8068 + * You should have received a copy of the GNU General Public License
8069 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8073 + * lookup and dentry operations
8076 +#include <linux/iversion.h>
8077 +#include <linux/namei.h>
8081 + * returns positive/negative dentry, NULL or an error.
8082 + * NULL means whiteout-ed or not-found.
8084 +static struct dentry*
8085 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8086 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8088 + struct dentry *h_dentry;
8089 + struct inode *h_inode;
8090 + struct au_branch *br;
8091 + int wh_found, opq;
8092 + unsigned char wh_able;
8093 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8094 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8098 + br = au_sbr(dentry->d_sb, bindex);
8099 + wh_able = !!au_br_whable(br->br_perm);
8101 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8102 + h_dentry = ERR_PTR(wh_found);
8105 + if (unlikely(wh_found < 0))
8108 + /* We found a whiteout */
8109 + /* au_set_dbbot(dentry, bindex); */
8110 + au_set_dbwh(dentry, bindex);
8112 + return NULL; /* success */
8116 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8118 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8119 + if (IS_ERR(h_dentry)) {
8120 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8126 + h_inode = d_inode(h_dentry);
8127 + if (d_is_negative(h_dentry)) {
8130 + } else if (wh_found
8131 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8133 + else if (au_ftest_lkup(args->flags, DIRREN)
8135 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8136 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8137 + (unsigned long long)h_inode->i_ino);
8141 + if (au_dbbot(dentry) <= bindex)
8142 + au_set_dbbot(dentry, bindex);
8143 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8144 + au_set_dbtop(dentry, bindex);
8145 + au_set_h_dptr(dentry, bindex, h_dentry);
8147 + if (!d_is_dir(h_dentry)
8149 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8150 + goto out; /* success */
8152 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8153 + opq = au_diropq_test(h_dentry);
8154 + inode_unlock_shared(h_inode);
8156 + au_set_dbdiropq(dentry, bindex);
8157 + else if (unlikely(opq < 0)) {
8158 + au_set_h_dptr(dentry, bindex, NULL);
8159 + h_dentry = ERR_PTR(opq);
8170 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8172 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8173 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8179 + * returns the number of lower positive dentries,
8180 + * otherwise an error.
8181 + * can be called at unlinking with @type is zero.
8183 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8184 + unsigned int flags)
8186 + int npositive, err;
8187 + aufs_bindex_t bindex, btail, bdiropq;
8188 + unsigned char isdir, dirperm1, dirren;
8189 + struct au_do_lookup_args args = {
8191 + .name = &dentry->d_name
8193 + struct dentry *parent;
8194 + struct super_block *sb;
8196 + sb = dentry->d_sb;
8197 + err = au_test_shwh(sb, args.name);
8198 + if (unlikely(err))
8201 + err = au_wh_name_alloc(&args.whname, args.name);
8202 + if (unlikely(err))
8205 + isdir = !!d_is_dir(dentry);
8206 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8207 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8209 + au_fset_lkup(args.flags, DIRREN);
8212 + parent = dget_parent(dentry);
8213 + btail = au_dbtaildir(parent);
8214 + for (bindex = btop; bindex <= btail; bindex++) {
8215 + struct dentry *h_parent, *h_dentry;
8216 + struct inode *h_inode, *h_dir;
8217 + struct au_branch *br;
8219 + h_dentry = au_h_dptr(dentry, bindex);
8221 + if (d_is_positive(h_dentry))
8225 + h_parent = au_h_dptr(parent, bindex);
8226 + if (!h_parent || !d_is_dir(h_parent))
8230 + /* if the inum matches, then use the prepared name */
8231 + err = au_dr_lkup_name(&args, bindex);
8232 + if (unlikely(err))
8236 + h_dir = d_inode(h_parent);
8237 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8238 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8239 + inode_unlock_shared(h_dir);
8240 + err = PTR_ERR(h_dentry);
8241 + if (IS_ERR(h_dentry))
8244 + au_fclr_lkup(args.flags, ALLOW_NEG);
8246 + au_fset_lkup(args.flags, IGNORE_PERM);
8248 + if (au_dbwh(dentry) == bindex)
8252 + if (d_is_negative(h_dentry))
8254 + h_inode = d_inode(h_dentry);
8257 + args.type = h_inode->i_mode & S_IFMT;
8258 + if (args.type != S_IFDIR)
8261 + /* the type of lower may be different */
8262 + bdiropq = au_dbdiropq(dentry);
8263 + if (bdiropq >= 0 && bdiropq <= bindex)
8266 + br = au_sbr(sb, bindex);
8268 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8269 + /*add_ent*/NULL)) {
8270 + /* prepare next name to lookup */
8271 + err = au_dr_lkup(&args, dentry, bindex);
8272 + if (unlikely(err))
8278 + AuLabel(positive);
8279 + au_update_dbtop(dentry);
8282 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8283 + && au_dbtop(dentry) < 0)) {
8285 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8291 + au_kfree_try_rcu(args.whname.name);
8293 + au_dr_lkup_fin(&args);
8298 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8300 + struct dentry *dentry;
8303 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8304 + dentry = vfsub_lkup_one(name, parent);
8306 + struct vfsub_lkup_one_args args = {
8312 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8313 + if (unlikely(wkq_err))
8314 + dentry = ERR_PTR(wkq_err);
8321 + * lookup @dentry on @bindex which should be negative.
8323 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8326 + struct dentry *parent, *h_parent, *h_dentry;
8327 + struct au_branch *br;
8329 + parent = dget_parent(dentry);
8330 + h_parent = au_h_dptr(parent, bindex);
8331 + br = au_sbr(dentry->d_sb, bindex);
8333 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8335 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8336 + err = PTR_ERR(h_dentry);
8337 + if (IS_ERR(h_dentry))
8339 + if (unlikely(d_is_positive(h_dentry))) {
8341 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8347 + if (bindex < au_dbtop(dentry))
8348 + au_set_dbtop(dentry, bindex);
8349 + if (au_dbbot(dentry) < bindex)
8350 + au_set_dbbot(dentry, bindex);
8351 + au_set_h_dptr(dentry, bindex, h_dentry);
8358 +/* ---------------------------------------------------------------------- */
8360 +/* subset of struct inode */
8362 + unsigned long i_ino;
8363 + /* unsigned int i_nlink; */
8369 + blkcnt_t i_blocks;
8374 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8376 + ia->i_ino = h_inode->i_ino;
8377 + /* ia->i_nlink = h_inode->i_nlink; */
8378 + ia->i_uid = h_inode->i_uid;
8379 + ia->i_gid = h_inode->i_gid;
8380 + ia->i_version = inode_query_iversion(h_inode);
8382 + ia->i_size = h_inode->i_size;
8383 + ia->i_blocks = h_inode->i_blocks;
8385 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8388 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8390 + return ia->i_ino != h_inode->i_ino
8391 + /* || ia->i_nlink != h_inode->i_nlink */
8392 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8393 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8394 + || !inode_eq_iversion(h_inode, ia->i_version)
8396 + || ia->i_size != h_inode->i_size
8397 + || ia->i_blocks != h_inode->i_blocks
8399 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8402 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8403 + struct au_branch *br)
8406 + struct au_iattr ia;
8407 + struct inode *h_inode;
8408 + struct dentry *h_d;
8409 + struct super_block *h_sb;
8412 + memset(&ia, -1, sizeof(ia));
8413 + h_sb = h_dentry->d_sb;
8415 + if (d_is_positive(h_dentry)) {
8416 + h_inode = d_inode(h_dentry);
8417 + au_iattr_save(&ia, h_inode);
8418 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8419 + /* nfs d_revalidate may return 0 for negative dentry */
8420 + /* fuse d_revalidate always return 0 for negative dentry */
8423 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8424 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8425 + err = PTR_ERR(h_d);
8430 + if (unlikely(h_d != h_dentry
8431 + || d_inode(h_d) != h_inode
8432 + || (h_inode && au_iattr_test(&ia, h_inode))))
8433 + err = au_busy_or_stale();
8441 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8442 + struct dentry *h_parent, struct au_branch *br)
8447 + if (udba == AuOpt_UDBA_REVAL
8448 + && !au_test_fs_remote(h_dentry->d_sb)) {
8450 + err = (d_inode(h_dentry->d_parent) != h_dir);
8451 + } else if (udba != AuOpt_UDBA_NONE)
8452 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8457 +/* ---------------------------------------------------------------------- */
8459 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8462 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8463 + struct au_hdentry tmp, *p, *q;
8464 + struct au_dinfo *dinfo;
8465 + struct super_block *sb;
8467 + DiMustWriteLock(dentry);
8469 + sb = dentry->d_sb;
8470 + dinfo = au_di(dentry);
8471 + bbot = dinfo->di_bbot;
8472 + bwh = dinfo->di_bwh;
8473 + bdiropq = dinfo->di_bdiropq;
8474 + bindex = dinfo->di_btop;
8475 + p = au_hdentry(dinfo, bindex);
8476 + for (; bindex <= bbot; bindex++, p++) {
8477 + if (!p->hd_dentry)
8480 + new_bindex = au_br_index(sb, p->hd_id);
8481 + if (new_bindex == bindex)
8484 + if (dinfo->di_bwh == bindex)
8486 + if (dinfo->di_bdiropq == bindex)
8487 + bdiropq = new_bindex;
8488 + if (new_bindex < 0) {
8490 + p->hd_dentry = NULL;
8494 + /* swap two lower dentries, and loop again */
8495 + q = au_hdentry(dinfo, new_bindex);
8499 + if (tmp.hd_dentry) {
8505 + dinfo->di_bwh = -1;
8506 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8507 + dinfo->di_bwh = bwh;
8509 + dinfo->di_bdiropq = -1;
8511 + && bdiropq <= au_sbbot(sb)
8512 + && au_sbr_whable(sb, bdiropq))
8513 + dinfo->di_bdiropq = bdiropq;
8516 + dinfo->di_btop = -1;
8517 + dinfo->di_bbot = -1;
8518 + bbot = au_dbbot(parent);
8520 + p = au_hdentry(dinfo, bindex);
8521 + for (; bindex <= bbot; bindex++, p++)
8522 + if (p->hd_dentry) {
8523 + dinfo->di_btop = bindex;
8527 + if (dinfo->di_btop >= 0) {
8529 + p = au_hdentry(dinfo, bindex);
8530 + for (; bindex >= 0; bindex--, p--)
8531 + if (p->hd_dentry) {
8532 + dinfo->di_bbot = bindex;
8541 +static void au_do_hide(struct dentry *dentry)
8543 + struct inode *inode;
8545 + if (d_really_is_positive(dentry)) {
8546 + inode = d_inode(dentry);
8547 + if (!d_is_dir(dentry)) {
8548 + if (inode->i_nlink && !d_unhashed(dentry))
8549 + drop_nlink(inode);
8551 + clear_nlink(inode);
8552 + /* stop next lookup */
8553 + inode->i_flags |= S_DEAD;
8555 + smp_mb(); /* necessary? */
8560 +static int au_hide_children(struct dentry *parent)
8562 + int err, i, j, ndentry;
8563 + struct au_dcsub_pages dpages;
8564 + struct au_dpage *dpage;
8565 + struct dentry *dentry;
8567 + err = au_dpages_init(&dpages, GFP_NOFS);
8568 + if (unlikely(err))
8570 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8571 + if (unlikely(err))
8574 + /* in reverse order */
8575 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8576 + dpage = dpages.dpages + i;
8577 + ndentry = dpage->ndentry;
8578 + for (j = ndentry - 1; j >= 0; j--) {
8579 + dentry = dpage->dentries[j];
8580 + if (dentry != parent)
8581 + au_do_hide(dentry);
8586 + au_dpages_free(&dpages);
8591 +static void au_hide(struct dentry *dentry)
8595 + AuDbgDentry(dentry);
8596 + if (d_is_dir(dentry)) {
8597 + /* shrink_dcache_parent(dentry); */
8598 + err = au_hide_children(dentry);
8599 + if (unlikely(err))
8600 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8603 + au_do_hide(dentry);
8607 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8609 + * a dirty branch is added
8610 + * - on the top of layers
8611 + * - in the middle of layers
8612 + * - to the bottom of layers
8614 + * on the added branch there exists
8617 + * - a same named entry
8619 + * * negative --> positive
8620 + * * positive --> positive
8621 + * - type is unchanged
8622 + * - type is changed
8624 + * * negative --> negative
8625 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8628 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8629 + struct au_dinfo *tmp)
8632 + aufs_bindex_t bindex, bbot;
8634 + struct dentry *dentry;
8635 + struct inode *inode;
8637 + } orig_h, tmp_h = {
8640 + struct au_hdentry *hd;
8641 + struct inode *inode, *h_inode;
8642 + struct dentry *h_dentry;
8645 + AuDebugOn(dinfo->di_btop < 0);
8647 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8648 + orig_h.inode = NULL;
8649 + if (d_is_positive(orig_h.dentry)) {
8650 + orig_h.inode = d_inode(orig_h.dentry);
8651 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8653 + if (tmp->di_btop >= 0) {
8654 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8655 + if (d_is_positive(tmp_h.dentry)) {
8656 + tmp_h.inode = d_inode(tmp_h.dentry);
8657 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8662 + if (d_really_is_positive(dentry))
8663 + inode = d_inode(dentry);
8664 + if (!orig_h.inode) {
8665 + AuDbg("negative originally\n");
8671 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8672 + AuDebugOn(dinfo->di_bdiropq != -1);
8674 + if (!tmp_h.inode) {
8675 + AuDbg("negative --> negative\n");
8676 + /* should have only one negative lower */
8677 + if (tmp->di_btop >= 0
8678 + && tmp->di_btop < dinfo->di_btop) {
8679 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8680 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8681 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8682 + au_di_cp(dinfo, tmp);
8683 + hd = au_hdentry(tmp, tmp->di_btop);
8684 + au_set_h_dptr(dentry, tmp->di_btop,
8685 + dget(hd->hd_dentry));
8687 + au_dbg_verify_dinode(dentry);
8689 + AuDbg("negative --> positive\n");
8691 + * similar to the behaviour of creating with bypassing
8693 + * unhash it in order to force an error in the
8694 + * succeeding create operation.
8695 + * we should not set S_DEAD here.
8698 + /* au_di_swap(tmp, dinfo); */
8699 + au_dbg_verify_dinode(dentry);
8702 + AuDbg("positive originally\n");
8703 + /* inode may be NULL */
8704 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8705 + if (!tmp_h.inode) {
8706 + AuDbg("positive --> negative\n");
8707 + /* or bypassing aufs */
8709 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8710 + dinfo->di_bwh = tmp->di_bwh;
8712 + err = au_refresh_hinode_self(inode);
8713 + au_dbg_verify_dinode(dentry);
8714 + } else if (orig_h.mode == tmp_h.mode) {
8715 + AuDbg("positive --> positive, same type\n");
8716 + if (!S_ISDIR(orig_h.mode)
8717 + && dinfo->di_btop > tmp->di_btop) {
8719 + * similar to the behaviour of removing and
8724 + err = au_refresh_hinode_self(inode);
8725 + au_dbg_verify_dinode(dentry);
8727 + /* fill empty slots */
8728 + if (dinfo->di_btop > tmp->di_btop)
8729 + dinfo->di_btop = tmp->di_btop;
8730 + if (dinfo->di_bbot < tmp->di_bbot)
8731 + dinfo->di_bbot = tmp->di_bbot;
8732 + dinfo->di_bwh = tmp->di_bwh;
8733 + dinfo->di_bdiropq = tmp->di_bdiropq;
8734 + bbot = dinfo->di_bbot;
8735 + bindex = tmp->di_btop;
8736 + hd = au_hdentry(tmp, bindex);
8737 + for (; bindex <= bbot; bindex++, hd++) {
8738 + if (au_h_dptr(dentry, bindex))
8740 + h_dentry = hd->hd_dentry;
8743 + AuDebugOn(d_is_negative(h_dentry));
8744 + h_inode = d_inode(h_dentry);
8745 + AuDebugOn(orig_h.mode
8746 + != (h_inode->i_mode
8748 + au_set_h_dptr(dentry, bindex,
8752 + err = au_refresh_hinode(inode, dentry);
8753 + au_dbg_verify_dinode(dentry);
8756 + AuDbg("positive --> positive, different type\n");
8757 + /* similar to the behaviour of removing and creating */
8760 + err = au_refresh_hinode_self(inode);
8761 + au_dbg_verify_dinode(dentry);
8769 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8771 + const struct dentry_operations *dop
8772 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8773 + static const unsigned int mask
8774 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8776 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8778 + if (dentry->d_op == dop)
8781 + AuDbg("%pd\n", dentry);
8782 + spin_lock(&dentry->d_lock);
8783 + if (dop == &aufs_dop)
8784 + dentry->d_flags |= mask;
8786 + dentry->d_flags &= ~mask;
8787 + dentry->d_op = dop;
8788 + spin_unlock(&dentry->d_lock);
8791 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8793 + int err, ebrange, nbr;
8794 + unsigned int sigen;
8795 + struct au_dinfo *dinfo, *tmp;
8796 + struct super_block *sb;
8797 + struct inode *inode;
8799 + DiMustWriteLock(dentry);
8800 + AuDebugOn(IS_ROOT(dentry));
8801 + AuDebugOn(d_really_is_negative(parent));
8803 + sb = dentry->d_sb;
8804 + sigen = au_sigen(sb);
8805 + err = au_digen_test(parent, sigen);
8806 + if (unlikely(err))
8809 + nbr = au_sbbot(sb) + 1;
8810 + dinfo = au_di(dentry);
8811 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8812 + if (unlikely(err))
8814 + ebrange = au_dbrange_test(dentry);
8816 + ebrange = au_do_refresh_hdentry(dentry, parent);
8818 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8819 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8820 + if (d_really_is_positive(dentry)) {
8821 + inode = d_inode(dentry);
8822 + err = au_refresh_hinode_self(inode);
8824 + au_dbg_verify_dinode(dentry);
8826 + goto out_dgen; /* success */
8830 + /* temporary dinfo */
8831 + AuDbgDentry(dentry);
8833 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8834 + if (unlikely(!tmp))
8836 + au_di_swap(tmp, dinfo);
8837 + /* returns the number of positive dentries */
8839 + * if current working dir is removed, it returns an error.
8840 + * but the dentry is legal.
8842 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8843 + AuDbgDentry(dentry);
8844 + au_di_swap(tmp, dinfo);
8845 + if (err == -ENOENT)
8848 + /* compare/refresh by dinfo */
8849 + AuDbgDentry(dentry);
8850 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8851 + au_dbg_verify_dinode(dentry);
8854 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8855 + au_rw_write_unlock(&tmp->di_rwsem);
8857 + if (unlikely(err))
8861 + au_update_digen(dentry);
8863 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8864 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8865 + AuDbgDentry(dentry);
8871 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8872 + struct dentry *dentry, aufs_bindex_t bindex)
8877 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8880 + AuDbg("b%d\n", bindex);
8882 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8883 + * due to whiteout and branch permission.
8885 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8886 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8887 + /* it may return tri-state */
8888 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8890 + if (unlikely(valid < 0))
8900 +/* todo: remove this */
8901 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8902 + unsigned int flags, int do_udba, int dirren)
8905 + umode_t mode, h_mode;
8906 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8907 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8908 + struct inode *h_inode, *h_cached_inode;
8909 + struct dentry *h_dentry;
8910 + struct qstr *name, *h_name;
8917 + unhashed = !!d_unhashed(dentry);
8918 + is_root = !!IS_ROOT(dentry);
8919 + name = &dentry->d_name;
8920 + tmpfile = au_di(dentry)->di_tmpfile;
8923 + * Theoretically, REVAL test should be unnecessary in case of
8925 + * But {fs,i}notify doesn't fire some necessary events,
8926 + * IN_ATTRIB for atime/nlink/pageio
8927 + * Let's do REVAL test too.
8929 + if (do_udba && inode) {
8930 + mode = (inode->i_mode & S_IFMT);
8931 + plus = (inode->i_nlink > 0);
8932 + ibs = au_ibtop(inode);
8933 + ibe = au_ibbot(inode);
8936 + btop = au_dbtop(dentry);
8938 + if (inode && S_ISDIR(inode->i_mode))
8939 + btail = au_dbtaildir(dentry);
8940 + for (bindex = btop; bindex <= btail; bindex++) {
8941 + h_dentry = au_h_dptr(dentry, bindex);
8945 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8946 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8947 + spin_lock(&h_dentry->d_lock);
8948 + h_name = &h_dentry->d_name;
8949 + if (unlikely(do_udba
8952 + && (unhashed != !!d_unhashed(h_dentry)
8953 + || (!tmpfile && !dirren
8954 + && !au_qstreq(name, h_name))
8957 + && !(flags & LOOKUP_OPEN)
8958 + && (h_dentry->d_flags
8959 + & DCACHE_NFSFS_RENAMED)))
8963 + h_unhashed = d_unhashed(h_dentry);
8964 + spin_unlock(&h_dentry->d_lock);
8965 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8966 + unhashed, h_unhashed, dentry, h_dentry);
8969 + spin_unlock(&h_dentry->d_lock);
8971 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8972 + if (unlikely(err))
8973 + /* do not goto err, to keep the errno */
8976 + /* todo: plink too? */
8981 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8985 + if (d_is_positive(h_dentry))
8986 + h_inode = d_inode(h_dentry);
8989 + h_cached_inode = h_inode;
8991 + h_mode = (h_inode->i_mode & S_IFMT);
8992 + h_plus = (h_inode->i_nlink > 0);
8994 + if (inode && ibs <= bindex && bindex <= ibe)
8995 + h_cached_inode = au_h_iptr(inode, bindex);
8998 + if (unlikely(plus != h_plus && !tmpfile))
9001 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
9003 + && !IS_ROOT(h_dentry)
9004 + && unhashed != d_unhashed(h_dentry)))
9007 + if (unlikely(mode != h_mode
9008 + || h_cached_inode != h_inode))
9021 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
9022 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
9025 + struct dentry *parent;
9027 + if (!au_digen_test(dentry, sigen))
9030 + parent = dget_parent(dentry);
9031 + di_read_lock_parent(parent, AuLock_IR);
9032 + AuDebugOn(au_digen_test(parent, sigen));
9033 + au_dbg_verify_gen(parent, sigen);
9034 + err = au_refresh_dentry(dentry, parent);
9035 + di_read_unlock(parent, AuLock_IR);
9041 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
9044 + struct dentry *d, *parent;
9046 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
9047 + return simple_reval_dpath(dentry, sigen);
9049 + /* slow loop, keep it simple and stupid */
9050 + /* cf: au_cpup_dirs() */
9053 + while (au_digen_test(dentry, sigen)) {
9057 + parent = dget_parent(d);
9058 + if (!au_digen_test(parent, sigen))
9064 + di_write_lock_child2(d);
9066 + /* someone might update our dentry while we were sleeping */
9067 + if (au_digen_test(d, sigen)) {
9069 + * todo: consolidate with simple_reval_dpath(),
9070 + * do_refresh() and au_reval_for_attr().
9072 + di_read_lock_parent(parent, AuLock_IR);
9073 + err = au_refresh_dentry(d, parent);
9074 + di_read_unlock(parent, AuLock_IR);
9078 + di_write_unlock(d);
9080 + if (unlikely(err))
9088 + * if valid returns 1, otherwise 0.
9090 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9093 + unsigned int sigen;
9094 + unsigned char do_udba, dirren;
9095 + struct super_block *sb;
9096 + struct inode *inode;
9098 + /* todo: support rcu-walk? */
9099 + if (flags & LOOKUP_RCU)
9103 + if (unlikely(!au_di(dentry)))
9107 + sb = dentry->d_sb;
9110 + * i_mutex of parent dir may be held,
9111 + * but we should not return 'invalid' due to busy.
9113 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9114 + if (unlikely(err)) {
9120 + if (d_really_is_positive(dentry))
9121 + inode = d_inode(dentry);
9122 + if (unlikely(inode && au_is_bad_inode(inode))) {
9127 + if (unlikely(au_dbrange_test(dentry))) {
9133 + sigen = au_sigen(sb);
9134 + if (au_digen_test(dentry, sigen)) {
9135 + AuDebugOn(IS_ROOT(dentry));
9136 + err = au_reval_dpath(dentry, sigen);
9137 + if (unlikely(err)) {
9142 + di_downgrade_lock(dentry, AuLock_IR);
9145 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9147 + && !(inode->i_state && I_LINKABLE)
9148 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9153 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9154 + if (do_udba && inode) {
9155 + aufs_bindex_t btop = au_ibtop(inode);
9156 + struct inode *h_inode;
9159 + h_inode = au_h_iptr(inode, btop);
9160 + if (h_inode && au_test_higen(inode, h_inode)) {
9167 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9168 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9169 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9171 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9177 + di_downgrade_lock(dentry, AuLock_IR);
9179 + aufs_read_unlock(dentry, AuLock_IR);
9184 + AuDbg("%pd invalid, %d\n", dentry, valid);
9190 +static void aufs_d_release(struct dentry *dentry)
9192 + if (au_di(dentry)) {
9193 + au_di_fin(dentry);
9194 + au_hn_di_reinit(dentry);
9198 +const struct dentry_operations aufs_dop = {
9199 + .d_revalidate = aufs_d_revalidate,
9200 + .d_weak_revalidate = aufs_d_revalidate,
9201 + .d_release = aufs_d_release
9204 +/* aufs_dop without d_revalidate */
9205 +const struct dentry_operations aufs_dop_noreval = {
9206 + .d_release = aufs_d_release
9208 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9209 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9210 +++ linux/fs/aufs/dentry.h 2020-01-27 10:57:18.168871450 +0100
9212 +/* SPDX-License-Identifier: GPL-2.0 */
9214 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9216 + * This program, aufs is free software; you can redistribute it and/or modify
9217 + * it under the terms of the GNU General Public License as published by
9218 + * the Free Software Foundation; either version 2 of the License, or
9219 + * (at your option) any later version.
9221 + * This program is distributed in the hope that it will be useful,
9222 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9223 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9224 + * GNU General Public License for more details.
9226 + * You should have received a copy of the GNU General Public License
9227 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9231 + * lookup and dentry operations
9234 +#ifndef __AUFS_DENTRY_H__
9235 +#define __AUFS_DENTRY_H__
9239 +#include <linux/dcache.h>
9240 +#include "dirren.h"
9243 +struct au_hdentry {
9244 + struct dentry *hd_dentry;
9245 + aufs_bindex_t hd_id;
9249 + atomic_t di_generation;
9251 + struct au_rwsem di_rwsem;
9252 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9253 + unsigned char di_tmpfile; /* to allow the different name */
9254 + struct au_hdentry *di_hdentry;
9255 + struct rcu_head rcu;
9256 +} ____cacheline_aligned_in_smp;
9258 +/* ---------------------------------------------------------------------- */
9260 +/* flags for au_lkup_dentry() */
9261 +#define AuLkup_ALLOW_NEG 1
9262 +#define AuLkup_IGNORE_PERM (1 << 1)
9263 +#define AuLkup_DIRREN (1 << 2)
9264 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9265 +#define au_fset_lkup(flags, name) \
9266 + do { (flags) |= AuLkup_##name; } while (0)
9267 +#define au_fclr_lkup(flags, name) \
9268 + do { (flags) &= ~AuLkup_##name; } while (0)
9270 +#ifndef CONFIG_AUFS_DIRREN
9271 +#undef AuLkup_DIRREN
9272 +#define AuLkup_DIRREN 0
9275 +struct au_do_lookup_args {
9276 + unsigned int flags;
9278 + struct qstr whname, *name;
9279 + struct au_dr_lookup dirren;
9282 +/* ---------------------------------------------------------------------- */
9285 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9287 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9288 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9289 + struct dentry *h_parent, struct au_branch *br);
9291 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9292 + unsigned int flags);
9293 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9294 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9295 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9296 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9299 +void au_di_init_once(void *_di);
9300 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9301 +void au_di_free(struct au_dinfo *dinfo);
9302 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9303 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9304 +int au_di_init(struct dentry *dentry);
9305 +void au_di_fin(struct dentry *dentry);
9306 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9308 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9309 +void di_read_unlock(struct dentry *d, int flags);
9310 +void di_downgrade_lock(struct dentry *d, int flags);
9311 +void di_write_lock(struct dentry *d, unsigned int lsc);
9312 +void di_write_unlock(struct dentry *d);
9313 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9314 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9315 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9317 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9318 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9319 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9320 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9322 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9323 + struct dentry *h_dentry);
9324 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9325 +int au_dbrange_test(struct dentry *dentry);
9326 +void au_update_digen(struct dentry *dentry);
9327 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9328 +void au_update_dbtop(struct dentry *dentry);
9329 +void au_update_dbbot(struct dentry *dentry);
9330 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9332 +/* ---------------------------------------------------------------------- */
9334 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9336 + return dentry->d_fsdata;
9339 +/* ---------------------------------------------------------------------- */
9341 +/* lock subclass for dinfo */
9343 + AuLsc_DI_CHILD, /* child first */
9344 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9345 + AuLsc_DI_CHILD3, /* copyup dirs */
9349 + AuLsc_DI_TMP /* temp for replacing dinfo */
9353 + * di_read_lock_child, di_write_lock_child,
9354 + * di_read_lock_child2, di_write_lock_child2,
9355 + * di_read_lock_child3, di_write_lock_child3,
9356 + * di_read_lock_parent, di_write_lock_parent,
9357 + * di_read_lock_parent2, di_write_lock_parent2,
9358 + * di_read_lock_parent3, di_write_lock_parent3,
9360 +#define AuReadLockFunc(name, lsc) \
9361 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9362 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9364 +#define AuWriteLockFunc(name, lsc) \
9365 +static inline void di_write_lock_##name(struct dentry *d) \
9366 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9368 +#define AuRWLockFuncs(name, lsc) \
9369 + AuReadLockFunc(name, lsc) \
9370 + AuWriteLockFunc(name, lsc)
9372 +AuRWLockFuncs(child, CHILD);
9373 +AuRWLockFuncs(child2, CHILD2);
9374 +AuRWLockFuncs(child3, CHILD3);
9375 +AuRWLockFuncs(parent, PARENT);
9376 +AuRWLockFuncs(parent2, PARENT2);
9377 +AuRWLockFuncs(parent3, PARENT3);
9379 +#undef AuReadLockFunc
9380 +#undef AuWriteLockFunc
9381 +#undef AuRWLockFuncs
9383 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9384 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9385 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9387 +/* ---------------------------------------------------------------------- */
9389 +/* todo: memory barrier? */
9390 +static inline unsigned int au_digen(struct dentry *d)
9392 + return atomic_read(&au_di(d)->di_generation);
9395 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9397 + hdentry->hd_dentry = NULL;
9400 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9401 + aufs_bindex_t bindex)
9403 + return di->di_hdentry + bindex;
9406 +static inline void au_hdput(struct au_hdentry *hd)
9409 + dput(hd->hd_dentry);
9412 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9414 + DiMustAnyLock(dentry);
9415 + return au_di(dentry)->di_btop;
9418 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9420 + DiMustAnyLock(dentry);
9421 + return au_di(dentry)->di_bbot;
9424 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9426 + DiMustAnyLock(dentry);
9427 + return au_di(dentry)->di_bwh;
9430 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9432 + DiMustAnyLock(dentry);
9433 + return au_di(dentry)->di_bdiropq;
9436 +/* todo: hard/soft set? */
9437 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9439 + DiMustWriteLock(dentry);
9440 + au_di(dentry)->di_btop = bindex;
9443 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9445 + DiMustWriteLock(dentry);
9446 + au_di(dentry)->di_bbot = bindex;
9449 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9451 + DiMustWriteLock(dentry);
9452 + /* dbwh can be outside of btop - bbot range */
9453 + au_di(dentry)->di_bwh = bindex;
9456 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9458 + DiMustWriteLock(dentry);
9459 + au_di(dentry)->di_bdiropq = bindex;
9462 +/* ---------------------------------------------------------------------- */
9464 +#ifdef CONFIG_AUFS_HNOTIFY
9465 +static inline void au_digen_dec(struct dentry *d)
9467 + atomic_dec(&au_di(d)->di_generation);
9470 +static inline void au_hn_di_reinit(struct dentry *dentry)
9472 + dentry->d_fsdata = NULL;
9475 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9476 +#endif /* CONFIG_AUFS_HNOTIFY */
9478 +#endif /* __KERNEL__ */
9479 +#endif /* __AUFS_DENTRY_H__ */
9480 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9481 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9482 +++ linux/fs/aufs/dinfo.c 2020-01-27 10:57:18.168871450 +0100
9484 +// SPDX-License-Identifier: GPL-2.0
9486 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9488 + * This program, aufs is free software; you can redistribute it and/or modify
9489 + * it under the terms of the GNU General Public License as published by
9490 + * the Free Software Foundation; either version 2 of the License, or
9491 + * (at your option) any later version.
9493 + * This program is distributed in the hope that it will be useful,
9494 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9495 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9496 + * GNU General Public License for more details.
9498 + * You should have received a copy of the GNU General Public License
9499 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9503 + * dentry private data
9508 +void au_di_init_once(void *_dinfo)
9510 + struct au_dinfo *dinfo = _dinfo;
9512 + au_rw_init(&dinfo->di_rwsem);
9515 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9517 + struct au_dinfo *dinfo;
9520 + dinfo = au_cache_alloc_dinfo();
9521 + if (unlikely(!dinfo))
9524 + nbr = au_sbbot(sb) + 1;
9527 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9528 + if (dinfo->di_hdentry) {
9529 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9530 + dinfo->di_btop = -1;
9531 + dinfo->di_bbot = -1;
9532 + dinfo->di_bwh = -1;
9533 + dinfo->di_bdiropq = -1;
9534 + dinfo->di_tmpfile = 0;
9535 + for (i = 0; i < nbr; i++)
9536 + dinfo->di_hdentry[i].hd_id = -1;
9540 + au_cache_free_dinfo(dinfo);
9547 +void au_di_free(struct au_dinfo *dinfo)
9549 + struct au_hdentry *p;
9550 + aufs_bindex_t bbot, bindex;
9552 + /* dentry may not be revalidated */
9553 + bindex = dinfo->di_btop;
9554 + if (bindex >= 0) {
9555 + bbot = dinfo->di_bbot;
9556 + p = au_hdentry(dinfo, bindex);
9557 + while (bindex++ <= bbot)
9560 + au_kfree_try_rcu(dinfo->di_hdentry);
9561 + au_cache_free_dinfo(dinfo);
9564 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9566 + struct au_hdentry *p;
9569 + AuRwMustWriteLock(&a->di_rwsem);
9570 + AuRwMustWriteLock(&b->di_rwsem);
9572 +#define DiSwap(v, name) \
9574 + v = a->di_##name; \
9575 + a->di_##name = b->di_##name; \
9576 + b->di_##name = v; \
9579 + DiSwap(p, hdentry);
9583 + DiSwap(bi, bdiropq);
9589 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9591 + AuRwMustWriteLock(&dst->di_rwsem);
9592 + AuRwMustWriteLock(&src->di_rwsem);
9594 + dst->di_btop = src->di_btop;
9595 + dst->di_bbot = src->di_bbot;
9596 + dst->di_bwh = src->di_bwh;
9597 + dst->di_bdiropq = src->di_bdiropq;
9601 +int au_di_init(struct dentry *dentry)
9604 + struct super_block *sb;
9605 + struct au_dinfo *dinfo;
9608 + sb = dentry->d_sb;
9609 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9611 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9612 + /* smp_mb(); */ /* atomic_set */
9613 + dentry->d_fsdata = dinfo;
9620 +void au_di_fin(struct dentry *dentry)
9622 + struct au_dinfo *dinfo;
9624 + dinfo = au_di(dentry);
9625 + AuRwDestroy(&dinfo->di_rwsem);
9626 + au_di_free(dinfo);
9629 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9632 + struct au_hdentry *hdp;
9634 + AuRwMustWriteLock(&dinfo->di_rwsem);
9637 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9639 + sz = sizeof(*hdp);
9640 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9643 + dinfo->di_hdentry = hdp;
9650 +/* ---------------------------------------------------------------------- */
9652 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9655 + case AuLsc_DI_CHILD:
9656 + ii_write_lock_child(inode);
9658 + case AuLsc_DI_CHILD2:
9659 + ii_write_lock_child2(inode);
9661 + case AuLsc_DI_CHILD3:
9662 + ii_write_lock_child3(inode);
9664 + case AuLsc_DI_PARENT:
9665 + ii_write_lock_parent(inode);
9667 + case AuLsc_DI_PARENT2:
9668 + ii_write_lock_parent2(inode);
9670 + case AuLsc_DI_PARENT3:
9671 + ii_write_lock_parent3(inode);
9678 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9681 + case AuLsc_DI_CHILD:
9682 + ii_read_lock_child(inode);
9684 + case AuLsc_DI_CHILD2:
9685 + ii_read_lock_child2(inode);
9687 + case AuLsc_DI_CHILD3:
9688 + ii_read_lock_child3(inode);
9690 + case AuLsc_DI_PARENT:
9691 + ii_read_lock_parent(inode);
9693 + case AuLsc_DI_PARENT2:
9694 + ii_read_lock_parent2(inode);
9696 + case AuLsc_DI_PARENT3:
9697 + ii_read_lock_parent3(inode);
9704 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9706 + struct inode *inode;
9708 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9709 + if (d_really_is_positive(d)) {
9710 + inode = d_inode(d);
9711 + if (au_ftest_lock(flags, IW))
9712 + do_ii_write_lock(inode, lsc);
9713 + else if (au_ftest_lock(flags, IR))
9714 + do_ii_read_lock(inode, lsc);
9718 +void di_read_unlock(struct dentry *d, int flags)
9720 + struct inode *inode;
9722 + if (d_really_is_positive(d)) {
9723 + inode = d_inode(d);
9724 + if (au_ftest_lock(flags, IW)) {
9725 + au_dbg_verify_dinode(d);
9726 + ii_write_unlock(inode);
9727 + } else if (au_ftest_lock(flags, IR)) {
9728 + au_dbg_verify_dinode(d);
9729 + ii_read_unlock(inode);
9732 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9735 +void di_downgrade_lock(struct dentry *d, int flags)
9737 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9738 + ii_downgrade_lock(d_inode(d));
9739 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9742 +void di_write_lock(struct dentry *d, unsigned int lsc)
9744 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9745 + if (d_really_is_positive(d))
9746 + do_ii_write_lock(d_inode(d), lsc);
9749 +void di_write_unlock(struct dentry *d)
9751 + au_dbg_verify_dinode(d);
9752 + if (d_really_is_positive(d))
9753 + ii_write_unlock(d_inode(d));
9754 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9757 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9759 + AuDebugOn(d1 == d2
9760 + || d_inode(d1) == d_inode(d2)
9761 + || d1->d_sb != d2->d_sb);
9763 + if ((isdir && au_test_subdir(d1, d2))
9765 + di_write_lock_child(d1);
9766 + di_write_lock_child2(d2);
9768 + di_write_lock_child(d2);
9769 + di_write_lock_child2(d1);
9773 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9775 + AuDebugOn(d1 == d2
9776 + || d_inode(d1) == d_inode(d2)
9777 + || d1->d_sb != d2->d_sb);
9779 + if ((isdir && au_test_subdir(d1, d2))
9781 + di_write_lock_parent(d1);
9782 + di_write_lock_parent2(d2);
9784 + di_write_lock_parent(d2);
9785 + di_write_lock_parent2(d1);
9789 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9791 + di_write_unlock(d1);
9792 + if (d_inode(d1) == d_inode(d2))
9793 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9795 + di_write_unlock(d2);
9798 +/* ---------------------------------------------------------------------- */
9800 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9804 + DiMustAnyLock(dentry);
9806 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9808 + AuDebugOn(bindex < 0);
9809 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9810 + AuDebugOn(d && au_dcount(d) <= 0);
9815 + * extended version of au_h_dptr().
9816 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9819 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9821 + struct dentry *h_dentry;
9822 + struct inode *inode, *h_inode;
9824 + AuDebugOn(d_really_is_negative(dentry));
9827 + if (au_dbtop(dentry) <= bindex
9828 + && bindex <= au_dbbot(dentry))
9829 + h_dentry = au_h_dptr(dentry, bindex);
9830 + if (h_dentry && !au_d_linkable(h_dentry)) {
9832 + goto out; /* success */
9835 + inode = d_inode(dentry);
9836 + AuDebugOn(bindex < au_ibtop(inode));
9837 + AuDebugOn(au_ibbot(inode) < bindex);
9838 + h_inode = au_h_iptr(inode, bindex);
9839 + h_dentry = d_find_alias(h_inode);
9841 + if (!IS_ERR(h_dentry)) {
9842 + if (!au_d_linkable(h_dentry))
9843 + goto out; /* success */
9849 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9850 + h_dentry = au_plink_lkup(inode, bindex);
9851 + AuDebugOn(!h_dentry);
9852 + if (!IS_ERR(h_dentry)) {
9853 + if (!au_d_hashed_positive(h_dentry))
9854 + goto out; /* success */
9861 + AuDbgDentry(h_dentry);
9865 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9867 + aufs_bindex_t bbot, bwh;
9869 + bbot = au_dbbot(dentry);
9871 + bwh = au_dbwh(dentry);
9874 + if (0 < bwh && bwh < bbot)
9880 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9882 + aufs_bindex_t bbot, bopq;
9884 + bbot = au_dbtail(dentry);
9886 + bopq = au_dbdiropq(dentry);
9887 + if (0 <= bopq && bopq < bbot)
9893 +/* ---------------------------------------------------------------------- */
9895 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9896 + struct dentry *h_dentry)
9898 + struct au_dinfo *dinfo;
9899 + struct au_hdentry *hd;
9900 + struct au_branch *br;
9902 + DiMustWriteLock(dentry);
9904 + dinfo = au_di(dentry);
9905 + hd = au_hdentry(dinfo, bindex);
9907 + hd->hd_dentry = h_dentry;
9909 + br = au_sbr(dentry->d_sb, bindex);
9910 + hd->hd_id = br->br_id;
9914 +int au_dbrange_test(struct dentry *dentry)
9917 + aufs_bindex_t btop, bbot;
9920 + btop = au_dbtop(dentry);
9921 + bbot = au_dbbot(dentry);
9923 + AuDebugOn(bbot < 0 && btop > bbot);
9926 + AuDebugOn(bbot >= 0);
9932 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9937 + if (unlikely(au_digen(dentry) != sigen
9938 + || au_iigen_test(d_inode(dentry), sigen)))
9944 +void au_update_digen(struct dentry *dentry)
9946 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9947 + /* smp_mb(); */ /* atomic_set */
9950 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9952 + struct au_dinfo *dinfo;
9953 + struct dentry *h_d;
9954 + struct au_hdentry *hdp;
9955 + aufs_bindex_t bindex, bbot;
9957 + DiMustWriteLock(dentry);
9959 + dinfo = au_di(dentry);
9960 + if (!dinfo || dinfo->di_btop < 0)
9963 + if (do_put_zero) {
9964 + bbot = dinfo->di_bbot;
9965 + bindex = dinfo->di_btop;
9966 + hdp = au_hdentry(dinfo, bindex);
9967 + for (; bindex <= bbot; bindex++, hdp++) {
9968 + h_d = hdp->hd_dentry;
9969 + if (h_d && d_is_negative(h_d))
9970 + au_set_h_dptr(dentry, bindex, NULL);
9974 + dinfo->di_btop = 0;
9975 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9976 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9977 + if (hdp->hd_dentry)
9979 + if (dinfo->di_btop > dinfo->di_bbot) {
9980 + dinfo->di_btop = -1;
9981 + dinfo->di_bbot = -1;
9985 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9986 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9987 + if (hdp->hd_dentry)
9989 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9992 +void au_update_dbtop(struct dentry *dentry)
9994 + aufs_bindex_t bindex, bbot;
9995 + struct dentry *h_dentry;
9997 + bbot = au_dbbot(dentry);
9998 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9999 + h_dentry = au_h_dptr(dentry, bindex);
10002 + if (d_is_positive(h_dentry)) {
10003 + au_set_dbtop(dentry, bindex);
10006 + au_set_h_dptr(dentry, bindex, NULL);
10010 +void au_update_dbbot(struct dentry *dentry)
10012 + aufs_bindex_t bindex, btop;
10013 + struct dentry *h_dentry;
10015 + btop = au_dbtop(dentry);
10016 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
10017 + h_dentry = au_h_dptr(dentry, bindex);
10020 + if (d_is_positive(h_dentry)) {
10021 + au_set_dbbot(dentry, bindex);
10024 + au_set_h_dptr(dentry, bindex, NULL);
10028 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
10030 + aufs_bindex_t bindex, bbot;
10032 + bbot = au_dbbot(dentry);
10033 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
10034 + if (au_h_dptr(dentry, bindex) == h_dentry)
10038 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
10039 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
10040 +++ linux/fs/aufs/dir.c 2020-01-27 10:57:18.168871450 +0100
10042 +// SPDX-License-Identifier: GPL-2.0
10044 + * Copyright (C) 2005-2020 Junjiro R. Okajima
10046 + * This program, aufs is free software; you can redistribute it and/or modify
10047 + * it under the terms of the GNU General Public License as published by
10048 + * the Free Software Foundation; either version 2 of the License, or
10049 + * (at your option) any later version.
10051 + * This program is distributed in the hope that it will be useful,
10052 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10053 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10054 + * GNU General Public License for more details.
10056 + * You should have received a copy of the GNU General Public License
10057 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10061 + * directory operations
10064 +#include <linux/fs_stack.h>
10065 +#include <linux/iversion.h>
10068 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10070 + unsigned int nlink;
10072 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10074 + nlink = dir->i_nlink;
10075 + nlink += h_dir->i_nlink - 2;
10076 + if (h_dir->i_nlink < 2)
10078 + smp_mb(); /* for i_nlink */
10079 + /* 0 can happen in revaliding */
10080 + set_nlink(dir, nlink);
10083 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10085 + unsigned int nlink;
10087 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10089 + nlink = dir->i_nlink;
10090 + nlink -= h_dir->i_nlink - 2;
10091 + if (h_dir->i_nlink < 2)
10093 + smp_mb(); /* for i_nlink */
10094 + /* nlink == 0 means the branch-fs is broken */
10095 + set_nlink(dir, nlink);
10098 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10101 + aufs_bindex_t bindex, bbot;
10102 + struct file *h_file;
10103 + struct dentry *h_dentry;
10107 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10109 + bbot = au_fbbot_dir(file);
10110 + for (bindex = au_fbtop(file);
10111 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10113 + h_file = au_hf_dir(file, bindex);
10114 + if (h_file && file_inode(h_file))
10115 + sz += vfsub_f_size_read(h_file);
10118 + AuDebugOn(!dentry);
10119 + AuDebugOn(!d_is_dir(dentry));
10121 + bbot = au_dbtaildir(dentry);
10122 + for (bindex = au_dbtop(dentry);
10123 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10125 + h_dentry = au_h_dptr(dentry, bindex);
10126 + if (h_dentry && d_is_positive(h_dentry))
10127 + sz += i_size_read(d_inode(h_dentry));
10130 + if (sz < KMALLOC_MAX_SIZE)
10131 + sz = roundup_pow_of_two(sz);
10132 + if (sz > KMALLOC_MAX_SIZE)
10133 + sz = KMALLOC_MAX_SIZE;
10134 + else if (sz < NAME_MAX) {
10135 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10136 + sz = AUFS_RDBLK_DEF;
10141 +struct au_dir_ts_arg {
10142 + struct dentry *dentry;
10143 + aufs_bindex_t brid;
10146 +static void au_do_dir_ts(void *arg)
10148 + struct au_dir_ts_arg *a = arg;
10149 + struct au_dtime dt;
10150 + struct path h_path;
10151 + struct inode *dir, *h_dir;
10152 + struct super_block *sb;
10153 + struct au_branch *br;
10154 + struct au_hinode *hdir;
10156 + aufs_bindex_t btop, bindex;
10158 + sb = a->dentry->d_sb;
10159 + if (d_really_is_negative(a->dentry))
10161 + /* no dir->i_mutex lock */
10162 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10164 + dir = d_inode(a->dentry);
10165 + btop = au_ibtop(dir);
10166 + bindex = au_br_index(sb, a->brid);
10167 + if (bindex < btop)
10170 + br = au_sbr(sb, bindex);
10171 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10172 + if (!h_path.dentry)
10174 + h_path.mnt = au_br_mnt(br);
10175 + au_dtime_store(&dt, a->dentry, &h_path);
10177 + br = au_sbr(sb, btop);
10178 + if (!au_br_writable(br->br_perm))
10180 + h_path.dentry = au_h_dptr(a->dentry, btop);
10181 + h_path.mnt = au_br_mnt(br);
10182 + err = vfsub_mnt_want_write(h_path.mnt);
10185 + hdir = au_hi(dir, btop);
10186 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10187 + h_dir = au_h_iptr(dir, btop);
10188 + if (h_dir->i_nlink
10189 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10190 + dt.dt_h_path = h_path;
10191 + au_dtime_revert(&dt);
10193 + au_hn_inode_unlock(hdir);
10194 + vfsub_mnt_drop_write(h_path.mnt);
10195 + au_cpup_attr_timesizes(dir);
10198 + aufs_read_unlock(a->dentry, AuLock_DW);
10201 + au_nwt_done(&au_sbi(sb)->si_nowait);
10202 + au_kfree_try_rcu(arg);
10205 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10207 + int perm, wkq_err;
10208 + aufs_bindex_t btop;
10209 + struct au_dir_ts_arg *arg;
10210 + struct dentry *dentry;
10211 + struct super_block *sb;
10215 + dentry = d_find_any_alias(dir);
10216 + AuDebugOn(!dentry);
10217 + sb = dentry->d_sb;
10218 + btop = au_ibtop(dir);
10219 + if (btop == bindex) {
10220 + au_cpup_attr_timesizes(dir);
10224 + perm = au_sbr_perm(sb, btop);
10225 + if (!au_br_writable(perm))
10228 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10232 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10233 + arg->brid = au_sbr_id(sb, bindex);
10234 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10235 + if (unlikely(wkq_err)) {
10236 + pr_err("wkq %d\n", wkq_err);
10238 + au_kfree_try_rcu(arg);
10245 +/* ---------------------------------------------------------------------- */
10247 +static int reopen_dir(struct file *file)
10250 + unsigned int flags;
10251 + aufs_bindex_t bindex, btail, btop;
10252 + struct dentry *dentry, *h_dentry;
10253 + struct file *h_file;
10255 + /* open all lower dirs */
10256 + dentry = file->f_path.dentry;
10257 + btop = au_dbtop(dentry);
10258 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10259 + au_set_h_fptr(file, bindex, NULL);
10260 + au_set_fbtop(file, btop);
10262 + btail = au_dbtaildir(dentry);
10263 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10264 + au_set_h_fptr(file, bindex, NULL);
10265 + au_set_fbbot_dir(file, btail);
10267 + flags = vfsub_file_flags(file);
10268 + for (bindex = btop; bindex <= btail; bindex++) {
10269 + h_dentry = au_h_dptr(dentry, bindex);
10272 + h_file = au_hf_dir(file, bindex);
10276 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10277 + err = PTR_ERR(h_file);
10278 + if (IS_ERR(h_file))
10279 + goto out; /* close all? */
10280 + au_set_h_fptr(file, bindex, h_file);
10282 + au_update_figen(file);
10283 + /* todo: necessary? */
10284 + /* file->f_ra = h_file->f_ra; */
10291 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10294 + aufs_bindex_t bindex, btail;
10295 + struct dentry *dentry, *h_dentry;
10296 + struct vfsmount *mnt;
10298 + FiMustWriteLock(file);
10299 + AuDebugOn(h_file);
10302 + mnt = file->f_path.mnt;
10303 + dentry = file->f_path.dentry;
10304 + file->f_version = inode_query_iversion(d_inode(dentry));
10305 + bindex = au_dbtop(dentry);
10306 + au_set_fbtop(file, bindex);
10307 + btail = au_dbtaildir(dentry);
10308 + au_set_fbbot_dir(file, btail);
10309 + for (; !err && bindex <= btail; bindex++) {
10310 + h_dentry = au_h_dptr(dentry, bindex);
10314 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10315 + if (unlikely(err))
10317 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10318 + if (IS_ERR(h_file)) {
10319 + err = PTR_ERR(h_file);
10322 + au_set_h_fptr(file, bindex, h_file);
10324 + au_update_figen(file);
10325 + /* todo: necessary? */
10326 + /* file->f_ra = h_file->f_ra; */
10328 + return 0; /* success */
10331 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10332 + au_set_h_fptr(file, bindex, NULL);
10333 + au_set_fbtop(file, -1);
10334 + au_set_fbbot_dir(file, -1);
10339 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10340 + struct file *file)
10343 + struct super_block *sb;
10344 + struct au_fidir *fidir;
10347 + sb = file->f_path.dentry->d_sb;
10348 + si_read_lock(sb, AuLock_FLUSH);
10349 + fidir = au_fidir_alloc(sb);
10351 + struct au_do_open_args args = {
10352 + .open = do_open_dir,
10355 + err = au_do_open(file, &args);
10356 + if (unlikely(err))
10357 + au_kfree_rcu(fidir);
10359 + si_read_unlock(sb);
10363 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10364 + struct file *file)
10366 + struct au_vdir *vdir_cache;
10367 + struct au_finfo *finfo;
10368 + struct au_fidir *fidir;
10369 + struct au_hfile *hf;
10370 + aufs_bindex_t bindex, bbot;
10372 + finfo = au_fi(file);
10373 + fidir = finfo->fi_hdir;
10375 + au_hbl_del(&finfo->fi_hlist,
10376 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10377 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10379 + au_vdir_free(vdir_cache);
10381 + bindex = finfo->fi_btop;
10382 + if (bindex >= 0) {
10383 + hf = fidir->fd_hfile + bindex;
10385 + * calls fput() instead of filp_close(),
10386 + * since no dnotify or lock for the lower file.
10388 + bbot = fidir->fd_bbot;
10389 + for (; bindex <= bbot; bindex++, hf++)
10391 + au_hfput(hf, /*execed*/0);
10393 + au_kfree_rcu(fidir);
10394 + finfo->fi_hdir = NULL;
10396 + au_finfo_fin(file);
10400 +/* ---------------------------------------------------------------------- */
10402 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10405 + aufs_bindex_t bindex, bbot;
10406 + struct file *h_file;
10409 + bbot = au_fbbot_dir(file);
10410 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10411 + h_file = au_hf_dir(file, bindex);
10413 + err = vfsub_flush(h_file, id);
10418 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10420 + return au_do_flush(file, id, au_do_flush_dir);
10423 +/* ---------------------------------------------------------------------- */
10425 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10428 + aufs_bindex_t bbot, bindex;
10429 + struct inode *inode;
10430 + struct super_block *sb;
10433 + sb = dentry->d_sb;
10434 + inode = d_inode(dentry);
10435 + IMustLock(inode);
10436 + bbot = au_dbbot(dentry);
10437 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10438 + struct path h_path;
10440 + if (au_test_ro(sb, bindex, inode))
10442 + h_path.dentry = au_h_dptr(dentry, bindex);
10443 + if (!h_path.dentry)
10446 + h_path.mnt = au_sbr_mnt(sb, bindex);
10447 + err = vfsub_fsync(NULL, &h_path, datasync);
10453 +static int au_do_fsync_dir(struct file *file, int datasync)
10456 + aufs_bindex_t bbot, bindex;
10457 + struct file *h_file;
10458 + struct super_block *sb;
10459 + struct inode *inode;
10461 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10462 + if (unlikely(err))
10465 + inode = file_inode(file);
10466 + sb = inode->i_sb;
10467 + bbot = au_fbbot_dir(file);
10468 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10469 + h_file = au_hf_dir(file, bindex);
10470 + if (!h_file || au_test_ro(sb, bindex, inode))
10473 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10481 + * @file may be NULL
10483 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10487 + struct dentry *dentry;
10488 + struct inode *inode;
10489 + struct super_block *sb;
10492 + dentry = file->f_path.dentry;
10493 + inode = d_inode(dentry);
10494 + inode_lock(inode);
10495 + sb = dentry->d_sb;
10496 + si_noflush_read_lock(sb);
10498 + err = au_do_fsync_dir(file, datasync);
10500 + di_write_lock_child(dentry);
10501 + err = au_do_fsync_dir_no_file(dentry, datasync);
10503 + au_cpup_attr_timesizes(inode);
10504 + di_write_unlock(dentry);
10506 + fi_write_unlock(file);
10508 + si_read_unlock(sb);
10509 + inode_unlock(inode);
10513 +/* ---------------------------------------------------------------------- */
10515 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10518 + struct dentry *dentry;
10519 + struct inode *inode, *h_inode;
10520 + struct super_block *sb;
10522 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10524 + dentry = file->f_path.dentry;
10525 + inode = d_inode(dentry);
10526 + IMustLock(inode);
10528 + sb = dentry->d_sb;
10529 + si_read_lock(sb, AuLock_FLUSH);
10530 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10531 + if (unlikely(err))
10533 + err = au_alive_dir(dentry);
10535 + err = au_vdir_init(file);
10536 + di_downgrade_lock(dentry, AuLock_IR);
10537 + if (unlikely(err))
10540 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10541 + if (!au_test_nfsd()) {
10542 + err = au_vdir_fill_de(file, ctx);
10543 + fsstack_copy_attr_atime(inode, h_inode);
10546 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10547 + * encode_fh() and others.
10549 + atomic_inc(&h_inode->i_count);
10550 + di_read_unlock(dentry, AuLock_IR);
10551 + si_read_unlock(sb);
10552 + err = au_vdir_fill_de(file, ctx);
10553 + fsstack_copy_attr_atime(inode, h_inode);
10554 + fi_write_unlock(file);
10562 + di_read_unlock(dentry, AuLock_IR);
10563 + fi_write_unlock(file);
10565 + si_read_unlock(sb);
10569 +/* ---------------------------------------------------------------------- */
10571 +#define AuTestEmpty_WHONLY 1
10572 +#define AuTestEmpty_CALLED (1 << 1)
10573 +#define AuTestEmpty_SHWH (1 << 2)
10574 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10575 +#define au_fset_testempty(flags, name) \
10576 + do { (flags) |= AuTestEmpty_##name; } while (0)
10577 +#define au_fclr_testempty(flags, name) \
10578 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10580 +#ifndef CONFIG_AUFS_SHWH
10581 +#undef AuTestEmpty_SHWH
10582 +#define AuTestEmpty_SHWH 0
10585 +struct test_empty_arg {
10586 + struct dir_context ctx;
10587 + struct au_nhash *whlist;
10588 + unsigned int flags;
10590 + aufs_bindex_t bindex;
10593 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10594 + int namelen, loff_t offset __maybe_unused, u64 ino,
10595 + unsigned int d_type)
10597 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10599 + char *name = (void *)__name;
10602 + au_fset_testempty(arg->flags, CALLED);
10604 + if (name[0] == '.'
10605 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10606 + goto out; /* success */
10608 + if (namelen <= AUFS_WH_PFX_LEN
10609 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10610 + if (au_ftest_testempty(arg->flags, WHONLY)
10611 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10612 + arg->err = -ENOTEMPTY;
10616 + name += AUFS_WH_PFX_LEN;
10617 + namelen -= AUFS_WH_PFX_LEN;
10618 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10619 + arg->err = au_nhash_append_wh
10620 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10621 + au_ftest_testempty(arg->flags, SHWH));
10625 + AuTraceErr(arg->err);
10629 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10632 + struct file *h_file;
10633 + struct au_branch *br;
10635 + h_file = au_h_open(dentry, arg->bindex,
10636 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10637 + /*file*/NULL, /*force_wr*/0);
10638 + err = PTR_ERR(h_file);
10639 + if (IS_ERR(h_file))
10643 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10644 + && !file_inode(h_file)->i_nlink)
10649 + au_fclr_testempty(arg->flags, CALLED);
10651 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10654 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10658 + br = au_sbr(dentry->d_sb, arg->bindex);
10659 + au_lcnt_dec(&br->br_nfiles);
10664 +struct do_test_empty_args {
10666 + struct dentry *dentry;
10667 + struct test_empty_arg *arg;
10670 +static void call_do_test_empty(void *args)
10672 + struct do_test_empty_args *a = args;
10673 + *a->errp = do_test_empty(a->dentry, a->arg);
10676 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10678 + int err, wkq_err;
10679 + struct dentry *h_dentry;
10680 + struct inode *h_inode;
10682 + h_dentry = au_h_dptr(dentry, arg->bindex);
10683 + h_inode = d_inode(h_dentry);
10684 + /* todo: i_mode changes anytime? */
10685 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10686 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10687 + inode_unlock_shared(h_inode);
10689 + err = do_test_empty(dentry, arg);
10691 + struct do_test_empty_args args = {
10693 + .dentry = dentry,
10696 + unsigned int flags = arg->flags;
10698 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10699 + if (unlikely(wkq_err))
10701 + arg->flags = flags;
10707 +int au_test_empty_lower(struct dentry *dentry)
10710 + unsigned int rdhash;
10711 + aufs_bindex_t bindex, btop, btail;
10712 + struct au_nhash whlist;
10713 + struct test_empty_arg arg = {
10715 + .actor = test_empty_cb
10718 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10720 + SiMustAnyLock(dentry->d_sb);
10722 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10724 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10725 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10726 + if (unlikely(err))
10730 + arg.whlist = &whlist;
10731 + btop = au_dbtop(dentry);
10732 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10733 + au_fset_testempty(arg.flags, SHWH);
10734 + test_empty = do_test_empty;
10735 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10736 + test_empty = sio_test_empty;
10737 + arg.bindex = btop;
10738 + err = test_empty(dentry, &arg);
10739 + if (unlikely(err))
10742 + au_fset_testempty(arg.flags, WHONLY);
10743 + btail = au_dbtaildir(dentry);
10744 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10745 + struct dentry *h_dentry;
10747 + h_dentry = au_h_dptr(dentry, bindex);
10748 + if (h_dentry && d_is_positive(h_dentry)) {
10749 + arg.bindex = bindex;
10750 + err = test_empty(dentry, &arg);
10755 + au_nhash_wh_free(&whlist);
10760 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10763 + struct test_empty_arg arg = {
10765 + .actor = test_empty_cb
10768 + aufs_bindex_t bindex, btail;
10771 + arg.whlist = whlist;
10772 + arg.flags = AuTestEmpty_WHONLY;
10773 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10774 + au_fset_testempty(arg.flags, SHWH);
10775 + btail = au_dbtaildir(dentry);
10776 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10777 + struct dentry *h_dentry;
10779 + h_dentry = au_h_dptr(dentry, bindex);
10780 + if (h_dentry && d_is_positive(h_dentry)) {
10781 + arg.bindex = bindex;
10782 + err = sio_test_empty(dentry, &arg);
10789 +/* ---------------------------------------------------------------------- */
10791 +const struct file_operations aufs_dir_fop = {
10792 + .owner = THIS_MODULE,
10793 + .llseek = default_llseek,
10794 + .read = generic_read_dir,
10795 + .iterate_shared = aufs_iterate_shared,
10796 + .unlocked_ioctl = aufs_ioctl_dir,
10797 +#ifdef CONFIG_COMPAT
10798 + .compat_ioctl = aufs_compat_ioctl_dir,
10800 + .open = aufs_open_dir,
10801 + .release = aufs_release_dir,
10802 + .flush = aufs_flush_dir,
10803 + .fsync = aufs_fsync_dir
10805 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10806 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10807 +++ linux/fs/aufs/dir.h 2020-08-03 09:14:46.095748745 +0200
10809 +/* SPDX-License-Identifier: GPL-2.0 */
10811 + * Copyright (C) 2005-2020 Junjiro R. Okajima
10813 + * This program, aufs is free software; you can redistribute it and/or modify
10814 + * it under the terms of the GNU General Public License as published by
10815 + * the Free Software Foundation; either version 2 of the License, or
10816 + * (at your option) any later version.
10818 + * This program is distributed in the hope that it will be useful,
10819 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10820 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10821 + * GNU General Public License for more details.
10823 + * You should have received a copy of the GNU General Public License
10824 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10828 + * directory operations
10831 +#ifndef __AUFS_DIR_H__
10832 +#define __AUFS_DIR_H__
10836 +#include <linux/fs.h>
10838 +/* ---------------------------------------------------------------------- */
10840 +/* need to be faster and smaller */
10843 + unsigned int nh_num;
10844 + struct hlist_head *nh_head;
10847 +struct au_vdir_destr {
10848 + unsigned char len;
10849 + unsigned char name[];
10852 +struct au_vdir_dehstr {
10853 + struct hlist_node hash;
10854 + struct au_vdir_destr *str;
10855 + struct rcu_head rcu;
10856 +} ____cacheline_aligned_in_smp;
10858 +struct au_vdir_de {
10860 + unsigned char de_type;
10861 + /* caution: packed */
10862 + struct au_vdir_destr de_str;
10865 +struct au_vdir_wh {
10866 + struct hlist_node wh_hash;
10867 +#ifdef CONFIG_AUFS_SHWH
10869 + aufs_bindex_t wh_bindex;
10870 + unsigned char wh_type;
10872 + aufs_bindex_t wh_bindex;
10874 + /* caution: packed */
10875 + struct au_vdir_destr wh_str;
10878 +union au_vdir_deblk_p {
10879 + unsigned char *deblk;
10880 + struct au_vdir_de *de;
10884 + unsigned char **vd_deblk;
10885 + unsigned long vd_nblk;
10887 + unsigned long ul;
10888 + union au_vdir_deblk_p p;
10892 + unsigned int vd_deblk_sz;
10893 + unsigned long vd_jiffy;
10894 + struct rcu_head rcu;
10895 +} ____cacheline_aligned_in_smp;
10897 +/* ---------------------------------------------------------------------- */
10900 +extern const struct file_operations aufs_dir_fop;
10901 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10902 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10903 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10904 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10905 +int au_test_empty_lower(struct dentry *dentry);
10906 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10909 +unsigned int au_rdhash_est(loff_t sz);
10910 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10911 +void au_nhash_wh_free(struct au_nhash *whlist);
10912 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10914 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10915 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10916 + unsigned int d_type, aufs_bindex_t bindex,
10917 + unsigned char shwh);
10918 +void au_vdir_free(struct au_vdir *vdir);
10919 +int au_vdir_init(struct file *file);
10920 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10923 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10925 +#ifdef CONFIG_AUFS_RDU
10927 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10928 +#ifdef CONFIG_COMPAT
10929 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10930 + unsigned long arg);
10933 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10934 + unsigned int cmd, unsigned long arg)
10935 +#ifdef CONFIG_COMPAT
10936 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10937 + unsigned int cmd, unsigned long arg)
10941 +#endif /* __KERNEL__ */
10942 +#endif /* __AUFS_DIR_H__ */
10943 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10944 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10945 +++ linux/fs/aufs/dirren.c 2020-08-03 09:14:46.095748745 +0200
10947 +// SPDX-License-Identifier: GPL-2.0
10949 + * Copyright (C) 2017-2020 Junjiro R. Okajima
10951 + * This program, aufs is free software; you can redistribute it and/or modify
10952 + * it under the terms of the GNU General Public License as published by
10953 + * the Free Software Foundation; either version 2 of the License, or
10954 + * (at your option) any later version.
10956 + * This program is distributed in the hope that it will be useful,
10957 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10958 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10959 + * GNU General Public License for more details.
10961 + * You should have received a copy of the GNU General Public License
10962 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10966 + * special handling in renaming a directory
10967 + * in order to support looking-up the before-renamed name on the lower readonly
10971 +#include <linux/byteorder/generic.h>
10974 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10978 + idx = au_dr_ihash(ent->dr_h_ino);
10979 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10982 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10985 + struct hlist_bl_head *hbl;
10988 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10989 + hbl = dr->dr_h_ino + i;
10990 + hlist_bl_lock(hbl);
10991 + ret &= hlist_bl_empty(hbl);
10992 + hlist_bl_unlock(hbl);
10998 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
11000 + struct au_dr_hino *found, *ent;
11001 + struct hlist_bl_head *hbl;
11002 + struct hlist_bl_node *pos;
11006 + idx = au_dr_ihash(ino);
11007 + hbl = dr->dr_h_ino + idx;
11008 + hlist_bl_lock(hbl);
11009 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11010 + if (ent->dr_h_ino == ino) {
11014 + hlist_bl_unlock(hbl);
11019 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
11020 + struct au_dr_hino *add_ent)
11023 + struct hlist_bl_head *hbl;
11024 + struct hlist_bl_node *pos;
11025 + struct au_dr_hino *ent;
11028 + idx = au_dr_ihash(ino);
11029 + hbl = dr->dr_h_ino + idx;
11030 +#if 0 /* debug print */
11032 + struct hlist_bl_node *tmp;
11034 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11035 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
11038 + hlist_bl_lock(hbl);
11039 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11040 + if (ent->dr_h_ino == ino) {
11044 + if (!found && add_ent)
11045 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
11046 + hlist_bl_unlock(hbl);
11048 + if (!found && add_ent)
11049 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
11054 +void au_dr_hino_free(struct au_dr_br *dr)
11057 + struct hlist_bl_head *hbl;
11058 + struct hlist_bl_node *pos, *tmp;
11059 + struct au_dr_hino *ent;
11061 + /* SiMustWriteLock(sb); */
11063 + for (i = 0; i < AuDirren_NHASH; i++) {
11064 + hbl = dr->dr_h_ino + i;
11065 + /* no spinlock since sbinfo must be write-locked */
11066 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11067 + au_kfree_rcu(ent);
11068 + INIT_HLIST_BL_HEAD(hbl);
11072 +/* returns the number of inodes or an error */
11073 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11074 + struct file *hinofile)
11078 + loff_t pos, oldsize;
11080 + struct inode *hinoinode;
11081 + struct hlist_bl_head *hbl;
11082 + struct hlist_bl_node *n1, *n2;
11083 + struct au_dr_hino *ent;
11085 + SiMustWriteLock(sb);
11086 + AuDebugOn(!au_br_writable(br->br_perm));
11088 + hinoinode = file_inode(hinofile);
11089 + oldsize = i_size_read(hinoinode);
11093 + hbl = br->br_dirren.dr_h_ino;
11094 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11095 + /* no bit-lock since sbinfo must be write-locked */
11096 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11097 + AuDbg("hi%llu, %pD2\n",
11098 + (unsigned long long)ent->dr_h_ino, hinofile);
11099 + u64 = cpu_to_be64(ent->dr_h_ino);
11100 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11101 + if (ssz == sizeof(u64))
11104 + /* write error */
11105 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11112 + /* regardless the error */
11113 + if (pos < oldsize) {
11114 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11122 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11129 + struct au_dr_hino *ent;
11130 + struct inode *hinoinode;
11131 + struct hlist_bl_head *hbl;
11135 + hbl = dr->dr_h_ino;
11136 + hinoinode = file_inode(hinofile);
11137 + sz = i_size_read(hinoinode);
11138 + AuDebugOn(sz % sizeof(u64));
11139 + n = sz / sizeof(u64);
11141 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11142 + if (unlikely(ssz != sizeof(u64))) {
11143 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11150 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11156 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11157 + AuDbg("hi%llu, %pD2\n",
11158 + (unsigned long long)ent->dr_h_ino, hinofile);
11159 + hidx = au_dr_ihash(ent->dr_h_ino);
11160 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11162 + goto out; /* success */
11165 + au_dr_hino_free(dr);
11172 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11173 + * @path is a switch to distinguish load and store.
11175 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11176 + struct au_branch *br, const struct path *path)
11179 + unsigned char load, suspend;
11180 + struct file *hinofile;
11181 + struct au_hinode *hdir;
11182 + struct inode *dir, *delegated;
11183 + struct path hinopath;
11184 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11185 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11187 + AuDebugOn(bindex < 0 && !br);
11188 + AuDebugOn(bindex >= 0 && br);
11193 + br = au_sbr(sb, bindex);
11196 + path = &br->br_path;
11197 + AuDebugOn(!au_br_writable(br->br_perm));
11198 + if (unlikely(!au_br_writable(br->br_perm)))
11204 + dir = d_inode(sb->s_root);
11205 + hdir = au_hinode(au_ii(dir), bindex);
11206 + dir = hdir->hi_inode;
11207 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11209 + dir = d_inode(path->dentry);
11210 + inode_lock_nested(dir, AuLsc_I_CHILD);
11212 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11213 + err = PTR_ERR(hinopath.dentry);
11214 + if (IS_ERR(hinopath.dentry))
11218 + flags = O_RDONLY;
11220 + if (d_is_negative(hinopath.dentry))
11221 + goto out_dput; /* success */
11223 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11224 + if (d_is_positive(hinopath.dentry)) {
11225 + delegated = NULL;
11226 + err = vfsub_unlink(dir, &hinopath, &delegated,
11229 + if (unlikely(err))
11230 + pr_err("ignored err %d, %pd2\n",
11231 + err, hinopath.dentry);
11232 + if (unlikely(err == -EWOULDBLOCK))
11237 + } else if (!d_is_positive(hinopath.dentry)) {
11238 + err = vfsub_create(dir, &hinopath, 0600,
11239 + /*want_excl*/false);
11241 + if (unlikely(err))
11244 + flags = O_WRONLY;
11246 + hinopath.mnt = path->mnt;
11247 + hinofile = vfsub_dentry_open(&hinopath, flags);
11249 + au_hn_inode_unlock(hdir);
11251 + inode_unlock(dir);
11252 + dput(hinopath.dentry);
11253 + AuTraceErrPtr(hinofile);
11254 + if (IS_ERR(hinofile)) {
11255 + err = PTR_ERR(hinofile);
11260 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11262 + err = au_dr_hino_store(sb, br, hinofile);
11267 + dput(hinopath.dentry);
11270 + au_hn_inode_unlock(hdir);
11272 + inode_unlock(dir);
11278 +/* ---------------------------------------------------------------------- */
11280 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11283 + struct kstatfs kstfs;
11285 + struct dentry *dentry;
11286 + struct super_block *sb;
11288 + err = vfs_statfs((void *)path, &kstfs);
11290 + if (unlikely(err))
11293 + /* todo: support for UUID */
11295 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11296 + brid->type = AuBrid_FSID;
11297 + brid->fsid = kstfs.f_fsid;
11299 + dentry = path->dentry;
11300 + sb = dentry->d_sb;
11303 + brid->type = AuBrid_DEV;
11312 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11313 + const struct path *path)
11316 + struct au_dr_br *dr;
11317 + struct hlist_bl_head *hbl;
11319 + dr = &br->br_dirren;
11320 + hbl = dr->dr_h_ino;
11321 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11322 + INIT_HLIST_BL_HEAD(hbl);
11324 + err = au_dr_brid_init(&dr->dr_brid, path);
11325 + if (unlikely(err))
11328 + if (au_opt_test(au_mntflags(sb), DIRREN))
11329 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11336 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11341 + if (au_br_writable(br->br_perm))
11342 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11344 + au_dr_hino_free(&br->br_dirren);
11349 +/* ---------------------------------------------------------------------- */
11351 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11352 + char *buf, size_t sz)
11355 + unsigned int major, minor;
11359 + err = snprintf(p, sz, "%d_", brid->type);
11360 + AuDebugOn(err > sz);
11363 + switch (brid->type) {
11364 + case AuBrid_Unset:
11366 + case AuBrid_UUID:
11367 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11369 + case AuBrid_FSID:
11370 + err = snprintf(p, sz, "%08x-%08x",
11371 + brid->fsid.val[0], brid->fsid.val[1]);
11374 + major = MAJOR(brid->dev);
11375 + minor = MINOR(brid->dev);
11376 + if (major <= 0xff && minor <= 0xff)
11377 + err = snprintf(p, sz, "%02x%02x", major, minor);
11379 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11382 + AuDebugOn(err > sz);
11385 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11386 + AuDebugOn(err > sz);
11393 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11396 + struct dentry *br_dentry;
11397 + struct inode *br_inode;
11399 + br_dentry = au_br_dentry(br);
11400 + br_inode = d_inode(br_dentry);
11401 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11402 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11403 + AuDebugOn(rlen > len);
11408 +/* ---------------------------------------------------------------------- */
11411 + * from the given @h_dentry, construct drinfo at @*fdata.
11412 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11415 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11416 + struct dentry *h_dentry,
11417 + unsigned char *allocated)
11420 + struct au_drinfo_fdata *f, *p;
11421 + struct au_drinfo *drinfo;
11422 + struct inode *h_inode;
11423 + struct qstr *qname;
11427 + h_inode = d_inode(h_dentry);
11428 + qname = &h_dentry->d_name;
11429 + drinfo = &f->drinfo;
11430 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11431 + drinfo->oldnamelen = qname->len;
11432 + if (*allocated < sizeof(*f) + qname->len) {
11433 + v = roundup_pow_of_two(*allocated + qname->len);
11434 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11435 + if (unlikely(!p)) {
11443 + drinfo = &f->drinfo;
11445 + memcpy(drinfo->oldname, qname->name, qname->len);
11446 + AuDbg("i%llu, %.*s\n",
11447 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11448 + drinfo->oldname);
11455 +/* callers have to free the return value */
11456 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11458 + struct au_drinfo *ret, *drinfo;
11459 + struct au_drinfo_fdata fdata;
11464 + ret = ERR_PTR(-EIO);
11466 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11467 + if (unlikely(ssz != sizeof(fdata))) {
11468 + AuIOErr("ssz %zd, %u, %pD2\n",
11469 + ssz, (unsigned int)sizeof(fdata), file);
11473 + fdata.magic = ntohl((__force __be32)fdata.magic);
11474 + switch (fdata.magic) {
11475 + case AUFS_DRINFO_MAGIC_V1:
11478 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11479 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11483 + drinfo = &fdata.drinfo;
11484 + len = drinfo->oldnamelen;
11486 + AuIOErr("broken drinfo %pD2\n", file);
11491 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11492 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11493 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11494 + (unsigned long long)drinfo->ino,
11495 + (unsigned long long)h_ino, file);
11496 + goto out; /* success */
11499 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11500 + if (unlikely(!ret)) {
11501 + ret = ERR_PTR(-ENOMEM);
11502 + AuTraceErrPtr(ret);
11507 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11508 + if (unlikely(ssz != len)) {
11509 + au_kfree_rcu(ret);
11510 + ret = ERR_PTR(-EIO);
11511 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11515 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11521 +/* ---------------------------------------------------------------------- */
11523 +/* in order to be revertible */
11524 +struct au_drinfo_rev_elm {
11526 + struct dentry *info_dentry;
11527 + struct au_drinfo *info_last;
11530 +struct au_drinfo_rev {
11531 + unsigned char already;
11532 + aufs_bindex_t nelm;
11533 + struct au_drinfo_rev_elm elm[];
11536 +/* todo: isn't it too large? */
11537 +struct au_drinfo_store {
11538 + struct path h_ppath;
11539 + struct dentry *h_dentry;
11540 + struct au_drinfo_fdata *fdata;
11541 + char *infoname; /* inside of whname, just after PFX */
11542 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11543 + aufs_bindex_t btgt, btail;
11544 + unsigned char no_sio,
11545 + allocated, /* current size of *fdata */
11546 + infonamelen, /* room size for p */
11547 + whnamelen, /* length of the generated name */
11548 + renameback; /* renamed back */
11551 +/* on rename(2) error, the caller should revert it using @elm */
11552 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11553 + struct au_drinfo_rev_elm *elm)
11558 + struct path infopath = {
11559 + .mnt = w->h_ppath.mnt
11561 + struct inode *h_dir, *h_inode, *delegated;
11562 + struct file *infofile;
11563 + struct qstr *qname;
11566 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11568 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11570 + AuTraceErrPtr(infopath.dentry);
11571 + if (IS_ERR(infopath.dentry)) {
11572 + err = PTR_ERR(infopath.dentry);
11577 + h_dir = d_inode(w->h_ppath.dentry);
11578 + if (elm && d_is_negative(infopath.dentry)) {
11579 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11581 + if (unlikely(err))
11583 + elm->created = 1;
11584 + elm->info_dentry = dget(infopath.dentry);
11587 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11588 + AuTraceErrPtr(infofile);
11589 + if (IS_ERR(infofile)) {
11590 + err = PTR_ERR(infofile);
11594 + h_inode = d_inode(infopath.dentry);
11595 + if (elm && i_size_read(h_inode)) {
11596 + h_inode = d_inode(w->h_dentry);
11597 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11598 + AuTraceErrPtr(elm->info_last);
11599 + if (IS_ERR(elm->info_last)) {
11600 + err = PTR_ERR(elm->info_last);
11601 + elm->info_last = NULL;
11602 + AuDebugOn(elm->info_dentry);
11607 + if (elm && w->renameback) {
11608 + delegated = NULL;
11609 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11611 + if (unlikely(err == -EWOULDBLOCK))
11617 + qname = &w->h_dentry->d_name;
11618 + len = sizeof(*w->fdata) + qname->len;
11620 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11621 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11622 + if (ssz == len) {
11623 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11624 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11625 + goto out_fput; /* success */
11630 + /* the caller should revert it using @elm */
11636 + dput(infopath.dentry);
11642 +struct au_call_drinfo_do_store_args {
11644 + struct au_drinfo_store *w;
11645 + struct au_drinfo_rev_elm *elm;
11648 +static void au_call_drinfo_do_store(void *args)
11650 + struct au_call_drinfo_do_store_args *a = args;
11652 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11655 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11656 + struct au_drinfo_rev_elm *elm)
11658 + int err, wkq_err;
11661 + err = au_drinfo_do_store(w, elm);
11663 + struct au_call_drinfo_do_store_args a = {
11668 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11669 + if (unlikely(wkq_err))
11677 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11678 + aufs_bindex_t btgt)
11682 + memset(w, 0, sizeof(*w));
11683 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11684 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11685 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11686 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11688 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11691 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11692 + if (unlikely(!w->fdata)) {
11696 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11703 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11705 + au_kfree_rcu(w->fdata);
11708 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11709 + struct au_drinfo_store *w)
11711 + struct au_drinfo_rev_elm *elm;
11712 + struct inode *h_dir, *delegated;
11714 + struct path infopath = {
11715 + .mnt = w->h_ppath.mnt
11718 + h_dir = d_inode(w->h_ppath.dentry);
11719 + IMustLock(h_dir);
11723 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11724 + AuDebugOn(elm->created && elm->info_last);
11725 + if (elm->created) {
11727 + delegated = NULL;
11728 + infopath.dentry = elm->info_dentry;
11729 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11732 + if (unlikely(err == -EWOULDBLOCK))
11734 + dput(elm->info_dentry);
11735 + } else if (elm->info_last) {
11737 + w->fdata->drinfo = *elm->info_last;
11738 + memcpy(w->fdata->drinfo.oldname,
11739 + elm->info_last->oldname,
11740 + elm->info_last->oldnamelen);
11741 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11742 + au_kfree_rcu(elm->info_last);
11744 + if (unlikely(err))
11745 + AuIOErr("%d, %s\n", err, w->whname);
11746 + /* go on even if err */
11750 +/* caller has to call au_dr_rename_fin() later */
11751 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11752 + struct qstr *dst_name, void *_rev)
11754 + int err, sz, nelm;
11755 + aufs_bindex_t bindex, btail;
11756 + struct au_drinfo_store work;
11757 + struct au_drinfo_rev *rev, **p;
11758 + struct au_drinfo_rev_elm *elm;
11759 + struct super_block *sb;
11760 + struct au_branch *br;
11761 + struct au_hinode *hdir;
11763 + err = au_drinfo_store_work_init(&work, btgt);
11765 + if (unlikely(err))
11769 + btail = au_dbtaildir(dentry);
11770 + nelm = btail - btgt;
11771 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11772 + rev = kcalloc(1, sz, GFP_NOFS);
11773 + if (unlikely(!rev)) {
11777 + rev->nelm = nelm;
11783 + sb = dentry->d_sb;
11784 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11785 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11786 + hdir = au_hi(d_inode(dentry), btgt);
11787 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11788 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11789 + work.h_dentry = au_h_dptr(dentry, bindex);
11790 + if (!work.h_dentry)
11793 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11794 + &work.allocated);
11796 + if (unlikely(err))
11799 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11800 + br = au_sbr(sb, bindex);
11801 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11802 + work.whnamelen += au_drinfo_name(br, work.infoname,
11803 + work.infonamelen);
11804 + AuDbg("whname %.*s, i%llu, %.*s\n",
11805 + work.whnamelen, work.whname,
11806 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11807 + work.fdata->drinfo.oldnamelen,
11808 + work.fdata->drinfo.oldname);
11810 + err = au_drinfo_store_sio(&work, elm);
11812 + if (unlikely(err))
11815 + if (unlikely(err)) {
11816 + /* revert all drinfo */
11817 + au_drinfo_store_rev(rev, &work);
11818 + au_kfree_try_rcu(rev);
11821 + au_hn_inode_unlock(hdir);
11824 + au_drinfo_store_work_fin(&work);
11829 +/* ---------------------------------------------------------------------- */
11831 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11832 + struct qstr *dst_name, void *_rev)
11834 + int err, already;
11836 + struct super_block *sb;
11837 + struct au_branch *br;
11838 + struct au_dr_br *dr;
11839 + struct dentry *h_dentry;
11840 + struct inode *h_inode;
11841 + struct au_dr_hino *ent;
11842 + struct au_drinfo_rev *rev, **p;
11844 + AuDbg("bindex %d\n", bindex);
11847 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11848 + if (unlikely(!ent))
11852 + br = au_sbr(sb, bindex);
11853 + dr = &br->br_dirren;
11854 + h_dentry = au_h_dptr(src, bindex);
11855 + h_inode = d_inode(h_dentry);
11856 + ino = h_inode->i_ino;
11857 + ent->dr_h_ino = ino;
11858 + already = au_dr_hino_test_add(dr, ino, ent);
11859 + AuDbg("b%d, hi%llu, already %d\n",
11860 + bindex, (unsigned long long)ino, already);
11862 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11867 + rev->already = already;
11868 + goto out; /* success */
11873 + au_dr_hino_del(dr, ent);
11874 + au_kfree_rcu(ent);
11881 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11883 + struct au_drinfo_rev *rev;
11884 + struct au_drinfo_rev_elm *elm;
11889 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11890 + dput(elm->info_dentry);
11891 + au_kfree_rcu(elm->info_last);
11893 + au_kfree_try_rcu(rev);
11896 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11899 + struct au_drinfo_store work;
11900 + struct au_drinfo_rev *rev = _rev;
11901 + struct super_block *sb;
11902 + struct au_branch *br;
11903 + struct inode *h_inode;
11904 + struct au_dr_br *dr;
11905 + struct au_dr_hino *ent;
11907 + err = au_drinfo_store_work_init(&work, btgt);
11908 + if (unlikely(err))
11912 + br = au_sbr(sb, btgt);
11913 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11914 + work.h_ppath.mnt = au_br_mnt(br);
11915 + au_drinfo_store_rev(rev, &work);
11916 + au_drinfo_store_work_fin(&work);
11917 + if (rev->already)
11920 + dr = &br->br_dirren;
11921 + h_inode = d_inode(work.h_ppath.dentry);
11922 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11924 + au_dr_hino_del(dr, ent);
11925 + au_kfree_rcu(ent);
11928 + au_kfree_try_rcu(rev);
11929 + if (unlikely(err))
11930 + pr_err("failed to remove dirren info\n");
11933 +/* ---------------------------------------------------------------------- */
11935 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11936 + char *whname, int whnamelen,
11937 + struct dentry **info_dentry)
11939 + struct au_drinfo *drinfo;
11941 + struct inode *h_dir;
11942 + struct path infopath;
11945 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11947 + *info_dentry = NULL;
11950 + h_dir = d_inode(h_ppath->dentry);
11951 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11952 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
11954 + if (IS_ERR(infopath.dentry)) {
11955 + drinfo = (void *)infopath.dentry;
11959 + if (d_is_negative(infopath.dentry))
11960 + goto out_dput; /* success */
11962 + infopath.mnt = h_ppath->mnt;
11963 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11964 + inode_unlock_shared(h_dir);
11967 + drinfo = (void *)f;
11971 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11972 + if (IS_ERR_OR_NULL(drinfo))
11975 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11976 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11981 + dput(infopath.dentry);
11984 + inode_unlock_shared(h_dir);
11985 + AuTraceErrPtr(drinfo);
11989 +struct au_drinfo_do_load_args {
11990 + struct au_drinfo **drinfop;
11991 + struct path *h_ppath;
11994 + struct dentry **info_dentry;
11997 +static void au_call_drinfo_do_load(void *args)
11999 + struct au_drinfo_do_load_args *a = args;
12001 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
12005 +struct au_drinfo_load {
12006 + struct path h_ppath;
12007 + struct qstr *qname;
12008 + unsigned char no_sio;
12010 + aufs_bindex_t ninfo;
12011 + struct au_drinfo **drinfo;
12014 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
12015 + struct au_branch *br)
12017 + int err, wkq_err, whnamelen, e;
12018 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
12019 + = AUFS_WH_DR_INFO_PFX;
12020 + struct au_drinfo *drinfo;
12021 + struct qstr oldname;
12022 + struct inode *h_dir, *delegated;
12023 + struct dentry *info_dentry;
12024 + struct path infopath;
12026 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
12027 + whnamelen += au_drinfo_name(br, whname + whnamelen,
12028 + sizeof(whname) - whnamelen);
12030 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
12033 + struct au_drinfo_do_load_args args = {
12034 + .drinfop = &drinfo,
12035 + .h_ppath = &w->h_ppath,
12036 + .whname = whname,
12037 + .whnamelen = whnamelen,
12038 + .info_dentry = &info_dentry
12040 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
12041 + if (unlikely(wkq_err))
12042 + drinfo = ERR_PTR(wkq_err);
12044 + err = PTR_ERR(drinfo);
12045 + if (IS_ERR_OR_NULL(drinfo))
12049 + oldname.len = drinfo->oldnamelen;
12050 + oldname.name = drinfo->oldname;
12051 + if (au_qstreq(w->qname, &oldname)) {
12052 + /* the name is renamed back */
12053 + au_kfree_rcu(drinfo);
12056 + infopath.dentry = info_dentry;
12057 + infopath.mnt = w->h_ppath.mnt;
12058 + h_dir = d_inode(w->h_ppath.dentry);
12059 + delegated = NULL;
12060 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
12061 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
12062 + inode_unlock(h_dir);
12064 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
12065 + if (unlikely(e == -EWOULDBLOCK))
12068 + au_kfree_rcu(w->drinfo[bindex]);
12069 + w->drinfo[bindex] = drinfo;
12070 + dput(info_dentry);
12077 +/* ---------------------------------------------------------------------- */
12079 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12081 + struct au_drinfo **p = drinfo;
12084 + au_kfree_rcu(*drinfo++);
12085 + au_kfree_try_rcu(p);
12088 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12089 + aufs_bindex_t btgt)
12092 + struct au_drinfo_load w;
12093 + aufs_bindex_t bindex, bbot;
12094 + struct au_branch *br;
12095 + struct inode *h_dir;
12096 + struct au_dr_hino *ent;
12097 + struct super_block *sb;
12099 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12100 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12101 + AuLNPair(&lkup->whname), btgt);
12103 + sb = dentry->d_sb;
12104 + bbot = au_sbbot(sb);
12105 + w.ninfo = bbot + 1;
12106 + if (!lkup->dirren.drinfo) {
12107 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12108 + sizeof(*lkup->dirren.drinfo),
12110 + if (unlikely(!lkup->dirren.drinfo)) {
12114 + lkup->dirren.ninfo = w.ninfo;
12116 + w.drinfo = lkup->dirren.drinfo;
12117 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12118 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12119 + AuDebugOn(!w.h_ppath.dentry);
12120 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12121 + w.qname = &dentry->d_name;
12124 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12125 + br = au_sbr(sb, bindex);
12126 + err = au_drinfo_load(&w, bindex, br);
12127 + if (unlikely(err))
12129 + if (w.drinfo[bindex])
12133 + br = au_sbr(sb, btgt);
12134 + h_dir = d_inode(w.h_ppath.dentry);
12135 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12137 + au_dr_hino_del(&br->br_dirren, ent);
12138 + au_kfree_rcu(ent);
12140 + goto out; /* success */
12143 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12144 + lkup->dirren.ninfo = 0;
12145 + lkup->dirren.drinfo = NULL;
12151 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12153 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12156 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12159 + struct au_drinfo *drinfo;
12162 + if (!lkup->dirren.drinfo)
12164 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12165 + drinfo = lkup->dirren.drinfo[btgt];
12169 + au_kfree_try_rcu(lkup->whname.name);
12170 + lkup->whname.name = NULL;
12171 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12172 + lkup->dirren.dr_name.name = drinfo->oldname;
12173 + lkup->name = &lkup->dirren.dr_name;
12174 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12176 + AuDbg("name %.*s, whname %.*s, b%d\n",
12177 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12185 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12189 + struct au_drinfo *drinfo;
12192 + if (!lkup->dirren.drinfo)
12194 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12195 + drinfo = lkup->dirren.drinfo[bindex];
12199 + match = (drinfo->ino == h_ino);
12200 + AuDbg("match %d\n", match);
12206 +/* ---------------------------------------------------------------------- */
12208 +int au_dr_opt_set(struct super_block *sb)
12211 + aufs_bindex_t bindex, bbot;
12212 + struct au_branch *br;
12215 + bbot = au_sbbot(sb);
12216 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12217 + br = au_sbr(sb, bindex);
12218 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12224 +int au_dr_opt_flush(struct super_block *sb)
12227 + aufs_bindex_t bindex, bbot;
12228 + struct au_branch *br;
12231 + bbot = au_sbbot(sb);
12232 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12233 + br = au_sbr(sb, bindex);
12234 + if (au_br_writable(br->br_perm))
12235 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12241 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12244 + aufs_bindex_t bindex, bbot;
12245 + struct au_branch *br;
12249 + err = au_dr_opt_flush(sb);
12250 + if (unlikely(err))
12254 + bbot = au_sbbot(sb);
12255 + for (bindex = 0; bindex <= bbot; bindex++) {
12256 + br = au_sbr(sb, bindex);
12257 + au_dr_hino_free(&br->br_dirren);
12263 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12264 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12265 +++ linux/fs/aufs/dirren.h 2020-01-27 10:57:18.168871450 +0100
12267 +/* SPDX-License-Identifier: GPL-2.0 */
12269 + * Copyright (C) 2017-2020 Junjiro R. Okajima
12271 + * This program, aufs is free software; you can redistribute it and/or modify
12272 + * it under the terms of the GNU General Public License as published by
12273 + * the Free Software Foundation; either version 2 of the License, or
12274 + * (at your option) any later version.
12276 + * This program is distributed in the hope that it will be useful,
12277 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12278 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12279 + * GNU General Public License for more details.
12281 + * You should have received a copy of the GNU General Public License
12282 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12286 + * renamed dir info
12289 +#ifndef __AUFS_DIRREN_H__
12290 +#define __AUFS_DIRREN_H__
12294 +#include <linux/dcache.h>
12295 +#include <linux/statfs.h>
12296 +#include <linux/uuid.h>
12299 +#define AuDirren_NHASH 100
12301 +#ifdef CONFIG_AUFS_DIRREN
12302 +enum au_brid_type {
12309 +struct au_dr_brid {
12310 + enum au_brid_type type;
12312 + uuid_t uuid; /* unimplemented yet */
12318 +/* 20 is the max digits length of ulong 64 */
12319 +/* brid-type "_" uuid "_" inum */
12320 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12321 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12323 +struct au_dr_hino {
12324 + struct hlist_bl_node dr_hnode;
12329 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12330 + struct au_dr_brid dr_brid;
12333 +struct au_dr_lookup {
12334 + /* dr_name is pointed by struct au_do_lookup_args.name */
12335 + struct qstr dr_name; /* subset of dr_info */
12336 + aufs_bindex_t ninfo;
12337 + struct au_drinfo **drinfo;
12340 +struct au_dr_hino;
12342 +struct au_dr_br { };
12343 +struct au_dr_lookup { };
12346 +/* ---------------------------------------------------------------------- */
12349 +struct au_do_lookup_args;
12351 +#ifdef CONFIG_AUFS_DIRREN
12352 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12353 + struct au_dr_hino *add_ent);
12354 +void au_dr_hino_free(struct au_dr_br *dr);
12355 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12356 + const struct path *path);
12357 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12358 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12359 + struct qstr *dst_name, void *_rev);
12360 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12361 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12362 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12363 + aufs_bindex_t bindex);
12364 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12365 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12367 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12368 +int au_dr_opt_set(struct super_block *sb);
12369 +int au_dr_opt_flush(struct super_block *sb);
12370 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12372 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12373 + struct au_dr_hino *add_ent);
12374 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12375 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12376 + const struct path *path);
12377 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12378 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12379 + struct qstr *dst_name, void *_rev);
12380 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12381 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12383 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12384 + aufs_bindex_t bindex);
12385 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12386 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12387 + aufs_bindex_t bindex, ino_t h_ino);
12388 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12389 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12390 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12391 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12394 +/* ---------------------------------------------------------------------- */
12396 +#ifdef CONFIG_AUFS_DIRREN
12397 +static inline int au_dr_ihash(ino_t h_ino)
12399 + return h_ino % AuDirren_NHASH;
12402 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12405 +#endif /* __KERNEL__ */
12406 +#endif /* __AUFS_DIRREN_H__ */
12407 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12408 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12409 +++ linux/fs/aufs/dynop.c 2020-01-27 10:57:18.168871450 +0100
12411 +// SPDX-License-Identifier: GPL-2.0
12413 + * Copyright (C) 2010-2020 Junjiro R. Okajima
12415 + * This program, aufs is free software; you can redistribute it and/or modify
12416 + * it under the terms of the GNU General Public License as published by
12417 + * the Free Software Foundation; either version 2 of the License, or
12418 + * (at your option) any later version.
12420 + * This program is distributed in the hope that it will be useful,
12421 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12422 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12423 + * GNU General Public License for more details.
12425 + * You should have received a copy of the GNU General Public License
12426 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12430 + * dynamically customizable operations for regular files
12435 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12438 + * How large will these lists be?
12439 + * Usually just a few elements, 20-30 at most for each, I guess.
12441 +static struct hlist_bl_head dynop[AuDyLast];
12443 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12444 + const void *h_op)
12446 + struct au_dykey *key, *tmp;
12447 + struct hlist_bl_node *pos;
12450 + hlist_bl_lock(hbl);
12451 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12452 + if (tmp->dk_op.dy_hop == h_op) {
12453 + if (kref_get_unless_zero(&tmp->dk_kref))
12457 + hlist_bl_unlock(hbl);
12462 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12464 + struct au_dykey **k, *found;
12465 + const void *h_op = key->dk_op.dy_hop;
12469 + k = br->br_dykey;
12470 + for (i = 0; i < AuBrDynOp; i++)
12472 + if (k[i]->dk_op.dy_hop == h_op) {
12479 + spin_lock(&br->br_dykey_lock);
12480 + for (; i < AuBrDynOp; i++)
12482 + if (k[i]->dk_op.dy_hop == h_op) {
12490 + spin_unlock(&br->br_dykey_lock);
12491 + BUG_ON(i == AuBrDynOp); /* expand the array */
12497 +/* kref_get() if @key is already added */
12498 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12500 + struct au_dykey *tmp, *found;
12501 + struct hlist_bl_node *pos;
12502 + const void *h_op = key->dk_op.dy_hop;
12505 + hlist_bl_lock(hbl);
12506 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12507 + if (tmp->dk_op.dy_hop == h_op) {
12508 + if (kref_get_unless_zero(&tmp->dk_kref))
12513 + hlist_bl_add_head(&key->dk_hnode, hbl);
12514 + hlist_bl_unlock(hbl);
12521 +static void dy_free_rcu(struct rcu_head *rcu)
12523 + struct au_dykey *key;
12525 + key = container_of(rcu, struct au_dykey, dk_rcu);
12530 +static void dy_free(struct kref *kref)
12532 + struct au_dykey *key;
12533 + struct hlist_bl_head *hbl;
12535 + key = container_of(kref, struct au_dykey, dk_kref);
12536 + hbl = dynop + key->dk_op.dy_type;
12537 + au_hbl_del(&key->dk_hnode, hbl);
12538 + call_rcu(&key->dk_rcu, dy_free_rcu);
12541 +void au_dy_put(struct au_dykey *key)
12543 + kref_put(&key->dk_kref, dy_free);
12546 +/* ---------------------------------------------------------------------- */
12548 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12550 +#ifdef CONFIG_AUFS_DEBUG
12551 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12552 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12554 +#define DyDbgDeclare(cnt) do {} while (0)
12555 +#define DyDbgInc(cnt) do {} while (0)
12558 +#define DySet(func, dst, src, h_op, h_sb) do { \
12560 + if (h_op->func) { \
12562 + dst.func = src.func; \
12564 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12568 +#define DySetForce(func, dst, src) do { \
12569 + AuDebugOn(!src.func); \
12571 + dst.func = src.func; \
12574 +#define DySetAop(func) \
12575 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12576 +#define DySetAopForce(func) \
12577 + DySetForce(func, dyaop->da_op, aufs_aop)
12579 +static void dy_aop(struct au_dykey *key, const void *h_op,
12580 + struct super_block *h_sb __maybe_unused)
12582 + struct au_dyaop *dyaop = (void *)key;
12583 + const struct address_space_operations *h_aop = h_op;
12584 + DyDbgDeclare(cnt);
12586 + AuDbg("%s\n", au_sbtype(h_sb));
12588 + DySetAop(writepage);
12589 + DySetAopForce(readpage); /* force */
12590 + DySetAop(writepages);
12591 + DySetAop(set_page_dirty);
12592 + DySetAop(readpages);
12593 + DySetAop(write_begin);
12594 + DySetAop(write_end);
12596 + DySetAop(invalidatepage);
12597 + DySetAop(releasepage);
12598 + DySetAop(freepage);
12599 + /* this one will be changed according to an aufs mount option */
12600 + DySetAop(direct_IO);
12601 + DySetAop(migratepage);
12602 + DySetAop(isolate_page);
12603 + DySetAop(putback_page);
12604 + DySetAop(launder_page);
12605 + DySetAop(is_partially_uptodate);
12606 + DySetAop(is_dirty_writeback);
12607 + DySetAop(error_remove_page);
12608 + DySetAop(swap_activate);
12609 + DySetAop(swap_deactivate);
12611 + DyDbgSize(cnt, *h_aop);
12614 +/* ---------------------------------------------------------------------- */
12616 +static void dy_bug(struct kref *kref)
12621 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12623 + struct au_dykey *key, *old;
12624 + struct hlist_bl_head *hbl;
12627 + void (*set)(struct au_dykey *key, const void *h_op,
12628 + struct super_block *h_sb __maybe_unused);
12630 + static const struct op a[] = {
12632 + .sz = sizeof(struct au_dyaop),
12636 + const struct op *p;
12638 + hbl = dynop + op->dy_type;
12639 + key = dy_gfind_get(hbl, op->dy_hop);
12641 + goto out_add; /* success */
12643 + p = a + op->dy_type;
12644 + key = kzalloc(p->sz, GFP_NOFS);
12645 + if (unlikely(!key)) {
12646 + key = ERR_PTR(-ENOMEM);
12650 + key->dk_op.dy_hop = op->dy_hop;
12651 + kref_init(&key->dk_kref);
12652 + p->set(key, op->dy_hop, au_br_sb(br));
12653 + old = dy_gadd(hbl, key);
12655 + au_kfree_rcu(key);
12660 + old = dy_bradd(br, key);
12662 + /* its ref-count should never be zero here */
12663 + kref_put(&key->dk_kref, dy_bug);
12668 +/* ---------------------------------------------------------------------- */
12670 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12671 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12672 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12673 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12674 + * See the aufs manual in detail.
12676 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12679 + dyaop->da_op.direct_IO = NULL;
12681 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12684 +static struct au_dyaop *dy_aget(struct au_branch *br,
12685 + const struct address_space_operations *h_aop,
12688 + struct au_dyaop *dyaop;
12689 + struct au_dynop op;
12691 + op.dy_type = AuDy_AOP;
12692 + op.dy_haop = h_aop;
12693 + dyaop = (void *)dy_get(&op, br);
12694 + if (IS_ERR(dyaop))
12696 + dy_adx(dyaop, do_dx);
12702 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12703 + struct inode *h_inode)
12706 + struct super_block *sb;
12707 + struct au_branch *br;
12708 + struct au_dyaop *dyaop;
12710 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12711 + IiMustWriteLock(inode);
12713 + sb = inode->i_sb;
12714 + br = au_sbr(sb, bindex);
12715 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12716 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12717 + err = PTR_ERR(dyaop);
12718 + if (IS_ERR(dyaop))
12719 + /* unnecessary to call dy_fput() */
12723 + inode->i_mapping->a_ops = &dyaop->da_op;
12730 + * Is it safe to replace a_ops during the inode/file is in operation?
12731 + * Yes, I hope so.
12733 +int au_dy_irefresh(struct inode *inode)
12736 + aufs_bindex_t btop;
12737 + struct inode *h_inode;
12740 + if (S_ISREG(inode->i_mode)) {
12741 + btop = au_ibtop(inode);
12742 + h_inode = au_h_iptr(inode, btop);
12743 + err = au_dy_iaop(inode, btop, h_inode);
12748 +void au_dy_arefresh(int do_dx)
12750 + struct hlist_bl_head *hbl;
12751 + struct hlist_bl_node *pos;
12752 + struct au_dykey *key;
12754 + hbl = dynop + AuDy_AOP;
12755 + hlist_bl_lock(hbl);
12756 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12757 + dy_adx((void *)key, do_dx);
12758 + hlist_bl_unlock(hbl);
12761 +/* ---------------------------------------------------------------------- */
12763 +void __init au_dy_init(void)
12767 + for (i = 0; i < AuDyLast; i++)
12768 + INIT_HLIST_BL_HEAD(dynop + i);
12771 +void au_dy_fin(void)
12775 + for (i = 0; i < AuDyLast; i++)
12776 + WARN_ON(!hlist_bl_empty(dynop + i));
12778 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12779 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12780 +++ linux/fs/aufs/dynop.h 2020-01-27 10:57:18.168871450 +0100
12782 +/* SPDX-License-Identifier: GPL-2.0 */
12784 + * Copyright (C) 2010-2020 Junjiro R. Okajima
12786 + * This program, aufs is free software; you can redistribute it and/or modify
12787 + * it under the terms of the GNU General Public License as published by
12788 + * the Free Software Foundation; either version 2 of the License, or
12789 + * (at your option) any later version.
12791 + * This program is distributed in the hope that it will be useful,
12792 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12793 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12794 + * GNU General Public License for more details.
12796 + * You should have received a copy of the GNU General Public License
12797 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12801 + * dynamically customizable operations (for regular files only)
12804 +#ifndef __AUFS_DYNOP_H__
12805 +#define __AUFS_DYNOP_H__
12809 +#include <linux/fs.h>
12810 +#include <linux/kref.h>
12812 +enum {AuDy_AOP, AuDyLast};
12817 + const void *dy_hop;
12818 + const struct address_space_operations *dy_haop;
12824 + struct hlist_bl_node dk_hnode;
12825 + struct rcu_head dk_rcu;
12827 + struct au_dynop dk_op;
12830 + * during I am in the branch local array, kref is gotten. when the
12831 + * branch is removed, kref is put.
12833 + struct kref dk_kref;
12836 +/* stop unioning since their sizes are very different from each other */
12838 + struct au_dykey da_key;
12839 + struct address_space_operations da_op; /* not const */
12841 +/* make sure that 'struct au_dykey *' can be any type */
12842 +static_assert(!offsetof(struct au_dyaop, da_key));
12844 +/* ---------------------------------------------------------------------- */
12848 +void au_dy_put(struct au_dykey *key);
12849 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12850 + struct inode *h_inode);
12851 +int au_dy_irefresh(struct inode *inode);
12852 +void au_dy_arefresh(int do_dio);
12854 +void __init au_dy_init(void);
12855 +void au_dy_fin(void);
12857 +#endif /* __KERNEL__ */
12858 +#endif /* __AUFS_DYNOP_H__ */
12859 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12860 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12861 +++ linux/fs/aufs/export.c 2020-01-27 10:57:18.168871450 +0100
12863 +// SPDX-License-Identifier: GPL-2.0
12865 + * Copyright (C) 2005-2020 Junjiro R. Okajima
12867 + * This program, aufs is free software; you can redistribute it and/or modify
12868 + * it under the terms of the GNU General Public License as published by
12869 + * the Free Software Foundation; either version 2 of the License, or
12870 + * (at your option) any later version.
12872 + * This program is distributed in the hope that it will be useful,
12873 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12874 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12875 + * GNU General Public License for more details.
12877 + * You should have received a copy of the GNU General Public License
12878 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12885 +#include <linux/exportfs.h>
12886 +#include <linux/fs_struct.h>
12887 +#include <linux/namei.h>
12888 +#include <linux/nsproxy.h>
12889 +#include <linux/random.h>
12890 +#include <linux/writeback.h>
12894 +#ifdef CONFIG_AUFS_INO_T_64
12902 +static ino_t decode_ino(__u32 *a)
12906 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12908 +#ifdef CONFIG_AUFS_INO_T_64
12914 +static void encode_ino(__u32 *a, ino_t ino)
12920 +#ifdef CONFIG_AUFS_INO_T_64
12925 +/* NFS file handle */
12929 +#ifdef CONFIG_AUFS_INO_T_64
12930 + /* support 64bit inode number */
12943 + Fh_ino = Fh_ino1,
12944 + Fh_dir_ino = Fh_dir_ino1
12947 +static int au_test_anon(struct dentry *dentry)
12949 + /* note: read d_flags without d_lock */
12950 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12953 +int au_test_nfsd(void)
12956 + struct task_struct *tsk = current;
12957 + char comm[sizeof(tsk->comm)];
12960 + if (tsk->flags & PF_KTHREAD) {
12961 + get_task_comm(comm, tsk);
12962 + ret = !strcmp(comm, "nfsd");
12968 +/* ---------------------------------------------------------------------- */
12969 +/* inode generation external table */
12971 +void au_xigen_inc(struct inode *inode)
12976 + struct super_block *sb;
12977 + struct au_sbinfo *sbinfo;
12979 + sb = inode->i_sb;
12980 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12982 + sbinfo = au_sbi(sb);
12983 + pos = inode->i_ino;
12984 + pos *= sizeof(igen);
12985 + igen = inode->i_generation + 1;
12986 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
12987 + sizeof(igen), &pos);
12988 + if (sz == sizeof(igen))
12989 + return; /* success */
12991 + if (unlikely(sz >= 0))
12992 + AuIOErr("xigen error (%zd)\n", sz);
12995 +int au_xigen_new(struct inode *inode)
13000 + struct super_block *sb;
13001 + struct au_sbinfo *sbinfo;
13002 + struct file *file;
13005 + /* todo: dirty, at mount time */
13006 + if (inode->i_ino == AUFS_ROOT_INO)
13008 + sb = inode->i_sb;
13009 + SiMustAnyLock(sb);
13010 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13014 + pos = inode->i_ino;
13015 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
13016 + AuIOErr1("too large i%lld\n", pos);
13019 + pos *= sizeof(inode->i_generation);
13022 + sbinfo = au_sbi(sb);
13023 + file = sbinfo->si_xigen;
13026 + if (vfsub_f_size_read(file)
13027 + < pos + sizeof(inode->i_generation)) {
13028 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
13029 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
13030 + sizeof(inode->i_generation), &pos);
13032 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
13033 + sizeof(inode->i_generation), &pos);
13034 + if (sz == sizeof(inode->i_generation))
13035 + goto out; /* success */
13038 + if (unlikely(sz >= 0)) {
13040 + AuIOErr("xigen error (%zd)\n", sz);
13047 +int au_xigen_set(struct super_block *sb, struct path *path)
13050 + struct au_sbinfo *sbinfo;
13051 + struct file *file;
13053 + SiMustWriteLock(sb);
13055 + sbinfo = au_sbi(sb);
13056 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
13057 + err = PTR_ERR(file);
13058 + if (IS_ERR(file))
13061 + if (sbinfo->si_xigen)
13062 + fput(sbinfo->si_xigen);
13063 + sbinfo->si_xigen = file;
13070 +void au_xigen_clr(struct super_block *sb)
13072 + struct au_sbinfo *sbinfo;
13074 + SiMustWriteLock(sb);
13076 + sbinfo = au_sbi(sb);
13077 + if (sbinfo->si_xigen) {
13078 + fput(sbinfo->si_xigen);
13079 + sbinfo->si_xigen = NULL;
13083 +/* ---------------------------------------------------------------------- */
13085 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13088 + struct dentry *dentry, *d;
13089 + struct inode *inode;
13090 + unsigned int sigen;
13093 + inode = ilookup(sb, ino);
13097 + dentry = ERR_PTR(-ESTALE);
13098 + sigen = au_sigen(sb);
13099 + if (unlikely(au_is_bad_inode(inode)
13100 + || IS_DEADDIR(inode)
13101 + || sigen != au_iigen(inode, NULL)))
13105 + if (!dir_ino || S_ISDIR(inode->i_mode))
13106 + dentry = d_find_alias(inode);
13108 + spin_lock(&inode->i_lock);
13109 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13110 + spin_lock(&d->d_lock);
13111 + if (!au_test_anon(d)
13112 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13113 + dentry = dget_dlock(d);
13114 + spin_unlock(&d->d_lock);
13117 + spin_unlock(&d->d_lock);
13119 + spin_unlock(&inode->i_lock);
13121 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13122 + /* need to refresh */
13130 + AuTraceErrPtr(dentry);
13134 +/* ---------------------------------------------------------------------- */
13136 +/* todo: dirty? */
13137 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13139 +struct au_compare_mnt_args {
13141 + struct super_block *sb;
13144 + struct vfsmount *mnt;
13147 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13149 + struct au_compare_mnt_args *a = arg;
13151 + if (mnt->mnt_sb != a->sb)
13153 + a->mnt = mntget(mnt);
13157 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13160 + struct path root;
13161 + struct au_compare_mnt_args args = {
13165 + get_fs_root(current->fs, &root);
13167 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13168 + rcu_read_unlock();
13171 + AuDebugOn(!args.mnt);
13175 +struct au_nfsd_si_lock {
13176 + unsigned int sigen;
13177 + aufs_bindex_t bindex, br_id;
13178 + unsigned char force_lock;
13181 +static int si_nfsd_read_lock(struct super_block *sb,
13182 + struct au_nfsd_si_lock *nsi_lock)
13185 + aufs_bindex_t bindex;
13187 + si_read_lock(sb, AuLock_FLUSH);
13189 + /* branch id may be wrapped around */
13191 + bindex = au_br_index(sb, nsi_lock->br_id);
13192 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13193 + goto out; /* success */
13197 + if (!nsi_lock->force_lock)
13198 + si_read_unlock(sb);
13201 + nsi_lock->bindex = bindex;
13205 +struct find_name_by_ino {
13206 + struct dir_context ctx;
13207 + int called, found;
13214 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13215 + loff_t offset, u64 ino, unsigned int d_type)
13217 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13221 + if (a->ino != ino)
13224 + memcpy(a->name, name, namelen);
13225 + a->namelen = namelen;
13230 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13231 + struct au_nfsd_si_lock *nsi_lock)
13233 + struct dentry *dentry, *parent;
13234 + struct file *file;
13235 + struct inode *dir;
13236 + struct find_name_by_ino arg = {
13238 + .actor = find_name_by_ino
13243 + parent = path->dentry;
13245 + si_read_unlock(parent->d_sb);
13246 + file = vfsub_dentry_open(path, au_dir_roflags);
13247 + dentry = (void *)file;
13248 + if (IS_ERR(file))
13251 + dentry = ERR_PTR(-ENOMEM);
13252 + arg.name = (void *)__get_free_page(GFP_NOFS);
13253 + if (unlikely(!arg.name))
13260 + err = vfsub_iterate_dir(file, &arg.ctx);
13261 + } while (!err && !arg.found && arg.called);
13262 + dentry = ERR_PTR(err);
13263 + if (unlikely(err))
13265 + /* instead of ENOENT */
13266 + dentry = ERR_PTR(-ESTALE);
13270 + /* do not call vfsub_lkup_one() */
13271 + dir = d_inode(parent);
13272 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13273 + AuTraceErrPtr(dentry);
13274 + if (IS_ERR(dentry))
13276 + AuDebugOn(au_test_anon(dentry));
13277 + if (unlikely(d_really_is_negative(dentry))) {
13279 + dentry = ERR_PTR(-ENOENT);
13283 + free_page((unsigned long)arg.name);
13287 + if (unlikely(nsi_lock
13288 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13289 + if (!IS_ERR(dentry)) {
13291 + dentry = ERR_PTR(-ESTALE);
13293 + AuTraceErrPtr(dentry);
13297 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13299 + struct au_nfsd_si_lock *nsi_lock)
13301 + struct dentry *dentry;
13302 + struct path path;
13304 + if (dir_ino != AUFS_ROOT_INO) {
13305 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13306 + dentry = path.dentry;
13307 + if (!path.dentry || IS_ERR(path.dentry))
13309 + AuDebugOn(au_test_anon(path.dentry));
13311 + path.dentry = dget(sb->s_root);
13313 + path.mnt = au_mnt_get(sb);
13314 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13318 + AuTraceErrPtr(dentry);
13322 +/* ---------------------------------------------------------------------- */
13324 +static int h_acceptable(void *expv, struct dentry *dentry)
13329 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13330 + char *buf, int len, struct super_block *sb)
13334 + struct path path;
13336 + p = d_path(h_rootpath, buf, len);
13341 + path.mnt = h_rootpath->mnt;
13342 + path.dentry = h_parent;
13343 + p = d_path(&path, buf, len);
13349 + path.mnt = au_mnt_get(sb);
13350 + path.dentry = sb->s_root;
13351 + p = d_path(&path, buf, len - strlen(p));
13352 + mntput(path.mnt);
13356 + p[strlen(p)] = '/';
13359 + AuTraceErrPtr(p);
13364 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13365 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13367 + struct dentry *dentry, *h_parent, *root;
13368 + struct super_block *h_sb;
13369 + char *pathname, *p;
13370 + struct vfsmount *h_mnt;
13371 + struct au_branch *br;
13373 + struct path path;
13375 + br = au_sbr(sb, nsi_lock->bindex);
13376 + h_mnt = au_br_mnt(br);
13377 + h_sb = h_mnt->mnt_sb;
13378 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13380 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13381 + fh_len - Fh_tail, fh[Fh_h_type],
13382 + h_acceptable, /*context*/NULL);
13384 + dentry = h_parent;
13385 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13386 + AuWarn1("%s decode_fh failed, %ld\n",
13387 + au_sbtype(h_sb), PTR_ERR(h_parent));
13391 + if (unlikely(au_test_anon(h_parent))) {
13392 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13393 + au_sbtype(h_sb));
13394 + goto out_h_parent;
13397 + dentry = ERR_PTR(-ENOMEM);
13398 + pathname = (void *)__get_free_page(GFP_NOFS);
13399 + if (unlikely(!pathname))
13400 + goto out_h_parent;
13402 + root = sb->s_root;
13403 + path.mnt = h_mnt;
13404 + di_read_lock_parent(root, !AuLock_IR);
13405 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13406 + di_read_unlock(root, !AuLock_IR);
13407 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13408 + dentry = (void *)p;
13410 + goto out_pathname;
13412 + si_read_unlock(sb);
13413 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13414 + dentry = ERR_PTR(err);
13415 + if (unlikely(err))
13418 + dentry = ERR_PTR(-ENOENT);
13419 + AuDebugOn(au_test_anon(path.dentry));
13420 + if (unlikely(d_really_is_negative(path.dentry)))
13423 + if (ino != d_inode(path.dentry)->i_ino)
13424 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13426 + dentry = dget(path.dentry);
13431 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13432 + if (!IS_ERR(dentry)) {
13434 + dentry = ERR_PTR(-ESTALE);
13437 + free_page((unsigned long)pathname);
13441 + AuTraceErrPtr(dentry);
13445 +/* ---------------------------------------------------------------------- */
13447 +static struct dentry *
13448 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13451 + struct dentry *dentry;
13452 + __u32 *fh = fid->raw;
13453 + struct au_branch *br;
13454 + ino_t ino, dir_ino;
13455 + struct au_nfsd_si_lock nsi_lock = {
13459 + dentry = ERR_PTR(-ESTALE);
13460 + /* it should never happen, but the file handle is unreliable */
13461 + if (unlikely(fh_len < Fh_tail))
13463 + nsi_lock.sigen = fh[Fh_sigen];
13464 + nsi_lock.br_id = fh[Fh_br_id];
13466 + /* branch id may be wrapped around */
13468 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13470 + nsi_lock.force_lock = 1;
13472 + /* is this inode still cached? */
13473 + ino = decode_ino(fh + Fh_ino);
13474 + /* it should never happen */
13475 + if (unlikely(ino == AUFS_ROOT_INO))
13478 + dir_ino = decode_ino(fh + Fh_dir_ino);
13479 + dentry = decode_by_ino(sb, ino, dir_ino);
13480 + if (IS_ERR(dentry))
13485 + /* is the parent dir cached? */
13486 + br = au_sbr(sb, nsi_lock.bindex);
13487 + au_lcnt_inc(&br->br_nfiles);
13488 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13489 + if (IS_ERR(dentry))
13494 + /* lookup path */
13495 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13496 + if (IS_ERR(dentry))
13498 + if (unlikely(!dentry))
13499 + /* todo?: make it ESTALE */
13503 + if (!au_digen_test(dentry, au_sigen(sb))
13504 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13505 + goto out_unlock; /* success */
13508 + dentry = ERR_PTR(-ESTALE);
13511 + au_lcnt_dec(&br->br_nfiles);
13512 + si_read_unlock(sb);
13514 + AuTraceErrPtr(dentry);
13518 +#if 0 /* reserved for future use */
13519 +/* support subtreecheck option */
13520 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13521 + int fh_len, int fh_type)
13523 + struct dentry *parent;
13524 + __u32 *fh = fid->raw;
13527 + dir_ino = decode_ino(fh + Fh_dir_ino);
13528 + parent = decode_by_ino(sb, dir_ino, 0);
13529 + if (IS_ERR(parent))
13532 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13533 + dir_ino, fh, fh_len);
13536 + AuTraceErrPtr(parent);
13541 +/* ---------------------------------------------------------------------- */
13543 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13544 + struct inode *dir)
13547 + aufs_bindex_t bindex;
13548 + struct super_block *sb, *h_sb;
13549 + struct dentry *dentry, *parent, *h_parent;
13550 + struct inode *h_dir;
13551 + struct au_branch *br;
13554 + if (unlikely(*max_len <= Fh_tail)) {
13555 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13559 + err = FILEID_ROOT;
13560 + if (inode->i_ino == AUFS_ROOT_INO) {
13561 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13566 + sb = inode->i_sb;
13567 + err = si_read_lock(sb, AuLock_FLUSH);
13568 + if (unlikely(err))
13571 +#ifdef CONFIG_AUFS_DEBUG
13572 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13573 + AuWarn1("NFS-exporting requires xino\n");
13577 + ii_read_lock_child(inode);
13578 + bindex = au_ibtop(inode);
13580 + dentry = d_find_any_alias(inode);
13581 + if (unlikely(!dentry))
13583 + AuDebugOn(au_test_anon(dentry));
13584 + parent = dget_parent(dentry);
13586 + if (unlikely(!parent))
13588 + if (d_really_is_positive(parent))
13589 + dir = d_inode(parent);
13592 + ii_read_lock_parent(dir);
13593 + h_dir = au_h_iptr(dir, bindex);
13594 + ii_read_unlock(dir);
13595 + if (unlikely(!h_dir))
13597 + h_parent = d_find_any_alias(h_dir);
13598 + if (unlikely(!h_parent))
13599 + goto out_hparent;
13602 + br = au_sbr(sb, bindex);
13603 + h_sb = au_br_sb(br);
13604 + if (unlikely(!h_sb->s_export_op)) {
13605 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13606 + goto out_hparent;
13609 + fh[Fh_br_id] = br->br_id;
13610 + fh[Fh_sigen] = au_sigen(sb);
13611 + encode_ino(fh + Fh_ino, inode->i_ino);
13612 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13613 + fh[Fh_igen] = inode->i_generation;
13615 + *max_len -= Fh_tail;
13616 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13618 + /*connectable or subtreecheck*/0);
13619 + err = fh[Fh_h_type];
13620 + *max_len += Fh_tail;
13621 + /* todo: macros? */
13622 + if (err != FILEID_INVALID)
13625 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13632 + ii_read_unlock(inode);
13633 + si_read_unlock(sb);
13635 + if (unlikely(err < 0))
13636 + err = FILEID_INVALID;
13640 +/* ---------------------------------------------------------------------- */
13642 +static int aufs_commit_metadata(struct inode *inode)
13645 + aufs_bindex_t bindex;
13646 + struct super_block *sb;
13647 + struct inode *h_inode;
13648 + int (*f)(struct inode *inode);
13650 + sb = inode->i_sb;
13651 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13652 + ii_write_lock_child(inode);
13653 + bindex = au_ibtop(inode);
13654 + AuDebugOn(bindex < 0);
13655 + h_inode = au_h_iptr(inode, bindex);
13657 + f = h_inode->i_sb->s_export_op->commit_metadata;
13659 + err = f(h_inode);
13661 + struct writeback_control wbc = {
13662 + .sync_mode = WB_SYNC_ALL,
13663 + .nr_to_write = 0 /* metadata only */
13666 + err = sync_inode(h_inode, &wbc);
13669 + au_cpup_attr_timesizes(inode);
13670 + ii_write_unlock(inode);
13671 + si_read_unlock(sb);
13675 +/* ---------------------------------------------------------------------- */
13677 +static struct export_operations aufs_export_op = {
13678 + .fh_to_dentry = aufs_fh_to_dentry,
13679 + /* .fh_to_parent = aufs_fh_to_parent, */
13680 + .encode_fh = aufs_encode_fh,
13681 + .commit_metadata = aufs_commit_metadata
13684 +void au_export_init(struct super_block *sb)
13686 + struct au_sbinfo *sbinfo;
13689 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13690 + && IS_MODULE(CONFIG_EXPORTFS),
13691 + AUFS_NAME ": unsupported configuration "
13692 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13694 + sb->s_export_op = &aufs_export_op;
13695 + sbinfo = au_sbi(sb);
13696 + sbinfo->si_xigen = NULL;
13697 + get_random_bytes(&u, sizeof(u));
13698 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13699 + atomic_set(&sbinfo->si_xigen_next, u);
13701 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13702 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13703 +++ linux/fs/aufs/fhsm.c 2020-01-27 10:57:18.172204883 +0100
13705 +// SPDX-License-Identifier: GPL-2.0
13707 + * Copyright (C) 2011-2020 Junjiro R. Okajima
13709 + * This program, aufs is free software; you can redistribute it and/or modify
13710 + * it under the terms of the GNU General Public License as published by
13711 + * the Free Software Foundation; either version 2 of the License, or
13712 + * (at your option) any later version.
13714 + * This program is distributed in the hope that it will be useful,
13715 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13716 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13717 + * GNU General Public License for more details.
13719 + * You should have received a copy of the GNU General Public License
13720 + * along with this program; if not, write to the Free Software
13721 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13725 + * File-based Hierarchy Storage Management
13728 +#include <linux/anon_inodes.h>
13729 +#include <linux/poll.h>
13730 +#include <linux/seq_file.h>
13731 +#include <linux/statfs.h>
13734 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13736 + struct au_sbinfo *sbinfo;
13737 + struct au_fhsm *fhsm;
13739 + SiMustAnyLock(sb);
13741 + sbinfo = au_sbi(sb);
13742 + fhsm = &sbinfo->si_fhsm;
13743 + AuDebugOn(!fhsm);
13744 + return fhsm->fhsm_bottom;
13747 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13749 + struct au_sbinfo *sbinfo;
13750 + struct au_fhsm *fhsm;
13752 + SiMustWriteLock(sb);
13754 + sbinfo = au_sbi(sb);
13755 + fhsm = &sbinfo->si_fhsm;
13756 + AuDebugOn(!fhsm);
13757 + fhsm->fhsm_bottom = bindex;
13760 +/* ---------------------------------------------------------------------- */
13762 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13764 + struct au_br_fhsm *bf;
13766 + bf = br->br_fhsm;
13767 + MtxMustLock(&bf->bf_lock);
13769 + return !bf->bf_readable
13770 + || time_after(jiffies,
13771 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13774 +/* ---------------------------------------------------------------------- */
13776 +static void au_fhsm_notify(struct super_block *sb, int val)
13778 + struct au_sbinfo *sbinfo;
13779 + struct au_fhsm *fhsm;
13781 + SiMustAnyLock(sb);
13783 + sbinfo = au_sbi(sb);
13784 + fhsm = &sbinfo->si_fhsm;
13785 + if (au_fhsm_pid(fhsm)
13786 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13787 + atomic_set(&fhsm->fhsm_readable, val);
13789 + wake_up(&fhsm->fhsm_wqh);
13793 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13794 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13797 + struct au_branch *br;
13798 + struct au_br_fhsm *bf;
13800 + br = au_sbr(sb, bindex);
13801 + AuDebugOn(au_br_rdonly(br));
13802 + bf = br->br_fhsm;
13806 + mutex_lock(&bf->bf_lock);
13808 + MtxMustLock(&bf->bf_lock);
13810 + /* sb->s_root for NFS is unreliable */
13811 + err = au_br_stfs(br, &bf->bf_stfs);
13812 + if (unlikely(err)) {
13813 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13817 + bf->bf_jiffy = jiffies;
13818 + bf->bf_readable = 1;
13820 + au_fhsm_notify(sb, /*val*/1);
13822 + *rstfs = bf->bf_stfs;
13826 + mutex_unlock(&bf->bf_lock);
13827 + au_fhsm_notify(sb, /*val*/1);
13832 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13835 + struct au_sbinfo *sbinfo;
13836 + struct au_fhsm *fhsm;
13837 + struct au_branch *br;
13838 + struct au_br_fhsm *bf;
13840 + AuDbg("b%d, force %d\n", bindex, force);
13841 + SiMustAnyLock(sb);
13843 + sbinfo = au_sbi(sb);
13844 + fhsm = &sbinfo->si_fhsm;
13845 + if (!au_ftest_si(sbinfo, FHSM)
13846 + || fhsm->fhsm_bottom == bindex)
13849 + br = au_sbr(sb, bindex);
13850 + bf = br->br_fhsm;
13852 + mutex_lock(&bf->bf_lock);
13854 + || au_fhsm_pid(fhsm)
13855 + || au_fhsm_test_jiffy(sbinfo, br))
13856 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13858 + mutex_unlock(&bf->bf_lock);
13861 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13863 + aufs_bindex_t bindex, bbot;
13864 + struct au_branch *br;
13866 + /* exclude the bottom */
13867 + bbot = au_fhsm_bottom(sb);
13868 + for (bindex = 0; bindex < bbot; bindex++) {
13869 + br = au_sbr(sb, bindex);
13870 + if (au_br_fhsm(br->br_perm))
13871 + au_fhsm_wrote(sb, bindex, force);
13875 +/* ---------------------------------------------------------------------- */
13877 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13880 + struct au_sbinfo *sbinfo;
13881 + struct au_fhsm *fhsm;
13884 + sbinfo = file->private_data;
13885 + fhsm = &sbinfo->si_fhsm;
13886 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13887 + if (atomic_read(&fhsm->fhsm_readable))
13888 + mask = EPOLLIN /* | EPOLLRDNORM */;
13891 + AuDbg("mask 0x%x\n", mask);
13895 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13896 + struct aufs_stfs *stfs, __s16 brid)
13900 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13902 + err = __put_user(brid, &stbr->brid);
13903 + if (unlikely(err))
13909 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13910 + struct aufs_stbr __user *stbr, size_t count)
13914 + aufs_bindex_t bindex, bbot;
13915 + struct au_branch *br;
13916 + struct au_br_fhsm *bf;
13918 + /* except the bottom branch */
13921 + bbot = au_fhsm_bottom(sb);
13922 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13923 + br = au_sbr(sb, bindex);
13924 + if (!au_br_fhsm(br->br_perm))
13927 + bf = br->br_fhsm;
13928 + mutex_lock(&bf->bf_lock);
13929 + if (bf->bf_readable) {
13931 + if (count >= sizeof(*stbr))
13932 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13935 + bf->bf_readable = 0;
13936 + count -= sizeof(*stbr);
13940 + mutex_unlock(&bf->bf_lock);
13943 + err = sizeof(*stbr) * nstbr;
13948 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13953 + aufs_bindex_t nfhsm, bindex, bbot;
13954 + struct au_sbinfo *sbinfo;
13955 + struct au_fhsm *fhsm;
13956 + struct au_branch *br;
13957 + struct super_block *sb;
13960 + sbinfo = file->private_data;
13961 + fhsm = &sbinfo->si_fhsm;
13963 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13964 + if (!atomic_read(&fhsm->fhsm_readable)) {
13965 + if (vfsub_file_flags(file) & O_NONBLOCK)
13968 + err = wait_event_interruptible_locked_irq
13970 + atomic_read(&fhsm->fhsm_readable));
13972 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13973 + if (unlikely(err))
13976 + /* sb may already be dead */
13977 + au_rw_read_lock(&sbinfo->si_rwsem);
13978 + readable = atomic_read(&fhsm->fhsm_readable);
13979 + if (readable > 0) {
13980 + sb = sbinfo->si_sb;
13982 + /* exclude the bottom branch */
13984 + bbot = au_fhsm_bottom(sb);
13985 + for (bindex = 0; bindex < bbot; bindex++) {
13986 + br = au_sbr(sb, bindex);
13987 + if (au_br_fhsm(br->br_perm))
13991 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13992 + atomic_set(&fhsm->fhsm_readable, 0);
13993 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13997 + au_rw_read_unlock(&sbinfo->si_rwsem);
14005 +static int au_fhsm_release(struct inode *inode, struct file *file)
14007 + struct au_sbinfo *sbinfo;
14008 + struct au_fhsm *fhsm;
14010 + /* sb may already be dead */
14011 + sbinfo = file->private_data;
14012 + fhsm = &sbinfo->si_fhsm;
14013 + spin_lock(&fhsm->fhsm_spin);
14014 + fhsm->fhsm_pid = 0;
14015 + spin_unlock(&fhsm->fhsm_spin);
14016 + kobject_put(&sbinfo->si_kobj);
14021 +static const struct file_operations au_fhsm_fops = {
14022 + .owner = THIS_MODULE,
14023 + .llseek = noop_llseek,
14024 + .read = au_fhsm_read,
14025 + .poll = au_fhsm_poll,
14026 + .release = au_fhsm_release
14029 +int au_fhsm_fd(struct super_block *sb, int oflags)
14032 + struct au_sbinfo *sbinfo;
14033 + struct au_fhsm *fhsm;
14036 + if (unlikely(!capable(CAP_SYS_ADMIN)))
14040 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
14044 + sbinfo = au_sbi(sb);
14045 + fhsm = &sbinfo->si_fhsm;
14046 + spin_lock(&fhsm->fhsm_spin);
14047 + if (!fhsm->fhsm_pid)
14048 + fhsm->fhsm_pid = current->pid;
14051 + spin_unlock(&fhsm->fhsm_spin);
14052 + if (unlikely(err))
14055 + oflags |= O_RDONLY;
14056 + /* oflags |= FMODE_NONOTIFY; */
14057 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
14059 + if (unlikely(fd < 0))
14062 + /* succeed regardless 'fhsm' status */
14063 + kobject_get(&sbinfo->si_kobj);
14064 + si_noflush_read_lock(sb);
14065 + if (au_ftest_si(sbinfo, FHSM))
14066 + au_fhsm_wrote_all(sb, /*force*/0);
14067 + si_read_unlock(sb);
14068 + goto out; /* success */
14071 + spin_lock(&fhsm->fhsm_spin);
14072 + fhsm->fhsm_pid = 0;
14073 + spin_unlock(&fhsm->fhsm_spin);
14079 +/* ---------------------------------------------------------------------- */
14081 +int au_fhsm_br_alloc(struct au_branch *br)
14086 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14088 + au_br_fhsm_init(br->br_fhsm);
14095 +/* ---------------------------------------------------------------------- */
14097 +void au_fhsm_fin(struct super_block *sb)
14099 + au_fhsm_notify(sb, /*val*/-1);
14102 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14104 + struct au_fhsm *fhsm;
14106 + fhsm = &sbinfo->si_fhsm;
14107 + spin_lock_init(&fhsm->fhsm_spin);
14108 + init_waitqueue_head(&fhsm->fhsm_wqh);
14109 + atomic_set(&fhsm->fhsm_readable, 0);
14110 + fhsm->fhsm_expire
14111 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14112 + fhsm->fhsm_bottom = -1;
14115 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14117 + sbinfo->si_fhsm.fhsm_expire
14118 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14121 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14125 + if (!au_ftest_si(sbinfo, FHSM))
14128 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14129 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14130 + seq_printf(seq, ",fhsm_sec=%u", u);
14132 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14133 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14134 +++ linux/fs/aufs/file.c 2020-01-27 10:57:18.172204883 +0100
14136 +// SPDX-License-Identifier: GPL-2.0
14138 + * Copyright (C) 2005-2020 Junjiro R. Okajima
14140 + * This program, aufs is free software; you can redistribute it and/or modify
14141 + * it under the terms of the GNU General Public License as published by
14142 + * the Free Software Foundation; either version 2 of the License, or
14143 + * (at your option) any later version.
14145 + * This program is distributed in the hope that it will be useful,
14146 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14147 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14148 + * GNU General Public License for more details.
14150 + * You should have received a copy of the GNU General Public License
14151 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14155 + * handling file/dir, and address_space operation
14158 +#ifdef CONFIG_AUFS_DEBUG
14159 +#include <linux/migrate.h>
14161 +#include <linux/pagemap.h>
14164 +/* drop flags for writing */
14165 +unsigned int au_file_roflags(unsigned int flags)
14167 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14168 + flags |= O_RDONLY | O_NOATIME;
14172 +/* common functions to regular file and dir */
14173 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14174 + struct file *file, int force_wr)
14176 + struct file *h_file;
14177 + struct dentry *h_dentry;
14178 + struct inode *h_inode;
14179 + struct super_block *sb;
14180 + struct au_branch *br;
14181 + struct path h_path;
14184 + /* a race condition can happen between open and unlink/rmdir */
14185 + h_file = ERR_PTR(-ENOENT);
14186 + h_dentry = au_h_dptr(dentry, bindex);
14187 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14189 + h_inode = d_inode(h_dentry);
14190 + spin_lock(&h_dentry->d_lock);
14191 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14192 + /* || !d_inode(dentry)->i_nlink */
14194 + spin_unlock(&h_dentry->d_lock);
14195 + if (unlikely(err))
14198 + sb = dentry->d_sb;
14199 + br = au_sbr(sb, bindex);
14200 + err = au_br_test_oflag(flags, br);
14201 + h_file = ERR_PTR(err);
14202 + if (unlikely(err))
14205 + /* drop flags for writing */
14206 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14207 + if (force_wr && !(flags & O_WRONLY))
14209 + flags = au_file_roflags(flags);
14211 + h_file = ERR_PTR(-EROFS);
14212 + flags = au_file_roflags(flags);
14213 + if (unlikely(vfsub_native_ro(h_inode)
14214 + || IS_APPEND(h_inode)))
14216 + flags &= ~O_ACCMODE;
14217 + flags |= O_WRONLY;
14220 + flags &= ~O_CREAT;
14221 + au_lcnt_inc(&br->br_nfiles);
14222 + h_path.dentry = h_dentry;
14223 + h_path.mnt = au_br_mnt(br);
14224 + h_file = vfsub_dentry_open(&h_path, flags);
14225 + if (IS_ERR(h_file))
14228 + if (flags & __FMODE_EXEC) {
14229 + err = deny_write_access(h_file);
14230 + if (unlikely(err)) {
14232 + h_file = ERR_PTR(err);
14236 + fsnotify_open(h_file);
14237 + goto out; /* success */
14240 + au_lcnt_dec(&br->br_nfiles);
14245 +static int au_cmoo(struct dentry *dentry)
14247 + int err, cmoo, matched;
14248 + unsigned int udba;
14249 + struct path h_path;
14250 + struct au_pin pin;
14251 + struct au_cp_generic cpg = {
14252 + .dentry = dentry,
14257 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14259 + struct inode *delegated;
14260 + struct super_block *sb;
14261 + struct au_sbinfo *sbinfo;
14262 + struct au_fhsm *fhsm;
14264 + struct au_branch *br;
14265 + struct dentry *parent;
14266 + struct au_hinode *hdir;
14268 + DiMustWriteLock(dentry);
14269 + IiMustWriteLock(d_inode(dentry));
14272 + if (IS_ROOT(dentry))
14274 + cpg.bsrc = au_dbtop(dentry);
14278 + sb = dentry->d_sb;
14279 + sbinfo = au_sbi(sb);
14280 + fhsm = &sbinfo->si_fhsm;
14281 + pid = au_fhsm_pid(fhsm);
14284 + && (current->pid == pid
14285 + || rcu_dereference(current->real_parent)->pid == pid));
14286 + rcu_read_unlock();
14290 + br = au_sbr(sb, cpg.bsrc);
14291 + cmoo = au_br_cmoo(br->br_perm);
14294 + if (!d_is_reg(dentry))
14295 + cmoo &= AuBrAttr_COO_ALL;
14299 + parent = dget_parent(dentry);
14300 + di_write_lock_parent(parent);
14301 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14303 + if (unlikely(err < 0)) {
14304 + err = 0; /* there is no upper writable branch */
14307 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14309 + /* do not respect the coo attrib for the target branch */
14310 + err = au_cpup_dirs(dentry, cpg.bdst);
14311 + if (unlikely(err))
14314 + di_downgrade_lock(parent, AuLock_IR);
14315 + udba = au_opt_udba(sb);
14316 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14317 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14318 + if (unlikely(err))
14321 + err = au_sio_cpup_simple(&cpg);
14323 + if (unlikely(err))
14325 + if (!(cmoo & AuBrWAttr_MOO))
14326 + goto out_parent; /* success */
14328 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14329 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14330 + if (unlikely(err))
14333 + h_path.mnt = au_br_mnt(br);
14334 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14335 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14336 + delegated = NULL;
14337 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14339 + /* todo: keep h_dentry or not? */
14340 + if (unlikely(err == -EWOULDBLOCK)) {
14341 + pr_warn("cannot retry for NFSv4 delegation"
14342 + " for an internal unlink\n");
14345 + if (unlikely(err)) {
14346 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14350 + goto out_parent; /* success */
14353 + di_downgrade_lock(parent, AuLock_IR);
14355 + di_read_unlock(parent, AuLock_IR);
14362 +int au_do_open(struct file *file, struct au_do_open_args *args)
14364 + int err, aopen = args->aopen;
14365 + struct dentry *dentry;
14366 + struct au_finfo *finfo;
14369 + err = au_finfo_init(file, args->fidir);
14372 + err = au_finfo_init(file, args->fidir);
14375 + if (unlikely(err))
14378 + dentry = file->f_path.dentry;
14379 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14380 + di_write_lock_child(dentry);
14381 + err = au_cmoo(dentry);
14382 + di_downgrade_lock(dentry, AuLock_IR);
14385 + err = args->open(file, vfsub_file_flags(file), NULL);
14388 + err = args->open(file, vfsub_file_flags(file),
14393 + di_read_unlock(dentry, AuLock_IR);
14395 + finfo = au_fi(file);
14397 + finfo->fi_file = file;
14398 + au_hbl_add(&finfo->fi_hlist,
14399 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14402 + fi_write_unlock(file);
14405 + fi_write_unlock(file);
14408 + if (unlikely(err)) {
14409 + finfo->fi_hdir = NULL;
14410 + au_finfo_fin(file);
14418 +int au_reopen_nondir(struct file *file)
14421 + aufs_bindex_t btop;
14422 + struct dentry *dentry;
14423 + struct au_branch *br;
14424 + struct file *h_file, *h_file_tmp;
14426 + dentry = file->f_path.dentry;
14427 + btop = au_dbtop(dentry);
14428 + br = au_sbr(dentry->d_sb, btop);
14429 + h_file_tmp = NULL;
14430 + if (au_fbtop(file) == btop) {
14431 + h_file = au_hf_top(file);
14432 + if (file->f_mode == h_file->f_mode)
14433 + return 0; /* success */
14434 + h_file_tmp = h_file;
14435 + get_file(h_file_tmp);
14436 + au_lcnt_inc(&br->br_nfiles);
14437 + au_set_h_fptr(file, btop, NULL);
14439 + AuDebugOn(au_fi(file)->fi_hdir);
14442 + * file exists on both of rw and ro
14443 + * open --> dbtop and fbtop are both 0
14444 + * prepend a branch as rw, "rw" become ro
14446 + * delete the top branch, "rw" becomes rw again
14447 + * --> dbtop is 1, fbtop is still 0
14448 + * write --> fbtop is 0 but dbtop is 1
14450 + /* AuDebugOn(au_fbtop(file) < btop); */
14452 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14453 + file, /*force_wr*/0);
14454 + err = PTR_ERR(h_file);
14455 + if (IS_ERR(h_file)) {
14456 + if (h_file_tmp) {
14458 + au_set_h_fptr(file, btop, h_file_tmp);
14459 + h_file_tmp = NULL;
14461 + goto out; /* todo: close all? */
14465 + au_set_fbtop(file, btop);
14466 + au_set_h_fptr(file, btop, h_file);
14467 + au_update_figen(file);
14468 + /* todo: necessary? */
14469 + /* file->f_ra = h_file->f_ra; */
14472 + if (h_file_tmp) {
14473 + fput(h_file_tmp);
14474 + au_lcnt_dec(&br->br_nfiles);
14479 +/* ---------------------------------------------------------------------- */
14481 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14482 + struct dentry *hi_wh)
14485 + aufs_bindex_t btop;
14486 + struct au_dinfo *dinfo;
14487 + struct dentry *h_dentry;
14488 + struct au_hdentry *hdp;
14490 + dinfo = au_di(file->f_path.dentry);
14491 + AuRwMustWriteLock(&dinfo->di_rwsem);
14493 + btop = dinfo->di_btop;
14494 + dinfo->di_btop = btgt;
14495 + hdp = au_hdentry(dinfo, btgt);
14496 + h_dentry = hdp->hd_dentry;
14497 + hdp->hd_dentry = hi_wh;
14498 + err = au_reopen_nondir(file);
14499 + hdp->hd_dentry = h_dentry;
14500 + dinfo->di_btop = btop;
14505 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14506 + aufs_bindex_t bcpup, struct au_pin *pin)
14509 + struct inode *inode, *h_inode;
14510 + struct dentry *h_dentry, *hi_wh;
14511 + struct au_cp_generic cpg = {
14512 + .dentry = file->f_path.dentry,
14519 + au_update_dbtop(cpg.dentry);
14520 + inode = d_inode(cpg.dentry);
14522 + if (au_dbtop(cpg.dentry) <= bcpup
14523 + && au_dbbot(cpg.dentry) >= bcpup) {
14524 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14525 + if (h_dentry && d_is_positive(h_dentry))
14526 + h_inode = d_inode(h_dentry);
14528 + hi_wh = au_hi_wh(inode, bcpup);
14529 + if (!hi_wh && !h_inode)
14530 + err = au_sio_cpup_wh(&cpg, file);
14532 + /* already copied-up after unlink */
14533 + err = au_reopen_wh(file, bcpup, hi_wh);
14536 + && (inode->i_nlink > 1
14537 + || (inode->i_state & I_LINKABLE))
14538 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14539 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14545 + * prepare the @file for writing.
14547 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14550 + aufs_bindex_t dbtop;
14551 + struct dentry *parent;
14552 + struct inode *inode;
14553 + struct super_block *sb;
14554 + struct file *h_file;
14555 + struct au_cp_generic cpg = {
14556 + .dentry = file->f_path.dentry,
14561 + .flags = AuCpup_DTIME
14564 + sb = cpg.dentry->d_sb;
14565 + inode = d_inode(cpg.dentry);
14566 + cpg.bsrc = au_fbtop(file);
14567 + err = au_test_ro(sb, cpg.bsrc, inode);
14568 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14569 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14574 + /* need to cpup or reopen */
14575 + parent = dget_parent(cpg.dentry);
14576 + di_write_lock_parent(parent);
14577 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14579 + if (unlikely(err < 0))
14583 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14584 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14585 + if (unlikely(err))
14589 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14590 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14591 + if (unlikely(err))
14594 + dbtop = au_dbtop(cpg.dentry);
14595 + if (dbtop <= cpg.bdst)
14596 + cpg.bsrc = cpg.bdst;
14598 + if (dbtop <= cpg.bdst /* just reopen */
14599 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14601 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14602 + if (IS_ERR(h_file))
14603 + err = PTR_ERR(h_file);
14605 + di_downgrade_lock(parent, AuLock_IR);
14606 + if (dbtop > cpg.bdst)
14607 + err = au_sio_cpup_simple(&cpg);
14609 + err = au_reopen_nondir(file);
14610 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14612 + } else { /* copyup as wh and reopen */
14614 + * since writable hfsplus branch is not supported,
14615 + * h_open_pre/post() are unnecessary.
14617 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14618 + di_downgrade_lock(parent, AuLock_IR);
14622 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14623 + goto out_dput; /* success */
14629 + di_downgrade_lock(parent, AuLock_IR);
14631 + di_read_unlock(parent, AuLock_IR);
14638 +/* ---------------------------------------------------------------------- */
14640 +int au_do_flush(struct file *file, fl_owner_t id,
14641 + int (*flush)(struct file *file, fl_owner_t id))
14644 + struct super_block *sb;
14645 + struct inode *inode;
14647 + inode = file_inode(file);
14648 + sb = inode->i_sb;
14649 + si_noflush_read_lock(sb);
14650 + fi_read_lock(file);
14651 + ii_read_lock_child(inode);
14653 + err = flush(file, id);
14654 + au_cpup_attr_timesizes(inode);
14656 + ii_read_unlock(inode);
14657 + fi_read_unlock(file);
14658 + si_read_unlock(sb);
14662 +/* ---------------------------------------------------------------------- */
14664 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14667 + struct au_pin pin;
14668 + struct au_finfo *finfo;
14669 + struct dentry *parent, *hi_wh;
14670 + struct inode *inode;
14671 + struct super_block *sb;
14672 + struct au_cp_generic cpg = {
14673 + .dentry = file->f_path.dentry,
14678 + .flags = AuCpup_DTIME
14681 + FiMustWriteLock(file);
14684 + finfo = au_fi(file);
14685 + sb = cpg.dentry->d_sb;
14686 + inode = d_inode(cpg.dentry);
14687 + cpg.bdst = au_ibtop(inode);
14688 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14691 + parent = dget_parent(cpg.dentry);
14692 + if (au_test_ro(sb, cpg.bdst, inode)) {
14693 + di_read_lock_parent(parent, !AuLock_IR);
14694 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14696 + di_read_unlock(parent, !AuLock_IR);
14697 + if (unlikely(err < 0))
14702 + di_read_lock_parent(parent, AuLock_IR);
14703 + hi_wh = au_hi_wh(inode, cpg.bdst);
14704 + if (!S_ISDIR(inode->i_mode)
14705 + && au_opt_test(au_mntflags(sb), PLINK)
14706 + && au_plink_test(inode)
14707 + && !d_unhashed(cpg.dentry)
14708 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14709 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14710 + if (unlikely(err))
14713 + /* always superio. */
14714 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14715 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14717 + err = au_sio_cpup_simple(&cpg);
14720 + } else if (hi_wh) {
14721 + /* already copied-up after unlink */
14722 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14723 + *need_reopen = 0;
14727 + di_read_unlock(parent, AuLock_IR);
14734 +static void au_do_refresh_dir(struct file *file)
14736 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14737 + struct au_hfile *p, tmp, *q;
14738 + struct au_finfo *finfo;
14739 + struct super_block *sb;
14740 + struct au_fidir *fidir;
14742 + FiMustWriteLock(file);
14744 + sb = file->f_path.dentry->d_sb;
14745 + finfo = au_fi(file);
14746 + fidir = finfo->fi_hdir;
14747 + AuDebugOn(!fidir);
14748 + p = fidir->fd_hfile + finfo->fi_btop;
14749 + brid = p->hf_br->br_id;
14750 + bbot = fidir->fd_bbot;
14751 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14755 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14756 + if (new_bindex == bindex)
14758 + if (new_bindex < 0) {
14759 + au_set_h_fptr(file, bindex, NULL);
14763 + /* swap two lower inode, and loop again */
14764 + q = fidir->fd_hfile + new_bindex;
14768 + if (tmp.hf_file) {
14774 + p = fidir->fd_hfile;
14775 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14776 + bbot = au_sbbot(sb);
14777 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14778 + finfo->fi_btop++, p++)
14779 + if (p->hf_file) {
14780 + if (file_inode(p->hf_file))
14782 + au_hfput(p, /*execed*/0);
14785 + bbot = au_br_index(sb, brid);
14786 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14787 + finfo->fi_btop++, p++)
14789 + au_hfput(p, /*execed*/0);
14790 + bbot = au_sbbot(sb);
14793 + p = fidir->fd_hfile + bbot;
14794 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14795 + fidir->fd_bbot--, p--)
14796 + if (p->hf_file) {
14797 + if (file_inode(p->hf_file))
14799 + au_hfput(p, /*execed*/0);
14801 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14805 + * after branch manipulating, refresh the file.
14807 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14809 + int err, need_reopen, nbr;
14810 + aufs_bindex_t bbot, bindex;
14811 + struct dentry *dentry;
14812 + struct super_block *sb;
14813 + struct au_finfo *finfo;
14814 + struct au_hfile *hfile;
14816 + dentry = file->f_path.dentry;
14817 + sb = dentry->d_sb;
14818 + nbr = au_sbbot(sb) + 1;
14819 + finfo = au_fi(file);
14820 + if (!finfo->fi_hdir) {
14821 + hfile = &finfo->fi_htop;
14822 + AuDebugOn(!hfile->hf_file);
14823 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14824 + AuDebugOn(bindex < 0);
14825 + if (bindex != finfo->fi_btop)
14826 + au_set_fbtop(file, bindex);
14828 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14829 + if (unlikely(err))
14831 + au_do_refresh_dir(file);
14836 + if (!au_test_mmapped(file))
14837 + err = au_file_refresh_by_inode(file, &need_reopen);
14838 + if (finfo->fi_hdir)
14839 + /* harmless if err */
14840 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14841 + if (!err && need_reopen && !d_unlinked(dentry))
14842 + err = reopen(file);
14844 + au_update_figen(file);
14845 + goto out; /* success */
14848 + /* error, close all lower files */
14849 + if (finfo->fi_hdir) {
14850 + bbot = au_fbbot_dir(file);
14851 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14852 + au_set_h_fptr(file, bindex, NULL);
14859 +/* common function to regular file and dir */
14860 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14861 + int wlock, unsigned int fi_lsc)
14864 + unsigned int sigen, figen;
14865 + aufs_bindex_t btop;
14866 + unsigned char pseudo_link;
14867 + struct dentry *dentry;
14868 + struct inode *inode;
14871 + dentry = file->f_path.dentry;
14872 + inode = d_inode(dentry);
14873 + sigen = au_sigen(dentry->d_sb);
14874 + fi_write_lock_nested(file, fi_lsc);
14875 + figen = au_figen(file);
14877 + di_write_lock_child(dentry);
14879 + di_write_lock_child2(dentry);
14880 + btop = au_dbtop(dentry);
14881 + pseudo_link = (btop != au_ibtop(inode));
14882 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14884 + di_downgrade_lock(dentry, AuLock_IR);
14885 + fi_downgrade_lock(file);
14887 + goto out; /* success */
14890 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14891 + if (au_digen_test(dentry, sigen)) {
14892 + err = au_reval_dpath(dentry, sigen);
14893 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14897 + err = refresh_file(file, reopen);
14900 + di_downgrade_lock(dentry, AuLock_IR);
14901 + fi_downgrade_lock(file);
14904 + di_write_unlock(dentry);
14905 + fi_write_unlock(file);
14912 +/* ---------------------------------------------------------------------- */
14914 +/* cf. aufs_nopage() */
14915 +/* for madvise(2) */
14916 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14918 + unlock_page(page);
14922 +/* it will never be called, but necessary to support O_DIRECT */
14923 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14924 +{ BUG(); return 0; }
14926 +/* they will never be called. */
14927 +#ifdef CONFIG_AUFS_DEBUG
14928 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14929 + loff_t pos, unsigned len, unsigned flags,
14930 + struct page **pagep, void **fsdata)
14931 +{ AuUnsupport(); return 0; }
14932 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14933 + loff_t pos, unsigned len, unsigned copied,
14934 + struct page *page, void *fsdata)
14935 +{ AuUnsupport(); return 0; }
14936 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14937 +{ AuUnsupport(); return 0; }
14939 +static int aufs_set_page_dirty(struct page *page)
14940 +{ AuUnsupport(); return 0; }
14941 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14942 + unsigned int length)
14943 +{ AuUnsupport(); }
14944 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14945 +{ AuUnsupport(); return 0; }
14946 +#if 0 /* called by memory compaction regardless file */
14947 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14948 + struct page *page, enum migrate_mode mode)
14949 +{ AuUnsupport(); return 0; }
14951 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14952 +{ AuUnsupport(); return true; }
14953 +static void aufs_putback_page(struct page *page)
14954 +{ AuUnsupport(); }
14955 +static int aufs_launder_page(struct page *page)
14956 +{ AuUnsupport(); return 0; }
14957 +static int aufs_is_partially_uptodate(struct page *page,
14958 + unsigned long from,
14959 + unsigned long count)
14960 +{ AuUnsupport(); return 0; }
14961 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14963 +{ AuUnsupport(); }
14964 +static int aufs_error_remove_page(struct address_space *mapping,
14965 + struct page *page)
14966 +{ AuUnsupport(); return 0; }
14967 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14969 +{ AuUnsupport(); return 0; }
14970 +static void aufs_swap_deactivate(struct file *file)
14971 +{ AuUnsupport(); }
14972 +#endif /* CONFIG_AUFS_DEBUG */
14974 +const struct address_space_operations aufs_aop = {
14975 + .readpage = aufs_readpage,
14976 + .direct_IO = aufs_direct_IO,
14977 +#ifdef CONFIG_AUFS_DEBUG
14978 + .writepage = aufs_writepage,
14979 + /* no writepages, because of writepage */
14980 + .set_page_dirty = aufs_set_page_dirty,
14981 + /* no readpages, because of readpage */
14982 + .write_begin = aufs_write_begin,
14983 + .write_end = aufs_write_end,
14984 + /* no bmap, no block device */
14985 + .invalidatepage = aufs_invalidatepage,
14986 + .releasepage = aufs_releasepage,
14987 + /* is fallback_migrate_page ok? */
14988 + /* .migratepage = aufs_migratepage, */
14989 + .isolate_page = aufs_isolate_page,
14990 + .putback_page = aufs_putback_page,
14991 + .launder_page = aufs_launder_page,
14992 + .is_partially_uptodate = aufs_is_partially_uptodate,
14993 + .is_dirty_writeback = aufs_is_dirty_writeback,
14994 + .error_remove_page = aufs_error_remove_page,
14995 + .swap_activate = aufs_swap_activate,
14996 + .swap_deactivate = aufs_swap_deactivate
14997 +#endif /* CONFIG_AUFS_DEBUG */
14999 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
15000 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
15001 +++ linux/fs/aufs/file.h 2020-01-27 10:57:18.172204883 +0100
15003 +/* SPDX-License-Identifier: GPL-2.0 */
15005 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15007 + * This program, aufs is free software; you can redistribute it and/or modify
15008 + * it under the terms of the GNU General Public License as published by
15009 + * the Free Software Foundation; either version 2 of the License, or
15010 + * (at your option) any later version.
15012 + * This program is distributed in the hope that it will be useful,
15013 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15014 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15015 + * GNU General Public License for more details.
15017 + * You should have received a copy of the GNU General Public License
15018 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15022 + * file operations
15025 +#ifndef __AUFS_FILE_H__
15026 +#define __AUFS_FILE_H__
15030 +#include <linux/file.h>
15031 +#include <linux/fs.h>
15032 +#include <linux/mm_types.h>
15033 +#include <linux/poll.h>
15034 +#include "rwsem.h"
15038 + struct file *hf_file;
15039 + struct au_branch *hf_br;
15044 + aufs_bindex_t fd_bbot;
15045 + aufs_bindex_t fd_nent;
15046 + struct au_vdir *fd_vdir_cache;
15047 + struct au_hfile fd_hfile[];
15050 +static inline int au_fidir_sz(int nent)
15052 + AuDebugOn(nent < 0);
15053 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
15057 + atomic_t fi_generation;
15059 + struct au_rwsem fi_rwsem;
15060 + aufs_bindex_t fi_btop;
15062 + /* do not union them */
15063 + struct { /* for non-dir */
15064 + struct au_hfile fi_htop;
15065 + atomic_t fi_mmapped;
15067 + struct au_fidir *fi_hdir; /* for dir only */
15069 + struct hlist_bl_node fi_hlist;
15070 + struct file *fi_file; /* very ugly */
15071 + struct rcu_head rcu;
15072 +} ____cacheline_aligned_in_smp;
15074 +/* ---------------------------------------------------------------------- */
15077 +extern const struct address_space_operations aufs_aop;
15078 +unsigned int au_file_roflags(unsigned int flags);
15079 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15080 + struct file *file, int force_wr);
15081 +struct au_do_open_args {
15083 + int (*open)(struct file *file, int flags,
15084 + struct file *h_file);
15085 + struct au_fidir *fidir;
15086 + struct file *h_file;
15088 +int au_do_open(struct file *file, struct au_do_open_args *args);
15089 +int au_reopen_nondir(struct file *file);
15091 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15092 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15093 + int wlock, unsigned int fi_lsc);
15094 +int au_do_flush(struct file *file, fl_owner_t id,
15095 + int (*flush)(struct file *file, fl_owner_t id));
15098 +#ifdef CONFIG_AUFS_POLL
15099 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15102 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15104 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15106 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15107 + struct file *h_file);
15109 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15110 + aufs_bindex_t bindex, int force_wr)
15111 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15112 + struct file *h_file);
15116 +extern const struct file_operations aufs_file_fop;
15117 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15118 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15119 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15122 +void au_hfput(struct au_hfile *hf, int execed);
15123 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15124 + struct file *h_file);
15126 +void au_update_figen(struct file *file);
15127 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15128 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15130 +void au_fi_init_once(void *_fi);
15131 +void au_finfo_fin(struct file *file);
15132 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15135 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15136 +#ifdef CONFIG_COMPAT
15137 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15138 + unsigned long arg);
15139 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15140 + unsigned long arg);
15143 +/* ---------------------------------------------------------------------- */
15145 +static inline struct au_finfo *au_fi(struct file *file)
15147 + return file->private_data;
15150 +/* ---------------------------------------------------------------------- */
15152 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15153 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15154 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15155 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15157 +#define fi_read_trylock_nested(f) \
15158 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15159 +#define fi_write_trylock_nested(f) \
15160 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15163 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15164 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15165 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15167 +/* lock subclass for finfo */
15173 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15175 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15178 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15180 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15184 + * fi_read_lock_1, fi_write_lock_1,
15185 + * fi_read_lock_2, fi_write_lock_2
15187 +#define AuReadLockFunc(name) \
15188 +static inline void fi_read_lock_##name(struct file *f) \
15189 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15191 +#define AuWriteLockFunc(name) \
15192 +static inline void fi_write_lock_##name(struct file *f) \
15193 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15195 +#define AuRWLockFuncs(name) \
15196 + AuReadLockFunc(name) \
15197 + AuWriteLockFunc(name)
15202 +#undef AuReadLockFunc
15203 +#undef AuWriteLockFunc
15204 +#undef AuRWLockFuncs
15206 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15207 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15208 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15210 +/* ---------------------------------------------------------------------- */
15212 +/* todo: hard/soft set? */
15213 +static inline aufs_bindex_t au_fbtop(struct file *file)
15215 + FiMustAnyLock(file);
15216 + return au_fi(file)->fi_btop;
15219 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15221 + FiMustAnyLock(file);
15222 + AuDebugOn(!au_fi(file)->fi_hdir);
15223 + return au_fi(file)->fi_hdir->fd_bbot;
15226 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15228 + FiMustAnyLock(file);
15229 + AuDebugOn(!au_fi(file)->fi_hdir);
15230 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15233 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15235 + FiMustWriteLock(file);
15236 + au_fi(file)->fi_btop = bindex;
15239 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15241 + FiMustWriteLock(file);
15242 + AuDebugOn(!au_fi(file)->fi_hdir);
15243 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15246 +static inline void au_set_fvdir_cache(struct file *file,
15247 + struct au_vdir *vdir_cache)
15249 + FiMustWriteLock(file);
15250 + AuDebugOn(!au_fi(file)->fi_hdir);
15251 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15254 +static inline struct file *au_hf_top(struct file *file)
15256 + FiMustAnyLock(file);
15257 + AuDebugOn(au_fi(file)->fi_hdir);
15258 + return au_fi(file)->fi_htop.hf_file;
15261 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15263 + FiMustAnyLock(file);
15264 + AuDebugOn(!au_fi(file)->fi_hdir);
15265 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15268 +/* todo: memory barrier? */
15269 +static inline unsigned int au_figen(struct file *f)
15271 + return atomic_read(&au_fi(f)->fi_generation);
15274 +static inline void au_set_mmapped(struct file *f)
15276 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15278 + pr_warn("fi_mmapped wrapped around\n");
15279 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15283 +static inline void au_unset_mmapped(struct file *f)
15285 + atomic_dec(&au_fi(f)->fi_mmapped);
15288 +static inline int au_test_mmapped(struct file *f)
15290 + return atomic_read(&au_fi(f)->fi_mmapped);
15293 +/* customize vma->vm_file */
15295 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15296 + struct file *file)
15300 + f = vma->vm_file;
15302 + vma->vm_file = file;
15307 +#define AuDbgVmRegion(file, vma) do {} while (0)
15309 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15310 + struct file *file)
15312 + au_do_vm_file_reset(vma, file);
15315 +#define AuDbgVmRegion(file, vma) \
15316 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15318 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15319 + struct file *file)
15323 + au_do_vm_file_reset(vma, file);
15324 + f = vma->vm_region->vm_file;
15326 + vma->vm_region->vm_file = file;
15329 +#endif /* CONFIG_MMU */
15331 +/* handle vma->vm_prfile */
15332 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15333 + struct file *file)
15336 + vma->vm_prfile = file;
15337 +#ifndef CONFIG_MMU
15339 + vma->vm_region->vm_prfile = file;
15343 +#endif /* __KERNEL__ */
15344 +#endif /* __AUFS_FILE_H__ */
15345 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15346 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15347 +++ linux/fs/aufs/finfo.c 2020-01-27 10:57:18.172204883 +0100
15349 +// SPDX-License-Identifier: GPL-2.0
15351 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15353 + * This program, aufs is free software; you can redistribute it and/or modify
15354 + * it under the terms of the GNU General Public License as published by
15355 + * the Free Software Foundation; either version 2 of the License, or
15356 + * (at your option) any later version.
15358 + * This program is distributed in the hope that it will be useful,
15359 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15360 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15361 + * GNU General Public License for more details.
15363 + * You should have received a copy of the GNU General Public License
15364 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15368 + * file private data
15373 +void au_hfput(struct au_hfile *hf, int execed)
15376 + allow_write_access(hf->hf_file);
15377 + fput(hf->hf_file);
15378 + hf->hf_file = NULL;
15379 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15380 + hf->hf_br = NULL;
15383 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15385 + struct au_finfo *finfo = au_fi(file);
15386 + struct au_hfile *hf;
15387 + struct au_fidir *fidir;
15389 + fidir = finfo->fi_hdir;
15391 + AuDebugOn(finfo->fi_btop != bindex);
15392 + hf = &finfo->fi_htop;
15394 + hf = fidir->fd_hfile + bindex;
15396 + if (hf && hf->hf_file)
15397 + au_hfput(hf, vfsub_file_execed(file));
15399 + FiMustWriteLock(file);
15400 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15401 + hf->hf_file = val;
15402 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15406 +void au_update_figen(struct file *file)
15408 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15409 + /* smp_mb(); */ /* atomic_set */
15412 +/* ---------------------------------------------------------------------- */
15414 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15416 + struct au_fidir *fidir;
15419 + nbr = au_sbbot(sb) + 1;
15421 + nbr = 2; /* initial allocate for 2 branches */
15422 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15424 + fidir->fd_bbot = -1;
15425 + fidir->fd_nent = nbr;
15431 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15434 + struct au_fidir *fidir, *p;
15436 + AuRwMustWriteLock(&finfo->fi_rwsem);
15437 + fidir = finfo->fi_hdir;
15438 + AuDebugOn(!fidir);
15441 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15442 + GFP_NOFS, may_shrink);
15444 + p->fd_nent = nbr;
15445 + finfo->fi_hdir = p;
15452 +/* ---------------------------------------------------------------------- */
15454 +void au_finfo_fin(struct file *file)
15456 + struct au_finfo *finfo;
15458 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15460 + finfo = au_fi(file);
15461 + AuDebugOn(finfo->fi_hdir);
15462 + AuRwDestroy(&finfo->fi_rwsem);
15463 + au_cache_free_finfo(finfo);
15466 +void au_fi_init_once(void *_finfo)
15468 + struct au_finfo *finfo = _finfo;
15470 + au_rw_init(&finfo->fi_rwsem);
15473 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15476 + struct au_finfo *finfo;
15477 + struct dentry *dentry;
15480 + dentry = file->f_path.dentry;
15481 + finfo = au_cache_alloc_finfo();
15482 + if (unlikely(!finfo))
15486 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15487 + au_rw_write_lock(&finfo->fi_rwsem);
15488 + finfo->fi_btop = -1;
15489 + finfo->fi_hdir = fidir;
15490 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15491 + /* smp_mb(); */ /* atomic_set */
15493 + file->private_data = finfo;
15498 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15499 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15500 +++ linux/fs/aufs/f_op.c 2020-01-27 10:57:18.172204883 +0100
15502 +// SPDX-License-Identifier: GPL-2.0
15504 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15506 + * This program, aufs is free software; you can redistribute it and/or modify
15507 + * it under the terms of the GNU General Public License as published by
15508 + * the Free Software Foundation; either version 2 of the License, or
15509 + * (at your option) any later version.
15511 + * This program is distributed in the hope that it will be useful,
15512 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15513 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15514 + * GNU General Public License for more details.
15516 + * You should have received a copy of the GNU General Public License
15517 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15521 + * file and vm operations
15524 +#include <linux/aio.h>
15525 +#include <linux/fs_stack.h>
15526 +#include <linux/mman.h>
15527 +#include <linux/security.h>
15530 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15533 + aufs_bindex_t bindex;
15534 + struct dentry *dentry, *h_dentry;
15535 + struct au_finfo *finfo;
15536 + struct inode *h_inode;
15538 + FiMustWriteLock(file);
15541 + dentry = file->f_path.dentry;
15542 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15543 + finfo = au_fi(file);
15544 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15545 + atomic_set(&finfo->fi_mmapped, 0);
15546 + bindex = au_dbtop(dentry);
15548 + h_dentry = au_h_dptr(dentry, bindex);
15549 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15550 + if (unlikely(err))
15552 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15553 + if (IS_ERR(h_file)) {
15554 + err = PTR_ERR(h_file);
15558 + h_dentry = h_file->f_path.dentry;
15559 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15560 + if (unlikely(err))
15562 + /* br ref is already inc-ed */
15565 + if ((flags & __O_TMPFILE)
15566 + && !(flags & O_EXCL)) {
15567 + h_inode = file_inode(h_file);
15568 + spin_lock(&h_inode->i_lock);
15569 + h_inode->i_state |= I_LINKABLE;
15570 + spin_unlock(&h_inode->i_lock);
15572 + au_set_fbtop(file, bindex);
15573 + au_set_h_fptr(file, bindex, h_file);
15574 + au_update_figen(file);
15575 + /* todo: necessary? */
15576 + /* file->f_ra = h_file->f_ra; */
15582 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15583 + struct file *file)
15586 + struct super_block *sb;
15587 + struct au_do_open_args args = {
15588 + .open = au_do_open_nondir
15591 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15592 + file, vfsub_file_flags(file), file->f_mode);
15594 + sb = file->f_path.dentry->d_sb;
15595 + si_read_lock(sb, AuLock_FLUSH);
15596 + err = au_do_open(file, &args);
15597 + si_read_unlock(sb);
15601 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15603 + struct au_finfo *finfo;
15604 + aufs_bindex_t bindex;
15606 + finfo = au_fi(file);
15607 + au_hbl_del(&finfo->fi_hlist,
15608 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15609 + bindex = finfo->fi_btop;
15611 + au_set_h_fptr(file, bindex, NULL);
15613 + au_finfo_fin(file);
15617 +/* ---------------------------------------------------------------------- */
15619 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15622 + struct file *h_file;
15625 + h_file = au_hf_top(file);
15627 + err = vfsub_flush(h_file, id);
15631 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15633 + return au_do_flush(file, id, au_do_flush_nondir);
15636 +/* ---------------------------------------------------------------------- */
15638 + * read and write functions acquire [fdi]_rwsem once, but release before
15639 + * mmap_sem. This is because to stop a race condition between mmap(2).
15640 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15641 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15642 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15645 +/* Callers should call au_read_post() or fput() in the end */
15646 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15648 + struct file *h_file;
15651 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15653 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15654 + h_file = au_hf_top(file);
15655 + get_file(h_file);
15657 + fi_read_unlock(file);
15659 + h_file = ERR_PTR(err);
15664 +static void au_read_post(struct inode *inode, struct file *h_file)
15666 + /* update without lock, I don't think it a problem */
15667 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15671 +struct au_write_pre {
15673 + unsigned int lsc;
15677 + aufs_bindex_t btop;
15681 + * return with iinfo is write-locked
15682 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15685 +static struct file *au_write_pre(struct file *file, int do_ready,
15686 + struct au_write_pre *wpre)
15688 + struct file *h_file;
15689 + struct dentry *dentry;
15691 + unsigned int lsc;
15692 + struct au_pin pin;
15697 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15698 + h_file = ERR_PTR(err);
15699 + if (unlikely(err))
15702 + dentry = file->f_path.dentry;
15704 + err = au_ready_to_write(file, -1, &pin);
15705 + if (unlikely(err)) {
15706 + h_file = ERR_PTR(err);
15707 + di_write_unlock(dentry);
15712 + di_downgrade_lock(dentry, /*flags*/0);
15714 + wpre->btop = au_fbtop(file);
15715 + h_file = au_hf_top(file);
15716 + get_file(h_file);
15718 + wpre->blks = file_inode(h_file)->i_blocks;
15721 + di_read_unlock(dentry, /*flags*/0);
15724 + fi_write_unlock(file);
15729 +static void au_write_post(struct inode *inode, struct file *h_file,
15730 + struct au_write_pre *wpre, ssize_t written)
15732 + struct inode *h_inode;
15734 + au_cpup_attr_timesizes(inode);
15735 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15736 + h_inode = file_inode(h_file);
15737 + inode->i_mode = h_inode->i_mode;
15738 + ii_write_unlock(inode);
15739 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15741 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15742 + /*force*/h_inode->i_blocks > wpre->blks);
15746 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
15750 + struct inode *inode;
15751 + struct file *h_file;
15752 + struct super_block *sb;
15754 + inode = file_inode(file);
15755 + sb = inode->i_sb;
15756 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15758 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15759 + err = PTR_ERR(h_file);
15760 + if (IS_ERR(h_file))
15763 + /* filedata may be obsoleted by concurrent copyup, but no problem */
15764 + err = vfsub_read_u(h_file, buf, count, ppos);
15765 + /* todo: necessary? */
15766 + /* file->f_ra = h_file->f_ra; */
15767 + au_read_post(inode, h_file);
15770 + si_read_unlock(sb);
15775 + * todo: very ugly
15776 + * it locks both of i_mutex and si_rwsem for read in safe.
15777 + * if the plink maintenance mode continues forever (that is the problem),
15778 + * may loop forever.
15780 +static void au_mtx_and_read_lock(struct inode *inode)
15783 + struct super_block *sb = inode->i_sb;
15786 + inode_lock(inode);
15787 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15790 + inode_unlock(inode);
15791 + si_read_lock(sb, AuLock_NOPLMW);
15792 + si_read_unlock(sb);
15796 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
15797 + size_t count, loff_t *ppos)
15800 + struct au_write_pre wpre;
15801 + struct inode *inode;
15802 + struct file *h_file;
15803 + char __user *buf = (char __user *)ubuf;
15805 + inode = file_inode(file);
15806 + au_mtx_and_read_lock(inode);
15809 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15810 + err = PTR_ERR(h_file);
15811 + if (IS_ERR(h_file))
15814 + err = vfsub_write_u(h_file, buf, count, ppos);
15815 + au_write_post(inode, h_file, &wpre, err);
15818 + si_read_unlock(inode->i_sb);
15819 + inode_unlock(inode);
15823 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15824 + struct iov_iter *iov_iter)
15827 + struct file *file;
15828 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15830 + err = security_file_permission(h_file, rw);
15831 + if (unlikely(err))
15834 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15836 + if (rw == MAY_READ)
15837 + iter = h_file->f_op->read_iter;
15838 + else if (rw == MAY_WRITE)
15839 + iter = h_file->f_op->write_iter;
15841 + file = kio->ki_filp;
15842 + kio->ki_filp = h_file;
15845 + err = iter(kio, iov_iter);
15848 + /* currently there is no such fs */
15850 + kio->ki_filp = file;
15856 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15859 + struct file *file, *h_file;
15860 + struct inode *inode;
15861 + struct super_block *sb;
15863 + file = kio->ki_filp;
15864 + inode = file_inode(file);
15865 + sb = inode->i_sb;
15866 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15868 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15869 + err = PTR_ERR(h_file);
15870 + if (IS_ERR(h_file))
15873 + if (au_test_loopback_kthread()) {
15874 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15875 + if (file->f_mapping != h_file->f_mapping) {
15876 + file->f_mapping = h_file->f_mapping;
15877 + smp_mb(); /* unnecessary? */
15880 + fi_read_unlock(file);
15882 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15883 + /* todo: necessary? */
15884 + /* file->f_ra = h_file->f_ra; */
15885 + au_read_post(inode, h_file);
15888 + si_read_unlock(sb);
15892 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15895 + struct au_write_pre wpre;
15896 + struct inode *inode;
15897 + struct file *file, *h_file;
15899 + file = kio->ki_filp;
15900 + inode = file_inode(file);
15901 + au_mtx_and_read_lock(inode);
15904 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15905 + err = PTR_ERR(h_file);
15906 + if (IS_ERR(h_file))
15909 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15910 + au_write_post(inode, h_file, &wpre, err);
15913 + si_read_unlock(inode->i_sb);
15914 + inode_unlock(inode);
15918 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15919 + struct pipe_inode_info *pipe, size_t len,
15920 + unsigned int flags)
15923 + struct file *h_file;
15924 + struct inode *inode;
15925 + struct super_block *sb;
15927 + inode = file_inode(file);
15928 + sb = inode->i_sb;
15929 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15931 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15932 + err = PTR_ERR(h_file);
15933 + if (IS_ERR(h_file))
15936 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15937 + /* todo: necessary? */
15938 + /* file->f_ra = h_file->f_ra; */
15939 + au_read_post(inode, h_file);
15942 + si_read_unlock(sb);
15947 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15948 + size_t len, unsigned int flags)
15951 + struct au_write_pre wpre;
15952 + struct inode *inode;
15953 + struct file *h_file;
15955 + inode = file_inode(file);
15956 + au_mtx_and_read_lock(inode);
15959 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15960 + err = PTR_ERR(h_file);
15961 + if (IS_ERR(h_file))
15964 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15965 + au_write_post(inode, h_file, &wpre, err);
15968 + si_read_unlock(inode->i_sb);
15969 + inode_unlock(inode);
15973 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15977 + struct au_write_pre wpre;
15978 + struct inode *inode;
15979 + struct file *h_file;
15981 + inode = file_inode(file);
15982 + au_mtx_and_read_lock(inode);
15985 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15986 + err = PTR_ERR(h_file);
15987 + if (IS_ERR(h_file))
15991 + err = vfs_fallocate(h_file, mode, offset, len);
15993 + au_write_post(inode, h_file, &wpre, /*written*/1);
15996 + si_read_unlock(inode->i_sb);
15997 + inode_unlock(inode);
16001 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
16002 + struct file *dst, loff_t dst_pos,
16003 + size_t len, unsigned int flags)
16006 + struct au_write_pre wpre;
16007 + enum { SRC, DST };
16009 + struct inode *inode;
16010 + struct file *h_file;
16011 + struct super_block *h_sb;
16013 +#define a_src a[SRC]
16014 +#define a_dst a[DST]
16017 + a_src.inode = file_inode(src);
16018 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
16020 + a_dst.inode = file_inode(dst);
16021 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
16024 + au_mtx_and_read_lock(a_dst.inode);
16026 + * in order to match the order in di_write_lock2_{child,parent}(),
16027 + * use f_path.dentry for this comparison.
16029 + if (src->f_path.dentry < dst->f_path.dentry) {
16030 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
16031 + err = PTR_ERR(a_src.h_file);
16032 + if (IS_ERR(a_src.h_file))
16035 + wpre.lsc = AuLsc_FI_2;
16036 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16037 + err = PTR_ERR(a_dst.h_file);
16038 + if (IS_ERR(a_dst.h_file)) {
16039 + au_read_post(a_src.inode, a_src.h_file);
16043 + wpre.lsc = AuLsc_FI_1;
16044 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16045 + err = PTR_ERR(a_dst.h_file);
16046 + if (IS_ERR(a_dst.h_file))
16049 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
16050 + err = PTR_ERR(a_src.h_file);
16051 + if (IS_ERR(a_src.h_file)) {
16052 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
16059 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
16060 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
16061 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
16067 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
16068 + dst_pos, len, flags);
16071 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
16072 + fi_read_unlock(src);
16073 + au_read_post(a_src.inode, a_src.h_file);
16075 + si_read_unlock(a_dst.inode->i_sb);
16076 + inode_unlock(a_dst.inode);
16083 +/* ---------------------------------------------------------------------- */
16086 + * The locking order around current->mmap_sem.
16087 + * - in most and regular cases
16088 + * file I/O syscall -- aufs_read() or something
16089 + * -- si_rwsem for read -- mmap_sem
16090 + * (Note that [fdi]i_rwsem are released before mmap_sem).
16092 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
16093 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
16094 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
16095 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
16096 + * It means that when aufs acquires si_rwsem for write, the process should never
16097 + * acquire mmap_sem.
16099 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
16100 + * problem either since any directory is not able to be mmap-ed.
16101 + * The similar scenario is applied to aufs_readlink() too.
16104 +#if 0 /* stop calling security_file_mmap() */
16105 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
16106 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
16108 +static unsigned long au_arch_prot_conv(unsigned long flags)
16110 + /* currently ppc64 only */
16111 +#ifdef CONFIG_PPC64
16112 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16113 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16114 + return AuConv_VM_PROT(flags, SAO);
16116 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16121 +static unsigned long au_prot_conv(unsigned long flags)
16123 + return AuConv_VM_PROT(flags, READ)
16124 + | AuConv_VM_PROT(flags, WRITE)
16125 + | AuConv_VM_PROT(flags, EXEC)
16126 + | au_arch_prot_conv(flags);
16129 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16130 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16132 +static unsigned long au_flag_conv(unsigned long flags)
16134 + return AuConv_VM_MAP(flags, GROWSDOWN)
16135 + | AuConv_VM_MAP(flags, DENYWRITE)
16136 + | AuConv_VM_MAP(flags, LOCKED);
16140 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16143 + const unsigned char wlock
16144 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16145 + struct super_block *sb;
16146 + struct file *h_file;
16147 + struct inode *inode;
16149 + AuDbgVmRegion(file, vma);
16151 + inode = file_inode(file);
16152 + sb = inode->i_sb;
16154 + si_read_lock(sb, AuLock_NOPLMW);
16156 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16158 + err = PTR_ERR(h_file);
16159 + if (IS_ERR(h_file))
16163 + au_set_mmapped(file);
16164 + au_vm_file_reset(vma, h_file);
16166 + * we cannot call security_mmap_file() here since it may acquire
16167 + * mmap_sem or i_mutex.
16169 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16170 + * au_flag_conv(vma->vm_flags));
16173 + err = call_mmap(h_file, vma);
16175 + au_vm_prfile_set(vma, file);
16176 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16177 + goto out_fput; /* success */
16179 + au_unset_mmapped(file);
16180 + au_vm_file_reset(vma, file);
16184 + ii_write_unlock(inode);
16189 + si_read_unlock(sb);
16195 +/* ---------------------------------------------------------------------- */
16197 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16201 + struct au_write_pre wpre;
16202 + struct inode *inode;
16203 + struct file *h_file;
16205 + err = 0; /* -EBADF; */ /* posix? */
16206 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16209 + inode = file_inode(file);
16210 + au_mtx_and_read_lock(inode);
16213 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16214 + err = PTR_ERR(h_file);
16215 + if (IS_ERR(h_file))
16218 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16219 + au_write_post(inode, h_file, &wpre, /*written*/0);
16222 + si_read_unlock(inode->i_sb);
16223 + inode_unlock(inode);
16228 +static int aufs_fasync(int fd, struct file *file, int flag)
16231 + struct file *h_file;
16232 + struct super_block *sb;
16234 + sb = file->f_path.dentry->d_sb;
16235 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16237 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16238 + err = PTR_ERR(h_file);
16239 + if (IS_ERR(h_file))
16242 + if (h_file->f_op->fasync)
16243 + err = h_file->f_op->fasync(fd, h_file, flag);
16244 + fput(h_file); /* instead of au_read_post() */
16247 + si_read_unlock(sb);
16251 +static int aufs_setfl(struct file *file, unsigned long arg)
16254 + struct file *h_file;
16255 + struct super_block *sb;
16257 + sb = file->f_path.dentry->d_sb;
16258 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16260 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16261 + err = PTR_ERR(h_file);
16262 + if (IS_ERR(h_file))
16265 + /* stop calling h_file->fasync */
16266 + arg |= vfsub_file_flags(file) & FASYNC;
16267 + err = setfl(/*unused fd*/-1, h_file, arg);
16268 + fput(h_file); /* instead of au_read_post() */
16271 + si_read_unlock(sb);
16275 +/* ---------------------------------------------------------------------- */
16277 +/* no one supports this operation, currently */
16278 +#if 0 /* reserved for future use */
16279 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16280 + size_t len, loff_t *pos, int more)
16285 +/* ---------------------------------------------------------------------- */
16287 +const struct file_operations aufs_file_fop = {
16288 + .owner = THIS_MODULE,
16290 + .llseek = default_llseek,
16292 + .read = aufs_read,
16293 + .write = aufs_write,
16294 + .read_iter = aufs_read_iter,
16295 + .write_iter = aufs_write_iter,
16297 +#ifdef CONFIG_AUFS_POLL
16298 + .poll = aufs_poll,
16300 + .unlocked_ioctl = aufs_ioctl_nondir,
16301 +#ifdef CONFIG_COMPAT
16302 + .compat_ioctl = aufs_compat_ioctl_nondir,
16304 + .mmap = aufs_mmap,
16305 + .open = aufs_open_nondir,
16306 + .flush = aufs_flush_nondir,
16307 + .release = aufs_release_nondir,
16308 + .fsync = aufs_fsync_nondir,
16309 + .fasync = aufs_fasync,
16310 + /* .sendpage = aufs_sendpage, */
16311 + .setfl = aufs_setfl,
16312 + .splice_write = aufs_splice_write,
16313 + .splice_read = aufs_splice_read,
16314 +#if 0 /* reserved for future use */
16315 + .aio_splice_write = aufs_aio_splice_write,
16316 + .aio_splice_read = aufs_aio_splice_read,
16318 + .fallocate = aufs_fallocate,
16319 + .copy_file_range = aufs_copy_file_range
16321 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16322 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16323 +++ linux/fs/aufs/fstype.h 2020-01-27 10:57:18.172204883 +0100
16325 +/* SPDX-License-Identifier: GPL-2.0 */
16327 + * Copyright (C) 2005-2020 Junjiro R. Okajima
16329 + * This program, aufs is free software; you can redistribute it and/or modify
16330 + * it under the terms of the GNU General Public License as published by
16331 + * the Free Software Foundation; either version 2 of the License, or
16332 + * (at your option) any later version.
16334 + * This program is distributed in the hope that it will be useful,
16335 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16336 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16337 + * GNU General Public License for more details.
16339 + * You should have received a copy of the GNU General Public License
16340 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16344 + * judging filesystem type
16347 +#ifndef __AUFS_FSTYPE_H__
16348 +#define __AUFS_FSTYPE_H__
16352 +#include <linux/fs.h>
16353 +#include <linux/magic.h>
16354 +#include <linux/nfs_fs.h>
16355 +#include <linux/romfs_fs.h>
16357 +static inline int au_test_aufs(struct super_block *sb)
16359 + return sb->s_magic == AUFS_SUPER_MAGIC;
16362 +static inline const char *au_sbtype(struct super_block *sb)
16364 + return sb->s_type->name;
16367 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16369 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16370 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16376 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16378 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16379 + return sb->s_magic == ROMFS_MAGIC;
16385 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16387 +#if IS_ENABLED(CONFIG_CRAMFS)
16388 + return sb->s_magic == CRAMFS_MAGIC;
16393 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16395 +#if IS_ENABLED(CONFIG_NFS_FS)
16396 + return sb->s_magic == NFS_SUPER_MAGIC;
16402 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16404 +#if IS_ENABLED(CONFIG_FUSE_FS)
16405 + return sb->s_magic == FUSE_SUPER_MAGIC;
16411 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16413 +#if IS_ENABLED(CONFIG_XFS_FS)
16414 + return sb->s_magic == XFS_SB_MAGIC;
16420 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16422 +#ifdef CONFIG_TMPFS
16423 + return sb->s_magic == TMPFS_MAGIC;
16429 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16431 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16432 + return !strcmp(au_sbtype(sb), "ecryptfs");
16438 +static inline int au_test_ramfs(struct super_block *sb)
16440 + return sb->s_magic == RAMFS_MAGIC;
16443 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16445 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16446 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16452 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16454 +#ifdef CONFIG_PROC_FS
16455 + return sb->s_magic == PROC_SUPER_MAGIC;
16461 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16463 +#ifdef CONFIG_SYSFS
16464 + return sb->s_magic == SYSFS_MAGIC;
16470 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16472 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16473 + return sb->s_magic == CONFIGFS_MAGIC;
16479 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16481 +#if IS_ENABLED(CONFIG_MINIX_FS)
16482 + return sb->s_magic == MINIX3_SUPER_MAGIC
16483 + || sb->s_magic == MINIX2_SUPER_MAGIC
16484 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16485 + || sb->s_magic == MINIX_SUPER_MAGIC
16486 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16492 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16494 +#if IS_ENABLED(CONFIG_FAT_FS)
16495 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16501 +static inline int au_test_msdos(struct super_block *sb)
16503 + return au_test_fat(sb);
16506 +static inline int au_test_vfat(struct super_block *sb)
16508 + return au_test_fat(sb);
16511 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16513 +#ifdef CONFIG_SECURITYFS
16514 + return sb->s_magic == SECURITYFS_MAGIC;
16520 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16522 +#if IS_ENABLED(CONFIG_SQUASHFS)
16523 + return sb->s_magic == SQUASHFS_MAGIC;
16529 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16531 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16532 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16538 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16540 +#if IS_ENABLED(CONFIG_XENFS)
16541 + return sb->s_magic == XENFS_SUPER_MAGIC;
16547 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16549 +#ifdef CONFIG_DEBUG_FS
16550 + return sb->s_magic == DEBUGFS_MAGIC;
16556 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16558 +#if IS_ENABLED(CONFIG_NILFS)
16559 + return sb->s_magic == NILFS_SUPER_MAGIC;
16565 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16567 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16568 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16574 +/* ---------------------------------------------------------------------- */
16576 + * they can't be an aufs branch.
16578 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16581 +#ifndef CONFIG_AUFS_BR_RAMFS
16582 + au_test_ramfs(sb) ||
16584 + au_test_procfs(sb)
16585 + || au_test_sysfs(sb)
16586 + || au_test_configfs(sb)
16587 + || au_test_debugfs(sb)
16588 + || au_test_securityfs(sb)
16589 + || au_test_xenfs(sb)
16590 + || au_test_ecryptfs(sb)
16591 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16592 + || au_test_aufs(sb); /* will be supported in next version */
16595 +static inline int au_test_fs_remote(struct super_block *sb)
16597 + return !au_test_tmpfs(sb)
16598 +#ifdef CONFIG_AUFS_BR_RAMFS
16599 + && !au_test_ramfs(sb)
16601 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16604 +/* ---------------------------------------------------------------------- */
16607 + * Note: these functions (below) are created after reading ->getattr() in all
16608 + * filesystems under linux/fs. it means we have to do so in every update...
16612 + * some filesystems require getattr to refresh the inode attributes before
16614 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16615 + * and leave the work for d_revalidate()
16617 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16619 + return au_test_nfs(sb)
16620 + || au_test_fuse(sb)
16621 + /* || au_test_btrfs(sb) */ /* untested */
16626 + * filesystems which don't maintain i_size or i_blocks.
16628 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16630 + return au_test_xfs(sb)
16631 + || au_test_btrfs(sb)
16632 + || au_test_ubifs(sb)
16633 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16634 + /* || au_test_minix(sb) */ /* untested */
16639 + * filesystems which don't store the correct value in some of their inode
16642 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16644 + return au_test_fs_bad_iattr_size(sb)
16645 + || au_test_fat(sb)
16646 + || au_test_msdos(sb)
16647 + || au_test_vfat(sb);
16650 +/* they don't check i_nlink in link(2) */
16651 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16653 + return au_test_tmpfs(sb)
16654 +#ifdef CONFIG_AUFS_BR_RAMFS
16655 + || au_test_ramfs(sb)
16657 + || au_test_ubifs(sb)
16658 + || au_test_hfsplus(sb);
16662 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16664 +static inline int au_test_fs_notime(struct super_block *sb)
16666 + return au_test_nfs(sb)
16667 + || au_test_fuse(sb)
16668 + || au_test_ubifs(sb)
16672 +/* temporary support for i#1 in cramfs */
16673 +static inline int au_test_fs_unique_ino(struct inode *inode)
16675 + if (au_test_cramfs(inode->i_sb))
16676 + return inode->i_ino != 1;
16680 +/* ---------------------------------------------------------------------- */
16683 + * the filesystem where the xino files placed must support i/o after unlink and
16684 + * maintain i_size and i_blocks.
16686 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16688 + return au_test_fs_remote(sb)
16689 + || au_test_fs_bad_iattr_size(sb)
16690 + /* don't want unnecessary work for xino */
16691 + || au_test_aufs(sb)
16692 + || au_test_ecryptfs(sb)
16693 + || au_test_nilfs(sb);
16696 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16698 + return au_test_tmpfs(sb)
16699 + || au_test_ramfs(sb);
16703 + * test if the @sb is real-readonly.
16705 +static inline int au_test_fs_rr(struct super_block *sb)
16707 + return au_test_squashfs(sb)
16708 + || au_test_iso9660(sb)
16709 + || au_test_cramfs(sb)
16710 + || au_test_romfs(sb);
16714 + * test if the @inode is nfs with 'noacl' option
16715 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16717 +static inline int au_test_nfs_noacl(struct inode *inode)
16719 + return au_test_nfs(inode->i_sb)
16720 + /* && IS_POSIXACL(inode) */
16721 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16724 +#endif /* __KERNEL__ */
16725 +#endif /* __AUFS_FSTYPE_H__ */
16726 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16727 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16728 +++ linux/fs/aufs/hbl.h 2020-01-27 10:57:18.172204883 +0100
16730 +/* SPDX-License-Identifier: GPL-2.0 */
16732 + * Copyright (C) 2017-2020 Junjiro R. Okajima
16734 + * This program, aufs is free software; you can redistribute it and/or modify
16735 + * it under the terms of the GNU General Public License as published by
16736 + * the Free Software Foundation; either version 2 of the License, or
16737 + * (at your option) any later version.
16739 + * This program is distributed in the hope that it will be useful,
16740 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16741 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16742 + * GNU General Public License for more details.
16744 + * You should have received a copy of the GNU General Public License
16745 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16749 + * helpers for hlist_bl.h
16752 +#ifndef __AUFS_HBL_H__
16753 +#define __AUFS_HBL_H__
16757 +#include <linux/list_bl.h>
16759 +static inline void au_hbl_add(struct hlist_bl_node *node,
16760 + struct hlist_bl_head *hbl)
16762 + hlist_bl_lock(hbl);
16763 + hlist_bl_add_head(node, hbl);
16764 + hlist_bl_unlock(hbl);
16767 +static inline void au_hbl_del(struct hlist_bl_node *node,
16768 + struct hlist_bl_head *hbl)
16770 + hlist_bl_lock(hbl);
16771 + hlist_bl_del(node);
16772 + hlist_bl_unlock(hbl);
16775 +#define au_hbl_for_each(pos, head) \
16776 + for (pos = hlist_bl_first(head); \
16780 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16782 + unsigned long cnt;
16783 + struct hlist_bl_node *pos;
16786 + hlist_bl_lock(hbl);
16787 + au_hbl_for_each(pos, hbl)
16789 + hlist_bl_unlock(hbl);
16793 +#endif /* __KERNEL__ */
16794 +#endif /* __AUFS_HBL_H__ */
16795 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16796 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16797 +++ linux/fs/aufs/hfsnotify.c 2020-01-27 10:57:18.172204883 +0100
16799 +// SPDX-License-Identifier: GPL-2.0
16801 + * Copyright (C) 2005-2020 Junjiro R. Okajima
16803 + * This program, aufs is free software; you can redistribute it and/or modify
16804 + * it under the terms of the GNU General Public License as published by
16805 + * the Free Software Foundation; either version 2 of the License, or
16806 + * (at your option) any later version.
16808 + * This program is distributed in the hope that it will be useful,
16809 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16810 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16811 + * GNU General Public License for more details.
16813 + * You should have received a copy of the GNU General Public License
16814 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16818 + * fsnotify for the lower directories
16823 +/* FS_IN_IGNORED is unnecessary */
16824 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16825 + | FS_CREATE | FS_EVENT_ON_CHILD);
16826 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16827 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16829 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16831 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16833 + /* AuDbg("here\n"); */
16834 + au_cache_free_hnotify(hn);
16835 + smp_mb__before_atomic(); /* for atomic64_dec */
16836 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16837 + wake_up(&au_hfsn_wq);
16840 +static int au_hfsn_alloc(struct au_hinode *hinode)
16843 + struct au_hnotify *hn;
16844 + struct super_block *sb;
16845 + struct au_branch *br;
16846 + struct fsnotify_mark *mark;
16847 + aufs_bindex_t bindex;
16849 + hn = hinode->hi_notify;
16850 + sb = hn->hn_aufs_inode->i_sb;
16851 + bindex = au_br_index(sb, hinode->hi_id);
16852 + br = au_sbr(sb, bindex);
16853 + AuDebugOn(!br->br_hfsn);
16855 + mark = &hn->hn_mark;
16856 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16857 + mark->mask = AuHfsnMask;
16859 + * by udba rename or rmdir, aufs assign a new inode to the known
16860 + * h_inode, so specify 1 to allow dups.
16863 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16869 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16871 + struct fsnotify_mark *mark;
16872 + unsigned long long ull;
16873 + struct fsnotify_group *group;
16875 + ull = atomic64_inc_return(&au_hfsn_ifree);
16878 + mark = &hn->hn_mark;
16879 + spin_lock(&mark->lock);
16880 + group = mark->group;
16881 + fsnotify_get_group(group);
16882 + spin_unlock(&mark->lock);
16884 + fsnotify_destroy_mark(mark, group);
16885 + fsnotify_put_mark(mark);
16886 + fsnotify_put_group(group);
16889 + /* free hn by myself */
16893 +/* ---------------------------------------------------------------------- */
16895 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16897 + struct fsnotify_mark *mark;
16899 + mark = &hinode->hi_notify->hn_mark;
16900 + spin_lock(&mark->lock);
16902 + AuDebugOn(mark->mask & AuHfsnMask);
16903 + mark->mask |= AuHfsnMask;
16905 + AuDebugOn(!(mark->mask & AuHfsnMask));
16906 + mark->mask &= ~AuHfsnMask;
16908 + spin_unlock(&mark->lock);
16909 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16912 +/* ---------------------------------------------------------------------- */
16914 +/* #define AuDbgHnotify */
16915 +#ifdef AuDbgHnotify
16916 +static char *au_hfsn_name(u32 mask)
16918 +#ifdef CONFIG_AUFS_DEBUG
16919 +#define test_ret(flag) \
16921 + if (mask & flag) \
16924 + test_ret(FS_ACCESS);
16925 + test_ret(FS_MODIFY);
16926 + test_ret(FS_ATTRIB);
16927 + test_ret(FS_CLOSE_WRITE);
16928 + test_ret(FS_CLOSE_NOWRITE);
16929 + test_ret(FS_OPEN);
16930 + test_ret(FS_MOVED_FROM);
16931 + test_ret(FS_MOVED_TO);
16932 + test_ret(FS_CREATE);
16933 + test_ret(FS_DELETE);
16934 + test_ret(FS_DELETE_SELF);
16935 + test_ret(FS_MOVE_SELF);
16936 + test_ret(FS_UNMOUNT);
16937 + test_ret(FS_Q_OVERFLOW);
16938 + test_ret(FS_IN_IGNORED);
16939 + test_ret(FS_ISDIR);
16940 + test_ret(FS_IN_ONESHOT);
16941 + test_ret(FS_EVENT_ON_CHILD);
16950 +/* ---------------------------------------------------------------------- */
16952 +static void au_hfsn_free_group(struct fsnotify_group *group)
16954 + struct au_br_hfsnotify *hfsn = group->private;
16956 + /* AuDbg("here\n"); */
16957 + au_kfree_try_rcu(hfsn);
16960 +static int au_hfsn_handle_event(struct fsnotify_group *group,
16961 + struct inode *inode,
16962 + u32 mask, const void *data, int data_type,
16963 + const struct qstr *file_name, u32 cookie,
16964 + struct fsnotify_iter_info *iter_info)
16967 + struct au_hnotify *hnotify;
16968 + struct inode *h_dir, *h_inode;
16969 + struct fsnotify_mark *inode_mark;
16971 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
16974 + /* if FS_UNMOUNT happens, there must be another bug */
16975 + AuDebugOn(mask & FS_UNMOUNT);
16976 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
16981 +#ifdef AuDbgHnotify
16983 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
16984 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
16985 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
16986 + h_dir->i_ino, mask, au_hfsn_name(mask),
16987 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
16988 + /* WARN_ON(1); */
16993 + inode_mark = fsnotify_iter_inode_mark(iter_info);
16994 + AuDebugOn(!inode_mark);
16995 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
16996 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
17002 +static struct fsnotify_ops au_hfsn_ops = {
17003 + .handle_event = au_hfsn_handle_event,
17004 + .free_group_priv = au_hfsn_free_group,
17005 + .free_mark = au_hfsn_free_mark
17008 +/* ---------------------------------------------------------------------- */
17010 +static void au_hfsn_fin_br(struct au_branch *br)
17012 + struct au_br_hfsnotify *hfsn;
17014 + hfsn = br->br_hfsn;
17017 + fsnotify_put_group(hfsn->hfsn_group);
17022 +static int au_hfsn_init_br(struct au_branch *br, int perm)
17025 + struct fsnotify_group *group;
17026 + struct au_br_hfsnotify *hfsn;
17029 + br->br_hfsn = NULL;
17030 + if (!au_br_hnotifyable(perm))
17034 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
17035 + if (unlikely(!hfsn))
17039 + group = fsnotify_alloc_group(&au_hfsn_ops);
17040 + if (IS_ERR(group)) {
17041 + err = PTR_ERR(group);
17042 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
17046 + group->private = hfsn;
17047 + hfsn->hfsn_group = group;
17048 + br->br_hfsn = hfsn;
17049 + goto out; /* success */
17052 + au_kfree_try_rcu(hfsn);
17057 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
17062 + if (!br->br_hfsn)
17063 + err = au_hfsn_init_br(br, perm);
17068 +/* ---------------------------------------------------------------------- */
17070 +static void au_hfsn_fin(void)
17072 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
17073 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
17076 +const struct au_hnotify_op au_hnotify_op = {
17077 + .ctl = au_hfsn_ctl,
17078 + .alloc = au_hfsn_alloc,
17079 + .free = au_hfsn_free,
17081 + .fin = au_hfsn_fin,
17083 + .reset_br = au_hfsn_reset_br,
17084 + .fin_br = au_hfsn_fin_br,
17085 + .init_br = au_hfsn_init_br
17087 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
17088 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
17089 +++ linux/fs/aufs/hfsplus.c 2020-01-27 10:57:18.172204883 +0100
17091 +// SPDX-License-Identifier: GPL-2.0
17093 + * Copyright (C) 2010-2020 Junjiro R. Okajima
17095 + * This program, aufs is free software; you can redistribute it and/or modify
17096 + * it under the terms of the GNU General Public License as published by
17097 + * the Free Software Foundation; either version 2 of the License, or
17098 + * (at your option) any later version.
17100 + * This program is distributed in the hope that it will be useful,
17101 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17102 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17103 + * GNU General Public License for more details.
17105 + * You should have received a copy of the GNU General Public License
17106 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17110 + * special support for filesystems which acquires an inode mutex
17111 + * at final closing a file, eg, hfsplus.
17113 + * This trick is very simple and stupid, just to open the file before really
17114 + * necessary open to tell hfsplus that this is not the final closing.
17115 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
17116 + * and au_h_open_post() after releasing it.
17121 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
17124 + struct file *h_file;
17125 + struct dentry *h_dentry;
17127 + h_dentry = au_h_dptr(dentry, bindex);
17128 + AuDebugOn(!h_dentry);
17129 + AuDebugOn(d_is_negative(h_dentry));
17132 + if (au_test_hfsplus(h_dentry->d_sb)
17133 + && d_is_reg(h_dentry))
17134 + h_file = au_h_open(dentry, bindex,
17135 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17136 + /*file*/NULL, force_wr);
17140 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17141 + struct file *h_file)
17143 + struct au_branch *br;
17147 + br = au_sbr(dentry->d_sb, bindex);
17148 + au_lcnt_dec(&br->br_nfiles);
17151 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17152 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17153 +++ linux/fs/aufs/hnotify.c 2020-01-27 10:57:18.172204883 +0100
17155 +// SPDX-License-Identifier: GPL-2.0
17157 + * Copyright (C) 2005-2020 Junjiro R. Okajima
17159 + * This program, aufs is free software; you can redistribute it and/or modify
17160 + * it under the terms of the GNU General Public License as published by
17161 + * the Free Software Foundation; either version 2 of the License, or
17162 + * (at your option) any later version.
17164 + * This program is distributed in the hope that it will be useful,
17165 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17166 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17167 + * GNU General Public License for more details.
17169 + * You should have received a copy of the GNU General Public License
17170 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17174 + * abstraction to notify the direct changes on lower directories
17177 +/* #include <linux/iversion.h> */
17180 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17183 + struct au_hnotify *hn;
17186 + hn = au_cache_alloc_hnotify();
17188 + hn->hn_aufs_inode = inode;
17189 + hinode->hi_notify = hn;
17190 + err = au_hnotify_op.alloc(hinode);
17192 + if (unlikely(err)) {
17193 + hinode->hi_notify = NULL;
17194 + au_cache_free_hnotify(hn);
17196 + * The upper dir was removed by udba, but the same named
17197 + * dir left. In this case, aufs assigns a new inode
17198 + * number and set the monitor again.
17199 + * For the lower dir, the old monitor is still left.
17201 + if (err == -EEXIST)
17210 +void au_hn_free(struct au_hinode *hinode)
17212 + struct au_hnotify *hn;
17214 + hn = hinode->hi_notify;
17216 + hinode->hi_notify = NULL;
17217 + if (au_hnotify_op.free(hinode, hn))
17218 + au_cache_free_hnotify(hn);
17222 +/* ---------------------------------------------------------------------- */
17224 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17226 + if (hinode->hi_notify)
17227 + au_hnotify_op.ctl(hinode, do_set);
17230 +void au_hn_reset(struct inode *inode, unsigned int flags)
17232 + aufs_bindex_t bindex, bbot;
17233 + struct inode *hi;
17234 + struct dentry *iwhdentry;
17236 + bbot = au_ibbot(inode);
17237 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17238 + hi = au_h_iptr(inode, bindex);
17242 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17243 + iwhdentry = au_hi_wh(inode, bindex);
17247 + au_set_h_iptr(inode, bindex, NULL, 0);
17248 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17249 + flags & ~AuHi_XINO);
17252 + /* inode_unlock(hi); */
17256 +/* ---------------------------------------------------------------------- */
17258 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17261 + aufs_bindex_t bindex, bbot, bfound, btop;
17262 + struct inode *h_i;
17265 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17266 + pr_warn("branch root dir was changed\n");
17271 + bbot = au_ibbot(inode);
17272 + btop = au_ibtop(inode);
17273 +#if 0 /* reserved for future use */
17274 + if (bindex == bbot) {
17275 + /* keep this ino in rename case */
17279 + for (bindex = btop; bindex <= bbot; bindex++)
17280 + if (au_h_iptr(inode, bindex) == h_inode) {
17287 + for (bindex = btop; bindex <= bbot; bindex++) {
17288 + h_i = au_h_iptr(inode, bindex);
17292 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17293 + /* ignore this error */
17294 + /* bad action? */
17297 + /* children inode number will be broken */
17304 +static int hn_gen_tree(struct dentry *dentry)
17306 + int err, i, j, ndentry;
17307 + struct au_dcsub_pages dpages;
17308 + struct au_dpage *dpage;
17309 + struct dentry **dentries;
17311 + err = au_dpages_init(&dpages, GFP_NOFS);
17312 + if (unlikely(err))
17314 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17315 + if (unlikely(err))
17318 + for (i = 0; i < dpages.ndpage; i++) {
17319 + dpage = dpages.dpages + i;
17320 + dentries = dpage->dentries;
17321 + ndentry = dpage->ndentry;
17322 + for (j = 0; j < ndentry; j++) {
17323 + struct dentry *d;
17330 + if (d_really_is_positive(d))
17331 + /* todo: reset children xino?
17332 + cached children only? */
17333 + au_iigen_dec(d_inode(d));
17338 + au_dpages_free(&dpages);
17344 + * return 0 if processed.
17346 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17347 + const unsigned int isdir)
17350 + struct dentry *d;
17351 + struct qstr *dname;
17354 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17355 + pr_warn("branch root dir was changed\n");
17361 + AuDebugOn(!name);
17362 + au_iigen_dec(inode);
17363 + spin_lock(&inode->i_lock);
17364 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17365 + spin_lock(&d->d_lock);
17366 + dname = &d->d_name;
17367 + if (dname->len != nlen
17368 + && memcmp(dname->name, name, nlen)) {
17369 + spin_unlock(&d->d_lock);
17374 + spin_unlock(&d->d_lock);
17377 + spin_unlock(&inode->i_lock);
17379 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17380 + d = d_find_any_alias(inode);
17382 + au_iigen_dec(inode);
17386 + spin_lock(&d->d_lock);
17387 + dname = &d->d_name;
17388 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17389 + spin_unlock(&d->d_lock);
17390 + err = hn_gen_tree(d);
17391 + spin_lock(&d->d_lock);
17393 + spin_unlock(&d->d_lock);
17402 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17406 + if (IS_ROOT(dentry)) {
17407 + pr_warn("branch root dir was changed\n");
17413 + au_digen_dec(dentry);
17414 + if (d_really_is_positive(dentry))
17415 + au_iigen_dec(d_inode(dentry));
17417 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17418 + if (d_really_is_positive(dentry))
17419 + err = hn_gen_tree(dentry);
17426 +/* ---------------------------------------------------------------------- */
17428 +/* hnotify job flags */
17429 +#define AuHnJob_XINO0 1
17430 +#define AuHnJob_GEN (1 << 1)
17431 +#define AuHnJob_DIRENT (1 << 2)
17432 +#define AuHnJob_ISDIR (1 << 3)
17433 +#define AuHnJob_TRYXINO0 (1 << 4)
17434 +#define AuHnJob_MNTPNT (1 << 5)
17435 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17436 +#define au_fset_hnjob(flags, name) \
17437 + do { (flags) |= AuHnJob_##name; } while (0)
17438 +#define au_fclr_hnjob(flags, name) \
17439 + do { (flags) &= ~AuHnJob_##name; } while (0)
17447 +struct au_hnotify_args {
17448 + struct inode *h_dir, *dir, *h_child_inode;
17450 + unsigned int flags[AuHnLast];
17451 + unsigned int h_child_nlen;
17452 + char h_child_name[];
17455 +struct hn_job_args {
17456 + unsigned int flags;
17457 + struct inode *inode, *h_inode, *dir, *h_dir;
17458 + struct dentry *dentry;
17463 +static int hn_job(struct hn_job_args *a)
17465 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17469 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17470 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17472 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17475 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17476 + if (!a->h_inode->i_nlink
17477 + && !(a->h_inode->i_state & I_LINKABLE))
17478 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17479 + inode_unlock_shared(a->h_inode);
17482 + /* make the generation obsolete */
17483 + if (au_ftest_hnjob(a->flags, GEN)) {
17486 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17488 + if (e && a->dentry)
17489 + hn_gen_by_name(a->dentry, isdir);
17490 + /* ignore this error */
17493 + /* make dir entries obsolete */
17494 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17495 + struct au_vdir *vdir;
17497 + vdir = au_ivdir(a->inode);
17499 + vdir->vd_jiffy = 0;
17500 + /* IMustLock(a->inode); */
17501 + /* inode_inc_iversion(a->inode); */
17504 + /* can do nothing but warn */
17505 + if (au_ftest_hnjob(a->flags, MNTPNT)
17507 + && d_mountpoint(a->dentry))
17508 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17513 +/* ---------------------------------------------------------------------- */
17515 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17516 + struct inode *dir)
17518 + struct dentry *dentry, *d, *parent;
17519 + struct qstr *dname;
17521 + parent = d_find_any_alias(dir);
17526 + spin_lock(&parent->d_lock);
17527 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17528 + /* AuDbg("%pd\n", d); */
17529 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17530 + dname = &d->d_name;
17531 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17532 + goto cont_unlock;
17536 + goto cont_unlock;
17537 + if (au_dcount(d) > 0) {
17538 + dentry = dget_dlock(d);
17539 + spin_unlock(&d->d_lock);
17544 + spin_unlock(&d->d_lock);
17546 + spin_unlock(&parent->d_lock);
17550 + di_write_lock_child(dentry);
17555 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17556 + aufs_bindex_t bindex, ino_t h_ino)
17558 + struct inode *inode;
17563 + err = au_xino_read(sb, bindex, h_ino, &ino);
17565 + inode = ilookup(sb, ino);
17569 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17570 + pr_warn("wrong root branch\n");
17576 + ii_write_lock_child(inode);
17582 +static void au_hn_bh(void *_args)
17584 + struct au_hnotify_args *a = _args;
17585 + struct super_block *sb;
17586 + aufs_bindex_t bindex, bbot, bfound;
17587 + unsigned char xino, try_iput;
17589 + struct inode *inode;
17591 + struct hn_job_args args;
17592 + struct dentry *dentry;
17593 + struct au_sbinfo *sbinfo;
17595 + AuDebugOn(!_args);
17596 + AuDebugOn(!a->h_dir);
17597 + AuDebugOn(!a->dir);
17598 + AuDebugOn(!a->mask);
17599 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17600 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17601 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17606 + * do not lock a->dir->i_mutex here
17607 + * because of d_revalidate() may cause a deadlock.
17609 + sb = a->dir->i_sb;
17611 + sbinfo = au_sbi(sb);
17612 + AuDebugOn(!sbinfo);
17613 + si_write_lock(sb, AuLock_NOPLMW);
17615 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17616 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17617 + case FS_MOVED_FROM:
17618 + case FS_MOVED_TO:
17619 + AuWarn1("DIRREN with UDBA may not work correctly "
17620 + "for the direct rename(2)\n");
17623 + ii_read_lock_parent(a->dir);
17625 + bbot = au_ibbot(a->dir);
17626 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17627 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17631 + ii_read_unlock(a->dir);
17632 + if (unlikely(bfound < 0))
17635 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17637 + if (a->h_child_inode)
17638 + h_ino = a->h_child_inode->i_ino;
17640 + if (a->h_child_nlen
17641 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17642 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17643 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17646 + if (dentry && d_really_is_positive(dentry))
17647 + inode = d_inode(dentry);
17648 + if (xino && !inode && h_ino
17649 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17650 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17651 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17652 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17656 + args.flags = a->flags[AuHn_CHILD];
17657 + args.dentry = dentry;
17658 + args.inode = inode;
17659 + args.h_inode = a->h_child_inode;
17660 + args.dir = a->dir;
17661 + args.h_dir = a->h_dir;
17662 + args.h_name = a->h_child_name;
17663 + args.h_nlen = a->h_child_nlen;
17664 + err = hn_job(&args);
17666 + if (au_di(dentry))
17667 + di_write_unlock(dentry);
17670 + if (inode && try_iput) {
17671 + ii_write_unlock(inode);
17675 + ii_write_lock_parent(a->dir);
17676 + args.flags = a->flags[AuHn_PARENT];
17677 + args.dentry = NULL;
17678 + args.inode = a->dir;
17679 + args.h_inode = a->h_dir;
17681 + args.h_dir = NULL;
17682 + args.h_name = NULL;
17684 + err = hn_job(&args);
17685 + ii_write_unlock(a->dir);
17688 + iput(a->h_child_inode);
17691 + si_write_unlock(sb);
17692 + au_nwt_done(&sbinfo->si_nowait);
17696 +/* ---------------------------------------------------------------------- */
17698 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17699 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
17702 + unsigned int flags[AuHnLast], f;
17703 + unsigned char isdir, isroot, wh;
17704 + struct inode *dir;
17705 + struct au_hnotify_args *args;
17706 + char *p, *h_child_name;
17709 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17710 + dir = igrab(hnotify->hn_aufs_inode);
17714 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17716 + h_child_name = (void *)h_child_qstr->name;
17717 + len = h_child_qstr->len;
17718 + if (h_child_name) {
17719 + if (len > AUFS_WH_PFX_LEN
17720 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17721 + h_child_name += AUFS_WH_PFX_LEN;
17722 + len -= AUFS_WH_PFX_LEN;
17728 + if (h_child_inode)
17729 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17730 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17731 + flags[AuHn_CHILD] = 0;
17733 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17734 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17735 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17736 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
17737 + case FS_MOVED_FROM:
17738 + case FS_MOVED_TO:
17739 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17740 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17743 + AuDebugOn(!h_child_name);
17748 + * aufs never be able to get this child inode.
17749 + * revalidation should be in d_revalidate()
17750 + * by checking i_nlink, i_generation or d_unhashed().
17752 + AuDebugOn(!h_child_name);
17753 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17754 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17762 + h_child_inode = NULL;
17765 + /* iput() and kfree() will be called in au_hnotify() */
17766 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17767 + if (unlikely(!args)) {
17768 + AuErr1("no memory\n");
17772 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17773 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17774 + args->mask = mask;
17776 + args->h_dir = igrab(h_dir);
17777 + if (h_child_inode)
17778 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17779 + args->h_child_inode = h_child_inode;
17780 + args->h_child_nlen = len;
17782 + p = (void *)args;
17783 + p += sizeof(*args);
17784 + memcpy(p, h_child_name, len);
17788 + /* NFS fires the event for silly-renamed one from kworker */
17790 + if (!dir->i_nlink
17791 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17793 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17794 + if (unlikely(err)) {
17795 + pr_err("wkq %d\n", err);
17796 + iput(args->h_child_inode);
17797 + iput(args->h_dir);
17799 + au_kfree_rcu(args);
17806 +/* ---------------------------------------------------------------------- */
17808 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17812 + AuDebugOn(!(udba & AuOptMask_UDBA));
17815 + if (au_hnotify_op.reset_br)
17816 + err = au_hnotify_op.reset_br(udba, br, perm);
17821 +int au_hnotify_init_br(struct au_branch *br, int perm)
17826 + if (au_hnotify_op.init_br)
17827 + err = au_hnotify_op.init_br(br, perm);
17832 +void au_hnotify_fin_br(struct au_branch *br)
17834 + if (au_hnotify_op.fin_br)
17835 + au_hnotify_op.fin_br(br);
17838 +static void au_hn_destroy_cache(void)
17840 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17841 + au_cache[AuCache_HNOTIFY] = NULL;
17844 +int __init au_hnotify_init(void)
17849 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17850 + if (au_cache[AuCache_HNOTIFY]) {
17852 + if (au_hnotify_op.init)
17853 + err = au_hnotify_op.init();
17854 + if (unlikely(err))
17855 + au_hn_destroy_cache();
17861 +void au_hnotify_fin(void)
17863 + if (au_hnotify_op.fin)
17864 + au_hnotify_op.fin();
17866 + /* cf. au_cache_fin() */
17867 + if (au_cache[AuCache_HNOTIFY])
17868 + au_hn_destroy_cache();
17870 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17871 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17872 +++ linux/fs/aufs/iinfo.c 2020-01-27 10:57:18.175538316 +0100
17874 +// SPDX-License-Identifier: GPL-2.0
17876 + * Copyright (C) 2005-2020 Junjiro R. Okajima
17878 + * This program, aufs is free software; you can redistribute it and/or modify
17879 + * it under the terms of the GNU General Public License as published by
17880 + * the Free Software Foundation; either version 2 of the License, or
17881 + * (at your option) any later version.
17883 + * This program is distributed in the hope that it will be useful,
17884 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17885 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17886 + * GNU General Public License for more details.
17888 + * You should have received a copy of the GNU General Public License
17889 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17893 + * inode private data
17898 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17900 + struct inode *h_inode;
17901 + struct au_hinode *hinode;
17903 + IiMustAnyLock(inode);
17905 + hinode = au_hinode(au_ii(inode), bindex);
17906 + h_inode = hinode->hi_inode;
17907 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17911 +/* todo: hard/soft set? */
17912 +void au_hiput(struct au_hinode *hinode)
17914 + au_hn_free(hinode);
17915 + dput(hinode->hi_whdentry);
17916 + iput(hinode->hi_inode);
17919 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17921 + unsigned int flags;
17922 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17925 + if (au_opt_test(mnt_flags, XINO))
17926 + au_fset_hi(flags, XINO);
17927 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17928 + au_fset_hi(flags, HNOTIFY);
17932 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17933 + struct inode *h_inode, unsigned int flags)
17935 + struct au_hinode *hinode;
17936 + struct inode *hi;
17937 + struct au_iinfo *iinfo = au_ii(inode);
17939 + IiMustWriteLock(inode);
17941 + hinode = au_hinode(iinfo, bindex);
17942 + hi = hinode->hi_inode;
17943 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17946 + au_hiput(hinode);
17947 + hinode->hi_inode = h_inode;
17950 + struct super_block *sb = inode->i_sb;
17951 + struct au_branch *br;
17953 + AuDebugOn(inode->i_mode
17954 + && (h_inode->i_mode & S_IFMT)
17955 + != (inode->i_mode & S_IFMT));
17956 + if (bindex == iinfo->ii_btop)
17957 + au_cpup_igen(inode, h_inode);
17958 + br = au_sbr(sb, bindex);
17959 + hinode->hi_id = br->br_id;
17960 + if (au_ftest_hi(flags, XINO)) {
17961 + err = au_xino_write(sb, bindex, h_inode->i_ino,
17963 + if (unlikely(err))
17964 + AuIOErr1("failed au_xino_write() %d\n", err);
17967 + if (au_ftest_hi(flags, HNOTIFY)
17968 + && au_br_hnotifyable(br->br_perm)) {
17969 + err = au_hn_alloc(hinode, inode);
17970 + if (unlikely(err))
17971 + AuIOErr1("au_hn_alloc() %d\n", err);
17976 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17977 + struct dentry *h_wh)
17979 + struct au_hinode *hinode;
17981 + IiMustWriteLock(inode);
17983 + hinode = au_hinode(au_ii(inode), bindex);
17984 + AuDebugOn(hinode->hi_whdentry);
17985 + hinode->hi_whdentry = h_wh;
17988 +void au_update_iigen(struct inode *inode, int half)
17990 + struct au_iinfo *iinfo;
17991 + struct au_iigen *iigen;
17992 + unsigned int sigen;
17994 + sigen = au_sigen(inode->i_sb);
17995 + iinfo = au_ii(inode);
17996 + iigen = &iinfo->ii_generation;
17997 + spin_lock(&iigen->ig_spin);
17998 + iigen->ig_generation = sigen;
18000 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
18002 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
18003 + spin_unlock(&iigen->ig_spin);
18006 +/* it may be called at remount time, too */
18007 +void au_update_ibrange(struct inode *inode, int do_put_zero)
18009 + struct au_iinfo *iinfo;
18010 + aufs_bindex_t bindex, bbot;
18012 + AuDebugOn(au_is_bad_inode(inode));
18013 + IiMustWriteLock(inode);
18015 + iinfo = au_ii(inode);
18016 + if (do_put_zero && iinfo->ii_btop >= 0) {
18017 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18019 + struct inode *h_i;
18021 + h_i = au_hinode(iinfo, bindex)->hi_inode;
18024 + && !(h_i->i_state & I_LINKABLE))
18025 + au_set_h_iptr(inode, bindex, NULL, 0);
18029 + iinfo->ii_btop = -1;
18030 + iinfo->ii_bbot = -1;
18031 + bbot = au_sbbot(inode->i_sb);
18032 + for (bindex = 0; bindex <= bbot; bindex++)
18033 + if (au_hinode(iinfo, bindex)->hi_inode) {
18034 + iinfo->ii_btop = bindex;
18037 + if (iinfo->ii_btop >= 0)
18038 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
18039 + if (au_hinode(iinfo, bindex)->hi_inode) {
18040 + iinfo->ii_bbot = bindex;
18043 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
18046 +/* ---------------------------------------------------------------------- */
18048 +void au_icntnr_init_once(void *_c)
18050 + struct au_icntnr *c = _c;
18051 + struct au_iinfo *iinfo = &c->iinfo;
18053 + spin_lock_init(&iinfo->ii_generation.ig_spin);
18054 + au_rw_init(&iinfo->ii_rwsem);
18055 + inode_init_once(&c->vfs_inode);
18058 +void au_hinode_init(struct au_hinode *hinode)
18060 + hinode->hi_inode = NULL;
18061 + hinode->hi_id = -1;
18062 + au_hn_init(hinode);
18063 + hinode->hi_whdentry = NULL;
18066 +int au_iinfo_init(struct inode *inode)
18068 + struct au_iinfo *iinfo;
18069 + struct super_block *sb;
18070 + struct au_hinode *hi;
18073 + sb = inode->i_sb;
18074 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18075 + nbr = au_sbbot(sb) + 1;
18076 + if (unlikely(nbr <= 0))
18078 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
18080 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
18082 + iinfo->ii_hinode = hi;
18083 + for (i = 0; i < nbr; i++, hi++)
18084 + au_hinode_init(hi);
18086 + iinfo->ii_generation.ig_generation = au_sigen(sb);
18087 + iinfo->ii_btop = -1;
18088 + iinfo->ii_bbot = -1;
18089 + iinfo->ii_vdir = NULL;
18095 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
18098 + struct au_hinode *hip;
18100 + AuRwMustWriteLock(&iinfo->ii_rwsem);
18103 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
18106 + iinfo->ii_hinode = hip;
18107 + i = iinfo->ii_bbot + 1;
18109 + for (; i < nbr; i++, hip++)
18110 + au_hinode_init(hip);
18117 +void au_iinfo_fin(struct inode *inode)
18119 + struct au_iinfo *iinfo;
18120 + struct au_hinode *hi;
18121 + struct super_block *sb;
18122 + aufs_bindex_t bindex, bbot;
18123 + const unsigned char unlinked = !inode->i_nlink;
18125 + AuDebugOn(au_is_bad_inode(inode));
18127 + sb = inode->i_sb;
18128 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
18129 + if (si_pid_test(sb))
18130 + au_xino_delete_inode(inode, unlinked);
18133 + * it is safe to hide the dependency between sbinfo and
18137 + si_noflush_read_lock(sb);
18138 + au_xino_delete_inode(inode, unlinked);
18139 + si_read_unlock(sb);
18143 + iinfo = au_ii(inode);
18144 + if (iinfo->ii_vdir)
18145 + au_vdir_free(iinfo->ii_vdir);
18147 + bindex = iinfo->ii_btop;
18148 + if (bindex >= 0) {
18149 + hi = au_hinode(iinfo, bindex);
18150 + bbot = iinfo->ii_bbot;
18151 + while (bindex++ <= bbot) {
18152 + if (hi->hi_inode)
18157 + au_kfree_rcu(iinfo->ii_hinode);
18158 + AuRwDestroy(&iinfo->ii_rwsem);
18160 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18161 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18162 +++ linux/fs/aufs/inode.c 2020-01-27 10:57:18.175538316 +0100
18164 +// SPDX-License-Identifier: GPL-2.0
18166 + * Copyright (C) 2005-2020 Junjiro R. Okajima
18168 + * This program, aufs is free software; you can redistribute it and/or modify
18169 + * it under the terms of the GNU General Public License as published by
18170 + * the Free Software Foundation; either version 2 of the License, or
18171 + * (at your option) any later version.
18173 + * This program is distributed in the hope that it will be useful,
18174 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18175 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18176 + * GNU General Public License for more details.
18178 + * You should have received a copy of the GNU General Public License
18179 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18183 + * inode functions
18186 +#include <linux/iversion.h>
18189 +struct inode *au_igrab(struct inode *inode)
18192 + AuDebugOn(!atomic_read(&inode->i_count));
18198 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18200 + au_cpup_attr_all(inode, /*force*/0);
18201 + au_update_iigen(inode, /*half*/1);
18203 + inode_inc_iversion(inode);
18206 +static int au_ii_refresh(struct inode *inode, int *update)
18210 + aufs_bindex_t bindex, new_bindex;
18211 + struct super_block *sb;
18212 + struct au_iinfo *iinfo;
18213 + struct au_hinode *p, *q, tmp;
18215 + AuDebugOn(au_is_bad_inode(inode));
18216 + IiMustWriteLock(inode);
18219 + sb = inode->i_sb;
18220 + nbr = au_sbbot(sb) + 1;
18221 + type = inode->i_mode & S_IFMT;
18222 + iinfo = au_ii(inode);
18223 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18224 + if (unlikely(err))
18227 + AuDebugOn(iinfo->ii_btop < 0);
18228 + p = au_hinode(iinfo, iinfo->ii_btop);
18229 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18231 + if (!p->hi_inode)
18234 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18235 + new_bindex = au_br_index(sb, p->hi_id);
18236 + if (new_bindex == bindex)
18239 + if (new_bindex < 0) {
18242 + p->hi_inode = NULL;
18246 + if (new_bindex < iinfo->ii_btop)
18247 + iinfo->ii_btop = new_bindex;
18248 + if (iinfo->ii_bbot < new_bindex)
18249 + iinfo->ii_bbot = new_bindex;
18250 + /* swap two lower inode, and loop again */
18251 + q = au_hinode(iinfo, new_bindex);
18255 + if (tmp.hi_inode) {
18260 + au_update_ibrange(inode, /*do_put_zero*/0);
18261 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18262 + e = au_dy_irefresh(inode);
18263 + if (unlikely(e && !err))
18271 +void au_refresh_iop(struct inode *inode, int force_getattr)
18274 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18275 + const struct inode_operations *iop
18276 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18278 + if (inode->i_op == iop)
18281 + switch (inode->i_mode & S_IFMT) {
18283 + type = AuIop_DIR;
18286 + type = AuIop_SYMLINK;
18289 + type = AuIop_OTHER;
18293 + inode->i_op = iop + type;
18294 + /* unnecessary smp_wmb() */
18297 +int au_refresh_hinode_self(struct inode *inode)
18301 + err = au_ii_refresh(inode, &update);
18303 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18309 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18311 + int err, e, update;
18312 + unsigned int flags;
18314 + aufs_bindex_t bindex, bbot;
18315 + unsigned char isdir;
18316 + struct au_hinode *p;
18317 + struct au_iinfo *iinfo;
18319 + err = au_ii_refresh(inode, &update);
18320 + if (unlikely(err))
18324 + iinfo = au_ii(inode);
18325 + p = au_hinode(iinfo, iinfo->ii_btop);
18326 + mode = (inode->i_mode & S_IFMT);
18327 + isdir = S_ISDIR(mode);
18328 + flags = au_hi_flags(inode, isdir);
18329 + bbot = au_dbbot(dentry);
18330 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18331 + struct inode *h_i, *h_inode;
18332 + struct dentry *h_d;
18334 + h_d = au_h_dptr(dentry, bindex);
18335 + if (!h_d || d_is_negative(h_d))
18338 + h_inode = d_inode(h_d);
18339 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18340 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18341 + h_i = au_h_iptr(inode, bindex);
18343 + if (h_i == h_inode)
18349 + if (bindex < iinfo->ii_btop)
18350 + iinfo->ii_btop = bindex;
18351 + if (iinfo->ii_bbot < bindex)
18352 + iinfo->ii_bbot = bindex;
18353 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18356 + au_update_ibrange(inode, /*do_put_zero*/0);
18357 + e = au_dy_irefresh(inode);
18358 + if (unlikely(e && !err))
18361 + au_refresh_hinode_attr(inode, update && isdir);
18368 +static int set_inode(struct inode *inode, struct dentry *dentry)
18371 + unsigned int flags;
18373 + aufs_bindex_t bindex, btop, btail;
18374 + unsigned char isdir;
18375 + struct dentry *h_dentry;
18376 + struct inode *h_inode;
18377 + struct au_iinfo *iinfo;
18378 + const struct inode_operations *iop;
18380 + IiMustWriteLock(inode);
18384 + iop = au_sbi(inode->i_sb)->si_iop_array;
18385 + btop = au_dbtop(dentry);
18386 + h_dentry = au_h_dptr(dentry, btop);
18387 + h_inode = d_inode(h_dentry);
18388 + mode = h_inode->i_mode;
18389 + switch (mode & S_IFMT) {
18391 + btail = au_dbtail(dentry);
18392 + inode->i_op = iop + AuIop_OTHER;
18393 + inode->i_fop = &aufs_file_fop;
18394 + err = au_dy_iaop(inode, btop, h_inode);
18395 + if (unlikely(err))
18400 + btail = au_dbtaildir(dentry);
18401 + inode->i_op = iop + AuIop_DIR;
18402 + inode->i_fop = &aufs_dir_fop;
18405 + btail = au_dbtail(dentry);
18406 + inode->i_op = iop + AuIop_SYMLINK;
18412 + btail = au_dbtail(dentry);
18413 + inode->i_op = iop + AuIop_OTHER;
18414 + init_special_inode(inode, mode, h_inode->i_rdev);
18417 + AuIOErr("Unknown file type 0%o\n", mode);
18422 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18423 + flags = au_hi_flags(inode, isdir);
18424 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18425 + && au_ftest_hi(flags, HNOTIFY)
18426 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18427 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18428 + au_fclr_hi(flags, HNOTIFY);
18429 + iinfo = au_ii(inode);
18430 + iinfo->ii_btop = btop;
18431 + iinfo->ii_bbot = btail;
18432 + for (bindex = btop; bindex <= btail; bindex++) {
18433 + h_dentry = au_h_dptr(dentry, bindex);
18435 + au_set_h_iptr(inode, bindex,
18436 + au_igrab(d_inode(h_dentry)), flags);
18438 + au_cpup_attr_all(inode, /*force*/1);
18440 + * to force calling aufs_get_acl() every time,
18441 + * do not call cache_no_acl() for aufs inode.
18449 + * successful returns with iinfo write_locked
18451 + * zero: success, matched
18452 + * plus: no error, but unmatched
18454 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18457 + unsigned int gen, igflags;
18458 + aufs_bindex_t bindex, bbot;
18459 + struct inode *h_inode, *h_dinode;
18460 + struct dentry *h_dentry;
18463 + * before this function, if aufs got any iinfo lock, it must be only
18464 + * one, the parent dir.
18465 + * it can happen by UDBA and the obsoleted inode number.
18468 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18472 + ii_write_lock_new_child(inode);
18473 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18474 + h_dinode = d_inode(h_dentry);
18475 + bbot = au_ibbot(inode);
18476 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18477 + h_inode = au_h_iptr(inode, bindex);
18478 + if (!h_inode || h_inode != h_dinode)
18482 + gen = au_iigen(inode, &igflags);
18483 + if (gen == au_digen(dentry)
18484 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18487 + /* fully refresh inode using dentry */
18488 + err = au_refresh_hinode(inode, dentry);
18490 + au_update_iigen(inode, /*half*/0);
18494 + if (unlikely(err))
18495 + ii_write_unlock(inode);
18500 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18501 + unsigned int d_type, ino_t *ino)
18504 + const int isnondir = d_type != DT_DIR;
18506 + /* prevent hardlinked inode number from race condition */
18508 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18509 + if (unlikely(err))
18513 + err = au_xino_read(sb, bindex, h_ino, ino);
18514 + if (unlikely(err))
18515 + goto out_xinondir;
18519 + *ino = au_xino_new_ino(sb);
18520 + if (unlikely(!*ino))
18521 + goto out_xinondir;
18522 + err = au_xino_write(sb, bindex, h_ino, *ino);
18523 + if (unlikely(err))
18524 + goto out_xinondir;
18528 + if (isnondir && idx >= 0)
18529 + au_xinondir_leave(sb, bindex, h_ino, idx);
18534 +/* successful returns with iinfo write_locked */
18535 +/* todo: return with unlocked? */
18536 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18538 + struct inode *inode, *h_inode;
18539 + struct dentry *h_dentry;
18540 + struct super_block *sb;
18541 + ino_t h_ino, ino;
18542 + int err, idx, hlinked;
18543 + aufs_bindex_t btop;
18545 + sb = dentry->d_sb;
18546 + btop = au_dbtop(dentry);
18547 + h_dentry = au_h_dptr(dentry, btop);
18548 + h_inode = d_inode(h_dentry);
18549 + h_ino = h_inode->i_ino;
18550 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18554 + * stop 'race'-ing between hardlinks under different
18558 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18559 + inode = ERR_PTR(err);
18560 + if (unlikely(err))
18564 + err = au_xino_read(sb, btop, h_ino, &ino);
18565 + inode = ERR_PTR(err);
18566 + if (unlikely(err))
18567 + goto out_xinondir;
18570 + ino = au_xino_new_ino(sb);
18571 + if (unlikely(!ino)) {
18572 + inode = ERR_PTR(-EIO);
18573 + goto out_xinondir;
18577 + AuDbg("i%lu\n", (unsigned long)ino);
18578 + inode = au_iget_locked(sb, ino);
18579 + err = PTR_ERR(inode);
18580 + if (IS_ERR(inode))
18581 + goto out_xinondir;
18583 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18584 + if (inode->i_state & I_NEW) {
18585 + ii_write_lock_new_child(inode);
18586 + err = set_inode(inode, dentry);
18588 + unlock_new_inode(inode);
18589 + goto out_xinondir; /* success */
18593 + * iget_failed() calls iput(), but we need to call
18594 + * ii_write_unlock() after iget_failed(). so dirty hack for
18597 + atomic_inc(&inode->i_count);
18598 + iget_failed(inode);
18599 + ii_write_unlock(inode);
18600 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18601 + /* ignore this error */
18603 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18605 + * horrible race condition between lookup, readdir and copyup
18606 + * (or something).
18608 + if (hlinked && idx >= 0)
18609 + au_xinondir_leave(sb, btop, h_ino, idx);
18610 + err = reval_inode(inode, dentry);
18611 + if (unlikely(err < 0)) {
18616 + goto out; /* success */
18617 + else if (hlinked && idx >= 0) {
18618 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18619 + if (unlikely(err)) {
18621 + inode = ERR_PTR(err);
18627 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18628 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18629 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18630 + btop, au_sbtype(h_dentry->d_sb), dentry,
18631 + (unsigned long)h_ino, (unsigned long)ino);
18633 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18636 + if (hlinked && idx >= 0)
18637 + au_xinondir_leave(sb, btop, h_ino, idx);
18643 + inode = ERR_PTR(err);
18645 + if (hlinked && idx >= 0)
18646 + au_xinondir_leave(sb, btop, h_ino, idx);
18651 +/* ---------------------------------------------------------------------- */
18653 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18654 + struct inode *inode)
18657 + struct inode *hi;
18659 + err = au_br_rdonly(au_sbr(sb, bindex));
18661 + /* pseudo-link after flushed may happen out of bounds */
18664 + && au_ibtop(inode) <= bindex
18665 + && bindex <= au_ibbot(inode)) {
18667 + * permission check is unnecessary since vfsub routine
18668 + * will be called later
18670 + hi = au_h_iptr(inode, bindex);
18672 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18678 +int au_test_h_perm(struct inode *h_inode, int mask)
18680 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18682 + return inode_permission(h_inode, mask);
18685 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18687 + if (au_test_nfs(h_inode->i_sb)
18688 + && (mask & MAY_WRITE)
18689 + && S_ISDIR(h_inode->i_mode))
18690 + mask |= MAY_READ; /* force permission check */
18691 + return au_test_h_perm(h_inode, mask);
18693 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18694 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18695 +++ linux/fs/aufs/inode.h 2020-08-03 09:14:46.095748745 +0200
18697 +/* SPDX-License-Identifier: GPL-2.0 */
18699 + * Copyright (C) 2005-2020 Junjiro R. Okajima
18701 + * This program, aufs is free software; you can redistribute it and/or modify
18702 + * it under the terms of the GNU General Public License as published by
18703 + * the Free Software Foundation; either version 2 of the License, or
18704 + * (at your option) any later version.
18706 + * This program is distributed in the hope that it will be useful,
18707 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18708 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18709 + * GNU General Public License for more details.
18711 + * You should have received a copy of the GNU General Public License
18712 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18716 + * inode operations
18719 +#ifndef __AUFS_INODE_H__
18720 +#define __AUFS_INODE_H__
18724 +#include <linux/fsnotify.h>
18725 +#include "rwsem.h"
18729 +struct au_hnotify {
18730 +#ifdef CONFIG_AUFS_HNOTIFY
18731 +#ifdef CONFIG_AUFS_HFSNOTIFY
18732 + /* never use fsnotify_add_vfsmount_mark() */
18733 + struct fsnotify_mark hn_mark;
18735 + struct inode *hn_aufs_inode; /* no get/put */
18736 + struct rcu_head rcu;
18738 +} ____cacheline_aligned_in_smp;
18740 +struct au_hinode {
18741 + struct inode *hi_inode;
18742 + aufs_bindex_t hi_id;
18743 +#ifdef CONFIG_AUFS_HNOTIFY
18744 + struct au_hnotify *hi_notify;
18747 + /* reference to the copied-up whiteout with get/put */
18748 + struct dentry *hi_whdentry;
18752 +#define AuIG_HALF_REFRESHED 1
18753 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18754 +#define au_ig_fset(flags, name) \
18755 + do { (flags) |= AuIG_##name; } while (0)
18756 +#define au_ig_fclr(flags, name) \
18757 + do { (flags) &= ~AuIG_##name; } while (0)
18760 + spinlock_t ig_spin;
18761 + __u32 ig_generation, ig_flags;
18766 + struct au_iigen ii_generation;
18767 + struct super_block *ii_hsb1; /* no get/put */
18769 + struct au_rwsem ii_rwsem;
18770 + aufs_bindex_t ii_btop, ii_bbot;
18772 + struct au_hinode *ii_hinode;
18773 + struct au_vdir *ii_vdir;
18776 +struct au_icntnr {
18777 + struct au_iinfo iinfo;
18778 + struct inode vfs_inode;
18779 + struct hlist_bl_node plink;
18780 + struct rcu_head rcu;
18781 +} ____cacheline_aligned_in_smp;
18783 +/* au_pin flags */
18784 +#define AuPin_DI_LOCKED 1
18785 +#define AuPin_MNT_WRITE (1 << 1)
18786 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18787 +#define au_fset_pin(flags, name) \
18788 + do { (flags) |= AuPin_##name; } while (0)
18789 +#define au_fclr_pin(flags, name) \
18790 + do { (flags) &= ~AuPin_##name; } while (0)
18794 + struct dentry *dentry;
18795 + unsigned int udba;
18796 + unsigned char lsc_di, lsc_hi, flags;
18797 + aufs_bindex_t bindex;
18800 + struct dentry *parent;
18801 + struct au_hinode *hdir;
18802 + struct vfsmount *h_mnt;
18804 + /* temporary unlock/relock for copyup */
18805 + struct dentry *h_dentry, *h_parent;
18806 + struct au_branch *br;
18807 + struct task_struct *task;
18810 +void au_pin_hdir_unlock(struct au_pin *p);
18811 +int au_pin_hdir_lock(struct au_pin *p);
18812 +int au_pin_hdir_relock(struct au_pin *p);
18813 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18814 +void au_pin_hdir_release(struct au_pin *p);
18816 +/* ---------------------------------------------------------------------- */
18818 +static inline struct au_iinfo *au_ii(struct inode *inode)
18820 + BUG_ON(is_bad_inode(inode));
18821 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18824 +/* ---------------------------------------------------------------------- */
18827 +struct inode *au_igrab(struct inode *inode);
18828 +void au_refresh_iop(struct inode *inode, int force_getattr);
18829 +int au_refresh_hinode_self(struct inode *inode);
18830 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18831 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18832 + unsigned int d_type, ino_t *ino);
18833 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18834 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18835 + struct inode *inode);
18836 +int au_test_h_perm(struct inode *h_inode, int mask);
18837 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18839 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18840 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18842 +#ifdef CONFIG_AUFS_SHWH
18843 + return au_ino(sb, bindex, h_ino, d_type, ino);
18856 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
18857 + aufs_iop_nogetattr[AuIop_Last];
18859 +/* au_wr_dir flags */
18860 +#define AuWrDir_ADD_ENTRY 1
18861 +#define AuWrDir_ISDIR (1 << 1)
18862 +#define AuWrDir_TMPFILE (1 << 2)
18863 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18864 +#define au_fset_wrdir(flags, name) \
18865 + do { (flags) |= AuWrDir_##name; } while (0)
18866 +#define au_fclr_wrdir(flags, name) \
18867 + do { (flags) &= ~AuWrDir_##name; } while (0)
18869 +struct au_wr_dir_args {
18870 + aufs_bindex_t force_btgt;
18871 + unsigned char flags;
18873 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18874 + struct au_wr_dir_args *args);
18876 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18877 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18878 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18879 + unsigned int udba, unsigned char flags);
18880 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18881 + unsigned int udba, unsigned char flags) __must_check;
18882 +int au_do_pin(struct au_pin *pin) __must_check;
18883 +void au_unpin(struct au_pin *pin);
18884 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18886 +#define AuIcpup_DID_CPUP 1
18887 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18888 +#define au_fset_icpup(flags, name) \
18889 + do { (flags) |= AuIcpup_##name; } while (0)
18890 +#define au_fclr_icpup(flags, name) \
18891 + do { (flags) &= ~AuIcpup_##name; } while (0)
18893 +struct au_icpup_args {
18894 + unsigned char flags;
18895 + unsigned char pin_flags;
18896 + aufs_bindex_t btgt;
18897 + unsigned int udba;
18898 + struct au_pin pin;
18899 + struct path h_path;
18900 + struct inode *h_inode;
18903 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18904 + struct au_icpup_args *a);
18906 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
18907 + struct path *h_path, int locked);
18910 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18911 + struct dentry *h_parent, int isdir);
18912 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18914 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
18915 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18917 +struct vfsub_aopen_args;
18918 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18919 + struct vfsub_aopen_args *args);
18920 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
18921 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18922 + struct dentry *dentry);
18923 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
18926 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18927 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18928 + struct dentry *h_parent, int isdir);
18929 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18930 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
18933 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
18934 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
18935 + struct inode *dir, struct dentry *dentry,
18936 + unsigned int flags);
18939 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
18940 +void au_hiput(struct au_hinode *hinode);
18941 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18942 + struct dentry *h_wh);
18943 +unsigned int au_hi_flags(struct inode *inode, int isdir);
18945 +/* hinode flags */
18946 +#define AuHi_XINO 1
18947 +#define AuHi_HNOTIFY (1 << 1)
18948 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
18949 +#define au_fset_hi(flags, name) \
18950 + do { (flags) |= AuHi_##name; } while (0)
18951 +#define au_fclr_hi(flags, name) \
18952 + do { (flags) &= ~AuHi_##name; } while (0)
18954 +#ifndef CONFIG_AUFS_HNOTIFY
18955 +#undef AuHi_HNOTIFY
18956 +#define AuHi_HNOTIFY 0
18959 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18960 + struct inode *h_inode, unsigned int flags);
18962 +void au_update_iigen(struct inode *inode, int half);
18963 +void au_update_ibrange(struct inode *inode, int do_put_zero);
18965 +void au_icntnr_init_once(void *_c);
18966 +void au_hinode_init(struct au_hinode *hinode);
18967 +int au_iinfo_init(struct inode *inode);
18968 +void au_iinfo_fin(struct inode *inode);
18969 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
18971 +#ifdef CONFIG_PROC_FS
18973 +int au_plink_maint(struct super_block *sb, int flags);
18975 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
18976 +int au_plink_maint_enter(struct super_block *sb);
18977 +#ifdef CONFIG_AUFS_DEBUG
18978 +void au_plink_list(struct super_block *sb);
18980 +AuStubVoid(au_plink_list, struct super_block *sb)
18982 +int au_plink_test(struct inode *inode);
18983 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
18984 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
18985 + struct dentry *h_dentry);
18986 +void au_plink_put(struct super_block *sb, int verbose);
18987 +void au_plink_clean(struct super_block *sb, int verbose);
18988 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
18990 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
18991 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
18992 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
18993 +AuStubVoid(au_plink_list, struct super_block *sb);
18994 +AuStubInt0(au_plink_test, struct inode *inode);
18995 +AuStub(struct dentry *, au_plink_lkup, return NULL,
18996 + struct inode *inode, aufs_bindex_t bindex);
18997 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
18998 + struct dentry *h_dentry);
18999 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
19000 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
19001 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
19002 +#endif /* CONFIG_PROC_FS */
19004 +#ifdef CONFIG_AUFS_XATTR
19006 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
19007 + unsigned int verbose);
19008 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
19009 +void au_xattr_init(struct super_block *sb);
19011 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
19012 + int ignore_flags, unsigned int verbose);
19013 +AuStubVoid(au_xattr_init, struct super_block *sb);
19016 +#ifdef CONFIG_FS_POSIX_ACL
19017 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
19018 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
19021 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19027 +struct au_sxattr {
19031 + const char *name;
19032 + const void *value;
19037 + struct posix_acl *acl;
19042 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19043 + struct au_sxattr *arg);
19046 +/* ---------------------------------------------------------------------- */
19048 +/* lock subclass for iinfo */
19050 + AuLsc_II_CHILD, /* child first */
19051 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
19052 + AuLsc_II_CHILD3, /* copyup dirs */
19053 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
19054 + AuLsc_II_PARENT2,
19055 + AuLsc_II_PARENT3, /* copyup dirs */
19056 + AuLsc_II_NEW_CHILD
19060 + * ii_read_lock_child, ii_write_lock_child,
19061 + * ii_read_lock_child2, ii_write_lock_child2,
19062 + * ii_read_lock_child3, ii_write_lock_child3,
19063 + * ii_read_lock_parent, ii_write_lock_parent,
19064 + * ii_read_lock_parent2, ii_write_lock_parent2,
19065 + * ii_read_lock_parent3, ii_write_lock_parent3,
19066 + * ii_read_lock_new_child, ii_write_lock_new_child,
19068 +#define AuReadLockFunc(name, lsc) \
19069 +static inline void ii_read_lock_##name(struct inode *i) \
19071 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19074 +#define AuWriteLockFunc(name, lsc) \
19075 +static inline void ii_write_lock_##name(struct inode *i) \
19077 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19080 +#define AuRWLockFuncs(name, lsc) \
19081 + AuReadLockFunc(name, lsc) \
19082 + AuWriteLockFunc(name, lsc)
19084 +AuRWLockFuncs(child, CHILD);
19085 +AuRWLockFuncs(child2, CHILD2);
19086 +AuRWLockFuncs(child3, CHILD3);
19087 +AuRWLockFuncs(parent, PARENT);
19088 +AuRWLockFuncs(parent2, PARENT2);
19089 +AuRWLockFuncs(parent3, PARENT3);
19090 +AuRWLockFuncs(new_child, NEW_CHILD);
19092 +#undef AuReadLockFunc
19093 +#undef AuWriteLockFunc
19094 +#undef AuRWLockFuncs
19096 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
19097 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
19098 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
19100 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
19101 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
19102 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
19104 +/* ---------------------------------------------------------------------- */
19106 +static inline void au_icntnr_init(struct au_icntnr *c)
19108 +#ifdef CONFIG_AUFS_DEBUG
19109 + c->vfs_inode.i_mode = 0;
19113 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
19115 + unsigned int gen;
19116 + struct au_iinfo *iinfo;
19117 + struct au_iigen *iigen;
19119 + iinfo = au_ii(inode);
19120 + iigen = &iinfo->ii_generation;
19121 + spin_lock(&iigen->ig_spin);
19123 + *igflags = iigen->ig_flags;
19124 + gen = iigen->ig_generation;
19125 + spin_unlock(&iigen->ig_spin);
19130 +/* tiny test for inode number */
19131 +/* tmpfs generation is too rough */
19132 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19134 + struct au_iinfo *iinfo;
19136 + iinfo = au_ii(inode);
19137 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19138 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19139 + && iinfo->ii_higen == h_inode->i_generation);
19142 +static inline void au_iigen_dec(struct inode *inode)
19144 + struct au_iinfo *iinfo;
19145 + struct au_iigen *iigen;
19147 + iinfo = au_ii(inode);
19148 + iigen = &iinfo->ii_generation;
19149 + spin_lock(&iigen->ig_spin);
19150 + iigen->ig_generation--;
19151 + spin_unlock(&iigen->ig_spin);
19154 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19159 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19165 +/* ---------------------------------------------------------------------- */
19167 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19168 + aufs_bindex_t bindex)
19170 + return iinfo->ii_hinode + bindex;
19173 +static inline int au_is_bad_inode(struct inode *inode)
19175 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19178 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19179 + aufs_bindex_t bindex)
19181 + IiMustAnyLock(inode);
19182 + return au_hinode(au_ii(inode), bindex)->hi_id;
19185 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19187 + IiMustAnyLock(inode);
19188 + return au_ii(inode)->ii_btop;
19191 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19193 + IiMustAnyLock(inode);
19194 + return au_ii(inode)->ii_bbot;
19197 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19199 + IiMustAnyLock(inode);
19200 + return au_ii(inode)->ii_vdir;
19203 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19205 + IiMustAnyLock(inode);
19206 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19209 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19211 + IiMustWriteLock(inode);
19212 + au_ii(inode)->ii_btop = bindex;
19215 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19217 + IiMustWriteLock(inode);
19218 + au_ii(inode)->ii_bbot = bindex;
19221 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19223 + IiMustWriteLock(inode);
19224 + au_ii(inode)->ii_vdir = vdir;
19227 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19229 + IiMustAnyLock(inode);
19230 + return au_hinode(au_ii(inode), bindex);
19233 +/* ---------------------------------------------------------------------- */
19235 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19238 + return pin->parent;
19242 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19244 + if (pin && pin->hdir)
19245 + return pin->hdir->hi_inode;
19249 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19252 + return pin->hdir;
19256 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19259 + pin->dentry = dentry;
19262 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19263 + unsigned char lflag)
19267 + au_fset_pin(pin->flags, DI_LOCKED);
19269 + au_fclr_pin(pin->flags, DI_LOCKED);
19273 +#if 0 /* reserved */
19274 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19277 + dput(pin->parent);
19278 + pin->parent = dget(parent);
19283 +/* ---------------------------------------------------------------------- */
19286 +#ifdef CONFIG_AUFS_HNOTIFY
19287 +struct au_hnotify_op {
19288 + void (*ctl)(struct au_hinode *hinode, int do_set);
19289 + int (*alloc)(struct au_hinode *hinode);
19292 + * if it returns true, the the caller should free hinode->hi_notify,
19293 + * otherwise ->free() frees it.
19295 + int (*free)(struct au_hinode *hinode,
19296 + struct au_hnotify *hn) __must_check;
19298 + void (*fin)(void);
19299 + int (*init)(void);
19301 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19302 + void (*fin_br)(struct au_branch *br);
19303 + int (*init_br)(struct au_branch *br, int perm);
19307 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19308 +void au_hn_free(struct au_hinode *hinode);
19309 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19310 +void au_hn_reset(struct inode *inode, unsigned int flags);
19311 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19312 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
19313 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19314 +int au_hnotify_init_br(struct au_branch *br, int perm);
19315 +void au_hnotify_fin_br(struct au_branch *br);
19316 +int __init au_hnotify_init(void);
19317 +void au_hnotify_fin(void);
19320 +extern const struct au_hnotify_op au_hnotify_op;
19323 +void au_hn_init(struct au_hinode *hinode)
19325 + hinode->hi_notify = NULL;
19328 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19330 + return hinode->hi_notify;
19334 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19335 + struct au_hinode *hinode __maybe_unused,
19336 + struct inode *inode __maybe_unused)
19337 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19338 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19339 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19340 + int do_set __maybe_unused)
19341 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19342 + unsigned int flags __maybe_unused)
19343 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19344 + struct au_branch *br __maybe_unused,
19345 + int perm __maybe_unused)
19346 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19347 + int perm __maybe_unused)
19348 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19349 +AuStubInt0(__init au_hnotify_init, void)
19350 +AuStubVoid(au_hnotify_fin, void)
19351 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19352 +#endif /* CONFIG_AUFS_HNOTIFY */
19354 +static inline void au_hn_suspend(struct au_hinode *hdir)
19356 + au_hn_ctl(hdir, /*do_set*/0);
19359 +static inline void au_hn_resume(struct au_hinode *hdir)
19361 + au_hn_ctl(hdir, /*do_set*/1);
19364 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19366 + inode_lock(hdir->hi_inode);
19367 + au_hn_suspend(hdir);
19370 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19371 + unsigned int sc __maybe_unused)
19373 + inode_lock_nested(hdir->hi_inode, sc);
19374 + au_hn_suspend(hdir);
19377 +#if 0 /* unused */
19378 +#include "vfsub.h"
19379 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19382 + inode_lock_shared_nested(hdir->hi_inode, sc);
19383 + au_hn_suspend(hdir);
19387 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19389 + au_hn_resume(hdir);
19390 + inode_unlock(hdir->hi_inode);
19393 +#endif /* __KERNEL__ */
19394 +#endif /* __AUFS_INODE_H__ */
19395 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19396 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19397 +++ linux/fs/aufs/ioctl.c 2020-01-27 10:57:18.175538316 +0100
19399 +// SPDX-License-Identifier: GPL-2.0
19401 + * Copyright (C) 2005-2020 Junjiro R. Okajima
19403 + * This program, aufs is free software; you can redistribute it and/or modify
19404 + * it under the terms of the GNU General Public License as published by
19405 + * the Free Software Foundation; either version 2 of the License, or
19406 + * (at your option) any later version.
19408 + * This program is distributed in the hope that it will be useful,
19409 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19410 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19411 + * GNU General Public License for more details.
19413 + * You should have received a copy of the GNU General Public License
19414 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19419 + * plink-management and readdir in userspace.
19420 + * assist the pathconf(3) wrapper library.
19422 + * File-based Hierarchical Storage Management.
19425 +#include <linux/compat.h>
19426 +#include <linux/file.h>
19429 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19432 + aufs_bindex_t wbi, bindex, bbot;
19433 + struct file *h_file;
19434 + struct super_block *sb;
19435 + struct dentry *root;
19436 + struct au_branch *br;
19437 + struct aufs_wbr_fd wbrfd = {
19438 + .oflags = au_dir_roflags,
19441 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19442 + | O_NOATIME | O_CLOEXEC;
19444 + AuDebugOn(wbrfd.oflags & ~valid);
19447 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19448 + if (unlikely(err)) {
19454 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19455 + wbrfd.oflags |= au_dir_roflags;
19456 + AuDbg("0%o\n", wbrfd.oflags);
19457 + if (unlikely(wbrfd.oflags & ~valid))
19461 + fd = get_unused_fd_flags(0);
19463 + if (unlikely(fd < 0))
19466 + h_file = ERR_PTR(-EINVAL);
19469 + sb = path->dentry->d_sb;
19470 + root = sb->s_root;
19471 + aufs_read_lock(root, AuLock_IR);
19472 + bbot = au_sbbot(sb);
19473 + if (wbrfd.brid >= 0) {
19474 + wbi = au_br_index(sb, wbrfd.brid);
19475 + if (unlikely(wbi < 0 || wbi > bbot))
19479 + h_file = ERR_PTR(-ENOENT);
19480 + br = au_sbr(sb, wbi);
19481 + if (!au_br_writable(br->br_perm)) {
19485 + bindex = wbi + 1;
19487 + for (; bindex <= bbot; bindex++) {
19488 + br = au_sbr(sb, bindex);
19489 + if (au_br_writable(br->br_perm)) {
19491 + br = au_sbr(sb, wbi);
19496 + AuDbg("wbi %d\n", wbi);
19498 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19502 + aufs_read_unlock(root, AuLock_IR);
19503 + err = PTR_ERR(h_file);
19504 + if (IS_ERR(h_file))
19507 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19508 + fd_install(fd, h_file);
19510 + goto out; /* success */
19513 + put_unused_fd(fd);
19519 +/* ---------------------------------------------------------------------- */
19521 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19524 + struct dentry *dentry;
19527 + case AUFS_CTL_RDU:
19528 + case AUFS_CTL_RDU_INO:
19529 + err = au_rdu_ioctl(file, cmd, arg);
19532 + case AUFS_CTL_WBR_FD:
19533 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19536 + case AUFS_CTL_IBUSY:
19537 + err = au_ibusy_ioctl(file, arg);
19540 + case AUFS_CTL_BRINFO:
19541 + err = au_brinfo_ioctl(file, arg);
19544 + case AUFS_CTL_FHSM_FD:
19545 + dentry = file->f_path.dentry;
19546 + if (IS_ROOT(dentry))
19547 + err = au_fhsm_fd(dentry->d_sb, arg);
19553 + /* do not call the lower */
19554 + AuDbg("0x%x\n", cmd);
19562 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19567 + case AUFS_CTL_MVDOWN:
19568 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19571 + case AUFS_CTL_WBR_FD:
19572 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19576 + /* do not call the lower */
19577 + AuDbg("0x%x\n", cmd);
19585 +#ifdef CONFIG_COMPAT
19586 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19587 + unsigned long arg)
19592 + case AUFS_CTL_RDU:
19593 + case AUFS_CTL_RDU_INO:
19594 + err = au_rdu_compat_ioctl(file, cmd, arg);
19597 + case AUFS_CTL_IBUSY:
19598 + err = au_ibusy_compat_ioctl(file, arg);
19601 + case AUFS_CTL_BRINFO:
19602 + err = au_brinfo_compat_ioctl(file, arg);
19606 + err = aufs_ioctl_dir(file, cmd, arg);
19613 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19614 + unsigned long arg)
19616 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19619 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19620 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19621 +++ linux/fs/aufs/i_op_add.c 2020-01-27 10:57:18.172204883 +0100
19623 +// SPDX-License-Identifier: GPL-2.0
19625 + * Copyright (C) 2005-2020 Junjiro R. Okajima
19627 + * This program, aufs is free software; you can redistribute it and/or modify
19628 + * it under the terms of the GNU General Public License as published by
19629 + * the Free Software Foundation; either version 2 of the License, or
19630 + * (at your option) any later version.
19632 + * This program is distributed in the hope that it will be useful,
19633 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19634 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19635 + * GNU General Public License for more details.
19637 + * You should have received a copy of the GNU General Public License
19638 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19642 + * inode operations (add entry)
19645 +#include <linux/iversion.h>
19649 + * final procedure of adding a new entry, except link(2).
19650 + * remove whiteout, instantiate, copyup the parent dir's times and size
19651 + * and update version.
19652 + * if it failed, re-create the removed whiteout.
19654 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19655 + struct dentry *wh_dentry, struct dentry *dentry)
19658 + aufs_bindex_t bwh;
19659 + struct path h_path;
19660 + struct super_block *sb;
19661 + struct inode *inode, *h_dir;
19662 + struct dentry *wh;
19667 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19668 + IMustLock(h_dir);
19669 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19670 + bwh = au_dbwh(dentry);
19671 + h_path.dentry = wh_dentry;
19672 + h_path.mnt = au_sbr_mnt(sb, bindex);
19673 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19675 + if (unlikely(err))
19679 + inode = au_new_inode(dentry, /*must_new*/1);
19680 + if (!IS_ERR(inode)) {
19681 + d_instantiate(dentry, inode);
19682 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19684 + au_dir_ts(dir, bindex);
19685 + inode_inc_iversion(dir);
19686 + au_fhsm_wrote(sb, bindex, /*force*/0);
19687 + return 0; /* success */
19690 + err = PTR_ERR(inode);
19695 + /* dir inode is locked */
19696 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19697 + rerr = PTR_ERR(wh);
19698 + if (IS_ERR(wh)) {
19699 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19700 + dentry, err, rerr);
19709 +static int au_d_may_add(struct dentry *dentry)
19714 + if (unlikely(d_unhashed(dentry)))
19716 + if (unlikely(d_really_is_positive(dentry)))
19722 + * simple tests for the adding inode operations.
19723 + * following the checks in vfs, plus the parent-child relationship.
19725 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19726 + struct dentry *h_parent, int isdir)
19730 + struct dentry *h_dentry;
19731 + struct inode *h_inode;
19733 + err = -ENAMETOOLONG;
19734 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19737 + h_dentry = au_h_dptr(dentry, bindex);
19738 + if (d_really_is_negative(dentry)) {
19740 + if (unlikely(d_is_positive(h_dentry)))
19743 + /* rename(2) case */
19745 + if (unlikely(d_is_negative(h_dentry)))
19747 + h_inode = d_inode(h_dentry);
19748 + if (unlikely(!h_inode->i_nlink))
19751 + h_mode = h_inode->i_mode;
19754 + if (unlikely(S_ISDIR(h_mode)))
19756 + } else if (unlikely(!S_ISDIR(h_mode))) {
19763 + /* expected parent dir is locked */
19764 + if (unlikely(h_parent != h_dentry->d_parent))
19773 + * initial procedure of adding a new entry.
19774 + * prepare writable branch and the parent dir, lock it,
19775 + * and lookup whiteout for the new entry.
19777 +static struct dentry*
19778 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19779 + struct dentry *src_dentry, struct au_pin *pin,
19780 + struct au_wr_dir_args *wr_dir_args)
19782 + struct dentry *wh_dentry, *h_parent;
19783 + struct super_block *sb;
19784 + struct au_branch *br;
19786 + unsigned int udba;
19787 + aufs_bindex_t bcpup;
19789 + AuDbg("%pd\n", dentry);
19791 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19793 + wh_dentry = ERR_PTR(err);
19794 + if (unlikely(err < 0))
19797 + sb = dentry->d_sb;
19798 + udba = au_opt_udba(sb);
19799 + err = au_pin(pin, dentry, bcpup, udba,
19800 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19801 + wh_dentry = ERR_PTR(err);
19802 + if (unlikely(err))
19805 + h_parent = au_pinned_h_parent(pin);
19806 + if (udba != AuOpt_UDBA_NONE
19807 + && au_dbtop(dentry) == bcpup)
19808 + err = au_may_add(dentry, bcpup, h_parent,
19809 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19810 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19811 + err = -ENAMETOOLONG;
19812 + wh_dentry = ERR_PTR(err);
19813 + if (unlikely(err))
19816 + br = au_sbr(sb, bcpup);
19818 + struct path tmp = {
19819 + .dentry = h_parent,
19820 + .mnt = au_br_mnt(br)
19822 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19825 + wh_dentry = NULL;
19826 + if (bcpup != au_dbwh(dentry))
19827 + goto out; /* success */
19830 + * ENAMETOOLONG here means that if we allowed create such name, then it
19831 + * would not be able to removed in the future. So we don't allow such
19832 + * name here and we don't handle ENAMETOOLONG differently here.
19834 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19837 + if (IS_ERR(wh_dentry))
19840 + return wh_dentry;
19843 +/* ---------------------------------------------------------------------- */
19845 +enum { Mknod, Symlink, Creat };
19846 +struct simple_arg {
19853 + struct vfsub_aopen_args *aopen;
19856 + const char *symname;
19865 +static int add_simple(struct inode *dir, struct dentry *dentry,
19866 + struct simple_arg *arg)
19869 + aufs_bindex_t btop;
19870 + unsigned char created;
19871 + const unsigned char try_aopen
19872 + = (arg->type == Creat && arg->u.c.try_aopen);
19873 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19874 + struct dentry *wh_dentry, *parent;
19875 + struct inode *h_dir;
19876 + struct super_block *sb;
19877 + struct au_branch *br;
19878 + /* to reduce stack size */
19880 + struct au_dtime dt;
19881 + struct au_pin pin;
19882 + struct path h_path;
19883 + struct au_wr_dir_args wr_dir_args;
19886 + AuDbg("%pd\n", dentry);
19890 + a = kmalloc(sizeof(*a), GFP_NOFS);
19891 + if (unlikely(!a))
19893 + a->wr_dir_args.force_btgt = -1;
19894 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19896 + parent = dentry->d_parent; /* dir inode is locked */
19897 + if (!try_aopen) {
19898 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19899 + if (unlikely(err))
19902 + err = au_d_may_add(dentry);
19903 + if (unlikely(err))
19906 + di_write_lock_parent(parent);
19907 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19908 + &a->pin, &a->wr_dir_args);
19909 + err = PTR_ERR(wh_dentry);
19910 + if (IS_ERR(wh_dentry))
19913 + btop = au_dbtop(dentry);
19914 + sb = dentry->d_sb;
19915 + br = au_sbr(sb, btop);
19916 + a->h_path.dentry = au_h_dptr(dentry, btop);
19917 + a->h_path.mnt = au_br_mnt(br);
19918 + h_dir = au_pinned_h_dir(&a->pin);
19919 + switch (arg->type) {
19921 + if (!try_aopen || !h_dir->i_op->atomic_open) {
19922 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19923 + arg->u.c.want_excl);
19925 + if (!err && try_aopen)
19926 + aopen->file->f_mode |= FMODE_CREATED;
19929 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
19930 + AuDbg("err %d\n", err);
19931 + AuDbgFile(aopen->file);
19932 + created = err >= 0
19933 + && !!(aopen->file->f_mode & FMODE_CREATED);
19937 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
19941 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
19948 + if (unlikely(err < 0))
19951 + err = epilog(dir, btop, wh_dentry, dentry);
19953 + goto out_unpin; /* success */
19956 + if (created /* && d_is_positive(a->h_path.dentry) */) {
19957 + /* no delegation since it is just created */
19958 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
19961 + AuIOErr("%pd revert failure(%d, %d)\n",
19962 + dentry, err, rerr);
19965 + au_dtime_revert(&a->dt);
19967 + if (try_aopen && h_dir->i_op->atomic_open
19968 + && (aopen->file->f_mode & FMODE_OPENED))
19969 + /* aopen->file is still opened */
19970 + au_lcnt_dec(&aopen->br->br_nfiles);
19973 + au_unpin(&a->pin);
19977 + di_write_unlock(parent);
19979 + if (unlikely(err)) {
19980 + au_update_dbtop(dentry);
19984 + aufs_read_unlock(dentry, AuLock_DW);
19991 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
19994 + struct simple_arg arg = {
20001 + return add_simple(dir, dentry, &arg);
20004 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
20006 + struct simple_arg arg = {
20008 + .u.s.symname = symname
20010 + return add_simple(dir, dentry, &arg);
20013 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
20016 + struct simple_arg arg = {
20020 + .want_excl = want_excl
20023 + return add_simple(dir, dentry, &arg);
20026 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20027 + struct vfsub_aopen_args *aopen_args)
20029 + struct simple_arg arg = {
20032 + .mode = aopen_args->create_mode,
20033 + .want_excl = aopen_args->open_flag & O_EXCL,
20034 + .try_aopen = true,
20035 + .aopen = aopen_args
20038 + return add_simple(dir, dentry, &arg);
20041 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
20044 + aufs_bindex_t bindex;
20045 + struct super_block *sb;
20046 + struct dentry *parent, *h_parent, *h_dentry;
20047 + struct inode *h_dir, *inode;
20048 + struct vfsmount *h_mnt;
20049 + struct au_wr_dir_args wr_dir_args = {
20050 + .force_btgt = -1,
20051 + .flags = AuWrDir_TMPFILE
20054 + /* copy-up may happen */
20058 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20059 + if (unlikely(err))
20062 + err = au_di_init(dentry);
20063 + if (unlikely(err))
20067 + parent = d_find_any_alias(dir);
20068 + AuDebugOn(!parent);
20069 + di_write_lock_parent(parent);
20070 + if (unlikely(d_inode(parent) != dir))
20073 + err = au_digen_test(parent, au_sigen(sb));
20074 + if (unlikely(err))
20077 + bindex = au_dbtop(parent);
20078 + au_set_dbtop(dentry, bindex);
20079 + au_set_dbbot(dentry, bindex);
20080 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
20082 + if (unlikely(err < 0))
20085 + err = -EOPNOTSUPP;
20086 + h_dir = au_h_iptr(dir, bindex);
20087 + if (unlikely(!h_dir->i_op->tmpfile))
20090 + h_mnt = au_sbr_mnt(sb, bindex);
20091 + err = vfsub_mnt_want_write(h_mnt);
20092 + if (unlikely(err))
20095 + h_parent = au_h_dptr(parent, bindex);
20096 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
20097 + if (IS_ERR(h_dentry)) {
20098 + err = PTR_ERR(h_dentry);
20102 + au_set_dbtop(dentry, bindex);
20103 + au_set_dbbot(dentry, bindex);
20104 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
20105 + inode = au_new_inode(dentry, /*must_new*/1);
20106 + if (IS_ERR(inode)) {
20107 + err = PTR_ERR(inode);
20108 + au_set_h_dptr(dentry, bindex, NULL);
20109 + au_set_dbtop(dentry, -1);
20110 + au_set_dbbot(dentry, -1);
20112 + if (!inode->i_nlink)
20113 + set_nlink(inode, 1);
20114 + d_tmpfile(dentry, inode);
20115 + au_di(dentry)->di_tmpfile = 1;
20117 + /* update without i_mutex */
20118 + if (au_ibtop(dir) == au_dbtop(dentry))
20119 + au_cpup_attr_timesizes(dir);
20124 + vfsub_mnt_drop_write(h_mnt);
20126 + di_write_unlock(parent);
20128 + di_write_unlock(dentry);
20129 + if (unlikely(err)) {
20130 + au_di_fin(dentry);
20131 + dentry->d_fsdata = NULL;
20134 + si_read_unlock(sb);
20136 + inode_unlock(dir);
20140 +/* ---------------------------------------------------------------------- */
20142 +struct au_link_args {
20143 + aufs_bindex_t bdst, bsrc;
20144 + struct au_pin pin;
20145 + struct path h_path;
20146 + struct dentry *src_parent, *parent;
20149 +static int au_cpup_before_link(struct dentry *src_dentry,
20150 + struct au_link_args *a)
20153 + struct dentry *h_src_dentry;
20154 + struct au_cp_generic cpg = {
20155 + .dentry = src_dentry,
20160 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20163 + di_read_lock_parent(a->src_parent, AuLock_IR);
20164 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20165 + if (unlikely(err))
20168 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20169 + err = au_pin(&a->pin, src_dentry, a->bdst,
20170 + au_opt_udba(src_dentry->d_sb),
20171 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20172 + if (unlikely(err))
20175 + err = au_sio_cpup_simple(&cpg);
20176 + au_unpin(&a->pin);
20179 + di_read_unlock(a->src_parent, AuLock_IR);
20183 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20184 + struct au_link_args *a)
20187 + unsigned char plink;
20188 + aufs_bindex_t bbot;
20189 + struct dentry *h_src_dentry;
20190 + struct inode *h_inode, *inode, *delegated;
20191 + struct super_block *sb;
20192 + struct file *h_file;
20196 + sb = src_dentry->d_sb;
20197 + inode = d_inode(src_dentry);
20198 + if (au_ibtop(inode) <= a->bdst)
20199 + h_inode = au_h_iptr(inode, a->bdst);
20200 + if (!h_inode || !h_inode->i_nlink) {
20201 + /* copyup src_dentry as the name of dentry. */
20202 + bbot = au_dbbot(dentry);
20203 + if (bbot < a->bsrc)
20204 + au_set_dbbot(dentry, a->bsrc);
20205 + au_set_h_dptr(dentry, a->bsrc,
20206 + dget(au_h_dptr(src_dentry, a->bsrc)));
20207 + dget(a->h_path.dentry);
20208 + au_set_h_dptr(dentry, a->bdst, NULL);
20209 + AuDbg("temporary d_inode...\n");
20210 + spin_lock(&dentry->d_lock);
20211 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20212 + spin_unlock(&dentry->d_lock);
20213 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20214 + if (IS_ERR(h_file))
20215 + err = PTR_ERR(h_file);
20217 + struct au_cp_generic cpg = {
20218 + .dentry = dentry,
20223 + .flags = AuCpup_KEEPLINO
20225 + err = au_sio_cpup_simple(&cpg);
20226 + au_h_open_post(dentry, a->bsrc, h_file);
20228 + dput(a->h_path.dentry);
20229 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20231 + au_set_h_dptr(dentry, a->bdst,
20232 + a->h_path.dentry);
20234 + spin_lock(&dentry->d_lock);
20235 + dentry->d_inode = NULL; /* restore */
20236 + spin_unlock(&dentry->d_lock);
20237 + AuDbg("temporary d_inode...done\n");
20238 + au_set_h_dptr(dentry, a->bsrc, NULL);
20239 + au_set_dbbot(dentry, bbot);
20241 + /* the inode of src_dentry already exists on a.bdst branch */
20242 + h_src_dentry = d_find_alias(h_inode);
20243 + if (!h_src_dentry && au_plink_test(inode)) {
20245 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20246 + err = PTR_ERR(h_src_dentry);
20247 + if (IS_ERR(h_src_dentry))
20250 + if (unlikely(d_is_negative(h_src_dentry))) {
20251 + dput(h_src_dentry);
20252 + h_src_dentry = NULL;
20256 + if (h_src_dentry) {
20257 + delegated = NULL;
20258 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20259 + &a->h_path, &delegated);
20260 + if (unlikely(err == -EWOULDBLOCK)) {
20261 + pr_warn("cannot retry for NFSv4 delegation"
20262 + " for an internal link\n");
20265 + dput(h_src_dentry);
20267 + AuIOErr("no dentry found for hi%lu on b%d\n",
20268 + h_inode->i_ino, a->bdst);
20273 + if (!err && !plink)
20274 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20281 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20282 + struct dentry *dentry)
20285 + struct au_dtime dt;
20286 + struct au_link_args *a;
20287 + struct dentry *wh_dentry, *h_src_dentry;
20288 + struct inode *inode, *delegated;
20289 + struct super_block *sb;
20290 + struct au_wr_dir_args wr_dir_args = {
20291 + /* .force_btgt = -1, */
20292 + .flags = AuWrDir_ADD_ENTRY
20296 + inode = d_inode(src_dentry);
20297 + IMustLock(inode);
20300 + a = kzalloc(sizeof(*a), GFP_NOFS);
20301 + if (unlikely(!a))
20304 + a->parent = dentry->d_parent; /* dir inode is locked */
20305 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20306 + AuLock_NOPLM | AuLock_GEN);
20307 + if (unlikely(err))
20309 + err = au_d_linkable(src_dentry);
20310 + if (unlikely(err))
20312 + err = au_d_may_add(dentry);
20313 + if (unlikely(err))
20316 + a->src_parent = dget_parent(src_dentry);
20317 + wr_dir_args.force_btgt = au_ibtop(inode);
20319 + di_write_lock_parent(a->parent);
20320 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20321 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20323 + err = PTR_ERR(wh_dentry);
20324 + if (IS_ERR(wh_dentry))
20328 + sb = dentry->d_sb;
20329 + a->bdst = au_dbtop(dentry);
20330 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20331 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20332 + a->bsrc = au_ibtop(inode);
20333 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20334 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20335 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20336 + if (!h_src_dentry) {
20337 + a->bsrc = au_dbtop(src_dentry);
20338 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20339 + AuDebugOn(!h_src_dentry);
20340 + } else if (IS_ERR(h_src_dentry)) {
20341 + err = PTR_ERR(h_src_dentry);
20346 + * aufs doesn't touch the credential so
20347 + * security_dentry_create_files_as() is unnecessary.
20349 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20350 + if (a->bdst < a->bsrc
20351 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20352 + err = au_cpup_or_link(src_dentry, dentry, a);
20354 + delegated = NULL;
20355 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20356 + &a->h_path, &delegated);
20357 + if (unlikely(err == -EWOULDBLOCK)) {
20358 + pr_warn("cannot retry for NFSv4 delegation"
20359 + " for an internal link\n");
20363 + dput(h_src_dentry);
20366 + * copyup src_dentry to the branch we process,
20367 + * and then link(2) to it.
20369 + dput(h_src_dentry);
20370 + if (a->bdst < a->bsrc
20371 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20372 + au_unpin(&a->pin);
20373 + di_write_unlock(a->parent);
20374 + err = au_cpup_before_link(src_dentry, a);
20375 + di_write_lock_parent(a->parent);
20377 + err = au_pin(&a->pin, dentry, a->bdst,
20379 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20380 + if (unlikely(err))
20384 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20386 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20387 + delegated = NULL;
20388 + err = vfsub_link(h_src_dentry,
20389 + au_pinned_h_dir(&a->pin),
20390 + &a->h_path, &delegated);
20391 + if (unlikely(err == -EWOULDBLOCK)) {
20392 + pr_warn("cannot retry"
20393 + " for NFSv4 delegation"
20394 + " for an internal link\n");
20400 + if (unlikely(err))
20404 + a->h_path.dentry = wh_dentry;
20405 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20407 + if (unlikely(err))
20411 + au_dir_ts(dir, a->bdst);
20412 + inode_inc_iversion(dir);
20413 + inc_nlink(inode);
20414 + inode->i_ctime = dir->i_ctime;
20415 + d_instantiate(dentry, au_igrab(inode));
20416 + if (d_unhashed(a->h_path.dentry))
20417 + /* some filesystem calls d_drop() */
20419 + /* some filesystems consume an inode even hardlink */
20420 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20421 + goto out_unpin; /* success */
20424 + /* no delegation since it is just created */
20425 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20426 + /*delegated*/NULL, /*force*/0);
20427 + if (unlikely(rerr)) {
20428 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20431 + au_dtime_revert(&dt);
20433 + au_unpin(&a->pin);
20437 + di_write_unlock(a->parent);
20438 + dput(a->src_parent);
20440 + if (unlikely(err)) {
20441 + au_update_dbtop(dentry);
20444 + aufs_read_and_write_unlock2(dentry, src_dentry);
20452 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20455 + aufs_bindex_t bindex;
20456 + unsigned char diropq;
20457 + struct path h_path;
20458 + struct dentry *wh_dentry, *parent, *opq_dentry;
20459 + struct inode *h_inode;
20460 + struct super_block *sb;
20462 + struct au_pin pin;
20463 + struct au_dtime dt;
20464 + } *a; /* reduce the stack usage */
20465 + struct au_wr_dir_args wr_dir_args = {
20466 + .force_btgt = -1,
20467 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20473 + a = kmalloc(sizeof(*a), GFP_NOFS);
20474 + if (unlikely(!a))
20477 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20478 + if (unlikely(err))
20480 + err = au_d_may_add(dentry);
20481 + if (unlikely(err))
20484 + parent = dentry->d_parent; /* dir inode is locked */
20485 + di_write_lock_parent(parent);
20486 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20487 + &a->pin, &wr_dir_args);
20488 + err = PTR_ERR(wh_dentry);
20489 + if (IS_ERR(wh_dentry))
20492 + sb = dentry->d_sb;
20493 + bindex = au_dbtop(dentry);
20494 + h_path.dentry = au_h_dptr(dentry, bindex);
20495 + h_path.mnt = au_sbr_mnt(sb, bindex);
20496 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20497 + if (unlikely(err))
20500 + /* make the dir opaque */
20502 + h_inode = d_inode(h_path.dentry);
20504 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20505 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20506 + opq_dentry = au_diropq_create(dentry, bindex);
20507 + inode_unlock(h_inode);
20508 + err = PTR_ERR(opq_dentry);
20509 + if (IS_ERR(opq_dentry))
20511 + dput(opq_dentry);
20515 + err = epilog(dir, bindex, wh_dentry, dentry);
20518 + goto out_unpin; /* success */
20523 + AuLabel(revert opq);
20524 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20525 + rerr = au_diropq_remove(dentry, bindex);
20526 + inode_unlock(h_inode);
20528 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20529 + dentry, err, rerr);
20535 + AuLabel(revert dir);
20536 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20538 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20539 + dentry, err, rerr);
20542 + au_dtime_revert(&a->dt);
20544 + au_unpin(&a->pin);
20547 + di_write_unlock(parent);
20549 + if (unlikely(err)) {
20550 + au_update_dbtop(dentry);
20553 + aufs_read_unlock(dentry, AuLock_DW);
20559 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20560 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20561 +++ linux/fs/aufs/i_op.c 2020-08-03 09:14:46.095748745 +0200
20563 +// SPDX-License-Identifier: GPL-2.0
20565 + * Copyright (C) 2005-2020 Junjiro R. Okajima
20567 + * This program, aufs is free software; you can redistribute it and/or modify
20568 + * it under the terms of the GNU General Public License as published by
20569 + * the Free Software Foundation; either version 2 of the License, or
20570 + * (at your option) any later version.
20572 + * This program is distributed in the hope that it will be useful,
20573 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20574 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20575 + * GNU General Public License for more details.
20577 + * You should have received a copy of the GNU General Public License
20578 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20582 + * inode operations (except add/del/rename)
20585 +#include <linux/device_cgroup.h>
20586 +#include <linux/fs_stack.h>
20587 +#include <linux/iversion.h>
20588 +#include <linux/namei.h>
20589 +#include <linux/security.h>
20592 +static int h_permission(struct inode *h_inode, int mask,
20593 + struct path *h_path, int brperm)
20596 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20599 + if (write_mask && IS_IMMUTABLE(h_inode))
20603 + if (((mask & MAY_EXEC)
20604 + && S_ISREG(h_inode->i_mode)
20605 + && (path_noexec(h_path)
20606 + || !(h_inode->i_mode & 0111))))
20610 + * - skip the lower fs test in the case of write to ro branch.
20611 + * - nfs dir permission write check is optimized, but a policy for
20612 + * link/rename requires a real check.
20613 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20614 + * in this case, generic_permission() returns -EOPNOTSUPP.
20616 + if ((write_mask && !au_br_writable(brperm))
20617 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20618 + && write_mask && !(mask & MAY_READ))
20619 + || !h_inode->i_op->permission) {
20620 + /* AuLabel(generic_permission); */
20621 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20622 + err = generic_permission(h_inode, mask);
20623 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20624 + err = h_inode->i_op->permission(h_inode, mask);
20627 + /* AuLabel(h_inode->permission); */
20628 + err = h_inode->i_op->permission(h_inode, mask);
20633 + err = devcgroup_inode_permission(h_inode, mask);
20635 + err = security_inode_permission(h_inode, mask);
20641 +static int aufs_permission(struct inode *inode, int mask)
20644 + aufs_bindex_t bindex, bbot;
20645 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20646 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20647 + struct inode *h_inode;
20648 + struct super_block *sb;
20649 + struct au_branch *br;
20651 + /* todo: support rcu-walk? */
20652 + if (mask & MAY_NOT_BLOCK)
20655 + sb = inode->i_sb;
20656 + si_read_lock(sb, AuLock_FLUSH);
20657 + ii_read_lock_child(inode);
20658 +#if 0 /* reserved for future use */
20660 + * This test may be rather 'too much' since the test is essentially done
20661 + * in the aufs_lookup(). Theoretically it is possible that the inode
20662 + * generation doesn't match to the superblock's here. But it isn't a
20663 + * big deal I suppose.
20665 + err = au_iigen_test(inode, au_sigen(sb));
20666 + if (unlikely(err))
20672 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20673 + err = au_busy_or_stale();
20674 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20675 + if (unlikely(!h_inode
20676 + || (h_inode->i_mode & S_IFMT)
20677 + != (inode->i_mode & S_IFMT)))
20681 + bindex = au_ibtop(inode);
20682 + br = au_sbr(sb, bindex);
20683 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20686 + && !special_file(h_inode->i_mode)) {
20687 + /* test whether the upper writable branch exists */
20689 + for (; bindex >= 0; bindex--)
20690 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20698 + /* non-write to dir */
20700 + bbot = au_ibbot(inode);
20701 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20702 + h_inode = au_h_iptr(inode, bindex);
20704 + err = au_busy_or_stale();
20705 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20708 + br = au_sbr(sb, bindex);
20709 + err = h_permission(h_inode, mask, &br->br_path,
20715 + ii_read_unlock(inode);
20716 + si_read_unlock(sb);
20720 +/* ---------------------------------------------------------------------- */
20722 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20723 + unsigned int flags)
20725 + struct dentry *ret, *parent;
20726 + struct inode *inode;
20727 + struct super_block *sb;
20728 + int err, npositive;
20732 + /* todo: support rcu-walk? */
20733 + ret = ERR_PTR(-ECHILD);
20734 + if (flags & LOOKUP_RCU)
20737 + ret = ERR_PTR(-ENAMETOOLONG);
20738 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20742 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20743 + ret = ERR_PTR(err);
20744 + if (unlikely(err))
20747 + err = au_di_init(dentry);
20748 + ret = ERR_PTR(err);
20749 + if (unlikely(err))
20753 + npositive = 0; /* suppress a warning */
20754 + parent = dentry->d_parent; /* dir inode is locked */
20755 + di_read_lock_parent(parent, AuLock_IR);
20756 + err = au_alive_dir(parent);
20758 + err = au_digen_test(parent, au_sigen(sb));
20760 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20761 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20762 + AuLkup_ALLOW_NEG);
20765 + di_read_unlock(parent, AuLock_IR);
20766 + ret = ERR_PTR(err);
20767 + if (unlikely(err < 0))
20771 + inode = au_new_inode(dentry, /*must_new*/0);
20772 + if (IS_ERR(inode)) {
20773 + ret = (void *)inode;
20780 + atomic_inc(&inode->i_count);
20781 + ret = d_splice_alias(inode, dentry);
20782 +#if 0 /* reserved for future use */
20783 + if (unlikely(d_need_lookup(dentry))) {
20784 + spin_lock(&dentry->d_lock);
20785 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20786 + spin_unlock(&dentry->d_lock);
20790 + if (!IS_ERR(ret)) {
20792 + if (ret && ret != dentry)
20793 + ii_write_unlock(inode);
20795 + ii_write_unlock(inode);
20802 + di_write_unlock(dentry);
20804 + si_read_unlock(sb);
20809 +/* ---------------------------------------------------------------------- */
20812 + * very dirty and complicated aufs ->atomic_open().
20813 + * aufs_atomic_open()
20814 + * + au_aopen_or_create()
20816 + * + vfsub_atomic_open()
20817 + * + branch fs ->atomic_open()
20818 + * may call the actual 'open' for h_file
20819 + * + inc br_nfiles only if opened
20820 + * + au_aopen_no_open() or au_aopen_do_open()
20822 + * au_aopen_do_open()
20823 + * + finish_open()
20824 + * + au_do_aopen()
20825 + * + au_do_open() the body of all 'open'
20826 + * + au_do_open_nondir()
20827 + * set the passed h_file
20829 + * au_aopen_no_open()
20830 + * + finish_no_open()
20833 +struct aopen_node {
20834 + struct hlist_bl_node hblist;
20835 + struct file *file, *h_file;
20838 +static int au_do_aopen(struct inode *inode, struct file *file)
20840 + struct hlist_bl_head *aopen;
20841 + struct hlist_bl_node *pos;
20842 + struct aopen_node *node;
20843 + struct au_do_open_args args = {
20845 + .open = au_do_open_nondir
20848 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20849 + hlist_bl_lock(aopen);
20850 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20851 + if (node->file == file) {
20852 + args.h_file = node->h_file;
20855 + hlist_bl_unlock(aopen);
20856 + /* AuDebugOn(!args.h_file); */
20858 + return au_do_open(file, &args);
20861 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20862 + struct aopen_node *aopen_node)
20865 + struct hlist_bl_head *aopen;
20868 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20869 + au_hbl_add(&aopen_node->hblist, aopen);
20870 + err = finish_open(file, dentry, au_do_aopen);
20871 + au_hbl_del(&aopen_node->hblist, aopen);
20872 + /* AuDbgFile(file); */
20873 + AuDbg("%pd%s%s\n", dentry,
20874 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20875 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20881 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20887 + err = finish_no_open(file, dentry);
20893 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20894 + struct file *file, unsigned int open_flag,
20895 + umode_t create_mode)
20897 + int err, did_open;
20898 + unsigned int lkup_flags;
20899 + aufs_bindex_t bindex;
20900 + struct super_block *sb;
20901 + struct dentry *parent, *d;
20902 + struct vfsub_aopen_args args = {
20903 + .open_flag = open_flag,
20904 + .create_mode = create_mode
20906 + struct aopen_node aopen_node = {
20911 + AuDbg("open_flag 0%o\n", open_flag);
20912 + AuDbgDentry(dentry);
20915 + if (!au_di(dentry)) {
20916 + lkup_flags = LOOKUP_OPEN;
20917 + if (open_flag & O_CREAT)
20918 + lkup_flags |= LOOKUP_CREATE;
20919 + d = aufs_lookup(dir, dentry, lkup_flags);
20921 + err = PTR_ERR(d);
20926 + * obsoleted dentry found.
20927 + * another error will be returned later.
20933 + AuDbgDentry(dentry);
20936 + if (d_is_positive(dentry)
20937 + || d_unhashed(dentry)
20938 + || d_unlinked(dentry)
20939 + || !(open_flag & O_CREAT)) {
20940 + err = au_aopen_no_open(file, dentry);
20941 + goto out; /* success */
20944 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20945 + if (unlikely(err))
20948 + sb = dentry->d_sb;
20949 + parent = dentry->d_parent; /* dir is locked */
20950 + di_write_lock_parent(parent);
20951 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
20952 + if (unlikely(err < 0))
20955 + AuDbgDentry(dentry);
20956 + if (d_is_positive(dentry)) {
20957 + err = au_aopen_no_open(file, dentry);
20958 + goto out_parent; /* success */
20961 + args.file = alloc_empty_file(file->f_flags, current_cred());
20962 + err = PTR_ERR(args.file);
20963 + if (IS_ERR(args.file))
20966 + bindex = au_dbtop(dentry);
20967 + err = au_aopen_or_create(dir, dentry, &args);
20969 + AuDbgFile(args.file);
20970 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
20971 + did_open = !!(args.file->f_mode & FMODE_OPENED);
20974 + args.file = NULL;
20976 + di_write_unlock(parent);
20977 + di_write_unlock(dentry);
20978 + if (unlikely(err < 0)) {
20985 + err = au_aopen_no_open(file, dentry);
20987 + aopen_node.h_file = args.file;
20988 + err = au_aopen_do_open(file, dentry, &aopen_node);
20990 + if (unlikely(err < 0)) {
20994 + au_lcnt_dec(&args.br->br_nfiles);
20996 + goto out_sb; /* success */
20999 + di_write_unlock(parent);
21000 + di_write_unlock(dentry);
21002 + si_read_unlock(sb);
21010 +/* ---------------------------------------------------------------------- */
21012 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
21013 + const unsigned char add_entry, aufs_bindex_t bcpup,
21014 + aufs_bindex_t btop)
21017 + struct dentry *h_parent;
21018 + struct inode *h_dir;
21021 + IMustLock(d_inode(parent));
21023 + di_write_lock_parent(parent);
21026 + if (!au_h_dptr(parent, bcpup)) {
21027 + if (btop > bcpup)
21028 + err = au_cpup_dirs(dentry, bcpup);
21029 + else if (btop < bcpup)
21030 + err = au_cpdown_dirs(dentry, bcpup);
21034 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
21035 + h_parent = au_h_dptr(parent, bcpup);
21036 + h_dir = d_inode(h_parent);
21037 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
21038 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
21039 + /* todo: no unlock here */
21040 + inode_unlock_shared(h_dir);
21042 + AuDbg("bcpup %d\n", bcpup);
21044 + if (d_really_is_negative(dentry))
21045 + au_set_h_dptr(dentry, btop, NULL);
21046 + au_update_dbrange(dentry, /*do_put_zero*/0);
21051 + di_write_unlock(parent);
21053 + err = bcpup; /* success */
21060 + * decide the branch and the parent dir where we will create a new entry.
21061 + * returns new bindex or an error.
21062 + * copyup the parent dir if needed.
21064 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
21065 + struct au_wr_dir_args *args)
21068 + unsigned int flags;
21069 + aufs_bindex_t bcpup, btop, src_btop;
21070 + const unsigned char add_entry
21071 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
21072 + | au_ftest_wrdir(args->flags, TMPFILE);
21073 + struct super_block *sb;
21074 + struct dentry *parent;
21075 + struct au_sbinfo *sbinfo;
21077 + sb = dentry->d_sb;
21078 + sbinfo = au_sbi(sb);
21079 + parent = dget_parent(dentry);
21080 + btop = au_dbtop(dentry);
21082 + if (args->force_btgt < 0) {
21083 + if (src_dentry) {
21084 + src_btop = au_dbtop(src_dentry);
21085 + if (src_btop < btop)
21086 + bcpup = src_btop;
21087 + } else if (add_entry) {
21089 + if (au_ftest_wrdir(args->flags, ISDIR))
21090 + au_fset_wbr(flags, DIR);
21091 + err = AuWbrCreate(sbinfo, dentry, flags);
21095 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
21097 + err = AuWbrCopyup(sbinfo, dentry);
21099 + if (!IS_ROOT(dentry)) {
21100 + di_read_lock_parent(parent, !AuLock_IR);
21101 + err = AuWbrCopyup(sbinfo, dentry);
21102 + di_read_unlock(parent, !AuLock_IR);
21104 + err = AuWbrCopyup(sbinfo, dentry);
21107 + if (unlikely(err < 0))
21111 + bcpup = args->force_btgt;
21112 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21115 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21117 + if (bcpup == btop)
21118 + goto out; /* success */
21120 + /* copyup the new parent into the branch we process */
21121 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21123 + if (d_really_is_negative(dentry)) {
21124 + au_set_h_dptr(dentry, btop, NULL);
21125 + au_set_dbtop(dentry, bcpup);
21126 + au_set_dbbot(dentry, bcpup);
21128 + AuDebugOn(add_entry
21129 + && !au_ftest_wrdir(args->flags, TMPFILE)
21130 + && !au_h_dptr(dentry, bcpup));
21138 +/* ---------------------------------------------------------------------- */
21140 +void au_pin_hdir_unlock(struct au_pin *p)
21143 + au_hn_inode_unlock(p->hdir);
21146 +int au_pin_hdir_lock(struct au_pin *p)
21154 + /* even if an error happens later, keep this lock */
21155 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21158 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21163 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21164 + p->h_parent, p->br);
21170 +int au_pin_hdir_relock(struct au_pin *p)
21173 + struct inode *h_i;
21174 + struct dentry *h_d[] = {
21179 + err = au_pin_hdir_lock(p);
21180 + if (unlikely(err))
21183 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21186 + if (d_is_positive(h_d[i])) {
21187 + h_i = d_inode(h_d[i]);
21188 + err = !h_i->i_nlink;
21196 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21198 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
21201 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21204 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21205 + p->lsc_hi, 0, NULL, _RET_IP_);
21206 + au_pin_hdir_set_owner(p, current);
21210 +void au_pin_hdir_release(struct au_pin *p)
21213 + au_pin_hdir_set_owner(p, p->task);
21214 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
21218 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21220 + if (pin && pin->parent)
21221 + return au_h_dptr(pin->parent, pin->bindex);
21225 +void au_unpin(struct au_pin *p)
21228 + au_pin_hdir_unlock(p);
21229 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21230 + vfsub_mnt_drop_write(p->h_mnt);
21234 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21235 + di_read_unlock(p->parent, AuLock_IR);
21236 + iput(p->hdir->hi_inode);
21238 + p->parent = NULL;
21241 + /* do not clear p->task */
21244 +int au_do_pin(struct au_pin *p)
21247 + struct super_block *sb;
21248 + struct inode *h_dir;
21251 + sb = p->dentry->d_sb;
21252 + p->br = au_sbr(sb, p->bindex);
21253 + if (IS_ROOT(p->dentry)) {
21254 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21255 + p->h_mnt = au_br_mnt(p->br);
21256 + err = vfsub_mnt_want_write(p->h_mnt);
21257 + if (unlikely(err)) {
21258 + au_fclr_pin(p->flags, MNT_WRITE);
21265 + p->h_dentry = NULL;
21266 + if (p->bindex <= au_dbbot(p->dentry))
21267 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21269 + p->parent = dget_parent(p->dentry);
21270 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21271 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21274 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21275 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21277 + h_dir = p->hdir->hi_inode;
21281 + * if DI_LOCKED is not set, then p->parent may be different
21282 + * and h_parent can be NULL.
21284 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21286 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21287 + di_read_unlock(p->parent, AuLock_IR);
21289 + p->parent = NULL;
21293 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21294 + p->h_mnt = au_br_mnt(p->br);
21295 + err = vfsub_mnt_want_write(p->h_mnt);
21296 + if (unlikely(err)) {
21297 + au_fclr_pin(p->flags, MNT_WRITE);
21298 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21299 + di_read_unlock(p->parent, AuLock_IR);
21301 + p->parent = NULL;
21307 + err = au_pin_hdir_lock(p);
21309 + goto out; /* success */
21314 + pr_err("err %d\n", err);
21315 + err = au_busy_or_stale();
21320 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21321 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21322 + unsigned int udba, unsigned char flags)
21324 + p->dentry = dentry;
21326 + p->lsc_di = lsc_di;
21327 + p->lsc_hi = lsc_hi;
21328 + p->flags = flags;
21329 + p->bindex = bindex;
21331 + p->parent = NULL;
21335 + p->h_dentry = NULL;
21336 + p->h_parent = NULL;
21338 + p->task = current;
21341 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21342 + unsigned int udba, unsigned char flags)
21344 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21346 + return au_do_pin(pin);
21349 +/* ---------------------------------------------------------------------- */
21352 + * ->setattr() and ->getattr() are called in various cases.
21353 + * chmod, stat: dentry is revalidated.
21354 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21356 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21358 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21359 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21362 + struct dentry *parent;
21365 + if (au_digen_test(dentry, sigen)) {
21366 + parent = dget_parent(dentry);
21367 + di_read_lock_parent(parent, AuLock_IR);
21368 + err = au_refresh_dentry(dentry, parent);
21369 + di_read_unlock(parent, AuLock_IR);
21377 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21378 + struct au_icpup_args *a)
21382 + aufs_bindex_t btop, ibtop;
21383 + struct dentry *hi_wh, *parent;
21384 + struct inode *inode;
21385 + struct au_wr_dir_args wr_dir_args = {
21386 + .force_btgt = -1,
21390 + if (d_is_dir(dentry))
21391 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21392 + /* plink or hi_wh() case */
21393 + btop = au_dbtop(dentry);
21394 + inode = d_inode(dentry);
21395 + ibtop = au_ibtop(inode);
21396 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21397 + wr_dir_args.force_btgt = ibtop;
21398 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21399 + if (unlikely(err < 0))
21403 + au_fset_icpup(a->flags, DID_CPUP);
21406 + a->pin_flags = AuPin_MNT_WRITE;
21408 + if (!IS_ROOT(dentry)) {
21409 + au_fset_pin(a->pin_flags, DI_LOCKED);
21410 + parent = dget_parent(dentry);
21411 + di_write_lock_parent(parent);
21414 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21415 + if (unlikely(err))
21419 + a->h_path.dentry = au_h_dptr(dentry, btop);
21420 + a->h_inode = d_inode(a->h_path.dentry);
21421 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21422 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21423 + if (ia->ia_size < i_size_read(a->h_inode))
21424 + sz = ia->ia_size;
21425 + inode_unlock_shared(a->h_inode);
21429 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21430 + hi_wh = au_hi_wh(inode, a->btgt);
21432 + struct au_cp_generic cpg = {
21433 + .dentry = dentry,
21439 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21440 + if (unlikely(err))
21442 + hi_wh = au_hi_wh(inode, a->btgt);
21443 + /* todo: revalidate hi_wh? */
21448 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21449 + di_downgrade_lock(parent, AuLock_IR);
21453 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21454 + goto out; /* success */
21456 + if (!d_unhashed(dentry)) {
21457 + struct au_cp_generic cpg = {
21458 + .dentry = dentry,
21463 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21465 + err = au_sio_cpup_simple(&cpg);
21467 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21468 + } else if (!hi_wh)
21469 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21471 + a->h_path.dentry = hi_wh; /* do not dget here */
21474 + a->h_inode = d_inode(a->h_path.dentry);
21476 + goto out; /* success */
21477 + au_unpin(&a->pin);
21480 + di_write_unlock(parent);
21485 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21489 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21492 + struct inode *inode, *delegated;
21493 + struct super_block *sb;
21494 + struct file *file;
21495 + struct au_icpup_args *a;
21497 + inode = d_inode(dentry);
21498 + IMustLock(inode);
21500 + err = setattr_prepare(dentry, ia);
21501 + if (unlikely(err))
21505 + a = kzalloc(sizeof(*a), GFP_NOFS);
21506 + if (unlikely(!a))
21509 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21510 + ia->ia_valid &= ~ATTR_MODE;
21513 + sb = dentry->d_sb;
21514 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21515 + if (unlikely(err))
21518 + if (ia->ia_valid & ATTR_FILE) {
21519 + /* currently ftruncate(2) only */
21520 + AuDebugOn(!d_is_reg(dentry));
21521 + file = ia->ia_file;
21522 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21524 + if (unlikely(err))
21526 + ia->ia_file = au_hf_top(file);
21527 + a->udba = AuOpt_UDBA_NONE;
21529 + /* fchmod() doesn't pass ia_file */
21530 + a->udba = au_opt_udba(sb);
21531 + di_write_lock_child(dentry);
21532 + /* no d_unlinked(), to set UDBA_NONE for root */
21533 + if (d_unhashed(dentry))
21534 + a->udba = AuOpt_UDBA_NONE;
21535 + if (a->udba != AuOpt_UDBA_NONE) {
21536 + AuDebugOn(IS_ROOT(dentry));
21537 + err = au_reval_for_attr(dentry, au_sigen(sb));
21538 + if (unlikely(err))
21543 + err = au_pin_and_icpup(dentry, ia, a);
21544 + if (unlikely(err < 0))
21546 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21547 + ia->ia_file = NULL;
21548 + ia->ia_valid &= ~ATTR_FILE;
21551 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21552 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21553 + == (ATTR_MODE | ATTR_CTIME)) {
21554 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21555 + if (unlikely(err))
21557 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21558 + && (ia->ia_valid & ATTR_CTIME)) {
21559 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21560 + if (unlikely(err))
21564 + if (ia->ia_valid & ATTR_SIZE) {
21567 + if (ia->ia_size < i_size_read(inode))
21569 + truncate_setsize(inode, ia->ia_size);
21572 + if (ia->ia_valid & ATTR_FILE)
21574 + inode_unlock(a->h_inode);
21575 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21576 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21578 + delegated = NULL;
21580 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21582 + err = break_deleg_wait(&delegated);
21590 + * regardless aufs 'acl' option setting.
21591 + * why don't all acl-aware fs call this func from their ->setattr()?
21593 + if (!err && (ia->ia_valid & ATTR_MODE))
21594 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21596 + au_cpup_attr_changeable(inode);
21599 + inode_unlock(a->h_inode);
21600 + au_unpin(&a->pin);
21601 + if (unlikely(err))
21602 + au_update_dbtop(dentry);
21604 + di_write_unlock(dentry);
21606 + fi_write_unlock(file);
21607 + ia->ia_file = file;
21608 + ia->ia_valid |= ATTR_FILE;
21611 + si_read_unlock(sb);
21619 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21620 +static int au_h_path_to_set_attr(struct dentry *dentry,
21621 + struct au_icpup_args *a, struct path *h_path)
21624 + struct super_block *sb;
21626 + sb = dentry->d_sb;
21627 + a->udba = au_opt_udba(sb);
21628 + /* no d_unlinked(), to set UDBA_NONE for root */
21629 + if (d_unhashed(dentry))
21630 + a->udba = AuOpt_UDBA_NONE;
21631 + if (a->udba != AuOpt_UDBA_NONE) {
21632 + AuDebugOn(IS_ROOT(dentry));
21633 + err = au_reval_for_attr(dentry, au_sigen(sb));
21634 + if (unlikely(err))
21637 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21638 + if (unlikely(err < 0))
21641 + h_path->dentry = a->h_path.dentry;
21642 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21648 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21649 + struct au_sxattr *arg)
21652 + struct path h_path;
21653 + struct super_block *sb;
21654 + struct au_icpup_args *a;
21655 + struct inode *h_inode;
21657 + IMustLock(inode);
21660 + a = kzalloc(sizeof(*a), GFP_NOFS);
21661 + if (unlikely(!a))
21664 + sb = dentry->d_sb;
21665 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21666 + if (unlikely(err))
21669 + h_path.dentry = NULL; /* silence gcc */
21670 + di_write_lock_child(dentry);
21671 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21672 + if (unlikely(err))
21675 + inode_unlock(a->h_inode);
21676 + switch (arg->type) {
21677 + case AU_XATTR_SET:
21678 + AuDebugOn(d_is_negative(h_path.dentry));
21679 + err = vfsub_setxattr(h_path.dentry,
21680 + arg->u.set.name, arg->u.set.value,
21681 + arg->u.set.size, arg->u.set.flags);
21684 + err = -EOPNOTSUPP;
21685 + h_inode = d_inode(h_path.dentry);
21686 + if (h_inode->i_op->set_acl)
21687 + /* this will call posix_acl_update_mode */
21688 + err = h_inode->i_op->set_acl(h_inode,
21689 + arg->u.acl_set.acl,
21690 + arg->u.acl_set.type);
21694 + au_cpup_attr_timesizes(inode);
21696 + au_unpin(&a->pin);
21697 + if (unlikely(err))
21698 + au_update_dbtop(dentry);
21701 + di_write_unlock(dentry);
21702 + si_read_unlock(sb);
21711 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21712 + unsigned int nlink)
21716 + inode->i_mode = st->mode;
21717 + /* don't i_[ug]id_write() here */
21718 + inode->i_uid = st->uid;
21719 + inode->i_gid = st->gid;
21720 + inode->i_atime = st->atime;
21721 + inode->i_mtime = st->mtime;
21722 + inode->i_ctime = st->ctime;
21724 + au_cpup_attr_nlink(inode, /*force*/0);
21725 + if (S_ISDIR(inode->i_mode)) {
21726 + n = inode->i_nlink;
21729 + smp_mb(); /* for i_nlink */
21730 + /* 0 can happen */
21731 + set_nlink(inode, n);
21734 + spin_lock(&inode->i_lock);
21735 + inode->i_blocks = st->blocks;
21736 + i_size_write(inode, st->size);
21737 + spin_unlock(&inode->i_lock);
21741 + * common routine for aufs_getattr() and au_getxattr().
21742 + * returns zero or negative (an error).
21743 + * @dentry will be read-locked in success.
21745 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
21746 + struct path *h_path, int locked)
21749 + unsigned int mnt_flags, sigen;
21750 + unsigned char udba_none;
21751 + aufs_bindex_t bindex;
21752 + struct super_block *sb, *h_sb;
21754 + h_path->mnt = NULL;
21755 + h_path->dentry = NULL;
21758 + sb = dentry->d_sb;
21759 + mnt_flags = au_mntflags(sb);
21760 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21762 + if (unlikely(locked))
21763 + goto body; /* skip locking dinfo */
21765 + /* support fstat(2) */
21766 + if (!d_unlinked(dentry) && !udba_none) {
21767 + sigen = au_sigen(sb);
21768 + err = au_digen_test(dentry, sigen);
21770 + di_read_lock_child(dentry, AuLock_IR);
21771 + err = au_dbrange_test(dentry);
21772 + if (unlikely(err)) {
21773 + di_read_unlock(dentry, AuLock_IR);
21777 + AuDebugOn(IS_ROOT(dentry));
21778 + di_write_lock_child(dentry);
21779 + err = au_dbrange_test(dentry);
21781 + err = au_reval_for_attr(dentry, sigen);
21783 + di_downgrade_lock(dentry, AuLock_IR);
21785 + di_write_unlock(dentry);
21790 + di_read_lock_child(dentry, AuLock_IR);
21794 + inode = d_inode(dentry);
21795 + if (unlikely(!inode))
21798 + bindex = au_ibtop(inode);
21799 + h_path->mnt = au_sbr_mnt(sb, bindex);
21800 + h_sb = h_path->mnt->mnt_sb;
21802 + && !au_test_fs_bad_iattr(h_sb)
21804 + goto out; /* success */
21806 + if (au_dbtop(dentry) == bindex)
21807 + h_path->dentry = au_h_dptr(dentry, bindex);
21808 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21809 + h_path->dentry = au_plink_lkup(inode, bindex);
21810 + if (IS_ERR(h_path->dentry))
21811 + /* pretending success */
21812 + h_path->dentry = NULL;
21814 + dput(h_path->dentry);
21821 +static int aufs_getattr(const struct path *path, struct kstat *st,
21822 + u32 request, unsigned int query)
21825 + unsigned char positive;
21826 + struct path h_path;
21827 + struct dentry *dentry;
21828 + struct inode *inode;
21829 + struct super_block *sb;
21831 + dentry = path->dentry;
21832 + inode = d_inode(dentry);
21833 + sb = dentry->d_sb;
21834 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21835 + if (unlikely(err))
21837 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
21839 + if (unlikely(err))
21841 + if (unlikely(!h_path.dentry))
21842 + /* illegally overlapped or something */
21843 + goto out_fill; /* pretending success */
21845 + positive = d_is_positive(h_path.dentry);
21847 + /* no vfsub version */
21848 + err = vfs_getattr(&h_path, st, request, query);
21851 + au_refresh_iattr(inode, st,
21852 + d_inode(h_path.dentry)->i_nlink);
21853 + goto out_fill; /* success */
21859 + generic_fillattr(inode, st);
21861 + di_read_unlock(dentry, AuLock_IR);
21863 + si_read_unlock(sb);
21869 +/* ---------------------------------------------------------------------- */
21871 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21872 + struct delayed_call *done)
21875 + struct dentry *h_dentry;
21876 + struct inode *h_inode;
21878 + aufs_bindex_t bindex;
21880 + ret = NULL; /* suppress a warning */
21885 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21886 + if (unlikely(err))
21889 + err = au_d_hashed_positive(dentry);
21890 + if (unlikely(err))
21894 + inode = d_inode(dentry);
21895 + bindex = au_ibtop(inode);
21896 + h_inode = au_h_iptr(inode, bindex);
21897 + if (unlikely(!h_inode->i_op->get_link))
21902 + if (au_dbtop(dentry) <= bindex) {
21903 + h_dentry = au_h_dptr(dentry, bindex);
21908 + h_dentry = d_find_any_alias(h_inode);
21909 + if (IS_ERR(h_dentry)) {
21910 + err = PTR_ERR(h_dentry);
21914 + if (unlikely(!h_dentry))
21918 + AuDbg("%ps\n", h_inode->i_op->get_link);
21919 + AuDbgDentry(h_dentry);
21920 + ret = vfs_get_link(h_dentry, done);
21923 + err = PTR_ERR(ret);
21926 + aufs_read_unlock(dentry, AuLock_IR);
21928 + if (unlikely(err))
21929 + ret = ERR_PTR(err);
21930 + AuTraceErrPtr(ret);
21934 +/* ---------------------------------------------------------------------- */
21936 +static int au_is_special(struct inode *inode)
21938 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
21941 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
21945 + aufs_bindex_t bindex;
21946 + struct super_block *sb;
21947 + struct inode *h_inode;
21948 + struct vfsmount *h_mnt;
21950 + sb = inode->i_sb;
21951 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
21952 + "unexpected s_flags 0x%lx", sb->s_flags);
21954 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
21956 + si_read_lock(sb, AuLock_FLUSH);
21957 + ii_write_lock_child(inode);
21960 + bindex = au_ibtop(inode);
21961 + h_inode = au_h_iptr(inode, bindex);
21962 + if (!au_test_ro(sb, bindex, inode)) {
21963 + h_mnt = au_sbr_mnt(sb, bindex);
21964 + err = vfsub_mnt_want_write(h_mnt);
21966 + err = vfsub_update_time(h_inode, ts, flags);
21967 + vfsub_mnt_drop_write(h_mnt);
21969 + } else if (au_is_special(h_inode)) {
21971 + * Never copy-up here.
21972 + * These special files may already be opened and used for
21973 + * communicating. If we copied it up, then the communication
21974 + * would be corrupted.
21976 + AuWarn1("timestamps for i%lu are ignored "
21977 + "since it is on readonly branch (hi%lu).\n",
21978 + inode->i_ino, h_inode->i_ino);
21979 + } else if (flags & ~S_ATIME) {
21981 + AuIOErr1("unexpected flags 0x%x\n", flags);
21986 + au_cpup_attr_timesizes(inode);
21987 + ii_write_unlock(inode);
21988 + si_read_unlock(sb);
21991 + if (!err && (flags & S_VERSION))
21992 + inode_inc_iversion(inode);
21997 +/* ---------------------------------------------------------------------- */
21999 +/* no getattr version will be set by module.c:aufs_init() */
22000 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
22002 + [AuIop_SYMLINK] = {
22003 + .permission = aufs_permission,
22004 +#ifdef CONFIG_FS_POSIX_ACL
22005 + .get_acl = aufs_get_acl,
22006 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
22009 + .setattr = aufs_setattr,
22010 + .getattr = aufs_getattr,
22012 +#ifdef CONFIG_AUFS_XATTR
22013 + .listxattr = aufs_listxattr,
22016 + .get_link = aufs_get_link,
22018 + /* .update_time = aufs_update_time */
22021 + .create = aufs_create,
22022 + .lookup = aufs_lookup,
22023 + .link = aufs_link,
22024 + .unlink = aufs_unlink,
22025 + .symlink = aufs_symlink,
22026 + .mkdir = aufs_mkdir,
22027 + .rmdir = aufs_rmdir,
22028 + .mknod = aufs_mknod,
22029 + .rename = aufs_rename,
22031 + .permission = aufs_permission,
22032 +#ifdef CONFIG_FS_POSIX_ACL
22033 + .get_acl = aufs_get_acl,
22034 + .set_acl = aufs_set_acl,
22037 + .setattr = aufs_setattr,
22038 + .getattr = aufs_getattr,
22040 +#ifdef CONFIG_AUFS_XATTR
22041 + .listxattr = aufs_listxattr,
22044 + .update_time = aufs_update_time,
22045 + .atomic_open = aufs_atomic_open,
22046 + .tmpfile = aufs_tmpfile
22048 + [AuIop_OTHER] = {
22049 + .permission = aufs_permission,
22050 +#ifdef CONFIG_FS_POSIX_ACL
22051 + .get_acl = aufs_get_acl,
22052 + .set_acl = aufs_set_acl,
22055 + .setattr = aufs_setattr,
22056 + .getattr = aufs_getattr,
22058 +#ifdef CONFIG_AUFS_XATTR
22059 + .listxattr = aufs_listxattr,
22062 + .update_time = aufs_update_time
22065 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
22066 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
22067 +++ linux/fs/aufs/i_op_del.c 2020-01-27 10:57:18.172204883 +0100
22069 +// SPDX-License-Identifier: GPL-2.0
22071 + * Copyright (C) 2005-2020 Junjiro R. Okajima
22073 + * This program, aufs is free software; you can redistribute it and/or modify
22074 + * it under the terms of the GNU General Public License as published by
22075 + * the Free Software Foundation; either version 2 of the License, or
22076 + * (at your option) any later version.
22078 + * This program is distributed in the hope that it will be useful,
22079 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22080 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22081 + * GNU General Public License for more details.
22083 + * You should have received a copy of the GNU General Public License
22084 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22088 + * inode operations (del entry)
22091 +#include <linux/iversion.h>
22095 + * decide if a new whiteout for @dentry is necessary or not.
22096 + * when it is necessary, prepare the parent dir for the upper branch whose
22097 + * branch index is @bcpup for creation. the actual creation of the whiteout will
22098 + * be done by caller.
22100 + * 0: wh is unnecessary
22101 + * plus: wh is necessary
22104 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
22106 + int need_wh, err;
22107 + aufs_bindex_t btop;
22108 + struct super_block *sb;
22110 + sb = dentry->d_sb;
22111 + btop = au_dbtop(dentry);
22112 + if (*bcpup < 0) {
22114 + if (au_test_ro(sb, btop, d_inode(dentry))) {
22115 + err = AuWbrCopyup(au_sbi(sb), dentry);
22117 + if (unlikely(err < 0))
22121 + AuDebugOn(btop < *bcpup
22122 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22123 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22125 + if (*bcpup != btop) {
22126 + err = au_cpup_dirs(dentry, *bcpup);
22127 + if (unlikely(err))
22131 + struct au_dinfo *dinfo, *tmp;
22133 + need_wh = -ENOMEM;
22134 + dinfo = au_di(dentry);
22135 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22137 + au_di_cp(tmp, dinfo);
22138 + au_di_swap(tmp, dinfo);
22139 + /* returns the number of positive dentries */
22140 + need_wh = au_lkup_dentry(dentry, btop + 1,
22141 + /* AuLkup_IGNORE_PERM */ 0);
22142 + au_di_swap(tmp, dinfo);
22143 + au_rw_write_unlock(&tmp->di_rwsem);
22147 + AuDbg("need_wh %d\n", need_wh);
22155 + * simple tests for the del-entry operations.
22156 + * following the checks in vfs, plus the parent-child relationship.
22158 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22159 + struct dentry *h_parent, int isdir)
22163 + struct dentry *h_dentry, *h_latest;
22164 + struct inode *h_inode;
22166 + h_dentry = au_h_dptr(dentry, bindex);
22167 + if (d_really_is_positive(dentry)) {
22169 + if (unlikely(d_is_negative(h_dentry)))
22171 + h_inode = d_inode(h_dentry);
22172 + if (unlikely(!h_inode->i_nlink))
22175 + h_mode = h_inode->i_mode;
22178 + if (unlikely(S_ISDIR(h_mode)))
22180 + } else if (unlikely(!S_ISDIR(h_mode))) {
22185 + /* rename(2) case */
22187 + if (unlikely(d_is_positive(h_dentry)))
22192 + /* expected parent dir is locked */
22193 + if (unlikely(h_parent != h_dentry->d_parent))
22198 + * rmdir a dir may break the consistency on some filesystem.
22199 + * let's try heavy test.
22202 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22203 + && au_test_h_perm(d_inode(h_parent),
22204 + MAY_EXEC | MAY_WRITE)))
22207 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
22209 + if (IS_ERR(h_latest))
22211 + if (h_latest == h_dentry)
22220 + * decide the branch where we operate for @dentry. the branch index will be set
22221 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22222 + * dir for reverting.
22223 + * when a new whiteout is necessary, create it.
22225 +static struct dentry*
22226 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22227 + struct au_dtime *dt, struct au_pin *pin)
22229 + struct dentry *wh_dentry;
22230 + struct super_block *sb;
22231 + struct path h_path;
22232 + int err, need_wh;
22233 + unsigned int udba;
22234 + aufs_bindex_t bcpup;
22236 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22237 + wh_dentry = ERR_PTR(need_wh);
22238 + if (unlikely(need_wh < 0))
22241 + sb = dentry->d_sb;
22242 + udba = au_opt_udba(sb);
22244 + err = au_pin(pin, dentry, bcpup, udba,
22245 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22246 + wh_dentry = ERR_PTR(err);
22247 + if (unlikely(err))
22250 + h_path.dentry = au_pinned_h_parent(pin);
22251 + if (udba != AuOpt_UDBA_NONE
22252 + && au_dbtop(dentry) == bcpup) {
22253 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22254 + wh_dentry = ERR_PTR(err);
22255 + if (unlikely(err))
22259 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22260 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22261 + wh_dentry = NULL;
22263 + goto out; /* success, no need to create whiteout */
22265 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22266 + if (IS_ERR(wh_dentry))
22269 + /* returns with the parent is locked and wh_dentry is dget-ed */
22270 + goto out; /* success */
22275 + return wh_dentry;
22279 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22280 + * in order to be revertible and save time for removing many child whiteouts
22282 + * returns 1 when there are too many child whiteout and caller should remove
22283 + * them asynchronously. returns 0 when the number of children is enough small to
22284 + * remove now or the branch fs is a remote fs.
22285 + * otherwise return an error.
22287 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22288 + struct au_nhash *whlist, struct inode *dir)
22290 + int rmdir_later, err, dirwh;
22291 + struct dentry *h_dentry;
22292 + struct super_block *sb;
22293 + struct inode *inode;
22295 + sb = dentry->d_sb;
22296 + SiMustAnyLock(sb);
22297 + h_dentry = au_h_dptr(dentry, bindex);
22298 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22299 + if (unlikely(err))
22302 + /* stop monitoring */
22303 + inode = d_inode(dentry);
22304 + au_hn_free(au_hi(inode, bindex));
22306 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22307 + dirwh = au_sbi(sb)->si_dirwh;
22308 + rmdir_later = (dirwh <= 1);
22309 + if (!rmdir_later)
22310 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22313 + return rmdir_later;
22316 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22317 + if (unlikely(err)) {
22318 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22319 + h_dentry, bindex, err);
22329 + * final procedure for deleting a entry.
22330 + * maintain dentry and iattr.
22332 +static void epilog(struct inode *dir, struct dentry *dentry,
22333 + aufs_bindex_t bindex)
22335 + struct inode *inode;
22337 + inode = d_inode(dentry);
22339 + inode->i_ctime = dir->i_ctime;
22341 + au_dir_ts(dir, bindex);
22342 + inode_inc_iversion(dir);
22346 + * when an error happened, remove the created whiteout and revert everything.
22348 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22349 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22350 + struct dentry *dentry, struct au_dtime *dt)
22353 + struct path h_path = {
22354 + .dentry = wh_dentry,
22355 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22358 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22360 + au_set_dbwh(dentry, bwh);
22361 + au_dtime_revert(dt);
22365 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22369 +/* ---------------------------------------------------------------------- */
22371 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22374 + aufs_bindex_t bwh, bindex, btop;
22375 + struct inode *inode, *h_dir, *delegated;
22376 + struct dentry *parent, *wh_dentry;
22377 + /* to reduce stack size */
22379 + struct au_dtime dt;
22380 + struct au_pin pin;
22381 + struct path h_path;
22387 + a = kmalloc(sizeof(*a), GFP_NOFS);
22388 + if (unlikely(!a))
22391 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22392 + if (unlikely(err))
22394 + err = au_d_hashed_positive(dentry);
22395 + if (unlikely(err))
22397 + inode = d_inode(dentry);
22398 + IMustLock(inode);
22400 + if (unlikely(d_is_dir(dentry)))
22401 + goto out_unlock; /* possible? */
22403 + btop = au_dbtop(dentry);
22404 + bwh = au_dbwh(dentry);
22406 + parent = dentry->d_parent; /* dir inode is locked */
22407 + di_write_lock_parent(parent);
22408 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22410 + err = PTR_ERR(wh_dentry);
22411 + if (IS_ERR(wh_dentry))
22414 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22415 + a->h_path.dentry = au_h_dptr(dentry, btop);
22416 + dget(a->h_path.dentry);
22417 + if (bindex == btop) {
22418 + h_dir = au_pinned_h_dir(&a->pin);
22419 + delegated = NULL;
22420 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22421 + if (unlikely(err == -EWOULDBLOCK)) {
22422 + pr_warn("cannot retry for NFSv4 delegation"
22423 + " for an internal unlink\n");
22427 + /* dir inode is locked */
22428 + h_dir = d_inode(wh_dentry->d_parent);
22429 + IMustLock(h_dir);
22434 + vfsub_drop_nlink(inode);
22435 + epilog(dir, dentry, bindex);
22437 + /* update target timestamps */
22438 + if (bindex == btop) {
22439 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22441 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22443 + /* todo: this timestamp may be reverted later */
22444 + inode->i_ctime = h_dir->i_ctime;
22445 + goto out_unpin; /* success */
22452 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22459 + au_unpin(&a->pin);
22461 + dput(a->h_path.dentry);
22463 + di_write_unlock(parent);
22465 + aufs_read_unlock(dentry, AuLock_DW);
22472 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22474 + int err, rmdir_later;
22475 + aufs_bindex_t bwh, bindex, btop;
22476 + struct inode *inode;
22477 + struct dentry *parent, *wh_dentry, *h_dentry;
22478 + struct au_whtmp_rmdir *args;
22479 + /* to reduce stack size */
22481 + struct au_dtime dt;
22482 + struct au_pin pin;
22488 + a = kmalloc(sizeof(*a), GFP_NOFS);
22489 + if (unlikely(!a))
22492 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22493 + if (unlikely(err))
22495 + err = au_alive_dir(dentry);
22496 + if (unlikely(err))
22498 + inode = d_inode(dentry);
22499 + IMustLock(inode);
22501 + if (unlikely(!d_is_dir(dentry)))
22502 + goto out_unlock; /* possible? */
22505 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22506 + if (unlikely(!args))
22509 + parent = dentry->d_parent; /* dir inode is locked */
22510 + di_write_lock_parent(parent);
22511 + err = au_test_empty(dentry, &args->whlist);
22512 + if (unlikely(err))
22515 + btop = au_dbtop(dentry);
22516 + bwh = au_dbwh(dentry);
22518 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22520 + err = PTR_ERR(wh_dentry);
22521 + if (IS_ERR(wh_dentry))
22524 + h_dentry = au_h_dptr(dentry, btop);
22527 + if (bindex == btop) {
22528 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22530 + rmdir_later = err;
22534 + /* stop monitoring */
22535 + au_hn_free(au_hi(inode, btop));
22537 + /* dir inode is locked */
22538 + IMustLock(d_inode(wh_dentry->d_parent));
22543 + vfsub_dead_dir(inode);
22544 + au_set_dbdiropq(dentry, -1);
22545 + epilog(dir, dentry, bindex);
22547 + if (rmdir_later) {
22548 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22552 + goto out_unpin; /* success */
22560 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22567 + au_unpin(&a->pin);
22571 + di_write_unlock(parent);
22573 + au_whtmp_rmdir_free(args);
22575 + aufs_read_unlock(dentry, AuLock_DW);
22582 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22583 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22584 +++ linux/fs/aufs/i_op_ren.c 2020-01-27 10:57:18.172204883 +0100
22586 +// SPDX-License-Identifier: GPL-2.0
22588 + * Copyright (C) 2005-2020 Junjiro R. Okajima
22590 + * This program, aufs is free software; you can redistribute it and/or modify
22591 + * it under the terms of the GNU General Public License as published by
22592 + * the Free Software Foundation; either version 2 of the License, or
22593 + * (at your option) any later version.
22595 + * This program is distributed in the hope that it will be useful,
22596 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22597 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22598 + * GNU General Public License for more details.
22600 + * You should have received a copy of the GNU General Public License
22601 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22605 + * inode operation (rename entry)
22606 + * todo: this is crazy monster
22609 +#include <linux/iversion.h>
22612 +enum { AuSRC, AuDST, AuSrcDst };
22613 +enum { AuPARENT, AuCHILD, AuParentChild };
22615 +#define AuRen_ISDIR_SRC 1
22616 +#define AuRen_ISDIR_DST (1 << 1)
22617 +#define AuRen_ISSAMEDIR (1 << 2)
22618 +#define AuRen_WHSRC (1 << 3)
22619 +#define AuRen_WHDST (1 << 4)
22620 +#define AuRen_MNT_WRITE (1 << 5)
22621 +#define AuRen_DT_DSTDIR (1 << 6)
22622 +#define AuRen_DIROPQ_SRC (1 << 7)
22623 +#define AuRen_DIROPQ_DST (1 << 8)
22624 +#define AuRen_DIRREN (1 << 9)
22625 +#define AuRen_DROPPED_SRC (1 << 10)
22626 +#define AuRen_DROPPED_DST (1 << 11)
22627 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22628 +#define au_fset_ren(flags, name) \
22629 + do { (flags) |= AuRen_##name; } while (0)
22630 +#define au_fclr_ren(flags, name) \
22631 + do { (flags) &= ~AuRen_##name; } while (0)
22633 +#ifndef CONFIG_AUFS_DIRREN
22634 +#undef AuRen_DIRREN
22635 +#define AuRen_DIRREN 0
22638 +struct au_ren_args {
22640 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22642 + struct inode *dir, *inode;
22643 + struct au_hinode *hdir, *hinode;
22644 + struct au_dtime dt[AuParentChild];
22645 + aufs_bindex_t btop, bdiropq;
22648 +#define src_dentry sd[AuSRC].dentry
22649 +#define src_dir sd[AuSRC].dir
22650 +#define src_inode sd[AuSRC].inode
22651 +#define src_h_dentry sd[AuSRC].h_dentry
22652 +#define src_parent sd[AuSRC].parent
22653 +#define src_h_parent sd[AuSRC].h_parent
22654 +#define src_wh_dentry sd[AuSRC].wh_dentry
22655 +#define src_hdir sd[AuSRC].hdir
22656 +#define src_hinode sd[AuSRC].hinode
22657 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22658 +#define src_dt sd[AuSRC].dt
22659 +#define src_btop sd[AuSRC].btop
22660 +#define src_bdiropq sd[AuSRC].bdiropq
22662 +#define dst_dentry sd[AuDST].dentry
22663 +#define dst_dir sd[AuDST].dir
22664 +#define dst_inode sd[AuDST].inode
22665 +#define dst_h_dentry sd[AuDST].h_dentry
22666 +#define dst_parent sd[AuDST].parent
22667 +#define dst_h_parent sd[AuDST].h_parent
22668 +#define dst_wh_dentry sd[AuDST].wh_dentry
22669 +#define dst_hdir sd[AuDST].hdir
22670 +#define dst_hinode sd[AuDST].hinode
22671 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22672 +#define dst_dt sd[AuDST].dt
22673 +#define dst_btop sd[AuDST].btop
22674 +#define dst_bdiropq sd[AuDST].bdiropq
22676 + struct dentry *h_trap;
22677 + struct au_branch *br;
22678 + struct path h_path;
22679 + struct au_nhash whlist;
22680 + aufs_bindex_t btgt, src_bwh;
22683 + unsigned short auren_flags;
22684 + unsigned char flags; /* syscall parameter */
22685 + unsigned char exchange;
22688 + struct au_whtmp_rmdir *thargs;
22689 + struct dentry *h_dst;
22690 + struct au_hinode *h_root;
22693 +/* ---------------------------------------------------------------------- */
22696 + * functions for reverting.
22697 + * when an error happened in a single rename systemcall, we should revert
22698 + * everything as if nothing happened.
22699 + * we don't need to revert the copied-up/down the parent dir since they are
22703 +#define RevertFailure(fmt, ...) do { \
22704 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22705 + ##__VA_ARGS__, err, rerr); \
22709 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22712 + struct dentry *d;
22713 +#define src_or_dst(member) a->sd[idx].member
22715 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22716 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22717 + rerr = au_diropq_remove(d, a->btgt);
22718 + au_hn_inode_unlock(src_or_dst(hinode));
22719 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22721 + RevertFailure("remove diropq %pd", d);
22723 +#undef src_or_dst_
22726 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22728 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22729 + au_ren_do_rev_diropq(err, a, AuSRC);
22730 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22731 + au_ren_do_rev_diropq(err, a, AuDST);
22734 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22737 + struct inode *delegated;
22739 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22740 + a->src_h_parent);
22741 + rerr = PTR_ERR(a->h_path.dentry);
22742 + if (IS_ERR(a->h_path.dentry)) {
22743 + RevertFailure("lkup one %pd", a->src_dentry);
22747 + delegated = NULL;
22748 + rerr = vfsub_rename(a->dst_h_dir,
22749 + au_h_dptr(a->src_dentry, a->btgt),
22750 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22751 + if (unlikely(rerr == -EWOULDBLOCK)) {
22752 + pr_warn("cannot retry for NFSv4 delegation"
22753 + " for an internal rename\n");
22756 + d_drop(a->h_path.dentry);
22757 + dput(a->h_path.dentry);
22758 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22760 + RevertFailure("rename %pd", a->src_dentry);
22763 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22766 + struct inode *delegated;
22768 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22769 + a->dst_h_parent);
22770 + rerr = PTR_ERR(a->h_path.dentry);
22771 + if (IS_ERR(a->h_path.dentry)) {
22772 + RevertFailure("lkup one %pd", a->dst_dentry);
22775 + if (d_is_positive(a->h_path.dentry)) {
22776 + d_drop(a->h_path.dentry);
22777 + dput(a->h_path.dentry);
22781 + delegated = NULL;
22782 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22783 + &delegated, a->flags);
22784 + if (unlikely(rerr == -EWOULDBLOCK)) {
22785 + pr_warn("cannot retry for NFSv4 delegation"
22786 + " for an internal rename\n");
22789 + d_drop(a->h_path.dentry);
22790 + dput(a->h_path.dentry);
22792 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22794 + RevertFailure("rename %pd", a->h_dst);
22797 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22801 + a->h_path.dentry = a->src_wh_dentry;
22802 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22803 + au_set_dbwh(a->src_dentry, a->src_bwh);
22805 + RevertFailure("unlink %pd", a->src_wh_dentry);
22807 +#undef RevertFailure
22809 +/* ---------------------------------------------------------------------- */
22812 + * when we have to copyup the renaming entry, do it with the rename-target name
22813 + * in order to minimize the cost (the later actual rename is unnecessary).
22814 + * otherwise rename it on the target branch.
22816 +static int au_ren_or_cpup(struct au_ren_args *a)
22819 + struct dentry *d;
22820 + struct inode *delegated;
22822 + d = a->src_dentry;
22823 + if (au_dbtop(d) == a->btgt) {
22824 + a->h_path.dentry = a->dst_h_dentry;
22825 + AuDebugOn(au_dbtop(d) != a->btgt);
22826 + delegated = NULL;
22827 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22828 + a->dst_h_dir, &a->h_path, &delegated,
22830 + if (unlikely(err == -EWOULDBLOCK)) {
22831 + pr_warn("cannot retry for NFSv4 delegation"
22832 + " for an internal rename\n");
22838 + if (!err && a->h_dst)
22839 + /* it will be set to dinfo later */
22845 +/* cf. aufs_rmdir() */
22846 +static int au_ren_del_whtmp(struct au_ren_args *a)
22849 + struct inode *dir;
22851 + dir = a->dst_dir;
22852 + SiMustAnyLock(dir->i_sb);
22853 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22854 + au_sbi(dir->i_sb)->si_dirwh)
22855 + || au_test_fs_remote(a->h_dst->d_sb)) {
22856 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22857 + if (unlikely(err))
22858 + pr_warn("failed removing whtmp dir %pd (%d), "
22859 + "ignored.\n", a->h_dst, err);
22861 + au_nhash_wh_free(&a->thargs->whlist);
22862 + a->thargs->whlist = a->whlist;
22863 + a->whlist.nh_num = 0;
22864 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22866 + a->thargs = NULL;
22872 +/* make it 'opaque' dir. */
22873 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22876 + struct dentry *d, *diropq;
22877 +#define src_or_dst(member) a->sd[idx].member
22880 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22881 + src_or_dst(bdiropq) = au_dbdiropq(d);
22882 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22883 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22884 + diropq = au_diropq_create(d, a->btgt);
22885 + au_hn_inode_unlock(src_or_dst(hinode));
22886 + if (IS_ERR(diropq))
22887 + err = PTR_ERR(diropq);
22891 +#undef src_or_dst_
22895 +static int au_ren_diropq(struct au_ren_args *a)
22898 + unsigned char always;
22899 + struct dentry *d;
22902 + d = a->dst_dentry; /* already renamed on the branch */
22903 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22904 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22905 + && !au_ftest_ren(a->auren_flags, DIRREN)
22906 + && a->btgt != au_dbdiropq(a->src_dentry)
22907 + && (a->dst_wh_dentry
22908 + || a->btgt <= au_dbdiropq(d)
22909 + /* hide the lower to keep xino */
22910 + /* the lowers may not be a dir, but we hide them anyway */
22911 + || a->btgt < au_dbbot(d)
22914 + err = au_ren_do_diropq(a, AuSRC);
22915 + if (unlikely(err))
22917 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22919 + if (!a->exchange)
22920 + goto out; /* success */
22922 + d = a->src_dentry; /* already renamed on the branch */
22923 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22924 + && a->btgt != au_dbdiropq(a->dst_dentry)
22925 + && (a->btgt < au_dbdiropq(d)
22926 + || a->btgt < au_dbbot(d)
22928 + AuDbgDentry(a->src_dentry);
22929 + AuDbgDentry(a->dst_dentry);
22930 + err = au_ren_do_diropq(a, AuDST);
22931 + if (unlikely(err))
22932 + goto out_rev_src;
22933 + au_fset_ren(a->auren_flags, DIROPQ_DST);
22935 + goto out; /* success */
22938 + AuDbg("err %d, reverting src\n", err);
22939 + au_ren_rev_diropq(err, a);
22944 +static int do_rename(struct au_ren_args *a)
22947 + struct dentry *d, *h_d;
22949 + if (!a->exchange) {
22950 + /* prepare workqueue args for asynchronous rmdir */
22951 + h_d = a->dst_h_dentry;
22952 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22953 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
22954 + && d_is_positive(h_d)) {
22956 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
22958 + if (unlikely(!a->thargs))
22960 + a->h_dst = dget(h_d);
22963 + /* create whiteout for src_dentry */
22964 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
22965 + a->src_bwh = au_dbwh(a->src_dentry);
22966 + AuDebugOn(a->src_bwh >= 0);
22967 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
22968 + a->src_h_parent);
22969 + err = PTR_ERR(a->src_wh_dentry);
22970 + if (IS_ERR(a->src_wh_dentry))
22974 + /* lookup whiteout for dentry */
22975 + if (au_ftest_ren(a->auren_flags, WHDST)) {
22976 + h_d = au_wh_lkup(a->dst_h_parent,
22977 + &a->dst_dentry->d_name, a->br);
22978 + err = PTR_ERR(h_d);
22981 + if (d_is_negative(h_d))
22984 + a->dst_wh_dentry = h_d;
22987 + /* rename dentry to tmpwh */
22989 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
22990 + if (unlikely(err))
22993 + d = a->dst_dentry;
22994 + au_set_h_dptr(d, a->btgt, NULL);
22995 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
22996 + if (unlikely(err))
22998 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
23002 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
23003 +#if 0 /* debugging */
23004 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
23005 + && d_is_positive(a->dst_h_dentry)
23006 + && a->src_btop != a->btgt);
23009 + /* rename by vfs_rename or cpup */
23010 + err = au_ren_or_cpup(a);
23011 + if (unlikely(err))
23012 + /* leave the copied-up one */
23015 + /* make dir opaque */
23016 + err = au_ren_diropq(a);
23017 + if (unlikely(err))
23020 + /* update target timestamps */
23021 + if (a->exchange) {
23022 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
23023 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
23024 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23025 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23027 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
23028 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
23029 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23030 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23032 + if (!a->exchange) {
23033 + /* remove whiteout for dentry */
23034 + if (a->dst_wh_dentry) {
23035 + a->h_path.dentry = a->dst_wh_dentry;
23036 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
23038 + if (unlikely(err))
23042 + /* remove whtmp */
23044 + au_ren_del_whtmp(a); /* ignore this error */
23046 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
23049 + goto out_success;
23052 + au_ren_rev_diropq(err, a);
23054 + au_ren_rev_rename(err, a);
23058 + au_ren_rev_whtmp(err, a);
23060 + dput(a->dst_wh_dentry);
23061 + a->dst_wh_dentry = NULL;
23063 + if (a->src_wh_dentry)
23064 + au_ren_rev_whsrc(err, a);
23066 + dput(a->src_wh_dentry);
23067 + dput(a->dst_wh_dentry);
23071 + au_whtmp_rmdir_free(a->thargs);
23072 + a->thargs = NULL;
23078 +/* ---------------------------------------------------------------------- */
23081 + * test if @dentry dir can be rename destination or not.
23082 + * success means, it is a logically empty dir.
23084 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
23086 + return au_test_empty(dentry, whlist);
23090 + * test if @a->src_dentry dir can be rename source or not.
23091 + * if it can, return 0.
23093 + * - it is a logically empty dir.
23094 + * - or, it exists on writable branch and has no children including whiteouts
23095 + * on the lower branch unless DIRREN is on.
23097 +static int may_rename_srcdir(struct au_ren_args *a)
23100 + unsigned int rdhash;
23101 + aufs_bindex_t btop, btgt;
23102 + struct dentry *dentry;
23103 + struct super_block *sb;
23104 + struct au_sbinfo *sbinfo;
23106 + dentry = a->src_dentry;
23107 + sb = dentry->d_sb;
23108 + sbinfo = au_sbi(sb);
23109 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
23110 + au_fset_ren(a->auren_flags, DIRREN);
23113 + btop = au_dbtop(dentry);
23114 + if (btop != btgt) {
23115 + struct au_nhash whlist;
23117 + SiMustAnyLock(sb);
23118 + rdhash = sbinfo->si_rdhash;
23120 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23122 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23123 + if (unlikely(err))
23125 + err = au_test_empty(dentry, &whlist);
23126 + au_nhash_wh_free(&whlist);
23130 + if (btop == au_dbtaildir(dentry))
23131 + return 0; /* success */
23133 + err = au_test_empty_lower(dentry);
23136 + if (err == -ENOTEMPTY) {
23137 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23140 + AuWarn1("renaming dir who has child(ren) on multiple "
23141 + "branches, is not supported\n");
23148 +/* side effect: sets whlist and h_dentry */
23149 +static int au_ren_may_dir(struct au_ren_args *a)
23152 + unsigned int rdhash;
23153 + struct dentry *d;
23155 + d = a->dst_dentry;
23156 + SiMustAnyLock(d->d_sb);
23159 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23160 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23162 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23163 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23164 + if (unlikely(err))
23167 + if (!a->exchange) {
23168 + au_set_dbtop(d, a->dst_btop);
23169 + err = may_rename_dstdir(d, &a->whlist);
23170 + au_set_dbtop(d, a->btgt);
23172 + err = may_rename_srcdir(a);
23174 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23175 + if (unlikely(err))
23178 + d = a->src_dentry;
23179 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23180 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23181 + err = may_rename_srcdir(a);
23182 + if (unlikely(err)) {
23183 + au_nhash_wh_free(&a->whlist);
23184 + a->whlist.nh_num = 0;
23191 +/* ---------------------------------------------------------------------- */
23194 + * simple tests for rename.
23195 + * following the checks in vfs, plus the parent-child relationship.
23197 +static int au_may_ren(struct au_ren_args *a)
23200 + struct inode *h_inode;
23202 + if (a->src_btop == a->btgt) {
23203 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23204 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23205 + if (unlikely(err))
23208 + if (unlikely(a->src_h_dentry == a->h_trap))
23213 + if (a->dst_btop != a->btgt)
23216 + err = -ENOTEMPTY;
23217 + if (unlikely(a->dst_h_dentry == a->h_trap))
23221 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23222 + if (d_really_is_negative(a->dst_dentry)) {
23223 + if (d_is_negative(a->dst_h_dentry))
23224 + err = au_may_add(a->dst_dentry, a->btgt,
23225 + a->dst_h_parent, isdir);
23227 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23229 + h_inode = d_inode(a->dst_h_dentry);
23230 + if (h_inode->i_nlink)
23231 + err = au_may_del(a->dst_dentry, a->btgt,
23232 + a->dst_h_parent, isdir);
23236 + if (unlikely(err == -ENOENT || err == -EEXIST))
23242 +/* ---------------------------------------------------------------------- */
23247 + * - src_dir and dir by lock_rename()
23248 + * - inode if exists
23251 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23253 + * + di_write_lock2_child()
23254 + * + di_write_lock_child()
23255 + * + ii_write_lock_child()
23256 + * + di_write_lock_child2()
23257 + * + ii_write_lock_child2()
23258 + * + src_parent and parent
23259 + * + di_write_lock_parent()
23260 + * + ii_write_lock_parent()
23261 + * + di_write_lock_parent2()
23262 + * + ii_write_lock_parent2()
23263 + * + lower src_dir and dir by vfsub_lock_rename()
23264 + * + verify the every relationships between child and parent. if any
23265 + * of them failed, unlock all and return -EBUSY.
23267 +static void au_ren_unlock(struct au_ren_args *a)
23269 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23270 + a->dst_h_parent, a->dst_hdir);
23271 + if (au_ftest_ren(a->auren_flags, DIRREN)
23273 + au_hn_inode_unlock(a->h_root);
23274 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23275 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23278 +static int au_ren_lock(struct au_ren_args *a)
23281 + unsigned int udba;
23284 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23285 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23286 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23287 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23289 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23290 + if (unlikely(err))
23292 + au_fset_ren(a->auren_flags, MNT_WRITE);
23293 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23294 + struct dentry *root;
23295 + struct inode *dir;
23298 + * sbinfo is already locked, so this ii_read_lock is
23299 + * unnecessary. but our debugging feature checks it.
23301 + root = a->src_inode->i_sb->s_root;
23302 + if (root != a->src_parent && root != a->dst_parent) {
23303 + dir = d_inode(root);
23304 + ii_read_lock_parent3(dir);
23305 + a->h_root = au_hi(dir, a->btgt);
23306 + ii_read_unlock(dir);
23307 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23310 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23311 + a->dst_h_parent, a->dst_hdir);
23312 + udba = au_opt_udba(a->src_dentry->d_sb);
23313 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23314 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23315 + err = au_busy_or_stale();
23316 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23317 + err = au_h_verify(a->src_h_dentry, udba,
23318 + d_inode(a->src_h_parent), a->src_h_parent,
23320 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23321 + err = au_h_verify(a->dst_h_dentry, udba,
23322 + d_inode(a->dst_h_parent), a->dst_h_parent,
23325 + goto out; /* success */
23327 + err = au_busy_or_stale();
23328 + au_ren_unlock(a);
23334 +/* ---------------------------------------------------------------------- */
23336 +static void au_ren_refresh_dir(struct au_ren_args *a)
23338 + struct inode *dir;
23340 + dir = a->dst_dir;
23341 + inode_inc_iversion(dir);
23342 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23343 + /* is this updating defined in POSIX? */
23344 + au_cpup_attr_timesizes(a->src_inode);
23345 + au_cpup_attr_nlink(dir, /*force*/1);
23347 + au_dir_ts(dir, a->btgt);
23349 + if (a->exchange) {
23350 + dir = a->src_dir;
23351 + inode_inc_iversion(dir);
23352 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23353 + /* is this updating defined in POSIX? */
23354 + au_cpup_attr_timesizes(a->dst_inode);
23355 + au_cpup_attr_nlink(dir, /*force*/1);
23357 + au_dir_ts(dir, a->btgt);
23360 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23363 + dir = a->src_dir;
23364 + inode_inc_iversion(dir);
23365 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23366 + au_cpup_attr_nlink(dir, /*force*/1);
23367 + au_dir_ts(dir, a->btgt);
23370 +static void au_ren_refresh(struct au_ren_args *a)
23372 + aufs_bindex_t bbot, bindex;
23373 + struct dentry *d, *h_d;
23374 + struct inode *i, *h_i;
23375 + struct super_block *sb;
23377 + d = a->dst_dentry;
23380 + /* already dget-ed by au_ren_or_cpup() */
23381 + au_set_h_dptr(d, a->btgt, a->h_dst);
23383 + i = a->dst_inode;
23385 + if (!a->exchange) {
23386 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23387 + vfsub_drop_nlink(i);
23389 + vfsub_dead_dir(i);
23390 + au_cpup_attr_timesizes(i);
23392 + au_update_dbrange(d, /*do_put_zero*/1);
23394 + au_cpup_attr_nlink(i, /*force*/1);
23397 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23398 + au_set_h_dptr(d, bindex, NULL);
23399 + bbot = au_dbbot(d);
23400 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23401 + au_set_h_dptr(d, bindex, NULL);
23402 + au_update_dbrange(d, /*do_put_zero*/0);
23406 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23407 + d_drop(a->src_dentry);
23408 + if (au_ftest_ren(a->auren_flags, DIRREN))
23409 + au_set_dbwh(a->src_dentry, -1);
23413 + d = a->src_dentry;
23414 + au_set_dbwh(d, -1);
23415 + bbot = au_dbbot(d);
23416 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23417 + h_d = au_h_dptr(d, bindex);
23419 + au_set_h_dptr(d, bindex, NULL);
23421 + au_set_dbbot(d, a->btgt);
23424 + i = a->src_inode;
23425 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23426 + return; /* success */
23428 + bbot = au_ibbot(i);
23429 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23430 + h_i = au_h_iptr(i, bindex);
23432 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23433 + /* ignore this error */
23434 + au_set_h_iptr(i, bindex, NULL, 0);
23437 + au_set_ibbot(i, a->btgt);
23440 +/* ---------------------------------------------------------------------- */
23442 +/* mainly for link(2) and rename(2) */
23443 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23445 + aufs_bindex_t bdiropq, bwh;
23446 + struct dentry *parent;
23447 + struct au_branch *br;
23449 + parent = dentry->d_parent;
23450 + IMustLock(d_inode(parent)); /* dir is locked */
23452 + bdiropq = au_dbdiropq(parent);
23453 + bwh = au_dbwh(dentry);
23454 + br = au_sbr(dentry->d_sb, btgt);
23455 + if (au_br_rdonly(br)
23456 + || (0 <= bdiropq && bdiropq < btgt)
23457 + || (0 <= bwh && bwh < btgt))
23460 + AuDbg("btgt %d\n", btgt);
23464 +/* sets src_btop, dst_btop and btgt */
23465 +static int au_ren_wbr(struct au_ren_args *a)
23468 + struct au_wr_dir_args wr_dir_args = {
23469 + /* .force_btgt = -1, */
23470 + .flags = AuWrDir_ADD_ENTRY
23473 + a->src_btop = au_dbtop(a->src_dentry);
23474 + a->dst_btop = au_dbtop(a->dst_dentry);
23475 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23476 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23477 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23478 + wr_dir_args.force_btgt = a->src_btop;
23479 + if (a->dst_inode && a->dst_btop < a->src_btop)
23480 + wr_dir_args.force_btgt = a->dst_btop;
23481 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23482 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23485 + au_update_dbtop(a->dst_dentry);
23490 +static void au_ren_dt(struct au_ren_args *a)
23492 + a->h_path.dentry = a->src_h_parent;
23493 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23494 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23495 + a->h_path.dentry = a->dst_h_parent;
23496 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23499 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23500 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23504 + a->h_path.dentry = a->src_h_dentry;
23505 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23506 + if (d_is_positive(a->dst_h_dentry)) {
23507 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23508 + a->h_path.dentry = a->dst_h_dentry;
23509 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23513 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23515 + struct dentry *h_d;
23516 + struct inode *h_inode;
23518 + au_dtime_revert(a->src_dt + AuPARENT);
23519 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23520 + au_dtime_revert(a->dst_dt + AuPARENT);
23522 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23523 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23524 + h_inode = d_inode(h_d);
23525 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23526 + au_dtime_revert(a->src_dt + AuCHILD);
23527 + inode_unlock(h_inode);
23529 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23530 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23531 + h_inode = d_inode(h_d);
23532 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23533 + au_dtime_revert(a->dst_dt + AuCHILD);
23534 + inode_unlock(h_inode);
23539 +/* ---------------------------------------------------------------------- */
23541 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23542 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23543 + unsigned int _flags)
23545 + int err, lock_flags;
23547 + /* reduce stack space */
23548 + struct au_ren_args *a;
23549 + struct au_pin pin;
23551 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23552 + IMustLock(_src_dir);
23553 + IMustLock(_dst_dir);
23556 + if (unlikely(_flags & RENAME_WHITEOUT))
23560 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23561 + a = kzalloc(sizeof(*a), GFP_NOFS);
23562 + if (unlikely(!a))
23565 + a->flags = _flags;
23566 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23567 + && RENAME_EXCHANGE > U8_MAX);
23568 + a->exchange = _flags & RENAME_EXCHANGE;
23569 + a->src_dir = _src_dir;
23570 + a->src_dentry = _src_dentry;
23571 + a->src_inode = NULL;
23572 + if (d_really_is_positive(a->src_dentry))
23573 + a->src_inode = d_inode(a->src_dentry);
23574 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23575 + a->dst_dir = _dst_dir;
23576 + a->dst_dentry = _dst_dentry;
23577 + a->dst_inode = NULL;
23578 + if (d_really_is_positive(a->dst_dentry))
23579 + a->dst_inode = d_inode(a->dst_dentry);
23580 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23581 + if (a->dst_inode) {
23583 + * if EXCHANGE && src is non-dir && dst is dir,
23584 + * dst is not locked.
23586 + /* IMustLock(a->dst_inode); */
23587 + au_igrab(a->dst_inode);
23591 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23592 + if (d_is_dir(a->src_dentry)) {
23593 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23594 + if (unlikely(!a->exchange
23595 + && d_really_is_positive(a->dst_dentry)
23596 + && !d_is_dir(a->dst_dentry)))
23598 + lock_flags |= AuLock_DIRS;
23600 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23601 + au_fset_ren(a->auren_flags, ISDIR_DST);
23602 + if (unlikely(!a->exchange
23603 + && d_really_is_positive(a->src_dentry)
23604 + && !d_is_dir(a->src_dentry)))
23606 + lock_flags |= AuLock_DIRS;
23608 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23610 + if (unlikely(err))
23613 + err = au_d_hashed_positive(a->src_dentry);
23614 + if (unlikely(err))
23617 + if (a->dst_inode) {
23619 + * If it is a dir, VFS unhash it before this
23620 + * function. It means we cannot rely upon d_unhashed().
23622 + if (unlikely(!a->dst_inode->i_nlink))
23624 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23625 + err = au_d_hashed_positive(a->dst_dentry);
23626 + if (unlikely(err && !a->exchange))
23628 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23630 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23634 + * is it possible?
23635 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23636 + * there may exist a problem somewhere else.
23639 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23642 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23643 + di_write_lock_parent(a->dst_parent);
23645 + /* which branch we process */
23646 + err = au_ren_wbr(a);
23647 + if (unlikely(err < 0))
23649 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23650 + a->h_path.mnt = au_br_mnt(a->br);
23652 + /* are they available to be renamed */
23653 + err = au_ren_may_dir(a);
23654 + if (unlikely(err))
23655 + goto out_children;
23657 + /* prepare the writable parent dir on the same branch */
23658 + if (a->dst_btop == a->btgt) {
23659 + au_fset_ren(a->auren_flags, WHDST);
23661 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23662 + if (unlikely(err))
23663 + goto out_children;
23667 + if (!a->exchange) {
23668 + if (a->src_dir != a->dst_dir) {
23670 + * this temporary unlock is safe,
23671 + * because both dir->i_mutex are locked.
23673 + di_write_unlock(a->dst_parent);
23674 + di_write_lock_parent(a->src_parent);
23675 + err = au_wr_dir_need_wh(a->src_dentry,
23676 + au_ftest_ren(a->auren_flags,
23679 + di_write_unlock(a->src_parent);
23680 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23682 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23684 + err = au_wr_dir_need_wh(a->src_dentry,
23685 + au_ftest_ren(a->auren_flags,
23689 + if (unlikely(err < 0))
23690 + goto out_children;
23692 + au_fset_ren(a->auren_flags, WHSRC);
23695 + if (a->src_btop != a->btgt) {
23696 + err = au_pin(&pin, a->src_dentry, a->btgt,
23697 + au_opt_udba(a->src_dentry->d_sb),
23698 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23700 + struct au_cp_generic cpg = {
23701 + .dentry = a->src_dentry,
23703 + .bsrc = a->src_btop,
23706 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23708 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23709 + err = au_sio_cpup_simple(&cpg);
23712 + if (unlikely(err))
23713 + goto out_children;
23714 + a->src_btop = a->btgt;
23715 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23716 + if (!a->exchange)
23717 + au_fset_ren(a->auren_flags, WHSRC);
23721 + if (a->exchange && a->dst_inode
23722 + && a->dst_btop != a->btgt) {
23723 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23724 + au_opt_udba(a->dst_dentry->d_sb),
23725 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23727 + struct au_cp_generic cpg = {
23728 + .dentry = a->dst_dentry,
23730 + .bsrc = a->dst_btop,
23733 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23735 + err = au_sio_cpup_simple(&cpg);
23738 + if (unlikely(err))
23739 + goto out_children;
23740 + a->dst_btop = a->btgt;
23741 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23744 + /* lock them all */
23745 + err = au_ren_lock(a);
23746 + if (unlikely(err))
23747 + /* leave the copied-up one */
23748 + goto out_children;
23750 + if (!a->exchange) {
23751 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23752 + err = au_may_ren(a);
23753 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23754 + err = -ENAMETOOLONG;
23755 + if (unlikely(err))
23759 + /* store timestamps to be revertible */
23762 + /* store dirren info */
23763 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23764 + err = au_dr_rename(a->src_dentry, a->btgt,
23765 + &a->dst_dentry->d_name, &rev);
23767 + if (unlikely(err))
23772 + err = do_rename(a);
23773 + if (unlikely(err))
23776 + if (au_ftest_ren(a->auren_flags, DIRREN))
23777 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23779 + /* update dir attributes */
23780 + au_ren_refresh_dir(a);
23782 + /* dput/iput all lower dentries */
23783 + au_ren_refresh(a);
23785 + goto out_hdir; /* success */
23788 + if (au_ftest_ren(a->auren_flags, DIRREN))
23789 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23791 + au_ren_rev_dt(err, a);
23793 + au_ren_unlock(a);
23795 + au_nhash_wh_free(&a->whlist);
23796 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23797 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23798 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23799 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23803 + if (d_unhashed(a->src_dentry))
23804 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23805 + if (d_unhashed(a->dst_dentry))
23806 + au_fset_ren(a->auren_flags, DROPPED_DST);
23807 + if (!a->exchange)
23808 + d_move(a->src_dentry, a->dst_dentry);
23810 + d_exchange(a->src_dentry, a->dst_dentry);
23811 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23812 + d_drop(a->dst_dentry);
23814 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23815 + d_drop(a->src_dentry);
23817 + au_update_dbtop(a->dst_dentry);
23818 + if (!a->dst_inode)
23819 + d_drop(a->dst_dentry);
23821 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23822 + di_write_unlock(a->dst_parent);
23824 + di_write_unlock2(a->src_parent, a->dst_parent);
23826 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23828 + iput(a->dst_inode);
23830 + au_whtmp_rmdir_free(a->thargs);
23836 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23837 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23838 +++ linux/fs/aufs/Kconfig 2019-07-11 15:42:14.458904362 +0200
23840 +# SPDX-License-Identifier: GPL-2.0
23842 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23844 + Aufs is a stackable unification filesystem such as Unionfs,
23845 + which unifies several directories and provides a merged single
23847 + In the early days, aufs was entirely re-designed and
23848 + re-implemented Unionfs Version 1.x series. Introducing many
23849 + original ideas, approaches and improvements, it becomes totally
23850 + different from Unionfs while keeping the basic features.
23854 + prompt "Maximum number of branches"
23855 + default AUFS_BRANCH_MAX_127
23857 + Specifies the maximum number of branches (or member directories)
23858 + in a single aufs. The larger value consumes more system
23859 + resources and has a minor impact to performance.
23860 +config AUFS_BRANCH_MAX_127
23863 + Specifies the maximum number of branches (or member directories)
23864 + in a single aufs. The larger value consumes more system
23865 + resources and has a minor impact to performance.
23866 +config AUFS_BRANCH_MAX_511
23869 + Specifies the maximum number of branches (or member directories)
23870 + in a single aufs. The larger value consumes more system
23871 + resources and has a minor impact to performance.
23872 +config AUFS_BRANCH_MAX_1023
23875 + Specifies the maximum number of branches (or member directories)
23876 + in a single aufs. The larger value consumes more system
23877 + resources and has a minor impact to performance.
23878 +config AUFS_BRANCH_MAX_32767
23881 + Specifies the maximum number of branches (or member directories)
23882 + in a single aufs. The larger value consumes more system
23883 + resources and has a minor impact to performance.
23886 +config AUFS_SBILIST
23888 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23891 + Automatic configuration for internal use.
23892 + When aufs supports Magic SysRq or /proc, enabled automatically.
23894 +config AUFS_HNOTIFY
23895 + bool "Detect direct branch access (bypassing aufs)"
23897 + If you want to modify files on branches directly, eg. bypassing aufs,
23898 + and want aufs to detect the changes of them fully, then enable this
23899 + option and use 'udba=notify' mount option.
23900 + Currently there is only one available configuration, "fsnotify".
23901 + It will have a negative impact to the performance.
23902 + See detail in aufs.5.
23905 + prompt "method" if AUFS_HNOTIFY
23906 + default AUFS_HFSNOTIFY
23907 +config AUFS_HFSNOTIFY
23912 +config AUFS_EXPORT
23913 + bool "NFS-exportable aufs"
23914 + depends on EXPORTFS
23916 + If you want to export your mounted aufs via NFS, then enable this
23917 + option. There are several requirements for this configuration.
23918 + See detail in aufs.5.
23920 +config AUFS_INO_T_64
23922 + depends on AUFS_EXPORT
23923 + depends on 64BIT && !(ALPHA || S390)
23926 + Automatic configuration for internal use.
23927 + /* typedef unsigned long/int __kernel_ino_t */
23928 + /* alpha and s390x are int */
23931 + bool "support for XATTR/EA (including Security Labels)"
23933 + If your branch fs supports XATTR/EA and you want to make them
23934 + available in aufs too, then enable this opsion and specify the
23935 + branch attributes for EA.
23936 + See detail in aufs.5.
23939 + bool "File-based Hierarchical Storage Management"
23941 + Hierarchical Storage Management (or HSM) is a well-known feature
23942 + in the storage world. Aufs provides this feature as file-based.
23943 + with multiple branches.
23944 + These multiple branches are prioritized, ie. the topmost one
23945 + should be the fastest drive and be used heavily.
23948 + bool "Readdir in userspace"
23950 + Aufs has two methods to provide a merged view for a directory,
23951 + by a user-space library and by kernel-space natively. The latter
23952 + is always enabled but sometimes large and slow.
23953 + If you enable this option, install the library in aufs2-util
23954 + package, and set some environment variables for your readdir(3),
23955 + then the work will be handled in user-space which generally
23956 + shows better performance in most cases.
23957 + See detail in aufs.5.
23959 +config AUFS_DIRREN
23960 + bool "Workaround for rename(2)-ing a directory"
23962 + By default, aufs returns EXDEV error in renameing a dir who has
23963 + his child on the lower branch, since it is a bad idea to issue
23964 + rename(2) internally for every lower branch. But user may not
23965 + accept this behaviour. So here is a workaround to allow such
23966 + rename(2) and store some extra infromation on the writable
23967 + branch. Obviously this costs high (and I don't like it).
23968 + To use this feature, you need to enable this configuration AND
23969 + to specify the mount option `dirren.'
23970 + See details in aufs.5 and the design documents.
23973 + bool "Show whiteouts"
23975 + If you want to make the whiteouts in aufs visible, then enable
23976 + this option and specify 'shwh' mount option. Although it may
23977 + sounds like philosophy or something, but in technically it
23978 + simply shows the name of whiteout with keeping its behaviour.
23980 +config AUFS_BR_RAMFS
23981 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
23983 + If you want to use ramfs as an aufs branch fs, then enable this
23984 + option. Generally tmpfs is recommended.
23985 + Aufs prohibited them to be a branch fs by default, because
23986 + initramfs becomes unusable after switch_root or something
23987 + generally. If you sets initramfs as an aufs branch and boot your
23988 + system by switch_root, you will meet a problem easily since the
23989 + files in initramfs may be inaccessible.
23990 + Unless you are going to use ramfs as an aufs branch fs without
23991 + switch_root or something, leave it N.
23993 +config AUFS_BR_FUSE
23994 + bool "Fuse fs as an aufs branch"
23995 + depends on FUSE_FS
23998 + If you want to use fuse-based userspace filesystem as an aufs
23999 + branch fs, then enable this option.
24000 + It implements the internal poll(2) operation which is
24001 + implemented by fuse only (curretnly).
24006 + Automatic configuration for internal use.
24008 +config AUFS_BR_HFSPLUS
24009 + bool "Hfsplus as an aufs branch"
24010 + depends on HFSPLUS_FS
24013 + If you want to use hfsplus fs as an aufs branch fs, then enable
24014 + this option. This option introduces a small overhead at
24015 + copying-up a file on hfsplus.
24017 +config AUFS_BDEV_LOOP
24019 + depends on BLK_DEV_LOOP
24022 + Automatic configuration for internal use.
24023 + Convert =[ym] into =y.
24026 + bool "Debug aufs"
24028 + Enable this to compile aufs internal debug code.
24029 + It will have a negative impact to the performance.
24031 +config AUFS_MAGIC_SYSRQ
24033 + depends on AUFS_DEBUG && MAGIC_SYSRQ
24036 + Automatic configuration for internal use.
24037 + When aufs supports Magic SysRq, enabled automatically.
24039 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
24040 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
24041 +++ linux/fs/aufs/lcnt.h 2020-01-27 10:57:18.175538316 +0100
24043 +/* SPDX-License-Identifier: GPL-2.0 */
24045 + * Copyright (C) 2018-2020 Junjiro R. Okajima
24047 + * This program, aufs is free software; you can redistribute it and/or modify
24048 + * it under the terms of the GNU General Public License as published by
24049 + * the Free Software Foundation; either version 2 of the License, or
24050 + * (at your option) any later version.
24052 + * This program is distributed in the hope that it will be useful,
24053 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24054 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24055 + * GNU General Public License for more details.
24057 + * You should have received a copy of the GNU General Public License
24058 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24062 + * simple long counter wrapper
24065 +#ifndef __AUFS_LCNT_H__
24066 +#define __AUFS_LCNT_H__
24070 +#include "debug.h"
24072 +#define AuLCntATOMIC 1
24073 +#define AuLCntPCPUCNT 2
24075 + * why does percpu_refcount require extra synchronize_rcu()s in
24076 + * au_br_do_free()
24078 +#define AuLCntPCPUREF 3
24080 +/* #define AuLCntChosen AuLCntATOMIC */
24081 +#define AuLCntChosen AuLCntPCPUCNT
24082 +/* #define AuLCntChosen AuLCntPCPUREF */
24084 +#if AuLCntChosen == AuLCntATOMIC
24085 +#include <linux/atomic.h>
24087 +typedef atomic_long_t au_lcnt_t;
24089 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24091 + atomic_long_set(cnt, 0);
24095 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24100 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
24101 + int do_sync __maybe_unused)
24106 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24108 + atomic_long_inc(cnt);
24111 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24113 + atomic_long_dec(cnt);
24116 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24118 + return atomic_long_read(cnt);
24122 +#if AuLCntChosen == AuLCntPCPUCNT
24123 +#include <linux/percpu_counter.h>
24125 +typedef struct percpu_counter au_lcnt_t;
24127 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24129 + return percpu_counter_init(cnt, 0, GFP_NOFS);
24132 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24137 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
24139 + percpu_counter_destroy(cnt);
24142 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24144 + percpu_counter_inc(cnt);
24147 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24149 + percpu_counter_dec(cnt);
24152 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24156 + n = percpu_counter_sum(cnt);
24158 + if (LONG_MAX != LLONG_MAX
24160 + AuWarn1("%s\n", "wrap-around");
24166 +#if AuLCntChosen == AuLCntPCPUREF
24167 +#include <linux/percpu-refcount.h>
24169 +typedef struct percpu_ref au_lcnt_t;
24171 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24174 + release = percpu_ref_exit;
24175 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24178 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24180 + synchronize_rcu();
24183 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24185 + percpu_ref_kill(cnt);
24187 + au_lcnt_wait_for_fin(cnt);
24190 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24192 + percpu_ref_get(cnt);
24195 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24197 + percpu_ref_put(cnt);
24201 + * avoid calling this func as possible.
24203 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24207 + percpu_ref_switch_to_atomic_sync(cnt);
24208 + l = atomic_long_read(&cnt->count);
24210 + percpu_ref_switch_to_percpu(cnt);
24212 + /* percpu_ref is initialized by 1 instead of 0 */
24217 +#ifdef CONFIG_AUFS_DEBUG
24218 +#define AuLCntZero(val) do { \
24221 + AuDbg("%s = %ld\n", #val, l); \
24224 +#define AuLCntZero(val) do {} while (0)
24227 +#endif /* __KERNEL__ */
24228 +#endif /* __AUFS_LCNT_H__ */
24229 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24230 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24231 +++ linux/fs/aufs/loop.c 2020-01-27 10:57:18.175538316 +0100
24233 +// SPDX-License-Identifier: GPL-2.0
24235 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24237 + * This program, aufs is free software; you can redistribute it and/or modify
24238 + * it under the terms of the GNU General Public License as published by
24239 + * the Free Software Foundation; either version 2 of the License, or
24240 + * (at your option) any later version.
24242 + * This program is distributed in the hope that it will be useful,
24243 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24244 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24245 + * GNU General Public License for more details.
24247 + * You should have received a copy of the GNU General Public License
24248 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24252 + * support for loopback block device as a branch
24257 +/* added into drivers/block/loop.c */
24258 +static struct file *(*backing_file_func)(struct super_block *sb);
24261 + * test if two lower dentries have overlapping branches.
24263 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24265 + struct super_block *h_sb;
24266 + struct file *backing_file;
24268 + if (unlikely(!backing_file_func)) {
24269 + /* don't load "loop" module here */
24270 + backing_file_func = symbol_get(loop_backing_file);
24271 + if (unlikely(!backing_file_func))
24272 + /* "loop" module is not loaded */
24276 + h_sb = h_adding->d_sb;
24277 + backing_file = backing_file_func(h_sb);
24278 + if (!backing_file)
24281 + h_adding = backing_file->f_path.dentry;
24283 + * h_adding can be local NFS.
24284 + * in this case aufs cannot detect the loop.
24286 + if (unlikely(h_adding->d_sb == sb))
24288 + return !!au_test_subdir(h_adding, sb->s_root);
24291 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24292 +int au_test_loopback_kthread(void)
24295 + struct task_struct *tsk = current;
24296 + char c, comm[sizeof(tsk->comm)];
24299 + if (tsk->flags & PF_KTHREAD) {
24300 + get_task_comm(comm, tsk);
24302 + ret = ('0' <= c && c <= '9'
24303 + && !strncmp(comm, "loop", 4));
24309 +/* ---------------------------------------------------------------------- */
24311 +#define au_warn_loopback_step 16
24312 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24313 +static unsigned long *au_warn_loopback_array;
24315 +void au_warn_loopback(struct super_block *h_sb)
24317 + int i, new_nelem;
24318 + unsigned long *a, magic;
24319 + static DEFINE_SPINLOCK(spin);
24321 + magic = h_sb->s_magic;
24322 + spin_lock(&spin);
24323 + a = au_warn_loopback_array;
24324 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24325 + if (a[i] == magic) {
24326 + spin_unlock(&spin);
24330 + /* h_sb is new to us, print it */
24331 + if (i < au_warn_loopback_nelem) {
24336 + /* expand the array */
24337 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24338 + a = au_kzrealloc(au_warn_loopback_array,
24339 + au_warn_loopback_nelem * sizeof(unsigned long),
24340 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24341 + /*may_shrink*/0);
24343 + au_warn_loopback_nelem = new_nelem;
24344 + au_warn_loopback_array = a;
24349 + spin_unlock(&spin);
24350 + AuWarn1("realloc failed, ignored\n");
24354 + spin_unlock(&spin);
24355 + pr_warn("you may want to try another patch for loopback file "
24356 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24359 +int au_loopback_init(void)
24362 + struct super_block *sb __maybe_unused;
24364 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
24367 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24368 + sizeof(unsigned long), GFP_NOFS);
24369 + if (unlikely(!au_warn_loopback_array))
24375 +void au_loopback_fin(void)
24377 + if (backing_file_func)
24378 + symbol_put(loop_backing_file);
24379 + au_kfree_try_rcu(au_warn_loopback_array);
24381 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24382 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24383 +++ linux/fs/aufs/loop.h 2020-01-27 10:57:18.175538316 +0100
24385 +/* SPDX-License-Identifier: GPL-2.0 */
24387 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24389 + * This program, aufs is free software; you can redistribute it and/or modify
24390 + * it under the terms of the GNU General Public License as published by
24391 + * the Free Software Foundation; either version 2 of the License, or
24392 + * (at your option) any later version.
24394 + * This program is distributed in the hope that it will be useful,
24395 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24396 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24397 + * GNU General Public License for more details.
24399 + * You should have received a copy of the GNU General Public License
24400 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24404 + * support for loopback mount as a branch
24407 +#ifndef __AUFS_LOOP_H__
24408 +#define __AUFS_LOOP_H__
24413 +struct super_block;
24415 +#ifdef CONFIG_AUFS_BDEV_LOOP
24416 +/* drivers/block/loop.c */
24417 +struct file *loop_backing_file(struct super_block *sb);
24420 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24421 +int au_test_loopback_kthread(void);
24422 +void au_warn_loopback(struct super_block *h_sb);
24424 +int au_loopback_init(void);
24425 +void au_loopback_fin(void);
24427 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
24429 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24430 + struct dentry *h_adding)
24431 +AuStubInt0(au_test_loopback_kthread, void)
24432 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24434 +AuStubInt0(au_loopback_init, void)
24435 +AuStubVoid(au_loopback_fin, void)
24436 +#endif /* BLK_DEV_LOOP */
24438 +#endif /* __KERNEL__ */
24439 +#endif /* __AUFS_LOOP_H__ */
24440 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24441 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24442 +++ linux/fs/aufs/magic.mk 2019-07-11 15:42:14.468904634 +0200
24444 +# SPDX-License-Identifier: GPL-2.0
24446 +# defined in ${srctree}/fs/fuse/inode.c
24448 +ifdef CONFIG_FUSE_FS
24449 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24452 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24454 +ifdef CONFIG_XFS_FS
24455 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24458 +# defined in ${srctree}/fs/configfs/mount.c
24460 +ifdef CONFIG_CONFIGFS_FS
24461 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24464 +# defined in ${srctree}/fs/ubifs/ubifs.h
24466 +ifdef CONFIG_UBIFS_FS
24467 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24470 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24472 +ifdef CONFIG_HFSPLUS_FS
24473 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24475 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24476 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24477 +++ linux/fs/aufs/Makefile 2019-07-11 15:42:14.462237786 +0200
24479 +# SPDX-License-Identifier: GPL-2.0
24481 +include ${src}/magic.mk
24482 +ifeq (${CONFIG_AUFS_FS},m)
24483 +include ${src}/conf.mk
24485 +-include ${src}/priv_def.mk
24487 +# cf. include/linux/kernel.h
24489 +ccflags-y += -DDEBUG
24490 +# sparse requires the full pathname
24492 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24494 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24497 +obj-$(CONFIG_AUFS_FS) += aufs.o
24498 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24499 + wkq.o vfsub.o dcsub.o \
24500 + cpup.o whout.o wbr_policy.o \
24501 + dinfo.o dentry.o \
24503 + finfo.o file.o f_op.o \
24505 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24509 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24510 +aufs-$(CONFIG_SYSFS) += sysfs.o
24511 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24512 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24513 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24514 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24515 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24516 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24517 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24518 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24519 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24520 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24521 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24522 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24523 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24524 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24525 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24526 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24527 +++ linux/fs/aufs/module.c 2020-01-27 10:57:18.175538316 +0100
24529 +// SPDX-License-Identifier: GPL-2.0
24531 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24533 + * This program, aufs is free software; you can redistribute it and/or modify
24534 + * it under the terms of the GNU General Public License as published by
24535 + * the Free Software Foundation; either version 2 of the License, or
24536 + * (at your option) any later version.
24538 + * This program is distributed in the hope that it will be useful,
24539 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24540 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24541 + * GNU General Public License for more details.
24543 + * You should have received a copy of the GNU General Public License
24544 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24548 + * module global variables and operations
24551 +#include <linux/module.h>
24552 +#include <linux/seq_file.h>
24555 +/* shrinkable realloc */
24556 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24564 +#if 0 /* unused */
24571 + AuDebugOn(!new_sz);
24574 + diff = au_kmidx_sub(sz, new_sz);
24580 + /* expand or SLOB */
24581 + p = krealloc(p, new_sz, gfp);
24582 + else if (new_sz < sz && may_shrink) {
24586 + q = kmalloc(new_sz, gfp);
24589 + memcpy(q, p, new_sz);
24590 + au_kfree_try_rcu(p);
24601 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24604 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24605 + if (p && new_sz > nused)
24606 + memset(p + nused, 0, new_sz - nused);
24610 +/* ---------------------------------------------------------------------- */
24614 +struct kmem_cache *au_cache[AuCache_Last];
24616 +static void au_cache_fin(void)
24621 + * Make sure all delayed rcu free inodes are flushed before we
24626 + /* excluding AuCache_HNOTIFY */
24627 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24628 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24629 + kmem_cache_destroy(au_cache[i]);
24630 + au_cache[i] = NULL;
24634 +static int __init au_cache_init(void)
24636 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24637 + if (au_cache[AuCache_DINFO])
24638 + /* SLAB_DESTROY_BY_RCU */
24639 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24640 + au_icntnr_init_once);
24641 + if (au_cache[AuCache_ICNTNR])
24642 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24643 + au_fi_init_once);
24644 + if (au_cache[AuCache_FINFO])
24645 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24646 + if (au_cache[AuCache_VDIR])
24647 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24648 + if (au_cache[AuCache_DEHSTR])
24655 +/* ---------------------------------------------------------------------- */
24657 +int au_dir_roflags;
24659 +#ifdef CONFIG_AUFS_SBILIST
24661 + * iterate_supers_type() doesn't protect us from
24662 + * remounting (branch management)
24664 +struct hlist_bl_head au_sbilist;
24668 + * functions for module interface.
24670 +MODULE_LICENSE("GPL");
24671 +/* MODULE_LICENSE("GPL v2"); */
24672 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24673 +MODULE_DESCRIPTION(AUFS_NAME
24674 + " -- Advanced multi layered unification filesystem");
24675 +MODULE_VERSION(AUFS_VERSION);
24676 +MODULE_ALIAS_FS(AUFS_NAME);
24678 +/* this module parameter has no meaning when SYSFS is disabled */
24679 +int sysaufs_brs = 1;
24680 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24681 +module_param_named(brs, sysaufs_brs, int, 0444);
24683 +/* this module parameter has no meaning when USER_NS is disabled */
24685 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24686 +module_param_named(allow_userns, au_userns, bool, 0444);
24688 +/* ---------------------------------------------------------------------- */
24690 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24692 +int au_seq_path(struct seq_file *seq, struct path *path)
24696 + err = seq_path(seq, path, au_esc_chars);
24705 +/* ---------------------------------------------------------------------- */
24707 +static int __init aufs_init(void)
24712 + p = au_esc_chars;
24713 + for (i = 1; i <= ' '; i++)
24719 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24721 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24722 + for (i = 0; i < AuIop_Last; i++)
24723 + aufs_iop_nogetattr[i].getattr = NULL;
24725 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24727 + au_sbilist_init();
24728 + sysaufs_brs_init();
24731 + err = sysaufs_init();
24732 + if (unlikely(err))
24734 + err = dbgaufs_init();
24735 + if (unlikely(err))
24736 + goto out_sysaufs;
24737 + err = au_procfs_init();
24738 + if (unlikely(err))
24739 + goto out_dbgaufs;
24740 + err = au_wkq_init();
24741 + if (unlikely(err))
24743 + err = au_loopback_init();
24744 + if (unlikely(err))
24746 + err = au_hnotify_init();
24747 + if (unlikely(err))
24748 + goto out_loopback;
24749 + err = au_sysrq_init();
24750 + if (unlikely(err))
24752 + err = au_cache_init();
24753 + if (unlikely(err))
24756 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24757 + err = register_filesystem(&aufs_fs_type);
24758 + if (unlikely(err))
24761 + /* since we define pr_fmt, call printk directly */
24762 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24763 + goto out; /* success */
24770 + au_hnotify_fin();
24772 + au_loopback_fin();
24786 +static void __exit aufs_exit(void)
24788 + unregister_filesystem(&aufs_fs_type);
24791 + au_hnotify_fin();
24792 + au_loopback_fin();
24800 +module_init(aufs_init);
24801 +module_exit(aufs_exit);
24802 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24803 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24804 +++ linux/fs/aufs/module.h 2020-01-27 10:57:18.175538316 +0100
24806 +/* SPDX-License-Identifier: GPL-2.0 */
24808 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24810 + * This program, aufs is free software; you can redistribute it and/or modify
24811 + * it under the terms of the GNU General Public License as published by
24812 + * the Free Software Foundation; either version 2 of the License, or
24813 + * (at your option) any later version.
24815 + * This program is distributed in the hope that it will be useful,
24816 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24817 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24818 + * GNU General Public License for more details.
24820 + * You should have received a copy of the GNU General Public License
24821 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24825 + * module initialization and module-global
24828 +#ifndef __AUFS_MODULE_H__
24829 +#define __AUFS_MODULE_H__
24833 +#include <linux/slab.h>
24834 +#include "debug.h"
24835 +#include "dentry.h"
24838 +#include "inode.h"
24843 +/* module parameters */
24844 +extern int sysaufs_brs;
24845 +extern bool au_userns;
24847 +/* ---------------------------------------------------------------------- */
24849 +extern int au_dir_roflags;
24851 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24852 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24856 + * Comparing the size of the object with sizeof(struct rcu_head)
24857 + * case 1: object is always larger
24858 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24859 + * case 2: object is always smaller
24860 + * --> au_kfree_small()
24861 + * case 3: object can be any size
24862 + * --> au_kfree_try_rcu()
24865 +static inline void au_kfree_do_rcu(const void *p)
24868 + struct rcu_head rcu;
24869 + } *a = (void *)p;
24871 + kfree_rcu(a, rcu);
24874 +#define au_kfree_rcu(_p) do { \
24875 + typeof(_p) p = (_p); \
24876 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24878 + au_kfree_do_rcu(p); \
24881 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
24882 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
24884 +static inline void au_kfree_try_rcu(const void *p)
24888 + if (au_kfree_sz_test(p))
24889 + au_kfree_do_rcu(p);
24894 +static inline void au_kfree_small(const void *p)
24898 + AuDebugOn(au_kfree_sz_test(p));
24902 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24904 +#ifndef CONFIG_SLOB
24905 + return kmalloc_index(sz) - kmalloc_index(new_sz);
24907 + return -1; /* SLOB is untested */
24911 +int au_seq_path(struct seq_file *seq, struct path *path);
24913 +#ifdef CONFIG_PROC_FS
24915 +int __init au_procfs_init(void);
24916 +void au_procfs_fin(void);
24918 +AuStubInt0(au_procfs_init, void);
24919 +AuStubVoid(au_procfs_fin, void);
24922 +/* ---------------------------------------------------------------------- */
24931 + AuCache_HNOTIFY, /* must be last */
24935 +extern struct kmem_cache *au_cache[AuCache_Last];
24937 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24938 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24939 +#define AuCacheCtor(type, ctor) \
24940 + kmem_cache_create(#type, sizeof(struct type), \
24941 + __alignof__(struct type), AuCacheFlags, ctor)
24943 +#define AuCacheFuncs(name, index) \
24944 + static inline struct au_##name *au_cache_alloc_##name(void) \
24945 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24946 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
24947 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
24949 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
24950 + { void *p = rcu; \
24951 + p -= offsetof(struct au_##name, rcu); \
24952 + kmem_cache_free(au_cache[AuCache_##index], p); } \
24953 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
24954 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
24955 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
24957 + static inline void au_cache_free_##name(struct au_##name *p) \
24958 + { /* au_cache_free_##name##_norcu(p); */ \
24959 + au_cache_free_##name##_rcu(p); }
24961 +AuCacheFuncs(dinfo, DINFO);
24962 +AuCacheFuncs(icntnr, ICNTNR);
24963 +AuCacheFuncs(finfo, FINFO);
24964 +AuCacheFuncs(vdir, VDIR);
24965 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24966 +#ifdef CONFIG_AUFS_HNOTIFY
24967 +AuCacheFuncs(hnotify, HNOTIFY);
24970 +#endif /* __KERNEL__ */
24971 +#endif /* __AUFS_MODULE_H__ */
24972 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24973 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24974 +++ linux/fs/aufs/mvdown.c 2020-01-27 10:57:18.175538316 +0100
24976 +// SPDX-License-Identifier: GPL-2.0
24978 + * Copyright (C) 2011-2020 Junjiro R. Okajima
24980 + * This program, aufs is free software; you can redistribute it and/or modify
24981 + * it under the terms of the GNU General Public License as published by
24982 + * the Free Software Foundation; either version 2 of the License, or
24983 + * (at your option) any later version.
24985 + * This program is distributed in the hope that it will be useful,
24986 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24987 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24988 + * GNU General Public License for more details.
24990 + * You should have received a copy of the GNU General Public License
24991 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24995 + * move-down, opposite of copy-up
25000 +struct au_mvd_args {
25002 + struct super_block *h_sb;
25003 + struct dentry *h_parent;
25004 + struct au_hinode *hdir;
25005 + struct inode *h_dir, *h_inode;
25006 + struct au_pin pin;
25007 + } info[AUFS_MVDOWN_NARRAY];
25009 + struct aufs_mvdown mvdown;
25010 + struct dentry *dentry, *parent;
25011 + struct inode *inode, *dir;
25012 + struct super_block *sb;
25013 + aufs_bindex_t bopq, bwh, bfound;
25014 + unsigned char rename_lock;
25017 +#define mvd_errno mvdown.au_errno
25018 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
25019 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
25020 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
25021 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
25023 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
25024 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
25025 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
25026 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
25027 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
25028 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
25030 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
25031 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
25032 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
25033 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
25034 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
25035 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
25037 +#define AU_MVD_PR(flag, ...) do { \
25039 + pr_err(__VA_ARGS__); \
25042 +static int find_lower_writable(struct au_mvd_args *a)
25044 + struct super_block *sb;
25045 + aufs_bindex_t bindex, bbot;
25046 + struct au_branch *br;
25049 + bindex = a->mvd_bsrc;
25050 + bbot = au_sbbot(sb);
25051 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
25052 + for (bindex++; bindex <= bbot; bindex++) {
25053 + br = au_sbr(sb, bindex);
25054 + if (au_br_fhsm(br->br_perm)
25055 + && !sb_rdonly(au_br_sb(br)))
25058 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
25059 + for (bindex++; bindex <= bbot; bindex++) {
25060 + br = au_sbr(sb, bindex);
25061 + if (!au_br_rdonly(br))
25065 + for (bindex++; bindex <= bbot; bindex++) {
25066 + br = au_sbr(sb, bindex);
25067 + if (!sb_rdonly(au_br_sb(br))) {
25068 + if (au_br_rdonly(br))
25070 + |= AUFS_MVDOWN_ROLOWER_R;
25078 +/* make the parent dir on bdst */
25079 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
25084 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
25085 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
25086 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
25087 + a->mvd_h_dst_parent = NULL;
25088 + if (au_dbbot(a->parent) >= a->mvd_bdst)
25089 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25090 + if (!a->mvd_h_dst_parent) {
25091 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
25092 + if (unlikely(err)) {
25093 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
25096 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25104 +/* lock them all */
25105 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
25108 + struct dentry *h_trap;
25110 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
25111 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
25112 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
25113 + au_opt_udba(a->sb),
25114 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25116 + if (unlikely(err)) {
25117 + AU_MVD_PR(dmsg, "pin_dst failed\n");
25121 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
25122 + a->rename_lock = 0;
25123 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25124 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
25125 + au_opt_udba(a->sb),
25126 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25127 + err = au_do_pin(&a->mvd_pin_src);
25129 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25130 + if (unlikely(err)) {
25131 + AU_MVD_PR(dmsg, "pin_src failed\n");
25134 + goto out; /* success */
25137 + a->rename_lock = 1;
25138 + au_pin_hdir_unlock(&a->mvd_pin_dst);
25139 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25140 + au_opt_udba(a->sb),
25141 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25143 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25144 + if (unlikely(err)) {
25145 + AU_MVD_PR(dmsg, "pin_src failed\n");
25146 + au_pin_hdir_lock(&a->mvd_pin_dst);
25149 + au_pin_hdir_unlock(&a->mvd_pin_src);
25150 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25151 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25153 + err = (h_trap != a->mvd_h_src_parent);
25155 + err = (h_trap != a->mvd_h_dst_parent);
25157 + BUG_ON(err); /* it should never happen */
25158 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25161 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25162 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25163 + au_pin_hdir_lock(&a->mvd_pin_src);
25164 + au_unpin(&a->mvd_pin_src);
25165 + au_pin_hdir_lock(&a->mvd_pin_dst);
25168 + goto out; /* success */
25171 + au_unpin(&a->mvd_pin_dst);
25177 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25179 + if (!a->rename_lock)
25180 + au_unpin(&a->mvd_pin_src);
25182 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25183 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25184 + au_pin_hdir_lock(&a->mvd_pin_src);
25185 + au_unpin(&a->mvd_pin_src);
25186 + au_pin_hdir_lock(&a->mvd_pin_dst);
25188 + au_unpin(&a->mvd_pin_dst);
25191 +/* copy-down the file */
25192 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25195 + struct au_cp_generic cpg = {
25196 + .dentry = a->dentry,
25197 + .bdst = a->mvd_bdst,
25198 + .bsrc = a->mvd_bsrc,
25200 + .pin = &a->mvd_pin_dst,
25201 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25204 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25205 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25206 + au_fset_cpup(cpg.flags, OVERWRITE);
25207 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25208 + au_fset_cpup(cpg.flags, RWDST);
25209 + err = au_sio_cpdown_simple(&cpg);
25210 + if (unlikely(err))
25211 + AU_MVD_PR(dmsg, "cpdown failed\n");
25218 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25221 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25224 + struct path h_path;
25225 + struct au_branch *br;
25226 + struct inode *delegated;
25228 + br = au_sbr(a->sb, a->mvd_bdst);
25229 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25230 + err = PTR_ERR(h_path.dentry);
25231 + if (IS_ERR(h_path.dentry)) {
25232 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25237 + if (d_is_positive(h_path.dentry)) {
25238 + h_path.mnt = au_br_mnt(br);
25239 + delegated = NULL;
25240 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25241 + &delegated, /*force*/0);
25242 + if (unlikely(err == -EWOULDBLOCK)) {
25243 + pr_warn("cannot retry for NFSv4 delegation"
25244 + " for an internal unlink\n");
25247 + if (unlikely(err))
25248 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25250 + dput(h_path.dentry);
25258 + * unlink the topmost h_dentry
25260 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25263 + struct path h_path;
25264 + struct inode *delegated;
25266 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25267 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25268 + delegated = NULL;
25269 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25270 + if (unlikely(err == -EWOULDBLOCK)) {
25271 + pr_warn("cannot retry for NFSv4 delegation"
25272 + " for an internal unlink\n");
25275 + if (unlikely(err))
25276 + AU_MVD_PR(dmsg, "unlink failed\n");
25282 +/* Since mvdown succeeded, we ignore an error of this function */
25283 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25286 + struct au_branch *br;
25288 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25289 + br = au_sbr(a->sb, a->mvd_bsrc);
25290 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25292 + br = au_sbr(a->sb, a->mvd_bdst);
25293 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25294 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25297 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25299 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25303 + * copy-down the file and unlink the bsrc file.
25304 + * - unlink the bdst whout if exist
25305 + * - copy-down the file (with whtmp name and rename)
25306 + * - unlink the bsrc file
25308 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25312 + err = au_do_mkdir(dmsg, a);
25314 + err = au_do_lock(dmsg, a);
25315 + if (unlikely(err))
25319 + * do not revert the activities we made on bdst since they should be
25320 + * harmless in aufs.
25323 + err = au_do_cpdown(dmsg, a);
25325 + err = au_do_unlink_wh(dmsg, a);
25326 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25327 + err = au_do_unlink(dmsg, a);
25328 + if (unlikely(err))
25331 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25332 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25333 + if (find_lower_writable(a) < 0)
25334 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25336 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25337 + au_do_stfs(dmsg, a);
25339 + /* maintain internal array */
25340 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25341 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25342 + au_set_dbtop(a->dentry, a->mvd_bdst);
25343 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25344 + au_set_ibtop(a->inode, a->mvd_bdst);
25346 + /* hide the lower */
25347 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25348 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25349 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25350 + au_set_ibbot(a->inode, a->mvd_bsrc);
25352 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25353 + au_set_dbbot(a->dentry, a->mvd_bdst);
25354 + if (au_ibbot(a->inode) < a->mvd_bdst)
25355 + au_set_ibbot(a->inode, a->mvd_bdst);
25358 + au_do_unlock(dmsg, a);
25364 +/* ---------------------------------------------------------------------- */
25366 +/* make sure the file is idle */
25367 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25369 + int err, plinked;
25372 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25373 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25374 + && au_dcount(a->dentry) == 1
25375 + && atomic_read(&a->inode->i_count) == 1
25376 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25377 + && (!plinked || !au_plink_test(a->inode))
25378 + && a->inode->i_nlink == 1)
25383 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25384 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25385 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25386 + a->mvd_h_src_inode->i_nlink,
25387 + plinked, plinked ? au_plink_test(a->inode) : 0);
25394 +/* make sure the parent dir is fine */
25395 +static int au_mvd_args_parent(const unsigned char dmsg,
25396 + struct au_mvd_args *a)
25399 + aufs_bindex_t bindex;
25402 + if (unlikely(au_alive_dir(a->parent))) {
25404 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25408 + a->bopq = au_dbdiropq(a->parent);
25409 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25410 + AuDbg("b%d\n", bindex);
25411 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25412 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25414 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25415 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25416 + a->bopq, a->mvd_bdst);
25424 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25425 + struct au_mvd_args *a)
25428 + struct au_dinfo *dinfo, *tmp;
25430 + /* lookup the next lower positive entry */
25432 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25433 + if (unlikely(!tmp))
25438 + dinfo = au_di(a->dentry);
25439 + au_di_cp(tmp, dinfo);
25440 + au_di_swap(tmp, dinfo);
25442 + /* returns the number of positive dentries */
25443 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25444 + /* AuLkup_IGNORE_PERM */ 0);
25446 + a->bwh = au_dbwh(a->dentry);
25447 + else if (err > 0)
25448 + a->bfound = au_dbtop(a->dentry);
25450 + au_di_swap(tmp, dinfo);
25451 + au_rw_write_unlock(&tmp->di_rwsem);
25453 + if (unlikely(err < 0))
25454 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25457 + * here, we have these cases.
25459 + * no positive dentry under bsrc. there are more sub-cases.
25461 + * there no whiteout, we can safely move-down.
25464 + * bsrc < bwh && bwh < bdst
25465 + * there is a whiteout on RO branch. cannot proceed.
25467 + * there is a whiteout on the RW target branch. it should
25470 + * there is a whiteout somewhere unrelated branch.
25471 + * -1 < bfound && bfound <= bsrc
25474 + * found, but it is on RO branch between bsrc and bdst. cannot
25477 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25480 + * found, after we create the file on bdst, it will be hidden.
25483 + AuDebugOn(a->bfound == -1
25485 + && a->bwh <= a->mvd_bsrc);
25486 + AuDebugOn(-1 < a->bfound
25487 + && a->bfound <= a->mvd_bsrc);
25490 + if (a->bfound == -1
25491 + && a->mvd_bsrc < a->bwh
25493 + && a->bwh < a->mvd_bdst) {
25494 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25495 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25496 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25498 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25499 + a->mvd_errno = EAU_MVDOWN_UPPER;
25500 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25501 + a->mvd_bdst, a->bfound);
25505 + err = 0; /* success */
25512 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25517 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25518 + && a->bfound == a->mvd_bdst)
25524 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25527 + struct au_branch *br;
25530 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25534 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25535 + a->mvd_bsrc = au_ibtop(a->inode);
25537 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25538 + if (unlikely(a->mvd_bsrc < 0
25539 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25540 + || au_dbbot(a->dentry) < a->mvd_bsrc
25541 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25542 + || (a->mvd_bsrc < au_ibtop(a->inode)
25543 + || au_ibbot(a->inode) < a->mvd_bsrc
25544 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25545 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25546 + AU_MVD_PR(dmsg, "no upper\n");
25550 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25551 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25552 + AU_MVD_PR(dmsg, "on the bottom\n");
25555 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25556 + br = au_sbr(a->sb, a->mvd_bsrc);
25557 + err = au_br_rdonly(br);
25558 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25559 + if (unlikely(err))
25561 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25562 + || IS_APPEND(a->mvd_h_src_inode))) {
25564 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25570 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25571 + a->mvd_bdst = find_lower_writable(a);
25572 + if (unlikely(a->mvd_bdst < 0)) {
25573 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25574 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25578 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25579 + if (unlikely(a->mvd_bdst < 0
25580 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25581 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25582 + AU_MVD_PR(dmsg, "no lower brid\n");
25587 + err = au_mvd_args_busy(dmsg, a);
25589 + err = au_mvd_args_parent(dmsg, a);
25591 + err = au_mvd_args_intermediate(dmsg, a);
25593 + err = au_mvd_args_exist(dmsg, a);
25595 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25602 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25605 + unsigned char dmsg;
25606 + struct au_mvd_args *args;
25607 + struct inode *inode;
25609 + inode = d_inode(dentry);
25611 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25615 + args = kmalloc(sizeof(*args), GFP_NOFS);
25616 + if (unlikely(!args))
25619 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25621 + /* VERIFY_WRITE */
25622 + err = !access_ok(uarg, sizeof(*uarg));
25623 + if (unlikely(err)) {
25628 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25629 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25630 + args->mvdown.au_errno = 0;
25631 + args->dentry = dentry;
25632 + args->inode = inode;
25633 + args->sb = dentry->d_sb;
25636 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25637 + args->parent = dget_parent(dentry);
25638 + args->dir = d_inode(args->parent);
25639 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25640 + dput(args->parent);
25641 + if (unlikely(args->parent != dentry->d_parent)) {
25642 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25646 + inode_lock_nested(inode, I_MUTEX_CHILD);
25647 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25648 + if (unlikely(err))
25651 + di_write_lock_parent(args->parent);
25652 + err = au_mvd_args(dmsg, args);
25653 + if (unlikely(err))
25656 + err = au_do_mvdown(dmsg, args);
25657 + if (unlikely(err))
25660 + au_cpup_attr_timesizes(args->dir);
25661 + au_cpup_attr_timesizes(inode);
25662 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25663 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25664 + /* au_digen_dec(dentry); */
25667 + di_write_unlock(args->parent);
25668 + aufs_read_unlock(dentry, AuLock_DW);
25670 + inode_unlock(inode);
25672 + inode_unlock(args->dir);
25674 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25677 + au_kfree_rcu(args);
25682 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25683 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25684 +++ linux/fs/aufs/opts.c 2020-01-27 10:57:18.175538316 +0100
25686 +// SPDX-License-Identifier: GPL-2.0
25688 + * Copyright (C) 2005-2020 Junjiro R. Okajima
25690 + * This program, aufs is free software; you can redistribute it and/or modify
25691 + * it under the terms of the GNU General Public License as published by
25692 + * the Free Software Foundation; either version 2 of the License, or
25693 + * (at your option) any later version.
25695 + * This program is distributed in the hope that it will be useful,
25696 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25697 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25698 + * GNU General Public License for more details.
25700 + * You should have received a copy of the GNU General Public License
25701 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25705 + * mount options/flags
25708 +#include <linux/namei.h>
25709 +#include <linux/types.h> /* a distribution requires */
25710 +#include <linux/parser.h>
25713 +/* ---------------------------------------------------------------------- */
25717 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25718 + Opt_idel, Opt_imod,
25719 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25720 + Opt_rdblk_def, Opt_rdhash_def,
25721 + Opt_xino, Opt_noxino,
25722 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25723 + Opt_trunc_xino_path, Opt_itrunc_xino,
25724 + Opt_trunc_xib, Opt_notrunc_xib,
25725 + Opt_shwh, Opt_noshwh,
25726 + Opt_plink, Opt_noplink, Opt_list_plink,
25728 + Opt_dio, Opt_nodio,
25729 + Opt_diropq_a, Opt_diropq_w,
25730 + Opt_warn_perm, Opt_nowarn_perm,
25731 + Opt_wbr_copyup, Opt_wbr_create,
25733 + Opt_verbose, Opt_noverbose,
25734 + Opt_sum, Opt_nosum, Opt_wsum,
25735 + Opt_dirperm1, Opt_nodirperm1,
25736 + Opt_dirren, Opt_nodirren,
25737 + Opt_acl, Opt_noacl,
25738 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25741 +static match_table_t options = {
25742 + {Opt_br, "br=%s"},
25743 + {Opt_br, "br:%s"},
25745 + {Opt_add, "add=%d:%s"},
25746 + {Opt_add, "add:%d:%s"},
25747 + {Opt_add, "ins=%d:%s"},
25748 + {Opt_add, "ins:%d:%s"},
25749 + {Opt_append, "append=%s"},
25750 + {Opt_append, "append:%s"},
25751 + {Opt_prepend, "prepend=%s"},
25752 + {Opt_prepend, "prepend:%s"},
25754 + {Opt_del, "del=%s"},
25755 + {Opt_del, "del:%s"},
25756 + /* {Opt_idel, "idel:%d"}, */
25757 + {Opt_mod, "mod=%s"},
25758 + {Opt_mod, "mod:%s"},
25759 + /* {Opt_imod, "imod:%d:%s"}, */
25761 + {Opt_dirwh, "dirwh=%d"},
25763 + {Opt_xino, "xino=%s"},
25764 + {Opt_noxino, "noxino"},
25765 + {Opt_trunc_xino, "trunc_xino"},
25766 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25767 + {Opt_notrunc_xino, "notrunc_xino"},
25768 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25769 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25770 + /* {Opt_zxino, "zxino=%s"}, */
25771 + {Opt_trunc_xib, "trunc_xib"},
25772 + {Opt_notrunc_xib, "notrunc_xib"},
25774 +#ifdef CONFIG_PROC_FS
25775 + {Opt_plink, "plink"},
25777 + {Opt_ignore_silent, "plink"},
25780 + {Opt_noplink, "noplink"},
25782 +#ifdef CONFIG_AUFS_DEBUG
25783 + {Opt_list_plink, "list_plink"},
25786 + {Opt_udba, "udba=%s"},
25788 + {Opt_dio, "dio"},
25789 + {Opt_nodio, "nodio"},
25791 +#ifdef CONFIG_AUFS_DIRREN
25792 + {Opt_dirren, "dirren"},
25793 + {Opt_nodirren, "nodirren"},
25795 + {Opt_ignore, "dirren"},
25796 + {Opt_ignore_silent, "nodirren"},
25799 +#ifdef CONFIG_AUFS_FHSM
25800 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25802 + {Opt_ignore, "fhsm_sec=%d"},
25805 + {Opt_diropq_a, "diropq=always"},
25806 + {Opt_diropq_a, "diropq=a"},
25807 + {Opt_diropq_w, "diropq=whiteouted"},
25808 + {Opt_diropq_w, "diropq=w"},
25810 + {Opt_warn_perm, "warn_perm"},
25811 + {Opt_nowarn_perm, "nowarn_perm"},
25813 + /* keep them temporary */
25814 + {Opt_ignore_silent, "nodlgt"},
25815 + {Opt_ignore, "clean_plink"},
25817 +#ifdef CONFIG_AUFS_SHWH
25818 + {Opt_shwh, "shwh"},
25820 + {Opt_noshwh, "noshwh"},
25822 + {Opt_dirperm1, "dirperm1"},
25823 + {Opt_nodirperm1, "nodirperm1"},
25825 + {Opt_verbose, "verbose"},
25826 + {Opt_verbose, "v"},
25827 + {Opt_noverbose, "noverbose"},
25828 + {Opt_noverbose, "quiet"},
25829 + {Opt_noverbose, "q"},
25830 + {Opt_noverbose, "silent"},
25832 + {Opt_sum, "sum"},
25833 + {Opt_nosum, "nosum"},
25834 + {Opt_wsum, "wsum"},
25836 + {Opt_rdcache, "rdcache=%d"},
25837 + {Opt_rdblk, "rdblk=%d"},
25838 + {Opt_rdblk_def, "rdblk=def"},
25839 + {Opt_rdhash, "rdhash=%d"},
25840 + {Opt_rdhash_def, "rdhash=def"},
25842 + {Opt_wbr_create, "create=%s"},
25843 + {Opt_wbr_create, "create_policy=%s"},
25844 + {Opt_wbr_copyup, "cpup=%s"},
25845 + {Opt_wbr_copyup, "copyup=%s"},
25846 + {Opt_wbr_copyup, "copyup_policy=%s"},
25848 + /* generic VFS flag */
25849 +#ifdef CONFIG_FS_POSIX_ACL
25850 + {Opt_acl, "acl"},
25851 + {Opt_noacl, "noacl"},
25853 + {Opt_ignore, "acl"},
25854 + {Opt_ignore_silent, "noacl"},
25857 + /* internal use for the scripts */
25858 + {Opt_ignore_silent, "si=%s"},
25860 + {Opt_br, "dirs=%s"},
25861 + {Opt_ignore, "debug=%d"},
25862 + {Opt_ignore, "delete=whiteout"},
25863 + {Opt_ignore, "delete=all"},
25864 + {Opt_ignore, "imap=%s"},
25866 + /* temporary workaround, due to old mount(8)? */
25867 + {Opt_ignore_silent, "relatime"},
25872 +/* ---------------------------------------------------------------------- */
25874 +static const char *au_parser_pattern(int val, match_table_t tbl)
25876 + struct match_token *p;
25879 + while (p->pattern) {
25880 + if (p->token == val)
25881 + return p->pattern;
25888 +static const char *au_optstr(int *val, match_table_t tbl)
25890 + struct match_token *p;
25897 + while (p->pattern) {
25899 + && (v & p->token) == p->token) {
25900 + *val &= ~p->token;
25901 + return p->pattern;
25910 +/* ---------------------------------------------------------------------- */
25912 +static match_table_t brperm = {
25913 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25914 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25915 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25919 +static match_table_t brattr = {
25921 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25922 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25923 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25924 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25925 +#ifdef CONFIG_AUFS_FHSM
25926 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25928 +#ifdef CONFIG_AUFS_XATTR
25929 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25930 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25931 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25932 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25933 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25934 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25937 + /* ro/rr branch */
25938 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25941 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25942 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25947 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25954 + p = strchr(str, '+');
25957 + v = match_token(str, table, args);
25959 + if (v & AuBrAttr_CMOO_Mask)
25960 + attr &= ~AuBrAttr_CMOO_Mask;
25965 + pr_warn("ignored branch attribute %s\n", str);
25975 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25983 + p = au_optstr(&perm, brattr);
25986 + memcpy(q, p, sz + 1);
25992 + p = au_optstr(&perm, brattr);
25996 + memcpy(q, p, sz + 1);
26002 + return q - str->a;
26005 +static int noinline_for_stack br_perm_val(char *perm)
26007 + int val, bad, sz;
26009 + substring_t args[MAX_OPT_ARGS];
26010 + au_br_perm_str_t attr;
26012 + p = strchr(perm, '+');
26015 + val = match_token(perm, brperm, args);
26019 + pr_warn("ignored branch permission %s\n", perm);
26020 + val = AuBrPerm_RO;
26026 + val |= br_attr_val(p + 1, brattr, args);
26029 + switch (val & AuBrPerm_Mask) {
26030 + case AuBrPerm_RO:
26031 + case AuBrPerm_RR:
26032 + bad = val & AuBrWAttr_Mask;
26033 + val &= ~AuBrWAttr_Mask;
26035 + case AuBrPerm_RW:
26036 + bad = val & AuBrRAttr_Mask;
26037 + val &= ~AuBrRAttr_Mask;
26042 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
26043 + * does not treat it as an error, just warning.
26044 + * this is a tiny guard for the user operation.
26046 + if (val & AuBrAttr_UNPIN) {
26047 + bad |= AuBrAttr_UNPIN;
26048 + val &= ~AuBrAttr_UNPIN;
26051 + if (unlikely(bad)) {
26052 + sz = au_do_optstr_br_attr(&attr, bad);
26054 + pr_warn("ignored branch attribute %s\n", attr.a);
26061 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
26063 + au_br_perm_str_t attr;
26069 + p = au_optstr(&perm, brperm);
26070 + AuDebugOn(!p || !*p);
26072 + memcpy(q, p, sz + 1);
26075 + sz = au_do_optstr_br_attr(&attr, perm);
26078 + memcpy(q, attr.a, sz + 1);
26081 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
26084 +/* ---------------------------------------------------------------------- */
26086 +static match_table_t udbalevel = {
26087 + {AuOpt_UDBA_REVAL, "reval"},
26088 + {AuOpt_UDBA_NONE, "none"},
26089 +#ifdef CONFIG_AUFS_HNOTIFY
26090 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
26091 +#ifdef CONFIG_AUFS_HFSNOTIFY
26092 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
26098 +static int noinline_for_stack udba_val(char *str)
26100 + substring_t args[MAX_OPT_ARGS];
26102 + return match_token(str, udbalevel, args);
26105 +const char *au_optstr_udba(int udba)
26107 + return au_parser_pattern(udba, udbalevel);
26110 +/* ---------------------------------------------------------------------- */
26112 +static match_table_t au_wbr_create_policy = {
26113 + {AuWbrCreate_TDP, "tdp"},
26114 + {AuWbrCreate_TDP, "top-down-parent"},
26115 + {AuWbrCreate_RR, "rr"},
26116 + {AuWbrCreate_RR, "round-robin"},
26117 + {AuWbrCreate_MFS, "mfs"},
26118 + {AuWbrCreate_MFS, "most-free-space"},
26119 + {AuWbrCreate_MFSV, "mfs:%d"},
26120 + {AuWbrCreate_MFSV, "most-free-space:%d"},
26122 + /* top-down regardless the parent, and then mfs */
26123 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
26124 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
26126 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
26127 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
26128 + {AuWbrCreate_PMFS, "pmfs"},
26129 + {AuWbrCreate_PMFSV, "pmfs:%d"},
26130 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
26131 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26136 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26137 + struct au_opt_wbr_create *create)
26140 + unsigned long long ull;
26143 + if (!match_u64(arg, &ull))
26144 + create->mfsrr_watermark = ull;
26146 + pr_err("bad integer in %s\n", str);
26153 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26154 + struct au_opt_wbr_create *create)
26159 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26160 + create->mfs_second = n;
26162 + pr_err("bad integer in %s\n", str);
26169 +static int noinline_for_stack
26170 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26173 + substring_t args[MAX_OPT_ARGS];
26175 + err = match_token(str, au_wbr_create_policy, args);
26176 + create->wbr_create = err;
26178 + case AuWbrCreate_MFSRRV:
26179 + case AuWbrCreate_TDMFSV:
26180 + case AuWbrCreate_PMFSRRV:
26181 + e = au_wbr_mfs_wmark(&args[0], str, create);
26183 + e = au_wbr_mfs_sec(&args[1], str, create);
26187 + case AuWbrCreate_MFSRR:
26188 + case AuWbrCreate_TDMFS:
26189 + case AuWbrCreate_PMFSRR:
26190 + e = au_wbr_mfs_wmark(&args[0], str, create);
26191 + if (unlikely(e)) {
26196 + case AuWbrCreate_MFS:
26197 + case AuWbrCreate_PMFS:
26198 + create->mfs_second = AUFS_MFS_DEF_SEC;
26200 + case AuWbrCreate_MFSV:
26201 + case AuWbrCreate_PMFSV:
26202 + e = au_wbr_mfs_sec(&args[0], str, create);
26211 +const char *au_optstr_wbr_create(int wbr_create)
26213 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26216 +static match_table_t au_wbr_copyup_policy = {
26217 + {AuWbrCopyup_TDP, "tdp"},
26218 + {AuWbrCopyup_TDP, "top-down-parent"},
26219 + {AuWbrCopyup_BUP, "bup"},
26220 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26221 + {AuWbrCopyup_BU, "bu"},
26222 + {AuWbrCopyup_BU, "bottom-up"},
26226 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26228 + substring_t args[MAX_OPT_ARGS];
26230 + return match_token(str, au_wbr_copyup_policy, args);
26233 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26235 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26238 +/* ---------------------------------------------------------------------- */
26240 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26242 +static void dump_opts(struct au_opts *opts)
26244 +#ifdef CONFIG_AUFS_DEBUG
26245 + /* reduce stack space */
26247 + struct au_opt_add *add;
26248 + struct au_opt_del *del;
26249 + struct au_opt_mod *mod;
26250 + struct au_opt_xino *xino;
26251 + struct au_opt_xino_itrunc *xino_itrunc;
26252 + struct au_opt_wbr_create *create;
26254 + struct au_opt *opt;
26257 + while (opt->type != Opt_tail) {
26258 + switch (opt->type) {
26260 + u.add = &opt->add;
26261 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26262 + u.add->bindex, u.add->pathname, u.add->perm,
26263 + u.add->path.dentry);
26267 + u.del = &opt->del;
26268 + AuDbg("del {%s, %p}\n",
26269 + u.del->pathname, u.del->h_path.dentry);
26273 + u.mod = &opt->mod;
26274 + AuDbg("mod {%s, 0x%x, %p}\n",
26275 + u.mod->path, u.mod->perm, u.mod->h_root);
26278 + u.add = &opt->add;
26279 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26280 + u.add->bindex, u.add->pathname, u.add->perm,
26281 + u.add->path.dentry);
26283 + case Opt_prepend:
26284 + u.add = &opt->add;
26285 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26286 + u.add->bindex, u.add->pathname, u.add->perm,
26287 + u.add->path.dentry);
26290 + AuDbg("dirwh %d\n", opt->dirwh);
26292 + case Opt_rdcache:
26293 + AuDbg("rdcache %d\n", opt->rdcache);
26296 + AuDbg("rdblk %u\n", opt->rdblk);
26298 + case Opt_rdblk_def:
26299 + AuDbg("rdblk_def\n");
26302 + AuDbg("rdhash %u\n", opt->rdhash);
26304 + case Opt_rdhash_def:
26305 + AuDbg("rdhash_def\n");
26308 + u.xino = &opt->xino;
26309 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26311 + case Opt_trunc_xino:
26312 + AuLabel(trunc_xino);
26314 + case Opt_notrunc_xino:
26315 + AuLabel(notrunc_xino);
26317 + case Opt_trunc_xino_path:
26318 + case Opt_itrunc_xino:
26319 + u.xino_itrunc = &opt->xino_itrunc;
26320 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26325 + case Opt_trunc_xib:
26326 + AuLabel(trunc_xib);
26328 + case Opt_notrunc_xib:
26329 + AuLabel(notrunc_xib);
26337 + case Opt_dirperm1:
26338 + AuLabel(dirperm1);
26340 + case Opt_nodirperm1:
26341 + AuLabel(nodirperm1);
26346 + case Opt_noplink:
26347 + AuLabel(noplink);
26349 + case Opt_list_plink:
26350 + AuLabel(list_plink);
26353 + AuDbg("udba %d, %s\n",
26354 + opt->udba, au_optstr_udba(opt->udba));
26362 + case Opt_diropq_a:
26363 + AuLabel(diropq_a);
26365 + case Opt_diropq_w:
26366 + AuLabel(diropq_w);
26368 + case Opt_warn_perm:
26369 + AuLabel(warn_perm);
26371 + case Opt_nowarn_perm:
26372 + AuLabel(nowarn_perm);
26374 + case Opt_verbose:
26375 + AuLabel(verbose);
26377 + case Opt_noverbose:
26378 + AuLabel(noverbose);
26389 + case Opt_wbr_create:
26390 + u.create = &opt->wbr_create;
26391 + AuDbg("create %d, %s\n", u.create->wbr_create,
26392 + au_optstr_wbr_create(u.create->wbr_create));
26393 + switch (u.create->wbr_create) {
26394 + case AuWbrCreate_MFSV:
26395 + case AuWbrCreate_PMFSV:
26396 + AuDbg("%d sec\n", u.create->mfs_second);
26398 + case AuWbrCreate_MFSRR:
26399 + case AuWbrCreate_TDMFS:
26400 + AuDbg("%llu watermark\n",
26401 + u.create->mfsrr_watermark);
26403 + case AuWbrCreate_MFSRRV:
26404 + case AuWbrCreate_TDMFSV:
26405 + case AuWbrCreate_PMFSRRV:
26406 + AuDbg("%llu watermark, %d sec\n",
26407 + u.create->mfsrr_watermark,
26408 + u.create->mfs_second);
26412 + case Opt_wbr_copyup:
26413 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26414 + au_optstr_wbr_copyup(opt->wbr_copyup));
26416 + case Opt_fhsm_sec:
26417 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26422 + case Opt_nodirren:
26423 + AuLabel(nodirren);
26439 +void au_opts_free(struct au_opts *opts)
26441 + struct au_opt *opt;
26444 + while (opt->type != Opt_tail) {
26445 + switch (opt->type) {
26448 + case Opt_prepend:
26449 + path_put(&opt->add.path);
26453 + path_put(&opt->del.h_path);
26457 + dput(opt->mod.h_root);
26460 + fput(opt->xino.file);
26467 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26468 + aufs_bindex_t bindex)
26471 + struct au_opt_add *add = &opt->add;
26474 + add->bindex = bindex;
26475 + add->perm = AuBrPerm_RO;
26476 + add->pathname = opt_str;
26477 + p = strchr(opt_str, '=');
26481 + add->perm = br_perm_val(p);
26484 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26487 + add->perm = AuBrPerm_RO;
26488 + if (au_test_fs_rr(add->path.dentry->d_sb))
26489 + add->perm = AuBrPerm_RR;
26490 + else if (!bindex && !(sb_flags & SB_RDONLY))
26491 + add->perm = AuBrPerm_RW;
26493 + opt->type = Opt_add;
26496 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26503 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26507 + del->pathname = args[0].from;
26508 + AuDbg("del path %s\n", del->pathname);
26510 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26511 + if (unlikely(err))
26512 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26517 +#if 0 /* reserved for future use */
26518 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26519 + struct au_opt_del *del, substring_t args[])
26522 + struct dentry *root;
26525 + root = sb->s_root;
26526 + aufs_read_lock(root, AuLock_FLUSH);
26527 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26528 + pr_err("out of bounds, %d\n", bindex);
26533 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26534 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26537 + aufs_read_unlock(root, !AuLock_IR);
26542 +static int noinline_for_stack
26543 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26546 + struct path path;
26550 + mod->path = args[0].from;
26551 + p = strchr(mod->path, '=');
26552 + if (unlikely(!p)) {
26553 + pr_err("no permission %s\n", args[0].from);
26558 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26559 + if (unlikely(err)) {
26560 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26564 + mod->perm = br_perm_val(p);
26565 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26566 + mod->h_root = dget(path.dentry);
26573 +#if 0 /* reserved for future use */
26574 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26575 + struct au_opt_mod *mod, substring_t args[])
26578 + struct dentry *root;
26581 + root = sb->s_root;
26582 + aufs_read_lock(root, AuLock_FLUSH);
26583 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26584 + pr_err("out of bounds, %d\n", bindex);
26589 + mod->perm = br_perm_val(args[1].from);
26590 + AuDbg("mod path %s, perm 0x%x, %s\n",
26591 + mod->path, mod->perm, args[1].from);
26592 + mod->h_root = dget(au_h_dptr(root, bindex));
26595 + aufs_read_unlock(root, !AuLock_IR);
26600 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26601 + substring_t args[])
26604 + struct file *file;
26606 + file = au_xino_create(sb, args[0].from, /*silent*/0, /*wbrtop*/0);
26607 + err = PTR_ERR(file);
26608 + if (IS_ERR(file))
26612 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26614 + pr_err("%s must be outside\n", args[0].from);
26619 + xino->file = file;
26620 + xino->path = args[0].from;
26626 +static int noinline_for_stack
26627 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26628 + struct au_opt_xino_itrunc *xino_itrunc,
26629 + substring_t args[])
26632 + aufs_bindex_t bbot, bindex;
26633 + struct path path;
26634 + struct dentry *root;
26636 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26637 + if (unlikely(err)) {
26638 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26642 + xino_itrunc->bindex = -1;
26643 + root = sb->s_root;
26644 + aufs_read_lock(root, AuLock_FLUSH);
26645 + bbot = au_sbbot(sb);
26646 + for (bindex = 0; bindex <= bbot; bindex++) {
26647 + if (au_h_dptr(root, bindex) == path.dentry) {
26648 + xino_itrunc->bindex = bindex;
26652 + aufs_read_unlock(root, !AuLock_IR);
26655 + if (unlikely(xino_itrunc->bindex < 0)) {
26656 + pr_err("no such branch %s\n", args[0].from);
26664 +/* called without aufs lock */
26665 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26667 + int err, n, token;
26668 + aufs_bindex_t bindex;
26669 + unsigned char skipped;
26670 + struct dentry *root;
26671 + struct au_opt *opt, *opt_tail;
26673 + /* reduce the stack space */
26675 + struct au_opt_xino_itrunc *xino_itrunc;
26676 + struct au_opt_wbr_create *create;
26679 + substring_t args[MAX_OPT_ARGS];
26683 + a = kmalloc(sizeof(*a), GFP_NOFS);
26684 + if (unlikely(!a))
26687 + root = sb->s_root;
26691 + opt_tail = opt + opts->max_opt - 1;
26692 + opt->type = Opt_tail;
26693 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26696 + token = match_token(opt_str, options, a->args);
26700 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26702 + err = opt_add(opt, opt_str, opts->sb_flags,
26704 + if (unlikely(!err && ++opt > opt_tail)) {
26708 + opt->type = Opt_tail;
26713 + if (unlikely(match_int(&a->args[0], &n))) {
26714 + pr_err("bad integer in %s\n", opt_str);
26718 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26721 + opt->type = token;
26724 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26725 + /*dummy bindex*/1);
26727 + opt->type = token;
26729 + case Opt_prepend:
26730 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26733 + opt->type = token;
26736 + err = au_opts_parse_del(&opt->del, a->args);
26738 + opt->type = token;
26740 +#if 0 /* reserved for future use */
26742 + del->pathname = "(indexed)";
26743 + if (unlikely(match_int(&args[0], &n))) {
26744 + pr_err("bad integer in %s\n", opt_str);
26747 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26749 + opt->type = token;
26753 + err = au_opts_parse_mod(&opt->mod, a->args);
26755 + opt->type = token;
26757 +#ifdef IMOD /* reserved for future use */
26759 + u.mod->path = "(indexed)";
26760 + if (unlikely(match_int(&a->args[0], &n))) {
26761 + pr_err("bad integer in %s\n", opt_str);
26764 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26766 + opt->type = token;
26770 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26772 + opt->type = token;
26775 + case Opt_trunc_xino_path:
26776 + err = au_opts_parse_xino_itrunc_path
26777 + (sb, &opt->xino_itrunc, a->args);
26779 + opt->type = token;
26782 + case Opt_itrunc_xino:
26783 + u.xino_itrunc = &opt->xino_itrunc;
26784 + if (unlikely(match_int(&a->args[0], &n))) {
26785 + pr_err("bad integer in %s\n", opt_str);
26788 + u.xino_itrunc->bindex = n;
26789 + aufs_read_lock(root, AuLock_FLUSH);
26790 + if (n < 0 || au_sbbot(sb) < n) {
26791 + pr_err("out of bounds, %d\n", n);
26792 + aufs_read_unlock(root, !AuLock_IR);
26795 + aufs_read_unlock(root, !AuLock_IR);
26797 + opt->type = token;
26801 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26804 + opt->type = token;
26807 + case Opt_rdcache:
26808 + if (unlikely(match_int(&a->args[0], &n))) {
26809 + pr_err("bad integer in %s\n", opt_str);
26812 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26813 + pr_err("rdcache must be smaller than %d\n",
26814 + AUFS_RDCACHE_MAX);
26817 + opt->rdcache = n;
26819 + opt->type = token;
26822 + if (unlikely(match_int(&a->args[0], &n)
26824 + || n > KMALLOC_MAX_SIZE)) {
26825 + pr_err("bad integer in %s\n", opt_str);
26828 + if (unlikely(n && n < NAME_MAX)) {
26829 + pr_err("rdblk must be larger than %d\n",
26835 + opt->type = token;
26838 + if (unlikely(match_int(&a->args[0], &n)
26840 + || n * sizeof(struct hlist_head)
26841 + > KMALLOC_MAX_SIZE)) {
26842 + pr_err("bad integer in %s\n", opt_str);
26847 + opt->type = token;
26850 + case Opt_trunc_xino:
26851 + case Opt_notrunc_xino:
26853 + case Opt_trunc_xib:
26854 + case Opt_notrunc_xib:
26857 + case Opt_dirperm1:
26858 + case Opt_nodirperm1:
26860 + case Opt_noplink:
26861 + case Opt_list_plink:
26864 + case Opt_diropq_a:
26865 + case Opt_diropq_w:
26866 + case Opt_warn_perm:
26867 + case Opt_nowarn_perm:
26868 + case Opt_verbose:
26869 + case Opt_noverbose:
26873 + case Opt_rdblk_def:
26874 + case Opt_rdhash_def:
26876 + case Opt_nodirren:
26880 + opt->type = token;
26884 + opt->udba = udba_val(a->args[0].from);
26885 + if (opt->udba >= 0) {
26887 + opt->type = token;
26889 + pr_err("wrong value, %s\n", opt_str);
26892 + case Opt_wbr_create:
26893 + u.create = &opt->wbr_create;
26894 + u.create->wbr_create
26895 + = au_wbr_create_val(a->args[0].from, u.create);
26896 + if (u.create->wbr_create >= 0) {
26898 + opt->type = token;
26900 + pr_err("wrong value, %s\n", opt_str);
26902 + case Opt_wbr_copyup:
26903 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26904 + if (opt->wbr_copyup >= 0) {
26906 + opt->type = token;
26908 + pr_err("wrong value, %s\n", opt_str);
26911 + case Opt_fhsm_sec:
26912 + if (unlikely(match_int(&a->args[0], &n)
26914 + pr_err("bad integer in %s\n", opt_str);
26917 + if (sysaufs_brs) {
26918 + opt->fhsm_second = n;
26919 + opt->type = token;
26921 + pr_warn("ignored %s\n", opt_str);
26926 + pr_warn("ignored %s\n", opt_str);
26928 + case Opt_ignore_silent:
26933 + pr_err("unknown option %s\n", opt_str);
26937 + if (!err && !skipped) {
26938 + if (unlikely(++opt > opt_tail)) {
26941 + opt->type = Opt_tail;
26944 + opt->type = Opt_tail;
26950 + if (unlikely(err))
26951 + au_opts_free(opts);
26957 +static int au_opt_wbr_create(struct super_block *sb,
26958 + struct au_opt_wbr_create *create)
26961 + struct au_sbinfo *sbinfo;
26963 + SiMustWriteLock(sb);
26965 + err = 1; /* handled */
26966 + sbinfo = au_sbi(sb);
26967 + if (sbinfo->si_wbr_create_ops->fin) {
26968 + err = sbinfo->si_wbr_create_ops->fin(sb);
26973 + sbinfo->si_wbr_create = create->wbr_create;
26974 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26975 + switch (create->wbr_create) {
26976 + case AuWbrCreate_MFSRRV:
26977 + case AuWbrCreate_MFSRR:
26978 + case AuWbrCreate_TDMFS:
26979 + case AuWbrCreate_TDMFSV:
26980 + case AuWbrCreate_PMFSRR:
26981 + case AuWbrCreate_PMFSRRV:
26982 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26984 + case AuWbrCreate_MFS:
26985 + case AuWbrCreate_MFSV:
26986 + case AuWbrCreate_PMFS:
26987 + case AuWbrCreate_PMFSV:
26988 + sbinfo->si_wbr_mfs.mfs_expire
26989 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
26993 + if (sbinfo->si_wbr_create_ops->init)
26994 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27001 + * plus: processed without an error
27002 + * zero: unprocessed
27004 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27005 + struct au_opts *opts)
27008 + struct au_sbinfo *sbinfo;
27010 + SiMustWriteLock(sb);
27012 + err = 1; /* handled */
27013 + sbinfo = au_sbi(sb);
27014 + switch (opt->type) {
27016 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27017 + sbinfo->si_mntflags |= opt->udba;
27018 + opts->given_udba |= opt->udba;
27022 + au_opt_set(sbinfo->si_mntflags, PLINK);
27024 + case Opt_noplink:
27025 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27026 + au_plink_put(sb, /*verbose*/1);
27027 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27029 + case Opt_list_plink:
27030 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27031 + au_plink_list(sb);
27035 + au_opt_set(sbinfo->si_mntflags, DIO);
27036 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27039 + au_opt_clr(sbinfo->si_mntflags, DIO);
27040 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27043 + case Opt_fhsm_sec:
27044 + au_fhsm_set(sbinfo, opt->fhsm_second);
27047 + case Opt_diropq_a:
27048 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27050 + case Opt_diropq_w:
27051 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27054 + case Opt_warn_perm:
27055 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27057 + case Opt_nowarn_perm:
27058 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27061 + case Opt_verbose:
27062 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27064 + case Opt_noverbose:
27065 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27069 + au_opt_set(sbinfo->si_mntflags, SUM);
27072 + au_opt_clr(sbinfo->si_mntflags, SUM);
27073 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27076 + au_opt_clr(sbinfo->si_mntflags, SUM);
27077 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27080 + case Opt_wbr_create:
27081 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27083 + case Opt_wbr_copyup:
27084 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27085 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27089 + sbinfo->si_dirwh = opt->dirwh;
27092 + case Opt_rdcache:
27093 + sbinfo->si_rdcache
27094 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27097 + sbinfo->si_rdblk = opt->rdblk;
27099 + case Opt_rdblk_def:
27100 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
27103 + sbinfo->si_rdhash = opt->rdhash;
27105 + case Opt_rdhash_def:
27106 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
27110 + au_opt_set(sbinfo->si_mntflags, SHWH);
27113 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27116 + case Opt_dirperm1:
27117 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27119 + case Opt_nodirperm1:
27120 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27123 + case Opt_trunc_xino:
27124 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27126 + case Opt_notrunc_xino:
27127 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27130 + case Opt_trunc_xino_path:
27131 + case Opt_itrunc_xino:
27132 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27138 + case Opt_trunc_xib:
27139 + au_fset_opts(opts->flags, TRUNC_XIB);
27141 + case Opt_notrunc_xib:
27142 + au_fclr_opts(opts->flags, TRUNC_XIB);
27147 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27148 + err = au_dr_opt_set(sb);
27153 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27155 + case Opt_nodirren:
27157 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27158 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27164 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27168 + sb->s_flags |= SB_POSIXACL;
27171 + sb->s_flags &= ~SB_POSIXACL;
27183 + * returns tri-state.
27184 + * plus: processed without an error
27185 + * zero: unprocessed
27188 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27189 + struct au_opts *opts)
27191 + int err, do_refresh;
27194 + switch (opt->type) {
27196 + opt->add.bindex = au_sbbot(sb) + 1;
27197 + if (opt->add.bindex < 0)
27198 + opt->add.bindex = 0;
27200 + /* Always goto add, not fallthrough */
27201 + case Opt_prepend:
27202 + opt->add.bindex = 0;
27203 + /* fallthrough */
27204 + add: /* indented label */
27206 + err = au_br_add(sb, &opt->add,
27207 + au_ftest_opts(opts->flags, REMOUNT));
27210 + au_fset_opts(opts->flags, REFRESH);
27216 + err = au_br_del(sb, &opt->del,
27217 + au_ftest_opts(opts->flags, REMOUNT));
27220 + au_fset_opts(opts->flags, TRUNC_XIB);
27221 + au_fset_opts(opts->flags, REFRESH);
27227 + err = au_br_mod(sb, &opt->mod,
27228 + au_ftest_opts(opts->flags, REMOUNT),
27233 + au_fset_opts(opts->flags, REFRESH);
27240 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27241 + struct au_opt_xino **opt_xino,
27242 + struct au_opts *opts)
27247 + switch (opt->type) {
27249 + err = au_xino_set(sb, &opt->xino,
27250 + !!au_ftest_opts(opts->flags, REMOUNT));
27251 + if (unlikely(err))
27254 + *opt_xino = &opt->xino;
27259 + *opt_xino = (void *)-1;
27266 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27267 + unsigned int pending)
27270 + aufs_bindex_t bindex, bbot;
27271 + unsigned char do_plink, skip, do_free, can_no_dreval;
27272 + struct au_branch *br;
27273 + struct au_wbr *wbr;
27274 + struct dentry *root, *dentry;
27275 + struct inode *dir, *h_dir;
27276 + struct au_sbinfo *sbinfo;
27277 + struct au_hinode *hdir;
27279 + SiMustAnyLock(sb);
27281 + sbinfo = au_sbi(sb);
27282 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27284 + if (!(sb_flags & SB_RDONLY)) {
27285 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27286 + pr_warn("first branch should be rw\n");
27287 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27288 + pr_warn_once("shwh should be used with ro\n");
27291 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27292 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27293 + pr_warn_once("udba=*notify requires xino\n");
27295 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27296 + pr_warn_once("dirperm1 breaks the protection"
27297 + " by the permission bits on the lower branch\n");
27301 + root = sb->s_root;
27302 + dir = d_inode(root);
27303 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27304 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27306 + bbot = au_sbbot(sb);
27307 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27309 + h_dir = au_h_iptr(dir, bindex);
27310 + br = au_sbr(sb, bindex);
27312 + if ((br->br_perm & AuBrAttr_ICEX)
27313 + && !h_dir->i_op->listxattr)
27314 + br->br_perm &= ~AuBrAttr_ICEX;
27315 +#if 0 /* untested */
27316 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27317 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27318 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27322 + wbr = br->br_wbr;
27324 + wbr_wh_read_lock(wbr);
27326 + if (!au_br_writable(br->br_perm)) {
27329 + || (!wbr->wbr_whbase
27330 + && !wbr->wbr_plink
27331 + && !wbr->wbr_orph));
27332 + } else if (!au_br_wh_linkable(br->br_perm)) {
27333 + /* skip = (!br->br_whbase && !br->br_orph); */
27334 + skip = (!wbr || !wbr->wbr_whbase);
27335 + if (skip && wbr) {
27337 + skip = !!wbr->wbr_plink;
27339 + skip = !wbr->wbr_plink;
27342 + /* skip = (br->br_whbase && br->br_ohph); */
27343 + skip = (wbr && wbr->wbr_whbase);
27346 + skip = !!wbr->wbr_plink;
27348 + skip = !wbr->wbr_plink;
27352 + wbr_wh_read_unlock(wbr);
27354 + if (can_no_dreval) {
27355 + dentry = br->br_path.dentry;
27356 + spin_lock(&dentry->d_lock);
27357 + if (dentry->d_flags &
27358 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27359 + can_no_dreval = 0;
27360 + spin_unlock(&dentry->d_lock);
27363 + if (au_br_fhsm(br->br_perm)) {
27365 + AuDebugOn(!br->br_fhsm);
27371 + hdir = au_hi(dir, bindex);
27372 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27374 + wbr_wh_write_lock(wbr);
27375 + err = au_wh_init(br, sb);
27377 + wbr_wh_write_unlock(wbr);
27378 + au_hn_inode_unlock(hdir);
27380 + if (!err && do_free) {
27381 + au_kfree_rcu(wbr);
27382 + br->br_wbr = NULL;
27386 + if (can_no_dreval)
27387 + au_fset_si(sbinfo, NO_DREVAL);
27389 + au_fclr_si(sbinfo, NO_DREVAL);
27392 + au_fset_si(sbinfo, FHSM);
27393 + for (bindex = bbot; bindex >= 0; bindex--) {
27394 + br = au_sbr(sb, bindex);
27395 + if (au_br_fhsm(br->br_perm)) {
27396 + au_fhsm_set_bottom(sb, bindex);
27401 + au_fclr_si(sbinfo, FHSM);
27402 + au_fhsm_set_bottom(sb, -1);
27408 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27411 + unsigned int tmp;
27412 + aufs_bindex_t bindex, bbot;
27413 + struct au_opt *opt;
27414 + struct au_opt_xino *opt_xino, xino;
27415 + struct au_sbinfo *sbinfo;
27416 + struct au_branch *br;
27417 + struct inode *dir;
27419 + SiMustWriteLock(sb);
27424 + while (err >= 0 && opt->type != Opt_tail)
27425 + err = au_opt_simple(sb, opt++, opts);
27428 + else if (unlikely(err < 0))
27431 + /* disable xino and udba temporary */
27432 + sbinfo = au_sbi(sb);
27433 + tmp = sbinfo->si_mntflags;
27434 + au_opt_clr(sbinfo->si_mntflags, XINO);
27435 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27438 + while (err >= 0 && opt->type != Opt_tail)
27439 + err = au_opt_br(sb, opt++, opts);
27442 + else if (unlikely(err < 0))
27445 + bbot = au_sbbot(sb);
27446 + if (unlikely(bbot < 0)) {
27448 + pr_err("no branches\n");
27452 + if (au_opt_test(tmp, XINO))
27453 + au_opt_set(sbinfo->si_mntflags, XINO);
27455 + while (!err && opt->type != Opt_tail)
27456 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27457 + if (unlikely(err))
27460 + err = au_opts_verify(sb, sb->s_flags, tmp);
27461 + if (unlikely(err))
27464 + /* restore xino */
27465 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27466 + xino.file = au_xino_def(sb);
27467 + err = PTR_ERR(xino.file);
27468 + if (IS_ERR(xino.file))
27471 + err = au_xino_set(sb, &xino, /*remount*/0);
27473 + if (unlikely(err))
27477 + /* restore udba */
27478 + tmp &= AuOptMask_UDBA;
27479 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27480 + sbinfo->si_mntflags |= tmp;
27481 + bbot = au_sbbot(sb);
27482 + for (bindex = 0; bindex <= bbot; bindex++) {
27483 + br = au_sbr(sb, bindex);
27484 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27485 + if (unlikely(err))
27486 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27488 + /* go on even if err */
27490 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27491 + dir = d_inode(sb->s_root);
27492 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27499 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27502 + unsigned char no_dreval;
27503 + struct inode *dir;
27504 + struct au_opt_xino *opt_xino;
27505 + struct au_opt *opt;
27506 + struct au_sbinfo *sbinfo;
27508 + SiMustWriteLock(sb);
27510 + err = au_dr_opt_flush(sb);
27511 + if (unlikely(err))
27513 + au_fset_opts(opts->flags, DR_FLUSHED);
27515 + dir = d_inode(sb->s_root);
27516 + sbinfo = au_sbi(sb);
27519 + while (err >= 0 && opt->type != Opt_tail) {
27520 + err = au_opt_simple(sb, opt, opts);
27522 + err = au_opt_br(sb, opt, opts);
27524 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27530 + /* go on even err */
27532 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27533 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27534 + if (unlikely(rerr && !err))
27537 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27538 + au_fset_opts(opts->flags, REFRESH_IDOP);
27540 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27541 + rerr = au_xib_trunc(sb);
27542 + if (unlikely(rerr && !err))
27546 + /* will be handled by the caller */
27547 + if (!au_ftest_opts(opts->flags, REFRESH)
27548 + && (opts->given_udba
27549 + || au_opt_test(sbinfo->si_mntflags, XINO)
27550 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27552 + au_fset_opts(opts->flags, REFRESH);
27554 + AuDbg("status 0x%x\n", opts->flags);
27560 +/* ---------------------------------------------------------------------- */
27562 +unsigned int au_opt_udba(struct super_block *sb)
27564 + return au_mntflags(sb) & AuOptMask_UDBA;
27566 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27567 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27568 +++ linux/fs/aufs/opts.h 2020-01-27 10:57:18.175538316 +0100
27570 +/* SPDX-License-Identifier: GPL-2.0 */
27572 + * Copyright (C) 2005-2020 Junjiro R. Okajima
27574 + * This program, aufs is free software; you can redistribute it and/or modify
27575 + * it under the terms of the GNU General Public License as published by
27576 + * the Free Software Foundation; either version 2 of the License, or
27577 + * (at your option) any later version.
27579 + * This program is distributed in the hope that it will be useful,
27580 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27581 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27582 + * GNU General Public License for more details.
27584 + * You should have received a copy of the GNU General Public License
27585 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27589 + * mount options/flags
27592 +#ifndef __AUFS_OPTS_H__
27593 +#define __AUFS_OPTS_H__
27597 +#include <linux/path.h>
27601 +/* ---------------------------------------------------------------------- */
27604 +#define AuOpt_XINO 1 /* external inode number bitmap
27605 + and translation table */
27606 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27607 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27608 +#define AuOpt_UDBA_REVAL (1 << 3)
27609 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27610 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27611 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27612 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27614 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27615 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27616 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27617 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27618 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27619 +#define AuOpt_DIO (1 << 14) /* direct io */
27620 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27622 +#ifndef CONFIG_AUFS_HNOTIFY
27623 +#undef AuOpt_UDBA_HNOTIFY
27624 +#define AuOpt_UDBA_HNOTIFY 0
27626 +#ifndef CONFIG_AUFS_DIRREN
27627 +#undef AuOpt_DIRREN
27628 +#define AuOpt_DIRREN 0
27630 +#ifndef CONFIG_AUFS_SHWH
27632 +#define AuOpt_SHWH 0
27635 +#define AuOpt_Def (AuOpt_XINO \
27636 + | AuOpt_UDBA_REVAL \
27638 + /* | AuOpt_DIRPERM1 */ \
27639 + | AuOpt_WARN_PERM)
27640 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27641 + | AuOpt_UDBA_REVAL \
27642 + | AuOpt_UDBA_HNOTIFY)
27644 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27645 +#define au_opt_set(flags, name) do { \
27646 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27647 + ((flags) |= AuOpt_##name); \
27649 +#define au_opt_set_udba(flags, name) do { \
27650 + (flags) &= ~AuOptMask_UDBA; \
27651 + ((flags) |= AuOpt_##name); \
27653 +#define au_opt_clr(flags, name) do { \
27654 + ((flags) &= ~AuOpt_##name); \
27657 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27659 +#ifdef CONFIG_PROC_FS
27662 + return mntflags & ~AuOpt_PLINK;
27666 +/* ---------------------------------------------------------------------- */
27668 +/* policies to select one among multiple writable branches */
27670 + AuWbrCreate_TDP, /* top down parent */
27671 + AuWbrCreate_RR, /* round robin */
27672 + AuWbrCreate_MFS, /* most free space */
27673 + AuWbrCreate_MFSV, /* mfs with seconds */
27674 + AuWbrCreate_MFSRR, /* mfs then rr */
27675 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27676 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27677 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27678 + AuWbrCreate_PMFS, /* parent and mfs */
27679 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27680 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27681 + AuWbrCreate_PMFSRRV, /* plus seconds */
27683 + AuWbrCreate_Def = AuWbrCreate_TDP
27687 + AuWbrCopyup_TDP, /* top down parent */
27688 + AuWbrCopyup_BUP, /* bottom up parent */
27689 + AuWbrCopyup_BU, /* bottom up */
27691 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27694 +/* ---------------------------------------------------------------------- */
27696 +struct au_opt_add {
27697 + aufs_bindex_t bindex;
27700 + struct path path;
27703 +struct au_opt_del {
27705 + struct path h_path;
27708 +struct au_opt_mod {
27711 + struct dentry *h_root;
27714 +struct au_opt_xino {
27716 + struct file *file;
27719 +struct au_opt_xino_itrunc {
27720 + aufs_bindex_t bindex;
27723 +struct au_opt_wbr_create {
27726 + unsigned long long mfsrr_watermark;
27732 + struct au_opt_xino xino;
27733 + struct au_opt_xino_itrunc xino_itrunc;
27734 + struct au_opt_add add;
27735 + struct au_opt_del del;
27736 + struct au_opt_mod mod;
27739 + unsigned int rdblk;
27740 + unsigned int rdhash;
27742 + struct au_opt_wbr_create wbr_create;
27744 + unsigned int fhsm_second;
27749 +#define AuOpts_REMOUNT 1
27750 +#define AuOpts_REFRESH (1 << 1)
27751 +#define AuOpts_TRUNC_XIB (1 << 2)
27752 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27753 +#define AuOpts_REFRESH_IDOP (1 << 4)
27754 +#define AuOpts_DR_FLUSHED (1 << 5)
27755 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27756 +#define au_fset_opts(flags, name) \
27757 + do { (flags) |= AuOpts_##name; } while (0)
27758 +#define au_fclr_opts(flags, name) \
27759 + do { (flags) &= ~AuOpts_##name; } while (0)
27761 +#ifndef CONFIG_AUFS_DIRREN
27762 +#undef AuOpts_DR_FLUSHED
27763 +#define AuOpts_DR_FLUSHED 0
27767 + struct au_opt *opt;
27770 + unsigned int given_udba;
27771 + unsigned int flags;
27772 + unsigned long sb_flags;
27775 +/* ---------------------------------------------------------------------- */
27778 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27779 +const char *au_optstr_udba(int udba);
27780 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27781 +const char *au_optstr_wbr_create(int wbr_create);
27783 +void au_opts_free(struct au_opts *opts);
27784 +struct super_block;
27785 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27786 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27787 + unsigned int pending);
27788 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27789 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27791 +unsigned int au_opt_udba(struct super_block *sb);
27793 +#endif /* __KERNEL__ */
27794 +#endif /* __AUFS_OPTS_H__ */
27795 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27796 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27797 +++ linux/fs/aufs/plink.c 2020-01-27 10:57:18.175538316 +0100
27799 +// SPDX-License-Identifier: GPL-2.0
27801 + * Copyright (C) 2005-2020 Junjiro R. Okajima
27803 + * This program, aufs is free software; you can redistribute it and/or modify
27804 + * it under the terms of the GNU General Public License as published by
27805 + * the Free Software Foundation; either version 2 of the License, or
27806 + * (at your option) any later version.
27808 + * This program is distributed in the hope that it will be useful,
27809 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27810 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27811 + * GNU General Public License for more details.
27813 + * You should have received a copy of the GNU General Public License
27814 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27824 + * the pseudo-link maintenance mode.
27825 + * during a user process maintains the pseudo-links,
27826 + * prohibit adding a new plink and branch manipulation.
27830 + * For entry functions which will handle plink, and i_mutex is already held
27832 + * They cannot wait and should return an error at once.
27833 + * Callers has to check the error.
27835 + * For entry functions which will handle plink, but i_mutex is not held
27837 + * They can wait the plink maintenance mode to finish.
27839 + * They behave like F_SETLK and F_SETLKW.
27840 + * If the caller never handle plink, then both flags are unnecessary.
27843 +int au_plink_maint(struct super_block *sb, int flags)
27847 + struct task_struct *parent, *prev;
27848 + struct au_sbinfo *sbi;
27850 + SiMustAnyLock(sb);
27853 + if (!au_opt_test(au_mntflags(sb), PLINK))
27856 + sbi = au_sbi(sb);
27857 + pid = sbi->si_plink_maint_pid;
27858 + if (!pid || pid == current->pid)
27861 + /* todo: it highly depends upon /sbin/mount.aufs */
27863 + parent = current;
27867 + parent = rcu_dereference(parent->real_parent);
27868 + if (parent == prev)
27870 + ppid = task_pid_vnr(parent);
27871 + if (pid == ppid) {
27872 + rcu_read_unlock();
27877 + rcu_read_unlock();
27879 + if (au_ftest_lock(flags, NOPLMW)) {
27880 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27881 + /* AuDebugOn(!lockdep_depth(current)); */
27882 + while (sbi->si_plink_maint_pid) {
27883 + si_read_unlock(sb);
27884 + /* gave up wake_up_bit() */
27885 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27887 + if (au_ftest_lock(flags, FLUSH))
27888 + au_nwt_flush(&sbi->si_nowait);
27889 + si_noflush_read_lock(sb);
27891 + } else if (au_ftest_lock(flags, NOPLM)) {
27892 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27900 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27902 + spin_lock(&sbinfo->si_plink_maint_lock);
27903 + sbinfo->si_plink_maint_pid = 0;
27904 + spin_unlock(&sbinfo->si_plink_maint_lock);
27905 + wake_up_all(&sbinfo->si_plink_wq);
27908 +int au_plink_maint_enter(struct super_block *sb)
27911 + struct au_sbinfo *sbinfo;
27914 + sbinfo = au_sbi(sb);
27915 + /* make sure i am the only one in this fs */
27916 + si_write_lock(sb, AuLock_FLUSH);
27917 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27918 + spin_lock(&sbinfo->si_plink_maint_lock);
27919 + if (!sbinfo->si_plink_maint_pid)
27920 + sbinfo->si_plink_maint_pid = current->pid;
27923 + spin_unlock(&sbinfo->si_plink_maint_lock);
27925 + si_write_unlock(sb);
27930 +/* ---------------------------------------------------------------------- */
27932 +#ifdef CONFIG_AUFS_DEBUG
27933 +void au_plink_list(struct super_block *sb)
27936 + struct au_sbinfo *sbinfo;
27937 + struct hlist_bl_head *hbl;
27938 + struct hlist_bl_node *pos;
27939 + struct au_icntnr *icntnr;
27941 + SiMustAnyLock(sb);
27943 + sbinfo = au_sbi(sb);
27944 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27945 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27947 + for (i = 0; i < AuPlink_NHASH; i++) {
27948 + hbl = sbinfo->si_plink + i;
27949 + hlist_bl_lock(hbl);
27950 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27951 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27952 + hlist_bl_unlock(hbl);
27957 +/* is the inode pseudo-linked? */
27958 +int au_plink_test(struct inode *inode)
27961 + struct au_sbinfo *sbinfo;
27962 + struct hlist_bl_head *hbl;
27963 + struct hlist_bl_node *pos;
27964 + struct au_icntnr *icntnr;
27966 + sbinfo = au_sbi(inode->i_sb);
27967 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27968 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27969 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27972 + i = au_plink_hash(inode->i_ino);
27973 + hbl = sbinfo->si_plink + i;
27974 + hlist_bl_lock(hbl);
27975 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27976 + if (&icntnr->vfs_inode == inode) {
27980 + hlist_bl_unlock(hbl);
27984 +/* ---------------------------------------------------------------------- */
27987 + * generate a name for plink.
27988 + * the file will be stored under AUFS_WH_PLINKDIR.
27990 +/* 20 is max digits length of ulong 64 */
27991 +#define PLINK_NAME_LEN ((20 + 1) * 2)
27993 +static int plink_name(char *name, int len, struct inode *inode,
27994 + aufs_bindex_t bindex)
27997 + struct inode *h_inode;
27999 + h_inode = au_h_iptr(inode, bindex);
28000 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28004 +struct au_do_plink_lkup_args {
28005 + struct dentry **errp;
28006 + struct qstr *tgtname;
28007 + struct dentry *h_parent;
28008 + struct au_branch *br;
28011 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28012 + struct dentry *h_parent,
28013 + struct au_branch *br)
28015 + struct dentry *h_dentry;
28016 + struct inode *h_inode;
28018 + h_inode = d_inode(h_parent);
28019 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28020 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
28021 + inode_unlock_shared(h_inode);
28025 +static void au_call_do_plink_lkup(void *args)
28027 + struct au_do_plink_lkup_args *a = args;
28028 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
28031 +/* lookup the plink-ed @inode under the branch at @bindex */
28032 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28034 + struct dentry *h_dentry, *h_parent;
28035 + struct au_branch *br;
28037 + char a[PLINK_NAME_LEN];
28038 + struct qstr tgtname = QSTR_INIT(a, 0);
28040 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28042 + br = au_sbr(inode->i_sb, bindex);
28043 + h_parent = br->br_wbr->wbr_plink;
28044 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28046 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28047 + struct au_do_plink_lkup_args args = {
28048 + .errp = &h_dentry,
28049 + .tgtname = &tgtname,
28050 + .h_parent = h_parent,
28054 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28055 + if (unlikely(wkq_err))
28056 + h_dentry = ERR_PTR(wkq_err);
28058 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
28063 +/* create a pseudo-link */
28064 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
28065 + struct dentry *h_dentry, struct au_branch *br)
28068 + struct path h_path = {
28069 + .mnt = au_br_mnt(br)
28071 + struct inode *h_dir, *delegated;
28073 + h_dir = d_inode(h_parent);
28074 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28076 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
28077 + err = PTR_ERR(h_path.dentry);
28078 + if (IS_ERR(h_path.dentry))
28082 + /* wh.plink dir is not monitored */
28083 + /* todo: is it really safe? */
28084 + if (d_is_positive(h_path.dentry)
28085 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28086 + delegated = NULL;
28087 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28088 + if (unlikely(err == -EWOULDBLOCK)) {
28089 + pr_warn("cannot retry for NFSv4 delegation"
28090 + " for an internal unlink\n");
28093 + dput(h_path.dentry);
28094 + h_path.dentry = NULL;
28098 + if (!err && d_is_negative(h_path.dentry)) {
28099 + delegated = NULL;
28100 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28101 + if (unlikely(err == -EWOULDBLOCK)) {
28102 + pr_warn("cannot retry for NFSv4 delegation"
28103 + " for an internal link\n");
28107 + dput(h_path.dentry);
28110 + inode_unlock(h_dir);
28114 +struct do_whplink_args {
28116 + struct qstr *tgt;
28117 + struct dentry *h_parent;
28118 + struct dentry *h_dentry;
28119 + struct au_branch *br;
28122 +static void call_do_whplink(void *args)
28124 + struct do_whplink_args *a = args;
28125 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
28128 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28129 + aufs_bindex_t bindex, struct au_branch *br)
28131 + int err, wkq_err;
28132 + struct au_wbr *wbr;
28133 + struct dentry *h_parent;
28134 + char a[PLINK_NAME_LEN];
28135 + struct qstr tgtname = QSTR_INIT(a, 0);
28137 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
28138 + h_parent = wbr->wbr_plink;
28139 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28141 + /* always superio. */
28142 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28143 + struct do_whplink_args args = {
28146 + .h_parent = h_parent,
28147 + .h_dentry = h_dentry,
28150 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28151 + if (unlikely(wkq_err))
28154 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
28160 + * create a new pseudo-link for @h_dentry on @bindex.
28161 + * the linked inode is held in aufs @inode.
28163 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28164 + struct dentry *h_dentry)
28166 + struct super_block *sb;
28167 + struct au_sbinfo *sbinfo;
28168 + struct hlist_bl_head *hbl;
28169 + struct hlist_bl_node *pos;
28170 + struct au_icntnr *icntnr;
28171 + int found, err, cnt, i;
28173 + sb = inode->i_sb;
28174 + sbinfo = au_sbi(sb);
28175 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28176 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28178 + found = au_plink_test(inode);
28182 + i = au_plink_hash(inode->i_ino);
28183 + hbl = sbinfo->si_plink + i;
28186 + hlist_bl_lock(hbl);
28187 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28188 + if (&icntnr->vfs_inode == inode) {
28194 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28195 + hlist_bl_add_head(&icntnr->plink, hbl);
28197 + hlist_bl_unlock(hbl);
28199 + cnt = au_hbl_count(hbl);
28200 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28201 + if (cnt > AUFS_PLINK_WARN)
28202 + AuWarn1(msg ", %d\n", cnt);
28204 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
28205 + if (unlikely(err)) {
28206 + pr_warn("err %d, damaged pseudo link.\n", err);
28207 + au_hbl_del(&icntnr->plink, hbl);
28208 + iput(&icntnr->vfs_inode);
28211 + iput(&icntnr->vfs_inode);
28214 +/* free all plinks */
28215 +void au_plink_put(struct super_block *sb, int verbose)
28218 + struct au_sbinfo *sbinfo;
28219 + struct hlist_bl_head *hbl;
28220 + struct hlist_bl_node *pos, *tmp;
28221 + struct au_icntnr *icntnr;
28223 + SiMustWriteLock(sb);
28225 + sbinfo = au_sbi(sb);
28226 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28227 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28229 + /* no spin_lock since sbinfo is write-locked */
28231 + for (i = 0; i < AuPlink_NHASH; i++) {
28232 + hbl = sbinfo->si_plink + i;
28233 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28234 + pr_warn("pseudo-link is not flushed");
28237 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28238 + iput(&icntnr->vfs_inode);
28239 + INIT_HLIST_BL_HEAD(hbl);
28243 +void au_plink_clean(struct super_block *sb, int verbose)
28245 + struct dentry *root;
28247 + root = sb->s_root;
28248 + aufs_write_lock(root);
28249 + if (au_opt_test(au_mntflags(sb), PLINK))
28250 + au_plink_put(sb, verbose);
28251 + aufs_write_unlock(root);
28254 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28257 + aufs_bindex_t btop, bbot, bindex;
28260 + btop = au_ibtop(inode);
28261 + bbot = au_ibbot(inode);
28263 + for (bindex = btop; bindex <= bbot; bindex++) {
28264 + if (!au_h_iptr(inode, bindex)
28265 + || au_ii_br_id(inode, bindex) != br_id)
28267 + au_set_h_iptr(inode, bindex, NULL, 0);
28272 + for (bindex = btop; bindex <= bbot; bindex++)
28273 + if (au_h_iptr(inode, bindex)) {
28283 +/* free the plinks on a branch specified by @br_id */
28284 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28286 + struct au_sbinfo *sbinfo;
28287 + struct hlist_bl_head *hbl;
28288 + struct hlist_bl_node *pos, *tmp;
28289 + struct au_icntnr *icntnr;
28290 + struct inode *inode;
28293 + SiMustWriteLock(sb);
28295 + sbinfo = au_sbi(sb);
28296 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28297 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28299 + /* no bit_lock since sbinfo is write-locked */
28300 + for (i = 0; i < AuPlink_NHASH; i++) {
28301 + hbl = sbinfo->si_plink + i;
28302 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28303 + inode = au_igrab(&icntnr->vfs_inode);
28304 + ii_write_lock_child(inode);
28305 + do_put = au_plink_do_half_refresh(inode, br_id);
28307 + hlist_bl_del(&icntnr->plink);
28310 + ii_write_unlock(inode);
28315 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28316 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28317 +++ linux/fs/aufs/poll.c 2020-01-27 10:57:18.175538316 +0100
28319 +// SPDX-License-Identifier: GPL-2.0
28321 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28323 + * This program, aufs is free software; you can redistribute it and/or modify
28324 + * it under the terms of the GNU General Public License as published by
28325 + * the Free Software Foundation; either version 2 of the License, or
28326 + * (at your option) any later version.
28328 + * This program is distributed in the hope that it will be useful,
28329 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28330 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28331 + * GNU General Public License for more details.
28333 + * You should have received a copy of the GNU General Public License
28334 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28339 + * There is only one filesystem which implements ->poll operation, currently.
28344 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28347 + struct file *h_file;
28348 + struct super_block *sb;
28350 + /* We should pretend an error happened. */
28351 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28352 + sb = file->f_path.dentry->d_sb;
28353 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28355 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28356 + if (IS_ERR(h_file)) {
28357 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28361 + mask = vfs_poll(h_file, pt);
28362 + fput(h_file); /* instead of au_read_post() */
28365 + si_read_unlock(sb);
28366 + if (mask & EPOLLERR)
28367 + AuDbg("mask 0x%x\n", mask);
28370 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28371 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28372 +++ linux/fs/aufs/posix_acl.c 2020-01-27 10:57:18.175538316 +0100
28374 +// SPDX-License-Identifier: GPL-2.0
28376 + * Copyright (C) 2014-2020 Junjiro R. Okajima
28378 + * This program, aufs is free software; you can redistribute it and/or modify
28379 + * it under the terms of the GNU General Public License as published by
28380 + * the Free Software Foundation; either version 2 of the License, or
28381 + * (at your option) any later version.
28383 + * This program is distributed in the hope that it will be useful,
28384 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28385 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28386 + * GNU General Public License for more details.
28388 + * You should have received a copy of the GNU General Public License
28389 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28393 + * posix acl operations
28396 +#include <linux/fs.h>
28399 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28401 + struct posix_acl *acl;
28403 + aufs_bindex_t bindex;
28404 + struct inode *h_inode;
28405 + struct super_block *sb;
28408 + sb = inode->i_sb;
28409 + si_read_lock(sb, AuLock_FLUSH);
28410 + ii_read_lock_child(inode);
28411 + if (!(sb->s_flags & SB_POSIXACL))
28414 + bindex = au_ibtop(inode);
28415 + h_inode = au_h_iptr(inode, bindex);
28416 + if (unlikely(!h_inode
28417 + || ((h_inode->i_mode & S_IFMT)
28418 + != (inode->i_mode & S_IFMT)))) {
28419 + err = au_busy_or_stale();
28420 + acl = ERR_PTR(err);
28424 + /* always topmost only */
28425 + acl = get_acl(h_inode, type);
28427 + forget_cached_acl(inode, type);
28429 + set_cached_acl(inode, type, acl);
28432 + ii_read_unlock(inode);
28433 + si_read_unlock(sb);
28435 + AuTraceErrPtr(acl);
28439 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28443 + struct dentry *dentry;
28444 + struct au_sxattr arg = {
28445 + .type = AU_ACL_SET,
28452 + IMustLock(inode);
28454 + if (inode->i_ino == AUFS_ROOT_INO)
28455 + dentry = dget(inode->i_sb->s_root);
28457 + dentry = d_find_alias(inode);
28459 + dentry = d_find_any_alias(inode);
28461 + pr_warn("cannot handle this inode, "
28462 + "please report to aufs-users ML\n");
28468 + ssz = au_sxattr(dentry, inode, &arg);
28469 + /* forget even it if succeeds since the branch might set differently */
28470 + forget_cached_acl(inode, type);
28479 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28480 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28481 +++ linux/fs/aufs/procfs.c 2020-08-03 09:14:43.142321747 +0200
28483 +// SPDX-License-Identifier: GPL-2.0
28485 + * Copyright (C) 2010-2020 Junjiro R. Okajima
28487 + * This program, aufs is free software; you can redistribute it and/or modify
28488 + * it under the terms of the GNU General Public License as published by
28489 + * the Free Software Foundation; either version 2 of the License, or
28490 + * (at your option) any later version.
28492 + * This program is distributed in the hope that it will be useful,
28493 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28494 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28495 + * GNU General Public License for more details.
28497 + * You should have received a copy of the GNU General Public License
28498 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28502 + * procfs interfaces
28505 +#include <linux/proc_fs.h>
28508 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28510 + struct au_sbinfo *sbinfo;
28512 + sbinfo = file->private_data;
28514 + au_plink_maint_leave(sbinfo);
28515 + kobject_put(&sbinfo->si_kobj);
28521 +static void au_procfs_plm_write_clean(struct file *file)
28523 + struct au_sbinfo *sbinfo;
28525 + sbinfo = file->private_data;
28527 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28530 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28533 + struct super_block *sb;
28534 + struct au_sbinfo *sbinfo;
28535 + struct hlist_bl_node *pos;
28538 + if (unlikely(file->private_data))
28542 + /* don't use au_sbilist_lock() here */
28543 + hlist_bl_lock(&au_sbilist);
28544 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28545 + if (id == sysaufs_si_id(sbinfo)) {
28546 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28547 + sb = sbinfo->si_sb;
28550 + hlist_bl_unlock(&au_sbilist);
28553 + if (unlikely(!sb))
28556 + err = au_plink_maint_enter(sb);
28558 + /* keep kobject_get() */
28559 + file->private_data = sbinfo;
28561 + kobject_put(&sbinfo->si_kobj);
28567 + * Accept a valid "si=xxxx" only.
28568 + * Once it is accepted successfully, accept "clean" too.
28570 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28571 + size_t count, loff_t *ppos)
28574 + unsigned long id;
28575 + /* last newline is allowed */
28576 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28579 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28583 + if (unlikely(count > sizeof(buf)))
28586 + err = copy_from_user(buf, ubuf, count);
28587 + if (unlikely(err)) {
28594 + if (!strcmp("clean", buf)) {
28595 + au_procfs_plm_write_clean(file);
28596 + goto out_success;
28597 + } else if (unlikely(strncmp("si=", buf, 3)))
28600 + err = kstrtoul(buf + 3, 16, &id);
28601 + if (unlikely(err))
28604 + err = au_procfs_plm_write_si(file, id);
28605 + if (unlikely(err))
28609 + err = count; /* success */
28614 +static const struct proc_ops au_procfs_plm_op = {
28615 + .proc_write = au_procfs_plm_write,
28616 + .proc_release = au_procfs_plm_release
28619 +/* ---------------------------------------------------------------------- */
28621 +static struct proc_dir_entry *au_procfs_dir;
28623 +void au_procfs_fin(void)
28625 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28626 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28629 +int __init au_procfs_init(void)
28632 + struct proc_dir_entry *entry;
28635 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28636 + if (unlikely(!au_procfs_dir))
28639 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28640 + au_procfs_dir, &au_procfs_plm_op);
28641 + if (unlikely(!entry))
28645 + goto out; /* success */
28649 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28653 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28654 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28655 +++ linux/fs/aufs/rdu.c 2020-01-27 10:57:18.178871751 +0100
28657 +// SPDX-License-Identifier: GPL-2.0
28659 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28661 + * This program, aufs is free software; you can redistribute it and/or modify
28662 + * it under the terms of the GNU General Public License as published by
28663 + * the Free Software Foundation; either version 2 of the License, or
28664 + * (at your option) any later version.
28666 + * This program is distributed in the hope that it will be useful,
28667 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28668 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28669 + * GNU General Public License for more details.
28671 + * You should have received a copy of the GNU General Public License
28672 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28676 + * readdir in userspace.
28679 +#include <linux/compat.h>
28680 +#include <linux/fs_stack.h>
28681 +#include <linux/security.h>
28684 +/* bits for struct aufs_rdu.flags */
28685 +#define AuRdu_CALLED 1
28686 +#define AuRdu_CONT (1 << 1)
28687 +#define AuRdu_FULL (1 << 2)
28688 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28689 +#define au_fset_rdu(flags, name) \
28690 + do { (flags) |= AuRdu_##name; } while (0)
28691 +#define au_fclr_rdu(flags, name) \
28692 + do { (flags) &= ~AuRdu_##name; } while (0)
28694 +struct au_rdu_arg {
28695 + struct dir_context ctx;
28696 + struct aufs_rdu *rdu;
28697 + union au_rdu_ent_ul ent;
28698 + unsigned long end;
28700 + struct super_block *sb;
28704 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28705 + loff_t offset, u64 h_ino, unsigned int d_type)
28708 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28709 + struct aufs_rdu *rdu = arg->rdu;
28710 + struct au_rdu_ent ent;
28714 + au_fset_rdu(rdu->cookie.flags, CALLED);
28715 + len = au_rdu_len(nlen);
28716 + if (arg->ent.ul + len < arg->end) {
28718 + ent.bindex = rdu->cookie.bindex;
28719 + ent.type = d_type;
28721 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28722 + ent.type = DT_UNKNOWN;
28724 + /* unnecessary to support mmap_sem since this is a dir */
28726 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28728 + if (copy_to_user(arg->ent.e->name, name, nlen))
28730 + /* the terminating NULL */
28731 + if (__put_user(0, arg->ent.e->name + nlen))
28734 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28735 + arg->ent.ul += len;
28739 + au_fset_rdu(rdu->cookie.flags, FULL);
28741 + rdu->tail = arg->ent;
28745 + /* AuTraceErr(err); */
28749 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28753 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28755 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28756 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28758 + if (unlikely(offset != cookie->h_pos))
28764 + au_fclr_rdu(cookie->flags, CALLED);
28766 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28770 + && au_ftest_rdu(cookie->flags, CALLED)
28771 + && !au_ftest_rdu(cookie->flags, FULL));
28772 + cookie->h_pos = h_file->f_pos;
28779 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28782 + aufs_bindex_t bbot;
28783 + struct au_rdu_arg arg = {
28785 + .actor = au_rdu_fill
28788 + struct dentry *dentry;
28789 + struct inode *inode;
28790 + struct file *h_file;
28791 + struct au_rdu_cookie *cookie = &rdu->cookie;
28793 + /* VERIFY_WRITE */
28794 + err = !access_ok(rdu->ent.e, rdu->sz);
28795 + if (unlikely(err)) {
28801 + rdu->tail = rdu->ent;
28804 + arg.ent = rdu->ent;
28805 + arg.end = arg.ent.ul;
28806 + arg.end += rdu->sz;
28809 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28812 + err = security_file_permission(file, MAY_READ);
28814 + if (unlikely(err))
28817 + dentry = file->f_path.dentry;
28818 + inode = d_inode(dentry);
28819 + inode_lock_shared(inode);
28821 + arg.sb = inode->i_sb;
28822 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28823 + if (unlikely(err))
28825 + err = au_alive_dir(dentry);
28826 + if (unlikely(err))
28828 + /* todo: reval? */
28829 + fi_read_lock(file);
28832 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28833 + && cookie->generation != au_figen(file)))
28838 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28840 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28842 + bbot = au_fbtop(file);
28843 + if (cookie->bindex < bbot)
28844 + cookie->bindex = bbot;
28845 + bbot = au_fbbot_dir(file);
28846 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28847 + for (; !err && cookie->bindex <= bbot;
28848 + cookie->bindex++, cookie->h_pos = 0) {
28849 + h_file = au_hf_dir(file, cookie->bindex);
28853 + au_fclr_rdu(cookie->flags, FULL);
28854 + err = au_rdu_do(h_file, &arg);
28856 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28859 + AuDbg("rent %llu\n", rdu->rent);
28861 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28862 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28863 + au_fset_rdu(cookie->flags, CONT);
28864 + cookie->generation = au_figen(file);
28867 + ii_read_lock_child(inode);
28868 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28869 + ii_read_unlock(inode);
28872 + fi_read_unlock(file);
28874 + si_read_unlock(arg.sb);
28876 + inode_unlock_shared(inode);
28882 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28886 + unsigned long long nent;
28887 + union au_rdu_ent_ul *u;
28888 + struct au_rdu_ent ent;
28889 + struct super_block *sb;
28892 + nent = rdu->nent;
28894 + sb = file->f_path.dentry->d_sb;
28895 + si_read_lock(sb, AuLock_FLUSH);
28896 + while (nent-- > 0) {
28897 + /* unnecessary to support mmap_sem since this is a dir */
28898 + err = copy_from_user(&ent, u->e, sizeof(ent));
28900 + /* VERIFY_WRITE */
28901 + err = !access_ok(&u->e->ino, sizeof(ino));
28902 + if (unlikely(err)) {
28908 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28910 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28912 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28914 + if (unlikely(err)) {
28919 + err = __put_user(ino, &u->e->ino);
28920 + if (unlikely(err)) {
28925 + u->ul += au_rdu_len(ent.nlen);
28927 + si_read_unlock(sb);
28932 +/* ---------------------------------------------------------------------- */
28934 +static int au_rdu_verify(struct aufs_rdu *rdu)
28936 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28937 + "%llu, b%d, 0x%x, g%u}\n",
28938 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28940 + rdu->rent, rdu->shwh, rdu->full,
28941 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28942 + rdu->cookie.generation);
28944 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28948 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28952 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28955 + struct aufs_rdu rdu;
28956 + void __user *p = (void __user *)arg;
28958 + err = copy_from_user(&rdu, p, sizeof(rdu));
28959 + if (unlikely(err)) {
28964 + err = au_rdu_verify(&rdu);
28965 + if (unlikely(err))
28969 + case AUFS_CTL_RDU:
28970 + err = au_rdu(file, &rdu);
28971 + if (unlikely(err))
28974 + e = copy_to_user(p, &rdu, sizeof(rdu));
28975 + if (unlikely(e)) {
28980 + case AUFS_CTL_RDU_INO:
28981 + err = au_rdu_ino(file, &rdu);
28985 + /* err = -ENOTTY; */
28994 +#ifdef CONFIG_COMPAT
28995 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28998 + struct aufs_rdu rdu;
28999 + void __user *p = compat_ptr(arg);
29001 + /* todo: get_user()? */
29002 + err = copy_from_user(&rdu, p, sizeof(rdu));
29003 + if (unlikely(err)) {
29008 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29009 + err = au_rdu_verify(&rdu);
29010 + if (unlikely(err))
29014 + case AUFS_CTL_RDU:
29015 + err = au_rdu(file, &rdu);
29016 + if (unlikely(err))
29019 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29020 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29021 + e = copy_to_user(p, &rdu, sizeof(rdu));
29022 + if (unlikely(e)) {
29027 + case AUFS_CTL_RDU_INO:
29028 + err = au_rdu_ino(file, &rdu);
29032 + /* err = -ENOTTY; */
29041 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29042 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29043 +++ linux/fs/aufs/rwsem.h 2020-01-27 10:57:18.178871751 +0100
29045 +/* SPDX-License-Identifier: GPL-2.0 */
29047 + * Copyright (C) 2005-2020 Junjiro R. Okajima
29049 + * This program, aufs is free software; you can redistribute it and/or modify
29050 + * it under the terms of the GNU General Public License as published by
29051 + * the Free Software Foundation; either version 2 of the License, or
29052 + * (at your option) any later version.
29054 + * This program is distributed in the hope that it will be useful,
29055 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29056 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29057 + * GNU General Public License for more details.
29059 + * You should have received a copy of the GNU General Public License
29060 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29064 + * simple read-write semaphore wrappers
29067 +#ifndef __AUFS_RWSEM_H__
29068 +#define __AUFS_RWSEM_H__
29072 +#include "debug.h"
29074 +/* in the future, the name 'au_rwsem' will be totally gone */
29075 +#define au_rwsem rw_semaphore
29077 +/* to debug easier, do not make them inlined functions */
29078 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29079 +/* rwsem_is_locked() is unusable */
29080 +#define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \
29082 + && !lockdep_is_held_type(rw, 1))
29083 +#define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \
29085 + && !lockdep_is_held_type(rw, 0))
29086 +#define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \
29088 + && !lockdep_is_held(rw))
29089 +#define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \
29091 + && lockdep_is_held(rw))
29093 +#define au_rw_init(rw) init_rwsem(rw)
29095 +#define au_rw_init_wlock(rw) do { \
29096 + au_rw_init(rw); \
29097 + down_write(rw); \
29100 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29101 + au_rw_init(rw); \
29102 + down_write_nested(rw, lsc); \
29105 +#define au_rw_read_lock(rw) down_read(rw)
29106 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29107 +#define au_rw_read_unlock(rw) up_read(rw)
29108 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29109 +#define au_rw_write_lock(rw) down_write(rw)
29110 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29111 +#define au_rw_write_unlock(rw) up_write(rw)
29112 +/* why is not _nested version defined? */
29113 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29114 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29116 +#endif /* __KERNEL__ */
29117 +#endif /* __AUFS_RWSEM_H__ */
29118 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29119 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29120 +++ linux/fs/aufs/sbinfo.c 2020-01-27 10:57:18.178871751 +0100
29122 +// SPDX-License-Identifier: GPL-2.0
29124 + * Copyright (C) 2005-2020 Junjiro R. Okajima
29126 + * This program, aufs is free software; you can redistribute it and/or modify
29127 + * it under the terms of the GNU General Public License as published by
29128 + * the Free Software Foundation; either version 2 of the License, or
29129 + * (at your option) any later version.
29131 + * This program is distributed in the hope that it will be useful,
29132 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29133 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29134 + * GNU General Public License for more details.
29136 + * You should have received a copy of the GNU General Public License
29137 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29141 + * superblock private data
29144 +#include <linux/iversion.h>
29148 + * they are necessary regardless sysfs is disabled.
29150 +void au_si_free(struct kobject *kobj)
29153 + struct au_sbinfo *sbinfo;
29154 + char *locked __maybe_unused; /* debug only */
29156 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29157 + for (i = 0; i < AuPlink_NHASH; i++)
29158 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29159 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29161 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29162 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29163 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29164 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29166 + dbgaufs_si_fin(sbinfo);
29167 + au_rw_write_lock(&sbinfo->si_rwsem);
29168 + au_br_free(sbinfo);
29169 + au_rw_write_unlock(&sbinfo->si_rwsem);
29171 + au_kfree_try_rcu(sbinfo->si_branch);
29172 + mutex_destroy(&sbinfo->si_xib_mtx);
29173 + AuRwDestroy(&sbinfo->si_rwsem);
29175 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29176 + /* si_nfiles is waited too */
29177 + au_kfree_rcu(sbinfo);
29180 +int au_si_alloc(struct super_block *sb)
29183 + struct au_sbinfo *sbinfo;
29186 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29187 + if (unlikely(!sbinfo))
29190 + /* will be reallocated separately */
29191 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29192 + if (unlikely(!sbinfo->si_branch))
29195 + err = sysaufs_si_init(sbinfo);
29197 + dbgaufs_si_null(sbinfo);
29198 + err = dbgaufs_si_init(sbinfo);
29199 + if (unlikely(err))
29200 + kobject_put(&sbinfo->si_kobj);
29202 + if (unlikely(err))
29205 + au_nwt_init(&sbinfo->si_nowait);
29206 + au_rw_init_wlock(&sbinfo->si_rwsem);
29208 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29209 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29211 + sbinfo->si_bbot = -1;
29212 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29214 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29215 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29216 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29217 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29219 + au_fhsm_init(sbinfo);
29221 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29223 + sbinfo->si_xino_jiffy = jiffies;
29224 + sbinfo->si_xino_expire
29225 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29226 + mutex_init(&sbinfo->si_xib_mtx);
29227 + /* leave si_xib_last_pindex and si_xib_next_bit */
29229 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29231 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29232 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29233 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29234 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29236 + for (i = 0; i < AuPlink_NHASH; i++)
29237 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29238 + init_waitqueue_head(&sbinfo->si_plink_wq);
29239 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29241 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29243 + /* with getattr by default */
29244 + sbinfo->si_iop_array = aufs_iop;
29246 + /* leave other members for sysaufs and si_mnt. */
29247 + sbinfo->si_sb = sb;
29248 + sb->s_fs_info = sbinfo;
29250 + return 0; /* success */
29253 + au_kfree_try_rcu(sbinfo->si_branch);
29255 + au_kfree_rcu(sbinfo);
29260 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29263 + struct au_branch **brp;
29265 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29268 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29269 + if (unlikely(!sz))
29270 + sz = sizeof(*brp);
29271 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29274 + sbinfo->si_branch = brp;
29281 +/* ---------------------------------------------------------------------- */
29283 +unsigned int au_sigen_inc(struct super_block *sb)
29285 + unsigned int gen;
29286 + struct inode *inode;
29288 + SiMustWriteLock(sb);
29290 + gen = ++au_sbi(sb)->si_generation;
29291 + au_update_digen(sb->s_root);
29292 + inode = d_inode(sb->s_root);
29293 + au_update_iigen(inode, /*half*/0);
29294 + inode_inc_iversion(inode);
29298 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29300 + aufs_bindex_t br_id;
29302 + struct au_sbinfo *sbinfo;
29304 + SiMustWriteLock(sb);
29306 + sbinfo = au_sbi(sb);
29307 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29308 + br_id = ++sbinfo->si_last_br_id;
29309 + AuDebugOn(br_id < 0);
29310 + if (br_id && au_br_index(sb, br_id) < 0)
29317 +/* ---------------------------------------------------------------------- */
29319 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29320 +int si_read_lock(struct super_block *sb, int flags)
29325 + if (au_ftest_lock(flags, FLUSH))
29326 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29328 + si_noflush_read_lock(sb);
29329 + err = au_plink_maint(sb, flags);
29330 + if (unlikely(err))
29331 + si_read_unlock(sb);
29336 +int si_write_lock(struct super_block *sb, int flags)
29340 + if (au_ftest_lock(flags, FLUSH))
29341 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29343 + si_noflush_write_lock(sb);
29344 + err = au_plink_maint(sb, flags);
29345 + if (unlikely(err))
29346 + si_write_unlock(sb);
29351 +/* dentry and super_block lock. call at entry point */
29352 +int aufs_read_lock(struct dentry *dentry, int flags)
29355 + struct super_block *sb;
29357 + sb = dentry->d_sb;
29358 + err = si_read_lock(sb, flags);
29359 + if (unlikely(err))
29362 + if (au_ftest_lock(flags, DW))
29363 + di_write_lock_child(dentry);
29365 + di_read_lock_child(dentry, flags);
29367 + if (au_ftest_lock(flags, GEN)) {
29368 + err = au_digen_test(dentry, au_sigen(sb));
29369 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29370 + AuDebugOn(!err && au_dbrange_test(dentry));
29372 + err = au_dbrange_test(dentry);
29373 + if (unlikely(err))
29374 + aufs_read_unlock(dentry, flags);
29381 +void aufs_read_unlock(struct dentry *dentry, int flags)
29383 + if (au_ftest_lock(flags, DW))
29384 + di_write_unlock(dentry);
29386 + di_read_unlock(dentry, flags);
29387 + si_read_unlock(dentry->d_sb);
29390 +void aufs_write_lock(struct dentry *dentry)
29392 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29393 + di_write_lock_child(dentry);
29396 +void aufs_write_unlock(struct dentry *dentry)
29398 + di_write_unlock(dentry);
29399 + si_write_unlock(dentry->d_sb);
29402 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29405 + unsigned int sigen;
29406 + struct super_block *sb;
29409 + err = si_read_lock(sb, flags);
29410 + if (unlikely(err))
29413 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29415 + if (au_ftest_lock(flags, GEN)) {
29416 + sigen = au_sigen(sb);
29417 + err = au_digen_test(d1, sigen);
29418 + AuDebugOn(!err && au_dbrange_test(d1));
29420 + err = au_digen_test(d2, sigen);
29421 + AuDebugOn(!err && au_dbrange_test(d2));
29423 + if (unlikely(err))
29424 + aufs_read_and_write_unlock2(d1, d2);
29431 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29433 + di_write_unlock2(d1, d2);
29434 + si_read_unlock(d1->d_sb);
29436 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29437 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29438 +++ linux/fs/aufs/super.c 2020-01-27 10:57:18.178871751 +0100
29440 +// SPDX-License-Identifier: GPL-2.0
29442 + * Copyright (C) 2005-2020 Junjiro R. Okajima
29444 + * This program, aufs is free software; you can redistribute it and/or modify
29445 + * it under the terms of the GNU General Public License as published by
29446 + * the Free Software Foundation; either version 2 of the License, or
29447 + * (at your option) any later version.
29449 + * This program is distributed in the hope that it will be useful,
29450 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29451 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29452 + * GNU General Public License for more details.
29454 + * You should have received a copy of the GNU General Public License
29455 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29459 + * mount and super_block operations
29462 +#include <linux/iversion.h>
29463 +#include <linux/mm.h>
29464 +#include <linux/seq_file.h>
29465 +#include <linux/statfs.h>
29466 +#include <linux/vmalloc.h>
29470 + * super_operations
29472 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29474 + struct au_icntnr *c;
29476 + c = au_cache_alloc_icntnr();
29478 + au_icntnr_init(c);
29479 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29480 + c->iinfo.ii_hinode = NULL;
29481 + return &c->vfs_inode;
29486 +static void aufs_destroy_inode(struct inode *inode)
29488 + if (!au_is_bad_inode(inode))
29489 + au_iinfo_fin(inode);
29492 +static void aufs_free_inode(struct inode *inode)
29494 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29497 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29499 + struct inode *inode;
29502 + inode = iget_locked(sb, ino);
29503 + if (unlikely(!inode)) {
29504 + inode = ERR_PTR(-ENOMEM);
29507 + if (!(inode->i_state & I_NEW))
29510 + err = au_xigen_new(inode);
29512 + err = au_iinfo_init(inode);
29514 + inode_inc_iversion(inode);
29516 + iget_failed(inode);
29517 + inode = ERR_PTR(err);
29521 + /* never return NULL */
29522 + AuDebugOn(!inode);
29523 + AuTraceErrPtr(inode);
29527 +/* lock free root dinfo */
29528 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29531 + aufs_bindex_t bindex, bbot;
29532 + struct path path;
29533 + struct au_hdentry *hdp;
29534 + struct au_branch *br;
29535 + au_br_perm_str_t perm;
29538 + bbot = au_sbbot(sb);
29540 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29541 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29542 + br = au_sbr(sb, bindex);
29543 + path.mnt = au_br_mnt(br);
29544 + path.dentry = hdp->hd_dentry;
29545 + err = au_seq_path(seq, &path);
29547 + au_optstr_br_perm(&perm, br->br_perm);
29548 + seq_printf(seq, "=%s", perm.a);
29549 + if (bindex != bbot)
29550 + seq_putc(seq, ':');
29553 + if (unlikely(err || seq_has_overflowed(seq)))
29559 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29560 + const char *append)
29565 + while (*pat != ':')
29568 + strcpy(p, append);
29569 + AuDebugOn(strlen(fmt) >= len);
29572 +static void au_show_wbr_create(struct seq_file *m, int v,
29573 + struct au_sbinfo *sbinfo)
29577 + struct au_wbr_mfs *mfs;
29579 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29581 + seq_puts(m, ",create=");
29582 + pat = au_optstr_wbr_create(v);
29583 + mfs = &sbinfo->si_wbr_mfs;
29585 + case AuWbrCreate_TDP:
29586 + case AuWbrCreate_RR:
29587 + case AuWbrCreate_MFS:
29588 + case AuWbrCreate_PMFS:
29589 + seq_puts(m, pat);
29591 + case AuWbrCreate_MFSRR:
29592 + case AuWbrCreate_TDMFS:
29593 + case AuWbrCreate_PMFSRR:
29594 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29595 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29597 + case AuWbrCreate_MFSV:
29598 + case AuWbrCreate_PMFSV:
29599 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29600 + seq_printf(m, fmt,
29601 + jiffies_to_msecs(mfs->mfs_expire)
29604 + case AuWbrCreate_MFSRRV:
29605 + case AuWbrCreate_TDMFSV:
29606 + case AuWbrCreate_PMFSRRV:
29607 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29608 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29609 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29616 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29618 +#ifdef CONFIG_SYSFS
29622 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29623 + aufs_bindex_t bindex, brid;
29624 + struct qstr *name;
29626 + struct dentry *d, *h_root;
29627 + struct au_branch *br;
29629 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29632 + f = au_sbi(sb)->si_xib;
29636 + /* stop printing the default xino path on the first writable branch */
29638 + bindex = au_xi_root(sb, f->f_path.dentry);
29639 + if (bindex >= 0) {
29640 + br = au_sbr_sb(sb, bindex);
29641 + h_root = au_br_dentry(br);
29644 + d = f->f_path.dentry;
29645 + name = &d->d_name;
29646 + /* safe ->d_parent because the file is unlinked */
29647 + if (d->d_parent == h_root
29648 + && name->len == len
29649 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29652 + seq_puts(seq, ",xino=");
29653 + err = au_xino_path(seq, f);
29660 +/* seq_file will re-call me in case of too long string */
29661 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29664 + unsigned int mnt_flags, v;
29665 + struct super_block *sb;
29666 + struct au_sbinfo *sbinfo;
29668 +#define AuBool(name, str) do { \
29669 + v = au_opt_test(mnt_flags, name); \
29670 + if (v != au_opt_test(AuOpt_Def, name)) \
29671 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29674 +#define AuStr(name, str) do { \
29675 + v = mnt_flags & AuOptMask_##name; \
29676 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29677 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29680 +#define AuUInt(name, str, val) do { \
29681 + if (val != AUFS_##name##_DEF) \
29682 + seq_printf(m, "," #str "=%u", val); \
29685 + sb = dentry->d_sb;
29686 + if (sb->s_flags & SB_POSIXACL)
29687 + seq_puts(m, ",acl");
29688 +#if 0 /* reserved for future use */
29689 + if (sb->s_flags & SB_I_VERSION)
29690 + seq_puts(m, ",i_version");
29693 + /* lock free root dinfo */
29694 + si_noflush_read_lock(sb);
29695 + sbinfo = au_sbi(sb);
29696 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29698 + mnt_flags = au_mntflags(sb);
29699 + if (au_opt_test(mnt_flags, XINO)) {
29700 + err = au_show_xino(m, sb);
29701 + if (unlikely(err))
29704 + seq_puts(m, ",noxino");
29706 + AuBool(TRUNC_XINO, trunc_xino);
29707 + AuStr(UDBA, udba);
29708 + AuBool(SHWH, shwh);
29709 + AuBool(PLINK, plink);
29710 + AuBool(DIO, dio);
29711 + AuBool(DIRPERM1, dirperm1);
29713 + v = sbinfo->si_wbr_create;
29714 + if (v != AuWbrCreate_Def)
29715 + au_show_wbr_create(m, v, sbinfo);
29717 + v = sbinfo->si_wbr_copyup;
29718 + if (v != AuWbrCopyup_Def)
29719 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29721 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29722 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29723 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29725 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29727 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29728 + AuUInt(RDCACHE, rdcache, v);
29730 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29731 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29733 + au_fhsm_show(m, sbinfo);
29735 + AuBool(DIRREN, dirren);
29736 + AuBool(SUM, sum);
29737 + /* AuBool(SUM_W, wsum); */
29738 + AuBool(WARN_PERM, warn_perm);
29739 + AuBool(VERBOSE, verbose);
29742 + /* be sure to print "br:" last */
29743 + if (!sysaufs_brs) {
29744 + seq_puts(m, ",br:");
29745 + au_show_brs(m, sb);
29747 + si_read_unlock(sb);
29755 +/* ---------------------------------------------------------------------- */
29757 +/* sum mode which returns the summation for statfs(2) */
29759 +static u64 au_add_till_max(u64 a, u64 b)
29767 + return ULLONG_MAX;
29770 +static u64 au_mul_till_max(u64 a, long mul)
29778 + return ULLONG_MAX;
29781 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29784 + long bsize, factor;
29785 + u64 blocks, bfree, bavail, files, ffree;
29786 + aufs_bindex_t bbot, bindex, i;
29787 + unsigned char shared;
29788 + struct path h_path;
29789 + struct super_block *h_sb;
29792 + bsize = LONG_MAX;
29798 + bbot = au_sbbot(sb);
29799 + for (bindex = 0; bindex <= bbot; bindex++) {
29800 + h_path.mnt = au_sbr_mnt(sb, bindex);
29801 + h_sb = h_path.mnt->mnt_sb;
29803 + for (i = 0; !shared && i < bindex; i++)
29804 + shared = (au_sbr_sb(sb, i) == h_sb);
29808 + /* sb->s_root for NFS is unreliable */
29809 + h_path.dentry = h_path.mnt->mnt_root;
29810 + err = vfs_statfs(&h_path, buf);
29811 + if (unlikely(err))
29814 + if (bsize > buf->f_bsize) {
29816 + * we will reduce bsize, so we have to expand blocks
29817 + * etc. to match them again
29819 + factor = (bsize / buf->f_bsize);
29820 + blocks = au_mul_till_max(blocks, factor);
29821 + bfree = au_mul_till_max(bfree, factor);
29822 + bavail = au_mul_till_max(bavail, factor);
29823 + bsize = buf->f_bsize;
29826 + factor = (buf->f_bsize / bsize);
29827 + blocks = au_add_till_max(blocks,
29828 + au_mul_till_max(buf->f_blocks, factor));
29829 + bfree = au_add_till_max(bfree,
29830 + au_mul_till_max(buf->f_bfree, factor));
29831 + bavail = au_add_till_max(bavail,
29832 + au_mul_till_max(buf->f_bavail, factor));
29833 + files = au_add_till_max(files, buf->f_files);
29834 + ffree = au_add_till_max(ffree, buf->f_ffree);
29837 + buf->f_bsize = bsize;
29838 + buf->f_blocks = blocks;
29839 + buf->f_bfree = bfree;
29840 + buf->f_bavail = bavail;
29841 + buf->f_files = files;
29842 + buf->f_ffree = ffree;
29843 + buf->f_frsize = 0;
29849 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29852 + struct path h_path;
29853 + struct super_block *sb;
29855 + /* lock free root dinfo */
29856 + sb = dentry->d_sb;
29857 + si_noflush_read_lock(sb);
29858 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29859 + /* sb->s_root for NFS is unreliable */
29860 + h_path.mnt = au_sbr_mnt(sb, 0);
29861 + h_path.dentry = h_path.mnt->mnt_root;
29862 + err = vfs_statfs(&h_path, buf);
29864 + err = au_statfs_sum(sb, buf);
29865 + si_read_unlock(sb);
29868 + buf->f_type = AUFS_SUPER_MAGIC;
29869 + buf->f_namelen = AUFS_MAX_NAMELEN;
29870 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29872 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29877 +/* ---------------------------------------------------------------------- */
29879 +static int aufs_sync_fs(struct super_block *sb, int wait)
29882 + aufs_bindex_t bbot, bindex;
29883 + struct au_branch *br;
29884 + struct super_block *h_sb;
29887 + si_noflush_read_lock(sb);
29888 + bbot = au_sbbot(sb);
29889 + for (bindex = 0; bindex <= bbot; bindex++) {
29890 + br = au_sbr(sb, bindex);
29891 + if (!au_br_writable(br->br_perm))
29894 + h_sb = au_sbr_sb(sb, bindex);
29895 + e = vfsub_sync_filesystem(h_sb, wait);
29896 + if (unlikely(e && !err))
29898 + /* go on even if an error happens */
29900 + si_read_unlock(sb);
29905 +/* ---------------------------------------------------------------------- */
29907 +/* final actions when unmounting a file system */
29908 +static void aufs_put_super(struct super_block *sb)
29910 + struct au_sbinfo *sbinfo;
29912 + sbinfo = au_sbi(sb);
29914 + kobject_put(&sbinfo->si_kobj);
29917 +/* ---------------------------------------------------------------------- */
29919 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29920 + struct super_block *sb, void *arg)
29923 + unsigned long long n, sz;
29930 + if (*hint > ULLONG_MAX / sizeof(array)) {
29931 + array = ERR_PTR(-EMFILE);
29932 + pr_err("hint %llu\n", *hint);
29936 + sz = sizeof(array) * *hint;
29937 + array = kzalloc(sz, GFP_NOFS);
29938 + if (unlikely(!array))
29939 + array = vzalloc(sz);
29940 + if (unlikely(!array)) {
29941 + array = ERR_PTR(-ENOMEM);
29945 + n = cb(sb, array, *hint, arg);
29946 + AuDebugOn(n > *hint);
29953 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29954 + unsigned long long max __maybe_unused,
29957 + unsigned long long n;
29958 + struct inode **p, *inode;
29959 + struct list_head *head;
29964 + spin_lock(&sb->s_inode_list_lock);
29965 + list_for_each_entry(inode, head, i_sb_list) {
29966 + if (!au_is_bad_inode(inode)
29967 + && au_ii(inode)->ii_btop >= 0) {
29968 + spin_lock(&inode->i_lock);
29969 + if (atomic_read(&inode->i_count)) {
29973 + AuDebugOn(n > max);
29975 + spin_unlock(&inode->i_lock);
29978 + spin_unlock(&sb->s_inode_list_lock);
29983 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
29985 + struct au_sbinfo *sbi;
29987 + sbi = au_sbi(sb);
29988 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
29989 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
29992 +void au_iarray_free(struct inode **a, unsigned long long max)
29994 + unsigned long long ull;
29996 + for (ull = 0; ull < max; ull++)
30001 +/* ---------------------------------------------------------------------- */
30004 + * refresh dentry and inode at remount time.
30006 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30007 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30008 + struct dentry *parent)
30012 + di_write_lock_child(dentry);
30013 + di_read_lock_parent(parent, AuLock_IR);
30014 + err = au_refresh_dentry(dentry, parent);
30015 + if (!err && dir_flags)
30016 + au_hn_reset(d_inode(dentry), dir_flags);
30017 + di_read_unlock(parent, AuLock_IR);
30018 + di_write_unlock(dentry);
30023 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30024 + struct au_sbinfo *sbinfo,
30025 + const unsigned int dir_flags, unsigned int do_idop)
30028 + struct dentry *parent;
30031 + parent = dget_parent(dentry);
30032 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30033 + if (d_really_is_positive(dentry)) {
30034 + if (!d_is_dir(dentry))
30035 + err = au_do_refresh(dentry, /*dir_flags*/0,
30038 + err = au_do_refresh(dentry, dir_flags, parent);
30039 + if (unlikely(err))
30040 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30043 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30044 + AuDbgDentry(dentry);
30050 + au_refresh_dop(dentry, /*force_reval*/0);
30052 + au_refresh_dop(dentry, /*force_reval*/1);
30058 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30060 + int err, i, j, ndentry, e;
30061 + unsigned int sigen;
30062 + struct au_dcsub_pages dpages;
30063 + struct au_dpage *dpage;
30064 + struct dentry **dentries, *d;
30065 + struct au_sbinfo *sbinfo;
30066 + struct dentry *root = sb->s_root;
30067 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30070 + au_refresh_dop(root, /*force_reval*/0);
30072 + err = au_dpages_init(&dpages, GFP_NOFS);
30073 + if (unlikely(err))
30075 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30076 + if (unlikely(err))
30079 + sigen = au_sigen(sb);
30080 + sbinfo = au_sbi(sb);
30081 + for (i = 0; i < dpages.ndpage; i++) {
30082 + dpage = dpages.dpages + i;
30083 + dentries = dpage->dentries;
30084 + ndentry = dpage->ndentry;
30085 + for (j = 0; j < ndentry; j++) {
30087 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30089 + if (unlikely(e && !err))
30091 + /* go on even err */
30096 + au_dpages_free(&dpages);
30101 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30104 + unsigned int sigen;
30105 + unsigned long long max, ull;
30106 + struct inode *inode, **array;
30108 + array = au_iarray_alloc(sb, &max);
30109 + err = PTR_ERR(array);
30110 + if (IS_ERR(array))
30114 + sigen = au_sigen(sb);
30115 + for (ull = 0; ull < max; ull++) {
30116 + inode = array[ull];
30117 + if (unlikely(!inode))
30121 + ii_write_lock_child(inode);
30122 + if (au_iigen(inode, NULL) != sigen) {
30123 + e = au_refresh_hinode_self(inode);
30124 + if (unlikely(e)) {
30125 + au_refresh_iop(inode, /*force_getattr*/1);
30126 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30129 + /* go on even if err */
30132 + if (!e && do_idop)
30133 + au_refresh_iop(inode, /*force_getattr*/0);
30134 + ii_write_unlock(inode);
30137 + au_iarray_free(array, max);
30143 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30146 + unsigned int udba;
30147 + aufs_bindex_t bindex, bbot;
30148 + struct dentry *root;
30149 + struct inode *inode;
30150 + struct au_branch *br;
30151 + struct au_sbinfo *sbi;
30153 + au_sigen_inc(sb);
30154 + sbi = au_sbi(sb);
30155 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30157 + root = sb->s_root;
30158 + DiMustNoWaiters(root);
30159 + inode = d_inode(root);
30160 + IiMustNoWaiters(inode);
30162 + udba = au_opt_udba(sb);
30163 + bbot = au_sbbot(sb);
30164 + for (bindex = 0; bindex <= bbot; bindex++) {
30165 + br = au_sbr(sb, bindex);
30166 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30167 + if (unlikely(err))
30168 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30170 + /* go on even if err */
30172 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30175 + if (au_ftest_si(sbi, NO_DREVAL)) {
30176 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30177 + sb->s_d_op = &aufs_dop_noreval;
30178 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30179 + sbi->si_iop_array = aufs_iop_nogetattr;
30181 + AuDebugOn(sb->s_d_op == &aufs_dop);
30182 + sb->s_d_op = &aufs_dop;
30183 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30184 + sbi->si_iop_array = aufs_iop;
30186 + pr_info("reset to %ps and %ps\n",
30187 + sb->s_d_op, sbi->si_iop_array);
30190 + di_write_unlock(root);
30191 + err = au_refresh_d(sb, do_idop);
30192 + e = au_refresh_i(sb, do_idop);
30193 + if (unlikely(e && !err))
30195 + /* aufs_write_lock() calls ..._child() */
30196 + di_write_lock_child(root);
30198 + au_cpup_attr_all(inode, /*force*/1);
30200 + if (unlikely(err))
30201 + AuIOErr("refresh failed, ignored, %d\n", err);
30204 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30205 +static int cvt_err(int err)
30219 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30222 + unsigned int mntflags;
30223 + struct au_opts opts = {
30226 + struct dentry *root;
30227 + struct inode *inode;
30228 + struct au_sbinfo *sbinfo;
30231 + root = sb->s_root;
30232 + if (!data || !*data) {
30233 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30235 + di_write_lock_child(root);
30236 + err = au_opts_verify(sb, *flags, /*pending*/0);
30237 + aufs_write_unlock(root);
30243 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30244 + if (unlikely(!opts.opt))
30246 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30247 + opts.flags = AuOpts_REMOUNT;
30248 + opts.sb_flags = *flags;
30250 + /* parse it before aufs lock */
30251 + err = au_opts_parse(sb, data, &opts);
30252 + if (unlikely(err))
30255 + sbinfo = au_sbi(sb);
30256 + inode = d_inode(root);
30257 + inode_lock(inode);
30258 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30259 + if (unlikely(err))
30261 + di_write_lock_child(root);
30263 + /* au_opts_remount() may return an error */
30264 + err = au_opts_remount(sb, &opts);
30265 + au_opts_free(&opts);
30267 + if (au_ftest_opts(opts.flags, REFRESH))
30268 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30270 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30271 + mntflags = au_mntflags(sb);
30272 + do_dx = !!au_opt_test(mntflags, DIO);
30273 + au_dy_arefresh(do_dx);
30276 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30277 + aufs_write_unlock(root);
30280 + inode_unlock(inode);
30282 + free_page((unsigned long)opts.opt);
30284 + err = cvt_err(err);
30289 +static const struct super_operations aufs_sop = {
30290 + .alloc_inode = aufs_alloc_inode,
30291 + .destroy_inode = aufs_destroy_inode,
30292 + .free_inode = aufs_free_inode,
30293 + /* always deleting, no clearing */
30294 + .drop_inode = generic_delete_inode,
30295 + .show_options = aufs_show_options,
30296 + .statfs = aufs_statfs,
30297 + .put_super = aufs_put_super,
30298 + .sync_fs = aufs_sync_fs,
30299 + .remount_fs = aufs_remount_fs
30302 +/* ---------------------------------------------------------------------- */
30304 +static int alloc_root(struct super_block *sb)
30307 + struct inode *inode;
30308 + struct dentry *root;
30311 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30312 + err = PTR_ERR(inode);
30313 + if (IS_ERR(inode))
30316 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30317 + inode->i_fop = &aufs_dir_fop;
30318 + inode->i_mode = S_IFDIR;
30319 + set_nlink(inode, 2);
30320 + unlock_new_inode(inode);
30322 + root = d_make_root(inode);
30323 + if (unlikely(!root))
30325 + err = PTR_ERR(root);
30326 + if (IS_ERR(root))
30329 + err = au_di_init(root);
30331 + sb->s_root = root;
30332 + return 0; /* success */
30340 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30341 + int silent __maybe_unused)
30344 + struct au_opts opts = {
30347 + struct au_sbinfo *sbinfo;
30348 + struct dentry *root;
30349 + struct inode *inode;
30350 + char *arg = raw_data;
30352 + if (unlikely(!arg || !*arg)) {
30354 + pr_err("no arg\n");
30359 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30360 + if (unlikely(!opts.opt))
30362 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30363 + opts.sb_flags = sb->s_flags;
30365 + err = au_si_alloc(sb);
30366 + if (unlikely(err))
30368 + sbinfo = au_sbi(sb);
30370 + /* all timestamps always follow the ones on the branch */
30371 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30372 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30373 + sb->s_op = &aufs_sop;
30374 + sb->s_d_op = &aufs_dop;
30375 + sb->s_magic = AUFS_SUPER_MAGIC;
30376 + sb->s_maxbytes = 0;
30377 + sb->s_stack_depth = 1;
30378 + au_export_init(sb);
30379 + au_xattr_init(sb);
30381 + err = alloc_root(sb);
30382 + if (unlikely(err)) {
30383 + si_write_unlock(sb);
30386 + root = sb->s_root;
30387 + inode = d_inode(root);
30390 + * actually we can parse options regardless aufs lock here.
30391 + * but at remount time, parsing must be done before aufs lock.
30392 + * so we follow the same rule.
30394 + ii_write_lock_parent(inode);
30395 + aufs_write_unlock(root);
30396 + err = au_opts_parse(sb, arg, &opts);
30397 + if (unlikely(err))
30400 + /* lock vfs_inode first, then aufs. */
30401 + inode_lock(inode);
30402 + aufs_write_lock(root);
30403 + err = au_opts_mount(sb, &opts);
30404 + au_opts_free(&opts);
30405 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30406 + sb->s_d_op = &aufs_dop_noreval;
30407 + pr_info("%ps\n", sb->s_d_op);
30408 + au_refresh_dop(root, /*force_reval*/0);
30409 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30410 + au_refresh_iop(inode, /*force_getattr*/0);
30412 + aufs_write_unlock(root);
30413 + inode_unlock(inode);
30415 + goto out_opts; /* success */
30419 + sb->s_root = NULL;
30421 + kobject_put(&sbinfo->si_kobj);
30422 + sb->s_fs_info = NULL;
30424 + free_page((unsigned long)opts.opt);
30427 + err = cvt_err(err);
30432 +/* ---------------------------------------------------------------------- */
30434 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30435 + const char *dev_name __maybe_unused,
30438 + struct dentry *root;
30440 + /* all timestamps always follow the ones on the branch */
30441 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30442 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30443 + if (IS_ERR(root))
30446 + au_sbilist_add(root->d_sb);
30452 +static void aufs_kill_sb(struct super_block *sb)
30454 + struct au_sbinfo *sbinfo;
30456 + sbinfo = au_sbi(sb);
30458 + au_sbilist_del(sb);
30459 + aufs_write_lock(sb->s_root);
30461 + if (sbinfo->si_wbr_create_ops->fin)
30462 + sbinfo->si_wbr_create_ops->fin(sb);
30463 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30464 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30465 + au_remount_refresh(sb, /*do_idop*/0);
30467 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30468 + au_plink_put(sb, /*verbose*/1);
30470 + au_dr_opt_flush(sb);
30471 + sbinfo->si_sb = NULL;
30472 + aufs_write_unlock(sb->s_root);
30473 + au_nwt_flush(&sbinfo->si_nowait);
30475 + kill_anon_super(sb);
30478 +struct file_system_type aufs_fs_type = {
30479 + .name = AUFS_FSTYPE,
30480 + /* a race between rename and others */
30481 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30482 + .mount = aufs_mount,
30483 + .kill_sb = aufs_kill_sb,
30484 + /* no need to __module_get() and module_put(). */
30485 + .owner = THIS_MODULE,
30487 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30488 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30489 +++ linux/fs/aufs/super.h 2020-01-27 10:57:18.178871751 +0100
30491 +/* SPDX-License-Identifier: GPL-2.0 */
30493 + * Copyright (C) 2005-2020 Junjiro R. Okajima
30495 + * This program, aufs is free software; you can redistribute it and/or modify
30496 + * it under the terms of the GNU General Public License as published by
30497 + * the Free Software Foundation; either version 2 of the License, or
30498 + * (at your option) any later version.
30500 + * This program is distributed in the hope that it will be useful,
30501 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30502 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30503 + * GNU General Public License for more details.
30505 + * You should have received a copy of the GNU General Public License
30506 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30510 + * super_block operations
30513 +#ifndef __AUFS_SUPER_H__
30514 +#define __AUFS_SUPER_H__
30518 +#include <linux/fs.h>
30519 +#include <linux/kobject.h>
30522 +#include "rwsem.h"
30525 +/* policies to select one among multiple writable branches */
30526 +struct au_wbr_copyup_operations {
30527 + int (*copyup)(struct dentry *dentry);
30530 +#define AuWbr_DIR 1 /* target is a dir */
30531 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30533 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30534 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30535 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30537 +struct au_wbr_create_operations {
30538 + int (*create)(struct dentry *dentry, unsigned int flags);
30539 + int (*init)(struct super_block *sb);
30540 + int (*fin)(struct super_block *sb);
30543 +struct au_wbr_mfs {
30544 + struct mutex mfs_lock; /* protect this structure */
30545 + unsigned long mfs_jiffy;
30546 + unsigned long mfs_expire;
30547 + aufs_bindex_t mfs_bindex;
30549 + unsigned long long mfsrr_bytes;
30550 + unsigned long long mfsrr_watermark;
30553 +#define AuPlink_NHASH 100
30554 +static inline int au_plink_hash(ino_t ino)
30556 + return ino % AuPlink_NHASH;
30559 +/* File-based Hierarchical Storage Management */
30561 +#ifdef CONFIG_AUFS_FHSM
30562 + /* allow only one process who can receive the notification */
30563 + spinlock_t fhsm_spin;
30565 + wait_queue_head_t fhsm_wqh;
30566 + atomic_t fhsm_readable;
30568 + /* these are protected by si_rwsem */
30569 + unsigned long fhsm_expire;
30570 + aufs_bindex_t fhsm_bottom;
30575 +struct au_sbinfo {
30576 + /* nowait tasks in the system-wide workqueue */
30577 + struct au_nowait_tasks si_nowait;
30580 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30581 + * rwsem for au_sbinfo is necessary.
30583 + struct au_rwsem si_rwsem;
30586 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30589 + au_lcnt_t si_ninodes, si_nfiles;
30591 + /* branch management */
30592 + unsigned int si_generation;
30594 + /* see AuSi_ flags */
30595 + unsigned char au_si_status;
30597 + aufs_bindex_t si_bbot;
30599 + /* dirty trick to keep br_id plus */
30600 + unsigned int si_last_br_id :
30601 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30602 + struct au_branch **si_branch;
30604 + /* policy to select a writable branch */
30605 + unsigned char si_wbr_copyup;
30606 + unsigned char si_wbr_create;
30607 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30608 + struct au_wbr_create_operations *si_wbr_create_ops;
30610 + /* round robin */
30611 + atomic_t si_wbr_rr_next;
30613 + /* most free space */
30614 + struct au_wbr_mfs si_wbr_mfs;
30616 + /* File-based Hierarchical Storage Management */
30617 + struct au_fhsm si_fhsm;
30619 + /* mount flags */
30620 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30621 + unsigned int si_mntflags;
30623 + /* external inode number (bitmap and translation table) */
30624 + vfs_readf_t si_xread;
30625 + vfs_writef_t si_xwrite;
30626 + loff_t si_ximaxent; /* max entries in a xino */
30628 + struct file *si_xib;
30629 + struct mutex si_xib_mtx; /* protect xib members */
30630 + unsigned long *si_xib_buf;
30631 + unsigned long si_xib_last_pindex;
30632 + int si_xib_next_bit;
30634 + unsigned long si_xino_jiffy;
30635 + unsigned long si_xino_expire;
30636 + /* reserved for future use */
30637 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30639 +#ifdef CONFIG_AUFS_EXPORT
30640 + /* i_generation */
30641 + /* todo: make xigen file an array to support many inode numbers */
30642 + struct file *si_xigen;
30643 + atomic_t si_xigen_next;
30646 + /* dirty trick to support atomic_open */
30647 + struct hlist_bl_head si_aopen;
30649 + /* vdir parameters */
30650 + unsigned long si_rdcache; /* max cache time in jiffies */
30651 + unsigned int si_rdblk; /* deblk size */
30652 + unsigned int si_rdhash; /* hash size */
30655 + * If the number of whiteouts are larger than si_dirwh, leave all of
30656 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30657 + * future fsck.aufs or kernel thread will remove them later.
30658 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30660 + unsigned int si_dirwh;
30662 + /* pseudo_link list */
30663 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30664 + wait_queue_head_t si_plink_wq;
30665 + spinlock_t si_plink_maint_lock;
30666 + pid_t si_plink_maint_pid;
30669 + struct hlist_bl_head si_files;
30671 + /* with/without getattr, brother of sb->s_d_op */
30672 + const struct inode_operations *si_iop_array;
30675 + * sysfs and lifetime management.
30676 + * this is not a small structure and it may be a waste of memory in case
30677 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30678 + * but using sysfs is majority.
30680 + struct kobject si_kobj;
30681 +#ifdef CONFIG_DEBUG_FS
30682 + struct dentry *si_dbgaufs;
30683 + struct dentry *si_dbgaufs_plink;
30684 + struct dentry *si_dbgaufs_xib;
30685 +#ifdef CONFIG_AUFS_EXPORT
30686 + struct dentry *si_dbgaufs_xigen;
30690 +#ifdef CONFIG_AUFS_SBILIST
30691 + struct hlist_bl_node si_list;
30694 + /* dirty, necessary for unmounting, sysfs and sysrq */
30695 + struct super_block *si_sb;
30698 +/* sbinfo status flags */
30700 + * set true when refresh_dirs() failed at remount time.
30701 + * then try refreshing dirs at access time again.
30702 + * if it is false, refreshing dirs at access time is unnecessary
30704 +#define AuSi_FAILED_REFRESH_DIR 1
30705 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30706 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30708 +#ifndef CONFIG_AUFS_FHSM
30710 +#define AuSi_FHSM 0
30713 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30714 + unsigned int flag)
30716 + AuRwMustAnyLock(&sbi->si_rwsem);
30717 + return sbi->au_si_status & flag;
30719 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30720 +#define au_fset_si(sbinfo, name) do { \
30721 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30722 + (sbinfo)->au_si_status |= AuSi_##name; \
30724 +#define au_fclr_si(sbinfo, name) do { \
30725 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30726 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30729 +/* ---------------------------------------------------------------------- */
30731 +/* policy to select one among writable branches */
30732 +#define AuWbrCopyup(sbinfo, ...) \
30733 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30734 +#define AuWbrCreate(sbinfo, ...) \
30735 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30737 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30738 +#define AuLock_DW 1 /* write-lock dentry */
30739 +#define AuLock_IR (1 << 1) /* read-lock inode */
30740 +#define AuLock_IW (1 << 2) /* write-lock inode */
30741 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30742 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30743 + /* except RENAME_EXCHANGE */
30744 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30745 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30746 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30747 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30748 +#define au_fset_lock(flags, name) \
30749 + do { (flags) |= AuLock_##name; } while (0)
30750 +#define au_fclr_lock(flags, name) \
30751 + do { (flags) &= ~AuLock_##name; } while (0)
30753 +/* ---------------------------------------------------------------------- */
30756 +extern struct file_system_type aufs_fs_type;
30757 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30758 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30759 + unsigned long long max, void *arg);
30760 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30761 + struct super_block *sb, void *arg);
30762 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30763 +void au_iarray_free(struct inode **a, unsigned long long max);
30766 +void au_si_free(struct kobject *kobj);
30767 +int au_si_alloc(struct super_block *sb);
30768 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30770 +unsigned int au_sigen_inc(struct super_block *sb);
30771 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30773 +int si_read_lock(struct super_block *sb, int flags);
30774 +int si_write_lock(struct super_block *sb, int flags);
30775 +int aufs_read_lock(struct dentry *dentry, int flags);
30776 +void aufs_read_unlock(struct dentry *dentry, int flags);
30777 +void aufs_write_lock(struct dentry *dentry);
30778 +void aufs_write_unlock(struct dentry *dentry);
30779 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30780 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30782 +/* wbr_policy.c */
30783 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30784 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30785 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30786 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30787 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30790 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30792 +#ifdef CONFIG_AUFS_FHSM
30795 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30799 + spin_lock(&fhsm->fhsm_spin);
30800 + pid = fhsm->fhsm_pid;
30801 + spin_unlock(&fhsm->fhsm_spin);
30806 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30807 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30808 +int au_fhsm_fd(struct super_block *sb, int oflags);
30809 +int au_fhsm_br_alloc(struct au_branch *br);
30810 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30811 +void au_fhsm_fin(struct super_block *sb);
30812 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30813 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30814 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30816 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30818 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30819 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30820 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30821 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30822 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30823 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30824 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30825 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30826 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30829 +/* ---------------------------------------------------------------------- */
30831 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30833 + return sb->s_fs_info;
30836 +/* ---------------------------------------------------------------------- */
30838 +#ifdef CONFIG_AUFS_EXPORT
30839 +int au_test_nfsd(void);
30840 +void au_export_init(struct super_block *sb);
30841 +void au_xigen_inc(struct inode *inode);
30842 +int au_xigen_new(struct inode *inode);
30843 +int au_xigen_set(struct super_block *sb, struct path *path);
30844 +void au_xigen_clr(struct super_block *sb);
30846 +static inline int au_busy_or_stale(void)
30848 + if (!au_test_nfsd())
30853 +AuStubInt0(au_test_nfsd, void)
30854 +AuStubVoid(au_export_init, struct super_block *sb)
30855 +AuStubVoid(au_xigen_inc, struct inode *inode)
30856 +AuStubInt0(au_xigen_new, struct inode *inode)
30857 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30858 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30859 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30860 +#endif /* CONFIG_AUFS_EXPORT */
30862 +/* ---------------------------------------------------------------------- */
30864 +#ifdef CONFIG_AUFS_SBILIST
30866 +extern struct hlist_bl_head au_sbilist;
30868 +static inline void au_sbilist_init(void)
30870 + INIT_HLIST_BL_HEAD(&au_sbilist);
30873 +static inline void au_sbilist_add(struct super_block *sb)
30875 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30878 +static inline void au_sbilist_del(struct super_block *sb)
30880 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30883 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30884 +static inline void au_sbilist_lock(void)
30886 + hlist_bl_lock(&au_sbilist);
30889 +static inline void au_sbilist_unlock(void)
30891 + hlist_bl_unlock(&au_sbilist);
30893 +#define AuGFP_SBILIST GFP_ATOMIC
30895 +AuStubVoid(au_sbilist_lock, void)
30896 +AuStubVoid(au_sbilist_unlock, void)
30897 +#define AuGFP_SBILIST GFP_NOFS
30898 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30900 +AuStubVoid(au_sbilist_init, void)
30901 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30902 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30903 +AuStubVoid(au_sbilist_lock, void)
30904 +AuStubVoid(au_sbilist_unlock, void)
30905 +#define AuGFP_SBILIST GFP_NOFS
30908 +/* ---------------------------------------------------------------------- */
30910 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30913 + * This function is a dynamic '__init' function actually,
30914 + * so the tiny check for si_rwsem is unnecessary.
30916 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30917 +#ifdef CONFIG_DEBUG_FS
30918 + sbinfo->si_dbgaufs = NULL;
30919 + sbinfo->si_dbgaufs_plink = NULL;
30920 + sbinfo->si_dbgaufs_xib = NULL;
30921 +#ifdef CONFIG_AUFS_EXPORT
30922 + sbinfo->si_dbgaufs_xigen = NULL;
30927 +/* ---------------------------------------------------------------------- */
30929 +/* current->atomic_flags */
30930 +/* this value should never corrupt the ones defined in linux/sched.h */
30931 +#define PFA_AUFS 0x10
30933 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30934 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30935 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30937 +static inline int si_pid_test(struct super_block *sb)
30939 + return !!task_test_aufs(current);
30942 +static inline void si_pid_clr(struct super_block *sb)
30944 + AuDebugOn(!task_test_aufs(current));
30945 + task_clear_aufs(current);
30948 +static inline void si_pid_set(struct super_block *sb)
30950 + AuDebugOn(task_test_aufs(current));
30951 + task_set_aufs(current);
30954 +/* ---------------------------------------------------------------------- */
30956 +/* lock superblock. mainly for entry point functions */
30957 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
30958 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
30959 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
30960 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
30962 +#define __si_read_trylock_nested(sb) \
30963 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
30964 +#define __si_write_trylock_nested(sb) \
30965 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
30968 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
30969 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
30970 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
30972 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30973 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30974 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30976 +static inline void si_noflush_read_lock(struct super_block *sb)
30978 + __si_read_lock(sb);
30982 +static inline int si_noflush_read_trylock(struct super_block *sb)
30986 + locked = __si_read_trylock(sb);
30992 +static inline void si_noflush_write_lock(struct super_block *sb)
30994 + __si_write_lock(sb);
30998 +static inline int si_noflush_write_trylock(struct super_block *sb)
31002 + locked = __si_write_trylock(sb);
31008 +#if 0 /* reserved */
31009 +static inline int si_read_trylock(struct super_block *sb, int flags)
31011 + if (au_ftest_lock(flags, FLUSH))
31012 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31013 + return si_noflush_read_trylock(sb);
31017 +static inline void si_read_unlock(struct super_block *sb)
31020 + __si_read_unlock(sb);
31023 +#if 0 /* reserved */
31024 +static inline int si_write_trylock(struct super_block *sb, int flags)
31026 + if (au_ftest_lock(flags, FLUSH))
31027 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31028 + return si_noflush_write_trylock(sb);
31032 +static inline void si_write_unlock(struct super_block *sb)
31035 + __si_write_unlock(sb);
31038 +#if 0 /* reserved */
31039 +static inline void si_downgrade_lock(struct super_block *sb)
31041 + __si_downgrade_lock(sb);
31045 +/* ---------------------------------------------------------------------- */
31047 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31049 + SiMustAnyLock(sb);
31050 + return au_sbi(sb)->si_bbot;
31053 +static inline unsigned int au_mntflags(struct super_block *sb)
31055 + SiMustAnyLock(sb);
31056 + return au_sbi(sb)->si_mntflags;
31059 +static inline unsigned int au_sigen(struct super_block *sb)
31061 + SiMustAnyLock(sb);
31062 + return au_sbi(sb)->si_generation;
31065 +static inline struct au_branch *au_sbr(struct super_block *sb,
31066 + aufs_bindex_t bindex)
31068 + SiMustAnyLock(sb);
31069 + return au_sbi(sb)->si_branch[0 + bindex];
31072 +static inline loff_t au_xi_maxent(struct super_block *sb)
31074 + SiMustAnyLock(sb);
31075 + return au_sbi(sb)->si_ximaxent;
31078 +#endif /* __KERNEL__ */
31079 +#endif /* __AUFS_SUPER_H__ */
31080 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31081 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31082 +++ linux/fs/aufs/sysaufs.c 2020-01-27 10:57:18.178871751 +0100
31084 +// SPDX-License-Identifier: GPL-2.0
31086 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31088 + * This program, aufs is free software; you can redistribute it and/or modify
31089 + * it under the terms of the GNU General Public License as published by
31090 + * the Free Software Foundation; either version 2 of the License, or
31091 + * (at your option) any later version.
31093 + * This program is distributed in the hope that it will be useful,
31094 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31095 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31096 + * GNU General Public License for more details.
31098 + * You should have received a copy of the GNU General Public License
31099 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31103 + * sysfs interface and lifetime management
31104 + * they are necessary regardless sysfs is disabled.
31107 +#include <linux/random.h>
31110 +unsigned long sysaufs_si_mask;
31111 +struct kset *sysaufs_kset;
31113 +#define AuSiAttr(_name) { \
31114 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31115 + .show = sysaufs_si_##_name, \
31118 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31119 +struct attribute *sysaufs_si_attrs[] = {
31120 + &sysaufs_si_attr_xi_path.attr,
31124 +static const struct sysfs_ops au_sbi_ops = {
31125 + .show = sysaufs_si_show
31128 +static struct kobj_type au_sbi_ktype = {
31129 + .release = au_si_free,
31130 + .sysfs_ops = &au_sbi_ops,
31131 + .default_attrs = sysaufs_si_attrs
31134 +/* ---------------------------------------------------------------------- */
31136 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31140 + sbinfo->si_kobj.kset = sysaufs_kset;
31141 + /* cf. sysaufs_name() */
31142 + err = kobject_init_and_add
31143 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31144 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31149 +void sysaufs_fin(void)
31151 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31152 + kset_unregister(sysaufs_kset);
31155 +int __init sysaufs_init(void)
31160 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31161 + } while (!sysaufs_si_mask);
31164 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31165 + if (unlikely(!sysaufs_kset))
31167 + err = PTR_ERR(sysaufs_kset);
31168 + if (IS_ERR(sysaufs_kset))
31170 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31171 + if (unlikely(err))
31172 + kset_unregister(sysaufs_kset);
31177 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31178 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31179 +++ linux/fs/aufs/sysaufs.h 2020-01-27 10:57:18.178871751 +0100
31181 +/* SPDX-License-Identifier: GPL-2.0 */
31183 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31185 + * This program, aufs is free software; you can redistribute it and/or modify
31186 + * it under the terms of the GNU General Public License as published by
31187 + * the Free Software Foundation; either version 2 of the License, or
31188 + * (at your option) any later version.
31190 + * This program is distributed in the hope that it will be useful,
31191 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31192 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31193 + * GNU General Public License for more details.
31195 + * You should have received a copy of the GNU General Public License
31196 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31200 + * sysfs interface and mount lifetime management
31203 +#ifndef __SYSAUFS_H__
31204 +#define __SYSAUFS_H__
31208 +#include <linux/sysfs.h>
31209 +#include "module.h"
31211 +struct super_block;
31214 +struct sysaufs_si_attr {
31215 + struct attribute attr;
31216 + int (*show)(struct seq_file *seq, struct super_block *sb);
31219 +/* ---------------------------------------------------------------------- */
31222 +extern unsigned long sysaufs_si_mask;
31223 +extern struct kset *sysaufs_kset;
31224 +extern struct attribute *sysaufs_si_attrs[];
31225 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31226 +int __init sysaufs_init(void);
31227 +void sysaufs_fin(void);
31229 +/* ---------------------------------------------------------------------- */
31231 +/* some people doesn't like to show a pointer in kernel */
31232 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31234 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31237 +#define SysaufsSiNamePrefix "si_"
31238 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31239 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31241 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31242 + sysaufs_si_id(sbinfo));
31246 +#ifdef CONFIG_SYSFS
31248 +extern struct attribute_group *sysaufs_attr_group;
31250 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31251 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31253 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31254 +#ifdef CONFIG_COMPAT
31255 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31258 +void sysaufs_br_init(struct au_branch *br);
31259 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31260 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31262 +#define sysaufs_brs_init() do {} while (0)
31265 +#define sysaufs_attr_group NULL
31267 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31268 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31269 + struct attribute *attr, char *buf)
31270 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31271 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31272 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31274 +static inline void sysaufs_brs_init(void)
31279 +#endif /* CONFIG_SYSFS */
31281 +#endif /* __KERNEL__ */
31282 +#endif /* __SYSAUFS_H__ */
31283 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31284 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31285 +++ linux/fs/aufs/sysfs.c 2020-01-27 10:57:18.178871751 +0100
31287 +// SPDX-License-Identifier: GPL-2.0
31289 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31291 + * This program, aufs is free software; you can redistribute it and/or modify
31292 + * it under the terms of the GNU General Public License as published by
31293 + * the Free Software Foundation; either version 2 of the License, or
31294 + * (at your option) any later version.
31296 + * This program is distributed in the hope that it will be useful,
31297 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31298 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31299 + * GNU General Public License for more details.
31301 + * You should have received a copy of the GNU General Public License
31302 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31306 + * sysfs interface
31309 +#include <linux/compat.h>
31310 +#include <linux/seq_file.h>
31313 +#ifdef CONFIG_AUFS_FS_MODULE
31314 +/* this entry violates the "one line per file" policy of sysfs */
31315 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31319 + static char *conf =
31320 +/* this file is generated at compiling */
31321 +#include "conf.str"
31324 + err = snprintf(buf, PAGE_SIZE, conf);
31325 + if (unlikely(err >= PAGE_SIZE))
31330 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31333 +static struct attribute *au_attr[] = {
31334 +#ifdef CONFIG_AUFS_FS_MODULE
31335 + &au_config_attr.attr,
31337 + NULL, /* need to NULL terminate the list of attributes */
31340 +static struct attribute_group sysaufs_attr_group_body = {
31344 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31346 +/* ---------------------------------------------------------------------- */
31348 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31352 + SiMustAnyLock(sb);
31355 + if (au_opt_test(au_mntflags(sb), XINO)) {
31356 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31357 + seq_putc(seq, '\n');
31363 + * the lifetime of branch is independent from the entry under sysfs.
31364 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31367 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31368 + aufs_bindex_t bindex, int idx)
31371 + struct path path;
31372 + struct dentry *root;
31373 + struct au_branch *br;
31374 + au_br_perm_str_t perm;
31376 + AuDbg("b%d\n", bindex);
31379 + root = sb->s_root;
31380 + di_read_lock_parent(root, !AuLock_IR);
31381 + br = au_sbr(sb, bindex);
31384 + case AuBrSysfs_BR:
31385 + path.mnt = au_br_mnt(br);
31386 + path.dentry = au_h_dptr(root, bindex);
31387 + err = au_seq_path(seq, &path);
31389 + au_optstr_br_perm(&perm, br->br_perm);
31390 + seq_printf(seq, "=%s\n", perm.a);
31393 + case AuBrSysfs_BRID:
31394 + seq_printf(seq, "%d\n", br->br_id);
31397 + di_read_unlock(root, !AuLock_IR);
31398 + if (unlikely(err || seq_has_overflowed(seq)))
31404 +/* ---------------------------------------------------------------------- */
31406 +static struct seq_file *au_seq(char *p, ssize_t len)
31408 + struct seq_file *seq;
31410 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31412 + /* mutex_init(&seq.lock); */
31415 + return seq; /* success */
31418 + seq = ERR_PTR(-ENOMEM);
31422 +#define SysaufsBr_PREFIX "br"
31423 +#define SysaufsBrid_PREFIX "brid"
31425 +/* todo: file size may exceed PAGE_SIZE */
31426 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31432 + aufs_bindex_t bbot;
31433 + struct au_sbinfo *sbinfo;
31434 + struct super_block *sb;
31435 + struct seq_file *seq;
31437 + struct attribute **cattr;
31439 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31440 + sb = sbinfo->si_sb;
31443 + * prevent a race condition between sysfs and aufs.
31444 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31445 + * prohibits maintaining the sysfs entries.
31446 + * hew we acquire read lock after sysfs_get_active_two().
31447 + * on the other hand, the remount process may maintain the sysfs/aufs
31448 + * entries after acquiring write lock.
31449 + * it can cause a deadlock.
31450 + * simply we gave up processing read here.
31453 + if (unlikely(!si_noflush_read_trylock(sb)))
31456 + seq = au_seq(buf, PAGE_SIZE);
31457 + err = PTR_ERR(seq);
31461 + name = (void *)attr->name;
31462 + cattr = sysaufs_si_attrs;
31464 + if (!strcmp(name, (*cattr)->name)) {
31465 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31472 + if (!strncmp(name, SysaufsBrid_PREFIX,
31473 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31474 + idx = AuBrSysfs_BRID;
31475 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31476 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31477 + sizeof(SysaufsBr_PREFIX) - 1)) {
31478 + idx = AuBrSysfs_BR;
31479 + name += sizeof(SysaufsBr_PREFIX) - 1;
31483 + err = kstrtol(name, 10, &l);
31485 + bbot = au_sbbot(sb);
31487 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31494 + err = seq->count;
31495 + /* sysfs limit */
31496 + if (unlikely(err == PAGE_SIZE))
31499 + au_kfree_rcu(seq);
31501 + si_read_unlock(sb);
31506 +/* ---------------------------------------------------------------------- */
31508 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31512 + aufs_bindex_t bindex, bbot;
31515 + struct seq_file *seq;
31516 + struct au_branch *br;
31518 + si_read_lock(sb, AuLock_FLUSH);
31519 + bbot = au_sbbot(sb);
31525 + buf = (void *)__get_free_page(GFP_NOFS);
31526 + if (unlikely(!buf))
31529 + seq = au_seq(buf, PAGE_SIZE);
31530 + err = PTR_ERR(seq);
31534 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31535 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31536 + /* VERIFY_WRITE */
31537 + err = !access_ok(arg, sizeof(*arg));
31538 + if (unlikely(err))
31541 + br = au_sbr(sb, bindex);
31542 + brid = br->br_id;
31543 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31544 + err = __put_user(brid, &arg->id);
31545 + if (unlikely(err))
31548 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31549 + err = __put_user(br->br_perm, &arg->perm);
31550 + if (unlikely(err))
31553 + err = au_seq_path(seq, &br->br_path);
31554 + if (unlikely(err))
31556 + seq_putc(seq, '\0');
31557 + if (!seq_has_overflowed(seq)) {
31558 + err = copy_to_user(arg->path, seq->buf, seq->count);
31560 + if (unlikely(err))
31567 + if (unlikely(err))
31571 + au_kfree_rcu(seq);
31573 + free_page((unsigned long)buf);
31575 + si_read_unlock(sb);
31579 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31581 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31584 +#ifdef CONFIG_COMPAT
31585 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31587 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31591 +/* ---------------------------------------------------------------------- */
31593 +void sysaufs_br_init(struct au_branch *br)
31596 + struct au_brsysfs *br_sysfs;
31597 + struct attribute *attr;
31599 + br_sysfs = br->br_sysfs;
31600 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31601 + attr = &br_sysfs->attr;
31602 + sysfs_attr_init(attr);
31603 + attr->name = br_sysfs->name;
31604 + attr->mode = 0444;
31609 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31611 + struct au_branch *br;
31612 + struct kobject *kobj;
31613 + struct au_brsysfs *br_sysfs;
31615 + aufs_bindex_t bbot;
31617 + if (!sysaufs_brs)
31620 + kobj = &au_sbi(sb)->si_kobj;
31621 + bbot = au_sbbot(sb);
31622 + for (; bindex <= bbot; bindex++) {
31623 + br = au_sbr(sb, bindex);
31624 + br_sysfs = br->br_sysfs;
31625 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31626 + sysfs_remove_file(kobj, &br_sysfs->attr);
31632 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31635 + aufs_bindex_t bbot;
31636 + struct kobject *kobj;
31637 + struct au_branch *br;
31638 + struct au_brsysfs *br_sysfs;
31640 + if (!sysaufs_brs)
31643 + kobj = &au_sbi(sb)->si_kobj;
31644 + bbot = au_sbbot(sb);
31645 + for (; bindex <= bbot; bindex++) {
31646 + br = au_sbr(sb, bindex);
31647 + br_sysfs = br->br_sysfs;
31648 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31649 + SysaufsBr_PREFIX "%d", bindex);
31650 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31651 + SysaufsBrid_PREFIX "%d", bindex);
31652 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31653 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31654 + if (unlikely(err))
31655 + pr_warn("failed %s under sysfs(%d)\n",
31656 + br_sysfs->name, err);
31661 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31662 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31663 +++ linux/fs/aufs/sysrq.c 2020-01-27 10:57:18.178871751 +0100
31665 +// SPDX-License-Identifier: GPL-2.0
31667 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31669 + * This program, aufs is free software; you can redistribute it and/or modify
31670 + * it under the terms of the GNU General Public License as published by
31671 + * the Free Software Foundation; either version 2 of the License, or
31672 + * (at your option) any later version.
31674 + * This program is distributed in the hope that it will be useful,
31675 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31676 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31677 + * GNU General Public License for more details.
31679 + * You should have received a copy of the GNU General Public License
31680 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31684 + * magic sysrq handler
31687 +/* #include <linux/sysrq.h> */
31688 +#include <linux/writeback.h>
31691 +/* ---------------------------------------------------------------------- */
31693 +static void sysrq_sb(struct super_block *sb)
31696 + struct au_sbinfo *sbinfo;
31697 + struct file *file;
31698 + struct hlist_bl_head *files;
31699 + struct hlist_bl_node *pos;
31700 + struct au_finfo *finfo;
31703 + plevel = au_plevel;
31704 + au_plevel = KERN_WARNING;
31706 + /* since we define pr_fmt, call printk directly */
31707 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31709 + sbinfo = au_sbi(sb);
31710 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31711 + pr("superblock\n");
31714 +#if 0 /* reserved */
31716 + int err, i, j, ndentry;
31717 + struct au_dcsub_pages dpages;
31718 + struct au_dpage *dpage;
31720 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31721 + if (unlikely(err))
31723 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31725 + for (i = 0; i < dpages.ndpage; i++) {
31726 + dpage = dpages.dpages + i;
31727 + ndentry = dpage->ndentry;
31728 + for (j = 0; j < ndentry; j++)
31729 + au_dpri_dentry(dpage->dentries[j]);
31731 + au_dpages_free(&dpages);
31735 + pr("isolated inode\n");
31736 + spin_lock(&sb->s_inode_list_lock);
31737 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31738 + spin_lock(&i->i_lock);
31739 + if (hlist_empty(&i->i_dentry))
31740 + au_dpri_inode(i);
31741 + spin_unlock(&i->i_lock);
31743 + spin_unlock(&sb->s_inode_list_lock);
31746 + files = &au_sbi(sb)->si_files;
31747 + hlist_bl_lock(files);
31748 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31751 + file = finfo->fi_file;
31752 + mode = file_inode(file)->i_mode;
31753 + if (!special_file(mode))
31754 + au_dpri_file(file);
31756 + hlist_bl_unlock(files);
31760 + au_plevel = plevel;
31763 +/* ---------------------------------------------------------------------- */
31765 +/* module parameter */
31766 +static char *aufs_sysrq_key = "a";
31767 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31768 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31770 +static void au_sysrq(int key __maybe_unused)
31772 + struct au_sbinfo *sbinfo;
31773 + struct hlist_bl_node *pos;
31776 + au_sbilist_lock();
31777 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31778 + sysrq_sb(sbinfo->si_sb);
31779 + au_sbilist_unlock();
31783 +static struct sysrq_key_op au_sysrq_op = {
31784 + .handler = au_sysrq,
31785 + .help_msg = "Aufs",
31786 + .action_msg = "Aufs",
31787 + .enable_mask = SYSRQ_ENABLE_DUMP
31790 +/* ---------------------------------------------------------------------- */
31792 +int __init au_sysrq_init(void)
31798 + key = *aufs_sysrq_key;
31799 + if ('a' <= key && key <= 'z')
31800 + err = register_sysrq_key(key, &au_sysrq_op);
31801 + if (unlikely(err))
31802 + pr_err("err %d, sysrq=%c\n", err, key);
31806 +void au_sysrq_fin(void)
31810 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31811 + if (unlikely(err))
31812 + pr_err("err %d (ignored)\n", err);
31814 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31815 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31816 +++ linux/fs/aufs/vdir.c 2020-01-27 10:57:18.178871751 +0100
31818 +// SPDX-License-Identifier: GPL-2.0
31820 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31822 + * This program, aufs is free software; you can redistribute it and/or modify
31823 + * it under the terms of the GNU General Public License as published by
31824 + * the Free Software Foundation; either version 2 of the License, or
31825 + * (at your option) any later version.
31827 + * This program is distributed in the hope that it will be useful,
31828 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31829 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31830 + * GNU General Public License for more details.
31832 + * You should have received a copy of the GNU General Public License
31833 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31837 + * virtual or vertical directory
31840 +#include <linux/iversion.h>
31843 +static unsigned int calc_size(int nlen)
31845 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31848 +static int set_deblk_end(union au_vdir_deblk_p *p,
31849 + union au_vdir_deblk_p *deblk_end)
31851 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31852 + p->de->de_str.len = 0;
31856 + return -1; /* error */
31859 +/* returns true or false */
31860 +static int is_deblk_end(union au_vdir_deblk_p *p,
31861 + union au_vdir_deblk_p *deblk_end)
31863 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31864 + return !p->de->de_str.len;
31868 +static unsigned char *last_deblk(struct au_vdir *vdir)
31870 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31873 +/* ---------------------------------------------------------------------- */
31875 +/* estimate the appropriate size for name hash table */
31876 +unsigned int au_rdhash_est(loff_t sz)
31884 + if (sz < AUFS_RDHASH_DEF)
31885 + n = AUFS_RDHASH_DEF;
31886 + /* pr_info("n %u\n", n); */
31891 + * the allocated memory has to be freed by
31892 + * au_nhash_wh_free() or au_nhash_de_free().
31894 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31896 + struct hlist_head *head;
31900 + sz = sizeof(*nhash->nh_head) * num_hash;
31901 + head = kmalloc(sz, gfp);
31903 + nhash->nh_num = num_hash;
31904 + nhash->nh_head = head;
31905 + for (u = 0; u < num_hash; u++)
31906 + INIT_HLIST_HEAD(head++);
31907 + return 0; /* success */
31913 +static void nhash_count(struct hlist_head *head)
31915 +#if 0 /* debugging */
31917 + struct hlist_node *pos;
31920 + hlist_for_each(pos, head)
31922 + pr_info("%lu\n", n);
31926 +static void au_nhash_wh_do_free(struct hlist_head *head)
31928 + struct au_vdir_wh *pos;
31929 + struct hlist_node *node;
31931 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31932 + au_kfree_rcu(pos);
31935 +static void au_nhash_de_do_free(struct hlist_head *head)
31937 + struct au_vdir_dehstr *pos;
31938 + struct hlist_node *node;
31940 + hlist_for_each_entry_safe(pos, node, head, hash)
31941 + au_cache_free_vdir_dehstr(pos);
31944 +static void au_nhash_do_free(struct au_nhash *nhash,
31945 + void (*free)(struct hlist_head *head))
31948 + struct hlist_head *head;
31950 + n = nhash->nh_num;
31954 + head = nhash->nh_head;
31955 + while (n-- > 0) {
31956 + nhash_count(head);
31959 + au_kfree_try_rcu(nhash->nh_head);
31962 +void au_nhash_wh_free(struct au_nhash *whlist)
31964 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31967 +static void au_nhash_de_free(struct au_nhash *delist)
31969 + au_nhash_do_free(delist, au_nhash_de_do_free);
31972 +/* ---------------------------------------------------------------------- */
31974 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
31978 + unsigned int u, n;
31979 + struct hlist_head *head;
31980 + struct au_vdir_wh *pos;
31983 + n = whlist->nh_num;
31984 + head = whlist->nh_head;
31985 + for (u = 0; u < n; u++, head++)
31986 + hlist_for_each_entry(pos, head, wh_hash)
31987 + if (pos->wh_bindex == btgt && ++num > limit)
31992 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
31993 + unsigned char *name,
31994 + unsigned int len)
31997 + /* const unsigned int magic_bit = 12; */
31999 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32006 + /* v = hash_long(v, magic_bit); */
32007 + v %= nhash->nh_num;
32008 + return nhash->nh_head + v;
32011 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32014 + return str->len == nlen && !memcmp(str->name, name, nlen);
32017 +/* returns found or not */
32018 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32020 + struct hlist_head *head;
32021 + struct au_vdir_wh *pos;
32022 + struct au_vdir_destr *str;
32024 + head = au_name_hash(whlist, name, nlen);
32025 + hlist_for_each_entry(pos, head, wh_hash) {
32026 + str = &pos->wh_str;
32027 + AuDbg("%.*s\n", str->len, str->name);
32028 + if (au_nhash_test_name(str, name, nlen))
32034 +/* returns found(true) or not */
32035 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32037 + struct hlist_head *head;
32038 + struct au_vdir_dehstr *pos;
32039 + struct au_vdir_destr *str;
32041 + head = au_name_hash(delist, name, nlen);
32042 + hlist_for_each_entry(pos, head, hash) {
32044 + AuDbg("%.*s\n", str->len, str->name);
32045 + if (au_nhash_test_name(str, name, nlen))
32051 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32052 + unsigned char d_type)
32054 +#ifdef CONFIG_AUFS_SHWH
32055 + wh->wh_ino = ino;
32056 + wh->wh_type = d_type;
32060 +/* ---------------------------------------------------------------------- */
32062 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32063 + unsigned int d_type, aufs_bindex_t bindex,
32064 + unsigned char shwh)
32067 + struct au_vdir_destr *str;
32068 + struct au_vdir_wh *wh;
32070 + AuDbg("%.*s\n", nlen, name);
32071 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32074 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32075 + if (unlikely(!wh))
32079 + wh->wh_bindex = bindex;
32081 + au_shwh_init_wh(wh, ino, d_type);
32082 + str = &wh->wh_str;
32084 + memcpy(str->name, name, nlen);
32085 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32092 +static int append_deblk(struct au_vdir *vdir)
32095 + unsigned long ul;
32096 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32097 + union au_vdir_deblk_p p, deblk_end;
32098 + unsigned char **o;
32101 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32102 + GFP_NOFS, /*may_shrink*/0);
32103 + if (unlikely(!o))
32106 + vdir->vd_deblk = o;
32107 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32109 + ul = vdir->vd_nblk++;
32110 + vdir->vd_deblk[ul] = p.deblk;
32111 + vdir->vd_last.ul = ul;
32112 + vdir->vd_last.p.deblk = p.deblk;
32113 + deblk_end.deblk = p.deblk + deblk_sz;
32114 + err = set_deblk_end(&p, &deblk_end);
32121 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32122 + unsigned int d_type, struct au_nhash *delist)
32126 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32127 + union au_vdir_deblk_p p, *room, deblk_end;
32128 + struct au_vdir_dehstr *dehstr;
32130 + p.deblk = last_deblk(vdir);
32131 + deblk_end.deblk = p.deblk + deblk_sz;
32132 + room = &vdir->vd_last.p;
32133 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32134 + || !is_deblk_end(room, &deblk_end));
32136 + sz = calc_size(nlen);
32137 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32138 + err = append_deblk(vdir);
32139 + if (unlikely(err))
32142 + p.deblk = last_deblk(vdir);
32143 + deblk_end.deblk = p.deblk + deblk_sz;
32145 + AuDebugOn(room->deblk != p.deblk);
32149 + dehstr = au_cache_alloc_vdir_dehstr();
32150 + if (unlikely(!dehstr))
32153 + dehstr->str = &room->de->de_str;
32154 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32155 + room->de->de_ino = ino;
32156 + room->de->de_type = d_type;
32157 + room->de->de_str.len = nlen;
32158 + memcpy(room->de->de_str.name, name, nlen);
32161 + room->deblk += sz;
32162 + if (unlikely(set_deblk_end(room, &deblk_end)))
32163 + err = append_deblk(vdir);
32170 +/* ---------------------------------------------------------------------- */
32172 +void au_vdir_free(struct au_vdir *vdir)
32174 + unsigned char **deblk;
32176 + deblk = vdir->vd_deblk;
32177 + while (vdir->vd_nblk--)
32178 + au_kfree_try_rcu(*deblk++);
32179 + au_kfree_try_rcu(vdir->vd_deblk);
32180 + au_cache_free_vdir(vdir);
32183 +static struct au_vdir *alloc_vdir(struct file *file)
32185 + struct au_vdir *vdir;
32186 + struct super_block *sb;
32189 + sb = file->f_path.dentry->d_sb;
32190 + SiMustAnyLock(sb);
32193 + vdir = au_cache_alloc_vdir();
32194 + if (unlikely(!vdir))
32197 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32198 + if (unlikely(!vdir->vd_deblk))
32201 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32202 + if (!vdir->vd_deblk_sz) {
32203 + /* estimate the appropriate size for deblk */
32204 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32205 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32207 + vdir->vd_nblk = 0;
32208 + vdir->vd_version = 0;
32209 + vdir->vd_jiffy = 0;
32210 + err = append_deblk(vdir);
32212 + return vdir; /* success */
32214 + au_kfree_try_rcu(vdir->vd_deblk);
32217 + au_cache_free_vdir(vdir);
32219 + vdir = ERR_PTR(err);
32223 +static int reinit_vdir(struct au_vdir *vdir)
32226 + union au_vdir_deblk_p p, deblk_end;
32228 + while (vdir->vd_nblk > 1) {
32229 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32230 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32233 + p.deblk = vdir->vd_deblk[0];
32234 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32235 + err = set_deblk_end(&p, &deblk_end);
32236 + /* keep vd_dblk_sz */
32237 + vdir->vd_last.ul = 0;
32238 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32239 + vdir->vd_version = 0;
32240 + vdir->vd_jiffy = 0;
32245 +/* ---------------------------------------------------------------------- */
32247 +#define AuFillVdir_CALLED 1
32248 +#define AuFillVdir_WHABLE (1 << 1)
32249 +#define AuFillVdir_SHWH (1 << 2)
32250 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32251 +#define au_fset_fillvdir(flags, name) \
32252 + do { (flags) |= AuFillVdir_##name; } while (0)
32253 +#define au_fclr_fillvdir(flags, name) \
32254 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32256 +#ifndef CONFIG_AUFS_SHWH
32257 +#undef AuFillVdir_SHWH
32258 +#define AuFillVdir_SHWH 0
32261 +struct fillvdir_arg {
32262 + struct dir_context ctx;
32263 + struct file *file;
32264 + struct au_vdir *vdir;
32265 + struct au_nhash delist;
32266 + struct au_nhash whlist;
32267 + aufs_bindex_t bindex;
32268 + unsigned int flags;
32272 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32273 + loff_t offset __maybe_unused, u64 h_ino,
32274 + unsigned int d_type)
32276 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32277 + char *name = (void *)__name;
32278 + struct super_block *sb;
32280 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32283 + sb = arg->file->f_path.dentry->d_sb;
32284 + au_fset_fillvdir(arg->flags, CALLED);
32286 + if (nlen <= AUFS_WH_PFX_LEN
32287 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32288 + if (test_known(&arg->delist, name, nlen)
32289 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32290 + goto out; /* already exists or whiteouted */
32292 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32294 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32295 + d_type = DT_UNKNOWN;
32296 + arg->err = append_de(arg->vdir, name, nlen, ino,
32297 + d_type, &arg->delist);
32299 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32300 + name += AUFS_WH_PFX_LEN;
32301 + nlen -= AUFS_WH_PFX_LEN;
32302 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32303 + goto out; /* already whiteouted */
32305 + ino = 0; /* just to suppress a warning */
32307 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32310 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32311 + d_type = DT_UNKNOWN;
32312 + arg->err = au_nhash_append_wh
32313 + (&arg->whlist, name, nlen, ino, d_type,
32314 + arg->bindex, shwh);
32320 + arg->vdir->vd_jiffy = jiffies;
32322 + AuTraceErr(arg->err);
32326 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32327 + struct au_nhash *whlist, struct au_nhash *delist)
32329 +#ifdef CONFIG_AUFS_SHWH
32331 + unsigned int nh, u;
32332 + struct hlist_head *head;
32333 + struct au_vdir_wh *pos;
32334 + struct hlist_node *n;
32336 + struct au_vdir_destr *destr;
32338 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32341 + o = p = (void *)__get_free_page(GFP_NOFS);
32342 + if (unlikely(!p))
32346 + nh = whlist->nh_num;
32347 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32348 + p += AUFS_WH_PFX_LEN;
32349 + for (u = 0; u < nh; u++) {
32350 + head = whlist->nh_head + u;
32351 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32352 + destr = &pos->wh_str;
32353 + memcpy(p, destr->name, destr->len);
32354 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32355 + pos->wh_ino, pos->wh_type, delist);
32356 + if (unlikely(err))
32361 + free_page((unsigned long)o);
32371 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32374 + unsigned int rdhash;
32376 + aufs_bindex_t bbot, bindex, btop;
32377 + unsigned char shwh;
32378 + struct file *hf, *file;
32379 + struct super_block *sb;
32381 + file = arg->file;
32382 + sb = file->f_path.dentry->d_sb;
32383 + SiMustAnyLock(sb);
32385 + rdhash = au_sbi(sb)->si_rdhash;
32387 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32388 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32389 + if (unlikely(err))
32391 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32392 + if (unlikely(err))
32398 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32400 + au_fset_fillvdir(arg->flags, SHWH);
32402 + btop = au_fbtop(file);
32403 + bbot = au_fbbot_dir(file);
32404 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32405 + hf = au_hf_dir(file, bindex);
32409 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32411 + if (unlikely(offset))
32414 + arg->bindex = bindex;
32415 + au_fclr_fillvdir(arg->flags, WHABLE);
32417 + || (bindex != bbot
32418 + && au_br_whable(au_sbr_perm(sb, bindex))))
32419 + au_fset_fillvdir(arg->flags, WHABLE);
32422 + au_fclr_fillvdir(arg->flags, CALLED);
32424 + err = vfsub_iterate_dir(hf, &arg->ctx);
32427 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32430 + * dir_relax() may be good for concurrency, but aufs should not
32431 + * use it since it will cause a lockdep problem.
32435 + if (!err && shwh)
32436 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32438 + au_nhash_wh_free(&arg->whlist);
32441 + au_nhash_de_free(&arg->delist);
32446 +static int read_vdir(struct file *file, int may_read)
32449 + unsigned long expire;
32450 + unsigned char do_read;
32451 + struct fillvdir_arg arg = {
32453 + .actor = fillvdir
32456 + struct inode *inode;
32457 + struct au_vdir *vdir, *allocated;
32460 + inode = file_inode(file);
32461 + IMustLock(inode);
32462 + IiMustWriteLock(inode);
32463 + SiMustAnyLock(inode->i_sb);
32465 + allocated = NULL;
32467 + expire = au_sbi(inode->i_sb)->si_rdcache;
32468 + vdir = au_ivdir(inode);
32471 + vdir = alloc_vdir(file);
32472 + err = PTR_ERR(vdir);
32473 + if (IS_ERR(vdir))
32476 + allocated = vdir;
32477 + } else if (may_read
32478 + && (!inode_eq_iversion(inode, vdir->vd_version)
32479 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32481 + err = reinit_vdir(vdir);
32482 + if (unlikely(err))
32487 + return 0; /* success */
32491 + err = au_do_read_vdir(&arg);
32493 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32494 + vdir->vd_version = inode_query_iversion(inode);
32495 + vdir->vd_last.ul = 0;
32496 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32498 + au_set_ivdir(inode, allocated);
32499 + } else if (allocated)
32500 + au_vdir_free(allocated);
32506 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32509 + unsigned long ul, n;
32510 + const unsigned int deblk_sz = src->vd_deblk_sz;
32512 + AuDebugOn(tgt->vd_nblk != 1);
32515 + if (tgt->vd_nblk < src->vd_nblk) {
32516 + unsigned char **p;
32518 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32519 + GFP_NOFS, /*may_shrink*/0);
32520 + if (unlikely(!p))
32522 + tgt->vd_deblk = p;
32525 + if (tgt->vd_deblk_sz != deblk_sz) {
32526 + unsigned char *p;
32528 + tgt->vd_deblk_sz = deblk_sz;
32529 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32530 + /*may_shrink*/1);
32531 + if (unlikely(!p))
32533 + tgt->vd_deblk[0] = p;
32535 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32536 + tgt->vd_version = src->vd_version;
32537 + tgt->vd_jiffy = src->vd_jiffy;
32539 + n = src->vd_nblk;
32540 + for (ul = 1; ul < n; ul++) {
32541 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32543 + if (unlikely(!tgt->vd_deblk[ul]))
32547 + tgt->vd_nblk = n;
32548 + tgt->vd_last.ul = tgt->vd_last.ul;
32549 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32550 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32551 + - src->vd_deblk[src->vd_last.ul];
32553 + return 0; /* success */
32556 + rerr = reinit_vdir(tgt);
32561 +int au_vdir_init(struct file *file)
32564 + struct inode *inode;
32565 + struct au_vdir *vdir_cache, *allocated;
32567 + /* test file->f_pos here instead of ctx->pos */
32568 + err = read_vdir(file, !file->f_pos);
32569 + if (unlikely(err))
32572 + allocated = NULL;
32573 + vdir_cache = au_fvdir_cache(file);
32574 + if (!vdir_cache) {
32575 + vdir_cache = alloc_vdir(file);
32576 + err = PTR_ERR(vdir_cache);
32577 + if (IS_ERR(vdir_cache))
32579 + allocated = vdir_cache;
32580 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32581 + /* test file->f_pos here instead of ctx->pos */
32582 + err = reinit_vdir(vdir_cache);
32583 + if (unlikely(err))
32586 + return 0; /* success */
32588 + inode = file_inode(file);
32589 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32591 + file->f_version = inode_query_iversion(inode);
32593 + au_set_fvdir_cache(file, allocated);
32594 + } else if (allocated)
32595 + au_vdir_free(allocated);
32601 +static loff_t calc_offset(struct au_vdir *vdir)
32604 + union au_vdir_deblk_p p;
32606 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32607 + offset = vdir->vd_last.p.deblk - p.deblk;
32608 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32612 +/* returns true or false */
32613 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32616 + unsigned int deblk_sz;
32617 + unsigned long ul, n;
32619 + union au_vdir_deblk_p p, deblk_end;
32620 + struct au_vdir *vdir_cache;
32623 + vdir_cache = au_fvdir_cache(file);
32624 + offset = calc_offset(vdir_cache);
32625 + AuDbg("offset %lld\n", offset);
32626 + if (ctx->pos == offset)
32629 + vdir_cache->vd_last.ul = 0;
32630 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32635 + deblk_sz = vdir_cache->vd_deblk_sz;
32636 + ul = div64_u64(ctx->pos, deblk_sz);
32637 + AuDbg("ul %lu\n", ul);
32638 + if (ul >= vdir_cache->vd_nblk)
32641 + n = vdir_cache->vd_nblk;
32642 + for (; ul < n; ul++) {
32643 + p.deblk = vdir_cache->vd_deblk[ul];
32644 + deblk_end.deblk = p.deblk + deblk_sz;
32646 + offset *= deblk_sz;
32647 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32650 + l = calc_size(p.de->de_str.len);
32654 + if (!is_deblk_end(&p, &deblk_end)) {
32656 + vdir_cache->vd_last.ul = ul;
32657 + vdir_cache->vd_last.p = p;
32665 + AuDbg("valid %d\n", !valid);
32669 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32671 + unsigned int l, deblk_sz;
32672 + union au_vdir_deblk_p deblk_end;
32673 + struct au_vdir *vdir_cache;
32674 + struct au_vdir_de *de;
32676 + if (!seek_vdir(file, ctx))
32679 + vdir_cache = au_fvdir_cache(file);
32680 + deblk_sz = vdir_cache->vd_deblk_sz;
32682 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32683 + deblk_end.deblk += deblk_sz;
32684 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32685 + de = vdir_cache->vd_last.p.de;
32686 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32687 + de->de_str.len, de->de_str.name, ctx->pos,
32688 + (unsigned long)de->de_ino, de->de_type);
32689 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32690 + de->de_str.len, de->de_ino,
32692 + /* todo: ignore the error caused by udba? */
32693 + /* return err; */
32697 + l = calc_size(de->de_str.len);
32698 + vdir_cache->vd_last.p.deblk += l;
32701 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32702 + vdir_cache->vd_last.ul++;
32703 + vdir_cache->vd_last.p.deblk
32704 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32705 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32714 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32715 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32716 +++ linux/fs/aufs/vfsub.c 2020-08-03 09:14:46.095748745 +0200
32718 +// SPDX-License-Identifier: GPL-2.0
32720 + * Copyright (C) 2005-2020 Junjiro R. Okajima
32722 + * This program, aufs is free software; you can redistribute it and/or modify
32723 + * it under the terms of the GNU General Public License as published by
32724 + * the Free Software Foundation; either version 2 of the License, or
32725 + * (at your option) any later version.
32727 + * This program is distributed in the hope that it will be useful,
32728 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32729 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32730 + * GNU General Public License for more details.
32732 + * You should have received a copy of the GNU General Public License
32733 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32737 + * sub-routines for VFS
32740 +#include <linux/mnt_namespace.h>
32741 +#include <linux/namei.h>
32742 +#include <linux/nsproxy.h>
32743 +#include <linux/security.h>
32744 +#include <linux/splice.h>
32747 +#ifdef CONFIG_AUFS_BR_FUSE
32748 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32750 + if (!au_test_fuse(h_sb) || !au_userns)
32753 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32757 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32762 + down_read(&h_sb->s_umount);
32763 + err = __sync_filesystem(h_sb, wait);
32764 + up_read(&h_sb->s_umount);
32770 +/* ---------------------------------------------------------------------- */
32772 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32776 + struct super_block *h_sb;
32778 + /* for remote fs, leave work for its getattr or d_revalidate */
32779 + /* for bad i_attr fs, handle them in aufs_getattr() */
32780 + /* still some fs may acquire i_mutex. we need to skip them */
32784 + h_sb = h_path->dentry->d_sb;
32785 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32787 + err = vfsub_getattr(h_path, &st);
32792 +/* ---------------------------------------------------------------------- */
32794 +struct file *vfsub_dentry_open(struct path *path, int flags)
32796 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32800 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32802 + struct file *file;
32805 + file = filp_open(path,
32806 + oflags /* | __FMODE_NONOTIFY */,
32809 + if (IS_ERR(file))
32811 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32818 + * Ideally this function should call VFS:do_last() in order to keep all its
32819 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32820 + * structure such as nameidata. This is a second (or third) best approach.
32821 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32823 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32824 + struct vfsub_aopen_args *args)
32827 + struct au_branch *br = args->br;
32828 + struct file *file = args->file;
32829 + /* copied from linux/fs/namei.c:atomic_open() */
32830 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32833 + AuDebugOn(!dir->i_op->atomic_open);
32835 + err = au_br_test_oflag(args->open_flag, br);
32836 + if (unlikely(err))
32839 + au_lcnt_inc(&br->br_nfiles);
32840 + file->f_path.dentry = DENTRY_NOT_SET;
32841 + file->f_path.mnt = au_br_mnt(br);
32842 + AuDbg("%ps\n", dir->i_op->atomic_open);
32843 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32844 + args->create_mode);
32845 + if (unlikely(err < 0)) {
32846 + au_lcnt_dec(&br->br_nfiles);
32850 + /* temporary workaround for nfsv4 branch */
32851 + if (au_test_nfs(dir->i_sb))
32852 + nfs_mark_for_revalidate(dir);
32854 + if (file->f_mode & FMODE_CREATED)
32855 + fsnotify_create(dir, dentry);
32856 + if (!(file->f_mode & FMODE_OPENED)) {
32857 + au_lcnt_dec(&br->br_nfiles);
32861 + /* todo: call VFS:may_open() here */
32862 + /* todo: ima_file_check() too? */
32863 + if (!err && (args->open_flag & __FMODE_EXEC))
32864 + err = deny_write_access(file);
32866 + fsnotify_open(file);
32868 + au_lcnt_dec(&br->br_nfiles);
32869 + /* note that the file is created and still opened */
32875 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32879 + err = kern_path(name, flags, path);
32880 + if (!err && d_is_positive(path->dentry))
32881 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32885 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32886 + struct dentry *parent, int len)
32888 + struct path path = {
32892 + path.dentry = lookup_one_len_unlocked(name, parent, len);
32893 + if (IS_ERR(path.dentry))
32895 + if (d_is_positive(path.dentry))
32896 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32899 + AuTraceErrPtr(path.dentry);
32900 + return path.dentry;
32903 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
32906 + struct path path = {
32910 + /* VFS checks it too, but by WARN_ON_ONCE() */
32911 + IMustLock(d_inode(parent));
32913 + path.dentry = lookup_one_len(name, parent, len);
32914 + if (IS_ERR(path.dentry))
32916 + if (d_is_positive(path.dentry))
32917 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32920 + AuTraceErrPtr(path.dentry);
32921 + return path.dentry;
32924 +void vfsub_call_lkup_one(void *args)
32926 + struct vfsub_lkup_one_args *a = args;
32927 + *a->errp = vfsub_lkup_one(a->name, a->parent);
32930 +/* ---------------------------------------------------------------------- */
32932 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32933 + struct dentry *d2, struct au_hinode *hdir2)
32935 + struct dentry *d;
32938 + d = lock_rename(d1, d2);
32940 + au_hn_suspend(hdir1);
32941 + if (hdir1 != hdir2)
32942 + au_hn_suspend(hdir2);
32947 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32948 + struct dentry *d2, struct au_hinode *hdir2)
32950 + au_hn_resume(hdir1);
32951 + if (hdir1 != hdir2)
32952 + au_hn_resume(hdir2);
32954 + unlock_rename(d1, d2);
32958 +/* ---------------------------------------------------------------------- */
32960 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32963 + struct dentry *d;
32967 + d = path->dentry;
32968 + path->dentry = d->d_parent;
32969 + err = security_path_mknod(path, d, mode, 0);
32970 + path->dentry = d;
32971 + if (unlikely(err))
32975 + err = vfs_create(dir, path->dentry, mode, want_excl);
32978 + struct path tmp = *path;
32981 + vfsub_update_h_iattr(&tmp, &did);
32983 + tmp.dentry = path->dentry->d_parent;
32984 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32993 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
32996 + struct dentry *d;
33000 + d = path->dentry;
33001 + path->dentry = d->d_parent;
33002 + err = security_path_symlink(path, d, symname);
33003 + path->dentry = d;
33004 + if (unlikely(err))
33008 + err = vfs_symlink(dir, path->dentry, symname);
33011 + struct path tmp = *path;
33014 + vfsub_update_h_iattr(&tmp, &did);
33016 + tmp.dentry = path->dentry->d_parent;
33017 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33026 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33029 + struct dentry *d;
33033 + d = path->dentry;
33034 + path->dentry = d->d_parent;
33035 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33036 + path->dentry = d;
33037 + if (unlikely(err))
33041 + err = vfs_mknod(dir, path->dentry, mode, dev);
33044 + struct path tmp = *path;
33047 + vfsub_update_h_iattr(&tmp, &did);
33049 + tmp.dentry = path->dentry->d_parent;
33050 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33059 +static int au_test_nlink(struct inode *inode)
33061 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33063 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33064 + || inode->i_nlink < link_max)
33069 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33070 + struct inode **delegated_inode)
33073 + struct dentry *d;
33077 + err = au_test_nlink(d_inode(src_dentry));
33078 + if (unlikely(err))
33081 + /* we don't call may_linkat() */
33082 + d = path->dentry;
33083 + path->dentry = d->d_parent;
33084 + err = security_path_link(src_dentry, path, d);
33085 + path->dentry = d;
33086 + if (unlikely(err))
33090 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
33093 + struct path tmp = *path;
33096 + /* fuse has different memory inode for the same inumber */
33097 + vfsub_update_h_iattr(&tmp, &did);
33099 + tmp.dentry = path->dentry->d_parent;
33100 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33101 + tmp.dentry = src_dentry;
33102 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33111 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33112 + struct inode *dir, struct path *path,
33113 + struct inode **delegated_inode, unsigned int flags)
33116 + struct path tmp = {
33119 + struct dentry *d;
33122 + IMustLock(src_dir);
33124 + d = path->dentry;
33125 + path->dentry = d->d_parent;
33126 + tmp.dentry = src_dentry->d_parent;
33127 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33128 + path->dentry = d;
33129 + if (unlikely(err))
33133 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
33134 + delegated_inode, flags);
33139 + tmp.dentry = d->d_parent;
33140 + vfsub_update_h_iattr(&tmp, &did);
33142 + tmp.dentry = src_dentry;
33143 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33144 + tmp.dentry = src_dentry->d_parent;
33145 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33154 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33157 + struct dentry *d;
33161 + d = path->dentry;
33162 + path->dentry = d->d_parent;
33163 + err = security_path_mkdir(path, d, mode);
33164 + path->dentry = d;
33165 + if (unlikely(err))
33169 + err = vfs_mkdir(dir, path->dentry, mode);
33172 + struct path tmp = *path;
33175 + vfsub_update_h_iattr(&tmp, &did);
33177 + tmp.dentry = path->dentry->d_parent;
33178 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33187 +int vfsub_rmdir(struct inode *dir, struct path *path)
33190 + struct dentry *d;
33194 + d = path->dentry;
33195 + path->dentry = d->d_parent;
33196 + err = security_path_rmdir(path, d);
33197 + path->dentry = d;
33198 + if (unlikely(err))
33202 + err = vfs_rmdir(dir, path->dentry);
33205 + struct path tmp = {
33206 + .dentry = path->dentry->d_parent,
33210 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33217 +/* ---------------------------------------------------------------------- */
33219 +/* todo: support mmap_sem? */
33220 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33226 + err = vfs_read(file, ubuf, count, ppos);
33229 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33233 +/* todo: kernel_read()? */
33234 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33238 + mm_segment_t oldfs;
33245 + oldfs = get_fs();
33246 + set_fs(KERNEL_DS);
33247 + err = vfsub_read_u(file, buf.u, count, ppos);
33252 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33258 + err = vfs_write(file, ubuf, count, ppos);
33261 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33265 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33268 + mm_segment_t oldfs;
33271 + const char __user *u;
33275 + oldfs = get_fs();
33276 + set_fs(KERNEL_DS);
33277 + err = vfsub_write_u(file, buf.u, count, ppos);
33282 +int vfsub_flush(struct file *file, fl_owner_t id)
33287 + if (file->f_op->flush) {
33288 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33289 + err = file->f_op->flush(file, id);
33292 + err = file->f_op->flush(file, id);
33296 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33302 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33306 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33309 + err = iterate_dir(file, ctx);
33312 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33317 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33318 + struct pipe_inode_info *pipe, size_t len,
33319 + unsigned int flags)
33324 + err = do_splice_to(in, ppos, pipe, len, flags);
33326 + file_accessed(in);
33328 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33332 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33333 + loff_t *ppos, size_t len, unsigned int flags)
33338 + err = do_splice_from(pipe, out, ppos, len, flags);
33341 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33345 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33349 + /* file can be NULL */
33351 + err = vfs_fsync(file, datasync);
33355 + AuDebugOn(!file);
33356 + path = &file->f_path;
33358 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33363 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33364 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33365 + struct file *h_file)
33368 + struct inode *h_inode;
33369 + struct super_block *h_sb;
33372 + err = vfsub_truncate(h_path, length);
33376 + h_inode = d_inode(h_path->dentry);
33377 + h_sb = h_inode->i_sb;
33379 + sb_start_write(h_sb);
33381 + err = locks_verify_truncate(h_inode, h_file, length);
33383 + err = security_path_truncate(h_path);
33386 + err = do_truncate(h_path->dentry, length, attr, h_file);
33390 + sb_end_write(h_sb);
33397 +/* ---------------------------------------------------------------------- */
33399 +struct au_vfsub_mkdir_args {
33401 + struct inode *dir;
33402 + struct path *path;
33406 +static void au_call_vfsub_mkdir(void *args)
33408 + struct au_vfsub_mkdir_args *a = args;
33409 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33412 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33414 + int err, do_sio, wkq_err;
33416 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33419 + err = vfsub_mkdir(dir, path, mode);
33422 + struct au_vfsub_mkdir_args args = {
33428 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33429 + if (unlikely(wkq_err))
33436 +struct au_vfsub_rmdir_args {
33438 + struct inode *dir;
33439 + struct path *path;
33442 +static void au_call_vfsub_rmdir(void *args)
33444 + struct au_vfsub_rmdir_args *a = args;
33445 + *a->errp = vfsub_rmdir(a->dir, a->path);
33448 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33450 + int err, do_sio, wkq_err;
33452 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33455 + err = vfsub_rmdir(dir, path);
33458 + struct au_vfsub_rmdir_args args = {
33463 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33464 + if (unlikely(wkq_err))
33471 +/* ---------------------------------------------------------------------- */
33473 +struct notify_change_args {
33475 + struct path *path;
33476 + struct iattr *ia;
33477 + struct inode **delegated_inode;
33480 +static void call_notify_change(void *args)
33482 + struct notify_change_args *a = args;
33483 + struct inode *h_inode;
33485 + h_inode = d_inode(a->path->dentry);
33486 + IMustLock(h_inode);
33488 + *a->errp = -EPERM;
33489 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33491 + *a->errp = notify_change(a->path->dentry, a->ia,
33492 + a->delegated_inode);
33495 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33497 + AuTraceErr(*a->errp);
33500 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33501 + struct inode **delegated_inode)
33504 + struct notify_change_args args = {
33508 + .delegated_inode = delegated_inode
33511 + call_notify_change(&args);
33516 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33517 + struct inode **delegated_inode)
33519 + int err, wkq_err;
33520 + struct notify_change_args args = {
33524 + .delegated_inode = delegated_inode
33527 + wkq_err = au_wkq_wait(call_notify_change, &args);
33528 + if (unlikely(wkq_err))
33534 +/* ---------------------------------------------------------------------- */
33536 +struct unlink_args {
33538 + struct inode *dir;
33539 + struct path *path;
33540 + struct inode **delegated_inode;
33543 +static void call_unlink(void *args)
33545 + struct unlink_args *a = args;
33546 + struct dentry *d = a->path->dentry;
33547 + struct inode *h_inode;
33548 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33549 + && au_dcount(d) == 1);
33551 + IMustLock(a->dir);
33553 + a->path->dentry = d->d_parent;
33554 + *a->errp = security_path_unlink(a->path, d);
33555 + a->path->dentry = d;
33556 + if (unlikely(*a->errp))
33559 + if (!stop_sillyrename)
33562 + if (d_is_positive(d)) {
33563 + h_inode = d_inode(d);
33568 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33571 + struct path tmp = {
33572 + .dentry = d->d_parent,
33573 + .mnt = a->path->mnt
33575 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33578 + if (!stop_sillyrename)
33583 + AuTraceErr(*a->errp);
33587 + * @dir: must be locked.
33588 + * @dentry: target dentry.
33590 +int vfsub_unlink(struct inode *dir, struct path *path,
33591 + struct inode **delegated_inode, int force)
33594 + struct unlink_args args = {
33598 + .delegated_inode = delegated_inode
33602 + call_unlink(&args);
33606 + wkq_err = au_wkq_wait(call_unlink, &args);
33607 + if (unlikely(wkq_err))
33613 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33614 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33615 +++ linux/fs/aufs/vfsub.h 2020-01-27 10:57:18.178871751 +0100
33617 +/* SPDX-License-Identifier: GPL-2.0 */
33619 + * Copyright (C) 2005-2020 Junjiro R. Okajima
33621 + * This program, aufs is free software; you can redistribute it and/or modify
33622 + * it under the terms of the GNU General Public License as published by
33623 + * the Free Software Foundation; either version 2 of the License, or
33624 + * (at your option) any later version.
33626 + * This program is distributed in the hope that it will be useful,
33627 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33628 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33629 + * GNU General Public License for more details.
33631 + * You should have received a copy of the GNU General Public License
33632 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33636 + * sub-routines for VFS
33639 +#ifndef __AUFS_VFSUB_H__
33640 +#define __AUFS_VFSUB_H__
33644 +#include <linux/fs.h>
33645 +#include <linux/mount.h>
33646 +#include <linux/posix_acl.h>
33647 +#include <linux/xattr.h>
33648 +#include "debug.h"
33650 +/* copied from linux/fs/internal.h */
33651 +/* todo: BAD approach!! */
33652 +extern void __mnt_drop_write(struct vfsmount *);
33653 +extern struct file *alloc_empty_file(int, const struct cred *);
33655 +/* ---------------------------------------------------------------------- */
33657 +/* lock subclass for lower inode */
33658 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33659 +/* reduce? gave up. */
33661 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33662 + AuLsc_I_PARENT, /* lower inode, parent first */
33663 + AuLsc_I_PARENT2, /* copyup dirs */
33664 + AuLsc_I_PARENT3, /* copyup wh */
33670 +/* to debug easier, do not make them inlined functions */
33671 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33672 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33674 +/* ---------------------------------------------------------------------- */
33676 +static inline void vfsub_drop_nlink(struct inode *inode)
33678 + AuDebugOn(!inode->i_nlink);
33679 + drop_nlink(inode);
33682 +static inline void vfsub_dead_dir(struct inode *inode)
33684 + AuDebugOn(!S_ISDIR(inode->i_mode));
33685 + inode->i_flags |= S_DEAD;
33686 + clear_nlink(inode);
33689 +static inline int vfsub_native_ro(struct inode *inode)
33691 + return sb_rdonly(inode->i_sb)
33692 + || IS_RDONLY(inode)
33693 + /* || IS_APPEND(inode) */
33694 + || IS_IMMUTABLE(inode);
33697 +#ifdef CONFIG_AUFS_BR_FUSE
33698 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33700 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33703 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33705 +/* ---------------------------------------------------------------------- */
33707 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33708 +struct file *vfsub_dentry_open(struct path *path, int flags);
33709 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33711 +struct vfsub_aopen_args {
33712 + struct file *file;
33713 + unsigned int open_flag;
33714 + umode_t create_mode;
33715 + struct au_branch *br;
33717 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33718 + struct vfsub_aopen_args *args);
33719 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33721 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33722 + struct dentry *parent, int len);
33723 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33726 +struct vfsub_lkup_one_args {
33727 + struct dentry **errp;
33728 + struct qstr *name;
33729 + struct dentry *parent;
33732 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33733 + struct dentry *parent)
33735 + return vfsub_lookup_one_len(name->name, parent, name->len);
33738 +void vfsub_call_lkup_one(void *args);
33740 +/* ---------------------------------------------------------------------- */
33742 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33747 + err = mnt_want_write(mnt);
33752 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33755 + mnt_drop_write(mnt);
33759 +#if 0 /* reserved */
33760 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33763 + mnt_drop_write_file(file);
33768 +/* ---------------------------------------------------------------------- */
33771 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33772 + struct dentry *d2, struct au_hinode *hdir2);
33773 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33774 + struct dentry *d2, struct au_hinode *hdir2);
33776 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33778 +int vfsub_symlink(struct inode *dir, struct path *path,
33779 + const char *symname);
33780 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33781 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33782 + struct path *path, struct inode **delegated_inode);
33783 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33784 + struct inode *hdir, struct path *path,
33785 + struct inode **delegated_inode, unsigned int flags);
33786 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33787 +int vfsub_rmdir(struct inode *dir, struct path *path);
33789 +/* ---------------------------------------------------------------------- */
33791 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33793 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33795 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33797 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33799 +int vfsub_flush(struct file *file, fl_owner_t id);
33800 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33802 +static inline loff_t vfsub_f_size_read(struct file *file)
33804 + return i_size_read(file_inode(file));
33807 +static inline unsigned int vfsub_file_flags(struct file *file)
33809 + unsigned int flags;
33811 + spin_lock(&file->f_lock);
33812 + flags = file->f_flags;
33813 + spin_unlock(&file->f_lock);
33818 +static inline int vfsub_file_execed(struct file *file)
33820 + /* todo: direct access f_flags */
33821 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33824 +#if 0 /* reserved */
33825 +static inline void vfsub_file_accessed(struct file *h_file)
33827 + file_accessed(h_file);
33828 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33832 +#if 0 /* reserved */
33833 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33834 + struct dentry *h_dentry)
33836 + struct path h_path = {
33837 + .dentry = h_dentry,
33840 + touch_atime(&h_path);
33841 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33845 +static inline int vfsub_update_time(struct inode *h_inode,
33846 + struct timespec64 *ts, int flags)
33848 + return update_time(h_inode, ts, flags);
33849 + /* no vfsub_update_h_iattr() since we don't have struct path */
33852 +#ifdef CONFIG_FS_POSIX_ACL
33853 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33857 + err = posix_acl_chmod(h_inode, h_mode);
33858 + if (err == -EOPNOTSUPP)
33863 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33866 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33867 + struct pipe_inode_info *pipe, size_t len,
33868 + unsigned int flags);
33869 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33870 + loff_t *ppos, size_t len, unsigned int flags);
33872 +static inline long vfsub_truncate(struct path *path, loff_t length)
33877 + err = vfs_truncate(path, length);
33882 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33883 + struct file *h_file);
33884 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33887 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33890 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
33896 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
33902 +/* copy_file_range(2) is a systemcall */
33903 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33904 + struct file *dst, loff_t dst_pos,
33905 + size_t len, unsigned int flags)
33910 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33916 +/* ---------------------------------------------------------------------- */
33918 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33923 + err = vfs_llseek(file, offset, origin);
33928 +/* ---------------------------------------------------------------------- */
33930 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33931 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33932 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33933 + struct inode **delegated_inode);
33934 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33935 + struct inode **delegated_inode);
33936 +int vfsub_unlink(struct inode *dir, struct path *path,
33937 + struct inode **delegated_inode, int force);
33939 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
33941 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
33944 +/* ---------------------------------------------------------------------- */
33946 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
33947 + const void *value, size_t size, int flags)
33952 + err = vfs_setxattr(dentry, name, value, size, flags);
33958 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
33963 + err = vfs_removexattr(dentry, name);
33969 +#endif /* __KERNEL__ */
33970 +#endif /* __AUFS_VFSUB_H__ */
33971 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
33972 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
33973 +++ linux/fs/aufs/wbr_policy.c 2020-01-27 10:57:18.178871751 +0100
33975 +// SPDX-License-Identifier: GPL-2.0
33977 + * Copyright (C) 2005-2020 Junjiro R. Okajima
33979 + * This program, aufs is free software; you can redistribute it and/or modify
33980 + * it under the terms of the GNU General Public License as published by
33981 + * the Free Software Foundation; either version 2 of the License, or
33982 + * (at your option) any later version.
33984 + * This program is distributed in the hope that it will be useful,
33985 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33986 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33987 + * GNU General Public License for more details.
33989 + * You should have received a copy of the GNU General Public License
33990 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33994 + * policies for selecting one among multiple writable branches
33997 +#include <linux/statfs.h>
34000 +/* subset of cpup_attr() */
34001 +static noinline_for_stack
34002 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34006 + struct inode *h_isrc;
34008 + h_isrc = d_inode(h_src);
34009 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34010 + ia.ia_mode = h_isrc->i_mode;
34011 + ia.ia_uid = h_isrc->i_uid;
34012 + ia.ia_gid = h_isrc->i_gid;
34013 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34014 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34015 + /* no delegation since it is just created */
34016 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34018 + /* is this nfs only? */
34019 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34020 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34021 + ia.ia_mode = h_isrc->i_mode;
34022 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34028 +#define AuCpdown_PARENT_OPQ 1
34029 +#define AuCpdown_WHED (1 << 1)
34030 +#define AuCpdown_MADE_DIR (1 << 2)
34031 +#define AuCpdown_DIROPQ (1 << 3)
34032 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34033 +#define au_fset_cpdown(flags, name) \
34034 + do { (flags) |= AuCpdown_##name; } while (0)
34035 +#define au_fclr_cpdown(flags, name) \
34036 + do { (flags) &= ~AuCpdown_##name; } while (0)
34038 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34039 + unsigned int *flags)
34042 + struct dentry *opq_dentry;
34044 + opq_dentry = au_diropq_create(dentry, bdst);
34045 + err = PTR_ERR(opq_dentry);
34046 + if (IS_ERR(opq_dentry))
34048 + dput(opq_dentry);
34049 + au_fset_cpdown(*flags, DIROPQ);
34055 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34056 + struct inode *dir, aufs_bindex_t bdst)
34059 + struct path h_path;
34060 + struct au_branch *br;
34062 + br = au_sbr(dentry->d_sb, bdst);
34063 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34064 + err = PTR_ERR(h_path.dentry);
34065 + if (IS_ERR(h_path.dentry))
34069 + if (d_is_positive(h_path.dentry)) {
34070 + h_path.mnt = au_br_mnt(br);
34071 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34074 + dput(h_path.dentry);
34080 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34081 + struct au_pin *pin,
34082 + struct dentry *h_parent, void *arg)
34085 + aufs_bindex_t bopq, btop;
34086 + struct path h_path;
34087 + struct dentry *parent;
34088 + struct inode *h_dir, *h_inode, *inode, *dir;
34089 + unsigned int *flags = arg;
34091 + btop = au_dbtop(dentry);
34092 + /* dentry is di-locked */
34093 + parent = dget_parent(dentry);
34094 + dir = d_inode(parent);
34095 + h_dir = d_inode(h_parent);
34096 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34097 + IMustLock(h_dir);
34099 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34100 + if (unlikely(err < 0))
34102 + h_path.dentry = au_h_dptr(dentry, bdst);
34103 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34104 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34105 + if (unlikely(err))
34107 + au_fset_cpdown(*flags, MADE_DIR);
34109 + bopq = au_dbdiropq(dentry);
34110 + au_fclr_cpdown(*flags, WHED);
34111 + au_fclr_cpdown(*flags, DIROPQ);
34112 + if (au_dbwh(dentry) == bdst)
34113 + au_fset_cpdown(*flags, WHED);
34114 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34115 + au_fset_cpdown(*flags, PARENT_OPQ);
34116 + h_inode = d_inode(h_path.dentry);
34117 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34118 + if (au_ftest_cpdown(*flags, WHED)) {
34119 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34120 + if (unlikely(err)) {
34121 + inode_unlock(h_inode);
34126 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34127 + inode_unlock(h_inode);
34128 + if (unlikely(err))
34131 + if (au_ftest_cpdown(*flags, WHED)) {
34132 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34133 + if (unlikely(err))
34137 + inode = d_inode(dentry);
34138 + if (au_ibbot(inode) < bdst)
34139 + au_set_ibbot(inode, bdst);
34140 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34141 + au_hi_flags(inode, /*isdir*/1));
34142 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34143 + goto out; /* success */
34147 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34148 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34149 + rerr = au_diropq_remove(dentry, bdst);
34150 + inode_unlock(h_inode);
34151 + if (unlikely(rerr)) {
34152 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34153 + dentry, bdst, rerr);
34159 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34160 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34161 + if (unlikely(rerr)) {
34162 + AuIOErr("failed removing %pd b%d (%d)\n",
34163 + dentry, bdst, rerr);
34168 + au_set_h_dptr(dentry, bdst, NULL);
34169 + if (au_dbbot(dentry) == bdst)
34170 + au_update_dbbot(dentry);
34176 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34179 + unsigned int flags;
34182 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34187 +/* ---------------------------------------------------------------------- */
34189 +/* policies for create */
34191 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34193 + int err, i, j, ndentry;
34194 + aufs_bindex_t bopq;
34195 + struct au_dcsub_pages dpages;
34196 + struct au_dpage *dpage;
34197 + struct dentry **dentries, *parent, *d;
34199 + err = au_dpages_init(&dpages, GFP_NOFS);
34200 + if (unlikely(err))
34202 + parent = dget_parent(dentry);
34203 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34204 + if (unlikely(err))
34208 + for (i = 0; i < dpages.ndpage; i++) {
34209 + dpage = dpages.dpages + i;
34210 + dentries = dpage->dentries;
34211 + ndentry = dpage->ndentry;
34212 + for (j = 0; j < ndentry; j++) {
34214 + di_read_lock_parent2(d, !AuLock_IR);
34215 + bopq = au_dbdiropq(d);
34216 + di_read_unlock(d, !AuLock_IR);
34217 + if (bopq >= 0 && bopq < err)
34224 + au_dpages_free(&dpages);
34229 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34231 + for (; bindex >= 0; bindex--)
34232 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34237 +/* top down parent */
34238 +static int au_wbr_create_tdp(struct dentry *dentry,
34239 + unsigned int flags __maybe_unused)
34242 + aufs_bindex_t btop, bindex;
34243 + struct super_block *sb;
34244 + struct dentry *parent, *h_parent;
34246 + sb = dentry->d_sb;
34247 + btop = au_dbtop(dentry);
34249 + if (!au_br_rdonly(au_sbr(sb, btop)))
34253 + parent = dget_parent(dentry);
34254 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34255 + h_parent = au_h_dptr(parent, bindex);
34256 + if (!h_parent || d_is_negative(h_parent))
34259 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34266 + /* bottom up here */
34267 + if (unlikely(err < 0)) {
34268 + err = au_wbr_bu(sb, btop - 1);
34270 + err = au_wbr_nonopq(dentry, err);
34274 + AuDbg("b%d\n", err);
34278 +/* ---------------------------------------------------------------------- */
34280 +/* an exception for the policy other than tdp */
34281 +static int au_wbr_create_exp(struct dentry *dentry)
34284 + aufs_bindex_t bwh, bdiropq;
34285 + struct dentry *parent;
34288 + bwh = au_dbwh(dentry);
34289 + parent = dget_parent(dentry);
34290 + bdiropq = au_dbdiropq(parent);
34292 + if (bdiropq >= 0)
34293 + err = min(bdiropq, bwh);
34296 + AuDbg("%d\n", err);
34297 + } else if (bdiropq >= 0) {
34299 + AuDbg("%d\n", err);
34304 + err = au_wbr_nonopq(dentry, err);
34306 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34309 + AuDbg("%d\n", err);
34313 +/* ---------------------------------------------------------------------- */
34316 +static int au_wbr_create_init_rr(struct super_block *sb)
34320 + err = au_wbr_bu(sb, au_sbbot(sb));
34321 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34324 + AuDbg("b%d\n", err);
34328 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34332 + aufs_bindex_t bindex, bbot;
34333 + struct super_block *sb;
34336 + err = au_wbr_create_exp(dentry);
34340 + sb = dentry->d_sb;
34341 + next = &au_sbi(sb)->si_wbr_rr_next;
34342 + bbot = au_sbbot(sb);
34344 + for (bindex = 0; bindex <= bbot; bindex++) {
34345 + if (!au_ftest_wbr(flags, DIR)) {
34346 + err = atomic_dec_return(next) + 1;
34347 + /* modulo for 0 is meaningless */
34348 + if (unlikely(!err))
34349 + err = atomic_dec_return(next) + 1;
34351 + err = atomic_read(next);
34352 + AuDbg("%d\n", err);
34355 + AuDbg("%d\n", err);
34356 + if (!au_br_rdonly(au_sbr(sb, err)))
34362 + err = au_wbr_nonopq(dentry, err);
34365 + AuDbg("%d\n", err);
34369 +/* ---------------------------------------------------------------------- */
34371 +/* most free space */
34372 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34374 + struct super_block *sb;
34375 + struct au_branch *br;
34376 + struct au_wbr_mfs *mfs;
34377 + struct dentry *h_parent;
34378 + aufs_bindex_t bindex, bbot;
34380 + unsigned long long b, bavail;
34381 + struct path h_path;
34382 + /* reduce the stack usage */
34383 + struct kstatfs *st;
34385 + st = kmalloc(sizeof(*st), GFP_NOFS);
34386 + if (unlikely(!st)) {
34387 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34392 + sb = dentry->d_sb;
34393 + mfs = &au_sbi(sb)->si_wbr_mfs;
34394 + MtxMustLock(&mfs->mfs_lock);
34395 + mfs->mfs_bindex = -EROFS;
34396 + mfs->mfsrr_bytes = 0;
34399 + bbot = au_sbbot(sb);
34401 + bindex = au_dbtop(parent);
34402 + bbot = au_dbtaildir(parent);
34405 + for (; bindex <= bbot; bindex++) {
34407 + h_parent = au_h_dptr(parent, bindex);
34408 + if (!h_parent || d_is_negative(h_parent))
34411 + br = au_sbr(sb, bindex);
34412 + if (au_br_rdonly(br))
34415 + /* sb->s_root for NFS is unreliable */
34416 + h_path.mnt = au_br_mnt(br);
34417 + h_path.dentry = h_path.mnt->mnt_root;
34418 + err = vfs_statfs(&h_path, st);
34419 + if (unlikely(err)) {
34420 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34424 + /* when the available size is equal, select the lower one */
34425 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34426 + || sizeof(b) < sizeof(st->f_bsize));
34427 + b = st->f_bavail * st->f_bsize;
34428 + br->br_wbr->wbr_bytes = b;
34429 + if (b >= bavail) {
34431 + mfs->mfs_bindex = bindex;
34432 + mfs->mfs_jiffy = jiffies;
34436 + mfs->mfsrr_bytes = bavail;
34437 + AuDbg("b%d\n", mfs->mfs_bindex);
34438 + au_kfree_rcu(st);
34441 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34444 + struct dentry *parent;
34445 + struct super_block *sb;
34446 + struct au_wbr_mfs *mfs;
34448 + err = au_wbr_create_exp(dentry);
34452 + sb = dentry->d_sb;
34454 + if (au_ftest_wbr(flags, PARENT))
34455 + parent = dget_parent(dentry);
34456 + mfs = &au_sbi(sb)->si_wbr_mfs;
34457 + mutex_lock(&mfs->mfs_lock);
34458 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34459 + || mfs->mfs_bindex < 0
34460 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34461 + au_mfs(dentry, parent);
34462 + mutex_unlock(&mfs->mfs_lock);
34463 + err = mfs->mfs_bindex;
34467 + err = au_wbr_nonopq(dentry, err);
34470 + AuDbg("b%d\n", err);
34474 +static int au_wbr_create_init_mfs(struct super_block *sb)
34476 + struct au_wbr_mfs *mfs;
34478 + mfs = &au_sbi(sb)->si_wbr_mfs;
34479 + mutex_init(&mfs->mfs_lock);
34480 + mfs->mfs_jiffy = 0;
34481 + mfs->mfs_bindex = -EROFS;
34486 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34488 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34492 +/* ---------------------------------------------------------------------- */
34494 +/* top down regardless parent, and then mfs */
34495 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34496 + unsigned int flags __maybe_unused)
34499 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34500 + unsigned long long watermark;
34501 + struct super_block *sb;
34502 + struct au_wbr_mfs *mfs;
34503 + struct au_branch *br;
34504 + struct dentry *parent;
34506 + sb = dentry->d_sb;
34507 + mfs = &au_sbi(sb)->si_wbr_mfs;
34508 + mutex_lock(&mfs->mfs_lock);
34509 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34510 + || mfs->mfs_bindex < 0)
34511 + au_mfs(dentry, /*parent*/NULL);
34512 + watermark = mfs->mfsrr_watermark;
34513 + bmfs = mfs->mfs_bindex;
34514 + mutex_unlock(&mfs->mfs_lock);
34516 + /* another style of au_wbr_create_exp() */
34517 + bwh = au_dbwh(dentry);
34518 + parent = dget_parent(dentry);
34519 + btail = au_dbtaildir(parent);
34520 + if (bwh >= 0 && bwh < btail)
34523 + err = au_wbr_nonopq(dentry, btail);
34524 + if (unlikely(err < 0))
34528 + for (bindex = 0; bindex <= btail; bindex++) {
34529 + br = au_sbr(sb, bindex);
34530 + if (au_br_rdonly(br))
34532 + if (br->br_wbr->wbr_bytes > watermark) {
34543 + AuDbg("b%d\n", err);
34547 +/* ---------------------------------------------------------------------- */
34549 +/* most free space and then round robin */
34550 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34553 + struct au_wbr_mfs *mfs;
34555 + err = au_wbr_create_mfs(dentry, flags);
34557 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34558 + mutex_lock(&mfs->mfs_lock);
34559 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34560 + err = au_wbr_create_rr(dentry, flags);
34561 + mutex_unlock(&mfs->mfs_lock);
34564 + AuDbg("b%d\n", err);
34568 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34572 + au_wbr_create_init_mfs(sb); /* ignore */
34573 + err = au_wbr_create_init_rr(sb);
34578 +/* ---------------------------------------------------------------------- */
34580 +/* top down parent and most free space */
34581 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34584 + unsigned long long b;
34585 + aufs_bindex_t bindex, btop, bbot;
34586 + struct super_block *sb;
34587 + struct dentry *parent, *h_parent;
34588 + struct au_branch *br;
34590 + err = au_wbr_create_tdp(dentry, flags);
34591 + if (unlikely(err < 0))
34593 + parent = dget_parent(dentry);
34594 + btop = au_dbtop(parent);
34595 + bbot = au_dbtaildir(parent);
34596 + if (btop == bbot)
34597 + goto out_parent; /* success */
34599 + e2 = au_wbr_create_mfs(dentry, flags);
34601 + goto out_parent; /* success */
34603 + /* when the available size is equal, select upper one */
34604 + sb = dentry->d_sb;
34605 + br = au_sbr(sb, err);
34606 + b = br->br_wbr->wbr_bytes;
34607 + AuDbg("b%d, %llu\n", err, b);
34609 + for (bindex = btop; bindex <= bbot; bindex++) {
34610 + h_parent = au_h_dptr(parent, bindex);
34611 + if (!h_parent || d_is_negative(h_parent))
34614 + br = au_sbr(sb, bindex);
34615 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34616 + b = br->br_wbr->wbr_bytes;
34618 + AuDbg("b%d, %llu\n", err, b);
34623 + err = au_wbr_nonopq(dentry, err);
34628 + AuDbg("b%d\n", err);
34632 +/* ---------------------------------------------------------------------- */
34635 + * - top down parent
34636 + * - most free space with parent
34637 + * - most free space round-robin regardless parent
34639 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34642 + unsigned long long watermark;
34643 + struct super_block *sb;
34644 + struct au_branch *br;
34645 + struct au_wbr_mfs *mfs;
34647 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34648 + if (unlikely(err < 0))
34651 + sb = dentry->d_sb;
34652 + br = au_sbr(sb, err);
34653 + mfs = &au_sbi(sb)->si_wbr_mfs;
34654 + mutex_lock(&mfs->mfs_lock);
34655 + watermark = mfs->mfsrr_watermark;
34656 + mutex_unlock(&mfs->mfs_lock);
34657 + if (br->br_wbr->wbr_bytes < watermark)
34658 + /* regardless the parent dir */
34659 + err = au_wbr_create_mfsrr(dentry, flags);
34662 + AuDbg("b%d\n", err);
34666 +/* ---------------------------------------------------------------------- */
34668 +/* policies for copyup */
34670 +/* top down parent */
34671 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34673 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34676 +/* bottom up parent */
34677 +static int au_wbr_copyup_bup(struct dentry *dentry)
34680 + aufs_bindex_t bindex, btop;
34681 + struct dentry *parent, *h_parent;
34682 + struct super_block *sb;
34685 + sb = dentry->d_sb;
34686 + parent = dget_parent(dentry);
34687 + btop = au_dbtop(parent);
34688 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34689 + h_parent = au_h_dptr(parent, bindex);
34690 + if (!h_parent || d_is_negative(h_parent))
34693 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34700 + /* bottom up here */
34701 + if (unlikely(err < 0))
34702 + err = au_wbr_bu(sb, btop - 1);
34704 + AuDbg("b%d\n", err);
34709 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34713 + err = au_wbr_bu(dentry->d_sb, btop);
34714 + AuDbg("b%d\n", err);
34716 + err = au_wbr_nonopq(dentry, err);
34718 + AuDbg("b%d\n", err);
34722 +static int au_wbr_copyup_bu(struct dentry *dentry)
34725 + aufs_bindex_t btop;
34727 + btop = au_dbtop(dentry);
34728 + err = au_wbr_do_copyup_bu(dentry, btop);
34732 +/* ---------------------------------------------------------------------- */
34734 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34735 + [AuWbrCopyup_TDP] = {
34736 + .copyup = au_wbr_copyup_tdp
34738 + [AuWbrCopyup_BUP] = {
34739 + .copyup = au_wbr_copyup_bup
34741 + [AuWbrCopyup_BU] = {
34742 + .copyup = au_wbr_copyup_bu
34746 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34747 + [AuWbrCreate_TDP] = {
34748 + .create = au_wbr_create_tdp
34750 + [AuWbrCreate_RR] = {
34751 + .create = au_wbr_create_rr,
34752 + .init = au_wbr_create_init_rr
34754 + [AuWbrCreate_MFS] = {
34755 + .create = au_wbr_create_mfs,
34756 + .init = au_wbr_create_init_mfs,
34757 + .fin = au_wbr_create_fin_mfs
34759 + [AuWbrCreate_MFSV] = {
34760 + .create = au_wbr_create_mfs,
34761 + .init = au_wbr_create_init_mfs,
34762 + .fin = au_wbr_create_fin_mfs
34764 + [AuWbrCreate_MFSRR] = {
34765 + .create = au_wbr_create_mfsrr,
34766 + .init = au_wbr_create_init_mfsrr,
34767 + .fin = au_wbr_create_fin_mfs
34769 + [AuWbrCreate_MFSRRV] = {
34770 + .create = au_wbr_create_mfsrr,
34771 + .init = au_wbr_create_init_mfsrr,
34772 + .fin = au_wbr_create_fin_mfs
34774 + [AuWbrCreate_TDMFS] = {
34775 + .create = au_wbr_create_tdmfs,
34776 + .init = au_wbr_create_init_mfs,
34777 + .fin = au_wbr_create_fin_mfs
34779 + [AuWbrCreate_TDMFSV] = {
34780 + .create = au_wbr_create_tdmfs,
34781 + .init = au_wbr_create_init_mfs,
34782 + .fin = au_wbr_create_fin_mfs
34784 + [AuWbrCreate_PMFS] = {
34785 + .create = au_wbr_create_pmfs,
34786 + .init = au_wbr_create_init_mfs,
34787 + .fin = au_wbr_create_fin_mfs
34789 + [AuWbrCreate_PMFSV] = {
34790 + .create = au_wbr_create_pmfs,
34791 + .init = au_wbr_create_init_mfs,
34792 + .fin = au_wbr_create_fin_mfs
34794 + [AuWbrCreate_PMFSRR] = {
34795 + .create = au_wbr_create_pmfsrr,
34796 + .init = au_wbr_create_init_mfsrr,
34797 + .fin = au_wbr_create_fin_mfs
34799 + [AuWbrCreate_PMFSRRV] = {
34800 + .create = au_wbr_create_pmfsrr,
34801 + .init = au_wbr_create_init_mfsrr,
34802 + .fin = au_wbr_create_fin_mfs
34805 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34806 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34807 +++ linux/fs/aufs/whout.c 2020-01-27 10:57:18.178871751 +0100
34809 +// SPDX-License-Identifier: GPL-2.0
34811 + * Copyright (C) 2005-2020 Junjiro R. Okajima
34813 + * This program, aufs is free software; you can redistribute it and/or modify
34814 + * it under the terms of the GNU General Public License as published by
34815 + * the Free Software Foundation; either version 2 of the License, or
34816 + * (at your option) any later version.
34818 + * This program is distributed in the hope that it will be useful,
34819 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34820 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34821 + * GNU General Public License for more details.
34823 + * You should have received a copy of the GNU General Public License
34824 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34828 + * whiteout for logical deletion and opaque directory
34833 +#define WH_MASK 0444
34836 + * If a directory contains this file, then it is opaque. We start with the
34837 + * .wh. flag so that it is blocked by lookup.
34839 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34840 + sizeof(AUFS_WH_DIROPQ) - 1);
34843 + * generate whiteout name, which is NOT terminated by NULL.
34844 + * @name: original d_name.name
34845 + * @len: original d_name.len
34846 + * @wh: whiteout qstr
34847 + * returns zero when succeeds, otherwise error.
34848 + * succeeded value as wh->name should be freed by kfree().
34850 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34854 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34855 + return -ENAMETOOLONG;
34857 + wh->len = name->len + AUFS_WH_PFX_LEN;
34858 + p = kmalloc(wh->len, GFP_NOFS);
34861 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34862 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34869 +/* ---------------------------------------------------------------------- */
34872 + * test if the @wh_name exists under @h_parent.
34873 + * @try_sio specifies the necessary of super-io.
34875 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
34878 + struct dentry *wh_dentry;
34881 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34883 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
34884 + err = PTR_ERR(wh_dentry);
34885 + if (IS_ERR(wh_dentry)) {
34886 + if (err == -ENAMETOOLONG)
34892 + if (d_is_negative(wh_dentry))
34893 + goto out_wh; /* success */
34896 + if (d_is_reg(wh_dentry))
34897 + goto out_wh; /* success */
34900 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34901 + wh_dentry, d_inode(wh_dentry)->i_mode);
34910 + * test if the @h_dentry sets opaque or not.
34912 +int au_diropq_test(struct dentry *h_dentry)
34915 + struct inode *h_dir;
34917 + h_dir = d_inode(h_dentry);
34918 + err = au_wh_test(h_dentry, &diropq_name,
34919 + au_test_h_perm_sio(h_dir, MAY_EXEC));
34924 + * returns a negative dentry whose name is unique and temporary.
34926 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34927 + struct qstr *prefix)
34929 + struct dentry *dentry;
34931 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34933 + /* strict atomic_t is unnecessary here */
34934 + static unsigned short cnt;
34937 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34940 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34941 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34942 + dentry = ERR_PTR(-ENAMETOOLONG);
34943 + if (unlikely(qs.len > NAME_MAX))
34945 + dentry = ERR_PTR(-ENOMEM);
34946 + name = kmalloc(qs.len + 1, GFP_NOFS);
34947 + if (unlikely(!name))
34951 + /* doubly whiteout-ed */
34952 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34953 + p = name + AUFS_WH_PFX_LEN * 2;
34954 + memcpy(p, prefix->name, prefix->len);
34955 + p += prefix->len;
34957 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34960 + for (i = 0; i < 3; i++) {
34961 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34962 + dentry = au_sio_lkup_one(&qs, h_parent);
34963 + if (IS_ERR(dentry) || d_is_negative(dentry))
34967 + /* pr_warn("could not get random name\n"); */
34968 + dentry = ERR_PTR(-EEXIST);
34969 + AuDbg("%.*s\n", AuLNPair(&qs));
34973 + if (name != defname)
34974 + au_kfree_try_rcu(name);
34976 + AuTraceErrPtr(dentry);
34981 + * rename the @h_dentry on @br to the whiteouted temporary name.
34983 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
34986 + struct path h_path = {
34987 + .mnt = au_br_mnt(br)
34989 + struct inode *h_dir, *delegated;
34990 + struct dentry *h_parent;
34992 + h_parent = h_dentry->d_parent; /* dir inode is locked */
34993 + h_dir = d_inode(h_parent);
34994 + IMustLock(h_dir);
34996 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
34997 + err = PTR_ERR(h_path.dentry);
34998 + if (IS_ERR(h_path.dentry))
35001 + /* under the same dir, no need to lock_rename() */
35002 + delegated = NULL;
35003 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35006 + if (unlikely(err == -EWOULDBLOCK)) {
35007 + pr_warn("cannot retry for NFSv4 delegation"
35008 + " for an internal rename\n");
35011 + dput(h_path.dentry);
35018 +/* ---------------------------------------------------------------------- */
35020 + * functions for removing a whiteout
35023 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35026 + struct inode *delegated;
35029 + * forces superio when the dir has a sticky bit.
35030 + * this may be a violation of unix fs semantics.
35032 + force = (h_dir->i_mode & S_ISVTX)
35033 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35034 + delegated = NULL;
35035 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35036 + if (unlikely(err == -EWOULDBLOCK)) {
35037 + pr_warn("cannot retry for NFSv4 delegation"
35038 + " for an internal unlink\n");
35044 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35045 + struct dentry *dentry)
35049 + err = do_unlink_wh(h_dir, h_path);
35050 + if (!err && dentry)
35051 + au_set_dbwh(dentry, -1);
35056 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
35057 + struct au_branch *br)
35060 + struct path h_path = {
35061 + .mnt = au_br_mnt(br)
35065 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
35066 + if (IS_ERR(h_path.dentry))
35067 + err = PTR_ERR(h_path.dentry);
35069 + if (d_is_reg(h_path.dentry))
35070 + err = do_unlink_wh(d_inode(h_parent), &h_path);
35071 + dput(h_path.dentry);
35077 +/* ---------------------------------------------------------------------- */
35079 + * initialize/clean whiteout for a branch
35082 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35086 + struct inode *delegated;
35088 + if (d_is_negative(whpath->dentry))
35092 + err = vfsub_rmdir(h_dir, whpath);
35094 + delegated = NULL;
35095 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35096 + if (unlikely(err == -EWOULDBLOCK)) {
35097 + pr_warn("cannot retry for NFSv4 delegation"
35098 + " for an internal unlink\n");
35102 + if (unlikely(err))
35103 + pr_warn("failed removing %pd (%d), ignored.\n",
35104 + whpath->dentry, err);
35107 +static int test_linkable(struct dentry *h_root)
35109 + struct inode *h_dir = d_inode(h_root);
35111 + if (h_dir->i_op->link)
35114 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35115 + h_root, au_sbtype(h_root->d_sb));
35116 + return -ENOSYS; /* the branch doesn't have its ->link() */
35119 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35120 +static int au_whdir(struct inode *h_dir, struct path *path)
35125 + if (d_is_negative(path->dentry)) {
35128 + if (au_test_nfs(path->dentry->d_sb))
35130 + err = vfsub_mkdir(h_dir, path, mode);
35131 + } else if (d_is_dir(path->dentry))
35134 + pr_err("unknown %pd exists\n", path->dentry);
35139 +struct au_wh_base {
35140 + const struct qstr *name;
35141 + struct dentry *dentry;
35144 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35145 + struct path *h_path)
35147 + h_path->dentry = base[AuBrWh_BASE].dentry;
35148 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35149 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35150 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35151 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35152 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35156 + * returns tri-state,
35157 + * minus: error, caller should print the message
35159 + * plus: error, caller should NOT print the message
35161 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35162 + int do_plink, struct au_wh_base base[],
35163 + struct path *h_path)
35166 + struct inode *h_dir;
35168 + h_dir = d_inode(h_root);
35169 + h_path->dentry = base[AuBrWh_BASE].dentry;
35170 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35171 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35173 + err = test_linkable(h_root);
35174 + if (unlikely(err)) {
35179 + err = au_whdir(h_dir, h_path);
35180 + if (unlikely(err))
35182 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35184 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35185 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35186 + err = au_whdir(h_dir, h_path);
35187 + if (unlikely(err))
35189 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35196 + * for the moment, aufs supports the branch filesystem which does not support
35197 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35198 + * copyup failed. finally, such filesystem will not be used as the writable
35201 + * returns tri-state, see above.
35203 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35204 + int do_plink, struct au_wh_base base[],
35205 + struct path *h_path)
35208 + struct inode *h_dir;
35210 + WbrWhMustWriteLock(wbr);
35212 + err = test_linkable(h_root);
35213 + if (unlikely(err)) {
35219 + * todo: should this create be done in /sbin/mount.aufs helper?
35222 + h_dir = d_inode(h_root);
35223 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35224 + h_path->dentry = base[AuBrWh_BASE].dentry;
35225 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35226 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35229 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35230 + if (unlikely(err))
35233 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35235 + err = au_whdir(h_dir, h_path);
35236 + if (unlikely(err))
35238 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35240 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35241 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35243 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35244 + err = au_whdir(h_dir, h_path);
35245 + if (unlikely(err))
35247 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35254 + * initialize the whiteout base file/dir for @br.
35256 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35259 + const unsigned char do_plink
35260 + = !!au_opt_test(au_mntflags(sb), PLINK);
35261 + struct inode *h_dir;
35262 + struct path path = br->br_path;
35263 + struct dentry *h_root = path.dentry;
35264 + struct au_wbr *wbr = br->br_wbr;
35265 + static const struct qstr base_name[] = {
35266 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35267 + sizeof(AUFS_BASE_NAME) - 1),
35268 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35269 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35270 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35271 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35273 + struct au_wh_base base[] = {
35274 + [AuBrWh_BASE] = {
35275 + .name = base_name + AuBrWh_BASE,
35278 + [AuBrWh_PLINK] = {
35279 + .name = base_name + AuBrWh_PLINK,
35282 + [AuBrWh_ORPH] = {
35283 + .name = base_name + AuBrWh_ORPH,
35289 + WbrWhMustWriteLock(wbr);
35291 + for (i = 0; i < AuBrWh_Last; i++) {
35292 + /* doubly whiteouted */
35293 + struct dentry *d;
35295 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35296 + err = PTR_ERR(d);
35300 + base[i].dentry = d;
35302 + && wbr->wbr_wh[i]
35303 + && wbr->wbr_wh[i] != base[i].dentry);
35307 + for (i = 0; i < AuBrWh_Last; i++) {
35308 + dput(wbr->wbr_wh[i]);
35309 + wbr->wbr_wh[i] = NULL;
35313 + if (!au_br_writable(br->br_perm)) {
35314 + h_dir = d_inode(h_root);
35315 + au_wh_init_ro(h_dir, base, &path);
35316 + } else if (!au_br_wh_linkable(br->br_perm)) {
35317 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35323 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35329 + goto out; /* success */
35332 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35333 + err, h_root, au_sbtype(h_root->d_sb));
35335 + for (i = 0; i < AuBrWh_Last; i++)
35336 + dput(base[i].dentry);
35340 +/* ---------------------------------------------------------------------- */
35342 + * whiteouts are all hard-linked usually.
35343 + * when its link count reaches a ceiling, we create a new whiteout base
35344 + * asynchronously.
35347 +struct reinit_br_wh {
35348 + struct super_block *sb;
35349 + struct au_branch *br;
35352 +static void reinit_br_wh(void *arg)
35355 + aufs_bindex_t bindex;
35356 + struct path h_path;
35357 + struct reinit_br_wh *a = arg;
35358 + struct au_wbr *wbr;
35359 + struct inode *dir, *delegated;
35360 + struct dentry *h_root;
35361 + struct au_hinode *hdir;
35364 + wbr = a->br->br_wbr;
35365 + /* big aufs lock */
35366 + si_noflush_write_lock(a->sb);
35367 + if (!au_br_writable(a->br->br_perm))
35369 + bindex = au_br_index(a->sb, a->br->br_id);
35370 + if (unlikely(bindex < 0))
35373 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35374 + dir = d_inode(a->sb->s_root);
35375 + hdir = au_hi(dir, bindex);
35376 + h_root = au_h_dptr(a->sb->s_root, bindex);
35377 + AuDebugOn(h_root != au_br_dentry(a->br));
35379 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35380 + wbr_wh_write_lock(wbr);
35381 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35384 + h_path.dentry = wbr->wbr_whbase;
35385 + h_path.mnt = au_br_mnt(a->br);
35386 + delegated = NULL;
35387 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35389 + if (unlikely(err == -EWOULDBLOCK)) {
35390 + pr_warn("cannot retry for NFSv4 delegation"
35391 + " for an internal unlink\n");
35395 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35398 + dput(wbr->wbr_whbase);
35399 + wbr->wbr_whbase = NULL;
35401 + err = au_wh_init(a->br, a->sb);
35402 + wbr_wh_write_unlock(wbr);
35403 + au_hn_inode_unlock(hdir);
35404 + di_read_unlock(a->sb->s_root, AuLock_IR);
35406 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35410 + atomic_dec(&wbr->wbr_wh_running);
35411 + au_lcnt_dec(&a->br->br_count);
35412 + si_write_unlock(a->sb);
35413 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35415 + if (unlikely(err))
35416 + AuIOErr("err %d\n", err);
35419 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35421 + int do_dec, wkq_err;
35422 + struct reinit_br_wh *arg;
35425 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35428 + /* ignore ENOMEM */
35429 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35432 + * dec(wh_running), kfree(arg) and dec(br_count)
35433 + * in reinit function
35437 + au_lcnt_inc(&br->br_count);
35438 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35439 + if (unlikely(wkq_err)) {
35440 + atomic_dec(&br->br_wbr->wbr_wh_running);
35441 + au_lcnt_dec(&br->br_count);
35442 + au_kfree_rcu(arg);
35449 + atomic_dec(&br->br_wbr->wbr_wh_running);
35452 +/* ---------------------------------------------------------------------- */
35455 + * create the whiteout @wh.
35457 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35458 + struct dentry *wh)
35461 + struct path h_path = {
35464 + struct au_branch *br;
35465 + struct au_wbr *wbr;
35466 + struct dentry *h_parent;
35467 + struct inode *h_dir, *delegated;
35469 + h_parent = wh->d_parent; /* dir inode is locked */
35470 + h_dir = d_inode(h_parent);
35471 + IMustLock(h_dir);
35473 + br = au_sbr(sb, bindex);
35474 + h_path.mnt = au_br_mnt(br);
35475 + wbr = br->br_wbr;
35476 + wbr_wh_read_lock(wbr);
35477 + if (wbr->wbr_whbase) {
35478 + delegated = NULL;
35479 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35480 + if (unlikely(err == -EWOULDBLOCK)) {
35481 + pr_warn("cannot retry for NFSv4 delegation"
35482 + " for an internal link\n");
35485 + if (!err || err != -EMLINK)
35488 + /* link count full. re-initialize br_whbase. */
35489 + kick_reinit_br_wh(sb, br);
35492 + /* return this error in this context */
35493 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35495 + au_fhsm_wrote(sb, bindex, /*force*/0);
35498 + wbr_wh_read_unlock(wbr);
35502 +/* ---------------------------------------------------------------------- */
35505 + * create or remove the diropq.
35507 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35508 + unsigned int flags)
35510 + struct dentry *opq_dentry, *h_dentry;
35511 + struct super_block *sb;
35512 + struct au_branch *br;
35515 + sb = dentry->d_sb;
35516 + br = au_sbr(sb, bindex);
35517 + h_dentry = au_h_dptr(dentry, bindex);
35518 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35519 + if (IS_ERR(opq_dentry))
35522 + if (au_ftest_diropq(flags, CREATE)) {
35523 + err = link_or_create_wh(sb, bindex, opq_dentry);
35525 + au_set_dbdiropq(dentry, bindex);
35526 + goto out; /* success */
35529 + struct path tmp = {
35530 + .dentry = opq_dentry,
35531 + .mnt = au_br_mnt(br)
35533 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35535 + au_set_dbdiropq(dentry, -1);
35537 + dput(opq_dentry);
35538 + opq_dentry = ERR_PTR(err);
35541 + return opq_dentry;
35544 +struct do_diropq_args {
35545 + struct dentry **errp;
35546 + struct dentry *dentry;
35547 + aufs_bindex_t bindex;
35548 + unsigned int flags;
35551 +static void call_do_diropq(void *args)
35553 + struct do_diropq_args *a = args;
35554 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35557 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35558 + unsigned int flags)
35560 + struct dentry *diropq, *h_dentry;
35562 + h_dentry = au_h_dptr(dentry, bindex);
35563 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35564 + diropq = do_diropq(dentry, bindex, flags);
35567 + struct do_diropq_args args = {
35569 + .dentry = dentry,
35570 + .bindex = bindex,
35574 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35575 + if (unlikely(wkq_err))
35576 + diropq = ERR_PTR(wkq_err);
35582 +/* ---------------------------------------------------------------------- */
35585 + * lookup whiteout dentry.
35586 + * @h_parent: lower parent dentry which must exist and be locked
35587 + * @base_name: name of dentry which will be whiteouted
35588 + * returns dentry for whiteout.
35590 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35591 + struct au_branch *br)
35594 + struct qstr wh_name;
35595 + struct dentry *wh_dentry;
35597 + err = au_wh_name_alloc(&wh_name, base_name);
35598 + wh_dentry = ERR_PTR(err);
35600 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35601 + au_kfree_try_rcu(wh_name.name);
35603 + return wh_dentry;
35607 + * link/create a whiteout for @dentry on @bindex.
35609 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35610 + struct dentry *h_parent)
35612 + struct dentry *wh_dentry;
35613 + struct super_block *sb;
35616 + sb = dentry->d_sb;
35617 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35618 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35619 + err = link_or_create_wh(sb, bindex, wh_dentry);
35621 + au_set_dbwh(dentry, bindex);
35622 + au_fhsm_wrote(sb, bindex, /*force*/0);
35625 + wh_dentry = ERR_PTR(err);
35629 + return wh_dentry;
35632 +/* ---------------------------------------------------------------------- */
35634 +/* Delete all whiteouts in this directory on branch bindex. */
35635 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35636 + aufs_bindex_t bindex, struct au_branch *br)
35639 + unsigned long ul, n;
35640 + struct qstr wh_name;
35642 + struct hlist_head *head;
35643 + struct au_vdir_wh *pos;
35644 + struct au_vdir_destr *str;
35647 + p = (void *)__get_free_page(GFP_NOFS);
35648 + wh_name.name = p;
35649 + if (unlikely(!wh_name.name))
35653 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35654 + p += AUFS_WH_PFX_LEN;
35655 + n = whlist->nh_num;
35656 + head = whlist->nh_head;
35657 + for (ul = 0; !err && ul < n; ul++, head++) {
35658 + hlist_for_each_entry(pos, head, wh_hash) {
35659 + if (pos->wh_bindex != bindex)
35662 + str = &pos->wh_str;
35663 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35664 + memcpy(p, str->name, str->len);
35665 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35666 + err = unlink_wh_name(h_dentry, &wh_name, br);
35671 + AuIOErr("whiteout name too long %.*s\n",
35672 + str->len, str->name);
35677 + free_page((unsigned long)wh_name.name);
35683 +struct del_wh_children_args {
35685 + struct dentry *h_dentry;
35686 + struct au_nhash *whlist;
35687 + aufs_bindex_t bindex;
35688 + struct au_branch *br;
35691 +static void call_del_wh_children(void *args)
35693 + struct del_wh_children_args *a = args;
35694 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35697 +/* ---------------------------------------------------------------------- */
35699 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35701 + struct au_whtmp_rmdir *whtmp;
35703 + unsigned int rdhash;
35705 + SiMustAnyLock(sb);
35707 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35708 + if (unlikely(!whtmp)) {
35709 + whtmp = ERR_PTR(-ENOMEM);
35713 + /* no estimation for dir size */
35714 + rdhash = au_sbi(sb)->si_rdhash;
35716 + rdhash = AUFS_RDHASH_DEF;
35717 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35718 + if (unlikely(err)) {
35719 + au_kfree_rcu(whtmp);
35720 + whtmp = ERR_PTR(err);
35727 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35730 + au_lcnt_dec(&whtmp->br->br_count);
35731 + dput(whtmp->wh_dentry);
35732 + iput(whtmp->dir);
35733 + au_nhash_wh_free(&whtmp->whlist);
35734 + au_kfree_rcu(whtmp);
35738 + * rmdir the whiteouted temporary named dir @h_dentry.
35739 + * @whlist: whiteouted children.
35741 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35742 + struct dentry *wh_dentry, struct au_nhash *whlist)
35745 + unsigned int h_nlink;
35746 + struct path h_tmp;
35747 + struct inode *wh_inode, *h_dir;
35748 + struct au_branch *br;
35750 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35751 + IMustLock(h_dir);
35753 + br = au_sbr(dir->i_sb, bindex);
35754 + wh_inode = d_inode(wh_dentry);
35755 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35758 + * someone else might change some whiteouts while we were sleeping.
35759 + * it means this whlist may have an obsoleted entry.
35761 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35762 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35765 + struct del_wh_children_args args = {
35767 + .h_dentry = wh_dentry,
35768 + .whlist = whlist,
35769 + .bindex = bindex,
35773 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35774 + if (unlikely(wkq_err))
35777 + inode_unlock(wh_inode);
35780 + h_tmp.dentry = wh_dentry;
35781 + h_tmp.mnt = au_br_mnt(br);
35782 + h_nlink = h_dir->i_nlink;
35783 + err = vfsub_rmdir(h_dir, &h_tmp);
35784 + /* some fs doesn't change the parent nlink in some cases */
35785 + h_nlink -= h_dir->i_nlink;
35789 + if (au_ibtop(dir) == bindex) {
35790 + /* todo: dir->i_mutex is necessary */
35791 + au_cpup_attr_timesizes(dir);
35793 + vfsub_drop_nlink(dir);
35795 + return 0; /* success */
35798 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35802 +static void call_rmdir_whtmp(void *args)
35805 + aufs_bindex_t bindex;
35806 + struct au_whtmp_rmdir *a = args;
35807 + struct super_block *sb;
35808 + struct dentry *h_parent;
35809 + struct inode *h_dir;
35810 + struct au_hinode *hdir;
35812 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35813 + /* inode_lock(a->dir); */
35815 + sb = a->dir->i_sb;
35816 + si_read_lock(sb, !AuLock_FLUSH);
35817 + if (!au_br_writable(a->br->br_perm))
35819 + bindex = au_br_index(sb, a->br->br_id);
35820 + if (unlikely(bindex < 0))
35824 + ii_write_lock_parent(a->dir);
35825 + h_parent = dget_parent(a->wh_dentry);
35826 + h_dir = d_inode(h_parent);
35827 + hdir = au_hi(a->dir, bindex);
35828 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35829 + if (unlikely(err))
35831 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35832 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35835 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35836 + au_hn_inode_unlock(hdir);
35837 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35841 + ii_write_unlock(a->dir);
35843 + /* inode_unlock(a->dir); */
35844 + au_whtmp_rmdir_free(a);
35845 + si_read_unlock(sb);
35846 + au_nwt_done(&au_sbi(sb)->si_nowait);
35847 + if (unlikely(err))
35848 + AuIOErr("err %d\n", err);
35851 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35852 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35855 + struct super_block *sb;
35859 + /* all post-process will be done in do_rmdir_whtmp(). */
35861 + args->dir = au_igrab(dir);
35862 + args->br = au_sbr(sb, bindex);
35863 + au_lcnt_inc(&args->br->br_count);
35864 + args->wh_dentry = dget(wh_dentry);
35865 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35866 + if (unlikely(wkq_err)) {
35867 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35868 + au_whtmp_rmdir_free(args);
35871 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35872 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35873 +++ linux/fs/aufs/whout.h 2020-01-27 10:57:18.178871751 +0100
35875 +/* SPDX-License-Identifier: GPL-2.0 */
35877 + * Copyright (C) 2005-2020 Junjiro R. Okajima
35879 + * This program, aufs is free software; you can redistribute it and/or modify
35880 + * it under the terms of the GNU General Public License as published by
35881 + * the Free Software Foundation; either version 2 of the License, or
35882 + * (at your option) any later version.
35884 + * This program is distributed in the hope that it will be useful,
35885 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35886 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35887 + * GNU General Public License for more details.
35889 + * You should have received a copy of the GNU General Public License
35890 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35894 + * whiteout for logical deletion and opaque directory
35897 +#ifndef __AUFS_WHOUT_H__
35898 +#define __AUFS_WHOUT_H__
35905 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35906 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
35907 +int au_diropq_test(struct dentry *h_dentry);
35909 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35910 + struct qstr *prefix);
35911 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35912 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35913 + struct dentry *dentry);
35914 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35916 +/* diropq flags */
35917 +#define AuDiropq_CREATE 1
35918 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35919 +#define au_fset_diropq(flags, name) \
35920 + do { (flags) |= AuDiropq_##name; } while (0)
35921 +#define au_fclr_diropq(flags, name) \
35922 + do { (flags) &= ~AuDiropq_##name; } while (0)
35924 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35925 + unsigned int flags);
35926 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35927 + struct au_branch *br);
35928 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35929 + struct dentry *h_parent);
35931 +/* real rmdir for the whiteout-ed dir */
35932 +struct au_whtmp_rmdir {
35933 + struct inode *dir;
35934 + struct au_branch *br;
35935 + struct dentry *wh_dentry;
35936 + struct au_nhash whlist;
35939 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35940 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35941 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35942 + struct dentry *wh_dentry, struct au_nhash *whlist);
35943 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35944 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35946 +/* ---------------------------------------------------------------------- */
35948 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35949 + aufs_bindex_t bindex)
35951 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35954 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35956 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35959 +#endif /* __KERNEL__ */
35960 +#endif /* __AUFS_WHOUT_H__ */
35961 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35962 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35963 +++ linux/fs/aufs/wkq.c 2020-08-03 09:12:33.764880472 +0200
35965 +// SPDX-License-Identifier: GPL-2.0
35967 + * Copyright (C) 2005-2020 Junjiro R. Okajima
35969 + * This program, aufs is free software; you can redistribute it and/or modify
35970 + * it under the terms of the GNU General Public License as published by
35971 + * the Free Software Foundation; either version 2 of the License, or
35972 + * (at your option) any later version.
35974 + * This program is distributed in the hope that it will be useful,
35975 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35976 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35977 + * GNU General Public License for more details.
35979 + * You should have received a copy of the GNU General Public License
35980 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35984 + * workqueue for asynchronous/super-io operations
35985 + * todo: try new credential scheme
35988 +#include <linux/module.h>
35991 +/* internal workqueue named AUFS_WKQ_NAME */
35993 +static struct workqueue_struct *au_wkq;
35995 +struct au_wkinfo {
35996 + struct work_struct wk;
35997 + struct kobject *kobj;
35999 + unsigned int flags; /* see wkq.h */
36001 + au_wkq_func_t func;
36004 +#ifdef CONFIG_LOCKDEP
36006 + struct held_lock **hlock;
36009 + struct completion *comp;
36012 +/* ---------------------------------------------------------------------- */
36014 + * Aufs passes some operations to the workqueue such as the internal copyup.
36015 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36016 + * job run by workqueue depends upon the locks acquired in the other task.
36017 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36018 + * information too. And the job in the workqueue restores the info in order to
36019 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36020 + * correctly and expectedly.
36023 +#ifndef CONFIG_LOCKDEP
36024 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36025 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36026 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36027 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36028 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36030 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36032 + wkinfo->hlock = NULL;
36033 + wkinfo->dont_check = 0;
36040 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36042 + static DEFINE_SPINLOCK(spin);
36045 + struct lock_class_key *key;
36047 + { .name = "&sbinfo->si_rwsem" },
36048 + { .name = "&finfo->fi_rwsem" },
36049 + { .name = "&dinfo->di_rwsem" },
36050 + { .name = "&iinfo->ii_rwsem" }
36055 + /* lockless read from 'set.' see below */
36056 + if (set == ARRAY_SIZE(a)) {
36057 + for (i = 0; i < ARRAY_SIZE(a); i++)
36058 + if (a[i].key == key)
36063 + spin_lock(&spin);
36065 + for (i = 0; i < ARRAY_SIZE(a); i++)
36066 + if (a[i].key == key) {
36067 + spin_unlock(&spin);
36070 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36072 + if (unlikely(a[i].key == key)) { /* rare but possible */
36073 + spin_unlock(&spin);
36078 + if (strstr(a[i].name, name)) {
36080 + * the order of these three lines is important for the
36081 + * lockless read above.
36084 + spin_unlock(&spin);
36086 + /* AuDbg("%d, %s\n", set, name); */
36090 + spin_unlock(&spin);
36099 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36102 + struct task_struct *curr;
36103 + struct held_lock **hl, *held_locks, *p;
36107 + wkinfo->dont_check = lockdep_recursing(curr);
36108 + if (wkinfo->dont_check)
36110 + n = curr->lockdep_depth;
36115 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36116 + if (unlikely(!wkinfo->hlock))
36120 +#if 0 /* left for debugging */
36121 + if (0 && au_debug_test())
36122 + lockdep_print_held_locks(curr);
36124 + held_locks = curr->held_locks;
36125 + hl = wkinfo->hlock;
36127 + p = held_locks++;
36128 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36137 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36139 + au_kfree_try_rcu(wkinfo->hlock);
36142 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36144 + struct held_lock *p, **hl = wkinfo->hlock;
36147 + if (wkinfo->dont_check)
36151 + while ((p = *hl++)) { /* assignment */
36152 + subclass = lockdep_hlock_class(p)->subclass;
36153 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36155 + rwsem_acquire_read(p->instance, subclass, 0,
36156 + /*p->acquire_ip*/_RET_IP_);
36158 + rwsem_acquire(p->instance, subclass, 0,
36159 + /*p->acquire_ip*/_RET_IP_);
36163 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36165 + struct held_lock *p, **hl = wkinfo->hlock;
36167 + if (wkinfo->dont_check)
36171 + while ((p = *hl++)) /* assignment */
36172 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36176 +static void wkq_func(struct work_struct *wk)
36178 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36180 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36181 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36183 + au_wkq_lockdep_pre(wkinfo);
36184 + wkinfo->func(wkinfo->args);
36185 + au_wkq_lockdep_post(wkinfo);
36186 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36187 + complete(wkinfo->comp);
36189 + kobject_put(wkinfo->kobj);
36190 + module_put(THIS_MODULE); /* todo: ?? */
36191 + au_kfree_rcu(wkinfo);
36196 + * Since struct completion is large, try allocating it dynamically.
36198 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36200 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36202 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36204 + init_completion(*comp);
36205 + wkinfo->comp = *comp;
36211 +static void au_wkq_comp_free(struct completion *comp)
36213 + au_kfree_rcu(comp);
36216 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36218 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36219 + if (au_wkq_test()) {
36220 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36221 + " due to a dead dir by UDBA,"
36222 + " or async xino write?\n");
36223 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36226 + au_dbg_verify_kthread();
36228 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36229 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36230 + queue_work(au_wkq, &wkinfo->wk);
36232 + INIT_WORK(&wkinfo->wk, wkq_func);
36233 + schedule_work(&wkinfo->wk);
36238 + * Be careful. It is easy to make deadlock happen.
36239 + * processA: lock, wkq and wait
36240 + * processB: wkq and wait, lock in wkq
36243 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36246 + AuWkqCompDeclare(comp);
36247 + struct au_wkinfo wkinfo = {
36253 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36254 + if (unlikely(err))
36256 + err = au_wkq_lockdep_alloc(&wkinfo);
36257 + if (unlikely(err))
36260 + au_wkq_run(&wkinfo);
36261 + /* no timeout, no interrupt */
36262 + wait_for_completion(wkinfo.comp);
36264 + au_wkq_lockdep_free(&wkinfo);
36267 + au_wkq_comp_free(comp);
36269 + destroy_work_on_stack(&wkinfo.wk);
36274 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36275 + * problem in a concurrent umounting.
36277 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36278 + unsigned int flags)
36281 + struct au_wkinfo *wkinfo;
36283 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36286 + * wkq_func() must free this wkinfo.
36287 + * it highly depends upon the implementation of workqueue.
36290 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36292 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36293 + wkinfo->flags = flags & ~AuWkq_WAIT;
36294 + wkinfo->func = func;
36295 + wkinfo->args = args;
36296 + wkinfo->comp = NULL;
36297 + au_wkq_lockdep_init(wkinfo);
36298 + kobject_get(wkinfo->kobj);
36299 + __module_get(THIS_MODULE); /* todo: ?? */
36301 + au_wkq_run(wkinfo);
36304 + au_nwt_done(&au_sbi(sb)->si_nowait);
36310 +/* ---------------------------------------------------------------------- */
36312 +void au_nwt_init(struct au_nowait_tasks *nwt)
36314 + atomic_set(&nwt->nw_len, 0);
36315 + /* smp_mb(); */ /* atomic_set */
36316 + init_waitqueue_head(&nwt->nw_wq);
36319 +void au_wkq_fin(void)
36321 + destroy_workqueue(au_wkq);
36324 +int __init au_wkq_init(void)
36329 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36330 + if (IS_ERR(au_wkq))
36331 + err = PTR_ERR(au_wkq);
36332 + else if (!au_wkq)
36337 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36338 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36339 +++ linux/fs/aufs/wkq.h 2020-01-27 10:57:18.182205184 +0100
36341 +/* SPDX-License-Identifier: GPL-2.0 */
36343 + * Copyright (C) 2005-2020 Junjiro R. Okajima
36345 + * This program, aufs is free software; you can redistribute it and/or modify
36346 + * it under the terms of the GNU General Public License as published by
36347 + * the Free Software Foundation; either version 2 of the License, or
36348 + * (at your option) any later version.
36350 + * This program is distributed in the hope that it will be useful,
36351 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36352 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36353 + * GNU General Public License for more details.
36355 + * You should have received a copy of the GNU General Public License
36356 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36360 + * workqueue for asynchronous/super-io operations
36361 + * todo: try new credentials management scheme
36364 +#ifndef __AUFS_WKQ_H__
36365 +#define __AUFS_WKQ_H__
36369 +#include <linux/wait.h>
36371 +struct super_block;
36373 +/* ---------------------------------------------------------------------- */
36376 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36378 +struct au_nowait_tasks {
36380 + wait_queue_head_t nw_wq;
36383 +/* ---------------------------------------------------------------------- */
36385 +typedef void (*au_wkq_func_t)(void *args);
36388 +#define AuWkq_WAIT 1
36389 +#define AuWkq_NEST (1 << 1)
36390 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36391 +#define au_fset_wkq(flags, name) \
36392 + do { (flags) |= AuWkq_##name; } while (0)
36393 +#define au_fclr_wkq(flags, name) \
36394 + do { (flags) &= ~AuWkq_##name; } while (0)
36397 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36398 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36399 + unsigned int flags);
36400 +void au_nwt_init(struct au_nowait_tasks *nwt);
36401 +int __init au_wkq_init(void);
36402 +void au_wkq_fin(void);
36404 +/* ---------------------------------------------------------------------- */
36406 +static inline int au_wkq_test(void)
36408 + return current->flags & PF_WQ_WORKER;
36411 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36413 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36416 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36418 + if (atomic_dec_and_test(&nwt->nw_len))
36419 + wake_up_all(&nwt->nw_wq);
36422 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36424 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36428 +#endif /* __KERNEL__ */
36429 +#endif /* __AUFS_WKQ_H__ */
36430 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36431 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36432 +++ linux/fs/aufs/xattr.c 2020-08-03 09:14:46.095748745 +0200
36434 +// SPDX-License-Identifier: GPL-2.0
36436 + * Copyright (C) 2014-2020 Junjiro R. Okajima
36438 + * This program, aufs is free software; you can redistribute it and/or modify
36439 + * it under the terms of the GNU General Public License as published by
36440 + * the Free Software Foundation; either version 2 of the License, or
36441 + * (at your option) any later version.
36443 + * This program is distributed in the hope that it will be useful,
36444 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36445 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36446 + * GNU General Public License for more details.
36448 + * You should have received a copy of the GNU General Public License
36449 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36453 + * handling xattr functions
36456 +#include <linux/fs.h>
36457 +#include <linux/posix_acl_xattr.h>
36458 +#include <linux/xattr.h>
36461 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36463 + if (!ignore_flags)
36471 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36476 +#define cmp(brattr, prefix) do { \
36477 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36478 + XATTR_##prefix##_PREFIX_LEN)) { \
36479 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36485 + cmp(SEC, SECURITY);
36486 + cmp(SYS, SYSTEM);
36487 + cmp(TR, TRUSTED);
36491 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36498 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36500 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36501 + char *name, char **buf, unsigned int ignore_flags,
36502 + unsigned int verbose)
36506 + struct inode *h_idst;
36508 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36510 + if (unlikely(err <= 0)) {
36511 + if (err == -ENODATA
36512 + || (err == -EOPNOTSUPP
36513 + && ((ignore_flags & au_xattr_out_of_list)
36514 + || (au_test_nfs_noacl(d_inode(h_src))
36515 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36517 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36520 + if (err && (verbose || au_debug_test()))
36521 + pr_err("%s, err %d\n", name, err);
36525 + /* unlock it temporary */
36526 + h_idst = d_inode(h_dst);
36527 + inode_unlock(h_idst);
36528 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36529 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36530 + if (unlikely(err)) {
36531 + if (verbose || au_debug_test())
36532 + pr_err("%s, err %d\n", name, err);
36533 + err = au_xattr_ignore(err, name, ignore_flags);
36540 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36541 + unsigned int verbose)
36543 + int err, unlocked, acl_access, acl_default;
36545 + struct inode *h_isrc, *h_idst;
36546 + char *value, *p, *o, *e;
36548 + /* try stopping to update the source inode while we are referencing */
36549 + /* there should not be the parent-child relationship between them */
36550 + h_isrc = d_inode(h_src);
36551 + h_idst = d_inode(h_dst);
36552 + inode_unlock(h_idst);
36553 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36554 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36557 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36558 + ssz = vfs_listxattr(h_src, NULL, 0);
36560 + if (unlikely(err < 0)) {
36562 + if (err == -ENODATA
36563 + || err == -EOPNOTSUPP)
36564 + err = 0; /* ignore */
36573 + p = kmalloc(ssz, GFP_NOFS);
36575 + if (unlikely(!p))
36577 + err = vfs_listxattr(h_src, p, ssz);
36579 + inode_unlock_shared(h_isrc);
36581 + AuDbg("err %d, ssz %zd\n", err, ssz);
36582 + if (unlikely(err < 0))
36590 + while (!err && p < e) {
36591 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36592 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36593 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36594 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36596 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36598 + p += strlen(p) + 1;
36601 + ignore_flags |= au_xattr_out_of_list;
36602 + if (!err && !acl_access) {
36603 + err = au_do_cpup_xattr(h_dst, h_src,
36604 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36605 + ignore_flags, verbose);
36608 + if (!err && !acl_default) {
36609 + err = au_do_cpup_xattr(h_dst, h_src,
36610 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36611 + ignore_flags, verbose);
36615 + au_kfree_try_rcu(value);
36618 + au_kfree_try_rcu(o);
36621 + inode_unlock_shared(h_isrc);
36626 +/* ---------------------------------------------------------------------- */
36628 +static int au_smack_reentering(struct super_block *sb)
36630 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36632 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36633 + * i_op->getxattr(). ouch.
36635 + return si_pid_test(sb);
36646 +struct au_lgxattr {
36654 + const char *name;
36661 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36662 + struct au_lgxattr *arg)
36666 + struct path h_path;
36667 + struct super_block *sb;
36669 + sb = dentry->d_sb;
36670 + reenter = au_smack_reentering(sb);
36672 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36673 + if (unlikely(err))
36676 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
36677 + if (unlikely(err))
36679 + if (unlikely(!h_path.dentry))
36680 + /* illegally overlapped or something */
36681 + goto out_di; /* pretending success */
36683 + /* always topmost entry only */
36684 + switch (arg->type) {
36685 + case AU_XATTR_LIST:
36686 + err = vfs_listxattr(h_path.dentry,
36687 + arg->u.list.list, arg->u.list.size);
36689 + case AU_XATTR_GET:
36690 + AuDebugOn(d_is_negative(h_path.dentry));
36691 + err = vfs_getxattr(h_path.dentry,
36692 + arg->u.get.name, arg->u.get.value,
36693 + arg->u.get.size);
36699 + di_read_unlock(dentry, AuLock_IR);
36702 + si_read_unlock(sb);
36708 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36710 + struct au_lgxattr arg = {
36711 + .type = AU_XATTR_LIST,
36718 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
36721 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
36722 + const char *name, void *value, size_t size)
36724 + struct au_lgxattr arg = {
36725 + .type = AU_XATTR_GET,
36733 + return au_lgxattr(dentry, inode, &arg);
36736 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36737 + const char *name, const void *value, size_t size,
36740 + struct au_sxattr arg = {
36741 + .type = AU_XATTR_SET,
36750 + return au_sxattr(dentry, inode, &arg);
36753 +/* ---------------------------------------------------------------------- */
36755 +static int au_xattr_get(const struct xattr_handler *handler,
36756 + struct dentry *dentry, struct inode *inode,
36757 + const char *name, void *buffer, size_t size)
36759 + return au_getxattr(dentry, inode, name, buffer, size);
36762 +static int au_xattr_set(const struct xattr_handler *handler,
36763 + struct dentry *dentry, struct inode *inode,
36764 + const char *name, const void *value, size_t size,
36767 + return au_setxattr(dentry, inode, name, value, size, flags);
36770 +static const struct xattr_handler au_xattr_handler = {
36773 + .get = au_xattr_get,
36774 + .set = au_xattr_set
36777 +static const struct xattr_handler *au_xattr_handlers[] = {
36778 +#ifdef CONFIG_FS_POSIX_ACL
36779 + &posix_acl_access_xattr_handler,
36780 + &posix_acl_default_xattr_handler,
36782 + &au_xattr_handler, /* must be last */
36786 +void au_xattr_init(struct super_block *sb)
36788 + sb->s_xattr = au_xattr_handlers;
36790 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36791 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36792 +++ linux/fs/aufs/xino.c 2020-04-03 08:16:49.834195677 +0200
36794 +// SPDX-License-Identifier: GPL-2.0
36796 + * Copyright (C) 2005-2020 Junjiro R. Okajima
36798 + * This program, aufs is free software; you can redistribute it and/or modify
36799 + * it under the terms of the GNU General Public License as published by
36800 + * the Free Software Foundation; either version 2 of the License, or
36801 + * (at your option) any later version.
36803 + * This program is distributed in the hope that it will be useful,
36804 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36805 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36806 + * GNU General Public License for more details.
36808 + * You should have received a copy of the GNU General Public License
36809 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36813 + * external inode number translation table and bitmap
36815 + * things to consider
36817 + * + au_xino object
36818 + * + XINO files (xino, xib, xigen)
36819 + * + dynamic debugfs entries (xiN)
36820 + * + static debugfs entries (xib, xigen)
36821 + * + static sysfs entry (xi_path)
36822 + * - several entry points to handle them.
36823 + * + mount(2) without xino option (default)
36824 + * + mount(2) with xino option
36825 + * + mount(2) with noxino option
36827 + * + remount with add/del branches
36828 + * + remount with xino/noxino options
36831 +#include <linux/seq_file.h>
36832 +#include <linux/statfs.h>
36835 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36836 + aufs_bindex_t bbot,
36837 + struct super_block *h_sb)
36839 + /* todo: try binary-search if the branches are many */
36840 + for (; btop <= bbot; btop++)
36841 + if (h_sb == au_sbr_sb(sb, btop))
36847 + * find another branch who is on the same filesystem of the specified
36848 + * branch{@btgt}. search until @bbot.
36850 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36851 + aufs_bindex_t bbot)
36853 + aufs_bindex_t bindex;
36854 + struct super_block *tgt_sb;
36856 + tgt_sb = au_sbr_sb(sb, btgt);
36857 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36859 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36864 +/* ---------------------------------------------------------------------- */
36867 + * stop unnecessary notify events at creating xino files
36870 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
36872 + aufs_bindex_t bfound, bindex, bbot;
36873 + struct dentry *parent;
36874 + struct au_branch *br;
36877 + parent = dentry->d_parent; /* safe d_parent access */
36878 + bbot = au_sbbot(sb);
36879 + for (bindex = 0; bindex <= bbot; bindex++) {
36880 + br = au_sbr(sb, bindex);
36881 + if (au_br_dentry(br) == parent) {
36887 + AuDbg("bfound b%d\n", bfound);
36891 +struct au_xino_lock_dir {
36892 + struct au_hinode *hdir;
36893 + struct dentry *parent;
36894 + struct inode *dir;
36897 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
36898 + unsigned int lsc)
36900 + struct dentry *parent;
36901 + struct inode *dir;
36903 + parent = dget_parent(dentry);
36904 + dir = d_inode(parent);
36905 + inode_lock_nested(dir, lsc);
36906 +#if 0 /* it should not happen */
36907 + spin_lock(&dentry->d_lock);
36908 + if (unlikely(dentry->d_parent != parent)) {
36909 + spin_unlock(&dentry->d_lock);
36910 + inode_unlock(dir);
36915 + spin_unlock(&dentry->d_lock);
36922 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
36923 + struct au_xino_lock_dir *ldir)
36925 + aufs_bindex_t bindex;
36927 + ldir->hdir = NULL;
36928 + bindex = au_xi_root(sb, xipath->dentry);
36929 + if (bindex >= 0) {
36930 + /* rw branch root */
36931 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36932 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36935 + ldir->parent = au_dget_parent_lock(xipath->dentry,
36937 + ldir->dir = d_inode(ldir->parent);
36941 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36944 + au_hn_inode_unlock(ldir->hdir);
36946 + inode_unlock(ldir->dir);
36947 + dput(ldir->parent);
36951 +/* ---------------------------------------------------------------------- */
36954 + * create and set a new xino file
36956 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
36959 + struct file *file;
36960 + struct dentry *h_parent, *d;
36961 + struct inode *h_dir, *inode;
36963 + static DEFINE_MUTEX(mtx);
36966 + * at mount-time, and the xino file is the default path,
36967 + * hnotify is disabled so we have no notify events to ignore.
36968 + * when a user specified the xino, we cannot get au_hdir to be ignored.
36971 + mutex_lock(&mtx);
36972 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36973 + /* | __FMODE_NONOTIFY */,
36975 + if (IS_ERR(file)) {
36977 + mutex_unlock(&mtx);
36979 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
36983 + /* keep file count */
36985 + d = file->f_path.dentry;
36986 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
36988 + mutex_unlock(&mtx);
36989 + /* mnt_want_write() is unnecessary here */
36990 + h_dir = d_inode(h_parent);
36991 + inode = file_inode(file);
36992 + /* no delegation since it is just created */
36993 + if (inode->i_nlink)
36994 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
36996 + inode_unlock(h_dir);
36998 + if (unlikely(err)) {
37000 + pr_err("unlink %s(%d)\n", fpath, err);
37005 + if (unlikely(sb == d->d_sb)) {
37007 + pr_err("%s must be outside\n", fpath);
37010 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37012 + pr_err("xino doesn't support %s(%s)\n",
37013 + fpath, au_sbtype(d->d_sb));
37016 + return file; /* success */
37020 + file = ERR_PTR(err);
37025 + * create a new xinofile at the same place/path as @base.
37027 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37028 + struct file *copy_src)
37030 + struct file *file;
37031 + struct dentry *dentry, *parent;
37032 + struct inode *dir, *delegated;
37033 + struct qstr *name;
37034 + struct path path;
37035 + int err, do_unlock;
37036 + struct au_xino_lock_dir ldir;
37039 + au_xino_lock_dir(sb, base, &ldir);
37040 + dentry = base->dentry;
37041 + parent = dentry->d_parent; /* dir inode is locked */
37042 + dir = d_inode(parent);
37045 + name = &dentry->d_name;
37046 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
37047 + if (IS_ERR(path.dentry)) {
37048 + file = (void *)path.dentry;
37049 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37053 + /* no need to mnt_want_write() since we call dentry_open() later */
37054 + err = vfs_create(dir, path.dentry, 0666, NULL);
37055 + if (unlikely(err)) {
37056 + file = ERR_PTR(err);
37057 + pr_err("%pd create err %d\n", dentry, err);
37061 + path.mnt = base->mnt;
37062 + file = vfsub_dentry_open(&path,
37063 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37064 + /* | __FMODE_NONOTIFY */);
37065 + if (IS_ERR(file)) {
37066 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37070 + delegated = NULL;
37071 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37072 + au_xino_unlock_dir(&ldir);
37074 + if (unlikely(err == -EWOULDBLOCK)) {
37075 + pr_warn("cannot retry for NFSv4 delegation"
37076 + " for an internal unlink\n");
37079 + if (unlikely(err)) {
37080 + pr_err("%pd unlink err %d\n", dentry, err);
37085 + /* no one can touch copy_src xino */
37086 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37087 + if (unlikely(err)) {
37088 + pr_err("%pd copy err %d\n", dentry, err);
37092 + goto out_dput; /* success */
37096 + file = ERR_PTR(err);
37098 + dput(path.dentry);
37101 + au_xino_unlock_dir(&ldir);
37105 +struct file *au_xino_file1(struct au_xino *xi)
37107 + struct file *file;
37108 + unsigned int u, nfile;
37111 + nfile = xi->xi_nfile;
37112 + for (u = 0; u < nfile; u++) {
37113 + file = xi->xi_file[u];
37121 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37132 + if (idx < xi->xi_nfile) {
37133 + f = xi->xi_file[idx];
37137 + p = au_kzrealloc(xi->xi_file,
37138 + sizeof(*xi->xi_file) * xi->xi_nfile,
37139 + sizeof(*xi->xi_file) * (idx + 1),
37140 + GFP_NOFS, /*may_shrink*/0);
37142 + MtxMustLock(&xi->xi_mtx);
37144 + xi->xi_nfile = idx + 1;
37152 + xi->xi_file[idx] = file;
37159 + * if @xinew->xi is not set, then create new xigen file.
37161 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37163 + struct file *file;
37166 + SiMustAnyLock(sb);
37168 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37169 + if (IS_ERR(file)) {
37170 + err = PTR_ERR(file);
37171 + pr_err("%s[%d], err %d\n",
37172 + xinew->xi ? "xino" : "xigen",
37173 + xinew->idx, err);
37178 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37181 + /* todo: make xigen file an array */
37182 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37185 + if (unlikely(err))
37186 + file = ERR_PTR(err);
37192 +/* ---------------------------------------------------------------------- */
37195 + * truncate xino files
37197 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37198 + int idx, struct kstatfs *st)
37202 + struct file *file, *new_xino;
37203 + struct au_xi_new xinew = {
37208 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37209 + file = au_xino_file(xinew.xi, idx);
37213 + xinew.base = &file->f_path;
37214 + err = vfs_statfs(xinew.base, st);
37215 + if (unlikely(err)) {
37216 + AuErr1("statfs err %d, ignored\n", err);
37221 + blocks = file_inode(file)->i_blocks;
37222 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37223 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37225 + xinew.copy_src = file;
37226 + new_xino = au_xi_new(sb, &xinew);
37227 + if (IS_ERR(new_xino)) {
37228 + err = PTR_ERR(new_xino);
37229 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37233 + err = vfs_statfs(&new_xino->f_path, st);
37235 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37236 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37237 + st->f_bfree, st->f_blocks);
37239 + AuErr1("statfs err %d, ignored\n", err);
37247 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37250 + unsigned long jiffy;
37251 + aufs_bindex_t bbot;
37252 + struct kstatfs *st;
37253 + struct au_branch *br;
37254 + struct au_xino *xi;
37257 + st = kmalloc(sizeof(*st), GFP_NOFS);
37258 + if (unlikely(!st))
37262 + bbot = au_sbbot(sb);
37263 + if (unlikely(bindex < 0 || bbot < bindex))
37268 + br = au_sbr(sb, bindex);
37269 + xi = br->br_xino;
37270 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37271 + err = au_xino_do_trunc(sb, bindex, i, st);
37273 + au_sbi(sb)->si_xino_jiffy = jiffy;
37276 + au_kfree_rcu(st);
37281 +struct xino_do_trunc_args {
37282 + struct super_block *sb;
37283 + struct au_branch *br;
37287 +static void xino_do_trunc(void *_args)
37289 + struct xino_do_trunc_args *args = _args;
37290 + struct super_block *sb;
37291 + struct au_branch *br;
37292 + struct inode *dir;
37294 + aufs_bindex_t bindex;
37298 + dir = d_inode(sb->s_root);
37302 + si_noflush_write_lock(sb);
37303 + ii_read_lock_parent(dir);
37304 + bindex = au_br_index(sb, br->br_id);
37305 + err = au_xino_trunc(sb, bindex, idx);
37306 + ii_read_unlock(dir);
37307 + if (unlikely(err))
37308 + pr_warn("err b%d, (%d)\n", bindex, err);
37309 + atomic_dec(&br->br_xino->xi_truncating);
37310 + au_lcnt_dec(&br->br_count);
37311 + si_write_unlock(sb);
37312 + au_nwt_done(&au_sbi(sb)->si_nowait);
37313 + au_kfree_rcu(args);
37317 + * returns the index in the xi_file array whose corresponding file is necessary
37318 + * to truncate, or -1 which means no need to truncate.
37320 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37324 + struct kstatfs st;
37325 + struct au_sbinfo *sbinfo;
37326 + struct au_xino *xi;
37327 + struct file *file;
37329 + /* todo: si_xino_expire and the ratio should be customizable */
37330 + sbinfo = au_sbi(sb);
37331 + if (time_before(jiffies,
37332 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37335 + /* truncation border */
37336 + xi = br->br_xino;
37337 + for (u = 0; u < xi->xi_nfile; u++) {
37338 + file = au_xino_file(xi, u);
37342 + err = vfs_statfs(&file->f_path, &st);
37343 + if (unlikely(err)) {
37344 + AuErr1("statfs err %d, ignored\n", err);
37347 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37348 + >= AUFS_XINO_DEF_TRUNC)
37355 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37358 + struct xino_do_trunc_args *args;
37361 + idx = xino_trunc_test(sb, br);
37365 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37368 + /* lock and kfree() will be called in trunc_xino() */
37369 + args = kmalloc(sizeof(*args), GFP_NOFS);
37370 + if (unlikely(!args)) {
37371 + AuErr1("no memory\n");
37375 + au_lcnt_inc(&br->br_count);
37379 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37381 + return; /* success */
37383 + pr_err("wkq %d\n", wkq_err);
37384 + au_lcnt_dec(&br->br_count);
37385 + au_kfree_rcu(args);
37388 + atomic_dec(&br->br_xino->xi_truncating);
37391 +/* ---------------------------------------------------------------------- */
37393 +struct au_xi_calc {
37398 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37399 + struct au_xi_calc *calc)
37403 + maxent = au_xi_maxent(sb);
37404 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37405 + calc->pos *= sizeof(ino_t);
37408 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37409 + struct au_xi_calc *calc)
37412 + struct file *file;
37413 + struct au_xino *xi = br->br_xino;
37414 + struct au_xi_new xinew = {
37418 + SiMustAnyLock(sb);
37424 + mutex_lock(&xi->xi_mtx);
37425 + file = au_xino_file(xi, calc->idx);
37429 + file = au_xino_file(xi, /*idx*/-1);
37430 + AuDebugOn(!file);
37431 + xinew.idx = calc->idx;
37432 + xinew.base = &file->f_path;
37433 + /* xinew.copy_src = NULL; */
37434 + file = au_xi_new(sb, &xinew);
37435 + if (IS_ERR(file))
37436 + err = PTR_ERR(file);
37439 + mutex_unlock(&xi->xi_mtx);
37444 +struct au_xino_do_new_async_args {
37445 + struct super_block *sb;
37446 + struct au_branch *br;
37447 + struct au_xi_calc calc;
37451 +struct au_xi_writing {
37452 + struct hlist_bl_node node;
37453 + ino_t h_ino, ino;
37456 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37457 + struct au_xi_calc *calc, ino_t ino);
37459 +static void au_xino_call_do_new_async(void *args)
37461 + struct au_xino_do_new_async_args *a = args;
37462 + struct au_branch *br;
37463 + struct super_block *sb;
37464 + struct au_sbinfo *sbi;
37465 + struct inode *root;
37466 + struct file *file;
37467 + struct au_xi_writing *del, *p;
37468 + struct hlist_bl_head *hbl;
37469 + struct hlist_bl_node *pos;
37474 + sbi = au_sbi(sb);
37475 + si_noflush_read_lock(sb);
37476 + root = d_inode(sb->s_root);
37477 + ii_read_lock_child(root);
37478 + err = au_xino_do_new_async(sb, br, &a->calc);
37479 + if (unlikely(err)) {
37480 + AuIOErr("err %d\n", err);
37484 + file = au_xino_file(br->br_xino, a->calc.idx);
37485 + AuDebugOn(!file);
37486 + err = au_xino_do_write(sbi->si_xwrite, file, &a->calc, a->ino);
37487 + if (unlikely(err)) {
37488 + AuIOErr("err %d\n", err);
37493 + hbl = &br->br_xino->xi_writing;
37494 + hlist_bl_lock(hbl);
37495 + au_hbl_for_each(pos, hbl) {
37496 + p = container_of(pos, struct au_xi_writing, node);
37497 + if (p->ino == a->ino) {
37499 + hlist_bl_del(&p->node);
37503 + hlist_bl_unlock(hbl);
37504 + au_kfree_rcu(del);
37507 + au_lcnt_dec(&br->br_count);
37508 + ii_read_unlock(root);
37509 + si_read_unlock(sb);
37510 + au_nwt_done(&sbi->si_nowait);
37515 + * create a new xino file asynchronously
37517 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37518 + struct au_xi_calc *calc, ino_t ino)
37521 + struct au_xino_do_new_async_args *arg;
37524 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37525 + if (unlikely(!arg))
37530 + arg->calc = *calc;
37532 + au_lcnt_inc(&br->br_count);
37533 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37534 + if (unlikely(err)) {
37535 + pr_err("wkq %d\n", err);
37536 + au_lcnt_dec(&br->br_count);
37537 + au_kfree_rcu(arg);
37545 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37546 + * at the position of @h_ino.
37548 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37553 + struct au_xi_calc calc;
37554 + struct au_sbinfo *sbinfo;
37555 + struct file *file;
37556 + struct au_xino *xi;
37557 + struct hlist_bl_head *hbl;
37558 + struct hlist_bl_node *pos;
37559 + struct au_xi_writing *p;
37562 + if (!au_opt_test(au_mntflags(sb), XINO))
37563 + return 0; /* no xino */
37566 + au_xi_calc(sb, h_ino, &calc);
37567 + xi = au_sbr(sb, bindex)->br_xino;
37568 + file = au_xino_file(xi, calc.idx);
37570 + hbl = &xi->xi_writing;
37571 + hlist_bl_lock(hbl);
37572 + au_hbl_for_each(pos, hbl) {
37573 + p = container_of(pos, struct au_xi_writing, node);
37574 + if (p->h_ino == h_ino) {
37575 + AuDbg("hi%llu, i%llu, found\n",
37576 + (u64)p->h_ino, (u64)p->ino);
37581 + hlist_bl_unlock(hbl);
37583 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37584 + return 0; /* no xino */
37586 + sbinfo = au_sbi(sb);
37587 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &calc.pos);
37588 + if (sz == sizeof(*ino))
37589 + return 0; /* success */
37592 + if (unlikely(sz >= 0)) {
37594 + AuIOErr("xino read error (%zd)\n", sz);
37599 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37600 + struct au_xi_calc *calc, ino_t ino)
37604 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &calc->pos);
37605 + if (sz == sizeof(ino))
37606 + return 0; /* success */
37608 + AuIOErr("write failed (%zd)\n", sz);
37613 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37614 + * at the position of @h_ino.
37615 + * even if @ino is zero, it is written to the xinofile and means no entry.
37616 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37617 + * try truncating it.
37619 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37623 + unsigned int mnt_flags;
37624 + struct au_xi_calc calc;
37625 + struct file *file;
37626 + struct au_branch *br;
37627 + struct au_xino *xi;
37628 + struct au_xi_writing *p;
37630 + SiMustAnyLock(sb);
37632 + mnt_flags = au_mntflags(sb);
37633 + if (!au_opt_test(mnt_flags, XINO))
37636 + au_xi_calc(sb, h_ino, &calc);
37637 + br = au_sbr(sb, bindex);
37638 + xi = br->br_xino;
37639 + file = au_xino_file(xi, calc.idx);
37641 + /* store the inum pair into the list */
37642 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37643 + p->h_ino = h_ino;
37645 + au_hbl_add(&p->node, &xi->xi_writing);
37647 + /* create and write a new xino file asynchronously */
37648 + err = au_xino_new_async(sb, br, &calc, ino);
37650 + return 0; /* success */
37654 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, file, &calc, ino);
37656 + br = au_sbr(sb, bindex);
37657 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37658 + && au_test_fs_trunc_xino(au_br_sb(br)))
37659 + xino_try_trunc(sb, br);
37660 + return 0; /* success */
37664 + AuIOErr("write failed (%d)\n", err);
37668 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37669 + size_t size, loff_t *pos);
37671 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37672 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
37676 + mm_segment_t oldfs;
37682 + const int prevent_endless = 10;
37686 + oldfs = get_fs();
37687 + set_fs(KERNEL_DS);
37689 + err = func(file, buf.u, size, pos);
37690 + if (err == -EINTR
37691 + && !au_wkq_test()
37692 + && fatal_signal_pending(current)) {
37694 + err = xino_fread_wkq(func, file, kbuf, size, pos);
37695 + BUG_ON(err == -EINTR);
37696 + oldfs = get_fs();
37697 + set_fs(KERNEL_DS);
37699 + } while (i++ < prevent_endless
37700 + && (err == -EAGAIN || err == -EINTR));
37703 +#if 0 /* reserved for future use */
37705 + fsnotify_access(file->f_path.dentry);
37711 +struct xino_fread_args {
37713 + vfs_readf_t func;
37714 + struct file *file;
37720 +static void call_xino_fread(void *args)
37722 + struct xino_fread_args *a = args;
37723 + *a->errp = xino_fread(a->func, a->file, a->buf, a->size, a->pos);
37726 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37727 + size_t size, loff_t *pos)
37731 + struct xino_fread_args args = {
37740 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37741 + if (unlikely(wkq_err))
37747 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37748 + size_t size, loff_t *pos);
37750 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
37751 + size_t size, loff_t *pos)
37754 + mm_segment_t oldfs;
37757 + const char __user *u;
37760 + const int prevent_endless = 10;
37764 + oldfs = get_fs();
37765 + set_fs(KERNEL_DS);
37767 + err = func(file, buf.u, size, pos);
37768 + if (err == -EINTR
37769 + && !au_wkq_test()
37770 + && fatal_signal_pending(current)) {
37772 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
37773 + BUG_ON(err == -EINTR);
37774 + oldfs = get_fs();
37775 + set_fs(KERNEL_DS);
37777 + } while (i++ < prevent_endless
37778 + && (err == -EAGAIN || err == -EINTR));
37781 +#if 0 /* reserved for future use */
37783 + fsnotify_modify(file->f_path.dentry);
37789 +struct do_xino_fwrite_args {
37791 + vfs_writef_t func;
37792 + struct file *file;
37798 +static void call_do_xino_fwrite(void *args)
37800 + struct do_xino_fwrite_args *a = args;
37801 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
37804 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37805 + size_t size, loff_t *pos)
37809 + struct do_xino_fwrite_args args = {
37819 + * it breaks RLIMIT_FSIZE and normal user's limit,
37820 + * users should care about quota and real 'filesystem full.'
37822 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37823 + if (unlikely(wkq_err))
37829 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
37830 + size_t size, loff_t *pos)
37834 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37836 + err = do_xino_fwrite(func, file, buf, size, pos);
37840 + err = xino_fwrite_wkq(func, file, buf, size, pos);
37847 +/* ---------------------------------------------------------------------- */
37850 + * inode number bitmap
37852 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37853 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37857 + AuDebugOn(bit < 0 || page_bits <= bit);
37858 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37862 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37864 + AuDebugOn(ino < AUFS_FIRST_INO);
37865 + ino -= AUFS_FIRST_INO;
37866 + *pindex = ino / page_bits;
37867 + *bit = ino % page_bits;
37870 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37875 + struct au_sbinfo *sbinfo;
37876 + struct file *xib;
37877 + unsigned long *p;
37879 + sbinfo = au_sbi(sb);
37880 + MtxMustLock(&sbinfo->si_xib_mtx);
37881 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37882 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37884 + if (pindex == sbinfo->si_xib_last_pindex)
37887 + xib = sbinfo->si_xib;
37888 + p = sbinfo->si_xib_buf;
37889 + pos = sbinfo->si_xib_last_pindex;
37890 + pos *= PAGE_SIZE;
37891 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37892 + if (unlikely(sz != PAGE_SIZE))
37896 + pos *= PAGE_SIZE;
37897 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37898 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
37900 + memset(p, 0, PAGE_SIZE);
37901 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37903 + if (sz == PAGE_SIZE) {
37904 + sbinfo->si_xib_last_pindex = pindex;
37905 + return 0; /* success */
37909 + AuIOErr1("write failed (%zd)\n", sz);
37916 +static void au_xib_clear_bit(struct inode *inode)
37919 + unsigned long pindex;
37920 + struct super_block *sb;
37921 + struct au_sbinfo *sbinfo;
37923 + AuDebugOn(inode->i_nlink);
37925 + sb = inode->i_sb;
37926 + xib_calc_bit(inode->i_ino, &pindex, &bit);
37927 + AuDebugOn(page_bits <= bit);
37928 + sbinfo = au_sbi(sb);
37929 + mutex_lock(&sbinfo->si_xib_mtx);
37930 + err = xib_pindex(sb, pindex);
37932 + clear_bit(bit, sbinfo->si_xib_buf);
37933 + sbinfo->si_xib_next_bit = bit;
37935 + mutex_unlock(&sbinfo->si_xib_mtx);
37938 +/* ---------------------------------------------------------------------- */
37941 + * truncate a xino bitmap file
37945 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
37949 + unsigned long pindex;
37950 + loff_t pos, pend;
37951 + struct au_sbinfo *sbinfo;
37952 + vfs_readf_t func;
37954 + unsigned long *p;
37957 + sbinfo = au_sbi(sb);
37958 + MtxMustLock(&sbinfo->si_xib_mtx);
37959 + p = sbinfo->si_xib_buf;
37960 + func = sbinfo->si_xread;
37961 + pend = vfsub_f_size_read(file);
37963 + while (pos < pend) {
37964 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
37966 + if (unlikely(sz <= 0))
37970 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
37971 + if (unlikely(*ino < AUFS_FIRST_INO))
37974 + xib_calc_bit(*ino, &pindex, &bit);
37975 + AuDebugOn(page_bits <= bit);
37976 + err = xib_pindex(sb, pindex);
37988 +static int xib_restore(struct super_block *sb)
37991 + unsigned int nfile;
37992 + aufs_bindex_t bindex, bbot;
37994 + struct au_branch *br;
37995 + struct au_xino *xi;
37996 + struct file *file;
37999 + page = (void *)__get_free_page(GFP_NOFS);
38000 + if (unlikely(!page))
38004 + bbot = au_sbbot(sb);
38005 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38006 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38007 + br = au_sbr(sb, bindex);
38008 + xi = br->br_xino;
38009 + nfile = xi->xi_nfile;
38010 + for (i = 0; i < nfile; i++) {
38011 + file = au_xino_file(xi, i);
38013 + err = do_xib_restore(sb, file, page);
38016 + AuDbg("skip shared b%d\n", bindex);
38017 + free_page((unsigned long)page);
38023 +int au_xib_trunc(struct super_block *sb)
38028 + struct au_sbinfo *sbinfo;
38029 + unsigned long *p;
38030 + struct file *file;
38032 + SiMustWriteLock(sb);
38035 + sbinfo = au_sbi(sb);
38036 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38039 + file = sbinfo->si_xib;
38040 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38043 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38044 + err = PTR_ERR(file);
38045 + if (IS_ERR(file))
38047 + fput(sbinfo->si_xib);
38048 + sbinfo->si_xib = file;
38050 + p = sbinfo->si_xib_buf;
38051 + memset(p, 0, PAGE_SIZE);
38053 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
38054 + if (unlikely(sz != PAGE_SIZE)) {
38056 + AuIOErr("err %d\n", err);
38062 + mutex_lock(&sbinfo->si_xib_mtx);
38063 + /* mnt_want_write() is unnecessary here */
38064 + err = xib_restore(sb);
38065 + mutex_unlock(&sbinfo->si_xib_mtx);
38071 +/* ---------------------------------------------------------------------- */
38073 +struct au_xino *au_xino_alloc(unsigned int nfile)
38075 + struct au_xino *xi;
38077 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38078 + if (unlikely(!xi))
38080 + xi->xi_nfile = nfile;
38081 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38082 + if (unlikely(!xi->xi_file))
38085 + xi->xi_nondir.total = 8; /* initial size */
38086 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38088 + if (unlikely(!xi->xi_nondir.array))
38091 + spin_lock_init(&xi->xi_nondir.spin);
38092 + init_waitqueue_head(&xi->xi_nondir.wqh);
38093 + mutex_init(&xi->xi_mtx);
38094 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38095 + atomic_set(&xi->xi_truncating, 0);
38096 + kref_init(&xi->xi_kref);
38097 + goto out; /* success */
38100 + au_kfree_try_rcu(xi->xi_file);
38102 + au_kfree_rcu(xi);
38108 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38111 + struct au_xino *xi;
38114 + xi = au_xino_alloc(idx + 1);
38115 + if (unlikely(!xi)) {
38122 + xi->xi_file[idx] = file;
38123 + AuDebugOn(br->br_xino);
38124 + br->br_xino = xi;
38130 +static void au_xino_release(struct kref *kref)
38132 + struct au_xino *xi;
38134 + unsigned long ul;
38135 + struct hlist_bl_head *hbl;
38136 + struct hlist_bl_node *pos, *n;
38137 + struct au_xi_writing *p;
38139 + xi = container_of(kref, struct au_xino, xi_kref);
38140 + for (i = 0; i < xi->xi_nfile; i++)
38141 + if (xi->xi_file[i])
38142 + fput(xi->xi_file[i]);
38143 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38144 + AuDebugOn(xi->xi_nondir.array[i]);
38145 + mutex_destroy(&xi->xi_mtx);
38146 + hbl = &xi->xi_writing;
38147 + ul = au_hbl_count(hbl);
38148 + if (unlikely(ul)) {
38149 + pr_warn("xi_writing %lu\n", ul);
38150 + hlist_bl_lock(hbl);
38151 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
38152 + hlist_bl_del(&p->node);
38153 + /* kmemleak reported au_kfree_rcu() doesn't free it */
38156 + hlist_bl_unlock(hbl);
38158 + au_kfree_try_rcu(xi->xi_file);
38159 + au_kfree_try_rcu(xi->xi_nondir.array);
38160 + au_kfree_rcu(xi);
38163 +int au_xino_put(struct au_branch *br)
38166 + struct au_xino *xi;
38169 + xi = br->br_xino;
38171 + br->br_xino = NULL;
38172 + ret = kref_put(&xi->xi_kref, au_xino_release);
38178 +/* ---------------------------------------------------------------------- */
38181 + * xino mount option handlers
38185 +static void xino_clear_xib(struct super_block *sb)
38187 + struct au_sbinfo *sbinfo;
38189 + SiMustWriteLock(sb);
38191 + sbinfo = au_sbi(sb);
38192 + /* unnecessary to clear sbinfo->si_xread and ->si_xwrite */
38193 + if (sbinfo->si_xib)
38194 + fput(sbinfo->si_xib);
38195 + sbinfo->si_xib = NULL;
38196 + if (sbinfo->si_xib_buf)
38197 + free_page((unsigned long)sbinfo->si_xib_buf);
38198 + sbinfo->si_xib_buf = NULL;
38201 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38205 + struct au_sbinfo *sbinfo;
38206 + struct file *file;
38207 + struct super_block *xi_sb;
38209 + SiMustWriteLock(sb);
38211 + sbinfo = au_sbi(sb);
38212 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38213 + err = PTR_ERR(file);
38214 + if (IS_ERR(file))
38216 + if (sbinfo->si_xib)
38217 + fput(sbinfo->si_xib);
38218 + sbinfo->si_xib = file;
38219 + sbinfo->si_xread = vfs_readf(file);
38220 + sbinfo->si_xwrite = vfs_writef(file);
38221 + xi_sb = file_inode(file)->i_sb;
38222 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38223 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38225 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38226 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38229 + sbinfo->si_ximaxent /= sizeof(ino_t);
38232 + if (!sbinfo->si_xib_buf)
38233 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38234 + if (unlikely(!sbinfo->si_xib_buf))
38237 + sbinfo->si_xib_last_pindex = 0;
38238 + sbinfo->si_xib_next_bit = 0;
38239 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38241 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
38242 + PAGE_SIZE, &pos);
38243 + if (unlikely(err != PAGE_SIZE))
38247 + goto out; /* success */
38250 + if (sbinfo->si_xib_buf)
38251 + free_page((unsigned long)sbinfo->si_xib_buf);
38252 + sbinfo->si_xib_buf = NULL;
38256 + fput(sbinfo->si_xib);
38257 + sbinfo->si_xib = NULL;
38263 +/* xino for each branch */
38264 +static void xino_clear_br(struct super_block *sb)
38266 + aufs_bindex_t bindex, bbot;
38267 + struct au_branch *br;
38269 + bbot = au_sbbot(sb);
38270 + for (bindex = 0; bindex <= bbot; bindex++) {
38271 + br = au_sbr(sb, bindex);
38277 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38278 + aufs_bindex_t bshared)
38280 + struct au_branch *brshared;
38282 + brshared = au_sbr(sb, bshared);
38283 + AuDebugOn(!brshared->br_xino);
38284 + AuDebugOn(!brshared->br_xino->xi_file);
38285 + if (br->br_xino != brshared->br_xino) {
38286 + au_xino_get(brshared);
38288 + br->br_xino = brshared->br_xino;
38292 +struct au_xino_do_set_br {
38293 + vfs_writef_t writef;
38294 + struct au_branch *br;
38296 + aufs_bindex_t bshared;
38299 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38300 + struct au_xino_do_set_br *args)
38303 + struct au_xi_calc calc;
38304 + struct file *file;
38305 + struct au_branch *br;
38306 + struct au_xi_new xinew = {
38311 + xinew.xi = br->br_xino;
38312 + au_xi_calc(sb, args->h_ino, &calc);
38313 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38314 + if (args->bshared >= 0)
38315 + /* shared xino */
38316 + au_xino_set_br_shared(sb, br, args->bshared);
38317 + else if (!xinew.xi) {
38319 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38320 + if (unlikely(err))
38324 + /* force re-creating */
38325 + xinew.xi = br->br_xino;
38326 + xinew.idx = calc.idx;
38327 + mutex_lock(&xinew.xi->xi_mtx);
38328 + file = au_xi_new(sb, &xinew);
38329 + mutex_unlock(&xinew.xi->xi_mtx);
38330 + err = PTR_ERR(file);
38331 + if (IS_ERR(file))
38333 + AuDebugOn(!file);
38335 + err = au_xino_do_write(args->writef, file, &calc, AUFS_ROOT_INO);
38336 + if (unlikely(err))
38344 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38347 + aufs_bindex_t bindex, bbot;
38348 + struct au_xino_do_set_br args;
38349 + struct inode *inode;
38351 + SiMustWriteLock(sb);
38353 + bbot = au_sbbot(sb);
38354 + inode = d_inode(sb->s_root);
38355 + args.writef = au_sbi(sb)->si_xwrite;
38356 + for (bindex = 0; bindex <= bbot; bindex++) {
38357 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38358 + args.br = au_sbr(sb, bindex);
38359 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38360 + err = au_xino_do_set_br(sb, path, &args);
38361 + if (unlikely(err))
38369 +void au_xino_clr(struct super_block *sb)
38371 + struct au_sbinfo *sbinfo;
38373 + au_xigen_clr(sb);
38374 + xino_clear_xib(sb);
38375 + xino_clear_br(sb);
38376 + dbgaufs_brs_del(sb, 0);
38377 + sbinfo = au_sbi(sb);
38378 + /* lvalue, do not call au_mntflags() */
38379 + au_opt_clr(sbinfo->si_mntflags, XINO);
38382 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38385 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38386 + struct qstr *dname, *cur_name;
38387 + struct file *cur_xino;
38388 + struct au_sbinfo *sbinfo;
38389 + struct path *path, *cur_path;
38391 + SiMustWriteLock(sb);
38394 + sbinfo = au_sbi(sb);
38395 + path = &xiopt->file->f_path;
38396 + dentry = path->dentry;
38397 + parent = dget_parent(dentry);
38400 + cur_xino = sbinfo->si_xib;
38402 + cur_path = &cur_xino->f_path;
38403 + cur_dentry = cur_path->dentry;
38404 + cur_parent = dget_parent(cur_dentry);
38405 + cur_name = &cur_dentry->d_name;
38406 + dname = &dentry->d_name;
38407 + skip = (cur_parent == parent
38408 + && au_qstreq(dname, cur_name));
38409 + dput(cur_parent);
38415 + au_opt_set(sbinfo->si_mntflags, XINO);
38416 + err = au_xino_set_xib(sb, path);
38417 + /* si_x{read,write} are set */
38419 + err = au_xigen_set(sb, path);
38421 + err = au_xino_set_br(sb, path);
38423 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38424 + goto out; /* success */
38428 + AuIOErr("failed setting xino(%d).\n", err);
38437 + * create a xinofile at the default place/path.
38439 +struct file *au_xino_def(struct super_block *sb)
38441 + struct file *file;
38443 + struct au_branch *br;
38444 + struct super_block *h_sb;
38445 + struct path path;
38446 + aufs_bindex_t bbot, bindex, bwr;
38449 + bbot = au_sbbot(sb);
38451 + for (bindex = 0; bindex <= bbot; bindex++) {
38452 + br = au_sbr(sb, bindex);
38453 + if (au_br_writable(br->br_perm)
38454 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38461 + file = ERR_PTR(-ENOMEM);
38462 + page = (void *)__get_free_page(GFP_NOFS);
38463 + if (unlikely(!page))
38465 + path.mnt = au_br_mnt(br);
38466 + path.dentry = au_h_dptr(sb->s_root, bwr);
38467 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38468 + file = (void *)p;
38469 + if (!IS_ERR(p)) {
38470 + strcat(p, "/" AUFS_XINO_FNAME);
38471 + AuDbg("%s\n", p);
38472 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38474 + free_page((unsigned long)page);
38476 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38478 + if (IS_ERR(file))
38480 + h_sb = file->f_path.dentry->d_sb;
38481 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38482 + pr_err("xino doesn't support %s(%s)\n",
38483 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38485 + file = ERR_PTR(-EINVAL);
38493 +/* ---------------------------------------------------------------------- */
38496 + * initialize the xinofile for the specified branch @br
38497 + * at the place/path where @base_file indicates.
38498 + * test whether another branch is on the same filesystem or not,
38499 + * if found then share the xinofile with another branch.
38501 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38502 + struct path *base)
38505 + struct au_xino_do_set_br args = {
38510 + args.writef = au_sbi(sb)->si_xwrite;
38511 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38513 + err = au_xino_do_set_br(sb, base, &args);
38514 + if (unlikely(err))
38520 +/* ---------------------------------------------------------------------- */
38523 + * get an unused inode number from bitmap
38525 +ino_t au_xino_new_ino(struct super_block *sb)
38528 + unsigned long *p, pindex, ul, pend;
38529 + struct au_sbinfo *sbinfo;
38530 + struct file *file;
38531 + int free_bit, err;
38533 + if (!au_opt_test(au_mntflags(sb), XINO))
38534 + return iunique(sb, AUFS_FIRST_INO);
38536 + sbinfo = au_sbi(sb);
38537 + mutex_lock(&sbinfo->si_xib_mtx);
38538 + p = sbinfo->si_xib_buf;
38539 + free_bit = sbinfo->si_xib_next_bit;
38540 + if (free_bit < page_bits && !test_bit(free_bit, p))
38541 + goto out; /* success */
38542 + free_bit = find_first_zero_bit(p, page_bits);
38543 + if (free_bit < page_bits)
38544 + goto out; /* success */
38546 + pindex = sbinfo->si_xib_last_pindex;
38547 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38548 + err = xib_pindex(sb, ul);
38549 + if (unlikely(err))
38551 + free_bit = find_first_zero_bit(p, page_bits);
38552 + if (free_bit < page_bits)
38553 + goto out; /* success */
38556 + file = sbinfo->si_xib;
38557 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38558 + for (ul = pindex + 1; ul <= pend; ul++) {
38559 + err = xib_pindex(sb, ul);
38560 + if (unlikely(err))
38562 + free_bit = find_first_zero_bit(p, page_bits);
38563 + if (free_bit < page_bits)
38564 + goto out; /* success */
38569 + set_bit(free_bit, p);
38570 + sbinfo->si_xib_next_bit = free_bit + 1;
38571 + pindex = sbinfo->si_xib_last_pindex;
38572 + mutex_unlock(&sbinfo->si_xib_mtx);
38573 + ino = xib_calc_ino(pindex, free_bit);
38574 + AuDbg("i%lu\n", (unsigned long)ino);
38577 + mutex_unlock(&sbinfo->si_xib_mtx);
38582 +/* for s_op->delete_inode() */
38583 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38586 + unsigned int mnt_flags;
38587 + aufs_bindex_t bindex, bbot, bi;
38588 + unsigned char try_trunc;
38589 + struct au_iinfo *iinfo;
38590 + struct super_block *sb;
38591 + struct au_hinode *hi;
38592 + struct inode *h_inode;
38593 + struct au_branch *br;
38594 + vfs_writef_t xwrite;
38595 + struct au_xi_calc calc;
38596 + struct file *file;
38598 + AuDebugOn(au_is_bad_inode(inode));
38600 + sb = inode->i_sb;
38601 + mnt_flags = au_mntflags(sb);
38602 + if (!au_opt_test(mnt_flags, XINO)
38603 + || inode->i_ino == AUFS_ROOT_INO)
38607 + au_xigen_inc(inode);
38608 + au_xib_clear_bit(inode);
38611 + iinfo = au_ii(inode);
38612 + bindex = iinfo->ii_btop;
38616 + xwrite = au_sbi(sb)->si_xwrite;
38617 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38618 + hi = au_hinode(iinfo, bindex);
38619 + bbot = iinfo->ii_bbot;
38620 + for (; bindex <= bbot; bindex++, hi++) {
38621 + h_inode = hi->hi_inode;
38623 + || (!unlinked && h_inode->i_nlink))
38626 + /* inode may not be revalidated */
38627 + bi = au_br_index(sb, hi->hi_id);
38631 + br = au_sbr(sb, bi);
38632 + au_xi_calc(sb, h_inode->i_ino, &calc);
38633 + file = au_xino_file(br->br_xino, calc.idx);
38634 + if (IS_ERR_OR_NULL(file))
38637 + err = au_xino_do_write(xwrite, file, &calc, /*ino*/0);
38638 + if (!err && try_trunc
38639 + && au_test_fs_trunc_xino(au_br_sb(br)))
38640 + xino_try_trunc(sb, br);
38644 +/* ---------------------------------------------------------------------- */
38646 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38648 + int found, total, i;
38651 + total = xi->xi_nondir.total;
38652 + for (i = 0; i < total; i++) {
38653 + if (xi->xi_nondir.array[i] != h_ino)
38662 +static int au_xinondir_expand(struct au_xino *xi)
38667 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38670 + sz = xi->xi_nondir.total * sizeof(ino_t);
38671 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38673 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38674 + /*may_shrink*/0);
38676 + xi->xi_nondir.array = p;
38677 + xi->xi_nondir.total <<= 1;
38678 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38686 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38687 + ino_t h_ino, int idx)
38689 + struct au_xino *xi;
38691 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38692 + xi = au_sbr(sb, bindex)->br_xino;
38693 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38695 + spin_lock(&xi->xi_nondir.spin);
38696 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38697 + xi->xi_nondir.array[idx] = 0;
38698 + spin_unlock(&xi->xi_nondir.spin);
38699 + wake_up_all(&xi->xi_nondir.wqh);
38702 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38705 + int err, found, empty;
38706 + struct au_xino *xi;
38710 + if (!au_opt_test(au_mntflags(sb), XINO))
38711 + goto out; /* no xino */
38713 + xi = au_sbr(sb, bindex)->br_xino;
38716 + spin_lock(&xi->xi_nondir.spin);
38717 + found = au_xinondir_find(xi, h_ino);
38718 + if (found == -1) {
38719 + empty = au_xinondir_find(xi, /*h_ino*/0);
38720 + if (empty == -1) {
38721 + empty = xi->xi_nondir.total;
38722 + err = au_xinondir_expand(xi);
38723 + if (unlikely(err))
38726 + xi->xi_nondir.array[empty] = h_ino;
38729 + spin_unlock(&xi->xi_nondir.spin);
38730 + wait_event(xi->xi_nondir.wqh,
38731 + xi->xi_nondir.array[found] != h_ino);
38736 + spin_unlock(&xi->xi_nondir.spin);
38741 +/* ---------------------------------------------------------------------- */
38743 +int au_xino_path(struct seq_file *seq, struct file *file)
38747 + err = au_seq_path(seq, &file->f_path);
38748 + if (unlikely(err))
38751 +#define Deleted "\\040(deleted)"
38752 + seq->count -= sizeof(Deleted) - 1;
38753 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38754 + sizeof(Deleted) - 1));
38760 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38761 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38762 +++ linux/include/uapi/linux/aufs_type.h 2020-08-03 09:14:46.095748745 +0200
38764 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
38766 + * Copyright (C) 2005-2020 Junjiro R. Okajima
38768 + * This program, aufs is free software; you can redistribute it and/or modify
38769 + * it under the terms of the GNU General Public License as published by
38770 + * the Free Software Foundation; either version 2 of the License, or
38771 + * (at your option) any later version.
38773 + * This program is distributed in the hope that it will be useful,
38774 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38775 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38776 + * GNU General Public License for more details.
38778 + * You should have received a copy of the GNU General Public License
38779 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38782 +#ifndef __AUFS_TYPE_H__
38783 +#define __AUFS_TYPE_H__
38785 +#define AUFS_NAME "aufs"
38789 + * define it before including all other headers.
38790 + * sched.h may use pr_* macros before defining "current", so define the
38791 + * no-current version first, and re-define later.
38793 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38794 +#include <linux/sched.h>
38796 +#define pr_fmt(fmt) \
38797 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38798 + (int)sizeof(current->comm), current->comm, current->pid
38799 +#include <linux/limits.h>
38801 +#include <stdint.h>
38802 +#include <sys/types.h>
38803 +#include <limits.h>
38804 +#endif /* __KERNEL__ */
38806 +#define AUFS_VERSION "5.x-rcN-20200622"
38808 +/* todo? move this to linux-2.6.19/include/magic.h */
38809 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38811 +/* ---------------------------------------------------------------------- */
38814 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38815 +typedef int8_t aufs_bindex_t;
38816 +#define AUFS_BRANCH_MAX 127
38818 +typedef int16_t aufs_bindex_t;
38819 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38820 +#define AUFS_BRANCH_MAX 511
38821 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38822 +#define AUFS_BRANCH_MAX 1023
38823 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38824 +#define AUFS_BRANCH_MAX 32767
38828 +#ifndef AUFS_BRANCH_MAX
38829 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38831 +#endif /* __KERNEL__ */
38833 +/* ---------------------------------------------------------------------- */
38835 +#define AUFS_FSTYPE AUFS_NAME
38837 +#define AUFS_ROOT_INO 2
38838 +#define AUFS_FIRST_INO 11
38840 +#define AUFS_WH_PFX ".wh."
38841 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38842 +#define AUFS_WH_TMP_LEN 4
38843 +/* a limit for rmdir/rename a dir and copyup */
38844 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38845 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38847 + - AUFS_WH_TMP_LEN) /* hex */
38848 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38849 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38850 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38851 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38852 +#define AUFS_DIRWH_DEF 3
38853 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38854 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38855 +#define AUFS_RDBLK_DEF 512 /* bytes */
38856 +#define AUFS_RDHASH_DEF 32
38857 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38858 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38859 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38860 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38861 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38863 +/* pseudo-link maintenace under /proc */
38864 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38865 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38866 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38868 +/* dirren, renamed dir */
38869 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38870 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38871 +/* whiteouted doubly */
38872 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38873 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38875 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38876 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38878 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38879 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38880 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38882 +/* doubly whiteouted */
38883 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38884 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38885 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38887 +/* branch permissions and attributes */
38888 +#define AUFS_BRPERM_RW "rw"
38889 +#define AUFS_BRPERM_RO "ro"
38890 +#define AUFS_BRPERM_RR "rr"
38891 +#define AUFS_BRATTR_COO_REG "coo_reg"
38892 +#define AUFS_BRATTR_COO_ALL "coo_all"
38893 +#define AUFS_BRATTR_FHSM "fhsm"
38894 +#define AUFS_BRATTR_UNPIN "unpin"
38895 +#define AUFS_BRATTR_ICEX "icex"
38896 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38897 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38898 +#define AUFS_BRATTR_ICEX_TR "icextr"
38899 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38900 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38901 +#define AUFS_BRRATTR_WH "wh"
38902 +#define AUFS_BRWATTR_NLWH "nolwh"
38903 +#define AUFS_BRWATTR_MOO "moo"
38905 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38906 +#define AuBrPerm_RO (1 << 1) /* readonly */
38907 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38908 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38910 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38911 +#define AuBrAttr_COO_ALL (1 << 4)
38912 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38914 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38915 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38916 + branch. meaningless since
38917 + linux-3.18-rc1 */
38919 +/* ignore error in copying XATTR */
38920 +#define AuBrAttr_ICEX_SEC (1 << 7)
38921 +#define AuBrAttr_ICEX_SYS (1 << 8)
38922 +#define AuBrAttr_ICEX_TR (1 << 9)
38923 +#define AuBrAttr_ICEX_USR (1 << 10)
38924 +#define AuBrAttr_ICEX_OTH (1 << 11)
38925 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38926 + | AuBrAttr_ICEX_SYS \
38927 + | AuBrAttr_ICEX_TR \
38928 + | AuBrAttr_ICEX_USR \
38929 + | AuBrAttr_ICEX_OTH)
38931 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
38932 +#define AuBrRAttr_Mask AuBrRAttr_WH
38934 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
38935 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
38936 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
38938 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
38940 +/* #warning test userspace */
38942 +#ifndef CONFIG_AUFS_FHSM
38943 +#undef AuBrAttr_FHSM
38944 +#define AuBrAttr_FHSM 0
38946 +#ifndef CONFIG_AUFS_XATTR
38947 +#undef AuBrAttr_ICEX
38948 +#define AuBrAttr_ICEX 0
38949 +#undef AuBrAttr_ICEX_SEC
38950 +#define AuBrAttr_ICEX_SEC 0
38951 +#undef AuBrAttr_ICEX_SYS
38952 +#define AuBrAttr_ICEX_SYS 0
38953 +#undef AuBrAttr_ICEX_TR
38954 +#define AuBrAttr_ICEX_TR 0
38955 +#undef AuBrAttr_ICEX_USR
38956 +#define AuBrAttr_ICEX_USR 0
38957 +#undef AuBrAttr_ICEX_OTH
38958 +#define AuBrAttr_ICEX_OTH 0
38962 +/* the longest combination */
38963 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
38964 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
38965 + "+" AUFS_BRATTR_COO_REG \
38966 + "+" AUFS_BRATTR_FHSM \
38967 + "+" AUFS_BRATTR_UNPIN \
38968 + "+" AUFS_BRATTR_ICEX_SEC \
38969 + "+" AUFS_BRATTR_ICEX_SYS \
38970 + "+" AUFS_BRATTR_ICEX_USR \
38971 + "+" AUFS_BRATTR_ICEX_OTH \
38972 + "+" AUFS_BRWATTR_NLWH)
38975 + char a[AuBrPermStrSz];
38976 +} au_br_perm_str_t;
38978 +static inline int au_br_writable(int brperm)
38980 + return brperm & AuBrPerm_RW;
38983 +static inline int au_br_whable(int brperm)
38985 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
38988 +static inline int au_br_wh_linkable(int brperm)
38990 + return !(brperm & AuBrWAttr_NoLinkWH);
38993 +static inline int au_br_cmoo(int brperm)
38995 + return brperm & AuBrAttr_CMOO_Mask;
38998 +static inline int au_br_fhsm(int brperm)
39000 + return brperm & AuBrAttr_FHSM;
39003 +/* ---------------------------------------------------------------------- */
39007 + /* readdir in userspace */
39011 + AuCtl_WBR_FD, /* pathconf wrapper */
39012 + AuCtl_IBUSY, /* busy inode */
39013 + AuCtl_MVDOWN, /* move-down */
39014 + AuCtl_BR, /* info about branches */
39015 + AuCtl_FHSM_FD /* connection for fhsm */
39018 +/* borrowed from linux/include/linux/kernel.h */
39020 +#ifdef _GNU_SOURCE
39021 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39023 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
39025 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39028 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39030 +#define __aligned(x) __attribute__((aligned(x)))
39035 +#define __packed __attribute__((packed))
39039 +struct au_rdu_cookie {
39044 + uint32_t generation;
39047 +struct au_rdu_ent {
39056 +static inline int au_rdu_len(int nlen)
39058 + /* include the terminating NULL */
39059 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39060 + sizeof(uint64_t));
39063 +union au_rdu_ent_ul {
39064 + struct au_rdu_ent __user *e;
39076 + uint64_t sz; /* AuCtl_RDU */
39077 + uint64_t nent; /* AuCtl_RDU_INO */
39079 + union au_rdu_ent_ul ent;
39080 + uint16_t verify[AufsCtlRduV_End];
39082 + /* input/output */
39086 + union au_rdu_ent_ul tail;
39087 + /* number of entries which were added in a single call */
39092 + struct au_rdu_cookie cookie;
39095 +/* ---------------------------------------------------------------------- */
39097 +/* dirren. the branch is identified by the filename who contains this */
39098 +struct au_drinfo {
39101 + uint8_t oldnamelen;
39102 + uint64_t _padding;
39104 + uint8_t oldname[];
39107 +struct au_drinfo_fdata {
39109 + struct au_drinfo drinfo;
39112 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39114 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39116 +/* ---------------------------------------------------------------------- */
39118 +struct aufs_wbr_fd {
39123 +/* ---------------------------------------------------------------------- */
39125 +struct aufs_ibusy {
39126 + uint64_t ino, h_ino;
39130 +/* ---------------------------------------------------------------------- */
39132 +/* error code for move-down */
39133 +/* the actual message strings are implemented in aufs-util.git */
39135 + EAU_MVDOWN_OPAQUE = 1,
39136 + EAU_MVDOWN_WHITEOUT,
39137 + EAU_MVDOWN_UPPER,
39138 + EAU_MVDOWN_BOTTOM,
39139 + EAU_MVDOWN_NOUPPER,
39140 + EAU_MVDOWN_NOLOWERBR,
39144 +/* flags for move-down */
39145 +#define AUFS_MVDOWN_DMSG 1
39146 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39147 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39148 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39149 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39150 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39151 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39152 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39153 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39154 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39155 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39156 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39157 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39159 +/* index for move-down */
39161 + AUFS_MVDOWN_UPPER,
39162 + AUFS_MVDOWN_LOWER,
39163 + AUFS_MVDOWN_NARRAY
39167 + * additional info of move-down
39168 + * number of free blocks and inodes.
39169 + * subset of struct kstatfs, but smaller and always 64bit.
39171 +struct aufs_stfs {
39172 + uint64_t f_blocks;
39173 + uint64_t f_bavail;
39174 + uint64_t f_files;
39175 + uint64_t f_ffree;
39178 +struct aufs_stbr {
39179 + int16_t brid; /* optional input */
39180 + int16_t bindex; /* output */
39181 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39184 +struct aufs_mvdown {
39185 + uint32_t flags; /* input/output */
39186 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39187 + int8_t au_errno; /* output */
39190 +/* ---------------------------------------------------------------------- */
39192 +union aufs_brinfo {
39193 + /* PATH_MAX may differ between kernel-space and user-space */
39194 + char _spacer[4096];
39202 +/* ---------------------------------------------------------------------- */
39204 +#define AuCtlType 'A'
39205 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39206 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39207 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39208 + struct aufs_wbr_fd)
39209 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39210 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39211 + struct aufs_mvdown)
39212 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39213 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39215 +#endif /* __AUFS_TYPE_H__ */
39216 SPDX-License-Identifier: GPL-2.0
39217 aufs5.x-rcN loopback patch
39219 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39220 index 0479902a0cd50..758c8ee4d4e6b 100644
39221 --- a/drivers/block/loop.c
39222 +++ b/drivers/block/loop.c
39223 @@ -638,6 +638,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39227 +static struct file *loop_real_file(struct file *file)
39229 + struct file *f = NULL;
39231 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39232 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39236 static void loop_reread_partitions(struct loop_device *lo,
39237 struct block_device *bdev)
39239 @@ -693,6 +702,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39242 struct file *file = NULL, *old_file;
39243 + struct file *f, *virt_file = NULL, *old_virt_file;
39247 @@ -712,12 +722,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39251 + f = loop_real_file(file);
39253 + virt_file = file;
39258 error = loop_validate_file(file, bdev);
39262 old_file = lo->lo_backing_file;
39263 + old_virt_file = lo->lo_backing_virt_file;
39267 @@ -729,6 +746,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39268 blk_mq_freeze_queue(lo->lo_queue);
39269 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39270 lo->lo_backing_file = file;
39271 + lo->lo_backing_virt_file = virt_file;
39272 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39273 mapping_set_gfp_mask(file->f_mapping,
39274 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39275 @@ -742,6 +760,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39279 + if (old_virt_file)
39280 + fput(old_virt_file);
39282 loop_reread_partitions(lo, bdev);
39284 @@ -750,6 +770,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39285 mutex_unlock(&loop_ctl_mutex);
39293 @@ -973,7 +995,7 @@ static void loop_update_rotational(struct loop_device *lo)
39294 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39295 struct block_device *bdev, unsigned int arg)
39297 - struct file *file;
39298 + struct file *file, *f, *virt_file = NULL;
39299 struct inode *inode;
39300 struct address_space *mapping;
39301 struct block_device *claimed_bdev = NULL;
39302 @@ -989,6 +1011,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39306 + f = loop_real_file(file);
39308 + virt_file = file;
39314 * If we don't hold exclusive handle for the device, upgrade to it
39315 @@ -1037,6 +1065,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39316 lo->lo_device = bdev;
39317 lo->lo_flags = lo_flags;
39318 lo->lo_backing_file = file;
39319 + lo->lo_backing_virt_file = virt_file;
39320 lo->transfer = NULL;
39322 lo->lo_sizelimit = 0;
39323 @@ -1090,6 +1119,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39324 bd_abort_claiming(bdev, claimed_bdev, loop_set_fd);
39330 /* This is safe: open() is still holding a reference. */
39331 module_put(THIS_MODULE);
39332 @@ -1136,6 +1167,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
39333 static int __loop_clr_fd(struct loop_device *lo, bool release)
39335 struct file *filp = NULL;
39336 + struct file *virt_filp = lo->lo_backing_virt_file;
39337 gfp_t gfp = lo->old_gfp_mask;
39338 struct block_device *bdev = lo->lo_device;
39340 @@ -1159,6 +1191,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39342 spin_lock_irq(&lo->lo_lock);
39343 lo->lo_backing_file = NULL;
39344 + lo->lo_backing_virt_file = NULL;
39345 spin_unlock_irq(&lo->lo_lock);
39347 loop_release_xfer(lo);
39348 @@ -1242,6 +1275,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39357 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39358 index af75a5ee40944..1d847cb194ff6 100644
39359 --- a/drivers/block/loop.h
39360 +++ b/drivers/block/loop.h
39361 @@ -46,7 +46,7 @@ struct loop_device {
39362 int (*ioctl)(struct loop_device *, int cmd,
39363 unsigned long arg);
39365 - struct file * lo_backing_file;
39366 + struct file *lo_backing_file, *lo_backing_virt_file;
39367 struct block_device *lo_device;
39370 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39371 index 6fb4a4ed8cc7f..ba9a959f2db27 100644
39372 --- a/fs/aufs/f_op.c
39373 +++ b/fs/aufs/f_op.c
39374 @@ -359,7 +359,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39375 if (IS_ERR(h_file))
39378 - if (au_test_loopback_kthread()) {
39379 + if (0 && au_test_loopback_kthread()) {
39380 au_warn_loopback(h_file->f_path.dentry->d_sb);
39381 if (file->f_mapping != h_file->f_mapping) {
39382 file->f_mapping = h_file->f_mapping;
39383 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39384 index a8b63acc62045..9d97c3af5686a 100644
39385 --- a/fs/aufs/loop.c
39386 +++ b/fs/aufs/loop.c
39387 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39388 symbol_put(loop_backing_file);
39389 au_kfree_try_rcu(au_warn_loopback_array);
39392 +/* ---------------------------------------------------------------------- */
39394 +/* support the loopback block device insude aufs */
39396 +struct file *aufs_real_loop(struct file *file)
39400 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39401 + fi_read_lock(file);
39402 + f = au_hf_top(file);
39403 + fi_read_unlock(file);
39407 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39408 index 94f4f80ae33bf..ca1194354aff4 100644
39409 --- a/fs/aufs/loop.h
39410 +++ b/fs/aufs/loop.h
39411 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39413 int au_loopback_init(void);
39414 void au_loopback_fin(void);
39416 +struct file *aufs_real_loop(struct file *file);
39418 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39420 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39422 AuStubInt0(au_loopback_init, void)
39423 AuStubVoid(au_loopback_fin, void)
39425 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39426 #endif /* BLK_DEV_LOOP */
39428 #endif /* __KERNEL__ */
39429 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39430 index 589dd01220201..801e0a7faec59 100644
39431 --- a/fs/aufs/super.c
39432 +++ b/fs/aufs/super.c
39433 @@ -844,7 +844,10 @@ static const struct super_operations aufs_sop = {
39434 .statfs = aufs_statfs,
39435 .put_super = aufs_put_super,
39436 .sync_fs = aufs_sync_fs,
39437 - .remount_fs = aufs_remount_fs
39438 + .remount_fs = aufs_remount_fs,
39439 +#ifdef CONFIG_AUFS_BDEV_LOOP
39440 + .real_loop = aufs_real_loop
39444 /* ---------------------------------------------------------------------- */
39445 diff --git a/include/linux/fs.h b/include/linux/fs.h
39446 index 916efd7e612b3..68f536f42b2a0 100644
39447 --- a/include/linux/fs.h
39448 +++ b/include/linux/fs.h
39449 @@ -1985,6 +1985,10 @@ struct super_operations {
39450 struct shrink_control *);
39451 long (*free_cached_objects)(struct super_block *,
39452 struct shrink_control *);
39453 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39455 + struct file *(*real_loop)(struct file *);