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/splice.c b/fs/splice.c
147 index 4e53efbd621db..9f230ee854e20 100644
150 @@ -849,8 +849,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
152 * Attempt to initiate a splice from pipe to file.
154 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
155 - loff_t *ppos, size_t len, unsigned int flags)
156 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
157 + loff_t *ppos, size_t len, unsigned int flags)
159 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
160 loff_t *, size_t, unsigned int);
161 @@ -866,9 +866,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
163 * Attempt to initiate a splice from a file to a pipe.
165 -static long do_splice_to(struct file *in, loff_t *ppos,
166 - struct pipe_inode_info *pipe, size_t len,
167 - unsigned int flags)
168 +long do_splice_to(struct file *in, loff_t *ppos,
169 + struct pipe_inode_info *pipe, size_t len,
170 + unsigned int flags)
172 ssize_t (*splice_read)(struct file *, loff_t *,
173 struct pipe_inode_info *, size_t, unsigned int);
174 diff --git a/fs/sync.c b/fs/sync.c
175 index 4d1ff010bc5af..457f4e4a5cc1f 100644
179 * wait == 1 case since in that case write_inode() functions do
180 * sync_dirty_buffer() and thus effectively write one block at a time.
182 -static int __sync_filesystem(struct super_block *sb, int wait)
183 +int __sync_filesystem(struct super_block *sb, int wait)
187 diff --git a/include/linux/fs.h b/include/linux/fs.h
188 index 45cc10cdf6ddd..916efd7e612b3 100644
189 --- a/include/linux/fs.h
190 +++ b/include/linux/fs.h
191 @@ -1370,6 +1370,7 @@
192 /* can be called from interrupts */
193 extern void kill_fasync(struct fasync_struct **, int, int);
195 +extern int setfl(int fd, struct file *filp, unsigned long arg);
196 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
197 extern int f_setown(struct file *filp, unsigned long arg, int force);
198 extern void f_delown(struct file *filp);
199 @@ -1858,6 +1859,7 @@
200 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
201 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
202 int (*check_flags)(int);
203 + int (*setfl)(struct file *, unsigned long);
204 int (*flock) (struct file *, int, struct file_lock *);
205 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
206 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
207 @@ -2362,6 +2370,7 @@
208 extern void ihold(struct inode * inode);
209 extern void iput(struct inode *);
210 extern int generic_update_time(struct inode *, struct timespec64 *, int);
211 +extern int update_time(struct inode *, struct timespec64 *, int);
214 extern struct kobject *fs_kobj;
215 @@ -2549,6 +2558,7 @@
218 void emergency_thaw_all(void);
219 +extern int __sync_filesystem(struct super_block *, int);
220 extern int sync_filesystem(struct super_block *);
221 extern const struct file_operations def_blk_fops;
222 extern const struct file_operations def_chr_fops;
223 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
224 index 206774ac69460..e5eda5226fbc7 100644
225 --- a/include/linux/lockdep.h
226 +++ b/include/linux/lockdep.h
227 @@ -376,6 +376,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
228 return lock->key == key;
231 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
236 @@ -521,6 +523,7 @@ struct lockdep_map { };
238 #define lockdep_depth(tsk) (0)
240 +#define lockdep_is_held(lock) (1)
241 #define lockdep_is_held_type(l, r) (1)
243 #define lockdep_assert_held(l) do { (void)(l); } while (0)
244 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
245 index 35942084cd40d..24f5fd1a789de 100644
246 --- a/include/linux/mnt_namespace.h
247 +++ b/include/linux/mnt_namespace.h
250 struct user_namespace;
254 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
255 struct user_namespace *, struct fs_struct *);
256 extern void put_mnt_ns(struct mnt_namespace *ns);
257 extern struct ns_common *from_mnt_ns(struct mnt_namespace *);
259 +extern int is_current_mnt_ns(struct vfsmount *mnt);
261 extern const struct file_operations proc_mounts_operations;
262 extern const struct file_operations proc_mountinfo_operations;
263 extern const struct file_operations proc_mountstats_operations;
264 diff --git a/include/linux/splice.h b/include/linux/splice.h
265 index ebbbfea48aa0b..d68d574250283 100644
266 --- a/include/linux/splice.h
267 +++ b/include/linux/splice.h
268 @@ -90,4 +90,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
270 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
271 extern const struct pipe_buf_operations default_pipe_buf_ops;
273 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
274 + loff_t *ppos, size_t len, unsigned int flags);
275 +extern long do_splice_to(struct file *in, loff_t *ppos,
276 + struct pipe_inode_info *pipe, size_t len,
277 + unsigned int flags);
279 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
280 index ac10db66cc63f..837a3358e77ca 100644
281 --- a/kernel/locking/lockdep.c
282 +++ b/kernel/locking/lockdep.c
283 @@ -169,7 +169,7 @@ static
284 struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
285 static DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS);
287 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
288 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
290 unsigned int class_idx = hlock->class_idx;
292 @@ -190,6 +190,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
294 return lock_classes + class_idx;
296 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
298 #ifdef CONFIG_LOCK_STAT
299 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
300 SPDX-License-Identifier: GPL-2.0
301 aufs5.x-rcN mmap patch
303 diff --git a/fs/proc/base.c b/fs/proc/base.c
304 index eb2255e95f62b..92f6062423c0c 100644
307 @@ -2162,7 +2162,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
309 vma = find_exact_vma(mm, vm_start, vm_end);
310 if (vma && vma->vm_file) {
311 - *path = vma->vm_file->f_path;
312 + *path = vma_pr_or_file(vma)->f_path;
316 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
317 index 14c2badb8fd93..65afe5287e43e 100644
318 --- a/fs/proc/nommu.c
319 +++ b/fs/proc/nommu.c
320 @@ -41,7 +41,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
321 file = region->vm_file;
324 - struct inode *inode = file_inode(region->vm_file);
325 + struct inode *inode;
327 + file = vmr_pr_or_file(region);
328 + inode = file_inode(file);
329 dev = inode->i_sb->s_dev;
332 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
333 index 8d382d4ec0672..93a768f754c91 100644
334 --- a/fs/proc/task_mmu.c
335 +++ b/fs/proc/task_mmu.c
336 @@ -280,7 +280,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
337 const char *name = NULL;
340 - struct inode *inode = file_inode(vma->vm_file);
341 + struct inode *inode;
343 + file = vma_pr_or_file(vma);
344 + inode = file_inode(file);
345 dev = inode->i_sb->s_dev;
347 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
348 @@ -1787,7 +1790,7 @@ static int show_numa_map(struct seq_file *m, void *v)
349 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
350 struct vm_area_struct *vma = v;
351 struct numa_maps *md = &numa_priv->md;
352 - struct file *file = vma->vm_file;
353 + struct file *file = vma_pr_or_file(vma);
354 struct mm_struct *mm = vma->vm_mm;
355 struct mempolicy *pol;
357 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
358 index 7907e6419e572..d17209cf52bc3 100644
359 --- a/fs/proc/task_nommu.c
360 +++ b/fs/proc/task_nommu.c
361 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
365 - struct inode *inode = file_inode(vma->vm_file);
366 + struct inode *inode;
368 + file = vma_pr_or_file(vma);
369 + inode = file_inode(file);
370 dev = inode->i_sb->s_dev;
372 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
373 diff --git a/include/linux/mm.h b/include/linux/mm.h
374 index f3fe7371855ce..a5b9751a5b331 100644
375 --- a/include/linux/mm.h
376 +++ b/include/linux/mm.h
377 @@ -1688,6 +1688,28 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
378 unmap_mapping_range(mapping, holebegin, holelen, 0);
381 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
382 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
384 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
385 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
387 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
389 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
391 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
392 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
395 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
396 +extern void vmr_do_fput(struct vm_region *, const char[], int);
398 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
400 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
401 +#endif /* !CONFIG_MMU */
403 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
404 void *buf, int len, unsigned int gup_flags);
405 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
406 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
407 index 4aba6c0c2ba80..974802987f69d 100644
408 --- a/include/linux/mm_types.h
409 +++ b/include/linux/mm_types.h
410 @@ -272,6 +272,7 @@ struct vm_region {
411 unsigned long vm_top; /* region allocated to here */
412 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
413 struct file *vm_file; /* the backing file or NULL */
414 + struct file *vm_prfile; /* the virtual backing file or NULL */
416 int vm_usage; /* region usage count (access under nommu_region_sem) */
417 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
418 @@ -351,6 +352,7 @@ struct vm_area_struct {
419 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
421 struct file * vm_file; /* File we map to (can be NULL). */
422 + struct file *vm_prfile; /* shadow of vm_file */
423 void * vm_private_data; /* was vm_pte (shared mem) */
426 diff --git a/kernel/fork.c b/kernel/fork.c
427 index 48ed22774efaa..d7439388c1c52 100644
430 @@ -568,7 +568,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
431 struct inode *inode = file_inode(file);
432 struct address_space *mapping = file->f_mapping;
436 if (tmp->vm_flags & VM_DENYWRITE)
437 atomic_dec(&inode->i_writecount);
438 i_mmap_lock_write(mapping);
439 diff --git a/mm/Makefile b/mm/Makefile
440 index fccd3756b25f0..51485ceec650a 100644
443 @@ -44,7 +44,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \
444 mm_init.o mmu_context.o percpu.o slab_common.o \
445 compaction.o vmacache.o \
446 interval_tree.o list_lru.o workingset.o \
447 - debug.o gup.o $(mmu-y)
448 + prfile.o debug.o gup.o $(mmu-y)
450 # Give 'page_alloc' its own module-parameter namespace
451 page-alloc-y := page_alloc.o
452 diff --git a/mm/filemap.c b/mm/filemap.c
453 index 23a051a7ef0fb..e2fe9132feb21 100644
456 @@ -2660,7 +2660,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
457 vm_fault_t ret = VM_FAULT_LOCKED;
459 sb_start_pagefault(inode->i_sb);
460 - file_update_time(vmf->vma->vm_file);
461 + vma_file_update_time(vmf->vma);
463 if (page->mapping != inode->i_mapping) {
465 diff --git a/mm/mmap.c b/mm/mmap.c
466 index f609e9ec4a253..d554b349c653c 100644
469 @@ -179,7 +179,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
470 if (vma->vm_ops && vma->vm_ops->close)
471 vma->vm_ops->close(vma);
473 - fput(vma->vm_file);
475 mpol_put(vma_policy(vma));
478 @@ -910,7 +910,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
481 uprobe_munmap(next, next->vm_start, next->vm_end);
486 anon_vma_merge(vma, next);
487 @@ -1831,8 +1831,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
495 /* Undo any partial mapping done by a device driver. */
496 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
497 @@ -2683,7 +2683,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
501 - get_file(new->vm_file);
504 if (new->vm_ops && new->vm_ops->open)
505 new->vm_ops->open(new);
506 @@ -2702,7 +2702,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
507 if (new->vm_ops && new->vm_ops->close)
508 new->vm_ops->close(new);
510 - fput(new->vm_file);
512 unlink_anon_vmas(new);
514 mpol_put(vma_policy(new));
515 @@ -2894,7 +2894,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
516 struct vm_area_struct *vma;
517 unsigned long populate = 0;
518 unsigned long ret = -EINVAL;
520 + struct file *file, *prfile;
522 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n",
523 current->comm, current->pid);
524 @@ -2969,10 +2969,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
528 - file = get_file(vma->vm_file);
530 + file = vma->vm_file;
531 + prfile = vma->vm_prfile;
532 ret = do_mmap(vma->vm_file, start, size,
533 prot, flags, pgoff, &populate, NULL);
534 + if (!IS_ERR_VALUE(ret) && file && prfile) {
535 + struct vm_area_struct *new_vma;
537 + new_vma = find_vma(mm, ret);
538 + if (!new_vma->vm_prfile)
539 + new_vma->vm_prfile = prfile;
540 + if (new_vma != vma)
544 + * two fput()s instead of vma_fput(vma),
545 + * coz vma may not be available anymore.
551 up_write(&mm->mmap_sem);
553 @@ -3263,7 +3280,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
554 if (anon_vma_clone(new_vma, vma))
555 goto out_free_mempol;
556 if (new_vma->vm_file)
557 - get_file(new_vma->vm_file);
558 + vma_get_file(new_vma);
559 if (new_vma->vm_ops && new_vma->vm_ops->open)
560 new_vma->vm_ops->open(new_vma);
561 vma_link(mm, new_vma, prev, rb_link, rb_parent);
562 diff --git a/mm/nommu.c b/mm/nommu.c
563 index 318df4e236c99..7f051e86ea1dd 100644
566 @@ -567,7 +567,7 @@ static void __put_nommu_region(struct vm_region *region)
567 up_write(&nommu_region_sem);
570 - fput(region->vm_file);
573 /* IO memory and memory shared directly out of the pagecache
574 * from ramfs/tmpfs mustn't be released here */
575 @@ -699,7 +699,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
576 if (vma->vm_ops && vma->vm_ops->close)
577 vma->vm_ops->close(vma);
579 - fput(vma->vm_file);
581 put_nommu_region(vma->vm_region);
584 @@ -1222,7 +1222,7 @@ unsigned long do_mmap(struct file *file,
585 goto error_just_free;
588 - fput(region->vm_file);
590 kmem_cache_free(vm_region_jar, region);
593 @@ -1299,10 +1299,10 @@ unsigned long do_mmap(struct file *file,
594 up_write(&nommu_region_sem);
597 - fput(region->vm_file);
599 kmem_cache_free(vm_region_jar, region);
601 - fput(vma->vm_file);
606 diff --git a/mm/prfile.c b/mm/prfile.c
608 index 0000000000000..00d51187c3250
612 +// SPDX-License-Identifier: GPL-2.0
614 + * Mainly for aufs which mmap(2) different file and wants to print different
615 + * path in /proc/PID/maps.
616 + * Call these functions via macros defined in linux/mm.h.
618 + * See Documentation/filesystems/aufs/design/06mmap.txt
620 + * Copyright (c) 2014-2020 Junjro R. Okajima
621 + * Copyright (c) 2014 Ian Campbell
624 +#include <linux/mm.h>
625 +#include <linux/file.h>
626 +#include <linux/fs.h>
628 +/* #define PRFILE_TRACE */
629 +static inline void prfile_trace(struct file *f, struct file *pr,
630 + const char func[], int line, const char func2[])
634 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
638 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
641 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
643 + prfile_trace(f, pr, func, line, __func__);
644 + file_update_time(f);
646 + file_update_time(pr);
649 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
652 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
654 + prfile_trace(f, pr, func, line, __func__);
655 + return (f && pr) ? pr : f;
658 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
660 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
662 + prfile_trace(f, pr, func, line, __func__);
668 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
670 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
672 + prfile_trace(f, pr, func, line, __func__);
679 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
682 + struct file *f = region->vm_file, *pr = region->vm_prfile;
684 + prfile_trace(f, pr, func, line, __func__);
685 + return (f && pr) ? pr : f;
688 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
690 + struct file *f = region->vm_file, *pr = region->vm_prfile;
692 + prfile_trace(f, pr, func, line, __func__);
697 +#endif /* !CONFIG_MMU */
698 SPDX-License-Identifier: GPL-2.0
699 aufs5.x-rcN standalone patch
701 diff --git a/fs/dcache.c b/fs/dcache.c
702 index 046000653e4d8..15aa871d1b450 100644
705 @@ -1371,6 +1371,7 @@ void d_walk(struct dentry *parent, void *data,
709 +EXPORT_SYMBOL_GPL(d_walk);
712 struct vfsmount *mnt;
713 @@ -2916,6 +2917,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
715 write_sequnlock(&rename_lock);
717 +EXPORT_SYMBOL_GPL(d_exchange);
720 * d_ancestor - search for an ancestor
721 diff --git a/fs/exec.c b/fs/exec.c
722 index 2c465119affcc..239bcb8906e78 100644
725 @@ -109,6 +109,7 @@ bool path_noexec(const struct path *path)
726 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
727 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
729 +EXPORT_SYMBOL_GPL(path_noexec);
733 diff --git a/fs/fcntl.c b/fs/fcntl.c
734 index 0b28a37f7e505..f2c90a416b751 100644
737 @@ -85,6 +85,7 @@ int setfl(int fd, struct file *filp, unsigned long arg)
741 +EXPORT_SYMBOL_GPL(setfl);
743 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
745 diff --git a/fs/file_table.c b/fs/file_table.c
746 index 30d55c9a1744a..34b9bbf4c5566 100644
747 --- a/fs/file_table.c
748 +++ b/fs/file_table.c
749 @@ -162,6 +162,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
751 return ERR_PTR(-ENFILE);
753 +EXPORT_SYMBOL_GPL(alloc_empty_file);
756 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
757 @@ -375,6 +376,7 @@ void __fput_sync(struct file *file)
761 +EXPORT_SYMBOL_GPL(__fput_sync);
763 void __init files_init(void)
765 diff --git a/fs/inode.c b/fs/inode.c
766 index 7700c5e4783b9..6284b41fcf3f0 100644
769 @@ -1694,6 +1694,7 @@ int update_time(struct inode *inode, struct timespec64 *time, int flags)
770 return inode->i_op->update_time(inode, time, flags);
771 return generic_update_time(inode, time, flags);
773 +EXPORT_SYMBOL_GPL(update_time);
776 * touch_atime - update the access time
777 diff --git a/fs/namespace.c b/fs/namespace.c
778 index 12e725e34c6ca..fa17b9d5926ba 100644
781 @@ -431,6 +431,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
782 mnt_dec_writers(real_mount(mnt));
785 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
788 * mnt_drop_write - give up write access to a mount
789 @@ -781,6 +782,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
791 return check_mnt(real_mount(mnt));
793 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
796 * vfsmount lock must be held for write
797 @@ -1903,6 +1905,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
801 +EXPORT_SYMBOL_GPL(iterate_mounts);
803 static void lock_mnt_tree(struct mount *mnt)
805 diff --git a/fs/notify/group.c b/fs/notify/group.c
806 index 133f723aca070..0b9f7f6d8390f 100644
807 --- a/fs/notify/group.c
808 +++ b/fs/notify/group.c
809 @@ -99,6 +99,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
811 refcount_inc(&group->refcnt);
813 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
816 * Drop a reference to a group. Free it if it's through.
817 diff --git a/fs/open.c b/fs/open.c
818 index 719b320ede52b..f88ce55c1c998 100644
821 @@ -65,6 +65,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
822 inode_unlock(dentry->d_inode);
825 +EXPORT_SYMBOL_GPL(do_truncate);
827 long vfs_truncate(const struct path *path, loff_t length)
829 diff --git a/fs/read_write.c b/fs/read_write.c
830 index 5d684d7d29207..6f61c0b6aa664 100644
831 --- a/fs/read_write.c
832 +++ b/fs/read_write.c
833 @@ -469,6 +469,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
837 +EXPORT_SYMBOL_GPL(vfs_read);
839 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
841 @@ -589,6 +592,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
845 +EXPORT_SYMBOL_GPL(vfs_write);
847 /* file_ppos returns &file->f_pos or NULL if file is stream */
848 static inline loff_t *file_ppos(struct file *file)
849 diff --git a/fs/splice.c b/fs/splice.c
850 index 9f230ee854e20..a6bd05004433c 100644
853 @@ -862,6 +862,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
855 return splice_write(pipe, out, ppos, len, flags);
857 +EXPORT_SYMBOL_GPL(do_splice_from);
860 * Attempt to initiate a splice from a file to a pipe.
861 @@ -891,6 +892,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
863 return splice_read(in, ppos, pipe, len, flags);
865 +EXPORT_SYMBOL_GPL(do_splice_to);
868 * splice_direct_to_actor - splices data directly between two non-pipes
869 diff --git a/fs/sync.c b/fs/sync.c
870 index 457f4e4a5cc1f..67c66358f3fe4 100644
873 @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
874 sb->s_op->sync_fs(sb, wait);
875 return __sync_blockdev(sb->s_bdev, wait);
877 +EXPORT_SYMBOL_GPL(__sync_filesystem);
880 * Write out and wait upon all dirty data associated with this
881 diff --git a/fs/xattr.c b/fs/xattr.c
882 index 91608d9bfc6aa..02d19ab3ba540 100644
885 @@ -296,6 +296,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
886 *xattr_value = value;
889 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
892 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
893 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
894 index 837a3358e77ca..715ba9c1b91ae 100644
895 --- a/kernel/locking/lockdep.c
896 +++ b/kernel/locking/lockdep.c
897 @@ -190,6 +190,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
899 return lock_classes + class_idx;
901 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
902 #define hlock_class(hlock) lockdep_hlock_class(hlock)
904 #ifdef CONFIG_LOCK_STAT
905 diff --git a/kernel/task_work.c b/kernel/task_work.c
906 index 825f28259a19a..b77593b29c1a5 100644
907 --- a/kernel/task_work.c
908 +++ b/kernel/task_work.c
909 @@ -126,3 +126,4 @@ void task_work_run(void)
913 +EXPORT_SYMBOL_GPL(task_work_run);
914 diff --git a/security/security.c b/security/security.c
915 index 51de970fbb1ed..b21f1ffd90051 100644
916 --- a/security/security.c
917 +++ b/security/security.c
918 @@ -1087,6 +1087,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
920 return call_int_hook(path_rmdir, 0, dir, dentry);
922 +EXPORT_SYMBOL_GPL(security_path_rmdir);
924 int security_path_unlink(const struct path *dir, struct dentry *dentry)
926 @@ -1103,6 +1104,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
928 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
930 +EXPORT_SYMBOL_GPL(security_path_symlink);
932 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
933 struct dentry *new_dentry)
934 @@ -1111,6 +1113,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
936 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
938 +EXPORT_SYMBOL_GPL(security_path_link);
940 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
941 const struct path *new_dir, struct dentry *new_dentry,
942 @@ -1138,6 +1141,7 @@ int security_path_truncate(const struct path *path)
944 return call_int_hook(path_truncate, 0, path);
946 +EXPORT_SYMBOL_GPL(security_path_truncate);
948 int security_path_chmod(const struct path *path, umode_t mode)
950 @@ -1145,6 +1149,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
952 return call_int_hook(path_chmod, 0, path, mode);
954 +EXPORT_SYMBOL_GPL(security_path_chmod);
956 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
958 @@ -1152,6 +1157,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
960 return call_int_hook(path_chown, 0, path, uid, gid);
962 +EXPORT_SYMBOL_GPL(security_path_chown);
964 int security_path_chroot(const struct path *path)
966 @@ -1252,6 +1258,7 @@ int security_inode_permission(struct inode *inode, int mask)
968 return call_int_hook(inode_permission, 0, inode, mask);
970 +EXPORT_SYMBOL_GPL(security_inode_permission);
972 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
974 @@ -1429,6 +1436,7 @@ int security_file_permission(struct file *file, int mask)
976 return fsnotify_perm(file, mask);
978 +EXPORT_SYMBOL_GPL(security_file_permission);
980 int security_file_alloc(struct file *file)
982 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
983 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
984 +++ linux/Documentation/ABI/testing/debugfs-aufs 2019-07-11 15:42:14.455570938 +0200
986 +What: /debug/aufs/si_<id>/
988 +Contact: J. R. Okajima <hooanon05g@gmail.com>
990 + Under /debug/aufs, a directory named si_<id> is created
991 + per aufs mount, where <id> is a unique id generated
994 +What: /debug/aufs/si_<id>/plink
996 +Contact: J. R. Okajima <hooanon05g@gmail.com>
998 + It has three lines and shows the information about the
999 + pseudo-link. The first line is a single number
1000 + representing a number of buckets. The second line is a
1001 + number of pseudo-links per buckets (separated by a
1002 + blank). The last line is a single number representing a
1003 + total number of psedo-links.
1004 + When the aufs mount option 'noplink' is specified, it
1005 + will show "1\n0\n0\n".
1007 +What: /debug/aufs/si_<id>/xib
1009 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1011 + It shows the consumed blocks by xib (External Inode Number
1012 + Bitmap), its block size and file size.
1013 + When the aufs mount option 'noxino' is specified, it
1014 + will be empty. About XINO files, see the aufs manual.
1016 +What: /debug/aufs/si_<id>/xi0, xi1 ... xiN and xiN-N
1018 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1020 + It shows the consumed blocks by xino (External Inode Number
1021 + Translation Table), its link count, block size and file
1023 + Due to the file size limit, there may exist multiple
1024 + xino files per branch. In this case, "-N" is added to
1025 + the filename and it corresponds to the index of the
1026 + internal xino array. "-0" is omitted.
1027 + When the aufs mount option 'noxino' is specified, Those
1028 + entries won't exist. About XINO files, see the aufs
1031 +What: /debug/aufs/si_<id>/xigen
1033 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1035 + It shows the consumed blocks by xigen (External Inode
1036 + Generation Table), its block size and file size.
1037 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1039 + When the aufs mount option 'noxino' is specified, it
1040 + will be empty. About XINO files, see the aufs manual.
1041 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1042 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1043 +++ linux/Documentation/ABI/testing/sysfs-aufs 2019-07-11 15:42:14.455570938 +0200
1045 +What: /sys/fs/aufs/si_<id>/
1047 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1049 + Under /sys/fs/aufs, a directory named si_<id> is created
1050 + per aufs mount, where <id> is a unique id generated
1053 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1055 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1057 + It shows the abolute path of a member directory (which
1058 + is called branch) in aufs, and its permission.
1060 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1062 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1064 + It shows the id of a member directory (which is called
1067 +What: /sys/fs/aufs/si_<id>/xi_path
1069 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1071 + It shows the abolute path of XINO (External Inode Number
1072 + Bitmap, Translation Table and Generation Table) file
1073 + even if it is the default path.
1074 + When the aufs mount option 'noxino' is specified, it
1075 + will be empty. About XINO files, see the aufs manual.
1076 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1077 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1078 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2020-01-27 10:57:18.162204582 +0100
1081 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1083 +# This program is free software; you can redistribute it and/or modify
1084 +# it under the terms of the GNU General Public License as published by
1085 +# the Free Software Foundation; either version 2 of the License, or
1086 +# (at your option) any later version.
1088 +# This program is distributed in the hope that it will be useful,
1089 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1090 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1091 +# GNU General Public License for more details.
1093 +# You should have received a copy of the GNU General Public License
1094 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1097 +----------------------------------------
1099 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1100 +1. abbrev. for "advanced multi-layered unification filesystem".
1101 +2. abbrev. for "another unionfs".
1102 +3. abbrev. for "auf das" in German which means "on the" in English.
1103 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1104 + But "Filesystem aufs Filesystem" is hard to understand.
1105 +4. abbrev. for "African Urban Fashion Show".
1107 +AUFS is a filesystem with features:
1108 +- multi layered stackable unification filesystem, the member directory
1109 + is called as a branch.
1110 +- branch permission and attribute, 'readonly', 'real-readonly',
1111 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1113 +- internal "file copy-on-write".
1114 +- logical deletion, whiteout.
1115 +- dynamic branch manipulation, adding, deleting and changing permission.
1116 +- allow bypassing aufs, user's direct branch access.
1117 +- external inode number translation table and bitmap which maintains the
1118 + persistent aufs inode number.
1119 +- seekable directory, including NFS readdir.
1120 +- file mapping, mmap and sharing pages.
1121 +- pseudo-link, hardlink over branches.
1122 +- loopback mounted filesystem as a branch.
1123 +- several policies to select one among multiple writable branches.
1124 +- revert a single systemcall when an error occurs in aufs.
1128 +Multi Layered Stackable Unification Filesystem
1129 +----------------------------------------------------------------------
1130 +Most people already knows what it is.
1131 +It is a filesystem which unifies several directories and provides a
1132 +merged single directory. When users access a file, the access will be
1133 +passed/re-directed/converted (sorry, I am not sure which English word is
1134 +correct) to the real file on the member filesystem. The member
1135 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1136 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1137 +readonly branch is handled by creating 'whiteout' on the upper writable
1140 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1141 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1142 +different approaches to implement the merged-view.
1143 +The former tries putting it into VFS, and the latter implements as a
1144 +separate filesystem.
1145 +(If I misunderstand about these implementations, please let me know and
1146 +I shall correct it. Because it is a long time ago when I read their
1147 +source files last time).
1149 +UnionMount's approach will be able to small, but may be hard to share
1150 +branches between several UnionMount since the whiteout in it is
1151 +implemented in the inode on branch filesystem and always
1152 +shared. According to Bharata's post, readdir does not seems to be
1154 +There are several missing features known in this implementations such as
1155 +- for users, the inode number may change silently. eg. copy-up.
1156 +- link(2) may break by copy-up.
1157 +- read(2) may get an obsoleted filedata (fstat(2) too).
1158 +- fcntl(F_SETLK) may be broken by copy-up.
1159 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1162 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1163 +merged into mainline. This is another implementation of UnionMount as a
1164 +separated filesystem. All the limitations and known problems which
1165 +UnionMount are equally inherited to "overlay" filesystem.
1167 +Unionfs has a longer history. When I started implementing a stackable
1168 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1169 +inode, dentry and file objects and they have an array pointing lower
1170 +same kind objects. After contributing many patches for Unionfs, I
1171 +re-started my project AUFS (Jun 2006).
1173 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1174 +implemented my own ideas, approaches and enhancements and it became
1175 +totally different one.
1177 +Comparing DM snapshot and fs based implementation
1178 +- the number of bytes to be copied between devices is much smaller.
1179 +- the type of filesystem must be one and only.
1180 +- the fs must be writable, no readonly fs, even for the lower original
1181 + device. so the compression fs will not be usable. but if we use
1182 + loopback mount, we may address this issue.
1184 + mount /cdrom/squashfs.img /sq
1185 + losetup /sq/ext2.img
1186 + losetup /somewhere/cow
1187 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1188 +- it will be difficult (or needs more operations) to extract the
1189 + difference between the original device and COW.
1190 +- DM snapshot-merge may help a lot when users try merging. in the
1191 + fs-layer union, users will use rsync(1).
1193 +You may want to read my old paper "Filesystems in LiveCD"
1194 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1197 +Several characters/aspects/persona of aufs
1198 +----------------------------------------------------------------------
1200 +Aufs has several characters, aspects or persona.
1201 +1. a filesystem, callee of VFS helper
1202 +2. sub-VFS, caller of VFS helper for branches
1203 +3. a virtual filesystem which maintains persistent inode number
1204 +4. reader/writer of files on branches such like an application
1206 +1. Callee of VFS Helper
1207 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1208 +unlink(2) from an application reaches sys_unlink() kernel function and
1209 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1210 +calls filesystem specific unlink operation. Actually aufs implements the
1211 +unlink operation but it behaves like a redirector.
1213 +2. Caller of VFS Helper for Branches
1214 +aufs_unlink() passes the unlink request to the branch filesystem as if
1215 +it were called from VFS. So the called unlink operation of the branch
1216 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1217 +every necessary pre/post operation for the branch filesystem.
1218 +- acquire the lock for the parent dir on a branch
1219 +- lookup in a branch
1220 +- revalidate dentry on a branch
1221 +- mnt_want_write() for a branch
1222 +- vfs_unlink() for a branch
1223 +- mnt_drop_write() for a branch
1224 +- release the lock on a branch
1226 +3. Persistent Inode Number
1227 +One of the most important issue for a filesystem is to maintain inode
1228 +numbers. This is particularly important to support exporting a
1229 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1230 +backend block device for its own. But some storage is necessary to
1231 +keep and maintain the inode numbers. It may be a large space and may not
1232 +suit to keep in memory. Aufs rents some space from its first writable
1233 +branch filesystem (by default) and creates file(s) on it. These files
1234 +are created by aufs internally and removed soon (currently) keeping
1236 +Note: Because these files are removed, they are totally gone after
1237 + unmounting aufs. It means the inode numbers are not persistent
1238 + across unmount or reboot. I have a plan to make them really
1239 + persistent which will be important for aufs on NFS server.
1241 +4. Read/Write Files Internally (copy-on-write)
1242 +Because a branch can be readonly, when you write a file on it, aufs will
1243 +"copy-up" it to the upper writable branch internally. And then write the
1244 +originally requested thing to the file. Generally kernel doesn't
1245 +open/read/write file actively. In aufs, even a single write may cause a
1246 +internal "file copy". This behaviour is very similar to cp(1) command.
1248 +Some people may think it is better to pass such work to user space
1249 +helper, instead of doing in kernel space. Actually I am still thinking
1250 +about it. But currently I have implemented it in kernel space.
1251 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1252 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1253 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2020-01-27 10:57:18.162204582 +0100
1256 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1258 +# This program is free software; you can redistribute it and/or modify
1259 +# it under the terms of the GNU General Public License as published by
1260 +# the Free Software Foundation; either version 2 of the License, or
1261 +# (at your option) any later version.
1263 +# This program is distributed in the hope that it will be useful,
1264 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1265 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1266 +# GNU General Public License for more details.
1268 +# You should have received a copy of the GNU General Public License
1269 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1271 +Basic Aufs Internal Structure
1273 +Superblock/Inode/Dentry/File Objects
1274 +----------------------------------------------------------------------
1275 +As like an ordinary filesystem, aufs has its own
1276 +superblock/inode/dentry/file objects. All these objects have a
1277 +dynamically allocated array and store the same kind of pointers to the
1278 +lower filesystem, branch.
1279 +For example, when you build a union with one readwrite branch and one
1280 +readonly, mounted /au, /rw and /ro respectively.
1282 +- /ro/fileA exists but /rw/fileA
1284 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1285 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1286 +- [0] = NULL (because /rw/fileA doesn't exist)
1289 +This style of an array is essentially same to the aufs
1290 +superblock/inode/dentry/file objects.
1292 +Because aufs supports manipulating branches, ie. add/delete/change
1293 +branches dynamically, these objects has its own generation. When
1294 +branches are changed, the generation in aufs superblock is
1295 +incremented. And a generation in other object are compared when it is
1296 +accessed. When a generation in other objects are obsoleted, aufs
1297 +refreshes the internal array.
1301 +----------------------------------------------------------------------
1302 +Additionally aufs superblock has some data for policies to select one
1303 +among multiple writable branches, XIB files, pseudo-links and kobject.
1304 +See below in detail.
1305 +About the policies which supports copy-down a directory, see
1306 +wbr_policy.txt too.
1309 +Branch and XINO(External Inode Number Translation Table)
1310 +----------------------------------------------------------------------
1311 +Every branch has its own xino (external inode number translation table)
1312 +file. The xino file is created and unlinked by aufs internally. When two
1313 +members of a union exist on the same filesystem, they share the single
1315 +The struct of a xino file is simple, just a sequence of aufs inode
1316 +numbers which is indexed by the lower inode number.
1317 +In the above sample, assume the inode number of /ro/fileA is i111 and
1318 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1319 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1321 +When the inode numbers are not contiguous, the xino file will be sparse
1322 +which has a hole in it and doesn't consume as much disk space as it
1323 +might appear. If your branch filesystem consumes disk space for such
1324 +holes, then you should specify 'xino=' option at mounting aufs.
1326 +Aufs has a mount option to free the disk blocks for such holes in XINO
1327 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1328 +meet a problem of disk shortage due to XINO files, then you should try
1329 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1330 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1331 +the holes in XINO files.
1333 +Also a writable branch has three kinds of "whiteout bases". All these
1334 +are existed when the branch is joined to aufs, and their names are
1335 +whiteout-ed doubly, so that users will never see their names in aufs
1337 +1. a regular file which will be hardlinked to all whiteouts.
1338 +2. a directory to store a pseudo-link.
1339 +3. a directory to store an "orphan"-ed file temporary.
1342 + When you remove a file on a readonly branch, aufs handles it as a
1343 + logical deletion and creates a whiteout on the upper writable branch
1344 + as a hardlink of this file in order not to consume inode on the
1347 + See below, Pseudo-link.
1349 + When "fileC" exists on the lower readonly branch only and it is
1350 + opened and removed with its parent dir, and then user writes
1351 + something into it, then aufs copies-up fileC to this
1352 + directory. Because there is no other dir to store fileC. After
1353 + creating a file under this dir, the file is unlinked.
1355 +Because aufs supports manipulating branches, ie. add/delete/change
1356 +dynamically, a branch has its own id. When the branch order changes,
1357 +aufs finds the new index by searching the branch id.
1361 +----------------------------------------------------------------------
1362 +Assume "fileA" exists on the lower readonly branch only and it is
1363 +hardlinked to "fileB" on the branch. When you write something to fileA,
1364 +aufs copies-up it to the upper writable branch. Additionally aufs
1365 +creates a hardlink under the Pseudo-link Directory of the writable
1366 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1367 +simple list. If fileB is read after unlinking fileA, aufs returns
1368 +filedata from the pseudo-link instead of the lower readonly
1369 +branch. Because the pseudo-link is based upon the inode, to keep the
1370 +inode number by xino (see above) is essentially necessary.
1372 +All the hardlinks under the Pseudo-link Directory of the writable branch
1373 +should be restored in a proper location later. Aufs provides a utility
1374 +to do this. The userspace helpers executed at remounting and unmounting
1376 +During this utility is running, it puts aufs into the pseudo-link
1377 +maintenance mode. In this mode, only the process which began the
1378 +maintenance mode (and its child processes) is allowed to operate in
1379 +aufs. Some other processes which are not related to the pseudo-link will
1380 +be allowed to run too, but the rest have to return an error or wait
1381 +until the maintenance mode ends. If a process already acquires an inode
1382 +mutex (in VFS), it has to return an error.
1385 +XIB(external inode number bitmap)
1386 +----------------------------------------------------------------------
1387 +Addition to the xino file per a branch, aufs has an external inode number
1388 +bitmap in a superblock object. It is also an internal file such like a
1390 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1392 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1394 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1395 +reduce the number of consumed disk blocks for these files.
1398 +Virtual or Vertical Dir, and Readdir in Userspace
1399 +----------------------------------------------------------------------
1400 +In order to support multiple layers (branches), aufs readdir operation
1401 +constructs a virtual dir block on memory. For readdir, aufs calls
1402 +vfs_readdir() internally for each dir on branches, merges their entries
1403 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1404 +object. So the file object has its entry list until it is closed. The
1405 +entry list will be updated when the file position is zero and becomes
1406 +obsoleted. This decision is made in aufs automatically.
1408 +The dynamically allocated memory block for the name of entries has a
1409 +unit of 512 bytes (by default) and stores the names contiguously (no
1410 +padding). Another block for each entry is handled by kmem_cache too.
1411 +During building dir blocks, aufs creates hash list and judging whether
1412 +the entry is whiteouted by its upper branch or already listed.
1413 +The merged result is cached in the corresponding inode object and
1414 +maintained by a customizable life-time option.
1416 +Some people may call it can be a security hole or invite DoS attack
1417 +since the opened and once readdir-ed dir (file object) holds its entry
1418 +list and becomes a pressure for system memory. But I'd say it is similar
1419 +to files under /proc or /sys. The virtual files in them also holds a
1420 +memory page (generally) while they are opened. When an idea to reduce
1421 +memory for them is introduced, it will be applied to aufs too.
1422 +For those who really hate this situation, I've developed readdir(3)
1423 +library which operates this merging in userspace. You just need to set
1424 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1425 +kernel space for readdir(3).
1429 +----------------------------------------------------------------------
1430 +Aufs sometimes requires privilege access to a branch. For instance,
1431 +in copy-up/down operation. When a user process is going to make changes
1432 +to a file which exists in the lower readonly branch only, and the mode
1433 +of one of ancestor directories may not be writable by a user
1434 +process. Here aufs copy-up the file with its ancestors and they may
1435 +require privilege to set its owner/group/mode/etc.
1436 +This is a typical case of a application character of aufs (see
1439 +Aufs uses workqueue synchronously for this case. It creates its own
1440 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1441 +passes the request to call mkdir or write (for example), and wait for
1442 +its completion. This approach solves a problem of a signal handler
1444 +If aufs didn't adopt the workqueue and changed the privilege of the
1445 +process, then the process may receive the unexpected SIGXFSZ or other
1448 +Also aufs uses the system global workqueue ("events" kernel thread) too
1449 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1450 +whiteout base and etc. This is unrelated to a privilege.
1451 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1452 +superblock at the beginning, at the same time waits for the completion
1453 +of all queued asynchronous tasks.
1457 +----------------------------------------------------------------------
1458 +The whiteout in aufs is very similar to Unionfs's. That is represented
1459 +by its filename. UnionMount takes an approach of a file mode, but I am
1460 +afraid several utilities (find(1) or something) will have to support it.
1462 +Basically the whiteout represents "logical deletion" which stops aufs to
1463 +lookup further, but also it represents "dir is opaque" which also stop
1466 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1467 +In order to make several functions in a single systemcall to be
1468 +revertible, aufs adopts an approach to rename a directory to a temporary
1469 +unique whiteouted name.
1470 +For example, in rename(2) dir where the target dir already existed, aufs
1471 +renames the target dir to a temporary unique whiteouted name before the
1472 +actual rename on a branch, and then handles other actions (make it opaque,
1473 +update the attributes, etc). If an error happens in these actions, aufs
1474 +simply renames the whiteouted name back and returns an error. If all are
1475 +succeeded, aufs registers a function to remove the whiteouted unique
1476 +temporary name completely and asynchronously to the system global
1481 +----------------------------------------------------------------------
1482 +It is a well-known feature or concept.
1483 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1484 +internally and makes change to the new file on the upper writable branch.
1485 +When the trigger systemcall does not update the timestamps of the parent
1486 +dir, aufs reverts it after copy-up.
1489 +Move-down (aufs3.9 and later)
1490 +----------------------------------------------------------------------
1491 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1492 +the lower readonly branch to the upper writable branch when a user
1493 +changes something about the file.
1494 +"Move-down" is an opposite action of copy-up. Basically this action is
1495 +ran manually instead of automatically and internally.
1496 +For desgin and implementation, aufs has to consider these issues.
1497 +- whiteout for the file may exist on the lower branch.
1498 +- ancestor directories may not exist on the lower branch.
1499 +- diropq for the ancestor directories may exist on the upper branch.
1500 +- free space on the lower branch will reduce.
1501 +- another access to the file may happen during moving-down, including
1502 + UDBA (see "Revalidate Dentry and UDBA").
1503 +- the file should not be hard-linked nor pseudo-linked. they should be
1504 + handled by auplink utility later.
1506 +Sometimes users want to move-down a file from the upper writable branch
1507 +to the lower readonly or writable branch. For instance,
1508 +- the free space of the upper writable branch is going to run out.
1509 +- create a new intermediate branch between the upper and lower branch.
1512 +For this purpose, use "aumvdown" command in aufs-util.git.
1513 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1514 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1515 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2020-01-27 10:57:18.162204582 +0100
1518 +# Copyright (C) 2015-2020 Junjiro R. Okajima
1520 +# This program is free software; you can redistribute it and/or modify
1521 +# it under the terms of the GNU General Public License as published by
1522 +# the Free Software Foundation; either version 2 of the License, or
1523 +# (at your option) any later version.
1525 +# This program is distributed in the hope that it will be useful,
1526 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1527 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1528 +# GNU General Public License for more details.
1530 +# You should have received a copy of the GNU General Public License
1531 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1533 +Support for a branch who has its ->atomic_open()
1534 +----------------------------------------------------------------------
1535 +The filesystems who implement its ->atomic_open() are not majority. For
1536 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1537 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1538 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1539 +sure whether all filesystems who have ->atomic_open() behave like this,
1540 +but NFSv4 surely returns the error.
1542 +In order to support ->atomic_open() for aufs, there are a few
1545 +A. Introduce aufs_atomic_open()
1546 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1548 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1549 + an aufs user Pip Cet's approach
1550 + - calls aufs_create(), VFS finish_open() and notify_change().
1551 + - pass fake-mode to finish_open(), and then correct the mode by
1553 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1554 + - no aufs_atomic_open().
1555 + - aufs_lookup() registers the TID to an aufs internal object.
1556 + - aufs_create() does nothing when the matching TID is registered, but
1557 + registers the mode.
1558 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1559 + TID is registered.
1560 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1562 + - no aufs_atomic_open().
1563 + - aufs_create() registers the TID to an internal object. this info
1564 + represents "this process created this file just now."
1565 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1566 + registered TID and re-try open() with superuser's credential.
1568 +Pros and cons for each approach.
1571 + - straightforward but highly depends upon VFS internal.
1572 + - the atomic behavaiour is kept.
1573 + - some of parameters such as nameidata are hard to reproduce for
1577 + - easy to implement.
1578 + - the atomic behavaiour is lost.
1580 + - the atomic behavaiour is kept.
1581 + - dirty and tricky.
1582 + - VFS checks whether the file is created correctly after calling
1583 + ->create(), which means this approach doesn't work.
1585 + - easy to implement.
1586 + - the atomic behavaiour is lost.
1587 + - to open a file with superuser's credential and give it to a user
1588 + process is a bad idea, since the file object keeps the credential
1589 + in it. It may affect LSM or something. This approach doesn't work
1592 +The approach A is ideal, but it hard to implement. So here is a
1593 +variation of A, which is to be implemented.
1595 +A-1. Introduce aufs_atomic_open()
1596 + - calls branch fs ->atomic_open() if exists. otherwise calls
1597 + vfs_create() and finish_open().
1598 + - the demerit is that the several checks after branch fs
1599 + ->atomic_open() are lost. in the ordinary case, the checks are
1600 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1601 + be implemented in aufs, but not all I am afraid.
1602 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1603 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1604 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2020-01-27 10:57:18.165538015 +0100
1607 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1609 +# This program is free software; you can redistribute it and/or modify
1610 +# it under the terms of the GNU General Public License as published by
1611 +# the Free Software Foundation; either version 2 of the License, or
1612 +# (at your option) any later version.
1614 +# This program is distributed in the hope that it will be useful,
1615 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1616 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1617 +# GNU General Public License for more details.
1619 +# You should have received a copy of the GNU General Public License
1620 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1623 +----------------------------------------------------------------------
1624 +Since aufs has a character of sub-VFS (see Introduction), it operates
1625 +lookup for branches as VFS does. It may be a heavy work. But almost all
1626 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1627 +directly connected to its parent. Digging down the directory hierarchy
1628 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1631 +When a branch is a remote filesystem, aufs basically relies upon its
1632 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1634 +For d_revalidate, aufs implements three levels of revalidate tests. See
1635 +"Revalidate Dentry and UDBA" in detail.
1638 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1639 +----------------------------------------------------------------------
1640 +Let's try case study.
1641 +- aufs has two branches, upper readwrite and lower readonly.
1643 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1644 +- user invoked "chmod a+rx /au/dirA"
1645 +- the internal copy-up is activated and "/rw/dirA" is created and its
1646 + permission bits are set to world readable.
1647 +- then "/au/dirA" becomes world readable?
1649 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1650 +or it may be a natively readonly filesystem. If aufs respects the lower
1651 +branch, it should not respond readdir request from other users. But user
1652 +allowed it by chmod. Should really aufs rejects showing the entries
1655 +To be honest, I don't have a good solution for this case. So aufs
1656 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1658 +When dirperm1 is specified, aufs checks only the highest one for the
1659 +directory permission, and shows the entries. Otherwise, as usual, checks
1660 +every dir existing on all branches and rejects the request.
1662 +As a side effect, dirperm1 option improves the performance of aufs
1663 +because the number of permission check is reduced when the number of
1667 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1668 +----------------------------------------------------------------------
1669 +Generally VFS helpers re-validate a dentry as a part of lookup.
1670 +0. digging down the directory hierarchy.
1671 +1. lock the parent dir by its i_mutex.
1672 +2. lookup the final (child) entry.
1674 +4. call the actual operation (create, unlink, etc.)
1675 +5. unlock the parent dir
1677 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1678 +called. Actually aufs implements it and checks the dentry on a branch is
1680 +But it is not enough. Because aufs has to release the lock for the
1681 +parent dir on a branch at the end of ->lookup() (step 2) and
1682 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1684 +If the file on a branch is changed directly, eg. bypassing aufs, after
1685 +aufs released the lock, then the subsequent operation may cause
1686 +something unpleasant result.
1688 +This situation is a result of VFS architecture, ->lookup() and
1689 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1690 +design from VFS's point of view. It is just not suitable for sub-VFS
1693 +Aufs supports such case by three level of revalidation which is
1694 +selectable by user.
1695 +1. Simple Revalidate
1696 + Addition to the native flow in VFS's, confirm the child-parent
1697 + relationship on the branch just after locking the parent dir on the
1698 + branch in the "actual operation" (step 4). When this validation
1699 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1700 + checks the validation of the dentry on branches.
1701 +2. Monitor Changes Internally by Inotify/Fsnotify
1702 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1703 + the dentry on the branch, and returns EBUSY if it finds different
1705 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1706 + during it is in cache. When the event is notified, aufs registers a
1707 + function to kernel 'events' thread by schedule_work(). And the
1708 + function sets some special status to the cached aufs dentry and inode
1709 + private data. If they are not cached, then aufs has nothing to
1710 + do. When the same file is accessed through aufs (step 0-3) later,
1711 + aufs will detect the status and refresh all necessary data.
1712 + In this mode, aufs has to ignore the event which is fired by aufs
1714 +3. No Extra Validation
1715 + This is the simplest test and doesn't add any additional revalidation
1716 + test, and skip the revalidation in step 4. It is useful and improves
1717 + aufs performance when system surely hide the aufs branches from user,
1718 + by over-mounting something (or another method).
1719 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1720 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1721 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2020-01-27 10:57:18.165538015 +0100
1724 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1726 +# This program is free software; you can redistribute it and/or modify
1727 +# it under the terms of the GNU General Public License as published by
1728 +# the Free Software Foundation; either version 2 of the License, or
1729 +# (at your option) any later version.
1731 +# This program is distributed in the hope that it will be useful,
1732 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1733 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1734 +# GNU General Public License for more details.
1736 +# You should have received a copy of the GNU General Public License
1737 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1739 +Branch Manipulation
1741 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1742 +and changing its permission/attribute, there are a lot of works to do.
1746 +----------------------------------------------------------------------
1747 +o Confirm the adding dir exists outside of aufs, including loopback
1748 + mount, and its various attributes.
1749 +o Initialize the xino file and whiteout bases if necessary.
1752 +o Check the owner/group/mode of the directory
1753 + When the owner/group/mode of the adding directory differs from the
1754 + existing branch, aufs issues a warning because it may impose a
1756 + For example, when a upper writable branch has a world writable empty
1757 + top directory, a malicious user can create any files on the writable
1758 + branch directly, like copy-up and modify manually. If something like
1759 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1760 + writable branch, and the writable branch is world-writable, then a
1761 + malicious guy may create /etc/passwd on the writable branch directly
1762 + and the infected file will be valid in aufs.
1763 + I am afraid it can be a security issue, but aufs can do nothing except
1764 + producing a warning.
1768 +----------------------------------------------------------------------
1769 +o Confirm the deleting branch is not busy
1770 + To be general, there is one merit to adopt "remount" interface to
1771 + manipulate branches. It is to discard caches. At deleting a branch,
1772 + aufs checks the still cached (and connected) dentries and inodes. If
1773 + there are any, then they are all in-use. An inode without its
1774 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1776 + For the cached one, aufs checks whether the same named entry exists on
1778 + If the cached one is a directory, because aufs provides a merged view
1779 + to users, as long as one dir is left on any branch aufs can show the
1780 + dir to users. In this case, the branch can be removed from aufs.
1781 + Otherwise aufs rejects deleting the branch.
1783 + If any file on the deleting branch is opened by aufs, then aufs
1787 +Modify the Permission of a Branch
1788 +----------------------------------------------------------------------
1789 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1792 +o rw --> ro: Confirm the modifying branch is not busy
1793 + Aufs rejects the request if any of these conditions are true.
1794 + - a file on the branch is mmap-ed.
1795 + - a regular file on the branch is opened for write and there is no
1796 + same named entry on the upper branch.
1797 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1798 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1799 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2020-01-27 10:57:18.165538015 +0100
1802 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1804 +# This program is free software; you can redistribute it and/or modify
1805 +# it under the terms of the GNU General Public License as published by
1806 +# the Free Software Foundation; either version 2 of the License, or
1807 +# (at your option) any later version.
1809 +# This program is distributed in the hope that it will be useful,
1810 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1811 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1812 +# GNU General Public License for more details.
1814 +# You should have received a copy of the GNU General Public License
1815 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1817 +Policies to Select One among Multiple Writable Branches
1818 +----------------------------------------------------------------------
1819 +When the number of writable branch is more than one, aufs has to decide
1820 +the target branch for file creation or copy-up. By default, the highest
1821 +writable branch which has the parent (or ancestor) dir of the target
1822 +file is chosen (top-down-parent policy).
1823 +By user's request, aufs implements some other policies to select the
1824 +writable branch, for file creation several policies, round-robin,
1825 +most-free-space, and other policies. For copy-up, top-down-parent,
1826 +bottom-up-parent, bottom-up and others.
1828 +As expected, the round-robin policy selects the branch in circular. When
1829 +you have two writable branches and creates 10 new files, 5 files will be
1830 +created for each branch. mkdir(2) systemcall is an exception. When you
1831 +create 10 new directories, all will be created on the same branch.
1832 +And the most-free-space policy selects the one which has most free
1833 +space among the writable branches. The amount of free space will be
1834 +checked by aufs internally, and users can specify its time interval.
1836 +The policies for copy-up is more simple,
1837 +top-down-parent is equivalent to the same named on in create policy,
1838 +bottom-up-parent selects the writable branch where the parent dir
1839 +exists and the nearest upper one from the copyup-source,
1840 +bottom-up selects the nearest upper writable branch from the
1841 +copyup-source, regardless the existence of the parent dir.
1843 +There are some rules or exceptions to apply these policies.
1844 +- If there is a readonly branch above the policy-selected branch and
1845 + the parent dir is marked as opaque (a variation of whiteout), or the
1846 + target (creating) file is whiteout-ed on the upper readonly branch,
1847 + then the result of the policy is ignored and the target file will be
1848 + created on the nearest upper writable branch than the readonly branch.
1849 +- If there is a writable branch above the policy-selected branch and
1850 + the parent dir is marked as opaque or the target file is whiteouted
1851 + on the branch, then the result of the policy is ignored and the target
1852 + file will be created on the highest one among the upper writable
1853 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1855 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1856 + They try selecting the branch where the source exists as possible
1857 + since copyup a large file will take long time. If it can't be,
1858 + ie. the branch where the source exists is readonly, then they will
1859 + follow the copyup policy.
1860 +- There is an exception for rename(2) when the target exists.
1861 + If the rename target exists, aufs compares the index of the branches
1862 + where the source and the target exists and selects the higher
1863 + one. If the selected branch is readonly, then aufs follows the
1865 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1866 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1867 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2019-07-11 15:42:14.458904362 +0200
1870 +// to view this graph, run dot(1) command in GRAPHVIZ.
1874 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1878 +aufs_rename -> whinfo [label="store/remove"];
1881 +inode_list [label="h_inum list in branch\ncache"];
1884 +whinode [label="h_inum list file"];
1887 +brmgmt [label="br_add/del/mod/umount"];
1889 +brmgmt -> inode_list [label="create/remove"];
1890 +brmgmt -> whinode [label="load/store"];
1892 +inode_list -> whinode [style=dashed,dir=both];
1894 +aufs_rename -> inode_list [label="add/del"];
1896 +aufs_lookup -> inode_list [label="search"];
1898 +aufs_lookup -> whinfo [label="load/remove"];
1900 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1901 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1902 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2020-01-27 10:57:18.165538015 +0100
1905 +# Copyright (C) 2017-2020 Junjiro R. Okajima
1907 +# This program is free software; you can redistribute it and/or modify
1908 +# it under the terms of the GNU General Public License as published by
1909 +# the Free Software Foundation; either version 2 of the License, or
1910 +# (at your option) any later version.
1912 +# This program is distributed in the hope that it will be useful,
1913 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1914 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1915 +# GNU General Public License for more details.
1917 +# You should have received a copy of the GNU General Public License
1918 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1920 +Special handling for renaming a directory (DIRREN)
1921 +----------------------------------------------------------------------
1922 +First, let's assume we have a simple usecase.
1926 +- /ro/dirA and /ro/dirA/file exist too
1927 +- there is no dirB on both branches
1928 +- a user issues rename("dirA", "dirB")
1930 +Now, what should aufs behave against this rename(2)?
1931 +There are a few possible cases.
1934 + since dirA exists on a readonly branch which cannot be renamed.
1936 + it is possible to copy-up dirA (only the dir itself), but the child
1937 + entries ("file" in this case) should not be. it must be a bad
1938 + approach to copy-up recursively.
1939 +C. returns a success.
1940 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
1941 + is a violation of aufs' policy.
1942 +D. construct an extra information which indicates that /ro/dirA should
1943 + be handled as the name of dirB.
1944 + overlayfs has a similar feature called REDIRECT.
1946 +Until now, aufs implements the case B only which returns EXDEV, and
1947 +expects the userspace application behaves like mv(1) which tries
1948 +issueing rename(2) recursively.
1950 +A new aufs feature called DIRREN is introduced which implements the case
1951 +D. There are several "extra information" added.
1953 +1. detailed info per renamed directory
1954 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
1955 +2. the inode-number list of directories on a branch
1956 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
1958 +The filename of "detailed info per directory" represents the lower
1959 +branch, and its format is
1960 +- a type of the branch id
1962 + + uuid (not implemented yet)
1965 +- the inode-number of the branch root dir
1967 +And it contains these info in a single regular file.
1969 +- branch's inode-number of the logically renamed dir
1970 +- the name of the before-renamed dir
1972 +The "detailed info per directory" file is created in aufs rename(2), and
1973 +loaded in any lookup.
1974 +The info is considered in lookup for the matching case only. Here
1975 +"matching" means that the root of branch (in the info filename) is same
1976 +to the current looking-up branch. After looking-up the before-renamed
1977 +name, the inode-number is compared. And the matched dentry is used.
1979 +The "inode-number list of directories" is a regular file which contains
1980 +simply the inode-numbers on the branch. The file is created or updated
1981 +in removing the branch, and loaded in adding the branch. Its lifetime is
1982 +equal to the branch.
1983 +The list is refered in lookup, and when the current target inode is
1984 +found in the list, the aufs tries loading the "detailed info per
1985 +directory" and get the changed and valid name of the dir.
1987 +Theoretically these "extra informaiton" may be able to be put into XATTR
1988 +in the dir inode. But aufs doesn't choose this way because
1989 +1. XATTR may not be supported by the branch (or its configuration)
1990 +2. XATTR may have its size limit.
1991 +3. XATTR may be less easy to convert than a regular file, when the
1992 + format of the info is changed in the future.
1993 +At the same time, I agree that the regular file approach is much slower
1994 +than XATTR approach. So, in the future, aufs may take the XATTR or other
1997 +This DIRREN feature is enabled by aufs configuration, and is activated
1998 +by a new mount option.
2000 +For the more complicated case, there is a work with UDBA option, which
2001 +is to dected the direct access to the branches (by-passing aufs) and to
2002 +maintain the cashes in aufs. Since a single cached aufs dentry may
2003 +contains two names, before- and after-rename, the name comparision in
2004 +UDBA handler may not work correctly. In this case, the behaviour will be
2005 +equivalen to udba=reval case.
2006 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
2007 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
2008 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2020-01-27 10:57:18.165538015 +0100
2011 +# Copyright (C) 2011-2020 Junjiro R. Okajima
2013 +# This program is free software; you can redistribute it and/or modify
2014 +# it under the terms of the GNU General Public License as published by
2015 +# the Free Software Foundation; either version 2 of the License, or
2016 +# (at your option) any later version.
2018 +# This program is distributed in the hope that it will be useful,
2019 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2020 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2021 +# GNU General Public License for more details.
2023 +# You should have received a copy of the GNU General Public License
2024 +# along with this program; if not, write to the Free Software
2025 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2028 +File-based Hierarchical Storage Management (FHSM)
2029 +----------------------------------------------------------------------
2030 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2031 +storage world. Aufs provides this feature as file-based with multiple
2032 +writable branches, based upon the principle of "Colder, the Lower".
2033 +Here the word "colder" means that the less used files, and "lower" means
2034 +that the position in the order of the stacked branches vertically.
2035 +These multiple writable branches are prioritized, ie. the topmost one
2036 +should be the fastest drive and be used heavily.
2038 +o Characters in aufs FHSM story
2039 +- aufs itself and a new branch attribute.
2040 +- a new ioctl interface to move-down and to establish a connection with
2041 + the daemon ("move-down" is a converse of "copy-up").
2042 +- userspace tool and daemon.
2044 +The userspace daemon establishes a connection with aufs and waits for
2045 +the notification. The notified information is very similar to struct
2046 +statfs containing the number of consumed blocks and inodes.
2047 +When the consumed blocks/inodes of a branch exceeds the user-specified
2048 +upper watermark, the daemon activates its move-down process until the
2049 +consumed blocks/inodes reaches the user-specified lower watermark.
2051 +The actual move-down is done by aufs based upon the request from
2052 +user-space since we need to maintain the inode number and the internal
2053 +pointer arrays in aufs.
2055 +Currently aufs FHSM handles the regular files only. Additionally they
2056 +must not be hard-linked nor pseudo-linked.
2059 +o Cowork of aufs and the user-space daemon
2060 + During the userspace daemon established the connection, aufs sends a
2061 + small notification to it whenever aufs writes something into the
2062 + writable branch. But it may cost high since aufs issues statfs(2)
2063 + internally. So user can specify a new option to cache the
2064 + info. Actually the notification is controlled by these factors.
2065 + + the specified cache time.
2066 + + classified as "force" by aufs internally.
2067 + Until the specified time expires, aufs doesn't send the info
2068 + except the forced cases. When aufs decide forcing, the info is always
2069 + notified to userspace.
2070 + For example, the number of free inodes is generally large enough and
2071 + the shortage of it happens rarely. So aufs doesn't force the
2072 + notification when creating a new file, directory and others. This is
2073 + the typical case which aufs doesn't force.
2074 + When aufs writes the actual filedata and the files consumes any of new
2075 + blocks, the aufs forces notifying.
2078 +o Interfaces in aufs
2079 +- New branch attribute.
2081 + Specifies that the branch is managed by FHSM feature. In other word,
2082 + participant in the FHSM.
2083 + When nofhsm is set to the branch, it will not be the source/target
2084 + branch of the move-down operation. This attribute is set
2085 + independently from coo and moo attributes, and if you want full
2086 + FHSM, you should specify them as well.
2087 +- New mount option.
2089 + Specifies a second to suppress many less important info to be
2092 + + AUFS_CTL_FHSM_FD
2093 + create a new file descriptor which userspace can read the notification
2094 + (a subset of struct statfs) from aufs.
2095 +- Module parameter 'brs'
2096 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2098 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2099 + When there are two or more branches with fhsm attributes,
2100 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2101 + terminates it. As a result of remounting and branch-manipulation, the
2102 + number of branches with fhsm attribute can be one. In this case,
2103 + /sbin/mount.aufs will terminate the user-space daemon.
2106 +Finally the operation is done as these steps in kernel-space.
2108 + + no one else is using the file.
2109 + + the file is not hard-linked.
2110 + + the file is not pseudo-linked.
2111 + + the file is a regular file.
2112 + + the parent dir is not opaqued.
2113 +- find the target writable branch.
2114 +- make sure the file is not whiteout-ed by the upper (than the target)
2116 +- make the parent dir on the target branch.
2117 +- mutex lock the inode on the branch.
2118 +- unlink the whiteout on the target branch (if exists).
2119 +- lookup and create the whiteout-ed temporary name on the target branch.
2120 +- copy the file as the whiteout-ed temporary name on the target branch.
2121 +- rename the whiteout-ed temporary name to the original name.
2122 +- unlink the file on the source branch.
2123 +- maintain the internal pointer array and the external inode number
2125 +- maintain the timestamps and other attributes of the parent dir and the
2128 +And of course, in every step, an error may happen. So the operation
2129 +should restore the original file state after an error happens.
2130 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2131 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2132 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2020-01-27 10:57:18.165538015 +0100
2135 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2137 +# This program is free software; you can redistribute it and/or modify
2138 +# it under the terms of the GNU General Public License as published by
2139 +# the Free Software Foundation; either version 2 of the License, or
2140 +# (at your option) any later version.
2142 +# This program is distributed in the hope that it will be useful,
2143 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2144 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2145 +# GNU General Public License for more details.
2147 +# You should have received a copy of the GNU General Public License
2148 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2150 +mmap(2) -- File Memory Mapping
2151 +----------------------------------------------------------------------
2152 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2153 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2155 +This approach is simple and good, but there is one problem.
2156 +Under /proc, several entries show the mmapped files by its path (with
2157 +device and inode number), and the printed path will be the path on the
2158 +branch fs's instead of virtual aufs's.
2159 +This is not a problem in most cases, but some utilities lsof(1) (and its
2160 +user) may expect the path on aufs.
2162 +To address this issue, aufs adds a new member called vm_prfile in struct
2163 +vm_area_struct (and struct vm_region). The original vm_file points to
2164 +the file on the branch fs in order to handle everything correctly as
2165 +usual. The new vm_prfile points to a virtual file in aufs, and the
2166 +show-functions in procfs refers to vm_prfile if it is set.
2167 +Also we need to maintain several other places where touching vm_file
2169 +- fork()/clone() copies vma and the reference count of vm_file is
2171 +- merging vma maintains the ref count too.
2173 +This is not a good approach. It just fakes the printed path. But it
2174 +leaves all behaviour around f_mapping unchanged. This is surely an
2176 +Actually aufs had adopted another complicated approach which calls
2177 +generic_file_mmap() and handles struct vm_operations_struct. In this
2178 +approach, aufs met a hard problem and I could not solve it without
2179 +switching the approach.
2181 +There may be one more another approach which is
2182 +- bind-mount the branch-root onto the aufs-root internally
2183 +- grab the new vfsmount (ie. struct mount)
2184 +- lazy-umount the branch-root internally
2185 +- in open(2) the aufs-file, open the branch-file with the hidden
2186 + vfsmount (instead of the original branch's vfsmount)
2187 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2188 + but it may be possible from userspace by the mount helper.
2190 +Adding the internal hidden vfsmount and using it in opening a file, the
2191 +file path under /proc will be printed correctly. This approach looks
2192 +smarter, but is not possible I am afraid.
2193 +- aufs-root may be bind-mount later. when it happens, another hidden
2194 + vfsmount will be required.
2195 +- it is hard to get the chance to bind-mount and lazy-umount
2196 + + in kernel-space, FS can have vfsmount in open(2) via
2197 + file->f_path, and aufs can know its vfsmount. But several locks are
2198 + already acquired, and if aufs tries to bind-mount and lazy-umount
2199 + here, then it may cause a deadlock.
2200 + + in user-space, bind-mount doesn't invoke the mount helper.
2201 +- since /proc shows dev and ino, aufs has to give vma these info. it
2202 + means a new member vm_prinode will be necessary. this is essentially
2203 + equivalent to vm_prfile described above.
2205 +I have to give up this "looks-smater" approach.
2206 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2207 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2208 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2020-01-27 10:57:18.165538015 +0100
2211 +# Copyright (C) 2014-2020 Junjiro R. Okajima
2213 +# This program is free software; you can redistribute it and/or modify
2214 +# it under the terms of the GNU General Public License as published by
2215 +# the Free Software Foundation; either version 2 of the License, or
2216 +# (at your option) any later version.
2218 +# This program is distributed in the hope that it will be useful,
2219 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2220 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2221 +# GNU General Public License for more details.
2223 +# You should have received a copy of the GNU General Public License
2224 +# along with this program; if not, write to the Free Software
2225 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2228 +Listing XATTR/EA and getting the value
2229 +----------------------------------------------------------------------
2230 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2231 +shows the values from the topmost existing file. This behaviour is good
2232 +for the non-dir entries since the bahaviour exactly matches the shown
2233 +information. But for the directories, aufs considers all the same named
2234 +entries on the lower branches. Which means, if one of the lower entry
2235 +rejects readdir call, then aufs returns an error even if the topmost
2236 +entry allows it. This behaviour is necessary to respect the branch fs's
2237 +security, but can make users confused since the user-visible standard
2238 +attributes don't match the behaviour.
2239 +To address this issue, aufs has a mount option called dirperm1 which
2240 +checks the permission for the topmost entry only, and ignores the lower
2241 +entry's permission.
2243 +A similar issue can happen around XATTR.
2244 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2245 +always set. Otherwise these very unpleasant situation would happen.
2246 +- listxattr(2) may return the duplicated entries.
2247 +- users may not be able to remove or reset the XATTR forever,
2250 +XATTR/EA support in the internal (copy,move)-(up,down)
2251 +----------------------------------------------------------------------
2252 +Generally the extended attributes of inode are categorized as these.
2253 +- "security" for LSM and capability.
2254 +- "system" for posix ACL, 'acl' mount option is required for the branch
2256 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2257 +- "user" for userspace, 'user_xattr' mount option is required for the
2258 + branch fs generally.
2260 +Moreover there are some other categories. Aufs handles these rather
2261 +unpopular categories as the ordinary ones, ie. there is no special
2262 +condition nor exception.
2264 +In copy-up, the support for XATTR on the dst branch may differ from the
2265 +src branch. In this case, the copy-up operation will get an error and
2266 +the original user operation which triggered the copy-up will fail. It
2267 +can happen that even all copy-up will fail.
2268 +When both of src and dst branches support XATTR and if an error occurs
2269 +during copying XATTR, then the copy-up should fail obviously. That is a
2270 +good reason and aufs should return an error to userspace. But when only
2271 +the src branch support that XATTR, aufs should not return an error.
2272 +For example, the src branch supports ACL but the dst branch doesn't
2273 +because the dst branch may natively un-support it or temporary
2274 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2275 +may NOT return an error even if the XATTR is not supported. It is
2276 +totally up to the branch fs.
2278 +Anyway when the aufs internal copy-up gets an error from the dst branch
2279 +fs, then aufs tries removing the just copied entry and returns the error
2280 +to the userspace. The worst case of this situation will be all copy-up
2283 +For the copy-up operation, there two basic approaches.
2284 +- copy the specified XATTR only (by category above), and return the
2285 + error unconditionally if it happens.
2286 +- copy all XATTR, and ignore the error on the specified category only.
2288 +In order to support XATTR and to implement the correct behaviour, aufs
2289 +chooses the latter approach and introduces some new branch attributes,
2290 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2291 +They correspond to the XATTR namespaces (see above). Additionally, to be
2292 +convenient, "icex" is also provided which means all "icex*" attributes
2293 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2295 +The meaning of these attributes is to ignore the error from setting
2296 +XATTR on that branch.
2297 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2298 +error from the dst branch according to the specified attributes.
2300 +Some XATTR may have its default value. The default value may come from
2301 +the parent dir or the environment. If the default value is set at the
2302 +file creating-time, it will be overwritten by copy-up.
2303 +Some contradiction may happen I am afraid.
2304 +Do we need another attribute to stop copying XATTR? I am unsure. For
2305 +now, aufs implements the branch attributes to ignore the error.
2306 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2307 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2308 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2020-01-27 10:57:18.165538015 +0100
2311 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2313 +# This program is free software; you can redistribute it and/or modify
2314 +# it under the terms of the GNU General Public License as published by
2315 +# the Free Software Foundation; either version 2 of the License, or
2316 +# (at your option) any later version.
2318 +# This program is distributed in the hope that it will be useful,
2319 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2320 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2321 +# GNU General Public License for more details.
2323 +# You should have received a copy of the GNU General Public License
2324 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2326 +Export Aufs via NFS
2327 +----------------------------------------------------------------------
2328 +Here is an approach.
2329 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2331 +- iget_locked(): initialize aufs inode generation for a new inode, and
2332 + store it in xigen file.
2333 +- destroy_inode(): increment aufs inode generation and store it in xigen
2334 + file. it is necessary even if it is not unlinked, because any data of
2335 + inode may be changed by UDBA.
2336 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2337 + build file handle by
2338 + + branch id (4 bytes)
2339 + + superblock generation (4 bytes)
2340 + + inode number (4 or 8 bytes)
2341 + + parent dir inode number (4 or 8 bytes)
2342 + + inode generation (4 bytes))
2343 + + return value of exportfs_encode_fh() for the parent on a branch (4
2345 + + file handle for a branch (by exportfs_encode_fh())
2347 + + find the index of a branch from its id in handle, and check it is
2348 + still exist in aufs.
2349 + + 1st level: get the inode number from handle and search it in cache.
2350 + + 2nd level: if not found in cache, get the parent inode number from
2351 + the handle and search it in cache. and then open the found parent
2352 + dir, find the matching inode number by vfs_readdir() and get its
2353 + name, and call lookup_one_len() for the target dentry.
2354 + + 3rd level: if the parent dir is not cached, call
2355 + exportfs_decode_fh() for a branch and get the parent on a branch,
2356 + build a pathname of it, convert it a pathname in aufs, call
2357 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2359 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2360 + for every branch, but not itself. to get this, (currently) aufs
2361 + searches in current->nsproxy->mnt_ns list. it may not be a good
2362 + idea, but I didn't get other approach.
2363 + + test the generation of the gotten inode.
2364 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2365 + convert it into ESTALE for NFSD.
2366 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2367 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2368 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2369 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2370 +++ linux/Documentation/filesystems/aufs/design/08shwh.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 +Show Whiteout Mode (shwh)
2389 +----------------------------------------------------------------------
2390 +Generally aufs hides the name of whiteouts. But in some cases, to show
2391 +them is very useful for users. For instance, creating a new middle layer
2392 +(branch) by merging existing layers.
2394 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2395 +When you have three branches,
2396 +- Bottom: 'system', squashfs (underlying base system), read-only
2397 +- Middle: 'mods', squashfs, read-only
2398 +- Top: 'overlay', ram (tmpfs), read-write
2400 +The top layer is loaded at boot time and saved at shutdown, to preserve
2401 +the changes made to the system during the session.
2402 +When larger changes have been made, or smaller changes have accumulated,
2403 +the size of the saved top layer data grows. At this point, it would be
2404 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2405 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2406 +restoring save and load speed.
2408 +This merging is simplified by the use of another aufs mount, of just the
2409 +two overlay branches using the 'shwh' option.
2410 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2411 + aufs /livesys/merge_union
2413 +A merged view of these two branches is then available at
2414 +/livesys/merge_union, and the new feature is that the whiteouts are
2416 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2417 +writing to all branches. Also the default mode for all branches is 'ro'.
2418 +It is now possible to save the combined contents of the two overlay
2419 +branches to a new squashfs, e.g.:
2420 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2422 +This new squashfs archive can be stored on the boot device and the
2423 +initramfs will use it to replace the old one at the next boot.
2424 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2425 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2426 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2020-01-27 10:57:18.165538015 +0100
2429 +# Copyright (C) 2010-2020 Junjiro R. Okajima
2431 +# This program is free software; you can redistribute it and/or modify
2432 +# it under the terms of the GNU General Public License as published by
2433 +# the Free Software Foundation; either version 2 of the License, or
2434 +# (at your option) any later version.
2436 +# This program is distributed in the hope that it will be useful,
2437 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2438 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2439 +# GNU General Public License for more details.
2441 +# You should have received a copy of the GNU General Public License
2442 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2444 +Dynamically customizable FS operations
2445 +----------------------------------------------------------------------
2446 +Generally FS operations (struct inode_operations, struct
2447 +address_space_operations, struct file_operations, etc.) are defined as
2448 +"static const", but it never means that FS have only one set of
2449 +operation. Some FS have multiple sets of them. For instance, ext2 has
2450 +three sets, one for XIP, for NOBH, and for normal.
2451 +Since aufs overrides and redirects these operations, sometimes aufs has
2452 +to change its behaviour according to the branch FS type. More importantly
2453 +VFS acts differently if a function (member in the struct) is set or
2454 +not. It means aufs should have several sets of operations and select one
2455 +among them according to the branch FS definition.
2457 +In order to solve this problem and not to affect the behaviour of VFS,
2458 +aufs defines these operations dynamically. For instance, aufs defines
2459 +dummy direct_IO function for struct address_space_operations, but it may
2460 +not be set to the address_space_operations actually. When the branch FS
2461 +doesn't have it, aufs doesn't set it to its address_space_operations
2462 +while the function definition itself is still alive. So the behaviour
2463 +itself will not change, and it will return an error when direct_IO is
2466 +The lifetime of these dynamically generated operation object is
2467 +maintained by aufs branch object. When the branch is removed from aufs,
2468 +the reference counter of the object is decremented. When it reaches
2469 +zero, the dynamically generated operation object will be freed.
2471 +This approach is designed to support AIO (io_submit), Direct I/O and
2473 +Currently this approach is applied to address_space_operations for
2474 +regular files only.
2475 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2476 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2477 +++ linux/Documentation/filesystems/aufs/README 2020-01-23 09:59:36.748660743 +0100
2480 +Aufs5 -- advanced multi layered unification filesystem version 5.x
2486 +----------------------------------------
2487 +In the early days, aufs was entirely re-designed and re-implemented
2488 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2489 +improvements and implementations, it became totally different from
2490 +Unionfs while keeping the basic features.
2491 +Later, Unionfs Version 2.x series began taking some of the same
2492 +approaches to aufs1's.
2493 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2494 +University and his team.
2496 +Aufs5 supports linux-v5.0 and later, If you want older kernel version
2498 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2499 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2500 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2501 + or aufs1 from CVS on SourceForge.
2503 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2504 + According to Christoph Hellwig, linux rejects all union-type
2505 + filesystems but UnionMount.
2506 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2508 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2509 + UnionMount, and he pointed out an issue around a directory mutex
2510 + lock and aufs addressed it. But it is still unsure whether aufs will
2511 + be merged (or any other union solution).
2512 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2516 +----------------------------------------
2517 +- unite several directories into a single virtual filesystem. The member
2518 + directory is called as a branch.
2519 +- you can specify the permission flags to the branch, which are 'readonly',
2520 + 'readwrite' and 'whiteout-able.'
2521 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2522 + readonly branch are modifiable logically.
2523 +- dynamic branch manipulation, add, del.
2526 +Also there are many enhancements in aufs, such as:
2527 +- test only the highest one for the directory permission (dirperm1)
2528 +- copyup on open (coo=)
2529 +- 'move' policy for copy-up between two writable branches, after
2530 + checking free space.
2532 +- readdir(3) in userspace.
2533 +- keep inode number by external inode number table
2534 +- keep the timestamps of file/dir in internal copyup operation
2535 +- seekable directory, supporting NFS readdir.
2536 +- whiteout is hardlinked in order to reduce the consumption of inodes
2538 +- do not copyup, nor create a whiteout when it is unnecessary
2539 +- revert a single systemcall when an error occurs in aufs
2540 +- remount interface instead of ioctl
2541 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2542 +- loopback mounted filesystem as a branch
2543 +- kernel thread for removing the dir who has a plenty of whiteouts
2544 +- support copyup sparse file (a file which has a 'hole' in it)
2545 +- default permission flags for branches
2546 +- selectable permission flags for ro branch, whether whiteout can
2549 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2550 +- support multiple writable branches, some policies to select one
2551 + among multiple writable branches.
2552 +- a new semantics for link(2) and rename(2) to support multiple
2553 + writable branches.
2554 +- no glibc changes are required.
2555 +- pseudo hardlink (hardlink over branches)
2556 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2557 + including NFS or remote filesystem branch.
2558 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2561 +Currently these features are dropped temporary from aufs5.
2562 +See design/08plan.txt in detail.
2563 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2565 +- statistics of aufs thread (/sys/fs/aufs/stat)
2567 +Features or just an idea in the future (see also design/*.txt),
2568 +- reorder the branch index without del/re-add.
2569 +- permanent xino files for NFSD
2570 +- an option for refreshing the opened files after add/del branches
2571 +- light version, without branch manipulation. (unnecessary?)
2572 +- copyup in userspace
2573 +- inotify in userspace
2578 +----------------------------------------
2579 +There are three GIT trees for aufs5, aufs5-linux.git,
2580 +aufs5-standalone.git, and aufs-util.git. Note that there is no "5" in
2582 +While the aufs-util is always necessary, you need either of aufs5-linux
2583 +or aufs5-standalone.
2585 +The aufs5-linux tree includes the whole linux mainline GIT tree,
2586 +git://git.kernel.org/.../torvalds/linux.git.
2587 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2588 +build aufs5 as an external kernel module.
2589 +Several extra patches are not included in this tree. Only
2590 +aufs5-standalone tree contains them. They are described in the later
2591 +section "Configuration and Compilation."
2593 +On the other hand, the aufs5-standalone tree has only aufs source files
2594 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2595 +But you need to apply all aufs patches manually.
2597 +You will find GIT branches whose name is in form of "aufs5.x" where "x"
2598 +represents the linux kernel version, "linux-5.x". For instance,
2599 +"aufs5.0" is for linux-5.0. For latest "linux-5.x-rcN", use
2600 +"aufs5.x-rcN" branch.
2603 +$ git clone --reference /your/linux/git/tree \
2604 + git://github.com/sfjro/aufs5-linux.git aufs5-linux.git
2605 +- if you don't have linux GIT tree, then remove "--reference ..."
2606 +$ cd aufs5-linux.git
2607 +$ git checkout origin/aufs5.0
2609 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2610 +leave the patch-work to GIT.
2611 +$ cd /your/linux/git/tree
2612 +$ git remote add aufs5 git://github.com/sfjro/aufs5-linux.git
2614 +$ git checkout -b my5.0 v5.0
2615 +$ (add your local change...)
2616 +$ git pull aufs5 aufs5.0
2617 +- now you have v5.0 + your_changes + aufs5.0 in you my5.0 branch.
2618 +- you may need to solve some conflicts between your_changes and
2619 + aufs5.0. in this case, git-rerere is recommended so that you can
2620 + solve the similar conflicts automatically when you upgrade to 5.1 or
2621 + later in the future.
2623 +o aufs5-standalone tree
2624 +$ git clone git://github.com/sfjro/aufs5-standalone.git aufs5-standalone.git
2625 +$ cd aufs5-standalone.git
2626 +$ git checkout origin/aufs5.0
2629 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2630 +- note that the public aufs-util.git is on SourceForge instead of
2633 +$ git checkout origin/aufs5.0
2635 +Note: The 5.x-rcN branch is to be used with `rc' kernel versions ONLY.
2636 +The minor version number, 'x' in '5.x', of aufs may not always
2637 +follow the minor version number of the kernel.
2638 +Because changes in the kernel that cause the use of a new
2639 +minor version number do not always require changes to aufs-util.
2641 +Since aufs-util has its own minor version number, you may not be
2642 +able to find a GIT branch in aufs-util for your kernel's
2643 +exact minor version number.
2644 +In this case, you should git-checkout the branch for the
2645 +nearest lower number.
2647 +For (an unreleased) example:
2648 +If you are using "linux-5.10" and the "aufs5.10" branch
2649 +does not exist in aufs-util repository, then "aufs5.9", "aufs5.8"
2650 +or something numerically smaller is the branch for your kernel.
2652 +Also you can view all branches by
2656 +3. Configuration and Compilation
2657 +----------------------------------------
2658 +Make sure you have git-checkout'ed the correct branch.
2660 +For aufs5-linux tree,
2661 +- enable CONFIG_AUFS_FS.
2662 +- set other aufs configurations if necessary.
2664 +For aufs5-standalone tree,
2665 +There are several ways to build.
2668 +- apply ./aufs5-kbuild.patch to your kernel source files.
2669 +- apply ./aufs5-base.patch too.
2670 +- apply ./aufs5-mmap.patch too.
2671 +- apply ./aufs5-standalone.patch too, if you have a plan to set
2672 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch.
2673 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2674 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2675 +- enable CONFIG_AUFS_FS, you can select either
2677 +- and build your kernel as usual.
2678 +- install the built kernel.
2679 +- install the header files too by "make headers_install" to the
2680 + directory where you specify. By default, it is $PWD/usr.
2681 + "make help" shows a brief note for headers_install.
2682 +- and reboot your system.
2685 +- module only (CONFIG_AUFS_FS=m).
2686 +- apply ./aufs5-base.patch to your kernel source files.
2687 +- apply ./aufs5-mmap.patch too.
2688 +- apply ./aufs5-standalone.patch too.
2689 +- build your kernel, don't forget "make headers_install", and reboot.
2690 +- edit ./config.mk and set other aufs configurations if necessary.
2691 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2692 + every aufs configurations.
2693 +- build the module by simple "make".
2694 +- you can specify ${KDIR} make variable which points to your kernel
2696 +- install the files
2697 + + run "make install" to install the aufs module, or copy the built
2698 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2699 + + run "make install_headers" (instead of headers_install) to install
2700 + the modified aufs header file (you can specify DESTDIR which is
2701 + available in aufs standalone version's Makefile only), or copy
2702 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2703 + you like manually. By default, the target directory is $PWD/usr.
2704 +- no need to apply aufs5-kbuild.patch, nor copying source files to your
2705 + kernel source tree.
2707 +Note: The header file aufs_type.h is necessary to build aufs-util
2708 + as well as "make headers_install" in the kernel source tree.
2709 + headers_install is subject to be forgotten, but it is essentially
2710 + necessary, not only for building aufs-util.
2711 + You may not meet problems without headers_install in some older
2715 +- read README in aufs-util, build and install it
2716 +- note that your distribution may contain an obsoleted version of
2717 + aufs_type.h in /usr/include/linux or something. When you build aufs
2718 + utilities, make sure that your compiler refers the correct aufs header
2719 + file which is built by "make headers_install."
2720 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2721 + then run "make install_ulib" too. And refer to the aufs manual in
2724 +There several other patches in aufs5-standalone.git. They are all
2725 +optional. When you meet some problems, they will help you.
2726 +- aufs5-loopback.patch
2727 + Supports a nested loopback mount in a branch-fs. This patch is
2728 + unnecessary until aufs produces a message like "you may want to try
2729 + another patch for loopback file".
2730 +- proc_mounts.patch
2731 + When there are many mountpoints and many mount(2)/umount(2) are
2732 + running, then /proc/mounts may not show the all mountpoints. This
2733 + patch makes /proc/mounts always show the full mountpoints list.
2734 + If you don't want to apply this patch and meet such problem, then you
2735 + need to increase the value of 'ProcMounts_Times' make-variable in
2736 + aufs-util.git as a second best solution.
2738 + Modifies a system global kernel internal function get_next_ino() in
2739 + order to stop assigning 0 for an inode-number. Not directly related to
2740 + aufs, but recommended generally.
2742 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2743 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2744 + duplication of inode number, which is important for backup tools and
2745 + other utilities. When you find aufs XINO files for tmpfs branch
2746 + growing too much, try this patch.
2747 +- lockdep-debug.patch
2748 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2749 + also a caller of VFS functions for branch filesystems, subclassing of
2750 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2751 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2752 + need to apply this debug patch to expand several constant values.
2753 + If you don't know what LOCKDEP is, then you don't have apply this
2758 +----------------------------------------
2759 +At first, make sure aufs-util are installed, and please read the aufs
2760 +manual, aufs.5 in aufs-util.git tree.
2764 +$ mkdir /tmp/rw /tmp/aufs
2765 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2767 +Here is another example. The result is equivalent.
2768 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2770 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2771 +# mount -o remount,append:${HOME} /tmp/aufs
2773 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2774 +you modify a file under /tmp/aufs, the one on your home directory is
2775 +not affected, instead the same named file will be newly created under
2776 +/tmp/rw. And all of your modification to a file will be applied to
2777 +the one under /tmp/rw. This is called the file based Copy on Write
2779 +Aufs mount options are described in aufs.5.
2780 +If you run chroot or something and make your aufs as a root directory,
2781 +then you need to customize the shutdown script. See the aufs manual in
2784 +Additionally, there are some sample usages of aufs which are a
2785 +diskless system with network booting, and LiveCD over NFS.
2786 +See sample dir in CVS tree on SourceForge.
2790 +----------------------------------------
2791 +When you have any problems or strange behaviour in aufs, please let me
2793 +- /proc/mounts (instead of the output of mount(8))
2794 +- /sys/module/aufs/*
2795 +- /sys/fs/aufs/* (if you have them)
2796 +- /debug/aufs/* (if you have them)
2797 +- linux kernel version
2798 + if your kernel is not plain, for example modified by distributor,
2799 + the url where i can download its source is necessary too.
2800 +- aufs version which was printed at loading the module or booting the
2801 + system, instead of the date you downloaded.
2802 +- configuration (define/undefine CONFIG_AUFS_xxx)
2803 +- kernel configuration or /proc/config.gz (if you have it)
2804 +- LSM (linux security module, if you are using)
2805 +- behaviour which you think to be incorrect
2806 +- actual operation, reproducible one is better
2807 +- mailto: aufs-users at lists.sourceforge.net
2809 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2810 +and Feature Requests) on SourceForge. Please join and write to
2814 +6. Acknowledgements
2815 +----------------------------------------
2816 +Thanks to everyone who have tried and are using aufs, whoever
2817 +have reported a bug or any feedback.
2819 +Especially donators:
2820 +Tomas Matejicek(slax.org) made a donation (much more than once).
2821 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2822 + scripts) is making "doubling" donations.
2823 + Unfortunately I cannot list all of the donators, but I really
2825 + It ends Aug 2010, but the ordinary donation URL is still available.
2826 + <http://sourceforge.net/donate/index.php?group_id=167503>
2827 +Dai Itasaka made a donation (2007/8).
2828 +Chuck Smith made a donation (2008/4, 10 and 12).
2829 +Henk Schoneveld made a donation (2008/9).
2830 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2831 +Francois Dupoux made a donation (2008/11).
2832 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2833 + aufs2 GIT tree (2009/2).
2834 +William Grant made a donation (2009/3).
2835 +Patrick Lane made a donation (2009/4).
2836 +The Mail Archive (mail-archive.com) made donations (2009/5).
2837 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2838 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2839 +Pavel Pronskiy made a donation (2011/2).
2840 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2841 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2842 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2844 +Sam Liddicott made a donation (2011/9).
2845 +Era Scarecrow made a donation (2013/4).
2846 +Bor Ratajc made a donation (2013/4).
2847 +Alessandro Gorreta made a donation (2013/4).
2848 +POIRETTE Marc made a donation (2013/4).
2849 +Alessandro Gorreta made a donation (2013/4).
2850 +lauri kasvandik made a donation (2013/5).
2851 +"pemasu from Finland" made a donation (2013/7).
2852 +The Parted Magic Project made a donation (2013/9 and 11).
2853 +Pavel Barta made a donation (2013/10).
2854 +Nikolay Pertsev made a donation (2014/5).
2855 +James B made a donation (2014/7 and 2015/7).
2856 +Stefano Di Biase made a donation (2014/8).
2857 +Daniel Epellei made a donation (2015/1).
2858 +OmegaPhil made a donation (2016/1, 2018/4).
2859 +Tomasz Szewczyk made a donation (2016/4).
2860 +James Burry made a donation (2016/12).
2861 +Carsten Rose made a donation (2018/9).
2862 +Porteus Kiosk made a donation (2018/10).
2864 +Thank you very much.
2865 +Donations are always, including future donations, very important and
2866 +helpful for me to keep on developing aufs.
2870 +----------------------------------------
2871 +If you are an experienced user, no explanation is needed. Aufs is
2872 +just a linux filesystem.
2877 +# Local variables: ;
2880 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2881 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2882 +++ linux/fs/aufs/aufs.h 2020-01-27 10:57:18.165538015 +0100
2884 +/* SPDX-License-Identifier: GPL-2.0 */
2886 + * Copyright (C) 2005-2020 Junjiro R. Okajima
2888 + * This program, aufs is free software; you can redistribute it and/or modify
2889 + * it under the terms of the GNU General Public License as published by
2890 + * the Free Software Foundation; either version 2 of the License, or
2891 + * (at your option) any later version.
2893 + * This program is distributed in the hope that it will be useful,
2894 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2895 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2896 + * GNU General Public License for more details.
2898 + * You should have received a copy of the GNU General Public License
2899 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2903 + * all header files
2911 +#define AuStub(type, name, body, ...) \
2912 + static inline type name(__VA_ARGS__) { body; }
2914 +#define AuStubVoid(name, ...) \
2915 + AuStub(void, name, , __VA_ARGS__)
2916 +#define AuStubInt0(name, ...) \
2917 + AuStub(int, name, return 0, __VA_ARGS__)
2921 +#include "branch.h"
2924 +#include "dbgaufs.h"
2925 +#include "dentry.h"
2927 +#include "dirren.h"
2930 +#include "fstype.h"
2935 +#include "module.h"
2939 +#include "sysaufs.h"
2944 +#endif /* __KERNEL__ */
2945 +#endif /* __AUFS_H__ */
2946 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2947 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2948 +++ linux/fs/aufs/branch.c 2020-08-03 09:14:46.095748745 +0200
2950 +// SPDX-License-Identifier: GPL-2.0
2952 + * Copyright (C) 2005-2020 Junjiro R. Okajima
2954 + * This program, aufs is free software; you can redistribute it and/or modify
2955 + * it under the terms of the GNU General Public License as published by
2956 + * the Free Software Foundation; either version 2 of the License, or
2957 + * (at your option) any later version.
2959 + * This program is distributed in the hope that it will be useful,
2960 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2961 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2962 + * GNU General Public License for more details.
2964 + * You should have received a copy of the GNU General Public License
2965 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2969 + * branch management
2972 +#include <linux/compat.h>
2973 +#include <linux/statfs.h>
2977 + * free a single branch
2979 +static void au_br_do_free(struct au_branch *br)
2982 + struct au_wbr *wbr;
2983 + struct au_dykey **key;
2985 + au_hnotify_fin_br(br);
2986 + /* always, regardless the mount option */
2987 + au_dr_hino_free(&br->br_dirren);
2990 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
2991 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
2992 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
2993 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
2997 + for (i = 0; i < AuBrWh_Last; i++)
2998 + dput(wbr->wbr_wh[i]);
2999 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
3000 + AuRwDestroy(&wbr->wbr_wh_rwsem);
3003 + if (br->br_fhsm) {
3004 + au_br_fhsm_fin(br->br_fhsm);
3005 + au_kfree_try_rcu(br->br_fhsm);
3008 + key = br->br_dykey;
3009 + for (i = 0; i < AuBrDynOp; i++, key++)
3015 + /* recursive lock, s_umount of branch's */
3016 + /* synchronize_rcu(); */ /* why? */
3018 + path_put(&br->br_path);
3020 + au_kfree_rcu(wbr);
3021 + au_lcnt_wait_for_fin(&br->br_nfiles);
3022 + au_lcnt_wait_for_fin(&br->br_count);
3023 + /* I don't know why, but percpu_refcount requires this */
3024 + /* synchronize_rcu(); */
3029 + * frees all branches
3031 +void au_br_free(struct au_sbinfo *sbinfo)
3033 + aufs_bindex_t bmax;
3034 + struct au_branch **br;
3036 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3038 + bmax = sbinfo->si_bbot + 1;
3039 + br = sbinfo->si_branch;
3041 + au_br_do_free(*br++);
3045 + * find the index of a branch which is specified by @br_id.
3047 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3049 + aufs_bindex_t bindex, bbot;
3051 + bbot = au_sbbot(sb);
3052 + for (bindex = 0; bindex <= bbot; bindex++)
3053 + if (au_sbr_id(sb, bindex) == br_id)
3058 +/* ---------------------------------------------------------------------- */
3064 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3065 + struct dentry *h_root)
3067 + if (unlikely(h_adding == h_root
3068 + || au_test_loopback_overlap(sb, h_adding)))
3070 + if (h_adding->d_sb != h_root->d_sb)
3072 + return au_test_subdir(h_adding, h_root)
3073 + || au_test_subdir(h_root, h_adding);
3077 + * returns a newly allocated branch. @new_nbranch is a number of branches
3078 + * after adding a branch.
3080 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3083 + struct au_branch *add_branch;
3084 + struct dentry *root;
3085 + struct inode *inode;
3089 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3090 + if (unlikely(!add_branch))
3092 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3093 + if (unlikely(!add_branch->br_xino))
3095 + err = au_hnotify_init_br(add_branch, perm);
3096 + if (unlikely(err))
3099 + if (au_br_writable(perm)) {
3100 + /* may be freed separately at changing the branch permission */
3101 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3103 + if (unlikely(!add_branch->br_wbr))
3107 + if (au_br_fhsm(perm)) {
3108 + err = au_fhsm_br_alloc(add_branch);
3109 + if (unlikely(err))
3113 + root = sb->s_root;
3114 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3116 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3118 + inode = d_inode(root);
3119 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3123 + return add_branch; /* success */
3126 + au_kfree_rcu(add_branch->br_wbr);
3128 + au_hnotify_fin_br(add_branch);
3130 + au_xino_put(add_branch);
3132 + au_kfree_rcu(add_branch);
3134 + return ERR_PTR(err);
3138 + * test if the branch permission is legal or not.
3140 +static int test_br(struct inode *inode, int brperm, char *path)
3144 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3149 + pr_err("write permission for readonly mount or inode, %s\n", path);
3157 + * 0: success, the caller will add it
3158 + * plus: success, it is already unified, the caller should ignore it
3161 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3164 + aufs_bindex_t bbot, bindex;
3165 + struct dentry *root, *h_dentry;
3166 + struct inode *inode, *h_inode;
3168 + root = sb->s_root;
3169 + bbot = au_sbbot(sb);
3170 + if (unlikely(bbot >= 0
3171 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3175 + pr_err("%s duplicated\n", add->pathname);
3180 + err = -ENOSPC; /* -E2BIG; */
3181 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3182 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3183 + pr_err("number of branches exceeded %s\n", add->pathname);
3188 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3189 + pr_err("bad index %d\n", add->bindex);
3193 + inode = d_inode(add->path.dentry);
3195 + if (unlikely(!inode->i_nlink)) {
3196 + pr_err("no existence %s\n", add->pathname);
3201 + if (unlikely(inode->i_sb == sb)) {
3202 + pr_err("%s must be outside\n", add->pathname);
3206 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3207 + pr_err("unsupported filesystem, %s (%s)\n",
3208 + add->pathname, au_sbtype(inode->i_sb));
3212 + if (unlikely(inode->i_sb->s_stack_depth)) {
3213 + pr_err("already stacked, %s (%s)\n",
3214 + add->pathname, au_sbtype(inode->i_sb));
3218 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3219 + if (unlikely(err))
3223 + return 0; /* success */
3226 + for (bindex = 0; bindex <= bbot; bindex++)
3227 + if (unlikely(test_overlap(sb, add->path.dentry,
3228 + au_h_dptr(root, bindex)))) {
3229 + pr_err("%s is overlapped\n", add->pathname);
3234 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3235 + h_dentry = au_h_dptr(root, 0);
3236 + h_inode = d_inode(h_dentry);
3237 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3238 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3239 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3240 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3242 + i_uid_read(inode), i_gid_read(inode),
3243 + (inode->i_mode & S_IALLUGO),
3244 + i_uid_read(h_inode), i_gid_read(h_inode),
3245 + (h_inode->i_mode & S_IALLUGO));
3253 + * initialize or clean the whiteouts for an adding branch
3255 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3258 + int err, old_perm;
3259 + aufs_bindex_t bindex;
3260 + struct inode *h_inode;
3261 + struct au_wbr *wbr;
3262 + struct au_hinode *hdir;
3263 + struct dentry *h_dentry;
3265 + err = vfsub_mnt_want_write(au_br_mnt(br));
3266 + if (unlikely(err))
3270 + old_perm = br->br_perm;
3271 + br->br_perm = new_perm;
3274 + bindex = au_br_index(sb, br->br_id);
3275 + if (0 <= bindex) {
3276 + hdir = au_hi(d_inode(sb->s_root), bindex);
3277 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3279 + h_dentry = au_br_dentry(br);
3280 + h_inode = d_inode(h_dentry);
3281 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3284 + err = au_wh_init(br, sb);
3286 + wbr_wh_write_lock(wbr);
3287 + err = au_wh_init(br, sb);
3288 + wbr_wh_write_unlock(wbr);
3291 + au_hn_inode_unlock(hdir);
3293 + inode_unlock(h_inode);
3294 + vfsub_mnt_drop_write(au_br_mnt(br));
3295 + br->br_perm = old_perm;
3297 + if (!err && wbr && !au_br_writable(new_perm)) {
3298 + au_kfree_rcu(wbr);
3299 + br->br_wbr = NULL;
3306 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3310 + struct kstatfs kst;
3311 + struct au_wbr *wbr;
3314 + au_rw_init(&wbr->wbr_wh_rwsem);
3315 + atomic_set(&wbr->wbr_wh_running, 0);
3318 + * a limit for rmdir/rename a dir
3319 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3321 + err = vfs_statfs(&br->br_path, &kst);
3322 + if (unlikely(err))
3325 + if (kst.f_namelen >= NAME_MAX)
3326 + err = au_br_init_wh(sb, br, perm);
3328 + pr_err("%pd(%s), unsupported namelen %ld\n",
3330 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3336 +/* initialize a new branch */
3337 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3338 + struct au_opt_add *add)
3341 + struct au_branch *brbase;
3343 + struct inode *h_inode;
3346 + br->br_perm = add->perm;
3347 + br->br_path = add->path; /* set first, path_get() later */
3348 + spin_lock_init(&br->br_dykey_lock);
3349 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3350 + au_lcnt_init(&br->br_count, /*release*/NULL);
3351 + br->br_id = au_new_br_id(sb);
3352 + AuDebugOn(br->br_id < 0);
3354 + /* always, regardless the given option */
3355 + err = au_dr_br_init(sb, br, &add->path);
3356 + if (unlikely(err))
3359 + if (au_br_writable(add->perm)) {
3360 + err = au_wbr_init(br, sb, add->perm);
3361 + if (unlikely(err))
3365 + if (au_opt_test(au_mntflags(sb), XINO)) {
3366 + brbase = au_sbr(sb, 0);
3367 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3369 + h_inode = d_inode(add->path.dentry);
3370 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3371 + if (unlikely(err)) {
3372 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3377 + sysaufs_br_init(br);
3378 + path_get(&br->br_path);
3379 + goto out; /* success */
3382 + memset(&br->br_path, 0, sizeof(br->br_path));
3387 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3388 + struct au_branch *br, aufs_bindex_t bbot,
3389 + aufs_bindex_t amount)
3391 + struct au_branch **brp;
3393 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3395 + brp = sbinfo->si_branch + bindex;
3396 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3398 + sbinfo->si_bbot++;
3399 + if (unlikely(bbot < 0))
3400 + sbinfo->si_bbot = 0;
3403 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3404 + aufs_bindex_t bbot, aufs_bindex_t amount)
3406 + struct au_hdentry *hdp;
3408 + AuRwMustWriteLock(&dinfo->di_rwsem);
3410 + hdp = au_hdentry(dinfo, bindex);
3411 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3412 + au_h_dentry_init(hdp);
3414 + if (unlikely(bbot < 0))
3415 + dinfo->di_btop = 0;
3418 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3419 + aufs_bindex_t bbot, aufs_bindex_t amount)
3421 + struct au_hinode *hip;
3423 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3425 + hip = au_hinode(iinfo, bindex);
3426 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3427 + au_hinode_init(hip);
3429 + if (unlikely(bbot < 0))
3430 + iinfo->ii_btop = 0;
3433 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3434 + aufs_bindex_t bindex)
3436 + struct dentry *root, *h_dentry;
3437 + struct inode *root_inode, *h_inode;
3438 + aufs_bindex_t bbot, amount;
3440 + root = sb->s_root;
3441 + root_inode = d_inode(root);
3442 + bbot = au_sbbot(sb);
3443 + amount = bbot + 1 - bindex;
3444 + h_dentry = au_br_dentry(br);
3445 + au_sbilist_lock();
3446 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3447 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3448 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3449 + au_set_h_dptr(root, bindex, dget(h_dentry));
3450 + h_inode = d_inode(h_dentry);
3451 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3452 + au_sbilist_unlock();
3455 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3458 + aufs_bindex_t bbot, add_bindex;
3459 + struct dentry *root, *h_dentry;
3460 + struct inode *root_inode;
3461 + struct au_branch *add_branch;
3463 + root = sb->s_root;
3464 + root_inode = d_inode(root);
3465 + IMustLock(root_inode);
3466 + IiMustWriteLock(root_inode);
3467 + err = test_add(sb, add, remount);
3468 + if (unlikely(err < 0))
3472 + goto out; /* success */
3475 + bbot = au_sbbot(sb);
3476 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3477 + err = PTR_ERR(add_branch);
3478 + if (IS_ERR(add_branch))
3481 + err = au_br_init(add_branch, sb, add);
3482 + if (unlikely(err)) {
3483 + au_br_do_free(add_branch);
3487 + add_bindex = add->bindex;
3488 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3489 + au_br_do_add(sb, add_branch, add_bindex);
3490 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3491 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3493 + h_dentry = add->path.dentry;
3494 + if (!add_bindex) {
3495 + au_cpup_attr_all(root_inode, /*force*/1);
3496 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3498 + au_add_nlink(root_inode, d_inode(h_dentry));
3504 +/* ---------------------------------------------------------------------- */
3506 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3507 + unsigned long long max __maybe_unused,
3510 + unsigned long long n;
3511 + struct file **p, *f;
3512 + struct hlist_bl_head *files;
3513 + struct hlist_bl_node *pos;
3514 + struct au_finfo *finfo;
3518 + files = &au_sbi(sb)->si_files;
3519 + hlist_bl_lock(files);
3520 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3521 + f = finfo->fi_file;
3523 + && !special_file(file_inode(f)->i_mode)) {
3527 + AuDebugOn(n > max);
3530 + hlist_bl_unlock(files);
3535 +static struct file **au_farray_alloc(struct super_block *sb,
3536 + unsigned long long *max)
3538 + struct au_sbinfo *sbi;
3541 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3542 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3545 +static void au_farray_free(struct file **a, unsigned long long max)
3547 + unsigned long long ull;
3549 + for (ull = 0; ull < max; ull++)
3555 +/* ---------------------------------------------------------------------- */
3561 +/* to show the line number, do not make it inlined function */
3562 +#define AuVerbose(do_info, fmt, ...) do { \
3564 + pr_info(fmt, ##__VA_ARGS__); \
3567 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3568 + aufs_bindex_t bbot)
3570 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3573 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3574 + aufs_bindex_t bbot)
3576 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3580 + * test if the branch is deletable or not.
3582 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3583 + unsigned int sigen, const unsigned int verbose)
3585 + int err, i, j, ndentry;
3586 + aufs_bindex_t btop, bbot;
3587 + struct au_dcsub_pages dpages;
3588 + struct au_dpage *dpage;
3591 + err = au_dpages_init(&dpages, GFP_NOFS);
3592 + if (unlikely(err))
3594 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3595 + if (unlikely(err))
3598 + for (i = 0; !err && i < dpages.ndpage; i++) {
3599 + dpage = dpages.dpages + i;
3600 + ndentry = dpage->ndentry;
3601 + for (j = 0; !err && j < ndentry; j++) {
3602 + d = dpage->dentries[j];
3603 + AuDebugOn(au_dcount(d) <= 0);
3604 + if (!au_digen_test(d, sigen)) {
3605 + di_read_lock_child(d, AuLock_IR);
3606 + if (unlikely(au_dbrange_test(d))) {
3607 + di_read_unlock(d, AuLock_IR);
3611 + di_write_lock_child(d);
3612 + if (unlikely(au_dbrange_test(d))) {
3613 + di_write_unlock(d);
3616 + err = au_reval_dpath(d, sigen);
3618 + di_downgrade_lock(d, AuLock_IR);
3620 + di_write_unlock(d);
3625 + /* AuDbgDentry(d); */
3626 + btop = au_dbtop(d);
3627 + bbot = au_dbbot(d);
3628 + if (btop <= bindex
3630 + && au_h_dptr(d, bindex)
3631 + && au_test_dbusy(d, btop, bbot)) {
3633 + AuVerbose(verbose, "busy %pd\n", d);
3636 + di_read_unlock(d, AuLock_IR);
3641 + au_dpages_free(&dpages);
3646 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3647 + unsigned int sigen, const unsigned int verbose)
3650 + unsigned long long max, ull;
3651 + struct inode *i, **array;
3652 + aufs_bindex_t btop, bbot;
3654 + array = au_iarray_alloc(sb, &max);
3655 + err = PTR_ERR(array);
3656 + if (IS_ERR(array))
3660 + AuDbg("b%d\n", bindex);
3661 + for (ull = 0; !err && ull < max; ull++) {
3665 + if (i->i_ino == AUFS_ROOT_INO)
3668 + /* AuDbgInode(i); */
3669 + if (au_iigen(i, NULL) == sigen)
3670 + ii_read_lock_child(i);
3672 + ii_write_lock_child(i);
3673 + err = au_refresh_hinode_self(i);
3676 + ii_downgrade_lock(i);
3678 + ii_write_unlock(i);
3683 + btop = au_ibtop(i);
3684 + bbot = au_ibbot(i);
3685 + if (btop <= bindex
3687 + && au_h_iptr(i, bindex)
3688 + && au_test_ibusy(i, btop, bbot)) {
3690 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3693 + ii_read_unlock(i);
3695 + au_iarray_free(array, max);
3701 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3702 + const unsigned int verbose)
3705 + unsigned int sigen;
3707 + sigen = au_sigen(root->d_sb);
3708 + DiMustNoWaiters(root);
3709 + IiMustNoWaiters(d_inode(root));
3710 + di_write_unlock(root);
3711 + err = test_dentry_busy(root, bindex, sigen, verbose);
3713 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3714 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3719 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3720 + struct file **to_free, int *idx)
3723 + unsigned char matched, root;
3724 + aufs_bindex_t bindex, bbot;
3725 + struct au_fidir *fidir;
3726 + struct au_hfile *hfile;
3729 + root = IS_ROOT(file->f_path.dentry);
3732 + to_free[*idx] = file;
3738 + fidir = au_fi(file)->fi_hdir;
3739 + AuDebugOn(!fidir);
3740 + bbot = au_fbbot_dir(file);
3741 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3742 + hfile = fidir->fd_hfile + bindex;
3743 + if (!hfile->hf_file)
3746 + if (hfile->hf_br->br_id == br_id) {
3758 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3759 + struct file **to_free, int opened)
3762 + unsigned long long ull, max;
3763 + aufs_bindex_t btop;
3764 + struct file *file, **array;
3765 + struct dentry *root;
3766 + struct au_hfile *hfile;
3768 + array = au_farray_alloc(sb, &max);
3769 + err = PTR_ERR(array);
3770 + if (IS_ERR(array))
3775 + root = sb->s_root;
3776 + di_write_unlock(root);
3777 + for (ull = 0; ull < max; ull++) {
3778 + file = array[ull];
3779 + if (unlikely(!file))
3782 + /* AuDbg("%pD\n", file); */
3783 + fi_read_lock(file);
3784 + btop = au_fbtop(file);
3785 + if (!d_is_dir(file->f_path.dentry)) {
3786 + hfile = &au_fi(file)->fi_htop;
3787 + if (hfile->hf_br->br_id == br_id)
3790 + err = test_dir_busy(file, br_id, to_free, &idx);
3791 + fi_read_unlock(file);
3792 + if (unlikely(err))
3795 + di_write_lock_child(root);
3796 + au_farray_free(array, max);
3797 + AuDebugOn(idx > opened);
3803 +static void br_del_file(struct file **to_free, unsigned long long opened,
3804 + aufs_bindex_t br_id)
3806 + unsigned long long ull;
3807 + aufs_bindex_t bindex, btop, bbot, bfound;
3808 + struct file *file;
3809 + struct au_fidir *fidir;
3810 + struct au_hfile *hfile;
3812 + for (ull = 0; ull < opened; ull++) {
3813 + file = to_free[ull];
3814 + if (unlikely(!file))
3817 + /* AuDbg("%pD\n", file); */
3818 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3820 + fidir = au_fi(file)->fi_hdir;
3821 + AuDebugOn(!fidir);
3822 + fi_write_lock(file);
3823 + btop = au_fbtop(file);
3824 + bbot = au_fbbot_dir(file);
3825 + for (bindex = btop; bindex <= bbot; bindex++) {
3826 + hfile = fidir->fd_hfile + bindex;
3827 + if (!hfile->hf_file)
3830 + if (hfile->hf_br->br_id == br_id) {
3835 + AuDebugOn(bfound < 0);
3836 + au_set_h_fptr(file, bfound, NULL);
3837 + if (bfound == btop) {
3838 + for (btop++; btop <= bbot; btop++)
3839 + if (au_hf_dir(file, btop)) {
3840 + au_set_fbtop(file, btop);
3844 + fi_write_unlock(file);
3848 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3849 + const aufs_bindex_t bindex,
3850 + const aufs_bindex_t bbot)
3852 + struct au_branch **brp, **p;
3854 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3856 + brp = sbinfo->si_branch + bindex;
3857 + if (bindex < bbot)
3858 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3859 + sbinfo->si_branch[0 + bbot] = NULL;
3860 + sbinfo->si_bbot--;
3862 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3865 + sbinfo->si_branch = p;
3866 + /* harmless error */
3869 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3870 + const aufs_bindex_t bbot)
3872 + struct au_hdentry *hdp, *p;
3874 + AuRwMustWriteLock(&dinfo->di_rwsem);
3876 + hdp = au_hdentry(dinfo, bindex);
3877 + if (bindex < bbot)
3878 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3879 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3882 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3885 + dinfo->di_hdentry = p;
3886 + /* harmless error */
3889 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3890 + const aufs_bindex_t bbot)
3892 + struct au_hinode *hip, *p;
3894 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3896 + hip = au_hinode(iinfo, bindex);
3897 + if (bindex < bbot)
3898 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3899 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3902 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3905 + iinfo->ii_hinode = p;
3906 + /* harmless error */
3909 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3910 + struct au_branch *br)
3912 + aufs_bindex_t bbot;
3913 + struct au_sbinfo *sbinfo;
3914 + struct dentry *root, *h_root;
3915 + struct inode *inode, *h_inode;
3916 + struct au_hinode *hinode;
3918 + SiMustWriteLock(sb);
3920 + root = sb->s_root;
3921 + inode = d_inode(root);
3922 + sbinfo = au_sbi(sb);
3923 + bbot = sbinfo->si_bbot;
3925 + h_root = au_h_dptr(root, bindex);
3926 + hinode = au_hi(inode, bindex);
3927 + h_inode = au_igrab(hinode->hi_inode);
3930 + au_sbilist_lock();
3931 + au_br_do_del_brp(sbinfo, bindex, bbot);
3932 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3933 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3934 + au_sbilist_unlock();
3936 + /* ignore an error */
3937 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
3941 + au_br_do_free(br);
3944 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3945 + unsigned long long max, void *arg)
3950 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3953 + unsigned long long opened;
3954 + unsigned int mnt_flags;
3955 + aufs_bindex_t bindex, bbot, br_id;
3956 + unsigned char do_wh, verbose;
3957 + struct au_branch *br;
3958 + struct au_wbr *wbr;
3959 + struct dentry *root;
3960 + struct file **to_free;
3965 + root = sb->s_root;
3966 + bindex = au_find_dbindex(root, del->h_path.dentry);
3969 + goto out; /* success */
3971 + pr_err("%s no such branch\n", del->pathname);
3974 + AuDbg("bindex b%d\n", bindex);
3977 + mnt_flags = au_mntflags(sb);
3978 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3979 + bbot = au_sbbot(sb);
3980 + if (unlikely(!bbot)) {
3981 + AuVerbose(verbose, "no more branches left\n");
3985 + br = au_sbr(sb, bindex);
3986 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3987 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
3988 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
3992 + br_id = br->br_id;
3993 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
3994 + if (unlikely(opened)) {
3995 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3996 + err = PTR_ERR(to_free);
3997 + if (IS_ERR(to_free))
4000 + err = test_file_busy(sb, br_id, to_free, opened);
4001 + if (unlikely(err)) {
4002 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
4008 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4010 + /* instead of WbrWhMustWriteLock(wbr) */
4011 + SiMustWriteLock(sb);
4012 + for (i = 0; i < AuBrWh_Last; i++) {
4013 + dput(wbr->wbr_wh[i]);
4014 + wbr->wbr_wh[i] = NULL;
4018 + err = test_children_busy(root, bindex, verbose);
4019 + if (unlikely(err)) {
4028 + * now we confirmed the branch is deletable.
4029 + * let's free the remaining opened dirs on the branch.
4031 + di_write_unlock(root);
4032 + br_del_file(to_free, opened, br_id);
4033 + di_write_lock_child(root);
4036 + sysaufs_brs_del(sb, bindex); /* remove successors */
4037 + dbgaufs_xino_del(br); /* remove one */
4038 + au_br_do_del(sb, bindex, br);
4039 + sysaufs_brs_add(sb, bindex); /* append successors */
4040 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4043 + au_cpup_attr_all(d_inode(root), /*force*/1);
4044 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4046 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4047 + if (au_opt_test(mnt_flags, PLINK))
4048 + au_plink_half_refresh(sb, br_id);
4050 + goto out; /* success */
4054 + rerr = au_br_init_wh(sb, br, br->br_perm);
4056 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4057 + del->pathname, rerr);
4060 + au_farray_free(to_free, opened);
4064 +/* ---------------------------------------------------------------------- */
4066 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4069 + aufs_bindex_t btop, bbot;
4070 + struct aufs_ibusy ibusy;
4071 + struct inode *inode, *h_inode;
4074 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4077 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4079 + /* VERIFY_WRITE */
4080 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4081 + if (unlikely(err)) {
4088 + si_read_lock(sb, AuLock_FLUSH);
4089 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4093 + ibusy.h_ino = 0; /* invalid */
4094 + inode = ilookup(sb, ibusy.ino);
4096 + || inode->i_ino == AUFS_ROOT_INO
4097 + || au_is_bad_inode(inode))
4100 + ii_read_lock_child(inode);
4101 + btop = au_ibtop(inode);
4102 + bbot = au_ibbot(inode);
4103 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4104 + h_inode = au_h_iptr(inode, ibusy.bindex);
4105 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4106 + ibusy.h_ino = h_inode->i_ino;
4108 + ii_read_unlock(inode);
4112 + si_read_unlock(sb);
4114 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4115 + if (unlikely(err)) {
4124 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4126 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4129 +#ifdef CONFIG_COMPAT
4130 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4132 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4136 +/* ---------------------------------------------------------------------- */
4139 + * change a branch permission
4142 +static void au_warn_ima(void)
4145 + /* since it doesn't support mark_files_ro() */
4146 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4150 +static int do_need_sigen_inc(int a, int b)
4152 + return au_br_whable(a) && !au_br_whable(b);
4155 +static int need_sigen_inc(int old, int new)
4157 + return do_need_sigen_inc(old, new)
4158 + || do_need_sigen_inc(new, old);
4161 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4164 + unsigned int mnt_flags;
4165 + unsigned long long ull, max;
4166 + aufs_bindex_t br_id;
4167 + unsigned char verbose, writer;
4168 + struct file *file, *hf, **array;
4169 + struct au_hfile *hfile;
4170 + struct inode *h_inode;
4172 + mnt_flags = au_mntflags(sb);
4173 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4175 + array = au_farray_alloc(sb, &max);
4176 + err = PTR_ERR(array);
4177 + if (IS_ERR(array))
4181 + br_id = au_sbr_id(sb, bindex);
4182 + for (ull = 0; ull < max; ull++) {
4183 + file = array[ull];
4184 + if (unlikely(!file))
4187 + /* AuDbg("%pD\n", file); */
4188 + fi_read_lock(file);
4189 + if (unlikely(au_test_mmapped(file))) {
4191 + AuVerbose(verbose, "mmapped %pD\n", file);
4193 + FiMustNoWaiters(file);
4194 + fi_read_unlock(file);
4198 + hfile = &au_fi(file)->fi_htop;
4199 + hf = hfile->hf_file;
4200 + if (!d_is_reg(file->f_path.dentry)
4201 + || !(file->f_mode & FMODE_WRITE)
4202 + || hfile->hf_br->br_id != br_id
4203 + || !(hf->f_mode & FMODE_WRITE))
4204 + array[ull] = NULL;
4210 + FiMustNoWaiters(file);
4211 + fi_read_unlock(file);
4219 + for (ull = 0; ull < max; ull++) {
4220 + file = array[ull];
4224 + /* todo: already flushed? */
4226 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4227 + * approach which resets f_mode and calls mnt_drop_write() and
4228 + * file_release_write() for each file, because the branch
4229 + * attribute in aufs world is totally different from the native
4232 + /* fi_read_lock(file); */
4233 + hfile = &au_fi(file)->fi_htop;
4234 + hf = hfile->hf_file;
4235 + /* fi_read_unlock(file); */
4236 + spin_lock(&hf->f_lock);
4237 + writer = !!(hf->f_mode & FMODE_WRITER);
4238 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4239 + spin_unlock(&hf->f_lock);
4241 + h_inode = file_inode(hf);
4242 + if (hf->f_mode & FMODE_READ)
4243 + i_readcount_inc(h_inode);
4244 + put_write_access(h_inode);
4245 + __mnt_drop_write(hf->f_path.mnt);
4250 + au_farray_free(array, max);
4256 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4260 + aufs_bindex_t bindex;
4261 + struct dentry *root;
4262 + struct au_branch *br;
4263 + struct au_br_fhsm *bf;
4265 + root = sb->s_root;
4266 + bindex = au_find_dbindex(root, mod->h_root);
4269 + return 0; /* success */
4271 + pr_err("%s no such branch\n", mod->path);
4274 + AuDbg("bindex b%d\n", bindex);
4276 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4277 + if (unlikely(err))
4280 + br = au_sbr(sb, bindex);
4281 + AuDebugOn(mod->h_root != au_br_dentry(br));
4282 + if (br->br_perm == mod->perm)
4283 + return 0; /* success */
4285 + /* pre-allocate for non-fhsm --> fhsm */
4287 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4288 + err = au_fhsm_br_alloc(br);
4289 + if (unlikely(err))
4292 + br->br_fhsm = NULL;
4295 + if (au_br_writable(br->br_perm)) {
4296 + /* remove whiteout base */
4297 + err = au_br_init_wh(sb, br, mod->perm);
4298 + if (unlikely(err))
4301 + if (!au_br_writable(mod->perm)) {
4302 + /* rw --> ro, file might be mmapped */
4303 + DiMustNoWaiters(root);
4304 + IiMustNoWaiters(d_inode(root));
4305 + di_write_unlock(root);
4306 + err = au_br_mod_files_ro(sb, bindex);
4307 + /* aufs_write_lock() calls ..._child() */
4308 + di_write_lock_child(root);
4310 + if (unlikely(err)) {
4312 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4315 + rerr = au_wbr_init(br, sb, br->br_perm);
4316 + if (unlikely(rerr)) {
4317 + AuIOErr("nested error %d (%d)\n",
4319 + br->br_perm = mod->perm;
4323 + } else if (au_br_writable(mod->perm)) {
4326 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4328 + err = au_wbr_init(br, sb, mod->perm);
4329 + if (unlikely(err)) {
4330 + au_kfree_rcu(br->br_wbr);
4331 + br->br_wbr = NULL;
4335 + if (unlikely(err))
4338 + if (au_br_fhsm(br->br_perm)) {
4339 + if (!au_br_fhsm(mod->perm)) {
4340 + /* fhsm --> non-fhsm */
4341 + au_br_fhsm_fin(br->br_fhsm);
4342 + au_kfree_rcu(br->br_fhsm);
4343 + br->br_fhsm = NULL;
4345 + } else if (au_br_fhsm(mod->perm))
4346 + /* non-fhsm --> fhsm */
4349 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4350 + br->br_perm = mod->perm;
4351 + goto out; /* success */
4354 + au_kfree_try_rcu(bf);
4360 +/* ---------------------------------------------------------------------- */
4362 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4365 + struct kstatfs kstfs;
4367 + err = vfs_statfs(&br->br_path, &kstfs);
4369 + stfs->f_blocks = kstfs.f_blocks;
4370 + stfs->f_bavail = kstfs.f_bavail;
4371 + stfs->f_files = kstfs.f_files;
4372 + stfs->f_ffree = kstfs.f_ffree;
4377 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4378 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4379 +++ linux/fs/aufs/branch.h 2020-12-15 14:10:58.911356294 +0100
4381 +/* SPDX-License-Identifier: GPL-2.0 */
4383 + * Copyright (C) 2005-2020 Junjiro R. Okajima
4385 + * This program, aufs is free software; you can redistribute it and/or modify
4386 + * it under the terms of the GNU General Public License as published by
4387 + * the Free Software Foundation; either version 2 of the License, or
4388 + * (at your option) any later version.
4390 + * This program is distributed in the hope that it will be useful,
4391 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4392 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4393 + * GNU General Public License for more details.
4395 + * You should have received a copy of the GNU General Public License
4396 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4400 + * branch filesystems and xino for them
4403 +#ifndef __AUFS_BRANCH_H__
4404 +#define __AUFS_BRANCH_H__
4408 +#include <linux/mount.h>
4409 +#include "dirren.h"
4415 +/* ---------------------------------------------------------------------- */
4419 + struct file **xi_file;
4420 + unsigned int xi_nfile;
4426 + /* reserved for future use */
4427 + /* unsigned long *bitmap; */
4428 + wait_queue_head_t wqh;
4431 + struct mutex xi_mtx; /* protects xi_file array */
4432 + struct hlist_bl_head xi_writing;
4434 + atomic_t xi_truncating;
4436 + struct kref xi_kref;
4439 +/* File-based Hierarchical Storage Management */
4440 +struct au_br_fhsm {
4441 +#ifdef CONFIG_AUFS_FHSM
4442 + struct mutex bf_lock;
4443 + unsigned long bf_jiffy;
4444 + struct aufs_stfs bf_stfs;
4449 +/* members for writable branch only */
4450 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4452 + struct au_rwsem wbr_wh_rwsem;
4453 + struct dentry *wbr_wh[AuBrWh_Last];
4454 + atomic_t wbr_wh_running;
4455 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4456 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4457 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4460 + unsigned long long wbr_bytes;
4463 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4464 +#define AuBrDynOp (AuDyLast * 4)
4466 +#ifdef CONFIG_AUFS_HFSNOTIFY
4467 +/* support for asynchronous destruction */
4468 +struct au_br_hfsnotify {
4469 + struct fsnotify_group *hfsn_group;
4473 +/* sysfs entries */
4474 +struct au_brsysfs {
4476 + struct attribute attr;
4485 +/* protected by superblock rwsem */
4487 + struct au_xino *br_xino;
4489 + aufs_bindex_t br_id;
4492 + struct path br_path;
4493 + spinlock_t br_dykey_lock;
4494 + struct au_dykey *br_dykey[AuBrDynOp];
4495 + au_lcnt_t br_nfiles; /* opened files */
4496 + au_lcnt_t br_count; /* in-use for other */
4498 + struct au_wbr *br_wbr;
4499 + struct au_br_fhsm *br_fhsm;
4501 +#ifdef CONFIG_AUFS_HFSNOTIFY
4502 + struct au_br_hfsnotify *br_hfsn;
4505 +#ifdef CONFIG_SYSFS
4506 + /* entries under sysfs per mount-point */
4507 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4510 +#ifdef CONFIG_DEBUG_FS
4511 + struct dentry *br_dbgaufs; /* xino */
4514 + struct au_dr_br br_dirren;
4517 +/* ---------------------------------------------------------------------- */
4519 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4521 + return br->br_path.mnt;
4524 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4526 + return br->br_path.dentry;
4529 +static inline struct super_block *au_br_sb(struct au_branch *br)
4531 + return au_br_mnt(br)->mnt_sb;
4534 +static inline int au_br_rdonly(struct au_branch *br)
4536 + return (sb_rdonly(au_br_sb(br))
4537 + || !au_br_writable(br->br_perm))
4541 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4543 +#ifdef CONFIG_AUFS_HNOTIFY
4544 + return !(brperm & AuBrPerm_RR);
4550 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4552 + int err, exec_flag;
4555 + exec_flag = oflag & __FMODE_EXEC;
4556 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4562 +static inline void au_xino_get(struct au_branch *br)
4564 + struct au_xino *xi;
4568 + kref_get(&xi->xi_kref);
4571 +static inline int au_xino_count(struct au_branch *br)
4574 + struct au_xino *xi;
4579 + v = kref_read(&xi->xi_kref);
4584 +/* ---------------------------------------------------------------------- */
4588 +void au_br_free(struct au_sbinfo *sinfo);
4589 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4591 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4593 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4594 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4595 +#ifdef CONFIG_COMPAT
4596 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4599 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4602 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4605 +static const loff_t au_loff_max = LLONG_MAX;
4607 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4608 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4610 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4611 + struct file *copy_src);
4613 + struct au_xino *xi; /* switch between xino and xigen */
4615 + struct path *base;
4616 + struct file *copy_src;
4618 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4620 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4622 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4624 +ssize_t xino_fread(struct file *file, void *buf, size_t size, loff_t *pos);
4625 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos);
4627 +int au_xib_trunc(struct super_block *sb);
4628 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4630 +struct au_xino *au_xino_alloc(unsigned int nfile);
4631 +int au_xino_put(struct au_branch *br);
4632 +struct file *au_xino_file1(struct au_xino *xi);
4634 +struct au_opt_xino;
4635 +void au_xino_clr(struct super_block *sb);
4636 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4637 +struct file *au_xino_def(struct super_block *sb);
4638 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4639 + struct path *base);
4641 +ino_t au_xino_new_ino(struct super_block *sb);
4642 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4644 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4645 + ino_t h_ino, int idx);
4646 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4649 +int au_xino_path(struct seq_file *seq, struct file *file);
4651 +/* ---------------------------------------------------------------------- */
4653 +/* @idx is signed to accept -1 meaning the first file */
4654 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4656 + struct file *file;
4663 + if (idx < xi->xi_nfile)
4664 + file = xi->xi_file[idx];
4666 + file = au_xino_file1(xi);
4672 +/* ---------------------------------------------------------------------- */
4674 +/* Superblock to branch */
4676 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4678 + return au_sbr(sb, bindex)->br_id;
4682 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4684 + return au_br_mnt(au_sbr(sb, bindex));
4688 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4690 + return au_br_sb(au_sbr(sb, bindex));
4693 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4695 + return au_sbr(sb, bindex)->br_perm;
4698 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4700 + return au_br_whable(au_sbr_perm(sb, bindex));
4703 +/* ---------------------------------------------------------------------- */
4705 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4706 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4707 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4708 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4710 +#define wbr_wh_read_trylock_nested(wbr) \
4711 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4712 +#define wbr_wh_write_trylock_nested(wbr) \
4713 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4716 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4717 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4718 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4720 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4721 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4722 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4724 +/* ---------------------------------------------------------------------- */
4726 +#ifdef CONFIG_AUFS_FHSM
4727 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4729 + mutex_init(&brfhsm->bf_lock);
4730 + brfhsm->bf_jiffy = 0;
4731 + brfhsm->bf_readable = 0;
4734 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4736 + mutex_destroy(&brfhsm->bf_lock);
4739 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4740 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4743 +#endif /* __KERNEL__ */
4744 +#endif /* __AUFS_BRANCH_H__ */
4745 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4746 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4747 +++ linux/fs/aufs/conf.mk 2019-07-11 15:42:14.462237786 +0200
4749 +# SPDX-License-Identifier: GPL-2.0
4751 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4755 +AuConfStr += ${1}=${${1}}
4759 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4761 + HNOTIFY HFSNOTIFY \
4773 +$(foreach i, ${AuConfAll}, \
4774 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4776 +AuConfName = ${obj}/conf.str
4777 +${AuConfName}.tmp: FORCE
4778 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4779 +${AuConfName}: ${AuConfName}.tmp
4780 + @diff -q $< $@ > /dev/null 2>&1 || { \
4781 + echo ' GEN ' $@; \
4785 +clean-files += ${AuConfName} ${AuConfName}.tmp
4786 +${obj}/sysfs.o: ${AuConfName}
4788 +-include ${srctree}/${src}/conf_priv.mk
4789 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4790 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4791 +++ linux/fs/aufs/cpup.c 2020-12-15 14:10:58.911356294 +0100
4793 +// SPDX-License-Identifier: GPL-2.0
4795 + * Copyright (C) 2005-2020 Junjiro R. Okajima
4797 + * This program, aufs is free software; you can redistribute it and/or modify
4798 + * it under the terms of the GNU General Public License as published by
4799 + * the Free Software Foundation; either version 2 of the License, or
4800 + * (at your option) any later version.
4802 + * This program is distributed in the hope that it will be useful,
4803 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4804 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4805 + * GNU General Public License for more details.
4807 + * You should have received a copy of the GNU General Public License
4808 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4812 + * copy-up functions, see wbr_policy.c for copy-down
4815 +#include <linux/fs_stack.h>
4816 +#include <linux/mm.h>
4817 +#include <linux/task_work.h>
4820 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4822 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4823 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4825 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4827 + dst->i_flags |= iflags & ~mask;
4828 + if (au_test_fs_notime(dst->i_sb))
4829 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4832 +void au_cpup_attr_timesizes(struct inode *inode)
4834 + struct inode *h_inode;
4836 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4837 + fsstack_copy_attr_times(inode, h_inode);
4838 + fsstack_copy_inode_size(inode, h_inode);
4841 +void au_cpup_attr_nlink(struct inode *inode, int force)
4843 + struct inode *h_inode;
4844 + struct super_block *sb;
4845 + aufs_bindex_t bindex, bbot;
4848 + bindex = au_ibtop(inode);
4849 + h_inode = au_h_iptr(inode, bindex);
4851 + && !S_ISDIR(h_inode->i_mode)
4852 + && au_opt_test(au_mntflags(sb), PLINK)
4853 + && au_plink_test(inode))
4857 + * 0 can happen in revalidating.
4858 + * h_inode->i_mutex may not be held here, but it is harmless since once
4859 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4861 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4862 + * the incorrect link count.
4864 + set_nlink(inode, h_inode->i_nlink);
4867 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4868 + * it may includes whplink directory.
4870 + if (S_ISDIR(h_inode->i_mode)) {
4871 + bbot = au_ibbot(inode);
4872 + for (bindex++; bindex <= bbot; bindex++) {
4873 + h_inode = au_h_iptr(inode, bindex);
4875 + au_add_nlink(inode, h_inode);
4880 +void au_cpup_attr_changeable(struct inode *inode)
4882 + struct inode *h_inode;
4884 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4885 + inode->i_mode = h_inode->i_mode;
4886 + inode->i_uid = h_inode->i_uid;
4887 + inode->i_gid = h_inode->i_gid;
4888 + au_cpup_attr_timesizes(inode);
4889 + au_cpup_attr_flags(inode, h_inode->i_flags);
4892 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4894 + struct au_iinfo *iinfo = au_ii(inode);
4896 + IiMustWriteLock(inode);
4898 + iinfo->ii_higen = h_inode->i_generation;
4899 + iinfo->ii_hsb1 = h_inode->i_sb;
4902 +void au_cpup_attr_all(struct inode *inode, int force)
4904 + struct inode *h_inode;
4906 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4907 + au_cpup_attr_changeable(inode);
4908 + if (inode->i_nlink > 0)
4909 + au_cpup_attr_nlink(inode, force);
4910 + inode->i_rdev = h_inode->i_rdev;
4911 + inode->i_blkbits = h_inode->i_blkbits;
4912 + au_cpup_igen(inode, h_inode);
4915 +/* ---------------------------------------------------------------------- */
4917 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4919 +/* keep the timestamps of the parent dir when cpup */
4920 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4921 + struct path *h_path)
4923 + struct inode *h_inode;
4925 + dt->dt_dentry = dentry;
4926 + dt->dt_h_path = *h_path;
4927 + h_inode = d_inode(h_path->dentry);
4928 + dt->dt_atime = h_inode->i_atime;
4929 + dt->dt_mtime = h_inode->i_mtime;
4933 +void au_dtime_revert(struct au_dtime *dt)
4935 + struct iattr attr;
4938 + attr.ia_atime = dt->dt_atime;
4939 + attr.ia_mtime = dt->dt_mtime;
4940 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4941 + | ATTR_ATIME | ATTR_ATIME_SET;
4943 + /* no delegation since this is a directory */
4944 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4945 + if (unlikely(err))
4946 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4949 +/* ---------------------------------------------------------------------- */
4951 +/* internal use only */
4952 +struct au_cpup_reg_attr {
4955 + unsigned int iflags; /* inode->i_flags */
4958 +static noinline_for_stack
4959 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4960 + struct au_cpup_reg_attr *h_src_attr)
4962 + int err, sbits, icex;
4963 + unsigned int mnt_flags;
4964 + unsigned char verbose;
4966 + struct path h_path;
4967 + struct inode *h_isrc, *h_idst;
4968 + struct kstat *h_st;
4969 + struct au_branch *br;
4971 + h_path.dentry = au_h_dptr(dst, bindex);
4972 + h_idst = d_inode(h_path.dentry);
4973 + br = au_sbr(dst->d_sb, bindex);
4974 + h_path.mnt = au_br_mnt(br);
4975 + h_isrc = d_inode(h_src);
4976 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4977 + | ATTR_ATIME | ATTR_MTIME
4978 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4979 + if (h_src_attr && h_src_attr->valid) {
4980 + h_st = &h_src_attr->st;
4981 + ia.ia_uid = h_st->uid;
4982 + ia.ia_gid = h_st->gid;
4983 + ia.ia_atime = h_st->atime;
4984 + ia.ia_mtime = h_st->mtime;
4985 + if (h_idst->i_mode != h_st->mode
4986 + && !S_ISLNK(h_idst->i_mode)) {
4987 + ia.ia_valid |= ATTR_MODE;
4988 + ia.ia_mode = h_st->mode;
4990 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4991 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4993 + ia.ia_uid = h_isrc->i_uid;
4994 + ia.ia_gid = h_isrc->i_gid;
4995 + ia.ia_atime = h_isrc->i_atime;
4996 + ia.ia_mtime = h_isrc->i_mtime;
4997 + if (h_idst->i_mode != h_isrc->i_mode
4998 + && !S_ISLNK(h_idst->i_mode)) {
4999 + ia.ia_valid |= ATTR_MODE;
5000 + ia.ia_mode = h_isrc->i_mode;
5002 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5003 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5005 + /* no delegation since it is just created */
5006 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5008 + /* is this nfs only? */
5009 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5010 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5011 + ia.ia_mode = h_isrc->i_mode;
5012 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5015 + icex = br->br_perm & AuBrAttr_ICEX;
5017 + mnt_flags = au_mntflags(dst->d_sb);
5018 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5019 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5025 +/* ---------------------------------------------------------------------- */
5027 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5028 + char *buf, unsigned long blksize)
5031 + size_t sz, rbytes, wbytes;
5032 + unsigned char all_zero;
5034 + struct inode *h_inode;
5035 + /* reduce stack usage */
5038 + zp = page_address(ZERO_PAGE(0));
5039 + if (unlikely(!zp))
5040 + return -ENOMEM; /* possible? */
5045 + AuDbg("len %lld\n", len);
5047 + if (len < blksize)
5051 + /* todo: signal_pending? */
5052 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5053 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5056 + if (unlikely(err < 0))
5060 + if (len >= rbytes && rbytes == blksize)
5061 + all_zero = !memcmp(buf, zp, rbytes);
5068 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5070 + /* todo: signal_pending? */
5071 + if (unlikely(err == -EAGAIN || err == -EINTR))
5073 + if (unlikely(err < 0))
5078 + if (unlikely(err < 0))
5084 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5086 + if (unlikely(res < 0))
5093 + /* the last block may be a hole */
5094 + if (!err && all_zero) {
5095 + AuLabel(last hole);
5098 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5099 + /* nfs requires this step to make last hole */
5100 + /* is this only nfs? */
5102 + /* todo: signal_pending? */
5103 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5104 + } while (err == -EAGAIN || err == -EINTR);
5111 + ia->ia_size = dst->f_pos;
5112 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5113 + ia->ia_file = dst;
5114 + h_inode = file_inode(dst);
5115 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5116 + /* no delegation since it is just created */
5117 + err = vfsub_notify_change(&dst->f_path, ia,
5118 + /*delegated*/NULL);
5119 + inode_unlock(h_inode);
5126 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5129 + unsigned long blksize;
5130 + unsigned char do_kfree;
5132 + struct super_block *h_sb;
5135 + h_sb = file_inode(dst)->i_sb;
5136 + blksize = h_sb->s_blocksize;
5137 + if (!blksize || PAGE_SIZE < blksize)
5138 + blksize = PAGE_SIZE;
5139 + AuDbg("blksize %lu\n", blksize);
5140 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5142 + buf = kmalloc(blksize, GFP_NOFS);
5144 + buf = (void *)__get_free_page(GFP_NOFS);
5145 + if (unlikely(!buf))
5148 + if (len > (1 << 22))
5149 + AuDbg("copying a large file %lld\n", (long long)len);
5153 + err = au_do_copy_file(dst, src, len, buf, blksize);
5155 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5156 + au_kfree_do_rcu(buf);
5158 + free_page((unsigned long)buf);
5164 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5167 + struct super_block *h_src_sb;
5168 + struct inode *h_src_inode;
5170 + h_src_inode = file_inode(src);
5171 + h_src_sb = h_src_inode->i_sb;
5173 + /* XFS acquires inode_lock */
5174 + if (!au_test_xfs(h_src_sb))
5175 + err = au_copy_file(dst, src, len);
5177 + inode_unlock_shared(h_src_inode);
5178 + err = au_copy_file(dst, src, len);
5179 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5185 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5189 + struct super_block *h_src_sb;
5190 + struct inode *h_src_inode;
5192 + h_src_inode = file_inode(src);
5193 + h_src_sb = h_src_inode->i_sb;
5194 + if (h_src_sb != file_inode(dst)->i_sb
5195 + || !dst->f_op->remap_file_range) {
5196 + err = au_do_copy(dst, src, len);
5200 + if (!au_test_nfs(h_src_sb)) {
5201 + inode_unlock_shared(h_src_inode);
5202 + lo = vfsub_clone_file_range(src, dst, len);
5203 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5205 + lo = vfsub_clone_file_range(src, dst, len);
5208 + goto out; /* success */
5209 + } else if (lo >= 0)
5210 + /* todo: possible? */
5211 + /* paritially succeeded */
5212 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5213 + else if (lo != -EOPNOTSUPP) {
5214 + /* older XFS has a condition in cloning */
5219 + /* the backend fs on NFS may not support cloning */
5220 + err = au_do_copy(dst, src, len);
5228 + * to support a sparse file which is opened with O_APPEND,
5229 + * we need to close the file.
5231 +static int au_cp_regular(struct au_cp_generic *cpg)
5234 + enum { SRC, DST };
5236 + aufs_bindex_t bindex;
5237 + unsigned int flags;
5238 + struct dentry *dentry;
5240 + struct file *file;
5243 + .bindex = cpg->bsrc,
5244 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5247 + .bindex = cpg->bdst,
5248 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5249 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5252 + struct au_branch *br;
5253 + struct super_block *sb, *h_src_sb;
5254 + struct inode *h_src_inode;
5255 + struct task_struct *tsk = current;
5257 + /* bsrc branch can be ro/rw. */
5258 + sb = cpg->dentry->d_sb;
5260 + for (i = 0; i < 2; i++, f++) {
5261 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5262 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5263 + /*file*/NULL, f->force_wr);
5264 + if (IS_ERR(f->file)) {
5265 + err = PTR_ERR(f->file);
5273 + /* try stopping to update while we copyup */
5274 + h_src_inode = d_inode(file[SRC].dentry);
5275 + h_src_sb = h_src_inode->i_sb;
5276 + if (!au_test_nfs(h_src_sb))
5277 + IMustLock(h_src_inode);
5278 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5280 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5281 + if (tsk->flags & PF_KTHREAD)
5282 + __fput_sync(file[DST].file);
5284 + /* it happened actually */
5285 + fput(file[DST].file);
5288 + * we have to call both since we don't know which place the file
5292 + flush_delayed_fput();
5294 + br = au_sbr(sb, file[DST].bindex);
5295 + au_lcnt_dec(&br->br_nfiles);
5298 + fput(file[SRC].file);
5299 + br = au_sbr(sb, file[SRC].bindex);
5300 + au_lcnt_dec(&br->br_nfiles);
5305 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5306 + struct au_cpup_reg_attr *h_src_attr)
5310 + struct path h_path;
5311 + struct inode *h_src_inode, *h_dst_inode;
5314 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5315 + l = i_size_read(h_src_inode);
5316 + if (cpg->len == -1 || l < cpg->len)
5319 + /* try stopping to update while we are referencing */
5320 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5321 + au_pin_hdir_unlock(cpg->pin);
5323 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5324 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5325 + h_src_attr->iflags = h_src_inode->i_flags;
5326 + if (!au_test_nfs(h_src_inode->i_sb))
5327 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5329 + inode_unlock_shared(h_src_inode);
5330 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5331 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5333 + if (unlikely(err)) {
5334 + inode_unlock_shared(h_src_inode);
5337 + h_src_attr->valid = 1;
5338 + if (!au_test_nfs(h_src_inode->i_sb)) {
5339 + err = au_cp_regular(cpg);
5340 + inode_unlock_shared(h_src_inode);
5342 + inode_unlock_shared(h_src_inode);
5343 + err = au_cp_regular(cpg);
5345 + rerr = au_pin_hdir_relock(cpg->pin);
5349 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5350 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5351 + h_dst_inode = d_inode(h_path.dentry);
5352 + spin_lock(&h_dst_inode->i_lock);
5353 + h_dst_inode->i_state |= I_LINKABLE;
5354 + spin_unlock(&h_dst_inode->i_lock);
5361 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5362 + struct inode *h_dir)
5365 + DEFINE_DELAYED_CALL(done);
5368 + sym = vfs_get_link(h_src, &done);
5369 + err = PTR_ERR(sym);
5373 + err = vfsub_symlink(h_dir, h_path, sym);
5376 + do_delayed_call(&done);
5381 + * regardless 'acl' option, reset all ACL.
5382 + * All ACL will be copied up later from the original entry on the lower branch.
5384 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5387 + struct dentry *h_dentry;
5388 + struct inode *h_inode;
5390 + h_dentry = h_path->dentry;
5391 + h_inode = d_inode(h_dentry);
5392 + /* forget_all_cached_acls(h_inode)); */
5393 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5395 + if (err == -EOPNOTSUPP)
5398 + err = vfsub_acl_chmod(h_inode, mode);
5404 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5405 + struct inode *h_dir, struct path *h_path)
5408 + struct inode *dir, *inode;
5410 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5412 + if (err == -EOPNOTSUPP)
5414 + if (unlikely(err))
5418 + * strange behaviour from the users view,
5419 + * particularly setattr case
5421 + dir = d_inode(dst_parent);
5422 + if (au_ibtop(dir) == cpg->bdst)
5423 + au_cpup_attr_nlink(dir, /*force*/1);
5424 + inode = d_inode(cpg->dentry);
5425 + au_cpup_attr_nlink(inode, /*force*/1);
5431 +static noinline_for_stack
5432 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5433 + struct au_cpup_reg_attr *h_src_attr)
5437 + unsigned int mnt_flags;
5438 + unsigned char isdir, isreg, force;
5439 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5440 + struct au_dtime dt;
5441 + struct path h_path;
5442 + struct dentry *h_src, *h_dst, *h_parent;
5443 + struct inode *h_inode, *h_dir;
5444 + struct super_block *sb;
5446 + /* bsrc branch can be ro/rw. */
5447 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5448 + h_inode = d_inode(h_src);
5449 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5451 + /* try stopping to be referenced while we are creating */
5452 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5453 + if (au_ftest_cpup(cpg->flags, RENAME))
5454 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5455 + AUFS_WH_PFX_LEN));
5456 + h_parent = h_dst->d_parent; /* dir inode is locked */
5457 + h_dir = d_inode(h_parent);
5459 + AuDebugOn(h_parent != h_dst->d_parent);
5461 + sb = cpg->dentry->d_sb;
5462 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5464 + h_path.dentry = h_parent;
5465 + au_dtime_store(&dt, dst_parent, &h_path);
5467 + h_path.dentry = h_dst;
5471 + mode = h_inode->i_mode;
5472 + switch (mode & S_IFMT) {
5475 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5477 + err = au_do_cpup_regular(cpg, h_src_attr);
5481 + err = vfsub_mkdir(h_dir, &h_path, mode);
5483 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5486 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5490 + AuDebugOn(!capable(CAP_MKNOD));
5494 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5497 + AuIOErr("Unknown inode type 0%o\n", mode);
5501 + err = au_reset_acl(h_dir, &h_path, mode);
5503 + mnt_flags = au_mntflags(sb);
5504 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5506 + && au_opt_test(mnt_flags, XINO)
5507 + && (h_inode->i_nlink == 1
5508 + || (h_inode->i_state & I_LINKABLE))
5509 + /* todo: unnecessary? */
5510 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5511 + && cpg->bdst < cpg->bsrc
5512 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5513 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5514 + /* ignore this error */
5519 + force = !!cpg->len;
5520 + if (cpg->len == -1)
5521 + force = !!i_size_read(h_inode);
5523 + au_fhsm_wrote(sb, cpg->bdst, force);
5527 + au_dtime_revert(&dt);
5531 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5534 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5535 + struct inode *h_dir;
5536 + aufs_bindex_t bdst;
5538 + dentry = cpg->dentry;
5540 + h_dentry = au_h_dptr(dentry, bdst);
5541 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5543 + au_set_h_dptr(dentry, bdst, NULL);
5544 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5546 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5547 + au_set_h_dptr(dentry, bdst, h_dentry);
5550 + parent = dget_parent(dentry);
5551 + h_parent = au_h_dptr(parent, bdst);
5553 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5554 + if (IS_ERR(h_path->dentry))
5555 + err = PTR_ERR(h_path->dentry);
5557 + if (unlikely(err))
5560 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5561 + h_dir = d_inode(h_parent);
5563 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5564 + /* no delegation since it is just created */
5565 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5567 + dput(h_path->dentry);
5574 + * copyup the @dentry from @bsrc to @bdst.
5575 + * the caller must set the both of lower dentries.
5576 + * @len is for truncating when it is -1 copyup the entire file.
5577 + * in link/rename cases, @dst_parent may be different from the real one.
5578 + * basic->bsrc can be larger than basic->bdst.
5579 + * aufs doesn't touch the credential so
5580 + * security_inode_copy_up{,_xattr}() are unnecessary.
5582 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5585 + aufs_bindex_t old_ibtop;
5586 + unsigned char isdir, plink;
5587 + struct dentry *h_src, *h_dst, *h_parent;
5588 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5589 + struct super_block *sb;
5590 + struct au_branch *br;
5591 + /* to reduce stack size */
5593 + struct au_dtime dt;
5594 + struct path h_path;
5595 + struct au_cpup_reg_attr h_src_attr;
5599 + a = kmalloc(sizeof(*a), GFP_NOFS);
5602 + a->h_src_attr.valid = 0;
5604 + sb = cpg->dentry->d_sb;
5605 + br = au_sbr(sb, cpg->bdst);
5606 + a->h_path.mnt = au_br_mnt(br);
5607 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5608 + h_parent = h_dst->d_parent; /* dir inode is locked */
5609 + h_dir = d_inode(h_parent);
5612 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5613 + inode = d_inode(cpg->dentry);
5616 + dst_parent = dget_parent(cpg->dentry);
5620 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5621 + dst_inode = au_h_iptr(inode, cpg->bdst);
5623 + if (unlikely(!plink)) {
5625 + AuIOErr("hi%lu(i%lu) exists on b%d "
5626 + "but plink is disabled\n",
5627 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5631 + if (dst_inode->i_nlink) {
5632 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5634 + h_src = au_plink_lkup(inode, cpg->bdst);
5635 + err = PTR_ERR(h_src);
5636 + if (IS_ERR(h_src))
5638 + if (unlikely(d_is_negative(h_src))) {
5640 + AuIOErr("i%lu exists on b%d "
5641 + "but not pseudo-linked\n",
5642 + inode->i_ino, cpg->bdst);
5648 + a->h_path.dentry = h_parent;
5649 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5652 + a->h_path.dentry = h_dst;
5654 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5655 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5656 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5658 + au_dtime_revert(&a->dt);
5659 + if (unlikely(err == -EWOULDBLOCK)) {
5660 + pr_warn("cannot retry for NFSv4 delegation"
5661 + " for an internal link\n");
5667 + /* todo: cpup_wh_file? */
5669 + au_update_ibrange(inode, /*do_put_zero*/1);
5672 + isdir = S_ISDIR(inode->i_mode);
5673 + old_ibtop = au_ibtop(inode);
5674 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5675 + if (unlikely(err))
5677 + dst_inode = d_inode(h_dst);
5678 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5679 + /* todo: necessary? */
5680 + /* au_pin_hdir_unlock(cpg->pin); */
5682 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5683 + if (unlikely(err)) {
5684 + /* todo: necessary? */
5685 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5686 + inode_unlock(dst_inode);
5690 + if (cpg->bdst < old_ibtop) {
5691 + if (S_ISREG(inode->i_mode)) {
5692 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5693 + if (unlikely(err)) {
5694 + /* ignore an error */
5695 + /* au_pin_hdir_relock(cpg->pin); */
5696 + inode_unlock(dst_inode);
5700 + au_set_ibtop(inode, cpg->bdst);
5702 + au_set_ibbot(inode, cpg->bdst);
5703 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5704 + au_hi_flags(inode, isdir));
5706 + /* todo: necessary? */
5707 + /* err = au_pin_hdir_relock(cpg->pin); */
5708 + inode_unlock(dst_inode);
5709 + if (unlikely(err))
5712 + src_inode = d_inode(h_src);
5714 + && (src_inode->i_nlink > 1
5715 + || src_inode->i_state & I_LINKABLE)
5717 + au_plink_append(inode, cpg->bdst, h_dst);
5719 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5720 + a->h_path.dentry = h_dst;
5721 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5724 + goto out_parent; /* success */
5728 + a->h_path.dentry = h_parent;
5729 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5730 + a->h_path.dentry = h_dst;
5732 + if (d_is_positive(h_dst)) {
5734 + /* no delegation since it is just created */
5735 + rerr = vfsub_unlink(h_dir, &a->h_path,
5736 + /*delegated*/NULL, /*force*/0);
5738 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5740 + au_dtime_revert(&a->dt);
5742 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5752 +#if 0 /* reserved */
5753 +struct au_cpup_single_args {
5755 + struct au_cp_generic *cpg;
5756 + struct dentry *dst_parent;
5759 +static void au_call_cpup_single(void *args)
5761 + struct au_cpup_single_args *a = args;
5763 + au_pin_hdir_acquire_nest(a->cpg->pin);
5764 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5765 + au_pin_hdir_release(a->cpg->pin);
5770 + * prevent SIGXFSZ in copy-up.
5771 + * testing CAP_MKNOD is for generic fs,
5772 + * but CAP_FSETID is for xfs only, currently.
5774 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5777 + struct super_block *sb;
5778 + struct inode *h_dir;
5781 + sb = au_pinned_parent(pin)->d_sb;
5782 + if (!au_wkq_test()
5783 + && (!au_sbi(sb)->si_plink_maint_pid
5784 + || au_plink_maint(sb, AuLock_NOPLM))) {
5785 + switch (mode & S_IFMT) {
5787 + /* no condition about RLIMIT_FSIZE and the file size */
5792 + do_sio = !capable(CAP_MKNOD);
5796 + do_sio = ((mode & (S_ISUID | S_ISGID))
5797 + && !capable(CAP_FSETID));
5798 + /* this workaround may be removed in the future */
5800 + h_dir = au_pinned_h_dir(pin);
5801 + do_sio = h_dir->i_mode & S_ISVTX;
5808 +#if 0 /* reserved */
5809 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5812 + struct dentry *h_dentry;
5814 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5815 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5816 + err = au_cpup_single(cpg, dst_parent);
5818 + struct au_cpup_single_args args = {
5821 + .dst_parent = dst_parent
5823 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5824 + if (unlikely(wkq_err))
5833 + * copyup the @dentry from the first active lower branch to @bdst,
5834 + * using au_cpup_single().
5836 +static int au_cpup_simple(struct au_cp_generic *cpg)
5839 + unsigned int flags_orig;
5840 + struct dentry *dentry;
5842 + AuDebugOn(cpg->bsrc < 0);
5844 + dentry = cpg->dentry;
5845 + DiMustWriteLock(dentry);
5847 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5849 + flags_orig = cpg->flags;
5850 + au_fset_cpup(cpg->flags, RENAME);
5851 + err = au_cpup_single(cpg, NULL);
5852 + cpg->flags = flags_orig;
5854 + return 0; /* success */
5857 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5858 + au_set_dbtop(dentry, cpg->bsrc);
5864 +struct au_cpup_simple_args {
5866 + struct au_cp_generic *cpg;
5869 +static void au_call_cpup_simple(void *args)
5871 + struct au_cpup_simple_args *a = args;
5873 + au_pin_hdir_acquire_nest(a->cpg->pin);
5874 + *a->errp = au_cpup_simple(a->cpg);
5875 + au_pin_hdir_release(a->cpg->pin);
5878 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5881 + struct dentry *dentry, *parent;
5882 + struct file *h_file;
5883 + struct inode *h_dir;
5885 + dentry = cpg->dentry;
5887 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5888 + AuDebugOn(cpg->bsrc < 0);
5889 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5890 + err = PTR_ERR(h_file);
5891 + if (IS_ERR(h_file))
5895 + parent = dget_parent(dentry);
5896 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5897 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5898 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5899 + err = au_cpup_simple(cpg);
5901 + struct au_cpup_simple_args args = {
5905 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5906 + if (unlikely(wkq_err))
5912 + au_h_open_post(dentry, cpg->bsrc, h_file);
5918 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5920 + aufs_bindex_t bsrc, bbot;
5921 + struct dentry *dentry, *h_dentry;
5923 + if (cpg->bsrc < 0) {
5924 + dentry = cpg->dentry;
5925 + bbot = au_dbbot(dentry);
5926 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5927 + h_dentry = au_h_dptr(dentry, bsrc);
5929 + AuDebugOn(d_is_negative(h_dentry));
5933 + AuDebugOn(bsrc > bbot);
5936 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5937 + return au_do_sio_cpup_simple(cpg);
5940 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5942 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5943 + return au_do_sio_cpup_simple(cpg);
5946 +/* ---------------------------------------------------------------------- */
5949 + * copyup the deleted file for writing.
5951 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5952 + struct file *file)
5955 + unsigned int flags_orig;
5956 + aufs_bindex_t bsrc_orig;
5957 + struct au_dinfo *dinfo;
5959 + struct au_hdentry *hd;
5960 + struct dentry *h_dentry;
5963 + dinfo = au_di(cpg->dentry);
5964 + AuRwMustWriteLock(&dinfo->di_rwsem);
5966 + bsrc_orig = cpg->bsrc;
5967 + cpg->bsrc = dinfo->di_btop;
5968 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5969 + hdst.h_dentry = hdst.hd->hd_dentry;
5970 + hdst.hd->hd_dentry = wh_dentry;
5971 + dinfo->di_btop = cpg->bdst;
5973 + hsrc.h_dentry = NULL;
5975 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5976 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5977 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5979 + flags_orig = cpg->flags;
5980 + cpg->flags = !AuCpup_DTIME;
5981 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5982 + cpg->flags = flags_orig;
5985 + err = au_reopen_nondir(file);
5986 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5988 + hdst.hd->hd_dentry = hdst.h_dentry;
5989 + dinfo->di_btop = cpg->bsrc;
5990 + cpg->bsrc = bsrc_orig;
5995 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5998 + aufs_bindex_t bdst;
5999 + struct au_dtime dt;
6000 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6001 + struct au_branch *br;
6002 + struct path h_path;
6004 + dentry = cpg->dentry;
6006 + br = au_sbr(dentry->d_sb, bdst);
6007 + parent = dget_parent(dentry);
6008 + h_parent = au_h_dptr(parent, bdst);
6009 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6010 + err = PTR_ERR(wh_dentry);
6011 + if (IS_ERR(wh_dentry))
6014 + h_path.dentry = h_parent;
6015 + h_path.mnt = au_br_mnt(br);
6016 + au_dtime_store(&dt, parent, &h_path);
6017 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6018 + if (unlikely(err))
6022 + h_path.dentry = wh_dentry;
6023 + if (!d_is_dir(wh_dentry)) {
6024 + /* no delegation since it is just created */
6025 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6026 + /*delegated*/NULL, /*force*/0);
6028 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6029 + if (unlikely(err)) {
6030 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6034 + au_dtime_revert(&dt);
6035 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6044 +struct au_cpup_wh_args {
6046 + struct au_cp_generic *cpg;
6047 + struct file *file;
6050 +static void au_call_cpup_wh(void *args)
6052 + struct au_cpup_wh_args *a = args;
6054 + au_pin_hdir_acquire_nest(a->cpg->pin);
6055 + *a->errp = au_cpup_wh(a->cpg, a->file);
6056 + au_pin_hdir_release(a->cpg->pin);
6059 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6062 + aufs_bindex_t bdst;
6063 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6064 + struct inode *dir, *h_dir, *h_tmpdir;
6065 + struct au_wbr *wbr;
6066 + struct au_pin wh_pin, *pin_orig;
6068 + dentry = cpg->dentry;
6070 + parent = dget_parent(dentry);
6071 + dir = d_inode(parent);
6074 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6077 + if (!h_dir->i_nlink) {
6078 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6079 + h_orph = wbr->wbr_orph;
6081 + h_parent = dget(au_h_dptr(parent, bdst));
6082 + au_set_h_dptr(parent, bdst, dget(h_orph));
6083 + h_tmpdir = d_inode(h_orph);
6084 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6086 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6087 + /* todo: au_h_open_pre()? */
6089 + pin_orig = cpg->pin;
6090 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6091 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6092 + cpg->pin = &wh_pin;
6095 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6096 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6097 + err = au_cpup_wh(cpg, file);
6099 + struct au_cpup_wh_args args = {
6104 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6105 + if (unlikely(wkq_err))
6110 + inode_unlock(h_tmpdir);
6111 + /* todo: au_h_open_post()? */
6112 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6113 + au_set_h_dptr(parent, bdst, h_parent);
6114 + AuDebugOn(!pin_orig);
6115 + cpg->pin = pin_orig;
6123 +/* ---------------------------------------------------------------------- */
6126 + * generic routine for both of copy-up and copy-down.
6128 +/* cf. revalidate function in file.c */
6129 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6130 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6131 + struct au_pin *pin,
6132 + struct dentry *h_parent, void *arg),
6136 + struct au_pin pin;
6137 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6140 + parent = dget_parent(dentry);
6141 + if (IS_ROOT(parent))
6144 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6145 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6147 + /* do not use au_dpage */
6148 + real_parent = parent;
6151 + parent = dget_parent(dentry);
6152 + h_parent = au_h_dptr(parent, bdst);
6154 + goto out; /* success */
6156 + /* find top dir which is necessary to cpup */
6160 + parent = dget_parent(d);
6161 + di_read_lock_parent3(parent, !AuLock_IR);
6162 + h_parent = au_h_dptr(parent, bdst);
6163 + di_read_unlock(parent, !AuLock_IR);
6164 + } while (!h_parent);
6166 + if (d != real_parent)
6167 + di_write_lock_child3(d);
6169 + /* somebody else might create while we were sleeping */
6170 + h_dentry = au_h_dptr(d, bdst);
6171 + if (!h_dentry || d_is_negative(h_dentry)) {
6173 + au_update_dbtop(d);
6175 + au_pin_set_dentry(&pin, d);
6176 + err = au_do_pin(&pin);
6178 + err = cp(d, bdst, &pin, h_parent, arg);
6183 + if (d != real_parent)
6184 + di_write_unlock(d);
6185 + if (unlikely(err))
6194 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6195 + struct au_pin *pin,
6196 + struct dentry *h_parent __maybe_unused,
6197 + void *arg __maybe_unused)
6199 + struct au_cp_generic cpg = {
6205 + .flags = AuCpup_DTIME
6207 + return au_sio_cpup_simple(&cpg);
6210 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6212 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6215 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6218 + struct dentry *parent;
6219 + struct inode *dir;
6221 + parent = dget_parent(dentry);
6222 + dir = d_inode(parent);
6224 + if (au_h_iptr(dir, bdst))
6227 + di_read_unlock(parent, AuLock_IR);
6228 + di_write_lock_parent(parent);
6229 + /* someone else might change our inode while we were sleeping */
6230 + if (!au_h_iptr(dir, bdst))
6231 + err = au_cpup_dirs(dentry, bdst);
6232 + di_downgrade_lock(parent, AuLock_IR);
6238 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6239 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6240 +++ linux/fs/aufs/cpup.h 2020-01-27 10:57:18.168871450 +0100
6242 +/* SPDX-License-Identifier: GPL-2.0 */
6244 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6246 + * This program, aufs is free software; you can redistribute it and/or modify
6247 + * it under the terms of the GNU General Public License as published by
6248 + * the Free Software Foundation; either version 2 of the License, or
6249 + * (at your option) any later version.
6251 + * This program is distributed in the hope that it will be useful,
6252 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6253 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6254 + * GNU General Public License for more details.
6256 + * You should have received a copy of the GNU General Public License
6257 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6261 + * copy-up/down functions
6264 +#ifndef __AUFS_CPUP_H__
6265 +#define __AUFS_CPUP_H__
6269 +#include <linux/path.h>
6275 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6276 +void au_cpup_attr_timesizes(struct inode *inode);
6277 +void au_cpup_attr_nlink(struct inode *inode, int force);
6278 +void au_cpup_attr_changeable(struct inode *inode);
6279 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6280 +void au_cpup_attr_all(struct inode *inode, int force);
6282 +/* ---------------------------------------------------------------------- */
6284 +struct au_cp_generic {
6285 + struct dentry *dentry;
6286 + aufs_bindex_t bdst, bsrc;
6288 + struct au_pin *pin;
6289 + unsigned int flags;
6293 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6294 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6296 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6297 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6299 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6301 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6302 + the branch is marked as RO */
6304 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6305 +#undef AuCpup_HOPEN
6306 +#define AuCpup_HOPEN 0
6309 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6310 +#define au_fset_cpup(flags, name) \
6311 + do { (flags) |= AuCpup_##name; } while (0)
6312 +#define au_fclr_cpup(flags, name) \
6313 + do { (flags) &= ~AuCpup_##name; } while (0)
6315 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6316 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6317 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6318 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6320 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6321 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6322 + struct au_pin *pin,
6323 + struct dentry *h_parent, void *arg),
6325 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6326 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6328 +/* ---------------------------------------------------------------------- */
6330 +/* keep timestamps when copyup */
6332 + struct dentry *dt_dentry;
6333 + struct path dt_h_path;
6334 + struct timespec64 dt_atime, dt_mtime;
6336 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6337 + struct path *h_path);
6338 +void au_dtime_revert(struct au_dtime *dt);
6340 +#endif /* __KERNEL__ */
6341 +#endif /* __AUFS_CPUP_H__ */
6342 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6343 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6344 +++ linux/fs/aufs/dbgaufs.c 2020-01-27 10:57:18.168871450 +0100
6346 +// SPDX-License-Identifier: GPL-2.0
6348 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6350 + * This program, aufs is free software; you can redistribute it and/or modify
6351 + * it under the terms of the GNU General Public License as published by
6352 + * the Free Software Foundation; either version 2 of the License, or
6353 + * (at your option) any later version.
6355 + * This program is distributed in the hope that it will be useful,
6356 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6357 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6358 + * GNU General Public License for more details.
6360 + * You should have received a copy of the GNU General Public License
6361 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6365 + * debugfs interface
6368 +#include <linux/debugfs.h>
6371 +#ifndef CONFIG_SYSFS
6372 +#error DEBUG_FS depends upon SYSFS
6375 +static struct dentry *dbgaufs;
6376 +static const mode_t dbgaufs_mode = 0444;
6378 +/* 20 is max digits length of ulong 64 */
6379 +struct dbgaufs_arg {
6385 + * common function for all XINO files
6387 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6388 + struct file *file)
6392 + p = file->private_data;
6394 + /* this is struct dbgaufs_arg */
6395 + AuDebugOn(!au_kfree_sz_test(p));
6396 + au_kfree_do_rcu(p);
6401 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6406 + struct dbgaufs_arg *p;
6409 + p = kmalloc(sizeof(*p), GFP_NOFS);
6415 + file->private_data = p;
6419 + err = vfsub_getattr(&xf->f_path, &st);
6423 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6424 + cnt, st.blocks, st.blksize,
6425 + (long long)st.size);
6427 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6428 + st.blocks, st.blksize,
6429 + (long long)st.size);
6430 + AuDebugOn(p->n >= sizeof(p->a));
6432 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6440 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6441 + size_t count, loff_t *ppos)
6443 + struct dbgaufs_arg *p;
6445 + p = file->private_data;
6446 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6449 +/* ---------------------------------------------------------------------- */
6451 +struct dbgaufs_plink_arg {
6456 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6457 + struct file *file)
6459 + free_page((unsigned long)file->private_data);
6463 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6465 + int err, i, limit;
6466 + unsigned long n, sum;
6467 + struct dbgaufs_plink_arg *p;
6468 + struct au_sbinfo *sbinfo;
6469 + struct super_block *sb;
6470 + struct hlist_bl_head *hbl;
6473 + p = (void *)get_zeroed_page(GFP_NOFS);
6478 + sbinfo = inode->i_private;
6479 + sb = sbinfo->si_sb;
6480 + si_noflush_read_lock(sb);
6481 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6482 + limit = PAGE_SIZE - sizeof(p->n);
6484 + /* the number of buckets */
6485 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6490 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6492 + n = au_hbl_count(hbl);
6495 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6498 + if (unlikely(limit <= 0))
6501 + p->a[p->n - 1] = '\n';
6503 + /* the sum of plinks */
6504 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6507 + if (unlikely(limit <= 0))
6510 +#define str "1\n0\n0\n"
6511 + p->n = sizeof(str) - 1;
6512 + strcpy(p->a, str);
6515 + si_read_unlock(sb);
6518 + file->private_data = p;
6519 + goto out; /* success */
6522 + free_page((unsigned long)p);
6527 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6528 + size_t count, loff_t *ppos)
6530 + struct dbgaufs_plink_arg *p;
6532 + p = file->private_data;
6533 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6536 +static const struct file_operations dbgaufs_plink_fop = {
6537 + .owner = THIS_MODULE,
6538 + .open = dbgaufs_plink_open,
6539 + .release = dbgaufs_plink_release,
6540 + .read = dbgaufs_plink_read
6543 +/* ---------------------------------------------------------------------- */
6545 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6548 + struct au_sbinfo *sbinfo;
6549 + struct super_block *sb;
6551 + sbinfo = inode->i_private;
6552 + sb = sbinfo->si_sb;
6553 + si_noflush_read_lock(sb);
6554 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6555 + si_read_unlock(sb);
6559 +static const struct file_operations dbgaufs_xib_fop = {
6560 + .owner = THIS_MODULE,
6561 + .open = dbgaufs_xib_open,
6562 + .release = dbgaufs_xi_release,
6563 + .read = dbgaufs_xi_read
6566 +/* ---------------------------------------------------------------------- */
6568 +#define DbgaufsXi_PREFIX "xi"
6570 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6574 + aufs_bindex_t bindex;
6575 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6576 + struct au_sbinfo *sbinfo;
6577 + struct super_block *sb;
6578 + struct au_xino *xi;
6580 + struct qstr *name;
6581 + struct au_branch *br;
6584 + name = &file->f_path.dentry->d_name;
6585 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6586 + || memcmp(name->name, DbgaufsXi_PREFIX,
6587 + sizeof(DbgaufsXi_PREFIX) - 1)))
6590 + AuDebugOn(name->len >= sizeof(a));
6591 + memcpy(a, name->name, name->len);
6592 + a[name->len] = '\0';
6593 + p = strchr(a, '-');
6596 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6597 + if (unlikely(err))
6602 + err = kstrtol(p + 1, 10, &l);
6603 + if (unlikely(err))
6609 + sbinfo = inode->i_private;
6610 + sb = sbinfo->si_sb;
6611 + si_noflush_read_lock(sb);
6612 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6614 + br = au_sbr(sb, bindex);
6616 + if (unlikely(idx >= xi->xi_nfile))
6618 + xf = au_xino_file(xi, idx);
6620 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6621 + au_xino_count(br));
6624 + si_read_unlock(sb);
6630 +static const struct file_operations dbgaufs_xino_fop = {
6631 + .owner = THIS_MODULE,
6632 + .open = dbgaufs_xino_open,
6633 + .release = dbgaufs_xi_release,
6634 + .read = dbgaufs_xi_read
6637 +void dbgaufs_xino_del(struct au_branch *br)
6639 + struct dentry *dbgaufs;
6641 + dbgaufs = br->br_dbgaufs;
6645 + br->br_dbgaufs = NULL;
6646 + /* debugfs acquires the parent i_mutex */
6648 + debugfs_remove(dbgaufs);
6652 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6654 + aufs_bindex_t bbot;
6655 + struct au_branch *br;
6657 + if (!au_sbi(sb)->si_dbgaufs)
6660 + bbot = au_sbbot(sb);
6661 + for (; bindex <= bbot; bindex++) {
6662 + br = au_sbr(sb, bindex);
6663 + dbgaufs_xino_del(br);
6667 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6668 + unsigned int idx, struct dentry *parent,
6669 + struct au_sbinfo *sbinfo)
6671 + struct au_branch *br;
6673 + /* "xi" bindex(5) "-" idx(2) NULL */
6674 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6677 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6679 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6681 + br = au_sbr(sb, bindex);
6682 + if (br->br_dbgaufs) {
6683 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6685 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6686 + /* debugfs acquires the parent i_mutex */
6688 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6692 + pr_warn("failed renaming %pd/%s, ignored.\n",
6697 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6698 + sbinfo, &dbgaufs_xino_fop);
6700 + if (unlikely(!br->br_dbgaufs))
6701 + pr_warn("failed creating %pd/%s, ignored.\n",
6706 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6707 + struct dentry *parent, struct au_sbinfo *sbinfo)
6709 + struct au_branch *br;
6710 + struct au_xino *xi;
6713 + br = au_sbr(sb, bindex);
6715 + for (u = 0; u < xi->xi_nfile; u++)
6716 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6719 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6721 + struct au_sbinfo *sbinfo;
6722 + struct dentry *parent;
6723 + aufs_bindex_t bbot;
6725 + if (!au_opt_test(au_mntflags(sb), XINO))
6728 + sbinfo = au_sbi(sb);
6729 + parent = sbinfo->si_dbgaufs;
6733 + bbot = au_sbbot(sb);
6735 + for (; bindex <= bbot; bindex++)
6736 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6738 + for (; bbot >= bindex; bbot--)
6739 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6742 +/* ---------------------------------------------------------------------- */
6744 +#ifdef CONFIG_AUFS_EXPORT
6745 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6748 + struct au_sbinfo *sbinfo;
6749 + struct super_block *sb;
6751 + sbinfo = inode->i_private;
6752 + sb = sbinfo->si_sb;
6753 + si_noflush_read_lock(sb);
6754 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6755 + si_read_unlock(sb);
6759 +static const struct file_operations dbgaufs_xigen_fop = {
6760 + .owner = THIS_MODULE,
6761 + .open = dbgaufs_xigen_open,
6762 + .release = dbgaufs_xi_release,
6763 + .read = dbgaufs_xi_read
6766 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6771 + * This function is a dynamic '__init' function actually,
6772 + * so the tiny check for si_rwsem is unnecessary.
6774 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6777 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6778 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6779 + &dbgaufs_xigen_fop);
6780 + if (sbinfo->si_dbgaufs_xigen)
6786 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6790 +#endif /* CONFIG_AUFS_EXPORT */
6792 +/* ---------------------------------------------------------------------- */
6794 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6797 + * This function is a dynamic '__fin' function actually,
6798 + * so the tiny check for si_rwsem is unnecessary.
6800 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6802 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6803 + sbinfo->si_dbgaufs = NULL;
6806 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6809 + char name[SysaufsSiNameLen];
6812 + * This function is a dynamic '__init' function actually,
6813 + * so the tiny check for si_rwsem is unnecessary.
6815 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6819 + AuErr1("/debug/aufs is uninitialized\n");
6824 + sysaufs_name(sbinfo, name);
6825 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6826 + if (unlikely(!sbinfo->si_dbgaufs))
6829 + /* regardless plink/noplink option */
6830 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6831 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6832 + &dbgaufs_plink_fop);
6833 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6836 + /* regardless xino/noxino option */
6837 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6838 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6839 + &dbgaufs_xib_fop);
6840 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6843 + err = dbgaufs_xigen_init(sbinfo);
6845 + goto out; /* success */
6848 + dbgaufs_si_fin(sbinfo);
6850 + if (unlikely(err))
6851 + pr_err("debugfs/aufs failed\n");
6855 +/* ---------------------------------------------------------------------- */
6857 +void dbgaufs_fin(void)
6859 + debugfs_remove(dbgaufs);
6862 +int __init dbgaufs_init(void)
6867 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6872 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6873 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6874 +++ linux/fs/aufs/dbgaufs.h 2020-01-27 10:57:18.168871450 +0100
6876 +/* SPDX-License-Identifier: GPL-2.0 */
6878 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6880 + * This program, aufs is free software; you can redistribute it and/or modify
6881 + * it under the terms of the GNU General Public License as published by
6882 + * the Free Software Foundation; either version 2 of the License, or
6883 + * (at your option) any later version.
6885 + * This program is distributed in the hope that it will be useful,
6886 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6887 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6888 + * GNU General Public License for more details.
6890 + * You should have received a copy of the GNU General Public License
6891 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6895 + * debugfs interface
6898 +#ifndef __DBGAUFS_H__
6899 +#define __DBGAUFS_H__
6903 +struct super_block;
6907 +#ifdef CONFIG_DEBUG_FS
6909 +void dbgaufs_xino_del(struct au_branch *br);
6910 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6911 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6912 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6913 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6914 +void dbgaufs_fin(void);
6915 +int __init dbgaufs_init(void);
6917 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6918 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6919 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6921 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6922 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6923 +AuStubVoid(dbgaufs_fin, void)
6924 +AuStubInt0(__init dbgaufs_init, void)
6925 +#endif /* CONFIG_DEBUG_FS */
6927 +#endif /* __KERNEL__ */
6928 +#endif /* __DBGAUFS_H__ */
6929 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6930 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6931 +++ linux/fs/aufs/dcsub.c 2020-01-27 10:57:18.168871450 +0100
6933 +// SPDX-License-Identifier: GPL-2.0
6935 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6937 + * This program, aufs is free software; you can redistribute it and/or modify
6938 + * it under the terms of the GNU General Public License as published by
6939 + * the Free Software Foundation; either version 2 of the License, or
6940 + * (at your option) any later version.
6942 + * This program is distributed in the hope that it will be useful,
6943 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6944 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6945 + * GNU General Public License for more details.
6947 + * You should have received a copy of the GNU General Public License
6948 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6952 + * sub-routines for dentry cache
6957 +static void au_dpage_free(struct au_dpage *dpage)
6960 + struct dentry **p;
6962 + p = dpage->dentries;
6963 + for (i = 0; i < dpage->ndentry; i++)
6965 + free_page((unsigned long)dpage->dentries);
6968 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6974 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6975 + if (unlikely(!dpages->dpages))
6978 + p = (void *)__get_free_page(gfp);
6982 + dpages->dpages[0].ndentry = 0;
6983 + dpages->dpages[0].dentries = p;
6984 + dpages->ndpage = 1;
6985 + return 0; /* success */
6988 + au_kfree_try_rcu(dpages->dpages);
6993 +void au_dpages_free(struct au_dcsub_pages *dpages)
6996 + struct au_dpage *p;
6998 + p = dpages->dpages;
6999 + for (i = 0; i < dpages->ndpage; i++)
7000 + au_dpage_free(p++);
7001 + au_kfree_try_rcu(dpages->dpages);
7004 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7005 + struct dentry *dentry, gfp_t gfp)
7008 + struct au_dpage *dpage;
7011 + dpage = dpages->dpages + dpages->ndpage - 1;
7012 + sz = PAGE_SIZE / sizeof(dentry);
7013 + if (unlikely(dpage->ndentry >= sz)) {
7014 + AuLabel(new dpage);
7016 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7017 + p = au_kzrealloc(dpages->dpages, sz,
7018 + sz + sizeof(*dpages->dpages), gfp,
7023 + dpages->dpages = p;
7024 + dpage = dpages->dpages + dpages->ndpage;
7025 + p = (void *)__get_free_page(gfp);
7029 + dpage->ndentry = 0;
7030 + dpage->dentries = p;
7034 + AuDebugOn(au_dcount(dentry) <= 0);
7035 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7036 + return 0; /* success */
7042 +/* todo: BAD approach */
7043 +/* copied from linux/fs/dcache.c */
7051 +extern void d_walk(struct dentry *parent, void *data,
7052 + enum d_walk_ret (*enter)(void *, struct dentry *));
7054 +struct ac_dpages_arg {
7056 + struct au_dcsub_pages *dpages;
7057 + struct super_block *sb;
7058 + au_dpages_test test;
7062 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7064 + enum d_walk_ret ret;
7065 + struct ac_dpages_arg *arg = _arg;
7067 + ret = D_WALK_CONTINUE;
7068 + if (dentry->d_sb == arg->sb
7069 + && !IS_ROOT(dentry)
7070 + && au_dcount(dentry) > 0
7072 + && (!arg->test || arg->test(dentry, arg->arg))) {
7073 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7074 + if (unlikely(arg->err))
7075 + ret = D_WALK_QUIT;
7081 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7082 + au_dpages_test test, void *arg)
7084 + struct ac_dpages_arg args = {
7092 + d_walk(root, &args, au_call_dpages_append);
7097 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7098 + int do_include, au_dpages_test test, void *arg)
7103 + write_seqlock(&rename_lock);
7104 + spin_lock(&dentry->d_lock);
7106 + && au_dcount(dentry) > 0
7107 + && (!test || test(dentry, arg)))
7108 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7109 + spin_unlock(&dentry->d_lock);
7110 + if (unlikely(err))
7114 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7117 + while (!IS_ROOT(dentry)) {
7118 + dentry = dentry->d_parent; /* rename_lock is locked */
7119 + spin_lock(&dentry->d_lock);
7120 + if (au_dcount(dentry) > 0
7121 + && (!test || test(dentry, arg)))
7122 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7123 + spin_unlock(&dentry->d_lock);
7124 + if (unlikely(err))
7129 + write_sequnlock(&rename_lock);
7133 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7135 + return au_di(dentry) && dentry->d_sb == arg;
7138 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7139 + struct dentry *dentry, int do_include)
7141 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7142 + au_dcsub_dpages_aufs, dentry->d_sb);
7145 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7147 + struct path path[2] = {
7156 + return path_is_under(path + 0, path + 1);
7158 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7159 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7160 +++ linux/fs/aufs/dcsub.h 2020-01-27 10:57:18.168871450 +0100
7162 +/* SPDX-License-Identifier: GPL-2.0 */
7164 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7166 + * This program, aufs is free software; you can redistribute it and/or modify
7167 + * it under the terms of the GNU General Public License as published by
7168 + * the Free Software Foundation; either version 2 of the License, or
7169 + * (at your option) any later version.
7171 + * This program is distributed in the hope that it will be useful,
7172 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7173 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7174 + * GNU General Public License for more details.
7176 + * You should have received a copy of the GNU General Public License
7177 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7181 + * sub-routines for dentry cache
7184 +#ifndef __AUFS_DCSUB_H__
7185 +#define __AUFS_DCSUB_H__
7189 +#include <linux/dcache.h>
7190 +#include <linux/fs.h>
7194 + struct dentry **dentries;
7197 +struct au_dcsub_pages {
7199 + struct au_dpage *dpages;
7202 +/* ---------------------------------------------------------------------- */
7205 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7206 +void au_dpages_free(struct au_dcsub_pages *dpages);
7207 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7208 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7209 + au_dpages_test test, void *arg);
7210 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7211 + int do_include, au_dpages_test test, void *arg);
7212 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7213 + struct dentry *dentry, int do_include);
7214 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7216 +/* ---------------------------------------------------------------------- */
7219 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7220 + * include/linux/dcache.h. Try them (in the future).
7223 +static inline int au_d_hashed_positive(struct dentry *d)
7226 + struct inode *inode = d_inode(d);
7229 + if (unlikely(d_unhashed(d)
7230 + || d_is_negative(d)
7231 + || !inode->i_nlink))
7236 +static inline int au_d_linkable(struct dentry *d)
7239 + struct inode *inode = d_inode(d);
7241 + err = au_d_hashed_positive(d);
7243 + && d_is_positive(d)
7244 + && (inode->i_state & I_LINKABLE))
7249 +static inline int au_d_alive(struct dentry *d)
7252 + struct inode *inode;
7256 + err = au_d_hashed_positive(d);
7258 + inode = d_inode(d);
7259 + if (unlikely(d_unlinked(d)
7260 + || d_is_negative(d)
7261 + || !inode->i_nlink))
7267 +static inline int au_alive_dir(struct dentry *d)
7271 + err = au_d_alive(d);
7272 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7277 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7279 + return a->len == b->len
7280 + && !memcmp(a->name, b->name, a->len);
7285 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7287 + * the type of d_lockref.count became int, but the inlined function d_count()
7288 + * still returns unsigned int.
7289 + * I don't know why. Maybe it is for every d_count() users?
7290 + * Anyway au_dcount() lives on.
7292 +static inline int au_dcount(struct dentry *d)
7294 + return (int)d_count(d);
7297 +#endif /* __KERNEL__ */
7298 +#endif /* __AUFS_DCSUB_H__ */
7299 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7300 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7301 +++ linux/fs/aufs/debug.c 2020-01-27 10:57:18.168871450 +0100
7303 +// SPDX-License-Identifier: GPL-2.0
7305 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7307 + * This program, aufs is free software; you can redistribute it and/or modify
7308 + * it under the terms of the GNU General Public License as published by
7309 + * the Free Software Foundation; either version 2 of the License, or
7310 + * (at your option) any later version.
7312 + * This program is distributed in the hope that it will be useful,
7313 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7314 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7315 + * GNU General Public License for more details.
7317 + * You should have received a copy of the GNU General Public License
7318 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7322 + * debug print functions
7325 +#include <linux/iversion.h>
7328 +/* Returns 0, or -errno. arg is in kp->arg. */
7329 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7333 + err = kstrtoint(val, 0, &n);
7343 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7344 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7349 + return sprintf(buffer, "%d", atomic_read(a));
7352 +static struct kernel_param_ops param_ops_atomic_t = {
7353 + .set = param_atomic_t_set,
7354 + .get = param_atomic_t_get
7355 + /* void (*free)(void *arg) */
7358 +atomic_t aufs_debug = ATOMIC_INIT(0);
7359 +MODULE_PARM_DESC(debug, "debug print");
7360 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7362 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7363 +char *au_plevel = KERN_DEBUG;
7364 +#define dpri(fmt, ...) do { \
7366 + && strcmp(au_plevel, KERN_DEBUG)) \
7367 + || au_debug_test()) \
7368 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7371 +/* ---------------------------------------------------------------------- */
7373 +void au_dpri_whlist(struct au_nhash *whlist)
7375 + unsigned long ul, n;
7376 + struct hlist_head *head;
7377 + struct au_vdir_wh *pos;
7379 + n = whlist->nh_num;
7380 + head = whlist->nh_head;
7381 + for (ul = 0; ul < n; ul++) {
7382 + hlist_for_each_entry(pos, head, wh_hash)
7383 + dpri("b%d, %.*s, %d\n",
7385 + pos->wh_str.len, pos->wh_str.name,
7391 +void au_dpri_vdir(struct au_vdir *vdir)
7394 + union au_vdir_deblk_p p;
7397 + if (!vdir || IS_ERR(vdir)) {
7398 + dpri("err %ld\n", PTR_ERR(vdir));
7402 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7403 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7404 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7405 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7406 + p.deblk = vdir->vd_deblk[ul];
7408 + dpri("[%lu]: %p\n", ul, o);
7412 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7413 + struct dentry *wh)
7418 + if (!inode || IS_ERR(inode)) {
7419 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7423 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7424 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7425 + && sizeof(inode->i_blocks) != sizeof(u64));
7427 + n = (void *)wh->d_name.name;
7428 + l = wh->d_name.len;
7431 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7432 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7434 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7435 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7436 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7437 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7438 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7439 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7440 + inode->i_generation,
7441 + l ? ", wh " : "", l, n);
7445 +void au_dpri_inode(struct inode *inode)
7447 + struct au_iinfo *iinfo;
7448 + struct au_hinode *hi;
7449 + aufs_bindex_t bindex;
7452 + err = do_pri_inode(-1, inode, -1, NULL);
7453 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7456 + iinfo = au_ii(inode);
7457 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7458 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7459 + if (iinfo->ii_btop < 0)
7462 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7463 + hi = au_hinode(iinfo, bindex);
7465 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7469 +void au_dpri_dalias(struct inode *inode)
7473 + spin_lock(&inode->i_lock);
7474 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7475 + au_dpri_dentry(d);
7476 + spin_unlock(&inode->i_lock);
7479 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7481 + struct dentry *wh = NULL;
7483 + struct inode *inode;
7484 + struct au_iinfo *iinfo;
7485 + struct au_hinode *hi;
7487 + if (!dentry || IS_ERR(dentry)) {
7488 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7491 + /* do not call dget_parent() here */
7492 + /* note: access d_xxx without d_lock */
7493 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7494 + bindex, dentry, dentry,
7495 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7496 + au_dcount(dentry), dentry->d_flags,
7497 + d_unhashed(dentry) ? "un" : "");
7500 + if (d_is_positive(dentry))
7501 + inode = d_inode(dentry);
7503 + && au_test_aufs(dentry->d_sb)
7505 + && !au_is_bad_inode(inode)) {
7506 + iinfo = au_ii(inode);
7507 + hi = au_hinode(iinfo, bindex);
7509 + wh = hi->hi_whdentry;
7511 + do_pri_inode(bindex, inode, hn, wh);
7515 +void au_dpri_dentry(struct dentry *dentry)
7517 + struct au_dinfo *dinfo;
7518 + aufs_bindex_t bindex;
7521 + err = do_pri_dentry(-1, dentry);
7522 + if (err || !au_test_aufs(dentry->d_sb))
7525 + dinfo = au_di(dentry);
7528 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7529 + dinfo->di_btop, dinfo->di_bbot,
7530 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7531 + dinfo->di_tmpfile);
7532 + if (dinfo->di_btop < 0)
7534 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7535 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7538 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7542 + if (!file || IS_ERR(file)) {
7543 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7548 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7549 + && au_test_aufs(file->f_path.dentry->d_sb)
7551 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7552 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7553 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7554 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7555 + file->f_version, file->f_pos, a);
7556 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7557 + do_pri_dentry(bindex, file->f_path.dentry);
7561 +void au_dpri_file(struct file *file)
7563 + struct au_finfo *finfo;
7564 + struct au_fidir *fidir;
7565 + struct au_hfile *hfile;
7566 + aufs_bindex_t bindex;
7569 + err = do_pri_file(-1, file);
7571 + || IS_ERR_OR_NULL(file->f_path.dentry)
7572 + || !au_test_aufs(file->f_path.dentry->d_sb))
7575 + finfo = au_fi(file);
7578 + if (finfo->fi_btop < 0)
7580 + fidir = finfo->fi_hdir;
7582 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7584 + for (bindex = finfo->fi_btop;
7585 + bindex >= 0 && bindex <= fidir->fd_bbot;
7587 + hfile = fidir->fd_hfile + bindex;
7588 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7592 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7594 + struct vfsmount *mnt;
7595 + struct super_block *sb;
7597 + if (!br || IS_ERR(br))
7599 + mnt = au_br_mnt(br);
7600 + if (!mnt || IS_ERR(mnt))
7603 + if (!sb || IS_ERR(sb))
7606 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7607 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7609 + bindex, br->br_perm, br->br_id, br->br_wbr,
7610 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7611 + sb->s_flags, sb->s_count,
7612 + atomic_read(&sb->s_active),
7613 + !!au_xino_file(br->br_xino, /*idx*/-1));
7617 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7621 +void au_dpri_sb(struct super_block *sb)
7623 + struct au_sbinfo *sbinfo;
7624 + aufs_bindex_t bindex;
7626 + /* to reduce stack size */
7628 + struct vfsmount mnt;
7629 + struct au_branch fake;
7632 + /* this function can be called from magic sysrq */
7633 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7634 + if (unlikely(!a)) {
7635 + dpri("no memory\n");
7639 + a->mnt.mnt_sb = sb;
7640 + a->fake.br_path.mnt = &a->mnt;
7641 + err = do_pri_br(-1, &a->fake);
7643 + dpri("dev 0x%x\n", sb->s_dev);
7644 + if (err || !au_test_aufs(sb))
7647 + sbinfo = au_sbi(sb);
7650 + dpri("nw %d, gen %u, kobj %d\n",
7651 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7652 + kref_read(&sbinfo->si_kobj.kref));
7653 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7654 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7657 +/* ---------------------------------------------------------------------- */
7659 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7661 + struct inode *h_inode, *inode = d_inode(dentry);
7662 + struct dentry *h_dentry;
7663 + aufs_bindex_t bindex, bbot, bi;
7665 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7668 + bbot = au_dbbot(dentry);
7669 + bi = au_ibbot(inode);
7672 + bindex = au_dbtop(dentry);
7673 + bi = au_ibtop(inode);
7677 + for (; bindex <= bbot; bindex++) {
7678 + h_dentry = au_h_dptr(dentry, bindex);
7681 + h_inode = au_h_iptr(inode, bindex);
7682 + if (unlikely(h_inode != d_inode(h_dentry))) {
7684 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7685 + AuDbgDentry(dentry);
7686 + AuDbgInode(inode);
7693 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7696 + struct au_dcsub_pages dpages;
7697 + struct au_dpage *dpage;
7698 + struct dentry **dentries;
7700 + err = au_dpages_init(&dpages, GFP_NOFS);
7702 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7704 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7705 + dpage = dpages.dpages + i;
7706 + dentries = dpage->dentries;
7707 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7708 + AuDebugOn(au_digen_test(dentries[j], sigen));
7710 + au_dpages_free(&dpages);
7713 +void au_dbg_verify_kthread(void)
7715 + if (au_wkq_test()) {
7718 + * It may be recursive, but udba=notify between two aufs mounts,
7719 + * where a single ro branch is shared, is not a problem.
7725 +/* ---------------------------------------------------------------------- */
7727 +int __init au_debug_init(void)
7729 + aufs_bindex_t bindex;
7730 + struct au_vdir_destr destr;
7733 + AuDebugOn(bindex >= 0);
7736 + AuDebugOn(destr.len < NAME_MAX);
7738 +#ifdef CONFIG_4KSTACKS
7739 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7744 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7745 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7746 +++ linux/fs/aufs/debug.h 2020-01-27 10:57:18.168871450 +0100
7748 +/* SPDX-License-Identifier: GPL-2.0 */
7750 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7752 + * This program, aufs is free software; you can redistribute it and/or modify
7753 + * it under the terms of the GNU General Public License as published by
7754 + * the Free Software Foundation; either version 2 of the License, or
7755 + * (at your option) any later version.
7757 + * This program is distributed in the hope that it will be useful,
7758 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7759 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7760 + * GNU General Public License for more details.
7762 + * You should have received a copy of the GNU General Public License
7763 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7767 + * debug print functions
7770 +#ifndef __AUFS_DEBUG_H__
7771 +#define __AUFS_DEBUG_H__
7775 +#include <linux/atomic.h>
7776 +#include <linux/module.h>
7777 +#include <linux/kallsyms.h>
7778 +#include <linux/sysrq.h>
7780 +#ifdef CONFIG_AUFS_DEBUG
7781 +#define AuDebugOn(a) BUG_ON(a)
7783 +/* module parameter */
7784 +extern atomic_t aufs_debug;
7785 +static inline void au_debug_on(void)
7787 + atomic_inc(&aufs_debug);
7789 +static inline void au_debug_off(void)
7791 + atomic_dec_if_positive(&aufs_debug);
7794 +static inline int au_debug_test(void)
7796 + return atomic_read(&aufs_debug) > 0;
7799 +#define AuDebugOn(a) do {} while (0)
7800 +AuStubVoid(au_debug_on, void)
7801 +AuStubVoid(au_debug_off, void)
7802 +AuStubInt0(au_debug_test, void)
7803 +#endif /* CONFIG_AUFS_DEBUG */
7805 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7807 +/* ---------------------------------------------------------------------- */
7811 +#define AuDbg(fmt, ...) do { \
7812 + if (au_debug_test()) \
7813 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7815 +#define AuLabel(l) AuDbg(#l "\n")
7816 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7817 +#define AuWarn1(fmt, ...) do { \
7818 + static unsigned char _c; \
7820 + pr_warn(fmt, ##__VA_ARGS__); \
7823 +#define AuErr1(fmt, ...) do { \
7824 + static unsigned char _c; \
7826 + pr_err(fmt, ##__VA_ARGS__); \
7829 +#define AuIOErr1(fmt, ...) do { \
7830 + static unsigned char _c; \
7832 + AuIOErr(fmt, ##__VA_ARGS__); \
7835 +#define AuUnsupportMsg "This operation is not supported." \
7836 + " Please report this application to aufs-users ML."
7837 +#define AuUnsupport(fmt, ...) do { \
7838 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7842 +#define AuTraceErr(e) do { \
7843 + if (unlikely((e) < 0)) \
7844 + AuDbg("err %d\n", (int)(e)); \
7847 +#define AuTraceErrPtr(p) do { \
7849 + AuDbg("err %ld\n", PTR_ERR(p)); \
7852 +/* dirty macros for debug print, use with "%.*s" and caution */
7853 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7855 +/* ---------------------------------------------------------------------- */
7858 +#ifdef CONFIG_AUFS_DEBUG
7859 +extern struct mutex au_dbg_mtx;
7860 +extern char *au_plevel;
7862 +void au_dpri_whlist(struct au_nhash *whlist);
7864 +void au_dpri_vdir(struct au_vdir *vdir);
7866 +void au_dpri_inode(struct inode *inode);
7867 +void au_dpri_dalias(struct inode *inode);
7868 +void au_dpri_dentry(struct dentry *dentry);
7870 +void au_dpri_file(struct file *filp);
7871 +struct super_block;
7872 +void au_dpri_sb(struct super_block *sb);
7874 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7875 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7876 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7877 +void au_dbg_verify_kthread(void);
7879 +int __init au_debug_init(void);
7881 +#define AuDbgWhlist(w) do { \
7882 + mutex_lock(&au_dbg_mtx); \
7884 + au_dpri_whlist(w); \
7885 + mutex_unlock(&au_dbg_mtx); \
7888 +#define AuDbgVdir(v) do { \
7889 + mutex_lock(&au_dbg_mtx); \
7891 + au_dpri_vdir(v); \
7892 + mutex_unlock(&au_dbg_mtx); \
7895 +#define AuDbgInode(i) do { \
7896 + mutex_lock(&au_dbg_mtx); \
7898 + au_dpri_inode(i); \
7899 + mutex_unlock(&au_dbg_mtx); \
7902 +#define AuDbgDAlias(i) do { \
7903 + mutex_lock(&au_dbg_mtx); \
7905 + au_dpri_dalias(i); \
7906 + mutex_unlock(&au_dbg_mtx); \
7909 +#define AuDbgDentry(d) do { \
7910 + mutex_lock(&au_dbg_mtx); \
7912 + au_dpri_dentry(d); \
7913 + mutex_unlock(&au_dbg_mtx); \
7916 +#define AuDbgFile(f) do { \
7917 + mutex_lock(&au_dbg_mtx); \
7919 + au_dpri_file(f); \
7920 + mutex_unlock(&au_dbg_mtx); \
7923 +#define AuDbgSb(sb) do { \
7924 + mutex_lock(&au_dbg_mtx); \
7925 + AuDbg(#sb "\n"); \
7927 + mutex_unlock(&au_dbg_mtx); \
7930 +#define AuDbgSym(addr) do { \
7931 + char sym[KSYM_SYMBOL_LEN]; \
7932 + sprint_symbol(sym, (unsigned long)addr); \
7933 + AuDbg("%s\n", sym); \
7936 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7937 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7938 +AuStubVoid(au_dbg_verify_kthread, void)
7939 +AuStubInt0(__init au_debug_init, void)
7941 +#define AuDbgWhlist(w) do {} while (0)
7942 +#define AuDbgVdir(v) do {} while (0)
7943 +#define AuDbgInode(i) do {} while (0)
7944 +#define AuDbgDAlias(i) do {} while (0)
7945 +#define AuDbgDentry(d) do {} while (0)
7946 +#define AuDbgFile(f) do {} while (0)
7947 +#define AuDbgSb(sb) do {} while (0)
7948 +#define AuDbgSym(addr) do {} while (0)
7949 +#endif /* CONFIG_AUFS_DEBUG */
7951 +/* ---------------------------------------------------------------------- */
7953 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7954 +int __init au_sysrq_init(void);
7955 +void au_sysrq_fin(void);
7957 +#ifdef CONFIG_HW_CONSOLE
7958 +#define au_dbg_blocked() do { \
7960 + handle_sysrq('w'); \
7963 +AuStubVoid(au_dbg_blocked, void)
7967 +AuStubInt0(__init au_sysrq_init, void)
7968 +AuStubVoid(au_sysrq_fin, void)
7969 +AuStubVoid(au_dbg_blocked, void)
7970 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7972 +#endif /* __KERNEL__ */
7973 +#endif /* __AUFS_DEBUG_H__ */
7974 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7975 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7976 +++ linux/fs/aufs/dentry.c 2020-01-27 10:57:18.168871450 +0100
7978 +// SPDX-License-Identifier: GPL-2.0
7980 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7982 + * This program, aufs is free software; you can redistribute it and/or modify
7983 + * it under the terms of the GNU General Public License as published by
7984 + * the Free Software Foundation; either version 2 of the License, or
7985 + * (at your option) any later version.
7987 + * This program is distributed in the hope that it will be useful,
7988 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7989 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7990 + * GNU General Public License for more details.
7992 + * You should have received a copy of the GNU General Public License
7993 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7997 + * lookup and dentry operations
8000 +#include <linux/iversion.h>
8001 +#include <linux/namei.h>
8005 + * returns positive/negative dentry, NULL or an error.
8006 + * NULL means whiteout-ed or not-found.
8008 +static struct dentry*
8009 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8010 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8012 + struct dentry *h_dentry;
8013 + struct inode *h_inode;
8014 + struct au_branch *br;
8015 + int wh_found, opq;
8016 + unsigned char wh_able;
8017 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8018 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8022 + br = au_sbr(dentry->d_sb, bindex);
8023 + wh_able = !!au_br_whable(br->br_perm);
8025 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8026 + h_dentry = ERR_PTR(wh_found);
8029 + if (unlikely(wh_found < 0))
8032 + /* We found a whiteout */
8033 + /* au_set_dbbot(dentry, bindex); */
8034 + au_set_dbwh(dentry, bindex);
8036 + return NULL; /* success */
8040 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8042 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8043 + if (IS_ERR(h_dentry)) {
8044 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8050 + h_inode = d_inode(h_dentry);
8051 + if (d_is_negative(h_dentry)) {
8054 + } else if (wh_found
8055 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8057 + else if (au_ftest_lkup(args->flags, DIRREN)
8059 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8060 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8061 + (unsigned long long)h_inode->i_ino);
8065 + if (au_dbbot(dentry) <= bindex)
8066 + au_set_dbbot(dentry, bindex);
8067 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8068 + au_set_dbtop(dentry, bindex);
8069 + au_set_h_dptr(dentry, bindex, h_dentry);
8071 + if (!d_is_dir(h_dentry)
8073 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8074 + goto out; /* success */
8076 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8077 + opq = au_diropq_test(h_dentry);
8078 + inode_unlock_shared(h_inode);
8080 + au_set_dbdiropq(dentry, bindex);
8081 + else if (unlikely(opq < 0)) {
8082 + au_set_h_dptr(dentry, bindex, NULL);
8083 + h_dentry = ERR_PTR(opq);
8094 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8096 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8097 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8103 + * returns the number of lower positive dentries,
8104 + * otherwise an error.
8105 + * can be called at unlinking with @type is zero.
8107 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8108 + unsigned int flags)
8110 + int npositive, err;
8111 + aufs_bindex_t bindex, btail, bdiropq;
8112 + unsigned char isdir, dirperm1, dirren;
8113 + struct au_do_lookup_args args = {
8115 + .name = &dentry->d_name
8117 + struct dentry *parent;
8118 + struct super_block *sb;
8120 + sb = dentry->d_sb;
8121 + err = au_test_shwh(sb, args.name);
8122 + if (unlikely(err))
8125 + err = au_wh_name_alloc(&args.whname, args.name);
8126 + if (unlikely(err))
8129 + isdir = !!d_is_dir(dentry);
8130 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8131 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8133 + au_fset_lkup(args.flags, DIRREN);
8136 + parent = dget_parent(dentry);
8137 + btail = au_dbtaildir(parent);
8138 + for (bindex = btop; bindex <= btail; bindex++) {
8139 + struct dentry *h_parent, *h_dentry;
8140 + struct inode *h_inode, *h_dir;
8141 + struct au_branch *br;
8143 + h_dentry = au_h_dptr(dentry, bindex);
8145 + if (d_is_positive(h_dentry))
8149 + h_parent = au_h_dptr(parent, bindex);
8150 + if (!h_parent || !d_is_dir(h_parent))
8154 + /* if the inum matches, then use the prepared name */
8155 + err = au_dr_lkup_name(&args, bindex);
8156 + if (unlikely(err))
8160 + h_dir = d_inode(h_parent);
8161 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8162 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8163 + inode_unlock_shared(h_dir);
8164 + err = PTR_ERR(h_dentry);
8165 + if (IS_ERR(h_dentry))
8168 + au_fclr_lkup(args.flags, ALLOW_NEG);
8170 + au_fset_lkup(args.flags, IGNORE_PERM);
8172 + if (au_dbwh(dentry) == bindex)
8176 + if (d_is_negative(h_dentry))
8178 + h_inode = d_inode(h_dentry);
8181 + args.type = h_inode->i_mode & S_IFMT;
8182 + if (args.type != S_IFDIR)
8185 + /* the type of lower may be different */
8186 + bdiropq = au_dbdiropq(dentry);
8187 + if (bdiropq >= 0 && bdiropq <= bindex)
8190 + br = au_sbr(sb, bindex);
8192 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8193 + /*add_ent*/NULL)) {
8194 + /* prepare next name to lookup */
8195 + err = au_dr_lkup(&args, dentry, bindex);
8196 + if (unlikely(err))
8202 + AuLabel(positive);
8203 + au_update_dbtop(dentry);
8206 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8207 + && au_dbtop(dentry) < 0)) {
8209 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8215 + au_kfree_try_rcu(args.whname.name);
8217 + au_dr_lkup_fin(&args);
8222 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8224 + struct dentry *dentry;
8227 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8228 + dentry = vfsub_lkup_one(name, parent);
8230 + struct vfsub_lkup_one_args args = {
8236 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8237 + if (unlikely(wkq_err))
8238 + dentry = ERR_PTR(wkq_err);
8245 + * lookup @dentry on @bindex which should be negative.
8247 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8250 + struct dentry *parent, *h_parent, *h_dentry;
8251 + struct au_branch *br;
8253 + parent = dget_parent(dentry);
8254 + h_parent = au_h_dptr(parent, bindex);
8255 + br = au_sbr(dentry->d_sb, bindex);
8257 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8259 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8260 + err = PTR_ERR(h_dentry);
8261 + if (IS_ERR(h_dentry))
8263 + if (unlikely(d_is_positive(h_dentry))) {
8265 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8271 + if (bindex < au_dbtop(dentry))
8272 + au_set_dbtop(dentry, bindex);
8273 + if (au_dbbot(dentry) < bindex)
8274 + au_set_dbbot(dentry, bindex);
8275 + au_set_h_dptr(dentry, bindex, h_dentry);
8282 +/* ---------------------------------------------------------------------- */
8284 +/* subset of struct inode */
8286 + unsigned long i_ino;
8287 + /* unsigned int i_nlink; */
8293 + blkcnt_t i_blocks;
8298 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8300 + ia->i_ino = h_inode->i_ino;
8301 + /* ia->i_nlink = h_inode->i_nlink; */
8302 + ia->i_uid = h_inode->i_uid;
8303 + ia->i_gid = h_inode->i_gid;
8304 + ia->i_version = inode_query_iversion(h_inode);
8306 + ia->i_size = h_inode->i_size;
8307 + ia->i_blocks = h_inode->i_blocks;
8309 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8312 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8314 + return ia->i_ino != h_inode->i_ino
8315 + /* || ia->i_nlink != h_inode->i_nlink */
8316 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8317 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8318 + || !inode_eq_iversion(h_inode, ia->i_version)
8320 + || ia->i_size != h_inode->i_size
8321 + || ia->i_blocks != h_inode->i_blocks
8323 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8326 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8327 + struct au_branch *br)
8330 + struct au_iattr ia;
8331 + struct inode *h_inode;
8332 + struct dentry *h_d;
8333 + struct super_block *h_sb;
8336 + memset(&ia, -1, sizeof(ia));
8337 + h_sb = h_dentry->d_sb;
8339 + if (d_is_positive(h_dentry)) {
8340 + h_inode = d_inode(h_dentry);
8341 + au_iattr_save(&ia, h_inode);
8342 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8343 + /* nfs d_revalidate may return 0 for negative dentry */
8344 + /* fuse d_revalidate always return 0 for negative dentry */
8347 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8348 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8349 + err = PTR_ERR(h_d);
8354 + if (unlikely(h_d != h_dentry
8355 + || d_inode(h_d) != h_inode
8356 + || (h_inode && au_iattr_test(&ia, h_inode))))
8357 + err = au_busy_or_stale();
8365 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8366 + struct dentry *h_parent, struct au_branch *br)
8371 + if (udba == AuOpt_UDBA_REVAL
8372 + && !au_test_fs_remote(h_dentry->d_sb)) {
8374 + err = (d_inode(h_dentry->d_parent) != h_dir);
8375 + } else if (udba != AuOpt_UDBA_NONE)
8376 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8381 +/* ---------------------------------------------------------------------- */
8383 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8386 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8387 + struct au_hdentry tmp, *p, *q;
8388 + struct au_dinfo *dinfo;
8389 + struct super_block *sb;
8391 + DiMustWriteLock(dentry);
8393 + sb = dentry->d_sb;
8394 + dinfo = au_di(dentry);
8395 + bbot = dinfo->di_bbot;
8396 + bwh = dinfo->di_bwh;
8397 + bdiropq = dinfo->di_bdiropq;
8398 + bindex = dinfo->di_btop;
8399 + p = au_hdentry(dinfo, bindex);
8400 + for (; bindex <= bbot; bindex++, p++) {
8401 + if (!p->hd_dentry)
8404 + new_bindex = au_br_index(sb, p->hd_id);
8405 + if (new_bindex == bindex)
8408 + if (dinfo->di_bwh == bindex)
8410 + if (dinfo->di_bdiropq == bindex)
8411 + bdiropq = new_bindex;
8412 + if (new_bindex < 0) {
8414 + p->hd_dentry = NULL;
8418 + /* swap two lower dentries, and loop again */
8419 + q = au_hdentry(dinfo, new_bindex);
8423 + if (tmp.hd_dentry) {
8429 + dinfo->di_bwh = -1;
8430 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8431 + dinfo->di_bwh = bwh;
8433 + dinfo->di_bdiropq = -1;
8435 + && bdiropq <= au_sbbot(sb)
8436 + && au_sbr_whable(sb, bdiropq))
8437 + dinfo->di_bdiropq = bdiropq;
8440 + dinfo->di_btop = -1;
8441 + dinfo->di_bbot = -1;
8442 + bbot = au_dbbot(parent);
8444 + p = au_hdentry(dinfo, bindex);
8445 + for (; bindex <= bbot; bindex++, p++)
8446 + if (p->hd_dentry) {
8447 + dinfo->di_btop = bindex;
8451 + if (dinfo->di_btop >= 0) {
8453 + p = au_hdentry(dinfo, bindex);
8454 + for (; bindex >= 0; bindex--, p--)
8455 + if (p->hd_dentry) {
8456 + dinfo->di_bbot = bindex;
8465 +static void au_do_hide(struct dentry *dentry)
8467 + struct inode *inode;
8469 + if (d_really_is_positive(dentry)) {
8470 + inode = d_inode(dentry);
8471 + if (!d_is_dir(dentry)) {
8472 + if (inode->i_nlink && !d_unhashed(dentry))
8473 + drop_nlink(inode);
8475 + clear_nlink(inode);
8476 + /* stop next lookup */
8477 + inode->i_flags |= S_DEAD;
8479 + smp_mb(); /* necessary? */
8484 +static int au_hide_children(struct dentry *parent)
8486 + int err, i, j, ndentry;
8487 + struct au_dcsub_pages dpages;
8488 + struct au_dpage *dpage;
8489 + struct dentry *dentry;
8491 + err = au_dpages_init(&dpages, GFP_NOFS);
8492 + if (unlikely(err))
8494 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8495 + if (unlikely(err))
8498 + /* in reverse order */
8499 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8500 + dpage = dpages.dpages + i;
8501 + ndentry = dpage->ndentry;
8502 + for (j = ndentry - 1; j >= 0; j--) {
8503 + dentry = dpage->dentries[j];
8504 + if (dentry != parent)
8505 + au_do_hide(dentry);
8510 + au_dpages_free(&dpages);
8515 +static void au_hide(struct dentry *dentry)
8519 + AuDbgDentry(dentry);
8520 + if (d_is_dir(dentry)) {
8521 + /* shrink_dcache_parent(dentry); */
8522 + err = au_hide_children(dentry);
8523 + if (unlikely(err))
8524 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8527 + au_do_hide(dentry);
8531 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8533 + * a dirty branch is added
8534 + * - on the top of layers
8535 + * - in the middle of layers
8536 + * - to the bottom of layers
8538 + * on the added branch there exists
8541 + * - a same named entry
8543 + * * negative --> positive
8544 + * * positive --> positive
8545 + * - type is unchanged
8546 + * - type is changed
8548 + * * negative --> negative
8549 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8552 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8553 + struct au_dinfo *tmp)
8556 + aufs_bindex_t bindex, bbot;
8558 + struct dentry *dentry;
8559 + struct inode *inode;
8561 + } orig_h, tmp_h = {
8564 + struct au_hdentry *hd;
8565 + struct inode *inode, *h_inode;
8566 + struct dentry *h_dentry;
8569 + AuDebugOn(dinfo->di_btop < 0);
8571 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8572 + orig_h.inode = NULL;
8573 + if (d_is_positive(orig_h.dentry)) {
8574 + orig_h.inode = d_inode(orig_h.dentry);
8575 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8577 + if (tmp->di_btop >= 0) {
8578 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8579 + if (d_is_positive(tmp_h.dentry)) {
8580 + tmp_h.inode = d_inode(tmp_h.dentry);
8581 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8586 + if (d_really_is_positive(dentry))
8587 + inode = d_inode(dentry);
8588 + if (!orig_h.inode) {
8589 + AuDbg("negative originally\n");
8595 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8596 + AuDebugOn(dinfo->di_bdiropq != -1);
8598 + if (!tmp_h.inode) {
8599 + AuDbg("negative --> negative\n");
8600 + /* should have only one negative lower */
8601 + if (tmp->di_btop >= 0
8602 + && tmp->di_btop < dinfo->di_btop) {
8603 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8604 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8605 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8606 + au_di_cp(dinfo, tmp);
8607 + hd = au_hdentry(tmp, tmp->di_btop);
8608 + au_set_h_dptr(dentry, tmp->di_btop,
8609 + dget(hd->hd_dentry));
8611 + au_dbg_verify_dinode(dentry);
8613 + AuDbg("negative --> positive\n");
8615 + * similar to the behaviour of creating with bypassing
8617 + * unhash it in order to force an error in the
8618 + * succeeding create operation.
8619 + * we should not set S_DEAD here.
8622 + /* au_di_swap(tmp, dinfo); */
8623 + au_dbg_verify_dinode(dentry);
8626 + AuDbg("positive originally\n");
8627 + /* inode may be NULL */
8628 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8629 + if (!tmp_h.inode) {
8630 + AuDbg("positive --> negative\n");
8631 + /* or bypassing aufs */
8633 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8634 + dinfo->di_bwh = tmp->di_bwh;
8636 + err = au_refresh_hinode_self(inode);
8637 + au_dbg_verify_dinode(dentry);
8638 + } else if (orig_h.mode == tmp_h.mode) {
8639 + AuDbg("positive --> positive, same type\n");
8640 + if (!S_ISDIR(orig_h.mode)
8641 + && dinfo->di_btop > tmp->di_btop) {
8643 + * similar to the behaviour of removing and
8648 + err = au_refresh_hinode_self(inode);
8649 + au_dbg_verify_dinode(dentry);
8651 + /* fill empty slots */
8652 + if (dinfo->di_btop > tmp->di_btop)
8653 + dinfo->di_btop = tmp->di_btop;
8654 + if (dinfo->di_bbot < tmp->di_bbot)
8655 + dinfo->di_bbot = tmp->di_bbot;
8656 + dinfo->di_bwh = tmp->di_bwh;
8657 + dinfo->di_bdiropq = tmp->di_bdiropq;
8658 + bbot = dinfo->di_bbot;
8659 + bindex = tmp->di_btop;
8660 + hd = au_hdentry(tmp, bindex);
8661 + for (; bindex <= bbot; bindex++, hd++) {
8662 + if (au_h_dptr(dentry, bindex))
8664 + h_dentry = hd->hd_dentry;
8667 + AuDebugOn(d_is_negative(h_dentry));
8668 + h_inode = d_inode(h_dentry);
8669 + AuDebugOn(orig_h.mode
8670 + != (h_inode->i_mode
8672 + au_set_h_dptr(dentry, bindex,
8676 + err = au_refresh_hinode(inode, dentry);
8677 + au_dbg_verify_dinode(dentry);
8680 + AuDbg("positive --> positive, different type\n");
8681 + /* similar to the behaviour of removing and creating */
8684 + err = au_refresh_hinode_self(inode);
8685 + au_dbg_verify_dinode(dentry);
8693 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8695 + const struct dentry_operations *dop
8696 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8697 + static const unsigned int mask
8698 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8700 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8702 + if (dentry->d_op == dop)
8705 + AuDbg("%pd\n", dentry);
8706 + spin_lock(&dentry->d_lock);
8707 + if (dop == &aufs_dop)
8708 + dentry->d_flags |= mask;
8710 + dentry->d_flags &= ~mask;
8711 + dentry->d_op = dop;
8712 + spin_unlock(&dentry->d_lock);
8715 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8717 + int err, ebrange, nbr;
8718 + unsigned int sigen;
8719 + struct au_dinfo *dinfo, *tmp;
8720 + struct super_block *sb;
8721 + struct inode *inode;
8723 + DiMustWriteLock(dentry);
8724 + AuDebugOn(IS_ROOT(dentry));
8725 + AuDebugOn(d_really_is_negative(parent));
8727 + sb = dentry->d_sb;
8728 + sigen = au_sigen(sb);
8729 + err = au_digen_test(parent, sigen);
8730 + if (unlikely(err))
8733 + nbr = au_sbbot(sb) + 1;
8734 + dinfo = au_di(dentry);
8735 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8736 + if (unlikely(err))
8738 + ebrange = au_dbrange_test(dentry);
8740 + ebrange = au_do_refresh_hdentry(dentry, parent);
8742 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8743 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8744 + if (d_really_is_positive(dentry)) {
8745 + inode = d_inode(dentry);
8746 + err = au_refresh_hinode_self(inode);
8748 + au_dbg_verify_dinode(dentry);
8750 + goto out_dgen; /* success */
8754 + /* temporary dinfo */
8755 + AuDbgDentry(dentry);
8757 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8758 + if (unlikely(!tmp))
8760 + au_di_swap(tmp, dinfo);
8761 + /* returns the number of positive dentries */
8763 + * if current working dir is removed, it returns an error.
8764 + * but the dentry is legal.
8766 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8767 + AuDbgDentry(dentry);
8768 + au_di_swap(tmp, dinfo);
8769 + if (err == -ENOENT)
8772 + /* compare/refresh by dinfo */
8773 + AuDbgDentry(dentry);
8774 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8775 + au_dbg_verify_dinode(dentry);
8778 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8779 + au_rw_write_unlock(&tmp->di_rwsem);
8781 + if (unlikely(err))
8785 + au_update_digen(dentry);
8787 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8788 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8789 + AuDbgDentry(dentry);
8795 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8796 + struct dentry *dentry, aufs_bindex_t bindex)
8801 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8804 + AuDbg("b%d\n", bindex);
8806 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8807 + * due to whiteout and branch permission.
8809 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8810 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8811 + /* it may return tri-state */
8812 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8814 + if (unlikely(valid < 0))
8824 +/* todo: remove this */
8825 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8826 + unsigned int flags, int do_udba, int dirren)
8829 + umode_t mode, h_mode;
8830 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8831 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8832 + struct inode *h_inode, *h_cached_inode;
8833 + struct dentry *h_dentry;
8834 + struct qstr *name, *h_name;
8841 + unhashed = !!d_unhashed(dentry);
8842 + is_root = !!IS_ROOT(dentry);
8843 + name = &dentry->d_name;
8844 + tmpfile = au_di(dentry)->di_tmpfile;
8847 + * Theoretically, REVAL test should be unnecessary in case of
8849 + * But {fs,i}notify doesn't fire some necessary events,
8850 + * IN_ATTRIB for atime/nlink/pageio
8851 + * Let's do REVAL test too.
8853 + if (do_udba && inode) {
8854 + mode = (inode->i_mode & S_IFMT);
8855 + plus = (inode->i_nlink > 0);
8856 + ibs = au_ibtop(inode);
8857 + ibe = au_ibbot(inode);
8860 + btop = au_dbtop(dentry);
8862 + if (inode && S_ISDIR(inode->i_mode))
8863 + btail = au_dbtaildir(dentry);
8864 + for (bindex = btop; bindex <= btail; bindex++) {
8865 + h_dentry = au_h_dptr(dentry, bindex);
8869 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8870 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8871 + spin_lock(&h_dentry->d_lock);
8872 + h_name = &h_dentry->d_name;
8873 + if (unlikely(do_udba
8876 + && (unhashed != !!d_unhashed(h_dentry)
8877 + || (!tmpfile && !dirren
8878 + && !au_qstreq(name, h_name))
8881 + && !(flags & LOOKUP_OPEN)
8882 + && (h_dentry->d_flags
8883 + & DCACHE_NFSFS_RENAMED)))
8887 + h_unhashed = d_unhashed(h_dentry);
8888 + spin_unlock(&h_dentry->d_lock);
8889 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8890 + unhashed, h_unhashed, dentry, h_dentry);
8893 + spin_unlock(&h_dentry->d_lock);
8895 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8896 + if (unlikely(err))
8897 + /* do not goto err, to keep the errno */
8900 + /* todo: plink too? */
8905 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8909 + if (d_is_positive(h_dentry))
8910 + h_inode = d_inode(h_dentry);
8913 + h_cached_inode = h_inode;
8915 + h_mode = (h_inode->i_mode & S_IFMT);
8916 + h_plus = (h_inode->i_nlink > 0);
8918 + if (inode && ibs <= bindex && bindex <= ibe)
8919 + h_cached_inode = au_h_iptr(inode, bindex);
8922 + if (unlikely(plus != h_plus && !tmpfile))
8925 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8927 + && !IS_ROOT(h_dentry)
8928 + && unhashed != d_unhashed(h_dentry)))
8931 + if (unlikely(mode != h_mode
8932 + || h_cached_inode != h_inode))
8945 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8946 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8949 + struct dentry *parent;
8951 + if (!au_digen_test(dentry, sigen))
8954 + parent = dget_parent(dentry);
8955 + di_read_lock_parent(parent, AuLock_IR);
8956 + AuDebugOn(au_digen_test(parent, sigen));
8957 + au_dbg_verify_gen(parent, sigen);
8958 + err = au_refresh_dentry(dentry, parent);
8959 + di_read_unlock(parent, AuLock_IR);
8965 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8968 + struct dentry *d, *parent;
8970 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8971 + return simple_reval_dpath(dentry, sigen);
8973 + /* slow loop, keep it simple and stupid */
8974 + /* cf: au_cpup_dirs() */
8977 + while (au_digen_test(dentry, sigen)) {
8981 + parent = dget_parent(d);
8982 + if (!au_digen_test(parent, sigen))
8988 + di_write_lock_child2(d);
8990 + /* someone might update our dentry while we were sleeping */
8991 + if (au_digen_test(d, sigen)) {
8993 + * todo: consolidate with simple_reval_dpath(),
8994 + * do_refresh() and au_reval_for_attr().
8996 + di_read_lock_parent(parent, AuLock_IR);
8997 + err = au_refresh_dentry(d, parent);
8998 + di_read_unlock(parent, AuLock_IR);
9002 + di_write_unlock(d);
9004 + if (unlikely(err))
9012 + * if valid returns 1, otherwise 0.
9014 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9017 + unsigned int sigen;
9018 + unsigned char do_udba, dirren;
9019 + struct super_block *sb;
9020 + struct inode *inode;
9022 + /* todo: support rcu-walk? */
9023 + if (flags & LOOKUP_RCU)
9027 + if (unlikely(!au_di(dentry)))
9031 + sb = dentry->d_sb;
9034 + * i_mutex of parent dir may be held,
9035 + * but we should not return 'invalid' due to busy.
9037 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9038 + if (unlikely(err)) {
9044 + if (d_really_is_positive(dentry))
9045 + inode = d_inode(dentry);
9046 + if (unlikely(inode && au_is_bad_inode(inode))) {
9051 + if (unlikely(au_dbrange_test(dentry))) {
9057 + sigen = au_sigen(sb);
9058 + if (au_digen_test(dentry, sigen)) {
9059 + AuDebugOn(IS_ROOT(dentry));
9060 + err = au_reval_dpath(dentry, sigen);
9061 + if (unlikely(err)) {
9066 + di_downgrade_lock(dentry, AuLock_IR);
9069 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9071 + && !(inode->i_state && I_LINKABLE)
9072 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9077 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9078 + if (do_udba && inode) {
9079 + aufs_bindex_t btop = au_ibtop(inode);
9080 + struct inode *h_inode;
9083 + h_inode = au_h_iptr(inode, btop);
9084 + if (h_inode && au_test_higen(inode, h_inode)) {
9091 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9092 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9093 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9095 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9101 + di_downgrade_lock(dentry, AuLock_IR);
9103 + aufs_read_unlock(dentry, AuLock_IR);
9108 + AuDbg("%pd invalid, %d\n", dentry, valid);
9114 +static void aufs_d_release(struct dentry *dentry)
9116 + if (au_di(dentry)) {
9117 + au_di_fin(dentry);
9118 + au_hn_di_reinit(dentry);
9122 +const struct dentry_operations aufs_dop = {
9123 + .d_revalidate = aufs_d_revalidate,
9124 + .d_weak_revalidate = aufs_d_revalidate,
9125 + .d_release = aufs_d_release
9128 +/* aufs_dop without d_revalidate */
9129 +const struct dentry_operations aufs_dop_noreval = {
9130 + .d_release = aufs_d_release
9132 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9133 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9134 +++ linux/fs/aufs/dentry.h 2020-01-27 10:57:18.168871450 +0100
9136 +/* SPDX-License-Identifier: GPL-2.0 */
9138 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9140 + * This program, aufs is free software; you can redistribute it and/or modify
9141 + * it under the terms of the GNU General Public License as published by
9142 + * the Free Software Foundation; either version 2 of the License, or
9143 + * (at your option) any later version.
9145 + * This program is distributed in the hope that it will be useful,
9146 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9147 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9148 + * GNU General Public License for more details.
9150 + * You should have received a copy of the GNU General Public License
9151 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9155 + * lookup and dentry operations
9158 +#ifndef __AUFS_DENTRY_H__
9159 +#define __AUFS_DENTRY_H__
9163 +#include <linux/dcache.h>
9164 +#include "dirren.h"
9167 +struct au_hdentry {
9168 + struct dentry *hd_dentry;
9169 + aufs_bindex_t hd_id;
9173 + atomic_t di_generation;
9175 + struct au_rwsem di_rwsem;
9176 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9177 + unsigned char di_tmpfile; /* to allow the different name */
9178 + struct au_hdentry *di_hdentry;
9179 + struct rcu_head rcu;
9180 +} ____cacheline_aligned_in_smp;
9182 +/* ---------------------------------------------------------------------- */
9184 +/* flags for au_lkup_dentry() */
9185 +#define AuLkup_ALLOW_NEG 1
9186 +#define AuLkup_IGNORE_PERM (1 << 1)
9187 +#define AuLkup_DIRREN (1 << 2)
9188 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9189 +#define au_fset_lkup(flags, name) \
9190 + do { (flags) |= AuLkup_##name; } while (0)
9191 +#define au_fclr_lkup(flags, name) \
9192 + do { (flags) &= ~AuLkup_##name; } while (0)
9194 +#ifndef CONFIG_AUFS_DIRREN
9195 +#undef AuLkup_DIRREN
9196 +#define AuLkup_DIRREN 0
9199 +struct au_do_lookup_args {
9200 + unsigned int flags;
9202 + struct qstr whname, *name;
9203 + struct au_dr_lookup dirren;
9206 +/* ---------------------------------------------------------------------- */
9209 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9211 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9212 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9213 + struct dentry *h_parent, struct au_branch *br);
9215 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9216 + unsigned int flags);
9217 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9218 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9219 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9220 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9223 +void au_di_init_once(void *_di);
9224 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9225 +void au_di_free(struct au_dinfo *dinfo);
9226 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9227 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9228 +int au_di_init(struct dentry *dentry);
9229 +void au_di_fin(struct dentry *dentry);
9230 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9232 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9233 +void di_read_unlock(struct dentry *d, int flags);
9234 +void di_downgrade_lock(struct dentry *d, int flags);
9235 +void di_write_lock(struct dentry *d, unsigned int lsc);
9236 +void di_write_unlock(struct dentry *d);
9237 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9238 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9239 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9241 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9242 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9243 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9244 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9246 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9247 + struct dentry *h_dentry);
9248 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9249 +int au_dbrange_test(struct dentry *dentry);
9250 +void au_update_digen(struct dentry *dentry);
9251 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9252 +void au_update_dbtop(struct dentry *dentry);
9253 +void au_update_dbbot(struct dentry *dentry);
9254 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9256 +/* ---------------------------------------------------------------------- */
9258 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9260 + return dentry->d_fsdata;
9263 +/* ---------------------------------------------------------------------- */
9265 +/* lock subclass for dinfo */
9267 + AuLsc_DI_CHILD, /* child first */
9268 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9269 + AuLsc_DI_CHILD3, /* copyup dirs */
9273 + AuLsc_DI_TMP /* temp for replacing dinfo */
9277 + * di_read_lock_child, di_write_lock_child,
9278 + * di_read_lock_child2, di_write_lock_child2,
9279 + * di_read_lock_child3, di_write_lock_child3,
9280 + * di_read_lock_parent, di_write_lock_parent,
9281 + * di_read_lock_parent2, di_write_lock_parent2,
9282 + * di_read_lock_parent3, di_write_lock_parent3,
9284 +#define AuReadLockFunc(name, lsc) \
9285 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9286 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9288 +#define AuWriteLockFunc(name, lsc) \
9289 +static inline void di_write_lock_##name(struct dentry *d) \
9290 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9292 +#define AuRWLockFuncs(name, lsc) \
9293 + AuReadLockFunc(name, lsc) \
9294 + AuWriteLockFunc(name, lsc)
9296 +AuRWLockFuncs(child, CHILD);
9297 +AuRWLockFuncs(child2, CHILD2);
9298 +AuRWLockFuncs(child3, CHILD3);
9299 +AuRWLockFuncs(parent, PARENT);
9300 +AuRWLockFuncs(parent2, PARENT2);
9301 +AuRWLockFuncs(parent3, PARENT3);
9303 +#undef AuReadLockFunc
9304 +#undef AuWriteLockFunc
9305 +#undef AuRWLockFuncs
9307 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9308 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9309 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9311 +/* ---------------------------------------------------------------------- */
9313 +/* todo: memory barrier? */
9314 +static inline unsigned int au_digen(struct dentry *d)
9316 + return atomic_read(&au_di(d)->di_generation);
9319 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9321 + hdentry->hd_dentry = NULL;
9324 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9325 + aufs_bindex_t bindex)
9327 + return di->di_hdentry + bindex;
9330 +static inline void au_hdput(struct au_hdentry *hd)
9333 + dput(hd->hd_dentry);
9336 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9338 + DiMustAnyLock(dentry);
9339 + return au_di(dentry)->di_btop;
9342 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9344 + DiMustAnyLock(dentry);
9345 + return au_di(dentry)->di_bbot;
9348 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9350 + DiMustAnyLock(dentry);
9351 + return au_di(dentry)->di_bwh;
9354 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9356 + DiMustAnyLock(dentry);
9357 + return au_di(dentry)->di_bdiropq;
9360 +/* todo: hard/soft set? */
9361 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9363 + DiMustWriteLock(dentry);
9364 + au_di(dentry)->di_btop = bindex;
9367 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9369 + DiMustWriteLock(dentry);
9370 + au_di(dentry)->di_bbot = bindex;
9373 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9375 + DiMustWriteLock(dentry);
9376 + /* dbwh can be outside of btop - bbot range */
9377 + au_di(dentry)->di_bwh = bindex;
9380 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9382 + DiMustWriteLock(dentry);
9383 + au_di(dentry)->di_bdiropq = bindex;
9386 +/* ---------------------------------------------------------------------- */
9388 +#ifdef CONFIG_AUFS_HNOTIFY
9389 +static inline void au_digen_dec(struct dentry *d)
9391 + atomic_dec(&au_di(d)->di_generation);
9394 +static inline void au_hn_di_reinit(struct dentry *dentry)
9396 + dentry->d_fsdata = NULL;
9399 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9400 +#endif /* CONFIG_AUFS_HNOTIFY */
9402 +#endif /* __KERNEL__ */
9403 +#endif /* __AUFS_DENTRY_H__ */
9404 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9405 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9406 +++ linux/fs/aufs/dinfo.c 2020-01-27 10:57:18.168871450 +0100
9408 +// SPDX-License-Identifier: GPL-2.0
9410 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9412 + * This program, aufs is free software; you can redistribute it and/or modify
9413 + * it under the terms of the GNU General Public License as published by
9414 + * the Free Software Foundation; either version 2 of the License, or
9415 + * (at your option) any later version.
9417 + * This program is distributed in the hope that it will be useful,
9418 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9419 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9420 + * GNU General Public License for more details.
9422 + * You should have received a copy of the GNU General Public License
9423 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9427 + * dentry private data
9432 +void au_di_init_once(void *_dinfo)
9434 + struct au_dinfo *dinfo = _dinfo;
9436 + au_rw_init(&dinfo->di_rwsem);
9439 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9441 + struct au_dinfo *dinfo;
9444 + dinfo = au_cache_alloc_dinfo();
9445 + if (unlikely(!dinfo))
9448 + nbr = au_sbbot(sb) + 1;
9451 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9452 + if (dinfo->di_hdentry) {
9453 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9454 + dinfo->di_btop = -1;
9455 + dinfo->di_bbot = -1;
9456 + dinfo->di_bwh = -1;
9457 + dinfo->di_bdiropq = -1;
9458 + dinfo->di_tmpfile = 0;
9459 + for (i = 0; i < nbr; i++)
9460 + dinfo->di_hdentry[i].hd_id = -1;
9464 + au_cache_free_dinfo(dinfo);
9471 +void au_di_free(struct au_dinfo *dinfo)
9473 + struct au_hdentry *p;
9474 + aufs_bindex_t bbot, bindex;
9476 + /* dentry may not be revalidated */
9477 + bindex = dinfo->di_btop;
9478 + if (bindex >= 0) {
9479 + bbot = dinfo->di_bbot;
9480 + p = au_hdentry(dinfo, bindex);
9481 + while (bindex++ <= bbot)
9484 + au_kfree_try_rcu(dinfo->di_hdentry);
9485 + au_cache_free_dinfo(dinfo);
9488 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9490 + struct au_hdentry *p;
9493 + AuRwMustWriteLock(&a->di_rwsem);
9494 + AuRwMustWriteLock(&b->di_rwsem);
9496 +#define DiSwap(v, name) \
9498 + v = a->di_##name; \
9499 + a->di_##name = b->di_##name; \
9500 + b->di_##name = v; \
9503 + DiSwap(p, hdentry);
9507 + DiSwap(bi, bdiropq);
9513 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9515 + AuRwMustWriteLock(&dst->di_rwsem);
9516 + AuRwMustWriteLock(&src->di_rwsem);
9518 + dst->di_btop = src->di_btop;
9519 + dst->di_bbot = src->di_bbot;
9520 + dst->di_bwh = src->di_bwh;
9521 + dst->di_bdiropq = src->di_bdiropq;
9525 +int au_di_init(struct dentry *dentry)
9528 + struct super_block *sb;
9529 + struct au_dinfo *dinfo;
9532 + sb = dentry->d_sb;
9533 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9535 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9536 + /* smp_mb(); */ /* atomic_set */
9537 + dentry->d_fsdata = dinfo;
9544 +void au_di_fin(struct dentry *dentry)
9546 + struct au_dinfo *dinfo;
9548 + dinfo = au_di(dentry);
9549 + AuRwDestroy(&dinfo->di_rwsem);
9550 + au_di_free(dinfo);
9553 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9556 + struct au_hdentry *hdp;
9558 + AuRwMustWriteLock(&dinfo->di_rwsem);
9561 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9563 + sz = sizeof(*hdp);
9564 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9567 + dinfo->di_hdentry = hdp;
9574 +/* ---------------------------------------------------------------------- */
9576 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9579 + case AuLsc_DI_CHILD:
9580 + ii_write_lock_child(inode);
9582 + case AuLsc_DI_CHILD2:
9583 + ii_write_lock_child2(inode);
9585 + case AuLsc_DI_CHILD3:
9586 + ii_write_lock_child3(inode);
9588 + case AuLsc_DI_PARENT:
9589 + ii_write_lock_parent(inode);
9591 + case AuLsc_DI_PARENT2:
9592 + ii_write_lock_parent2(inode);
9594 + case AuLsc_DI_PARENT3:
9595 + ii_write_lock_parent3(inode);
9602 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9605 + case AuLsc_DI_CHILD:
9606 + ii_read_lock_child(inode);
9608 + case AuLsc_DI_CHILD2:
9609 + ii_read_lock_child2(inode);
9611 + case AuLsc_DI_CHILD3:
9612 + ii_read_lock_child3(inode);
9614 + case AuLsc_DI_PARENT:
9615 + ii_read_lock_parent(inode);
9617 + case AuLsc_DI_PARENT2:
9618 + ii_read_lock_parent2(inode);
9620 + case AuLsc_DI_PARENT3:
9621 + ii_read_lock_parent3(inode);
9628 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9630 + struct inode *inode;
9632 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9633 + if (d_really_is_positive(d)) {
9634 + inode = d_inode(d);
9635 + if (au_ftest_lock(flags, IW))
9636 + do_ii_write_lock(inode, lsc);
9637 + else if (au_ftest_lock(flags, IR))
9638 + do_ii_read_lock(inode, lsc);
9642 +void di_read_unlock(struct dentry *d, int flags)
9644 + struct inode *inode;
9646 + if (d_really_is_positive(d)) {
9647 + inode = d_inode(d);
9648 + if (au_ftest_lock(flags, IW)) {
9649 + au_dbg_verify_dinode(d);
9650 + ii_write_unlock(inode);
9651 + } else if (au_ftest_lock(flags, IR)) {
9652 + au_dbg_verify_dinode(d);
9653 + ii_read_unlock(inode);
9656 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9659 +void di_downgrade_lock(struct dentry *d, int flags)
9661 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9662 + ii_downgrade_lock(d_inode(d));
9663 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9666 +void di_write_lock(struct dentry *d, unsigned int lsc)
9668 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9669 + if (d_really_is_positive(d))
9670 + do_ii_write_lock(d_inode(d), lsc);
9673 +void di_write_unlock(struct dentry *d)
9675 + au_dbg_verify_dinode(d);
9676 + if (d_really_is_positive(d))
9677 + ii_write_unlock(d_inode(d));
9678 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9681 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9683 + AuDebugOn(d1 == d2
9684 + || d_inode(d1) == d_inode(d2)
9685 + || d1->d_sb != d2->d_sb);
9687 + if ((isdir && au_test_subdir(d1, d2))
9689 + di_write_lock_child(d1);
9690 + di_write_lock_child2(d2);
9692 + di_write_lock_child(d2);
9693 + di_write_lock_child2(d1);
9697 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9699 + AuDebugOn(d1 == d2
9700 + || d_inode(d1) == d_inode(d2)
9701 + || d1->d_sb != d2->d_sb);
9703 + if ((isdir && au_test_subdir(d1, d2))
9705 + di_write_lock_parent(d1);
9706 + di_write_lock_parent2(d2);
9708 + di_write_lock_parent(d2);
9709 + di_write_lock_parent2(d1);
9713 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9715 + di_write_unlock(d1);
9716 + if (d_inode(d1) == d_inode(d2))
9717 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9719 + di_write_unlock(d2);
9722 +/* ---------------------------------------------------------------------- */
9724 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9728 + DiMustAnyLock(dentry);
9730 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9732 + AuDebugOn(bindex < 0);
9733 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9734 + AuDebugOn(d && au_dcount(d) <= 0);
9739 + * extended version of au_h_dptr().
9740 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9743 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9745 + struct dentry *h_dentry;
9746 + struct inode *inode, *h_inode;
9748 + AuDebugOn(d_really_is_negative(dentry));
9751 + if (au_dbtop(dentry) <= bindex
9752 + && bindex <= au_dbbot(dentry))
9753 + h_dentry = au_h_dptr(dentry, bindex);
9754 + if (h_dentry && !au_d_linkable(h_dentry)) {
9756 + goto out; /* success */
9759 + inode = d_inode(dentry);
9760 + AuDebugOn(bindex < au_ibtop(inode));
9761 + AuDebugOn(au_ibbot(inode) < bindex);
9762 + h_inode = au_h_iptr(inode, bindex);
9763 + h_dentry = d_find_alias(h_inode);
9765 + if (!IS_ERR(h_dentry)) {
9766 + if (!au_d_linkable(h_dentry))
9767 + goto out; /* success */
9773 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9774 + h_dentry = au_plink_lkup(inode, bindex);
9775 + AuDebugOn(!h_dentry);
9776 + if (!IS_ERR(h_dentry)) {
9777 + if (!au_d_hashed_positive(h_dentry))
9778 + goto out; /* success */
9785 + AuDbgDentry(h_dentry);
9789 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9791 + aufs_bindex_t bbot, bwh;
9793 + bbot = au_dbbot(dentry);
9795 + bwh = au_dbwh(dentry);
9798 + if (0 < bwh && bwh < bbot)
9804 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9806 + aufs_bindex_t bbot, bopq;
9808 + bbot = au_dbtail(dentry);
9810 + bopq = au_dbdiropq(dentry);
9811 + if (0 <= bopq && bopq < bbot)
9817 +/* ---------------------------------------------------------------------- */
9819 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9820 + struct dentry *h_dentry)
9822 + struct au_dinfo *dinfo;
9823 + struct au_hdentry *hd;
9824 + struct au_branch *br;
9826 + DiMustWriteLock(dentry);
9828 + dinfo = au_di(dentry);
9829 + hd = au_hdentry(dinfo, bindex);
9831 + hd->hd_dentry = h_dentry;
9833 + br = au_sbr(dentry->d_sb, bindex);
9834 + hd->hd_id = br->br_id;
9838 +int au_dbrange_test(struct dentry *dentry)
9841 + aufs_bindex_t btop, bbot;
9844 + btop = au_dbtop(dentry);
9845 + bbot = au_dbbot(dentry);
9847 + AuDebugOn(bbot < 0 && btop > bbot);
9850 + AuDebugOn(bbot >= 0);
9856 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9861 + if (unlikely(au_digen(dentry) != sigen
9862 + || au_iigen_test(d_inode(dentry), sigen)))
9868 +void au_update_digen(struct dentry *dentry)
9870 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9871 + /* smp_mb(); */ /* atomic_set */
9874 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9876 + struct au_dinfo *dinfo;
9877 + struct dentry *h_d;
9878 + struct au_hdentry *hdp;
9879 + aufs_bindex_t bindex, bbot;
9881 + DiMustWriteLock(dentry);
9883 + dinfo = au_di(dentry);
9884 + if (!dinfo || dinfo->di_btop < 0)
9887 + if (do_put_zero) {
9888 + bbot = dinfo->di_bbot;
9889 + bindex = dinfo->di_btop;
9890 + hdp = au_hdentry(dinfo, bindex);
9891 + for (; bindex <= bbot; bindex++, hdp++) {
9892 + h_d = hdp->hd_dentry;
9893 + if (h_d && d_is_negative(h_d))
9894 + au_set_h_dptr(dentry, bindex, NULL);
9898 + dinfo->di_btop = 0;
9899 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9900 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9901 + if (hdp->hd_dentry)
9903 + if (dinfo->di_btop > dinfo->di_bbot) {
9904 + dinfo->di_btop = -1;
9905 + dinfo->di_bbot = -1;
9909 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9910 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9911 + if (hdp->hd_dentry)
9913 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9916 +void au_update_dbtop(struct dentry *dentry)
9918 + aufs_bindex_t bindex, bbot;
9919 + struct dentry *h_dentry;
9921 + bbot = au_dbbot(dentry);
9922 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9923 + h_dentry = au_h_dptr(dentry, bindex);
9926 + if (d_is_positive(h_dentry)) {
9927 + au_set_dbtop(dentry, bindex);
9930 + au_set_h_dptr(dentry, bindex, NULL);
9934 +void au_update_dbbot(struct dentry *dentry)
9936 + aufs_bindex_t bindex, btop;
9937 + struct dentry *h_dentry;
9939 + btop = au_dbtop(dentry);
9940 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9941 + h_dentry = au_h_dptr(dentry, bindex);
9944 + if (d_is_positive(h_dentry)) {
9945 + au_set_dbbot(dentry, bindex);
9948 + au_set_h_dptr(dentry, bindex, NULL);
9952 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9954 + aufs_bindex_t bindex, bbot;
9956 + bbot = au_dbbot(dentry);
9957 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9958 + if (au_h_dptr(dentry, bindex) == h_dentry)
9962 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9963 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9964 +++ linux/fs/aufs/dir.c 2020-01-27 10:57:18.168871450 +0100
9966 +// SPDX-License-Identifier: GPL-2.0
9968 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9970 + * This program, aufs is free software; you can redistribute it and/or modify
9971 + * it under the terms of the GNU General Public License as published by
9972 + * the Free Software Foundation; either version 2 of the License, or
9973 + * (at your option) any later version.
9975 + * This program is distributed in the hope that it will be useful,
9976 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9977 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9978 + * GNU General Public License for more details.
9980 + * You should have received a copy of the GNU General Public License
9981 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9985 + * directory operations
9988 +#include <linux/fs_stack.h>
9989 +#include <linux/iversion.h>
9992 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9994 + unsigned int nlink;
9996 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9998 + nlink = dir->i_nlink;
9999 + nlink += h_dir->i_nlink - 2;
10000 + if (h_dir->i_nlink < 2)
10002 + smp_mb(); /* for i_nlink */
10003 + /* 0 can happen in revaliding */
10004 + set_nlink(dir, nlink);
10007 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10009 + unsigned int nlink;
10011 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10013 + nlink = dir->i_nlink;
10014 + nlink -= h_dir->i_nlink - 2;
10015 + if (h_dir->i_nlink < 2)
10017 + smp_mb(); /* for i_nlink */
10018 + /* nlink == 0 means the branch-fs is broken */
10019 + set_nlink(dir, nlink);
10022 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10025 + aufs_bindex_t bindex, bbot;
10026 + struct file *h_file;
10027 + struct dentry *h_dentry;
10031 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10033 + bbot = au_fbbot_dir(file);
10034 + for (bindex = au_fbtop(file);
10035 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10037 + h_file = au_hf_dir(file, bindex);
10038 + if (h_file && file_inode(h_file))
10039 + sz += vfsub_f_size_read(h_file);
10042 + AuDebugOn(!dentry);
10043 + AuDebugOn(!d_is_dir(dentry));
10045 + bbot = au_dbtaildir(dentry);
10046 + for (bindex = au_dbtop(dentry);
10047 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10049 + h_dentry = au_h_dptr(dentry, bindex);
10050 + if (h_dentry && d_is_positive(h_dentry))
10051 + sz += i_size_read(d_inode(h_dentry));
10054 + if (sz < KMALLOC_MAX_SIZE)
10055 + sz = roundup_pow_of_two(sz);
10056 + if (sz > KMALLOC_MAX_SIZE)
10057 + sz = KMALLOC_MAX_SIZE;
10058 + else if (sz < NAME_MAX) {
10059 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10060 + sz = AUFS_RDBLK_DEF;
10065 +struct au_dir_ts_arg {
10066 + struct dentry *dentry;
10067 + aufs_bindex_t brid;
10070 +static void au_do_dir_ts(void *arg)
10072 + struct au_dir_ts_arg *a = arg;
10073 + struct au_dtime dt;
10074 + struct path h_path;
10075 + struct inode *dir, *h_dir;
10076 + struct super_block *sb;
10077 + struct au_branch *br;
10078 + struct au_hinode *hdir;
10080 + aufs_bindex_t btop, bindex;
10082 + sb = a->dentry->d_sb;
10083 + if (d_really_is_negative(a->dentry))
10085 + /* no dir->i_mutex lock */
10086 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10088 + dir = d_inode(a->dentry);
10089 + btop = au_ibtop(dir);
10090 + bindex = au_br_index(sb, a->brid);
10091 + if (bindex < btop)
10094 + br = au_sbr(sb, bindex);
10095 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10096 + if (!h_path.dentry)
10098 + h_path.mnt = au_br_mnt(br);
10099 + au_dtime_store(&dt, a->dentry, &h_path);
10101 + br = au_sbr(sb, btop);
10102 + if (!au_br_writable(br->br_perm))
10104 + h_path.dentry = au_h_dptr(a->dentry, btop);
10105 + h_path.mnt = au_br_mnt(br);
10106 + err = vfsub_mnt_want_write(h_path.mnt);
10109 + hdir = au_hi(dir, btop);
10110 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10111 + h_dir = au_h_iptr(dir, btop);
10112 + if (h_dir->i_nlink
10113 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10114 + dt.dt_h_path = h_path;
10115 + au_dtime_revert(&dt);
10117 + au_hn_inode_unlock(hdir);
10118 + vfsub_mnt_drop_write(h_path.mnt);
10119 + au_cpup_attr_timesizes(dir);
10122 + aufs_read_unlock(a->dentry, AuLock_DW);
10125 + au_nwt_done(&au_sbi(sb)->si_nowait);
10126 + au_kfree_try_rcu(arg);
10129 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10131 + int perm, wkq_err;
10132 + aufs_bindex_t btop;
10133 + struct au_dir_ts_arg *arg;
10134 + struct dentry *dentry;
10135 + struct super_block *sb;
10139 + dentry = d_find_any_alias(dir);
10140 + AuDebugOn(!dentry);
10141 + sb = dentry->d_sb;
10142 + btop = au_ibtop(dir);
10143 + if (btop == bindex) {
10144 + au_cpup_attr_timesizes(dir);
10148 + perm = au_sbr_perm(sb, btop);
10149 + if (!au_br_writable(perm))
10152 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10156 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10157 + arg->brid = au_sbr_id(sb, bindex);
10158 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10159 + if (unlikely(wkq_err)) {
10160 + pr_err("wkq %d\n", wkq_err);
10162 + au_kfree_try_rcu(arg);
10169 +/* ---------------------------------------------------------------------- */
10171 +static int reopen_dir(struct file *file)
10174 + unsigned int flags;
10175 + aufs_bindex_t bindex, btail, btop;
10176 + struct dentry *dentry, *h_dentry;
10177 + struct file *h_file;
10179 + /* open all lower dirs */
10180 + dentry = file->f_path.dentry;
10181 + btop = au_dbtop(dentry);
10182 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10183 + au_set_h_fptr(file, bindex, NULL);
10184 + au_set_fbtop(file, btop);
10186 + btail = au_dbtaildir(dentry);
10187 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10188 + au_set_h_fptr(file, bindex, NULL);
10189 + au_set_fbbot_dir(file, btail);
10191 + flags = vfsub_file_flags(file);
10192 + for (bindex = btop; bindex <= btail; bindex++) {
10193 + h_dentry = au_h_dptr(dentry, bindex);
10196 + h_file = au_hf_dir(file, bindex);
10200 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10201 + err = PTR_ERR(h_file);
10202 + if (IS_ERR(h_file))
10203 + goto out; /* close all? */
10204 + au_set_h_fptr(file, bindex, h_file);
10206 + au_update_figen(file);
10207 + /* todo: necessary? */
10208 + /* file->f_ra = h_file->f_ra; */
10215 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10218 + aufs_bindex_t bindex, btail;
10219 + struct dentry *dentry, *h_dentry;
10220 + struct vfsmount *mnt;
10222 + FiMustWriteLock(file);
10223 + AuDebugOn(h_file);
10226 + mnt = file->f_path.mnt;
10227 + dentry = file->f_path.dentry;
10228 + file->f_version = inode_query_iversion(d_inode(dentry));
10229 + bindex = au_dbtop(dentry);
10230 + au_set_fbtop(file, bindex);
10231 + btail = au_dbtaildir(dentry);
10232 + au_set_fbbot_dir(file, btail);
10233 + for (; !err && bindex <= btail; bindex++) {
10234 + h_dentry = au_h_dptr(dentry, bindex);
10238 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10239 + if (unlikely(err))
10241 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10242 + if (IS_ERR(h_file)) {
10243 + err = PTR_ERR(h_file);
10246 + au_set_h_fptr(file, bindex, h_file);
10248 + au_update_figen(file);
10249 + /* todo: necessary? */
10250 + /* file->f_ra = h_file->f_ra; */
10252 + return 0; /* success */
10255 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10256 + au_set_h_fptr(file, bindex, NULL);
10257 + au_set_fbtop(file, -1);
10258 + au_set_fbbot_dir(file, -1);
10263 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10264 + struct file *file)
10267 + struct super_block *sb;
10268 + struct au_fidir *fidir;
10271 + sb = file->f_path.dentry->d_sb;
10272 + si_read_lock(sb, AuLock_FLUSH);
10273 + fidir = au_fidir_alloc(sb);
10275 + struct au_do_open_args args = {
10276 + .open = do_open_dir,
10279 + err = au_do_open(file, &args);
10280 + if (unlikely(err))
10281 + au_kfree_rcu(fidir);
10283 + si_read_unlock(sb);
10287 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10288 + struct file *file)
10290 + struct au_vdir *vdir_cache;
10291 + struct au_finfo *finfo;
10292 + struct au_fidir *fidir;
10293 + struct au_hfile *hf;
10294 + aufs_bindex_t bindex, bbot;
10296 + finfo = au_fi(file);
10297 + fidir = finfo->fi_hdir;
10299 + au_hbl_del(&finfo->fi_hlist,
10300 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10301 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10303 + au_vdir_free(vdir_cache);
10305 + bindex = finfo->fi_btop;
10306 + if (bindex >= 0) {
10307 + hf = fidir->fd_hfile + bindex;
10309 + * calls fput() instead of filp_close(),
10310 + * since no dnotify or lock for the lower file.
10312 + bbot = fidir->fd_bbot;
10313 + for (; bindex <= bbot; bindex++, hf++)
10315 + au_hfput(hf, /*execed*/0);
10317 + au_kfree_rcu(fidir);
10318 + finfo->fi_hdir = NULL;
10320 + au_finfo_fin(file);
10324 +/* ---------------------------------------------------------------------- */
10326 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10329 + aufs_bindex_t bindex, bbot;
10330 + struct file *h_file;
10333 + bbot = au_fbbot_dir(file);
10334 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10335 + h_file = au_hf_dir(file, bindex);
10337 + err = vfsub_flush(h_file, id);
10342 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10344 + return au_do_flush(file, id, au_do_flush_dir);
10347 +/* ---------------------------------------------------------------------- */
10349 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10352 + aufs_bindex_t bbot, bindex;
10353 + struct inode *inode;
10354 + struct super_block *sb;
10357 + sb = dentry->d_sb;
10358 + inode = d_inode(dentry);
10359 + IMustLock(inode);
10360 + bbot = au_dbbot(dentry);
10361 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10362 + struct path h_path;
10364 + if (au_test_ro(sb, bindex, inode))
10366 + h_path.dentry = au_h_dptr(dentry, bindex);
10367 + if (!h_path.dentry)
10370 + h_path.mnt = au_sbr_mnt(sb, bindex);
10371 + err = vfsub_fsync(NULL, &h_path, datasync);
10377 +static int au_do_fsync_dir(struct file *file, int datasync)
10380 + aufs_bindex_t bbot, bindex;
10381 + struct file *h_file;
10382 + struct super_block *sb;
10383 + struct inode *inode;
10385 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10386 + if (unlikely(err))
10389 + inode = file_inode(file);
10390 + sb = inode->i_sb;
10391 + bbot = au_fbbot_dir(file);
10392 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10393 + h_file = au_hf_dir(file, bindex);
10394 + if (!h_file || au_test_ro(sb, bindex, inode))
10397 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10405 + * @file may be NULL
10407 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10411 + struct dentry *dentry;
10412 + struct inode *inode;
10413 + struct super_block *sb;
10416 + dentry = file->f_path.dentry;
10417 + inode = d_inode(dentry);
10418 + inode_lock(inode);
10419 + sb = dentry->d_sb;
10420 + si_noflush_read_lock(sb);
10422 + err = au_do_fsync_dir(file, datasync);
10424 + di_write_lock_child(dentry);
10425 + err = au_do_fsync_dir_no_file(dentry, datasync);
10427 + au_cpup_attr_timesizes(inode);
10428 + di_write_unlock(dentry);
10430 + fi_write_unlock(file);
10432 + si_read_unlock(sb);
10433 + inode_unlock(inode);
10437 +/* ---------------------------------------------------------------------- */
10439 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10442 + struct dentry *dentry;
10443 + struct inode *inode, *h_inode;
10444 + struct super_block *sb;
10446 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10448 + dentry = file->f_path.dentry;
10449 + inode = d_inode(dentry);
10450 + IMustLock(inode);
10452 + sb = dentry->d_sb;
10453 + si_read_lock(sb, AuLock_FLUSH);
10454 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10455 + if (unlikely(err))
10457 + err = au_alive_dir(dentry);
10459 + err = au_vdir_init(file);
10460 + di_downgrade_lock(dentry, AuLock_IR);
10461 + if (unlikely(err))
10464 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10465 + if (!au_test_nfsd()) {
10466 + err = au_vdir_fill_de(file, ctx);
10467 + fsstack_copy_attr_atime(inode, h_inode);
10470 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10471 + * encode_fh() and others.
10473 + atomic_inc(&h_inode->i_count);
10474 + di_read_unlock(dentry, AuLock_IR);
10475 + si_read_unlock(sb);
10476 + err = au_vdir_fill_de(file, ctx);
10477 + fsstack_copy_attr_atime(inode, h_inode);
10478 + fi_write_unlock(file);
10486 + di_read_unlock(dentry, AuLock_IR);
10487 + fi_write_unlock(file);
10489 + si_read_unlock(sb);
10493 +/* ---------------------------------------------------------------------- */
10495 +#define AuTestEmpty_WHONLY 1
10496 +#define AuTestEmpty_CALLED (1 << 1)
10497 +#define AuTestEmpty_SHWH (1 << 2)
10498 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10499 +#define au_fset_testempty(flags, name) \
10500 + do { (flags) |= AuTestEmpty_##name; } while (0)
10501 +#define au_fclr_testempty(flags, name) \
10502 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10504 +#ifndef CONFIG_AUFS_SHWH
10505 +#undef AuTestEmpty_SHWH
10506 +#define AuTestEmpty_SHWH 0
10509 +struct test_empty_arg {
10510 + struct dir_context ctx;
10511 + struct au_nhash *whlist;
10512 + unsigned int flags;
10514 + aufs_bindex_t bindex;
10517 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10518 + int namelen, loff_t offset __maybe_unused, u64 ino,
10519 + unsigned int d_type)
10521 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10523 + char *name = (void *)__name;
10526 + au_fset_testempty(arg->flags, CALLED);
10528 + if (name[0] == '.'
10529 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10530 + goto out; /* success */
10532 + if (namelen <= AUFS_WH_PFX_LEN
10533 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10534 + if (au_ftest_testempty(arg->flags, WHONLY)
10535 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10536 + arg->err = -ENOTEMPTY;
10540 + name += AUFS_WH_PFX_LEN;
10541 + namelen -= AUFS_WH_PFX_LEN;
10542 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10543 + arg->err = au_nhash_append_wh
10544 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10545 + au_ftest_testempty(arg->flags, SHWH));
10549 + AuTraceErr(arg->err);
10553 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10556 + struct file *h_file;
10557 + struct au_branch *br;
10559 + h_file = au_h_open(dentry, arg->bindex,
10560 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10561 + /*file*/NULL, /*force_wr*/0);
10562 + err = PTR_ERR(h_file);
10563 + if (IS_ERR(h_file))
10567 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10568 + && !file_inode(h_file)->i_nlink)
10573 + au_fclr_testempty(arg->flags, CALLED);
10575 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10578 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10582 + br = au_sbr(dentry->d_sb, arg->bindex);
10583 + au_lcnt_dec(&br->br_nfiles);
10588 +struct do_test_empty_args {
10590 + struct dentry *dentry;
10591 + struct test_empty_arg *arg;
10594 +static void call_do_test_empty(void *args)
10596 + struct do_test_empty_args *a = args;
10597 + *a->errp = do_test_empty(a->dentry, a->arg);
10600 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10602 + int err, wkq_err;
10603 + struct dentry *h_dentry;
10604 + struct inode *h_inode;
10606 + h_dentry = au_h_dptr(dentry, arg->bindex);
10607 + h_inode = d_inode(h_dentry);
10608 + /* todo: i_mode changes anytime? */
10609 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10610 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10611 + inode_unlock_shared(h_inode);
10613 + err = do_test_empty(dentry, arg);
10615 + struct do_test_empty_args args = {
10617 + .dentry = dentry,
10620 + unsigned int flags = arg->flags;
10622 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10623 + if (unlikely(wkq_err))
10625 + arg->flags = flags;
10631 +int au_test_empty_lower(struct dentry *dentry)
10634 + unsigned int rdhash;
10635 + aufs_bindex_t bindex, btop, btail;
10636 + struct au_nhash whlist;
10637 + struct test_empty_arg arg = {
10639 + .actor = test_empty_cb
10642 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10644 + SiMustAnyLock(dentry->d_sb);
10646 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10648 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10649 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10650 + if (unlikely(err))
10654 + arg.whlist = &whlist;
10655 + btop = au_dbtop(dentry);
10656 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10657 + au_fset_testempty(arg.flags, SHWH);
10658 + test_empty = do_test_empty;
10659 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10660 + test_empty = sio_test_empty;
10661 + arg.bindex = btop;
10662 + err = test_empty(dentry, &arg);
10663 + if (unlikely(err))
10666 + au_fset_testempty(arg.flags, WHONLY);
10667 + btail = au_dbtaildir(dentry);
10668 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10669 + struct dentry *h_dentry;
10671 + h_dentry = au_h_dptr(dentry, bindex);
10672 + if (h_dentry && d_is_positive(h_dentry)) {
10673 + arg.bindex = bindex;
10674 + err = test_empty(dentry, &arg);
10679 + au_nhash_wh_free(&whlist);
10684 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10687 + struct test_empty_arg arg = {
10689 + .actor = test_empty_cb
10692 + aufs_bindex_t bindex, btail;
10695 + arg.whlist = whlist;
10696 + arg.flags = AuTestEmpty_WHONLY;
10697 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10698 + au_fset_testempty(arg.flags, SHWH);
10699 + btail = au_dbtaildir(dentry);
10700 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10701 + struct dentry *h_dentry;
10703 + h_dentry = au_h_dptr(dentry, bindex);
10704 + if (h_dentry && d_is_positive(h_dentry)) {
10705 + arg.bindex = bindex;
10706 + err = sio_test_empty(dentry, &arg);
10713 +/* ---------------------------------------------------------------------- */
10715 +const struct file_operations aufs_dir_fop = {
10716 + .owner = THIS_MODULE,
10717 + .llseek = default_llseek,
10718 + .read = generic_read_dir,
10719 + .iterate_shared = aufs_iterate_shared,
10720 + .unlocked_ioctl = aufs_ioctl_dir,
10721 +#ifdef CONFIG_COMPAT
10722 + .compat_ioctl = aufs_compat_ioctl_dir,
10724 + .open = aufs_open_dir,
10725 + .release = aufs_release_dir,
10726 + .flush = aufs_flush_dir,
10727 + .fsync = aufs_fsync_dir
10729 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10730 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10731 +++ linux/fs/aufs/dir.h 2020-08-03 09:14:46.095748745 +0200
10733 +/* SPDX-License-Identifier: GPL-2.0 */
10735 + * Copyright (C) 2005-2020 Junjiro R. Okajima
10737 + * This program, aufs is free software; you can redistribute it and/or modify
10738 + * it under the terms of the GNU General Public License as published by
10739 + * the Free Software Foundation; either version 2 of the License, or
10740 + * (at your option) any later version.
10742 + * This program is distributed in the hope that it will be useful,
10743 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10744 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10745 + * GNU General Public License for more details.
10747 + * You should have received a copy of the GNU General Public License
10748 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10752 + * directory operations
10755 +#ifndef __AUFS_DIR_H__
10756 +#define __AUFS_DIR_H__
10760 +#include <linux/fs.h>
10762 +/* ---------------------------------------------------------------------- */
10764 +/* need to be faster and smaller */
10767 + unsigned int nh_num;
10768 + struct hlist_head *nh_head;
10771 +struct au_vdir_destr {
10772 + unsigned char len;
10773 + unsigned char name[];
10776 +struct au_vdir_dehstr {
10777 + struct hlist_node hash;
10778 + struct au_vdir_destr *str;
10779 + struct rcu_head rcu;
10780 +} ____cacheline_aligned_in_smp;
10782 +struct au_vdir_de {
10784 + unsigned char de_type;
10785 + /* caution: packed */
10786 + struct au_vdir_destr de_str;
10789 +struct au_vdir_wh {
10790 + struct hlist_node wh_hash;
10791 +#ifdef CONFIG_AUFS_SHWH
10793 + aufs_bindex_t wh_bindex;
10794 + unsigned char wh_type;
10796 + aufs_bindex_t wh_bindex;
10798 + /* caution: packed */
10799 + struct au_vdir_destr wh_str;
10802 +union au_vdir_deblk_p {
10803 + unsigned char *deblk;
10804 + struct au_vdir_de *de;
10808 + unsigned char **vd_deblk;
10809 + unsigned long vd_nblk;
10811 + unsigned long ul;
10812 + union au_vdir_deblk_p p;
10816 + unsigned int vd_deblk_sz;
10817 + unsigned long vd_jiffy;
10818 + struct rcu_head rcu;
10819 +} ____cacheline_aligned_in_smp;
10821 +/* ---------------------------------------------------------------------- */
10824 +extern const struct file_operations aufs_dir_fop;
10825 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10826 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10827 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10828 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10829 +int au_test_empty_lower(struct dentry *dentry);
10830 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10833 +unsigned int au_rdhash_est(loff_t sz);
10834 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10835 +void au_nhash_wh_free(struct au_nhash *whlist);
10836 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10838 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10839 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10840 + unsigned int d_type, aufs_bindex_t bindex,
10841 + unsigned char shwh);
10842 +void au_vdir_free(struct au_vdir *vdir);
10843 +int au_vdir_init(struct file *file);
10844 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10847 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10849 +#ifdef CONFIG_AUFS_RDU
10851 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10852 +#ifdef CONFIG_COMPAT
10853 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10854 + unsigned long arg);
10857 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10858 + unsigned int cmd, unsigned long arg)
10859 +#ifdef CONFIG_COMPAT
10860 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10861 + unsigned int cmd, unsigned long arg)
10865 +#endif /* __KERNEL__ */
10866 +#endif /* __AUFS_DIR_H__ */
10867 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10868 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10869 +++ linux/fs/aufs/dirren.c 2020-08-03 09:14:46.095748745 +0200
10871 +// SPDX-License-Identifier: GPL-2.0
10873 + * Copyright (C) 2017-2020 Junjiro R. Okajima
10875 + * This program, aufs is free software; you can redistribute it and/or modify
10876 + * it under the terms of the GNU General Public License as published by
10877 + * the Free Software Foundation; either version 2 of the License, or
10878 + * (at your option) any later version.
10880 + * This program is distributed in the hope that it will be useful,
10881 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10882 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10883 + * GNU General Public License for more details.
10885 + * You should have received a copy of the GNU General Public License
10886 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10890 + * special handling in renaming a directory
10891 + * in order to support looking-up the before-renamed name on the lower readonly
10895 +#include <linux/byteorder/generic.h>
10898 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10902 + idx = au_dr_ihash(ent->dr_h_ino);
10903 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10906 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10909 + struct hlist_bl_head *hbl;
10912 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10913 + hbl = dr->dr_h_ino + i;
10914 + hlist_bl_lock(hbl);
10915 + ret &= hlist_bl_empty(hbl);
10916 + hlist_bl_unlock(hbl);
10922 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10924 + struct au_dr_hino *found, *ent;
10925 + struct hlist_bl_head *hbl;
10926 + struct hlist_bl_node *pos;
10930 + idx = au_dr_ihash(ino);
10931 + hbl = dr->dr_h_ino + idx;
10932 + hlist_bl_lock(hbl);
10933 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10934 + if (ent->dr_h_ino == ino) {
10938 + hlist_bl_unlock(hbl);
10943 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10944 + struct au_dr_hino *add_ent)
10947 + struct hlist_bl_head *hbl;
10948 + struct hlist_bl_node *pos;
10949 + struct au_dr_hino *ent;
10952 + idx = au_dr_ihash(ino);
10953 + hbl = dr->dr_h_ino + idx;
10954 +#if 0 /* debug print */
10956 + struct hlist_bl_node *tmp;
10958 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10959 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10962 + hlist_bl_lock(hbl);
10963 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10964 + if (ent->dr_h_ino == ino) {
10968 + if (!found && add_ent)
10969 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10970 + hlist_bl_unlock(hbl);
10972 + if (!found && add_ent)
10973 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
10978 +void au_dr_hino_free(struct au_dr_br *dr)
10981 + struct hlist_bl_head *hbl;
10982 + struct hlist_bl_node *pos, *tmp;
10983 + struct au_dr_hino *ent;
10985 + /* SiMustWriteLock(sb); */
10987 + for (i = 0; i < AuDirren_NHASH; i++) {
10988 + hbl = dr->dr_h_ino + i;
10989 + /* no spinlock since sbinfo must be write-locked */
10990 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10991 + au_kfree_rcu(ent);
10992 + INIT_HLIST_BL_HEAD(hbl);
10996 +/* returns the number of inodes or an error */
10997 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
10998 + struct file *hinofile)
11002 + loff_t pos, oldsize;
11004 + struct inode *hinoinode;
11005 + struct hlist_bl_head *hbl;
11006 + struct hlist_bl_node *n1, *n2;
11007 + struct au_dr_hino *ent;
11009 + SiMustWriteLock(sb);
11010 + AuDebugOn(!au_br_writable(br->br_perm));
11012 + hinoinode = file_inode(hinofile);
11013 + oldsize = i_size_read(hinoinode);
11017 + hbl = br->br_dirren.dr_h_ino;
11018 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11019 + /* no bit-lock since sbinfo must be write-locked */
11020 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11021 + AuDbg("hi%llu, %pD2\n",
11022 + (unsigned long long)ent->dr_h_ino, hinofile);
11023 + u64 = cpu_to_be64(ent->dr_h_ino);
11024 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11025 + if (ssz == sizeof(u64))
11028 + /* write error */
11029 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11036 + /* regardless the error */
11037 + if (pos < oldsize) {
11038 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11046 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11053 + struct au_dr_hino *ent;
11054 + struct inode *hinoinode;
11055 + struct hlist_bl_head *hbl;
11059 + hbl = dr->dr_h_ino;
11060 + hinoinode = file_inode(hinofile);
11061 + sz = i_size_read(hinoinode);
11062 + AuDebugOn(sz % sizeof(u64));
11063 + n = sz / sizeof(u64);
11065 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11066 + if (unlikely(ssz != sizeof(u64))) {
11067 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11074 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11080 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11081 + AuDbg("hi%llu, %pD2\n",
11082 + (unsigned long long)ent->dr_h_ino, hinofile);
11083 + hidx = au_dr_ihash(ent->dr_h_ino);
11084 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11086 + goto out; /* success */
11089 + au_dr_hino_free(dr);
11096 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11097 + * @path is a switch to distinguish load and store.
11099 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11100 + struct au_branch *br, const struct path *path)
11103 + unsigned char load, suspend;
11104 + struct file *hinofile;
11105 + struct au_hinode *hdir;
11106 + struct inode *dir, *delegated;
11107 + struct path hinopath;
11108 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11109 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11111 + AuDebugOn(bindex < 0 && !br);
11112 + AuDebugOn(bindex >= 0 && br);
11117 + br = au_sbr(sb, bindex);
11120 + path = &br->br_path;
11121 + AuDebugOn(!au_br_writable(br->br_perm));
11122 + if (unlikely(!au_br_writable(br->br_perm)))
11128 + dir = d_inode(sb->s_root);
11129 + hdir = au_hinode(au_ii(dir), bindex);
11130 + dir = hdir->hi_inode;
11131 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11133 + dir = d_inode(path->dentry);
11134 + inode_lock_nested(dir, AuLsc_I_CHILD);
11136 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11137 + err = PTR_ERR(hinopath.dentry);
11138 + if (IS_ERR(hinopath.dentry))
11142 + flags = O_RDONLY;
11144 + if (d_is_negative(hinopath.dentry))
11145 + goto out_dput; /* success */
11147 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11148 + if (d_is_positive(hinopath.dentry)) {
11149 + delegated = NULL;
11150 + err = vfsub_unlink(dir, &hinopath, &delegated,
11153 + if (unlikely(err))
11154 + pr_err("ignored err %d, %pd2\n",
11155 + err, hinopath.dentry);
11156 + if (unlikely(err == -EWOULDBLOCK))
11161 + } else if (!d_is_positive(hinopath.dentry)) {
11162 + err = vfsub_create(dir, &hinopath, 0600,
11163 + /*want_excl*/false);
11165 + if (unlikely(err))
11168 + flags = O_WRONLY;
11170 + hinopath.mnt = path->mnt;
11171 + hinofile = vfsub_dentry_open(&hinopath, flags);
11173 + au_hn_inode_unlock(hdir);
11175 + inode_unlock(dir);
11176 + dput(hinopath.dentry);
11177 + AuTraceErrPtr(hinofile);
11178 + if (IS_ERR(hinofile)) {
11179 + err = PTR_ERR(hinofile);
11184 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11186 + err = au_dr_hino_store(sb, br, hinofile);
11191 + dput(hinopath.dentry);
11194 + au_hn_inode_unlock(hdir);
11196 + inode_unlock(dir);
11202 +/* ---------------------------------------------------------------------- */
11204 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11207 + struct kstatfs kstfs;
11209 + struct dentry *dentry;
11210 + struct super_block *sb;
11212 + err = vfs_statfs((void *)path, &kstfs);
11214 + if (unlikely(err))
11217 + /* todo: support for UUID */
11219 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11220 + brid->type = AuBrid_FSID;
11221 + brid->fsid = kstfs.f_fsid;
11223 + dentry = path->dentry;
11224 + sb = dentry->d_sb;
11227 + brid->type = AuBrid_DEV;
11236 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11237 + const struct path *path)
11240 + struct au_dr_br *dr;
11241 + struct hlist_bl_head *hbl;
11243 + dr = &br->br_dirren;
11244 + hbl = dr->dr_h_ino;
11245 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11246 + INIT_HLIST_BL_HEAD(hbl);
11248 + err = au_dr_brid_init(&dr->dr_brid, path);
11249 + if (unlikely(err))
11252 + if (au_opt_test(au_mntflags(sb), DIRREN))
11253 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11260 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11265 + if (au_br_writable(br->br_perm))
11266 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11268 + au_dr_hino_free(&br->br_dirren);
11273 +/* ---------------------------------------------------------------------- */
11275 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11276 + char *buf, size_t sz)
11279 + unsigned int major, minor;
11283 + err = snprintf(p, sz, "%d_", brid->type);
11284 + AuDebugOn(err > sz);
11287 + switch (brid->type) {
11288 + case AuBrid_Unset:
11290 + case AuBrid_UUID:
11291 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11293 + case AuBrid_FSID:
11294 + err = snprintf(p, sz, "%08x-%08x",
11295 + brid->fsid.val[0], brid->fsid.val[1]);
11298 + major = MAJOR(brid->dev);
11299 + minor = MINOR(brid->dev);
11300 + if (major <= 0xff && minor <= 0xff)
11301 + err = snprintf(p, sz, "%02x%02x", major, minor);
11303 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11306 + AuDebugOn(err > sz);
11309 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11310 + AuDebugOn(err > sz);
11317 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11320 + struct dentry *br_dentry;
11321 + struct inode *br_inode;
11323 + br_dentry = au_br_dentry(br);
11324 + br_inode = d_inode(br_dentry);
11325 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11326 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11327 + AuDebugOn(rlen > len);
11332 +/* ---------------------------------------------------------------------- */
11335 + * from the given @h_dentry, construct drinfo at @*fdata.
11336 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11339 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11340 + struct dentry *h_dentry,
11341 + unsigned char *allocated)
11344 + struct au_drinfo_fdata *f, *p;
11345 + struct au_drinfo *drinfo;
11346 + struct inode *h_inode;
11347 + struct qstr *qname;
11351 + h_inode = d_inode(h_dentry);
11352 + qname = &h_dentry->d_name;
11353 + drinfo = &f->drinfo;
11354 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11355 + drinfo->oldnamelen = qname->len;
11356 + if (*allocated < sizeof(*f) + qname->len) {
11357 + v = roundup_pow_of_two(*allocated + qname->len);
11358 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11359 + if (unlikely(!p)) {
11367 + drinfo = &f->drinfo;
11369 + memcpy(drinfo->oldname, qname->name, qname->len);
11370 + AuDbg("i%llu, %.*s\n",
11371 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11372 + drinfo->oldname);
11379 +/* callers have to free the return value */
11380 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11382 + struct au_drinfo *ret, *drinfo;
11383 + struct au_drinfo_fdata fdata;
11388 + ret = ERR_PTR(-EIO);
11390 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11391 + if (unlikely(ssz != sizeof(fdata))) {
11392 + AuIOErr("ssz %zd, %u, %pD2\n",
11393 + ssz, (unsigned int)sizeof(fdata), file);
11397 + fdata.magic = ntohl((__force __be32)fdata.magic);
11398 + switch (fdata.magic) {
11399 + case AUFS_DRINFO_MAGIC_V1:
11402 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11403 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11407 + drinfo = &fdata.drinfo;
11408 + len = drinfo->oldnamelen;
11410 + AuIOErr("broken drinfo %pD2\n", file);
11415 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11416 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11417 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11418 + (unsigned long long)drinfo->ino,
11419 + (unsigned long long)h_ino, file);
11420 + goto out; /* success */
11423 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11424 + if (unlikely(!ret)) {
11425 + ret = ERR_PTR(-ENOMEM);
11426 + AuTraceErrPtr(ret);
11431 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11432 + if (unlikely(ssz != len)) {
11433 + au_kfree_rcu(ret);
11434 + ret = ERR_PTR(-EIO);
11435 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11439 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11445 +/* ---------------------------------------------------------------------- */
11447 +/* in order to be revertible */
11448 +struct au_drinfo_rev_elm {
11450 + struct dentry *info_dentry;
11451 + struct au_drinfo *info_last;
11454 +struct au_drinfo_rev {
11455 + unsigned char already;
11456 + aufs_bindex_t nelm;
11457 + struct au_drinfo_rev_elm elm[];
11460 +/* todo: isn't it too large? */
11461 +struct au_drinfo_store {
11462 + struct path h_ppath;
11463 + struct dentry *h_dentry;
11464 + struct au_drinfo_fdata *fdata;
11465 + char *infoname; /* inside of whname, just after PFX */
11466 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11467 + aufs_bindex_t btgt, btail;
11468 + unsigned char no_sio,
11469 + allocated, /* current size of *fdata */
11470 + infonamelen, /* room size for p */
11471 + whnamelen, /* length of the generated name */
11472 + renameback; /* renamed back */
11475 +/* on rename(2) error, the caller should revert it using @elm */
11476 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11477 + struct au_drinfo_rev_elm *elm)
11482 + struct path infopath = {
11483 + .mnt = w->h_ppath.mnt
11485 + struct inode *h_dir, *h_inode, *delegated;
11486 + struct file *infofile;
11487 + struct qstr *qname;
11490 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11492 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11494 + AuTraceErrPtr(infopath.dentry);
11495 + if (IS_ERR(infopath.dentry)) {
11496 + err = PTR_ERR(infopath.dentry);
11501 + h_dir = d_inode(w->h_ppath.dentry);
11502 + if (elm && d_is_negative(infopath.dentry)) {
11503 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11505 + if (unlikely(err))
11507 + elm->created = 1;
11508 + elm->info_dentry = dget(infopath.dentry);
11511 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11512 + AuTraceErrPtr(infofile);
11513 + if (IS_ERR(infofile)) {
11514 + err = PTR_ERR(infofile);
11518 + h_inode = d_inode(infopath.dentry);
11519 + if (elm && i_size_read(h_inode)) {
11520 + h_inode = d_inode(w->h_dentry);
11521 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11522 + AuTraceErrPtr(elm->info_last);
11523 + if (IS_ERR(elm->info_last)) {
11524 + err = PTR_ERR(elm->info_last);
11525 + elm->info_last = NULL;
11526 + AuDebugOn(elm->info_dentry);
11531 + if (elm && w->renameback) {
11532 + delegated = NULL;
11533 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11535 + if (unlikely(err == -EWOULDBLOCK))
11541 + qname = &w->h_dentry->d_name;
11542 + len = sizeof(*w->fdata) + qname->len;
11544 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11545 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11546 + if (ssz == len) {
11547 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11548 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11549 + goto out_fput; /* success */
11554 + /* the caller should revert it using @elm */
11560 + dput(infopath.dentry);
11566 +struct au_call_drinfo_do_store_args {
11568 + struct au_drinfo_store *w;
11569 + struct au_drinfo_rev_elm *elm;
11572 +static void au_call_drinfo_do_store(void *args)
11574 + struct au_call_drinfo_do_store_args *a = args;
11576 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11579 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11580 + struct au_drinfo_rev_elm *elm)
11582 + int err, wkq_err;
11585 + err = au_drinfo_do_store(w, elm);
11587 + struct au_call_drinfo_do_store_args a = {
11592 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11593 + if (unlikely(wkq_err))
11601 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11602 + aufs_bindex_t btgt)
11606 + memset(w, 0, sizeof(*w));
11607 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11608 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11609 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11610 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11612 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11615 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11616 + if (unlikely(!w->fdata)) {
11620 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11627 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11629 + au_kfree_rcu(w->fdata);
11632 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11633 + struct au_drinfo_store *w)
11635 + struct au_drinfo_rev_elm *elm;
11636 + struct inode *h_dir, *delegated;
11638 + struct path infopath = {
11639 + .mnt = w->h_ppath.mnt
11642 + h_dir = d_inode(w->h_ppath.dentry);
11643 + IMustLock(h_dir);
11647 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11648 + AuDebugOn(elm->created && elm->info_last);
11649 + if (elm->created) {
11651 + delegated = NULL;
11652 + infopath.dentry = elm->info_dentry;
11653 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11656 + if (unlikely(err == -EWOULDBLOCK))
11658 + dput(elm->info_dentry);
11659 + } else if (elm->info_last) {
11661 + w->fdata->drinfo = *elm->info_last;
11662 + memcpy(w->fdata->drinfo.oldname,
11663 + elm->info_last->oldname,
11664 + elm->info_last->oldnamelen);
11665 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11666 + au_kfree_rcu(elm->info_last);
11668 + if (unlikely(err))
11669 + AuIOErr("%d, %s\n", err, w->whname);
11670 + /* go on even if err */
11674 +/* caller has to call au_dr_rename_fin() later */
11675 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11676 + struct qstr *dst_name, void *_rev)
11678 + int err, sz, nelm;
11679 + aufs_bindex_t bindex, btail;
11680 + struct au_drinfo_store work;
11681 + struct au_drinfo_rev *rev, **p;
11682 + struct au_drinfo_rev_elm *elm;
11683 + struct super_block *sb;
11684 + struct au_branch *br;
11685 + struct au_hinode *hdir;
11687 + err = au_drinfo_store_work_init(&work, btgt);
11689 + if (unlikely(err))
11693 + btail = au_dbtaildir(dentry);
11694 + nelm = btail - btgt;
11695 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11696 + rev = kcalloc(1, sz, GFP_NOFS);
11697 + if (unlikely(!rev)) {
11701 + rev->nelm = nelm;
11707 + sb = dentry->d_sb;
11708 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11709 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11710 + hdir = au_hi(d_inode(dentry), btgt);
11711 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11712 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11713 + work.h_dentry = au_h_dptr(dentry, bindex);
11714 + if (!work.h_dentry)
11717 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11718 + &work.allocated);
11720 + if (unlikely(err))
11723 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11724 + br = au_sbr(sb, bindex);
11725 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11726 + work.whnamelen += au_drinfo_name(br, work.infoname,
11727 + work.infonamelen);
11728 + AuDbg("whname %.*s, i%llu, %.*s\n",
11729 + work.whnamelen, work.whname,
11730 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11731 + work.fdata->drinfo.oldnamelen,
11732 + work.fdata->drinfo.oldname);
11734 + err = au_drinfo_store_sio(&work, elm);
11736 + if (unlikely(err))
11739 + if (unlikely(err)) {
11740 + /* revert all drinfo */
11741 + au_drinfo_store_rev(rev, &work);
11742 + au_kfree_try_rcu(rev);
11745 + au_hn_inode_unlock(hdir);
11748 + au_drinfo_store_work_fin(&work);
11753 +/* ---------------------------------------------------------------------- */
11755 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11756 + struct qstr *dst_name, void *_rev)
11758 + int err, already;
11760 + struct super_block *sb;
11761 + struct au_branch *br;
11762 + struct au_dr_br *dr;
11763 + struct dentry *h_dentry;
11764 + struct inode *h_inode;
11765 + struct au_dr_hino *ent;
11766 + struct au_drinfo_rev *rev, **p;
11768 + AuDbg("bindex %d\n", bindex);
11771 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11772 + if (unlikely(!ent))
11776 + br = au_sbr(sb, bindex);
11777 + dr = &br->br_dirren;
11778 + h_dentry = au_h_dptr(src, bindex);
11779 + h_inode = d_inode(h_dentry);
11780 + ino = h_inode->i_ino;
11781 + ent->dr_h_ino = ino;
11782 + already = au_dr_hino_test_add(dr, ino, ent);
11783 + AuDbg("b%d, hi%llu, already %d\n",
11784 + bindex, (unsigned long long)ino, already);
11786 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11791 + rev->already = already;
11792 + goto out; /* success */
11797 + au_dr_hino_del(dr, ent);
11798 + au_kfree_rcu(ent);
11805 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11807 + struct au_drinfo_rev *rev;
11808 + struct au_drinfo_rev_elm *elm;
11813 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11814 + dput(elm->info_dentry);
11815 + au_kfree_rcu(elm->info_last);
11817 + au_kfree_try_rcu(rev);
11820 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11823 + struct au_drinfo_store work;
11824 + struct au_drinfo_rev *rev = _rev;
11825 + struct super_block *sb;
11826 + struct au_branch *br;
11827 + struct inode *h_inode;
11828 + struct au_dr_br *dr;
11829 + struct au_dr_hino *ent;
11831 + err = au_drinfo_store_work_init(&work, btgt);
11832 + if (unlikely(err))
11836 + br = au_sbr(sb, btgt);
11837 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11838 + work.h_ppath.mnt = au_br_mnt(br);
11839 + au_drinfo_store_rev(rev, &work);
11840 + au_drinfo_store_work_fin(&work);
11841 + if (rev->already)
11844 + dr = &br->br_dirren;
11845 + h_inode = d_inode(work.h_ppath.dentry);
11846 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11848 + au_dr_hino_del(dr, ent);
11849 + au_kfree_rcu(ent);
11852 + au_kfree_try_rcu(rev);
11853 + if (unlikely(err))
11854 + pr_err("failed to remove dirren info\n");
11857 +/* ---------------------------------------------------------------------- */
11859 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11860 + char *whname, int whnamelen,
11861 + struct dentry **info_dentry)
11863 + struct au_drinfo *drinfo;
11865 + struct inode *h_dir;
11866 + struct path infopath;
11869 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11871 + *info_dentry = NULL;
11874 + h_dir = d_inode(h_ppath->dentry);
11875 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11876 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
11878 + if (IS_ERR(infopath.dentry)) {
11879 + drinfo = (void *)infopath.dentry;
11883 + if (d_is_negative(infopath.dentry))
11884 + goto out_dput; /* success */
11886 + infopath.mnt = h_ppath->mnt;
11887 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11888 + inode_unlock_shared(h_dir);
11891 + drinfo = (void *)f;
11895 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11896 + if (IS_ERR_OR_NULL(drinfo))
11899 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11900 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11905 + dput(infopath.dentry);
11908 + inode_unlock_shared(h_dir);
11909 + AuTraceErrPtr(drinfo);
11913 +struct au_drinfo_do_load_args {
11914 + struct au_drinfo **drinfop;
11915 + struct path *h_ppath;
11918 + struct dentry **info_dentry;
11921 +static void au_call_drinfo_do_load(void *args)
11923 + struct au_drinfo_do_load_args *a = args;
11925 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11929 +struct au_drinfo_load {
11930 + struct path h_ppath;
11931 + struct qstr *qname;
11932 + unsigned char no_sio;
11934 + aufs_bindex_t ninfo;
11935 + struct au_drinfo **drinfo;
11938 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11939 + struct au_branch *br)
11941 + int err, wkq_err, whnamelen, e;
11942 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11943 + = AUFS_WH_DR_INFO_PFX;
11944 + struct au_drinfo *drinfo;
11945 + struct qstr oldname;
11946 + struct inode *h_dir, *delegated;
11947 + struct dentry *info_dentry;
11948 + struct path infopath;
11950 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11951 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11952 + sizeof(whname) - whnamelen);
11954 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11957 + struct au_drinfo_do_load_args args = {
11958 + .drinfop = &drinfo,
11959 + .h_ppath = &w->h_ppath,
11960 + .whname = whname,
11961 + .whnamelen = whnamelen,
11962 + .info_dentry = &info_dentry
11964 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11965 + if (unlikely(wkq_err))
11966 + drinfo = ERR_PTR(wkq_err);
11968 + err = PTR_ERR(drinfo);
11969 + if (IS_ERR_OR_NULL(drinfo))
11973 + oldname.len = drinfo->oldnamelen;
11974 + oldname.name = drinfo->oldname;
11975 + if (au_qstreq(w->qname, &oldname)) {
11976 + /* the name is renamed back */
11977 + au_kfree_rcu(drinfo);
11980 + infopath.dentry = info_dentry;
11981 + infopath.mnt = w->h_ppath.mnt;
11982 + h_dir = d_inode(w->h_ppath.dentry);
11983 + delegated = NULL;
11984 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
11985 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
11986 + inode_unlock(h_dir);
11988 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
11989 + if (unlikely(e == -EWOULDBLOCK))
11992 + au_kfree_rcu(w->drinfo[bindex]);
11993 + w->drinfo[bindex] = drinfo;
11994 + dput(info_dentry);
12001 +/* ---------------------------------------------------------------------- */
12003 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12005 + struct au_drinfo **p = drinfo;
12008 + au_kfree_rcu(*drinfo++);
12009 + au_kfree_try_rcu(p);
12012 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12013 + aufs_bindex_t btgt)
12016 + struct au_drinfo_load w;
12017 + aufs_bindex_t bindex, bbot;
12018 + struct au_branch *br;
12019 + struct inode *h_dir;
12020 + struct au_dr_hino *ent;
12021 + struct super_block *sb;
12023 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12024 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12025 + AuLNPair(&lkup->whname), btgt);
12027 + sb = dentry->d_sb;
12028 + bbot = au_sbbot(sb);
12029 + w.ninfo = bbot + 1;
12030 + if (!lkup->dirren.drinfo) {
12031 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12032 + sizeof(*lkup->dirren.drinfo),
12034 + if (unlikely(!lkup->dirren.drinfo)) {
12038 + lkup->dirren.ninfo = w.ninfo;
12040 + w.drinfo = lkup->dirren.drinfo;
12041 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12042 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12043 + AuDebugOn(!w.h_ppath.dentry);
12044 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12045 + w.qname = &dentry->d_name;
12048 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12049 + br = au_sbr(sb, bindex);
12050 + err = au_drinfo_load(&w, bindex, br);
12051 + if (unlikely(err))
12053 + if (w.drinfo[bindex])
12057 + br = au_sbr(sb, btgt);
12058 + h_dir = d_inode(w.h_ppath.dentry);
12059 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12061 + au_dr_hino_del(&br->br_dirren, ent);
12062 + au_kfree_rcu(ent);
12064 + goto out; /* success */
12067 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12068 + lkup->dirren.ninfo = 0;
12069 + lkup->dirren.drinfo = NULL;
12075 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12077 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12080 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12083 + struct au_drinfo *drinfo;
12086 + if (!lkup->dirren.drinfo)
12088 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12089 + drinfo = lkup->dirren.drinfo[btgt];
12093 + au_kfree_try_rcu(lkup->whname.name);
12094 + lkup->whname.name = NULL;
12095 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12096 + lkup->dirren.dr_name.name = drinfo->oldname;
12097 + lkup->name = &lkup->dirren.dr_name;
12098 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12100 + AuDbg("name %.*s, whname %.*s, b%d\n",
12101 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12109 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12113 + struct au_drinfo *drinfo;
12116 + if (!lkup->dirren.drinfo)
12118 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12119 + drinfo = lkup->dirren.drinfo[bindex];
12123 + match = (drinfo->ino == h_ino);
12124 + AuDbg("match %d\n", match);
12130 +/* ---------------------------------------------------------------------- */
12132 +int au_dr_opt_set(struct super_block *sb)
12135 + aufs_bindex_t bindex, bbot;
12136 + struct au_branch *br;
12139 + bbot = au_sbbot(sb);
12140 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12141 + br = au_sbr(sb, bindex);
12142 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12148 +int au_dr_opt_flush(struct super_block *sb)
12151 + aufs_bindex_t bindex, bbot;
12152 + struct au_branch *br;
12155 + bbot = au_sbbot(sb);
12156 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12157 + br = au_sbr(sb, bindex);
12158 + if (au_br_writable(br->br_perm))
12159 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12165 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12168 + aufs_bindex_t bindex, bbot;
12169 + struct au_branch *br;
12173 + err = au_dr_opt_flush(sb);
12174 + if (unlikely(err))
12178 + bbot = au_sbbot(sb);
12179 + for (bindex = 0; bindex <= bbot; bindex++) {
12180 + br = au_sbr(sb, bindex);
12181 + au_dr_hino_free(&br->br_dirren);
12187 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12188 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12189 +++ linux/fs/aufs/dirren.h 2020-01-27 10:57:18.168871450 +0100
12191 +/* SPDX-License-Identifier: GPL-2.0 */
12193 + * Copyright (C) 2017-2020 Junjiro R. Okajima
12195 + * This program, aufs is free software; you can redistribute it and/or modify
12196 + * it under the terms of the GNU General Public License as published by
12197 + * the Free Software Foundation; either version 2 of the License, or
12198 + * (at your option) any later version.
12200 + * This program is distributed in the hope that it will be useful,
12201 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12202 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12203 + * GNU General Public License for more details.
12205 + * You should have received a copy of the GNU General Public License
12206 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12210 + * renamed dir info
12213 +#ifndef __AUFS_DIRREN_H__
12214 +#define __AUFS_DIRREN_H__
12218 +#include <linux/dcache.h>
12219 +#include <linux/statfs.h>
12220 +#include <linux/uuid.h>
12223 +#define AuDirren_NHASH 100
12225 +#ifdef CONFIG_AUFS_DIRREN
12226 +enum au_brid_type {
12233 +struct au_dr_brid {
12234 + enum au_brid_type type;
12236 + uuid_t uuid; /* unimplemented yet */
12242 +/* 20 is the max digits length of ulong 64 */
12243 +/* brid-type "_" uuid "_" inum */
12244 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12245 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12247 +struct au_dr_hino {
12248 + struct hlist_bl_node dr_hnode;
12253 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12254 + struct au_dr_brid dr_brid;
12257 +struct au_dr_lookup {
12258 + /* dr_name is pointed by struct au_do_lookup_args.name */
12259 + struct qstr dr_name; /* subset of dr_info */
12260 + aufs_bindex_t ninfo;
12261 + struct au_drinfo **drinfo;
12264 +struct au_dr_hino;
12266 +struct au_dr_br { };
12267 +struct au_dr_lookup { };
12270 +/* ---------------------------------------------------------------------- */
12273 +struct au_do_lookup_args;
12275 +#ifdef CONFIG_AUFS_DIRREN
12276 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12277 + struct au_dr_hino *add_ent);
12278 +void au_dr_hino_free(struct au_dr_br *dr);
12279 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12280 + const struct path *path);
12281 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12282 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12283 + struct qstr *dst_name, void *_rev);
12284 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12285 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12286 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12287 + aufs_bindex_t bindex);
12288 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12289 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12291 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12292 +int au_dr_opt_set(struct super_block *sb);
12293 +int au_dr_opt_flush(struct super_block *sb);
12294 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12296 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12297 + struct au_dr_hino *add_ent);
12298 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12299 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12300 + const struct path *path);
12301 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12302 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12303 + struct qstr *dst_name, void *_rev);
12304 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12305 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12307 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12308 + aufs_bindex_t bindex);
12309 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12310 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12311 + aufs_bindex_t bindex, ino_t h_ino);
12312 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12313 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12314 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12315 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12318 +/* ---------------------------------------------------------------------- */
12320 +#ifdef CONFIG_AUFS_DIRREN
12321 +static inline int au_dr_ihash(ino_t h_ino)
12323 + return h_ino % AuDirren_NHASH;
12326 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12329 +#endif /* __KERNEL__ */
12330 +#endif /* __AUFS_DIRREN_H__ */
12331 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12332 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12333 +++ linux/fs/aufs/dynop.c 2020-12-15 14:10:58.914689728 +0100
12335 +// SPDX-License-Identifier: GPL-2.0
12337 + * Copyright (C) 2010-2020 Junjiro R. Okajima
12339 + * This program, aufs is free software; you can redistribute it and/or modify
12340 + * it under the terms of the GNU General Public License as published by
12341 + * the Free Software Foundation; either version 2 of the License, or
12342 + * (at your option) any later version.
12344 + * This program is distributed in the hope that it will be useful,
12345 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12346 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12347 + * GNU General Public License for more details.
12349 + * You should have received a copy of the GNU General Public License
12350 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12354 + * dynamically customizable operations for regular files
12359 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12362 + * How large will these lists be?
12363 + * Usually just a few elements, 20-30 at most for each, I guess.
12365 +static struct hlist_bl_head dynop[AuDyLast];
12367 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12368 + const void *h_op)
12370 + struct au_dykey *key, *tmp;
12371 + struct hlist_bl_node *pos;
12374 + hlist_bl_lock(hbl);
12375 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12376 + if (tmp->dk_op.dy_hop == h_op) {
12377 + if (kref_get_unless_zero(&tmp->dk_kref))
12381 + hlist_bl_unlock(hbl);
12386 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12388 + struct au_dykey **k, *found;
12389 + const void *h_op = key->dk_op.dy_hop;
12393 + k = br->br_dykey;
12394 + for (i = 0; i < AuBrDynOp; i++)
12396 + if (k[i]->dk_op.dy_hop == h_op) {
12403 + spin_lock(&br->br_dykey_lock);
12404 + for (; i < AuBrDynOp; i++)
12406 + if (k[i]->dk_op.dy_hop == h_op) {
12414 + spin_unlock(&br->br_dykey_lock);
12415 + BUG_ON(i == AuBrDynOp); /* expand the array */
12421 +/* kref_get() if @key is already added */
12422 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12424 + struct au_dykey *tmp, *found;
12425 + struct hlist_bl_node *pos;
12426 + const void *h_op = key->dk_op.dy_hop;
12429 + hlist_bl_lock(hbl);
12430 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12431 + if (tmp->dk_op.dy_hop == h_op) {
12432 + if (kref_get_unless_zero(&tmp->dk_kref))
12437 + hlist_bl_add_head(&key->dk_hnode, hbl);
12438 + hlist_bl_unlock(hbl);
12445 +static void dy_free_rcu(struct rcu_head *rcu)
12447 + struct au_dykey *key;
12449 + key = container_of(rcu, struct au_dykey, dk_rcu);
12454 +static void dy_free(struct kref *kref)
12456 + struct au_dykey *key;
12457 + struct hlist_bl_head *hbl;
12459 + key = container_of(kref, struct au_dykey, dk_kref);
12460 + hbl = dynop + key->dk_op.dy_type;
12461 + au_hbl_del(&key->dk_hnode, hbl);
12462 + call_rcu(&key->dk_rcu, dy_free_rcu);
12465 +void au_dy_put(struct au_dykey *key)
12467 + kref_put(&key->dk_kref, dy_free);
12470 +/* ---------------------------------------------------------------------- */
12472 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12474 +#ifdef CONFIG_AUFS_DEBUG
12475 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12476 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12478 +#define DyDbgDeclare(cnt) do {} while (0)
12479 +#define DyDbgInc(cnt) do {} while (0)
12482 +#define DySet(func, dst, src, h_op, h_sb) do { \
12484 + if (h_op->func) { \
12486 + dst.func = src.func; \
12488 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12492 +#define DySetForce(func, dst, src) do { \
12493 + AuDebugOn(!src.func); \
12495 + dst.func = src.func; \
12498 +#define DySetAop(func) \
12499 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12500 +#define DySetAopForce(func) \
12501 + DySetForce(func, dyaop->da_op, aufs_aop)
12503 +static void dy_aop(struct au_dykey *key, const void *h_op,
12504 + struct super_block *h_sb __maybe_unused)
12506 + struct au_dyaop *dyaop = (void *)key;
12507 + const struct address_space_operations *h_aop = h_op;
12508 + DyDbgDeclare(cnt);
12510 + AuDbg("%s\n", au_sbtype(h_sb));
12512 + DySetAop(writepage);
12513 + DySetAopForce(readpage); /* force */
12514 + DySetAop(writepages);
12515 + DySetAop(set_page_dirty);
12516 + DySetAop(readpages);
12517 + DySetAop(readahead);
12518 + DySetAop(write_begin);
12519 + DySetAop(write_end);
12521 + DySetAop(invalidatepage);
12522 + DySetAop(releasepage);
12523 + DySetAop(freepage);
12524 + /* this one will be changed according to an aufs mount option */
12525 + DySetAop(direct_IO);
12526 + DySetAop(migratepage);
12527 + DySetAop(isolate_page);
12528 + DySetAop(putback_page);
12529 + DySetAop(launder_page);
12530 + DySetAop(is_partially_uptodate);
12531 + DySetAop(is_dirty_writeback);
12532 + DySetAop(error_remove_page);
12533 + DySetAop(swap_activate);
12534 + DySetAop(swap_deactivate);
12536 + DyDbgSize(cnt, *h_aop);
12539 +/* ---------------------------------------------------------------------- */
12541 +static void dy_bug(struct kref *kref)
12546 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12548 + struct au_dykey *key, *old;
12549 + struct hlist_bl_head *hbl;
12552 + void (*set)(struct au_dykey *key, const void *h_op,
12553 + struct super_block *h_sb __maybe_unused);
12555 + static const struct op a[] = {
12557 + .sz = sizeof(struct au_dyaop),
12561 + const struct op *p;
12563 + hbl = dynop + op->dy_type;
12564 + key = dy_gfind_get(hbl, op->dy_hop);
12566 + goto out_add; /* success */
12568 + p = a + op->dy_type;
12569 + key = kzalloc(p->sz, GFP_NOFS);
12570 + if (unlikely(!key)) {
12571 + key = ERR_PTR(-ENOMEM);
12575 + key->dk_op.dy_hop = op->dy_hop;
12576 + kref_init(&key->dk_kref);
12577 + p->set(key, op->dy_hop, au_br_sb(br));
12578 + old = dy_gadd(hbl, key);
12580 + au_kfree_rcu(key);
12585 + old = dy_bradd(br, key);
12587 + /* its ref-count should never be zero here */
12588 + kref_put(&key->dk_kref, dy_bug);
12593 +/* ---------------------------------------------------------------------- */
12595 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12596 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12597 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12598 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12599 + * See the aufs manual in detail.
12601 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12604 + dyaop->da_op.direct_IO = NULL;
12606 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12609 +static struct au_dyaop *dy_aget(struct au_branch *br,
12610 + const struct address_space_operations *h_aop,
12613 + struct au_dyaop *dyaop;
12614 + struct au_dynop op;
12616 + op.dy_type = AuDy_AOP;
12617 + op.dy_haop = h_aop;
12618 + dyaop = (void *)dy_get(&op, br);
12619 + if (IS_ERR(dyaop))
12621 + dy_adx(dyaop, do_dx);
12627 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12628 + struct inode *h_inode)
12631 + struct super_block *sb;
12632 + struct au_branch *br;
12633 + struct au_dyaop *dyaop;
12635 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12636 + IiMustWriteLock(inode);
12638 + sb = inode->i_sb;
12639 + br = au_sbr(sb, bindex);
12640 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12641 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12642 + err = PTR_ERR(dyaop);
12643 + if (IS_ERR(dyaop))
12644 + /* unnecessary to call dy_fput() */
12648 + inode->i_mapping->a_ops = &dyaop->da_op;
12655 + * Is it safe to replace a_ops during the inode/file is in operation?
12656 + * Yes, I hope so.
12658 +int au_dy_irefresh(struct inode *inode)
12661 + aufs_bindex_t btop;
12662 + struct inode *h_inode;
12665 + if (S_ISREG(inode->i_mode)) {
12666 + btop = au_ibtop(inode);
12667 + h_inode = au_h_iptr(inode, btop);
12668 + err = au_dy_iaop(inode, btop, h_inode);
12673 +void au_dy_arefresh(int do_dx)
12675 + struct hlist_bl_head *hbl;
12676 + struct hlist_bl_node *pos;
12677 + struct au_dykey *key;
12679 + hbl = dynop + AuDy_AOP;
12680 + hlist_bl_lock(hbl);
12681 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12682 + dy_adx((void *)key, do_dx);
12683 + hlist_bl_unlock(hbl);
12686 +/* ---------------------------------------------------------------------- */
12688 +void __init au_dy_init(void)
12692 + for (i = 0; i < AuDyLast; i++)
12693 + INIT_HLIST_BL_HEAD(dynop + i);
12696 +void au_dy_fin(void)
12700 + for (i = 0; i < AuDyLast; i++)
12701 + WARN_ON(!hlist_bl_empty(dynop + i));
12703 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12704 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12705 +++ linux/fs/aufs/dynop.h 2020-01-27 10:57:18.168871450 +0100
12707 +/* SPDX-License-Identifier: GPL-2.0 */
12709 + * Copyright (C) 2010-2020 Junjiro R. Okajima
12711 + * This program, aufs is free software; you can redistribute it and/or modify
12712 + * it under the terms of the GNU General Public License as published by
12713 + * the Free Software Foundation; either version 2 of the License, or
12714 + * (at your option) any later version.
12716 + * This program is distributed in the hope that it will be useful,
12717 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12718 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12719 + * GNU General Public License for more details.
12721 + * You should have received a copy of the GNU General Public License
12722 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12726 + * dynamically customizable operations (for regular files only)
12729 +#ifndef __AUFS_DYNOP_H__
12730 +#define __AUFS_DYNOP_H__
12734 +#include <linux/fs.h>
12735 +#include <linux/kref.h>
12737 +enum {AuDy_AOP, AuDyLast};
12742 + const void *dy_hop;
12743 + const struct address_space_operations *dy_haop;
12749 + struct hlist_bl_node dk_hnode;
12750 + struct rcu_head dk_rcu;
12752 + struct au_dynop dk_op;
12755 + * during I am in the branch local array, kref is gotten. when the
12756 + * branch is removed, kref is put.
12758 + struct kref dk_kref;
12761 +/* stop unioning since their sizes are very different from each other */
12763 + struct au_dykey da_key;
12764 + struct address_space_operations da_op; /* not const */
12766 +/* make sure that 'struct au_dykey *' can be any type */
12767 +static_assert(!offsetof(struct au_dyaop, da_key));
12769 +/* ---------------------------------------------------------------------- */
12773 +void au_dy_put(struct au_dykey *key);
12774 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12775 + struct inode *h_inode);
12776 +int au_dy_irefresh(struct inode *inode);
12777 +void au_dy_arefresh(int do_dio);
12779 +void __init au_dy_init(void);
12780 +void au_dy_fin(void);
12782 +#endif /* __KERNEL__ */
12783 +#endif /* __AUFS_DYNOP_H__ */
12784 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12785 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12786 +++ linux/fs/aufs/export.c 2020-12-15 14:10:58.914689728 +0100
12788 +// SPDX-License-Identifier: GPL-2.0
12790 + * Copyright (C) 2005-2020 Junjiro R. Okajima
12792 + * This program, aufs is free software; you can redistribute it and/or modify
12793 + * it under the terms of the GNU General Public License as published by
12794 + * the Free Software Foundation; either version 2 of the License, or
12795 + * (at your option) any later version.
12797 + * This program is distributed in the hope that it will be useful,
12798 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12799 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12800 + * GNU General Public License for more details.
12802 + * You should have received a copy of the GNU General Public License
12803 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12810 +#include <linux/exportfs.h>
12811 +#include <linux/fs_struct.h>
12812 +#include <linux/namei.h>
12813 +#include <linux/nsproxy.h>
12814 +#include <linux/random.h>
12815 +#include <linux/writeback.h>
12819 +#ifdef CONFIG_AUFS_INO_T_64
12827 +static ino_t decode_ino(__u32 *a)
12831 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12833 +#ifdef CONFIG_AUFS_INO_T_64
12839 +static void encode_ino(__u32 *a, ino_t ino)
12845 +#ifdef CONFIG_AUFS_INO_T_64
12850 +/* NFS file handle */
12854 +#ifdef CONFIG_AUFS_INO_T_64
12855 + /* support 64bit inode number */
12868 + Fh_ino = Fh_ino1,
12869 + Fh_dir_ino = Fh_dir_ino1
12872 +static int au_test_anon(struct dentry *dentry)
12874 + /* note: read d_flags without d_lock */
12875 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12878 +int au_test_nfsd(void)
12881 + struct task_struct *tsk = current;
12882 + char comm[sizeof(tsk->comm)];
12885 + if (tsk->flags & PF_KTHREAD) {
12886 + get_task_comm(comm, tsk);
12887 + ret = !strcmp(comm, "nfsd");
12893 +/* ---------------------------------------------------------------------- */
12894 +/* inode generation external table */
12896 +void au_xigen_inc(struct inode *inode)
12901 + struct super_block *sb;
12902 + struct au_sbinfo *sbinfo;
12904 + sb = inode->i_sb;
12905 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12907 + sbinfo = au_sbi(sb);
12908 + pos = inode->i_ino;
12909 + pos *= sizeof(igen);
12910 + igen = inode->i_generation + 1;
12911 + sz = xino_fwrite(sbinfo->si_xigen, &igen, sizeof(igen), &pos);
12912 + if (sz == sizeof(igen))
12913 + return; /* success */
12915 + if (unlikely(sz >= 0))
12916 + AuIOErr("xigen error (%zd)\n", sz);
12919 +int au_xigen_new(struct inode *inode)
12924 + struct super_block *sb;
12925 + struct au_sbinfo *sbinfo;
12926 + struct file *file;
12929 + /* todo: dirty, at mount time */
12930 + if (inode->i_ino == AUFS_ROOT_INO)
12932 + sb = inode->i_sb;
12933 + SiMustAnyLock(sb);
12934 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12938 + pos = inode->i_ino;
12939 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12940 + AuIOErr1("too large i%lld\n", pos);
12943 + pos *= sizeof(inode->i_generation);
12946 + sbinfo = au_sbi(sb);
12947 + file = sbinfo->si_xigen;
12950 + if (vfsub_f_size_read(file)
12951 + < pos + sizeof(inode->i_generation)) {
12952 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12953 + sz = xino_fwrite(file, &inode->i_generation,
12954 + sizeof(inode->i_generation), &pos);
12956 + sz = xino_fread(file, &inode->i_generation,
12957 + sizeof(inode->i_generation), &pos);
12958 + if (sz == sizeof(inode->i_generation))
12959 + goto out; /* success */
12962 + if (unlikely(sz >= 0)) {
12964 + AuIOErr("xigen error (%zd)\n", sz);
12971 +int au_xigen_set(struct super_block *sb, struct path *path)
12974 + struct au_sbinfo *sbinfo;
12975 + struct file *file;
12977 + SiMustWriteLock(sb);
12979 + sbinfo = au_sbi(sb);
12980 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
12981 + err = PTR_ERR(file);
12982 + if (IS_ERR(file))
12985 + if (sbinfo->si_xigen)
12986 + fput(sbinfo->si_xigen);
12987 + sbinfo->si_xigen = file;
12994 +void au_xigen_clr(struct super_block *sb)
12996 + struct au_sbinfo *sbinfo;
12998 + SiMustWriteLock(sb);
13000 + sbinfo = au_sbi(sb);
13001 + if (sbinfo->si_xigen) {
13002 + fput(sbinfo->si_xigen);
13003 + sbinfo->si_xigen = NULL;
13007 +/* ---------------------------------------------------------------------- */
13009 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13012 + struct dentry *dentry, *d;
13013 + struct inode *inode;
13014 + unsigned int sigen;
13017 + inode = ilookup(sb, ino);
13021 + dentry = ERR_PTR(-ESTALE);
13022 + sigen = au_sigen(sb);
13023 + if (unlikely(au_is_bad_inode(inode)
13024 + || IS_DEADDIR(inode)
13025 + || sigen != au_iigen(inode, NULL)))
13029 + if (!dir_ino || S_ISDIR(inode->i_mode))
13030 + dentry = d_find_alias(inode);
13032 + spin_lock(&inode->i_lock);
13033 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13034 + spin_lock(&d->d_lock);
13035 + if (!au_test_anon(d)
13036 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13037 + dentry = dget_dlock(d);
13038 + spin_unlock(&d->d_lock);
13041 + spin_unlock(&d->d_lock);
13043 + spin_unlock(&inode->i_lock);
13045 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13046 + /* need to refresh */
13054 + AuTraceErrPtr(dentry);
13058 +/* ---------------------------------------------------------------------- */
13060 +/* todo: dirty? */
13061 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13063 +struct au_compare_mnt_args {
13065 + struct super_block *sb;
13068 + struct vfsmount *mnt;
13071 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13073 + struct au_compare_mnt_args *a = arg;
13075 + if (mnt->mnt_sb != a->sb)
13077 + a->mnt = mntget(mnt);
13081 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13084 + struct path root;
13085 + struct au_compare_mnt_args args = {
13089 + get_fs_root(current->fs, &root);
13091 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13092 + rcu_read_unlock();
13095 + AuDebugOn(!args.mnt);
13099 +struct au_nfsd_si_lock {
13100 + unsigned int sigen;
13101 + aufs_bindex_t bindex, br_id;
13102 + unsigned char force_lock;
13105 +static int si_nfsd_read_lock(struct super_block *sb,
13106 + struct au_nfsd_si_lock *nsi_lock)
13109 + aufs_bindex_t bindex;
13111 + si_read_lock(sb, AuLock_FLUSH);
13113 + /* branch id may be wrapped around */
13115 + bindex = au_br_index(sb, nsi_lock->br_id);
13116 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13117 + goto out; /* success */
13121 + if (!nsi_lock->force_lock)
13122 + si_read_unlock(sb);
13125 + nsi_lock->bindex = bindex;
13129 +struct find_name_by_ino {
13130 + struct dir_context ctx;
13131 + int called, found;
13138 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13139 + loff_t offset, u64 ino, unsigned int d_type)
13141 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13145 + if (a->ino != ino)
13148 + memcpy(a->name, name, namelen);
13149 + a->namelen = namelen;
13154 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13155 + struct au_nfsd_si_lock *nsi_lock)
13157 + struct dentry *dentry, *parent;
13158 + struct file *file;
13159 + struct inode *dir;
13160 + struct find_name_by_ino arg = {
13162 + .actor = find_name_by_ino
13167 + parent = path->dentry;
13169 + si_read_unlock(parent->d_sb);
13170 + file = vfsub_dentry_open(path, au_dir_roflags);
13171 + dentry = (void *)file;
13172 + if (IS_ERR(file))
13175 + dentry = ERR_PTR(-ENOMEM);
13176 + arg.name = (void *)__get_free_page(GFP_NOFS);
13177 + if (unlikely(!arg.name))
13184 + err = vfsub_iterate_dir(file, &arg.ctx);
13185 + } while (!err && !arg.found && arg.called);
13186 + dentry = ERR_PTR(err);
13187 + if (unlikely(err))
13189 + /* instead of ENOENT */
13190 + dentry = ERR_PTR(-ESTALE);
13194 + /* do not call vfsub_lkup_one() */
13195 + dir = d_inode(parent);
13196 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13197 + AuTraceErrPtr(dentry);
13198 + if (IS_ERR(dentry))
13200 + AuDebugOn(au_test_anon(dentry));
13201 + if (unlikely(d_really_is_negative(dentry))) {
13203 + dentry = ERR_PTR(-ENOENT);
13207 + free_page((unsigned long)arg.name);
13211 + if (unlikely(nsi_lock
13212 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13213 + if (!IS_ERR(dentry)) {
13215 + dentry = ERR_PTR(-ESTALE);
13217 + AuTraceErrPtr(dentry);
13221 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13223 + struct au_nfsd_si_lock *nsi_lock)
13225 + struct dentry *dentry;
13226 + struct path path;
13228 + if (dir_ino != AUFS_ROOT_INO) {
13229 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13230 + dentry = path.dentry;
13231 + if (!path.dentry || IS_ERR(path.dentry))
13233 + AuDebugOn(au_test_anon(path.dentry));
13235 + path.dentry = dget(sb->s_root);
13237 + path.mnt = au_mnt_get(sb);
13238 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13242 + AuTraceErrPtr(dentry);
13246 +/* ---------------------------------------------------------------------- */
13248 +static int h_acceptable(void *expv, struct dentry *dentry)
13253 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13254 + char *buf, int len, struct super_block *sb)
13258 + struct path path;
13260 + p = d_path(h_rootpath, buf, len);
13265 + path.mnt = h_rootpath->mnt;
13266 + path.dentry = h_parent;
13267 + p = d_path(&path, buf, len);
13273 + path.mnt = au_mnt_get(sb);
13274 + path.dentry = sb->s_root;
13275 + p = d_path(&path, buf, len - strlen(p));
13276 + mntput(path.mnt);
13280 + p[strlen(p)] = '/';
13283 + AuTraceErrPtr(p);
13288 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13289 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13291 + struct dentry *dentry, *h_parent, *root;
13292 + struct super_block *h_sb;
13293 + char *pathname, *p;
13294 + struct vfsmount *h_mnt;
13295 + struct au_branch *br;
13297 + struct path path;
13299 + br = au_sbr(sb, nsi_lock->bindex);
13300 + h_mnt = au_br_mnt(br);
13301 + h_sb = h_mnt->mnt_sb;
13302 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13304 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13305 + fh_len - Fh_tail, fh[Fh_h_type],
13306 + h_acceptable, /*context*/NULL);
13308 + dentry = h_parent;
13309 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13310 + AuWarn1("%s decode_fh failed, %ld\n",
13311 + au_sbtype(h_sb), PTR_ERR(h_parent));
13315 + if (unlikely(au_test_anon(h_parent))) {
13316 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13317 + au_sbtype(h_sb));
13318 + goto out_h_parent;
13321 + dentry = ERR_PTR(-ENOMEM);
13322 + pathname = (void *)__get_free_page(GFP_NOFS);
13323 + if (unlikely(!pathname))
13324 + goto out_h_parent;
13326 + root = sb->s_root;
13327 + path.mnt = h_mnt;
13328 + di_read_lock_parent(root, !AuLock_IR);
13329 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13330 + di_read_unlock(root, !AuLock_IR);
13331 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13332 + dentry = (void *)p;
13334 + goto out_pathname;
13336 + si_read_unlock(sb);
13337 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13338 + dentry = ERR_PTR(err);
13339 + if (unlikely(err))
13342 + dentry = ERR_PTR(-ENOENT);
13343 + AuDebugOn(au_test_anon(path.dentry));
13344 + if (unlikely(d_really_is_negative(path.dentry)))
13347 + if (ino != d_inode(path.dentry)->i_ino)
13348 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13350 + dentry = dget(path.dentry);
13355 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13356 + if (!IS_ERR(dentry)) {
13358 + dentry = ERR_PTR(-ESTALE);
13361 + free_page((unsigned long)pathname);
13365 + AuTraceErrPtr(dentry);
13369 +/* ---------------------------------------------------------------------- */
13371 +static struct dentry *
13372 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13375 + struct dentry *dentry;
13376 + __u32 *fh = fid->raw;
13377 + struct au_branch *br;
13378 + ino_t ino, dir_ino;
13379 + struct au_nfsd_si_lock nsi_lock = {
13383 + dentry = ERR_PTR(-ESTALE);
13384 + /* it should never happen, but the file handle is unreliable */
13385 + if (unlikely(fh_len < Fh_tail))
13387 + nsi_lock.sigen = fh[Fh_sigen];
13388 + nsi_lock.br_id = fh[Fh_br_id];
13390 + /* branch id may be wrapped around */
13392 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13394 + nsi_lock.force_lock = 1;
13396 + /* is this inode still cached? */
13397 + ino = decode_ino(fh + Fh_ino);
13398 + /* it should never happen */
13399 + if (unlikely(ino == AUFS_ROOT_INO))
13402 + dir_ino = decode_ino(fh + Fh_dir_ino);
13403 + dentry = decode_by_ino(sb, ino, dir_ino);
13404 + if (IS_ERR(dentry))
13409 + /* is the parent dir cached? */
13410 + br = au_sbr(sb, nsi_lock.bindex);
13411 + au_lcnt_inc(&br->br_nfiles);
13412 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13413 + if (IS_ERR(dentry))
13418 + /* lookup path */
13419 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13420 + if (IS_ERR(dentry))
13422 + if (unlikely(!dentry))
13423 + /* todo?: make it ESTALE */
13427 + if (!au_digen_test(dentry, au_sigen(sb))
13428 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13429 + goto out_unlock; /* success */
13432 + dentry = ERR_PTR(-ESTALE);
13435 + au_lcnt_dec(&br->br_nfiles);
13436 + si_read_unlock(sb);
13438 + AuTraceErrPtr(dentry);
13442 +#if 0 /* reserved for future use */
13443 +/* support subtreecheck option */
13444 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13445 + int fh_len, int fh_type)
13447 + struct dentry *parent;
13448 + __u32 *fh = fid->raw;
13451 + dir_ino = decode_ino(fh + Fh_dir_ino);
13452 + parent = decode_by_ino(sb, dir_ino, 0);
13453 + if (IS_ERR(parent))
13456 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13457 + dir_ino, fh, fh_len);
13460 + AuTraceErrPtr(parent);
13465 +/* ---------------------------------------------------------------------- */
13467 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13468 + struct inode *dir)
13471 + aufs_bindex_t bindex;
13472 + struct super_block *sb, *h_sb;
13473 + struct dentry *dentry, *parent, *h_parent;
13474 + struct inode *h_dir;
13475 + struct au_branch *br;
13478 + if (unlikely(*max_len <= Fh_tail)) {
13479 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13483 + err = FILEID_ROOT;
13484 + if (inode->i_ino == AUFS_ROOT_INO) {
13485 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13490 + sb = inode->i_sb;
13491 + err = si_read_lock(sb, AuLock_FLUSH);
13492 + if (unlikely(err))
13495 +#ifdef CONFIG_AUFS_DEBUG
13496 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13497 + AuWarn1("NFS-exporting requires xino\n");
13501 + ii_read_lock_child(inode);
13502 + bindex = au_ibtop(inode);
13504 + dentry = d_find_any_alias(inode);
13505 + if (unlikely(!dentry))
13507 + AuDebugOn(au_test_anon(dentry));
13508 + parent = dget_parent(dentry);
13510 + if (unlikely(!parent))
13512 + if (d_really_is_positive(parent))
13513 + dir = d_inode(parent);
13516 + ii_read_lock_parent(dir);
13517 + h_dir = au_h_iptr(dir, bindex);
13518 + ii_read_unlock(dir);
13519 + if (unlikely(!h_dir))
13521 + h_parent = d_find_any_alias(h_dir);
13522 + if (unlikely(!h_parent))
13523 + goto out_hparent;
13526 + br = au_sbr(sb, bindex);
13527 + h_sb = au_br_sb(br);
13528 + if (unlikely(!h_sb->s_export_op)) {
13529 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13530 + goto out_hparent;
13533 + fh[Fh_br_id] = br->br_id;
13534 + fh[Fh_sigen] = au_sigen(sb);
13535 + encode_ino(fh + Fh_ino, inode->i_ino);
13536 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13537 + fh[Fh_igen] = inode->i_generation;
13539 + *max_len -= Fh_tail;
13540 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13542 + /*connectable or subtreecheck*/0);
13543 + err = fh[Fh_h_type];
13544 + *max_len += Fh_tail;
13545 + /* todo: macros? */
13546 + if (err != FILEID_INVALID)
13549 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13556 + ii_read_unlock(inode);
13557 + si_read_unlock(sb);
13559 + if (unlikely(err < 0))
13560 + err = FILEID_INVALID;
13564 +/* ---------------------------------------------------------------------- */
13566 +static int aufs_commit_metadata(struct inode *inode)
13569 + aufs_bindex_t bindex;
13570 + struct super_block *sb;
13571 + struct inode *h_inode;
13572 + int (*f)(struct inode *inode);
13574 + sb = inode->i_sb;
13575 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13576 + ii_write_lock_child(inode);
13577 + bindex = au_ibtop(inode);
13578 + AuDebugOn(bindex < 0);
13579 + h_inode = au_h_iptr(inode, bindex);
13581 + f = h_inode->i_sb->s_export_op->commit_metadata;
13583 + err = f(h_inode);
13585 + struct writeback_control wbc = {
13586 + .sync_mode = WB_SYNC_ALL,
13587 + .nr_to_write = 0 /* metadata only */
13590 + err = sync_inode(h_inode, &wbc);
13593 + au_cpup_attr_timesizes(inode);
13594 + ii_write_unlock(inode);
13595 + si_read_unlock(sb);
13599 +/* ---------------------------------------------------------------------- */
13601 +static struct export_operations aufs_export_op = {
13602 + .fh_to_dentry = aufs_fh_to_dentry,
13603 + /* .fh_to_parent = aufs_fh_to_parent, */
13604 + .encode_fh = aufs_encode_fh,
13605 + .commit_metadata = aufs_commit_metadata
13608 +void au_export_init(struct super_block *sb)
13610 + struct au_sbinfo *sbinfo;
13613 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13614 + && IS_MODULE(CONFIG_EXPORTFS),
13615 + AUFS_NAME ": unsupported configuration "
13616 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13618 + sb->s_export_op = &aufs_export_op;
13619 + sbinfo = au_sbi(sb);
13620 + sbinfo->si_xigen = NULL;
13621 + get_random_bytes(&u, sizeof(u));
13622 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13623 + atomic_set(&sbinfo->si_xigen_next, u);
13625 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13626 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13627 +++ linux/fs/aufs/fhsm.c 2020-01-27 10:57:18.172204883 +0100
13629 +// SPDX-License-Identifier: GPL-2.0
13631 + * Copyright (C) 2011-2020 Junjiro R. Okajima
13633 + * This program, aufs is free software; you can redistribute it and/or modify
13634 + * it under the terms of the GNU General Public License as published by
13635 + * the Free Software Foundation; either version 2 of the License, or
13636 + * (at your option) any later version.
13638 + * This program is distributed in the hope that it will be useful,
13639 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13640 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13641 + * GNU General Public License for more details.
13643 + * You should have received a copy of the GNU General Public License
13644 + * along with this program; if not, write to the Free Software
13645 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13649 + * File-based Hierarchy Storage Management
13652 +#include <linux/anon_inodes.h>
13653 +#include <linux/poll.h>
13654 +#include <linux/seq_file.h>
13655 +#include <linux/statfs.h>
13658 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13660 + struct au_sbinfo *sbinfo;
13661 + struct au_fhsm *fhsm;
13663 + SiMustAnyLock(sb);
13665 + sbinfo = au_sbi(sb);
13666 + fhsm = &sbinfo->si_fhsm;
13667 + AuDebugOn(!fhsm);
13668 + return fhsm->fhsm_bottom;
13671 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13673 + struct au_sbinfo *sbinfo;
13674 + struct au_fhsm *fhsm;
13676 + SiMustWriteLock(sb);
13678 + sbinfo = au_sbi(sb);
13679 + fhsm = &sbinfo->si_fhsm;
13680 + AuDebugOn(!fhsm);
13681 + fhsm->fhsm_bottom = bindex;
13684 +/* ---------------------------------------------------------------------- */
13686 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13688 + struct au_br_fhsm *bf;
13690 + bf = br->br_fhsm;
13691 + MtxMustLock(&bf->bf_lock);
13693 + return !bf->bf_readable
13694 + || time_after(jiffies,
13695 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13698 +/* ---------------------------------------------------------------------- */
13700 +static void au_fhsm_notify(struct super_block *sb, int val)
13702 + struct au_sbinfo *sbinfo;
13703 + struct au_fhsm *fhsm;
13705 + SiMustAnyLock(sb);
13707 + sbinfo = au_sbi(sb);
13708 + fhsm = &sbinfo->si_fhsm;
13709 + if (au_fhsm_pid(fhsm)
13710 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13711 + atomic_set(&fhsm->fhsm_readable, val);
13713 + wake_up(&fhsm->fhsm_wqh);
13717 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13718 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13721 + struct au_branch *br;
13722 + struct au_br_fhsm *bf;
13724 + br = au_sbr(sb, bindex);
13725 + AuDebugOn(au_br_rdonly(br));
13726 + bf = br->br_fhsm;
13730 + mutex_lock(&bf->bf_lock);
13732 + MtxMustLock(&bf->bf_lock);
13734 + /* sb->s_root for NFS is unreliable */
13735 + err = au_br_stfs(br, &bf->bf_stfs);
13736 + if (unlikely(err)) {
13737 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13741 + bf->bf_jiffy = jiffies;
13742 + bf->bf_readable = 1;
13744 + au_fhsm_notify(sb, /*val*/1);
13746 + *rstfs = bf->bf_stfs;
13750 + mutex_unlock(&bf->bf_lock);
13751 + au_fhsm_notify(sb, /*val*/1);
13756 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13759 + struct au_sbinfo *sbinfo;
13760 + struct au_fhsm *fhsm;
13761 + struct au_branch *br;
13762 + struct au_br_fhsm *bf;
13764 + AuDbg("b%d, force %d\n", bindex, force);
13765 + SiMustAnyLock(sb);
13767 + sbinfo = au_sbi(sb);
13768 + fhsm = &sbinfo->si_fhsm;
13769 + if (!au_ftest_si(sbinfo, FHSM)
13770 + || fhsm->fhsm_bottom == bindex)
13773 + br = au_sbr(sb, bindex);
13774 + bf = br->br_fhsm;
13776 + mutex_lock(&bf->bf_lock);
13778 + || au_fhsm_pid(fhsm)
13779 + || au_fhsm_test_jiffy(sbinfo, br))
13780 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13782 + mutex_unlock(&bf->bf_lock);
13785 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13787 + aufs_bindex_t bindex, bbot;
13788 + struct au_branch *br;
13790 + /* exclude the bottom */
13791 + bbot = au_fhsm_bottom(sb);
13792 + for (bindex = 0; bindex < bbot; bindex++) {
13793 + br = au_sbr(sb, bindex);
13794 + if (au_br_fhsm(br->br_perm))
13795 + au_fhsm_wrote(sb, bindex, force);
13799 +/* ---------------------------------------------------------------------- */
13801 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13804 + struct au_sbinfo *sbinfo;
13805 + struct au_fhsm *fhsm;
13808 + sbinfo = file->private_data;
13809 + fhsm = &sbinfo->si_fhsm;
13810 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13811 + if (atomic_read(&fhsm->fhsm_readable))
13812 + mask = EPOLLIN /* | EPOLLRDNORM */;
13815 + AuDbg("mask 0x%x\n", mask);
13819 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13820 + struct aufs_stfs *stfs, __s16 brid)
13824 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13826 + err = __put_user(brid, &stbr->brid);
13827 + if (unlikely(err))
13833 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13834 + struct aufs_stbr __user *stbr, size_t count)
13838 + aufs_bindex_t bindex, bbot;
13839 + struct au_branch *br;
13840 + struct au_br_fhsm *bf;
13842 + /* except the bottom branch */
13845 + bbot = au_fhsm_bottom(sb);
13846 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13847 + br = au_sbr(sb, bindex);
13848 + if (!au_br_fhsm(br->br_perm))
13851 + bf = br->br_fhsm;
13852 + mutex_lock(&bf->bf_lock);
13853 + if (bf->bf_readable) {
13855 + if (count >= sizeof(*stbr))
13856 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13859 + bf->bf_readable = 0;
13860 + count -= sizeof(*stbr);
13864 + mutex_unlock(&bf->bf_lock);
13867 + err = sizeof(*stbr) * nstbr;
13872 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13877 + aufs_bindex_t nfhsm, bindex, bbot;
13878 + struct au_sbinfo *sbinfo;
13879 + struct au_fhsm *fhsm;
13880 + struct au_branch *br;
13881 + struct super_block *sb;
13884 + sbinfo = file->private_data;
13885 + fhsm = &sbinfo->si_fhsm;
13887 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13888 + if (!atomic_read(&fhsm->fhsm_readable)) {
13889 + if (vfsub_file_flags(file) & O_NONBLOCK)
13892 + err = wait_event_interruptible_locked_irq
13894 + atomic_read(&fhsm->fhsm_readable));
13896 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13897 + if (unlikely(err))
13900 + /* sb may already be dead */
13901 + au_rw_read_lock(&sbinfo->si_rwsem);
13902 + readable = atomic_read(&fhsm->fhsm_readable);
13903 + if (readable > 0) {
13904 + sb = sbinfo->si_sb;
13906 + /* exclude the bottom branch */
13908 + bbot = au_fhsm_bottom(sb);
13909 + for (bindex = 0; bindex < bbot; bindex++) {
13910 + br = au_sbr(sb, bindex);
13911 + if (au_br_fhsm(br->br_perm))
13915 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13916 + atomic_set(&fhsm->fhsm_readable, 0);
13917 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13921 + au_rw_read_unlock(&sbinfo->si_rwsem);
13929 +static int au_fhsm_release(struct inode *inode, struct file *file)
13931 + struct au_sbinfo *sbinfo;
13932 + struct au_fhsm *fhsm;
13934 + /* sb may already be dead */
13935 + sbinfo = file->private_data;
13936 + fhsm = &sbinfo->si_fhsm;
13937 + spin_lock(&fhsm->fhsm_spin);
13938 + fhsm->fhsm_pid = 0;
13939 + spin_unlock(&fhsm->fhsm_spin);
13940 + kobject_put(&sbinfo->si_kobj);
13945 +static const struct file_operations au_fhsm_fops = {
13946 + .owner = THIS_MODULE,
13947 + .llseek = noop_llseek,
13948 + .read = au_fhsm_read,
13949 + .poll = au_fhsm_poll,
13950 + .release = au_fhsm_release
13953 +int au_fhsm_fd(struct super_block *sb, int oflags)
13956 + struct au_sbinfo *sbinfo;
13957 + struct au_fhsm *fhsm;
13960 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13964 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13968 + sbinfo = au_sbi(sb);
13969 + fhsm = &sbinfo->si_fhsm;
13970 + spin_lock(&fhsm->fhsm_spin);
13971 + if (!fhsm->fhsm_pid)
13972 + fhsm->fhsm_pid = current->pid;
13975 + spin_unlock(&fhsm->fhsm_spin);
13976 + if (unlikely(err))
13979 + oflags |= O_RDONLY;
13980 + /* oflags |= FMODE_NONOTIFY; */
13981 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
13983 + if (unlikely(fd < 0))
13986 + /* succeed regardless 'fhsm' status */
13987 + kobject_get(&sbinfo->si_kobj);
13988 + si_noflush_read_lock(sb);
13989 + if (au_ftest_si(sbinfo, FHSM))
13990 + au_fhsm_wrote_all(sb, /*force*/0);
13991 + si_read_unlock(sb);
13992 + goto out; /* success */
13995 + spin_lock(&fhsm->fhsm_spin);
13996 + fhsm->fhsm_pid = 0;
13997 + spin_unlock(&fhsm->fhsm_spin);
14003 +/* ---------------------------------------------------------------------- */
14005 +int au_fhsm_br_alloc(struct au_branch *br)
14010 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14012 + au_br_fhsm_init(br->br_fhsm);
14019 +/* ---------------------------------------------------------------------- */
14021 +void au_fhsm_fin(struct super_block *sb)
14023 + au_fhsm_notify(sb, /*val*/-1);
14026 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14028 + struct au_fhsm *fhsm;
14030 + fhsm = &sbinfo->si_fhsm;
14031 + spin_lock_init(&fhsm->fhsm_spin);
14032 + init_waitqueue_head(&fhsm->fhsm_wqh);
14033 + atomic_set(&fhsm->fhsm_readable, 0);
14034 + fhsm->fhsm_expire
14035 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14036 + fhsm->fhsm_bottom = -1;
14039 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14041 + sbinfo->si_fhsm.fhsm_expire
14042 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14045 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14049 + if (!au_ftest_si(sbinfo, FHSM))
14052 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14053 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14054 + seq_printf(seq, ",fhsm_sec=%u", u);
14056 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14057 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14058 +++ linux/fs/aufs/file.c 2020-12-15 14:10:58.918023162 +0100
14060 +// SPDX-License-Identifier: GPL-2.0
14062 + * Copyright (C) 2005-2020 Junjiro R. Okajima
14064 + * This program, aufs is free software; you can redistribute it and/or modify
14065 + * it under the terms of the GNU General Public License as published by
14066 + * the Free Software Foundation; either version 2 of the License, or
14067 + * (at your option) any later version.
14069 + * This program is distributed in the hope that it will be useful,
14070 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14071 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14072 + * GNU General Public License for more details.
14074 + * You should have received a copy of the GNU General Public License
14075 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14079 + * handling file/dir, and address_space operation
14082 +#ifdef CONFIG_AUFS_DEBUG
14083 +#include <linux/migrate.h>
14085 +#include <linux/pagemap.h>
14088 +/* drop flags for writing */
14089 +unsigned int au_file_roflags(unsigned int flags)
14091 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14092 + flags |= O_RDONLY | O_NOATIME;
14096 +/* common functions to regular file and dir */
14097 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14098 + struct file *file, int force_wr)
14100 + struct file *h_file;
14101 + struct dentry *h_dentry;
14102 + struct inode *h_inode;
14103 + struct super_block *sb;
14104 + struct au_branch *br;
14105 + struct path h_path;
14108 + /* a race condition can happen between open and unlink/rmdir */
14109 + h_file = ERR_PTR(-ENOENT);
14110 + h_dentry = au_h_dptr(dentry, bindex);
14111 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14113 + h_inode = d_inode(h_dentry);
14114 + spin_lock(&h_dentry->d_lock);
14115 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14116 + /* || !d_inode(dentry)->i_nlink */
14118 + spin_unlock(&h_dentry->d_lock);
14119 + if (unlikely(err))
14122 + sb = dentry->d_sb;
14123 + br = au_sbr(sb, bindex);
14124 + err = au_br_test_oflag(flags, br);
14125 + h_file = ERR_PTR(err);
14126 + if (unlikely(err))
14129 + /* drop flags for writing */
14130 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14131 + if (force_wr && !(flags & O_WRONLY))
14133 + flags = au_file_roflags(flags);
14135 + h_file = ERR_PTR(-EROFS);
14136 + flags = au_file_roflags(flags);
14137 + if (unlikely(vfsub_native_ro(h_inode)
14138 + || IS_APPEND(h_inode)))
14140 + flags &= ~O_ACCMODE;
14141 + flags |= O_WRONLY;
14144 + flags &= ~O_CREAT;
14145 + au_lcnt_inc(&br->br_nfiles);
14146 + h_path.dentry = h_dentry;
14147 + h_path.mnt = au_br_mnt(br);
14148 + h_file = vfsub_dentry_open(&h_path, flags);
14149 + if (IS_ERR(h_file))
14152 + if (flags & __FMODE_EXEC) {
14153 + err = deny_write_access(h_file);
14154 + if (unlikely(err)) {
14156 + h_file = ERR_PTR(err);
14160 + fsnotify_open(h_file);
14161 + goto out; /* success */
14164 + au_lcnt_dec(&br->br_nfiles);
14169 +static int au_cmoo(struct dentry *dentry)
14171 + int err, cmoo, matched;
14172 + unsigned int udba;
14173 + struct path h_path;
14174 + struct au_pin pin;
14175 + struct au_cp_generic cpg = {
14176 + .dentry = dentry,
14181 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14183 + struct inode *delegated;
14184 + struct super_block *sb;
14185 + struct au_sbinfo *sbinfo;
14186 + struct au_fhsm *fhsm;
14188 + struct au_branch *br;
14189 + struct dentry *parent;
14190 + struct au_hinode *hdir;
14192 + DiMustWriteLock(dentry);
14193 + IiMustWriteLock(d_inode(dentry));
14196 + if (IS_ROOT(dentry))
14198 + cpg.bsrc = au_dbtop(dentry);
14202 + sb = dentry->d_sb;
14203 + sbinfo = au_sbi(sb);
14204 + fhsm = &sbinfo->si_fhsm;
14205 + pid = au_fhsm_pid(fhsm);
14208 + && (current->pid == pid
14209 + || rcu_dereference(current->real_parent)->pid == pid));
14210 + rcu_read_unlock();
14214 + br = au_sbr(sb, cpg.bsrc);
14215 + cmoo = au_br_cmoo(br->br_perm);
14218 + if (!d_is_reg(dentry))
14219 + cmoo &= AuBrAttr_COO_ALL;
14223 + parent = dget_parent(dentry);
14224 + di_write_lock_parent(parent);
14225 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14227 + if (unlikely(err < 0)) {
14228 + err = 0; /* there is no upper writable branch */
14231 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14233 + /* do not respect the coo attrib for the target branch */
14234 + err = au_cpup_dirs(dentry, cpg.bdst);
14235 + if (unlikely(err))
14238 + di_downgrade_lock(parent, AuLock_IR);
14239 + udba = au_opt_udba(sb);
14240 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14241 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14242 + if (unlikely(err))
14245 + err = au_sio_cpup_simple(&cpg);
14247 + if (unlikely(err))
14249 + if (!(cmoo & AuBrWAttr_MOO))
14250 + goto out_parent; /* success */
14252 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14253 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14254 + if (unlikely(err))
14257 + h_path.mnt = au_br_mnt(br);
14258 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14259 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14260 + delegated = NULL;
14261 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14263 + /* todo: keep h_dentry or not? */
14264 + if (unlikely(err == -EWOULDBLOCK)) {
14265 + pr_warn("cannot retry for NFSv4 delegation"
14266 + " for an internal unlink\n");
14269 + if (unlikely(err)) {
14270 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14274 + goto out_parent; /* success */
14277 + di_downgrade_lock(parent, AuLock_IR);
14279 + di_read_unlock(parent, AuLock_IR);
14286 +int au_do_open(struct file *file, struct au_do_open_args *args)
14288 + int err, aopen = args->aopen;
14289 + struct dentry *dentry;
14290 + struct au_finfo *finfo;
14293 + err = au_finfo_init(file, args->fidir);
14296 + err = au_finfo_init(file, args->fidir);
14299 + if (unlikely(err))
14302 + dentry = file->f_path.dentry;
14303 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14304 + di_write_lock_child(dentry);
14305 + err = au_cmoo(dentry);
14306 + di_downgrade_lock(dentry, AuLock_IR);
14309 + err = args->open(file, vfsub_file_flags(file), NULL);
14312 + err = args->open(file, vfsub_file_flags(file),
14317 + di_read_unlock(dentry, AuLock_IR);
14319 + finfo = au_fi(file);
14321 + finfo->fi_file = file;
14322 + au_hbl_add(&finfo->fi_hlist,
14323 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14326 + fi_write_unlock(file);
14329 + fi_write_unlock(file);
14332 + if (unlikely(err)) {
14333 + finfo->fi_hdir = NULL;
14334 + au_finfo_fin(file);
14342 +int au_reopen_nondir(struct file *file)
14345 + aufs_bindex_t btop;
14346 + struct dentry *dentry;
14347 + struct au_branch *br;
14348 + struct file *h_file, *h_file_tmp;
14350 + dentry = file->f_path.dentry;
14351 + btop = au_dbtop(dentry);
14352 + br = au_sbr(dentry->d_sb, btop);
14353 + h_file_tmp = NULL;
14354 + if (au_fbtop(file) == btop) {
14355 + h_file = au_hf_top(file);
14356 + if (file->f_mode == h_file->f_mode)
14357 + return 0; /* success */
14358 + h_file_tmp = h_file;
14359 + get_file(h_file_tmp);
14360 + au_lcnt_inc(&br->br_nfiles);
14361 + au_set_h_fptr(file, btop, NULL);
14363 + AuDebugOn(au_fi(file)->fi_hdir);
14366 + * file exists on both of rw and ro
14367 + * open --> dbtop and fbtop are both 0
14368 + * prepend a branch as rw, "rw" become ro
14370 + * delete the top branch, "rw" becomes rw again
14371 + * --> dbtop is 1, fbtop is still 0
14372 + * write --> fbtop is 0 but dbtop is 1
14374 + /* AuDebugOn(au_fbtop(file) < btop); */
14376 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14377 + file, /*force_wr*/0);
14378 + err = PTR_ERR(h_file);
14379 + if (IS_ERR(h_file)) {
14380 + if (h_file_tmp) {
14382 + au_set_h_fptr(file, btop, h_file_tmp);
14383 + h_file_tmp = NULL;
14385 + goto out; /* todo: close all? */
14389 + au_set_fbtop(file, btop);
14390 + au_set_h_fptr(file, btop, h_file);
14391 + au_update_figen(file);
14392 + /* todo: necessary? */
14393 + /* file->f_ra = h_file->f_ra; */
14396 + if (h_file_tmp) {
14397 + fput(h_file_tmp);
14398 + au_lcnt_dec(&br->br_nfiles);
14403 +/* ---------------------------------------------------------------------- */
14405 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14406 + struct dentry *hi_wh)
14409 + aufs_bindex_t btop;
14410 + struct au_dinfo *dinfo;
14411 + struct dentry *h_dentry;
14412 + struct au_hdentry *hdp;
14414 + dinfo = au_di(file->f_path.dentry);
14415 + AuRwMustWriteLock(&dinfo->di_rwsem);
14417 + btop = dinfo->di_btop;
14418 + dinfo->di_btop = btgt;
14419 + hdp = au_hdentry(dinfo, btgt);
14420 + h_dentry = hdp->hd_dentry;
14421 + hdp->hd_dentry = hi_wh;
14422 + err = au_reopen_nondir(file);
14423 + hdp->hd_dentry = h_dentry;
14424 + dinfo->di_btop = btop;
14429 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14430 + aufs_bindex_t bcpup, struct au_pin *pin)
14433 + struct inode *inode, *h_inode;
14434 + struct dentry *h_dentry, *hi_wh;
14435 + struct au_cp_generic cpg = {
14436 + .dentry = file->f_path.dentry,
14443 + au_update_dbtop(cpg.dentry);
14444 + inode = d_inode(cpg.dentry);
14446 + if (au_dbtop(cpg.dentry) <= bcpup
14447 + && au_dbbot(cpg.dentry) >= bcpup) {
14448 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14449 + if (h_dentry && d_is_positive(h_dentry))
14450 + h_inode = d_inode(h_dentry);
14452 + hi_wh = au_hi_wh(inode, bcpup);
14453 + if (!hi_wh && !h_inode)
14454 + err = au_sio_cpup_wh(&cpg, file);
14456 + /* already copied-up after unlink */
14457 + err = au_reopen_wh(file, bcpup, hi_wh);
14460 + && (inode->i_nlink > 1
14461 + || (inode->i_state & I_LINKABLE))
14462 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14463 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14469 + * prepare the @file for writing.
14471 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14474 + aufs_bindex_t dbtop;
14475 + struct dentry *parent;
14476 + struct inode *inode;
14477 + struct super_block *sb;
14478 + struct file *h_file;
14479 + struct au_cp_generic cpg = {
14480 + .dentry = file->f_path.dentry,
14485 + .flags = AuCpup_DTIME
14488 + sb = cpg.dentry->d_sb;
14489 + inode = d_inode(cpg.dentry);
14490 + cpg.bsrc = au_fbtop(file);
14491 + err = au_test_ro(sb, cpg.bsrc, inode);
14492 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14493 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14498 + /* need to cpup or reopen */
14499 + parent = dget_parent(cpg.dentry);
14500 + di_write_lock_parent(parent);
14501 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14503 + if (unlikely(err < 0))
14507 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14508 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14509 + if (unlikely(err))
14513 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14514 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14515 + if (unlikely(err))
14518 + dbtop = au_dbtop(cpg.dentry);
14519 + if (dbtop <= cpg.bdst)
14520 + cpg.bsrc = cpg.bdst;
14522 + if (dbtop <= cpg.bdst /* just reopen */
14523 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14525 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14526 + if (IS_ERR(h_file))
14527 + err = PTR_ERR(h_file);
14529 + di_downgrade_lock(parent, AuLock_IR);
14530 + if (dbtop > cpg.bdst)
14531 + err = au_sio_cpup_simple(&cpg);
14533 + err = au_reopen_nondir(file);
14534 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14536 + } else { /* copyup as wh and reopen */
14538 + * since writable hfsplus branch is not supported,
14539 + * h_open_pre/post() are unnecessary.
14541 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14542 + di_downgrade_lock(parent, AuLock_IR);
14546 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14547 + goto out_dput; /* success */
14553 + di_downgrade_lock(parent, AuLock_IR);
14555 + di_read_unlock(parent, AuLock_IR);
14562 +/* ---------------------------------------------------------------------- */
14564 +int au_do_flush(struct file *file, fl_owner_t id,
14565 + int (*flush)(struct file *file, fl_owner_t id))
14568 + struct super_block *sb;
14569 + struct inode *inode;
14571 + inode = file_inode(file);
14572 + sb = inode->i_sb;
14573 + si_noflush_read_lock(sb);
14574 + fi_read_lock(file);
14575 + ii_read_lock_child(inode);
14577 + err = flush(file, id);
14578 + au_cpup_attr_timesizes(inode);
14580 + ii_read_unlock(inode);
14581 + fi_read_unlock(file);
14582 + si_read_unlock(sb);
14586 +/* ---------------------------------------------------------------------- */
14588 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14591 + struct au_pin pin;
14592 + struct au_finfo *finfo;
14593 + struct dentry *parent, *hi_wh;
14594 + struct inode *inode;
14595 + struct super_block *sb;
14596 + struct au_cp_generic cpg = {
14597 + .dentry = file->f_path.dentry,
14602 + .flags = AuCpup_DTIME
14605 + FiMustWriteLock(file);
14608 + finfo = au_fi(file);
14609 + sb = cpg.dentry->d_sb;
14610 + inode = d_inode(cpg.dentry);
14611 + cpg.bdst = au_ibtop(inode);
14612 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14615 + parent = dget_parent(cpg.dentry);
14616 + if (au_test_ro(sb, cpg.bdst, inode)) {
14617 + di_read_lock_parent(parent, !AuLock_IR);
14618 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14620 + di_read_unlock(parent, !AuLock_IR);
14621 + if (unlikely(err < 0))
14626 + di_read_lock_parent(parent, AuLock_IR);
14627 + hi_wh = au_hi_wh(inode, cpg.bdst);
14628 + if (!S_ISDIR(inode->i_mode)
14629 + && au_opt_test(au_mntflags(sb), PLINK)
14630 + && au_plink_test(inode)
14631 + && !d_unhashed(cpg.dentry)
14632 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14633 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14634 + if (unlikely(err))
14637 + /* always superio. */
14638 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14639 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14641 + err = au_sio_cpup_simple(&cpg);
14644 + } else if (hi_wh) {
14645 + /* already copied-up after unlink */
14646 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14647 + *need_reopen = 0;
14651 + di_read_unlock(parent, AuLock_IR);
14658 +static void au_do_refresh_dir(struct file *file)
14660 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14661 + struct au_hfile *p, tmp, *q;
14662 + struct au_finfo *finfo;
14663 + struct super_block *sb;
14664 + struct au_fidir *fidir;
14666 + FiMustWriteLock(file);
14668 + sb = file->f_path.dentry->d_sb;
14669 + finfo = au_fi(file);
14670 + fidir = finfo->fi_hdir;
14671 + AuDebugOn(!fidir);
14672 + p = fidir->fd_hfile + finfo->fi_btop;
14673 + brid = p->hf_br->br_id;
14674 + bbot = fidir->fd_bbot;
14675 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14679 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14680 + if (new_bindex == bindex)
14682 + if (new_bindex < 0) {
14683 + au_set_h_fptr(file, bindex, NULL);
14687 + /* swap two lower inode, and loop again */
14688 + q = fidir->fd_hfile + new_bindex;
14692 + if (tmp.hf_file) {
14698 + p = fidir->fd_hfile;
14699 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14700 + bbot = au_sbbot(sb);
14701 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14702 + finfo->fi_btop++, p++)
14703 + if (p->hf_file) {
14704 + if (file_inode(p->hf_file))
14706 + au_hfput(p, /*execed*/0);
14709 + bbot = au_br_index(sb, brid);
14710 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14711 + finfo->fi_btop++, p++)
14713 + au_hfput(p, /*execed*/0);
14714 + bbot = au_sbbot(sb);
14717 + p = fidir->fd_hfile + bbot;
14718 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14719 + fidir->fd_bbot--, p--)
14720 + if (p->hf_file) {
14721 + if (file_inode(p->hf_file))
14723 + au_hfput(p, /*execed*/0);
14725 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14729 + * after branch manipulating, refresh the file.
14731 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14733 + int err, need_reopen, nbr;
14734 + aufs_bindex_t bbot, bindex;
14735 + struct dentry *dentry;
14736 + struct super_block *sb;
14737 + struct au_finfo *finfo;
14738 + struct au_hfile *hfile;
14740 + dentry = file->f_path.dentry;
14741 + sb = dentry->d_sb;
14742 + nbr = au_sbbot(sb) + 1;
14743 + finfo = au_fi(file);
14744 + if (!finfo->fi_hdir) {
14745 + hfile = &finfo->fi_htop;
14746 + AuDebugOn(!hfile->hf_file);
14747 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14748 + AuDebugOn(bindex < 0);
14749 + if (bindex != finfo->fi_btop)
14750 + au_set_fbtop(file, bindex);
14752 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14753 + if (unlikely(err))
14755 + au_do_refresh_dir(file);
14760 + if (!au_test_mmapped(file))
14761 + err = au_file_refresh_by_inode(file, &need_reopen);
14762 + if (finfo->fi_hdir)
14763 + /* harmless if err */
14764 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14765 + if (!err && need_reopen && !d_unlinked(dentry))
14766 + err = reopen(file);
14768 + au_update_figen(file);
14769 + goto out; /* success */
14772 + /* error, close all lower files */
14773 + if (finfo->fi_hdir) {
14774 + bbot = au_fbbot_dir(file);
14775 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14776 + au_set_h_fptr(file, bindex, NULL);
14783 +/* common function to regular file and dir */
14784 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14785 + int wlock, unsigned int fi_lsc)
14788 + unsigned int sigen, figen;
14789 + aufs_bindex_t btop;
14790 + unsigned char pseudo_link;
14791 + struct dentry *dentry;
14792 + struct inode *inode;
14795 + dentry = file->f_path.dentry;
14796 + inode = d_inode(dentry);
14797 + sigen = au_sigen(dentry->d_sb);
14798 + fi_write_lock_nested(file, fi_lsc);
14799 + figen = au_figen(file);
14801 + di_write_lock_child(dentry);
14803 + di_write_lock_child2(dentry);
14804 + btop = au_dbtop(dentry);
14805 + pseudo_link = (btop != au_ibtop(inode));
14806 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14808 + di_downgrade_lock(dentry, AuLock_IR);
14809 + fi_downgrade_lock(file);
14811 + goto out; /* success */
14814 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14815 + if (au_digen_test(dentry, sigen)) {
14816 + err = au_reval_dpath(dentry, sigen);
14817 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14821 + err = refresh_file(file, reopen);
14824 + di_downgrade_lock(dentry, AuLock_IR);
14825 + fi_downgrade_lock(file);
14828 + di_write_unlock(dentry);
14829 + fi_write_unlock(file);
14836 +/* ---------------------------------------------------------------------- */
14838 +/* cf. aufs_nopage() */
14839 +/* for madvise(2) */
14840 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14842 + unlock_page(page);
14846 +/* it will never be called, but necessary to support O_DIRECT */
14847 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14848 +{ BUG(); return 0; }
14850 +/* they will never be called. */
14851 +#ifdef CONFIG_AUFS_DEBUG
14853 +void aufs_readahead(struct readahead_control *)
14854 +{ AuUnsupport(); }
14856 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14857 + loff_t pos, unsigned len, unsigned flags,
14858 + struct page **pagep, void **fsdata)
14859 +{ AuUnsupport(); return 0; }
14860 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14861 + loff_t pos, unsigned len, unsigned copied,
14862 + struct page *page, void *fsdata)
14863 +{ AuUnsupport(); return 0; }
14864 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14865 +{ AuUnsupport(); return 0; }
14867 +static int aufs_set_page_dirty(struct page *page)
14868 +{ AuUnsupport(); return 0; }
14869 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14870 + unsigned int length)
14871 +{ AuUnsupport(); }
14872 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14873 +{ AuUnsupport(); return 0; }
14874 +#if 0 /* called by memory compaction regardless file */
14875 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14876 + struct page *page, enum migrate_mode mode)
14877 +{ AuUnsupport(); return 0; }
14879 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14880 +{ AuUnsupport(); return true; }
14881 +static void aufs_putback_page(struct page *page)
14882 +{ AuUnsupport(); }
14883 +static int aufs_launder_page(struct page *page)
14884 +{ AuUnsupport(); return 0; }
14885 +static int aufs_is_partially_uptodate(struct page *page,
14886 + unsigned long from,
14887 + unsigned long count)
14888 +{ AuUnsupport(); return 0; }
14889 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14891 +{ AuUnsupport(); }
14892 +static int aufs_error_remove_page(struct address_space *mapping,
14893 + struct page *page)
14894 +{ AuUnsupport(); return 0; }
14895 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14897 +{ AuUnsupport(); return 0; }
14898 +static void aufs_swap_deactivate(struct file *file)
14899 +{ AuUnsupport(); }
14900 +#endif /* CONFIG_AUFS_DEBUG */
14902 +const struct address_space_operations aufs_aop = {
14903 + .readpage = aufs_readpage,
14904 + .direct_IO = aufs_direct_IO,
14905 +#ifdef CONFIG_AUFS_DEBUG
14906 + .writepage = aufs_writepage,
14907 + /* no writepages, because of writepage */
14908 + .set_page_dirty = aufs_set_page_dirty,
14909 + /* no readpages, because of readpage */
14910 + .write_begin = aufs_write_begin,
14911 + .write_end = aufs_write_end,
14912 + /* no bmap, no block device */
14913 + .invalidatepage = aufs_invalidatepage,
14914 + .releasepage = aufs_releasepage,
14915 + /* is fallback_migrate_page ok? */
14916 + /* .migratepage = aufs_migratepage, */
14917 + .isolate_page = aufs_isolate_page,
14918 + .putback_page = aufs_putback_page,
14919 + .launder_page = aufs_launder_page,
14920 + .is_partially_uptodate = aufs_is_partially_uptodate,
14921 + .is_dirty_writeback = aufs_is_dirty_writeback,
14922 + .error_remove_page = aufs_error_remove_page,
14923 + .swap_activate = aufs_swap_activate,
14924 + .swap_deactivate = aufs_swap_deactivate
14925 +#endif /* CONFIG_AUFS_DEBUG */
14927 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14928 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14929 +++ linux/fs/aufs/file.h 2020-01-27 10:57:18.172204883 +0100
14931 +/* SPDX-License-Identifier: GPL-2.0 */
14933 + * Copyright (C) 2005-2020 Junjiro R. Okajima
14935 + * This program, aufs is free software; you can redistribute it and/or modify
14936 + * it under the terms of the GNU General Public License as published by
14937 + * the Free Software Foundation; either version 2 of the License, or
14938 + * (at your option) any later version.
14940 + * This program is distributed in the hope that it will be useful,
14941 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14942 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14943 + * GNU General Public License for more details.
14945 + * You should have received a copy of the GNU General Public License
14946 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14950 + * file operations
14953 +#ifndef __AUFS_FILE_H__
14954 +#define __AUFS_FILE_H__
14958 +#include <linux/file.h>
14959 +#include <linux/fs.h>
14960 +#include <linux/mm_types.h>
14961 +#include <linux/poll.h>
14962 +#include "rwsem.h"
14966 + struct file *hf_file;
14967 + struct au_branch *hf_br;
14972 + aufs_bindex_t fd_bbot;
14973 + aufs_bindex_t fd_nent;
14974 + struct au_vdir *fd_vdir_cache;
14975 + struct au_hfile fd_hfile[];
14978 +static inline int au_fidir_sz(int nent)
14980 + AuDebugOn(nent < 0);
14981 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
14985 + atomic_t fi_generation;
14987 + struct au_rwsem fi_rwsem;
14988 + aufs_bindex_t fi_btop;
14990 + /* do not union them */
14991 + struct { /* for non-dir */
14992 + struct au_hfile fi_htop;
14993 + atomic_t fi_mmapped;
14995 + struct au_fidir *fi_hdir; /* for dir only */
14997 + struct hlist_bl_node fi_hlist;
14998 + struct file *fi_file; /* very ugly */
14999 + struct rcu_head rcu;
15000 +} ____cacheline_aligned_in_smp;
15002 +/* ---------------------------------------------------------------------- */
15005 +extern const struct address_space_operations aufs_aop;
15006 +unsigned int au_file_roflags(unsigned int flags);
15007 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15008 + struct file *file, int force_wr);
15009 +struct au_do_open_args {
15011 + int (*open)(struct file *file, int flags,
15012 + struct file *h_file);
15013 + struct au_fidir *fidir;
15014 + struct file *h_file;
15016 +int au_do_open(struct file *file, struct au_do_open_args *args);
15017 +int au_reopen_nondir(struct file *file);
15019 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15020 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15021 + int wlock, unsigned int fi_lsc);
15022 +int au_do_flush(struct file *file, fl_owner_t id,
15023 + int (*flush)(struct file *file, fl_owner_t id));
15026 +#ifdef CONFIG_AUFS_POLL
15027 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15030 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15032 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15034 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15035 + struct file *h_file);
15037 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15038 + aufs_bindex_t bindex, int force_wr)
15039 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15040 + struct file *h_file);
15044 +extern const struct file_operations aufs_file_fop;
15045 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15046 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15047 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15050 +void au_hfput(struct au_hfile *hf, int execed);
15051 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15052 + struct file *h_file);
15054 +void au_update_figen(struct file *file);
15055 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15056 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15058 +void au_fi_init_once(void *_fi);
15059 +void au_finfo_fin(struct file *file);
15060 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15063 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15064 +#ifdef CONFIG_COMPAT
15065 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15066 + unsigned long arg);
15067 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15068 + unsigned long arg);
15071 +/* ---------------------------------------------------------------------- */
15073 +static inline struct au_finfo *au_fi(struct file *file)
15075 + return file->private_data;
15078 +/* ---------------------------------------------------------------------- */
15080 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15081 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15082 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15083 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15085 +#define fi_read_trylock_nested(f) \
15086 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15087 +#define fi_write_trylock_nested(f) \
15088 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15091 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15092 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15093 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15095 +/* lock subclass for finfo */
15101 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15103 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15106 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15108 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15112 + * fi_read_lock_1, fi_write_lock_1,
15113 + * fi_read_lock_2, fi_write_lock_2
15115 +#define AuReadLockFunc(name) \
15116 +static inline void fi_read_lock_##name(struct file *f) \
15117 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15119 +#define AuWriteLockFunc(name) \
15120 +static inline void fi_write_lock_##name(struct file *f) \
15121 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15123 +#define AuRWLockFuncs(name) \
15124 + AuReadLockFunc(name) \
15125 + AuWriteLockFunc(name)
15130 +#undef AuReadLockFunc
15131 +#undef AuWriteLockFunc
15132 +#undef AuRWLockFuncs
15134 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15135 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15136 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15138 +/* ---------------------------------------------------------------------- */
15140 +/* todo: hard/soft set? */
15141 +static inline aufs_bindex_t au_fbtop(struct file *file)
15143 + FiMustAnyLock(file);
15144 + return au_fi(file)->fi_btop;
15147 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15149 + FiMustAnyLock(file);
15150 + AuDebugOn(!au_fi(file)->fi_hdir);
15151 + return au_fi(file)->fi_hdir->fd_bbot;
15154 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15156 + FiMustAnyLock(file);
15157 + AuDebugOn(!au_fi(file)->fi_hdir);
15158 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15161 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15163 + FiMustWriteLock(file);
15164 + au_fi(file)->fi_btop = bindex;
15167 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15169 + FiMustWriteLock(file);
15170 + AuDebugOn(!au_fi(file)->fi_hdir);
15171 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15174 +static inline void au_set_fvdir_cache(struct file *file,
15175 + struct au_vdir *vdir_cache)
15177 + FiMustWriteLock(file);
15178 + AuDebugOn(!au_fi(file)->fi_hdir);
15179 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15182 +static inline struct file *au_hf_top(struct file *file)
15184 + FiMustAnyLock(file);
15185 + AuDebugOn(au_fi(file)->fi_hdir);
15186 + return au_fi(file)->fi_htop.hf_file;
15189 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15191 + FiMustAnyLock(file);
15192 + AuDebugOn(!au_fi(file)->fi_hdir);
15193 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15196 +/* todo: memory barrier? */
15197 +static inline unsigned int au_figen(struct file *f)
15199 + return atomic_read(&au_fi(f)->fi_generation);
15202 +static inline void au_set_mmapped(struct file *f)
15204 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15206 + pr_warn("fi_mmapped wrapped around\n");
15207 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15211 +static inline void au_unset_mmapped(struct file *f)
15213 + atomic_dec(&au_fi(f)->fi_mmapped);
15216 +static inline int au_test_mmapped(struct file *f)
15218 + return atomic_read(&au_fi(f)->fi_mmapped);
15221 +/* customize vma->vm_file */
15223 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15224 + struct file *file)
15228 + f = vma->vm_file;
15230 + vma->vm_file = file;
15235 +#define AuDbgVmRegion(file, vma) do {} while (0)
15237 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15238 + struct file *file)
15240 + au_do_vm_file_reset(vma, file);
15243 +#define AuDbgVmRegion(file, vma) \
15244 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15246 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15247 + struct file *file)
15251 + au_do_vm_file_reset(vma, file);
15252 + f = vma->vm_region->vm_file;
15254 + vma->vm_region->vm_file = file;
15257 +#endif /* CONFIG_MMU */
15259 +/* handle vma->vm_prfile */
15260 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15261 + struct file *file)
15264 + vma->vm_prfile = file;
15265 +#ifndef CONFIG_MMU
15267 + vma->vm_region->vm_prfile = file;
15271 +#endif /* __KERNEL__ */
15272 +#endif /* __AUFS_FILE_H__ */
15273 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15274 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15275 +++ linux/fs/aufs/finfo.c 2020-01-27 10:57:18.172204883 +0100
15277 +// SPDX-License-Identifier: GPL-2.0
15279 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15281 + * This program, aufs is free software; you can redistribute it and/or modify
15282 + * it under the terms of the GNU General Public License as published by
15283 + * the Free Software Foundation; either version 2 of the License, or
15284 + * (at your option) any later version.
15286 + * This program is distributed in the hope that it will be useful,
15287 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15288 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15289 + * GNU General Public License for more details.
15291 + * You should have received a copy of the GNU General Public License
15292 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15296 + * file private data
15301 +void au_hfput(struct au_hfile *hf, int execed)
15304 + allow_write_access(hf->hf_file);
15305 + fput(hf->hf_file);
15306 + hf->hf_file = NULL;
15307 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15308 + hf->hf_br = NULL;
15311 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15313 + struct au_finfo *finfo = au_fi(file);
15314 + struct au_hfile *hf;
15315 + struct au_fidir *fidir;
15317 + fidir = finfo->fi_hdir;
15319 + AuDebugOn(finfo->fi_btop != bindex);
15320 + hf = &finfo->fi_htop;
15322 + hf = fidir->fd_hfile + bindex;
15324 + if (hf && hf->hf_file)
15325 + au_hfput(hf, vfsub_file_execed(file));
15327 + FiMustWriteLock(file);
15328 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15329 + hf->hf_file = val;
15330 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15334 +void au_update_figen(struct file *file)
15336 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15337 + /* smp_mb(); */ /* atomic_set */
15340 +/* ---------------------------------------------------------------------- */
15342 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15344 + struct au_fidir *fidir;
15347 + nbr = au_sbbot(sb) + 1;
15349 + nbr = 2; /* initial allocate for 2 branches */
15350 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15352 + fidir->fd_bbot = -1;
15353 + fidir->fd_nent = nbr;
15359 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15362 + struct au_fidir *fidir, *p;
15364 + AuRwMustWriteLock(&finfo->fi_rwsem);
15365 + fidir = finfo->fi_hdir;
15366 + AuDebugOn(!fidir);
15369 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15370 + GFP_NOFS, may_shrink);
15372 + p->fd_nent = nbr;
15373 + finfo->fi_hdir = p;
15380 +/* ---------------------------------------------------------------------- */
15382 +void au_finfo_fin(struct file *file)
15384 + struct au_finfo *finfo;
15386 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15388 + finfo = au_fi(file);
15389 + AuDebugOn(finfo->fi_hdir);
15390 + AuRwDestroy(&finfo->fi_rwsem);
15391 + au_cache_free_finfo(finfo);
15394 +void au_fi_init_once(void *_finfo)
15396 + struct au_finfo *finfo = _finfo;
15398 + au_rw_init(&finfo->fi_rwsem);
15401 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15404 + struct au_finfo *finfo;
15405 + struct dentry *dentry;
15408 + dentry = file->f_path.dentry;
15409 + finfo = au_cache_alloc_finfo();
15410 + if (unlikely(!finfo))
15414 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15415 + au_rw_write_lock(&finfo->fi_rwsem);
15416 + finfo->fi_btop = -1;
15417 + finfo->fi_hdir = fidir;
15418 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15419 + /* smp_mb(); */ /* atomic_set */
15421 + file->private_data = finfo;
15426 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15427 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15428 +++ linux/fs/aufs/f_op.c 2020-12-15 14:10:58.914689728 +0100
15430 +// SPDX-License-Identifier: GPL-2.0
15432 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15434 + * This program, aufs is free software; you can redistribute it and/or modify
15435 + * it under the terms of the GNU General Public License as published by
15436 + * the Free Software Foundation; either version 2 of the License, or
15437 + * (at your option) any later version.
15439 + * This program is distributed in the hope that it will be useful,
15440 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15441 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15442 + * GNU General Public License for more details.
15444 + * You should have received a copy of the GNU General Public License
15445 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15449 + * file and vm operations
15452 +#include <linux/aio.h>
15453 +#include <linux/fs_stack.h>
15454 +#include <linux/mman.h>
15455 +#include <linux/security.h>
15458 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15461 + aufs_bindex_t bindex;
15462 + struct dentry *dentry, *h_dentry;
15463 + struct au_finfo *finfo;
15464 + struct inode *h_inode;
15466 + FiMustWriteLock(file);
15469 + dentry = file->f_path.dentry;
15470 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15471 + finfo = au_fi(file);
15472 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15473 + atomic_set(&finfo->fi_mmapped, 0);
15474 + bindex = au_dbtop(dentry);
15476 + h_dentry = au_h_dptr(dentry, bindex);
15477 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15478 + if (unlikely(err))
15480 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15481 + if (IS_ERR(h_file)) {
15482 + err = PTR_ERR(h_file);
15486 + h_dentry = h_file->f_path.dentry;
15487 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15488 + if (unlikely(err))
15490 + /* br ref is already inc-ed */
15493 + if ((flags & __O_TMPFILE)
15494 + && !(flags & O_EXCL)) {
15495 + h_inode = file_inode(h_file);
15496 + spin_lock(&h_inode->i_lock);
15497 + h_inode->i_state |= I_LINKABLE;
15498 + spin_unlock(&h_inode->i_lock);
15500 + au_set_fbtop(file, bindex);
15501 + au_set_h_fptr(file, bindex, h_file);
15502 + au_update_figen(file);
15503 + /* todo: necessary? */
15504 + /* file->f_ra = h_file->f_ra; */
15510 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15511 + struct file *file)
15514 + struct super_block *sb;
15515 + struct au_do_open_args args = {
15516 + .open = au_do_open_nondir
15519 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15520 + file, vfsub_file_flags(file), file->f_mode);
15522 + sb = file->f_path.dentry->d_sb;
15523 + si_read_lock(sb, AuLock_FLUSH);
15524 + err = au_do_open(file, &args);
15525 + si_read_unlock(sb);
15529 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15531 + struct au_finfo *finfo;
15532 + aufs_bindex_t bindex;
15534 + finfo = au_fi(file);
15535 + au_hbl_del(&finfo->fi_hlist,
15536 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15537 + bindex = finfo->fi_btop;
15539 + au_set_h_fptr(file, bindex, NULL);
15541 + au_finfo_fin(file);
15545 +/* ---------------------------------------------------------------------- */
15547 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15550 + struct file *h_file;
15553 + h_file = au_hf_top(file);
15555 + err = vfsub_flush(h_file, id);
15559 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15561 + return au_do_flush(file, id, au_do_flush_nondir);
15564 +/* ---------------------------------------------------------------------- */
15566 + * read and write functions acquire [fdi]_rwsem once, but release before
15567 + * mmap_sem. This is because to stop a race condition between mmap(2).
15568 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15569 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15570 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15573 +/* Callers should call au_read_post() or fput() in the end */
15574 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15576 + struct file *h_file;
15579 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15581 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15582 + h_file = au_hf_top(file);
15583 + get_file(h_file);
15585 + fi_read_unlock(file);
15587 + h_file = ERR_PTR(err);
15592 +static void au_read_post(struct inode *inode, struct file *h_file)
15594 + /* update without lock, I don't think it a problem */
15595 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15599 +struct au_write_pre {
15601 + unsigned int lsc;
15605 + aufs_bindex_t btop;
15609 + * return with iinfo is write-locked
15610 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15613 +static struct file *au_write_pre(struct file *file, int do_ready,
15614 + struct au_write_pre *wpre)
15616 + struct file *h_file;
15617 + struct dentry *dentry;
15619 + unsigned int lsc;
15620 + struct au_pin pin;
15625 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15626 + h_file = ERR_PTR(err);
15627 + if (unlikely(err))
15630 + dentry = file->f_path.dentry;
15632 + err = au_ready_to_write(file, -1, &pin);
15633 + if (unlikely(err)) {
15634 + h_file = ERR_PTR(err);
15635 + di_write_unlock(dentry);
15640 + di_downgrade_lock(dentry, /*flags*/0);
15642 + wpre->btop = au_fbtop(file);
15643 + h_file = au_hf_top(file);
15644 + get_file(h_file);
15646 + wpre->blks = file_inode(h_file)->i_blocks;
15649 + di_read_unlock(dentry, /*flags*/0);
15652 + fi_write_unlock(file);
15657 +static void au_write_post(struct inode *inode, struct file *h_file,
15658 + struct au_write_pre *wpre, ssize_t written)
15660 + struct inode *h_inode;
15662 + au_cpup_attr_timesizes(inode);
15663 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15664 + h_inode = file_inode(h_file);
15665 + inode->i_mode = h_inode->i_mode;
15666 + ii_write_unlock(inode);
15667 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15669 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15670 + /*force*/h_inode->i_blocks > wpre->blks);
15675 + * todo: very ugly
15676 + * it locks both of i_mutex and si_rwsem for read in safe.
15677 + * if the plink maintenance mode continues forever (that is the problem),
15678 + * may loop forever.
15680 +static void au_mtx_and_read_lock(struct inode *inode)
15683 + struct super_block *sb = inode->i_sb;
15686 + inode_lock(inode);
15687 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15690 + inode_unlock(inode);
15691 + si_read_lock(sb, AuLock_NOPLMW);
15692 + si_read_unlock(sb);
15696 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15697 + struct iov_iter *iov_iter)
15700 + struct file *file;
15701 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15703 + err = security_file_permission(h_file, rw);
15704 + if (unlikely(err))
15707 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15709 + if (rw == MAY_READ)
15710 + iter = h_file->f_op->read_iter;
15711 + else if (rw == MAY_WRITE)
15712 + iter = h_file->f_op->write_iter;
15714 + file = kio->ki_filp;
15715 + kio->ki_filp = h_file;
15718 + err = iter(kio, iov_iter);
15721 + /* currently there is no such fs */
15723 + kio->ki_filp = file;
15729 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15732 + struct file *file, *h_file;
15733 + struct inode *inode;
15734 + struct super_block *sb;
15736 + file = kio->ki_filp;
15737 + inode = file_inode(file);
15738 + sb = inode->i_sb;
15739 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15741 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15742 + err = PTR_ERR(h_file);
15743 + if (IS_ERR(h_file))
15746 + if (au_test_loopback_kthread()) {
15747 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15748 + if (file->f_mapping != h_file->f_mapping) {
15749 + file->f_mapping = h_file->f_mapping;
15750 + smp_mb(); /* unnecessary? */
15753 + fi_read_unlock(file);
15755 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15756 + /* todo: necessary? */
15757 + /* file->f_ra = h_file->f_ra; */
15758 + au_read_post(inode, h_file);
15761 + si_read_unlock(sb);
15765 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15768 + struct au_write_pre wpre;
15769 + struct inode *inode;
15770 + struct file *file, *h_file;
15772 + file = kio->ki_filp;
15773 + inode = file_inode(file);
15774 + au_mtx_and_read_lock(inode);
15777 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15778 + err = PTR_ERR(h_file);
15779 + if (IS_ERR(h_file))
15782 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15783 + au_write_post(inode, h_file, &wpre, err);
15786 + si_read_unlock(inode->i_sb);
15787 + inode_unlock(inode);
15791 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15792 + struct pipe_inode_info *pipe, size_t len,
15793 + unsigned int flags)
15796 + struct file *h_file;
15797 + struct inode *inode;
15798 + struct super_block *sb;
15800 + inode = file_inode(file);
15801 + sb = inode->i_sb;
15802 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15804 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15805 + err = PTR_ERR(h_file);
15806 + if (IS_ERR(h_file))
15809 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15810 + /* todo: necessary? */
15811 + /* file->f_ra = h_file->f_ra; */
15812 + au_read_post(inode, h_file);
15815 + si_read_unlock(sb);
15820 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15821 + size_t len, unsigned int flags)
15824 + struct au_write_pre wpre;
15825 + struct inode *inode;
15826 + struct file *h_file;
15828 + inode = file_inode(file);
15829 + au_mtx_and_read_lock(inode);
15832 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15833 + err = PTR_ERR(h_file);
15834 + if (IS_ERR(h_file))
15837 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15838 + au_write_post(inode, h_file, &wpre, err);
15841 + si_read_unlock(inode->i_sb);
15842 + inode_unlock(inode);
15846 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15850 + struct au_write_pre wpre;
15851 + struct inode *inode;
15852 + struct file *h_file;
15854 + inode = file_inode(file);
15855 + au_mtx_and_read_lock(inode);
15858 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15859 + err = PTR_ERR(h_file);
15860 + if (IS_ERR(h_file))
15864 + err = vfs_fallocate(h_file, mode, offset, len);
15866 + au_write_post(inode, h_file, &wpre, /*written*/1);
15869 + si_read_unlock(inode->i_sb);
15870 + inode_unlock(inode);
15874 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15875 + struct file *dst, loff_t dst_pos,
15876 + size_t len, unsigned int flags)
15879 + struct au_write_pre wpre;
15880 + enum { SRC, DST };
15882 + struct inode *inode;
15883 + struct file *h_file;
15884 + struct super_block *h_sb;
15886 +#define a_src a[SRC]
15887 +#define a_dst a[DST]
15890 + a_src.inode = file_inode(src);
15891 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15893 + a_dst.inode = file_inode(dst);
15894 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15897 + au_mtx_and_read_lock(a_dst.inode);
15899 + * in order to match the order in di_write_lock2_{child,parent}(),
15900 + * use f_path.dentry for this comparison.
15902 + if (src->f_path.dentry < dst->f_path.dentry) {
15903 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15904 + err = PTR_ERR(a_src.h_file);
15905 + if (IS_ERR(a_src.h_file))
15908 + wpre.lsc = AuLsc_FI_2;
15909 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15910 + err = PTR_ERR(a_dst.h_file);
15911 + if (IS_ERR(a_dst.h_file)) {
15912 + au_read_post(a_src.inode, a_src.h_file);
15916 + wpre.lsc = AuLsc_FI_1;
15917 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15918 + err = PTR_ERR(a_dst.h_file);
15919 + if (IS_ERR(a_dst.h_file))
15922 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15923 + err = PTR_ERR(a_src.h_file);
15924 + if (IS_ERR(a_src.h_file)) {
15925 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15932 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15933 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15934 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15940 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15941 + dst_pos, len, flags);
15944 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15945 + fi_read_unlock(src);
15946 + au_read_post(a_src.inode, a_src.h_file);
15948 + si_read_unlock(a_dst.inode->i_sb);
15949 + inode_unlock(a_dst.inode);
15956 +/* ---------------------------------------------------------------------- */
15959 + * The locking order around current->mmap_sem.
15960 + * - in most and regular cases
15961 + * file I/O syscall -- aufs_read() or something
15962 + * -- si_rwsem for read -- mmap_sem
15963 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15965 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15966 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
15967 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
15968 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
15969 + * It means that when aufs acquires si_rwsem for write, the process should never
15970 + * acquire mmap_sem.
15972 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
15973 + * problem either since any directory is not able to be mmap-ed.
15974 + * The similar scenario is applied to aufs_readlink() too.
15977 +#if 0 /* stop calling security_file_mmap() */
15978 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
15979 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
15981 +static unsigned long au_arch_prot_conv(unsigned long flags)
15983 + /* currently ppc64 only */
15984 +#ifdef CONFIG_PPC64
15985 + /* cf. linux/arch/powerpc/include/asm/mman.h */
15986 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
15987 + return AuConv_VM_PROT(flags, SAO);
15989 + AuDebugOn(arch_calc_vm_prot_bits(-1));
15994 +static unsigned long au_prot_conv(unsigned long flags)
15996 + return AuConv_VM_PROT(flags, READ)
15997 + | AuConv_VM_PROT(flags, WRITE)
15998 + | AuConv_VM_PROT(flags, EXEC)
15999 + | au_arch_prot_conv(flags);
16002 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16003 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16005 +static unsigned long au_flag_conv(unsigned long flags)
16007 + return AuConv_VM_MAP(flags, GROWSDOWN)
16008 + | AuConv_VM_MAP(flags, DENYWRITE)
16009 + | AuConv_VM_MAP(flags, LOCKED);
16013 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16016 + const unsigned char wlock
16017 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16018 + struct super_block *sb;
16019 + struct file *h_file;
16020 + struct inode *inode;
16022 + AuDbgVmRegion(file, vma);
16024 + inode = file_inode(file);
16025 + sb = inode->i_sb;
16027 + si_read_lock(sb, AuLock_NOPLMW);
16029 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16031 + err = PTR_ERR(h_file);
16032 + if (IS_ERR(h_file))
16036 + au_set_mmapped(file);
16037 + au_vm_file_reset(vma, h_file);
16039 + * we cannot call security_mmap_file() here since it may acquire
16040 + * mmap_sem or i_mutex.
16042 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16043 + * au_flag_conv(vma->vm_flags));
16046 + err = call_mmap(h_file, vma);
16048 + au_vm_prfile_set(vma, file);
16049 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16050 + goto out_fput; /* success */
16052 + au_unset_mmapped(file);
16053 + au_vm_file_reset(vma, file);
16057 + ii_write_unlock(inode);
16062 + si_read_unlock(sb);
16068 +/* ---------------------------------------------------------------------- */
16070 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16074 + struct au_write_pre wpre;
16075 + struct inode *inode;
16076 + struct file *h_file;
16078 + err = 0; /* -EBADF; */ /* posix? */
16079 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16082 + inode = file_inode(file);
16083 + au_mtx_and_read_lock(inode);
16086 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16087 + err = PTR_ERR(h_file);
16088 + if (IS_ERR(h_file))
16091 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16092 + au_write_post(inode, h_file, &wpre, /*written*/0);
16095 + si_read_unlock(inode->i_sb);
16096 + inode_unlock(inode);
16101 +static int aufs_fasync(int fd, struct file *file, int flag)
16104 + struct file *h_file;
16105 + struct super_block *sb;
16107 + sb = file->f_path.dentry->d_sb;
16108 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16110 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16111 + err = PTR_ERR(h_file);
16112 + if (IS_ERR(h_file))
16115 + if (h_file->f_op->fasync)
16116 + err = h_file->f_op->fasync(fd, h_file, flag);
16117 + fput(h_file); /* instead of au_read_post() */
16120 + si_read_unlock(sb);
16124 +static int aufs_setfl(struct file *file, unsigned long arg)
16127 + struct file *h_file;
16128 + struct super_block *sb;
16130 + sb = file->f_path.dentry->d_sb;
16131 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16133 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16134 + err = PTR_ERR(h_file);
16135 + if (IS_ERR(h_file))
16138 + /* stop calling h_file->fasync */
16139 + arg |= vfsub_file_flags(file) & FASYNC;
16140 + err = setfl(/*unused fd*/-1, h_file, arg);
16141 + fput(h_file); /* instead of au_read_post() */
16144 + si_read_unlock(sb);
16148 +/* ---------------------------------------------------------------------- */
16150 +/* no one supports this operation, currently */
16151 +#if 0 /* reserved for future use */
16152 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16153 + size_t len, loff_t *pos, int more)
16158 +/* ---------------------------------------------------------------------- */
16160 +const struct file_operations aufs_file_fop = {
16161 + .owner = THIS_MODULE,
16163 + .llseek = default_llseek,
16165 + .read_iter = aufs_read_iter,
16166 + .write_iter = aufs_write_iter,
16168 +#ifdef CONFIG_AUFS_POLL
16169 + .poll = aufs_poll,
16171 + .unlocked_ioctl = aufs_ioctl_nondir,
16172 +#ifdef CONFIG_COMPAT
16173 + .compat_ioctl = aufs_compat_ioctl_nondir,
16175 + .mmap = aufs_mmap,
16176 + .open = aufs_open_nondir,
16177 + .flush = aufs_flush_nondir,
16178 + .release = aufs_release_nondir,
16179 + .fsync = aufs_fsync_nondir,
16180 + .fasync = aufs_fasync,
16181 + /* .sendpage = aufs_sendpage, */
16182 + .setfl = aufs_setfl,
16183 + .splice_write = aufs_splice_write,
16184 + .splice_read = aufs_splice_read,
16185 +#if 0 /* reserved for future use */
16186 + .aio_splice_write = aufs_aio_splice_write,
16187 + .aio_splice_read = aufs_aio_splice_read,
16189 + .fallocate = aufs_fallocate,
16190 + .copy_file_range = aufs_copy_file_range
16192 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16193 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16194 +++ linux/fs/aufs/fstype.h 2020-01-27 10:57:18.172204883 +0100
16196 +/* SPDX-License-Identifier: GPL-2.0 */
16198 + * Copyright (C) 2005-2020 Junjiro R. Okajima
16200 + * This program, aufs is free software; you can redistribute it and/or modify
16201 + * it under the terms of the GNU General Public License as published by
16202 + * the Free Software Foundation; either version 2 of the License, or
16203 + * (at your option) any later version.
16205 + * This program is distributed in the hope that it will be useful,
16206 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16207 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16208 + * GNU General Public License for more details.
16210 + * You should have received a copy of the GNU General Public License
16211 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16215 + * judging filesystem type
16218 +#ifndef __AUFS_FSTYPE_H__
16219 +#define __AUFS_FSTYPE_H__
16223 +#include <linux/fs.h>
16224 +#include <linux/magic.h>
16225 +#include <linux/nfs_fs.h>
16226 +#include <linux/romfs_fs.h>
16228 +static inline int au_test_aufs(struct super_block *sb)
16230 + return sb->s_magic == AUFS_SUPER_MAGIC;
16233 +static inline const char *au_sbtype(struct super_block *sb)
16235 + return sb->s_type->name;
16238 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16240 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16241 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16247 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16249 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16250 + return sb->s_magic == ROMFS_MAGIC;
16256 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16258 +#if IS_ENABLED(CONFIG_CRAMFS)
16259 + return sb->s_magic == CRAMFS_MAGIC;
16264 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16266 +#if IS_ENABLED(CONFIG_NFS_FS)
16267 + return sb->s_magic == NFS_SUPER_MAGIC;
16273 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16275 +#if IS_ENABLED(CONFIG_FUSE_FS)
16276 + return sb->s_magic == FUSE_SUPER_MAGIC;
16282 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16284 +#if IS_ENABLED(CONFIG_XFS_FS)
16285 + return sb->s_magic == XFS_SB_MAGIC;
16291 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16293 +#ifdef CONFIG_TMPFS
16294 + return sb->s_magic == TMPFS_MAGIC;
16300 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16302 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16303 + return !strcmp(au_sbtype(sb), "ecryptfs");
16309 +static inline int au_test_ramfs(struct super_block *sb)
16311 + return sb->s_magic == RAMFS_MAGIC;
16314 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16316 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16317 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16323 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16325 +#ifdef CONFIG_PROC_FS
16326 + return sb->s_magic == PROC_SUPER_MAGIC;
16332 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16334 +#ifdef CONFIG_SYSFS
16335 + return sb->s_magic == SYSFS_MAGIC;
16341 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16343 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16344 + return sb->s_magic == CONFIGFS_MAGIC;
16350 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16352 +#if IS_ENABLED(CONFIG_MINIX_FS)
16353 + return sb->s_magic == MINIX3_SUPER_MAGIC
16354 + || sb->s_magic == MINIX2_SUPER_MAGIC
16355 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16356 + || sb->s_magic == MINIX_SUPER_MAGIC
16357 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16363 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16365 +#if IS_ENABLED(CONFIG_FAT_FS)
16366 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16372 +static inline int au_test_msdos(struct super_block *sb)
16374 + return au_test_fat(sb);
16377 +static inline int au_test_vfat(struct super_block *sb)
16379 + return au_test_fat(sb);
16382 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16384 +#ifdef CONFIG_SECURITYFS
16385 + return sb->s_magic == SECURITYFS_MAGIC;
16391 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16393 +#if IS_ENABLED(CONFIG_SQUASHFS)
16394 + return sb->s_magic == SQUASHFS_MAGIC;
16400 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16402 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16403 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16409 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16411 +#if IS_ENABLED(CONFIG_XENFS)
16412 + return sb->s_magic == XENFS_SUPER_MAGIC;
16418 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16420 +#ifdef CONFIG_DEBUG_FS
16421 + return sb->s_magic == DEBUGFS_MAGIC;
16427 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16429 +#if IS_ENABLED(CONFIG_NILFS)
16430 + return sb->s_magic == NILFS_SUPER_MAGIC;
16436 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16438 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16439 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16445 +/* ---------------------------------------------------------------------- */
16447 + * they can't be an aufs branch.
16449 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16452 +#ifndef CONFIG_AUFS_BR_RAMFS
16453 + au_test_ramfs(sb) ||
16455 + au_test_procfs(sb)
16456 + || au_test_sysfs(sb)
16457 + || au_test_configfs(sb)
16458 + || au_test_debugfs(sb)
16459 + || au_test_securityfs(sb)
16460 + || au_test_xenfs(sb)
16461 + || au_test_ecryptfs(sb)
16462 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16463 + || au_test_aufs(sb); /* will be supported in next version */
16466 +static inline int au_test_fs_remote(struct super_block *sb)
16468 + return !au_test_tmpfs(sb)
16469 +#ifdef CONFIG_AUFS_BR_RAMFS
16470 + && !au_test_ramfs(sb)
16472 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16475 +/* ---------------------------------------------------------------------- */
16478 + * Note: these functions (below) are created after reading ->getattr() in all
16479 + * filesystems under linux/fs. it means we have to do so in every update...
16483 + * some filesystems require getattr to refresh the inode attributes before
16485 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16486 + * and leave the work for d_revalidate()
16488 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16490 + return au_test_nfs(sb)
16491 + || au_test_fuse(sb)
16492 + /* || au_test_btrfs(sb) */ /* untested */
16497 + * filesystems which don't maintain i_size or i_blocks.
16499 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16501 + return au_test_xfs(sb)
16502 + || au_test_btrfs(sb)
16503 + || au_test_ubifs(sb)
16504 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16505 + /* || au_test_minix(sb) */ /* untested */
16510 + * filesystems which don't store the correct value in some of their inode
16513 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16515 + return au_test_fs_bad_iattr_size(sb)
16516 + || au_test_fat(sb)
16517 + || au_test_msdos(sb)
16518 + || au_test_vfat(sb);
16521 +/* they don't check i_nlink in link(2) */
16522 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16524 + return au_test_tmpfs(sb)
16525 +#ifdef CONFIG_AUFS_BR_RAMFS
16526 + || au_test_ramfs(sb)
16528 + || au_test_ubifs(sb)
16529 + || au_test_hfsplus(sb);
16533 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16535 +static inline int au_test_fs_notime(struct super_block *sb)
16537 + return au_test_nfs(sb)
16538 + || au_test_fuse(sb)
16539 + || au_test_ubifs(sb)
16543 +/* temporary support for i#1 in cramfs */
16544 +static inline int au_test_fs_unique_ino(struct inode *inode)
16546 + if (au_test_cramfs(inode->i_sb))
16547 + return inode->i_ino != 1;
16551 +/* ---------------------------------------------------------------------- */
16554 + * the filesystem where the xino files placed must support i/o after unlink and
16555 + * maintain i_size and i_blocks.
16557 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16559 + return au_test_fs_remote(sb)
16560 + || au_test_fs_bad_iattr_size(sb)
16561 + /* don't want unnecessary work for xino */
16562 + || au_test_aufs(sb)
16563 + || au_test_ecryptfs(sb)
16564 + || au_test_nilfs(sb);
16567 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16569 + return au_test_tmpfs(sb)
16570 + || au_test_ramfs(sb);
16574 + * test if the @sb is real-readonly.
16576 +static inline int au_test_fs_rr(struct super_block *sb)
16578 + return au_test_squashfs(sb)
16579 + || au_test_iso9660(sb)
16580 + || au_test_cramfs(sb)
16581 + || au_test_romfs(sb);
16585 + * test if the @inode is nfs with 'noacl' option
16586 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16588 +static inline int au_test_nfs_noacl(struct inode *inode)
16590 + return au_test_nfs(inode->i_sb)
16591 + /* && IS_POSIXACL(inode) */
16592 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16595 +#endif /* __KERNEL__ */
16596 +#endif /* __AUFS_FSTYPE_H__ */
16597 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16598 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16599 +++ linux/fs/aufs/hbl.h 2020-01-27 10:57:18.172204883 +0100
16601 +/* SPDX-License-Identifier: GPL-2.0 */
16603 + * Copyright (C) 2017-2020 Junjiro R. Okajima
16605 + * This program, aufs is free software; you can redistribute it and/or modify
16606 + * it under the terms of the GNU General Public License as published by
16607 + * the Free Software Foundation; either version 2 of the License, or
16608 + * (at your option) any later version.
16610 + * This program is distributed in the hope that it will be useful,
16611 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16612 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16613 + * GNU General Public License for more details.
16615 + * You should have received a copy of the GNU General Public License
16616 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16620 + * helpers for hlist_bl.h
16623 +#ifndef __AUFS_HBL_H__
16624 +#define __AUFS_HBL_H__
16628 +#include <linux/list_bl.h>
16630 +static inline void au_hbl_add(struct hlist_bl_node *node,
16631 + struct hlist_bl_head *hbl)
16633 + hlist_bl_lock(hbl);
16634 + hlist_bl_add_head(node, hbl);
16635 + hlist_bl_unlock(hbl);
16638 +static inline void au_hbl_del(struct hlist_bl_node *node,
16639 + struct hlist_bl_head *hbl)
16641 + hlist_bl_lock(hbl);
16642 + hlist_bl_del(node);
16643 + hlist_bl_unlock(hbl);
16646 +#define au_hbl_for_each(pos, head) \
16647 + for (pos = hlist_bl_first(head); \
16651 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16653 + unsigned long cnt;
16654 + struct hlist_bl_node *pos;
16657 + hlist_bl_lock(hbl);
16658 + au_hbl_for_each(pos, hbl)
16660 + hlist_bl_unlock(hbl);
16664 +#endif /* __KERNEL__ */
16665 +#endif /* __AUFS_HBL_H__ */
16666 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16667 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16668 +++ linux/fs/aufs/hfsnotify.c 2020-12-15 14:10:58.918023162 +0100
16670 +// SPDX-License-Identifier: GPL-2.0
16672 + * Copyright (C) 2005-2020 Junjiro R. Okajima
16674 + * This program, aufs is free software; you can redistribute it and/or modify
16675 + * it under the terms of the GNU General Public License as published by
16676 + * the Free Software Foundation; either version 2 of the License, or
16677 + * (at your option) any later version.
16679 + * This program is distributed in the hope that it will be useful,
16680 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16681 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16682 + * GNU General Public License for more details.
16684 + * You should have received a copy of the GNU General Public License
16685 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16689 + * fsnotify for the lower directories
16694 +/* FS_IN_IGNORED is unnecessary */
16695 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16696 + | FS_CREATE | FS_EVENT_ON_CHILD);
16697 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16698 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16700 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16702 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16704 + /* AuDbg("here\n"); */
16705 + au_cache_free_hnotify(hn);
16706 + smp_mb__before_atomic(); /* for atomic64_dec */
16707 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16708 + wake_up(&au_hfsn_wq);
16711 +static int au_hfsn_alloc(struct au_hinode *hinode)
16714 + struct au_hnotify *hn;
16715 + struct super_block *sb;
16716 + struct au_branch *br;
16717 + struct fsnotify_mark *mark;
16718 + aufs_bindex_t bindex;
16720 + hn = hinode->hi_notify;
16721 + sb = hn->hn_aufs_inode->i_sb;
16722 + bindex = au_br_index(sb, hinode->hi_id);
16723 + br = au_sbr(sb, bindex);
16724 + AuDebugOn(!br->br_hfsn);
16726 + mark = &hn->hn_mark;
16727 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16728 + mark->mask = AuHfsnMask;
16730 + * by udba rename or rmdir, aufs assign a new inode to the known
16731 + * h_inode, so specify 1 to allow dups.
16734 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16740 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16742 + struct fsnotify_mark *mark;
16743 + unsigned long long ull;
16744 + struct fsnotify_group *group;
16746 + ull = atomic64_inc_return(&au_hfsn_ifree);
16749 + mark = &hn->hn_mark;
16750 + spin_lock(&mark->lock);
16751 + group = mark->group;
16752 + fsnotify_get_group(group);
16753 + spin_unlock(&mark->lock);
16755 + fsnotify_destroy_mark(mark, group);
16756 + fsnotify_put_mark(mark);
16757 + fsnotify_put_group(group);
16760 + /* free hn by myself */
16764 +/* ---------------------------------------------------------------------- */
16766 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16768 + struct fsnotify_mark *mark;
16770 + mark = &hinode->hi_notify->hn_mark;
16771 + spin_lock(&mark->lock);
16773 + AuDebugOn(mark->mask & AuHfsnMask);
16774 + mark->mask |= AuHfsnMask;
16776 + AuDebugOn(!(mark->mask & AuHfsnMask));
16777 + mark->mask &= ~AuHfsnMask;
16779 + spin_unlock(&mark->lock);
16780 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16783 +/* ---------------------------------------------------------------------- */
16785 +/* #define AuDbgHnotify */
16786 +#ifdef AuDbgHnotify
16787 +static char *au_hfsn_name(u32 mask)
16789 +#ifdef CONFIG_AUFS_DEBUG
16790 +#define test_ret(flag) \
16792 + if (mask & flag) \
16795 + test_ret(FS_ACCESS);
16796 + test_ret(FS_MODIFY);
16797 + test_ret(FS_ATTRIB);
16798 + test_ret(FS_CLOSE_WRITE);
16799 + test_ret(FS_CLOSE_NOWRITE);
16800 + test_ret(FS_OPEN);
16801 + test_ret(FS_MOVED_FROM);
16802 + test_ret(FS_MOVED_TO);
16803 + test_ret(FS_CREATE);
16804 + test_ret(FS_DELETE);
16805 + test_ret(FS_DELETE_SELF);
16806 + test_ret(FS_MOVE_SELF);
16807 + test_ret(FS_UNMOUNT);
16808 + test_ret(FS_Q_OVERFLOW);
16809 + test_ret(FS_IN_IGNORED);
16810 + test_ret(FS_ISDIR);
16811 + test_ret(FS_IN_ONESHOT);
16812 + test_ret(FS_EVENT_ON_CHILD);
16821 +/* ---------------------------------------------------------------------- */
16823 +static void au_hfsn_free_group(struct fsnotify_group *group)
16825 + struct au_br_hfsnotify *hfsn = group->private;
16827 + /* AuDbg("here\n"); */
16828 + au_kfree_try_rcu(hfsn);
16831 +static int au_hfsn_handle_event(struct fsnotify_group *group,
16832 + u32 mask, const void *data, int data_type,
16833 + struct inode *dir,
16834 + const struct qstr *file_name, u32 cookie,
16835 + struct fsnotify_iter_info *iter_info)
16838 + struct au_hnotify *hnotify;
16839 + struct inode *h_dir, *h_inode;
16840 + struct fsnotify_mark *inode_mark;
16842 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
16845 + /* if FS_UNMOUNT happens, there must be another bug */
16846 + AuDebugOn(mask & FS_UNMOUNT);
16847 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
16852 +#ifdef AuDbgHnotify
16854 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
16855 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
16856 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
16857 + h_dir->i_ino, mask, au_hfsn_name(mask),
16858 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
16859 + /* WARN_ON(1); */
16864 + inode_mark = fsnotify_iter_inode_mark(iter_info);
16865 + AuDebugOn(!inode_mark);
16866 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
16867 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
16873 +static struct fsnotify_ops au_hfsn_ops = {
16874 + .handle_event = au_hfsn_handle_event,
16875 + .free_group_priv = au_hfsn_free_group,
16876 + .free_mark = au_hfsn_free_mark
16879 +/* ---------------------------------------------------------------------- */
16881 +static void au_hfsn_fin_br(struct au_branch *br)
16883 + struct au_br_hfsnotify *hfsn;
16885 + hfsn = br->br_hfsn;
16888 + fsnotify_put_group(hfsn->hfsn_group);
16893 +static int au_hfsn_init_br(struct au_branch *br, int perm)
16896 + struct fsnotify_group *group;
16897 + struct au_br_hfsnotify *hfsn;
16900 + br->br_hfsn = NULL;
16901 + if (!au_br_hnotifyable(perm))
16905 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
16906 + if (unlikely(!hfsn))
16910 + group = fsnotify_alloc_group(&au_hfsn_ops);
16911 + if (IS_ERR(group)) {
16912 + err = PTR_ERR(group);
16913 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
16917 + group->private = hfsn;
16918 + hfsn->hfsn_group = group;
16919 + br->br_hfsn = hfsn;
16920 + goto out; /* success */
16923 + au_kfree_try_rcu(hfsn);
16928 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
16933 + if (!br->br_hfsn)
16934 + err = au_hfsn_init_br(br, perm);
16939 +/* ---------------------------------------------------------------------- */
16941 +static void au_hfsn_fin(void)
16943 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
16944 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
16947 +const struct au_hnotify_op au_hnotify_op = {
16948 + .ctl = au_hfsn_ctl,
16949 + .alloc = au_hfsn_alloc,
16950 + .free = au_hfsn_free,
16952 + .fin = au_hfsn_fin,
16954 + .reset_br = au_hfsn_reset_br,
16955 + .fin_br = au_hfsn_fin_br,
16956 + .init_br = au_hfsn_init_br
16958 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
16959 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
16960 +++ linux/fs/aufs/hfsplus.c 2020-01-27 10:57:18.172204883 +0100
16962 +// SPDX-License-Identifier: GPL-2.0
16964 + * Copyright (C) 2010-2020 Junjiro R. Okajima
16966 + * This program, aufs is free software; you can redistribute it and/or modify
16967 + * it under the terms of the GNU General Public License as published by
16968 + * the Free Software Foundation; either version 2 of the License, or
16969 + * (at your option) any later version.
16971 + * This program is distributed in the hope that it will be useful,
16972 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16973 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16974 + * GNU General Public License for more details.
16976 + * You should have received a copy of the GNU General Public License
16977 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16981 + * special support for filesystems which acquires an inode mutex
16982 + * at final closing a file, eg, hfsplus.
16984 + * This trick is very simple and stupid, just to open the file before really
16985 + * necessary open to tell hfsplus that this is not the final closing.
16986 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
16987 + * and au_h_open_post() after releasing it.
16992 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
16995 + struct file *h_file;
16996 + struct dentry *h_dentry;
16998 + h_dentry = au_h_dptr(dentry, bindex);
16999 + AuDebugOn(!h_dentry);
17000 + AuDebugOn(d_is_negative(h_dentry));
17003 + if (au_test_hfsplus(h_dentry->d_sb)
17004 + && d_is_reg(h_dentry))
17005 + h_file = au_h_open(dentry, bindex,
17006 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17007 + /*file*/NULL, force_wr);
17011 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17012 + struct file *h_file)
17014 + struct au_branch *br;
17018 + br = au_sbr(dentry->d_sb, bindex);
17019 + au_lcnt_dec(&br->br_nfiles);
17022 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17023 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17024 +++ linux/fs/aufs/hnotify.c 2020-01-27 10:57:18.172204883 +0100
17026 +// SPDX-License-Identifier: GPL-2.0
17028 + * Copyright (C) 2005-2020 Junjiro R. Okajima
17030 + * This program, aufs is free software; you can redistribute it and/or modify
17031 + * it under the terms of the GNU General Public License as published by
17032 + * the Free Software Foundation; either version 2 of the License, or
17033 + * (at your option) any later version.
17035 + * This program is distributed in the hope that it will be useful,
17036 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17037 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17038 + * GNU General Public License for more details.
17040 + * You should have received a copy of the GNU General Public License
17041 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17045 + * abstraction to notify the direct changes on lower directories
17048 +/* #include <linux/iversion.h> */
17051 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17054 + struct au_hnotify *hn;
17057 + hn = au_cache_alloc_hnotify();
17059 + hn->hn_aufs_inode = inode;
17060 + hinode->hi_notify = hn;
17061 + err = au_hnotify_op.alloc(hinode);
17063 + if (unlikely(err)) {
17064 + hinode->hi_notify = NULL;
17065 + au_cache_free_hnotify(hn);
17067 + * The upper dir was removed by udba, but the same named
17068 + * dir left. In this case, aufs assigns a new inode
17069 + * number and set the monitor again.
17070 + * For the lower dir, the old monitor is still left.
17072 + if (err == -EEXIST)
17081 +void au_hn_free(struct au_hinode *hinode)
17083 + struct au_hnotify *hn;
17085 + hn = hinode->hi_notify;
17087 + hinode->hi_notify = NULL;
17088 + if (au_hnotify_op.free(hinode, hn))
17089 + au_cache_free_hnotify(hn);
17093 +/* ---------------------------------------------------------------------- */
17095 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17097 + if (hinode->hi_notify)
17098 + au_hnotify_op.ctl(hinode, do_set);
17101 +void au_hn_reset(struct inode *inode, unsigned int flags)
17103 + aufs_bindex_t bindex, bbot;
17104 + struct inode *hi;
17105 + struct dentry *iwhdentry;
17107 + bbot = au_ibbot(inode);
17108 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17109 + hi = au_h_iptr(inode, bindex);
17113 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17114 + iwhdentry = au_hi_wh(inode, bindex);
17118 + au_set_h_iptr(inode, bindex, NULL, 0);
17119 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17120 + flags & ~AuHi_XINO);
17123 + /* inode_unlock(hi); */
17127 +/* ---------------------------------------------------------------------- */
17129 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17132 + aufs_bindex_t bindex, bbot, bfound, btop;
17133 + struct inode *h_i;
17136 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17137 + pr_warn("branch root dir was changed\n");
17142 + bbot = au_ibbot(inode);
17143 + btop = au_ibtop(inode);
17144 +#if 0 /* reserved for future use */
17145 + if (bindex == bbot) {
17146 + /* keep this ino in rename case */
17150 + for (bindex = btop; bindex <= bbot; bindex++)
17151 + if (au_h_iptr(inode, bindex) == h_inode) {
17158 + for (bindex = btop; bindex <= bbot; bindex++) {
17159 + h_i = au_h_iptr(inode, bindex);
17163 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17164 + /* ignore this error */
17165 + /* bad action? */
17168 + /* children inode number will be broken */
17175 +static int hn_gen_tree(struct dentry *dentry)
17177 + int err, i, j, ndentry;
17178 + struct au_dcsub_pages dpages;
17179 + struct au_dpage *dpage;
17180 + struct dentry **dentries;
17182 + err = au_dpages_init(&dpages, GFP_NOFS);
17183 + if (unlikely(err))
17185 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17186 + if (unlikely(err))
17189 + for (i = 0; i < dpages.ndpage; i++) {
17190 + dpage = dpages.dpages + i;
17191 + dentries = dpage->dentries;
17192 + ndentry = dpage->ndentry;
17193 + for (j = 0; j < ndentry; j++) {
17194 + struct dentry *d;
17201 + if (d_really_is_positive(d))
17202 + /* todo: reset children xino?
17203 + cached children only? */
17204 + au_iigen_dec(d_inode(d));
17209 + au_dpages_free(&dpages);
17215 + * return 0 if processed.
17217 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17218 + const unsigned int isdir)
17221 + struct dentry *d;
17222 + struct qstr *dname;
17225 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17226 + pr_warn("branch root dir was changed\n");
17232 + AuDebugOn(!name);
17233 + au_iigen_dec(inode);
17234 + spin_lock(&inode->i_lock);
17235 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17236 + spin_lock(&d->d_lock);
17237 + dname = &d->d_name;
17238 + if (dname->len != nlen
17239 + && memcmp(dname->name, name, nlen)) {
17240 + spin_unlock(&d->d_lock);
17245 + spin_unlock(&d->d_lock);
17248 + spin_unlock(&inode->i_lock);
17250 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17251 + d = d_find_any_alias(inode);
17253 + au_iigen_dec(inode);
17257 + spin_lock(&d->d_lock);
17258 + dname = &d->d_name;
17259 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17260 + spin_unlock(&d->d_lock);
17261 + err = hn_gen_tree(d);
17262 + spin_lock(&d->d_lock);
17264 + spin_unlock(&d->d_lock);
17273 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17277 + if (IS_ROOT(dentry)) {
17278 + pr_warn("branch root dir was changed\n");
17284 + au_digen_dec(dentry);
17285 + if (d_really_is_positive(dentry))
17286 + au_iigen_dec(d_inode(dentry));
17288 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17289 + if (d_really_is_positive(dentry))
17290 + err = hn_gen_tree(dentry);
17297 +/* ---------------------------------------------------------------------- */
17299 +/* hnotify job flags */
17300 +#define AuHnJob_XINO0 1
17301 +#define AuHnJob_GEN (1 << 1)
17302 +#define AuHnJob_DIRENT (1 << 2)
17303 +#define AuHnJob_ISDIR (1 << 3)
17304 +#define AuHnJob_TRYXINO0 (1 << 4)
17305 +#define AuHnJob_MNTPNT (1 << 5)
17306 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17307 +#define au_fset_hnjob(flags, name) \
17308 + do { (flags) |= AuHnJob_##name; } while (0)
17309 +#define au_fclr_hnjob(flags, name) \
17310 + do { (flags) &= ~AuHnJob_##name; } while (0)
17318 +struct au_hnotify_args {
17319 + struct inode *h_dir, *dir, *h_child_inode;
17321 + unsigned int flags[AuHnLast];
17322 + unsigned int h_child_nlen;
17323 + char h_child_name[];
17326 +struct hn_job_args {
17327 + unsigned int flags;
17328 + struct inode *inode, *h_inode, *dir, *h_dir;
17329 + struct dentry *dentry;
17334 +static int hn_job(struct hn_job_args *a)
17336 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17340 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17341 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17343 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17346 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17347 + if (!a->h_inode->i_nlink
17348 + && !(a->h_inode->i_state & I_LINKABLE))
17349 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17350 + inode_unlock_shared(a->h_inode);
17353 + /* make the generation obsolete */
17354 + if (au_ftest_hnjob(a->flags, GEN)) {
17357 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17359 + if (e && a->dentry)
17360 + hn_gen_by_name(a->dentry, isdir);
17361 + /* ignore this error */
17364 + /* make dir entries obsolete */
17365 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17366 + struct au_vdir *vdir;
17368 + vdir = au_ivdir(a->inode);
17370 + vdir->vd_jiffy = 0;
17371 + /* IMustLock(a->inode); */
17372 + /* inode_inc_iversion(a->inode); */
17375 + /* can do nothing but warn */
17376 + if (au_ftest_hnjob(a->flags, MNTPNT)
17378 + && d_mountpoint(a->dentry))
17379 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17384 +/* ---------------------------------------------------------------------- */
17386 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17387 + struct inode *dir)
17389 + struct dentry *dentry, *d, *parent;
17390 + struct qstr *dname;
17392 + parent = d_find_any_alias(dir);
17397 + spin_lock(&parent->d_lock);
17398 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17399 + /* AuDbg("%pd\n", d); */
17400 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17401 + dname = &d->d_name;
17402 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17403 + goto cont_unlock;
17407 + goto cont_unlock;
17408 + if (au_dcount(d) > 0) {
17409 + dentry = dget_dlock(d);
17410 + spin_unlock(&d->d_lock);
17415 + spin_unlock(&d->d_lock);
17417 + spin_unlock(&parent->d_lock);
17421 + di_write_lock_child(dentry);
17426 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17427 + aufs_bindex_t bindex, ino_t h_ino)
17429 + struct inode *inode;
17434 + err = au_xino_read(sb, bindex, h_ino, &ino);
17436 + inode = ilookup(sb, ino);
17440 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17441 + pr_warn("wrong root branch\n");
17447 + ii_write_lock_child(inode);
17453 +static void au_hn_bh(void *_args)
17455 + struct au_hnotify_args *a = _args;
17456 + struct super_block *sb;
17457 + aufs_bindex_t bindex, bbot, bfound;
17458 + unsigned char xino, try_iput;
17460 + struct inode *inode;
17462 + struct hn_job_args args;
17463 + struct dentry *dentry;
17464 + struct au_sbinfo *sbinfo;
17466 + AuDebugOn(!_args);
17467 + AuDebugOn(!a->h_dir);
17468 + AuDebugOn(!a->dir);
17469 + AuDebugOn(!a->mask);
17470 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17471 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17472 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17477 + * do not lock a->dir->i_mutex here
17478 + * because of d_revalidate() may cause a deadlock.
17480 + sb = a->dir->i_sb;
17482 + sbinfo = au_sbi(sb);
17483 + AuDebugOn(!sbinfo);
17484 + si_write_lock(sb, AuLock_NOPLMW);
17486 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17487 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17488 + case FS_MOVED_FROM:
17489 + case FS_MOVED_TO:
17490 + AuWarn1("DIRREN with UDBA may not work correctly "
17491 + "for the direct rename(2)\n");
17494 + ii_read_lock_parent(a->dir);
17496 + bbot = au_ibbot(a->dir);
17497 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17498 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17502 + ii_read_unlock(a->dir);
17503 + if (unlikely(bfound < 0))
17506 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17508 + if (a->h_child_inode)
17509 + h_ino = a->h_child_inode->i_ino;
17511 + if (a->h_child_nlen
17512 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17513 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17514 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17517 + if (dentry && d_really_is_positive(dentry))
17518 + inode = d_inode(dentry);
17519 + if (xino && !inode && h_ino
17520 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17521 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17522 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17523 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17527 + args.flags = a->flags[AuHn_CHILD];
17528 + args.dentry = dentry;
17529 + args.inode = inode;
17530 + args.h_inode = a->h_child_inode;
17531 + args.dir = a->dir;
17532 + args.h_dir = a->h_dir;
17533 + args.h_name = a->h_child_name;
17534 + args.h_nlen = a->h_child_nlen;
17535 + err = hn_job(&args);
17537 + if (au_di(dentry))
17538 + di_write_unlock(dentry);
17541 + if (inode && try_iput) {
17542 + ii_write_unlock(inode);
17546 + ii_write_lock_parent(a->dir);
17547 + args.flags = a->flags[AuHn_PARENT];
17548 + args.dentry = NULL;
17549 + args.inode = a->dir;
17550 + args.h_inode = a->h_dir;
17552 + args.h_dir = NULL;
17553 + args.h_name = NULL;
17555 + err = hn_job(&args);
17556 + ii_write_unlock(a->dir);
17559 + iput(a->h_child_inode);
17562 + si_write_unlock(sb);
17563 + au_nwt_done(&sbinfo->si_nowait);
17567 +/* ---------------------------------------------------------------------- */
17569 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17570 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
17573 + unsigned int flags[AuHnLast], f;
17574 + unsigned char isdir, isroot, wh;
17575 + struct inode *dir;
17576 + struct au_hnotify_args *args;
17577 + char *p, *h_child_name;
17580 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17581 + dir = igrab(hnotify->hn_aufs_inode);
17585 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17587 + h_child_name = (void *)h_child_qstr->name;
17588 + len = h_child_qstr->len;
17589 + if (h_child_name) {
17590 + if (len > AUFS_WH_PFX_LEN
17591 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17592 + h_child_name += AUFS_WH_PFX_LEN;
17593 + len -= AUFS_WH_PFX_LEN;
17599 + if (h_child_inode)
17600 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17601 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17602 + flags[AuHn_CHILD] = 0;
17604 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17605 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17606 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17607 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
17608 + case FS_MOVED_FROM:
17609 + case FS_MOVED_TO:
17610 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17611 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17614 + AuDebugOn(!h_child_name);
17619 + * aufs never be able to get this child inode.
17620 + * revalidation should be in d_revalidate()
17621 + * by checking i_nlink, i_generation or d_unhashed().
17623 + AuDebugOn(!h_child_name);
17624 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17625 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17633 + h_child_inode = NULL;
17636 + /* iput() and kfree() will be called in au_hnotify() */
17637 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17638 + if (unlikely(!args)) {
17639 + AuErr1("no memory\n");
17643 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17644 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17645 + args->mask = mask;
17647 + args->h_dir = igrab(h_dir);
17648 + if (h_child_inode)
17649 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17650 + args->h_child_inode = h_child_inode;
17651 + args->h_child_nlen = len;
17653 + p = (void *)args;
17654 + p += sizeof(*args);
17655 + memcpy(p, h_child_name, len);
17659 + /* NFS fires the event for silly-renamed one from kworker */
17661 + if (!dir->i_nlink
17662 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17664 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17665 + if (unlikely(err)) {
17666 + pr_err("wkq %d\n", err);
17667 + iput(args->h_child_inode);
17668 + iput(args->h_dir);
17670 + au_kfree_rcu(args);
17677 +/* ---------------------------------------------------------------------- */
17679 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17683 + AuDebugOn(!(udba & AuOptMask_UDBA));
17686 + if (au_hnotify_op.reset_br)
17687 + err = au_hnotify_op.reset_br(udba, br, perm);
17692 +int au_hnotify_init_br(struct au_branch *br, int perm)
17697 + if (au_hnotify_op.init_br)
17698 + err = au_hnotify_op.init_br(br, perm);
17703 +void au_hnotify_fin_br(struct au_branch *br)
17705 + if (au_hnotify_op.fin_br)
17706 + au_hnotify_op.fin_br(br);
17709 +static void au_hn_destroy_cache(void)
17711 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17712 + au_cache[AuCache_HNOTIFY] = NULL;
17715 +int __init au_hnotify_init(void)
17720 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17721 + if (au_cache[AuCache_HNOTIFY]) {
17723 + if (au_hnotify_op.init)
17724 + err = au_hnotify_op.init();
17725 + if (unlikely(err))
17726 + au_hn_destroy_cache();
17732 +void au_hnotify_fin(void)
17734 + if (au_hnotify_op.fin)
17735 + au_hnotify_op.fin();
17737 + /* cf. au_cache_fin() */
17738 + if (au_cache[AuCache_HNOTIFY])
17739 + au_hn_destroy_cache();
17741 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17742 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17743 +++ linux/fs/aufs/iinfo.c 2020-01-27 10:57:18.175538316 +0100
17745 +// SPDX-License-Identifier: GPL-2.0
17747 + * Copyright (C) 2005-2020 Junjiro R. Okajima
17749 + * This program, aufs is free software; you can redistribute it and/or modify
17750 + * it under the terms of the GNU General Public License as published by
17751 + * the Free Software Foundation; either version 2 of the License, or
17752 + * (at your option) any later version.
17754 + * This program is distributed in the hope that it will be useful,
17755 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17756 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17757 + * GNU General Public License for more details.
17759 + * You should have received a copy of the GNU General Public License
17760 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17764 + * inode private data
17769 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17771 + struct inode *h_inode;
17772 + struct au_hinode *hinode;
17774 + IiMustAnyLock(inode);
17776 + hinode = au_hinode(au_ii(inode), bindex);
17777 + h_inode = hinode->hi_inode;
17778 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17782 +/* todo: hard/soft set? */
17783 +void au_hiput(struct au_hinode *hinode)
17785 + au_hn_free(hinode);
17786 + dput(hinode->hi_whdentry);
17787 + iput(hinode->hi_inode);
17790 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17792 + unsigned int flags;
17793 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17796 + if (au_opt_test(mnt_flags, XINO))
17797 + au_fset_hi(flags, XINO);
17798 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17799 + au_fset_hi(flags, HNOTIFY);
17803 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17804 + struct inode *h_inode, unsigned int flags)
17806 + struct au_hinode *hinode;
17807 + struct inode *hi;
17808 + struct au_iinfo *iinfo = au_ii(inode);
17810 + IiMustWriteLock(inode);
17812 + hinode = au_hinode(iinfo, bindex);
17813 + hi = hinode->hi_inode;
17814 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17817 + au_hiput(hinode);
17818 + hinode->hi_inode = h_inode;
17821 + struct super_block *sb = inode->i_sb;
17822 + struct au_branch *br;
17824 + AuDebugOn(inode->i_mode
17825 + && (h_inode->i_mode & S_IFMT)
17826 + != (inode->i_mode & S_IFMT));
17827 + if (bindex == iinfo->ii_btop)
17828 + au_cpup_igen(inode, h_inode);
17829 + br = au_sbr(sb, bindex);
17830 + hinode->hi_id = br->br_id;
17831 + if (au_ftest_hi(flags, XINO)) {
17832 + err = au_xino_write(sb, bindex, h_inode->i_ino,
17834 + if (unlikely(err))
17835 + AuIOErr1("failed au_xino_write() %d\n", err);
17838 + if (au_ftest_hi(flags, HNOTIFY)
17839 + && au_br_hnotifyable(br->br_perm)) {
17840 + err = au_hn_alloc(hinode, inode);
17841 + if (unlikely(err))
17842 + AuIOErr1("au_hn_alloc() %d\n", err);
17847 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17848 + struct dentry *h_wh)
17850 + struct au_hinode *hinode;
17852 + IiMustWriteLock(inode);
17854 + hinode = au_hinode(au_ii(inode), bindex);
17855 + AuDebugOn(hinode->hi_whdentry);
17856 + hinode->hi_whdentry = h_wh;
17859 +void au_update_iigen(struct inode *inode, int half)
17861 + struct au_iinfo *iinfo;
17862 + struct au_iigen *iigen;
17863 + unsigned int sigen;
17865 + sigen = au_sigen(inode->i_sb);
17866 + iinfo = au_ii(inode);
17867 + iigen = &iinfo->ii_generation;
17868 + spin_lock(&iigen->ig_spin);
17869 + iigen->ig_generation = sigen;
17871 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
17873 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
17874 + spin_unlock(&iigen->ig_spin);
17877 +/* it may be called at remount time, too */
17878 +void au_update_ibrange(struct inode *inode, int do_put_zero)
17880 + struct au_iinfo *iinfo;
17881 + aufs_bindex_t bindex, bbot;
17883 + AuDebugOn(au_is_bad_inode(inode));
17884 + IiMustWriteLock(inode);
17886 + iinfo = au_ii(inode);
17887 + if (do_put_zero && iinfo->ii_btop >= 0) {
17888 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
17890 + struct inode *h_i;
17892 + h_i = au_hinode(iinfo, bindex)->hi_inode;
17895 + && !(h_i->i_state & I_LINKABLE))
17896 + au_set_h_iptr(inode, bindex, NULL, 0);
17900 + iinfo->ii_btop = -1;
17901 + iinfo->ii_bbot = -1;
17902 + bbot = au_sbbot(inode->i_sb);
17903 + for (bindex = 0; bindex <= bbot; bindex++)
17904 + if (au_hinode(iinfo, bindex)->hi_inode) {
17905 + iinfo->ii_btop = bindex;
17908 + if (iinfo->ii_btop >= 0)
17909 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
17910 + if (au_hinode(iinfo, bindex)->hi_inode) {
17911 + iinfo->ii_bbot = bindex;
17914 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
17917 +/* ---------------------------------------------------------------------- */
17919 +void au_icntnr_init_once(void *_c)
17921 + struct au_icntnr *c = _c;
17922 + struct au_iinfo *iinfo = &c->iinfo;
17924 + spin_lock_init(&iinfo->ii_generation.ig_spin);
17925 + au_rw_init(&iinfo->ii_rwsem);
17926 + inode_init_once(&c->vfs_inode);
17929 +void au_hinode_init(struct au_hinode *hinode)
17931 + hinode->hi_inode = NULL;
17932 + hinode->hi_id = -1;
17933 + au_hn_init(hinode);
17934 + hinode->hi_whdentry = NULL;
17937 +int au_iinfo_init(struct inode *inode)
17939 + struct au_iinfo *iinfo;
17940 + struct super_block *sb;
17941 + struct au_hinode *hi;
17944 + sb = inode->i_sb;
17945 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
17946 + nbr = au_sbbot(sb) + 1;
17947 + if (unlikely(nbr <= 0))
17949 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
17951 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
17953 + iinfo->ii_hinode = hi;
17954 + for (i = 0; i < nbr; i++, hi++)
17955 + au_hinode_init(hi);
17957 + iinfo->ii_generation.ig_generation = au_sigen(sb);
17958 + iinfo->ii_btop = -1;
17959 + iinfo->ii_bbot = -1;
17960 + iinfo->ii_vdir = NULL;
17966 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
17969 + struct au_hinode *hip;
17971 + AuRwMustWriteLock(&iinfo->ii_rwsem);
17974 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
17977 + iinfo->ii_hinode = hip;
17978 + i = iinfo->ii_bbot + 1;
17980 + for (; i < nbr; i++, hip++)
17981 + au_hinode_init(hip);
17988 +void au_iinfo_fin(struct inode *inode)
17990 + struct au_iinfo *iinfo;
17991 + struct au_hinode *hi;
17992 + struct super_block *sb;
17993 + aufs_bindex_t bindex, bbot;
17994 + const unsigned char unlinked = !inode->i_nlink;
17996 + AuDebugOn(au_is_bad_inode(inode));
17998 + sb = inode->i_sb;
17999 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
18000 + if (si_pid_test(sb))
18001 + au_xino_delete_inode(inode, unlinked);
18004 + * it is safe to hide the dependency between sbinfo and
18008 + si_noflush_read_lock(sb);
18009 + au_xino_delete_inode(inode, unlinked);
18010 + si_read_unlock(sb);
18014 + iinfo = au_ii(inode);
18015 + if (iinfo->ii_vdir)
18016 + au_vdir_free(iinfo->ii_vdir);
18018 + bindex = iinfo->ii_btop;
18019 + if (bindex >= 0) {
18020 + hi = au_hinode(iinfo, bindex);
18021 + bbot = iinfo->ii_bbot;
18022 + while (bindex++ <= bbot) {
18023 + if (hi->hi_inode)
18028 + au_kfree_rcu(iinfo->ii_hinode);
18029 + AuRwDestroy(&iinfo->ii_rwsem);
18031 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18032 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18033 +++ linux/fs/aufs/inode.c 2020-01-27 10:57:18.175538316 +0100
18035 +// SPDX-License-Identifier: GPL-2.0
18037 + * Copyright (C) 2005-2020 Junjiro R. Okajima
18039 + * This program, aufs is free software; you can redistribute it and/or modify
18040 + * it under the terms of the GNU General Public License as published by
18041 + * the Free Software Foundation; either version 2 of the License, or
18042 + * (at your option) any later version.
18044 + * This program is distributed in the hope that it will be useful,
18045 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18046 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18047 + * GNU General Public License for more details.
18049 + * You should have received a copy of the GNU General Public License
18050 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18054 + * inode functions
18057 +#include <linux/iversion.h>
18060 +struct inode *au_igrab(struct inode *inode)
18063 + AuDebugOn(!atomic_read(&inode->i_count));
18069 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18071 + au_cpup_attr_all(inode, /*force*/0);
18072 + au_update_iigen(inode, /*half*/1);
18074 + inode_inc_iversion(inode);
18077 +static int au_ii_refresh(struct inode *inode, int *update)
18081 + aufs_bindex_t bindex, new_bindex;
18082 + struct super_block *sb;
18083 + struct au_iinfo *iinfo;
18084 + struct au_hinode *p, *q, tmp;
18086 + AuDebugOn(au_is_bad_inode(inode));
18087 + IiMustWriteLock(inode);
18090 + sb = inode->i_sb;
18091 + nbr = au_sbbot(sb) + 1;
18092 + type = inode->i_mode & S_IFMT;
18093 + iinfo = au_ii(inode);
18094 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18095 + if (unlikely(err))
18098 + AuDebugOn(iinfo->ii_btop < 0);
18099 + p = au_hinode(iinfo, iinfo->ii_btop);
18100 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18102 + if (!p->hi_inode)
18105 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18106 + new_bindex = au_br_index(sb, p->hi_id);
18107 + if (new_bindex == bindex)
18110 + if (new_bindex < 0) {
18113 + p->hi_inode = NULL;
18117 + if (new_bindex < iinfo->ii_btop)
18118 + iinfo->ii_btop = new_bindex;
18119 + if (iinfo->ii_bbot < new_bindex)
18120 + iinfo->ii_bbot = new_bindex;
18121 + /* swap two lower inode, and loop again */
18122 + q = au_hinode(iinfo, new_bindex);
18126 + if (tmp.hi_inode) {
18131 + au_update_ibrange(inode, /*do_put_zero*/0);
18132 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18133 + e = au_dy_irefresh(inode);
18134 + if (unlikely(e && !err))
18142 +void au_refresh_iop(struct inode *inode, int force_getattr)
18145 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18146 + const struct inode_operations *iop
18147 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18149 + if (inode->i_op == iop)
18152 + switch (inode->i_mode & S_IFMT) {
18154 + type = AuIop_DIR;
18157 + type = AuIop_SYMLINK;
18160 + type = AuIop_OTHER;
18164 + inode->i_op = iop + type;
18165 + /* unnecessary smp_wmb() */
18168 +int au_refresh_hinode_self(struct inode *inode)
18172 + err = au_ii_refresh(inode, &update);
18174 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18180 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18182 + int err, e, update;
18183 + unsigned int flags;
18185 + aufs_bindex_t bindex, bbot;
18186 + unsigned char isdir;
18187 + struct au_hinode *p;
18188 + struct au_iinfo *iinfo;
18190 + err = au_ii_refresh(inode, &update);
18191 + if (unlikely(err))
18195 + iinfo = au_ii(inode);
18196 + p = au_hinode(iinfo, iinfo->ii_btop);
18197 + mode = (inode->i_mode & S_IFMT);
18198 + isdir = S_ISDIR(mode);
18199 + flags = au_hi_flags(inode, isdir);
18200 + bbot = au_dbbot(dentry);
18201 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18202 + struct inode *h_i, *h_inode;
18203 + struct dentry *h_d;
18205 + h_d = au_h_dptr(dentry, bindex);
18206 + if (!h_d || d_is_negative(h_d))
18209 + h_inode = d_inode(h_d);
18210 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18211 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18212 + h_i = au_h_iptr(inode, bindex);
18214 + if (h_i == h_inode)
18220 + if (bindex < iinfo->ii_btop)
18221 + iinfo->ii_btop = bindex;
18222 + if (iinfo->ii_bbot < bindex)
18223 + iinfo->ii_bbot = bindex;
18224 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18227 + au_update_ibrange(inode, /*do_put_zero*/0);
18228 + e = au_dy_irefresh(inode);
18229 + if (unlikely(e && !err))
18232 + au_refresh_hinode_attr(inode, update && isdir);
18239 +static int set_inode(struct inode *inode, struct dentry *dentry)
18242 + unsigned int flags;
18244 + aufs_bindex_t bindex, btop, btail;
18245 + unsigned char isdir;
18246 + struct dentry *h_dentry;
18247 + struct inode *h_inode;
18248 + struct au_iinfo *iinfo;
18249 + const struct inode_operations *iop;
18251 + IiMustWriteLock(inode);
18255 + iop = au_sbi(inode->i_sb)->si_iop_array;
18256 + btop = au_dbtop(dentry);
18257 + h_dentry = au_h_dptr(dentry, btop);
18258 + h_inode = d_inode(h_dentry);
18259 + mode = h_inode->i_mode;
18260 + switch (mode & S_IFMT) {
18262 + btail = au_dbtail(dentry);
18263 + inode->i_op = iop + AuIop_OTHER;
18264 + inode->i_fop = &aufs_file_fop;
18265 + err = au_dy_iaop(inode, btop, h_inode);
18266 + if (unlikely(err))
18271 + btail = au_dbtaildir(dentry);
18272 + inode->i_op = iop + AuIop_DIR;
18273 + inode->i_fop = &aufs_dir_fop;
18276 + btail = au_dbtail(dentry);
18277 + inode->i_op = iop + AuIop_SYMLINK;
18283 + btail = au_dbtail(dentry);
18284 + inode->i_op = iop + AuIop_OTHER;
18285 + init_special_inode(inode, mode, h_inode->i_rdev);
18288 + AuIOErr("Unknown file type 0%o\n", mode);
18293 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18294 + flags = au_hi_flags(inode, isdir);
18295 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18296 + && au_ftest_hi(flags, HNOTIFY)
18297 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18298 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18299 + au_fclr_hi(flags, HNOTIFY);
18300 + iinfo = au_ii(inode);
18301 + iinfo->ii_btop = btop;
18302 + iinfo->ii_bbot = btail;
18303 + for (bindex = btop; bindex <= btail; bindex++) {
18304 + h_dentry = au_h_dptr(dentry, bindex);
18306 + au_set_h_iptr(inode, bindex,
18307 + au_igrab(d_inode(h_dentry)), flags);
18309 + au_cpup_attr_all(inode, /*force*/1);
18311 + * to force calling aufs_get_acl() every time,
18312 + * do not call cache_no_acl() for aufs inode.
18320 + * successful returns with iinfo write_locked
18322 + * zero: success, matched
18323 + * plus: no error, but unmatched
18325 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18328 + unsigned int gen, igflags;
18329 + aufs_bindex_t bindex, bbot;
18330 + struct inode *h_inode, *h_dinode;
18331 + struct dentry *h_dentry;
18334 + * before this function, if aufs got any iinfo lock, it must be only
18335 + * one, the parent dir.
18336 + * it can happen by UDBA and the obsoleted inode number.
18339 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18343 + ii_write_lock_new_child(inode);
18344 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18345 + h_dinode = d_inode(h_dentry);
18346 + bbot = au_ibbot(inode);
18347 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18348 + h_inode = au_h_iptr(inode, bindex);
18349 + if (!h_inode || h_inode != h_dinode)
18353 + gen = au_iigen(inode, &igflags);
18354 + if (gen == au_digen(dentry)
18355 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18358 + /* fully refresh inode using dentry */
18359 + err = au_refresh_hinode(inode, dentry);
18361 + au_update_iigen(inode, /*half*/0);
18365 + if (unlikely(err))
18366 + ii_write_unlock(inode);
18371 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18372 + unsigned int d_type, ino_t *ino)
18375 + const int isnondir = d_type != DT_DIR;
18377 + /* prevent hardlinked inode number from race condition */
18379 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18380 + if (unlikely(err))
18384 + err = au_xino_read(sb, bindex, h_ino, ino);
18385 + if (unlikely(err))
18386 + goto out_xinondir;
18390 + *ino = au_xino_new_ino(sb);
18391 + if (unlikely(!*ino))
18392 + goto out_xinondir;
18393 + err = au_xino_write(sb, bindex, h_ino, *ino);
18394 + if (unlikely(err))
18395 + goto out_xinondir;
18399 + if (isnondir && idx >= 0)
18400 + au_xinondir_leave(sb, bindex, h_ino, idx);
18405 +/* successful returns with iinfo write_locked */
18406 +/* todo: return with unlocked? */
18407 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18409 + struct inode *inode, *h_inode;
18410 + struct dentry *h_dentry;
18411 + struct super_block *sb;
18412 + ino_t h_ino, ino;
18413 + int err, idx, hlinked;
18414 + aufs_bindex_t btop;
18416 + sb = dentry->d_sb;
18417 + btop = au_dbtop(dentry);
18418 + h_dentry = au_h_dptr(dentry, btop);
18419 + h_inode = d_inode(h_dentry);
18420 + h_ino = h_inode->i_ino;
18421 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18425 + * stop 'race'-ing between hardlinks under different
18429 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18430 + inode = ERR_PTR(err);
18431 + if (unlikely(err))
18435 + err = au_xino_read(sb, btop, h_ino, &ino);
18436 + inode = ERR_PTR(err);
18437 + if (unlikely(err))
18438 + goto out_xinondir;
18441 + ino = au_xino_new_ino(sb);
18442 + if (unlikely(!ino)) {
18443 + inode = ERR_PTR(-EIO);
18444 + goto out_xinondir;
18448 + AuDbg("i%lu\n", (unsigned long)ino);
18449 + inode = au_iget_locked(sb, ino);
18450 + err = PTR_ERR(inode);
18451 + if (IS_ERR(inode))
18452 + goto out_xinondir;
18454 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18455 + if (inode->i_state & I_NEW) {
18456 + ii_write_lock_new_child(inode);
18457 + err = set_inode(inode, dentry);
18459 + unlock_new_inode(inode);
18460 + goto out_xinondir; /* success */
18464 + * iget_failed() calls iput(), but we need to call
18465 + * ii_write_unlock() after iget_failed(). so dirty hack for
18468 + atomic_inc(&inode->i_count);
18469 + iget_failed(inode);
18470 + ii_write_unlock(inode);
18471 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18472 + /* ignore this error */
18474 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18476 + * horrible race condition between lookup, readdir and copyup
18477 + * (or something).
18479 + if (hlinked && idx >= 0)
18480 + au_xinondir_leave(sb, btop, h_ino, idx);
18481 + err = reval_inode(inode, dentry);
18482 + if (unlikely(err < 0)) {
18487 + goto out; /* success */
18488 + else if (hlinked && idx >= 0) {
18489 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18490 + if (unlikely(err)) {
18492 + inode = ERR_PTR(err);
18498 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18499 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18500 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18501 + btop, au_sbtype(h_dentry->d_sb), dentry,
18502 + (unsigned long)h_ino, (unsigned long)ino);
18504 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18507 + if (hlinked && idx >= 0)
18508 + au_xinondir_leave(sb, btop, h_ino, idx);
18514 + inode = ERR_PTR(err);
18516 + if (hlinked && idx >= 0)
18517 + au_xinondir_leave(sb, btop, h_ino, idx);
18522 +/* ---------------------------------------------------------------------- */
18524 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18525 + struct inode *inode)
18528 + struct inode *hi;
18530 + err = au_br_rdonly(au_sbr(sb, bindex));
18532 + /* pseudo-link after flushed may happen out of bounds */
18535 + && au_ibtop(inode) <= bindex
18536 + && bindex <= au_ibbot(inode)) {
18538 + * permission check is unnecessary since vfsub routine
18539 + * will be called later
18541 + hi = au_h_iptr(inode, bindex);
18543 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18549 +int au_test_h_perm(struct inode *h_inode, int mask)
18551 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18553 + return inode_permission(h_inode, mask);
18556 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18558 + if (au_test_nfs(h_inode->i_sb)
18559 + && (mask & MAY_WRITE)
18560 + && S_ISDIR(h_inode->i_mode))
18561 + mask |= MAY_READ; /* force permission check */
18562 + return au_test_h_perm(h_inode, mask);
18564 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18565 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18566 +++ linux/fs/aufs/inode.h 2020-08-03 09:14:46.095748745 +0200
18568 +/* SPDX-License-Identifier: GPL-2.0 */
18570 + * Copyright (C) 2005-2020 Junjiro R. Okajima
18572 + * This program, aufs is free software; you can redistribute it and/or modify
18573 + * it under the terms of the GNU General Public License as published by
18574 + * the Free Software Foundation; either version 2 of the License, or
18575 + * (at your option) any later version.
18577 + * This program is distributed in the hope that it will be useful,
18578 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18579 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18580 + * GNU General Public License for more details.
18582 + * You should have received a copy of the GNU General Public License
18583 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18587 + * inode operations
18590 +#ifndef __AUFS_INODE_H__
18591 +#define __AUFS_INODE_H__
18595 +#include <linux/fsnotify.h>
18596 +#include "rwsem.h"
18600 +struct au_hnotify {
18601 +#ifdef CONFIG_AUFS_HNOTIFY
18602 +#ifdef CONFIG_AUFS_HFSNOTIFY
18603 + /* never use fsnotify_add_vfsmount_mark() */
18604 + struct fsnotify_mark hn_mark;
18606 + struct inode *hn_aufs_inode; /* no get/put */
18607 + struct rcu_head rcu;
18609 +} ____cacheline_aligned_in_smp;
18611 +struct au_hinode {
18612 + struct inode *hi_inode;
18613 + aufs_bindex_t hi_id;
18614 +#ifdef CONFIG_AUFS_HNOTIFY
18615 + struct au_hnotify *hi_notify;
18618 + /* reference to the copied-up whiteout with get/put */
18619 + struct dentry *hi_whdentry;
18623 +#define AuIG_HALF_REFRESHED 1
18624 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18625 +#define au_ig_fset(flags, name) \
18626 + do { (flags) |= AuIG_##name; } while (0)
18627 +#define au_ig_fclr(flags, name) \
18628 + do { (flags) &= ~AuIG_##name; } while (0)
18631 + spinlock_t ig_spin;
18632 + __u32 ig_generation, ig_flags;
18637 + struct au_iigen ii_generation;
18638 + struct super_block *ii_hsb1; /* no get/put */
18640 + struct au_rwsem ii_rwsem;
18641 + aufs_bindex_t ii_btop, ii_bbot;
18643 + struct au_hinode *ii_hinode;
18644 + struct au_vdir *ii_vdir;
18647 +struct au_icntnr {
18648 + struct au_iinfo iinfo;
18649 + struct inode vfs_inode;
18650 + struct hlist_bl_node plink;
18651 + struct rcu_head rcu;
18652 +} ____cacheline_aligned_in_smp;
18654 +/* au_pin flags */
18655 +#define AuPin_DI_LOCKED 1
18656 +#define AuPin_MNT_WRITE (1 << 1)
18657 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18658 +#define au_fset_pin(flags, name) \
18659 + do { (flags) |= AuPin_##name; } while (0)
18660 +#define au_fclr_pin(flags, name) \
18661 + do { (flags) &= ~AuPin_##name; } while (0)
18665 + struct dentry *dentry;
18666 + unsigned int udba;
18667 + unsigned char lsc_di, lsc_hi, flags;
18668 + aufs_bindex_t bindex;
18671 + struct dentry *parent;
18672 + struct au_hinode *hdir;
18673 + struct vfsmount *h_mnt;
18675 + /* temporary unlock/relock for copyup */
18676 + struct dentry *h_dentry, *h_parent;
18677 + struct au_branch *br;
18678 + struct task_struct *task;
18681 +void au_pin_hdir_unlock(struct au_pin *p);
18682 +int au_pin_hdir_lock(struct au_pin *p);
18683 +int au_pin_hdir_relock(struct au_pin *p);
18684 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18685 +void au_pin_hdir_release(struct au_pin *p);
18687 +/* ---------------------------------------------------------------------- */
18689 +static inline struct au_iinfo *au_ii(struct inode *inode)
18691 + BUG_ON(is_bad_inode(inode));
18692 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18695 +/* ---------------------------------------------------------------------- */
18698 +struct inode *au_igrab(struct inode *inode);
18699 +void au_refresh_iop(struct inode *inode, int force_getattr);
18700 +int au_refresh_hinode_self(struct inode *inode);
18701 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18702 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18703 + unsigned int d_type, ino_t *ino);
18704 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18705 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18706 + struct inode *inode);
18707 +int au_test_h_perm(struct inode *h_inode, int mask);
18708 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18710 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18711 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18713 +#ifdef CONFIG_AUFS_SHWH
18714 + return au_ino(sb, bindex, h_ino, d_type, ino);
18727 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
18728 + aufs_iop_nogetattr[AuIop_Last];
18730 +/* au_wr_dir flags */
18731 +#define AuWrDir_ADD_ENTRY 1
18732 +#define AuWrDir_ISDIR (1 << 1)
18733 +#define AuWrDir_TMPFILE (1 << 2)
18734 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18735 +#define au_fset_wrdir(flags, name) \
18736 + do { (flags) |= AuWrDir_##name; } while (0)
18737 +#define au_fclr_wrdir(flags, name) \
18738 + do { (flags) &= ~AuWrDir_##name; } while (0)
18740 +struct au_wr_dir_args {
18741 + aufs_bindex_t force_btgt;
18742 + unsigned char flags;
18744 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18745 + struct au_wr_dir_args *args);
18747 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18748 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18749 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18750 + unsigned int udba, unsigned char flags);
18751 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18752 + unsigned int udba, unsigned char flags) __must_check;
18753 +int au_do_pin(struct au_pin *pin) __must_check;
18754 +void au_unpin(struct au_pin *pin);
18755 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18757 +#define AuIcpup_DID_CPUP 1
18758 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18759 +#define au_fset_icpup(flags, name) \
18760 + do { (flags) |= AuIcpup_##name; } while (0)
18761 +#define au_fclr_icpup(flags, name) \
18762 + do { (flags) &= ~AuIcpup_##name; } while (0)
18764 +struct au_icpup_args {
18765 + unsigned char flags;
18766 + unsigned char pin_flags;
18767 + aufs_bindex_t btgt;
18768 + unsigned int udba;
18769 + struct au_pin pin;
18770 + struct path h_path;
18771 + struct inode *h_inode;
18774 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18775 + struct au_icpup_args *a);
18777 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
18778 + struct path *h_path, int locked);
18781 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18782 + struct dentry *h_parent, int isdir);
18783 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18785 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
18786 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18788 +struct vfsub_aopen_args;
18789 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18790 + struct vfsub_aopen_args *args);
18791 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
18792 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18793 + struct dentry *dentry);
18794 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
18797 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18798 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18799 + struct dentry *h_parent, int isdir);
18800 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18801 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
18804 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
18805 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
18806 + struct inode *dir, struct dentry *dentry,
18807 + unsigned int flags);
18810 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
18811 +void au_hiput(struct au_hinode *hinode);
18812 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18813 + struct dentry *h_wh);
18814 +unsigned int au_hi_flags(struct inode *inode, int isdir);
18816 +/* hinode flags */
18817 +#define AuHi_XINO 1
18818 +#define AuHi_HNOTIFY (1 << 1)
18819 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
18820 +#define au_fset_hi(flags, name) \
18821 + do { (flags) |= AuHi_##name; } while (0)
18822 +#define au_fclr_hi(flags, name) \
18823 + do { (flags) &= ~AuHi_##name; } while (0)
18825 +#ifndef CONFIG_AUFS_HNOTIFY
18826 +#undef AuHi_HNOTIFY
18827 +#define AuHi_HNOTIFY 0
18830 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18831 + struct inode *h_inode, unsigned int flags);
18833 +void au_update_iigen(struct inode *inode, int half);
18834 +void au_update_ibrange(struct inode *inode, int do_put_zero);
18836 +void au_icntnr_init_once(void *_c);
18837 +void au_hinode_init(struct au_hinode *hinode);
18838 +int au_iinfo_init(struct inode *inode);
18839 +void au_iinfo_fin(struct inode *inode);
18840 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
18842 +#ifdef CONFIG_PROC_FS
18844 +int au_plink_maint(struct super_block *sb, int flags);
18846 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
18847 +int au_plink_maint_enter(struct super_block *sb);
18848 +#ifdef CONFIG_AUFS_DEBUG
18849 +void au_plink_list(struct super_block *sb);
18851 +AuStubVoid(au_plink_list, struct super_block *sb)
18853 +int au_plink_test(struct inode *inode);
18854 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
18855 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
18856 + struct dentry *h_dentry);
18857 +void au_plink_put(struct super_block *sb, int verbose);
18858 +void au_plink_clean(struct super_block *sb, int verbose);
18859 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
18861 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
18862 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
18863 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
18864 +AuStubVoid(au_plink_list, struct super_block *sb);
18865 +AuStubInt0(au_plink_test, struct inode *inode);
18866 +AuStub(struct dentry *, au_plink_lkup, return NULL,
18867 + struct inode *inode, aufs_bindex_t bindex);
18868 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
18869 + struct dentry *h_dentry);
18870 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
18871 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
18872 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
18873 +#endif /* CONFIG_PROC_FS */
18875 +#ifdef CONFIG_AUFS_XATTR
18877 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
18878 + unsigned int verbose);
18879 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
18880 +void au_xattr_init(struct super_block *sb);
18882 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
18883 + int ignore_flags, unsigned int verbose);
18884 +AuStubVoid(au_xattr_init, struct super_block *sb);
18887 +#ifdef CONFIG_FS_POSIX_ACL
18888 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
18889 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
18892 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
18898 +struct au_sxattr {
18902 + const char *name;
18903 + const void *value;
18908 + struct posix_acl *acl;
18913 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
18914 + struct au_sxattr *arg);
18917 +/* ---------------------------------------------------------------------- */
18919 +/* lock subclass for iinfo */
18921 + AuLsc_II_CHILD, /* child first */
18922 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
18923 + AuLsc_II_CHILD3, /* copyup dirs */
18924 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
18925 + AuLsc_II_PARENT2,
18926 + AuLsc_II_PARENT3, /* copyup dirs */
18927 + AuLsc_II_NEW_CHILD
18931 + * ii_read_lock_child, ii_write_lock_child,
18932 + * ii_read_lock_child2, ii_write_lock_child2,
18933 + * ii_read_lock_child3, ii_write_lock_child3,
18934 + * ii_read_lock_parent, ii_write_lock_parent,
18935 + * ii_read_lock_parent2, ii_write_lock_parent2,
18936 + * ii_read_lock_parent3, ii_write_lock_parent3,
18937 + * ii_read_lock_new_child, ii_write_lock_new_child,
18939 +#define AuReadLockFunc(name, lsc) \
18940 +static inline void ii_read_lock_##name(struct inode *i) \
18942 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18945 +#define AuWriteLockFunc(name, lsc) \
18946 +static inline void ii_write_lock_##name(struct inode *i) \
18948 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18951 +#define AuRWLockFuncs(name, lsc) \
18952 + AuReadLockFunc(name, lsc) \
18953 + AuWriteLockFunc(name, lsc)
18955 +AuRWLockFuncs(child, CHILD);
18956 +AuRWLockFuncs(child2, CHILD2);
18957 +AuRWLockFuncs(child3, CHILD3);
18958 +AuRWLockFuncs(parent, PARENT);
18959 +AuRWLockFuncs(parent2, PARENT2);
18960 +AuRWLockFuncs(parent3, PARENT3);
18961 +AuRWLockFuncs(new_child, NEW_CHILD);
18963 +#undef AuReadLockFunc
18964 +#undef AuWriteLockFunc
18965 +#undef AuRWLockFuncs
18967 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
18968 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
18969 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
18971 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
18972 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
18973 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
18975 +/* ---------------------------------------------------------------------- */
18977 +static inline void au_icntnr_init(struct au_icntnr *c)
18979 +#ifdef CONFIG_AUFS_DEBUG
18980 + c->vfs_inode.i_mode = 0;
18984 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
18986 + unsigned int gen;
18987 + struct au_iinfo *iinfo;
18988 + struct au_iigen *iigen;
18990 + iinfo = au_ii(inode);
18991 + iigen = &iinfo->ii_generation;
18992 + spin_lock(&iigen->ig_spin);
18994 + *igflags = iigen->ig_flags;
18995 + gen = iigen->ig_generation;
18996 + spin_unlock(&iigen->ig_spin);
19001 +/* tiny test for inode number */
19002 +/* tmpfs generation is too rough */
19003 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19005 + struct au_iinfo *iinfo;
19007 + iinfo = au_ii(inode);
19008 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19009 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19010 + && iinfo->ii_higen == h_inode->i_generation);
19013 +static inline void au_iigen_dec(struct inode *inode)
19015 + struct au_iinfo *iinfo;
19016 + struct au_iigen *iigen;
19018 + iinfo = au_ii(inode);
19019 + iigen = &iinfo->ii_generation;
19020 + spin_lock(&iigen->ig_spin);
19021 + iigen->ig_generation--;
19022 + spin_unlock(&iigen->ig_spin);
19025 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19030 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19036 +/* ---------------------------------------------------------------------- */
19038 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19039 + aufs_bindex_t bindex)
19041 + return iinfo->ii_hinode + bindex;
19044 +static inline int au_is_bad_inode(struct inode *inode)
19046 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19049 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19050 + aufs_bindex_t bindex)
19052 + IiMustAnyLock(inode);
19053 + return au_hinode(au_ii(inode), bindex)->hi_id;
19056 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19058 + IiMustAnyLock(inode);
19059 + return au_ii(inode)->ii_btop;
19062 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19064 + IiMustAnyLock(inode);
19065 + return au_ii(inode)->ii_bbot;
19068 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19070 + IiMustAnyLock(inode);
19071 + return au_ii(inode)->ii_vdir;
19074 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19076 + IiMustAnyLock(inode);
19077 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19080 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19082 + IiMustWriteLock(inode);
19083 + au_ii(inode)->ii_btop = bindex;
19086 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19088 + IiMustWriteLock(inode);
19089 + au_ii(inode)->ii_bbot = bindex;
19092 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19094 + IiMustWriteLock(inode);
19095 + au_ii(inode)->ii_vdir = vdir;
19098 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19100 + IiMustAnyLock(inode);
19101 + return au_hinode(au_ii(inode), bindex);
19104 +/* ---------------------------------------------------------------------- */
19106 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19109 + return pin->parent;
19113 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19115 + if (pin && pin->hdir)
19116 + return pin->hdir->hi_inode;
19120 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19123 + return pin->hdir;
19127 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19130 + pin->dentry = dentry;
19133 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19134 + unsigned char lflag)
19138 + au_fset_pin(pin->flags, DI_LOCKED);
19140 + au_fclr_pin(pin->flags, DI_LOCKED);
19144 +#if 0 /* reserved */
19145 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19148 + dput(pin->parent);
19149 + pin->parent = dget(parent);
19154 +/* ---------------------------------------------------------------------- */
19157 +#ifdef CONFIG_AUFS_HNOTIFY
19158 +struct au_hnotify_op {
19159 + void (*ctl)(struct au_hinode *hinode, int do_set);
19160 + int (*alloc)(struct au_hinode *hinode);
19163 + * if it returns true, the the caller should free hinode->hi_notify,
19164 + * otherwise ->free() frees it.
19166 + int (*free)(struct au_hinode *hinode,
19167 + struct au_hnotify *hn) __must_check;
19169 + void (*fin)(void);
19170 + int (*init)(void);
19172 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19173 + void (*fin_br)(struct au_branch *br);
19174 + int (*init_br)(struct au_branch *br, int perm);
19178 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19179 +void au_hn_free(struct au_hinode *hinode);
19180 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19181 +void au_hn_reset(struct inode *inode, unsigned int flags);
19182 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19183 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
19184 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19185 +int au_hnotify_init_br(struct au_branch *br, int perm);
19186 +void au_hnotify_fin_br(struct au_branch *br);
19187 +int __init au_hnotify_init(void);
19188 +void au_hnotify_fin(void);
19191 +extern const struct au_hnotify_op au_hnotify_op;
19194 +void au_hn_init(struct au_hinode *hinode)
19196 + hinode->hi_notify = NULL;
19199 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19201 + return hinode->hi_notify;
19205 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19206 + struct au_hinode *hinode __maybe_unused,
19207 + struct inode *inode __maybe_unused)
19208 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19209 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19210 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19211 + int do_set __maybe_unused)
19212 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19213 + unsigned int flags __maybe_unused)
19214 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19215 + struct au_branch *br __maybe_unused,
19216 + int perm __maybe_unused)
19217 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19218 + int perm __maybe_unused)
19219 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19220 +AuStubInt0(__init au_hnotify_init, void)
19221 +AuStubVoid(au_hnotify_fin, void)
19222 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19223 +#endif /* CONFIG_AUFS_HNOTIFY */
19225 +static inline void au_hn_suspend(struct au_hinode *hdir)
19227 + au_hn_ctl(hdir, /*do_set*/0);
19230 +static inline void au_hn_resume(struct au_hinode *hdir)
19232 + au_hn_ctl(hdir, /*do_set*/1);
19235 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19237 + inode_lock(hdir->hi_inode);
19238 + au_hn_suspend(hdir);
19241 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19242 + unsigned int sc __maybe_unused)
19244 + inode_lock_nested(hdir->hi_inode, sc);
19245 + au_hn_suspend(hdir);
19248 +#if 0 /* unused */
19249 +#include "vfsub.h"
19250 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19253 + inode_lock_shared_nested(hdir->hi_inode, sc);
19254 + au_hn_suspend(hdir);
19258 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19260 + au_hn_resume(hdir);
19261 + inode_unlock(hdir->hi_inode);
19264 +#endif /* __KERNEL__ */
19265 +#endif /* __AUFS_INODE_H__ */
19266 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19267 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19268 +++ linux/fs/aufs/ioctl.c 2020-01-27 10:57:18.175538316 +0100
19270 +// SPDX-License-Identifier: GPL-2.0
19272 + * Copyright (C) 2005-2020 Junjiro R. Okajima
19274 + * This program, aufs is free software; you can redistribute it and/or modify
19275 + * it under the terms of the GNU General Public License as published by
19276 + * the Free Software Foundation; either version 2 of the License, or
19277 + * (at your option) any later version.
19279 + * This program is distributed in the hope that it will be useful,
19280 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19281 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19282 + * GNU General Public License for more details.
19284 + * You should have received a copy of the GNU General Public License
19285 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19290 + * plink-management and readdir in userspace.
19291 + * assist the pathconf(3) wrapper library.
19293 + * File-based Hierarchical Storage Management.
19296 +#include <linux/compat.h>
19297 +#include <linux/file.h>
19300 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19303 + aufs_bindex_t wbi, bindex, bbot;
19304 + struct file *h_file;
19305 + struct super_block *sb;
19306 + struct dentry *root;
19307 + struct au_branch *br;
19308 + struct aufs_wbr_fd wbrfd = {
19309 + .oflags = au_dir_roflags,
19312 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19313 + | O_NOATIME | O_CLOEXEC;
19315 + AuDebugOn(wbrfd.oflags & ~valid);
19318 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19319 + if (unlikely(err)) {
19325 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19326 + wbrfd.oflags |= au_dir_roflags;
19327 + AuDbg("0%o\n", wbrfd.oflags);
19328 + if (unlikely(wbrfd.oflags & ~valid))
19332 + fd = get_unused_fd_flags(0);
19334 + if (unlikely(fd < 0))
19337 + h_file = ERR_PTR(-EINVAL);
19340 + sb = path->dentry->d_sb;
19341 + root = sb->s_root;
19342 + aufs_read_lock(root, AuLock_IR);
19343 + bbot = au_sbbot(sb);
19344 + if (wbrfd.brid >= 0) {
19345 + wbi = au_br_index(sb, wbrfd.brid);
19346 + if (unlikely(wbi < 0 || wbi > bbot))
19350 + h_file = ERR_PTR(-ENOENT);
19351 + br = au_sbr(sb, wbi);
19352 + if (!au_br_writable(br->br_perm)) {
19356 + bindex = wbi + 1;
19358 + for (; bindex <= bbot; bindex++) {
19359 + br = au_sbr(sb, bindex);
19360 + if (au_br_writable(br->br_perm)) {
19362 + br = au_sbr(sb, wbi);
19367 + AuDbg("wbi %d\n", wbi);
19369 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19373 + aufs_read_unlock(root, AuLock_IR);
19374 + err = PTR_ERR(h_file);
19375 + if (IS_ERR(h_file))
19378 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19379 + fd_install(fd, h_file);
19381 + goto out; /* success */
19384 + put_unused_fd(fd);
19390 +/* ---------------------------------------------------------------------- */
19392 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19395 + struct dentry *dentry;
19398 + case AUFS_CTL_RDU:
19399 + case AUFS_CTL_RDU_INO:
19400 + err = au_rdu_ioctl(file, cmd, arg);
19403 + case AUFS_CTL_WBR_FD:
19404 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19407 + case AUFS_CTL_IBUSY:
19408 + err = au_ibusy_ioctl(file, arg);
19411 + case AUFS_CTL_BRINFO:
19412 + err = au_brinfo_ioctl(file, arg);
19415 + case AUFS_CTL_FHSM_FD:
19416 + dentry = file->f_path.dentry;
19417 + if (IS_ROOT(dentry))
19418 + err = au_fhsm_fd(dentry->d_sb, arg);
19424 + /* do not call the lower */
19425 + AuDbg("0x%x\n", cmd);
19433 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19438 + case AUFS_CTL_MVDOWN:
19439 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19442 + case AUFS_CTL_WBR_FD:
19443 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19447 + /* do not call the lower */
19448 + AuDbg("0x%x\n", cmd);
19456 +#ifdef CONFIG_COMPAT
19457 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19458 + unsigned long arg)
19463 + case AUFS_CTL_RDU:
19464 + case AUFS_CTL_RDU_INO:
19465 + err = au_rdu_compat_ioctl(file, cmd, arg);
19468 + case AUFS_CTL_IBUSY:
19469 + err = au_ibusy_compat_ioctl(file, arg);
19472 + case AUFS_CTL_BRINFO:
19473 + err = au_brinfo_compat_ioctl(file, arg);
19477 + err = aufs_ioctl_dir(file, cmd, arg);
19484 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19485 + unsigned long arg)
19487 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19490 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19491 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19492 +++ linux/fs/aufs/i_op_add.c 2020-01-27 10:57:18.172204883 +0100
19494 +// SPDX-License-Identifier: GPL-2.0
19496 + * Copyright (C) 2005-2020 Junjiro R. Okajima
19498 + * This program, aufs is free software; you can redistribute it and/or modify
19499 + * it under the terms of the GNU General Public License as published by
19500 + * the Free Software Foundation; either version 2 of the License, or
19501 + * (at your option) any later version.
19503 + * This program is distributed in the hope that it will be useful,
19504 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19505 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19506 + * GNU General Public License for more details.
19508 + * You should have received a copy of the GNU General Public License
19509 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19513 + * inode operations (add entry)
19516 +#include <linux/iversion.h>
19520 + * final procedure of adding a new entry, except link(2).
19521 + * remove whiteout, instantiate, copyup the parent dir's times and size
19522 + * and update version.
19523 + * if it failed, re-create the removed whiteout.
19525 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19526 + struct dentry *wh_dentry, struct dentry *dentry)
19529 + aufs_bindex_t bwh;
19530 + struct path h_path;
19531 + struct super_block *sb;
19532 + struct inode *inode, *h_dir;
19533 + struct dentry *wh;
19538 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19539 + IMustLock(h_dir);
19540 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19541 + bwh = au_dbwh(dentry);
19542 + h_path.dentry = wh_dentry;
19543 + h_path.mnt = au_sbr_mnt(sb, bindex);
19544 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19546 + if (unlikely(err))
19550 + inode = au_new_inode(dentry, /*must_new*/1);
19551 + if (!IS_ERR(inode)) {
19552 + d_instantiate(dentry, inode);
19553 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19555 + au_dir_ts(dir, bindex);
19556 + inode_inc_iversion(dir);
19557 + au_fhsm_wrote(sb, bindex, /*force*/0);
19558 + return 0; /* success */
19561 + err = PTR_ERR(inode);
19566 + /* dir inode is locked */
19567 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19568 + rerr = PTR_ERR(wh);
19569 + if (IS_ERR(wh)) {
19570 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19571 + dentry, err, rerr);
19580 +static int au_d_may_add(struct dentry *dentry)
19585 + if (unlikely(d_unhashed(dentry)))
19587 + if (unlikely(d_really_is_positive(dentry)))
19593 + * simple tests for the adding inode operations.
19594 + * following the checks in vfs, plus the parent-child relationship.
19596 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19597 + struct dentry *h_parent, int isdir)
19601 + struct dentry *h_dentry;
19602 + struct inode *h_inode;
19604 + err = -ENAMETOOLONG;
19605 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19608 + h_dentry = au_h_dptr(dentry, bindex);
19609 + if (d_really_is_negative(dentry)) {
19611 + if (unlikely(d_is_positive(h_dentry)))
19614 + /* rename(2) case */
19616 + if (unlikely(d_is_negative(h_dentry)))
19618 + h_inode = d_inode(h_dentry);
19619 + if (unlikely(!h_inode->i_nlink))
19622 + h_mode = h_inode->i_mode;
19625 + if (unlikely(S_ISDIR(h_mode)))
19627 + } else if (unlikely(!S_ISDIR(h_mode))) {
19634 + /* expected parent dir is locked */
19635 + if (unlikely(h_parent != h_dentry->d_parent))
19644 + * initial procedure of adding a new entry.
19645 + * prepare writable branch and the parent dir, lock it,
19646 + * and lookup whiteout for the new entry.
19648 +static struct dentry*
19649 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19650 + struct dentry *src_dentry, struct au_pin *pin,
19651 + struct au_wr_dir_args *wr_dir_args)
19653 + struct dentry *wh_dentry, *h_parent;
19654 + struct super_block *sb;
19655 + struct au_branch *br;
19657 + unsigned int udba;
19658 + aufs_bindex_t bcpup;
19660 + AuDbg("%pd\n", dentry);
19662 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19664 + wh_dentry = ERR_PTR(err);
19665 + if (unlikely(err < 0))
19668 + sb = dentry->d_sb;
19669 + udba = au_opt_udba(sb);
19670 + err = au_pin(pin, dentry, bcpup, udba,
19671 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19672 + wh_dentry = ERR_PTR(err);
19673 + if (unlikely(err))
19676 + h_parent = au_pinned_h_parent(pin);
19677 + if (udba != AuOpt_UDBA_NONE
19678 + && au_dbtop(dentry) == bcpup)
19679 + err = au_may_add(dentry, bcpup, h_parent,
19680 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19681 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19682 + err = -ENAMETOOLONG;
19683 + wh_dentry = ERR_PTR(err);
19684 + if (unlikely(err))
19687 + br = au_sbr(sb, bcpup);
19689 + struct path tmp = {
19690 + .dentry = h_parent,
19691 + .mnt = au_br_mnt(br)
19693 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19696 + wh_dentry = NULL;
19697 + if (bcpup != au_dbwh(dentry))
19698 + goto out; /* success */
19701 + * ENAMETOOLONG here means that if we allowed create such name, then it
19702 + * would not be able to removed in the future. So we don't allow such
19703 + * name here and we don't handle ENAMETOOLONG differently here.
19705 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19708 + if (IS_ERR(wh_dentry))
19711 + return wh_dentry;
19714 +/* ---------------------------------------------------------------------- */
19716 +enum { Mknod, Symlink, Creat };
19717 +struct simple_arg {
19724 + struct vfsub_aopen_args *aopen;
19727 + const char *symname;
19736 +static int add_simple(struct inode *dir, struct dentry *dentry,
19737 + struct simple_arg *arg)
19740 + aufs_bindex_t btop;
19741 + unsigned char created;
19742 + const unsigned char try_aopen
19743 + = (arg->type == Creat && arg->u.c.try_aopen);
19744 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19745 + struct dentry *wh_dentry, *parent;
19746 + struct inode *h_dir;
19747 + struct super_block *sb;
19748 + struct au_branch *br;
19749 + /* to reduce stack size */
19751 + struct au_dtime dt;
19752 + struct au_pin pin;
19753 + struct path h_path;
19754 + struct au_wr_dir_args wr_dir_args;
19757 + AuDbg("%pd\n", dentry);
19761 + a = kmalloc(sizeof(*a), GFP_NOFS);
19762 + if (unlikely(!a))
19764 + a->wr_dir_args.force_btgt = -1;
19765 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19767 + parent = dentry->d_parent; /* dir inode is locked */
19768 + if (!try_aopen) {
19769 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19770 + if (unlikely(err))
19773 + err = au_d_may_add(dentry);
19774 + if (unlikely(err))
19777 + di_write_lock_parent(parent);
19778 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19779 + &a->pin, &a->wr_dir_args);
19780 + err = PTR_ERR(wh_dentry);
19781 + if (IS_ERR(wh_dentry))
19784 + btop = au_dbtop(dentry);
19785 + sb = dentry->d_sb;
19786 + br = au_sbr(sb, btop);
19787 + a->h_path.dentry = au_h_dptr(dentry, btop);
19788 + a->h_path.mnt = au_br_mnt(br);
19789 + h_dir = au_pinned_h_dir(&a->pin);
19790 + switch (arg->type) {
19792 + if (!try_aopen || !h_dir->i_op->atomic_open) {
19793 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19794 + arg->u.c.want_excl);
19796 + if (!err && try_aopen)
19797 + aopen->file->f_mode |= FMODE_CREATED;
19800 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
19801 + AuDbg("err %d\n", err);
19802 + AuDbgFile(aopen->file);
19803 + created = err >= 0
19804 + && !!(aopen->file->f_mode & FMODE_CREATED);
19808 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
19812 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
19819 + if (unlikely(err < 0))
19822 + err = epilog(dir, btop, wh_dentry, dentry);
19824 + goto out_unpin; /* success */
19827 + if (created /* && d_is_positive(a->h_path.dentry) */) {
19828 + /* no delegation since it is just created */
19829 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
19832 + AuIOErr("%pd revert failure(%d, %d)\n",
19833 + dentry, err, rerr);
19836 + au_dtime_revert(&a->dt);
19838 + if (try_aopen && h_dir->i_op->atomic_open
19839 + && (aopen->file->f_mode & FMODE_OPENED))
19840 + /* aopen->file is still opened */
19841 + au_lcnt_dec(&aopen->br->br_nfiles);
19844 + au_unpin(&a->pin);
19848 + di_write_unlock(parent);
19850 + if (unlikely(err)) {
19851 + au_update_dbtop(dentry);
19855 + aufs_read_unlock(dentry, AuLock_DW);
19862 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
19865 + struct simple_arg arg = {
19872 + return add_simple(dir, dentry, &arg);
19875 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
19877 + struct simple_arg arg = {
19879 + .u.s.symname = symname
19881 + return add_simple(dir, dentry, &arg);
19884 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
19887 + struct simple_arg arg = {
19891 + .want_excl = want_excl
19894 + return add_simple(dir, dentry, &arg);
19897 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
19898 + struct vfsub_aopen_args *aopen_args)
19900 + struct simple_arg arg = {
19903 + .mode = aopen_args->create_mode,
19904 + .want_excl = aopen_args->open_flag & O_EXCL,
19905 + .try_aopen = true,
19906 + .aopen = aopen_args
19909 + return add_simple(dir, dentry, &arg);
19912 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
19915 + aufs_bindex_t bindex;
19916 + struct super_block *sb;
19917 + struct dentry *parent, *h_parent, *h_dentry;
19918 + struct inode *h_dir, *inode;
19919 + struct vfsmount *h_mnt;
19920 + struct au_wr_dir_args wr_dir_args = {
19921 + .force_btgt = -1,
19922 + .flags = AuWrDir_TMPFILE
19925 + /* copy-up may happen */
19929 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19930 + if (unlikely(err))
19933 + err = au_di_init(dentry);
19934 + if (unlikely(err))
19938 + parent = d_find_any_alias(dir);
19939 + AuDebugOn(!parent);
19940 + di_write_lock_parent(parent);
19941 + if (unlikely(d_inode(parent) != dir))
19944 + err = au_digen_test(parent, au_sigen(sb));
19945 + if (unlikely(err))
19948 + bindex = au_dbtop(parent);
19949 + au_set_dbtop(dentry, bindex);
19950 + au_set_dbbot(dentry, bindex);
19951 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19953 + if (unlikely(err < 0))
19956 + err = -EOPNOTSUPP;
19957 + h_dir = au_h_iptr(dir, bindex);
19958 + if (unlikely(!h_dir->i_op->tmpfile))
19961 + h_mnt = au_sbr_mnt(sb, bindex);
19962 + err = vfsub_mnt_want_write(h_mnt);
19963 + if (unlikely(err))
19966 + h_parent = au_h_dptr(parent, bindex);
19967 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
19968 + if (IS_ERR(h_dentry)) {
19969 + err = PTR_ERR(h_dentry);
19973 + au_set_dbtop(dentry, bindex);
19974 + au_set_dbbot(dentry, bindex);
19975 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
19976 + inode = au_new_inode(dentry, /*must_new*/1);
19977 + if (IS_ERR(inode)) {
19978 + err = PTR_ERR(inode);
19979 + au_set_h_dptr(dentry, bindex, NULL);
19980 + au_set_dbtop(dentry, -1);
19981 + au_set_dbbot(dentry, -1);
19983 + if (!inode->i_nlink)
19984 + set_nlink(inode, 1);
19985 + d_tmpfile(dentry, inode);
19986 + au_di(dentry)->di_tmpfile = 1;
19988 + /* update without i_mutex */
19989 + if (au_ibtop(dir) == au_dbtop(dentry))
19990 + au_cpup_attr_timesizes(dir);
19995 + vfsub_mnt_drop_write(h_mnt);
19997 + di_write_unlock(parent);
19999 + di_write_unlock(dentry);
20000 + if (unlikely(err)) {
20001 + au_di_fin(dentry);
20002 + dentry->d_fsdata = NULL;
20005 + si_read_unlock(sb);
20007 + inode_unlock(dir);
20011 +/* ---------------------------------------------------------------------- */
20013 +struct au_link_args {
20014 + aufs_bindex_t bdst, bsrc;
20015 + struct au_pin pin;
20016 + struct path h_path;
20017 + struct dentry *src_parent, *parent;
20020 +static int au_cpup_before_link(struct dentry *src_dentry,
20021 + struct au_link_args *a)
20024 + struct dentry *h_src_dentry;
20025 + struct au_cp_generic cpg = {
20026 + .dentry = src_dentry,
20031 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20034 + di_read_lock_parent(a->src_parent, AuLock_IR);
20035 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20036 + if (unlikely(err))
20039 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20040 + err = au_pin(&a->pin, src_dentry, a->bdst,
20041 + au_opt_udba(src_dentry->d_sb),
20042 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20043 + if (unlikely(err))
20046 + err = au_sio_cpup_simple(&cpg);
20047 + au_unpin(&a->pin);
20050 + di_read_unlock(a->src_parent, AuLock_IR);
20054 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20055 + struct au_link_args *a)
20058 + unsigned char plink;
20059 + aufs_bindex_t bbot;
20060 + struct dentry *h_src_dentry;
20061 + struct inode *h_inode, *inode, *delegated;
20062 + struct super_block *sb;
20063 + struct file *h_file;
20067 + sb = src_dentry->d_sb;
20068 + inode = d_inode(src_dentry);
20069 + if (au_ibtop(inode) <= a->bdst)
20070 + h_inode = au_h_iptr(inode, a->bdst);
20071 + if (!h_inode || !h_inode->i_nlink) {
20072 + /* copyup src_dentry as the name of dentry. */
20073 + bbot = au_dbbot(dentry);
20074 + if (bbot < a->bsrc)
20075 + au_set_dbbot(dentry, a->bsrc);
20076 + au_set_h_dptr(dentry, a->bsrc,
20077 + dget(au_h_dptr(src_dentry, a->bsrc)));
20078 + dget(a->h_path.dentry);
20079 + au_set_h_dptr(dentry, a->bdst, NULL);
20080 + AuDbg("temporary d_inode...\n");
20081 + spin_lock(&dentry->d_lock);
20082 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20083 + spin_unlock(&dentry->d_lock);
20084 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20085 + if (IS_ERR(h_file))
20086 + err = PTR_ERR(h_file);
20088 + struct au_cp_generic cpg = {
20089 + .dentry = dentry,
20094 + .flags = AuCpup_KEEPLINO
20096 + err = au_sio_cpup_simple(&cpg);
20097 + au_h_open_post(dentry, a->bsrc, h_file);
20099 + dput(a->h_path.dentry);
20100 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20102 + au_set_h_dptr(dentry, a->bdst,
20103 + a->h_path.dentry);
20105 + spin_lock(&dentry->d_lock);
20106 + dentry->d_inode = NULL; /* restore */
20107 + spin_unlock(&dentry->d_lock);
20108 + AuDbg("temporary d_inode...done\n");
20109 + au_set_h_dptr(dentry, a->bsrc, NULL);
20110 + au_set_dbbot(dentry, bbot);
20112 + /* the inode of src_dentry already exists on a.bdst branch */
20113 + h_src_dentry = d_find_alias(h_inode);
20114 + if (!h_src_dentry && au_plink_test(inode)) {
20116 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20117 + err = PTR_ERR(h_src_dentry);
20118 + if (IS_ERR(h_src_dentry))
20121 + if (unlikely(d_is_negative(h_src_dentry))) {
20122 + dput(h_src_dentry);
20123 + h_src_dentry = NULL;
20127 + if (h_src_dentry) {
20128 + delegated = NULL;
20129 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20130 + &a->h_path, &delegated);
20131 + if (unlikely(err == -EWOULDBLOCK)) {
20132 + pr_warn("cannot retry for NFSv4 delegation"
20133 + " for an internal link\n");
20136 + dput(h_src_dentry);
20138 + AuIOErr("no dentry found for hi%lu on b%d\n",
20139 + h_inode->i_ino, a->bdst);
20144 + if (!err && !plink)
20145 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20152 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20153 + struct dentry *dentry)
20156 + struct au_dtime dt;
20157 + struct au_link_args *a;
20158 + struct dentry *wh_dentry, *h_src_dentry;
20159 + struct inode *inode, *delegated;
20160 + struct super_block *sb;
20161 + struct au_wr_dir_args wr_dir_args = {
20162 + /* .force_btgt = -1, */
20163 + .flags = AuWrDir_ADD_ENTRY
20167 + inode = d_inode(src_dentry);
20168 + IMustLock(inode);
20171 + a = kzalloc(sizeof(*a), GFP_NOFS);
20172 + if (unlikely(!a))
20175 + a->parent = dentry->d_parent; /* dir inode is locked */
20176 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20177 + AuLock_NOPLM | AuLock_GEN);
20178 + if (unlikely(err))
20180 + err = au_d_linkable(src_dentry);
20181 + if (unlikely(err))
20183 + err = au_d_may_add(dentry);
20184 + if (unlikely(err))
20187 + a->src_parent = dget_parent(src_dentry);
20188 + wr_dir_args.force_btgt = au_ibtop(inode);
20190 + di_write_lock_parent(a->parent);
20191 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20192 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20194 + err = PTR_ERR(wh_dentry);
20195 + if (IS_ERR(wh_dentry))
20199 + sb = dentry->d_sb;
20200 + a->bdst = au_dbtop(dentry);
20201 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20202 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20203 + a->bsrc = au_ibtop(inode);
20204 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20205 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20206 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20207 + if (!h_src_dentry) {
20208 + a->bsrc = au_dbtop(src_dentry);
20209 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20210 + AuDebugOn(!h_src_dentry);
20211 + } else if (IS_ERR(h_src_dentry)) {
20212 + err = PTR_ERR(h_src_dentry);
20217 + * aufs doesn't touch the credential so
20218 + * security_dentry_create_files_as() is unnecessary.
20220 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20221 + if (a->bdst < a->bsrc
20222 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20223 + err = au_cpup_or_link(src_dentry, dentry, a);
20225 + delegated = NULL;
20226 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20227 + &a->h_path, &delegated);
20228 + if (unlikely(err == -EWOULDBLOCK)) {
20229 + pr_warn("cannot retry for NFSv4 delegation"
20230 + " for an internal link\n");
20234 + dput(h_src_dentry);
20237 + * copyup src_dentry to the branch we process,
20238 + * and then link(2) to it.
20240 + dput(h_src_dentry);
20241 + if (a->bdst < a->bsrc
20242 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20243 + au_unpin(&a->pin);
20244 + di_write_unlock(a->parent);
20245 + err = au_cpup_before_link(src_dentry, a);
20246 + di_write_lock_parent(a->parent);
20248 + err = au_pin(&a->pin, dentry, a->bdst,
20250 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20251 + if (unlikely(err))
20255 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20257 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20258 + delegated = NULL;
20259 + err = vfsub_link(h_src_dentry,
20260 + au_pinned_h_dir(&a->pin),
20261 + &a->h_path, &delegated);
20262 + if (unlikely(err == -EWOULDBLOCK)) {
20263 + pr_warn("cannot retry"
20264 + " for NFSv4 delegation"
20265 + " for an internal link\n");
20271 + if (unlikely(err))
20275 + a->h_path.dentry = wh_dentry;
20276 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20278 + if (unlikely(err))
20282 + au_dir_ts(dir, a->bdst);
20283 + inode_inc_iversion(dir);
20284 + inc_nlink(inode);
20285 + inode->i_ctime = dir->i_ctime;
20286 + d_instantiate(dentry, au_igrab(inode));
20287 + if (d_unhashed(a->h_path.dentry))
20288 + /* some filesystem calls d_drop() */
20290 + /* some filesystems consume an inode even hardlink */
20291 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20292 + goto out_unpin; /* success */
20295 + /* no delegation since it is just created */
20296 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20297 + /*delegated*/NULL, /*force*/0);
20298 + if (unlikely(rerr)) {
20299 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20302 + au_dtime_revert(&dt);
20304 + au_unpin(&a->pin);
20308 + di_write_unlock(a->parent);
20309 + dput(a->src_parent);
20311 + if (unlikely(err)) {
20312 + au_update_dbtop(dentry);
20315 + aufs_read_and_write_unlock2(dentry, src_dentry);
20323 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20326 + aufs_bindex_t bindex;
20327 + unsigned char diropq;
20328 + struct path h_path;
20329 + struct dentry *wh_dentry, *parent, *opq_dentry;
20330 + struct inode *h_inode;
20331 + struct super_block *sb;
20333 + struct au_pin pin;
20334 + struct au_dtime dt;
20335 + } *a; /* reduce the stack usage */
20336 + struct au_wr_dir_args wr_dir_args = {
20337 + .force_btgt = -1,
20338 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20344 + a = kmalloc(sizeof(*a), GFP_NOFS);
20345 + if (unlikely(!a))
20348 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20349 + if (unlikely(err))
20351 + err = au_d_may_add(dentry);
20352 + if (unlikely(err))
20355 + parent = dentry->d_parent; /* dir inode is locked */
20356 + di_write_lock_parent(parent);
20357 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20358 + &a->pin, &wr_dir_args);
20359 + err = PTR_ERR(wh_dentry);
20360 + if (IS_ERR(wh_dentry))
20363 + sb = dentry->d_sb;
20364 + bindex = au_dbtop(dentry);
20365 + h_path.dentry = au_h_dptr(dentry, bindex);
20366 + h_path.mnt = au_sbr_mnt(sb, bindex);
20367 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20368 + if (unlikely(err))
20371 + /* make the dir opaque */
20373 + h_inode = d_inode(h_path.dentry);
20375 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20376 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20377 + opq_dentry = au_diropq_create(dentry, bindex);
20378 + inode_unlock(h_inode);
20379 + err = PTR_ERR(opq_dentry);
20380 + if (IS_ERR(opq_dentry))
20382 + dput(opq_dentry);
20386 + err = epilog(dir, bindex, wh_dentry, dentry);
20389 + goto out_unpin; /* success */
20394 + AuLabel(revert opq);
20395 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20396 + rerr = au_diropq_remove(dentry, bindex);
20397 + inode_unlock(h_inode);
20399 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20400 + dentry, err, rerr);
20406 + AuLabel(revert dir);
20407 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20409 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20410 + dentry, err, rerr);
20413 + au_dtime_revert(&a->dt);
20415 + au_unpin(&a->pin);
20418 + di_write_unlock(parent);
20420 + if (unlikely(err)) {
20421 + au_update_dbtop(dentry);
20424 + aufs_read_unlock(dentry, AuLock_DW);
20430 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20431 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20432 +++ linux/fs/aufs/i_op.c 2020-08-03 09:14:46.095748745 +0200
20434 +// SPDX-License-Identifier: GPL-2.0
20436 + * Copyright (C) 2005-2020 Junjiro R. Okajima
20438 + * This program, aufs is free software; you can redistribute it and/or modify
20439 + * it under the terms of the GNU General Public License as published by
20440 + * the Free Software Foundation; either version 2 of the License, or
20441 + * (at your option) any later version.
20443 + * This program is distributed in the hope that it will be useful,
20444 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20445 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20446 + * GNU General Public License for more details.
20448 + * You should have received a copy of the GNU General Public License
20449 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20453 + * inode operations (except add/del/rename)
20456 +#include <linux/device_cgroup.h>
20457 +#include <linux/fs_stack.h>
20458 +#include <linux/iversion.h>
20459 +#include <linux/namei.h>
20460 +#include <linux/security.h>
20463 +static int h_permission(struct inode *h_inode, int mask,
20464 + struct path *h_path, int brperm)
20467 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20470 + if (write_mask && IS_IMMUTABLE(h_inode))
20474 + if (((mask & MAY_EXEC)
20475 + && S_ISREG(h_inode->i_mode)
20476 + && (path_noexec(h_path)
20477 + || !(h_inode->i_mode & 0111))))
20481 + * - skip the lower fs test in the case of write to ro branch.
20482 + * - nfs dir permission write check is optimized, but a policy for
20483 + * link/rename requires a real check.
20484 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20485 + * in this case, generic_permission() returns -EOPNOTSUPP.
20487 + if ((write_mask && !au_br_writable(brperm))
20488 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20489 + && write_mask && !(mask & MAY_READ))
20490 + || !h_inode->i_op->permission) {
20491 + /* AuLabel(generic_permission); */
20492 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20493 + err = generic_permission(h_inode, mask);
20494 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20495 + err = h_inode->i_op->permission(h_inode, mask);
20498 + /* AuLabel(h_inode->permission); */
20499 + err = h_inode->i_op->permission(h_inode, mask);
20504 + err = devcgroup_inode_permission(h_inode, mask);
20506 + err = security_inode_permission(h_inode, mask);
20512 +static int aufs_permission(struct inode *inode, int mask)
20515 + aufs_bindex_t bindex, bbot;
20516 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20517 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20518 + struct inode *h_inode;
20519 + struct super_block *sb;
20520 + struct au_branch *br;
20522 + /* todo: support rcu-walk? */
20523 + if (mask & MAY_NOT_BLOCK)
20526 + sb = inode->i_sb;
20527 + si_read_lock(sb, AuLock_FLUSH);
20528 + ii_read_lock_child(inode);
20529 +#if 0 /* reserved for future use */
20531 + * This test may be rather 'too much' since the test is essentially done
20532 + * in the aufs_lookup(). Theoretically it is possible that the inode
20533 + * generation doesn't match to the superblock's here. But it isn't a
20534 + * big deal I suppose.
20536 + err = au_iigen_test(inode, au_sigen(sb));
20537 + if (unlikely(err))
20543 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20544 + err = au_busy_or_stale();
20545 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20546 + if (unlikely(!h_inode
20547 + || (h_inode->i_mode & S_IFMT)
20548 + != (inode->i_mode & S_IFMT)))
20552 + bindex = au_ibtop(inode);
20553 + br = au_sbr(sb, bindex);
20554 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20557 + && !special_file(h_inode->i_mode)) {
20558 + /* test whether the upper writable branch exists */
20560 + for (; bindex >= 0; bindex--)
20561 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20569 + /* non-write to dir */
20571 + bbot = au_ibbot(inode);
20572 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20573 + h_inode = au_h_iptr(inode, bindex);
20575 + err = au_busy_or_stale();
20576 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20579 + br = au_sbr(sb, bindex);
20580 + err = h_permission(h_inode, mask, &br->br_path,
20586 + ii_read_unlock(inode);
20587 + si_read_unlock(sb);
20591 +/* ---------------------------------------------------------------------- */
20593 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20594 + unsigned int flags)
20596 + struct dentry *ret, *parent;
20597 + struct inode *inode;
20598 + struct super_block *sb;
20599 + int err, npositive;
20603 + /* todo: support rcu-walk? */
20604 + ret = ERR_PTR(-ECHILD);
20605 + if (flags & LOOKUP_RCU)
20608 + ret = ERR_PTR(-ENAMETOOLONG);
20609 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20613 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20614 + ret = ERR_PTR(err);
20615 + if (unlikely(err))
20618 + err = au_di_init(dentry);
20619 + ret = ERR_PTR(err);
20620 + if (unlikely(err))
20624 + npositive = 0; /* suppress a warning */
20625 + parent = dentry->d_parent; /* dir inode is locked */
20626 + di_read_lock_parent(parent, AuLock_IR);
20627 + err = au_alive_dir(parent);
20629 + err = au_digen_test(parent, au_sigen(sb));
20631 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20632 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20633 + AuLkup_ALLOW_NEG);
20636 + di_read_unlock(parent, AuLock_IR);
20637 + ret = ERR_PTR(err);
20638 + if (unlikely(err < 0))
20642 + inode = au_new_inode(dentry, /*must_new*/0);
20643 + if (IS_ERR(inode)) {
20644 + ret = (void *)inode;
20651 + atomic_inc(&inode->i_count);
20652 + ret = d_splice_alias(inode, dentry);
20653 +#if 0 /* reserved for future use */
20654 + if (unlikely(d_need_lookup(dentry))) {
20655 + spin_lock(&dentry->d_lock);
20656 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20657 + spin_unlock(&dentry->d_lock);
20661 + if (!IS_ERR(ret)) {
20663 + if (ret && ret != dentry)
20664 + ii_write_unlock(inode);
20666 + ii_write_unlock(inode);
20673 + di_write_unlock(dentry);
20675 + si_read_unlock(sb);
20680 +/* ---------------------------------------------------------------------- */
20683 + * very dirty and complicated aufs ->atomic_open().
20684 + * aufs_atomic_open()
20685 + * + au_aopen_or_create()
20687 + * + vfsub_atomic_open()
20688 + * + branch fs ->atomic_open()
20689 + * may call the actual 'open' for h_file
20690 + * + inc br_nfiles only if opened
20691 + * + au_aopen_no_open() or au_aopen_do_open()
20693 + * au_aopen_do_open()
20694 + * + finish_open()
20695 + * + au_do_aopen()
20696 + * + au_do_open() the body of all 'open'
20697 + * + au_do_open_nondir()
20698 + * set the passed h_file
20700 + * au_aopen_no_open()
20701 + * + finish_no_open()
20704 +struct aopen_node {
20705 + struct hlist_bl_node hblist;
20706 + struct file *file, *h_file;
20709 +static int au_do_aopen(struct inode *inode, struct file *file)
20711 + struct hlist_bl_head *aopen;
20712 + struct hlist_bl_node *pos;
20713 + struct aopen_node *node;
20714 + struct au_do_open_args args = {
20716 + .open = au_do_open_nondir
20719 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20720 + hlist_bl_lock(aopen);
20721 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20722 + if (node->file == file) {
20723 + args.h_file = node->h_file;
20726 + hlist_bl_unlock(aopen);
20727 + /* AuDebugOn(!args.h_file); */
20729 + return au_do_open(file, &args);
20732 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20733 + struct aopen_node *aopen_node)
20736 + struct hlist_bl_head *aopen;
20739 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20740 + au_hbl_add(&aopen_node->hblist, aopen);
20741 + err = finish_open(file, dentry, au_do_aopen);
20742 + au_hbl_del(&aopen_node->hblist, aopen);
20743 + /* AuDbgFile(file); */
20744 + AuDbg("%pd%s%s\n", dentry,
20745 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20746 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20752 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20758 + err = finish_no_open(file, dentry);
20764 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20765 + struct file *file, unsigned int open_flag,
20766 + umode_t create_mode)
20768 + int err, did_open;
20769 + unsigned int lkup_flags;
20770 + aufs_bindex_t bindex;
20771 + struct super_block *sb;
20772 + struct dentry *parent, *d;
20773 + struct vfsub_aopen_args args = {
20774 + .open_flag = open_flag,
20775 + .create_mode = create_mode
20777 + struct aopen_node aopen_node = {
20782 + AuDbg("open_flag 0%o\n", open_flag);
20783 + AuDbgDentry(dentry);
20786 + if (!au_di(dentry)) {
20787 + lkup_flags = LOOKUP_OPEN;
20788 + if (open_flag & O_CREAT)
20789 + lkup_flags |= LOOKUP_CREATE;
20790 + d = aufs_lookup(dir, dentry, lkup_flags);
20792 + err = PTR_ERR(d);
20797 + * obsoleted dentry found.
20798 + * another error will be returned later.
20804 + AuDbgDentry(dentry);
20807 + if (d_is_positive(dentry)
20808 + || d_unhashed(dentry)
20809 + || d_unlinked(dentry)
20810 + || !(open_flag & O_CREAT)) {
20811 + err = au_aopen_no_open(file, dentry);
20812 + goto out; /* success */
20815 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20816 + if (unlikely(err))
20819 + sb = dentry->d_sb;
20820 + parent = dentry->d_parent; /* dir is locked */
20821 + di_write_lock_parent(parent);
20822 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
20823 + if (unlikely(err < 0))
20826 + AuDbgDentry(dentry);
20827 + if (d_is_positive(dentry)) {
20828 + err = au_aopen_no_open(file, dentry);
20829 + goto out_parent; /* success */
20832 + args.file = alloc_empty_file(file->f_flags, current_cred());
20833 + err = PTR_ERR(args.file);
20834 + if (IS_ERR(args.file))
20837 + bindex = au_dbtop(dentry);
20838 + err = au_aopen_or_create(dir, dentry, &args);
20840 + AuDbgFile(args.file);
20841 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
20842 + did_open = !!(args.file->f_mode & FMODE_OPENED);
20845 + args.file = NULL;
20847 + di_write_unlock(parent);
20848 + di_write_unlock(dentry);
20849 + if (unlikely(err < 0)) {
20856 + err = au_aopen_no_open(file, dentry);
20858 + aopen_node.h_file = args.file;
20859 + err = au_aopen_do_open(file, dentry, &aopen_node);
20861 + if (unlikely(err < 0)) {
20865 + au_lcnt_dec(&args.br->br_nfiles);
20867 + goto out_sb; /* success */
20870 + di_write_unlock(parent);
20871 + di_write_unlock(dentry);
20873 + si_read_unlock(sb);
20881 +/* ---------------------------------------------------------------------- */
20883 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
20884 + const unsigned char add_entry, aufs_bindex_t bcpup,
20885 + aufs_bindex_t btop)
20888 + struct dentry *h_parent;
20889 + struct inode *h_dir;
20892 + IMustLock(d_inode(parent));
20894 + di_write_lock_parent(parent);
20897 + if (!au_h_dptr(parent, bcpup)) {
20898 + if (btop > bcpup)
20899 + err = au_cpup_dirs(dentry, bcpup);
20900 + else if (btop < bcpup)
20901 + err = au_cpdown_dirs(dentry, bcpup);
20905 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
20906 + h_parent = au_h_dptr(parent, bcpup);
20907 + h_dir = d_inode(h_parent);
20908 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
20909 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
20910 + /* todo: no unlock here */
20911 + inode_unlock_shared(h_dir);
20913 + AuDbg("bcpup %d\n", bcpup);
20915 + if (d_really_is_negative(dentry))
20916 + au_set_h_dptr(dentry, btop, NULL);
20917 + au_update_dbrange(dentry, /*do_put_zero*/0);
20922 + di_write_unlock(parent);
20924 + err = bcpup; /* success */
20931 + * decide the branch and the parent dir where we will create a new entry.
20932 + * returns new bindex or an error.
20933 + * copyup the parent dir if needed.
20935 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
20936 + struct au_wr_dir_args *args)
20939 + unsigned int flags;
20940 + aufs_bindex_t bcpup, btop, src_btop;
20941 + const unsigned char add_entry
20942 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
20943 + | au_ftest_wrdir(args->flags, TMPFILE);
20944 + struct super_block *sb;
20945 + struct dentry *parent;
20946 + struct au_sbinfo *sbinfo;
20948 + sb = dentry->d_sb;
20949 + sbinfo = au_sbi(sb);
20950 + parent = dget_parent(dentry);
20951 + btop = au_dbtop(dentry);
20953 + if (args->force_btgt < 0) {
20954 + if (src_dentry) {
20955 + src_btop = au_dbtop(src_dentry);
20956 + if (src_btop < btop)
20957 + bcpup = src_btop;
20958 + } else if (add_entry) {
20960 + if (au_ftest_wrdir(args->flags, ISDIR))
20961 + au_fset_wbr(flags, DIR);
20962 + err = AuWbrCreate(sbinfo, dentry, flags);
20966 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
20968 + err = AuWbrCopyup(sbinfo, dentry);
20970 + if (!IS_ROOT(dentry)) {
20971 + di_read_lock_parent(parent, !AuLock_IR);
20972 + err = AuWbrCopyup(sbinfo, dentry);
20973 + di_read_unlock(parent, !AuLock_IR);
20975 + err = AuWbrCopyup(sbinfo, dentry);
20978 + if (unlikely(err < 0))
20982 + bcpup = args->force_btgt;
20983 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
20986 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
20988 + if (bcpup == btop)
20989 + goto out; /* success */
20991 + /* copyup the new parent into the branch we process */
20992 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
20994 + if (d_really_is_negative(dentry)) {
20995 + au_set_h_dptr(dentry, btop, NULL);
20996 + au_set_dbtop(dentry, bcpup);
20997 + au_set_dbbot(dentry, bcpup);
20999 + AuDebugOn(add_entry
21000 + && !au_ftest_wrdir(args->flags, TMPFILE)
21001 + && !au_h_dptr(dentry, bcpup));
21009 +/* ---------------------------------------------------------------------- */
21011 +void au_pin_hdir_unlock(struct au_pin *p)
21014 + au_hn_inode_unlock(p->hdir);
21017 +int au_pin_hdir_lock(struct au_pin *p)
21025 + /* even if an error happens later, keep this lock */
21026 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21029 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21034 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21035 + p->h_parent, p->br);
21041 +int au_pin_hdir_relock(struct au_pin *p)
21044 + struct inode *h_i;
21045 + struct dentry *h_d[] = {
21050 + err = au_pin_hdir_lock(p);
21051 + if (unlikely(err))
21054 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21057 + if (d_is_positive(h_d[i])) {
21058 + h_i = d_inode(h_d[i]);
21059 + err = !h_i->i_nlink;
21067 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21069 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
21072 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21075 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21076 + p->lsc_hi, 0, NULL, _RET_IP_);
21077 + au_pin_hdir_set_owner(p, current);
21081 +void au_pin_hdir_release(struct au_pin *p)
21084 + au_pin_hdir_set_owner(p, p->task);
21085 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
21089 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21091 + if (pin && pin->parent)
21092 + return au_h_dptr(pin->parent, pin->bindex);
21096 +void au_unpin(struct au_pin *p)
21099 + au_pin_hdir_unlock(p);
21100 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21101 + vfsub_mnt_drop_write(p->h_mnt);
21105 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21106 + di_read_unlock(p->parent, AuLock_IR);
21107 + iput(p->hdir->hi_inode);
21109 + p->parent = NULL;
21112 + /* do not clear p->task */
21115 +int au_do_pin(struct au_pin *p)
21118 + struct super_block *sb;
21119 + struct inode *h_dir;
21122 + sb = p->dentry->d_sb;
21123 + p->br = au_sbr(sb, p->bindex);
21124 + if (IS_ROOT(p->dentry)) {
21125 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21126 + p->h_mnt = au_br_mnt(p->br);
21127 + err = vfsub_mnt_want_write(p->h_mnt);
21128 + if (unlikely(err)) {
21129 + au_fclr_pin(p->flags, MNT_WRITE);
21136 + p->h_dentry = NULL;
21137 + if (p->bindex <= au_dbbot(p->dentry))
21138 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21140 + p->parent = dget_parent(p->dentry);
21141 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21142 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21145 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21146 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21148 + h_dir = p->hdir->hi_inode;
21152 + * if DI_LOCKED is not set, then p->parent may be different
21153 + * and h_parent can be NULL.
21155 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21157 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21158 + di_read_unlock(p->parent, AuLock_IR);
21160 + p->parent = NULL;
21164 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21165 + p->h_mnt = au_br_mnt(p->br);
21166 + err = vfsub_mnt_want_write(p->h_mnt);
21167 + if (unlikely(err)) {
21168 + au_fclr_pin(p->flags, MNT_WRITE);
21169 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21170 + di_read_unlock(p->parent, AuLock_IR);
21172 + p->parent = NULL;
21178 + err = au_pin_hdir_lock(p);
21180 + goto out; /* success */
21185 + pr_err("err %d\n", err);
21186 + err = au_busy_or_stale();
21191 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21192 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21193 + unsigned int udba, unsigned char flags)
21195 + p->dentry = dentry;
21197 + p->lsc_di = lsc_di;
21198 + p->lsc_hi = lsc_hi;
21199 + p->flags = flags;
21200 + p->bindex = bindex;
21202 + p->parent = NULL;
21206 + p->h_dentry = NULL;
21207 + p->h_parent = NULL;
21209 + p->task = current;
21212 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21213 + unsigned int udba, unsigned char flags)
21215 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21217 + return au_do_pin(pin);
21220 +/* ---------------------------------------------------------------------- */
21223 + * ->setattr() and ->getattr() are called in various cases.
21224 + * chmod, stat: dentry is revalidated.
21225 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21227 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21229 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21230 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21233 + struct dentry *parent;
21236 + if (au_digen_test(dentry, sigen)) {
21237 + parent = dget_parent(dentry);
21238 + di_read_lock_parent(parent, AuLock_IR);
21239 + err = au_refresh_dentry(dentry, parent);
21240 + di_read_unlock(parent, AuLock_IR);
21248 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21249 + struct au_icpup_args *a)
21253 + aufs_bindex_t btop, ibtop;
21254 + struct dentry *hi_wh, *parent;
21255 + struct inode *inode;
21256 + struct au_wr_dir_args wr_dir_args = {
21257 + .force_btgt = -1,
21261 + if (d_is_dir(dentry))
21262 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21263 + /* plink or hi_wh() case */
21264 + btop = au_dbtop(dentry);
21265 + inode = d_inode(dentry);
21266 + ibtop = au_ibtop(inode);
21267 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21268 + wr_dir_args.force_btgt = ibtop;
21269 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21270 + if (unlikely(err < 0))
21274 + au_fset_icpup(a->flags, DID_CPUP);
21277 + a->pin_flags = AuPin_MNT_WRITE;
21279 + if (!IS_ROOT(dentry)) {
21280 + au_fset_pin(a->pin_flags, DI_LOCKED);
21281 + parent = dget_parent(dentry);
21282 + di_write_lock_parent(parent);
21285 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21286 + if (unlikely(err))
21290 + a->h_path.dentry = au_h_dptr(dentry, btop);
21291 + a->h_inode = d_inode(a->h_path.dentry);
21292 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21293 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21294 + if (ia->ia_size < i_size_read(a->h_inode))
21295 + sz = ia->ia_size;
21296 + inode_unlock_shared(a->h_inode);
21300 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21301 + hi_wh = au_hi_wh(inode, a->btgt);
21303 + struct au_cp_generic cpg = {
21304 + .dentry = dentry,
21310 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21311 + if (unlikely(err))
21313 + hi_wh = au_hi_wh(inode, a->btgt);
21314 + /* todo: revalidate hi_wh? */
21319 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21320 + di_downgrade_lock(parent, AuLock_IR);
21324 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21325 + goto out; /* success */
21327 + if (!d_unhashed(dentry)) {
21328 + struct au_cp_generic cpg = {
21329 + .dentry = dentry,
21334 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21336 + err = au_sio_cpup_simple(&cpg);
21338 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21339 + } else if (!hi_wh)
21340 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21342 + a->h_path.dentry = hi_wh; /* do not dget here */
21345 + a->h_inode = d_inode(a->h_path.dentry);
21347 + goto out; /* success */
21348 + au_unpin(&a->pin);
21351 + di_write_unlock(parent);
21356 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21360 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21363 + struct inode *inode, *delegated;
21364 + struct super_block *sb;
21365 + struct file *file;
21366 + struct au_icpup_args *a;
21368 + inode = d_inode(dentry);
21369 + IMustLock(inode);
21371 + err = setattr_prepare(dentry, ia);
21372 + if (unlikely(err))
21376 + a = kzalloc(sizeof(*a), GFP_NOFS);
21377 + if (unlikely(!a))
21380 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21381 + ia->ia_valid &= ~ATTR_MODE;
21384 + sb = dentry->d_sb;
21385 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21386 + if (unlikely(err))
21389 + if (ia->ia_valid & ATTR_FILE) {
21390 + /* currently ftruncate(2) only */
21391 + AuDebugOn(!d_is_reg(dentry));
21392 + file = ia->ia_file;
21393 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21395 + if (unlikely(err))
21397 + ia->ia_file = au_hf_top(file);
21398 + a->udba = AuOpt_UDBA_NONE;
21400 + /* fchmod() doesn't pass ia_file */
21401 + a->udba = au_opt_udba(sb);
21402 + di_write_lock_child(dentry);
21403 + /* no d_unlinked(), to set UDBA_NONE for root */
21404 + if (d_unhashed(dentry))
21405 + a->udba = AuOpt_UDBA_NONE;
21406 + if (a->udba != AuOpt_UDBA_NONE) {
21407 + AuDebugOn(IS_ROOT(dentry));
21408 + err = au_reval_for_attr(dentry, au_sigen(sb));
21409 + if (unlikely(err))
21414 + err = au_pin_and_icpup(dentry, ia, a);
21415 + if (unlikely(err < 0))
21417 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21418 + ia->ia_file = NULL;
21419 + ia->ia_valid &= ~ATTR_FILE;
21422 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21423 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21424 + == (ATTR_MODE | ATTR_CTIME)) {
21425 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21426 + if (unlikely(err))
21428 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21429 + && (ia->ia_valid & ATTR_CTIME)) {
21430 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21431 + if (unlikely(err))
21435 + if (ia->ia_valid & ATTR_SIZE) {
21438 + if (ia->ia_size < i_size_read(inode))
21440 + truncate_setsize(inode, ia->ia_size);
21443 + if (ia->ia_valid & ATTR_FILE)
21445 + inode_unlock(a->h_inode);
21446 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21447 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21449 + delegated = NULL;
21451 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21453 + err = break_deleg_wait(&delegated);
21461 + * regardless aufs 'acl' option setting.
21462 + * why don't all acl-aware fs call this func from their ->setattr()?
21464 + if (!err && (ia->ia_valid & ATTR_MODE))
21465 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21467 + au_cpup_attr_changeable(inode);
21470 + inode_unlock(a->h_inode);
21471 + au_unpin(&a->pin);
21472 + if (unlikely(err))
21473 + au_update_dbtop(dentry);
21475 + di_write_unlock(dentry);
21477 + fi_write_unlock(file);
21478 + ia->ia_file = file;
21479 + ia->ia_valid |= ATTR_FILE;
21482 + si_read_unlock(sb);
21490 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21491 +static int au_h_path_to_set_attr(struct dentry *dentry,
21492 + struct au_icpup_args *a, struct path *h_path)
21495 + struct super_block *sb;
21497 + sb = dentry->d_sb;
21498 + a->udba = au_opt_udba(sb);
21499 + /* no d_unlinked(), to set UDBA_NONE for root */
21500 + if (d_unhashed(dentry))
21501 + a->udba = AuOpt_UDBA_NONE;
21502 + if (a->udba != AuOpt_UDBA_NONE) {
21503 + AuDebugOn(IS_ROOT(dentry));
21504 + err = au_reval_for_attr(dentry, au_sigen(sb));
21505 + if (unlikely(err))
21508 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21509 + if (unlikely(err < 0))
21512 + h_path->dentry = a->h_path.dentry;
21513 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21519 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21520 + struct au_sxattr *arg)
21523 + struct path h_path;
21524 + struct super_block *sb;
21525 + struct au_icpup_args *a;
21526 + struct inode *h_inode;
21528 + IMustLock(inode);
21531 + a = kzalloc(sizeof(*a), GFP_NOFS);
21532 + if (unlikely(!a))
21535 + sb = dentry->d_sb;
21536 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21537 + if (unlikely(err))
21540 + h_path.dentry = NULL; /* silence gcc */
21541 + di_write_lock_child(dentry);
21542 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21543 + if (unlikely(err))
21546 + inode_unlock(a->h_inode);
21547 + switch (arg->type) {
21548 + case AU_XATTR_SET:
21549 + AuDebugOn(d_is_negative(h_path.dentry));
21550 + err = vfsub_setxattr(h_path.dentry,
21551 + arg->u.set.name, arg->u.set.value,
21552 + arg->u.set.size, arg->u.set.flags);
21555 + err = -EOPNOTSUPP;
21556 + h_inode = d_inode(h_path.dentry);
21557 + if (h_inode->i_op->set_acl)
21558 + /* this will call posix_acl_update_mode */
21559 + err = h_inode->i_op->set_acl(h_inode,
21560 + arg->u.acl_set.acl,
21561 + arg->u.acl_set.type);
21565 + au_cpup_attr_timesizes(inode);
21567 + au_unpin(&a->pin);
21568 + if (unlikely(err))
21569 + au_update_dbtop(dentry);
21572 + di_write_unlock(dentry);
21573 + si_read_unlock(sb);
21582 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21583 + unsigned int nlink)
21587 + inode->i_mode = st->mode;
21588 + /* don't i_[ug]id_write() here */
21589 + inode->i_uid = st->uid;
21590 + inode->i_gid = st->gid;
21591 + inode->i_atime = st->atime;
21592 + inode->i_mtime = st->mtime;
21593 + inode->i_ctime = st->ctime;
21595 + au_cpup_attr_nlink(inode, /*force*/0);
21596 + if (S_ISDIR(inode->i_mode)) {
21597 + n = inode->i_nlink;
21600 + smp_mb(); /* for i_nlink */
21601 + /* 0 can happen */
21602 + set_nlink(inode, n);
21605 + spin_lock(&inode->i_lock);
21606 + inode->i_blocks = st->blocks;
21607 + i_size_write(inode, st->size);
21608 + spin_unlock(&inode->i_lock);
21612 + * common routine for aufs_getattr() and au_getxattr().
21613 + * returns zero or negative (an error).
21614 + * @dentry will be read-locked in success.
21616 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
21617 + struct path *h_path, int locked)
21620 + unsigned int mnt_flags, sigen;
21621 + unsigned char udba_none;
21622 + aufs_bindex_t bindex;
21623 + struct super_block *sb, *h_sb;
21625 + h_path->mnt = NULL;
21626 + h_path->dentry = NULL;
21629 + sb = dentry->d_sb;
21630 + mnt_flags = au_mntflags(sb);
21631 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21633 + if (unlikely(locked))
21634 + goto body; /* skip locking dinfo */
21636 + /* support fstat(2) */
21637 + if (!d_unlinked(dentry) && !udba_none) {
21638 + sigen = au_sigen(sb);
21639 + err = au_digen_test(dentry, sigen);
21641 + di_read_lock_child(dentry, AuLock_IR);
21642 + err = au_dbrange_test(dentry);
21643 + if (unlikely(err)) {
21644 + di_read_unlock(dentry, AuLock_IR);
21648 + AuDebugOn(IS_ROOT(dentry));
21649 + di_write_lock_child(dentry);
21650 + err = au_dbrange_test(dentry);
21652 + err = au_reval_for_attr(dentry, sigen);
21654 + di_downgrade_lock(dentry, AuLock_IR);
21656 + di_write_unlock(dentry);
21661 + di_read_lock_child(dentry, AuLock_IR);
21665 + inode = d_inode(dentry);
21666 + if (unlikely(!inode))
21669 + bindex = au_ibtop(inode);
21670 + h_path->mnt = au_sbr_mnt(sb, bindex);
21671 + h_sb = h_path->mnt->mnt_sb;
21673 + && !au_test_fs_bad_iattr(h_sb)
21675 + goto out; /* success */
21677 + if (au_dbtop(dentry) == bindex)
21678 + h_path->dentry = au_h_dptr(dentry, bindex);
21679 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21680 + h_path->dentry = au_plink_lkup(inode, bindex);
21681 + if (IS_ERR(h_path->dentry))
21682 + /* pretending success */
21683 + h_path->dentry = NULL;
21685 + dput(h_path->dentry);
21692 +static int aufs_getattr(const struct path *path, struct kstat *st,
21693 + u32 request, unsigned int query)
21696 + unsigned char positive;
21697 + struct path h_path;
21698 + struct dentry *dentry;
21699 + struct inode *inode;
21700 + struct super_block *sb;
21702 + dentry = path->dentry;
21703 + inode = d_inode(dentry);
21704 + sb = dentry->d_sb;
21705 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21706 + if (unlikely(err))
21708 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
21710 + if (unlikely(err))
21712 + if (unlikely(!h_path.dentry))
21713 + /* illegally overlapped or something */
21714 + goto out_fill; /* pretending success */
21716 + positive = d_is_positive(h_path.dentry);
21718 + /* no vfsub version */
21719 + err = vfs_getattr(&h_path, st, request, query);
21722 + au_refresh_iattr(inode, st,
21723 + d_inode(h_path.dentry)->i_nlink);
21724 + goto out_fill; /* success */
21730 + generic_fillattr(inode, st);
21732 + di_read_unlock(dentry, AuLock_IR);
21734 + si_read_unlock(sb);
21740 +/* ---------------------------------------------------------------------- */
21742 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21743 + struct delayed_call *done)
21746 + struct dentry *h_dentry;
21747 + struct inode *h_inode;
21749 + aufs_bindex_t bindex;
21751 + ret = NULL; /* suppress a warning */
21756 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21757 + if (unlikely(err))
21760 + err = au_d_hashed_positive(dentry);
21761 + if (unlikely(err))
21765 + inode = d_inode(dentry);
21766 + bindex = au_ibtop(inode);
21767 + h_inode = au_h_iptr(inode, bindex);
21768 + if (unlikely(!h_inode->i_op->get_link))
21773 + if (au_dbtop(dentry) <= bindex) {
21774 + h_dentry = au_h_dptr(dentry, bindex);
21779 + h_dentry = d_find_any_alias(h_inode);
21780 + if (IS_ERR(h_dentry)) {
21781 + err = PTR_ERR(h_dentry);
21785 + if (unlikely(!h_dentry))
21789 + AuDbg("%ps\n", h_inode->i_op->get_link);
21790 + AuDbgDentry(h_dentry);
21791 + ret = vfs_get_link(h_dentry, done);
21794 + err = PTR_ERR(ret);
21797 + aufs_read_unlock(dentry, AuLock_IR);
21799 + if (unlikely(err))
21800 + ret = ERR_PTR(err);
21801 + AuTraceErrPtr(ret);
21805 +/* ---------------------------------------------------------------------- */
21807 +static int au_is_special(struct inode *inode)
21809 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
21812 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
21816 + aufs_bindex_t bindex;
21817 + struct super_block *sb;
21818 + struct inode *h_inode;
21819 + struct vfsmount *h_mnt;
21821 + sb = inode->i_sb;
21822 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
21823 + "unexpected s_flags 0x%lx", sb->s_flags);
21825 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
21827 + si_read_lock(sb, AuLock_FLUSH);
21828 + ii_write_lock_child(inode);
21831 + bindex = au_ibtop(inode);
21832 + h_inode = au_h_iptr(inode, bindex);
21833 + if (!au_test_ro(sb, bindex, inode)) {
21834 + h_mnt = au_sbr_mnt(sb, bindex);
21835 + err = vfsub_mnt_want_write(h_mnt);
21837 + err = vfsub_update_time(h_inode, ts, flags);
21838 + vfsub_mnt_drop_write(h_mnt);
21840 + } else if (au_is_special(h_inode)) {
21842 + * Never copy-up here.
21843 + * These special files may already be opened and used for
21844 + * communicating. If we copied it up, then the communication
21845 + * would be corrupted.
21847 + AuWarn1("timestamps for i%lu are ignored "
21848 + "since it is on readonly branch (hi%lu).\n",
21849 + inode->i_ino, h_inode->i_ino);
21850 + } else if (flags & ~S_ATIME) {
21852 + AuIOErr1("unexpected flags 0x%x\n", flags);
21857 + au_cpup_attr_timesizes(inode);
21858 + ii_write_unlock(inode);
21859 + si_read_unlock(sb);
21862 + if (!err && (flags & S_VERSION))
21863 + inode_inc_iversion(inode);
21868 +/* ---------------------------------------------------------------------- */
21870 +/* no getattr version will be set by module.c:aufs_init() */
21871 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
21873 + [AuIop_SYMLINK] = {
21874 + .permission = aufs_permission,
21875 +#ifdef CONFIG_FS_POSIX_ACL
21876 + .get_acl = aufs_get_acl,
21877 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
21880 + .setattr = aufs_setattr,
21881 + .getattr = aufs_getattr,
21883 +#ifdef CONFIG_AUFS_XATTR
21884 + .listxattr = aufs_listxattr,
21887 + .get_link = aufs_get_link,
21889 + /* .update_time = aufs_update_time */
21892 + .create = aufs_create,
21893 + .lookup = aufs_lookup,
21894 + .link = aufs_link,
21895 + .unlink = aufs_unlink,
21896 + .symlink = aufs_symlink,
21897 + .mkdir = aufs_mkdir,
21898 + .rmdir = aufs_rmdir,
21899 + .mknod = aufs_mknod,
21900 + .rename = aufs_rename,
21902 + .permission = aufs_permission,
21903 +#ifdef CONFIG_FS_POSIX_ACL
21904 + .get_acl = aufs_get_acl,
21905 + .set_acl = aufs_set_acl,
21908 + .setattr = aufs_setattr,
21909 + .getattr = aufs_getattr,
21911 +#ifdef CONFIG_AUFS_XATTR
21912 + .listxattr = aufs_listxattr,
21915 + .update_time = aufs_update_time,
21916 + .atomic_open = aufs_atomic_open,
21917 + .tmpfile = aufs_tmpfile
21919 + [AuIop_OTHER] = {
21920 + .permission = aufs_permission,
21921 +#ifdef CONFIG_FS_POSIX_ACL
21922 + .get_acl = aufs_get_acl,
21923 + .set_acl = aufs_set_acl,
21926 + .setattr = aufs_setattr,
21927 + .getattr = aufs_getattr,
21929 +#ifdef CONFIG_AUFS_XATTR
21930 + .listxattr = aufs_listxattr,
21933 + .update_time = aufs_update_time
21936 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
21937 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
21938 +++ linux/fs/aufs/i_op_del.c 2020-01-27 10:57:18.172204883 +0100
21940 +// SPDX-License-Identifier: GPL-2.0
21942 + * Copyright (C) 2005-2020 Junjiro R. Okajima
21944 + * This program, aufs is free software; you can redistribute it and/or modify
21945 + * it under the terms of the GNU General Public License as published by
21946 + * the Free Software Foundation; either version 2 of the License, or
21947 + * (at your option) any later version.
21949 + * This program is distributed in the hope that it will be useful,
21950 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21951 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21952 + * GNU General Public License for more details.
21954 + * You should have received a copy of the GNU General Public License
21955 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21959 + * inode operations (del entry)
21962 +#include <linux/iversion.h>
21966 + * decide if a new whiteout for @dentry is necessary or not.
21967 + * when it is necessary, prepare the parent dir for the upper branch whose
21968 + * branch index is @bcpup for creation. the actual creation of the whiteout will
21969 + * be done by caller.
21971 + * 0: wh is unnecessary
21972 + * plus: wh is necessary
21975 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
21977 + int need_wh, err;
21978 + aufs_bindex_t btop;
21979 + struct super_block *sb;
21981 + sb = dentry->d_sb;
21982 + btop = au_dbtop(dentry);
21983 + if (*bcpup < 0) {
21985 + if (au_test_ro(sb, btop, d_inode(dentry))) {
21986 + err = AuWbrCopyup(au_sbi(sb), dentry);
21988 + if (unlikely(err < 0))
21992 + AuDebugOn(btop < *bcpup
21993 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
21994 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
21996 + if (*bcpup != btop) {
21997 + err = au_cpup_dirs(dentry, *bcpup);
21998 + if (unlikely(err))
22002 + struct au_dinfo *dinfo, *tmp;
22004 + need_wh = -ENOMEM;
22005 + dinfo = au_di(dentry);
22006 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22008 + au_di_cp(tmp, dinfo);
22009 + au_di_swap(tmp, dinfo);
22010 + /* returns the number of positive dentries */
22011 + need_wh = au_lkup_dentry(dentry, btop + 1,
22012 + /* AuLkup_IGNORE_PERM */ 0);
22013 + au_di_swap(tmp, dinfo);
22014 + au_rw_write_unlock(&tmp->di_rwsem);
22018 + AuDbg("need_wh %d\n", need_wh);
22026 + * simple tests for the del-entry operations.
22027 + * following the checks in vfs, plus the parent-child relationship.
22029 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22030 + struct dentry *h_parent, int isdir)
22034 + struct dentry *h_dentry, *h_latest;
22035 + struct inode *h_inode;
22037 + h_dentry = au_h_dptr(dentry, bindex);
22038 + if (d_really_is_positive(dentry)) {
22040 + if (unlikely(d_is_negative(h_dentry)))
22042 + h_inode = d_inode(h_dentry);
22043 + if (unlikely(!h_inode->i_nlink))
22046 + h_mode = h_inode->i_mode;
22049 + if (unlikely(S_ISDIR(h_mode)))
22051 + } else if (unlikely(!S_ISDIR(h_mode))) {
22056 + /* rename(2) case */
22058 + if (unlikely(d_is_positive(h_dentry)))
22063 + /* expected parent dir is locked */
22064 + if (unlikely(h_parent != h_dentry->d_parent))
22069 + * rmdir a dir may break the consistency on some filesystem.
22070 + * let's try heavy test.
22073 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22074 + && au_test_h_perm(d_inode(h_parent),
22075 + MAY_EXEC | MAY_WRITE)))
22078 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
22080 + if (IS_ERR(h_latest))
22082 + if (h_latest == h_dentry)
22091 + * decide the branch where we operate for @dentry. the branch index will be set
22092 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22093 + * dir for reverting.
22094 + * when a new whiteout is necessary, create it.
22096 +static struct dentry*
22097 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22098 + struct au_dtime *dt, struct au_pin *pin)
22100 + struct dentry *wh_dentry;
22101 + struct super_block *sb;
22102 + struct path h_path;
22103 + int err, need_wh;
22104 + unsigned int udba;
22105 + aufs_bindex_t bcpup;
22107 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22108 + wh_dentry = ERR_PTR(need_wh);
22109 + if (unlikely(need_wh < 0))
22112 + sb = dentry->d_sb;
22113 + udba = au_opt_udba(sb);
22115 + err = au_pin(pin, dentry, bcpup, udba,
22116 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22117 + wh_dentry = ERR_PTR(err);
22118 + if (unlikely(err))
22121 + h_path.dentry = au_pinned_h_parent(pin);
22122 + if (udba != AuOpt_UDBA_NONE
22123 + && au_dbtop(dentry) == bcpup) {
22124 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22125 + wh_dentry = ERR_PTR(err);
22126 + if (unlikely(err))
22130 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22131 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22132 + wh_dentry = NULL;
22134 + goto out; /* success, no need to create whiteout */
22136 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22137 + if (IS_ERR(wh_dentry))
22140 + /* returns with the parent is locked and wh_dentry is dget-ed */
22141 + goto out; /* success */
22146 + return wh_dentry;
22150 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22151 + * in order to be revertible and save time for removing many child whiteouts
22153 + * returns 1 when there are too many child whiteout and caller should remove
22154 + * them asynchronously. returns 0 when the number of children is enough small to
22155 + * remove now or the branch fs is a remote fs.
22156 + * otherwise return an error.
22158 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22159 + struct au_nhash *whlist, struct inode *dir)
22161 + int rmdir_later, err, dirwh;
22162 + struct dentry *h_dentry;
22163 + struct super_block *sb;
22164 + struct inode *inode;
22166 + sb = dentry->d_sb;
22167 + SiMustAnyLock(sb);
22168 + h_dentry = au_h_dptr(dentry, bindex);
22169 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22170 + if (unlikely(err))
22173 + /* stop monitoring */
22174 + inode = d_inode(dentry);
22175 + au_hn_free(au_hi(inode, bindex));
22177 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22178 + dirwh = au_sbi(sb)->si_dirwh;
22179 + rmdir_later = (dirwh <= 1);
22180 + if (!rmdir_later)
22181 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22184 + return rmdir_later;
22187 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22188 + if (unlikely(err)) {
22189 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22190 + h_dentry, bindex, err);
22200 + * final procedure for deleting a entry.
22201 + * maintain dentry and iattr.
22203 +static void epilog(struct inode *dir, struct dentry *dentry,
22204 + aufs_bindex_t bindex)
22206 + struct inode *inode;
22208 + inode = d_inode(dentry);
22210 + inode->i_ctime = dir->i_ctime;
22212 + au_dir_ts(dir, bindex);
22213 + inode_inc_iversion(dir);
22217 + * when an error happened, remove the created whiteout and revert everything.
22219 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22220 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22221 + struct dentry *dentry, struct au_dtime *dt)
22224 + struct path h_path = {
22225 + .dentry = wh_dentry,
22226 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22229 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22231 + au_set_dbwh(dentry, bwh);
22232 + au_dtime_revert(dt);
22236 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22240 +/* ---------------------------------------------------------------------- */
22242 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22245 + aufs_bindex_t bwh, bindex, btop;
22246 + struct inode *inode, *h_dir, *delegated;
22247 + struct dentry *parent, *wh_dentry;
22248 + /* to reduce stack size */
22250 + struct au_dtime dt;
22251 + struct au_pin pin;
22252 + struct path h_path;
22258 + a = kmalloc(sizeof(*a), GFP_NOFS);
22259 + if (unlikely(!a))
22262 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22263 + if (unlikely(err))
22265 + err = au_d_hashed_positive(dentry);
22266 + if (unlikely(err))
22268 + inode = d_inode(dentry);
22269 + IMustLock(inode);
22271 + if (unlikely(d_is_dir(dentry)))
22272 + goto out_unlock; /* possible? */
22274 + btop = au_dbtop(dentry);
22275 + bwh = au_dbwh(dentry);
22277 + parent = dentry->d_parent; /* dir inode is locked */
22278 + di_write_lock_parent(parent);
22279 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22281 + err = PTR_ERR(wh_dentry);
22282 + if (IS_ERR(wh_dentry))
22285 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22286 + a->h_path.dentry = au_h_dptr(dentry, btop);
22287 + dget(a->h_path.dentry);
22288 + if (bindex == btop) {
22289 + h_dir = au_pinned_h_dir(&a->pin);
22290 + delegated = NULL;
22291 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22292 + if (unlikely(err == -EWOULDBLOCK)) {
22293 + pr_warn("cannot retry for NFSv4 delegation"
22294 + " for an internal unlink\n");
22298 + /* dir inode is locked */
22299 + h_dir = d_inode(wh_dentry->d_parent);
22300 + IMustLock(h_dir);
22305 + vfsub_drop_nlink(inode);
22306 + epilog(dir, dentry, bindex);
22308 + /* update target timestamps */
22309 + if (bindex == btop) {
22310 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22312 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22314 + /* todo: this timestamp may be reverted later */
22315 + inode->i_ctime = h_dir->i_ctime;
22316 + goto out_unpin; /* success */
22323 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22330 + au_unpin(&a->pin);
22332 + dput(a->h_path.dentry);
22334 + di_write_unlock(parent);
22336 + aufs_read_unlock(dentry, AuLock_DW);
22343 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22345 + int err, rmdir_later;
22346 + aufs_bindex_t bwh, bindex, btop;
22347 + struct inode *inode;
22348 + struct dentry *parent, *wh_dentry, *h_dentry;
22349 + struct au_whtmp_rmdir *args;
22350 + /* to reduce stack size */
22352 + struct au_dtime dt;
22353 + struct au_pin pin;
22359 + a = kmalloc(sizeof(*a), GFP_NOFS);
22360 + if (unlikely(!a))
22363 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22364 + if (unlikely(err))
22366 + err = au_alive_dir(dentry);
22367 + if (unlikely(err))
22369 + inode = d_inode(dentry);
22370 + IMustLock(inode);
22372 + if (unlikely(!d_is_dir(dentry)))
22373 + goto out_unlock; /* possible? */
22376 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22377 + if (unlikely(!args))
22380 + parent = dentry->d_parent; /* dir inode is locked */
22381 + di_write_lock_parent(parent);
22382 + err = au_test_empty(dentry, &args->whlist);
22383 + if (unlikely(err))
22386 + btop = au_dbtop(dentry);
22387 + bwh = au_dbwh(dentry);
22389 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22391 + err = PTR_ERR(wh_dentry);
22392 + if (IS_ERR(wh_dentry))
22395 + h_dentry = au_h_dptr(dentry, btop);
22398 + if (bindex == btop) {
22399 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22401 + rmdir_later = err;
22405 + /* stop monitoring */
22406 + au_hn_free(au_hi(inode, btop));
22408 + /* dir inode is locked */
22409 + IMustLock(d_inode(wh_dentry->d_parent));
22414 + vfsub_dead_dir(inode);
22415 + au_set_dbdiropq(dentry, -1);
22416 + epilog(dir, dentry, bindex);
22418 + if (rmdir_later) {
22419 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22423 + goto out_unpin; /* success */
22431 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22438 + au_unpin(&a->pin);
22442 + di_write_unlock(parent);
22444 + au_whtmp_rmdir_free(args);
22446 + aufs_read_unlock(dentry, AuLock_DW);
22453 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22454 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22455 +++ linux/fs/aufs/i_op_ren.c 2020-01-27 10:57:18.172204883 +0100
22457 +// SPDX-License-Identifier: GPL-2.0
22459 + * Copyright (C) 2005-2020 Junjiro R. Okajima
22461 + * This program, aufs is free software; you can redistribute it and/or modify
22462 + * it under the terms of the GNU General Public License as published by
22463 + * the Free Software Foundation; either version 2 of the License, or
22464 + * (at your option) any later version.
22466 + * This program is distributed in the hope that it will be useful,
22467 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22468 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22469 + * GNU General Public License for more details.
22471 + * You should have received a copy of the GNU General Public License
22472 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22476 + * inode operation (rename entry)
22477 + * todo: this is crazy monster
22480 +#include <linux/iversion.h>
22483 +enum { AuSRC, AuDST, AuSrcDst };
22484 +enum { AuPARENT, AuCHILD, AuParentChild };
22486 +#define AuRen_ISDIR_SRC 1
22487 +#define AuRen_ISDIR_DST (1 << 1)
22488 +#define AuRen_ISSAMEDIR (1 << 2)
22489 +#define AuRen_WHSRC (1 << 3)
22490 +#define AuRen_WHDST (1 << 4)
22491 +#define AuRen_MNT_WRITE (1 << 5)
22492 +#define AuRen_DT_DSTDIR (1 << 6)
22493 +#define AuRen_DIROPQ_SRC (1 << 7)
22494 +#define AuRen_DIROPQ_DST (1 << 8)
22495 +#define AuRen_DIRREN (1 << 9)
22496 +#define AuRen_DROPPED_SRC (1 << 10)
22497 +#define AuRen_DROPPED_DST (1 << 11)
22498 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22499 +#define au_fset_ren(flags, name) \
22500 + do { (flags) |= AuRen_##name; } while (0)
22501 +#define au_fclr_ren(flags, name) \
22502 + do { (flags) &= ~AuRen_##name; } while (0)
22504 +#ifndef CONFIG_AUFS_DIRREN
22505 +#undef AuRen_DIRREN
22506 +#define AuRen_DIRREN 0
22509 +struct au_ren_args {
22511 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22513 + struct inode *dir, *inode;
22514 + struct au_hinode *hdir, *hinode;
22515 + struct au_dtime dt[AuParentChild];
22516 + aufs_bindex_t btop, bdiropq;
22519 +#define src_dentry sd[AuSRC].dentry
22520 +#define src_dir sd[AuSRC].dir
22521 +#define src_inode sd[AuSRC].inode
22522 +#define src_h_dentry sd[AuSRC].h_dentry
22523 +#define src_parent sd[AuSRC].parent
22524 +#define src_h_parent sd[AuSRC].h_parent
22525 +#define src_wh_dentry sd[AuSRC].wh_dentry
22526 +#define src_hdir sd[AuSRC].hdir
22527 +#define src_hinode sd[AuSRC].hinode
22528 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22529 +#define src_dt sd[AuSRC].dt
22530 +#define src_btop sd[AuSRC].btop
22531 +#define src_bdiropq sd[AuSRC].bdiropq
22533 +#define dst_dentry sd[AuDST].dentry
22534 +#define dst_dir sd[AuDST].dir
22535 +#define dst_inode sd[AuDST].inode
22536 +#define dst_h_dentry sd[AuDST].h_dentry
22537 +#define dst_parent sd[AuDST].parent
22538 +#define dst_h_parent sd[AuDST].h_parent
22539 +#define dst_wh_dentry sd[AuDST].wh_dentry
22540 +#define dst_hdir sd[AuDST].hdir
22541 +#define dst_hinode sd[AuDST].hinode
22542 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22543 +#define dst_dt sd[AuDST].dt
22544 +#define dst_btop sd[AuDST].btop
22545 +#define dst_bdiropq sd[AuDST].bdiropq
22547 + struct dentry *h_trap;
22548 + struct au_branch *br;
22549 + struct path h_path;
22550 + struct au_nhash whlist;
22551 + aufs_bindex_t btgt, src_bwh;
22554 + unsigned short auren_flags;
22555 + unsigned char flags; /* syscall parameter */
22556 + unsigned char exchange;
22559 + struct au_whtmp_rmdir *thargs;
22560 + struct dentry *h_dst;
22561 + struct au_hinode *h_root;
22564 +/* ---------------------------------------------------------------------- */
22567 + * functions for reverting.
22568 + * when an error happened in a single rename systemcall, we should revert
22569 + * everything as if nothing happened.
22570 + * we don't need to revert the copied-up/down the parent dir since they are
22574 +#define RevertFailure(fmt, ...) do { \
22575 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22576 + ##__VA_ARGS__, err, rerr); \
22580 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22583 + struct dentry *d;
22584 +#define src_or_dst(member) a->sd[idx].member
22586 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22587 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22588 + rerr = au_diropq_remove(d, a->btgt);
22589 + au_hn_inode_unlock(src_or_dst(hinode));
22590 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22592 + RevertFailure("remove diropq %pd", d);
22594 +#undef src_or_dst_
22597 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22599 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22600 + au_ren_do_rev_diropq(err, a, AuSRC);
22601 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22602 + au_ren_do_rev_diropq(err, a, AuDST);
22605 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22608 + struct inode *delegated;
22610 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22611 + a->src_h_parent);
22612 + rerr = PTR_ERR(a->h_path.dentry);
22613 + if (IS_ERR(a->h_path.dentry)) {
22614 + RevertFailure("lkup one %pd", a->src_dentry);
22618 + delegated = NULL;
22619 + rerr = vfsub_rename(a->dst_h_dir,
22620 + au_h_dptr(a->src_dentry, a->btgt),
22621 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22622 + if (unlikely(rerr == -EWOULDBLOCK)) {
22623 + pr_warn("cannot retry for NFSv4 delegation"
22624 + " for an internal rename\n");
22627 + d_drop(a->h_path.dentry);
22628 + dput(a->h_path.dentry);
22629 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22631 + RevertFailure("rename %pd", a->src_dentry);
22634 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22637 + struct inode *delegated;
22639 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22640 + a->dst_h_parent);
22641 + rerr = PTR_ERR(a->h_path.dentry);
22642 + if (IS_ERR(a->h_path.dentry)) {
22643 + RevertFailure("lkup one %pd", a->dst_dentry);
22646 + if (d_is_positive(a->h_path.dentry)) {
22647 + d_drop(a->h_path.dentry);
22648 + dput(a->h_path.dentry);
22652 + delegated = NULL;
22653 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22654 + &delegated, a->flags);
22655 + if (unlikely(rerr == -EWOULDBLOCK)) {
22656 + pr_warn("cannot retry for NFSv4 delegation"
22657 + " for an internal rename\n");
22660 + d_drop(a->h_path.dentry);
22661 + dput(a->h_path.dentry);
22663 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22665 + RevertFailure("rename %pd", a->h_dst);
22668 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22672 + a->h_path.dentry = a->src_wh_dentry;
22673 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22674 + au_set_dbwh(a->src_dentry, a->src_bwh);
22676 + RevertFailure("unlink %pd", a->src_wh_dentry);
22678 +#undef RevertFailure
22680 +/* ---------------------------------------------------------------------- */
22683 + * when we have to copyup the renaming entry, do it with the rename-target name
22684 + * in order to minimize the cost (the later actual rename is unnecessary).
22685 + * otherwise rename it on the target branch.
22687 +static int au_ren_or_cpup(struct au_ren_args *a)
22690 + struct dentry *d;
22691 + struct inode *delegated;
22693 + d = a->src_dentry;
22694 + if (au_dbtop(d) == a->btgt) {
22695 + a->h_path.dentry = a->dst_h_dentry;
22696 + AuDebugOn(au_dbtop(d) != a->btgt);
22697 + delegated = NULL;
22698 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22699 + a->dst_h_dir, &a->h_path, &delegated,
22701 + if (unlikely(err == -EWOULDBLOCK)) {
22702 + pr_warn("cannot retry for NFSv4 delegation"
22703 + " for an internal rename\n");
22709 + if (!err && a->h_dst)
22710 + /* it will be set to dinfo later */
22716 +/* cf. aufs_rmdir() */
22717 +static int au_ren_del_whtmp(struct au_ren_args *a)
22720 + struct inode *dir;
22722 + dir = a->dst_dir;
22723 + SiMustAnyLock(dir->i_sb);
22724 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22725 + au_sbi(dir->i_sb)->si_dirwh)
22726 + || au_test_fs_remote(a->h_dst->d_sb)) {
22727 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22728 + if (unlikely(err))
22729 + pr_warn("failed removing whtmp dir %pd (%d), "
22730 + "ignored.\n", a->h_dst, err);
22732 + au_nhash_wh_free(&a->thargs->whlist);
22733 + a->thargs->whlist = a->whlist;
22734 + a->whlist.nh_num = 0;
22735 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22737 + a->thargs = NULL;
22743 +/* make it 'opaque' dir. */
22744 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22747 + struct dentry *d, *diropq;
22748 +#define src_or_dst(member) a->sd[idx].member
22751 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22752 + src_or_dst(bdiropq) = au_dbdiropq(d);
22753 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22754 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22755 + diropq = au_diropq_create(d, a->btgt);
22756 + au_hn_inode_unlock(src_or_dst(hinode));
22757 + if (IS_ERR(diropq))
22758 + err = PTR_ERR(diropq);
22762 +#undef src_or_dst_
22766 +static int au_ren_diropq(struct au_ren_args *a)
22769 + unsigned char always;
22770 + struct dentry *d;
22773 + d = a->dst_dentry; /* already renamed on the branch */
22774 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22775 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22776 + && !au_ftest_ren(a->auren_flags, DIRREN)
22777 + && a->btgt != au_dbdiropq(a->src_dentry)
22778 + && (a->dst_wh_dentry
22779 + || a->btgt <= au_dbdiropq(d)
22780 + /* hide the lower to keep xino */
22781 + /* the lowers may not be a dir, but we hide them anyway */
22782 + || a->btgt < au_dbbot(d)
22785 + err = au_ren_do_diropq(a, AuSRC);
22786 + if (unlikely(err))
22788 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22790 + if (!a->exchange)
22791 + goto out; /* success */
22793 + d = a->src_dentry; /* already renamed on the branch */
22794 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22795 + && a->btgt != au_dbdiropq(a->dst_dentry)
22796 + && (a->btgt < au_dbdiropq(d)
22797 + || a->btgt < au_dbbot(d)
22799 + AuDbgDentry(a->src_dentry);
22800 + AuDbgDentry(a->dst_dentry);
22801 + err = au_ren_do_diropq(a, AuDST);
22802 + if (unlikely(err))
22803 + goto out_rev_src;
22804 + au_fset_ren(a->auren_flags, DIROPQ_DST);
22806 + goto out; /* success */
22809 + AuDbg("err %d, reverting src\n", err);
22810 + au_ren_rev_diropq(err, a);
22815 +static int do_rename(struct au_ren_args *a)
22818 + struct dentry *d, *h_d;
22820 + if (!a->exchange) {
22821 + /* prepare workqueue args for asynchronous rmdir */
22822 + h_d = a->dst_h_dentry;
22823 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22824 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
22825 + && d_is_positive(h_d)) {
22827 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
22829 + if (unlikely(!a->thargs))
22831 + a->h_dst = dget(h_d);
22834 + /* create whiteout for src_dentry */
22835 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
22836 + a->src_bwh = au_dbwh(a->src_dentry);
22837 + AuDebugOn(a->src_bwh >= 0);
22838 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
22839 + a->src_h_parent);
22840 + err = PTR_ERR(a->src_wh_dentry);
22841 + if (IS_ERR(a->src_wh_dentry))
22845 + /* lookup whiteout for dentry */
22846 + if (au_ftest_ren(a->auren_flags, WHDST)) {
22847 + h_d = au_wh_lkup(a->dst_h_parent,
22848 + &a->dst_dentry->d_name, a->br);
22849 + err = PTR_ERR(h_d);
22852 + if (d_is_negative(h_d))
22855 + a->dst_wh_dentry = h_d;
22858 + /* rename dentry to tmpwh */
22860 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
22861 + if (unlikely(err))
22864 + d = a->dst_dentry;
22865 + au_set_h_dptr(d, a->btgt, NULL);
22866 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
22867 + if (unlikely(err))
22869 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
22873 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
22874 +#if 0 /* debugging */
22875 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
22876 + && d_is_positive(a->dst_h_dentry)
22877 + && a->src_btop != a->btgt);
22880 + /* rename by vfs_rename or cpup */
22881 + err = au_ren_or_cpup(a);
22882 + if (unlikely(err))
22883 + /* leave the copied-up one */
22886 + /* make dir opaque */
22887 + err = au_ren_diropq(a);
22888 + if (unlikely(err))
22891 + /* update target timestamps */
22892 + if (a->exchange) {
22893 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
22894 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
22895 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22896 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22898 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
22899 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
22900 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22901 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22903 + if (!a->exchange) {
22904 + /* remove whiteout for dentry */
22905 + if (a->dst_wh_dentry) {
22906 + a->h_path.dentry = a->dst_wh_dentry;
22907 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
22909 + if (unlikely(err))
22913 + /* remove whtmp */
22915 + au_ren_del_whtmp(a); /* ignore this error */
22917 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
22920 + goto out_success;
22923 + au_ren_rev_diropq(err, a);
22925 + au_ren_rev_rename(err, a);
22929 + au_ren_rev_whtmp(err, a);
22931 + dput(a->dst_wh_dentry);
22932 + a->dst_wh_dentry = NULL;
22934 + if (a->src_wh_dentry)
22935 + au_ren_rev_whsrc(err, a);
22937 + dput(a->src_wh_dentry);
22938 + dput(a->dst_wh_dentry);
22942 + au_whtmp_rmdir_free(a->thargs);
22943 + a->thargs = NULL;
22949 +/* ---------------------------------------------------------------------- */
22952 + * test if @dentry dir can be rename destination or not.
22953 + * success means, it is a logically empty dir.
22955 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
22957 + return au_test_empty(dentry, whlist);
22961 + * test if @a->src_dentry dir can be rename source or not.
22962 + * if it can, return 0.
22964 + * - it is a logically empty dir.
22965 + * - or, it exists on writable branch and has no children including whiteouts
22966 + * on the lower branch unless DIRREN is on.
22968 +static int may_rename_srcdir(struct au_ren_args *a)
22971 + unsigned int rdhash;
22972 + aufs_bindex_t btop, btgt;
22973 + struct dentry *dentry;
22974 + struct super_block *sb;
22975 + struct au_sbinfo *sbinfo;
22977 + dentry = a->src_dentry;
22978 + sb = dentry->d_sb;
22979 + sbinfo = au_sbi(sb);
22980 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
22981 + au_fset_ren(a->auren_flags, DIRREN);
22984 + btop = au_dbtop(dentry);
22985 + if (btop != btgt) {
22986 + struct au_nhash whlist;
22988 + SiMustAnyLock(sb);
22989 + rdhash = sbinfo->si_rdhash;
22991 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
22993 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
22994 + if (unlikely(err))
22996 + err = au_test_empty(dentry, &whlist);
22997 + au_nhash_wh_free(&whlist);
23001 + if (btop == au_dbtaildir(dentry))
23002 + return 0; /* success */
23004 + err = au_test_empty_lower(dentry);
23007 + if (err == -ENOTEMPTY) {
23008 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23011 + AuWarn1("renaming dir who has child(ren) on multiple "
23012 + "branches, is not supported\n");
23019 +/* side effect: sets whlist and h_dentry */
23020 +static int au_ren_may_dir(struct au_ren_args *a)
23023 + unsigned int rdhash;
23024 + struct dentry *d;
23026 + d = a->dst_dentry;
23027 + SiMustAnyLock(d->d_sb);
23030 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23031 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23033 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23034 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23035 + if (unlikely(err))
23038 + if (!a->exchange) {
23039 + au_set_dbtop(d, a->dst_btop);
23040 + err = may_rename_dstdir(d, &a->whlist);
23041 + au_set_dbtop(d, a->btgt);
23043 + err = may_rename_srcdir(a);
23045 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23046 + if (unlikely(err))
23049 + d = a->src_dentry;
23050 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23051 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23052 + err = may_rename_srcdir(a);
23053 + if (unlikely(err)) {
23054 + au_nhash_wh_free(&a->whlist);
23055 + a->whlist.nh_num = 0;
23062 +/* ---------------------------------------------------------------------- */
23065 + * simple tests for rename.
23066 + * following the checks in vfs, plus the parent-child relationship.
23068 +static int au_may_ren(struct au_ren_args *a)
23071 + struct inode *h_inode;
23073 + if (a->src_btop == a->btgt) {
23074 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23075 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23076 + if (unlikely(err))
23079 + if (unlikely(a->src_h_dentry == a->h_trap))
23084 + if (a->dst_btop != a->btgt)
23087 + err = -ENOTEMPTY;
23088 + if (unlikely(a->dst_h_dentry == a->h_trap))
23092 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23093 + if (d_really_is_negative(a->dst_dentry)) {
23094 + if (d_is_negative(a->dst_h_dentry))
23095 + err = au_may_add(a->dst_dentry, a->btgt,
23096 + a->dst_h_parent, isdir);
23098 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23100 + h_inode = d_inode(a->dst_h_dentry);
23101 + if (h_inode->i_nlink)
23102 + err = au_may_del(a->dst_dentry, a->btgt,
23103 + a->dst_h_parent, isdir);
23107 + if (unlikely(err == -ENOENT || err == -EEXIST))
23113 +/* ---------------------------------------------------------------------- */
23118 + * - src_dir and dir by lock_rename()
23119 + * - inode if exists
23122 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23124 + * + di_write_lock2_child()
23125 + * + di_write_lock_child()
23126 + * + ii_write_lock_child()
23127 + * + di_write_lock_child2()
23128 + * + ii_write_lock_child2()
23129 + * + src_parent and parent
23130 + * + di_write_lock_parent()
23131 + * + ii_write_lock_parent()
23132 + * + di_write_lock_parent2()
23133 + * + ii_write_lock_parent2()
23134 + * + lower src_dir and dir by vfsub_lock_rename()
23135 + * + verify the every relationships between child and parent. if any
23136 + * of them failed, unlock all and return -EBUSY.
23138 +static void au_ren_unlock(struct au_ren_args *a)
23140 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23141 + a->dst_h_parent, a->dst_hdir);
23142 + if (au_ftest_ren(a->auren_flags, DIRREN)
23144 + au_hn_inode_unlock(a->h_root);
23145 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23146 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23149 +static int au_ren_lock(struct au_ren_args *a)
23152 + unsigned int udba;
23155 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23156 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23157 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23158 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23160 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23161 + if (unlikely(err))
23163 + au_fset_ren(a->auren_flags, MNT_WRITE);
23164 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23165 + struct dentry *root;
23166 + struct inode *dir;
23169 + * sbinfo is already locked, so this ii_read_lock is
23170 + * unnecessary. but our debugging feature checks it.
23172 + root = a->src_inode->i_sb->s_root;
23173 + if (root != a->src_parent && root != a->dst_parent) {
23174 + dir = d_inode(root);
23175 + ii_read_lock_parent3(dir);
23176 + a->h_root = au_hi(dir, a->btgt);
23177 + ii_read_unlock(dir);
23178 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23181 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23182 + a->dst_h_parent, a->dst_hdir);
23183 + udba = au_opt_udba(a->src_dentry->d_sb);
23184 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23185 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23186 + err = au_busy_or_stale();
23187 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23188 + err = au_h_verify(a->src_h_dentry, udba,
23189 + d_inode(a->src_h_parent), a->src_h_parent,
23191 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23192 + err = au_h_verify(a->dst_h_dentry, udba,
23193 + d_inode(a->dst_h_parent), a->dst_h_parent,
23196 + goto out; /* success */
23198 + err = au_busy_or_stale();
23199 + au_ren_unlock(a);
23205 +/* ---------------------------------------------------------------------- */
23207 +static void au_ren_refresh_dir(struct au_ren_args *a)
23209 + struct inode *dir;
23211 + dir = a->dst_dir;
23212 + inode_inc_iversion(dir);
23213 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23214 + /* is this updating defined in POSIX? */
23215 + au_cpup_attr_timesizes(a->src_inode);
23216 + au_cpup_attr_nlink(dir, /*force*/1);
23218 + au_dir_ts(dir, a->btgt);
23220 + if (a->exchange) {
23221 + dir = a->src_dir;
23222 + inode_inc_iversion(dir);
23223 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23224 + /* is this updating defined in POSIX? */
23225 + au_cpup_attr_timesizes(a->dst_inode);
23226 + au_cpup_attr_nlink(dir, /*force*/1);
23228 + au_dir_ts(dir, a->btgt);
23231 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23234 + dir = a->src_dir;
23235 + inode_inc_iversion(dir);
23236 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23237 + au_cpup_attr_nlink(dir, /*force*/1);
23238 + au_dir_ts(dir, a->btgt);
23241 +static void au_ren_refresh(struct au_ren_args *a)
23243 + aufs_bindex_t bbot, bindex;
23244 + struct dentry *d, *h_d;
23245 + struct inode *i, *h_i;
23246 + struct super_block *sb;
23248 + d = a->dst_dentry;
23251 + /* already dget-ed by au_ren_or_cpup() */
23252 + au_set_h_dptr(d, a->btgt, a->h_dst);
23254 + i = a->dst_inode;
23256 + if (!a->exchange) {
23257 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23258 + vfsub_drop_nlink(i);
23260 + vfsub_dead_dir(i);
23261 + au_cpup_attr_timesizes(i);
23263 + au_update_dbrange(d, /*do_put_zero*/1);
23265 + au_cpup_attr_nlink(i, /*force*/1);
23268 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23269 + au_set_h_dptr(d, bindex, NULL);
23270 + bbot = au_dbbot(d);
23271 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23272 + au_set_h_dptr(d, bindex, NULL);
23273 + au_update_dbrange(d, /*do_put_zero*/0);
23277 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23278 + d_drop(a->src_dentry);
23279 + if (au_ftest_ren(a->auren_flags, DIRREN))
23280 + au_set_dbwh(a->src_dentry, -1);
23284 + d = a->src_dentry;
23285 + au_set_dbwh(d, -1);
23286 + bbot = au_dbbot(d);
23287 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23288 + h_d = au_h_dptr(d, bindex);
23290 + au_set_h_dptr(d, bindex, NULL);
23292 + au_set_dbbot(d, a->btgt);
23295 + i = a->src_inode;
23296 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23297 + return; /* success */
23299 + bbot = au_ibbot(i);
23300 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23301 + h_i = au_h_iptr(i, bindex);
23303 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23304 + /* ignore this error */
23305 + au_set_h_iptr(i, bindex, NULL, 0);
23308 + au_set_ibbot(i, a->btgt);
23311 +/* ---------------------------------------------------------------------- */
23313 +/* mainly for link(2) and rename(2) */
23314 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23316 + aufs_bindex_t bdiropq, bwh;
23317 + struct dentry *parent;
23318 + struct au_branch *br;
23320 + parent = dentry->d_parent;
23321 + IMustLock(d_inode(parent)); /* dir is locked */
23323 + bdiropq = au_dbdiropq(parent);
23324 + bwh = au_dbwh(dentry);
23325 + br = au_sbr(dentry->d_sb, btgt);
23326 + if (au_br_rdonly(br)
23327 + || (0 <= bdiropq && bdiropq < btgt)
23328 + || (0 <= bwh && bwh < btgt))
23331 + AuDbg("btgt %d\n", btgt);
23335 +/* sets src_btop, dst_btop and btgt */
23336 +static int au_ren_wbr(struct au_ren_args *a)
23339 + struct au_wr_dir_args wr_dir_args = {
23340 + /* .force_btgt = -1, */
23341 + .flags = AuWrDir_ADD_ENTRY
23344 + a->src_btop = au_dbtop(a->src_dentry);
23345 + a->dst_btop = au_dbtop(a->dst_dentry);
23346 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23347 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23348 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23349 + wr_dir_args.force_btgt = a->src_btop;
23350 + if (a->dst_inode && a->dst_btop < a->src_btop)
23351 + wr_dir_args.force_btgt = a->dst_btop;
23352 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23353 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23356 + au_update_dbtop(a->dst_dentry);
23361 +static void au_ren_dt(struct au_ren_args *a)
23363 + a->h_path.dentry = a->src_h_parent;
23364 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23365 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23366 + a->h_path.dentry = a->dst_h_parent;
23367 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23370 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23371 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23375 + a->h_path.dentry = a->src_h_dentry;
23376 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23377 + if (d_is_positive(a->dst_h_dentry)) {
23378 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23379 + a->h_path.dentry = a->dst_h_dentry;
23380 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23384 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23386 + struct dentry *h_d;
23387 + struct inode *h_inode;
23389 + au_dtime_revert(a->src_dt + AuPARENT);
23390 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23391 + au_dtime_revert(a->dst_dt + AuPARENT);
23393 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23394 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23395 + h_inode = d_inode(h_d);
23396 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23397 + au_dtime_revert(a->src_dt + AuCHILD);
23398 + inode_unlock(h_inode);
23400 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23401 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23402 + h_inode = d_inode(h_d);
23403 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23404 + au_dtime_revert(a->dst_dt + AuCHILD);
23405 + inode_unlock(h_inode);
23410 +/* ---------------------------------------------------------------------- */
23412 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23413 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23414 + unsigned int _flags)
23416 + int err, lock_flags;
23418 + /* reduce stack space */
23419 + struct au_ren_args *a;
23420 + struct au_pin pin;
23422 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23423 + IMustLock(_src_dir);
23424 + IMustLock(_dst_dir);
23427 + if (unlikely(_flags & RENAME_WHITEOUT))
23431 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23432 + a = kzalloc(sizeof(*a), GFP_NOFS);
23433 + if (unlikely(!a))
23436 + a->flags = _flags;
23437 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23438 + && RENAME_EXCHANGE > U8_MAX);
23439 + a->exchange = _flags & RENAME_EXCHANGE;
23440 + a->src_dir = _src_dir;
23441 + a->src_dentry = _src_dentry;
23442 + a->src_inode = NULL;
23443 + if (d_really_is_positive(a->src_dentry))
23444 + a->src_inode = d_inode(a->src_dentry);
23445 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23446 + a->dst_dir = _dst_dir;
23447 + a->dst_dentry = _dst_dentry;
23448 + a->dst_inode = NULL;
23449 + if (d_really_is_positive(a->dst_dentry))
23450 + a->dst_inode = d_inode(a->dst_dentry);
23451 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23452 + if (a->dst_inode) {
23454 + * if EXCHANGE && src is non-dir && dst is dir,
23455 + * dst is not locked.
23457 + /* IMustLock(a->dst_inode); */
23458 + au_igrab(a->dst_inode);
23462 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23463 + if (d_is_dir(a->src_dentry)) {
23464 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23465 + if (unlikely(!a->exchange
23466 + && d_really_is_positive(a->dst_dentry)
23467 + && !d_is_dir(a->dst_dentry)))
23469 + lock_flags |= AuLock_DIRS;
23471 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23472 + au_fset_ren(a->auren_flags, ISDIR_DST);
23473 + if (unlikely(!a->exchange
23474 + && d_really_is_positive(a->src_dentry)
23475 + && !d_is_dir(a->src_dentry)))
23477 + lock_flags |= AuLock_DIRS;
23479 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23481 + if (unlikely(err))
23484 + err = au_d_hashed_positive(a->src_dentry);
23485 + if (unlikely(err))
23488 + if (a->dst_inode) {
23490 + * If it is a dir, VFS unhash it before this
23491 + * function. It means we cannot rely upon d_unhashed().
23493 + if (unlikely(!a->dst_inode->i_nlink))
23495 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23496 + err = au_d_hashed_positive(a->dst_dentry);
23497 + if (unlikely(err && !a->exchange))
23499 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23501 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23505 + * is it possible?
23506 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23507 + * there may exist a problem somewhere else.
23510 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23513 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23514 + di_write_lock_parent(a->dst_parent);
23516 + /* which branch we process */
23517 + err = au_ren_wbr(a);
23518 + if (unlikely(err < 0))
23520 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23521 + a->h_path.mnt = au_br_mnt(a->br);
23523 + /* are they available to be renamed */
23524 + err = au_ren_may_dir(a);
23525 + if (unlikely(err))
23526 + goto out_children;
23528 + /* prepare the writable parent dir on the same branch */
23529 + if (a->dst_btop == a->btgt) {
23530 + au_fset_ren(a->auren_flags, WHDST);
23532 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23533 + if (unlikely(err))
23534 + goto out_children;
23538 + if (!a->exchange) {
23539 + if (a->src_dir != a->dst_dir) {
23541 + * this temporary unlock is safe,
23542 + * because both dir->i_mutex are locked.
23544 + di_write_unlock(a->dst_parent);
23545 + di_write_lock_parent(a->src_parent);
23546 + err = au_wr_dir_need_wh(a->src_dentry,
23547 + au_ftest_ren(a->auren_flags,
23550 + di_write_unlock(a->src_parent);
23551 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23553 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23555 + err = au_wr_dir_need_wh(a->src_dentry,
23556 + au_ftest_ren(a->auren_flags,
23560 + if (unlikely(err < 0))
23561 + goto out_children;
23563 + au_fset_ren(a->auren_flags, WHSRC);
23566 + if (a->src_btop != a->btgt) {
23567 + err = au_pin(&pin, a->src_dentry, a->btgt,
23568 + au_opt_udba(a->src_dentry->d_sb),
23569 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23571 + struct au_cp_generic cpg = {
23572 + .dentry = a->src_dentry,
23574 + .bsrc = a->src_btop,
23577 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23579 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23580 + err = au_sio_cpup_simple(&cpg);
23583 + if (unlikely(err))
23584 + goto out_children;
23585 + a->src_btop = a->btgt;
23586 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23587 + if (!a->exchange)
23588 + au_fset_ren(a->auren_flags, WHSRC);
23592 + if (a->exchange && a->dst_inode
23593 + && a->dst_btop != a->btgt) {
23594 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23595 + au_opt_udba(a->dst_dentry->d_sb),
23596 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23598 + struct au_cp_generic cpg = {
23599 + .dentry = a->dst_dentry,
23601 + .bsrc = a->dst_btop,
23604 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23606 + err = au_sio_cpup_simple(&cpg);
23609 + if (unlikely(err))
23610 + goto out_children;
23611 + a->dst_btop = a->btgt;
23612 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23615 + /* lock them all */
23616 + err = au_ren_lock(a);
23617 + if (unlikely(err))
23618 + /* leave the copied-up one */
23619 + goto out_children;
23621 + if (!a->exchange) {
23622 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23623 + err = au_may_ren(a);
23624 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23625 + err = -ENAMETOOLONG;
23626 + if (unlikely(err))
23630 + /* store timestamps to be revertible */
23633 + /* store dirren info */
23634 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23635 + err = au_dr_rename(a->src_dentry, a->btgt,
23636 + &a->dst_dentry->d_name, &rev);
23638 + if (unlikely(err))
23643 + err = do_rename(a);
23644 + if (unlikely(err))
23647 + if (au_ftest_ren(a->auren_flags, DIRREN))
23648 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23650 + /* update dir attributes */
23651 + au_ren_refresh_dir(a);
23653 + /* dput/iput all lower dentries */
23654 + au_ren_refresh(a);
23656 + goto out_hdir; /* success */
23659 + if (au_ftest_ren(a->auren_flags, DIRREN))
23660 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23662 + au_ren_rev_dt(err, a);
23664 + au_ren_unlock(a);
23666 + au_nhash_wh_free(&a->whlist);
23667 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23668 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23669 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23670 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23674 + if (d_unhashed(a->src_dentry))
23675 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23676 + if (d_unhashed(a->dst_dentry))
23677 + au_fset_ren(a->auren_flags, DROPPED_DST);
23678 + if (!a->exchange)
23679 + d_move(a->src_dentry, a->dst_dentry);
23681 + d_exchange(a->src_dentry, a->dst_dentry);
23682 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23683 + d_drop(a->dst_dentry);
23685 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23686 + d_drop(a->src_dentry);
23688 + au_update_dbtop(a->dst_dentry);
23689 + if (!a->dst_inode)
23690 + d_drop(a->dst_dentry);
23692 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23693 + di_write_unlock(a->dst_parent);
23695 + di_write_unlock2(a->src_parent, a->dst_parent);
23697 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23699 + iput(a->dst_inode);
23701 + au_whtmp_rmdir_free(a->thargs);
23707 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23708 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23709 +++ linux/fs/aufs/Kconfig 2019-07-11 15:42:14.458904362 +0200
23711 +# SPDX-License-Identifier: GPL-2.0
23713 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23715 + Aufs is a stackable unification filesystem such as Unionfs,
23716 + which unifies several directories and provides a merged single
23718 + In the early days, aufs was entirely re-designed and
23719 + re-implemented Unionfs Version 1.x series. Introducing many
23720 + original ideas, approaches and improvements, it becomes totally
23721 + different from Unionfs while keeping the basic features.
23725 + prompt "Maximum number of branches"
23726 + default AUFS_BRANCH_MAX_127
23728 + Specifies the maximum number of branches (or member directories)
23729 + in a single aufs. The larger value consumes more system
23730 + resources and has a minor impact to performance.
23731 +config AUFS_BRANCH_MAX_127
23734 + Specifies the maximum number of branches (or member directories)
23735 + in a single aufs. The larger value consumes more system
23736 + resources and has a minor impact to performance.
23737 +config AUFS_BRANCH_MAX_511
23740 + Specifies the maximum number of branches (or member directories)
23741 + in a single aufs. The larger value consumes more system
23742 + resources and has a minor impact to performance.
23743 +config AUFS_BRANCH_MAX_1023
23746 + Specifies the maximum number of branches (or member directories)
23747 + in a single aufs. The larger value consumes more system
23748 + resources and has a minor impact to performance.
23749 +config AUFS_BRANCH_MAX_32767
23752 + Specifies the maximum number of branches (or member directories)
23753 + in a single aufs. The larger value consumes more system
23754 + resources and has a minor impact to performance.
23757 +config AUFS_SBILIST
23759 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23762 + Automatic configuration for internal use.
23763 + When aufs supports Magic SysRq or /proc, enabled automatically.
23765 +config AUFS_HNOTIFY
23766 + bool "Detect direct branch access (bypassing aufs)"
23768 + If you want to modify files on branches directly, eg. bypassing aufs,
23769 + and want aufs to detect the changes of them fully, then enable this
23770 + option and use 'udba=notify' mount option.
23771 + Currently there is only one available configuration, "fsnotify".
23772 + It will have a negative impact to the performance.
23773 + See detail in aufs.5.
23776 + prompt "method" if AUFS_HNOTIFY
23777 + default AUFS_HFSNOTIFY
23778 +config AUFS_HFSNOTIFY
23783 +config AUFS_EXPORT
23784 + bool "NFS-exportable aufs"
23785 + depends on EXPORTFS
23787 + If you want to export your mounted aufs via NFS, then enable this
23788 + option. There are several requirements for this configuration.
23789 + See detail in aufs.5.
23791 +config AUFS_INO_T_64
23793 + depends on AUFS_EXPORT
23794 + depends on 64BIT && !(ALPHA || S390)
23797 + Automatic configuration for internal use.
23798 + /* typedef unsigned long/int __kernel_ino_t */
23799 + /* alpha and s390x are int */
23802 + bool "support for XATTR/EA (including Security Labels)"
23804 + If your branch fs supports XATTR/EA and you want to make them
23805 + available in aufs too, then enable this opsion and specify the
23806 + branch attributes for EA.
23807 + See detail in aufs.5.
23810 + bool "File-based Hierarchical Storage Management"
23812 + Hierarchical Storage Management (or HSM) is a well-known feature
23813 + in the storage world. Aufs provides this feature as file-based.
23814 + with multiple branches.
23815 + These multiple branches are prioritized, ie. the topmost one
23816 + should be the fastest drive and be used heavily.
23819 + bool "Readdir in userspace"
23821 + Aufs has two methods to provide a merged view for a directory,
23822 + by a user-space library and by kernel-space natively. The latter
23823 + is always enabled but sometimes large and slow.
23824 + If you enable this option, install the library in aufs2-util
23825 + package, and set some environment variables for your readdir(3),
23826 + then the work will be handled in user-space which generally
23827 + shows better performance in most cases.
23828 + See detail in aufs.5.
23830 +config AUFS_DIRREN
23831 + bool "Workaround for rename(2)-ing a directory"
23833 + By default, aufs returns EXDEV error in renameing a dir who has
23834 + his child on the lower branch, since it is a bad idea to issue
23835 + rename(2) internally for every lower branch. But user may not
23836 + accept this behaviour. So here is a workaround to allow such
23837 + rename(2) and store some extra infromation on the writable
23838 + branch. Obviously this costs high (and I don't like it).
23839 + To use this feature, you need to enable this configuration AND
23840 + to specify the mount option `dirren.'
23841 + See details in aufs.5 and the design documents.
23844 + bool "Show whiteouts"
23846 + If you want to make the whiteouts in aufs visible, then enable
23847 + this option and specify 'shwh' mount option. Although it may
23848 + sounds like philosophy or something, but in technically it
23849 + simply shows the name of whiteout with keeping its behaviour.
23851 +config AUFS_BR_RAMFS
23852 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
23854 + If you want to use ramfs as an aufs branch fs, then enable this
23855 + option. Generally tmpfs is recommended.
23856 + Aufs prohibited them to be a branch fs by default, because
23857 + initramfs becomes unusable after switch_root or something
23858 + generally. If you sets initramfs as an aufs branch and boot your
23859 + system by switch_root, you will meet a problem easily since the
23860 + files in initramfs may be inaccessible.
23861 + Unless you are going to use ramfs as an aufs branch fs without
23862 + switch_root or something, leave it N.
23864 +config AUFS_BR_FUSE
23865 + bool "Fuse fs as an aufs branch"
23866 + depends on FUSE_FS
23869 + If you want to use fuse-based userspace filesystem as an aufs
23870 + branch fs, then enable this option.
23871 + It implements the internal poll(2) operation which is
23872 + implemented by fuse only (curretnly).
23877 + Automatic configuration for internal use.
23879 +config AUFS_BR_HFSPLUS
23880 + bool "Hfsplus as an aufs branch"
23881 + depends on HFSPLUS_FS
23884 + If you want to use hfsplus fs as an aufs branch fs, then enable
23885 + this option. This option introduces a small overhead at
23886 + copying-up a file on hfsplus.
23888 +config AUFS_BDEV_LOOP
23890 + depends on BLK_DEV_LOOP
23893 + Automatic configuration for internal use.
23894 + Convert =[ym] into =y.
23897 + bool "Debug aufs"
23899 + Enable this to compile aufs internal debug code.
23900 + It will have a negative impact to the performance.
23902 +config AUFS_MAGIC_SYSRQ
23904 + depends on AUFS_DEBUG && MAGIC_SYSRQ
23907 + Automatic configuration for internal use.
23908 + When aufs supports Magic SysRq, enabled automatically.
23910 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
23911 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
23912 +++ linux/fs/aufs/lcnt.h 2020-01-27 10:57:18.175538316 +0100
23914 +/* SPDX-License-Identifier: GPL-2.0 */
23916 + * Copyright (C) 2018-2020 Junjiro R. Okajima
23918 + * This program, aufs is free software; you can redistribute it and/or modify
23919 + * it under the terms of the GNU General Public License as published by
23920 + * the Free Software Foundation; either version 2 of the License, or
23921 + * (at your option) any later version.
23923 + * This program is distributed in the hope that it will be useful,
23924 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23925 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23926 + * GNU General Public License for more details.
23928 + * You should have received a copy of the GNU General Public License
23929 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23933 + * simple long counter wrapper
23936 +#ifndef __AUFS_LCNT_H__
23937 +#define __AUFS_LCNT_H__
23941 +#include "debug.h"
23943 +#define AuLCntATOMIC 1
23944 +#define AuLCntPCPUCNT 2
23946 + * why does percpu_refcount require extra synchronize_rcu()s in
23947 + * au_br_do_free()
23949 +#define AuLCntPCPUREF 3
23951 +/* #define AuLCntChosen AuLCntATOMIC */
23952 +#define AuLCntChosen AuLCntPCPUCNT
23953 +/* #define AuLCntChosen AuLCntPCPUREF */
23955 +#if AuLCntChosen == AuLCntATOMIC
23956 +#include <linux/atomic.h>
23958 +typedef atomic_long_t au_lcnt_t;
23960 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
23962 + atomic_long_set(cnt, 0);
23966 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
23971 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
23972 + int do_sync __maybe_unused)
23977 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
23979 + atomic_long_inc(cnt);
23982 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
23984 + atomic_long_dec(cnt);
23987 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
23989 + return atomic_long_read(cnt);
23993 +#if AuLCntChosen == AuLCntPCPUCNT
23994 +#include <linux/percpu_counter.h>
23996 +typedef struct percpu_counter au_lcnt_t;
23998 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24000 + return percpu_counter_init(cnt, 0, GFP_NOFS);
24003 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24008 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
24010 + percpu_counter_destroy(cnt);
24013 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24015 + percpu_counter_inc(cnt);
24018 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24020 + percpu_counter_dec(cnt);
24023 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24027 + n = percpu_counter_sum(cnt);
24029 + if (LONG_MAX != LLONG_MAX
24031 + AuWarn1("%s\n", "wrap-around");
24037 +#if AuLCntChosen == AuLCntPCPUREF
24038 +#include <linux/percpu-refcount.h>
24040 +typedef struct percpu_ref au_lcnt_t;
24042 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24045 + release = percpu_ref_exit;
24046 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24049 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24051 + synchronize_rcu();
24054 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24056 + percpu_ref_kill(cnt);
24058 + au_lcnt_wait_for_fin(cnt);
24061 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24063 + percpu_ref_get(cnt);
24066 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24068 + percpu_ref_put(cnt);
24072 + * avoid calling this func as possible.
24074 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24078 + percpu_ref_switch_to_atomic_sync(cnt);
24079 + l = atomic_long_read(&cnt->count);
24081 + percpu_ref_switch_to_percpu(cnt);
24083 + /* percpu_ref is initialized by 1 instead of 0 */
24088 +#ifdef CONFIG_AUFS_DEBUG
24089 +#define AuLCntZero(val) do { \
24092 + AuDbg("%s = %ld\n", #val, l); \
24095 +#define AuLCntZero(val) do {} while (0)
24098 +#endif /* __KERNEL__ */
24099 +#endif /* __AUFS_LCNT_H__ */
24100 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24101 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24102 +++ linux/fs/aufs/loop.c 2020-01-27 10:57:18.175538316 +0100
24104 +// SPDX-License-Identifier: GPL-2.0
24106 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24108 + * This program, aufs is free software; you can redistribute it and/or modify
24109 + * it under the terms of the GNU General Public License as published by
24110 + * the Free Software Foundation; either version 2 of the License, or
24111 + * (at your option) any later version.
24113 + * This program is distributed in the hope that it will be useful,
24114 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24115 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24116 + * GNU General Public License for more details.
24118 + * You should have received a copy of the GNU General Public License
24119 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24123 + * support for loopback block device as a branch
24128 +/* added into drivers/block/loop.c */
24129 +static struct file *(*backing_file_func)(struct super_block *sb);
24132 + * test if two lower dentries have overlapping branches.
24134 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24136 + struct super_block *h_sb;
24137 + struct file *backing_file;
24139 + if (unlikely(!backing_file_func)) {
24140 + /* don't load "loop" module here */
24141 + backing_file_func = symbol_get(loop_backing_file);
24142 + if (unlikely(!backing_file_func))
24143 + /* "loop" module is not loaded */
24147 + h_sb = h_adding->d_sb;
24148 + backing_file = backing_file_func(h_sb);
24149 + if (!backing_file)
24152 + h_adding = backing_file->f_path.dentry;
24154 + * h_adding can be local NFS.
24155 + * in this case aufs cannot detect the loop.
24157 + if (unlikely(h_adding->d_sb == sb))
24159 + return !!au_test_subdir(h_adding, sb->s_root);
24162 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24163 +int au_test_loopback_kthread(void)
24166 + struct task_struct *tsk = current;
24167 + char c, comm[sizeof(tsk->comm)];
24170 + if (tsk->flags & PF_KTHREAD) {
24171 + get_task_comm(comm, tsk);
24173 + ret = ('0' <= c && c <= '9'
24174 + && !strncmp(comm, "loop", 4));
24180 +/* ---------------------------------------------------------------------- */
24182 +#define au_warn_loopback_step 16
24183 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24184 +static unsigned long *au_warn_loopback_array;
24186 +void au_warn_loopback(struct super_block *h_sb)
24188 + int i, new_nelem;
24189 + unsigned long *a, magic;
24190 + static DEFINE_SPINLOCK(spin);
24192 + magic = h_sb->s_magic;
24193 + spin_lock(&spin);
24194 + a = au_warn_loopback_array;
24195 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24196 + if (a[i] == magic) {
24197 + spin_unlock(&spin);
24201 + /* h_sb is new to us, print it */
24202 + if (i < au_warn_loopback_nelem) {
24207 + /* expand the array */
24208 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24209 + a = au_kzrealloc(au_warn_loopback_array,
24210 + au_warn_loopback_nelem * sizeof(unsigned long),
24211 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24212 + /*may_shrink*/0);
24214 + au_warn_loopback_nelem = new_nelem;
24215 + au_warn_loopback_array = a;
24220 + spin_unlock(&spin);
24221 + AuWarn1("realloc failed, ignored\n");
24225 + spin_unlock(&spin);
24226 + pr_warn("you may want to try another patch for loopback file "
24227 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24230 +int au_loopback_init(void)
24233 + struct super_block *sb __maybe_unused;
24235 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
24238 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24239 + sizeof(unsigned long), GFP_NOFS);
24240 + if (unlikely(!au_warn_loopback_array))
24246 +void au_loopback_fin(void)
24248 + if (backing_file_func)
24249 + symbol_put(loop_backing_file);
24250 + au_kfree_try_rcu(au_warn_loopback_array);
24252 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24253 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24254 +++ linux/fs/aufs/loop.h 2020-01-27 10:57:18.175538316 +0100
24256 +/* SPDX-License-Identifier: GPL-2.0 */
24258 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24260 + * This program, aufs is free software; you can redistribute it and/or modify
24261 + * it under the terms of the GNU General Public License as published by
24262 + * the Free Software Foundation; either version 2 of the License, or
24263 + * (at your option) any later version.
24265 + * This program is distributed in the hope that it will be useful,
24266 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24267 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24268 + * GNU General Public License for more details.
24270 + * You should have received a copy of the GNU General Public License
24271 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24275 + * support for loopback mount as a branch
24278 +#ifndef __AUFS_LOOP_H__
24279 +#define __AUFS_LOOP_H__
24284 +struct super_block;
24286 +#ifdef CONFIG_AUFS_BDEV_LOOP
24287 +/* drivers/block/loop.c */
24288 +struct file *loop_backing_file(struct super_block *sb);
24291 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24292 +int au_test_loopback_kthread(void);
24293 +void au_warn_loopback(struct super_block *h_sb);
24295 +int au_loopback_init(void);
24296 +void au_loopback_fin(void);
24298 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
24300 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24301 + struct dentry *h_adding)
24302 +AuStubInt0(au_test_loopback_kthread, void)
24303 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24305 +AuStubInt0(au_loopback_init, void)
24306 +AuStubVoid(au_loopback_fin, void)
24307 +#endif /* BLK_DEV_LOOP */
24309 +#endif /* __KERNEL__ */
24310 +#endif /* __AUFS_LOOP_H__ */
24311 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24312 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24313 +++ linux/fs/aufs/magic.mk 2019-07-11 15:42:14.468904634 +0200
24315 +# SPDX-License-Identifier: GPL-2.0
24317 +# defined in ${srctree}/fs/fuse/inode.c
24319 +ifdef CONFIG_FUSE_FS
24320 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24323 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24325 +ifdef CONFIG_XFS_FS
24326 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24329 +# defined in ${srctree}/fs/configfs/mount.c
24331 +ifdef CONFIG_CONFIGFS_FS
24332 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24335 +# defined in ${srctree}/fs/ubifs/ubifs.h
24337 +ifdef CONFIG_UBIFS_FS
24338 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24341 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24343 +ifdef CONFIG_HFSPLUS_FS
24344 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24346 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24347 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24348 +++ linux/fs/aufs/Makefile 2019-07-11 15:42:14.462237786 +0200
24350 +# SPDX-License-Identifier: GPL-2.0
24352 +include ${src}/magic.mk
24353 +ifeq (${CONFIG_AUFS_FS},m)
24354 +include ${src}/conf.mk
24356 +-include ${src}/priv_def.mk
24358 +# cf. include/linux/kernel.h
24360 +ccflags-y += -DDEBUG
24361 +# sparse requires the full pathname
24363 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24365 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24368 +obj-$(CONFIG_AUFS_FS) += aufs.o
24369 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24370 + wkq.o vfsub.o dcsub.o \
24371 + cpup.o whout.o wbr_policy.o \
24372 + dinfo.o dentry.o \
24374 + finfo.o file.o f_op.o \
24376 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24380 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24381 +aufs-$(CONFIG_SYSFS) += sysfs.o
24382 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24383 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24384 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24385 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24386 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24387 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24388 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24389 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24390 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24391 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24392 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24393 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24394 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24395 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24396 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24397 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24398 +++ linux/fs/aufs/module.c 2020-01-27 10:57:18.175538316 +0100
24400 +// SPDX-License-Identifier: GPL-2.0
24402 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24404 + * This program, aufs is free software; you can redistribute it and/or modify
24405 + * it under the terms of the GNU General Public License as published by
24406 + * the Free Software Foundation; either version 2 of the License, or
24407 + * (at your option) any later version.
24409 + * This program is distributed in the hope that it will be useful,
24410 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24411 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24412 + * GNU General Public License for more details.
24414 + * You should have received a copy of the GNU General Public License
24415 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24419 + * module global variables and operations
24422 +#include <linux/module.h>
24423 +#include <linux/seq_file.h>
24426 +/* shrinkable realloc */
24427 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24435 +#if 0 /* unused */
24442 + AuDebugOn(!new_sz);
24445 + diff = au_kmidx_sub(sz, new_sz);
24451 + /* expand or SLOB */
24452 + p = krealloc(p, new_sz, gfp);
24453 + else if (new_sz < sz && may_shrink) {
24457 + q = kmalloc(new_sz, gfp);
24460 + memcpy(q, p, new_sz);
24461 + au_kfree_try_rcu(p);
24472 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24475 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24476 + if (p && new_sz > nused)
24477 + memset(p + nused, 0, new_sz - nused);
24481 +/* ---------------------------------------------------------------------- */
24485 +struct kmem_cache *au_cache[AuCache_Last];
24487 +static void au_cache_fin(void)
24492 + * Make sure all delayed rcu free inodes are flushed before we
24497 + /* excluding AuCache_HNOTIFY */
24498 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24499 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24500 + kmem_cache_destroy(au_cache[i]);
24501 + au_cache[i] = NULL;
24505 +static int __init au_cache_init(void)
24507 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24508 + if (au_cache[AuCache_DINFO])
24509 + /* SLAB_DESTROY_BY_RCU */
24510 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24511 + au_icntnr_init_once);
24512 + if (au_cache[AuCache_ICNTNR])
24513 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24514 + au_fi_init_once);
24515 + if (au_cache[AuCache_FINFO])
24516 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24517 + if (au_cache[AuCache_VDIR])
24518 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24519 + if (au_cache[AuCache_DEHSTR])
24526 +/* ---------------------------------------------------------------------- */
24528 +int au_dir_roflags;
24530 +#ifdef CONFIG_AUFS_SBILIST
24532 + * iterate_supers_type() doesn't protect us from
24533 + * remounting (branch management)
24535 +struct hlist_bl_head au_sbilist;
24539 + * functions for module interface.
24541 +MODULE_LICENSE("GPL");
24542 +/* MODULE_LICENSE("GPL v2"); */
24543 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24544 +MODULE_DESCRIPTION(AUFS_NAME
24545 + " -- Advanced multi layered unification filesystem");
24546 +MODULE_VERSION(AUFS_VERSION);
24547 +MODULE_ALIAS_FS(AUFS_NAME);
24549 +/* this module parameter has no meaning when SYSFS is disabled */
24550 +int sysaufs_brs = 1;
24551 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24552 +module_param_named(brs, sysaufs_brs, int, 0444);
24554 +/* this module parameter has no meaning when USER_NS is disabled */
24556 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24557 +module_param_named(allow_userns, au_userns, bool, 0444);
24559 +/* ---------------------------------------------------------------------- */
24561 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24563 +int au_seq_path(struct seq_file *seq, struct path *path)
24567 + err = seq_path(seq, path, au_esc_chars);
24576 +/* ---------------------------------------------------------------------- */
24578 +static int __init aufs_init(void)
24583 + p = au_esc_chars;
24584 + for (i = 1; i <= ' '; i++)
24590 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24592 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24593 + for (i = 0; i < AuIop_Last; i++)
24594 + aufs_iop_nogetattr[i].getattr = NULL;
24596 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24598 + au_sbilist_init();
24599 + sysaufs_brs_init();
24602 + err = sysaufs_init();
24603 + if (unlikely(err))
24605 + err = dbgaufs_init();
24606 + if (unlikely(err))
24607 + goto out_sysaufs;
24608 + err = au_procfs_init();
24609 + if (unlikely(err))
24610 + goto out_dbgaufs;
24611 + err = au_wkq_init();
24612 + if (unlikely(err))
24614 + err = au_loopback_init();
24615 + if (unlikely(err))
24617 + err = au_hnotify_init();
24618 + if (unlikely(err))
24619 + goto out_loopback;
24620 + err = au_sysrq_init();
24621 + if (unlikely(err))
24623 + err = au_cache_init();
24624 + if (unlikely(err))
24627 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24628 + err = register_filesystem(&aufs_fs_type);
24629 + if (unlikely(err))
24632 + /* since we define pr_fmt, call printk directly */
24633 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24634 + goto out; /* success */
24641 + au_hnotify_fin();
24643 + au_loopback_fin();
24657 +static void __exit aufs_exit(void)
24659 + unregister_filesystem(&aufs_fs_type);
24662 + au_hnotify_fin();
24663 + au_loopback_fin();
24671 +module_init(aufs_init);
24672 +module_exit(aufs_exit);
24673 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24674 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24675 +++ linux/fs/aufs/module.h 2020-01-27 10:57:18.175538316 +0100
24677 +/* SPDX-License-Identifier: GPL-2.0 */
24679 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24681 + * This program, aufs is free software; you can redistribute it and/or modify
24682 + * it under the terms of the GNU General Public License as published by
24683 + * the Free Software Foundation; either version 2 of the License, or
24684 + * (at your option) any later version.
24686 + * This program is distributed in the hope that it will be useful,
24687 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24688 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24689 + * GNU General Public License for more details.
24691 + * You should have received a copy of the GNU General Public License
24692 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24696 + * module initialization and module-global
24699 +#ifndef __AUFS_MODULE_H__
24700 +#define __AUFS_MODULE_H__
24704 +#include <linux/slab.h>
24705 +#include "debug.h"
24706 +#include "dentry.h"
24709 +#include "inode.h"
24714 +/* module parameters */
24715 +extern int sysaufs_brs;
24716 +extern bool au_userns;
24718 +/* ---------------------------------------------------------------------- */
24720 +extern int au_dir_roflags;
24722 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24723 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24727 + * Comparing the size of the object with sizeof(struct rcu_head)
24728 + * case 1: object is always larger
24729 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24730 + * case 2: object is always smaller
24731 + * --> au_kfree_small()
24732 + * case 3: object can be any size
24733 + * --> au_kfree_try_rcu()
24736 +static inline void au_kfree_do_rcu(const void *p)
24739 + struct rcu_head rcu;
24740 + } *a = (void *)p;
24742 + kfree_rcu(a, rcu);
24745 +#define au_kfree_rcu(_p) do { \
24746 + typeof(_p) p = (_p); \
24747 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24749 + au_kfree_do_rcu(p); \
24752 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
24753 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
24755 +static inline void au_kfree_try_rcu(const void *p)
24759 + if (au_kfree_sz_test(p))
24760 + au_kfree_do_rcu(p);
24765 +static inline void au_kfree_small(const void *p)
24769 + AuDebugOn(au_kfree_sz_test(p));
24773 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24775 +#ifndef CONFIG_SLOB
24776 + return kmalloc_index(sz) - kmalloc_index(new_sz);
24778 + return -1; /* SLOB is untested */
24782 +int au_seq_path(struct seq_file *seq, struct path *path);
24784 +#ifdef CONFIG_PROC_FS
24786 +int __init au_procfs_init(void);
24787 +void au_procfs_fin(void);
24789 +AuStubInt0(au_procfs_init, void);
24790 +AuStubVoid(au_procfs_fin, void);
24793 +/* ---------------------------------------------------------------------- */
24802 + AuCache_HNOTIFY, /* must be last */
24806 +extern struct kmem_cache *au_cache[AuCache_Last];
24808 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24809 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24810 +#define AuCacheCtor(type, ctor) \
24811 + kmem_cache_create(#type, sizeof(struct type), \
24812 + __alignof__(struct type), AuCacheFlags, ctor)
24814 +#define AuCacheFuncs(name, index) \
24815 + static inline struct au_##name *au_cache_alloc_##name(void) \
24816 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24817 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
24818 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
24820 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
24821 + { void *p = rcu; \
24822 + p -= offsetof(struct au_##name, rcu); \
24823 + kmem_cache_free(au_cache[AuCache_##index], p); } \
24824 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
24825 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
24826 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
24828 + static inline void au_cache_free_##name(struct au_##name *p) \
24829 + { /* au_cache_free_##name##_norcu(p); */ \
24830 + au_cache_free_##name##_rcu(p); }
24832 +AuCacheFuncs(dinfo, DINFO);
24833 +AuCacheFuncs(icntnr, ICNTNR);
24834 +AuCacheFuncs(finfo, FINFO);
24835 +AuCacheFuncs(vdir, VDIR);
24836 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24837 +#ifdef CONFIG_AUFS_HNOTIFY
24838 +AuCacheFuncs(hnotify, HNOTIFY);
24841 +#endif /* __KERNEL__ */
24842 +#endif /* __AUFS_MODULE_H__ */
24843 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24844 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24845 +++ linux/fs/aufs/mvdown.c 2020-01-27 10:57:18.175538316 +0100
24847 +// SPDX-License-Identifier: GPL-2.0
24849 + * Copyright (C) 2011-2020 Junjiro R. Okajima
24851 + * This program, aufs is free software; you can redistribute it and/or modify
24852 + * it under the terms of the GNU General Public License as published by
24853 + * the Free Software Foundation; either version 2 of the License, or
24854 + * (at your option) any later version.
24856 + * This program is distributed in the hope that it will be useful,
24857 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24858 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24859 + * GNU General Public License for more details.
24861 + * You should have received a copy of the GNU General Public License
24862 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24866 + * move-down, opposite of copy-up
24871 +struct au_mvd_args {
24873 + struct super_block *h_sb;
24874 + struct dentry *h_parent;
24875 + struct au_hinode *hdir;
24876 + struct inode *h_dir, *h_inode;
24877 + struct au_pin pin;
24878 + } info[AUFS_MVDOWN_NARRAY];
24880 + struct aufs_mvdown mvdown;
24881 + struct dentry *dentry, *parent;
24882 + struct inode *inode, *dir;
24883 + struct super_block *sb;
24884 + aufs_bindex_t bopq, bwh, bfound;
24885 + unsigned char rename_lock;
24888 +#define mvd_errno mvdown.au_errno
24889 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
24890 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
24891 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
24892 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
24894 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
24895 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
24896 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
24897 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
24898 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
24899 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
24901 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
24902 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
24903 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
24904 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
24905 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
24906 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
24908 +#define AU_MVD_PR(flag, ...) do { \
24910 + pr_err(__VA_ARGS__); \
24913 +static int find_lower_writable(struct au_mvd_args *a)
24915 + struct super_block *sb;
24916 + aufs_bindex_t bindex, bbot;
24917 + struct au_branch *br;
24920 + bindex = a->mvd_bsrc;
24921 + bbot = au_sbbot(sb);
24922 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
24923 + for (bindex++; bindex <= bbot; bindex++) {
24924 + br = au_sbr(sb, bindex);
24925 + if (au_br_fhsm(br->br_perm)
24926 + && !sb_rdonly(au_br_sb(br)))
24929 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
24930 + for (bindex++; bindex <= bbot; bindex++) {
24931 + br = au_sbr(sb, bindex);
24932 + if (!au_br_rdonly(br))
24936 + for (bindex++; bindex <= bbot; bindex++) {
24937 + br = au_sbr(sb, bindex);
24938 + if (!sb_rdonly(au_br_sb(br))) {
24939 + if (au_br_rdonly(br))
24941 + |= AUFS_MVDOWN_ROLOWER_R;
24949 +/* make the parent dir on bdst */
24950 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
24955 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
24956 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
24957 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
24958 + a->mvd_h_dst_parent = NULL;
24959 + if (au_dbbot(a->parent) >= a->mvd_bdst)
24960 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24961 + if (!a->mvd_h_dst_parent) {
24962 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
24963 + if (unlikely(err)) {
24964 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
24967 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24975 +/* lock them all */
24976 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
24979 + struct dentry *h_trap;
24981 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
24982 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
24983 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
24984 + au_opt_udba(a->sb),
24985 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24987 + if (unlikely(err)) {
24988 + AU_MVD_PR(dmsg, "pin_dst failed\n");
24992 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
24993 + a->rename_lock = 0;
24994 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
24995 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
24996 + au_opt_udba(a->sb),
24997 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24998 + err = au_do_pin(&a->mvd_pin_src);
25000 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25001 + if (unlikely(err)) {
25002 + AU_MVD_PR(dmsg, "pin_src failed\n");
25005 + goto out; /* success */
25008 + a->rename_lock = 1;
25009 + au_pin_hdir_unlock(&a->mvd_pin_dst);
25010 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25011 + au_opt_udba(a->sb),
25012 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25014 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25015 + if (unlikely(err)) {
25016 + AU_MVD_PR(dmsg, "pin_src failed\n");
25017 + au_pin_hdir_lock(&a->mvd_pin_dst);
25020 + au_pin_hdir_unlock(&a->mvd_pin_src);
25021 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25022 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25024 + err = (h_trap != a->mvd_h_src_parent);
25026 + err = (h_trap != a->mvd_h_dst_parent);
25028 + BUG_ON(err); /* it should never happen */
25029 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25032 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25033 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25034 + au_pin_hdir_lock(&a->mvd_pin_src);
25035 + au_unpin(&a->mvd_pin_src);
25036 + au_pin_hdir_lock(&a->mvd_pin_dst);
25039 + goto out; /* success */
25042 + au_unpin(&a->mvd_pin_dst);
25048 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25050 + if (!a->rename_lock)
25051 + au_unpin(&a->mvd_pin_src);
25053 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25054 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25055 + au_pin_hdir_lock(&a->mvd_pin_src);
25056 + au_unpin(&a->mvd_pin_src);
25057 + au_pin_hdir_lock(&a->mvd_pin_dst);
25059 + au_unpin(&a->mvd_pin_dst);
25062 +/* copy-down the file */
25063 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25066 + struct au_cp_generic cpg = {
25067 + .dentry = a->dentry,
25068 + .bdst = a->mvd_bdst,
25069 + .bsrc = a->mvd_bsrc,
25071 + .pin = &a->mvd_pin_dst,
25072 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25075 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25076 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25077 + au_fset_cpup(cpg.flags, OVERWRITE);
25078 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25079 + au_fset_cpup(cpg.flags, RWDST);
25080 + err = au_sio_cpdown_simple(&cpg);
25081 + if (unlikely(err))
25082 + AU_MVD_PR(dmsg, "cpdown failed\n");
25089 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25092 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25095 + struct path h_path;
25096 + struct au_branch *br;
25097 + struct inode *delegated;
25099 + br = au_sbr(a->sb, a->mvd_bdst);
25100 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25101 + err = PTR_ERR(h_path.dentry);
25102 + if (IS_ERR(h_path.dentry)) {
25103 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25108 + if (d_is_positive(h_path.dentry)) {
25109 + h_path.mnt = au_br_mnt(br);
25110 + delegated = NULL;
25111 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25112 + &delegated, /*force*/0);
25113 + if (unlikely(err == -EWOULDBLOCK)) {
25114 + pr_warn("cannot retry for NFSv4 delegation"
25115 + " for an internal unlink\n");
25118 + if (unlikely(err))
25119 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25121 + dput(h_path.dentry);
25129 + * unlink the topmost h_dentry
25131 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25134 + struct path h_path;
25135 + struct inode *delegated;
25137 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25138 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25139 + delegated = NULL;
25140 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25141 + if (unlikely(err == -EWOULDBLOCK)) {
25142 + pr_warn("cannot retry for NFSv4 delegation"
25143 + " for an internal unlink\n");
25146 + if (unlikely(err))
25147 + AU_MVD_PR(dmsg, "unlink failed\n");
25153 +/* Since mvdown succeeded, we ignore an error of this function */
25154 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25157 + struct au_branch *br;
25159 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25160 + br = au_sbr(a->sb, a->mvd_bsrc);
25161 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25163 + br = au_sbr(a->sb, a->mvd_bdst);
25164 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25165 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25168 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25170 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25174 + * copy-down the file and unlink the bsrc file.
25175 + * - unlink the bdst whout if exist
25176 + * - copy-down the file (with whtmp name and rename)
25177 + * - unlink the bsrc file
25179 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25183 + err = au_do_mkdir(dmsg, a);
25185 + err = au_do_lock(dmsg, a);
25186 + if (unlikely(err))
25190 + * do not revert the activities we made on bdst since they should be
25191 + * harmless in aufs.
25194 + err = au_do_cpdown(dmsg, a);
25196 + err = au_do_unlink_wh(dmsg, a);
25197 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25198 + err = au_do_unlink(dmsg, a);
25199 + if (unlikely(err))
25202 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25203 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25204 + if (find_lower_writable(a) < 0)
25205 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25207 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25208 + au_do_stfs(dmsg, a);
25210 + /* maintain internal array */
25211 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25212 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25213 + au_set_dbtop(a->dentry, a->mvd_bdst);
25214 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25215 + au_set_ibtop(a->inode, a->mvd_bdst);
25217 + /* hide the lower */
25218 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25219 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25220 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25221 + au_set_ibbot(a->inode, a->mvd_bsrc);
25223 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25224 + au_set_dbbot(a->dentry, a->mvd_bdst);
25225 + if (au_ibbot(a->inode) < a->mvd_bdst)
25226 + au_set_ibbot(a->inode, a->mvd_bdst);
25229 + au_do_unlock(dmsg, a);
25235 +/* ---------------------------------------------------------------------- */
25237 +/* make sure the file is idle */
25238 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25240 + int err, plinked;
25243 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25244 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25245 + && au_dcount(a->dentry) == 1
25246 + && atomic_read(&a->inode->i_count) == 1
25247 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25248 + && (!plinked || !au_plink_test(a->inode))
25249 + && a->inode->i_nlink == 1)
25254 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25255 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25256 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25257 + a->mvd_h_src_inode->i_nlink,
25258 + plinked, plinked ? au_plink_test(a->inode) : 0);
25265 +/* make sure the parent dir is fine */
25266 +static int au_mvd_args_parent(const unsigned char dmsg,
25267 + struct au_mvd_args *a)
25270 + aufs_bindex_t bindex;
25273 + if (unlikely(au_alive_dir(a->parent))) {
25275 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25279 + a->bopq = au_dbdiropq(a->parent);
25280 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25281 + AuDbg("b%d\n", bindex);
25282 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25283 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25285 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25286 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25287 + a->bopq, a->mvd_bdst);
25295 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25296 + struct au_mvd_args *a)
25299 + struct au_dinfo *dinfo, *tmp;
25301 + /* lookup the next lower positive entry */
25303 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25304 + if (unlikely(!tmp))
25309 + dinfo = au_di(a->dentry);
25310 + au_di_cp(tmp, dinfo);
25311 + au_di_swap(tmp, dinfo);
25313 + /* returns the number of positive dentries */
25314 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25315 + /* AuLkup_IGNORE_PERM */ 0);
25317 + a->bwh = au_dbwh(a->dentry);
25318 + else if (err > 0)
25319 + a->bfound = au_dbtop(a->dentry);
25321 + au_di_swap(tmp, dinfo);
25322 + au_rw_write_unlock(&tmp->di_rwsem);
25324 + if (unlikely(err < 0))
25325 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25328 + * here, we have these cases.
25330 + * no positive dentry under bsrc. there are more sub-cases.
25332 + * there no whiteout, we can safely move-down.
25335 + * bsrc < bwh && bwh < bdst
25336 + * there is a whiteout on RO branch. cannot proceed.
25338 + * there is a whiteout on the RW target branch. it should
25341 + * there is a whiteout somewhere unrelated branch.
25342 + * -1 < bfound && bfound <= bsrc
25345 + * found, but it is on RO branch between bsrc and bdst. cannot
25348 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25351 + * found, after we create the file on bdst, it will be hidden.
25354 + AuDebugOn(a->bfound == -1
25356 + && a->bwh <= a->mvd_bsrc);
25357 + AuDebugOn(-1 < a->bfound
25358 + && a->bfound <= a->mvd_bsrc);
25361 + if (a->bfound == -1
25362 + && a->mvd_bsrc < a->bwh
25364 + && a->bwh < a->mvd_bdst) {
25365 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25366 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25367 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25369 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25370 + a->mvd_errno = EAU_MVDOWN_UPPER;
25371 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25372 + a->mvd_bdst, a->bfound);
25376 + err = 0; /* success */
25383 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25388 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25389 + && a->bfound == a->mvd_bdst)
25395 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25398 + struct au_branch *br;
25401 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25405 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25406 + a->mvd_bsrc = au_ibtop(a->inode);
25408 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25409 + if (unlikely(a->mvd_bsrc < 0
25410 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25411 + || au_dbbot(a->dentry) < a->mvd_bsrc
25412 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25413 + || (a->mvd_bsrc < au_ibtop(a->inode)
25414 + || au_ibbot(a->inode) < a->mvd_bsrc
25415 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25416 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25417 + AU_MVD_PR(dmsg, "no upper\n");
25421 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25422 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25423 + AU_MVD_PR(dmsg, "on the bottom\n");
25426 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25427 + br = au_sbr(a->sb, a->mvd_bsrc);
25428 + err = au_br_rdonly(br);
25429 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25430 + if (unlikely(err))
25432 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25433 + || IS_APPEND(a->mvd_h_src_inode))) {
25435 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25441 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25442 + a->mvd_bdst = find_lower_writable(a);
25443 + if (unlikely(a->mvd_bdst < 0)) {
25444 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25445 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25449 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25450 + if (unlikely(a->mvd_bdst < 0
25451 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25452 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25453 + AU_MVD_PR(dmsg, "no lower brid\n");
25458 + err = au_mvd_args_busy(dmsg, a);
25460 + err = au_mvd_args_parent(dmsg, a);
25462 + err = au_mvd_args_intermediate(dmsg, a);
25464 + err = au_mvd_args_exist(dmsg, a);
25466 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25473 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25476 + unsigned char dmsg;
25477 + struct au_mvd_args *args;
25478 + struct inode *inode;
25480 + inode = d_inode(dentry);
25482 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25486 + args = kmalloc(sizeof(*args), GFP_NOFS);
25487 + if (unlikely(!args))
25490 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25492 + /* VERIFY_WRITE */
25493 + err = !access_ok(uarg, sizeof(*uarg));
25494 + if (unlikely(err)) {
25499 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25500 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25501 + args->mvdown.au_errno = 0;
25502 + args->dentry = dentry;
25503 + args->inode = inode;
25504 + args->sb = dentry->d_sb;
25507 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25508 + args->parent = dget_parent(dentry);
25509 + args->dir = d_inode(args->parent);
25510 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25511 + dput(args->parent);
25512 + if (unlikely(args->parent != dentry->d_parent)) {
25513 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25517 + inode_lock_nested(inode, I_MUTEX_CHILD);
25518 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25519 + if (unlikely(err))
25522 + di_write_lock_parent(args->parent);
25523 + err = au_mvd_args(dmsg, args);
25524 + if (unlikely(err))
25527 + err = au_do_mvdown(dmsg, args);
25528 + if (unlikely(err))
25531 + au_cpup_attr_timesizes(args->dir);
25532 + au_cpup_attr_timesizes(inode);
25533 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25534 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25535 + /* au_digen_dec(dentry); */
25538 + di_write_unlock(args->parent);
25539 + aufs_read_unlock(dentry, AuLock_DW);
25541 + inode_unlock(inode);
25543 + inode_unlock(args->dir);
25545 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25548 + au_kfree_rcu(args);
25553 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25554 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25555 +++ linux/fs/aufs/opts.c 2020-01-27 10:57:18.175538316 +0100
25557 +// SPDX-License-Identifier: GPL-2.0
25559 + * Copyright (C) 2005-2020 Junjiro R. Okajima
25561 + * This program, aufs is free software; you can redistribute it and/or modify
25562 + * it under the terms of the GNU General Public License as published by
25563 + * the Free Software Foundation; either version 2 of the License, or
25564 + * (at your option) any later version.
25566 + * This program is distributed in the hope that it will be useful,
25567 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25568 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25569 + * GNU General Public License for more details.
25571 + * You should have received a copy of the GNU General Public License
25572 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25576 + * mount options/flags
25579 +#include <linux/namei.h>
25580 +#include <linux/types.h> /* a distribution requires */
25581 +#include <linux/parser.h>
25584 +/* ---------------------------------------------------------------------- */
25588 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25589 + Opt_idel, Opt_imod,
25590 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25591 + Opt_rdblk_def, Opt_rdhash_def,
25592 + Opt_xino, Opt_noxino,
25593 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25594 + Opt_trunc_xino_path, Opt_itrunc_xino,
25595 + Opt_trunc_xib, Opt_notrunc_xib,
25596 + Opt_shwh, Opt_noshwh,
25597 + Opt_plink, Opt_noplink, Opt_list_plink,
25599 + Opt_dio, Opt_nodio,
25600 + Opt_diropq_a, Opt_diropq_w,
25601 + Opt_warn_perm, Opt_nowarn_perm,
25602 + Opt_wbr_copyup, Opt_wbr_create,
25604 + Opt_verbose, Opt_noverbose,
25605 + Opt_sum, Opt_nosum, Opt_wsum,
25606 + Opt_dirperm1, Opt_nodirperm1,
25607 + Opt_dirren, Opt_nodirren,
25608 + Opt_acl, Opt_noacl,
25609 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25612 +static match_table_t options = {
25613 + {Opt_br, "br=%s"},
25614 + {Opt_br, "br:%s"},
25616 + {Opt_add, "add=%d:%s"},
25617 + {Opt_add, "add:%d:%s"},
25618 + {Opt_add, "ins=%d:%s"},
25619 + {Opt_add, "ins:%d:%s"},
25620 + {Opt_append, "append=%s"},
25621 + {Opt_append, "append:%s"},
25622 + {Opt_prepend, "prepend=%s"},
25623 + {Opt_prepend, "prepend:%s"},
25625 + {Opt_del, "del=%s"},
25626 + {Opt_del, "del:%s"},
25627 + /* {Opt_idel, "idel:%d"}, */
25628 + {Opt_mod, "mod=%s"},
25629 + {Opt_mod, "mod:%s"},
25630 + /* {Opt_imod, "imod:%d:%s"}, */
25632 + {Opt_dirwh, "dirwh=%d"},
25634 + {Opt_xino, "xino=%s"},
25635 + {Opt_noxino, "noxino"},
25636 + {Opt_trunc_xino, "trunc_xino"},
25637 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25638 + {Opt_notrunc_xino, "notrunc_xino"},
25639 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25640 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25641 + /* {Opt_zxino, "zxino=%s"}, */
25642 + {Opt_trunc_xib, "trunc_xib"},
25643 + {Opt_notrunc_xib, "notrunc_xib"},
25645 +#ifdef CONFIG_PROC_FS
25646 + {Opt_plink, "plink"},
25648 + {Opt_ignore_silent, "plink"},
25651 + {Opt_noplink, "noplink"},
25653 +#ifdef CONFIG_AUFS_DEBUG
25654 + {Opt_list_plink, "list_plink"},
25657 + {Opt_udba, "udba=%s"},
25659 + {Opt_dio, "dio"},
25660 + {Opt_nodio, "nodio"},
25662 +#ifdef CONFIG_AUFS_DIRREN
25663 + {Opt_dirren, "dirren"},
25664 + {Opt_nodirren, "nodirren"},
25666 + {Opt_ignore, "dirren"},
25667 + {Opt_ignore_silent, "nodirren"},
25670 +#ifdef CONFIG_AUFS_FHSM
25671 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25673 + {Opt_ignore, "fhsm_sec=%d"},
25676 + {Opt_diropq_a, "diropq=always"},
25677 + {Opt_diropq_a, "diropq=a"},
25678 + {Opt_diropq_w, "diropq=whiteouted"},
25679 + {Opt_diropq_w, "diropq=w"},
25681 + {Opt_warn_perm, "warn_perm"},
25682 + {Opt_nowarn_perm, "nowarn_perm"},
25684 + /* keep them temporary */
25685 + {Opt_ignore_silent, "nodlgt"},
25686 + {Opt_ignore, "clean_plink"},
25688 +#ifdef CONFIG_AUFS_SHWH
25689 + {Opt_shwh, "shwh"},
25691 + {Opt_noshwh, "noshwh"},
25693 + {Opt_dirperm1, "dirperm1"},
25694 + {Opt_nodirperm1, "nodirperm1"},
25696 + {Opt_verbose, "verbose"},
25697 + {Opt_verbose, "v"},
25698 + {Opt_noverbose, "noverbose"},
25699 + {Opt_noverbose, "quiet"},
25700 + {Opt_noverbose, "q"},
25701 + {Opt_noverbose, "silent"},
25703 + {Opt_sum, "sum"},
25704 + {Opt_nosum, "nosum"},
25705 + {Opt_wsum, "wsum"},
25707 + {Opt_rdcache, "rdcache=%d"},
25708 + {Opt_rdblk, "rdblk=%d"},
25709 + {Opt_rdblk_def, "rdblk=def"},
25710 + {Opt_rdhash, "rdhash=%d"},
25711 + {Opt_rdhash_def, "rdhash=def"},
25713 + {Opt_wbr_create, "create=%s"},
25714 + {Opt_wbr_create, "create_policy=%s"},
25715 + {Opt_wbr_copyup, "cpup=%s"},
25716 + {Opt_wbr_copyup, "copyup=%s"},
25717 + {Opt_wbr_copyup, "copyup_policy=%s"},
25719 + /* generic VFS flag */
25720 +#ifdef CONFIG_FS_POSIX_ACL
25721 + {Opt_acl, "acl"},
25722 + {Opt_noacl, "noacl"},
25724 + {Opt_ignore, "acl"},
25725 + {Opt_ignore_silent, "noacl"},
25728 + /* internal use for the scripts */
25729 + {Opt_ignore_silent, "si=%s"},
25731 + {Opt_br, "dirs=%s"},
25732 + {Opt_ignore, "debug=%d"},
25733 + {Opt_ignore, "delete=whiteout"},
25734 + {Opt_ignore, "delete=all"},
25735 + {Opt_ignore, "imap=%s"},
25737 + /* temporary workaround, due to old mount(8)? */
25738 + {Opt_ignore_silent, "relatime"},
25743 +/* ---------------------------------------------------------------------- */
25745 +static const char *au_parser_pattern(int val, match_table_t tbl)
25747 + struct match_token *p;
25750 + while (p->pattern) {
25751 + if (p->token == val)
25752 + return p->pattern;
25759 +static const char *au_optstr(int *val, match_table_t tbl)
25761 + struct match_token *p;
25768 + while (p->pattern) {
25770 + && (v & p->token) == p->token) {
25771 + *val &= ~p->token;
25772 + return p->pattern;
25781 +/* ---------------------------------------------------------------------- */
25783 +static match_table_t brperm = {
25784 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25785 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25786 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25790 +static match_table_t brattr = {
25792 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25793 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25794 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25795 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25796 +#ifdef CONFIG_AUFS_FHSM
25797 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25799 +#ifdef CONFIG_AUFS_XATTR
25800 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25801 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25802 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25803 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25804 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25805 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25808 + /* ro/rr branch */
25809 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25812 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25813 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25818 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25825 + p = strchr(str, '+');
25828 + v = match_token(str, table, args);
25830 + if (v & AuBrAttr_CMOO_Mask)
25831 + attr &= ~AuBrAttr_CMOO_Mask;
25836 + pr_warn("ignored branch attribute %s\n", str);
25846 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25854 + p = au_optstr(&perm, brattr);
25857 + memcpy(q, p, sz + 1);
25863 + p = au_optstr(&perm, brattr);
25867 + memcpy(q, p, sz + 1);
25873 + return q - str->a;
25876 +static int noinline_for_stack br_perm_val(char *perm)
25878 + int val, bad, sz;
25880 + substring_t args[MAX_OPT_ARGS];
25881 + au_br_perm_str_t attr;
25883 + p = strchr(perm, '+');
25886 + val = match_token(perm, brperm, args);
25890 + pr_warn("ignored branch permission %s\n", perm);
25891 + val = AuBrPerm_RO;
25897 + val |= br_attr_val(p + 1, brattr, args);
25900 + switch (val & AuBrPerm_Mask) {
25901 + case AuBrPerm_RO:
25902 + case AuBrPerm_RR:
25903 + bad = val & AuBrWAttr_Mask;
25904 + val &= ~AuBrWAttr_Mask;
25906 + case AuBrPerm_RW:
25907 + bad = val & AuBrRAttr_Mask;
25908 + val &= ~AuBrRAttr_Mask;
25913 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
25914 + * does not treat it as an error, just warning.
25915 + * this is a tiny guard for the user operation.
25917 + if (val & AuBrAttr_UNPIN) {
25918 + bad |= AuBrAttr_UNPIN;
25919 + val &= ~AuBrAttr_UNPIN;
25922 + if (unlikely(bad)) {
25923 + sz = au_do_optstr_br_attr(&attr, bad);
25925 + pr_warn("ignored branch attribute %s\n", attr.a);
25932 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
25934 + au_br_perm_str_t attr;
25940 + p = au_optstr(&perm, brperm);
25941 + AuDebugOn(!p || !*p);
25943 + memcpy(q, p, sz + 1);
25946 + sz = au_do_optstr_br_attr(&attr, perm);
25949 + memcpy(q, attr.a, sz + 1);
25952 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
25955 +/* ---------------------------------------------------------------------- */
25957 +static match_table_t udbalevel = {
25958 + {AuOpt_UDBA_REVAL, "reval"},
25959 + {AuOpt_UDBA_NONE, "none"},
25960 +#ifdef CONFIG_AUFS_HNOTIFY
25961 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
25962 +#ifdef CONFIG_AUFS_HFSNOTIFY
25963 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
25969 +static int noinline_for_stack udba_val(char *str)
25971 + substring_t args[MAX_OPT_ARGS];
25973 + return match_token(str, udbalevel, args);
25976 +const char *au_optstr_udba(int udba)
25978 + return au_parser_pattern(udba, udbalevel);
25981 +/* ---------------------------------------------------------------------- */
25983 +static match_table_t au_wbr_create_policy = {
25984 + {AuWbrCreate_TDP, "tdp"},
25985 + {AuWbrCreate_TDP, "top-down-parent"},
25986 + {AuWbrCreate_RR, "rr"},
25987 + {AuWbrCreate_RR, "round-robin"},
25988 + {AuWbrCreate_MFS, "mfs"},
25989 + {AuWbrCreate_MFS, "most-free-space"},
25990 + {AuWbrCreate_MFSV, "mfs:%d"},
25991 + {AuWbrCreate_MFSV, "most-free-space:%d"},
25993 + /* top-down regardless the parent, and then mfs */
25994 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
25995 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
25997 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
25998 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
25999 + {AuWbrCreate_PMFS, "pmfs"},
26000 + {AuWbrCreate_PMFSV, "pmfs:%d"},
26001 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
26002 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26007 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26008 + struct au_opt_wbr_create *create)
26011 + unsigned long long ull;
26014 + if (!match_u64(arg, &ull))
26015 + create->mfsrr_watermark = ull;
26017 + pr_err("bad integer in %s\n", str);
26024 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26025 + struct au_opt_wbr_create *create)
26030 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26031 + create->mfs_second = n;
26033 + pr_err("bad integer in %s\n", str);
26040 +static int noinline_for_stack
26041 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26044 + substring_t args[MAX_OPT_ARGS];
26046 + err = match_token(str, au_wbr_create_policy, args);
26047 + create->wbr_create = err;
26049 + case AuWbrCreate_MFSRRV:
26050 + case AuWbrCreate_TDMFSV:
26051 + case AuWbrCreate_PMFSRRV:
26052 + e = au_wbr_mfs_wmark(&args[0], str, create);
26054 + e = au_wbr_mfs_sec(&args[1], str, create);
26058 + case AuWbrCreate_MFSRR:
26059 + case AuWbrCreate_TDMFS:
26060 + case AuWbrCreate_PMFSRR:
26061 + e = au_wbr_mfs_wmark(&args[0], str, create);
26062 + if (unlikely(e)) {
26067 + case AuWbrCreate_MFS:
26068 + case AuWbrCreate_PMFS:
26069 + create->mfs_second = AUFS_MFS_DEF_SEC;
26071 + case AuWbrCreate_MFSV:
26072 + case AuWbrCreate_PMFSV:
26073 + e = au_wbr_mfs_sec(&args[0], str, create);
26082 +const char *au_optstr_wbr_create(int wbr_create)
26084 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26087 +static match_table_t au_wbr_copyup_policy = {
26088 + {AuWbrCopyup_TDP, "tdp"},
26089 + {AuWbrCopyup_TDP, "top-down-parent"},
26090 + {AuWbrCopyup_BUP, "bup"},
26091 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26092 + {AuWbrCopyup_BU, "bu"},
26093 + {AuWbrCopyup_BU, "bottom-up"},
26097 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26099 + substring_t args[MAX_OPT_ARGS];
26101 + return match_token(str, au_wbr_copyup_policy, args);
26104 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26106 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26109 +/* ---------------------------------------------------------------------- */
26111 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26113 +static void dump_opts(struct au_opts *opts)
26115 +#ifdef CONFIG_AUFS_DEBUG
26116 + /* reduce stack space */
26118 + struct au_opt_add *add;
26119 + struct au_opt_del *del;
26120 + struct au_opt_mod *mod;
26121 + struct au_opt_xino *xino;
26122 + struct au_opt_xino_itrunc *xino_itrunc;
26123 + struct au_opt_wbr_create *create;
26125 + struct au_opt *opt;
26128 + while (opt->type != Opt_tail) {
26129 + switch (opt->type) {
26131 + u.add = &opt->add;
26132 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26133 + u.add->bindex, u.add->pathname, u.add->perm,
26134 + u.add->path.dentry);
26138 + u.del = &opt->del;
26139 + AuDbg("del {%s, %p}\n",
26140 + u.del->pathname, u.del->h_path.dentry);
26144 + u.mod = &opt->mod;
26145 + AuDbg("mod {%s, 0x%x, %p}\n",
26146 + u.mod->path, u.mod->perm, u.mod->h_root);
26149 + u.add = &opt->add;
26150 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26151 + u.add->bindex, u.add->pathname, u.add->perm,
26152 + u.add->path.dentry);
26154 + case Opt_prepend:
26155 + u.add = &opt->add;
26156 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26157 + u.add->bindex, u.add->pathname, u.add->perm,
26158 + u.add->path.dentry);
26161 + AuDbg("dirwh %d\n", opt->dirwh);
26163 + case Opt_rdcache:
26164 + AuDbg("rdcache %d\n", opt->rdcache);
26167 + AuDbg("rdblk %u\n", opt->rdblk);
26169 + case Opt_rdblk_def:
26170 + AuDbg("rdblk_def\n");
26173 + AuDbg("rdhash %u\n", opt->rdhash);
26175 + case Opt_rdhash_def:
26176 + AuDbg("rdhash_def\n");
26179 + u.xino = &opt->xino;
26180 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26182 + case Opt_trunc_xino:
26183 + AuLabel(trunc_xino);
26185 + case Opt_notrunc_xino:
26186 + AuLabel(notrunc_xino);
26188 + case Opt_trunc_xino_path:
26189 + case Opt_itrunc_xino:
26190 + u.xino_itrunc = &opt->xino_itrunc;
26191 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26196 + case Opt_trunc_xib:
26197 + AuLabel(trunc_xib);
26199 + case Opt_notrunc_xib:
26200 + AuLabel(notrunc_xib);
26208 + case Opt_dirperm1:
26209 + AuLabel(dirperm1);
26211 + case Opt_nodirperm1:
26212 + AuLabel(nodirperm1);
26217 + case Opt_noplink:
26218 + AuLabel(noplink);
26220 + case Opt_list_plink:
26221 + AuLabel(list_plink);
26224 + AuDbg("udba %d, %s\n",
26225 + opt->udba, au_optstr_udba(opt->udba));
26233 + case Opt_diropq_a:
26234 + AuLabel(diropq_a);
26236 + case Opt_diropq_w:
26237 + AuLabel(diropq_w);
26239 + case Opt_warn_perm:
26240 + AuLabel(warn_perm);
26242 + case Opt_nowarn_perm:
26243 + AuLabel(nowarn_perm);
26245 + case Opt_verbose:
26246 + AuLabel(verbose);
26248 + case Opt_noverbose:
26249 + AuLabel(noverbose);
26260 + case Opt_wbr_create:
26261 + u.create = &opt->wbr_create;
26262 + AuDbg("create %d, %s\n", u.create->wbr_create,
26263 + au_optstr_wbr_create(u.create->wbr_create));
26264 + switch (u.create->wbr_create) {
26265 + case AuWbrCreate_MFSV:
26266 + case AuWbrCreate_PMFSV:
26267 + AuDbg("%d sec\n", u.create->mfs_second);
26269 + case AuWbrCreate_MFSRR:
26270 + case AuWbrCreate_TDMFS:
26271 + AuDbg("%llu watermark\n",
26272 + u.create->mfsrr_watermark);
26274 + case AuWbrCreate_MFSRRV:
26275 + case AuWbrCreate_TDMFSV:
26276 + case AuWbrCreate_PMFSRRV:
26277 + AuDbg("%llu watermark, %d sec\n",
26278 + u.create->mfsrr_watermark,
26279 + u.create->mfs_second);
26283 + case Opt_wbr_copyup:
26284 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26285 + au_optstr_wbr_copyup(opt->wbr_copyup));
26287 + case Opt_fhsm_sec:
26288 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26293 + case Opt_nodirren:
26294 + AuLabel(nodirren);
26310 +void au_opts_free(struct au_opts *opts)
26312 + struct au_opt *opt;
26315 + while (opt->type != Opt_tail) {
26316 + switch (opt->type) {
26319 + case Opt_prepend:
26320 + path_put(&opt->add.path);
26324 + path_put(&opt->del.h_path);
26328 + dput(opt->mod.h_root);
26331 + fput(opt->xino.file);
26338 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26339 + aufs_bindex_t bindex)
26342 + struct au_opt_add *add = &opt->add;
26345 + add->bindex = bindex;
26346 + add->perm = AuBrPerm_RO;
26347 + add->pathname = opt_str;
26348 + p = strchr(opt_str, '=');
26352 + add->perm = br_perm_val(p);
26355 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26358 + add->perm = AuBrPerm_RO;
26359 + if (au_test_fs_rr(add->path.dentry->d_sb))
26360 + add->perm = AuBrPerm_RR;
26361 + else if (!bindex && !(sb_flags & SB_RDONLY))
26362 + add->perm = AuBrPerm_RW;
26364 + opt->type = Opt_add;
26367 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26374 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26378 + del->pathname = args[0].from;
26379 + AuDbg("del path %s\n", del->pathname);
26381 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26382 + if (unlikely(err))
26383 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26388 +#if 0 /* reserved for future use */
26389 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26390 + struct au_opt_del *del, substring_t args[])
26393 + struct dentry *root;
26396 + root = sb->s_root;
26397 + aufs_read_lock(root, AuLock_FLUSH);
26398 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26399 + pr_err("out of bounds, %d\n", bindex);
26404 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26405 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26408 + aufs_read_unlock(root, !AuLock_IR);
26413 +static int noinline_for_stack
26414 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26417 + struct path path;
26421 + mod->path = args[0].from;
26422 + p = strchr(mod->path, '=');
26423 + if (unlikely(!p)) {
26424 + pr_err("no permission %s\n", args[0].from);
26429 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26430 + if (unlikely(err)) {
26431 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26435 + mod->perm = br_perm_val(p);
26436 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26437 + mod->h_root = dget(path.dentry);
26444 +#if 0 /* reserved for future use */
26445 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26446 + struct au_opt_mod *mod, substring_t args[])
26449 + struct dentry *root;
26452 + root = sb->s_root;
26453 + aufs_read_lock(root, AuLock_FLUSH);
26454 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26455 + pr_err("out of bounds, %d\n", bindex);
26460 + mod->perm = br_perm_val(args[1].from);
26461 + AuDbg("mod path %s, perm 0x%x, %s\n",
26462 + mod->path, mod->perm, args[1].from);
26463 + mod->h_root = dget(au_h_dptr(root, bindex));
26466 + aufs_read_unlock(root, !AuLock_IR);
26471 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26472 + substring_t args[])
26475 + struct file *file;
26477 + file = au_xino_create(sb, args[0].from, /*silent*/0, /*wbrtop*/0);
26478 + err = PTR_ERR(file);
26479 + if (IS_ERR(file))
26483 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26485 + pr_err("%s must be outside\n", args[0].from);
26490 + xino->file = file;
26491 + xino->path = args[0].from;
26497 +static int noinline_for_stack
26498 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26499 + struct au_opt_xino_itrunc *xino_itrunc,
26500 + substring_t args[])
26503 + aufs_bindex_t bbot, bindex;
26504 + struct path path;
26505 + struct dentry *root;
26507 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26508 + if (unlikely(err)) {
26509 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26513 + xino_itrunc->bindex = -1;
26514 + root = sb->s_root;
26515 + aufs_read_lock(root, AuLock_FLUSH);
26516 + bbot = au_sbbot(sb);
26517 + for (bindex = 0; bindex <= bbot; bindex++) {
26518 + if (au_h_dptr(root, bindex) == path.dentry) {
26519 + xino_itrunc->bindex = bindex;
26523 + aufs_read_unlock(root, !AuLock_IR);
26526 + if (unlikely(xino_itrunc->bindex < 0)) {
26527 + pr_err("no such branch %s\n", args[0].from);
26535 +/* called without aufs lock */
26536 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26538 + int err, n, token;
26539 + aufs_bindex_t bindex;
26540 + unsigned char skipped;
26541 + struct dentry *root;
26542 + struct au_opt *opt, *opt_tail;
26544 + /* reduce the stack space */
26546 + struct au_opt_xino_itrunc *xino_itrunc;
26547 + struct au_opt_wbr_create *create;
26550 + substring_t args[MAX_OPT_ARGS];
26554 + a = kmalloc(sizeof(*a), GFP_NOFS);
26555 + if (unlikely(!a))
26558 + root = sb->s_root;
26562 + opt_tail = opt + opts->max_opt - 1;
26563 + opt->type = Opt_tail;
26564 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26567 + token = match_token(opt_str, options, a->args);
26571 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26573 + err = opt_add(opt, opt_str, opts->sb_flags,
26575 + if (unlikely(!err && ++opt > opt_tail)) {
26579 + opt->type = Opt_tail;
26584 + if (unlikely(match_int(&a->args[0], &n))) {
26585 + pr_err("bad integer in %s\n", opt_str);
26589 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26592 + opt->type = token;
26595 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26596 + /*dummy bindex*/1);
26598 + opt->type = token;
26600 + case Opt_prepend:
26601 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26604 + opt->type = token;
26607 + err = au_opts_parse_del(&opt->del, a->args);
26609 + opt->type = token;
26611 +#if 0 /* reserved for future use */
26613 + del->pathname = "(indexed)";
26614 + if (unlikely(match_int(&args[0], &n))) {
26615 + pr_err("bad integer in %s\n", opt_str);
26618 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26620 + opt->type = token;
26624 + err = au_opts_parse_mod(&opt->mod, a->args);
26626 + opt->type = token;
26628 +#ifdef IMOD /* reserved for future use */
26630 + u.mod->path = "(indexed)";
26631 + if (unlikely(match_int(&a->args[0], &n))) {
26632 + pr_err("bad integer in %s\n", opt_str);
26635 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26637 + opt->type = token;
26641 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26643 + opt->type = token;
26646 + case Opt_trunc_xino_path:
26647 + err = au_opts_parse_xino_itrunc_path
26648 + (sb, &opt->xino_itrunc, a->args);
26650 + opt->type = token;
26653 + case Opt_itrunc_xino:
26654 + u.xino_itrunc = &opt->xino_itrunc;
26655 + if (unlikely(match_int(&a->args[0], &n))) {
26656 + pr_err("bad integer in %s\n", opt_str);
26659 + u.xino_itrunc->bindex = n;
26660 + aufs_read_lock(root, AuLock_FLUSH);
26661 + if (n < 0 || au_sbbot(sb) < n) {
26662 + pr_err("out of bounds, %d\n", n);
26663 + aufs_read_unlock(root, !AuLock_IR);
26666 + aufs_read_unlock(root, !AuLock_IR);
26668 + opt->type = token;
26672 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26675 + opt->type = token;
26678 + case Opt_rdcache:
26679 + if (unlikely(match_int(&a->args[0], &n))) {
26680 + pr_err("bad integer in %s\n", opt_str);
26683 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26684 + pr_err("rdcache must be smaller than %d\n",
26685 + AUFS_RDCACHE_MAX);
26688 + opt->rdcache = n;
26690 + opt->type = token;
26693 + if (unlikely(match_int(&a->args[0], &n)
26695 + || n > KMALLOC_MAX_SIZE)) {
26696 + pr_err("bad integer in %s\n", opt_str);
26699 + if (unlikely(n && n < NAME_MAX)) {
26700 + pr_err("rdblk must be larger than %d\n",
26706 + opt->type = token;
26709 + if (unlikely(match_int(&a->args[0], &n)
26711 + || n * sizeof(struct hlist_head)
26712 + > KMALLOC_MAX_SIZE)) {
26713 + pr_err("bad integer in %s\n", opt_str);
26718 + opt->type = token;
26721 + case Opt_trunc_xino:
26722 + case Opt_notrunc_xino:
26724 + case Opt_trunc_xib:
26725 + case Opt_notrunc_xib:
26728 + case Opt_dirperm1:
26729 + case Opt_nodirperm1:
26731 + case Opt_noplink:
26732 + case Opt_list_plink:
26735 + case Opt_diropq_a:
26736 + case Opt_diropq_w:
26737 + case Opt_warn_perm:
26738 + case Opt_nowarn_perm:
26739 + case Opt_verbose:
26740 + case Opt_noverbose:
26744 + case Opt_rdblk_def:
26745 + case Opt_rdhash_def:
26747 + case Opt_nodirren:
26751 + opt->type = token;
26755 + opt->udba = udba_val(a->args[0].from);
26756 + if (opt->udba >= 0) {
26758 + opt->type = token;
26760 + pr_err("wrong value, %s\n", opt_str);
26763 + case Opt_wbr_create:
26764 + u.create = &opt->wbr_create;
26765 + u.create->wbr_create
26766 + = au_wbr_create_val(a->args[0].from, u.create);
26767 + if (u.create->wbr_create >= 0) {
26769 + opt->type = token;
26771 + pr_err("wrong value, %s\n", opt_str);
26773 + case Opt_wbr_copyup:
26774 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26775 + if (opt->wbr_copyup >= 0) {
26777 + opt->type = token;
26779 + pr_err("wrong value, %s\n", opt_str);
26782 + case Opt_fhsm_sec:
26783 + if (unlikely(match_int(&a->args[0], &n)
26785 + pr_err("bad integer in %s\n", opt_str);
26788 + if (sysaufs_brs) {
26789 + opt->fhsm_second = n;
26790 + opt->type = token;
26792 + pr_warn("ignored %s\n", opt_str);
26797 + pr_warn("ignored %s\n", opt_str);
26799 + case Opt_ignore_silent:
26804 + pr_err("unknown option %s\n", opt_str);
26808 + if (!err && !skipped) {
26809 + if (unlikely(++opt > opt_tail)) {
26812 + opt->type = Opt_tail;
26815 + opt->type = Opt_tail;
26821 + if (unlikely(err))
26822 + au_opts_free(opts);
26828 +static int au_opt_wbr_create(struct super_block *sb,
26829 + struct au_opt_wbr_create *create)
26832 + struct au_sbinfo *sbinfo;
26834 + SiMustWriteLock(sb);
26836 + err = 1; /* handled */
26837 + sbinfo = au_sbi(sb);
26838 + if (sbinfo->si_wbr_create_ops->fin) {
26839 + err = sbinfo->si_wbr_create_ops->fin(sb);
26844 + sbinfo->si_wbr_create = create->wbr_create;
26845 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26846 + switch (create->wbr_create) {
26847 + case AuWbrCreate_MFSRRV:
26848 + case AuWbrCreate_MFSRR:
26849 + case AuWbrCreate_TDMFS:
26850 + case AuWbrCreate_TDMFSV:
26851 + case AuWbrCreate_PMFSRR:
26852 + case AuWbrCreate_PMFSRRV:
26853 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26855 + case AuWbrCreate_MFS:
26856 + case AuWbrCreate_MFSV:
26857 + case AuWbrCreate_PMFS:
26858 + case AuWbrCreate_PMFSV:
26859 + sbinfo->si_wbr_mfs.mfs_expire
26860 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
26864 + if (sbinfo->si_wbr_create_ops->init)
26865 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
26872 + * plus: processed without an error
26873 + * zero: unprocessed
26875 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
26876 + struct au_opts *opts)
26879 + struct au_sbinfo *sbinfo;
26881 + SiMustWriteLock(sb);
26883 + err = 1; /* handled */
26884 + sbinfo = au_sbi(sb);
26885 + switch (opt->type) {
26887 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
26888 + sbinfo->si_mntflags |= opt->udba;
26889 + opts->given_udba |= opt->udba;
26893 + au_opt_set(sbinfo->si_mntflags, PLINK);
26895 + case Opt_noplink:
26896 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26897 + au_plink_put(sb, /*verbose*/1);
26898 + au_opt_clr(sbinfo->si_mntflags, PLINK);
26900 + case Opt_list_plink:
26901 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26902 + au_plink_list(sb);
26906 + au_opt_set(sbinfo->si_mntflags, DIO);
26907 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26910 + au_opt_clr(sbinfo->si_mntflags, DIO);
26911 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26914 + case Opt_fhsm_sec:
26915 + au_fhsm_set(sbinfo, opt->fhsm_second);
26918 + case Opt_diropq_a:
26919 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26921 + case Opt_diropq_w:
26922 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26925 + case Opt_warn_perm:
26926 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
26928 + case Opt_nowarn_perm:
26929 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
26932 + case Opt_verbose:
26933 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
26935 + case Opt_noverbose:
26936 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
26940 + au_opt_set(sbinfo->si_mntflags, SUM);
26943 + au_opt_clr(sbinfo->si_mntflags, SUM);
26944 + au_opt_set(sbinfo->si_mntflags, SUM_W);
26947 + au_opt_clr(sbinfo->si_mntflags, SUM);
26948 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
26951 + case Opt_wbr_create:
26952 + err = au_opt_wbr_create(sb, &opt->wbr_create);
26954 + case Opt_wbr_copyup:
26955 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
26956 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
26960 + sbinfo->si_dirwh = opt->dirwh;
26963 + case Opt_rdcache:
26964 + sbinfo->si_rdcache
26965 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
26968 + sbinfo->si_rdblk = opt->rdblk;
26970 + case Opt_rdblk_def:
26971 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26974 + sbinfo->si_rdhash = opt->rdhash;
26976 + case Opt_rdhash_def:
26977 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26981 + au_opt_set(sbinfo->si_mntflags, SHWH);
26984 + au_opt_clr(sbinfo->si_mntflags, SHWH);
26987 + case Opt_dirperm1:
26988 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
26990 + case Opt_nodirperm1:
26991 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
26994 + case Opt_trunc_xino:
26995 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
26997 + case Opt_notrunc_xino:
26998 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27001 + case Opt_trunc_xino_path:
27002 + case Opt_itrunc_xino:
27003 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27009 + case Opt_trunc_xib:
27010 + au_fset_opts(opts->flags, TRUNC_XIB);
27012 + case Opt_notrunc_xib:
27013 + au_fclr_opts(opts->flags, TRUNC_XIB);
27018 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27019 + err = au_dr_opt_set(sb);
27024 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27026 + case Opt_nodirren:
27028 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27029 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27035 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27039 + sb->s_flags |= SB_POSIXACL;
27042 + sb->s_flags &= ~SB_POSIXACL;
27054 + * returns tri-state.
27055 + * plus: processed without an error
27056 + * zero: unprocessed
27059 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27060 + struct au_opts *opts)
27062 + int err, do_refresh;
27065 + switch (opt->type) {
27067 + opt->add.bindex = au_sbbot(sb) + 1;
27068 + if (opt->add.bindex < 0)
27069 + opt->add.bindex = 0;
27071 + /* Always goto add, not fallthrough */
27072 + case Opt_prepend:
27073 + opt->add.bindex = 0;
27074 + /* fallthrough */
27075 + add: /* indented label */
27077 + err = au_br_add(sb, &opt->add,
27078 + au_ftest_opts(opts->flags, REMOUNT));
27081 + au_fset_opts(opts->flags, REFRESH);
27087 + err = au_br_del(sb, &opt->del,
27088 + au_ftest_opts(opts->flags, REMOUNT));
27091 + au_fset_opts(opts->flags, TRUNC_XIB);
27092 + au_fset_opts(opts->flags, REFRESH);
27098 + err = au_br_mod(sb, &opt->mod,
27099 + au_ftest_opts(opts->flags, REMOUNT),
27104 + au_fset_opts(opts->flags, REFRESH);
27111 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27112 + struct au_opt_xino **opt_xino,
27113 + struct au_opts *opts)
27118 + switch (opt->type) {
27120 + err = au_xino_set(sb, &opt->xino,
27121 + !!au_ftest_opts(opts->flags, REMOUNT));
27122 + if (unlikely(err))
27125 + *opt_xino = &opt->xino;
27130 + *opt_xino = (void *)-1;
27137 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27138 + unsigned int pending)
27141 + aufs_bindex_t bindex, bbot;
27142 + unsigned char do_plink, skip, do_free, can_no_dreval;
27143 + struct au_branch *br;
27144 + struct au_wbr *wbr;
27145 + struct dentry *root, *dentry;
27146 + struct inode *dir, *h_dir;
27147 + struct au_sbinfo *sbinfo;
27148 + struct au_hinode *hdir;
27150 + SiMustAnyLock(sb);
27152 + sbinfo = au_sbi(sb);
27153 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27155 + if (!(sb_flags & SB_RDONLY)) {
27156 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27157 + pr_warn("first branch should be rw\n");
27158 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27159 + pr_warn_once("shwh should be used with ro\n");
27162 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27163 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27164 + pr_warn_once("udba=*notify requires xino\n");
27166 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27167 + pr_warn_once("dirperm1 breaks the protection"
27168 + " by the permission bits on the lower branch\n");
27172 + root = sb->s_root;
27173 + dir = d_inode(root);
27174 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27175 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27177 + bbot = au_sbbot(sb);
27178 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27180 + h_dir = au_h_iptr(dir, bindex);
27181 + br = au_sbr(sb, bindex);
27183 + if ((br->br_perm & AuBrAttr_ICEX)
27184 + && !h_dir->i_op->listxattr)
27185 + br->br_perm &= ~AuBrAttr_ICEX;
27186 +#if 0 /* untested */
27187 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27188 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27189 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27193 + wbr = br->br_wbr;
27195 + wbr_wh_read_lock(wbr);
27197 + if (!au_br_writable(br->br_perm)) {
27200 + || (!wbr->wbr_whbase
27201 + && !wbr->wbr_plink
27202 + && !wbr->wbr_orph));
27203 + } else if (!au_br_wh_linkable(br->br_perm)) {
27204 + /* skip = (!br->br_whbase && !br->br_orph); */
27205 + skip = (!wbr || !wbr->wbr_whbase);
27206 + if (skip && wbr) {
27208 + skip = !!wbr->wbr_plink;
27210 + skip = !wbr->wbr_plink;
27213 + /* skip = (br->br_whbase && br->br_ohph); */
27214 + skip = (wbr && wbr->wbr_whbase);
27217 + skip = !!wbr->wbr_plink;
27219 + skip = !wbr->wbr_plink;
27223 + wbr_wh_read_unlock(wbr);
27225 + if (can_no_dreval) {
27226 + dentry = br->br_path.dentry;
27227 + spin_lock(&dentry->d_lock);
27228 + if (dentry->d_flags &
27229 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27230 + can_no_dreval = 0;
27231 + spin_unlock(&dentry->d_lock);
27234 + if (au_br_fhsm(br->br_perm)) {
27236 + AuDebugOn(!br->br_fhsm);
27242 + hdir = au_hi(dir, bindex);
27243 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27245 + wbr_wh_write_lock(wbr);
27246 + err = au_wh_init(br, sb);
27248 + wbr_wh_write_unlock(wbr);
27249 + au_hn_inode_unlock(hdir);
27251 + if (!err && do_free) {
27252 + au_kfree_rcu(wbr);
27253 + br->br_wbr = NULL;
27257 + if (can_no_dreval)
27258 + au_fset_si(sbinfo, NO_DREVAL);
27260 + au_fclr_si(sbinfo, NO_DREVAL);
27263 + au_fset_si(sbinfo, FHSM);
27264 + for (bindex = bbot; bindex >= 0; bindex--) {
27265 + br = au_sbr(sb, bindex);
27266 + if (au_br_fhsm(br->br_perm)) {
27267 + au_fhsm_set_bottom(sb, bindex);
27272 + au_fclr_si(sbinfo, FHSM);
27273 + au_fhsm_set_bottom(sb, -1);
27279 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27282 + unsigned int tmp;
27283 + aufs_bindex_t bindex, bbot;
27284 + struct au_opt *opt;
27285 + struct au_opt_xino *opt_xino, xino;
27286 + struct au_sbinfo *sbinfo;
27287 + struct au_branch *br;
27288 + struct inode *dir;
27290 + SiMustWriteLock(sb);
27295 + while (err >= 0 && opt->type != Opt_tail)
27296 + err = au_opt_simple(sb, opt++, opts);
27299 + else if (unlikely(err < 0))
27302 + /* disable xino and udba temporary */
27303 + sbinfo = au_sbi(sb);
27304 + tmp = sbinfo->si_mntflags;
27305 + au_opt_clr(sbinfo->si_mntflags, XINO);
27306 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27309 + while (err >= 0 && opt->type != Opt_tail)
27310 + err = au_opt_br(sb, opt++, opts);
27313 + else if (unlikely(err < 0))
27316 + bbot = au_sbbot(sb);
27317 + if (unlikely(bbot < 0)) {
27319 + pr_err("no branches\n");
27323 + if (au_opt_test(tmp, XINO))
27324 + au_opt_set(sbinfo->si_mntflags, XINO);
27326 + while (!err && opt->type != Opt_tail)
27327 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27328 + if (unlikely(err))
27331 + err = au_opts_verify(sb, sb->s_flags, tmp);
27332 + if (unlikely(err))
27335 + /* restore xino */
27336 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27337 + xino.file = au_xino_def(sb);
27338 + err = PTR_ERR(xino.file);
27339 + if (IS_ERR(xino.file))
27342 + err = au_xino_set(sb, &xino, /*remount*/0);
27344 + if (unlikely(err))
27348 + /* restore udba */
27349 + tmp &= AuOptMask_UDBA;
27350 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27351 + sbinfo->si_mntflags |= tmp;
27352 + bbot = au_sbbot(sb);
27353 + for (bindex = 0; bindex <= bbot; bindex++) {
27354 + br = au_sbr(sb, bindex);
27355 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27356 + if (unlikely(err))
27357 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27359 + /* go on even if err */
27361 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27362 + dir = d_inode(sb->s_root);
27363 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27370 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27373 + unsigned char no_dreval;
27374 + struct inode *dir;
27375 + struct au_opt_xino *opt_xino;
27376 + struct au_opt *opt;
27377 + struct au_sbinfo *sbinfo;
27379 + SiMustWriteLock(sb);
27381 + err = au_dr_opt_flush(sb);
27382 + if (unlikely(err))
27384 + au_fset_opts(opts->flags, DR_FLUSHED);
27386 + dir = d_inode(sb->s_root);
27387 + sbinfo = au_sbi(sb);
27390 + while (err >= 0 && opt->type != Opt_tail) {
27391 + err = au_opt_simple(sb, opt, opts);
27393 + err = au_opt_br(sb, opt, opts);
27395 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27401 + /* go on even err */
27403 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27404 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27405 + if (unlikely(rerr && !err))
27408 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27409 + au_fset_opts(opts->flags, REFRESH_IDOP);
27411 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27412 + rerr = au_xib_trunc(sb);
27413 + if (unlikely(rerr && !err))
27417 + /* will be handled by the caller */
27418 + if (!au_ftest_opts(opts->flags, REFRESH)
27419 + && (opts->given_udba
27420 + || au_opt_test(sbinfo->si_mntflags, XINO)
27421 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27423 + au_fset_opts(opts->flags, REFRESH);
27425 + AuDbg("status 0x%x\n", opts->flags);
27431 +/* ---------------------------------------------------------------------- */
27433 +unsigned int au_opt_udba(struct super_block *sb)
27435 + return au_mntflags(sb) & AuOptMask_UDBA;
27437 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27438 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27439 +++ linux/fs/aufs/opts.h 2020-01-27 10:57:18.175538316 +0100
27441 +/* SPDX-License-Identifier: GPL-2.0 */
27443 + * Copyright (C) 2005-2020 Junjiro R. Okajima
27445 + * This program, aufs is free software; you can redistribute it and/or modify
27446 + * it under the terms of the GNU General Public License as published by
27447 + * the Free Software Foundation; either version 2 of the License, or
27448 + * (at your option) any later version.
27450 + * This program is distributed in the hope that it will be useful,
27451 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27452 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27453 + * GNU General Public License for more details.
27455 + * You should have received a copy of the GNU General Public License
27456 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27460 + * mount options/flags
27463 +#ifndef __AUFS_OPTS_H__
27464 +#define __AUFS_OPTS_H__
27468 +#include <linux/path.h>
27472 +/* ---------------------------------------------------------------------- */
27475 +#define AuOpt_XINO 1 /* external inode number bitmap
27476 + and translation table */
27477 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27478 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27479 +#define AuOpt_UDBA_REVAL (1 << 3)
27480 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27481 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27482 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27483 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27485 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27486 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27487 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27488 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27489 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27490 +#define AuOpt_DIO (1 << 14) /* direct io */
27491 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27493 +#ifndef CONFIG_AUFS_HNOTIFY
27494 +#undef AuOpt_UDBA_HNOTIFY
27495 +#define AuOpt_UDBA_HNOTIFY 0
27497 +#ifndef CONFIG_AUFS_DIRREN
27498 +#undef AuOpt_DIRREN
27499 +#define AuOpt_DIRREN 0
27501 +#ifndef CONFIG_AUFS_SHWH
27503 +#define AuOpt_SHWH 0
27506 +#define AuOpt_Def (AuOpt_XINO \
27507 + | AuOpt_UDBA_REVAL \
27509 + /* | AuOpt_DIRPERM1 */ \
27510 + | AuOpt_WARN_PERM)
27511 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27512 + | AuOpt_UDBA_REVAL \
27513 + | AuOpt_UDBA_HNOTIFY)
27515 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27516 +#define au_opt_set(flags, name) do { \
27517 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27518 + ((flags) |= AuOpt_##name); \
27520 +#define au_opt_set_udba(flags, name) do { \
27521 + (flags) &= ~AuOptMask_UDBA; \
27522 + ((flags) |= AuOpt_##name); \
27524 +#define au_opt_clr(flags, name) do { \
27525 + ((flags) &= ~AuOpt_##name); \
27528 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27530 +#ifdef CONFIG_PROC_FS
27533 + return mntflags & ~AuOpt_PLINK;
27537 +/* ---------------------------------------------------------------------- */
27539 +/* policies to select one among multiple writable branches */
27541 + AuWbrCreate_TDP, /* top down parent */
27542 + AuWbrCreate_RR, /* round robin */
27543 + AuWbrCreate_MFS, /* most free space */
27544 + AuWbrCreate_MFSV, /* mfs with seconds */
27545 + AuWbrCreate_MFSRR, /* mfs then rr */
27546 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27547 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27548 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27549 + AuWbrCreate_PMFS, /* parent and mfs */
27550 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27551 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27552 + AuWbrCreate_PMFSRRV, /* plus seconds */
27554 + AuWbrCreate_Def = AuWbrCreate_TDP
27558 + AuWbrCopyup_TDP, /* top down parent */
27559 + AuWbrCopyup_BUP, /* bottom up parent */
27560 + AuWbrCopyup_BU, /* bottom up */
27562 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27565 +/* ---------------------------------------------------------------------- */
27567 +struct au_opt_add {
27568 + aufs_bindex_t bindex;
27571 + struct path path;
27574 +struct au_opt_del {
27576 + struct path h_path;
27579 +struct au_opt_mod {
27582 + struct dentry *h_root;
27585 +struct au_opt_xino {
27587 + struct file *file;
27590 +struct au_opt_xino_itrunc {
27591 + aufs_bindex_t bindex;
27594 +struct au_opt_wbr_create {
27597 + unsigned long long mfsrr_watermark;
27603 + struct au_opt_xino xino;
27604 + struct au_opt_xino_itrunc xino_itrunc;
27605 + struct au_opt_add add;
27606 + struct au_opt_del del;
27607 + struct au_opt_mod mod;
27610 + unsigned int rdblk;
27611 + unsigned int rdhash;
27613 + struct au_opt_wbr_create wbr_create;
27615 + unsigned int fhsm_second;
27620 +#define AuOpts_REMOUNT 1
27621 +#define AuOpts_REFRESH (1 << 1)
27622 +#define AuOpts_TRUNC_XIB (1 << 2)
27623 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27624 +#define AuOpts_REFRESH_IDOP (1 << 4)
27625 +#define AuOpts_DR_FLUSHED (1 << 5)
27626 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27627 +#define au_fset_opts(flags, name) \
27628 + do { (flags) |= AuOpts_##name; } while (0)
27629 +#define au_fclr_opts(flags, name) \
27630 + do { (flags) &= ~AuOpts_##name; } while (0)
27632 +#ifndef CONFIG_AUFS_DIRREN
27633 +#undef AuOpts_DR_FLUSHED
27634 +#define AuOpts_DR_FLUSHED 0
27638 + struct au_opt *opt;
27641 + unsigned int given_udba;
27642 + unsigned int flags;
27643 + unsigned long sb_flags;
27646 +/* ---------------------------------------------------------------------- */
27649 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27650 +const char *au_optstr_udba(int udba);
27651 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27652 +const char *au_optstr_wbr_create(int wbr_create);
27654 +void au_opts_free(struct au_opts *opts);
27655 +struct super_block;
27656 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27657 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27658 + unsigned int pending);
27659 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27660 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27662 +unsigned int au_opt_udba(struct super_block *sb);
27664 +#endif /* __KERNEL__ */
27665 +#endif /* __AUFS_OPTS_H__ */
27666 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27667 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27668 +++ linux/fs/aufs/plink.c 2020-01-27 10:57:18.175538316 +0100
27670 +// SPDX-License-Identifier: GPL-2.0
27672 + * Copyright (C) 2005-2020 Junjiro R. Okajima
27674 + * This program, aufs is free software; you can redistribute it and/or modify
27675 + * it under the terms of the GNU General Public License as published by
27676 + * the Free Software Foundation; either version 2 of the License, or
27677 + * (at your option) any later version.
27679 + * This program is distributed in the hope that it will be useful,
27680 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27681 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27682 + * GNU General Public License for more details.
27684 + * You should have received a copy of the GNU General Public License
27685 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27695 + * the pseudo-link maintenance mode.
27696 + * during a user process maintains the pseudo-links,
27697 + * prohibit adding a new plink and branch manipulation.
27701 + * For entry functions which will handle plink, and i_mutex is already held
27703 + * They cannot wait and should return an error at once.
27704 + * Callers has to check the error.
27706 + * For entry functions which will handle plink, but i_mutex is not held
27708 + * They can wait the plink maintenance mode to finish.
27710 + * They behave like F_SETLK and F_SETLKW.
27711 + * If the caller never handle plink, then both flags are unnecessary.
27714 +int au_plink_maint(struct super_block *sb, int flags)
27718 + struct task_struct *parent, *prev;
27719 + struct au_sbinfo *sbi;
27721 + SiMustAnyLock(sb);
27724 + if (!au_opt_test(au_mntflags(sb), PLINK))
27727 + sbi = au_sbi(sb);
27728 + pid = sbi->si_plink_maint_pid;
27729 + if (!pid || pid == current->pid)
27732 + /* todo: it highly depends upon /sbin/mount.aufs */
27734 + parent = current;
27738 + parent = rcu_dereference(parent->real_parent);
27739 + if (parent == prev)
27741 + ppid = task_pid_vnr(parent);
27742 + if (pid == ppid) {
27743 + rcu_read_unlock();
27748 + rcu_read_unlock();
27750 + if (au_ftest_lock(flags, NOPLMW)) {
27751 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27752 + /* AuDebugOn(!lockdep_depth(current)); */
27753 + while (sbi->si_plink_maint_pid) {
27754 + si_read_unlock(sb);
27755 + /* gave up wake_up_bit() */
27756 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27758 + if (au_ftest_lock(flags, FLUSH))
27759 + au_nwt_flush(&sbi->si_nowait);
27760 + si_noflush_read_lock(sb);
27762 + } else if (au_ftest_lock(flags, NOPLM)) {
27763 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27771 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27773 + spin_lock(&sbinfo->si_plink_maint_lock);
27774 + sbinfo->si_plink_maint_pid = 0;
27775 + spin_unlock(&sbinfo->si_plink_maint_lock);
27776 + wake_up_all(&sbinfo->si_plink_wq);
27779 +int au_plink_maint_enter(struct super_block *sb)
27782 + struct au_sbinfo *sbinfo;
27785 + sbinfo = au_sbi(sb);
27786 + /* make sure i am the only one in this fs */
27787 + si_write_lock(sb, AuLock_FLUSH);
27788 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27789 + spin_lock(&sbinfo->si_plink_maint_lock);
27790 + if (!sbinfo->si_plink_maint_pid)
27791 + sbinfo->si_plink_maint_pid = current->pid;
27794 + spin_unlock(&sbinfo->si_plink_maint_lock);
27796 + si_write_unlock(sb);
27801 +/* ---------------------------------------------------------------------- */
27803 +#ifdef CONFIG_AUFS_DEBUG
27804 +void au_plink_list(struct super_block *sb)
27807 + struct au_sbinfo *sbinfo;
27808 + struct hlist_bl_head *hbl;
27809 + struct hlist_bl_node *pos;
27810 + struct au_icntnr *icntnr;
27812 + SiMustAnyLock(sb);
27814 + sbinfo = au_sbi(sb);
27815 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27816 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27818 + for (i = 0; i < AuPlink_NHASH; i++) {
27819 + hbl = sbinfo->si_plink + i;
27820 + hlist_bl_lock(hbl);
27821 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27822 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27823 + hlist_bl_unlock(hbl);
27828 +/* is the inode pseudo-linked? */
27829 +int au_plink_test(struct inode *inode)
27832 + struct au_sbinfo *sbinfo;
27833 + struct hlist_bl_head *hbl;
27834 + struct hlist_bl_node *pos;
27835 + struct au_icntnr *icntnr;
27837 + sbinfo = au_sbi(inode->i_sb);
27838 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27839 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27840 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27843 + i = au_plink_hash(inode->i_ino);
27844 + hbl = sbinfo->si_plink + i;
27845 + hlist_bl_lock(hbl);
27846 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27847 + if (&icntnr->vfs_inode == inode) {
27851 + hlist_bl_unlock(hbl);
27855 +/* ---------------------------------------------------------------------- */
27858 + * generate a name for plink.
27859 + * the file will be stored under AUFS_WH_PLINKDIR.
27861 +/* 20 is max digits length of ulong 64 */
27862 +#define PLINK_NAME_LEN ((20 + 1) * 2)
27864 +static int plink_name(char *name, int len, struct inode *inode,
27865 + aufs_bindex_t bindex)
27868 + struct inode *h_inode;
27870 + h_inode = au_h_iptr(inode, bindex);
27871 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
27875 +struct au_do_plink_lkup_args {
27876 + struct dentry **errp;
27877 + struct qstr *tgtname;
27878 + struct dentry *h_parent;
27879 + struct au_branch *br;
27882 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
27883 + struct dentry *h_parent,
27884 + struct au_branch *br)
27886 + struct dentry *h_dentry;
27887 + struct inode *h_inode;
27889 + h_inode = d_inode(h_parent);
27890 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
27891 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
27892 + inode_unlock_shared(h_inode);
27896 +static void au_call_do_plink_lkup(void *args)
27898 + struct au_do_plink_lkup_args *a = args;
27899 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
27902 +/* lookup the plink-ed @inode under the branch at @bindex */
27903 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
27905 + struct dentry *h_dentry, *h_parent;
27906 + struct au_branch *br;
27908 + char a[PLINK_NAME_LEN];
27909 + struct qstr tgtname = QSTR_INIT(a, 0);
27911 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27913 + br = au_sbr(inode->i_sb, bindex);
27914 + h_parent = br->br_wbr->wbr_plink;
27915 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27917 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27918 + struct au_do_plink_lkup_args args = {
27919 + .errp = &h_dentry,
27920 + .tgtname = &tgtname,
27921 + .h_parent = h_parent,
27925 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
27926 + if (unlikely(wkq_err))
27927 + h_dentry = ERR_PTR(wkq_err);
27929 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
27934 +/* create a pseudo-link */
27935 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
27936 + struct dentry *h_dentry, struct au_branch *br)
27939 + struct path h_path = {
27940 + .mnt = au_br_mnt(br)
27942 + struct inode *h_dir, *delegated;
27944 + h_dir = d_inode(h_parent);
27945 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
27947 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
27948 + err = PTR_ERR(h_path.dentry);
27949 + if (IS_ERR(h_path.dentry))
27953 + /* wh.plink dir is not monitored */
27954 + /* todo: is it really safe? */
27955 + if (d_is_positive(h_path.dentry)
27956 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
27957 + delegated = NULL;
27958 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
27959 + if (unlikely(err == -EWOULDBLOCK)) {
27960 + pr_warn("cannot retry for NFSv4 delegation"
27961 + " for an internal unlink\n");
27964 + dput(h_path.dentry);
27965 + h_path.dentry = NULL;
27969 + if (!err && d_is_negative(h_path.dentry)) {
27970 + delegated = NULL;
27971 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
27972 + if (unlikely(err == -EWOULDBLOCK)) {
27973 + pr_warn("cannot retry for NFSv4 delegation"
27974 + " for an internal link\n");
27978 + dput(h_path.dentry);
27981 + inode_unlock(h_dir);
27985 +struct do_whplink_args {
27987 + struct qstr *tgt;
27988 + struct dentry *h_parent;
27989 + struct dentry *h_dentry;
27990 + struct au_branch *br;
27993 +static void call_do_whplink(void *args)
27995 + struct do_whplink_args *a = args;
27996 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
27999 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28000 + aufs_bindex_t bindex, struct au_branch *br)
28002 + int err, wkq_err;
28003 + struct au_wbr *wbr;
28004 + struct dentry *h_parent;
28005 + char a[PLINK_NAME_LEN];
28006 + struct qstr tgtname = QSTR_INIT(a, 0);
28008 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
28009 + h_parent = wbr->wbr_plink;
28010 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28012 + /* always superio. */
28013 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28014 + struct do_whplink_args args = {
28017 + .h_parent = h_parent,
28018 + .h_dentry = h_dentry,
28021 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28022 + if (unlikely(wkq_err))
28025 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
28031 + * create a new pseudo-link for @h_dentry on @bindex.
28032 + * the linked inode is held in aufs @inode.
28034 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28035 + struct dentry *h_dentry)
28037 + struct super_block *sb;
28038 + struct au_sbinfo *sbinfo;
28039 + struct hlist_bl_head *hbl;
28040 + struct hlist_bl_node *pos;
28041 + struct au_icntnr *icntnr;
28042 + int found, err, cnt, i;
28044 + sb = inode->i_sb;
28045 + sbinfo = au_sbi(sb);
28046 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28047 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28049 + found = au_plink_test(inode);
28053 + i = au_plink_hash(inode->i_ino);
28054 + hbl = sbinfo->si_plink + i;
28057 + hlist_bl_lock(hbl);
28058 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28059 + if (&icntnr->vfs_inode == inode) {
28065 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28066 + hlist_bl_add_head(&icntnr->plink, hbl);
28068 + hlist_bl_unlock(hbl);
28070 + cnt = au_hbl_count(hbl);
28071 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28072 + if (cnt > AUFS_PLINK_WARN)
28073 + AuWarn1(msg ", %d\n", cnt);
28075 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
28076 + if (unlikely(err)) {
28077 + pr_warn("err %d, damaged pseudo link.\n", err);
28078 + au_hbl_del(&icntnr->plink, hbl);
28079 + iput(&icntnr->vfs_inode);
28082 + iput(&icntnr->vfs_inode);
28085 +/* free all plinks */
28086 +void au_plink_put(struct super_block *sb, int verbose)
28089 + struct au_sbinfo *sbinfo;
28090 + struct hlist_bl_head *hbl;
28091 + struct hlist_bl_node *pos, *tmp;
28092 + struct au_icntnr *icntnr;
28094 + SiMustWriteLock(sb);
28096 + sbinfo = au_sbi(sb);
28097 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28098 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28100 + /* no spin_lock since sbinfo is write-locked */
28102 + for (i = 0; i < AuPlink_NHASH; i++) {
28103 + hbl = sbinfo->si_plink + i;
28104 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28105 + pr_warn("pseudo-link is not flushed");
28108 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28109 + iput(&icntnr->vfs_inode);
28110 + INIT_HLIST_BL_HEAD(hbl);
28114 +void au_plink_clean(struct super_block *sb, int verbose)
28116 + struct dentry *root;
28118 + root = sb->s_root;
28119 + aufs_write_lock(root);
28120 + if (au_opt_test(au_mntflags(sb), PLINK))
28121 + au_plink_put(sb, verbose);
28122 + aufs_write_unlock(root);
28125 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28128 + aufs_bindex_t btop, bbot, bindex;
28131 + btop = au_ibtop(inode);
28132 + bbot = au_ibbot(inode);
28134 + for (bindex = btop; bindex <= bbot; bindex++) {
28135 + if (!au_h_iptr(inode, bindex)
28136 + || au_ii_br_id(inode, bindex) != br_id)
28138 + au_set_h_iptr(inode, bindex, NULL, 0);
28143 + for (bindex = btop; bindex <= bbot; bindex++)
28144 + if (au_h_iptr(inode, bindex)) {
28154 +/* free the plinks on a branch specified by @br_id */
28155 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28157 + struct au_sbinfo *sbinfo;
28158 + struct hlist_bl_head *hbl;
28159 + struct hlist_bl_node *pos, *tmp;
28160 + struct au_icntnr *icntnr;
28161 + struct inode *inode;
28164 + SiMustWriteLock(sb);
28166 + sbinfo = au_sbi(sb);
28167 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28168 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28170 + /* no bit_lock since sbinfo is write-locked */
28171 + for (i = 0; i < AuPlink_NHASH; i++) {
28172 + hbl = sbinfo->si_plink + i;
28173 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28174 + inode = au_igrab(&icntnr->vfs_inode);
28175 + ii_write_lock_child(inode);
28176 + do_put = au_plink_do_half_refresh(inode, br_id);
28178 + hlist_bl_del(&icntnr->plink);
28181 + ii_write_unlock(inode);
28186 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28187 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28188 +++ linux/fs/aufs/poll.c 2020-01-27 10:57:18.175538316 +0100
28190 +// SPDX-License-Identifier: GPL-2.0
28192 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28194 + * This program, aufs is free software; you can redistribute it and/or modify
28195 + * it under the terms of the GNU General Public License as published by
28196 + * the Free Software Foundation; either version 2 of the License, or
28197 + * (at your option) any later version.
28199 + * This program is distributed in the hope that it will be useful,
28200 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28201 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28202 + * GNU General Public License for more details.
28204 + * You should have received a copy of the GNU General Public License
28205 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28210 + * There is only one filesystem which implements ->poll operation, currently.
28215 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28218 + struct file *h_file;
28219 + struct super_block *sb;
28221 + /* We should pretend an error happened. */
28222 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28223 + sb = file->f_path.dentry->d_sb;
28224 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28226 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28227 + if (IS_ERR(h_file)) {
28228 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28232 + mask = vfs_poll(h_file, pt);
28233 + fput(h_file); /* instead of au_read_post() */
28236 + si_read_unlock(sb);
28237 + if (mask & EPOLLERR)
28238 + AuDbg("mask 0x%x\n", mask);
28241 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28242 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28243 +++ linux/fs/aufs/posix_acl.c 2020-01-27 10:57:18.175538316 +0100
28245 +// SPDX-License-Identifier: GPL-2.0
28247 + * Copyright (C) 2014-2020 Junjiro R. Okajima
28249 + * This program, aufs is free software; you can redistribute it and/or modify
28250 + * it under the terms of the GNU General Public License as published by
28251 + * the Free Software Foundation; either version 2 of the License, or
28252 + * (at your option) any later version.
28254 + * This program is distributed in the hope that it will be useful,
28255 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28256 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28257 + * GNU General Public License for more details.
28259 + * You should have received a copy of the GNU General Public License
28260 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28264 + * posix acl operations
28267 +#include <linux/fs.h>
28270 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28272 + struct posix_acl *acl;
28274 + aufs_bindex_t bindex;
28275 + struct inode *h_inode;
28276 + struct super_block *sb;
28279 + sb = inode->i_sb;
28280 + si_read_lock(sb, AuLock_FLUSH);
28281 + ii_read_lock_child(inode);
28282 + if (!(sb->s_flags & SB_POSIXACL))
28285 + bindex = au_ibtop(inode);
28286 + h_inode = au_h_iptr(inode, bindex);
28287 + if (unlikely(!h_inode
28288 + || ((h_inode->i_mode & S_IFMT)
28289 + != (inode->i_mode & S_IFMT)))) {
28290 + err = au_busy_or_stale();
28291 + acl = ERR_PTR(err);
28295 + /* always topmost only */
28296 + acl = get_acl(h_inode, type);
28298 + forget_cached_acl(inode, type);
28300 + set_cached_acl(inode, type, acl);
28303 + ii_read_unlock(inode);
28304 + si_read_unlock(sb);
28306 + AuTraceErrPtr(acl);
28310 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28314 + struct dentry *dentry;
28315 + struct au_sxattr arg = {
28316 + .type = AU_ACL_SET,
28323 + IMustLock(inode);
28325 + if (inode->i_ino == AUFS_ROOT_INO)
28326 + dentry = dget(inode->i_sb->s_root);
28328 + dentry = d_find_alias(inode);
28330 + dentry = d_find_any_alias(inode);
28332 + pr_warn("cannot handle this inode, "
28333 + "please report to aufs-users ML\n");
28339 + ssz = au_sxattr(dentry, inode, &arg);
28340 + /* forget even it if succeeds since the branch might set differently */
28341 + forget_cached_acl(inode, type);
28350 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28351 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28352 +++ linux/fs/aufs/procfs.c 2020-08-03 09:14:43.142321747 +0200
28354 +// SPDX-License-Identifier: GPL-2.0
28356 + * Copyright (C) 2010-2020 Junjiro R. Okajima
28358 + * This program, aufs is free software; you can redistribute it and/or modify
28359 + * it under the terms of the GNU General Public License as published by
28360 + * the Free Software Foundation; either version 2 of the License, or
28361 + * (at your option) any later version.
28363 + * This program is distributed in the hope that it will be useful,
28364 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28365 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28366 + * GNU General Public License for more details.
28368 + * You should have received a copy of the GNU General Public License
28369 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28373 + * procfs interfaces
28376 +#include <linux/proc_fs.h>
28379 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28381 + struct au_sbinfo *sbinfo;
28383 + sbinfo = file->private_data;
28385 + au_plink_maint_leave(sbinfo);
28386 + kobject_put(&sbinfo->si_kobj);
28392 +static void au_procfs_plm_write_clean(struct file *file)
28394 + struct au_sbinfo *sbinfo;
28396 + sbinfo = file->private_data;
28398 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28401 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28404 + struct super_block *sb;
28405 + struct au_sbinfo *sbinfo;
28406 + struct hlist_bl_node *pos;
28409 + if (unlikely(file->private_data))
28413 + /* don't use au_sbilist_lock() here */
28414 + hlist_bl_lock(&au_sbilist);
28415 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28416 + if (id == sysaufs_si_id(sbinfo)) {
28417 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28418 + sb = sbinfo->si_sb;
28421 + hlist_bl_unlock(&au_sbilist);
28424 + if (unlikely(!sb))
28427 + err = au_plink_maint_enter(sb);
28429 + /* keep kobject_get() */
28430 + file->private_data = sbinfo;
28432 + kobject_put(&sbinfo->si_kobj);
28438 + * Accept a valid "si=xxxx" only.
28439 + * Once it is accepted successfully, accept "clean" too.
28441 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28442 + size_t count, loff_t *ppos)
28445 + unsigned long id;
28446 + /* last newline is allowed */
28447 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28450 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28454 + if (unlikely(count > sizeof(buf)))
28457 + err = copy_from_user(buf, ubuf, count);
28458 + if (unlikely(err)) {
28465 + if (!strcmp("clean", buf)) {
28466 + au_procfs_plm_write_clean(file);
28467 + goto out_success;
28468 + } else if (unlikely(strncmp("si=", buf, 3)))
28471 + err = kstrtoul(buf + 3, 16, &id);
28472 + if (unlikely(err))
28475 + err = au_procfs_plm_write_si(file, id);
28476 + if (unlikely(err))
28480 + err = count; /* success */
28485 +static const struct proc_ops au_procfs_plm_op = {
28486 + .proc_write = au_procfs_plm_write,
28487 + .proc_release = au_procfs_plm_release
28490 +/* ---------------------------------------------------------------------- */
28492 +static struct proc_dir_entry *au_procfs_dir;
28494 +void au_procfs_fin(void)
28496 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28497 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28500 +int __init au_procfs_init(void)
28503 + struct proc_dir_entry *entry;
28506 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28507 + if (unlikely(!au_procfs_dir))
28510 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28511 + au_procfs_dir, &au_procfs_plm_op);
28512 + if (unlikely(!entry))
28516 + goto out; /* success */
28520 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28524 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28525 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28526 +++ linux/fs/aufs/rdu.c 2020-01-27 10:57:18.178871751 +0100
28528 +// SPDX-License-Identifier: GPL-2.0
28530 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28532 + * This program, aufs is free software; you can redistribute it and/or modify
28533 + * it under the terms of the GNU General Public License as published by
28534 + * the Free Software Foundation; either version 2 of the License, or
28535 + * (at your option) any later version.
28537 + * This program is distributed in the hope that it will be useful,
28538 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28539 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28540 + * GNU General Public License for more details.
28542 + * You should have received a copy of the GNU General Public License
28543 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28547 + * readdir in userspace.
28550 +#include <linux/compat.h>
28551 +#include <linux/fs_stack.h>
28552 +#include <linux/security.h>
28555 +/* bits for struct aufs_rdu.flags */
28556 +#define AuRdu_CALLED 1
28557 +#define AuRdu_CONT (1 << 1)
28558 +#define AuRdu_FULL (1 << 2)
28559 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28560 +#define au_fset_rdu(flags, name) \
28561 + do { (flags) |= AuRdu_##name; } while (0)
28562 +#define au_fclr_rdu(flags, name) \
28563 + do { (flags) &= ~AuRdu_##name; } while (0)
28565 +struct au_rdu_arg {
28566 + struct dir_context ctx;
28567 + struct aufs_rdu *rdu;
28568 + union au_rdu_ent_ul ent;
28569 + unsigned long end;
28571 + struct super_block *sb;
28575 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28576 + loff_t offset, u64 h_ino, unsigned int d_type)
28579 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28580 + struct aufs_rdu *rdu = arg->rdu;
28581 + struct au_rdu_ent ent;
28585 + au_fset_rdu(rdu->cookie.flags, CALLED);
28586 + len = au_rdu_len(nlen);
28587 + if (arg->ent.ul + len < arg->end) {
28589 + ent.bindex = rdu->cookie.bindex;
28590 + ent.type = d_type;
28592 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28593 + ent.type = DT_UNKNOWN;
28595 + /* unnecessary to support mmap_sem since this is a dir */
28597 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28599 + if (copy_to_user(arg->ent.e->name, name, nlen))
28601 + /* the terminating NULL */
28602 + if (__put_user(0, arg->ent.e->name + nlen))
28605 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28606 + arg->ent.ul += len;
28610 + au_fset_rdu(rdu->cookie.flags, FULL);
28612 + rdu->tail = arg->ent;
28616 + /* AuTraceErr(err); */
28620 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28624 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28626 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28627 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28629 + if (unlikely(offset != cookie->h_pos))
28635 + au_fclr_rdu(cookie->flags, CALLED);
28637 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28641 + && au_ftest_rdu(cookie->flags, CALLED)
28642 + && !au_ftest_rdu(cookie->flags, FULL));
28643 + cookie->h_pos = h_file->f_pos;
28650 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28653 + aufs_bindex_t bbot;
28654 + struct au_rdu_arg arg = {
28656 + .actor = au_rdu_fill
28659 + struct dentry *dentry;
28660 + struct inode *inode;
28661 + struct file *h_file;
28662 + struct au_rdu_cookie *cookie = &rdu->cookie;
28664 + /* VERIFY_WRITE */
28665 + err = !access_ok(rdu->ent.e, rdu->sz);
28666 + if (unlikely(err)) {
28672 + rdu->tail = rdu->ent;
28675 + arg.ent = rdu->ent;
28676 + arg.end = arg.ent.ul;
28677 + arg.end += rdu->sz;
28680 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28683 + err = security_file_permission(file, MAY_READ);
28685 + if (unlikely(err))
28688 + dentry = file->f_path.dentry;
28689 + inode = d_inode(dentry);
28690 + inode_lock_shared(inode);
28692 + arg.sb = inode->i_sb;
28693 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28694 + if (unlikely(err))
28696 + err = au_alive_dir(dentry);
28697 + if (unlikely(err))
28699 + /* todo: reval? */
28700 + fi_read_lock(file);
28703 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28704 + && cookie->generation != au_figen(file)))
28709 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28711 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28713 + bbot = au_fbtop(file);
28714 + if (cookie->bindex < bbot)
28715 + cookie->bindex = bbot;
28716 + bbot = au_fbbot_dir(file);
28717 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28718 + for (; !err && cookie->bindex <= bbot;
28719 + cookie->bindex++, cookie->h_pos = 0) {
28720 + h_file = au_hf_dir(file, cookie->bindex);
28724 + au_fclr_rdu(cookie->flags, FULL);
28725 + err = au_rdu_do(h_file, &arg);
28727 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28730 + AuDbg("rent %llu\n", rdu->rent);
28732 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28733 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28734 + au_fset_rdu(cookie->flags, CONT);
28735 + cookie->generation = au_figen(file);
28738 + ii_read_lock_child(inode);
28739 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28740 + ii_read_unlock(inode);
28743 + fi_read_unlock(file);
28745 + si_read_unlock(arg.sb);
28747 + inode_unlock_shared(inode);
28753 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28757 + unsigned long long nent;
28758 + union au_rdu_ent_ul *u;
28759 + struct au_rdu_ent ent;
28760 + struct super_block *sb;
28763 + nent = rdu->nent;
28765 + sb = file->f_path.dentry->d_sb;
28766 + si_read_lock(sb, AuLock_FLUSH);
28767 + while (nent-- > 0) {
28768 + /* unnecessary to support mmap_sem since this is a dir */
28769 + err = copy_from_user(&ent, u->e, sizeof(ent));
28771 + /* VERIFY_WRITE */
28772 + err = !access_ok(&u->e->ino, sizeof(ino));
28773 + if (unlikely(err)) {
28779 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28781 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28783 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28785 + if (unlikely(err)) {
28790 + err = __put_user(ino, &u->e->ino);
28791 + if (unlikely(err)) {
28796 + u->ul += au_rdu_len(ent.nlen);
28798 + si_read_unlock(sb);
28803 +/* ---------------------------------------------------------------------- */
28805 +static int au_rdu_verify(struct aufs_rdu *rdu)
28807 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28808 + "%llu, b%d, 0x%x, g%u}\n",
28809 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28811 + rdu->rent, rdu->shwh, rdu->full,
28812 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28813 + rdu->cookie.generation);
28815 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28819 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28823 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28826 + struct aufs_rdu rdu;
28827 + void __user *p = (void __user *)arg;
28829 + err = copy_from_user(&rdu, p, sizeof(rdu));
28830 + if (unlikely(err)) {
28835 + err = au_rdu_verify(&rdu);
28836 + if (unlikely(err))
28840 + case AUFS_CTL_RDU:
28841 + err = au_rdu(file, &rdu);
28842 + if (unlikely(err))
28845 + e = copy_to_user(p, &rdu, sizeof(rdu));
28846 + if (unlikely(e)) {
28851 + case AUFS_CTL_RDU_INO:
28852 + err = au_rdu_ino(file, &rdu);
28856 + /* err = -ENOTTY; */
28865 +#ifdef CONFIG_COMPAT
28866 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28869 + struct aufs_rdu rdu;
28870 + void __user *p = compat_ptr(arg);
28872 + /* todo: get_user()? */
28873 + err = copy_from_user(&rdu, p, sizeof(rdu));
28874 + if (unlikely(err)) {
28879 + rdu.ent.e = compat_ptr(rdu.ent.ul);
28880 + err = au_rdu_verify(&rdu);
28881 + if (unlikely(err))
28885 + case AUFS_CTL_RDU:
28886 + err = au_rdu(file, &rdu);
28887 + if (unlikely(err))
28890 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
28891 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
28892 + e = copy_to_user(p, &rdu, sizeof(rdu));
28893 + if (unlikely(e)) {
28898 + case AUFS_CTL_RDU_INO:
28899 + err = au_rdu_ino(file, &rdu);
28903 + /* err = -ENOTTY; */
28912 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
28913 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
28914 +++ linux/fs/aufs/rwsem.h 2020-01-27 10:57:18.178871751 +0100
28916 +/* SPDX-License-Identifier: GPL-2.0 */
28918 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28920 + * This program, aufs is free software; you can redistribute it and/or modify
28921 + * it under the terms of the GNU General Public License as published by
28922 + * the Free Software Foundation; either version 2 of the License, or
28923 + * (at your option) any later version.
28925 + * This program is distributed in the hope that it will be useful,
28926 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28927 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28928 + * GNU General Public License for more details.
28930 + * You should have received a copy of the GNU General Public License
28931 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28935 + * simple read-write semaphore wrappers
28938 +#ifndef __AUFS_RWSEM_H__
28939 +#define __AUFS_RWSEM_H__
28943 +#include "debug.h"
28945 +/* in the future, the name 'au_rwsem' will be totally gone */
28946 +#define au_rwsem rw_semaphore
28948 +/* to debug easier, do not make them inlined functions */
28949 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
28950 +/* rwsem_is_locked() is unusable */
28951 +#define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \
28953 + && !lockdep_is_held_type(rw, 1))
28954 +#define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \
28956 + && !lockdep_is_held_type(rw, 0))
28957 +#define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \
28959 + && !lockdep_is_held(rw))
28960 +#define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \
28962 + && lockdep_is_held(rw))
28964 +#define au_rw_init(rw) init_rwsem(rw)
28966 +#define au_rw_init_wlock(rw) do { \
28967 + au_rw_init(rw); \
28968 + down_write(rw); \
28971 +#define au_rw_init_wlock_nested(rw, lsc) do { \
28972 + au_rw_init(rw); \
28973 + down_write_nested(rw, lsc); \
28976 +#define au_rw_read_lock(rw) down_read(rw)
28977 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
28978 +#define au_rw_read_unlock(rw) up_read(rw)
28979 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
28980 +#define au_rw_write_lock(rw) down_write(rw)
28981 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
28982 +#define au_rw_write_unlock(rw) up_write(rw)
28983 +/* why is not _nested version defined? */
28984 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
28985 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
28987 +#endif /* __KERNEL__ */
28988 +#endif /* __AUFS_RWSEM_H__ */
28989 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
28990 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
28991 +++ linux/fs/aufs/sbinfo.c 2020-01-27 10:57:18.178871751 +0100
28993 +// SPDX-License-Identifier: GPL-2.0
28995 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28997 + * This program, aufs is free software; you can redistribute it and/or modify
28998 + * it under the terms of the GNU General Public License as published by
28999 + * the Free Software Foundation; either version 2 of the License, or
29000 + * (at your option) any later version.
29002 + * This program is distributed in the hope that it will be useful,
29003 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29004 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29005 + * GNU General Public License for more details.
29007 + * You should have received a copy of the GNU General Public License
29008 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29012 + * superblock private data
29015 +#include <linux/iversion.h>
29019 + * they are necessary regardless sysfs is disabled.
29021 +void au_si_free(struct kobject *kobj)
29024 + struct au_sbinfo *sbinfo;
29025 + char *locked __maybe_unused; /* debug only */
29027 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29028 + for (i = 0; i < AuPlink_NHASH; i++)
29029 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29030 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29032 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29033 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29034 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29035 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29037 + dbgaufs_si_fin(sbinfo);
29038 + au_rw_write_lock(&sbinfo->si_rwsem);
29039 + au_br_free(sbinfo);
29040 + au_rw_write_unlock(&sbinfo->si_rwsem);
29042 + au_kfree_try_rcu(sbinfo->si_branch);
29043 + mutex_destroy(&sbinfo->si_xib_mtx);
29044 + AuRwDestroy(&sbinfo->si_rwsem);
29046 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29047 + /* si_nfiles is waited too */
29048 + au_kfree_rcu(sbinfo);
29051 +int au_si_alloc(struct super_block *sb)
29054 + struct au_sbinfo *sbinfo;
29057 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29058 + if (unlikely(!sbinfo))
29061 + /* will be reallocated separately */
29062 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29063 + if (unlikely(!sbinfo->si_branch))
29066 + err = sysaufs_si_init(sbinfo);
29068 + dbgaufs_si_null(sbinfo);
29069 + err = dbgaufs_si_init(sbinfo);
29070 + if (unlikely(err))
29071 + kobject_put(&sbinfo->si_kobj);
29073 + if (unlikely(err))
29076 + au_nwt_init(&sbinfo->si_nowait);
29077 + au_rw_init_wlock(&sbinfo->si_rwsem);
29079 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29080 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29082 + sbinfo->si_bbot = -1;
29083 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29085 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29086 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29087 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29088 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29090 + au_fhsm_init(sbinfo);
29092 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29094 + sbinfo->si_xino_jiffy = jiffies;
29095 + sbinfo->si_xino_expire
29096 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29097 + mutex_init(&sbinfo->si_xib_mtx);
29098 + /* leave si_xib_last_pindex and si_xib_next_bit */
29100 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29102 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29103 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29104 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29105 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29107 + for (i = 0; i < AuPlink_NHASH; i++)
29108 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29109 + init_waitqueue_head(&sbinfo->si_plink_wq);
29110 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29112 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29114 + /* with getattr by default */
29115 + sbinfo->si_iop_array = aufs_iop;
29117 + /* leave other members for sysaufs and si_mnt. */
29118 + sbinfo->si_sb = sb;
29119 + sb->s_fs_info = sbinfo;
29121 + return 0; /* success */
29124 + au_kfree_try_rcu(sbinfo->si_branch);
29126 + au_kfree_rcu(sbinfo);
29131 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29134 + struct au_branch **brp;
29136 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29139 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29140 + if (unlikely(!sz))
29141 + sz = sizeof(*brp);
29142 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29145 + sbinfo->si_branch = brp;
29152 +/* ---------------------------------------------------------------------- */
29154 +unsigned int au_sigen_inc(struct super_block *sb)
29156 + unsigned int gen;
29157 + struct inode *inode;
29159 + SiMustWriteLock(sb);
29161 + gen = ++au_sbi(sb)->si_generation;
29162 + au_update_digen(sb->s_root);
29163 + inode = d_inode(sb->s_root);
29164 + au_update_iigen(inode, /*half*/0);
29165 + inode_inc_iversion(inode);
29169 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29171 + aufs_bindex_t br_id;
29173 + struct au_sbinfo *sbinfo;
29175 + SiMustWriteLock(sb);
29177 + sbinfo = au_sbi(sb);
29178 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29179 + br_id = ++sbinfo->si_last_br_id;
29180 + AuDebugOn(br_id < 0);
29181 + if (br_id && au_br_index(sb, br_id) < 0)
29188 +/* ---------------------------------------------------------------------- */
29190 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29191 +int si_read_lock(struct super_block *sb, int flags)
29196 + if (au_ftest_lock(flags, FLUSH))
29197 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29199 + si_noflush_read_lock(sb);
29200 + err = au_plink_maint(sb, flags);
29201 + if (unlikely(err))
29202 + si_read_unlock(sb);
29207 +int si_write_lock(struct super_block *sb, int flags)
29211 + if (au_ftest_lock(flags, FLUSH))
29212 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29214 + si_noflush_write_lock(sb);
29215 + err = au_plink_maint(sb, flags);
29216 + if (unlikely(err))
29217 + si_write_unlock(sb);
29222 +/* dentry and super_block lock. call at entry point */
29223 +int aufs_read_lock(struct dentry *dentry, int flags)
29226 + struct super_block *sb;
29228 + sb = dentry->d_sb;
29229 + err = si_read_lock(sb, flags);
29230 + if (unlikely(err))
29233 + if (au_ftest_lock(flags, DW))
29234 + di_write_lock_child(dentry);
29236 + di_read_lock_child(dentry, flags);
29238 + if (au_ftest_lock(flags, GEN)) {
29239 + err = au_digen_test(dentry, au_sigen(sb));
29240 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29241 + AuDebugOn(!err && au_dbrange_test(dentry));
29243 + err = au_dbrange_test(dentry);
29244 + if (unlikely(err))
29245 + aufs_read_unlock(dentry, flags);
29252 +void aufs_read_unlock(struct dentry *dentry, int flags)
29254 + if (au_ftest_lock(flags, DW))
29255 + di_write_unlock(dentry);
29257 + di_read_unlock(dentry, flags);
29258 + si_read_unlock(dentry->d_sb);
29261 +void aufs_write_lock(struct dentry *dentry)
29263 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29264 + di_write_lock_child(dentry);
29267 +void aufs_write_unlock(struct dentry *dentry)
29269 + di_write_unlock(dentry);
29270 + si_write_unlock(dentry->d_sb);
29273 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29276 + unsigned int sigen;
29277 + struct super_block *sb;
29280 + err = si_read_lock(sb, flags);
29281 + if (unlikely(err))
29284 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29286 + if (au_ftest_lock(flags, GEN)) {
29287 + sigen = au_sigen(sb);
29288 + err = au_digen_test(d1, sigen);
29289 + AuDebugOn(!err && au_dbrange_test(d1));
29291 + err = au_digen_test(d2, sigen);
29292 + AuDebugOn(!err && au_dbrange_test(d2));
29294 + if (unlikely(err))
29295 + aufs_read_and_write_unlock2(d1, d2);
29302 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29304 + di_write_unlock2(d1, d2);
29305 + si_read_unlock(d1->d_sb);
29307 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29308 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29309 +++ linux/fs/aufs/super.c 2020-01-27 10:57:18.178871751 +0100
29311 +// SPDX-License-Identifier: GPL-2.0
29313 + * Copyright (C) 2005-2020 Junjiro R. Okajima
29315 + * This program, aufs is free software; you can redistribute it and/or modify
29316 + * it under the terms of the GNU General Public License as published by
29317 + * the Free Software Foundation; either version 2 of the License, or
29318 + * (at your option) any later version.
29320 + * This program is distributed in the hope that it will be useful,
29321 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29322 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29323 + * GNU General Public License for more details.
29325 + * You should have received a copy of the GNU General Public License
29326 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29330 + * mount and super_block operations
29333 +#include <linux/iversion.h>
29334 +#include <linux/mm.h>
29335 +#include <linux/seq_file.h>
29336 +#include <linux/statfs.h>
29337 +#include <linux/vmalloc.h>
29341 + * super_operations
29343 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29345 + struct au_icntnr *c;
29347 + c = au_cache_alloc_icntnr();
29349 + au_icntnr_init(c);
29350 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29351 + c->iinfo.ii_hinode = NULL;
29352 + return &c->vfs_inode;
29357 +static void aufs_destroy_inode(struct inode *inode)
29359 + if (!au_is_bad_inode(inode))
29360 + au_iinfo_fin(inode);
29363 +static void aufs_free_inode(struct inode *inode)
29365 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29368 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29370 + struct inode *inode;
29373 + inode = iget_locked(sb, ino);
29374 + if (unlikely(!inode)) {
29375 + inode = ERR_PTR(-ENOMEM);
29378 + if (!(inode->i_state & I_NEW))
29381 + err = au_xigen_new(inode);
29383 + err = au_iinfo_init(inode);
29385 + inode_inc_iversion(inode);
29387 + iget_failed(inode);
29388 + inode = ERR_PTR(err);
29392 + /* never return NULL */
29393 + AuDebugOn(!inode);
29394 + AuTraceErrPtr(inode);
29398 +/* lock free root dinfo */
29399 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29402 + aufs_bindex_t bindex, bbot;
29403 + struct path path;
29404 + struct au_hdentry *hdp;
29405 + struct au_branch *br;
29406 + au_br_perm_str_t perm;
29409 + bbot = au_sbbot(sb);
29411 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29412 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29413 + br = au_sbr(sb, bindex);
29414 + path.mnt = au_br_mnt(br);
29415 + path.dentry = hdp->hd_dentry;
29416 + err = au_seq_path(seq, &path);
29418 + au_optstr_br_perm(&perm, br->br_perm);
29419 + seq_printf(seq, "=%s", perm.a);
29420 + if (bindex != bbot)
29421 + seq_putc(seq, ':');
29424 + if (unlikely(err || seq_has_overflowed(seq)))
29430 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29431 + const char *append)
29436 + while (*pat != ':')
29439 + strcpy(p, append);
29440 + AuDebugOn(strlen(fmt) >= len);
29443 +static void au_show_wbr_create(struct seq_file *m, int v,
29444 + struct au_sbinfo *sbinfo)
29448 + struct au_wbr_mfs *mfs;
29450 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29452 + seq_puts(m, ",create=");
29453 + pat = au_optstr_wbr_create(v);
29454 + mfs = &sbinfo->si_wbr_mfs;
29456 + case AuWbrCreate_TDP:
29457 + case AuWbrCreate_RR:
29458 + case AuWbrCreate_MFS:
29459 + case AuWbrCreate_PMFS:
29460 + seq_puts(m, pat);
29462 + case AuWbrCreate_MFSRR:
29463 + case AuWbrCreate_TDMFS:
29464 + case AuWbrCreate_PMFSRR:
29465 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29466 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29468 + case AuWbrCreate_MFSV:
29469 + case AuWbrCreate_PMFSV:
29470 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29471 + seq_printf(m, fmt,
29472 + jiffies_to_msecs(mfs->mfs_expire)
29475 + case AuWbrCreate_MFSRRV:
29476 + case AuWbrCreate_TDMFSV:
29477 + case AuWbrCreate_PMFSRRV:
29478 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29479 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29480 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29487 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29489 +#ifdef CONFIG_SYSFS
29493 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29494 + aufs_bindex_t bindex, brid;
29495 + struct qstr *name;
29497 + struct dentry *d, *h_root;
29498 + struct au_branch *br;
29500 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29503 + f = au_sbi(sb)->si_xib;
29507 + /* stop printing the default xino path on the first writable branch */
29509 + bindex = au_xi_root(sb, f->f_path.dentry);
29510 + if (bindex >= 0) {
29511 + br = au_sbr_sb(sb, bindex);
29512 + h_root = au_br_dentry(br);
29515 + d = f->f_path.dentry;
29516 + name = &d->d_name;
29517 + /* safe ->d_parent because the file is unlinked */
29518 + if (d->d_parent == h_root
29519 + && name->len == len
29520 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29523 + seq_puts(seq, ",xino=");
29524 + err = au_xino_path(seq, f);
29531 +/* seq_file will re-call me in case of too long string */
29532 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29535 + unsigned int mnt_flags, v;
29536 + struct super_block *sb;
29537 + struct au_sbinfo *sbinfo;
29539 +#define AuBool(name, str) do { \
29540 + v = au_opt_test(mnt_flags, name); \
29541 + if (v != au_opt_test(AuOpt_Def, name)) \
29542 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29545 +#define AuStr(name, str) do { \
29546 + v = mnt_flags & AuOptMask_##name; \
29547 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29548 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29551 +#define AuUInt(name, str, val) do { \
29552 + if (val != AUFS_##name##_DEF) \
29553 + seq_printf(m, "," #str "=%u", val); \
29556 + sb = dentry->d_sb;
29557 + if (sb->s_flags & SB_POSIXACL)
29558 + seq_puts(m, ",acl");
29559 +#if 0 /* reserved for future use */
29560 + if (sb->s_flags & SB_I_VERSION)
29561 + seq_puts(m, ",i_version");
29564 + /* lock free root dinfo */
29565 + si_noflush_read_lock(sb);
29566 + sbinfo = au_sbi(sb);
29567 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29569 + mnt_flags = au_mntflags(sb);
29570 + if (au_opt_test(mnt_flags, XINO)) {
29571 + err = au_show_xino(m, sb);
29572 + if (unlikely(err))
29575 + seq_puts(m, ",noxino");
29577 + AuBool(TRUNC_XINO, trunc_xino);
29578 + AuStr(UDBA, udba);
29579 + AuBool(SHWH, shwh);
29580 + AuBool(PLINK, plink);
29581 + AuBool(DIO, dio);
29582 + AuBool(DIRPERM1, dirperm1);
29584 + v = sbinfo->si_wbr_create;
29585 + if (v != AuWbrCreate_Def)
29586 + au_show_wbr_create(m, v, sbinfo);
29588 + v = sbinfo->si_wbr_copyup;
29589 + if (v != AuWbrCopyup_Def)
29590 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29592 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29593 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29594 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29596 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29598 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29599 + AuUInt(RDCACHE, rdcache, v);
29601 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29602 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29604 + au_fhsm_show(m, sbinfo);
29606 + AuBool(DIRREN, dirren);
29607 + AuBool(SUM, sum);
29608 + /* AuBool(SUM_W, wsum); */
29609 + AuBool(WARN_PERM, warn_perm);
29610 + AuBool(VERBOSE, verbose);
29613 + /* be sure to print "br:" last */
29614 + if (!sysaufs_brs) {
29615 + seq_puts(m, ",br:");
29616 + au_show_brs(m, sb);
29618 + si_read_unlock(sb);
29626 +/* ---------------------------------------------------------------------- */
29628 +/* sum mode which returns the summation for statfs(2) */
29630 +static u64 au_add_till_max(u64 a, u64 b)
29638 + return ULLONG_MAX;
29641 +static u64 au_mul_till_max(u64 a, long mul)
29649 + return ULLONG_MAX;
29652 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29655 + long bsize, factor;
29656 + u64 blocks, bfree, bavail, files, ffree;
29657 + aufs_bindex_t bbot, bindex, i;
29658 + unsigned char shared;
29659 + struct path h_path;
29660 + struct super_block *h_sb;
29663 + bsize = LONG_MAX;
29669 + bbot = au_sbbot(sb);
29670 + for (bindex = 0; bindex <= bbot; bindex++) {
29671 + h_path.mnt = au_sbr_mnt(sb, bindex);
29672 + h_sb = h_path.mnt->mnt_sb;
29674 + for (i = 0; !shared && i < bindex; i++)
29675 + shared = (au_sbr_sb(sb, i) == h_sb);
29679 + /* sb->s_root for NFS is unreliable */
29680 + h_path.dentry = h_path.mnt->mnt_root;
29681 + err = vfs_statfs(&h_path, buf);
29682 + if (unlikely(err))
29685 + if (bsize > buf->f_bsize) {
29687 + * we will reduce bsize, so we have to expand blocks
29688 + * etc. to match them again
29690 + factor = (bsize / buf->f_bsize);
29691 + blocks = au_mul_till_max(blocks, factor);
29692 + bfree = au_mul_till_max(bfree, factor);
29693 + bavail = au_mul_till_max(bavail, factor);
29694 + bsize = buf->f_bsize;
29697 + factor = (buf->f_bsize / bsize);
29698 + blocks = au_add_till_max(blocks,
29699 + au_mul_till_max(buf->f_blocks, factor));
29700 + bfree = au_add_till_max(bfree,
29701 + au_mul_till_max(buf->f_bfree, factor));
29702 + bavail = au_add_till_max(bavail,
29703 + au_mul_till_max(buf->f_bavail, factor));
29704 + files = au_add_till_max(files, buf->f_files);
29705 + ffree = au_add_till_max(ffree, buf->f_ffree);
29708 + buf->f_bsize = bsize;
29709 + buf->f_blocks = blocks;
29710 + buf->f_bfree = bfree;
29711 + buf->f_bavail = bavail;
29712 + buf->f_files = files;
29713 + buf->f_ffree = ffree;
29714 + buf->f_frsize = 0;
29720 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29723 + struct path h_path;
29724 + struct super_block *sb;
29726 + /* lock free root dinfo */
29727 + sb = dentry->d_sb;
29728 + si_noflush_read_lock(sb);
29729 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29730 + /* sb->s_root for NFS is unreliable */
29731 + h_path.mnt = au_sbr_mnt(sb, 0);
29732 + h_path.dentry = h_path.mnt->mnt_root;
29733 + err = vfs_statfs(&h_path, buf);
29735 + err = au_statfs_sum(sb, buf);
29736 + si_read_unlock(sb);
29739 + buf->f_type = AUFS_SUPER_MAGIC;
29740 + buf->f_namelen = AUFS_MAX_NAMELEN;
29741 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29743 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29748 +/* ---------------------------------------------------------------------- */
29750 +static int aufs_sync_fs(struct super_block *sb, int wait)
29753 + aufs_bindex_t bbot, bindex;
29754 + struct au_branch *br;
29755 + struct super_block *h_sb;
29758 + si_noflush_read_lock(sb);
29759 + bbot = au_sbbot(sb);
29760 + for (bindex = 0; bindex <= bbot; bindex++) {
29761 + br = au_sbr(sb, bindex);
29762 + if (!au_br_writable(br->br_perm))
29765 + h_sb = au_sbr_sb(sb, bindex);
29766 + e = vfsub_sync_filesystem(h_sb, wait);
29767 + if (unlikely(e && !err))
29769 + /* go on even if an error happens */
29771 + si_read_unlock(sb);
29776 +/* ---------------------------------------------------------------------- */
29778 +/* final actions when unmounting a file system */
29779 +static void aufs_put_super(struct super_block *sb)
29781 + struct au_sbinfo *sbinfo;
29783 + sbinfo = au_sbi(sb);
29785 + kobject_put(&sbinfo->si_kobj);
29788 +/* ---------------------------------------------------------------------- */
29790 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29791 + struct super_block *sb, void *arg)
29794 + unsigned long long n, sz;
29801 + if (*hint > ULLONG_MAX / sizeof(array)) {
29802 + array = ERR_PTR(-EMFILE);
29803 + pr_err("hint %llu\n", *hint);
29807 + sz = sizeof(array) * *hint;
29808 + array = kzalloc(sz, GFP_NOFS);
29809 + if (unlikely(!array))
29810 + array = vzalloc(sz);
29811 + if (unlikely(!array)) {
29812 + array = ERR_PTR(-ENOMEM);
29816 + n = cb(sb, array, *hint, arg);
29817 + AuDebugOn(n > *hint);
29824 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29825 + unsigned long long max __maybe_unused,
29828 + unsigned long long n;
29829 + struct inode **p, *inode;
29830 + struct list_head *head;
29835 + spin_lock(&sb->s_inode_list_lock);
29836 + list_for_each_entry(inode, head, i_sb_list) {
29837 + if (!au_is_bad_inode(inode)
29838 + && au_ii(inode)->ii_btop >= 0) {
29839 + spin_lock(&inode->i_lock);
29840 + if (atomic_read(&inode->i_count)) {
29844 + AuDebugOn(n > max);
29846 + spin_unlock(&inode->i_lock);
29849 + spin_unlock(&sb->s_inode_list_lock);
29854 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
29856 + struct au_sbinfo *sbi;
29858 + sbi = au_sbi(sb);
29859 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
29860 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
29863 +void au_iarray_free(struct inode **a, unsigned long long max)
29865 + unsigned long long ull;
29867 + for (ull = 0; ull < max; ull++)
29872 +/* ---------------------------------------------------------------------- */
29875 + * refresh dentry and inode at remount time.
29877 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
29878 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
29879 + struct dentry *parent)
29883 + di_write_lock_child(dentry);
29884 + di_read_lock_parent(parent, AuLock_IR);
29885 + err = au_refresh_dentry(dentry, parent);
29886 + if (!err && dir_flags)
29887 + au_hn_reset(d_inode(dentry), dir_flags);
29888 + di_read_unlock(parent, AuLock_IR);
29889 + di_write_unlock(dentry);
29894 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
29895 + struct au_sbinfo *sbinfo,
29896 + const unsigned int dir_flags, unsigned int do_idop)
29899 + struct dentry *parent;
29902 + parent = dget_parent(dentry);
29903 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
29904 + if (d_really_is_positive(dentry)) {
29905 + if (!d_is_dir(dentry))
29906 + err = au_do_refresh(dentry, /*dir_flags*/0,
29909 + err = au_do_refresh(dentry, dir_flags, parent);
29910 + if (unlikely(err))
29911 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
29914 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
29915 + AuDbgDentry(dentry);
29921 + au_refresh_dop(dentry, /*force_reval*/0);
29923 + au_refresh_dop(dentry, /*force_reval*/1);
29929 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
29931 + int err, i, j, ndentry, e;
29932 + unsigned int sigen;
29933 + struct au_dcsub_pages dpages;
29934 + struct au_dpage *dpage;
29935 + struct dentry **dentries, *d;
29936 + struct au_sbinfo *sbinfo;
29937 + struct dentry *root = sb->s_root;
29938 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
29941 + au_refresh_dop(root, /*force_reval*/0);
29943 + err = au_dpages_init(&dpages, GFP_NOFS);
29944 + if (unlikely(err))
29946 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
29947 + if (unlikely(err))
29950 + sigen = au_sigen(sb);
29951 + sbinfo = au_sbi(sb);
29952 + for (i = 0; i < dpages.ndpage; i++) {
29953 + dpage = dpages.dpages + i;
29954 + dentries = dpage->dentries;
29955 + ndentry = dpage->ndentry;
29956 + for (j = 0; j < ndentry; j++) {
29958 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
29960 + if (unlikely(e && !err))
29962 + /* go on even err */
29967 + au_dpages_free(&dpages);
29972 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
29975 + unsigned int sigen;
29976 + unsigned long long max, ull;
29977 + struct inode *inode, **array;
29979 + array = au_iarray_alloc(sb, &max);
29980 + err = PTR_ERR(array);
29981 + if (IS_ERR(array))
29985 + sigen = au_sigen(sb);
29986 + for (ull = 0; ull < max; ull++) {
29987 + inode = array[ull];
29988 + if (unlikely(!inode))
29992 + ii_write_lock_child(inode);
29993 + if (au_iigen(inode, NULL) != sigen) {
29994 + e = au_refresh_hinode_self(inode);
29995 + if (unlikely(e)) {
29996 + au_refresh_iop(inode, /*force_getattr*/1);
29997 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30000 + /* go on even if err */
30003 + if (!e && do_idop)
30004 + au_refresh_iop(inode, /*force_getattr*/0);
30005 + ii_write_unlock(inode);
30008 + au_iarray_free(array, max);
30014 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30017 + unsigned int udba;
30018 + aufs_bindex_t bindex, bbot;
30019 + struct dentry *root;
30020 + struct inode *inode;
30021 + struct au_branch *br;
30022 + struct au_sbinfo *sbi;
30024 + au_sigen_inc(sb);
30025 + sbi = au_sbi(sb);
30026 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30028 + root = sb->s_root;
30029 + DiMustNoWaiters(root);
30030 + inode = d_inode(root);
30031 + IiMustNoWaiters(inode);
30033 + udba = au_opt_udba(sb);
30034 + bbot = au_sbbot(sb);
30035 + for (bindex = 0; bindex <= bbot; bindex++) {
30036 + br = au_sbr(sb, bindex);
30037 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30038 + if (unlikely(err))
30039 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30041 + /* go on even if err */
30043 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30046 + if (au_ftest_si(sbi, NO_DREVAL)) {
30047 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30048 + sb->s_d_op = &aufs_dop_noreval;
30049 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30050 + sbi->si_iop_array = aufs_iop_nogetattr;
30052 + AuDebugOn(sb->s_d_op == &aufs_dop);
30053 + sb->s_d_op = &aufs_dop;
30054 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30055 + sbi->si_iop_array = aufs_iop;
30057 + pr_info("reset to %ps and %ps\n",
30058 + sb->s_d_op, sbi->si_iop_array);
30061 + di_write_unlock(root);
30062 + err = au_refresh_d(sb, do_idop);
30063 + e = au_refresh_i(sb, do_idop);
30064 + if (unlikely(e && !err))
30066 + /* aufs_write_lock() calls ..._child() */
30067 + di_write_lock_child(root);
30069 + au_cpup_attr_all(inode, /*force*/1);
30071 + if (unlikely(err))
30072 + AuIOErr("refresh failed, ignored, %d\n", err);
30075 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30076 +static int cvt_err(int err)
30090 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30093 + unsigned int mntflags;
30094 + struct au_opts opts = {
30097 + struct dentry *root;
30098 + struct inode *inode;
30099 + struct au_sbinfo *sbinfo;
30102 + root = sb->s_root;
30103 + if (!data || !*data) {
30104 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30106 + di_write_lock_child(root);
30107 + err = au_opts_verify(sb, *flags, /*pending*/0);
30108 + aufs_write_unlock(root);
30114 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30115 + if (unlikely(!opts.opt))
30117 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30118 + opts.flags = AuOpts_REMOUNT;
30119 + opts.sb_flags = *flags;
30121 + /* parse it before aufs lock */
30122 + err = au_opts_parse(sb, data, &opts);
30123 + if (unlikely(err))
30126 + sbinfo = au_sbi(sb);
30127 + inode = d_inode(root);
30128 + inode_lock(inode);
30129 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30130 + if (unlikely(err))
30132 + di_write_lock_child(root);
30134 + /* au_opts_remount() may return an error */
30135 + err = au_opts_remount(sb, &opts);
30136 + au_opts_free(&opts);
30138 + if (au_ftest_opts(opts.flags, REFRESH))
30139 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30141 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30142 + mntflags = au_mntflags(sb);
30143 + do_dx = !!au_opt_test(mntflags, DIO);
30144 + au_dy_arefresh(do_dx);
30147 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30148 + aufs_write_unlock(root);
30151 + inode_unlock(inode);
30153 + free_page((unsigned long)opts.opt);
30155 + err = cvt_err(err);
30160 +static const struct super_operations aufs_sop = {
30161 + .alloc_inode = aufs_alloc_inode,
30162 + .destroy_inode = aufs_destroy_inode,
30163 + .free_inode = aufs_free_inode,
30164 + /* always deleting, no clearing */
30165 + .drop_inode = generic_delete_inode,
30166 + .show_options = aufs_show_options,
30167 + .statfs = aufs_statfs,
30168 + .put_super = aufs_put_super,
30169 + .sync_fs = aufs_sync_fs,
30170 + .remount_fs = aufs_remount_fs
30173 +/* ---------------------------------------------------------------------- */
30175 +static int alloc_root(struct super_block *sb)
30178 + struct inode *inode;
30179 + struct dentry *root;
30182 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30183 + err = PTR_ERR(inode);
30184 + if (IS_ERR(inode))
30187 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30188 + inode->i_fop = &aufs_dir_fop;
30189 + inode->i_mode = S_IFDIR;
30190 + set_nlink(inode, 2);
30191 + unlock_new_inode(inode);
30193 + root = d_make_root(inode);
30194 + if (unlikely(!root))
30196 + err = PTR_ERR(root);
30197 + if (IS_ERR(root))
30200 + err = au_di_init(root);
30202 + sb->s_root = root;
30203 + return 0; /* success */
30211 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30212 + int silent __maybe_unused)
30215 + struct au_opts opts = {
30218 + struct au_sbinfo *sbinfo;
30219 + struct dentry *root;
30220 + struct inode *inode;
30221 + char *arg = raw_data;
30223 + if (unlikely(!arg || !*arg)) {
30225 + pr_err("no arg\n");
30230 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30231 + if (unlikely(!opts.opt))
30233 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30234 + opts.sb_flags = sb->s_flags;
30236 + err = au_si_alloc(sb);
30237 + if (unlikely(err))
30239 + sbinfo = au_sbi(sb);
30241 + /* all timestamps always follow the ones on the branch */
30242 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30243 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30244 + sb->s_op = &aufs_sop;
30245 + sb->s_d_op = &aufs_dop;
30246 + sb->s_magic = AUFS_SUPER_MAGIC;
30247 + sb->s_maxbytes = 0;
30248 + sb->s_stack_depth = 1;
30249 + au_export_init(sb);
30250 + au_xattr_init(sb);
30252 + err = alloc_root(sb);
30253 + if (unlikely(err)) {
30254 + si_write_unlock(sb);
30257 + root = sb->s_root;
30258 + inode = d_inode(root);
30261 + * actually we can parse options regardless aufs lock here.
30262 + * but at remount time, parsing must be done before aufs lock.
30263 + * so we follow the same rule.
30265 + ii_write_lock_parent(inode);
30266 + aufs_write_unlock(root);
30267 + err = au_opts_parse(sb, arg, &opts);
30268 + if (unlikely(err))
30271 + /* lock vfs_inode first, then aufs. */
30272 + inode_lock(inode);
30273 + aufs_write_lock(root);
30274 + err = au_opts_mount(sb, &opts);
30275 + au_opts_free(&opts);
30276 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30277 + sb->s_d_op = &aufs_dop_noreval;
30278 + pr_info("%ps\n", sb->s_d_op);
30279 + au_refresh_dop(root, /*force_reval*/0);
30280 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30281 + au_refresh_iop(inode, /*force_getattr*/0);
30283 + aufs_write_unlock(root);
30284 + inode_unlock(inode);
30286 + goto out_opts; /* success */
30290 + sb->s_root = NULL;
30292 + kobject_put(&sbinfo->si_kobj);
30293 + sb->s_fs_info = NULL;
30295 + free_page((unsigned long)opts.opt);
30298 + err = cvt_err(err);
30303 +/* ---------------------------------------------------------------------- */
30305 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30306 + const char *dev_name __maybe_unused,
30309 + struct dentry *root;
30311 + /* all timestamps always follow the ones on the branch */
30312 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30313 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30314 + if (IS_ERR(root))
30317 + au_sbilist_add(root->d_sb);
30323 +static void aufs_kill_sb(struct super_block *sb)
30325 + struct au_sbinfo *sbinfo;
30327 + sbinfo = au_sbi(sb);
30329 + au_sbilist_del(sb);
30330 + aufs_write_lock(sb->s_root);
30332 + if (sbinfo->si_wbr_create_ops->fin)
30333 + sbinfo->si_wbr_create_ops->fin(sb);
30334 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30335 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30336 + au_remount_refresh(sb, /*do_idop*/0);
30338 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30339 + au_plink_put(sb, /*verbose*/1);
30341 + au_dr_opt_flush(sb);
30342 + sbinfo->si_sb = NULL;
30343 + aufs_write_unlock(sb->s_root);
30344 + au_nwt_flush(&sbinfo->si_nowait);
30346 + kill_anon_super(sb);
30349 +struct file_system_type aufs_fs_type = {
30350 + .name = AUFS_FSTYPE,
30351 + /* a race between rename and others */
30352 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30353 + .mount = aufs_mount,
30354 + .kill_sb = aufs_kill_sb,
30355 + /* no need to __module_get() and module_put(). */
30356 + .owner = THIS_MODULE,
30358 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30359 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30360 +++ linux/fs/aufs/super.h 2020-12-15 14:10:58.918023162 +0100
30362 +/* SPDX-License-Identifier: GPL-2.0 */
30364 + * Copyright (C) 2005-2020 Junjiro R. Okajima
30366 + * This program, aufs is free software; you can redistribute it and/or modify
30367 + * it under the terms of the GNU General Public License as published by
30368 + * the Free Software Foundation; either version 2 of the License, or
30369 + * (at your option) any later version.
30371 + * This program is distributed in the hope that it will be useful,
30372 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30373 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30374 + * GNU General Public License for more details.
30376 + * You should have received a copy of the GNU General Public License
30377 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30381 + * super_block operations
30384 +#ifndef __AUFS_SUPER_H__
30385 +#define __AUFS_SUPER_H__
30389 +#include <linux/fs.h>
30390 +#include <linux/kobject.h>
30393 +#include "rwsem.h"
30396 +/* policies to select one among multiple writable branches */
30397 +struct au_wbr_copyup_operations {
30398 + int (*copyup)(struct dentry *dentry);
30401 +#define AuWbr_DIR 1 /* target is a dir */
30402 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30404 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30405 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30406 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30408 +struct au_wbr_create_operations {
30409 + int (*create)(struct dentry *dentry, unsigned int flags);
30410 + int (*init)(struct super_block *sb);
30411 + int (*fin)(struct super_block *sb);
30414 +struct au_wbr_mfs {
30415 + struct mutex mfs_lock; /* protect this structure */
30416 + unsigned long mfs_jiffy;
30417 + unsigned long mfs_expire;
30418 + aufs_bindex_t mfs_bindex;
30420 + unsigned long long mfsrr_bytes;
30421 + unsigned long long mfsrr_watermark;
30424 +#define AuPlink_NHASH 100
30425 +static inline int au_plink_hash(ino_t ino)
30427 + return ino % AuPlink_NHASH;
30430 +/* File-based Hierarchical Storage Management */
30432 +#ifdef CONFIG_AUFS_FHSM
30433 + /* allow only one process who can receive the notification */
30434 + spinlock_t fhsm_spin;
30436 + wait_queue_head_t fhsm_wqh;
30437 + atomic_t fhsm_readable;
30439 + /* these are protected by si_rwsem */
30440 + unsigned long fhsm_expire;
30441 + aufs_bindex_t fhsm_bottom;
30446 +struct au_sbinfo {
30447 + /* nowait tasks in the system-wide workqueue */
30448 + struct au_nowait_tasks si_nowait;
30451 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30452 + * rwsem for au_sbinfo is necessary.
30454 + struct au_rwsem si_rwsem;
30457 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30460 + au_lcnt_t si_ninodes, si_nfiles;
30462 + /* branch management */
30463 + unsigned int si_generation;
30465 + /* see AuSi_ flags */
30466 + unsigned char au_si_status;
30468 + aufs_bindex_t si_bbot;
30470 + /* dirty trick to keep br_id plus */
30471 + unsigned int si_last_br_id :
30472 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30473 + struct au_branch **si_branch;
30475 + /* policy to select a writable branch */
30476 + unsigned char si_wbr_copyup;
30477 + unsigned char si_wbr_create;
30478 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30479 + struct au_wbr_create_operations *si_wbr_create_ops;
30481 + /* round robin */
30482 + atomic_t si_wbr_rr_next;
30484 + /* most free space */
30485 + struct au_wbr_mfs si_wbr_mfs;
30487 + /* File-based Hierarchical Storage Management */
30488 + struct au_fhsm si_fhsm;
30490 + /* mount flags */
30491 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30492 + unsigned int si_mntflags;
30494 + /* external inode number (bitmap and translation table) */
30495 + loff_t si_ximaxent; /* max entries in a xino */
30497 + struct file *si_xib;
30498 + struct mutex si_xib_mtx; /* protect xib members */
30499 + unsigned long *si_xib_buf;
30500 + unsigned long si_xib_last_pindex;
30501 + int si_xib_next_bit;
30503 + unsigned long si_xino_jiffy;
30504 + unsigned long si_xino_expire;
30505 + /* reserved for future use */
30506 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30508 +#ifdef CONFIG_AUFS_EXPORT
30509 + /* i_generation */
30510 + /* todo: make xigen file an array to support many inode numbers */
30511 + struct file *si_xigen;
30512 + atomic_t si_xigen_next;
30515 + /* dirty trick to support atomic_open */
30516 + struct hlist_bl_head si_aopen;
30518 + /* vdir parameters */
30519 + unsigned long si_rdcache; /* max cache time in jiffies */
30520 + unsigned int si_rdblk; /* deblk size */
30521 + unsigned int si_rdhash; /* hash size */
30524 + * If the number of whiteouts are larger than si_dirwh, leave all of
30525 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30526 + * future fsck.aufs or kernel thread will remove them later.
30527 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30529 + unsigned int si_dirwh;
30531 + /* pseudo_link list */
30532 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30533 + wait_queue_head_t si_plink_wq;
30534 + spinlock_t si_plink_maint_lock;
30535 + pid_t si_plink_maint_pid;
30538 + struct hlist_bl_head si_files;
30540 + /* with/without getattr, brother of sb->s_d_op */
30541 + const struct inode_operations *si_iop_array;
30544 + * sysfs and lifetime management.
30545 + * this is not a small structure and it may be a waste of memory in case
30546 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30547 + * but using sysfs is majority.
30549 + struct kobject si_kobj;
30550 +#ifdef CONFIG_DEBUG_FS
30551 + struct dentry *si_dbgaufs;
30552 + struct dentry *si_dbgaufs_plink;
30553 + struct dentry *si_dbgaufs_xib;
30554 +#ifdef CONFIG_AUFS_EXPORT
30555 + struct dentry *si_dbgaufs_xigen;
30559 +#ifdef CONFIG_AUFS_SBILIST
30560 + struct hlist_bl_node si_list;
30563 + /* dirty, necessary for unmounting, sysfs and sysrq */
30564 + struct super_block *si_sb;
30567 +/* sbinfo status flags */
30569 + * set true when refresh_dirs() failed at remount time.
30570 + * then try refreshing dirs at access time again.
30571 + * if it is false, refreshing dirs at access time is unnecessary
30573 +#define AuSi_FAILED_REFRESH_DIR 1
30574 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30575 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30577 +#ifndef CONFIG_AUFS_FHSM
30579 +#define AuSi_FHSM 0
30582 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30583 + unsigned int flag)
30585 + AuRwMustAnyLock(&sbi->si_rwsem);
30586 + return sbi->au_si_status & flag;
30588 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30589 +#define au_fset_si(sbinfo, name) do { \
30590 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30591 + (sbinfo)->au_si_status |= AuSi_##name; \
30593 +#define au_fclr_si(sbinfo, name) do { \
30594 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30595 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30598 +/* ---------------------------------------------------------------------- */
30600 +/* policy to select one among writable branches */
30601 +#define AuWbrCopyup(sbinfo, ...) \
30602 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30603 +#define AuWbrCreate(sbinfo, ...) \
30604 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30606 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30607 +#define AuLock_DW 1 /* write-lock dentry */
30608 +#define AuLock_IR (1 << 1) /* read-lock inode */
30609 +#define AuLock_IW (1 << 2) /* write-lock inode */
30610 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30611 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30612 + /* except RENAME_EXCHANGE */
30613 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30614 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30615 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30616 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30617 +#define au_fset_lock(flags, name) \
30618 + do { (flags) |= AuLock_##name; } while (0)
30619 +#define au_fclr_lock(flags, name) \
30620 + do { (flags) &= ~AuLock_##name; } while (0)
30622 +/* ---------------------------------------------------------------------- */
30625 +extern struct file_system_type aufs_fs_type;
30626 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30627 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30628 + unsigned long long max, void *arg);
30629 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30630 + struct super_block *sb, void *arg);
30631 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30632 +void au_iarray_free(struct inode **a, unsigned long long max);
30635 +void au_si_free(struct kobject *kobj);
30636 +int au_si_alloc(struct super_block *sb);
30637 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30639 +unsigned int au_sigen_inc(struct super_block *sb);
30640 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30642 +int si_read_lock(struct super_block *sb, int flags);
30643 +int si_write_lock(struct super_block *sb, int flags);
30644 +int aufs_read_lock(struct dentry *dentry, int flags);
30645 +void aufs_read_unlock(struct dentry *dentry, int flags);
30646 +void aufs_write_lock(struct dentry *dentry);
30647 +void aufs_write_unlock(struct dentry *dentry);
30648 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30649 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30651 +/* wbr_policy.c */
30652 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30653 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30654 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30655 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30656 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30659 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30661 +#ifdef CONFIG_AUFS_FHSM
30664 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30668 + spin_lock(&fhsm->fhsm_spin);
30669 + pid = fhsm->fhsm_pid;
30670 + spin_unlock(&fhsm->fhsm_spin);
30675 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30676 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30677 +int au_fhsm_fd(struct super_block *sb, int oflags);
30678 +int au_fhsm_br_alloc(struct au_branch *br);
30679 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30680 +void au_fhsm_fin(struct super_block *sb);
30681 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30682 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30683 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30685 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30687 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30688 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30689 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30690 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30691 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30692 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30693 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30694 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30695 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30698 +/* ---------------------------------------------------------------------- */
30700 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30702 + return sb->s_fs_info;
30705 +/* ---------------------------------------------------------------------- */
30707 +#ifdef CONFIG_AUFS_EXPORT
30708 +int au_test_nfsd(void);
30709 +void au_export_init(struct super_block *sb);
30710 +void au_xigen_inc(struct inode *inode);
30711 +int au_xigen_new(struct inode *inode);
30712 +int au_xigen_set(struct super_block *sb, struct path *path);
30713 +void au_xigen_clr(struct super_block *sb);
30715 +static inline int au_busy_or_stale(void)
30717 + if (!au_test_nfsd())
30722 +AuStubInt0(au_test_nfsd, void)
30723 +AuStubVoid(au_export_init, struct super_block *sb)
30724 +AuStubVoid(au_xigen_inc, struct inode *inode)
30725 +AuStubInt0(au_xigen_new, struct inode *inode)
30726 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30727 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30728 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30729 +#endif /* CONFIG_AUFS_EXPORT */
30731 +/* ---------------------------------------------------------------------- */
30733 +#ifdef CONFIG_AUFS_SBILIST
30735 +extern struct hlist_bl_head au_sbilist;
30737 +static inline void au_sbilist_init(void)
30739 + INIT_HLIST_BL_HEAD(&au_sbilist);
30742 +static inline void au_sbilist_add(struct super_block *sb)
30744 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30747 +static inline void au_sbilist_del(struct super_block *sb)
30749 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30752 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30753 +static inline void au_sbilist_lock(void)
30755 + hlist_bl_lock(&au_sbilist);
30758 +static inline void au_sbilist_unlock(void)
30760 + hlist_bl_unlock(&au_sbilist);
30762 +#define AuGFP_SBILIST GFP_ATOMIC
30764 +AuStubVoid(au_sbilist_lock, void)
30765 +AuStubVoid(au_sbilist_unlock, void)
30766 +#define AuGFP_SBILIST GFP_NOFS
30767 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30769 +AuStubVoid(au_sbilist_init, void)
30770 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30771 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30772 +AuStubVoid(au_sbilist_lock, void)
30773 +AuStubVoid(au_sbilist_unlock, void)
30774 +#define AuGFP_SBILIST GFP_NOFS
30777 +/* ---------------------------------------------------------------------- */
30779 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30782 + * This function is a dynamic '__init' function actually,
30783 + * so the tiny check for si_rwsem is unnecessary.
30785 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30786 +#ifdef CONFIG_DEBUG_FS
30787 + sbinfo->si_dbgaufs = NULL;
30788 + sbinfo->si_dbgaufs_plink = NULL;
30789 + sbinfo->si_dbgaufs_xib = NULL;
30790 +#ifdef CONFIG_AUFS_EXPORT
30791 + sbinfo->si_dbgaufs_xigen = NULL;
30796 +/* ---------------------------------------------------------------------- */
30798 +/* current->atomic_flags */
30799 +/* this value should never corrupt the ones defined in linux/sched.h */
30800 +#define PFA_AUFS 0x10
30802 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30803 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30804 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30806 +static inline int si_pid_test(struct super_block *sb)
30808 + return !!task_test_aufs(current);
30811 +static inline void si_pid_clr(struct super_block *sb)
30813 + AuDebugOn(!task_test_aufs(current));
30814 + task_clear_aufs(current);
30817 +static inline void si_pid_set(struct super_block *sb)
30819 + AuDebugOn(task_test_aufs(current));
30820 + task_set_aufs(current);
30823 +/* ---------------------------------------------------------------------- */
30825 +/* lock superblock. mainly for entry point functions */
30826 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
30827 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
30828 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
30829 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
30831 +#define __si_read_trylock_nested(sb) \
30832 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
30833 +#define __si_write_trylock_nested(sb) \
30834 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
30837 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
30838 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
30839 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
30841 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30842 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30843 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30845 +static inline void si_noflush_read_lock(struct super_block *sb)
30847 + __si_read_lock(sb);
30851 +static inline int si_noflush_read_trylock(struct super_block *sb)
30855 + locked = __si_read_trylock(sb);
30861 +static inline void si_noflush_write_lock(struct super_block *sb)
30863 + __si_write_lock(sb);
30867 +static inline int si_noflush_write_trylock(struct super_block *sb)
30871 + locked = __si_write_trylock(sb);
30877 +#if 0 /* reserved */
30878 +static inline int si_read_trylock(struct super_block *sb, int flags)
30880 + if (au_ftest_lock(flags, FLUSH))
30881 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30882 + return si_noflush_read_trylock(sb);
30886 +static inline void si_read_unlock(struct super_block *sb)
30889 + __si_read_unlock(sb);
30892 +#if 0 /* reserved */
30893 +static inline int si_write_trylock(struct super_block *sb, int flags)
30895 + if (au_ftest_lock(flags, FLUSH))
30896 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30897 + return si_noflush_write_trylock(sb);
30901 +static inline void si_write_unlock(struct super_block *sb)
30904 + __si_write_unlock(sb);
30907 +#if 0 /* reserved */
30908 +static inline void si_downgrade_lock(struct super_block *sb)
30910 + __si_downgrade_lock(sb);
30914 +/* ---------------------------------------------------------------------- */
30916 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
30918 + SiMustAnyLock(sb);
30919 + return au_sbi(sb)->si_bbot;
30922 +static inline unsigned int au_mntflags(struct super_block *sb)
30924 + SiMustAnyLock(sb);
30925 + return au_sbi(sb)->si_mntflags;
30928 +static inline unsigned int au_sigen(struct super_block *sb)
30930 + SiMustAnyLock(sb);
30931 + return au_sbi(sb)->si_generation;
30934 +static inline struct au_branch *au_sbr(struct super_block *sb,
30935 + aufs_bindex_t bindex)
30937 + SiMustAnyLock(sb);
30938 + return au_sbi(sb)->si_branch[0 + bindex];
30941 +static inline loff_t au_xi_maxent(struct super_block *sb)
30943 + SiMustAnyLock(sb);
30944 + return au_sbi(sb)->si_ximaxent;
30947 +#endif /* __KERNEL__ */
30948 +#endif /* __AUFS_SUPER_H__ */
30949 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
30950 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
30951 +++ linux/fs/aufs/sysaufs.c 2020-01-27 10:57:18.178871751 +0100
30953 +// SPDX-License-Identifier: GPL-2.0
30955 + * Copyright (C) 2005-2020 Junjiro R. Okajima
30957 + * This program, aufs is free software; you can redistribute it and/or modify
30958 + * it under the terms of the GNU General Public License as published by
30959 + * the Free Software Foundation; either version 2 of the License, or
30960 + * (at your option) any later version.
30962 + * This program is distributed in the hope that it will be useful,
30963 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30964 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30965 + * GNU General Public License for more details.
30967 + * You should have received a copy of the GNU General Public License
30968 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30972 + * sysfs interface and lifetime management
30973 + * they are necessary regardless sysfs is disabled.
30976 +#include <linux/random.h>
30979 +unsigned long sysaufs_si_mask;
30980 +struct kset *sysaufs_kset;
30982 +#define AuSiAttr(_name) { \
30983 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
30984 + .show = sysaufs_si_##_name, \
30987 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
30988 +struct attribute *sysaufs_si_attrs[] = {
30989 + &sysaufs_si_attr_xi_path.attr,
30993 +static const struct sysfs_ops au_sbi_ops = {
30994 + .show = sysaufs_si_show
30997 +static struct kobj_type au_sbi_ktype = {
30998 + .release = au_si_free,
30999 + .sysfs_ops = &au_sbi_ops,
31000 + .default_attrs = sysaufs_si_attrs
31003 +/* ---------------------------------------------------------------------- */
31005 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31009 + sbinfo->si_kobj.kset = sysaufs_kset;
31010 + /* cf. sysaufs_name() */
31011 + err = kobject_init_and_add
31012 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31013 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31018 +void sysaufs_fin(void)
31020 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31021 + kset_unregister(sysaufs_kset);
31024 +int __init sysaufs_init(void)
31029 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31030 + } while (!sysaufs_si_mask);
31033 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31034 + if (unlikely(!sysaufs_kset))
31036 + err = PTR_ERR(sysaufs_kset);
31037 + if (IS_ERR(sysaufs_kset))
31039 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31040 + if (unlikely(err))
31041 + kset_unregister(sysaufs_kset);
31046 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31047 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31048 +++ linux/fs/aufs/sysaufs.h 2020-01-27 10:57:18.178871751 +0100
31050 +/* SPDX-License-Identifier: GPL-2.0 */
31052 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31054 + * This program, aufs is free software; you can redistribute it and/or modify
31055 + * it under the terms of the GNU General Public License as published by
31056 + * the Free Software Foundation; either version 2 of the License, or
31057 + * (at your option) any later version.
31059 + * This program is distributed in the hope that it will be useful,
31060 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31061 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31062 + * GNU General Public License for more details.
31064 + * You should have received a copy of the GNU General Public License
31065 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31069 + * sysfs interface and mount lifetime management
31072 +#ifndef __SYSAUFS_H__
31073 +#define __SYSAUFS_H__
31077 +#include <linux/sysfs.h>
31078 +#include "module.h"
31080 +struct super_block;
31083 +struct sysaufs_si_attr {
31084 + struct attribute attr;
31085 + int (*show)(struct seq_file *seq, struct super_block *sb);
31088 +/* ---------------------------------------------------------------------- */
31091 +extern unsigned long sysaufs_si_mask;
31092 +extern struct kset *sysaufs_kset;
31093 +extern struct attribute *sysaufs_si_attrs[];
31094 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31095 +int __init sysaufs_init(void);
31096 +void sysaufs_fin(void);
31098 +/* ---------------------------------------------------------------------- */
31100 +/* some people doesn't like to show a pointer in kernel */
31101 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31103 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31106 +#define SysaufsSiNamePrefix "si_"
31107 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31108 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31110 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31111 + sysaufs_si_id(sbinfo));
31115 +#ifdef CONFIG_SYSFS
31117 +extern struct attribute_group *sysaufs_attr_group;
31119 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31120 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31122 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31123 +#ifdef CONFIG_COMPAT
31124 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31127 +void sysaufs_br_init(struct au_branch *br);
31128 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31129 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31131 +#define sysaufs_brs_init() do {} while (0)
31134 +#define sysaufs_attr_group NULL
31136 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31137 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31138 + struct attribute *attr, char *buf)
31139 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31140 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31141 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31143 +static inline void sysaufs_brs_init(void)
31148 +#endif /* CONFIG_SYSFS */
31150 +#endif /* __KERNEL__ */
31151 +#endif /* __SYSAUFS_H__ */
31152 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31153 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31154 +++ linux/fs/aufs/sysfs.c 2020-01-27 10:57:18.178871751 +0100
31156 +// SPDX-License-Identifier: GPL-2.0
31158 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31160 + * This program, aufs is free software; you can redistribute it and/or modify
31161 + * it under the terms of the GNU General Public License as published by
31162 + * the Free Software Foundation; either version 2 of the License, or
31163 + * (at your option) any later version.
31165 + * This program is distributed in the hope that it will be useful,
31166 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31167 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31168 + * GNU General Public License for more details.
31170 + * You should have received a copy of the GNU General Public License
31171 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31175 + * sysfs interface
31178 +#include <linux/compat.h>
31179 +#include <linux/seq_file.h>
31182 +#ifdef CONFIG_AUFS_FS_MODULE
31183 +/* this entry violates the "one line per file" policy of sysfs */
31184 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31188 + static char *conf =
31189 +/* this file is generated at compiling */
31190 +#include "conf.str"
31193 + err = snprintf(buf, PAGE_SIZE, conf);
31194 + if (unlikely(err >= PAGE_SIZE))
31199 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31202 +static struct attribute *au_attr[] = {
31203 +#ifdef CONFIG_AUFS_FS_MODULE
31204 + &au_config_attr.attr,
31206 + NULL, /* need to NULL terminate the list of attributes */
31209 +static struct attribute_group sysaufs_attr_group_body = {
31213 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31215 +/* ---------------------------------------------------------------------- */
31217 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31221 + SiMustAnyLock(sb);
31224 + if (au_opt_test(au_mntflags(sb), XINO)) {
31225 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31226 + seq_putc(seq, '\n');
31232 + * the lifetime of branch is independent from the entry under sysfs.
31233 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31236 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31237 + aufs_bindex_t bindex, int idx)
31240 + struct path path;
31241 + struct dentry *root;
31242 + struct au_branch *br;
31243 + au_br_perm_str_t perm;
31245 + AuDbg("b%d\n", bindex);
31248 + root = sb->s_root;
31249 + di_read_lock_parent(root, !AuLock_IR);
31250 + br = au_sbr(sb, bindex);
31253 + case AuBrSysfs_BR:
31254 + path.mnt = au_br_mnt(br);
31255 + path.dentry = au_h_dptr(root, bindex);
31256 + err = au_seq_path(seq, &path);
31258 + au_optstr_br_perm(&perm, br->br_perm);
31259 + seq_printf(seq, "=%s\n", perm.a);
31262 + case AuBrSysfs_BRID:
31263 + seq_printf(seq, "%d\n", br->br_id);
31266 + di_read_unlock(root, !AuLock_IR);
31267 + if (unlikely(err || seq_has_overflowed(seq)))
31273 +/* ---------------------------------------------------------------------- */
31275 +static struct seq_file *au_seq(char *p, ssize_t len)
31277 + struct seq_file *seq;
31279 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31281 + /* mutex_init(&seq.lock); */
31284 + return seq; /* success */
31287 + seq = ERR_PTR(-ENOMEM);
31291 +#define SysaufsBr_PREFIX "br"
31292 +#define SysaufsBrid_PREFIX "brid"
31294 +/* todo: file size may exceed PAGE_SIZE */
31295 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31301 + aufs_bindex_t bbot;
31302 + struct au_sbinfo *sbinfo;
31303 + struct super_block *sb;
31304 + struct seq_file *seq;
31306 + struct attribute **cattr;
31308 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31309 + sb = sbinfo->si_sb;
31312 + * prevent a race condition between sysfs and aufs.
31313 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31314 + * prohibits maintaining the sysfs entries.
31315 + * hew we acquire read lock after sysfs_get_active_two().
31316 + * on the other hand, the remount process may maintain the sysfs/aufs
31317 + * entries after acquiring write lock.
31318 + * it can cause a deadlock.
31319 + * simply we gave up processing read here.
31322 + if (unlikely(!si_noflush_read_trylock(sb)))
31325 + seq = au_seq(buf, PAGE_SIZE);
31326 + err = PTR_ERR(seq);
31330 + name = (void *)attr->name;
31331 + cattr = sysaufs_si_attrs;
31333 + if (!strcmp(name, (*cattr)->name)) {
31334 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31341 + if (!strncmp(name, SysaufsBrid_PREFIX,
31342 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31343 + idx = AuBrSysfs_BRID;
31344 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31345 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31346 + sizeof(SysaufsBr_PREFIX) - 1)) {
31347 + idx = AuBrSysfs_BR;
31348 + name += sizeof(SysaufsBr_PREFIX) - 1;
31352 + err = kstrtol(name, 10, &l);
31354 + bbot = au_sbbot(sb);
31356 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31363 + err = seq->count;
31364 + /* sysfs limit */
31365 + if (unlikely(err == PAGE_SIZE))
31368 + au_kfree_rcu(seq);
31370 + si_read_unlock(sb);
31375 +/* ---------------------------------------------------------------------- */
31377 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31381 + aufs_bindex_t bindex, bbot;
31384 + struct seq_file *seq;
31385 + struct au_branch *br;
31387 + si_read_lock(sb, AuLock_FLUSH);
31388 + bbot = au_sbbot(sb);
31394 + buf = (void *)__get_free_page(GFP_NOFS);
31395 + if (unlikely(!buf))
31398 + seq = au_seq(buf, PAGE_SIZE);
31399 + err = PTR_ERR(seq);
31403 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31404 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31405 + /* VERIFY_WRITE */
31406 + err = !access_ok(arg, sizeof(*arg));
31407 + if (unlikely(err))
31410 + br = au_sbr(sb, bindex);
31411 + brid = br->br_id;
31412 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31413 + err = __put_user(brid, &arg->id);
31414 + if (unlikely(err))
31417 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31418 + err = __put_user(br->br_perm, &arg->perm);
31419 + if (unlikely(err))
31422 + err = au_seq_path(seq, &br->br_path);
31423 + if (unlikely(err))
31425 + seq_putc(seq, '\0');
31426 + if (!seq_has_overflowed(seq)) {
31427 + err = copy_to_user(arg->path, seq->buf, seq->count);
31429 + if (unlikely(err))
31436 + if (unlikely(err))
31440 + au_kfree_rcu(seq);
31442 + free_page((unsigned long)buf);
31444 + si_read_unlock(sb);
31448 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31450 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31453 +#ifdef CONFIG_COMPAT
31454 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31456 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31460 +/* ---------------------------------------------------------------------- */
31462 +void sysaufs_br_init(struct au_branch *br)
31465 + struct au_brsysfs *br_sysfs;
31466 + struct attribute *attr;
31468 + br_sysfs = br->br_sysfs;
31469 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31470 + attr = &br_sysfs->attr;
31471 + sysfs_attr_init(attr);
31472 + attr->name = br_sysfs->name;
31473 + attr->mode = 0444;
31478 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31480 + struct au_branch *br;
31481 + struct kobject *kobj;
31482 + struct au_brsysfs *br_sysfs;
31484 + aufs_bindex_t bbot;
31486 + if (!sysaufs_brs)
31489 + kobj = &au_sbi(sb)->si_kobj;
31490 + bbot = au_sbbot(sb);
31491 + for (; bindex <= bbot; bindex++) {
31492 + br = au_sbr(sb, bindex);
31493 + br_sysfs = br->br_sysfs;
31494 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31495 + sysfs_remove_file(kobj, &br_sysfs->attr);
31501 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31504 + aufs_bindex_t bbot;
31505 + struct kobject *kobj;
31506 + struct au_branch *br;
31507 + struct au_brsysfs *br_sysfs;
31509 + if (!sysaufs_brs)
31512 + kobj = &au_sbi(sb)->si_kobj;
31513 + bbot = au_sbbot(sb);
31514 + for (; bindex <= bbot; bindex++) {
31515 + br = au_sbr(sb, bindex);
31516 + br_sysfs = br->br_sysfs;
31517 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31518 + SysaufsBr_PREFIX "%d", bindex);
31519 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31520 + SysaufsBrid_PREFIX "%d", bindex);
31521 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31522 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31523 + if (unlikely(err))
31524 + pr_warn("failed %s under sysfs(%d)\n",
31525 + br_sysfs->name, err);
31530 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31531 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31532 +++ linux/fs/aufs/sysrq.c 2020-01-27 10:57:18.178871751 +0100
31534 +// SPDX-License-Identifier: GPL-2.0
31536 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31538 + * This program, aufs is free software; you can redistribute it and/or modify
31539 + * it under the terms of the GNU General Public License as published by
31540 + * the Free Software Foundation; either version 2 of the License, or
31541 + * (at your option) any later version.
31543 + * This program is distributed in the hope that it will be useful,
31544 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31545 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31546 + * GNU General Public License for more details.
31548 + * You should have received a copy of the GNU General Public License
31549 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31553 + * magic sysrq handler
31556 +/* #include <linux/sysrq.h> */
31557 +#include <linux/writeback.h>
31560 +/* ---------------------------------------------------------------------- */
31562 +static void sysrq_sb(struct super_block *sb)
31565 + struct au_sbinfo *sbinfo;
31566 + struct file *file;
31567 + struct hlist_bl_head *files;
31568 + struct hlist_bl_node *pos;
31569 + struct au_finfo *finfo;
31572 + plevel = au_plevel;
31573 + au_plevel = KERN_WARNING;
31575 + /* since we define pr_fmt, call printk directly */
31576 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31578 + sbinfo = au_sbi(sb);
31579 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31580 + pr("superblock\n");
31583 +#if 0 /* reserved */
31585 + int err, i, j, ndentry;
31586 + struct au_dcsub_pages dpages;
31587 + struct au_dpage *dpage;
31589 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31590 + if (unlikely(err))
31592 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31594 + for (i = 0; i < dpages.ndpage; i++) {
31595 + dpage = dpages.dpages + i;
31596 + ndentry = dpage->ndentry;
31597 + for (j = 0; j < ndentry; j++)
31598 + au_dpri_dentry(dpage->dentries[j]);
31600 + au_dpages_free(&dpages);
31604 + pr("isolated inode\n");
31605 + spin_lock(&sb->s_inode_list_lock);
31606 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31607 + spin_lock(&i->i_lock);
31608 + if (hlist_empty(&i->i_dentry))
31609 + au_dpri_inode(i);
31610 + spin_unlock(&i->i_lock);
31612 + spin_unlock(&sb->s_inode_list_lock);
31615 + files = &au_sbi(sb)->si_files;
31616 + hlist_bl_lock(files);
31617 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31620 + file = finfo->fi_file;
31621 + mode = file_inode(file)->i_mode;
31622 + if (!special_file(mode))
31623 + au_dpri_file(file);
31625 + hlist_bl_unlock(files);
31629 + au_plevel = plevel;
31632 +/* ---------------------------------------------------------------------- */
31634 +/* module parameter */
31635 +static char *aufs_sysrq_key = "a";
31636 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31637 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31639 +static void au_sysrq(int key __maybe_unused)
31641 + struct au_sbinfo *sbinfo;
31642 + struct hlist_bl_node *pos;
31645 + au_sbilist_lock();
31646 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31647 + sysrq_sb(sbinfo->si_sb);
31648 + au_sbilist_unlock();
31652 +static struct sysrq_key_op au_sysrq_op = {
31653 + .handler = au_sysrq,
31654 + .help_msg = "Aufs",
31655 + .action_msg = "Aufs",
31656 + .enable_mask = SYSRQ_ENABLE_DUMP
31659 +/* ---------------------------------------------------------------------- */
31661 +int __init au_sysrq_init(void)
31667 + key = *aufs_sysrq_key;
31668 + if ('a' <= key && key <= 'z')
31669 + err = register_sysrq_key(key, &au_sysrq_op);
31670 + if (unlikely(err))
31671 + pr_err("err %d, sysrq=%c\n", err, key);
31675 +void au_sysrq_fin(void)
31679 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31680 + if (unlikely(err))
31681 + pr_err("err %d (ignored)\n", err);
31683 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31684 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31685 +++ linux/fs/aufs/vdir.c 2020-01-27 10:57:18.178871751 +0100
31687 +// SPDX-License-Identifier: GPL-2.0
31689 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31691 + * This program, aufs is free software; you can redistribute it and/or modify
31692 + * it under the terms of the GNU General Public License as published by
31693 + * the Free Software Foundation; either version 2 of the License, or
31694 + * (at your option) any later version.
31696 + * This program is distributed in the hope that it will be useful,
31697 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31698 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31699 + * GNU General Public License for more details.
31701 + * You should have received a copy of the GNU General Public License
31702 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31706 + * virtual or vertical directory
31709 +#include <linux/iversion.h>
31712 +static unsigned int calc_size(int nlen)
31714 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31717 +static int set_deblk_end(union au_vdir_deblk_p *p,
31718 + union au_vdir_deblk_p *deblk_end)
31720 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31721 + p->de->de_str.len = 0;
31725 + return -1; /* error */
31728 +/* returns true or false */
31729 +static int is_deblk_end(union au_vdir_deblk_p *p,
31730 + union au_vdir_deblk_p *deblk_end)
31732 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31733 + return !p->de->de_str.len;
31737 +static unsigned char *last_deblk(struct au_vdir *vdir)
31739 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31742 +/* ---------------------------------------------------------------------- */
31744 +/* estimate the appropriate size for name hash table */
31745 +unsigned int au_rdhash_est(loff_t sz)
31753 + if (sz < AUFS_RDHASH_DEF)
31754 + n = AUFS_RDHASH_DEF;
31755 + /* pr_info("n %u\n", n); */
31760 + * the allocated memory has to be freed by
31761 + * au_nhash_wh_free() or au_nhash_de_free().
31763 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31765 + struct hlist_head *head;
31769 + sz = sizeof(*nhash->nh_head) * num_hash;
31770 + head = kmalloc(sz, gfp);
31772 + nhash->nh_num = num_hash;
31773 + nhash->nh_head = head;
31774 + for (u = 0; u < num_hash; u++)
31775 + INIT_HLIST_HEAD(head++);
31776 + return 0; /* success */
31782 +static void nhash_count(struct hlist_head *head)
31784 +#if 0 /* debugging */
31786 + struct hlist_node *pos;
31789 + hlist_for_each(pos, head)
31791 + pr_info("%lu\n", n);
31795 +static void au_nhash_wh_do_free(struct hlist_head *head)
31797 + struct au_vdir_wh *pos;
31798 + struct hlist_node *node;
31800 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31801 + au_kfree_rcu(pos);
31804 +static void au_nhash_de_do_free(struct hlist_head *head)
31806 + struct au_vdir_dehstr *pos;
31807 + struct hlist_node *node;
31809 + hlist_for_each_entry_safe(pos, node, head, hash)
31810 + au_cache_free_vdir_dehstr(pos);
31813 +static void au_nhash_do_free(struct au_nhash *nhash,
31814 + void (*free)(struct hlist_head *head))
31817 + struct hlist_head *head;
31819 + n = nhash->nh_num;
31823 + head = nhash->nh_head;
31824 + while (n-- > 0) {
31825 + nhash_count(head);
31828 + au_kfree_try_rcu(nhash->nh_head);
31831 +void au_nhash_wh_free(struct au_nhash *whlist)
31833 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31836 +static void au_nhash_de_free(struct au_nhash *delist)
31838 + au_nhash_do_free(delist, au_nhash_de_do_free);
31841 +/* ---------------------------------------------------------------------- */
31843 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
31847 + unsigned int u, n;
31848 + struct hlist_head *head;
31849 + struct au_vdir_wh *pos;
31852 + n = whlist->nh_num;
31853 + head = whlist->nh_head;
31854 + for (u = 0; u < n; u++, head++)
31855 + hlist_for_each_entry(pos, head, wh_hash)
31856 + if (pos->wh_bindex == btgt && ++num > limit)
31861 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
31862 + unsigned char *name,
31863 + unsigned int len)
31866 + /* const unsigned int magic_bit = 12; */
31868 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
31875 + /* v = hash_long(v, magic_bit); */
31876 + v %= nhash->nh_num;
31877 + return nhash->nh_head + v;
31880 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
31883 + return str->len == nlen && !memcmp(str->name, name, nlen);
31886 +/* returns found or not */
31887 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
31889 + struct hlist_head *head;
31890 + struct au_vdir_wh *pos;
31891 + struct au_vdir_destr *str;
31893 + head = au_name_hash(whlist, name, nlen);
31894 + hlist_for_each_entry(pos, head, wh_hash) {
31895 + str = &pos->wh_str;
31896 + AuDbg("%.*s\n", str->len, str->name);
31897 + if (au_nhash_test_name(str, name, nlen))
31903 +/* returns found(true) or not */
31904 +static int test_known(struct au_nhash *delist, char *name, int nlen)
31906 + struct hlist_head *head;
31907 + struct au_vdir_dehstr *pos;
31908 + struct au_vdir_destr *str;
31910 + head = au_name_hash(delist, name, nlen);
31911 + hlist_for_each_entry(pos, head, hash) {
31913 + AuDbg("%.*s\n", str->len, str->name);
31914 + if (au_nhash_test_name(str, name, nlen))
31920 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
31921 + unsigned char d_type)
31923 +#ifdef CONFIG_AUFS_SHWH
31924 + wh->wh_ino = ino;
31925 + wh->wh_type = d_type;
31929 +/* ---------------------------------------------------------------------- */
31931 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
31932 + unsigned int d_type, aufs_bindex_t bindex,
31933 + unsigned char shwh)
31936 + struct au_vdir_destr *str;
31937 + struct au_vdir_wh *wh;
31939 + AuDbg("%.*s\n", nlen, name);
31940 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
31943 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
31944 + if (unlikely(!wh))
31948 + wh->wh_bindex = bindex;
31950 + au_shwh_init_wh(wh, ino, d_type);
31951 + str = &wh->wh_str;
31953 + memcpy(str->name, name, nlen);
31954 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
31961 +static int append_deblk(struct au_vdir *vdir)
31964 + unsigned long ul;
31965 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
31966 + union au_vdir_deblk_p p, deblk_end;
31967 + unsigned char **o;
31970 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
31971 + GFP_NOFS, /*may_shrink*/0);
31972 + if (unlikely(!o))
31975 + vdir->vd_deblk = o;
31976 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
31978 + ul = vdir->vd_nblk++;
31979 + vdir->vd_deblk[ul] = p.deblk;
31980 + vdir->vd_last.ul = ul;
31981 + vdir->vd_last.p.deblk = p.deblk;
31982 + deblk_end.deblk = p.deblk + deblk_sz;
31983 + err = set_deblk_end(&p, &deblk_end);
31990 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
31991 + unsigned int d_type, struct au_nhash *delist)
31995 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
31996 + union au_vdir_deblk_p p, *room, deblk_end;
31997 + struct au_vdir_dehstr *dehstr;
31999 + p.deblk = last_deblk(vdir);
32000 + deblk_end.deblk = p.deblk + deblk_sz;
32001 + room = &vdir->vd_last.p;
32002 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32003 + || !is_deblk_end(room, &deblk_end));
32005 + sz = calc_size(nlen);
32006 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32007 + err = append_deblk(vdir);
32008 + if (unlikely(err))
32011 + p.deblk = last_deblk(vdir);
32012 + deblk_end.deblk = p.deblk + deblk_sz;
32014 + AuDebugOn(room->deblk != p.deblk);
32018 + dehstr = au_cache_alloc_vdir_dehstr();
32019 + if (unlikely(!dehstr))
32022 + dehstr->str = &room->de->de_str;
32023 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32024 + room->de->de_ino = ino;
32025 + room->de->de_type = d_type;
32026 + room->de->de_str.len = nlen;
32027 + memcpy(room->de->de_str.name, name, nlen);
32030 + room->deblk += sz;
32031 + if (unlikely(set_deblk_end(room, &deblk_end)))
32032 + err = append_deblk(vdir);
32039 +/* ---------------------------------------------------------------------- */
32041 +void au_vdir_free(struct au_vdir *vdir)
32043 + unsigned char **deblk;
32045 + deblk = vdir->vd_deblk;
32046 + while (vdir->vd_nblk--)
32047 + au_kfree_try_rcu(*deblk++);
32048 + au_kfree_try_rcu(vdir->vd_deblk);
32049 + au_cache_free_vdir(vdir);
32052 +static struct au_vdir *alloc_vdir(struct file *file)
32054 + struct au_vdir *vdir;
32055 + struct super_block *sb;
32058 + sb = file->f_path.dentry->d_sb;
32059 + SiMustAnyLock(sb);
32062 + vdir = au_cache_alloc_vdir();
32063 + if (unlikely(!vdir))
32066 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32067 + if (unlikely(!vdir->vd_deblk))
32070 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32071 + if (!vdir->vd_deblk_sz) {
32072 + /* estimate the appropriate size for deblk */
32073 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32074 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32076 + vdir->vd_nblk = 0;
32077 + vdir->vd_version = 0;
32078 + vdir->vd_jiffy = 0;
32079 + err = append_deblk(vdir);
32081 + return vdir; /* success */
32083 + au_kfree_try_rcu(vdir->vd_deblk);
32086 + au_cache_free_vdir(vdir);
32088 + vdir = ERR_PTR(err);
32092 +static int reinit_vdir(struct au_vdir *vdir)
32095 + union au_vdir_deblk_p p, deblk_end;
32097 + while (vdir->vd_nblk > 1) {
32098 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32099 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32102 + p.deblk = vdir->vd_deblk[0];
32103 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32104 + err = set_deblk_end(&p, &deblk_end);
32105 + /* keep vd_dblk_sz */
32106 + vdir->vd_last.ul = 0;
32107 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32108 + vdir->vd_version = 0;
32109 + vdir->vd_jiffy = 0;
32114 +/* ---------------------------------------------------------------------- */
32116 +#define AuFillVdir_CALLED 1
32117 +#define AuFillVdir_WHABLE (1 << 1)
32118 +#define AuFillVdir_SHWH (1 << 2)
32119 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32120 +#define au_fset_fillvdir(flags, name) \
32121 + do { (flags) |= AuFillVdir_##name; } while (0)
32122 +#define au_fclr_fillvdir(flags, name) \
32123 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32125 +#ifndef CONFIG_AUFS_SHWH
32126 +#undef AuFillVdir_SHWH
32127 +#define AuFillVdir_SHWH 0
32130 +struct fillvdir_arg {
32131 + struct dir_context ctx;
32132 + struct file *file;
32133 + struct au_vdir *vdir;
32134 + struct au_nhash delist;
32135 + struct au_nhash whlist;
32136 + aufs_bindex_t bindex;
32137 + unsigned int flags;
32141 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32142 + loff_t offset __maybe_unused, u64 h_ino,
32143 + unsigned int d_type)
32145 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32146 + char *name = (void *)__name;
32147 + struct super_block *sb;
32149 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32152 + sb = arg->file->f_path.dentry->d_sb;
32153 + au_fset_fillvdir(arg->flags, CALLED);
32155 + if (nlen <= AUFS_WH_PFX_LEN
32156 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32157 + if (test_known(&arg->delist, name, nlen)
32158 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32159 + goto out; /* already exists or whiteouted */
32161 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32163 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32164 + d_type = DT_UNKNOWN;
32165 + arg->err = append_de(arg->vdir, name, nlen, ino,
32166 + d_type, &arg->delist);
32168 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32169 + name += AUFS_WH_PFX_LEN;
32170 + nlen -= AUFS_WH_PFX_LEN;
32171 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32172 + goto out; /* already whiteouted */
32174 + ino = 0; /* just to suppress a warning */
32176 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32179 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32180 + d_type = DT_UNKNOWN;
32181 + arg->err = au_nhash_append_wh
32182 + (&arg->whlist, name, nlen, ino, d_type,
32183 + arg->bindex, shwh);
32189 + arg->vdir->vd_jiffy = jiffies;
32191 + AuTraceErr(arg->err);
32195 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32196 + struct au_nhash *whlist, struct au_nhash *delist)
32198 +#ifdef CONFIG_AUFS_SHWH
32200 + unsigned int nh, u;
32201 + struct hlist_head *head;
32202 + struct au_vdir_wh *pos;
32203 + struct hlist_node *n;
32205 + struct au_vdir_destr *destr;
32207 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32210 + o = p = (void *)__get_free_page(GFP_NOFS);
32211 + if (unlikely(!p))
32215 + nh = whlist->nh_num;
32216 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32217 + p += AUFS_WH_PFX_LEN;
32218 + for (u = 0; u < nh; u++) {
32219 + head = whlist->nh_head + u;
32220 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32221 + destr = &pos->wh_str;
32222 + memcpy(p, destr->name, destr->len);
32223 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32224 + pos->wh_ino, pos->wh_type, delist);
32225 + if (unlikely(err))
32230 + free_page((unsigned long)o);
32240 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32243 + unsigned int rdhash;
32245 + aufs_bindex_t bbot, bindex, btop;
32246 + unsigned char shwh;
32247 + struct file *hf, *file;
32248 + struct super_block *sb;
32250 + file = arg->file;
32251 + sb = file->f_path.dentry->d_sb;
32252 + SiMustAnyLock(sb);
32254 + rdhash = au_sbi(sb)->si_rdhash;
32256 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32257 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32258 + if (unlikely(err))
32260 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32261 + if (unlikely(err))
32267 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32269 + au_fset_fillvdir(arg->flags, SHWH);
32271 + btop = au_fbtop(file);
32272 + bbot = au_fbbot_dir(file);
32273 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32274 + hf = au_hf_dir(file, bindex);
32278 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32280 + if (unlikely(offset))
32283 + arg->bindex = bindex;
32284 + au_fclr_fillvdir(arg->flags, WHABLE);
32286 + || (bindex != bbot
32287 + && au_br_whable(au_sbr_perm(sb, bindex))))
32288 + au_fset_fillvdir(arg->flags, WHABLE);
32291 + au_fclr_fillvdir(arg->flags, CALLED);
32293 + err = vfsub_iterate_dir(hf, &arg->ctx);
32296 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32299 + * dir_relax() may be good for concurrency, but aufs should not
32300 + * use it since it will cause a lockdep problem.
32304 + if (!err && shwh)
32305 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32307 + au_nhash_wh_free(&arg->whlist);
32310 + au_nhash_de_free(&arg->delist);
32315 +static int read_vdir(struct file *file, int may_read)
32318 + unsigned long expire;
32319 + unsigned char do_read;
32320 + struct fillvdir_arg arg = {
32322 + .actor = fillvdir
32325 + struct inode *inode;
32326 + struct au_vdir *vdir, *allocated;
32329 + inode = file_inode(file);
32330 + IMustLock(inode);
32331 + IiMustWriteLock(inode);
32332 + SiMustAnyLock(inode->i_sb);
32334 + allocated = NULL;
32336 + expire = au_sbi(inode->i_sb)->si_rdcache;
32337 + vdir = au_ivdir(inode);
32340 + vdir = alloc_vdir(file);
32341 + err = PTR_ERR(vdir);
32342 + if (IS_ERR(vdir))
32345 + allocated = vdir;
32346 + } else if (may_read
32347 + && (!inode_eq_iversion(inode, vdir->vd_version)
32348 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32350 + err = reinit_vdir(vdir);
32351 + if (unlikely(err))
32356 + return 0; /* success */
32360 + err = au_do_read_vdir(&arg);
32362 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32363 + vdir->vd_version = inode_query_iversion(inode);
32364 + vdir->vd_last.ul = 0;
32365 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32367 + au_set_ivdir(inode, allocated);
32368 + } else if (allocated)
32369 + au_vdir_free(allocated);
32375 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32378 + unsigned long ul, n;
32379 + const unsigned int deblk_sz = src->vd_deblk_sz;
32381 + AuDebugOn(tgt->vd_nblk != 1);
32384 + if (tgt->vd_nblk < src->vd_nblk) {
32385 + unsigned char **p;
32387 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32388 + GFP_NOFS, /*may_shrink*/0);
32389 + if (unlikely(!p))
32391 + tgt->vd_deblk = p;
32394 + if (tgt->vd_deblk_sz != deblk_sz) {
32395 + unsigned char *p;
32397 + tgt->vd_deblk_sz = deblk_sz;
32398 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32399 + /*may_shrink*/1);
32400 + if (unlikely(!p))
32402 + tgt->vd_deblk[0] = p;
32404 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32405 + tgt->vd_version = src->vd_version;
32406 + tgt->vd_jiffy = src->vd_jiffy;
32408 + n = src->vd_nblk;
32409 + for (ul = 1; ul < n; ul++) {
32410 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32412 + if (unlikely(!tgt->vd_deblk[ul]))
32416 + tgt->vd_nblk = n;
32417 + tgt->vd_last.ul = tgt->vd_last.ul;
32418 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32419 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32420 + - src->vd_deblk[src->vd_last.ul];
32422 + return 0; /* success */
32425 + rerr = reinit_vdir(tgt);
32430 +int au_vdir_init(struct file *file)
32433 + struct inode *inode;
32434 + struct au_vdir *vdir_cache, *allocated;
32436 + /* test file->f_pos here instead of ctx->pos */
32437 + err = read_vdir(file, !file->f_pos);
32438 + if (unlikely(err))
32441 + allocated = NULL;
32442 + vdir_cache = au_fvdir_cache(file);
32443 + if (!vdir_cache) {
32444 + vdir_cache = alloc_vdir(file);
32445 + err = PTR_ERR(vdir_cache);
32446 + if (IS_ERR(vdir_cache))
32448 + allocated = vdir_cache;
32449 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32450 + /* test file->f_pos here instead of ctx->pos */
32451 + err = reinit_vdir(vdir_cache);
32452 + if (unlikely(err))
32455 + return 0; /* success */
32457 + inode = file_inode(file);
32458 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32460 + file->f_version = inode_query_iversion(inode);
32462 + au_set_fvdir_cache(file, allocated);
32463 + } else if (allocated)
32464 + au_vdir_free(allocated);
32470 +static loff_t calc_offset(struct au_vdir *vdir)
32473 + union au_vdir_deblk_p p;
32475 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32476 + offset = vdir->vd_last.p.deblk - p.deblk;
32477 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32481 +/* returns true or false */
32482 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32485 + unsigned int deblk_sz;
32486 + unsigned long ul, n;
32488 + union au_vdir_deblk_p p, deblk_end;
32489 + struct au_vdir *vdir_cache;
32492 + vdir_cache = au_fvdir_cache(file);
32493 + offset = calc_offset(vdir_cache);
32494 + AuDbg("offset %lld\n", offset);
32495 + if (ctx->pos == offset)
32498 + vdir_cache->vd_last.ul = 0;
32499 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32504 + deblk_sz = vdir_cache->vd_deblk_sz;
32505 + ul = div64_u64(ctx->pos, deblk_sz);
32506 + AuDbg("ul %lu\n", ul);
32507 + if (ul >= vdir_cache->vd_nblk)
32510 + n = vdir_cache->vd_nblk;
32511 + for (; ul < n; ul++) {
32512 + p.deblk = vdir_cache->vd_deblk[ul];
32513 + deblk_end.deblk = p.deblk + deblk_sz;
32515 + offset *= deblk_sz;
32516 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32519 + l = calc_size(p.de->de_str.len);
32523 + if (!is_deblk_end(&p, &deblk_end)) {
32525 + vdir_cache->vd_last.ul = ul;
32526 + vdir_cache->vd_last.p = p;
32534 + AuDbg("valid %d\n", !valid);
32538 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32540 + unsigned int l, deblk_sz;
32541 + union au_vdir_deblk_p deblk_end;
32542 + struct au_vdir *vdir_cache;
32543 + struct au_vdir_de *de;
32545 + if (!seek_vdir(file, ctx))
32548 + vdir_cache = au_fvdir_cache(file);
32549 + deblk_sz = vdir_cache->vd_deblk_sz;
32551 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32552 + deblk_end.deblk += deblk_sz;
32553 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32554 + de = vdir_cache->vd_last.p.de;
32555 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32556 + de->de_str.len, de->de_str.name, ctx->pos,
32557 + (unsigned long)de->de_ino, de->de_type);
32558 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32559 + de->de_str.len, de->de_ino,
32561 + /* todo: ignore the error caused by udba? */
32562 + /* return err; */
32566 + l = calc_size(de->de_str.len);
32567 + vdir_cache->vd_last.p.deblk += l;
32570 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32571 + vdir_cache->vd_last.ul++;
32572 + vdir_cache->vd_last.p.deblk
32573 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32574 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32583 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32584 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32585 +++ linux/fs/aufs/vfsub.c 2020-12-15 14:10:58.921356596 +0100
32587 +// SPDX-License-Identifier: GPL-2.0
32589 + * Copyright (C) 2005-2020 Junjiro R. Okajima
32591 + * This program, aufs is free software; you can redistribute it and/or modify
32592 + * it under the terms of the GNU General Public License as published by
32593 + * the Free Software Foundation; either version 2 of the License, or
32594 + * (at your option) any later version.
32596 + * This program is distributed in the hope that it will be useful,
32597 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32598 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32599 + * GNU General Public License for more details.
32601 + * You should have received a copy of the GNU General Public License
32602 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32606 + * sub-routines for VFS
32609 +#include <linux/mnt_namespace.h>
32610 +#include <linux/namei.h>
32611 +#include <linux/nsproxy.h>
32612 +#include <linux/security.h>
32613 +#include <linux/splice.h>
32616 +#ifdef CONFIG_AUFS_BR_FUSE
32617 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32619 + if (!au_test_fuse(h_sb) || !au_userns)
32622 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32626 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32631 + down_read(&h_sb->s_umount);
32632 + err = __sync_filesystem(h_sb, wait);
32633 + up_read(&h_sb->s_umount);
32639 +/* ---------------------------------------------------------------------- */
32641 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32645 + struct super_block *h_sb;
32647 + /* for remote fs, leave work for its getattr or d_revalidate */
32648 + /* for bad i_attr fs, handle them in aufs_getattr() */
32649 + /* still some fs may acquire i_mutex. we need to skip them */
32653 + h_sb = h_path->dentry->d_sb;
32654 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32656 + err = vfsub_getattr(h_path, &st);
32661 +/* ---------------------------------------------------------------------- */
32663 +struct file *vfsub_dentry_open(struct path *path, int flags)
32665 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32669 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32671 + struct file *file;
32674 + file = filp_open(path,
32675 + oflags /* | __FMODE_NONOTIFY */,
32678 + if (IS_ERR(file))
32680 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32687 + * Ideally this function should call VFS:do_last() in order to keep all its
32688 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32689 + * structure such as nameidata. This is a second (or third) best approach.
32690 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32692 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32693 + struct vfsub_aopen_args *args)
32696 + struct au_branch *br = args->br;
32697 + struct file *file = args->file;
32698 + /* copied from linux/fs/namei.c:atomic_open() */
32699 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32702 + AuDebugOn(!dir->i_op->atomic_open);
32704 + err = au_br_test_oflag(args->open_flag, br);
32705 + if (unlikely(err))
32708 + au_lcnt_inc(&br->br_nfiles);
32709 + file->f_path.dentry = DENTRY_NOT_SET;
32710 + file->f_path.mnt = au_br_mnt(br);
32711 + AuDbg("%ps\n", dir->i_op->atomic_open);
32712 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32713 + args->create_mode);
32714 + if (unlikely(err < 0)) {
32715 + au_lcnt_dec(&br->br_nfiles);
32719 + /* temporary workaround for nfsv4 branch */
32720 + if (au_test_nfs(dir->i_sb))
32721 + nfs_mark_for_revalidate(dir);
32723 + if (file->f_mode & FMODE_CREATED)
32724 + fsnotify_create(dir, dentry);
32725 + if (!(file->f_mode & FMODE_OPENED)) {
32726 + au_lcnt_dec(&br->br_nfiles);
32730 + /* todo: call VFS:may_open() here */
32731 + /* todo: ima_file_check() too? */
32732 + if (!err && (args->open_flag & __FMODE_EXEC))
32733 + err = deny_write_access(file);
32735 + fsnotify_open(file);
32737 + au_lcnt_dec(&br->br_nfiles);
32738 + /* note that the file is created and still opened */
32744 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32748 + err = kern_path(name, flags, path);
32749 + if (!err && d_is_positive(path->dentry))
32750 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32754 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32755 + struct dentry *parent, int len)
32757 + struct path path = {
32761 + path.dentry = lookup_one_len_unlocked(name, parent, len);
32762 + if (IS_ERR(path.dentry))
32764 + if (d_is_positive(path.dentry))
32765 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32768 + AuTraceErrPtr(path.dentry);
32769 + return path.dentry;
32772 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
32775 + struct path path = {
32779 + /* VFS checks it too, but by WARN_ON_ONCE() */
32780 + IMustLock(d_inode(parent));
32782 + path.dentry = lookup_one_len(name, parent, len);
32783 + if (IS_ERR(path.dentry))
32785 + if (d_is_positive(path.dentry))
32786 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32789 + AuTraceErrPtr(path.dentry);
32790 + return path.dentry;
32793 +void vfsub_call_lkup_one(void *args)
32795 + struct vfsub_lkup_one_args *a = args;
32796 + *a->errp = vfsub_lkup_one(a->name, a->parent);
32799 +/* ---------------------------------------------------------------------- */
32801 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32802 + struct dentry *d2, struct au_hinode *hdir2)
32804 + struct dentry *d;
32807 + d = lock_rename(d1, d2);
32809 + au_hn_suspend(hdir1);
32810 + if (hdir1 != hdir2)
32811 + au_hn_suspend(hdir2);
32816 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32817 + struct dentry *d2, struct au_hinode *hdir2)
32819 + au_hn_resume(hdir1);
32820 + if (hdir1 != hdir2)
32821 + au_hn_resume(hdir2);
32823 + unlock_rename(d1, d2);
32827 +/* ---------------------------------------------------------------------- */
32829 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32832 + struct dentry *d;
32836 + d = path->dentry;
32837 + path->dentry = d->d_parent;
32838 + err = security_path_mknod(path, d, mode, 0);
32839 + path->dentry = d;
32840 + if (unlikely(err))
32844 + err = vfs_create(dir, path->dentry, mode, want_excl);
32847 + struct path tmp = *path;
32850 + vfsub_update_h_iattr(&tmp, &did);
32852 + tmp.dentry = path->dentry->d_parent;
32853 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32862 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
32865 + struct dentry *d;
32869 + d = path->dentry;
32870 + path->dentry = d->d_parent;
32871 + err = security_path_symlink(path, d, symname);
32872 + path->dentry = d;
32873 + if (unlikely(err))
32877 + err = vfs_symlink(dir, path->dentry, symname);
32880 + struct path tmp = *path;
32883 + vfsub_update_h_iattr(&tmp, &did);
32885 + tmp.dentry = path->dentry->d_parent;
32886 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32895 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
32898 + struct dentry *d;
32902 + d = path->dentry;
32903 + path->dentry = d->d_parent;
32904 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
32905 + path->dentry = d;
32906 + if (unlikely(err))
32910 + err = vfs_mknod(dir, path->dentry, mode, dev);
32913 + struct path tmp = *path;
32916 + vfsub_update_h_iattr(&tmp, &did);
32918 + tmp.dentry = path->dentry->d_parent;
32919 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32928 +static int au_test_nlink(struct inode *inode)
32930 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
32932 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
32933 + || inode->i_nlink < link_max)
32938 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
32939 + struct inode **delegated_inode)
32942 + struct dentry *d;
32946 + err = au_test_nlink(d_inode(src_dentry));
32947 + if (unlikely(err))
32950 + /* we don't call may_linkat() */
32951 + d = path->dentry;
32952 + path->dentry = d->d_parent;
32953 + err = security_path_link(src_dentry, path, d);
32954 + path->dentry = d;
32955 + if (unlikely(err))
32959 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
32962 + struct path tmp = *path;
32965 + /* fuse has different memory inode for the same inumber */
32966 + vfsub_update_h_iattr(&tmp, &did);
32968 + tmp.dentry = path->dentry->d_parent;
32969 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32970 + tmp.dentry = src_dentry;
32971 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32980 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
32981 + struct inode *dir, struct path *path,
32982 + struct inode **delegated_inode, unsigned int flags)
32985 + struct path tmp = {
32988 + struct dentry *d;
32991 + IMustLock(src_dir);
32993 + d = path->dentry;
32994 + path->dentry = d->d_parent;
32995 + tmp.dentry = src_dentry->d_parent;
32996 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
32997 + path->dentry = d;
32998 + if (unlikely(err))
33002 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
33003 + delegated_inode, flags);
33008 + tmp.dentry = d->d_parent;
33009 + vfsub_update_h_iattr(&tmp, &did);
33011 + tmp.dentry = src_dentry;
33012 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33013 + tmp.dentry = src_dentry->d_parent;
33014 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33023 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33026 + struct dentry *d;
33030 + d = path->dentry;
33031 + path->dentry = d->d_parent;
33032 + err = security_path_mkdir(path, d, mode);
33033 + path->dentry = d;
33034 + if (unlikely(err))
33038 + err = vfs_mkdir(dir, path->dentry, mode);
33041 + struct path tmp = *path;
33044 + vfsub_update_h_iattr(&tmp, &did);
33046 + tmp.dentry = path->dentry->d_parent;
33047 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33056 +int vfsub_rmdir(struct inode *dir, struct path *path)
33059 + struct dentry *d;
33063 + d = path->dentry;
33064 + path->dentry = d->d_parent;
33065 + err = security_path_rmdir(path, d);
33066 + path->dentry = d;
33067 + if (unlikely(err))
33071 + err = vfs_rmdir(dir, path->dentry);
33074 + struct path tmp = {
33075 + .dentry = path->dentry->d_parent,
33079 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33086 +/* ---------------------------------------------------------------------- */
33088 +/* todo: support mmap_sem? */
33089 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33095 + err = vfs_read(file, ubuf, count, ppos);
33098 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33102 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33108 + err = kernel_read(file, kbuf, count, ppos);
33112 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33116 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33122 + err = vfs_write(file, ubuf, count, ppos);
33125 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33129 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33134 + err = kernel_write(file, kbuf, count, ppos);
33137 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33141 +int vfsub_flush(struct file *file, fl_owner_t id)
33146 + if (file->f_op->flush) {
33147 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33148 + err = file->f_op->flush(file, id);
33151 + err = file->f_op->flush(file, id);
33155 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33161 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33165 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33168 + err = iterate_dir(file, ctx);
33171 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33176 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33177 + struct pipe_inode_info *pipe, size_t len,
33178 + unsigned int flags)
33183 + err = do_splice_to(in, ppos, pipe, len, flags);
33185 + file_accessed(in);
33187 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33191 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33192 + loff_t *ppos, size_t len, unsigned int flags)
33197 + err = do_splice_from(pipe, out, ppos, len, flags);
33200 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33204 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33208 + /* file can be NULL */
33210 + err = vfs_fsync(file, datasync);
33214 + AuDebugOn(!file);
33215 + path = &file->f_path;
33217 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33222 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33223 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33224 + struct file *h_file)
33227 + struct inode *h_inode;
33228 + struct super_block *h_sb;
33231 + err = vfsub_truncate(h_path, length);
33235 + h_inode = d_inode(h_path->dentry);
33236 + h_sb = h_inode->i_sb;
33238 + sb_start_write(h_sb);
33240 + err = locks_verify_truncate(h_inode, h_file, length);
33242 + err = security_path_truncate(h_path);
33245 + err = do_truncate(h_path->dentry, length, attr, h_file);
33249 + sb_end_write(h_sb);
33256 +/* ---------------------------------------------------------------------- */
33258 +struct au_vfsub_mkdir_args {
33260 + struct inode *dir;
33261 + struct path *path;
33265 +static void au_call_vfsub_mkdir(void *args)
33267 + struct au_vfsub_mkdir_args *a = args;
33268 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33271 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33273 + int err, do_sio, wkq_err;
33275 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33278 + err = vfsub_mkdir(dir, path, mode);
33281 + struct au_vfsub_mkdir_args args = {
33287 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33288 + if (unlikely(wkq_err))
33295 +struct au_vfsub_rmdir_args {
33297 + struct inode *dir;
33298 + struct path *path;
33301 +static void au_call_vfsub_rmdir(void *args)
33303 + struct au_vfsub_rmdir_args *a = args;
33304 + *a->errp = vfsub_rmdir(a->dir, a->path);
33307 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33309 + int err, do_sio, wkq_err;
33311 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33314 + err = vfsub_rmdir(dir, path);
33317 + struct au_vfsub_rmdir_args args = {
33322 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33323 + if (unlikely(wkq_err))
33330 +/* ---------------------------------------------------------------------- */
33332 +struct notify_change_args {
33334 + struct path *path;
33335 + struct iattr *ia;
33336 + struct inode **delegated_inode;
33339 +static void call_notify_change(void *args)
33341 + struct notify_change_args *a = args;
33342 + struct inode *h_inode;
33344 + h_inode = d_inode(a->path->dentry);
33345 + IMustLock(h_inode);
33347 + *a->errp = -EPERM;
33348 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33350 + *a->errp = notify_change(a->path->dentry, a->ia,
33351 + a->delegated_inode);
33354 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33356 + AuTraceErr(*a->errp);
33359 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33360 + struct inode **delegated_inode)
33363 + struct notify_change_args args = {
33367 + .delegated_inode = delegated_inode
33370 + call_notify_change(&args);
33375 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33376 + struct inode **delegated_inode)
33378 + int err, wkq_err;
33379 + struct notify_change_args args = {
33383 + .delegated_inode = delegated_inode
33386 + wkq_err = au_wkq_wait(call_notify_change, &args);
33387 + if (unlikely(wkq_err))
33393 +/* ---------------------------------------------------------------------- */
33395 +struct unlink_args {
33397 + struct inode *dir;
33398 + struct path *path;
33399 + struct inode **delegated_inode;
33402 +static void call_unlink(void *args)
33404 + struct unlink_args *a = args;
33405 + struct dentry *d = a->path->dentry;
33406 + struct inode *h_inode;
33407 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33408 + && au_dcount(d) == 1);
33410 + IMustLock(a->dir);
33412 + a->path->dentry = d->d_parent;
33413 + *a->errp = security_path_unlink(a->path, d);
33414 + a->path->dentry = d;
33415 + if (unlikely(*a->errp))
33418 + if (!stop_sillyrename)
33421 + if (d_is_positive(d)) {
33422 + h_inode = d_inode(d);
33427 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33430 + struct path tmp = {
33431 + .dentry = d->d_parent,
33432 + .mnt = a->path->mnt
33434 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33437 + if (!stop_sillyrename)
33442 + AuTraceErr(*a->errp);
33446 + * @dir: must be locked.
33447 + * @dentry: target dentry.
33449 +int vfsub_unlink(struct inode *dir, struct path *path,
33450 + struct inode **delegated_inode, int force)
33453 + struct unlink_args args = {
33457 + .delegated_inode = delegated_inode
33461 + call_unlink(&args);
33465 + wkq_err = au_wkq_wait(call_unlink, &args);
33466 + if (unlikely(wkq_err))
33472 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33473 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33474 +++ linux/fs/aufs/vfsub.h 2020-01-27 10:57:18.178871751 +0100
33476 +/* SPDX-License-Identifier: GPL-2.0 */
33478 + * Copyright (C) 2005-2020 Junjiro R. Okajima
33480 + * This program, aufs is free software; you can redistribute it and/or modify
33481 + * it under the terms of the GNU General Public License as published by
33482 + * the Free Software Foundation; either version 2 of the License, or
33483 + * (at your option) any later version.
33485 + * This program is distributed in the hope that it will be useful,
33486 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33487 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33488 + * GNU General Public License for more details.
33490 + * You should have received a copy of the GNU General Public License
33491 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33495 + * sub-routines for VFS
33498 +#ifndef __AUFS_VFSUB_H__
33499 +#define __AUFS_VFSUB_H__
33503 +#include <linux/fs.h>
33504 +#include <linux/mount.h>
33505 +#include <linux/posix_acl.h>
33506 +#include <linux/xattr.h>
33507 +#include "debug.h"
33509 +/* copied from linux/fs/internal.h */
33510 +/* todo: BAD approach!! */
33511 +extern void __mnt_drop_write(struct vfsmount *);
33512 +extern struct file *alloc_empty_file(int, const struct cred *);
33514 +/* ---------------------------------------------------------------------- */
33516 +/* lock subclass for lower inode */
33517 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33518 +/* reduce? gave up. */
33520 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33521 + AuLsc_I_PARENT, /* lower inode, parent first */
33522 + AuLsc_I_PARENT2, /* copyup dirs */
33523 + AuLsc_I_PARENT3, /* copyup wh */
33529 +/* to debug easier, do not make them inlined functions */
33530 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33531 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33533 +/* ---------------------------------------------------------------------- */
33535 +static inline void vfsub_drop_nlink(struct inode *inode)
33537 + AuDebugOn(!inode->i_nlink);
33538 + drop_nlink(inode);
33541 +static inline void vfsub_dead_dir(struct inode *inode)
33543 + AuDebugOn(!S_ISDIR(inode->i_mode));
33544 + inode->i_flags |= S_DEAD;
33545 + clear_nlink(inode);
33548 +static inline int vfsub_native_ro(struct inode *inode)
33550 + return sb_rdonly(inode->i_sb)
33551 + || IS_RDONLY(inode)
33552 + /* || IS_APPEND(inode) */
33553 + || IS_IMMUTABLE(inode);
33556 +#ifdef CONFIG_AUFS_BR_FUSE
33557 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33559 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33562 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33564 +/* ---------------------------------------------------------------------- */
33566 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33567 +struct file *vfsub_dentry_open(struct path *path, int flags);
33568 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33570 +struct vfsub_aopen_args {
33571 + struct file *file;
33572 + unsigned int open_flag;
33573 + umode_t create_mode;
33574 + struct au_branch *br;
33576 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33577 + struct vfsub_aopen_args *args);
33578 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33580 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33581 + struct dentry *parent, int len);
33582 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33585 +struct vfsub_lkup_one_args {
33586 + struct dentry **errp;
33587 + struct qstr *name;
33588 + struct dentry *parent;
33591 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33592 + struct dentry *parent)
33594 + return vfsub_lookup_one_len(name->name, parent, name->len);
33597 +void vfsub_call_lkup_one(void *args);
33599 +/* ---------------------------------------------------------------------- */
33601 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33606 + err = mnt_want_write(mnt);
33611 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33614 + mnt_drop_write(mnt);
33618 +#if 0 /* reserved */
33619 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33622 + mnt_drop_write_file(file);
33627 +/* ---------------------------------------------------------------------- */
33630 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33631 + struct dentry *d2, struct au_hinode *hdir2);
33632 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33633 + struct dentry *d2, struct au_hinode *hdir2);
33635 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33637 +int vfsub_symlink(struct inode *dir, struct path *path,
33638 + const char *symname);
33639 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33640 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33641 + struct path *path, struct inode **delegated_inode);
33642 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33643 + struct inode *hdir, struct path *path,
33644 + struct inode **delegated_inode, unsigned int flags);
33645 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33646 +int vfsub_rmdir(struct inode *dir, struct path *path);
33648 +/* ---------------------------------------------------------------------- */
33650 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33652 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33654 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33656 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33658 +int vfsub_flush(struct file *file, fl_owner_t id);
33659 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33661 +static inline loff_t vfsub_f_size_read(struct file *file)
33663 + return i_size_read(file_inode(file));
33666 +static inline unsigned int vfsub_file_flags(struct file *file)
33668 + unsigned int flags;
33670 + spin_lock(&file->f_lock);
33671 + flags = file->f_flags;
33672 + spin_unlock(&file->f_lock);
33677 +static inline int vfsub_file_execed(struct file *file)
33679 + /* todo: direct access f_flags */
33680 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33683 +#if 0 /* reserved */
33684 +static inline void vfsub_file_accessed(struct file *h_file)
33686 + file_accessed(h_file);
33687 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33691 +#if 0 /* reserved */
33692 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33693 + struct dentry *h_dentry)
33695 + struct path h_path = {
33696 + .dentry = h_dentry,
33699 + touch_atime(&h_path);
33700 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33704 +static inline int vfsub_update_time(struct inode *h_inode,
33705 + struct timespec64 *ts, int flags)
33707 + return update_time(h_inode, ts, flags);
33708 + /* no vfsub_update_h_iattr() since we don't have struct path */
33711 +#ifdef CONFIG_FS_POSIX_ACL
33712 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33716 + err = posix_acl_chmod(h_inode, h_mode);
33717 + if (err == -EOPNOTSUPP)
33722 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33725 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33726 + struct pipe_inode_info *pipe, size_t len,
33727 + unsigned int flags);
33728 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33729 + loff_t *ppos, size_t len, unsigned int flags);
33731 +static inline long vfsub_truncate(struct path *path, loff_t length)
33736 + err = vfs_truncate(path, length);
33741 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33742 + struct file *h_file);
33743 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33746 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33749 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
33755 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
33761 +/* copy_file_range(2) is a systemcall */
33762 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33763 + struct file *dst, loff_t dst_pos,
33764 + size_t len, unsigned int flags)
33769 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33775 +/* ---------------------------------------------------------------------- */
33777 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33782 + err = vfs_llseek(file, offset, origin);
33787 +/* ---------------------------------------------------------------------- */
33789 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33790 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33791 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33792 + struct inode **delegated_inode);
33793 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33794 + struct inode **delegated_inode);
33795 +int vfsub_unlink(struct inode *dir, struct path *path,
33796 + struct inode **delegated_inode, int force);
33798 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
33800 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
33803 +/* ---------------------------------------------------------------------- */
33805 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
33806 + const void *value, size_t size, int flags)
33811 + err = vfs_setxattr(dentry, name, value, size, flags);
33817 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
33822 + err = vfs_removexattr(dentry, name);
33828 +#endif /* __KERNEL__ */
33829 +#endif /* __AUFS_VFSUB_H__ */
33830 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
33831 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
33832 +++ linux/fs/aufs/wbr_policy.c 2020-01-27 10:57:18.178871751 +0100
33834 +// SPDX-License-Identifier: GPL-2.0
33836 + * Copyright (C) 2005-2020 Junjiro R. Okajima
33838 + * This program, aufs is free software; you can redistribute it and/or modify
33839 + * it under the terms of the GNU General Public License as published by
33840 + * the Free Software Foundation; either version 2 of the License, or
33841 + * (at your option) any later version.
33843 + * This program is distributed in the hope that it will be useful,
33844 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33845 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33846 + * GNU General Public License for more details.
33848 + * You should have received a copy of the GNU General Public License
33849 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33853 + * policies for selecting one among multiple writable branches
33856 +#include <linux/statfs.h>
33859 +/* subset of cpup_attr() */
33860 +static noinline_for_stack
33861 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
33865 + struct inode *h_isrc;
33867 + h_isrc = d_inode(h_src);
33868 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
33869 + ia.ia_mode = h_isrc->i_mode;
33870 + ia.ia_uid = h_isrc->i_uid;
33871 + ia.ia_gid = h_isrc->i_gid;
33872 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
33873 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
33874 + /* no delegation since it is just created */
33875 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33877 + /* is this nfs only? */
33878 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
33879 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
33880 + ia.ia_mode = h_isrc->i_mode;
33881 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33887 +#define AuCpdown_PARENT_OPQ 1
33888 +#define AuCpdown_WHED (1 << 1)
33889 +#define AuCpdown_MADE_DIR (1 << 2)
33890 +#define AuCpdown_DIROPQ (1 << 3)
33891 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
33892 +#define au_fset_cpdown(flags, name) \
33893 + do { (flags) |= AuCpdown_##name; } while (0)
33894 +#define au_fclr_cpdown(flags, name) \
33895 + do { (flags) &= ~AuCpdown_##name; } while (0)
33897 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
33898 + unsigned int *flags)
33901 + struct dentry *opq_dentry;
33903 + opq_dentry = au_diropq_create(dentry, bdst);
33904 + err = PTR_ERR(opq_dentry);
33905 + if (IS_ERR(opq_dentry))
33907 + dput(opq_dentry);
33908 + au_fset_cpdown(*flags, DIROPQ);
33914 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
33915 + struct inode *dir, aufs_bindex_t bdst)
33918 + struct path h_path;
33919 + struct au_branch *br;
33921 + br = au_sbr(dentry->d_sb, bdst);
33922 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
33923 + err = PTR_ERR(h_path.dentry);
33924 + if (IS_ERR(h_path.dentry))
33928 + if (d_is_positive(h_path.dentry)) {
33929 + h_path.mnt = au_br_mnt(br);
33930 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
33933 + dput(h_path.dentry);
33939 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
33940 + struct au_pin *pin,
33941 + struct dentry *h_parent, void *arg)
33944 + aufs_bindex_t bopq, btop;
33945 + struct path h_path;
33946 + struct dentry *parent;
33947 + struct inode *h_dir, *h_inode, *inode, *dir;
33948 + unsigned int *flags = arg;
33950 + btop = au_dbtop(dentry);
33951 + /* dentry is di-locked */
33952 + parent = dget_parent(dentry);
33953 + dir = d_inode(parent);
33954 + h_dir = d_inode(h_parent);
33955 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
33956 + IMustLock(h_dir);
33958 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
33959 + if (unlikely(err < 0))
33961 + h_path.dentry = au_h_dptr(dentry, bdst);
33962 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
33963 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
33964 + if (unlikely(err))
33966 + au_fset_cpdown(*flags, MADE_DIR);
33968 + bopq = au_dbdiropq(dentry);
33969 + au_fclr_cpdown(*flags, WHED);
33970 + au_fclr_cpdown(*flags, DIROPQ);
33971 + if (au_dbwh(dentry) == bdst)
33972 + au_fset_cpdown(*flags, WHED);
33973 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
33974 + au_fset_cpdown(*flags, PARENT_OPQ);
33975 + h_inode = d_inode(h_path.dentry);
33976 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
33977 + if (au_ftest_cpdown(*flags, WHED)) {
33978 + err = au_cpdown_dir_opq(dentry, bdst, flags);
33979 + if (unlikely(err)) {
33980 + inode_unlock(h_inode);
33985 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
33986 + inode_unlock(h_inode);
33987 + if (unlikely(err))
33990 + if (au_ftest_cpdown(*flags, WHED)) {
33991 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
33992 + if (unlikely(err))
33996 + inode = d_inode(dentry);
33997 + if (au_ibbot(inode) < bdst)
33998 + au_set_ibbot(inode, bdst);
33999 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34000 + au_hi_flags(inode, /*isdir*/1));
34001 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34002 + goto out; /* success */
34006 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34007 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34008 + rerr = au_diropq_remove(dentry, bdst);
34009 + inode_unlock(h_inode);
34010 + if (unlikely(rerr)) {
34011 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34012 + dentry, bdst, rerr);
34018 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34019 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34020 + if (unlikely(rerr)) {
34021 + AuIOErr("failed removing %pd b%d (%d)\n",
34022 + dentry, bdst, rerr);
34027 + au_set_h_dptr(dentry, bdst, NULL);
34028 + if (au_dbbot(dentry) == bdst)
34029 + au_update_dbbot(dentry);
34035 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34038 + unsigned int flags;
34041 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34046 +/* ---------------------------------------------------------------------- */
34048 +/* policies for create */
34050 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34052 + int err, i, j, ndentry;
34053 + aufs_bindex_t bopq;
34054 + struct au_dcsub_pages dpages;
34055 + struct au_dpage *dpage;
34056 + struct dentry **dentries, *parent, *d;
34058 + err = au_dpages_init(&dpages, GFP_NOFS);
34059 + if (unlikely(err))
34061 + parent = dget_parent(dentry);
34062 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34063 + if (unlikely(err))
34067 + for (i = 0; i < dpages.ndpage; i++) {
34068 + dpage = dpages.dpages + i;
34069 + dentries = dpage->dentries;
34070 + ndentry = dpage->ndentry;
34071 + for (j = 0; j < ndentry; j++) {
34073 + di_read_lock_parent2(d, !AuLock_IR);
34074 + bopq = au_dbdiropq(d);
34075 + di_read_unlock(d, !AuLock_IR);
34076 + if (bopq >= 0 && bopq < err)
34083 + au_dpages_free(&dpages);
34088 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34090 + for (; bindex >= 0; bindex--)
34091 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34096 +/* top down parent */
34097 +static int au_wbr_create_tdp(struct dentry *dentry,
34098 + unsigned int flags __maybe_unused)
34101 + aufs_bindex_t btop, bindex;
34102 + struct super_block *sb;
34103 + struct dentry *parent, *h_parent;
34105 + sb = dentry->d_sb;
34106 + btop = au_dbtop(dentry);
34108 + if (!au_br_rdonly(au_sbr(sb, btop)))
34112 + parent = dget_parent(dentry);
34113 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34114 + h_parent = au_h_dptr(parent, bindex);
34115 + if (!h_parent || d_is_negative(h_parent))
34118 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34125 + /* bottom up here */
34126 + if (unlikely(err < 0)) {
34127 + err = au_wbr_bu(sb, btop - 1);
34129 + err = au_wbr_nonopq(dentry, err);
34133 + AuDbg("b%d\n", err);
34137 +/* ---------------------------------------------------------------------- */
34139 +/* an exception for the policy other than tdp */
34140 +static int au_wbr_create_exp(struct dentry *dentry)
34143 + aufs_bindex_t bwh, bdiropq;
34144 + struct dentry *parent;
34147 + bwh = au_dbwh(dentry);
34148 + parent = dget_parent(dentry);
34149 + bdiropq = au_dbdiropq(parent);
34151 + if (bdiropq >= 0)
34152 + err = min(bdiropq, bwh);
34155 + AuDbg("%d\n", err);
34156 + } else if (bdiropq >= 0) {
34158 + AuDbg("%d\n", err);
34163 + err = au_wbr_nonopq(dentry, err);
34165 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34168 + AuDbg("%d\n", err);
34172 +/* ---------------------------------------------------------------------- */
34175 +static int au_wbr_create_init_rr(struct super_block *sb)
34179 + err = au_wbr_bu(sb, au_sbbot(sb));
34180 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34183 + AuDbg("b%d\n", err);
34187 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34191 + aufs_bindex_t bindex, bbot;
34192 + struct super_block *sb;
34195 + err = au_wbr_create_exp(dentry);
34199 + sb = dentry->d_sb;
34200 + next = &au_sbi(sb)->si_wbr_rr_next;
34201 + bbot = au_sbbot(sb);
34203 + for (bindex = 0; bindex <= bbot; bindex++) {
34204 + if (!au_ftest_wbr(flags, DIR)) {
34205 + err = atomic_dec_return(next) + 1;
34206 + /* modulo for 0 is meaningless */
34207 + if (unlikely(!err))
34208 + err = atomic_dec_return(next) + 1;
34210 + err = atomic_read(next);
34211 + AuDbg("%d\n", err);
34214 + AuDbg("%d\n", err);
34215 + if (!au_br_rdonly(au_sbr(sb, err)))
34221 + err = au_wbr_nonopq(dentry, err);
34224 + AuDbg("%d\n", err);
34228 +/* ---------------------------------------------------------------------- */
34230 +/* most free space */
34231 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34233 + struct super_block *sb;
34234 + struct au_branch *br;
34235 + struct au_wbr_mfs *mfs;
34236 + struct dentry *h_parent;
34237 + aufs_bindex_t bindex, bbot;
34239 + unsigned long long b, bavail;
34240 + struct path h_path;
34241 + /* reduce the stack usage */
34242 + struct kstatfs *st;
34244 + st = kmalloc(sizeof(*st), GFP_NOFS);
34245 + if (unlikely(!st)) {
34246 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34251 + sb = dentry->d_sb;
34252 + mfs = &au_sbi(sb)->si_wbr_mfs;
34253 + MtxMustLock(&mfs->mfs_lock);
34254 + mfs->mfs_bindex = -EROFS;
34255 + mfs->mfsrr_bytes = 0;
34258 + bbot = au_sbbot(sb);
34260 + bindex = au_dbtop(parent);
34261 + bbot = au_dbtaildir(parent);
34264 + for (; bindex <= bbot; bindex++) {
34266 + h_parent = au_h_dptr(parent, bindex);
34267 + if (!h_parent || d_is_negative(h_parent))
34270 + br = au_sbr(sb, bindex);
34271 + if (au_br_rdonly(br))
34274 + /* sb->s_root for NFS is unreliable */
34275 + h_path.mnt = au_br_mnt(br);
34276 + h_path.dentry = h_path.mnt->mnt_root;
34277 + err = vfs_statfs(&h_path, st);
34278 + if (unlikely(err)) {
34279 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34283 + /* when the available size is equal, select the lower one */
34284 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34285 + || sizeof(b) < sizeof(st->f_bsize));
34286 + b = st->f_bavail * st->f_bsize;
34287 + br->br_wbr->wbr_bytes = b;
34288 + if (b >= bavail) {
34290 + mfs->mfs_bindex = bindex;
34291 + mfs->mfs_jiffy = jiffies;
34295 + mfs->mfsrr_bytes = bavail;
34296 + AuDbg("b%d\n", mfs->mfs_bindex);
34297 + au_kfree_rcu(st);
34300 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34303 + struct dentry *parent;
34304 + struct super_block *sb;
34305 + struct au_wbr_mfs *mfs;
34307 + err = au_wbr_create_exp(dentry);
34311 + sb = dentry->d_sb;
34313 + if (au_ftest_wbr(flags, PARENT))
34314 + parent = dget_parent(dentry);
34315 + mfs = &au_sbi(sb)->si_wbr_mfs;
34316 + mutex_lock(&mfs->mfs_lock);
34317 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34318 + || mfs->mfs_bindex < 0
34319 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34320 + au_mfs(dentry, parent);
34321 + mutex_unlock(&mfs->mfs_lock);
34322 + err = mfs->mfs_bindex;
34326 + err = au_wbr_nonopq(dentry, err);
34329 + AuDbg("b%d\n", err);
34333 +static int au_wbr_create_init_mfs(struct super_block *sb)
34335 + struct au_wbr_mfs *mfs;
34337 + mfs = &au_sbi(sb)->si_wbr_mfs;
34338 + mutex_init(&mfs->mfs_lock);
34339 + mfs->mfs_jiffy = 0;
34340 + mfs->mfs_bindex = -EROFS;
34345 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34347 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34351 +/* ---------------------------------------------------------------------- */
34353 +/* top down regardless parent, and then mfs */
34354 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34355 + unsigned int flags __maybe_unused)
34358 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34359 + unsigned long long watermark;
34360 + struct super_block *sb;
34361 + struct au_wbr_mfs *mfs;
34362 + struct au_branch *br;
34363 + struct dentry *parent;
34365 + sb = dentry->d_sb;
34366 + mfs = &au_sbi(sb)->si_wbr_mfs;
34367 + mutex_lock(&mfs->mfs_lock);
34368 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34369 + || mfs->mfs_bindex < 0)
34370 + au_mfs(dentry, /*parent*/NULL);
34371 + watermark = mfs->mfsrr_watermark;
34372 + bmfs = mfs->mfs_bindex;
34373 + mutex_unlock(&mfs->mfs_lock);
34375 + /* another style of au_wbr_create_exp() */
34376 + bwh = au_dbwh(dentry);
34377 + parent = dget_parent(dentry);
34378 + btail = au_dbtaildir(parent);
34379 + if (bwh >= 0 && bwh < btail)
34382 + err = au_wbr_nonopq(dentry, btail);
34383 + if (unlikely(err < 0))
34387 + for (bindex = 0; bindex <= btail; bindex++) {
34388 + br = au_sbr(sb, bindex);
34389 + if (au_br_rdonly(br))
34391 + if (br->br_wbr->wbr_bytes > watermark) {
34402 + AuDbg("b%d\n", err);
34406 +/* ---------------------------------------------------------------------- */
34408 +/* most free space and then round robin */
34409 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34412 + struct au_wbr_mfs *mfs;
34414 + err = au_wbr_create_mfs(dentry, flags);
34416 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34417 + mutex_lock(&mfs->mfs_lock);
34418 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34419 + err = au_wbr_create_rr(dentry, flags);
34420 + mutex_unlock(&mfs->mfs_lock);
34423 + AuDbg("b%d\n", err);
34427 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34431 + au_wbr_create_init_mfs(sb); /* ignore */
34432 + err = au_wbr_create_init_rr(sb);
34437 +/* ---------------------------------------------------------------------- */
34439 +/* top down parent and most free space */
34440 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34443 + unsigned long long b;
34444 + aufs_bindex_t bindex, btop, bbot;
34445 + struct super_block *sb;
34446 + struct dentry *parent, *h_parent;
34447 + struct au_branch *br;
34449 + err = au_wbr_create_tdp(dentry, flags);
34450 + if (unlikely(err < 0))
34452 + parent = dget_parent(dentry);
34453 + btop = au_dbtop(parent);
34454 + bbot = au_dbtaildir(parent);
34455 + if (btop == bbot)
34456 + goto out_parent; /* success */
34458 + e2 = au_wbr_create_mfs(dentry, flags);
34460 + goto out_parent; /* success */
34462 + /* when the available size is equal, select upper one */
34463 + sb = dentry->d_sb;
34464 + br = au_sbr(sb, err);
34465 + b = br->br_wbr->wbr_bytes;
34466 + AuDbg("b%d, %llu\n", err, b);
34468 + for (bindex = btop; bindex <= bbot; bindex++) {
34469 + h_parent = au_h_dptr(parent, bindex);
34470 + if (!h_parent || d_is_negative(h_parent))
34473 + br = au_sbr(sb, bindex);
34474 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34475 + b = br->br_wbr->wbr_bytes;
34477 + AuDbg("b%d, %llu\n", err, b);
34482 + err = au_wbr_nonopq(dentry, err);
34487 + AuDbg("b%d\n", err);
34491 +/* ---------------------------------------------------------------------- */
34494 + * - top down parent
34495 + * - most free space with parent
34496 + * - most free space round-robin regardless parent
34498 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34501 + unsigned long long watermark;
34502 + struct super_block *sb;
34503 + struct au_branch *br;
34504 + struct au_wbr_mfs *mfs;
34506 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34507 + if (unlikely(err < 0))
34510 + sb = dentry->d_sb;
34511 + br = au_sbr(sb, err);
34512 + mfs = &au_sbi(sb)->si_wbr_mfs;
34513 + mutex_lock(&mfs->mfs_lock);
34514 + watermark = mfs->mfsrr_watermark;
34515 + mutex_unlock(&mfs->mfs_lock);
34516 + if (br->br_wbr->wbr_bytes < watermark)
34517 + /* regardless the parent dir */
34518 + err = au_wbr_create_mfsrr(dentry, flags);
34521 + AuDbg("b%d\n", err);
34525 +/* ---------------------------------------------------------------------- */
34527 +/* policies for copyup */
34529 +/* top down parent */
34530 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34532 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34535 +/* bottom up parent */
34536 +static int au_wbr_copyup_bup(struct dentry *dentry)
34539 + aufs_bindex_t bindex, btop;
34540 + struct dentry *parent, *h_parent;
34541 + struct super_block *sb;
34544 + sb = dentry->d_sb;
34545 + parent = dget_parent(dentry);
34546 + btop = au_dbtop(parent);
34547 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34548 + h_parent = au_h_dptr(parent, bindex);
34549 + if (!h_parent || d_is_negative(h_parent))
34552 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34559 + /* bottom up here */
34560 + if (unlikely(err < 0))
34561 + err = au_wbr_bu(sb, btop - 1);
34563 + AuDbg("b%d\n", err);
34568 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34572 + err = au_wbr_bu(dentry->d_sb, btop);
34573 + AuDbg("b%d\n", err);
34575 + err = au_wbr_nonopq(dentry, err);
34577 + AuDbg("b%d\n", err);
34581 +static int au_wbr_copyup_bu(struct dentry *dentry)
34584 + aufs_bindex_t btop;
34586 + btop = au_dbtop(dentry);
34587 + err = au_wbr_do_copyup_bu(dentry, btop);
34591 +/* ---------------------------------------------------------------------- */
34593 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34594 + [AuWbrCopyup_TDP] = {
34595 + .copyup = au_wbr_copyup_tdp
34597 + [AuWbrCopyup_BUP] = {
34598 + .copyup = au_wbr_copyup_bup
34600 + [AuWbrCopyup_BU] = {
34601 + .copyup = au_wbr_copyup_bu
34605 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34606 + [AuWbrCreate_TDP] = {
34607 + .create = au_wbr_create_tdp
34609 + [AuWbrCreate_RR] = {
34610 + .create = au_wbr_create_rr,
34611 + .init = au_wbr_create_init_rr
34613 + [AuWbrCreate_MFS] = {
34614 + .create = au_wbr_create_mfs,
34615 + .init = au_wbr_create_init_mfs,
34616 + .fin = au_wbr_create_fin_mfs
34618 + [AuWbrCreate_MFSV] = {
34619 + .create = au_wbr_create_mfs,
34620 + .init = au_wbr_create_init_mfs,
34621 + .fin = au_wbr_create_fin_mfs
34623 + [AuWbrCreate_MFSRR] = {
34624 + .create = au_wbr_create_mfsrr,
34625 + .init = au_wbr_create_init_mfsrr,
34626 + .fin = au_wbr_create_fin_mfs
34628 + [AuWbrCreate_MFSRRV] = {
34629 + .create = au_wbr_create_mfsrr,
34630 + .init = au_wbr_create_init_mfsrr,
34631 + .fin = au_wbr_create_fin_mfs
34633 + [AuWbrCreate_TDMFS] = {
34634 + .create = au_wbr_create_tdmfs,
34635 + .init = au_wbr_create_init_mfs,
34636 + .fin = au_wbr_create_fin_mfs
34638 + [AuWbrCreate_TDMFSV] = {
34639 + .create = au_wbr_create_tdmfs,
34640 + .init = au_wbr_create_init_mfs,
34641 + .fin = au_wbr_create_fin_mfs
34643 + [AuWbrCreate_PMFS] = {
34644 + .create = au_wbr_create_pmfs,
34645 + .init = au_wbr_create_init_mfs,
34646 + .fin = au_wbr_create_fin_mfs
34648 + [AuWbrCreate_PMFSV] = {
34649 + .create = au_wbr_create_pmfs,
34650 + .init = au_wbr_create_init_mfs,
34651 + .fin = au_wbr_create_fin_mfs
34653 + [AuWbrCreate_PMFSRR] = {
34654 + .create = au_wbr_create_pmfsrr,
34655 + .init = au_wbr_create_init_mfsrr,
34656 + .fin = au_wbr_create_fin_mfs
34658 + [AuWbrCreate_PMFSRRV] = {
34659 + .create = au_wbr_create_pmfsrr,
34660 + .init = au_wbr_create_init_mfsrr,
34661 + .fin = au_wbr_create_fin_mfs
34664 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34665 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34666 +++ linux/fs/aufs/whout.c 2020-01-27 10:57:18.178871751 +0100
34668 +// SPDX-License-Identifier: GPL-2.0
34670 + * Copyright (C) 2005-2020 Junjiro R. Okajima
34672 + * This program, aufs is free software; you can redistribute it and/or modify
34673 + * it under the terms of the GNU General Public License as published by
34674 + * the Free Software Foundation; either version 2 of the License, or
34675 + * (at your option) any later version.
34677 + * This program is distributed in the hope that it will be useful,
34678 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34679 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34680 + * GNU General Public License for more details.
34682 + * You should have received a copy of the GNU General Public License
34683 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34687 + * whiteout for logical deletion and opaque directory
34692 +#define WH_MASK 0444
34695 + * If a directory contains this file, then it is opaque. We start with the
34696 + * .wh. flag so that it is blocked by lookup.
34698 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34699 + sizeof(AUFS_WH_DIROPQ) - 1);
34702 + * generate whiteout name, which is NOT terminated by NULL.
34703 + * @name: original d_name.name
34704 + * @len: original d_name.len
34705 + * @wh: whiteout qstr
34706 + * returns zero when succeeds, otherwise error.
34707 + * succeeded value as wh->name should be freed by kfree().
34709 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34713 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34714 + return -ENAMETOOLONG;
34716 + wh->len = name->len + AUFS_WH_PFX_LEN;
34717 + p = kmalloc(wh->len, GFP_NOFS);
34720 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34721 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34728 +/* ---------------------------------------------------------------------- */
34731 + * test if the @wh_name exists under @h_parent.
34732 + * @try_sio specifies the necessary of super-io.
34734 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
34737 + struct dentry *wh_dentry;
34740 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34742 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
34743 + err = PTR_ERR(wh_dentry);
34744 + if (IS_ERR(wh_dentry)) {
34745 + if (err == -ENAMETOOLONG)
34751 + if (d_is_negative(wh_dentry))
34752 + goto out_wh; /* success */
34755 + if (d_is_reg(wh_dentry))
34756 + goto out_wh; /* success */
34759 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34760 + wh_dentry, d_inode(wh_dentry)->i_mode);
34769 + * test if the @h_dentry sets opaque or not.
34771 +int au_diropq_test(struct dentry *h_dentry)
34774 + struct inode *h_dir;
34776 + h_dir = d_inode(h_dentry);
34777 + err = au_wh_test(h_dentry, &diropq_name,
34778 + au_test_h_perm_sio(h_dir, MAY_EXEC));
34783 + * returns a negative dentry whose name is unique and temporary.
34785 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34786 + struct qstr *prefix)
34788 + struct dentry *dentry;
34790 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34792 + /* strict atomic_t is unnecessary here */
34793 + static unsigned short cnt;
34796 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34799 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34800 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34801 + dentry = ERR_PTR(-ENAMETOOLONG);
34802 + if (unlikely(qs.len > NAME_MAX))
34804 + dentry = ERR_PTR(-ENOMEM);
34805 + name = kmalloc(qs.len + 1, GFP_NOFS);
34806 + if (unlikely(!name))
34810 + /* doubly whiteout-ed */
34811 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34812 + p = name + AUFS_WH_PFX_LEN * 2;
34813 + memcpy(p, prefix->name, prefix->len);
34814 + p += prefix->len;
34816 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34819 + for (i = 0; i < 3; i++) {
34820 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34821 + dentry = au_sio_lkup_one(&qs, h_parent);
34822 + if (IS_ERR(dentry) || d_is_negative(dentry))
34826 + /* pr_warn("could not get random name\n"); */
34827 + dentry = ERR_PTR(-EEXIST);
34828 + AuDbg("%.*s\n", AuLNPair(&qs));
34832 + if (name != defname)
34833 + au_kfree_try_rcu(name);
34835 + AuTraceErrPtr(dentry);
34840 + * rename the @h_dentry on @br to the whiteouted temporary name.
34842 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
34845 + struct path h_path = {
34846 + .mnt = au_br_mnt(br)
34848 + struct inode *h_dir, *delegated;
34849 + struct dentry *h_parent;
34851 + h_parent = h_dentry->d_parent; /* dir inode is locked */
34852 + h_dir = d_inode(h_parent);
34853 + IMustLock(h_dir);
34855 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
34856 + err = PTR_ERR(h_path.dentry);
34857 + if (IS_ERR(h_path.dentry))
34860 + /* under the same dir, no need to lock_rename() */
34861 + delegated = NULL;
34862 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
34865 + if (unlikely(err == -EWOULDBLOCK)) {
34866 + pr_warn("cannot retry for NFSv4 delegation"
34867 + " for an internal rename\n");
34870 + dput(h_path.dentry);
34877 +/* ---------------------------------------------------------------------- */
34879 + * functions for removing a whiteout
34882 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
34885 + struct inode *delegated;
34888 + * forces superio when the dir has a sticky bit.
34889 + * this may be a violation of unix fs semantics.
34891 + force = (h_dir->i_mode & S_ISVTX)
34892 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
34893 + delegated = NULL;
34894 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
34895 + if (unlikely(err == -EWOULDBLOCK)) {
34896 + pr_warn("cannot retry for NFSv4 delegation"
34897 + " for an internal unlink\n");
34903 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
34904 + struct dentry *dentry)
34908 + err = do_unlink_wh(h_dir, h_path);
34909 + if (!err && dentry)
34910 + au_set_dbwh(dentry, -1);
34915 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
34916 + struct au_branch *br)
34919 + struct path h_path = {
34920 + .mnt = au_br_mnt(br)
34924 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
34925 + if (IS_ERR(h_path.dentry))
34926 + err = PTR_ERR(h_path.dentry);
34928 + if (d_is_reg(h_path.dentry))
34929 + err = do_unlink_wh(d_inode(h_parent), &h_path);
34930 + dput(h_path.dentry);
34936 +/* ---------------------------------------------------------------------- */
34938 + * initialize/clean whiteout for a branch
34941 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
34945 + struct inode *delegated;
34947 + if (d_is_negative(whpath->dentry))
34951 + err = vfsub_rmdir(h_dir, whpath);
34953 + delegated = NULL;
34954 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
34955 + if (unlikely(err == -EWOULDBLOCK)) {
34956 + pr_warn("cannot retry for NFSv4 delegation"
34957 + " for an internal unlink\n");
34961 + if (unlikely(err))
34962 + pr_warn("failed removing %pd (%d), ignored.\n",
34963 + whpath->dentry, err);
34966 +static int test_linkable(struct dentry *h_root)
34968 + struct inode *h_dir = d_inode(h_root);
34970 + if (h_dir->i_op->link)
34973 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
34974 + h_root, au_sbtype(h_root->d_sb));
34975 + return -ENOSYS; /* the branch doesn't have its ->link() */
34978 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
34979 +static int au_whdir(struct inode *h_dir, struct path *path)
34984 + if (d_is_negative(path->dentry)) {
34987 + if (au_test_nfs(path->dentry->d_sb))
34989 + err = vfsub_mkdir(h_dir, path, mode);
34990 + } else if (d_is_dir(path->dentry))
34993 + pr_err("unknown %pd exists\n", path->dentry);
34998 +struct au_wh_base {
34999 + const struct qstr *name;
35000 + struct dentry *dentry;
35003 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35004 + struct path *h_path)
35006 + h_path->dentry = base[AuBrWh_BASE].dentry;
35007 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35008 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35009 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35010 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35011 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35015 + * returns tri-state,
35016 + * minus: error, caller should print the message
35018 + * plus: error, caller should NOT print the message
35020 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35021 + int do_plink, struct au_wh_base base[],
35022 + struct path *h_path)
35025 + struct inode *h_dir;
35027 + h_dir = d_inode(h_root);
35028 + h_path->dentry = base[AuBrWh_BASE].dentry;
35029 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35030 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35032 + err = test_linkable(h_root);
35033 + if (unlikely(err)) {
35038 + err = au_whdir(h_dir, h_path);
35039 + if (unlikely(err))
35041 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35043 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35044 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35045 + err = au_whdir(h_dir, h_path);
35046 + if (unlikely(err))
35048 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35055 + * for the moment, aufs supports the branch filesystem which does not support
35056 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35057 + * copyup failed. finally, such filesystem will not be used as the writable
35060 + * returns tri-state, see above.
35062 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35063 + int do_plink, struct au_wh_base base[],
35064 + struct path *h_path)
35067 + struct inode *h_dir;
35069 + WbrWhMustWriteLock(wbr);
35071 + err = test_linkable(h_root);
35072 + if (unlikely(err)) {
35078 + * todo: should this create be done in /sbin/mount.aufs helper?
35081 + h_dir = d_inode(h_root);
35082 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35083 + h_path->dentry = base[AuBrWh_BASE].dentry;
35084 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35085 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35088 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35089 + if (unlikely(err))
35092 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35094 + err = au_whdir(h_dir, h_path);
35095 + if (unlikely(err))
35097 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35099 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35100 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35102 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35103 + err = au_whdir(h_dir, h_path);
35104 + if (unlikely(err))
35106 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35113 + * initialize the whiteout base file/dir for @br.
35115 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35118 + const unsigned char do_plink
35119 + = !!au_opt_test(au_mntflags(sb), PLINK);
35120 + struct inode *h_dir;
35121 + struct path path = br->br_path;
35122 + struct dentry *h_root = path.dentry;
35123 + struct au_wbr *wbr = br->br_wbr;
35124 + static const struct qstr base_name[] = {
35125 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35126 + sizeof(AUFS_BASE_NAME) - 1),
35127 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35128 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35129 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35130 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35132 + struct au_wh_base base[] = {
35133 + [AuBrWh_BASE] = {
35134 + .name = base_name + AuBrWh_BASE,
35137 + [AuBrWh_PLINK] = {
35138 + .name = base_name + AuBrWh_PLINK,
35141 + [AuBrWh_ORPH] = {
35142 + .name = base_name + AuBrWh_ORPH,
35148 + WbrWhMustWriteLock(wbr);
35150 + for (i = 0; i < AuBrWh_Last; i++) {
35151 + /* doubly whiteouted */
35152 + struct dentry *d;
35154 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35155 + err = PTR_ERR(d);
35159 + base[i].dentry = d;
35161 + && wbr->wbr_wh[i]
35162 + && wbr->wbr_wh[i] != base[i].dentry);
35166 + for (i = 0; i < AuBrWh_Last; i++) {
35167 + dput(wbr->wbr_wh[i]);
35168 + wbr->wbr_wh[i] = NULL;
35172 + if (!au_br_writable(br->br_perm)) {
35173 + h_dir = d_inode(h_root);
35174 + au_wh_init_ro(h_dir, base, &path);
35175 + } else if (!au_br_wh_linkable(br->br_perm)) {
35176 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35182 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35188 + goto out; /* success */
35191 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35192 + err, h_root, au_sbtype(h_root->d_sb));
35194 + for (i = 0; i < AuBrWh_Last; i++)
35195 + dput(base[i].dentry);
35199 +/* ---------------------------------------------------------------------- */
35201 + * whiteouts are all hard-linked usually.
35202 + * when its link count reaches a ceiling, we create a new whiteout base
35203 + * asynchronously.
35206 +struct reinit_br_wh {
35207 + struct super_block *sb;
35208 + struct au_branch *br;
35211 +static void reinit_br_wh(void *arg)
35214 + aufs_bindex_t bindex;
35215 + struct path h_path;
35216 + struct reinit_br_wh *a = arg;
35217 + struct au_wbr *wbr;
35218 + struct inode *dir, *delegated;
35219 + struct dentry *h_root;
35220 + struct au_hinode *hdir;
35223 + wbr = a->br->br_wbr;
35224 + /* big aufs lock */
35225 + si_noflush_write_lock(a->sb);
35226 + if (!au_br_writable(a->br->br_perm))
35228 + bindex = au_br_index(a->sb, a->br->br_id);
35229 + if (unlikely(bindex < 0))
35232 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35233 + dir = d_inode(a->sb->s_root);
35234 + hdir = au_hi(dir, bindex);
35235 + h_root = au_h_dptr(a->sb->s_root, bindex);
35236 + AuDebugOn(h_root != au_br_dentry(a->br));
35238 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35239 + wbr_wh_write_lock(wbr);
35240 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35243 + h_path.dentry = wbr->wbr_whbase;
35244 + h_path.mnt = au_br_mnt(a->br);
35245 + delegated = NULL;
35246 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35248 + if (unlikely(err == -EWOULDBLOCK)) {
35249 + pr_warn("cannot retry for NFSv4 delegation"
35250 + " for an internal unlink\n");
35254 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35257 + dput(wbr->wbr_whbase);
35258 + wbr->wbr_whbase = NULL;
35260 + err = au_wh_init(a->br, a->sb);
35261 + wbr_wh_write_unlock(wbr);
35262 + au_hn_inode_unlock(hdir);
35263 + di_read_unlock(a->sb->s_root, AuLock_IR);
35265 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35269 + atomic_dec(&wbr->wbr_wh_running);
35270 + au_lcnt_dec(&a->br->br_count);
35271 + si_write_unlock(a->sb);
35272 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35274 + if (unlikely(err))
35275 + AuIOErr("err %d\n", err);
35278 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35280 + int do_dec, wkq_err;
35281 + struct reinit_br_wh *arg;
35284 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35287 + /* ignore ENOMEM */
35288 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35291 + * dec(wh_running), kfree(arg) and dec(br_count)
35292 + * in reinit function
35296 + au_lcnt_inc(&br->br_count);
35297 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35298 + if (unlikely(wkq_err)) {
35299 + atomic_dec(&br->br_wbr->wbr_wh_running);
35300 + au_lcnt_dec(&br->br_count);
35301 + au_kfree_rcu(arg);
35308 + atomic_dec(&br->br_wbr->wbr_wh_running);
35311 +/* ---------------------------------------------------------------------- */
35314 + * create the whiteout @wh.
35316 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35317 + struct dentry *wh)
35320 + struct path h_path = {
35323 + struct au_branch *br;
35324 + struct au_wbr *wbr;
35325 + struct dentry *h_parent;
35326 + struct inode *h_dir, *delegated;
35328 + h_parent = wh->d_parent; /* dir inode is locked */
35329 + h_dir = d_inode(h_parent);
35330 + IMustLock(h_dir);
35332 + br = au_sbr(sb, bindex);
35333 + h_path.mnt = au_br_mnt(br);
35334 + wbr = br->br_wbr;
35335 + wbr_wh_read_lock(wbr);
35336 + if (wbr->wbr_whbase) {
35337 + delegated = NULL;
35338 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35339 + if (unlikely(err == -EWOULDBLOCK)) {
35340 + pr_warn("cannot retry for NFSv4 delegation"
35341 + " for an internal link\n");
35344 + if (!err || err != -EMLINK)
35347 + /* link count full. re-initialize br_whbase. */
35348 + kick_reinit_br_wh(sb, br);
35351 + /* return this error in this context */
35352 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35354 + au_fhsm_wrote(sb, bindex, /*force*/0);
35357 + wbr_wh_read_unlock(wbr);
35361 +/* ---------------------------------------------------------------------- */
35364 + * create or remove the diropq.
35366 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35367 + unsigned int flags)
35369 + struct dentry *opq_dentry, *h_dentry;
35370 + struct super_block *sb;
35371 + struct au_branch *br;
35374 + sb = dentry->d_sb;
35375 + br = au_sbr(sb, bindex);
35376 + h_dentry = au_h_dptr(dentry, bindex);
35377 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35378 + if (IS_ERR(opq_dentry))
35381 + if (au_ftest_diropq(flags, CREATE)) {
35382 + err = link_or_create_wh(sb, bindex, opq_dentry);
35384 + au_set_dbdiropq(dentry, bindex);
35385 + goto out; /* success */
35388 + struct path tmp = {
35389 + .dentry = opq_dentry,
35390 + .mnt = au_br_mnt(br)
35392 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35394 + au_set_dbdiropq(dentry, -1);
35396 + dput(opq_dentry);
35397 + opq_dentry = ERR_PTR(err);
35400 + return opq_dentry;
35403 +struct do_diropq_args {
35404 + struct dentry **errp;
35405 + struct dentry *dentry;
35406 + aufs_bindex_t bindex;
35407 + unsigned int flags;
35410 +static void call_do_diropq(void *args)
35412 + struct do_diropq_args *a = args;
35413 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35416 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35417 + unsigned int flags)
35419 + struct dentry *diropq, *h_dentry;
35421 + h_dentry = au_h_dptr(dentry, bindex);
35422 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35423 + diropq = do_diropq(dentry, bindex, flags);
35426 + struct do_diropq_args args = {
35428 + .dentry = dentry,
35429 + .bindex = bindex,
35433 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35434 + if (unlikely(wkq_err))
35435 + diropq = ERR_PTR(wkq_err);
35441 +/* ---------------------------------------------------------------------- */
35444 + * lookup whiteout dentry.
35445 + * @h_parent: lower parent dentry which must exist and be locked
35446 + * @base_name: name of dentry which will be whiteouted
35447 + * returns dentry for whiteout.
35449 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35450 + struct au_branch *br)
35453 + struct qstr wh_name;
35454 + struct dentry *wh_dentry;
35456 + err = au_wh_name_alloc(&wh_name, base_name);
35457 + wh_dentry = ERR_PTR(err);
35459 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35460 + au_kfree_try_rcu(wh_name.name);
35462 + return wh_dentry;
35466 + * link/create a whiteout for @dentry on @bindex.
35468 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35469 + struct dentry *h_parent)
35471 + struct dentry *wh_dentry;
35472 + struct super_block *sb;
35475 + sb = dentry->d_sb;
35476 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35477 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35478 + err = link_or_create_wh(sb, bindex, wh_dentry);
35480 + au_set_dbwh(dentry, bindex);
35481 + au_fhsm_wrote(sb, bindex, /*force*/0);
35484 + wh_dentry = ERR_PTR(err);
35488 + return wh_dentry;
35491 +/* ---------------------------------------------------------------------- */
35493 +/* Delete all whiteouts in this directory on branch bindex. */
35494 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35495 + aufs_bindex_t bindex, struct au_branch *br)
35498 + unsigned long ul, n;
35499 + struct qstr wh_name;
35501 + struct hlist_head *head;
35502 + struct au_vdir_wh *pos;
35503 + struct au_vdir_destr *str;
35506 + p = (void *)__get_free_page(GFP_NOFS);
35507 + wh_name.name = p;
35508 + if (unlikely(!wh_name.name))
35512 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35513 + p += AUFS_WH_PFX_LEN;
35514 + n = whlist->nh_num;
35515 + head = whlist->nh_head;
35516 + for (ul = 0; !err && ul < n; ul++, head++) {
35517 + hlist_for_each_entry(pos, head, wh_hash) {
35518 + if (pos->wh_bindex != bindex)
35521 + str = &pos->wh_str;
35522 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35523 + memcpy(p, str->name, str->len);
35524 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35525 + err = unlink_wh_name(h_dentry, &wh_name, br);
35530 + AuIOErr("whiteout name too long %.*s\n",
35531 + str->len, str->name);
35536 + free_page((unsigned long)wh_name.name);
35542 +struct del_wh_children_args {
35544 + struct dentry *h_dentry;
35545 + struct au_nhash *whlist;
35546 + aufs_bindex_t bindex;
35547 + struct au_branch *br;
35550 +static void call_del_wh_children(void *args)
35552 + struct del_wh_children_args *a = args;
35553 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35556 +/* ---------------------------------------------------------------------- */
35558 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35560 + struct au_whtmp_rmdir *whtmp;
35562 + unsigned int rdhash;
35564 + SiMustAnyLock(sb);
35566 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35567 + if (unlikely(!whtmp)) {
35568 + whtmp = ERR_PTR(-ENOMEM);
35572 + /* no estimation for dir size */
35573 + rdhash = au_sbi(sb)->si_rdhash;
35575 + rdhash = AUFS_RDHASH_DEF;
35576 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35577 + if (unlikely(err)) {
35578 + au_kfree_rcu(whtmp);
35579 + whtmp = ERR_PTR(err);
35586 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35589 + au_lcnt_dec(&whtmp->br->br_count);
35590 + dput(whtmp->wh_dentry);
35591 + iput(whtmp->dir);
35592 + au_nhash_wh_free(&whtmp->whlist);
35593 + au_kfree_rcu(whtmp);
35597 + * rmdir the whiteouted temporary named dir @h_dentry.
35598 + * @whlist: whiteouted children.
35600 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35601 + struct dentry *wh_dentry, struct au_nhash *whlist)
35604 + unsigned int h_nlink;
35605 + struct path h_tmp;
35606 + struct inode *wh_inode, *h_dir;
35607 + struct au_branch *br;
35609 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35610 + IMustLock(h_dir);
35612 + br = au_sbr(dir->i_sb, bindex);
35613 + wh_inode = d_inode(wh_dentry);
35614 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35617 + * someone else might change some whiteouts while we were sleeping.
35618 + * it means this whlist may have an obsoleted entry.
35620 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35621 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35624 + struct del_wh_children_args args = {
35626 + .h_dentry = wh_dentry,
35627 + .whlist = whlist,
35628 + .bindex = bindex,
35632 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35633 + if (unlikely(wkq_err))
35636 + inode_unlock(wh_inode);
35639 + h_tmp.dentry = wh_dentry;
35640 + h_tmp.mnt = au_br_mnt(br);
35641 + h_nlink = h_dir->i_nlink;
35642 + err = vfsub_rmdir(h_dir, &h_tmp);
35643 + /* some fs doesn't change the parent nlink in some cases */
35644 + h_nlink -= h_dir->i_nlink;
35648 + if (au_ibtop(dir) == bindex) {
35649 + /* todo: dir->i_mutex is necessary */
35650 + au_cpup_attr_timesizes(dir);
35652 + vfsub_drop_nlink(dir);
35654 + return 0; /* success */
35657 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35661 +static void call_rmdir_whtmp(void *args)
35664 + aufs_bindex_t bindex;
35665 + struct au_whtmp_rmdir *a = args;
35666 + struct super_block *sb;
35667 + struct dentry *h_parent;
35668 + struct inode *h_dir;
35669 + struct au_hinode *hdir;
35671 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35672 + /* inode_lock(a->dir); */
35674 + sb = a->dir->i_sb;
35675 + si_read_lock(sb, !AuLock_FLUSH);
35676 + if (!au_br_writable(a->br->br_perm))
35678 + bindex = au_br_index(sb, a->br->br_id);
35679 + if (unlikely(bindex < 0))
35683 + ii_write_lock_parent(a->dir);
35684 + h_parent = dget_parent(a->wh_dentry);
35685 + h_dir = d_inode(h_parent);
35686 + hdir = au_hi(a->dir, bindex);
35687 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35688 + if (unlikely(err))
35690 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35691 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35694 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35695 + au_hn_inode_unlock(hdir);
35696 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35700 + ii_write_unlock(a->dir);
35702 + /* inode_unlock(a->dir); */
35703 + au_whtmp_rmdir_free(a);
35704 + si_read_unlock(sb);
35705 + au_nwt_done(&au_sbi(sb)->si_nowait);
35706 + if (unlikely(err))
35707 + AuIOErr("err %d\n", err);
35710 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35711 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35714 + struct super_block *sb;
35718 + /* all post-process will be done in do_rmdir_whtmp(). */
35720 + args->dir = au_igrab(dir);
35721 + args->br = au_sbr(sb, bindex);
35722 + au_lcnt_inc(&args->br->br_count);
35723 + args->wh_dentry = dget(wh_dentry);
35724 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35725 + if (unlikely(wkq_err)) {
35726 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35727 + au_whtmp_rmdir_free(args);
35730 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35731 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35732 +++ linux/fs/aufs/whout.h 2020-01-27 10:57:18.178871751 +0100
35734 +/* SPDX-License-Identifier: GPL-2.0 */
35736 + * Copyright (C) 2005-2020 Junjiro R. Okajima
35738 + * This program, aufs is free software; you can redistribute it and/or modify
35739 + * it under the terms of the GNU General Public License as published by
35740 + * the Free Software Foundation; either version 2 of the License, or
35741 + * (at your option) any later version.
35743 + * This program is distributed in the hope that it will be useful,
35744 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35745 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35746 + * GNU General Public License for more details.
35748 + * You should have received a copy of the GNU General Public License
35749 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35753 + * whiteout for logical deletion and opaque directory
35756 +#ifndef __AUFS_WHOUT_H__
35757 +#define __AUFS_WHOUT_H__
35764 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35765 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
35766 +int au_diropq_test(struct dentry *h_dentry);
35768 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35769 + struct qstr *prefix);
35770 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35771 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35772 + struct dentry *dentry);
35773 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35775 +/* diropq flags */
35776 +#define AuDiropq_CREATE 1
35777 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35778 +#define au_fset_diropq(flags, name) \
35779 + do { (flags) |= AuDiropq_##name; } while (0)
35780 +#define au_fclr_diropq(flags, name) \
35781 + do { (flags) &= ~AuDiropq_##name; } while (0)
35783 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35784 + unsigned int flags);
35785 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35786 + struct au_branch *br);
35787 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35788 + struct dentry *h_parent);
35790 +/* real rmdir for the whiteout-ed dir */
35791 +struct au_whtmp_rmdir {
35792 + struct inode *dir;
35793 + struct au_branch *br;
35794 + struct dentry *wh_dentry;
35795 + struct au_nhash whlist;
35798 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35799 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35800 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35801 + struct dentry *wh_dentry, struct au_nhash *whlist);
35802 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35803 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35805 +/* ---------------------------------------------------------------------- */
35807 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35808 + aufs_bindex_t bindex)
35810 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35813 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35815 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35818 +#endif /* __KERNEL__ */
35819 +#endif /* __AUFS_WHOUT_H__ */
35820 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35821 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35822 +++ linux/fs/aufs/wkq.c 2020-08-03 09:12:33.764880472 +0200
35824 +// SPDX-License-Identifier: GPL-2.0
35826 + * Copyright (C) 2005-2020 Junjiro R. Okajima
35828 + * This program, aufs is free software; you can redistribute it and/or modify
35829 + * it under the terms of the GNU General Public License as published by
35830 + * the Free Software Foundation; either version 2 of the License, or
35831 + * (at your option) any later version.
35833 + * This program is distributed in the hope that it will be useful,
35834 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35835 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35836 + * GNU General Public License for more details.
35838 + * You should have received a copy of the GNU General Public License
35839 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35843 + * workqueue for asynchronous/super-io operations
35844 + * todo: try new credential scheme
35847 +#include <linux/module.h>
35850 +/* internal workqueue named AUFS_WKQ_NAME */
35852 +static struct workqueue_struct *au_wkq;
35854 +struct au_wkinfo {
35855 + struct work_struct wk;
35856 + struct kobject *kobj;
35858 + unsigned int flags; /* see wkq.h */
35860 + au_wkq_func_t func;
35863 +#ifdef CONFIG_LOCKDEP
35865 + struct held_lock **hlock;
35868 + struct completion *comp;
35871 +/* ---------------------------------------------------------------------- */
35873 + * Aufs passes some operations to the workqueue such as the internal copyup.
35874 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
35875 + * job run by workqueue depends upon the locks acquired in the other task.
35876 + * Delegating a small operation to the workqueue, aufs passes its lockdep
35877 + * information too. And the job in the workqueue restores the info in order to
35878 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
35879 + * correctly and expectedly.
35882 +#ifndef CONFIG_LOCKDEP
35883 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
35884 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
35885 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
35886 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
35887 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
35889 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
35891 + wkinfo->hlock = NULL;
35892 + wkinfo->dont_check = 0;
35899 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
35901 + static DEFINE_SPINLOCK(spin);
35904 + struct lock_class_key *key;
35906 + { .name = "&sbinfo->si_rwsem" },
35907 + { .name = "&finfo->fi_rwsem" },
35908 + { .name = "&dinfo->di_rwsem" },
35909 + { .name = "&iinfo->ii_rwsem" }
35914 + /* lockless read from 'set.' see below */
35915 + if (set == ARRAY_SIZE(a)) {
35916 + for (i = 0; i < ARRAY_SIZE(a); i++)
35917 + if (a[i].key == key)
35922 + spin_lock(&spin);
35924 + for (i = 0; i < ARRAY_SIZE(a); i++)
35925 + if (a[i].key == key) {
35926 + spin_unlock(&spin);
35929 + for (i = 0; i < ARRAY_SIZE(a); i++) {
35931 + if (unlikely(a[i].key == key)) { /* rare but possible */
35932 + spin_unlock(&spin);
35937 + if (strstr(a[i].name, name)) {
35939 + * the order of these three lines is important for the
35940 + * lockless read above.
35943 + spin_unlock(&spin);
35945 + /* AuDbg("%d, %s\n", set, name); */
35949 + spin_unlock(&spin);
35958 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
35961 + struct task_struct *curr;
35962 + struct held_lock **hl, *held_locks, *p;
35966 + wkinfo->dont_check = lockdep_recursing(curr);
35967 + if (wkinfo->dont_check)
35969 + n = curr->lockdep_depth;
35974 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
35975 + if (unlikely(!wkinfo->hlock))
35979 +#if 0 /* left for debugging */
35980 + if (0 && au_debug_test())
35981 + lockdep_print_held_locks(curr);
35983 + held_locks = curr->held_locks;
35984 + hl = wkinfo->hlock;
35986 + p = held_locks++;
35987 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
35996 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
35998 + au_kfree_try_rcu(wkinfo->hlock);
36001 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36003 + struct held_lock *p, **hl = wkinfo->hlock;
36006 + if (wkinfo->dont_check)
36010 + while ((p = *hl++)) { /* assignment */
36011 + subclass = lockdep_hlock_class(p)->subclass;
36012 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36014 + rwsem_acquire_read(p->instance, subclass, 0,
36015 + /*p->acquire_ip*/_RET_IP_);
36017 + rwsem_acquire(p->instance, subclass, 0,
36018 + /*p->acquire_ip*/_RET_IP_);
36022 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36024 + struct held_lock *p, **hl = wkinfo->hlock;
36026 + if (wkinfo->dont_check)
36030 + while ((p = *hl++)) /* assignment */
36031 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36035 +static void wkq_func(struct work_struct *wk)
36037 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36039 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36040 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36042 + au_wkq_lockdep_pre(wkinfo);
36043 + wkinfo->func(wkinfo->args);
36044 + au_wkq_lockdep_post(wkinfo);
36045 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36046 + complete(wkinfo->comp);
36048 + kobject_put(wkinfo->kobj);
36049 + module_put(THIS_MODULE); /* todo: ?? */
36050 + au_kfree_rcu(wkinfo);
36055 + * Since struct completion is large, try allocating it dynamically.
36057 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36059 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36061 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36063 + init_completion(*comp);
36064 + wkinfo->comp = *comp;
36070 +static void au_wkq_comp_free(struct completion *comp)
36072 + au_kfree_rcu(comp);
36075 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36077 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36078 + if (au_wkq_test()) {
36079 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36080 + " due to a dead dir by UDBA,"
36081 + " or async xino write?\n");
36082 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36085 + au_dbg_verify_kthread();
36087 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36088 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36089 + queue_work(au_wkq, &wkinfo->wk);
36091 + INIT_WORK(&wkinfo->wk, wkq_func);
36092 + schedule_work(&wkinfo->wk);
36097 + * Be careful. It is easy to make deadlock happen.
36098 + * processA: lock, wkq and wait
36099 + * processB: wkq and wait, lock in wkq
36102 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36105 + AuWkqCompDeclare(comp);
36106 + struct au_wkinfo wkinfo = {
36112 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36113 + if (unlikely(err))
36115 + err = au_wkq_lockdep_alloc(&wkinfo);
36116 + if (unlikely(err))
36119 + au_wkq_run(&wkinfo);
36120 + /* no timeout, no interrupt */
36121 + wait_for_completion(wkinfo.comp);
36123 + au_wkq_lockdep_free(&wkinfo);
36126 + au_wkq_comp_free(comp);
36128 + destroy_work_on_stack(&wkinfo.wk);
36133 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36134 + * problem in a concurrent umounting.
36136 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36137 + unsigned int flags)
36140 + struct au_wkinfo *wkinfo;
36142 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36145 + * wkq_func() must free this wkinfo.
36146 + * it highly depends upon the implementation of workqueue.
36149 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36151 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36152 + wkinfo->flags = flags & ~AuWkq_WAIT;
36153 + wkinfo->func = func;
36154 + wkinfo->args = args;
36155 + wkinfo->comp = NULL;
36156 + au_wkq_lockdep_init(wkinfo);
36157 + kobject_get(wkinfo->kobj);
36158 + __module_get(THIS_MODULE); /* todo: ?? */
36160 + au_wkq_run(wkinfo);
36163 + au_nwt_done(&au_sbi(sb)->si_nowait);
36169 +/* ---------------------------------------------------------------------- */
36171 +void au_nwt_init(struct au_nowait_tasks *nwt)
36173 + atomic_set(&nwt->nw_len, 0);
36174 + /* smp_mb(); */ /* atomic_set */
36175 + init_waitqueue_head(&nwt->nw_wq);
36178 +void au_wkq_fin(void)
36180 + destroy_workqueue(au_wkq);
36183 +int __init au_wkq_init(void)
36188 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36189 + if (IS_ERR(au_wkq))
36190 + err = PTR_ERR(au_wkq);
36191 + else if (!au_wkq)
36196 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36197 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36198 +++ linux/fs/aufs/wkq.h 2020-01-27 10:57:18.182205184 +0100
36200 +/* SPDX-License-Identifier: GPL-2.0 */
36202 + * Copyright (C) 2005-2020 Junjiro R. Okajima
36204 + * This program, aufs is free software; you can redistribute it and/or modify
36205 + * it under the terms of the GNU General Public License as published by
36206 + * the Free Software Foundation; either version 2 of the License, or
36207 + * (at your option) any later version.
36209 + * This program is distributed in the hope that it will be useful,
36210 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36211 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36212 + * GNU General Public License for more details.
36214 + * You should have received a copy of the GNU General Public License
36215 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36219 + * workqueue for asynchronous/super-io operations
36220 + * todo: try new credentials management scheme
36223 +#ifndef __AUFS_WKQ_H__
36224 +#define __AUFS_WKQ_H__
36228 +#include <linux/wait.h>
36230 +struct super_block;
36232 +/* ---------------------------------------------------------------------- */
36235 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36237 +struct au_nowait_tasks {
36239 + wait_queue_head_t nw_wq;
36242 +/* ---------------------------------------------------------------------- */
36244 +typedef void (*au_wkq_func_t)(void *args);
36247 +#define AuWkq_WAIT 1
36248 +#define AuWkq_NEST (1 << 1)
36249 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36250 +#define au_fset_wkq(flags, name) \
36251 + do { (flags) |= AuWkq_##name; } while (0)
36252 +#define au_fclr_wkq(flags, name) \
36253 + do { (flags) &= ~AuWkq_##name; } while (0)
36256 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36257 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36258 + unsigned int flags);
36259 +void au_nwt_init(struct au_nowait_tasks *nwt);
36260 +int __init au_wkq_init(void);
36261 +void au_wkq_fin(void);
36263 +/* ---------------------------------------------------------------------- */
36265 +static inline int au_wkq_test(void)
36267 + return current->flags & PF_WQ_WORKER;
36270 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36272 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36275 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36277 + if (atomic_dec_and_test(&nwt->nw_len))
36278 + wake_up_all(&nwt->nw_wq);
36281 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36283 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36287 +#endif /* __KERNEL__ */
36288 +#endif /* __AUFS_WKQ_H__ */
36289 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36290 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36291 +++ linux/fs/aufs/xattr.c 2020-08-03 09:14:46.095748745 +0200
36293 +// SPDX-License-Identifier: GPL-2.0
36295 + * Copyright (C) 2014-2020 Junjiro R. Okajima
36297 + * This program, aufs is free software; you can redistribute it and/or modify
36298 + * it under the terms of the GNU General Public License as published by
36299 + * the Free Software Foundation; either version 2 of the License, or
36300 + * (at your option) any later version.
36302 + * This program is distributed in the hope that it will be useful,
36303 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36304 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36305 + * GNU General Public License for more details.
36307 + * You should have received a copy of the GNU General Public License
36308 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36312 + * handling xattr functions
36315 +#include <linux/fs.h>
36316 +#include <linux/posix_acl_xattr.h>
36317 +#include <linux/xattr.h>
36320 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36322 + if (!ignore_flags)
36330 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36335 +#define cmp(brattr, prefix) do { \
36336 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36337 + XATTR_##prefix##_PREFIX_LEN)) { \
36338 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36344 + cmp(SEC, SECURITY);
36345 + cmp(SYS, SYSTEM);
36346 + cmp(TR, TRUSTED);
36350 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36357 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36359 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36360 + char *name, char **buf, unsigned int ignore_flags,
36361 + unsigned int verbose)
36365 + struct inode *h_idst;
36367 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36369 + if (unlikely(err <= 0)) {
36370 + if (err == -ENODATA
36371 + || (err == -EOPNOTSUPP
36372 + && ((ignore_flags & au_xattr_out_of_list)
36373 + || (au_test_nfs_noacl(d_inode(h_src))
36374 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36376 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36379 + if (err && (verbose || au_debug_test()))
36380 + pr_err("%s, err %d\n", name, err);
36384 + /* unlock it temporary */
36385 + h_idst = d_inode(h_dst);
36386 + inode_unlock(h_idst);
36387 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36388 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36389 + if (unlikely(err)) {
36390 + if (verbose || au_debug_test())
36391 + pr_err("%s, err %d\n", name, err);
36392 + err = au_xattr_ignore(err, name, ignore_flags);
36399 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36400 + unsigned int verbose)
36402 + int err, unlocked, acl_access, acl_default;
36404 + struct inode *h_isrc, *h_idst;
36405 + char *value, *p, *o, *e;
36407 + /* try stopping to update the source inode while we are referencing */
36408 + /* there should not be the parent-child relationship between them */
36409 + h_isrc = d_inode(h_src);
36410 + h_idst = d_inode(h_dst);
36411 + inode_unlock(h_idst);
36412 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36413 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36416 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36417 + ssz = vfs_listxattr(h_src, NULL, 0);
36419 + if (unlikely(err < 0)) {
36421 + if (err == -ENODATA
36422 + || err == -EOPNOTSUPP)
36423 + err = 0; /* ignore */
36432 + p = kmalloc(ssz, GFP_NOFS);
36434 + if (unlikely(!p))
36436 + err = vfs_listxattr(h_src, p, ssz);
36438 + inode_unlock_shared(h_isrc);
36440 + AuDbg("err %d, ssz %zd\n", err, ssz);
36441 + if (unlikely(err < 0))
36449 + while (!err && p < e) {
36450 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36451 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36452 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36453 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36455 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36457 + p += strlen(p) + 1;
36460 + ignore_flags |= au_xattr_out_of_list;
36461 + if (!err && !acl_access) {
36462 + err = au_do_cpup_xattr(h_dst, h_src,
36463 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36464 + ignore_flags, verbose);
36467 + if (!err && !acl_default) {
36468 + err = au_do_cpup_xattr(h_dst, h_src,
36469 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36470 + ignore_flags, verbose);
36474 + au_kfree_try_rcu(value);
36477 + au_kfree_try_rcu(o);
36480 + inode_unlock_shared(h_isrc);
36485 +/* ---------------------------------------------------------------------- */
36487 +static int au_smack_reentering(struct super_block *sb)
36489 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36491 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36492 + * i_op->getxattr(). ouch.
36494 + return si_pid_test(sb);
36505 +struct au_lgxattr {
36513 + const char *name;
36520 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36521 + struct au_lgxattr *arg)
36525 + struct path h_path;
36526 + struct super_block *sb;
36528 + sb = dentry->d_sb;
36529 + reenter = au_smack_reentering(sb);
36531 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36532 + if (unlikely(err))
36535 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
36536 + if (unlikely(err))
36538 + if (unlikely(!h_path.dentry))
36539 + /* illegally overlapped or something */
36540 + goto out_di; /* pretending success */
36542 + /* always topmost entry only */
36543 + switch (arg->type) {
36544 + case AU_XATTR_LIST:
36545 + err = vfs_listxattr(h_path.dentry,
36546 + arg->u.list.list, arg->u.list.size);
36548 + case AU_XATTR_GET:
36549 + AuDebugOn(d_is_negative(h_path.dentry));
36550 + err = vfs_getxattr(h_path.dentry,
36551 + arg->u.get.name, arg->u.get.value,
36552 + arg->u.get.size);
36558 + di_read_unlock(dentry, AuLock_IR);
36561 + si_read_unlock(sb);
36567 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36569 + struct au_lgxattr arg = {
36570 + .type = AU_XATTR_LIST,
36577 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
36580 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
36581 + const char *name, void *value, size_t size)
36583 + struct au_lgxattr arg = {
36584 + .type = AU_XATTR_GET,
36592 + return au_lgxattr(dentry, inode, &arg);
36595 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36596 + const char *name, const void *value, size_t size,
36599 + struct au_sxattr arg = {
36600 + .type = AU_XATTR_SET,
36609 + return au_sxattr(dentry, inode, &arg);
36612 +/* ---------------------------------------------------------------------- */
36614 +static int au_xattr_get(const struct xattr_handler *handler,
36615 + struct dentry *dentry, struct inode *inode,
36616 + const char *name, void *buffer, size_t size)
36618 + return au_getxattr(dentry, inode, name, buffer, size);
36621 +static int au_xattr_set(const struct xattr_handler *handler,
36622 + struct dentry *dentry, struct inode *inode,
36623 + const char *name, const void *value, size_t size,
36626 + return au_setxattr(dentry, inode, name, value, size, flags);
36629 +static const struct xattr_handler au_xattr_handler = {
36632 + .get = au_xattr_get,
36633 + .set = au_xattr_set
36636 +static const struct xattr_handler *au_xattr_handlers[] = {
36637 +#ifdef CONFIG_FS_POSIX_ACL
36638 + &posix_acl_access_xattr_handler,
36639 + &posix_acl_default_xattr_handler,
36641 + &au_xattr_handler, /* must be last */
36645 +void au_xattr_init(struct super_block *sb)
36647 + sb->s_xattr = au_xattr_handlers;
36649 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36650 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36651 +++ linux/fs/aufs/xino.c 2020-12-15 14:10:58.924690030 +0100
36653 +// SPDX-License-Identifier: GPL-2.0
36655 + * Copyright (C) 2005-2020 Junjiro R. Okajima
36657 + * This program, aufs is free software; you can redistribute it and/or modify
36658 + * it under the terms of the GNU General Public License as published by
36659 + * the Free Software Foundation; either version 2 of the License, or
36660 + * (at your option) any later version.
36662 + * This program is distributed in the hope that it will be useful,
36663 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36664 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36665 + * GNU General Public License for more details.
36667 + * You should have received a copy of the GNU General Public License
36668 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36672 + * external inode number translation table and bitmap
36674 + * things to consider
36676 + * + au_xino object
36677 + * + XINO files (xino, xib, xigen)
36678 + * + dynamic debugfs entries (xiN)
36679 + * + static debugfs entries (xib, xigen)
36680 + * + static sysfs entry (xi_path)
36681 + * - several entry points to handle them.
36682 + * + mount(2) without xino option (default)
36683 + * + mount(2) with xino option
36684 + * + mount(2) with noxino option
36686 + * + remount with add/del branches
36687 + * + remount with xino/noxino options
36690 +#include <linux/seq_file.h>
36691 +#include <linux/statfs.h>
36694 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36695 + aufs_bindex_t bbot,
36696 + struct super_block *h_sb)
36698 + /* todo: try binary-search if the branches are many */
36699 + for (; btop <= bbot; btop++)
36700 + if (h_sb == au_sbr_sb(sb, btop))
36706 + * find another branch who is on the same filesystem of the specified
36707 + * branch{@btgt}. search until @bbot.
36709 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36710 + aufs_bindex_t bbot)
36712 + aufs_bindex_t bindex;
36713 + struct super_block *tgt_sb;
36715 + tgt_sb = au_sbr_sb(sb, btgt);
36716 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36718 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36723 +/* ---------------------------------------------------------------------- */
36726 + * stop unnecessary notify events at creating xino files
36729 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
36731 + aufs_bindex_t bfound, bindex, bbot;
36732 + struct dentry *parent;
36733 + struct au_branch *br;
36736 + parent = dentry->d_parent; /* safe d_parent access */
36737 + bbot = au_sbbot(sb);
36738 + for (bindex = 0; bindex <= bbot; bindex++) {
36739 + br = au_sbr(sb, bindex);
36740 + if (au_br_dentry(br) == parent) {
36746 + AuDbg("bfound b%d\n", bfound);
36750 +struct au_xino_lock_dir {
36751 + struct au_hinode *hdir;
36752 + struct dentry *parent;
36753 + struct inode *dir;
36756 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
36757 + unsigned int lsc)
36759 + struct dentry *parent;
36760 + struct inode *dir;
36762 + parent = dget_parent(dentry);
36763 + dir = d_inode(parent);
36764 + inode_lock_nested(dir, lsc);
36765 +#if 0 /* it should not happen */
36766 + spin_lock(&dentry->d_lock);
36767 + if (unlikely(dentry->d_parent != parent)) {
36768 + spin_unlock(&dentry->d_lock);
36769 + inode_unlock(dir);
36774 + spin_unlock(&dentry->d_lock);
36781 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
36782 + struct au_xino_lock_dir *ldir)
36784 + aufs_bindex_t bindex;
36786 + ldir->hdir = NULL;
36787 + bindex = au_xi_root(sb, xipath->dentry);
36788 + if (bindex >= 0) {
36789 + /* rw branch root */
36790 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36791 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36794 + ldir->parent = au_dget_parent_lock(xipath->dentry,
36796 + ldir->dir = d_inode(ldir->parent);
36800 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36803 + au_hn_inode_unlock(ldir->hdir);
36805 + inode_unlock(ldir->dir);
36806 + dput(ldir->parent);
36810 +/* ---------------------------------------------------------------------- */
36813 + * create and set a new xino file
36815 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
36818 + struct file *file;
36819 + struct dentry *h_parent, *d;
36820 + struct inode *h_dir, *inode;
36822 + static DEFINE_MUTEX(mtx);
36825 + * at mount-time, and the xino file is the default path,
36826 + * hnotify is disabled so we have no notify events to ignore.
36827 + * when a user specified the xino, we cannot get au_hdir to be ignored.
36830 + mutex_lock(&mtx);
36831 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36832 + /* | __FMODE_NONOTIFY */,
36834 + if (IS_ERR(file)) {
36836 + mutex_unlock(&mtx);
36838 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
36842 + /* keep file count */
36844 + d = file->f_path.dentry;
36845 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
36847 + mutex_unlock(&mtx);
36848 + /* mnt_want_write() is unnecessary here */
36849 + h_dir = d_inode(h_parent);
36850 + inode = file_inode(file);
36851 + /* no delegation since it is just created */
36852 + if (inode->i_nlink)
36853 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
36855 + inode_unlock(h_dir);
36857 + if (unlikely(err)) {
36859 + pr_err("unlink %s(%d)\n", fpath, err);
36864 + if (unlikely(sb == d->d_sb)) {
36866 + pr_err("%s must be outside\n", fpath);
36869 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
36871 + pr_err("xino doesn't support %s(%s)\n",
36872 + fpath, au_sbtype(d->d_sb));
36875 + return file; /* success */
36879 + file = ERR_PTR(err);
36884 + * create a new xinofile at the same place/path as @base.
36886 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
36887 + struct file *copy_src)
36889 + struct file *file;
36890 + struct dentry *dentry, *parent;
36891 + struct inode *dir, *delegated;
36892 + struct qstr *name;
36893 + struct path path;
36894 + int err, do_unlock;
36895 + struct au_xino_lock_dir ldir;
36898 + au_xino_lock_dir(sb, base, &ldir);
36899 + dentry = base->dentry;
36900 + parent = dentry->d_parent; /* dir inode is locked */
36901 + dir = d_inode(parent);
36904 + name = &dentry->d_name;
36905 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
36906 + if (IS_ERR(path.dentry)) {
36907 + file = (void *)path.dentry;
36908 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
36912 + /* no need to mnt_want_write() since we call dentry_open() later */
36913 + err = vfs_create(dir, path.dentry, 0666, NULL);
36914 + if (unlikely(err)) {
36915 + file = ERR_PTR(err);
36916 + pr_err("%pd create err %d\n", dentry, err);
36920 + path.mnt = base->mnt;
36921 + file = vfsub_dentry_open(&path,
36922 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36923 + /* | __FMODE_NONOTIFY */);
36924 + if (IS_ERR(file)) {
36925 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
36929 + delegated = NULL;
36930 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
36931 + au_xino_unlock_dir(&ldir);
36933 + if (unlikely(err == -EWOULDBLOCK)) {
36934 + pr_warn("cannot retry for NFSv4 delegation"
36935 + " for an internal unlink\n");
36938 + if (unlikely(err)) {
36939 + pr_err("%pd unlink err %d\n", dentry, err);
36944 + /* no one can touch copy_src xino */
36945 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
36946 + if (unlikely(err)) {
36947 + pr_err("%pd copy err %d\n", dentry, err);
36951 + goto out_dput; /* success */
36955 + file = ERR_PTR(err);
36957 + dput(path.dentry);
36960 + au_xino_unlock_dir(&ldir);
36964 +struct file *au_xino_file1(struct au_xino *xi)
36966 + struct file *file;
36967 + unsigned int u, nfile;
36970 + nfile = xi->xi_nfile;
36971 + for (u = 0; u < nfile; u++) {
36972 + file = xi->xi_file[u];
36980 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
36991 + if (idx < xi->xi_nfile) {
36992 + f = xi->xi_file[idx];
36996 + p = au_kzrealloc(xi->xi_file,
36997 + sizeof(*xi->xi_file) * xi->xi_nfile,
36998 + sizeof(*xi->xi_file) * (idx + 1),
36999 + GFP_NOFS, /*may_shrink*/0);
37001 + MtxMustLock(&xi->xi_mtx);
37003 + xi->xi_nfile = idx + 1;
37011 + xi->xi_file[idx] = file;
37018 + * if @xinew->xi is not set, then create new xigen file.
37020 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37022 + struct file *file;
37025 + SiMustAnyLock(sb);
37027 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37028 + if (IS_ERR(file)) {
37029 + err = PTR_ERR(file);
37030 + pr_err("%s[%d], err %d\n",
37031 + xinew->xi ? "xino" : "xigen",
37032 + xinew->idx, err);
37037 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37040 + /* todo: make xigen file an array */
37041 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37044 + if (unlikely(err))
37045 + file = ERR_PTR(err);
37051 +/* ---------------------------------------------------------------------- */
37054 + * truncate xino files
37056 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37057 + int idx, struct kstatfs *st)
37061 + struct file *file, *new_xino;
37062 + struct au_xi_new xinew = {
37067 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37068 + file = au_xino_file(xinew.xi, idx);
37072 + xinew.base = &file->f_path;
37073 + err = vfs_statfs(xinew.base, st);
37074 + if (unlikely(err)) {
37075 + AuErr1("statfs err %d, ignored\n", err);
37080 + blocks = file_inode(file)->i_blocks;
37081 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37082 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37084 + xinew.copy_src = file;
37085 + new_xino = au_xi_new(sb, &xinew);
37086 + if (IS_ERR(new_xino)) {
37087 + err = PTR_ERR(new_xino);
37088 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37092 + err = vfs_statfs(&new_xino->f_path, st);
37094 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37095 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37096 + st->f_bfree, st->f_blocks);
37098 + AuErr1("statfs err %d, ignored\n", err);
37106 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37109 + unsigned long jiffy;
37110 + aufs_bindex_t bbot;
37111 + struct kstatfs *st;
37112 + struct au_branch *br;
37113 + struct au_xino *xi;
37116 + st = kmalloc(sizeof(*st), GFP_NOFS);
37117 + if (unlikely(!st))
37121 + bbot = au_sbbot(sb);
37122 + if (unlikely(bindex < 0 || bbot < bindex))
37127 + br = au_sbr(sb, bindex);
37128 + xi = br->br_xino;
37129 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37130 + err = au_xino_do_trunc(sb, bindex, i, st);
37132 + au_sbi(sb)->si_xino_jiffy = jiffy;
37135 + au_kfree_rcu(st);
37140 +struct xino_do_trunc_args {
37141 + struct super_block *sb;
37142 + struct au_branch *br;
37146 +static void xino_do_trunc(void *_args)
37148 + struct xino_do_trunc_args *args = _args;
37149 + struct super_block *sb;
37150 + struct au_branch *br;
37151 + struct inode *dir;
37153 + aufs_bindex_t bindex;
37157 + dir = d_inode(sb->s_root);
37161 + si_noflush_write_lock(sb);
37162 + ii_read_lock_parent(dir);
37163 + bindex = au_br_index(sb, br->br_id);
37164 + err = au_xino_trunc(sb, bindex, idx);
37165 + ii_read_unlock(dir);
37166 + if (unlikely(err))
37167 + pr_warn("err b%d, (%d)\n", bindex, err);
37168 + atomic_dec(&br->br_xino->xi_truncating);
37169 + au_lcnt_dec(&br->br_count);
37170 + si_write_unlock(sb);
37171 + au_nwt_done(&au_sbi(sb)->si_nowait);
37172 + au_kfree_rcu(args);
37176 + * returns the index in the xi_file array whose corresponding file is necessary
37177 + * to truncate, or -1 which means no need to truncate.
37179 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37183 + struct kstatfs st;
37184 + struct au_sbinfo *sbinfo;
37185 + struct au_xino *xi;
37186 + struct file *file;
37188 + /* todo: si_xino_expire and the ratio should be customizable */
37189 + sbinfo = au_sbi(sb);
37190 + if (time_before(jiffies,
37191 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37194 + /* truncation border */
37195 + xi = br->br_xino;
37196 + for (u = 0; u < xi->xi_nfile; u++) {
37197 + file = au_xino_file(xi, u);
37201 + err = vfs_statfs(&file->f_path, &st);
37202 + if (unlikely(err)) {
37203 + AuErr1("statfs err %d, ignored\n", err);
37206 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37207 + >= AUFS_XINO_DEF_TRUNC)
37214 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37217 + struct xino_do_trunc_args *args;
37220 + idx = xino_trunc_test(sb, br);
37224 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37227 + /* lock and kfree() will be called in trunc_xino() */
37228 + args = kmalloc(sizeof(*args), GFP_NOFS);
37229 + if (unlikely(!args)) {
37230 + AuErr1("no memory\n");
37234 + au_lcnt_inc(&br->br_count);
37238 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37240 + return; /* success */
37242 + pr_err("wkq %d\n", wkq_err);
37243 + au_lcnt_dec(&br->br_count);
37244 + au_kfree_rcu(args);
37247 + atomic_dec(&br->br_xino->xi_truncating);
37250 +/* ---------------------------------------------------------------------- */
37252 +struct au_xi_calc {
37257 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37258 + struct au_xi_calc *calc)
37262 + maxent = au_xi_maxent(sb);
37263 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37264 + calc->pos *= sizeof(ino_t);
37267 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37268 + struct au_xi_calc *calc)
37271 + struct file *file;
37272 + struct au_xino *xi = br->br_xino;
37273 + struct au_xi_new xinew = {
37277 + SiMustAnyLock(sb);
37283 + mutex_lock(&xi->xi_mtx);
37284 + file = au_xino_file(xi, calc->idx);
37288 + file = au_xino_file(xi, /*idx*/-1);
37289 + AuDebugOn(!file);
37290 + xinew.idx = calc->idx;
37291 + xinew.base = &file->f_path;
37292 + /* xinew.copy_src = NULL; */
37293 + file = au_xi_new(sb, &xinew);
37294 + if (IS_ERR(file))
37295 + err = PTR_ERR(file);
37298 + mutex_unlock(&xi->xi_mtx);
37303 +struct au_xino_do_new_async_args {
37304 + struct super_block *sb;
37305 + struct au_branch *br;
37306 + struct au_xi_calc calc;
37310 +struct au_xi_writing {
37311 + struct hlist_bl_node node;
37312 + ino_t h_ino, ino;
37315 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37318 +static void au_xino_call_do_new_async(void *args)
37320 + struct au_xino_do_new_async_args *a = args;
37321 + struct au_branch *br;
37322 + struct super_block *sb;
37323 + struct au_sbinfo *sbi;
37324 + struct inode *root;
37325 + struct file *file;
37326 + struct au_xi_writing *del, *p;
37327 + struct hlist_bl_head *hbl;
37328 + struct hlist_bl_node *pos;
37333 + sbi = au_sbi(sb);
37334 + si_noflush_read_lock(sb);
37335 + root = d_inode(sb->s_root);
37336 + ii_read_lock_child(root);
37337 + err = au_xino_do_new_async(sb, br, &a->calc);
37338 + if (unlikely(err)) {
37339 + AuIOErr("err %d\n", err);
37343 + file = au_xino_file(br->br_xino, a->calc.idx);
37344 + AuDebugOn(!file);
37345 + err = au_xino_do_write(file, &a->calc, a->ino);
37346 + if (unlikely(err)) {
37347 + AuIOErr("err %d\n", err);
37352 + hbl = &br->br_xino->xi_writing;
37353 + hlist_bl_lock(hbl);
37354 + au_hbl_for_each(pos, hbl) {
37355 + p = container_of(pos, struct au_xi_writing, node);
37356 + if (p->ino == a->ino) {
37358 + hlist_bl_del(&p->node);
37362 + hlist_bl_unlock(hbl);
37363 + au_kfree_rcu(del);
37366 + au_lcnt_dec(&br->br_count);
37367 + ii_read_unlock(root);
37368 + si_read_unlock(sb);
37369 + au_nwt_done(&sbi->si_nowait);
37374 + * create a new xino file asynchronously
37376 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37377 + struct au_xi_calc *calc, ino_t ino)
37380 + struct au_xino_do_new_async_args *arg;
37383 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37384 + if (unlikely(!arg))
37389 + arg->calc = *calc;
37391 + au_lcnt_inc(&br->br_count);
37392 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37393 + if (unlikely(err)) {
37394 + pr_err("wkq %d\n", err);
37395 + au_lcnt_dec(&br->br_count);
37396 + au_kfree_rcu(arg);
37404 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37405 + * at the position of @h_ino.
37407 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37412 + struct au_xi_calc calc;
37413 + struct au_sbinfo *sbinfo;
37414 + struct file *file;
37415 + struct au_xino *xi;
37416 + struct hlist_bl_head *hbl;
37417 + struct hlist_bl_node *pos;
37418 + struct au_xi_writing *p;
37421 + if (!au_opt_test(au_mntflags(sb), XINO))
37422 + return 0; /* no xino */
37425 + au_xi_calc(sb, h_ino, &calc);
37426 + xi = au_sbr(sb, bindex)->br_xino;
37427 + file = au_xino_file(xi, calc.idx);
37429 + hbl = &xi->xi_writing;
37430 + hlist_bl_lock(hbl);
37431 + au_hbl_for_each(pos, hbl) {
37432 + p = container_of(pos, struct au_xi_writing, node);
37433 + if (p->h_ino == h_ino) {
37434 + AuDbg("hi%llu, i%llu, found\n",
37435 + (u64)p->h_ino, (u64)p->ino);
37440 + hlist_bl_unlock(hbl);
37442 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37443 + return 0; /* no xino */
37445 + sbinfo = au_sbi(sb);
37446 + sz = xino_fread(file, ino, sizeof(*ino), &calc.pos);
37447 + if (sz == sizeof(*ino))
37448 + return 0; /* success */
37451 + if (unlikely(sz >= 0)) {
37453 + AuIOErr("xino read error (%zd)\n", sz);
37458 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37463 + sz = xino_fwrite(file, &ino, sizeof(ino), &calc->pos);
37464 + if (sz == sizeof(ino))
37465 + return 0; /* success */
37467 + AuIOErr("write failed (%zd)\n", sz);
37472 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37473 + * at the position of @h_ino.
37474 + * even if @ino is zero, it is written to the xinofile and means no entry.
37475 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37476 + * try truncating it.
37478 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37482 + unsigned int mnt_flags;
37483 + struct au_xi_calc calc;
37484 + struct file *file;
37485 + struct au_branch *br;
37486 + struct au_xino *xi;
37487 + struct au_xi_writing *p;
37489 + SiMustAnyLock(sb);
37491 + mnt_flags = au_mntflags(sb);
37492 + if (!au_opt_test(mnt_flags, XINO))
37495 + au_xi_calc(sb, h_ino, &calc);
37496 + br = au_sbr(sb, bindex);
37497 + xi = br->br_xino;
37498 + file = au_xino_file(xi, calc.idx);
37500 + /* store the inum pair into the list */
37501 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37502 + p->h_ino = h_ino;
37504 + au_hbl_add(&p->node, &xi->xi_writing);
37506 + /* create and write a new xino file asynchronously */
37507 + err = au_xino_new_async(sb, br, &calc, ino);
37509 + return 0; /* success */
37513 + err = au_xino_do_write(file, &calc, ino);
37515 + br = au_sbr(sb, bindex);
37516 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37517 + && au_test_fs_trunc_xino(au_br_sb(br)))
37518 + xino_try_trunc(sb, br);
37519 + return 0; /* success */
37523 + AuIOErr("write failed (%d)\n", err);
37527 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37530 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37531 +ssize_t xino_fread(struct file *file, void *kbuf, size_t size, loff_t *pos)
37535 + const int prevent_endless = 10;
37539 + err = vfsub_read_k(file, kbuf, size, pos);
37540 + if (err == -EINTR
37541 + && !au_wkq_test()
37542 + && fatal_signal_pending(current)) {
37543 + err = xino_fread_wkq(file, kbuf, size, pos);
37544 + BUG_ON(err == -EINTR);
37546 + } while (i++ < prevent_endless
37547 + && (err == -EAGAIN || err == -EINTR));
37549 +#if 0 /* reserved for future use */
37551 + fsnotify_access(file->f_path.dentry);
37557 +struct xino_fread_args {
37559 + struct file *file;
37565 +static void call_xino_fread(void *args)
37567 + struct xino_fread_args *a = args;
37568 + *a->errp = xino_fread(a->file, a->buf, a->size, a->pos);
37571 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37576 + struct xino_fread_args args = {
37584 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37585 + if (unlikely(wkq_err))
37591 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37594 +static ssize_t do_xino_fwrite(struct file *file, void *kbuf, size_t size,
37599 + const int prevent_endless = 10;
37603 + err = vfsub_write_k(file, kbuf, size, pos);
37604 + if (err == -EINTR
37605 + && !au_wkq_test()
37606 + && fatal_signal_pending(current)) {
37607 + err = xino_fwrite_wkq(file, kbuf, size, pos);
37608 + BUG_ON(err == -EINTR);
37610 + } while (i++ < prevent_endless
37611 + && (err == -EAGAIN || err == -EINTR));
37613 +#if 0 /* reserved for future use */
37615 + fsnotify_modify(file->f_path.dentry);
37621 +struct do_xino_fwrite_args {
37623 + struct file *file;
37629 +static void call_do_xino_fwrite(void *args)
37631 + struct do_xino_fwrite_args *a = args;
37632 + *a->errp = do_xino_fwrite(a->file, a->buf, a->size, a->pos);
37635 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37640 + struct do_xino_fwrite_args args = {
37649 + * it breaks RLIMIT_FSIZE and normal user's limit,
37650 + * users should care about quota and real 'filesystem full.'
37652 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37653 + if (unlikely(wkq_err))
37659 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos)
37663 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37665 + err = do_xino_fwrite(file, buf, size, pos);
37669 + err = xino_fwrite_wkq(file, buf, size, pos);
37676 +/* ---------------------------------------------------------------------- */
37679 + * inode number bitmap
37681 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37682 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37686 + AuDebugOn(bit < 0 || page_bits <= bit);
37687 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37691 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37693 + AuDebugOn(ino < AUFS_FIRST_INO);
37694 + ino -= AUFS_FIRST_INO;
37695 + *pindex = ino / page_bits;
37696 + *bit = ino % page_bits;
37699 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37704 + struct au_sbinfo *sbinfo;
37705 + struct file *xib;
37706 + unsigned long *p;
37708 + sbinfo = au_sbi(sb);
37709 + MtxMustLock(&sbinfo->si_xib_mtx);
37710 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37711 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37713 + if (pindex == sbinfo->si_xib_last_pindex)
37716 + xib = sbinfo->si_xib;
37717 + p = sbinfo->si_xib_buf;
37718 + pos = sbinfo->si_xib_last_pindex;
37719 + pos *= PAGE_SIZE;
37720 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
37721 + if (unlikely(sz != PAGE_SIZE))
37725 + pos *= PAGE_SIZE;
37726 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37727 + sz = xino_fread(xib, p, PAGE_SIZE, &pos);
37729 + memset(p, 0, PAGE_SIZE);
37730 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
37732 + if (sz == PAGE_SIZE) {
37733 + sbinfo->si_xib_last_pindex = pindex;
37734 + return 0; /* success */
37738 + AuIOErr1("write failed (%zd)\n", sz);
37745 +static void au_xib_clear_bit(struct inode *inode)
37748 + unsigned long pindex;
37749 + struct super_block *sb;
37750 + struct au_sbinfo *sbinfo;
37752 + AuDebugOn(inode->i_nlink);
37754 + sb = inode->i_sb;
37755 + xib_calc_bit(inode->i_ino, &pindex, &bit);
37756 + AuDebugOn(page_bits <= bit);
37757 + sbinfo = au_sbi(sb);
37758 + mutex_lock(&sbinfo->si_xib_mtx);
37759 + err = xib_pindex(sb, pindex);
37761 + clear_bit(bit, sbinfo->si_xib_buf);
37762 + sbinfo->si_xib_next_bit = bit;
37764 + mutex_unlock(&sbinfo->si_xib_mtx);
37767 +/* ---------------------------------------------------------------------- */
37770 + * truncate a xino bitmap file
37774 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
37778 + unsigned long pindex;
37779 + loff_t pos, pend;
37780 + struct au_sbinfo *sbinfo;
37782 + unsigned long *p;
37785 + sbinfo = au_sbi(sb);
37786 + MtxMustLock(&sbinfo->si_xib_mtx);
37787 + p = sbinfo->si_xib_buf;
37788 + pend = vfsub_f_size_read(file);
37790 + while (pos < pend) {
37791 + sz = xino_fread(file, page, PAGE_SIZE, &pos);
37793 + if (unlikely(sz <= 0))
37797 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
37798 + if (unlikely(*ino < AUFS_FIRST_INO))
37801 + xib_calc_bit(*ino, &pindex, &bit);
37802 + AuDebugOn(page_bits <= bit);
37803 + err = xib_pindex(sb, pindex);
37815 +static int xib_restore(struct super_block *sb)
37818 + unsigned int nfile;
37819 + aufs_bindex_t bindex, bbot;
37821 + struct au_branch *br;
37822 + struct au_xino *xi;
37823 + struct file *file;
37826 + page = (void *)__get_free_page(GFP_NOFS);
37827 + if (unlikely(!page))
37831 + bbot = au_sbbot(sb);
37832 + for (bindex = 0; !err && bindex <= bbot; bindex++)
37833 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
37834 + br = au_sbr(sb, bindex);
37835 + xi = br->br_xino;
37836 + nfile = xi->xi_nfile;
37837 + for (i = 0; i < nfile; i++) {
37838 + file = au_xino_file(xi, i);
37840 + err = do_xib_restore(sb, file, page);
37843 + AuDbg("skip shared b%d\n", bindex);
37844 + free_page((unsigned long)page);
37850 +int au_xib_trunc(struct super_block *sb)
37855 + struct au_sbinfo *sbinfo;
37856 + unsigned long *p;
37857 + struct file *file;
37859 + SiMustWriteLock(sb);
37862 + sbinfo = au_sbi(sb);
37863 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
37866 + file = sbinfo->si_xib;
37867 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
37870 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
37871 + err = PTR_ERR(file);
37872 + if (IS_ERR(file))
37874 + fput(sbinfo->si_xib);
37875 + sbinfo->si_xib = file;
37877 + p = sbinfo->si_xib_buf;
37878 + memset(p, 0, PAGE_SIZE);
37880 + sz = xino_fwrite(sbinfo->si_xib, p, PAGE_SIZE, &pos);
37881 + if (unlikely(sz != PAGE_SIZE)) {
37883 + AuIOErr("err %d\n", err);
37889 + mutex_lock(&sbinfo->si_xib_mtx);
37890 + /* mnt_want_write() is unnecessary here */
37891 + err = xib_restore(sb);
37892 + mutex_unlock(&sbinfo->si_xib_mtx);
37898 +/* ---------------------------------------------------------------------- */
37900 +struct au_xino *au_xino_alloc(unsigned int nfile)
37902 + struct au_xino *xi;
37904 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
37905 + if (unlikely(!xi))
37907 + xi->xi_nfile = nfile;
37908 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
37909 + if (unlikely(!xi->xi_file))
37912 + xi->xi_nondir.total = 8; /* initial size */
37913 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
37915 + if (unlikely(!xi->xi_nondir.array))
37918 + spin_lock_init(&xi->xi_nondir.spin);
37919 + init_waitqueue_head(&xi->xi_nondir.wqh);
37920 + mutex_init(&xi->xi_mtx);
37921 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
37922 + atomic_set(&xi->xi_truncating, 0);
37923 + kref_init(&xi->xi_kref);
37924 + goto out; /* success */
37927 + au_kfree_try_rcu(xi->xi_file);
37929 + au_kfree_rcu(xi);
37935 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
37938 + struct au_xino *xi;
37941 + xi = au_xino_alloc(idx + 1);
37942 + if (unlikely(!xi)) {
37949 + xi->xi_file[idx] = file;
37950 + AuDebugOn(br->br_xino);
37951 + br->br_xino = xi;
37957 +static void au_xino_release(struct kref *kref)
37959 + struct au_xino *xi;
37961 + unsigned long ul;
37962 + struct hlist_bl_head *hbl;
37963 + struct hlist_bl_node *pos, *n;
37964 + struct au_xi_writing *p;
37966 + xi = container_of(kref, struct au_xino, xi_kref);
37967 + for (i = 0; i < xi->xi_nfile; i++)
37968 + if (xi->xi_file[i])
37969 + fput(xi->xi_file[i]);
37970 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
37971 + AuDebugOn(xi->xi_nondir.array[i]);
37972 + mutex_destroy(&xi->xi_mtx);
37973 + hbl = &xi->xi_writing;
37974 + ul = au_hbl_count(hbl);
37975 + if (unlikely(ul)) {
37976 + pr_warn("xi_writing %lu\n", ul);
37977 + hlist_bl_lock(hbl);
37978 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
37979 + hlist_bl_del(&p->node);
37980 + /* kmemleak reported au_kfree_rcu() doesn't free it */
37983 + hlist_bl_unlock(hbl);
37985 + au_kfree_try_rcu(xi->xi_file);
37986 + au_kfree_try_rcu(xi->xi_nondir.array);
37987 + au_kfree_rcu(xi);
37990 +int au_xino_put(struct au_branch *br)
37993 + struct au_xino *xi;
37996 + xi = br->br_xino;
37998 + br->br_xino = NULL;
37999 + ret = kref_put(&xi->xi_kref, au_xino_release);
38005 +/* ---------------------------------------------------------------------- */
38008 + * xino mount option handlers
38012 +static void xino_clear_xib(struct super_block *sb)
38014 + struct au_sbinfo *sbinfo;
38016 + SiMustWriteLock(sb);
38018 + sbinfo = au_sbi(sb);
38019 + if (sbinfo->si_xib)
38020 + fput(sbinfo->si_xib);
38021 + sbinfo->si_xib = NULL;
38022 + if (sbinfo->si_xib_buf)
38023 + free_page((unsigned long)sbinfo->si_xib_buf);
38024 + sbinfo->si_xib_buf = NULL;
38027 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38031 + struct au_sbinfo *sbinfo;
38032 + struct file *file;
38033 + struct super_block *xi_sb;
38035 + SiMustWriteLock(sb);
38037 + sbinfo = au_sbi(sb);
38038 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38039 + err = PTR_ERR(file);
38040 + if (IS_ERR(file))
38042 + if (sbinfo->si_xib)
38043 + fput(sbinfo->si_xib);
38044 + sbinfo->si_xib = file;
38045 + xi_sb = file_inode(file)->i_sb;
38046 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38047 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38049 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38050 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38053 + sbinfo->si_ximaxent /= sizeof(ino_t);
38056 + if (!sbinfo->si_xib_buf)
38057 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38058 + if (unlikely(!sbinfo->si_xib_buf))
38061 + sbinfo->si_xib_last_pindex = 0;
38062 + sbinfo->si_xib_next_bit = 0;
38063 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38065 + err = xino_fwrite(file, sbinfo->si_xib_buf, PAGE_SIZE, &pos);
38066 + if (unlikely(err != PAGE_SIZE))
38070 + goto out; /* success */
38073 + if (sbinfo->si_xib_buf)
38074 + free_page((unsigned long)sbinfo->si_xib_buf);
38075 + sbinfo->si_xib_buf = NULL;
38079 + fput(sbinfo->si_xib);
38080 + sbinfo->si_xib = NULL;
38086 +/* xino for each branch */
38087 +static void xino_clear_br(struct super_block *sb)
38089 + aufs_bindex_t bindex, bbot;
38090 + struct au_branch *br;
38092 + bbot = au_sbbot(sb);
38093 + for (bindex = 0; bindex <= bbot; bindex++) {
38094 + br = au_sbr(sb, bindex);
38100 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38101 + aufs_bindex_t bshared)
38103 + struct au_branch *brshared;
38105 + brshared = au_sbr(sb, bshared);
38106 + AuDebugOn(!brshared->br_xino);
38107 + AuDebugOn(!brshared->br_xino->xi_file);
38108 + if (br->br_xino != brshared->br_xino) {
38109 + au_xino_get(brshared);
38111 + br->br_xino = brshared->br_xino;
38115 +struct au_xino_do_set_br {
38116 + struct au_branch *br;
38118 + aufs_bindex_t bshared;
38121 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38122 + struct au_xino_do_set_br *args)
38125 + struct au_xi_calc calc;
38126 + struct file *file;
38127 + struct au_branch *br;
38128 + struct au_xi_new xinew = {
38133 + xinew.xi = br->br_xino;
38134 + au_xi_calc(sb, args->h_ino, &calc);
38135 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38136 + if (args->bshared >= 0)
38137 + /* shared xino */
38138 + au_xino_set_br_shared(sb, br, args->bshared);
38139 + else if (!xinew.xi) {
38141 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38142 + if (unlikely(err))
38146 + /* force re-creating */
38147 + xinew.xi = br->br_xino;
38148 + xinew.idx = calc.idx;
38149 + mutex_lock(&xinew.xi->xi_mtx);
38150 + file = au_xi_new(sb, &xinew);
38151 + mutex_unlock(&xinew.xi->xi_mtx);
38152 + err = PTR_ERR(file);
38153 + if (IS_ERR(file))
38155 + AuDebugOn(!file);
38157 + err = au_xino_do_write(file, &calc, AUFS_ROOT_INO);
38158 + if (unlikely(err))
38166 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38169 + aufs_bindex_t bindex, bbot;
38170 + struct au_xino_do_set_br args;
38171 + struct inode *inode;
38173 + SiMustWriteLock(sb);
38175 + bbot = au_sbbot(sb);
38176 + inode = d_inode(sb->s_root);
38177 + for (bindex = 0; bindex <= bbot; bindex++) {
38178 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38179 + args.br = au_sbr(sb, bindex);
38180 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38181 + err = au_xino_do_set_br(sb, path, &args);
38182 + if (unlikely(err))
38190 +void au_xino_clr(struct super_block *sb)
38192 + struct au_sbinfo *sbinfo;
38194 + au_xigen_clr(sb);
38195 + xino_clear_xib(sb);
38196 + xino_clear_br(sb);
38197 + dbgaufs_brs_del(sb, 0);
38198 + sbinfo = au_sbi(sb);
38199 + /* lvalue, do not call au_mntflags() */
38200 + au_opt_clr(sbinfo->si_mntflags, XINO);
38203 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38206 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38207 + struct qstr *dname, *cur_name;
38208 + struct file *cur_xino;
38209 + struct au_sbinfo *sbinfo;
38210 + struct path *path, *cur_path;
38212 + SiMustWriteLock(sb);
38215 + sbinfo = au_sbi(sb);
38216 + path = &xiopt->file->f_path;
38217 + dentry = path->dentry;
38218 + parent = dget_parent(dentry);
38221 + cur_xino = sbinfo->si_xib;
38223 + cur_path = &cur_xino->f_path;
38224 + cur_dentry = cur_path->dentry;
38225 + cur_parent = dget_parent(cur_dentry);
38226 + cur_name = &cur_dentry->d_name;
38227 + dname = &dentry->d_name;
38228 + skip = (cur_parent == parent
38229 + && au_qstreq(dname, cur_name));
38230 + dput(cur_parent);
38236 + au_opt_set(sbinfo->si_mntflags, XINO);
38237 + err = au_xino_set_xib(sb, path);
38238 + /* si_x{read,write} are set */
38240 + err = au_xigen_set(sb, path);
38242 + err = au_xino_set_br(sb, path);
38244 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38245 + goto out; /* success */
38249 + AuIOErr("failed setting xino(%d).\n", err);
38258 + * create a xinofile at the default place/path.
38260 +struct file *au_xino_def(struct super_block *sb)
38262 + struct file *file;
38264 + struct au_branch *br;
38265 + struct super_block *h_sb;
38266 + struct path path;
38267 + aufs_bindex_t bbot, bindex, bwr;
38270 + bbot = au_sbbot(sb);
38272 + for (bindex = 0; bindex <= bbot; bindex++) {
38273 + br = au_sbr(sb, bindex);
38274 + if (au_br_writable(br->br_perm)
38275 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38282 + file = ERR_PTR(-ENOMEM);
38283 + page = (void *)__get_free_page(GFP_NOFS);
38284 + if (unlikely(!page))
38286 + path.mnt = au_br_mnt(br);
38287 + path.dentry = au_h_dptr(sb->s_root, bwr);
38288 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38289 + file = (void *)p;
38290 + if (!IS_ERR(p)) {
38291 + strcat(p, "/" AUFS_XINO_FNAME);
38292 + AuDbg("%s\n", p);
38293 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38295 + free_page((unsigned long)page);
38297 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38299 + if (IS_ERR(file))
38301 + h_sb = file->f_path.dentry->d_sb;
38302 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38303 + pr_err("xino doesn't support %s(%s)\n",
38304 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38306 + file = ERR_PTR(-EINVAL);
38314 +/* ---------------------------------------------------------------------- */
38317 + * initialize the xinofile for the specified branch @br
38318 + * at the place/path where @base_file indicates.
38319 + * test whether another branch is on the same filesystem or not,
38320 + * if found then share the xinofile with another branch.
38322 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38323 + struct path *base)
38326 + struct au_xino_do_set_br args = {
38331 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38333 + err = au_xino_do_set_br(sb, base, &args);
38334 + if (unlikely(err))
38340 +/* ---------------------------------------------------------------------- */
38343 + * get an unused inode number from bitmap
38345 +ino_t au_xino_new_ino(struct super_block *sb)
38348 + unsigned long *p, pindex, ul, pend;
38349 + struct au_sbinfo *sbinfo;
38350 + struct file *file;
38351 + int free_bit, err;
38353 + if (!au_opt_test(au_mntflags(sb), XINO))
38354 + return iunique(sb, AUFS_FIRST_INO);
38356 + sbinfo = au_sbi(sb);
38357 + mutex_lock(&sbinfo->si_xib_mtx);
38358 + p = sbinfo->si_xib_buf;
38359 + free_bit = sbinfo->si_xib_next_bit;
38360 + if (free_bit < page_bits && !test_bit(free_bit, p))
38361 + goto out; /* success */
38362 + free_bit = find_first_zero_bit(p, page_bits);
38363 + if (free_bit < page_bits)
38364 + goto out; /* success */
38366 + pindex = sbinfo->si_xib_last_pindex;
38367 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38368 + err = xib_pindex(sb, ul);
38369 + if (unlikely(err))
38371 + free_bit = find_first_zero_bit(p, page_bits);
38372 + if (free_bit < page_bits)
38373 + goto out; /* success */
38376 + file = sbinfo->si_xib;
38377 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38378 + for (ul = pindex + 1; ul <= pend; ul++) {
38379 + err = xib_pindex(sb, ul);
38380 + if (unlikely(err))
38382 + free_bit = find_first_zero_bit(p, page_bits);
38383 + if (free_bit < page_bits)
38384 + goto out; /* success */
38389 + set_bit(free_bit, p);
38390 + sbinfo->si_xib_next_bit = free_bit + 1;
38391 + pindex = sbinfo->si_xib_last_pindex;
38392 + mutex_unlock(&sbinfo->si_xib_mtx);
38393 + ino = xib_calc_ino(pindex, free_bit);
38394 + AuDbg("i%lu\n", (unsigned long)ino);
38397 + mutex_unlock(&sbinfo->si_xib_mtx);
38402 +/* for s_op->delete_inode() */
38403 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38406 + unsigned int mnt_flags;
38407 + aufs_bindex_t bindex, bbot, bi;
38408 + unsigned char try_trunc;
38409 + struct au_iinfo *iinfo;
38410 + struct super_block *sb;
38411 + struct au_hinode *hi;
38412 + struct inode *h_inode;
38413 + struct au_branch *br;
38414 + struct au_xi_calc calc;
38415 + struct file *file;
38417 + AuDebugOn(au_is_bad_inode(inode));
38419 + sb = inode->i_sb;
38420 + mnt_flags = au_mntflags(sb);
38421 + if (!au_opt_test(mnt_flags, XINO)
38422 + || inode->i_ino == AUFS_ROOT_INO)
38426 + au_xigen_inc(inode);
38427 + au_xib_clear_bit(inode);
38430 + iinfo = au_ii(inode);
38431 + bindex = iinfo->ii_btop;
38435 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38436 + hi = au_hinode(iinfo, bindex);
38437 + bbot = iinfo->ii_bbot;
38438 + for (; bindex <= bbot; bindex++, hi++) {
38439 + h_inode = hi->hi_inode;
38441 + || (!unlinked && h_inode->i_nlink))
38444 + /* inode may not be revalidated */
38445 + bi = au_br_index(sb, hi->hi_id);
38449 + br = au_sbr(sb, bi);
38450 + au_xi_calc(sb, h_inode->i_ino, &calc);
38451 + file = au_xino_file(br->br_xino, calc.idx);
38452 + if (IS_ERR_OR_NULL(file))
38455 + err = au_xino_do_write(file, &calc, /*ino*/0);
38456 + if (!err && try_trunc
38457 + && au_test_fs_trunc_xino(au_br_sb(br)))
38458 + xino_try_trunc(sb, br);
38462 +/* ---------------------------------------------------------------------- */
38464 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38466 + int found, total, i;
38469 + total = xi->xi_nondir.total;
38470 + for (i = 0; i < total; i++) {
38471 + if (xi->xi_nondir.array[i] != h_ino)
38480 +static int au_xinondir_expand(struct au_xino *xi)
38485 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38488 + sz = xi->xi_nondir.total * sizeof(ino_t);
38489 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38491 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38492 + /*may_shrink*/0);
38494 + xi->xi_nondir.array = p;
38495 + xi->xi_nondir.total <<= 1;
38496 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38504 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38505 + ino_t h_ino, int idx)
38507 + struct au_xino *xi;
38509 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38510 + xi = au_sbr(sb, bindex)->br_xino;
38511 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38513 + spin_lock(&xi->xi_nondir.spin);
38514 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38515 + xi->xi_nondir.array[idx] = 0;
38516 + spin_unlock(&xi->xi_nondir.spin);
38517 + wake_up_all(&xi->xi_nondir.wqh);
38520 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38523 + int err, found, empty;
38524 + struct au_xino *xi;
38528 + if (!au_opt_test(au_mntflags(sb), XINO))
38529 + goto out; /* no xino */
38531 + xi = au_sbr(sb, bindex)->br_xino;
38534 + spin_lock(&xi->xi_nondir.spin);
38535 + found = au_xinondir_find(xi, h_ino);
38536 + if (found == -1) {
38537 + empty = au_xinondir_find(xi, /*h_ino*/0);
38538 + if (empty == -1) {
38539 + empty = xi->xi_nondir.total;
38540 + err = au_xinondir_expand(xi);
38541 + if (unlikely(err))
38544 + xi->xi_nondir.array[empty] = h_ino;
38547 + spin_unlock(&xi->xi_nondir.spin);
38548 + wait_event(xi->xi_nondir.wqh,
38549 + xi->xi_nondir.array[found] != h_ino);
38554 + spin_unlock(&xi->xi_nondir.spin);
38559 +/* ---------------------------------------------------------------------- */
38561 +int au_xino_path(struct seq_file *seq, struct file *file)
38565 + err = au_seq_path(seq, &file->f_path);
38566 + if (unlikely(err))
38569 +#define Deleted "\\040(deleted)"
38570 + seq->count -= sizeof(Deleted) - 1;
38571 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38572 + sizeof(Deleted) - 1));
38578 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38579 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38580 +++ linux/include/uapi/linux/aufs_type.h 2020-10-14 08:51:27.819581640 +0200
38582 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
38584 + * Copyright (C) 2005-2020 Junjiro R. Okajima
38586 + * This program, aufs is free software; you can redistribute it and/or modify
38587 + * it under the terms of the GNU General Public License as published by
38588 + * the Free Software Foundation; either version 2 of the License, or
38589 + * (at your option) any later version.
38591 + * This program is distributed in the hope that it will be useful,
38592 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38593 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38594 + * GNU General Public License for more details.
38596 + * You should have received a copy of the GNU General Public License
38597 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38600 +#ifndef __AUFS_TYPE_H__
38601 +#define __AUFS_TYPE_H__
38603 +#define AUFS_NAME "aufs"
38607 + * define it before including all other headers.
38608 + * sched.h may use pr_* macros before defining "current", so define the
38609 + * no-current version first, and re-define later.
38611 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38612 +#include <linux/sched.h>
38614 +#define pr_fmt(fmt) \
38615 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38616 + (int)sizeof(current->comm), current->comm, current->pid
38617 +#include <linux/limits.h>
38619 +#include <stdint.h>
38620 +#include <sys/types.h>
38621 +#include <limits.h>
38622 +#endif /* __KERNEL__ */
38624 +#define AUFS_VERSION "5.x-rcN-20200622"
38626 +/* todo? move this to linux-2.6.19/include/magic.h */
38627 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38629 +/* ---------------------------------------------------------------------- */
38632 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38633 +typedef int8_t aufs_bindex_t;
38634 +#define AUFS_BRANCH_MAX 127
38636 +typedef int16_t aufs_bindex_t;
38637 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38638 +#define AUFS_BRANCH_MAX 511
38639 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38640 +#define AUFS_BRANCH_MAX 1023
38641 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38642 +#define AUFS_BRANCH_MAX 32767
38646 +#ifndef AUFS_BRANCH_MAX
38647 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38649 +#endif /* __KERNEL__ */
38651 +/* ---------------------------------------------------------------------- */
38653 +#define AUFS_FSTYPE AUFS_NAME
38655 +#define AUFS_ROOT_INO 2
38656 +#define AUFS_FIRST_INO 11
38658 +#define AUFS_WH_PFX ".wh."
38659 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38660 +#define AUFS_WH_TMP_LEN 4
38661 +/* a limit for rmdir/rename a dir and copyup */
38662 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38663 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38665 + - AUFS_WH_TMP_LEN) /* hex */
38666 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38667 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38668 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38669 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38670 +#define AUFS_DIRWH_DEF 3
38671 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38672 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38673 +#define AUFS_RDBLK_DEF 512 /* bytes */
38674 +#define AUFS_RDHASH_DEF 32
38675 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38676 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38677 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38678 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38679 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38681 +/* pseudo-link maintenace under /proc */
38682 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38683 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38684 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38686 +/* dirren, renamed dir */
38687 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38688 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38689 +/* whiteouted doubly */
38690 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38691 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38693 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38694 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38696 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38697 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38698 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38700 +/* doubly whiteouted */
38701 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38702 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38703 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38705 +/* branch permissions and attributes */
38706 +#define AUFS_BRPERM_RW "rw"
38707 +#define AUFS_BRPERM_RO "ro"
38708 +#define AUFS_BRPERM_RR "rr"
38709 +#define AUFS_BRATTR_COO_REG "coo_reg"
38710 +#define AUFS_BRATTR_COO_ALL "coo_all"
38711 +#define AUFS_BRATTR_FHSM "fhsm"
38712 +#define AUFS_BRATTR_UNPIN "unpin"
38713 +#define AUFS_BRATTR_ICEX "icex"
38714 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38715 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38716 +#define AUFS_BRATTR_ICEX_TR "icextr"
38717 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38718 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38719 +#define AUFS_BRRATTR_WH "wh"
38720 +#define AUFS_BRWATTR_NLWH "nolwh"
38721 +#define AUFS_BRWATTR_MOO "moo"
38723 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38724 +#define AuBrPerm_RO (1 << 1) /* readonly */
38725 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38726 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38728 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38729 +#define AuBrAttr_COO_ALL (1 << 4)
38730 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38732 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38733 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38734 + branch. meaningless since
38735 + linux-3.18-rc1 */
38737 +/* ignore error in copying XATTR */
38738 +#define AuBrAttr_ICEX_SEC (1 << 7)
38739 +#define AuBrAttr_ICEX_SYS (1 << 8)
38740 +#define AuBrAttr_ICEX_TR (1 << 9)
38741 +#define AuBrAttr_ICEX_USR (1 << 10)
38742 +#define AuBrAttr_ICEX_OTH (1 << 11)
38743 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38744 + | AuBrAttr_ICEX_SYS \
38745 + | AuBrAttr_ICEX_TR \
38746 + | AuBrAttr_ICEX_USR \
38747 + | AuBrAttr_ICEX_OTH)
38749 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
38750 +#define AuBrRAttr_Mask AuBrRAttr_WH
38752 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
38753 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
38754 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
38756 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
38758 +/* #warning test userspace */
38760 +#ifndef CONFIG_AUFS_FHSM
38761 +#undef AuBrAttr_FHSM
38762 +#define AuBrAttr_FHSM 0
38764 +#ifndef CONFIG_AUFS_XATTR
38765 +#undef AuBrAttr_ICEX
38766 +#define AuBrAttr_ICEX 0
38767 +#undef AuBrAttr_ICEX_SEC
38768 +#define AuBrAttr_ICEX_SEC 0
38769 +#undef AuBrAttr_ICEX_SYS
38770 +#define AuBrAttr_ICEX_SYS 0
38771 +#undef AuBrAttr_ICEX_TR
38772 +#define AuBrAttr_ICEX_TR 0
38773 +#undef AuBrAttr_ICEX_USR
38774 +#define AuBrAttr_ICEX_USR 0
38775 +#undef AuBrAttr_ICEX_OTH
38776 +#define AuBrAttr_ICEX_OTH 0
38780 +/* the longest combination */
38781 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
38782 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
38783 + "+" AUFS_BRATTR_COO_REG \
38784 + "+" AUFS_BRATTR_FHSM \
38785 + "+" AUFS_BRATTR_UNPIN \
38786 + "+" AUFS_BRATTR_ICEX_SEC \
38787 + "+" AUFS_BRATTR_ICEX_SYS \
38788 + "+" AUFS_BRATTR_ICEX_USR \
38789 + "+" AUFS_BRATTR_ICEX_OTH \
38790 + "+" AUFS_BRWATTR_NLWH)
38793 + char a[AuBrPermStrSz];
38794 +} au_br_perm_str_t;
38796 +static inline int au_br_writable(int brperm)
38798 + return brperm & AuBrPerm_RW;
38801 +static inline int au_br_whable(int brperm)
38803 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
38806 +static inline int au_br_wh_linkable(int brperm)
38808 + return !(brperm & AuBrWAttr_NoLinkWH);
38811 +static inline int au_br_cmoo(int brperm)
38813 + return brperm & AuBrAttr_CMOO_Mask;
38816 +static inline int au_br_fhsm(int brperm)
38818 + return brperm & AuBrAttr_FHSM;
38821 +/* ---------------------------------------------------------------------- */
38825 + /* readdir in userspace */
38829 + AuCtl_WBR_FD, /* pathconf wrapper */
38830 + AuCtl_IBUSY, /* busy inode */
38831 + AuCtl_MVDOWN, /* move-down */
38832 + AuCtl_BR, /* info about branches */
38833 + AuCtl_FHSM_FD /* connection for fhsm */
38836 +/* borrowed from linux/include/linux/kernel.h */
38838 +#ifdef _GNU_SOURCE
38839 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
38841 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
38843 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
38846 +/* borrowed from linux/include/linux/compiler-gcc3.h */
38848 +#define __aligned(x) __attribute__((aligned(x)))
38853 +#define __packed __attribute__((packed))
38857 +struct au_rdu_cookie {
38862 + uint32_t generation;
38865 +struct au_rdu_ent {
38874 +static inline int au_rdu_len(int nlen)
38876 + /* include the terminating NULL */
38877 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
38878 + sizeof(uint64_t));
38881 +union au_rdu_ent_ul {
38882 + struct au_rdu_ent __user *e;
38894 + uint64_t sz; /* AuCtl_RDU */
38895 + uint64_t nent; /* AuCtl_RDU_INO */
38897 + union au_rdu_ent_ul ent;
38898 + uint16_t verify[AufsCtlRduV_End];
38900 + /* input/output */
38904 + union au_rdu_ent_ul tail;
38905 + /* number of entries which were added in a single call */
38910 + struct au_rdu_cookie cookie;
38913 +/* ---------------------------------------------------------------------- */
38915 +/* dirren. the branch is identified by the filename who contains this */
38916 +struct au_drinfo {
38919 + uint8_t oldnamelen;
38920 + uint64_t _padding;
38922 + uint8_t oldname[];
38925 +struct au_drinfo_fdata {
38927 + struct au_drinfo drinfo;
38930 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
38932 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
38934 +/* ---------------------------------------------------------------------- */
38936 +struct aufs_wbr_fd {
38941 +/* ---------------------------------------------------------------------- */
38943 +struct aufs_ibusy {
38944 + uint64_t ino, h_ino;
38948 +/* ---------------------------------------------------------------------- */
38950 +/* error code for move-down */
38951 +/* the actual message strings are implemented in aufs-util.git */
38953 + EAU_MVDOWN_OPAQUE = 1,
38954 + EAU_MVDOWN_WHITEOUT,
38955 + EAU_MVDOWN_UPPER,
38956 + EAU_MVDOWN_BOTTOM,
38957 + EAU_MVDOWN_NOUPPER,
38958 + EAU_MVDOWN_NOLOWERBR,
38962 +/* flags for move-down */
38963 +#define AUFS_MVDOWN_DMSG 1
38964 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
38965 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
38966 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
38967 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
38968 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
38969 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
38970 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
38971 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
38972 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
38973 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
38974 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
38975 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
38977 +/* index for move-down */
38979 + AUFS_MVDOWN_UPPER,
38980 + AUFS_MVDOWN_LOWER,
38981 + AUFS_MVDOWN_NARRAY
38985 + * additional info of move-down
38986 + * number of free blocks and inodes.
38987 + * subset of struct kstatfs, but smaller and always 64bit.
38989 +struct aufs_stfs {
38990 + uint64_t f_blocks;
38991 + uint64_t f_bavail;
38992 + uint64_t f_files;
38993 + uint64_t f_ffree;
38996 +struct aufs_stbr {
38997 + int16_t brid; /* optional input */
38998 + int16_t bindex; /* output */
38999 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39002 +struct aufs_mvdown {
39003 + uint32_t flags; /* input/output */
39004 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39005 + int8_t au_errno; /* output */
39008 +/* ---------------------------------------------------------------------- */
39010 +union aufs_brinfo {
39011 + /* PATH_MAX may differ between kernel-space and user-space */
39012 + char _spacer[4096];
39020 +/* ---------------------------------------------------------------------- */
39022 +#define AuCtlType 'A'
39023 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39024 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39025 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39026 + struct aufs_wbr_fd)
39027 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39028 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39029 + struct aufs_mvdown)
39030 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39031 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39033 +#endif /* __AUFS_TYPE_H__ */
39034 SPDX-License-Identifier: GPL-2.0
39035 aufs5.x-rcN loopback patch
39037 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39038 index 0479902a0cd50..758c8ee4d4e6b 100644
39039 --- a/drivers/block/loop.c
39040 +++ b/drivers/block/loop.c
39041 @@ -638,6 +638,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39045 +static struct file *loop_real_file(struct file *file)
39047 + struct file *f = NULL;
39049 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39050 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39054 static void loop_reread_partitions(struct loop_device *lo,
39055 struct block_device *bdev)
39057 @@ -693,6 +702,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39060 struct file *file = NULL, *old_file;
39061 + struct file *f, *virt_file = NULL, *old_virt_file;
39065 @@ -712,12 +722,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39069 + f = loop_real_file(file);
39071 + virt_file = file;
39076 error = loop_validate_file(file, bdev);
39080 old_file = lo->lo_backing_file;
39081 + old_virt_file = lo->lo_backing_virt_file;
39085 @@ -729,6 +746,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39086 blk_mq_freeze_queue(lo->lo_queue);
39087 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39088 lo->lo_backing_file = file;
39089 + lo->lo_backing_virt_file = virt_file;
39090 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39091 mapping_set_gfp_mask(file->f_mapping,
39092 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39093 @@ -742,6 +760,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39097 + if (old_virt_file)
39098 + fput(old_virt_file);
39100 loop_reread_partitions(lo, bdev);
39102 @@ -750,6 +770,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39103 mutex_unlock(&loop_ctl_mutex);
39111 @@ -973,7 +995,7 @@ static void loop_update_rotational(struct loop_device *lo)
39112 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39113 struct block_device *bdev, unsigned int arg)
39115 - struct file *file;
39116 + struct file *file, *f, *virt_file = NULL;
39117 struct inode *inode;
39118 struct address_space *mapping;
39119 struct block_device *claimed_bdev = NULL;
39120 @@ -989,6 +1011,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39124 + f = loop_real_file(file);
39126 + virt_file = file;
39132 * If we don't hold exclusive handle for the device, upgrade to it
39133 @@ -1079,6 +1079,7 @@ static int loop_configure(struct loop_de
39134 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39135 lo->lo_device = bdev;
39136 lo->lo_backing_file = file;
39137 + lo->lo_backing_virt_file = virt_file;
39138 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39139 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39141 @@ -1090,6 +1119,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39142 bd_abort_claiming(bdev, claimed_bdev, loop_set_fd);
39148 /* This is safe: open() is still holding a reference. */
39149 module_put(THIS_MODULE);
39150 @@ -1136,6 +1167,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
39151 static int __loop_clr_fd(struct loop_device *lo, bool release)
39153 struct file *filp = NULL;
39154 + struct file *virt_filp = lo->lo_backing_virt_file;
39155 gfp_t gfp = lo->old_gfp_mask;
39156 struct block_device *bdev = lo->lo_device;
39158 @@ -1159,6 +1191,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39160 spin_lock_irq(&lo->lo_lock);
39161 lo->lo_backing_file = NULL;
39162 + lo->lo_backing_virt_file = NULL;
39163 spin_unlock_irq(&lo->lo_lock);
39165 loop_release_xfer(lo);
39166 @@ -1242,6 +1275,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39175 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39176 index af75a5ee40944..1d847cb194ff6 100644
39177 --- a/drivers/block/loop.h
39178 +++ b/drivers/block/loop.h
39179 @@ -46,7 +46,7 @@ struct loop_device {
39180 int (*ioctl)(struct loop_device *, int cmd,
39181 unsigned long arg);
39183 - struct file * lo_backing_file;
39184 + struct file *lo_backing_file, *lo_backing_virt_file;
39185 struct block_device *lo_device;
39188 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39189 index 6fb4a4ed8cc7f..ba9a959f2db27 100644
39190 --- a/fs/aufs/f_op.c
39191 +++ b/fs/aufs/f_op.c
39192 @@ -359,7 +359,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39193 if (IS_ERR(h_file))
39196 - if (au_test_loopback_kthread()) {
39197 + if (0 && au_test_loopback_kthread()) {
39198 au_warn_loopback(h_file->f_path.dentry->d_sb);
39199 if (file->f_mapping != h_file->f_mapping) {
39200 file->f_mapping = h_file->f_mapping;
39201 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39202 index a8b63acc62045..9d97c3af5686a 100644
39203 --- a/fs/aufs/loop.c
39204 +++ b/fs/aufs/loop.c
39205 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39206 symbol_put(loop_backing_file);
39207 au_kfree_try_rcu(au_warn_loopback_array);
39210 +/* ---------------------------------------------------------------------- */
39212 +/* support the loopback block device insude aufs */
39214 +struct file *aufs_real_loop(struct file *file)
39218 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39219 + fi_read_lock(file);
39220 + f = au_hf_top(file);
39221 + fi_read_unlock(file);
39225 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39226 index 94f4f80ae33bf..ca1194354aff4 100644
39227 --- a/fs/aufs/loop.h
39228 +++ b/fs/aufs/loop.h
39229 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39231 int au_loopback_init(void);
39232 void au_loopback_fin(void);
39234 +struct file *aufs_real_loop(struct file *file);
39236 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39238 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39240 AuStubInt0(au_loopback_init, void)
39241 AuStubVoid(au_loopback_fin, void)
39243 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39244 #endif /* BLK_DEV_LOOP */
39246 #endif /* __KERNEL__ */
39247 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39248 index 589dd01220201..801e0a7faec59 100644
39249 --- a/fs/aufs/super.c
39250 +++ b/fs/aufs/super.c
39251 @@ -844,7 +844,10 @@ static const struct super_operations aufs_sop = {
39252 .statfs = aufs_statfs,
39253 .put_super = aufs_put_super,
39254 .sync_fs = aufs_sync_fs,
39255 - .remount_fs = aufs_remount_fs
39256 + .remount_fs = aufs_remount_fs,
39257 +#ifdef CONFIG_AUFS_BDEV_LOOP
39258 + .real_loop = aufs_real_loop
39262 /* ---------------------------------------------------------------------- */
39263 diff --git a/include/linux/fs.h b/include/linux/fs.h
39264 index 916efd7e612b3..68f536f42b2a0 100644
39265 --- a/include/linux/fs.h
39266 +++ b/include/linux/fs.h
39267 @@ -1985,6 +1985,10 @@ struct super_operations {
39268 struct shrink_control *);
39269 long (*free_cached_objects)(struct super_block *,
39270 struct shrink_control *);
39271 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39273 + struct file *(*real_loop)(struct file *);