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 /* caller is responsible for file_start_write/file_end_write */
177 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_write(struct file *, const char __user *, size_t, loff_t *);
252 extern ssize_t vfs_readv(struct file *, const struct iovec __user *,
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
296 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);
303 extern struct ns_common *from_mnt_ns(struct mnt_namespace *);
305 +extern int is_current_mnt_ns(struct vfsmount *mnt);
307 extern const struct file_operations proc_mounts_operations;
308 extern const struct file_operations proc_mountinfo_operations;
309 extern const struct file_operations proc_mountstats_operations;
310 diff --git a/include/linux/splice.h b/include/linux/splice.h
311 index ebbbfea48aa0b..d68d574250283 100644
312 --- a/include/linux/splice.h
313 +++ b/include/linux/splice.h
314 @@ -90,4 +90,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
316 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
317 extern const struct pipe_buf_operations default_pipe_buf_ops;
319 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
320 + loff_t *ppos, size_t len, unsigned int flags);
321 +extern long do_splice_to(struct file *in, loff_t *ppos,
322 + struct pipe_inode_info *pipe, size_t len,
323 + unsigned int flags);
325 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
326 index ac10db66cc63f..837a3358e77ca 100644
327 --- a/kernel/locking/lockdep.c
328 +++ b/kernel/locking/lockdep.c
329 @@ -169,7 +169,7 @@ static
330 struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
331 static DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS);
333 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
334 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
336 unsigned int class_idx = hlock->class_idx;
338 @@ -190,6 +190,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
340 return lock_classes + class_idx;
342 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
344 #ifdef CONFIG_LOCK_STAT
345 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
346 SPDX-License-Identifier: GPL-2.0
347 aufs5.x-rcN mmap patch
349 diff --git a/fs/proc/base.c b/fs/proc/base.c
350 index eb2255e95f62b..92f6062423c0c 100644
353 @@ -2162,7 +2162,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
355 vma = find_exact_vma(mm, vm_start, vm_end);
356 if (vma && vma->vm_file) {
357 - *path = vma->vm_file->f_path;
358 + *path = vma_pr_or_file(vma)->f_path;
362 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
363 index 14c2badb8fd93..65afe5287e43e 100644
364 --- a/fs/proc/nommu.c
365 +++ b/fs/proc/nommu.c
366 @@ -41,7 +41,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
367 file = region->vm_file;
370 - struct inode *inode = file_inode(region->vm_file);
371 + struct inode *inode;
373 + file = vmr_pr_or_file(region);
374 + inode = file_inode(file);
375 dev = inode->i_sb->s_dev;
378 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
379 index 8d382d4ec0672..93a768f754c91 100644
380 --- a/fs/proc/task_mmu.c
381 +++ b/fs/proc/task_mmu.c
382 @@ -280,7 +280,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
383 const char *name = NULL;
386 - struct inode *inode = file_inode(vma->vm_file);
387 + struct inode *inode;
389 + file = vma_pr_or_file(vma);
390 + inode = file_inode(file);
391 dev = inode->i_sb->s_dev;
393 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
394 @@ -1787,7 +1790,7 @@ static int show_numa_map(struct seq_file *m, void *v)
395 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
396 struct vm_area_struct *vma = v;
397 struct numa_maps *md = &numa_priv->md;
398 - struct file *file = vma->vm_file;
399 + struct file *file = vma_pr_or_file(vma);
400 struct mm_struct *mm = vma->vm_mm;
401 struct mempolicy *pol;
403 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
404 index 7907e6419e572..d17209cf52bc3 100644
405 --- a/fs/proc/task_nommu.c
406 +++ b/fs/proc/task_nommu.c
407 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
411 - struct inode *inode = file_inode(vma->vm_file);
412 + struct inode *inode;
414 + file = vma_pr_or_file(vma);
415 + inode = file_inode(file);
416 dev = inode->i_sb->s_dev;
418 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
419 diff --git a/include/linux/mm.h b/include/linux/mm.h
420 index f3fe7371855ce..a5b9751a5b331 100644
421 --- a/include/linux/mm.h
422 +++ b/include/linux/mm.h
423 @@ -1688,6 +1688,28 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
424 unmap_mapping_range(mapping, holebegin, holelen, 0);
427 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
428 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
430 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
431 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
433 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
435 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
437 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
438 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
441 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
442 +extern void vmr_do_fput(struct vm_region *, const char[], int);
444 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
446 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
447 +#endif /* !CONFIG_MMU */
449 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
450 void *buf, int len, unsigned int gup_flags);
451 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
452 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
453 index 4aba6c0c2ba80..974802987f69d 100644
454 --- a/include/linux/mm_types.h
455 +++ b/include/linux/mm_types.h
456 @@ -272,6 +272,7 @@ struct vm_region {
457 unsigned long vm_top; /* region allocated to here */
458 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
459 struct file *vm_file; /* the backing file or NULL */
460 + struct file *vm_prfile; /* the virtual backing file or NULL */
462 int vm_usage; /* region usage count (access under nommu_region_sem) */
463 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
464 @@ -351,6 +352,7 @@ struct vm_area_struct {
465 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
467 struct file * vm_file; /* File we map to (can be NULL). */
468 + struct file *vm_prfile; /* shadow of vm_file */
469 void * vm_private_data; /* was vm_pte (shared mem) */
472 diff --git a/kernel/fork.c b/kernel/fork.c
473 index 48ed22774efaa..d7439388c1c52 100644
476 @@ -568,7 +568,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
477 struct inode *inode = file_inode(file);
478 struct address_space *mapping = file->f_mapping;
482 if (tmp->vm_flags & VM_DENYWRITE)
483 atomic_dec(&inode->i_writecount);
484 i_mmap_lock_write(mapping);
485 diff --git a/mm/Makefile b/mm/Makefile
486 index fccd3756b25f0..51485ceec650a 100644
489 @@ -44,7 +44,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \
490 mm_init.o mmu_context.o percpu.o slab_common.o \
491 compaction.o vmacache.o \
492 interval_tree.o list_lru.o workingset.o \
493 - debug.o gup.o $(mmu-y)
494 + prfile.o debug.o gup.o $(mmu-y)
496 # Give 'page_alloc' its own module-parameter namespace
497 page-alloc-y := page_alloc.o
498 diff --git a/mm/filemap.c b/mm/filemap.c
499 index 23a051a7ef0fb..e2fe9132feb21 100644
502 @@ -2660,7 +2660,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
503 vm_fault_t ret = VM_FAULT_LOCKED;
505 sb_start_pagefault(inode->i_sb);
506 - file_update_time(vmf->vma->vm_file);
507 + vma_file_update_time(vmf->vma);
509 if (page->mapping != inode->i_mapping) {
511 diff --git a/mm/mmap.c b/mm/mmap.c
512 index f609e9ec4a253..d554b349c653c 100644
515 @@ -179,7 +179,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
516 if (vma->vm_ops && vma->vm_ops->close)
517 vma->vm_ops->close(vma);
519 - fput(vma->vm_file);
521 mpol_put(vma_policy(vma));
524 @@ -910,7 +910,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
527 uprobe_munmap(next, next->vm_start, next->vm_end);
532 anon_vma_merge(vma, next);
533 @@ -1831,8 +1831,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
541 /* Undo any partial mapping done by a device driver. */
542 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
543 @@ -2683,7 +2683,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
547 - get_file(new->vm_file);
550 if (new->vm_ops && new->vm_ops->open)
551 new->vm_ops->open(new);
552 @@ -2702,7 +2702,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
553 if (new->vm_ops && new->vm_ops->close)
554 new->vm_ops->close(new);
556 - fput(new->vm_file);
558 unlink_anon_vmas(new);
560 mpol_put(vma_policy(new));
561 @@ -2894,7 +2894,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
562 struct vm_area_struct *vma;
563 unsigned long populate = 0;
564 unsigned long ret = -EINVAL;
566 + struct file *file, *prfile;
568 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n",
569 current->comm, current->pid);
570 @@ -2969,10 +2969,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
574 - file = get_file(vma->vm_file);
576 + file = vma->vm_file;
577 + prfile = vma->vm_prfile;
578 ret = do_mmap_pgoff(vma->vm_file, start, size,
579 prot, flags, pgoff, &populate, NULL);
580 + if (!IS_ERR_VALUE(ret) && file && prfile) {
581 + struct vm_area_struct *new_vma;
583 + new_vma = find_vma(mm, ret);
584 + if (!new_vma->vm_prfile)
585 + new_vma->vm_prfile = prfile;
586 + if (new_vma != vma)
590 + * two fput()s instead of vma_fput(vma),
591 + * coz vma may not be available anymore.
597 up_write(&mm->mmap_sem);
599 @@ -3263,7 +3280,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
600 if (anon_vma_clone(new_vma, vma))
601 goto out_free_mempol;
602 if (new_vma->vm_file)
603 - get_file(new_vma->vm_file);
604 + vma_get_file(new_vma);
605 if (new_vma->vm_ops && new_vma->vm_ops->open)
606 new_vma->vm_ops->open(new_vma);
607 vma_link(mm, new_vma, prev, rb_link, rb_parent);
608 diff --git a/mm/nommu.c b/mm/nommu.c
609 index 318df4e236c99..7f051e86ea1dd 100644
612 @@ -567,7 +567,7 @@ static void __put_nommu_region(struct vm_region *region)
613 up_write(&nommu_region_sem);
616 - fput(region->vm_file);
619 /* IO memory and memory shared directly out of the pagecache
620 * from ramfs/tmpfs mustn't be released here */
621 @@ -699,7 +699,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
622 if (vma->vm_ops && vma->vm_ops->close)
623 vma->vm_ops->close(vma);
625 - fput(vma->vm_file);
627 put_nommu_region(vma->vm_region);
630 @@ -1222,7 +1222,7 @@ unsigned long do_mmap(struct file *file,
631 goto error_just_free;
634 - fput(region->vm_file);
636 kmem_cache_free(vm_region_jar, region);
639 @@ -1299,10 +1299,10 @@ unsigned long do_mmap(struct file *file,
640 up_write(&nommu_region_sem);
643 - fput(region->vm_file);
645 kmem_cache_free(vm_region_jar, region);
647 - fput(vma->vm_file);
652 diff --git a/mm/prfile.c b/mm/prfile.c
654 index 0000000000000..00d51187c3250
658 +// SPDX-License-Identifier: GPL-2.0
660 + * Mainly for aufs which mmap(2) different file and wants to print different
661 + * path in /proc/PID/maps.
662 + * Call these functions via macros defined in linux/mm.h.
664 + * See Documentation/filesystems/aufs/design/06mmap.txt
666 + * Copyright (c) 2014-2020 Junjro R. Okajima
667 + * Copyright (c) 2014 Ian Campbell
670 +#include <linux/mm.h>
671 +#include <linux/file.h>
672 +#include <linux/fs.h>
674 +/* #define PRFILE_TRACE */
675 +static inline void prfile_trace(struct file *f, struct file *pr,
676 + const char func[], int line, const char func2[])
680 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
684 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
687 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
689 + prfile_trace(f, pr, func, line, __func__);
690 + file_update_time(f);
692 + file_update_time(pr);
695 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
698 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
700 + prfile_trace(f, pr, func, line, __func__);
701 + return (f && pr) ? pr : f;
704 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
706 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
708 + prfile_trace(f, pr, func, line, __func__);
714 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
716 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
718 + prfile_trace(f, pr, func, line, __func__);
725 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
728 + struct file *f = region->vm_file, *pr = region->vm_prfile;
730 + prfile_trace(f, pr, func, line, __func__);
731 + return (f && pr) ? pr : f;
734 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
736 + struct file *f = region->vm_file, *pr = region->vm_prfile;
738 + prfile_trace(f, pr, func, line, __func__);
743 +#endif /* !CONFIG_MMU */
744 SPDX-License-Identifier: GPL-2.0
745 aufs5.x-rcN standalone patch
747 diff --git a/fs/dcache.c b/fs/dcache.c
748 index 046000653e4d8..15aa871d1b450 100644
751 @@ -1371,6 +1371,7 @@ void d_walk(struct dentry *parent, void *data,
755 +EXPORT_SYMBOL_GPL(d_walk);
758 struct vfsmount *mnt;
759 @@ -2916,6 +2917,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
761 write_sequnlock(&rename_lock);
763 +EXPORT_SYMBOL_GPL(d_exchange);
766 * d_ancestor - search for an ancestor
767 diff --git a/fs/exec.c b/fs/exec.c
768 index 2c465119affcc..239bcb8906e78 100644
771 @@ -109,6 +109,7 @@ bool path_noexec(const struct path *path)
772 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
773 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
775 +EXPORT_SYMBOL_GPL(path_noexec);
779 diff --git a/fs/fcntl.c b/fs/fcntl.c
780 index 0b28a37f7e505..f2c90a416b751 100644
783 @@ -85,6 +85,7 @@ int setfl(int fd, struct file *filp, unsigned long arg)
787 +EXPORT_SYMBOL_GPL(setfl);
789 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
791 diff --git a/fs/file_table.c b/fs/file_table.c
792 index 30d55c9a1744a..34b9bbf4c5566 100644
793 --- a/fs/file_table.c
794 +++ b/fs/file_table.c
795 @@ -162,6 +162,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
797 return ERR_PTR(-ENFILE);
799 +EXPORT_SYMBOL_GPL(alloc_empty_file);
802 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
803 @@ -375,6 +376,7 @@ void __fput_sync(struct file *file)
807 +EXPORT_SYMBOL_GPL(__fput_sync);
809 void __init files_init(void)
811 diff --git a/fs/inode.c b/fs/inode.c
812 index 7700c5e4783b9..6284b41fcf3f0 100644
815 @@ -1694,6 +1694,7 @@ int update_time(struct inode *inode, struct timespec64 *time, int flags)
816 return inode->i_op->update_time(inode, time, flags);
817 return generic_update_time(inode, time, flags);
819 +EXPORT_SYMBOL_GPL(update_time);
822 * touch_atime - update the access time
823 diff --git a/fs/namespace.c b/fs/namespace.c
824 index 12e725e34c6ca..fa17b9d5926ba 100644
827 @@ -431,6 +431,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
828 mnt_dec_writers(real_mount(mnt));
831 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
834 * mnt_drop_write - give up write access to a mount
835 @@ -781,6 +782,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
837 return check_mnt(real_mount(mnt));
839 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
842 * vfsmount lock must be held for write
843 @@ -1903,6 +1905,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
847 +EXPORT_SYMBOL_GPL(iterate_mounts);
849 static void lock_mnt_tree(struct mount *mnt)
851 diff --git a/fs/notify/group.c b/fs/notify/group.c
852 index 133f723aca070..0b9f7f6d8390f 100644
853 --- a/fs/notify/group.c
854 +++ b/fs/notify/group.c
855 @@ -99,6 +99,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
857 refcount_inc(&group->refcnt);
859 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
862 * Drop a reference to a group. Free it if it's through.
863 diff --git a/fs/open.c b/fs/open.c
864 index 719b320ede52b..f88ce55c1c998 100644
867 @@ -65,6 +65,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
868 inode_unlock(dentry->d_inode);
871 +EXPORT_SYMBOL_GPL(do_truncate);
873 long vfs_truncate(const struct path *path, loff_t length)
875 diff --git a/fs/read_write.c b/fs/read_write.c
876 index 5d684d7d29207..6f61c0b6aa664 100644
877 --- a/fs/read_write.c
878 +++ b/fs/read_write.c
879 @@ -469,6 +469,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
883 +EXPORT_SYMBOL_GPL(vfs_read);
885 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
887 @@ -509,6 +510,7 @@ vfs_readf_t vfs_readf(struct file *file)
888 return new_sync_read;
889 return ERR_PTR(-ENOSYS); /* doesn't have ->read(|_iter)() op */
891 +EXPORT_SYMBOL_GPL(vfs_readf);
893 vfs_writef_t vfs_writef(struct file *file)
895 @@ -520,6 +522,7 @@ vfs_writef_t vfs_writef(struct file *file)
896 return new_sync_write;
897 return ERR_PTR(-ENOSYS); /* doesn't have ->write(|_iter)() op */
899 +EXPORT_SYMBOL_GPL(vfs_writef);
901 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
903 @@ -589,6 +592,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
907 +EXPORT_SYMBOL_GPL(vfs_write);
909 /* file_ppos returns &file->f_pos or NULL if file is stream */
910 static inline loff_t *file_ppos(struct file *file)
911 diff --git a/fs/splice.c b/fs/splice.c
912 index 9f230ee854e20..a6bd05004433c 100644
915 @@ -862,6 +862,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
917 return splice_write(pipe, out, ppos, len, flags);
919 +EXPORT_SYMBOL_GPL(do_splice_from);
922 * Attempt to initiate a splice from a file to a pipe.
923 @@ -891,6 +892,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
925 return splice_read(in, ppos, pipe, len, flags);
927 +EXPORT_SYMBOL_GPL(do_splice_to);
930 * splice_direct_to_actor - splices data directly between two non-pipes
931 diff --git a/fs/sync.c b/fs/sync.c
932 index 457f4e4a5cc1f..67c66358f3fe4 100644
935 @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
936 sb->s_op->sync_fs(sb, wait);
937 return __sync_blockdev(sb->s_bdev, wait);
939 +EXPORT_SYMBOL_GPL(__sync_filesystem);
942 * Write out and wait upon all dirty data associated with this
943 diff --git a/fs/xattr.c b/fs/xattr.c
944 index 91608d9bfc6aa..02d19ab3ba540 100644
947 @@ -296,6 +296,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
948 *xattr_value = value;
951 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
954 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
955 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
956 index 837a3358e77ca..715ba9c1b91ae 100644
957 --- a/kernel/locking/lockdep.c
958 +++ b/kernel/locking/lockdep.c
959 @@ -190,6 +190,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
961 return lock_classes + class_idx;
963 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
964 #define hlock_class(hlock) lockdep_hlock_class(hlock)
966 #ifdef CONFIG_LOCK_STAT
967 diff --git a/kernel/task_work.c b/kernel/task_work.c
968 index 825f28259a19a..b77593b29c1a5 100644
969 --- a/kernel/task_work.c
970 +++ b/kernel/task_work.c
971 @@ -126,3 +126,4 @@ void task_work_run(void)
975 +EXPORT_SYMBOL_GPL(task_work_run);
976 diff --git a/security/security.c b/security/security.c
977 index 51de970fbb1ed..b21f1ffd90051 100644
978 --- a/security/security.c
979 +++ b/security/security.c
980 @@ -1087,6 +1087,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
982 return call_int_hook(path_rmdir, 0, dir, dentry);
984 +EXPORT_SYMBOL_GPL(security_path_rmdir);
986 int security_path_unlink(const struct path *dir, struct dentry *dentry)
988 @@ -1103,6 +1104,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
990 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
992 +EXPORT_SYMBOL_GPL(security_path_symlink);
994 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
995 struct dentry *new_dentry)
996 @@ -1111,6 +1113,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
998 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
1000 +EXPORT_SYMBOL_GPL(security_path_link);
1002 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1003 const struct path *new_dir, struct dentry *new_dentry,
1004 @@ -1138,6 +1141,7 @@ int security_path_truncate(const struct path *path)
1006 return call_int_hook(path_truncate, 0, path);
1008 +EXPORT_SYMBOL_GPL(security_path_truncate);
1010 int security_path_chmod(const struct path *path, umode_t mode)
1012 @@ -1145,6 +1149,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1014 return call_int_hook(path_chmod, 0, path, mode);
1016 +EXPORT_SYMBOL_GPL(security_path_chmod);
1018 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1020 @@ -1152,6 +1157,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1022 return call_int_hook(path_chown, 0, path, uid, gid);
1024 +EXPORT_SYMBOL_GPL(security_path_chown);
1026 int security_path_chroot(const struct path *path)
1028 @@ -1252,6 +1258,7 @@ int security_inode_permission(struct inode *inode, int mask)
1030 return call_int_hook(inode_permission, 0, inode, mask);
1032 +EXPORT_SYMBOL_GPL(security_inode_permission);
1034 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1036 @@ -1429,6 +1436,7 @@ int security_file_permission(struct file *file, int mask)
1038 return fsnotify_perm(file, mask);
1040 +EXPORT_SYMBOL_GPL(security_file_permission);
1042 int security_file_alloc(struct file *file)
1044 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1045 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1046 +++ linux/Documentation/ABI/testing/debugfs-aufs 2019-07-11 15:42:14.455570938 +0200
1048 +What: /debug/aufs/si_<id>/
1050 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1052 + Under /debug/aufs, a directory named si_<id> is created
1053 + per aufs mount, where <id> is a unique id generated
1056 +What: /debug/aufs/si_<id>/plink
1058 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1060 + It has three lines and shows the information about the
1061 + pseudo-link. The first line is a single number
1062 + representing a number of buckets. The second line is a
1063 + number of pseudo-links per buckets (separated by a
1064 + blank). The last line is a single number representing a
1065 + total number of psedo-links.
1066 + When the aufs mount option 'noplink' is specified, it
1067 + will show "1\n0\n0\n".
1069 +What: /debug/aufs/si_<id>/xib
1071 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1073 + It shows the consumed blocks by xib (External Inode Number
1074 + Bitmap), its block size and file size.
1075 + When the aufs mount option 'noxino' is specified, it
1076 + will be empty. About XINO files, see the aufs manual.
1078 +What: /debug/aufs/si_<id>/xi0, xi1 ... xiN and xiN-N
1080 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1082 + It shows the consumed blocks by xino (External Inode Number
1083 + Translation Table), its link count, block size and file
1085 + Due to the file size limit, there may exist multiple
1086 + xino files per branch. In this case, "-N" is added to
1087 + the filename and it corresponds to the index of the
1088 + internal xino array. "-0" is omitted.
1089 + When the aufs mount option 'noxino' is specified, Those
1090 + entries won't exist. About XINO files, see the aufs
1093 +What: /debug/aufs/si_<id>/xigen
1095 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1097 + It shows the consumed blocks by xigen (External Inode
1098 + Generation Table), its block size and file size.
1099 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1101 + When the aufs mount option 'noxino' is specified, it
1102 + will be empty. About XINO files, see the aufs manual.
1103 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1104 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1105 +++ linux/Documentation/ABI/testing/sysfs-aufs 2019-07-11 15:42:14.455570938 +0200
1107 +What: /sys/fs/aufs/si_<id>/
1109 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1111 + Under /sys/fs/aufs, a directory named si_<id> is created
1112 + per aufs mount, where <id> is a unique id generated
1115 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1117 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1119 + It shows the abolute path of a member directory (which
1120 + is called branch) in aufs, and its permission.
1122 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1124 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1126 + It shows the id of a member directory (which is called
1129 +What: /sys/fs/aufs/si_<id>/xi_path
1131 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1133 + It shows the abolute path of XINO (External Inode Number
1134 + Bitmap, Translation Table and Generation Table) file
1135 + even if it is the default path.
1136 + When the aufs mount option 'noxino' is specified, it
1137 + will be empty. About XINO files, see the aufs manual.
1138 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1139 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1140 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2020-01-27 10:57:18.162204582 +0100
1143 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1145 +# This program is free software; you can redistribute it and/or modify
1146 +# it under the terms of the GNU General Public License as published by
1147 +# the Free Software Foundation; either version 2 of the License, or
1148 +# (at your option) any later version.
1150 +# This program is distributed in the hope that it will be useful,
1151 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1152 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1153 +# GNU General Public License for more details.
1155 +# You should have received a copy of the GNU General Public License
1156 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1159 +----------------------------------------
1161 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1162 +1. abbrev. for "advanced multi-layered unification filesystem".
1163 +2. abbrev. for "another unionfs".
1164 +3. abbrev. for "auf das" in German which means "on the" in English.
1165 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1166 + But "Filesystem aufs Filesystem" is hard to understand.
1167 +4. abbrev. for "African Urban Fashion Show".
1169 +AUFS is a filesystem with features:
1170 +- multi layered stackable unification filesystem, the member directory
1171 + is called as a branch.
1172 +- branch permission and attribute, 'readonly', 'real-readonly',
1173 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1175 +- internal "file copy-on-write".
1176 +- logical deletion, whiteout.
1177 +- dynamic branch manipulation, adding, deleting and changing permission.
1178 +- allow bypassing aufs, user's direct branch access.
1179 +- external inode number translation table and bitmap which maintains the
1180 + persistent aufs inode number.
1181 +- seekable directory, including NFS readdir.
1182 +- file mapping, mmap and sharing pages.
1183 +- pseudo-link, hardlink over branches.
1184 +- loopback mounted filesystem as a branch.
1185 +- several policies to select one among multiple writable branches.
1186 +- revert a single systemcall when an error occurs in aufs.
1190 +Multi Layered Stackable Unification Filesystem
1191 +----------------------------------------------------------------------
1192 +Most people already knows what it is.
1193 +It is a filesystem which unifies several directories and provides a
1194 +merged single directory. When users access a file, the access will be
1195 +passed/re-directed/converted (sorry, I am not sure which English word is
1196 +correct) to the real file on the member filesystem. The member
1197 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1198 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1199 +readonly branch is handled by creating 'whiteout' on the upper writable
1202 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1203 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1204 +different approaches to implement the merged-view.
1205 +The former tries putting it into VFS, and the latter implements as a
1206 +separate filesystem.
1207 +(If I misunderstand about these implementations, please let me know and
1208 +I shall correct it. Because it is a long time ago when I read their
1209 +source files last time).
1211 +UnionMount's approach will be able to small, but may be hard to share
1212 +branches between several UnionMount since the whiteout in it is
1213 +implemented in the inode on branch filesystem and always
1214 +shared. According to Bharata's post, readdir does not seems to be
1216 +There are several missing features known in this implementations such as
1217 +- for users, the inode number may change silently. eg. copy-up.
1218 +- link(2) may break by copy-up.
1219 +- read(2) may get an obsoleted filedata (fstat(2) too).
1220 +- fcntl(F_SETLK) may be broken by copy-up.
1221 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1224 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1225 +merged into mainline. This is another implementation of UnionMount as a
1226 +separated filesystem. All the limitations and known problems which
1227 +UnionMount are equally inherited to "overlay" filesystem.
1229 +Unionfs has a longer history. When I started implementing a stackable
1230 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1231 +inode, dentry and file objects and they have an array pointing lower
1232 +same kind objects. After contributing many patches for Unionfs, I
1233 +re-started my project AUFS (Jun 2006).
1235 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1236 +implemented my own ideas, approaches and enhancements and it became
1237 +totally different one.
1239 +Comparing DM snapshot and fs based implementation
1240 +- the number of bytes to be copied between devices is much smaller.
1241 +- the type of filesystem must be one and only.
1242 +- the fs must be writable, no readonly fs, even for the lower original
1243 + device. so the compression fs will not be usable. but if we use
1244 + loopback mount, we may address this issue.
1246 + mount /cdrom/squashfs.img /sq
1247 + losetup /sq/ext2.img
1248 + losetup /somewhere/cow
1249 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1250 +- it will be difficult (or needs more operations) to extract the
1251 + difference between the original device and COW.
1252 +- DM snapshot-merge may help a lot when users try merging. in the
1253 + fs-layer union, users will use rsync(1).
1255 +You may want to read my old paper "Filesystems in LiveCD"
1256 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1259 +Several characters/aspects/persona of aufs
1260 +----------------------------------------------------------------------
1262 +Aufs has several characters, aspects or persona.
1263 +1. a filesystem, callee of VFS helper
1264 +2. sub-VFS, caller of VFS helper for branches
1265 +3. a virtual filesystem which maintains persistent inode number
1266 +4. reader/writer of files on branches such like an application
1268 +1. Callee of VFS Helper
1269 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1270 +unlink(2) from an application reaches sys_unlink() kernel function and
1271 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1272 +calls filesystem specific unlink operation. Actually aufs implements the
1273 +unlink operation but it behaves like a redirector.
1275 +2. Caller of VFS Helper for Branches
1276 +aufs_unlink() passes the unlink request to the branch filesystem as if
1277 +it were called from VFS. So the called unlink operation of the branch
1278 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1279 +every necessary pre/post operation for the branch filesystem.
1280 +- acquire the lock for the parent dir on a branch
1281 +- lookup in a branch
1282 +- revalidate dentry on a branch
1283 +- mnt_want_write() for a branch
1284 +- vfs_unlink() for a branch
1285 +- mnt_drop_write() for a branch
1286 +- release the lock on a branch
1288 +3. Persistent Inode Number
1289 +One of the most important issue for a filesystem is to maintain inode
1290 +numbers. This is particularly important to support exporting a
1291 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1292 +backend block device for its own. But some storage is necessary to
1293 +keep and maintain the inode numbers. It may be a large space and may not
1294 +suit to keep in memory. Aufs rents some space from its first writable
1295 +branch filesystem (by default) and creates file(s) on it. These files
1296 +are created by aufs internally and removed soon (currently) keeping
1298 +Note: Because these files are removed, they are totally gone after
1299 + unmounting aufs. It means the inode numbers are not persistent
1300 + across unmount or reboot. I have a plan to make them really
1301 + persistent which will be important for aufs on NFS server.
1303 +4. Read/Write Files Internally (copy-on-write)
1304 +Because a branch can be readonly, when you write a file on it, aufs will
1305 +"copy-up" it to the upper writable branch internally. And then write the
1306 +originally requested thing to the file. Generally kernel doesn't
1307 +open/read/write file actively. In aufs, even a single write may cause a
1308 +internal "file copy". This behaviour is very similar to cp(1) command.
1310 +Some people may think it is better to pass such work to user space
1311 +helper, instead of doing in kernel space. Actually I am still thinking
1312 +about it. But currently I have implemented it in kernel space.
1313 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1314 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1315 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2020-01-27 10:57:18.162204582 +0100
1318 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1320 +# This program is free software; you can redistribute it and/or modify
1321 +# it under the terms of the GNU General Public License as published by
1322 +# the Free Software Foundation; either version 2 of the License, or
1323 +# (at your option) any later version.
1325 +# This program is distributed in the hope that it will be useful,
1326 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1327 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1328 +# GNU General Public License for more details.
1330 +# You should have received a copy of the GNU General Public License
1331 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1333 +Basic Aufs Internal Structure
1335 +Superblock/Inode/Dentry/File Objects
1336 +----------------------------------------------------------------------
1337 +As like an ordinary filesystem, aufs has its own
1338 +superblock/inode/dentry/file objects. All these objects have a
1339 +dynamically allocated array and store the same kind of pointers to the
1340 +lower filesystem, branch.
1341 +For example, when you build a union with one readwrite branch and one
1342 +readonly, mounted /au, /rw and /ro respectively.
1344 +- /ro/fileA exists but /rw/fileA
1346 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1347 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1348 +- [0] = NULL (because /rw/fileA doesn't exist)
1351 +This style of an array is essentially same to the aufs
1352 +superblock/inode/dentry/file objects.
1354 +Because aufs supports manipulating branches, ie. add/delete/change
1355 +branches dynamically, these objects has its own generation. When
1356 +branches are changed, the generation in aufs superblock is
1357 +incremented. And a generation in other object are compared when it is
1358 +accessed. When a generation in other objects are obsoleted, aufs
1359 +refreshes the internal array.
1363 +----------------------------------------------------------------------
1364 +Additionally aufs superblock has some data for policies to select one
1365 +among multiple writable branches, XIB files, pseudo-links and kobject.
1366 +See below in detail.
1367 +About the policies which supports copy-down a directory, see
1368 +wbr_policy.txt too.
1371 +Branch and XINO(External Inode Number Translation Table)
1372 +----------------------------------------------------------------------
1373 +Every branch has its own xino (external inode number translation table)
1374 +file. The xino file is created and unlinked by aufs internally. When two
1375 +members of a union exist on the same filesystem, they share the single
1377 +The struct of a xino file is simple, just a sequence of aufs inode
1378 +numbers which is indexed by the lower inode number.
1379 +In the above sample, assume the inode number of /ro/fileA is i111 and
1380 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1381 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1383 +When the inode numbers are not contiguous, the xino file will be sparse
1384 +which has a hole in it and doesn't consume as much disk space as it
1385 +might appear. If your branch filesystem consumes disk space for such
1386 +holes, then you should specify 'xino=' option at mounting aufs.
1388 +Aufs has a mount option to free the disk blocks for such holes in XINO
1389 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1390 +meet a problem of disk shortage due to XINO files, then you should try
1391 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1392 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1393 +the holes in XINO files.
1395 +Also a writable branch has three kinds of "whiteout bases". All these
1396 +are existed when the branch is joined to aufs, and their names are
1397 +whiteout-ed doubly, so that users will never see their names in aufs
1399 +1. a regular file which will be hardlinked to all whiteouts.
1400 +2. a directory to store a pseudo-link.
1401 +3. a directory to store an "orphan"-ed file temporary.
1404 + When you remove a file on a readonly branch, aufs handles it as a
1405 + logical deletion and creates a whiteout on the upper writable branch
1406 + as a hardlink of this file in order not to consume inode on the
1409 + See below, Pseudo-link.
1411 + When "fileC" exists on the lower readonly branch only and it is
1412 + opened and removed with its parent dir, and then user writes
1413 + something into it, then aufs copies-up fileC to this
1414 + directory. Because there is no other dir to store fileC. After
1415 + creating a file under this dir, the file is unlinked.
1417 +Because aufs supports manipulating branches, ie. add/delete/change
1418 +dynamically, a branch has its own id. When the branch order changes,
1419 +aufs finds the new index by searching the branch id.
1423 +----------------------------------------------------------------------
1424 +Assume "fileA" exists on the lower readonly branch only and it is
1425 +hardlinked to "fileB" on the branch. When you write something to fileA,
1426 +aufs copies-up it to the upper writable branch. Additionally aufs
1427 +creates a hardlink under the Pseudo-link Directory of the writable
1428 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1429 +simple list. If fileB is read after unlinking fileA, aufs returns
1430 +filedata from the pseudo-link instead of the lower readonly
1431 +branch. Because the pseudo-link is based upon the inode, to keep the
1432 +inode number by xino (see above) is essentially necessary.
1434 +All the hardlinks under the Pseudo-link Directory of the writable branch
1435 +should be restored in a proper location later. Aufs provides a utility
1436 +to do this. The userspace helpers executed at remounting and unmounting
1438 +During this utility is running, it puts aufs into the pseudo-link
1439 +maintenance mode. In this mode, only the process which began the
1440 +maintenance mode (and its child processes) is allowed to operate in
1441 +aufs. Some other processes which are not related to the pseudo-link will
1442 +be allowed to run too, but the rest have to return an error or wait
1443 +until the maintenance mode ends. If a process already acquires an inode
1444 +mutex (in VFS), it has to return an error.
1447 +XIB(external inode number bitmap)
1448 +----------------------------------------------------------------------
1449 +Addition to the xino file per a branch, aufs has an external inode number
1450 +bitmap in a superblock object. It is also an internal file such like a
1452 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1454 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1456 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1457 +reduce the number of consumed disk blocks for these files.
1460 +Virtual or Vertical Dir, and Readdir in Userspace
1461 +----------------------------------------------------------------------
1462 +In order to support multiple layers (branches), aufs readdir operation
1463 +constructs a virtual dir block on memory. For readdir, aufs calls
1464 +vfs_readdir() internally for each dir on branches, merges their entries
1465 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1466 +object. So the file object has its entry list until it is closed. The
1467 +entry list will be updated when the file position is zero and becomes
1468 +obsoleted. This decision is made in aufs automatically.
1470 +The dynamically allocated memory block for the name of entries has a
1471 +unit of 512 bytes (by default) and stores the names contiguously (no
1472 +padding). Another block for each entry is handled by kmem_cache too.
1473 +During building dir blocks, aufs creates hash list and judging whether
1474 +the entry is whiteouted by its upper branch or already listed.
1475 +The merged result is cached in the corresponding inode object and
1476 +maintained by a customizable life-time option.
1478 +Some people may call it can be a security hole or invite DoS attack
1479 +since the opened and once readdir-ed dir (file object) holds its entry
1480 +list and becomes a pressure for system memory. But I'd say it is similar
1481 +to files under /proc or /sys. The virtual files in them also holds a
1482 +memory page (generally) while they are opened. When an idea to reduce
1483 +memory for them is introduced, it will be applied to aufs too.
1484 +For those who really hate this situation, I've developed readdir(3)
1485 +library which operates this merging in userspace. You just need to set
1486 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1487 +kernel space for readdir(3).
1491 +----------------------------------------------------------------------
1492 +Aufs sometimes requires privilege access to a branch. For instance,
1493 +in copy-up/down operation. When a user process is going to make changes
1494 +to a file which exists in the lower readonly branch only, and the mode
1495 +of one of ancestor directories may not be writable by a user
1496 +process. Here aufs copy-up the file with its ancestors and they may
1497 +require privilege to set its owner/group/mode/etc.
1498 +This is a typical case of a application character of aufs (see
1501 +Aufs uses workqueue synchronously for this case. It creates its own
1502 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1503 +passes the request to call mkdir or write (for example), and wait for
1504 +its completion. This approach solves a problem of a signal handler
1506 +If aufs didn't adopt the workqueue and changed the privilege of the
1507 +process, then the process may receive the unexpected SIGXFSZ or other
1510 +Also aufs uses the system global workqueue ("events" kernel thread) too
1511 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1512 +whiteout base and etc. This is unrelated to a privilege.
1513 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1514 +superblock at the beginning, at the same time waits for the completion
1515 +of all queued asynchronous tasks.
1519 +----------------------------------------------------------------------
1520 +The whiteout in aufs is very similar to Unionfs's. That is represented
1521 +by its filename. UnionMount takes an approach of a file mode, but I am
1522 +afraid several utilities (find(1) or something) will have to support it.
1524 +Basically the whiteout represents "logical deletion" which stops aufs to
1525 +lookup further, but also it represents "dir is opaque" which also stop
1528 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1529 +In order to make several functions in a single systemcall to be
1530 +revertible, aufs adopts an approach to rename a directory to a temporary
1531 +unique whiteouted name.
1532 +For example, in rename(2) dir where the target dir already existed, aufs
1533 +renames the target dir to a temporary unique whiteouted name before the
1534 +actual rename on a branch, and then handles other actions (make it opaque,
1535 +update the attributes, etc). If an error happens in these actions, aufs
1536 +simply renames the whiteouted name back and returns an error. If all are
1537 +succeeded, aufs registers a function to remove the whiteouted unique
1538 +temporary name completely and asynchronously to the system global
1543 +----------------------------------------------------------------------
1544 +It is a well-known feature or concept.
1545 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1546 +internally and makes change to the new file on the upper writable branch.
1547 +When the trigger systemcall does not update the timestamps of the parent
1548 +dir, aufs reverts it after copy-up.
1551 +Move-down (aufs3.9 and later)
1552 +----------------------------------------------------------------------
1553 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1554 +the lower readonly branch to the upper writable branch when a user
1555 +changes something about the file.
1556 +"Move-down" is an opposite action of copy-up. Basically this action is
1557 +ran manually instead of automatically and internally.
1558 +For desgin and implementation, aufs has to consider these issues.
1559 +- whiteout for the file may exist on the lower branch.
1560 +- ancestor directories may not exist on the lower branch.
1561 +- diropq for the ancestor directories may exist on the upper branch.
1562 +- free space on the lower branch will reduce.
1563 +- another access to the file may happen during moving-down, including
1564 + UDBA (see "Revalidate Dentry and UDBA").
1565 +- the file should not be hard-linked nor pseudo-linked. they should be
1566 + handled by auplink utility later.
1568 +Sometimes users want to move-down a file from the upper writable branch
1569 +to the lower readonly or writable branch. For instance,
1570 +- the free space of the upper writable branch is going to run out.
1571 +- create a new intermediate branch between the upper and lower branch.
1574 +For this purpose, use "aumvdown" command in aufs-util.git.
1575 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1576 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1577 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2020-01-27 10:57:18.162204582 +0100
1580 +# Copyright (C) 2015-2020 Junjiro R. Okajima
1582 +# This program is free software; you can redistribute it and/or modify
1583 +# it under the terms of the GNU General Public License as published by
1584 +# the Free Software Foundation; either version 2 of the License, or
1585 +# (at your option) any later version.
1587 +# This program is distributed in the hope that it will be useful,
1588 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1589 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1590 +# GNU General Public License for more details.
1592 +# You should have received a copy of the GNU General Public License
1593 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1595 +Support for a branch who has its ->atomic_open()
1596 +----------------------------------------------------------------------
1597 +The filesystems who implement its ->atomic_open() are not majority. For
1598 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1599 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1600 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1601 +sure whether all filesystems who have ->atomic_open() behave like this,
1602 +but NFSv4 surely returns the error.
1604 +In order to support ->atomic_open() for aufs, there are a few
1607 +A. Introduce aufs_atomic_open()
1608 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1610 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1611 + an aufs user Pip Cet's approach
1612 + - calls aufs_create(), VFS finish_open() and notify_change().
1613 + - pass fake-mode to finish_open(), and then correct the mode by
1615 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1616 + - no aufs_atomic_open().
1617 + - aufs_lookup() registers the TID to an aufs internal object.
1618 + - aufs_create() does nothing when the matching TID is registered, but
1619 + registers the mode.
1620 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1621 + TID is registered.
1622 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1624 + - no aufs_atomic_open().
1625 + - aufs_create() registers the TID to an internal object. this info
1626 + represents "this process created this file just now."
1627 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1628 + registered TID and re-try open() with superuser's credential.
1630 +Pros and cons for each approach.
1633 + - straightforward but highly depends upon VFS internal.
1634 + - the atomic behavaiour is kept.
1635 + - some of parameters such as nameidata are hard to reproduce for
1639 + - easy to implement.
1640 + - the atomic behavaiour is lost.
1642 + - the atomic behavaiour is kept.
1643 + - dirty and tricky.
1644 + - VFS checks whether the file is created correctly after calling
1645 + ->create(), which means this approach doesn't work.
1647 + - easy to implement.
1648 + - the atomic behavaiour is lost.
1649 + - to open a file with superuser's credential and give it to a user
1650 + process is a bad idea, since the file object keeps the credential
1651 + in it. It may affect LSM or something. This approach doesn't work
1654 +The approach A is ideal, but it hard to implement. So here is a
1655 +variation of A, which is to be implemented.
1657 +A-1. Introduce aufs_atomic_open()
1658 + - calls branch fs ->atomic_open() if exists. otherwise calls
1659 + vfs_create() and finish_open().
1660 + - the demerit is that the several checks after branch fs
1661 + ->atomic_open() are lost. in the ordinary case, the checks are
1662 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1663 + be implemented in aufs, but not all I am afraid.
1664 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1665 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1666 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2020-01-27 10:57:18.165538015 +0100
1669 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1671 +# This program is free software; you can redistribute it and/or modify
1672 +# it under the terms of the GNU General Public License as published by
1673 +# the Free Software Foundation; either version 2 of the License, or
1674 +# (at your option) any later version.
1676 +# This program is distributed in the hope that it will be useful,
1677 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1678 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1679 +# GNU General Public License for more details.
1681 +# You should have received a copy of the GNU General Public License
1682 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1685 +----------------------------------------------------------------------
1686 +Since aufs has a character of sub-VFS (see Introduction), it operates
1687 +lookup for branches as VFS does. It may be a heavy work. But almost all
1688 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1689 +directly connected to its parent. Digging down the directory hierarchy
1690 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1693 +When a branch is a remote filesystem, aufs basically relies upon its
1694 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1696 +For d_revalidate, aufs implements three levels of revalidate tests. See
1697 +"Revalidate Dentry and UDBA" in detail.
1700 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1701 +----------------------------------------------------------------------
1702 +Let's try case study.
1703 +- aufs has two branches, upper readwrite and lower readonly.
1705 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1706 +- user invoked "chmod a+rx /au/dirA"
1707 +- the internal copy-up is activated and "/rw/dirA" is created and its
1708 + permission bits are set to world readable.
1709 +- then "/au/dirA" becomes world readable?
1711 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1712 +or it may be a natively readonly filesystem. If aufs respects the lower
1713 +branch, it should not respond readdir request from other users. But user
1714 +allowed it by chmod. Should really aufs rejects showing the entries
1717 +To be honest, I don't have a good solution for this case. So aufs
1718 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1720 +When dirperm1 is specified, aufs checks only the highest one for the
1721 +directory permission, and shows the entries. Otherwise, as usual, checks
1722 +every dir existing on all branches and rejects the request.
1724 +As a side effect, dirperm1 option improves the performance of aufs
1725 +because the number of permission check is reduced when the number of
1729 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1730 +----------------------------------------------------------------------
1731 +Generally VFS helpers re-validate a dentry as a part of lookup.
1732 +0. digging down the directory hierarchy.
1733 +1. lock the parent dir by its i_mutex.
1734 +2. lookup the final (child) entry.
1736 +4. call the actual operation (create, unlink, etc.)
1737 +5. unlock the parent dir
1739 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1740 +called. Actually aufs implements it and checks the dentry on a branch is
1742 +But it is not enough. Because aufs has to release the lock for the
1743 +parent dir on a branch at the end of ->lookup() (step 2) and
1744 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1746 +If the file on a branch is changed directly, eg. bypassing aufs, after
1747 +aufs released the lock, then the subsequent operation may cause
1748 +something unpleasant result.
1750 +This situation is a result of VFS architecture, ->lookup() and
1751 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1752 +design from VFS's point of view. It is just not suitable for sub-VFS
1755 +Aufs supports such case by three level of revalidation which is
1756 +selectable by user.
1757 +1. Simple Revalidate
1758 + Addition to the native flow in VFS's, confirm the child-parent
1759 + relationship on the branch just after locking the parent dir on the
1760 + branch in the "actual operation" (step 4). When this validation
1761 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1762 + checks the validation of the dentry on branches.
1763 +2. Monitor Changes Internally by Inotify/Fsnotify
1764 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1765 + the dentry on the branch, and returns EBUSY if it finds different
1767 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1768 + during it is in cache. When the event is notified, aufs registers a
1769 + function to kernel 'events' thread by schedule_work(). And the
1770 + function sets some special status to the cached aufs dentry and inode
1771 + private data. If they are not cached, then aufs has nothing to
1772 + do. When the same file is accessed through aufs (step 0-3) later,
1773 + aufs will detect the status and refresh all necessary data.
1774 + In this mode, aufs has to ignore the event which is fired by aufs
1776 +3. No Extra Validation
1777 + This is the simplest test and doesn't add any additional revalidation
1778 + test, and skip the revalidation in step 4. It is useful and improves
1779 + aufs performance when system surely hide the aufs branches from user,
1780 + by over-mounting something (or another method).
1781 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1782 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1783 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2020-01-27 10:57:18.165538015 +0100
1786 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1788 +# This program is free software; you can redistribute it and/or modify
1789 +# it under the terms of the GNU General Public License as published by
1790 +# the Free Software Foundation; either version 2 of the License, or
1791 +# (at your option) any later version.
1793 +# This program is distributed in the hope that it will be useful,
1794 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1795 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1796 +# GNU General Public License for more details.
1798 +# You should have received a copy of the GNU General Public License
1799 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1801 +Branch Manipulation
1803 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1804 +and changing its permission/attribute, there are a lot of works to do.
1808 +----------------------------------------------------------------------
1809 +o Confirm the adding dir exists outside of aufs, including loopback
1810 + mount, and its various attributes.
1811 +o Initialize the xino file and whiteout bases if necessary.
1814 +o Check the owner/group/mode of the directory
1815 + When the owner/group/mode of the adding directory differs from the
1816 + existing branch, aufs issues a warning because it may impose a
1818 + For example, when a upper writable branch has a world writable empty
1819 + top directory, a malicious user can create any files on the writable
1820 + branch directly, like copy-up and modify manually. If something like
1821 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1822 + writable branch, and the writable branch is world-writable, then a
1823 + malicious guy may create /etc/passwd on the writable branch directly
1824 + and the infected file will be valid in aufs.
1825 + I am afraid it can be a security issue, but aufs can do nothing except
1826 + producing a warning.
1830 +----------------------------------------------------------------------
1831 +o Confirm the deleting branch is not busy
1832 + To be general, there is one merit to adopt "remount" interface to
1833 + manipulate branches. It is to discard caches. At deleting a branch,
1834 + aufs checks the still cached (and connected) dentries and inodes. If
1835 + there are any, then they are all in-use. An inode without its
1836 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1838 + For the cached one, aufs checks whether the same named entry exists on
1840 + If the cached one is a directory, because aufs provides a merged view
1841 + to users, as long as one dir is left on any branch aufs can show the
1842 + dir to users. In this case, the branch can be removed from aufs.
1843 + Otherwise aufs rejects deleting the branch.
1845 + If any file on the deleting branch is opened by aufs, then aufs
1849 +Modify the Permission of a Branch
1850 +----------------------------------------------------------------------
1851 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1854 +o rw --> ro: Confirm the modifying branch is not busy
1855 + Aufs rejects the request if any of these conditions are true.
1856 + - a file on the branch is mmap-ed.
1857 + - a regular file on the branch is opened for write and there is no
1858 + same named entry on the upper branch.
1859 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1860 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1861 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2020-01-27 10:57:18.165538015 +0100
1864 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1866 +# This program is free software; you can redistribute it and/or modify
1867 +# it under the terms of the GNU General Public License as published by
1868 +# the Free Software Foundation; either version 2 of the License, or
1869 +# (at your option) any later version.
1871 +# This program is distributed in the hope that it will be useful,
1872 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1873 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1874 +# GNU General Public License for more details.
1876 +# You should have received a copy of the GNU General Public License
1877 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1879 +Policies to Select One among Multiple Writable Branches
1880 +----------------------------------------------------------------------
1881 +When the number of writable branch is more than one, aufs has to decide
1882 +the target branch for file creation or copy-up. By default, the highest
1883 +writable branch which has the parent (or ancestor) dir of the target
1884 +file is chosen (top-down-parent policy).
1885 +By user's request, aufs implements some other policies to select the
1886 +writable branch, for file creation several policies, round-robin,
1887 +most-free-space, and other policies. For copy-up, top-down-parent,
1888 +bottom-up-parent, bottom-up and others.
1890 +As expected, the round-robin policy selects the branch in circular. When
1891 +you have two writable branches and creates 10 new files, 5 files will be
1892 +created for each branch. mkdir(2) systemcall is an exception. When you
1893 +create 10 new directories, all will be created on the same branch.
1894 +And the most-free-space policy selects the one which has most free
1895 +space among the writable branches. The amount of free space will be
1896 +checked by aufs internally, and users can specify its time interval.
1898 +The policies for copy-up is more simple,
1899 +top-down-parent is equivalent to the same named on in create policy,
1900 +bottom-up-parent selects the writable branch where the parent dir
1901 +exists and the nearest upper one from the copyup-source,
1902 +bottom-up selects the nearest upper writable branch from the
1903 +copyup-source, regardless the existence of the parent dir.
1905 +There are some rules or exceptions to apply these policies.
1906 +- If there is a readonly branch above the policy-selected branch and
1907 + the parent dir is marked as opaque (a variation of whiteout), or the
1908 + target (creating) file is whiteout-ed on the upper readonly branch,
1909 + then the result of the policy is ignored and the target file will be
1910 + created on the nearest upper writable branch than the readonly branch.
1911 +- If there is a writable branch above the policy-selected branch and
1912 + the parent dir is marked as opaque or the target file is whiteouted
1913 + on the branch, then the result of the policy is ignored and the target
1914 + file will be created on the highest one among the upper writable
1915 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1917 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1918 + They try selecting the branch where the source exists as possible
1919 + since copyup a large file will take long time. If it can't be,
1920 + ie. the branch where the source exists is readonly, then they will
1921 + follow the copyup policy.
1922 +- There is an exception for rename(2) when the target exists.
1923 + If the rename target exists, aufs compares the index of the branches
1924 + where the source and the target exists and selects the higher
1925 + one. If the selected branch is readonly, then aufs follows the
1927 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1928 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1929 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2019-07-11 15:42:14.458904362 +0200
1932 +// to view this graph, run dot(1) command in GRAPHVIZ.
1936 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1940 +aufs_rename -> whinfo [label="store/remove"];
1943 +inode_list [label="h_inum list in branch\ncache"];
1946 +whinode [label="h_inum list file"];
1949 +brmgmt [label="br_add/del/mod/umount"];
1951 +brmgmt -> inode_list [label="create/remove"];
1952 +brmgmt -> whinode [label="load/store"];
1954 +inode_list -> whinode [style=dashed,dir=both];
1956 +aufs_rename -> inode_list [label="add/del"];
1958 +aufs_lookup -> inode_list [label="search"];
1960 +aufs_lookup -> whinfo [label="load/remove"];
1962 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1963 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1964 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2020-01-27 10:57:18.165538015 +0100
1967 +# Copyright (C) 2017-2020 Junjiro R. Okajima
1969 +# This program is free software; you can redistribute it and/or modify
1970 +# it under the terms of the GNU General Public License as published by
1971 +# the Free Software Foundation; either version 2 of the License, or
1972 +# (at your option) any later version.
1974 +# This program is distributed in the hope that it will be useful,
1975 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1976 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1977 +# GNU General Public License for more details.
1979 +# You should have received a copy of the GNU General Public License
1980 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1982 +Special handling for renaming a directory (DIRREN)
1983 +----------------------------------------------------------------------
1984 +First, let's assume we have a simple usecase.
1988 +- /ro/dirA and /ro/dirA/file exist too
1989 +- there is no dirB on both branches
1990 +- a user issues rename("dirA", "dirB")
1992 +Now, what should aufs behave against this rename(2)?
1993 +There are a few possible cases.
1996 + since dirA exists on a readonly branch which cannot be renamed.
1998 + it is possible to copy-up dirA (only the dir itself), but the child
1999 + entries ("file" in this case) should not be. it must be a bad
2000 + approach to copy-up recursively.
2001 +C. returns a success.
2002 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
2003 + is a violation of aufs' policy.
2004 +D. construct an extra information which indicates that /ro/dirA should
2005 + be handled as the name of dirB.
2006 + overlayfs has a similar feature called REDIRECT.
2008 +Until now, aufs implements the case B only which returns EXDEV, and
2009 +expects the userspace application behaves like mv(1) which tries
2010 +issueing rename(2) recursively.
2012 +A new aufs feature called DIRREN is introduced which implements the case
2013 +D. There are several "extra information" added.
2015 +1. detailed info per renamed directory
2016 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
2017 +2. the inode-number list of directories on a branch
2018 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
2020 +The filename of "detailed info per directory" represents the lower
2021 +branch, and its format is
2022 +- a type of the branch id
2024 + + uuid (not implemented yet)
2027 +- the inode-number of the branch root dir
2029 +And it contains these info in a single regular file.
2031 +- branch's inode-number of the logically renamed dir
2032 +- the name of the before-renamed dir
2034 +The "detailed info per directory" file is created in aufs rename(2), and
2035 +loaded in any lookup.
2036 +The info is considered in lookup for the matching case only. Here
2037 +"matching" means that the root of branch (in the info filename) is same
2038 +to the current looking-up branch. After looking-up the before-renamed
2039 +name, the inode-number is compared. And the matched dentry is used.
2041 +The "inode-number list of directories" is a regular file which contains
2042 +simply the inode-numbers on the branch. The file is created or updated
2043 +in removing the branch, and loaded in adding the branch. Its lifetime is
2044 +equal to the branch.
2045 +The list is refered in lookup, and when the current target inode is
2046 +found in the list, the aufs tries loading the "detailed info per
2047 +directory" and get the changed and valid name of the dir.
2049 +Theoretically these "extra informaiton" may be able to be put into XATTR
2050 +in the dir inode. But aufs doesn't choose this way because
2051 +1. XATTR may not be supported by the branch (or its configuration)
2052 +2. XATTR may have its size limit.
2053 +3. XATTR may be less easy to convert than a regular file, when the
2054 + format of the info is changed in the future.
2055 +At the same time, I agree that the regular file approach is much slower
2056 +than XATTR approach. So, in the future, aufs may take the XATTR or other
2059 +This DIRREN feature is enabled by aufs configuration, and is activated
2060 +by a new mount option.
2062 +For the more complicated case, there is a work with UDBA option, which
2063 +is to dected the direct access to the branches (by-passing aufs) and to
2064 +maintain the cashes in aufs. Since a single cached aufs dentry may
2065 +contains two names, before- and after-rename, the name comparision in
2066 +UDBA handler may not work correctly. In this case, the behaviour will be
2067 +equivalen to udba=reval case.
2068 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
2069 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
2070 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2020-01-27 10:57:18.165538015 +0100
2073 +# Copyright (C) 2011-2020 Junjiro R. Okajima
2075 +# This program is free software; you can redistribute it and/or modify
2076 +# it under the terms of the GNU General Public License as published by
2077 +# the Free Software Foundation; either version 2 of the License, or
2078 +# (at your option) any later version.
2080 +# This program is distributed in the hope that it will be useful,
2081 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2082 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2083 +# GNU General Public License for more details.
2085 +# You should have received a copy of the GNU General Public License
2086 +# along with this program; if not, write to the Free Software
2087 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2090 +File-based Hierarchical Storage Management (FHSM)
2091 +----------------------------------------------------------------------
2092 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2093 +storage world. Aufs provides this feature as file-based with multiple
2094 +writable branches, based upon the principle of "Colder, the Lower".
2095 +Here the word "colder" means that the less used files, and "lower" means
2096 +that the position in the order of the stacked branches vertically.
2097 +These multiple writable branches are prioritized, ie. the topmost one
2098 +should be the fastest drive and be used heavily.
2100 +o Characters in aufs FHSM story
2101 +- aufs itself and a new branch attribute.
2102 +- a new ioctl interface to move-down and to establish a connection with
2103 + the daemon ("move-down" is a converse of "copy-up").
2104 +- userspace tool and daemon.
2106 +The userspace daemon establishes a connection with aufs and waits for
2107 +the notification. The notified information is very similar to struct
2108 +statfs containing the number of consumed blocks and inodes.
2109 +When the consumed blocks/inodes of a branch exceeds the user-specified
2110 +upper watermark, the daemon activates its move-down process until the
2111 +consumed blocks/inodes reaches the user-specified lower watermark.
2113 +The actual move-down is done by aufs based upon the request from
2114 +user-space since we need to maintain the inode number and the internal
2115 +pointer arrays in aufs.
2117 +Currently aufs FHSM handles the regular files only. Additionally they
2118 +must not be hard-linked nor pseudo-linked.
2121 +o Cowork of aufs and the user-space daemon
2122 + During the userspace daemon established the connection, aufs sends a
2123 + small notification to it whenever aufs writes something into the
2124 + writable branch. But it may cost high since aufs issues statfs(2)
2125 + internally. So user can specify a new option to cache the
2126 + info. Actually the notification is controlled by these factors.
2127 + + the specified cache time.
2128 + + classified as "force" by aufs internally.
2129 + Until the specified time expires, aufs doesn't send the info
2130 + except the forced cases. When aufs decide forcing, the info is always
2131 + notified to userspace.
2132 + For example, the number of free inodes is generally large enough and
2133 + the shortage of it happens rarely. So aufs doesn't force the
2134 + notification when creating a new file, directory and others. This is
2135 + the typical case which aufs doesn't force.
2136 + When aufs writes the actual filedata and the files consumes any of new
2137 + blocks, the aufs forces notifying.
2140 +o Interfaces in aufs
2141 +- New branch attribute.
2143 + Specifies that the branch is managed by FHSM feature. In other word,
2144 + participant in the FHSM.
2145 + When nofhsm is set to the branch, it will not be the source/target
2146 + branch of the move-down operation. This attribute is set
2147 + independently from coo and moo attributes, and if you want full
2148 + FHSM, you should specify them as well.
2149 +- New mount option.
2151 + Specifies a second to suppress many less important info to be
2154 + + AUFS_CTL_FHSM_FD
2155 + create a new file descriptor which userspace can read the notification
2156 + (a subset of struct statfs) from aufs.
2157 +- Module parameter 'brs'
2158 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2160 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2161 + When there are two or more branches with fhsm attributes,
2162 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2163 + terminates it. As a result of remounting and branch-manipulation, the
2164 + number of branches with fhsm attribute can be one. In this case,
2165 + /sbin/mount.aufs will terminate the user-space daemon.
2168 +Finally the operation is done as these steps in kernel-space.
2170 + + no one else is using the file.
2171 + + the file is not hard-linked.
2172 + + the file is not pseudo-linked.
2173 + + the file is a regular file.
2174 + + the parent dir is not opaqued.
2175 +- find the target writable branch.
2176 +- make sure the file is not whiteout-ed by the upper (than the target)
2178 +- make the parent dir on the target branch.
2179 +- mutex lock the inode on the branch.
2180 +- unlink the whiteout on the target branch (if exists).
2181 +- lookup and create the whiteout-ed temporary name on the target branch.
2182 +- copy the file as the whiteout-ed temporary name on the target branch.
2183 +- rename the whiteout-ed temporary name to the original name.
2184 +- unlink the file on the source branch.
2185 +- maintain the internal pointer array and the external inode number
2187 +- maintain the timestamps and other attributes of the parent dir and the
2190 +And of course, in every step, an error may happen. So the operation
2191 +should restore the original file state after an error happens.
2192 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2193 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2194 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2020-01-27 10:57:18.165538015 +0100
2197 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2199 +# This program is free software; you can redistribute it and/or modify
2200 +# it under the terms of the GNU General Public License as published by
2201 +# the Free Software Foundation; either version 2 of the License, or
2202 +# (at your option) any later version.
2204 +# This program is distributed in the hope that it will be useful,
2205 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2206 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2207 +# GNU General Public License for more details.
2209 +# You should have received a copy of the GNU General Public License
2210 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2212 +mmap(2) -- File Memory Mapping
2213 +----------------------------------------------------------------------
2214 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2215 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2217 +This approach is simple and good, but there is one problem.
2218 +Under /proc, several entries show the mmapped files by its path (with
2219 +device and inode number), and the printed path will be the path on the
2220 +branch fs's instead of virtual aufs's.
2221 +This is not a problem in most cases, but some utilities lsof(1) (and its
2222 +user) may expect the path on aufs.
2224 +To address this issue, aufs adds a new member called vm_prfile in struct
2225 +vm_area_struct (and struct vm_region). The original vm_file points to
2226 +the file on the branch fs in order to handle everything correctly as
2227 +usual. The new vm_prfile points to a virtual file in aufs, and the
2228 +show-functions in procfs refers to vm_prfile if it is set.
2229 +Also we need to maintain several other places where touching vm_file
2231 +- fork()/clone() copies vma and the reference count of vm_file is
2233 +- merging vma maintains the ref count too.
2235 +This is not a good approach. It just fakes the printed path. But it
2236 +leaves all behaviour around f_mapping unchanged. This is surely an
2238 +Actually aufs had adopted another complicated approach which calls
2239 +generic_file_mmap() and handles struct vm_operations_struct. In this
2240 +approach, aufs met a hard problem and I could not solve it without
2241 +switching the approach.
2243 +There may be one more another approach which is
2244 +- bind-mount the branch-root onto the aufs-root internally
2245 +- grab the new vfsmount (ie. struct mount)
2246 +- lazy-umount the branch-root internally
2247 +- in open(2) the aufs-file, open the branch-file with the hidden
2248 + vfsmount (instead of the original branch's vfsmount)
2249 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2250 + but it may be possible from userspace by the mount helper.
2252 +Adding the internal hidden vfsmount and using it in opening a file, the
2253 +file path under /proc will be printed correctly. This approach looks
2254 +smarter, but is not possible I am afraid.
2255 +- aufs-root may be bind-mount later. when it happens, another hidden
2256 + vfsmount will be required.
2257 +- it is hard to get the chance to bind-mount and lazy-umount
2258 + + in kernel-space, FS can have vfsmount in open(2) via
2259 + file->f_path, and aufs can know its vfsmount. But several locks are
2260 + already acquired, and if aufs tries to bind-mount and lazy-umount
2261 + here, then it may cause a deadlock.
2262 + + in user-space, bind-mount doesn't invoke the mount helper.
2263 +- since /proc shows dev and ino, aufs has to give vma these info. it
2264 + means a new member vm_prinode will be necessary. this is essentially
2265 + equivalent to vm_prfile described above.
2267 +I have to give up this "looks-smater" approach.
2268 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2269 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2270 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2020-01-27 10:57:18.165538015 +0100
2273 +# Copyright (C) 2014-2020 Junjiro R. Okajima
2275 +# This program is free software; you can redistribute it and/or modify
2276 +# it under the terms of the GNU General Public License as published by
2277 +# the Free Software Foundation; either version 2 of the License, or
2278 +# (at your option) any later version.
2280 +# This program is distributed in the hope that it will be useful,
2281 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2282 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2283 +# GNU General Public License for more details.
2285 +# You should have received a copy of the GNU General Public License
2286 +# along with this program; if not, write to the Free Software
2287 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2290 +Listing XATTR/EA and getting the value
2291 +----------------------------------------------------------------------
2292 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2293 +shows the values from the topmost existing file. This behaviour is good
2294 +for the non-dir entries since the bahaviour exactly matches the shown
2295 +information. But for the directories, aufs considers all the same named
2296 +entries on the lower branches. Which means, if one of the lower entry
2297 +rejects readdir call, then aufs returns an error even if the topmost
2298 +entry allows it. This behaviour is necessary to respect the branch fs's
2299 +security, but can make users confused since the user-visible standard
2300 +attributes don't match the behaviour.
2301 +To address this issue, aufs has a mount option called dirperm1 which
2302 +checks the permission for the topmost entry only, and ignores the lower
2303 +entry's permission.
2305 +A similar issue can happen around XATTR.
2306 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2307 +always set. Otherwise these very unpleasant situation would happen.
2308 +- listxattr(2) may return the duplicated entries.
2309 +- users may not be able to remove or reset the XATTR forever,
2312 +XATTR/EA support in the internal (copy,move)-(up,down)
2313 +----------------------------------------------------------------------
2314 +Generally the extended attributes of inode are categorized as these.
2315 +- "security" for LSM and capability.
2316 +- "system" for posix ACL, 'acl' mount option is required for the branch
2318 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2319 +- "user" for userspace, 'user_xattr' mount option is required for the
2320 + branch fs generally.
2322 +Moreover there are some other categories. Aufs handles these rather
2323 +unpopular categories as the ordinary ones, ie. there is no special
2324 +condition nor exception.
2326 +In copy-up, the support for XATTR on the dst branch may differ from the
2327 +src branch. In this case, the copy-up operation will get an error and
2328 +the original user operation which triggered the copy-up will fail. It
2329 +can happen that even all copy-up will fail.
2330 +When both of src and dst branches support XATTR and if an error occurs
2331 +during copying XATTR, then the copy-up should fail obviously. That is a
2332 +good reason and aufs should return an error to userspace. But when only
2333 +the src branch support that XATTR, aufs should not return an error.
2334 +For example, the src branch supports ACL but the dst branch doesn't
2335 +because the dst branch may natively un-support it or temporary
2336 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2337 +may NOT return an error even if the XATTR is not supported. It is
2338 +totally up to the branch fs.
2340 +Anyway when the aufs internal copy-up gets an error from the dst branch
2341 +fs, then aufs tries removing the just copied entry and returns the error
2342 +to the userspace. The worst case of this situation will be all copy-up
2345 +For the copy-up operation, there two basic approaches.
2346 +- copy the specified XATTR only (by category above), and return the
2347 + error unconditionally if it happens.
2348 +- copy all XATTR, and ignore the error on the specified category only.
2350 +In order to support XATTR and to implement the correct behaviour, aufs
2351 +chooses the latter approach and introduces some new branch attributes,
2352 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2353 +They correspond to the XATTR namespaces (see above). Additionally, to be
2354 +convenient, "icex" is also provided which means all "icex*" attributes
2355 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2357 +The meaning of these attributes is to ignore the error from setting
2358 +XATTR on that branch.
2359 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2360 +error from the dst branch according to the specified attributes.
2362 +Some XATTR may have its default value. The default value may come from
2363 +the parent dir or the environment. If the default value is set at the
2364 +file creating-time, it will be overwritten by copy-up.
2365 +Some contradiction may happen I am afraid.
2366 +Do we need another attribute to stop copying XATTR? I am unsure. For
2367 +now, aufs implements the branch attributes to ignore the error.
2368 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2369 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2370 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2020-01-27 10:57:18.165538015 +0100
2373 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2375 +# This program is free software; you can redistribute it and/or modify
2376 +# it under the terms of the GNU General Public License as published by
2377 +# the Free Software Foundation; either version 2 of the License, or
2378 +# (at your option) any later version.
2380 +# This program is distributed in the hope that it will be useful,
2381 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2382 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2383 +# GNU General Public License for more details.
2385 +# You should have received a copy of the GNU General Public License
2386 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2388 +Export Aufs via NFS
2389 +----------------------------------------------------------------------
2390 +Here is an approach.
2391 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2393 +- iget_locked(): initialize aufs inode generation for a new inode, and
2394 + store it in xigen file.
2395 +- destroy_inode(): increment aufs inode generation and store it in xigen
2396 + file. it is necessary even if it is not unlinked, because any data of
2397 + inode may be changed by UDBA.
2398 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2399 + build file handle by
2400 + + branch id (4 bytes)
2401 + + superblock generation (4 bytes)
2402 + + inode number (4 or 8 bytes)
2403 + + parent dir inode number (4 or 8 bytes)
2404 + + inode generation (4 bytes))
2405 + + return value of exportfs_encode_fh() for the parent on a branch (4
2407 + + file handle for a branch (by exportfs_encode_fh())
2409 + + find the index of a branch from its id in handle, and check it is
2410 + still exist in aufs.
2411 + + 1st level: get the inode number from handle and search it in cache.
2412 + + 2nd level: if not found in cache, get the parent inode number from
2413 + the handle and search it in cache. and then open the found parent
2414 + dir, find the matching inode number by vfs_readdir() and get its
2415 + name, and call lookup_one_len() for the target dentry.
2416 + + 3rd level: if the parent dir is not cached, call
2417 + exportfs_decode_fh() for a branch and get the parent on a branch,
2418 + build a pathname of it, convert it a pathname in aufs, call
2419 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2421 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2422 + for every branch, but not itself. to get this, (currently) aufs
2423 + searches in current->nsproxy->mnt_ns list. it may not be a good
2424 + idea, but I didn't get other approach.
2425 + + test the generation of the gotten inode.
2426 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2427 + convert it into ESTALE for NFSD.
2428 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2429 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2430 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2431 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2432 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2020-01-27 10:57:18.165538015 +0100
2435 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2437 +# This program is free software; you can redistribute it and/or modify
2438 +# it under the terms of the GNU General Public License as published by
2439 +# the Free Software Foundation; either version 2 of the License, or
2440 +# (at your option) any later version.
2442 +# This program is distributed in the hope that it will be useful,
2443 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2444 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2445 +# GNU General Public License for more details.
2447 +# You should have received a copy of the GNU General Public License
2448 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2450 +Show Whiteout Mode (shwh)
2451 +----------------------------------------------------------------------
2452 +Generally aufs hides the name of whiteouts. But in some cases, to show
2453 +them is very useful for users. For instance, creating a new middle layer
2454 +(branch) by merging existing layers.
2456 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2457 +When you have three branches,
2458 +- Bottom: 'system', squashfs (underlying base system), read-only
2459 +- Middle: 'mods', squashfs, read-only
2460 +- Top: 'overlay', ram (tmpfs), read-write
2462 +The top layer is loaded at boot time and saved at shutdown, to preserve
2463 +the changes made to the system during the session.
2464 +When larger changes have been made, or smaller changes have accumulated,
2465 +the size of the saved top layer data grows. At this point, it would be
2466 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2467 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2468 +restoring save and load speed.
2470 +This merging is simplified by the use of another aufs mount, of just the
2471 +two overlay branches using the 'shwh' option.
2472 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2473 + aufs /livesys/merge_union
2475 +A merged view of these two branches is then available at
2476 +/livesys/merge_union, and the new feature is that the whiteouts are
2478 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2479 +writing to all branches. Also the default mode for all branches is 'ro'.
2480 +It is now possible to save the combined contents of the two overlay
2481 +branches to a new squashfs, e.g.:
2482 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2484 +This new squashfs archive can be stored on the boot device and the
2485 +initramfs will use it to replace the old one at the next boot.
2486 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2487 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2488 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2020-01-27 10:57:18.165538015 +0100
2491 +# Copyright (C) 2010-2020 Junjiro R. Okajima
2493 +# This program is free software; you can redistribute it and/or modify
2494 +# it under the terms of the GNU General Public License as published by
2495 +# the Free Software Foundation; either version 2 of the License, or
2496 +# (at your option) any later version.
2498 +# This program is distributed in the hope that it will be useful,
2499 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2500 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2501 +# GNU General Public License for more details.
2503 +# You should have received a copy of the GNU General Public License
2504 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2506 +Dynamically customizable FS operations
2507 +----------------------------------------------------------------------
2508 +Generally FS operations (struct inode_operations, struct
2509 +address_space_operations, struct file_operations, etc.) are defined as
2510 +"static const", but it never means that FS have only one set of
2511 +operation. Some FS have multiple sets of them. For instance, ext2 has
2512 +three sets, one for XIP, for NOBH, and for normal.
2513 +Since aufs overrides and redirects these operations, sometimes aufs has
2514 +to change its behaviour according to the branch FS type. More importantly
2515 +VFS acts differently if a function (member in the struct) is set or
2516 +not. It means aufs should have several sets of operations and select one
2517 +among them according to the branch FS definition.
2519 +In order to solve this problem and not to affect the behaviour of VFS,
2520 +aufs defines these operations dynamically. For instance, aufs defines
2521 +dummy direct_IO function for struct address_space_operations, but it may
2522 +not be set to the address_space_operations actually. When the branch FS
2523 +doesn't have it, aufs doesn't set it to its address_space_operations
2524 +while the function definition itself is still alive. So the behaviour
2525 +itself will not change, and it will return an error when direct_IO is
2528 +The lifetime of these dynamically generated operation object is
2529 +maintained by aufs branch object. When the branch is removed from aufs,
2530 +the reference counter of the object is decremented. When it reaches
2531 +zero, the dynamically generated operation object will be freed.
2533 +This approach is designed to support AIO (io_submit), Direct I/O and
2535 +Currently this approach is applied to address_space_operations for
2536 +regular files only.
2537 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2538 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2539 +++ linux/Documentation/filesystems/aufs/README 2020-01-23 09:59:36.748660743 +0100
2542 +Aufs5 -- advanced multi layered unification filesystem version 5.x
2548 +----------------------------------------
2549 +In the early days, aufs was entirely re-designed and re-implemented
2550 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2551 +improvements and implementations, it became totally different from
2552 +Unionfs while keeping the basic features.
2553 +Later, Unionfs Version 2.x series began taking some of the same
2554 +approaches to aufs1's.
2555 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2556 +University and his team.
2558 +Aufs5 supports linux-v5.0 and later, If you want older kernel version
2560 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2561 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2562 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2563 + or aufs1 from CVS on SourceForge.
2565 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2566 + According to Christoph Hellwig, linux rejects all union-type
2567 + filesystems but UnionMount.
2568 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2570 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2571 + UnionMount, and he pointed out an issue around a directory mutex
2572 + lock and aufs addressed it. But it is still unsure whether aufs will
2573 + be merged (or any other union solution).
2574 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2578 +----------------------------------------
2579 +- unite several directories into a single virtual filesystem. The member
2580 + directory is called as a branch.
2581 +- you can specify the permission flags to the branch, which are 'readonly',
2582 + 'readwrite' and 'whiteout-able.'
2583 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2584 + readonly branch are modifiable logically.
2585 +- dynamic branch manipulation, add, del.
2588 +Also there are many enhancements in aufs, such as:
2589 +- test only the highest one for the directory permission (dirperm1)
2590 +- copyup on open (coo=)
2591 +- 'move' policy for copy-up between two writable branches, after
2592 + checking free space.
2594 +- readdir(3) in userspace.
2595 +- keep inode number by external inode number table
2596 +- keep the timestamps of file/dir in internal copyup operation
2597 +- seekable directory, supporting NFS readdir.
2598 +- whiteout is hardlinked in order to reduce the consumption of inodes
2600 +- do not copyup, nor create a whiteout when it is unnecessary
2601 +- revert a single systemcall when an error occurs in aufs
2602 +- remount interface instead of ioctl
2603 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2604 +- loopback mounted filesystem as a branch
2605 +- kernel thread for removing the dir who has a plenty of whiteouts
2606 +- support copyup sparse file (a file which has a 'hole' in it)
2607 +- default permission flags for branches
2608 +- selectable permission flags for ro branch, whether whiteout can
2611 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2612 +- support multiple writable branches, some policies to select one
2613 + among multiple writable branches.
2614 +- a new semantics for link(2) and rename(2) to support multiple
2615 + writable branches.
2616 +- no glibc changes are required.
2617 +- pseudo hardlink (hardlink over branches)
2618 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2619 + including NFS or remote filesystem branch.
2620 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2623 +Currently these features are dropped temporary from aufs5.
2624 +See design/08plan.txt in detail.
2625 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2627 +- statistics of aufs thread (/sys/fs/aufs/stat)
2629 +Features or just an idea in the future (see also design/*.txt),
2630 +- reorder the branch index without del/re-add.
2631 +- permanent xino files for NFSD
2632 +- an option for refreshing the opened files after add/del branches
2633 +- light version, without branch manipulation. (unnecessary?)
2634 +- copyup in userspace
2635 +- inotify in userspace
2640 +----------------------------------------
2641 +There are three GIT trees for aufs5, aufs5-linux.git,
2642 +aufs5-standalone.git, and aufs-util.git. Note that there is no "5" in
2644 +While the aufs-util is always necessary, you need either of aufs5-linux
2645 +or aufs5-standalone.
2647 +The aufs5-linux tree includes the whole linux mainline GIT tree,
2648 +git://git.kernel.org/.../torvalds/linux.git.
2649 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2650 +build aufs5 as an external kernel module.
2651 +Several extra patches are not included in this tree. Only
2652 +aufs5-standalone tree contains them. They are described in the later
2653 +section "Configuration and Compilation."
2655 +On the other hand, the aufs5-standalone tree has only aufs source files
2656 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2657 +But you need to apply all aufs patches manually.
2659 +You will find GIT branches whose name is in form of "aufs5.x" where "x"
2660 +represents the linux kernel version, "linux-5.x". For instance,
2661 +"aufs5.0" is for linux-5.0. For latest "linux-5.x-rcN", use
2662 +"aufs5.x-rcN" branch.
2665 +$ git clone --reference /your/linux/git/tree \
2666 + git://github.com/sfjro/aufs5-linux.git aufs5-linux.git
2667 +- if you don't have linux GIT tree, then remove "--reference ..."
2668 +$ cd aufs5-linux.git
2669 +$ git checkout origin/aufs5.0
2671 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2672 +leave the patch-work to GIT.
2673 +$ cd /your/linux/git/tree
2674 +$ git remote add aufs5 git://github.com/sfjro/aufs5-linux.git
2676 +$ git checkout -b my5.0 v5.0
2677 +$ (add your local change...)
2678 +$ git pull aufs5 aufs5.0
2679 +- now you have v5.0 + your_changes + aufs5.0 in you my5.0 branch.
2680 +- you may need to solve some conflicts between your_changes and
2681 + aufs5.0. in this case, git-rerere is recommended so that you can
2682 + solve the similar conflicts automatically when you upgrade to 5.1 or
2683 + later in the future.
2685 +o aufs5-standalone tree
2686 +$ git clone git://github.com/sfjro/aufs5-standalone.git aufs5-standalone.git
2687 +$ cd aufs5-standalone.git
2688 +$ git checkout origin/aufs5.0
2691 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2692 +- note that the public aufs-util.git is on SourceForge instead of
2695 +$ git checkout origin/aufs5.0
2697 +Note: The 5.x-rcN branch is to be used with `rc' kernel versions ONLY.
2698 +The minor version number, 'x' in '5.x', of aufs may not always
2699 +follow the minor version number of the kernel.
2700 +Because changes in the kernel that cause the use of a new
2701 +minor version number do not always require changes to aufs-util.
2703 +Since aufs-util has its own minor version number, you may not be
2704 +able to find a GIT branch in aufs-util for your kernel's
2705 +exact minor version number.
2706 +In this case, you should git-checkout the branch for the
2707 +nearest lower number.
2709 +For (an unreleased) example:
2710 +If you are using "linux-5.10" and the "aufs5.10" branch
2711 +does not exist in aufs-util repository, then "aufs5.9", "aufs5.8"
2712 +or something numerically smaller is the branch for your kernel.
2714 +Also you can view all branches by
2718 +3. Configuration and Compilation
2719 +----------------------------------------
2720 +Make sure you have git-checkout'ed the correct branch.
2722 +For aufs5-linux tree,
2723 +- enable CONFIG_AUFS_FS.
2724 +- set other aufs configurations if necessary.
2726 +For aufs5-standalone tree,
2727 +There are several ways to build.
2730 +- apply ./aufs5-kbuild.patch to your kernel source files.
2731 +- apply ./aufs5-base.patch too.
2732 +- apply ./aufs5-mmap.patch too.
2733 +- apply ./aufs5-standalone.patch too, if you have a plan to set
2734 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch.
2735 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2736 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2737 +- enable CONFIG_AUFS_FS, you can select either
2739 +- and build your kernel as usual.
2740 +- install the built kernel.
2741 +- install the header files too by "make headers_install" to the
2742 + directory where you specify. By default, it is $PWD/usr.
2743 + "make help" shows a brief note for headers_install.
2744 +- and reboot your system.
2747 +- module only (CONFIG_AUFS_FS=m).
2748 +- apply ./aufs5-base.patch to your kernel source files.
2749 +- apply ./aufs5-mmap.patch too.
2750 +- apply ./aufs5-standalone.patch too.
2751 +- build your kernel, don't forget "make headers_install", and reboot.
2752 +- edit ./config.mk and set other aufs configurations if necessary.
2753 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2754 + every aufs configurations.
2755 +- build the module by simple "make".
2756 +- you can specify ${KDIR} make variable which points to your kernel
2758 +- install the files
2759 + + run "make install" to install the aufs module, or copy the built
2760 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2761 + + run "make install_headers" (instead of headers_install) to install
2762 + the modified aufs header file (you can specify DESTDIR which is
2763 + available in aufs standalone version's Makefile only), or copy
2764 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2765 + you like manually. By default, the target directory is $PWD/usr.
2766 +- no need to apply aufs5-kbuild.patch, nor copying source files to your
2767 + kernel source tree.
2769 +Note: The header file aufs_type.h is necessary to build aufs-util
2770 + as well as "make headers_install" in the kernel source tree.
2771 + headers_install is subject to be forgotten, but it is essentially
2772 + necessary, not only for building aufs-util.
2773 + You may not meet problems without headers_install in some older
2777 +- read README in aufs-util, build and install it
2778 +- note that your distribution may contain an obsoleted version of
2779 + aufs_type.h in /usr/include/linux or something. When you build aufs
2780 + utilities, make sure that your compiler refers the correct aufs header
2781 + file which is built by "make headers_install."
2782 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2783 + then run "make install_ulib" too. And refer to the aufs manual in
2786 +There several other patches in aufs5-standalone.git. They are all
2787 +optional. When you meet some problems, they will help you.
2788 +- aufs5-loopback.patch
2789 + Supports a nested loopback mount in a branch-fs. This patch is
2790 + unnecessary until aufs produces a message like "you may want to try
2791 + another patch for loopback file".
2792 +- proc_mounts.patch
2793 + When there are many mountpoints and many mount(2)/umount(2) are
2794 + running, then /proc/mounts may not show the all mountpoints. This
2795 + patch makes /proc/mounts always show the full mountpoints list.
2796 + If you don't want to apply this patch and meet such problem, then you
2797 + need to increase the value of 'ProcMounts_Times' make-variable in
2798 + aufs-util.git as a second best solution.
2800 + Modifies a system global kernel internal function get_next_ino() in
2801 + order to stop assigning 0 for an inode-number. Not directly related to
2802 + aufs, but recommended generally.
2804 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2805 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2806 + duplication of inode number, which is important for backup tools and
2807 + other utilities. When you find aufs XINO files for tmpfs branch
2808 + growing too much, try this patch.
2809 +- lockdep-debug.patch
2810 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2811 + also a caller of VFS functions for branch filesystems, subclassing of
2812 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2813 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2814 + need to apply this debug patch to expand several constant values.
2815 + If you don't know what LOCKDEP is, then you don't have apply this
2820 +----------------------------------------
2821 +At first, make sure aufs-util are installed, and please read the aufs
2822 +manual, aufs.5 in aufs-util.git tree.
2826 +$ mkdir /tmp/rw /tmp/aufs
2827 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2829 +Here is another example. The result is equivalent.
2830 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2832 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2833 +# mount -o remount,append:${HOME} /tmp/aufs
2835 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2836 +you modify a file under /tmp/aufs, the one on your home directory is
2837 +not affected, instead the same named file will be newly created under
2838 +/tmp/rw. And all of your modification to a file will be applied to
2839 +the one under /tmp/rw. This is called the file based Copy on Write
2841 +Aufs mount options are described in aufs.5.
2842 +If you run chroot or something and make your aufs as a root directory,
2843 +then you need to customize the shutdown script. See the aufs manual in
2846 +Additionally, there are some sample usages of aufs which are a
2847 +diskless system with network booting, and LiveCD over NFS.
2848 +See sample dir in CVS tree on SourceForge.
2852 +----------------------------------------
2853 +When you have any problems or strange behaviour in aufs, please let me
2855 +- /proc/mounts (instead of the output of mount(8))
2856 +- /sys/module/aufs/*
2857 +- /sys/fs/aufs/* (if you have them)
2858 +- /debug/aufs/* (if you have them)
2859 +- linux kernel version
2860 + if your kernel is not plain, for example modified by distributor,
2861 + the url where i can download its source is necessary too.
2862 +- aufs version which was printed at loading the module or booting the
2863 + system, instead of the date you downloaded.
2864 +- configuration (define/undefine CONFIG_AUFS_xxx)
2865 +- kernel configuration or /proc/config.gz (if you have it)
2866 +- LSM (linux security module, if you are using)
2867 +- behaviour which you think to be incorrect
2868 +- actual operation, reproducible one is better
2869 +- mailto: aufs-users at lists.sourceforge.net
2871 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2872 +and Feature Requests) on SourceForge. Please join and write to
2876 +6. Acknowledgements
2877 +----------------------------------------
2878 +Thanks to everyone who have tried and are using aufs, whoever
2879 +have reported a bug or any feedback.
2881 +Especially donators:
2882 +Tomas Matejicek(slax.org) made a donation (much more than once).
2883 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2884 + scripts) is making "doubling" donations.
2885 + Unfortunately I cannot list all of the donators, but I really
2887 + It ends Aug 2010, but the ordinary donation URL is still available.
2888 + <http://sourceforge.net/donate/index.php?group_id=167503>
2889 +Dai Itasaka made a donation (2007/8).
2890 +Chuck Smith made a donation (2008/4, 10 and 12).
2891 +Henk Schoneveld made a donation (2008/9).
2892 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2893 +Francois Dupoux made a donation (2008/11).
2894 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2895 + aufs2 GIT tree (2009/2).
2896 +William Grant made a donation (2009/3).
2897 +Patrick Lane made a donation (2009/4).
2898 +The Mail Archive (mail-archive.com) made donations (2009/5).
2899 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2900 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2901 +Pavel Pronskiy made a donation (2011/2).
2902 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2903 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2904 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2906 +Sam Liddicott made a donation (2011/9).
2907 +Era Scarecrow made a donation (2013/4).
2908 +Bor Ratajc made a donation (2013/4).
2909 +Alessandro Gorreta made a donation (2013/4).
2910 +POIRETTE Marc made a donation (2013/4).
2911 +Alessandro Gorreta made a donation (2013/4).
2912 +lauri kasvandik made a donation (2013/5).
2913 +"pemasu from Finland" made a donation (2013/7).
2914 +The Parted Magic Project made a donation (2013/9 and 11).
2915 +Pavel Barta made a donation (2013/10).
2916 +Nikolay Pertsev made a donation (2014/5).
2917 +James B made a donation (2014/7 and 2015/7).
2918 +Stefano Di Biase made a donation (2014/8).
2919 +Daniel Epellei made a donation (2015/1).
2920 +OmegaPhil made a donation (2016/1, 2018/4).
2921 +Tomasz Szewczyk made a donation (2016/4).
2922 +James Burry made a donation (2016/12).
2923 +Carsten Rose made a donation (2018/9).
2924 +Porteus Kiosk made a donation (2018/10).
2926 +Thank you very much.
2927 +Donations are always, including future donations, very important and
2928 +helpful for me to keep on developing aufs.
2932 +----------------------------------------
2933 +If you are an experienced user, no explanation is needed. Aufs is
2934 +just a linux filesystem.
2939 +# Local variables: ;
2942 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2943 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2944 +++ linux/fs/aufs/aufs.h 2020-01-27 10:57:18.165538015 +0100
2946 +/* SPDX-License-Identifier: GPL-2.0 */
2948 + * Copyright (C) 2005-2020 Junjiro R. Okajima
2950 + * This program, aufs is free software; you can redistribute it and/or modify
2951 + * it under the terms of the GNU General Public License as published by
2952 + * the Free Software Foundation; either version 2 of the License, or
2953 + * (at your option) any later version.
2955 + * This program is distributed in the hope that it will be useful,
2956 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2957 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2958 + * GNU General Public License for more details.
2960 + * You should have received a copy of the GNU General Public License
2961 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2965 + * all header files
2973 +#define AuStub(type, name, body, ...) \
2974 + static inline type name(__VA_ARGS__) { body; }
2976 +#define AuStubVoid(name, ...) \
2977 + AuStub(void, name, , __VA_ARGS__)
2978 +#define AuStubInt0(name, ...) \
2979 + AuStub(int, name, return 0, __VA_ARGS__)
2983 +#include "branch.h"
2986 +#include "dbgaufs.h"
2987 +#include "dentry.h"
2989 +#include "dirren.h"
2992 +#include "fstype.h"
2997 +#include "module.h"
3001 +#include "sysaufs.h"
3006 +#endif /* __KERNEL__ */
3007 +#endif /* __AUFS_H__ */
3008 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
3009 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
3010 +++ linux/fs/aufs/branch.c 2020-08-03 09:14:46.095748745 +0200
3012 +// SPDX-License-Identifier: GPL-2.0
3014 + * Copyright (C) 2005-2020 Junjiro R. Okajima
3016 + * This program, aufs is free software; you can redistribute it and/or modify
3017 + * it under the terms of the GNU General Public License as published by
3018 + * the Free Software Foundation; either version 2 of the License, or
3019 + * (at your option) any later version.
3021 + * This program is distributed in the hope that it will be useful,
3022 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3023 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3024 + * GNU General Public License for more details.
3026 + * You should have received a copy of the GNU General Public License
3027 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3031 + * branch management
3034 +#include <linux/compat.h>
3035 +#include <linux/statfs.h>
3039 + * free a single branch
3041 +static void au_br_do_free(struct au_branch *br)
3044 + struct au_wbr *wbr;
3045 + struct au_dykey **key;
3047 + au_hnotify_fin_br(br);
3048 + /* always, regardless the mount option */
3049 + au_dr_hino_free(&br->br_dirren);
3052 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
3053 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
3054 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
3055 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
3059 + for (i = 0; i < AuBrWh_Last; i++)
3060 + dput(wbr->wbr_wh[i]);
3061 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
3062 + AuRwDestroy(&wbr->wbr_wh_rwsem);
3065 + if (br->br_fhsm) {
3066 + au_br_fhsm_fin(br->br_fhsm);
3067 + au_kfree_try_rcu(br->br_fhsm);
3070 + key = br->br_dykey;
3071 + for (i = 0; i < AuBrDynOp; i++, key++)
3077 + /* recursive lock, s_umount of branch's */
3078 + /* synchronize_rcu(); */ /* why? */
3080 + path_put(&br->br_path);
3082 + au_kfree_rcu(wbr);
3083 + au_lcnt_wait_for_fin(&br->br_nfiles);
3084 + au_lcnt_wait_for_fin(&br->br_count);
3085 + /* I don't know why, but percpu_refcount requires this */
3086 + /* synchronize_rcu(); */
3091 + * frees all branches
3093 +void au_br_free(struct au_sbinfo *sbinfo)
3095 + aufs_bindex_t bmax;
3096 + struct au_branch **br;
3098 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3100 + bmax = sbinfo->si_bbot + 1;
3101 + br = sbinfo->si_branch;
3103 + au_br_do_free(*br++);
3107 + * find the index of a branch which is specified by @br_id.
3109 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3111 + aufs_bindex_t bindex, bbot;
3113 + bbot = au_sbbot(sb);
3114 + for (bindex = 0; bindex <= bbot; bindex++)
3115 + if (au_sbr_id(sb, bindex) == br_id)
3120 +/* ---------------------------------------------------------------------- */
3126 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3127 + struct dentry *h_root)
3129 + if (unlikely(h_adding == h_root
3130 + || au_test_loopback_overlap(sb, h_adding)))
3132 + if (h_adding->d_sb != h_root->d_sb)
3134 + return au_test_subdir(h_adding, h_root)
3135 + || au_test_subdir(h_root, h_adding);
3139 + * returns a newly allocated branch. @new_nbranch is a number of branches
3140 + * after adding a branch.
3142 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3145 + struct au_branch *add_branch;
3146 + struct dentry *root;
3147 + struct inode *inode;
3151 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3152 + if (unlikely(!add_branch))
3154 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3155 + if (unlikely(!add_branch->br_xino))
3157 + err = au_hnotify_init_br(add_branch, perm);
3158 + if (unlikely(err))
3161 + if (au_br_writable(perm)) {
3162 + /* may be freed separately at changing the branch permission */
3163 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3165 + if (unlikely(!add_branch->br_wbr))
3169 + if (au_br_fhsm(perm)) {
3170 + err = au_fhsm_br_alloc(add_branch);
3171 + if (unlikely(err))
3175 + root = sb->s_root;
3176 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3178 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3180 + inode = d_inode(root);
3181 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3185 + return add_branch; /* success */
3188 + au_kfree_rcu(add_branch->br_wbr);
3190 + au_hnotify_fin_br(add_branch);
3192 + au_xino_put(add_branch);
3194 + au_kfree_rcu(add_branch);
3196 + return ERR_PTR(err);
3200 + * test if the branch permission is legal or not.
3202 +static int test_br(struct inode *inode, int brperm, char *path)
3206 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3211 + pr_err("write permission for readonly mount or inode, %s\n", path);
3219 + * 0: success, the caller will add it
3220 + * plus: success, it is already unified, the caller should ignore it
3223 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3226 + aufs_bindex_t bbot, bindex;
3227 + struct dentry *root, *h_dentry;
3228 + struct inode *inode, *h_inode;
3230 + root = sb->s_root;
3231 + bbot = au_sbbot(sb);
3232 + if (unlikely(bbot >= 0
3233 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3237 + pr_err("%s duplicated\n", add->pathname);
3242 + err = -ENOSPC; /* -E2BIG; */
3243 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3244 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3245 + pr_err("number of branches exceeded %s\n", add->pathname);
3250 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3251 + pr_err("bad index %d\n", add->bindex);
3255 + inode = d_inode(add->path.dentry);
3257 + if (unlikely(!inode->i_nlink)) {
3258 + pr_err("no existence %s\n", add->pathname);
3263 + if (unlikely(inode->i_sb == sb)) {
3264 + pr_err("%s must be outside\n", add->pathname);
3268 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3269 + pr_err("unsupported filesystem, %s (%s)\n",
3270 + add->pathname, au_sbtype(inode->i_sb));
3274 + if (unlikely(inode->i_sb->s_stack_depth)) {
3275 + pr_err("already stacked, %s (%s)\n",
3276 + add->pathname, au_sbtype(inode->i_sb));
3280 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3281 + if (unlikely(err))
3285 + return 0; /* success */
3288 + for (bindex = 0; bindex <= bbot; bindex++)
3289 + if (unlikely(test_overlap(sb, add->path.dentry,
3290 + au_h_dptr(root, bindex)))) {
3291 + pr_err("%s is overlapped\n", add->pathname);
3296 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3297 + h_dentry = au_h_dptr(root, 0);
3298 + h_inode = d_inode(h_dentry);
3299 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3300 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3301 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3302 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3304 + i_uid_read(inode), i_gid_read(inode),
3305 + (inode->i_mode & S_IALLUGO),
3306 + i_uid_read(h_inode), i_gid_read(h_inode),
3307 + (h_inode->i_mode & S_IALLUGO));
3315 + * initialize or clean the whiteouts for an adding branch
3317 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3320 + int err, old_perm;
3321 + aufs_bindex_t bindex;
3322 + struct inode *h_inode;
3323 + struct au_wbr *wbr;
3324 + struct au_hinode *hdir;
3325 + struct dentry *h_dentry;
3327 + err = vfsub_mnt_want_write(au_br_mnt(br));
3328 + if (unlikely(err))
3332 + old_perm = br->br_perm;
3333 + br->br_perm = new_perm;
3336 + bindex = au_br_index(sb, br->br_id);
3337 + if (0 <= bindex) {
3338 + hdir = au_hi(d_inode(sb->s_root), bindex);
3339 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3341 + h_dentry = au_br_dentry(br);
3342 + h_inode = d_inode(h_dentry);
3343 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3346 + err = au_wh_init(br, sb);
3348 + wbr_wh_write_lock(wbr);
3349 + err = au_wh_init(br, sb);
3350 + wbr_wh_write_unlock(wbr);
3353 + au_hn_inode_unlock(hdir);
3355 + inode_unlock(h_inode);
3356 + vfsub_mnt_drop_write(au_br_mnt(br));
3357 + br->br_perm = old_perm;
3359 + if (!err && wbr && !au_br_writable(new_perm)) {
3360 + au_kfree_rcu(wbr);
3361 + br->br_wbr = NULL;
3368 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3372 + struct kstatfs kst;
3373 + struct au_wbr *wbr;
3376 + au_rw_init(&wbr->wbr_wh_rwsem);
3377 + atomic_set(&wbr->wbr_wh_running, 0);
3380 + * a limit for rmdir/rename a dir
3381 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3383 + err = vfs_statfs(&br->br_path, &kst);
3384 + if (unlikely(err))
3387 + if (kst.f_namelen >= NAME_MAX)
3388 + err = au_br_init_wh(sb, br, perm);
3390 + pr_err("%pd(%s), unsupported namelen %ld\n",
3392 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3398 +/* initialize a new branch */
3399 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3400 + struct au_opt_add *add)
3403 + struct au_branch *brbase;
3405 + struct inode *h_inode;
3408 + br->br_perm = add->perm;
3409 + br->br_path = add->path; /* set first, path_get() later */
3410 + spin_lock_init(&br->br_dykey_lock);
3411 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3412 + au_lcnt_init(&br->br_count, /*release*/NULL);
3413 + br->br_id = au_new_br_id(sb);
3414 + AuDebugOn(br->br_id < 0);
3416 + /* always, regardless the given option */
3417 + err = au_dr_br_init(sb, br, &add->path);
3418 + if (unlikely(err))
3421 + if (au_br_writable(add->perm)) {
3422 + err = au_wbr_init(br, sb, add->perm);
3423 + if (unlikely(err))
3427 + if (au_opt_test(au_mntflags(sb), XINO)) {
3428 + brbase = au_sbr(sb, 0);
3429 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3431 + h_inode = d_inode(add->path.dentry);
3432 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3433 + if (unlikely(err)) {
3434 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3439 + sysaufs_br_init(br);
3440 + path_get(&br->br_path);
3441 + goto out; /* success */
3444 + memset(&br->br_path, 0, sizeof(br->br_path));
3449 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3450 + struct au_branch *br, aufs_bindex_t bbot,
3451 + aufs_bindex_t amount)
3453 + struct au_branch **brp;
3455 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3457 + brp = sbinfo->si_branch + bindex;
3458 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3460 + sbinfo->si_bbot++;
3461 + if (unlikely(bbot < 0))
3462 + sbinfo->si_bbot = 0;
3465 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3466 + aufs_bindex_t bbot, aufs_bindex_t amount)
3468 + struct au_hdentry *hdp;
3470 + AuRwMustWriteLock(&dinfo->di_rwsem);
3472 + hdp = au_hdentry(dinfo, bindex);
3473 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3474 + au_h_dentry_init(hdp);
3476 + if (unlikely(bbot < 0))
3477 + dinfo->di_btop = 0;
3480 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3481 + aufs_bindex_t bbot, aufs_bindex_t amount)
3483 + struct au_hinode *hip;
3485 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3487 + hip = au_hinode(iinfo, bindex);
3488 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3489 + au_hinode_init(hip);
3491 + if (unlikely(bbot < 0))
3492 + iinfo->ii_btop = 0;
3495 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3496 + aufs_bindex_t bindex)
3498 + struct dentry *root, *h_dentry;
3499 + struct inode *root_inode, *h_inode;
3500 + aufs_bindex_t bbot, amount;
3502 + root = sb->s_root;
3503 + root_inode = d_inode(root);
3504 + bbot = au_sbbot(sb);
3505 + amount = bbot + 1 - bindex;
3506 + h_dentry = au_br_dentry(br);
3507 + au_sbilist_lock();
3508 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3509 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3510 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3511 + au_set_h_dptr(root, bindex, dget(h_dentry));
3512 + h_inode = d_inode(h_dentry);
3513 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3514 + au_sbilist_unlock();
3517 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3520 + aufs_bindex_t bbot, add_bindex;
3521 + struct dentry *root, *h_dentry;
3522 + struct inode *root_inode;
3523 + struct au_branch *add_branch;
3525 + root = sb->s_root;
3526 + root_inode = d_inode(root);
3527 + IMustLock(root_inode);
3528 + IiMustWriteLock(root_inode);
3529 + err = test_add(sb, add, remount);
3530 + if (unlikely(err < 0))
3534 + goto out; /* success */
3537 + bbot = au_sbbot(sb);
3538 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3539 + err = PTR_ERR(add_branch);
3540 + if (IS_ERR(add_branch))
3543 + err = au_br_init(add_branch, sb, add);
3544 + if (unlikely(err)) {
3545 + au_br_do_free(add_branch);
3549 + add_bindex = add->bindex;
3550 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3551 + au_br_do_add(sb, add_branch, add_bindex);
3552 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3553 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3555 + h_dentry = add->path.dentry;
3556 + if (!add_bindex) {
3557 + au_cpup_attr_all(root_inode, /*force*/1);
3558 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3560 + au_add_nlink(root_inode, d_inode(h_dentry));
3566 +/* ---------------------------------------------------------------------- */
3568 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3569 + unsigned long long max __maybe_unused,
3572 + unsigned long long n;
3573 + struct file **p, *f;
3574 + struct hlist_bl_head *files;
3575 + struct hlist_bl_node *pos;
3576 + struct au_finfo *finfo;
3580 + files = &au_sbi(sb)->si_files;
3581 + hlist_bl_lock(files);
3582 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3583 + f = finfo->fi_file;
3585 + && !special_file(file_inode(f)->i_mode)) {
3589 + AuDebugOn(n > max);
3592 + hlist_bl_unlock(files);
3597 +static struct file **au_farray_alloc(struct super_block *sb,
3598 + unsigned long long *max)
3600 + struct au_sbinfo *sbi;
3603 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3604 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3607 +static void au_farray_free(struct file **a, unsigned long long max)
3609 + unsigned long long ull;
3611 + for (ull = 0; ull < max; ull++)
3617 +/* ---------------------------------------------------------------------- */
3623 +/* to show the line number, do not make it inlined function */
3624 +#define AuVerbose(do_info, fmt, ...) do { \
3626 + pr_info(fmt, ##__VA_ARGS__); \
3629 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3630 + aufs_bindex_t bbot)
3632 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3635 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3636 + aufs_bindex_t bbot)
3638 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3642 + * test if the branch is deletable or not.
3644 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3645 + unsigned int sigen, const unsigned int verbose)
3647 + int err, i, j, ndentry;
3648 + aufs_bindex_t btop, bbot;
3649 + struct au_dcsub_pages dpages;
3650 + struct au_dpage *dpage;
3653 + err = au_dpages_init(&dpages, GFP_NOFS);
3654 + if (unlikely(err))
3656 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3657 + if (unlikely(err))
3660 + for (i = 0; !err && i < dpages.ndpage; i++) {
3661 + dpage = dpages.dpages + i;
3662 + ndentry = dpage->ndentry;
3663 + for (j = 0; !err && j < ndentry; j++) {
3664 + d = dpage->dentries[j];
3665 + AuDebugOn(au_dcount(d) <= 0);
3666 + if (!au_digen_test(d, sigen)) {
3667 + di_read_lock_child(d, AuLock_IR);
3668 + if (unlikely(au_dbrange_test(d))) {
3669 + di_read_unlock(d, AuLock_IR);
3673 + di_write_lock_child(d);
3674 + if (unlikely(au_dbrange_test(d))) {
3675 + di_write_unlock(d);
3678 + err = au_reval_dpath(d, sigen);
3680 + di_downgrade_lock(d, AuLock_IR);
3682 + di_write_unlock(d);
3687 + /* AuDbgDentry(d); */
3688 + btop = au_dbtop(d);
3689 + bbot = au_dbbot(d);
3690 + if (btop <= bindex
3692 + && au_h_dptr(d, bindex)
3693 + && au_test_dbusy(d, btop, bbot)) {
3695 + AuVerbose(verbose, "busy %pd\n", d);
3698 + di_read_unlock(d, AuLock_IR);
3703 + au_dpages_free(&dpages);
3708 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3709 + unsigned int sigen, const unsigned int verbose)
3712 + unsigned long long max, ull;
3713 + struct inode *i, **array;
3714 + aufs_bindex_t btop, bbot;
3716 + array = au_iarray_alloc(sb, &max);
3717 + err = PTR_ERR(array);
3718 + if (IS_ERR(array))
3722 + AuDbg("b%d\n", bindex);
3723 + for (ull = 0; !err && ull < max; ull++) {
3727 + if (i->i_ino == AUFS_ROOT_INO)
3730 + /* AuDbgInode(i); */
3731 + if (au_iigen(i, NULL) == sigen)
3732 + ii_read_lock_child(i);
3734 + ii_write_lock_child(i);
3735 + err = au_refresh_hinode_self(i);
3738 + ii_downgrade_lock(i);
3740 + ii_write_unlock(i);
3745 + btop = au_ibtop(i);
3746 + bbot = au_ibbot(i);
3747 + if (btop <= bindex
3749 + && au_h_iptr(i, bindex)
3750 + && au_test_ibusy(i, btop, bbot)) {
3752 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3755 + ii_read_unlock(i);
3757 + au_iarray_free(array, max);
3763 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3764 + const unsigned int verbose)
3767 + unsigned int sigen;
3769 + sigen = au_sigen(root->d_sb);
3770 + DiMustNoWaiters(root);
3771 + IiMustNoWaiters(d_inode(root));
3772 + di_write_unlock(root);
3773 + err = test_dentry_busy(root, bindex, sigen, verbose);
3775 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3776 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3781 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3782 + struct file **to_free, int *idx)
3785 + unsigned char matched, root;
3786 + aufs_bindex_t bindex, bbot;
3787 + struct au_fidir *fidir;
3788 + struct au_hfile *hfile;
3791 + root = IS_ROOT(file->f_path.dentry);
3794 + to_free[*idx] = file;
3800 + fidir = au_fi(file)->fi_hdir;
3801 + AuDebugOn(!fidir);
3802 + bbot = au_fbbot_dir(file);
3803 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3804 + hfile = fidir->fd_hfile + bindex;
3805 + if (!hfile->hf_file)
3808 + if (hfile->hf_br->br_id == br_id) {
3820 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3821 + struct file **to_free, int opened)
3824 + unsigned long long ull, max;
3825 + aufs_bindex_t btop;
3826 + struct file *file, **array;
3827 + struct dentry *root;
3828 + struct au_hfile *hfile;
3830 + array = au_farray_alloc(sb, &max);
3831 + err = PTR_ERR(array);
3832 + if (IS_ERR(array))
3837 + root = sb->s_root;
3838 + di_write_unlock(root);
3839 + for (ull = 0; ull < max; ull++) {
3840 + file = array[ull];
3841 + if (unlikely(!file))
3844 + /* AuDbg("%pD\n", file); */
3845 + fi_read_lock(file);
3846 + btop = au_fbtop(file);
3847 + if (!d_is_dir(file->f_path.dentry)) {
3848 + hfile = &au_fi(file)->fi_htop;
3849 + if (hfile->hf_br->br_id == br_id)
3852 + err = test_dir_busy(file, br_id, to_free, &idx);
3853 + fi_read_unlock(file);
3854 + if (unlikely(err))
3857 + di_write_lock_child(root);
3858 + au_farray_free(array, max);
3859 + AuDebugOn(idx > opened);
3865 +static void br_del_file(struct file **to_free, unsigned long long opened,
3866 + aufs_bindex_t br_id)
3868 + unsigned long long ull;
3869 + aufs_bindex_t bindex, btop, bbot, bfound;
3870 + struct file *file;
3871 + struct au_fidir *fidir;
3872 + struct au_hfile *hfile;
3874 + for (ull = 0; ull < opened; ull++) {
3875 + file = to_free[ull];
3876 + if (unlikely(!file))
3879 + /* AuDbg("%pD\n", file); */
3880 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3882 + fidir = au_fi(file)->fi_hdir;
3883 + AuDebugOn(!fidir);
3884 + fi_write_lock(file);
3885 + btop = au_fbtop(file);
3886 + bbot = au_fbbot_dir(file);
3887 + for (bindex = btop; bindex <= bbot; bindex++) {
3888 + hfile = fidir->fd_hfile + bindex;
3889 + if (!hfile->hf_file)
3892 + if (hfile->hf_br->br_id == br_id) {
3897 + AuDebugOn(bfound < 0);
3898 + au_set_h_fptr(file, bfound, NULL);
3899 + if (bfound == btop) {
3900 + for (btop++; btop <= bbot; btop++)
3901 + if (au_hf_dir(file, btop)) {
3902 + au_set_fbtop(file, btop);
3906 + fi_write_unlock(file);
3910 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3911 + const aufs_bindex_t bindex,
3912 + const aufs_bindex_t bbot)
3914 + struct au_branch **brp, **p;
3916 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3918 + brp = sbinfo->si_branch + bindex;
3919 + if (bindex < bbot)
3920 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3921 + sbinfo->si_branch[0 + bbot] = NULL;
3922 + sbinfo->si_bbot--;
3924 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3927 + sbinfo->si_branch = p;
3928 + /* harmless error */
3931 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3932 + const aufs_bindex_t bbot)
3934 + struct au_hdentry *hdp, *p;
3936 + AuRwMustWriteLock(&dinfo->di_rwsem);
3938 + hdp = au_hdentry(dinfo, bindex);
3939 + if (bindex < bbot)
3940 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3941 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3944 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3947 + dinfo->di_hdentry = p;
3948 + /* harmless error */
3951 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3952 + const aufs_bindex_t bbot)
3954 + struct au_hinode *hip, *p;
3956 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3958 + hip = au_hinode(iinfo, bindex);
3959 + if (bindex < bbot)
3960 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3961 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3964 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3967 + iinfo->ii_hinode = p;
3968 + /* harmless error */
3971 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3972 + struct au_branch *br)
3974 + aufs_bindex_t bbot;
3975 + struct au_sbinfo *sbinfo;
3976 + struct dentry *root, *h_root;
3977 + struct inode *inode, *h_inode;
3978 + struct au_hinode *hinode;
3980 + SiMustWriteLock(sb);
3982 + root = sb->s_root;
3983 + inode = d_inode(root);
3984 + sbinfo = au_sbi(sb);
3985 + bbot = sbinfo->si_bbot;
3987 + h_root = au_h_dptr(root, bindex);
3988 + hinode = au_hi(inode, bindex);
3989 + h_inode = au_igrab(hinode->hi_inode);
3992 + au_sbilist_lock();
3993 + au_br_do_del_brp(sbinfo, bindex, bbot);
3994 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3995 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3996 + au_sbilist_unlock();
3998 + /* ignore an error */
3999 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
4003 + au_br_do_free(br);
4006 +static unsigned long long empty_cb(struct super_block *sb, void *array,
4007 + unsigned long long max, void *arg)
4012 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
4015 + unsigned long long opened;
4016 + unsigned int mnt_flags;
4017 + aufs_bindex_t bindex, bbot, br_id;
4018 + unsigned char do_wh, verbose;
4019 + struct au_branch *br;
4020 + struct au_wbr *wbr;
4021 + struct dentry *root;
4022 + struct file **to_free;
4027 + root = sb->s_root;
4028 + bindex = au_find_dbindex(root, del->h_path.dentry);
4031 + goto out; /* success */
4033 + pr_err("%s no such branch\n", del->pathname);
4036 + AuDbg("bindex b%d\n", bindex);
4039 + mnt_flags = au_mntflags(sb);
4040 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4041 + bbot = au_sbbot(sb);
4042 + if (unlikely(!bbot)) {
4043 + AuVerbose(verbose, "no more branches left\n");
4047 + br = au_sbr(sb, bindex);
4048 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
4049 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
4050 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
4054 + br_id = br->br_id;
4055 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
4056 + if (unlikely(opened)) {
4057 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
4058 + err = PTR_ERR(to_free);
4059 + if (IS_ERR(to_free))
4062 + err = test_file_busy(sb, br_id, to_free, opened);
4063 + if (unlikely(err)) {
4064 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
4070 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4072 + /* instead of WbrWhMustWriteLock(wbr) */
4073 + SiMustWriteLock(sb);
4074 + for (i = 0; i < AuBrWh_Last; i++) {
4075 + dput(wbr->wbr_wh[i]);
4076 + wbr->wbr_wh[i] = NULL;
4080 + err = test_children_busy(root, bindex, verbose);
4081 + if (unlikely(err)) {
4090 + * now we confirmed the branch is deletable.
4091 + * let's free the remaining opened dirs on the branch.
4093 + di_write_unlock(root);
4094 + br_del_file(to_free, opened, br_id);
4095 + di_write_lock_child(root);
4098 + sysaufs_brs_del(sb, bindex); /* remove successors */
4099 + dbgaufs_xino_del(br); /* remove one */
4100 + au_br_do_del(sb, bindex, br);
4101 + sysaufs_brs_add(sb, bindex); /* append successors */
4102 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4105 + au_cpup_attr_all(d_inode(root), /*force*/1);
4106 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4108 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4109 + if (au_opt_test(mnt_flags, PLINK))
4110 + au_plink_half_refresh(sb, br_id);
4112 + goto out; /* success */
4116 + rerr = au_br_init_wh(sb, br, br->br_perm);
4118 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4119 + del->pathname, rerr);
4122 + au_farray_free(to_free, opened);
4126 +/* ---------------------------------------------------------------------- */
4128 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4131 + aufs_bindex_t btop, bbot;
4132 + struct aufs_ibusy ibusy;
4133 + struct inode *inode, *h_inode;
4136 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4139 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4141 + /* VERIFY_WRITE */
4142 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4143 + if (unlikely(err)) {
4150 + si_read_lock(sb, AuLock_FLUSH);
4151 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4155 + ibusy.h_ino = 0; /* invalid */
4156 + inode = ilookup(sb, ibusy.ino);
4158 + || inode->i_ino == AUFS_ROOT_INO
4159 + || au_is_bad_inode(inode))
4162 + ii_read_lock_child(inode);
4163 + btop = au_ibtop(inode);
4164 + bbot = au_ibbot(inode);
4165 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4166 + h_inode = au_h_iptr(inode, ibusy.bindex);
4167 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4168 + ibusy.h_ino = h_inode->i_ino;
4170 + ii_read_unlock(inode);
4174 + si_read_unlock(sb);
4176 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4177 + if (unlikely(err)) {
4186 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4188 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4191 +#ifdef CONFIG_COMPAT
4192 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4194 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4198 +/* ---------------------------------------------------------------------- */
4201 + * change a branch permission
4204 +static void au_warn_ima(void)
4207 + /* since it doesn't support mark_files_ro() */
4208 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4212 +static int do_need_sigen_inc(int a, int b)
4214 + return au_br_whable(a) && !au_br_whable(b);
4217 +static int need_sigen_inc(int old, int new)
4219 + return do_need_sigen_inc(old, new)
4220 + || do_need_sigen_inc(new, old);
4223 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4226 + unsigned int mnt_flags;
4227 + unsigned long long ull, max;
4228 + aufs_bindex_t br_id;
4229 + unsigned char verbose, writer;
4230 + struct file *file, *hf, **array;
4231 + struct au_hfile *hfile;
4232 + struct inode *h_inode;
4234 + mnt_flags = au_mntflags(sb);
4235 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4237 + array = au_farray_alloc(sb, &max);
4238 + err = PTR_ERR(array);
4239 + if (IS_ERR(array))
4243 + br_id = au_sbr_id(sb, bindex);
4244 + for (ull = 0; ull < max; ull++) {
4245 + file = array[ull];
4246 + if (unlikely(!file))
4249 + /* AuDbg("%pD\n", file); */
4250 + fi_read_lock(file);
4251 + if (unlikely(au_test_mmapped(file))) {
4253 + AuVerbose(verbose, "mmapped %pD\n", file);
4255 + FiMustNoWaiters(file);
4256 + fi_read_unlock(file);
4260 + hfile = &au_fi(file)->fi_htop;
4261 + hf = hfile->hf_file;
4262 + if (!d_is_reg(file->f_path.dentry)
4263 + || !(file->f_mode & FMODE_WRITE)
4264 + || hfile->hf_br->br_id != br_id
4265 + || !(hf->f_mode & FMODE_WRITE))
4266 + array[ull] = NULL;
4272 + FiMustNoWaiters(file);
4273 + fi_read_unlock(file);
4281 + for (ull = 0; ull < max; ull++) {
4282 + file = array[ull];
4286 + /* todo: already flushed? */
4288 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4289 + * approach which resets f_mode and calls mnt_drop_write() and
4290 + * file_release_write() for each file, because the branch
4291 + * attribute in aufs world is totally different from the native
4294 + /* fi_read_lock(file); */
4295 + hfile = &au_fi(file)->fi_htop;
4296 + hf = hfile->hf_file;
4297 + /* fi_read_unlock(file); */
4298 + spin_lock(&hf->f_lock);
4299 + writer = !!(hf->f_mode & FMODE_WRITER);
4300 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4301 + spin_unlock(&hf->f_lock);
4303 + h_inode = file_inode(hf);
4304 + if (hf->f_mode & FMODE_READ)
4305 + i_readcount_inc(h_inode);
4306 + put_write_access(h_inode);
4307 + __mnt_drop_write(hf->f_path.mnt);
4312 + au_farray_free(array, max);
4318 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4322 + aufs_bindex_t bindex;
4323 + struct dentry *root;
4324 + struct au_branch *br;
4325 + struct au_br_fhsm *bf;
4327 + root = sb->s_root;
4328 + bindex = au_find_dbindex(root, mod->h_root);
4331 + return 0; /* success */
4333 + pr_err("%s no such branch\n", mod->path);
4336 + AuDbg("bindex b%d\n", bindex);
4338 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4339 + if (unlikely(err))
4342 + br = au_sbr(sb, bindex);
4343 + AuDebugOn(mod->h_root != au_br_dentry(br));
4344 + if (br->br_perm == mod->perm)
4345 + return 0; /* success */
4347 + /* pre-allocate for non-fhsm --> fhsm */
4349 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4350 + err = au_fhsm_br_alloc(br);
4351 + if (unlikely(err))
4354 + br->br_fhsm = NULL;
4357 + if (au_br_writable(br->br_perm)) {
4358 + /* remove whiteout base */
4359 + err = au_br_init_wh(sb, br, mod->perm);
4360 + if (unlikely(err))
4363 + if (!au_br_writable(mod->perm)) {
4364 + /* rw --> ro, file might be mmapped */
4365 + DiMustNoWaiters(root);
4366 + IiMustNoWaiters(d_inode(root));
4367 + di_write_unlock(root);
4368 + err = au_br_mod_files_ro(sb, bindex);
4369 + /* aufs_write_lock() calls ..._child() */
4370 + di_write_lock_child(root);
4372 + if (unlikely(err)) {
4374 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4377 + rerr = au_wbr_init(br, sb, br->br_perm);
4378 + if (unlikely(rerr)) {
4379 + AuIOErr("nested error %d (%d)\n",
4381 + br->br_perm = mod->perm;
4385 + } else if (au_br_writable(mod->perm)) {
4388 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4390 + err = au_wbr_init(br, sb, mod->perm);
4391 + if (unlikely(err)) {
4392 + au_kfree_rcu(br->br_wbr);
4393 + br->br_wbr = NULL;
4397 + if (unlikely(err))
4400 + if (au_br_fhsm(br->br_perm)) {
4401 + if (!au_br_fhsm(mod->perm)) {
4402 + /* fhsm --> non-fhsm */
4403 + au_br_fhsm_fin(br->br_fhsm);
4404 + au_kfree_rcu(br->br_fhsm);
4405 + br->br_fhsm = NULL;
4407 + } else if (au_br_fhsm(mod->perm))
4408 + /* non-fhsm --> fhsm */
4411 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4412 + br->br_perm = mod->perm;
4413 + goto out; /* success */
4416 + au_kfree_try_rcu(bf);
4422 +/* ---------------------------------------------------------------------- */
4424 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4427 + struct kstatfs kstfs;
4429 + err = vfs_statfs(&br->br_path, &kstfs);
4431 + stfs->f_blocks = kstfs.f_blocks;
4432 + stfs->f_bavail = kstfs.f_bavail;
4433 + stfs->f_files = kstfs.f_files;
4434 + stfs->f_ffree = kstfs.f_ffree;
4439 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4440 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4441 +++ linux/fs/aufs/branch.h 2020-01-27 10:57:18.165538015 +0100
4443 +/* SPDX-License-Identifier: GPL-2.0 */
4445 + * Copyright (C) 2005-2020 Junjiro R. Okajima
4447 + * This program, aufs is free software; you can redistribute it and/or modify
4448 + * it under the terms of the GNU General Public License as published by
4449 + * the Free Software Foundation; either version 2 of the License, or
4450 + * (at your option) any later version.
4452 + * This program is distributed in the hope that it will be useful,
4453 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4454 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4455 + * GNU General Public License for more details.
4457 + * You should have received a copy of the GNU General Public License
4458 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4462 + * branch filesystems and xino for them
4465 +#ifndef __AUFS_BRANCH_H__
4466 +#define __AUFS_BRANCH_H__
4470 +#include <linux/mount.h>
4471 +#include "dirren.h"
4477 +/* ---------------------------------------------------------------------- */
4481 + struct file **xi_file;
4482 + unsigned int xi_nfile;
4488 + /* reserved for future use */
4489 + /* unsigned long *bitmap; */
4490 + wait_queue_head_t wqh;
4493 + struct mutex xi_mtx; /* protects xi_file array */
4494 + struct hlist_bl_head xi_writing;
4496 + atomic_t xi_truncating;
4498 + struct kref xi_kref;
4501 +/* File-based Hierarchical Storage Management */
4502 +struct au_br_fhsm {
4503 +#ifdef CONFIG_AUFS_FHSM
4504 + struct mutex bf_lock;
4505 + unsigned long bf_jiffy;
4506 + struct aufs_stfs bf_stfs;
4511 +/* members for writable branch only */
4512 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4514 + struct au_rwsem wbr_wh_rwsem;
4515 + struct dentry *wbr_wh[AuBrWh_Last];
4516 + atomic_t wbr_wh_running;
4517 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4518 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4519 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4522 + unsigned long long wbr_bytes;
4525 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4526 +#define AuBrDynOp (AuDyLast * 4)
4528 +#ifdef CONFIG_AUFS_HFSNOTIFY
4529 +/* support for asynchronous destruction */
4530 +struct au_br_hfsnotify {
4531 + struct fsnotify_group *hfsn_group;
4535 +/* sysfs entries */
4536 +struct au_brsysfs {
4538 + struct attribute attr;
4547 +/* protected by superblock rwsem */
4549 + struct au_xino *br_xino;
4551 + aufs_bindex_t br_id;
4554 + struct path br_path;
4555 + spinlock_t br_dykey_lock;
4556 + struct au_dykey *br_dykey[AuBrDynOp];
4557 + au_lcnt_t br_nfiles; /* opened files */
4558 + au_lcnt_t br_count; /* in-use for other */
4560 + struct au_wbr *br_wbr;
4561 + struct au_br_fhsm *br_fhsm;
4563 +#ifdef CONFIG_AUFS_HFSNOTIFY
4564 + struct au_br_hfsnotify *br_hfsn;
4567 +#ifdef CONFIG_SYSFS
4568 + /* entries under sysfs per mount-point */
4569 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4572 +#ifdef CONFIG_DEBUG_FS
4573 + struct dentry *br_dbgaufs; /* xino */
4576 + struct au_dr_br br_dirren;
4579 +/* ---------------------------------------------------------------------- */
4581 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4583 + return br->br_path.mnt;
4586 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4588 + return br->br_path.dentry;
4591 +static inline struct super_block *au_br_sb(struct au_branch *br)
4593 + return au_br_mnt(br)->mnt_sb;
4596 +static inline int au_br_rdonly(struct au_branch *br)
4598 + return (sb_rdonly(au_br_sb(br))
4599 + || !au_br_writable(br->br_perm))
4603 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4605 +#ifdef CONFIG_AUFS_HNOTIFY
4606 + return !(brperm & AuBrPerm_RR);
4612 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4614 + int err, exec_flag;
4617 + exec_flag = oflag & __FMODE_EXEC;
4618 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4624 +static inline void au_xino_get(struct au_branch *br)
4626 + struct au_xino *xi;
4630 + kref_get(&xi->xi_kref);
4633 +static inline int au_xino_count(struct au_branch *br)
4636 + struct au_xino *xi;
4641 + v = kref_read(&xi->xi_kref);
4646 +/* ---------------------------------------------------------------------- */
4650 +void au_br_free(struct au_sbinfo *sinfo);
4651 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4653 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4655 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4656 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4657 +#ifdef CONFIG_COMPAT
4658 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4661 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4664 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4667 +static const loff_t au_loff_max = LLONG_MAX;
4669 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4670 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4672 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4673 + struct file *copy_src);
4675 + struct au_xino *xi; /* switch between xino and xigen */
4677 + struct path *base;
4678 + struct file *copy_src;
4680 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4682 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4684 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4686 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4688 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4689 + size_t size, loff_t *pos);
4691 +int au_xib_trunc(struct super_block *sb);
4692 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4694 +struct au_xino *au_xino_alloc(unsigned int nfile);
4695 +int au_xino_put(struct au_branch *br);
4696 +struct file *au_xino_file1(struct au_xino *xi);
4698 +struct au_opt_xino;
4699 +void au_xino_clr(struct super_block *sb);
4700 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4701 +struct file *au_xino_def(struct super_block *sb);
4702 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4703 + struct path *base);
4705 +ino_t au_xino_new_ino(struct super_block *sb);
4706 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4708 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4709 + ino_t h_ino, int idx);
4710 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4713 +int au_xino_path(struct seq_file *seq, struct file *file);
4715 +/* ---------------------------------------------------------------------- */
4717 +/* @idx is signed to accept -1 meaning the first file */
4718 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4720 + struct file *file;
4727 + if (idx < xi->xi_nfile)
4728 + file = xi->xi_file[idx];
4730 + file = au_xino_file1(xi);
4736 +/* ---------------------------------------------------------------------- */
4738 +/* Superblock to branch */
4740 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4742 + return au_sbr(sb, bindex)->br_id;
4746 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4748 + return au_br_mnt(au_sbr(sb, bindex));
4752 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4754 + return au_br_sb(au_sbr(sb, bindex));
4757 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4759 + return au_sbr(sb, bindex)->br_perm;
4762 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4764 + return au_br_whable(au_sbr_perm(sb, bindex));
4767 +/* ---------------------------------------------------------------------- */
4769 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4770 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4771 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4772 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4774 +#define wbr_wh_read_trylock_nested(wbr) \
4775 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4776 +#define wbr_wh_write_trylock_nested(wbr) \
4777 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4780 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4781 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4782 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4784 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4785 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4786 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4788 +/* ---------------------------------------------------------------------- */
4790 +#ifdef CONFIG_AUFS_FHSM
4791 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4793 + mutex_init(&brfhsm->bf_lock);
4794 + brfhsm->bf_jiffy = 0;
4795 + brfhsm->bf_readable = 0;
4798 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4800 + mutex_destroy(&brfhsm->bf_lock);
4803 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4804 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4807 +#endif /* __KERNEL__ */
4808 +#endif /* __AUFS_BRANCH_H__ */
4809 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4810 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4811 +++ linux/fs/aufs/conf.mk 2019-07-11 15:42:14.462237786 +0200
4813 +# SPDX-License-Identifier: GPL-2.0
4815 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4819 +AuConfStr += ${1}=${${1}}
4823 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4825 + HNOTIFY HFSNOTIFY \
4837 +$(foreach i, ${AuConfAll}, \
4838 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4840 +AuConfName = ${obj}/conf.str
4841 +${AuConfName}.tmp: FORCE
4842 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4843 +${AuConfName}: ${AuConfName}.tmp
4844 + @diff -q $< $@ > /dev/null 2>&1 || { \
4845 + echo ' GEN ' $@; \
4849 +clean-files += ${AuConfName} ${AuConfName}.tmp
4850 +${obj}/sysfs.o: ${AuConfName}
4852 +-include ${srctree}/${src}/conf_priv.mk
4853 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4854 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4855 +++ linux/fs/aufs/cpup.c 2020-01-27 10:57:18.165538015 +0100
4857 +// SPDX-License-Identifier: GPL-2.0
4859 + * Copyright (C) 2005-2020 Junjiro R. Okajima
4861 + * This program, aufs is free software; you can redistribute it and/or modify
4862 + * it under the terms of the GNU General Public License as published by
4863 + * the Free Software Foundation; either version 2 of the License, or
4864 + * (at your option) any later version.
4866 + * This program is distributed in the hope that it will be useful,
4867 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4868 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4869 + * GNU General Public License for more details.
4871 + * You should have received a copy of the GNU General Public License
4872 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4876 + * copy-up functions, see wbr_policy.c for copy-down
4879 +#include <linux/fs_stack.h>
4880 +#include <linux/mm.h>
4881 +#include <linux/task_work.h>
4884 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4886 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4887 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4889 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4891 + dst->i_flags |= iflags & ~mask;
4892 + if (au_test_fs_notime(dst->i_sb))
4893 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4896 +void au_cpup_attr_timesizes(struct inode *inode)
4898 + struct inode *h_inode;
4900 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4901 + fsstack_copy_attr_times(inode, h_inode);
4902 + fsstack_copy_inode_size(inode, h_inode);
4905 +void au_cpup_attr_nlink(struct inode *inode, int force)
4907 + struct inode *h_inode;
4908 + struct super_block *sb;
4909 + aufs_bindex_t bindex, bbot;
4912 + bindex = au_ibtop(inode);
4913 + h_inode = au_h_iptr(inode, bindex);
4915 + && !S_ISDIR(h_inode->i_mode)
4916 + && au_opt_test(au_mntflags(sb), PLINK)
4917 + && au_plink_test(inode))
4921 + * 0 can happen in revalidating.
4922 + * h_inode->i_mutex may not be held here, but it is harmless since once
4923 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4925 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4926 + * the incorrect link count.
4928 + set_nlink(inode, h_inode->i_nlink);
4931 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4932 + * it may includes whplink directory.
4934 + if (S_ISDIR(h_inode->i_mode)) {
4935 + bbot = au_ibbot(inode);
4936 + for (bindex++; bindex <= bbot; bindex++) {
4937 + h_inode = au_h_iptr(inode, bindex);
4939 + au_add_nlink(inode, h_inode);
4944 +void au_cpup_attr_changeable(struct inode *inode)
4946 + struct inode *h_inode;
4948 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4949 + inode->i_mode = h_inode->i_mode;
4950 + inode->i_uid = h_inode->i_uid;
4951 + inode->i_gid = h_inode->i_gid;
4952 + au_cpup_attr_timesizes(inode);
4953 + au_cpup_attr_flags(inode, h_inode->i_flags);
4956 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4958 + struct au_iinfo *iinfo = au_ii(inode);
4960 + IiMustWriteLock(inode);
4962 + iinfo->ii_higen = h_inode->i_generation;
4963 + iinfo->ii_hsb1 = h_inode->i_sb;
4966 +void au_cpup_attr_all(struct inode *inode, int force)
4968 + struct inode *h_inode;
4970 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4971 + au_cpup_attr_changeable(inode);
4972 + if (inode->i_nlink > 0)
4973 + au_cpup_attr_nlink(inode, force);
4974 + inode->i_rdev = h_inode->i_rdev;
4975 + inode->i_blkbits = h_inode->i_blkbits;
4976 + au_cpup_igen(inode, h_inode);
4979 +/* ---------------------------------------------------------------------- */
4981 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4983 +/* keep the timestamps of the parent dir when cpup */
4984 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4985 + struct path *h_path)
4987 + struct inode *h_inode;
4989 + dt->dt_dentry = dentry;
4990 + dt->dt_h_path = *h_path;
4991 + h_inode = d_inode(h_path->dentry);
4992 + dt->dt_atime = h_inode->i_atime;
4993 + dt->dt_mtime = h_inode->i_mtime;
4997 +void au_dtime_revert(struct au_dtime *dt)
4999 + struct iattr attr;
5002 + attr.ia_atime = dt->dt_atime;
5003 + attr.ia_mtime = dt->dt_mtime;
5004 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
5005 + | ATTR_ATIME | ATTR_ATIME_SET;
5007 + /* no delegation since this is a directory */
5008 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
5009 + if (unlikely(err))
5010 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
5013 +/* ---------------------------------------------------------------------- */
5015 +/* internal use only */
5016 +struct au_cpup_reg_attr {
5019 + unsigned int iflags; /* inode->i_flags */
5022 +static noinline_for_stack
5023 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
5024 + struct au_cpup_reg_attr *h_src_attr)
5026 + int err, sbits, icex;
5027 + unsigned int mnt_flags;
5028 + unsigned char verbose;
5030 + struct path h_path;
5031 + struct inode *h_isrc, *h_idst;
5032 + struct kstat *h_st;
5033 + struct au_branch *br;
5035 + h_path.dentry = au_h_dptr(dst, bindex);
5036 + h_idst = d_inode(h_path.dentry);
5037 + br = au_sbr(dst->d_sb, bindex);
5038 + h_path.mnt = au_br_mnt(br);
5039 + h_isrc = d_inode(h_src);
5040 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
5041 + | ATTR_ATIME | ATTR_MTIME
5042 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
5043 + if (h_src_attr && h_src_attr->valid) {
5044 + h_st = &h_src_attr->st;
5045 + ia.ia_uid = h_st->uid;
5046 + ia.ia_gid = h_st->gid;
5047 + ia.ia_atime = h_st->atime;
5048 + ia.ia_mtime = h_st->mtime;
5049 + if (h_idst->i_mode != h_st->mode
5050 + && !S_ISLNK(h_idst->i_mode)) {
5051 + ia.ia_valid |= ATTR_MODE;
5052 + ia.ia_mode = h_st->mode;
5054 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
5055 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
5057 + ia.ia_uid = h_isrc->i_uid;
5058 + ia.ia_gid = h_isrc->i_gid;
5059 + ia.ia_atime = h_isrc->i_atime;
5060 + ia.ia_mtime = h_isrc->i_mtime;
5061 + if (h_idst->i_mode != h_isrc->i_mode
5062 + && !S_ISLNK(h_idst->i_mode)) {
5063 + ia.ia_valid |= ATTR_MODE;
5064 + ia.ia_mode = h_isrc->i_mode;
5066 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5067 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5069 + /* no delegation since it is just created */
5070 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5072 + /* is this nfs only? */
5073 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5074 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5075 + ia.ia_mode = h_isrc->i_mode;
5076 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5079 + icex = br->br_perm & AuBrAttr_ICEX;
5081 + mnt_flags = au_mntflags(dst->d_sb);
5082 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5083 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5089 +/* ---------------------------------------------------------------------- */
5091 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5092 + char *buf, unsigned long blksize)
5095 + size_t sz, rbytes, wbytes;
5096 + unsigned char all_zero;
5098 + struct inode *h_inode;
5099 + /* reduce stack usage */
5102 + zp = page_address(ZERO_PAGE(0));
5103 + if (unlikely(!zp))
5104 + return -ENOMEM; /* possible? */
5109 + AuDbg("len %lld\n", len);
5111 + if (len < blksize)
5115 + /* todo: signal_pending? */
5116 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5117 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5120 + if (unlikely(err < 0))
5124 + if (len >= rbytes && rbytes == blksize)
5125 + all_zero = !memcmp(buf, zp, rbytes);
5132 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5134 + /* todo: signal_pending? */
5135 + if (unlikely(err == -EAGAIN || err == -EINTR))
5137 + if (unlikely(err < 0))
5142 + if (unlikely(err < 0))
5148 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5150 + if (unlikely(res < 0))
5157 + /* the last block may be a hole */
5158 + if (!err && all_zero) {
5159 + AuLabel(last hole);
5162 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5163 + /* nfs requires this step to make last hole */
5164 + /* is this only nfs? */
5166 + /* todo: signal_pending? */
5167 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5168 + } while (err == -EAGAIN || err == -EINTR);
5175 + ia->ia_size = dst->f_pos;
5176 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5177 + ia->ia_file = dst;
5178 + h_inode = file_inode(dst);
5179 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5180 + /* no delegation since it is just created */
5181 + err = vfsub_notify_change(&dst->f_path, ia,
5182 + /*delegated*/NULL);
5183 + inode_unlock(h_inode);
5190 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5193 + unsigned long blksize;
5194 + unsigned char do_kfree;
5196 + struct super_block *h_sb;
5199 + h_sb = file_inode(dst)->i_sb;
5200 + blksize = h_sb->s_blocksize;
5201 + if (!blksize || PAGE_SIZE < blksize)
5202 + blksize = PAGE_SIZE;
5203 + AuDbg("blksize %lu\n", blksize);
5204 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5206 + buf = kmalloc(blksize, GFP_NOFS);
5208 + buf = (void *)__get_free_page(GFP_NOFS);
5209 + if (unlikely(!buf))
5212 + if (len > (1 << 22))
5213 + AuDbg("copying a large file %lld\n", (long long)len);
5217 + err = au_do_copy_file(dst, src, len, buf, blksize);
5219 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5220 + au_kfree_do_rcu(buf);
5222 + free_page((unsigned long)buf);
5228 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5231 + struct super_block *h_src_sb;
5232 + struct inode *h_src_inode;
5234 + h_src_inode = file_inode(src);
5235 + h_src_sb = h_src_inode->i_sb;
5237 + /* XFS acquires inode_lock */
5238 + if (!au_test_xfs(h_src_sb))
5239 + err = au_copy_file(dst, src, len);
5241 + inode_unlock_shared(h_src_inode);
5242 + err = au_copy_file(dst, src, len);
5243 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5249 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5253 + struct super_block *h_src_sb;
5254 + struct inode *h_src_inode;
5256 + h_src_inode = file_inode(src);
5257 + h_src_sb = h_src_inode->i_sb;
5258 + if (h_src_sb != file_inode(dst)->i_sb
5259 + || !dst->f_op->remap_file_range) {
5260 + err = au_do_copy(dst, src, len);
5264 + if (!au_test_nfs(h_src_sb)) {
5265 + inode_unlock_shared(h_src_inode);
5266 + lo = vfsub_clone_file_range(src, dst, len);
5267 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5269 + lo = vfsub_clone_file_range(src, dst, len);
5272 + goto out; /* success */
5273 + } else if (lo >= 0)
5274 + /* todo: possible? */
5275 + /* paritially succeeded */
5276 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5277 + else if (lo != -EOPNOTSUPP) {
5278 + /* older XFS has a condition in cloning */
5283 + /* the backend fs on NFS may not support cloning */
5284 + err = au_do_copy(dst, src, len);
5292 + * to support a sparse file which is opened with O_APPEND,
5293 + * we need to close the file.
5295 +static int au_cp_regular(struct au_cp_generic *cpg)
5298 + enum { SRC, DST };
5300 + aufs_bindex_t bindex;
5301 + unsigned int flags;
5302 + struct dentry *dentry;
5304 + struct file *file;
5307 + .bindex = cpg->bsrc,
5308 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5311 + .bindex = cpg->bdst,
5312 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5313 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5316 + struct au_branch *br;
5317 + struct super_block *sb, *h_src_sb;
5318 + struct inode *h_src_inode;
5319 + struct task_struct *tsk = current;
5321 + /* bsrc branch can be ro/rw. */
5322 + sb = cpg->dentry->d_sb;
5324 + for (i = 0; i < 2; i++, f++) {
5325 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5326 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5327 + /*file*/NULL, f->force_wr);
5328 + if (IS_ERR(f->file)) {
5329 + err = PTR_ERR(f->file);
5337 + /* try stopping to update while we copyup */
5338 + h_src_inode = d_inode(file[SRC].dentry);
5339 + h_src_sb = h_src_inode->i_sb;
5340 + if (!au_test_nfs(h_src_sb))
5341 + IMustLock(h_src_inode);
5342 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5344 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5345 + if (tsk->flags & PF_KTHREAD)
5346 + __fput_sync(file[DST].file);
5348 + /* it happened actually */
5349 + fput(file[DST].file);
5352 + * we have to call both since we don't know which place the file
5356 + flush_delayed_fput();
5358 + br = au_sbr(sb, file[DST].bindex);
5359 + au_lcnt_dec(&br->br_nfiles);
5362 + fput(file[SRC].file);
5363 + br = au_sbr(sb, file[SRC].bindex);
5364 + au_lcnt_dec(&br->br_nfiles);
5369 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5370 + struct au_cpup_reg_attr *h_src_attr)
5374 + struct path h_path;
5375 + struct inode *h_src_inode, *h_dst_inode;
5378 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5379 + l = i_size_read(h_src_inode);
5380 + if (cpg->len == -1 || l < cpg->len)
5383 + /* try stopping to update while we are referencing */
5384 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5385 + au_pin_hdir_unlock(cpg->pin);
5387 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5388 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5389 + h_src_attr->iflags = h_src_inode->i_flags;
5390 + if (!au_test_nfs(h_src_inode->i_sb))
5391 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5393 + inode_unlock_shared(h_src_inode);
5394 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5395 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5397 + if (unlikely(err)) {
5398 + inode_unlock_shared(h_src_inode);
5401 + h_src_attr->valid = 1;
5402 + if (!au_test_nfs(h_src_inode->i_sb)) {
5403 + err = au_cp_regular(cpg);
5404 + inode_unlock_shared(h_src_inode);
5406 + inode_unlock_shared(h_src_inode);
5407 + err = au_cp_regular(cpg);
5409 + rerr = au_pin_hdir_relock(cpg->pin);
5413 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5414 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5415 + h_dst_inode = d_inode(h_path.dentry);
5416 + spin_lock(&h_dst_inode->i_lock);
5417 + h_dst_inode->i_state |= I_LINKABLE;
5418 + spin_unlock(&h_dst_inode->i_lock);
5425 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5426 + struct inode *h_dir)
5429 + mm_segment_t old_fs;
5436 + sym.k = (void *)__get_free_page(GFP_NOFS);
5437 + if (unlikely(!sym.k))
5440 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5441 + old_fs = get_fs();
5442 + set_fs(KERNEL_DS);
5443 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5448 + sym.k[symlen] = 0;
5449 + err = vfsub_symlink(h_dir, h_path, sym.k);
5451 + free_page((unsigned long)sym.k);
5458 + * regardless 'acl' option, reset all ACL.
5459 + * All ACL will be copied up later from the original entry on the lower branch.
5461 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5464 + struct dentry *h_dentry;
5465 + struct inode *h_inode;
5467 + h_dentry = h_path->dentry;
5468 + h_inode = d_inode(h_dentry);
5469 + /* forget_all_cached_acls(h_inode)); */
5470 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5472 + if (err == -EOPNOTSUPP)
5475 + err = vfsub_acl_chmod(h_inode, mode);
5481 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5482 + struct inode *h_dir, struct path *h_path)
5485 + struct inode *dir, *inode;
5487 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5489 + if (err == -EOPNOTSUPP)
5491 + if (unlikely(err))
5495 + * strange behaviour from the users view,
5496 + * particularly setattr case
5498 + dir = d_inode(dst_parent);
5499 + if (au_ibtop(dir) == cpg->bdst)
5500 + au_cpup_attr_nlink(dir, /*force*/1);
5501 + inode = d_inode(cpg->dentry);
5502 + au_cpup_attr_nlink(inode, /*force*/1);
5508 +static noinline_for_stack
5509 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5510 + struct au_cpup_reg_attr *h_src_attr)
5514 + unsigned int mnt_flags;
5515 + unsigned char isdir, isreg, force;
5516 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5517 + struct au_dtime dt;
5518 + struct path h_path;
5519 + struct dentry *h_src, *h_dst, *h_parent;
5520 + struct inode *h_inode, *h_dir;
5521 + struct super_block *sb;
5523 + /* bsrc branch can be ro/rw. */
5524 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5525 + h_inode = d_inode(h_src);
5526 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5528 + /* try stopping to be referenced while we are creating */
5529 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5530 + if (au_ftest_cpup(cpg->flags, RENAME))
5531 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5532 + AUFS_WH_PFX_LEN));
5533 + h_parent = h_dst->d_parent; /* dir inode is locked */
5534 + h_dir = d_inode(h_parent);
5536 + AuDebugOn(h_parent != h_dst->d_parent);
5538 + sb = cpg->dentry->d_sb;
5539 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5541 + h_path.dentry = h_parent;
5542 + au_dtime_store(&dt, dst_parent, &h_path);
5544 + h_path.dentry = h_dst;
5548 + mode = h_inode->i_mode;
5549 + switch (mode & S_IFMT) {
5552 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5554 + err = au_do_cpup_regular(cpg, h_src_attr);
5558 + err = vfsub_mkdir(h_dir, &h_path, mode);
5560 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5563 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5567 + AuDebugOn(!capable(CAP_MKNOD));
5571 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5574 + AuIOErr("Unknown inode type 0%o\n", mode);
5578 + err = au_reset_acl(h_dir, &h_path, mode);
5580 + mnt_flags = au_mntflags(sb);
5581 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5583 + && au_opt_test(mnt_flags, XINO)
5584 + && (h_inode->i_nlink == 1
5585 + || (h_inode->i_state & I_LINKABLE))
5586 + /* todo: unnecessary? */
5587 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5588 + && cpg->bdst < cpg->bsrc
5589 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5590 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5591 + /* ignore this error */
5596 + force = !!cpg->len;
5597 + if (cpg->len == -1)
5598 + force = !!i_size_read(h_inode);
5600 + au_fhsm_wrote(sb, cpg->bdst, force);
5604 + au_dtime_revert(&dt);
5608 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5611 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5612 + struct inode *h_dir;
5613 + aufs_bindex_t bdst;
5615 + dentry = cpg->dentry;
5617 + h_dentry = au_h_dptr(dentry, bdst);
5618 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5620 + au_set_h_dptr(dentry, bdst, NULL);
5621 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5623 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5624 + au_set_h_dptr(dentry, bdst, h_dentry);
5627 + parent = dget_parent(dentry);
5628 + h_parent = au_h_dptr(parent, bdst);
5630 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5631 + if (IS_ERR(h_path->dentry))
5632 + err = PTR_ERR(h_path->dentry);
5634 + if (unlikely(err))
5637 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5638 + h_dir = d_inode(h_parent);
5640 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5641 + /* no delegation since it is just created */
5642 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5644 + dput(h_path->dentry);
5651 + * copyup the @dentry from @bsrc to @bdst.
5652 + * the caller must set the both of lower dentries.
5653 + * @len is for truncating when it is -1 copyup the entire file.
5654 + * in link/rename cases, @dst_parent may be different from the real one.
5655 + * basic->bsrc can be larger than basic->bdst.
5656 + * aufs doesn't touch the credential so
5657 + * security_inode_copy_up{,_xattr}() are unnecessary.
5659 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5662 + aufs_bindex_t old_ibtop;
5663 + unsigned char isdir, plink;
5664 + struct dentry *h_src, *h_dst, *h_parent;
5665 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5666 + struct super_block *sb;
5667 + struct au_branch *br;
5668 + /* to reduce stack size */
5670 + struct au_dtime dt;
5671 + struct path h_path;
5672 + struct au_cpup_reg_attr h_src_attr;
5676 + a = kmalloc(sizeof(*a), GFP_NOFS);
5679 + a->h_src_attr.valid = 0;
5681 + sb = cpg->dentry->d_sb;
5682 + br = au_sbr(sb, cpg->bdst);
5683 + a->h_path.mnt = au_br_mnt(br);
5684 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5685 + h_parent = h_dst->d_parent; /* dir inode is locked */
5686 + h_dir = d_inode(h_parent);
5689 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5690 + inode = d_inode(cpg->dentry);
5693 + dst_parent = dget_parent(cpg->dentry);
5697 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5698 + dst_inode = au_h_iptr(inode, cpg->bdst);
5700 + if (unlikely(!plink)) {
5702 + AuIOErr("hi%lu(i%lu) exists on b%d "
5703 + "but plink is disabled\n",
5704 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5708 + if (dst_inode->i_nlink) {
5709 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5711 + h_src = au_plink_lkup(inode, cpg->bdst);
5712 + err = PTR_ERR(h_src);
5713 + if (IS_ERR(h_src))
5715 + if (unlikely(d_is_negative(h_src))) {
5717 + AuIOErr("i%lu exists on b%d "
5718 + "but not pseudo-linked\n",
5719 + inode->i_ino, cpg->bdst);
5725 + a->h_path.dentry = h_parent;
5726 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5729 + a->h_path.dentry = h_dst;
5731 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5732 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5733 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5735 + au_dtime_revert(&a->dt);
5736 + if (unlikely(err == -EWOULDBLOCK)) {
5737 + pr_warn("cannot retry for NFSv4 delegation"
5738 + " for an internal link\n");
5744 + /* todo: cpup_wh_file? */
5746 + au_update_ibrange(inode, /*do_put_zero*/1);
5749 + isdir = S_ISDIR(inode->i_mode);
5750 + old_ibtop = au_ibtop(inode);
5751 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5752 + if (unlikely(err))
5754 + dst_inode = d_inode(h_dst);
5755 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5756 + /* todo: necessary? */
5757 + /* au_pin_hdir_unlock(cpg->pin); */
5759 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5760 + if (unlikely(err)) {
5761 + /* todo: necessary? */
5762 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5763 + inode_unlock(dst_inode);
5767 + if (cpg->bdst < old_ibtop) {
5768 + if (S_ISREG(inode->i_mode)) {
5769 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5770 + if (unlikely(err)) {
5771 + /* ignore an error */
5772 + /* au_pin_hdir_relock(cpg->pin); */
5773 + inode_unlock(dst_inode);
5777 + au_set_ibtop(inode, cpg->bdst);
5779 + au_set_ibbot(inode, cpg->bdst);
5780 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5781 + au_hi_flags(inode, isdir));
5783 + /* todo: necessary? */
5784 + /* err = au_pin_hdir_relock(cpg->pin); */
5785 + inode_unlock(dst_inode);
5786 + if (unlikely(err))
5789 + src_inode = d_inode(h_src);
5791 + && (src_inode->i_nlink > 1
5792 + || src_inode->i_state & I_LINKABLE)
5794 + au_plink_append(inode, cpg->bdst, h_dst);
5796 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5797 + a->h_path.dentry = h_dst;
5798 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5801 + goto out_parent; /* success */
5805 + a->h_path.dentry = h_parent;
5806 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5807 + a->h_path.dentry = h_dst;
5809 + if (d_is_positive(h_dst)) {
5811 + /* no delegation since it is just created */
5812 + rerr = vfsub_unlink(h_dir, &a->h_path,
5813 + /*delegated*/NULL, /*force*/0);
5815 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5817 + au_dtime_revert(&a->dt);
5819 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5829 +#if 0 /* reserved */
5830 +struct au_cpup_single_args {
5832 + struct au_cp_generic *cpg;
5833 + struct dentry *dst_parent;
5836 +static void au_call_cpup_single(void *args)
5838 + struct au_cpup_single_args *a = args;
5840 + au_pin_hdir_acquire_nest(a->cpg->pin);
5841 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5842 + au_pin_hdir_release(a->cpg->pin);
5847 + * prevent SIGXFSZ in copy-up.
5848 + * testing CAP_MKNOD is for generic fs,
5849 + * but CAP_FSETID is for xfs only, currently.
5851 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5854 + struct super_block *sb;
5855 + struct inode *h_dir;
5858 + sb = au_pinned_parent(pin)->d_sb;
5859 + if (!au_wkq_test()
5860 + && (!au_sbi(sb)->si_plink_maint_pid
5861 + || au_plink_maint(sb, AuLock_NOPLM))) {
5862 + switch (mode & S_IFMT) {
5864 + /* no condition about RLIMIT_FSIZE and the file size */
5869 + do_sio = !capable(CAP_MKNOD);
5873 + do_sio = ((mode & (S_ISUID | S_ISGID))
5874 + && !capable(CAP_FSETID));
5875 + /* this workaround may be removed in the future */
5877 + h_dir = au_pinned_h_dir(pin);
5878 + do_sio = h_dir->i_mode & S_ISVTX;
5885 +#if 0 /* reserved */
5886 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5889 + struct dentry *h_dentry;
5891 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5892 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5893 + err = au_cpup_single(cpg, dst_parent);
5895 + struct au_cpup_single_args args = {
5898 + .dst_parent = dst_parent
5900 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5901 + if (unlikely(wkq_err))
5910 + * copyup the @dentry from the first active lower branch to @bdst,
5911 + * using au_cpup_single().
5913 +static int au_cpup_simple(struct au_cp_generic *cpg)
5916 + unsigned int flags_orig;
5917 + struct dentry *dentry;
5919 + AuDebugOn(cpg->bsrc < 0);
5921 + dentry = cpg->dentry;
5922 + DiMustWriteLock(dentry);
5924 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5926 + flags_orig = cpg->flags;
5927 + au_fset_cpup(cpg->flags, RENAME);
5928 + err = au_cpup_single(cpg, NULL);
5929 + cpg->flags = flags_orig;
5931 + return 0; /* success */
5934 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5935 + au_set_dbtop(dentry, cpg->bsrc);
5941 +struct au_cpup_simple_args {
5943 + struct au_cp_generic *cpg;
5946 +static void au_call_cpup_simple(void *args)
5948 + struct au_cpup_simple_args *a = args;
5950 + au_pin_hdir_acquire_nest(a->cpg->pin);
5951 + *a->errp = au_cpup_simple(a->cpg);
5952 + au_pin_hdir_release(a->cpg->pin);
5955 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5958 + struct dentry *dentry, *parent;
5959 + struct file *h_file;
5960 + struct inode *h_dir;
5962 + dentry = cpg->dentry;
5964 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5965 + AuDebugOn(cpg->bsrc < 0);
5966 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5967 + err = PTR_ERR(h_file);
5968 + if (IS_ERR(h_file))
5972 + parent = dget_parent(dentry);
5973 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5974 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5975 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5976 + err = au_cpup_simple(cpg);
5978 + struct au_cpup_simple_args args = {
5982 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5983 + if (unlikely(wkq_err))
5989 + au_h_open_post(dentry, cpg->bsrc, h_file);
5995 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5997 + aufs_bindex_t bsrc, bbot;
5998 + struct dentry *dentry, *h_dentry;
6000 + if (cpg->bsrc < 0) {
6001 + dentry = cpg->dentry;
6002 + bbot = au_dbbot(dentry);
6003 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
6004 + h_dentry = au_h_dptr(dentry, bsrc);
6006 + AuDebugOn(d_is_negative(h_dentry));
6010 + AuDebugOn(bsrc > bbot);
6013 + AuDebugOn(cpg->bsrc <= cpg->bdst);
6014 + return au_do_sio_cpup_simple(cpg);
6017 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
6019 + AuDebugOn(cpg->bdst <= cpg->bsrc);
6020 + return au_do_sio_cpup_simple(cpg);
6023 +/* ---------------------------------------------------------------------- */
6026 + * copyup the deleted file for writing.
6028 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
6029 + struct file *file)
6032 + unsigned int flags_orig;
6033 + aufs_bindex_t bsrc_orig;
6034 + struct au_dinfo *dinfo;
6036 + struct au_hdentry *hd;
6037 + struct dentry *h_dentry;
6040 + dinfo = au_di(cpg->dentry);
6041 + AuRwMustWriteLock(&dinfo->di_rwsem);
6043 + bsrc_orig = cpg->bsrc;
6044 + cpg->bsrc = dinfo->di_btop;
6045 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
6046 + hdst.h_dentry = hdst.hd->hd_dentry;
6047 + hdst.hd->hd_dentry = wh_dentry;
6048 + dinfo->di_btop = cpg->bdst;
6050 + hsrc.h_dentry = NULL;
6052 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
6053 + hsrc.h_dentry = hsrc.hd->hd_dentry;
6054 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
6056 + flags_orig = cpg->flags;
6057 + cpg->flags = !AuCpup_DTIME;
6058 + err = au_cpup_single(cpg, /*h_parent*/NULL);
6059 + cpg->flags = flags_orig;
6062 + err = au_reopen_nondir(file);
6063 + hsrc.hd->hd_dentry = hsrc.h_dentry;
6065 + hdst.hd->hd_dentry = hdst.h_dentry;
6066 + dinfo->di_btop = cpg->bsrc;
6067 + cpg->bsrc = bsrc_orig;
6072 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6075 + aufs_bindex_t bdst;
6076 + struct au_dtime dt;
6077 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6078 + struct au_branch *br;
6079 + struct path h_path;
6081 + dentry = cpg->dentry;
6083 + br = au_sbr(dentry->d_sb, bdst);
6084 + parent = dget_parent(dentry);
6085 + h_parent = au_h_dptr(parent, bdst);
6086 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6087 + err = PTR_ERR(wh_dentry);
6088 + if (IS_ERR(wh_dentry))
6091 + h_path.dentry = h_parent;
6092 + h_path.mnt = au_br_mnt(br);
6093 + au_dtime_store(&dt, parent, &h_path);
6094 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6095 + if (unlikely(err))
6099 + h_path.dentry = wh_dentry;
6100 + if (!d_is_dir(wh_dentry)) {
6101 + /* no delegation since it is just created */
6102 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6103 + /*delegated*/NULL, /*force*/0);
6105 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6106 + if (unlikely(err)) {
6107 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6111 + au_dtime_revert(&dt);
6112 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6121 +struct au_cpup_wh_args {
6123 + struct au_cp_generic *cpg;
6124 + struct file *file;
6127 +static void au_call_cpup_wh(void *args)
6129 + struct au_cpup_wh_args *a = args;
6131 + au_pin_hdir_acquire_nest(a->cpg->pin);
6132 + *a->errp = au_cpup_wh(a->cpg, a->file);
6133 + au_pin_hdir_release(a->cpg->pin);
6136 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6139 + aufs_bindex_t bdst;
6140 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6141 + struct inode *dir, *h_dir, *h_tmpdir;
6142 + struct au_wbr *wbr;
6143 + struct au_pin wh_pin, *pin_orig;
6145 + dentry = cpg->dentry;
6147 + parent = dget_parent(dentry);
6148 + dir = d_inode(parent);
6151 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6154 + if (!h_dir->i_nlink) {
6155 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6156 + h_orph = wbr->wbr_orph;
6158 + h_parent = dget(au_h_dptr(parent, bdst));
6159 + au_set_h_dptr(parent, bdst, dget(h_orph));
6160 + h_tmpdir = d_inode(h_orph);
6161 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6163 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6164 + /* todo: au_h_open_pre()? */
6166 + pin_orig = cpg->pin;
6167 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6168 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6169 + cpg->pin = &wh_pin;
6172 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6173 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6174 + err = au_cpup_wh(cpg, file);
6176 + struct au_cpup_wh_args args = {
6181 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6182 + if (unlikely(wkq_err))
6187 + inode_unlock(h_tmpdir);
6188 + /* todo: au_h_open_post()? */
6189 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6190 + au_set_h_dptr(parent, bdst, h_parent);
6191 + AuDebugOn(!pin_orig);
6192 + cpg->pin = pin_orig;
6200 +/* ---------------------------------------------------------------------- */
6203 + * generic routine for both of copy-up and copy-down.
6205 +/* cf. revalidate function in file.c */
6206 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6207 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6208 + struct au_pin *pin,
6209 + struct dentry *h_parent, void *arg),
6213 + struct au_pin pin;
6214 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6217 + parent = dget_parent(dentry);
6218 + if (IS_ROOT(parent))
6221 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6222 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6224 + /* do not use au_dpage */
6225 + real_parent = parent;
6228 + parent = dget_parent(dentry);
6229 + h_parent = au_h_dptr(parent, bdst);
6231 + goto out; /* success */
6233 + /* find top dir which is necessary to cpup */
6237 + parent = dget_parent(d);
6238 + di_read_lock_parent3(parent, !AuLock_IR);
6239 + h_parent = au_h_dptr(parent, bdst);
6240 + di_read_unlock(parent, !AuLock_IR);
6241 + } while (!h_parent);
6243 + if (d != real_parent)
6244 + di_write_lock_child3(d);
6246 + /* somebody else might create while we were sleeping */
6247 + h_dentry = au_h_dptr(d, bdst);
6248 + if (!h_dentry || d_is_negative(h_dentry)) {
6250 + au_update_dbtop(d);
6252 + au_pin_set_dentry(&pin, d);
6253 + err = au_do_pin(&pin);
6255 + err = cp(d, bdst, &pin, h_parent, arg);
6260 + if (d != real_parent)
6261 + di_write_unlock(d);
6262 + if (unlikely(err))
6271 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6272 + struct au_pin *pin,
6273 + struct dentry *h_parent __maybe_unused,
6274 + void *arg __maybe_unused)
6276 + struct au_cp_generic cpg = {
6282 + .flags = AuCpup_DTIME
6284 + return au_sio_cpup_simple(&cpg);
6287 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6289 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6292 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6295 + struct dentry *parent;
6296 + struct inode *dir;
6298 + parent = dget_parent(dentry);
6299 + dir = d_inode(parent);
6301 + if (au_h_iptr(dir, bdst))
6304 + di_read_unlock(parent, AuLock_IR);
6305 + di_write_lock_parent(parent);
6306 + /* someone else might change our inode while we were sleeping */
6307 + if (!au_h_iptr(dir, bdst))
6308 + err = au_cpup_dirs(dentry, bdst);
6309 + di_downgrade_lock(parent, AuLock_IR);
6315 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6316 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6317 +++ linux/fs/aufs/cpup.h 2020-01-27 10:57:18.168871450 +0100
6319 +/* SPDX-License-Identifier: GPL-2.0 */
6321 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6323 + * This program, aufs is free software; you can redistribute it and/or modify
6324 + * it under the terms of the GNU General Public License as published by
6325 + * the Free Software Foundation; either version 2 of the License, or
6326 + * (at your option) any later version.
6328 + * This program is distributed in the hope that it will be useful,
6329 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6330 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6331 + * GNU General Public License for more details.
6333 + * You should have received a copy of the GNU General Public License
6334 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6338 + * copy-up/down functions
6341 +#ifndef __AUFS_CPUP_H__
6342 +#define __AUFS_CPUP_H__
6346 +#include <linux/path.h>
6352 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6353 +void au_cpup_attr_timesizes(struct inode *inode);
6354 +void au_cpup_attr_nlink(struct inode *inode, int force);
6355 +void au_cpup_attr_changeable(struct inode *inode);
6356 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6357 +void au_cpup_attr_all(struct inode *inode, int force);
6359 +/* ---------------------------------------------------------------------- */
6361 +struct au_cp_generic {
6362 + struct dentry *dentry;
6363 + aufs_bindex_t bdst, bsrc;
6365 + struct au_pin *pin;
6366 + unsigned int flags;
6370 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6371 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6373 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6374 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6376 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6378 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6379 + the branch is marked as RO */
6381 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6382 +#undef AuCpup_HOPEN
6383 +#define AuCpup_HOPEN 0
6386 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6387 +#define au_fset_cpup(flags, name) \
6388 + do { (flags) |= AuCpup_##name; } while (0)
6389 +#define au_fclr_cpup(flags, name) \
6390 + do { (flags) &= ~AuCpup_##name; } while (0)
6392 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6393 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6394 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6395 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6397 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6398 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6399 + struct au_pin *pin,
6400 + struct dentry *h_parent, void *arg),
6402 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6403 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6405 +/* ---------------------------------------------------------------------- */
6407 +/* keep timestamps when copyup */
6409 + struct dentry *dt_dentry;
6410 + struct path dt_h_path;
6411 + struct timespec64 dt_atime, dt_mtime;
6413 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6414 + struct path *h_path);
6415 +void au_dtime_revert(struct au_dtime *dt);
6417 +#endif /* __KERNEL__ */
6418 +#endif /* __AUFS_CPUP_H__ */
6419 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6420 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6421 +++ linux/fs/aufs/dbgaufs.c 2020-01-27 10:57:18.168871450 +0100
6423 +// SPDX-License-Identifier: GPL-2.0
6425 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6427 + * This program, aufs is free software; you can redistribute it and/or modify
6428 + * it under the terms of the GNU General Public License as published by
6429 + * the Free Software Foundation; either version 2 of the License, or
6430 + * (at your option) any later version.
6432 + * This program is distributed in the hope that it will be useful,
6433 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6434 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6435 + * GNU General Public License for more details.
6437 + * You should have received a copy of the GNU General Public License
6438 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6442 + * debugfs interface
6445 +#include <linux/debugfs.h>
6448 +#ifndef CONFIG_SYSFS
6449 +#error DEBUG_FS depends upon SYSFS
6452 +static struct dentry *dbgaufs;
6453 +static const mode_t dbgaufs_mode = 0444;
6455 +/* 20 is max digits length of ulong 64 */
6456 +struct dbgaufs_arg {
6462 + * common function for all XINO files
6464 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6465 + struct file *file)
6469 + p = file->private_data;
6471 + /* this is struct dbgaufs_arg */
6472 + AuDebugOn(!au_kfree_sz_test(p));
6473 + au_kfree_do_rcu(p);
6478 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6483 + struct dbgaufs_arg *p;
6486 + p = kmalloc(sizeof(*p), GFP_NOFS);
6492 + file->private_data = p;
6496 + err = vfsub_getattr(&xf->f_path, &st);
6500 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6501 + cnt, st.blocks, st.blksize,
6502 + (long long)st.size);
6504 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6505 + st.blocks, st.blksize,
6506 + (long long)st.size);
6507 + AuDebugOn(p->n >= sizeof(p->a));
6509 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6517 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6518 + size_t count, loff_t *ppos)
6520 + struct dbgaufs_arg *p;
6522 + p = file->private_data;
6523 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6526 +/* ---------------------------------------------------------------------- */
6528 +struct dbgaufs_plink_arg {
6533 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6534 + struct file *file)
6536 + free_page((unsigned long)file->private_data);
6540 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6542 + int err, i, limit;
6543 + unsigned long n, sum;
6544 + struct dbgaufs_plink_arg *p;
6545 + struct au_sbinfo *sbinfo;
6546 + struct super_block *sb;
6547 + struct hlist_bl_head *hbl;
6550 + p = (void *)get_zeroed_page(GFP_NOFS);
6555 + sbinfo = inode->i_private;
6556 + sb = sbinfo->si_sb;
6557 + si_noflush_read_lock(sb);
6558 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6559 + limit = PAGE_SIZE - sizeof(p->n);
6561 + /* the number of buckets */
6562 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6567 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6569 + n = au_hbl_count(hbl);
6572 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6575 + if (unlikely(limit <= 0))
6578 + p->a[p->n - 1] = '\n';
6580 + /* the sum of plinks */
6581 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6584 + if (unlikely(limit <= 0))
6587 +#define str "1\n0\n0\n"
6588 + p->n = sizeof(str) - 1;
6589 + strcpy(p->a, str);
6592 + si_read_unlock(sb);
6595 + file->private_data = p;
6596 + goto out; /* success */
6599 + free_page((unsigned long)p);
6604 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6605 + size_t count, loff_t *ppos)
6607 + struct dbgaufs_plink_arg *p;
6609 + p = file->private_data;
6610 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6613 +static const struct file_operations dbgaufs_plink_fop = {
6614 + .owner = THIS_MODULE,
6615 + .open = dbgaufs_plink_open,
6616 + .release = dbgaufs_plink_release,
6617 + .read = dbgaufs_plink_read
6620 +/* ---------------------------------------------------------------------- */
6622 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6625 + struct au_sbinfo *sbinfo;
6626 + struct super_block *sb;
6628 + sbinfo = inode->i_private;
6629 + sb = sbinfo->si_sb;
6630 + si_noflush_read_lock(sb);
6631 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6632 + si_read_unlock(sb);
6636 +static const struct file_operations dbgaufs_xib_fop = {
6637 + .owner = THIS_MODULE,
6638 + .open = dbgaufs_xib_open,
6639 + .release = dbgaufs_xi_release,
6640 + .read = dbgaufs_xi_read
6643 +/* ---------------------------------------------------------------------- */
6645 +#define DbgaufsXi_PREFIX "xi"
6647 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6651 + aufs_bindex_t bindex;
6652 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6653 + struct au_sbinfo *sbinfo;
6654 + struct super_block *sb;
6655 + struct au_xino *xi;
6657 + struct qstr *name;
6658 + struct au_branch *br;
6661 + name = &file->f_path.dentry->d_name;
6662 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6663 + || memcmp(name->name, DbgaufsXi_PREFIX,
6664 + sizeof(DbgaufsXi_PREFIX) - 1)))
6667 + AuDebugOn(name->len >= sizeof(a));
6668 + memcpy(a, name->name, name->len);
6669 + a[name->len] = '\0';
6670 + p = strchr(a, '-');
6673 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6674 + if (unlikely(err))
6679 + err = kstrtol(p + 1, 10, &l);
6680 + if (unlikely(err))
6686 + sbinfo = inode->i_private;
6687 + sb = sbinfo->si_sb;
6688 + si_noflush_read_lock(sb);
6689 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6691 + br = au_sbr(sb, bindex);
6693 + if (unlikely(idx >= xi->xi_nfile))
6695 + xf = au_xino_file(xi, idx);
6697 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6698 + au_xino_count(br));
6701 + si_read_unlock(sb);
6707 +static const struct file_operations dbgaufs_xino_fop = {
6708 + .owner = THIS_MODULE,
6709 + .open = dbgaufs_xino_open,
6710 + .release = dbgaufs_xi_release,
6711 + .read = dbgaufs_xi_read
6714 +void dbgaufs_xino_del(struct au_branch *br)
6716 + struct dentry *dbgaufs;
6718 + dbgaufs = br->br_dbgaufs;
6722 + br->br_dbgaufs = NULL;
6723 + /* debugfs acquires the parent i_mutex */
6725 + debugfs_remove(dbgaufs);
6729 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6731 + aufs_bindex_t bbot;
6732 + struct au_branch *br;
6734 + if (!au_sbi(sb)->si_dbgaufs)
6737 + bbot = au_sbbot(sb);
6738 + for (; bindex <= bbot; bindex++) {
6739 + br = au_sbr(sb, bindex);
6740 + dbgaufs_xino_del(br);
6744 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6745 + unsigned int idx, struct dentry *parent,
6746 + struct au_sbinfo *sbinfo)
6748 + struct au_branch *br;
6750 + /* "xi" bindex(5) "-" idx(2) NULL */
6751 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6754 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6756 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6758 + br = au_sbr(sb, bindex);
6759 + if (br->br_dbgaufs) {
6760 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6762 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6763 + /* debugfs acquires the parent i_mutex */
6765 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6769 + pr_warn("failed renaming %pd/%s, ignored.\n",
6774 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6775 + sbinfo, &dbgaufs_xino_fop);
6777 + if (unlikely(!br->br_dbgaufs))
6778 + pr_warn("failed creating %pd/%s, ignored.\n",
6783 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6784 + struct dentry *parent, struct au_sbinfo *sbinfo)
6786 + struct au_branch *br;
6787 + struct au_xino *xi;
6790 + br = au_sbr(sb, bindex);
6792 + for (u = 0; u < xi->xi_nfile; u++)
6793 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6796 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6798 + struct au_sbinfo *sbinfo;
6799 + struct dentry *parent;
6800 + aufs_bindex_t bbot;
6802 + if (!au_opt_test(au_mntflags(sb), XINO))
6805 + sbinfo = au_sbi(sb);
6806 + parent = sbinfo->si_dbgaufs;
6810 + bbot = au_sbbot(sb);
6812 + for (; bindex <= bbot; bindex++)
6813 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6815 + for (; bbot >= bindex; bbot--)
6816 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6819 +/* ---------------------------------------------------------------------- */
6821 +#ifdef CONFIG_AUFS_EXPORT
6822 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6825 + struct au_sbinfo *sbinfo;
6826 + struct super_block *sb;
6828 + sbinfo = inode->i_private;
6829 + sb = sbinfo->si_sb;
6830 + si_noflush_read_lock(sb);
6831 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6832 + si_read_unlock(sb);
6836 +static const struct file_operations dbgaufs_xigen_fop = {
6837 + .owner = THIS_MODULE,
6838 + .open = dbgaufs_xigen_open,
6839 + .release = dbgaufs_xi_release,
6840 + .read = dbgaufs_xi_read
6843 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6848 + * This function is a dynamic '__init' function actually,
6849 + * so the tiny check for si_rwsem is unnecessary.
6851 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6854 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6855 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6856 + &dbgaufs_xigen_fop);
6857 + if (sbinfo->si_dbgaufs_xigen)
6863 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6867 +#endif /* CONFIG_AUFS_EXPORT */
6869 +/* ---------------------------------------------------------------------- */
6871 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6874 + * This function is a dynamic '__fin' function actually,
6875 + * so the tiny check for si_rwsem is unnecessary.
6877 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6879 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6880 + sbinfo->si_dbgaufs = NULL;
6883 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6886 + char name[SysaufsSiNameLen];
6889 + * This function is a dynamic '__init' function actually,
6890 + * so the tiny check for si_rwsem is unnecessary.
6892 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6896 + AuErr1("/debug/aufs is uninitialized\n");
6901 + sysaufs_name(sbinfo, name);
6902 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6903 + if (unlikely(!sbinfo->si_dbgaufs))
6906 + /* regardless plink/noplink option */
6907 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6908 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6909 + &dbgaufs_plink_fop);
6910 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6913 + /* regardless xino/noxino option */
6914 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6915 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6916 + &dbgaufs_xib_fop);
6917 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6920 + err = dbgaufs_xigen_init(sbinfo);
6922 + goto out; /* success */
6925 + dbgaufs_si_fin(sbinfo);
6927 + if (unlikely(err))
6928 + pr_err("debugfs/aufs failed\n");
6932 +/* ---------------------------------------------------------------------- */
6934 +void dbgaufs_fin(void)
6936 + debugfs_remove(dbgaufs);
6939 +int __init dbgaufs_init(void)
6944 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6949 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6950 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6951 +++ linux/fs/aufs/dbgaufs.h 2020-01-27 10:57:18.168871450 +0100
6953 +/* SPDX-License-Identifier: GPL-2.0 */
6955 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6957 + * This program, aufs is free software; you can redistribute it and/or modify
6958 + * it under the terms of the GNU General Public License as published by
6959 + * the Free Software Foundation; either version 2 of the License, or
6960 + * (at your option) any later version.
6962 + * This program is distributed in the hope that it will be useful,
6963 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6964 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6965 + * GNU General Public License for more details.
6967 + * You should have received a copy of the GNU General Public License
6968 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6972 + * debugfs interface
6975 +#ifndef __DBGAUFS_H__
6976 +#define __DBGAUFS_H__
6980 +struct super_block;
6984 +#ifdef CONFIG_DEBUG_FS
6986 +void dbgaufs_xino_del(struct au_branch *br);
6987 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6988 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6989 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6990 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6991 +void dbgaufs_fin(void);
6992 +int __init dbgaufs_init(void);
6994 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6995 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6996 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6998 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6999 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
7000 +AuStubVoid(dbgaufs_fin, void)
7001 +AuStubInt0(__init dbgaufs_init, void)
7002 +#endif /* CONFIG_DEBUG_FS */
7004 +#endif /* __KERNEL__ */
7005 +#endif /* __DBGAUFS_H__ */
7006 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
7007 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
7008 +++ linux/fs/aufs/dcsub.c 2020-01-27 10:57:18.168871450 +0100
7010 +// SPDX-License-Identifier: GPL-2.0
7012 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7014 + * This program, aufs is free software; you can redistribute it and/or modify
7015 + * it under the terms of the GNU General Public License as published by
7016 + * the Free Software Foundation; either version 2 of the License, or
7017 + * (at your option) any later version.
7019 + * This program is distributed in the hope that it will be useful,
7020 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7021 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7022 + * GNU General Public License for more details.
7024 + * You should have received a copy of the GNU General Public License
7025 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7029 + * sub-routines for dentry cache
7034 +static void au_dpage_free(struct au_dpage *dpage)
7037 + struct dentry **p;
7039 + p = dpage->dentries;
7040 + for (i = 0; i < dpage->ndentry; i++)
7042 + free_page((unsigned long)dpage->dentries);
7045 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
7051 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
7052 + if (unlikely(!dpages->dpages))
7055 + p = (void *)__get_free_page(gfp);
7059 + dpages->dpages[0].ndentry = 0;
7060 + dpages->dpages[0].dentries = p;
7061 + dpages->ndpage = 1;
7062 + return 0; /* success */
7065 + au_kfree_try_rcu(dpages->dpages);
7070 +void au_dpages_free(struct au_dcsub_pages *dpages)
7073 + struct au_dpage *p;
7075 + p = dpages->dpages;
7076 + for (i = 0; i < dpages->ndpage; i++)
7077 + au_dpage_free(p++);
7078 + au_kfree_try_rcu(dpages->dpages);
7081 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7082 + struct dentry *dentry, gfp_t gfp)
7085 + struct au_dpage *dpage;
7088 + dpage = dpages->dpages + dpages->ndpage - 1;
7089 + sz = PAGE_SIZE / sizeof(dentry);
7090 + if (unlikely(dpage->ndentry >= sz)) {
7091 + AuLabel(new dpage);
7093 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7094 + p = au_kzrealloc(dpages->dpages, sz,
7095 + sz + sizeof(*dpages->dpages), gfp,
7100 + dpages->dpages = p;
7101 + dpage = dpages->dpages + dpages->ndpage;
7102 + p = (void *)__get_free_page(gfp);
7106 + dpage->ndentry = 0;
7107 + dpage->dentries = p;
7111 + AuDebugOn(au_dcount(dentry) <= 0);
7112 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7113 + return 0; /* success */
7119 +/* todo: BAD approach */
7120 +/* copied from linux/fs/dcache.c */
7128 +extern void d_walk(struct dentry *parent, void *data,
7129 + enum d_walk_ret (*enter)(void *, struct dentry *));
7131 +struct ac_dpages_arg {
7133 + struct au_dcsub_pages *dpages;
7134 + struct super_block *sb;
7135 + au_dpages_test test;
7139 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7141 + enum d_walk_ret ret;
7142 + struct ac_dpages_arg *arg = _arg;
7144 + ret = D_WALK_CONTINUE;
7145 + if (dentry->d_sb == arg->sb
7146 + && !IS_ROOT(dentry)
7147 + && au_dcount(dentry) > 0
7149 + && (!arg->test || arg->test(dentry, arg->arg))) {
7150 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7151 + if (unlikely(arg->err))
7152 + ret = D_WALK_QUIT;
7158 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7159 + au_dpages_test test, void *arg)
7161 + struct ac_dpages_arg args = {
7169 + d_walk(root, &args, au_call_dpages_append);
7174 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7175 + int do_include, au_dpages_test test, void *arg)
7180 + write_seqlock(&rename_lock);
7181 + spin_lock(&dentry->d_lock);
7183 + && au_dcount(dentry) > 0
7184 + && (!test || test(dentry, arg)))
7185 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7186 + spin_unlock(&dentry->d_lock);
7187 + if (unlikely(err))
7191 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7194 + while (!IS_ROOT(dentry)) {
7195 + dentry = dentry->d_parent; /* rename_lock is locked */
7196 + spin_lock(&dentry->d_lock);
7197 + if (au_dcount(dentry) > 0
7198 + && (!test || test(dentry, arg)))
7199 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7200 + spin_unlock(&dentry->d_lock);
7201 + if (unlikely(err))
7206 + write_sequnlock(&rename_lock);
7210 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7212 + return au_di(dentry) && dentry->d_sb == arg;
7215 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7216 + struct dentry *dentry, int do_include)
7218 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7219 + au_dcsub_dpages_aufs, dentry->d_sb);
7222 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7224 + struct path path[2] = {
7233 + return path_is_under(path + 0, path + 1);
7235 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7236 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7237 +++ linux/fs/aufs/dcsub.h 2020-01-27 10:57:18.168871450 +0100
7239 +/* SPDX-License-Identifier: GPL-2.0 */
7241 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7243 + * This program, aufs is free software; you can redistribute it and/or modify
7244 + * it under the terms of the GNU General Public License as published by
7245 + * the Free Software Foundation; either version 2 of the License, or
7246 + * (at your option) any later version.
7248 + * This program is distributed in the hope that it will be useful,
7249 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7250 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7251 + * GNU General Public License for more details.
7253 + * You should have received a copy of the GNU General Public License
7254 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7258 + * sub-routines for dentry cache
7261 +#ifndef __AUFS_DCSUB_H__
7262 +#define __AUFS_DCSUB_H__
7266 +#include <linux/dcache.h>
7267 +#include <linux/fs.h>
7271 + struct dentry **dentries;
7274 +struct au_dcsub_pages {
7276 + struct au_dpage *dpages;
7279 +/* ---------------------------------------------------------------------- */
7282 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7283 +void au_dpages_free(struct au_dcsub_pages *dpages);
7284 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7285 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7286 + au_dpages_test test, void *arg);
7287 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7288 + int do_include, au_dpages_test test, void *arg);
7289 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7290 + struct dentry *dentry, int do_include);
7291 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7293 +/* ---------------------------------------------------------------------- */
7296 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7297 + * include/linux/dcache.h. Try them (in the future).
7300 +static inline int au_d_hashed_positive(struct dentry *d)
7303 + struct inode *inode = d_inode(d);
7306 + if (unlikely(d_unhashed(d)
7307 + || d_is_negative(d)
7308 + || !inode->i_nlink))
7313 +static inline int au_d_linkable(struct dentry *d)
7316 + struct inode *inode = d_inode(d);
7318 + err = au_d_hashed_positive(d);
7320 + && d_is_positive(d)
7321 + && (inode->i_state & I_LINKABLE))
7326 +static inline int au_d_alive(struct dentry *d)
7329 + struct inode *inode;
7333 + err = au_d_hashed_positive(d);
7335 + inode = d_inode(d);
7336 + if (unlikely(d_unlinked(d)
7337 + || d_is_negative(d)
7338 + || !inode->i_nlink))
7344 +static inline int au_alive_dir(struct dentry *d)
7348 + err = au_d_alive(d);
7349 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7354 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7356 + return a->len == b->len
7357 + && !memcmp(a->name, b->name, a->len);
7362 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7364 + * the type of d_lockref.count became int, but the inlined function d_count()
7365 + * still returns unsigned int.
7366 + * I don't know why. Maybe it is for every d_count() users?
7367 + * Anyway au_dcount() lives on.
7369 +static inline int au_dcount(struct dentry *d)
7371 + return (int)d_count(d);
7374 +#endif /* __KERNEL__ */
7375 +#endif /* __AUFS_DCSUB_H__ */
7376 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7377 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7378 +++ linux/fs/aufs/debug.c 2020-01-27 10:57:18.168871450 +0100
7380 +// SPDX-License-Identifier: GPL-2.0
7382 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7384 + * This program, aufs is free software; you can redistribute it and/or modify
7385 + * it under the terms of the GNU General Public License as published by
7386 + * the Free Software Foundation; either version 2 of the License, or
7387 + * (at your option) any later version.
7389 + * This program is distributed in the hope that it will be useful,
7390 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7391 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7392 + * GNU General Public License for more details.
7394 + * You should have received a copy of the GNU General Public License
7395 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7399 + * debug print functions
7402 +#include <linux/iversion.h>
7405 +/* Returns 0, or -errno. arg is in kp->arg. */
7406 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7410 + err = kstrtoint(val, 0, &n);
7420 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7421 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7426 + return sprintf(buffer, "%d", atomic_read(a));
7429 +static struct kernel_param_ops param_ops_atomic_t = {
7430 + .set = param_atomic_t_set,
7431 + .get = param_atomic_t_get
7432 + /* void (*free)(void *arg) */
7435 +atomic_t aufs_debug = ATOMIC_INIT(0);
7436 +MODULE_PARM_DESC(debug, "debug print");
7437 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7439 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7440 +char *au_plevel = KERN_DEBUG;
7441 +#define dpri(fmt, ...) do { \
7443 + && strcmp(au_plevel, KERN_DEBUG)) \
7444 + || au_debug_test()) \
7445 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7448 +/* ---------------------------------------------------------------------- */
7450 +void au_dpri_whlist(struct au_nhash *whlist)
7452 + unsigned long ul, n;
7453 + struct hlist_head *head;
7454 + struct au_vdir_wh *pos;
7456 + n = whlist->nh_num;
7457 + head = whlist->nh_head;
7458 + for (ul = 0; ul < n; ul++) {
7459 + hlist_for_each_entry(pos, head, wh_hash)
7460 + dpri("b%d, %.*s, %d\n",
7462 + pos->wh_str.len, pos->wh_str.name,
7468 +void au_dpri_vdir(struct au_vdir *vdir)
7471 + union au_vdir_deblk_p p;
7474 + if (!vdir || IS_ERR(vdir)) {
7475 + dpri("err %ld\n", PTR_ERR(vdir));
7479 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7480 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7481 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7482 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7483 + p.deblk = vdir->vd_deblk[ul];
7485 + dpri("[%lu]: %p\n", ul, o);
7489 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7490 + struct dentry *wh)
7495 + if (!inode || IS_ERR(inode)) {
7496 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7500 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7501 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7502 + && sizeof(inode->i_blocks) != sizeof(u64));
7504 + n = (void *)wh->d_name.name;
7505 + l = wh->d_name.len;
7508 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7509 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7511 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7512 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7513 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7514 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7515 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7516 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7517 + inode->i_generation,
7518 + l ? ", wh " : "", l, n);
7522 +void au_dpri_inode(struct inode *inode)
7524 + struct au_iinfo *iinfo;
7525 + struct au_hinode *hi;
7526 + aufs_bindex_t bindex;
7529 + err = do_pri_inode(-1, inode, -1, NULL);
7530 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7533 + iinfo = au_ii(inode);
7534 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7535 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7536 + if (iinfo->ii_btop < 0)
7539 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7540 + hi = au_hinode(iinfo, bindex);
7542 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7546 +void au_dpri_dalias(struct inode *inode)
7550 + spin_lock(&inode->i_lock);
7551 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7552 + au_dpri_dentry(d);
7553 + spin_unlock(&inode->i_lock);
7556 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7558 + struct dentry *wh = NULL;
7560 + struct inode *inode;
7561 + struct au_iinfo *iinfo;
7562 + struct au_hinode *hi;
7564 + if (!dentry || IS_ERR(dentry)) {
7565 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7568 + /* do not call dget_parent() here */
7569 + /* note: access d_xxx without d_lock */
7570 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7571 + bindex, dentry, dentry,
7572 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7573 + au_dcount(dentry), dentry->d_flags,
7574 + d_unhashed(dentry) ? "un" : "");
7577 + if (d_is_positive(dentry))
7578 + inode = d_inode(dentry);
7580 + && au_test_aufs(dentry->d_sb)
7582 + && !au_is_bad_inode(inode)) {
7583 + iinfo = au_ii(inode);
7584 + hi = au_hinode(iinfo, bindex);
7586 + wh = hi->hi_whdentry;
7588 + do_pri_inode(bindex, inode, hn, wh);
7592 +void au_dpri_dentry(struct dentry *dentry)
7594 + struct au_dinfo *dinfo;
7595 + aufs_bindex_t bindex;
7598 + err = do_pri_dentry(-1, dentry);
7599 + if (err || !au_test_aufs(dentry->d_sb))
7602 + dinfo = au_di(dentry);
7605 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7606 + dinfo->di_btop, dinfo->di_bbot,
7607 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7608 + dinfo->di_tmpfile);
7609 + if (dinfo->di_btop < 0)
7611 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7612 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7615 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7619 + if (!file || IS_ERR(file)) {
7620 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7625 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7626 + && au_test_aufs(file->f_path.dentry->d_sb)
7628 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7629 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7630 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7631 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7632 + file->f_version, file->f_pos, a);
7633 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7634 + do_pri_dentry(bindex, file->f_path.dentry);
7638 +void au_dpri_file(struct file *file)
7640 + struct au_finfo *finfo;
7641 + struct au_fidir *fidir;
7642 + struct au_hfile *hfile;
7643 + aufs_bindex_t bindex;
7646 + err = do_pri_file(-1, file);
7648 + || IS_ERR_OR_NULL(file->f_path.dentry)
7649 + || !au_test_aufs(file->f_path.dentry->d_sb))
7652 + finfo = au_fi(file);
7655 + if (finfo->fi_btop < 0)
7657 + fidir = finfo->fi_hdir;
7659 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7661 + for (bindex = finfo->fi_btop;
7662 + bindex >= 0 && bindex <= fidir->fd_bbot;
7664 + hfile = fidir->fd_hfile + bindex;
7665 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7669 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7671 + struct vfsmount *mnt;
7672 + struct super_block *sb;
7674 + if (!br || IS_ERR(br))
7676 + mnt = au_br_mnt(br);
7677 + if (!mnt || IS_ERR(mnt))
7680 + if (!sb || IS_ERR(sb))
7683 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7684 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7686 + bindex, br->br_perm, br->br_id, br->br_wbr,
7687 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7688 + sb->s_flags, sb->s_count,
7689 + atomic_read(&sb->s_active),
7690 + !!au_xino_file(br->br_xino, /*idx*/-1));
7694 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7698 +void au_dpri_sb(struct super_block *sb)
7700 + struct au_sbinfo *sbinfo;
7701 + aufs_bindex_t bindex;
7703 + /* to reduce stack size */
7705 + struct vfsmount mnt;
7706 + struct au_branch fake;
7709 + /* this function can be called from magic sysrq */
7710 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7711 + if (unlikely(!a)) {
7712 + dpri("no memory\n");
7716 + a->mnt.mnt_sb = sb;
7717 + a->fake.br_path.mnt = &a->mnt;
7718 + err = do_pri_br(-1, &a->fake);
7720 + dpri("dev 0x%x\n", sb->s_dev);
7721 + if (err || !au_test_aufs(sb))
7724 + sbinfo = au_sbi(sb);
7727 + dpri("nw %d, gen %u, kobj %d\n",
7728 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7729 + kref_read(&sbinfo->si_kobj.kref));
7730 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7731 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7734 +/* ---------------------------------------------------------------------- */
7736 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7738 + struct inode *h_inode, *inode = d_inode(dentry);
7739 + struct dentry *h_dentry;
7740 + aufs_bindex_t bindex, bbot, bi;
7742 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7745 + bbot = au_dbbot(dentry);
7746 + bi = au_ibbot(inode);
7749 + bindex = au_dbtop(dentry);
7750 + bi = au_ibtop(inode);
7754 + for (; bindex <= bbot; bindex++) {
7755 + h_dentry = au_h_dptr(dentry, bindex);
7758 + h_inode = au_h_iptr(inode, bindex);
7759 + if (unlikely(h_inode != d_inode(h_dentry))) {
7761 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7762 + AuDbgDentry(dentry);
7763 + AuDbgInode(inode);
7770 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7773 + struct au_dcsub_pages dpages;
7774 + struct au_dpage *dpage;
7775 + struct dentry **dentries;
7777 + err = au_dpages_init(&dpages, GFP_NOFS);
7779 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7781 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7782 + dpage = dpages.dpages + i;
7783 + dentries = dpage->dentries;
7784 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7785 + AuDebugOn(au_digen_test(dentries[j], sigen));
7787 + au_dpages_free(&dpages);
7790 +void au_dbg_verify_kthread(void)
7792 + if (au_wkq_test()) {
7795 + * It may be recursive, but udba=notify between two aufs mounts,
7796 + * where a single ro branch is shared, is not a problem.
7802 +/* ---------------------------------------------------------------------- */
7804 +int __init au_debug_init(void)
7806 + aufs_bindex_t bindex;
7807 + struct au_vdir_destr destr;
7810 + AuDebugOn(bindex >= 0);
7813 + AuDebugOn(destr.len < NAME_MAX);
7815 +#ifdef CONFIG_4KSTACKS
7816 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7821 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7822 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7823 +++ linux/fs/aufs/debug.h 2020-01-27 10:57:18.168871450 +0100
7825 +/* SPDX-License-Identifier: GPL-2.0 */
7827 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7829 + * This program, aufs is free software; you can redistribute it and/or modify
7830 + * it under the terms of the GNU General Public License as published by
7831 + * the Free Software Foundation; either version 2 of the License, or
7832 + * (at your option) any later version.
7834 + * This program is distributed in the hope that it will be useful,
7835 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7836 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7837 + * GNU General Public License for more details.
7839 + * You should have received a copy of the GNU General Public License
7840 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7844 + * debug print functions
7847 +#ifndef __AUFS_DEBUG_H__
7848 +#define __AUFS_DEBUG_H__
7852 +#include <linux/atomic.h>
7853 +#include <linux/module.h>
7854 +#include <linux/kallsyms.h>
7855 +#include <linux/sysrq.h>
7857 +#ifdef CONFIG_AUFS_DEBUG
7858 +#define AuDebugOn(a) BUG_ON(a)
7860 +/* module parameter */
7861 +extern atomic_t aufs_debug;
7862 +static inline void au_debug_on(void)
7864 + atomic_inc(&aufs_debug);
7866 +static inline void au_debug_off(void)
7868 + atomic_dec_if_positive(&aufs_debug);
7871 +static inline int au_debug_test(void)
7873 + return atomic_read(&aufs_debug) > 0;
7876 +#define AuDebugOn(a) do {} while (0)
7877 +AuStubVoid(au_debug_on, void)
7878 +AuStubVoid(au_debug_off, void)
7879 +AuStubInt0(au_debug_test, void)
7880 +#endif /* CONFIG_AUFS_DEBUG */
7882 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7884 +/* ---------------------------------------------------------------------- */
7888 +#define AuDbg(fmt, ...) do { \
7889 + if (au_debug_test()) \
7890 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7892 +#define AuLabel(l) AuDbg(#l "\n")
7893 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7894 +#define AuWarn1(fmt, ...) do { \
7895 + static unsigned char _c; \
7897 + pr_warn(fmt, ##__VA_ARGS__); \
7900 +#define AuErr1(fmt, ...) do { \
7901 + static unsigned char _c; \
7903 + pr_err(fmt, ##__VA_ARGS__); \
7906 +#define AuIOErr1(fmt, ...) do { \
7907 + static unsigned char _c; \
7909 + AuIOErr(fmt, ##__VA_ARGS__); \
7912 +#define AuUnsupportMsg "This operation is not supported." \
7913 + " Please report this application to aufs-users ML."
7914 +#define AuUnsupport(fmt, ...) do { \
7915 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7919 +#define AuTraceErr(e) do { \
7920 + if (unlikely((e) < 0)) \
7921 + AuDbg("err %d\n", (int)(e)); \
7924 +#define AuTraceErrPtr(p) do { \
7926 + AuDbg("err %ld\n", PTR_ERR(p)); \
7929 +/* dirty macros for debug print, use with "%.*s" and caution */
7930 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7932 +/* ---------------------------------------------------------------------- */
7935 +#ifdef CONFIG_AUFS_DEBUG
7936 +extern struct mutex au_dbg_mtx;
7937 +extern char *au_plevel;
7939 +void au_dpri_whlist(struct au_nhash *whlist);
7941 +void au_dpri_vdir(struct au_vdir *vdir);
7943 +void au_dpri_inode(struct inode *inode);
7944 +void au_dpri_dalias(struct inode *inode);
7945 +void au_dpri_dentry(struct dentry *dentry);
7947 +void au_dpri_file(struct file *filp);
7948 +struct super_block;
7949 +void au_dpri_sb(struct super_block *sb);
7951 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7952 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7953 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7954 +void au_dbg_verify_kthread(void);
7956 +int __init au_debug_init(void);
7958 +#define AuDbgWhlist(w) do { \
7959 + mutex_lock(&au_dbg_mtx); \
7961 + au_dpri_whlist(w); \
7962 + mutex_unlock(&au_dbg_mtx); \
7965 +#define AuDbgVdir(v) do { \
7966 + mutex_lock(&au_dbg_mtx); \
7968 + au_dpri_vdir(v); \
7969 + mutex_unlock(&au_dbg_mtx); \
7972 +#define AuDbgInode(i) do { \
7973 + mutex_lock(&au_dbg_mtx); \
7975 + au_dpri_inode(i); \
7976 + mutex_unlock(&au_dbg_mtx); \
7979 +#define AuDbgDAlias(i) do { \
7980 + mutex_lock(&au_dbg_mtx); \
7982 + au_dpri_dalias(i); \
7983 + mutex_unlock(&au_dbg_mtx); \
7986 +#define AuDbgDentry(d) do { \
7987 + mutex_lock(&au_dbg_mtx); \
7989 + au_dpri_dentry(d); \
7990 + mutex_unlock(&au_dbg_mtx); \
7993 +#define AuDbgFile(f) do { \
7994 + mutex_lock(&au_dbg_mtx); \
7996 + au_dpri_file(f); \
7997 + mutex_unlock(&au_dbg_mtx); \
8000 +#define AuDbgSb(sb) do { \
8001 + mutex_lock(&au_dbg_mtx); \
8002 + AuDbg(#sb "\n"); \
8004 + mutex_unlock(&au_dbg_mtx); \
8007 +#define AuDbgSym(addr) do { \
8008 + char sym[KSYM_SYMBOL_LEN]; \
8009 + sprint_symbol(sym, (unsigned long)addr); \
8010 + AuDbg("%s\n", sym); \
8013 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
8014 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
8015 +AuStubVoid(au_dbg_verify_kthread, void)
8016 +AuStubInt0(__init au_debug_init, void)
8018 +#define AuDbgWhlist(w) do {} while (0)
8019 +#define AuDbgVdir(v) do {} while (0)
8020 +#define AuDbgInode(i) do {} while (0)
8021 +#define AuDbgDAlias(i) do {} while (0)
8022 +#define AuDbgDentry(d) do {} while (0)
8023 +#define AuDbgFile(f) do {} while (0)
8024 +#define AuDbgSb(sb) do {} while (0)
8025 +#define AuDbgSym(addr) do {} while (0)
8026 +#endif /* CONFIG_AUFS_DEBUG */
8028 +/* ---------------------------------------------------------------------- */
8030 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
8031 +int __init au_sysrq_init(void);
8032 +void au_sysrq_fin(void);
8034 +#ifdef CONFIG_HW_CONSOLE
8035 +#define au_dbg_blocked() do { \
8037 + handle_sysrq('w'); \
8040 +AuStubVoid(au_dbg_blocked, void)
8044 +AuStubInt0(__init au_sysrq_init, void)
8045 +AuStubVoid(au_sysrq_fin, void)
8046 +AuStubVoid(au_dbg_blocked, void)
8047 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
8049 +#endif /* __KERNEL__ */
8050 +#endif /* __AUFS_DEBUG_H__ */
8051 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
8052 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
8053 +++ linux/fs/aufs/dentry.c 2020-01-27 10:57:18.168871450 +0100
8055 +// SPDX-License-Identifier: GPL-2.0
8057 + * Copyright (C) 2005-2020 Junjiro R. Okajima
8059 + * This program, aufs is free software; you can redistribute it and/or modify
8060 + * it under the terms of the GNU General Public License as published by
8061 + * the Free Software Foundation; either version 2 of the License, or
8062 + * (at your option) any later version.
8064 + * This program is distributed in the hope that it will be useful,
8065 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8066 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8067 + * GNU General Public License for more details.
8069 + * You should have received a copy of the GNU General Public License
8070 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8074 + * lookup and dentry operations
8077 +#include <linux/iversion.h>
8078 +#include <linux/namei.h>
8082 + * returns positive/negative dentry, NULL or an error.
8083 + * NULL means whiteout-ed or not-found.
8085 +static struct dentry*
8086 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8087 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8089 + struct dentry *h_dentry;
8090 + struct inode *h_inode;
8091 + struct au_branch *br;
8092 + int wh_found, opq;
8093 + unsigned char wh_able;
8094 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8095 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8099 + br = au_sbr(dentry->d_sb, bindex);
8100 + wh_able = !!au_br_whable(br->br_perm);
8102 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8103 + h_dentry = ERR_PTR(wh_found);
8106 + if (unlikely(wh_found < 0))
8109 + /* We found a whiteout */
8110 + /* au_set_dbbot(dentry, bindex); */
8111 + au_set_dbwh(dentry, bindex);
8113 + return NULL; /* success */
8117 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8119 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8120 + if (IS_ERR(h_dentry)) {
8121 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8127 + h_inode = d_inode(h_dentry);
8128 + if (d_is_negative(h_dentry)) {
8131 + } else if (wh_found
8132 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8134 + else if (au_ftest_lkup(args->flags, DIRREN)
8136 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8137 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8138 + (unsigned long long)h_inode->i_ino);
8142 + if (au_dbbot(dentry) <= bindex)
8143 + au_set_dbbot(dentry, bindex);
8144 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8145 + au_set_dbtop(dentry, bindex);
8146 + au_set_h_dptr(dentry, bindex, h_dentry);
8148 + if (!d_is_dir(h_dentry)
8150 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8151 + goto out; /* success */
8153 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8154 + opq = au_diropq_test(h_dentry);
8155 + inode_unlock_shared(h_inode);
8157 + au_set_dbdiropq(dentry, bindex);
8158 + else if (unlikely(opq < 0)) {
8159 + au_set_h_dptr(dentry, bindex, NULL);
8160 + h_dentry = ERR_PTR(opq);
8171 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8173 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8174 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8180 + * returns the number of lower positive dentries,
8181 + * otherwise an error.
8182 + * can be called at unlinking with @type is zero.
8184 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8185 + unsigned int flags)
8187 + int npositive, err;
8188 + aufs_bindex_t bindex, btail, bdiropq;
8189 + unsigned char isdir, dirperm1, dirren;
8190 + struct au_do_lookup_args args = {
8192 + .name = &dentry->d_name
8194 + struct dentry *parent;
8195 + struct super_block *sb;
8197 + sb = dentry->d_sb;
8198 + err = au_test_shwh(sb, args.name);
8199 + if (unlikely(err))
8202 + err = au_wh_name_alloc(&args.whname, args.name);
8203 + if (unlikely(err))
8206 + isdir = !!d_is_dir(dentry);
8207 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8208 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8210 + au_fset_lkup(args.flags, DIRREN);
8213 + parent = dget_parent(dentry);
8214 + btail = au_dbtaildir(parent);
8215 + for (bindex = btop; bindex <= btail; bindex++) {
8216 + struct dentry *h_parent, *h_dentry;
8217 + struct inode *h_inode, *h_dir;
8218 + struct au_branch *br;
8220 + h_dentry = au_h_dptr(dentry, bindex);
8222 + if (d_is_positive(h_dentry))
8226 + h_parent = au_h_dptr(parent, bindex);
8227 + if (!h_parent || !d_is_dir(h_parent))
8231 + /* if the inum matches, then use the prepared name */
8232 + err = au_dr_lkup_name(&args, bindex);
8233 + if (unlikely(err))
8237 + h_dir = d_inode(h_parent);
8238 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8239 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8240 + inode_unlock_shared(h_dir);
8241 + err = PTR_ERR(h_dentry);
8242 + if (IS_ERR(h_dentry))
8245 + au_fclr_lkup(args.flags, ALLOW_NEG);
8247 + au_fset_lkup(args.flags, IGNORE_PERM);
8249 + if (au_dbwh(dentry) == bindex)
8253 + if (d_is_negative(h_dentry))
8255 + h_inode = d_inode(h_dentry);
8258 + args.type = h_inode->i_mode & S_IFMT;
8259 + if (args.type != S_IFDIR)
8262 + /* the type of lower may be different */
8263 + bdiropq = au_dbdiropq(dentry);
8264 + if (bdiropq >= 0 && bdiropq <= bindex)
8267 + br = au_sbr(sb, bindex);
8269 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8270 + /*add_ent*/NULL)) {
8271 + /* prepare next name to lookup */
8272 + err = au_dr_lkup(&args, dentry, bindex);
8273 + if (unlikely(err))
8279 + AuLabel(positive);
8280 + au_update_dbtop(dentry);
8283 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8284 + && au_dbtop(dentry) < 0)) {
8286 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8292 + au_kfree_try_rcu(args.whname.name);
8294 + au_dr_lkup_fin(&args);
8299 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8301 + struct dentry *dentry;
8304 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8305 + dentry = vfsub_lkup_one(name, parent);
8307 + struct vfsub_lkup_one_args args = {
8313 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8314 + if (unlikely(wkq_err))
8315 + dentry = ERR_PTR(wkq_err);
8322 + * lookup @dentry on @bindex which should be negative.
8324 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8327 + struct dentry *parent, *h_parent, *h_dentry;
8328 + struct au_branch *br;
8330 + parent = dget_parent(dentry);
8331 + h_parent = au_h_dptr(parent, bindex);
8332 + br = au_sbr(dentry->d_sb, bindex);
8334 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8336 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8337 + err = PTR_ERR(h_dentry);
8338 + if (IS_ERR(h_dentry))
8340 + if (unlikely(d_is_positive(h_dentry))) {
8342 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8348 + if (bindex < au_dbtop(dentry))
8349 + au_set_dbtop(dentry, bindex);
8350 + if (au_dbbot(dentry) < bindex)
8351 + au_set_dbbot(dentry, bindex);
8352 + au_set_h_dptr(dentry, bindex, h_dentry);
8359 +/* ---------------------------------------------------------------------- */
8361 +/* subset of struct inode */
8363 + unsigned long i_ino;
8364 + /* unsigned int i_nlink; */
8370 + blkcnt_t i_blocks;
8375 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8377 + ia->i_ino = h_inode->i_ino;
8378 + /* ia->i_nlink = h_inode->i_nlink; */
8379 + ia->i_uid = h_inode->i_uid;
8380 + ia->i_gid = h_inode->i_gid;
8381 + ia->i_version = inode_query_iversion(h_inode);
8383 + ia->i_size = h_inode->i_size;
8384 + ia->i_blocks = h_inode->i_blocks;
8386 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8389 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8391 + return ia->i_ino != h_inode->i_ino
8392 + /* || ia->i_nlink != h_inode->i_nlink */
8393 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8394 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8395 + || !inode_eq_iversion(h_inode, ia->i_version)
8397 + || ia->i_size != h_inode->i_size
8398 + || ia->i_blocks != h_inode->i_blocks
8400 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8403 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8404 + struct au_branch *br)
8407 + struct au_iattr ia;
8408 + struct inode *h_inode;
8409 + struct dentry *h_d;
8410 + struct super_block *h_sb;
8413 + memset(&ia, -1, sizeof(ia));
8414 + h_sb = h_dentry->d_sb;
8416 + if (d_is_positive(h_dentry)) {
8417 + h_inode = d_inode(h_dentry);
8418 + au_iattr_save(&ia, h_inode);
8419 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8420 + /* nfs d_revalidate may return 0 for negative dentry */
8421 + /* fuse d_revalidate always return 0 for negative dentry */
8424 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8425 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8426 + err = PTR_ERR(h_d);
8431 + if (unlikely(h_d != h_dentry
8432 + || d_inode(h_d) != h_inode
8433 + || (h_inode && au_iattr_test(&ia, h_inode))))
8434 + err = au_busy_or_stale();
8442 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8443 + struct dentry *h_parent, struct au_branch *br)
8448 + if (udba == AuOpt_UDBA_REVAL
8449 + && !au_test_fs_remote(h_dentry->d_sb)) {
8451 + err = (d_inode(h_dentry->d_parent) != h_dir);
8452 + } else if (udba != AuOpt_UDBA_NONE)
8453 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8458 +/* ---------------------------------------------------------------------- */
8460 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8463 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8464 + struct au_hdentry tmp, *p, *q;
8465 + struct au_dinfo *dinfo;
8466 + struct super_block *sb;
8468 + DiMustWriteLock(dentry);
8470 + sb = dentry->d_sb;
8471 + dinfo = au_di(dentry);
8472 + bbot = dinfo->di_bbot;
8473 + bwh = dinfo->di_bwh;
8474 + bdiropq = dinfo->di_bdiropq;
8475 + bindex = dinfo->di_btop;
8476 + p = au_hdentry(dinfo, bindex);
8477 + for (; bindex <= bbot; bindex++, p++) {
8478 + if (!p->hd_dentry)
8481 + new_bindex = au_br_index(sb, p->hd_id);
8482 + if (new_bindex == bindex)
8485 + if (dinfo->di_bwh == bindex)
8487 + if (dinfo->di_bdiropq == bindex)
8488 + bdiropq = new_bindex;
8489 + if (new_bindex < 0) {
8491 + p->hd_dentry = NULL;
8495 + /* swap two lower dentries, and loop again */
8496 + q = au_hdentry(dinfo, new_bindex);
8500 + if (tmp.hd_dentry) {
8506 + dinfo->di_bwh = -1;
8507 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8508 + dinfo->di_bwh = bwh;
8510 + dinfo->di_bdiropq = -1;
8512 + && bdiropq <= au_sbbot(sb)
8513 + && au_sbr_whable(sb, bdiropq))
8514 + dinfo->di_bdiropq = bdiropq;
8517 + dinfo->di_btop = -1;
8518 + dinfo->di_bbot = -1;
8519 + bbot = au_dbbot(parent);
8521 + p = au_hdentry(dinfo, bindex);
8522 + for (; bindex <= bbot; bindex++, p++)
8523 + if (p->hd_dentry) {
8524 + dinfo->di_btop = bindex;
8528 + if (dinfo->di_btop >= 0) {
8530 + p = au_hdentry(dinfo, bindex);
8531 + for (; bindex >= 0; bindex--, p--)
8532 + if (p->hd_dentry) {
8533 + dinfo->di_bbot = bindex;
8542 +static void au_do_hide(struct dentry *dentry)
8544 + struct inode *inode;
8546 + if (d_really_is_positive(dentry)) {
8547 + inode = d_inode(dentry);
8548 + if (!d_is_dir(dentry)) {
8549 + if (inode->i_nlink && !d_unhashed(dentry))
8550 + drop_nlink(inode);
8552 + clear_nlink(inode);
8553 + /* stop next lookup */
8554 + inode->i_flags |= S_DEAD;
8556 + smp_mb(); /* necessary? */
8561 +static int au_hide_children(struct dentry *parent)
8563 + int err, i, j, ndentry;
8564 + struct au_dcsub_pages dpages;
8565 + struct au_dpage *dpage;
8566 + struct dentry *dentry;
8568 + err = au_dpages_init(&dpages, GFP_NOFS);
8569 + if (unlikely(err))
8571 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8572 + if (unlikely(err))
8575 + /* in reverse order */
8576 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8577 + dpage = dpages.dpages + i;
8578 + ndentry = dpage->ndentry;
8579 + for (j = ndentry - 1; j >= 0; j--) {
8580 + dentry = dpage->dentries[j];
8581 + if (dentry != parent)
8582 + au_do_hide(dentry);
8587 + au_dpages_free(&dpages);
8592 +static void au_hide(struct dentry *dentry)
8596 + AuDbgDentry(dentry);
8597 + if (d_is_dir(dentry)) {
8598 + /* shrink_dcache_parent(dentry); */
8599 + err = au_hide_children(dentry);
8600 + if (unlikely(err))
8601 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8604 + au_do_hide(dentry);
8608 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8610 + * a dirty branch is added
8611 + * - on the top of layers
8612 + * - in the middle of layers
8613 + * - to the bottom of layers
8615 + * on the added branch there exists
8618 + * - a same named entry
8620 + * * negative --> positive
8621 + * * positive --> positive
8622 + * - type is unchanged
8623 + * - type is changed
8625 + * * negative --> negative
8626 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8629 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8630 + struct au_dinfo *tmp)
8633 + aufs_bindex_t bindex, bbot;
8635 + struct dentry *dentry;
8636 + struct inode *inode;
8638 + } orig_h, tmp_h = {
8641 + struct au_hdentry *hd;
8642 + struct inode *inode, *h_inode;
8643 + struct dentry *h_dentry;
8646 + AuDebugOn(dinfo->di_btop < 0);
8648 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8649 + orig_h.inode = NULL;
8650 + if (d_is_positive(orig_h.dentry)) {
8651 + orig_h.inode = d_inode(orig_h.dentry);
8652 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8654 + if (tmp->di_btop >= 0) {
8655 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8656 + if (d_is_positive(tmp_h.dentry)) {
8657 + tmp_h.inode = d_inode(tmp_h.dentry);
8658 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8663 + if (d_really_is_positive(dentry))
8664 + inode = d_inode(dentry);
8665 + if (!orig_h.inode) {
8666 + AuDbg("negative originally\n");
8672 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8673 + AuDebugOn(dinfo->di_bdiropq != -1);
8675 + if (!tmp_h.inode) {
8676 + AuDbg("negative --> negative\n");
8677 + /* should have only one negative lower */
8678 + if (tmp->di_btop >= 0
8679 + && tmp->di_btop < dinfo->di_btop) {
8680 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8681 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8682 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8683 + au_di_cp(dinfo, tmp);
8684 + hd = au_hdentry(tmp, tmp->di_btop);
8685 + au_set_h_dptr(dentry, tmp->di_btop,
8686 + dget(hd->hd_dentry));
8688 + au_dbg_verify_dinode(dentry);
8690 + AuDbg("negative --> positive\n");
8692 + * similar to the behaviour of creating with bypassing
8694 + * unhash it in order to force an error in the
8695 + * succeeding create operation.
8696 + * we should not set S_DEAD here.
8699 + /* au_di_swap(tmp, dinfo); */
8700 + au_dbg_verify_dinode(dentry);
8703 + AuDbg("positive originally\n");
8704 + /* inode may be NULL */
8705 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8706 + if (!tmp_h.inode) {
8707 + AuDbg("positive --> negative\n");
8708 + /* or bypassing aufs */
8710 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8711 + dinfo->di_bwh = tmp->di_bwh;
8713 + err = au_refresh_hinode_self(inode);
8714 + au_dbg_verify_dinode(dentry);
8715 + } else if (orig_h.mode == tmp_h.mode) {
8716 + AuDbg("positive --> positive, same type\n");
8717 + if (!S_ISDIR(orig_h.mode)
8718 + && dinfo->di_btop > tmp->di_btop) {
8720 + * similar to the behaviour of removing and
8725 + err = au_refresh_hinode_self(inode);
8726 + au_dbg_verify_dinode(dentry);
8728 + /* fill empty slots */
8729 + if (dinfo->di_btop > tmp->di_btop)
8730 + dinfo->di_btop = tmp->di_btop;
8731 + if (dinfo->di_bbot < tmp->di_bbot)
8732 + dinfo->di_bbot = tmp->di_bbot;
8733 + dinfo->di_bwh = tmp->di_bwh;
8734 + dinfo->di_bdiropq = tmp->di_bdiropq;
8735 + bbot = dinfo->di_bbot;
8736 + bindex = tmp->di_btop;
8737 + hd = au_hdentry(tmp, bindex);
8738 + for (; bindex <= bbot; bindex++, hd++) {
8739 + if (au_h_dptr(dentry, bindex))
8741 + h_dentry = hd->hd_dentry;
8744 + AuDebugOn(d_is_negative(h_dentry));
8745 + h_inode = d_inode(h_dentry);
8746 + AuDebugOn(orig_h.mode
8747 + != (h_inode->i_mode
8749 + au_set_h_dptr(dentry, bindex,
8753 + err = au_refresh_hinode(inode, dentry);
8754 + au_dbg_verify_dinode(dentry);
8757 + AuDbg("positive --> positive, different type\n");
8758 + /* similar to the behaviour of removing and creating */
8761 + err = au_refresh_hinode_self(inode);
8762 + au_dbg_verify_dinode(dentry);
8770 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8772 + const struct dentry_operations *dop
8773 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8774 + static const unsigned int mask
8775 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8777 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8779 + if (dentry->d_op == dop)
8782 + AuDbg("%pd\n", dentry);
8783 + spin_lock(&dentry->d_lock);
8784 + if (dop == &aufs_dop)
8785 + dentry->d_flags |= mask;
8787 + dentry->d_flags &= ~mask;
8788 + dentry->d_op = dop;
8789 + spin_unlock(&dentry->d_lock);
8792 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8794 + int err, ebrange, nbr;
8795 + unsigned int sigen;
8796 + struct au_dinfo *dinfo, *tmp;
8797 + struct super_block *sb;
8798 + struct inode *inode;
8800 + DiMustWriteLock(dentry);
8801 + AuDebugOn(IS_ROOT(dentry));
8802 + AuDebugOn(d_really_is_negative(parent));
8804 + sb = dentry->d_sb;
8805 + sigen = au_sigen(sb);
8806 + err = au_digen_test(parent, sigen);
8807 + if (unlikely(err))
8810 + nbr = au_sbbot(sb) + 1;
8811 + dinfo = au_di(dentry);
8812 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8813 + if (unlikely(err))
8815 + ebrange = au_dbrange_test(dentry);
8817 + ebrange = au_do_refresh_hdentry(dentry, parent);
8819 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8820 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8821 + if (d_really_is_positive(dentry)) {
8822 + inode = d_inode(dentry);
8823 + err = au_refresh_hinode_self(inode);
8825 + au_dbg_verify_dinode(dentry);
8827 + goto out_dgen; /* success */
8831 + /* temporary dinfo */
8832 + AuDbgDentry(dentry);
8834 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8835 + if (unlikely(!tmp))
8837 + au_di_swap(tmp, dinfo);
8838 + /* returns the number of positive dentries */
8840 + * if current working dir is removed, it returns an error.
8841 + * but the dentry is legal.
8843 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8844 + AuDbgDentry(dentry);
8845 + au_di_swap(tmp, dinfo);
8846 + if (err == -ENOENT)
8849 + /* compare/refresh by dinfo */
8850 + AuDbgDentry(dentry);
8851 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8852 + au_dbg_verify_dinode(dentry);
8855 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8856 + au_rw_write_unlock(&tmp->di_rwsem);
8858 + if (unlikely(err))
8862 + au_update_digen(dentry);
8864 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8865 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8866 + AuDbgDentry(dentry);
8872 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8873 + struct dentry *dentry, aufs_bindex_t bindex)
8878 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8881 + AuDbg("b%d\n", bindex);
8883 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8884 + * due to whiteout and branch permission.
8886 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8887 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8888 + /* it may return tri-state */
8889 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8891 + if (unlikely(valid < 0))
8901 +/* todo: remove this */
8902 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8903 + unsigned int flags, int do_udba, int dirren)
8906 + umode_t mode, h_mode;
8907 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8908 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8909 + struct inode *h_inode, *h_cached_inode;
8910 + struct dentry *h_dentry;
8911 + struct qstr *name, *h_name;
8918 + unhashed = !!d_unhashed(dentry);
8919 + is_root = !!IS_ROOT(dentry);
8920 + name = &dentry->d_name;
8921 + tmpfile = au_di(dentry)->di_tmpfile;
8924 + * Theoretically, REVAL test should be unnecessary in case of
8926 + * But {fs,i}notify doesn't fire some necessary events,
8927 + * IN_ATTRIB for atime/nlink/pageio
8928 + * Let's do REVAL test too.
8930 + if (do_udba && inode) {
8931 + mode = (inode->i_mode & S_IFMT);
8932 + plus = (inode->i_nlink > 0);
8933 + ibs = au_ibtop(inode);
8934 + ibe = au_ibbot(inode);
8937 + btop = au_dbtop(dentry);
8939 + if (inode && S_ISDIR(inode->i_mode))
8940 + btail = au_dbtaildir(dentry);
8941 + for (bindex = btop; bindex <= btail; bindex++) {
8942 + h_dentry = au_h_dptr(dentry, bindex);
8946 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8947 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8948 + spin_lock(&h_dentry->d_lock);
8949 + h_name = &h_dentry->d_name;
8950 + if (unlikely(do_udba
8953 + && (unhashed != !!d_unhashed(h_dentry)
8954 + || (!tmpfile && !dirren
8955 + && !au_qstreq(name, h_name))
8958 + && !(flags & LOOKUP_OPEN)
8959 + && (h_dentry->d_flags
8960 + & DCACHE_NFSFS_RENAMED)))
8964 + h_unhashed = d_unhashed(h_dentry);
8965 + spin_unlock(&h_dentry->d_lock);
8966 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8967 + unhashed, h_unhashed, dentry, h_dentry);
8970 + spin_unlock(&h_dentry->d_lock);
8972 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8973 + if (unlikely(err))
8974 + /* do not goto err, to keep the errno */
8977 + /* todo: plink too? */
8982 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8986 + if (d_is_positive(h_dentry))
8987 + h_inode = d_inode(h_dentry);
8990 + h_cached_inode = h_inode;
8992 + h_mode = (h_inode->i_mode & S_IFMT);
8993 + h_plus = (h_inode->i_nlink > 0);
8995 + if (inode && ibs <= bindex && bindex <= ibe)
8996 + h_cached_inode = au_h_iptr(inode, bindex);
8999 + if (unlikely(plus != h_plus && !tmpfile))
9002 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
9004 + && !IS_ROOT(h_dentry)
9005 + && unhashed != d_unhashed(h_dentry)))
9008 + if (unlikely(mode != h_mode
9009 + || h_cached_inode != h_inode))
9022 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
9023 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
9026 + struct dentry *parent;
9028 + if (!au_digen_test(dentry, sigen))
9031 + parent = dget_parent(dentry);
9032 + di_read_lock_parent(parent, AuLock_IR);
9033 + AuDebugOn(au_digen_test(parent, sigen));
9034 + au_dbg_verify_gen(parent, sigen);
9035 + err = au_refresh_dentry(dentry, parent);
9036 + di_read_unlock(parent, AuLock_IR);
9042 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
9045 + struct dentry *d, *parent;
9047 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
9048 + return simple_reval_dpath(dentry, sigen);
9050 + /* slow loop, keep it simple and stupid */
9051 + /* cf: au_cpup_dirs() */
9054 + while (au_digen_test(dentry, sigen)) {
9058 + parent = dget_parent(d);
9059 + if (!au_digen_test(parent, sigen))
9065 + di_write_lock_child2(d);
9067 + /* someone might update our dentry while we were sleeping */
9068 + if (au_digen_test(d, sigen)) {
9070 + * todo: consolidate with simple_reval_dpath(),
9071 + * do_refresh() and au_reval_for_attr().
9073 + di_read_lock_parent(parent, AuLock_IR);
9074 + err = au_refresh_dentry(d, parent);
9075 + di_read_unlock(parent, AuLock_IR);
9079 + di_write_unlock(d);
9081 + if (unlikely(err))
9089 + * if valid returns 1, otherwise 0.
9091 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9094 + unsigned int sigen;
9095 + unsigned char do_udba, dirren;
9096 + struct super_block *sb;
9097 + struct inode *inode;
9099 + /* todo: support rcu-walk? */
9100 + if (flags & LOOKUP_RCU)
9104 + if (unlikely(!au_di(dentry)))
9108 + sb = dentry->d_sb;
9111 + * i_mutex of parent dir may be held,
9112 + * but we should not return 'invalid' due to busy.
9114 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9115 + if (unlikely(err)) {
9121 + if (d_really_is_positive(dentry))
9122 + inode = d_inode(dentry);
9123 + if (unlikely(inode && au_is_bad_inode(inode))) {
9128 + if (unlikely(au_dbrange_test(dentry))) {
9134 + sigen = au_sigen(sb);
9135 + if (au_digen_test(dentry, sigen)) {
9136 + AuDebugOn(IS_ROOT(dentry));
9137 + err = au_reval_dpath(dentry, sigen);
9138 + if (unlikely(err)) {
9143 + di_downgrade_lock(dentry, AuLock_IR);
9146 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9148 + && !(inode->i_state && I_LINKABLE)
9149 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9154 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9155 + if (do_udba && inode) {
9156 + aufs_bindex_t btop = au_ibtop(inode);
9157 + struct inode *h_inode;
9160 + h_inode = au_h_iptr(inode, btop);
9161 + if (h_inode && au_test_higen(inode, h_inode)) {
9168 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9169 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9170 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9172 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9178 + di_downgrade_lock(dentry, AuLock_IR);
9180 + aufs_read_unlock(dentry, AuLock_IR);
9185 + AuDbg("%pd invalid, %d\n", dentry, valid);
9191 +static void aufs_d_release(struct dentry *dentry)
9193 + if (au_di(dentry)) {
9194 + au_di_fin(dentry);
9195 + au_hn_di_reinit(dentry);
9199 +const struct dentry_operations aufs_dop = {
9200 + .d_revalidate = aufs_d_revalidate,
9201 + .d_weak_revalidate = aufs_d_revalidate,
9202 + .d_release = aufs_d_release
9205 +/* aufs_dop without d_revalidate */
9206 +const struct dentry_operations aufs_dop_noreval = {
9207 + .d_release = aufs_d_release
9209 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9210 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9211 +++ linux/fs/aufs/dentry.h 2020-01-27 10:57:18.168871450 +0100
9213 +/* SPDX-License-Identifier: GPL-2.0 */
9215 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9217 + * This program, aufs is free software; you can redistribute it and/or modify
9218 + * it under the terms of the GNU General Public License as published by
9219 + * the Free Software Foundation; either version 2 of the License, or
9220 + * (at your option) any later version.
9222 + * This program is distributed in the hope that it will be useful,
9223 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9224 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9225 + * GNU General Public License for more details.
9227 + * You should have received a copy of the GNU General Public License
9228 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9232 + * lookup and dentry operations
9235 +#ifndef __AUFS_DENTRY_H__
9236 +#define __AUFS_DENTRY_H__
9240 +#include <linux/dcache.h>
9241 +#include "dirren.h"
9244 +struct au_hdentry {
9245 + struct dentry *hd_dentry;
9246 + aufs_bindex_t hd_id;
9250 + atomic_t di_generation;
9252 + struct au_rwsem di_rwsem;
9253 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9254 + unsigned char di_tmpfile; /* to allow the different name */
9255 + struct au_hdentry *di_hdentry;
9256 + struct rcu_head rcu;
9257 +} ____cacheline_aligned_in_smp;
9259 +/* ---------------------------------------------------------------------- */
9261 +/* flags for au_lkup_dentry() */
9262 +#define AuLkup_ALLOW_NEG 1
9263 +#define AuLkup_IGNORE_PERM (1 << 1)
9264 +#define AuLkup_DIRREN (1 << 2)
9265 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9266 +#define au_fset_lkup(flags, name) \
9267 + do { (flags) |= AuLkup_##name; } while (0)
9268 +#define au_fclr_lkup(flags, name) \
9269 + do { (flags) &= ~AuLkup_##name; } while (0)
9271 +#ifndef CONFIG_AUFS_DIRREN
9272 +#undef AuLkup_DIRREN
9273 +#define AuLkup_DIRREN 0
9276 +struct au_do_lookup_args {
9277 + unsigned int flags;
9279 + struct qstr whname, *name;
9280 + struct au_dr_lookup dirren;
9283 +/* ---------------------------------------------------------------------- */
9286 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9288 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9289 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9290 + struct dentry *h_parent, struct au_branch *br);
9292 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9293 + unsigned int flags);
9294 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9295 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9296 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9297 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9300 +void au_di_init_once(void *_di);
9301 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9302 +void au_di_free(struct au_dinfo *dinfo);
9303 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9304 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9305 +int au_di_init(struct dentry *dentry);
9306 +void au_di_fin(struct dentry *dentry);
9307 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9309 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9310 +void di_read_unlock(struct dentry *d, int flags);
9311 +void di_downgrade_lock(struct dentry *d, int flags);
9312 +void di_write_lock(struct dentry *d, unsigned int lsc);
9313 +void di_write_unlock(struct dentry *d);
9314 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9315 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9316 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9318 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9319 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9320 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9321 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9323 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9324 + struct dentry *h_dentry);
9325 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9326 +int au_dbrange_test(struct dentry *dentry);
9327 +void au_update_digen(struct dentry *dentry);
9328 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9329 +void au_update_dbtop(struct dentry *dentry);
9330 +void au_update_dbbot(struct dentry *dentry);
9331 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9333 +/* ---------------------------------------------------------------------- */
9335 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9337 + return dentry->d_fsdata;
9340 +/* ---------------------------------------------------------------------- */
9342 +/* lock subclass for dinfo */
9344 + AuLsc_DI_CHILD, /* child first */
9345 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9346 + AuLsc_DI_CHILD3, /* copyup dirs */
9350 + AuLsc_DI_TMP /* temp for replacing dinfo */
9354 + * di_read_lock_child, di_write_lock_child,
9355 + * di_read_lock_child2, di_write_lock_child2,
9356 + * di_read_lock_child3, di_write_lock_child3,
9357 + * di_read_lock_parent, di_write_lock_parent,
9358 + * di_read_lock_parent2, di_write_lock_parent2,
9359 + * di_read_lock_parent3, di_write_lock_parent3,
9361 +#define AuReadLockFunc(name, lsc) \
9362 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9363 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9365 +#define AuWriteLockFunc(name, lsc) \
9366 +static inline void di_write_lock_##name(struct dentry *d) \
9367 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9369 +#define AuRWLockFuncs(name, lsc) \
9370 + AuReadLockFunc(name, lsc) \
9371 + AuWriteLockFunc(name, lsc)
9373 +AuRWLockFuncs(child, CHILD);
9374 +AuRWLockFuncs(child2, CHILD2);
9375 +AuRWLockFuncs(child3, CHILD3);
9376 +AuRWLockFuncs(parent, PARENT);
9377 +AuRWLockFuncs(parent2, PARENT2);
9378 +AuRWLockFuncs(parent3, PARENT3);
9380 +#undef AuReadLockFunc
9381 +#undef AuWriteLockFunc
9382 +#undef AuRWLockFuncs
9384 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9385 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9386 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9388 +/* ---------------------------------------------------------------------- */
9390 +/* todo: memory barrier? */
9391 +static inline unsigned int au_digen(struct dentry *d)
9393 + return atomic_read(&au_di(d)->di_generation);
9396 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9398 + hdentry->hd_dentry = NULL;
9401 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9402 + aufs_bindex_t bindex)
9404 + return di->di_hdentry + bindex;
9407 +static inline void au_hdput(struct au_hdentry *hd)
9410 + dput(hd->hd_dentry);
9413 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9415 + DiMustAnyLock(dentry);
9416 + return au_di(dentry)->di_btop;
9419 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9421 + DiMustAnyLock(dentry);
9422 + return au_di(dentry)->di_bbot;
9425 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9427 + DiMustAnyLock(dentry);
9428 + return au_di(dentry)->di_bwh;
9431 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9433 + DiMustAnyLock(dentry);
9434 + return au_di(dentry)->di_bdiropq;
9437 +/* todo: hard/soft set? */
9438 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9440 + DiMustWriteLock(dentry);
9441 + au_di(dentry)->di_btop = bindex;
9444 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9446 + DiMustWriteLock(dentry);
9447 + au_di(dentry)->di_bbot = bindex;
9450 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9452 + DiMustWriteLock(dentry);
9453 + /* dbwh can be outside of btop - bbot range */
9454 + au_di(dentry)->di_bwh = bindex;
9457 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9459 + DiMustWriteLock(dentry);
9460 + au_di(dentry)->di_bdiropq = bindex;
9463 +/* ---------------------------------------------------------------------- */
9465 +#ifdef CONFIG_AUFS_HNOTIFY
9466 +static inline void au_digen_dec(struct dentry *d)
9468 + atomic_dec(&au_di(d)->di_generation);
9471 +static inline void au_hn_di_reinit(struct dentry *dentry)
9473 + dentry->d_fsdata = NULL;
9476 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9477 +#endif /* CONFIG_AUFS_HNOTIFY */
9479 +#endif /* __KERNEL__ */
9480 +#endif /* __AUFS_DENTRY_H__ */
9481 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9482 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9483 +++ linux/fs/aufs/dinfo.c 2020-01-27 10:57:18.168871450 +0100
9485 +// SPDX-License-Identifier: GPL-2.0
9487 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9489 + * This program, aufs is free software; you can redistribute it and/or modify
9490 + * it under the terms of the GNU General Public License as published by
9491 + * the Free Software Foundation; either version 2 of the License, or
9492 + * (at your option) any later version.
9494 + * This program is distributed in the hope that it will be useful,
9495 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9496 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9497 + * GNU General Public License for more details.
9499 + * You should have received a copy of the GNU General Public License
9500 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9504 + * dentry private data
9509 +void au_di_init_once(void *_dinfo)
9511 + struct au_dinfo *dinfo = _dinfo;
9513 + au_rw_init(&dinfo->di_rwsem);
9516 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9518 + struct au_dinfo *dinfo;
9521 + dinfo = au_cache_alloc_dinfo();
9522 + if (unlikely(!dinfo))
9525 + nbr = au_sbbot(sb) + 1;
9528 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9529 + if (dinfo->di_hdentry) {
9530 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9531 + dinfo->di_btop = -1;
9532 + dinfo->di_bbot = -1;
9533 + dinfo->di_bwh = -1;
9534 + dinfo->di_bdiropq = -1;
9535 + dinfo->di_tmpfile = 0;
9536 + for (i = 0; i < nbr; i++)
9537 + dinfo->di_hdentry[i].hd_id = -1;
9541 + au_cache_free_dinfo(dinfo);
9548 +void au_di_free(struct au_dinfo *dinfo)
9550 + struct au_hdentry *p;
9551 + aufs_bindex_t bbot, bindex;
9553 + /* dentry may not be revalidated */
9554 + bindex = dinfo->di_btop;
9555 + if (bindex >= 0) {
9556 + bbot = dinfo->di_bbot;
9557 + p = au_hdentry(dinfo, bindex);
9558 + while (bindex++ <= bbot)
9561 + au_kfree_try_rcu(dinfo->di_hdentry);
9562 + au_cache_free_dinfo(dinfo);
9565 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9567 + struct au_hdentry *p;
9570 + AuRwMustWriteLock(&a->di_rwsem);
9571 + AuRwMustWriteLock(&b->di_rwsem);
9573 +#define DiSwap(v, name) \
9575 + v = a->di_##name; \
9576 + a->di_##name = b->di_##name; \
9577 + b->di_##name = v; \
9580 + DiSwap(p, hdentry);
9584 + DiSwap(bi, bdiropq);
9590 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9592 + AuRwMustWriteLock(&dst->di_rwsem);
9593 + AuRwMustWriteLock(&src->di_rwsem);
9595 + dst->di_btop = src->di_btop;
9596 + dst->di_bbot = src->di_bbot;
9597 + dst->di_bwh = src->di_bwh;
9598 + dst->di_bdiropq = src->di_bdiropq;
9602 +int au_di_init(struct dentry *dentry)
9605 + struct super_block *sb;
9606 + struct au_dinfo *dinfo;
9609 + sb = dentry->d_sb;
9610 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9612 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9613 + /* smp_mb(); */ /* atomic_set */
9614 + dentry->d_fsdata = dinfo;
9621 +void au_di_fin(struct dentry *dentry)
9623 + struct au_dinfo *dinfo;
9625 + dinfo = au_di(dentry);
9626 + AuRwDestroy(&dinfo->di_rwsem);
9627 + au_di_free(dinfo);
9630 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9633 + struct au_hdentry *hdp;
9635 + AuRwMustWriteLock(&dinfo->di_rwsem);
9638 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9640 + sz = sizeof(*hdp);
9641 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9644 + dinfo->di_hdentry = hdp;
9651 +/* ---------------------------------------------------------------------- */
9653 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9656 + case AuLsc_DI_CHILD:
9657 + ii_write_lock_child(inode);
9659 + case AuLsc_DI_CHILD2:
9660 + ii_write_lock_child2(inode);
9662 + case AuLsc_DI_CHILD3:
9663 + ii_write_lock_child3(inode);
9665 + case AuLsc_DI_PARENT:
9666 + ii_write_lock_parent(inode);
9668 + case AuLsc_DI_PARENT2:
9669 + ii_write_lock_parent2(inode);
9671 + case AuLsc_DI_PARENT3:
9672 + ii_write_lock_parent3(inode);
9679 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9682 + case AuLsc_DI_CHILD:
9683 + ii_read_lock_child(inode);
9685 + case AuLsc_DI_CHILD2:
9686 + ii_read_lock_child2(inode);
9688 + case AuLsc_DI_CHILD3:
9689 + ii_read_lock_child3(inode);
9691 + case AuLsc_DI_PARENT:
9692 + ii_read_lock_parent(inode);
9694 + case AuLsc_DI_PARENT2:
9695 + ii_read_lock_parent2(inode);
9697 + case AuLsc_DI_PARENT3:
9698 + ii_read_lock_parent3(inode);
9705 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9707 + struct inode *inode;
9709 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9710 + if (d_really_is_positive(d)) {
9711 + inode = d_inode(d);
9712 + if (au_ftest_lock(flags, IW))
9713 + do_ii_write_lock(inode, lsc);
9714 + else if (au_ftest_lock(flags, IR))
9715 + do_ii_read_lock(inode, lsc);
9719 +void di_read_unlock(struct dentry *d, int flags)
9721 + struct inode *inode;
9723 + if (d_really_is_positive(d)) {
9724 + inode = d_inode(d);
9725 + if (au_ftest_lock(flags, IW)) {
9726 + au_dbg_verify_dinode(d);
9727 + ii_write_unlock(inode);
9728 + } else if (au_ftest_lock(flags, IR)) {
9729 + au_dbg_verify_dinode(d);
9730 + ii_read_unlock(inode);
9733 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9736 +void di_downgrade_lock(struct dentry *d, int flags)
9738 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9739 + ii_downgrade_lock(d_inode(d));
9740 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9743 +void di_write_lock(struct dentry *d, unsigned int lsc)
9745 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9746 + if (d_really_is_positive(d))
9747 + do_ii_write_lock(d_inode(d), lsc);
9750 +void di_write_unlock(struct dentry *d)
9752 + au_dbg_verify_dinode(d);
9753 + if (d_really_is_positive(d))
9754 + ii_write_unlock(d_inode(d));
9755 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9758 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9760 + AuDebugOn(d1 == d2
9761 + || d_inode(d1) == d_inode(d2)
9762 + || d1->d_sb != d2->d_sb);
9764 + if ((isdir && au_test_subdir(d1, d2))
9766 + di_write_lock_child(d1);
9767 + di_write_lock_child2(d2);
9769 + di_write_lock_child(d2);
9770 + di_write_lock_child2(d1);
9774 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9776 + AuDebugOn(d1 == d2
9777 + || d_inode(d1) == d_inode(d2)
9778 + || d1->d_sb != d2->d_sb);
9780 + if ((isdir && au_test_subdir(d1, d2))
9782 + di_write_lock_parent(d1);
9783 + di_write_lock_parent2(d2);
9785 + di_write_lock_parent(d2);
9786 + di_write_lock_parent2(d1);
9790 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9792 + di_write_unlock(d1);
9793 + if (d_inode(d1) == d_inode(d2))
9794 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9796 + di_write_unlock(d2);
9799 +/* ---------------------------------------------------------------------- */
9801 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9805 + DiMustAnyLock(dentry);
9807 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9809 + AuDebugOn(bindex < 0);
9810 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9811 + AuDebugOn(d && au_dcount(d) <= 0);
9816 + * extended version of au_h_dptr().
9817 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9820 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9822 + struct dentry *h_dentry;
9823 + struct inode *inode, *h_inode;
9825 + AuDebugOn(d_really_is_negative(dentry));
9828 + if (au_dbtop(dentry) <= bindex
9829 + && bindex <= au_dbbot(dentry))
9830 + h_dentry = au_h_dptr(dentry, bindex);
9831 + if (h_dentry && !au_d_linkable(h_dentry)) {
9833 + goto out; /* success */
9836 + inode = d_inode(dentry);
9837 + AuDebugOn(bindex < au_ibtop(inode));
9838 + AuDebugOn(au_ibbot(inode) < bindex);
9839 + h_inode = au_h_iptr(inode, bindex);
9840 + h_dentry = d_find_alias(h_inode);
9842 + if (!IS_ERR(h_dentry)) {
9843 + if (!au_d_linkable(h_dentry))
9844 + goto out; /* success */
9850 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9851 + h_dentry = au_plink_lkup(inode, bindex);
9852 + AuDebugOn(!h_dentry);
9853 + if (!IS_ERR(h_dentry)) {
9854 + if (!au_d_hashed_positive(h_dentry))
9855 + goto out; /* success */
9862 + AuDbgDentry(h_dentry);
9866 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9868 + aufs_bindex_t bbot, bwh;
9870 + bbot = au_dbbot(dentry);
9872 + bwh = au_dbwh(dentry);
9875 + if (0 < bwh && bwh < bbot)
9881 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9883 + aufs_bindex_t bbot, bopq;
9885 + bbot = au_dbtail(dentry);
9887 + bopq = au_dbdiropq(dentry);
9888 + if (0 <= bopq && bopq < bbot)
9894 +/* ---------------------------------------------------------------------- */
9896 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9897 + struct dentry *h_dentry)
9899 + struct au_dinfo *dinfo;
9900 + struct au_hdentry *hd;
9901 + struct au_branch *br;
9903 + DiMustWriteLock(dentry);
9905 + dinfo = au_di(dentry);
9906 + hd = au_hdentry(dinfo, bindex);
9908 + hd->hd_dentry = h_dentry;
9910 + br = au_sbr(dentry->d_sb, bindex);
9911 + hd->hd_id = br->br_id;
9915 +int au_dbrange_test(struct dentry *dentry)
9918 + aufs_bindex_t btop, bbot;
9921 + btop = au_dbtop(dentry);
9922 + bbot = au_dbbot(dentry);
9924 + AuDebugOn(bbot < 0 && btop > bbot);
9927 + AuDebugOn(bbot >= 0);
9933 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9938 + if (unlikely(au_digen(dentry) != sigen
9939 + || au_iigen_test(d_inode(dentry), sigen)))
9945 +void au_update_digen(struct dentry *dentry)
9947 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9948 + /* smp_mb(); */ /* atomic_set */
9951 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9953 + struct au_dinfo *dinfo;
9954 + struct dentry *h_d;
9955 + struct au_hdentry *hdp;
9956 + aufs_bindex_t bindex, bbot;
9958 + DiMustWriteLock(dentry);
9960 + dinfo = au_di(dentry);
9961 + if (!dinfo || dinfo->di_btop < 0)
9964 + if (do_put_zero) {
9965 + bbot = dinfo->di_bbot;
9966 + bindex = dinfo->di_btop;
9967 + hdp = au_hdentry(dinfo, bindex);
9968 + for (; bindex <= bbot; bindex++, hdp++) {
9969 + h_d = hdp->hd_dentry;
9970 + if (h_d && d_is_negative(h_d))
9971 + au_set_h_dptr(dentry, bindex, NULL);
9975 + dinfo->di_btop = 0;
9976 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9977 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9978 + if (hdp->hd_dentry)
9980 + if (dinfo->di_btop > dinfo->di_bbot) {
9981 + dinfo->di_btop = -1;
9982 + dinfo->di_bbot = -1;
9986 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9987 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9988 + if (hdp->hd_dentry)
9990 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9993 +void au_update_dbtop(struct dentry *dentry)
9995 + aufs_bindex_t bindex, bbot;
9996 + struct dentry *h_dentry;
9998 + bbot = au_dbbot(dentry);
9999 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
10000 + h_dentry = au_h_dptr(dentry, bindex);
10003 + if (d_is_positive(h_dentry)) {
10004 + au_set_dbtop(dentry, bindex);
10007 + au_set_h_dptr(dentry, bindex, NULL);
10011 +void au_update_dbbot(struct dentry *dentry)
10013 + aufs_bindex_t bindex, btop;
10014 + struct dentry *h_dentry;
10016 + btop = au_dbtop(dentry);
10017 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
10018 + h_dentry = au_h_dptr(dentry, bindex);
10021 + if (d_is_positive(h_dentry)) {
10022 + au_set_dbbot(dentry, bindex);
10025 + au_set_h_dptr(dentry, bindex, NULL);
10029 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
10031 + aufs_bindex_t bindex, bbot;
10033 + bbot = au_dbbot(dentry);
10034 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
10035 + if (au_h_dptr(dentry, bindex) == h_dentry)
10039 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
10040 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
10041 +++ linux/fs/aufs/dir.c 2020-01-27 10:57:18.168871450 +0100
10043 +// SPDX-License-Identifier: GPL-2.0
10045 + * Copyright (C) 2005-2020 Junjiro R. Okajima
10047 + * This program, aufs is free software; you can redistribute it and/or modify
10048 + * it under the terms of the GNU General Public License as published by
10049 + * the Free Software Foundation; either version 2 of the License, or
10050 + * (at your option) any later version.
10052 + * This program is distributed in the hope that it will be useful,
10053 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10054 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10055 + * GNU General Public License for more details.
10057 + * You should have received a copy of the GNU General Public License
10058 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10062 + * directory operations
10065 +#include <linux/fs_stack.h>
10066 +#include <linux/iversion.h>
10069 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10071 + unsigned int nlink;
10073 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10075 + nlink = dir->i_nlink;
10076 + nlink += h_dir->i_nlink - 2;
10077 + if (h_dir->i_nlink < 2)
10079 + smp_mb(); /* for i_nlink */
10080 + /* 0 can happen in revaliding */
10081 + set_nlink(dir, nlink);
10084 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10086 + unsigned int nlink;
10088 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10090 + nlink = dir->i_nlink;
10091 + nlink -= h_dir->i_nlink - 2;
10092 + if (h_dir->i_nlink < 2)
10094 + smp_mb(); /* for i_nlink */
10095 + /* nlink == 0 means the branch-fs is broken */
10096 + set_nlink(dir, nlink);
10099 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10102 + aufs_bindex_t bindex, bbot;
10103 + struct file *h_file;
10104 + struct dentry *h_dentry;
10108 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10110 + bbot = au_fbbot_dir(file);
10111 + for (bindex = au_fbtop(file);
10112 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10114 + h_file = au_hf_dir(file, bindex);
10115 + if (h_file && file_inode(h_file))
10116 + sz += vfsub_f_size_read(h_file);
10119 + AuDebugOn(!dentry);
10120 + AuDebugOn(!d_is_dir(dentry));
10122 + bbot = au_dbtaildir(dentry);
10123 + for (bindex = au_dbtop(dentry);
10124 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10126 + h_dentry = au_h_dptr(dentry, bindex);
10127 + if (h_dentry && d_is_positive(h_dentry))
10128 + sz += i_size_read(d_inode(h_dentry));
10131 + if (sz < KMALLOC_MAX_SIZE)
10132 + sz = roundup_pow_of_two(sz);
10133 + if (sz > KMALLOC_MAX_SIZE)
10134 + sz = KMALLOC_MAX_SIZE;
10135 + else if (sz < NAME_MAX) {
10136 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10137 + sz = AUFS_RDBLK_DEF;
10142 +struct au_dir_ts_arg {
10143 + struct dentry *dentry;
10144 + aufs_bindex_t brid;
10147 +static void au_do_dir_ts(void *arg)
10149 + struct au_dir_ts_arg *a = arg;
10150 + struct au_dtime dt;
10151 + struct path h_path;
10152 + struct inode *dir, *h_dir;
10153 + struct super_block *sb;
10154 + struct au_branch *br;
10155 + struct au_hinode *hdir;
10157 + aufs_bindex_t btop, bindex;
10159 + sb = a->dentry->d_sb;
10160 + if (d_really_is_negative(a->dentry))
10162 + /* no dir->i_mutex lock */
10163 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10165 + dir = d_inode(a->dentry);
10166 + btop = au_ibtop(dir);
10167 + bindex = au_br_index(sb, a->brid);
10168 + if (bindex < btop)
10171 + br = au_sbr(sb, bindex);
10172 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10173 + if (!h_path.dentry)
10175 + h_path.mnt = au_br_mnt(br);
10176 + au_dtime_store(&dt, a->dentry, &h_path);
10178 + br = au_sbr(sb, btop);
10179 + if (!au_br_writable(br->br_perm))
10181 + h_path.dentry = au_h_dptr(a->dentry, btop);
10182 + h_path.mnt = au_br_mnt(br);
10183 + err = vfsub_mnt_want_write(h_path.mnt);
10186 + hdir = au_hi(dir, btop);
10187 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10188 + h_dir = au_h_iptr(dir, btop);
10189 + if (h_dir->i_nlink
10190 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10191 + dt.dt_h_path = h_path;
10192 + au_dtime_revert(&dt);
10194 + au_hn_inode_unlock(hdir);
10195 + vfsub_mnt_drop_write(h_path.mnt);
10196 + au_cpup_attr_timesizes(dir);
10199 + aufs_read_unlock(a->dentry, AuLock_DW);
10202 + au_nwt_done(&au_sbi(sb)->si_nowait);
10203 + au_kfree_try_rcu(arg);
10206 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10208 + int perm, wkq_err;
10209 + aufs_bindex_t btop;
10210 + struct au_dir_ts_arg *arg;
10211 + struct dentry *dentry;
10212 + struct super_block *sb;
10216 + dentry = d_find_any_alias(dir);
10217 + AuDebugOn(!dentry);
10218 + sb = dentry->d_sb;
10219 + btop = au_ibtop(dir);
10220 + if (btop == bindex) {
10221 + au_cpup_attr_timesizes(dir);
10225 + perm = au_sbr_perm(sb, btop);
10226 + if (!au_br_writable(perm))
10229 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10233 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10234 + arg->brid = au_sbr_id(sb, bindex);
10235 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10236 + if (unlikely(wkq_err)) {
10237 + pr_err("wkq %d\n", wkq_err);
10239 + au_kfree_try_rcu(arg);
10246 +/* ---------------------------------------------------------------------- */
10248 +static int reopen_dir(struct file *file)
10251 + unsigned int flags;
10252 + aufs_bindex_t bindex, btail, btop;
10253 + struct dentry *dentry, *h_dentry;
10254 + struct file *h_file;
10256 + /* open all lower dirs */
10257 + dentry = file->f_path.dentry;
10258 + btop = au_dbtop(dentry);
10259 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10260 + au_set_h_fptr(file, bindex, NULL);
10261 + au_set_fbtop(file, btop);
10263 + btail = au_dbtaildir(dentry);
10264 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10265 + au_set_h_fptr(file, bindex, NULL);
10266 + au_set_fbbot_dir(file, btail);
10268 + flags = vfsub_file_flags(file);
10269 + for (bindex = btop; bindex <= btail; bindex++) {
10270 + h_dentry = au_h_dptr(dentry, bindex);
10273 + h_file = au_hf_dir(file, bindex);
10277 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10278 + err = PTR_ERR(h_file);
10279 + if (IS_ERR(h_file))
10280 + goto out; /* close all? */
10281 + au_set_h_fptr(file, bindex, h_file);
10283 + au_update_figen(file);
10284 + /* todo: necessary? */
10285 + /* file->f_ra = h_file->f_ra; */
10292 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10295 + aufs_bindex_t bindex, btail;
10296 + struct dentry *dentry, *h_dentry;
10297 + struct vfsmount *mnt;
10299 + FiMustWriteLock(file);
10300 + AuDebugOn(h_file);
10303 + mnt = file->f_path.mnt;
10304 + dentry = file->f_path.dentry;
10305 + file->f_version = inode_query_iversion(d_inode(dentry));
10306 + bindex = au_dbtop(dentry);
10307 + au_set_fbtop(file, bindex);
10308 + btail = au_dbtaildir(dentry);
10309 + au_set_fbbot_dir(file, btail);
10310 + for (; !err && bindex <= btail; bindex++) {
10311 + h_dentry = au_h_dptr(dentry, bindex);
10315 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10316 + if (unlikely(err))
10318 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10319 + if (IS_ERR(h_file)) {
10320 + err = PTR_ERR(h_file);
10323 + au_set_h_fptr(file, bindex, h_file);
10325 + au_update_figen(file);
10326 + /* todo: necessary? */
10327 + /* file->f_ra = h_file->f_ra; */
10329 + return 0; /* success */
10332 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10333 + au_set_h_fptr(file, bindex, NULL);
10334 + au_set_fbtop(file, -1);
10335 + au_set_fbbot_dir(file, -1);
10340 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10341 + struct file *file)
10344 + struct super_block *sb;
10345 + struct au_fidir *fidir;
10348 + sb = file->f_path.dentry->d_sb;
10349 + si_read_lock(sb, AuLock_FLUSH);
10350 + fidir = au_fidir_alloc(sb);
10352 + struct au_do_open_args args = {
10353 + .open = do_open_dir,
10356 + err = au_do_open(file, &args);
10357 + if (unlikely(err))
10358 + au_kfree_rcu(fidir);
10360 + si_read_unlock(sb);
10364 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10365 + struct file *file)
10367 + struct au_vdir *vdir_cache;
10368 + struct au_finfo *finfo;
10369 + struct au_fidir *fidir;
10370 + struct au_hfile *hf;
10371 + aufs_bindex_t bindex, bbot;
10373 + finfo = au_fi(file);
10374 + fidir = finfo->fi_hdir;
10376 + au_hbl_del(&finfo->fi_hlist,
10377 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10378 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10380 + au_vdir_free(vdir_cache);
10382 + bindex = finfo->fi_btop;
10383 + if (bindex >= 0) {
10384 + hf = fidir->fd_hfile + bindex;
10386 + * calls fput() instead of filp_close(),
10387 + * since no dnotify or lock for the lower file.
10389 + bbot = fidir->fd_bbot;
10390 + for (; bindex <= bbot; bindex++, hf++)
10392 + au_hfput(hf, /*execed*/0);
10394 + au_kfree_rcu(fidir);
10395 + finfo->fi_hdir = NULL;
10397 + au_finfo_fin(file);
10401 +/* ---------------------------------------------------------------------- */
10403 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10406 + aufs_bindex_t bindex, bbot;
10407 + struct file *h_file;
10410 + bbot = au_fbbot_dir(file);
10411 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10412 + h_file = au_hf_dir(file, bindex);
10414 + err = vfsub_flush(h_file, id);
10419 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10421 + return au_do_flush(file, id, au_do_flush_dir);
10424 +/* ---------------------------------------------------------------------- */
10426 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10429 + aufs_bindex_t bbot, bindex;
10430 + struct inode *inode;
10431 + struct super_block *sb;
10434 + sb = dentry->d_sb;
10435 + inode = d_inode(dentry);
10436 + IMustLock(inode);
10437 + bbot = au_dbbot(dentry);
10438 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10439 + struct path h_path;
10441 + if (au_test_ro(sb, bindex, inode))
10443 + h_path.dentry = au_h_dptr(dentry, bindex);
10444 + if (!h_path.dentry)
10447 + h_path.mnt = au_sbr_mnt(sb, bindex);
10448 + err = vfsub_fsync(NULL, &h_path, datasync);
10454 +static int au_do_fsync_dir(struct file *file, int datasync)
10457 + aufs_bindex_t bbot, bindex;
10458 + struct file *h_file;
10459 + struct super_block *sb;
10460 + struct inode *inode;
10462 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10463 + if (unlikely(err))
10466 + inode = file_inode(file);
10467 + sb = inode->i_sb;
10468 + bbot = au_fbbot_dir(file);
10469 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10470 + h_file = au_hf_dir(file, bindex);
10471 + if (!h_file || au_test_ro(sb, bindex, inode))
10474 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10482 + * @file may be NULL
10484 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10488 + struct dentry *dentry;
10489 + struct inode *inode;
10490 + struct super_block *sb;
10493 + dentry = file->f_path.dentry;
10494 + inode = d_inode(dentry);
10495 + inode_lock(inode);
10496 + sb = dentry->d_sb;
10497 + si_noflush_read_lock(sb);
10499 + err = au_do_fsync_dir(file, datasync);
10501 + di_write_lock_child(dentry);
10502 + err = au_do_fsync_dir_no_file(dentry, datasync);
10504 + au_cpup_attr_timesizes(inode);
10505 + di_write_unlock(dentry);
10507 + fi_write_unlock(file);
10509 + si_read_unlock(sb);
10510 + inode_unlock(inode);
10514 +/* ---------------------------------------------------------------------- */
10516 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10519 + struct dentry *dentry;
10520 + struct inode *inode, *h_inode;
10521 + struct super_block *sb;
10523 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10525 + dentry = file->f_path.dentry;
10526 + inode = d_inode(dentry);
10527 + IMustLock(inode);
10529 + sb = dentry->d_sb;
10530 + si_read_lock(sb, AuLock_FLUSH);
10531 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10532 + if (unlikely(err))
10534 + err = au_alive_dir(dentry);
10536 + err = au_vdir_init(file);
10537 + di_downgrade_lock(dentry, AuLock_IR);
10538 + if (unlikely(err))
10541 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10542 + if (!au_test_nfsd()) {
10543 + err = au_vdir_fill_de(file, ctx);
10544 + fsstack_copy_attr_atime(inode, h_inode);
10547 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10548 + * encode_fh() and others.
10550 + atomic_inc(&h_inode->i_count);
10551 + di_read_unlock(dentry, AuLock_IR);
10552 + si_read_unlock(sb);
10553 + err = au_vdir_fill_de(file, ctx);
10554 + fsstack_copy_attr_atime(inode, h_inode);
10555 + fi_write_unlock(file);
10563 + di_read_unlock(dentry, AuLock_IR);
10564 + fi_write_unlock(file);
10566 + si_read_unlock(sb);
10570 +/* ---------------------------------------------------------------------- */
10572 +#define AuTestEmpty_WHONLY 1
10573 +#define AuTestEmpty_CALLED (1 << 1)
10574 +#define AuTestEmpty_SHWH (1 << 2)
10575 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10576 +#define au_fset_testempty(flags, name) \
10577 + do { (flags) |= AuTestEmpty_##name; } while (0)
10578 +#define au_fclr_testempty(flags, name) \
10579 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10581 +#ifndef CONFIG_AUFS_SHWH
10582 +#undef AuTestEmpty_SHWH
10583 +#define AuTestEmpty_SHWH 0
10586 +struct test_empty_arg {
10587 + struct dir_context ctx;
10588 + struct au_nhash *whlist;
10589 + unsigned int flags;
10591 + aufs_bindex_t bindex;
10594 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10595 + int namelen, loff_t offset __maybe_unused, u64 ino,
10596 + unsigned int d_type)
10598 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10600 + char *name = (void *)__name;
10603 + au_fset_testempty(arg->flags, CALLED);
10605 + if (name[0] == '.'
10606 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10607 + goto out; /* success */
10609 + if (namelen <= AUFS_WH_PFX_LEN
10610 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10611 + if (au_ftest_testempty(arg->flags, WHONLY)
10612 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10613 + arg->err = -ENOTEMPTY;
10617 + name += AUFS_WH_PFX_LEN;
10618 + namelen -= AUFS_WH_PFX_LEN;
10619 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10620 + arg->err = au_nhash_append_wh
10621 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10622 + au_ftest_testempty(arg->flags, SHWH));
10626 + AuTraceErr(arg->err);
10630 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10633 + struct file *h_file;
10634 + struct au_branch *br;
10636 + h_file = au_h_open(dentry, arg->bindex,
10637 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10638 + /*file*/NULL, /*force_wr*/0);
10639 + err = PTR_ERR(h_file);
10640 + if (IS_ERR(h_file))
10644 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10645 + && !file_inode(h_file)->i_nlink)
10650 + au_fclr_testempty(arg->flags, CALLED);
10652 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10655 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10659 + br = au_sbr(dentry->d_sb, arg->bindex);
10660 + au_lcnt_dec(&br->br_nfiles);
10665 +struct do_test_empty_args {
10667 + struct dentry *dentry;
10668 + struct test_empty_arg *arg;
10671 +static void call_do_test_empty(void *args)
10673 + struct do_test_empty_args *a = args;
10674 + *a->errp = do_test_empty(a->dentry, a->arg);
10677 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10679 + int err, wkq_err;
10680 + struct dentry *h_dentry;
10681 + struct inode *h_inode;
10683 + h_dentry = au_h_dptr(dentry, arg->bindex);
10684 + h_inode = d_inode(h_dentry);
10685 + /* todo: i_mode changes anytime? */
10686 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10687 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10688 + inode_unlock_shared(h_inode);
10690 + err = do_test_empty(dentry, arg);
10692 + struct do_test_empty_args args = {
10694 + .dentry = dentry,
10697 + unsigned int flags = arg->flags;
10699 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10700 + if (unlikely(wkq_err))
10702 + arg->flags = flags;
10708 +int au_test_empty_lower(struct dentry *dentry)
10711 + unsigned int rdhash;
10712 + aufs_bindex_t bindex, btop, btail;
10713 + struct au_nhash whlist;
10714 + struct test_empty_arg arg = {
10716 + .actor = test_empty_cb
10719 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10721 + SiMustAnyLock(dentry->d_sb);
10723 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10725 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10726 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10727 + if (unlikely(err))
10731 + arg.whlist = &whlist;
10732 + btop = au_dbtop(dentry);
10733 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10734 + au_fset_testempty(arg.flags, SHWH);
10735 + test_empty = do_test_empty;
10736 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10737 + test_empty = sio_test_empty;
10738 + arg.bindex = btop;
10739 + err = test_empty(dentry, &arg);
10740 + if (unlikely(err))
10743 + au_fset_testempty(arg.flags, WHONLY);
10744 + btail = au_dbtaildir(dentry);
10745 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10746 + struct dentry *h_dentry;
10748 + h_dentry = au_h_dptr(dentry, bindex);
10749 + if (h_dentry && d_is_positive(h_dentry)) {
10750 + arg.bindex = bindex;
10751 + err = test_empty(dentry, &arg);
10756 + au_nhash_wh_free(&whlist);
10761 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10764 + struct test_empty_arg arg = {
10766 + .actor = test_empty_cb
10769 + aufs_bindex_t bindex, btail;
10772 + arg.whlist = whlist;
10773 + arg.flags = AuTestEmpty_WHONLY;
10774 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10775 + au_fset_testempty(arg.flags, SHWH);
10776 + btail = au_dbtaildir(dentry);
10777 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10778 + struct dentry *h_dentry;
10780 + h_dentry = au_h_dptr(dentry, bindex);
10781 + if (h_dentry && d_is_positive(h_dentry)) {
10782 + arg.bindex = bindex;
10783 + err = sio_test_empty(dentry, &arg);
10790 +/* ---------------------------------------------------------------------- */
10792 +const struct file_operations aufs_dir_fop = {
10793 + .owner = THIS_MODULE,
10794 + .llseek = default_llseek,
10795 + .read = generic_read_dir,
10796 + .iterate_shared = aufs_iterate_shared,
10797 + .unlocked_ioctl = aufs_ioctl_dir,
10798 +#ifdef CONFIG_COMPAT
10799 + .compat_ioctl = aufs_compat_ioctl_dir,
10801 + .open = aufs_open_dir,
10802 + .release = aufs_release_dir,
10803 + .flush = aufs_flush_dir,
10804 + .fsync = aufs_fsync_dir
10806 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10807 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10808 +++ linux/fs/aufs/dir.h 2020-08-03 09:14:46.095748745 +0200
10810 +/* SPDX-License-Identifier: GPL-2.0 */
10812 + * Copyright (C) 2005-2020 Junjiro R. Okajima
10814 + * This program, aufs is free software; you can redistribute it and/or modify
10815 + * it under the terms of the GNU General Public License as published by
10816 + * the Free Software Foundation; either version 2 of the License, or
10817 + * (at your option) any later version.
10819 + * This program is distributed in the hope that it will be useful,
10820 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10821 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10822 + * GNU General Public License for more details.
10824 + * You should have received a copy of the GNU General Public License
10825 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10829 + * directory operations
10832 +#ifndef __AUFS_DIR_H__
10833 +#define __AUFS_DIR_H__
10837 +#include <linux/fs.h>
10839 +/* ---------------------------------------------------------------------- */
10841 +/* need to be faster and smaller */
10844 + unsigned int nh_num;
10845 + struct hlist_head *nh_head;
10848 +struct au_vdir_destr {
10849 + unsigned char len;
10850 + unsigned char name[];
10853 +struct au_vdir_dehstr {
10854 + struct hlist_node hash;
10855 + struct au_vdir_destr *str;
10856 + struct rcu_head rcu;
10857 +} ____cacheline_aligned_in_smp;
10859 +struct au_vdir_de {
10861 + unsigned char de_type;
10862 + /* caution: packed */
10863 + struct au_vdir_destr de_str;
10866 +struct au_vdir_wh {
10867 + struct hlist_node wh_hash;
10868 +#ifdef CONFIG_AUFS_SHWH
10870 + aufs_bindex_t wh_bindex;
10871 + unsigned char wh_type;
10873 + aufs_bindex_t wh_bindex;
10875 + /* caution: packed */
10876 + struct au_vdir_destr wh_str;
10879 +union au_vdir_deblk_p {
10880 + unsigned char *deblk;
10881 + struct au_vdir_de *de;
10885 + unsigned char **vd_deblk;
10886 + unsigned long vd_nblk;
10888 + unsigned long ul;
10889 + union au_vdir_deblk_p p;
10893 + unsigned int vd_deblk_sz;
10894 + unsigned long vd_jiffy;
10895 + struct rcu_head rcu;
10896 +} ____cacheline_aligned_in_smp;
10898 +/* ---------------------------------------------------------------------- */
10901 +extern const struct file_operations aufs_dir_fop;
10902 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10903 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10904 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10905 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10906 +int au_test_empty_lower(struct dentry *dentry);
10907 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10910 +unsigned int au_rdhash_est(loff_t sz);
10911 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10912 +void au_nhash_wh_free(struct au_nhash *whlist);
10913 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10915 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10916 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10917 + unsigned int d_type, aufs_bindex_t bindex,
10918 + unsigned char shwh);
10919 +void au_vdir_free(struct au_vdir *vdir);
10920 +int au_vdir_init(struct file *file);
10921 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10924 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10926 +#ifdef CONFIG_AUFS_RDU
10928 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10929 +#ifdef CONFIG_COMPAT
10930 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10931 + unsigned long arg);
10934 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10935 + unsigned int cmd, unsigned long arg)
10936 +#ifdef CONFIG_COMPAT
10937 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10938 + unsigned int cmd, unsigned long arg)
10942 +#endif /* __KERNEL__ */
10943 +#endif /* __AUFS_DIR_H__ */
10944 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10945 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10946 +++ linux/fs/aufs/dirren.c 2020-08-03 09:14:46.095748745 +0200
10948 +// SPDX-License-Identifier: GPL-2.0
10950 + * Copyright (C) 2017-2020 Junjiro R. Okajima
10952 + * This program, aufs is free software; you can redistribute it and/or modify
10953 + * it under the terms of the GNU General Public License as published by
10954 + * the Free Software Foundation; either version 2 of the License, or
10955 + * (at your option) any later version.
10957 + * This program is distributed in the hope that it will be useful,
10958 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10959 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10960 + * GNU General Public License for more details.
10962 + * You should have received a copy of the GNU General Public License
10963 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10967 + * special handling in renaming a directory
10968 + * in order to support looking-up the before-renamed name on the lower readonly
10972 +#include <linux/byteorder/generic.h>
10975 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10979 + idx = au_dr_ihash(ent->dr_h_ino);
10980 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10983 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10986 + struct hlist_bl_head *hbl;
10989 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10990 + hbl = dr->dr_h_ino + i;
10991 + hlist_bl_lock(hbl);
10992 + ret &= hlist_bl_empty(hbl);
10993 + hlist_bl_unlock(hbl);
10999 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
11001 + struct au_dr_hino *found, *ent;
11002 + struct hlist_bl_head *hbl;
11003 + struct hlist_bl_node *pos;
11007 + idx = au_dr_ihash(ino);
11008 + hbl = dr->dr_h_ino + idx;
11009 + hlist_bl_lock(hbl);
11010 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11011 + if (ent->dr_h_ino == ino) {
11015 + hlist_bl_unlock(hbl);
11020 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
11021 + struct au_dr_hino *add_ent)
11024 + struct hlist_bl_head *hbl;
11025 + struct hlist_bl_node *pos;
11026 + struct au_dr_hino *ent;
11029 + idx = au_dr_ihash(ino);
11030 + hbl = dr->dr_h_ino + idx;
11031 +#if 0 /* debug print */
11033 + struct hlist_bl_node *tmp;
11035 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11036 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
11039 + hlist_bl_lock(hbl);
11040 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11041 + if (ent->dr_h_ino == ino) {
11045 + if (!found && add_ent)
11046 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
11047 + hlist_bl_unlock(hbl);
11049 + if (!found && add_ent)
11050 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
11055 +void au_dr_hino_free(struct au_dr_br *dr)
11058 + struct hlist_bl_head *hbl;
11059 + struct hlist_bl_node *pos, *tmp;
11060 + struct au_dr_hino *ent;
11062 + /* SiMustWriteLock(sb); */
11064 + for (i = 0; i < AuDirren_NHASH; i++) {
11065 + hbl = dr->dr_h_ino + i;
11066 + /* no spinlock since sbinfo must be write-locked */
11067 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11068 + au_kfree_rcu(ent);
11069 + INIT_HLIST_BL_HEAD(hbl);
11073 +/* returns the number of inodes or an error */
11074 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11075 + struct file *hinofile)
11079 + loff_t pos, oldsize;
11081 + struct inode *hinoinode;
11082 + struct hlist_bl_head *hbl;
11083 + struct hlist_bl_node *n1, *n2;
11084 + struct au_dr_hino *ent;
11086 + SiMustWriteLock(sb);
11087 + AuDebugOn(!au_br_writable(br->br_perm));
11089 + hinoinode = file_inode(hinofile);
11090 + oldsize = i_size_read(hinoinode);
11094 + hbl = br->br_dirren.dr_h_ino;
11095 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11096 + /* no bit-lock since sbinfo must be write-locked */
11097 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11098 + AuDbg("hi%llu, %pD2\n",
11099 + (unsigned long long)ent->dr_h_ino, hinofile);
11100 + u64 = cpu_to_be64(ent->dr_h_ino);
11101 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11102 + if (ssz == sizeof(u64))
11105 + /* write error */
11106 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11113 + /* regardless the error */
11114 + if (pos < oldsize) {
11115 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11123 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11130 + struct au_dr_hino *ent;
11131 + struct inode *hinoinode;
11132 + struct hlist_bl_head *hbl;
11136 + hbl = dr->dr_h_ino;
11137 + hinoinode = file_inode(hinofile);
11138 + sz = i_size_read(hinoinode);
11139 + AuDebugOn(sz % sizeof(u64));
11140 + n = sz / sizeof(u64);
11142 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11143 + if (unlikely(ssz != sizeof(u64))) {
11144 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11151 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11157 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11158 + AuDbg("hi%llu, %pD2\n",
11159 + (unsigned long long)ent->dr_h_ino, hinofile);
11160 + hidx = au_dr_ihash(ent->dr_h_ino);
11161 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11163 + goto out; /* success */
11166 + au_dr_hino_free(dr);
11173 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11174 + * @path is a switch to distinguish load and store.
11176 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11177 + struct au_branch *br, const struct path *path)
11180 + unsigned char load, suspend;
11181 + struct file *hinofile;
11182 + struct au_hinode *hdir;
11183 + struct inode *dir, *delegated;
11184 + struct path hinopath;
11185 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11186 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11188 + AuDebugOn(bindex < 0 && !br);
11189 + AuDebugOn(bindex >= 0 && br);
11194 + br = au_sbr(sb, bindex);
11197 + path = &br->br_path;
11198 + AuDebugOn(!au_br_writable(br->br_perm));
11199 + if (unlikely(!au_br_writable(br->br_perm)))
11205 + dir = d_inode(sb->s_root);
11206 + hdir = au_hinode(au_ii(dir), bindex);
11207 + dir = hdir->hi_inode;
11208 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11210 + dir = d_inode(path->dentry);
11211 + inode_lock_nested(dir, AuLsc_I_CHILD);
11213 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11214 + err = PTR_ERR(hinopath.dentry);
11215 + if (IS_ERR(hinopath.dentry))
11219 + flags = O_RDONLY;
11221 + if (d_is_negative(hinopath.dentry))
11222 + goto out_dput; /* success */
11224 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11225 + if (d_is_positive(hinopath.dentry)) {
11226 + delegated = NULL;
11227 + err = vfsub_unlink(dir, &hinopath, &delegated,
11230 + if (unlikely(err))
11231 + pr_err("ignored err %d, %pd2\n",
11232 + err, hinopath.dentry);
11233 + if (unlikely(err == -EWOULDBLOCK))
11238 + } else if (!d_is_positive(hinopath.dentry)) {
11239 + err = vfsub_create(dir, &hinopath, 0600,
11240 + /*want_excl*/false);
11242 + if (unlikely(err))
11245 + flags = O_WRONLY;
11247 + hinopath.mnt = path->mnt;
11248 + hinofile = vfsub_dentry_open(&hinopath, flags);
11250 + au_hn_inode_unlock(hdir);
11252 + inode_unlock(dir);
11253 + dput(hinopath.dentry);
11254 + AuTraceErrPtr(hinofile);
11255 + if (IS_ERR(hinofile)) {
11256 + err = PTR_ERR(hinofile);
11261 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11263 + err = au_dr_hino_store(sb, br, hinofile);
11268 + dput(hinopath.dentry);
11271 + au_hn_inode_unlock(hdir);
11273 + inode_unlock(dir);
11279 +/* ---------------------------------------------------------------------- */
11281 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11284 + struct kstatfs kstfs;
11286 + struct dentry *dentry;
11287 + struct super_block *sb;
11289 + err = vfs_statfs((void *)path, &kstfs);
11291 + if (unlikely(err))
11294 + /* todo: support for UUID */
11296 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11297 + brid->type = AuBrid_FSID;
11298 + brid->fsid = kstfs.f_fsid;
11300 + dentry = path->dentry;
11301 + sb = dentry->d_sb;
11304 + brid->type = AuBrid_DEV;
11313 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11314 + const struct path *path)
11317 + struct au_dr_br *dr;
11318 + struct hlist_bl_head *hbl;
11320 + dr = &br->br_dirren;
11321 + hbl = dr->dr_h_ino;
11322 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11323 + INIT_HLIST_BL_HEAD(hbl);
11325 + err = au_dr_brid_init(&dr->dr_brid, path);
11326 + if (unlikely(err))
11329 + if (au_opt_test(au_mntflags(sb), DIRREN))
11330 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11337 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11342 + if (au_br_writable(br->br_perm))
11343 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11345 + au_dr_hino_free(&br->br_dirren);
11350 +/* ---------------------------------------------------------------------- */
11352 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11353 + char *buf, size_t sz)
11356 + unsigned int major, minor;
11360 + err = snprintf(p, sz, "%d_", brid->type);
11361 + AuDebugOn(err > sz);
11364 + switch (brid->type) {
11365 + case AuBrid_Unset:
11367 + case AuBrid_UUID:
11368 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11370 + case AuBrid_FSID:
11371 + err = snprintf(p, sz, "%08x-%08x",
11372 + brid->fsid.val[0], brid->fsid.val[1]);
11375 + major = MAJOR(brid->dev);
11376 + minor = MINOR(brid->dev);
11377 + if (major <= 0xff && minor <= 0xff)
11378 + err = snprintf(p, sz, "%02x%02x", major, minor);
11380 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11383 + AuDebugOn(err > sz);
11386 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11387 + AuDebugOn(err > sz);
11394 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11397 + struct dentry *br_dentry;
11398 + struct inode *br_inode;
11400 + br_dentry = au_br_dentry(br);
11401 + br_inode = d_inode(br_dentry);
11402 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11403 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11404 + AuDebugOn(rlen > len);
11409 +/* ---------------------------------------------------------------------- */
11412 + * from the given @h_dentry, construct drinfo at @*fdata.
11413 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11416 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11417 + struct dentry *h_dentry,
11418 + unsigned char *allocated)
11421 + struct au_drinfo_fdata *f, *p;
11422 + struct au_drinfo *drinfo;
11423 + struct inode *h_inode;
11424 + struct qstr *qname;
11428 + h_inode = d_inode(h_dentry);
11429 + qname = &h_dentry->d_name;
11430 + drinfo = &f->drinfo;
11431 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11432 + drinfo->oldnamelen = qname->len;
11433 + if (*allocated < sizeof(*f) + qname->len) {
11434 + v = roundup_pow_of_two(*allocated + qname->len);
11435 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11436 + if (unlikely(!p)) {
11444 + drinfo = &f->drinfo;
11446 + memcpy(drinfo->oldname, qname->name, qname->len);
11447 + AuDbg("i%llu, %.*s\n",
11448 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11449 + drinfo->oldname);
11456 +/* callers have to free the return value */
11457 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11459 + struct au_drinfo *ret, *drinfo;
11460 + struct au_drinfo_fdata fdata;
11465 + ret = ERR_PTR(-EIO);
11467 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11468 + if (unlikely(ssz != sizeof(fdata))) {
11469 + AuIOErr("ssz %zd, %u, %pD2\n",
11470 + ssz, (unsigned int)sizeof(fdata), file);
11474 + fdata.magic = ntohl((__force __be32)fdata.magic);
11475 + switch (fdata.magic) {
11476 + case AUFS_DRINFO_MAGIC_V1:
11479 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11480 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11484 + drinfo = &fdata.drinfo;
11485 + len = drinfo->oldnamelen;
11487 + AuIOErr("broken drinfo %pD2\n", file);
11492 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11493 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11494 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11495 + (unsigned long long)drinfo->ino,
11496 + (unsigned long long)h_ino, file);
11497 + goto out; /* success */
11500 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11501 + if (unlikely(!ret)) {
11502 + ret = ERR_PTR(-ENOMEM);
11503 + AuTraceErrPtr(ret);
11508 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11509 + if (unlikely(ssz != len)) {
11510 + au_kfree_rcu(ret);
11511 + ret = ERR_PTR(-EIO);
11512 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11516 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11522 +/* ---------------------------------------------------------------------- */
11524 +/* in order to be revertible */
11525 +struct au_drinfo_rev_elm {
11527 + struct dentry *info_dentry;
11528 + struct au_drinfo *info_last;
11531 +struct au_drinfo_rev {
11532 + unsigned char already;
11533 + aufs_bindex_t nelm;
11534 + struct au_drinfo_rev_elm elm[];
11537 +/* todo: isn't it too large? */
11538 +struct au_drinfo_store {
11539 + struct path h_ppath;
11540 + struct dentry *h_dentry;
11541 + struct au_drinfo_fdata *fdata;
11542 + char *infoname; /* inside of whname, just after PFX */
11543 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11544 + aufs_bindex_t btgt, btail;
11545 + unsigned char no_sio,
11546 + allocated, /* current size of *fdata */
11547 + infonamelen, /* room size for p */
11548 + whnamelen, /* length of the generated name */
11549 + renameback; /* renamed back */
11552 +/* on rename(2) error, the caller should revert it using @elm */
11553 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11554 + struct au_drinfo_rev_elm *elm)
11559 + struct path infopath = {
11560 + .mnt = w->h_ppath.mnt
11562 + struct inode *h_dir, *h_inode, *delegated;
11563 + struct file *infofile;
11564 + struct qstr *qname;
11567 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11569 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11571 + AuTraceErrPtr(infopath.dentry);
11572 + if (IS_ERR(infopath.dentry)) {
11573 + err = PTR_ERR(infopath.dentry);
11578 + h_dir = d_inode(w->h_ppath.dentry);
11579 + if (elm && d_is_negative(infopath.dentry)) {
11580 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11582 + if (unlikely(err))
11584 + elm->created = 1;
11585 + elm->info_dentry = dget(infopath.dentry);
11588 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11589 + AuTraceErrPtr(infofile);
11590 + if (IS_ERR(infofile)) {
11591 + err = PTR_ERR(infofile);
11595 + h_inode = d_inode(infopath.dentry);
11596 + if (elm && i_size_read(h_inode)) {
11597 + h_inode = d_inode(w->h_dentry);
11598 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11599 + AuTraceErrPtr(elm->info_last);
11600 + if (IS_ERR(elm->info_last)) {
11601 + err = PTR_ERR(elm->info_last);
11602 + elm->info_last = NULL;
11603 + AuDebugOn(elm->info_dentry);
11608 + if (elm && w->renameback) {
11609 + delegated = NULL;
11610 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11612 + if (unlikely(err == -EWOULDBLOCK))
11618 + qname = &w->h_dentry->d_name;
11619 + len = sizeof(*w->fdata) + qname->len;
11621 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11622 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11623 + if (ssz == len) {
11624 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11625 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11626 + goto out_fput; /* success */
11631 + /* the caller should revert it using @elm */
11637 + dput(infopath.dentry);
11643 +struct au_call_drinfo_do_store_args {
11645 + struct au_drinfo_store *w;
11646 + struct au_drinfo_rev_elm *elm;
11649 +static void au_call_drinfo_do_store(void *args)
11651 + struct au_call_drinfo_do_store_args *a = args;
11653 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11656 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11657 + struct au_drinfo_rev_elm *elm)
11659 + int err, wkq_err;
11662 + err = au_drinfo_do_store(w, elm);
11664 + struct au_call_drinfo_do_store_args a = {
11669 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11670 + if (unlikely(wkq_err))
11678 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11679 + aufs_bindex_t btgt)
11683 + memset(w, 0, sizeof(*w));
11684 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11685 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11686 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11687 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11689 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11692 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11693 + if (unlikely(!w->fdata)) {
11697 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11704 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11706 + au_kfree_rcu(w->fdata);
11709 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11710 + struct au_drinfo_store *w)
11712 + struct au_drinfo_rev_elm *elm;
11713 + struct inode *h_dir, *delegated;
11715 + struct path infopath = {
11716 + .mnt = w->h_ppath.mnt
11719 + h_dir = d_inode(w->h_ppath.dentry);
11720 + IMustLock(h_dir);
11724 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11725 + AuDebugOn(elm->created && elm->info_last);
11726 + if (elm->created) {
11728 + delegated = NULL;
11729 + infopath.dentry = elm->info_dentry;
11730 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11733 + if (unlikely(err == -EWOULDBLOCK))
11735 + dput(elm->info_dentry);
11736 + } else if (elm->info_last) {
11738 + w->fdata->drinfo = *elm->info_last;
11739 + memcpy(w->fdata->drinfo.oldname,
11740 + elm->info_last->oldname,
11741 + elm->info_last->oldnamelen);
11742 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11743 + au_kfree_rcu(elm->info_last);
11745 + if (unlikely(err))
11746 + AuIOErr("%d, %s\n", err, w->whname);
11747 + /* go on even if err */
11751 +/* caller has to call au_dr_rename_fin() later */
11752 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11753 + struct qstr *dst_name, void *_rev)
11755 + int err, sz, nelm;
11756 + aufs_bindex_t bindex, btail;
11757 + struct au_drinfo_store work;
11758 + struct au_drinfo_rev *rev, **p;
11759 + struct au_drinfo_rev_elm *elm;
11760 + struct super_block *sb;
11761 + struct au_branch *br;
11762 + struct au_hinode *hdir;
11764 + err = au_drinfo_store_work_init(&work, btgt);
11766 + if (unlikely(err))
11770 + btail = au_dbtaildir(dentry);
11771 + nelm = btail - btgt;
11772 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11773 + rev = kcalloc(1, sz, GFP_NOFS);
11774 + if (unlikely(!rev)) {
11778 + rev->nelm = nelm;
11784 + sb = dentry->d_sb;
11785 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11786 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11787 + hdir = au_hi(d_inode(dentry), btgt);
11788 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11789 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11790 + work.h_dentry = au_h_dptr(dentry, bindex);
11791 + if (!work.h_dentry)
11794 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11795 + &work.allocated);
11797 + if (unlikely(err))
11800 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11801 + br = au_sbr(sb, bindex);
11802 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11803 + work.whnamelen += au_drinfo_name(br, work.infoname,
11804 + work.infonamelen);
11805 + AuDbg("whname %.*s, i%llu, %.*s\n",
11806 + work.whnamelen, work.whname,
11807 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11808 + work.fdata->drinfo.oldnamelen,
11809 + work.fdata->drinfo.oldname);
11811 + err = au_drinfo_store_sio(&work, elm);
11813 + if (unlikely(err))
11816 + if (unlikely(err)) {
11817 + /* revert all drinfo */
11818 + au_drinfo_store_rev(rev, &work);
11819 + au_kfree_try_rcu(rev);
11822 + au_hn_inode_unlock(hdir);
11825 + au_drinfo_store_work_fin(&work);
11830 +/* ---------------------------------------------------------------------- */
11832 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11833 + struct qstr *dst_name, void *_rev)
11835 + int err, already;
11837 + struct super_block *sb;
11838 + struct au_branch *br;
11839 + struct au_dr_br *dr;
11840 + struct dentry *h_dentry;
11841 + struct inode *h_inode;
11842 + struct au_dr_hino *ent;
11843 + struct au_drinfo_rev *rev, **p;
11845 + AuDbg("bindex %d\n", bindex);
11848 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11849 + if (unlikely(!ent))
11853 + br = au_sbr(sb, bindex);
11854 + dr = &br->br_dirren;
11855 + h_dentry = au_h_dptr(src, bindex);
11856 + h_inode = d_inode(h_dentry);
11857 + ino = h_inode->i_ino;
11858 + ent->dr_h_ino = ino;
11859 + already = au_dr_hino_test_add(dr, ino, ent);
11860 + AuDbg("b%d, hi%llu, already %d\n",
11861 + bindex, (unsigned long long)ino, already);
11863 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11868 + rev->already = already;
11869 + goto out; /* success */
11874 + au_dr_hino_del(dr, ent);
11875 + au_kfree_rcu(ent);
11882 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11884 + struct au_drinfo_rev *rev;
11885 + struct au_drinfo_rev_elm *elm;
11890 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11891 + dput(elm->info_dentry);
11892 + au_kfree_rcu(elm->info_last);
11894 + au_kfree_try_rcu(rev);
11897 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11900 + struct au_drinfo_store work;
11901 + struct au_drinfo_rev *rev = _rev;
11902 + struct super_block *sb;
11903 + struct au_branch *br;
11904 + struct inode *h_inode;
11905 + struct au_dr_br *dr;
11906 + struct au_dr_hino *ent;
11908 + err = au_drinfo_store_work_init(&work, btgt);
11909 + if (unlikely(err))
11913 + br = au_sbr(sb, btgt);
11914 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11915 + work.h_ppath.mnt = au_br_mnt(br);
11916 + au_drinfo_store_rev(rev, &work);
11917 + au_drinfo_store_work_fin(&work);
11918 + if (rev->already)
11921 + dr = &br->br_dirren;
11922 + h_inode = d_inode(work.h_ppath.dentry);
11923 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11925 + au_dr_hino_del(dr, ent);
11926 + au_kfree_rcu(ent);
11929 + au_kfree_try_rcu(rev);
11930 + if (unlikely(err))
11931 + pr_err("failed to remove dirren info\n");
11934 +/* ---------------------------------------------------------------------- */
11936 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11937 + char *whname, int whnamelen,
11938 + struct dentry **info_dentry)
11940 + struct au_drinfo *drinfo;
11942 + struct inode *h_dir;
11943 + struct path infopath;
11946 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11948 + *info_dentry = NULL;
11951 + h_dir = d_inode(h_ppath->dentry);
11952 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11953 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
11955 + if (IS_ERR(infopath.dentry)) {
11956 + drinfo = (void *)infopath.dentry;
11960 + if (d_is_negative(infopath.dentry))
11961 + goto out_dput; /* success */
11963 + infopath.mnt = h_ppath->mnt;
11964 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11965 + inode_unlock_shared(h_dir);
11968 + drinfo = (void *)f;
11972 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11973 + if (IS_ERR_OR_NULL(drinfo))
11976 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11977 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11982 + dput(infopath.dentry);
11985 + inode_unlock_shared(h_dir);
11986 + AuTraceErrPtr(drinfo);
11990 +struct au_drinfo_do_load_args {
11991 + struct au_drinfo **drinfop;
11992 + struct path *h_ppath;
11995 + struct dentry **info_dentry;
11998 +static void au_call_drinfo_do_load(void *args)
12000 + struct au_drinfo_do_load_args *a = args;
12002 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
12006 +struct au_drinfo_load {
12007 + struct path h_ppath;
12008 + struct qstr *qname;
12009 + unsigned char no_sio;
12011 + aufs_bindex_t ninfo;
12012 + struct au_drinfo **drinfo;
12015 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
12016 + struct au_branch *br)
12018 + int err, wkq_err, whnamelen, e;
12019 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
12020 + = AUFS_WH_DR_INFO_PFX;
12021 + struct au_drinfo *drinfo;
12022 + struct qstr oldname;
12023 + struct inode *h_dir, *delegated;
12024 + struct dentry *info_dentry;
12025 + struct path infopath;
12027 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
12028 + whnamelen += au_drinfo_name(br, whname + whnamelen,
12029 + sizeof(whname) - whnamelen);
12031 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
12034 + struct au_drinfo_do_load_args args = {
12035 + .drinfop = &drinfo,
12036 + .h_ppath = &w->h_ppath,
12037 + .whname = whname,
12038 + .whnamelen = whnamelen,
12039 + .info_dentry = &info_dentry
12041 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
12042 + if (unlikely(wkq_err))
12043 + drinfo = ERR_PTR(wkq_err);
12045 + err = PTR_ERR(drinfo);
12046 + if (IS_ERR_OR_NULL(drinfo))
12050 + oldname.len = drinfo->oldnamelen;
12051 + oldname.name = drinfo->oldname;
12052 + if (au_qstreq(w->qname, &oldname)) {
12053 + /* the name is renamed back */
12054 + au_kfree_rcu(drinfo);
12057 + infopath.dentry = info_dentry;
12058 + infopath.mnt = w->h_ppath.mnt;
12059 + h_dir = d_inode(w->h_ppath.dentry);
12060 + delegated = NULL;
12061 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
12062 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
12063 + inode_unlock(h_dir);
12065 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
12066 + if (unlikely(e == -EWOULDBLOCK))
12069 + au_kfree_rcu(w->drinfo[bindex]);
12070 + w->drinfo[bindex] = drinfo;
12071 + dput(info_dentry);
12078 +/* ---------------------------------------------------------------------- */
12080 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12082 + struct au_drinfo **p = drinfo;
12085 + au_kfree_rcu(*drinfo++);
12086 + au_kfree_try_rcu(p);
12089 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12090 + aufs_bindex_t btgt)
12093 + struct au_drinfo_load w;
12094 + aufs_bindex_t bindex, bbot;
12095 + struct au_branch *br;
12096 + struct inode *h_dir;
12097 + struct au_dr_hino *ent;
12098 + struct super_block *sb;
12100 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12101 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12102 + AuLNPair(&lkup->whname), btgt);
12104 + sb = dentry->d_sb;
12105 + bbot = au_sbbot(sb);
12106 + w.ninfo = bbot + 1;
12107 + if (!lkup->dirren.drinfo) {
12108 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12109 + sizeof(*lkup->dirren.drinfo),
12111 + if (unlikely(!lkup->dirren.drinfo)) {
12115 + lkup->dirren.ninfo = w.ninfo;
12117 + w.drinfo = lkup->dirren.drinfo;
12118 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12119 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12120 + AuDebugOn(!w.h_ppath.dentry);
12121 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12122 + w.qname = &dentry->d_name;
12125 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12126 + br = au_sbr(sb, bindex);
12127 + err = au_drinfo_load(&w, bindex, br);
12128 + if (unlikely(err))
12130 + if (w.drinfo[bindex])
12134 + br = au_sbr(sb, btgt);
12135 + h_dir = d_inode(w.h_ppath.dentry);
12136 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12138 + au_dr_hino_del(&br->br_dirren, ent);
12139 + au_kfree_rcu(ent);
12141 + goto out; /* success */
12144 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12145 + lkup->dirren.ninfo = 0;
12146 + lkup->dirren.drinfo = NULL;
12152 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12154 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12157 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12160 + struct au_drinfo *drinfo;
12163 + if (!lkup->dirren.drinfo)
12165 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12166 + drinfo = lkup->dirren.drinfo[btgt];
12170 + au_kfree_try_rcu(lkup->whname.name);
12171 + lkup->whname.name = NULL;
12172 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12173 + lkup->dirren.dr_name.name = drinfo->oldname;
12174 + lkup->name = &lkup->dirren.dr_name;
12175 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12177 + AuDbg("name %.*s, whname %.*s, b%d\n",
12178 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12186 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12190 + struct au_drinfo *drinfo;
12193 + if (!lkup->dirren.drinfo)
12195 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12196 + drinfo = lkup->dirren.drinfo[bindex];
12200 + match = (drinfo->ino == h_ino);
12201 + AuDbg("match %d\n", match);
12207 +/* ---------------------------------------------------------------------- */
12209 +int au_dr_opt_set(struct super_block *sb)
12212 + aufs_bindex_t bindex, bbot;
12213 + struct au_branch *br;
12216 + bbot = au_sbbot(sb);
12217 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12218 + br = au_sbr(sb, bindex);
12219 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12225 +int au_dr_opt_flush(struct super_block *sb)
12228 + aufs_bindex_t bindex, bbot;
12229 + struct au_branch *br;
12232 + bbot = au_sbbot(sb);
12233 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12234 + br = au_sbr(sb, bindex);
12235 + if (au_br_writable(br->br_perm))
12236 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12242 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12245 + aufs_bindex_t bindex, bbot;
12246 + struct au_branch *br;
12250 + err = au_dr_opt_flush(sb);
12251 + if (unlikely(err))
12255 + bbot = au_sbbot(sb);
12256 + for (bindex = 0; bindex <= bbot; bindex++) {
12257 + br = au_sbr(sb, bindex);
12258 + au_dr_hino_free(&br->br_dirren);
12264 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12265 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12266 +++ linux/fs/aufs/dirren.h 2020-01-27 10:57:18.168871450 +0100
12268 +/* SPDX-License-Identifier: GPL-2.0 */
12270 + * Copyright (C) 2017-2020 Junjiro R. Okajima
12272 + * This program, aufs is free software; you can redistribute it and/or modify
12273 + * it under the terms of the GNU General Public License as published by
12274 + * the Free Software Foundation; either version 2 of the License, or
12275 + * (at your option) any later version.
12277 + * This program is distributed in the hope that it will be useful,
12278 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12279 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12280 + * GNU General Public License for more details.
12282 + * You should have received a copy of the GNU General Public License
12283 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12287 + * renamed dir info
12290 +#ifndef __AUFS_DIRREN_H__
12291 +#define __AUFS_DIRREN_H__
12295 +#include <linux/dcache.h>
12296 +#include <linux/statfs.h>
12297 +#include <linux/uuid.h>
12300 +#define AuDirren_NHASH 100
12302 +#ifdef CONFIG_AUFS_DIRREN
12303 +enum au_brid_type {
12310 +struct au_dr_brid {
12311 + enum au_brid_type type;
12313 + uuid_t uuid; /* unimplemented yet */
12319 +/* 20 is the max digits length of ulong 64 */
12320 +/* brid-type "_" uuid "_" inum */
12321 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12322 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12324 +struct au_dr_hino {
12325 + struct hlist_bl_node dr_hnode;
12330 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12331 + struct au_dr_brid dr_brid;
12334 +struct au_dr_lookup {
12335 + /* dr_name is pointed by struct au_do_lookup_args.name */
12336 + struct qstr dr_name; /* subset of dr_info */
12337 + aufs_bindex_t ninfo;
12338 + struct au_drinfo **drinfo;
12341 +struct au_dr_hino;
12343 +struct au_dr_br { };
12344 +struct au_dr_lookup { };
12347 +/* ---------------------------------------------------------------------- */
12350 +struct au_do_lookup_args;
12352 +#ifdef CONFIG_AUFS_DIRREN
12353 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12354 + struct au_dr_hino *add_ent);
12355 +void au_dr_hino_free(struct au_dr_br *dr);
12356 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12357 + const struct path *path);
12358 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12359 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12360 + struct qstr *dst_name, void *_rev);
12361 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12362 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12363 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12364 + aufs_bindex_t bindex);
12365 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12366 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12368 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12369 +int au_dr_opt_set(struct super_block *sb);
12370 +int au_dr_opt_flush(struct super_block *sb);
12371 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12373 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12374 + struct au_dr_hino *add_ent);
12375 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12376 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12377 + const struct path *path);
12378 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12379 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12380 + struct qstr *dst_name, void *_rev);
12381 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12382 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12384 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12385 + aufs_bindex_t bindex);
12386 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12387 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12388 + aufs_bindex_t bindex, ino_t h_ino);
12389 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12390 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12391 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12392 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12395 +/* ---------------------------------------------------------------------- */
12397 +#ifdef CONFIG_AUFS_DIRREN
12398 +static inline int au_dr_ihash(ino_t h_ino)
12400 + return h_ino % AuDirren_NHASH;
12403 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12406 +#endif /* __KERNEL__ */
12407 +#endif /* __AUFS_DIRREN_H__ */
12408 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12409 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12410 +++ linux/fs/aufs/dynop.c 2020-01-27 10:57:18.168871450 +0100
12412 +// SPDX-License-Identifier: GPL-2.0
12414 + * Copyright (C) 2010-2020 Junjiro R. Okajima
12416 + * This program, aufs is free software; you can redistribute it and/or modify
12417 + * it under the terms of the GNU General Public License as published by
12418 + * the Free Software Foundation; either version 2 of the License, or
12419 + * (at your option) any later version.
12421 + * This program is distributed in the hope that it will be useful,
12422 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12423 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12424 + * GNU General Public License for more details.
12426 + * You should have received a copy of the GNU General Public License
12427 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12431 + * dynamically customizable operations for regular files
12436 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12439 + * How large will these lists be?
12440 + * Usually just a few elements, 20-30 at most for each, I guess.
12442 +static struct hlist_bl_head dynop[AuDyLast];
12444 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12445 + const void *h_op)
12447 + struct au_dykey *key, *tmp;
12448 + struct hlist_bl_node *pos;
12451 + hlist_bl_lock(hbl);
12452 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12453 + if (tmp->dk_op.dy_hop == h_op) {
12454 + if (kref_get_unless_zero(&tmp->dk_kref))
12458 + hlist_bl_unlock(hbl);
12463 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12465 + struct au_dykey **k, *found;
12466 + const void *h_op = key->dk_op.dy_hop;
12470 + k = br->br_dykey;
12471 + for (i = 0; i < AuBrDynOp; i++)
12473 + if (k[i]->dk_op.dy_hop == h_op) {
12480 + spin_lock(&br->br_dykey_lock);
12481 + for (; i < AuBrDynOp; i++)
12483 + if (k[i]->dk_op.dy_hop == h_op) {
12491 + spin_unlock(&br->br_dykey_lock);
12492 + BUG_ON(i == AuBrDynOp); /* expand the array */
12498 +/* kref_get() if @key is already added */
12499 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12501 + struct au_dykey *tmp, *found;
12502 + struct hlist_bl_node *pos;
12503 + const void *h_op = key->dk_op.dy_hop;
12506 + hlist_bl_lock(hbl);
12507 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12508 + if (tmp->dk_op.dy_hop == h_op) {
12509 + if (kref_get_unless_zero(&tmp->dk_kref))
12514 + hlist_bl_add_head(&key->dk_hnode, hbl);
12515 + hlist_bl_unlock(hbl);
12522 +static void dy_free_rcu(struct rcu_head *rcu)
12524 + struct au_dykey *key;
12526 + key = container_of(rcu, struct au_dykey, dk_rcu);
12531 +static void dy_free(struct kref *kref)
12533 + struct au_dykey *key;
12534 + struct hlist_bl_head *hbl;
12536 + key = container_of(kref, struct au_dykey, dk_kref);
12537 + hbl = dynop + key->dk_op.dy_type;
12538 + au_hbl_del(&key->dk_hnode, hbl);
12539 + call_rcu(&key->dk_rcu, dy_free_rcu);
12542 +void au_dy_put(struct au_dykey *key)
12544 + kref_put(&key->dk_kref, dy_free);
12547 +/* ---------------------------------------------------------------------- */
12549 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12551 +#ifdef CONFIG_AUFS_DEBUG
12552 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12553 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12555 +#define DyDbgDeclare(cnt) do {} while (0)
12556 +#define DyDbgInc(cnt) do {} while (0)
12559 +#define DySet(func, dst, src, h_op, h_sb) do { \
12561 + if (h_op->func) { \
12563 + dst.func = src.func; \
12565 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12569 +#define DySetForce(func, dst, src) do { \
12570 + AuDebugOn(!src.func); \
12572 + dst.func = src.func; \
12575 +#define DySetAop(func) \
12576 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12577 +#define DySetAopForce(func) \
12578 + DySetForce(func, dyaop->da_op, aufs_aop)
12580 +static void dy_aop(struct au_dykey *key, const void *h_op,
12581 + struct super_block *h_sb __maybe_unused)
12583 + struct au_dyaop *dyaop = (void *)key;
12584 + const struct address_space_operations *h_aop = h_op;
12585 + DyDbgDeclare(cnt);
12587 + AuDbg("%s\n", au_sbtype(h_sb));
12589 + DySetAop(writepage);
12590 + DySetAopForce(readpage); /* force */
12591 + DySetAop(writepages);
12592 + DySetAop(set_page_dirty);
12593 + DySetAop(readpages);
12594 + DySetAop(write_begin);
12595 + DySetAop(write_end);
12597 + DySetAop(invalidatepage);
12598 + DySetAop(releasepage);
12599 + DySetAop(freepage);
12600 + /* this one will be changed according to an aufs mount option */
12601 + DySetAop(direct_IO);
12602 + DySetAop(migratepage);
12603 + DySetAop(isolate_page);
12604 + DySetAop(putback_page);
12605 + DySetAop(launder_page);
12606 + DySetAop(is_partially_uptodate);
12607 + DySetAop(is_dirty_writeback);
12608 + DySetAop(error_remove_page);
12609 + DySetAop(swap_activate);
12610 + DySetAop(swap_deactivate);
12612 + DyDbgSize(cnt, *h_aop);
12615 +/* ---------------------------------------------------------------------- */
12617 +static void dy_bug(struct kref *kref)
12622 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12624 + struct au_dykey *key, *old;
12625 + struct hlist_bl_head *hbl;
12628 + void (*set)(struct au_dykey *key, const void *h_op,
12629 + struct super_block *h_sb __maybe_unused);
12631 + static const struct op a[] = {
12633 + .sz = sizeof(struct au_dyaop),
12637 + const struct op *p;
12639 + hbl = dynop + op->dy_type;
12640 + key = dy_gfind_get(hbl, op->dy_hop);
12642 + goto out_add; /* success */
12644 + p = a + op->dy_type;
12645 + key = kzalloc(p->sz, GFP_NOFS);
12646 + if (unlikely(!key)) {
12647 + key = ERR_PTR(-ENOMEM);
12651 + key->dk_op.dy_hop = op->dy_hop;
12652 + kref_init(&key->dk_kref);
12653 + p->set(key, op->dy_hop, au_br_sb(br));
12654 + old = dy_gadd(hbl, key);
12656 + au_kfree_rcu(key);
12661 + old = dy_bradd(br, key);
12663 + /* its ref-count should never be zero here */
12664 + kref_put(&key->dk_kref, dy_bug);
12669 +/* ---------------------------------------------------------------------- */
12671 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12672 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12673 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12674 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12675 + * See the aufs manual in detail.
12677 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12680 + dyaop->da_op.direct_IO = NULL;
12682 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12685 +static struct au_dyaop *dy_aget(struct au_branch *br,
12686 + const struct address_space_operations *h_aop,
12689 + struct au_dyaop *dyaop;
12690 + struct au_dynop op;
12692 + op.dy_type = AuDy_AOP;
12693 + op.dy_haop = h_aop;
12694 + dyaop = (void *)dy_get(&op, br);
12695 + if (IS_ERR(dyaop))
12697 + dy_adx(dyaop, do_dx);
12703 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12704 + struct inode *h_inode)
12707 + struct super_block *sb;
12708 + struct au_branch *br;
12709 + struct au_dyaop *dyaop;
12711 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12712 + IiMustWriteLock(inode);
12714 + sb = inode->i_sb;
12715 + br = au_sbr(sb, bindex);
12716 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12717 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12718 + err = PTR_ERR(dyaop);
12719 + if (IS_ERR(dyaop))
12720 + /* unnecessary to call dy_fput() */
12724 + inode->i_mapping->a_ops = &dyaop->da_op;
12731 + * Is it safe to replace a_ops during the inode/file is in operation?
12732 + * Yes, I hope so.
12734 +int au_dy_irefresh(struct inode *inode)
12737 + aufs_bindex_t btop;
12738 + struct inode *h_inode;
12741 + if (S_ISREG(inode->i_mode)) {
12742 + btop = au_ibtop(inode);
12743 + h_inode = au_h_iptr(inode, btop);
12744 + err = au_dy_iaop(inode, btop, h_inode);
12749 +void au_dy_arefresh(int do_dx)
12751 + struct hlist_bl_head *hbl;
12752 + struct hlist_bl_node *pos;
12753 + struct au_dykey *key;
12755 + hbl = dynop + AuDy_AOP;
12756 + hlist_bl_lock(hbl);
12757 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12758 + dy_adx((void *)key, do_dx);
12759 + hlist_bl_unlock(hbl);
12762 +/* ---------------------------------------------------------------------- */
12764 +void __init au_dy_init(void)
12768 + for (i = 0; i < AuDyLast; i++)
12769 + INIT_HLIST_BL_HEAD(dynop + i);
12772 +void au_dy_fin(void)
12776 + for (i = 0; i < AuDyLast; i++)
12777 + WARN_ON(!hlist_bl_empty(dynop + i));
12779 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12780 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12781 +++ linux/fs/aufs/dynop.h 2020-01-27 10:57:18.168871450 +0100
12783 +/* SPDX-License-Identifier: GPL-2.0 */
12785 + * Copyright (C) 2010-2020 Junjiro R. Okajima
12787 + * This program, aufs is free software; you can redistribute it and/or modify
12788 + * it under the terms of the GNU General Public License as published by
12789 + * the Free Software Foundation; either version 2 of the License, or
12790 + * (at your option) any later version.
12792 + * This program is distributed in the hope that it will be useful,
12793 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12794 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12795 + * GNU General Public License for more details.
12797 + * You should have received a copy of the GNU General Public License
12798 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12802 + * dynamically customizable operations (for regular files only)
12805 +#ifndef __AUFS_DYNOP_H__
12806 +#define __AUFS_DYNOP_H__
12810 +#include <linux/fs.h>
12811 +#include <linux/kref.h>
12813 +enum {AuDy_AOP, AuDyLast};
12818 + const void *dy_hop;
12819 + const struct address_space_operations *dy_haop;
12825 + struct hlist_bl_node dk_hnode;
12826 + struct rcu_head dk_rcu;
12828 + struct au_dynop dk_op;
12831 + * during I am in the branch local array, kref is gotten. when the
12832 + * branch is removed, kref is put.
12834 + struct kref dk_kref;
12837 +/* stop unioning since their sizes are very different from each other */
12839 + struct au_dykey da_key;
12840 + struct address_space_operations da_op; /* not const */
12842 +/* make sure that 'struct au_dykey *' can be any type */
12843 +static_assert(!offsetof(struct au_dyaop, da_key));
12845 +/* ---------------------------------------------------------------------- */
12849 +void au_dy_put(struct au_dykey *key);
12850 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12851 + struct inode *h_inode);
12852 +int au_dy_irefresh(struct inode *inode);
12853 +void au_dy_arefresh(int do_dio);
12855 +void __init au_dy_init(void);
12856 +void au_dy_fin(void);
12858 +#endif /* __KERNEL__ */
12859 +#endif /* __AUFS_DYNOP_H__ */
12860 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12861 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12862 +++ linux/fs/aufs/export.c 2020-01-27 10:57:18.168871450 +0100
12864 +// SPDX-License-Identifier: GPL-2.0
12866 + * Copyright (C) 2005-2020 Junjiro R. Okajima
12868 + * This program, aufs is free software; you can redistribute it and/or modify
12869 + * it under the terms of the GNU General Public License as published by
12870 + * the Free Software Foundation; either version 2 of the License, or
12871 + * (at your option) any later version.
12873 + * This program is distributed in the hope that it will be useful,
12874 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12875 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12876 + * GNU General Public License for more details.
12878 + * You should have received a copy of the GNU General Public License
12879 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12886 +#include <linux/exportfs.h>
12887 +#include <linux/fs_struct.h>
12888 +#include <linux/namei.h>
12889 +#include <linux/nsproxy.h>
12890 +#include <linux/random.h>
12891 +#include <linux/writeback.h>
12895 +#ifdef CONFIG_AUFS_INO_T_64
12903 +static ino_t decode_ino(__u32 *a)
12907 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12909 +#ifdef CONFIG_AUFS_INO_T_64
12915 +static void encode_ino(__u32 *a, ino_t ino)
12921 +#ifdef CONFIG_AUFS_INO_T_64
12926 +/* NFS file handle */
12930 +#ifdef CONFIG_AUFS_INO_T_64
12931 + /* support 64bit inode number */
12944 + Fh_ino = Fh_ino1,
12945 + Fh_dir_ino = Fh_dir_ino1
12948 +static int au_test_anon(struct dentry *dentry)
12950 + /* note: read d_flags without d_lock */
12951 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12954 +int au_test_nfsd(void)
12957 + struct task_struct *tsk = current;
12958 + char comm[sizeof(tsk->comm)];
12961 + if (tsk->flags & PF_KTHREAD) {
12962 + get_task_comm(comm, tsk);
12963 + ret = !strcmp(comm, "nfsd");
12969 +/* ---------------------------------------------------------------------- */
12970 +/* inode generation external table */
12972 +void au_xigen_inc(struct inode *inode)
12977 + struct super_block *sb;
12978 + struct au_sbinfo *sbinfo;
12980 + sb = inode->i_sb;
12981 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12983 + sbinfo = au_sbi(sb);
12984 + pos = inode->i_ino;
12985 + pos *= sizeof(igen);
12986 + igen = inode->i_generation + 1;
12987 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
12988 + sizeof(igen), &pos);
12989 + if (sz == sizeof(igen))
12990 + return; /* success */
12992 + if (unlikely(sz >= 0))
12993 + AuIOErr("xigen error (%zd)\n", sz);
12996 +int au_xigen_new(struct inode *inode)
13001 + struct super_block *sb;
13002 + struct au_sbinfo *sbinfo;
13003 + struct file *file;
13006 + /* todo: dirty, at mount time */
13007 + if (inode->i_ino == AUFS_ROOT_INO)
13009 + sb = inode->i_sb;
13010 + SiMustAnyLock(sb);
13011 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13015 + pos = inode->i_ino;
13016 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
13017 + AuIOErr1("too large i%lld\n", pos);
13020 + pos *= sizeof(inode->i_generation);
13023 + sbinfo = au_sbi(sb);
13024 + file = sbinfo->si_xigen;
13027 + if (vfsub_f_size_read(file)
13028 + < pos + sizeof(inode->i_generation)) {
13029 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
13030 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
13031 + sizeof(inode->i_generation), &pos);
13033 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
13034 + sizeof(inode->i_generation), &pos);
13035 + if (sz == sizeof(inode->i_generation))
13036 + goto out; /* success */
13039 + if (unlikely(sz >= 0)) {
13041 + AuIOErr("xigen error (%zd)\n", sz);
13048 +int au_xigen_set(struct super_block *sb, struct path *path)
13051 + struct au_sbinfo *sbinfo;
13052 + struct file *file;
13054 + SiMustWriteLock(sb);
13056 + sbinfo = au_sbi(sb);
13057 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
13058 + err = PTR_ERR(file);
13059 + if (IS_ERR(file))
13062 + if (sbinfo->si_xigen)
13063 + fput(sbinfo->si_xigen);
13064 + sbinfo->si_xigen = file;
13071 +void au_xigen_clr(struct super_block *sb)
13073 + struct au_sbinfo *sbinfo;
13075 + SiMustWriteLock(sb);
13077 + sbinfo = au_sbi(sb);
13078 + if (sbinfo->si_xigen) {
13079 + fput(sbinfo->si_xigen);
13080 + sbinfo->si_xigen = NULL;
13084 +/* ---------------------------------------------------------------------- */
13086 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13089 + struct dentry *dentry, *d;
13090 + struct inode *inode;
13091 + unsigned int sigen;
13094 + inode = ilookup(sb, ino);
13098 + dentry = ERR_PTR(-ESTALE);
13099 + sigen = au_sigen(sb);
13100 + if (unlikely(au_is_bad_inode(inode)
13101 + || IS_DEADDIR(inode)
13102 + || sigen != au_iigen(inode, NULL)))
13106 + if (!dir_ino || S_ISDIR(inode->i_mode))
13107 + dentry = d_find_alias(inode);
13109 + spin_lock(&inode->i_lock);
13110 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13111 + spin_lock(&d->d_lock);
13112 + if (!au_test_anon(d)
13113 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13114 + dentry = dget_dlock(d);
13115 + spin_unlock(&d->d_lock);
13118 + spin_unlock(&d->d_lock);
13120 + spin_unlock(&inode->i_lock);
13122 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13123 + /* need to refresh */
13131 + AuTraceErrPtr(dentry);
13135 +/* ---------------------------------------------------------------------- */
13137 +/* todo: dirty? */
13138 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13140 +struct au_compare_mnt_args {
13142 + struct super_block *sb;
13145 + struct vfsmount *mnt;
13148 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13150 + struct au_compare_mnt_args *a = arg;
13152 + if (mnt->mnt_sb != a->sb)
13154 + a->mnt = mntget(mnt);
13158 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13161 + struct path root;
13162 + struct au_compare_mnt_args args = {
13166 + get_fs_root(current->fs, &root);
13168 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13169 + rcu_read_unlock();
13172 + AuDebugOn(!args.mnt);
13176 +struct au_nfsd_si_lock {
13177 + unsigned int sigen;
13178 + aufs_bindex_t bindex, br_id;
13179 + unsigned char force_lock;
13182 +static int si_nfsd_read_lock(struct super_block *sb,
13183 + struct au_nfsd_si_lock *nsi_lock)
13186 + aufs_bindex_t bindex;
13188 + si_read_lock(sb, AuLock_FLUSH);
13190 + /* branch id may be wrapped around */
13192 + bindex = au_br_index(sb, nsi_lock->br_id);
13193 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13194 + goto out; /* success */
13198 + if (!nsi_lock->force_lock)
13199 + si_read_unlock(sb);
13202 + nsi_lock->bindex = bindex;
13206 +struct find_name_by_ino {
13207 + struct dir_context ctx;
13208 + int called, found;
13215 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13216 + loff_t offset, u64 ino, unsigned int d_type)
13218 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13222 + if (a->ino != ino)
13225 + memcpy(a->name, name, namelen);
13226 + a->namelen = namelen;
13231 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13232 + struct au_nfsd_si_lock *nsi_lock)
13234 + struct dentry *dentry, *parent;
13235 + struct file *file;
13236 + struct inode *dir;
13237 + struct find_name_by_ino arg = {
13239 + .actor = find_name_by_ino
13244 + parent = path->dentry;
13246 + si_read_unlock(parent->d_sb);
13247 + file = vfsub_dentry_open(path, au_dir_roflags);
13248 + dentry = (void *)file;
13249 + if (IS_ERR(file))
13252 + dentry = ERR_PTR(-ENOMEM);
13253 + arg.name = (void *)__get_free_page(GFP_NOFS);
13254 + if (unlikely(!arg.name))
13261 + err = vfsub_iterate_dir(file, &arg.ctx);
13262 + } while (!err && !arg.found && arg.called);
13263 + dentry = ERR_PTR(err);
13264 + if (unlikely(err))
13266 + /* instead of ENOENT */
13267 + dentry = ERR_PTR(-ESTALE);
13271 + /* do not call vfsub_lkup_one() */
13272 + dir = d_inode(parent);
13273 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13274 + AuTraceErrPtr(dentry);
13275 + if (IS_ERR(dentry))
13277 + AuDebugOn(au_test_anon(dentry));
13278 + if (unlikely(d_really_is_negative(dentry))) {
13280 + dentry = ERR_PTR(-ENOENT);
13284 + free_page((unsigned long)arg.name);
13288 + if (unlikely(nsi_lock
13289 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13290 + if (!IS_ERR(dentry)) {
13292 + dentry = ERR_PTR(-ESTALE);
13294 + AuTraceErrPtr(dentry);
13298 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13300 + struct au_nfsd_si_lock *nsi_lock)
13302 + struct dentry *dentry;
13303 + struct path path;
13305 + if (dir_ino != AUFS_ROOT_INO) {
13306 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13307 + dentry = path.dentry;
13308 + if (!path.dentry || IS_ERR(path.dentry))
13310 + AuDebugOn(au_test_anon(path.dentry));
13312 + path.dentry = dget(sb->s_root);
13314 + path.mnt = au_mnt_get(sb);
13315 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13319 + AuTraceErrPtr(dentry);
13323 +/* ---------------------------------------------------------------------- */
13325 +static int h_acceptable(void *expv, struct dentry *dentry)
13330 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13331 + char *buf, int len, struct super_block *sb)
13335 + struct path path;
13337 + p = d_path(h_rootpath, buf, len);
13342 + path.mnt = h_rootpath->mnt;
13343 + path.dentry = h_parent;
13344 + p = d_path(&path, buf, len);
13350 + path.mnt = au_mnt_get(sb);
13351 + path.dentry = sb->s_root;
13352 + p = d_path(&path, buf, len - strlen(p));
13353 + mntput(path.mnt);
13357 + p[strlen(p)] = '/';
13360 + AuTraceErrPtr(p);
13365 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13366 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13368 + struct dentry *dentry, *h_parent, *root;
13369 + struct super_block *h_sb;
13370 + char *pathname, *p;
13371 + struct vfsmount *h_mnt;
13372 + struct au_branch *br;
13374 + struct path path;
13376 + br = au_sbr(sb, nsi_lock->bindex);
13377 + h_mnt = au_br_mnt(br);
13378 + h_sb = h_mnt->mnt_sb;
13379 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13381 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13382 + fh_len - Fh_tail, fh[Fh_h_type],
13383 + h_acceptable, /*context*/NULL);
13385 + dentry = h_parent;
13386 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13387 + AuWarn1("%s decode_fh failed, %ld\n",
13388 + au_sbtype(h_sb), PTR_ERR(h_parent));
13392 + if (unlikely(au_test_anon(h_parent))) {
13393 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13394 + au_sbtype(h_sb));
13395 + goto out_h_parent;
13398 + dentry = ERR_PTR(-ENOMEM);
13399 + pathname = (void *)__get_free_page(GFP_NOFS);
13400 + if (unlikely(!pathname))
13401 + goto out_h_parent;
13403 + root = sb->s_root;
13404 + path.mnt = h_mnt;
13405 + di_read_lock_parent(root, !AuLock_IR);
13406 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13407 + di_read_unlock(root, !AuLock_IR);
13408 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13409 + dentry = (void *)p;
13411 + goto out_pathname;
13413 + si_read_unlock(sb);
13414 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13415 + dentry = ERR_PTR(err);
13416 + if (unlikely(err))
13419 + dentry = ERR_PTR(-ENOENT);
13420 + AuDebugOn(au_test_anon(path.dentry));
13421 + if (unlikely(d_really_is_negative(path.dentry)))
13424 + if (ino != d_inode(path.dentry)->i_ino)
13425 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13427 + dentry = dget(path.dentry);
13432 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13433 + if (!IS_ERR(dentry)) {
13435 + dentry = ERR_PTR(-ESTALE);
13438 + free_page((unsigned long)pathname);
13442 + AuTraceErrPtr(dentry);
13446 +/* ---------------------------------------------------------------------- */
13448 +static struct dentry *
13449 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13452 + struct dentry *dentry;
13453 + __u32 *fh = fid->raw;
13454 + struct au_branch *br;
13455 + ino_t ino, dir_ino;
13456 + struct au_nfsd_si_lock nsi_lock = {
13460 + dentry = ERR_PTR(-ESTALE);
13461 + /* it should never happen, but the file handle is unreliable */
13462 + if (unlikely(fh_len < Fh_tail))
13464 + nsi_lock.sigen = fh[Fh_sigen];
13465 + nsi_lock.br_id = fh[Fh_br_id];
13467 + /* branch id may be wrapped around */
13469 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13471 + nsi_lock.force_lock = 1;
13473 + /* is this inode still cached? */
13474 + ino = decode_ino(fh + Fh_ino);
13475 + /* it should never happen */
13476 + if (unlikely(ino == AUFS_ROOT_INO))
13479 + dir_ino = decode_ino(fh + Fh_dir_ino);
13480 + dentry = decode_by_ino(sb, ino, dir_ino);
13481 + if (IS_ERR(dentry))
13486 + /* is the parent dir cached? */
13487 + br = au_sbr(sb, nsi_lock.bindex);
13488 + au_lcnt_inc(&br->br_nfiles);
13489 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13490 + if (IS_ERR(dentry))
13495 + /* lookup path */
13496 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13497 + if (IS_ERR(dentry))
13499 + if (unlikely(!dentry))
13500 + /* todo?: make it ESTALE */
13504 + if (!au_digen_test(dentry, au_sigen(sb))
13505 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13506 + goto out_unlock; /* success */
13509 + dentry = ERR_PTR(-ESTALE);
13512 + au_lcnt_dec(&br->br_nfiles);
13513 + si_read_unlock(sb);
13515 + AuTraceErrPtr(dentry);
13519 +#if 0 /* reserved for future use */
13520 +/* support subtreecheck option */
13521 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13522 + int fh_len, int fh_type)
13524 + struct dentry *parent;
13525 + __u32 *fh = fid->raw;
13528 + dir_ino = decode_ino(fh + Fh_dir_ino);
13529 + parent = decode_by_ino(sb, dir_ino, 0);
13530 + if (IS_ERR(parent))
13533 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13534 + dir_ino, fh, fh_len);
13537 + AuTraceErrPtr(parent);
13542 +/* ---------------------------------------------------------------------- */
13544 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13545 + struct inode *dir)
13548 + aufs_bindex_t bindex;
13549 + struct super_block *sb, *h_sb;
13550 + struct dentry *dentry, *parent, *h_parent;
13551 + struct inode *h_dir;
13552 + struct au_branch *br;
13555 + if (unlikely(*max_len <= Fh_tail)) {
13556 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13560 + err = FILEID_ROOT;
13561 + if (inode->i_ino == AUFS_ROOT_INO) {
13562 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13567 + sb = inode->i_sb;
13568 + err = si_read_lock(sb, AuLock_FLUSH);
13569 + if (unlikely(err))
13572 +#ifdef CONFIG_AUFS_DEBUG
13573 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13574 + AuWarn1("NFS-exporting requires xino\n");
13578 + ii_read_lock_child(inode);
13579 + bindex = au_ibtop(inode);
13581 + dentry = d_find_any_alias(inode);
13582 + if (unlikely(!dentry))
13584 + AuDebugOn(au_test_anon(dentry));
13585 + parent = dget_parent(dentry);
13587 + if (unlikely(!parent))
13589 + if (d_really_is_positive(parent))
13590 + dir = d_inode(parent);
13593 + ii_read_lock_parent(dir);
13594 + h_dir = au_h_iptr(dir, bindex);
13595 + ii_read_unlock(dir);
13596 + if (unlikely(!h_dir))
13598 + h_parent = d_find_any_alias(h_dir);
13599 + if (unlikely(!h_parent))
13600 + goto out_hparent;
13603 + br = au_sbr(sb, bindex);
13604 + h_sb = au_br_sb(br);
13605 + if (unlikely(!h_sb->s_export_op)) {
13606 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13607 + goto out_hparent;
13610 + fh[Fh_br_id] = br->br_id;
13611 + fh[Fh_sigen] = au_sigen(sb);
13612 + encode_ino(fh + Fh_ino, inode->i_ino);
13613 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13614 + fh[Fh_igen] = inode->i_generation;
13616 + *max_len -= Fh_tail;
13617 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13619 + /*connectable or subtreecheck*/0);
13620 + err = fh[Fh_h_type];
13621 + *max_len += Fh_tail;
13622 + /* todo: macros? */
13623 + if (err != FILEID_INVALID)
13626 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13633 + ii_read_unlock(inode);
13634 + si_read_unlock(sb);
13636 + if (unlikely(err < 0))
13637 + err = FILEID_INVALID;
13641 +/* ---------------------------------------------------------------------- */
13643 +static int aufs_commit_metadata(struct inode *inode)
13646 + aufs_bindex_t bindex;
13647 + struct super_block *sb;
13648 + struct inode *h_inode;
13649 + int (*f)(struct inode *inode);
13651 + sb = inode->i_sb;
13652 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13653 + ii_write_lock_child(inode);
13654 + bindex = au_ibtop(inode);
13655 + AuDebugOn(bindex < 0);
13656 + h_inode = au_h_iptr(inode, bindex);
13658 + f = h_inode->i_sb->s_export_op->commit_metadata;
13660 + err = f(h_inode);
13662 + struct writeback_control wbc = {
13663 + .sync_mode = WB_SYNC_ALL,
13664 + .nr_to_write = 0 /* metadata only */
13667 + err = sync_inode(h_inode, &wbc);
13670 + au_cpup_attr_timesizes(inode);
13671 + ii_write_unlock(inode);
13672 + si_read_unlock(sb);
13676 +/* ---------------------------------------------------------------------- */
13678 +static struct export_operations aufs_export_op = {
13679 + .fh_to_dentry = aufs_fh_to_dentry,
13680 + /* .fh_to_parent = aufs_fh_to_parent, */
13681 + .encode_fh = aufs_encode_fh,
13682 + .commit_metadata = aufs_commit_metadata
13685 +void au_export_init(struct super_block *sb)
13687 + struct au_sbinfo *sbinfo;
13690 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13691 + && IS_MODULE(CONFIG_EXPORTFS),
13692 + AUFS_NAME ": unsupported configuration "
13693 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13695 + sb->s_export_op = &aufs_export_op;
13696 + sbinfo = au_sbi(sb);
13697 + sbinfo->si_xigen = NULL;
13698 + get_random_bytes(&u, sizeof(u));
13699 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13700 + atomic_set(&sbinfo->si_xigen_next, u);
13702 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13703 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13704 +++ linux/fs/aufs/fhsm.c 2020-01-27 10:57:18.172204883 +0100
13706 +// SPDX-License-Identifier: GPL-2.0
13708 + * Copyright (C) 2011-2020 Junjiro R. Okajima
13710 + * This program, aufs is free software; you can redistribute it and/or modify
13711 + * it under the terms of the GNU General Public License as published by
13712 + * the Free Software Foundation; either version 2 of the License, or
13713 + * (at your option) any later version.
13715 + * This program is distributed in the hope that it will be useful,
13716 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13717 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13718 + * GNU General Public License for more details.
13720 + * You should have received a copy of the GNU General Public License
13721 + * along with this program; if not, write to the Free Software
13722 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13726 + * File-based Hierarchy Storage Management
13729 +#include <linux/anon_inodes.h>
13730 +#include <linux/poll.h>
13731 +#include <linux/seq_file.h>
13732 +#include <linux/statfs.h>
13735 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13737 + struct au_sbinfo *sbinfo;
13738 + struct au_fhsm *fhsm;
13740 + SiMustAnyLock(sb);
13742 + sbinfo = au_sbi(sb);
13743 + fhsm = &sbinfo->si_fhsm;
13744 + AuDebugOn(!fhsm);
13745 + return fhsm->fhsm_bottom;
13748 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13750 + struct au_sbinfo *sbinfo;
13751 + struct au_fhsm *fhsm;
13753 + SiMustWriteLock(sb);
13755 + sbinfo = au_sbi(sb);
13756 + fhsm = &sbinfo->si_fhsm;
13757 + AuDebugOn(!fhsm);
13758 + fhsm->fhsm_bottom = bindex;
13761 +/* ---------------------------------------------------------------------- */
13763 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13765 + struct au_br_fhsm *bf;
13767 + bf = br->br_fhsm;
13768 + MtxMustLock(&bf->bf_lock);
13770 + return !bf->bf_readable
13771 + || time_after(jiffies,
13772 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13775 +/* ---------------------------------------------------------------------- */
13777 +static void au_fhsm_notify(struct super_block *sb, int val)
13779 + struct au_sbinfo *sbinfo;
13780 + struct au_fhsm *fhsm;
13782 + SiMustAnyLock(sb);
13784 + sbinfo = au_sbi(sb);
13785 + fhsm = &sbinfo->si_fhsm;
13786 + if (au_fhsm_pid(fhsm)
13787 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13788 + atomic_set(&fhsm->fhsm_readable, val);
13790 + wake_up(&fhsm->fhsm_wqh);
13794 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13795 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13798 + struct au_branch *br;
13799 + struct au_br_fhsm *bf;
13801 + br = au_sbr(sb, bindex);
13802 + AuDebugOn(au_br_rdonly(br));
13803 + bf = br->br_fhsm;
13807 + mutex_lock(&bf->bf_lock);
13809 + MtxMustLock(&bf->bf_lock);
13811 + /* sb->s_root for NFS is unreliable */
13812 + err = au_br_stfs(br, &bf->bf_stfs);
13813 + if (unlikely(err)) {
13814 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13818 + bf->bf_jiffy = jiffies;
13819 + bf->bf_readable = 1;
13821 + au_fhsm_notify(sb, /*val*/1);
13823 + *rstfs = bf->bf_stfs;
13827 + mutex_unlock(&bf->bf_lock);
13828 + au_fhsm_notify(sb, /*val*/1);
13833 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13836 + struct au_sbinfo *sbinfo;
13837 + struct au_fhsm *fhsm;
13838 + struct au_branch *br;
13839 + struct au_br_fhsm *bf;
13841 + AuDbg("b%d, force %d\n", bindex, force);
13842 + SiMustAnyLock(sb);
13844 + sbinfo = au_sbi(sb);
13845 + fhsm = &sbinfo->si_fhsm;
13846 + if (!au_ftest_si(sbinfo, FHSM)
13847 + || fhsm->fhsm_bottom == bindex)
13850 + br = au_sbr(sb, bindex);
13851 + bf = br->br_fhsm;
13853 + mutex_lock(&bf->bf_lock);
13855 + || au_fhsm_pid(fhsm)
13856 + || au_fhsm_test_jiffy(sbinfo, br))
13857 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13859 + mutex_unlock(&bf->bf_lock);
13862 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13864 + aufs_bindex_t bindex, bbot;
13865 + struct au_branch *br;
13867 + /* exclude the bottom */
13868 + bbot = au_fhsm_bottom(sb);
13869 + for (bindex = 0; bindex < bbot; bindex++) {
13870 + br = au_sbr(sb, bindex);
13871 + if (au_br_fhsm(br->br_perm))
13872 + au_fhsm_wrote(sb, bindex, force);
13876 +/* ---------------------------------------------------------------------- */
13878 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13881 + struct au_sbinfo *sbinfo;
13882 + struct au_fhsm *fhsm;
13885 + sbinfo = file->private_data;
13886 + fhsm = &sbinfo->si_fhsm;
13887 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13888 + if (atomic_read(&fhsm->fhsm_readable))
13889 + mask = EPOLLIN /* | EPOLLRDNORM */;
13892 + AuDbg("mask 0x%x\n", mask);
13896 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13897 + struct aufs_stfs *stfs, __s16 brid)
13901 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13903 + err = __put_user(brid, &stbr->brid);
13904 + if (unlikely(err))
13910 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13911 + struct aufs_stbr __user *stbr, size_t count)
13915 + aufs_bindex_t bindex, bbot;
13916 + struct au_branch *br;
13917 + struct au_br_fhsm *bf;
13919 + /* except the bottom branch */
13922 + bbot = au_fhsm_bottom(sb);
13923 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13924 + br = au_sbr(sb, bindex);
13925 + if (!au_br_fhsm(br->br_perm))
13928 + bf = br->br_fhsm;
13929 + mutex_lock(&bf->bf_lock);
13930 + if (bf->bf_readable) {
13932 + if (count >= sizeof(*stbr))
13933 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13936 + bf->bf_readable = 0;
13937 + count -= sizeof(*stbr);
13941 + mutex_unlock(&bf->bf_lock);
13944 + err = sizeof(*stbr) * nstbr;
13949 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13954 + aufs_bindex_t nfhsm, bindex, bbot;
13955 + struct au_sbinfo *sbinfo;
13956 + struct au_fhsm *fhsm;
13957 + struct au_branch *br;
13958 + struct super_block *sb;
13961 + sbinfo = file->private_data;
13962 + fhsm = &sbinfo->si_fhsm;
13964 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13965 + if (!atomic_read(&fhsm->fhsm_readable)) {
13966 + if (vfsub_file_flags(file) & O_NONBLOCK)
13969 + err = wait_event_interruptible_locked_irq
13971 + atomic_read(&fhsm->fhsm_readable));
13973 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13974 + if (unlikely(err))
13977 + /* sb may already be dead */
13978 + au_rw_read_lock(&sbinfo->si_rwsem);
13979 + readable = atomic_read(&fhsm->fhsm_readable);
13980 + if (readable > 0) {
13981 + sb = sbinfo->si_sb;
13983 + /* exclude the bottom branch */
13985 + bbot = au_fhsm_bottom(sb);
13986 + for (bindex = 0; bindex < bbot; bindex++) {
13987 + br = au_sbr(sb, bindex);
13988 + if (au_br_fhsm(br->br_perm))
13992 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13993 + atomic_set(&fhsm->fhsm_readable, 0);
13994 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13998 + au_rw_read_unlock(&sbinfo->si_rwsem);
14006 +static int au_fhsm_release(struct inode *inode, struct file *file)
14008 + struct au_sbinfo *sbinfo;
14009 + struct au_fhsm *fhsm;
14011 + /* sb may already be dead */
14012 + sbinfo = file->private_data;
14013 + fhsm = &sbinfo->si_fhsm;
14014 + spin_lock(&fhsm->fhsm_spin);
14015 + fhsm->fhsm_pid = 0;
14016 + spin_unlock(&fhsm->fhsm_spin);
14017 + kobject_put(&sbinfo->si_kobj);
14022 +static const struct file_operations au_fhsm_fops = {
14023 + .owner = THIS_MODULE,
14024 + .llseek = noop_llseek,
14025 + .read = au_fhsm_read,
14026 + .poll = au_fhsm_poll,
14027 + .release = au_fhsm_release
14030 +int au_fhsm_fd(struct super_block *sb, int oflags)
14033 + struct au_sbinfo *sbinfo;
14034 + struct au_fhsm *fhsm;
14037 + if (unlikely(!capable(CAP_SYS_ADMIN)))
14041 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
14045 + sbinfo = au_sbi(sb);
14046 + fhsm = &sbinfo->si_fhsm;
14047 + spin_lock(&fhsm->fhsm_spin);
14048 + if (!fhsm->fhsm_pid)
14049 + fhsm->fhsm_pid = current->pid;
14052 + spin_unlock(&fhsm->fhsm_spin);
14053 + if (unlikely(err))
14056 + oflags |= O_RDONLY;
14057 + /* oflags |= FMODE_NONOTIFY; */
14058 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
14060 + if (unlikely(fd < 0))
14063 + /* succeed regardless 'fhsm' status */
14064 + kobject_get(&sbinfo->si_kobj);
14065 + si_noflush_read_lock(sb);
14066 + if (au_ftest_si(sbinfo, FHSM))
14067 + au_fhsm_wrote_all(sb, /*force*/0);
14068 + si_read_unlock(sb);
14069 + goto out; /* success */
14072 + spin_lock(&fhsm->fhsm_spin);
14073 + fhsm->fhsm_pid = 0;
14074 + spin_unlock(&fhsm->fhsm_spin);
14080 +/* ---------------------------------------------------------------------- */
14082 +int au_fhsm_br_alloc(struct au_branch *br)
14087 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14089 + au_br_fhsm_init(br->br_fhsm);
14096 +/* ---------------------------------------------------------------------- */
14098 +void au_fhsm_fin(struct super_block *sb)
14100 + au_fhsm_notify(sb, /*val*/-1);
14103 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14105 + struct au_fhsm *fhsm;
14107 + fhsm = &sbinfo->si_fhsm;
14108 + spin_lock_init(&fhsm->fhsm_spin);
14109 + init_waitqueue_head(&fhsm->fhsm_wqh);
14110 + atomic_set(&fhsm->fhsm_readable, 0);
14111 + fhsm->fhsm_expire
14112 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14113 + fhsm->fhsm_bottom = -1;
14116 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14118 + sbinfo->si_fhsm.fhsm_expire
14119 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14122 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14126 + if (!au_ftest_si(sbinfo, FHSM))
14129 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14130 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14131 + seq_printf(seq, ",fhsm_sec=%u", u);
14133 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14134 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14135 +++ linux/fs/aufs/file.c 2020-01-27 10:57:18.172204883 +0100
14137 +// SPDX-License-Identifier: GPL-2.0
14139 + * Copyright (C) 2005-2020 Junjiro R. Okajima
14141 + * This program, aufs is free software; you can redistribute it and/or modify
14142 + * it under the terms of the GNU General Public License as published by
14143 + * the Free Software Foundation; either version 2 of the License, or
14144 + * (at your option) any later version.
14146 + * This program is distributed in the hope that it will be useful,
14147 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14148 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14149 + * GNU General Public License for more details.
14151 + * You should have received a copy of the GNU General Public License
14152 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14156 + * handling file/dir, and address_space operation
14159 +#ifdef CONFIG_AUFS_DEBUG
14160 +#include <linux/migrate.h>
14162 +#include <linux/pagemap.h>
14165 +/* drop flags for writing */
14166 +unsigned int au_file_roflags(unsigned int flags)
14168 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14169 + flags |= O_RDONLY | O_NOATIME;
14173 +/* common functions to regular file and dir */
14174 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14175 + struct file *file, int force_wr)
14177 + struct file *h_file;
14178 + struct dentry *h_dentry;
14179 + struct inode *h_inode;
14180 + struct super_block *sb;
14181 + struct au_branch *br;
14182 + struct path h_path;
14185 + /* a race condition can happen between open and unlink/rmdir */
14186 + h_file = ERR_PTR(-ENOENT);
14187 + h_dentry = au_h_dptr(dentry, bindex);
14188 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14190 + h_inode = d_inode(h_dentry);
14191 + spin_lock(&h_dentry->d_lock);
14192 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14193 + /* || !d_inode(dentry)->i_nlink */
14195 + spin_unlock(&h_dentry->d_lock);
14196 + if (unlikely(err))
14199 + sb = dentry->d_sb;
14200 + br = au_sbr(sb, bindex);
14201 + err = au_br_test_oflag(flags, br);
14202 + h_file = ERR_PTR(err);
14203 + if (unlikely(err))
14206 + /* drop flags for writing */
14207 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14208 + if (force_wr && !(flags & O_WRONLY))
14210 + flags = au_file_roflags(flags);
14212 + h_file = ERR_PTR(-EROFS);
14213 + flags = au_file_roflags(flags);
14214 + if (unlikely(vfsub_native_ro(h_inode)
14215 + || IS_APPEND(h_inode)))
14217 + flags &= ~O_ACCMODE;
14218 + flags |= O_WRONLY;
14221 + flags &= ~O_CREAT;
14222 + au_lcnt_inc(&br->br_nfiles);
14223 + h_path.dentry = h_dentry;
14224 + h_path.mnt = au_br_mnt(br);
14225 + h_file = vfsub_dentry_open(&h_path, flags);
14226 + if (IS_ERR(h_file))
14229 + if (flags & __FMODE_EXEC) {
14230 + err = deny_write_access(h_file);
14231 + if (unlikely(err)) {
14233 + h_file = ERR_PTR(err);
14237 + fsnotify_open(h_file);
14238 + goto out; /* success */
14241 + au_lcnt_dec(&br->br_nfiles);
14246 +static int au_cmoo(struct dentry *dentry)
14248 + int err, cmoo, matched;
14249 + unsigned int udba;
14250 + struct path h_path;
14251 + struct au_pin pin;
14252 + struct au_cp_generic cpg = {
14253 + .dentry = dentry,
14258 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14260 + struct inode *delegated;
14261 + struct super_block *sb;
14262 + struct au_sbinfo *sbinfo;
14263 + struct au_fhsm *fhsm;
14265 + struct au_branch *br;
14266 + struct dentry *parent;
14267 + struct au_hinode *hdir;
14269 + DiMustWriteLock(dentry);
14270 + IiMustWriteLock(d_inode(dentry));
14273 + if (IS_ROOT(dentry))
14275 + cpg.bsrc = au_dbtop(dentry);
14279 + sb = dentry->d_sb;
14280 + sbinfo = au_sbi(sb);
14281 + fhsm = &sbinfo->si_fhsm;
14282 + pid = au_fhsm_pid(fhsm);
14285 + && (current->pid == pid
14286 + || rcu_dereference(current->real_parent)->pid == pid));
14287 + rcu_read_unlock();
14291 + br = au_sbr(sb, cpg.bsrc);
14292 + cmoo = au_br_cmoo(br->br_perm);
14295 + if (!d_is_reg(dentry))
14296 + cmoo &= AuBrAttr_COO_ALL;
14300 + parent = dget_parent(dentry);
14301 + di_write_lock_parent(parent);
14302 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14304 + if (unlikely(err < 0)) {
14305 + err = 0; /* there is no upper writable branch */
14308 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14310 + /* do not respect the coo attrib for the target branch */
14311 + err = au_cpup_dirs(dentry, cpg.bdst);
14312 + if (unlikely(err))
14315 + di_downgrade_lock(parent, AuLock_IR);
14316 + udba = au_opt_udba(sb);
14317 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14318 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14319 + if (unlikely(err))
14322 + err = au_sio_cpup_simple(&cpg);
14324 + if (unlikely(err))
14326 + if (!(cmoo & AuBrWAttr_MOO))
14327 + goto out_parent; /* success */
14329 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14330 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14331 + if (unlikely(err))
14334 + h_path.mnt = au_br_mnt(br);
14335 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14336 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14337 + delegated = NULL;
14338 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14340 + /* todo: keep h_dentry or not? */
14341 + if (unlikely(err == -EWOULDBLOCK)) {
14342 + pr_warn("cannot retry for NFSv4 delegation"
14343 + " for an internal unlink\n");
14346 + if (unlikely(err)) {
14347 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14351 + goto out_parent; /* success */
14354 + di_downgrade_lock(parent, AuLock_IR);
14356 + di_read_unlock(parent, AuLock_IR);
14363 +int au_do_open(struct file *file, struct au_do_open_args *args)
14365 + int err, aopen = args->aopen;
14366 + struct dentry *dentry;
14367 + struct au_finfo *finfo;
14370 + err = au_finfo_init(file, args->fidir);
14373 + err = au_finfo_init(file, args->fidir);
14376 + if (unlikely(err))
14379 + dentry = file->f_path.dentry;
14380 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14381 + di_write_lock_child(dentry);
14382 + err = au_cmoo(dentry);
14383 + di_downgrade_lock(dentry, AuLock_IR);
14386 + err = args->open(file, vfsub_file_flags(file), NULL);
14389 + err = args->open(file, vfsub_file_flags(file),
14394 + di_read_unlock(dentry, AuLock_IR);
14396 + finfo = au_fi(file);
14398 + finfo->fi_file = file;
14399 + au_hbl_add(&finfo->fi_hlist,
14400 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14403 + fi_write_unlock(file);
14406 + fi_write_unlock(file);
14409 + if (unlikely(err)) {
14410 + finfo->fi_hdir = NULL;
14411 + au_finfo_fin(file);
14419 +int au_reopen_nondir(struct file *file)
14422 + aufs_bindex_t btop;
14423 + struct dentry *dentry;
14424 + struct au_branch *br;
14425 + struct file *h_file, *h_file_tmp;
14427 + dentry = file->f_path.dentry;
14428 + btop = au_dbtop(dentry);
14429 + br = au_sbr(dentry->d_sb, btop);
14430 + h_file_tmp = NULL;
14431 + if (au_fbtop(file) == btop) {
14432 + h_file = au_hf_top(file);
14433 + if (file->f_mode == h_file->f_mode)
14434 + return 0; /* success */
14435 + h_file_tmp = h_file;
14436 + get_file(h_file_tmp);
14437 + au_lcnt_inc(&br->br_nfiles);
14438 + au_set_h_fptr(file, btop, NULL);
14440 + AuDebugOn(au_fi(file)->fi_hdir);
14443 + * file exists on both of rw and ro
14444 + * open --> dbtop and fbtop are both 0
14445 + * prepend a branch as rw, "rw" become ro
14447 + * delete the top branch, "rw" becomes rw again
14448 + * --> dbtop is 1, fbtop is still 0
14449 + * write --> fbtop is 0 but dbtop is 1
14451 + /* AuDebugOn(au_fbtop(file) < btop); */
14453 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14454 + file, /*force_wr*/0);
14455 + err = PTR_ERR(h_file);
14456 + if (IS_ERR(h_file)) {
14457 + if (h_file_tmp) {
14459 + au_set_h_fptr(file, btop, h_file_tmp);
14460 + h_file_tmp = NULL;
14462 + goto out; /* todo: close all? */
14466 + au_set_fbtop(file, btop);
14467 + au_set_h_fptr(file, btop, h_file);
14468 + au_update_figen(file);
14469 + /* todo: necessary? */
14470 + /* file->f_ra = h_file->f_ra; */
14473 + if (h_file_tmp) {
14474 + fput(h_file_tmp);
14475 + au_lcnt_dec(&br->br_nfiles);
14480 +/* ---------------------------------------------------------------------- */
14482 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14483 + struct dentry *hi_wh)
14486 + aufs_bindex_t btop;
14487 + struct au_dinfo *dinfo;
14488 + struct dentry *h_dentry;
14489 + struct au_hdentry *hdp;
14491 + dinfo = au_di(file->f_path.dentry);
14492 + AuRwMustWriteLock(&dinfo->di_rwsem);
14494 + btop = dinfo->di_btop;
14495 + dinfo->di_btop = btgt;
14496 + hdp = au_hdentry(dinfo, btgt);
14497 + h_dentry = hdp->hd_dentry;
14498 + hdp->hd_dentry = hi_wh;
14499 + err = au_reopen_nondir(file);
14500 + hdp->hd_dentry = h_dentry;
14501 + dinfo->di_btop = btop;
14506 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14507 + aufs_bindex_t bcpup, struct au_pin *pin)
14510 + struct inode *inode, *h_inode;
14511 + struct dentry *h_dentry, *hi_wh;
14512 + struct au_cp_generic cpg = {
14513 + .dentry = file->f_path.dentry,
14520 + au_update_dbtop(cpg.dentry);
14521 + inode = d_inode(cpg.dentry);
14523 + if (au_dbtop(cpg.dentry) <= bcpup
14524 + && au_dbbot(cpg.dentry) >= bcpup) {
14525 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14526 + if (h_dentry && d_is_positive(h_dentry))
14527 + h_inode = d_inode(h_dentry);
14529 + hi_wh = au_hi_wh(inode, bcpup);
14530 + if (!hi_wh && !h_inode)
14531 + err = au_sio_cpup_wh(&cpg, file);
14533 + /* already copied-up after unlink */
14534 + err = au_reopen_wh(file, bcpup, hi_wh);
14537 + && (inode->i_nlink > 1
14538 + || (inode->i_state & I_LINKABLE))
14539 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14540 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14546 + * prepare the @file for writing.
14548 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14551 + aufs_bindex_t dbtop;
14552 + struct dentry *parent;
14553 + struct inode *inode;
14554 + struct super_block *sb;
14555 + struct file *h_file;
14556 + struct au_cp_generic cpg = {
14557 + .dentry = file->f_path.dentry,
14562 + .flags = AuCpup_DTIME
14565 + sb = cpg.dentry->d_sb;
14566 + inode = d_inode(cpg.dentry);
14567 + cpg.bsrc = au_fbtop(file);
14568 + err = au_test_ro(sb, cpg.bsrc, inode);
14569 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14570 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14575 + /* need to cpup or reopen */
14576 + parent = dget_parent(cpg.dentry);
14577 + di_write_lock_parent(parent);
14578 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14580 + if (unlikely(err < 0))
14584 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14585 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14586 + if (unlikely(err))
14590 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14591 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14592 + if (unlikely(err))
14595 + dbtop = au_dbtop(cpg.dentry);
14596 + if (dbtop <= cpg.bdst)
14597 + cpg.bsrc = cpg.bdst;
14599 + if (dbtop <= cpg.bdst /* just reopen */
14600 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14602 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14603 + if (IS_ERR(h_file))
14604 + err = PTR_ERR(h_file);
14606 + di_downgrade_lock(parent, AuLock_IR);
14607 + if (dbtop > cpg.bdst)
14608 + err = au_sio_cpup_simple(&cpg);
14610 + err = au_reopen_nondir(file);
14611 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14613 + } else { /* copyup as wh and reopen */
14615 + * since writable hfsplus branch is not supported,
14616 + * h_open_pre/post() are unnecessary.
14618 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14619 + di_downgrade_lock(parent, AuLock_IR);
14623 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14624 + goto out_dput; /* success */
14630 + di_downgrade_lock(parent, AuLock_IR);
14632 + di_read_unlock(parent, AuLock_IR);
14639 +/* ---------------------------------------------------------------------- */
14641 +int au_do_flush(struct file *file, fl_owner_t id,
14642 + int (*flush)(struct file *file, fl_owner_t id))
14645 + struct super_block *sb;
14646 + struct inode *inode;
14648 + inode = file_inode(file);
14649 + sb = inode->i_sb;
14650 + si_noflush_read_lock(sb);
14651 + fi_read_lock(file);
14652 + ii_read_lock_child(inode);
14654 + err = flush(file, id);
14655 + au_cpup_attr_timesizes(inode);
14657 + ii_read_unlock(inode);
14658 + fi_read_unlock(file);
14659 + si_read_unlock(sb);
14663 +/* ---------------------------------------------------------------------- */
14665 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14668 + struct au_pin pin;
14669 + struct au_finfo *finfo;
14670 + struct dentry *parent, *hi_wh;
14671 + struct inode *inode;
14672 + struct super_block *sb;
14673 + struct au_cp_generic cpg = {
14674 + .dentry = file->f_path.dentry,
14679 + .flags = AuCpup_DTIME
14682 + FiMustWriteLock(file);
14685 + finfo = au_fi(file);
14686 + sb = cpg.dentry->d_sb;
14687 + inode = d_inode(cpg.dentry);
14688 + cpg.bdst = au_ibtop(inode);
14689 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14692 + parent = dget_parent(cpg.dentry);
14693 + if (au_test_ro(sb, cpg.bdst, inode)) {
14694 + di_read_lock_parent(parent, !AuLock_IR);
14695 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14697 + di_read_unlock(parent, !AuLock_IR);
14698 + if (unlikely(err < 0))
14703 + di_read_lock_parent(parent, AuLock_IR);
14704 + hi_wh = au_hi_wh(inode, cpg.bdst);
14705 + if (!S_ISDIR(inode->i_mode)
14706 + && au_opt_test(au_mntflags(sb), PLINK)
14707 + && au_plink_test(inode)
14708 + && !d_unhashed(cpg.dentry)
14709 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14710 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14711 + if (unlikely(err))
14714 + /* always superio. */
14715 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14716 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14718 + err = au_sio_cpup_simple(&cpg);
14721 + } else if (hi_wh) {
14722 + /* already copied-up after unlink */
14723 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14724 + *need_reopen = 0;
14728 + di_read_unlock(parent, AuLock_IR);
14735 +static void au_do_refresh_dir(struct file *file)
14737 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14738 + struct au_hfile *p, tmp, *q;
14739 + struct au_finfo *finfo;
14740 + struct super_block *sb;
14741 + struct au_fidir *fidir;
14743 + FiMustWriteLock(file);
14745 + sb = file->f_path.dentry->d_sb;
14746 + finfo = au_fi(file);
14747 + fidir = finfo->fi_hdir;
14748 + AuDebugOn(!fidir);
14749 + p = fidir->fd_hfile + finfo->fi_btop;
14750 + brid = p->hf_br->br_id;
14751 + bbot = fidir->fd_bbot;
14752 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14756 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14757 + if (new_bindex == bindex)
14759 + if (new_bindex < 0) {
14760 + au_set_h_fptr(file, bindex, NULL);
14764 + /* swap two lower inode, and loop again */
14765 + q = fidir->fd_hfile + new_bindex;
14769 + if (tmp.hf_file) {
14775 + p = fidir->fd_hfile;
14776 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14777 + bbot = au_sbbot(sb);
14778 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14779 + finfo->fi_btop++, p++)
14780 + if (p->hf_file) {
14781 + if (file_inode(p->hf_file))
14783 + au_hfput(p, /*execed*/0);
14786 + bbot = au_br_index(sb, brid);
14787 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14788 + finfo->fi_btop++, p++)
14790 + au_hfput(p, /*execed*/0);
14791 + bbot = au_sbbot(sb);
14794 + p = fidir->fd_hfile + bbot;
14795 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14796 + fidir->fd_bbot--, p--)
14797 + if (p->hf_file) {
14798 + if (file_inode(p->hf_file))
14800 + au_hfput(p, /*execed*/0);
14802 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14806 + * after branch manipulating, refresh the file.
14808 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14810 + int err, need_reopen, nbr;
14811 + aufs_bindex_t bbot, bindex;
14812 + struct dentry *dentry;
14813 + struct super_block *sb;
14814 + struct au_finfo *finfo;
14815 + struct au_hfile *hfile;
14817 + dentry = file->f_path.dentry;
14818 + sb = dentry->d_sb;
14819 + nbr = au_sbbot(sb) + 1;
14820 + finfo = au_fi(file);
14821 + if (!finfo->fi_hdir) {
14822 + hfile = &finfo->fi_htop;
14823 + AuDebugOn(!hfile->hf_file);
14824 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14825 + AuDebugOn(bindex < 0);
14826 + if (bindex != finfo->fi_btop)
14827 + au_set_fbtop(file, bindex);
14829 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14830 + if (unlikely(err))
14832 + au_do_refresh_dir(file);
14837 + if (!au_test_mmapped(file))
14838 + err = au_file_refresh_by_inode(file, &need_reopen);
14839 + if (finfo->fi_hdir)
14840 + /* harmless if err */
14841 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14842 + if (!err && need_reopen && !d_unlinked(dentry))
14843 + err = reopen(file);
14845 + au_update_figen(file);
14846 + goto out; /* success */
14849 + /* error, close all lower files */
14850 + if (finfo->fi_hdir) {
14851 + bbot = au_fbbot_dir(file);
14852 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14853 + au_set_h_fptr(file, bindex, NULL);
14860 +/* common function to regular file and dir */
14861 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14862 + int wlock, unsigned int fi_lsc)
14865 + unsigned int sigen, figen;
14866 + aufs_bindex_t btop;
14867 + unsigned char pseudo_link;
14868 + struct dentry *dentry;
14869 + struct inode *inode;
14872 + dentry = file->f_path.dentry;
14873 + inode = d_inode(dentry);
14874 + sigen = au_sigen(dentry->d_sb);
14875 + fi_write_lock_nested(file, fi_lsc);
14876 + figen = au_figen(file);
14878 + di_write_lock_child(dentry);
14880 + di_write_lock_child2(dentry);
14881 + btop = au_dbtop(dentry);
14882 + pseudo_link = (btop != au_ibtop(inode));
14883 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14885 + di_downgrade_lock(dentry, AuLock_IR);
14886 + fi_downgrade_lock(file);
14888 + goto out; /* success */
14891 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14892 + if (au_digen_test(dentry, sigen)) {
14893 + err = au_reval_dpath(dentry, sigen);
14894 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14898 + err = refresh_file(file, reopen);
14901 + di_downgrade_lock(dentry, AuLock_IR);
14902 + fi_downgrade_lock(file);
14905 + di_write_unlock(dentry);
14906 + fi_write_unlock(file);
14913 +/* ---------------------------------------------------------------------- */
14915 +/* cf. aufs_nopage() */
14916 +/* for madvise(2) */
14917 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14919 + unlock_page(page);
14923 +/* it will never be called, but necessary to support O_DIRECT */
14924 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14925 +{ BUG(); return 0; }
14927 +/* they will never be called. */
14928 +#ifdef CONFIG_AUFS_DEBUG
14929 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14930 + loff_t pos, unsigned len, unsigned flags,
14931 + struct page **pagep, void **fsdata)
14932 +{ AuUnsupport(); return 0; }
14933 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14934 + loff_t pos, unsigned len, unsigned copied,
14935 + struct page *page, void *fsdata)
14936 +{ AuUnsupport(); return 0; }
14937 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14938 +{ AuUnsupport(); return 0; }
14940 +static int aufs_set_page_dirty(struct page *page)
14941 +{ AuUnsupport(); return 0; }
14942 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14943 + unsigned int length)
14944 +{ AuUnsupport(); }
14945 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14946 +{ AuUnsupport(); return 0; }
14947 +#if 0 /* called by memory compaction regardless file */
14948 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14949 + struct page *page, enum migrate_mode mode)
14950 +{ AuUnsupport(); return 0; }
14952 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14953 +{ AuUnsupport(); return true; }
14954 +static void aufs_putback_page(struct page *page)
14955 +{ AuUnsupport(); }
14956 +static int aufs_launder_page(struct page *page)
14957 +{ AuUnsupport(); return 0; }
14958 +static int aufs_is_partially_uptodate(struct page *page,
14959 + unsigned long from,
14960 + unsigned long count)
14961 +{ AuUnsupport(); return 0; }
14962 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14964 +{ AuUnsupport(); }
14965 +static int aufs_error_remove_page(struct address_space *mapping,
14966 + struct page *page)
14967 +{ AuUnsupport(); return 0; }
14968 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14970 +{ AuUnsupport(); return 0; }
14971 +static void aufs_swap_deactivate(struct file *file)
14972 +{ AuUnsupport(); }
14973 +#endif /* CONFIG_AUFS_DEBUG */
14975 +const struct address_space_operations aufs_aop = {
14976 + .readpage = aufs_readpage,
14977 + .direct_IO = aufs_direct_IO,
14978 +#ifdef CONFIG_AUFS_DEBUG
14979 + .writepage = aufs_writepage,
14980 + /* no writepages, because of writepage */
14981 + .set_page_dirty = aufs_set_page_dirty,
14982 + /* no readpages, because of readpage */
14983 + .write_begin = aufs_write_begin,
14984 + .write_end = aufs_write_end,
14985 + /* no bmap, no block device */
14986 + .invalidatepage = aufs_invalidatepage,
14987 + .releasepage = aufs_releasepage,
14988 + /* is fallback_migrate_page ok? */
14989 + /* .migratepage = aufs_migratepage, */
14990 + .isolate_page = aufs_isolate_page,
14991 + .putback_page = aufs_putback_page,
14992 + .launder_page = aufs_launder_page,
14993 + .is_partially_uptodate = aufs_is_partially_uptodate,
14994 + .is_dirty_writeback = aufs_is_dirty_writeback,
14995 + .error_remove_page = aufs_error_remove_page,
14996 + .swap_activate = aufs_swap_activate,
14997 + .swap_deactivate = aufs_swap_deactivate
14998 +#endif /* CONFIG_AUFS_DEBUG */
15000 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
15001 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
15002 +++ linux/fs/aufs/file.h 2020-01-27 10:57:18.172204883 +0100
15004 +/* SPDX-License-Identifier: GPL-2.0 */
15006 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15008 + * This program, aufs is free software; you can redistribute it and/or modify
15009 + * it under the terms of the GNU General Public License as published by
15010 + * the Free Software Foundation; either version 2 of the License, or
15011 + * (at your option) any later version.
15013 + * This program is distributed in the hope that it will be useful,
15014 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15015 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15016 + * GNU General Public License for more details.
15018 + * You should have received a copy of the GNU General Public License
15019 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15023 + * file operations
15026 +#ifndef __AUFS_FILE_H__
15027 +#define __AUFS_FILE_H__
15031 +#include <linux/file.h>
15032 +#include <linux/fs.h>
15033 +#include <linux/mm_types.h>
15034 +#include <linux/poll.h>
15035 +#include "rwsem.h"
15039 + struct file *hf_file;
15040 + struct au_branch *hf_br;
15045 + aufs_bindex_t fd_bbot;
15046 + aufs_bindex_t fd_nent;
15047 + struct au_vdir *fd_vdir_cache;
15048 + struct au_hfile fd_hfile[];
15051 +static inline int au_fidir_sz(int nent)
15053 + AuDebugOn(nent < 0);
15054 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
15058 + atomic_t fi_generation;
15060 + struct au_rwsem fi_rwsem;
15061 + aufs_bindex_t fi_btop;
15063 + /* do not union them */
15064 + struct { /* for non-dir */
15065 + struct au_hfile fi_htop;
15066 + atomic_t fi_mmapped;
15068 + struct au_fidir *fi_hdir; /* for dir only */
15070 + struct hlist_bl_node fi_hlist;
15071 + struct file *fi_file; /* very ugly */
15072 + struct rcu_head rcu;
15073 +} ____cacheline_aligned_in_smp;
15075 +/* ---------------------------------------------------------------------- */
15078 +extern const struct address_space_operations aufs_aop;
15079 +unsigned int au_file_roflags(unsigned int flags);
15080 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15081 + struct file *file, int force_wr);
15082 +struct au_do_open_args {
15084 + int (*open)(struct file *file, int flags,
15085 + struct file *h_file);
15086 + struct au_fidir *fidir;
15087 + struct file *h_file;
15089 +int au_do_open(struct file *file, struct au_do_open_args *args);
15090 +int au_reopen_nondir(struct file *file);
15092 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15093 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15094 + int wlock, unsigned int fi_lsc);
15095 +int au_do_flush(struct file *file, fl_owner_t id,
15096 + int (*flush)(struct file *file, fl_owner_t id));
15099 +#ifdef CONFIG_AUFS_POLL
15100 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15103 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15105 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15107 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15108 + struct file *h_file);
15110 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15111 + aufs_bindex_t bindex, int force_wr)
15112 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15113 + struct file *h_file);
15117 +extern const struct file_operations aufs_file_fop;
15118 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15119 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15120 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15123 +void au_hfput(struct au_hfile *hf, int execed);
15124 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15125 + struct file *h_file);
15127 +void au_update_figen(struct file *file);
15128 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15129 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15131 +void au_fi_init_once(void *_fi);
15132 +void au_finfo_fin(struct file *file);
15133 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15136 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15137 +#ifdef CONFIG_COMPAT
15138 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15139 + unsigned long arg);
15140 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15141 + unsigned long arg);
15144 +/* ---------------------------------------------------------------------- */
15146 +static inline struct au_finfo *au_fi(struct file *file)
15148 + return file->private_data;
15151 +/* ---------------------------------------------------------------------- */
15153 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15154 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15155 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15156 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15158 +#define fi_read_trylock_nested(f) \
15159 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15160 +#define fi_write_trylock_nested(f) \
15161 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15164 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15165 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15166 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15168 +/* lock subclass for finfo */
15174 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15176 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15179 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15181 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15185 + * fi_read_lock_1, fi_write_lock_1,
15186 + * fi_read_lock_2, fi_write_lock_2
15188 +#define AuReadLockFunc(name) \
15189 +static inline void fi_read_lock_##name(struct file *f) \
15190 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15192 +#define AuWriteLockFunc(name) \
15193 +static inline void fi_write_lock_##name(struct file *f) \
15194 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15196 +#define AuRWLockFuncs(name) \
15197 + AuReadLockFunc(name) \
15198 + AuWriteLockFunc(name)
15203 +#undef AuReadLockFunc
15204 +#undef AuWriteLockFunc
15205 +#undef AuRWLockFuncs
15207 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15208 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15209 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15211 +/* ---------------------------------------------------------------------- */
15213 +/* todo: hard/soft set? */
15214 +static inline aufs_bindex_t au_fbtop(struct file *file)
15216 + FiMustAnyLock(file);
15217 + return au_fi(file)->fi_btop;
15220 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15222 + FiMustAnyLock(file);
15223 + AuDebugOn(!au_fi(file)->fi_hdir);
15224 + return au_fi(file)->fi_hdir->fd_bbot;
15227 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15229 + FiMustAnyLock(file);
15230 + AuDebugOn(!au_fi(file)->fi_hdir);
15231 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15234 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15236 + FiMustWriteLock(file);
15237 + au_fi(file)->fi_btop = bindex;
15240 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15242 + FiMustWriteLock(file);
15243 + AuDebugOn(!au_fi(file)->fi_hdir);
15244 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15247 +static inline void au_set_fvdir_cache(struct file *file,
15248 + struct au_vdir *vdir_cache)
15250 + FiMustWriteLock(file);
15251 + AuDebugOn(!au_fi(file)->fi_hdir);
15252 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15255 +static inline struct file *au_hf_top(struct file *file)
15257 + FiMustAnyLock(file);
15258 + AuDebugOn(au_fi(file)->fi_hdir);
15259 + return au_fi(file)->fi_htop.hf_file;
15262 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15264 + FiMustAnyLock(file);
15265 + AuDebugOn(!au_fi(file)->fi_hdir);
15266 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15269 +/* todo: memory barrier? */
15270 +static inline unsigned int au_figen(struct file *f)
15272 + return atomic_read(&au_fi(f)->fi_generation);
15275 +static inline void au_set_mmapped(struct file *f)
15277 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15279 + pr_warn("fi_mmapped wrapped around\n");
15280 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15284 +static inline void au_unset_mmapped(struct file *f)
15286 + atomic_dec(&au_fi(f)->fi_mmapped);
15289 +static inline int au_test_mmapped(struct file *f)
15291 + return atomic_read(&au_fi(f)->fi_mmapped);
15294 +/* customize vma->vm_file */
15296 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15297 + struct file *file)
15301 + f = vma->vm_file;
15303 + vma->vm_file = file;
15308 +#define AuDbgVmRegion(file, vma) do {} while (0)
15310 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15311 + struct file *file)
15313 + au_do_vm_file_reset(vma, file);
15316 +#define AuDbgVmRegion(file, vma) \
15317 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15319 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15320 + struct file *file)
15324 + au_do_vm_file_reset(vma, file);
15325 + f = vma->vm_region->vm_file;
15327 + vma->vm_region->vm_file = file;
15330 +#endif /* CONFIG_MMU */
15332 +/* handle vma->vm_prfile */
15333 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15334 + struct file *file)
15337 + vma->vm_prfile = file;
15338 +#ifndef CONFIG_MMU
15340 + vma->vm_region->vm_prfile = file;
15344 +#endif /* __KERNEL__ */
15345 +#endif /* __AUFS_FILE_H__ */
15346 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15347 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15348 +++ linux/fs/aufs/finfo.c 2020-01-27 10:57:18.172204883 +0100
15350 +// SPDX-License-Identifier: GPL-2.0
15352 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15354 + * This program, aufs is free software; you can redistribute it and/or modify
15355 + * it under the terms of the GNU General Public License as published by
15356 + * the Free Software Foundation; either version 2 of the License, or
15357 + * (at your option) any later version.
15359 + * This program is distributed in the hope that it will be useful,
15360 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15361 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15362 + * GNU General Public License for more details.
15364 + * You should have received a copy of the GNU General Public License
15365 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15369 + * file private data
15374 +void au_hfput(struct au_hfile *hf, int execed)
15377 + allow_write_access(hf->hf_file);
15378 + fput(hf->hf_file);
15379 + hf->hf_file = NULL;
15380 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15381 + hf->hf_br = NULL;
15384 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15386 + struct au_finfo *finfo = au_fi(file);
15387 + struct au_hfile *hf;
15388 + struct au_fidir *fidir;
15390 + fidir = finfo->fi_hdir;
15392 + AuDebugOn(finfo->fi_btop != bindex);
15393 + hf = &finfo->fi_htop;
15395 + hf = fidir->fd_hfile + bindex;
15397 + if (hf && hf->hf_file)
15398 + au_hfput(hf, vfsub_file_execed(file));
15400 + FiMustWriteLock(file);
15401 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15402 + hf->hf_file = val;
15403 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15407 +void au_update_figen(struct file *file)
15409 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15410 + /* smp_mb(); */ /* atomic_set */
15413 +/* ---------------------------------------------------------------------- */
15415 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15417 + struct au_fidir *fidir;
15420 + nbr = au_sbbot(sb) + 1;
15422 + nbr = 2; /* initial allocate for 2 branches */
15423 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15425 + fidir->fd_bbot = -1;
15426 + fidir->fd_nent = nbr;
15432 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15435 + struct au_fidir *fidir, *p;
15437 + AuRwMustWriteLock(&finfo->fi_rwsem);
15438 + fidir = finfo->fi_hdir;
15439 + AuDebugOn(!fidir);
15442 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15443 + GFP_NOFS, may_shrink);
15445 + p->fd_nent = nbr;
15446 + finfo->fi_hdir = p;
15453 +/* ---------------------------------------------------------------------- */
15455 +void au_finfo_fin(struct file *file)
15457 + struct au_finfo *finfo;
15459 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15461 + finfo = au_fi(file);
15462 + AuDebugOn(finfo->fi_hdir);
15463 + AuRwDestroy(&finfo->fi_rwsem);
15464 + au_cache_free_finfo(finfo);
15467 +void au_fi_init_once(void *_finfo)
15469 + struct au_finfo *finfo = _finfo;
15471 + au_rw_init(&finfo->fi_rwsem);
15474 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15477 + struct au_finfo *finfo;
15478 + struct dentry *dentry;
15481 + dentry = file->f_path.dentry;
15482 + finfo = au_cache_alloc_finfo();
15483 + if (unlikely(!finfo))
15487 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15488 + au_rw_write_lock(&finfo->fi_rwsem);
15489 + finfo->fi_btop = -1;
15490 + finfo->fi_hdir = fidir;
15491 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15492 + /* smp_mb(); */ /* atomic_set */
15494 + file->private_data = finfo;
15499 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15500 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15501 +++ linux/fs/aufs/f_op.c 2020-01-27 10:57:18.172204883 +0100
15503 +// SPDX-License-Identifier: GPL-2.0
15505 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15507 + * This program, aufs is free software; you can redistribute it and/or modify
15508 + * it under the terms of the GNU General Public License as published by
15509 + * the Free Software Foundation; either version 2 of the License, or
15510 + * (at your option) any later version.
15512 + * This program is distributed in the hope that it will be useful,
15513 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15514 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15515 + * GNU General Public License for more details.
15517 + * You should have received a copy of the GNU General Public License
15518 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15522 + * file and vm operations
15525 +#include <linux/aio.h>
15526 +#include <linux/fs_stack.h>
15527 +#include <linux/mman.h>
15528 +#include <linux/security.h>
15531 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15534 + aufs_bindex_t bindex;
15535 + struct dentry *dentry, *h_dentry;
15536 + struct au_finfo *finfo;
15537 + struct inode *h_inode;
15539 + FiMustWriteLock(file);
15542 + dentry = file->f_path.dentry;
15543 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15544 + finfo = au_fi(file);
15545 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15546 + atomic_set(&finfo->fi_mmapped, 0);
15547 + bindex = au_dbtop(dentry);
15549 + h_dentry = au_h_dptr(dentry, bindex);
15550 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15551 + if (unlikely(err))
15553 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15554 + if (IS_ERR(h_file)) {
15555 + err = PTR_ERR(h_file);
15559 + h_dentry = h_file->f_path.dentry;
15560 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15561 + if (unlikely(err))
15563 + /* br ref is already inc-ed */
15566 + if ((flags & __O_TMPFILE)
15567 + && !(flags & O_EXCL)) {
15568 + h_inode = file_inode(h_file);
15569 + spin_lock(&h_inode->i_lock);
15570 + h_inode->i_state |= I_LINKABLE;
15571 + spin_unlock(&h_inode->i_lock);
15573 + au_set_fbtop(file, bindex);
15574 + au_set_h_fptr(file, bindex, h_file);
15575 + au_update_figen(file);
15576 + /* todo: necessary? */
15577 + /* file->f_ra = h_file->f_ra; */
15583 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15584 + struct file *file)
15587 + struct super_block *sb;
15588 + struct au_do_open_args args = {
15589 + .open = au_do_open_nondir
15592 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15593 + file, vfsub_file_flags(file), file->f_mode);
15595 + sb = file->f_path.dentry->d_sb;
15596 + si_read_lock(sb, AuLock_FLUSH);
15597 + err = au_do_open(file, &args);
15598 + si_read_unlock(sb);
15602 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15604 + struct au_finfo *finfo;
15605 + aufs_bindex_t bindex;
15607 + finfo = au_fi(file);
15608 + au_hbl_del(&finfo->fi_hlist,
15609 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15610 + bindex = finfo->fi_btop;
15612 + au_set_h_fptr(file, bindex, NULL);
15614 + au_finfo_fin(file);
15618 +/* ---------------------------------------------------------------------- */
15620 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15623 + struct file *h_file;
15626 + h_file = au_hf_top(file);
15628 + err = vfsub_flush(h_file, id);
15632 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15634 + return au_do_flush(file, id, au_do_flush_nondir);
15637 +/* ---------------------------------------------------------------------- */
15639 + * read and write functions acquire [fdi]_rwsem once, but release before
15640 + * mmap_sem. This is because to stop a race condition between mmap(2).
15641 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15642 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15643 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15646 +/* Callers should call au_read_post() or fput() in the end */
15647 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15649 + struct file *h_file;
15652 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15654 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15655 + h_file = au_hf_top(file);
15656 + get_file(h_file);
15658 + fi_read_unlock(file);
15660 + h_file = ERR_PTR(err);
15665 +static void au_read_post(struct inode *inode, struct file *h_file)
15667 + /* update without lock, I don't think it a problem */
15668 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15672 +struct au_write_pre {
15674 + unsigned int lsc;
15678 + aufs_bindex_t btop;
15682 + * return with iinfo is write-locked
15683 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15686 +static struct file *au_write_pre(struct file *file, int do_ready,
15687 + struct au_write_pre *wpre)
15689 + struct file *h_file;
15690 + struct dentry *dentry;
15692 + unsigned int lsc;
15693 + struct au_pin pin;
15698 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15699 + h_file = ERR_PTR(err);
15700 + if (unlikely(err))
15703 + dentry = file->f_path.dentry;
15705 + err = au_ready_to_write(file, -1, &pin);
15706 + if (unlikely(err)) {
15707 + h_file = ERR_PTR(err);
15708 + di_write_unlock(dentry);
15713 + di_downgrade_lock(dentry, /*flags*/0);
15715 + wpre->btop = au_fbtop(file);
15716 + h_file = au_hf_top(file);
15717 + get_file(h_file);
15719 + wpre->blks = file_inode(h_file)->i_blocks;
15722 + di_read_unlock(dentry, /*flags*/0);
15725 + fi_write_unlock(file);
15730 +static void au_write_post(struct inode *inode, struct file *h_file,
15731 + struct au_write_pre *wpre, ssize_t written)
15733 + struct inode *h_inode;
15735 + au_cpup_attr_timesizes(inode);
15736 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15737 + h_inode = file_inode(h_file);
15738 + inode->i_mode = h_inode->i_mode;
15739 + ii_write_unlock(inode);
15740 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15742 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15743 + /*force*/h_inode->i_blocks > wpre->blks);
15747 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
15751 + struct inode *inode;
15752 + struct file *h_file;
15753 + struct super_block *sb;
15755 + inode = file_inode(file);
15756 + sb = inode->i_sb;
15757 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15759 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15760 + err = PTR_ERR(h_file);
15761 + if (IS_ERR(h_file))
15764 + /* filedata may be obsoleted by concurrent copyup, but no problem */
15765 + err = vfsub_read_u(h_file, buf, count, ppos);
15766 + /* todo: necessary? */
15767 + /* file->f_ra = h_file->f_ra; */
15768 + au_read_post(inode, h_file);
15771 + si_read_unlock(sb);
15776 + * todo: very ugly
15777 + * it locks both of i_mutex and si_rwsem for read in safe.
15778 + * if the plink maintenance mode continues forever (that is the problem),
15779 + * may loop forever.
15781 +static void au_mtx_and_read_lock(struct inode *inode)
15784 + struct super_block *sb = inode->i_sb;
15787 + inode_lock(inode);
15788 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15791 + inode_unlock(inode);
15792 + si_read_lock(sb, AuLock_NOPLMW);
15793 + si_read_unlock(sb);
15797 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
15798 + size_t count, loff_t *ppos)
15801 + struct au_write_pre wpre;
15802 + struct inode *inode;
15803 + struct file *h_file;
15804 + char __user *buf = (char __user *)ubuf;
15806 + inode = file_inode(file);
15807 + au_mtx_and_read_lock(inode);
15810 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15811 + err = PTR_ERR(h_file);
15812 + if (IS_ERR(h_file))
15815 + err = vfsub_write_u(h_file, buf, count, ppos);
15816 + au_write_post(inode, h_file, &wpre, err);
15819 + si_read_unlock(inode->i_sb);
15820 + inode_unlock(inode);
15824 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15825 + struct iov_iter *iov_iter)
15828 + struct file *file;
15829 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15831 + err = security_file_permission(h_file, rw);
15832 + if (unlikely(err))
15835 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15837 + if (rw == MAY_READ)
15838 + iter = h_file->f_op->read_iter;
15839 + else if (rw == MAY_WRITE)
15840 + iter = h_file->f_op->write_iter;
15842 + file = kio->ki_filp;
15843 + kio->ki_filp = h_file;
15846 + err = iter(kio, iov_iter);
15849 + /* currently there is no such fs */
15851 + kio->ki_filp = file;
15857 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15860 + struct file *file, *h_file;
15861 + struct inode *inode;
15862 + struct super_block *sb;
15864 + file = kio->ki_filp;
15865 + inode = file_inode(file);
15866 + sb = inode->i_sb;
15867 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15869 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15870 + err = PTR_ERR(h_file);
15871 + if (IS_ERR(h_file))
15874 + if (au_test_loopback_kthread()) {
15875 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15876 + if (file->f_mapping != h_file->f_mapping) {
15877 + file->f_mapping = h_file->f_mapping;
15878 + smp_mb(); /* unnecessary? */
15881 + fi_read_unlock(file);
15883 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15884 + /* todo: necessary? */
15885 + /* file->f_ra = h_file->f_ra; */
15886 + au_read_post(inode, h_file);
15889 + si_read_unlock(sb);
15893 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15896 + struct au_write_pre wpre;
15897 + struct inode *inode;
15898 + struct file *file, *h_file;
15900 + file = kio->ki_filp;
15901 + inode = file_inode(file);
15902 + au_mtx_and_read_lock(inode);
15905 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15906 + err = PTR_ERR(h_file);
15907 + if (IS_ERR(h_file))
15910 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15911 + au_write_post(inode, h_file, &wpre, err);
15914 + si_read_unlock(inode->i_sb);
15915 + inode_unlock(inode);
15919 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15920 + struct pipe_inode_info *pipe, size_t len,
15921 + unsigned int flags)
15924 + struct file *h_file;
15925 + struct inode *inode;
15926 + struct super_block *sb;
15928 + inode = file_inode(file);
15929 + sb = inode->i_sb;
15930 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15932 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15933 + err = PTR_ERR(h_file);
15934 + if (IS_ERR(h_file))
15937 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15938 + /* todo: necessary? */
15939 + /* file->f_ra = h_file->f_ra; */
15940 + au_read_post(inode, h_file);
15943 + si_read_unlock(sb);
15948 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15949 + size_t len, unsigned int flags)
15952 + struct au_write_pre wpre;
15953 + struct inode *inode;
15954 + struct file *h_file;
15956 + inode = file_inode(file);
15957 + au_mtx_and_read_lock(inode);
15960 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15961 + err = PTR_ERR(h_file);
15962 + if (IS_ERR(h_file))
15965 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15966 + au_write_post(inode, h_file, &wpre, err);
15969 + si_read_unlock(inode->i_sb);
15970 + inode_unlock(inode);
15974 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15978 + struct au_write_pre wpre;
15979 + struct inode *inode;
15980 + struct file *h_file;
15982 + inode = file_inode(file);
15983 + au_mtx_and_read_lock(inode);
15986 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15987 + err = PTR_ERR(h_file);
15988 + if (IS_ERR(h_file))
15992 + err = vfs_fallocate(h_file, mode, offset, len);
15994 + au_write_post(inode, h_file, &wpre, /*written*/1);
15997 + si_read_unlock(inode->i_sb);
15998 + inode_unlock(inode);
16002 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
16003 + struct file *dst, loff_t dst_pos,
16004 + size_t len, unsigned int flags)
16007 + struct au_write_pre wpre;
16008 + enum { SRC, DST };
16010 + struct inode *inode;
16011 + struct file *h_file;
16012 + struct super_block *h_sb;
16014 +#define a_src a[SRC]
16015 +#define a_dst a[DST]
16018 + a_src.inode = file_inode(src);
16019 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
16021 + a_dst.inode = file_inode(dst);
16022 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
16025 + au_mtx_and_read_lock(a_dst.inode);
16027 + * in order to match the order in di_write_lock2_{child,parent}(),
16028 + * use f_path.dentry for this comparison.
16030 + if (src->f_path.dentry < dst->f_path.dentry) {
16031 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
16032 + err = PTR_ERR(a_src.h_file);
16033 + if (IS_ERR(a_src.h_file))
16036 + wpre.lsc = AuLsc_FI_2;
16037 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16038 + err = PTR_ERR(a_dst.h_file);
16039 + if (IS_ERR(a_dst.h_file)) {
16040 + au_read_post(a_src.inode, a_src.h_file);
16044 + wpre.lsc = AuLsc_FI_1;
16045 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16046 + err = PTR_ERR(a_dst.h_file);
16047 + if (IS_ERR(a_dst.h_file))
16050 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
16051 + err = PTR_ERR(a_src.h_file);
16052 + if (IS_ERR(a_src.h_file)) {
16053 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
16060 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
16061 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
16062 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
16068 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
16069 + dst_pos, len, flags);
16072 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
16073 + fi_read_unlock(src);
16074 + au_read_post(a_src.inode, a_src.h_file);
16076 + si_read_unlock(a_dst.inode->i_sb);
16077 + inode_unlock(a_dst.inode);
16084 +/* ---------------------------------------------------------------------- */
16087 + * The locking order around current->mmap_sem.
16088 + * - in most and regular cases
16089 + * file I/O syscall -- aufs_read() or something
16090 + * -- si_rwsem for read -- mmap_sem
16091 + * (Note that [fdi]i_rwsem are released before mmap_sem).
16093 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
16094 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
16095 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
16096 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
16097 + * It means that when aufs acquires si_rwsem for write, the process should never
16098 + * acquire mmap_sem.
16100 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
16101 + * problem either since any directory is not able to be mmap-ed.
16102 + * The similar scenario is applied to aufs_readlink() too.
16105 +#if 0 /* stop calling security_file_mmap() */
16106 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
16107 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
16109 +static unsigned long au_arch_prot_conv(unsigned long flags)
16111 + /* currently ppc64 only */
16112 +#ifdef CONFIG_PPC64
16113 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16114 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16115 + return AuConv_VM_PROT(flags, SAO);
16117 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16122 +static unsigned long au_prot_conv(unsigned long flags)
16124 + return AuConv_VM_PROT(flags, READ)
16125 + | AuConv_VM_PROT(flags, WRITE)
16126 + | AuConv_VM_PROT(flags, EXEC)
16127 + | au_arch_prot_conv(flags);
16130 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16131 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16133 +static unsigned long au_flag_conv(unsigned long flags)
16135 + return AuConv_VM_MAP(flags, GROWSDOWN)
16136 + | AuConv_VM_MAP(flags, DENYWRITE)
16137 + | AuConv_VM_MAP(flags, LOCKED);
16141 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16144 + const unsigned char wlock
16145 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16146 + struct super_block *sb;
16147 + struct file *h_file;
16148 + struct inode *inode;
16150 + AuDbgVmRegion(file, vma);
16152 + inode = file_inode(file);
16153 + sb = inode->i_sb;
16155 + si_read_lock(sb, AuLock_NOPLMW);
16157 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16159 + err = PTR_ERR(h_file);
16160 + if (IS_ERR(h_file))
16164 + au_set_mmapped(file);
16165 + au_vm_file_reset(vma, h_file);
16167 + * we cannot call security_mmap_file() here since it may acquire
16168 + * mmap_sem or i_mutex.
16170 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16171 + * au_flag_conv(vma->vm_flags));
16174 + err = call_mmap(h_file, vma);
16176 + au_vm_prfile_set(vma, file);
16177 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16178 + goto out_fput; /* success */
16180 + au_unset_mmapped(file);
16181 + au_vm_file_reset(vma, file);
16185 + ii_write_unlock(inode);
16190 + si_read_unlock(sb);
16196 +/* ---------------------------------------------------------------------- */
16198 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16202 + struct au_write_pre wpre;
16203 + struct inode *inode;
16204 + struct file *h_file;
16206 + err = 0; /* -EBADF; */ /* posix? */
16207 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16210 + inode = file_inode(file);
16211 + au_mtx_and_read_lock(inode);
16214 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16215 + err = PTR_ERR(h_file);
16216 + if (IS_ERR(h_file))
16219 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16220 + au_write_post(inode, h_file, &wpre, /*written*/0);
16223 + si_read_unlock(inode->i_sb);
16224 + inode_unlock(inode);
16229 +static int aufs_fasync(int fd, struct file *file, int flag)
16232 + struct file *h_file;
16233 + struct super_block *sb;
16235 + sb = file->f_path.dentry->d_sb;
16236 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16238 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16239 + err = PTR_ERR(h_file);
16240 + if (IS_ERR(h_file))
16243 + if (h_file->f_op->fasync)
16244 + err = h_file->f_op->fasync(fd, h_file, flag);
16245 + fput(h_file); /* instead of au_read_post() */
16248 + si_read_unlock(sb);
16252 +static int aufs_setfl(struct file *file, unsigned long arg)
16255 + struct file *h_file;
16256 + struct super_block *sb;
16258 + sb = file->f_path.dentry->d_sb;
16259 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16261 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16262 + err = PTR_ERR(h_file);
16263 + if (IS_ERR(h_file))
16266 + /* stop calling h_file->fasync */
16267 + arg |= vfsub_file_flags(file) & FASYNC;
16268 + err = setfl(/*unused fd*/-1, h_file, arg);
16269 + fput(h_file); /* instead of au_read_post() */
16272 + si_read_unlock(sb);
16276 +/* ---------------------------------------------------------------------- */
16278 +/* no one supports this operation, currently */
16279 +#if 0 /* reserved for future use */
16280 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16281 + size_t len, loff_t *pos, int more)
16286 +/* ---------------------------------------------------------------------- */
16288 +const struct file_operations aufs_file_fop = {
16289 + .owner = THIS_MODULE,
16291 + .llseek = default_llseek,
16293 + .read = aufs_read,
16294 + .write = aufs_write,
16295 + .read_iter = aufs_read_iter,
16296 + .write_iter = aufs_write_iter,
16298 +#ifdef CONFIG_AUFS_POLL
16299 + .poll = aufs_poll,
16301 + .unlocked_ioctl = aufs_ioctl_nondir,
16302 +#ifdef CONFIG_COMPAT
16303 + .compat_ioctl = aufs_compat_ioctl_nondir,
16305 + .mmap = aufs_mmap,
16306 + .open = aufs_open_nondir,
16307 + .flush = aufs_flush_nondir,
16308 + .release = aufs_release_nondir,
16309 + .fsync = aufs_fsync_nondir,
16310 + .fasync = aufs_fasync,
16311 + /* .sendpage = aufs_sendpage, */
16312 + .setfl = aufs_setfl,
16313 + .splice_write = aufs_splice_write,
16314 + .splice_read = aufs_splice_read,
16315 +#if 0 /* reserved for future use */
16316 + .aio_splice_write = aufs_aio_splice_write,
16317 + .aio_splice_read = aufs_aio_splice_read,
16319 + .fallocate = aufs_fallocate,
16320 + .copy_file_range = aufs_copy_file_range
16322 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16323 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16324 +++ linux/fs/aufs/fstype.h 2020-01-27 10:57:18.172204883 +0100
16326 +/* SPDX-License-Identifier: GPL-2.0 */
16328 + * Copyright (C) 2005-2020 Junjiro R. Okajima
16330 + * This program, aufs is free software; you can redistribute it and/or modify
16331 + * it under the terms of the GNU General Public License as published by
16332 + * the Free Software Foundation; either version 2 of the License, or
16333 + * (at your option) any later version.
16335 + * This program is distributed in the hope that it will be useful,
16336 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16337 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16338 + * GNU General Public License for more details.
16340 + * You should have received a copy of the GNU General Public License
16341 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16345 + * judging filesystem type
16348 +#ifndef __AUFS_FSTYPE_H__
16349 +#define __AUFS_FSTYPE_H__
16353 +#include <linux/fs.h>
16354 +#include <linux/magic.h>
16355 +#include <linux/nfs_fs.h>
16356 +#include <linux/romfs_fs.h>
16358 +static inline int au_test_aufs(struct super_block *sb)
16360 + return sb->s_magic == AUFS_SUPER_MAGIC;
16363 +static inline const char *au_sbtype(struct super_block *sb)
16365 + return sb->s_type->name;
16368 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16370 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16371 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16377 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16379 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16380 + return sb->s_magic == ROMFS_MAGIC;
16386 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16388 +#if IS_ENABLED(CONFIG_CRAMFS)
16389 + return sb->s_magic == CRAMFS_MAGIC;
16394 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16396 +#if IS_ENABLED(CONFIG_NFS_FS)
16397 + return sb->s_magic == NFS_SUPER_MAGIC;
16403 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16405 +#if IS_ENABLED(CONFIG_FUSE_FS)
16406 + return sb->s_magic == FUSE_SUPER_MAGIC;
16412 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16414 +#if IS_ENABLED(CONFIG_XFS_FS)
16415 + return sb->s_magic == XFS_SB_MAGIC;
16421 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16423 +#ifdef CONFIG_TMPFS
16424 + return sb->s_magic == TMPFS_MAGIC;
16430 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16432 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16433 + return !strcmp(au_sbtype(sb), "ecryptfs");
16439 +static inline int au_test_ramfs(struct super_block *sb)
16441 + return sb->s_magic == RAMFS_MAGIC;
16444 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16446 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16447 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16453 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16455 +#ifdef CONFIG_PROC_FS
16456 + return sb->s_magic == PROC_SUPER_MAGIC;
16462 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16464 +#ifdef CONFIG_SYSFS
16465 + return sb->s_magic == SYSFS_MAGIC;
16471 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16473 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16474 + return sb->s_magic == CONFIGFS_MAGIC;
16480 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16482 +#if IS_ENABLED(CONFIG_MINIX_FS)
16483 + return sb->s_magic == MINIX3_SUPER_MAGIC
16484 + || sb->s_magic == MINIX2_SUPER_MAGIC
16485 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16486 + || sb->s_magic == MINIX_SUPER_MAGIC
16487 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16493 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16495 +#if IS_ENABLED(CONFIG_FAT_FS)
16496 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16502 +static inline int au_test_msdos(struct super_block *sb)
16504 + return au_test_fat(sb);
16507 +static inline int au_test_vfat(struct super_block *sb)
16509 + return au_test_fat(sb);
16512 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16514 +#ifdef CONFIG_SECURITYFS
16515 + return sb->s_magic == SECURITYFS_MAGIC;
16521 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16523 +#if IS_ENABLED(CONFIG_SQUASHFS)
16524 + return sb->s_magic == SQUASHFS_MAGIC;
16530 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16532 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16533 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16539 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16541 +#if IS_ENABLED(CONFIG_XENFS)
16542 + return sb->s_magic == XENFS_SUPER_MAGIC;
16548 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16550 +#ifdef CONFIG_DEBUG_FS
16551 + return sb->s_magic == DEBUGFS_MAGIC;
16557 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16559 +#if IS_ENABLED(CONFIG_NILFS)
16560 + return sb->s_magic == NILFS_SUPER_MAGIC;
16566 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16568 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16569 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16575 +/* ---------------------------------------------------------------------- */
16577 + * they can't be an aufs branch.
16579 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16582 +#ifndef CONFIG_AUFS_BR_RAMFS
16583 + au_test_ramfs(sb) ||
16585 + au_test_procfs(sb)
16586 + || au_test_sysfs(sb)
16587 + || au_test_configfs(sb)
16588 + || au_test_debugfs(sb)
16589 + || au_test_securityfs(sb)
16590 + || au_test_xenfs(sb)
16591 + || au_test_ecryptfs(sb)
16592 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16593 + || au_test_aufs(sb); /* will be supported in next version */
16596 +static inline int au_test_fs_remote(struct super_block *sb)
16598 + return !au_test_tmpfs(sb)
16599 +#ifdef CONFIG_AUFS_BR_RAMFS
16600 + && !au_test_ramfs(sb)
16602 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16605 +/* ---------------------------------------------------------------------- */
16608 + * Note: these functions (below) are created after reading ->getattr() in all
16609 + * filesystems under linux/fs. it means we have to do so in every update...
16613 + * some filesystems require getattr to refresh the inode attributes before
16615 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16616 + * and leave the work for d_revalidate()
16618 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16620 + return au_test_nfs(sb)
16621 + || au_test_fuse(sb)
16622 + /* || au_test_btrfs(sb) */ /* untested */
16627 + * filesystems which don't maintain i_size or i_blocks.
16629 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16631 + return au_test_xfs(sb)
16632 + || au_test_btrfs(sb)
16633 + || au_test_ubifs(sb)
16634 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16635 + /* || au_test_minix(sb) */ /* untested */
16640 + * filesystems which don't store the correct value in some of their inode
16643 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16645 + return au_test_fs_bad_iattr_size(sb)
16646 + || au_test_fat(sb)
16647 + || au_test_msdos(sb)
16648 + || au_test_vfat(sb);
16651 +/* they don't check i_nlink in link(2) */
16652 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16654 + return au_test_tmpfs(sb)
16655 +#ifdef CONFIG_AUFS_BR_RAMFS
16656 + || au_test_ramfs(sb)
16658 + || au_test_ubifs(sb)
16659 + || au_test_hfsplus(sb);
16663 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16665 +static inline int au_test_fs_notime(struct super_block *sb)
16667 + return au_test_nfs(sb)
16668 + || au_test_fuse(sb)
16669 + || au_test_ubifs(sb)
16673 +/* temporary support for i#1 in cramfs */
16674 +static inline int au_test_fs_unique_ino(struct inode *inode)
16676 + if (au_test_cramfs(inode->i_sb))
16677 + return inode->i_ino != 1;
16681 +/* ---------------------------------------------------------------------- */
16684 + * the filesystem where the xino files placed must support i/o after unlink and
16685 + * maintain i_size and i_blocks.
16687 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16689 + return au_test_fs_remote(sb)
16690 + || au_test_fs_bad_iattr_size(sb)
16691 + /* don't want unnecessary work for xino */
16692 + || au_test_aufs(sb)
16693 + || au_test_ecryptfs(sb)
16694 + || au_test_nilfs(sb);
16697 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16699 + return au_test_tmpfs(sb)
16700 + || au_test_ramfs(sb);
16704 + * test if the @sb is real-readonly.
16706 +static inline int au_test_fs_rr(struct super_block *sb)
16708 + return au_test_squashfs(sb)
16709 + || au_test_iso9660(sb)
16710 + || au_test_cramfs(sb)
16711 + || au_test_romfs(sb);
16715 + * test if the @inode is nfs with 'noacl' option
16716 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16718 +static inline int au_test_nfs_noacl(struct inode *inode)
16720 + return au_test_nfs(inode->i_sb)
16721 + /* && IS_POSIXACL(inode) */
16722 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16725 +#endif /* __KERNEL__ */
16726 +#endif /* __AUFS_FSTYPE_H__ */
16727 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16728 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16729 +++ linux/fs/aufs/hbl.h 2020-01-27 10:57:18.172204883 +0100
16731 +/* SPDX-License-Identifier: GPL-2.0 */
16733 + * Copyright (C) 2017-2020 Junjiro R. Okajima
16735 + * This program, aufs is free software; you can redistribute it and/or modify
16736 + * it under the terms of the GNU General Public License as published by
16737 + * the Free Software Foundation; either version 2 of the License, or
16738 + * (at your option) any later version.
16740 + * This program is distributed in the hope that it will be useful,
16741 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16742 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16743 + * GNU General Public License for more details.
16745 + * You should have received a copy of the GNU General Public License
16746 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16750 + * helpers for hlist_bl.h
16753 +#ifndef __AUFS_HBL_H__
16754 +#define __AUFS_HBL_H__
16758 +#include <linux/list_bl.h>
16760 +static inline void au_hbl_add(struct hlist_bl_node *node,
16761 + struct hlist_bl_head *hbl)
16763 + hlist_bl_lock(hbl);
16764 + hlist_bl_add_head(node, hbl);
16765 + hlist_bl_unlock(hbl);
16768 +static inline void au_hbl_del(struct hlist_bl_node *node,
16769 + struct hlist_bl_head *hbl)
16771 + hlist_bl_lock(hbl);
16772 + hlist_bl_del(node);
16773 + hlist_bl_unlock(hbl);
16776 +#define au_hbl_for_each(pos, head) \
16777 + for (pos = hlist_bl_first(head); \
16781 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16783 + unsigned long cnt;
16784 + struct hlist_bl_node *pos;
16787 + hlist_bl_lock(hbl);
16788 + au_hbl_for_each(pos, hbl)
16790 + hlist_bl_unlock(hbl);
16794 +#endif /* __KERNEL__ */
16795 +#endif /* __AUFS_HBL_H__ */
16796 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16797 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16798 +++ linux/fs/aufs/hfsnotify.c 2020-01-27 10:57:18.172204883 +0100
16800 +// SPDX-License-Identifier: GPL-2.0
16802 + * Copyright (C) 2005-2020 Junjiro R. Okajima
16804 + * This program, aufs is free software; you can redistribute it and/or modify
16805 + * it under the terms of the GNU General Public License as published by
16806 + * the Free Software Foundation; either version 2 of the License, or
16807 + * (at your option) any later version.
16809 + * This program is distributed in the hope that it will be useful,
16810 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16811 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16812 + * GNU General Public License for more details.
16814 + * You should have received a copy of the GNU General Public License
16815 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16819 + * fsnotify for the lower directories
16824 +/* FS_IN_IGNORED is unnecessary */
16825 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16826 + | FS_CREATE | FS_EVENT_ON_CHILD);
16827 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16828 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16830 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16832 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16834 + /* AuDbg("here\n"); */
16835 + au_cache_free_hnotify(hn);
16836 + smp_mb__before_atomic(); /* for atomic64_dec */
16837 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16838 + wake_up(&au_hfsn_wq);
16841 +static int au_hfsn_alloc(struct au_hinode *hinode)
16844 + struct au_hnotify *hn;
16845 + struct super_block *sb;
16846 + struct au_branch *br;
16847 + struct fsnotify_mark *mark;
16848 + aufs_bindex_t bindex;
16850 + hn = hinode->hi_notify;
16851 + sb = hn->hn_aufs_inode->i_sb;
16852 + bindex = au_br_index(sb, hinode->hi_id);
16853 + br = au_sbr(sb, bindex);
16854 + AuDebugOn(!br->br_hfsn);
16856 + mark = &hn->hn_mark;
16857 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16858 + mark->mask = AuHfsnMask;
16860 + * by udba rename or rmdir, aufs assign a new inode to the known
16861 + * h_inode, so specify 1 to allow dups.
16864 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16870 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16872 + struct fsnotify_mark *mark;
16873 + unsigned long long ull;
16874 + struct fsnotify_group *group;
16876 + ull = atomic64_inc_return(&au_hfsn_ifree);
16879 + mark = &hn->hn_mark;
16880 + spin_lock(&mark->lock);
16881 + group = mark->group;
16882 + fsnotify_get_group(group);
16883 + spin_unlock(&mark->lock);
16885 + fsnotify_destroy_mark(mark, group);
16886 + fsnotify_put_mark(mark);
16887 + fsnotify_put_group(group);
16890 + /* free hn by myself */
16894 +/* ---------------------------------------------------------------------- */
16896 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16898 + struct fsnotify_mark *mark;
16900 + mark = &hinode->hi_notify->hn_mark;
16901 + spin_lock(&mark->lock);
16903 + AuDebugOn(mark->mask & AuHfsnMask);
16904 + mark->mask |= AuHfsnMask;
16906 + AuDebugOn(!(mark->mask & AuHfsnMask));
16907 + mark->mask &= ~AuHfsnMask;
16909 + spin_unlock(&mark->lock);
16910 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16913 +/* ---------------------------------------------------------------------- */
16915 +/* #define AuDbgHnotify */
16916 +#ifdef AuDbgHnotify
16917 +static char *au_hfsn_name(u32 mask)
16919 +#ifdef CONFIG_AUFS_DEBUG
16920 +#define test_ret(flag) \
16922 + if (mask & flag) \
16925 + test_ret(FS_ACCESS);
16926 + test_ret(FS_MODIFY);
16927 + test_ret(FS_ATTRIB);
16928 + test_ret(FS_CLOSE_WRITE);
16929 + test_ret(FS_CLOSE_NOWRITE);
16930 + test_ret(FS_OPEN);
16931 + test_ret(FS_MOVED_FROM);
16932 + test_ret(FS_MOVED_TO);
16933 + test_ret(FS_CREATE);
16934 + test_ret(FS_DELETE);
16935 + test_ret(FS_DELETE_SELF);
16936 + test_ret(FS_MOVE_SELF);
16937 + test_ret(FS_UNMOUNT);
16938 + test_ret(FS_Q_OVERFLOW);
16939 + test_ret(FS_IN_IGNORED);
16940 + test_ret(FS_ISDIR);
16941 + test_ret(FS_IN_ONESHOT);
16942 + test_ret(FS_EVENT_ON_CHILD);
16951 +/* ---------------------------------------------------------------------- */
16953 +static void au_hfsn_free_group(struct fsnotify_group *group)
16955 + struct au_br_hfsnotify *hfsn = group->private;
16957 + /* AuDbg("here\n"); */
16958 + au_kfree_try_rcu(hfsn);
16961 +static int au_hfsn_handle_event(struct fsnotify_group *group,
16962 + struct inode *inode,
16963 + u32 mask, const void *data, int data_type,
16964 + const struct qstr *file_name, u32 cookie,
16965 + struct fsnotify_iter_info *iter_info)
16968 + struct au_hnotify *hnotify;
16969 + struct inode *h_dir, *h_inode;
16970 + struct fsnotify_mark *inode_mark;
16972 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
16975 + /* if FS_UNMOUNT happens, there must be another bug */
16976 + AuDebugOn(mask & FS_UNMOUNT);
16977 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
16982 +#ifdef AuDbgHnotify
16984 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
16985 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
16986 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
16987 + h_dir->i_ino, mask, au_hfsn_name(mask),
16988 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
16989 + /* WARN_ON(1); */
16994 + inode_mark = fsnotify_iter_inode_mark(iter_info);
16995 + AuDebugOn(!inode_mark);
16996 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
16997 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
17003 +static struct fsnotify_ops au_hfsn_ops = {
17004 + .handle_event = au_hfsn_handle_event,
17005 + .free_group_priv = au_hfsn_free_group,
17006 + .free_mark = au_hfsn_free_mark
17009 +/* ---------------------------------------------------------------------- */
17011 +static void au_hfsn_fin_br(struct au_branch *br)
17013 + struct au_br_hfsnotify *hfsn;
17015 + hfsn = br->br_hfsn;
17018 + fsnotify_put_group(hfsn->hfsn_group);
17023 +static int au_hfsn_init_br(struct au_branch *br, int perm)
17026 + struct fsnotify_group *group;
17027 + struct au_br_hfsnotify *hfsn;
17030 + br->br_hfsn = NULL;
17031 + if (!au_br_hnotifyable(perm))
17035 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
17036 + if (unlikely(!hfsn))
17040 + group = fsnotify_alloc_group(&au_hfsn_ops);
17041 + if (IS_ERR(group)) {
17042 + err = PTR_ERR(group);
17043 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
17047 + group->private = hfsn;
17048 + hfsn->hfsn_group = group;
17049 + br->br_hfsn = hfsn;
17050 + goto out; /* success */
17053 + au_kfree_try_rcu(hfsn);
17058 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
17063 + if (!br->br_hfsn)
17064 + err = au_hfsn_init_br(br, perm);
17069 +/* ---------------------------------------------------------------------- */
17071 +static void au_hfsn_fin(void)
17073 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
17074 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
17077 +const struct au_hnotify_op au_hnotify_op = {
17078 + .ctl = au_hfsn_ctl,
17079 + .alloc = au_hfsn_alloc,
17080 + .free = au_hfsn_free,
17082 + .fin = au_hfsn_fin,
17084 + .reset_br = au_hfsn_reset_br,
17085 + .fin_br = au_hfsn_fin_br,
17086 + .init_br = au_hfsn_init_br
17088 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
17089 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
17090 +++ linux/fs/aufs/hfsplus.c 2020-01-27 10:57:18.172204883 +0100
17092 +// SPDX-License-Identifier: GPL-2.0
17094 + * Copyright (C) 2010-2020 Junjiro R. Okajima
17096 + * This program, aufs is free software; you can redistribute it and/or modify
17097 + * it under the terms of the GNU General Public License as published by
17098 + * the Free Software Foundation; either version 2 of the License, or
17099 + * (at your option) any later version.
17101 + * This program is distributed in the hope that it will be useful,
17102 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17103 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17104 + * GNU General Public License for more details.
17106 + * You should have received a copy of the GNU General Public License
17107 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17111 + * special support for filesystems which acquires an inode mutex
17112 + * at final closing a file, eg, hfsplus.
17114 + * This trick is very simple and stupid, just to open the file before really
17115 + * necessary open to tell hfsplus that this is not the final closing.
17116 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
17117 + * and au_h_open_post() after releasing it.
17122 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
17125 + struct file *h_file;
17126 + struct dentry *h_dentry;
17128 + h_dentry = au_h_dptr(dentry, bindex);
17129 + AuDebugOn(!h_dentry);
17130 + AuDebugOn(d_is_negative(h_dentry));
17133 + if (au_test_hfsplus(h_dentry->d_sb)
17134 + && d_is_reg(h_dentry))
17135 + h_file = au_h_open(dentry, bindex,
17136 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17137 + /*file*/NULL, force_wr);
17141 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17142 + struct file *h_file)
17144 + struct au_branch *br;
17148 + br = au_sbr(dentry->d_sb, bindex);
17149 + au_lcnt_dec(&br->br_nfiles);
17152 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17153 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17154 +++ linux/fs/aufs/hnotify.c 2020-01-27 10:57:18.172204883 +0100
17156 +// SPDX-License-Identifier: GPL-2.0
17158 + * Copyright (C) 2005-2020 Junjiro R. Okajima
17160 + * This program, aufs is free software; you can redistribute it and/or modify
17161 + * it under the terms of the GNU General Public License as published by
17162 + * the Free Software Foundation; either version 2 of the License, or
17163 + * (at your option) any later version.
17165 + * This program is distributed in the hope that it will be useful,
17166 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17167 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17168 + * GNU General Public License for more details.
17170 + * You should have received a copy of the GNU General Public License
17171 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17175 + * abstraction to notify the direct changes on lower directories
17178 +/* #include <linux/iversion.h> */
17181 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17184 + struct au_hnotify *hn;
17187 + hn = au_cache_alloc_hnotify();
17189 + hn->hn_aufs_inode = inode;
17190 + hinode->hi_notify = hn;
17191 + err = au_hnotify_op.alloc(hinode);
17193 + if (unlikely(err)) {
17194 + hinode->hi_notify = NULL;
17195 + au_cache_free_hnotify(hn);
17197 + * The upper dir was removed by udba, but the same named
17198 + * dir left. In this case, aufs assigns a new inode
17199 + * number and set the monitor again.
17200 + * For the lower dir, the old monitor is still left.
17202 + if (err == -EEXIST)
17211 +void au_hn_free(struct au_hinode *hinode)
17213 + struct au_hnotify *hn;
17215 + hn = hinode->hi_notify;
17217 + hinode->hi_notify = NULL;
17218 + if (au_hnotify_op.free(hinode, hn))
17219 + au_cache_free_hnotify(hn);
17223 +/* ---------------------------------------------------------------------- */
17225 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17227 + if (hinode->hi_notify)
17228 + au_hnotify_op.ctl(hinode, do_set);
17231 +void au_hn_reset(struct inode *inode, unsigned int flags)
17233 + aufs_bindex_t bindex, bbot;
17234 + struct inode *hi;
17235 + struct dentry *iwhdentry;
17237 + bbot = au_ibbot(inode);
17238 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17239 + hi = au_h_iptr(inode, bindex);
17243 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17244 + iwhdentry = au_hi_wh(inode, bindex);
17248 + au_set_h_iptr(inode, bindex, NULL, 0);
17249 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17250 + flags & ~AuHi_XINO);
17253 + /* inode_unlock(hi); */
17257 +/* ---------------------------------------------------------------------- */
17259 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17262 + aufs_bindex_t bindex, bbot, bfound, btop;
17263 + struct inode *h_i;
17266 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17267 + pr_warn("branch root dir was changed\n");
17272 + bbot = au_ibbot(inode);
17273 + btop = au_ibtop(inode);
17274 +#if 0 /* reserved for future use */
17275 + if (bindex == bbot) {
17276 + /* keep this ino in rename case */
17280 + for (bindex = btop; bindex <= bbot; bindex++)
17281 + if (au_h_iptr(inode, bindex) == h_inode) {
17288 + for (bindex = btop; bindex <= bbot; bindex++) {
17289 + h_i = au_h_iptr(inode, bindex);
17293 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17294 + /* ignore this error */
17295 + /* bad action? */
17298 + /* children inode number will be broken */
17305 +static int hn_gen_tree(struct dentry *dentry)
17307 + int err, i, j, ndentry;
17308 + struct au_dcsub_pages dpages;
17309 + struct au_dpage *dpage;
17310 + struct dentry **dentries;
17312 + err = au_dpages_init(&dpages, GFP_NOFS);
17313 + if (unlikely(err))
17315 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17316 + if (unlikely(err))
17319 + for (i = 0; i < dpages.ndpage; i++) {
17320 + dpage = dpages.dpages + i;
17321 + dentries = dpage->dentries;
17322 + ndentry = dpage->ndentry;
17323 + for (j = 0; j < ndentry; j++) {
17324 + struct dentry *d;
17331 + if (d_really_is_positive(d))
17332 + /* todo: reset children xino?
17333 + cached children only? */
17334 + au_iigen_dec(d_inode(d));
17339 + au_dpages_free(&dpages);
17345 + * return 0 if processed.
17347 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17348 + const unsigned int isdir)
17351 + struct dentry *d;
17352 + struct qstr *dname;
17355 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17356 + pr_warn("branch root dir was changed\n");
17362 + AuDebugOn(!name);
17363 + au_iigen_dec(inode);
17364 + spin_lock(&inode->i_lock);
17365 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17366 + spin_lock(&d->d_lock);
17367 + dname = &d->d_name;
17368 + if (dname->len != nlen
17369 + && memcmp(dname->name, name, nlen)) {
17370 + spin_unlock(&d->d_lock);
17375 + spin_unlock(&d->d_lock);
17378 + spin_unlock(&inode->i_lock);
17380 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17381 + d = d_find_any_alias(inode);
17383 + au_iigen_dec(inode);
17387 + spin_lock(&d->d_lock);
17388 + dname = &d->d_name;
17389 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17390 + spin_unlock(&d->d_lock);
17391 + err = hn_gen_tree(d);
17392 + spin_lock(&d->d_lock);
17394 + spin_unlock(&d->d_lock);
17403 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17407 + if (IS_ROOT(dentry)) {
17408 + pr_warn("branch root dir was changed\n");
17414 + au_digen_dec(dentry);
17415 + if (d_really_is_positive(dentry))
17416 + au_iigen_dec(d_inode(dentry));
17418 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17419 + if (d_really_is_positive(dentry))
17420 + err = hn_gen_tree(dentry);
17427 +/* ---------------------------------------------------------------------- */
17429 +/* hnotify job flags */
17430 +#define AuHnJob_XINO0 1
17431 +#define AuHnJob_GEN (1 << 1)
17432 +#define AuHnJob_DIRENT (1 << 2)
17433 +#define AuHnJob_ISDIR (1 << 3)
17434 +#define AuHnJob_TRYXINO0 (1 << 4)
17435 +#define AuHnJob_MNTPNT (1 << 5)
17436 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17437 +#define au_fset_hnjob(flags, name) \
17438 + do { (flags) |= AuHnJob_##name; } while (0)
17439 +#define au_fclr_hnjob(flags, name) \
17440 + do { (flags) &= ~AuHnJob_##name; } while (0)
17448 +struct au_hnotify_args {
17449 + struct inode *h_dir, *dir, *h_child_inode;
17451 + unsigned int flags[AuHnLast];
17452 + unsigned int h_child_nlen;
17453 + char h_child_name[];
17456 +struct hn_job_args {
17457 + unsigned int flags;
17458 + struct inode *inode, *h_inode, *dir, *h_dir;
17459 + struct dentry *dentry;
17464 +static int hn_job(struct hn_job_args *a)
17466 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17470 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17471 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17473 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17476 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17477 + if (!a->h_inode->i_nlink
17478 + && !(a->h_inode->i_state & I_LINKABLE))
17479 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17480 + inode_unlock_shared(a->h_inode);
17483 + /* make the generation obsolete */
17484 + if (au_ftest_hnjob(a->flags, GEN)) {
17487 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17489 + if (e && a->dentry)
17490 + hn_gen_by_name(a->dentry, isdir);
17491 + /* ignore this error */
17494 + /* make dir entries obsolete */
17495 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17496 + struct au_vdir *vdir;
17498 + vdir = au_ivdir(a->inode);
17500 + vdir->vd_jiffy = 0;
17501 + /* IMustLock(a->inode); */
17502 + /* inode_inc_iversion(a->inode); */
17505 + /* can do nothing but warn */
17506 + if (au_ftest_hnjob(a->flags, MNTPNT)
17508 + && d_mountpoint(a->dentry))
17509 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17514 +/* ---------------------------------------------------------------------- */
17516 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17517 + struct inode *dir)
17519 + struct dentry *dentry, *d, *parent;
17520 + struct qstr *dname;
17522 + parent = d_find_any_alias(dir);
17527 + spin_lock(&parent->d_lock);
17528 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17529 + /* AuDbg("%pd\n", d); */
17530 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17531 + dname = &d->d_name;
17532 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17533 + goto cont_unlock;
17537 + goto cont_unlock;
17538 + if (au_dcount(d) > 0) {
17539 + dentry = dget_dlock(d);
17540 + spin_unlock(&d->d_lock);
17545 + spin_unlock(&d->d_lock);
17547 + spin_unlock(&parent->d_lock);
17551 + di_write_lock_child(dentry);
17556 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17557 + aufs_bindex_t bindex, ino_t h_ino)
17559 + struct inode *inode;
17564 + err = au_xino_read(sb, bindex, h_ino, &ino);
17566 + inode = ilookup(sb, ino);
17570 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17571 + pr_warn("wrong root branch\n");
17577 + ii_write_lock_child(inode);
17583 +static void au_hn_bh(void *_args)
17585 + struct au_hnotify_args *a = _args;
17586 + struct super_block *sb;
17587 + aufs_bindex_t bindex, bbot, bfound;
17588 + unsigned char xino, try_iput;
17590 + struct inode *inode;
17592 + struct hn_job_args args;
17593 + struct dentry *dentry;
17594 + struct au_sbinfo *sbinfo;
17596 + AuDebugOn(!_args);
17597 + AuDebugOn(!a->h_dir);
17598 + AuDebugOn(!a->dir);
17599 + AuDebugOn(!a->mask);
17600 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17601 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17602 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17607 + * do not lock a->dir->i_mutex here
17608 + * because of d_revalidate() may cause a deadlock.
17610 + sb = a->dir->i_sb;
17612 + sbinfo = au_sbi(sb);
17613 + AuDebugOn(!sbinfo);
17614 + si_write_lock(sb, AuLock_NOPLMW);
17616 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17617 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17618 + case FS_MOVED_FROM:
17619 + case FS_MOVED_TO:
17620 + AuWarn1("DIRREN with UDBA may not work correctly "
17621 + "for the direct rename(2)\n");
17624 + ii_read_lock_parent(a->dir);
17626 + bbot = au_ibbot(a->dir);
17627 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17628 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17632 + ii_read_unlock(a->dir);
17633 + if (unlikely(bfound < 0))
17636 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17638 + if (a->h_child_inode)
17639 + h_ino = a->h_child_inode->i_ino;
17641 + if (a->h_child_nlen
17642 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17643 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17644 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17647 + if (dentry && d_really_is_positive(dentry))
17648 + inode = d_inode(dentry);
17649 + if (xino && !inode && h_ino
17650 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17651 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17652 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17653 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17657 + args.flags = a->flags[AuHn_CHILD];
17658 + args.dentry = dentry;
17659 + args.inode = inode;
17660 + args.h_inode = a->h_child_inode;
17661 + args.dir = a->dir;
17662 + args.h_dir = a->h_dir;
17663 + args.h_name = a->h_child_name;
17664 + args.h_nlen = a->h_child_nlen;
17665 + err = hn_job(&args);
17667 + if (au_di(dentry))
17668 + di_write_unlock(dentry);
17671 + if (inode && try_iput) {
17672 + ii_write_unlock(inode);
17676 + ii_write_lock_parent(a->dir);
17677 + args.flags = a->flags[AuHn_PARENT];
17678 + args.dentry = NULL;
17679 + args.inode = a->dir;
17680 + args.h_inode = a->h_dir;
17682 + args.h_dir = NULL;
17683 + args.h_name = NULL;
17685 + err = hn_job(&args);
17686 + ii_write_unlock(a->dir);
17689 + iput(a->h_child_inode);
17692 + si_write_unlock(sb);
17693 + au_nwt_done(&sbinfo->si_nowait);
17697 +/* ---------------------------------------------------------------------- */
17699 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17700 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
17703 + unsigned int flags[AuHnLast], f;
17704 + unsigned char isdir, isroot, wh;
17705 + struct inode *dir;
17706 + struct au_hnotify_args *args;
17707 + char *p, *h_child_name;
17710 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17711 + dir = igrab(hnotify->hn_aufs_inode);
17715 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17717 + h_child_name = (void *)h_child_qstr->name;
17718 + len = h_child_qstr->len;
17719 + if (h_child_name) {
17720 + if (len > AUFS_WH_PFX_LEN
17721 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17722 + h_child_name += AUFS_WH_PFX_LEN;
17723 + len -= AUFS_WH_PFX_LEN;
17729 + if (h_child_inode)
17730 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17731 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17732 + flags[AuHn_CHILD] = 0;
17734 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17735 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17736 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17737 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
17738 + case FS_MOVED_FROM:
17739 + case FS_MOVED_TO:
17740 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17741 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17744 + AuDebugOn(!h_child_name);
17749 + * aufs never be able to get this child inode.
17750 + * revalidation should be in d_revalidate()
17751 + * by checking i_nlink, i_generation or d_unhashed().
17753 + AuDebugOn(!h_child_name);
17754 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17755 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17763 + h_child_inode = NULL;
17766 + /* iput() and kfree() will be called in au_hnotify() */
17767 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17768 + if (unlikely(!args)) {
17769 + AuErr1("no memory\n");
17773 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17774 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17775 + args->mask = mask;
17777 + args->h_dir = igrab(h_dir);
17778 + if (h_child_inode)
17779 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17780 + args->h_child_inode = h_child_inode;
17781 + args->h_child_nlen = len;
17783 + p = (void *)args;
17784 + p += sizeof(*args);
17785 + memcpy(p, h_child_name, len);
17789 + /* NFS fires the event for silly-renamed one from kworker */
17791 + if (!dir->i_nlink
17792 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17794 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17795 + if (unlikely(err)) {
17796 + pr_err("wkq %d\n", err);
17797 + iput(args->h_child_inode);
17798 + iput(args->h_dir);
17800 + au_kfree_rcu(args);
17807 +/* ---------------------------------------------------------------------- */
17809 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17813 + AuDebugOn(!(udba & AuOptMask_UDBA));
17816 + if (au_hnotify_op.reset_br)
17817 + err = au_hnotify_op.reset_br(udba, br, perm);
17822 +int au_hnotify_init_br(struct au_branch *br, int perm)
17827 + if (au_hnotify_op.init_br)
17828 + err = au_hnotify_op.init_br(br, perm);
17833 +void au_hnotify_fin_br(struct au_branch *br)
17835 + if (au_hnotify_op.fin_br)
17836 + au_hnotify_op.fin_br(br);
17839 +static void au_hn_destroy_cache(void)
17841 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17842 + au_cache[AuCache_HNOTIFY] = NULL;
17845 +int __init au_hnotify_init(void)
17850 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17851 + if (au_cache[AuCache_HNOTIFY]) {
17853 + if (au_hnotify_op.init)
17854 + err = au_hnotify_op.init();
17855 + if (unlikely(err))
17856 + au_hn_destroy_cache();
17862 +void au_hnotify_fin(void)
17864 + if (au_hnotify_op.fin)
17865 + au_hnotify_op.fin();
17867 + /* cf. au_cache_fin() */
17868 + if (au_cache[AuCache_HNOTIFY])
17869 + au_hn_destroy_cache();
17871 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17872 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17873 +++ linux/fs/aufs/iinfo.c 2020-01-27 10:57:18.175538316 +0100
17875 +// SPDX-License-Identifier: GPL-2.0
17877 + * Copyright (C) 2005-2020 Junjiro R. Okajima
17879 + * This program, aufs is free software; you can redistribute it and/or modify
17880 + * it under the terms of the GNU General Public License as published by
17881 + * the Free Software Foundation; either version 2 of the License, or
17882 + * (at your option) any later version.
17884 + * This program is distributed in the hope that it will be useful,
17885 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17886 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17887 + * GNU General Public License for more details.
17889 + * You should have received a copy of the GNU General Public License
17890 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17894 + * inode private data
17899 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17901 + struct inode *h_inode;
17902 + struct au_hinode *hinode;
17904 + IiMustAnyLock(inode);
17906 + hinode = au_hinode(au_ii(inode), bindex);
17907 + h_inode = hinode->hi_inode;
17908 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17912 +/* todo: hard/soft set? */
17913 +void au_hiput(struct au_hinode *hinode)
17915 + au_hn_free(hinode);
17916 + dput(hinode->hi_whdentry);
17917 + iput(hinode->hi_inode);
17920 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17922 + unsigned int flags;
17923 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17926 + if (au_opt_test(mnt_flags, XINO))
17927 + au_fset_hi(flags, XINO);
17928 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17929 + au_fset_hi(flags, HNOTIFY);
17933 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17934 + struct inode *h_inode, unsigned int flags)
17936 + struct au_hinode *hinode;
17937 + struct inode *hi;
17938 + struct au_iinfo *iinfo = au_ii(inode);
17940 + IiMustWriteLock(inode);
17942 + hinode = au_hinode(iinfo, bindex);
17943 + hi = hinode->hi_inode;
17944 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17947 + au_hiput(hinode);
17948 + hinode->hi_inode = h_inode;
17951 + struct super_block *sb = inode->i_sb;
17952 + struct au_branch *br;
17954 + AuDebugOn(inode->i_mode
17955 + && (h_inode->i_mode & S_IFMT)
17956 + != (inode->i_mode & S_IFMT));
17957 + if (bindex == iinfo->ii_btop)
17958 + au_cpup_igen(inode, h_inode);
17959 + br = au_sbr(sb, bindex);
17960 + hinode->hi_id = br->br_id;
17961 + if (au_ftest_hi(flags, XINO)) {
17962 + err = au_xino_write(sb, bindex, h_inode->i_ino,
17964 + if (unlikely(err))
17965 + AuIOErr1("failed au_xino_write() %d\n", err);
17968 + if (au_ftest_hi(flags, HNOTIFY)
17969 + && au_br_hnotifyable(br->br_perm)) {
17970 + err = au_hn_alloc(hinode, inode);
17971 + if (unlikely(err))
17972 + AuIOErr1("au_hn_alloc() %d\n", err);
17977 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17978 + struct dentry *h_wh)
17980 + struct au_hinode *hinode;
17982 + IiMustWriteLock(inode);
17984 + hinode = au_hinode(au_ii(inode), bindex);
17985 + AuDebugOn(hinode->hi_whdentry);
17986 + hinode->hi_whdentry = h_wh;
17989 +void au_update_iigen(struct inode *inode, int half)
17991 + struct au_iinfo *iinfo;
17992 + struct au_iigen *iigen;
17993 + unsigned int sigen;
17995 + sigen = au_sigen(inode->i_sb);
17996 + iinfo = au_ii(inode);
17997 + iigen = &iinfo->ii_generation;
17998 + spin_lock(&iigen->ig_spin);
17999 + iigen->ig_generation = sigen;
18001 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
18003 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
18004 + spin_unlock(&iigen->ig_spin);
18007 +/* it may be called at remount time, too */
18008 +void au_update_ibrange(struct inode *inode, int do_put_zero)
18010 + struct au_iinfo *iinfo;
18011 + aufs_bindex_t bindex, bbot;
18013 + AuDebugOn(au_is_bad_inode(inode));
18014 + IiMustWriteLock(inode);
18016 + iinfo = au_ii(inode);
18017 + if (do_put_zero && iinfo->ii_btop >= 0) {
18018 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18020 + struct inode *h_i;
18022 + h_i = au_hinode(iinfo, bindex)->hi_inode;
18025 + && !(h_i->i_state & I_LINKABLE))
18026 + au_set_h_iptr(inode, bindex, NULL, 0);
18030 + iinfo->ii_btop = -1;
18031 + iinfo->ii_bbot = -1;
18032 + bbot = au_sbbot(inode->i_sb);
18033 + for (bindex = 0; bindex <= bbot; bindex++)
18034 + if (au_hinode(iinfo, bindex)->hi_inode) {
18035 + iinfo->ii_btop = bindex;
18038 + if (iinfo->ii_btop >= 0)
18039 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
18040 + if (au_hinode(iinfo, bindex)->hi_inode) {
18041 + iinfo->ii_bbot = bindex;
18044 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
18047 +/* ---------------------------------------------------------------------- */
18049 +void au_icntnr_init_once(void *_c)
18051 + struct au_icntnr *c = _c;
18052 + struct au_iinfo *iinfo = &c->iinfo;
18054 + spin_lock_init(&iinfo->ii_generation.ig_spin);
18055 + au_rw_init(&iinfo->ii_rwsem);
18056 + inode_init_once(&c->vfs_inode);
18059 +void au_hinode_init(struct au_hinode *hinode)
18061 + hinode->hi_inode = NULL;
18062 + hinode->hi_id = -1;
18063 + au_hn_init(hinode);
18064 + hinode->hi_whdentry = NULL;
18067 +int au_iinfo_init(struct inode *inode)
18069 + struct au_iinfo *iinfo;
18070 + struct super_block *sb;
18071 + struct au_hinode *hi;
18074 + sb = inode->i_sb;
18075 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18076 + nbr = au_sbbot(sb) + 1;
18077 + if (unlikely(nbr <= 0))
18079 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
18081 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
18083 + iinfo->ii_hinode = hi;
18084 + for (i = 0; i < nbr; i++, hi++)
18085 + au_hinode_init(hi);
18087 + iinfo->ii_generation.ig_generation = au_sigen(sb);
18088 + iinfo->ii_btop = -1;
18089 + iinfo->ii_bbot = -1;
18090 + iinfo->ii_vdir = NULL;
18096 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
18099 + struct au_hinode *hip;
18101 + AuRwMustWriteLock(&iinfo->ii_rwsem);
18104 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
18107 + iinfo->ii_hinode = hip;
18108 + i = iinfo->ii_bbot + 1;
18110 + for (; i < nbr; i++, hip++)
18111 + au_hinode_init(hip);
18118 +void au_iinfo_fin(struct inode *inode)
18120 + struct au_iinfo *iinfo;
18121 + struct au_hinode *hi;
18122 + struct super_block *sb;
18123 + aufs_bindex_t bindex, bbot;
18124 + const unsigned char unlinked = !inode->i_nlink;
18126 + AuDebugOn(au_is_bad_inode(inode));
18128 + sb = inode->i_sb;
18129 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
18130 + if (si_pid_test(sb))
18131 + au_xino_delete_inode(inode, unlinked);
18134 + * it is safe to hide the dependency between sbinfo and
18138 + si_noflush_read_lock(sb);
18139 + au_xino_delete_inode(inode, unlinked);
18140 + si_read_unlock(sb);
18144 + iinfo = au_ii(inode);
18145 + if (iinfo->ii_vdir)
18146 + au_vdir_free(iinfo->ii_vdir);
18148 + bindex = iinfo->ii_btop;
18149 + if (bindex >= 0) {
18150 + hi = au_hinode(iinfo, bindex);
18151 + bbot = iinfo->ii_bbot;
18152 + while (bindex++ <= bbot) {
18153 + if (hi->hi_inode)
18158 + au_kfree_rcu(iinfo->ii_hinode);
18159 + AuRwDestroy(&iinfo->ii_rwsem);
18161 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18162 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18163 +++ linux/fs/aufs/inode.c 2020-01-27 10:57:18.175538316 +0100
18165 +// SPDX-License-Identifier: GPL-2.0
18167 + * Copyright (C) 2005-2020 Junjiro R. Okajima
18169 + * This program, aufs is free software; you can redistribute it and/or modify
18170 + * it under the terms of the GNU General Public License as published by
18171 + * the Free Software Foundation; either version 2 of the License, or
18172 + * (at your option) any later version.
18174 + * This program is distributed in the hope that it will be useful,
18175 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18176 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18177 + * GNU General Public License for more details.
18179 + * You should have received a copy of the GNU General Public License
18180 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18184 + * inode functions
18187 +#include <linux/iversion.h>
18190 +struct inode *au_igrab(struct inode *inode)
18193 + AuDebugOn(!atomic_read(&inode->i_count));
18199 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18201 + au_cpup_attr_all(inode, /*force*/0);
18202 + au_update_iigen(inode, /*half*/1);
18204 + inode_inc_iversion(inode);
18207 +static int au_ii_refresh(struct inode *inode, int *update)
18211 + aufs_bindex_t bindex, new_bindex;
18212 + struct super_block *sb;
18213 + struct au_iinfo *iinfo;
18214 + struct au_hinode *p, *q, tmp;
18216 + AuDebugOn(au_is_bad_inode(inode));
18217 + IiMustWriteLock(inode);
18220 + sb = inode->i_sb;
18221 + nbr = au_sbbot(sb) + 1;
18222 + type = inode->i_mode & S_IFMT;
18223 + iinfo = au_ii(inode);
18224 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18225 + if (unlikely(err))
18228 + AuDebugOn(iinfo->ii_btop < 0);
18229 + p = au_hinode(iinfo, iinfo->ii_btop);
18230 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18232 + if (!p->hi_inode)
18235 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18236 + new_bindex = au_br_index(sb, p->hi_id);
18237 + if (new_bindex == bindex)
18240 + if (new_bindex < 0) {
18243 + p->hi_inode = NULL;
18247 + if (new_bindex < iinfo->ii_btop)
18248 + iinfo->ii_btop = new_bindex;
18249 + if (iinfo->ii_bbot < new_bindex)
18250 + iinfo->ii_bbot = new_bindex;
18251 + /* swap two lower inode, and loop again */
18252 + q = au_hinode(iinfo, new_bindex);
18256 + if (tmp.hi_inode) {
18261 + au_update_ibrange(inode, /*do_put_zero*/0);
18262 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18263 + e = au_dy_irefresh(inode);
18264 + if (unlikely(e && !err))
18272 +void au_refresh_iop(struct inode *inode, int force_getattr)
18275 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18276 + const struct inode_operations *iop
18277 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18279 + if (inode->i_op == iop)
18282 + switch (inode->i_mode & S_IFMT) {
18284 + type = AuIop_DIR;
18287 + type = AuIop_SYMLINK;
18290 + type = AuIop_OTHER;
18294 + inode->i_op = iop + type;
18295 + /* unnecessary smp_wmb() */
18298 +int au_refresh_hinode_self(struct inode *inode)
18302 + err = au_ii_refresh(inode, &update);
18304 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18310 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18312 + int err, e, update;
18313 + unsigned int flags;
18315 + aufs_bindex_t bindex, bbot;
18316 + unsigned char isdir;
18317 + struct au_hinode *p;
18318 + struct au_iinfo *iinfo;
18320 + err = au_ii_refresh(inode, &update);
18321 + if (unlikely(err))
18325 + iinfo = au_ii(inode);
18326 + p = au_hinode(iinfo, iinfo->ii_btop);
18327 + mode = (inode->i_mode & S_IFMT);
18328 + isdir = S_ISDIR(mode);
18329 + flags = au_hi_flags(inode, isdir);
18330 + bbot = au_dbbot(dentry);
18331 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18332 + struct inode *h_i, *h_inode;
18333 + struct dentry *h_d;
18335 + h_d = au_h_dptr(dentry, bindex);
18336 + if (!h_d || d_is_negative(h_d))
18339 + h_inode = d_inode(h_d);
18340 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18341 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18342 + h_i = au_h_iptr(inode, bindex);
18344 + if (h_i == h_inode)
18350 + if (bindex < iinfo->ii_btop)
18351 + iinfo->ii_btop = bindex;
18352 + if (iinfo->ii_bbot < bindex)
18353 + iinfo->ii_bbot = bindex;
18354 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18357 + au_update_ibrange(inode, /*do_put_zero*/0);
18358 + e = au_dy_irefresh(inode);
18359 + if (unlikely(e && !err))
18362 + au_refresh_hinode_attr(inode, update && isdir);
18369 +static int set_inode(struct inode *inode, struct dentry *dentry)
18372 + unsigned int flags;
18374 + aufs_bindex_t bindex, btop, btail;
18375 + unsigned char isdir;
18376 + struct dentry *h_dentry;
18377 + struct inode *h_inode;
18378 + struct au_iinfo *iinfo;
18379 + const struct inode_operations *iop;
18381 + IiMustWriteLock(inode);
18385 + iop = au_sbi(inode->i_sb)->si_iop_array;
18386 + btop = au_dbtop(dentry);
18387 + h_dentry = au_h_dptr(dentry, btop);
18388 + h_inode = d_inode(h_dentry);
18389 + mode = h_inode->i_mode;
18390 + switch (mode & S_IFMT) {
18392 + btail = au_dbtail(dentry);
18393 + inode->i_op = iop + AuIop_OTHER;
18394 + inode->i_fop = &aufs_file_fop;
18395 + err = au_dy_iaop(inode, btop, h_inode);
18396 + if (unlikely(err))
18401 + btail = au_dbtaildir(dentry);
18402 + inode->i_op = iop + AuIop_DIR;
18403 + inode->i_fop = &aufs_dir_fop;
18406 + btail = au_dbtail(dentry);
18407 + inode->i_op = iop + AuIop_SYMLINK;
18413 + btail = au_dbtail(dentry);
18414 + inode->i_op = iop + AuIop_OTHER;
18415 + init_special_inode(inode, mode, h_inode->i_rdev);
18418 + AuIOErr("Unknown file type 0%o\n", mode);
18423 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18424 + flags = au_hi_flags(inode, isdir);
18425 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18426 + && au_ftest_hi(flags, HNOTIFY)
18427 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18428 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18429 + au_fclr_hi(flags, HNOTIFY);
18430 + iinfo = au_ii(inode);
18431 + iinfo->ii_btop = btop;
18432 + iinfo->ii_bbot = btail;
18433 + for (bindex = btop; bindex <= btail; bindex++) {
18434 + h_dentry = au_h_dptr(dentry, bindex);
18436 + au_set_h_iptr(inode, bindex,
18437 + au_igrab(d_inode(h_dentry)), flags);
18439 + au_cpup_attr_all(inode, /*force*/1);
18441 + * to force calling aufs_get_acl() every time,
18442 + * do not call cache_no_acl() for aufs inode.
18450 + * successful returns with iinfo write_locked
18452 + * zero: success, matched
18453 + * plus: no error, but unmatched
18455 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18458 + unsigned int gen, igflags;
18459 + aufs_bindex_t bindex, bbot;
18460 + struct inode *h_inode, *h_dinode;
18461 + struct dentry *h_dentry;
18464 + * before this function, if aufs got any iinfo lock, it must be only
18465 + * one, the parent dir.
18466 + * it can happen by UDBA and the obsoleted inode number.
18469 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18473 + ii_write_lock_new_child(inode);
18474 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18475 + h_dinode = d_inode(h_dentry);
18476 + bbot = au_ibbot(inode);
18477 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18478 + h_inode = au_h_iptr(inode, bindex);
18479 + if (!h_inode || h_inode != h_dinode)
18483 + gen = au_iigen(inode, &igflags);
18484 + if (gen == au_digen(dentry)
18485 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18488 + /* fully refresh inode using dentry */
18489 + err = au_refresh_hinode(inode, dentry);
18491 + au_update_iigen(inode, /*half*/0);
18495 + if (unlikely(err))
18496 + ii_write_unlock(inode);
18501 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18502 + unsigned int d_type, ino_t *ino)
18505 + const int isnondir = d_type != DT_DIR;
18507 + /* prevent hardlinked inode number from race condition */
18509 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18510 + if (unlikely(err))
18514 + err = au_xino_read(sb, bindex, h_ino, ino);
18515 + if (unlikely(err))
18516 + goto out_xinondir;
18520 + *ino = au_xino_new_ino(sb);
18521 + if (unlikely(!*ino))
18522 + goto out_xinondir;
18523 + err = au_xino_write(sb, bindex, h_ino, *ino);
18524 + if (unlikely(err))
18525 + goto out_xinondir;
18529 + if (isnondir && idx >= 0)
18530 + au_xinondir_leave(sb, bindex, h_ino, idx);
18535 +/* successful returns with iinfo write_locked */
18536 +/* todo: return with unlocked? */
18537 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18539 + struct inode *inode, *h_inode;
18540 + struct dentry *h_dentry;
18541 + struct super_block *sb;
18542 + ino_t h_ino, ino;
18543 + int err, idx, hlinked;
18544 + aufs_bindex_t btop;
18546 + sb = dentry->d_sb;
18547 + btop = au_dbtop(dentry);
18548 + h_dentry = au_h_dptr(dentry, btop);
18549 + h_inode = d_inode(h_dentry);
18550 + h_ino = h_inode->i_ino;
18551 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18555 + * stop 'race'-ing between hardlinks under different
18559 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18560 + inode = ERR_PTR(err);
18561 + if (unlikely(err))
18565 + err = au_xino_read(sb, btop, h_ino, &ino);
18566 + inode = ERR_PTR(err);
18567 + if (unlikely(err))
18568 + goto out_xinondir;
18571 + ino = au_xino_new_ino(sb);
18572 + if (unlikely(!ino)) {
18573 + inode = ERR_PTR(-EIO);
18574 + goto out_xinondir;
18578 + AuDbg("i%lu\n", (unsigned long)ino);
18579 + inode = au_iget_locked(sb, ino);
18580 + err = PTR_ERR(inode);
18581 + if (IS_ERR(inode))
18582 + goto out_xinondir;
18584 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18585 + if (inode->i_state & I_NEW) {
18586 + ii_write_lock_new_child(inode);
18587 + err = set_inode(inode, dentry);
18589 + unlock_new_inode(inode);
18590 + goto out_xinondir; /* success */
18594 + * iget_failed() calls iput(), but we need to call
18595 + * ii_write_unlock() after iget_failed(). so dirty hack for
18598 + atomic_inc(&inode->i_count);
18599 + iget_failed(inode);
18600 + ii_write_unlock(inode);
18601 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18602 + /* ignore this error */
18604 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18606 + * horrible race condition between lookup, readdir and copyup
18607 + * (or something).
18609 + if (hlinked && idx >= 0)
18610 + au_xinondir_leave(sb, btop, h_ino, idx);
18611 + err = reval_inode(inode, dentry);
18612 + if (unlikely(err < 0)) {
18617 + goto out; /* success */
18618 + else if (hlinked && idx >= 0) {
18619 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18620 + if (unlikely(err)) {
18622 + inode = ERR_PTR(err);
18628 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18629 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18630 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18631 + btop, au_sbtype(h_dentry->d_sb), dentry,
18632 + (unsigned long)h_ino, (unsigned long)ino);
18634 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18637 + if (hlinked && idx >= 0)
18638 + au_xinondir_leave(sb, btop, h_ino, idx);
18644 + inode = ERR_PTR(err);
18646 + if (hlinked && idx >= 0)
18647 + au_xinondir_leave(sb, btop, h_ino, idx);
18652 +/* ---------------------------------------------------------------------- */
18654 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18655 + struct inode *inode)
18658 + struct inode *hi;
18660 + err = au_br_rdonly(au_sbr(sb, bindex));
18662 + /* pseudo-link after flushed may happen out of bounds */
18665 + && au_ibtop(inode) <= bindex
18666 + && bindex <= au_ibbot(inode)) {
18668 + * permission check is unnecessary since vfsub routine
18669 + * will be called later
18671 + hi = au_h_iptr(inode, bindex);
18673 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18679 +int au_test_h_perm(struct inode *h_inode, int mask)
18681 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18683 + return inode_permission(h_inode, mask);
18686 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18688 + if (au_test_nfs(h_inode->i_sb)
18689 + && (mask & MAY_WRITE)
18690 + && S_ISDIR(h_inode->i_mode))
18691 + mask |= MAY_READ; /* force permission check */
18692 + return au_test_h_perm(h_inode, mask);
18694 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18695 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18696 +++ linux/fs/aufs/inode.h 2020-08-03 09:14:46.095748745 +0200
18698 +/* SPDX-License-Identifier: GPL-2.0 */
18700 + * Copyright (C) 2005-2020 Junjiro R. Okajima
18702 + * This program, aufs is free software; you can redistribute it and/or modify
18703 + * it under the terms of the GNU General Public License as published by
18704 + * the Free Software Foundation; either version 2 of the License, or
18705 + * (at your option) any later version.
18707 + * This program is distributed in the hope that it will be useful,
18708 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18709 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18710 + * GNU General Public License for more details.
18712 + * You should have received a copy of the GNU General Public License
18713 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18717 + * inode operations
18720 +#ifndef __AUFS_INODE_H__
18721 +#define __AUFS_INODE_H__
18725 +#include <linux/fsnotify.h>
18726 +#include "rwsem.h"
18730 +struct au_hnotify {
18731 +#ifdef CONFIG_AUFS_HNOTIFY
18732 +#ifdef CONFIG_AUFS_HFSNOTIFY
18733 + /* never use fsnotify_add_vfsmount_mark() */
18734 + struct fsnotify_mark hn_mark;
18736 + struct inode *hn_aufs_inode; /* no get/put */
18737 + struct rcu_head rcu;
18739 +} ____cacheline_aligned_in_smp;
18741 +struct au_hinode {
18742 + struct inode *hi_inode;
18743 + aufs_bindex_t hi_id;
18744 +#ifdef CONFIG_AUFS_HNOTIFY
18745 + struct au_hnotify *hi_notify;
18748 + /* reference to the copied-up whiteout with get/put */
18749 + struct dentry *hi_whdentry;
18753 +#define AuIG_HALF_REFRESHED 1
18754 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18755 +#define au_ig_fset(flags, name) \
18756 + do { (flags) |= AuIG_##name; } while (0)
18757 +#define au_ig_fclr(flags, name) \
18758 + do { (flags) &= ~AuIG_##name; } while (0)
18761 + spinlock_t ig_spin;
18762 + __u32 ig_generation, ig_flags;
18767 + struct au_iigen ii_generation;
18768 + struct super_block *ii_hsb1; /* no get/put */
18770 + struct au_rwsem ii_rwsem;
18771 + aufs_bindex_t ii_btop, ii_bbot;
18773 + struct au_hinode *ii_hinode;
18774 + struct au_vdir *ii_vdir;
18777 +struct au_icntnr {
18778 + struct au_iinfo iinfo;
18779 + struct inode vfs_inode;
18780 + struct hlist_bl_node plink;
18781 + struct rcu_head rcu;
18782 +} ____cacheline_aligned_in_smp;
18784 +/* au_pin flags */
18785 +#define AuPin_DI_LOCKED 1
18786 +#define AuPin_MNT_WRITE (1 << 1)
18787 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18788 +#define au_fset_pin(flags, name) \
18789 + do { (flags) |= AuPin_##name; } while (0)
18790 +#define au_fclr_pin(flags, name) \
18791 + do { (flags) &= ~AuPin_##name; } while (0)
18795 + struct dentry *dentry;
18796 + unsigned int udba;
18797 + unsigned char lsc_di, lsc_hi, flags;
18798 + aufs_bindex_t bindex;
18801 + struct dentry *parent;
18802 + struct au_hinode *hdir;
18803 + struct vfsmount *h_mnt;
18805 + /* temporary unlock/relock for copyup */
18806 + struct dentry *h_dentry, *h_parent;
18807 + struct au_branch *br;
18808 + struct task_struct *task;
18811 +void au_pin_hdir_unlock(struct au_pin *p);
18812 +int au_pin_hdir_lock(struct au_pin *p);
18813 +int au_pin_hdir_relock(struct au_pin *p);
18814 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18815 +void au_pin_hdir_release(struct au_pin *p);
18817 +/* ---------------------------------------------------------------------- */
18819 +static inline struct au_iinfo *au_ii(struct inode *inode)
18821 + BUG_ON(is_bad_inode(inode));
18822 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18825 +/* ---------------------------------------------------------------------- */
18828 +struct inode *au_igrab(struct inode *inode);
18829 +void au_refresh_iop(struct inode *inode, int force_getattr);
18830 +int au_refresh_hinode_self(struct inode *inode);
18831 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18832 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18833 + unsigned int d_type, ino_t *ino);
18834 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18835 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18836 + struct inode *inode);
18837 +int au_test_h_perm(struct inode *h_inode, int mask);
18838 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18840 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18841 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18843 +#ifdef CONFIG_AUFS_SHWH
18844 + return au_ino(sb, bindex, h_ino, d_type, ino);
18857 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
18858 + aufs_iop_nogetattr[AuIop_Last];
18860 +/* au_wr_dir flags */
18861 +#define AuWrDir_ADD_ENTRY 1
18862 +#define AuWrDir_ISDIR (1 << 1)
18863 +#define AuWrDir_TMPFILE (1 << 2)
18864 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18865 +#define au_fset_wrdir(flags, name) \
18866 + do { (flags) |= AuWrDir_##name; } while (0)
18867 +#define au_fclr_wrdir(flags, name) \
18868 + do { (flags) &= ~AuWrDir_##name; } while (0)
18870 +struct au_wr_dir_args {
18871 + aufs_bindex_t force_btgt;
18872 + unsigned char flags;
18874 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18875 + struct au_wr_dir_args *args);
18877 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18878 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18879 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18880 + unsigned int udba, unsigned char flags);
18881 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18882 + unsigned int udba, unsigned char flags) __must_check;
18883 +int au_do_pin(struct au_pin *pin) __must_check;
18884 +void au_unpin(struct au_pin *pin);
18885 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18887 +#define AuIcpup_DID_CPUP 1
18888 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18889 +#define au_fset_icpup(flags, name) \
18890 + do { (flags) |= AuIcpup_##name; } while (0)
18891 +#define au_fclr_icpup(flags, name) \
18892 + do { (flags) &= ~AuIcpup_##name; } while (0)
18894 +struct au_icpup_args {
18895 + unsigned char flags;
18896 + unsigned char pin_flags;
18897 + aufs_bindex_t btgt;
18898 + unsigned int udba;
18899 + struct au_pin pin;
18900 + struct path h_path;
18901 + struct inode *h_inode;
18904 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18905 + struct au_icpup_args *a);
18907 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
18908 + struct path *h_path, int locked);
18911 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18912 + struct dentry *h_parent, int isdir);
18913 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18915 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
18916 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18918 +struct vfsub_aopen_args;
18919 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18920 + struct vfsub_aopen_args *args);
18921 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
18922 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18923 + struct dentry *dentry);
18924 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
18927 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18928 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18929 + struct dentry *h_parent, int isdir);
18930 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18931 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
18934 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
18935 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
18936 + struct inode *dir, struct dentry *dentry,
18937 + unsigned int flags);
18940 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
18941 +void au_hiput(struct au_hinode *hinode);
18942 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18943 + struct dentry *h_wh);
18944 +unsigned int au_hi_flags(struct inode *inode, int isdir);
18946 +/* hinode flags */
18947 +#define AuHi_XINO 1
18948 +#define AuHi_HNOTIFY (1 << 1)
18949 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
18950 +#define au_fset_hi(flags, name) \
18951 + do { (flags) |= AuHi_##name; } while (0)
18952 +#define au_fclr_hi(flags, name) \
18953 + do { (flags) &= ~AuHi_##name; } while (0)
18955 +#ifndef CONFIG_AUFS_HNOTIFY
18956 +#undef AuHi_HNOTIFY
18957 +#define AuHi_HNOTIFY 0
18960 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18961 + struct inode *h_inode, unsigned int flags);
18963 +void au_update_iigen(struct inode *inode, int half);
18964 +void au_update_ibrange(struct inode *inode, int do_put_zero);
18966 +void au_icntnr_init_once(void *_c);
18967 +void au_hinode_init(struct au_hinode *hinode);
18968 +int au_iinfo_init(struct inode *inode);
18969 +void au_iinfo_fin(struct inode *inode);
18970 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
18972 +#ifdef CONFIG_PROC_FS
18974 +int au_plink_maint(struct super_block *sb, int flags);
18976 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
18977 +int au_plink_maint_enter(struct super_block *sb);
18978 +#ifdef CONFIG_AUFS_DEBUG
18979 +void au_plink_list(struct super_block *sb);
18981 +AuStubVoid(au_plink_list, struct super_block *sb)
18983 +int au_plink_test(struct inode *inode);
18984 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
18985 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
18986 + struct dentry *h_dentry);
18987 +void au_plink_put(struct super_block *sb, int verbose);
18988 +void au_plink_clean(struct super_block *sb, int verbose);
18989 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
18991 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
18992 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
18993 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
18994 +AuStubVoid(au_plink_list, struct super_block *sb);
18995 +AuStubInt0(au_plink_test, struct inode *inode);
18996 +AuStub(struct dentry *, au_plink_lkup, return NULL,
18997 + struct inode *inode, aufs_bindex_t bindex);
18998 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
18999 + struct dentry *h_dentry);
19000 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
19001 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
19002 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
19003 +#endif /* CONFIG_PROC_FS */
19005 +#ifdef CONFIG_AUFS_XATTR
19007 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
19008 + unsigned int verbose);
19009 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
19010 +void au_xattr_init(struct super_block *sb);
19012 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
19013 + int ignore_flags, unsigned int verbose);
19014 +AuStubVoid(au_xattr_init, struct super_block *sb);
19017 +#ifdef CONFIG_FS_POSIX_ACL
19018 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
19019 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
19022 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19028 +struct au_sxattr {
19032 + const char *name;
19033 + const void *value;
19038 + struct posix_acl *acl;
19043 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19044 + struct au_sxattr *arg);
19047 +/* ---------------------------------------------------------------------- */
19049 +/* lock subclass for iinfo */
19051 + AuLsc_II_CHILD, /* child first */
19052 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
19053 + AuLsc_II_CHILD3, /* copyup dirs */
19054 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
19055 + AuLsc_II_PARENT2,
19056 + AuLsc_II_PARENT3, /* copyup dirs */
19057 + AuLsc_II_NEW_CHILD
19061 + * ii_read_lock_child, ii_write_lock_child,
19062 + * ii_read_lock_child2, ii_write_lock_child2,
19063 + * ii_read_lock_child3, ii_write_lock_child3,
19064 + * ii_read_lock_parent, ii_write_lock_parent,
19065 + * ii_read_lock_parent2, ii_write_lock_parent2,
19066 + * ii_read_lock_parent3, ii_write_lock_parent3,
19067 + * ii_read_lock_new_child, ii_write_lock_new_child,
19069 +#define AuReadLockFunc(name, lsc) \
19070 +static inline void ii_read_lock_##name(struct inode *i) \
19072 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19075 +#define AuWriteLockFunc(name, lsc) \
19076 +static inline void ii_write_lock_##name(struct inode *i) \
19078 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19081 +#define AuRWLockFuncs(name, lsc) \
19082 + AuReadLockFunc(name, lsc) \
19083 + AuWriteLockFunc(name, lsc)
19085 +AuRWLockFuncs(child, CHILD);
19086 +AuRWLockFuncs(child2, CHILD2);
19087 +AuRWLockFuncs(child3, CHILD3);
19088 +AuRWLockFuncs(parent, PARENT);
19089 +AuRWLockFuncs(parent2, PARENT2);
19090 +AuRWLockFuncs(parent3, PARENT3);
19091 +AuRWLockFuncs(new_child, NEW_CHILD);
19093 +#undef AuReadLockFunc
19094 +#undef AuWriteLockFunc
19095 +#undef AuRWLockFuncs
19097 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
19098 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
19099 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
19101 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
19102 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
19103 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
19105 +/* ---------------------------------------------------------------------- */
19107 +static inline void au_icntnr_init(struct au_icntnr *c)
19109 +#ifdef CONFIG_AUFS_DEBUG
19110 + c->vfs_inode.i_mode = 0;
19114 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
19116 + unsigned int gen;
19117 + struct au_iinfo *iinfo;
19118 + struct au_iigen *iigen;
19120 + iinfo = au_ii(inode);
19121 + iigen = &iinfo->ii_generation;
19122 + spin_lock(&iigen->ig_spin);
19124 + *igflags = iigen->ig_flags;
19125 + gen = iigen->ig_generation;
19126 + spin_unlock(&iigen->ig_spin);
19131 +/* tiny test for inode number */
19132 +/* tmpfs generation is too rough */
19133 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19135 + struct au_iinfo *iinfo;
19137 + iinfo = au_ii(inode);
19138 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19139 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19140 + && iinfo->ii_higen == h_inode->i_generation);
19143 +static inline void au_iigen_dec(struct inode *inode)
19145 + struct au_iinfo *iinfo;
19146 + struct au_iigen *iigen;
19148 + iinfo = au_ii(inode);
19149 + iigen = &iinfo->ii_generation;
19150 + spin_lock(&iigen->ig_spin);
19151 + iigen->ig_generation--;
19152 + spin_unlock(&iigen->ig_spin);
19155 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19160 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19166 +/* ---------------------------------------------------------------------- */
19168 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19169 + aufs_bindex_t bindex)
19171 + return iinfo->ii_hinode + bindex;
19174 +static inline int au_is_bad_inode(struct inode *inode)
19176 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19179 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19180 + aufs_bindex_t bindex)
19182 + IiMustAnyLock(inode);
19183 + return au_hinode(au_ii(inode), bindex)->hi_id;
19186 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19188 + IiMustAnyLock(inode);
19189 + return au_ii(inode)->ii_btop;
19192 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19194 + IiMustAnyLock(inode);
19195 + return au_ii(inode)->ii_bbot;
19198 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19200 + IiMustAnyLock(inode);
19201 + return au_ii(inode)->ii_vdir;
19204 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19206 + IiMustAnyLock(inode);
19207 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19210 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19212 + IiMustWriteLock(inode);
19213 + au_ii(inode)->ii_btop = bindex;
19216 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19218 + IiMustWriteLock(inode);
19219 + au_ii(inode)->ii_bbot = bindex;
19222 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19224 + IiMustWriteLock(inode);
19225 + au_ii(inode)->ii_vdir = vdir;
19228 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19230 + IiMustAnyLock(inode);
19231 + return au_hinode(au_ii(inode), bindex);
19234 +/* ---------------------------------------------------------------------- */
19236 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19239 + return pin->parent;
19243 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19245 + if (pin && pin->hdir)
19246 + return pin->hdir->hi_inode;
19250 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19253 + return pin->hdir;
19257 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19260 + pin->dentry = dentry;
19263 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19264 + unsigned char lflag)
19268 + au_fset_pin(pin->flags, DI_LOCKED);
19270 + au_fclr_pin(pin->flags, DI_LOCKED);
19274 +#if 0 /* reserved */
19275 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19278 + dput(pin->parent);
19279 + pin->parent = dget(parent);
19284 +/* ---------------------------------------------------------------------- */
19287 +#ifdef CONFIG_AUFS_HNOTIFY
19288 +struct au_hnotify_op {
19289 + void (*ctl)(struct au_hinode *hinode, int do_set);
19290 + int (*alloc)(struct au_hinode *hinode);
19293 + * if it returns true, the the caller should free hinode->hi_notify,
19294 + * otherwise ->free() frees it.
19296 + int (*free)(struct au_hinode *hinode,
19297 + struct au_hnotify *hn) __must_check;
19299 + void (*fin)(void);
19300 + int (*init)(void);
19302 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19303 + void (*fin_br)(struct au_branch *br);
19304 + int (*init_br)(struct au_branch *br, int perm);
19308 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19309 +void au_hn_free(struct au_hinode *hinode);
19310 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19311 +void au_hn_reset(struct inode *inode, unsigned int flags);
19312 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19313 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
19314 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19315 +int au_hnotify_init_br(struct au_branch *br, int perm);
19316 +void au_hnotify_fin_br(struct au_branch *br);
19317 +int __init au_hnotify_init(void);
19318 +void au_hnotify_fin(void);
19321 +extern const struct au_hnotify_op au_hnotify_op;
19324 +void au_hn_init(struct au_hinode *hinode)
19326 + hinode->hi_notify = NULL;
19329 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19331 + return hinode->hi_notify;
19335 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19336 + struct au_hinode *hinode __maybe_unused,
19337 + struct inode *inode __maybe_unused)
19338 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19339 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19340 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19341 + int do_set __maybe_unused)
19342 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19343 + unsigned int flags __maybe_unused)
19344 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19345 + struct au_branch *br __maybe_unused,
19346 + int perm __maybe_unused)
19347 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19348 + int perm __maybe_unused)
19349 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19350 +AuStubInt0(__init au_hnotify_init, void)
19351 +AuStubVoid(au_hnotify_fin, void)
19352 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19353 +#endif /* CONFIG_AUFS_HNOTIFY */
19355 +static inline void au_hn_suspend(struct au_hinode *hdir)
19357 + au_hn_ctl(hdir, /*do_set*/0);
19360 +static inline void au_hn_resume(struct au_hinode *hdir)
19362 + au_hn_ctl(hdir, /*do_set*/1);
19365 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19367 + inode_lock(hdir->hi_inode);
19368 + au_hn_suspend(hdir);
19371 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19372 + unsigned int sc __maybe_unused)
19374 + inode_lock_nested(hdir->hi_inode, sc);
19375 + au_hn_suspend(hdir);
19378 +#if 0 /* unused */
19379 +#include "vfsub.h"
19380 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19383 + inode_lock_shared_nested(hdir->hi_inode, sc);
19384 + au_hn_suspend(hdir);
19388 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19390 + au_hn_resume(hdir);
19391 + inode_unlock(hdir->hi_inode);
19394 +#endif /* __KERNEL__ */
19395 +#endif /* __AUFS_INODE_H__ */
19396 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19397 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19398 +++ linux/fs/aufs/ioctl.c 2020-01-27 10:57:18.175538316 +0100
19400 +// SPDX-License-Identifier: GPL-2.0
19402 + * Copyright (C) 2005-2020 Junjiro R. Okajima
19404 + * This program, aufs is free software; you can redistribute it and/or modify
19405 + * it under the terms of the GNU General Public License as published by
19406 + * the Free Software Foundation; either version 2 of the License, or
19407 + * (at your option) any later version.
19409 + * This program is distributed in the hope that it will be useful,
19410 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19411 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19412 + * GNU General Public License for more details.
19414 + * You should have received a copy of the GNU General Public License
19415 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19420 + * plink-management and readdir in userspace.
19421 + * assist the pathconf(3) wrapper library.
19423 + * File-based Hierarchical Storage Management.
19426 +#include <linux/compat.h>
19427 +#include <linux/file.h>
19430 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19433 + aufs_bindex_t wbi, bindex, bbot;
19434 + struct file *h_file;
19435 + struct super_block *sb;
19436 + struct dentry *root;
19437 + struct au_branch *br;
19438 + struct aufs_wbr_fd wbrfd = {
19439 + .oflags = au_dir_roflags,
19442 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19443 + | O_NOATIME | O_CLOEXEC;
19445 + AuDebugOn(wbrfd.oflags & ~valid);
19448 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19449 + if (unlikely(err)) {
19455 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19456 + wbrfd.oflags |= au_dir_roflags;
19457 + AuDbg("0%o\n", wbrfd.oflags);
19458 + if (unlikely(wbrfd.oflags & ~valid))
19462 + fd = get_unused_fd_flags(0);
19464 + if (unlikely(fd < 0))
19467 + h_file = ERR_PTR(-EINVAL);
19470 + sb = path->dentry->d_sb;
19471 + root = sb->s_root;
19472 + aufs_read_lock(root, AuLock_IR);
19473 + bbot = au_sbbot(sb);
19474 + if (wbrfd.brid >= 0) {
19475 + wbi = au_br_index(sb, wbrfd.brid);
19476 + if (unlikely(wbi < 0 || wbi > bbot))
19480 + h_file = ERR_PTR(-ENOENT);
19481 + br = au_sbr(sb, wbi);
19482 + if (!au_br_writable(br->br_perm)) {
19486 + bindex = wbi + 1;
19488 + for (; bindex <= bbot; bindex++) {
19489 + br = au_sbr(sb, bindex);
19490 + if (au_br_writable(br->br_perm)) {
19492 + br = au_sbr(sb, wbi);
19497 + AuDbg("wbi %d\n", wbi);
19499 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19503 + aufs_read_unlock(root, AuLock_IR);
19504 + err = PTR_ERR(h_file);
19505 + if (IS_ERR(h_file))
19508 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19509 + fd_install(fd, h_file);
19511 + goto out; /* success */
19514 + put_unused_fd(fd);
19520 +/* ---------------------------------------------------------------------- */
19522 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19525 + struct dentry *dentry;
19528 + case AUFS_CTL_RDU:
19529 + case AUFS_CTL_RDU_INO:
19530 + err = au_rdu_ioctl(file, cmd, arg);
19533 + case AUFS_CTL_WBR_FD:
19534 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19537 + case AUFS_CTL_IBUSY:
19538 + err = au_ibusy_ioctl(file, arg);
19541 + case AUFS_CTL_BRINFO:
19542 + err = au_brinfo_ioctl(file, arg);
19545 + case AUFS_CTL_FHSM_FD:
19546 + dentry = file->f_path.dentry;
19547 + if (IS_ROOT(dentry))
19548 + err = au_fhsm_fd(dentry->d_sb, arg);
19554 + /* do not call the lower */
19555 + AuDbg("0x%x\n", cmd);
19563 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19568 + case AUFS_CTL_MVDOWN:
19569 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19572 + case AUFS_CTL_WBR_FD:
19573 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19577 + /* do not call the lower */
19578 + AuDbg("0x%x\n", cmd);
19586 +#ifdef CONFIG_COMPAT
19587 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19588 + unsigned long arg)
19593 + case AUFS_CTL_RDU:
19594 + case AUFS_CTL_RDU_INO:
19595 + err = au_rdu_compat_ioctl(file, cmd, arg);
19598 + case AUFS_CTL_IBUSY:
19599 + err = au_ibusy_compat_ioctl(file, arg);
19602 + case AUFS_CTL_BRINFO:
19603 + err = au_brinfo_compat_ioctl(file, arg);
19607 + err = aufs_ioctl_dir(file, cmd, arg);
19614 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19615 + unsigned long arg)
19617 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19620 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19621 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19622 +++ linux/fs/aufs/i_op_add.c 2020-01-27 10:57:18.172204883 +0100
19624 +// SPDX-License-Identifier: GPL-2.0
19626 + * Copyright (C) 2005-2020 Junjiro R. Okajima
19628 + * This program, aufs is free software; you can redistribute it and/or modify
19629 + * it under the terms of the GNU General Public License as published by
19630 + * the Free Software Foundation; either version 2 of the License, or
19631 + * (at your option) any later version.
19633 + * This program is distributed in the hope that it will be useful,
19634 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19635 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19636 + * GNU General Public License for more details.
19638 + * You should have received a copy of the GNU General Public License
19639 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19643 + * inode operations (add entry)
19646 +#include <linux/iversion.h>
19650 + * final procedure of adding a new entry, except link(2).
19651 + * remove whiteout, instantiate, copyup the parent dir's times and size
19652 + * and update version.
19653 + * if it failed, re-create the removed whiteout.
19655 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19656 + struct dentry *wh_dentry, struct dentry *dentry)
19659 + aufs_bindex_t bwh;
19660 + struct path h_path;
19661 + struct super_block *sb;
19662 + struct inode *inode, *h_dir;
19663 + struct dentry *wh;
19668 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19669 + IMustLock(h_dir);
19670 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19671 + bwh = au_dbwh(dentry);
19672 + h_path.dentry = wh_dentry;
19673 + h_path.mnt = au_sbr_mnt(sb, bindex);
19674 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19676 + if (unlikely(err))
19680 + inode = au_new_inode(dentry, /*must_new*/1);
19681 + if (!IS_ERR(inode)) {
19682 + d_instantiate(dentry, inode);
19683 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19685 + au_dir_ts(dir, bindex);
19686 + inode_inc_iversion(dir);
19687 + au_fhsm_wrote(sb, bindex, /*force*/0);
19688 + return 0; /* success */
19691 + err = PTR_ERR(inode);
19696 + /* dir inode is locked */
19697 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19698 + rerr = PTR_ERR(wh);
19699 + if (IS_ERR(wh)) {
19700 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19701 + dentry, err, rerr);
19710 +static int au_d_may_add(struct dentry *dentry)
19715 + if (unlikely(d_unhashed(dentry)))
19717 + if (unlikely(d_really_is_positive(dentry)))
19723 + * simple tests for the adding inode operations.
19724 + * following the checks in vfs, plus the parent-child relationship.
19726 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19727 + struct dentry *h_parent, int isdir)
19731 + struct dentry *h_dentry;
19732 + struct inode *h_inode;
19734 + err = -ENAMETOOLONG;
19735 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19738 + h_dentry = au_h_dptr(dentry, bindex);
19739 + if (d_really_is_negative(dentry)) {
19741 + if (unlikely(d_is_positive(h_dentry)))
19744 + /* rename(2) case */
19746 + if (unlikely(d_is_negative(h_dentry)))
19748 + h_inode = d_inode(h_dentry);
19749 + if (unlikely(!h_inode->i_nlink))
19752 + h_mode = h_inode->i_mode;
19755 + if (unlikely(S_ISDIR(h_mode)))
19757 + } else if (unlikely(!S_ISDIR(h_mode))) {
19764 + /* expected parent dir is locked */
19765 + if (unlikely(h_parent != h_dentry->d_parent))
19774 + * initial procedure of adding a new entry.
19775 + * prepare writable branch and the parent dir, lock it,
19776 + * and lookup whiteout for the new entry.
19778 +static struct dentry*
19779 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19780 + struct dentry *src_dentry, struct au_pin *pin,
19781 + struct au_wr_dir_args *wr_dir_args)
19783 + struct dentry *wh_dentry, *h_parent;
19784 + struct super_block *sb;
19785 + struct au_branch *br;
19787 + unsigned int udba;
19788 + aufs_bindex_t bcpup;
19790 + AuDbg("%pd\n", dentry);
19792 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19794 + wh_dentry = ERR_PTR(err);
19795 + if (unlikely(err < 0))
19798 + sb = dentry->d_sb;
19799 + udba = au_opt_udba(sb);
19800 + err = au_pin(pin, dentry, bcpup, udba,
19801 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19802 + wh_dentry = ERR_PTR(err);
19803 + if (unlikely(err))
19806 + h_parent = au_pinned_h_parent(pin);
19807 + if (udba != AuOpt_UDBA_NONE
19808 + && au_dbtop(dentry) == bcpup)
19809 + err = au_may_add(dentry, bcpup, h_parent,
19810 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19811 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19812 + err = -ENAMETOOLONG;
19813 + wh_dentry = ERR_PTR(err);
19814 + if (unlikely(err))
19817 + br = au_sbr(sb, bcpup);
19819 + struct path tmp = {
19820 + .dentry = h_parent,
19821 + .mnt = au_br_mnt(br)
19823 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19826 + wh_dentry = NULL;
19827 + if (bcpup != au_dbwh(dentry))
19828 + goto out; /* success */
19831 + * ENAMETOOLONG here means that if we allowed create such name, then it
19832 + * would not be able to removed in the future. So we don't allow such
19833 + * name here and we don't handle ENAMETOOLONG differently here.
19835 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19838 + if (IS_ERR(wh_dentry))
19841 + return wh_dentry;
19844 +/* ---------------------------------------------------------------------- */
19846 +enum { Mknod, Symlink, Creat };
19847 +struct simple_arg {
19854 + struct vfsub_aopen_args *aopen;
19857 + const char *symname;
19866 +static int add_simple(struct inode *dir, struct dentry *dentry,
19867 + struct simple_arg *arg)
19870 + aufs_bindex_t btop;
19871 + unsigned char created;
19872 + const unsigned char try_aopen
19873 + = (arg->type == Creat && arg->u.c.try_aopen);
19874 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19875 + struct dentry *wh_dentry, *parent;
19876 + struct inode *h_dir;
19877 + struct super_block *sb;
19878 + struct au_branch *br;
19879 + /* to reduce stack size */
19881 + struct au_dtime dt;
19882 + struct au_pin pin;
19883 + struct path h_path;
19884 + struct au_wr_dir_args wr_dir_args;
19887 + AuDbg("%pd\n", dentry);
19891 + a = kmalloc(sizeof(*a), GFP_NOFS);
19892 + if (unlikely(!a))
19894 + a->wr_dir_args.force_btgt = -1;
19895 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19897 + parent = dentry->d_parent; /* dir inode is locked */
19898 + if (!try_aopen) {
19899 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19900 + if (unlikely(err))
19903 + err = au_d_may_add(dentry);
19904 + if (unlikely(err))
19907 + di_write_lock_parent(parent);
19908 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19909 + &a->pin, &a->wr_dir_args);
19910 + err = PTR_ERR(wh_dentry);
19911 + if (IS_ERR(wh_dentry))
19914 + btop = au_dbtop(dentry);
19915 + sb = dentry->d_sb;
19916 + br = au_sbr(sb, btop);
19917 + a->h_path.dentry = au_h_dptr(dentry, btop);
19918 + a->h_path.mnt = au_br_mnt(br);
19919 + h_dir = au_pinned_h_dir(&a->pin);
19920 + switch (arg->type) {
19922 + if (!try_aopen || !h_dir->i_op->atomic_open) {
19923 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19924 + arg->u.c.want_excl);
19926 + if (!err && try_aopen)
19927 + aopen->file->f_mode |= FMODE_CREATED;
19930 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
19931 + AuDbg("err %d\n", err);
19932 + AuDbgFile(aopen->file);
19933 + created = err >= 0
19934 + && !!(aopen->file->f_mode & FMODE_CREATED);
19938 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
19942 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
19949 + if (unlikely(err < 0))
19952 + err = epilog(dir, btop, wh_dentry, dentry);
19954 + goto out_unpin; /* success */
19957 + if (created /* && d_is_positive(a->h_path.dentry) */) {
19958 + /* no delegation since it is just created */
19959 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
19962 + AuIOErr("%pd revert failure(%d, %d)\n",
19963 + dentry, err, rerr);
19966 + au_dtime_revert(&a->dt);
19968 + if (try_aopen && h_dir->i_op->atomic_open
19969 + && (aopen->file->f_mode & FMODE_OPENED))
19970 + /* aopen->file is still opened */
19971 + au_lcnt_dec(&aopen->br->br_nfiles);
19974 + au_unpin(&a->pin);
19978 + di_write_unlock(parent);
19980 + if (unlikely(err)) {
19981 + au_update_dbtop(dentry);
19985 + aufs_read_unlock(dentry, AuLock_DW);
19992 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
19995 + struct simple_arg arg = {
20002 + return add_simple(dir, dentry, &arg);
20005 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
20007 + struct simple_arg arg = {
20009 + .u.s.symname = symname
20011 + return add_simple(dir, dentry, &arg);
20014 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
20017 + struct simple_arg arg = {
20021 + .want_excl = want_excl
20024 + return add_simple(dir, dentry, &arg);
20027 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20028 + struct vfsub_aopen_args *aopen_args)
20030 + struct simple_arg arg = {
20033 + .mode = aopen_args->create_mode,
20034 + .want_excl = aopen_args->open_flag & O_EXCL,
20035 + .try_aopen = true,
20036 + .aopen = aopen_args
20039 + return add_simple(dir, dentry, &arg);
20042 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
20045 + aufs_bindex_t bindex;
20046 + struct super_block *sb;
20047 + struct dentry *parent, *h_parent, *h_dentry;
20048 + struct inode *h_dir, *inode;
20049 + struct vfsmount *h_mnt;
20050 + struct au_wr_dir_args wr_dir_args = {
20051 + .force_btgt = -1,
20052 + .flags = AuWrDir_TMPFILE
20055 + /* copy-up may happen */
20059 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20060 + if (unlikely(err))
20063 + err = au_di_init(dentry);
20064 + if (unlikely(err))
20068 + parent = d_find_any_alias(dir);
20069 + AuDebugOn(!parent);
20070 + di_write_lock_parent(parent);
20071 + if (unlikely(d_inode(parent) != dir))
20074 + err = au_digen_test(parent, au_sigen(sb));
20075 + if (unlikely(err))
20078 + bindex = au_dbtop(parent);
20079 + au_set_dbtop(dentry, bindex);
20080 + au_set_dbbot(dentry, bindex);
20081 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
20083 + if (unlikely(err < 0))
20086 + err = -EOPNOTSUPP;
20087 + h_dir = au_h_iptr(dir, bindex);
20088 + if (unlikely(!h_dir->i_op->tmpfile))
20091 + h_mnt = au_sbr_mnt(sb, bindex);
20092 + err = vfsub_mnt_want_write(h_mnt);
20093 + if (unlikely(err))
20096 + h_parent = au_h_dptr(parent, bindex);
20097 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
20098 + if (IS_ERR(h_dentry)) {
20099 + err = PTR_ERR(h_dentry);
20103 + au_set_dbtop(dentry, bindex);
20104 + au_set_dbbot(dentry, bindex);
20105 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
20106 + inode = au_new_inode(dentry, /*must_new*/1);
20107 + if (IS_ERR(inode)) {
20108 + err = PTR_ERR(inode);
20109 + au_set_h_dptr(dentry, bindex, NULL);
20110 + au_set_dbtop(dentry, -1);
20111 + au_set_dbbot(dentry, -1);
20113 + if (!inode->i_nlink)
20114 + set_nlink(inode, 1);
20115 + d_tmpfile(dentry, inode);
20116 + au_di(dentry)->di_tmpfile = 1;
20118 + /* update without i_mutex */
20119 + if (au_ibtop(dir) == au_dbtop(dentry))
20120 + au_cpup_attr_timesizes(dir);
20125 + vfsub_mnt_drop_write(h_mnt);
20127 + di_write_unlock(parent);
20129 + di_write_unlock(dentry);
20130 + if (unlikely(err)) {
20131 + au_di_fin(dentry);
20132 + dentry->d_fsdata = NULL;
20135 + si_read_unlock(sb);
20137 + inode_unlock(dir);
20141 +/* ---------------------------------------------------------------------- */
20143 +struct au_link_args {
20144 + aufs_bindex_t bdst, bsrc;
20145 + struct au_pin pin;
20146 + struct path h_path;
20147 + struct dentry *src_parent, *parent;
20150 +static int au_cpup_before_link(struct dentry *src_dentry,
20151 + struct au_link_args *a)
20154 + struct dentry *h_src_dentry;
20155 + struct au_cp_generic cpg = {
20156 + .dentry = src_dentry,
20161 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20164 + di_read_lock_parent(a->src_parent, AuLock_IR);
20165 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20166 + if (unlikely(err))
20169 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20170 + err = au_pin(&a->pin, src_dentry, a->bdst,
20171 + au_opt_udba(src_dentry->d_sb),
20172 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20173 + if (unlikely(err))
20176 + err = au_sio_cpup_simple(&cpg);
20177 + au_unpin(&a->pin);
20180 + di_read_unlock(a->src_parent, AuLock_IR);
20184 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20185 + struct au_link_args *a)
20188 + unsigned char plink;
20189 + aufs_bindex_t bbot;
20190 + struct dentry *h_src_dentry;
20191 + struct inode *h_inode, *inode, *delegated;
20192 + struct super_block *sb;
20193 + struct file *h_file;
20197 + sb = src_dentry->d_sb;
20198 + inode = d_inode(src_dentry);
20199 + if (au_ibtop(inode) <= a->bdst)
20200 + h_inode = au_h_iptr(inode, a->bdst);
20201 + if (!h_inode || !h_inode->i_nlink) {
20202 + /* copyup src_dentry as the name of dentry. */
20203 + bbot = au_dbbot(dentry);
20204 + if (bbot < a->bsrc)
20205 + au_set_dbbot(dentry, a->bsrc);
20206 + au_set_h_dptr(dentry, a->bsrc,
20207 + dget(au_h_dptr(src_dentry, a->bsrc)));
20208 + dget(a->h_path.dentry);
20209 + au_set_h_dptr(dentry, a->bdst, NULL);
20210 + AuDbg("temporary d_inode...\n");
20211 + spin_lock(&dentry->d_lock);
20212 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20213 + spin_unlock(&dentry->d_lock);
20214 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20215 + if (IS_ERR(h_file))
20216 + err = PTR_ERR(h_file);
20218 + struct au_cp_generic cpg = {
20219 + .dentry = dentry,
20224 + .flags = AuCpup_KEEPLINO
20226 + err = au_sio_cpup_simple(&cpg);
20227 + au_h_open_post(dentry, a->bsrc, h_file);
20229 + dput(a->h_path.dentry);
20230 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20232 + au_set_h_dptr(dentry, a->bdst,
20233 + a->h_path.dentry);
20235 + spin_lock(&dentry->d_lock);
20236 + dentry->d_inode = NULL; /* restore */
20237 + spin_unlock(&dentry->d_lock);
20238 + AuDbg("temporary d_inode...done\n");
20239 + au_set_h_dptr(dentry, a->bsrc, NULL);
20240 + au_set_dbbot(dentry, bbot);
20242 + /* the inode of src_dentry already exists on a.bdst branch */
20243 + h_src_dentry = d_find_alias(h_inode);
20244 + if (!h_src_dentry && au_plink_test(inode)) {
20246 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20247 + err = PTR_ERR(h_src_dentry);
20248 + if (IS_ERR(h_src_dentry))
20251 + if (unlikely(d_is_negative(h_src_dentry))) {
20252 + dput(h_src_dentry);
20253 + h_src_dentry = NULL;
20257 + if (h_src_dentry) {
20258 + delegated = NULL;
20259 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20260 + &a->h_path, &delegated);
20261 + if (unlikely(err == -EWOULDBLOCK)) {
20262 + pr_warn("cannot retry for NFSv4 delegation"
20263 + " for an internal link\n");
20266 + dput(h_src_dentry);
20268 + AuIOErr("no dentry found for hi%lu on b%d\n",
20269 + h_inode->i_ino, a->bdst);
20274 + if (!err && !plink)
20275 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20282 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20283 + struct dentry *dentry)
20286 + struct au_dtime dt;
20287 + struct au_link_args *a;
20288 + struct dentry *wh_dentry, *h_src_dentry;
20289 + struct inode *inode, *delegated;
20290 + struct super_block *sb;
20291 + struct au_wr_dir_args wr_dir_args = {
20292 + /* .force_btgt = -1, */
20293 + .flags = AuWrDir_ADD_ENTRY
20297 + inode = d_inode(src_dentry);
20298 + IMustLock(inode);
20301 + a = kzalloc(sizeof(*a), GFP_NOFS);
20302 + if (unlikely(!a))
20305 + a->parent = dentry->d_parent; /* dir inode is locked */
20306 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20307 + AuLock_NOPLM | AuLock_GEN);
20308 + if (unlikely(err))
20310 + err = au_d_linkable(src_dentry);
20311 + if (unlikely(err))
20313 + err = au_d_may_add(dentry);
20314 + if (unlikely(err))
20317 + a->src_parent = dget_parent(src_dentry);
20318 + wr_dir_args.force_btgt = au_ibtop(inode);
20320 + di_write_lock_parent(a->parent);
20321 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20322 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20324 + err = PTR_ERR(wh_dentry);
20325 + if (IS_ERR(wh_dentry))
20329 + sb = dentry->d_sb;
20330 + a->bdst = au_dbtop(dentry);
20331 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20332 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20333 + a->bsrc = au_ibtop(inode);
20334 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20335 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20336 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20337 + if (!h_src_dentry) {
20338 + a->bsrc = au_dbtop(src_dentry);
20339 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20340 + AuDebugOn(!h_src_dentry);
20341 + } else if (IS_ERR(h_src_dentry)) {
20342 + err = PTR_ERR(h_src_dentry);
20347 + * aufs doesn't touch the credential so
20348 + * security_dentry_create_files_as() is unnecessary.
20350 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20351 + if (a->bdst < a->bsrc
20352 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20353 + err = au_cpup_or_link(src_dentry, dentry, a);
20355 + delegated = NULL;
20356 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20357 + &a->h_path, &delegated);
20358 + if (unlikely(err == -EWOULDBLOCK)) {
20359 + pr_warn("cannot retry for NFSv4 delegation"
20360 + " for an internal link\n");
20364 + dput(h_src_dentry);
20367 + * copyup src_dentry to the branch we process,
20368 + * and then link(2) to it.
20370 + dput(h_src_dentry);
20371 + if (a->bdst < a->bsrc
20372 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20373 + au_unpin(&a->pin);
20374 + di_write_unlock(a->parent);
20375 + err = au_cpup_before_link(src_dentry, a);
20376 + di_write_lock_parent(a->parent);
20378 + err = au_pin(&a->pin, dentry, a->bdst,
20380 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20381 + if (unlikely(err))
20385 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20387 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20388 + delegated = NULL;
20389 + err = vfsub_link(h_src_dentry,
20390 + au_pinned_h_dir(&a->pin),
20391 + &a->h_path, &delegated);
20392 + if (unlikely(err == -EWOULDBLOCK)) {
20393 + pr_warn("cannot retry"
20394 + " for NFSv4 delegation"
20395 + " for an internal link\n");
20401 + if (unlikely(err))
20405 + a->h_path.dentry = wh_dentry;
20406 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20408 + if (unlikely(err))
20412 + au_dir_ts(dir, a->bdst);
20413 + inode_inc_iversion(dir);
20414 + inc_nlink(inode);
20415 + inode->i_ctime = dir->i_ctime;
20416 + d_instantiate(dentry, au_igrab(inode));
20417 + if (d_unhashed(a->h_path.dentry))
20418 + /* some filesystem calls d_drop() */
20420 + /* some filesystems consume an inode even hardlink */
20421 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20422 + goto out_unpin; /* success */
20425 + /* no delegation since it is just created */
20426 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20427 + /*delegated*/NULL, /*force*/0);
20428 + if (unlikely(rerr)) {
20429 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20432 + au_dtime_revert(&dt);
20434 + au_unpin(&a->pin);
20438 + di_write_unlock(a->parent);
20439 + dput(a->src_parent);
20441 + if (unlikely(err)) {
20442 + au_update_dbtop(dentry);
20445 + aufs_read_and_write_unlock2(dentry, src_dentry);
20453 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20456 + aufs_bindex_t bindex;
20457 + unsigned char diropq;
20458 + struct path h_path;
20459 + struct dentry *wh_dentry, *parent, *opq_dentry;
20460 + struct inode *h_inode;
20461 + struct super_block *sb;
20463 + struct au_pin pin;
20464 + struct au_dtime dt;
20465 + } *a; /* reduce the stack usage */
20466 + struct au_wr_dir_args wr_dir_args = {
20467 + .force_btgt = -1,
20468 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20474 + a = kmalloc(sizeof(*a), GFP_NOFS);
20475 + if (unlikely(!a))
20478 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20479 + if (unlikely(err))
20481 + err = au_d_may_add(dentry);
20482 + if (unlikely(err))
20485 + parent = dentry->d_parent; /* dir inode is locked */
20486 + di_write_lock_parent(parent);
20487 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20488 + &a->pin, &wr_dir_args);
20489 + err = PTR_ERR(wh_dentry);
20490 + if (IS_ERR(wh_dentry))
20493 + sb = dentry->d_sb;
20494 + bindex = au_dbtop(dentry);
20495 + h_path.dentry = au_h_dptr(dentry, bindex);
20496 + h_path.mnt = au_sbr_mnt(sb, bindex);
20497 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20498 + if (unlikely(err))
20501 + /* make the dir opaque */
20503 + h_inode = d_inode(h_path.dentry);
20505 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20506 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20507 + opq_dentry = au_diropq_create(dentry, bindex);
20508 + inode_unlock(h_inode);
20509 + err = PTR_ERR(opq_dentry);
20510 + if (IS_ERR(opq_dentry))
20512 + dput(opq_dentry);
20516 + err = epilog(dir, bindex, wh_dentry, dentry);
20519 + goto out_unpin; /* success */
20524 + AuLabel(revert opq);
20525 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20526 + rerr = au_diropq_remove(dentry, bindex);
20527 + inode_unlock(h_inode);
20529 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20530 + dentry, err, rerr);
20536 + AuLabel(revert dir);
20537 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20539 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20540 + dentry, err, rerr);
20543 + au_dtime_revert(&a->dt);
20545 + au_unpin(&a->pin);
20548 + di_write_unlock(parent);
20550 + if (unlikely(err)) {
20551 + au_update_dbtop(dentry);
20554 + aufs_read_unlock(dentry, AuLock_DW);
20560 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20561 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20562 +++ linux/fs/aufs/i_op.c 2020-08-03 09:14:46.095748745 +0200
20564 +// SPDX-License-Identifier: GPL-2.0
20566 + * Copyright (C) 2005-2020 Junjiro R. Okajima
20568 + * This program, aufs is free software; you can redistribute it and/or modify
20569 + * it under the terms of the GNU General Public License as published by
20570 + * the Free Software Foundation; either version 2 of the License, or
20571 + * (at your option) any later version.
20573 + * This program is distributed in the hope that it will be useful,
20574 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20575 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20576 + * GNU General Public License for more details.
20578 + * You should have received a copy of the GNU General Public License
20579 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20583 + * inode operations (except add/del/rename)
20586 +#include <linux/device_cgroup.h>
20587 +#include <linux/fs_stack.h>
20588 +#include <linux/iversion.h>
20589 +#include <linux/namei.h>
20590 +#include <linux/security.h>
20593 +static int h_permission(struct inode *h_inode, int mask,
20594 + struct path *h_path, int brperm)
20597 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20600 + if (write_mask && IS_IMMUTABLE(h_inode))
20604 + if (((mask & MAY_EXEC)
20605 + && S_ISREG(h_inode->i_mode)
20606 + && (path_noexec(h_path)
20607 + || !(h_inode->i_mode & 0111))))
20611 + * - skip the lower fs test in the case of write to ro branch.
20612 + * - nfs dir permission write check is optimized, but a policy for
20613 + * link/rename requires a real check.
20614 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20615 + * in this case, generic_permission() returns -EOPNOTSUPP.
20617 + if ((write_mask && !au_br_writable(brperm))
20618 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20619 + && write_mask && !(mask & MAY_READ))
20620 + || !h_inode->i_op->permission) {
20621 + /* AuLabel(generic_permission); */
20622 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20623 + err = generic_permission(h_inode, mask);
20624 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20625 + err = h_inode->i_op->permission(h_inode, mask);
20628 + /* AuLabel(h_inode->permission); */
20629 + err = h_inode->i_op->permission(h_inode, mask);
20634 + err = devcgroup_inode_permission(h_inode, mask);
20636 + err = security_inode_permission(h_inode, mask);
20642 +static int aufs_permission(struct inode *inode, int mask)
20645 + aufs_bindex_t bindex, bbot;
20646 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20647 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20648 + struct inode *h_inode;
20649 + struct super_block *sb;
20650 + struct au_branch *br;
20652 + /* todo: support rcu-walk? */
20653 + if (mask & MAY_NOT_BLOCK)
20656 + sb = inode->i_sb;
20657 + si_read_lock(sb, AuLock_FLUSH);
20658 + ii_read_lock_child(inode);
20659 +#if 0 /* reserved for future use */
20661 + * This test may be rather 'too much' since the test is essentially done
20662 + * in the aufs_lookup(). Theoretically it is possible that the inode
20663 + * generation doesn't match to the superblock's here. But it isn't a
20664 + * big deal I suppose.
20666 + err = au_iigen_test(inode, au_sigen(sb));
20667 + if (unlikely(err))
20673 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20674 + err = au_busy_or_stale();
20675 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20676 + if (unlikely(!h_inode
20677 + || (h_inode->i_mode & S_IFMT)
20678 + != (inode->i_mode & S_IFMT)))
20682 + bindex = au_ibtop(inode);
20683 + br = au_sbr(sb, bindex);
20684 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20687 + && !special_file(h_inode->i_mode)) {
20688 + /* test whether the upper writable branch exists */
20690 + for (; bindex >= 0; bindex--)
20691 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20699 + /* non-write to dir */
20701 + bbot = au_ibbot(inode);
20702 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20703 + h_inode = au_h_iptr(inode, bindex);
20705 + err = au_busy_or_stale();
20706 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20709 + br = au_sbr(sb, bindex);
20710 + err = h_permission(h_inode, mask, &br->br_path,
20716 + ii_read_unlock(inode);
20717 + si_read_unlock(sb);
20721 +/* ---------------------------------------------------------------------- */
20723 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20724 + unsigned int flags)
20726 + struct dentry *ret, *parent;
20727 + struct inode *inode;
20728 + struct super_block *sb;
20729 + int err, npositive;
20733 + /* todo: support rcu-walk? */
20734 + ret = ERR_PTR(-ECHILD);
20735 + if (flags & LOOKUP_RCU)
20738 + ret = ERR_PTR(-ENAMETOOLONG);
20739 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20743 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20744 + ret = ERR_PTR(err);
20745 + if (unlikely(err))
20748 + err = au_di_init(dentry);
20749 + ret = ERR_PTR(err);
20750 + if (unlikely(err))
20754 + npositive = 0; /* suppress a warning */
20755 + parent = dentry->d_parent; /* dir inode is locked */
20756 + di_read_lock_parent(parent, AuLock_IR);
20757 + err = au_alive_dir(parent);
20759 + err = au_digen_test(parent, au_sigen(sb));
20761 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20762 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20763 + AuLkup_ALLOW_NEG);
20766 + di_read_unlock(parent, AuLock_IR);
20767 + ret = ERR_PTR(err);
20768 + if (unlikely(err < 0))
20772 + inode = au_new_inode(dentry, /*must_new*/0);
20773 + if (IS_ERR(inode)) {
20774 + ret = (void *)inode;
20781 + atomic_inc(&inode->i_count);
20782 + ret = d_splice_alias(inode, dentry);
20783 +#if 0 /* reserved for future use */
20784 + if (unlikely(d_need_lookup(dentry))) {
20785 + spin_lock(&dentry->d_lock);
20786 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20787 + spin_unlock(&dentry->d_lock);
20791 + if (!IS_ERR(ret)) {
20793 + if (ret && ret != dentry)
20794 + ii_write_unlock(inode);
20796 + ii_write_unlock(inode);
20803 + di_write_unlock(dentry);
20805 + si_read_unlock(sb);
20810 +/* ---------------------------------------------------------------------- */
20813 + * very dirty and complicated aufs ->atomic_open().
20814 + * aufs_atomic_open()
20815 + * + au_aopen_or_create()
20817 + * + vfsub_atomic_open()
20818 + * + branch fs ->atomic_open()
20819 + * may call the actual 'open' for h_file
20820 + * + inc br_nfiles only if opened
20821 + * + au_aopen_no_open() or au_aopen_do_open()
20823 + * au_aopen_do_open()
20824 + * + finish_open()
20825 + * + au_do_aopen()
20826 + * + au_do_open() the body of all 'open'
20827 + * + au_do_open_nondir()
20828 + * set the passed h_file
20830 + * au_aopen_no_open()
20831 + * + finish_no_open()
20834 +struct aopen_node {
20835 + struct hlist_bl_node hblist;
20836 + struct file *file, *h_file;
20839 +static int au_do_aopen(struct inode *inode, struct file *file)
20841 + struct hlist_bl_head *aopen;
20842 + struct hlist_bl_node *pos;
20843 + struct aopen_node *node;
20844 + struct au_do_open_args args = {
20846 + .open = au_do_open_nondir
20849 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20850 + hlist_bl_lock(aopen);
20851 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20852 + if (node->file == file) {
20853 + args.h_file = node->h_file;
20856 + hlist_bl_unlock(aopen);
20857 + /* AuDebugOn(!args.h_file); */
20859 + return au_do_open(file, &args);
20862 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20863 + struct aopen_node *aopen_node)
20866 + struct hlist_bl_head *aopen;
20869 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20870 + au_hbl_add(&aopen_node->hblist, aopen);
20871 + err = finish_open(file, dentry, au_do_aopen);
20872 + au_hbl_del(&aopen_node->hblist, aopen);
20873 + /* AuDbgFile(file); */
20874 + AuDbg("%pd%s%s\n", dentry,
20875 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20876 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20882 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20888 + err = finish_no_open(file, dentry);
20894 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20895 + struct file *file, unsigned int open_flag,
20896 + umode_t create_mode)
20898 + int err, did_open;
20899 + unsigned int lkup_flags;
20900 + aufs_bindex_t bindex;
20901 + struct super_block *sb;
20902 + struct dentry *parent, *d;
20903 + struct vfsub_aopen_args args = {
20904 + .open_flag = open_flag,
20905 + .create_mode = create_mode
20907 + struct aopen_node aopen_node = {
20912 + AuDbg("open_flag 0%o\n", open_flag);
20913 + AuDbgDentry(dentry);
20916 + if (!au_di(dentry)) {
20917 + lkup_flags = LOOKUP_OPEN;
20918 + if (open_flag & O_CREAT)
20919 + lkup_flags |= LOOKUP_CREATE;
20920 + d = aufs_lookup(dir, dentry, lkup_flags);
20922 + err = PTR_ERR(d);
20927 + * obsoleted dentry found.
20928 + * another error will be returned later.
20934 + AuDbgDentry(dentry);
20937 + if (d_is_positive(dentry)
20938 + || d_unhashed(dentry)
20939 + || d_unlinked(dentry)
20940 + || !(open_flag & O_CREAT)) {
20941 + err = au_aopen_no_open(file, dentry);
20942 + goto out; /* success */
20945 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20946 + if (unlikely(err))
20949 + sb = dentry->d_sb;
20950 + parent = dentry->d_parent; /* dir is locked */
20951 + di_write_lock_parent(parent);
20952 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
20953 + if (unlikely(err < 0))
20956 + AuDbgDentry(dentry);
20957 + if (d_is_positive(dentry)) {
20958 + err = au_aopen_no_open(file, dentry);
20959 + goto out_parent; /* success */
20962 + args.file = alloc_empty_file(file->f_flags, current_cred());
20963 + err = PTR_ERR(args.file);
20964 + if (IS_ERR(args.file))
20967 + bindex = au_dbtop(dentry);
20968 + err = au_aopen_or_create(dir, dentry, &args);
20970 + AuDbgFile(args.file);
20971 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
20972 + did_open = !!(args.file->f_mode & FMODE_OPENED);
20975 + args.file = NULL;
20977 + di_write_unlock(parent);
20978 + di_write_unlock(dentry);
20979 + if (unlikely(err < 0)) {
20986 + err = au_aopen_no_open(file, dentry);
20988 + aopen_node.h_file = args.file;
20989 + err = au_aopen_do_open(file, dentry, &aopen_node);
20991 + if (unlikely(err < 0)) {
20995 + au_lcnt_dec(&args.br->br_nfiles);
20997 + goto out_sb; /* success */
21000 + di_write_unlock(parent);
21001 + di_write_unlock(dentry);
21003 + si_read_unlock(sb);
21011 +/* ---------------------------------------------------------------------- */
21013 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
21014 + const unsigned char add_entry, aufs_bindex_t bcpup,
21015 + aufs_bindex_t btop)
21018 + struct dentry *h_parent;
21019 + struct inode *h_dir;
21022 + IMustLock(d_inode(parent));
21024 + di_write_lock_parent(parent);
21027 + if (!au_h_dptr(parent, bcpup)) {
21028 + if (btop > bcpup)
21029 + err = au_cpup_dirs(dentry, bcpup);
21030 + else if (btop < bcpup)
21031 + err = au_cpdown_dirs(dentry, bcpup);
21035 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
21036 + h_parent = au_h_dptr(parent, bcpup);
21037 + h_dir = d_inode(h_parent);
21038 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
21039 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
21040 + /* todo: no unlock here */
21041 + inode_unlock_shared(h_dir);
21043 + AuDbg("bcpup %d\n", bcpup);
21045 + if (d_really_is_negative(dentry))
21046 + au_set_h_dptr(dentry, btop, NULL);
21047 + au_update_dbrange(dentry, /*do_put_zero*/0);
21052 + di_write_unlock(parent);
21054 + err = bcpup; /* success */
21061 + * decide the branch and the parent dir where we will create a new entry.
21062 + * returns new bindex or an error.
21063 + * copyup the parent dir if needed.
21065 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
21066 + struct au_wr_dir_args *args)
21069 + unsigned int flags;
21070 + aufs_bindex_t bcpup, btop, src_btop;
21071 + const unsigned char add_entry
21072 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
21073 + | au_ftest_wrdir(args->flags, TMPFILE);
21074 + struct super_block *sb;
21075 + struct dentry *parent;
21076 + struct au_sbinfo *sbinfo;
21078 + sb = dentry->d_sb;
21079 + sbinfo = au_sbi(sb);
21080 + parent = dget_parent(dentry);
21081 + btop = au_dbtop(dentry);
21083 + if (args->force_btgt < 0) {
21084 + if (src_dentry) {
21085 + src_btop = au_dbtop(src_dentry);
21086 + if (src_btop < btop)
21087 + bcpup = src_btop;
21088 + } else if (add_entry) {
21090 + if (au_ftest_wrdir(args->flags, ISDIR))
21091 + au_fset_wbr(flags, DIR);
21092 + err = AuWbrCreate(sbinfo, dentry, flags);
21096 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
21098 + err = AuWbrCopyup(sbinfo, dentry);
21100 + if (!IS_ROOT(dentry)) {
21101 + di_read_lock_parent(parent, !AuLock_IR);
21102 + err = AuWbrCopyup(sbinfo, dentry);
21103 + di_read_unlock(parent, !AuLock_IR);
21105 + err = AuWbrCopyup(sbinfo, dentry);
21108 + if (unlikely(err < 0))
21112 + bcpup = args->force_btgt;
21113 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21116 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21118 + if (bcpup == btop)
21119 + goto out; /* success */
21121 + /* copyup the new parent into the branch we process */
21122 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21124 + if (d_really_is_negative(dentry)) {
21125 + au_set_h_dptr(dentry, btop, NULL);
21126 + au_set_dbtop(dentry, bcpup);
21127 + au_set_dbbot(dentry, bcpup);
21129 + AuDebugOn(add_entry
21130 + && !au_ftest_wrdir(args->flags, TMPFILE)
21131 + && !au_h_dptr(dentry, bcpup));
21139 +/* ---------------------------------------------------------------------- */
21141 +void au_pin_hdir_unlock(struct au_pin *p)
21144 + au_hn_inode_unlock(p->hdir);
21147 +int au_pin_hdir_lock(struct au_pin *p)
21155 + /* even if an error happens later, keep this lock */
21156 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21159 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21164 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21165 + p->h_parent, p->br);
21171 +int au_pin_hdir_relock(struct au_pin *p)
21174 + struct inode *h_i;
21175 + struct dentry *h_d[] = {
21180 + err = au_pin_hdir_lock(p);
21181 + if (unlikely(err))
21184 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21187 + if (d_is_positive(h_d[i])) {
21188 + h_i = d_inode(h_d[i]);
21189 + err = !h_i->i_nlink;
21197 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21199 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
21202 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21205 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21206 + p->lsc_hi, 0, NULL, _RET_IP_);
21207 + au_pin_hdir_set_owner(p, current);
21211 +void au_pin_hdir_release(struct au_pin *p)
21214 + au_pin_hdir_set_owner(p, p->task);
21215 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
21219 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21221 + if (pin && pin->parent)
21222 + return au_h_dptr(pin->parent, pin->bindex);
21226 +void au_unpin(struct au_pin *p)
21229 + au_pin_hdir_unlock(p);
21230 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21231 + vfsub_mnt_drop_write(p->h_mnt);
21235 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21236 + di_read_unlock(p->parent, AuLock_IR);
21237 + iput(p->hdir->hi_inode);
21239 + p->parent = NULL;
21242 + /* do not clear p->task */
21245 +int au_do_pin(struct au_pin *p)
21248 + struct super_block *sb;
21249 + struct inode *h_dir;
21252 + sb = p->dentry->d_sb;
21253 + p->br = au_sbr(sb, p->bindex);
21254 + if (IS_ROOT(p->dentry)) {
21255 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21256 + p->h_mnt = au_br_mnt(p->br);
21257 + err = vfsub_mnt_want_write(p->h_mnt);
21258 + if (unlikely(err)) {
21259 + au_fclr_pin(p->flags, MNT_WRITE);
21266 + p->h_dentry = NULL;
21267 + if (p->bindex <= au_dbbot(p->dentry))
21268 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21270 + p->parent = dget_parent(p->dentry);
21271 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21272 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21275 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21276 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21278 + h_dir = p->hdir->hi_inode;
21282 + * if DI_LOCKED is not set, then p->parent may be different
21283 + * and h_parent can be NULL.
21285 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21287 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21288 + di_read_unlock(p->parent, AuLock_IR);
21290 + p->parent = NULL;
21294 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21295 + p->h_mnt = au_br_mnt(p->br);
21296 + err = vfsub_mnt_want_write(p->h_mnt);
21297 + if (unlikely(err)) {
21298 + au_fclr_pin(p->flags, MNT_WRITE);
21299 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21300 + di_read_unlock(p->parent, AuLock_IR);
21302 + p->parent = NULL;
21308 + err = au_pin_hdir_lock(p);
21310 + goto out; /* success */
21315 + pr_err("err %d\n", err);
21316 + err = au_busy_or_stale();
21321 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21322 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21323 + unsigned int udba, unsigned char flags)
21325 + p->dentry = dentry;
21327 + p->lsc_di = lsc_di;
21328 + p->lsc_hi = lsc_hi;
21329 + p->flags = flags;
21330 + p->bindex = bindex;
21332 + p->parent = NULL;
21336 + p->h_dentry = NULL;
21337 + p->h_parent = NULL;
21339 + p->task = current;
21342 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21343 + unsigned int udba, unsigned char flags)
21345 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21347 + return au_do_pin(pin);
21350 +/* ---------------------------------------------------------------------- */
21353 + * ->setattr() and ->getattr() are called in various cases.
21354 + * chmod, stat: dentry is revalidated.
21355 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21357 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21359 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21360 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21363 + struct dentry *parent;
21366 + if (au_digen_test(dentry, sigen)) {
21367 + parent = dget_parent(dentry);
21368 + di_read_lock_parent(parent, AuLock_IR);
21369 + err = au_refresh_dentry(dentry, parent);
21370 + di_read_unlock(parent, AuLock_IR);
21378 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21379 + struct au_icpup_args *a)
21383 + aufs_bindex_t btop, ibtop;
21384 + struct dentry *hi_wh, *parent;
21385 + struct inode *inode;
21386 + struct au_wr_dir_args wr_dir_args = {
21387 + .force_btgt = -1,
21391 + if (d_is_dir(dentry))
21392 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21393 + /* plink or hi_wh() case */
21394 + btop = au_dbtop(dentry);
21395 + inode = d_inode(dentry);
21396 + ibtop = au_ibtop(inode);
21397 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21398 + wr_dir_args.force_btgt = ibtop;
21399 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21400 + if (unlikely(err < 0))
21404 + au_fset_icpup(a->flags, DID_CPUP);
21407 + a->pin_flags = AuPin_MNT_WRITE;
21409 + if (!IS_ROOT(dentry)) {
21410 + au_fset_pin(a->pin_flags, DI_LOCKED);
21411 + parent = dget_parent(dentry);
21412 + di_write_lock_parent(parent);
21415 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21416 + if (unlikely(err))
21420 + a->h_path.dentry = au_h_dptr(dentry, btop);
21421 + a->h_inode = d_inode(a->h_path.dentry);
21422 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21423 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21424 + if (ia->ia_size < i_size_read(a->h_inode))
21425 + sz = ia->ia_size;
21426 + inode_unlock_shared(a->h_inode);
21430 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21431 + hi_wh = au_hi_wh(inode, a->btgt);
21433 + struct au_cp_generic cpg = {
21434 + .dentry = dentry,
21440 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21441 + if (unlikely(err))
21443 + hi_wh = au_hi_wh(inode, a->btgt);
21444 + /* todo: revalidate hi_wh? */
21449 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21450 + di_downgrade_lock(parent, AuLock_IR);
21454 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21455 + goto out; /* success */
21457 + if (!d_unhashed(dentry)) {
21458 + struct au_cp_generic cpg = {
21459 + .dentry = dentry,
21464 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21466 + err = au_sio_cpup_simple(&cpg);
21468 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21469 + } else if (!hi_wh)
21470 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21472 + a->h_path.dentry = hi_wh; /* do not dget here */
21475 + a->h_inode = d_inode(a->h_path.dentry);
21477 + goto out; /* success */
21478 + au_unpin(&a->pin);
21481 + di_write_unlock(parent);
21486 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21490 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21493 + struct inode *inode, *delegated;
21494 + struct super_block *sb;
21495 + struct file *file;
21496 + struct au_icpup_args *a;
21498 + inode = d_inode(dentry);
21499 + IMustLock(inode);
21501 + err = setattr_prepare(dentry, ia);
21502 + if (unlikely(err))
21506 + a = kzalloc(sizeof(*a), GFP_NOFS);
21507 + if (unlikely(!a))
21510 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21511 + ia->ia_valid &= ~ATTR_MODE;
21514 + sb = dentry->d_sb;
21515 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21516 + if (unlikely(err))
21519 + if (ia->ia_valid & ATTR_FILE) {
21520 + /* currently ftruncate(2) only */
21521 + AuDebugOn(!d_is_reg(dentry));
21522 + file = ia->ia_file;
21523 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21525 + if (unlikely(err))
21527 + ia->ia_file = au_hf_top(file);
21528 + a->udba = AuOpt_UDBA_NONE;
21530 + /* fchmod() doesn't pass ia_file */
21531 + a->udba = au_opt_udba(sb);
21532 + di_write_lock_child(dentry);
21533 + /* no d_unlinked(), to set UDBA_NONE for root */
21534 + if (d_unhashed(dentry))
21535 + a->udba = AuOpt_UDBA_NONE;
21536 + if (a->udba != AuOpt_UDBA_NONE) {
21537 + AuDebugOn(IS_ROOT(dentry));
21538 + err = au_reval_for_attr(dentry, au_sigen(sb));
21539 + if (unlikely(err))
21544 + err = au_pin_and_icpup(dentry, ia, a);
21545 + if (unlikely(err < 0))
21547 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21548 + ia->ia_file = NULL;
21549 + ia->ia_valid &= ~ATTR_FILE;
21552 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21553 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21554 + == (ATTR_MODE | ATTR_CTIME)) {
21555 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21556 + if (unlikely(err))
21558 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21559 + && (ia->ia_valid & ATTR_CTIME)) {
21560 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21561 + if (unlikely(err))
21565 + if (ia->ia_valid & ATTR_SIZE) {
21568 + if (ia->ia_size < i_size_read(inode))
21570 + truncate_setsize(inode, ia->ia_size);
21573 + if (ia->ia_valid & ATTR_FILE)
21575 + inode_unlock(a->h_inode);
21576 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21577 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21579 + delegated = NULL;
21581 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21583 + err = break_deleg_wait(&delegated);
21591 + * regardless aufs 'acl' option setting.
21592 + * why don't all acl-aware fs call this func from their ->setattr()?
21594 + if (!err && (ia->ia_valid & ATTR_MODE))
21595 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21597 + au_cpup_attr_changeable(inode);
21600 + inode_unlock(a->h_inode);
21601 + au_unpin(&a->pin);
21602 + if (unlikely(err))
21603 + au_update_dbtop(dentry);
21605 + di_write_unlock(dentry);
21607 + fi_write_unlock(file);
21608 + ia->ia_file = file;
21609 + ia->ia_valid |= ATTR_FILE;
21612 + si_read_unlock(sb);
21620 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21621 +static int au_h_path_to_set_attr(struct dentry *dentry,
21622 + struct au_icpup_args *a, struct path *h_path)
21625 + struct super_block *sb;
21627 + sb = dentry->d_sb;
21628 + a->udba = au_opt_udba(sb);
21629 + /* no d_unlinked(), to set UDBA_NONE for root */
21630 + if (d_unhashed(dentry))
21631 + a->udba = AuOpt_UDBA_NONE;
21632 + if (a->udba != AuOpt_UDBA_NONE) {
21633 + AuDebugOn(IS_ROOT(dentry));
21634 + err = au_reval_for_attr(dentry, au_sigen(sb));
21635 + if (unlikely(err))
21638 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21639 + if (unlikely(err < 0))
21642 + h_path->dentry = a->h_path.dentry;
21643 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21649 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21650 + struct au_sxattr *arg)
21653 + struct path h_path;
21654 + struct super_block *sb;
21655 + struct au_icpup_args *a;
21656 + struct inode *h_inode;
21658 + IMustLock(inode);
21661 + a = kzalloc(sizeof(*a), GFP_NOFS);
21662 + if (unlikely(!a))
21665 + sb = dentry->d_sb;
21666 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21667 + if (unlikely(err))
21670 + h_path.dentry = NULL; /* silence gcc */
21671 + di_write_lock_child(dentry);
21672 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21673 + if (unlikely(err))
21676 + inode_unlock(a->h_inode);
21677 + switch (arg->type) {
21678 + case AU_XATTR_SET:
21679 + AuDebugOn(d_is_negative(h_path.dentry));
21680 + err = vfsub_setxattr(h_path.dentry,
21681 + arg->u.set.name, arg->u.set.value,
21682 + arg->u.set.size, arg->u.set.flags);
21685 + err = -EOPNOTSUPP;
21686 + h_inode = d_inode(h_path.dentry);
21687 + if (h_inode->i_op->set_acl)
21688 + /* this will call posix_acl_update_mode */
21689 + err = h_inode->i_op->set_acl(h_inode,
21690 + arg->u.acl_set.acl,
21691 + arg->u.acl_set.type);
21695 + au_cpup_attr_timesizes(inode);
21697 + au_unpin(&a->pin);
21698 + if (unlikely(err))
21699 + au_update_dbtop(dentry);
21702 + di_write_unlock(dentry);
21703 + si_read_unlock(sb);
21712 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21713 + unsigned int nlink)
21717 + inode->i_mode = st->mode;
21718 + /* don't i_[ug]id_write() here */
21719 + inode->i_uid = st->uid;
21720 + inode->i_gid = st->gid;
21721 + inode->i_atime = st->atime;
21722 + inode->i_mtime = st->mtime;
21723 + inode->i_ctime = st->ctime;
21725 + au_cpup_attr_nlink(inode, /*force*/0);
21726 + if (S_ISDIR(inode->i_mode)) {
21727 + n = inode->i_nlink;
21730 + smp_mb(); /* for i_nlink */
21731 + /* 0 can happen */
21732 + set_nlink(inode, n);
21735 + spin_lock(&inode->i_lock);
21736 + inode->i_blocks = st->blocks;
21737 + i_size_write(inode, st->size);
21738 + spin_unlock(&inode->i_lock);
21742 + * common routine for aufs_getattr() and au_getxattr().
21743 + * returns zero or negative (an error).
21744 + * @dentry will be read-locked in success.
21746 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
21747 + struct path *h_path, int locked)
21750 + unsigned int mnt_flags, sigen;
21751 + unsigned char udba_none;
21752 + aufs_bindex_t bindex;
21753 + struct super_block *sb, *h_sb;
21755 + h_path->mnt = NULL;
21756 + h_path->dentry = NULL;
21759 + sb = dentry->d_sb;
21760 + mnt_flags = au_mntflags(sb);
21761 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21763 + if (unlikely(locked))
21764 + goto body; /* skip locking dinfo */
21766 + /* support fstat(2) */
21767 + if (!d_unlinked(dentry) && !udba_none) {
21768 + sigen = au_sigen(sb);
21769 + err = au_digen_test(dentry, sigen);
21771 + di_read_lock_child(dentry, AuLock_IR);
21772 + err = au_dbrange_test(dentry);
21773 + if (unlikely(err)) {
21774 + di_read_unlock(dentry, AuLock_IR);
21778 + AuDebugOn(IS_ROOT(dentry));
21779 + di_write_lock_child(dentry);
21780 + err = au_dbrange_test(dentry);
21782 + err = au_reval_for_attr(dentry, sigen);
21784 + di_downgrade_lock(dentry, AuLock_IR);
21786 + di_write_unlock(dentry);
21791 + di_read_lock_child(dentry, AuLock_IR);
21795 + inode = d_inode(dentry);
21796 + if (unlikely(!inode))
21799 + bindex = au_ibtop(inode);
21800 + h_path->mnt = au_sbr_mnt(sb, bindex);
21801 + h_sb = h_path->mnt->mnt_sb;
21803 + && !au_test_fs_bad_iattr(h_sb)
21805 + goto out; /* success */
21807 + if (au_dbtop(dentry) == bindex)
21808 + h_path->dentry = au_h_dptr(dentry, bindex);
21809 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21810 + h_path->dentry = au_plink_lkup(inode, bindex);
21811 + if (IS_ERR(h_path->dentry))
21812 + /* pretending success */
21813 + h_path->dentry = NULL;
21815 + dput(h_path->dentry);
21822 +static int aufs_getattr(const struct path *path, struct kstat *st,
21823 + u32 request, unsigned int query)
21826 + unsigned char positive;
21827 + struct path h_path;
21828 + struct dentry *dentry;
21829 + struct inode *inode;
21830 + struct super_block *sb;
21832 + dentry = path->dentry;
21833 + inode = d_inode(dentry);
21834 + sb = dentry->d_sb;
21835 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21836 + if (unlikely(err))
21838 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
21840 + if (unlikely(err))
21842 + if (unlikely(!h_path.dentry))
21843 + /* illegally overlapped or something */
21844 + goto out_fill; /* pretending success */
21846 + positive = d_is_positive(h_path.dentry);
21848 + /* no vfsub version */
21849 + err = vfs_getattr(&h_path, st, request, query);
21852 + au_refresh_iattr(inode, st,
21853 + d_inode(h_path.dentry)->i_nlink);
21854 + goto out_fill; /* success */
21860 + generic_fillattr(inode, st);
21862 + di_read_unlock(dentry, AuLock_IR);
21864 + si_read_unlock(sb);
21870 +/* ---------------------------------------------------------------------- */
21872 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21873 + struct delayed_call *done)
21876 + struct dentry *h_dentry;
21877 + struct inode *h_inode;
21879 + aufs_bindex_t bindex;
21881 + ret = NULL; /* suppress a warning */
21886 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21887 + if (unlikely(err))
21890 + err = au_d_hashed_positive(dentry);
21891 + if (unlikely(err))
21895 + inode = d_inode(dentry);
21896 + bindex = au_ibtop(inode);
21897 + h_inode = au_h_iptr(inode, bindex);
21898 + if (unlikely(!h_inode->i_op->get_link))
21903 + if (au_dbtop(dentry) <= bindex) {
21904 + h_dentry = au_h_dptr(dentry, bindex);
21909 + h_dentry = d_find_any_alias(h_inode);
21910 + if (IS_ERR(h_dentry)) {
21911 + err = PTR_ERR(h_dentry);
21915 + if (unlikely(!h_dentry))
21919 + AuDbg("%ps\n", h_inode->i_op->get_link);
21920 + AuDbgDentry(h_dentry);
21921 + ret = vfs_get_link(h_dentry, done);
21924 + err = PTR_ERR(ret);
21927 + aufs_read_unlock(dentry, AuLock_IR);
21929 + if (unlikely(err))
21930 + ret = ERR_PTR(err);
21931 + AuTraceErrPtr(ret);
21935 +/* ---------------------------------------------------------------------- */
21937 +static int au_is_special(struct inode *inode)
21939 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
21942 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
21946 + aufs_bindex_t bindex;
21947 + struct super_block *sb;
21948 + struct inode *h_inode;
21949 + struct vfsmount *h_mnt;
21951 + sb = inode->i_sb;
21952 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
21953 + "unexpected s_flags 0x%lx", sb->s_flags);
21955 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
21957 + si_read_lock(sb, AuLock_FLUSH);
21958 + ii_write_lock_child(inode);
21961 + bindex = au_ibtop(inode);
21962 + h_inode = au_h_iptr(inode, bindex);
21963 + if (!au_test_ro(sb, bindex, inode)) {
21964 + h_mnt = au_sbr_mnt(sb, bindex);
21965 + err = vfsub_mnt_want_write(h_mnt);
21967 + err = vfsub_update_time(h_inode, ts, flags);
21968 + vfsub_mnt_drop_write(h_mnt);
21970 + } else if (au_is_special(h_inode)) {
21972 + * Never copy-up here.
21973 + * These special files may already be opened and used for
21974 + * communicating. If we copied it up, then the communication
21975 + * would be corrupted.
21977 + AuWarn1("timestamps for i%lu are ignored "
21978 + "since it is on readonly branch (hi%lu).\n",
21979 + inode->i_ino, h_inode->i_ino);
21980 + } else if (flags & ~S_ATIME) {
21982 + AuIOErr1("unexpected flags 0x%x\n", flags);
21987 + au_cpup_attr_timesizes(inode);
21988 + ii_write_unlock(inode);
21989 + si_read_unlock(sb);
21992 + if (!err && (flags & S_VERSION))
21993 + inode_inc_iversion(inode);
21998 +/* ---------------------------------------------------------------------- */
22000 +/* no getattr version will be set by module.c:aufs_init() */
22001 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
22003 + [AuIop_SYMLINK] = {
22004 + .permission = aufs_permission,
22005 +#ifdef CONFIG_FS_POSIX_ACL
22006 + .get_acl = aufs_get_acl,
22007 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
22010 + .setattr = aufs_setattr,
22011 + .getattr = aufs_getattr,
22013 +#ifdef CONFIG_AUFS_XATTR
22014 + .listxattr = aufs_listxattr,
22017 + .get_link = aufs_get_link,
22019 + /* .update_time = aufs_update_time */
22022 + .create = aufs_create,
22023 + .lookup = aufs_lookup,
22024 + .link = aufs_link,
22025 + .unlink = aufs_unlink,
22026 + .symlink = aufs_symlink,
22027 + .mkdir = aufs_mkdir,
22028 + .rmdir = aufs_rmdir,
22029 + .mknod = aufs_mknod,
22030 + .rename = aufs_rename,
22032 + .permission = aufs_permission,
22033 +#ifdef CONFIG_FS_POSIX_ACL
22034 + .get_acl = aufs_get_acl,
22035 + .set_acl = aufs_set_acl,
22038 + .setattr = aufs_setattr,
22039 + .getattr = aufs_getattr,
22041 +#ifdef CONFIG_AUFS_XATTR
22042 + .listxattr = aufs_listxattr,
22045 + .update_time = aufs_update_time,
22046 + .atomic_open = aufs_atomic_open,
22047 + .tmpfile = aufs_tmpfile
22049 + [AuIop_OTHER] = {
22050 + .permission = aufs_permission,
22051 +#ifdef CONFIG_FS_POSIX_ACL
22052 + .get_acl = aufs_get_acl,
22053 + .set_acl = aufs_set_acl,
22056 + .setattr = aufs_setattr,
22057 + .getattr = aufs_getattr,
22059 +#ifdef CONFIG_AUFS_XATTR
22060 + .listxattr = aufs_listxattr,
22063 + .update_time = aufs_update_time
22066 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
22067 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
22068 +++ linux/fs/aufs/i_op_del.c 2020-01-27 10:57:18.172204883 +0100
22070 +// SPDX-License-Identifier: GPL-2.0
22072 + * Copyright (C) 2005-2020 Junjiro R. Okajima
22074 + * This program, aufs is free software; you can redistribute it and/or modify
22075 + * it under the terms of the GNU General Public License as published by
22076 + * the Free Software Foundation; either version 2 of the License, or
22077 + * (at your option) any later version.
22079 + * This program is distributed in the hope that it will be useful,
22080 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22081 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22082 + * GNU General Public License for more details.
22084 + * You should have received a copy of the GNU General Public License
22085 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22089 + * inode operations (del entry)
22092 +#include <linux/iversion.h>
22096 + * decide if a new whiteout for @dentry is necessary or not.
22097 + * when it is necessary, prepare the parent dir for the upper branch whose
22098 + * branch index is @bcpup for creation. the actual creation of the whiteout will
22099 + * be done by caller.
22101 + * 0: wh is unnecessary
22102 + * plus: wh is necessary
22105 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
22107 + int need_wh, err;
22108 + aufs_bindex_t btop;
22109 + struct super_block *sb;
22111 + sb = dentry->d_sb;
22112 + btop = au_dbtop(dentry);
22113 + if (*bcpup < 0) {
22115 + if (au_test_ro(sb, btop, d_inode(dentry))) {
22116 + err = AuWbrCopyup(au_sbi(sb), dentry);
22118 + if (unlikely(err < 0))
22122 + AuDebugOn(btop < *bcpup
22123 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22124 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22126 + if (*bcpup != btop) {
22127 + err = au_cpup_dirs(dentry, *bcpup);
22128 + if (unlikely(err))
22132 + struct au_dinfo *dinfo, *tmp;
22134 + need_wh = -ENOMEM;
22135 + dinfo = au_di(dentry);
22136 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22138 + au_di_cp(tmp, dinfo);
22139 + au_di_swap(tmp, dinfo);
22140 + /* returns the number of positive dentries */
22141 + need_wh = au_lkup_dentry(dentry, btop + 1,
22142 + /* AuLkup_IGNORE_PERM */ 0);
22143 + au_di_swap(tmp, dinfo);
22144 + au_rw_write_unlock(&tmp->di_rwsem);
22148 + AuDbg("need_wh %d\n", need_wh);
22156 + * simple tests for the del-entry operations.
22157 + * following the checks in vfs, plus the parent-child relationship.
22159 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22160 + struct dentry *h_parent, int isdir)
22164 + struct dentry *h_dentry, *h_latest;
22165 + struct inode *h_inode;
22167 + h_dentry = au_h_dptr(dentry, bindex);
22168 + if (d_really_is_positive(dentry)) {
22170 + if (unlikely(d_is_negative(h_dentry)))
22172 + h_inode = d_inode(h_dentry);
22173 + if (unlikely(!h_inode->i_nlink))
22176 + h_mode = h_inode->i_mode;
22179 + if (unlikely(S_ISDIR(h_mode)))
22181 + } else if (unlikely(!S_ISDIR(h_mode))) {
22186 + /* rename(2) case */
22188 + if (unlikely(d_is_positive(h_dentry)))
22193 + /* expected parent dir is locked */
22194 + if (unlikely(h_parent != h_dentry->d_parent))
22199 + * rmdir a dir may break the consistency on some filesystem.
22200 + * let's try heavy test.
22203 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22204 + && au_test_h_perm(d_inode(h_parent),
22205 + MAY_EXEC | MAY_WRITE)))
22208 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
22210 + if (IS_ERR(h_latest))
22212 + if (h_latest == h_dentry)
22221 + * decide the branch where we operate for @dentry. the branch index will be set
22222 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22223 + * dir for reverting.
22224 + * when a new whiteout is necessary, create it.
22226 +static struct dentry*
22227 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22228 + struct au_dtime *dt, struct au_pin *pin)
22230 + struct dentry *wh_dentry;
22231 + struct super_block *sb;
22232 + struct path h_path;
22233 + int err, need_wh;
22234 + unsigned int udba;
22235 + aufs_bindex_t bcpup;
22237 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22238 + wh_dentry = ERR_PTR(need_wh);
22239 + if (unlikely(need_wh < 0))
22242 + sb = dentry->d_sb;
22243 + udba = au_opt_udba(sb);
22245 + err = au_pin(pin, dentry, bcpup, udba,
22246 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22247 + wh_dentry = ERR_PTR(err);
22248 + if (unlikely(err))
22251 + h_path.dentry = au_pinned_h_parent(pin);
22252 + if (udba != AuOpt_UDBA_NONE
22253 + && au_dbtop(dentry) == bcpup) {
22254 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22255 + wh_dentry = ERR_PTR(err);
22256 + if (unlikely(err))
22260 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22261 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22262 + wh_dentry = NULL;
22264 + goto out; /* success, no need to create whiteout */
22266 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22267 + if (IS_ERR(wh_dentry))
22270 + /* returns with the parent is locked and wh_dentry is dget-ed */
22271 + goto out; /* success */
22276 + return wh_dentry;
22280 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22281 + * in order to be revertible and save time for removing many child whiteouts
22283 + * returns 1 when there are too many child whiteout and caller should remove
22284 + * them asynchronously. returns 0 when the number of children is enough small to
22285 + * remove now or the branch fs is a remote fs.
22286 + * otherwise return an error.
22288 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22289 + struct au_nhash *whlist, struct inode *dir)
22291 + int rmdir_later, err, dirwh;
22292 + struct dentry *h_dentry;
22293 + struct super_block *sb;
22294 + struct inode *inode;
22296 + sb = dentry->d_sb;
22297 + SiMustAnyLock(sb);
22298 + h_dentry = au_h_dptr(dentry, bindex);
22299 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22300 + if (unlikely(err))
22303 + /* stop monitoring */
22304 + inode = d_inode(dentry);
22305 + au_hn_free(au_hi(inode, bindex));
22307 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22308 + dirwh = au_sbi(sb)->si_dirwh;
22309 + rmdir_later = (dirwh <= 1);
22310 + if (!rmdir_later)
22311 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22314 + return rmdir_later;
22317 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22318 + if (unlikely(err)) {
22319 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22320 + h_dentry, bindex, err);
22330 + * final procedure for deleting a entry.
22331 + * maintain dentry and iattr.
22333 +static void epilog(struct inode *dir, struct dentry *dentry,
22334 + aufs_bindex_t bindex)
22336 + struct inode *inode;
22338 + inode = d_inode(dentry);
22340 + inode->i_ctime = dir->i_ctime;
22342 + au_dir_ts(dir, bindex);
22343 + inode_inc_iversion(dir);
22347 + * when an error happened, remove the created whiteout and revert everything.
22349 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22350 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22351 + struct dentry *dentry, struct au_dtime *dt)
22354 + struct path h_path = {
22355 + .dentry = wh_dentry,
22356 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22359 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22361 + au_set_dbwh(dentry, bwh);
22362 + au_dtime_revert(dt);
22366 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22370 +/* ---------------------------------------------------------------------- */
22372 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22375 + aufs_bindex_t bwh, bindex, btop;
22376 + struct inode *inode, *h_dir, *delegated;
22377 + struct dentry *parent, *wh_dentry;
22378 + /* to reduce stack size */
22380 + struct au_dtime dt;
22381 + struct au_pin pin;
22382 + struct path h_path;
22388 + a = kmalloc(sizeof(*a), GFP_NOFS);
22389 + if (unlikely(!a))
22392 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22393 + if (unlikely(err))
22395 + err = au_d_hashed_positive(dentry);
22396 + if (unlikely(err))
22398 + inode = d_inode(dentry);
22399 + IMustLock(inode);
22401 + if (unlikely(d_is_dir(dentry)))
22402 + goto out_unlock; /* possible? */
22404 + btop = au_dbtop(dentry);
22405 + bwh = au_dbwh(dentry);
22407 + parent = dentry->d_parent; /* dir inode is locked */
22408 + di_write_lock_parent(parent);
22409 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22411 + err = PTR_ERR(wh_dentry);
22412 + if (IS_ERR(wh_dentry))
22415 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22416 + a->h_path.dentry = au_h_dptr(dentry, btop);
22417 + dget(a->h_path.dentry);
22418 + if (bindex == btop) {
22419 + h_dir = au_pinned_h_dir(&a->pin);
22420 + delegated = NULL;
22421 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22422 + if (unlikely(err == -EWOULDBLOCK)) {
22423 + pr_warn("cannot retry for NFSv4 delegation"
22424 + " for an internal unlink\n");
22428 + /* dir inode is locked */
22429 + h_dir = d_inode(wh_dentry->d_parent);
22430 + IMustLock(h_dir);
22435 + vfsub_drop_nlink(inode);
22436 + epilog(dir, dentry, bindex);
22438 + /* update target timestamps */
22439 + if (bindex == btop) {
22440 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22442 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22444 + /* todo: this timestamp may be reverted later */
22445 + inode->i_ctime = h_dir->i_ctime;
22446 + goto out_unpin; /* success */
22453 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22460 + au_unpin(&a->pin);
22462 + dput(a->h_path.dentry);
22464 + di_write_unlock(parent);
22466 + aufs_read_unlock(dentry, AuLock_DW);
22473 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22475 + int err, rmdir_later;
22476 + aufs_bindex_t bwh, bindex, btop;
22477 + struct inode *inode;
22478 + struct dentry *parent, *wh_dentry, *h_dentry;
22479 + struct au_whtmp_rmdir *args;
22480 + /* to reduce stack size */
22482 + struct au_dtime dt;
22483 + struct au_pin pin;
22489 + a = kmalloc(sizeof(*a), GFP_NOFS);
22490 + if (unlikely(!a))
22493 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22494 + if (unlikely(err))
22496 + err = au_alive_dir(dentry);
22497 + if (unlikely(err))
22499 + inode = d_inode(dentry);
22500 + IMustLock(inode);
22502 + if (unlikely(!d_is_dir(dentry)))
22503 + goto out_unlock; /* possible? */
22506 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22507 + if (unlikely(!args))
22510 + parent = dentry->d_parent; /* dir inode is locked */
22511 + di_write_lock_parent(parent);
22512 + err = au_test_empty(dentry, &args->whlist);
22513 + if (unlikely(err))
22516 + btop = au_dbtop(dentry);
22517 + bwh = au_dbwh(dentry);
22519 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22521 + err = PTR_ERR(wh_dentry);
22522 + if (IS_ERR(wh_dentry))
22525 + h_dentry = au_h_dptr(dentry, btop);
22528 + if (bindex == btop) {
22529 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22531 + rmdir_later = err;
22535 + /* stop monitoring */
22536 + au_hn_free(au_hi(inode, btop));
22538 + /* dir inode is locked */
22539 + IMustLock(d_inode(wh_dentry->d_parent));
22544 + vfsub_dead_dir(inode);
22545 + au_set_dbdiropq(dentry, -1);
22546 + epilog(dir, dentry, bindex);
22548 + if (rmdir_later) {
22549 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22553 + goto out_unpin; /* success */
22561 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22568 + au_unpin(&a->pin);
22572 + di_write_unlock(parent);
22574 + au_whtmp_rmdir_free(args);
22576 + aufs_read_unlock(dentry, AuLock_DW);
22583 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22584 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22585 +++ linux/fs/aufs/i_op_ren.c 2020-01-27 10:57:18.172204883 +0100
22587 +// SPDX-License-Identifier: GPL-2.0
22589 + * Copyright (C) 2005-2020 Junjiro R. Okajima
22591 + * This program, aufs is free software; you can redistribute it and/or modify
22592 + * it under the terms of the GNU General Public License as published by
22593 + * the Free Software Foundation; either version 2 of the License, or
22594 + * (at your option) any later version.
22596 + * This program is distributed in the hope that it will be useful,
22597 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22598 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22599 + * GNU General Public License for more details.
22601 + * You should have received a copy of the GNU General Public License
22602 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22606 + * inode operation (rename entry)
22607 + * todo: this is crazy monster
22610 +#include <linux/iversion.h>
22613 +enum { AuSRC, AuDST, AuSrcDst };
22614 +enum { AuPARENT, AuCHILD, AuParentChild };
22616 +#define AuRen_ISDIR_SRC 1
22617 +#define AuRen_ISDIR_DST (1 << 1)
22618 +#define AuRen_ISSAMEDIR (1 << 2)
22619 +#define AuRen_WHSRC (1 << 3)
22620 +#define AuRen_WHDST (1 << 4)
22621 +#define AuRen_MNT_WRITE (1 << 5)
22622 +#define AuRen_DT_DSTDIR (1 << 6)
22623 +#define AuRen_DIROPQ_SRC (1 << 7)
22624 +#define AuRen_DIROPQ_DST (1 << 8)
22625 +#define AuRen_DIRREN (1 << 9)
22626 +#define AuRen_DROPPED_SRC (1 << 10)
22627 +#define AuRen_DROPPED_DST (1 << 11)
22628 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22629 +#define au_fset_ren(flags, name) \
22630 + do { (flags) |= AuRen_##name; } while (0)
22631 +#define au_fclr_ren(flags, name) \
22632 + do { (flags) &= ~AuRen_##name; } while (0)
22634 +#ifndef CONFIG_AUFS_DIRREN
22635 +#undef AuRen_DIRREN
22636 +#define AuRen_DIRREN 0
22639 +struct au_ren_args {
22641 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22643 + struct inode *dir, *inode;
22644 + struct au_hinode *hdir, *hinode;
22645 + struct au_dtime dt[AuParentChild];
22646 + aufs_bindex_t btop, bdiropq;
22649 +#define src_dentry sd[AuSRC].dentry
22650 +#define src_dir sd[AuSRC].dir
22651 +#define src_inode sd[AuSRC].inode
22652 +#define src_h_dentry sd[AuSRC].h_dentry
22653 +#define src_parent sd[AuSRC].parent
22654 +#define src_h_parent sd[AuSRC].h_parent
22655 +#define src_wh_dentry sd[AuSRC].wh_dentry
22656 +#define src_hdir sd[AuSRC].hdir
22657 +#define src_hinode sd[AuSRC].hinode
22658 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22659 +#define src_dt sd[AuSRC].dt
22660 +#define src_btop sd[AuSRC].btop
22661 +#define src_bdiropq sd[AuSRC].bdiropq
22663 +#define dst_dentry sd[AuDST].dentry
22664 +#define dst_dir sd[AuDST].dir
22665 +#define dst_inode sd[AuDST].inode
22666 +#define dst_h_dentry sd[AuDST].h_dentry
22667 +#define dst_parent sd[AuDST].parent
22668 +#define dst_h_parent sd[AuDST].h_parent
22669 +#define dst_wh_dentry sd[AuDST].wh_dentry
22670 +#define dst_hdir sd[AuDST].hdir
22671 +#define dst_hinode sd[AuDST].hinode
22672 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22673 +#define dst_dt sd[AuDST].dt
22674 +#define dst_btop sd[AuDST].btop
22675 +#define dst_bdiropq sd[AuDST].bdiropq
22677 + struct dentry *h_trap;
22678 + struct au_branch *br;
22679 + struct path h_path;
22680 + struct au_nhash whlist;
22681 + aufs_bindex_t btgt, src_bwh;
22684 + unsigned short auren_flags;
22685 + unsigned char flags; /* syscall parameter */
22686 + unsigned char exchange;
22689 + struct au_whtmp_rmdir *thargs;
22690 + struct dentry *h_dst;
22691 + struct au_hinode *h_root;
22694 +/* ---------------------------------------------------------------------- */
22697 + * functions for reverting.
22698 + * when an error happened in a single rename systemcall, we should revert
22699 + * everything as if nothing happened.
22700 + * we don't need to revert the copied-up/down the parent dir since they are
22704 +#define RevertFailure(fmt, ...) do { \
22705 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22706 + ##__VA_ARGS__, err, rerr); \
22710 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22713 + struct dentry *d;
22714 +#define src_or_dst(member) a->sd[idx].member
22716 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22717 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22718 + rerr = au_diropq_remove(d, a->btgt);
22719 + au_hn_inode_unlock(src_or_dst(hinode));
22720 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22722 + RevertFailure("remove diropq %pd", d);
22724 +#undef src_or_dst_
22727 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22729 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22730 + au_ren_do_rev_diropq(err, a, AuSRC);
22731 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22732 + au_ren_do_rev_diropq(err, a, AuDST);
22735 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22738 + struct inode *delegated;
22740 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22741 + a->src_h_parent);
22742 + rerr = PTR_ERR(a->h_path.dentry);
22743 + if (IS_ERR(a->h_path.dentry)) {
22744 + RevertFailure("lkup one %pd", a->src_dentry);
22748 + delegated = NULL;
22749 + rerr = vfsub_rename(a->dst_h_dir,
22750 + au_h_dptr(a->src_dentry, a->btgt),
22751 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22752 + if (unlikely(rerr == -EWOULDBLOCK)) {
22753 + pr_warn("cannot retry for NFSv4 delegation"
22754 + " for an internal rename\n");
22757 + d_drop(a->h_path.dentry);
22758 + dput(a->h_path.dentry);
22759 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22761 + RevertFailure("rename %pd", a->src_dentry);
22764 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22767 + struct inode *delegated;
22769 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22770 + a->dst_h_parent);
22771 + rerr = PTR_ERR(a->h_path.dentry);
22772 + if (IS_ERR(a->h_path.dentry)) {
22773 + RevertFailure("lkup one %pd", a->dst_dentry);
22776 + if (d_is_positive(a->h_path.dentry)) {
22777 + d_drop(a->h_path.dentry);
22778 + dput(a->h_path.dentry);
22782 + delegated = NULL;
22783 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22784 + &delegated, a->flags);
22785 + if (unlikely(rerr == -EWOULDBLOCK)) {
22786 + pr_warn("cannot retry for NFSv4 delegation"
22787 + " for an internal rename\n");
22790 + d_drop(a->h_path.dentry);
22791 + dput(a->h_path.dentry);
22793 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22795 + RevertFailure("rename %pd", a->h_dst);
22798 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22802 + a->h_path.dentry = a->src_wh_dentry;
22803 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22804 + au_set_dbwh(a->src_dentry, a->src_bwh);
22806 + RevertFailure("unlink %pd", a->src_wh_dentry);
22808 +#undef RevertFailure
22810 +/* ---------------------------------------------------------------------- */
22813 + * when we have to copyup the renaming entry, do it with the rename-target name
22814 + * in order to minimize the cost (the later actual rename is unnecessary).
22815 + * otherwise rename it on the target branch.
22817 +static int au_ren_or_cpup(struct au_ren_args *a)
22820 + struct dentry *d;
22821 + struct inode *delegated;
22823 + d = a->src_dentry;
22824 + if (au_dbtop(d) == a->btgt) {
22825 + a->h_path.dentry = a->dst_h_dentry;
22826 + AuDebugOn(au_dbtop(d) != a->btgt);
22827 + delegated = NULL;
22828 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22829 + a->dst_h_dir, &a->h_path, &delegated,
22831 + if (unlikely(err == -EWOULDBLOCK)) {
22832 + pr_warn("cannot retry for NFSv4 delegation"
22833 + " for an internal rename\n");
22839 + if (!err && a->h_dst)
22840 + /* it will be set to dinfo later */
22846 +/* cf. aufs_rmdir() */
22847 +static int au_ren_del_whtmp(struct au_ren_args *a)
22850 + struct inode *dir;
22852 + dir = a->dst_dir;
22853 + SiMustAnyLock(dir->i_sb);
22854 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22855 + au_sbi(dir->i_sb)->si_dirwh)
22856 + || au_test_fs_remote(a->h_dst->d_sb)) {
22857 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22858 + if (unlikely(err))
22859 + pr_warn("failed removing whtmp dir %pd (%d), "
22860 + "ignored.\n", a->h_dst, err);
22862 + au_nhash_wh_free(&a->thargs->whlist);
22863 + a->thargs->whlist = a->whlist;
22864 + a->whlist.nh_num = 0;
22865 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22867 + a->thargs = NULL;
22873 +/* make it 'opaque' dir. */
22874 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22877 + struct dentry *d, *diropq;
22878 +#define src_or_dst(member) a->sd[idx].member
22881 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22882 + src_or_dst(bdiropq) = au_dbdiropq(d);
22883 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22884 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22885 + diropq = au_diropq_create(d, a->btgt);
22886 + au_hn_inode_unlock(src_or_dst(hinode));
22887 + if (IS_ERR(diropq))
22888 + err = PTR_ERR(diropq);
22892 +#undef src_or_dst_
22896 +static int au_ren_diropq(struct au_ren_args *a)
22899 + unsigned char always;
22900 + struct dentry *d;
22903 + d = a->dst_dentry; /* already renamed on the branch */
22904 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22905 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22906 + && !au_ftest_ren(a->auren_flags, DIRREN)
22907 + && a->btgt != au_dbdiropq(a->src_dentry)
22908 + && (a->dst_wh_dentry
22909 + || a->btgt <= au_dbdiropq(d)
22910 + /* hide the lower to keep xino */
22911 + /* the lowers may not be a dir, but we hide them anyway */
22912 + || a->btgt < au_dbbot(d)
22915 + err = au_ren_do_diropq(a, AuSRC);
22916 + if (unlikely(err))
22918 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22920 + if (!a->exchange)
22921 + goto out; /* success */
22923 + d = a->src_dentry; /* already renamed on the branch */
22924 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22925 + && a->btgt != au_dbdiropq(a->dst_dentry)
22926 + && (a->btgt < au_dbdiropq(d)
22927 + || a->btgt < au_dbbot(d)
22929 + AuDbgDentry(a->src_dentry);
22930 + AuDbgDentry(a->dst_dentry);
22931 + err = au_ren_do_diropq(a, AuDST);
22932 + if (unlikely(err))
22933 + goto out_rev_src;
22934 + au_fset_ren(a->auren_flags, DIROPQ_DST);
22936 + goto out; /* success */
22939 + AuDbg("err %d, reverting src\n", err);
22940 + au_ren_rev_diropq(err, a);
22945 +static int do_rename(struct au_ren_args *a)
22948 + struct dentry *d, *h_d;
22950 + if (!a->exchange) {
22951 + /* prepare workqueue args for asynchronous rmdir */
22952 + h_d = a->dst_h_dentry;
22953 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22954 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
22955 + && d_is_positive(h_d)) {
22957 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
22959 + if (unlikely(!a->thargs))
22961 + a->h_dst = dget(h_d);
22964 + /* create whiteout for src_dentry */
22965 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
22966 + a->src_bwh = au_dbwh(a->src_dentry);
22967 + AuDebugOn(a->src_bwh >= 0);
22968 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
22969 + a->src_h_parent);
22970 + err = PTR_ERR(a->src_wh_dentry);
22971 + if (IS_ERR(a->src_wh_dentry))
22975 + /* lookup whiteout for dentry */
22976 + if (au_ftest_ren(a->auren_flags, WHDST)) {
22977 + h_d = au_wh_lkup(a->dst_h_parent,
22978 + &a->dst_dentry->d_name, a->br);
22979 + err = PTR_ERR(h_d);
22982 + if (d_is_negative(h_d))
22985 + a->dst_wh_dentry = h_d;
22988 + /* rename dentry to tmpwh */
22990 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
22991 + if (unlikely(err))
22994 + d = a->dst_dentry;
22995 + au_set_h_dptr(d, a->btgt, NULL);
22996 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
22997 + if (unlikely(err))
22999 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
23003 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
23004 +#if 0 /* debugging */
23005 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
23006 + && d_is_positive(a->dst_h_dentry)
23007 + && a->src_btop != a->btgt);
23010 + /* rename by vfs_rename or cpup */
23011 + err = au_ren_or_cpup(a);
23012 + if (unlikely(err))
23013 + /* leave the copied-up one */
23016 + /* make dir opaque */
23017 + err = au_ren_diropq(a);
23018 + if (unlikely(err))
23021 + /* update target timestamps */
23022 + if (a->exchange) {
23023 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
23024 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
23025 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23026 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23028 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
23029 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
23030 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23031 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23033 + if (!a->exchange) {
23034 + /* remove whiteout for dentry */
23035 + if (a->dst_wh_dentry) {
23036 + a->h_path.dentry = a->dst_wh_dentry;
23037 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
23039 + if (unlikely(err))
23043 + /* remove whtmp */
23045 + au_ren_del_whtmp(a); /* ignore this error */
23047 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
23050 + goto out_success;
23053 + au_ren_rev_diropq(err, a);
23055 + au_ren_rev_rename(err, a);
23059 + au_ren_rev_whtmp(err, a);
23061 + dput(a->dst_wh_dentry);
23062 + a->dst_wh_dentry = NULL;
23064 + if (a->src_wh_dentry)
23065 + au_ren_rev_whsrc(err, a);
23067 + dput(a->src_wh_dentry);
23068 + dput(a->dst_wh_dentry);
23072 + au_whtmp_rmdir_free(a->thargs);
23073 + a->thargs = NULL;
23079 +/* ---------------------------------------------------------------------- */
23082 + * test if @dentry dir can be rename destination or not.
23083 + * success means, it is a logically empty dir.
23085 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
23087 + return au_test_empty(dentry, whlist);
23091 + * test if @a->src_dentry dir can be rename source or not.
23092 + * if it can, return 0.
23094 + * - it is a logically empty dir.
23095 + * - or, it exists on writable branch and has no children including whiteouts
23096 + * on the lower branch unless DIRREN is on.
23098 +static int may_rename_srcdir(struct au_ren_args *a)
23101 + unsigned int rdhash;
23102 + aufs_bindex_t btop, btgt;
23103 + struct dentry *dentry;
23104 + struct super_block *sb;
23105 + struct au_sbinfo *sbinfo;
23107 + dentry = a->src_dentry;
23108 + sb = dentry->d_sb;
23109 + sbinfo = au_sbi(sb);
23110 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
23111 + au_fset_ren(a->auren_flags, DIRREN);
23114 + btop = au_dbtop(dentry);
23115 + if (btop != btgt) {
23116 + struct au_nhash whlist;
23118 + SiMustAnyLock(sb);
23119 + rdhash = sbinfo->si_rdhash;
23121 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23123 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23124 + if (unlikely(err))
23126 + err = au_test_empty(dentry, &whlist);
23127 + au_nhash_wh_free(&whlist);
23131 + if (btop == au_dbtaildir(dentry))
23132 + return 0; /* success */
23134 + err = au_test_empty_lower(dentry);
23137 + if (err == -ENOTEMPTY) {
23138 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23141 + AuWarn1("renaming dir who has child(ren) on multiple "
23142 + "branches, is not supported\n");
23149 +/* side effect: sets whlist and h_dentry */
23150 +static int au_ren_may_dir(struct au_ren_args *a)
23153 + unsigned int rdhash;
23154 + struct dentry *d;
23156 + d = a->dst_dentry;
23157 + SiMustAnyLock(d->d_sb);
23160 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23161 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23163 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23164 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23165 + if (unlikely(err))
23168 + if (!a->exchange) {
23169 + au_set_dbtop(d, a->dst_btop);
23170 + err = may_rename_dstdir(d, &a->whlist);
23171 + au_set_dbtop(d, a->btgt);
23173 + err = may_rename_srcdir(a);
23175 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23176 + if (unlikely(err))
23179 + d = a->src_dentry;
23180 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23181 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23182 + err = may_rename_srcdir(a);
23183 + if (unlikely(err)) {
23184 + au_nhash_wh_free(&a->whlist);
23185 + a->whlist.nh_num = 0;
23192 +/* ---------------------------------------------------------------------- */
23195 + * simple tests for rename.
23196 + * following the checks in vfs, plus the parent-child relationship.
23198 +static int au_may_ren(struct au_ren_args *a)
23201 + struct inode *h_inode;
23203 + if (a->src_btop == a->btgt) {
23204 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23205 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23206 + if (unlikely(err))
23209 + if (unlikely(a->src_h_dentry == a->h_trap))
23214 + if (a->dst_btop != a->btgt)
23217 + err = -ENOTEMPTY;
23218 + if (unlikely(a->dst_h_dentry == a->h_trap))
23222 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23223 + if (d_really_is_negative(a->dst_dentry)) {
23224 + if (d_is_negative(a->dst_h_dentry))
23225 + err = au_may_add(a->dst_dentry, a->btgt,
23226 + a->dst_h_parent, isdir);
23228 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23230 + h_inode = d_inode(a->dst_h_dentry);
23231 + if (h_inode->i_nlink)
23232 + err = au_may_del(a->dst_dentry, a->btgt,
23233 + a->dst_h_parent, isdir);
23237 + if (unlikely(err == -ENOENT || err == -EEXIST))
23243 +/* ---------------------------------------------------------------------- */
23248 + * - src_dir and dir by lock_rename()
23249 + * - inode if exists
23252 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23254 + * + di_write_lock2_child()
23255 + * + di_write_lock_child()
23256 + * + ii_write_lock_child()
23257 + * + di_write_lock_child2()
23258 + * + ii_write_lock_child2()
23259 + * + src_parent and parent
23260 + * + di_write_lock_parent()
23261 + * + ii_write_lock_parent()
23262 + * + di_write_lock_parent2()
23263 + * + ii_write_lock_parent2()
23264 + * + lower src_dir and dir by vfsub_lock_rename()
23265 + * + verify the every relationships between child and parent. if any
23266 + * of them failed, unlock all and return -EBUSY.
23268 +static void au_ren_unlock(struct au_ren_args *a)
23270 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23271 + a->dst_h_parent, a->dst_hdir);
23272 + if (au_ftest_ren(a->auren_flags, DIRREN)
23274 + au_hn_inode_unlock(a->h_root);
23275 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23276 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23279 +static int au_ren_lock(struct au_ren_args *a)
23282 + unsigned int udba;
23285 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23286 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23287 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23288 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23290 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23291 + if (unlikely(err))
23293 + au_fset_ren(a->auren_flags, MNT_WRITE);
23294 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23295 + struct dentry *root;
23296 + struct inode *dir;
23299 + * sbinfo is already locked, so this ii_read_lock is
23300 + * unnecessary. but our debugging feature checks it.
23302 + root = a->src_inode->i_sb->s_root;
23303 + if (root != a->src_parent && root != a->dst_parent) {
23304 + dir = d_inode(root);
23305 + ii_read_lock_parent3(dir);
23306 + a->h_root = au_hi(dir, a->btgt);
23307 + ii_read_unlock(dir);
23308 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23311 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23312 + a->dst_h_parent, a->dst_hdir);
23313 + udba = au_opt_udba(a->src_dentry->d_sb);
23314 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23315 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23316 + err = au_busy_or_stale();
23317 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23318 + err = au_h_verify(a->src_h_dentry, udba,
23319 + d_inode(a->src_h_parent), a->src_h_parent,
23321 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23322 + err = au_h_verify(a->dst_h_dentry, udba,
23323 + d_inode(a->dst_h_parent), a->dst_h_parent,
23326 + goto out; /* success */
23328 + err = au_busy_or_stale();
23329 + au_ren_unlock(a);
23335 +/* ---------------------------------------------------------------------- */
23337 +static void au_ren_refresh_dir(struct au_ren_args *a)
23339 + struct inode *dir;
23341 + dir = a->dst_dir;
23342 + inode_inc_iversion(dir);
23343 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23344 + /* is this updating defined in POSIX? */
23345 + au_cpup_attr_timesizes(a->src_inode);
23346 + au_cpup_attr_nlink(dir, /*force*/1);
23348 + au_dir_ts(dir, a->btgt);
23350 + if (a->exchange) {
23351 + dir = a->src_dir;
23352 + inode_inc_iversion(dir);
23353 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23354 + /* is this updating defined in POSIX? */
23355 + au_cpup_attr_timesizes(a->dst_inode);
23356 + au_cpup_attr_nlink(dir, /*force*/1);
23358 + au_dir_ts(dir, a->btgt);
23361 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23364 + dir = a->src_dir;
23365 + inode_inc_iversion(dir);
23366 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23367 + au_cpup_attr_nlink(dir, /*force*/1);
23368 + au_dir_ts(dir, a->btgt);
23371 +static void au_ren_refresh(struct au_ren_args *a)
23373 + aufs_bindex_t bbot, bindex;
23374 + struct dentry *d, *h_d;
23375 + struct inode *i, *h_i;
23376 + struct super_block *sb;
23378 + d = a->dst_dentry;
23381 + /* already dget-ed by au_ren_or_cpup() */
23382 + au_set_h_dptr(d, a->btgt, a->h_dst);
23384 + i = a->dst_inode;
23386 + if (!a->exchange) {
23387 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23388 + vfsub_drop_nlink(i);
23390 + vfsub_dead_dir(i);
23391 + au_cpup_attr_timesizes(i);
23393 + au_update_dbrange(d, /*do_put_zero*/1);
23395 + au_cpup_attr_nlink(i, /*force*/1);
23398 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23399 + au_set_h_dptr(d, bindex, NULL);
23400 + bbot = au_dbbot(d);
23401 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23402 + au_set_h_dptr(d, bindex, NULL);
23403 + au_update_dbrange(d, /*do_put_zero*/0);
23407 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23408 + d_drop(a->src_dentry);
23409 + if (au_ftest_ren(a->auren_flags, DIRREN))
23410 + au_set_dbwh(a->src_dentry, -1);
23414 + d = a->src_dentry;
23415 + au_set_dbwh(d, -1);
23416 + bbot = au_dbbot(d);
23417 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23418 + h_d = au_h_dptr(d, bindex);
23420 + au_set_h_dptr(d, bindex, NULL);
23422 + au_set_dbbot(d, a->btgt);
23425 + i = a->src_inode;
23426 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23427 + return; /* success */
23429 + bbot = au_ibbot(i);
23430 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23431 + h_i = au_h_iptr(i, bindex);
23433 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23434 + /* ignore this error */
23435 + au_set_h_iptr(i, bindex, NULL, 0);
23438 + au_set_ibbot(i, a->btgt);
23441 +/* ---------------------------------------------------------------------- */
23443 +/* mainly for link(2) and rename(2) */
23444 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23446 + aufs_bindex_t bdiropq, bwh;
23447 + struct dentry *parent;
23448 + struct au_branch *br;
23450 + parent = dentry->d_parent;
23451 + IMustLock(d_inode(parent)); /* dir is locked */
23453 + bdiropq = au_dbdiropq(parent);
23454 + bwh = au_dbwh(dentry);
23455 + br = au_sbr(dentry->d_sb, btgt);
23456 + if (au_br_rdonly(br)
23457 + || (0 <= bdiropq && bdiropq < btgt)
23458 + || (0 <= bwh && bwh < btgt))
23461 + AuDbg("btgt %d\n", btgt);
23465 +/* sets src_btop, dst_btop and btgt */
23466 +static int au_ren_wbr(struct au_ren_args *a)
23469 + struct au_wr_dir_args wr_dir_args = {
23470 + /* .force_btgt = -1, */
23471 + .flags = AuWrDir_ADD_ENTRY
23474 + a->src_btop = au_dbtop(a->src_dentry);
23475 + a->dst_btop = au_dbtop(a->dst_dentry);
23476 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23477 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23478 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23479 + wr_dir_args.force_btgt = a->src_btop;
23480 + if (a->dst_inode && a->dst_btop < a->src_btop)
23481 + wr_dir_args.force_btgt = a->dst_btop;
23482 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23483 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23486 + au_update_dbtop(a->dst_dentry);
23491 +static void au_ren_dt(struct au_ren_args *a)
23493 + a->h_path.dentry = a->src_h_parent;
23494 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23495 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23496 + a->h_path.dentry = a->dst_h_parent;
23497 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23500 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23501 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23505 + a->h_path.dentry = a->src_h_dentry;
23506 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23507 + if (d_is_positive(a->dst_h_dentry)) {
23508 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23509 + a->h_path.dentry = a->dst_h_dentry;
23510 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23514 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23516 + struct dentry *h_d;
23517 + struct inode *h_inode;
23519 + au_dtime_revert(a->src_dt + AuPARENT);
23520 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23521 + au_dtime_revert(a->dst_dt + AuPARENT);
23523 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23524 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23525 + h_inode = d_inode(h_d);
23526 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23527 + au_dtime_revert(a->src_dt + AuCHILD);
23528 + inode_unlock(h_inode);
23530 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23531 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23532 + h_inode = d_inode(h_d);
23533 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23534 + au_dtime_revert(a->dst_dt + AuCHILD);
23535 + inode_unlock(h_inode);
23540 +/* ---------------------------------------------------------------------- */
23542 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23543 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23544 + unsigned int _flags)
23546 + int err, lock_flags;
23548 + /* reduce stack space */
23549 + struct au_ren_args *a;
23550 + struct au_pin pin;
23552 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23553 + IMustLock(_src_dir);
23554 + IMustLock(_dst_dir);
23557 + if (unlikely(_flags & RENAME_WHITEOUT))
23561 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23562 + a = kzalloc(sizeof(*a), GFP_NOFS);
23563 + if (unlikely(!a))
23566 + a->flags = _flags;
23567 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23568 + && RENAME_EXCHANGE > U8_MAX);
23569 + a->exchange = _flags & RENAME_EXCHANGE;
23570 + a->src_dir = _src_dir;
23571 + a->src_dentry = _src_dentry;
23572 + a->src_inode = NULL;
23573 + if (d_really_is_positive(a->src_dentry))
23574 + a->src_inode = d_inode(a->src_dentry);
23575 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23576 + a->dst_dir = _dst_dir;
23577 + a->dst_dentry = _dst_dentry;
23578 + a->dst_inode = NULL;
23579 + if (d_really_is_positive(a->dst_dentry))
23580 + a->dst_inode = d_inode(a->dst_dentry);
23581 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23582 + if (a->dst_inode) {
23584 + * if EXCHANGE && src is non-dir && dst is dir,
23585 + * dst is not locked.
23587 + /* IMustLock(a->dst_inode); */
23588 + au_igrab(a->dst_inode);
23592 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23593 + if (d_is_dir(a->src_dentry)) {
23594 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23595 + if (unlikely(!a->exchange
23596 + && d_really_is_positive(a->dst_dentry)
23597 + && !d_is_dir(a->dst_dentry)))
23599 + lock_flags |= AuLock_DIRS;
23601 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23602 + au_fset_ren(a->auren_flags, ISDIR_DST);
23603 + if (unlikely(!a->exchange
23604 + && d_really_is_positive(a->src_dentry)
23605 + && !d_is_dir(a->src_dentry)))
23607 + lock_flags |= AuLock_DIRS;
23609 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23611 + if (unlikely(err))
23614 + err = au_d_hashed_positive(a->src_dentry);
23615 + if (unlikely(err))
23618 + if (a->dst_inode) {
23620 + * If it is a dir, VFS unhash it before this
23621 + * function. It means we cannot rely upon d_unhashed().
23623 + if (unlikely(!a->dst_inode->i_nlink))
23625 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23626 + err = au_d_hashed_positive(a->dst_dentry);
23627 + if (unlikely(err && !a->exchange))
23629 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23631 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23635 + * is it possible?
23636 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23637 + * there may exist a problem somewhere else.
23640 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23643 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23644 + di_write_lock_parent(a->dst_parent);
23646 + /* which branch we process */
23647 + err = au_ren_wbr(a);
23648 + if (unlikely(err < 0))
23650 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23651 + a->h_path.mnt = au_br_mnt(a->br);
23653 + /* are they available to be renamed */
23654 + err = au_ren_may_dir(a);
23655 + if (unlikely(err))
23656 + goto out_children;
23658 + /* prepare the writable parent dir on the same branch */
23659 + if (a->dst_btop == a->btgt) {
23660 + au_fset_ren(a->auren_flags, WHDST);
23662 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23663 + if (unlikely(err))
23664 + goto out_children;
23668 + if (!a->exchange) {
23669 + if (a->src_dir != a->dst_dir) {
23671 + * this temporary unlock is safe,
23672 + * because both dir->i_mutex are locked.
23674 + di_write_unlock(a->dst_parent);
23675 + di_write_lock_parent(a->src_parent);
23676 + err = au_wr_dir_need_wh(a->src_dentry,
23677 + au_ftest_ren(a->auren_flags,
23680 + di_write_unlock(a->src_parent);
23681 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23683 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23685 + err = au_wr_dir_need_wh(a->src_dentry,
23686 + au_ftest_ren(a->auren_flags,
23690 + if (unlikely(err < 0))
23691 + goto out_children;
23693 + au_fset_ren(a->auren_flags, WHSRC);
23696 + if (a->src_btop != a->btgt) {
23697 + err = au_pin(&pin, a->src_dentry, a->btgt,
23698 + au_opt_udba(a->src_dentry->d_sb),
23699 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23701 + struct au_cp_generic cpg = {
23702 + .dentry = a->src_dentry,
23704 + .bsrc = a->src_btop,
23707 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23709 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23710 + err = au_sio_cpup_simple(&cpg);
23713 + if (unlikely(err))
23714 + goto out_children;
23715 + a->src_btop = a->btgt;
23716 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23717 + if (!a->exchange)
23718 + au_fset_ren(a->auren_flags, WHSRC);
23722 + if (a->exchange && a->dst_inode
23723 + && a->dst_btop != a->btgt) {
23724 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23725 + au_opt_udba(a->dst_dentry->d_sb),
23726 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23728 + struct au_cp_generic cpg = {
23729 + .dentry = a->dst_dentry,
23731 + .bsrc = a->dst_btop,
23734 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23736 + err = au_sio_cpup_simple(&cpg);
23739 + if (unlikely(err))
23740 + goto out_children;
23741 + a->dst_btop = a->btgt;
23742 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23745 + /* lock them all */
23746 + err = au_ren_lock(a);
23747 + if (unlikely(err))
23748 + /* leave the copied-up one */
23749 + goto out_children;
23751 + if (!a->exchange) {
23752 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23753 + err = au_may_ren(a);
23754 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23755 + err = -ENAMETOOLONG;
23756 + if (unlikely(err))
23760 + /* store timestamps to be revertible */
23763 + /* store dirren info */
23764 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23765 + err = au_dr_rename(a->src_dentry, a->btgt,
23766 + &a->dst_dentry->d_name, &rev);
23768 + if (unlikely(err))
23773 + err = do_rename(a);
23774 + if (unlikely(err))
23777 + if (au_ftest_ren(a->auren_flags, DIRREN))
23778 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23780 + /* update dir attributes */
23781 + au_ren_refresh_dir(a);
23783 + /* dput/iput all lower dentries */
23784 + au_ren_refresh(a);
23786 + goto out_hdir; /* success */
23789 + if (au_ftest_ren(a->auren_flags, DIRREN))
23790 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23792 + au_ren_rev_dt(err, a);
23794 + au_ren_unlock(a);
23796 + au_nhash_wh_free(&a->whlist);
23797 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23798 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23799 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23800 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23804 + if (d_unhashed(a->src_dentry))
23805 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23806 + if (d_unhashed(a->dst_dentry))
23807 + au_fset_ren(a->auren_flags, DROPPED_DST);
23808 + if (!a->exchange)
23809 + d_move(a->src_dentry, a->dst_dentry);
23811 + d_exchange(a->src_dentry, a->dst_dentry);
23812 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23813 + d_drop(a->dst_dentry);
23815 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23816 + d_drop(a->src_dentry);
23818 + au_update_dbtop(a->dst_dentry);
23819 + if (!a->dst_inode)
23820 + d_drop(a->dst_dentry);
23822 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23823 + di_write_unlock(a->dst_parent);
23825 + di_write_unlock2(a->src_parent, a->dst_parent);
23827 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23829 + iput(a->dst_inode);
23831 + au_whtmp_rmdir_free(a->thargs);
23837 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23838 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23839 +++ linux/fs/aufs/Kconfig 2019-07-11 15:42:14.458904362 +0200
23841 +# SPDX-License-Identifier: GPL-2.0
23843 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23845 + Aufs is a stackable unification filesystem such as Unionfs,
23846 + which unifies several directories and provides a merged single
23848 + In the early days, aufs was entirely re-designed and
23849 + re-implemented Unionfs Version 1.x series. Introducing many
23850 + original ideas, approaches and improvements, it becomes totally
23851 + different from Unionfs while keeping the basic features.
23855 + prompt "Maximum number of branches"
23856 + default AUFS_BRANCH_MAX_127
23858 + Specifies the maximum number of branches (or member directories)
23859 + in a single aufs. The larger value consumes more system
23860 + resources and has a minor impact to performance.
23861 +config AUFS_BRANCH_MAX_127
23864 + Specifies the maximum number of branches (or member directories)
23865 + in a single aufs. The larger value consumes more system
23866 + resources and has a minor impact to performance.
23867 +config AUFS_BRANCH_MAX_511
23870 + Specifies the maximum number of branches (or member directories)
23871 + in a single aufs. The larger value consumes more system
23872 + resources and has a minor impact to performance.
23873 +config AUFS_BRANCH_MAX_1023
23876 + Specifies the maximum number of branches (or member directories)
23877 + in a single aufs. The larger value consumes more system
23878 + resources and has a minor impact to performance.
23879 +config AUFS_BRANCH_MAX_32767
23882 + Specifies the maximum number of branches (or member directories)
23883 + in a single aufs. The larger value consumes more system
23884 + resources and has a minor impact to performance.
23887 +config AUFS_SBILIST
23889 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23892 + Automatic configuration for internal use.
23893 + When aufs supports Magic SysRq or /proc, enabled automatically.
23895 +config AUFS_HNOTIFY
23896 + bool "Detect direct branch access (bypassing aufs)"
23898 + If you want to modify files on branches directly, eg. bypassing aufs,
23899 + and want aufs to detect the changes of them fully, then enable this
23900 + option and use 'udba=notify' mount option.
23901 + Currently there is only one available configuration, "fsnotify".
23902 + It will have a negative impact to the performance.
23903 + See detail in aufs.5.
23906 + prompt "method" if AUFS_HNOTIFY
23907 + default AUFS_HFSNOTIFY
23908 +config AUFS_HFSNOTIFY
23913 +config AUFS_EXPORT
23914 + bool "NFS-exportable aufs"
23915 + depends on EXPORTFS
23917 + If you want to export your mounted aufs via NFS, then enable this
23918 + option. There are several requirements for this configuration.
23919 + See detail in aufs.5.
23921 +config AUFS_INO_T_64
23923 + depends on AUFS_EXPORT
23924 + depends on 64BIT && !(ALPHA || S390)
23927 + Automatic configuration for internal use.
23928 + /* typedef unsigned long/int __kernel_ino_t */
23929 + /* alpha and s390x are int */
23932 + bool "support for XATTR/EA (including Security Labels)"
23934 + If your branch fs supports XATTR/EA and you want to make them
23935 + available in aufs too, then enable this opsion and specify the
23936 + branch attributes for EA.
23937 + See detail in aufs.5.
23940 + bool "File-based Hierarchical Storage Management"
23942 + Hierarchical Storage Management (or HSM) is a well-known feature
23943 + in the storage world. Aufs provides this feature as file-based.
23944 + with multiple branches.
23945 + These multiple branches are prioritized, ie. the topmost one
23946 + should be the fastest drive and be used heavily.
23949 + bool "Readdir in userspace"
23951 + Aufs has two methods to provide a merged view for a directory,
23952 + by a user-space library and by kernel-space natively. The latter
23953 + is always enabled but sometimes large and slow.
23954 + If you enable this option, install the library in aufs2-util
23955 + package, and set some environment variables for your readdir(3),
23956 + then the work will be handled in user-space which generally
23957 + shows better performance in most cases.
23958 + See detail in aufs.5.
23960 +config AUFS_DIRREN
23961 + bool "Workaround for rename(2)-ing a directory"
23963 + By default, aufs returns EXDEV error in renameing a dir who has
23964 + his child on the lower branch, since it is a bad idea to issue
23965 + rename(2) internally for every lower branch. But user may not
23966 + accept this behaviour. So here is a workaround to allow such
23967 + rename(2) and store some extra infromation on the writable
23968 + branch. Obviously this costs high (and I don't like it).
23969 + To use this feature, you need to enable this configuration AND
23970 + to specify the mount option `dirren.'
23971 + See details in aufs.5 and the design documents.
23974 + bool "Show whiteouts"
23976 + If you want to make the whiteouts in aufs visible, then enable
23977 + this option and specify 'shwh' mount option. Although it may
23978 + sounds like philosophy or something, but in technically it
23979 + simply shows the name of whiteout with keeping its behaviour.
23981 +config AUFS_BR_RAMFS
23982 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
23984 + If you want to use ramfs as an aufs branch fs, then enable this
23985 + option. Generally tmpfs is recommended.
23986 + Aufs prohibited them to be a branch fs by default, because
23987 + initramfs becomes unusable after switch_root or something
23988 + generally. If you sets initramfs as an aufs branch and boot your
23989 + system by switch_root, you will meet a problem easily since the
23990 + files in initramfs may be inaccessible.
23991 + Unless you are going to use ramfs as an aufs branch fs without
23992 + switch_root or something, leave it N.
23994 +config AUFS_BR_FUSE
23995 + bool "Fuse fs as an aufs branch"
23996 + depends on FUSE_FS
23999 + If you want to use fuse-based userspace filesystem as an aufs
24000 + branch fs, then enable this option.
24001 + It implements the internal poll(2) operation which is
24002 + implemented by fuse only (curretnly).
24007 + Automatic configuration for internal use.
24009 +config AUFS_BR_HFSPLUS
24010 + bool "Hfsplus as an aufs branch"
24011 + depends on HFSPLUS_FS
24014 + If you want to use hfsplus fs as an aufs branch fs, then enable
24015 + this option. This option introduces a small overhead at
24016 + copying-up a file on hfsplus.
24018 +config AUFS_BDEV_LOOP
24020 + depends on BLK_DEV_LOOP
24023 + Automatic configuration for internal use.
24024 + Convert =[ym] into =y.
24027 + bool "Debug aufs"
24029 + Enable this to compile aufs internal debug code.
24030 + It will have a negative impact to the performance.
24032 +config AUFS_MAGIC_SYSRQ
24034 + depends on AUFS_DEBUG && MAGIC_SYSRQ
24037 + Automatic configuration for internal use.
24038 + When aufs supports Magic SysRq, enabled automatically.
24040 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
24041 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
24042 +++ linux/fs/aufs/lcnt.h 2020-01-27 10:57:18.175538316 +0100
24044 +/* SPDX-License-Identifier: GPL-2.0 */
24046 + * Copyright (C) 2018-2020 Junjiro R. Okajima
24048 + * This program, aufs is free software; you can redistribute it and/or modify
24049 + * it under the terms of the GNU General Public License as published by
24050 + * the Free Software Foundation; either version 2 of the License, or
24051 + * (at your option) any later version.
24053 + * This program is distributed in the hope that it will be useful,
24054 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24055 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24056 + * GNU General Public License for more details.
24058 + * You should have received a copy of the GNU General Public License
24059 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24063 + * simple long counter wrapper
24066 +#ifndef __AUFS_LCNT_H__
24067 +#define __AUFS_LCNT_H__
24071 +#include "debug.h"
24073 +#define AuLCntATOMIC 1
24074 +#define AuLCntPCPUCNT 2
24076 + * why does percpu_refcount require extra synchronize_rcu()s in
24077 + * au_br_do_free()
24079 +#define AuLCntPCPUREF 3
24081 +/* #define AuLCntChosen AuLCntATOMIC */
24082 +#define AuLCntChosen AuLCntPCPUCNT
24083 +/* #define AuLCntChosen AuLCntPCPUREF */
24085 +#if AuLCntChosen == AuLCntATOMIC
24086 +#include <linux/atomic.h>
24088 +typedef atomic_long_t au_lcnt_t;
24090 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24092 + atomic_long_set(cnt, 0);
24096 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24101 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
24102 + int do_sync __maybe_unused)
24107 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24109 + atomic_long_inc(cnt);
24112 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24114 + atomic_long_dec(cnt);
24117 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24119 + return atomic_long_read(cnt);
24123 +#if AuLCntChosen == AuLCntPCPUCNT
24124 +#include <linux/percpu_counter.h>
24126 +typedef struct percpu_counter au_lcnt_t;
24128 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24130 + return percpu_counter_init(cnt, 0, GFP_NOFS);
24133 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24138 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
24140 + percpu_counter_destroy(cnt);
24143 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24145 + percpu_counter_inc(cnt);
24148 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24150 + percpu_counter_dec(cnt);
24153 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24157 + n = percpu_counter_sum(cnt);
24159 + if (LONG_MAX != LLONG_MAX
24161 + AuWarn1("%s\n", "wrap-around");
24167 +#if AuLCntChosen == AuLCntPCPUREF
24168 +#include <linux/percpu-refcount.h>
24170 +typedef struct percpu_ref au_lcnt_t;
24172 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24175 + release = percpu_ref_exit;
24176 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24179 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24181 + synchronize_rcu();
24184 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24186 + percpu_ref_kill(cnt);
24188 + au_lcnt_wait_for_fin(cnt);
24191 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24193 + percpu_ref_get(cnt);
24196 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24198 + percpu_ref_put(cnt);
24202 + * avoid calling this func as possible.
24204 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24208 + percpu_ref_switch_to_atomic_sync(cnt);
24209 + l = atomic_long_read(&cnt->count);
24211 + percpu_ref_switch_to_percpu(cnt);
24213 + /* percpu_ref is initialized by 1 instead of 0 */
24218 +#ifdef CONFIG_AUFS_DEBUG
24219 +#define AuLCntZero(val) do { \
24222 + AuDbg("%s = %ld\n", #val, l); \
24225 +#define AuLCntZero(val) do {} while (0)
24228 +#endif /* __KERNEL__ */
24229 +#endif /* __AUFS_LCNT_H__ */
24230 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24231 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24232 +++ linux/fs/aufs/loop.c 2020-01-27 10:57:18.175538316 +0100
24234 +// SPDX-License-Identifier: GPL-2.0
24236 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24238 + * This program, aufs is free software; you can redistribute it and/or modify
24239 + * it under the terms of the GNU General Public License as published by
24240 + * the Free Software Foundation; either version 2 of the License, or
24241 + * (at your option) any later version.
24243 + * This program is distributed in the hope that it will be useful,
24244 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24245 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24246 + * GNU General Public License for more details.
24248 + * You should have received a copy of the GNU General Public License
24249 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24253 + * support for loopback block device as a branch
24258 +/* added into drivers/block/loop.c */
24259 +static struct file *(*backing_file_func)(struct super_block *sb);
24262 + * test if two lower dentries have overlapping branches.
24264 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24266 + struct super_block *h_sb;
24267 + struct file *backing_file;
24269 + if (unlikely(!backing_file_func)) {
24270 + /* don't load "loop" module here */
24271 + backing_file_func = symbol_get(loop_backing_file);
24272 + if (unlikely(!backing_file_func))
24273 + /* "loop" module is not loaded */
24277 + h_sb = h_adding->d_sb;
24278 + backing_file = backing_file_func(h_sb);
24279 + if (!backing_file)
24282 + h_adding = backing_file->f_path.dentry;
24284 + * h_adding can be local NFS.
24285 + * in this case aufs cannot detect the loop.
24287 + if (unlikely(h_adding->d_sb == sb))
24289 + return !!au_test_subdir(h_adding, sb->s_root);
24292 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24293 +int au_test_loopback_kthread(void)
24296 + struct task_struct *tsk = current;
24297 + char c, comm[sizeof(tsk->comm)];
24300 + if (tsk->flags & PF_KTHREAD) {
24301 + get_task_comm(comm, tsk);
24303 + ret = ('0' <= c && c <= '9'
24304 + && !strncmp(comm, "loop", 4));
24310 +/* ---------------------------------------------------------------------- */
24312 +#define au_warn_loopback_step 16
24313 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24314 +static unsigned long *au_warn_loopback_array;
24316 +void au_warn_loopback(struct super_block *h_sb)
24318 + int i, new_nelem;
24319 + unsigned long *a, magic;
24320 + static DEFINE_SPINLOCK(spin);
24322 + magic = h_sb->s_magic;
24323 + spin_lock(&spin);
24324 + a = au_warn_loopback_array;
24325 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24326 + if (a[i] == magic) {
24327 + spin_unlock(&spin);
24331 + /* h_sb is new to us, print it */
24332 + if (i < au_warn_loopback_nelem) {
24337 + /* expand the array */
24338 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24339 + a = au_kzrealloc(au_warn_loopback_array,
24340 + au_warn_loopback_nelem * sizeof(unsigned long),
24341 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24342 + /*may_shrink*/0);
24344 + au_warn_loopback_nelem = new_nelem;
24345 + au_warn_loopback_array = a;
24350 + spin_unlock(&spin);
24351 + AuWarn1("realloc failed, ignored\n");
24355 + spin_unlock(&spin);
24356 + pr_warn("you may want to try another patch for loopback file "
24357 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24360 +int au_loopback_init(void)
24363 + struct super_block *sb __maybe_unused;
24365 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
24368 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24369 + sizeof(unsigned long), GFP_NOFS);
24370 + if (unlikely(!au_warn_loopback_array))
24376 +void au_loopback_fin(void)
24378 + if (backing_file_func)
24379 + symbol_put(loop_backing_file);
24380 + au_kfree_try_rcu(au_warn_loopback_array);
24382 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24383 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24384 +++ linux/fs/aufs/loop.h 2020-01-27 10:57:18.175538316 +0100
24386 +/* SPDX-License-Identifier: GPL-2.0 */
24388 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24390 + * This program, aufs is free software; you can redistribute it and/or modify
24391 + * it under the terms of the GNU General Public License as published by
24392 + * the Free Software Foundation; either version 2 of the License, or
24393 + * (at your option) any later version.
24395 + * This program is distributed in the hope that it will be useful,
24396 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24397 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24398 + * GNU General Public License for more details.
24400 + * You should have received a copy of the GNU General Public License
24401 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24405 + * support for loopback mount as a branch
24408 +#ifndef __AUFS_LOOP_H__
24409 +#define __AUFS_LOOP_H__
24414 +struct super_block;
24416 +#ifdef CONFIG_AUFS_BDEV_LOOP
24417 +/* drivers/block/loop.c */
24418 +struct file *loop_backing_file(struct super_block *sb);
24421 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24422 +int au_test_loopback_kthread(void);
24423 +void au_warn_loopback(struct super_block *h_sb);
24425 +int au_loopback_init(void);
24426 +void au_loopback_fin(void);
24428 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
24430 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24431 + struct dentry *h_adding)
24432 +AuStubInt0(au_test_loopback_kthread, void)
24433 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24435 +AuStubInt0(au_loopback_init, void)
24436 +AuStubVoid(au_loopback_fin, void)
24437 +#endif /* BLK_DEV_LOOP */
24439 +#endif /* __KERNEL__ */
24440 +#endif /* __AUFS_LOOP_H__ */
24441 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24442 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24443 +++ linux/fs/aufs/magic.mk 2019-07-11 15:42:14.468904634 +0200
24445 +# SPDX-License-Identifier: GPL-2.0
24447 +# defined in ${srctree}/fs/fuse/inode.c
24449 +ifdef CONFIG_FUSE_FS
24450 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24453 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24455 +ifdef CONFIG_XFS_FS
24456 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24459 +# defined in ${srctree}/fs/configfs/mount.c
24461 +ifdef CONFIG_CONFIGFS_FS
24462 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24465 +# defined in ${srctree}/fs/ubifs/ubifs.h
24467 +ifdef CONFIG_UBIFS_FS
24468 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24471 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24473 +ifdef CONFIG_HFSPLUS_FS
24474 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24476 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24477 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24478 +++ linux/fs/aufs/Makefile 2019-07-11 15:42:14.462237786 +0200
24480 +# SPDX-License-Identifier: GPL-2.0
24482 +include ${src}/magic.mk
24483 +ifeq (${CONFIG_AUFS_FS},m)
24484 +include ${src}/conf.mk
24486 +-include ${src}/priv_def.mk
24488 +# cf. include/linux/kernel.h
24490 +ccflags-y += -DDEBUG
24491 +# sparse requires the full pathname
24493 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24495 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24498 +obj-$(CONFIG_AUFS_FS) += aufs.o
24499 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24500 + wkq.o vfsub.o dcsub.o \
24501 + cpup.o whout.o wbr_policy.o \
24502 + dinfo.o dentry.o \
24504 + finfo.o file.o f_op.o \
24506 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24510 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24511 +aufs-$(CONFIG_SYSFS) += sysfs.o
24512 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24513 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24514 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24515 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24516 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24517 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24518 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24519 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24520 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24521 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24522 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24523 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24524 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24525 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24526 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24527 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24528 +++ linux/fs/aufs/module.c 2020-01-27 10:57:18.175538316 +0100
24530 +// SPDX-License-Identifier: GPL-2.0
24532 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24534 + * This program, aufs is free software; you can redistribute it and/or modify
24535 + * it under the terms of the GNU General Public License as published by
24536 + * the Free Software Foundation; either version 2 of the License, or
24537 + * (at your option) any later version.
24539 + * This program is distributed in the hope that it will be useful,
24540 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24541 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24542 + * GNU General Public License for more details.
24544 + * You should have received a copy of the GNU General Public License
24545 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24549 + * module global variables and operations
24552 +#include <linux/module.h>
24553 +#include <linux/seq_file.h>
24556 +/* shrinkable realloc */
24557 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24565 +#if 0 /* unused */
24572 + AuDebugOn(!new_sz);
24575 + diff = au_kmidx_sub(sz, new_sz);
24581 + /* expand or SLOB */
24582 + p = krealloc(p, new_sz, gfp);
24583 + else if (new_sz < sz && may_shrink) {
24587 + q = kmalloc(new_sz, gfp);
24590 + memcpy(q, p, new_sz);
24591 + au_kfree_try_rcu(p);
24602 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24605 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24606 + if (p && new_sz > nused)
24607 + memset(p + nused, 0, new_sz - nused);
24611 +/* ---------------------------------------------------------------------- */
24615 +struct kmem_cache *au_cache[AuCache_Last];
24617 +static void au_cache_fin(void)
24622 + * Make sure all delayed rcu free inodes are flushed before we
24627 + /* excluding AuCache_HNOTIFY */
24628 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24629 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24630 + kmem_cache_destroy(au_cache[i]);
24631 + au_cache[i] = NULL;
24635 +static int __init au_cache_init(void)
24637 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24638 + if (au_cache[AuCache_DINFO])
24639 + /* SLAB_DESTROY_BY_RCU */
24640 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24641 + au_icntnr_init_once);
24642 + if (au_cache[AuCache_ICNTNR])
24643 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24644 + au_fi_init_once);
24645 + if (au_cache[AuCache_FINFO])
24646 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24647 + if (au_cache[AuCache_VDIR])
24648 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24649 + if (au_cache[AuCache_DEHSTR])
24656 +/* ---------------------------------------------------------------------- */
24658 +int au_dir_roflags;
24660 +#ifdef CONFIG_AUFS_SBILIST
24662 + * iterate_supers_type() doesn't protect us from
24663 + * remounting (branch management)
24665 +struct hlist_bl_head au_sbilist;
24669 + * functions for module interface.
24671 +MODULE_LICENSE("GPL");
24672 +/* MODULE_LICENSE("GPL v2"); */
24673 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24674 +MODULE_DESCRIPTION(AUFS_NAME
24675 + " -- Advanced multi layered unification filesystem");
24676 +MODULE_VERSION(AUFS_VERSION);
24677 +MODULE_ALIAS_FS(AUFS_NAME);
24679 +/* this module parameter has no meaning when SYSFS is disabled */
24680 +int sysaufs_brs = 1;
24681 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24682 +module_param_named(brs, sysaufs_brs, int, 0444);
24684 +/* this module parameter has no meaning when USER_NS is disabled */
24686 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24687 +module_param_named(allow_userns, au_userns, bool, 0444);
24689 +/* ---------------------------------------------------------------------- */
24691 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24693 +int au_seq_path(struct seq_file *seq, struct path *path)
24697 + err = seq_path(seq, path, au_esc_chars);
24706 +/* ---------------------------------------------------------------------- */
24708 +static int __init aufs_init(void)
24713 + p = au_esc_chars;
24714 + for (i = 1; i <= ' '; i++)
24720 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24722 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24723 + for (i = 0; i < AuIop_Last; i++)
24724 + aufs_iop_nogetattr[i].getattr = NULL;
24726 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24728 + au_sbilist_init();
24729 + sysaufs_brs_init();
24732 + err = sysaufs_init();
24733 + if (unlikely(err))
24735 + err = dbgaufs_init();
24736 + if (unlikely(err))
24737 + goto out_sysaufs;
24738 + err = au_procfs_init();
24739 + if (unlikely(err))
24740 + goto out_dbgaufs;
24741 + err = au_wkq_init();
24742 + if (unlikely(err))
24744 + err = au_loopback_init();
24745 + if (unlikely(err))
24747 + err = au_hnotify_init();
24748 + if (unlikely(err))
24749 + goto out_loopback;
24750 + err = au_sysrq_init();
24751 + if (unlikely(err))
24753 + err = au_cache_init();
24754 + if (unlikely(err))
24757 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24758 + err = register_filesystem(&aufs_fs_type);
24759 + if (unlikely(err))
24762 + /* since we define pr_fmt, call printk directly */
24763 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24764 + goto out; /* success */
24771 + au_hnotify_fin();
24773 + au_loopback_fin();
24787 +static void __exit aufs_exit(void)
24789 + unregister_filesystem(&aufs_fs_type);
24792 + au_hnotify_fin();
24793 + au_loopback_fin();
24801 +module_init(aufs_init);
24802 +module_exit(aufs_exit);
24803 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24804 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24805 +++ linux/fs/aufs/module.h 2020-01-27 10:57:18.175538316 +0100
24807 +/* SPDX-License-Identifier: GPL-2.0 */
24809 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24811 + * This program, aufs is free software; you can redistribute it and/or modify
24812 + * it under the terms of the GNU General Public License as published by
24813 + * the Free Software Foundation; either version 2 of the License, or
24814 + * (at your option) any later version.
24816 + * This program is distributed in the hope that it will be useful,
24817 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24818 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24819 + * GNU General Public License for more details.
24821 + * You should have received a copy of the GNU General Public License
24822 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24826 + * module initialization and module-global
24829 +#ifndef __AUFS_MODULE_H__
24830 +#define __AUFS_MODULE_H__
24834 +#include <linux/slab.h>
24835 +#include "debug.h"
24836 +#include "dentry.h"
24839 +#include "inode.h"
24844 +/* module parameters */
24845 +extern int sysaufs_brs;
24846 +extern bool au_userns;
24848 +/* ---------------------------------------------------------------------- */
24850 +extern int au_dir_roflags;
24852 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24853 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24857 + * Comparing the size of the object with sizeof(struct rcu_head)
24858 + * case 1: object is always larger
24859 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24860 + * case 2: object is always smaller
24861 + * --> au_kfree_small()
24862 + * case 3: object can be any size
24863 + * --> au_kfree_try_rcu()
24866 +static inline void au_kfree_do_rcu(const void *p)
24869 + struct rcu_head rcu;
24870 + } *a = (void *)p;
24872 + kfree_rcu(a, rcu);
24875 +#define au_kfree_rcu(_p) do { \
24876 + typeof(_p) p = (_p); \
24877 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24879 + au_kfree_do_rcu(p); \
24882 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
24883 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
24885 +static inline void au_kfree_try_rcu(const void *p)
24889 + if (au_kfree_sz_test(p))
24890 + au_kfree_do_rcu(p);
24895 +static inline void au_kfree_small(const void *p)
24899 + AuDebugOn(au_kfree_sz_test(p));
24903 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24905 +#ifndef CONFIG_SLOB
24906 + return kmalloc_index(sz) - kmalloc_index(new_sz);
24908 + return -1; /* SLOB is untested */
24912 +int au_seq_path(struct seq_file *seq, struct path *path);
24914 +#ifdef CONFIG_PROC_FS
24916 +int __init au_procfs_init(void);
24917 +void au_procfs_fin(void);
24919 +AuStubInt0(au_procfs_init, void);
24920 +AuStubVoid(au_procfs_fin, void);
24923 +/* ---------------------------------------------------------------------- */
24932 + AuCache_HNOTIFY, /* must be last */
24936 +extern struct kmem_cache *au_cache[AuCache_Last];
24938 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24939 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24940 +#define AuCacheCtor(type, ctor) \
24941 + kmem_cache_create(#type, sizeof(struct type), \
24942 + __alignof__(struct type), AuCacheFlags, ctor)
24944 +#define AuCacheFuncs(name, index) \
24945 + static inline struct au_##name *au_cache_alloc_##name(void) \
24946 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24947 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
24948 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
24950 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
24951 + { void *p = rcu; \
24952 + p -= offsetof(struct au_##name, rcu); \
24953 + kmem_cache_free(au_cache[AuCache_##index], p); } \
24954 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
24955 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
24956 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
24958 + static inline void au_cache_free_##name(struct au_##name *p) \
24959 + { /* au_cache_free_##name##_norcu(p); */ \
24960 + au_cache_free_##name##_rcu(p); }
24962 +AuCacheFuncs(dinfo, DINFO);
24963 +AuCacheFuncs(icntnr, ICNTNR);
24964 +AuCacheFuncs(finfo, FINFO);
24965 +AuCacheFuncs(vdir, VDIR);
24966 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24967 +#ifdef CONFIG_AUFS_HNOTIFY
24968 +AuCacheFuncs(hnotify, HNOTIFY);
24971 +#endif /* __KERNEL__ */
24972 +#endif /* __AUFS_MODULE_H__ */
24973 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24974 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24975 +++ linux/fs/aufs/mvdown.c 2020-01-27 10:57:18.175538316 +0100
24977 +// SPDX-License-Identifier: GPL-2.0
24979 + * Copyright (C) 2011-2020 Junjiro R. Okajima
24981 + * This program, aufs is free software; you can redistribute it and/or modify
24982 + * it under the terms of the GNU General Public License as published by
24983 + * the Free Software Foundation; either version 2 of the License, or
24984 + * (at your option) any later version.
24986 + * This program is distributed in the hope that it will be useful,
24987 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24988 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24989 + * GNU General Public License for more details.
24991 + * You should have received a copy of the GNU General Public License
24992 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24996 + * move-down, opposite of copy-up
25001 +struct au_mvd_args {
25003 + struct super_block *h_sb;
25004 + struct dentry *h_parent;
25005 + struct au_hinode *hdir;
25006 + struct inode *h_dir, *h_inode;
25007 + struct au_pin pin;
25008 + } info[AUFS_MVDOWN_NARRAY];
25010 + struct aufs_mvdown mvdown;
25011 + struct dentry *dentry, *parent;
25012 + struct inode *inode, *dir;
25013 + struct super_block *sb;
25014 + aufs_bindex_t bopq, bwh, bfound;
25015 + unsigned char rename_lock;
25018 +#define mvd_errno mvdown.au_errno
25019 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
25020 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
25021 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
25022 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
25024 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
25025 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
25026 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
25027 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
25028 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
25029 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
25031 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
25032 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
25033 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
25034 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
25035 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
25036 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
25038 +#define AU_MVD_PR(flag, ...) do { \
25040 + pr_err(__VA_ARGS__); \
25043 +static int find_lower_writable(struct au_mvd_args *a)
25045 + struct super_block *sb;
25046 + aufs_bindex_t bindex, bbot;
25047 + struct au_branch *br;
25050 + bindex = a->mvd_bsrc;
25051 + bbot = au_sbbot(sb);
25052 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
25053 + for (bindex++; bindex <= bbot; bindex++) {
25054 + br = au_sbr(sb, bindex);
25055 + if (au_br_fhsm(br->br_perm)
25056 + && !sb_rdonly(au_br_sb(br)))
25059 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
25060 + for (bindex++; bindex <= bbot; bindex++) {
25061 + br = au_sbr(sb, bindex);
25062 + if (!au_br_rdonly(br))
25066 + for (bindex++; bindex <= bbot; bindex++) {
25067 + br = au_sbr(sb, bindex);
25068 + if (!sb_rdonly(au_br_sb(br))) {
25069 + if (au_br_rdonly(br))
25071 + |= AUFS_MVDOWN_ROLOWER_R;
25079 +/* make the parent dir on bdst */
25080 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
25085 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
25086 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
25087 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
25088 + a->mvd_h_dst_parent = NULL;
25089 + if (au_dbbot(a->parent) >= a->mvd_bdst)
25090 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25091 + if (!a->mvd_h_dst_parent) {
25092 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
25093 + if (unlikely(err)) {
25094 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
25097 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25105 +/* lock them all */
25106 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
25109 + struct dentry *h_trap;
25111 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
25112 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
25113 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
25114 + au_opt_udba(a->sb),
25115 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25117 + if (unlikely(err)) {
25118 + AU_MVD_PR(dmsg, "pin_dst failed\n");
25122 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
25123 + a->rename_lock = 0;
25124 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25125 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
25126 + au_opt_udba(a->sb),
25127 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25128 + err = au_do_pin(&a->mvd_pin_src);
25130 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25131 + if (unlikely(err)) {
25132 + AU_MVD_PR(dmsg, "pin_src failed\n");
25135 + goto out; /* success */
25138 + a->rename_lock = 1;
25139 + au_pin_hdir_unlock(&a->mvd_pin_dst);
25140 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25141 + au_opt_udba(a->sb),
25142 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25144 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25145 + if (unlikely(err)) {
25146 + AU_MVD_PR(dmsg, "pin_src failed\n");
25147 + au_pin_hdir_lock(&a->mvd_pin_dst);
25150 + au_pin_hdir_unlock(&a->mvd_pin_src);
25151 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25152 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25154 + err = (h_trap != a->mvd_h_src_parent);
25156 + err = (h_trap != a->mvd_h_dst_parent);
25158 + BUG_ON(err); /* it should never happen */
25159 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25162 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25163 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25164 + au_pin_hdir_lock(&a->mvd_pin_src);
25165 + au_unpin(&a->mvd_pin_src);
25166 + au_pin_hdir_lock(&a->mvd_pin_dst);
25169 + goto out; /* success */
25172 + au_unpin(&a->mvd_pin_dst);
25178 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25180 + if (!a->rename_lock)
25181 + au_unpin(&a->mvd_pin_src);
25183 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25184 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25185 + au_pin_hdir_lock(&a->mvd_pin_src);
25186 + au_unpin(&a->mvd_pin_src);
25187 + au_pin_hdir_lock(&a->mvd_pin_dst);
25189 + au_unpin(&a->mvd_pin_dst);
25192 +/* copy-down the file */
25193 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25196 + struct au_cp_generic cpg = {
25197 + .dentry = a->dentry,
25198 + .bdst = a->mvd_bdst,
25199 + .bsrc = a->mvd_bsrc,
25201 + .pin = &a->mvd_pin_dst,
25202 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25205 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25206 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25207 + au_fset_cpup(cpg.flags, OVERWRITE);
25208 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25209 + au_fset_cpup(cpg.flags, RWDST);
25210 + err = au_sio_cpdown_simple(&cpg);
25211 + if (unlikely(err))
25212 + AU_MVD_PR(dmsg, "cpdown failed\n");
25219 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25222 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25225 + struct path h_path;
25226 + struct au_branch *br;
25227 + struct inode *delegated;
25229 + br = au_sbr(a->sb, a->mvd_bdst);
25230 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25231 + err = PTR_ERR(h_path.dentry);
25232 + if (IS_ERR(h_path.dentry)) {
25233 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25238 + if (d_is_positive(h_path.dentry)) {
25239 + h_path.mnt = au_br_mnt(br);
25240 + delegated = NULL;
25241 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25242 + &delegated, /*force*/0);
25243 + if (unlikely(err == -EWOULDBLOCK)) {
25244 + pr_warn("cannot retry for NFSv4 delegation"
25245 + " for an internal unlink\n");
25248 + if (unlikely(err))
25249 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25251 + dput(h_path.dentry);
25259 + * unlink the topmost h_dentry
25261 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25264 + struct path h_path;
25265 + struct inode *delegated;
25267 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25268 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25269 + delegated = NULL;
25270 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25271 + if (unlikely(err == -EWOULDBLOCK)) {
25272 + pr_warn("cannot retry for NFSv4 delegation"
25273 + " for an internal unlink\n");
25276 + if (unlikely(err))
25277 + AU_MVD_PR(dmsg, "unlink failed\n");
25283 +/* Since mvdown succeeded, we ignore an error of this function */
25284 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25287 + struct au_branch *br;
25289 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25290 + br = au_sbr(a->sb, a->mvd_bsrc);
25291 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25293 + br = au_sbr(a->sb, a->mvd_bdst);
25294 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25295 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25298 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25300 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25304 + * copy-down the file and unlink the bsrc file.
25305 + * - unlink the bdst whout if exist
25306 + * - copy-down the file (with whtmp name and rename)
25307 + * - unlink the bsrc file
25309 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25313 + err = au_do_mkdir(dmsg, a);
25315 + err = au_do_lock(dmsg, a);
25316 + if (unlikely(err))
25320 + * do not revert the activities we made on bdst since they should be
25321 + * harmless in aufs.
25324 + err = au_do_cpdown(dmsg, a);
25326 + err = au_do_unlink_wh(dmsg, a);
25327 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25328 + err = au_do_unlink(dmsg, a);
25329 + if (unlikely(err))
25332 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25333 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25334 + if (find_lower_writable(a) < 0)
25335 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25337 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25338 + au_do_stfs(dmsg, a);
25340 + /* maintain internal array */
25341 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25342 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25343 + au_set_dbtop(a->dentry, a->mvd_bdst);
25344 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25345 + au_set_ibtop(a->inode, a->mvd_bdst);
25347 + /* hide the lower */
25348 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25349 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25350 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25351 + au_set_ibbot(a->inode, a->mvd_bsrc);
25353 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25354 + au_set_dbbot(a->dentry, a->mvd_bdst);
25355 + if (au_ibbot(a->inode) < a->mvd_bdst)
25356 + au_set_ibbot(a->inode, a->mvd_bdst);
25359 + au_do_unlock(dmsg, a);
25365 +/* ---------------------------------------------------------------------- */
25367 +/* make sure the file is idle */
25368 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25370 + int err, plinked;
25373 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25374 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25375 + && au_dcount(a->dentry) == 1
25376 + && atomic_read(&a->inode->i_count) == 1
25377 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25378 + && (!plinked || !au_plink_test(a->inode))
25379 + && a->inode->i_nlink == 1)
25384 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25385 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25386 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25387 + a->mvd_h_src_inode->i_nlink,
25388 + plinked, plinked ? au_plink_test(a->inode) : 0);
25395 +/* make sure the parent dir is fine */
25396 +static int au_mvd_args_parent(const unsigned char dmsg,
25397 + struct au_mvd_args *a)
25400 + aufs_bindex_t bindex;
25403 + if (unlikely(au_alive_dir(a->parent))) {
25405 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25409 + a->bopq = au_dbdiropq(a->parent);
25410 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25411 + AuDbg("b%d\n", bindex);
25412 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25413 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25415 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25416 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25417 + a->bopq, a->mvd_bdst);
25425 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25426 + struct au_mvd_args *a)
25429 + struct au_dinfo *dinfo, *tmp;
25431 + /* lookup the next lower positive entry */
25433 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25434 + if (unlikely(!tmp))
25439 + dinfo = au_di(a->dentry);
25440 + au_di_cp(tmp, dinfo);
25441 + au_di_swap(tmp, dinfo);
25443 + /* returns the number of positive dentries */
25444 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25445 + /* AuLkup_IGNORE_PERM */ 0);
25447 + a->bwh = au_dbwh(a->dentry);
25448 + else if (err > 0)
25449 + a->bfound = au_dbtop(a->dentry);
25451 + au_di_swap(tmp, dinfo);
25452 + au_rw_write_unlock(&tmp->di_rwsem);
25454 + if (unlikely(err < 0))
25455 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25458 + * here, we have these cases.
25460 + * no positive dentry under bsrc. there are more sub-cases.
25462 + * there no whiteout, we can safely move-down.
25465 + * bsrc < bwh && bwh < bdst
25466 + * there is a whiteout on RO branch. cannot proceed.
25468 + * there is a whiteout on the RW target branch. it should
25471 + * there is a whiteout somewhere unrelated branch.
25472 + * -1 < bfound && bfound <= bsrc
25475 + * found, but it is on RO branch between bsrc and bdst. cannot
25478 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25481 + * found, after we create the file on bdst, it will be hidden.
25484 + AuDebugOn(a->bfound == -1
25486 + && a->bwh <= a->mvd_bsrc);
25487 + AuDebugOn(-1 < a->bfound
25488 + && a->bfound <= a->mvd_bsrc);
25491 + if (a->bfound == -1
25492 + && a->mvd_bsrc < a->bwh
25494 + && a->bwh < a->mvd_bdst) {
25495 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25496 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25497 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25499 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25500 + a->mvd_errno = EAU_MVDOWN_UPPER;
25501 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25502 + a->mvd_bdst, a->bfound);
25506 + err = 0; /* success */
25513 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25518 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25519 + && a->bfound == a->mvd_bdst)
25525 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25528 + struct au_branch *br;
25531 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25535 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25536 + a->mvd_bsrc = au_ibtop(a->inode);
25538 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25539 + if (unlikely(a->mvd_bsrc < 0
25540 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25541 + || au_dbbot(a->dentry) < a->mvd_bsrc
25542 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25543 + || (a->mvd_bsrc < au_ibtop(a->inode)
25544 + || au_ibbot(a->inode) < a->mvd_bsrc
25545 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25546 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25547 + AU_MVD_PR(dmsg, "no upper\n");
25551 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25552 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25553 + AU_MVD_PR(dmsg, "on the bottom\n");
25556 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25557 + br = au_sbr(a->sb, a->mvd_bsrc);
25558 + err = au_br_rdonly(br);
25559 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25560 + if (unlikely(err))
25562 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25563 + || IS_APPEND(a->mvd_h_src_inode))) {
25565 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25571 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25572 + a->mvd_bdst = find_lower_writable(a);
25573 + if (unlikely(a->mvd_bdst < 0)) {
25574 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25575 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25579 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25580 + if (unlikely(a->mvd_bdst < 0
25581 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25582 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25583 + AU_MVD_PR(dmsg, "no lower brid\n");
25588 + err = au_mvd_args_busy(dmsg, a);
25590 + err = au_mvd_args_parent(dmsg, a);
25592 + err = au_mvd_args_intermediate(dmsg, a);
25594 + err = au_mvd_args_exist(dmsg, a);
25596 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25603 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25606 + unsigned char dmsg;
25607 + struct au_mvd_args *args;
25608 + struct inode *inode;
25610 + inode = d_inode(dentry);
25612 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25616 + args = kmalloc(sizeof(*args), GFP_NOFS);
25617 + if (unlikely(!args))
25620 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25622 + /* VERIFY_WRITE */
25623 + err = !access_ok(uarg, sizeof(*uarg));
25624 + if (unlikely(err)) {
25629 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25630 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25631 + args->mvdown.au_errno = 0;
25632 + args->dentry = dentry;
25633 + args->inode = inode;
25634 + args->sb = dentry->d_sb;
25637 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25638 + args->parent = dget_parent(dentry);
25639 + args->dir = d_inode(args->parent);
25640 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25641 + dput(args->parent);
25642 + if (unlikely(args->parent != dentry->d_parent)) {
25643 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25647 + inode_lock_nested(inode, I_MUTEX_CHILD);
25648 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25649 + if (unlikely(err))
25652 + di_write_lock_parent(args->parent);
25653 + err = au_mvd_args(dmsg, args);
25654 + if (unlikely(err))
25657 + err = au_do_mvdown(dmsg, args);
25658 + if (unlikely(err))
25661 + au_cpup_attr_timesizes(args->dir);
25662 + au_cpup_attr_timesizes(inode);
25663 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25664 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25665 + /* au_digen_dec(dentry); */
25668 + di_write_unlock(args->parent);
25669 + aufs_read_unlock(dentry, AuLock_DW);
25671 + inode_unlock(inode);
25673 + inode_unlock(args->dir);
25675 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25678 + au_kfree_rcu(args);
25683 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25684 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25685 +++ linux/fs/aufs/opts.c 2020-01-27 10:57:18.175538316 +0100
25687 +// SPDX-License-Identifier: GPL-2.0
25689 + * Copyright (C) 2005-2020 Junjiro R. Okajima
25691 + * This program, aufs is free software; you can redistribute it and/or modify
25692 + * it under the terms of the GNU General Public License as published by
25693 + * the Free Software Foundation; either version 2 of the License, or
25694 + * (at your option) any later version.
25696 + * This program is distributed in the hope that it will be useful,
25697 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25698 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25699 + * GNU General Public License for more details.
25701 + * You should have received a copy of the GNU General Public License
25702 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25706 + * mount options/flags
25709 +#include <linux/namei.h>
25710 +#include <linux/types.h> /* a distribution requires */
25711 +#include <linux/parser.h>
25714 +/* ---------------------------------------------------------------------- */
25718 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25719 + Opt_idel, Opt_imod,
25720 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25721 + Opt_rdblk_def, Opt_rdhash_def,
25722 + Opt_xino, Opt_noxino,
25723 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25724 + Opt_trunc_xino_path, Opt_itrunc_xino,
25725 + Opt_trunc_xib, Opt_notrunc_xib,
25726 + Opt_shwh, Opt_noshwh,
25727 + Opt_plink, Opt_noplink, Opt_list_plink,
25729 + Opt_dio, Opt_nodio,
25730 + Opt_diropq_a, Opt_diropq_w,
25731 + Opt_warn_perm, Opt_nowarn_perm,
25732 + Opt_wbr_copyup, Opt_wbr_create,
25734 + Opt_verbose, Opt_noverbose,
25735 + Opt_sum, Opt_nosum, Opt_wsum,
25736 + Opt_dirperm1, Opt_nodirperm1,
25737 + Opt_dirren, Opt_nodirren,
25738 + Opt_acl, Opt_noacl,
25739 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25742 +static match_table_t options = {
25743 + {Opt_br, "br=%s"},
25744 + {Opt_br, "br:%s"},
25746 + {Opt_add, "add=%d:%s"},
25747 + {Opt_add, "add:%d:%s"},
25748 + {Opt_add, "ins=%d:%s"},
25749 + {Opt_add, "ins:%d:%s"},
25750 + {Opt_append, "append=%s"},
25751 + {Opt_append, "append:%s"},
25752 + {Opt_prepend, "prepend=%s"},
25753 + {Opt_prepend, "prepend:%s"},
25755 + {Opt_del, "del=%s"},
25756 + {Opt_del, "del:%s"},
25757 + /* {Opt_idel, "idel:%d"}, */
25758 + {Opt_mod, "mod=%s"},
25759 + {Opt_mod, "mod:%s"},
25760 + /* {Opt_imod, "imod:%d:%s"}, */
25762 + {Opt_dirwh, "dirwh=%d"},
25764 + {Opt_xino, "xino=%s"},
25765 + {Opt_noxino, "noxino"},
25766 + {Opt_trunc_xino, "trunc_xino"},
25767 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25768 + {Opt_notrunc_xino, "notrunc_xino"},
25769 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25770 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25771 + /* {Opt_zxino, "zxino=%s"}, */
25772 + {Opt_trunc_xib, "trunc_xib"},
25773 + {Opt_notrunc_xib, "notrunc_xib"},
25775 +#ifdef CONFIG_PROC_FS
25776 + {Opt_plink, "plink"},
25778 + {Opt_ignore_silent, "plink"},
25781 + {Opt_noplink, "noplink"},
25783 +#ifdef CONFIG_AUFS_DEBUG
25784 + {Opt_list_plink, "list_plink"},
25787 + {Opt_udba, "udba=%s"},
25789 + {Opt_dio, "dio"},
25790 + {Opt_nodio, "nodio"},
25792 +#ifdef CONFIG_AUFS_DIRREN
25793 + {Opt_dirren, "dirren"},
25794 + {Opt_nodirren, "nodirren"},
25796 + {Opt_ignore, "dirren"},
25797 + {Opt_ignore_silent, "nodirren"},
25800 +#ifdef CONFIG_AUFS_FHSM
25801 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25803 + {Opt_ignore, "fhsm_sec=%d"},
25806 + {Opt_diropq_a, "diropq=always"},
25807 + {Opt_diropq_a, "diropq=a"},
25808 + {Opt_diropq_w, "diropq=whiteouted"},
25809 + {Opt_diropq_w, "diropq=w"},
25811 + {Opt_warn_perm, "warn_perm"},
25812 + {Opt_nowarn_perm, "nowarn_perm"},
25814 + /* keep them temporary */
25815 + {Opt_ignore_silent, "nodlgt"},
25816 + {Opt_ignore, "clean_plink"},
25818 +#ifdef CONFIG_AUFS_SHWH
25819 + {Opt_shwh, "shwh"},
25821 + {Opt_noshwh, "noshwh"},
25823 + {Opt_dirperm1, "dirperm1"},
25824 + {Opt_nodirperm1, "nodirperm1"},
25826 + {Opt_verbose, "verbose"},
25827 + {Opt_verbose, "v"},
25828 + {Opt_noverbose, "noverbose"},
25829 + {Opt_noverbose, "quiet"},
25830 + {Opt_noverbose, "q"},
25831 + {Opt_noverbose, "silent"},
25833 + {Opt_sum, "sum"},
25834 + {Opt_nosum, "nosum"},
25835 + {Opt_wsum, "wsum"},
25837 + {Opt_rdcache, "rdcache=%d"},
25838 + {Opt_rdblk, "rdblk=%d"},
25839 + {Opt_rdblk_def, "rdblk=def"},
25840 + {Opt_rdhash, "rdhash=%d"},
25841 + {Opt_rdhash_def, "rdhash=def"},
25843 + {Opt_wbr_create, "create=%s"},
25844 + {Opt_wbr_create, "create_policy=%s"},
25845 + {Opt_wbr_copyup, "cpup=%s"},
25846 + {Opt_wbr_copyup, "copyup=%s"},
25847 + {Opt_wbr_copyup, "copyup_policy=%s"},
25849 + /* generic VFS flag */
25850 +#ifdef CONFIG_FS_POSIX_ACL
25851 + {Opt_acl, "acl"},
25852 + {Opt_noacl, "noacl"},
25854 + {Opt_ignore, "acl"},
25855 + {Opt_ignore_silent, "noacl"},
25858 + /* internal use for the scripts */
25859 + {Opt_ignore_silent, "si=%s"},
25861 + {Opt_br, "dirs=%s"},
25862 + {Opt_ignore, "debug=%d"},
25863 + {Opt_ignore, "delete=whiteout"},
25864 + {Opt_ignore, "delete=all"},
25865 + {Opt_ignore, "imap=%s"},
25867 + /* temporary workaround, due to old mount(8)? */
25868 + {Opt_ignore_silent, "relatime"},
25873 +/* ---------------------------------------------------------------------- */
25875 +static const char *au_parser_pattern(int val, match_table_t tbl)
25877 + struct match_token *p;
25880 + while (p->pattern) {
25881 + if (p->token == val)
25882 + return p->pattern;
25889 +static const char *au_optstr(int *val, match_table_t tbl)
25891 + struct match_token *p;
25898 + while (p->pattern) {
25900 + && (v & p->token) == p->token) {
25901 + *val &= ~p->token;
25902 + return p->pattern;
25911 +/* ---------------------------------------------------------------------- */
25913 +static match_table_t brperm = {
25914 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25915 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25916 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25920 +static match_table_t brattr = {
25922 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25923 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25924 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25925 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25926 +#ifdef CONFIG_AUFS_FHSM
25927 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25929 +#ifdef CONFIG_AUFS_XATTR
25930 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25931 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25932 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25933 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25934 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25935 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25938 + /* ro/rr branch */
25939 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25942 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25943 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25948 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25955 + p = strchr(str, '+');
25958 + v = match_token(str, table, args);
25960 + if (v & AuBrAttr_CMOO_Mask)
25961 + attr &= ~AuBrAttr_CMOO_Mask;
25966 + pr_warn("ignored branch attribute %s\n", str);
25976 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25984 + p = au_optstr(&perm, brattr);
25987 + memcpy(q, p, sz + 1);
25993 + p = au_optstr(&perm, brattr);
25997 + memcpy(q, p, sz + 1);
26003 + return q - str->a;
26006 +static int noinline_for_stack br_perm_val(char *perm)
26008 + int val, bad, sz;
26010 + substring_t args[MAX_OPT_ARGS];
26011 + au_br_perm_str_t attr;
26013 + p = strchr(perm, '+');
26016 + val = match_token(perm, brperm, args);
26020 + pr_warn("ignored branch permission %s\n", perm);
26021 + val = AuBrPerm_RO;
26027 + val |= br_attr_val(p + 1, brattr, args);
26030 + switch (val & AuBrPerm_Mask) {
26031 + case AuBrPerm_RO:
26032 + case AuBrPerm_RR:
26033 + bad = val & AuBrWAttr_Mask;
26034 + val &= ~AuBrWAttr_Mask;
26036 + case AuBrPerm_RW:
26037 + bad = val & AuBrRAttr_Mask;
26038 + val &= ~AuBrRAttr_Mask;
26043 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
26044 + * does not treat it as an error, just warning.
26045 + * this is a tiny guard for the user operation.
26047 + if (val & AuBrAttr_UNPIN) {
26048 + bad |= AuBrAttr_UNPIN;
26049 + val &= ~AuBrAttr_UNPIN;
26052 + if (unlikely(bad)) {
26053 + sz = au_do_optstr_br_attr(&attr, bad);
26055 + pr_warn("ignored branch attribute %s\n", attr.a);
26062 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
26064 + au_br_perm_str_t attr;
26070 + p = au_optstr(&perm, brperm);
26071 + AuDebugOn(!p || !*p);
26073 + memcpy(q, p, sz + 1);
26076 + sz = au_do_optstr_br_attr(&attr, perm);
26079 + memcpy(q, attr.a, sz + 1);
26082 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
26085 +/* ---------------------------------------------------------------------- */
26087 +static match_table_t udbalevel = {
26088 + {AuOpt_UDBA_REVAL, "reval"},
26089 + {AuOpt_UDBA_NONE, "none"},
26090 +#ifdef CONFIG_AUFS_HNOTIFY
26091 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
26092 +#ifdef CONFIG_AUFS_HFSNOTIFY
26093 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
26099 +static int noinline_for_stack udba_val(char *str)
26101 + substring_t args[MAX_OPT_ARGS];
26103 + return match_token(str, udbalevel, args);
26106 +const char *au_optstr_udba(int udba)
26108 + return au_parser_pattern(udba, udbalevel);
26111 +/* ---------------------------------------------------------------------- */
26113 +static match_table_t au_wbr_create_policy = {
26114 + {AuWbrCreate_TDP, "tdp"},
26115 + {AuWbrCreate_TDP, "top-down-parent"},
26116 + {AuWbrCreate_RR, "rr"},
26117 + {AuWbrCreate_RR, "round-robin"},
26118 + {AuWbrCreate_MFS, "mfs"},
26119 + {AuWbrCreate_MFS, "most-free-space"},
26120 + {AuWbrCreate_MFSV, "mfs:%d"},
26121 + {AuWbrCreate_MFSV, "most-free-space:%d"},
26123 + /* top-down regardless the parent, and then mfs */
26124 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
26125 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
26127 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
26128 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
26129 + {AuWbrCreate_PMFS, "pmfs"},
26130 + {AuWbrCreate_PMFSV, "pmfs:%d"},
26131 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
26132 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26137 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26138 + struct au_opt_wbr_create *create)
26141 + unsigned long long ull;
26144 + if (!match_u64(arg, &ull))
26145 + create->mfsrr_watermark = ull;
26147 + pr_err("bad integer in %s\n", str);
26154 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26155 + struct au_opt_wbr_create *create)
26160 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26161 + create->mfs_second = n;
26163 + pr_err("bad integer in %s\n", str);
26170 +static int noinline_for_stack
26171 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26174 + substring_t args[MAX_OPT_ARGS];
26176 + err = match_token(str, au_wbr_create_policy, args);
26177 + create->wbr_create = err;
26179 + case AuWbrCreate_MFSRRV:
26180 + case AuWbrCreate_TDMFSV:
26181 + case AuWbrCreate_PMFSRRV:
26182 + e = au_wbr_mfs_wmark(&args[0], str, create);
26184 + e = au_wbr_mfs_sec(&args[1], str, create);
26188 + case AuWbrCreate_MFSRR:
26189 + case AuWbrCreate_TDMFS:
26190 + case AuWbrCreate_PMFSRR:
26191 + e = au_wbr_mfs_wmark(&args[0], str, create);
26192 + if (unlikely(e)) {
26197 + case AuWbrCreate_MFS:
26198 + case AuWbrCreate_PMFS:
26199 + create->mfs_second = AUFS_MFS_DEF_SEC;
26201 + case AuWbrCreate_MFSV:
26202 + case AuWbrCreate_PMFSV:
26203 + e = au_wbr_mfs_sec(&args[0], str, create);
26212 +const char *au_optstr_wbr_create(int wbr_create)
26214 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26217 +static match_table_t au_wbr_copyup_policy = {
26218 + {AuWbrCopyup_TDP, "tdp"},
26219 + {AuWbrCopyup_TDP, "top-down-parent"},
26220 + {AuWbrCopyup_BUP, "bup"},
26221 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26222 + {AuWbrCopyup_BU, "bu"},
26223 + {AuWbrCopyup_BU, "bottom-up"},
26227 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26229 + substring_t args[MAX_OPT_ARGS];
26231 + return match_token(str, au_wbr_copyup_policy, args);
26234 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26236 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26239 +/* ---------------------------------------------------------------------- */
26241 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26243 +static void dump_opts(struct au_opts *opts)
26245 +#ifdef CONFIG_AUFS_DEBUG
26246 + /* reduce stack space */
26248 + struct au_opt_add *add;
26249 + struct au_opt_del *del;
26250 + struct au_opt_mod *mod;
26251 + struct au_opt_xino *xino;
26252 + struct au_opt_xino_itrunc *xino_itrunc;
26253 + struct au_opt_wbr_create *create;
26255 + struct au_opt *opt;
26258 + while (opt->type != Opt_tail) {
26259 + switch (opt->type) {
26261 + u.add = &opt->add;
26262 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26263 + u.add->bindex, u.add->pathname, u.add->perm,
26264 + u.add->path.dentry);
26268 + u.del = &opt->del;
26269 + AuDbg("del {%s, %p}\n",
26270 + u.del->pathname, u.del->h_path.dentry);
26274 + u.mod = &opt->mod;
26275 + AuDbg("mod {%s, 0x%x, %p}\n",
26276 + u.mod->path, u.mod->perm, u.mod->h_root);
26279 + u.add = &opt->add;
26280 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26281 + u.add->bindex, u.add->pathname, u.add->perm,
26282 + u.add->path.dentry);
26284 + case Opt_prepend:
26285 + u.add = &opt->add;
26286 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26287 + u.add->bindex, u.add->pathname, u.add->perm,
26288 + u.add->path.dentry);
26291 + AuDbg("dirwh %d\n", opt->dirwh);
26293 + case Opt_rdcache:
26294 + AuDbg("rdcache %d\n", opt->rdcache);
26297 + AuDbg("rdblk %u\n", opt->rdblk);
26299 + case Opt_rdblk_def:
26300 + AuDbg("rdblk_def\n");
26303 + AuDbg("rdhash %u\n", opt->rdhash);
26305 + case Opt_rdhash_def:
26306 + AuDbg("rdhash_def\n");
26309 + u.xino = &opt->xino;
26310 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26312 + case Opt_trunc_xino:
26313 + AuLabel(trunc_xino);
26315 + case Opt_notrunc_xino:
26316 + AuLabel(notrunc_xino);
26318 + case Opt_trunc_xino_path:
26319 + case Opt_itrunc_xino:
26320 + u.xino_itrunc = &opt->xino_itrunc;
26321 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26326 + case Opt_trunc_xib:
26327 + AuLabel(trunc_xib);
26329 + case Opt_notrunc_xib:
26330 + AuLabel(notrunc_xib);
26338 + case Opt_dirperm1:
26339 + AuLabel(dirperm1);
26341 + case Opt_nodirperm1:
26342 + AuLabel(nodirperm1);
26347 + case Opt_noplink:
26348 + AuLabel(noplink);
26350 + case Opt_list_plink:
26351 + AuLabel(list_plink);
26354 + AuDbg("udba %d, %s\n",
26355 + opt->udba, au_optstr_udba(opt->udba));
26363 + case Opt_diropq_a:
26364 + AuLabel(diropq_a);
26366 + case Opt_diropq_w:
26367 + AuLabel(diropq_w);
26369 + case Opt_warn_perm:
26370 + AuLabel(warn_perm);
26372 + case Opt_nowarn_perm:
26373 + AuLabel(nowarn_perm);
26375 + case Opt_verbose:
26376 + AuLabel(verbose);
26378 + case Opt_noverbose:
26379 + AuLabel(noverbose);
26390 + case Opt_wbr_create:
26391 + u.create = &opt->wbr_create;
26392 + AuDbg("create %d, %s\n", u.create->wbr_create,
26393 + au_optstr_wbr_create(u.create->wbr_create));
26394 + switch (u.create->wbr_create) {
26395 + case AuWbrCreate_MFSV:
26396 + case AuWbrCreate_PMFSV:
26397 + AuDbg("%d sec\n", u.create->mfs_second);
26399 + case AuWbrCreate_MFSRR:
26400 + case AuWbrCreate_TDMFS:
26401 + AuDbg("%llu watermark\n",
26402 + u.create->mfsrr_watermark);
26404 + case AuWbrCreate_MFSRRV:
26405 + case AuWbrCreate_TDMFSV:
26406 + case AuWbrCreate_PMFSRRV:
26407 + AuDbg("%llu watermark, %d sec\n",
26408 + u.create->mfsrr_watermark,
26409 + u.create->mfs_second);
26413 + case Opt_wbr_copyup:
26414 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26415 + au_optstr_wbr_copyup(opt->wbr_copyup));
26417 + case Opt_fhsm_sec:
26418 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26423 + case Opt_nodirren:
26424 + AuLabel(nodirren);
26440 +void au_opts_free(struct au_opts *opts)
26442 + struct au_opt *opt;
26445 + while (opt->type != Opt_tail) {
26446 + switch (opt->type) {
26449 + case Opt_prepend:
26450 + path_put(&opt->add.path);
26454 + path_put(&opt->del.h_path);
26458 + dput(opt->mod.h_root);
26461 + fput(opt->xino.file);
26468 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26469 + aufs_bindex_t bindex)
26472 + struct au_opt_add *add = &opt->add;
26475 + add->bindex = bindex;
26476 + add->perm = AuBrPerm_RO;
26477 + add->pathname = opt_str;
26478 + p = strchr(opt_str, '=');
26482 + add->perm = br_perm_val(p);
26485 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26488 + add->perm = AuBrPerm_RO;
26489 + if (au_test_fs_rr(add->path.dentry->d_sb))
26490 + add->perm = AuBrPerm_RR;
26491 + else if (!bindex && !(sb_flags & SB_RDONLY))
26492 + add->perm = AuBrPerm_RW;
26494 + opt->type = Opt_add;
26497 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26504 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26508 + del->pathname = args[0].from;
26509 + AuDbg("del path %s\n", del->pathname);
26511 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26512 + if (unlikely(err))
26513 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26518 +#if 0 /* reserved for future use */
26519 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26520 + struct au_opt_del *del, substring_t args[])
26523 + struct dentry *root;
26526 + root = sb->s_root;
26527 + aufs_read_lock(root, AuLock_FLUSH);
26528 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26529 + pr_err("out of bounds, %d\n", bindex);
26534 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26535 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26538 + aufs_read_unlock(root, !AuLock_IR);
26543 +static int noinline_for_stack
26544 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26547 + struct path path;
26551 + mod->path = args[0].from;
26552 + p = strchr(mod->path, '=');
26553 + if (unlikely(!p)) {
26554 + pr_err("no permission %s\n", args[0].from);
26559 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26560 + if (unlikely(err)) {
26561 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26565 + mod->perm = br_perm_val(p);
26566 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26567 + mod->h_root = dget(path.dentry);
26574 +#if 0 /* reserved for future use */
26575 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26576 + struct au_opt_mod *mod, substring_t args[])
26579 + struct dentry *root;
26582 + root = sb->s_root;
26583 + aufs_read_lock(root, AuLock_FLUSH);
26584 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26585 + pr_err("out of bounds, %d\n", bindex);
26590 + mod->perm = br_perm_val(args[1].from);
26591 + AuDbg("mod path %s, perm 0x%x, %s\n",
26592 + mod->path, mod->perm, args[1].from);
26593 + mod->h_root = dget(au_h_dptr(root, bindex));
26596 + aufs_read_unlock(root, !AuLock_IR);
26601 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26602 + substring_t args[])
26605 + struct file *file;
26607 + file = au_xino_create(sb, args[0].from, /*silent*/0, /*wbrtop*/0);
26608 + err = PTR_ERR(file);
26609 + if (IS_ERR(file))
26613 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26615 + pr_err("%s must be outside\n", args[0].from);
26620 + xino->file = file;
26621 + xino->path = args[0].from;
26627 +static int noinline_for_stack
26628 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26629 + struct au_opt_xino_itrunc *xino_itrunc,
26630 + substring_t args[])
26633 + aufs_bindex_t bbot, bindex;
26634 + struct path path;
26635 + struct dentry *root;
26637 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26638 + if (unlikely(err)) {
26639 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26643 + xino_itrunc->bindex = -1;
26644 + root = sb->s_root;
26645 + aufs_read_lock(root, AuLock_FLUSH);
26646 + bbot = au_sbbot(sb);
26647 + for (bindex = 0; bindex <= bbot; bindex++) {
26648 + if (au_h_dptr(root, bindex) == path.dentry) {
26649 + xino_itrunc->bindex = bindex;
26653 + aufs_read_unlock(root, !AuLock_IR);
26656 + if (unlikely(xino_itrunc->bindex < 0)) {
26657 + pr_err("no such branch %s\n", args[0].from);
26665 +/* called without aufs lock */
26666 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26668 + int err, n, token;
26669 + aufs_bindex_t bindex;
26670 + unsigned char skipped;
26671 + struct dentry *root;
26672 + struct au_opt *opt, *opt_tail;
26674 + /* reduce the stack space */
26676 + struct au_opt_xino_itrunc *xino_itrunc;
26677 + struct au_opt_wbr_create *create;
26680 + substring_t args[MAX_OPT_ARGS];
26684 + a = kmalloc(sizeof(*a), GFP_NOFS);
26685 + if (unlikely(!a))
26688 + root = sb->s_root;
26692 + opt_tail = opt + opts->max_opt - 1;
26693 + opt->type = Opt_tail;
26694 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26697 + token = match_token(opt_str, options, a->args);
26701 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26703 + err = opt_add(opt, opt_str, opts->sb_flags,
26705 + if (unlikely(!err && ++opt > opt_tail)) {
26709 + opt->type = Opt_tail;
26714 + if (unlikely(match_int(&a->args[0], &n))) {
26715 + pr_err("bad integer in %s\n", opt_str);
26719 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26722 + opt->type = token;
26725 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26726 + /*dummy bindex*/1);
26728 + opt->type = token;
26730 + case Opt_prepend:
26731 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26734 + opt->type = token;
26737 + err = au_opts_parse_del(&opt->del, a->args);
26739 + opt->type = token;
26741 +#if 0 /* reserved for future use */
26743 + del->pathname = "(indexed)";
26744 + if (unlikely(match_int(&args[0], &n))) {
26745 + pr_err("bad integer in %s\n", opt_str);
26748 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26750 + opt->type = token;
26754 + err = au_opts_parse_mod(&opt->mod, a->args);
26756 + opt->type = token;
26758 +#ifdef IMOD /* reserved for future use */
26760 + u.mod->path = "(indexed)";
26761 + if (unlikely(match_int(&a->args[0], &n))) {
26762 + pr_err("bad integer in %s\n", opt_str);
26765 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26767 + opt->type = token;
26771 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26773 + opt->type = token;
26776 + case Opt_trunc_xino_path:
26777 + err = au_opts_parse_xino_itrunc_path
26778 + (sb, &opt->xino_itrunc, a->args);
26780 + opt->type = token;
26783 + case Opt_itrunc_xino:
26784 + u.xino_itrunc = &opt->xino_itrunc;
26785 + if (unlikely(match_int(&a->args[0], &n))) {
26786 + pr_err("bad integer in %s\n", opt_str);
26789 + u.xino_itrunc->bindex = n;
26790 + aufs_read_lock(root, AuLock_FLUSH);
26791 + if (n < 0 || au_sbbot(sb) < n) {
26792 + pr_err("out of bounds, %d\n", n);
26793 + aufs_read_unlock(root, !AuLock_IR);
26796 + aufs_read_unlock(root, !AuLock_IR);
26798 + opt->type = token;
26802 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26805 + opt->type = token;
26808 + case Opt_rdcache:
26809 + if (unlikely(match_int(&a->args[0], &n))) {
26810 + pr_err("bad integer in %s\n", opt_str);
26813 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26814 + pr_err("rdcache must be smaller than %d\n",
26815 + AUFS_RDCACHE_MAX);
26818 + opt->rdcache = n;
26820 + opt->type = token;
26823 + if (unlikely(match_int(&a->args[0], &n)
26825 + || n > KMALLOC_MAX_SIZE)) {
26826 + pr_err("bad integer in %s\n", opt_str);
26829 + if (unlikely(n && n < NAME_MAX)) {
26830 + pr_err("rdblk must be larger than %d\n",
26836 + opt->type = token;
26839 + if (unlikely(match_int(&a->args[0], &n)
26841 + || n * sizeof(struct hlist_head)
26842 + > KMALLOC_MAX_SIZE)) {
26843 + pr_err("bad integer in %s\n", opt_str);
26848 + opt->type = token;
26851 + case Opt_trunc_xino:
26852 + case Opt_notrunc_xino:
26854 + case Opt_trunc_xib:
26855 + case Opt_notrunc_xib:
26858 + case Opt_dirperm1:
26859 + case Opt_nodirperm1:
26861 + case Opt_noplink:
26862 + case Opt_list_plink:
26865 + case Opt_diropq_a:
26866 + case Opt_diropq_w:
26867 + case Opt_warn_perm:
26868 + case Opt_nowarn_perm:
26869 + case Opt_verbose:
26870 + case Opt_noverbose:
26874 + case Opt_rdblk_def:
26875 + case Opt_rdhash_def:
26877 + case Opt_nodirren:
26881 + opt->type = token;
26885 + opt->udba = udba_val(a->args[0].from);
26886 + if (opt->udba >= 0) {
26888 + opt->type = token;
26890 + pr_err("wrong value, %s\n", opt_str);
26893 + case Opt_wbr_create:
26894 + u.create = &opt->wbr_create;
26895 + u.create->wbr_create
26896 + = au_wbr_create_val(a->args[0].from, u.create);
26897 + if (u.create->wbr_create >= 0) {
26899 + opt->type = token;
26901 + pr_err("wrong value, %s\n", opt_str);
26903 + case Opt_wbr_copyup:
26904 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26905 + if (opt->wbr_copyup >= 0) {
26907 + opt->type = token;
26909 + pr_err("wrong value, %s\n", opt_str);
26912 + case Opt_fhsm_sec:
26913 + if (unlikely(match_int(&a->args[0], &n)
26915 + pr_err("bad integer in %s\n", opt_str);
26918 + if (sysaufs_brs) {
26919 + opt->fhsm_second = n;
26920 + opt->type = token;
26922 + pr_warn("ignored %s\n", opt_str);
26927 + pr_warn("ignored %s\n", opt_str);
26929 + case Opt_ignore_silent:
26934 + pr_err("unknown option %s\n", opt_str);
26938 + if (!err && !skipped) {
26939 + if (unlikely(++opt > opt_tail)) {
26942 + opt->type = Opt_tail;
26945 + opt->type = Opt_tail;
26951 + if (unlikely(err))
26952 + au_opts_free(opts);
26958 +static int au_opt_wbr_create(struct super_block *sb,
26959 + struct au_opt_wbr_create *create)
26962 + struct au_sbinfo *sbinfo;
26964 + SiMustWriteLock(sb);
26966 + err = 1; /* handled */
26967 + sbinfo = au_sbi(sb);
26968 + if (sbinfo->si_wbr_create_ops->fin) {
26969 + err = sbinfo->si_wbr_create_ops->fin(sb);
26974 + sbinfo->si_wbr_create = create->wbr_create;
26975 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26976 + switch (create->wbr_create) {
26977 + case AuWbrCreate_MFSRRV:
26978 + case AuWbrCreate_MFSRR:
26979 + case AuWbrCreate_TDMFS:
26980 + case AuWbrCreate_TDMFSV:
26981 + case AuWbrCreate_PMFSRR:
26982 + case AuWbrCreate_PMFSRRV:
26983 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26985 + case AuWbrCreate_MFS:
26986 + case AuWbrCreate_MFSV:
26987 + case AuWbrCreate_PMFS:
26988 + case AuWbrCreate_PMFSV:
26989 + sbinfo->si_wbr_mfs.mfs_expire
26990 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
26994 + if (sbinfo->si_wbr_create_ops->init)
26995 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27002 + * plus: processed without an error
27003 + * zero: unprocessed
27005 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27006 + struct au_opts *opts)
27009 + struct au_sbinfo *sbinfo;
27011 + SiMustWriteLock(sb);
27013 + err = 1; /* handled */
27014 + sbinfo = au_sbi(sb);
27015 + switch (opt->type) {
27017 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27018 + sbinfo->si_mntflags |= opt->udba;
27019 + opts->given_udba |= opt->udba;
27023 + au_opt_set(sbinfo->si_mntflags, PLINK);
27025 + case Opt_noplink:
27026 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27027 + au_plink_put(sb, /*verbose*/1);
27028 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27030 + case Opt_list_plink:
27031 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27032 + au_plink_list(sb);
27036 + au_opt_set(sbinfo->si_mntflags, DIO);
27037 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27040 + au_opt_clr(sbinfo->si_mntflags, DIO);
27041 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27044 + case Opt_fhsm_sec:
27045 + au_fhsm_set(sbinfo, opt->fhsm_second);
27048 + case Opt_diropq_a:
27049 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27051 + case Opt_diropq_w:
27052 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27055 + case Opt_warn_perm:
27056 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27058 + case Opt_nowarn_perm:
27059 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27062 + case Opt_verbose:
27063 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27065 + case Opt_noverbose:
27066 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27070 + au_opt_set(sbinfo->si_mntflags, SUM);
27073 + au_opt_clr(sbinfo->si_mntflags, SUM);
27074 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27077 + au_opt_clr(sbinfo->si_mntflags, SUM);
27078 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27081 + case Opt_wbr_create:
27082 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27084 + case Opt_wbr_copyup:
27085 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27086 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27090 + sbinfo->si_dirwh = opt->dirwh;
27093 + case Opt_rdcache:
27094 + sbinfo->si_rdcache
27095 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27098 + sbinfo->si_rdblk = opt->rdblk;
27100 + case Opt_rdblk_def:
27101 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
27104 + sbinfo->si_rdhash = opt->rdhash;
27106 + case Opt_rdhash_def:
27107 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
27111 + au_opt_set(sbinfo->si_mntflags, SHWH);
27114 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27117 + case Opt_dirperm1:
27118 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27120 + case Opt_nodirperm1:
27121 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27124 + case Opt_trunc_xino:
27125 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27127 + case Opt_notrunc_xino:
27128 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27131 + case Opt_trunc_xino_path:
27132 + case Opt_itrunc_xino:
27133 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27139 + case Opt_trunc_xib:
27140 + au_fset_opts(opts->flags, TRUNC_XIB);
27142 + case Opt_notrunc_xib:
27143 + au_fclr_opts(opts->flags, TRUNC_XIB);
27148 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27149 + err = au_dr_opt_set(sb);
27154 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27156 + case Opt_nodirren:
27158 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27159 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27165 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27169 + sb->s_flags |= SB_POSIXACL;
27172 + sb->s_flags &= ~SB_POSIXACL;
27184 + * returns tri-state.
27185 + * plus: processed without an error
27186 + * zero: unprocessed
27189 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27190 + struct au_opts *opts)
27192 + int err, do_refresh;
27195 + switch (opt->type) {
27197 + opt->add.bindex = au_sbbot(sb) + 1;
27198 + if (opt->add.bindex < 0)
27199 + opt->add.bindex = 0;
27201 + /* Always goto add, not fallthrough */
27202 + case Opt_prepend:
27203 + opt->add.bindex = 0;
27204 + /* fallthrough */
27205 + add: /* indented label */
27207 + err = au_br_add(sb, &opt->add,
27208 + au_ftest_opts(opts->flags, REMOUNT));
27211 + au_fset_opts(opts->flags, REFRESH);
27217 + err = au_br_del(sb, &opt->del,
27218 + au_ftest_opts(opts->flags, REMOUNT));
27221 + au_fset_opts(opts->flags, TRUNC_XIB);
27222 + au_fset_opts(opts->flags, REFRESH);
27228 + err = au_br_mod(sb, &opt->mod,
27229 + au_ftest_opts(opts->flags, REMOUNT),
27234 + au_fset_opts(opts->flags, REFRESH);
27241 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27242 + struct au_opt_xino **opt_xino,
27243 + struct au_opts *opts)
27248 + switch (opt->type) {
27250 + err = au_xino_set(sb, &opt->xino,
27251 + !!au_ftest_opts(opts->flags, REMOUNT));
27252 + if (unlikely(err))
27255 + *opt_xino = &opt->xino;
27260 + *opt_xino = (void *)-1;
27267 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27268 + unsigned int pending)
27271 + aufs_bindex_t bindex, bbot;
27272 + unsigned char do_plink, skip, do_free, can_no_dreval;
27273 + struct au_branch *br;
27274 + struct au_wbr *wbr;
27275 + struct dentry *root, *dentry;
27276 + struct inode *dir, *h_dir;
27277 + struct au_sbinfo *sbinfo;
27278 + struct au_hinode *hdir;
27280 + SiMustAnyLock(sb);
27282 + sbinfo = au_sbi(sb);
27283 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27285 + if (!(sb_flags & SB_RDONLY)) {
27286 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27287 + pr_warn("first branch should be rw\n");
27288 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27289 + pr_warn_once("shwh should be used with ro\n");
27292 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27293 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27294 + pr_warn_once("udba=*notify requires xino\n");
27296 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27297 + pr_warn_once("dirperm1 breaks the protection"
27298 + " by the permission bits on the lower branch\n");
27302 + root = sb->s_root;
27303 + dir = d_inode(root);
27304 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27305 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27307 + bbot = au_sbbot(sb);
27308 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27310 + h_dir = au_h_iptr(dir, bindex);
27311 + br = au_sbr(sb, bindex);
27313 + if ((br->br_perm & AuBrAttr_ICEX)
27314 + && !h_dir->i_op->listxattr)
27315 + br->br_perm &= ~AuBrAttr_ICEX;
27316 +#if 0 /* untested */
27317 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27318 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27319 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27323 + wbr = br->br_wbr;
27325 + wbr_wh_read_lock(wbr);
27327 + if (!au_br_writable(br->br_perm)) {
27330 + || (!wbr->wbr_whbase
27331 + && !wbr->wbr_plink
27332 + && !wbr->wbr_orph));
27333 + } else if (!au_br_wh_linkable(br->br_perm)) {
27334 + /* skip = (!br->br_whbase && !br->br_orph); */
27335 + skip = (!wbr || !wbr->wbr_whbase);
27336 + if (skip && wbr) {
27338 + skip = !!wbr->wbr_plink;
27340 + skip = !wbr->wbr_plink;
27343 + /* skip = (br->br_whbase && br->br_ohph); */
27344 + skip = (wbr && wbr->wbr_whbase);
27347 + skip = !!wbr->wbr_plink;
27349 + skip = !wbr->wbr_plink;
27353 + wbr_wh_read_unlock(wbr);
27355 + if (can_no_dreval) {
27356 + dentry = br->br_path.dentry;
27357 + spin_lock(&dentry->d_lock);
27358 + if (dentry->d_flags &
27359 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27360 + can_no_dreval = 0;
27361 + spin_unlock(&dentry->d_lock);
27364 + if (au_br_fhsm(br->br_perm)) {
27366 + AuDebugOn(!br->br_fhsm);
27372 + hdir = au_hi(dir, bindex);
27373 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27375 + wbr_wh_write_lock(wbr);
27376 + err = au_wh_init(br, sb);
27378 + wbr_wh_write_unlock(wbr);
27379 + au_hn_inode_unlock(hdir);
27381 + if (!err && do_free) {
27382 + au_kfree_rcu(wbr);
27383 + br->br_wbr = NULL;
27387 + if (can_no_dreval)
27388 + au_fset_si(sbinfo, NO_DREVAL);
27390 + au_fclr_si(sbinfo, NO_DREVAL);
27393 + au_fset_si(sbinfo, FHSM);
27394 + for (bindex = bbot; bindex >= 0; bindex--) {
27395 + br = au_sbr(sb, bindex);
27396 + if (au_br_fhsm(br->br_perm)) {
27397 + au_fhsm_set_bottom(sb, bindex);
27402 + au_fclr_si(sbinfo, FHSM);
27403 + au_fhsm_set_bottom(sb, -1);
27409 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27412 + unsigned int tmp;
27413 + aufs_bindex_t bindex, bbot;
27414 + struct au_opt *opt;
27415 + struct au_opt_xino *opt_xino, xino;
27416 + struct au_sbinfo *sbinfo;
27417 + struct au_branch *br;
27418 + struct inode *dir;
27420 + SiMustWriteLock(sb);
27425 + while (err >= 0 && opt->type != Opt_tail)
27426 + err = au_opt_simple(sb, opt++, opts);
27429 + else if (unlikely(err < 0))
27432 + /* disable xino and udba temporary */
27433 + sbinfo = au_sbi(sb);
27434 + tmp = sbinfo->si_mntflags;
27435 + au_opt_clr(sbinfo->si_mntflags, XINO);
27436 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27439 + while (err >= 0 && opt->type != Opt_tail)
27440 + err = au_opt_br(sb, opt++, opts);
27443 + else if (unlikely(err < 0))
27446 + bbot = au_sbbot(sb);
27447 + if (unlikely(bbot < 0)) {
27449 + pr_err("no branches\n");
27453 + if (au_opt_test(tmp, XINO))
27454 + au_opt_set(sbinfo->si_mntflags, XINO);
27456 + while (!err && opt->type != Opt_tail)
27457 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27458 + if (unlikely(err))
27461 + err = au_opts_verify(sb, sb->s_flags, tmp);
27462 + if (unlikely(err))
27465 + /* restore xino */
27466 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27467 + xino.file = au_xino_def(sb);
27468 + err = PTR_ERR(xino.file);
27469 + if (IS_ERR(xino.file))
27472 + err = au_xino_set(sb, &xino, /*remount*/0);
27474 + if (unlikely(err))
27478 + /* restore udba */
27479 + tmp &= AuOptMask_UDBA;
27480 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27481 + sbinfo->si_mntflags |= tmp;
27482 + bbot = au_sbbot(sb);
27483 + for (bindex = 0; bindex <= bbot; bindex++) {
27484 + br = au_sbr(sb, bindex);
27485 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27486 + if (unlikely(err))
27487 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27489 + /* go on even if err */
27491 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27492 + dir = d_inode(sb->s_root);
27493 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27500 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27503 + unsigned char no_dreval;
27504 + struct inode *dir;
27505 + struct au_opt_xino *opt_xino;
27506 + struct au_opt *opt;
27507 + struct au_sbinfo *sbinfo;
27509 + SiMustWriteLock(sb);
27511 + err = au_dr_opt_flush(sb);
27512 + if (unlikely(err))
27514 + au_fset_opts(opts->flags, DR_FLUSHED);
27516 + dir = d_inode(sb->s_root);
27517 + sbinfo = au_sbi(sb);
27520 + while (err >= 0 && opt->type != Opt_tail) {
27521 + err = au_opt_simple(sb, opt, opts);
27523 + err = au_opt_br(sb, opt, opts);
27525 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27531 + /* go on even err */
27533 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27534 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27535 + if (unlikely(rerr && !err))
27538 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27539 + au_fset_opts(opts->flags, REFRESH_IDOP);
27541 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27542 + rerr = au_xib_trunc(sb);
27543 + if (unlikely(rerr && !err))
27547 + /* will be handled by the caller */
27548 + if (!au_ftest_opts(opts->flags, REFRESH)
27549 + && (opts->given_udba
27550 + || au_opt_test(sbinfo->si_mntflags, XINO)
27551 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27553 + au_fset_opts(opts->flags, REFRESH);
27555 + AuDbg("status 0x%x\n", opts->flags);
27561 +/* ---------------------------------------------------------------------- */
27563 +unsigned int au_opt_udba(struct super_block *sb)
27565 + return au_mntflags(sb) & AuOptMask_UDBA;
27567 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27568 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27569 +++ linux/fs/aufs/opts.h 2020-01-27 10:57:18.175538316 +0100
27571 +/* SPDX-License-Identifier: GPL-2.0 */
27573 + * Copyright (C) 2005-2020 Junjiro R. Okajima
27575 + * This program, aufs is free software; you can redistribute it and/or modify
27576 + * it under the terms of the GNU General Public License as published by
27577 + * the Free Software Foundation; either version 2 of the License, or
27578 + * (at your option) any later version.
27580 + * This program is distributed in the hope that it will be useful,
27581 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27582 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27583 + * GNU General Public License for more details.
27585 + * You should have received a copy of the GNU General Public License
27586 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27590 + * mount options/flags
27593 +#ifndef __AUFS_OPTS_H__
27594 +#define __AUFS_OPTS_H__
27598 +#include <linux/path.h>
27602 +/* ---------------------------------------------------------------------- */
27605 +#define AuOpt_XINO 1 /* external inode number bitmap
27606 + and translation table */
27607 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27608 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27609 +#define AuOpt_UDBA_REVAL (1 << 3)
27610 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27611 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27612 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27613 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27615 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27616 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27617 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27618 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27619 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27620 +#define AuOpt_DIO (1 << 14) /* direct io */
27621 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27623 +#ifndef CONFIG_AUFS_HNOTIFY
27624 +#undef AuOpt_UDBA_HNOTIFY
27625 +#define AuOpt_UDBA_HNOTIFY 0
27627 +#ifndef CONFIG_AUFS_DIRREN
27628 +#undef AuOpt_DIRREN
27629 +#define AuOpt_DIRREN 0
27631 +#ifndef CONFIG_AUFS_SHWH
27633 +#define AuOpt_SHWH 0
27636 +#define AuOpt_Def (AuOpt_XINO \
27637 + | AuOpt_UDBA_REVAL \
27639 + /* | AuOpt_DIRPERM1 */ \
27640 + | AuOpt_WARN_PERM)
27641 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27642 + | AuOpt_UDBA_REVAL \
27643 + | AuOpt_UDBA_HNOTIFY)
27645 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27646 +#define au_opt_set(flags, name) do { \
27647 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27648 + ((flags) |= AuOpt_##name); \
27650 +#define au_opt_set_udba(flags, name) do { \
27651 + (flags) &= ~AuOptMask_UDBA; \
27652 + ((flags) |= AuOpt_##name); \
27654 +#define au_opt_clr(flags, name) do { \
27655 + ((flags) &= ~AuOpt_##name); \
27658 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27660 +#ifdef CONFIG_PROC_FS
27663 + return mntflags & ~AuOpt_PLINK;
27667 +/* ---------------------------------------------------------------------- */
27669 +/* policies to select one among multiple writable branches */
27671 + AuWbrCreate_TDP, /* top down parent */
27672 + AuWbrCreate_RR, /* round robin */
27673 + AuWbrCreate_MFS, /* most free space */
27674 + AuWbrCreate_MFSV, /* mfs with seconds */
27675 + AuWbrCreate_MFSRR, /* mfs then rr */
27676 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27677 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27678 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27679 + AuWbrCreate_PMFS, /* parent and mfs */
27680 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27681 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27682 + AuWbrCreate_PMFSRRV, /* plus seconds */
27684 + AuWbrCreate_Def = AuWbrCreate_TDP
27688 + AuWbrCopyup_TDP, /* top down parent */
27689 + AuWbrCopyup_BUP, /* bottom up parent */
27690 + AuWbrCopyup_BU, /* bottom up */
27692 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27695 +/* ---------------------------------------------------------------------- */
27697 +struct au_opt_add {
27698 + aufs_bindex_t bindex;
27701 + struct path path;
27704 +struct au_opt_del {
27706 + struct path h_path;
27709 +struct au_opt_mod {
27712 + struct dentry *h_root;
27715 +struct au_opt_xino {
27717 + struct file *file;
27720 +struct au_opt_xino_itrunc {
27721 + aufs_bindex_t bindex;
27724 +struct au_opt_wbr_create {
27727 + unsigned long long mfsrr_watermark;
27733 + struct au_opt_xino xino;
27734 + struct au_opt_xino_itrunc xino_itrunc;
27735 + struct au_opt_add add;
27736 + struct au_opt_del del;
27737 + struct au_opt_mod mod;
27740 + unsigned int rdblk;
27741 + unsigned int rdhash;
27743 + struct au_opt_wbr_create wbr_create;
27745 + unsigned int fhsm_second;
27750 +#define AuOpts_REMOUNT 1
27751 +#define AuOpts_REFRESH (1 << 1)
27752 +#define AuOpts_TRUNC_XIB (1 << 2)
27753 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27754 +#define AuOpts_REFRESH_IDOP (1 << 4)
27755 +#define AuOpts_DR_FLUSHED (1 << 5)
27756 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27757 +#define au_fset_opts(flags, name) \
27758 + do { (flags) |= AuOpts_##name; } while (0)
27759 +#define au_fclr_opts(flags, name) \
27760 + do { (flags) &= ~AuOpts_##name; } while (0)
27762 +#ifndef CONFIG_AUFS_DIRREN
27763 +#undef AuOpts_DR_FLUSHED
27764 +#define AuOpts_DR_FLUSHED 0
27768 + struct au_opt *opt;
27771 + unsigned int given_udba;
27772 + unsigned int flags;
27773 + unsigned long sb_flags;
27776 +/* ---------------------------------------------------------------------- */
27779 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27780 +const char *au_optstr_udba(int udba);
27781 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27782 +const char *au_optstr_wbr_create(int wbr_create);
27784 +void au_opts_free(struct au_opts *opts);
27785 +struct super_block;
27786 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27787 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27788 + unsigned int pending);
27789 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27790 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27792 +unsigned int au_opt_udba(struct super_block *sb);
27794 +#endif /* __KERNEL__ */
27795 +#endif /* __AUFS_OPTS_H__ */
27796 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27797 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27798 +++ linux/fs/aufs/plink.c 2020-01-27 10:57:18.175538316 +0100
27800 +// SPDX-License-Identifier: GPL-2.0
27802 + * Copyright (C) 2005-2020 Junjiro R. Okajima
27804 + * This program, aufs is free software; you can redistribute it and/or modify
27805 + * it under the terms of the GNU General Public License as published by
27806 + * the Free Software Foundation; either version 2 of the License, or
27807 + * (at your option) any later version.
27809 + * This program is distributed in the hope that it will be useful,
27810 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27811 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27812 + * GNU General Public License for more details.
27814 + * You should have received a copy of the GNU General Public License
27815 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27825 + * the pseudo-link maintenance mode.
27826 + * during a user process maintains the pseudo-links,
27827 + * prohibit adding a new plink and branch manipulation.
27831 + * For entry functions which will handle plink, and i_mutex is already held
27833 + * They cannot wait and should return an error at once.
27834 + * Callers has to check the error.
27836 + * For entry functions which will handle plink, but i_mutex is not held
27838 + * They can wait the plink maintenance mode to finish.
27840 + * They behave like F_SETLK and F_SETLKW.
27841 + * If the caller never handle plink, then both flags are unnecessary.
27844 +int au_plink_maint(struct super_block *sb, int flags)
27848 + struct task_struct *parent, *prev;
27849 + struct au_sbinfo *sbi;
27851 + SiMustAnyLock(sb);
27854 + if (!au_opt_test(au_mntflags(sb), PLINK))
27857 + sbi = au_sbi(sb);
27858 + pid = sbi->si_plink_maint_pid;
27859 + if (!pid || pid == current->pid)
27862 + /* todo: it highly depends upon /sbin/mount.aufs */
27864 + parent = current;
27868 + parent = rcu_dereference(parent->real_parent);
27869 + if (parent == prev)
27871 + ppid = task_pid_vnr(parent);
27872 + if (pid == ppid) {
27873 + rcu_read_unlock();
27878 + rcu_read_unlock();
27880 + if (au_ftest_lock(flags, NOPLMW)) {
27881 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27882 + /* AuDebugOn(!lockdep_depth(current)); */
27883 + while (sbi->si_plink_maint_pid) {
27884 + si_read_unlock(sb);
27885 + /* gave up wake_up_bit() */
27886 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27888 + if (au_ftest_lock(flags, FLUSH))
27889 + au_nwt_flush(&sbi->si_nowait);
27890 + si_noflush_read_lock(sb);
27892 + } else if (au_ftest_lock(flags, NOPLM)) {
27893 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27901 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27903 + spin_lock(&sbinfo->si_plink_maint_lock);
27904 + sbinfo->si_plink_maint_pid = 0;
27905 + spin_unlock(&sbinfo->si_plink_maint_lock);
27906 + wake_up_all(&sbinfo->si_plink_wq);
27909 +int au_plink_maint_enter(struct super_block *sb)
27912 + struct au_sbinfo *sbinfo;
27915 + sbinfo = au_sbi(sb);
27916 + /* make sure i am the only one in this fs */
27917 + si_write_lock(sb, AuLock_FLUSH);
27918 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27919 + spin_lock(&sbinfo->si_plink_maint_lock);
27920 + if (!sbinfo->si_plink_maint_pid)
27921 + sbinfo->si_plink_maint_pid = current->pid;
27924 + spin_unlock(&sbinfo->si_plink_maint_lock);
27926 + si_write_unlock(sb);
27931 +/* ---------------------------------------------------------------------- */
27933 +#ifdef CONFIG_AUFS_DEBUG
27934 +void au_plink_list(struct super_block *sb)
27937 + struct au_sbinfo *sbinfo;
27938 + struct hlist_bl_head *hbl;
27939 + struct hlist_bl_node *pos;
27940 + struct au_icntnr *icntnr;
27942 + SiMustAnyLock(sb);
27944 + sbinfo = au_sbi(sb);
27945 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27946 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27948 + for (i = 0; i < AuPlink_NHASH; i++) {
27949 + hbl = sbinfo->si_plink + i;
27950 + hlist_bl_lock(hbl);
27951 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27952 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27953 + hlist_bl_unlock(hbl);
27958 +/* is the inode pseudo-linked? */
27959 +int au_plink_test(struct inode *inode)
27962 + struct au_sbinfo *sbinfo;
27963 + struct hlist_bl_head *hbl;
27964 + struct hlist_bl_node *pos;
27965 + struct au_icntnr *icntnr;
27967 + sbinfo = au_sbi(inode->i_sb);
27968 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27969 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27970 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27973 + i = au_plink_hash(inode->i_ino);
27974 + hbl = sbinfo->si_plink + i;
27975 + hlist_bl_lock(hbl);
27976 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27977 + if (&icntnr->vfs_inode == inode) {
27981 + hlist_bl_unlock(hbl);
27985 +/* ---------------------------------------------------------------------- */
27988 + * generate a name for plink.
27989 + * the file will be stored under AUFS_WH_PLINKDIR.
27991 +/* 20 is max digits length of ulong 64 */
27992 +#define PLINK_NAME_LEN ((20 + 1) * 2)
27994 +static int plink_name(char *name, int len, struct inode *inode,
27995 + aufs_bindex_t bindex)
27998 + struct inode *h_inode;
28000 + h_inode = au_h_iptr(inode, bindex);
28001 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28005 +struct au_do_plink_lkup_args {
28006 + struct dentry **errp;
28007 + struct qstr *tgtname;
28008 + struct dentry *h_parent;
28009 + struct au_branch *br;
28012 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28013 + struct dentry *h_parent,
28014 + struct au_branch *br)
28016 + struct dentry *h_dentry;
28017 + struct inode *h_inode;
28019 + h_inode = d_inode(h_parent);
28020 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28021 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
28022 + inode_unlock_shared(h_inode);
28026 +static void au_call_do_plink_lkup(void *args)
28028 + struct au_do_plink_lkup_args *a = args;
28029 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
28032 +/* lookup the plink-ed @inode under the branch at @bindex */
28033 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28035 + struct dentry *h_dentry, *h_parent;
28036 + struct au_branch *br;
28038 + char a[PLINK_NAME_LEN];
28039 + struct qstr tgtname = QSTR_INIT(a, 0);
28041 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28043 + br = au_sbr(inode->i_sb, bindex);
28044 + h_parent = br->br_wbr->wbr_plink;
28045 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28047 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28048 + struct au_do_plink_lkup_args args = {
28049 + .errp = &h_dentry,
28050 + .tgtname = &tgtname,
28051 + .h_parent = h_parent,
28055 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28056 + if (unlikely(wkq_err))
28057 + h_dentry = ERR_PTR(wkq_err);
28059 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
28064 +/* create a pseudo-link */
28065 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
28066 + struct dentry *h_dentry, struct au_branch *br)
28069 + struct path h_path = {
28070 + .mnt = au_br_mnt(br)
28072 + struct inode *h_dir, *delegated;
28074 + h_dir = d_inode(h_parent);
28075 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28077 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
28078 + err = PTR_ERR(h_path.dentry);
28079 + if (IS_ERR(h_path.dentry))
28083 + /* wh.plink dir is not monitored */
28084 + /* todo: is it really safe? */
28085 + if (d_is_positive(h_path.dentry)
28086 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28087 + delegated = NULL;
28088 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28089 + if (unlikely(err == -EWOULDBLOCK)) {
28090 + pr_warn("cannot retry for NFSv4 delegation"
28091 + " for an internal unlink\n");
28094 + dput(h_path.dentry);
28095 + h_path.dentry = NULL;
28099 + if (!err && d_is_negative(h_path.dentry)) {
28100 + delegated = NULL;
28101 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28102 + if (unlikely(err == -EWOULDBLOCK)) {
28103 + pr_warn("cannot retry for NFSv4 delegation"
28104 + " for an internal link\n");
28108 + dput(h_path.dentry);
28111 + inode_unlock(h_dir);
28115 +struct do_whplink_args {
28117 + struct qstr *tgt;
28118 + struct dentry *h_parent;
28119 + struct dentry *h_dentry;
28120 + struct au_branch *br;
28123 +static void call_do_whplink(void *args)
28125 + struct do_whplink_args *a = args;
28126 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
28129 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28130 + aufs_bindex_t bindex, struct au_branch *br)
28132 + int err, wkq_err;
28133 + struct au_wbr *wbr;
28134 + struct dentry *h_parent;
28135 + char a[PLINK_NAME_LEN];
28136 + struct qstr tgtname = QSTR_INIT(a, 0);
28138 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
28139 + h_parent = wbr->wbr_plink;
28140 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28142 + /* always superio. */
28143 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28144 + struct do_whplink_args args = {
28147 + .h_parent = h_parent,
28148 + .h_dentry = h_dentry,
28151 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28152 + if (unlikely(wkq_err))
28155 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
28161 + * create a new pseudo-link for @h_dentry on @bindex.
28162 + * the linked inode is held in aufs @inode.
28164 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28165 + struct dentry *h_dentry)
28167 + struct super_block *sb;
28168 + struct au_sbinfo *sbinfo;
28169 + struct hlist_bl_head *hbl;
28170 + struct hlist_bl_node *pos;
28171 + struct au_icntnr *icntnr;
28172 + int found, err, cnt, i;
28174 + sb = inode->i_sb;
28175 + sbinfo = au_sbi(sb);
28176 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28177 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28179 + found = au_plink_test(inode);
28183 + i = au_plink_hash(inode->i_ino);
28184 + hbl = sbinfo->si_plink + i;
28187 + hlist_bl_lock(hbl);
28188 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28189 + if (&icntnr->vfs_inode == inode) {
28195 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28196 + hlist_bl_add_head(&icntnr->plink, hbl);
28198 + hlist_bl_unlock(hbl);
28200 + cnt = au_hbl_count(hbl);
28201 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28202 + if (cnt > AUFS_PLINK_WARN)
28203 + AuWarn1(msg ", %d\n", cnt);
28205 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
28206 + if (unlikely(err)) {
28207 + pr_warn("err %d, damaged pseudo link.\n", err);
28208 + au_hbl_del(&icntnr->plink, hbl);
28209 + iput(&icntnr->vfs_inode);
28212 + iput(&icntnr->vfs_inode);
28215 +/* free all plinks */
28216 +void au_plink_put(struct super_block *sb, int verbose)
28219 + struct au_sbinfo *sbinfo;
28220 + struct hlist_bl_head *hbl;
28221 + struct hlist_bl_node *pos, *tmp;
28222 + struct au_icntnr *icntnr;
28224 + SiMustWriteLock(sb);
28226 + sbinfo = au_sbi(sb);
28227 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28228 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28230 + /* no spin_lock since sbinfo is write-locked */
28232 + for (i = 0; i < AuPlink_NHASH; i++) {
28233 + hbl = sbinfo->si_plink + i;
28234 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28235 + pr_warn("pseudo-link is not flushed");
28238 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28239 + iput(&icntnr->vfs_inode);
28240 + INIT_HLIST_BL_HEAD(hbl);
28244 +void au_plink_clean(struct super_block *sb, int verbose)
28246 + struct dentry *root;
28248 + root = sb->s_root;
28249 + aufs_write_lock(root);
28250 + if (au_opt_test(au_mntflags(sb), PLINK))
28251 + au_plink_put(sb, verbose);
28252 + aufs_write_unlock(root);
28255 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28258 + aufs_bindex_t btop, bbot, bindex;
28261 + btop = au_ibtop(inode);
28262 + bbot = au_ibbot(inode);
28264 + for (bindex = btop; bindex <= bbot; bindex++) {
28265 + if (!au_h_iptr(inode, bindex)
28266 + || au_ii_br_id(inode, bindex) != br_id)
28268 + au_set_h_iptr(inode, bindex, NULL, 0);
28273 + for (bindex = btop; bindex <= bbot; bindex++)
28274 + if (au_h_iptr(inode, bindex)) {
28284 +/* free the plinks on a branch specified by @br_id */
28285 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28287 + struct au_sbinfo *sbinfo;
28288 + struct hlist_bl_head *hbl;
28289 + struct hlist_bl_node *pos, *tmp;
28290 + struct au_icntnr *icntnr;
28291 + struct inode *inode;
28294 + SiMustWriteLock(sb);
28296 + sbinfo = au_sbi(sb);
28297 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28298 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28300 + /* no bit_lock since sbinfo is write-locked */
28301 + for (i = 0; i < AuPlink_NHASH; i++) {
28302 + hbl = sbinfo->si_plink + i;
28303 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28304 + inode = au_igrab(&icntnr->vfs_inode);
28305 + ii_write_lock_child(inode);
28306 + do_put = au_plink_do_half_refresh(inode, br_id);
28308 + hlist_bl_del(&icntnr->plink);
28311 + ii_write_unlock(inode);
28316 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28317 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28318 +++ linux/fs/aufs/poll.c 2020-01-27 10:57:18.175538316 +0100
28320 +// SPDX-License-Identifier: GPL-2.0
28322 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28324 + * This program, aufs is free software; you can redistribute it and/or modify
28325 + * it under the terms of the GNU General Public License as published by
28326 + * the Free Software Foundation; either version 2 of the License, or
28327 + * (at your option) any later version.
28329 + * This program is distributed in the hope that it will be useful,
28330 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28331 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28332 + * GNU General Public License for more details.
28334 + * You should have received a copy of the GNU General Public License
28335 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28340 + * There is only one filesystem which implements ->poll operation, currently.
28345 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28348 + struct file *h_file;
28349 + struct super_block *sb;
28351 + /* We should pretend an error happened. */
28352 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28353 + sb = file->f_path.dentry->d_sb;
28354 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28356 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28357 + if (IS_ERR(h_file)) {
28358 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28362 + mask = vfs_poll(h_file, pt);
28363 + fput(h_file); /* instead of au_read_post() */
28366 + si_read_unlock(sb);
28367 + if (mask & EPOLLERR)
28368 + AuDbg("mask 0x%x\n", mask);
28371 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28372 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28373 +++ linux/fs/aufs/posix_acl.c 2020-01-27 10:57:18.175538316 +0100
28375 +// SPDX-License-Identifier: GPL-2.0
28377 + * Copyright (C) 2014-2020 Junjiro R. Okajima
28379 + * This program, aufs is free software; you can redistribute it and/or modify
28380 + * it under the terms of the GNU General Public License as published by
28381 + * the Free Software Foundation; either version 2 of the License, or
28382 + * (at your option) any later version.
28384 + * This program is distributed in the hope that it will be useful,
28385 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28386 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28387 + * GNU General Public License for more details.
28389 + * You should have received a copy of the GNU General Public License
28390 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28394 + * posix acl operations
28397 +#include <linux/fs.h>
28400 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28402 + struct posix_acl *acl;
28404 + aufs_bindex_t bindex;
28405 + struct inode *h_inode;
28406 + struct super_block *sb;
28409 + sb = inode->i_sb;
28410 + si_read_lock(sb, AuLock_FLUSH);
28411 + ii_read_lock_child(inode);
28412 + if (!(sb->s_flags & SB_POSIXACL))
28415 + bindex = au_ibtop(inode);
28416 + h_inode = au_h_iptr(inode, bindex);
28417 + if (unlikely(!h_inode
28418 + || ((h_inode->i_mode & S_IFMT)
28419 + != (inode->i_mode & S_IFMT)))) {
28420 + err = au_busy_or_stale();
28421 + acl = ERR_PTR(err);
28425 + /* always topmost only */
28426 + acl = get_acl(h_inode, type);
28428 + forget_cached_acl(inode, type);
28430 + set_cached_acl(inode, type, acl);
28433 + ii_read_unlock(inode);
28434 + si_read_unlock(sb);
28436 + AuTraceErrPtr(acl);
28440 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28444 + struct dentry *dentry;
28445 + struct au_sxattr arg = {
28446 + .type = AU_ACL_SET,
28453 + IMustLock(inode);
28455 + if (inode->i_ino == AUFS_ROOT_INO)
28456 + dentry = dget(inode->i_sb->s_root);
28458 + dentry = d_find_alias(inode);
28460 + dentry = d_find_any_alias(inode);
28462 + pr_warn("cannot handle this inode, "
28463 + "please report to aufs-users ML\n");
28469 + ssz = au_sxattr(dentry, inode, &arg);
28470 + /* forget even it if succeeds since the branch might set differently */
28471 + forget_cached_acl(inode, type);
28480 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28481 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28482 +++ linux/fs/aufs/procfs.c 2020-08-03 09:14:43.142321747 +0200
28484 +// SPDX-License-Identifier: GPL-2.0
28486 + * Copyright (C) 2010-2020 Junjiro R. Okajima
28488 + * This program, aufs is free software; you can redistribute it and/or modify
28489 + * it under the terms of the GNU General Public License as published by
28490 + * the Free Software Foundation; either version 2 of the License, or
28491 + * (at your option) any later version.
28493 + * This program is distributed in the hope that it will be useful,
28494 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28495 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28496 + * GNU General Public License for more details.
28498 + * You should have received a copy of the GNU General Public License
28499 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28503 + * procfs interfaces
28506 +#include <linux/proc_fs.h>
28509 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28511 + struct au_sbinfo *sbinfo;
28513 + sbinfo = file->private_data;
28515 + au_plink_maint_leave(sbinfo);
28516 + kobject_put(&sbinfo->si_kobj);
28522 +static void au_procfs_plm_write_clean(struct file *file)
28524 + struct au_sbinfo *sbinfo;
28526 + sbinfo = file->private_data;
28528 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28531 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28534 + struct super_block *sb;
28535 + struct au_sbinfo *sbinfo;
28536 + struct hlist_bl_node *pos;
28539 + if (unlikely(file->private_data))
28543 + /* don't use au_sbilist_lock() here */
28544 + hlist_bl_lock(&au_sbilist);
28545 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28546 + if (id == sysaufs_si_id(sbinfo)) {
28547 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28548 + sb = sbinfo->si_sb;
28551 + hlist_bl_unlock(&au_sbilist);
28554 + if (unlikely(!sb))
28557 + err = au_plink_maint_enter(sb);
28559 + /* keep kobject_get() */
28560 + file->private_data = sbinfo;
28562 + kobject_put(&sbinfo->si_kobj);
28568 + * Accept a valid "si=xxxx" only.
28569 + * Once it is accepted successfully, accept "clean" too.
28571 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28572 + size_t count, loff_t *ppos)
28575 + unsigned long id;
28576 + /* last newline is allowed */
28577 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28580 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28584 + if (unlikely(count > sizeof(buf)))
28587 + err = copy_from_user(buf, ubuf, count);
28588 + if (unlikely(err)) {
28595 + if (!strcmp("clean", buf)) {
28596 + au_procfs_plm_write_clean(file);
28597 + goto out_success;
28598 + } else if (unlikely(strncmp("si=", buf, 3)))
28601 + err = kstrtoul(buf + 3, 16, &id);
28602 + if (unlikely(err))
28605 + err = au_procfs_plm_write_si(file, id);
28606 + if (unlikely(err))
28610 + err = count; /* success */
28615 +static const struct proc_ops au_procfs_plm_op = {
28616 + .proc_write = au_procfs_plm_write,
28617 + .proc_release = au_procfs_plm_release
28620 +/* ---------------------------------------------------------------------- */
28622 +static struct proc_dir_entry *au_procfs_dir;
28624 +void au_procfs_fin(void)
28626 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28627 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28630 +int __init au_procfs_init(void)
28633 + struct proc_dir_entry *entry;
28636 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28637 + if (unlikely(!au_procfs_dir))
28640 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28641 + au_procfs_dir, &au_procfs_plm_op);
28642 + if (unlikely(!entry))
28646 + goto out; /* success */
28650 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28654 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28655 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28656 +++ linux/fs/aufs/rdu.c 2020-01-27 10:57:18.178871751 +0100
28658 +// SPDX-License-Identifier: GPL-2.0
28660 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28662 + * This program, aufs is free software; you can redistribute it and/or modify
28663 + * it under the terms of the GNU General Public License as published by
28664 + * the Free Software Foundation; either version 2 of the License, or
28665 + * (at your option) any later version.
28667 + * This program is distributed in the hope that it will be useful,
28668 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28669 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28670 + * GNU General Public License for more details.
28672 + * You should have received a copy of the GNU General Public License
28673 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28677 + * readdir in userspace.
28680 +#include <linux/compat.h>
28681 +#include <linux/fs_stack.h>
28682 +#include <linux/security.h>
28685 +/* bits for struct aufs_rdu.flags */
28686 +#define AuRdu_CALLED 1
28687 +#define AuRdu_CONT (1 << 1)
28688 +#define AuRdu_FULL (1 << 2)
28689 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28690 +#define au_fset_rdu(flags, name) \
28691 + do { (flags) |= AuRdu_##name; } while (0)
28692 +#define au_fclr_rdu(flags, name) \
28693 + do { (flags) &= ~AuRdu_##name; } while (0)
28695 +struct au_rdu_arg {
28696 + struct dir_context ctx;
28697 + struct aufs_rdu *rdu;
28698 + union au_rdu_ent_ul ent;
28699 + unsigned long end;
28701 + struct super_block *sb;
28705 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28706 + loff_t offset, u64 h_ino, unsigned int d_type)
28709 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28710 + struct aufs_rdu *rdu = arg->rdu;
28711 + struct au_rdu_ent ent;
28715 + au_fset_rdu(rdu->cookie.flags, CALLED);
28716 + len = au_rdu_len(nlen);
28717 + if (arg->ent.ul + len < arg->end) {
28719 + ent.bindex = rdu->cookie.bindex;
28720 + ent.type = d_type;
28722 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28723 + ent.type = DT_UNKNOWN;
28725 + /* unnecessary to support mmap_sem since this is a dir */
28727 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28729 + if (copy_to_user(arg->ent.e->name, name, nlen))
28731 + /* the terminating NULL */
28732 + if (__put_user(0, arg->ent.e->name + nlen))
28735 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28736 + arg->ent.ul += len;
28740 + au_fset_rdu(rdu->cookie.flags, FULL);
28742 + rdu->tail = arg->ent;
28746 + /* AuTraceErr(err); */
28750 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28754 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28756 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28757 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28759 + if (unlikely(offset != cookie->h_pos))
28765 + au_fclr_rdu(cookie->flags, CALLED);
28767 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28771 + && au_ftest_rdu(cookie->flags, CALLED)
28772 + && !au_ftest_rdu(cookie->flags, FULL));
28773 + cookie->h_pos = h_file->f_pos;
28780 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28783 + aufs_bindex_t bbot;
28784 + struct au_rdu_arg arg = {
28786 + .actor = au_rdu_fill
28789 + struct dentry *dentry;
28790 + struct inode *inode;
28791 + struct file *h_file;
28792 + struct au_rdu_cookie *cookie = &rdu->cookie;
28794 + /* VERIFY_WRITE */
28795 + err = !access_ok(rdu->ent.e, rdu->sz);
28796 + if (unlikely(err)) {
28802 + rdu->tail = rdu->ent;
28805 + arg.ent = rdu->ent;
28806 + arg.end = arg.ent.ul;
28807 + arg.end += rdu->sz;
28810 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28813 + err = security_file_permission(file, MAY_READ);
28815 + if (unlikely(err))
28818 + dentry = file->f_path.dentry;
28819 + inode = d_inode(dentry);
28820 + inode_lock_shared(inode);
28822 + arg.sb = inode->i_sb;
28823 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28824 + if (unlikely(err))
28826 + err = au_alive_dir(dentry);
28827 + if (unlikely(err))
28829 + /* todo: reval? */
28830 + fi_read_lock(file);
28833 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28834 + && cookie->generation != au_figen(file)))
28839 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28841 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28843 + bbot = au_fbtop(file);
28844 + if (cookie->bindex < bbot)
28845 + cookie->bindex = bbot;
28846 + bbot = au_fbbot_dir(file);
28847 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28848 + for (; !err && cookie->bindex <= bbot;
28849 + cookie->bindex++, cookie->h_pos = 0) {
28850 + h_file = au_hf_dir(file, cookie->bindex);
28854 + au_fclr_rdu(cookie->flags, FULL);
28855 + err = au_rdu_do(h_file, &arg);
28857 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28860 + AuDbg("rent %llu\n", rdu->rent);
28862 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28863 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28864 + au_fset_rdu(cookie->flags, CONT);
28865 + cookie->generation = au_figen(file);
28868 + ii_read_lock_child(inode);
28869 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28870 + ii_read_unlock(inode);
28873 + fi_read_unlock(file);
28875 + si_read_unlock(arg.sb);
28877 + inode_unlock_shared(inode);
28883 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28887 + unsigned long long nent;
28888 + union au_rdu_ent_ul *u;
28889 + struct au_rdu_ent ent;
28890 + struct super_block *sb;
28893 + nent = rdu->nent;
28895 + sb = file->f_path.dentry->d_sb;
28896 + si_read_lock(sb, AuLock_FLUSH);
28897 + while (nent-- > 0) {
28898 + /* unnecessary to support mmap_sem since this is a dir */
28899 + err = copy_from_user(&ent, u->e, sizeof(ent));
28901 + /* VERIFY_WRITE */
28902 + err = !access_ok(&u->e->ino, sizeof(ino));
28903 + if (unlikely(err)) {
28909 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28911 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28913 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28915 + if (unlikely(err)) {
28920 + err = __put_user(ino, &u->e->ino);
28921 + if (unlikely(err)) {
28926 + u->ul += au_rdu_len(ent.nlen);
28928 + si_read_unlock(sb);
28933 +/* ---------------------------------------------------------------------- */
28935 +static int au_rdu_verify(struct aufs_rdu *rdu)
28937 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28938 + "%llu, b%d, 0x%x, g%u}\n",
28939 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28941 + rdu->rent, rdu->shwh, rdu->full,
28942 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28943 + rdu->cookie.generation);
28945 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28949 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28953 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28956 + struct aufs_rdu rdu;
28957 + void __user *p = (void __user *)arg;
28959 + err = copy_from_user(&rdu, p, sizeof(rdu));
28960 + if (unlikely(err)) {
28965 + err = au_rdu_verify(&rdu);
28966 + if (unlikely(err))
28970 + case AUFS_CTL_RDU:
28971 + err = au_rdu(file, &rdu);
28972 + if (unlikely(err))
28975 + e = copy_to_user(p, &rdu, sizeof(rdu));
28976 + if (unlikely(e)) {
28981 + case AUFS_CTL_RDU_INO:
28982 + err = au_rdu_ino(file, &rdu);
28986 + /* err = -ENOTTY; */
28995 +#ifdef CONFIG_COMPAT
28996 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28999 + struct aufs_rdu rdu;
29000 + void __user *p = compat_ptr(arg);
29002 + /* todo: get_user()? */
29003 + err = copy_from_user(&rdu, p, sizeof(rdu));
29004 + if (unlikely(err)) {
29009 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29010 + err = au_rdu_verify(&rdu);
29011 + if (unlikely(err))
29015 + case AUFS_CTL_RDU:
29016 + err = au_rdu(file, &rdu);
29017 + if (unlikely(err))
29020 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29021 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29022 + e = copy_to_user(p, &rdu, sizeof(rdu));
29023 + if (unlikely(e)) {
29028 + case AUFS_CTL_RDU_INO:
29029 + err = au_rdu_ino(file, &rdu);
29033 + /* err = -ENOTTY; */
29042 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29043 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29044 +++ linux/fs/aufs/rwsem.h 2020-01-27 10:57:18.178871751 +0100
29046 +/* SPDX-License-Identifier: GPL-2.0 */
29048 + * Copyright (C) 2005-2020 Junjiro R. Okajima
29050 + * This program, aufs is free software; you can redistribute it and/or modify
29051 + * it under the terms of the GNU General Public License as published by
29052 + * the Free Software Foundation; either version 2 of the License, or
29053 + * (at your option) any later version.
29055 + * This program is distributed in the hope that it will be useful,
29056 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29057 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29058 + * GNU General Public License for more details.
29060 + * You should have received a copy of the GNU General Public License
29061 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29065 + * simple read-write semaphore wrappers
29068 +#ifndef __AUFS_RWSEM_H__
29069 +#define __AUFS_RWSEM_H__
29073 +#include "debug.h"
29075 +/* in the future, the name 'au_rwsem' will be totally gone */
29076 +#define au_rwsem rw_semaphore
29078 +/* to debug easier, do not make them inlined functions */
29079 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29080 +/* rwsem_is_locked() is unusable */
29081 +#define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \
29083 + && !lockdep_is_held_type(rw, 1))
29084 +#define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \
29086 + && !lockdep_is_held_type(rw, 0))
29087 +#define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \
29089 + && !lockdep_is_held(rw))
29090 +#define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \
29092 + && lockdep_is_held(rw))
29094 +#define au_rw_init(rw) init_rwsem(rw)
29096 +#define au_rw_init_wlock(rw) do { \
29097 + au_rw_init(rw); \
29098 + down_write(rw); \
29101 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29102 + au_rw_init(rw); \
29103 + down_write_nested(rw, lsc); \
29106 +#define au_rw_read_lock(rw) down_read(rw)
29107 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29108 +#define au_rw_read_unlock(rw) up_read(rw)
29109 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29110 +#define au_rw_write_lock(rw) down_write(rw)
29111 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29112 +#define au_rw_write_unlock(rw) up_write(rw)
29113 +/* why is not _nested version defined? */
29114 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29115 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29117 +#endif /* __KERNEL__ */
29118 +#endif /* __AUFS_RWSEM_H__ */
29119 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29120 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29121 +++ linux/fs/aufs/sbinfo.c 2020-01-27 10:57:18.178871751 +0100
29123 +// SPDX-License-Identifier: GPL-2.0
29125 + * Copyright (C) 2005-2020 Junjiro R. Okajima
29127 + * This program, aufs is free software; you can redistribute it and/or modify
29128 + * it under the terms of the GNU General Public License as published by
29129 + * the Free Software Foundation; either version 2 of the License, or
29130 + * (at your option) any later version.
29132 + * This program is distributed in the hope that it will be useful,
29133 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29134 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29135 + * GNU General Public License for more details.
29137 + * You should have received a copy of the GNU General Public License
29138 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29142 + * superblock private data
29145 +#include <linux/iversion.h>
29149 + * they are necessary regardless sysfs is disabled.
29151 +void au_si_free(struct kobject *kobj)
29154 + struct au_sbinfo *sbinfo;
29155 + char *locked __maybe_unused; /* debug only */
29157 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29158 + for (i = 0; i < AuPlink_NHASH; i++)
29159 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29160 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29162 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29163 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29164 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29165 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29167 + dbgaufs_si_fin(sbinfo);
29168 + au_rw_write_lock(&sbinfo->si_rwsem);
29169 + au_br_free(sbinfo);
29170 + au_rw_write_unlock(&sbinfo->si_rwsem);
29172 + au_kfree_try_rcu(sbinfo->si_branch);
29173 + mutex_destroy(&sbinfo->si_xib_mtx);
29174 + AuRwDestroy(&sbinfo->si_rwsem);
29176 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29177 + /* si_nfiles is waited too */
29178 + au_kfree_rcu(sbinfo);
29181 +int au_si_alloc(struct super_block *sb)
29184 + struct au_sbinfo *sbinfo;
29187 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29188 + if (unlikely(!sbinfo))
29191 + /* will be reallocated separately */
29192 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29193 + if (unlikely(!sbinfo->si_branch))
29196 + err = sysaufs_si_init(sbinfo);
29198 + dbgaufs_si_null(sbinfo);
29199 + err = dbgaufs_si_init(sbinfo);
29200 + if (unlikely(err))
29201 + kobject_put(&sbinfo->si_kobj);
29203 + if (unlikely(err))
29206 + au_nwt_init(&sbinfo->si_nowait);
29207 + au_rw_init_wlock(&sbinfo->si_rwsem);
29209 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29210 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29212 + sbinfo->si_bbot = -1;
29213 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29215 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29216 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29217 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29218 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29220 + au_fhsm_init(sbinfo);
29222 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29224 + sbinfo->si_xino_jiffy = jiffies;
29225 + sbinfo->si_xino_expire
29226 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29227 + mutex_init(&sbinfo->si_xib_mtx);
29228 + /* leave si_xib_last_pindex and si_xib_next_bit */
29230 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29232 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29233 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29234 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29235 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29237 + for (i = 0; i < AuPlink_NHASH; i++)
29238 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29239 + init_waitqueue_head(&sbinfo->si_plink_wq);
29240 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29242 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29244 + /* with getattr by default */
29245 + sbinfo->si_iop_array = aufs_iop;
29247 + /* leave other members for sysaufs and si_mnt. */
29248 + sbinfo->si_sb = sb;
29249 + sb->s_fs_info = sbinfo;
29251 + return 0; /* success */
29254 + au_kfree_try_rcu(sbinfo->si_branch);
29256 + au_kfree_rcu(sbinfo);
29261 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29264 + struct au_branch **brp;
29266 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29269 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29270 + if (unlikely(!sz))
29271 + sz = sizeof(*brp);
29272 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29275 + sbinfo->si_branch = brp;
29282 +/* ---------------------------------------------------------------------- */
29284 +unsigned int au_sigen_inc(struct super_block *sb)
29286 + unsigned int gen;
29287 + struct inode *inode;
29289 + SiMustWriteLock(sb);
29291 + gen = ++au_sbi(sb)->si_generation;
29292 + au_update_digen(sb->s_root);
29293 + inode = d_inode(sb->s_root);
29294 + au_update_iigen(inode, /*half*/0);
29295 + inode_inc_iversion(inode);
29299 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29301 + aufs_bindex_t br_id;
29303 + struct au_sbinfo *sbinfo;
29305 + SiMustWriteLock(sb);
29307 + sbinfo = au_sbi(sb);
29308 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29309 + br_id = ++sbinfo->si_last_br_id;
29310 + AuDebugOn(br_id < 0);
29311 + if (br_id && au_br_index(sb, br_id) < 0)
29318 +/* ---------------------------------------------------------------------- */
29320 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29321 +int si_read_lock(struct super_block *sb, int flags)
29326 + if (au_ftest_lock(flags, FLUSH))
29327 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29329 + si_noflush_read_lock(sb);
29330 + err = au_plink_maint(sb, flags);
29331 + if (unlikely(err))
29332 + si_read_unlock(sb);
29337 +int si_write_lock(struct super_block *sb, int flags)
29341 + if (au_ftest_lock(flags, FLUSH))
29342 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29344 + si_noflush_write_lock(sb);
29345 + err = au_plink_maint(sb, flags);
29346 + if (unlikely(err))
29347 + si_write_unlock(sb);
29352 +/* dentry and super_block lock. call at entry point */
29353 +int aufs_read_lock(struct dentry *dentry, int flags)
29356 + struct super_block *sb;
29358 + sb = dentry->d_sb;
29359 + err = si_read_lock(sb, flags);
29360 + if (unlikely(err))
29363 + if (au_ftest_lock(flags, DW))
29364 + di_write_lock_child(dentry);
29366 + di_read_lock_child(dentry, flags);
29368 + if (au_ftest_lock(flags, GEN)) {
29369 + err = au_digen_test(dentry, au_sigen(sb));
29370 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29371 + AuDebugOn(!err && au_dbrange_test(dentry));
29373 + err = au_dbrange_test(dentry);
29374 + if (unlikely(err))
29375 + aufs_read_unlock(dentry, flags);
29382 +void aufs_read_unlock(struct dentry *dentry, int flags)
29384 + if (au_ftest_lock(flags, DW))
29385 + di_write_unlock(dentry);
29387 + di_read_unlock(dentry, flags);
29388 + si_read_unlock(dentry->d_sb);
29391 +void aufs_write_lock(struct dentry *dentry)
29393 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29394 + di_write_lock_child(dentry);
29397 +void aufs_write_unlock(struct dentry *dentry)
29399 + di_write_unlock(dentry);
29400 + si_write_unlock(dentry->d_sb);
29403 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29406 + unsigned int sigen;
29407 + struct super_block *sb;
29410 + err = si_read_lock(sb, flags);
29411 + if (unlikely(err))
29414 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29416 + if (au_ftest_lock(flags, GEN)) {
29417 + sigen = au_sigen(sb);
29418 + err = au_digen_test(d1, sigen);
29419 + AuDebugOn(!err && au_dbrange_test(d1));
29421 + err = au_digen_test(d2, sigen);
29422 + AuDebugOn(!err && au_dbrange_test(d2));
29424 + if (unlikely(err))
29425 + aufs_read_and_write_unlock2(d1, d2);
29432 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29434 + di_write_unlock2(d1, d2);
29435 + si_read_unlock(d1->d_sb);
29437 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29438 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29439 +++ linux/fs/aufs/super.c 2020-01-27 10:57:18.178871751 +0100
29441 +// SPDX-License-Identifier: GPL-2.0
29443 + * Copyright (C) 2005-2020 Junjiro R. Okajima
29445 + * This program, aufs is free software; you can redistribute it and/or modify
29446 + * it under the terms of the GNU General Public License as published by
29447 + * the Free Software Foundation; either version 2 of the License, or
29448 + * (at your option) any later version.
29450 + * This program is distributed in the hope that it will be useful,
29451 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29452 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29453 + * GNU General Public License for more details.
29455 + * You should have received a copy of the GNU General Public License
29456 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29460 + * mount and super_block operations
29463 +#include <linux/iversion.h>
29464 +#include <linux/mm.h>
29465 +#include <linux/seq_file.h>
29466 +#include <linux/statfs.h>
29467 +#include <linux/vmalloc.h>
29471 + * super_operations
29473 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29475 + struct au_icntnr *c;
29477 + c = au_cache_alloc_icntnr();
29479 + au_icntnr_init(c);
29480 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29481 + c->iinfo.ii_hinode = NULL;
29482 + return &c->vfs_inode;
29487 +static void aufs_destroy_inode(struct inode *inode)
29489 + if (!au_is_bad_inode(inode))
29490 + au_iinfo_fin(inode);
29493 +static void aufs_free_inode(struct inode *inode)
29495 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29498 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29500 + struct inode *inode;
29503 + inode = iget_locked(sb, ino);
29504 + if (unlikely(!inode)) {
29505 + inode = ERR_PTR(-ENOMEM);
29508 + if (!(inode->i_state & I_NEW))
29511 + err = au_xigen_new(inode);
29513 + err = au_iinfo_init(inode);
29515 + inode_inc_iversion(inode);
29517 + iget_failed(inode);
29518 + inode = ERR_PTR(err);
29522 + /* never return NULL */
29523 + AuDebugOn(!inode);
29524 + AuTraceErrPtr(inode);
29528 +/* lock free root dinfo */
29529 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29532 + aufs_bindex_t bindex, bbot;
29533 + struct path path;
29534 + struct au_hdentry *hdp;
29535 + struct au_branch *br;
29536 + au_br_perm_str_t perm;
29539 + bbot = au_sbbot(sb);
29541 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29542 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29543 + br = au_sbr(sb, bindex);
29544 + path.mnt = au_br_mnt(br);
29545 + path.dentry = hdp->hd_dentry;
29546 + err = au_seq_path(seq, &path);
29548 + au_optstr_br_perm(&perm, br->br_perm);
29549 + seq_printf(seq, "=%s", perm.a);
29550 + if (bindex != bbot)
29551 + seq_putc(seq, ':');
29554 + if (unlikely(err || seq_has_overflowed(seq)))
29560 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29561 + const char *append)
29566 + while (*pat != ':')
29569 + strcpy(p, append);
29570 + AuDebugOn(strlen(fmt) >= len);
29573 +static void au_show_wbr_create(struct seq_file *m, int v,
29574 + struct au_sbinfo *sbinfo)
29578 + struct au_wbr_mfs *mfs;
29580 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29582 + seq_puts(m, ",create=");
29583 + pat = au_optstr_wbr_create(v);
29584 + mfs = &sbinfo->si_wbr_mfs;
29586 + case AuWbrCreate_TDP:
29587 + case AuWbrCreate_RR:
29588 + case AuWbrCreate_MFS:
29589 + case AuWbrCreate_PMFS:
29590 + seq_puts(m, pat);
29592 + case AuWbrCreate_MFSRR:
29593 + case AuWbrCreate_TDMFS:
29594 + case AuWbrCreate_PMFSRR:
29595 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29596 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29598 + case AuWbrCreate_MFSV:
29599 + case AuWbrCreate_PMFSV:
29600 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29601 + seq_printf(m, fmt,
29602 + jiffies_to_msecs(mfs->mfs_expire)
29605 + case AuWbrCreate_MFSRRV:
29606 + case AuWbrCreate_TDMFSV:
29607 + case AuWbrCreate_PMFSRRV:
29608 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29609 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29610 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29617 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29619 +#ifdef CONFIG_SYSFS
29623 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29624 + aufs_bindex_t bindex, brid;
29625 + struct qstr *name;
29627 + struct dentry *d, *h_root;
29628 + struct au_branch *br;
29630 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29633 + f = au_sbi(sb)->si_xib;
29637 + /* stop printing the default xino path on the first writable branch */
29639 + bindex = au_xi_root(sb, f->f_path.dentry);
29640 + if (bindex >= 0) {
29641 + br = au_sbr_sb(sb, bindex);
29642 + h_root = au_br_dentry(br);
29645 + d = f->f_path.dentry;
29646 + name = &d->d_name;
29647 + /* safe ->d_parent because the file is unlinked */
29648 + if (d->d_parent == h_root
29649 + && name->len == len
29650 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29653 + seq_puts(seq, ",xino=");
29654 + err = au_xino_path(seq, f);
29661 +/* seq_file will re-call me in case of too long string */
29662 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29665 + unsigned int mnt_flags, v;
29666 + struct super_block *sb;
29667 + struct au_sbinfo *sbinfo;
29669 +#define AuBool(name, str) do { \
29670 + v = au_opt_test(mnt_flags, name); \
29671 + if (v != au_opt_test(AuOpt_Def, name)) \
29672 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29675 +#define AuStr(name, str) do { \
29676 + v = mnt_flags & AuOptMask_##name; \
29677 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29678 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29681 +#define AuUInt(name, str, val) do { \
29682 + if (val != AUFS_##name##_DEF) \
29683 + seq_printf(m, "," #str "=%u", val); \
29686 + sb = dentry->d_sb;
29687 + if (sb->s_flags & SB_POSIXACL)
29688 + seq_puts(m, ",acl");
29689 +#if 0 /* reserved for future use */
29690 + if (sb->s_flags & SB_I_VERSION)
29691 + seq_puts(m, ",i_version");
29694 + /* lock free root dinfo */
29695 + si_noflush_read_lock(sb);
29696 + sbinfo = au_sbi(sb);
29697 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29699 + mnt_flags = au_mntflags(sb);
29700 + if (au_opt_test(mnt_flags, XINO)) {
29701 + err = au_show_xino(m, sb);
29702 + if (unlikely(err))
29705 + seq_puts(m, ",noxino");
29707 + AuBool(TRUNC_XINO, trunc_xino);
29708 + AuStr(UDBA, udba);
29709 + AuBool(SHWH, shwh);
29710 + AuBool(PLINK, plink);
29711 + AuBool(DIO, dio);
29712 + AuBool(DIRPERM1, dirperm1);
29714 + v = sbinfo->si_wbr_create;
29715 + if (v != AuWbrCreate_Def)
29716 + au_show_wbr_create(m, v, sbinfo);
29718 + v = sbinfo->si_wbr_copyup;
29719 + if (v != AuWbrCopyup_Def)
29720 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29722 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29723 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29724 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29726 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29728 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29729 + AuUInt(RDCACHE, rdcache, v);
29731 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29732 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29734 + au_fhsm_show(m, sbinfo);
29736 + AuBool(DIRREN, dirren);
29737 + AuBool(SUM, sum);
29738 + /* AuBool(SUM_W, wsum); */
29739 + AuBool(WARN_PERM, warn_perm);
29740 + AuBool(VERBOSE, verbose);
29743 + /* be sure to print "br:" last */
29744 + if (!sysaufs_brs) {
29745 + seq_puts(m, ",br:");
29746 + au_show_brs(m, sb);
29748 + si_read_unlock(sb);
29756 +/* ---------------------------------------------------------------------- */
29758 +/* sum mode which returns the summation for statfs(2) */
29760 +static u64 au_add_till_max(u64 a, u64 b)
29768 + return ULLONG_MAX;
29771 +static u64 au_mul_till_max(u64 a, long mul)
29779 + return ULLONG_MAX;
29782 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29785 + long bsize, factor;
29786 + u64 blocks, bfree, bavail, files, ffree;
29787 + aufs_bindex_t bbot, bindex, i;
29788 + unsigned char shared;
29789 + struct path h_path;
29790 + struct super_block *h_sb;
29793 + bsize = LONG_MAX;
29799 + bbot = au_sbbot(sb);
29800 + for (bindex = 0; bindex <= bbot; bindex++) {
29801 + h_path.mnt = au_sbr_mnt(sb, bindex);
29802 + h_sb = h_path.mnt->mnt_sb;
29804 + for (i = 0; !shared && i < bindex; i++)
29805 + shared = (au_sbr_sb(sb, i) == h_sb);
29809 + /* sb->s_root for NFS is unreliable */
29810 + h_path.dentry = h_path.mnt->mnt_root;
29811 + err = vfs_statfs(&h_path, buf);
29812 + if (unlikely(err))
29815 + if (bsize > buf->f_bsize) {
29817 + * we will reduce bsize, so we have to expand blocks
29818 + * etc. to match them again
29820 + factor = (bsize / buf->f_bsize);
29821 + blocks = au_mul_till_max(blocks, factor);
29822 + bfree = au_mul_till_max(bfree, factor);
29823 + bavail = au_mul_till_max(bavail, factor);
29824 + bsize = buf->f_bsize;
29827 + factor = (buf->f_bsize / bsize);
29828 + blocks = au_add_till_max(blocks,
29829 + au_mul_till_max(buf->f_blocks, factor));
29830 + bfree = au_add_till_max(bfree,
29831 + au_mul_till_max(buf->f_bfree, factor));
29832 + bavail = au_add_till_max(bavail,
29833 + au_mul_till_max(buf->f_bavail, factor));
29834 + files = au_add_till_max(files, buf->f_files);
29835 + ffree = au_add_till_max(ffree, buf->f_ffree);
29838 + buf->f_bsize = bsize;
29839 + buf->f_blocks = blocks;
29840 + buf->f_bfree = bfree;
29841 + buf->f_bavail = bavail;
29842 + buf->f_files = files;
29843 + buf->f_ffree = ffree;
29844 + buf->f_frsize = 0;
29850 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29853 + struct path h_path;
29854 + struct super_block *sb;
29856 + /* lock free root dinfo */
29857 + sb = dentry->d_sb;
29858 + si_noflush_read_lock(sb);
29859 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29860 + /* sb->s_root for NFS is unreliable */
29861 + h_path.mnt = au_sbr_mnt(sb, 0);
29862 + h_path.dentry = h_path.mnt->mnt_root;
29863 + err = vfs_statfs(&h_path, buf);
29865 + err = au_statfs_sum(sb, buf);
29866 + si_read_unlock(sb);
29869 + buf->f_type = AUFS_SUPER_MAGIC;
29870 + buf->f_namelen = AUFS_MAX_NAMELEN;
29871 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29873 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29878 +/* ---------------------------------------------------------------------- */
29880 +static int aufs_sync_fs(struct super_block *sb, int wait)
29883 + aufs_bindex_t bbot, bindex;
29884 + struct au_branch *br;
29885 + struct super_block *h_sb;
29888 + si_noflush_read_lock(sb);
29889 + bbot = au_sbbot(sb);
29890 + for (bindex = 0; bindex <= bbot; bindex++) {
29891 + br = au_sbr(sb, bindex);
29892 + if (!au_br_writable(br->br_perm))
29895 + h_sb = au_sbr_sb(sb, bindex);
29896 + e = vfsub_sync_filesystem(h_sb, wait);
29897 + if (unlikely(e && !err))
29899 + /* go on even if an error happens */
29901 + si_read_unlock(sb);
29906 +/* ---------------------------------------------------------------------- */
29908 +/* final actions when unmounting a file system */
29909 +static void aufs_put_super(struct super_block *sb)
29911 + struct au_sbinfo *sbinfo;
29913 + sbinfo = au_sbi(sb);
29915 + kobject_put(&sbinfo->si_kobj);
29918 +/* ---------------------------------------------------------------------- */
29920 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29921 + struct super_block *sb, void *arg)
29924 + unsigned long long n, sz;
29931 + if (*hint > ULLONG_MAX / sizeof(array)) {
29932 + array = ERR_PTR(-EMFILE);
29933 + pr_err("hint %llu\n", *hint);
29937 + sz = sizeof(array) * *hint;
29938 + array = kzalloc(sz, GFP_NOFS);
29939 + if (unlikely(!array))
29940 + array = vzalloc(sz);
29941 + if (unlikely(!array)) {
29942 + array = ERR_PTR(-ENOMEM);
29946 + n = cb(sb, array, *hint, arg);
29947 + AuDebugOn(n > *hint);
29954 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29955 + unsigned long long max __maybe_unused,
29958 + unsigned long long n;
29959 + struct inode **p, *inode;
29960 + struct list_head *head;
29965 + spin_lock(&sb->s_inode_list_lock);
29966 + list_for_each_entry(inode, head, i_sb_list) {
29967 + if (!au_is_bad_inode(inode)
29968 + && au_ii(inode)->ii_btop >= 0) {
29969 + spin_lock(&inode->i_lock);
29970 + if (atomic_read(&inode->i_count)) {
29974 + AuDebugOn(n > max);
29976 + spin_unlock(&inode->i_lock);
29979 + spin_unlock(&sb->s_inode_list_lock);
29984 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
29986 + struct au_sbinfo *sbi;
29988 + sbi = au_sbi(sb);
29989 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
29990 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
29993 +void au_iarray_free(struct inode **a, unsigned long long max)
29995 + unsigned long long ull;
29997 + for (ull = 0; ull < max; ull++)
30002 +/* ---------------------------------------------------------------------- */
30005 + * refresh dentry and inode at remount time.
30007 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30008 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30009 + struct dentry *parent)
30013 + di_write_lock_child(dentry);
30014 + di_read_lock_parent(parent, AuLock_IR);
30015 + err = au_refresh_dentry(dentry, parent);
30016 + if (!err && dir_flags)
30017 + au_hn_reset(d_inode(dentry), dir_flags);
30018 + di_read_unlock(parent, AuLock_IR);
30019 + di_write_unlock(dentry);
30024 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30025 + struct au_sbinfo *sbinfo,
30026 + const unsigned int dir_flags, unsigned int do_idop)
30029 + struct dentry *parent;
30032 + parent = dget_parent(dentry);
30033 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30034 + if (d_really_is_positive(dentry)) {
30035 + if (!d_is_dir(dentry))
30036 + err = au_do_refresh(dentry, /*dir_flags*/0,
30039 + err = au_do_refresh(dentry, dir_flags, parent);
30040 + if (unlikely(err))
30041 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30044 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30045 + AuDbgDentry(dentry);
30051 + au_refresh_dop(dentry, /*force_reval*/0);
30053 + au_refresh_dop(dentry, /*force_reval*/1);
30059 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30061 + int err, i, j, ndentry, e;
30062 + unsigned int sigen;
30063 + struct au_dcsub_pages dpages;
30064 + struct au_dpage *dpage;
30065 + struct dentry **dentries, *d;
30066 + struct au_sbinfo *sbinfo;
30067 + struct dentry *root = sb->s_root;
30068 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30071 + au_refresh_dop(root, /*force_reval*/0);
30073 + err = au_dpages_init(&dpages, GFP_NOFS);
30074 + if (unlikely(err))
30076 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30077 + if (unlikely(err))
30080 + sigen = au_sigen(sb);
30081 + sbinfo = au_sbi(sb);
30082 + for (i = 0; i < dpages.ndpage; i++) {
30083 + dpage = dpages.dpages + i;
30084 + dentries = dpage->dentries;
30085 + ndentry = dpage->ndentry;
30086 + for (j = 0; j < ndentry; j++) {
30088 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30090 + if (unlikely(e && !err))
30092 + /* go on even err */
30097 + au_dpages_free(&dpages);
30102 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30105 + unsigned int sigen;
30106 + unsigned long long max, ull;
30107 + struct inode *inode, **array;
30109 + array = au_iarray_alloc(sb, &max);
30110 + err = PTR_ERR(array);
30111 + if (IS_ERR(array))
30115 + sigen = au_sigen(sb);
30116 + for (ull = 0; ull < max; ull++) {
30117 + inode = array[ull];
30118 + if (unlikely(!inode))
30122 + ii_write_lock_child(inode);
30123 + if (au_iigen(inode, NULL) != sigen) {
30124 + e = au_refresh_hinode_self(inode);
30125 + if (unlikely(e)) {
30126 + au_refresh_iop(inode, /*force_getattr*/1);
30127 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30130 + /* go on even if err */
30133 + if (!e && do_idop)
30134 + au_refresh_iop(inode, /*force_getattr*/0);
30135 + ii_write_unlock(inode);
30138 + au_iarray_free(array, max);
30144 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30147 + unsigned int udba;
30148 + aufs_bindex_t bindex, bbot;
30149 + struct dentry *root;
30150 + struct inode *inode;
30151 + struct au_branch *br;
30152 + struct au_sbinfo *sbi;
30154 + au_sigen_inc(sb);
30155 + sbi = au_sbi(sb);
30156 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30158 + root = sb->s_root;
30159 + DiMustNoWaiters(root);
30160 + inode = d_inode(root);
30161 + IiMustNoWaiters(inode);
30163 + udba = au_opt_udba(sb);
30164 + bbot = au_sbbot(sb);
30165 + for (bindex = 0; bindex <= bbot; bindex++) {
30166 + br = au_sbr(sb, bindex);
30167 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30168 + if (unlikely(err))
30169 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30171 + /* go on even if err */
30173 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30176 + if (au_ftest_si(sbi, NO_DREVAL)) {
30177 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30178 + sb->s_d_op = &aufs_dop_noreval;
30179 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30180 + sbi->si_iop_array = aufs_iop_nogetattr;
30182 + AuDebugOn(sb->s_d_op == &aufs_dop);
30183 + sb->s_d_op = &aufs_dop;
30184 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30185 + sbi->si_iop_array = aufs_iop;
30187 + pr_info("reset to %ps and %ps\n",
30188 + sb->s_d_op, sbi->si_iop_array);
30191 + di_write_unlock(root);
30192 + err = au_refresh_d(sb, do_idop);
30193 + e = au_refresh_i(sb, do_idop);
30194 + if (unlikely(e && !err))
30196 + /* aufs_write_lock() calls ..._child() */
30197 + di_write_lock_child(root);
30199 + au_cpup_attr_all(inode, /*force*/1);
30201 + if (unlikely(err))
30202 + AuIOErr("refresh failed, ignored, %d\n", err);
30205 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30206 +static int cvt_err(int err)
30220 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30223 + unsigned int mntflags;
30224 + struct au_opts opts = {
30227 + struct dentry *root;
30228 + struct inode *inode;
30229 + struct au_sbinfo *sbinfo;
30232 + root = sb->s_root;
30233 + if (!data || !*data) {
30234 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30236 + di_write_lock_child(root);
30237 + err = au_opts_verify(sb, *flags, /*pending*/0);
30238 + aufs_write_unlock(root);
30244 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30245 + if (unlikely(!opts.opt))
30247 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30248 + opts.flags = AuOpts_REMOUNT;
30249 + opts.sb_flags = *flags;
30251 + /* parse it before aufs lock */
30252 + err = au_opts_parse(sb, data, &opts);
30253 + if (unlikely(err))
30256 + sbinfo = au_sbi(sb);
30257 + inode = d_inode(root);
30258 + inode_lock(inode);
30259 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30260 + if (unlikely(err))
30262 + di_write_lock_child(root);
30264 + /* au_opts_remount() may return an error */
30265 + err = au_opts_remount(sb, &opts);
30266 + au_opts_free(&opts);
30268 + if (au_ftest_opts(opts.flags, REFRESH))
30269 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30271 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30272 + mntflags = au_mntflags(sb);
30273 + do_dx = !!au_opt_test(mntflags, DIO);
30274 + au_dy_arefresh(do_dx);
30277 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30278 + aufs_write_unlock(root);
30281 + inode_unlock(inode);
30283 + free_page((unsigned long)opts.opt);
30285 + err = cvt_err(err);
30290 +static const struct super_operations aufs_sop = {
30291 + .alloc_inode = aufs_alloc_inode,
30292 + .destroy_inode = aufs_destroy_inode,
30293 + .free_inode = aufs_free_inode,
30294 + /* always deleting, no clearing */
30295 + .drop_inode = generic_delete_inode,
30296 + .show_options = aufs_show_options,
30297 + .statfs = aufs_statfs,
30298 + .put_super = aufs_put_super,
30299 + .sync_fs = aufs_sync_fs,
30300 + .remount_fs = aufs_remount_fs
30303 +/* ---------------------------------------------------------------------- */
30305 +static int alloc_root(struct super_block *sb)
30308 + struct inode *inode;
30309 + struct dentry *root;
30312 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30313 + err = PTR_ERR(inode);
30314 + if (IS_ERR(inode))
30317 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30318 + inode->i_fop = &aufs_dir_fop;
30319 + inode->i_mode = S_IFDIR;
30320 + set_nlink(inode, 2);
30321 + unlock_new_inode(inode);
30323 + root = d_make_root(inode);
30324 + if (unlikely(!root))
30326 + err = PTR_ERR(root);
30327 + if (IS_ERR(root))
30330 + err = au_di_init(root);
30332 + sb->s_root = root;
30333 + return 0; /* success */
30341 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30342 + int silent __maybe_unused)
30345 + struct au_opts opts = {
30348 + struct au_sbinfo *sbinfo;
30349 + struct dentry *root;
30350 + struct inode *inode;
30351 + char *arg = raw_data;
30353 + if (unlikely(!arg || !*arg)) {
30355 + pr_err("no arg\n");
30360 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30361 + if (unlikely(!opts.opt))
30363 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30364 + opts.sb_flags = sb->s_flags;
30366 + err = au_si_alloc(sb);
30367 + if (unlikely(err))
30369 + sbinfo = au_sbi(sb);
30371 + /* all timestamps always follow the ones on the branch */
30372 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30373 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30374 + sb->s_op = &aufs_sop;
30375 + sb->s_d_op = &aufs_dop;
30376 + sb->s_magic = AUFS_SUPER_MAGIC;
30377 + sb->s_maxbytes = 0;
30378 + sb->s_stack_depth = 1;
30379 + au_export_init(sb);
30380 + au_xattr_init(sb);
30382 + err = alloc_root(sb);
30383 + if (unlikely(err)) {
30384 + si_write_unlock(sb);
30387 + root = sb->s_root;
30388 + inode = d_inode(root);
30391 + * actually we can parse options regardless aufs lock here.
30392 + * but at remount time, parsing must be done before aufs lock.
30393 + * so we follow the same rule.
30395 + ii_write_lock_parent(inode);
30396 + aufs_write_unlock(root);
30397 + err = au_opts_parse(sb, arg, &opts);
30398 + if (unlikely(err))
30401 + /* lock vfs_inode first, then aufs. */
30402 + inode_lock(inode);
30403 + aufs_write_lock(root);
30404 + err = au_opts_mount(sb, &opts);
30405 + au_opts_free(&opts);
30406 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30407 + sb->s_d_op = &aufs_dop_noreval;
30408 + pr_info("%ps\n", sb->s_d_op);
30409 + au_refresh_dop(root, /*force_reval*/0);
30410 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30411 + au_refresh_iop(inode, /*force_getattr*/0);
30413 + aufs_write_unlock(root);
30414 + inode_unlock(inode);
30416 + goto out_opts; /* success */
30420 + sb->s_root = NULL;
30422 + kobject_put(&sbinfo->si_kobj);
30423 + sb->s_fs_info = NULL;
30425 + free_page((unsigned long)opts.opt);
30428 + err = cvt_err(err);
30433 +/* ---------------------------------------------------------------------- */
30435 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30436 + const char *dev_name __maybe_unused,
30439 + struct dentry *root;
30441 + /* all timestamps always follow the ones on the branch */
30442 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30443 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30444 + if (IS_ERR(root))
30447 + au_sbilist_add(root->d_sb);
30453 +static void aufs_kill_sb(struct super_block *sb)
30455 + struct au_sbinfo *sbinfo;
30457 + sbinfo = au_sbi(sb);
30459 + au_sbilist_del(sb);
30460 + aufs_write_lock(sb->s_root);
30462 + if (sbinfo->si_wbr_create_ops->fin)
30463 + sbinfo->si_wbr_create_ops->fin(sb);
30464 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30465 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30466 + au_remount_refresh(sb, /*do_idop*/0);
30468 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30469 + au_plink_put(sb, /*verbose*/1);
30471 + au_dr_opt_flush(sb);
30472 + sbinfo->si_sb = NULL;
30473 + aufs_write_unlock(sb->s_root);
30474 + au_nwt_flush(&sbinfo->si_nowait);
30476 + kill_anon_super(sb);
30479 +struct file_system_type aufs_fs_type = {
30480 + .name = AUFS_FSTYPE,
30481 + /* a race between rename and others */
30482 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30483 + .mount = aufs_mount,
30484 + .kill_sb = aufs_kill_sb,
30485 + /* no need to __module_get() and module_put(). */
30486 + .owner = THIS_MODULE,
30488 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30489 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30490 +++ linux/fs/aufs/super.h 2020-01-27 10:57:18.178871751 +0100
30492 +/* SPDX-License-Identifier: GPL-2.0 */
30494 + * Copyright (C) 2005-2020 Junjiro R. Okajima
30496 + * This program, aufs is free software; you can redistribute it and/or modify
30497 + * it under the terms of the GNU General Public License as published by
30498 + * the Free Software Foundation; either version 2 of the License, or
30499 + * (at your option) any later version.
30501 + * This program is distributed in the hope that it will be useful,
30502 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30503 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30504 + * GNU General Public License for more details.
30506 + * You should have received a copy of the GNU General Public License
30507 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30511 + * super_block operations
30514 +#ifndef __AUFS_SUPER_H__
30515 +#define __AUFS_SUPER_H__
30519 +#include <linux/fs.h>
30520 +#include <linux/kobject.h>
30523 +#include "rwsem.h"
30526 +/* policies to select one among multiple writable branches */
30527 +struct au_wbr_copyup_operations {
30528 + int (*copyup)(struct dentry *dentry);
30531 +#define AuWbr_DIR 1 /* target is a dir */
30532 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30534 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30535 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30536 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30538 +struct au_wbr_create_operations {
30539 + int (*create)(struct dentry *dentry, unsigned int flags);
30540 + int (*init)(struct super_block *sb);
30541 + int (*fin)(struct super_block *sb);
30544 +struct au_wbr_mfs {
30545 + struct mutex mfs_lock; /* protect this structure */
30546 + unsigned long mfs_jiffy;
30547 + unsigned long mfs_expire;
30548 + aufs_bindex_t mfs_bindex;
30550 + unsigned long long mfsrr_bytes;
30551 + unsigned long long mfsrr_watermark;
30554 +#define AuPlink_NHASH 100
30555 +static inline int au_plink_hash(ino_t ino)
30557 + return ino % AuPlink_NHASH;
30560 +/* File-based Hierarchical Storage Management */
30562 +#ifdef CONFIG_AUFS_FHSM
30563 + /* allow only one process who can receive the notification */
30564 + spinlock_t fhsm_spin;
30566 + wait_queue_head_t fhsm_wqh;
30567 + atomic_t fhsm_readable;
30569 + /* these are protected by si_rwsem */
30570 + unsigned long fhsm_expire;
30571 + aufs_bindex_t fhsm_bottom;
30576 +struct au_sbinfo {
30577 + /* nowait tasks in the system-wide workqueue */
30578 + struct au_nowait_tasks si_nowait;
30581 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30582 + * rwsem for au_sbinfo is necessary.
30584 + struct au_rwsem si_rwsem;
30587 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30590 + au_lcnt_t si_ninodes, si_nfiles;
30592 + /* branch management */
30593 + unsigned int si_generation;
30595 + /* see AuSi_ flags */
30596 + unsigned char au_si_status;
30598 + aufs_bindex_t si_bbot;
30600 + /* dirty trick to keep br_id plus */
30601 + unsigned int si_last_br_id :
30602 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30603 + struct au_branch **si_branch;
30605 + /* policy to select a writable branch */
30606 + unsigned char si_wbr_copyup;
30607 + unsigned char si_wbr_create;
30608 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30609 + struct au_wbr_create_operations *si_wbr_create_ops;
30611 + /* round robin */
30612 + atomic_t si_wbr_rr_next;
30614 + /* most free space */
30615 + struct au_wbr_mfs si_wbr_mfs;
30617 + /* File-based Hierarchical Storage Management */
30618 + struct au_fhsm si_fhsm;
30620 + /* mount flags */
30621 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30622 + unsigned int si_mntflags;
30624 + /* external inode number (bitmap and translation table) */
30625 + vfs_readf_t si_xread;
30626 + vfs_writef_t si_xwrite;
30627 + loff_t si_ximaxent; /* max entries in a xino */
30629 + struct file *si_xib;
30630 + struct mutex si_xib_mtx; /* protect xib members */
30631 + unsigned long *si_xib_buf;
30632 + unsigned long si_xib_last_pindex;
30633 + int si_xib_next_bit;
30635 + unsigned long si_xino_jiffy;
30636 + unsigned long si_xino_expire;
30637 + /* reserved for future use */
30638 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30640 +#ifdef CONFIG_AUFS_EXPORT
30641 + /* i_generation */
30642 + /* todo: make xigen file an array to support many inode numbers */
30643 + struct file *si_xigen;
30644 + atomic_t si_xigen_next;
30647 + /* dirty trick to support atomic_open */
30648 + struct hlist_bl_head si_aopen;
30650 + /* vdir parameters */
30651 + unsigned long si_rdcache; /* max cache time in jiffies */
30652 + unsigned int si_rdblk; /* deblk size */
30653 + unsigned int si_rdhash; /* hash size */
30656 + * If the number of whiteouts are larger than si_dirwh, leave all of
30657 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30658 + * future fsck.aufs or kernel thread will remove them later.
30659 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30661 + unsigned int si_dirwh;
30663 + /* pseudo_link list */
30664 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30665 + wait_queue_head_t si_plink_wq;
30666 + spinlock_t si_plink_maint_lock;
30667 + pid_t si_plink_maint_pid;
30670 + struct hlist_bl_head si_files;
30672 + /* with/without getattr, brother of sb->s_d_op */
30673 + const struct inode_operations *si_iop_array;
30676 + * sysfs and lifetime management.
30677 + * this is not a small structure and it may be a waste of memory in case
30678 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30679 + * but using sysfs is majority.
30681 + struct kobject si_kobj;
30682 +#ifdef CONFIG_DEBUG_FS
30683 + struct dentry *si_dbgaufs;
30684 + struct dentry *si_dbgaufs_plink;
30685 + struct dentry *si_dbgaufs_xib;
30686 +#ifdef CONFIG_AUFS_EXPORT
30687 + struct dentry *si_dbgaufs_xigen;
30691 +#ifdef CONFIG_AUFS_SBILIST
30692 + struct hlist_bl_node si_list;
30695 + /* dirty, necessary for unmounting, sysfs and sysrq */
30696 + struct super_block *si_sb;
30699 +/* sbinfo status flags */
30701 + * set true when refresh_dirs() failed at remount time.
30702 + * then try refreshing dirs at access time again.
30703 + * if it is false, refreshing dirs at access time is unnecessary
30705 +#define AuSi_FAILED_REFRESH_DIR 1
30706 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30707 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30709 +#ifndef CONFIG_AUFS_FHSM
30711 +#define AuSi_FHSM 0
30714 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30715 + unsigned int flag)
30717 + AuRwMustAnyLock(&sbi->si_rwsem);
30718 + return sbi->au_si_status & flag;
30720 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30721 +#define au_fset_si(sbinfo, name) do { \
30722 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30723 + (sbinfo)->au_si_status |= AuSi_##name; \
30725 +#define au_fclr_si(sbinfo, name) do { \
30726 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30727 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30730 +/* ---------------------------------------------------------------------- */
30732 +/* policy to select one among writable branches */
30733 +#define AuWbrCopyup(sbinfo, ...) \
30734 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30735 +#define AuWbrCreate(sbinfo, ...) \
30736 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30738 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30739 +#define AuLock_DW 1 /* write-lock dentry */
30740 +#define AuLock_IR (1 << 1) /* read-lock inode */
30741 +#define AuLock_IW (1 << 2) /* write-lock inode */
30742 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30743 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30744 + /* except RENAME_EXCHANGE */
30745 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30746 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30747 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30748 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30749 +#define au_fset_lock(flags, name) \
30750 + do { (flags) |= AuLock_##name; } while (0)
30751 +#define au_fclr_lock(flags, name) \
30752 + do { (flags) &= ~AuLock_##name; } while (0)
30754 +/* ---------------------------------------------------------------------- */
30757 +extern struct file_system_type aufs_fs_type;
30758 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30759 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30760 + unsigned long long max, void *arg);
30761 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30762 + struct super_block *sb, void *arg);
30763 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30764 +void au_iarray_free(struct inode **a, unsigned long long max);
30767 +void au_si_free(struct kobject *kobj);
30768 +int au_si_alloc(struct super_block *sb);
30769 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30771 +unsigned int au_sigen_inc(struct super_block *sb);
30772 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30774 +int si_read_lock(struct super_block *sb, int flags);
30775 +int si_write_lock(struct super_block *sb, int flags);
30776 +int aufs_read_lock(struct dentry *dentry, int flags);
30777 +void aufs_read_unlock(struct dentry *dentry, int flags);
30778 +void aufs_write_lock(struct dentry *dentry);
30779 +void aufs_write_unlock(struct dentry *dentry);
30780 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30781 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30783 +/* wbr_policy.c */
30784 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30785 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30786 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30787 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30788 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30791 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30793 +#ifdef CONFIG_AUFS_FHSM
30796 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30800 + spin_lock(&fhsm->fhsm_spin);
30801 + pid = fhsm->fhsm_pid;
30802 + spin_unlock(&fhsm->fhsm_spin);
30807 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30808 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30809 +int au_fhsm_fd(struct super_block *sb, int oflags);
30810 +int au_fhsm_br_alloc(struct au_branch *br);
30811 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30812 +void au_fhsm_fin(struct super_block *sb);
30813 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30814 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30815 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30817 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30819 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30820 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30821 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30822 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30823 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30824 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30825 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30826 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30827 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30830 +/* ---------------------------------------------------------------------- */
30832 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30834 + return sb->s_fs_info;
30837 +/* ---------------------------------------------------------------------- */
30839 +#ifdef CONFIG_AUFS_EXPORT
30840 +int au_test_nfsd(void);
30841 +void au_export_init(struct super_block *sb);
30842 +void au_xigen_inc(struct inode *inode);
30843 +int au_xigen_new(struct inode *inode);
30844 +int au_xigen_set(struct super_block *sb, struct path *path);
30845 +void au_xigen_clr(struct super_block *sb);
30847 +static inline int au_busy_or_stale(void)
30849 + if (!au_test_nfsd())
30854 +AuStubInt0(au_test_nfsd, void)
30855 +AuStubVoid(au_export_init, struct super_block *sb)
30856 +AuStubVoid(au_xigen_inc, struct inode *inode)
30857 +AuStubInt0(au_xigen_new, struct inode *inode)
30858 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30859 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30860 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30861 +#endif /* CONFIG_AUFS_EXPORT */
30863 +/* ---------------------------------------------------------------------- */
30865 +#ifdef CONFIG_AUFS_SBILIST
30867 +extern struct hlist_bl_head au_sbilist;
30869 +static inline void au_sbilist_init(void)
30871 + INIT_HLIST_BL_HEAD(&au_sbilist);
30874 +static inline void au_sbilist_add(struct super_block *sb)
30876 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30879 +static inline void au_sbilist_del(struct super_block *sb)
30881 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30884 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30885 +static inline void au_sbilist_lock(void)
30887 + hlist_bl_lock(&au_sbilist);
30890 +static inline void au_sbilist_unlock(void)
30892 + hlist_bl_unlock(&au_sbilist);
30894 +#define AuGFP_SBILIST GFP_ATOMIC
30896 +AuStubVoid(au_sbilist_lock, void)
30897 +AuStubVoid(au_sbilist_unlock, void)
30898 +#define AuGFP_SBILIST GFP_NOFS
30899 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30901 +AuStubVoid(au_sbilist_init, void)
30902 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30903 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30904 +AuStubVoid(au_sbilist_lock, void)
30905 +AuStubVoid(au_sbilist_unlock, void)
30906 +#define AuGFP_SBILIST GFP_NOFS
30909 +/* ---------------------------------------------------------------------- */
30911 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30914 + * This function is a dynamic '__init' function actually,
30915 + * so the tiny check for si_rwsem is unnecessary.
30917 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30918 +#ifdef CONFIG_DEBUG_FS
30919 + sbinfo->si_dbgaufs = NULL;
30920 + sbinfo->si_dbgaufs_plink = NULL;
30921 + sbinfo->si_dbgaufs_xib = NULL;
30922 +#ifdef CONFIG_AUFS_EXPORT
30923 + sbinfo->si_dbgaufs_xigen = NULL;
30928 +/* ---------------------------------------------------------------------- */
30930 +/* current->atomic_flags */
30931 +/* this value should never corrupt the ones defined in linux/sched.h */
30932 +#define PFA_AUFS 0x10
30934 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30935 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30936 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30938 +static inline int si_pid_test(struct super_block *sb)
30940 + return !!task_test_aufs(current);
30943 +static inline void si_pid_clr(struct super_block *sb)
30945 + AuDebugOn(!task_test_aufs(current));
30946 + task_clear_aufs(current);
30949 +static inline void si_pid_set(struct super_block *sb)
30951 + AuDebugOn(task_test_aufs(current));
30952 + task_set_aufs(current);
30955 +/* ---------------------------------------------------------------------- */
30957 +/* lock superblock. mainly for entry point functions */
30958 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
30959 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
30960 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
30961 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
30963 +#define __si_read_trylock_nested(sb) \
30964 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
30965 +#define __si_write_trylock_nested(sb) \
30966 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
30969 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
30970 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
30971 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
30973 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30974 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30975 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30977 +static inline void si_noflush_read_lock(struct super_block *sb)
30979 + __si_read_lock(sb);
30983 +static inline int si_noflush_read_trylock(struct super_block *sb)
30987 + locked = __si_read_trylock(sb);
30993 +static inline void si_noflush_write_lock(struct super_block *sb)
30995 + __si_write_lock(sb);
30999 +static inline int si_noflush_write_trylock(struct super_block *sb)
31003 + locked = __si_write_trylock(sb);
31009 +#if 0 /* reserved */
31010 +static inline int si_read_trylock(struct super_block *sb, int flags)
31012 + if (au_ftest_lock(flags, FLUSH))
31013 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31014 + return si_noflush_read_trylock(sb);
31018 +static inline void si_read_unlock(struct super_block *sb)
31021 + __si_read_unlock(sb);
31024 +#if 0 /* reserved */
31025 +static inline int si_write_trylock(struct super_block *sb, int flags)
31027 + if (au_ftest_lock(flags, FLUSH))
31028 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31029 + return si_noflush_write_trylock(sb);
31033 +static inline void si_write_unlock(struct super_block *sb)
31036 + __si_write_unlock(sb);
31039 +#if 0 /* reserved */
31040 +static inline void si_downgrade_lock(struct super_block *sb)
31042 + __si_downgrade_lock(sb);
31046 +/* ---------------------------------------------------------------------- */
31048 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31050 + SiMustAnyLock(sb);
31051 + return au_sbi(sb)->si_bbot;
31054 +static inline unsigned int au_mntflags(struct super_block *sb)
31056 + SiMustAnyLock(sb);
31057 + return au_sbi(sb)->si_mntflags;
31060 +static inline unsigned int au_sigen(struct super_block *sb)
31062 + SiMustAnyLock(sb);
31063 + return au_sbi(sb)->si_generation;
31066 +static inline struct au_branch *au_sbr(struct super_block *sb,
31067 + aufs_bindex_t bindex)
31069 + SiMustAnyLock(sb);
31070 + return au_sbi(sb)->si_branch[0 + bindex];
31073 +static inline loff_t au_xi_maxent(struct super_block *sb)
31075 + SiMustAnyLock(sb);
31076 + return au_sbi(sb)->si_ximaxent;
31079 +#endif /* __KERNEL__ */
31080 +#endif /* __AUFS_SUPER_H__ */
31081 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31082 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31083 +++ linux/fs/aufs/sysaufs.c 2020-01-27 10:57:18.178871751 +0100
31085 +// SPDX-License-Identifier: GPL-2.0
31087 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31089 + * This program, aufs is free software; you can redistribute it and/or modify
31090 + * it under the terms of the GNU General Public License as published by
31091 + * the Free Software Foundation; either version 2 of the License, or
31092 + * (at your option) any later version.
31094 + * This program is distributed in the hope that it will be useful,
31095 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31096 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31097 + * GNU General Public License for more details.
31099 + * You should have received a copy of the GNU General Public License
31100 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31104 + * sysfs interface and lifetime management
31105 + * they are necessary regardless sysfs is disabled.
31108 +#include <linux/random.h>
31111 +unsigned long sysaufs_si_mask;
31112 +struct kset *sysaufs_kset;
31114 +#define AuSiAttr(_name) { \
31115 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31116 + .show = sysaufs_si_##_name, \
31119 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31120 +struct attribute *sysaufs_si_attrs[] = {
31121 + &sysaufs_si_attr_xi_path.attr,
31125 +static const struct sysfs_ops au_sbi_ops = {
31126 + .show = sysaufs_si_show
31129 +static struct kobj_type au_sbi_ktype = {
31130 + .release = au_si_free,
31131 + .sysfs_ops = &au_sbi_ops,
31132 + .default_attrs = sysaufs_si_attrs
31135 +/* ---------------------------------------------------------------------- */
31137 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31141 + sbinfo->si_kobj.kset = sysaufs_kset;
31142 + /* cf. sysaufs_name() */
31143 + err = kobject_init_and_add
31144 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31145 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31150 +void sysaufs_fin(void)
31152 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31153 + kset_unregister(sysaufs_kset);
31156 +int __init sysaufs_init(void)
31161 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31162 + } while (!sysaufs_si_mask);
31165 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31166 + if (unlikely(!sysaufs_kset))
31168 + err = PTR_ERR(sysaufs_kset);
31169 + if (IS_ERR(sysaufs_kset))
31171 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31172 + if (unlikely(err))
31173 + kset_unregister(sysaufs_kset);
31178 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31179 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31180 +++ linux/fs/aufs/sysaufs.h 2020-01-27 10:57:18.178871751 +0100
31182 +/* SPDX-License-Identifier: GPL-2.0 */
31184 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31186 + * This program, aufs is free software; you can redistribute it and/or modify
31187 + * it under the terms of the GNU General Public License as published by
31188 + * the Free Software Foundation; either version 2 of the License, or
31189 + * (at your option) any later version.
31191 + * This program is distributed in the hope that it will be useful,
31192 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31193 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31194 + * GNU General Public License for more details.
31196 + * You should have received a copy of the GNU General Public License
31197 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31201 + * sysfs interface and mount lifetime management
31204 +#ifndef __SYSAUFS_H__
31205 +#define __SYSAUFS_H__
31209 +#include <linux/sysfs.h>
31210 +#include "module.h"
31212 +struct super_block;
31215 +struct sysaufs_si_attr {
31216 + struct attribute attr;
31217 + int (*show)(struct seq_file *seq, struct super_block *sb);
31220 +/* ---------------------------------------------------------------------- */
31223 +extern unsigned long sysaufs_si_mask;
31224 +extern struct kset *sysaufs_kset;
31225 +extern struct attribute *sysaufs_si_attrs[];
31226 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31227 +int __init sysaufs_init(void);
31228 +void sysaufs_fin(void);
31230 +/* ---------------------------------------------------------------------- */
31232 +/* some people doesn't like to show a pointer in kernel */
31233 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31235 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31238 +#define SysaufsSiNamePrefix "si_"
31239 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31240 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31242 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31243 + sysaufs_si_id(sbinfo));
31247 +#ifdef CONFIG_SYSFS
31249 +extern struct attribute_group *sysaufs_attr_group;
31251 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31252 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31254 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31255 +#ifdef CONFIG_COMPAT
31256 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31259 +void sysaufs_br_init(struct au_branch *br);
31260 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31261 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31263 +#define sysaufs_brs_init() do {} while (0)
31266 +#define sysaufs_attr_group NULL
31268 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31269 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31270 + struct attribute *attr, char *buf)
31271 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31272 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31273 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31275 +static inline void sysaufs_brs_init(void)
31280 +#endif /* CONFIG_SYSFS */
31282 +#endif /* __KERNEL__ */
31283 +#endif /* __SYSAUFS_H__ */
31284 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31285 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31286 +++ linux/fs/aufs/sysfs.c 2020-01-27 10:57:18.178871751 +0100
31288 +// SPDX-License-Identifier: GPL-2.0
31290 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31292 + * This program, aufs is free software; you can redistribute it and/or modify
31293 + * it under the terms of the GNU General Public License as published by
31294 + * the Free Software Foundation; either version 2 of the License, or
31295 + * (at your option) any later version.
31297 + * This program is distributed in the hope that it will be useful,
31298 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31299 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31300 + * GNU General Public License for more details.
31302 + * You should have received a copy of the GNU General Public License
31303 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31307 + * sysfs interface
31310 +#include <linux/compat.h>
31311 +#include <linux/seq_file.h>
31314 +#ifdef CONFIG_AUFS_FS_MODULE
31315 +/* this entry violates the "one line per file" policy of sysfs */
31316 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31320 + static char *conf =
31321 +/* this file is generated at compiling */
31322 +#include "conf.str"
31325 + err = snprintf(buf, PAGE_SIZE, conf);
31326 + if (unlikely(err >= PAGE_SIZE))
31331 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31334 +static struct attribute *au_attr[] = {
31335 +#ifdef CONFIG_AUFS_FS_MODULE
31336 + &au_config_attr.attr,
31338 + NULL, /* need to NULL terminate the list of attributes */
31341 +static struct attribute_group sysaufs_attr_group_body = {
31345 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31347 +/* ---------------------------------------------------------------------- */
31349 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31353 + SiMustAnyLock(sb);
31356 + if (au_opt_test(au_mntflags(sb), XINO)) {
31357 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31358 + seq_putc(seq, '\n');
31364 + * the lifetime of branch is independent from the entry under sysfs.
31365 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31368 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31369 + aufs_bindex_t bindex, int idx)
31372 + struct path path;
31373 + struct dentry *root;
31374 + struct au_branch *br;
31375 + au_br_perm_str_t perm;
31377 + AuDbg("b%d\n", bindex);
31380 + root = sb->s_root;
31381 + di_read_lock_parent(root, !AuLock_IR);
31382 + br = au_sbr(sb, bindex);
31385 + case AuBrSysfs_BR:
31386 + path.mnt = au_br_mnt(br);
31387 + path.dentry = au_h_dptr(root, bindex);
31388 + err = au_seq_path(seq, &path);
31390 + au_optstr_br_perm(&perm, br->br_perm);
31391 + seq_printf(seq, "=%s\n", perm.a);
31394 + case AuBrSysfs_BRID:
31395 + seq_printf(seq, "%d\n", br->br_id);
31398 + di_read_unlock(root, !AuLock_IR);
31399 + if (unlikely(err || seq_has_overflowed(seq)))
31405 +/* ---------------------------------------------------------------------- */
31407 +static struct seq_file *au_seq(char *p, ssize_t len)
31409 + struct seq_file *seq;
31411 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31413 + /* mutex_init(&seq.lock); */
31416 + return seq; /* success */
31419 + seq = ERR_PTR(-ENOMEM);
31423 +#define SysaufsBr_PREFIX "br"
31424 +#define SysaufsBrid_PREFIX "brid"
31426 +/* todo: file size may exceed PAGE_SIZE */
31427 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31433 + aufs_bindex_t bbot;
31434 + struct au_sbinfo *sbinfo;
31435 + struct super_block *sb;
31436 + struct seq_file *seq;
31438 + struct attribute **cattr;
31440 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31441 + sb = sbinfo->si_sb;
31444 + * prevent a race condition between sysfs and aufs.
31445 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31446 + * prohibits maintaining the sysfs entries.
31447 + * hew we acquire read lock after sysfs_get_active_two().
31448 + * on the other hand, the remount process may maintain the sysfs/aufs
31449 + * entries after acquiring write lock.
31450 + * it can cause a deadlock.
31451 + * simply we gave up processing read here.
31454 + if (unlikely(!si_noflush_read_trylock(sb)))
31457 + seq = au_seq(buf, PAGE_SIZE);
31458 + err = PTR_ERR(seq);
31462 + name = (void *)attr->name;
31463 + cattr = sysaufs_si_attrs;
31465 + if (!strcmp(name, (*cattr)->name)) {
31466 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31473 + if (!strncmp(name, SysaufsBrid_PREFIX,
31474 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31475 + idx = AuBrSysfs_BRID;
31476 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31477 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31478 + sizeof(SysaufsBr_PREFIX) - 1)) {
31479 + idx = AuBrSysfs_BR;
31480 + name += sizeof(SysaufsBr_PREFIX) - 1;
31484 + err = kstrtol(name, 10, &l);
31486 + bbot = au_sbbot(sb);
31488 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31495 + err = seq->count;
31496 + /* sysfs limit */
31497 + if (unlikely(err == PAGE_SIZE))
31500 + au_kfree_rcu(seq);
31502 + si_read_unlock(sb);
31507 +/* ---------------------------------------------------------------------- */
31509 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31513 + aufs_bindex_t bindex, bbot;
31516 + struct seq_file *seq;
31517 + struct au_branch *br;
31519 + si_read_lock(sb, AuLock_FLUSH);
31520 + bbot = au_sbbot(sb);
31526 + buf = (void *)__get_free_page(GFP_NOFS);
31527 + if (unlikely(!buf))
31530 + seq = au_seq(buf, PAGE_SIZE);
31531 + err = PTR_ERR(seq);
31535 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31536 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31537 + /* VERIFY_WRITE */
31538 + err = !access_ok(arg, sizeof(*arg));
31539 + if (unlikely(err))
31542 + br = au_sbr(sb, bindex);
31543 + brid = br->br_id;
31544 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31545 + err = __put_user(brid, &arg->id);
31546 + if (unlikely(err))
31549 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31550 + err = __put_user(br->br_perm, &arg->perm);
31551 + if (unlikely(err))
31554 + err = au_seq_path(seq, &br->br_path);
31555 + if (unlikely(err))
31557 + seq_putc(seq, '\0');
31558 + if (!seq_has_overflowed(seq)) {
31559 + err = copy_to_user(arg->path, seq->buf, seq->count);
31561 + if (unlikely(err))
31568 + if (unlikely(err))
31572 + au_kfree_rcu(seq);
31574 + free_page((unsigned long)buf);
31576 + si_read_unlock(sb);
31580 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31582 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31585 +#ifdef CONFIG_COMPAT
31586 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31588 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31592 +/* ---------------------------------------------------------------------- */
31594 +void sysaufs_br_init(struct au_branch *br)
31597 + struct au_brsysfs *br_sysfs;
31598 + struct attribute *attr;
31600 + br_sysfs = br->br_sysfs;
31601 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31602 + attr = &br_sysfs->attr;
31603 + sysfs_attr_init(attr);
31604 + attr->name = br_sysfs->name;
31605 + attr->mode = 0444;
31610 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31612 + struct au_branch *br;
31613 + struct kobject *kobj;
31614 + struct au_brsysfs *br_sysfs;
31616 + aufs_bindex_t bbot;
31618 + if (!sysaufs_brs)
31621 + kobj = &au_sbi(sb)->si_kobj;
31622 + bbot = au_sbbot(sb);
31623 + for (; bindex <= bbot; bindex++) {
31624 + br = au_sbr(sb, bindex);
31625 + br_sysfs = br->br_sysfs;
31626 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31627 + sysfs_remove_file(kobj, &br_sysfs->attr);
31633 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31636 + aufs_bindex_t bbot;
31637 + struct kobject *kobj;
31638 + struct au_branch *br;
31639 + struct au_brsysfs *br_sysfs;
31641 + if (!sysaufs_brs)
31644 + kobj = &au_sbi(sb)->si_kobj;
31645 + bbot = au_sbbot(sb);
31646 + for (; bindex <= bbot; bindex++) {
31647 + br = au_sbr(sb, bindex);
31648 + br_sysfs = br->br_sysfs;
31649 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31650 + SysaufsBr_PREFIX "%d", bindex);
31651 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31652 + SysaufsBrid_PREFIX "%d", bindex);
31653 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31654 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31655 + if (unlikely(err))
31656 + pr_warn("failed %s under sysfs(%d)\n",
31657 + br_sysfs->name, err);
31662 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31663 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31664 +++ linux/fs/aufs/sysrq.c 2020-01-27 10:57:18.178871751 +0100
31666 +// SPDX-License-Identifier: GPL-2.0
31668 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31670 + * This program, aufs is free software; you can redistribute it and/or modify
31671 + * it under the terms of the GNU General Public License as published by
31672 + * the Free Software Foundation; either version 2 of the License, or
31673 + * (at your option) any later version.
31675 + * This program is distributed in the hope that it will be useful,
31676 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31677 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31678 + * GNU General Public License for more details.
31680 + * You should have received a copy of the GNU General Public License
31681 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31685 + * magic sysrq handler
31688 +/* #include <linux/sysrq.h> */
31689 +#include <linux/writeback.h>
31692 +/* ---------------------------------------------------------------------- */
31694 +static void sysrq_sb(struct super_block *sb)
31697 + struct au_sbinfo *sbinfo;
31698 + struct file *file;
31699 + struct hlist_bl_head *files;
31700 + struct hlist_bl_node *pos;
31701 + struct au_finfo *finfo;
31704 + plevel = au_plevel;
31705 + au_plevel = KERN_WARNING;
31707 + /* since we define pr_fmt, call printk directly */
31708 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31710 + sbinfo = au_sbi(sb);
31711 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31712 + pr("superblock\n");
31715 +#if 0 /* reserved */
31717 + int err, i, j, ndentry;
31718 + struct au_dcsub_pages dpages;
31719 + struct au_dpage *dpage;
31721 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31722 + if (unlikely(err))
31724 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31726 + for (i = 0; i < dpages.ndpage; i++) {
31727 + dpage = dpages.dpages + i;
31728 + ndentry = dpage->ndentry;
31729 + for (j = 0; j < ndentry; j++)
31730 + au_dpri_dentry(dpage->dentries[j]);
31732 + au_dpages_free(&dpages);
31736 + pr("isolated inode\n");
31737 + spin_lock(&sb->s_inode_list_lock);
31738 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31739 + spin_lock(&i->i_lock);
31740 + if (hlist_empty(&i->i_dentry))
31741 + au_dpri_inode(i);
31742 + spin_unlock(&i->i_lock);
31744 + spin_unlock(&sb->s_inode_list_lock);
31747 + files = &au_sbi(sb)->si_files;
31748 + hlist_bl_lock(files);
31749 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31752 + file = finfo->fi_file;
31753 + mode = file_inode(file)->i_mode;
31754 + if (!special_file(mode))
31755 + au_dpri_file(file);
31757 + hlist_bl_unlock(files);
31761 + au_plevel = plevel;
31764 +/* ---------------------------------------------------------------------- */
31766 +/* module parameter */
31767 +static char *aufs_sysrq_key = "a";
31768 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31769 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31771 +static void au_sysrq(int key __maybe_unused)
31773 + struct au_sbinfo *sbinfo;
31774 + struct hlist_bl_node *pos;
31777 + au_sbilist_lock();
31778 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31779 + sysrq_sb(sbinfo->si_sb);
31780 + au_sbilist_unlock();
31784 +static struct sysrq_key_op au_sysrq_op = {
31785 + .handler = au_sysrq,
31786 + .help_msg = "Aufs",
31787 + .action_msg = "Aufs",
31788 + .enable_mask = SYSRQ_ENABLE_DUMP
31791 +/* ---------------------------------------------------------------------- */
31793 +int __init au_sysrq_init(void)
31799 + key = *aufs_sysrq_key;
31800 + if ('a' <= key && key <= 'z')
31801 + err = register_sysrq_key(key, &au_sysrq_op);
31802 + if (unlikely(err))
31803 + pr_err("err %d, sysrq=%c\n", err, key);
31807 +void au_sysrq_fin(void)
31811 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31812 + if (unlikely(err))
31813 + pr_err("err %d (ignored)\n", err);
31815 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31816 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31817 +++ linux/fs/aufs/vdir.c 2020-01-27 10:57:18.178871751 +0100
31819 +// SPDX-License-Identifier: GPL-2.0
31821 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31823 + * This program, aufs is free software; you can redistribute it and/or modify
31824 + * it under the terms of the GNU General Public License as published by
31825 + * the Free Software Foundation; either version 2 of the License, or
31826 + * (at your option) any later version.
31828 + * This program is distributed in the hope that it will be useful,
31829 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31830 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31831 + * GNU General Public License for more details.
31833 + * You should have received a copy of the GNU General Public License
31834 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31838 + * virtual or vertical directory
31841 +#include <linux/iversion.h>
31844 +static unsigned int calc_size(int nlen)
31846 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31849 +static int set_deblk_end(union au_vdir_deblk_p *p,
31850 + union au_vdir_deblk_p *deblk_end)
31852 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31853 + p->de->de_str.len = 0;
31857 + return -1; /* error */
31860 +/* returns true or false */
31861 +static int is_deblk_end(union au_vdir_deblk_p *p,
31862 + union au_vdir_deblk_p *deblk_end)
31864 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31865 + return !p->de->de_str.len;
31869 +static unsigned char *last_deblk(struct au_vdir *vdir)
31871 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31874 +/* ---------------------------------------------------------------------- */
31876 +/* estimate the appropriate size for name hash table */
31877 +unsigned int au_rdhash_est(loff_t sz)
31885 + if (sz < AUFS_RDHASH_DEF)
31886 + n = AUFS_RDHASH_DEF;
31887 + /* pr_info("n %u\n", n); */
31892 + * the allocated memory has to be freed by
31893 + * au_nhash_wh_free() or au_nhash_de_free().
31895 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31897 + struct hlist_head *head;
31901 + sz = sizeof(*nhash->nh_head) * num_hash;
31902 + head = kmalloc(sz, gfp);
31904 + nhash->nh_num = num_hash;
31905 + nhash->nh_head = head;
31906 + for (u = 0; u < num_hash; u++)
31907 + INIT_HLIST_HEAD(head++);
31908 + return 0; /* success */
31914 +static void nhash_count(struct hlist_head *head)
31916 +#if 0 /* debugging */
31918 + struct hlist_node *pos;
31921 + hlist_for_each(pos, head)
31923 + pr_info("%lu\n", n);
31927 +static void au_nhash_wh_do_free(struct hlist_head *head)
31929 + struct au_vdir_wh *pos;
31930 + struct hlist_node *node;
31932 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31933 + au_kfree_rcu(pos);
31936 +static void au_nhash_de_do_free(struct hlist_head *head)
31938 + struct au_vdir_dehstr *pos;
31939 + struct hlist_node *node;
31941 + hlist_for_each_entry_safe(pos, node, head, hash)
31942 + au_cache_free_vdir_dehstr(pos);
31945 +static void au_nhash_do_free(struct au_nhash *nhash,
31946 + void (*free)(struct hlist_head *head))
31949 + struct hlist_head *head;
31951 + n = nhash->nh_num;
31955 + head = nhash->nh_head;
31956 + while (n-- > 0) {
31957 + nhash_count(head);
31960 + au_kfree_try_rcu(nhash->nh_head);
31963 +void au_nhash_wh_free(struct au_nhash *whlist)
31965 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31968 +static void au_nhash_de_free(struct au_nhash *delist)
31970 + au_nhash_do_free(delist, au_nhash_de_do_free);
31973 +/* ---------------------------------------------------------------------- */
31975 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
31979 + unsigned int u, n;
31980 + struct hlist_head *head;
31981 + struct au_vdir_wh *pos;
31984 + n = whlist->nh_num;
31985 + head = whlist->nh_head;
31986 + for (u = 0; u < n; u++, head++)
31987 + hlist_for_each_entry(pos, head, wh_hash)
31988 + if (pos->wh_bindex == btgt && ++num > limit)
31993 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
31994 + unsigned char *name,
31995 + unsigned int len)
31998 + /* const unsigned int magic_bit = 12; */
32000 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32007 + /* v = hash_long(v, magic_bit); */
32008 + v %= nhash->nh_num;
32009 + return nhash->nh_head + v;
32012 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32015 + return str->len == nlen && !memcmp(str->name, name, nlen);
32018 +/* returns found or not */
32019 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32021 + struct hlist_head *head;
32022 + struct au_vdir_wh *pos;
32023 + struct au_vdir_destr *str;
32025 + head = au_name_hash(whlist, name, nlen);
32026 + hlist_for_each_entry(pos, head, wh_hash) {
32027 + str = &pos->wh_str;
32028 + AuDbg("%.*s\n", str->len, str->name);
32029 + if (au_nhash_test_name(str, name, nlen))
32035 +/* returns found(true) or not */
32036 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32038 + struct hlist_head *head;
32039 + struct au_vdir_dehstr *pos;
32040 + struct au_vdir_destr *str;
32042 + head = au_name_hash(delist, name, nlen);
32043 + hlist_for_each_entry(pos, head, hash) {
32045 + AuDbg("%.*s\n", str->len, str->name);
32046 + if (au_nhash_test_name(str, name, nlen))
32052 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32053 + unsigned char d_type)
32055 +#ifdef CONFIG_AUFS_SHWH
32056 + wh->wh_ino = ino;
32057 + wh->wh_type = d_type;
32061 +/* ---------------------------------------------------------------------- */
32063 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32064 + unsigned int d_type, aufs_bindex_t bindex,
32065 + unsigned char shwh)
32068 + struct au_vdir_destr *str;
32069 + struct au_vdir_wh *wh;
32071 + AuDbg("%.*s\n", nlen, name);
32072 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32075 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32076 + if (unlikely(!wh))
32080 + wh->wh_bindex = bindex;
32082 + au_shwh_init_wh(wh, ino, d_type);
32083 + str = &wh->wh_str;
32085 + memcpy(str->name, name, nlen);
32086 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32093 +static int append_deblk(struct au_vdir *vdir)
32096 + unsigned long ul;
32097 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32098 + union au_vdir_deblk_p p, deblk_end;
32099 + unsigned char **o;
32102 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32103 + GFP_NOFS, /*may_shrink*/0);
32104 + if (unlikely(!o))
32107 + vdir->vd_deblk = o;
32108 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32110 + ul = vdir->vd_nblk++;
32111 + vdir->vd_deblk[ul] = p.deblk;
32112 + vdir->vd_last.ul = ul;
32113 + vdir->vd_last.p.deblk = p.deblk;
32114 + deblk_end.deblk = p.deblk + deblk_sz;
32115 + err = set_deblk_end(&p, &deblk_end);
32122 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32123 + unsigned int d_type, struct au_nhash *delist)
32127 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32128 + union au_vdir_deblk_p p, *room, deblk_end;
32129 + struct au_vdir_dehstr *dehstr;
32131 + p.deblk = last_deblk(vdir);
32132 + deblk_end.deblk = p.deblk + deblk_sz;
32133 + room = &vdir->vd_last.p;
32134 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32135 + || !is_deblk_end(room, &deblk_end));
32137 + sz = calc_size(nlen);
32138 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32139 + err = append_deblk(vdir);
32140 + if (unlikely(err))
32143 + p.deblk = last_deblk(vdir);
32144 + deblk_end.deblk = p.deblk + deblk_sz;
32146 + AuDebugOn(room->deblk != p.deblk);
32150 + dehstr = au_cache_alloc_vdir_dehstr();
32151 + if (unlikely(!dehstr))
32154 + dehstr->str = &room->de->de_str;
32155 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32156 + room->de->de_ino = ino;
32157 + room->de->de_type = d_type;
32158 + room->de->de_str.len = nlen;
32159 + memcpy(room->de->de_str.name, name, nlen);
32162 + room->deblk += sz;
32163 + if (unlikely(set_deblk_end(room, &deblk_end)))
32164 + err = append_deblk(vdir);
32171 +/* ---------------------------------------------------------------------- */
32173 +void au_vdir_free(struct au_vdir *vdir)
32175 + unsigned char **deblk;
32177 + deblk = vdir->vd_deblk;
32178 + while (vdir->vd_nblk--)
32179 + au_kfree_try_rcu(*deblk++);
32180 + au_kfree_try_rcu(vdir->vd_deblk);
32181 + au_cache_free_vdir(vdir);
32184 +static struct au_vdir *alloc_vdir(struct file *file)
32186 + struct au_vdir *vdir;
32187 + struct super_block *sb;
32190 + sb = file->f_path.dentry->d_sb;
32191 + SiMustAnyLock(sb);
32194 + vdir = au_cache_alloc_vdir();
32195 + if (unlikely(!vdir))
32198 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32199 + if (unlikely(!vdir->vd_deblk))
32202 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32203 + if (!vdir->vd_deblk_sz) {
32204 + /* estimate the appropriate size for deblk */
32205 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32206 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32208 + vdir->vd_nblk = 0;
32209 + vdir->vd_version = 0;
32210 + vdir->vd_jiffy = 0;
32211 + err = append_deblk(vdir);
32213 + return vdir; /* success */
32215 + au_kfree_try_rcu(vdir->vd_deblk);
32218 + au_cache_free_vdir(vdir);
32220 + vdir = ERR_PTR(err);
32224 +static int reinit_vdir(struct au_vdir *vdir)
32227 + union au_vdir_deblk_p p, deblk_end;
32229 + while (vdir->vd_nblk > 1) {
32230 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32231 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32234 + p.deblk = vdir->vd_deblk[0];
32235 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32236 + err = set_deblk_end(&p, &deblk_end);
32237 + /* keep vd_dblk_sz */
32238 + vdir->vd_last.ul = 0;
32239 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32240 + vdir->vd_version = 0;
32241 + vdir->vd_jiffy = 0;
32246 +/* ---------------------------------------------------------------------- */
32248 +#define AuFillVdir_CALLED 1
32249 +#define AuFillVdir_WHABLE (1 << 1)
32250 +#define AuFillVdir_SHWH (1 << 2)
32251 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32252 +#define au_fset_fillvdir(flags, name) \
32253 + do { (flags) |= AuFillVdir_##name; } while (0)
32254 +#define au_fclr_fillvdir(flags, name) \
32255 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32257 +#ifndef CONFIG_AUFS_SHWH
32258 +#undef AuFillVdir_SHWH
32259 +#define AuFillVdir_SHWH 0
32262 +struct fillvdir_arg {
32263 + struct dir_context ctx;
32264 + struct file *file;
32265 + struct au_vdir *vdir;
32266 + struct au_nhash delist;
32267 + struct au_nhash whlist;
32268 + aufs_bindex_t bindex;
32269 + unsigned int flags;
32273 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32274 + loff_t offset __maybe_unused, u64 h_ino,
32275 + unsigned int d_type)
32277 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32278 + char *name = (void *)__name;
32279 + struct super_block *sb;
32281 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32284 + sb = arg->file->f_path.dentry->d_sb;
32285 + au_fset_fillvdir(arg->flags, CALLED);
32287 + if (nlen <= AUFS_WH_PFX_LEN
32288 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32289 + if (test_known(&arg->delist, name, nlen)
32290 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32291 + goto out; /* already exists or whiteouted */
32293 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32295 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32296 + d_type = DT_UNKNOWN;
32297 + arg->err = append_de(arg->vdir, name, nlen, ino,
32298 + d_type, &arg->delist);
32300 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32301 + name += AUFS_WH_PFX_LEN;
32302 + nlen -= AUFS_WH_PFX_LEN;
32303 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32304 + goto out; /* already whiteouted */
32306 + ino = 0; /* just to suppress a warning */
32308 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32311 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32312 + d_type = DT_UNKNOWN;
32313 + arg->err = au_nhash_append_wh
32314 + (&arg->whlist, name, nlen, ino, d_type,
32315 + arg->bindex, shwh);
32321 + arg->vdir->vd_jiffy = jiffies;
32323 + AuTraceErr(arg->err);
32327 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32328 + struct au_nhash *whlist, struct au_nhash *delist)
32330 +#ifdef CONFIG_AUFS_SHWH
32332 + unsigned int nh, u;
32333 + struct hlist_head *head;
32334 + struct au_vdir_wh *pos;
32335 + struct hlist_node *n;
32337 + struct au_vdir_destr *destr;
32339 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32342 + o = p = (void *)__get_free_page(GFP_NOFS);
32343 + if (unlikely(!p))
32347 + nh = whlist->nh_num;
32348 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32349 + p += AUFS_WH_PFX_LEN;
32350 + for (u = 0; u < nh; u++) {
32351 + head = whlist->nh_head + u;
32352 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32353 + destr = &pos->wh_str;
32354 + memcpy(p, destr->name, destr->len);
32355 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32356 + pos->wh_ino, pos->wh_type, delist);
32357 + if (unlikely(err))
32362 + free_page((unsigned long)o);
32372 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32375 + unsigned int rdhash;
32377 + aufs_bindex_t bbot, bindex, btop;
32378 + unsigned char shwh;
32379 + struct file *hf, *file;
32380 + struct super_block *sb;
32382 + file = arg->file;
32383 + sb = file->f_path.dentry->d_sb;
32384 + SiMustAnyLock(sb);
32386 + rdhash = au_sbi(sb)->si_rdhash;
32388 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32389 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32390 + if (unlikely(err))
32392 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32393 + if (unlikely(err))
32399 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32401 + au_fset_fillvdir(arg->flags, SHWH);
32403 + btop = au_fbtop(file);
32404 + bbot = au_fbbot_dir(file);
32405 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32406 + hf = au_hf_dir(file, bindex);
32410 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32412 + if (unlikely(offset))
32415 + arg->bindex = bindex;
32416 + au_fclr_fillvdir(arg->flags, WHABLE);
32418 + || (bindex != bbot
32419 + && au_br_whable(au_sbr_perm(sb, bindex))))
32420 + au_fset_fillvdir(arg->flags, WHABLE);
32423 + au_fclr_fillvdir(arg->flags, CALLED);
32425 + err = vfsub_iterate_dir(hf, &arg->ctx);
32428 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32431 + * dir_relax() may be good for concurrency, but aufs should not
32432 + * use it since it will cause a lockdep problem.
32436 + if (!err && shwh)
32437 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32439 + au_nhash_wh_free(&arg->whlist);
32442 + au_nhash_de_free(&arg->delist);
32447 +static int read_vdir(struct file *file, int may_read)
32450 + unsigned long expire;
32451 + unsigned char do_read;
32452 + struct fillvdir_arg arg = {
32454 + .actor = fillvdir
32457 + struct inode *inode;
32458 + struct au_vdir *vdir, *allocated;
32461 + inode = file_inode(file);
32462 + IMustLock(inode);
32463 + IiMustWriteLock(inode);
32464 + SiMustAnyLock(inode->i_sb);
32466 + allocated = NULL;
32468 + expire = au_sbi(inode->i_sb)->si_rdcache;
32469 + vdir = au_ivdir(inode);
32472 + vdir = alloc_vdir(file);
32473 + err = PTR_ERR(vdir);
32474 + if (IS_ERR(vdir))
32477 + allocated = vdir;
32478 + } else if (may_read
32479 + && (!inode_eq_iversion(inode, vdir->vd_version)
32480 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32482 + err = reinit_vdir(vdir);
32483 + if (unlikely(err))
32488 + return 0; /* success */
32492 + err = au_do_read_vdir(&arg);
32494 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32495 + vdir->vd_version = inode_query_iversion(inode);
32496 + vdir->vd_last.ul = 0;
32497 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32499 + au_set_ivdir(inode, allocated);
32500 + } else if (allocated)
32501 + au_vdir_free(allocated);
32507 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32510 + unsigned long ul, n;
32511 + const unsigned int deblk_sz = src->vd_deblk_sz;
32513 + AuDebugOn(tgt->vd_nblk != 1);
32516 + if (tgt->vd_nblk < src->vd_nblk) {
32517 + unsigned char **p;
32519 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32520 + GFP_NOFS, /*may_shrink*/0);
32521 + if (unlikely(!p))
32523 + tgt->vd_deblk = p;
32526 + if (tgt->vd_deblk_sz != deblk_sz) {
32527 + unsigned char *p;
32529 + tgt->vd_deblk_sz = deblk_sz;
32530 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32531 + /*may_shrink*/1);
32532 + if (unlikely(!p))
32534 + tgt->vd_deblk[0] = p;
32536 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32537 + tgt->vd_version = src->vd_version;
32538 + tgt->vd_jiffy = src->vd_jiffy;
32540 + n = src->vd_nblk;
32541 + for (ul = 1; ul < n; ul++) {
32542 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32544 + if (unlikely(!tgt->vd_deblk[ul]))
32548 + tgt->vd_nblk = n;
32549 + tgt->vd_last.ul = tgt->vd_last.ul;
32550 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32551 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32552 + - src->vd_deblk[src->vd_last.ul];
32554 + return 0; /* success */
32557 + rerr = reinit_vdir(tgt);
32562 +int au_vdir_init(struct file *file)
32565 + struct inode *inode;
32566 + struct au_vdir *vdir_cache, *allocated;
32568 + /* test file->f_pos here instead of ctx->pos */
32569 + err = read_vdir(file, !file->f_pos);
32570 + if (unlikely(err))
32573 + allocated = NULL;
32574 + vdir_cache = au_fvdir_cache(file);
32575 + if (!vdir_cache) {
32576 + vdir_cache = alloc_vdir(file);
32577 + err = PTR_ERR(vdir_cache);
32578 + if (IS_ERR(vdir_cache))
32580 + allocated = vdir_cache;
32581 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32582 + /* test file->f_pos here instead of ctx->pos */
32583 + err = reinit_vdir(vdir_cache);
32584 + if (unlikely(err))
32587 + return 0; /* success */
32589 + inode = file_inode(file);
32590 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32592 + file->f_version = inode_query_iversion(inode);
32594 + au_set_fvdir_cache(file, allocated);
32595 + } else if (allocated)
32596 + au_vdir_free(allocated);
32602 +static loff_t calc_offset(struct au_vdir *vdir)
32605 + union au_vdir_deblk_p p;
32607 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32608 + offset = vdir->vd_last.p.deblk - p.deblk;
32609 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32613 +/* returns true or false */
32614 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32617 + unsigned int deblk_sz;
32618 + unsigned long ul, n;
32620 + union au_vdir_deblk_p p, deblk_end;
32621 + struct au_vdir *vdir_cache;
32624 + vdir_cache = au_fvdir_cache(file);
32625 + offset = calc_offset(vdir_cache);
32626 + AuDbg("offset %lld\n", offset);
32627 + if (ctx->pos == offset)
32630 + vdir_cache->vd_last.ul = 0;
32631 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32636 + deblk_sz = vdir_cache->vd_deblk_sz;
32637 + ul = div64_u64(ctx->pos, deblk_sz);
32638 + AuDbg("ul %lu\n", ul);
32639 + if (ul >= vdir_cache->vd_nblk)
32642 + n = vdir_cache->vd_nblk;
32643 + for (; ul < n; ul++) {
32644 + p.deblk = vdir_cache->vd_deblk[ul];
32645 + deblk_end.deblk = p.deblk + deblk_sz;
32647 + offset *= deblk_sz;
32648 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32651 + l = calc_size(p.de->de_str.len);
32655 + if (!is_deblk_end(&p, &deblk_end)) {
32657 + vdir_cache->vd_last.ul = ul;
32658 + vdir_cache->vd_last.p = p;
32666 + AuDbg("valid %d\n", !valid);
32670 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32672 + unsigned int l, deblk_sz;
32673 + union au_vdir_deblk_p deblk_end;
32674 + struct au_vdir *vdir_cache;
32675 + struct au_vdir_de *de;
32677 + if (!seek_vdir(file, ctx))
32680 + vdir_cache = au_fvdir_cache(file);
32681 + deblk_sz = vdir_cache->vd_deblk_sz;
32683 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32684 + deblk_end.deblk += deblk_sz;
32685 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32686 + de = vdir_cache->vd_last.p.de;
32687 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32688 + de->de_str.len, de->de_str.name, ctx->pos,
32689 + (unsigned long)de->de_ino, de->de_type);
32690 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32691 + de->de_str.len, de->de_ino,
32693 + /* todo: ignore the error caused by udba? */
32694 + /* return err; */
32698 + l = calc_size(de->de_str.len);
32699 + vdir_cache->vd_last.p.deblk += l;
32702 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32703 + vdir_cache->vd_last.ul++;
32704 + vdir_cache->vd_last.p.deblk
32705 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32706 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32715 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32716 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32717 +++ linux/fs/aufs/vfsub.c 2020-08-03 09:14:46.095748745 +0200
32719 +// SPDX-License-Identifier: GPL-2.0
32721 + * Copyright (C) 2005-2020 Junjiro R. Okajima
32723 + * This program, aufs is free software; you can redistribute it and/or modify
32724 + * it under the terms of the GNU General Public License as published by
32725 + * the Free Software Foundation; either version 2 of the License, or
32726 + * (at your option) any later version.
32728 + * This program is distributed in the hope that it will be useful,
32729 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32730 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32731 + * GNU General Public License for more details.
32733 + * You should have received a copy of the GNU General Public License
32734 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32738 + * sub-routines for VFS
32741 +#include <linux/mnt_namespace.h>
32742 +#include <linux/namei.h>
32743 +#include <linux/nsproxy.h>
32744 +#include <linux/security.h>
32745 +#include <linux/splice.h>
32748 +#ifdef CONFIG_AUFS_BR_FUSE
32749 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32751 + if (!au_test_fuse(h_sb) || !au_userns)
32754 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32758 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32763 + down_read(&h_sb->s_umount);
32764 + err = __sync_filesystem(h_sb, wait);
32765 + up_read(&h_sb->s_umount);
32771 +/* ---------------------------------------------------------------------- */
32773 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32777 + struct super_block *h_sb;
32779 + /* for remote fs, leave work for its getattr or d_revalidate */
32780 + /* for bad i_attr fs, handle them in aufs_getattr() */
32781 + /* still some fs may acquire i_mutex. we need to skip them */
32785 + h_sb = h_path->dentry->d_sb;
32786 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32788 + err = vfsub_getattr(h_path, &st);
32793 +/* ---------------------------------------------------------------------- */
32795 +struct file *vfsub_dentry_open(struct path *path, int flags)
32797 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32801 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32803 + struct file *file;
32806 + file = filp_open(path,
32807 + oflags /* | __FMODE_NONOTIFY */,
32810 + if (IS_ERR(file))
32812 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32819 + * Ideally this function should call VFS:do_last() in order to keep all its
32820 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32821 + * structure such as nameidata. This is a second (or third) best approach.
32822 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32824 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32825 + struct vfsub_aopen_args *args)
32828 + struct au_branch *br = args->br;
32829 + struct file *file = args->file;
32830 + /* copied from linux/fs/namei.c:atomic_open() */
32831 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32834 + AuDebugOn(!dir->i_op->atomic_open);
32836 + err = au_br_test_oflag(args->open_flag, br);
32837 + if (unlikely(err))
32840 + au_lcnt_inc(&br->br_nfiles);
32841 + file->f_path.dentry = DENTRY_NOT_SET;
32842 + file->f_path.mnt = au_br_mnt(br);
32843 + AuDbg("%ps\n", dir->i_op->atomic_open);
32844 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32845 + args->create_mode);
32846 + if (unlikely(err < 0)) {
32847 + au_lcnt_dec(&br->br_nfiles);
32851 + /* temporary workaround for nfsv4 branch */
32852 + if (au_test_nfs(dir->i_sb))
32853 + nfs_mark_for_revalidate(dir);
32855 + if (file->f_mode & FMODE_CREATED)
32856 + fsnotify_create(dir, dentry);
32857 + if (!(file->f_mode & FMODE_OPENED)) {
32858 + au_lcnt_dec(&br->br_nfiles);
32862 + /* todo: call VFS:may_open() here */
32863 + /* todo: ima_file_check() too? */
32864 + if (!err && (args->open_flag & __FMODE_EXEC))
32865 + err = deny_write_access(file);
32867 + fsnotify_open(file);
32869 + au_lcnt_dec(&br->br_nfiles);
32870 + /* note that the file is created and still opened */
32876 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32880 + err = kern_path(name, flags, path);
32881 + if (!err && d_is_positive(path->dentry))
32882 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32886 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32887 + struct dentry *parent, int len)
32889 + struct path path = {
32893 + path.dentry = lookup_one_len_unlocked(name, parent, len);
32894 + if (IS_ERR(path.dentry))
32896 + if (d_is_positive(path.dentry))
32897 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32900 + AuTraceErrPtr(path.dentry);
32901 + return path.dentry;
32904 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
32907 + struct path path = {
32911 + /* VFS checks it too, but by WARN_ON_ONCE() */
32912 + IMustLock(d_inode(parent));
32914 + path.dentry = lookup_one_len(name, parent, len);
32915 + if (IS_ERR(path.dentry))
32917 + if (d_is_positive(path.dentry))
32918 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32921 + AuTraceErrPtr(path.dentry);
32922 + return path.dentry;
32925 +void vfsub_call_lkup_one(void *args)
32927 + struct vfsub_lkup_one_args *a = args;
32928 + *a->errp = vfsub_lkup_one(a->name, a->parent);
32931 +/* ---------------------------------------------------------------------- */
32933 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32934 + struct dentry *d2, struct au_hinode *hdir2)
32936 + struct dentry *d;
32939 + d = lock_rename(d1, d2);
32941 + au_hn_suspend(hdir1);
32942 + if (hdir1 != hdir2)
32943 + au_hn_suspend(hdir2);
32948 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32949 + struct dentry *d2, struct au_hinode *hdir2)
32951 + au_hn_resume(hdir1);
32952 + if (hdir1 != hdir2)
32953 + au_hn_resume(hdir2);
32955 + unlock_rename(d1, d2);
32959 +/* ---------------------------------------------------------------------- */
32961 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32964 + struct dentry *d;
32968 + d = path->dentry;
32969 + path->dentry = d->d_parent;
32970 + err = security_path_mknod(path, d, mode, 0);
32971 + path->dentry = d;
32972 + if (unlikely(err))
32976 + err = vfs_create(dir, path->dentry, mode, want_excl);
32979 + struct path tmp = *path;
32982 + vfsub_update_h_iattr(&tmp, &did);
32984 + tmp.dentry = path->dentry->d_parent;
32985 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32994 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
32997 + struct dentry *d;
33001 + d = path->dentry;
33002 + path->dentry = d->d_parent;
33003 + err = security_path_symlink(path, d, symname);
33004 + path->dentry = d;
33005 + if (unlikely(err))
33009 + err = vfs_symlink(dir, path->dentry, symname);
33012 + struct path tmp = *path;
33015 + vfsub_update_h_iattr(&tmp, &did);
33017 + tmp.dentry = path->dentry->d_parent;
33018 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33027 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33030 + struct dentry *d;
33034 + d = path->dentry;
33035 + path->dentry = d->d_parent;
33036 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33037 + path->dentry = d;
33038 + if (unlikely(err))
33042 + err = vfs_mknod(dir, path->dentry, mode, dev);
33045 + struct path tmp = *path;
33048 + vfsub_update_h_iattr(&tmp, &did);
33050 + tmp.dentry = path->dentry->d_parent;
33051 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33060 +static int au_test_nlink(struct inode *inode)
33062 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33064 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33065 + || inode->i_nlink < link_max)
33070 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33071 + struct inode **delegated_inode)
33074 + struct dentry *d;
33078 + err = au_test_nlink(d_inode(src_dentry));
33079 + if (unlikely(err))
33082 + /* we don't call may_linkat() */
33083 + d = path->dentry;
33084 + path->dentry = d->d_parent;
33085 + err = security_path_link(src_dentry, path, d);
33086 + path->dentry = d;
33087 + if (unlikely(err))
33091 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
33094 + struct path tmp = *path;
33097 + /* fuse has different memory inode for the same inumber */
33098 + vfsub_update_h_iattr(&tmp, &did);
33100 + tmp.dentry = path->dentry->d_parent;
33101 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33102 + tmp.dentry = src_dentry;
33103 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33112 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33113 + struct inode *dir, struct path *path,
33114 + struct inode **delegated_inode, unsigned int flags)
33117 + struct path tmp = {
33120 + struct dentry *d;
33123 + IMustLock(src_dir);
33125 + d = path->dentry;
33126 + path->dentry = d->d_parent;
33127 + tmp.dentry = src_dentry->d_parent;
33128 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33129 + path->dentry = d;
33130 + if (unlikely(err))
33134 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
33135 + delegated_inode, flags);
33140 + tmp.dentry = d->d_parent;
33141 + vfsub_update_h_iattr(&tmp, &did);
33143 + tmp.dentry = src_dentry;
33144 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33145 + tmp.dentry = src_dentry->d_parent;
33146 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33155 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33158 + struct dentry *d;
33162 + d = path->dentry;
33163 + path->dentry = d->d_parent;
33164 + err = security_path_mkdir(path, d, mode);
33165 + path->dentry = d;
33166 + if (unlikely(err))
33170 + err = vfs_mkdir(dir, path->dentry, mode);
33173 + struct path tmp = *path;
33176 + vfsub_update_h_iattr(&tmp, &did);
33178 + tmp.dentry = path->dentry->d_parent;
33179 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33188 +int vfsub_rmdir(struct inode *dir, struct path *path)
33191 + struct dentry *d;
33195 + d = path->dentry;
33196 + path->dentry = d->d_parent;
33197 + err = security_path_rmdir(path, d);
33198 + path->dentry = d;
33199 + if (unlikely(err))
33203 + err = vfs_rmdir(dir, path->dentry);
33206 + struct path tmp = {
33207 + .dentry = path->dentry->d_parent,
33211 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33218 +/* ---------------------------------------------------------------------- */
33220 +/* todo: support mmap_sem? */
33221 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33227 + err = vfs_read(file, ubuf, count, ppos);
33230 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33234 +/* todo: kernel_read()? */
33235 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33239 + mm_segment_t oldfs;
33246 + oldfs = get_fs();
33247 + set_fs(KERNEL_DS);
33248 + err = vfsub_read_u(file, buf.u, count, ppos);
33253 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33259 + err = vfs_write(file, ubuf, count, ppos);
33262 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33266 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33269 + mm_segment_t oldfs;
33272 + const char __user *u;
33276 + oldfs = get_fs();
33277 + set_fs(KERNEL_DS);
33278 + err = vfsub_write_u(file, buf.u, count, ppos);
33283 +int vfsub_flush(struct file *file, fl_owner_t id)
33288 + if (file->f_op->flush) {
33289 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33290 + err = file->f_op->flush(file, id);
33293 + err = file->f_op->flush(file, id);
33297 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33303 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33307 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33310 + err = iterate_dir(file, ctx);
33313 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33318 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33319 + struct pipe_inode_info *pipe, size_t len,
33320 + unsigned int flags)
33325 + err = do_splice_to(in, ppos, pipe, len, flags);
33327 + file_accessed(in);
33329 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33333 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33334 + loff_t *ppos, size_t len, unsigned int flags)
33339 + err = do_splice_from(pipe, out, ppos, len, flags);
33342 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33346 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33350 + /* file can be NULL */
33352 + err = vfs_fsync(file, datasync);
33356 + AuDebugOn(!file);
33357 + path = &file->f_path;
33359 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33364 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33365 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33366 + struct file *h_file)
33369 + struct inode *h_inode;
33370 + struct super_block *h_sb;
33373 + err = vfsub_truncate(h_path, length);
33377 + h_inode = d_inode(h_path->dentry);
33378 + h_sb = h_inode->i_sb;
33380 + sb_start_write(h_sb);
33382 + err = locks_verify_truncate(h_inode, h_file, length);
33384 + err = security_path_truncate(h_path);
33387 + err = do_truncate(h_path->dentry, length, attr, h_file);
33391 + sb_end_write(h_sb);
33398 +/* ---------------------------------------------------------------------- */
33400 +struct au_vfsub_mkdir_args {
33402 + struct inode *dir;
33403 + struct path *path;
33407 +static void au_call_vfsub_mkdir(void *args)
33409 + struct au_vfsub_mkdir_args *a = args;
33410 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33413 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33415 + int err, do_sio, wkq_err;
33417 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33420 + err = vfsub_mkdir(dir, path, mode);
33423 + struct au_vfsub_mkdir_args args = {
33429 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33430 + if (unlikely(wkq_err))
33437 +struct au_vfsub_rmdir_args {
33439 + struct inode *dir;
33440 + struct path *path;
33443 +static void au_call_vfsub_rmdir(void *args)
33445 + struct au_vfsub_rmdir_args *a = args;
33446 + *a->errp = vfsub_rmdir(a->dir, a->path);
33449 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33451 + int err, do_sio, wkq_err;
33453 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33456 + err = vfsub_rmdir(dir, path);
33459 + struct au_vfsub_rmdir_args args = {
33464 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33465 + if (unlikely(wkq_err))
33472 +/* ---------------------------------------------------------------------- */
33474 +struct notify_change_args {
33476 + struct path *path;
33477 + struct iattr *ia;
33478 + struct inode **delegated_inode;
33481 +static void call_notify_change(void *args)
33483 + struct notify_change_args *a = args;
33484 + struct inode *h_inode;
33486 + h_inode = d_inode(a->path->dentry);
33487 + IMustLock(h_inode);
33489 + *a->errp = -EPERM;
33490 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33492 + *a->errp = notify_change(a->path->dentry, a->ia,
33493 + a->delegated_inode);
33496 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33498 + AuTraceErr(*a->errp);
33501 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33502 + struct inode **delegated_inode)
33505 + struct notify_change_args args = {
33509 + .delegated_inode = delegated_inode
33512 + call_notify_change(&args);
33517 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33518 + struct inode **delegated_inode)
33520 + int err, wkq_err;
33521 + struct notify_change_args args = {
33525 + .delegated_inode = delegated_inode
33528 + wkq_err = au_wkq_wait(call_notify_change, &args);
33529 + if (unlikely(wkq_err))
33535 +/* ---------------------------------------------------------------------- */
33537 +struct unlink_args {
33539 + struct inode *dir;
33540 + struct path *path;
33541 + struct inode **delegated_inode;
33544 +static void call_unlink(void *args)
33546 + struct unlink_args *a = args;
33547 + struct dentry *d = a->path->dentry;
33548 + struct inode *h_inode;
33549 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33550 + && au_dcount(d) == 1);
33552 + IMustLock(a->dir);
33554 + a->path->dentry = d->d_parent;
33555 + *a->errp = security_path_unlink(a->path, d);
33556 + a->path->dentry = d;
33557 + if (unlikely(*a->errp))
33560 + if (!stop_sillyrename)
33563 + if (d_is_positive(d)) {
33564 + h_inode = d_inode(d);
33569 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33572 + struct path tmp = {
33573 + .dentry = d->d_parent,
33574 + .mnt = a->path->mnt
33576 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33579 + if (!stop_sillyrename)
33584 + AuTraceErr(*a->errp);
33588 + * @dir: must be locked.
33589 + * @dentry: target dentry.
33591 +int vfsub_unlink(struct inode *dir, struct path *path,
33592 + struct inode **delegated_inode, int force)
33595 + struct unlink_args args = {
33599 + .delegated_inode = delegated_inode
33603 + call_unlink(&args);
33607 + wkq_err = au_wkq_wait(call_unlink, &args);
33608 + if (unlikely(wkq_err))
33614 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33615 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33616 +++ linux/fs/aufs/vfsub.h 2020-01-27 10:57:18.178871751 +0100
33618 +/* SPDX-License-Identifier: GPL-2.0 */
33620 + * Copyright (C) 2005-2020 Junjiro R. Okajima
33622 + * This program, aufs is free software; you can redistribute it and/or modify
33623 + * it under the terms of the GNU General Public License as published by
33624 + * the Free Software Foundation; either version 2 of the License, or
33625 + * (at your option) any later version.
33627 + * This program is distributed in the hope that it will be useful,
33628 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33629 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33630 + * GNU General Public License for more details.
33632 + * You should have received a copy of the GNU General Public License
33633 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33637 + * sub-routines for VFS
33640 +#ifndef __AUFS_VFSUB_H__
33641 +#define __AUFS_VFSUB_H__
33645 +#include <linux/fs.h>
33646 +#include <linux/mount.h>
33647 +#include <linux/posix_acl.h>
33648 +#include <linux/xattr.h>
33649 +#include "debug.h"
33651 +/* copied from linux/fs/internal.h */
33652 +/* todo: BAD approach!! */
33653 +extern void __mnt_drop_write(struct vfsmount *);
33654 +extern struct file *alloc_empty_file(int, const struct cred *);
33656 +/* ---------------------------------------------------------------------- */
33658 +/* lock subclass for lower inode */
33659 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33660 +/* reduce? gave up. */
33662 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33663 + AuLsc_I_PARENT, /* lower inode, parent first */
33664 + AuLsc_I_PARENT2, /* copyup dirs */
33665 + AuLsc_I_PARENT3, /* copyup wh */
33671 +/* to debug easier, do not make them inlined functions */
33672 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33673 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33675 +/* ---------------------------------------------------------------------- */
33677 +static inline void vfsub_drop_nlink(struct inode *inode)
33679 + AuDebugOn(!inode->i_nlink);
33680 + drop_nlink(inode);
33683 +static inline void vfsub_dead_dir(struct inode *inode)
33685 + AuDebugOn(!S_ISDIR(inode->i_mode));
33686 + inode->i_flags |= S_DEAD;
33687 + clear_nlink(inode);
33690 +static inline int vfsub_native_ro(struct inode *inode)
33692 + return sb_rdonly(inode->i_sb)
33693 + || IS_RDONLY(inode)
33694 + /* || IS_APPEND(inode) */
33695 + || IS_IMMUTABLE(inode);
33698 +#ifdef CONFIG_AUFS_BR_FUSE
33699 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33701 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33704 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33706 +/* ---------------------------------------------------------------------- */
33708 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33709 +struct file *vfsub_dentry_open(struct path *path, int flags);
33710 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33712 +struct vfsub_aopen_args {
33713 + struct file *file;
33714 + unsigned int open_flag;
33715 + umode_t create_mode;
33716 + struct au_branch *br;
33718 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33719 + struct vfsub_aopen_args *args);
33720 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33722 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33723 + struct dentry *parent, int len);
33724 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33727 +struct vfsub_lkup_one_args {
33728 + struct dentry **errp;
33729 + struct qstr *name;
33730 + struct dentry *parent;
33733 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33734 + struct dentry *parent)
33736 + return vfsub_lookup_one_len(name->name, parent, name->len);
33739 +void vfsub_call_lkup_one(void *args);
33741 +/* ---------------------------------------------------------------------- */
33743 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33748 + err = mnt_want_write(mnt);
33753 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33756 + mnt_drop_write(mnt);
33760 +#if 0 /* reserved */
33761 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33764 + mnt_drop_write_file(file);
33769 +/* ---------------------------------------------------------------------- */
33772 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33773 + struct dentry *d2, struct au_hinode *hdir2);
33774 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33775 + struct dentry *d2, struct au_hinode *hdir2);
33777 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33779 +int vfsub_symlink(struct inode *dir, struct path *path,
33780 + const char *symname);
33781 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33782 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33783 + struct path *path, struct inode **delegated_inode);
33784 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33785 + struct inode *hdir, struct path *path,
33786 + struct inode **delegated_inode, unsigned int flags);
33787 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33788 +int vfsub_rmdir(struct inode *dir, struct path *path);
33790 +/* ---------------------------------------------------------------------- */
33792 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33794 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33796 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33798 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33800 +int vfsub_flush(struct file *file, fl_owner_t id);
33801 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33803 +static inline loff_t vfsub_f_size_read(struct file *file)
33805 + return i_size_read(file_inode(file));
33808 +static inline unsigned int vfsub_file_flags(struct file *file)
33810 + unsigned int flags;
33812 + spin_lock(&file->f_lock);
33813 + flags = file->f_flags;
33814 + spin_unlock(&file->f_lock);
33819 +static inline int vfsub_file_execed(struct file *file)
33821 + /* todo: direct access f_flags */
33822 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33825 +#if 0 /* reserved */
33826 +static inline void vfsub_file_accessed(struct file *h_file)
33828 + file_accessed(h_file);
33829 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33833 +#if 0 /* reserved */
33834 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33835 + struct dentry *h_dentry)
33837 + struct path h_path = {
33838 + .dentry = h_dentry,
33841 + touch_atime(&h_path);
33842 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33846 +static inline int vfsub_update_time(struct inode *h_inode,
33847 + struct timespec64 *ts, int flags)
33849 + return update_time(h_inode, ts, flags);
33850 + /* no vfsub_update_h_iattr() since we don't have struct path */
33853 +#ifdef CONFIG_FS_POSIX_ACL
33854 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33858 + err = posix_acl_chmod(h_inode, h_mode);
33859 + if (err == -EOPNOTSUPP)
33864 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33867 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33868 + struct pipe_inode_info *pipe, size_t len,
33869 + unsigned int flags);
33870 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33871 + loff_t *ppos, size_t len, unsigned int flags);
33873 +static inline long vfsub_truncate(struct path *path, loff_t length)
33878 + err = vfs_truncate(path, length);
33883 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33884 + struct file *h_file);
33885 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33888 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33891 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
33897 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
33903 +/* copy_file_range(2) is a systemcall */
33904 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33905 + struct file *dst, loff_t dst_pos,
33906 + size_t len, unsigned int flags)
33911 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33917 +/* ---------------------------------------------------------------------- */
33919 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33924 + err = vfs_llseek(file, offset, origin);
33929 +/* ---------------------------------------------------------------------- */
33931 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33932 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33933 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33934 + struct inode **delegated_inode);
33935 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33936 + struct inode **delegated_inode);
33937 +int vfsub_unlink(struct inode *dir, struct path *path,
33938 + struct inode **delegated_inode, int force);
33940 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
33942 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
33945 +/* ---------------------------------------------------------------------- */
33947 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
33948 + const void *value, size_t size, int flags)
33953 + err = vfs_setxattr(dentry, name, value, size, flags);
33959 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
33964 + err = vfs_removexattr(dentry, name);
33970 +#endif /* __KERNEL__ */
33971 +#endif /* __AUFS_VFSUB_H__ */
33972 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
33973 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
33974 +++ linux/fs/aufs/wbr_policy.c 2020-01-27 10:57:18.178871751 +0100
33976 +// SPDX-License-Identifier: GPL-2.0
33978 + * Copyright (C) 2005-2020 Junjiro R. Okajima
33980 + * This program, aufs is free software; you can redistribute it and/or modify
33981 + * it under the terms of the GNU General Public License as published by
33982 + * the Free Software Foundation; either version 2 of the License, or
33983 + * (at your option) any later version.
33985 + * This program is distributed in the hope that it will be useful,
33986 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33987 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33988 + * GNU General Public License for more details.
33990 + * You should have received a copy of the GNU General Public License
33991 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33995 + * policies for selecting one among multiple writable branches
33998 +#include <linux/statfs.h>
34001 +/* subset of cpup_attr() */
34002 +static noinline_for_stack
34003 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34007 + struct inode *h_isrc;
34009 + h_isrc = d_inode(h_src);
34010 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34011 + ia.ia_mode = h_isrc->i_mode;
34012 + ia.ia_uid = h_isrc->i_uid;
34013 + ia.ia_gid = h_isrc->i_gid;
34014 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34015 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34016 + /* no delegation since it is just created */
34017 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34019 + /* is this nfs only? */
34020 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34021 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34022 + ia.ia_mode = h_isrc->i_mode;
34023 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34029 +#define AuCpdown_PARENT_OPQ 1
34030 +#define AuCpdown_WHED (1 << 1)
34031 +#define AuCpdown_MADE_DIR (1 << 2)
34032 +#define AuCpdown_DIROPQ (1 << 3)
34033 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34034 +#define au_fset_cpdown(flags, name) \
34035 + do { (flags) |= AuCpdown_##name; } while (0)
34036 +#define au_fclr_cpdown(flags, name) \
34037 + do { (flags) &= ~AuCpdown_##name; } while (0)
34039 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34040 + unsigned int *flags)
34043 + struct dentry *opq_dentry;
34045 + opq_dentry = au_diropq_create(dentry, bdst);
34046 + err = PTR_ERR(opq_dentry);
34047 + if (IS_ERR(opq_dentry))
34049 + dput(opq_dentry);
34050 + au_fset_cpdown(*flags, DIROPQ);
34056 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34057 + struct inode *dir, aufs_bindex_t bdst)
34060 + struct path h_path;
34061 + struct au_branch *br;
34063 + br = au_sbr(dentry->d_sb, bdst);
34064 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34065 + err = PTR_ERR(h_path.dentry);
34066 + if (IS_ERR(h_path.dentry))
34070 + if (d_is_positive(h_path.dentry)) {
34071 + h_path.mnt = au_br_mnt(br);
34072 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34075 + dput(h_path.dentry);
34081 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34082 + struct au_pin *pin,
34083 + struct dentry *h_parent, void *arg)
34086 + aufs_bindex_t bopq, btop;
34087 + struct path h_path;
34088 + struct dentry *parent;
34089 + struct inode *h_dir, *h_inode, *inode, *dir;
34090 + unsigned int *flags = arg;
34092 + btop = au_dbtop(dentry);
34093 + /* dentry is di-locked */
34094 + parent = dget_parent(dentry);
34095 + dir = d_inode(parent);
34096 + h_dir = d_inode(h_parent);
34097 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34098 + IMustLock(h_dir);
34100 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34101 + if (unlikely(err < 0))
34103 + h_path.dentry = au_h_dptr(dentry, bdst);
34104 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34105 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34106 + if (unlikely(err))
34108 + au_fset_cpdown(*flags, MADE_DIR);
34110 + bopq = au_dbdiropq(dentry);
34111 + au_fclr_cpdown(*flags, WHED);
34112 + au_fclr_cpdown(*flags, DIROPQ);
34113 + if (au_dbwh(dentry) == bdst)
34114 + au_fset_cpdown(*flags, WHED);
34115 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34116 + au_fset_cpdown(*flags, PARENT_OPQ);
34117 + h_inode = d_inode(h_path.dentry);
34118 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34119 + if (au_ftest_cpdown(*flags, WHED)) {
34120 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34121 + if (unlikely(err)) {
34122 + inode_unlock(h_inode);
34127 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34128 + inode_unlock(h_inode);
34129 + if (unlikely(err))
34132 + if (au_ftest_cpdown(*flags, WHED)) {
34133 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34134 + if (unlikely(err))
34138 + inode = d_inode(dentry);
34139 + if (au_ibbot(inode) < bdst)
34140 + au_set_ibbot(inode, bdst);
34141 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34142 + au_hi_flags(inode, /*isdir*/1));
34143 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34144 + goto out; /* success */
34148 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34149 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34150 + rerr = au_diropq_remove(dentry, bdst);
34151 + inode_unlock(h_inode);
34152 + if (unlikely(rerr)) {
34153 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34154 + dentry, bdst, rerr);
34160 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34161 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34162 + if (unlikely(rerr)) {
34163 + AuIOErr("failed removing %pd b%d (%d)\n",
34164 + dentry, bdst, rerr);
34169 + au_set_h_dptr(dentry, bdst, NULL);
34170 + if (au_dbbot(dentry) == bdst)
34171 + au_update_dbbot(dentry);
34177 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34180 + unsigned int flags;
34183 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34188 +/* ---------------------------------------------------------------------- */
34190 +/* policies for create */
34192 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34194 + int err, i, j, ndentry;
34195 + aufs_bindex_t bopq;
34196 + struct au_dcsub_pages dpages;
34197 + struct au_dpage *dpage;
34198 + struct dentry **dentries, *parent, *d;
34200 + err = au_dpages_init(&dpages, GFP_NOFS);
34201 + if (unlikely(err))
34203 + parent = dget_parent(dentry);
34204 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34205 + if (unlikely(err))
34209 + for (i = 0; i < dpages.ndpage; i++) {
34210 + dpage = dpages.dpages + i;
34211 + dentries = dpage->dentries;
34212 + ndentry = dpage->ndentry;
34213 + for (j = 0; j < ndentry; j++) {
34215 + di_read_lock_parent2(d, !AuLock_IR);
34216 + bopq = au_dbdiropq(d);
34217 + di_read_unlock(d, !AuLock_IR);
34218 + if (bopq >= 0 && bopq < err)
34225 + au_dpages_free(&dpages);
34230 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34232 + for (; bindex >= 0; bindex--)
34233 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34238 +/* top down parent */
34239 +static int au_wbr_create_tdp(struct dentry *dentry,
34240 + unsigned int flags __maybe_unused)
34243 + aufs_bindex_t btop, bindex;
34244 + struct super_block *sb;
34245 + struct dentry *parent, *h_parent;
34247 + sb = dentry->d_sb;
34248 + btop = au_dbtop(dentry);
34250 + if (!au_br_rdonly(au_sbr(sb, btop)))
34254 + parent = dget_parent(dentry);
34255 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34256 + h_parent = au_h_dptr(parent, bindex);
34257 + if (!h_parent || d_is_negative(h_parent))
34260 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34267 + /* bottom up here */
34268 + if (unlikely(err < 0)) {
34269 + err = au_wbr_bu(sb, btop - 1);
34271 + err = au_wbr_nonopq(dentry, err);
34275 + AuDbg("b%d\n", err);
34279 +/* ---------------------------------------------------------------------- */
34281 +/* an exception for the policy other than tdp */
34282 +static int au_wbr_create_exp(struct dentry *dentry)
34285 + aufs_bindex_t bwh, bdiropq;
34286 + struct dentry *parent;
34289 + bwh = au_dbwh(dentry);
34290 + parent = dget_parent(dentry);
34291 + bdiropq = au_dbdiropq(parent);
34293 + if (bdiropq >= 0)
34294 + err = min(bdiropq, bwh);
34297 + AuDbg("%d\n", err);
34298 + } else if (bdiropq >= 0) {
34300 + AuDbg("%d\n", err);
34305 + err = au_wbr_nonopq(dentry, err);
34307 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34310 + AuDbg("%d\n", err);
34314 +/* ---------------------------------------------------------------------- */
34317 +static int au_wbr_create_init_rr(struct super_block *sb)
34321 + err = au_wbr_bu(sb, au_sbbot(sb));
34322 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34325 + AuDbg("b%d\n", err);
34329 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34333 + aufs_bindex_t bindex, bbot;
34334 + struct super_block *sb;
34337 + err = au_wbr_create_exp(dentry);
34341 + sb = dentry->d_sb;
34342 + next = &au_sbi(sb)->si_wbr_rr_next;
34343 + bbot = au_sbbot(sb);
34345 + for (bindex = 0; bindex <= bbot; bindex++) {
34346 + if (!au_ftest_wbr(flags, DIR)) {
34347 + err = atomic_dec_return(next) + 1;
34348 + /* modulo for 0 is meaningless */
34349 + if (unlikely(!err))
34350 + err = atomic_dec_return(next) + 1;
34352 + err = atomic_read(next);
34353 + AuDbg("%d\n", err);
34356 + AuDbg("%d\n", err);
34357 + if (!au_br_rdonly(au_sbr(sb, err)))
34363 + err = au_wbr_nonopq(dentry, err);
34366 + AuDbg("%d\n", err);
34370 +/* ---------------------------------------------------------------------- */
34372 +/* most free space */
34373 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34375 + struct super_block *sb;
34376 + struct au_branch *br;
34377 + struct au_wbr_mfs *mfs;
34378 + struct dentry *h_parent;
34379 + aufs_bindex_t bindex, bbot;
34381 + unsigned long long b, bavail;
34382 + struct path h_path;
34383 + /* reduce the stack usage */
34384 + struct kstatfs *st;
34386 + st = kmalloc(sizeof(*st), GFP_NOFS);
34387 + if (unlikely(!st)) {
34388 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34393 + sb = dentry->d_sb;
34394 + mfs = &au_sbi(sb)->si_wbr_mfs;
34395 + MtxMustLock(&mfs->mfs_lock);
34396 + mfs->mfs_bindex = -EROFS;
34397 + mfs->mfsrr_bytes = 0;
34400 + bbot = au_sbbot(sb);
34402 + bindex = au_dbtop(parent);
34403 + bbot = au_dbtaildir(parent);
34406 + for (; bindex <= bbot; bindex++) {
34408 + h_parent = au_h_dptr(parent, bindex);
34409 + if (!h_parent || d_is_negative(h_parent))
34412 + br = au_sbr(sb, bindex);
34413 + if (au_br_rdonly(br))
34416 + /* sb->s_root for NFS is unreliable */
34417 + h_path.mnt = au_br_mnt(br);
34418 + h_path.dentry = h_path.mnt->mnt_root;
34419 + err = vfs_statfs(&h_path, st);
34420 + if (unlikely(err)) {
34421 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34425 + /* when the available size is equal, select the lower one */
34426 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34427 + || sizeof(b) < sizeof(st->f_bsize));
34428 + b = st->f_bavail * st->f_bsize;
34429 + br->br_wbr->wbr_bytes = b;
34430 + if (b >= bavail) {
34432 + mfs->mfs_bindex = bindex;
34433 + mfs->mfs_jiffy = jiffies;
34437 + mfs->mfsrr_bytes = bavail;
34438 + AuDbg("b%d\n", mfs->mfs_bindex);
34439 + au_kfree_rcu(st);
34442 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34445 + struct dentry *parent;
34446 + struct super_block *sb;
34447 + struct au_wbr_mfs *mfs;
34449 + err = au_wbr_create_exp(dentry);
34453 + sb = dentry->d_sb;
34455 + if (au_ftest_wbr(flags, PARENT))
34456 + parent = dget_parent(dentry);
34457 + mfs = &au_sbi(sb)->si_wbr_mfs;
34458 + mutex_lock(&mfs->mfs_lock);
34459 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34460 + || mfs->mfs_bindex < 0
34461 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34462 + au_mfs(dentry, parent);
34463 + mutex_unlock(&mfs->mfs_lock);
34464 + err = mfs->mfs_bindex;
34468 + err = au_wbr_nonopq(dentry, err);
34471 + AuDbg("b%d\n", err);
34475 +static int au_wbr_create_init_mfs(struct super_block *sb)
34477 + struct au_wbr_mfs *mfs;
34479 + mfs = &au_sbi(sb)->si_wbr_mfs;
34480 + mutex_init(&mfs->mfs_lock);
34481 + mfs->mfs_jiffy = 0;
34482 + mfs->mfs_bindex = -EROFS;
34487 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34489 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34493 +/* ---------------------------------------------------------------------- */
34495 +/* top down regardless parent, and then mfs */
34496 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34497 + unsigned int flags __maybe_unused)
34500 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34501 + unsigned long long watermark;
34502 + struct super_block *sb;
34503 + struct au_wbr_mfs *mfs;
34504 + struct au_branch *br;
34505 + struct dentry *parent;
34507 + sb = dentry->d_sb;
34508 + mfs = &au_sbi(sb)->si_wbr_mfs;
34509 + mutex_lock(&mfs->mfs_lock);
34510 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34511 + || mfs->mfs_bindex < 0)
34512 + au_mfs(dentry, /*parent*/NULL);
34513 + watermark = mfs->mfsrr_watermark;
34514 + bmfs = mfs->mfs_bindex;
34515 + mutex_unlock(&mfs->mfs_lock);
34517 + /* another style of au_wbr_create_exp() */
34518 + bwh = au_dbwh(dentry);
34519 + parent = dget_parent(dentry);
34520 + btail = au_dbtaildir(parent);
34521 + if (bwh >= 0 && bwh < btail)
34524 + err = au_wbr_nonopq(dentry, btail);
34525 + if (unlikely(err < 0))
34529 + for (bindex = 0; bindex <= btail; bindex++) {
34530 + br = au_sbr(sb, bindex);
34531 + if (au_br_rdonly(br))
34533 + if (br->br_wbr->wbr_bytes > watermark) {
34544 + AuDbg("b%d\n", err);
34548 +/* ---------------------------------------------------------------------- */
34550 +/* most free space and then round robin */
34551 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34554 + struct au_wbr_mfs *mfs;
34556 + err = au_wbr_create_mfs(dentry, flags);
34558 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34559 + mutex_lock(&mfs->mfs_lock);
34560 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34561 + err = au_wbr_create_rr(dentry, flags);
34562 + mutex_unlock(&mfs->mfs_lock);
34565 + AuDbg("b%d\n", err);
34569 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34573 + au_wbr_create_init_mfs(sb); /* ignore */
34574 + err = au_wbr_create_init_rr(sb);
34579 +/* ---------------------------------------------------------------------- */
34581 +/* top down parent and most free space */
34582 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34585 + unsigned long long b;
34586 + aufs_bindex_t bindex, btop, bbot;
34587 + struct super_block *sb;
34588 + struct dentry *parent, *h_parent;
34589 + struct au_branch *br;
34591 + err = au_wbr_create_tdp(dentry, flags);
34592 + if (unlikely(err < 0))
34594 + parent = dget_parent(dentry);
34595 + btop = au_dbtop(parent);
34596 + bbot = au_dbtaildir(parent);
34597 + if (btop == bbot)
34598 + goto out_parent; /* success */
34600 + e2 = au_wbr_create_mfs(dentry, flags);
34602 + goto out_parent; /* success */
34604 + /* when the available size is equal, select upper one */
34605 + sb = dentry->d_sb;
34606 + br = au_sbr(sb, err);
34607 + b = br->br_wbr->wbr_bytes;
34608 + AuDbg("b%d, %llu\n", err, b);
34610 + for (bindex = btop; bindex <= bbot; bindex++) {
34611 + h_parent = au_h_dptr(parent, bindex);
34612 + if (!h_parent || d_is_negative(h_parent))
34615 + br = au_sbr(sb, bindex);
34616 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34617 + b = br->br_wbr->wbr_bytes;
34619 + AuDbg("b%d, %llu\n", err, b);
34624 + err = au_wbr_nonopq(dentry, err);
34629 + AuDbg("b%d\n", err);
34633 +/* ---------------------------------------------------------------------- */
34636 + * - top down parent
34637 + * - most free space with parent
34638 + * - most free space round-robin regardless parent
34640 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34643 + unsigned long long watermark;
34644 + struct super_block *sb;
34645 + struct au_branch *br;
34646 + struct au_wbr_mfs *mfs;
34648 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34649 + if (unlikely(err < 0))
34652 + sb = dentry->d_sb;
34653 + br = au_sbr(sb, err);
34654 + mfs = &au_sbi(sb)->si_wbr_mfs;
34655 + mutex_lock(&mfs->mfs_lock);
34656 + watermark = mfs->mfsrr_watermark;
34657 + mutex_unlock(&mfs->mfs_lock);
34658 + if (br->br_wbr->wbr_bytes < watermark)
34659 + /* regardless the parent dir */
34660 + err = au_wbr_create_mfsrr(dentry, flags);
34663 + AuDbg("b%d\n", err);
34667 +/* ---------------------------------------------------------------------- */
34669 +/* policies for copyup */
34671 +/* top down parent */
34672 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34674 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34677 +/* bottom up parent */
34678 +static int au_wbr_copyup_bup(struct dentry *dentry)
34681 + aufs_bindex_t bindex, btop;
34682 + struct dentry *parent, *h_parent;
34683 + struct super_block *sb;
34686 + sb = dentry->d_sb;
34687 + parent = dget_parent(dentry);
34688 + btop = au_dbtop(parent);
34689 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34690 + h_parent = au_h_dptr(parent, bindex);
34691 + if (!h_parent || d_is_negative(h_parent))
34694 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34701 + /* bottom up here */
34702 + if (unlikely(err < 0))
34703 + err = au_wbr_bu(sb, btop - 1);
34705 + AuDbg("b%d\n", err);
34710 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34714 + err = au_wbr_bu(dentry->d_sb, btop);
34715 + AuDbg("b%d\n", err);
34717 + err = au_wbr_nonopq(dentry, err);
34719 + AuDbg("b%d\n", err);
34723 +static int au_wbr_copyup_bu(struct dentry *dentry)
34726 + aufs_bindex_t btop;
34728 + btop = au_dbtop(dentry);
34729 + err = au_wbr_do_copyup_bu(dentry, btop);
34733 +/* ---------------------------------------------------------------------- */
34735 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34736 + [AuWbrCopyup_TDP] = {
34737 + .copyup = au_wbr_copyup_tdp
34739 + [AuWbrCopyup_BUP] = {
34740 + .copyup = au_wbr_copyup_bup
34742 + [AuWbrCopyup_BU] = {
34743 + .copyup = au_wbr_copyup_bu
34747 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34748 + [AuWbrCreate_TDP] = {
34749 + .create = au_wbr_create_tdp
34751 + [AuWbrCreate_RR] = {
34752 + .create = au_wbr_create_rr,
34753 + .init = au_wbr_create_init_rr
34755 + [AuWbrCreate_MFS] = {
34756 + .create = au_wbr_create_mfs,
34757 + .init = au_wbr_create_init_mfs,
34758 + .fin = au_wbr_create_fin_mfs
34760 + [AuWbrCreate_MFSV] = {
34761 + .create = au_wbr_create_mfs,
34762 + .init = au_wbr_create_init_mfs,
34763 + .fin = au_wbr_create_fin_mfs
34765 + [AuWbrCreate_MFSRR] = {
34766 + .create = au_wbr_create_mfsrr,
34767 + .init = au_wbr_create_init_mfsrr,
34768 + .fin = au_wbr_create_fin_mfs
34770 + [AuWbrCreate_MFSRRV] = {
34771 + .create = au_wbr_create_mfsrr,
34772 + .init = au_wbr_create_init_mfsrr,
34773 + .fin = au_wbr_create_fin_mfs
34775 + [AuWbrCreate_TDMFS] = {
34776 + .create = au_wbr_create_tdmfs,
34777 + .init = au_wbr_create_init_mfs,
34778 + .fin = au_wbr_create_fin_mfs
34780 + [AuWbrCreate_TDMFSV] = {
34781 + .create = au_wbr_create_tdmfs,
34782 + .init = au_wbr_create_init_mfs,
34783 + .fin = au_wbr_create_fin_mfs
34785 + [AuWbrCreate_PMFS] = {
34786 + .create = au_wbr_create_pmfs,
34787 + .init = au_wbr_create_init_mfs,
34788 + .fin = au_wbr_create_fin_mfs
34790 + [AuWbrCreate_PMFSV] = {
34791 + .create = au_wbr_create_pmfs,
34792 + .init = au_wbr_create_init_mfs,
34793 + .fin = au_wbr_create_fin_mfs
34795 + [AuWbrCreate_PMFSRR] = {
34796 + .create = au_wbr_create_pmfsrr,
34797 + .init = au_wbr_create_init_mfsrr,
34798 + .fin = au_wbr_create_fin_mfs
34800 + [AuWbrCreate_PMFSRRV] = {
34801 + .create = au_wbr_create_pmfsrr,
34802 + .init = au_wbr_create_init_mfsrr,
34803 + .fin = au_wbr_create_fin_mfs
34806 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34807 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34808 +++ linux/fs/aufs/whout.c 2020-01-27 10:57:18.178871751 +0100
34810 +// SPDX-License-Identifier: GPL-2.0
34812 + * Copyright (C) 2005-2020 Junjiro R. Okajima
34814 + * This program, aufs is free software; you can redistribute it and/or modify
34815 + * it under the terms of the GNU General Public License as published by
34816 + * the Free Software Foundation; either version 2 of the License, or
34817 + * (at your option) any later version.
34819 + * This program is distributed in the hope that it will be useful,
34820 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34821 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34822 + * GNU General Public License for more details.
34824 + * You should have received a copy of the GNU General Public License
34825 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34829 + * whiteout for logical deletion and opaque directory
34834 +#define WH_MASK 0444
34837 + * If a directory contains this file, then it is opaque. We start with the
34838 + * .wh. flag so that it is blocked by lookup.
34840 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34841 + sizeof(AUFS_WH_DIROPQ) - 1);
34844 + * generate whiteout name, which is NOT terminated by NULL.
34845 + * @name: original d_name.name
34846 + * @len: original d_name.len
34847 + * @wh: whiteout qstr
34848 + * returns zero when succeeds, otherwise error.
34849 + * succeeded value as wh->name should be freed by kfree().
34851 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34855 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34856 + return -ENAMETOOLONG;
34858 + wh->len = name->len + AUFS_WH_PFX_LEN;
34859 + p = kmalloc(wh->len, GFP_NOFS);
34862 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34863 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34870 +/* ---------------------------------------------------------------------- */
34873 + * test if the @wh_name exists under @h_parent.
34874 + * @try_sio specifies the necessary of super-io.
34876 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
34879 + struct dentry *wh_dentry;
34882 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34884 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
34885 + err = PTR_ERR(wh_dentry);
34886 + if (IS_ERR(wh_dentry)) {
34887 + if (err == -ENAMETOOLONG)
34893 + if (d_is_negative(wh_dentry))
34894 + goto out_wh; /* success */
34897 + if (d_is_reg(wh_dentry))
34898 + goto out_wh; /* success */
34901 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34902 + wh_dentry, d_inode(wh_dentry)->i_mode);
34911 + * test if the @h_dentry sets opaque or not.
34913 +int au_diropq_test(struct dentry *h_dentry)
34916 + struct inode *h_dir;
34918 + h_dir = d_inode(h_dentry);
34919 + err = au_wh_test(h_dentry, &diropq_name,
34920 + au_test_h_perm_sio(h_dir, MAY_EXEC));
34925 + * returns a negative dentry whose name is unique and temporary.
34927 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34928 + struct qstr *prefix)
34930 + struct dentry *dentry;
34932 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34934 + /* strict atomic_t is unnecessary here */
34935 + static unsigned short cnt;
34938 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34941 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34942 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34943 + dentry = ERR_PTR(-ENAMETOOLONG);
34944 + if (unlikely(qs.len > NAME_MAX))
34946 + dentry = ERR_PTR(-ENOMEM);
34947 + name = kmalloc(qs.len + 1, GFP_NOFS);
34948 + if (unlikely(!name))
34952 + /* doubly whiteout-ed */
34953 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34954 + p = name + AUFS_WH_PFX_LEN * 2;
34955 + memcpy(p, prefix->name, prefix->len);
34956 + p += prefix->len;
34958 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34961 + for (i = 0; i < 3; i++) {
34962 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34963 + dentry = au_sio_lkup_one(&qs, h_parent);
34964 + if (IS_ERR(dentry) || d_is_negative(dentry))
34968 + /* pr_warn("could not get random name\n"); */
34969 + dentry = ERR_PTR(-EEXIST);
34970 + AuDbg("%.*s\n", AuLNPair(&qs));
34974 + if (name != defname)
34975 + au_kfree_try_rcu(name);
34977 + AuTraceErrPtr(dentry);
34982 + * rename the @h_dentry on @br to the whiteouted temporary name.
34984 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
34987 + struct path h_path = {
34988 + .mnt = au_br_mnt(br)
34990 + struct inode *h_dir, *delegated;
34991 + struct dentry *h_parent;
34993 + h_parent = h_dentry->d_parent; /* dir inode is locked */
34994 + h_dir = d_inode(h_parent);
34995 + IMustLock(h_dir);
34997 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
34998 + err = PTR_ERR(h_path.dentry);
34999 + if (IS_ERR(h_path.dentry))
35002 + /* under the same dir, no need to lock_rename() */
35003 + delegated = NULL;
35004 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35007 + if (unlikely(err == -EWOULDBLOCK)) {
35008 + pr_warn("cannot retry for NFSv4 delegation"
35009 + " for an internal rename\n");
35012 + dput(h_path.dentry);
35019 +/* ---------------------------------------------------------------------- */
35021 + * functions for removing a whiteout
35024 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35027 + struct inode *delegated;
35030 + * forces superio when the dir has a sticky bit.
35031 + * this may be a violation of unix fs semantics.
35033 + force = (h_dir->i_mode & S_ISVTX)
35034 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35035 + delegated = NULL;
35036 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35037 + if (unlikely(err == -EWOULDBLOCK)) {
35038 + pr_warn("cannot retry for NFSv4 delegation"
35039 + " for an internal unlink\n");
35045 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35046 + struct dentry *dentry)
35050 + err = do_unlink_wh(h_dir, h_path);
35051 + if (!err && dentry)
35052 + au_set_dbwh(dentry, -1);
35057 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
35058 + struct au_branch *br)
35061 + struct path h_path = {
35062 + .mnt = au_br_mnt(br)
35066 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
35067 + if (IS_ERR(h_path.dentry))
35068 + err = PTR_ERR(h_path.dentry);
35070 + if (d_is_reg(h_path.dentry))
35071 + err = do_unlink_wh(d_inode(h_parent), &h_path);
35072 + dput(h_path.dentry);
35078 +/* ---------------------------------------------------------------------- */
35080 + * initialize/clean whiteout for a branch
35083 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35087 + struct inode *delegated;
35089 + if (d_is_negative(whpath->dentry))
35093 + err = vfsub_rmdir(h_dir, whpath);
35095 + delegated = NULL;
35096 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35097 + if (unlikely(err == -EWOULDBLOCK)) {
35098 + pr_warn("cannot retry for NFSv4 delegation"
35099 + " for an internal unlink\n");
35103 + if (unlikely(err))
35104 + pr_warn("failed removing %pd (%d), ignored.\n",
35105 + whpath->dentry, err);
35108 +static int test_linkable(struct dentry *h_root)
35110 + struct inode *h_dir = d_inode(h_root);
35112 + if (h_dir->i_op->link)
35115 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35116 + h_root, au_sbtype(h_root->d_sb));
35117 + return -ENOSYS; /* the branch doesn't have its ->link() */
35120 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35121 +static int au_whdir(struct inode *h_dir, struct path *path)
35126 + if (d_is_negative(path->dentry)) {
35129 + if (au_test_nfs(path->dentry->d_sb))
35131 + err = vfsub_mkdir(h_dir, path, mode);
35132 + } else if (d_is_dir(path->dentry))
35135 + pr_err("unknown %pd exists\n", path->dentry);
35140 +struct au_wh_base {
35141 + const struct qstr *name;
35142 + struct dentry *dentry;
35145 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35146 + struct path *h_path)
35148 + h_path->dentry = base[AuBrWh_BASE].dentry;
35149 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35150 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35151 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35152 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35153 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35157 + * returns tri-state,
35158 + * minus: error, caller should print the message
35160 + * plus: error, caller should NOT print the message
35162 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35163 + int do_plink, struct au_wh_base base[],
35164 + struct path *h_path)
35167 + struct inode *h_dir;
35169 + h_dir = d_inode(h_root);
35170 + h_path->dentry = base[AuBrWh_BASE].dentry;
35171 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35172 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35174 + err = test_linkable(h_root);
35175 + if (unlikely(err)) {
35180 + err = au_whdir(h_dir, h_path);
35181 + if (unlikely(err))
35183 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35185 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35186 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35187 + err = au_whdir(h_dir, h_path);
35188 + if (unlikely(err))
35190 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35197 + * for the moment, aufs supports the branch filesystem which does not support
35198 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35199 + * copyup failed. finally, such filesystem will not be used as the writable
35202 + * returns tri-state, see above.
35204 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35205 + int do_plink, struct au_wh_base base[],
35206 + struct path *h_path)
35209 + struct inode *h_dir;
35211 + WbrWhMustWriteLock(wbr);
35213 + err = test_linkable(h_root);
35214 + if (unlikely(err)) {
35220 + * todo: should this create be done in /sbin/mount.aufs helper?
35223 + h_dir = d_inode(h_root);
35224 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35225 + h_path->dentry = base[AuBrWh_BASE].dentry;
35226 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35227 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35230 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35231 + if (unlikely(err))
35234 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35236 + err = au_whdir(h_dir, h_path);
35237 + if (unlikely(err))
35239 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35241 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35242 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35244 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35245 + err = au_whdir(h_dir, h_path);
35246 + if (unlikely(err))
35248 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35255 + * initialize the whiteout base file/dir for @br.
35257 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35260 + const unsigned char do_plink
35261 + = !!au_opt_test(au_mntflags(sb), PLINK);
35262 + struct inode *h_dir;
35263 + struct path path = br->br_path;
35264 + struct dentry *h_root = path.dentry;
35265 + struct au_wbr *wbr = br->br_wbr;
35266 + static const struct qstr base_name[] = {
35267 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35268 + sizeof(AUFS_BASE_NAME) - 1),
35269 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35270 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35271 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35272 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35274 + struct au_wh_base base[] = {
35275 + [AuBrWh_BASE] = {
35276 + .name = base_name + AuBrWh_BASE,
35279 + [AuBrWh_PLINK] = {
35280 + .name = base_name + AuBrWh_PLINK,
35283 + [AuBrWh_ORPH] = {
35284 + .name = base_name + AuBrWh_ORPH,
35290 + WbrWhMustWriteLock(wbr);
35292 + for (i = 0; i < AuBrWh_Last; i++) {
35293 + /* doubly whiteouted */
35294 + struct dentry *d;
35296 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35297 + err = PTR_ERR(d);
35301 + base[i].dentry = d;
35303 + && wbr->wbr_wh[i]
35304 + && wbr->wbr_wh[i] != base[i].dentry);
35308 + for (i = 0; i < AuBrWh_Last; i++) {
35309 + dput(wbr->wbr_wh[i]);
35310 + wbr->wbr_wh[i] = NULL;
35314 + if (!au_br_writable(br->br_perm)) {
35315 + h_dir = d_inode(h_root);
35316 + au_wh_init_ro(h_dir, base, &path);
35317 + } else if (!au_br_wh_linkable(br->br_perm)) {
35318 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35324 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35330 + goto out; /* success */
35333 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35334 + err, h_root, au_sbtype(h_root->d_sb));
35336 + for (i = 0; i < AuBrWh_Last; i++)
35337 + dput(base[i].dentry);
35341 +/* ---------------------------------------------------------------------- */
35343 + * whiteouts are all hard-linked usually.
35344 + * when its link count reaches a ceiling, we create a new whiteout base
35345 + * asynchronously.
35348 +struct reinit_br_wh {
35349 + struct super_block *sb;
35350 + struct au_branch *br;
35353 +static void reinit_br_wh(void *arg)
35356 + aufs_bindex_t bindex;
35357 + struct path h_path;
35358 + struct reinit_br_wh *a = arg;
35359 + struct au_wbr *wbr;
35360 + struct inode *dir, *delegated;
35361 + struct dentry *h_root;
35362 + struct au_hinode *hdir;
35365 + wbr = a->br->br_wbr;
35366 + /* big aufs lock */
35367 + si_noflush_write_lock(a->sb);
35368 + if (!au_br_writable(a->br->br_perm))
35370 + bindex = au_br_index(a->sb, a->br->br_id);
35371 + if (unlikely(bindex < 0))
35374 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35375 + dir = d_inode(a->sb->s_root);
35376 + hdir = au_hi(dir, bindex);
35377 + h_root = au_h_dptr(a->sb->s_root, bindex);
35378 + AuDebugOn(h_root != au_br_dentry(a->br));
35380 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35381 + wbr_wh_write_lock(wbr);
35382 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35385 + h_path.dentry = wbr->wbr_whbase;
35386 + h_path.mnt = au_br_mnt(a->br);
35387 + delegated = NULL;
35388 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35390 + if (unlikely(err == -EWOULDBLOCK)) {
35391 + pr_warn("cannot retry for NFSv4 delegation"
35392 + " for an internal unlink\n");
35396 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35399 + dput(wbr->wbr_whbase);
35400 + wbr->wbr_whbase = NULL;
35402 + err = au_wh_init(a->br, a->sb);
35403 + wbr_wh_write_unlock(wbr);
35404 + au_hn_inode_unlock(hdir);
35405 + di_read_unlock(a->sb->s_root, AuLock_IR);
35407 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35411 + atomic_dec(&wbr->wbr_wh_running);
35412 + au_lcnt_dec(&a->br->br_count);
35413 + si_write_unlock(a->sb);
35414 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35416 + if (unlikely(err))
35417 + AuIOErr("err %d\n", err);
35420 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35422 + int do_dec, wkq_err;
35423 + struct reinit_br_wh *arg;
35426 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35429 + /* ignore ENOMEM */
35430 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35433 + * dec(wh_running), kfree(arg) and dec(br_count)
35434 + * in reinit function
35438 + au_lcnt_inc(&br->br_count);
35439 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35440 + if (unlikely(wkq_err)) {
35441 + atomic_dec(&br->br_wbr->wbr_wh_running);
35442 + au_lcnt_dec(&br->br_count);
35443 + au_kfree_rcu(arg);
35450 + atomic_dec(&br->br_wbr->wbr_wh_running);
35453 +/* ---------------------------------------------------------------------- */
35456 + * create the whiteout @wh.
35458 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35459 + struct dentry *wh)
35462 + struct path h_path = {
35465 + struct au_branch *br;
35466 + struct au_wbr *wbr;
35467 + struct dentry *h_parent;
35468 + struct inode *h_dir, *delegated;
35470 + h_parent = wh->d_parent; /* dir inode is locked */
35471 + h_dir = d_inode(h_parent);
35472 + IMustLock(h_dir);
35474 + br = au_sbr(sb, bindex);
35475 + h_path.mnt = au_br_mnt(br);
35476 + wbr = br->br_wbr;
35477 + wbr_wh_read_lock(wbr);
35478 + if (wbr->wbr_whbase) {
35479 + delegated = NULL;
35480 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35481 + if (unlikely(err == -EWOULDBLOCK)) {
35482 + pr_warn("cannot retry for NFSv4 delegation"
35483 + " for an internal link\n");
35486 + if (!err || err != -EMLINK)
35489 + /* link count full. re-initialize br_whbase. */
35490 + kick_reinit_br_wh(sb, br);
35493 + /* return this error in this context */
35494 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35496 + au_fhsm_wrote(sb, bindex, /*force*/0);
35499 + wbr_wh_read_unlock(wbr);
35503 +/* ---------------------------------------------------------------------- */
35506 + * create or remove the diropq.
35508 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35509 + unsigned int flags)
35511 + struct dentry *opq_dentry, *h_dentry;
35512 + struct super_block *sb;
35513 + struct au_branch *br;
35516 + sb = dentry->d_sb;
35517 + br = au_sbr(sb, bindex);
35518 + h_dentry = au_h_dptr(dentry, bindex);
35519 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35520 + if (IS_ERR(opq_dentry))
35523 + if (au_ftest_diropq(flags, CREATE)) {
35524 + err = link_or_create_wh(sb, bindex, opq_dentry);
35526 + au_set_dbdiropq(dentry, bindex);
35527 + goto out; /* success */
35530 + struct path tmp = {
35531 + .dentry = opq_dentry,
35532 + .mnt = au_br_mnt(br)
35534 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35536 + au_set_dbdiropq(dentry, -1);
35538 + dput(opq_dentry);
35539 + opq_dentry = ERR_PTR(err);
35542 + return opq_dentry;
35545 +struct do_diropq_args {
35546 + struct dentry **errp;
35547 + struct dentry *dentry;
35548 + aufs_bindex_t bindex;
35549 + unsigned int flags;
35552 +static void call_do_diropq(void *args)
35554 + struct do_diropq_args *a = args;
35555 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35558 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35559 + unsigned int flags)
35561 + struct dentry *diropq, *h_dentry;
35563 + h_dentry = au_h_dptr(dentry, bindex);
35564 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35565 + diropq = do_diropq(dentry, bindex, flags);
35568 + struct do_diropq_args args = {
35570 + .dentry = dentry,
35571 + .bindex = bindex,
35575 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35576 + if (unlikely(wkq_err))
35577 + diropq = ERR_PTR(wkq_err);
35583 +/* ---------------------------------------------------------------------- */
35586 + * lookup whiteout dentry.
35587 + * @h_parent: lower parent dentry which must exist and be locked
35588 + * @base_name: name of dentry which will be whiteouted
35589 + * returns dentry for whiteout.
35591 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35592 + struct au_branch *br)
35595 + struct qstr wh_name;
35596 + struct dentry *wh_dentry;
35598 + err = au_wh_name_alloc(&wh_name, base_name);
35599 + wh_dentry = ERR_PTR(err);
35601 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35602 + au_kfree_try_rcu(wh_name.name);
35604 + return wh_dentry;
35608 + * link/create a whiteout for @dentry on @bindex.
35610 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35611 + struct dentry *h_parent)
35613 + struct dentry *wh_dentry;
35614 + struct super_block *sb;
35617 + sb = dentry->d_sb;
35618 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35619 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35620 + err = link_or_create_wh(sb, bindex, wh_dentry);
35622 + au_set_dbwh(dentry, bindex);
35623 + au_fhsm_wrote(sb, bindex, /*force*/0);
35626 + wh_dentry = ERR_PTR(err);
35630 + return wh_dentry;
35633 +/* ---------------------------------------------------------------------- */
35635 +/* Delete all whiteouts in this directory on branch bindex. */
35636 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35637 + aufs_bindex_t bindex, struct au_branch *br)
35640 + unsigned long ul, n;
35641 + struct qstr wh_name;
35643 + struct hlist_head *head;
35644 + struct au_vdir_wh *pos;
35645 + struct au_vdir_destr *str;
35648 + p = (void *)__get_free_page(GFP_NOFS);
35649 + wh_name.name = p;
35650 + if (unlikely(!wh_name.name))
35654 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35655 + p += AUFS_WH_PFX_LEN;
35656 + n = whlist->nh_num;
35657 + head = whlist->nh_head;
35658 + for (ul = 0; !err && ul < n; ul++, head++) {
35659 + hlist_for_each_entry(pos, head, wh_hash) {
35660 + if (pos->wh_bindex != bindex)
35663 + str = &pos->wh_str;
35664 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35665 + memcpy(p, str->name, str->len);
35666 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35667 + err = unlink_wh_name(h_dentry, &wh_name, br);
35672 + AuIOErr("whiteout name too long %.*s\n",
35673 + str->len, str->name);
35678 + free_page((unsigned long)wh_name.name);
35684 +struct del_wh_children_args {
35686 + struct dentry *h_dentry;
35687 + struct au_nhash *whlist;
35688 + aufs_bindex_t bindex;
35689 + struct au_branch *br;
35692 +static void call_del_wh_children(void *args)
35694 + struct del_wh_children_args *a = args;
35695 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35698 +/* ---------------------------------------------------------------------- */
35700 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35702 + struct au_whtmp_rmdir *whtmp;
35704 + unsigned int rdhash;
35706 + SiMustAnyLock(sb);
35708 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35709 + if (unlikely(!whtmp)) {
35710 + whtmp = ERR_PTR(-ENOMEM);
35714 + /* no estimation for dir size */
35715 + rdhash = au_sbi(sb)->si_rdhash;
35717 + rdhash = AUFS_RDHASH_DEF;
35718 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35719 + if (unlikely(err)) {
35720 + au_kfree_rcu(whtmp);
35721 + whtmp = ERR_PTR(err);
35728 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35731 + au_lcnt_dec(&whtmp->br->br_count);
35732 + dput(whtmp->wh_dentry);
35733 + iput(whtmp->dir);
35734 + au_nhash_wh_free(&whtmp->whlist);
35735 + au_kfree_rcu(whtmp);
35739 + * rmdir the whiteouted temporary named dir @h_dentry.
35740 + * @whlist: whiteouted children.
35742 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35743 + struct dentry *wh_dentry, struct au_nhash *whlist)
35746 + unsigned int h_nlink;
35747 + struct path h_tmp;
35748 + struct inode *wh_inode, *h_dir;
35749 + struct au_branch *br;
35751 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35752 + IMustLock(h_dir);
35754 + br = au_sbr(dir->i_sb, bindex);
35755 + wh_inode = d_inode(wh_dentry);
35756 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35759 + * someone else might change some whiteouts while we were sleeping.
35760 + * it means this whlist may have an obsoleted entry.
35762 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35763 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35766 + struct del_wh_children_args args = {
35768 + .h_dentry = wh_dentry,
35769 + .whlist = whlist,
35770 + .bindex = bindex,
35774 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35775 + if (unlikely(wkq_err))
35778 + inode_unlock(wh_inode);
35781 + h_tmp.dentry = wh_dentry;
35782 + h_tmp.mnt = au_br_mnt(br);
35783 + h_nlink = h_dir->i_nlink;
35784 + err = vfsub_rmdir(h_dir, &h_tmp);
35785 + /* some fs doesn't change the parent nlink in some cases */
35786 + h_nlink -= h_dir->i_nlink;
35790 + if (au_ibtop(dir) == bindex) {
35791 + /* todo: dir->i_mutex is necessary */
35792 + au_cpup_attr_timesizes(dir);
35794 + vfsub_drop_nlink(dir);
35796 + return 0; /* success */
35799 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35803 +static void call_rmdir_whtmp(void *args)
35806 + aufs_bindex_t bindex;
35807 + struct au_whtmp_rmdir *a = args;
35808 + struct super_block *sb;
35809 + struct dentry *h_parent;
35810 + struct inode *h_dir;
35811 + struct au_hinode *hdir;
35813 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35814 + /* inode_lock(a->dir); */
35816 + sb = a->dir->i_sb;
35817 + si_read_lock(sb, !AuLock_FLUSH);
35818 + if (!au_br_writable(a->br->br_perm))
35820 + bindex = au_br_index(sb, a->br->br_id);
35821 + if (unlikely(bindex < 0))
35825 + ii_write_lock_parent(a->dir);
35826 + h_parent = dget_parent(a->wh_dentry);
35827 + h_dir = d_inode(h_parent);
35828 + hdir = au_hi(a->dir, bindex);
35829 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35830 + if (unlikely(err))
35832 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35833 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35836 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35837 + au_hn_inode_unlock(hdir);
35838 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35842 + ii_write_unlock(a->dir);
35844 + /* inode_unlock(a->dir); */
35845 + au_whtmp_rmdir_free(a);
35846 + si_read_unlock(sb);
35847 + au_nwt_done(&au_sbi(sb)->si_nowait);
35848 + if (unlikely(err))
35849 + AuIOErr("err %d\n", err);
35852 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35853 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35856 + struct super_block *sb;
35860 + /* all post-process will be done in do_rmdir_whtmp(). */
35862 + args->dir = au_igrab(dir);
35863 + args->br = au_sbr(sb, bindex);
35864 + au_lcnt_inc(&args->br->br_count);
35865 + args->wh_dentry = dget(wh_dentry);
35866 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35867 + if (unlikely(wkq_err)) {
35868 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35869 + au_whtmp_rmdir_free(args);
35872 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35873 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35874 +++ linux/fs/aufs/whout.h 2020-01-27 10:57:18.178871751 +0100
35876 +/* SPDX-License-Identifier: GPL-2.0 */
35878 + * Copyright (C) 2005-2020 Junjiro R. Okajima
35880 + * This program, aufs is free software; you can redistribute it and/or modify
35881 + * it under the terms of the GNU General Public License as published by
35882 + * the Free Software Foundation; either version 2 of the License, or
35883 + * (at your option) any later version.
35885 + * This program is distributed in the hope that it will be useful,
35886 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35887 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35888 + * GNU General Public License for more details.
35890 + * You should have received a copy of the GNU General Public License
35891 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35895 + * whiteout for logical deletion and opaque directory
35898 +#ifndef __AUFS_WHOUT_H__
35899 +#define __AUFS_WHOUT_H__
35906 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35907 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
35908 +int au_diropq_test(struct dentry *h_dentry);
35910 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35911 + struct qstr *prefix);
35912 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35913 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35914 + struct dentry *dentry);
35915 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35917 +/* diropq flags */
35918 +#define AuDiropq_CREATE 1
35919 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35920 +#define au_fset_diropq(flags, name) \
35921 + do { (flags) |= AuDiropq_##name; } while (0)
35922 +#define au_fclr_diropq(flags, name) \
35923 + do { (flags) &= ~AuDiropq_##name; } while (0)
35925 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35926 + unsigned int flags);
35927 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35928 + struct au_branch *br);
35929 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35930 + struct dentry *h_parent);
35932 +/* real rmdir for the whiteout-ed dir */
35933 +struct au_whtmp_rmdir {
35934 + struct inode *dir;
35935 + struct au_branch *br;
35936 + struct dentry *wh_dentry;
35937 + struct au_nhash whlist;
35940 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35941 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35942 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35943 + struct dentry *wh_dentry, struct au_nhash *whlist);
35944 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35945 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35947 +/* ---------------------------------------------------------------------- */
35949 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35950 + aufs_bindex_t bindex)
35952 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35955 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35957 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35960 +#endif /* __KERNEL__ */
35961 +#endif /* __AUFS_WHOUT_H__ */
35962 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35963 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35964 +++ linux/fs/aufs/wkq.c 2020-08-03 09:12:33.764880472 +0200
35966 +// SPDX-License-Identifier: GPL-2.0
35968 + * Copyright (C) 2005-2020 Junjiro R. Okajima
35970 + * This program, aufs is free software; you can redistribute it and/or modify
35971 + * it under the terms of the GNU General Public License as published by
35972 + * the Free Software Foundation; either version 2 of the License, or
35973 + * (at your option) any later version.
35975 + * This program is distributed in the hope that it will be useful,
35976 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35977 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35978 + * GNU General Public License for more details.
35980 + * You should have received a copy of the GNU General Public License
35981 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35985 + * workqueue for asynchronous/super-io operations
35986 + * todo: try new credential scheme
35989 +#include <linux/module.h>
35992 +/* internal workqueue named AUFS_WKQ_NAME */
35994 +static struct workqueue_struct *au_wkq;
35996 +struct au_wkinfo {
35997 + struct work_struct wk;
35998 + struct kobject *kobj;
36000 + unsigned int flags; /* see wkq.h */
36002 + au_wkq_func_t func;
36005 +#ifdef CONFIG_LOCKDEP
36007 + struct held_lock **hlock;
36010 + struct completion *comp;
36013 +/* ---------------------------------------------------------------------- */
36015 + * Aufs passes some operations to the workqueue such as the internal copyup.
36016 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36017 + * job run by workqueue depends upon the locks acquired in the other task.
36018 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36019 + * information too. And the job in the workqueue restores the info in order to
36020 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36021 + * correctly and expectedly.
36024 +#ifndef CONFIG_LOCKDEP
36025 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36026 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36027 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36028 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36029 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36031 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36033 + wkinfo->hlock = NULL;
36034 + wkinfo->dont_check = 0;
36041 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36043 + static DEFINE_SPINLOCK(spin);
36046 + struct lock_class_key *key;
36048 + { .name = "&sbinfo->si_rwsem" },
36049 + { .name = "&finfo->fi_rwsem" },
36050 + { .name = "&dinfo->di_rwsem" },
36051 + { .name = "&iinfo->ii_rwsem" }
36056 + /* lockless read from 'set.' see below */
36057 + if (set == ARRAY_SIZE(a)) {
36058 + for (i = 0; i < ARRAY_SIZE(a); i++)
36059 + if (a[i].key == key)
36064 + spin_lock(&spin);
36066 + for (i = 0; i < ARRAY_SIZE(a); i++)
36067 + if (a[i].key == key) {
36068 + spin_unlock(&spin);
36071 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36073 + if (unlikely(a[i].key == key)) { /* rare but possible */
36074 + spin_unlock(&spin);
36079 + if (strstr(a[i].name, name)) {
36081 + * the order of these three lines is important for the
36082 + * lockless read above.
36085 + spin_unlock(&spin);
36087 + /* AuDbg("%d, %s\n", set, name); */
36091 + spin_unlock(&spin);
36100 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36103 + struct task_struct *curr;
36104 + struct held_lock **hl, *held_locks, *p;
36108 + wkinfo->dont_check = lockdep_recursing(curr);
36109 + if (wkinfo->dont_check)
36111 + n = curr->lockdep_depth;
36116 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36117 + if (unlikely(!wkinfo->hlock))
36121 +#if 0 /* left for debugging */
36122 + if (0 && au_debug_test())
36123 + lockdep_print_held_locks(curr);
36125 + held_locks = curr->held_locks;
36126 + hl = wkinfo->hlock;
36128 + p = held_locks++;
36129 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36138 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36140 + au_kfree_try_rcu(wkinfo->hlock);
36143 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36145 + struct held_lock *p, **hl = wkinfo->hlock;
36148 + if (wkinfo->dont_check)
36152 + while ((p = *hl++)) { /* assignment */
36153 + subclass = lockdep_hlock_class(p)->subclass;
36154 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36156 + rwsem_acquire_read(p->instance, subclass, 0,
36157 + /*p->acquire_ip*/_RET_IP_);
36159 + rwsem_acquire(p->instance, subclass, 0,
36160 + /*p->acquire_ip*/_RET_IP_);
36164 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36166 + struct held_lock *p, **hl = wkinfo->hlock;
36168 + if (wkinfo->dont_check)
36172 + while ((p = *hl++)) /* assignment */
36173 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36177 +static void wkq_func(struct work_struct *wk)
36179 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36181 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36182 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36184 + au_wkq_lockdep_pre(wkinfo);
36185 + wkinfo->func(wkinfo->args);
36186 + au_wkq_lockdep_post(wkinfo);
36187 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36188 + complete(wkinfo->comp);
36190 + kobject_put(wkinfo->kobj);
36191 + module_put(THIS_MODULE); /* todo: ?? */
36192 + au_kfree_rcu(wkinfo);
36197 + * Since struct completion is large, try allocating it dynamically.
36199 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36201 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36203 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36205 + init_completion(*comp);
36206 + wkinfo->comp = *comp;
36212 +static void au_wkq_comp_free(struct completion *comp)
36214 + au_kfree_rcu(comp);
36217 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36219 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36220 + if (au_wkq_test()) {
36221 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36222 + " due to a dead dir by UDBA,"
36223 + " or async xino write?\n");
36224 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36227 + au_dbg_verify_kthread();
36229 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36230 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36231 + queue_work(au_wkq, &wkinfo->wk);
36233 + INIT_WORK(&wkinfo->wk, wkq_func);
36234 + schedule_work(&wkinfo->wk);
36239 + * Be careful. It is easy to make deadlock happen.
36240 + * processA: lock, wkq and wait
36241 + * processB: wkq and wait, lock in wkq
36244 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36247 + AuWkqCompDeclare(comp);
36248 + struct au_wkinfo wkinfo = {
36254 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36255 + if (unlikely(err))
36257 + err = au_wkq_lockdep_alloc(&wkinfo);
36258 + if (unlikely(err))
36261 + au_wkq_run(&wkinfo);
36262 + /* no timeout, no interrupt */
36263 + wait_for_completion(wkinfo.comp);
36265 + au_wkq_lockdep_free(&wkinfo);
36268 + au_wkq_comp_free(comp);
36270 + destroy_work_on_stack(&wkinfo.wk);
36275 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36276 + * problem in a concurrent umounting.
36278 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36279 + unsigned int flags)
36282 + struct au_wkinfo *wkinfo;
36284 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36287 + * wkq_func() must free this wkinfo.
36288 + * it highly depends upon the implementation of workqueue.
36291 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36293 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36294 + wkinfo->flags = flags & ~AuWkq_WAIT;
36295 + wkinfo->func = func;
36296 + wkinfo->args = args;
36297 + wkinfo->comp = NULL;
36298 + au_wkq_lockdep_init(wkinfo);
36299 + kobject_get(wkinfo->kobj);
36300 + __module_get(THIS_MODULE); /* todo: ?? */
36302 + au_wkq_run(wkinfo);
36305 + au_nwt_done(&au_sbi(sb)->si_nowait);
36311 +/* ---------------------------------------------------------------------- */
36313 +void au_nwt_init(struct au_nowait_tasks *nwt)
36315 + atomic_set(&nwt->nw_len, 0);
36316 + /* smp_mb(); */ /* atomic_set */
36317 + init_waitqueue_head(&nwt->nw_wq);
36320 +void au_wkq_fin(void)
36322 + destroy_workqueue(au_wkq);
36325 +int __init au_wkq_init(void)
36330 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36331 + if (IS_ERR(au_wkq))
36332 + err = PTR_ERR(au_wkq);
36333 + else if (!au_wkq)
36338 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36339 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36340 +++ linux/fs/aufs/wkq.h 2020-01-27 10:57:18.182205184 +0100
36342 +/* SPDX-License-Identifier: GPL-2.0 */
36344 + * Copyright (C) 2005-2020 Junjiro R. Okajima
36346 + * This program, aufs is free software; you can redistribute it and/or modify
36347 + * it under the terms of the GNU General Public License as published by
36348 + * the Free Software Foundation; either version 2 of the License, or
36349 + * (at your option) any later version.
36351 + * This program is distributed in the hope that it will be useful,
36352 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36353 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36354 + * GNU General Public License for more details.
36356 + * You should have received a copy of the GNU General Public License
36357 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36361 + * workqueue for asynchronous/super-io operations
36362 + * todo: try new credentials management scheme
36365 +#ifndef __AUFS_WKQ_H__
36366 +#define __AUFS_WKQ_H__
36370 +#include <linux/wait.h>
36372 +struct super_block;
36374 +/* ---------------------------------------------------------------------- */
36377 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36379 +struct au_nowait_tasks {
36381 + wait_queue_head_t nw_wq;
36384 +/* ---------------------------------------------------------------------- */
36386 +typedef void (*au_wkq_func_t)(void *args);
36389 +#define AuWkq_WAIT 1
36390 +#define AuWkq_NEST (1 << 1)
36391 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36392 +#define au_fset_wkq(flags, name) \
36393 + do { (flags) |= AuWkq_##name; } while (0)
36394 +#define au_fclr_wkq(flags, name) \
36395 + do { (flags) &= ~AuWkq_##name; } while (0)
36398 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36399 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36400 + unsigned int flags);
36401 +void au_nwt_init(struct au_nowait_tasks *nwt);
36402 +int __init au_wkq_init(void);
36403 +void au_wkq_fin(void);
36405 +/* ---------------------------------------------------------------------- */
36407 +static inline int au_wkq_test(void)
36409 + return current->flags & PF_WQ_WORKER;
36412 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36414 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36417 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36419 + if (atomic_dec_and_test(&nwt->nw_len))
36420 + wake_up_all(&nwt->nw_wq);
36423 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36425 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36429 +#endif /* __KERNEL__ */
36430 +#endif /* __AUFS_WKQ_H__ */
36431 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36432 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36433 +++ linux/fs/aufs/xattr.c 2020-08-03 09:14:46.095748745 +0200
36435 +// SPDX-License-Identifier: GPL-2.0
36437 + * Copyright (C) 2014-2020 Junjiro R. Okajima
36439 + * This program, aufs is free software; you can redistribute it and/or modify
36440 + * it under the terms of the GNU General Public License as published by
36441 + * the Free Software Foundation; either version 2 of the License, or
36442 + * (at your option) any later version.
36444 + * This program is distributed in the hope that it will be useful,
36445 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36446 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36447 + * GNU General Public License for more details.
36449 + * You should have received a copy of the GNU General Public License
36450 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36454 + * handling xattr functions
36457 +#include <linux/fs.h>
36458 +#include <linux/posix_acl_xattr.h>
36459 +#include <linux/xattr.h>
36462 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36464 + if (!ignore_flags)
36472 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36477 +#define cmp(brattr, prefix) do { \
36478 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36479 + XATTR_##prefix##_PREFIX_LEN)) { \
36480 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36486 + cmp(SEC, SECURITY);
36487 + cmp(SYS, SYSTEM);
36488 + cmp(TR, TRUSTED);
36492 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36499 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36501 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36502 + char *name, char **buf, unsigned int ignore_flags,
36503 + unsigned int verbose)
36507 + struct inode *h_idst;
36509 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36511 + if (unlikely(err <= 0)) {
36512 + if (err == -ENODATA
36513 + || (err == -EOPNOTSUPP
36514 + && ((ignore_flags & au_xattr_out_of_list)
36515 + || (au_test_nfs_noacl(d_inode(h_src))
36516 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36518 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36521 + if (err && (verbose || au_debug_test()))
36522 + pr_err("%s, err %d\n", name, err);
36526 + /* unlock it temporary */
36527 + h_idst = d_inode(h_dst);
36528 + inode_unlock(h_idst);
36529 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36530 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36531 + if (unlikely(err)) {
36532 + if (verbose || au_debug_test())
36533 + pr_err("%s, err %d\n", name, err);
36534 + err = au_xattr_ignore(err, name, ignore_flags);
36541 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36542 + unsigned int verbose)
36544 + int err, unlocked, acl_access, acl_default;
36546 + struct inode *h_isrc, *h_idst;
36547 + char *value, *p, *o, *e;
36549 + /* try stopping to update the source inode while we are referencing */
36550 + /* there should not be the parent-child relationship between them */
36551 + h_isrc = d_inode(h_src);
36552 + h_idst = d_inode(h_dst);
36553 + inode_unlock(h_idst);
36554 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36555 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36558 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36559 + ssz = vfs_listxattr(h_src, NULL, 0);
36561 + if (unlikely(err < 0)) {
36563 + if (err == -ENODATA
36564 + || err == -EOPNOTSUPP)
36565 + err = 0; /* ignore */
36574 + p = kmalloc(ssz, GFP_NOFS);
36576 + if (unlikely(!p))
36578 + err = vfs_listxattr(h_src, p, ssz);
36580 + inode_unlock_shared(h_isrc);
36582 + AuDbg("err %d, ssz %zd\n", err, ssz);
36583 + if (unlikely(err < 0))
36591 + while (!err && p < e) {
36592 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36593 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36594 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36595 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36597 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36599 + p += strlen(p) + 1;
36602 + ignore_flags |= au_xattr_out_of_list;
36603 + if (!err && !acl_access) {
36604 + err = au_do_cpup_xattr(h_dst, h_src,
36605 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36606 + ignore_flags, verbose);
36609 + if (!err && !acl_default) {
36610 + err = au_do_cpup_xattr(h_dst, h_src,
36611 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36612 + ignore_flags, verbose);
36616 + au_kfree_try_rcu(value);
36619 + au_kfree_try_rcu(o);
36622 + inode_unlock_shared(h_isrc);
36627 +/* ---------------------------------------------------------------------- */
36629 +static int au_smack_reentering(struct super_block *sb)
36631 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36633 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36634 + * i_op->getxattr(). ouch.
36636 + return si_pid_test(sb);
36647 +struct au_lgxattr {
36655 + const char *name;
36662 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36663 + struct au_lgxattr *arg)
36667 + struct path h_path;
36668 + struct super_block *sb;
36670 + sb = dentry->d_sb;
36671 + reenter = au_smack_reentering(sb);
36673 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36674 + if (unlikely(err))
36677 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
36678 + if (unlikely(err))
36680 + if (unlikely(!h_path.dentry))
36681 + /* illegally overlapped or something */
36682 + goto out_di; /* pretending success */
36684 + /* always topmost entry only */
36685 + switch (arg->type) {
36686 + case AU_XATTR_LIST:
36687 + err = vfs_listxattr(h_path.dentry,
36688 + arg->u.list.list, arg->u.list.size);
36690 + case AU_XATTR_GET:
36691 + AuDebugOn(d_is_negative(h_path.dentry));
36692 + err = vfs_getxattr(h_path.dentry,
36693 + arg->u.get.name, arg->u.get.value,
36694 + arg->u.get.size);
36700 + di_read_unlock(dentry, AuLock_IR);
36703 + si_read_unlock(sb);
36709 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36711 + struct au_lgxattr arg = {
36712 + .type = AU_XATTR_LIST,
36719 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
36722 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
36723 + const char *name, void *value, size_t size)
36725 + struct au_lgxattr arg = {
36726 + .type = AU_XATTR_GET,
36734 + return au_lgxattr(dentry, inode, &arg);
36737 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36738 + const char *name, const void *value, size_t size,
36741 + struct au_sxattr arg = {
36742 + .type = AU_XATTR_SET,
36751 + return au_sxattr(dentry, inode, &arg);
36754 +/* ---------------------------------------------------------------------- */
36756 +static int au_xattr_get(const struct xattr_handler *handler,
36757 + struct dentry *dentry, struct inode *inode,
36758 + const char *name, void *buffer, size_t size)
36760 + return au_getxattr(dentry, inode, name, buffer, size);
36763 +static int au_xattr_set(const struct xattr_handler *handler,
36764 + struct dentry *dentry, struct inode *inode,
36765 + const char *name, const void *value, size_t size,
36768 + return au_setxattr(dentry, inode, name, value, size, flags);
36771 +static const struct xattr_handler au_xattr_handler = {
36774 + .get = au_xattr_get,
36775 + .set = au_xattr_set
36778 +static const struct xattr_handler *au_xattr_handlers[] = {
36779 +#ifdef CONFIG_FS_POSIX_ACL
36780 + &posix_acl_access_xattr_handler,
36781 + &posix_acl_default_xattr_handler,
36783 + &au_xattr_handler, /* must be last */
36787 +void au_xattr_init(struct super_block *sb)
36789 + sb->s_xattr = au_xattr_handlers;
36791 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36792 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36793 +++ linux/fs/aufs/xino.c 2020-04-03 08:16:49.834195677 +0200
36795 +// SPDX-License-Identifier: GPL-2.0
36797 + * Copyright (C) 2005-2020 Junjiro R. Okajima
36799 + * This program, aufs is free software; you can redistribute it and/or modify
36800 + * it under the terms of the GNU General Public License as published by
36801 + * the Free Software Foundation; either version 2 of the License, or
36802 + * (at your option) any later version.
36804 + * This program is distributed in the hope that it will be useful,
36805 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36806 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36807 + * GNU General Public License for more details.
36809 + * You should have received a copy of the GNU General Public License
36810 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36814 + * external inode number translation table and bitmap
36816 + * things to consider
36818 + * + au_xino object
36819 + * + XINO files (xino, xib, xigen)
36820 + * + dynamic debugfs entries (xiN)
36821 + * + static debugfs entries (xib, xigen)
36822 + * + static sysfs entry (xi_path)
36823 + * - several entry points to handle them.
36824 + * + mount(2) without xino option (default)
36825 + * + mount(2) with xino option
36826 + * + mount(2) with noxino option
36828 + * + remount with add/del branches
36829 + * + remount with xino/noxino options
36832 +#include <linux/seq_file.h>
36833 +#include <linux/statfs.h>
36836 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36837 + aufs_bindex_t bbot,
36838 + struct super_block *h_sb)
36840 + /* todo: try binary-search if the branches are many */
36841 + for (; btop <= bbot; btop++)
36842 + if (h_sb == au_sbr_sb(sb, btop))
36848 + * find another branch who is on the same filesystem of the specified
36849 + * branch{@btgt}. search until @bbot.
36851 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36852 + aufs_bindex_t bbot)
36854 + aufs_bindex_t bindex;
36855 + struct super_block *tgt_sb;
36857 + tgt_sb = au_sbr_sb(sb, btgt);
36858 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36860 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36865 +/* ---------------------------------------------------------------------- */
36868 + * stop unnecessary notify events at creating xino files
36871 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
36873 + aufs_bindex_t bfound, bindex, bbot;
36874 + struct dentry *parent;
36875 + struct au_branch *br;
36878 + parent = dentry->d_parent; /* safe d_parent access */
36879 + bbot = au_sbbot(sb);
36880 + for (bindex = 0; bindex <= bbot; bindex++) {
36881 + br = au_sbr(sb, bindex);
36882 + if (au_br_dentry(br) == parent) {
36888 + AuDbg("bfound b%d\n", bfound);
36892 +struct au_xino_lock_dir {
36893 + struct au_hinode *hdir;
36894 + struct dentry *parent;
36895 + struct inode *dir;
36898 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
36899 + unsigned int lsc)
36901 + struct dentry *parent;
36902 + struct inode *dir;
36904 + parent = dget_parent(dentry);
36905 + dir = d_inode(parent);
36906 + inode_lock_nested(dir, lsc);
36907 +#if 0 /* it should not happen */
36908 + spin_lock(&dentry->d_lock);
36909 + if (unlikely(dentry->d_parent != parent)) {
36910 + spin_unlock(&dentry->d_lock);
36911 + inode_unlock(dir);
36916 + spin_unlock(&dentry->d_lock);
36923 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
36924 + struct au_xino_lock_dir *ldir)
36926 + aufs_bindex_t bindex;
36928 + ldir->hdir = NULL;
36929 + bindex = au_xi_root(sb, xipath->dentry);
36930 + if (bindex >= 0) {
36931 + /* rw branch root */
36932 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36933 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36936 + ldir->parent = au_dget_parent_lock(xipath->dentry,
36938 + ldir->dir = d_inode(ldir->parent);
36942 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36945 + au_hn_inode_unlock(ldir->hdir);
36947 + inode_unlock(ldir->dir);
36948 + dput(ldir->parent);
36952 +/* ---------------------------------------------------------------------- */
36955 + * create and set a new xino file
36957 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
36960 + struct file *file;
36961 + struct dentry *h_parent, *d;
36962 + struct inode *h_dir, *inode;
36964 + static DEFINE_MUTEX(mtx);
36967 + * at mount-time, and the xino file is the default path,
36968 + * hnotify is disabled so we have no notify events to ignore.
36969 + * when a user specified the xino, we cannot get au_hdir to be ignored.
36972 + mutex_lock(&mtx);
36973 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36974 + /* | __FMODE_NONOTIFY */,
36976 + if (IS_ERR(file)) {
36978 + mutex_unlock(&mtx);
36980 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
36984 + /* keep file count */
36986 + d = file->f_path.dentry;
36987 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
36989 + mutex_unlock(&mtx);
36990 + /* mnt_want_write() is unnecessary here */
36991 + h_dir = d_inode(h_parent);
36992 + inode = file_inode(file);
36993 + /* no delegation since it is just created */
36994 + if (inode->i_nlink)
36995 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
36997 + inode_unlock(h_dir);
36999 + if (unlikely(err)) {
37001 + pr_err("unlink %s(%d)\n", fpath, err);
37006 + if (unlikely(sb == d->d_sb)) {
37008 + pr_err("%s must be outside\n", fpath);
37011 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37013 + pr_err("xino doesn't support %s(%s)\n",
37014 + fpath, au_sbtype(d->d_sb));
37017 + return file; /* success */
37021 + file = ERR_PTR(err);
37026 + * create a new xinofile at the same place/path as @base.
37028 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37029 + struct file *copy_src)
37031 + struct file *file;
37032 + struct dentry *dentry, *parent;
37033 + struct inode *dir, *delegated;
37034 + struct qstr *name;
37035 + struct path path;
37036 + int err, do_unlock;
37037 + struct au_xino_lock_dir ldir;
37040 + au_xino_lock_dir(sb, base, &ldir);
37041 + dentry = base->dentry;
37042 + parent = dentry->d_parent; /* dir inode is locked */
37043 + dir = d_inode(parent);
37046 + name = &dentry->d_name;
37047 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
37048 + if (IS_ERR(path.dentry)) {
37049 + file = (void *)path.dentry;
37050 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37054 + /* no need to mnt_want_write() since we call dentry_open() later */
37055 + err = vfs_create(dir, path.dentry, 0666, NULL);
37056 + if (unlikely(err)) {
37057 + file = ERR_PTR(err);
37058 + pr_err("%pd create err %d\n", dentry, err);
37062 + path.mnt = base->mnt;
37063 + file = vfsub_dentry_open(&path,
37064 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37065 + /* | __FMODE_NONOTIFY */);
37066 + if (IS_ERR(file)) {
37067 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37071 + delegated = NULL;
37072 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37073 + au_xino_unlock_dir(&ldir);
37075 + if (unlikely(err == -EWOULDBLOCK)) {
37076 + pr_warn("cannot retry for NFSv4 delegation"
37077 + " for an internal unlink\n");
37080 + if (unlikely(err)) {
37081 + pr_err("%pd unlink err %d\n", dentry, err);
37086 + /* no one can touch copy_src xino */
37087 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37088 + if (unlikely(err)) {
37089 + pr_err("%pd copy err %d\n", dentry, err);
37093 + goto out_dput; /* success */
37097 + file = ERR_PTR(err);
37099 + dput(path.dentry);
37102 + au_xino_unlock_dir(&ldir);
37106 +struct file *au_xino_file1(struct au_xino *xi)
37108 + struct file *file;
37109 + unsigned int u, nfile;
37112 + nfile = xi->xi_nfile;
37113 + for (u = 0; u < nfile; u++) {
37114 + file = xi->xi_file[u];
37122 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37133 + if (idx < xi->xi_nfile) {
37134 + f = xi->xi_file[idx];
37138 + p = au_kzrealloc(xi->xi_file,
37139 + sizeof(*xi->xi_file) * xi->xi_nfile,
37140 + sizeof(*xi->xi_file) * (idx + 1),
37141 + GFP_NOFS, /*may_shrink*/0);
37143 + MtxMustLock(&xi->xi_mtx);
37145 + xi->xi_nfile = idx + 1;
37153 + xi->xi_file[idx] = file;
37160 + * if @xinew->xi is not set, then create new xigen file.
37162 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37164 + struct file *file;
37167 + SiMustAnyLock(sb);
37169 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37170 + if (IS_ERR(file)) {
37171 + err = PTR_ERR(file);
37172 + pr_err("%s[%d], err %d\n",
37173 + xinew->xi ? "xino" : "xigen",
37174 + xinew->idx, err);
37179 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37182 + /* todo: make xigen file an array */
37183 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37186 + if (unlikely(err))
37187 + file = ERR_PTR(err);
37193 +/* ---------------------------------------------------------------------- */
37196 + * truncate xino files
37198 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37199 + int idx, struct kstatfs *st)
37203 + struct file *file, *new_xino;
37204 + struct au_xi_new xinew = {
37209 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37210 + file = au_xino_file(xinew.xi, idx);
37214 + xinew.base = &file->f_path;
37215 + err = vfs_statfs(xinew.base, st);
37216 + if (unlikely(err)) {
37217 + AuErr1("statfs err %d, ignored\n", err);
37222 + blocks = file_inode(file)->i_blocks;
37223 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37224 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37226 + xinew.copy_src = file;
37227 + new_xino = au_xi_new(sb, &xinew);
37228 + if (IS_ERR(new_xino)) {
37229 + err = PTR_ERR(new_xino);
37230 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37234 + err = vfs_statfs(&new_xino->f_path, st);
37236 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37237 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37238 + st->f_bfree, st->f_blocks);
37240 + AuErr1("statfs err %d, ignored\n", err);
37248 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37251 + unsigned long jiffy;
37252 + aufs_bindex_t bbot;
37253 + struct kstatfs *st;
37254 + struct au_branch *br;
37255 + struct au_xino *xi;
37258 + st = kmalloc(sizeof(*st), GFP_NOFS);
37259 + if (unlikely(!st))
37263 + bbot = au_sbbot(sb);
37264 + if (unlikely(bindex < 0 || bbot < bindex))
37269 + br = au_sbr(sb, bindex);
37270 + xi = br->br_xino;
37271 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37272 + err = au_xino_do_trunc(sb, bindex, i, st);
37274 + au_sbi(sb)->si_xino_jiffy = jiffy;
37277 + au_kfree_rcu(st);
37282 +struct xino_do_trunc_args {
37283 + struct super_block *sb;
37284 + struct au_branch *br;
37288 +static void xino_do_trunc(void *_args)
37290 + struct xino_do_trunc_args *args = _args;
37291 + struct super_block *sb;
37292 + struct au_branch *br;
37293 + struct inode *dir;
37295 + aufs_bindex_t bindex;
37299 + dir = d_inode(sb->s_root);
37303 + si_noflush_write_lock(sb);
37304 + ii_read_lock_parent(dir);
37305 + bindex = au_br_index(sb, br->br_id);
37306 + err = au_xino_trunc(sb, bindex, idx);
37307 + ii_read_unlock(dir);
37308 + if (unlikely(err))
37309 + pr_warn("err b%d, (%d)\n", bindex, err);
37310 + atomic_dec(&br->br_xino->xi_truncating);
37311 + au_lcnt_dec(&br->br_count);
37312 + si_write_unlock(sb);
37313 + au_nwt_done(&au_sbi(sb)->si_nowait);
37314 + au_kfree_rcu(args);
37318 + * returns the index in the xi_file array whose corresponding file is necessary
37319 + * to truncate, or -1 which means no need to truncate.
37321 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37325 + struct kstatfs st;
37326 + struct au_sbinfo *sbinfo;
37327 + struct au_xino *xi;
37328 + struct file *file;
37330 + /* todo: si_xino_expire and the ratio should be customizable */
37331 + sbinfo = au_sbi(sb);
37332 + if (time_before(jiffies,
37333 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37336 + /* truncation border */
37337 + xi = br->br_xino;
37338 + for (u = 0; u < xi->xi_nfile; u++) {
37339 + file = au_xino_file(xi, u);
37343 + err = vfs_statfs(&file->f_path, &st);
37344 + if (unlikely(err)) {
37345 + AuErr1("statfs err %d, ignored\n", err);
37348 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37349 + >= AUFS_XINO_DEF_TRUNC)
37356 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37359 + struct xino_do_trunc_args *args;
37362 + idx = xino_trunc_test(sb, br);
37366 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37369 + /* lock and kfree() will be called in trunc_xino() */
37370 + args = kmalloc(sizeof(*args), GFP_NOFS);
37371 + if (unlikely(!args)) {
37372 + AuErr1("no memory\n");
37376 + au_lcnt_inc(&br->br_count);
37380 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37382 + return; /* success */
37384 + pr_err("wkq %d\n", wkq_err);
37385 + au_lcnt_dec(&br->br_count);
37386 + au_kfree_rcu(args);
37389 + atomic_dec(&br->br_xino->xi_truncating);
37392 +/* ---------------------------------------------------------------------- */
37394 +struct au_xi_calc {
37399 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37400 + struct au_xi_calc *calc)
37404 + maxent = au_xi_maxent(sb);
37405 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37406 + calc->pos *= sizeof(ino_t);
37409 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37410 + struct au_xi_calc *calc)
37413 + struct file *file;
37414 + struct au_xino *xi = br->br_xino;
37415 + struct au_xi_new xinew = {
37419 + SiMustAnyLock(sb);
37425 + mutex_lock(&xi->xi_mtx);
37426 + file = au_xino_file(xi, calc->idx);
37430 + file = au_xino_file(xi, /*idx*/-1);
37431 + AuDebugOn(!file);
37432 + xinew.idx = calc->idx;
37433 + xinew.base = &file->f_path;
37434 + /* xinew.copy_src = NULL; */
37435 + file = au_xi_new(sb, &xinew);
37436 + if (IS_ERR(file))
37437 + err = PTR_ERR(file);
37440 + mutex_unlock(&xi->xi_mtx);
37445 +struct au_xino_do_new_async_args {
37446 + struct super_block *sb;
37447 + struct au_branch *br;
37448 + struct au_xi_calc calc;
37452 +struct au_xi_writing {
37453 + struct hlist_bl_node node;
37454 + ino_t h_ino, ino;
37457 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37458 + struct au_xi_calc *calc, ino_t ino);
37460 +static void au_xino_call_do_new_async(void *args)
37462 + struct au_xino_do_new_async_args *a = args;
37463 + struct au_branch *br;
37464 + struct super_block *sb;
37465 + struct au_sbinfo *sbi;
37466 + struct inode *root;
37467 + struct file *file;
37468 + struct au_xi_writing *del, *p;
37469 + struct hlist_bl_head *hbl;
37470 + struct hlist_bl_node *pos;
37475 + sbi = au_sbi(sb);
37476 + si_noflush_read_lock(sb);
37477 + root = d_inode(sb->s_root);
37478 + ii_read_lock_child(root);
37479 + err = au_xino_do_new_async(sb, br, &a->calc);
37480 + if (unlikely(err)) {
37481 + AuIOErr("err %d\n", err);
37485 + file = au_xino_file(br->br_xino, a->calc.idx);
37486 + AuDebugOn(!file);
37487 + err = au_xino_do_write(sbi->si_xwrite, file, &a->calc, a->ino);
37488 + if (unlikely(err)) {
37489 + AuIOErr("err %d\n", err);
37494 + hbl = &br->br_xino->xi_writing;
37495 + hlist_bl_lock(hbl);
37496 + au_hbl_for_each(pos, hbl) {
37497 + p = container_of(pos, struct au_xi_writing, node);
37498 + if (p->ino == a->ino) {
37500 + hlist_bl_del(&p->node);
37504 + hlist_bl_unlock(hbl);
37505 + au_kfree_rcu(del);
37508 + au_lcnt_dec(&br->br_count);
37509 + ii_read_unlock(root);
37510 + si_read_unlock(sb);
37511 + au_nwt_done(&sbi->si_nowait);
37516 + * create a new xino file asynchronously
37518 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37519 + struct au_xi_calc *calc, ino_t ino)
37522 + struct au_xino_do_new_async_args *arg;
37525 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37526 + if (unlikely(!arg))
37531 + arg->calc = *calc;
37533 + au_lcnt_inc(&br->br_count);
37534 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37535 + if (unlikely(err)) {
37536 + pr_err("wkq %d\n", err);
37537 + au_lcnt_dec(&br->br_count);
37538 + au_kfree_rcu(arg);
37546 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37547 + * at the position of @h_ino.
37549 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37554 + struct au_xi_calc calc;
37555 + struct au_sbinfo *sbinfo;
37556 + struct file *file;
37557 + struct au_xino *xi;
37558 + struct hlist_bl_head *hbl;
37559 + struct hlist_bl_node *pos;
37560 + struct au_xi_writing *p;
37563 + if (!au_opt_test(au_mntflags(sb), XINO))
37564 + return 0; /* no xino */
37567 + au_xi_calc(sb, h_ino, &calc);
37568 + xi = au_sbr(sb, bindex)->br_xino;
37569 + file = au_xino_file(xi, calc.idx);
37571 + hbl = &xi->xi_writing;
37572 + hlist_bl_lock(hbl);
37573 + au_hbl_for_each(pos, hbl) {
37574 + p = container_of(pos, struct au_xi_writing, node);
37575 + if (p->h_ino == h_ino) {
37576 + AuDbg("hi%llu, i%llu, found\n",
37577 + (u64)p->h_ino, (u64)p->ino);
37582 + hlist_bl_unlock(hbl);
37584 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37585 + return 0; /* no xino */
37587 + sbinfo = au_sbi(sb);
37588 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &calc.pos);
37589 + if (sz == sizeof(*ino))
37590 + return 0; /* success */
37593 + if (unlikely(sz >= 0)) {
37595 + AuIOErr("xino read error (%zd)\n", sz);
37600 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37601 + struct au_xi_calc *calc, ino_t ino)
37605 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &calc->pos);
37606 + if (sz == sizeof(ino))
37607 + return 0; /* success */
37609 + AuIOErr("write failed (%zd)\n", sz);
37614 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37615 + * at the position of @h_ino.
37616 + * even if @ino is zero, it is written to the xinofile and means no entry.
37617 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37618 + * try truncating it.
37620 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37624 + unsigned int mnt_flags;
37625 + struct au_xi_calc calc;
37626 + struct file *file;
37627 + struct au_branch *br;
37628 + struct au_xino *xi;
37629 + struct au_xi_writing *p;
37631 + SiMustAnyLock(sb);
37633 + mnt_flags = au_mntflags(sb);
37634 + if (!au_opt_test(mnt_flags, XINO))
37637 + au_xi_calc(sb, h_ino, &calc);
37638 + br = au_sbr(sb, bindex);
37639 + xi = br->br_xino;
37640 + file = au_xino_file(xi, calc.idx);
37642 + /* store the inum pair into the list */
37643 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37644 + p->h_ino = h_ino;
37646 + au_hbl_add(&p->node, &xi->xi_writing);
37648 + /* create and write a new xino file asynchronously */
37649 + err = au_xino_new_async(sb, br, &calc, ino);
37651 + return 0; /* success */
37655 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, file, &calc, ino);
37657 + br = au_sbr(sb, bindex);
37658 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37659 + && au_test_fs_trunc_xino(au_br_sb(br)))
37660 + xino_try_trunc(sb, br);
37661 + return 0; /* success */
37665 + AuIOErr("write failed (%d)\n", err);
37669 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37670 + size_t size, loff_t *pos);
37672 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37673 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
37677 + mm_segment_t oldfs;
37683 + const int prevent_endless = 10;
37687 + oldfs = get_fs();
37688 + set_fs(KERNEL_DS);
37690 + err = func(file, buf.u, size, pos);
37691 + if (err == -EINTR
37692 + && !au_wkq_test()
37693 + && fatal_signal_pending(current)) {
37695 + err = xino_fread_wkq(func, file, kbuf, size, pos);
37696 + BUG_ON(err == -EINTR);
37697 + oldfs = get_fs();
37698 + set_fs(KERNEL_DS);
37700 + } while (i++ < prevent_endless
37701 + && (err == -EAGAIN || err == -EINTR));
37704 +#if 0 /* reserved for future use */
37706 + fsnotify_access(file->f_path.dentry);
37712 +struct xino_fread_args {
37714 + vfs_readf_t func;
37715 + struct file *file;
37721 +static void call_xino_fread(void *args)
37723 + struct xino_fread_args *a = args;
37724 + *a->errp = xino_fread(a->func, a->file, a->buf, a->size, a->pos);
37727 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37728 + size_t size, loff_t *pos)
37732 + struct xino_fread_args args = {
37741 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37742 + if (unlikely(wkq_err))
37748 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37749 + size_t size, loff_t *pos);
37751 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
37752 + size_t size, loff_t *pos)
37755 + mm_segment_t oldfs;
37758 + const char __user *u;
37761 + const int prevent_endless = 10;
37765 + oldfs = get_fs();
37766 + set_fs(KERNEL_DS);
37768 + err = func(file, buf.u, size, pos);
37769 + if (err == -EINTR
37770 + && !au_wkq_test()
37771 + && fatal_signal_pending(current)) {
37773 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
37774 + BUG_ON(err == -EINTR);
37775 + oldfs = get_fs();
37776 + set_fs(KERNEL_DS);
37778 + } while (i++ < prevent_endless
37779 + && (err == -EAGAIN || err == -EINTR));
37782 +#if 0 /* reserved for future use */
37784 + fsnotify_modify(file->f_path.dentry);
37790 +struct do_xino_fwrite_args {
37792 + vfs_writef_t func;
37793 + struct file *file;
37799 +static void call_do_xino_fwrite(void *args)
37801 + struct do_xino_fwrite_args *a = args;
37802 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
37805 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37806 + size_t size, loff_t *pos)
37810 + struct do_xino_fwrite_args args = {
37820 + * it breaks RLIMIT_FSIZE and normal user's limit,
37821 + * users should care about quota and real 'filesystem full.'
37823 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37824 + if (unlikely(wkq_err))
37830 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
37831 + size_t size, loff_t *pos)
37835 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37837 + err = do_xino_fwrite(func, file, buf, size, pos);
37841 + err = xino_fwrite_wkq(func, file, buf, size, pos);
37848 +/* ---------------------------------------------------------------------- */
37851 + * inode number bitmap
37853 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37854 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37858 + AuDebugOn(bit < 0 || page_bits <= bit);
37859 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37863 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37865 + AuDebugOn(ino < AUFS_FIRST_INO);
37866 + ino -= AUFS_FIRST_INO;
37867 + *pindex = ino / page_bits;
37868 + *bit = ino % page_bits;
37871 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37876 + struct au_sbinfo *sbinfo;
37877 + struct file *xib;
37878 + unsigned long *p;
37880 + sbinfo = au_sbi(sb);
37881 + MtxMustLock(&sbinfo->si_xib_mtx);
37882 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37883 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37885 + if (pindex == sbinfo->si_xib_last_pindex)
37888 + xib = sbinfo->si_xib;
37889 + p = sbinfo->si_xib_buf;
37890 + pos = sbinfo->si_xib_last_pindex;
37891 + pos *= PAGE_SIZE;
37892 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37893 + if (unlikely(sz != PAGE_SIZE))
37897 + pos *= PAGE_SIZE;
37898 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37899 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
37901 + memset(p, 0, PAGE_SIZE);
37902 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37904 + if (sz == PAGE_SIZE) {
37905 + sbinfo->si_xib_last_pindex = pindex;
37906 + return 0; /* success */
37910 + AuIOErr1("write failed (%zd)\n", sz);
37917 +static void au_xib_clear_bit(struct inode *inode)
37920 + unsigned long pindex;
37921 + struct super_block *sb;
37922 + struct au_sbinfo *sbinfo;
37924 + AuDebugOn(inode->i_nlink);
37926 + sb = inode->i_sb;
37927 + xib_calc_bit(inode->i_ino, &pindex, &bit);
37928 + AuDebugOn(page_bits <= bit);
37929 + sbinfo = au_sbi(sb);
37930 + mutex_lock(&sbinfo->si_xib_mtx);
37931 + err = xib_pindex(sb, pindex);
37933 + clear_bit(bit, sbinfo->si_xib_buf);
37934 + sbinfo->si_xib_next_bit = bit;
37936 + mutex_unlock(&sbinfo->si_xib_mtx);
37939 +/* ---------------------------------------------------------------------- */
37942 + * truncate a xino bitmap file
37946 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
37950 + unsigned long pindex;
37951 + loff_t pos, pend;
37952 + struct au_sbinfo *sbinfo;
37953 + vfs_readf_t func;
37955 + unsigned long *p;
37958 + sbinfo = au_sbi(sb);
37959 + MtxMustLock(&sbinfo->si_xib_mtx);
37960 + p = sbinfo->si_xib_buf;
37961 + func = sbinfo->si_xread;
37962 + pend = vfsub_f_size_read(file);
37964 + while (pos < pend) {
37965 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
37967 + if (unlikely(sz <= 0))
37971 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
37972 + if (unlikely(*ino < AUFS_FIRST_INO))
37975 + xib_calc_bit(*ino, &pindex, &bit);
37976 + AuDebugOn(page_bits <= bit);
37977 + err = xib_pindex(sb, pindex);
37989 +static int xib_restore(struct super_block *sb)
37992 + unsigned int nfile;
37993 + aufs_bindex_t bindex, bbot;
37995 + struct au_branch *br;
37996 + struct au_xino *xi;
37997 + struct file *file;
38000 + page = (void *)__get_free_page(GFP_NOFS);
38001 + if (unlikely(!page))
38005 + bbot = au_sbbot(sb);
38006 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38007 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38008 + br = au_sbr(sb, bindex);
38009 + xi = br->br_xino;
38010 + nfile = xi->xi_nfile;
38011 + for (i = 0; i < nfile; i++) {
38012 + file = au_xino_file(xi, i);
38014 + err = do_xib_restore(sb, file, page);
38017 + AuDbg("skip shared b%d\n", bindex);
38018 + free_page((unsigned long)page);
38024 +int au_xib_trunc(struct super_block *sb)
38029 + struct au_sbinfo *sbinfo;
38030 + unsigned long *p;
38031 + struct file *file;
38033 + SiMustWriteLock(sb);
38036 + sbinfo = au_sbi(sb);
38037 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38040 + file = sbinfo->si_xib;
38041 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38044 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38045 + err = PTR_ERR(file);
38046 + if (IS_ERR(file))
38048 + fput(sbinfo->si_xib);
38049 + sbinfo->si_xib = file;
38051 + p = sbinfo->si_xib_buf;
38052 + memset(p, 0, PAGE_SIZE);
38054 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
38055 + if (unlikely(sz != PAGE_SIZE)) {
38057 + AuIOErr("err %d\n", err);
38063 + mutex_lock(&sbinfo->si_xib_mtx);
38064 + /* mnt_want_write() is unnecessary here */
38065 + err = xib_restore(sb);
38066 + mutex_unlock(&sbinfo->si_xib_mtx);
38072 +/* ---------------------------------------------------------------------- */
38074 +struct au_xino *au_xino_alloc(unsigned int nfile)
38076 + struct au_xino *xi;
38078 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38079 + if (unlikely(!xi))
38081 + xi->xi_nfile = nfile;
38082 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38083 + if (unlikely(!xi->xi_file))
38086 + xi->xi_nondir.total = 8; /* initial size */
38087 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38089 + if (unlikely(!xi->xi_nondir.array))
38092 + spin_lock_init(&xi->xi_nondir.spin);
38093 + init_waitqueue_head(&xi->xi_nondir.wqh);
38094 + mutex_init(&xi->xi_mtx);
38095 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38096 + atomic_set(&xi->xi_truncating, 0);
38097 + kref_init(&xi->xi_kref);
38098 + goto out; /* success */
38101 + au_kfree_try_rcu(xi->xi_file);
38103 + au_kfree_rcu(xi);
38109 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38112 + struct au_xino *xi;
38115 + xi = au_xino_alloc(idx + 1);
38116 + if (unlikely(!xi)) {
38123 + xi->xi_file[idx] = file;
38124 + AuDebugOn(br->br_xino);
38125 + br->br_xino = xi;
38131 +static void au_xino_release(struct kref *kref)
38133 + struct au_xino *xi;
38135 + unsigned long ul;
38136 + struct hlist_bl_head *hbl;
38137 + struct hlist_bl_node *pos, *n;
38138 + struct au_xi_writing *p;
38140 + xi = container_of(kref, struct au_xino, xi_kref);
38141 + for (i = 0; i < xi->xi_nfile; i++)
38142 + if (xi->xi_file[i])
38143 + fput(xi->xi_file[i]);
38144 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38145 + AuDebugOn(xi->xi_nondir.array[i]);
38146 + mutex_destroy(&xi->xi_mtx);
38147 + hbl = &xi->xi_writing;
38148 + ul = au_hbl_count(hbl);
38149 + if (unlikely(ul)) {
38150 + pr_warn("xi_writing %lu\n", ul);
38151 + hlist_bl_lock(hbl);
38152 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
38153 + hlist_bl_del(&p->node);
38154 + /* kmemleak reported au_kfree_rcu() doesn't free it */
38157 + hlist_bl_unlock(hbl);
38159 + au_kfree_try_rcu(xi->xi_file);
38160 + au_kfree_try_rcu(xi->xi_nondir.array);
38161 + au_kfree_rcu(xi);
38164 +int au_xino_put(struct au_branch *br)
38167 + struct au_xino *xi;
38170 + xi = br->br_xino;
38172 + br->br_xino = NULL;
38173 + ret = kref_put(&xi->xi_kref, au_xino_release);
38179 +/* ---------------------------------------------------------------------- */
38182 + * xino mount option handlers
38186 +static void xino_clear_xib(struct super_block *sb)
38188 + struct au_sbinfo *sbinfo;
38190 + SiMustWriteLock(sb);
38192 + sbinfo = au_sbi(sb);
38193 + /* unnecessary to clear sbinfo->si_xread and ->si_xwrite */
38194 + if (sbinfo->si_xib)
38195 + fput(sbinfo->si_xib);
38196 + sbinfo->si_xib = NULL;
38197 + if (sbinfo->si_xib_buf)
38198 + free_page((unsigned long)sbinfo->si_xib_buf);
38199 + sbinfo->si_xib_buf = NULL;
38202 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38206 + struct au_sbinfo *sbinfo;
38207 + struct file *file;
38208 + struct super_block *xi_sb;
38210 + SiMustWriteLock(sb);
38212 + sbinfo = au_sbi(sb);
38213 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38214 + err = PTR_ERR(file);
38215 + if (IS_ERR(file))
38217 + if (sbinfo->si_xib)
38218 + fput(sbinfo->si_xib);
38219 + sbinfo->si_xib = file;
38220 + sbinfo->si_xread = vfs_readf(file);
38221 + sbinfo->si_xwrite = vfs_writef(file);
38222 + xi_sb = file_inode(file)->i_sb;
38223 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38224 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38226 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38227 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38230 + sbinfo->si_ximaxent /= sizeof(ino_t);
38233 + if (!sbinfo->si_xib_buf)
38234 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38235 + if (unlikely(!sbinfo->si_xib_buf))
38238 + sbinfo->si_xib_last_pindex = 0;
38239 + sbinfo->si_xib_next_bit = 0;
38240 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38242 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
38243 + PAGE_SIZE, &pos);
38244 + if (unlikely(err != PAGE_SIZE))
38248 + goto out; /* success */
38251 + if (sbinfo->si_xib_buf)
38252 + free_page((unsigned long)sbinfo->si_xib_buf);
38253 + sbinfo->si_xib_buf = NULL;
38257 + fput(sbinfo->si_xib);
38258 + sbinfo->si_xib = NULL;
38264 +/* xino for each branch */
38265 +static void xino_clear_br(struct super_block *sb)
38267 + aufs_bindex_t bindex, bbot;
38268 + struct au_branch *br;
38270 + bbot = au_sbbot(sb);
38271 + for (bindex = 0; bindex <= bbot; bindex++) {
38272 + br = au_sbr(sb, bindex);
38278 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38279 + aufs_bindex_t bshared)
38281 + struct au_branch *brshared;
38283 + brshared = au_sbr(sb, bshared);
38284 + AuDebugOn(!brshared->br_xino);
38285 + AuDebugOn(!brshared->br_xino->xi_file);
38286 + if (br->br_xino != brshared->br_xino) {
38287 + au_xino_get(brshared);
38289 + br->br_xino = brshared->br_xino;
38293 +struct au_xino_do_set_br {
38294 + vfs_writef_t writef;
38295 + struct au_branch *br;
38297 + aufs_bindex_t bshared;
38300 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38301 + struct au_xino_do_set_br *args)
38304 + struct au_xi_calc calc;
38305 + struct file *file;
38306 + struct au_branch *br;
38307 + struct au_xi_new xinew = {
38312 + xinew.xi = br->br_xino;
38313 + au_xi_calc(sb, args->h_ino, &calc);
38314 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38315 + if (args->bshared >= 0)
38316 + /* shared xino */
38317 + au_xino_set_br_shared(sb, br, args->bshared);
38318 + else if (!xinew.xi) {
38320 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38321 + if (unlikely(err))
38325 + /* force re-creating */
38326 + xinew.xi = br->br_xino;
38327 + xinew.idx = calc.idx;
38328 + mutex_lock(&xinew.xi->xi_mtx);
38329 + file = au_xi_new(sb, &xinew);
38330 + mutex_unlock(&xinew.xi->xi_mtx);
38331 + err = PTR_ERR(file);
38332 + if (IS_ERR(file))
38334 + AuDebugOn(!file);
38336 + err = au_xino_do_write(args->writef, file, &calc, AUFS_ROOT_INO);
38337 + if (unlikely(err))
38345 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38348 + aufs_bindex_t bindex, bbot;
38349 + struct au_xino_do_set_br args;
38350 + struct inode *inode;
38352 + SiMustWriteLock(sb);
38354 + bbot = au_sbbot(sb);
38355 + inode = d_inode(sb->s_root);
38356 + args.writef = au_sbi(sb)->si_xwrite;
38357 + for (bindex = 0; bindex <= bbot; bindex++) {
38358 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38359 + args.br = au_sbr(sb, bindex);
38360 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38361 + err = au_xino_do_set_br(sb, path, &args);
38362 + if (unlikely(err))
38370 +void au_xino_clr(struct super_block *sb)
38372 + struct au_sbinfo *sbinfo;
38374 + au_xigen_clr(sb);
38375 + xino_clear_xib(sb);
38376 + xino_clear_br(sb);
38377 + dbgaufs_brs_del(sb, 0);
38378 + sbinfo = au_sbi(sb);
38379 + /* lvalue, do not call au_mntflags() */
38380 + au_opt_clr(sbinfo->si_mntflags, XINO);
38383 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38386 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38387 + struct qstr *dname, *cur_name;
38388 + struct file *cur_xino;
38389 + struct au_sbinfo *sbinfo;
38390 + struct path *path, *cur_path;
38392 + SiMustWriteLock(sb);
38395 + sbinfo = au_sbi(sb);
38396 + path = &xiopt->file->f_path;
38397 + dentry = path->dentry;
38398 + parent = dget_parent(dentry);
38401 + cur_xino = sbinfo->si_xib;
38403 + cur_path = &cur_xino->f_path;
38404 + cur_dentry = cur_path->dentry;
38405 + cur_parent = dget_parent(cur_dentry);
38406 + cur_name = &cur_dentry->d_name;
38407 + dname = &dentry->d_name;
38408 + skip = (cur_parent == parent
38409 + && au_qstreq(dname, cur_name));
38410 + dput(cur_parent);
38416 + au_opt_set(sbinfo->si_mntflags, XINO);
38417 + err = au_xino_set_xib(sb, path);
38418 + /* si_x{read,write} are set */
38420 + err = au_xigen_set(sb, path);
38422 + err = au_xino_set_br(sb, path);
38424 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38425 + goto out; /* success */
38429 + AuIOErr("failed setting xino(%d).\n", err);
38438 + * create a xinofile at the default place/path.
38440 +struct file *au_xino_def(struct super_block *sb)
38442 + struct file *file;
38444 + struct au_branch *br;
38445 + struct super_block *h_sb;
38446 + struct path path;
38447 + aufs_bindex_t bbot, bindex, bwr;
38450 + bbot = au_sbbot(sb);
38452 + for (bindex = 0; bindex <= bbot; bindex++) {
38453 + br = au_sbr(sb, bindex);
38454 + if (au_br_writable(br->br_perm)
38455 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38462 + file = ERR_PTR(-ENOMEM);
38463 + page = (void *)__get_free_page(GFP_NOFS);
38464 + if (unlikely(!page))
38466 + path.mnt = au_br_mnt(br);
38467 + path.dentry = au_h_dptr(sb->s_root, bwr);
38468 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38469 + file = (void *)p;
38470 + if (!IS_ERR(p)) {
38471 + strcat(p, "/" AUFS_XINO_FNAME);
38472 + AuDbg("%s\n", p);
38473 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38475 + free_page((unsigned long)page);
38477 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38479 + if (IS_ERR(file))
38481 + h_sb = file->f_path.dentry->d_sb;
38482 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38483 + pr_err("xino doesn't support %s(%s)\n",
38484 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38486 + file = ERR_PTR(-EINVAL);
38494 +/* ---------------------------------------------------------------------- */
38497 + * initialize the xinofile for the specified branch @br
38498 + * at the place/path where @base_file indicates.
38499 + * test whether another branch is on the same filesystem or not,
38500 + * if found then share the xinofile with another branch.
38502 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38503 + struct path *base)
38506 + struct au_xino_do_set_br args = {
38511 + args.writef = au_sbi(sb)->si_xwrite;
38512 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38514 + err = au_xino_do_set_br(sb, base, &args);
38515 + if (unlikely(err))
38521 +/* ---------------------------------------------------------------------- */
38524 + * get an unused inode number from bitmap
38526 +ino_t au_xino_new_ino(struct super_block *sb)
38529 + unsigned long *p, pindex, ul, pend;
38530 + struct au_sbinfo *sbinfo;
38531 + struct file *file;
38532 + int free_bit, err;
38534 + if (!au_opt_test(au_mntflags(sb), XINO))
38535 + return iunique(sb, AUFS_FIRST_INO);
38537 + sbinfo = au_sbi(sb);
38538 + mutex_lock(&sbinfo->si_xib_mtx);
38539 + p = sbinfo->si_xib_buf;
38540 + free_bit = sbinfo->si_xib_next_bit;
38541 + if (free_bit < page_bits && !test_bit(free_bit, p))
38542 + goto out; /* success */
38543 + free_bit = find_first_zero_bit(p, page_bits);
38544 + if (free_bit < page_bits)
38545 + goto out; /* success */
38547 + pindex = sbinfo->si_xib_last_pindex;
38548 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38549 + err = xib_pindex(sb, ul);
38550 + if (unlikely(err))
38552 + free_bit = find_first_zero_bit(p, page_bits);
38553 + if (free_bit < page_bits)
38554 + goto out; /* success */
38557 + file = sbinfo->si_xib;
38558 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38559 + for (ul = pindex + 1; ul <= pend; ul++) {
38560 + err = xib_pindex(sb, ul);
38561 + if (unlikely(err))
38563 + free_bit = find_first_zero_bit(p, page_bits);
38564 + if (free_bit < page_bits)
38565 + goto out; /* success */
38570 + set_bit(free_bit, p);
38571 + sbinfo->si_xib_next_bit = free_bit + 1;
38572 + pindex = sbinfo->si_xib_last_pindex;
38573 + mutex_unlock(&sbinfo->si_xib_mtx);
38574 + ino = xib_calc_ino(pindex, free_bit);
38575 + AuDbg("i%lu\n", (unsigned long)ino);
38578 + mutex_unlock(&sbinfo->si_xib_mtx);
38583 +/* for s_op->delete_inode() */
38584 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38587 + unsigned int mnt_flags;
38588 + aufs_bindex_t bindex, bbot, bi;
38589 + unsigned char try_trunc;
38590 + struct au_iinfo *iinfo;
38591 + struct super_block *sb;
38592 + struct au_hinode *hi;
38593 + struct inode *h_inode;
38594 + struct au_branch *br;
38595 + vfs_writef_t xwrite;
38596 + struct au_xi_calc calc;
38597 + struct file *file;
38599 + AuDebugOn(au_is_bad_inode(inode));
38601 + sb = inode->i_sb;
38602 + mnt_flags = au_mntflags(sb);
38603 + if (!au_opt_test(mnt_flags, XINO)
38604 + || inode->i_ino == AUFS_ROOT_INO)
38608 + au_xigen_inc(inode);
38609 + au_xib_clear_bit(inode);
38612 + iinfo = au_ii(inode);
38613 + bindex = iinfo->ii_btop;
38617 + xwrite = au_sbi(sb)->si_xwrite;
38618 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38619 + hi = au_hinode(iinfo, bindex);
38620 + bbot = iinfo->ii_bbot;
38621 + for (; bindex <= bbot; bindex++, hi++) {
38622 + h_inode = hi->hi_inode;
38624 + || (!unlinked && h_inode->i_nlink))
38627 + /* inode may not be revalidated */
38628 + bi = au_br_index(sb, hi->hi_id);
38632 + br = au_sbr(sb, bi);
38633 + au_xi_calc(sb, h_inode->i_ino, &calc);
38634 + file = au_xino_file(br->br_xino, calc.idx);
38635 + if (IS_ERR_OR_NULL(file))
38638 + err = au_xino_do_write(xwrite, file, &calc, /*ino*/0);
38639 + if (!err && try_trunc
38640 + && au_test_fs_trunc_xino(au_br_sb(br)))
38641 + xino_try_trunc(sb, br);
38645 +/* ---------------------------------------------------------------------- */
38647 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38649 + int found, total, i;
38652 + total = xi->xi_nondir.total;
38653 + for (i = 0; i < total; i++) {
38654 + if (xi->xi_nondir.array[i] != h_ino)
38663 +static int au_xinondir_expand(struct au_xino *xi)
38668 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38671 + sz = xi->xi_nondir.total * sizeof(ino_t);
38672 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38674 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38675 + /*may_shrink*/0);
38677 + xi->xi_nondir.array = p;
38678 + xi->xi_nondir.total <<= 1;
38679 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38687 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38688 + ino_t h_ino, int idx)
38690 + struct au_xino *xi;
38692 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38693 + xi = au_sbr(sb, bindex)->br_xino;
38694 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38696 + spin_lock(&xi->xi_nondir.spin);
38697 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38698 + xi->xi_nondir.array[idx] = 0;
38699 + spin_unlock(&xi->xi_nondir.spin);
38700 + wake_up_all(&xi->xi_nondir.wqh);
38703 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38706 + int err, found, empty;
38707 + struct au_xino *xi;
38711 + if (!au_opt_test(au_mntflags(sb), XINO))
38712 + goto out; /* no xino */
38714 + xi = au_sbr(sb, bindex)->br_xino;
38717 + spin_lock(&xi->xi_nondir.spin);
38718 + found = au_xinondir_find(xi, h_ino);
38719 + if (found == -1) {
38720 + empty = au_xinondir_find(xi, /*h_ino*/0);
38721 + if (empty == -1) {
38722 + empty = xi->xi_nondir.total;
38723 + err = au_xinondir_expand(xi);
38724 + if (unlikely(err))
38727 + xi->xi_nondir.array[empty] = h_ino;
38730 + spin_unlock(&xi->xi_nondir.spin);
38731 + wait_event(xi->xi_nondir.wqh,
38732 + xi->xi_nondir.array[found] != h_ino);
38737 + spin_unlock(&xi->xi_nondir.spin);
38742 +/* ---------------------------------------------------------------------- */
38744 +int au_xino_path(struct seq_file *seq, struct file *file)
38748 + err = au_seq_path(seq, &file->f_path);
38749 + if (unlikely(err))
38752 +#define Deleted "\\040(deleted)"
38753 + seq->count -= sizeof(Deleted) - 1;
38754 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38755 + sizeof(Deleted) - 1));
38761 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38762 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38763 +++ linux/include/uapi/linux/aufs_type.h 2020-08-03 09:14:46.095748745 +0200
38765 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
38767 + * Copyright (C) 2005-2020 Junjiro R. Okajima
38769 + * This program, aufs is free software; you can redistribute it and/or modify
38770 + * it under the terms of the GNU General Public License as published by
38771 + * the Free Software Foundation; either version 2 of the License, or
38772 + * (at your option) any later version.
38774 + * This program is distributed in the hope that it will be useful,
38775 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38776 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38777 + * GNU General Public License for more details.
38779 + * You should have received a copy of the GNU General Public License
38780 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38783 +#ifndef __AUFS_TYPE_H__
38784 +#define __AUFS_TYPE_H__
38786 +#define AUFS_NAME "aufs"
38790 + * define it before including all other headers.
38791 + * sched.h may use pr_* macros before defining "current", so define the
38792 + * no-current version first, and re-define later.
38794 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38795 +#include <linux/sched.h>
38797 +#define pr_fmt(fmt) \
38798 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38799 + (int)sizeof(current->comm), current->comm, current->pid
38800 +#include <linux/limits.h>
38802 +#include <stdint.h>
38803 +#include <sys/types.h>
38804 +#include <limits.h>
38805 +#endif /* __KERNEL__ */
38807 +#define AUFS_VERSION "5.x-rcN-20200622"
38809 +/* todo? move this to linux-2.6.19/include/magic.h */
38810 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38812 +/* ---------------------------------------------------------------------- */
38815 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38816 +typedef int8_t aufs_bindex_t;
38817 +#define AUFS_BRANCH_MAX 127
38819 +typedef int16_t aufs_bindex_t;
38820 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38821 +#define AUFS_BRANCH_MAX 511
38822 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38823 +#define AUFS_BRANCH_MAX 1023
38824 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38825 +#define AUFS_BRANCH_MAX 32767
38829 +#ifndef AUFS_BRANCH_MAX
38830 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38832 +#endif /* __KERNEL__ */
38834 +/* ---------------------------------------------------------------------- */
38836 +#define AUFS_FSTYPE AUFS_NAME
38838 +#define AUFS_ROOT_INO 2
38839 +#define AUFS_FIRST_INO 11
38841 +#define AUFS_WH_PFX ".wh."
38842 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38843 +#define AUFS_WH_TMP_LEN 4
38844 +/* a limit for rmdir/rename a dir and copyup */
38845 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38846 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38848 + - AUFS_WH_TMP_LEN) /* hex */
38849 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38850 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38851 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38852 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38853 +#define AUFS_DIRWH_DEF 3
38854 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38855 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38856 +#define AUFS_RDBLK_DEF 512 /* bytes */
38857 +#define AUFS_RDHASH_DEF 32
38858 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38859 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38860 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38861 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38862 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38864 +/* pseudo-link maintenace under /proc */
38865 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38866 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38867 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38869 +/* dirren, renamed dir */
38870 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38871 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38872 +/* whiteouted doubly */
38873 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38874 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38876 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38877 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38879 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38880 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38881 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38883 +/* doubly whiteouted */
38884 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38885 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38886 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38888 +/* branch permissions and attributes */
38889 +#define AUFS_BRPERM_RW "rw"
38890 +#define AUFS_BRPERM_RO "ro"
38891 +#define AUFS_BRPERM_RR "rr"
38892 +#define AUFS_BRATTR_COO_REG "coo_reg"
38893 +#define AUFS_BRATTR_COO_ALL "coo_all"
38894 +#define AUFS_BRATTR_FHSM "fhsm"
38895 +#define AUFS_BRATTR_UNPIN "unpin"
38896 +#define AUFS_BRATTR_ICEX "icex"
38897 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38898 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38899 +#define AUFS_BRATTR_ICEX_TR "icextr"
38900 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38901 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38902 +#define AUFS_BRRATTR_WH "wh"
38903 +#define AUFS_BRWATTR_NLWH "nolwh"
38904 +#define AUFS_BRWATTR_MOO "moo"
38906 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38907 +#define AuBrPerm_RO (1 << 1) /* readonly */
38908 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38909 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38911 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38912 +#define AuBrAttr_COO_ALL (1 << 4)
38913 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38915 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38916 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38917 + branch. meaningless since
38918 + linux-3.18-rc1 */
38920 +/* ignore error in copying XATTR */
38921 +#define AuBrAttr_ICEX_SEC (1 << 7)
38922 +#define AuBrAttr_ICEX_SYS (1 << 8)
38923 +#define AuBrAttr_ICEX_TR (1 << 9)
38924 +#define AuBrAttr_ICEX_USR (1 << 10)
38925 +#define AuBrAttr_ICEX_OTH (1 << 11)
38926 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38927 + | AuBrAttr_ICEX_SYS \
38928 + | AuBrAttr_ICEX_TR \
38929 + | AuBrAttr_ICEX_USR \
38930 + | AuBrAttr_ICEX_OTH)
38932 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
38933 +#define AuBrRAttr_Mask AuBrRAttr_WH
38935 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
38936 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
38937 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
38939 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
38941 +/* #warning test userspace */
38943 +#ifndef CONFIG_AUFS_FHSM
38944 +#undef AuBrAttr_FHSM
38945 +#define AuBrAttr_FHSM 0
38947 +#ifndef CONFIG_AUFS_XATTR
38948 +#undef AuBrAttr_ICEX
38949 +#define AuBrAttr_ICEX 0
38950 +#undef AuBrAttr_ICEX_SEC
38951 +#define AuBrAttr_ICEX_SEC 0
38952 +#undef AuBrAttr_ICEX_SYS
38953 +#define AuBrAttr_ICEX_SYS 0
38954 +#undef AuBrAttr_ICEX_TR
38955 +#define AuBrAttr_ICEX_TR 0
38956 +#undef AuBrAttr_ICEX_USR
38957 +#define AuBrAttr_ICEX_USR 0
38958 +#undef AuBrAttr_ICEX_OTH
38959 +#define AuBrAttr_ICEX_OTH 0
38963 +/* the longest combination */
38964 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
38965 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
38966 + "+" AUFS_BRATTR_COO_REG \
38967 + "+" AUFS_BRATTR_FHSM \
38968 + "+" AUFS_BRATTR_UNPIN \
38969 + "+" AUFS_BRATTR_ICEX_SEC \
38970 + "+" AUFS_BRATTR_ICEX_SYS \
38971 + "+" AUFS_BRATTR_ICEX_USR \
38972 + "+" AUFS_BRATTR_ICEX_OTH \
38973 + "+" AUFS_BRWATTR_NLWH)
38976 + char a[AuBrPermStrSz];
38977 +} au_br_perm_str_t;
38979 +static inline int au_br_writable(int brperm)
38981 + return brperm & AuBrPerm_RW;
38984 +static inline int au_br_whable(int brperm)
38986 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
38989 +static inline int au_br_wh_linkable(int brperm)
38991 + return !(brperm & AuBrWAttr_NoLinkWH);
38994 +static inline int au_br_cmoo(int brperm)
38996 + return brperm & AuBrAttr_CMOO_Mask;
38999 +static inline int au_br_fhsm(int brperm)
39001 + return brperm & AuBrAttr_FHSM;
39004 +/* ---------------------------------------------------------------------- */
39008 + /* readdir in userspace */
39012 + AuCtl_WBR_FD, /* pathconf wrapper */
39013 + AuCtl_IBUSY, /* busy inode */
39014 + AuCtl_MVDOWN, /* move-down */
39015 + AuCtl_BR, /* info about branches */
39016 + AuCtl_FHSM_FD /* connection for fhsm */
39019 +/* borrowed from linux/include/linux/kernel.h */
39021 +#ifdef _GNU_SOURCE
39022 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39024 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
39026 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39029 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39031 +#define __aligned(x) __attribute__((aligned(x)))
39036 +#define __packed __attribute__((packed))
39040 +struct au_rdu_cookie {
39045 + uint32_t generation;
39048 +struct au_rdu_ent {
39057 +static inline int au_rdu_len(int nlen)
39059 + /* include the terminating NULL */
39060 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39061 + sizeof(uint64_t));
39064 +union au_rdu_ent_ul {
39065 + struct au_rdu_ent __user *e;
39077 + uint64_t sz; /* AuCtl_RDU */
39078 + uint64_t nent; /* AuCtl_RDU_INO */
39080 + union au_rdu_ent_ul ent;
39081 + uint16_t verify[AufsCtlRduV_End];
39083 + /* input/output */
39087 + union au_rdu_ent_ul tail;
39088 + /* number of entries which were added in a single call */
39093 + struct au_rdu_cookie cookie;
39096 +/* ---------------------------------------------------------------------- */
39098 +/* dirren. the branch is identified by the filename who contains this */
39099 +struct au_drinfo {
39102 + uint8_t oldnamelen;
39103 + uint64_t _padding;
39105 + uint8_t oldname[];
39108 +struct au_drinfo_fdata {
39110 + struct au_drinfo drinfo;
39113 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39115 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39117 +/* ---------------------------------------------------------------------- */
39119 +struct aufs_wbr_fd {
39124 +/* ---------------------------------------------------------------------- */
39126 +struct aufs_ibusy {
39127 + uint64_t ino, h_ino;
39131 +/* ---------------------------------------------------------------------- */
39133 +/* error code for move-down */
39134 +/* the actual message strings are implemented in aufs-util.git */
39136 + EAU_MVDOWN_OPAQUE = 1,
39137 + EAU_MVDOWN_WHITEOUT,
39138 + EAU_MVDOWN_UPPER,
39139 + EAU_MVDOWN_BOTTOM,
39140 + EAU_MVDOWN_NOUPPER,
39141 + EAU_MVDOWN_NOLOWERBR,
39145 +/* flags for move-down */
39146 +#define AUFS_MVDOWN_DMSG 1
39147 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39148 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39149 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39150 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39151 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39152 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39153 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39154 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39155 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39156 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39157 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39158 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39160 +/* index for move-down */
39162 + AUFS_MVDOWN_UPPER,
39163 + AUFS_MVDOWN_LOWER,
39164 + AUFS_MVDOWN_NARRAY
39168 + * additional info of move-down
39169 + * number of free blocks and inodes.
39170 + * subset of struct kstatfs, but smaller and always 64bit.
39172 +struct aufs_stfs {
39173 + uint64_t f_blocks;
39174 + uint64_t f_bavail;
39175 + uint64_t f_files;
39176 + uint64_t f_ffree;
39179 +struct aufs_stbr {
39180 + int16_t brid; /* optional input */
39181 + int16_t bindex; /* output */
39182 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39185 +struct aufs_mvdown {
39186 + uint32_t flags; /* input/output */
39187 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39188 + int8_t au_errno; /* output */
39191 +/* ---------------------------------------------------------------------- */
39193 +union aufs_brinfo {
39194 + /* PATH_MAX may differ between kernel-space and user-space */
39195 + char _spacer[4096];
39203 +/* ---------------------------------------------------------------------- */
39205 +#define AuCtlType 'A'
39206 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39207 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39208 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39209 + struct aufs_wbr_fd)
39210 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39211 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39212 + struct aufs_mvdown)
39213 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39214 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39216 +#endif /* __AUFS_TYPE_H__ */
39217 SPDX-License-Identifier: GPL-2.0
39218 aufs5.x-rcN loopback patch
39220 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39221 index 0479902a0cd50..758c8ee4d4e6b 100644
39222 --- a/drivers/block/loop.c
39223 +++ b/drivers/block/loop.c
39224 @@ -638,6 +638,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39228 +static struct file *loop_real_file(struct file *file)
39230 + struct file *f = NULL;
39232 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39233 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39237 static void loop_reread_partitions(struct loop_device *lo,
39238 struct block_device *bdev)
39240 @@ -693,6 +702,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39243 struct file *file = NULL, *old_file;
39244 + struct file *f, *virt_file = NULL, *old_virt_file;
39248 @@ -712,12 +722,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39252 + f = loop_real_file(file);
39254 + virt_file = file;
39259 error = loop_validate_file(file, bdev);
39263 old_file = lo->lo_backing_file;
39264 + old_virt_file = lo->lo_backing_virt_file;
39268 @@ -729,6 +746,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39269 blk_mq_freeze_queue(lo->lo_queue);
39270 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39271 lo->lo_backing_file = file;
39272 + lo->lo_backing_virt_file = virt_file;
39273 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39274 mapping_set_gfp_mask(file->f_mapping,
39275 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39276 @@ -742,6 +760,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39280 + if (old_virt_file)
39281 + fput(old_virt_file);
39283 loop_reread_partitions(lo, bdev);
39285 @@ -750,6 +770,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39286 mutex_unlock(&loop_ctl_mutex);
39294 @@ -973,7 +995,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode
39295 struct block_device *bdev,
39296 const struct loop_config *config)
39298 - struct file *file;
39299 + struct file *file, *f, *virt_file = NULL;
39300 struct inode *inode;
39301 struct address_space *mapping;
39302 struct block_device *claimed_bdev = NULL;
39303 @@ -989,6 +1011,12 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39307 + f = loop_real_file(file);
39309 + virt_file = file;
39315 * If we don't hold exclusive handle for the device, upgrade to it
39316 @@ -1037,6 +1065,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode
39317 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39318 lo->lo_device = bdev;
39319 lo->lo_backing_file = file;
39320 + lo->lo_backing_virt_file = virt_file;
39321 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39322 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39324 @@ -1090,6 +1119,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode
39325 bd_abort_claiming(bdev, claimed_bdev, loop_set_fd);
39331 /* This is safe: open() is still holding a reference. */
39332 module_put(THIS_MODULE);
39333 @@ -1136,6 +1167,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
39334 static int __loop_clr_fd(struct loop_device *lo, bool release)
39336 struct file *filp = NULL;
39337 + struct file *virt_filp = lo->lo_backing_virt_file;
39338 gfp_t gfp = lo->old_gfp_mask;
39339 struct block_device *bdev = lo->lo_device;
39341 @@ -1159,6 +1191,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39343 spin_lock_irq(&lo->lo_lock);
39344 lo->lo_backing_file = NULL;
39345 + lo->lo_backing_virt_file = NULL;
39346 spin_unlock_irq(&lo->lo_lock);
39348 loop_release_xfer(lo);
39349 @@ -1242,6 +1275,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39358 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39359 index af75a5ee40944..1d847cb194ff6 100644
39360 --- a/drivers/block/loop.h
39361 +++ b/drivers/block/loop.h
39362 @@ -46,7 +46,7 @@ struct loop_device {
39363 int (*ioctl)(struct loop_device *, int cmd,
39364 unsigned long arg);
39366 - struct file * lo_backing_file;
39367 + struct file *lo_backing_file, *lo_backing_virt_file;
39368 struct block_device *lo_device;
39371 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39372 index 6fb4a4ed8cc7f..ba9a959f2db27 100644
39373 --- a/fs/aufs/f_op.c
39374 +++ b/fs/aufs/f_op.c
39375 @@ -359,7 +359,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39376 if (IS_ERR(h_file))
39379 - if (au_test_loopback_kthread()) {
39380 + if (0 && au_test_loopback_kthread()) {
39381 au_warn_loopback(h_file->f_path.dentry->d_sb);
39382 if (file->f_mapping != h_file->f_mapping) {
39383 file->f_mapping = h_file->f_mapping;
39384 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39385 index a8b63acc62045..9d97c3af5686a 100644
39386 --- a/fs/aufs/loop.c
39387 +++ b/fs/aufs/loop.c
39388 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39389 symbol_put(loop_backing_file);
39390 au_kfree_try_rcu(au_warn_loopback_array);
39393 +/* ---------------------------------------------------------------------- */
39395 +/* support the loopback block device insude aufs */
39397 +struct file *aufs_real_loop(struct file *file)
39401 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39402 + fi_read_lock(file);
39403 + f = au_hf_top(file);
39404 + fi_read_unlock(file);
39408 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39409 index 94f4f80ae33bf..ca1194354aff4 100644
39410 --- a/fs/aufs/loop.h
39411 +++ b/fs/aufs/loop.h
39412 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39414 int au_loopback_init(void);
39415 void au_loopback_fin(void);
39417 +struct file *aufs_real_loop(struct file *file);
39419 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39421 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39423 AuStubInt0(au_loopback_init, void)
39424 AuStubVoid(au_loopback_fin, void)
39426 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39427 #endif /* BLK_DEV_LOOP */
39429 #endif /* __KERNEL__ */
39430 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39431 index 589dd01220201..801e0a7faec59 100644
39432 --- a/fs/aufs/super.c
39433 +++ b/fs/aufs/super.c
39434 @@ -844,7 +844,10 @@ static const struct super_operations aufs_sop = {
39435 .statfs = aufs_statfs,
39436 .put_super = aufs_put_super,
39437 .sync_fs = aufs_sync_fs,
39438 - .remount_fs = aufs_remount_fs
39439 + .remount_fs = aufs_remount_fs,
39440 +#ifdef CONFIG_AUFS_BDEV_LOOP
39441 + .real_loop = aufs_real_loop
39445 /* ---------------------------------------------------------------------- */
39446 diff --git a/include/linux/fs.h b/include/linux/fs.h
39447 index 916efd7e612b3..68f536f42b2a0 100644
39448 --- a/include/linux/fs.h
39449 +++ b/include/linux/fs.h
39450 @@ -1985,6 +1985,10 @@ struct super_operations {
39451 struct shrink_control *);
39452 long (*free_cached_objects)(struct super_block *,
39453 struct shrink_control *);
39454 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39456 + struct file *(*real_loop)(struct file *);