1 SPDX-License-Identifier: GPL-2.0
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index a547307c1ae8..919ca5404804 100644
8 @@ -318,6 +318,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 93b80529f8e8..a26c58d09435 100644
20 @@ -138,3 +138,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
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index 72b9654f764c..53fc0e89d1ea 100644
32 @@ -3425,6 +3425,19 @@ 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
41 +W: http://aufs.sourceforge.net
42 +T: git://github.com/sfjro/aufs4-linux.git
43 +F: Documentation/ABI/testing/debugfs-aufs
44 +F: Documentation/ABI/testing/sysfs-aufs
45 +F: Documentation/filesystems/aufs/
47 +F: include/uapi/linux/aufs_type.h
49 AUXILIARY DISPLAY DRIVERS
50 M: Miguel Ojeda <ojeda@kernel.org>
52 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
53 index ad92192c7d61..8ca56da3ca69 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -645,6 +645,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 bb0c4d0038db..d753ad7d77e6 100644
85 @@ -1345,7 +1345,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 146c9ab0cd4b..c980a0524118 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/namespace.c b/fs/namespace.c
117 index df137ba19d37..faae7f8644ac 100644
120 @@ -852,6 +852,12 @@ static inline int check_mnt(struct mount *mnt)
121 return mnt->mnt_ns == current->nsproxy->mnt_ns;
124 +/* for aufs, CONFIG_AUFS_BR_FUSE */
125 +int is_current_mnt_ns(struct vfsmount *mnt)
127 + return check_mnt(real_mount(mnt));
131 * vfsmount lock must be held for write
133 diff --git a/fs/splice.c b/fs/splice.c
134 index 0878b852b355..d83f9e5cddbc 100644
137 @@ -756,8 +756,8 @@ static int warn_unsupported(struct file *file, const char *op)
139 * Attempt to initiate a splice from pipe to file.
141 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
142 - loff_t *ppos, size_t len, unsigned int flags)
143 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
144 + loff_t *ppos, size_t len, unsigned int flags)
146 if (unlikely(!out->f_op->splice_write))
147 return warn_unsupported(out, "write");
148 @@ -767,9 +767,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
150 * Attempt to initiate a splice from a file to a pipe.
152 -static long do_splice_to(struct file *in, loff_t *ppos,
153 - struct pipe_inode_info *pipe, size_t len,
154 - unsigned int flags)
155 +long do_splice_to(struct file *in, loff_t *ppos,
156 + struct pipe_inode_info *pipe, size_t len,
157 + unsigned int flags)
159 unsigned int p_space;
161 diff --git a/include/linux/fs.h b/include/linux/fs.h
162 index 9eced4cc286e..9c5a33fce3a8 100644
163 --- a/include/linux/fs.h
164 +++ b/include/linux/fs.h
165 @@ -1364,6 +1364,7 @@ extern void fasync_free(struct fasync_struct *);
166 /* can be called from interrupts */
167 extern void kill_fasync(struct fasync_struct **, int, int);
169 +extern int setfl(int fd, struct file *filp, unsigned long arg);
170 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
171 extern int f_setown(struct file *filp, unsigned long arg, int force);
172 extern void f_delown(struct file *filp);
173 @@ -2115,6 +2116,7 @@ struct file_operations {
174 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
175 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
176 int (*check_flags)(int);
177 + int (*setfl)(struct file *, unsigned long);
178 int (*flock) (struct file *, int, struct file_lock *);
179 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
180 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
181 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
182 index 1f1099dac3f0..81d10b8e9dc0 100644
183 --- a/include/linux/lockdep.h
184 +++ b/include/linux/lockdep.h
185 @@ -248,6 +248,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
186 return lock->key == key;
189 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
194 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
195 index 8f882f5881e8..6b9808f09843 100644
196 --- a/include/linux/mnt_namespace.h
197 +++ b/include/linux/mnt_namespace.h
198 @@ -7,12 +7,15 @@ struct mnt_namespace;
200 struct user_namespace;
204 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
205 struct user_namespace *, struct fs_struct *);
206 extern void put_mnt_ns(struct mnt_namespace *ns);
207 extern struct ns_common *from_mnt_ns(struct mnt_namespace *);
209 +extern int is_current_mnt_ns(struct vfsmount *mnt);
211 extern const struct file_operations proc_mounts_operations;
212 extern const struct file_operations proc_mountinfo_operations;
213 extern const struct file_operations proc_mountstats_operations;
214 diff --git a/include/linux/splice.h b/include/linux/splice.h
215 index a55179fd60fc..8e21c53cf883 100644
216 --- a/include/linux/splice.h
217 +++ b/include/linux/splice.h
218 @@ -93,4 +93,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
220 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
221 extern const struct pipe_buf_operations default_pipe_buf_ops;
223 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
224 + loff_t *ppos, size_t len, unsigned int flags);
225 +extern long do_splice_to(struct file *in, loff_t *ppos,
226 + struct pipe_inode_info *pipe, size_t len,
227 + unsigned int flags);
229 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
230 index 64a13eb56078..c9f30e12aa32 100644
231 --- a/kernel/locking/lockdep.c
232 +++ b/kernel/locking/lockdep.c
233 @@ -217,7 +217,7 @@ unsigned long max_lock_class_idx;
234 struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
235 DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS);
237 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
238 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
240 unsigned int class_idx = hlock->class_idx;
242 @@ -238,6 +238,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
244 return lock_classes + class_idx;
246 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
248 #ifdef CONFIG_LOCK_STAT
249 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
250 SPDX-License-Identifier: GPL-2.0
253 diff --git a/fs/proc/base.c b/fs/proc/base.c
254 index 93f7e3d971e4..23aa1626020a 100644
257 @@ -2218,7 +2218,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
259 vma = find_exact_vma(mm, vm_start, vm_end);
260 if (vma && vma->vm_file) {
261 - *path = vma->vm_file->f_path;
262 + *path = vma_pr_or_file(vma)->f_path;
266 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
267 index 4d3493579458..42edd9a42c78 100644
268 --- a/fs/proc/nommu.c
269 +++ b/fs/proc/nommu.c
270 @@ -39,7 +39,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
271 file = region->vm_file;
274 - struct inode *inode = file_inode(region->vm_file);
275 + struct inode *inode;
277 + file = vmr_pr_or_file(region);
278 + inode = file_inode(file);
279 dev = inode->i_sb->s_dev;
282 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
283 index 4e0023643f8b..09394cf6e349 100644
284 --- a/fs/proc/task_mmu.c
285 +++ b/fs/proc/task_mmu.c
286 @@ -281,7 +281,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
287 const char *name = NULL;
290 - struct inode *inode = file_inode(vma->vm_file);
291 + struct inode *inode;
293 + file = vma_pr_or_file(vma);
294 + inode = file_inode(file);
295 dev = inode->i_sb->s_dev;
297 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
298 @@ -1912,7 +1915,7 @@ static int show_numa_map(struct seq_file *m, void *v)
299 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
300 struct vm_area_struct *vma = v;
301 struct numa_maps *md = &numa_priv->md;
302 - struct file *file = vma->vm_file;
303 + struct file *file = vma_pr_or_file(vma);
304 struct mm_struct *mm = vma->vm_mm;
305 struct mempolicy *pol;
307 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
308 index a6d21fc0033c..02c2de31196e 100644
309 --- a/fs/proc/task_nommu.c
310 +++ b/fs/proc/task_nommu.c
311 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
315 - struct inode *inode = file_inode(vma->vm_file);
316 + struct inode *inode;
318 + file = vma_pr_or_file(vma);
319 + inode = file_inode(file);
320 dev = inode->i_sb->s_dev;
322 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
323 diff --git a/include/linux/mm.h b/include/linux/mm.h
324 index 21f8b27bd9fd..de9572fe212b 100644
325 --- a/include/linux/mm.h
326 +++ b/include/linux/mm.h
327 @@ -1858,6 +1858,43 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
328 unmap_mapping_range(mapping, holebegin, holelen, 0);
331 +#if IS_ENABLED(CONFIG_AUFS_FS)
332 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
333 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
335 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
336 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
338 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
340 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
342 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
343 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
346 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
347 +extern void vmr_do_fput(struct vm_region *, const char[], int);
349 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
351 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
352 +#endif /* !CONFIG_MMU */
356 +#define vma_file_update_time(vma) file_update_time((vma)->vm_file)
357 +#define vma_pr_or_file(vma) (vma)->vm_file
358 +#define vma_get_file(vma) get_file((vma)->vm_file)
359 +#define vma_fput(vma) fput((vma)->vm_file)
362 +#define vmr_pr_or_file(region) (region)->vm_file
363 +#define vmr_fput(region) fput((region)->vm_file)
364 +#endif /* !CONFIG_MMU */
366 +#endif /* CONFIG_AUFS_FS */
368 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
369 void *buf, int len, unsigned int gup_flags);
370 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
371 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
372 index cf97f3884fda..a783130a669d 100644
373 --- a/include/linux/mm_types.h
374 +++ b/include/linux/mm_types.h
375 @@ -372,6 +372,9 @@ struct vm_region {
376 unsigned long vm_top; /* region allocated to here */
377 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
378 struct file *vm_file; /* the backing file or NULL */
379 +#if IS_ENABLED(CONFIG_AUFS_FS)
380 + struct file *vm_prfile; /* the virtual backing file or NULL */
383 int vm_usage; /* region usage count (access under nommu_region_sem) */
384 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
385 @@ -468,6 +471,9 @@ struct vm_area_struct {
386 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
388 struct file * vm_file; /* File we map to (can be NULL). */
389 +#if IS_ENABLED(CONFIG_AUFS_FS)
390 + struct file *vm_prfile; /* shadow of vm_file */
392 void * vm_private_data; /* was vm_pte (shared mem) */
395 diff --git a/kernel/fork.c b/kernel/fork.c
396 index 2b6bd511c6ed..944adfb5189a 100644
399 @@ -662,7 +662,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
401 struct address_space *mapping = file->f_mapping;
405 i_mmap_lock_write(mapping);
406 if (tmp->vm_flags & VM_SHARED)
407 mapping_allow_writable(mapping);
408 diff --git a/mm/Makefile b/mm/Makefile
409 index 9a564f836403..86a4be7f34a8 100644
412 @@ -134,3 +134,4 @@ obj-$(CONFIG_IO_MAPPING) += io-mapping.o
413 obj-$(CONFIG_HAVE_BOOTMEM_INFO_NODE) += bootmem_info.o
414 obj-$(CONFIG_GENERIC_IOREMAP) += ioremap.o
415 obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o
416 +obj-$(CONFIG_AUFS_FS:m=y) += prfile.o
417 diff --git a/mm/filemap.c b/mm/filemap.c
418 index 15800334147b..2c22abb4a14d 100644
421 @@ -3403,7 +3403,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
422 vm_fault_t ret = VM_FAULT_LOCKED;
424 sb_start_pagefault(mapping->host->i_sb);
425 - file_update_time(vmf->vma->vm_file);
426 + vma_file_update_time(vmf->vma);
428 if (folio->mapping != mapping) {
430 diff --git a/mm/mmap.c b/mm/mmap.c
431 index 9d780f415be3..e744ba276454 100644
434 @@ -142,7 +142,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
435 if (vma->vm_ops && vma->vm_ops->close)
436 vma->vm_ops->close(vma);
438 - fput(vma->vm_file);
440 mpol_put(vma_policy(vma));
443 @@ -911,7 +911,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
446 uprobe_munmap(next, next->vm_start, next->vm_end);
451 anon_vma_merge(vma, next);
452 @@ -1845,7 +1845,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
453 if (vma->vm_ops && vma->vm_ops->close)
454 vma->vm_ops->close(vma);
456 - fput(vma->vm_file);
460 /* Undo any partial mapping done by a device driver. */
461 @@ -2705,7 +2705,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
465 - get_file(new->vm_file);
468 if (new->vm_ops && new->vm_ops->open)
469 new->vm_ops->open(new);
470 @@ -2724,7 +2724,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
471 if (new->vm_ops && new->vm_ops->close)
472 new->vm_ops->close(new);
474 - fput(new->vm_file);
476 unlink_anon_vmas(new);
478 mpol_put(vma_policy(new));
479 @@ -2897,6 +2897,9 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
480 unsigned long populate = 0;
481 unsigned long ret = -EINVAL;
483 +#if IS_ENABLED(CONFIG_AUFS_FS)
484 + struct file *prfile;
487 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/mm/remap_file_pages.rst.\n",
488 current->comm, current->pid);
489 @@ -2952,10 +2955,34 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
490 if (vma->vm_flags & VM_LOCKED)
493 +#if IS_ENABLED(CONFIG_AUFS_FS)
495 + file = vma->vm_file;
496 + prfile = vma->vm_prfile;
497 + ret = do_mmap(vma->vm_file, start, size,
498 + prot, flags, pgoff, &populate, NULL);
499 + if (!IS_ERR_VALUE(ret) && file && prfile) {
500 + struct vm_area_struct *new_vma;
502 + new_vma = find_vma(mm, ret);
503 + if (!new_vma->vm_prfile)
504 + new_vma->vm_prfile = prfile;
505 + if (new_vma != vma)
509 + * two fput()s instead of vma_fput(vma),
510 + * coz vma may not be available anymore.
516 file = get_file(vma->vm_file);
517 ret = do_mmap(vma->vm_file, start, size,
518 prot, flags, pgoff, &populate, NULL);
520 +#endif /* CONFIG_AUFS_FS */
522 mmap_write_unlock(mm);
524 @@ -3229,7 +3256,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
525 if (anon_vma_clone(new_vma, vma))
526 goto out_free_mempol;
527 if (new_vma->vm_file)
528 - get_file(new_vma->vm_file);
529 + vma_get_file(new_vma);
530 if (new_vma->vm_ops && new_vma->vm_ops->open)
531 new_vma->vm_ops->open(new_vma);
532 vma_link(mm, new_vma, prev, rb_link, rb_parent);
533 diff --git a/mm/nommu.c b/mm/nommu.c
534 index e819cbc21b39..dc7d40fb197f 100644
537 @@ -524,7 +524,7 @@ static void __put_nommu_region(struct vm_region *region)
538 up_write(&nommu_region_sem);
541 - fput(region->vm_file);
544 /* IO memory and memory shared directly out of the pagecache
545 * from ramfs/tmpfs mustn't be released here */
546 @@ -656,7 +656,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
547 if (vma->vm_ops && vma->vm_ops->close)
548 vma->vm_ops->close(vma);
550 - fput(vma->vm_file);
552 put_nommu_region(vma->vm_region);
555 @@ -1176,7 +1176,7 @@ unsigned long do_mmap(struct file *file,
556 goto error_just_free;
559 - fput(region->vm_file);
561 kmem_cache_free(vm_region_jar, region);
564 @@ -1253,10 +1253,10 @@ unsigned long do_mmap(struct file *file,
565 up_write(&nommu_region_sem);
568 - fput(region->vm_file);
570 kmem_cache_free(vm_region_jar, region);
572 - fput(vma->vm_file);
577 diff --git a/mm/prfile.c b/mm/prfile.c
579 index 000000000000..8f820a235364
583 +// SPDX-License-Identifier: GPL-2.0
585 + * Mainly for aufs which mmap(2) different file and wants to print different
586 + * path in /proc/PID/maps.
587 + * Call these functions via macros defined in linux/mm.h.
589 + * See Documentation/filesystems/aufs/design/06mmap.txt
591 + * Copyright (c) 2014-2022 Junjro R. Okajima
592 + * Copyright (c) 2014 Ian Campbell
595 +#include <linux/mm.h>
596 +#include <linux/file.h>
597 +#include <linux/fs.h>
599 +/* #define PRFILE_TRACE */
600 +static inline void prfile_trace(struct file *f, struct file *pr,
601 + const char func[], int line, const char func2[])
605 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
609 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
612 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
614 + prfile_trace(f, pr, func, line, __func__);
615 + file_update_time(f);
617 + file_update_time(pr);
620 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
623 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
625 + prfile_trace(f, pr, func, line, __func__);
626 + return (f && pr) ? pr : f;
629 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
631 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
633 + prfile_trace(f, pr, func, line, __func__);
639 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
641 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
643 + prfile_trace(f, pr, func, line, __func__);
650 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
653 + struct file *f = region->vm_file, *pr = region->vm_prfile;
655 + prfile_trace(f, pr, func, line, __func__);
656 + return (f && pr) ? pr : f;
659 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
661 + struct file *f = region->vm_file, *pr = region->vm_prfile;
663 + prfile_trace(f, pr, func, line, __func__);
668 +#endif /* !CONFIG_MMU */
669 SPDX-License-Identifier: GPL-2.0
670 aufs6.0 standalone patch
672 diff --git a/fs/dcache.c b/fs/dcache.c
673 index d753ad7d77e6..1a3b40ebc12b 100644
676 @@ -1450,6 +1450,7 @@ void d_walk(struct dentry *parent, void *data,
680 +EXPORT_SYMBOL_GPL(d_walk);
683 struct vfsmount *mnt;
684 @@ -3061,6 +3062,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
686 write_sequnlock(&rename_lock);
688 +EXPORT_SYMBOL_GPL(d_exchange);
691 * d_ancestor - search for an ancestor
692 diff --git a/fs/exec.c b/fs/exec.c
693 index d046dbb9cbd0..5b9023e75de0 100644
696 @@ -111,6 +111,7 @@ bool path_noexec(const struct path *path)
697 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
698 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
700 +EXPORT_SYMBOL_GPL(path_noexec);
704 diff --git a/fs/fcntl.c b/fs/fcntl.c
705 index c980a0524118..40087d11a974 100644
708 @@ -86,6 +86,7 @@ int setfl(int fd, struct file *filp, unsigned long arg)
712 +EXPORT_SYMBOL_GPL(setfl);
714 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
716 diff --git a/fs/file_table.c b/fs/file_table.c
717 index 99c6796c9f28..ad533dcedfec 100644
718 --- a/fs/file_table.c
719 +++ b/fs/file_table.c
720 @@ -198,6 +198,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
722 return ERR_PTR(-ENFILE);
724 +EXPORT_SYMBOL_GPL(alloc_empty_file);
727 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
728 diff --git a/fs/namespace.c b/fs/namespace.c
729 index faae7f8644ac..0310c99a83dd 100644
732 @@ -456,6 +456,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
733 mnt_dec_writers(real_mount(mnt));
736 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
739 * mnt_drop_write - give up write access to a mount
740 @@ -857,6 +858,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
742 return check_mnt(real_mount(mnt));
744 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
747 * vfsmount lock must be held for write
748 @@ -2060,6 +2062,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
752 +EXPORT_SYMBOL_GPL(iterate_mounts);
754 static void lock_mnt_tree(struct mount *mnt)
756 diff --git a/fs/notify/group.c b/fs/notify/group.c
757 index 1de6631a3925..3008eb37a18d 100644
758 --- a/fs/notify/group.c
759 +++ b/fs/notify/group.c
760 @@ -100,6 +100,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
762 refcount_inc(&group->refcnt);
764 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
767 * Drop a reference to a group. Free it if it's through.
768 diff --git a/fs/open.c b/fs/open.c
769 index cf7e5c350a54..c99195ee46ba 100644
772 @@ -66,6 +66,7 @@ int do_truncate(struct user_namespace *mnt_userns, struct dentry *dentry,
773 inode_unlock(dentry->d_inode);
776 +EXPORT_SYMBOL_GPL(do_truncate);
778 long vfs_truncate(const struct path *path, loff_t length)
780 diff --git a/fs/read_write.c b/fs/read_write.c
781 index 328ce8cf9a85..59931848f794 100644
782 --- a/fs/read_write.c
783 +++ b/fs/read_write.c
784 @@ -477,6 +477,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
788 +EXPORT_SYMBOL_GPL(vfs_read);
790 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
792 @@ -592,6 +593,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
793 file_end_write(file);
796 +EXPORT_SYMBOL_GPL(vfs_write);
798 /* file_ppos returns &file->f_pos or NULL if file is stream */
799 static inline loff_t *file_ppos(struct file *file)
800 diff --git a/fs/splice.c b/fs/splice.c
801 index d83f9e5cddbc..ac355ebeb9f0 100644
804 @@ -763,6 +763,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
805 return warn_unsupported(out, "write");
806 return out->f_op->splice_write(pipe, out, ppos, len, flags);
808 +EXPORT_SYMBOL_GPL(do_splice_from);
811 * Attempt to initiate a splice from a file to a pipe.
812 @@ -792,6 +793,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
813 return warn_unsupported(in, "read");
814 return in->f_op->splice_read(in, ppos, pipe, len, flags);
816 +EXPORT_SYMBOL_GPL(do_splice_to);
819 * splice_direct_to_actor - splices data directly between two non-pipes
820 diff --git a/fs/xattr.c b/fs/xattr.c
821 index a1f4998bc6be..284d4ca54893 100644
824 @@ -396,6 +396,7 @@ vfs_getxattr_alloc(struct user_namespace *mnt_userns, struct dentry *dentry,
825 *xattr_value = value;
828 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
831 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
832 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
833 index c9f30e12aa32..d04fedf1e4d9 100644
834 --- a/kernel/locking/lockdep.c
835 +++ b/kernel/locking/lockdep.c
836 @@ -238,6 +238,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
838 return lock_classes + class_idx;
840 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
841 #define hlock_class(hlock) lockdep_hlock_class(hlock)
843 #ifdef CONFIG_LOCK_STAT
844 diff --git a/kernel/task_work.c b/kernel/task_work.c
845 index dff75bcde151..30b814618535 100644
846 --- a/kernel/task_work.c
847 +++ b/kernel/task_work.c
848 @@ -180,3 +180,4 @@ void task_work_run(void)
852 +EXPORT_SYMBOL_GPL(task_work_run);
853 diff --git a/security/security.c b/security/security.c
854 index 4b95de24bc8d..139e1443c49b 100644
855 --- a/security/security.c
856 +++ b/security/security.c
857 @@ -1165,6 +1165,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
859 return call_int_hook(path_rmdir, 0, dir, dentry);
861 +EXPORT_SYMBOL_GPL(security_path_rmdir);
863 int security_path_unlink(const struct path *dir, struct dentry *dentry)
865 @@ -1181,6 +1182,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
867 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
869 +EXPORT_SYMBOL_GPL(security_path_symlink);
871 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
872 struct dentry *new_dentry)
873 @@ -1189,6 +1191,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
875 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
877 +EXPORT_SYMBOL_GPL(security_path_link);
879 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
880 const struct path *new_dir, struct dentry *new_dentry,
881 @@ -1209,6 +1212,7 @@ int security_path_truncate(const struct path *path)
883 return call_int_hook(path_truncate, 0, path);
885 +EXPORT_SYMBOL_GPL(security_path_truncate);
887 int security_path_chmod(const struct path *path, umode_t mode)
889 @@ -1216,6 +1220,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
891 return call_int_hook(path_chmod, 0, path, mode);
893 +EXPORT_SYMBOL_GPL(security_path_chmod);
895 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
897 @@ -1223,6 +1228,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
899 return call_int_hook(path_chown, 0, path, uid, gid);
901 +EXPORT_SYMBOL_GPL(security_path_chown);
903 int security_path_chroot(const struct path *path)
905 @@ -1323,6 +1329,7 @@ int security_inode_permission(struct inode *inode, int mask)
907 return call_int_hook(inode_permission, 0, inode, mask);
909 +EXPORT_SYMBOL_GPL(security_inode_permission);
911 int security_inode_setattr(struct user_namespace *mnt_userns,
912 struct dentry *dentry, struct iattr *attr)
913 @@ -1521,6 +1528,7 @@ int security_file_permission(struct file *file, int mask)
915 return fsnotify_perm(file, mask);
917 +EXPORT_SYMBOL_GPL(security_file_permission);
919 int security_file_alloc(struct file *file)
921 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
922 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
923 +++ linux/Documentation/ABI/testing/debugfs-aufs 2022-11-05 23:02:18.955889283 +0100
925 +What: /debug/aufs/si_<id>/
927 +Contact: J. R. Okajima <hooanon05g@gmail.com>
929 + Under /debug/aufs, a directory named si_<id> is created
930 + per aufs mount, where <id> is a unique id generated
933 +What: /debug/aufs/si_<id>/plink
935 +Contact: J. R. Okajima <hooanon05g@gmail.com>
937 + It has three lines and shows the information about the
938 + pseudo-link. The first line is a single number
939 + representing a number of buckets. The second line is a
940 + number of pseudo-links per buckets (separated by a
941 + blank). The last line is a single number representing a
942 + total number of psedo-links.
943 + When the aufs mount option 'noplink' is specified, it
944 + will show "1\n0\n0\n".
946 +What: /debug/aufs/si_<id>/xib
948 +Contact: J. R. Okajima <hooanon05g@gmail.com>
950 + It shows the consumed blocks by xib (External Inode Number
951 + Bitmap), its block size and file size.
952 + When the aufs mount option 'noxino' is specified, it
953 + will be empty. About XINO files, see the aufs manual.
955 +What: /debug/aufs/si_<id>/xi<branch-index>
957 +Contact: J. R. Okajima <hooanon05g@gmail.com>
959 + It shows the consumed blocks by xino (External Inode Number
960 + Translation Table), its link count, block size and file
962 + Due to the file size limit, there may exist multiple
963 + xino files per branch. In this case, "-N" is added to
964 + the filename and it corresponds to the index of the
965 + internal xino array. "-0" is omitted.
966 + When the aufs mount option 'noxino' is specified, Those
967 + entries won't exist. About XINO files, see the aufs
970 +What: /debug/aufs/si_<id>/xigen
972 +Contact: J. R. Okajima <hooanon05g@gmail.com>
974 + It shows the consumed blocks by xigen (External Inode
975 + Generation Table), its block size and file size.
976 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
978 + When the aufs mount option 'noxino' is specified, it
979 + will be empty. About XINO files, see the aufs manual.
980 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
981 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
982 +++ linux/Documentation/ABI/testing/sysfs-aufs 2022-11-05 23:02:18.955889283 +0100
984 +What: /sys/fs/aufs/si_<id>/
986 +Contact: J. R. Okajima <hooanon05g@gmail.com>
988 + Under /sys/fs/aufs, a directory named si_<id> is created
989 + per aufs mount, where <id> is a unique id generated
992 +What: /sys/fs/aufs/si_<id>/br<idx>
994 +Contact: J. R. Okajima <hooanon05g@gmail.com>
996 + It shows the abolute path of a member directory (which
997 + is called branch) in aufs, and its permission.
999 +What: /sys/fs/aufs/si_<id>/brid<idx>
1001 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1003 + It shows the id of a member directory (which is called
1006 +What: /sys/fs/aufs/si_<id>/xi_path
1008 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1010 + It shows the abolute path of XINO (External Inode Number
1011 + Bitmap, Translation Table and Generation Table) file
1012 + even if it is the default path.
1013 + When the aufs mount option 'noxino' is specified, it
1014 + will be empty. About XINO files, see the aufs manual.
1015 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1016 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1017 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2022-11-05 23:02:18.955889283 +0100
1020 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1022 +# This program is free software; you can redistribute it and/or modify
1023 +# it under the terms of the GNU General Public License as published by
1024 +# the Free Software Foundation; either version 2 of the License, or
1025 +# (at your option) any later version.
1027 +# This program is distributed in the hope that it will be useful,
1028 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1029 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1030 +# GNU General Public License for more details.
1032 +# You should have received a copy of the GNU General Public License
1033 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1036 +----------------------------------------
1038 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1039 +1. abbrev. for "advanced multi-layered unification filesystem".
1040 +2. abbrev. for "another unionfs".
1041 +3. abbrev. for "auf das" in German which means "on the" in English.
1042 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1043 + But "Filesystem aufs Filesystem" is hard to understand.
1044 +4. abbrev. for "African Urban Fashion Show".
1046 +AUFS is a filesystem with features:
1047 +- multi layered stackable unification filesystem, the member directory
1048 + is called as a branch.
1049 +- branch permission and attribute, 'readonly', 'real-readonly',
1050 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1052 +- internal "file copy-on-write".
1053 +- logical deletion, whiteout.
1054 +- dynamic branch manipulation, adding, deleting and changing permission.
1055 +- allow bypassing aufs, user's direct branch access.
1056 +- external inode number translation table and bitmap which maintains the
1057 + persistent aufs inode number.
1058 +- seekable directory, including NFS readdir.
1059 +- file mapping, mmap and sharing pages.
1060 +- pseudo-link, hardlink over branches.
1061 +- loopback mounted filesystem as a branch.
1062 +- several policies to select one among multiple writable branches.
1063 +- revert a single systemcall when an error occurs in aufs.
1067 +Multi Layered Stackable Unification Filesystem
1068 +----------------------------------------------------------------------
1069 +Most people already knows what it is.
1070 +It is a filesystem which unifies several directories and provides a
1071 +merged single directory. When users access a file, the access will be
1072 +passed/re-directed/converted (sorry, I am not sure which English word is
1073 +correct) to the real file on the member filesystem. The member
1074 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1075 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1076 +readonly branch is handled by creating 'whiteout' on the upper writable
1079 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1080 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1081 +different approaches to implement the merged-view.
1082 +The former tries putting it into VFS, and the latter implements as a
1083 +separate filesystem.
1084 +(If I misunderstand about these implementations, please let me know and
1085 +I shall correct it. Because it is a long time ago when I read their
1086 +source files last time).
1088 +UnionMount's approach will be able to small, but may be hard to share
1089 +branches between several UnionMount since the whiteout in it is
1090 +implemented in the inode on branch filesystem and always
1091 +shared. According to Bharata's post, readdir does not seems to be
1093 +There are several missing features known in this implementations such as
1094 +- for users, the inode number may change silently. eg. copy-up.
1095 +- link(2) may break by copy-up.
1096 +- read(2) may get an obsoleted filedata (fstat(2) too).
1097 +- fcntl(F_SETLK) may be broken by copy-up.
1098 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1101 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1102 +merged into mainline. This is another implementation of UnionMount as a
1103 +separated filesystem. All the limitations and known problems which
1104 +UnionMount are equally inherited to "overlay" filesystem.
1106 +Unionfs has a longer history. When I started implementing a stackable
1107 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1108 +inode, dentry and file objects and they have an array pointing lower
1109 +same kind objects. After contributing many patches for Unionfs, I
1110 +re-started my project AUFS (Jun 2006).
1112 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1113 +implemented my own ideas, approaches and enhancements and it became
1114 +totally different one.
1116 +Comparing DM snapshot and fs based implementation
1117 +- the number of bytes to be copied between devices is much smaller.
1118 +- the type of filesystem must be one and only.
1119 +- the fs must be writable, no readonly fs, even for the lower original
1120 + device. so the compression fs will not be usable. but if we use
1121 + loopback mount, we may address this issue.
1123 + mount /cdrom/squashfs.img /sq
1124 + losetup /sq/ext2.img
1125 + losetup /somewhere/cow
1126 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1127 +- it will be difficult (or needs more operations) to extract the
1128 + difference between the original device and COW.
1129 +- DM snapshot-merge may help a lot when users try merging. in the
1130 + fs-layer union, users will use rsync(1).
1132 +You may want to read my old paper "Filesystems in LiveCD"
1133 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1136 +Several characters/aspects/persona of aufs
1137 +----------------------------------------------------------------------
1139 +Aufs has several characters, aspects or persona.
1140 +1. a filesystem, callee of VFS helper
1141 +2. sub-VFS, caller of VFS helper for branches
1142 +3. a virtual filesystem which maintains persistent inode number
1143 +4. reader/writer of files on branches such like an application
1145 +1. Callee of VFS Helper
1146 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1147 +unlink(2) from an application reaches sys_unlink() kernel function and
1148 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1149 +calls filesystem specific unlink operation. Actually aufs implements the
1150 +unlink operation but it behaves like a redirector.
1152 +2. Caller of VFS Helper for Branches
1153 +aufs_unlink() passes the unlink request to the branch filesystem as if
1154 +it were called from VFS. So the called unlink operation of the branch
1155 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1156 +every necessary pre/post operation for the branch filesystem.
1157 +- acquire the lock for the parent dir on a branch
1158 +- lookup in a branch
1159 +- revalidate dentry on a branch
1160 +- mnt_want_write() for a branch
1161 +- vfs_unlink() for a branch
1162 +- mnt_drop_write() for a branch
1163 +- release the lock on a branch
1165 +3. Persistent Inode Number
1166 +One of the most important issue for a filesystem is to maintain inode
1167 +numbers. This is particularly important to support exporting a
1168 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1169 +backend block device for its own. But some storage is necessary to
1170 +keep and maintain the inode numbers. It may be a large space and may not
1171 +suit to keep in memory. Aufs rents some space from its first writable
1172 +branch filesystem (by default) and creates file(s) on it. These files
1173 +are created by aufs internally and removed soon (currently) keeping
1175 +Note: Because these files are removed, they are totally gone after
1176 + unmounting aufs. It means the inode numbers are not persistent
1177 + across unmount or reboot. I have a plan to make them really
1178 + persistent which will be important for aufs on NFS server.
1180 +4. Read/Write Files Internally (copy-on-write)
1181 +Because a branch can be readonly, when you write a file on it, aufs will
1182 +"copy-up" it to the upper writable branch internally. And then write the
1183 +originally requested thing to the file. Generally kernel doesn't
1184 +open/read/write file actively. In aufs, even a single write may cause a
1185 +internal "file copy". This behaviour is very similar to cp(1) command.
1187 +Some people may think it is better to pass such work to user space
1188 +helper, instead of doing in kernel space. Actually I am still thinking
1189 +about it. But currently I have implemented it in kernel space.
1190 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1191 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1192 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2022-11-05 23:02:18.955889283 +0100
1195 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1197 +# This program is free software; you can redistribute it and/or modify
1198 +# it under the terms of the GNU General Public License as published by
1199 +# the Free Software Foundation; either version 2 of the License, or
1200 +# (at your option) any later version.
1202 +# This program is distributed in the hope that it will be useful,
1203 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1204 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1205 +# GNU General Public License for more details.
1207 +# You should have received a copy of the GNU General Public License
1208 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1210 +Basic Aufs Internal Structure
1212 +Superblock/Inode/Dentry/File Objects
1213 +----------------------------------------------------------------------
1214 +As like an ordinary filesystem, aufs has its own
1215 +superblock/inode/dentry/file objects. All these objects have a
1216 +dynamically allocated array and store the same kind of pointers to the
1217 +lower filesystem, branch.
1218 +For example, when you build a union with one readwrite branch and one
1219 +readonly, mounted /au, /rw and /ro respectively.
1221 +- /ro/fileA exists but /rw/fileA
1223 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1224 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1225 +- [0] = NULL (because /rw/fileA doesn't exist)
1228 +This style of an array is essentially same to the aufs
1229 +superblock/inode/dentry/file objects.
1231 +Because aufs supports manipulating branches, ie. add/delete/change
1232 +branches dynamically, these objects has its own generation. When
1233 +branches are changed, the generation in aufs superblock is
1234 +incremented. And a generation in other object are compared when it is
1235 +accessed. When a generation in other objects are obsoleted, aufs
1236 +refreshes the internal array.
1240 +----------------------------------------------------------------------
1241 +Additionally aufs superblock has some data for policies to select one
1242 +among multiple writable branches, XIB files, pseudo-links and kobject.
1243 +See below in detail.
1244 +About the policies which supports copy-down a directory, see
1245 +wbr_policy.txt too.
1248 +Branch and XINO(External Inode Number Translation Table)
1249 +----------------------------------------------------------------------
1250 +Every branch has its own xino (external inode number translation table)
1251 +file. The xino file is created and unlinked by aufs internally. When two
1252 +members of a union exist on the same filesystem, they share the single
1254 +The struct of a xino file is simple, just a sequence of aufs inode
1255 +numbers which is indexed by the lower inode number.
1256 +In the above sample, assume the inode number of /ro/fileA is i111 and
1257 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1258 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1260 +When the inode numbers are not contiguous, the xino file will be sparse
1261 +which has a hole in it and doesn't consume as much disk space as it
1262 +might appear. If your branch filesystem consumes disk space for such
1263 +holes, then you should specify 'xino=' option at mounting aufs.
1265 +Aufs has a mount option to free the disk blocks for such holes in XINO
1266 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1267 +meet a problem of disk shortage due to XINO files, then you should try
1268 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1269 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1270 +the holes in XINO files.
1272 +Also a writable branch has three kinds of "whiteout bases". All these
1273 +are existed when the branch is joined to aufs, and their names are
1274 +whiteout-ed doubly, so that users will never see their names in aufs
1276 +1. a regular file which will be hardlinked to all whiteouts.
1277 +2. a directory to store a pseudo-link.
1278 +3. a directory to store an "orphan"-ed file temporary.
1281 + When you remove a file on a readonly branch, aufs handles it as a
1282 + logical deletion and creates a whiteout on the upper writable branch
1283 + as a hardlink of this file in order not to consume inode on the
1286 + See below, Pseudo-link.
1288 + When "fileC" exists on the lower readonly branch only and it is
1289 + opened and removed with its parent dir, and then user writes
1290 + something into it, then aufs copies-up fileC to this
1291 + directory. Because there is no other dir to store fileC. After
1292 + creating a file under this dir, the file is unlinked.
1294 +Because aufs supports manipulating branches, ie. add/delete/change
1295 +dynamically, a branch has its own id. When the branch order changes,
1296 +aufs finds the new index by searching the branch id.
1300 +----------------------------------------------------------------------
1301 +Assume "fileA" exists on the lower readonly branch only and it is
1302 +hardlinked to "fileB" on the branch. When you write something to fileA,
1303 +aufs copies-up it to the upper writable branch. Additionally aufs
1304 +creates a hardlink under the Pseudo-link Directory of the writable
1305 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1306 +simple list. If fileB is read after unlinking fileA, aufs returns
1307 +filedata from the pseudo-link instead of the lower readonly
1308 +branch. Because the pseudo-link is based upon the inode, to keep the
1309 +inode number by xino (see above) is essentially necessary.
1311 +All the hardlinks under the Pseudo-link Directory of the writable branch
1312 +should be restored in a proper location later. Aufs provides a utility
1313 +to do this. The userspace helpers executed at remounting and unmounting
1315 +During this utility is running, it puts aufs into the pseudo-link
1316 +maintenance mode. In this mode, only the process which began the
1317 +maintenance mode (and its child processes) is allowed to operate in
1318 +aufs. Some other processes which are not related to the pseudo-link will
1319 +be allowed to run too, but the rest have to return an error or wait
1320 +until the maintenance mode ends. If a process already acquires an inode
1321 +mutex (in VFS), it has to return an error.
1324 +XIB(external inode number bitmap)
1325 +----------------------------------------------------------------------
1326 +Addition to the xino file per a branch, aufs has an external inode number
1327 +bitmap in a superblock object. It is also an internal file such like a
1329 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1331 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1333 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1334 +reduce the number of consumed disk blocks for these files.
1337 +Virtual or Vertical Dir, and Readdir in Userspace
1338 +----------------------------------------------------------------------
1339 +In order to support multiple layers (branches), aufs readdir operation
1340 +constructs a virtual dir block on memory. For readdir, aufs calls
1341 +vfs_readdir() internally for each dir on branches, merges their entries
1342 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1343 +object. So the file object has its entry list until it is closed. The
1344 +entry list will be updated when the file position is zero and becomes
1345 +obsoleted. This decision is made in aufs automatically.
1347 +The dynamically allocated memory block for the name of entries has a
1348 +unit of 512 bytes (by default) and stores the names contiguously (no
1349 +padding). Another block for each entry is handled by kmem_cache too.
1350 +During building dir blocks, aufs creates hash list and judging whether
1351 +the entry is whiteouted by its upper branch or already listed.
1352 +The merged result is cached in the corresponding inode object and
1353 +maintained by a customizable life-time option.
1355 +Some people may call it can be a security hole or invite DoS attack
1356 +since the opened and once readdir-ed dir (file object) holds its entry
1357 +list and becomes a pressure for system memory. But I'd say it is similar
1358 +to files under /proc or /sys. The virtual files in them also holds a
1359 +memory page (generally) while they are opened. When an idea to reduce
1360 +memory for them is introduced, it will be applied to aufs too.
1361 +For those who really hate this situation, I've developed readdir(3)
1362 +library which operates this merging in userspace. You just need to set
1363 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1364 +kernel space for readdir(3).
1368 +----------------------------------------------------------------------
1369 +Aufs sometimes requires privilege access to a branch. For instance,
1370 +in copy-up/down operation. When a user process is going to make changes
1371 +to a file which exists in the lower readonly branch only, and the mode
1372 +of one of ancestor directories may not be writable by a user
1373 +process. Here aufs copy-up the file with its ancestors and they may
1374 +require privilege to set its owner/group/mode/etc.
1375 +This is a typical case of a application character of aufs (see
1378 +Aufs uses workqueue synchronously for this case. It creates its own
1379 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1380 +passes the request to call mkdir or write (for example), and wait for
1381 +its completion. This approach solves a problem of a signal handler
1383 +If aufs didn't adopt the workqueue and changed the privilege of the
1384 +process, then the process may receive the unexpected SIGXFSZ or other
1387 +Also aufs uses the system global workqueue ("events" kernel thread) too
1388 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1389 +whiteout base and etc. This is unrelated to a privilege.
1390 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1391 +superblock at the beginning, at the same time waits for the completion
1392 +of all queued asynchronous tasks.
1396 +----------------------------------------------------------------------
1397 +The whiteout in aufs is very similar to Unionfs's. That is represented
1398 +by its filename. UnionMount takes an approach of a file mode, but I am
1399 +afraid several utilities (find(1) or something) will have to support it.
1401 +Basically the whiteout represents "logical deletion" which stops aufs to
1402 +lookup further, but also it represents "dir is opaque" which also stop
1405 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1406 +In order to make several functions in a single systemcall to be
1407 +revertible, aufs adopts an approach to rename a directory to a temporary
1408 +unique whiteouted name.
1409 +For example, in rename(2) dir where the target dir already existed, aufs
1410 +renames the target dir to a temporary unique whiteouted name before the
1411 +actual rename on a branch, and then handles other actions (make it opaque,
1412 +update the attributes, etc). If an error happens in these actions, aufs
1413 +simply renames the whiteouted name back and returns an error. If all are
1414 +succeeded, aufs registers a function to remove the whiteouted unique
1415 +temporary name completely and asynchronously to the system global
1420 +----------------------------------------------------------------------
1421 +It is a well-known feature or concept.
1422 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1423 +internally and makes change to the new file on the upper writable branch.
1424 +When the trigger systemcall does not update the timestamps of the parent
1425 +dir, aufs reverts it after copy-up.
1428 +Move-down (aufs3.9 and later)
1429 +----------------------------------------------------------------------
1430 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1431 +the lower readonly branch to the upper writable branch when a user
1432 +changes something about the file.
1433 +"Move-down" is an opposite action of copy-up. Basically this action is
1434 +ran manually instead of automatically and internally.
1435 +For desgin and implementation, aufs has to consider these issues.
1436 +- whiteout for the file may exist on the lower branch.
1437 +- ancestor directories may not exist on the lower branch.
1438 +- diropq for the ancestor directories may exist on the upper branch.
1439 +- free space on the lower branch will reduce.
1440 +- another access to the file may happen during moving-down, including
1441 + UDBA (see "Revalidate Dentry and UDBA").
1442 +- the file should not be hard-linked nor pseudo-linked. they should be
1443 + handled by auplink utility later.
1445 +Sometimes users want to move-down a file from the upper writable branch
1446 +to the lower readonly or writable branch. For instance,
1447 +- the free space of the upper writable branch is going to run out.
1448 +- create a new intermediate branch between the upper and lower branch.
1451 +For this purpose, use "aumvdown" command in aufs-util.git.
1452 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1453 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1454 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2022-11-05 23:02:18.955889283 +0100
1457 +# Copyright (C) 2015-2022 Junjiro R. Okajima
1459 +# This program is free software; you can redistribute it and/or modify
1460 +# it under the terms of the GNU General Public License as published by
1461 +# the Free Software Foundation; either version 2 of the License, or
1462 +# (at your option) any later version.
1464 +# This program is distributed in the hope that it will be useful,
1465 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1466 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1467 +# GNU General Public License for more details.
1469 +# You should have received a copy of the GNU General Public License
1470 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1472 +Support for a branch who has its ->atomic_open()
1473 +----------------------------------------------------------------------
1474 +The filesystems who implement its ->atomic_open() are not majority. For
1475 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1476 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1477 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1478 +sure whether all filesystems who have ->atomic_open() behave like this,
1479 +but NFSv4 surely returns the error.
1481 +In order to support ->atomic_open() for aufs, there are a few
1484 +A. Introduce aufs_atomic_open()
1485 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1487 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1488 + an aufs user Pip Cet's approach
1489 + - calls aufs_create(), VFS finish_open() and notify_change().
1490 + - pass fake-mode to finish_open(), and then correct the mode by
1492 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1493 + - no aufs_atomic_open().
1494 + - aufs_lookup() registers the TID to an aufs internal object.
1495 + - aufs_create() does nothing when the matching TID is registered, but
1496 + registers the mode.
1497 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1498 + TID is registered.
1499 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1501 + - no aufs_atomic_open().
1502 + - aufs_create() registers the TID to an internal object. this info
1503 + represents "this process created this file just now."
1504 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1505 + registered TID and re-try open() with superuser's credential.
1507 +Pros and cons for each approach.
1510 + - straightforward but highly depends upon VFS internal.
1511 + - the atomic behavaiour is kept.
1512 + - some of parameters such as nameidata are hard to reproduce for
1516 + - easy to implement.
1517 + - the atomic behavaiour is lost.
1519 + - the atomic behavaiour is kept.
1520 + - dirty and tricky.
1521 + - VFS checks whether the file is created correctly after calling
1522 + ->create(), which means this approach doesn't work.
1524 + - easy to implement.
1525 + - the atomic behavaiour is lost.
1526 + - to open a file with superuser's credential and give it to a user
1527 + process is a bad idea, since the file object keeps the credential
1528 + in it. It may affect LSM or something. This approach doesn't work
1531 +The approach A is ideal, but it hard to implement. So here is a
1532 +variation of A, which is to be implemented.
1534 +A-1. Introduce aufs_atomic_open()
1535 + - calls branch fs ->atomic_open() if exists. otherwise calls
1536 + vfs_create() and finish_open().
1537 + - the demerit is that the several checks after branch fs
1538 + ->atomic_open() are lost. in the ordinary case, the checks are
1539 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1540 + be implemented in aufs, but not all I am afraid.
1541 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1542 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1543 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2022-11-05 23:02:18.959222617 +0100
1546 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1548 +# This program is free software; you can redistribute it and/or modify
1549 +# it under the terms of the GNU General Public License as published by
1550 +# the Free Software Foundation; either version 2 of the License, or
1551 +# (at your option) any later version.
1553 +# This program is distributed in the hope that it will be useful,
1554 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1555 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1556 +# GNU General Public License for more details.
1558 +# You should have received a copy of the GNU General Public License
1559 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1562 +----------------------------------------------------------------------
1563 +Since aufs has a character of sub-VFS (see Introduction), it operates
1564 +lookup for branches as VFS does. It may be a heavy work. But almost all
1565 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1566 +directly connected to its parent. Digging down the directory hierarchy
1567 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1570 +When a branch is a remote filesystem, aufs basically relies upon its
1571 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1573 +For d_revalidate, aufs implements three levels of revalidate tests. See
1574 +"Revalidate Dentry and UDBA" in detail.
1577 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1578 +----------------------------------------------------------------------
1579 +Let's try case study.
1580 +- aufs has two branches, upper readwrite and lower readonly.
1582 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1583 +- user invoked "chmod a+rx /au/dirA"
1584 +- the internal copy-up is activated and "/rw/dirA" is created and its
1585 + permission bits are set to world readable.
1586 +- then "/au/dirA" becomes world readable?
1588 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1589 +or it may be a natively readonly filesystem. If aufs respects the lower
1590 +branch, it should not respond readdir request from other users. But user
1591 +allowed it by chmod. Should really aufs rejects showing the entries
1594 +To be honest, I don't have a good solution for this case. So aufs
1595 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1597 +When dirperm1 is specified, aufs checks only the highest one for the
1598 +directory permission, and shows the entries. Otherwise, as usual, checks
1599 +every dir existing on all branches and rejects the request.
1601 +As a side effect, dirperm1 option improves the performance of aufs
1602 +because the number of permission check is reduced when the number of
1606 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1607 +----------------------------------------------------------------------
1608 +Generally VFS helpers re-validate a dentry as a part of lookup.
1609 +0. digging down the directory hierarchy.
1610 +1. lock the parent dir by its i_mutex.
1611 +2. lookup the final (child) entry.
1613 +4. call the actual operation (create, unlink, etc.)
1614 +5. unlock the parent dir
1616 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1617 +called. Actually aufs implements it and checks the dentry on a branch is
1619 +But it is not enough. Because aufs has to release the lock for the
1620 +parent dir on a branch at the end of ->lookup() (step 2) and
1621 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1623 +If the file on a branch is changed directly, eg. bypassing aufs, after
1624 +aufs released the lock, then the subsequent operation may cause
1625 +something unpleasant result.
1627 +This situation is a result of VFS architecture, ->lookup() and
1628 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1629 +design from VFS's point of view. It is just not suitable for sub-VFS
1632 +Aufs supports such case by three level of revalidation which is
1633 +selectable by user.
1634 +1. Simple Revalidate
1635 + Addition to the native flow in VFS's, confirm the child-parent
1636 + relationship on the branch just after locking the parent dir on the
1637 + branch in the "actual operation" (step 4). When this validation
1638 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1639 + checks the validation of the dentry on branches.
1640 +2. Monitor Changes Internally by Inotify/Fsnotify
1641 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1642 + the dentry on the branch, and returns EBUSY if it finds different
1644 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1645 + during it is in cache. When the event is notified, aufs registers a
1646 + function to kernel 'events' thread by schedule_work(). And the
1647 + function sets some special status to the cached aufs dentry and inode
1648 + private data. If they are not cached, then aufs has nothing to
1649 + do. When the same file is accessed through aufs (step 0-3) later,
1650 + aufs will detect the status and refresh all necessary data.
1651 + In this mode, aufs has to ignore the event which is fired by aufs
1653 +3. No Extra Validation
1654 + This is the simplest test and doesn't add any additional revalidation
1655 + test, and skip the revalidation in step 4. It is useful and improves
1656 + aufs performance when system surely hide the aufs branches from user,
1657 + by over-mounting something (or another method).
1658 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1659 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1660 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2022-11-05 23:02:18.959222617 +0100
1663 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1665 +# This program is free software; you can redistribute it and/or modify
1666 +# it under the terms of the GNU General Public License as published by
1667 +# the Free Software Foundation; either version 2 of the License, or
1668 +# (at your option) any later version.
1670 +# This program is distributed in the hope that it will be useful,
1671 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1672 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1673 +# GNU General Public License for more details.
1675 +# You should have received a copy of the GNU General Public License
1676 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1678 +Branch Manipulation
1680 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1681 +and changing its permission/attribute, there are a lot of works to do.
1685 +----------------------------------------------------------------------
1686 +o Confirm the adding dir exists outside of aufs, including loopback
1687 + mount, and its various attributes.
1688 +o Initialize the xino file and whiteout bases if necessary.
1691 +o Check the owner/group/mode of the directory
1692 + When the owner/group/mode of the adding directory differs from the
1693 + existing branch, aufs issues a warning because it may impose a
1695 + For example, when a upper writable branch has a world writable empty
1696 + top directory, a malicious user can create any files on the writable
1697 + branch directly, like copy-up and modify manually. If something like
1698 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1699 + writable branch, and the writable branch is world-writable, then a
1700 + malicious guy may create /etc/passwd on the writable branch directly
1701 + and the infected file will be valid in aufs.
1702 + I am afraid it can be a security issue, but aufs can do nothing except
1703 + producing a warning.
1707 +----------------------------------------------------------------------
1708 +o Confirm the deleting branch is not busy
1709 + To be general, there is one merit to adopt "remount" interface to
1710 + manipulate branches. It is to discard caches. At deleting a branch,
1711 + aufs checks the still cached (and connected) dentries and inodes. If
1712 + there are any, then they are all in-use. An inode without its
1713 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1715 + For the cached one, aufs checks whether the same named entry exists on
1717 + If the cached one is a directory, because aufs provides a merged view
1718 + to users, as long as one dir is left on any branch aufs can show the
1719 + dir to users. In this case, the branch can be removed from aufs.
1720 + Otherwise aufs rejects deleting the branch.
1722 + If any file on the deleting branch is opened by aufs, then aufs
1726 +Modify the Permission of a Branch
1727 +----------------------------------------------------------------------
1728 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1731 +o rw --> ro: Confirm the modifying branch is not busy
1732 + Aufs rejects the request if any of these conditions are true.
1733 + - a file on the branch is mmap-ed.
1734 + - a regular file on the branch is opened for write and there is no
1735 + same named entry on the upper branch.
1736 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1737 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1738 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2022-11-05 23:02:18.959222617 +0100
1741 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1743 +# This program is free software; you can redistribute it and/or modify
1744 +# it under the terms of the GNU General Public License as published by
1745 +# the Free Software Foundation; either version 2 of the License, or
1746 +# (at your option) any later version.
1748 +# This program is distributed in the hope that it will be useful,
1749 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1750 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1751 +# GNU General Public License for more details.
1753 +# You should have received a copy of the GNU General Public License
1754 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1756 +Policies to Select One among Multiple Writable Branches
1757 +----------------------------------------------------------------------
1758 +When the number of writable branch is more than one, aufs has to decide
1759 +the target branch for file creation or copy-up. By default, the highest
1760 +writable branch which has the parent (or ancestor) dir of the target
1761 +file is chosen (top-down-parent policy).
1762 +By user's request, aufs implements some other policies to select the
1763 +writable branch, for file creation several policies, round-robin,
1764 +most-free-space, and other policies. For copy-up, top-down-parent,
1765 +bottom-up-parent, bottom-up and others.
1767 +As expected, the round-robin policy selects the branch in circular. When
1768 +you have two writable branches and creates 10 new files, 5 files will be
1769 +created for each branch. mkdir(2) systemcall is an exception. When you
1770 +create 10 new directories, all will be created on the same branch.
1771 +And the most-free-space policy selects the one which has most free
1772 +space among the writable branches. The amount of free space will be
1773 +checked by aufs internally, and users can specify its time interval.
1775 +The policies for copy-up is more simple,
1776 +top-down-parent is equivalent to the same named on in create policy,
1777 +bottom-up-parent selects the writable branch where the parent dir
1778 +exists and the nearest upper one from the copyup-source,
1779 +bottom-up selects the nearest upper writable branch from the
1780 +copyup-source, regardless the existence of the parent dir.
1782 +There are some rules or exceptions to apply these policies.
1783 +- If there is a readonly branch above the policy-selected branch and
1784 + the parent dir is marked as opaque (a variation of whiteout), or the
1785 + target (creating) file is whiteout-ed on the upper readonly branch,
1786 + then the result of the policy is ignored and the target file will be
1787 + created on the nearest upper writable branch than the readonly branch.
1788 +- If there is a writable branch above the policy-selected branch and
1789 + the parent dir is marked as opaque or the target file is whiteouted
1790 + on the branch, then the result of the policy is ignored and the target
1791 + file will be created on the highest one among the upper writable
1792 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1794 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1795 + They try selecting the branch where the source exists as possible
1796 + since copyup a large file will take long time. If it can't be,
1797 + ie. the branch where the source exists is readonly, then they will
1798 + follow the copyup policy.
1799 +- There is an exception for rename(2) when the target exists.
1800 + If the rename target exists, aufs compares the index of the branches
1801 + where the source and the target exists and selects the higher
1802 + one. If the selected branch is readonly, then aufs follows the
1804 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1805 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1806 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2022-11-05 23:02:18.959222617 +0100
1809 +// to view this graph, run dot(1) command in GRAPHVIZ.
1811 +// This program is free software; you can redistribute it and/or modify
1812 +// it under the terms of the GNU General Public License as published by
1813 +// the Free Software Foundation; either version 2 of the License, or
1814 +// (at your option) any later version.
1816 +// This program is distributed in the hope that it will be useful,
1817 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
1818 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1819 +// GNU General Public License for more details.
1821 +// You should have received a copy of the GNU General Public License
1822 +// along with this program. If not, see <http://www.gnu.org/licenses/>.
1826 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1830 +aufs_rename -> whinfo [label="store/remove"];
1833 +inode_list [label="h_inum list in branch\ncache"];
1836 +whinode [label="h_inum list file"];
1839 +brmgmt [label="br_add/del/mod/umount"];
1841 +brmgmt -> inode_list [label="create/remove"];
1842 +brmgmt -> whinode [label="load/store"];
1844 +inode_list -> whinode [style=dashed,dir=both];
1846 +aufs_rename -> inode_list [label="add/del"];
1848 +aufs_lookup -> inode_list [label="search"];
1850 +aufs_lookup -> whinfo [label="load/remove"];
1852 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1853 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1854 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2022-11-05 23:02:18.959222617 +0100
1857 +# Copyright (C) 2017-2022 Junjiro R. Okajima
1859 +# This program is free software; you can redistribute it and/or modify
1860 +# it under the terms of the GNU General Public License as published by
1861 +# the Free Software Foundation; either version 2 of the License, or
1862 +# (at your option) any later version.
1864 +# This program is distributed in the hope that it will be useful,
1865 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1866 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1867 +# GNU General Public License for more details.
1869 +# You should have received a copy of the GNU General Public License
1870 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1872 +Special handling for renaming a directory (DIRREN)
1873 +----------------------------------------------------------------------
1874 +First, let's assume we have a simple usecase.
1878 +- /ro/dirA and /ro/dirA/file exist too
1879 +- there is no dirB on both branches
1880 +- a user issues rename("dirA", "dirB")
1882 +Now, what should aufs behave against this rename(2)?
1883 +There are a few possible cases.
1886 + since dirA exists on a readonly branch which cannot be renamed.
1888 + it is possible to copy-up dirA (only the dir itself), but the child
1889 + entries ("file" in this case) should not be. it must be a bad
1890 + approach to copy-up recursively.
1891 +C. returns a success.
1892 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
1893 + is a violation of aufs' policy.
1894 +D. construct an extra information which indicates that /ro/dirA should
1895 + be handled as the name of dirB.
1896 + overlayfs has a similar feature called REDIRECT.
1898 +Until now, aufs implements the case B only which returns EXDEV, and
1899 +expects the userspace application behaves like mv(1) which tries
1900 +issueing rename(2) recursively.
1902 +A new aufs feature called DIRREN is introduced which implements the case
1903 +D. There are several "extra information" added.
1905 +1. detailed info per renamed directory
1906 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
1907 +2. the inode-number list of directories on a branch
1908 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
1910 +The filename of "detailed info per directory" represents the lower
1911 +branch, and its format is
1912 +- a type of the branch id
1914 + + uuid (not implemented yet)
1917 +- the inode-number of the branch root dir
1919 +And it contains these info in a single regular file.
1921 +- branch's inode-number of the logically renamed dir
1922 +- the name of the before-renamed dir
1924 +The "detailed info per directory" file is created in aufs rename(2), and
1925 +loaded in any lookup.
1926 +The info is considered in lookup for the matching case only. Here
1927 +"matching" means that the root of branch (in the info filename) is same
1928 +to the current looking-up branch. After looking-up the before-renamed
1929 +name, the inode-number is compared. And the matched dentry is used.
1931 +The "inode-number list of directories" is a regular file which contains
1932 +simply the inode-numbers on the branch. The file is created or updated
1933 +in removing the branch, and loaded in adding the branch. Its lifetime is
1934 +equal to the branch.
1935 +The list is referred in lookup, and when the current target inode is
1936 +found in the list, the aufs tries loading the "detailed info per
1937 +directory" and get the changed and valid name of the dir.
1939 +Theoretically these "extra informaiton" may be able to be put into XATTR
1940 +in the dir inode. But aufs doesn't choose this way because
1941 +1. XATTR may not be supported by the branch (or its configuration)
1942 +2. XATTR may have its size limit.
1943 +3. XATTR may be less easy to convert than a regular file, when the
1944 + format of the info is changed in the future.
1945 +At the same time, I agree that the regular file approach is much slower
1946 +than XATTR approach. So, in the future, aufs may take the XATTR or other
1949 +This DIRREN feature is enabled by aufs configuration, and is activated
1950 +by a new mount option.
1952 +For the more complicated case, there is a work with UDBA option, which
1953 +is to dected the direct access to the branches (by-passing aufs) and to
1954 +maintain the cashes in aufs. Since a single cached aufs dentry may
1955 +contains two names, before- and after-rename, the name comparision in
1956 +UDBA handler may not work correctly. In this case, the behaviour will be
1957 +equivalen to udba=reval case.
1958 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1959 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1960 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2022-11-05 23:02:18.959222617 +0100
1963 +# Copyright (C) 2011-2022 Junjiro R. Okajima
1965 +# This program is free software; you can redistribute it and/or modify
1966 +# it under the terms of the GNU General Public License as published by
1967 +# the Free Software Foundation; either version 2 of the License, or
1968 +# (at your option) any later version.
1970 +# This program is distributed in the hope that it will be useful,
1971 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1972 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1973 +# GNU General Public License for more details.
1975 +# You should have received a copy of the GNU General Public License
1976 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1978 +File-based Hierarchical Storage Management (FHSM)
1979 +----------------------------------------------------------------------
1980 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1981 +storage world. Aufs provides this feature as file-based with multiple
1982 +writable branches, based upon the principle of "Colder, the Lower".
1983 +Here the word "colder" means that the less used files, and "lower" means
1984 +that the position in the order of the stacked branches vertically.
1985 +These multiple writable branches are prioritized, ie. the topmost one
1986 +should be the fastest drive and be used heavily.
1988 +o Characters in aufs FHSM story
1989 +- aufs itself and a new branch attribute.
1990 +- a new ioctl interface to move-down and to establish a connection with
1991 + the daemon ("move-down" is a converse of "copy-up").
1992 +- userspace tool and daemon.
1994 +The userspace daemon establishes a connection with aufs and waits for
1995 +the notification. The notified information is very similar to struct
1996 +statfs containing the number of consumed blocks and inodes.
1997 +When the consumed blocks/inodes of a branch exceeds the user-specified
1998 +upper watermark, the daemon activates its move-down process until the
1999 +consumed blocks/inodes reaches the user-specified lower watermark.
2001 +The actual move-down is done by aufs based upon the request from
2002 +user-space since we need to maintain the inode number and the internal
2003 +pointer arrays in aufs.
2005 +Currently aufs FHSM handles the regular files only. Additionally they
2006 +must not be hard-linked nor pseudo-linked.
2009 +o Cowork of aufs and the user-space daemon
2010 + During the userspace daemon established the connection, aufs sends a
2011 + small notification to it whenever aufs writes something into the
2012 + writable branch. But it may cost high since aufs issues statfs(2)
2013 + internally. So user can specify a new option to cache the
2014 + info. Actually the notification is controlled by these factors.
2015 + + the specified cache time.
2016 + + classified as "force" by aufs internally.
2017 + Until the specified time expires, aufs doesn't send the info
2018 + except the forced cases. When aufs decide forcing, the info is always
2019 + notified to userspace.
2020 + For example, the number of free inodes is generally large enough and
2021 + the shortage of it happens rarely. So aufs doesn't force the
2022 + notification when creating a new file, directory and others. This is
2023 + the typical case which aufs doesn't force.
2024 + When aufs writes the actual filedata and the files consumes any of new
2025 + blocks, the aufs forces notifying.
2028 +o Interfaces in aufs
2029 +- New branch attribute.
2031 + Specifies that the branch is managed by FHSM feature. In other word,
2032 + participant in the FHSM.
2033 + When nofhsm is set to the branch, it will not be the source/target
2034 + branch of the move-down operation. This attribute is set
2035 + independently from coo and moo attributes, and if you want full
2036 + FHSM, you should specify them as well.
2037 +- New mount option.
2039 + Specifies a second to suppress many less important info to be
2042 + + AUFS_CTL_FHSM_FD
2043 + create a new file descriptor which userspace can read the notification
2044 + (a subset of struct statfs) from aufs.
2045 +- Module parameter 'brs'
2046 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2048 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2049 + When there are two or more branches with fhsm attributes,
2050 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2051 + terminates it. As a result of remounting and branch-manipulation, the
2052 + number of branches with fhsm attribute can be one. In this case,
2053 + /sbin/mount.aufs will terminate the user-space daemon.
2056 +Finally the operation is done as these steps in kernel-space.
2058 + + no one else is using the file.
2059 + + the file is not hard-linked.
2060 + + the file is not pseudo-linked.
2061 + + the file is a regular file.
2062 + + the parent dir is not opaqued.
2063 +- find the target writable branch.
2064 +- make sure the file is not whiteout-ed by the upper (than the target)
2066 +- make the parent dir on the target branch.
2067 +- mutex lock the inode on the branch.
2068 +- unlink the whiteout on the target branch (if exists).
2069 +- lookup and create the whiteout-ed temporary name on the target branch.
2070 +- copy the file as the whiteout-ed temporary name on the target branch.
2071 +- rename the whiteout-ed temporary name to the original name.
2072 +- unlink the file on the source branch.
2073 +- maintain the internal pointer array and the external inode number
2075 +- maintain the timestamps and other attributes of the parent dir and the
2078 +And of course, in every step, an error may happen. So the operation
2079 +should restore the original file state after an error happens.
2080 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2081 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2082 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2022-11-05 23:02:18.959222617 +0100
2085 +# Copyright (C) 2005-2022 Junjiro R. Okajima
2087 +# This program is free software; you can redistribute it and/or modify
2088 +# it under the terms of the GNU General Public License as published by
2089 +# the Free Software Foundation; either version 2 of the License, or
2090 +# (at your option) any later version.
2092 +# This program is distributed in the hope that it will be useful,
2093 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2094 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2095 +# GNU General Public License for more details.
2097 +# You should have received a copy of the GNU General Public License
2098 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2100 +mmap(2) -- File Memory Mapping
2101 +----------------------------------------------------------------------
2102 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2103 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2105 +This approach is simple and good, but there is one problem.
2106 +Under /proc, several entries show the mmapped files by its path (with
2107 +device and inode number), and the printed path will be the path on the
2108 +branch fs's instead of virtual aufs's.
2109 +This is not a problem in most cases, but some utilities lsof(1) (and its
2110 +user) may expect the path on aufs.
2112 +To address this issue, aufs adds a new member called vm_prfile in struct
2113 +vm_area_struct (and struct vm_region). The original vm_file points to
2114 +the file on the branch fs in order to handle everything correctly as
2115 +usual. The new vm_prfile points to a virtual file in aufs, and the
2116 +show-functions in procfs refers to vm_prfile if it is set.
2117 +Also we need to maintain several other places where touching vm_file
2119 +- fork()/clone() copies vma and the reference count of vm_file is
2121 +- merging vma maintains the ref count too.
2123 +This is not a good approach. It just fakes the printed path. But it
2124 +leaves all behaviour around f_mapping unchanged. This is surely an
2126 +Actually aufs had adopted another complicated approach which calls
2127 +generic_file_mmap() and handles struct vm_operations_struct. In this
2128 +approach, aufs met a hard problem and I could not solve it without
2129 +switching the approach.
2131 +There may be one more another approach which is
2132 +- bind-mount the branch-root onto the aufs-root internally
2133 +- grab the new vfsmount (ie. struct mount)
2134 +- lazy-umount the branch-root internally
2135 +- in open(2) the aufs-file, open the branch-file with the hidden
2136 + vfsmount (instead of the original branch's vfsmount)
2137 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2138 + but it may be possible from userspace by the mount helper.
2140 +Adding the internal hidden vfsmount and using it in opening a file, the
2141 +file path under /proc will be printed correctly. This approach looks
2142 +smarter, but is not possible I am afraid.
2143 +- aufs-root may be bind-mount later. when it happens, another hidden
2144 + vfsmount will be required.
2145 +- it is hard to get the chance to bind-mount and lazy-umount
2146 + + in kernel-space, FS can have vfsmount in open(2) via
2147 + file->f_path, and aufs can know its vfsmount. But several locks are
2148 + already acquired, and if aufs tries to bind-mount and lazy-umount
2149 + here, then it may cause a deadlock.
2150 + + in user-space, bind-mount doesn't invoke the mount helper.
2151 +- since /proc shows dev and ino, aufs has to give vma these info. it
2152 + means a new member vm_prinode will be necessary. this is essentially
2153 + equivalent to vm_prfile described above.
2155 +I have to give up this "looks-smater" approach.
2156 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2157 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2158 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2022-11-05 23:02:18.959222617 +0100
2161 +# Copyright (C) 2014-2022 Junjiro R. Okajima
2163 +# This program is free software; you can redistribute it and/or modify
2164 +# it under the terms of the GNU General Public License as published by
2165 +# the Free Software Foundation; either version 2 of the License, or
2166 +# (at your option) any later version.
2168 +# This program is distributed in the hope that it will be useful,
2169 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2170 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2171 +# GNU General Public License for more details.
2173 +# You should have received a copy of the GNU General Public License
2174 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2176 +Listing XATTR/EA and getting the value
2177 +----------------------------------------------------------------------
2178 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2179 +shows the values from the topmost existing file. This behaviour is good
2180 +for the non-dir entries since the bahaviour exactly matches the shown
2181 +information. But for the directories, aufs considers all the same named
2182 +entries on the lower branches. Which means, if one of the lower entry
2183 +rejects readdir call, then aufs returns an error even if the topmost
2184 +entry allows it. This behaviour is necessary to respect the branch fs's
2185 +security, but can make users confused since the user-visible standard
2186 +attributes don't match the behaviour.
2187 +To address this issue, aufs has a mount option called dirperm1 which
2188 +checks the permission for the topmost entry only, and ignores the lower
2189 +entry's permission.
2191 +A similar issue can happen around XATTR.
2192 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2193 +always set. Otherwise these very unpleasant situation would happen.
2194 +- listxattr(2) may return the duplicated entries.
2195 +- users may not be able to remove or reset the XATTR forever,
2198 +XATTR/EA support in the internal (copy,move)-(up,down)
2199 +----------------------------------------------------------------------
2200 +Generally the extended attributes of inode are categorized as these.
2201 +- "security" for LSM and capability.
2202 +- "system" for posix ACL, 'acl' mount option is required for the branch
2204 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2205 +- "user" for userspace, 'user_xattr' mount option is required for the
2206 + branch fs generally.
2208 +Moreover there are some other categories. Aufs handles these rather
2209 +unpopular categories as the ordinary ones, ie. there is no special
2210 +condition nor exception.
2212 +In copy-up, the support for XATTR on the dst branch may differ from the
2213 +src branch. In this case, the copy-up operation will get an error and
2214 +the original user operation which triggered the copy-up will fail. It
2215 +can happen that even all copy-up will fail.
2216 +When both of src and dst branches support XATTR and if an error occurs
2217 +during copying XATTR, then the copy-up should fail obviously. That is a
2218 +good reason and aufs should return an error to userspace. But when only
2219 +the src branch support that XATTR, aufs should not return an error.
2220 +For example, the src branch supports ACL but the dst branch doesn't
2221 +because the dst branch may natively un-support it or temporary
2222 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2223 +may NOT return an error even if the XATTR is not supported. It is
2224 +totally up to the branch fs.
2226 +Anyway when the aufs internal copy-up gets an error from the dst branch
2227 +fs, then aufs tries removing the just copied entry and returns the error
2228 +to the userspace. The worst case of this situation will be all copy-up
2231 +For the copy-up operation, there two basic approaches.
2232 +- copy the specified XATTR only (by category above), and return the
2233 + error unconditionally if it happens.
2234 +- copy all XATTR, and ignore the error on the specified category only.
2236 +In order to support XATTR and to implement the correct behaviour, aufs
2237 +chooses the latter approach and introduces some new branch attributes,
2238 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2239 +They correspond to the XATTR namespaces (see above). Additionally, to be
2240 +convenient, "icex" is also provided which means all "icex*" attributes
2241 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2243 +The meaning of these attributes is to ignore the error from setting
2244 +XATTR on that branch.
2245 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2246 +error from the dst branch according to the specified attributes.
2248 +Some XATTR may have its default value. The default value may come from
2249 +the parent dir or the environment. If the default value is set at the
2250 +file creating-time, it will be overwritten by copy-up.
2251 +Some contradiction may happen I am afraid.
2252 +Do we need another attribute to stop copying XATTR? I am unsure. For
2253 +now, aufs implements the branch attributes to ignore the error.
2254 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2255 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2256 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2022-11-05 23:02:18.959222617 +0100
2259 +# Copyright (C) 2005-2022 Junjiro R. Okajima
2261 +# This program is free software; you can redistribute it and/or modify
2262 +# it under the terms of the GNU General Public License as published by
2263 +# the Free Software Foundation; either version 2 of the License, or
2264 +# (at your option) any later version.
2266 +# This program is distributed in the hope that it will be useful,
2267 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2268 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2269 +# GNU General Public License for more details.
2271 +# You should have received a copy of the GNU General Public License
2272 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2274 +Export Aufs via NFS
2275 +----------------------------------------------------------------------
2276 +Here is an approach.
2277 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2279 +- iget_locked(): initialize aufs inode generation for a new inode, and
2280 + store it in xigen file.
2281 +- destroy_inode(): increment aufs inode generation and store it in xigen
2282 + file. it is necessary even if it is not unlinked, because any data of
2283 + inode may be changed by UDBA.
2284 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2285 + build file handle by
2286 + + branch id (4 bytes)
2287 + + superblock generation (4 bytes)
2288 + + inode number (4 or 8 bytes)
2289 + + parent dir inode number (4 or 8 bytes)
2290 + + inode generation (4 bytes))
2291 + + return value of exportfs_encode_fh() for the parent on a branch (4
2293 + + file handle for a branch (by exportfs_encode_fh())
2295 + + find the index of a branch from its id in handle, and check it is
2296 + still exist in aufs.
2297 + + 1st level: get the inode number from handle and search it in cache.
2298 + + 2nd level: if not found in cache, get the parent inode number from
2299 + the handle and search it in cache. and then open the found parent
2300 + dir, find the matching inode number by vfs_readdir() and get its
2301 + name, and call lookup_one_len() for the target dentry.
2302 + + 3rd level: if the parent dir is not cached, call
2303 + exportfs_decode_fh() for a branch and get the parent on a branch,
2304 + build a pathname of it, convert it a pathname in aufs, call
2305 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2307 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2308 + for every branch, but not itself. to get this, (currently) aufs
2309 + searches in current->nsproxy->mnt_ns list. it may not be a good
2310 + idea, but I didn't get other approach.
2311 + + test the generation of the gotten inode.
2312 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2313 + convert it into ESTALE for NFSD.
2314 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2315 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2316 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2317 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2318 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2022-11-05 23:02:18.959222617 +0100
2321 +# Copyright (C) 2005-2022 Junjiro R. Okajima
2323 +# This program is free software; you can redistribute it and/or modify
2324 +# it under the terms of the GNU General Public License as published by
2325 +# the Free Software Foundation; either version 2 of the License, or
2326 +# (at your option) any later version.
2328 +# This program is distributed in the hope that it will be useful,
2329 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2330 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2331 +# GNU General Public License for more details.
2333 +# You should have received a copy of the GNU General Public License
2334 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2336 +Show Whiteout Mode (shwh)
2337 +----------------------------------------------------------------------
2338 +Generally aufs hides the name of whiteouts. But in some cases, to show
2339 +them is very useful for users. For instance, creating a new middle layer
2340 +(branch) by merging existing layers.
2342 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2343 +When you have three branches,
2344 +- Bottom: 'system', squashfs (underlying base system), read-only
2345 +- Middle: 'mods', squashfs, read-only
2346 +- Top: 'overlay', ram (tmpfs), read-write
2348 +The top layer is loaded at boot time and saved at shutdown, to preserve
2349 +the changes made to the system during the session.
2350 +When larger changes have been made, or smaller changes have accumulated,
2351 +the size of the saved top layer data grows. At this point, it would be
2352 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2353 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2354 +restoring save and load speed.
2356 +This merging is simplified by the use of another aufs mount, of just the
2357 +two overlay branches using the 'shwh' option.
2358 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2359 + aufs /livesys/merge_union
2361 +A merged view of these two branches is then available at
2362 +/livesys/merge_union, and the new feature is that the whiteouts are
2364 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2365 +writing to all branches. Also the default mode for all branches is 'ro'.
2366 +It is now possible to save the combined contents of the two overlay
2367 +branches to a new squashfs, e.g.:
2368 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2370 +This new squashfs archive can be stored on the boot device and the
2371 +initramfs will use it to replace the old one at the next boot.
2372 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2373 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2374 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2022-11-05 23:02:18.959222617 +0100
2377 +# Copyright (C) 2010-2022 Junjiro R. Okajima
2379 +# This program is free software; you can redistribute it and/or modify
2380 +# it under the terms of the GNU General Public License as published by
2381 +# the Free Software Foundation; either version 2 of the License, or
2382 +# (at your option) any later version.
2384 +# This program is distributed in the hope that it will be useful,
2385 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2386 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2387 +# GNU General Public License for more details.
2389 +# You should have received a copy of the GNU General Public License
2390 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2392 +Dynamically customizable FS operations
2393 +----------------------------------------------------------------------
2394 +Generally FS operations (struct inode_operations, struct
2395 +address_space_operations, struct file_operations, etc.) are defined as
2396 +"static const", but it never means that FS have only one set of
2397 +operation. Some FS have multiple sets of them. For instance, ext2 has
2398 +three sets, one for XIP, for NOBH, and for normal.
2399 +Since aufs overrides and redirects these operations, sometimes aufs has
2400 +to change its behaviour according to the branch FS type. More importantly
2401 +VFS acts differently if a function (member in the struct) is set or
2402 +not. It means aufs should have several sets of operations and select one
2403 +among them according to the branch FS definition.
2405 +In order to solve this problem and not to affect the behaviour of VFS,
2406 +aufs defines these operations dynamically. For instance, aufs defines
2407 +dummy direct_IO function for struct address_space_operations, but it may
2408 +not be set to the address_space_operations actually. When the branch FS
2409 +doesn't have it, aufs doesn't set it to its address_space_operations
2410 +while the function definition itself is still alive. So the behaviour
2411 +itself will not change, and it will return an error when direct_IO is
2414 +The lifetime of these dynamically generated operation object is
2415 +maintained by aufs branch object. When the branch is removed from aufs,
2416 +the reference counter of the object is decremented. When it reaches
2417 +zero, the dynamically generated operation object will be freed.
2419 +This approach is designed to support AIO (io_submit), Direct I/O and
2421 +Currently this approach is applied to address_space_operations for
2422 +regular files only.
2423 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2424 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2425 +++ linux/Documentation/filesystems/aufs/README 2022-11-05 23:02:18.955889283 +0100
2428 +Aufs6 -- advanced multi layered unification filesystem version 6.x
2434 +----------------------------------------
2435 +In the early days, aufs was entirely re-designed and re-implemented
2436 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2437 +improvements and implementations, it became totally different from
2438 +Unionfs while keeping the basic features.
2439 +Later, Unionfs Version 2.x series began taking some of the same
2440 +approaches to aufs1's.
2441 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2442 +University and his team.
2444 +Aufs6 supports linux-v6.0 and later, try aufs6.0 branch in
2445 +aufs-linux.git or aufs-standalone.git.
2446 +If you want older kernel version support,
2447 +- for linux-v5.x series, try aufs-linux.git or aufs-standalone.git
2448 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2449 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2450 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2451 + or aufs1 from CVS on SourceForge.
2453 +Note: the name of aufs5-linux.git and aufs5-standalone.git on github
2454 + were changed. Now they are aufs-linux.git and
2455 + aufs-standalone.git and they contain aufs5 and later branches.
2457 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2458 + According to Christoph Hellwig, linux rejects all union-type
2459 + filesystems but UnionMount.
2460 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2462 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2463 + UnionMount, and he pointed out an issue around a directory mutex
2464 + lock and aufs addressed it. But it is still unsure whether aufs will
2465 + be merged (or any other union solution).
2466 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2470 +----------------------------------------
2471 +- unite several directories into a single virtual filesystem. The member
2472 + directory is called as a branch.
2473 +- you can specify the permission flags to the branch, which are 'readonly',
2474 + 'readwrite' and 'whiteout-able.'
2475 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2476 + readonly branch are modifiable logically.
2477 +- dynamic branch manipulation, add, del.
2480 +Also there are many enhancements in aufs, such as:
2481 +- test only the highest one for the directory permission (dirperm1)
2482 +- copyup on open (coo=)
2483 +- 'move' policy for copy-up between two writable branches, after
2484 + checking free space.
2486 +- readdir(3) in userspace.
2487 +- keep inode number by external inode number table
2488 +- keep the timestamps of file/dir in internal copyup operation
2489 +- seekable directory, supporting NFS readdir.
2490 +- whiteout is hardlinked in order to reduce the consumption of inodes
2492 +- do not copyup, nor create a whiteout when it is unnecessary
2493 +- revert a single systemcall when an error occurs in aufs
2494 +- remount interface instead of ioctl
2495 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2496 +- loopback mounted filesystem as a branch
2497 +- kernel thread for removing the dir who has a plenty of whiteouts
2498 +- support copyup sparse file (a file which has a 'hole' in it)
2499 +- default permission flags for branches
2500 +- selectable permission flags for ro branch, whether whiteout can
2503 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2504 +- support multiple writable branches, some policies to select one
2505 + among multiple writable branches.
2506 +- a new semantics for link(2) and rename(2) to support multiple
2507 + writable branches.
2508 +- no glibc changes are required.
2509 +- pseudo hardlink (hardlink over branches)
2510 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2511 + including NFS or remote filesystem branch.
2512 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2515 +Currently these features are dropped temporary from aufs6.
2516 +See design/08plan.txt in detail.
2517 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2519 +- statistics of aufs thread (/sys/fs/aufs/stat)
2521 +Features or just an idea in the future (see also design/*.txt),
2522 +- reorder the branch index without del/re-add.
2523 +- permanent xino files for NFSD
2524 +- an option for refreshing the opened files after add/del branches
2525 +- light version, without branch manipulation. (unnecessary?)
2526 +- copyup in userspace
2527 +- inotify in userspace
2532 +----------------------------------------
2533 +There are three GIT trees for aufs6, aufs6-linux.git,
2534 +aufs6-standalone.git, and aufs-util.git. Note that there is no "6" in
2536 +While the aufs-util is always necessary, you need either of aufs6-linux
2537 +or aufs6-standalone.
2539 +The aufs6-linux tree includes the whole linux mainline GIT tree,
2540 +git://git.kernel.org/.../torvalds/linux.git.
2541 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2542 +build aufs6 as an external kernel module.
2543 +Several extra patches are not included in this tree. Only
2544 +aufs6-standalone tree contains them. They are described in the later
2545 +section "Configuration and Compilation."
2547 +On the other hand, the aufs6-standalone tree has only aufs source files
2548 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2549 +But you need to apply all aufs patches manually.
2551 +You will find GIT branches whose name is in form of "aufs6.x" where "x"
2552 +represents the linux kernel version, "linux-6.x". For instance,
2553 +"aufs6.0" is for linux-6.0. For latest "linux-6.x-rcN", use
2554 +"aufs6.x-rcN" branch.
2557 +$ git clone --reference /your/linux/git/tree \
2558 + git://github.com/sfjro/aufs6-linux.git aufs6-linux.git
2559 +- if you don't have linux GIT tree, then remove "--reference ..."
2560 +$ cd aufs6-linux.git
2561 +$ git checkout origin/aufs6.0
2563 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2564 +leave the patch-work to GIT.
2565 +$ cd /your/linux/git/tree
2566 +$ git remote add aufs6 git://github.com/sfjro/aufs6-linux.git
2568 +$ git checkout -b my6.0 v6.0
2569 +$ (add your local change...)
2570 +$ git pull aufs6 aufs6.0
2571 +- now you have v6.0 + your_changes + aufs6.0 in you my6.0 branch.
2572 +- you may need to solve some conflicts between your_changes and
2573 + aufs6.0. in this case, git-rerere is recommended so that you can
2574 + solve the similar conflicts automatically when you upgrade to 6.1 or
2575 + later in the future.
2577 +o aufs6-standalone tree
2578 +$ git clone git://github.com/sfjro/aufs6-standalone.git aufs6-standalone.git
2579 +$ cd aufs6-standalone.git
2580 +$ git checkout origin/aufs6.0
2583 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2584 +- note that the public aufs-util.git is on SourceForge instead of
2587 +$ git checkout origin/aufs6.0
2589 +Note: The 6.x-rcN branch is to be used with `rc' kernel versions ONLY.
2590 +The minor version number, 'x' in '6.x', of aufs may not always
2591 +follow the minor version number of the kernel.
2592 +Because changes in the kernel that cause the use of a new
2593 +minor version number do not always require changes to aufs-util.
2595 +Since aufs-util has its own minor version number, you may not be
2596 +able to find a GIT branch in aufs-util for your kernel's
2597 +exact minor version number.
2598 +In this case, you should git-checkout the branch for the
2599 +nearest lower number.
2601 +For (an unreleased) example:
2602 +If you are using "linux-6.10" and the "aufs6.10" branch
2603 +does not exist in aufs-util repository, then "aufs6.9", "aufs6.8"
2604 +or something numerically smaller is the branch for your kernel.
2606 +Also you can view all branches by
2610 +3. Configuration and Compilation
2611 +----------------------------------------
2612 +Make sure you have git-checkout'ed the correct branch.
2614 +For aufs6-linux tree,
2615 +- enable CONFIG_AUFS_FS.
2616 +- set other aufs configurations if necessary.
2617 +- for aufs5.13 and later
2618 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2619 + also a caller of VFS functions for branch filesystems, subclassing of
2620 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2621 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2622 + need to customize some LOCKDEP numbers. Here are what I use on my
2624 + CONFIG_LOCKDEP_BITS=21
2625 + CONFIG_LOCKDEP_CHAINS_BITS=21
2626 + CONFIG_LOCKDEP_STACK_TRACE_BITS=24
2628 +For aufs6-standalone tree,
2629 +There are several ways to build.
2632 +- apply ./aufs6-kbuild.patch to your kernel source files.
2633 +- apply ./aufs6-base.patch too.
2634 +- apply ./aufs6-mmap.patch too.
2635 +- apply ./aufs6-standalone.patch too, if you have a plan to set
2636 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs6-standalone.patch.
2637 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2638 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2639 +- enable CONFIG_AUFS_FS, you can select either
2641 +- and build your kernel as usual.
2642 +- install the built kernel.
2643 +- install the header files too by "make headers_install" to the
2644 + directory where you specify. By default, it is $PWD/usr.
2645 + "make help" shows a brief note for headers_install.
2646 +- and reboot your system.
2649 +- module only (CONFIG_AUFS_FS=m).
2650 +- apply ./aufs6-base.patch to your kernel source files.
2651 +- apply ./aufs6-mmap.patch too.
2652 +- apply ./aufs6-standalone.patch too.
2653 +- build your kernel, don't forget "make headers_install", and reboot.
2654 +- edit ./config.mk and set other aufs configurations if necessary.
2655 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2656 + every aufs configurations.
2657 +- build the module by simple "make".
2658 +- you can specify ${KDIR} make variable which points to your kernel
2660 +- install the files
2661 + + run "make install" to install the aufs module, or copy the built
2662 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2663 + + run "make install_headers" (instead of headers_install) to install
2664 + the modified aufs header file (you can specify DESTDIR which is
2665 + available in aufs standalone version's Makefile only), or copy
2666 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2667 + you like manually. By default, the target directory is $PWD/usr.
2668 +- no need to apply aufs6-kbuild.patch, nor copying source files to your
2669 + kernel source tree.
2671 +Note: The header file aufs_type.h is necessary to build aufs-util
2672 + as well as "make headers_install" in the kernel source tree.
2673 + headers_install is subject to be forgotten, but it is essentially
2674 + necessary, not only for building aufs-util.
2675 + You may not meet problems without headers_install in some older
2679 +- read README in aufs-util, build and install it
2680 +- note that your distribution may contain an obsoleted version of
2681 + aufs_type.h in /usr/include/linux or something. When you build aufs
2682 + utilities, make sure that your compiler refers the correct aufs header
2683 + file which is built by "make headers_install."
2684 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2685 + then run "make install_ulib" too. And refer to the aufs manual in
2688 +There several other patches in aufs6-standalone.git. They are all
2689 +optional. When you meet some problems, they will help you.
2690 +- aufs6-loopback.patch
2691 + Supports a nested loopback mount in a branch-fs. This patch is
2692 + unnecessary until aufs produces a message like "you may want to try
2693 + another patch for loopback file".
2695 + Modifies a system global kernel internal function get_next_ino() in
2696 + order to stop assigning 0 for an inode-number. Not directly related to
2697 + aufs, but recommended generally.
2699 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2700 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2701 + duplication of inode number, which is important for backup tools and
2702 + other utilities. When you find aufs XINO files for tmpfs branch
2703 + growing too much, try this patch.
2707 +----------------------------------------
2708 +At first, make sure aufs-util are installed, and please read the aufs
2709 +manual, aufs.6 in aufs-util.git tree.
2713 +$ mkdir /tmp/rw /tmp/aufs
2714 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2716 +Here is another example. The result is equivalent.
2717 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2719 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2720 +# mount -o remount,append:${HOME} /tmp/aufs
2722 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2723 +you modify a file under /tmp/aufs, the one on your home directory is
2724 +not affected, instead the same named file will be newly created under
2725 +/tmp/rw. And all of your modification to a file will be applied to
2726 +the one under /tmp/rw. This is called the file based Copy on Write
2728 +Aufs mount options are described in aufs.6.
2729 +If you run chroot or something and make your aufs as a root directory,
2730 +then you need to customize the shutdown script. See the aufs manual in
2733 +Additionally, there are some sample usages of aufs which are a
2734 +diskless system with network booting, and LiveCD over NFS.
2735 +See sample dir in CVS tree on SourceForge.
2739 +----------------------------------------
2740 +When you have any problems or strange behaviour in aufs, please let me
2742 +- /proc/mounts (instead of the output of mount(8))
2743 +- /sys/module/aufs/*
2744 +- /sys/fs/aufs/* (if you have them)
2745 +- /debug/aufs/* (if you have them)
2746 +- linux kernel version
2747 + if your kernel is not plain, for example modified by distributor,
2748 + the url where i can download its source is necessary too.
2749 +- aufs version which was printed at loading the module or booting the
2750 + system, instead of the date you downloaded.
2751 +- configuration (define/undefine CONFIG_AUFS_xxx)
2752 +- kernel configuration or /proc/config.gz (if you have it)
2753 +- LSM (linux security module, if you are using)
2754 +- behaviour which you think to be incorrect
2755 +- actual operation, reproducible one is better
2756 +- mailto: aufs-users at lists.sourceforge.net
2758 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2759 +and Feature Requests) on SourceForge. Please join and write to
2763 +6. Acknowledgements
2764 +----------------------------------------
2765 +Thanks to everyone who have tried and are using aufs, whoever
2766 +have reported a bug or any feedback.
2768 +Especially donators:
2769 +Tomas Matejicek(slax.org) made a donation (much more than once).
2770 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2771 + scripts) is making "doubling" donations.
2772 + Unfortunately I cannot list all of the donators, but I really
2774 + It ends Aug 2010, but the ordinary donation URL is still available.
2775 + <http://sourceforge.net/donate/index.php?group_id=167503>
2776 +Dai Itasaka made a donation (2007/8).
2777 +Chuck Smith made a donation (2008/4, 10 and 12).
2778 +Henk Schoneveld made a donation (2008/9).
2779 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2780 +Francois Dupoux made a donation (2008/11).
2781 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2782 + aufs2 GIT tree (2009/2).
2783 +William Grant made a donation (2009/3).
2784 +Patrick Lane made a donation (2009/4).
2785 +The Mail Archive (mail-archive.com) made donations (2009/5).
2786 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2787 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2788 +Pavel Pronskiy made a donation (2011/2).
2789 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2790 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2791 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2793 +Sam Liddicott made a donation (2011/9).
2794 +Era Scarecrow made a donation (2013/4).
2795 +Bor Ratajc made a donation (2013/4).
2796 +Alessandro Gorreta made a donation (2013/4).
2797 +POIRETTE Marc made a donation (2013/4).
2798 +Alessandro Gorreta made a donation (2013/4).
2799 +lauri kasvandik made a donation (2013/5).
2800 +"pemasu from Finland" made a donation (2013/7).
2801 +The Parted Magic Project made a donation (2013/9 and 11).
2802 +Pavel Barta made a donation (2013/10).
2803 +Nikolay Pertsev made a donation (2014/5).
2804 +James B made a donation (2014/7, 2015/7, and 2021/12).
2805 +Stefano Di Biase made a donation (2014/8).
2806 +Daniel Epellei made a donation (2015/1).
2807 +OmegaPhil made a donation (2016/1, 2018/4).
2808 +Tomasz Szewczyk made a donation (2016/4).
2809 +James Burry made a donation (2016/12).
2810 +Carsten Rose made a donation (2018/9).
2811 +Porteus Kiosk made a donation (2018/10).
2812 +Enya Quetzalli Gomez Rodriguez made a donation (2022/5).
2814 +Thank you very much.
2815 +Donations are always, including future donations, very important and
2816 +helpful for me to keep on developing aufs.
2820 +----------------------------------------
2821 +If you are an experienced user, no explanation is needed. Aufs is
2822 +just a linux filesystem.
2827 +# Local variables: ;
2830 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2831 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2832 +++ linux/fs/aufs/aufs.h 2022-11-05 23:02:18.959222617 +0100
2834 +/* SPDX-License-Identifier: GPL-2.0 */
2836 + * Copyright (C) 2005-2022 Junjiro R. Okajima
2838 + * This program is free software; you can redistribute it and/or modify
2839 + * it under the terms of the GNU General Public License as published by
2840 + * the Free Software Foundation; either version 2 of the License, or
2841 + * (at your option) any later version.
2843 + * This program is distributed in the hope that it will be useful,
2844 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2845 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2846 + * GNU General Public License for more details.
2848 + * You should have received a copy of the GNU General Public License
2849 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2853 + * all header files
2861 +#define AuStub(type, name, body, ...) \
2862 + static inline type name(__VA_ARGS__) { body; }
2864 +#define AuStubVoid(name, ...) \
2865 + AuStub(void, name, , __VA_ARGS__)
2866 +#define AuStubInt0(name, ...) \
2867 + AuStub(int, name, return 0, __VA_ARGS__)
2871 +#include "branch.h"
2874 +#include "dbgaufs.h"
2875 +#include "dentry.h"
2877 +#include "dirren.h"
2880 +#include "fstype.h"
2885 +#include "module.h"
2889 +#include "sysaufs.h"
2894 +#endif /* __KERNEL__ */
2895 +#endif /* __AUFS_H__ */
2896 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2897 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2898 +++ linux/fs/aufs/branch.c 2022-11-05 23:02:18.959222617 +0100
2900 +// SPDX-License-Identifier: GPL-2.0
2902 + * Copyright (C) 2005-2022 Junjiro R. Okajima
2904 + * This program is free software; you can redistribute it and/or modify
2905 + * it under the terms of the GNU General Public License as published by
2906 + * the Free Software Foundation; either version 2 of the License, or
2907 + * (at your option) any later version.
2909 + * This program is distributed in the hope that it will be useful,
2910 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2911 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2912 + * GNU General Public License for more details.
2914 + * You should have received a copy of the GNU General Public License
2915 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2919 + * branch management
2922 +#include <linux/compat.h>
2923 +#include <linux/statfs.h>
2927 + * free a single branch
2929 +static void au_br_do_free(struct au_branch *br)
2932 + struct au_wbr *wbr;
2933 + struct au_dykey **key;
2935 + au_hnotify_fin_br(br);
2936 + /* always, regardless the mount option */
2937 + au_dr_hino_free(&br->br_dirren);
2940 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
2941 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
2942 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
2943 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
2947 + for (i = 0; i < AuBrWh_Last; i++)
2948 + dput(wbr->wbr_wh[i]);
2949 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2950 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2953 + if (br->br_fhsm) {
2954 + au_br_fhsm_fin(br->br_fhsm);
2955 + au_kfree_try_rcu(br->br_fhsm);
2958 + key = br->br_dykey;
2959 + for (i = 0; i < AuBrDynOp; i++, key++)
2965 + /* recursive lock, s_umount of branch's */
2966 + /* synchronize_rcu(); */ /* why? */
2968 + path_put(&br->br_path);
2970 + au_kfree_rcu(wbr);
2971 + au_lcnt_wait_for_fin(&br->br_nfiles);
2972 + au_lcnt_wait_for_fin(&br->br_count);
2973 + /* I don't know why, but percpu_refcount requires this */
2974 + /* synchronize_rcu(); */
2979 + * frees all branches
2981 +void au_br_free(struct au_sbinfo *sbinfo)
2983 + aufs_bindex_t bmax;
2984 + struct au_branch **br;
2986 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2988 + bmax = sbinfo->si_bbot + 1;
2989 + br = sbinfo->si_branch;
2991 + au_br_do_free(*br++);
2995 + * find the index of a branch which is specified by @br_id.
2997 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2999 + aufs_bindex_t bindex, bbot;
3001 + bbot = au_sbbot(sb);
3002 + for (bindex = 0; bindex <= bbot; bindex++)
3003 + if (au_sbr_id(sb, bindex) == br_id)
3008 +/* ---------------------------------------------------------------------- */
3014 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3015 + struct dentry *h_root)
3017 + if (unlikely(h_adding == h_root
3018 + || au_test_loopback_overlap(sb, h_adding)))
3020 + if (h_adding->d_sb != h_root->d_sb)
3022 + return au_test_subdir(h_adding, h_root)
3023 + || au_test_subdir(h_root, h_adding);
3027 + * returns a newly allocated branch. @new_nbranch is a number of branches
3028 + * after adding a branch.
3030 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3033 + struct au_branch *add_branch;
3034 + struct dentry *root;
3035 + struct inode *inode;
3039 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3040 + if (unlikely(!add_branch))
3042 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3043 + if (unlikely(!add_branch->br_xino))
3045 + err = au_hnotify_init_br(add_branch, perm);
3046 + if (unlikely(err))
3049 + if (au_br_writable(perm)) {
3050 + /* may be freed separately at changing the branch permission */
3051 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3053 + if (unlikely(!add_branch->br_wbr))
3057 + if (au_br_fhsm(perm)) {
3058 + err = au_fhsm_br_alloc(add_branch);
3059 + if (unlikely(err))
3063 + root = sb->s_root;
3064 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3066 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3068 + inode = d_inode(root);
3069 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3073 + return add_branch; /* success */
3076 + au_kfree_rcu(add_branch->br_wbr);
3078 + au_hnotify_fin_br(add_branch);
3080 + au_xino_put(add_branch);
3082 + au_kfree_rcu(add_branch);
3084 + return ERR_PTR(err);
3088 + * test if the branch permission is legal or not.
3090 +static int test_br(struct inode *inode, int brperm, char *path)
3094 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3099 + pr_err("write permission for readonly mount or inode, %s\n", path);
3107 + * 0: success, the caller will add it
3108 + * plus: success, it is already unified, the caller should ignore it
3111 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3114 + aufs_bindex_t bbot, bindex;
3115 + struct dentry *root, *h_dentry;
3116 + struct inode *inode, *h_inode;
3118 + root = sb->s_root;
3119 + bbot = au_sbbot(sb);
3120 + if (unlikely(bbot >= 0
3121 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3125 + pr_err("%s duplicated\n", add->pathname);
3130 + err = -ENOSPC; /* -E2BIG; */
3131 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3132 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3133 + pr_err("number of branches exceeded %s\n", add->pathname);
3138 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3139 + pr_err("bad index %d\n", add->bindex);
3143 + inode = d_inode(add->path.dentry);
3145 + if (unlikely(!inode->i_nlink)) {
3146 + pr_err("no existence %s\n", add->pathname);
3151 + if (unlikely(inode->i_sb == sb)) {
3152 + pr_err("%s must be outside\n", add->pathname);
3156 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3157 + pr_err("unsupported filesystem, %s (%s)\n",
3158 + add->pathname, au_sbtype(inode->i_sb));
3162 + if (unlikely(inode->i_sb->s_stack_depth)) {
3163 + pr_err("already stacked, %s (%s)\n",
3164 + add->pathname, au_sbtype(inode->i_sb));
3168 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3169 + if (unlikely(err))
3173 + return 0; /* success */
3176 + for (bindex = 0; bindex <= bbot; bindex++)
3177 + if (unlikely(test_overlap(sb, add->path.dentry,
3178 + au_h_dptr(root, bindex)))) {
3179 + pr_err("%s is overlapped\n", add->pathname);
3184 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3185 + h_dentry = au_h_dptr(root, 0);
3186 + h_inode = d_inode(h_dentry);
3187 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3188 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3189 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3190 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3192 + i_uid_read(inode), i_gid_read(inode),
3193 + (inode->i_mode & S_IALLUGO),
3194 + i_uid_read(h_inode), i_gid_read(h_inode),
3195 + (h_inode->i_mode & S_IALLUGO));
3203 + * initialize or clean the whiteouts for an adding branch
3205 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3208 + int err, old_perm;
3209 + aufs_bindex_t bindex;
3210 + struct inode *h_inode;
3211 + struct au_wbr *wbr;
3212 + struct au_hinode *hdir;
3213 + struct dentry *h_dentry;
3215 + err = vfsub_mnt_want_write(au_br_mnt(br));
3216 + if (unlikely(err))
3220 + old_perm = br->br_perm;
3221 + br->br_perm = new_perm;
3224 + bindex = au_br_index(sb, br->br_id);
3225 + if (0 <= bindex) {
3226 + hdir = au_hi(d_inode(sb->s_root), bindex);
3227 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3229 + h_dentry = au_br_dentry(br);
3230 + h_inode = d_inode(h_dentry);
3231 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3234 + err = au_wh_init(br, sb);
3236 + wbr_wh_write_lock(wbr);
3237 + err = au_wh_init(br, sb);
3238 + wbr_wh_write_unlock(wbr);
3241 + au_hn_inode_unlock(hdir);
3243 + inode_unlock(h_inode);
3244 + vfsub_mnt_drop_write(au_br_mnt(br));
3245 + br->br_perm = old_perm;
3247 + if (!err && wbr && !au_br_writable(new_perm)) {
3248 + au_kfree_rcu(wbr);
3249 + br->br_wbr = NULL;
3256 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3260 + struct kstatfs kst;
3261 + struct au_wbr *wbr;
3264 + au_rw_init(&wbr->wbr_wh_rwsem);
3265 + atomic_set(&wbr->wbr_wh_running, 0);
3268 + * a limit for rmdir/rename a dir
3269 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3271 + err = vfs_statfs(&br->br_path, &kst);
3272 + if (unlikely(err))
3275 + if (kst.f_namelen >= NAME_MAX)
3276 + err = au_br_init_wh(sb, br, perm);
3278 + pr_err("%pd(%s), unsupported namelen %ld\n",
3280 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3286 +/* initialize a new branch */
3287 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3288 + struct au_opt_add *add)
3291 + struct au_branch *brbase;
3293 + struct inode *h_inode;
3296 + br->br_perm = add->perm;
3297 + br->br_path = add->path; /* set first, path_get() later */
3298 + spin_lock_init(&br->br_dykey_lock);
3299 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3300 + au_lcnt_init(&br->br_count, /*release*/NULL);
3301 + br->br_id = au_new_br_id(sb);
3302 + AuDebugOn(br->br_id < 0);
3304 + /* always, regardless the given option */
3305 + err = au_dr_br_init(sb, br, &add->path);
3306 + if (unlikely(err))
3309 + if (au_br_writable(add->perm)) {
3310 + err = au_wbr_init(br, sb, add->perm);
3311 + if (unlikely(err))
3315 + if (au_opt_test(au_mntflags(sb), XINO)) {
3316 + brbase = au_sbr(sb, 0);
3317 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3319 + h_inode = d_inode(add->path.dentry);
3320 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3321 + if (unlikely(err)) {
3322 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3327 + sysaufs_br_init(br);
3328 + path_get(&br->br_path);
3329 + goto out; /* success */
3332 + memset(&br->br_path, 0, sizeof(br->br_path));
3337 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3338 + struct au_branch *br, aufs_bindex_t bbot,
3339 + aufs_bindex_t amount)
3341 + struct au_branch **brp;
3343 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3345 + brp = sbinfo->si_branch + bindex;
3346 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3348 + sbinfo->si_bbot++;
3349 + if (unlikely(bbot < 0))
3350 + sbinfo->si_bbot = 0;
3353 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3354 + aufs_bindex_t bbot, aufs_bindex_t amount)
3356 + struct au_hdentry *hdp;
3358 + AuRwMustWriteLock(&dinfo->di_rwsem);
3360 + hdp = au_hdentry(dinfo, bindex);
3361 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3362 + au_h_dentry_init(hdp);
3364 + if (unlikely(bbot < 0))
3365 + dinfo->di_btop = 0;
3368 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3369 + aufs_bindex_t bbot, aufs_bindex_t amount)
3371 + struct au_hinode *hip;
3373 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3375 + hip = au_hinode(iinfo, bindex);
3376 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3377 + au_hinode_init(hip);
3379 + if (unlikely(bbot < 0))
3380 + iinfo->ii_btop = 0;
3383 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3384 + aufs_bindex_t bindex)
3386 + struct dentry *root, *h_dentry;
3387 + struct inode *root_inode, *h_inode;
3388 + aufs_bindex_t bbot, amount;
3390 + root = sb->s_root;
3391 + root_inode = d_inode(root);
3392 + bbot = au_sbbot(sb);
3393 + amount = bbot + 1 - bindex;
3394 + h_dentry = au_br_dentry(br);
3395 + au_sbilist_lock();
3396 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3397 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3398 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3399 + au_set_h_dptr(root, bindex, dget(h_dentry));
3400 + h_inode = d_inode(h_dentry);
3401 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3402 + au_sbilist_unlock();
3405 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3408 + aufs_bindex_t bbot, add_bindex;
3409 + struct dentry *root, *h_dentry;
3410 + struct inode *root_inode;
3411 + struct au_branch *add_branch;
3413 + root = sb->s_root;
3414 + root_inode = d_inode(root);
3415 + IMustLock(root_inode);
3416 + IiMustWriteLock(root_inode);
3417 + err = test_add(sb, add, remount);
3418 + if (unlikely(err < 0))
3422 + goto out; /* success */
3425 + bbot = au_sbbot(sb);
3426 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3427 + err = PTR_ERR(add_branch);
3428 + if (IS_ERR(add_branch))
3431 + err = au_br_init(add_branch, sb, add);
3432 + if (unlikely(err)) {
3433 + au_br_do_free(add_branch);
3437 + add_bindex = add->bindex;
3438 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3439 + au_br_do_add(sb, add_branch, add_bindex);
3440 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3441 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3443 + h_dentry = add->path.dentry;
3444 + if (!add_bindex) {
3445 + au_cpup_attr_all(root_inode, /*force*/1);
3446 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3448 + au_add_nlink(root_inode, d_inode(h_dentry));
3454 +/* ---------------------------------------------------------------------- */
3456 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3457 + unsigned long long max __maybe_unused,
3460 + unsigned long long n;
3461 + struct file **p, *f;
3462 + struct hlist_bl_head *files;
3463 + struct hlist_bl_node *pos;
3464 + struct au_finfo *finfo;
3468 + files = &au_sbi(sb)->si_files;
3469 + hlist_bl_lock(files);
3470 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3471 + f = finfo->fi_file;
3473 + && !special_file(file_inode(f)->i_mode)) {
3477 + AuDebugOn(n > max);
3480 + hlist_bl_unlock(files);
3485 +static struct file **au_farray_alloc(struct super_block *sb,
3486 + unsigned long long *max)
3488 + struct au_sbinfo *sbi;
3491 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3492 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3495 +static void au_farray_free(struct file **a, unsigned long long max)
3497 + unsigned long long ull;
3499 + for (ull = 0; ull < max; ull++)
3505 +/* ---------------------------------------------------------------------- */
3511 +/* to show the line number, do not make it inlined function */
3512 +#define AuVerbose(do_info, fmt, ...) do { \
3514 + pr_info(fmt, ##__VA_ARGS__); \
3517 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3518 + aufs_bindex_t bbot)
3520 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3523 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3524 + aufs_bindex_t bbot)
3526 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3530 + * test if the branch is deletable or not.
3532 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3533 + unsigned int sigen, const unsigned int verbose)
3535 + int err, i, j, ndentry;
3536 + aufs_bindex_t btop, bbot;
3537 + struct au_dcsub_pages dpages;
3538 + struct au_dpage *dpage;
3541 + err = au_dpages_init(&dpages, GFP_NOFS);
3542 + if (unlikely(err))
3544 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3545 + if (unlikely(err))
3548 + for (i = 0; !err && i < dpages.ndpage; i++) {
3549 + dpage = dpages.dpages + i;
3550 + ndentry = dpage->ndentry;
3551 + for (j = 0; !err && j < ndentry; j++) {
3552 + d = dpage->dentries[j];
3553 + AuDebugOn(au_dcount(d) <= 0);
3554 + if (!au_digen_test(d, sigen)) {
3555 + di_read_lock_child(d, AuLock_IR);
3556 + if (unlikely(au_dbrange_test(d))) {
3557 + di_read_unlock(d, AuLock_IR);
3561 + di_write_lock_child(d);
3562 + if (unlikely(au_dbrange_test(d))) {
3563 + di_write_unlock(d);
3566 + err = au_reval_dpath(d, sigen);
3568 + di_downgrade_lock(d, AuLock_IR);
3570 + di_write_unlock(d);
3575 + /* AuDbgDentry(d); */
3576 + btop = au_dbtop(d);
3577 + bbot = au_dbbot(d);
3578 + if (btop <= bindex
3580 + && au_h_dptr(d, bindex)
3581 + && au_test_dbusy(d, btop, bbot)) {
3583 + AuVerbose(verbose, "busy %pd\n", d);
3586 + di_read_unlock(d, AuLock_IR);
3591 + au_dpages_free(&dpages);
3596 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3597 + unsigned int sigen, const unsigned int verbose)
3600 + unsigned long long max, ull;
3601 + struct inode *i, **array;
3602 + aufs_bindex_t btop, bbot;
3604 + array = au_iarray_alloc(sb, &max);
3605 + err = PTR_ERR(array);
3606 + if (IS_ERR(array))
3610 + AuDbg("b%d\n", bindex);
3611 + for (ull = 0; !err && ull < max; ull++) {
3615 + if (i->i_ino == AUFS_ROOT_INO)
3618 + /* AuDbgInode(i); */
3619 + if (au_iigen(i, NULL) == sigen)
3620 + ii_read_lock_child(i);
3622 + ii_write_lock_child(i);
3623 + err = au_refresh_hinode_self(i);
3626 + ii_downgrade_lock(i);
3628 + ii_write_unlock(i);
3633 + btop = au_ibtop(i);
3634 + bbot = au_ibbot(i);
3635 + if (btop <= bindex
3637 + && au_h_iptr(i, bindex)
3638 + && au_test_ibusy(i, btop, bbot)) {
3640 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3643 + ii_read_unlock(i);
3645 + au_iarray_free(array, max);
3651 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3652 + const unsigned int verbose)
3655 + unsigned int sigen;
3657 + sigen = au_sigen(root->d_sb);
3658 + DiMustNoWaiters(root);
3659 + IiMustNoWaiters(d_inode(root));
3660 + di_write_unlock(root);
3661 + err = test_dentry_busy(root, bindex, sigen, verbose);
3663 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3664 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3669 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3670 + struct file **to_free, int *idx)
3673 + unsigned char matched, root;
3674 + aufs_bindex_t bindex, bbot;
3675 + struct au_fidir *fidir;
3676 + struct au_hfile *hfile;
3679 + root = IS_ROOT(file->f_path.dentry);
3682 + to_free[*idx] = file;
3688 + fidir = au_fi(file)->fi_hdir;
3689 + AuDebugOn(!fidir);
3690 + bbot = au_fbbot_dir(file);
3691 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3692 + hfile = fidir->fd_hfile + bindex;
3693 + if (!hfile->hf_file)
3696 + if (hfile->hf_br->br_id == br_id) {
3708 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3709 + struct file **to_free, int opened)
3712 + unsigned long long ull, max;
3713 + aufs_bindex_t btop;
3714 + struct file *file, **array;
3715 + struct dentry *root;
3716 + struct au_hfile *hfile;
3718 + array = au_farray_alloc(sb, &max);
3719 + err = PTR_ERR(array);
3720 + if (IS_ERR(array))
3725 + root = sb->s_root;
3726 + di_write_unlock(root);
3727 + for (ull = 0; ull < max; ull++) {
3728 + file = array[ull];
3729 + if (unlikely(!file))
3732 + /* AuDbg("%pD\n", file); */
3733 + fi_read_lock(file);
3734 + btop = au_fbtop(file);
3735 + if (!d_is_dir(file->f_path.dentry)) {
3736 + hfile = &au_fi(file)->fi_htop;
3737 + if (hfile->hf_br->br_id == br_id)
3740 + err = test_dir_busy(file, br_id, to_free, &idx);
3741 + fi_read_unlock(file);
3742 + if (unlikely(err))
3745 + di_write_lock_child(root);
3746 + au_farray_free(array, max);
3747 + AuDebugOn(idx > opened);
3753 +static void br_del_file(struct file **to_free, unsigned long long opened,
3754 + aufs_bindex_t br_id)
3756 + unsigned long long ull;
3757 + aufs_bindex_t bindex, btop, bbot, bfound;
3758 + struct file *file;
3759 + struct au_fidir *fidir;
3760 + struct au_hfile *hfile;
3762 + for (ull = 0; ull < opened; ull++) {
3763 + file = to_free[ull];
3764 + if (unlikely(!file))
3767 + /* AuDbg("%pD\n", file); */
3768 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3770 + fidir = au_fi(file)->fi_hdir;
3771 + AuDebugOn(!fidir);
3772 + fi_write_lock(file);
3773 + btop = au_fbtop(file);
3774 + bbot = au_fbbot_dir(file);
3775 + for (bindex = btop; bindex <= bbot; bindex++) {
3776 + hfile = fidir->fd_hfile + bindex;
3777 + if (!hfile->hf_file)
3780 + if (hfile->hf_br->br_id == br_id) {
3785 + AuDebugOn(bfound < 0);
3786 + au_set_h_fptr(file, bfound, NULL);
3787 + if (bfound == btop) {
3788 + for (btop++; btop <= bbot; btop++)
3789 + if (au_hf_dir(file, btop)) {
3790 + au_set_fbtop(file, btop);
3794 + fi_write_unlock(file);
3798 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3799 + const aufs_bindex_t bindex,
3800 + const aufs_bindex_t bbot)
3802 + struct au_branch **brp, **p;
3804 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3806 + brp = sbinfo->si_branch + bindex;
3807 + if (bindex < bbot)
3808 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3809 + sbinfo->si_branch[0 + bbot] = NULL;
3810 + sbinfo->si_bbot--;
3812 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3815 + sbinfo->si_branch = p;
3816 + /* harmless error */
3819 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3820 + const aufs_bindex_t bbot)
3822 + struct au_hdentry *hdp, *p;
3824 + AuRwMustWriteLock(&dinfo->di_rwsem);
3826 + hdp = au_hdentry(dinfo, bindex);
3827 + if (bindex < bbot)
3828 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3829 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3832 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3835 + dinfo->di_hdentry = p;
3836 + /* harmless error */
3839 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3840 + const aufs_bindex_t bbot)
3842 + struct au_hinode *hip, *p;
3844 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3846 + hip = au_hinode(iinfo, bindex);
3847 + if (bindex < bbot)
3848 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3849 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3852 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3855 + iinfo->ii_hinode = p;
3856 + /* harmless error */
3859 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3860 + struct au_branch *br)
3862 + aufs_bindex_t bbot;
3863 + struct au_sbinfo *sbinfo;
3864 + struct dentry *root, *h_root;
3865 + struct inode *inode, *h_inode;
3866 + struct au_hinode *hinode;
3868 + SiMustWriteLock(sb);
3870 + root = sb->s_root;
3871 + inode = d_inode(root);
3872 + sbinfo = au_sbi(sb);
3873 + bbot = sbinfo->si_bbot;
3875 + h_root = au_h_dptr(root, bindex);
3876 + hinode = au_hi(inode, bindex);
3877 + h_inode = au_igrab(hinode->hi_inode);
3880 + au_sbilist_lock();
3881 + au_br_do_del_brp(sbinfo, bindex, bbot);
3882 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3883 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3884 + au_sbilist_unlock();
3886 + /* ignore an error */
3887 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
3891 + au_br_do_free(br);
3894 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3895 + unsigned long long max, void *arg)
3900 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3903 + unsigned long long opened;
3904 + unsigned int mnt_flags;
3905 + aufs_bindex_t bindex, bbot, br_id;
3906 + unsigned char do_wh, verbose;
3907 + struct au_branch *br;
3908 + struct au_wbr *wbr;
3909 + struct dentry *root;
3910 + struct file **to_free;
3915 + root = sb->s_root;
3916 + bindex = au_find_dbindex(root, del->h_path.dentry);
3919 + goto out; /* success */
3921 + pr_err("%s no such branch\n", del->pathname);
3924 + AuDbg("bindex b%d\n", bindex);
3927 + mnt_flags = au_mntflags(sb);
3928 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3929 + bbot = au_sbbot(sb);
3930 + if (unlikely(!bbot)) {
3931 + AuVerbose(verbose, "no more branches left\n");
3935 + br = au_sbr(sb, bindex);
3936 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3937 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
3938 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
3942 + br_id = br->br_id;
3943 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
3944 + if (unlikely(opened)) {
3945 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3946 + err = PTR_ERR(to_free);
3947 + if (IS_ERR(to_free))
3950 + err = test_file_busy(sb, br_id, to_free, opened);
3951 + if (unlikely(err)) {
3952 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3958 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3960 + /* instead of WbrWhMustWriteLock(wbr) */
3961 + SiMustWriteLock(sb);
3962 + for (i = 0; i < AuBrWh_Last; i++) {
3963 + dput(wbr->wbr_wh[i]);
3964 + wbr->wbr_wh[i] = NULL;
3968 + err = test_children_busy(root, bindex, verbose);
3969 + if (unlikely(err)) {
3978 + * now we confirmed the branch is deletable.
3979 + * let's free the remaining opened dirs on the branch.
3981 + di_write_unlock(root);
3982 + br_del_file(to_free, opened, br_id);
3983 + di_write_lock_child(root);
3986 + sysaufs_brs_del(sb, bindex); /* remove successors */
3987 + dbgaufs_xino_del(br); /* remove one */
3988 + au_br_do_del(sb, bindex, br);
3989 + sysaufs_brs_add(sb, bindex); /* append successors */
3990 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
3993 + au_cpup_attr_all(d_inode(root), /*force*/1);
3994 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3996 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
3997 + if (au_opt_test(mnt_flags, PLINK))
3998 + au_plink_half_refresh(sb, br_id);
4000 + goto out; /* success */
4004 + rerr = au_br_init_wh(sb, br, br->br_perm);
4006 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4007 + del->pathname, rerr);
4010 + au_farray_free(to_free, opened);
4014 +/* ---------------------------------------------------------------------- */
4016 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4019 + aufs_bindex_t btop, bbot;
4020 + struct aufs_ibusy ibusy;
4021 + struct inode *inode, *h_inode;
4024 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4027 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4029 + /* VERIFY_WRITE */
4030 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4031 + if (unlikely(err)) {
4038 + si_read_lock(sb, AuLock_FLUSH);
4039 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4043 + ibusy.h_ino = 0; /* invalid */
4044 + inode = ilookup(sb, ibusy.ino);
4046 + || inode->i_ino == AUFS_ROOT_INO
4047 + || au_is_bad_inode(inode))
4050 + ii_read_lock_child(inode);
4051 + btop = au_ibtop(inode);
4052 + bbot = au_ibbot(inode);
4053 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4054 + h_inode = au_h_iptr(inode, ibusy.bindex);
4055 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4056 + ibusy.h_ino = h_inode->i_ino;
4058 + ii_read_unlock(inode);
4062 + si_read_unlock(sb);
4064 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4065 + if (unlikely(err)) {
4074 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4076 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4079 +#ifdef CONFIG_COMPAT
4080 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4082 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4086 +/* ---------------------------------------------------------------------- */
4089 + * change a branch permission
4092 +static void au_warn_ima(void)
4095 + /* since it doesn't support mark_files_ro() */
4096 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4100 +static int do_need_sigen_inc(int a, int b)
4102 + return au_br_whable(a) && !au_br_whable(b);
4105 +static int need_sigen_inc(int old, int new)
4107 + return do_need_sigen_inc(old, new)
4108 + || do_need_sigen_inc(new, old);
4111 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4114 + unsigned int mnt_flags;
4115 + unsigned long long ull, max;
4116 + aufs_bindex_t br_id;
4117 + unsigned char verbose, writer;
4118 + struct file *file, *hf, **array;
4119 + struct au_hfile *hfile;
4120 + struct inode *h_inode;
4122 + mnt_flags = au_mntflags(sb);
4123 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4125 + array = au_farray_alloc(sb, &max);
4126 + err = PTR_ERR(array);
4127 + if (IS_ERR(array))
4131 + br_id = au_sbr_id(sb, bindex);
4132 + for (ull = 0; ull < max; ull++) {
4133 + file = array[ull];
4134 + if (unlikely(!file))
4137 + /* AuDbg("%pD\n", file); */
4138 + fi_read_lock(file);
4139 + if (unlikely(au_test_mmapped(file))) {
4141 + AuVerbose(verbose, "mmapped %pD\n", file);
4143 + FiMustNoWaiters(file);
4144 + fi_read_unlock(file);
4148 + hfile = &au_fi(file)->fi_htop;
4149 + hf = hfile->hf_file;
4150 + if (!d_is_reg(file->f_path.dentry)
4151 + || !(file->f_mode & FMODE_WRITE)
4152 + || hfile->hf_br->br_id != br_id
4153 + || !(hf->f_mode & FMODE_WRITE))
4154 + array[ull] = NULL;
4160 + FiMustNoWaiters(file);
4161 + fi_read_unlock(file);
4169 + for (ull = 0; ull < max; ull++) {
4170 + file = array[ull];
4174 + /* todo: already flushed? */
4176 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4177 + * approach which resets f_mode and calls mnt_drop_write() and
4178 + * file_release_write() for each file, because the branch
4179 + * attribute in aufs world is totally different from the native
4182 + /* fi_read_lock(file); */
4183 + hfile = &au_fi(file)->fi_htop;
4184 + hf = hfile->hf_file;
4185 + /* fi_read_unlock(file); */
4186 + spin_lock(&hf->f_lock);
4187 + writer = !!(hf->f_mode & FMODE_WRITER);
4188 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4189 + spin_unlock(&hf->f_lock);
4191 + h_inode = file_inode(hf);
4192 + if (hf->f_mode & FMODE_READ)
4193 + i_readcount_inc(h_inode);
4194 + put_write_access(h_inode);
4195 + __mnt_drop_write(hf->f_path.mnt);
4200 + au_farray_free(array, max);
4206 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4210 + aufs_bindex_t bindex;
4211 + struct dentry *root;
4212 + struct au_branch *br;
4213 + struct au_br_fhsm *bf;
4215 + root = sb->s_root;
4216 + bindex = au_find_dbindex(root, mod->h_root);
4219 + return 0; /* success */
4221 + pr_err("%s no such branch\n", mod->path);
4224 + AuDbg("bindex b%d\n", bindex);
4226 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4227 + if (unlikely(err))
4230 + br = au_sbr(sb, bindex);
4231 + AuDebugOn(mod->h_root != au_br_dentry(br));
4232 + if (br->br_perm == mod->perm)
4233 + return 0; /* success */
4235 + /* pre-allocate for non-fhsm --> fhsm */
4237 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4238 + err = au_fhsm_br_alloc(br);
4239 + if (unlikely(err))
4242 + br->br_fhsm = NULL;
4245 + if (au_br_writable(br->br_perm)) {
4246 + /* remove whiteout base */
4247 + err = au_br_init_wh(sb, br, mod->perm);
4248 + if (unlikely(err))
4251 + if (!au_br_writable(mod->perm)) {
4252 + /* rw --> ro, file might be mmapped */
4253 + DiMustNoWaiters(root);
4254 + IiMustNoWaiters(d_inode(root));
4255 + di_write_unlock(root);
4256 + err = au_br_mod_files_ro(sb, bindex);
4257 + /* aufs_write_lock() calls ..._child() */
4258 + di_write_lock_child(root);
4260 + if (unlikely(err)) {
4262 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4265 + rerr = au_wbr_init(br, sb, br->br_perm);
4266 + if (unlikely(rerr)) {
4267 + AuIOErr("nested error %d (%d)\n",
4269 + br->br_perm = mod->perm;
4273 + } else if (au_br_writable(mod->perm)) {
4276 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4278 + err = au_wbr_init(br, sb, mod->perm);
4279 + if (unlikely(err)) {
4280 + au_kfree_rcu(br->br_wbr);
4281 + br->br_wbr = NULL;
4285 + if (unlikely(err))
4288 + if (au_br_fhsm(br->br_perm)) {
4289 + if (!au_br_fhsm(mod->perm)) {
4290 + /* fhsm --> non-fhsm */
4291 + au_br_fhsm_fin(br->br_fhsm);
4292 + au_kfree_rcu(br->br_fhsm);
4293 + br->br_fhsm = NULL;
4295 + } else if (au_br_fhsm(mod->perm))
4296 + /* non-fhsm --> fhsm */
4299 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4300 + br->br_perm = mod->perm;
4301 + goto out; /* success */
4304 + au_kfree_try_rcu(bf);
4310 +/* ---------------------------------------------------------------------- */
4312 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4315 + struct kstatfs kstfs;
4317 + err = vfs_statfs(&br->br_path, &kstfs);
4319 + stfs->f_blocks = kstfs.f_blocks;
4320 + stfs->f_bavail = kstfs.f_bavail;
4321 + stfs->f_files = kstfs.f_files;
4322 + stfs->f_ffree = kstfs.f_ffree;
4327 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4328 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4329 +++ linux/fs/aufs/branch.h 2022-11-05 23:02:18.959222617 +0100
4331 +/* SPDX-License-Identifier: GPL-2.0 */
4333 + * Copyright (C) 2005-2022 Junjiro R. Okajima
4335 + * This program is free software; you can redistribute it and/or modify
4336 + * it under the terms of the GNU General Public License as published by
4337 + * the Free Software Foundation; either version 2 of the License, or
4338 + * (at your option) any later version.
4340 + * This program is distributed in the hope that it will be useful,
4341 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4342 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4343 + * GNU General Public License for more details.
4345 + * You should have received a copy of the GNU General Public License
4346 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4350 + * branch filesystems and xino for them
4353 +#ifndef __AUFS_BRANCH_H__
4354 +#define __AUFS_BRANCH_H__
4358 +#include <linux/mount.h>
4359 +#include "dirren.h"
4365 +/* ---------------------------------------------------------------------- */
4369 + struct file **xi_file;
4370 + unsigned int xi_nfile;
4376 + /* reserved for future use */
4377 + /* unsigned long *bitmap; */
4378 + wait_queue_head_t wqh;
4381 + struct mutex xi_mtx; /* protects xi_file array */
4382 + struct hlist_bl_head xi_writing;
4384 + atomic_t xi_truncating;
4386 + struct kref xi_kref;
4389 +/* File-based Hierarchical Storage Management */
4390 +struct au_br_fhsm {
4391 +#ifdef CONFIG_AUFS_FHSM
4392 + struct mutex bf_lock;
4393 + unsigned long bf_jiffy;
4394 + struct aufs_stfs bf_stfs;
4399 +/* members for writable branch only */
4400 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4402 + struct au_rwsem wbr_wh_rwsem;
4403 + struct dentry *wbr_wh[AuBrWh_Last];
4404 + atomic_t wbr_wh_running;
4405 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4406 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4407 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4410 + unsigned long long wbr_bytes;
4413 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4414 +#define AuBrDynOp (AuDyLast * 4)
4416 +#ifdef CONFIG_AUFS_HFSNOTIFY
4417 +/* support for asynchronous destruction */
4418 +struct au_br_hfsnotify {
4419 + struct fsnotify_group *hfsn_group;
4423 +/* sysfs entries */
4424 +struct au_brsysfs {
4426 + struct attribute attr;
4435 +/* protected by superblock rwsem */
4437 + struct au_xino *br_xino;
4439 + aufs_bindex_t br_id;
4442 + struct path br_path;
4443 + spinlock_t br_dykey_lock;
4444 + struct au_dykey *br_dykey[AuBrDynOp];
4445 + au_lcnt_t br_nfiles; /* opened files */
4446 + au_lcnt_t br_count; /* in-use for other */
4448 + struct au_wbr *br_wbr;
4449 + struct au_br_fhsm *br_fhsm;
4451 +#ifdef CONFIG_AUFS_HFSNOTIFY
4452 + struct au_br_hfsnotify *br_hfsn;
4455 +#ifdef CONFIG_SYSFS
4456 + /* entries under sysfs per mount-point */
4457 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4460 +#ifdef CONFIG_DEBUG_FS
4461 + struct dentry *br_dbgaufs; /* xino */
4464 + struct au_dr_br br_dirren;
4467 +/* ---------------------------------------------------------------------- */
4469 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4471 + return br->br_path.mnt;
4474 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4476 + return br->br_path.dentry;
4479 +static inline struct user_namespace *au_br_userns(struct au_branch *br)
4481 + return mnt_user_ns(br->br_path.mnt);
4484 +static inline struct super_block *au_br_sb(struct au_branch *br)
4486 + return au_br_mnt(br)->mnt_sb;
4489 +static inline int au_br_rdonly(struct au_branch *br)
4491 + return (sb_rdonly(au_br_sb(br))
4492 + || !au_br_writable(br->br_perm))
4496 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4498 +#ifdef CONFIG_AUFS_HNOTIFY
4499 + return !(brperm & AuBrPerm_RR);
4505 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4507 + int err, exec_flag;
4510 + exec_flag = oflag & __FMODE_EXEC;
4511 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4517 +static inline void au_xino_get(struct au_branch *br)
4519 + struct au_xino *xi;
4523 + kref_get(&xi->xi_kref);
4526 +static inline int au_xino_count(struct au_branch *br)
4529 + struct au_xino *xi;
4534 + v = kref_read(&xi->xi_kref);
4539 +/* ---------------------------------------------------------------------- */
4543 +void au_br_free(struct au_sbinfo *sinfo);
4544 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4546 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4548 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4549 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4550 +#ifdef CONFIG_COMPAT
4551 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4554 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4557 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4560 +static const loff_t au_loff_max = LLONG_MAX;
4562 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4563 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4565 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4566 + struct file *copy_src);
4568 + struct au_xino *xi; /* switch between xino and xigen */
4570 + struct path *base;
4571 + struct file *copy_src;
4573 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4575 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4577 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4579 +ssize_t xino_fread(struct file *file, void *buf, size_t size, loff_t *pos);
4580 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos);
4582 +int au_xib_trunc(struct super_block *sb);
4583 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4585 +struct au_xino *au_xino_alloc(unsigned int nfile);
4586 +int au_xino_put(struct au_branch *br);
4587 +struct file *au_xino_file1(struct au_xino *xi);
4589 +struct au_opt_xino;
4590 +void au_xino_clr(struct super_block *sb);
4591 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4592 +struct file *au_xino_def(struct super_block *sb);
4593 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4594 + struct path *base);
4596 +ino_t au_xino_new_ino(struct super_block *sb);
4597 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4599 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4600 + ino_t h_ino, int idx);
4601 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4604 +int au_xino_path(struct seq_file *seq, struct file *file);
4606 +/* ---------------------------------------------------------------------- */
4608 +/* @idx is signed to accept -1 meaning the first file */
4609 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4611 + struct file *file;
4618 + if (idx < xi->xi_nfile)
4619 + file = xi->xi_file[idx];
4621 + file = au_xino_file1(xi);
4627 +/* ---------------------------------------------------------------------- */
4629 +/* Superblock to branch */
4631 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4633 + return au_sbr(sb, bindex)->br_id;
4637 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4639 + return au_br_mnt(au_sbr(sb, bindex));
4643 +struct user_namespace *au_sbr_userns(struct super_block *sb, aufs_bindex_t bindex)
4645 + return au_br_userns(au_sbr(sb, bindex));
4649 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4651 + return au_br_sb(au_sbr(sb, bindex));
4654 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4656 + return au_sbr(sb, bindex)->br_perm;
4659 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4661 + return au_br_whable(au_sbr_perm(sb, bindex));
4664 +/* ---------------------------------------------------------------------- */
4666 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4667 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4668 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4669 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4671 +#define wbr_wh_read_trylock_nested(wbr) \
4672 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4673 +#define wbr_wh_write_trylock_nested(wbr) \
4674 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4677 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4678 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4679 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4681 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4682 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4683 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4685 +/* ---------------------------------------------------------------------- */
4687 +#ifdef CONFIG_AUFS_FHSM
4688 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4690 + mutex_init(&brfhsm->bf_lock);
4691 + brfhsm->bf_jiffy = 0;
4692 + brfhsm->bf_readable = 0;
4695 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4697 + mutex_destroy(&brfhsm->bf_lock);
4700 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4701 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4704 +#endif /* __KERNEL__ */
4705 +#endif /* __AUFS_BRANCH_H__ */
4706 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4707 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4708 +++ linux/fs/aufs/conf.mk 2022-11-05 23:02:18.959222617 +0100
4710 +# SPDX-License-Identifier: GPL-2.0
4712 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4716 +AuConfStr += ${1}=${${1}}
4720 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4722 + HNOTIFY HFSNOTIFY \
4734 +$(foreach i, ${AuConfAll}, \
4735 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4737 +AuConfName = ${obj}/conf.str
4738 +${AuConfName}.tmp: FORCE
4739 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4740 +${AuConfName}: ${AuConfName}.tmp
4741 + @diff -q $< $@ > /dev/null 2>&1 || { \
4742 + echo ' GEN ' $@; \
4746 +clean-files += ${AuConfName} ${AuConfName}.tmp
4747 +${obj}/sysfs.o: ${AuConfName}
4749 +-include ${srctree}/${src}/conf_priv.mk
4750 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4751 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4752 +++ linux/fs/aufs/cpup.c 2022-11-05 23:02:18.962555950 +0100
4754 +// SPDX-License-Identifier: GPL-2.0
4756 + * Copyright (C) 2005-2022 Junjiro R. Okajima
4758 + * This program is free software; you can redistribute it and/or modify
4759 + * it under the terms of the GNU General Public License as published by
4760 + * the Free Software Foundation; either version 2 of the License, or
4761 + * (at your option) any later version.
4763 + * This program is distributed in the hope that it will be useful,
4764 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4765 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4766 + * GNU General Public License for more details.
4768 + * You should have received a copy of the GNU General Public License
4769 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4773 + * copy-up functions, see wbr_policy.c for copy-down
4776 +#include <linux/fs_stack.h>
4777 +#include <linux/mm.h>
4778 +#include <linux/task_work.h>
4781 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4783 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4784 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4786 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4788 + dst->i_flags |= iflags & ~mask;
4789 + if (au_test_fs_notime(dst->i_sb))
4790 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4793 +void au_cpup_attr_timesizes(struct inode *inode)
4795 + struct inode *h_inode;
4797 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4798 + fsstack_copy_attr_times(inode, h_inode);
4799 + fsstack_copy_inode_size(inode, h_inode);
4802 +void au_cpup_attr_nlink(struct inode *inode, int force)
4804 + struct inode *h_inode;
4805 + struct super_block *sb;
4806 + aufs_bindex_t bindex, bbot;
4809 + bindex = au_ibtop(inode);
4810 + h_inode = au_h_iptr(inode, bindex);
4812 + && !S_ISDIR(h_inode->i_mode)
4813 + && au_opt_test(au_mntflags(sb), PLINK)
4814 + && au_plink_test(inode))
4818 + * 0 can happen in revalidating.
4819 + * h_inode->i_mutex may not be held here, but it is harmless since once
4820 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4822 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4823 + * the incorrect link count.
4825 + set_nlink(inode, h_inode->i_nlink);
4828 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4829 + * it may includes whplink directory.
4831 + if (S_ISDIR(h_inode->i_mode)) {
4832 + bbot = au_ibbot(inode);
4833 + for (bindex++; bindex <= bbot; bindex++) {
4834 + h_inode = au_h_iptr(inode, bindex);
4836 + au_add_nlink(inode, h_inode);
4841 +void au_cpup_attr_changeable(struct inode *inode)
4843 + struct inode *h_inode;
4845 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4846 + inode->i_mode = h_inode->i_mode;
4847 + inode->i_uid = h_inode->i_uid;
4848 + inode->i_gid = h_inode->i_gid;
4849 + au_cpup_attr_timesizes(inode);
4850 + au_cpup_attr_flags(inode, h_inode->i_flags);
4853 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4855 + struct au_iinfo *iinfo = au_ii(inode);
4857 + IiMustWriteLock(inode);
4859 + iinfo->ii_higen = h_inode->i_generation;
4860 + iinfo->ii_hsb1 = h_inode->i_sb;
4863 +void au_cpup_attr_all(struct inode *inode, int force)
4865 + struct inode *h_inode;
4867 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4868 + au_cpup_attr_changeable(inode);
4869 + if (inode->i_nlink > 0)
4870 + au_cpup_attr_nlink(inode, force);
4871 + inode->i_rdev = h_inode->i_rdev;
4872 + inode->i_blkbits = h_inode->i_blkbits;
4873 + au_cpup_igen(inode, h_inode);
4876 +/* ---------------------------------------------------------------------- */
4878 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4880 +/* keep the timestamps of the parent dir when cpup */
4881 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4882 + struct path *h_path)
4884 + struct inode *h_inode;
4886 + dt->dt_dentry = dentry;
4887 + dt->dt_h_path = *h_path;
4888 + h_inode = d_inode(h_path->dentry);
4889 + dt->dt_atime = h_inode->i_atime;
4890 + dt->dt_mtime = h_inode->i_mtime;
4894 +void au_dtime_revert(struct au_dtime *dt)
4896 + struct iattr attr;
4899 + attr.ia_atime = dt->dt_atime;
4900 + attr.ia_mtime = dt->dt_mtime;
4901 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4902 + | ATTR_ATIME | ATTR_ATIME_SET;
4904 + /* no delegation since this is a directory */
4905 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4906 + if (unlikely(err))
4907 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4910 +/* ---------------------------------------------------------------------- */
4912 +/* internal use only */
4913 +struct au_cpup_reg_attr {
4916 + unsigned int iflags; /* inode->i_flags */
4919 +static noinline_for_stack
4920 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct path *h_src,
4921 + struct au_cpup_reg_attr *h_src_attr)
4923 + int err, sbits, icex;
4924 + unsigned int mnt_flags;
4925 + unsigned char verbose;
4927 + struct path h_path;
4928 + struct inode *h_isrc, *h_idst;
4929 + struct kstat *h_st;
4930 + struct au_branch *br;
4932 + br = au_sbr(dst->d_sb, bindex);
4933 + h_path.mnt = au_br_mnt(br);
4934 + h_path.dentry = au_h_dptr(dst, bindex);
4935 + h_idst = d_inode(h_path.dentry);
4936 + h_isrc = d_inode(h_src->dentry);
4937 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4938 + | ATTR_ATIME | ATTR_MTIME
4939 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4940 + if (h_src_attr && h_src_attr->valid) {
4941 + h_st = &h_src_attr->st;
4942 + ia.ia_uid = h_st->uid;
4943 + ia.ia_gid = h_st->gid;
4944 + ia.ia_atime = h_st->atime;
4945 + ia.ia_mtime = h_st->mtime;
4946 + if (h_idst->i_mode != h_st->mode
4947 + && !S_ISLNK(h_idst->i_mode)) {
4948 + ia.ia_valid |= ATTR_MODE;
4949 + ia.ia_mode = h_st->mode;
4951 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4952 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4954 + ia.ia_uid = h_isrc->i_uid;
4955 + ia.ia_gid = h_isrc->i_gid;
4956 + ia.ia_atime = h_isrc->i_atime;
4957 + ia.ia_mtime = h_isrc->i_mtime;
4958 + if (h_idst->i_mode != h_isrc->i_mode
4959 + && !S_ISLNK(h_idst->i_mode)) {
4960 + ia.ia_valid |= ATTR_MODE;
4961 + ia.ia_mode = h_isrc->i_mode;
4963 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4964 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4966 + /* no delegation since it is just created */
4967 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4969 + /* is this nfs only? */
4970 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4971 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4972 + ia.ia_mode = h_isrc->i_mode;
4973 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4976 + icex = br->br_perm & AuBrAttr_ICEX;
4978 + mnt_flags = au_mntflags(dst->d_sb);
4979 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4980 + err = au_cpup_xattr(&h_path, h_src, icex, verbose);
4986 +/* ---------------------------------------------------------------------- */
4988 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4989 + char *buf, unsigned long blksize)
4992 + size_t sz, rbytes, wbytes;
4993 + unsigned char all_zero;
4995 + struct inode *h_inode;
4996 + /* reduce stack usage */
4999 + zp = page_address(ZERO_PAGE(0));
5000 + if (unlikely(!zp))
5001 + return -ENOMEM; /* possible? */
5006 + AuDbg("len %lld\n", len);
5008 + if (len < blksize)
5012 + /* todo: signal_pending? */
5013 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5014 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5017 + if (unlikely(err < 0))
5021 + if (len >= rbytes && rbytes == blksize)
5022 + all_zero = !memcmp(buf, zp, rbytes);
5029 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5031 + /* todo: signal_pending? */
5032 + if (unlikely(err == -EAGAIN || err == -EINTR))
5034 + if (unlikely(err < 0))
5039 + if (unlikely(err < 0))
5045 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5047 + if (unlikely(res < 0))
5054 + /* the last block may be a hole */
5055 + if (!err && all_zero) {
5056 + AuLabel(last hole);
5059 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5060 + /* nfs requires this step to make last hole */
5061 + /* is this only nfs? */
5063 + /* todo: signal_pending? */
5064 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5065 + } while (err == -EAGAIN || err == -EINTR);
5072 + ia->ia_size = dst->f_pos;
5073 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5074 + ia->ia_file = dst;
5075 + h_inode = file_inode(dst);
5076 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5077 + /* no delegation since it is just created */
5078 + err = vfsub_notify_change(&dst->f_path, ia,
5079 + /*delegated*/NULL);
5080 + inode_unlock(h_inode);
5087 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5090 + unsigned long blksize;
5091 + unsigned char do_kfree;
5093 + struct super_block *h_sb;
5096 + h_sb = file_inode(dst)->i_sb;
5097 + blksize = h_sb->s_blocksize;
5098 + if (!blksize || PAGE_SIZE < blksize)
5099 + blksize = PAGE_SIZE;
5100 + AuDbg("blksize %lu\n", blksize);
5101 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5103 + buf = kmalloc(blksize, GFP_NOFS);
5105 + buf = (void *)__get_free_page(GFP_NOFS);
5106 + if (unlikely(!buf))
5109 + if (len > (1 << 22))
5110 + AuDbg("copying a large file %lld\n", (long long)len);
5114 + err = au_do_copy_file(dst, src, len, buf, blksize);
5116 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5117 + au_kfree_do_rcu(buf);
5119 + free_page((unsigned long)buf);
5125 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5128 + struct super_block *h_src_sb;
5129 + struct inode *h_src_inode;
5131 + h_src_inode = file_inode(src);
5132 + h_src_sb = h_src_inode->i_sb;
5134 + /* XFS acquires inode_lock */
5135 + if (!au_test_xfs(h_src_sb))
5136 + err = au_copy_file(dst, src, len);
5138 + inode_unlock_shared(h_src_inode);
5139 + err = au_copy_file(dst, src, len);
5140 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5146 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5150 + struct super_block *h_src_sb;
5151 + struct inode *h_src_inode;
5153 + h_src_inode = file_inode(src);
5154 + h_src_sb = h_src_inode->i_sb;
5155 + if (h_src_sb != file_inode(dst)->i_sb
5156 + || !dst->f_op->remap_file_range) {
5157 + err = au_do_copy(dst, src, len);
5161 + if (!au_test_nfs(h_src_sb)) {
5162 + inode_unlock_shared(h_src_inode);
5163 + lo = vfsub_clone_file_range(src, dst, len);
5164 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5166 + lo = vfsub_clone_file_range(src, dst, len);
5169 + goto out; /* success */
5170 + } else if (lo >= 0)
5171 + /* todo: possible? */
5172 + /* paritially succeeded */
5173 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5174 + else if (lo != -EOPNOTSUPP) {
5175 + /* older XFS has a condition in cloning */
5180 + /* the backend fs on NFS may not support cloning */
5181 + err = au_do_copy(dst, src, len);
5189 + * to support a sparse file which is opened with O_APPEND,
5190 + * we need to close the file.
5192 +static int au_cp_regular(struct au_cp_generic *cpg)
5195 + enum { SRC, DST };
5197 + aufs_bindex_t bindex;
5198 + unsigned int flags;
5199 + struct dentry *dentry;
5201 + struct file *file;
5204 + .bindex = cpg->bsrc,
5205 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5208 + .bindex = cpg->bdst,
5209 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5210 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5213 + struct au_branch *br;
5214 + struct super_block *sb, *h_src_sb;
5215 + struct inode *h_src_inode;
5216 + struct task_struct *tsk = current;
5218 + /* bsrc branch can be ro/rw. */
5219 + sb = cpg->dentry->d_sb;
5221 + for (i = 0; i < 2; i++, f++) {
5222 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5223 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5224 + /*file*/NULL, f->force_wr);
5225 + if (IS_ERR(f->file)) {
5226 + err = PTR_ERR(f->file);
5234 + /* try stopping to update while we copyup */
5235 + h_src_inode = d_inode(file[SRC].dentry);
5236 + h_src_sb = h_src_inode->i_sb;
5237 + if (!au_test_nfs(h_src_sb))
5238 + IMustLock(h_src_inode);
5239 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5241 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5242 + if (tsk->flags & PF_KTHREAD)
5243 + __fput_sync(file[DST].file);
5245 + /* it happened actually */
5246 + fput(file[DST].file);
5249 + * we have to call both since we don't know which place the file
5253 + flush_delayed_fput();
5255 + br = au_sbr(sb, file[DST].bindex);
5256 + au_lcnt_dec(&br->br_nfiles);
5259 + fput(file[SRC].file);
5260 + br = au_sbr(sb, file[SRC].bindex);
5261 + au_lcnt_dec(&br->br_nfiles);
5266 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5267 + struct au_cpup_reg_attr *h_src_attr)
5271 + struct path h_path;
5272 + struct inode *h_src_inode, *h_dst_inode;
5275 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5276 + l = i_size_read(h_src_inode);
5277 + if (cpg->len == -1 || l < cpg->len)
5280 + /* try stopping to update while we are referencing */
5281 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5282 + au_pin_hdir_unlock(cpg->pin);
5284 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5285 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5286 + h_src_attr->iflags = h_src_inode->i_flags;
5287 + if (!au_test_nfs(h_src_inode->i_sb))
5288 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5290 + inode_unlock_shared(h_src_inode);
5291 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5292 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5294 + if (unlikely(err)) {
5295 + inode_unlock_shared(h_src_inode);
5298 + h_src_attr->valid = 1;
5299 + if (!au_test_nfs(h_src_inode->i_sb)) {
5300 + err = au_cp_regular(cpg);
5301 + inode_unlock_shared(h_src_inode);
5303 + inode_unlock_shared(h_src_inode);
5304 + err = au_cp_regular(cpg);
5306 + rerr = au_pin_hdir_relock(cpg->pin);
5310 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5311 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5312 + h_dst_inode = d_inode(h_path.dentry);
5313 + spin_lock(&h_dst_inode->i_lock);
5314 + h_dst_inode->i_state |= I_LINKABLE;
5315 + spin_unlock(&h_dst_inode->i_lock);
5322 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5323 + struct inode *h_dir)
5326 + DEFINE_DELAYED_CALL(done);
5329 + sym = vfs_get_link(h_src, &done);
5330 + err = PTR_ERR(sym);
5334 + err = vfsub_symlink(h_dir, h_path, sym);
5337 + do_delayed_call(&done);
5342 + * regardless 'acl' option, reset all ACL.
5343 + * All ACL will be copied up later from the original entry on the lower branch.
5345 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5348 + struct dentry *h_dentry;
5349 + struct inode *h_inode;
5350 + struct user_namespace *h_userns;
5352 + h_userns = mnt_user_ns(h_path->mnt);
5353 + h_dentry = h_path->dentry;
5354 + h_inode = d_inode(h_dentry);
5355 + /* forget_all_cached_acls(h_inode)); */
5356 + err = vfsub_removexattr(h_userns, h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5358 + if (err == -EOPNOTSUPP)
5361 + err = vfsub_acl_chmod(h_userns, h_inode, mode);
5367 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5368 + struct inode *h_dir, struct path *h_path)
5371 + struct inode *dir, *inode;
5372 + struct user_namespace *h_userns;
5374 + h_userns = mnt_user_ns(h_path->mnt);
5375 + err = vfsub_removexattr(h_userns, h_path->dentry,
5376 + XATTR_NAME_POSIX_ACL_DEFAULT);
5378 + if (err == -EOPNOTSUPP)
5380 + if (unlikely(err))
5384 + * strange behaviour from the users view,
5385 + * particularly setattr case
5387 + dir = d_inode(dst_parent);
5388 + if (au_ibtop(dir) == cpg->bdst)
5389 + au_cpup_attr_nlink(dir, /*force*/1);
5390 + inode = d_inode(cpg->dentry);
5391 + au_cpup_attr_nlink(inode, /*force*/1);
5397 +static noinline_for_stack
5398 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5399 + struct au_cpup_reg_attr *h_src_attr)
5403 + unsigned int mnt_flags;
5404 + unsigned char isdir, isreg, force;
5405 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5406 + struct au_dtime dt;
5407 + struct path h_path;
5408 + struct dentry *h_src, *h_dst, *h_parent;
5409 + struct inode *h_inode, *h_dir;
5410 + struct super_block *sb;
5412 + /* bsrc branch can be ro/rw. */
5413 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5414 + h_inode = d_inode(h_src);
5415 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5417 + /* try stopping to be referenced while we are creating */
5418 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5419 + if (au_ftest_cpup(cpg->flags, RENAME))
5420 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5421 + AUFS_WH_PFX_LEN));
5422 + h_parent = h_dst->d_parent; /* dir inode is locked */
5423 + h_dir = d_inode(h_parent);
5425 + AuDebugOn(h_parent != h_dst->d_parent);
5427 + sb = cpg->dentry->d_sb;
5428 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5430 + h_path.dentry = h_parent;
5431 + au_dtime_store(&dt, dst_parent, &h_path);
5433 + h_path.dentry = h_dst;
5437 + mode = h_inode->i_mode;
5438 + switch (mode & S_IFMT) {
5441 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5443 + err = au_do_cpup_regular(cpg, h_src_attr);
5447 + err = vfsub_mkdir(h_dir, &h_path, mode);
5449 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5452 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5456 + AuDebugOn(!capable(CAP_MKNOD));
5460 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5463 + AuIOErr("Unknown inode type 0%o\n", mode);
5467 + err = au_reset_acl(h_dir, &h_path, mode);
5469 + mnt_flags = au_mntflags(sb);
5470 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5472 + && au_opt_test(mnt_flags, XINO)
5473 + && (h_inode->i_nlink == 1
5474 + || (h_inode->i_state & I_LINKABLE))
5475 + /* todo: unnecessary? */
5476 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5477 + && cpg->bdst < cpg->bsrc
5478 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5479 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5480 + /* ignore this error */
5485 + force = !!cpg->len;
5486 + if (cpg->len == -1)
5487 + force = !!i_size_read(h_inode);
5489 + au_fhsm_wrote(sb, cpg->bdst, force);
5493 + au_dtime_revert(&dt);
5497 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5500 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5501 + struct path h_ppath;
5502 + struct inode *h_dir;
5503 + aufs_bindex_t bdst;
5505 + dentry = cpg->dentry;
5507 + h_ppath.mnt = au_sbr_mnt(dentry->d_sb, bdst);
5508 + h_dentry = au_h_dptr(dentry, bdst);
5509 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5511 + au_set_h_dptr(dentry, bdst, NULL);
5512 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5514 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5515 + au_set_h_dptr(dentry, bdst, h_dentry);
5518 + parent = dget_parent(dentry);
5519 + h_ppath.dentry = au_h_dptr(parent, bdst);
5521 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, &h_ppath);
5522 + if (IS_ERR(h_path->dentry))
5523 + err = PTR_ERR(h_path->dentry);
5525 + if (unlikely(err))
5528 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5529 + h_dir = d_inode(h_parent);
5531 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5532 + /* no delegation since it is just created */
5533 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5535 + dput(h_path->dentry);
5542 + * copyup the @dentry from @bsrc to @bdst.
5543 + * the caller must set the both of lower dentries.
5544 + * @len is for truncating when it is -1 copyup the entire file.
5545 + * in link/rename cases, @dst_parent may be different from the real one.
5546 + * basic->bsrc can be larger than basic->bdst.
5547 + * aufs doesn't touch the credential so
5548 + * security_inode_copy_up{,_xattr}() are unnecessary.
5550 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5553 + aufs_bindex_t old_ibtop;
5554 + unsigned char isdir, plink;
5555 + struct dentry *h_src, *h_dst, *h_parent;
5556 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5557 + struct super_block *sb;
5558 + struct au_branch *br;
5559 + struct path h_src_path;
5560 + /* to reduce stack size */
5562 + struct au_dtime dt;
5563 + struct path h_path;
5564 + struct au_cpup_reg_attr h_src_attr;
5568 + a = kmalloc(sizeof(*a), GFP_NOFS);
5571 + a->h_src_attr.valid = 0;
5573 + sb = cpg->dentry->d_sb;
5574 + br = au_sbr(sb, cpg->bdst);
5575 + a->h_path.mnt = au_br_mnt(br);
5576 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5577 + h_parent = h_dst->d_parent; /* dir inode is locked */
5578 + h_dir = d_inode(h_parent);
5581 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5582 + inode = d_inode(cpg->dentry);
5585 + dst_parent = dget_parent(cpg->dentry);
5589 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5590 + dst_inode = au_h_iptr(inode, cpg->bdst);
5592 + if (unlikely(!plink)) {
5594 + AuIOErr("hi%lu(i%lu) exists on b%d "
5595 + "but plink is disabled\n",
5596 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5600 + if (dst_inode->i_nlink) {
5601 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5603 + h_src = au_plink_lkup(inode, cpg->bdst);
5604 + err = PTR_ERR(h_src);
5605 + if (IS_ERR(h_src))
5607 + if (unlikely(d_is_negative(h_src))) {
5609 + AuIOErr("i%lu exists on b%d "
5610 + "but not pseudo-linked\n",
5611 + inode->i_ino, cpg->bdst);
5617 + a->h_path.dentry = h_parent;
5618 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5621 + a->h_path.dentry = h_dst;
5623 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5624 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5625 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5627 + au_dtime_revert(&a->dt);
5628 + if (unlikely(err == -EWOULDBLOCK)) {
5629 + pr_warn("cannot retry for NFSv4 delegation"
5630 + " for an internal link\n");
5636 + /* todo: cpup_wh_file? */
5638 + au_update_ibrange(inode, /*do_put_zero*/1);
5641 + isdir = S_ISDIR(inode->i_mode);
5642 + old_ibtop = au_ibtop(inode);
5643 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5644 + if (unlikely(err))
5646 + dst_inode = d_inode(h_dst);
5647 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5648 + /* todo: necessary? */
5649 + /* au_pin_hdir_unlock(cpg->pin); */
5651 + h_src_path.dentry = h_src;
5652 + h_src_path.mnt = au_sbr_mnt(sb, cpg->bsrc);
5653 + err = cpup_iattr(cpg->dentry, cpg->bdst, &h_src_path, &a->h_src_attr);
5654 + if (unlikely(err)) {
5655 + /* todo: necessary? */
5656 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5657 + inode_unlock(dst_inode);
5661 + if (cpg->bdst < old_ibtop) {
5662 + if (S_ISREG(inode->i_mode)) {
5663 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5664 + if (unlikely(err)) {
5665 + /* ignore an error */
5666 + /* au_pin_hdir_relock(cpg->pin); */
5667 + inode_unlock(dst_inode);
5671 + au_set_ibtop(inode, cpg->bdst);
5673 + au_set_ibbot(inode, cpg->bdst);
5674 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5675 + au_hi_flags(inode, isdir));
5677 + /* todo: necessary? */
5678 + /* err = au_pin_hdir_relock(cpg->pin); */
5679 + inode_unlock(dst_inode);
5680 + if (unlikely(err))
5683 + src_inode = d_inode(h_src);
5685 + && (src_inode->i_nlink > 1
5686 + || src_inode->i_state & I_LINKABLE)
5688 + au_plink_append(inode, cpg->bdst, h_dst);
5690 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5691 + a->h_path.dentry = h_dst;
5692 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5695 + goto out_parent; /* success */
5699 + a->h_path.dentry = h_parent;
5700 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5701 + a->h_path.dentry = h_dst;
5703 + if (d_is_positive(h_dst)) {
5705 + /* no delegation since it is just created */
5706 + rerr = vfsub_unlink(h_dir, &a->h_path,
5707 + /*delegated*/NULL, /*force*/0);
5709 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5711 + au_dtime_revert(&a->dt);
5713 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5723 +#if 0 /* reserved */
5724 +struct au_cpup_single_args {
5726 + struct au_cp_generic *cpg;
5727 + struct dentry *dst_parent;
5730 +static void au_call_cpup_single(void *args)
5732 + struct au_cpup_single_args *a = args;
5734 + au_pin_hdir_acquire_nest(a->cpg->pin);
5735 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5736 + au_pin_hdir_release(a->cpg->pin);
5741 + * prevent SIGXFSZ in copy-up.
5742 + * testing CAP_MKNOD is for generic fs,
5743 + * but CAP_FSETID is for xfs only, currently.
5745 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5748 + struct super_block *sb;
5749 + struct inode *h_dir;
5752 + sb = au_pinned_parent(pin)->d_sb;
5753 + if (!au_wkq_test()
5754 + && (!au_sbi(sb)->si_plink_maint_pid
5755 + || au_plink_maint(sb, AuLock_NOPLM))) {
5756 + switch (mode & S_IFMT) {
5758 + /* no condition about RLIMIT_FSIZE and the file size */
5763 + do_sio = !capable(CAP_MKNOD);
5767 + do_sio = ((mode & (S_ISUID | S_ISGID))
5768 + && !capable(CAP_FSETID));
5769 + /* this workaround may be removed in the future */
5771 + h_dir = au_pinned_h_dir(pin);
5772 + do_sio = h_dir->i_mode & S_ISVTX;
5779 +#if 0 /* reserved */
5780 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5783 + struct dentry *h_dentry;
5785 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5786 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5787 + err = au_cpup_single(cpg, dst_parent);
5789 + struct au_cpup_single_args args = {
5792 + .dst_parent = dst_parent
5794 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5795 + if (unlikely(wkq_err))
5804 + * copyup the @dentry from the first active lower branch to @bdst,
5805 + * using au_cpup_single().
5807 +static int au_cpup_simple(struct au_cp_generic *cpg)
5810 + unsigned int flags_orig;
5811 + struct dentry *dentry;
5813 + AuDebugOn(cpg->bsrc < 0);
5815 + dentry = cpg->dentry;
5816 + DiMustWriteLock(dentry);
5818 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5820 + flags_orig = cpg->flags;
5821 + au_fset_cpup(cpg->flags, RENAME);
5822 + err = au_cpup_single(cpg, NULL);
5823 + cpg->flags = flags_orig;
5825 + return 0; /* success */
5828 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5829 + au_set_dbtop(dentry, cpg->bsrc);
5835 +struct au_cpup_simple_args {
5837 + struct au_cp_generic *cpg;
5840 +static void au_call_cpup_simple(void *args)
5842 + struct au_cpup_simple_args *a = args;
5844 + au_pin_hdir_acquire_nest(a->cpg->pin);
5845 + *a->errp = au_cpup_simple(a->cpg);
5846 + au_pin_hdir_release(a->cpg->pin);
5849 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5852 + struct dentry *dentry, *parent;
5853 + struct file *h_file;
5854 + struct inode *h_dir;
5855 + struct user_namespace *h_userns;
5857 + dentry = cpg->dentry;
5859 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5860 + AuDebugOn(cpg->bsrc < 0);
5861 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5862 + err = PTR_ERR(h_file);
5863 + if (IS_ERR(h_file))
5867 + parent = dget_parent(dentry);
5868 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5869 + h_userns = au_sbr_userns(dentry->d_sb, cpg->bdst);
5870 + if (!au_test_h_perm_sio(h_userns, h_dir, MAY_EXEC | MAY_WRITE)
5871 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5872 + err = au_cpup_simple(cpg);
5874 + struct au_cpup_simple_args args = {
5878 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5879 + if (unlikely(wkq_err))
5885 + au_h_open_post(dentry, cpg->bsrc, h_file);
5891 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5893 + aufs_bindex_t bsrc, bbot;
5894 + struct dentry *dentry, *h_dentry;
5896 + if (cpg->bsrc < 0) {
5897 + dentry = cpg->dentry;
5898 + bbot = au_dbbot(dentry);
5899 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5900 + h_dentry = au_h_dptr(dentry, bsrc);
5902 + AuDebugOn(d_is_negative(h_dentry));
5906 + AuDebugOn(bsrc > bbot);
5909 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5910 + return au_do_sio_cpup_simple(cpg);
5913 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5915 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5916 + return au_do_sio_cpup_simple(cpg);
5919 +/* ---------------------------------------------------------------------- */
5922 + * copyup the deleted file for writing.
5924 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5925 + struct file *file)
5928 + unsigned int flags_orig;
5929 + aufs_bindex_t bsrc_orig;
5930 + struct au_dinfo *dinfo;
5932 + struct au_hdentry *hd;
5933 + struct dentry *h_dentry;
5936 + dinfo = au_di(cpg->dentry);
5937 + AuRwMustWriteLock(&dinfo->di_rwsem);
5939 + bsrc_orig = cpg->bsrc;
5940 + cpg->bsrc = dinfo->di_btop;
5941 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5942 + hdst.h_dentry = hdst.hd->hd_dentry;
5943 + hdst.hd->hd_dentry = wh_dentry;
5944 + dinfo->di_btop = cpg->bdst;
5946 + hsrc.h_dentry = NULL;
5948 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5949 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5950 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5952 + flags_orig = cpg->flags;
5953 + cpg->flags = !AuCpup_DTIME;
5954 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5955 + cpg->flags = flags_orig;
5958 + err = au_reopen_nondir(file);
5959 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5961 + hdst.hd->hd_dentry = hdst.h_dentry;
5962 + dinfo->di_btop = cpg->bsrc;
5963 + cpg->bsrc = bsrc_orig;
5968 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5971 + aufs_bindex_t bdst;
5972 + struct au_dtime dt;
5973 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5974 + struct au_branch *br;
5975 + struct path h_path;
5977 + dentry = cpg->dentry;
5979 + br = au_sbr(dentry->d_sb, bdst);
5980 + parent = dget_parent(dentry);
5981 + h_parent = au_h_dptr(parent, bdst);
5982 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5983 + err = PTR_ERR(wh_dentry);
5984 + if (IS_ERR(wh_dentry))
5987 + h_path.dentry = h_parent;
5988 + h_path.mnt = au_br_mnt(br);
5989 + au_dtime_store(&dt, parent, &h_path);
5990 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5991 + if (unlikely(err))
5995 + h_path.dentry = wh_dentry;
5996 + if (!d_is_dir(wh_dentry)) {
5997 + /* no delegation since it is just created */
5998 + err = vfsub_unlink(d_inode(h_parent), &h_path,
5999 + /*delegated*/NULL, /*force*/0);
6001 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6002 + if (unlikely(err)) {
6003 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6007 + au_dtime_revert(&dt);
6008 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6017 +struct au_cpup_wh_args {
6019 + struct au_cp_generic *cpg;
6020 + struct file *file;
6023 +static void au_call_cpup_wh(void *args)
6025 + struct au_cpup_wh_args *a = args;
6027 + au_pin_hdir_acquire_nest(a->cpg->pin);
6028 + *a->errp = au_cpup_wh(a->cpg, a->file);
6029 + au_pin_hdir_release(a->cpg->pin);
6032 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6035 + aufs_bindex_t bdst;
6036 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6037 + struct inode *dir, *h_dir, *h_tmpdir;
6038 + struct au_wbr *wbr;
6039 + struct au_pin wh_pin, *pin_orig;
6040 + struct user_namespace *h_userns;
6042 + dentry = cpg->dentry;
6044 + parent = dget_parent(dentry);
6045 + dir = d_inode(parent);
6048 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6051 + if (!h_dir->i_nlink) {
6052 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6053 + h_orph = wbr->wbr_orph;
6055 + h_parent = dget(au_h_dptr(parent, bdst));
6056 + au_set_h_dptr(parent, bdst, dget(h_orph));
6057 + h_tmpdir = d_inode(h_orph);
6058 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6060 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6061 + /* todo: au_h_open_pre()? */
6063 + pin_orig = cpg->pin;
6064 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6065 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6066 + cpg->pin = &wh_pin;
6069 + h_userns = au_sbr_userns(dentry->d_sb, bdst);
6070 + if (!au_test_h_perm_sio(h_userns, h_tmpdir, MAY_EXEC | MAY_WRITE)
6071 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6072 + err = au_cpup_wh(cpg, file);
6074 + struct au_cpup_wh_args args = {
6079 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6080 + if (unlikely(wkq_err))
6085 + inode_unlock(h_tmpdir);
6086 + /* todo: au_h_open_post()? */
6087 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6088 + au_set_h_dptr(parent, bdst, h_parent);
6089 + AuDebugOn(!pin_orig);
6090 + cpg->pin = pin_orig;
6098 +/* ---------------------------------------------------------------------- */
6101 + * generic routine for both of copy-up and copy-down.
6103 +/* cf. revalidate function in file.c */
6104 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6105 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6106 + struct au_pin *pin,
6107 + struct dentry *h_parent, void *arg),
6111 + struct au_pin pin;
6112 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6115 + parent = dget_parent(dentry);
6116 + if (IS_ROOT(parent))
6119 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6120 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6122 + /* do not use au_dpage */
6123 + real_parent = parent;
6126 + parent = dget_parent(dentry);
6127 + h_parent = au_h_dptr(parent, bdst);
6129 + goto out; /* success */
6131 + /* find top dir which is necessary to cpup */
6135 + parent = dget_parent(d);
6136 + di_read_lock_parent3(parent, !AuLock_IR);
6137 + h_parent = au_h_dptr(parent, bdst);
6138 + di_read_unlock(parent, !AuLock_IR);
6139 + } while (!h_parent);
6141 + if (d != real_parent)
6142 + di_write_lock_child3(d);
6144 + /* somebody else might create while we were sleeping */
6145 + h_dentry = au_h_dptr(d, bdst);
6146 + if (!h_dentry || d_is_negative(h_dentry)) {
6148 + au_update_dbtop(d);
6150 + au_pin_set_dentry(&pin, d);
6151 + err = au_do_pin(&pin);
6153 + err = cp(d, bdst, &pin, h_parent, arg);
6158 + if (d != real_parent)
6159 + di_write_unlock(d);
6160 + if (unlikely(err))
6169 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6170 + struct au_pin *pin,
6171 + struct dentry *h_parent __maybe_unused,
6172 + void *arg __maybe_unused)
6174 + struct au_cp_generic cpg = {
6180 + .flags = AuCpup_DTIME
6182 + return au_sio_cpup_simple(&cpg);
6185 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6187 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6190 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6193 + struct dentry *parent;
6194 + struct inode *dir;
6196 + parent = dget_parent(dentry);
6197 + dir = d_inode(parent);
6199 + if (au_h_iptr(dir, bdst))
6202 + di_read_unlock(parent, AuLock_IR);
6203 + di_write_lock_parent(parent);
6204 + /* someone else might change our inode while we were sleeping */
6205 + if (!au_h_iptr(dir, bdst))
6206 + err = au_cpup_dirs(dentry, bdst);
6207 + di_downgrade_lock(parent, AuLock_IR);
6213 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6214 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6215 +++ linux/fs/aufs/cpup.h 2022-11-05 23:02:18.962555950 +0100
6217 +/* SPDX-License-Identifier: GPL-2.0 */
6219 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6221 + * This program is free software; you can redistribute it and/or modify
6222 + * it under the terms of the GNU General Public License as published by
6223 + * the Free Software Foundation; either version 2 of the License, or
6224 + * (at your option) any later version.
6226 + * This program is distributed in the hope that it will be useful,
6227 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6228 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6229 + * GNU General Public License for more details.
6231 + * You should have received a copy of the GNU General Public License
6232 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6236 + * copy-up/down functions
6239 +#ifndef __AUFS_CPUP_H__
6240 +#define __AUFS_CPUP_H__
6244 +#include <linux/path.h>
6250 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6251 +void au_cpup_attr_timesizes(struct inode *inode);
6252 +void au_cpup_attr_nlink(struct inode *inode, int force);
6253 +void au_cpup_attr_changeable(struct inode *inode);
6254 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6255 +void au_cpup_attr_all(struct inode *inode, int force);
6257 +/* ---------------------------------------------------------------------- */
6259 +struct au_cp_generic {
6260 + struct dentry *dentry;
6261 + aufs_bindex_t bdst, bsrc;
6263 + struct au_pin *pin;
6264 + unsigned int flags;
6268 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6269 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6271 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6272 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6274 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6276 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6277 + the branch is marked as RO */
6279 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6280 +#undef AuCpup_HOPEN
6281 +#define AuCpup_HOPEN 0
6284 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6285 +#define au_fset_cpup(flags, name) \
6286 + do { (flags) |= AuCpup_##name; } while (0)
6287 +#define au_fclr_cpup(flags, name) \
6288 + do { (flags) &= ~AuCpup_##name; } while (0)
6290 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6291 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6292 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6293 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6295 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6296 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6297 + struct au_pin *pin,
6298 + struct dentry *h_parent, void *arg),
6300 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6301 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6303 +/* ---------------------------------------------------------------------- */
6305 +/* keep timestamps when copyup */
6307 + struct dentry *dt_dentry;
6308 + struct path dt_h_path;
6309 + struct timespec64 dt_atime, dt_mtime;
6311 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6312 + struct path *h_path);
6313 +void au_dtime_revert(struct au_dtime *dt);
6315 +#endif /* __KERNEL__ */
6316 +#endif /* __AUFS_CPUP_H__ */
6317 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6318 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6319 +++ linux/fs/aufs/dbgaufs.c 2022-11-05 23:02:18.962555950 +0100
6321 +// SPDX-License-Identifier: GPL-2.0
6323 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6325 + * This program is free software; you can redistribute it and/or modify
6326 + * it under the terms of the GNU General Public License as published by
6327 + * the Free Software Foundation; either version 2 of the License, or
6328 + * (at your option) any later version.
6330 + * This program is distributed in the hope that it will be useful,
6331 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6332 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6333 + * GNU General Public License for more details.
6335 + * You should have received a copy of the GNU General Public License
6336 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6340 + * debugfs interface
6343 +#include <linux/debugfs.h>
6346 +#ifndef CONFIG_SYSFS
6347 +#error DEBUG_FS depends upon SYSFS
6350 +static struct dentry *dbgaufs;
6351 +static const mode_t dbgaufs_mode = 0444;
6353 +/* 20 is max digits length of ulong 64 */
6354 +struct dbgaufs_arg {
6360 + * common function for all XINO files
6362 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6363 + struct file *file)
6367 + p = file->private_data;
6369 + /* this is struct dbgaufs_arg */
6370 + AuDebugOn(!au_kfree_sz_test(p));
6371 + au_kfree_do_rcu(p);
6376 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6381 + struct dbgaufs_arg *p;
6384 + p = kmalloc(sizeof(*p), GFP_NOFS);
6390 + file->private_data = p;
6394 + err = vfsub_getattr(&xf->f_path, &st);
6398 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6399 + cnt, st.blocks, st.blksize,
6400 + (long long)st.size);
6402 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6403 + st.blocks, st.blksize,
6404 + (long long)st.size);
6405 + AuDebugOn(p->n >= sizeof(p->a));
6407 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6415 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6416 + size_t count, loff_t *ppos)
6418 + struct dbgaufs_arg *p;
6420 + p = file->private_data;
6421 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6424 +/* ---------------------------------------------------------------------- */
6426 +struct dbgaufs_plink_arg {
6431 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6432 + struct file *file)
6434 + free_page((unsigned long)file->private_data);
6438 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6440 + int err, i, limit;
6441 + unsigned long n, sum;
6442 + struct dbgaufs_plink_arg *p;
6443 + struct au_sbinfo *sbinfo;
6444 + struct super_block *sb;
6445 + struct hlist_bl_head *hbl;
6448 + p = (void *)get_zeroed_page(GFP_NOFS);
6453 + sbinfo = inode->i_private;
6454 + sb = sbinfo->si_sb;
6455 + si_noflush_read_lock(sb);
6456 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6457 + limit = PAGE_SIZE - sizeof(p->n);
6459 + /* the number of buckets */
6460 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6465 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6467 + n = au_hbl_count(hbl);
6470 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6473 + if (unlikely(limit <= 0))
6476 + p->a[p->n - 1] = '\n';
6478 + /* the sum of plinks */
6479 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6482 + if (unlikely(limit <= 0))
6485 +#define str "1\n0\n0\n"
6486 + p->n = sizeof(str) - 1;
6487 + strcpy(p->a, str);
6490 + si_read_unlock(sb);
6493 + file->private_data = p;
6494 + goto out; /* success */
6497 + free_page((unsigned long)p);
6502 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6503 + size_t count, loff_t *ppos)
6505 + struct dbgaufs_plink_arg *p;
6507 + p = file->private_data;
6508 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6511 +static const struct file_operations dbgaufs_plink_fop = {
6512 + .owner = THIS_MODULE,
6513 + .open = dbgaufs_plink_open,
6514 + .release = dbgaufs_plink_release,
6515 + .read = dbgaufs_plink_read
6518 +/* ---------------------------------------------------------------------- */
6520 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6523 + struct au_sbinfo *sbinfo;
6524 + struct super_block *sb;
6526 + sbinfo = inode->i_private;
6527 + sb = sbinfo->si_sb;
6528 + si_noflush_read_lock(sb);
6529 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6530 + si_read_unlock(sb);
6534 +static const struct file_operations dbgaufs_xib_fop = {
6535 + .owner = THIS_MODULE,
6536 + .open = dbgaufs_xib_open,
6537 + .release = dbgaufs_xi_release,
6538 + .read = dbgaufs_xi_read
6541 +/* ---------------------------------------------------------------------- */
6543 +#define DbgaufsXi_PREFIX "xi"
6545 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6549 + aufs_bindex_t bindex;
6550 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6551 + struct au_sbinfo *sbinfo;
6552 + struct super_block *sb;
6553 + struct au_xino *xi;
6555 + struct qstr *name;
6556 + struct au_branch *br;
6559 + name = &file->f_path.dentry->d_name;
6560 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6561 + || memcmp(name->name, DbgaufsXi_PREFIX,
6562 + sizeof(DbgaufsXi_PREFIX) - 1)))
6565 + AuDebugOn(name->len >= sizeof(a));
6566 + memcpy(a, name->name, name->len);
6567 + a[name->len] = '\0';
6568 + p = strchr(a, '-');
6571 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6572 + if (unlikely(err))
6577 + err = kstrtol(p + 1, 10, &l);
6578 + if (unlikely(err))
6584 + sbinfo = inode->i_private;
6585 + sb = sbinfo->si_sb;
6586 + si_noflush_read_lock(sb);
6587 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6589 + br = au_sbr(sb, bindex);
6591 + if (unlikely(idx >= xi->xi_nfile))
6593 + xf = au_xino_file(xi, idx);
6595 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6596 + au_xino_count(br));
6599 + si_read_unlock(sb);
6605 +static const struct file_operations dbgaufs_xino_fop = {
6606 + .owner = THIS_MODULE,
6607 + .open = dbgaufs_xino_open,
6608 + .release = dbgaufs_xi_release,
6609 + .read = dbgaufs_xi_read
6612 +void dbgaufs_xino_del(struct au_branch *br)
6614 + struct dentry *dbgaufs;
6616 + dbgaufs = br->br_dbgaufs;
6620 + br->br_dbgaufs = NULL;
6621 + /* debugfs acquires the parent i_mutex */
6623 + debugfs_remove(dbgaufs);
6627 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6629 + aufs_bindex_t bbot;
6630 + struct au_branch *br;
6632 + if (!au_sbi(sb)->si_dbgaufs)
6635 + bbot = au_sbbot(sb);
6636 + for (; bindex <= bbot; bindex++) {
6637 + br = au_sbr(sb, bindex);
6638 + dbgaufs_xino_del(br);
6642 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6643 + unsigned int idx, struct dentry *parent,
6644 + struct au_sbinfo *sbinfo)
6646 + struct au_branch *br;
6648 + /* "xi" bindex(5) "-" idx(2) NULL */
6649 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6652 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6654 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6656 + br = au_sbr(sb, bindex);
6657 + if (br->br_dbgaufs) {
6658 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6660 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6661 + /* debugfs acquires the parent i_mutex */
6663 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6667 + pr_warn("failed renaming %pd/%s, ignored.\n",
6672 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6673 + sbinfo, &dbgaufs_xino_fop);
6675 + if (unlikely(!br->br_dbgaufs))
6676 + pr_warn("failed creating %pd/%s, ignored.\n",
6681 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6682 + struct dentry *parent, struct au_sbinfo *sbinfo)
6684 + struct au_branch *br;
6685 + struct au_xino *xi;
6688 + br = au_sbr(sb, bindex);
6690 + for (u = 0; u < xi->xi_nfile; u++)
6691 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6694 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6696 + struct au_sbinfo *sbinfo;
6697 + struct dentry *parent;
6698 + aufs_bindex_t bbot;
6700 + if (!au_opt_test(au_mntflags(sb), XINO))
6703 + sbinfo = au_sbi(sb);
6704 + parent = sbinfo->si_dbgaufs;
6708 + bbot = au_sbbot(sb);
6710 + for (; bindex <= bbot; bindex++)
6711 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6713 + for (; bbot >= bindex; bbot--)
6714 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6717 +/* ---------------------------------------------------------------------- */
6719 +#ifdef CONFIG_AUFS_EXPORT
6720 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6723 + struct au_sbinfo *sbinfo;
6724 + struct super_block *sb;
6726 + sbinfo = inode->i_private;
6727 + sb = sbinfo->si_sb;
6728 + si_noflush_read_lock(sb);
6729 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6730 + si_read_unlock(sb);
6734 +static const struct file_operations dbgaufs_xigen_fop = {
6735 + .owner = THIS_MODULE,
6736 + .open = dbgaufs_xigen_open,
6737 + .release = dbgaufs_xi_release,
6738 + .read = dbgaufs_xi_read
6741 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6746 + * This function is a dynamic '__init' function actually,
6747 + * so the tiny check for si_rwsem is unnecessary.
6749 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6752 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6753 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6754 + &dbgaufs_xigen_fop);
6755 + if (sbinfo->si_dbgaufs_xigen)
6761 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6765 +#endif /* CONFIG_AUFS_EXPORT */
6767 +/* ---------------------------------------------------------------------- */
6769 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6772 + * This function is a dynamic '__fin' function actually,
6773 + * so the tiny check for si_rwsem is unnecessary.
6775 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6777 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6778 + sbinfo->si_dbgaufs = NULL;
6781 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6784 + char name[SysaufsSiNameLen];
6787 + * This function is a dynamic '__init' function actually,
6788 + * so the tiny check for si_rwsem is unnecessary.
6790 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6794 + AuErr1("/debug/aufs is uninitialized\n");
6799 + sysaufs_name(sbinfo, name);
6800 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6801 + if (unlikely(!sbinfo->si_dbgaufs))
6804 + /* regardless plink/noplink option */
6805 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6806 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6807 + &dbgaufs_plink_fop);
6808 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6811 + /* regardless xino/noxino option */
6812 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6813 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6814 + &dbgaufs_xib_fop);
6815 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6818 + err = dbgaufs_xigen_init(sbinfo);
6820 + goto out; /* success */
6823 + dbgaufs_si_fin(sbinfo);
6825 + if (unlikely(err))
6826 + pr_err("debugfs/aufs failed\n");
6830 +/* ---------------------------------------------------------------------- */
6832 +void dbgaufs_fin(void)
6834 + debugfs_remove(dbgaufs);
6837 +int __init dbgaufs_init(void)
6842 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6847 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6848 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6849 +++ linux/fs/aufs/dbgaufs.h 2022-11-05 23:02:18.962555950 +0100
6851 +/* SPDX-License-Identifier: GPL-2.0 */
6853 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6855 + * This program is free software; you can redistribute it and/or modify
6856 + * it under the terms of the GNU General Public License as published by
6857 + * the Free Software Foundation; either version 2 of the License, or
6858 + * (at your option) any later version.
6860 + * This program is distributed in the hope that it will be useful,
6861 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6862 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6863 + * GNU General Public License for more details.
6865 + * You should have received a copy of the GNU General Public License
6866 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6870 + * debugfs interface
6873 +#ifndef __DBGAUFS_H__
6874 +#define __DBGAUFS_H__
6878 +struct super_block;
6882 +#ifdef CONFIG_DEBUG_FS
6884 +void dbgaufs_xino_del(struct au_branch *br);
6885 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6886 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6887 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6888 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6889 +void dbgaufs_fin(void);
6890 +int __init dbgaufs_init(void);
6892 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6893 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6894 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6896 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6897 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6898 +AuStubVoid(dbgaufs_fin, void)
6899 +AuStubInt0(__init dbgaufs_init, void)
6900 +#endif /* CONFIG_DEBUG_FS */
6902 +#endif /* __KERNEL__ */
6903 +#endif /* __DBGAUFS_H__ */
6904 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6905 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6906 +++ linux/fs/aufs/dcsub.c 2022-11-05 23:02:18.962555950 +0100
6908 +// SPDX-License-Identifier: GPL-2.0
6910 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6912 + * This program is free software; you can redistribute it and/or modify
6913 + * it under the terms of the GNU General Public License as published by
6914 + * the Free Software Foundation; either version 2 of the License, or
6915 + * (at your option) any later version.
6917 + * This program is distributed in the hope that it will be useful,
6918 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6919 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6920 + * GNU General Public License for more details.
6922 + * You should have received a copy of the GNU General Public License
6923 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6927 + * sub-routines for dentry cache
6932 +static void au_dpage_free(struct au_dpage *dpage)
6935 + struct dentry **p;
6937 + p = dpage->dentries;
6938 + for (i = 0; i < dpage->ndentry; i++)
6940 + free_page((unsigned long)dpage->dentries);
6943 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6949 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6950 + if (unlikely(!dpages->dpages))
6953 + p = (void *)__get_free_page(gfp);
6957 + dpages->dpages[0].ndentry = 0;
6958 + dpages->dpages[0].dentries = p;
6959 + dpages->ndpage = 1;
6960 + return 0; /* success */
6963 + au_kfree_try_rcu(dpages->dpages);
6968 +void au_dpages_free(struct au_dcsub_pages *dpages)
6971 + struct au_dpage *p;
6973 + p = dpages->dpages;
6974 + for (i = 0; i < dpages->ndpage; i++)
6975 + au_dpage_free(p++);
6976 + au_kfree_try_rcu(dpages->dpages);
6979 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6980 + struct dentry *dentry, gfp_t gfp)
6983 + struct au_dpage *dpage;
6986 + dpage = dpages->dpages + dpages->ndpage - 1;
6987 + sz = PAGE_SIZE / sizeof(dentry);
6988 + if (unlikely(dpage->ndentry >= sz)) {
6989 + AuLabel(new dpage);
6991 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6992 + p = au_kzrealloc(dpages->dpages, sz,
6993 + sz + sizeof(*dpages->dpages), gfp,
6998 + dpages->dpages = p;
6999 + dpage = dpages->dpages + dpages->ndpage;
7000 + p = (void *)__get_free_page(gfp);
7004 + dpage->ndentry = 0;
7005 + dpage->dentries = p;
7009 + AuDebugOn(au_dcount(dentry) <= 0);
7010 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7011 + return 0; /* success */
7017 +/* todo: BAD approach */
7018 +/* copied from linux/fs/dcache.c */
7026 +extern void d_walk(struct dentry *parent, void *data,
7027 + enum d_walk_ret (*enter)(void *, struct dentry *));
7029 +struct ac_dpages_arg {
7031 + struct au_dcsub_pages *dpages;
7032 + struct super_block *sb;
7033 + au_dpages_test test;
7037 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7039 + enum d_walk_ret ret;
7040 + struct ac_dpages_arg *arg = _arg;
7042 + ret = D_WALK_CONTINUE;
7043 + if (dentry->d_sb == arg->sb
7044 + && !IS_ROOT(dentry)
7045 + && au_dcount(dentry) > 0
7047 + && (!arg->test || arg->test(dentry, arg->arg))) {
7048 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7049 + if (unlikely(arg->err))
7050 + ret = D_WALK_QUIT;
7056 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7057 + au_dpages_test test, void *arg)
7059 + struct ac_dpages_arg args = {
7067 + d_walk(root, &args, au_call_dpages_append);
7072 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7073 + int do_include, au_dpages_test test, void *arg)
7078 + write_seqlock(&rename_lock);
7079 + spin_lock(&dentry->d_lock);
7081 + && au_dcount(dentry) > 0
7082 + && (!test || test(dentry, arg)))
7083 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7084 + spin_unlock(&dentry->d_lock);
7085 + if (unlikely(err))
7089 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7092 + while (!IS_ROOT(dentry)) {
7093 + dentry = dentry->d_parent; /* rename_lock is locked */
7094 + spin_lock(&dentry->d_lock);
7095 + if (au_dcount(dentry) > 0
7096 + && (!test || test(dentry, arg)))
7097 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7098 + spin_unlock(&dentry->d_lock);
7099 + if (unlikely(err))
7104 + write_sequnlock(&rename_lock);
7108 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7110 + return au_di(dentry) && dentry->d_sb == arg;
7113 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7114 + struct dentry *dentry, int do_include)
7116 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7117 + au_dcsub_dpages_aufs, dentry->d_sb);
7120 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7122 + struct path path[2] = {
7131 + return path_is_under(path + 0, path + 1);
7133 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7134 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7135 +++ linux/fs/aufs/dcsub.h 2022-11-05 23:02:18.962555950 +0100
7137 +/* SPDX-License-Identifier: GPL-2.0 */
7139 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7141 + * This program is free software; you can redistribute it and/or modify
7142 + * it under the terms of the GNU General Public License as published by
7143 + * the Free Software Foundation; either version 2 of the License, or
7144 + * (at your option) any later version.
7146 + * This program is distributed in the hope that it will be useful,
7147 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7148 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7149 + * GNU General Public License for more details.
7151 + * You should have received a copy of the GNU General Public License
7152 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7156 + * sub-routines for dentry cache
7159 +#ifndef __AUFS_DCSUB_H__
7160 +#define __AUFS_DCSUB_H__
7164 +#include <linux/dcache.h>
7165 +#include <linux/fs.h>
7169 + struct dentry **dentries;
7172 +struct au_dcsub_pages {
7174 + struct au_dpage *dpages;
7177 +/* ---------------------------------------------------------------------- */
7180 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7181 +void au_dpages_free(struct au_dcsub_pages *dpages);
7182 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7183 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7184 + au_dpages_test test, void *arg);
7185 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7186 + int do_include, au_dpages_test test, void *arg);
7187 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7188 + struct dentry *dentry, int do_include);
7189 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7191 +/* ---------------------------------------------------------------------- */
7194 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7195 + * include/linux/dcache.h. Try them (in the future).
7198 +static inline int au_d_hashed_positive(struct dentry *d)
7201 + struct inode *inode = d_inode(d);
7204 + if (unlikely(d_unhashed(d)
7205 + || d_is_negative(d)
7206 + || !inode->i_nlink))
7211 +static inline int au_d_linkable(struct dentry *d)
7214 + struct inode *inode = d_inode(d);
7216 + err = au_d_hashed_positive(d);
7218 + && d_is_positive(d)
7219 + && (inode->i_state & I_LINKABLE))
7224 +static inline int au_d_alive(struct dentry *d)
7227 + struct inode *inode;
7231 + err = au_d_hashed_positive(d);
7233 + inode = d_inode(d);
7234 + if (unlikely(d_unlinked(d)
7235 + || d_is_negative(d)
7236 + || !inode->i_nlink))
7242 +static inline int au_alive_dir(struct dentry *d)
7246 + err = au_d_alive(d);
7247 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7252 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7254 + return a->len == b->len
7255 + && !memcmp(a->name, b->name, a->len);
7260 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7262 + * the type of d_lockref.count became int, but the inlined function d_count()
7263 + * still returns unsigned int.
7264 + * I don't know why. Maybe it is for every d_count() users?
7265 + * Anyway au_dcount() lives on.
7267 +static inline int au_dcount(struct dentry *d)
7269 + return (int)d_count(d);
7272 +#endif /* __KERNEL__ */
7273 +#endif /* __AUFS_DCSUB_H__ */
7274 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7275 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7276 +++ linux/fs/aufs/debug.c 2022-11-05 23:02:18.962555950 +0100
7278 +// SPDX-License-Identifier: GPL-2.0
7280 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7282 + * This program is free software; you can redistribute it and/or modify
7283 + * it under the terms of the GNU General Public License as published by
7284 + * the Free Software Foundation; either version 2 of the License, or
7285 + * (at your option) any later version.
7287 + * This program is distributed in the hope that it will be useful,
7288 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7289 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7290 + * GNU General Public License for more details.
7292 + * You should have received a copy of the GNU General Public License
7293 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7297 + * debug print functions
7300 +#include <linux/iversion.h>
7303 +/* Returns 0, or -errno. arg is in kp->arg. */
7304 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7308 + err = kstrtoint(val, 0, &n);
7318 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7319 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7324 + return sprintf(buffer, "%d", atomic_read(a));
7327 +static const struct kernel_param_ops param_ops_atomic_t = {
7328 + .set = param_atomic_t_set,
7329 + .get = param_atomic_t_get
7330 + /* void (*free)(void *arg) */
7333 +atomic_t aufs_debug = ATOMIC_INIT(0);
7334 +MODULE_PARM_DESC(debug, "debug print");
7335 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7337 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7338 +char *au_plevel = KERN_DEBUG;
7339 +#define dpri(fmt, ...) do { \
7341 + && strcmp(au_plevel, KERN_DEBUG)) \
7342 + || au_debug_test()) \
7343 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7346 +/* ---------------------------------------------------------------------- */
7348 +void au_dpri_whlist(struct au_nhash *whlist)
7350 + unsigned long ul, n;
7351 + struct hlist_head *head;
7352 + struct au_vdir_wh *pos;
7354 + n = whlist->nh_num;
7355 + head = whlist->nh_head;
7356 + for (ul = 0; ul < n; ul++) {
7357 + hlist_for_each_entry(pos, head, wh_hash)
7358 + dpri("b%d, %.*s, %d\n",
7360 + pos->wh_str.len, pos->wh_str.name,
7366 +void au_dpri_vdir(struct au_vdir *vdir)
7369 + union au_vdir_deblk_p p;
7372 + if (!vdir || IS_ERR(vdir)) {
7373 + dpri("err %ld\n", PTR_ERR(vdir));
7377 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7378 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7379 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7380 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7381 + p.deblk = vdir->vd_deblk[ul];
7383 + dpri("[%lu]: %p\n", ul, o);
7387 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7388 + struct dentry *wh)
7393 + if (!inode || IS_ERR(inode)) {
7394 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7398 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7399 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7400 + && sizeof(inode->i_blocks) != sizeof(u64));
7402 + n = (void *)wh->d_name.name;
7403 + l = wh->d_name.len;
7406 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7407 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7409 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7410 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7411 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7412 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7413 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7414 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7415 + inode->i_generation,
7416 + l ? ", wh " : "", l, n);
7420 +void au_dpri_inode(struct inode *inode)
7422 + struct au_iinfo *iinfo;
7423 + struct au_hinode *hi;
7424 + aufs_bindex_t bindex;
7427 + err = do_pri_inode(-1, inode, -1, NULL);
7428 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7431 + iinfo = au_ii(inode);
7432 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7433 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7434 + if (iinfo->ii_btop < 0)
7437 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7438 + hi = au_hinode(iinfo, bindex);
7440 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7444 +void au_dpri_dalias(struct inode *inode)
7448 + spin_lock(&inode->i_lock);
7449 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7450 + au_dpri_dentry(d);
7451 + spin_unlock(&inode->i_lock);
7454 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7456 + struct dentry *wh = NULL;
7458 + struct inode *inode;
7459 + struct au_iinfo *iinfo;
7460 + struct au_hinode *hi;
7462 + if (!dentry || IS_ERR(dentry)) {
7463 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7466 + /* do not call dget_parent() here */
7467 + /* note: access d_xxx without d_lock */
7468 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7469 + bindex, dentry, dentry,
7470 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7471 + au_dcount(dentry), dentry->d_flags,
7472 + d_unhashed(dentry) ? "un" : "");
7475 + if (d_is_positive(dentry))
7476 + inode = d_inode(dentry);
7478 + && au_test_aufs(dentry->d_sb)
7480 + && !au_is_bad_inode(inode)) {
7481 + iinfo = au_ii(inode);
7482 + hi = au_hinode(iinfo, bindex);
7484 + wh = hi->hi_whdentry;
7486 + do_pri_inode(bindex, inode, hn, wh);
7490 +void au_dpri_dentry(struct dentry *dentry)
7492 + struct au_dinfo *dinfo;
7493 + aufs_bindex_t bindex;
7496 + err = do_pri_dentry(-1, dentry);
7497 + if (err || !au_test_aufs(dentry->d_sb))
7500 + dinfo = au_di(dentry);
7503 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7504 + dinfo->di_btop, dinfo->di_bbot,
7505 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7506 + dinfo->di_tmpfile);
7507 + if (dinfo->di_btop < 0)
7509 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7510 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7513 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7517 + if (!file || IS_ERR(file)) {
7518 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7523 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7524 + && au_test_aufs(file->f_path.dentry->d_sb)
7526 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7527 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7528 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7529 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7530 + file->f_version, file->f_pos, a);
7531 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7532 + do_pri_dentry(bindex, file->f_path.dentry);
7536 +void au_dpri_file(struct file *file)
7538 + struct au_finfo *finfo;
7539 + struct au_fidir *fidir;
7540 + struct au_hfile *hfile;
7541 + aufs_bindex_t bindex;
7544 + err = do_pri_file(-1, file);
7546 + || IS_ERR_OR_NULL(file->f_path.dentry)
7547 + || !au_test_aufs(file->f_path.dentry->d_sb))
7550 + finfo = au_fi(file);
7553 + if (finfo->fi_btop < 0)
7555 + fidir = finfo->fi_hdir;
7557 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7559 + for (bindex = finfo->fi_btop;
7560 + bindex >= 0 && bindex <= fidir->fd_bbot;
7562 + hfile = fidir->fd_hfile + bindex;
7563 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7567 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7569 + struct vfsmount *mnt;
7570 + struct super_block *sb;
7572 + if (!br || IS_ERR(br))
7574 + mnt = au_br_mnt(br);
7575 + if (!mnt || IS_ERR(mnt))
7578 + if (!sb || IS_ERR(sb))
7581 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7582 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7584 + bindex, br->br_perm, br->br_id, br->br_wbr,
7585 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7586 + sb->s_flags, sb->s_count,
7587 + atomic_read(&sb->s_active),
7588 + !!au_xino_file(br->br_xino, /*idx*/-1));
7592 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7596 +void au_dpri_sb(struct super_block *sb)
7598 + struct au_sbinfo *sbinfo;
7599 + aufs_bindex_t bindex;
7601 + /* to reduce stack size */
7603 + struct vfsmount mnt;
7604 + struct au_branch fake;
7607 + /* this function can be called from magic sysrq */
7608 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7609 + if (unlikely(!a)) {
7610 + dpri("no memory\n");
7614 + a->mnt.mnt_sb = sb;
7615 + a->fake.br_path.mnt = &a->mnt;
7616 + err = do_pri_br(-1, &a->fake);
7618 + dpri("dev 0x%x\n", sb->s_dev);
7619 + if (err || !au_test_aufs(sb))
7622 + sbinfo = au_sbi(sb);
7625 + dpri("nw %d, gen %u, kobj %d\n",
7626 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7627 + kref_read(&sbinfo->si_kobj.kref));
7628 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7629 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7632 +/* ---------------------------------------------------------------------- */
7634 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7636 + struct inode *h_inode, *inode = d_inode(dentry);
7637 + struct dentry *h_dentry;
7638 + aufs_bindex_t bindex, bbot, bi;
7640 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7643 + bbot = au_dbbot(dentry);
7644 + bi = au_ibbot(inode);
7647 + bindex = au_dbtop(dentry);
7648 + bi = au_ibtop(inode);
7652 + for (; bindex <= bbot; bindex++) {
7653 + h_dentry = au_h_dptr(dentry, bindex);
7656 + h_inode = au_h_iptr(inode, bindex);
7657 + if (unlikely(h_inode != d_inode(h_dentry))) {
7659 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7660 + AuDbgDentry(dentry);
7661 + AuDbgInode(inode);
7663 + if (au_test_fuse(h_inode->i_sb))
7671 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7674 + struct au_dcsub_pages dpages;
7675 + struct au_dpage *dpage;
7676 + struct dentry **dentries;
7678 + err = au_dpages_init(&dpages, GFP_NOFS);
7680 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7682 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7683 + dpage = dpages.dpages + i;
7684 + dentries = dpage->dentries;
7685 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7686 + AuDebugOn(au_digen_test(dentries[j], sigen));
7688 + au_dpages_free(&dpages);
7691 +void au_dbg_verify_kthread(void)
7693 + if (au_wkq_test()) {
7696 + * It may be recursive, but udba=notify between two aufs mounts,
7697 + * where a single ro branch is shared, is not a problem.
7703 +/* ---------------------------------------------------------------------- */
7705 +int __init au_debug_init(void)
7707 + aufs_bindex_t bindex;
7708 + struct au_vdir_destr destr;
7711 + AuDebugOn(bindex >= 0);
7714 + AuDebugOn(destr.len < NAME_MAX);
7716 +#ifdef CONFIG_4KSTACKS
7717 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7722 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7723 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7724 +++ linux/fs/aufs/debug.h 2022-11-05 23:02:18.962555950 +0100
7726 +/* SPDX-License-Identifier: GPL-2.0 */
7728 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7730 + * This program is free software; you can redistribute it and/or modify
7731 + * it under the terms of the GNU General Public License as published by
7732 + * the Free Software Foundation; either version 2 of the License, or
7733 + * (at your option) any later version.
7735 + * This program is distributed in the hope that it will be useful,
7736 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7737 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7738 + * GNU General Public License for more details.
7740 + * You should have received a copy of the GNU General Public License
7741 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7745 + * debug print functions
7748 +#ifndef __AUFS_DEBUG_H__
7749 +#define __AUFS_DEBUG_H__
7753 +#include <linux/atomic.h>
7754 +#include <linux/module.h>
7755 +#include <linux/kallsyms.h>
7756 +#include <linux/sysrq.h>
7758 +#ifdef CONFIG_AUFS_DEBUG
7759 +#define AuDebugOn(a) BUG_ON(a)
7761 +/* module parameter */
7762 +extern atomic_t aufs_debug;
7763 +static inline void au_debug_on(void)
7765 + atomic_inc(&aufs_debug);
7767 +static inline void au_debug_off(void)
7769 + atomic_dec_if_positive(&aufs_debug);
7772 +static inline int au_debug_test(void)
7774 + return atomic_read(&aufs_debug) > 0;
7777 +#define AuDebugOn(a) do {} while (0)
7778 +AuStubVoid(au_debug_on, void)
7779 +AuStubVoid(au_debug_off, void)
7780 +AuStubInt0(au_debug_test, void)
7781 +#endif /* CONFIG_AUFS_DEBUG */
7783 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7785 +/* ---------------------------------------------------------------------- */
7789 +#define AuDbg(fmt, ...) do { \
7790 + if (au_debug_test()) \
7791 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7793 +#define AuLabel(l) AuDbg(#l "\n")
7794 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7795 +#define AuWarn1(fmt, ...) do { \
7796 + static unsigned char _c; \
7798 + pr_warn(fmt, ##__VA_ARGS__); \
7801 +#define AuErr1(fmt, ...) do { \
7802 + static unsigned char _c; \
7804 + pr_err(fmt, ##__VA_ARGS__); \
7807 +#define AuIOErr1(fmt, ...) do { \
7808 + static unsigned char _c; \
7810 + AuIOErr(fmt, ##__VA_ARGS__); \
7813 +#define AuUnsupportMsg "This operation is not supported." \
7814 + " Please report this application to aufs-users ML."
7815 +#define AuUnsupport(fmt, ...) do { \
7816 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7820 +#define AuTraceErr(e) do { \
7821 + if (unlikely((e) < 0)) \
7822 + AuDbg("err %d\n", (int)(e)); \
7825 +#define AuTraceErrPtr(p) do { \
7827 + AuDbg("err %ld\n", PTR_ERR(p)); \
7830 +/* dirty macros for debug print, use with "%.*s" and caution */
7831 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7833 +/* ---------------------------------------------------------------------- */
7836 +#ifdef CONFIG_AUFS_DEBUG
7837 +extern struct mutex au_dbg_mtx;
7838 +extern char *au_plevel;
7840 +void au_dpri_whlist(struct au_nhash *whlist);
7842 +void au_dpri_vdir(struct au_vdir *vdir);
7844 +void au_dpri_inode(struct inode *inode);
7845 +void au_dpri_dalias(struct inode *inode);
7846 +void au_dpri_dentry(struct dentry *dentry);
7848 +void au_dpri_file(struct file *filp);
7849 +struct super_block;
7850 +void au_dpri_sb(struct super_block *sb);
7852 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7853 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7854 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7855 +void au_dbg_verify_kthread(void);
7857 +int __init au_debug_init(void);
7859 +#define AuDbgWhlist(w) do { \
7860 + mutex_lock(&au_dbg_mtx); \
7862 + au_dpri_whlist(w); \
7863 + mutex_unlock(&au_dbg_mtx); \
7866 +#define AuDbgVdir(v) do { \
7867 + mutex_lock(&au_dbg_mtx); \
7869 + au_dpri_vdir(v); \
7870 + mutex_unlock(&au_dbg_mtx); \
7873 +#define AuDbgInode(i) do { \
7874 + mutex_lock(&au_dbg_mtx); \
7876 + au_dpri_inode(i); \
7877 + mutex_unlock(&au_dbg_mtx); \
7880 +#define AuDbgDAlias(i) do { \
7881 + mutex_lock(&au_dbg_mtx); \
7883 + au_dpri_dalias(i); \
7884 + mutex_unlock(&au_dbg_mtx); \
7887 +#define AuDbgDentry(d) do { \
7888 + mutex_lock(&au_dbg_mtx); \
7890 + au_dpri_dentry(d); \
7891 + mutex_unlock(&au_dbg_mtx); \
7894 +#define AuDbgFile(f) do { \
7895 + mutex_lock(&au_dbg_mtx); \
7897 + au_dpri_file(f); \
7898 + mutex_unlock(&au_dbg_mtx); \
7901 +#define AuDbgSb(sb) do { \
7902 + mutex_lock(&au_dbg_mtx); \
7903 + AuDbg(#sb "\n"); \
7905 + mutex_unlock(&au_dbg_mtx); \
7908 +#define AuDbgSym(addr) do { \
7909 + char sym[KSYM_SYMBOL_LEN]; \
7910 + sprint_symbol(sym, (unsigned long)addr); \
7911 + AuDbg("%s\n", sym); \
7914 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7915 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7916 +AuStubVoid(au_dbg_verify_kthread, void)
7917 +AuStubInt0(__init au_debug_init, void)
7919 +#define AuDbgWhlist(w) do {} while (0)
7920 +#define AuDbgVdir(v) do {} while (0)
7921 +#define AuDbgInode(i) do {} while (0)
7922 +#define AuDbgDAlias(i) do {} while (0)
7923 +#define AuDbgDentry(d) do {} while (0)
7924 +#define AuDbgFile(f) do {} while (0)
7925 +#define AuDbgSb(sb) do {} while (0)
7926 +#define AuDbgSym(addr) do {} while (0)
7927 +#endif /* CONFIG_AUFS_DEBUG */
7929 +/* ---------------------------------------------------------------------- */
7931 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7932 +int __init au_sysrq_init(void);
7933 +void au_sysrq_fin(void);
7935 +#ifdef CONFIG_HW_CONSOLE
7936 +#define au_dbg_blocked() do { \
7938 + handle_sysrq('w'); \
7941 +AuStubVoid(au_dbg_blocked, void)
7945 +AuStubInt0(__init au_sysrq_init, void)
7946 +AuStubVoid(au_sysrq_fin, void)
7947 +AuStubVoid(au_dbg_blocked, void)
7948 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7950 +#endif /* __KERNEL__ */
7951 +#endif /* __AUFS_DEBUG_H__ */
7952 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7953 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7954 +++ linux/fs/aufs/dentry.c 2022-11-05 23:02:18.962555950 +0100
7956 +// SPDX-License-Identifier: GPL-2.0
7958 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7960 + * This program is free software; you can redistribute it and/or modify
7961 + * it under the terms of the GNU General Public License as published by
7962 + * the Free Software Foundation; either version 2 of the License, or
7963 + * (at your option) any later version.
7965 + * This program is distributed in the hope that it will be useful,
7966 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7967 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7968 + * GNU General Public License for more details.
7970 + * You should have received a copy of the GNU General Public License
7971 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7975 + * lookup and dentry operations
7978 +#include <linux/iversion.h>
7982 + * returns positive/negative dentry, NULL or an error.
7983 + * NULL means whiteout-ed or not-found.
7985 +static struct dentry*
7986 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7987 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
7989 + struct dentry *h_dentry;
7990 + struct inode *h_inode;
7991 + struct au_branch *br;
7992 + struct user_namespace *h_userns;
7993 + struct path h_path;
7994 + int wh_found, opq;
7995 + unsigned char wh_able;
7996 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7997 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8001 + br = au_sbr(dentry->d_sb, bindex);
8002 + h_path.dentry = h_parent;
8003 + h_path.mnt = au_br_mnt(br);
8004 + h_userns = au_br_userns(br);
8005 + wh_able = !!au_br_whable(br->br_perm);
8007 + wh_found = au_wh_test(h_userns, &h_path, &args->whname,
8009 + h_dentry = ERR_PTR(wh_found);
8012 + if (unlikely(wh_found < 0))
8015 + /* We found a whiteout */
8016 + /* au_set_dbbot(dentry, bindex); */
8017 + au_set_dbwh(dentry, bindex);
8019 + return NULL; /* success */
8023 + h_dentry = vfsub_lkup_one(args->name, &h_path);
8025 + h_dentry = au_sio_lkup_one(h_userns, args->name, &h_path);
8026 + if (IS_ERR(h_dentry)) {
8027 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8033 + h_inode = d_inode(h_dentry);
8034 + if (d_is_negative(h_dentry)) {
8037 + } else if (wh_found
8038 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8040 + else if (au_ftest_lkup(args->flags, DIRREN)
8042 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8043 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8044 + (unsigned long long)h_inode->i_ino);
8048 + if (au_dbbot(dentry) <= bindex)
8049 + au_set_dbbot(dentry, bindex);
8050 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8051 + au_set_dbtop(dentry, bindex);
8052 + au_set_h_dptr(dentry, bindex, h_dentry);
8054 + if (!d_is_dir(h_dentry)
8056 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8057 + goto out; /* success */
8059 + h_path.dentry = h_dentry;
8060 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8061 + opq = au_diropq_test(h_userns, &h_path);
8062 + inode_unlock_shared(h_inode);
8064 + au_set_dbdiropq(dentry, bindex);
8065 + else if (unlikely(opq < 0)) {
8066 + au_set_h_dptr(dentry, bindex, NULL);
8067 + h_dentry = ERR_PTR(opq);
8078 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8080 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8081 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8087 + * returns the number of lower positive dentries,
8088 + * otherwise an error.
8089 + * can be called at unlinking with @type is zero.
8091 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8092 + unsigned int flags)
8094 + int npositive, err;
8095 + aufs_bindex_t bindex, btail, bdiropq;
8096 + unsigned char isdir, dirperm1, dirren;
8097 + struct au_do_lookup_args args = {
8099 + .name = &dentry->d_name
8101 + struct dentry *parent;
8102 + struct super_block *sb;
8104 + sb = dentry->d_sb;
8105 + err = au_test_shwh(sb, args.name);
8106 + if (unlikely(err))
8109 + err = au_wh_name_alloc(&args.whname, args.name);
8110 + if (unlikely(err))
8113 + isdir = !!d_is_dir(dentry);
8114 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8115 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8117 + au_fset_lkup(args.flags, DIRREN);
8120 + parent = dget_parent(dentry);
8121 + btail = au_dbtaildir(parent);
8122 + for (bindex = btop; bindex <= btail; bindex++) {
8123 + struct dentry *h_parent, *h_dentry;
8124 + struct inode *h_inode, *h_dir;
8125 + struct au_branch *br;
8127 + h_dentry = au_h_dptr(dentry, bindex);
8129 + if (d_is_positive(h_dentry))
8133 + h_parent = au_h_dptr(parent, bindex);
8134 + if (!h_parent || !d_is_dir(h_parent))
8138 + /* if the inum matches, then use the prepared name */
8139 + err = au_dr_lkup_name(&args, bindex);
8140 + if (unlikely(err))
8144 + h_dir = d_inode(h_parent);
8145 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8146 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8147 + inode_unlock_shared(h_dir);
8148 + err = PTR_ERR(h_dentry);
8149 + if (IS_ERR(h_dentry))
8152 + au_fclr_lkup(args.flags, ALLOW_NEG);
8154 + au_fset_lkup(args.flags, IGNORE_PERM);
8156 + if (au_dbwh(dentry) == bindex)
8160 + if (d_is_negative(h_dentry))
8162 + h_inode = d_inode(h_dentry);
8165 + args.type = h_inode->i_mode & S_IFMT;
8166 + if (args.type != S_IFDIR)
8169 + /* the type of lower may be different */
8170 + bdiropq = au_dbdiropq(dentry);
8171 + if (bdiropq >= 0 && bdiropq <= bindex)
8174 + br = au_sbr(sb, bindex);
8176 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8177 + /*add_ent*/NULL)) {
8178 + /* prepare next name to lookup */
8179 + err = au_dr_lkup(&args, dentry, bindex);
8180 + if (unlikely(err))
8186 + AuLabel(positive);
8187 + au_update_dbtop(dentry);
8190 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8191 + && au_dbtop(dentry) < 0)) {
8193 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8199 + au_kfree_try_rcu(args.whname.name);
8201 + au_dr_lkup_fin(&args);
8206 +struct dentry *au_sio_lkup_one(struct user_namespace *userns, struct qstr *name,
8207 + struct path *ppath)
8209 + struct dentry *dentry;
8212 + if (!au_test_h_perm_sio(userns, d_inode(ppath->dentry), MAY_EXEC))
8213 + dentry = vfsub_lkup_one(name, ppath);
8215 + struct vfsub_lkup_one_args args = {
8221 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8222 + if (unlikely(wkq_err))
8223 + dentry = ERR_PTR(wkq_err);
8230 + * lookup @dentry on @bindex which should be negative.
8232 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8235 + struct dentry *parent, *h_dentry;
8236 + struct au_branch *br;
8237 + struct user_namespace *h_userns;
8238 + struct path h_ppath;
8240 + parent = dget_parent(dentry);
8241 + br = au_sbr(dentry->d_sb, bindex);
8242 + h_ppath.dentry = au_h_dptr(parent, bindex);
8243 + h_ppath.mnt = au_br_mnt(br);
8244 + h_userns = au_br_userns(br);
8246 + h_dentry = au_whtmp_lkup(h_ppath.dentry, br, &dentry->d_name);
8248 + h_dentry = au_sio_lkup_one(h_userns, &dentry->d_name, &h_ppath);
8249 + err = PTR_ERR(h_dentry);
8250 + if (IS_ERR(h_dentry))
8252 + if (unlikely(d_is_positive(h_dentry))) {
8254 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8260 + if (bindex < au_dbtop(dentry))
8261 + au_set_dbtop(dentry, bindex);
8262 + if (au_dbbot(dentry) < bindex)
8263 + au_set_dbbot(dentry, bindex);
8264 + au_set_h_dptr(dentry, bindex, h_dentry);
8271 +/* ---------------------------------------------------------------------- */
8273 +/* subset of struct inode */
8275 + unsigned long i_ino;
8276 + /* unsigned int i_nlink; */
8282 + blkcnt_t i_blocks;
8287 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8289 + ia->i_ino = h_inode->i_ino;
8290 + /* ia->i_nlink = h_inode->i_nlink; */
8291 + ia->i_uid = h_inode->i_uid;
8292 + ia->i_gid = h_inode->i_gid;
8293 + ia->i_version = inode_query_iversion(h_inode);
8295 + ia->i_size = h_inode->i_size;
8296 + ia->i_blocks = h_inode->i_blocks;
8298 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8301 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8303 + return ia->i_ino != h_inode->i_ino
8304 + /* || ia->i_nlink != h_inode->i_nlink */
8305 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8306 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8307 + || !inode_eq_iversion(h_inode, ia->i_version)
8309 + || ia->i_size != h_inode->i_size
8310 + || ia->i_blocks != h_inode->i_blocks
8312 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8315 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8316 + struct au_branch *br)
8319 + struct au_iattr ia;
8320 + struct inode *h_inode;
8321 + struct dentry *h_d;
8322 + struct super_block *h_sb;
8323 + struct path h_ppath;
8326 + memset(&ia, -1, sizeof(ia));
8327 + h_sb = h_dentry->d_sb;
8329 + if (d_is_positive(h_dentry)) {
8330 + h_inode = d_inode(h_dentry);
8331 + au_iattr_save(&ia, h_inode);
8332 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8333 + /* nfs d_revalidate may return 0 for negative dentry */
8334 + /* fuse d_revalidate always return 0 for negative dentry */
8337 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8338 + h_ppath.dentry = h_parent;
8339 + h_ppath.mnt = au_br_mnt(br);
8340 + h_d = vfsub_lkup_one(&h_dentry->d_name, &h_ppath);
8341 + err = PTR_ERR(h_d);
8346 + if (unlikely(h_d != h_dentry
8347 + || d_inode(h_d) != h_inode
8348 + || (h_inode && au_iattr_test(&ia, h_inode))))
8349 + err = au_busy_or_stale();
8357 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8358 + struct dentry *h_parent, struct au_branch *br)
8363 + if (udba == AuOpt_UDBA_REVAL
8364 + && !au_test_fs_remote(h_dentry->d_sb)) {
8366 + err = (d_inode(h_dentry->d_parent) != h_dir);
8367 + } else if (udba != AuOpt_UDBA_NONE)
8368 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8373 +/* ---------------------------------------------------------------------- */
8375 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8378 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8379 + struct au_hdentry tmp, *p, *q;
8380 + struct au_dinfo *dinfo;
8381 + struct super_block *sb;
8383 + DiMustWriteLock(dentry);
8385 + sb = dentry->d_sb;
8386 + dinfo = au_di(dentry);
8387 + bbot = dinfo->di_bbot;
8388 + bwh = dinfo->di_bwh;
8389 + bdiropq = dinfo->di_bdiropq;
8390 + bindex = dinfo->di_btop;
8391 + p = au_hdentry(dinfo, bindex);
8392 + for (; bindex <= bbot; bindex++, p++) {
8393 + if (!p->hd_dentry)
8396 + new_bindex = au_br_index(sb, p->hd_id);
8397 + if (new_bindex == bindex)
8400 + if (dinfo->di_bwh == bindex)
8402 + if (dinfo->di_bdiropq == bindex)
8403 + bdiropq = new_bindex;
8404 + if (new_bindex < 0) {
8406 + p->hd_dentry = NULL;
8410 + /* swap two lower dentries, and loop again */
8411 + q = au_hdentry(dinfo, new_bindex);
8415 + if (tmp.hd_dentry) {
8421 + dinfo->di_bwh = -1;
8422 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8423 + dinfo->di_bwh = bwh;
8425 + dinfo->di_bdiropq = -1;
8427 + && bdiropq <= au_sbbot(sb)
8428 + && au_sbr_whable(sb, bdiropq))
8429 + dinfo->di_bdiropq = bdiropq;
8432 + dinfo->di_btop = -1;
8433 + dinfo->di_bbot = -1;
8434 + bbot = au_dbbot(parent);
8436 + p = au_hdentry(dinfo, bindex);
8437 + for (; bindex <= bbot; bindex++, p++)
8438 + if (p->hd_dentry) {
8439 + dinfo->di_btop = bindex;
8443 + if (dinfo->di_btop >= 0) {
8445 + p = au_hdentry(dinfo, bindex);
8446 + for (; bindex >= 0; bindex--, p--)
8447 + if (p->hd_dentry) {
8448 + dinfo->di_bbot = bindex;
8457 +static void au_do_hide(struct dentry *dentry)
8459 + struct inode *inode;
8461 + if (d_really_is_positive(dentry)) {
8462 + inode = d_inode(dentry);
8463 + if (!d_is_dir(dentry)) {
8464 + if (inode->i_nlink && !d_unhashed(dentry))
8465 + drop_nlink(inode);
8467 + clear_nlink(inode);
8468 + /* stop next lookup */
8469 + inode->i_flags |= S_DEAD;
8471 + smp_mb(); /* necessary? */
8476 +static int au_hide_children(struct dentry *parent)
8478 + int err, i, j, ndentry;
8479 + struct au_dcsub_pages dpages;
8480 + struct au_dpage *dpage;
8481 + struct dentry *dentry;
8483 + err = au_dpages_init(&dpages, GFP_NOFS);
8484 + if (unlikely(err))
8486 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8487 + if (unlikely(err))
8490 + /* in reverse order */
8491 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8492 + dpage = dpages.dpages + i;
8493 + ndentry = dpage->ndentry;
8494 + for (j = ndentry - 1; j >= 0; j--) {
8495 + dentry = dpage->dentries[j];
8496 + if (dentry != parent)
8497 + au_do_hide(dentry);
8502 + au_dpages_free(&dpages);
8507 +static void au_hide(struct dentry *dentry)
8511 + AuDbgDentry(dentry);
8512 + if (d_is_dir(dentry)) {
8513 + /* shrink_dcache_parent(dentry); */
8514 + err = au_hide_children(dentry);
8515 + if (unlikely(err))
8516 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8519 + au_do_hide(dentry);
8523 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8525 + * a dirty branch is added
8526 + * - on the top of layers
8527 + * - in the middle of layers
8528 + * - to the bottom of layers
8530 + * on the added branch there exists
8533 + * - a same named entry
8535 + * * negative --> positive
8536 + * * positive --> positive
8537 + * - type is unchanged
8538 + * - type is changed
8540 + * * negative --> negative
8541 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8544 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8545 + struct au_dinfo *tmp)
8548 + aufs_bindex_t bindex, bbot;
8550 + struct dentry *dentry;
8551 + struct inode *inode;
8553 + } orig_h, tmp_h = {
8556 + struct au_hdentry *hd;
8557 + struct inode *inode, *h_inode;
8558 + struct dentry *h_dentry;
8561 + AuDebugOn(dinfo->di_btop < 0);
8563 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8564 + orig_h.inode = NULL;
8565 + if (d_is_positive(orig_h.dentry)) {
8566 + orig_h.inode = d_inode(orig_h.dentry);
8567 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8569 + if (tmp->di_btop >= 0) {
8570 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8571 + if (d_is_positive(tmp_h.dentry)) {
8572 + tmp_h.inode = d_inode(tmp_h.dentry);
8573 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8578 + if (d_really_is_positive(dentry))
8579 + inode = d_inode(dentry);
8580 + if (!orig_h.inode) {
8581 + AuDbg("negative originally\n");
8587 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8588 + AuDebugOn(dinfo->di_bdiropq != -1);
8590 + if (!tmp_h.inode) {
8591 + AuDbg("negative --> negative\n");
8592 + /* should have only one negative lower */
8593 + if (tmp->di_btop >= 0
8594 + && tmp->di_btop < dinfo->di_btop) {
8595 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8596 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8597 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8598 + au_di_cp(dinfo, tmp);
8599 + hd = au_hdentry(tmp, tmp->di_btop);
8600 + au_set_h_dptr(dentry, tmp->di_btop,
8601 + dget(hd->hd_dentry));
8603 + au_dbg_verify_dinode(dentry);
8605 + AuDbg("negative --> positive\n");
8607 + * similar to the behaviour of creating with bypassing
8609 + * unhash it in order to force an error in the
8610 + * succeeding create operation.
8611 + * we should not set S_DEAD here.
8614 + /* au_di_swap(tmp, dinfo); */
8615 + au_dbg_verify_dinode(dentry);
8618 + AuDbg("positive originally\n");
8619 + /* inode may be NULL */
8620 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8621 + if (!tmp_h.inode) {
8622 + AuDbg("positive --> negative\n");
8623 + /* or bypassing aufs */
8625 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8626 + dinfo->di_bwh = tmp->di_bwh;
8628 + err = au_refresh_hinode_self(inode);
8629 + au_dbg_verify_dinode(dentry);
8630 + } else if (orig_h.mode == tmp_h.mode) {
8631 + AuDbg("positive --> positive, same type\n");
8632 + if (!S_ISDIR(orig_h.mode)
8633 + && dinfo->di_btop > tmp->di_btop) {
8635 + * similar to the behaviour of removing and
8640 + err = au_refresh_hinode_self(inode);
8641 + au_dbg_verify_dinode(dentry);
8643 + /* fill empty slots */
8644 + if (dinfo->di_btop > tmp->di_btop)
8645 + dinfo->di_btop = tmp->di_btop;
8646 + if (dinfo->di_bbot < tmp->di_bbot)
8647 + dinfo->di_bbot = tmp->di_bbot;
8648 + dinfo->di_bwh = tmp->di_bwh;
8649 + dinfo->di_bdiropq = tmp->di_bdiropq;
8650 + bbot = dinfo->di_bbot;
8651 + bindex = tmp->di_btop;
8652 + hd = au_hdentry(tmp, bindex);
8653 + for (; bindex <= bbot; bindex++, hd++) {
8654 + if (au_h_dptr(dentry, bindex))
8656 + h_dentry = hd->hd_dentry;
8659 + AuDebugOn(d_is_negative(h_dentry));
8660 + h_inode = d_inode(h_dentry);
8661 + AuDebugOn(orig_h.mode
8662 + != (h_inode->i_mode
8664 + au_set_h_dptr(dentry, bindex,
8668 + err = au_refresh_hinode(inode, dentry);
8669 + au_dbg_verify_dinode(dentry);
8672 + AuDbg("positive --> positive, different type\n");
8673 + /* similar to the behaviour of removing and creating */
8676 + err = au_refresh_hinode_self(inode);
8677 + au_dbg_verify_dinode(dentry);
8685 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8687 + const struct dentry_operations *dop
8688 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8689 + static const unsigned int mask
8690 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8692 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8694 + if (dentry->d_op == dop)
8697 + AuDbg("%pd\n", dentry);
8698 + spin_lock(&dentry->d_lock);
8699 + if (dop == &aufs_dop)
8700 + dentry->d_flags |= mask;
8702 + dentry->d_flags &= ~mask;
8703 + dentry->d_op = dop;
8704 + spin_unlock(&dentry->d_lock);
8707 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8709 + int err, ebrange, nbr;
8710 + unsigned int sigen;
8711 + struct au_dinfo *dinfo, *tmp;
8712 + struct super_block *sb;
8713 + struct inode *inode;
8715 + DiMustWriteLock(dentry);
8716 + AuDebugOn(IS_ROOT(dentry));
8717 + AuDebugOn(d_really_is_negative(parent));
8719 + sb = dentry->d_sb;
8720 + sigen = au_sigen(sb);
8721 + err = au_digen_test(parent, sigen);
8722 + if (unlikely(err))
8725 + nbr = au_sbbot(sb) + 1;
8726 + dinfo = au_di(dentry);
8727 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8728 + if (unlikely(err))
8730 + ebrange = au_dbrange_test(dentry);
8732 + ebrange = au_do_refresh_hdentry(dentry, parent);
8734 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8735 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8736 + if (d_really_is_positive(dentry)) {
8737 + inode = d_inode(dentry);
8738 + err = au_refresh_hinode_self(inode);
8740 + au_dbg_verify_dinode(dentry);
8742 + goto out_dgen; /* success */
8746 + /* temporary dinfo */
8747 + AuDbgDentry(dentry);
8749 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8750 + if (unlikely(!tmp))
8752 + au_di_swap(tmp, dinfo);
8753 + /* returns the number of positive dentries */
8755 + * if current working dir is removed, it returns an error.
8756 + * but the dentry is legal.
8758 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8759 + AuDbgDentry(dentry);
8760 + au_di_swap(tmp, dinfo);
8761 + if (err == -ENOENT)
8764 + /* compare/refresh by dinfo */
8765 + AuDbgDentry(dentry);
8766 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8767 + au_dbg_verify_dinode(dentry);
8770 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8771 + au_rw_write_unlock(&tmp->di_rwsem);
8773 + if (unlikely(err))
8777 + au_update_digen(dentry);
8779 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8780 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8781 + AuDbgDentry(dentry);
8787 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8788 + struct dentry *dentry, aufs_bindex_t bindex)
8793 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8796 + AuDbg("b%d\n", bindex);
8798 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8799 + * due to whiteout and branch permission.
8801 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8802 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8803 + /* it may return tri-state */
8804 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8806 + if (unlikely(valid < 0))
8816 +/* todo: remove this */
8817 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8818 + unsigned int flags, int do_udba, int dirren)
8821 + umode_t mode, h_mode;
8822 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8823 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8824 + struct inode *h_inode, *h_cached_inode;
8825 + struct dentry *h_dentry;
8826 + struct qstr *name, *h_name;
8833 + unhashed = !!d_unhashed(dentry);
8834 + is_root = !!IS_ROOT(dentry);
8835 + name = &dentry->d_name;
8836 + tmpfile = au_di(dentry)->di_tmpfile;
8839 + * Theoretically, REVAL test should be unnecessary in case of
8841 + * But {fs,i}notify doesn't fire some necessary events,
8842 + * IN_ATTRIB for atime/nlink/pageio
8843 + * Let's do REVAL test too.
8845 + if (do_udba && inode) {
8846 + mode = (inode->i_mode & S_IFMT);
8847 + plus = (inode->i_nlink > 0);
8848 + ibs = au_ibtop(inode);
8849 + ibe = au_ibbot(inode);
8852 + btop = au_dbtop(dentry);
8854 + if (inode && S_ISDIR(inode->i_mode))
8855 + btail = au_dbtaildir(dentry);
8856 + for (bindex = btop; bindex <= btail; bindex++) {
8857 + h_dentry = au_h_dptr(dentry, bindex);
8861 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8862 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8863 + spin_lock(&h_dentry->d_lock);
8864 + h_name = &h_dentry->d_name;
8865 + if (unlikely(do_udba
8868 + && (unhashed != !!d_unhashed(h_dentry)
8869 + || (!tmpfile && !dirren
8870 + && !au_qstreq(name, h_name))
8873 + && !(flags & LOOKUP_OPEN)
8874 + && (h_dentry->d_flags
8875 + & DCACHE_NFSFS_RENAMED)))
8879 + h_unhashed = d_unhashed(h_dentry);
8880 + spin_unlock(&h_dentry->d_lock);
8881 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8882 + unhashed, h_unhashed, dentry, h_dentry);
8885 + spin_unlock(&h_dentry->d_lock);
8887 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8888 + if (unlikely(err))
8889 + /* do not goto err, to keep the errno */
8892 + /* todo: plink too? */
8897 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8901 + if (d_is_positive(h_dentry))
8902 + h_inode = d_inode(h_dentry);
8905 + h_cached_inode = h_inode;
8907 + h_mode = (h_inode->i_mode & S_IFMT);
8908 + h_plus = (h_inode->i_nlink > 0);
8910 + if (inode && ibs <= bindex && bindex <= ibe)
8911 + h_cached_inode = au_h_iptr(inode, bindex);
8914 + if (unlikely(plus != h_plus && !tmpfile))
8917 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8919 + && !IS_ROOT(h_dentry)
8920 + && unhashed != d_unhashed(h_dentry)))
8923 + if (unlikely(mode != h_mode
8924 + || h_cached_inode != h_inode))
8937 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8938 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8941 + struct dentry *parent;
8943 + if (!au_digen_test(dentry, sigen))
8946 + parent = dget_parent(dentry);
8947 + di_read_lock_parent(parent, AuLock_IR);
8948 + AuDebugOn(au_digen_test(parent, sigen));
8949 + au_dbg_verify_gen(parent, sigen);
8950 + err = au_refresh_dentry(dentry, parent);
8951 + di_read_unlock(parent, AuLock_IR);
8957 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8960 + struct dentry *d, *parent;
8962 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8963 + return simple_reval_dpath(dentry, sigen);
8965 + /* slow loop, keep it simple and stupid */
8966 + /* cf: au_cpup_dirs() */
8969 + while (au_digen_test(dentry, sigen)) {
8973 + parent = dget_parent(d);
8974 + if (!au_digen_test(parent, sigen))
8980 + di_write_lock_child2(d);
8982 + /* someone might update our dentry while we were sleeping */
8983 + if (au_digen_test(d, sigen)) {
8985 + * todo: consolidate with simple_reval_dpath(),
8986 + * do_refresh() and au_reval_for_attr().
8988 + di_read_lock_parent(parent, AuLock_IR);
8989 + err = au_refresh_dentry(d, parent);
8990 + di_read_unlock(parent, AuLock_IR);
8994 + di_write_unlock(d);
8996 + if (unlikely(err))
9004 + * if valid returns 1, otherwise 0.
9006 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9009 + unsigned int sigen;
9010 + unsigned char do_udba, dirren;
9011 + struct super_block *sb;
9012 + struct inode *inode;
9014 + /* todo: support rcu-walk? */
9015 + if (flags & LOOKUP_RCU)
9019 + if (unlikely(!au_di(dentry)))
9023 + sb = dentry->d_sb;
9026 + * i_mutex of parent dir may be held,
9027 + * but we should not return 'invalid' due to busy.
9029 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9030 + if (unlikely(err)) {
9036 + if (d_really_is_positive(dentry))
9037 + inode = d_inode(dentry);
9038 + if (unlikely(inode && au_is_bad_inode(inode))) {
9043 + if (unlikely(au_dbrange_test(dentry))) {
9049 + sigen = au_sigen(sb);
9050 + if (au_digen_test(dentry, sigen)) {
9051 + AuDebugOn(IS_ROOT(dentry));
9052 + err = au_reval_dpath(dentry, sigen);
9053 + if (unlikely(err)) {
9058 + di_downgrade_lock(dentry, AuLock_IR);
9061 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9063 + && !(inode->i_state && I_LINKABLE)
9064 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9069 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9070 + if (do_udba && inode) {
9071 + aufs_bindex_t btop = au_ibtop(inode);
9072 + struct inode *h_inode;
9075 + h_inode = au_h_iptr(inode, btop);
9076 + if (h_inode && au_test_higen(inode, h_inode)) {
9083 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9084 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9085 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9087 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9093 + di_downgrade_lock(dentry, AuLock_IR);
9095 + aufs_read_unlock(dentry, AuLock_IR);
9100 + AuDbg("%pd invalid, %d\n", dentry, valid);
9106 +static void aufs_d_release(struct dentry *dentry)
9108 + if (au_di(dentry)) {
9109 + au_di_fin(dentry);
9110 + au_hn_di_reinit(dentry);
9114 +const struct dentry_operations aufs_dop = {
9115 + .d_revalidate = aufs_d_revalidate,
9116 + .d_weak_revalidate = aufs_d_revalidate,
9117 + .d_release = aufs_d_release
9120 +/* aufs_dop without d_revalidate */
9121 +const struct dentry_operations aufs_dop_noreval = {
9122 + .d_release = aufs_d_release
9124 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9125 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9126 +++ linux/fs/aufs/dentry.h 2022-11-05 23:02:18.962555950 +0100
9128 +/* SPDX-License-Identifier: GPL-2.0 */
9130 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9132 + * This program is free software; you can redistribute it and/or modify
9133 + * it under the terms of the GNU General Public License as published by
9134 + * the Free Software Foundation; either version 2 of the License, or
9135 + * (at your option) any later version.
9137 + * This program is distributed in the hope that it will be useful,
9138 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9139 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9140 + * GNU General Public License for more details.
9142 + * You should have received a copy of the GNU General Public License
9143 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9147 + * lookup and dentry operations
9150 +#ifndef __AUFS_DENTRY_H__
9151 +#define __AUFS_DENTRY_H__
9155 +#include <linux/dcache.h>
9156 +#include "dirren.h"
9159 +struct au_hdentry {
9160 + struct dentry *hd_dentry;
9161 + aufs_bindex_t hd_id;
9165 + atomic_t di_generation;
9167 + struct au_rwsem di_rwsem;
9168 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9169 + unsigned char di_tmpfile; /* to allow the different name */
9170 + struct au_hdentry *di_hdentry;
9171 + struct rcu_head rcu;
9172 +} ____cacheline_aligned_in_smp;
9174 +/* ---------------------------------------------------------------------- */
9176 +/* flags for au_lkup_dentry() */
9177 +#define AuLkup_ALLOW_NEG 1
9178 +#define AuLkup_IGNORE_PERM (1 << 1)
9179 +#define AuLkup_DIRREN (1 << 2)
9180 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9181 +#define au_fset_lkup(flags, name) \
9182 + do { (flags) |= AuLkup_##name; } while (0)
9183 +#define au_fclr_lkup(flags, name) \
9184 + do { (flags) &= ~AuLkup_##name; } while (0)
9186 +#ifndef CONFIG_AUFS_DIRREN
9187 +#undef AuLkup_DIRREN
9188 +#define AuLkup_DIRREN 0
9191 +struct au_do_lookup_args {
9192 + unsigned int flags;
9194 + struct qstr whname, *name;
9195 + struct au_dr_lookup dirren;
9198 +/* ---------------------------------------------------------------------- */
9201 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9203 +struct dentry *au_sio_lkup_one(struct user_namespace *userns, struct qstr *name,
9204 + struct path *ppath);
9205 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9206 + struct dentry *h_parent, struct au_branch *br);
9208 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9209 + unsigned int flags);
9210 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9211 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9212 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9213 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9216 +void au_di_init_once(void *_di);
9217 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9218 +void au_di_free(struct au_dinfo *dinfo);
9219 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9220 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9221 +int au_di_init(struct dentry *dentry);
9222 +void au_di_fin(struct dentry *dentry);
9223 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9225 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9226 +void di_read_unlock(struct dentry *d, int flags);
9227 +void di_downgrade_lock(struct dentry *d, int flags);
9228 +void di_write_lock(struct dentry *d, unsigned int lsc);
9229 +void di_write_unlock(struct dentry *d);
9230 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9231 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9232 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9234 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9235 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9236 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9237 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9239 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9240 + struct dentry *h_dentry);
9241 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9242 +int au_dbrange_test(struct dentry *dentry);
9243 +void au_update_digen(struct dentry *dentry);
9244 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9245 +void au_update_dbtop(struct dentry *dentry);
9246 +void au_update_dbbot(struct dentry *dentry);
9247 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9249 +/* ---------------------------------------------------------------------- */
9251 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9253 + return dentry->d_fsdata;
9256 +/* ---------------------------------------------------------------------- */
9258 +/* lock subclass for dinfo */
9260 + AuLsc_DI_CHILD, /* child first */
9261 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9262 + AuLsc_DI_CHILD3, /* copyup dirs */
9266 + AuLsc_DI_TMP /* temp for replacing dinfo */
9270 + * di_read_lock_child, di_write_lock_child,
9271 + * di_read_lock_child2, di_write_lock_child2,
9272 + * di_read_lock_child3, di_write_lock_child3,
9273 + * di_read_lock_parent, di_write_lock_parent,
9274 + * di_read_lock_parent2, di_write_lock_parent2,
9275 + * di_read_lock_parent3, di_write_lock_parent3,
9277 +#define AuReadLockFunc(name, lsc) \
9278 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9279 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9281 +#define AuWriteLockFunc(name, lsc) \
9282 +static inline void di_write_lock_##name(struct dentry *d) \
9283 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9285 +#define AuRWLockFuncs(name, lsc) \
9286 + AuReadLockFunc(name, lsc) \
9287 + AuWriteLockFunc(name, lsc)
9289 +AuRWLockFuncs(child, CHILD);
9290 +AuRWLockFuncs(child2, CHILD2);
9291 +AuRWLockFuncs(child3, CHILD3);
9292 +AuRWLockFuncs(parent, PARENT);
9293 +AuRWLockFuncs(parent2, PARENT2);
9294 +AuRWLockFuncs(parent3, PARENT3);
9296 +#undef AuReadLockFunc
9297 +#undef AuWriteLockFunc
9298 +#undef AuRWLockFuncs
9300 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9301 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9302 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9304 +/* ---------------------------------------------------------------------- */
9306 +/* todo: memory barrier? */
9307 +static inline unsigned int au_digen(struct dentry *d)
9309 + return atomic_read(&au_di(d)->di_generation);
9312 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9314 + hdentry->hd_dentry = NULL;
9317 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9318 + aufs_bindex_t bindex)
9320 + return di->di_hdentry + bindex;
9323 +static inline void au_hdput(struct au_hdentry *hd)
9326 + dput(hd->hd_dentry);
9329 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9331 + DiMustAnyLock(dentry);
9332 + return au_di(dentry)->di_btop;
9335 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9337 + DiMustAnyLock(dentry);
9338 + return au_di(dentry)->di_bbot;
9341 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9343 + DiMustAnyLock(dentry);
9344 + return au_di(dentry)->di_bwh;
9347 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9349 + DiMustAnyLock(dentry);
9350 + return au_di(dentry)->di_bdiropq;
9353 +/* todo: hard/soft set? */
9354 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9356 + DiMustWriteLock(dentry);
9357 + au_di(dentry)->di_btop = bindex;
9360 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9362 + DiMustWriteLock(dentry);
9363 + au_di(dentry)->di_bbot = bindex;
9366 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9368 + DiMustWriteLock(dentry);
9369 + /* dbwh can be outside of btop - bbot range */
9370 + au_di(dentry)->di_bwh = bindex;
9373 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9375 + DiMustWriteLock(dentry);
9376 + au_di(dentry)->di_bdiropq = bindex;
9379 +/* ---------------------------------------------------------------------- */
9381 +#ifdef CONFIG_AUFS_HNOTIFY
9382 +static inline void au_digen_dec(struct dentry *d)
9384 + atomic_dec(&au_di(d)->di_generation);
9387 +static inline void au_hn_di_reinit(struct dentry *dentry)
9389 + dentry->d_fsdata = NULL;
9392 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9393 +#endif /* CONFIG_AUFS_HNOTIFY */
9395 +#endif /* __KERNEL__ */
9396 +#endif /* __AUFS_DENTRY_H__ */
9397 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9398 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9399 +++ linux/fs/aufs/dinfo.c 2022-11-05 23:02:18.962555950 +0100
9401 +// SPDX-License-Identifier: GPL-2.0
9403 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9405 + * This program is free software; you can redistribute it and/or modify
9406 + * it under the terms of the GNU General Public License as published by
9407 + * the Free Software Foundation; either version 2 of the License, or
9408 + * (at your option) any later version.
9410 + * This program is distributed in the hope that it will be useful,
9411 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9412 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9413 + * GNU General Public License for more details.
9415 + * You should have received a copy of the GNU General Public License
9416 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9420 + * dentry private data
9425 +void au_di_init_once(void *_dinfo)
9427 + struct au_dinfo *dinfo = _dinfo;
9429 + au_rw_init(&dinfo->di_rwsem);
9432 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9434 + struct au_dinfo *dinfo;
9437 + dinfo = au_cache_alloc_dinfo();
9438 + if (unlikely(!dinfo))
9441 + nbr = au_sbbot(sb) + 1;
9444 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9445 + if (dinfo->di_hdentry) {
9446 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9447 + dinfo->di_btop = -1;
9448 + dinfo->di_bbot = -1;
9449 + dinfo->di_bwh = -1;
9450 + dinfo->di_bdiropq = -1;
9451 + dinfo->di_tmpfile = 0;
9452 + for (i = 0; i < nbr; i++)
9453 + dinfo->di_hdentry[i].hd_id = -1;
9457 + au_cache_free_dinfo(dinfo);
9464 +void au_di_free(struct au_dinfo *dinfo)
9466 + struct au_hdentry *p;
9467 + aufs_bindex_t bbot, bindex;
9469 + /* dentry may not be revalidated */
9470 + bindex = dinfo->di_btop;
9471 + if (bindex >= 0) {
9472 + bbot = dinfo->di_bbot;
9473 + p = au_hdentry(dinfo, bindex);
9474 + while (bindex++ <= bbot)
9477 + au_kfree_try_rcu(dinfo->di_hdentry);
9478 + au_cache_free_dinfo(dinfo);
9481 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9483 + struct au_hdentry *p;
9486 + AuRwMustWriteLock(&a->di_rwsem);
9487 + AuRwMustWriteLock(&b->di_rwsem);
9489 +#define DiSwap(v, name) \
9491 + v = a->di_##name; \
9492 + a->di_##name = b->di_##name; \
9493 + b->di_##name = v; \
9496 + DiSwap(p, hdentry);
9500 + DiSwap(bi, bdiropq);
9506 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9508 + AuRwMustWriteLock(&dst->di_rwsem);
9509 + AuRwMustWriteLock(&src->di_rwsem);
9511 + dst->di_btop = src->di_btop;
9512 + dst->di_bbot = src->di_bbot;
9513 + dst->di_bwh = src->di_bwh;
9514 + dst->di_bdiropq = src->di_bdiropq;
9518 +int au_di_init(struct dentry *dentry)
9521 + struct super_block *sb;
9522 + struct au_dinfo *dinfo;
9525 + sb = dentry->d_sb;
9526 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9528 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9529 + /* smp_mb(); */ /* atomic_set */
9530 + dentry->d_fsdata = dinfo;
9537 +void au_di_fin(struct dentry *dentry)
9539 + struct au_dinfo *dinfo;
9541 + dinfo = au_di(dentry);
9542 + AuRwDestroy(&dinfo->di_rwsem);
9543 + au_di_free(dinfo);
9546 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9549 + struct au_hdentry *hdp;
9551 + AuRwMustWriteLock(&dinfo->di_rwsem);
9554 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9556 + sz = sizeof(*hdp);
9557 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9560 + dinfo->di_hdentry = hdp;
9567 +/* ---------------------------------------------------------------------- */
9569 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9572 + case AuLsc_DI_CHILD:
9573 + ii_write_lock_child(inode);
9575 + case AuLsc_DI_CHILD2:
9576 + ii_write_lock_child2(inode);
9578 + case AuLsc_DI_CHILD3:
9579 + ii_write_lock_child3(inode);
9581 + case AuLsc_DI_PARENT:
9582 + ii_write_lock_parent(inode);
9584 + case AuLsc_DI_PARENT2:
9585 + ii_write_lock_parent2(inode);
9587 + case AuLsc_DI_PARENT3:
9588 + ii_write_lock_parent3(inode);
9595 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9598 + case AuLsc_DI_CHILD:
9599 + ii_read_lock_child(inode);
9601 + case AuLsc_DI_CHILD2:
9602 + ii_read_lock_child2(inode);
9604 + case AuLsc_DI_CHILD3:
9605 + ii_read_lock_child3(inode);
9607 + case AuLsc_DI_PARENT:
9608 + ii_read_lock_parent(inode);
9610 + case AuLsc_DI_PARENT2:
9611 + ii_read_lock_parent2(inode);
9613 + case AuLsc_DI_PARENT3:
9614 + ii_read_lock_parent3(inode);
9621 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9623 + struct inode *inode;
9625 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9626 + if (d_really_is_positive(d)) {
9627 + inode = d_inode(d);
9628 + if (au_ftest_lock(flags, IW))
9629 + do_ii_write_lock(inode, lsc);
9630 + else if (au_ftest_lock(flags, IR))
9631 + do_ii_read_lock(inode, lsc);
9635 +void di_read_unlock(struct dentry *d, int flags)
9637 + struct inode *inode;
9639 + if (d_really_is_positive(d)) {
9640 + inode = d_inode(d);
9641 + if (au_ftest_lock(flags, IW)) {
9642 + au_dbg_verify_dinode(d);
9643 + ii_write_unlock(inode);
9644 + } else if (au_ftest_lock(flags, IR)) {
9645 + au_dbg_verify_dinode(d);
9646 + ii_read_unlock(inode);
9649 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9652 +void di_downgrade_lock(struct dentry *d, int flags)
9654 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9655 + ii_downgrade_lock(d_inode(d));
9656 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9659 +void di_write_lock(struct dentry *d, unsigned int lsc)
9661 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9662 + if (d_really_is_positive(d))
9663 + do_ii_write_lock(d_inode(d), lsc);
9666 +void di_write_unlock(struct dentry *d)
9668 + au_dbg_verify_dinode(d);
9669 + if (d_really_is_positive(d))
9670 + ii_write_unlock(d_inode(d));
9671 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9674 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9676 + AuDebugOn(d1 == d2
9677 + || d_inode(d1) == d_inode(d2)
9678 + || d1->d_sb != d2->d_sb);
9680 + if ((isdir && au_test_subdir(d1, d2))
9682 + di_write_lock_child(d1);
9683 + di_write_lock_child2(d2);
9685 + di_write_lock_child(d2);
9686 + di_write_lock_child2(d1);
9690 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9692 + AuDebugOn(d1 == d2
9693 + || d_inode(d1) == d_inode(d2)
9694 + || d1->d_sb != d2->d_sb);
9696 + if ((isdir && au_test_subdir(d1, d2))
9698 + di_write_lock_parent(d1);
9699 + di_write_lock_parent2(d2);
9701 + di_write_lock_parent(d2);
9702 + di_write_lock_parent2(d1);
9706 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9708 + di_write_unlock(d1);
9709 + if (d_inode(d1) == d_inode(d2))
9710 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9712 + di_write_unlock(d2);
9715 +/* ---------------------------------------------------------------------- */
9717 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9721 + DiMustAnyLock(dentry);
9723 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9725 + AuDebugOn(bindex < 0);
9726 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9727 + AuDebugOn(d && au_dcount(d) <= 0);
9732 + * extended version of au_h_dptr().
9733 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9736 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9738 + struct dentry *h_dentry;
9739 + struct inode *inode, *h_inode;
9741 + AuDebugOn(d_really_is_negative(dentry));
9744 + if (au_dbtop(dentry) <= bindex
9745 + && bindex <= au_dbbot(dentry))
9746 + h_dentry = au_h_dptr(dentry, bindex);
9747 + if (h_dentry && !au_d_linkable(h_dentry)) {
9749 + goto out; /* success */
9752 + inode = d_inode(dentry);
9753 + AuDebugOn(bindex < au_ibtop(inode));
9754 + AuDebugOn(au_ibbot(inode) < bindex);
9755 + h_inode = au_h_iptr(inode, bindex);
9756 + h_dentry = d_find_alias(h_inode);
9758 + if (!IS_ERR(h_dentry)) {
9759 + if (!au_d_linkable(h_dentry))
9760 + goto out; /* success */
9766 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9767 + h_dentry = au_plink_lkup(inode, bindex);
9768 + AuDebugOn(!h_dentry);
9769 + if (!IS_ERR(h_dentry)) {
9770 + if (!au_d_hashed_positive(h_dentry))
9771 + goto out; /* success */
9778 + AuDbgDentry(h_dentry);
9782 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9784 + aufs_bindex_t bbot, bwh;
9786 + bbot = au_dbbot(dentry);
9788 + bwh = au_dbwh(dentry);
9791 + if (0 < bwh && bwh < bbot)
9797 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9799 + aufs_bindex_t bbot, bopq;
9801 + bbot = au_dbtail(dentry);
9803 + bopq = au_dbdiropq(dentry);
9804 + if (0 <= bopq && bopq < bbot)
9810 +/* ---------------------------------------------------------------------- */
9812 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9813 + struct dentry *h_dentry)
9815 + struct au_dinfo *dinfo;
9816 + struct au_hdentry *hd;
9817 + struct au_branch *br;
9819 + DiMustWriteLock(dentry);
9821 + dinfo = au_di(dentry);
9822 + hd = au_hdentry(dinfo, bindex);
9824 + hd->hd_dentry = h_dentry;
9826 + br = au_sbr(dentry->d_sb, bindex);
9827 + hd->hd_id = br->br_id;
9831 +int au_dbrange_test(struct dentry *dentry)
9834 + aufs_bindex_t btop, bbot;
9837 + btop = au_dbtop(dentry);
9838 + bbot = au_dbbot(dentry);
9840 + AuDebugOn(bbot < 0 && btop > bbot);
9843 + AuDebugOn(bbot >= 0);
9849 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9854 + if (unlikely(au_digen(dentry) != sigen
9855 + || au_iigen_test(d_inode(dentry), sigen)))
9861 +void au_update_digen(struct dentry *dentry)
9863 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9864 + /* smp_mb(); */ /* atomic_set */
9867 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9869 + struct au_dinfo *dinfo;
9870 + struct dentry *h_d;
9871 + struct au_hdentry *hdp;
9872 + aufs_bindex_t bindex, bbot;
9874 + DiMustWriteLock(dentry);
9876 + dinfo = au_di(dentry);
9877 + if (!dinfo || dinfo->di_btop < 0)
9880 + if (do_put_zero) {
9881 + bbot = dinfo->di_bbot;
9882 + bindex = dinfo->di_btop;
9883 + hdp = au_hdentry(dinfo, bindex);
9884 + for (; bindex <= bbot; bindex++, hdp++) {
9885 + h_d = hdp->hd_dentry;
9886 + if (h_d && d_is_negative(h_d))
9887 + au_set_h_dptr(dentry, bindex, NULL);
9891 + dinfo->di_btop = 0;
9892 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9893 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9894 + if (hdp->hd_dentry)
9896 + if (dinfo->di_btop > dinfo->di_bbot) {
9897 + dinfo->di_btop = -1;
9898 + dinfo->di_bbot = -1;
9902 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9903 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9904 + if (hdp->hd_dentry)
9906 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9909 +void au_update_dbtop(struct dentry *dentry)
9911 + aufs_bindex_t bindex, bbot;
9912 + struct dentry *h_dentry;
9914 + bbot = au_dbbot(dentry);
9915 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9916 + h_dentry = au_h_dptr(dentry, bindex);
9919 + if (d_is_positive(h_dentry)) {
9920 + au_set_dbtop(dentry, bindex);
9923 + au_set_h_dptr(dentry, bindex, NULL);
9927 +void au_update_dbbot(struct dentry *dentry)
9929 + aufs_bindex_t bindex, btop;
9930 + struct dentry *h_dentry;
9932 + btop = au_dbtop(dentry);
9933 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9934 + h_dentry = au_h_dptr(dentry, bindex);
9937 + if (d_is_positive(h_dentry)) {
9938 + au_set_dbbot(dentry, bindex);
9941 + au_set_h_dptr(dentry, bindex, NULL);
9945 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9947 + aufs_bindex_t bindex, bbot;
9949 + bbot = au_dbbot(dentry);
9950 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9951 + if (au_h_dptr(dentry, bindex) == h_dentry)
9955 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9956 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9957 +++ linux/fs/aufs/dir.c 2022-11-05 23:02:18.962555950 +0100
9959 +// SPDX-License-Identifier: GPL-2.0
9961 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9963 + * This program is free software; you can redistribute it and/or modify
9964 + * it under the terms of the GNU General Public License as published by
9965 + * the Free Software Foundation; either version 2 of the License, or
9966 + * (at your option) any later version.
9968 + * This program is distributed in the hope that it will be useful,
9969 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9970 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9971 + * GNU General Public License for more details.
9973 + * You should have received a copy of the GNU General Public License
9974 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9978 + * directory operations
9981 +#include <linux/fs_stack.h>
9982 +#include <linux/iversion.h>
9985 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9987 + unsigned int nlink;
9989 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9991 + nlink = dir->i_nlink;
9992 + nlink += h_dir->i_nlink - 2;
9993 + if (h_dir->i_nlink < 2)
9995 + smp_mb(); /* for i_nlink */
9996 + /* 0 can happen in revaliding */
9997 + set_nlink(dir, nlink);
10000 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10002 + unsigned int nlink;
10004 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10006 + nlink = dir->i_nlink;
10007 + nlink -= h_dir->i_nlink - 2;
10008 + if (h_dir->i_nlink < 2)
10010 + smp_mb(); /* for i_nlink */
10011 + /* nlink == 0 means the branch-fs is broken */
10012 + set_nlink(dir, nlink);
10015 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10018 + aufs_bindex_t bindex, bbot;
10019 + struct file *h_file;
10020 + struct dentry *h_dentry;
10024 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10026 + bbot = au_fbbot_dir(file);
10027 + for (bindex = au_fbtop(file);
10028 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10030 + h_file = au_hf_dir(file, bindex);
10031 + if (h_file && file_inode(h_file))
10032 + sz += vfsub_f_size_read(h_file);
10035 + AuDebugOn(!dentry);
10036 + AuDebugOn(!d_is_dir(dentry));
10038 + bbot = au_dbtaildir(dentry);
10039 + for (bindex = au_dbtop(dentry);
10040 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10042 + h_dentry = au_h_dptr(dentry, bindex);
10043 + if (h_dentry && d_is_positive(h_dentry))
10044 + sz += i_size_read(d_inode(h_dentry));
10047 + if (sz < KMALLOC_MAX_SIZE)
10048 + sz = roundup_pow_of_two(sz);
10049 + if (sz > KMALLOC_MAX_SIZE)
10050 + sz = KMALLOC_MAX_SIZE;
10051 + else if (sz < NAME_MAX) {
10052 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10053 + sz = AUFS_RDBLK_DEF;
10058 +struct au_dir_ts_arg {
10059 + struct dentry *dentry;
10060 + aufs_bindex_t brid;
10063 +static void au_do_dir_ts(void *arg)
10065 + struct au_dir_ts_arg *a = arg;
10066 + struct au_dtime dt;
10067 + struct path h_path;
10068 + struct inode *dir, *h_dir;
10069 + struct super_block *sb;
10070 + struct au_branch *br;
10071 + struct au_hinode *hdir;
10073 + aufs_bindex_t btop, bindex;
10075 + sb = a->dentry->d_sb;
10076 + if (d_really_is_negative(a->dentry))
10078 + /* no dir->i_mutex lock */
10079 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10081 + dir = d_inode(a->dentry);
10082 + btop = au_ibtop(dir);
10083 + bindex = au_br_index(sb, a->brid);
10084 + if (bindex < btop)
10087 + br = au_sbr(sb, bindex);
10088 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10089 + if (!h_path.dentry)
10091 + h_path.mnt = au_br_mnt(br);
10092 + au_dtime_store(&dt, a->dentry, &h_path);
10094 + br = au_sbr(sb, btop);
10095 + if (!au_br_writable(br->br_perm))
10097 + h_path.dentry = au_h_dptr(a->dentry, btop);
10098 + h_path.mnt = au_br_mnt(br);
10099 + err = vfsub_mnt_want_write(h_path.mnt);
10102 + hdir = au_hi(dir, btop);
10103 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10104 + h_dir = au_h_iptr(dir, btop);
10105 + if (h_dir->i_nlink
10106 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10107 + dt.dt_h_path = h_path;
10108 + au_dtime_revert(&dt);
10110 + au_hn_inode_unlock(hdir);
10111 + vfsub_mnt_drop_write(h_path.mnt);
10112 + au_cpup_attr_timesizes(dir);
10115 + aufs_read_unlock(a->dentry, AuLock_DW);
10118 + au_nwt_done(&au_sbi(sb)->si_nowait);
10119 + au_kfree_try_rcu(arg);
10122 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10124 + int perm, wkq_err;
10125 + aufs_bindex_t btop;
10126 + struct au_dir_ts_arg *arg;
10127 + struct dentry *dentry;
10128 + struct super_block *sb;
10132 + dentry = d_find_any_alias(dir);
10133 + AuDebugOn(!dentry);
10134 + sb = dentry->d_sb;
10135 + btop = au_ibtop(dir);
10136 + if (btop == bindex) {
10137 + au_cpup_attr_timesizes(dir);
10141 + perm = au_sbr_perm(sb, btop);
10142 + if (!au_br_writable(perm))
10145 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10149 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10150 + arg->brid = au_sbr_id(sb, bindex);
10151 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10152 + if (unlikely(wkq_err)) {
10153 + pr_err("wkq %d\n", wkq_err);
10155 + au_kfree_try_rcu(arg);
10162 +/* ---------------------------------------------------------------------- */
10164 +static int reopen_dir(struct file *file)
10167 + unsigned int flags;
10168 + aufs_bindex_t bindex, btail, btop;
10169 + struct dentry *dentry, *h_dentry;
10170 + struct file *h_file;
10172 + /* open all lower dirs */
10173 + dentry = file->f_path.dentry;
10174 + btop = au_dbtop(dentry);
10175 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10176 + au_set_h_fptr(file, bindex, NULL);
10177 + au_set_fbtop(file, btop);
10179 + btail = au_dbtaildir(dentry);
10180 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10181 + au_set_h_fptr(file, bindex, NULL);
10182 + au_set_fbbot_dir(file, btail);
10184 + flags = vfsub_file_flags(file);
10185 + for (bindex = btop; bindex <= btail; bindex++) {
10186 + h_dentry = au_h_dptr(dentry, bindex);
10189 + h_file = au_hf_dir(file, bindex);
10193 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10194 + err = PTR_ERR(h_file);
10195 + if (IS_ERR(h_file))
10196 + goto out; /* close all? */
10197 + au_set_h_fptr(file, bindex, h_file);
10199 + au_update_figen(file);
10200 + /* todo: necessary? */
10201 + /* file->f_ra = h_file->f_ra; */
10208 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10211 + aufs_bindex_t bindex, btail;
10212 + struct dentry *dentry, *h_dentry;
10213 + struct vfsmount *mnt;
10215 + FiMustWriteLock(file);
10216 + AuDebugOn(h_file);
10219 + mnt = file->f_path.mnt;
10220 + dentry = file->f_path.dentry;
10221 + file->f_version = inode_query_iversion(d_inode(dentry));
10222 + bindex = au_dbtop(dentry);
10223 + au_set_fbtop(file, bindex);
10224 + btail = au_dbtaildir(dentry);
10225 + au_set_fbbot_dir(file, btail);
10226 + for (; !err && bindex <= btail; bindex++) {
10227 + h_dentry = au_h_dptr(dentry, bindex);
10231 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10232 + if (unlikely(err))
10234 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10235 + if (IS_ERR(h_file)) {
10236 + err = PTR_ERR(h_file);
10239 + au_set_h_fptr(file, bindex, h_file);
10241 + au_update_figen(file);
10242 + /* todo: necessary? */
10243 + /* file->f_ra = h_file->f_ra; */
10245 + return 0; /* success */
10248 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10249 + au_set_h_fptr(file, bindex, NULL);
10250 + au_set_fbtop(file, -1);
10251 + au_set_fbbot_dir(file, -1);
10256 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10257 + struct file *file)
10260 + struct super_block *sb;
10261 + struct au_fidir *fidir;
10264 + sb = file->f_path.dentry->d_sb;
10265 + si_read_lock(sb, AuLock_FLUSH);
10266 + fidir = au_fidir_alloc(sb);
10268 + struct au_do_open_args args = {
10269 + .open = do_open_dir,
10272 + err = au_do_open(file, &args);
10273 + if (unlikely(err))
10274 + au_kfree_rcu(fidir);
10276 + si_read_unlock(sb);
10280 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10281 + struct file *file)
10283 + struct au_vdir *vdir_cache;
10284 + struct au_finfo *finfo;
10285 + struct au_fidir *fidir;
10286 + struct au_hfile *hf;
10287 + aufs_bindex_t bindex, bbot;
10289 + finfo = au_fi(file);
10290 + fidir = finfo->fi_hdir;
10292 + au_hbl_del(&finfo->fi_hlist,
10293 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10294 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10296 + au_vdir_free(vdir_cache);
10298 + bindex = finfo->fi_btop;
10299 + if (bindex >= 0) {
10300 + hf = fidir->fd_hfile + bindex;
10302 + * calls fput() instead of filp_close(),
10303 + * since no dnotify or lock for the lower file.
10305 + bbot = fidir->fd_bbot;
10306 + for (; bindex <= bbot; bindex++, hf++)
10308 + au_hfput(hf, /*execed*/0);
10310 + au_kfree_rcu(fidir);
10311 + finfo->fi_hdir = NULL;
10313 + au_finfo_fin(file);
10317 +/* ---------------------------------------------------------------------- */
10319 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10322 + aufs_bindex_t bindex, bbot;
10323 + struct file *h_file;
10326 + bbot = au_fbbot_dir(file);
10327 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10328 + h_file = au_hf_dir(file, bindex);
10330 + err = vfsub_flush(h_file, id);
10335 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10337 + return au_do_flush(file, id, au_do_flush_dir);
10340 +/* ---------------------------------------------------------------------- */
10342 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10345 + aufs_bindex_t bbot, bindex;
10346 + struct inode *inode;
10347 + struct super_block *sb;
10350 + sb = dentry->d_sb;
10351 + inode = d_inode(dentry);
10352 + IMustLock(inode);
10353 + bbot = au_dbbot(dentry);
10354 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10355 + struct path h_path;
10357 + if (au_test_ro(sb, bindex, inode))
10359 + h_path.dentry = au_h_dptr(dentry, bindex);
10360 + if (!h_path.dentry)
10363 + h_path.mnt = au_sbr_mnt(sb, bindex);
10364 + err = vfsub_fsync(NULL, &h_path, datasync);
10370 +static int au_do_fsync_dir(struct file *file, int datasync)
10373 + aufs_bindex_t bbot, bindex;
10374 + struct file *h_file;
10375 + struct super_block *sb;
10376 + struct inode *inode;
10378 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10379 + if (unlikely(err))
10382 + inode = file_inode(file);
10383 + sb = inode->i_sb;
10384 + bbot = au_fbbot_dir(file);
10385 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10386 + h_file = au_hf_dir(file, bindex);
10387 + if (!h_file || au_test_ro(sb, bindex, inode))
10390 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10398 + * @file may be NULL
10400 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10404 + struct dentry *dentry;
10405 + struct inode *inode;
10406 + struct super_block *sb;
10409 + dentry = file->f_path.dentry;
10410 + inode = d_inode(dentry);
10411 + inode_lock(inode);
10412 + sb = dentry->d_sb;
10413 + si_noflush_read_lock(sb);
10415 + err = au_do_fsync_dir(file, datasync);
10417 + di_write_lock_child(dentry);
10418 + err = au_do_fsync_dir_no_file(dentry, datasync);
10420 + au_cpup_attr_timesizes(inode);
10421 + di_write_unlock(dentry);
10423 + fi_write_unlock(file);
10425 + si_read_unlock(sb);
10426 + inode_unlock(inode);
10430 +/* ---------------------------------------------------------------------- */
10432 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10435 + struct dentry *dentry;
10436 + struct inode *inode, *h_inode;
10437 + struct super_block *sb;
10439 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10441 + dentry = file->f_path.dentry;
10442 + inode = d_inode(dentry);
10443 + IMustLock(inode);
10445 + sb = dentry->d_sb;
10446 + si_read_lock(sb, AuLock_FLUSH);
10447 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10448 + if (unlikely(err))
10450 + err = au_alive_dir(dentry);
10452 + err = au_vdir_init(file);
10453 + di_downgrade_lock(dentry, AuLock_IR);
10454 + if (unlikely(err))
10457 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10458 + if (!au_test_nfsd()) {
10459 + err = au_vdir_fill_de(file, ctx);
10460 + fsstack_copy_attr_atime(inode, h_inode);
10463 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10464 + * encode_fh() and others.
10466 + atomic_inc(&h_inode->i_count);
10467 + di_read_unlock(dentry, AuLock_IR);
10468 + si_read_unlock(sb);
10469 + err = au_vdir_fill_de(file, ctx);
10470 + fsstack_copy_attr_atime(inode, h_inode);
10471 + fi_write_unlock(file);
10479 + di_read_unlock(dentry, AuLock_IR);
10480 + fi_write_unlock(file);
10482 + si_read_unlock(sb);
10486 +/* ---------------------------------------------------------------------- */
10488 +#define AuTestEmpty_WHONLY 1
10489 +#define AuTestEmpty_CALLED (1 << 1)
10490 +#define AuTestEmpty_SHWH (1 << 2)
10491 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10492 +#define au_fset_testempty(flags, name) \
10493 + do { (flags) |= AuTestEmpty_##name; } while (0)
10494 +#define au_fclr_testempty(flags, name) \
10495 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10497 +#ifndef CONFIG_AUFS_SHWH
10498 +#undef AuTestEmpty_SHWH
10499 +#define AuTestEmpty_SHWH 0
10502 +struct test_empty_arg {
10503 + struct dir_context ctx;
10504 + struct au_nhash *whlist;
10505 + unsigned int flags;
10507 + aufs_bindex_t bindex;
10510 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10511 + int namelen, loff_t offset __maybe_unused, u64 ino,
10512 + unsigned int d_type)
10514 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10516 + char *name = (void *)__name;
10519 + au_fset_testempty(arg->flags, CALLED);
10521 + if (name[0] == '.'
10522 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10523 + goto out; /* success */
10525 + if (namelen <= AUFS_WH_PFX_LEN
10526 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10527 + if (au_ftest_testempty(arg->flags, WHONLY)
10528 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10529 + arg->err = -ENOTEMPTY;
10533 + name += AUFS_WH_PFX_LEN;
10534 + namelen -= AUFS_WH_PFX_LEN;
10535 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10536 + arg->err = au_nhash_append_wh
10537 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10538 + au_ftest_testempty(arg->flags, SHWH));
10542 + AuTraceErr(arg->err);
10546 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10549 + struct file *h_file;
10550 + struct au_branch *br;
10552 + h_file = au_h_open(dentry, arg->bindex,
10553 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10554 + /*file*/NULL, /*force_wr*/0);
10555 + err = PTR_ERR(h_file);
10556 + if (IS_ERR(h_file))
10560 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10561 + && !file_inode(h_file)->i_nlink)
10566 + au_fclr_testempty(arg->flags, CALLED);
10568 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10571 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10575 + br = au_sbr(dentry->d_sb, arg->bindex);
10576 + au_lcnt_dec(&br->br_nfiles);
10581 +struct do_test_empty_args {
10583 + struct dentry *dentry;
10584 + struct test_empty_arg *arg;
10587 +static void call_do_test_empty(void *args)
10589 + struct do_test_empty_args *a = args;
10590 + *a->errp = do_test_empty(a->dentry, a->arg);
10593 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10595 + int err, wkq_err;
10596 + struct dentry *h_dentry;
10597 + struct inode *h_inode;
10598 + struct user_namespace *h_userns;
10600 + h_userns = au_sbr_userns(dentry->d_sb, arg->bindex);
10601 + h_dentry = au_h_dptr(dentry, arg->bindex);
10602 + h_inode = d_inode(h_dentry);
10603 + /* todo: i_mode changes anytime? */
10604 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10605 + err = au_test_h_perm_sio(h_userns, h_inode, MAY_EXEC | MAY_READ);
10606 + inode_unlock_shared(h_inode);
10608 + err = do_test_empty(dentry, arg);
10610 + struct do_test_empty_args args = {
10612 + .dentry = dentry,
10615 + unsigned int flags = arg->flags;
10617 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10618 + if (unlikely(wkq_err))
10620 + arg->flags = flags;
10626 +int au_test_empty_lower(struct dentry *dentry)
10629 + unsigned int rdhash;
10630 + aufs_bindex_t bindex, btop, btail;
10631 + struct au_nhash whlist;
10632 + struct test_empty_arg arg = {
10634 + .actor = test_empty_cb
10637 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10639 + SiMustAnyLock(dentry->d_sb);
10641 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10643 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10644 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10645 + if (unlikely(err))
10649 + arg.whlist = &whlist;
10650 + btop = au_dbtop(dentry);
10651 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10652 + au_fset_testempty(arg.flags, SHWH);
10653 + test_empty = do_test_empty;
10654 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10655 + test_empty = sio_test_empty;
10656 + arg.bindex = btop;
10657 + err = test_empty(dentry, &arg);
10658 + if (unlikely(err))
10661 + au_fset_testempty(arg.flags, WHONLY);
10662 + btail = au_dbtaildir(dentry);
10663 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10664 + struct dentry *h_dentry;
10666 + h_dentry = au_h_dptr(dentry, bindex);
10667 + if (h_dentry && d_is_positive(h_dentry)) {
10668 + arg.bindex = bindex;
10669 + err = test_empty(dentry, &arg);
10674 + au_nhash_wh_free(&whlist);
10679 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10682 + struct test_empty_arg arg = {
10684 + .actor = test_empty_cb
10687 + aufs_bindex_t bindex, btail;
10690 + arg.whlist = whlist;
10691 + arg.flags = AuTestEmpty_WHONLY;
10692 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10693 + au_fset_testempty(arg.flags, SHWH);
10694 + btail = au_dbtaildir(dentry);
10695 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10696 + struct dentry *h_dentry;
10698 + h_dentry = au_h_dptr(dentry, bindex);
10699 + if (h_dentry && d_is_positive(h_dentry)) {
10700 + arg.bindex = bindex;
10701 + err = sio_test_empty(dentry, &arg);
10708 +/* ---------------------------------------------------------------------- */
10710 +const struct file_operations aufs_dir_fop = {
10711 + .owner = THIS_MODULE,
10712 + .llseek = default_llseek,
10713 + .read = generic_read_dir,
10714 + .iterate_shared = aufs_iterate_shared,
10715 + .unlocked_ioctl = aufs_ioctl_dir,
10716 +#ifdef CONFIG_COMPAT
10717 + .compat_ioctl = aufs_compat_ioctl_dir,
10719 + .open = aufs_open_dir,
10720 + .release = aufs_release_dir,
10721 + .flush = aufs_flush_dir,
10722 + .fsync = aufs_fsync_dir
10724 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10725 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10726 +++ linux/fs/aufs/dir.h 2022-11-05 23:02:18.962555950 +0100
10728 +/* SPDX-License-Identifier: GPL-2.0 */
10730 + * Copyright (C) 2005-2022 Junjiro R. Okajima
10732 + * This program is free software; you can redistribute it and/or modify
10733 + * it under the terms of the GNU General Public License as published by
10734 + * the Free Software Foundation; either version 2 of the License, or
10735 + * (at your option) any later version.
10737 + * This program is distributed in the hope that it will be useful,
10738 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10739 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10740 + * GNU General Public License for more details.
10742 + * You should have received a copy of the GNU General Public License
10743 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10747 + * directory operations
10750 +#ifndef __AUFS_DIR_H__
10751 +#define __AUFS_DIR_H__
10755 +#include <linux/fs.h>
10757 +/* ---------------------------------------------------------------------- */
10759 +/* need to be faster and smaller */
10762 + unsigned int nh_num;
10763 + struct hlist_head *nh_head;
10766 +struct au_vdir_destr {
10767 + unsigned char len;
10768 + unsigned char name[];
10771 +struct au_vdir_dehstr {
10772 + struct hlist_node hash;
10773 + struct au_vdir_destr *str;
10774 + struct rcu_head rcu;
10775 +} ____cacheline_aligned_in_smp;
10777 +struct au_vdir_de {
10779 + unsigned char de_type;
10780 + /* caution: packed */
10781 + struct au_vdir_destr de_str;
10784 +struct au_vdir_wh {
10785 + struct hlist_node wh_hash;
10786 +#ifdef CONFIG_AUFS_SHWH
10788 + aufs_bindex_t wh_bindex;
10789 + unsigned char wh_type;
10791 + aufs_bindex_t wh_bindex;
10793 + /* caution: packed */
10794 + struct au_vdir_destr wh_str;
10797 +union au_vdir_deblk_p {
10798 + unsigned char *deblk;
10799 + struct au_vdir_de *de;
10803 + unsigned char **vd_deblk;
10804 + unsigned long vd_nblk;
10806 + unsigned long ul;
10807 + union au_vdir_deblk_p p;
10811 + unsigned int vd_deblk_sz;
10812 + unsigned long vd_jiffy;
10813 + struct rcu_head rcu;
10814 +} ____cacheline_aligned_in_smp;
10816 +/* ---------------------------------------------------------------------- */
10819 +extern const struct file_operations aufs_dir_fop;
10820 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10821 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10822 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10823 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10824 +int au_test_empty_lower(struct dentry *dentry);
10825 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10828 +unsigned int au_rdhash_est(loff_t sz);
10829 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10830 +void au_nhash_wh_free(struct au_nhash *whlist);
10831 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10833 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10834 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10835 + unsigned int d_type, aufs_bindex_t bindex,
10836 + unsigned char shwh);
10837 +void au_vdir_free(struct au_vdir *vdir);
10838 +int au_vdir_init(struct file *file);
10839 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10842 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10844 +#ifdef CONFIG_AUFS_RDU
10846 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10847 +#ifdef CONFIG_COMPAT
10848 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10849 + unsigned long arg);
10852 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10853 + unsigned int cmd, unsigned long arg)
10854 +#ifdef CONFIG_COMPAT
10855 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10856 + unsigned int cmd, unsigned long arg)
10860 +#endif /* __KERNEL__ */
10861 +#endif /* __AUFS_DIR_H__ */
10862 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10863 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10864 +++ linux/fs/aufs/dirren.c 2022-11-05 23:02:18.962555950 +0100
10866 +// SPDX-License-Identifier: GPL-2.0
10868 + * Copyright (C) 2017-2022 Junjiro R. Okajima
10870 + * This program is free software; you can redistribute it and/or modify
10871 + * it under the terms of the GNU General Public License as published by
10872 + * the Free Software Foundation; either version 2 of the License, or
10873 + * (at your option) any later version.
10875 + * This program is distributed in the hope that it will be useful,
10876 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10877 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10878 + * GNU General Public License for more details.
10880 + * You should have received a copy of the GNU General Public License
10881 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10885 + * special handling in renaming a directory
10886 + * in order to support looking-up the before-renamed name on the lower readonly
10890 +#include <linux/byteorder/generic.h>
10893 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10897 + idx = au_dr_ihash(ent->dr_h_ino);
10898 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10901 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10904 + struct hlist_bl_head *hbl;
10907 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10908 + hbl = dr->dr_h_ino + i;
10909 + hlist_bl_lock(hbl);
10910 + ret &= hlist_bl_empty(hbl);
10911 + hlist_bl_unlock(hbl);
10917 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10919 + struct au_dr_hino *found, *ent;
10920 + struct hlist_bl_head *hbl;
10921 + struct hlist_bl_node *pos;
10925 + idx = au_dr_ihash(ino);
10926 + hbl = dr->dr_h_ino + idx;
10927 + hlist_bl_lock(hbl);
10928 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10929 + if (ent->dr_h_ino == ino) {
10933 + hlist_bl_unlock(hbl);
10938 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10939 + struct au_dr_hino *add_ent)
10942 + struct hlist_bl_head *hbl;
10943 + struct hlist_bl_node *pos;
10944 + struct au_dr_hino *ent;
10947 + idx = au_dr_ihash(ino);
10948 + hbl = dr->dr_h_ino + idx;
10949 +#if 0 /* debug print */
10951 + struct hlist_bl_node *tmp;
10953 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10954 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10957 + hlist_bl_lock(hbl);
10958 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10959 + if (ent->dr_h_ino == ino) {
10963 + if (!found && add_ent)
10964 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10965 + hlist_bl_unlock(hbl);
10967 + if (!found && add_ent)
10968 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
10973 +void au_dr_hino_free(struct au_dr_br *dr)
10976 + struct hlist_bl_head *hbl;
10977 + struct hlist_bl_node *pos, *tmp;
10978 + struct au_dr_hino *ent;
10980 + /* SiMustWriteLock(sb); */
10982 + for (i = 0; i < AuDirren_NHASH; i++) {
10983 + hbl = dr->dr_h_ino + i;
10984 + /* no spinlock since sbinfo must be write-locked */
10985 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10986 + au_kfree_rcu(ent);
10987 + INIT_HLIST_BL_HEAD(hbl);
10991 +/* returns the number of inodes or an error */
10992 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
10993 + struct file *hinofile)
10997 + loff_t pos, oldsize;
10999 + struct inode *hinoinode;
11000 + struct hlist_bl_head *hbl;
11001 + struct hlist_bl_node *n1, *n2;
11002 + struct au_dr_hino *ent;
11004 + SiMustWriteLock(sb);
11005 + AuDebugOn(!au_br_writable(br->br_perm));
11007 + hinoinode = file_inode(hinofile);
11008 + oldsize = i_size_read(hinoinode);
11012 + hbl = br->br_dirren.dr_h_ino;
11013 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11014 + /* no bit-lock since sbinfo must be write-locked */
11015 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11016 + AuDbg("hi%llu, %pD2\n",
11017 + (unsigned long long)ent->dr_h_ino, hinofile);
11018 + u64 = cpu_to_be64(ent->dr_h_ino);
11019 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11020 + if (ssz == sizeof(u64))
11023 + /* write error */
11024 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11031 + /* regardless the error */
11032 + if (pos < oldsize) {
11033 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11041 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11048 + struct au_dr_hino *ent;
11049 + struct inode *hinoinode;
11050 + struct hlist_bl_head *hbl;
11054 + hbl = dr->dr_h_ino;
11055 + hinoinode = file_inode(hinofile);
11056 + sz = i_size_read(hinoinode);
11057 + AuDebugOn(sz % sizeof(u64));
11058 + n = sz / sizeof(u64);
11060 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11061 + if (unlikely(ssz != sizeof(u64))) {
11062 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11069 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11075 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11076 + AuDbg("hi%llu, %pD2\n",
11077 + (unsigned long long)ent->dr_h_ino, hinofile);
11078 + hidx = au_dr_ihash(ent->dr_h_ino);
11079 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11081 + goto out; /* success */
11084 + au_dr_hino_free(dr);
11091 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11092 + * @path is a switch to distinguish load and store.
11094 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11095 + struct au_branch *br, const struct path *path)
11098 + unsigned char load, suspend;
11099 + struct file *hinofile;
11100 + struct au_hinode *hdir;
11101 + struct inode *dir, *delegated;
11102 + struct path hinopath;
11103 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11104 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11106 + AuDebugOn(bindex < 0 && !br);
11107 + AuDebugOn(bindex >= 0 && br);
11112 + br = au_sbr(sb, bindex);
11115 + path = &br->br_path;
11116 + AuDebugOn(!au_br_writable(br->br_perm));
11117 + if (unlikely(!au_br_writable(br->br_perm)))
11123 + dir = d_inode(sb->s_root);
11124 + hdir = au_hinode(au_ii(dir), bindex);
11125 + dir = hdir->hi_inode;
11126 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11128 + dir = d_inode(path->dentry);
11129 + inode_lock_nested(dir, AuLsc_I_CHILD);
11131 + hinopath.mnt = path->mnt;
11132 + hinopath.dentry = vfsub_lkup_one(&hinoname, (struct path *)path);
11133 + err = PTR_ERR(hinopath.dentry);
11134 + if (IS_ERR(hinopath.dentry))
11138 + flags = O_RDONLY;
11140 + if (d_is_negative(hinopath.dentry))
11141 + goto out_dput; /* success */
11143 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11144 + if (d_is_positive(hinopath.dentry)) {
11145 + delegated = NULL;
11146 + err = vfsub_unlink(dir, &hinopath, &delegated,
11149 + if (unlikely(err))
11150 + pr_err("ignored err %d, %pd2\n",
11151 + err, hinopath.dentry);
11152 + if (unlikely(err == -EWOULDBLOCK))
11157 + } else if (!d_is_positive(hinopath.dentry)) {
11158 + err = vfsub_create(dir, &hinopath, 0600,
11159 + /*want_excl*/false);
11161 + if (unlikely(err))
11164 + flags = O_WRONLY;
11166 + hinofile = vfsub_dentry_open(&hinopath, flags);
11168 + au_hn_inode_unlock(hdir);
11170 + inode_unlock(dir);
11171 + dput(hinopath.dentry);
11172 + AuTraceErrPtr(hinofile);
11173 + if (IS_ERR(hinofile)) {
11174 + err = PTR_ERR(hinofile);
11179 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11181 + err = au_dr_hino_store(sb, br, hinofile);
11186 + dput(hinopath.dentry);
11189 + au_hn_inode_unlock(hdir);
11191 + inode_unlock(dir);
11197 +/* ---------------------------------------------------------------------- */
11199 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11202 + struct kstatfs kstfs;
11204 + struct dentry *dentry;
11205 + struct super_block *sb;
11207 + err = vfs_statfs((void *)path, &kstfs);
11209 + if (unlikely(err))
11212 + /* todo: support for UUID */
11214 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11215 + brid->type = AuBrid_FSID;
11216 + brid->fsid = kstfs.f_fsid;
11218 + dentry = path->dentry;
11219 + sb = dentry->d_sb;
11222 + brid->type = AuBrid_DEV;
11231 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11232 + const struct path *path)
11235 + struct au_dr_br *dr;
11236 + struct hlist_bl_head *hbl;
11238 + dr = &br->br_dirren;
11239 + hbl = dr->dr_h_ino;
11240 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11241 + INIT_HLIST_BL_HEAD(hbl);
11243 + err = au_dr_brid_init(&dr->dr_brid, path);
11244 + if (unlikely(err))
11247 + if (au_opt_test(au_mntflags(sb), DIRREN))
11248 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11255 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11260 + if (au_br_writable(br->br_perm))
11261 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11263 + au_dr_hino_free(&br->br_dirren);
11268 +/* ---------------------------------------------------------------------- */
11270 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11271 + char *buf, size_t sz)
11274 + unsigned int major, minor;
11278 + err = snprintf(p, sz, "%d_", brid->type);
11279 + AuDebugOn(err > sz);
11282 + switch (brid->type) {
11283 + case AuBrid_Unset:
11285 + case AuBrid_UUID:
11286 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11288 + case AuBrid_FSID:
11289 + err = snprintf(p, sz, "%08x-%08x",
11290 + brid->fsid.val[0], brid->fsid.val[1]);
11293 + major = MAJOR(brid->dev);
11294 + minor = MINOR(brid->dev);
11295 + if (major <= 0xff && minor <= 0xff)
11296 + err = snprintf(p, sz, "%02x%02x", major, minor);
11298 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11301 + AuDebugOn(err > sz);
11304 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11305 + AuDebugOn(err > sz);
11312 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11315 + struct dentry *br_dentry;
11316 + struct inode *br_inode;
11318 + br_dentry = au_br_dentry(br);
11319 + br_inode = d_inode(br_dentry);
11320 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11321 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11322 + AuDebugOn(rlen > len);
11327 +/* ---------------------------------------------------------------------- */
11330 + * from the given @h_dentry, construct drinfo at @*fdata.
11331 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11334 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11335 + struct dentry *h_dentry,
11336 + unsigned char *allocated)
11339 + struct au_drinfo_fdata *f, *p;
11340 + struct au_drinfo *drinfo;
11341 + struct inode *h_inode;
11342 + struct qstr *qname;
11346 + h_inode = d_inode(h_dentry);
11347 + qname = &h_dentry->d_name;
11348 + drinfo = &f->drinfo;
11349 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11350 + drinfo->oldnamelen = qname->len;
11351 + if (*allocated < sizeof(*f) + qname->len) {
11352 + v = roundup_pow_of_two(*allocated + qname->len);
11353 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11354 + if (unlikely(!p)) {
11362 + drinfo = &f->drinfo;
11364 + memcpy(drinfo->oldname, qname->name, qname->len);
11365 + AuDbg("i%llu, %.*s\n",
11366 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11367 + drinfo->oldname);
11374 +/* callers have to free the return value */
11375 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11377 + struct au_drinfo *ret, *drinfo;
11378 + struct au_drinfo_fdata fdata;
11383 + ret = ERR_PTR(-EIO);
11385 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11386 + if (unlikely(ssz != sizeof(fdata))) {
11387 + AuIOErr("ssz %zd, %u, %pD2\n",
11388 + ssz, (unsigned int)sizeof(fdata), file);
11392 + fdata.magic = ntohl((__force __be32)fdata.magic);
11393 + switch (fdata.magic) {
11394 + case AUFS_DRINFO_MAGIC_V1:
11397 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11398 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11402 + drinfo = &fdata.drinfo;
11403 + len = drinfo->oldnamelen;
11405 + AuIOErr("broken drinfo %pD2\n", file);
11410 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11411 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11412 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11413 + (unsigned long long)drinfo->ino,
11414 + (unsigned long long)h_ino, file);
11415 + goto out; /* success */
11418 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11419 + if (unlikely(!ret)) {
11420 + ret = ERR_PTR(-ENOMEM);
11421 + AuTraceErrPtr(ret);
11426 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11427 + if (unlikely(ssz != len)) {
11428 + au_kfree_rcu(ret);
11429 + ret = ERR_PTR(-EIO);
11430 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11434 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11440 +/* ---------------------------------------------------------------------- */
11442 +/* in order to be revertible */
11443 +struct au_drinfo_rev_elm {
11445 + struct dentry *info_dentry;
11446 + struct au_drinfo *info_last;
11449 +struct au_drinfo_rev {
11450 + unsigned char already;
11451 + aufs_bindex_t nelm;
11452 + struct au_drinfo_rev_elm elm[];
11455 +/* todo: isn't it too large? */
11456 +struct au_drinfo_store {
11457 + struct path h_ppath;
11458 + struct dentry *h_dentry;
11459 + struct au_drinfo_fdata *fdata;
11460 + char *infoname; /* inside of whname, just after PFX */
11461 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11462 + aufs_bindex_t btgt, btail;
11463 + unsigned char no_sio,
11464 + allocated, /* current size of *fdata */
11465 + infonamelen, /* room size for p */
11466 + whnamelen, /* length of the generated name */
11467 + renameback; /* renamed back */
11470 +/* on rename(2) error, the caller should revert it using @elm */
11471 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11472 + struct au_drinfo_rev_elm *elm)
11477 + struct path infopath = {
11478 + .mnt = w->h_ppath.mnt
11480 + struct inode *h_dir, *h_inode, *delegated;
11481 + struct file *infofile;
11482 + struct qstr *qname;
11485 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11487 + infopath.dentry = vfsub_lookup_one_len(w->whname, &w->h_ppath,
11489 + AuTraceErrPtr(infopath.dentry);
11490 + if (IS_ERR(infopath.dentry)) {
11491 + err = PTR_ERR(infopath.dentry);
11496 + h_dir = d_inode(w->h_ppath.dentry);
11497 + if (elm && d_is_negative(infopath.dentry)) {
11498 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11500 + if (unlikely(err))
11502 + elm->created = 1;
11503 + elm->info_dentry = dget(infopath.dentry);
11506 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11507 + AuTraceErrPtr(infofile);
11508 + if (IS_ERR(infofile)) {
11509 + err = PTR_ERR(infofile);
11513 + h_inode = d_inode(infopath.dentry);
11514 + if (elm && i_size_read(h_inode)) {
11515 + h_inode = d_inode(w->h_dentry);
11516 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11517 + AuTraceErrPtr(elm->info_last);
11518 + if (IS_ERR(elm->info_last)) {
11519 + err = PTR_ERR(elm->info_last);
11520 + elm->info_last = NULL;
11521 + AuDebugOn(elm->info_dentry);
11526 + if (elm && w->renameback) {
11527 + delegated = NULL;
11528 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11530 + if (unlikely(err == -EWOULDBLOCK))
11536 + qname = &w->h_dentry->d_name;
11537 + len = sizeof(*w->fdata) + qname->len;
11539 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11540 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11541 + if (ssz == len) {
11542 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11543 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11544 + goto out_fput; /* success */
11549 + /* the caller should revert it using @elm */
11555 + dput(infopath.dentry);
11561 +struct au_call_drinfo_do_store_args {
11563 + struct au_drinfo_store *w;
11564 + struct au_drinfo_rev_elm *elm;
11567 +static void au_call_drinfo_do_store(void *args)
11569 + struct au_call_drinfo_do_store_args *a = args;
11571 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11574 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11575 + struct au_drinfo_rev_elm *elm)
11577 + int err, wkq_err;
11580 + err = au_drinfo_do_store(w, elm);
11582 + struct au_call_drinfo_do_store_args a = {
11587 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11588 + if (unlikely(wkq_err))
11596 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11597 + aufs_bindex_t btgt)
11601 + memset(w, 0, sizeof(*w));
11602 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11603 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11604 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11605 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11607 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11610 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11611 + if (unlikely(!w->fdata)) {
11615 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11622 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11624 + au_kfree_rcu(w->fdata);
11627 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11628 + struct au_drinfo_store *w)
11630 + struct au_drinfo_rev_elm *elm;
11631 + struct inode *h_dir, *delegated;
11633 + struct path infopath = {
11634 + .mnt = w->h_ppath.mnt
11637 + h_dir = d_inode(w->h_ppath.dentry);
11638 + IMustLock(h_dir);
11642 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11643 + AuDebugOn(elm->created && elm->info_last);
11644 + if (elm->created) {
11646 + delegated = NULL;
11647 + infopath.dentry = elm->info_dentry;
11648 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11651 + if (unlikely(err == -EWOULDBLOCK))
11653 + dput(elm->info_dentry);
11654 + } else if (elm->info_last) {
11656 + w->fdata->drinfo = *elm->info_last;
11657 + memcpy(w->fdata->drinfo.oldname,
11658 + elm->info_last->oldname,
11659 + elm->info_last->oldnamelen);
11660 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11661 + au_kfree_rcu(elm->info_last);
11663 + if (unlikely(err))
11664 + AuIOErr("%d, %s\n", err, w->whname);
11665 + /* go on even if err */
11669 +/* caller has to call au_dr_rename_fin() later */
11670 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11671 + struct qstr *dst_name, void *_rev)
11673 + int err, sz, nelm;
11674 + aufs_bindex_t bindex, btail;
11675 + struct au_drinfo_store work;
11676 + struct au_drinfo_rev *rev, **p;
11677 + struct au_drinfo_rev_elm *elm;
11678 + struct super_block *sb;
11679 + struct au_branch *br;
11680 + struct au_hinode *hdir;
11682 + err = au_drinfo_store_work_init(&work, btgt);
11684 + if (unlikely(err))
11688 + btail = au_dbtaildir(dentry);
11689 + nelm = btail - btgt;
11690 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11691 + rev = kcalloc(1, sz, GFP_NOFS);
11692 + if (unlikely(!rev)) {
11696 + rev->nelm = nelm;
11702 + sb = dentry->d_sb;
11703 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11704 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11705 + hdir = au_hi(d_inode(dentry), btgt);
11706 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11707 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11708 + work.h_dentry = au_h_dptr(dentry, bindex);
11709 + if (!work.h_dentry)
11712 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11713 + &work.allocated);
11715 + if (unlikely(err))
11718 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11719 + br = au_sbr(sb, bindex);
11720 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11721 + work.whnamelen += au_drinfo_name(br, work.infoname,
11722 + work.infonamelen);
11723 + AuDbg("whname %.*s, i%llu, %.*s\n",
11724 + work.whnamelen, work.whname,
11725 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11726 + work.fdata->drinfo.oldnamelen,
11727 + work.fdata->drinfo.oldname);
11729 + err = au_drinfo_store_sio(&work, elm);
11731 + if (unlikely(err))
11734 + if (unlikely(err)) {
11735 + /* revert all drinfo */
11736 + au_drinfo_store_rev(rev, &work);
11737 + au_kfree_try_rcu(rev);
11740 + au_hn_inode_unlock(hdir);
11743 + au_drinfo_store_work_fin(&work);
11748 +/* ---------------------------------------------------------------------- */
11750 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11751 + struct qstr *dst_name, void *_rev)
11753 + int err, already;
11755 + struct super_block *sb;
11756 + struct au_branch *br;
11757 + struct au_dr_br *dr;
11758 + struct dentry *h_dentry;
11759 + struct inode *h_inode;
11760 + struct au_dr_hino *ent;
11761 + struct au_drinfo_rev *rev, **p;
11763 + AuDbg("bindex %d\n", bindex);
11766 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11767 + if (unlikely(!ent))
11771 + br = au_sbr(sb, bindex);
11772 + dr = &br->br_dirren;
11773 + h_dentry = au_h_dptr(src, bindex);
11774 + h_inode = d_inode(h_dentry);
11775 + ino = h_inode->i_ino;
11776 + ent->dr_h_ino = ino;
11777 + already = au_dr_hino_test_add(dr, ino, ent);
11778 + AuDbg("b%d, hi%llu, already %d\n",
11779 + bindex, (unsigned long long)ino, already);
11781 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11786 + rev->already = already;
11787 + goto out; /* success */
11792 + au_dr_hino_del(dr, ent);
11793 + au_kfree_rcu(ent);
11800 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11802 + struct au_drinfo_rev *rev;
11803 + struct au_drinfo_rev_elm *elm;
11808 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11809 + dput(elm->info_dentry);
11810 + au_kfree_rcu(elm->info_last);
11812 + au_kfree_try_rcu(rev);
11815 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11818 + struct au_drinfo_store work;
11819 + struct au_drinfo_rev *rev = _rev;
11820 + struct super_block *sb;
11821 + struct au_branch *br;
11822 + struct inode *h_inode;
11823 + struct au_dr_br *dr;
11824 + struct au_dr_hino *ent;
11826 + err = au_drinfo_store_work_init(&work, btgt);
11827 + if (unlikely(err))
11831 + br = au_sbr(sb, btgt);
11832 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11833 + work.h_ppath.mnt = au_br_mnt(br);
11834 + au_drinfo_store_rev(rev, &work);
11835 + au_drinfo_store_work_fin(&work);
11836 + if (rev->already)
11839 + dr = &br->br_dirren;
11840 + h_inode = d_inode(work.h_ppath.dentry);
11841 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11843 + au_dr_hino_del(dr, ent);
11844 + au_kfree_rcu(ent);
11847 + au_kfree_try_rcu(rev);
11848 + if (unlikely(err))
11849 + pr_err("failed to remove dirren info\n");
11852 +/* ---------------------------------------------------------------------- */
11854 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11855 + char *whname, int whnamelen,
11856 + struct dentry **info_dentry)
11858 + struct au_drinfo *drinfo;
11860 + struct inode *h_dir;
11861 + struct path infopath;
11864 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11866 + *info_dentry = NULL;
11869 + h_dir = d_inode(h_ppath->dentry);
11870 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11871 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath, whnamelen);
11872 + if (IS_ERR(infopath.dentry)) {
11873 + drinfo = (void *)infopath.dentry;
11877 + if (d_is_negative(infopath.dentry))
11878 + goto out_dput; /* success */
11880 + infopath.mnt = h_ppath->mnt;
11881 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11882 + inode_unlock_shared(h_dir);
11885 + drinfo = (void *)f;
11889 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11890 + if (IS_ERR_OR_NULL(drinfo))
11893 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11894 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11899 + dput(infopath.dentry);
11902 + inode_unlock_shared(h_dir);
11903 + AuTraceErrPtr(drinfo);
11907 +struct au_drinfo_do_load_args {
11908 + struct au_drinfo **drinfop;
11909 + struct path *h_ppath;
11912 + struct dentry **info_dentry;
11915 +static void au_call_drinfo_do_load(void *args)
11917 + struct au_drinfo_do_load_args *a = args;
11919 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11923 +struct au_drinfo_load {
11924 + struct path h_ppath;
11925 + struct qstr *qname;
11926 + unsigned char no_sio;
11928 + aufs_bindex_t ninfo;
11929 + struct au_drinfo **drinfo;
11932 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11933 + struct au_branch *br)
11935 + int err, wkq_err, whnamelen, e;
11936 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11937 + = AUFS_WH_DR_INFO_PFX;
11938 + struct au_drinfo *drinfo;
11939 + struct qstr oldname;
11940 + struct inode *h_dir, *delegated;
11941 + struct dentry *info_dentry;
11942 + struct path infopath;
11944 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11945 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11946 + sizeof(whname) - whnamelen);
11948 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11951 + struct au_drinfo_do_load_args args = {
11952 + .drinfop = &drinfo,
11953 + .h_ppath = &w->h_ppath,
11954 + .whname = whname,
11955 + .whnamelen = whnamelen,
11956 + .info_dentry = &info_dentry
11958 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11959 + if (unlikely(wkq_err))
11960 + drinfo = ERR_PTR(wkq_err);
11962 + err = PTR_ERR(drinfo);
11963 + if (IS_ERR_OR_NULL(drinfo))
11967 + oldname.len = drinfo->oldnamelen;
11968 + oldname.name = drinfo->oldname;
11969 + if (au_qstreq(w->qname, &oldname)) {
11970 + /* the name is renamed back */
11971 + au_kfree_rcu(drinfo);
11974 + infopath.dentry = info_dentry;
11975 + infopath.mnt = w->h_ppath.mnt;
11976 + h_dir = d_inode(w->h_ppath.dentry);
11977 + delegated = NULL;
11978 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
11979 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
11980 + inode_unlock(h_dir);
11982 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
11983 + if (unlikely(e == -EWOULDBLOCK))
11986 + au_kfree_rcu(w->drinfo[bindex]);
11987 + w->drinfo[bindex] = drinfo;
11988 + dput(info_dentry);
11995 +/* ---------------------------------------------------------------------- */
11997 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
11999 + struct au_drinfo **p = drinfo;
12002 + au_kfree_rcu(*drinfo++);
12003 + au_kfree_try_rcu(p);
12006 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12007 + aufs_bindex_t btgt)
12010 + struct au_drinfo_load w;
12011 + aufs_bindex_t bindex, bbot;
12012 + struct au_branch *br;
12013 + struct inode *h_dir;
12014 + struct au_dr_hino *ent;
12015 + struct super_block *sb;
12017 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12018 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12019 + AuLNPair(&lkup->whname), btgt);
12021 + sb = dentry->d_sb;
12022 + bbot = au_sbbot(sb);
12023 + w.ninfo = bbot + 1;
12024 + if (!lkup->dirren.drinfo) {
12025 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12026 + sizeof(*lkup->dirren.drinfo),
12028 + if (unlikely(!lkup->dirren.drinfo)) {
12032 + lkup->dirren.ninfo = w.ninfo;
12034 + w.drinfo = lkup->dirren.drinfo;
12035 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12036 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12037 + AuDebugOn(!w.h_ppath.dentry);
12038 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12039 + w.qname = &dentry->d_name;
12042 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12043 + br = au_sbr(sb, bindex);
12044 + err = au_drinfo_load(&w, bindex, br);
12045 + if (unlikely(err))
12047 + if (w.drinfo[bindex])
12051 + br = au_sbr(sb, btgt);
12052 + h_dir = d_inode(w.h_ppath.dentry);
12053 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12055 + au_dr_hino_del(&br->br_dirren, ent);
12056 + au_kfree_rcu(ent);
12058 + goto out; /* success */
12061 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12062 + lkup->dirren.ninfo = 0;
12063 + lkup->dirren.drinfo = NULL;
12069 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12071 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12074 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12077 + struct au_drinfo *drinfo;
12080 + if (!lkup->dirren.drinfo)
12082 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12083 + drinfo = lkup->dirren.drinfo[btgt];
12087 + au_kfree_try_rcu(lkup->whname.name);
12088 + lkup->whname.name = NULL;
12089 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12090 + lkup->dirren.dr_name.name = drinfo->oldname;
12091 + lkup->name = &lkup->dirren.dr_name;
12092 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12094 + AuDbg("name %.*s, whname %.*s, b%d\n",
12095 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12103 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12107 + struct au_drinfo *drinfo;
12110 + if (!lkup->dirren.drinfo)
12112 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12113 + drinfo = lkup->dirren.drinfo[bindex];
12117 + match = (drinfo->ino == h_ino);
12118 + AuDbg("match %d\n", match);
12124 +/* ---------------------------------------------------------------------- */
12126 +int au_dr_opt_set(struct super_block *sb)
12129 + aufs_bindex_t bindex, bbot;
12130 + struct au_branch *br;
12133 + bbot = au_sbbot(sb);
12134 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12135 + br = au_sbr(sb, bindex);
12136 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12142 +int au_dr_opt_flush(struct super_block *sb)
12145 + aufs_bindex_t bindex, bbot;
12146 + struct au_branch *br;
12149 + bbot = au_sbbot(sb);
12150 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12151 + br = au_sbr(sb, bindex);
12152 + if (au_br_writable(br->br_perm))
12153 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12159 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12162 + aufs_bindex_t bindex, bbot;
12163 + struct au_branch *br;
12167 + err = au_dr_opt_flush(sb);
12168 + if (unlikely(err))
12172 + bbot = au_sbbot(sb);
12173 + for (bindex = 0; bindex <= bbot; bindex++) {
12174 + br = au_sbr(sb, bindex);
12175 + au_dr_hino_free(&br->br_dirren);
12181 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12182 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12183 +++ linux/fs/aufs/dirren.h 2022-11-05 23:02:18.962555950 +0100
12185 +/* SPDX-License-Identifier: GPL-2.0 */
12187 + * Copyright (C) 2017-2022 Junjiro R. Okajima
12189 + * This program is free software; you can redistribute it and/or modify
12190 + * it under the terms of the GNU General Public License as published by
12191 + * the Free Software Foundation; either version 2 of the License, or
12192 + * (at your option) any later version.
12194 + * This program is distributed in the hope that it will be useful,
12195 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12196 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12197 + * GNU General Public License for more details.
12199 + * You should have received a copy of the GNU General Public License
12200 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12204 + * renamed dir info
12207 +#ifndef __AUFS_DIRREN_H__
12208 +#define __AUFS_DIRREN_H__
12212 +#include <linux/dcache.h>
12213 +#include <linux/statfs.h>
12214 +#include <linux/uuid.h>
12217 +#define AuDirren_NHASH 100
12219 +#ifdef CONFIG_AUFS_DIRREN
12220 +enum au_brid_type {
12227 +struct au_dr_brid {
12228 + enum au_brid_type type;
12230 + uuid_t uuid; /* unimplemented yet */
12236 +/* 20 is the max digits length of ulong 64 */
12237 +/* brid-type "_" uuid "_" inum */
12238 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12239 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12241 +struct au_dr_hino {
12242 + struct hlist_bl_node dr_hnode;
12247 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12248 + struct au_dr_brid dr_brid;
12251 +struct au_dr_lookup {
12252 + /* dr_name is pointed by struct au_do_lookup_args.name */
12253 + struct qstr dr_name; /* subset of dr_info */
12254 + aufs_bindex_t ninfo;
12255 + struct au_drinfo **drinfo;
12258 +struct au_dr_hino;
12260 +struct au_dr_br { };
12261 +struct au_dr_lookup { };
12264 +/* ---------------------------------------------------------------------- */
12267 +struct au_do_lookup_args;
12269 +#ifdef CONFIG_AUFS_DIRREN
12270 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12271 + struct au_dr_hino *add_ent);
12272 +void au_dr_hino_free(struct au_dr_br *dr);
12273 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12274 + const struct path *path);
12275 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12276 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12277 + struct qstr *dst_name, void *_rev);
12278 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12279 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12280 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12281 + aufs_bindex_t bindex);
12282 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12283 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12285 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12286 +int au_dr_opt_set(struct super_block *sb);
12287 +int au_dr_opt_flush(struct super_block *sb);
12288 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12290 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12291 + struct au_dr_hino *add_ent);
12292 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12293 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12294 + const struct path *path);
12295 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12296 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12297 + struct qstr *dst_name, void *_rev);
12298 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12299 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12301 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12302 + aufs_bindex_t bindex);
12303 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12304 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12305 + aufs_bindex_t bindex, ino_t h_ino);
12306 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12307 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12308 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12309 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12312 +/* ---------------------------------------------------------------------- */
12314 +#ifdef CONFIG_AUFS_DIRREN
12315 +static inline int au_dr_ihash(ino_t h_ino)
12317 + return h_ino % AuDirren_NHASH;
12320 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12323 +#endif /* __KERNEL__ */
12324 +#endif /* __AUFS_DIRREN_H__ */
12325 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12326 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12327 +++ linux/fs/aufs/dynop.c 2022-11-05 23:02:18.962555950 +0100
12329 +// SPDX-License-Identifier: GPL-2.0
12331 + * Copyright (C) 2010-2022 Junjiro R. Okajima
12333 + * This program is free software; you can redistribute it and/or modify
12334 + * it under the terms of the GNU General Public License as published by
12335 + * the Free Software Foundation; either version 2 of the License, or
12336 + * (at your option) any later version.
12338 + * This program is distributed in the hope that it will be useful,
12339 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12340 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12341 + * GNU General Public License for more details.
12343 + * You should have received a copy of the GNU General Public License
12344 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12348 + * dynamically customizable operations for regular files
12353 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12356 + * How large will these lists be?
12357 + * Usually just a few elements, 20-30 at most for each, I guess.
12359 +static struct hlist_bl_head dynop[AuDyLast];
12361 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12362 + const void *h_op)
12364 + struct au_dykey *key, *tmp;
12365 + struct hlist_bl_node *pos;
12368 + hlist_bl_lock(hbl);
12369 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12370 + if (tmp->dk_op.dy_hop == h_op) {
12371 + if (kref_get_unless_zero(&tmp->dk_kref))
12375 + hlist_bl_unlock(hbl);
12380 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12382 + struct au_dykey **k, *found;
12383 + const void *h_op = key->dk_op.dy_hop;
12387 + k = br->br_dykey;
12388 + for (i = 0; i < AuBrDynOp; i++)
12390 + if (k[i]->dk_op.dy_hop == h_op) {
12397 + spin_lock(&br->br_dykey_lock);
12398 + for (; i < AuBrDynOp; i++)
12400 + if (k[i]->dk_op.dy_hop == h_op) {
12408 + spin_unlock(&br->br_dykey_lock);
12409 + BUG_ON(i == AuBrDynOp); /* expand the array */
12415 +/* kref_get() if @key is already added */
12416 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12418 + struct au_dykey *tmp, *found;
12419 + struct hlist_bl_node *pos;
12420 + const void *h_op = key->dk_op.dy_hop;
12423 + hlist_bl_lock(hbl);
12424 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12425 + if (tmp->dk_op.dy_hop == h_op) {
12426 + if (kref_get_unless_zero(&tmp->dk_kref))
12431 + hlist_bl_add_head(&key->dk_hnode, hbl);
12432 + hlist_bl_unlock(hbl);
12439 +static void dy_free_rcu(struct rcu_head *rcu)
12441 + struct au_dykey *key;
12443 + key = container_of(rcu, struct au_dykey, dk_rcu);
12448 +static void dy_free(struct kref *kref)
12450 + struct au_dykey *key;
12451 + struct hlist_bl_head *hbl;
12453 + key = container_of(kref, struct au_dykey, dk_kref);
12454 + hbl = dynop + key->dk_op.dy_type;
12455 + au_hbl_del(&key->dk_hnode, hbl);
12456 + call_rcu(&key->dk_rcu, dy_free_rcu);
12459 +void au_dy_put(struct au_dykey *key)
12461 + kref_put(&key->dk_kref, dy_free);
12464 +/* ---------------------------------------------------------------------- */
12466 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12468 +#ifdef CONFIG_AUFS_DEBUG
12469 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12470 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12472 +#define DyDbgDeclare(cnt) do {} while (0)
12473 +#define DyDbgInc(cnt) do {} while (0)
12476 +#define DySet(func, dst, src, h_op, h_sb) do { \
12478 + if (h_op->func) { \
12480 + dst.func = src.func; \
12482 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12486 +#define DySetForce(func, dst, src) do { \
12487 + AuDebugOn(!src.func); \
12489 + dst.func = src.func; \
12492 +#define DySetAop(func) \
12493 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12494 +#define DySetAopForce(func) \
12495 + DySetForce(func, dyaop->da_op, aufs_aop)
12497 +static void dy_aop(struct au_dykey *key, const void *h_op,
12498 + struct super_block *h_sb __maybe_unused)
12500 + struct au_dyaop *dyaop = (void *)key;
12501 + const struct address_space_operations *h_aop = h_op;
12502 + DyDbgDeclare(cnt);
12504 + AuDbg("%s\n", au_sbtype(h_sb));
12506 + DySetAop(writepage);
12507 + DySetAopForce(read_folio); /* force */
12508 + DySetAop(writepages);
12509 + DySetAop(dirty_folio);
12510 + DySetAop(invalidate_folio);
12511 + DySetAop(readahead);
12512 + DySetAop(write_begin);
12513 + DySetAop(write_end);
12515 + DySetAop(release_folio);
12516 + DySetAop(free_folio);
12517 + /* this one will be changed according to an aufs mount option */
12518 + DySetAop(direct_IO);
12519 + DySetAop(migrate_folio);
12520 + DySetAop(launder_folio);
12521 + DySetAop(is_partially_uptodate);
12522 + DySetAop(is_dirty_writeback);
12523 + DySetAop(error_remove_page);
12524 + DySetAop(swap_activate);
12525 + DySetAop(swap_deactivate);
12526 + DySetAop(swap_rw);
12528 + DyDbgSize(cnt, *h_aop);
12531 +/* ---------------------------------------------------------------------- */
12533 +static void dy_bug(struct kref *kref)
12538 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12540 + struct au_dykey *key, *old;
12541 + struct hlist_bl_head *hbl;
12544 + void (*set)(struct au_dykey *key, const void *h_op,
12545 + struct super_block *h_sb __maybe_unused);
12547 + static const struct op a[] = {
12549 + .sz = sizeof(struct au_dyaop),
12553 + const struct op *p;
12555 + hbl = dynop + op->dy_type;
12556 + key = dy_gfind_get(hbl, op->dy_hop);
12558 + goto out_add; /* success */
12560 + p = a + op->dy_type;
12561 + key = kzalloc(p->sz, GFP_NOFS);
12562 + if (unlikely(!key)) {
12563 + key = ERR_PTR(-ENOMEM);
12567 + key->dk_op.dy_hop = op->dy_hop;
12568 + kref_init(&key->dk_kref);
12569 + p->set(key, op->dy_hop, au_br_sb(br));
12570 + old = dy_gadd(hbl, key);
12572 + au_kfree_rcu(key);
12577 + old = dy_bradd(br, key);
12579 + /* its ref-count should never be zero here */
12580 + kref_put(&key->dk_kref, dy_bug);
12585 +/* ---------------------------------------------------------------------- */
12587 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12588 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12589 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12590 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12591 + * See the aufs manual in detail.
12593 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12596 + dyaop->da_op.direct_IO = NULL;
12598 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12601 +static struct au_dyaop *dy_aget(struct au_branch *br,
12602 + const struct address_space_operations *h_aop,
12605 + struct au_dyaop *dyaop;
12606 + struct au_dynop op;
12608 + op.dy_type = AuDy_AOP;
12609 + op.dy_haop = h_aop;
12610 + dyaop = (void *)dy_get(&op, br);
12611 + if (IS_ERR(dyaop))
12613 + dy_adx(dyaop, do_dx);
12619 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12620 + struct inode *h_inode)
12623 + struct super_block *sb;
12624 + struct au_branch *br;
12625 + struct au_dyaop *dyaop;
12627 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12628 + IiMustWriteLock(inode);
12630 + sb = inode->i_sb;
12631 + br = au_sbr(sb, bindex);
12632 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12633 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12634 + err = PTR_ERR(dyaop);
12635 + if (IS_ERR(dyaop))
12636 + /* unnecessary to call dy_fput() */
12640 + inode->i_mapping->a_ops = &dyaop->da_op;
12647 + * Is it safe to replace a_ops during the inode/file is in operation?
12648 + * Yes, I hope so.
12650 +int au_dy_irefresh(struct inode *inode)
12653 + aufs_bindex_t btop;
12654 + struct inode *h_inode;
12657 + if (S_ISREG(inode->i_mode)) {
12658 + btop = au_ibtop(inode);
12659 + h_inode = au_h_iptr(inode, btop);
12660 + err = au_dy_iaop(inode, btop, h_inode);
12665 +void au_dy_arefresh(int do_dx)
12667 + struct hlist_bl_head *hbl;
12668 + struct hlist_bl_node *pos;
12669 + struct au_dykey *key;
12671 + hbl = dynop + AuDy_AOP;
12672 + hlist_bl_lock(hbl);
12673 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12674 + dy_adx((void *)key, do_dx);
12675 + hlist_bl_unlock(hbl);
12678 +/* ---------------------------------------------------------------------- */
12680 +void __init au_dy_init(void)
12684 + for (i = 0; i < AuDyLast; i++)
12685 + INIT_HLIST_BL_HEAD(dynop + i);
12688 +void au_dy_fin(void)
12692 + for (i = 0; i < AuDyLast; i++)
12693 + WARN_ON(!hlist_bl_empty(dynop + i));
12695 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12696 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12697 +++ linux/fs/aufs/dynop.h 2022-11-05 23:02:18.962555950 +0100
12699 +/* SPDX-License-Identifier: GPL-2.0 */
12701 + * Copyright (C) 2010-2022 Junjiro R. Okajima
12703 + * This program is free software; you can redistribute it and/or modify
12704 + * it under the terms of the GNU General Public License as published by
12705 + * the Free Software Foundation; either version 2 of the License, or
12706 + * (at your option) any later version.
12708 + * This program is distributed in the hope that it will be useful,
12709 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12710 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12711 + * GNU General Public License for more details.
12713 + * You should have received a copy of the GNU General Public License
12714 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12718 + * dynamically customizable operations (for regular files only)
12721 +#ifndef __AUFS_DYNOP_H__
12722 +#define __AUFS_DYNOP_H__
12726 +#include <linux/fs.h>
12727 +#include <linux/kref.h>
12729 +enum {AuDy_AOP, AuDyLast};
12734 + const void *dy_hop;
12735 + const struct address_space_operations *dy_haop;
12741 + struct hlist_bl_node dk_hnode;
12742 + struct rcu_head dk_rcu;
12744 + struct au_dynop dk_op;
12747 + * during I am in the branch local array, kref is gotten. when the
12748 + * branch is removed, kref is put.
12750 + struct kref dk_kref;
12753 +/* stop unioning since their sizes are very different from each other */
12755 + struct au_dykey da_key;
12756 + struct address_space_operations da_op; /* not const */
12758 +/* make sure that 'struct au_dykey *' can be any type */
12759 +static_assert(!offsetof(struct au_dyaop, da_key));
12761 +/* ---------------------------------------------------------------------- */
12765 +void au_dy_put(struct au_dykey *key);
12766 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12767 + struct inode *h_inode);
12768 +int au_dy_irefresh(struct inode *inode);
12769 +void au_dy_arefresh(int do_dio);
12771 +void __init au_dy_init(void);
12772 +void au_dy_fin(void);
12774 +#endif /* __KERNEL__ */
12775 +#endif /* __AUFS_DYNOP_H__ */
12776 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12777 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12778 +++ linux/fs/aufs/export.c 2022-11-05 23:02:18.962555950 +0100
12780 +// SPDX-License-Identifier: GPL-2.0
12782 + * Copyright (C) 2005-2022 Junjiro R. Okajima
12784 + * This program is free software; you can redistribute it and/or modify
12785 + * it under the terms of the GNU General Public License as published by
12786 + * the Free Software Foundation; either version 2 of the License, or
12787 + * (at your option) any later version.
12789 + * This program is distributed in the hope that it will be useful,
12790 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12791 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12792 + * GNU General Public License for more details.
12794 + * You should have received a copy of the GNU General Public License
12795 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12802 +#include <linux/exportfs.h>
12803 +#include <linux/fs_struct.h>
12804 +#include <linux/nsproxy.h>
12805 +#include <linux/random.h>
12806 +#include <linux/writeback.h>
12810 +#ifdef CONFIG_AUFS_INO_T_64
12818 +static ino_t decode_ino(__u32 *a)
12822 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12824 +#ifdef CONFIG_AUFS_INO_T_64
12830 +static void encode_ino(__u32 *a, ino_t ino)
12836 +#ifdef CONFIG_AUFS_INO_T_64
12841 +/* NFS file handle */
12845 +#ifdef CONFIG_AUFS_INO_T_64
12846 + /* support 64bit inode number */
12859 + Fh_ino = Fh_ino1,
12860 + Fh_dir_ino = Fh_dir_ino1
12863 +static int au_test_anon(struct dentry *dentry)
12865 + /* note: read d_flags without d_lock */
12866 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12869 +int au_test_nfsd(void)
12872 + struct task_struct *tsk = current;
12873 + char comm[sizeof(tsk->comm)];
12876 + if (tsk->flags & PF_KTHREAD) {
12877 + get_task_comm(comm, tsk);
12878 + ret = !strcmp(comm, "nfsd");
12884 +/* ---------------------------------------------------------------------- */
12885 +/* inode generation external table */
12887 +void au_xigen_inc(struct inode *inode)
12892 + struct super_block *sb;
12893 + struct au_sbinfo *sbinfo;
12895 + sb = inode->i_sb;
12896 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12898 + sbinfo = au_sbi(sb);
12899 + pos = inode->i_ino;
12900 + pos *= sizeof(igen);
12901 + igen = inode->i_generation + 1;
12902 + sz = xino_fwrite(sbinfo->si_xigen, &igen, sizeof(igen), &pos);
12903 + if (sz == sizeof(igen))
12904 + return; /* success */
12906 + if (unlikely(sz >= 0))
12907 + AuIOErr("xigen error (%zd)\n", sz);
12910 +int au_xigen_new(struct inode *inode)
12915 + struct super_block *sb;
12916 + struct au_sbinfo *sbinfo;
12917 + struct file *file;
12920 + /* todo: dirty, at mount time */
12921 + if (inode->i_ino == AUFS_ROOT_INO)
12923 + sb = inode->i_sb;
12924 + SiMustAnyLock(sb);
12925 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12929 + pos = inode->i_ino;
12930 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12931 + AuIOErr1("too large i%lld\n", pos);
12934 + pos *= sizeof(inode->i_generation);
12937 + sbinfo = au_sbi(sb);
12938 + file = sbinfo->si_xigen;
12941 + if (vfsub_f_size_read(file)
12942 + < pos + sizeof(inode->i_generation)) {
12943 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12944 + sz = xino_fwrite(file, &inode->i_generation,
12945 + sizeof(inode->i_generation), &pos);
12947 + sz = xino_fread(file, &inode->i_generation,
12948 + sizeof(inode->i_generation), &pos);
12949 + if (sz == sizeof(inode->i_generation))
12950 + goto out; /* success */
12953 + if (unlikely(sz >= 0)) {
12955 + AuIOErr("xigen error (%zd)\n", sz);
12962 +int au_xigen_set(struct super_block *sb, struct path *path)
12965 + struct au_sbinfo *sbinfo;
12966 + struct file *file;
12968 + SiMustWriteLock(sb);
12970 + sbinfo = au_sbi(sb);
12971 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
12972 + err = PTR_ERR(file);
12973 + if (IS_ERR(file))
12976 + if (sbinfo->si_xigen)
12977 + fput(sbinfo->si_xigen);
12978 + sbinfo->si_xigen = file;
12985 +void au_xigen_clr(struct super_block *sb)
12987 + struct au_sbinfo *sbinfo;
12989 + SiMustWriteLock(sb);
12991 + sbinfo = au_sbi(sb);
12992 + if (sbinfo->si_xigen) {
12993 + fput(sbinfo->si_xigen);
12994 + sbinfo->si_xigen = NULL;
12998 +/* ---------------------------------------------------------------------- */
13000 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13003 + struct dentry *dentry, *d;
13004 + struct inode *inode;
13005 + unsigned int sigen;
13008 + inode = ilookup(sb, ino);
13012 + dentry = ERR_PTR(-ESTALE);
13013 + sigen = au_sigen(sb);
13014 + if (unlikely(au_is_bad_inode(inode)
13015 + || IS_DEADDIR(inode)
13016 + || sigen != au_iigen(inode, NULL)))
13020 + if (!dir_ino || S_ISDIR(inode->i_mode))
13021 + dentry = d_find_alias(inode);
13023 + spin_lock(&inode->i_lock);
13024 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13025 + spin_lock(&d->d_lock);
13026 + if (!au_test_anon(d)
13027 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13028 + dentry = dget_dlock(d);
13029 + spin_unlock(&d->d_lock);
13032 + spin_unlock(&d->d_lock);
13034 + spin_unlock(&inode->i_lock);
13036 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13037 + /* need to refresh */
13045 + AuTraceErrPtr(dentry);
13049 +/* ---------------------------------------------------------------------- */
13051 +/* todo: dirty? */
13052 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13054 +struct au_compare_mnt_args {
13056 + struct super_block *sb;
13059 + struct vfsmount *mnt;
13062 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13064 + struct au_compare_mnt_args *a = arg;
13066 + if (mnt->mnt_sb != a->sb)
13068 + a->mnt = mntget(mnt);
13072 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13075 + struct path root;
13076 + struct au_compare_mnt_args args = {
13080 + get_fs_root(current->fs, &root);
13082 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13083 + rcu_read_unlock();
13086 + AuDebugOn(!args.mnt);
13090 +struct au_nfsd_si_lock {
13091 + unsigned int sigen;
13092 + aufs_bindex_t bindex, br_id;
13093 + unsigned char force_lock;
13096 +static int si_nfsd_read_lock(struct super_block *sb,
13097 + struct au_nfsd_si_lock *nsi_lock)
13100 + aufs_bindex_t bindex;
13102 + si_read_lock(sb, AuLock_FLUSH);
13104 + /* branch id may be wrapped around */
13106 + bindex = au_br_index(sb, nsi_lock->br_id);
13107 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13108 + goto out; /* success */
13112 + if (!nsi_lock->force_lock)
13113 + si_read_unlock(sb);
13116 + nsi_lock->bindex = bindex;
13120 +struct find_name_by_ino {
13121 + struct dir_context ctx;
13122 + int called, found;
13129 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13130 + loff_t offset, u64 ino, unsigned int d_type)
13132 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13136 + if (a->ino != ino)
13139 + memcpy(a->name, name, namelen);
13140 + a->namelen = namelen;
13145 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13146 + struct au_nfsd_si_lock *nsi_lock)
13148 + struct dentry *dentry, *parent;
13149 + struct file *file;
13150 + struct inode *dir;
13151 + struct find_name_by_ino arg = {
13153 + .actor = find_name_by_ino
13158 + parent = path->dentry;
13160 + si_read_unlock(parent->d_sb);
13161 + file = vfsub_dentry_open(path, au_dir_roflags);
13162 + dentry = (void *)file;
13163 + if (IS_ERR(file))
13166 + dentry = ERR_PTR(-ENOMEM);
13167 + arg.name = (void *)__get_free_page(GFP_NOFS);
13168 + if (unlikely(!arg.name))
13175 + err = vfsub_iterate_dir(file, &arg.ctx);
13176 + } while (!err && !arg.found && arg.called);
13177 + dentry = ERR_PTR(err);
13178 + if (unlikely(err))
13180 + /* instead of ENOENT */
13181 + dentry = ERR_PTR(-ESTALE);
13185 + /* do not call vfsub_lkup_one() */
13186 + dir = d_inode(parent);
13187 + dentry = vfsub_lookup_one_len_unlocked(arg.name, path, arg.namelen);
13188 + AuTraceErrPtr(dentry);
13189 + if (IS_ERR(dentry))
13191 + AuDebugOn(au_test_anon(dentry));
13192 + if (unlikely(d_really_is_negative(dentry))) {
13194 + dentry = ERR_PTR(-ENOENT);
13198 + free_page((unsigned long)arg.name);
13202 + if (unlikely(nsi_lock
13203 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13204 + if (!IS_ERR(dentry)) {
13206 + dentry = ERR_PTR(-ESTALE);
13208 + AuTraceErrPtr(dentry);
13212 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13214 + struct au_nfsd_si_lock *nsi_lock)
13216 + struct dentry *dentry;
13217 + struct path path;
13219 + if (dir_ino != AUFS_ROOT_INO) {
13220 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13221 + dentry = path.dentry;
13222 + if (!path.dentry || IS_ERR(path.dentry))
13224 + AuDebugOn(au_test_anon(path.dentry));
13226 + path.dentry = dget(sb->s_root);
13228 + path.mnt = au_mnt_get(sb);
13229 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13233 + AuTraceErrPtr(dentry);
13237 +/* ---------------------------------------------------------------------- */
13239 +static int h_acceptable(void *expv, struct dentry *dentry)
13244 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13245 + char *buf, int len, struct super_block *sb)
13249 + struct path path;
13251 + p = d_path(h_rootpath, buf, len);
13256 + path.mnt = h_rootpath->mnt;
13257 + path.dentry = h_parent;
13258 + p = d_path(&path, buf, len);
13264 + path.mnt = au_mnt_get(sb);
13265 + path.dentry = sb->s_root;
13266 + p = d_path(&path, buf, len - strlen(p));
13267 + mntput(path.mnt);
13271 + p[strlen(p)] = '/';
13274 + AuTraceErrPtr(p);
13279 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13280 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13282 + struct dentry *dentry, *h_parent, *root;
13283 + struct super_block *h_sb;
13284 + char *pathname, *p;
13285 + struct vfsmount *h_mnt;
13286 + struct au_branch *br;
13288 + struct path path;
13290 + br = au_sbr(sb, nsi_lock->bindex);
13291 + h_mnt = au_br_mnt(br);
13292 + h_sb = h_mnt->mnt_sb;
13293 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13295 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13296 + fh_len - Fh_tail, fh[Fh_h_type],
13297 + h_acceptable, /*context*/NULL);
13299 + dentry = h_parent;
13300 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13301 + AuWarn1("%s decode_fh failed, %ld\n",
13302 + au_sbtype(h_sb), PTR_ERR(h_parent));
13306 + if (unlikely(au_test_anon(h_parent))) {
13307 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13308 + au_sbtype(h_sb));
13309 + goto out_h_parent;
13312 + dentry = ERR_PTR(-ENOMEM);
13313 + pathname = (void *)__get_free_page(GFP_NOFS);
13314 + if (unlikely(!pathname))
13315 + goto out_h_parent;
13317 + root = sb->s_root;
13318 + path.mnt = h_mnt;
13319 + di_read_lock_parent(root, !AuLock_IR);
13320 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13321 + di_read_unlock(root, !AuLock_IR);
13322 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13323 + dentry = (void *)p;
13325 + goto out_pathname;
13327 + si_read_unlock(sb);
13328 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13329 + dentry = ERR_PTR(err);
13330 + if (unlikely(err))
13333 + dentry = ERR_PTR(-ENOENT);
13334 + AuDebugOn(au_test_anon(path.dentry));
13335 + if (unlikely(d_really_is_negative(path.dentry)))
13338 + if (ino != d_inode(path.dentry)->i_ino)
13339 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13341 + dentry = dget(path.dentry);
13346 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13347 + if (!IS_ERR(dentry)) {
13349 + dentry = ERR_PTR(-ESTALE);
13352 + free_page((unsigned long)pathname);
13356 + AuTraceErrPtr(dentry);
13360 +/* ---------------------------------------------------------------------- */
13362 +static struct dentry *
13363 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13366 + struct dentry *dentry;
13367 + __u32 *fh = fid->raw;
13368 + struct au_branch *br;
13369 + ino_t ino, dir_ino;
13370 + struct au_nfsd_si_lock nsi_lock = {
13374 + dentry = ERR_PTR(-ESTALE);
13375 + /* it should never happen, but the file handle is unreliable */
13376 + if (unlikely(fh_len < Fh_tail))
13378 + nsi_lock.sigen = fh[Fh_sigen];
13379 + nsi_lock.br_id = fh[Fh_br_id];
13381 + /* branch id may be wrapped around */
13383 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13385 + nsi_lock.force_lock = 1;
13387 + /* is this inode still cached? */
13388 + ino = decode_ino(fh + Fh_ino);
13389 + /* it should never happen */
13390 + if (unlikely(ino == AUFS_ROOT_INO))
13393 + dir_ino = decode_ino(fh + Fh_dir_ino);
13394 + dentry = decode_by_ino(sb, ino, dir_ino);
13395 + if (IS_ERR(dentry))
13400 + /* is the parent dir cached? */
13401 + br = au_sbr(sb, nsi_lock.bindex);
13402 + au_lcnt_inc(&br->br_nfiles);
13403 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13404 + if (IS_ERR(dentry))
13409 + /* lookup path */
13410 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13411 + if (IS_ERR(dentry))
13413 + if (unlikely(!dentry))
13414 + /* todo?: make it ESTALE */
13418 + if (!au_digen_test(dentry, au_sigen(sb))
13419 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13420 + goto out_unlock; /* success */
13423 + dentry = ERR_PTR(-ESTALE);
13426 + au_lcnt_dec(&br->br_nfiles);
13427 + si_read_unlock(sb);
13429 + AuTraceErrPtr(dentry);
13433 +#if 0 /* reserved for future use */
13434 +/* support subtreecheck option */
13435 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13436 + int fh_len, int fh_type)
13438 + struct dentry *parent;
13439 + __u32 *fh = fid->raw;
13442 + dir_ino = decode_ino(fh + Fh_dir_ino);
13443 + parent = decode_by_ino(sb, dir_ino, 0);
13444 + if (IS_ERR(parent))
13447 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13448 + dir_ino, fh, fh_len);
13451 + AuTraceErrPtr(parent);
13456 +/* ---------------------------------------------------------------------- */
13458 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13459 + struct inode *dir)
13462 + aufs_bindex_t bindex;
13463 + struct super_block *sb, *h_sb;
13464 + struct dentry *dentry, *parent, *h_parent;
13465 + struct inode *h_dir;
13466 + struct au_branch *br;
13469 + if (unlikely(*max_len <= Fh_tail)) {
13470 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13474 + err = FILEID_ROOT;
13475 + if (inode->i_ino == AUFS_ROOT_INO) {
13476 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13481 + sb = inode->i_sb;
13482 + err = si_read_lock(sb, AuLock_FLUSH);
13483 + if (unlikely(err))
13486 +#ifdef CONFIG_AUFS_DEBUG
13487 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13488 + AuWarn1("NFS-exporting requires xino\n");
13492 + ii_read_lock_child(inode);
13493 + bindex = au_ibtop(inode);
13495 + dentry = d_find_any_alias(inode);
13496 + if (unlikely(!dentry))
13498 + AuDebugOn(au_test_anon(dentry));
13499 + parent = dget_parent(dentry);
13501 + if (unlikely(!parent))
13503 + if (d_really_is_positive(parent))
13504 + dir = d_inode(parent);
13507 + ii_read_lock_parent(dir);
13508 + h_dir = au_h_iptr(dir, bindex);
13509 + ii_read_unlock(dir);
13510 + if (unlikely(!h_dir))
13512 + h_parent = d_find_any_alias(h_dir);
13513 + if (unlikely(!h_parent))
13514 + goto out_hparent;
13517 + br = au_sbr(sb, bindex);
13518 + h_sb = au_br_sb(br);
13519 + if (unlikely(!h_sb->s_export_op)) {
13520 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13521 + goto out_hparent;
13524 + fh[Fh_br_id] = br->br_id;
13525 + fh[Fh_sigen] = au_sigen(sb);
13526 + encode_ino(fh + Fh_ino, inode->i_ino);
13527 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13528 + fh[Fh_igen] = inode->i_generation;
13530 + *max_len -= Fh_tail;
13531 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13533 + /*connectable or subtreecheck*/0);
13534 + err = fh[Fh_h_type];
13535 + *max_len += Fh_tail;
13536 + /* todo: macros? */
13537 + if (err != FILEID_INVALID)
13540 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13547 + ii_read_unlock(inode);
13548 + si_read_unlock(sb);
13550 + if (unlikely(err < 0))
13551 + err = FILEID_INVALID;
13555 +/* ---------------------------------------------------------------------- */
13557 +static int aufs_commit_metadata(struct inode *inode)
13560 + aufs_bindex_t bindex;
13561 + struct super_block *sb;
13562 + struct inode *h_inode;
13563 + int (*f)(struct inode *inode);
13565 + sb = inode->i_sb;
13566 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13567 + ii_write_lock_child(inode);
13568 + bindex = au_ibtop(inode);
13569 + AuDebugOn(bindex < 0);
13570 + h_inode = au_h_iptr(inode, bindex);
13572 + f = h_inode->i_sb->s_export_op->commit_metadata;
13574 + err = f(h_inode);
13576 + err = sync_inode_metadata(h_inode, /*wait*/1);
13578 + au_cpup_attr_timesizes(inode);
13579 + ii_write_unlock(inode);
13580 + si_read_unlock(sb);
13584 +/* ---------------------------------------------------------------------- */
13586 +static struct export_operations aufs_export_op = {
13587 + .fh_to_dentry = aufs_fh_to_dentry,
13588 + /* .fh_to_parent = aufs_fh_to_parent, */
13589 + .encode_fh = aufs_encode_fh,
13590 + .commit_metadata = aufs_commit_metadata
13593 +void au_export_init(struct super_block *sb)
13595 + struct au_sbinfo *sbinfo;
13598 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13599 + && IS_MODULE(CONFIG_EXPORTFS),
13600 + AUFS_NAME ": unsupported configuration "
13601 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13603 + sb->s_export_op = &aufs_export_op;
13604 + sbinfo = au_sbi(sb);
13605 + sbinfo->si_xigen = NULL;
13606 + get_random_bytes(&u, sizeof(u));
13607 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13608 + atomic_set(&sbinfo->si_xigen_next, u);
13610 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13611 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13612 +++ linux/fs/aufs/fhsm.c 2022-11-05 23:02:18.962555950 +0100
13614 +// SPDX-License-Identifier: GPL-2.0
13616 + * Copyright (C) 2011-2022 Junjiro R. Okajima
13618 + * This program is free software; you can redistribute it and/or modify
13619 + * it under the terms of the GNU General Public License as published by
13620 + * the Free Software Foundation; either version 2 of the License, or
13621 + * (at your option) any later version.
13623 + * This program is distributed in the hope that it will be useful,
13624 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13625 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13626 + * GNU General Public License for more details.
13628 + * You should have received a copy of the GNU General Public License
13629 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13633 + * File-based Hierarchy Storage Management
13636 +#include <linux/anon_inodes.h>
13637 +#include <linux/poll.h>
13638 +#include <linux/seq_file.h>
13639 +#include <linux/statfs.h>
13642 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13644 + struct au_sbinfo *sbinfo;
13645 + struct au_fhsm *fhsm;
13647 + SiMustAnyLock(sb);
13649 + sbinfo = au_sbi(sb);
13650 + fhsm = &sbinfo->si_fhsm;
13651 + AuDebugOn(!fhsm);
13652 + return fhsm->fhsm_bottom;
13655 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13657 + struct au_sbinfo *sbinfo;
13658 + struct au_fhsm *fhsm;
13660 + SiMustWriteLock(sb);
13662 + sbinfo = au_sbi(sb);
13663 + fhsm = &sbinfo->si_fhsm;
13664 + AuDebugOn(!fhsm);
13665 + fhsm->fhsm_bottom = bindex;
13668 +/* ---------------------------------------------------------------------- */
13670 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13672 + struct au_br_fhsm *bf;
13674 + bf = br->br_fhsm;
13675 + MtxMustLock(&bf->bf_lock);
13677 + return !bf->bf_readable
13678 + || time_after(jiffies,
13679 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13682 +/* ---------------------------------------------------------------------- */
13684 +static void au_fhsm_notify(struct super_block *sb, int val)
13686 + struct au_sbinfo *sbinfo;
13687 + struct au_fhsm *fhsm;
13689 + SiMustAnyLock(sb);
13691 + sbinfo = au_sbi(sb);
13692 + fhsm = &sbinfo->si_fhsm;
13693 + if (au_fhsm_pid(fhsm)
13694 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13695 + atomic_set(&fhsm->fhsm_readable, val);
13697 + wake_up(&fhsm->fhsm_wqh);
13701 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13702 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13705 + struct au_branch *br;
13706 + struct au_br_fhsm *bf;
13708 + br = au_sbr(sb, bindex);
13709 + AuDebugOn(au_br_rdonly(br));
13710 + bf = br->br_fhsm;
13714 + mutex_lock(&bf->bf_lock);
13716 + MtxMustLock(&bf->bf_lock);
13718 + /* sb->s_root for NFS is unreliable */
13719 + err = au_br_stfs(br, &bf->bf_stfs);
13720 + if (unlikely(err)) {
13721 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13725 + bf->bf_jiffy = jiffies;
13726 + bf->bf_readable = 1;
13728 + au_fhsm_notify(sb, /*val*/1);
13730 + *rstfs = bf->bf_stfs;
13734 + mutex_unlock(&bf->bf_lock);
13735 + au_fhsm_notify(sb, /*val*/1);
13740 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13743 + struct au_sbinfo *sbinfo;
13744 + struct au_fhsm *fhsm;
13745 + struct au_branch *br;
13746 + struct au_br_fhsm *bf;
13748 + AuDbg("b%d, force %d\n", bindex, force);
13749 + SiMustAnyLock(sb);
13751 + sbinfo = au_sbi(sb);
13752 + fhsm = &sbinfo->si_fhsm;
13753 + if (!au_ftest_si(sbinfo, FHSM)
13754 + || fhsm->fhsm_bottom == bindex)
13757 + br = au_sbr(sb, bindex);
13758 + bf = br->br_fhsm;
13760 + mutex_lock(&bf->bf_lock);
13762 + || au_fhsm_pid(fhsm)
13763 + || au_fhsm_test_jiffy(sbinfo, br))
13764 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13766 + mutex_unlock(&bf->bf_lock);
13769 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13771 + aufs_bindex_t bindex, bbot;
13772 + struct au_branch *br;
13774 + /* exclude the bottom */
13775 + bbot = au_fhsm_bottom(sb);
13776 + for (bindex = 0; bindex < bbot; bindex++) {
13777 + br = au_sbr(sb, bindex);
13778 + if (au_br_fhsm(br->br_perm))
13779 + au_fhsm_wrote(sb, bindex, force);
13783 +/* ---------------------------------------------------------------------- */
13785 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13788 + struct au_sbinfo *sbinfo;
13789 + struct au_fhsm *fhsm;
13792 + sbinfo = file->private_data;
13793 + fhsm = &sbinfo->si_fhsm;
13794 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13795 + if (atomic_read(&fhsm->fhsm_readable))
13796 + mask = EPOLLIN /* | EPOLLRDNORM */;
13799 + AuDbg("mask 0x%x\n", mask);
13803 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13804 + struct aufs_stfs *stfs, __s16 brid)
13808 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13810 + err = __put_user(brid, &stbr->brid);
13811 + if (unlikely(err))
13817 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13818 + struct aufs_stbr __user *stbr, size_t count)
13822 + aufs_bindex_t bindex, bbot;
13823 + struct au_branch *br;
13824 + struct au_br_fhsm *bf;
13826 + /* except the bottom branch */
13829 + bbot = au_fhsm_bottom(sb);
13830 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13831 + br = au_sbr(sb, bindex);
13832 + if (!au_br_fhsm(br->br_perm))
13835 + bf = br->br_fhsm;
13836 + mutex_lock(&bf->bf_lock);
13837 + if (bf->bf_readable) {
13839 + if (count >= sizeof(*stbr))
13840 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13843 + bf->bf_readable = 0;
13844 + count -= sizeof(*stbr);
13848 + mutex_unlock(&bf->bf_lock);
13851 + err = sizeof(*stbr) * nstbr;
13856 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13861 + aufs_bindex_t nfhsm, bindex, bbot;
13862 + struct au_sbinfo *sbinfo;
13863 + struct au_fhsm *fhsm;
13864 + struct au_branch *br;
13865 + struct super_block *sb;
13868 + sbinfo = file->private_data;
13869 + fhsm = &sbinfo->si_fhsm;
13871 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13872 + if (!atomic_read(&fhsm->fhsm_readable)) {
13873 + if (vfsub_file_flags(file) & O_NONBLOCK)
13876 + err = wait_event_interruptible_locked_irq
13878 + atomic_read(&fhsm->fhsm_readable));
13880 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13881 + if (unlikely(err))
13884 + /* sb may already be dead */
13885 + au_rw_read_lock(&sbinfo->si_rwsem);
13886 + readable = atomic_read(&fhsm->fhsm_readable);
13887 + if (readable > 0) {
13888 + sb = sbinfo->si_sb;
13890 + /* exclude the bottom branch */
13892 + bbot = au_fhsm_bottom(sb);
13893 + for (bindex = 0; bindex < bbot; bindex++) {
13894 + br = au_sbr(sb, bindex);
13895 + if (au_br_fhsm(br->br_perm))
13899 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13900 + atomic_set(&fhsm->fhsm_readable, 0);
13901 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13905 + au_rw_read_unlock(&sbinfo->si_rwsem);
13913 +static int au_fhsm_release(struct inode *inode, struct file *file)
13915 + struct au_sbinfo *sbinfo;
13916 + struct au_fhsm *fhsm;
13918 + /* sb may already be dead */
13919 + sbinfo = file->private_data;
13920 + fhsm = &sbinfo->si_fhsm;
13921 + spin_lock(&fhsm->fhsm_spin);
13922 + fhsm->fhsm_pid = 0;
13923 + spin_unlock(&fhsm->fhsm_spin);
13924 + kobject_put(&sbinfo->si_kobj);
13929 +static const struct file_operations au_fhsm_fops = {
13930 + .owner = THIS_MODULE,
13931 + .llseek = noop_llseek,
13932 + .read = au_fhsm_read,
13933 + .poll = au_fhsm_poll,
13934 + .release = au_fhsm_release
13937 +int au_fhsm_fd(struct super_block *sb, int oflags)
13940 + struct au_sbinfo *sbinfo;
13941 + struct au_fhsm *fhsm;
13944 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13948 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13952 + sbinfo = au_sbi(sb);
13953 + fhsm = &sbinfo->si_fhsm;
13954 + spin_lock(&fhsm->fhsm_spin);
13955 + if (!fhsm->fhsm_pid)
13956 + fhsm->fhsm_pid = current->pid;
13959 + spin_unlock(&fhsm->fhsm_spin);
13960 + if (unlikely(err))
13963 + oflags |= O_RDONLY;
13964 + /* oflags |= FMODE_NONOTIFY; */
13965 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
13967 + if (unlikely(fd < 0))
13970 + /* succeed regardless 'fhsm' status */
13971 + kobject_get(&sbinfo->si_kobj);
13972 + si_noflush_read_lock(sb);
13973 + if (au_ftest_si(sbinfo, FHSM))
13974 + au_fhsm_wrote_all(sb, /*force*/0);
13975 + si_read_unlock(sb);
13976 + goto out; /* success */
13979 + spin_lock(&fhsm->fhsm_spin);
13980 + fhsm->fhsm_pid = 0;
13981 + spin_unlock(&fhsm->fhsm_spin);
13987 +/* ---------------------------------------------------------------------- */
13989 +int au_fhsm_br_alloc(struct au_branch *br)
13994 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
13996 + au_br_fhsm_init(br->br_fhsm);
14003 +/* ---------------------------------------------------------------------- */
14005 +void au_fhsm_fin(struct super_block *sb)
14007 + au_fhsm_notify(sb, /*val*/-1);
14010 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14012 + struct au_fhsm *fhsm;
14014 + fhsm = &sbinfo->si_fhsm;
14015 + spin_lock_init(&fhsm->fhsm_spin);
14016 + init_waitqueue_head(&fhsm->fhsm_wqh);
14017 + atomic_set(&fhsm->fhsm_readable, 0);
14018 + fhsm->fhsm_expire
14019 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14020 + fhsm->fhsm_bottom = -1;
14023 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14025 + sbinfo->si_fhsm.fhsm_expire
14026 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14029 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14033 + if (!au_ftest_si(sbinfo, FHSM))
14036 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14037 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14038 + seq_printf(seq, ",fhsm_sec=%u", u);
14040 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14041 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14042 +++ linux/fs/aufs/file.c 2022-11-05 23:02:18.965889284 +0100
14044 +// SPDX-License-Identifier: GPL-2.0
14046 + * Copyright (C) 2005-2022 Junjiro R. Okajima
14048 + * This program is free software; you can redistribute it and/or modify
14049 + * it under the terms of the GNU General Public License as published by
14050 + * the Free Software Foundation; either version 2 of the License, or
14051 + * (at your option) any later version.
14053 + * This program is distributed in the hope that it will be useful,
14054 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14055 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14056 + * GNU General Public License for more details.
14058 + * You should have received a copy of the GNU General Public License
14059 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14063 + * handling file/dir, and address_space operation
14066 +#ifdef CONFIG_AUFS_DEBUG
14067 +#include <linux/migrate.h>
14069 +#include <linux/pagemap.h>
14072 +/* drop flags for writing */
14073 +unsigned int au_file_roflags(unsigned int flags)
14075 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14076 + flags |= O_RDONLY | O_NOATIME;
14080 +/* common functions to regular file and dir */
14081 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14082 + struct file *file, int force_wr)
14084 + struct file *h_file;
14085 + struct dentry *h_dentry;
14086 + struct inode *h_inode;
14087 + struct super_block *sb;
14088 + struct au_branch *br;
14089 + struct path h_path;
14092 + /* a race condition can happen between open and unlink/rmdir */
14093 + h_file = ERR_PTR(-ENOENT);
14094 + h_dentry = au_h_dptr(dentry, bindex);
14095 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14097 + h_inode = d_inode(h_dentry);
14098 + spin_lock(&h_dentry->d_lock);
14099 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14100 + /* || !d_inode(dentry)->i_nlink */
14102 + spin_unlock(&h_dentry->d_lock);
14103 + if (unlikely(err))
14106 + sb = dentry->d_sb;
14107 + br = au_sbr(sb, bindex);
14108 + err = au_br_test_oflag(flags, br);
14109 + h_file = ERR_PTR(err);
14110 + if (unlikely(err))
14113 + /* drop flags for writing */
14114 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14115 + if (force_wr && !(flags & O_WRONLY))
14117 + flags = au_file_roflags(flags);
14119 + h_file = ERR_PTR(-EROFS);
14120 + flags = au_file_roflags(flags);
14121 + if (unlikely(vfsub_native_ro(h_inode)
14122 + || IS_APPEND(h_inode)))
14124 + flags &= ~O_ACCMODE;
14125 + flags |= O_WRONLY;
14128 + flags &= ~O_CREAT;
14129 + au_lcnt_inc(&br->br_nfiles);
14130 + h_path.dentry = h_dentry;
14131 + h_path.mnt = au_br_mnt(br);
14132 + h_file = vfsub_dentry_open(&h_path, flags);
14133 + if (IS_ERR(h_file))
14136 + if (flags & __FMODE_EXEC) {
14137 + err = deny_write_access(h_file);
14138 + if (unlikely(err)) {
14140 + h_file = ERR_PTR(err);
14144 + fsnotify_open(h_file);
14145 + goto out; /* success */
14148 + au_lcnt_dec(&br->br_nfiles);
14153 +static int au_cmoo(struct dentry *dentry)
14155 + int err, cmoo, matched;
14156 + unsigned int udba;
14157 + struct path h_path;
14158 + struct au_pin pin;
14159 + struct au_cp_generic cpg = {
14160 + .dentry = dentry,
14165 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14167 + struct inode *delegated;
14168 + struct super_block *sb;
14169 + struct au_sbinfo *sbinfo;
14170 + struct au_fhsm *fhsm;
14172 + struct au_branch *br;
14173 + struct dentry *parent;
14174 + struct au_hinode *hdir;
14176 + DiMustWriteLock(dentry);
14177 + IiMustWriteLock(d_inode(dentry));
14180 + if (IS_ROOT(dentry))
14182 + cpg.bsrc = au_dbtop(dentry);
14186 + sb = dentry->d_sb;
14187 + sbinfo = au_sbi(sb);
14188 + fhsm = &sbinfo->si_fhsm;
14189 + pid = au_fhsm_pid(fhsm);
14192 + && (current->pid == pid
14193 + || rcu_dereference(current->real_parent)->pid == pid));
14194 + rcu_read_unlock();
14198 + br = au_sbr(sb, cpg.bsrc);
14199 + cmoo = au_br_cmoo(br->br_perm);
14202 + if (!d_is_reg(dentry))
14203 + cmoo &= AuBrAttr_COO_ALL;
14207 + parent = dget_parent(dentry);
14208 + di_write_lock_parent(parent);
14209 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14211 + if (unlikely(err < 0)) {
14212 + err = 0; /* there is no upper writable branch */
14215 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14217 + /* do not respect the coo attrib for the target branch */
14218 + err = au_cpup_dirs(dentry, cpg.bdst);
14219 + if (unlikely(err))
14222 + di_downgrade_lock(parent, AuLock_IR);
14223 + udba = au_opt_udba(sb);
14224 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14225 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14226 + if (unlikely(err))
14229 + err = au_sio_cpup_simple(&cpg);
14231 + if (unlikely(err))
14233 + if (!(cmoo & AuBrWAttr_MOO))
14234 + goto out_parent; /* success */
14236 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14237 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14238 + if (unlikely(err))
14241 + h_path.mnt = au_br_mnt(br);
14242 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14243 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14244 + delegated = NULL;
14245 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14247 + /* todo: keep h_dentry or not? */
14248 + if (unlikely(err == -EWOULDBLOCK)) {
14249 + pr_warn("cannot retry for NFSv4 delegation"
14250 + " for an internal unlink\n");
14253 + if (unlikely(err)) {
14254 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14258 + goto out_parent; /* success */
14261 + di_downgrade_lock(parent, AuLock_IR);
14263 + di_read_unlock(parent, AuLock_IR);
14270 +int au_do_open(struct file *file, struct au_do_open_args *args)
14272 + int err, aopen = args->aopen;
14273 + struct dentry *dentry;
14274 + struct au_finfo *finfo;
14277 + err = au_finfo_init(file, args->fidir);
14280 + err = au_finfo_init(file, args->fidir);
14283 + if (unlikely(err))
14286 + dentry = file->f_path.dentry;
14287 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14288 + di_write_lock_child(dentry);
14289 + err = au_cmoo(dentry);
14290 + di_downgrade_lock(dentry, AuLock_IR);
14293 + err = args->open(file, vfsub_file_flags(file), NULL);
14296 + err = args->open(file, vfsub_file_flags(file),
14301 + di_read_unlock(dentry, AuLock_IR);
14303 + finfo = au_fi(file);
14305 + finfo->fi_file = file;
14306 + au_hbl_add(&finfo->fi_hlist,
14307 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14310 + fi_write_unlock(file);
14313 + fi_write_unlock(file);
14316 + if (unlikely(err)) {
14317 + finfo->fi_hdir = NULL;
14318 + au_finfo_fin(file);
14326 +int au_reopen_nondir(struct file *file)
14329 + aufs_bindex_t btop;
14330 + struct dentry *dentry;
14331 + struct au_branch *br;
14332 + struct file *h_file, *h_file_tmp;
14334 + dentry = file->f_path.dentry;
14335 + btop = au_dbtop(dentry);
14336 + br = au_sbr(dentry->d_sb, btop);
14337 + h_file_tmp = NULL;
14338 + if (au_fbtop(file) == btop) {
14339 + h_file = au_hf_top(file);
14340 + if (file->f_mode == h_file->f_mode)
14341 + return 0; /* success */
14342 + h_file_tmp = h_file;
14343 + get_file(h_file_tmp);
14344 + au_lcnt_inc(&br->br_nfiles);
14345 + au_set_h_fptr(file, btop, NULL);
14347 + AuDebugOn(au_fi(file)->fi_hdir);
14350 + * file exists on both of rw and ro
14351 + * open --> dbtop and fbtop are both 0
14352 + * prepend a branch as rw, "rw" become ro
14354 + * delete the top branch, "rw" becomes rw again
14355 + * --> dbtop is 1, fbtop is still 0
14356 + * write --> fbtop is 0 but dbtop is 1
14358 + /* AuDebugOn(au_fbtop(file) < btop); */
14360 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14361 + file, /*force_wr*/0);
14362 + err = PTR_ERR(h_file);
14363 + if (IS_ERR(h_file)) {
14364 + if (h_file_tmp) {
14366 + au_set_h_fptr(file, btop, h_file_tmp);
14367 + h_file_tmp = NULL;
14369 + goto out; /* todo: close all? */
14373 + au_set_fbtop(file, btop);
14374 + au_set_h_fptr(file, btop, h_file);
14375 + au_update_figen(file);
14376 + /* todo: necessary? */
14377 + /* file->f_ra = h_file->f_ra; */
14380 + if (h_file_tmp) {
14381 + fput(h_file_tmp);
14382 + au_lcnt_dec(&br->br_nfiles);
14387 +/* ---------------------------------------------------------------------- */
14389 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14390 + struct dentry *hi_wh)
14393 + aufs_bindex_t btop;
14394 + struct au_dinfo *dinfo;
14395 + struct dentry *h_dentry;
14396 + struct au_hdentry *hdp;
14398 + dinfo = au_di(file->f_path.dentry);
14399 + AuRwMustWriteLock(&dinfo->di_rwsem);
14401 + btop = dinfo->di_btop;
14402 + dinfo->di_btop = btgt;
14403 + hdp = au_hdentry(dinfo, btgt);
14404 + h_dentry = hdp->hd_dentry;
14405 + hdp->hd_dentry = hi_wh;
14406 + err = au_reopen_nondir(file);
14407 + hdp->hd_dentry = h_dentry;
14408 + dinfo->di_btop = btop;
14413 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14414 + aufs_bindex_t bcpup, struct au_pin *pin)
14417 + struct inode *inode, *h_inode;
14418 + struct dentry *h_dentry, *hi_wh;
14419 + struct au_cp_generic cpg = {
14420 + .dentry = file->f_path.dentry,
14427 + au_update_dbtop(cpg.dentry);
14428 + inode = d_inode(cpg.dentry);
14430 + if (au_dbtop(cpg.dentry) <= bcpup
14431 + && au_dbbot(cpg.dentry) >= bcpup) {
14432 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14433 + if (h_dentry && d_is_positive(h_dentry))
14434 + h_inode = d_inode(h_dentry);
14436 + hi_wh = au_hi_wh(inode, bcpup);
14437 + if (!hi_wh && !h_inode)
14438 + err = au_sio_cpup_wh(&cpg, file);
14440 + /* already copied-up after unlink */
14441 + err = au_reopen_wh(file, bcpup, hi_wh);
14444 + && (inode->i_nlink > 1
14445 + || (inode->i_state & I_LINKABLE))
14446 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14447 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14453 + * prepare the @file for writing.
14455 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14458 + aufs_bindex_t dbtop;
14459 + struct dentry *parent;
14460 + struct inode *inode;
14461 + struct super_block *sb;
14462 + struct file *h_file;
14463 + struct au_cp_generic cpg = {
14464 + .dentry = file->f_path.dentry,
14469 + .flags = AuCpup_DTIME
14472 + sb = cpg.dentry->d_sb;
14473 + inode = d_inode(cpg.dentry);
14474 + cpg.bsrc = au_fbtop(file);
14475 + err = au_test_ro(sb, cpg.bsrc, inode);
14476 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14477 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14482 + /* need to cpup or reopen */
14483 + parent = dget_parent(cpg.dentry);
14484 + di_write_lock_parent(parent);
14485 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14487 + if (unlikely(err < 0))
14491 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14492 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14493 + if (unlikely(err))
14497 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14498 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14499 + if (unlikely(err))
14502 + dbtop = au_dbtop(cpg.dentry);
14503 + if (dbtop <= cpg.bdst)
14504 + cpg.bsrc = cpg.bdst;
14506 + if (dbtop <= cpg.bdst /* just reopen */
14507 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14509 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14510 + if (IS_ERR(h_file))
14511 + err = PTR_ERR(h_file);
14513 + di_downgrade_lock(parent, AuLock_IR);
14514 + if (dbtop > cpg.bdst)
14515 + err = au_sio_cpup_simple(&cpg);
14517 + err = au_reopen_nondir(file);
14518 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14520 + } else { /* copyup as wh and reopen */
14522 + * since writable hfsplus branch is not supported,
14523 + * h_open_pre/post() are unnecessary.
14525 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14526 + di_downgrade_lock(parent, AuLock_IR);
14530 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14531 + goto out_dput; /* success */
14537 + di_downgrade_lock(parent, AuLock_IR);
14539 + di_read_unlock(parent, AuLock_IR);
14546 +/* ---------------------------------------------------------------------- */
14548 +int au_do_flush(struct file *file, fl_owner_t id,
14549 + int (*flush)(struct file *file, fl_owner_t id))
14552 + struct super_block *sb;
14553 + struct inode *inode;
14555 + inode = file_inode(file);
14556 + sb = inode->i_sb;
14557 + si_noflush_read_lock(sb);
14558 + fi_read_lock(file);
14559 + ii_read_lock_child(inode);
14561 + err = flush(file, id);
14562 + au_cpup_attr_timesizes(inode);
14564 + ii_read_unlock(inode);
14565 + fi_read_unlock(file);
14566 + si_read_unlock(sb);
14570 +/* ---------------------------------------------------------------------- */
14572 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14575 + struct au_pin pin;
14576 + struct au_finfo *finfo;
14577 + struct dentry *parent, *hi_wh;
14578 + struct inode *inode;
14579 + struct super_block *sb;
14580 + struct au_cp_generic cpg = {
14581 + .dentry = file->f_path.dentry,
14586 + .flags = AuCpup_DTIME
14589 + FiMustWriteLock(file);
14592 + finfo = au_fi(file);
14593 + sb = cpg.dentry->d_sb;
14594 + inode = d_inode(cpg.dentry);
14595 + cpg.bdst = au_ibtop(inode);
14596 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14599 + parent = dget_parent(cpg.dentry);
14600 + if (au_test_ro(sb, cpg.bdst, inode)) {
14601 + di_read_lock_parent(parent, !AuLock_IR);
14602 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14604 + di_read_unlock(parent, !AuLock_IR);
14605 + if (unlikely(err < 0))
14610 + di_read_lock_parent(parent, AuLock_IR);
14611 + hi_wh = au_hi_wh(inode, cpg.bdst);
14612 + if (!S_ISDIR(inode->i_mode)
14613 + && au_opt_test(au_mntflags(sb), PLINK)
14614 + && au_plink_test(inode)
14615 + && !d_unhashed(cpg.dentry)
14616 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14617 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14618 + if (unlikely(err))
14621 + /* always superio. */
14622 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14623 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14625 + err = au_sio_cpup_simple(&cpg);
14628 + } else if (hi_wh) {
14629 + /* already copied-up after unlink */
14630 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14631 + *need_reopen = 0;
14635 + di_read_unlock(parent, AuLock_IR);
14642 +static void au_do_refresh_dir(struct file *file)
14644 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14645 + struct au_hfile *p, tmp, *q;
14646 + struct au_finfo *finfo;
14647 + struct super_block *sb;
14648 + struct au_fidir *fidir;
14650 + FiMustWriteLock(file);
14652 + sb = file->f_path.dentry->d_sb;
14653 + finfo = au_fi(file);
14654 + fidir = finfo->fi_hdir;
14655 + AuDebugOn(!fidir);
14656 + p = fidir->fd_hfile + finfo->fi_btop;
14657 + brid = p->hf_br->br_id;
14658 + bbot = fidir->fd_bbot;
14659 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14663 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14664 + if (new_bindex == bindex)
14666 + if (new_bindex < 0) {
14667 + au_set_h_fptr(file, bindex, NULL);
14671 + /* swap two lower inode, and loop again */
14672 + q = fidir->fd_hfile + new_bindex;
14676 + if (tmp.hf_file) {
14682 + p = fidir->fd_hfile;
14683 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14684 + bbot = au_sbbot(sb);
14685 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14686 + finfo->fi_btop++, p++)
14687 + if (p->hf_file) {
14688 + if (file_inode(p->hf_file))
14690 + au_hfput(p, /*execed*/0);
14693 + bbot = au_br_index(sb, brid);
14694 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14695 + finfo->fi_btop++, p++)
14697 + au_hfput(p, /*execed*/0);
14698 + bbot = au_sbbot(sb);
14701 + p = fidir->fd_hfile + bbot;
14702 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14703 + fidir->fd_bbot--, p--)
14704 + if (p->hf_file) {
14705 + if (file_inode(p->hf_file))
14707 + au_hfput(p, /*execed*/0);
14709 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14713 + * after branch manipulating, refresh the file.
14715 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14717 + int err, need_reopen, nbr;
14718 + aufs_bindex_t bbot, bindex;
14719 + struct dentry *dentry;
14720 + struct super_block *sb;
14721 + struct au_finfo *finfo;
14722 + struct au_hfile *hfile;
14724 + dentry = file->f_path.dentry;
14725 + sb = dentry->d_sb;
14726 + nbr = au_sbbot(sb) + 1;
14727 + finfo = au_fi(file);
14728 + if (!finfo->fi_hdir) {
14729 + hfile = &finfo->fi_htop;
14730 + AuDebugOn(!hfile->hf_file);
14731 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14732 + AuDebugOn(bindex < 0);
14733 + if (bindex != finfo->fi_btop)
14734 + au_set_fbtop(file, bindex);
14736 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14737 + if (unlikely(err))
14739 + au_do_refresh_dir(file);
14744 + if (!au_test_mmapped(file))
14745 + err = au_file_refresh_by_inode(file, &need_reopen);
14746 + if (finfo->fi_hdir)
14747 + /* harmless if err */
14748 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14749 + if (!err && need_reopen && !d_unlinked(dentry))
14750 + err = reopen(file);
14752 + au_update_figen(file);
14753 + goto out; /* success */
14756 + /* error, close all lower files */
14757 + if (finfo->fi_hdir) {
14758 + bbot = au_fbbot_dir(file);
14759 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14760 + au_set_h_fptr(file, bindex, NULL);
14767 +/* common function to regular file and dir */
14768 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14769 + int wlock, unsigned int fi_lsc)
14772 + unsigned int sigen, figen;
14773 + aufs_bindex_t btop;
14774 + unsigned char pseudo_link;
14775 + struct dentry *dentry;
14776 + struct inode *inode;
14779 + dentry = file->f_path.dentry;
14780 + inode = d_inode(dentry);
14781 + sigen = au_sigen(dentry->d_sb);
14782 + fi_write_lock_nested(file, fi_lsc);
14783 + figen = au_figen(file);
14785 + di_write_lock_child(dentry);
14787 + di_write_lock_child2(dentry);
14788 + btop = au_dbtop(dentry);
14789 + pseudo_link = (btop != au_ibtop(inode));
14790 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14792 + di_downgrade_lock(dentry, AuLock_IR);
14793 + fi_downgrade_lock(file);
14795 + goto out; /* success */
14798 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14799 + if (au_digen_test(dentry, sigen)) {
14800 + err = au_reval_dpath(dentry, sigen);
14801 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14805 + err = refresh_file(file, reopen);
14808 + di_downgrade_lock(dentry, AuLock_IR);
14809 + fi_downgrade_lock(file);
14812 + di_write_unlock(dentry);
14813 + fi_write_unlock(file);
14820 +/* ---------------------------------------------------------------------- */
14822 +/* cf. aufs_nopage() */
14823 +/* for madvise(2) */
14824 +static int aufs_read_folio(struct file *file __maybe_unused, struct folio *folio)
14826 + folio_unlock(folio);
14830 +/* it will never be called, but necessary to support O_DIRECT */
14831 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14832 +{ BUG(); return 0; }
14834 +/* they will never be called. */
14835 +#ifdef CONFIG_AUFS_DEBUG
14836 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14837 + loff_t pos, unsigned len,
14838 + struct page **pagep, void **fsdata)
14839 +{ AuUnsupport(); return 0; }
14840 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14841 + loff_t pos, unsigned len, unsigned copied,
14842 + struct page *page, void *fsdata)
14843 +{ AuUnsupport(); return 0; }
14844 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14845 +{ AuUnsupport(); return 0; }
14847 +static bool aufs_dirty_folio(struct address_space *mapping, struct folio *folio)
14848 +{ AuUnsupport(); return true; }
14849 +static void aufs_invalidate_folio(struct folio *folio, size_t offset, size_t len)
14850 +{ AuUnsupport(); }
14851 +static bool aufs_release_folio(struct folio *folio, gfp_t gfp)
14852 +{ AuUnsupport(); return true; }
14853 +#if 0 /* called by memory compaction regardless file */
14854 +static int aufs_migrate_folio(struct address_space *mapping, struct folio *dst,
14855 + struct folio *src, enum migrate_mode mode)
14856 +{ AuUnsupport(); return 0; }
14858 +static int aufs_launder_folio(struct folio *folio)
14859 +{ AuUnsupport(); return 0; }
14860 +static bool aufs_is_partially_uptodate(struct folio *folio, size_t from,
14862 +{ AuUnsupport(); return true; }
14863 +static void aufs_is_dirty_writeback(struct folio *folio, bool *dirty,
14865 +{ AuUnsupport(); }
14866 +static int aufs_error_remove_page(struct address_space *mapping,
14867 + struct page *page)
14868 +{ AuUnsupport(); return 0; }
14869 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14871 +{ AuUnsupport(); return 0; }
14872 +static void aufs_swap_deactivate(struct file *file)
14873 +{ AuUnsupport(); }
14874 +static int aufs_swap_rw(struct kiocb *iocb, struct iov_iter *iter)
14875 +{ AuUnsupport(); return 0; }
14876 +#endif /* CONFIG_AUFS_DEBUG */
14878 +const struct address_space_operations aufs_aop = {
14879 + .read_folio = aufs_read_folio,
14880 + .direct_IO = aufs_direct_IO,
14881 +#ifdef CONFIG_AUFS_DEBUG
14882 + .writepage = aufs_writepage,
14883 + /* no writepages, because of writepage */
14884 + .dirty_folio = aufs_dirty_folio,
14885 + /* no readpages, because of readpage */
14886 + .write_begin = aufs_write_begin,
14887 + .write_end = aufs_write_end,
14888 + /* no bmap, no block device */
14889 + .invalidate_folio = aufs_invalidate_folio,
14890 + .release_folio = aufs_release_folio,
14891 + /* is fallback_migrate_page ok? */
14892 + /* .migrate_folio = aufs_migrate_folio, */
14893 + .launder_folio = aufs_launder_folio,
14894 + .is_partially_uptodate = aufs_is_partially_uptodate,
14895 + .is_dirty_writeback = aufs_is_dirty_writeback,
14896 + .error_remove_page = aufs_error_remove_page,
14897 + .swap_activate = aufs_swap_activate,
14898 + .swap_deactivate = aufs_swap_deactivate,
14899 + .swap_rw = aufs_swap_rw
14900 +#endif /* CONFIG_AUFS_DEBUG */
14902 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14903 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14904 +++ linux/fs/aufs/file.h 2022-11-05 23:02:18.965889284 +0100
14906 +/* SPDX-License-Identifier: GPL-2.0 */
14908 + * Copyright (C) 2005-2022 Junjiro R. Okajima
14910 + * This program is free software; you can redistribute it and/or modify
14911 + * it under the terms of the GNU General Public License as published by
14912 + * the Free Software Foundation; either version 2 of the License, or
14913 + * (at your option) any later version.
14915 + * This program is distributed in the hope that it will be useful,
14916 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14917 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14918 + * GNU General Public License for more details.
14920 + * You should have received a copy of the GNU General Public License
14921 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14925 + * file operations
14928 +#ifndef __AUFS_FILE_H__
14929 +#define __AUFS_FILE_H__
14933 +#include <linux/file.h>
14934 +#include <linux/fs.h>
14935 +#include <linux/mm_types.h>
14936 +#include <linux/poll.h>
14937 +#include "rwsem.h"
14941 + struct file *hf_file;
14942 + struct au_branch *hf_br;
14947 + aufs_bindex_t fd_bbot;
14948 + aufs_bindex_t fd_nent;
14949 + struct au_vdir *fd_vdir_cache;
14950 + struct au_hfile fd_hfile[];
14953 +static inline int au_fidir_sz(int nent)
14955 + AuDebugOn(nent < 0);
14956 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
14960 + atomic_t fi_generation;
14962 + struct au_rwsem fi_rwsem;
14963 + aufs_bindex_t fi_btop;
14965 + /* do not union them */
14966 + struct { /* for non-dir */
14967 + struct au_hfile fi_htop;
14968 + atomic_t fi_mmapped;
14970 + struct au_fidir *fi_hdir; /* for dir only */
14972 + struct hlist_bl_node fi_hlist;
14973 + struct file *fi_file; /* very ugly */
14974 + struct rcu_head rcu;
14975 +} ____cacheline_aligned_in_smp;
14977 +/* ---------------------------------------------------------------------- */
14980 +extern const struct address_space_operations aufs_aop;
14981 +unsigned int au_file_roflags(unsigned int flags);
14982 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14983 + struct file *file, int force_wr);
14984 +struct au_do_open_args {
14986 + int (*open)(struct file *file, int flags,
14987 + struct file *h_file);
14988 + struct au_fidir *fidir;
14989 + struct file *h_file;
14991 +int au_do_open(struct file *file, struct au_do_open_args *args);
14992 +int au_reopen_nondir(struct file *file);
14994 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
14995 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14996 + int wlock, unsigned int fi_lsc);
14997 +int au_do_flush(struct file *file, fl_owner_t id,
14998 + int (*flush)(struct file *file, fl_owner_t id));
15001 +#ifdef CONFIG_AUFS_POLL
15002 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15005 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15007 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15009 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15010 + struct file *h_file);
15012 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15013 + aufs_bindex_t bindex, int force_wr)
15014 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15015 + struct file *h_file);
15019 +extern const struct file_operations aufs_file_fop;
15020 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15021 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15022 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15025 +void au_hfput(struct au_hfile *hf, int execed);
15026 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15027 + struct file *h_file);
15029 +void au_update_figen(struct file *file);
15030 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15031 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15033 +void au_fi_init_once(void *_fi);
15034 +void au_finfo_fin(struct file *file);
15035 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15038 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15039 +#ifdef CONFIG_COMPAT
15040 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15041 + unsigned long arg);
15042 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15043 + unsigned long arg);
15046 +/* ---------------------------------------------------------------------- */
15048 +static inline struct au_finfo *au_fi(struct file *file)
15050 + return file->private_data;
15053 +/* ---------------------------------------------------------------------- */
15055 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15056 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15057 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15058 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15060 +#define fi_read_trylock_nested(f) \
15061 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15062 +#define fi_write_trylock_nested(f) \
15063 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15066 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15067 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15068 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15070 +/* lock subclass for finfo */
15076 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15078 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15081 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15083 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15087 + * fi_read_lock_1, fi_write_lock_1,
15088 + * fi_read_lock_2, fi_write_lock_2
15090 +#define AuReadLockFunc(name) \
15091 +static inline void fi_read_lock_##name(struct file *f) \
15092 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15094 +#define AuWriteLockFunc(name) \
15095 +static inline void fi_write_lock_##name(struct file *f) \
15096 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15098 +#define AuRWLockFuncs(name) \
15099 + AuReadLockFunc(name) \
15100 + AuWriteLockFunc(name)
15105 +#undef AuReadLockFunc
15106 +#undef AuWriteLockFunc
15107 +#undef AuRWLockFuncs
15109 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15110 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15111 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15113 +/* ---------------------------------------------------------------------- */
15115 +/* todo: hard/soft set? */
15116 +static inline aufs_bindex_t au_fbtop(struct file *file)
15118 + FiMustAnyLock(file);
15119 + return au_fi(file)->fi_btop;
15122 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15124 + FiMustAnyLock(file);
15125 + AuDebugOn(!au_fi(file)->fi_hdir);
15126 + return au_fi(file)->fi_hdir->fd_bbot;
15129 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15131 + FiMustAnyLock(file);
15132 + AuDebugOn(!au_fi(file)->fi_hdir);
15133 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15136 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15138 + FiMustWriteLock(file);
15139 + au_fi(file)->fi_btop = bindex;
15142 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15144 + FiMustWriteLock(file);
15145 + AuDebugOn(!au_fi(file)->fi_hdir);
15146 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15149 +static inline void au_set_fvdir_cache(struct file *file,
15150 + struct au_vdir *vdir_cache)
15152 + FiMustWriteLock(file);
15153 + AuDebugOn(!au_fi(file)->fi_hdir);
15154 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15157 +static inline struct file *au_hf_top(struct file *file)
15159 + FiMustAnyLock(file);
15160 + AuDebugOn(au_fi(file)->fi_hdir);
15161 + return au_fi(file)->fi_htop.hf_file;
15164 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15166 + FiMustAnyLock(file);
15167 + AuDebugOn(!au_fi(file)->fi_hdir);
15168 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15171 +/* todo: memory barrier? */
15172 +static inline unsigned int au_figen(struct file *f)
15174 + return atomic_read(&au_fi(f)->fi_generation);
15177 +static inline void au_set_mmapped(struct file *f)
15179 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15181 + pr_warn("fi_mmapped wrapped around\n");
15182 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15186 +static inline void au_unset_mmapped(struct file *f)
15188 + atomic_dec(&au_fi(f)->fi_mmapped);
15191 +static inline int au_test_mmapped(struct file *f)
15193 + return atomic_read(&au_fi(f)->fi_mmapped);
15196 +/* customize vma->vm_file */
15198 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15199 + struct file *file)
15203 + f = vma->vm_file;
15205 + vma->vm_file = file;
15210 +#define AuDbgVmRegion(file, vma) do {} while (0)
15212 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15213 + struct file *file)
15215 + au_do_vm_file_reset(vma, file);
15218 +#define AuDbgVmRegion(file, vma) \
15219 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15221 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15222 + struct file *file)
15226 + au_do_vm_file_reset(vma, file);
15227 + f = vma->vm_region->vm_file;
15229 + vma->vm_region->vm_file = file;
15232 +#endif /* CONFIG_MMU */
15234 +/* handle vma->vm_prfile */
15235 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15236 + struct file *file)
15239 + vma->vm_prfile = file;
15240 +#ifndef CONFIG_MMU
15242 + vma->vm_region->vm_prfile = file;
15246 +#endif /* __KERNEL__ */
15247 +#endif /* __AUFS_FILE_H__ */
15248 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15249 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15250 +++ linux/fs/aufs/finfo.c 2022-11-05 23:02:18.965889284 +0100
15252 +// SPDX-License-Identifier: GPL-2.0
15254 + * Copyright (C) 2005-2022 Junjiro R. Okajima
15256 + * This program is free software; you can redistribute it and/or modify
15257 + * it under the terms of the GNU General Public License as published by
15258 + * the Free Software Foundation; either version 2 of the License, or
15259 + * (at your option) any later version.
15261 + * This program is distributed in the hope that it will be useful,
15262 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15263 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15264 + * GNU General Public License for more details.
15266 + * You should have received a copy of the GNU General Public License
15267 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15271 + * file private data
15276 +void au_hfput(struct au_hfile *hf, int execed)
15279 + allow_write_access(hf->hf_file);
15280 + fput(hf->hf_file);
15281 + hf->hf_file = NULL;
15282 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15283 + hf->hf_br = NULL;
15286 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15288 + struct au_finfo *finfo = au_fi(file);
15289 + struct au_hfile *hf;
15290 + struct au_fidir *fidir;
15292 + fidir = finfo->fi_hdir;
15294 + AuDebugOn(finfo->fi_btop != bindex);
15295 + hf = &finfo->fi_htop;
15297 + hf = fidir->fd_hfile + bindex;
15299 + if (hf && hf->hf_file)
15300 + au_hfput(hf, vfsub_file_execed(file));
15302 + FiMustWriteLock(file);
15303 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15304 + hf->hf_file = val;
15305 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15309 +void au_update_figen(struct file *file)
15311 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15312 + /* smp_mb(); */ /* atomic_set */
15315 +/* ---------------------------------------------------------------------- */
15317 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15319 + struct au_fidir *fidir;
15322 + nbr = au_sbbot(sb) + 1;
15324 + nbr = 2; /* initial allocate for 2 branches */
15325 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15327 + fidir->fd_bbot = -1;
15328 + fidir->fd_nent = nbr;
15334 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15337 + struct au_fidir *fidir, *p;
15339 + AuRwMustWriteLock(&finfo->fi_rwsem);
15340 + fidir = finfo->fi_hdir;
15341 + AuDebugOn(!fidir);
15344 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15345 + GFP_NOFS, may_shrink);
15347 + p->fd_nent = nbr;
15348 + finfo->fi_hdir = p;
15355 +/* ---------------------------------------------------------------------- */
15357 +void au_finfo_fin(struct file *file)
15359 + struct au_finfo *finfo;
15361 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15363 + finfo = au_fi(file);
15364 + AuDebugOn(finfo->fi_hdir);
15365 + AuRwDestroy(&finfo->fi_rwsem);
15366 + au_cache_free_finfo(finfo);
15369 +void au_fi_init_once(void *_finfo)
15371 + struct au_finfo *finfo = _finfo;
15373 + au_rw_init(&finfo->fi_rwsem);
15376 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15379 + struct au_finfo *finfo;
15380 + struct dentry *dentry;
15383 + dentry = file->f_path.dentry;
15384 + finfo = au_cache_alloc_finfo();
15385 + if (unlikely(!finfo))
15389 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15390 + au_rw_write_lock(&finfo->fi_rwsem);
15391 + finfo->fi_btop = -1;
15392 + finfo->fi_hdir = fidir;
15393 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15394 + /* smp_mb(); */ /* atomic_set */
15396 + file->private_data = finfo;
15401 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15402 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15403 +++ linux/fs/aufs/f_op.c 2022-11-05 23:02:18.962555950 +0100
15405 +// SPDX-License-Identifier: GPL-2.0
15407 + * Copyright (C) 2005-2022 Junjiro R. Okajima
15409 + * This program is free software; you can redistribute it and/or modify
15410 + * it under the terms of the GNU General Public License as published by
15411 + * the Free Software Foundation; either version 2 of the License, or
15412 + * (at your option) any later version.
15414 + * This program is distributed in the hope that it will be useful,
15415 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15416 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15417 + * GNU General Public License for more details.
15419 + * You should have received a copy of the GNU General Public License
15420 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15424 + * file and vm operations
15427 +#include <linux/aio.h>
15428 +#include <linux/fs_stack.h>
15429 +#include <linux/mman.h>
15430 +#include <linux/security.h>
15433 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15436 + aufs_bindex_t bindex;
15437 + struct dentry *dentry, *h_dentry;
15438 + struct au_finfo *finfo;
15439 + struct inode *h_inode;
15441 + FiMustWriteLock(file);
15444 + dentry = file->f_path.dentry;
15445 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15446 + finfo = au_fi(file);
15447 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15448 + atomic_set(&finfo->fi_mmapped, 0);
15449 + bindex = au_dbtop(dentry);
15451 + h_dentry = au_h_dptr(dentry, bindex);
15452 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15453 + if (unlikely(err))
15455 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15456 + if (IS_ERR(h_file)) {
15457 + err = PTR_ERR(h_file);
15461 + h_dentry = h_file->f_path.dentry;
15462 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15463 + if (unlikely(err))
15465 + /* br ref is already inc-ed */
15468 + if ((flags & __O_TMPFILE)
15469 + && !(flags & O_EXCL)) {
15470 + h_inode = file_inode(h_file);
15471 + spin_lock(&h_inode->i_lock);
15472 + h_inode->i_state |= I_LINKABLE;
15473 + spin_unlock(&h_inode->i_lock);
15475 + au_set_fbtop(file, bindex);
15476 + au_set_h_fptr(file, bindex, h_file);
15477 + au_update_figen(file);
15478 + /* todo: necessary? */
15479 + /* file->f_ra = h_file->f_ra; */
15485 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15486 + struct file *file)
15489 + struct super_block *sb;
15490 + struct au_do_open_args args = {
15491 + .open = au_do_open_nondir
15494 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15495 + file, vfsub_file_flags(file), file->f_mode);
15497 + sb = file->f_path.dentry->d_sb;
15498 + si_read_lock(sb, AuLock_FLUSH);
15499 + err = au_do_open(file, &args);
15500 + si_read_unlock(sb);
15504 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15506 + struct au_finfo *finfo;
15507 + aufs_bindex_t bindex;
15509 + finfo = au_fi(file);
15510 + au_hbl_del(&finfo->fi_hlist,
15511 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15512 + bindex = finfo->fi_btop;
15514 + au_set_h_fptr(file, bindex, NULL);
15516 + au_finfo_fin(file);
15520 +/* ---------------------------------------------------------------------- */
15522 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15525 + struct file *h_file;
15528 + h_file = au_hf_top(file);
15530 + err = vfsub_flush(h_file, id);
15534 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15536 + return au_do_flush(file, id, au_do_flush_nondir);
15539 +/* ---------------------------------------------------------------------- */
15541 + * read and write functions acquire [fdi]_rwsem once, but release before
15542 + * mmap_sem. This is because to stop a race condition between mmap(2).
15543 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15544 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15545 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15548 +/* Callers should call au_read_post() or fput() in the end */
15549 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15551 + struct file *h_file;
15554 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15556 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15557 + h_file = au_hf_top(file);
15558 + get_file(h_file);
15560 + fi_read_unlock(file);
15562 + h_file = ERR_PTR(err);
15567 +static void au_read_post(struct inode *inode, struct file *h_file)
15569 + /* update without lock, I don't think it a problem */
15570 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15574 +struct au_write_pre {
15576 + unsigned int lsc;
15580 + aufs_bindex_t btop;
15584 + * return with iinfo is write-locked
15585 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15588 +static struct file *au_write_pre(struct file *file, int do_ready,
15589 + struct au_write_pre *wpre)
15591 + struct file *h_file;
15592 + struct dentry *dentry;
15594 + unsigned int lsc;
15595 + struct au_pin pin;
15600 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15601 + h_file = ERR_PTR(err);
15602 + if (unlikely(err))
15605 + dentry = file->f_path.dentry;
15607 + err = au_ready_to_write(file, -1, &pin);
15608 + if (unlikely(err)) {
15609 + h_file = ERR_PTR(err);
15610 + di_write_unlock(dentry);
15615 + di_downgrade_lock(dentry, /*flags*/0);
15617 + wpre->btop = au_fbtop(file);
15618 + h_file = au_hf_top(file);
15619 + get_file(h_file);
15621 + wpre->blks = file_inode(h_file)->i_blocks;
15624 + di_read_unlock(dentry, /*flags*/0);
15627 + fi_write_unlock(file);
15632 +static void au_write_post(struct inode *inode, struct file *h_file,
15633 + struct au_write_pre *wpre, ssize_t written)
15635 + struct inode *h_inode;
15637 + au_cpup_attr_timesizes(inode);
15638 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15639 + h_inode = file_inode(h_file);
15640 + inode->i_mode = h_inode->i_mode;
15641 + ii_write_unlock(inode);
15642 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15644 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15645 + /*force*/h_inode->i_blocks > wpre->blks);
15650 + * todo: very ugly
15651 + * it locks both of i_mutex and si_rwsem for read in safe.
15652 + * if the plink maintenance mode continues forever (that is the problem),
15653 + * may loop forever.
15655 +static void au_mtx_and_read_lock(struct inode *inode)
15658 + struct super_block *sb = inode->i_sb;
15661 + inode_lock(inode);
15662 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15665 + inode_unlock(inode);
15666 + si_read_lock(sb, AuLock_NOPLMW);
15667 + si_read_unlock(sb);
15671 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15672 + struct iov_iter *iov_iter)
15675 + struct file *file;
15676 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15678 + err = security_file_permission(h_file, rw);
15679 + if (unlikely(err))
15682 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15684 + if (rw == MAY_READ)
15685 + iter = h_file->f_op->read_iter;
15686 + else if (rw == MAY_WRITE)
15687 + iter = h_file->f_op->write_iter;
15689 + file = kio->ki_filp;
15690 + kio->ki_filp = h_file;
15693 + err = iter(kio, iov_iter);
15696 + /* currently there is no such fs */
15698 + kio->ki_filp = file;
15704 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15707 + struct file *file, *h_file;
15708 + struct inode *inode;
15709 + struct super_block *sb;
15711 + file = kio->ki_filp;
15712 + inode = file_inode(file);
15713 + sb = inode->i_sb;
15714 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15716 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15717 + err = PTR_ERR(h_file);
15718 + if (IS_ERR(h_file))
15721 + if (au_test_loopback_kthread()) {
15722 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15723 + if (file->f_mapping != h_file->f_mapping) {
15724 + file->f_mapping = h_file->f_mapping;
15725 + smp_mb(); /* unnecessary? */
15728 + fi_read_unlock(file);
15730 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15731 + /* todo: necessary? */
15732 + /* file->f_ra = h_file->f_ra; */
15733 + au_read_post(inode, h_file);
15736 + si_read_unlock(sb);
15740 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15743 + struct au_write_pre wpre;
15744 + struct inode *inode;
15745 + struct file *file, *h_file;
15747 + file = kio->ki_filp;
15748 + inode = file_inode(file);
15749 + au_mtx_and_read_lock(inode);
15752 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15753 + err = PTR_ERR(h_file);
15754 + if (IS_ERR(h_file))
15757 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15758 + au_write_post(inode, h_file, &wpre, err);
15761 + si_read_unlock(inode->i_sb);
15762 + inode_unlock(inode);
15767 + * We may be able to remove aufs_splice_{read,write}() since almost all FSes
15768 + * don't have their own .splice_{read,write} implimentations, and they use
15769 + * generic_file_splice_read() and iter_file_splice_write() who can act like the
15770 + * simple converters to f_op->iter_read() and ->iter_write().
15771 + * But we keep our own implementations because some non-mainlined FSes may have
15772 + * their own .splice_{read,write} implimentations and aufs doesn't want to take
15773 + * away an opportunity to co-work with aufs from them.
15775 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15776 + struct pipe_inode_info *pipe, size_t len,
15777 + unsigned int flags)
15780 + struct file *h_file;
15781 + struct inode *inode;
15782 + struct super_block *sb;
15784 + inode = file_inode(file);
15785 + sb = inode->i_sb;
15786 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15788 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15789 + err = PTR_ERR(h_file);
15790 + if (IS_ERR(h_file))
15793 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15794 + /* todo: necessary? */
15795 + /* file->f_ra = h_file->f_ra; */
15796 + au_read_post(inode, h_file);
15799 + si_read_unlock(sb);
15804 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15805 + size_t len, unsigned int flags)
15808 + struct au_write_pre wpre;
15809 + struct inode *inode;
15810 + struct file *h_file;
15812 + inode = file_inode(file);
15813 + au_mtx_and_read_lock(inode);
15816 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15817 + err = PTR_ERR(h_file);
15818 + if (IS_ERR(h_file))
15821 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15822 + au_write_post(inode, h_file, &wpre, err);
15825 + si_read_unlock(inode->i_sb);
15826 + inode_unlock(inode);
15830 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15834 + struct au_write_pre wpre;
15835 + struct inode *inode;
15836 + struct file *h_file;
15838 + inode = file_inode(file);
15839 + au_mtx_and_read_lock(inode);
15842 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15843 + err = PTR_ERR(h_file);
15844 + if (IS_ERR(h_file))
15848 + err = vfs_fallocate(h_file, mode, offset, len);
15850 + au_write_post(inode, h_file, &wpre, /*written*/1);
15853 + si_read_unlock(inode->i_sb);
15854 + inode_unlock(inode);
15858 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15859 + struct file *dst, loff_t dst_pos,
15860 + size_t len, unsigned int flags)
15863 + struct au_write_pre wpre;
15864 + enum { SRC, DST };
15866 + struct inode *inode;
15867 + struct file *h_file;
15868 + struct super_block *h_sb;
15870 +#define a_src a[SRC]
15871 +#define a_dst a[DST]
15874 + a_src.inode = file_inode(src);
15875 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15877 + a_dst.inode = file_inode(dst);
15878 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15881 + au_mtx_and_read_lock(a_dst.inode);
15883 + * in order to match the order in di_write_lock2_{child,parent}(),
15884 + * use f_path.dentry for this comparison.
15886 + if (src->f_path.dentry < dst->f_path.dentry) {
15887 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15888 + err = PTR_ERR(a_src.h_file);
15889 + if (IS_ERR(a_src.h_file))
15892 + wpre.lsc = AuLsc_FI_2;
15893 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15894 + err = PTR_ERR(a_dst.h_file);
15895 + if (IS_ERR(a_dst.h_file)) {
15896 + au_read_post(a_src.inode, a_src.h_file);
15900 + wpre.lsc = AuLsc_FI_1;
15901 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15902 + err = PTR_ERR(a_dst.h_file);
15903 + if (IS_ERR(a_dst.h_file))
15906 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15907 + err = PTR_ERR(a_src.h_file);
15908 + if (IS_ERR(a_src.h_file)) {
15909 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15916 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15917 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15918 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15924 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15925 + dst_pos, len, flags);
15928 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15929 + fi_read_unlock(src);
15930 + au_read_post(a_src.inode, a_src.h_file);
15932 + si_read_unlock(a_dst.inode->i_sb);
15933 + inode_unlock(a_dst.inode);
15940 +/* ---------------------------------------------------------------------- */
15943 + * The locking order around current->mmap_sem.
15944 + * - in most and regular cases
15945 + * file I/O syscall -- aufs_read() or something
15946 + * -- si_rwsem for read -- mmap_sem
15947 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15949 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15950 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
15951 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
15952 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
15953 + * It means that when aufs acquires si_rwsem for write, the process should never
15954 + * acquire mmap_sem.
15956 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
15957 + * problem either since any directory is not able to be mmap-ed.
15958 + * The similar scenario is applied to aufs_readlink() too.
15961 +#if 0 /* stop calling security_file_mmap() */
15962 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
15963 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
15965 +static unsigned long au_arch_prot_conv(unsigned long flags)
15967 + /* currently ppc64 only */
15968 +#ifdef CONFIG_PPC64
15969 + /* cf. linux/arch/powerpc/include/asm/mman.h */
15970 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
15971 + return AuConv_VM_PROT(flags, SAO);
15973 + AuDebugOn(arch_calc_vm_prot_bits(-1));
15978 +static unsigned long au_prot_conv(unsigned long flags)
15980 + return AuConv_VM_PROT(flags, READ)
15981 + | AuConv_VM_PROT(flags, WRITE)
15982 + | AuConv_VM_PROT(flags, EXEC)
15983 + | au_arch_prot_conv(flags);
15986 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
15987 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
15989 +static unsigned long au_flag_conv(unsigned long flags)
15991 + return AuConv_VM_MAP(flags, GROWSDOWN)
15992 + | AuConv_VM_MAP(flags, DENYWRITE)
15993 + | AuConv_VM_MAP(flags, LOCKED);
15997 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16000 + const unsigned char wlock
16001 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16002 + struct super_block *sb;
16003 + struct file *h_file;
16004 + struct inode *inode;
16006 + AuDbgVmRegion(file, vma);
16008 + inode = file_inode(file);
16009 + sb = inode->i_sb;
16011 + si_read_lock(sb, AuLock_NOPLMW);
16013 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16015 + err = PTR_ERR(h_file);
16016 + if (IS_ERR(h_file))
16020 + au_set_mmapped(file);
16021 + au_vm_file_reset(vma, h_file);
16023 + * we cannot call security_mmap_file() here since it may acquire
16024 + * mmap_sem or i_mutex.
16026 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16027 + * au_flag_conv(vma->vm_flags));
16030 + err = call_mmap(h_file, vma);
16032 + au_vm_prfile_set(vma, file);
16033 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16034 + goto out_fput; /* success */
16036 + au_unset_mmapped(file);
16037 + au_vm_file_reset(vma, file);
16041 + ii_write_unlock(inode);
16046 + si_read_unlock(sb);
16052 +/* ---------------------------------------------------------------------- */
16054 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16058 + struct au_write_pre wpre;
16059 + struct inode *inode;
16060 + struct file *h_file;
16062 + err = 0; /* -EBADF; */ /* posix? */
16063 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16066 + inode = file_inode(file);
16067 + au_mtx_and_read_lock(inode);
16070 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16071 + err = PTR_ERR(h_file);
16072 + if (IS_ERR(h_file))
16075 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16076 + au_write_post(inode, h_file, &wpre, /*written*/0);
16079 + si_read_unlock(inode->i_sb);
16080 + inode_unlock(inode);
16085 +static int aufs_fasync(int fd, struct file *file, int flag)
16088 + struct file *h_file;
16089 + struct super_block *sb;
16091 + sb = file->f_path.dentry->d_sb;
16092 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16094 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16095 + err = PTR_ERR(h_file);
16096 + if (IS_ERR(h_file))
16099 + if (h_file->f_op->fasync)
16100 + err = h_file->f_op->fasync(fd, h_file, flag);
16101 + fput(h_file); /* instead of au_read_post() */
16104 + si_read_unlock(sb);
16108 +static int aufs_setfl(struct file *file, unsigned long arg)
16111 + struct file *h_file;
16112 + struct super_block *sb;
16114 + sb = file->f_path.dentry->d_sb;
16115 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16117 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16118 + err = PTR_ERR(h_file);
16119 + if (IS_ERR(h_file))
16122 + /* stop calling h_file->fasync */
16123 + arg |= vfsub_file_flags(file) & FASYNC;
16124 + err = setfl(/*unused fd*/-1, h_file, arg);
16125 + fput(h_file); /* instead of au_read_post() */
16128 + si_read_unlock(sb);
16132 +/* ---------------------------------------------------------------------- */
16134 +/* no one supports this operation, currently */
16135 +#if 0 /* reserved for future use */
16136 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16137 + size_t len, loff_t *pos, int more)
16142 +/* ---------------------------------------------------------------------- */
16144 +const struct file_operations aufs_file_fop = {
16145 + .owner = THIS_MODULE,
16147 + .llseek = default_llseek,
16149 + .read_iter = aufs_read_iter,
16150 + .write_iter = aufs_write_iter,
16152 +#ifdef CONFIG_AUFS_POLL
16153 + .poll = aufs_poll,
16155 + .unlocked_ioctl = aufs_ioctl_nondir,
16156 +#ifdef CONFIG_COMPAT
16157 + .compat_ioctl = aufs_compat_ioctl_nondir,
16159 + .mmap = aufs_mmap,
16160 + .open = aufs_open_nondir,
16161 + .flush = aufs_flush_nondir,
16162 + .release = aufs_release_nondir,
16163 + .fsync = aufs_fsync_nondir,
16164 + .fasync = aufs_fasync,
16165 + /* .sendpage = aufs_sendpage, */
16166 + .setfl = aufs_setfl,
16167 + .splice_write = aufs_splice_write,
16168 + .splice_read = aufs_splice_read,
16169 +#if 0 /* reserved for future use */
16170 + .aio_splice_write = aufs_aio_splice_write,
16171 + .aio_splice_read = aufs_aio_splice_read,
16173 + .fallocate = aufs_fallocate,
16174 + .copy_file_range = aufs_copy_file_range
16176 diff -urN /usr/share/empty/fs/aufs/fsctx.c linux/fs/aufs/fsctx.c
16177 --- /usr/share/empty/fs/aufs/fsctx.c 1970-01-01 01:00:00.000000000 +0100
16178 +++ linux/fs/aufs/fsctx.c 2022-11-05 23:02:18.965889284 +0100
16180 +// SPDX-License-Identifier: GPL-2.0
16182 + * Copyright (C) 2022 Junjiro R. Okajima
16184 + * This program is free software; you can redistribute it and/or modify
16185 + * it under the terms of the GNU General Public License as published by
16186 + * the Free Software Foundation; either version 2 of the License, or
16187 + * (at your option) any later version.
16189 + * This program is distributed in the hope that it will be useful,
16190 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16191 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16192 + * GNU General Public License for more details.
16194 + * You should have received a copy of the GNU General Public License
16195 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16199 + * fs context, aka new mount api
16202 +#include <linux/fs_context.h>
16205 +struct au_fsctx_opts {
16206 + aufs_bindex_t bindex;
16207 + unsigned char skipped;
16208 + struct au_opt *opt, *opt_tail;
16209 + struct super_block *sb;
16210 + struct au_sbinfo *sbinfo;
16211 + struct au_opts opts;
16214 +/* stop extra interpretation of errno in mount(8), and strange error messages */
16215 +static int cvt_err(int err)
16229 +static int au_fsctx_reconfigure(struct fs_context *fc)
16232 + unsigned int mntflags;
16233 + struct dentry *root;
16234 + struct super_block *sb;
16235 + struct inode *inode;
16236 + struct au_fsctx_opts *a = fc->fs_private;
16238 + AuDbg("fc %p\n", fc);
16242 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16244 + di_write_lock_child(root);
16245 + err = au_opts_verify(sb, fc->sb_flags, /*pending*/0);
16246 + aufs_write_unlock(root);
16249 + inode = d_inode(root);
16250 + inode_lock(inode);
16251 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16252 + if (unlikely(err))
16254 + di_write_lock_child(root);
16256 + /* au_opts_remount() may return an error */
16257 + err = au_opts_remount(sb, &a->opts);
16259 + if (au_ftest_opts(a->opts.flags, REFRESH))
16260 + au_remount_refresh(sb, au_ftest_opts(a->opts.flags,
16263 + if (au_ftest_opts(a->opts.flags, REFRESH_DYAOP)) {
16264 + mntflags = au_mntflags(sb);
16265 + do_dx = !!au_opt_test(mntflags, DIO);
16266 + au_dy_arefresh(do_dx);
16269 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
16270 + aufs_write_unlock(root);
16273 + inode_unlock(inode);
16274 + err = cvt_err(err);
16280 +/* ---------------------------------------------------------------------- */
16282 +static int au_fsctx_fill_super(struct super_block *sb, struct fs_context *fc)
16285 + struct au_fsctx_opts *a = fc->fs_private;
16286 + struct au_sbinfo *sbinfo = a->sbinfo;
16287 + struct dentry *root;
16288 + struct inode *inode;
16290 + sbinfo->si_sb = sb;
16291 + sb->s_fs_info = sbinfo;
16292 + kobject_get(&sbinfo->si_kobj);
16294 + __si_write_lock(sb);
16296 + au_sbilist_add(sb);
16298 + /* all timestamps always follow the ones on the branch */
16299 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
16300 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
16301 + sb->s_op = &aufs_sop;
16302 + sb->s_d_op = &aufs_dop;
16303 + sb->s_magic = AUFS_SUPER_MAGIC;
16304 + sb->s_maxbytes = 0;
16305 + sb->s_stack_depth = 1;
16306 + au_export_init(sb);
16307 + au_xattr_init(sb);
16309 + err = au_alloc_root(sb);
16310 + if (unlikely(err)) {
16311 + si_write_unlock(sb);
16314 + root = sb->s_root;
16315 + inode = d_inode(root);
16316 + ii_write_lock_parent(inode);
16317 + aufs_write_unlock(root);
16319 + /* lock vfs_inode first, then aufs. */
16320 + inode_lock(inode);
16321 + aufs_write_lock(root);
16322 + err = au_opts_mount(sb, &a->opts);
16324 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
16325 + sb->s_d_op = &aufs_dop_noreval;
16326 + /* infofc(fc, "%ps", sb->s_d_op); */
16327 + pr_info("%ps\n", sb->s_d_op);
16328 + au_refresh_dop(root, /*force_reval*/0);
16329 + sbinfo->si_iop_array = aufs_iop_nogetattr;
16330 + au_refresh_iop(inode, /*force_getattr*/0);
16332 + aufs_write_unlock(root);
16333 + inode_unlock(inode);
16335 + goto out; /* success */
16338 + sb->s_root = NULL;
16341 + if (unlikely(err))
16342 + kobject_put(&sbinfo->si_kobj);
16344 + err = cvt_err(err);
16349 +static int au_fsctx_get_tree(struct fs_context *fc)
16353 + AuDbg("fc %p\n", fc);
16354 + err = get_tree_nodev(fc, au_fsctx_fill_super);
16360 +/* ---------------------------------------------------------------------- */
16362 +static void au_fsctx_dump(struct au_opts *opts)
16364 +#ifdef CONFIG_AUFS_DEBUG
16365 + /* reduce stack space */
16367 + struct au_opt_add *add;
16368 + struct au_opt_del *del;
16369 + struct au_opt_mod *mod;
16370 + struct au_opt_xino *xino;
16371 + struct au_opt_xino_itrunc *xino_itrunc;
16372 + struct au_opt_wbr_create *create;
16374 + struct au_opt *opt;
16377 + while (opt->type != Opt_tail) {
16378 + switch (opt->type) {
16380 + u.add = &opt->add;
16381 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
16382 + u.add->bindex, u.add->pathname, u.add->perm,
16383 + u.add->path.dentry);
16388 + u.del = &opt->del;
16389 + AuDbg("del {%s, %p}\n",
16390 + u.del->pathname, u.del->h_path.dentry);
16395 + u.mod = &opt->mod;
16396 + AuDbg("mod {%s, 0x%x, %p}\n",
16397 + u.mod->path, u.mod->perm, u.mod->h_root);
16400 + u.add = &opt->add;
16401 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
16402 + u.add->bindex, u.add->pathname, u.add->perm,
16403 + u.add->path.dentry);
16405 + case Opt_prepend:
16406 + u.add = &opt->add;
16407 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
16408 + u.add->bindex, u.add->pathname, u.add->perm,
16409 + u.add->path.dentry);
16413 + AuDbg("dirwh %d\n", opt->dirwh);
16415 + case Opt_rdcache:
16416 + AuDbg("rdcache %d\n", opt->rdcache);
16419 + AuDbg("rdblk %d\n", opt->rdblk);
16422 + AuDbg("rdhash %u\n", opt->rdhash);
16426 + u.xino = &opt->xino;
16427 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
16430 +#define au_fsctx_TF(name) \
16431 + case Opt_##name: \
16435 + AuLabel(no##name); \
16438 + /* simple true/false flag */
16439 + au_fsctx_TF(trunc_xino);
16440 + au_fsctx_TF(trunc_xib);
16441 + au_fsctx_TF(dirperm1);
16442 + au_fsctx_TF(plink);
16443 + au_fsctx_TF(shwh);
16444 + au_fsctx_TF(dio);
16445 + au_fsctx_TF(warn_perm);
16446 + au_fsctx_TF(verbose);
16447 + au_fsctx_TF(sum);
16448 + au_fsctx_TF(dirren);
16449 + au_fsctx_TF(acl);
16450 +#undef au_fsctx_TF
16452 + case Opt_trunc_xino_path:
16454 + case Opt_itrunc_xino:
16455 + u.xino_itrunc = &opt->xino_itrunc;
16456 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
16462 + case Opt_list_plink:
16463 + AuLabel(list_plink);
16466 + AuDbg("udba %d, %s\n",
16467 + opt->udba, au_optstr_udba(opt->udba));
16469 + case Opt_diropq_a:
16470 + AuLabel(diropq_a);
16472 + case Opt_diropq_w:
16473 + AuLabel(diropq_w);
16478 + case Opt_wbr_create:
16479 + u.create = &opt->wbr_create;
16480 + AuDbg("create %d, %s\n", u.create->wbr_create,
16481 + au_optstr_wbr_create(u.create->wbr_create));
16482 + switch (u.create->wbr_create) {
16483 + case AuWbrCreate_MFSV:
16485 + case AuWbrCreate_PMFSV:
16486 + AuDbg("%d sec\n", u.create->mfs_second);
16488 + case AuWbrCreate_MFSRR:
16490 + case AuWbrCreate_TDMFS:
16491 + AuDbg("%llu watermark\n",
16492 + u.create->mfsrr_watermark);
16494 + case AuWbrCreate_MFSRRV:
16496 + case AuWbrCreate_TDMFSV:
16498 + case AuWbrCreate_PMFSRRV:
16499 + AuDbg("%llu watermark, %d sec\n",
16500 + u.create->mfsrr_watermark,
16501 + u.create->mfs_second);
16505 + case Opt_wbr_copyup:
16506 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
16507 + au_optstr_wbr_copyup(opt->wbr_copyup));
16509 + case Opt_fhsm_sec:
16510 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
16514 + AuDbg("type %d\n", opt->type);
16522 +/* ---------------------------------------------------------------------- */
16525 + * For conditionally compiled mount options.
16526 + * Instead of fsparam_flag_no(), use this macro to distinguish ignore_silent.
16528 +#define au_ignore_flag(name, action) \
16529 + fsparam_flag(name, action), \
16530 + fsparam_flag("no" name, Opt_ignore_silent)
16532 +const struct fs_parameter_spec aufs_fsctx_paramspec[] = {
16533 + fsparam_string("br", Opt_br),
16535 + /* "add=%d:%s" or "ins=%d:%s" */
16536 + fsparam_string("add", Opt_add),
16537 + fsparam_string("ins", Opt_add),
16538 + fsparam_path("append", Opt_append),
16539 + fsparam_path("prepend", Opt_prepend),
16541 + fsparam_path("del", Opt_del),
16542 + /* fsparam_s32("idel", Opt_idel), */
16543 + fsparam_path("mod", Opt_mod),
16544 + /* fsparam_string("imod", Opt_imod), */
16546 + fsparam_s32("dirwh", Opt_dirwh),
16548 + fsparam_path("xino", Opt_xino),
16549 + fsparam_flag("noxino", Opt_noxino),
16550 + fsparam_flag_no("trunc_xino", Opt_trunc_xino),
16551 + /* "trunc_xino_v=%d:%d" */
16552 + /* fsparam_string("trunc_xino_v", Opt_trunc_xino_v), */
16553 + fsparam_path("trunc_xino", Opt_trunc_xino_path),
16554 + fsparam_s32("itrunc_xino", Opt_itrunc_xino),
16555 + /* fsparam_path("zxino", Opt_zxino), */
16556 + fsparam_flag_no("trunc_xib", Opt_trunc_xib),
16558 +#ifdef CONFIG_PROC_FS
16559 + fsparam_flag_no("plink", Opt_plink),
16561 + au_ignore_flag("plink", Opt_ignore),
16564 +#ifdef CONFIG_AUFS_DEBUG
16565 + fsparam_flag("list_plink", Opt_list_plink),
16568 + fsparam_string("udba", Opt_udba),
16570 + fsparam_flag_no("dio", Opt_dio),
16572 +#ifdef CONFIG_AUFS_DIRREN
16573 + fsparam_flag_no("dirren", Opt_dirren),
16575 + au_ignore_flag("dirren", Opt_ignore),
16578 +#ifdef CONFIG_AUFS_FHSM
16579 + fsparam_s32("fhsm_sec", Opt_fhsm_sec),
16581 + fsparam_s32("fhsm_sec", Opt_ignore),
16584 + /* always | a | whiteouted | w */
16585 + fsparam_string("diropq", Opt_diropq),
16587 + fsparam_flag_no("warn_perm", Opt_warn_perm),
16589 +#ifdef CONFIG_AUFS_SHWH
16590 + fsparam_flag_no("shwh", Opt_shwh),
16592 + au_ignore_flag("shwh", Opt_err),
16595 + fsparam_flag_no("dirperm1", Opt_dirperm1),
16597 + fsparam_flag_no("verbose", Opt_verbose),
16598 + fsparam_flag("v", Opt_verbose),
16599 + fsparam_flag("quiet", Opt_noverbose),
16600 + fsparam_flag("q", Opt_noverbose),
16601 + /* user-space may handle this */
16602 + fsparam_flag("silent", Opt_noverbose),
16604 + fsparam_flag_no("sum", Opt_sum),
16605 + fsparam_flag("wsum", Opt_wsum),
16607 + fsparam_s32("rdcache", Opt_rdcache),
16608 + /* "def" or s32 */
16609 + fsparam_string("rdblk", Opt_rdblk),
16610 + /* "def" or s32 */
16611 + fsparam_string("rdhash", Opt_rdhash),
16613 + fsparam_string("create", Opt_wbr_create),
16614 + fsparam_string("create_policy", Opt_wbr_create),
16615 + fsparam_string("cpup", Opt_wbr_copyup),
16616 + fsparam_string("copyup", Opt_wbr_copyup),
16617 + fsparam_string("copyup_policy", Opt_wbr_copyup),
16619 + /* generic VFS flag */
16620 +#ifdef CONFIG_FS_POSIX_ACL
16621 + fsparam_flag_no("acl", Opt_acl),
16623 + au_ignore_flag("acl", Opt_ignore),
16626 + /* internal use for the scripts */
16627 + fsparam_string("si", Opt_ignore_silent),
16629 + /* obsoleted, keep them temporary */
16630 + fsparam_flag("nodlgt", Opt_ignore_silent),
16631 + fsparam_flag("clean_plink", Opt_ignore),
16632 + fsparam_string("dirs", Opt_br),
16633 + fsparam_u32("debug", Opt_ignore),
16634 + /* "whiteout" or "all" */
16635 + fsparam_string("delete", Opt_ignore),
16636 + fsparam_string("imap", Opt_ignore),
16638 + /* temporary workaround, due to old mount(8)? */
16639 + fsparam_flag("relatime", Opt_ignore_silent),
16644 +static int au_fsctx_parse_do_add(struct fs_context *fc, struct au_opt *opt,
16645 + char *brspec, size_t speclen,
16646 + aufs_bindex_t bindex)
16651 + AuDbg("brspec %s\n", brspec);
16655 + speclen = strlen(brspec);
16656 + /* will be freed by au_fsctx_free() */
16657 + p = kmemdup_nul(brspec, speclen, GFP_NOFS);
16658 + if (unlikely(!p)) {
16659 + errorfc(fc, "failed in %s", brspec);
16662 + err = au_opt_add(opt, p, fc->sb_flags, bindex);
16669 +static int au_fsctx_parse_br(struct fs_context *fc, char *brspec)
16673 + struct au_fsctx_opts *a = fc->fs_private;
16674 + struct au_opt *opt = a->opt;
16675 + aufs_bindex_t bindex = a->bindex;
16677 + AuDbg("brspec %s\n", brspec);
16680 + while ((p = strsep(&brspec, ":")) && *p) {
16681 + err = au_fsctx_parse_do_add(fc, opt, p, /*len*/0, bindex);
16683 + if (unlikely(err))
16687 + if (unlikely(opt > a->opt_tail)) {
16693 + opt->type = Opt_tail;
16696 + a->bindex = bindex;
16703 +static int au_fsctx_parse_add(struct fs_context *fc, char *addspec)
16707 + struct au_fsctx_opts *a = fc->fs_private;
16708 + struct au_opt *opt = a->opt;
16711 + p = strchr(addspec, ':');
16712 + if (unlikely(!p)) {
16713 + errorfc(fc, "bad arg in %s", addspec);
16717 + err = kstrtoint(addspec, 0, &n);
16718 + if (unlikely(err)) {
16719 + errorfc(fc, "bad integer in %s", addspec);
16722 + AuDbg("n %d\n", n);
16723 + err = au_fsctx_parse_do_add(fc, opt, p, /*len*/0, n);
16730 +static int au_fsctx_parse_del(struct fs_context *fc, struct au_opt_del *del,
16731 + struct fs_parameter *param)
16736 + /* will be freed by au_fsctx_free() */
16737 + del->pathname = kmemdup_nul(param->string, param->size, GFP_NOFS);
16738 + if (unlikely(!del->pathname))
16740 + AuDbg("del %s\n", del->pathname);
16741 + err = vfsub_kern_path(del->pathname, AuOpt_LkupDirFlags, &del->h_path);
16742 + if (unlikely(err))
16743 + errorfc(fc, "lookup failed %s (%d)", del->pathname, err);
16750 +#if 0 /* reserved for future use */
16751 +static int au_fsctx_parse_idel(struct fs_context *fc, struct au_opt_del *del,
16752 + aufs_bindex_t bindex)
16755 + struct super_block *sb;
16756 + struct dentry *root;
16757 + struct au_fsctx_opts *a = fc->fs_private;
16763 + root = sb->s_root;
16764 + aufs_read_lock(root, AuLock_FLUSH);
16765 + if (bindex < 0 || au_sbbot(sb) < bindex) {
16766 + errorfc(fc, "out of bounds, %d", bindex);
16771 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
16772 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
16775 + aufs_read_unlock(root, !AuLock_IR);
16781 +static int au_fsctx_parse_mod(struct fs_context *fc, struct au_opt_mod *mod,
16782 + struct fs_parameter *param)
16785 + struct path path;
16789 + /* will be freed by au_fsctx_free() */
16790 + mod->path = kmemdup_nul(param->string, param->size, GFP_NOFS);
16791 + if (unlikely(!mod->path))
16795 + p = strchr(mod->path, '=');
16796 + if (unlikely(!p)) {
16797 + errorfc(fc, "no permission %s", mod->path);
16802 + err = vfsub_kern_path(mod->path, AuOpt_LkupDirFlags, &path);
16803 + if (unlikely(err)) {
16804 + errorfc(fc, "lookup failed %s (%d)", mod->path, err);
16808 + mod->perm = au_br_perm_val(p);
16809 + AuDbg("mod path %s, perm 0x%x, %s", mod->path, mod->perm, p);
16810 + mod->h_root = dget(path.dentry);
16818 +#if 0 /* reserved for future use */
16819 +static int au_fsctx_parse_imod(struct fs_context *fc, struct au_opt_mod *mod,
16824 + struct super_block *sb;
16825 + struct dentry *root;
16826 + struct au_fsctx_opts *a = fc->fs_private;
16832 + p = strchr(ibrspec, ':');
16833 + if (unlikely(!p)) {
16834 + errorfc(fc, "no index, %s", ibrspec);
16838 + err = kstrtoint(ibrspec, 0, &n);
16839 + if (unlikely(err)) {
16840 + errorfc(fc, "bad integer in %s", ibrspec);
16843 + AuDbg("n %d\n", n);
16845 + root = sb->s_root;
16846 + aufs_read_lock(root, AuLock_FLUSH);
16847 + if (n < 0 || au_sbbot(sb) < n) {
16848 + errorfc(fc, "out of bounds, %d", bindex);
16853 + mod->perm = au_br_perm_val(p);
16854 + AuDbg("mod path %s, perm 0x%x, %s\n",
16855 + mod->path, mod->perm, p);
16856 + mod->h_root = dget(au_h_dptr(root, bindex));
16859 + aufs_read_unlock(root, !AuLock_IR);
16866 +static int au_fsctx_parse_xino(struct fs_context *fc,
16867 + struct au_opt_xino *xino,
16868 + struct fs_parameter *param)
16871 + struct au_fsctx_opts *a = fc->fs_private;
16874 + /* will be freed by au_opts_free() */
16875 + xino->path = kmemdup_nul(param->string, param->size, GFP_NOFS);
16876 + if (unlikely(!xino->path))
16878 + AuDbg("path %s\n", xino->path);
16880 + xino->file = au_xino_create(a->sb, xino->path, /*silent*/0,
16882 + err = PTR_ERR(xino->file);
16883 + if (IS_ERR(xino->file)) {
16884 + xino->file = NULL;
16889 + if (unlikely(a->sb && xino->file->f_path.dentry->d_sb == a->sb)) {
16891 + errorfc(fc, "%s must be outside", xino->path);
16900 +int au_fsctx_parse_xino_itrunc_path(struct fs_context *fc,
16901 + struct au_opt_xino_itrunc *xino_itrunc,
16905 + aufs_bindex_t bbot, bindex;
16906 + struct path path;
16907 + struct dentry *root;
16908 + struct au_fsctx_opts *a = fc->fs_private;
16910 + AuDebugOn(!a->sb);
16912 + err = vfsub_kern_path(pathname, AuOpt_LkupDirFlags, &path);
16913 + if (unlikely(err)) {
16914 + errorfc(fc, "lookup failed %s (%d)", pathname, err);
16918 + xino_itrunc->bindex = -1;
16919 + root = a->sb->s_root;
16920 + aufs_read_lock(root, AuLock_FLUSH);
16921 + bbot = au_sbbot(a->sb);
16922 + for (bindex = 0; bindex <= bbot; bindex++) {
16923 + if (au_h_dptr(root, bindex) == path.dentry) {
16924 + xino_itrunc->bindex = bindex;
16928 + aufs_read_unlock(root, !AuLock_IR);
16931 + if (unlikely(xino_itrunc->bindex < 0)) {
16933 + errorfc(fc, "no such branch %s", pathname);
16941 +static int au_fsctx_parse_xino_itrunc(struct fs_context *fc,
16942 + struct au_opt_xino_itrunc *xino_itrunc,
16943 + unsigned int bindex)
16946 + aufs_bindex_t bbot;
16947 + struct super_block *sb;
16948 + struct au_fsctx_opts *a = fc->fs_private;
16954 + si_noflush_read_lock(sb);
16955 + bbot = au_sbbot(sb);
16956 + si_read_unlock(sb);
16957 + if (bindex <= bbot)
16958 + xino_itrunc->bindex = bindex;
16961 + errorfc(fc, "out of bounds, %u", bindex);
16968 +static int au_fsctx_parse_param(struct fs_context *fc, struct fs_parameter *param)
16971 + struct fs_parse_result result;
16972 + struct au_fsctx_opts *a = fc->fs_private;
16973 + struct au_opt *opt = a->opt;
16975 + AuDbg("fc %p, param {key %s, string %s}\n",
16976 + fc, param->key, param->string);
16977 + err = fs_parse(fc, aufs_fsctx_paramspec, param, &result);
16978 + if (unlikely(err < 0))
16981 + AuDbg("token %d, res{negated %d, uint64 %llu}\n",
16982 + token, result.negated, result.uint_64);
16988 + err = au_fsctx_parse_br(fc, param->string);
16991 + err = au_fsctx_parse_add(fc, param->string);
16994 + err = au_fsctx_parse_do_add(fc, opt, param->string, param->size,
16995 + /*dummy bindex*/1);
16997 + case Opt_prepend:
16998 + err = au_fsctx_parse_do_add(fc, opt, param->string, param->size,
17003 + err = au_fsctx_parse_del(fc, &opt->del, param);
17005 +#if 0 /* reserved for future use */
17012 + del->pathname = "(indexed)";
17013 + err = au_opts_parse_idel(fc, &opt->del, result.uint_32);
17018 + err = au_fsctx_parse_mod(fc, &opt->mod, param);
17020 +#ifdef IMOD /* reserved for future use */
17027 + u.mod->path = "(indexed)";
17028 + err = au_opts_parse_imod(fc, &opt->mod, param->string);
17033 + err = au_fsctx_parse_xino(fc, &opt->xino, param);
17035 + case Opt_trunc_xino_path:
17037 + errorfc(fc, "no such branch %s", param->string);
17040 + err = au_fsctx_parse_xino_itrunc_path(fc, &opt->xino_itrunc,
17044 + case Opt_trunc_xino_v:
17050 + err = au_fsctx_parse_xino_itrunc_path(fc, &opt->xino_itrunc,
17054 + case Opt_itrunc_xino:
17056 + errorfc(fc, "out of bounds %s", param->string);
17059 + err = au_fsctx_parse_xino_itrunc(fc, &opt->xino_itrunc,
17065 + opt->dirwh = result.int_32;
17068 + case Opt_rdcache:
17069 + if (unlikely(result.int_32 > AUFS_RDCACHE_MAX)) {
17070 + errorfc(fc, "rdcache must be smaller than %d",
17071 + AUFS_RDCACHE_MAX);
17075 + opt->rdcache = result.int_32;
17080 + opt->rdblk = AUFS_RDBLK_DEF;
17081 + if (!strcmp(param->string, "def"))
17084 + err = kstrtoint(param->string, 0, &result.int_32);
17085 + if (unlikely(err)) {
17086 + errorfc(fc, "bad value in %s", param->key);
17090 + if (unlikely(result.int_32 < 0
17091 + || result.int_32 > KMALLOC_MAX_SIZE)) {
17092 + errorfc(fc, "bad value in %s", param->key);
17095 + if (unlikely(result.int_32 && result.int_32 < NAME_MAX)) {
17096 + errorfc(fc, "rdblk must be larger than %d", NAME_MAX);
17100 + opt->rdblk = result.int_32;
17105 + opt->rdhash = AUFS_RDHASH_DEF;
17106 + if (!strcmp(param->string, "def"))
17109 + err = kstrtoint(param->string, 0, &result.int_32);
17110 + if (unlikely(err)) {
17111 + errorfc(fc, "bad value in %s", param->key);
17114 + /* how about zero? */
17115 + if (result.int_32 < 0
17116 + || result.int_32 * sizeof(struct hlist_head)
17117 + > KMALLOC_MAX_SIZE) {
17119 + errorfc(fc, "bad integer in %s", param->key);
17122 + opt->rdhash = result.int_32;
17127 + * As other options, fs/aufs/opts.c can handle these strings by
17128 + * match_token(). But "diropq=" is deprecated now and will
17129 + * never have other value. So simple strcmp() is enough here.
17131 + if (!strcmp(param->string, "a") ||
17132 + !strcmp(param->string, "always")) {
17134 + opt->type = Opt_diropq_a;
17135 + } else if (!strcmp(param->string, "w") ||
17136 + !strcmp(param->string, "whiteouted")) {
17138 + opt->type = Opt_diropq_w;
17140 + errorfc(fc, "unknown value %s", param->string);
17144 + opt->udba = au_udba_val(param->string);
17145 + if (opt->udba >= 0)
17148 + errorf(fc, "wrong value, %s", param->string);
17151 + case Opt_wbr_create:
17152 + opt->wbr_create.wbr_create
17153 + = au_wbr_create_val(param->string, &opt->wbr_create);
17154 + if (opt->wbr_create.wbr_create >= 0)
17157 + errorf(fc, "wrong value, %s", param->key);
17160 + case Opt_wbr_copyup:
17161 + opt->wbr_copyup = au_wbr_copyup_val(param->string);
17162 + if (opt->wbr_copyup >= 0)
17165 + errorfc(fc, "wrong value, %s", param->key);
17168 + case Opt_fhsm_sec:
17169 + if (unlikely(result.int_32 < 0)) {
17170 + errorfc(fc, "bad integer in %s\n", param->key);
17175 + opt->fhsm_second = result.int_32;
17177 + warnfc(fc, "ignored %s %s", param->key, param->string);
17180 + /* simple true/false flag */
17181 +#define au_fsctx_TF(name) \
17182 + case Opt_##name: \
17184 + opt->tf = !result.negated; \
17186 + au_fsctx_TF(trunc_xino);
17187 + au_fsctx_TF(trunc_xib);
17188 + au_fsctx_TF(dirperm1);
17189 + au_fsctx_TF(plink);
17190 + au_fsctx_TF(shwh);
17191 + au_fsctx_TF(dio);
17192 + au_fsctx_TF(warn_perm);
17193 + au_fsctx_TF(verbose);
17194 + au_fsctx_TF(sum);
17195 + au_fsctx_TF(dirren);
17196 + au_fsctx_TF(acl);
17197 +#undef au_fsctx_TF
17199 + case Opt_noverbose:
17201 + opt->type = Opt_verbose;
17207 + case Opt_list_plink:
17214 + warnfc(fc, "ignored %s", param->key);
17216 + case Opt_ignore_silent:
17225 + if (unlikely(err))
17233 + case Opt_noverbose:
17238 + opt->type = token;
17242 + if (unlikely(opt > a->opt_tail)) {
17246 + opt->type = Opt_tail;
17254 + * these options accept both 'name=val' and 'name:val' form.
17255 + * some accept optional '=' in its value.
17256 + * eg. br:/br1=rw:/br2=ro and br=/br1=rw:/br2=ro
17258 +static inline unsigned int is_colonopt(char *str)
17260 +#define do_test(name) \
17261 + if (!strncmp(str, name ":", sizeof(name))) \
17262 + return sizeof(name) - 1
17266 + do_test("append");
17267 + do_test("prepend");
17269 + /* do_test("idel"); */
17271 + /* do_test("imod"); */
17277 +static int au_fsctx_parse_monolithic(struct fs_context *fc, void *data)
17282 + struct au_fsctx_opts *a = fc->fs_private;
17285 + AuDbg("str %s\n", str);
17287 + u = is_colonopt(str);
17290 + str = strchr(str, ',');
17296 + AuDbg("str %s\n", str);
17298 + err = generic_parse_monolithic(fc, str);
17300 + au_fsctx_dump(&a->opts);
17305 +/* ---------------------------------------------------------------------- */
17307 +static void au_fsctx_opts_free(struct au_opts *opts)
17309 + struct au_opt *opt;
17312 + while (opt->type != Opt_tail) {
17313 + switch (opt->type) {
17318 + case Opt_prepend:
17319 + kfree(opt->add.pathname);
17320 + path_put(&opt->add.path);
17323 + kfree(opt->del.pathname);
17326 + path_put(&opt->del.h_path);
17329 + kfree(opt->mod.path);
17332 + dput(opt->mod.h_root);
17335 + kfree(opt->xino.path);
17336 + fput(opt->xino.file);
17343 +static void au_fsctx_free(struct fs_context *fc)
17345 + struct au_fsctx_opts *a = fc->fs_private;
17347 + /* fs_type=%p, root=%pD */
17348 + AuDbg("fc %p{sb_flags 0x%x, sb_flags_mask 0x%x, purpose %u\n",
17349 + fc, fc->sb_flags, fc->sb_flags_mask, fc->purpose);
17351 + kobject_put(&a->sbinfo->si_kobj);
17352 + au_fsctx_opts_free(&a->opts);
17353 + free_page((unsigned long)a->opts.opt);
17357 +static const struct fs_context_operations au_fsctx_ops = {
17358 + .free = au_fsctx_free,
17359 + .parse_param = au_fsctx_parse_param,
17360 + .parse_monolithic = au_fsctx_parse_monolithic,
17361 + .get_tree = au_fsctx_get_tree,
17362 + .reconfigure = au_fsctx_reconfigure
17364 + * nfs4 requires ->dup()? No.
17365 + * I don't know what is this ->dup() for.
17369 +int aufs_fsctx_init(struct fs_context *fc)
17372 + struct au_fsctx_opts *a;
17374 + /* fs_type=%p, root=%pD */
17375 + AuDbg("fc %p{sb_flags 0x%x, sb_flags_mask 0x%x, purpose %u\n",
17376 + fc, fc->sb_flags, fc->sb_flags_mask, fc->purpose);
17378 + /* they will be freed by au_fsctx_free() */
17380 + a = kzalloc(sizeof(*a), GFP_NOFS);
17381 + if (unlikely(!a))
17384 + a->opts.opt = (void *)__get_free_page(GFP_NOFS);
17385 + if (unlikely(!a->opts.opt))
17387 + a->opt = a->opts.opt;
17388 + a->opt->type = Opt_tail;
17389 + a->opts.max_opt = PAGE_SIZE / sizeof(*a->opts.opt);
17390 + a->opt_tail = a->opt + a->opts.max_opt - 1;
17391 + a->opts.sb_flags = fc->sb_flags;
17395 + AuDebugOn(fc->purpose != FS_CONTEXT_FOR_RECONFIGURE);
17396 + a->opts.flags = AuOpts_REMOUNT;
17397 + a->sb = fc->root->d_sb;
17398 + a->sbinfo = au_sbi(a->sb);
17399 + kobject_get(&a->sbinfo->si_kobj);
17401 + a->sbinfo = au_si_alloc(a->sb);
17402 + AuDebugOn(!a->sbinfo);
17403 + err = PTR_ERR(a->sbinfo);
17404 + if (IS_ERR(a->sbinfo))
17406 + au_rw_write_unlock(&a->sbinfo->si_rwsem);
17410 + fc->fs_private = a;
17411 + fc->ops = &au_fsctx_ops;
17412 + goto out; /* success */
17415 + free_page((unsigned long)a->opts.opt);
17422 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
17423 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
17424 +++ linux/fs/aufs/fstype.h 2022-11-05 23:02:18.965889284 +0100
17426 +/* SPDX-License-Identifier: GPL-2.0 */
17428 + * Copyright (C) 2005-2022 Junjiro R. Okajima
17430 + * This program is free software; you can redistribute it and/or modify
17431 + * it under the terms of the GNU General Public License as published by
17432 + * the Free Software Foundation; either version 2 of the License, or
17433 + * (at your option) any later version.
17435 + * This program is distributed in the hope that it will be useful,
17436 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17437 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17438 + * GNU General Public License for more details.
17440 + * You should have received a copy of the GNU General Public License
17441 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17445 + * judging filesystem type
17448 +#ifndef __AUFS_FSTYPE_H__
17449 +#define __AUFS_FSTYPE_H__
17453 +#include <linux/fs.h>
17454 +#include <linux/magic.h>
17455 +#include <linux/nfs_fs.h>
17456 +#include <linux/romfs_fs.h>
17458 +static inline int au_test_aufs(struct super_block *sb)
17460 + return sb->s_magic == AUFS_SUPER_MAGIC;
17463 +static inline const char *au_sbtype(struct super_block *sb)
17465 + return sb->s_type->name;
17468 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
17470 +#if IS_ENABLED(CONFIG_ISO9660_FS)
17471 + return sb->s_magic == ISOFS_SUPER_MAGIC;
17477 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
17479 +#if IS_ENABLED(CONFIG_ROMFS_FS)
17480 + return sb->s_magic == ROMFS_MAGIC;
17486 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
17488 +#if IS_ENABLED(CONFIG_CRAMFS)
17489 + return sb->s_magic == CRAMFS_MAGIC;
17494 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
17496 +#if IS_ENABLED(CONFIG_NFS_FS)
17497 + return sb->s_magic == NFS_SUPER_MAGIC;
17503 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
17505 +#if IS_ENABLED(CONFIG_FUSE_FS)
17506 + return sb->s_magic == FUSE_SUPER_MAGIC;
17512 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
17514 +#if IS_ENABLED(CONFIG_XFS_FS)
17515 + return sb->s_magic == XFS_SB_MAGIC;
17521 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
17523 +#ifdef CONFIG_TMPFS
17524 + return sb->s_magic == TMPFS_MAGIC;
17530 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
17532 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
17533 + return !strcmp(au_sbtype(sb), "ecryptfs");
17539 +static inline int au_test_ramfs(struct super_block *sb)
17541 + return sb->s_magic == RAMFS_MAGIC;
17544 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
17546 +#if IS_ENABLED(CONFIG_UBIFS_FS)
17547 + return sb->s_magic == UBIFS_SUPER_MAGIC;
17553 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
17555 +#ifdef CONFIG_PROC_FS
17556 + return sb->s_magic == PROC_SUPER_MAGIC;
17562 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
17564 +#ifdef CONFIG_SYSFS
17565 + return sb->s_magic == SYSFS_MAGIC;
17571 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
17573 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
17574 + return sb->s_magic == CONFIGFS_MAGIC;
17580 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
17582 +#if IS_ENABLED(CONFIG_MINIX_FS)
17583 + return sb->s_magic == MINIX3_SUPER_MAGIC
17584 + || sb->s_magic == MINIX2_SUPER_MAGIC
17585 + || sb->s_magic == MINIX2_SUPER_MAGIC2
17586 + || sb->s_magic == MINIX_SUPER_MAGIC
17587 + || sb->s_magic == MINIX_SUPER_MAGIC2;
17593 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
17595 +#if IS_ENABLED(CONFIG_FAT_FS)
17596 + return sb->s_magic == MSDOS_SUPER_MAGIC;
17602 +static inline int au_test_msdos(struct super_block *sb)
17604 + return au_test_fat(sb);
17607 +static inline int au_test_vfat(struct super_block *sb)
17609 + return au_test_fat(sb);
17612 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
17614 +#ifdef CONFIG_SECURITYFS
17615 + return sb->s_magic == SECURITYFS_MAGIC;
17621 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
17623 +#if IS_ENABLED(CONFIG_SQUASHFS)
17624 + return sb->s_magic == SQUASHFS_MAGIC;
17630 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
17632 +#if IS_ENABLED(CONFIG_BTRFS_FS)
17633 + return sb->s_magic == BTRFS_SUPER_MAGIC;
17639 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
17641 +#if IS_ENABLED(CONFIG_XENFS)
17642 + return sb->s_magic == XENFS_SUPER_MAGIC;
17648 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
17650 +#ifdef CONFIG_DEBUG_FS
17651 + return sb->s_magic == DEBUGFS_MAGIC;
17657 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
17659 +#if IS_ENABLED(CONFIG_NILFS)
17660 + return sb->s_magic == NILFS_SUPER_MAGIC;
17666 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
17668 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
17669 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
17675 +/* ---------------------------------------------------------------------- */
17677 + * they can't be an aufs branch.
17679 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
17682 +#ifndef CONFIG_AUFS_BR_RAMFS
17683 + au_test_ramfs(sb) ||
17685 + au_test_procfs(sb)
17686 + || au_test_sysfs(sb)
17687 + || au_test_configfs(sb)
17688 + || au_test_debugfs(sb)
17689 + || au_test_securityfs(sb)
17690 + || au_test_xenfs(sb)
17691 + || au_test_ecryptfs(sb)
17692 + /* || !strcmp(au_sbtype(sb), "unionfs") */
17693 + || au_test_aufs(sb); /* will be supported in next version */
17696 +static inline int au_test_fs_remote(struct super_block *sb)
17698 + return !au_test_tmpfs(sb)
17699 +#ifdef CONFIG_AUFS_BR_RAMFS
17700 + && !au_test_ramfs(sb)
17702 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
17705 +/* ---------------------------------------------------------------------- */
17708 + * Note: these functions (below) are created after reading ->getattr() in all
17709 + * filesystems under linux/fs. it means we have to do so in every update...
17713 + * some filesystems require getattr to refresh the inode attributes before
17715 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
17716 + * and leave the work for d_revalidate()
17718 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
17720 + return au_test_nfs(sb)
17721 + || au_test_fuse(sb)
17722 + /* || au_test_btrfs(sb) */ /* untested */
17727 + * filesystems which don't maintain i_size or i_blocks.
17729 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
17731 + return au_test_xfs(sb)
17732 + || au_test_btrfs(sb)
17733 + || au_test_ubifs(sb)
17734 + || au_test_hfsplus(sb) /* maintained, but incorrect */
17735 + /* || au_test_minix(sb) */ /* untested */
17740 + * filesystems which don't store the correct value in some of their inode
17743 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
17745 + return au_test_fs_bad_iattr_size(sb)
17746 + || au_test_fat(sb)
17747 + || au_test_msdos(sb)
17748 + || au_test_vfat(sb);
17751 +/* they don't check i_nlink in link(2) */
17752 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
17754 + return au_test_tmpfs(sb)
17755 +#ifdef CONFIG_AUFS_BR_RAMFS
17756 + || au_test_ramfs(sb)
17758 + || au_test_ubifs(sb)
17759 + || au_test_hfsplus(sb);
17763 + * filesystems which sets S_NOATIME and S_NOCMTIME.
17765 +static inline int au_test_fs_notime(struct super_block *sb)
17767 + return au_test_nfs(sb)
17768 + || au_test_fuse(sb)
17769 + || au_test_ubifs(sb)
17773 +/* temporary support for i#1 in cramfs */
17774 +static inline int au_test_fs_unique_ino(struct inode *inode)
17776 + if (au_test_cramfs(inode->i_sb))
17777 + return inode->i_ino != 1;
17781 +/* ---------------------------------------------------------------------- */
17784 + * the filesystem where the xino files placed must support i/o after unlink and
17785 + * maintain i_size and i_blocks.
17787 +static inline int au_test_fs_bad_xino(struct super_block *sb)
17789 + return au_test_fs_remote(sb)
17790 + || au_test_fs_bad_iattr_size(sb)
17791 + /* don't want unnecessary work for xino */
17792 + || au_test_aufs(sb)
17793 + || au_test_ecryptfs(sb)
17794 + || au_test_nilfs(sb);
17797 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
17799 + return au_test_tmpfs(sb)
17800 + || au_test_ramfs(sb);
17804 + * test if the @sb is real-readonly.
17806 +static inline int au_test_fs_rr(struct super_block *sb)
17808 + return au_test_squashfs(sb)
17809 + || au_test_iso9660(sb)
17810 + || au_test_cramfs(sb)
17811 + || au_test_romfs(sb);
17815 + * test if the @inode is nfs with 'noacl' option
17816 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
17818 +static inline int au_test_nfs_noacl(struct inode *inode)
17820 + return au_test_nfs(inode->i_sb)
17821 + /* && IS_POSIXACL(inode) */
17822 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
17825 +#endif /* __KERNEL__ */
17826 +#endif /* __AUFS_FSTYPE_H__ */
17827 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
17828 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
17829 +++ linux/fs/aufs/hbl.h 2022-11-05 23:02:18.965889284 +0100
17831 +/* SPDX-License-Identifier: GPL-2.0 */
17833 + * Copyright (C) 2017-2022 Junjiro R. Okajima
17835 + * This program is free software; you can redistribute it and/or modify
17836 + * it under the terms of the GNU General Public License as published by
17837 + * the Free Software Foundation; either version 2 of the License, or
17838 + * (at your option) any later version.
17840 + * This program is distributed in the hope that it will be useful,
17841 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17842 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17843 + * GNU General Public License for more details.
17845 + * You should have received a copy of the GNU General Public License
17846 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17850 + * helpers for hlist_bl.h
17853 +#ifndef __AUFS_HBL_H__
17854 +#define __AUFS_HBL_H__
17858 +#include <linux/list_bl.h>
17860 +static inline void au_hbl_add(struct hlist_bl_node *node,
17861 + struct hlist_bl_head *hbl)
17863 + hlist_bl_lock(hbl);
17864 + hlist_bl_add_head(node, hbl);
17865 + hlist_bl_unlock(hbl);
17868 +static inline void au_hbl_del(struct hlist_bl_node *node,
17869 + struct hlist_bl_head *hbl)
17871 + hlist_bl_lock(hbl);
17872 + hlist_bl_del(node);
17873 + hlist_bl_unlock(hbl);
17876 +#define au_hbl_for_each(pos, head) \
17877 + for (pos = hlist_bl_first(head); \
17881 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
17883 + unsigned long cnt;
17884 + struct hlist_bl_node *pos;
17887 + hlist_bl_lock(hbl);
17888 + au_hbl_for_each(pos, hbl)
17890 + hlist_bl_unlock(hbl);
17894 +#endif /* __KERNEL__ */
17895 +#endif /* __AUFS_HBL_H__ */
17896 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
17897 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
17898 +++ linux/fs/aufs/hfsnotify.c 2022-11-05 23:02:18.965889284 +0100
17900 +// SPDX-License-Identifier: GPL-2.0
17902 + * Copyright (C) 2005-2022 Junjiro R. Okajima
17904 + * This program is free software; you can redistribute it and/or modify
17905 + * it under the terms of the GNU General Public License as published by
17906 + * the Free Software Foundation; either version 2 of the License, or
17907 + * (at your option) any later version.
17909 + * This program is distributed in the hope that it will be useful,
17910 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17911 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17912 + * GNU General Public License for more details.
17914 + * You should have received a copy of the GNU General Public License
17915 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17919 + * fsnotify for the lower directories
17924 +/* FS_IN_IGNORED is unnecessary */
17925 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
17926 + | FS_CREATE | FS_EVENT_ON_CHILD);
17927 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
17928 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
17930 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
17932 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
17934 + /* AuDbg("here\n"); */
17935 + au_cache_free_hnotify(hn);
17936 + smp_mb__before_atomic(); /* for atomic64_dec */
17937 + if (atomic64_dec_and_test(&au_hfsn_ifree))
17938 + wake_up(&au_hfsn_wq);
17941 +static int au_hfsn_alloc(struct au_hinode *hinode)
17944 + struct au_hnotify *hn;
17945 + struct super_block *sb;
17946 + struct au_branch *br;
17947 + struct fsnotify_mark *mark;
17948 + aufs_bindex_t bindex;
17950 + hn = hinode->hi_notify;
17951 + sb = hn->hn_aufs_inode->i_sb;
17952 + bindex = au_br_index(sb, hinode->hi_id);
17953 + br = au_sbr(sb, bindex);
17954 + AuDebugOn(!br->br_hfsn);
17956 + mark = &hn->hn_mark;
17957 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
17958 + mark->mask = AuHfsnMask;
17960 + * by udba rename or rmdir, aufs assign a new inode to the known
17961 + * h_inode, so specify 1 to allow dups.
17964 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
17970 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
17972 + struct fsnotify_mark *mark;
17973 + unsigned long long ull;
17974 + struct fsnotify_group *group;
17976 + ull = atomic64_inc_return(&au_hfsn_ifree);
17979 + mark = &hn->hn_mark;
17980 + spin_lock(&mark->lock);
17981 + group = mark->group;
17982 + fsnotify_get_group(group);
17983 + spin_unlock(&mark->lock);
17985 + fsnotify_destroy_mark(mark, group);
17986 + fsnotify_put_mark(mark);
17987 + fsnotify_put_group(group);
17990 + /* free hn by myself */
17994 +/* ---------------------------------------------------------------------- */
17996 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
17998 + struct fsnotify_mark *mark;
18000 + mark = &hinode->hi_notify->hn_mark;
18001 + spin_lock(&mark->lock);
18003 + AuDebugOn(mark->mask & AuHfsnMask);
18004 + mark->mask |= AuHfsnMask;
18006 + AuDebugOn(!(mark->mask & AuHfsnMask));
18007 + mark->mask &= ~AuHfsnMask;
18009 + spin_unlock(&mark->lock);
18010 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
18013 +/* ---------------------------------------------------------------------- */
18015 +/* #define AuDbgHnotify */
18016 +#ifdef AuDbgHnotify
18017 +static char *au_hfsn_name(u32 mask)
18019 +#ifdef CONFIG_AUFS_DEBUG
18020 +#define test_ret(flag) \
18022 + if (mask & flag) \
18025 + test_ret(FS_ACCESS);
18026 + test_ret(FS_MODIFY);
18027 + test_ret(FS_ATTRIB);
18028 + test_ret(FS_CLOSE_WRITE);
18029 + test_ret(FS_CLOSE_NOWRITE);
18030 + test_ret(FS_OPEN);
18031 + test_ret(FS_MOVED_FROM);
18032 + test_ret(FS_MOVED_TO);
18033 + test_ret(FS_CREATE);
18034 + test_ret(FS_DELETE);
18035 + test_ret(FS_DELETE_SELF);
18036 + test_ret(FS_MOVE_SELF);
18037 + test_ret(FS_UNMOUNT);
18038 + test_ret(FS_Q_OVERFLOW);
18039 + test_ret(FS_IN_IGNORED);
18040 + test_ret(FS_ISDIR);
18041 + test_ret(FS_IN_ONESHOT);
18042 + test_ret(FS_EVENT_ON_CHILD);
18051 +/* ---------------------------------------------------------------------- */
18053 +static void au_hfsn_free_group(struct fsnotify_group *group)
18055 + struct au_br_hfsnotify *hfsn = group->private;
18057 + /* AuDbg("here\n"); */
18058 + au_kfree_try_rcu(hfsn);
18061 +static int au_hfsn_handle_event(struct fsnotify_group *group,
18062 + u32 mask, const void *data, int data_type,
18063 + struct inode *dir,
18064 + const struct qstr *file_name, u32 cookie,
18065 + struct fsnotify_iter_info *iter_info)
18068 + struct au_hnotify *hnotify;
18069 + struct inode *h_dir, *h_inode;
18070 + struct fsnotify_mark *inode_mark;
18072 + AuDebugOn(!(data_type == FSNOTIFY_EVENT_INODE
18073 + || data_type == FSNOTIFY_EVENT_DENTRY));
18076 + /* if FS_UNMOUNT happens, there must be another bug */
18077 + AuDebugOn(mask & FS_UNMOUNT);
18078 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
18083 +#ifdef AuDbgHnotify
18085 + if (1 || file_name.len != sizeof(AUFS_XINO_FNAME) - 1
18086 + || strncmp(file_name.name, AUFS_XINO_FNAME, file_name.len)) {
18087 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
18088 + h_dir->i_ino, mask, au_hfsn_name(mask),
18089 + AuLNPair(file_name), h_inode ? h_inode->i_ino : 0);
18090 + /* WARN_ON(1); */
18095 + inode_mark = fsnotify_iter_inode_mark(iter_info);
18096 + AuDebugOn(!inode_mark);
18097 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
18098 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
18104 +static struct fsnotify_ops au_hfsn_ops = {
18105 + .handle_event = au_hfsn_handle_event,
18106 + .free_group_priv = au_hfsn_free_group,
18107 + .free_mark = au_hfsn_free_mark
18110 +/* ---------------------------------------------------------------------- */
18112 +static void au_hfsn_fin_br(struct au_branch *br)
18114 + struct au_br_hfsnotify *hfsn;
18116 + hfsn = br->br_hfsn;
18119 + fsnotify_put_group(hfsn->hfsn_group);
18124 +static int au_hfsn_init_br(struct au_branch *br, int perm)
18127 + struct fsnotify_group *group;
18128 + struct au_br_hfsnotify *hfsn;
18131 + br->br_hfsn = NULL;
18132 + if (!au_br_hnotifyable(perm))
18136 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
18137 + if (unlikely(!hfsn))
18141 + group = fsnotify_alloc_group(&au_hfsn_ops,
18142 + /*flags - not for userspace*/0);
18143 + if (IS_ERR(group)) {
18144 + err = PTR_ERR(group);
18145 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
18149 + group->private = hfsn;
18150 + hfsn->hfsn_group = group;
18151 + br->br_hfsn = hfsn;
18152 + goto out; /* success */
18155 + au_kfree_try_rcu(hfsn);
18160 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
18165 + if (!br->br_hfsn)
18166 + err = au_hfsn_init_br(br, perm);
18171 +/* ---------------------------------------------------------------------- */
18173 +static void au_hfsn_fin(void)
18175 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
18176 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
18179 +const struct au_hnotify_op au_hnotify_op = {
18180 + .ctl = au_hfsn_ctl,
18181 + .alloc = au_hfsn_alloc,
18182 + .free = au_hfsn_free,
18184 + .fin = au_hfsn_fin,
18186 + .reset_br = au_hfsn_reset_br,
18187 + .fin_br = au_hfsn_fin_br,
18188 + .init_br = au_hfsn_init_br
18190 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
18191 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
18192 +++ linux/fs/aufs/hfsplus.c 2022-11-05 23:02:18.965889284 +0100
18194 +// SPDX-License-Identifier: GPL-2.0
18196 + * Copyright (C) 2010-2022 Junjiro R. Okajima
18198 + * This program is free software; you can redistribute it and/or modify
18199 + * it under the terms of the GNU General Public License as published by
18200 + * the Free Software Foundation; either version 2 of the License, or
18201 + * (at your option) any later version.
18203 + * This program is distributed in the hope that it will be useful,
18204 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18205 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18206 + * GNU General Public License for more details.
18208 + * You should have received a copy of the GNU General Public License
18209 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18213 + * special support for filesystems which acquires an inode mutex
18214 + * at final closing a file, eg, hfsplus.
18216 + * This trick is very simple and stupid, just to open the file before really
18217 + * necessary open to tell hfsplus that this is not the final closing.
18218 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
18219 + * and au_h_open_post() after releasing it.
18224 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
18227 + struct file *h_file;
18228 + struct dentry *h_dentry;
18230 + h_dentry = au_h_dptr(dentry, bindex);
18231 + AuDebugOn(!h_dentry);
18232 + AuDebugOn(d_is_negative(h_dentry));
18235 + if (au_test_hfsplus(h_dentry->d_sb)
18236 + && d_is_reg(h_dentry))
18237 + h_file = au_h_open(dentry, bindex,
18238 + O_RDONLY | O_NOATIME | O_LARGEFILE,
18239 + /*file*/NULL, force_wr);
18243 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
18244 + struct file *h_file)
18246 + struct au_branch *br;
18250 + br = au_sbr(dentry->d_sb, bindex);
18251 + au_lcnt_dec(&br->br_nfiles);
18254 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
18255 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
18256 +++ linux/fs/aufs/hnotify.c 2022-11-05 23:02:18.965889284 +0100
18258 +// SPDX-License-Identifier: GPL-2.0
18260 + * Copyright (C) 2005-2022 Junjiro R. Okajima
18262 + * This program is free software; you can redistribute it and/or modify
18263 + * it under the terms of the GNU General Public License as published by
18264 + * the Free Software Foundation; either version 2 of the License, or
18265 + * (at your option) any later version.
18267 + * This program is distributed in the hope that it will be useful,
18268 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18269 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18270 + * GNU General Public License for more details.
18272 + * You should have received a copy of the GNU General Public License
18273 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18277 + * abstraction to notify the direct changes on lower directories
18280 +/* #include <linux/iversion.h> */
18283 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
18286 + struct au_hnotify *hn;
18289 + hn = au_cache_alloc_hnotify();
18291 + hn->hn_aufs_inode = inode;
18292 + hinode->hi_notify = hn;
18293 + err = au_hnotify_op.alloc(hinode);
18295 + if (unlikely(err)) {
18296 + hinode->hi_notify = NULL;
18297 + au_cache_free_hnotify(hn);
18299 + * The upper dir was removed by udba, but the same named
18300 + * dir left. In this case, aufs assigns a new inode
18301 + * number and set the monitor again.
18302 + * For the lower dir, the old monitor is still left.
18304 + if (err == -EEXIST)
18313 +void au_hn_free(struct au_hinode *hinode)
18315 + struct au_hnotify *hn;
18317 + hn = hinode->hi_notify;
18319 + hinode->hi_notify = NULL;
18320 + if (au_hnotify_op.free(hinode, hn))
18321 + au_cache_free_hnotify(hn);
18325 +/* ---------------------------------------------------------------------- */
18327 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
18329 + if (hinode->hi_notify)
18330 + au_hnotify_op.ctl(hinode, do_set);
18333 +void au_hn_reset(struct inode *inode, unsigned int flags)
18335 + aufs_bindex_t bindex, bbot;
18336 + struct inode *hi;
18337 + struct dentry *iwhdentry;
18339 + bbot = au_ibbot(inode);
18340 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18341 + hi = au_h_iptr(inode, bindex);
18345 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
18346 + iwhdentry = au_hi_wh(inode, bindex);
18350 + au_set_h_iptr(inode, bindex, NULL, 0);
18351 + au_set_h_iptr(inode, bindex, au_igrab(hi),
18352 + flags & ~AuHi_XINO);
18355 + /* inode_unlock(hi); */
18359 +/* ---------------------------------------------------------------------- */
18361 +static int hn_xino(struct inode *inode, struct inode *h_inode)
18364 + aufs_bindex_t bindex, bbot, bfound, btop;
18365 + struct inode *h_i;
18368 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18369 + pr_warn("branch root dir was changed\n");
18374 + bbot = au_ibbot(inode);
18375 + btop = au_ibtop(inode);
18376 +#if 0 /* reserved for future use */
18377 + if (bindex == bbot) {
18378 + /* keep this ino in rename case */
18382 + for (bindex = btop; bindex <= bbot; bindex++)
18383 + if (au_h_iptr(inode, bindex) == h_inode) {
18390 + for (bindex = btop; bindex <= bbot; bindex++) {
18391 + h_i = au_h_iptr(inode, bindex);
18395 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
18396 + /* ignore this error */
18397 + /* bad action? */
18400 + /* children inode number will be broken */
18407 +static int hn_gen_tree(struct dentry *dentry)
18409 + int err, i, j, ndentry;
18410 + struct au_dcsub_pages dpages;
18411 + struct au_dpage *dpage;
18412 + struct dentry **dentries;
18414 + err = au_dpages_init(&dpages, GFP_NOFS);
18415 + if (unlikely(err))
18417 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
18418 + if (unlikely(err))
18421 + for (i = 0; i < dpages.ndpage; i++) {
18422 + dpage = dpages.dpages + i;
18423 + dentries = dpage->dentries;
18424 + ndentry = dpage->ndentry;
18425 + for (j = 0; j < ndentry; j++) {
18426 + struct dentry *d;
18433 + if (d_really_is_positive(d))
18434 + /* todo: reset children xino?
18435 + cached children only? */
18436 + au_iigen_dec(d_inode(d));
18441 + au_dpages_free(&dpages);
18447 + * return 0 if processed.
18449 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
18450 + const unsigned int isdir)
18453 + struct dentry *d;
18454 + struct qstr *dname;
18457 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18458 + pr_warn("branch root dir was changed\n");
18464 + AuDebugOn(!name);
18465 + au_iigen_dec(inode);
18466 + spin_lock(&inode->i_lock);
18467 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
18468 + spin_lock(&d->d_lock);
18469 + dname = &d->d_name;
18470 + if (dname->len != nlen
18471 + && memcmp(dname->name, name, nlen)) {
18472 + spin_unlock(&d->d_lock);
18477 + spin_unlock(&d->d_lock);
18480 + spin_unlock(&inode->i_lock);
18482 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
18483 + d = d_find_any_alias(inode);
18485 + au_iigen_dec(inode);
18489 + spin_lock(&d->d_lock);
18490 + dname = &d->d_name;
18491 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
18492 + spin_unlock(&d->d_lock);
18493 + err = hn_gen_tree(d);
18494 + spin_lock(&d->d_lock);
18496 + spin_unlock(&d->d_lock);
18505 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
18509 + if (IS_ROOT(dentry)) {
18510 + pr_warn("branch root dir was changed\n");
18516 + au_digen_dec(dentry);
18517 + if (d_really_is_positive(dentry))
18518 + au_iigen_dec(d_inode(dentry));
18520 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
18521 + if (d_really_is_positive(dentry))
18522 + err = hn_gen_tree(dentry);
18529 +/* ---------------------------------------------------------------------- */
18531 +/* hnotify job flags */
18532 +#define AuHnJob_XINO0 1
18533 +#define AuHnJob_GEN (1 << 1)
18534 +#define AuHnJob_DIRENT (1 << 2)
18535 +#define AuHnJob_ISDIR (1 << 3)
18536 +#define AuHnJob_TRYXINO0 (1 << 4)
18537 +#define AuHnJob_MNTPNT (1 << 5)
18538 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
18539 +#define au_fset_hnjob(flags, name) \
18540 + do { (flags) |= AuHnJob_##name; } while (0)
18541 +#define au_fclr_hnjob(flags, name) \
18542 + do { (flags) &= ~AuHnJob_##name; } while (0)
18550 +struct au_hnotify_args {
18551 + struct inode *h_dir, *dir, *h_child_inode;
18553 + unsigned int flags[AuHnLast];
18554 + unsigned int h_child_nlen;
18555 + char h_child_name[];
18558 +struct hn_job_args {
18559 + unsigned int flags;
18560 + struct inode *inode, *h_inode, *dir, *h_dir;
18561 + struct dentry *dentry;
18566 +static int hn_job(struct hn_job_args *a)
18568 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
18572 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
18573 + hn_xino(a->inode, a->h_inode); /* ignore this error */
18575 + if (au_ftest_hnjob(a->flags, TRYXINO0)
18578 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
18579 + if (!a->h_inode->i_nlink
18580 + && !(a->h_inode->i_state & I_LINKABLE))
18581 + hn_xino(a->inode, a->h_inode); /* ignore this error */
18582 + inode_unlock_shared(a->h_inode);
18585 + /* make the generation obsolete */
18586 + if (au_ftest_hnjob(a->flags, GEN)) {
18589 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
18591 + if (e && a->dentry)
18592 + hn_gen_by_name(a->dentry, isdir);
18593 + /* ignore this error */
18596 + /* make dir entries obsolete */
18597 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
18598 + struct au_vdir *vdir;
18600 + vdir = au_ivdir(a->inode);
18602 + vdir->vd_jiffy = 0;
18603 + /* IMustLock(a->inode); */
18604 + /* inode_inc_iversion(a->inode); */
18607 + /* can do nothing but warn */
18608 + if (au_ftest_hnjob(a->flags, MNTPNT)
18610 + && d_mountpoint(a->dentry))
18611 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
18616 +/* ---------------------------------------------------------------------- */
18618 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
18619 + struct inode *dir)
18621 + struct dentry *dentry, *d, *parent;
18622 + struct qstr *dname;
18624 + parent = d_find_any_alias(dir);
18629 + spin_lock(&parent->d_lock);
18630 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
18631 + /* AuDbg("%pd\n", d); */
18632 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
18633 + dname = &d->d_name;
18634 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
18635 + goto cont_unlock;
18639 + goto cont_unlock;
18640 + if (au_dcount(d) > 0) {
18641 + dentry = dget_dlock(d);
18642 + spin_unlock(&d->d_lock);
18647 + spin_unlock(&d->d_lock);
18649 + spin_unlock(&parent->d_lock);
18653 + di_write_lock_child(dentry);
18658 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
18659 + aufs_bindex_t bindex, ino_t h_ino)
18661 + struct inode *inode;
18666 + err = au_xino_read(sb, bindex, h_ino, &ino);
18668 + inode = ilookup(sb, ino);
18672 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18673 + pr_warn("wrong root branch\n");
18679 + ii_write_lock_child(inode);
18685 +static void au_hn_bh(void *_args)
18687 + struct au_hnotify_args *a = _args;
18688 + struct super_block *sb;
18689 + aufs_bindex_t bindex, bbot, bfound;
18690 + unsigned char xino, try_iput;
18692 + struct inode *inode;
18694 + struct hn_job_args args;
18695 + struct dentry *dentry;
18696 + struct au_sbinfo *sbinfo;
18698 + AuDebugOn(!_args);
18699 + AuDebugOn(!a->h_dir);
18700 + AuDebugOn(!a->dir);
18701 + AuDebugOn(!a->mask);
18702 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
18703 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
18704 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
18709 + * do not lock a->dir->i_mutex here
18710 + * because of d_revalidate() may cause a deadlock.
18712 + sb = a->dir->i_sb;
18714 + sbinfo = au_sbi(sb);
18715 + AuDebugOn(!sbinfo);
18716 + si_write_lock(sb, AuLock_NOPLMW);
18718 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
18719 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
18720 + case FS_MOVED_FROM:
18721 + case FS_MOVED_TO:
18722 + AuWarn1("DIRREN with UDBA may not work correctly "
18723 + "for the direct rename(2)\n");
18726 + ii_read_lock_parent(a->dir);
18728 + bbot = au_ibbot(a->dir);
18729 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
18730 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
18734 + ii_read_unlock(a->dir);
18735 + if (unlikely(bfound < 0))
18738 + xino = !!au_opt_test(au_mntflags(sb), XINO);
18740 + if (a->h_child_inode)
18741 + h_ino = a->h_child_inode->i_ino;
18743 + if (a->h_child_nlen
18744 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
18745 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
18746 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
18749 + if (dentry && d_really_is_positive(dentry))
18750 + inode = d_inode(dentry);
18751 + if (xino && !inode && h_ino
18752 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
18753 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
18754 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
18755 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
18759 + args.flags = a->flags[AuHn_CHILD];
18760 + args.dentry = dentry;
18761 + args.inode = inode;
18762 + args.h_inode = a->h_child_inode;
18763 + args.dir = a->dir;
18764 + args.h_dir = a->h_dir;
18765 + args.h_name = a->h_child_name;
18766 + args.h_nlen = a->h_child_nlen;
18767 + err = hn_job(&args);
18769 + if (au_di(dentry))
18770 + di_write_unlock(dentry);
18773 + if (inode && try_iput) {
18774 + ii_write_unlock(inode);
18778 + ii_write_lock_parent(a->dir);
18779 + args.flags = a->flags[AuHn_PARENT];
18780 + args.dentry = NULL;
18781 + args.inode = a->dir;
18782 + args.h_inode = a->h_dir;
18784 + args.h_dir = NULL;
18785 + args.h_name = NULL;
18787 + err = hn_job(&args);
18788 + ii_write_unlock(a->dir);
18791 + iput(a->h_child_inode);
18794 + si_write_unlock(sb);
18795 + au_nwt_done(&sbinfo->si_nowait);
18799 +/* ---------------------------------------------------------------------- */
18801 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
18802 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
18805 + unsigned int flags[AuHnLast], f;
18806 + unsigned char isdir, isroot, wh;
18807 + struct inode *dir;
18808 + struct au_hnotify_args *args;
18809 + char *p, *h_child_name;
18812 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
18813 + dir = igrab(hnotify->hn_aufs_inode);
18817 + isroot = (dir->i_ino == AUFS_ROOT_INO);
18819 + h_child_name = (void *)h_child_qstr->name;
18820 + len = h_child_qstr->len;
18821 + if (h_child_name) {
18822 + if (len > AUFS_WH_PFX_LEN
18823 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
18824 + h_child_name += AUFS_WH_PFX_LEN;
18825 + len -= AUFS_WH_PFX_LEN;
18831 + if (h_child_inode)
18832 + isdir = !!S_ISDIR(h_child_inode->i_mode);
18833 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
18834 + flags[AuHn_CHILD] = 0;
18836 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
18837 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
18838 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
18839 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
18840 + case FS_MOVED_FROM:
18841 + case FS_MOVED_TO:
18842 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
18843 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
18846 + AuDebugOn(!h_child_name);
18851 + * aufs never be able to get this child inode.
18852 + * revalidation should be in d_revalidate()
18853 + * by checking i_nlink, i_generation or d_unhashed().
18855 + AuDebugOn(!h_child_name);
18856 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
18857 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
18865 + h_child_inode = NULL;
18868 + /* iput() and kfree() will be called in au_hnotify() */
18869 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
18870 + if (unlikely(!args)) {
18871 + AuErr1("no memory\n");
18875 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
18876 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
18877 + args->mask = mask;
18879 + args->h_dir = igrab(h_dir);
18880 + if (h_child_inode)
18881 + h_child_inode = igrab(h_child_inode); /* can be NULL */
18882 + args->h_child_inode = h_child_inode;
18883 + args->h_child_nlen = len;
18885 + p = (void *)args;
18886 + p += sizeof(*args);
18887 + memcpy(p, h_child_name, len);
18891 + /* NFS fires the event for silly-renamed one from kworker */
18893 + if (!dir->i_nlink
18894 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
18896 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
18897 + if (unlikely(err)) {
18898 + pr_err("wkq %d\n", err);
18899 + iput(args->h_child_inode);
18900 + iput(args->h_dir);
18902 + au_kfree_rcu(args);
18909 +/* ---------------------------------------------------------------------- */
18911 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
18915 + AuDebugOn(!(udba & AuOptMask_UDBA));
18918 + if (au_hnotify_op.reset_br)
18919 + err = au_hnotify_op.reset_br(udba, br, perm);
18924 +int au_hnotify_init_br(struct au_branch *br, int perm)
18929 + if (au_hnotify_op.init_br)
18930 + err = au_hnotify_op.init_br(br, perm);
18935 +void au_hnotify_fin_br(struct au_branch *br)
18937 + if (au_hnotify_op.fin_br)
18938 + au_hnotify_op.fin_br(br);
18941 +static void au_hn_destroy_cache(void)
18943 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
18944 + au_cache[AuCache_HNOTIFY] = NULL;
18947 +int __init au_hnotify_init(void)
18952 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
18953 + if (au_cache[AuCache_HNOTIFY]) {
18955 + if (au_hnotify_op.init)
18956 + err = au_hnotify_op.init();
18957 + if (unlikely(err))
18958 + au_hn_destroy_cache();
18964 +void au_hnotify_fin(void)
18966 + if (au_hnotify_op.fin)
18967 + au_hnotify_op.fin();
18969 + /* cf. au_cache_fin() */
18970 + if (au_cache[AuCache_HNOTIFY])
18971 + au_hn_destroy_cache();
18973 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
18974 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
18975 +++ linux/fs/aufs/iinfo.c 2022-11-05 23:02:18.965889284 +0100
18977 +// SPDX-License-Identifier: GPL-2.0
18979 + * Copyright (C) 2005-2022 Junjiro R. Okajima
18981 + * This program is free software; you can redistribute it and/or modify
18982 + * it under the terms of the GNU General Public License as published by
18983 + * the Free Software Foundation; either version 2 of the License, or
18984 + * (at your option) any later version.
18986 + * This program is distributed in the hope that it will be useful,
18987 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18988 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18989 + * GNU General Public License for more details.
18991 + * You should have received a copy of the GNU General Public License
18992 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18996 + * inode private data
19001 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
19003 + struct inode *h_inode;
19004 + struct au_hinode *hinode;
19006 + IiMustAnyLock(inode);
19008 + hinode = au_hinode(au_ii(inode), bindex);
19009 + h_inode = hinode->hi_inode;
19010 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19014 +/* todo: hard/soft set? */
19015 +void au_hiput(struct au_hinode *hinode)
19017 + au_hn_free(hinode);
19018 + dput(hinode->hi_whdentry);
19019 + iput(hinode->hi_inode);
19022 +unsigned int au_hi_flags(struct inode *inode, int isdir)
19024 + unsigned int flags;
19025 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
19028 + if (au_opt_test(mnt_flags, XINO))
19029 + au_fset_hi(flags, XINO);
19030 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
19031 + au_fset_hi(flags, HNOTIFY);
19035 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19036 + struct inode *h_inode, unsigned int flags)
19038 + struct au_hinode *hinode;
19039 + struct inode *hi;
19040 + struct au_iinfo *iinfo = au_ii(inode);
19042 + IiMustWriteLock(inode);
19044 + hinode = au_hinode(iinfo, bindex);
19045 + hi = hinode->hi_inode;
19046 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19049 + au_hiput(hinode);
19050 + hinode->hi_inode = h_inode;
19053 + struct super_block *sb = inode->i_sb;
19054 + struct au_branch *br;
19056 + AuDebugOn(inode->i_mode
19057 + && (h_inode->i_mode & S_IFMT)
19058 + != (inode->i_mode & S_IFMT));
19059 + if (bindex == iinfo->ii_btop)
19060 + au_cpup_igen(inode, h_inode);
19061 + br = au_sbr(sb, bindex);
19062 + hinode->hi_id = br->br_id;
19063 + if (au_ftest_hi(flags, XINO)) {
19064 + err = au_xino_write(sb, bindex, h_inode->i_ino,
19066 + if (unlikely(err))
19067 + AuIOErr1("failed au_xino_write() %d\n", err);
19070 + if (au_ftest_hi(flags, HNOTIFY)
19071 + && au_br_hnotifyable(br->br_perm)) {
19072 + err = au_hn_alloc(hinode, inode);
19073 + if (unlikely(err))
19074 + AuIOErr1("au_hn_alloc() %d\n", err);
19079 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19080 + struct dentry *h_wh)
19082 + struct au_hinode *hinode;
19084 + IiMustWriteLock(inode);
19086 + hinode = au_hinode(au_ii(inode), bindex);
19087 + AuDebugOn(hinode->hi_whdentry);
19088 + hinode->hi_whdentry = h_wh;
19091 +void au_update_iigen(struct inode *inode, int half)
19093 + struct au_iinfo *iinfo;
19094 + struct au_iigen *iigen;
19095 + unsigned int sigen;
19097 + sigen = au_sigen(inode->i_sb);
19098 + iinfo = au_ii(inode);
19099 + iigen = &iinfo->ii_generation;
19100 + spin_lock(&iigen->ig_spin);
19101 + iigen->ig_generation = sigen;
19103 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
19105 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
19106 + spin_unlock(&iigen->ig_spin);
19109 +/* it may be called at remount time, too */
19110 +void au_update_ibrange(struct inode *inode, int do_put_zero)
19112 + struct au_iinfo *iinfo;
19113 + aufs_bindex_t bindex, bbot;
19115 + AuDebugOn(au_is_bad_inode(inode));
19116 + IiMustWriteLock(inode);
19118 + iinfo = au_ii(inode);
19119 + if (do_put_zero && iinfo->ii_btop >= 0) {
19120 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
19122 + struct inode *h_i;
19124 + h_i = au_hinode(iinfo, bindex)->hi_inode;
19127 + && !(h_i->i_state & I_LINKABLE))
19128 + au_set_h_iptr(inode, bindex, NULL, 0);
19132 + iinfo->ii_btop = -1;
19133 + iinfo->ii_bbot = -1;
19134 + bbot = au_sbbot(inode->i_sb);
19135 + for (bindex = 0; bindex <= bbot; bindex++)
19136 + if (au_hinode(iinfo, bindex)->hi_inode) {
19137 + iinfo->ii_btop = bindex;
19140 + if (iinfo->ii_btop >= 0)
19141 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
19142 + if (au_hinode(iinfo, bindex)->hi_inode) {
19143 + iinfo->ii_bbot = bindex;
19146 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
19149 +/* ---------------------------------------------------------------------- */
19151 +void au_icntnr_init_once(void *_c)
19153 + struct au_icntnr *c = _c;
19154 + struct au_iinfo *iinfo = &c->iinfo;
19156 + spin_lock_init(&iinfo->ii_generation.ig_spin);
19157 + au_rw_init(&iinfo->ii_rwsem);
19158 + inode_init_once(&c->vfs_inode);
19161 +void au_hinode_init(struct au_hinode *hinode)
19163 + hinode->hi_inode = NULL;
19164 + hinode->hi_id = -1;
19165 + au_hn_init(hinode);
19166 + hinode->hi_whdentry = NULL;
19169 +int au_iinfo_init(struct inode *inode)
19171 + struct au_iinfo *iinfo;
19172 + struct super_block *sb;
19173 + struct au_hinode *hi;
19176 + sb = inode->i_sb;
19177 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19178 + nbr = au_sbbot(sb) + 1;
19179 + if (unlikely(nbr <= 0))
19181 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
19183 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
19185 + iinfo->ii_hinode = hi;
19186 + for (i = 0; i < nbr; i++, hi++)
19187 + au_hinode_init(hi);
19189 + iinfo->ii_generation.ig_generation = au_sigen(sb);
19190 + iinfo->ii_btop = -1;
19191 + iinfo->ii_bbot = -1;
19192 + iinfo->ii_vdir = NULL;
19198 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
19201 + struct au_hinode *hip;
19203 + AuRwMustWriteLock(&iinfo->ii_rwsem);
19206 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
19209 + iinfo->ii_hinode = hip;
19210 + i = iinfo->ii_bbot + 1;
19212 + for (; i < nbr; i++, hip++)
19213 + au_hinode_init(hip);
19220 +void au_iinfo_fin(struct inode *inode)
19222 + struct au_iinfo *iinfo;
19223 + struct au_hinode *hi;
19224 + struct super_block *sb;
19225 + aufs_bindex_t bindex, bbot;
19226 + const unsigned char unlinked = !inode->i_nlink;
19228 + AuDebugOn(au_is_bad_inode(inode));
19230 + sb = inode->i_sb;
19231 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
19232 + if (si_pid_test(sb))
19233 + au_xino_delete_inode(inode, unlinked);
19236 + * it is safe to hide the dependency between sbinfo and
19240 + si_noflush_read_lock(sb);
19241 + au_xino_delete_inode(inode, unlinked);
19242 + si_read_unlock(sb);
19246 + iinfo = au_ii(inode);
19247 + if (iinfo->ii_vdir)
19248 + au_vdir_free(iinfo->ii_vdir);
19250 + bindex = iinfo->ii_btop;
19251 + if (bindex >= 0) {
19252 + hi = au_hinode(iinfo, bindex);
19253 + bbot = iinfo->ii_bbot;
19254 + while (bindex++ <= bbot) {
19255 + if (hi->hi_inode)
19260 + au_kfree_rcu(iinfo->ii_hinode);
19261 + AuRwDestroy(&iinfo->ii_rwsem);
19263 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
19264 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
19265 +++ linux/fs/aufs/inode.c 2022-11-05 23:02:18.965889284 +0100
19267 +// SPDX-License-Identifier: GPL-2.0
19269 + * Copyright (C) 2005-2022 Junjiro R. Okajima
19271 + * This program is free software; you can redistribute it and/or modify
19272 + * it under the terms of the GNU General Public License as published by
19273 + * the Free Software Foundation; either version 2 of the License, or
19274 + * (at your option) any later version.
19276 + * This program is distributed in the hope that it will be useful,
19277 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19278 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19279 + * GNU General Public License for more details.
19281 + * You should have received a copy of the GNU General Public License
19282 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19286 + * inode functions
19289 +#include <linux/iversion.h>
19292 +struct inode *au_igrab(struct inode *inode)
19295 + AuDebugOn(!atomic_read(&inode->i_count));
19301 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
19303 + au_cpup_attr_all(inode, /*force*/0);
19304 + au_update_iigen(inode, /*half*/1);
19306 + inode_inc_iversion(inode);
19309 +static int au_ii_refresh(struct inode *inode, int *update)
19313 + aufs_bindex_t bindex, new_bindex;
19314 + struct super_block *sb;
19315 + struct au_iinfo *iinfo;
19316 + struct au_hinode *p, *q, tmp;
19318 + AuDebugOn(au_is_bad_inode(inode));
19319 + IiMustWriteLock(inode);
19322 + sb = inode->i_sb;
19323 + nbr = au_sbbot(sb) + 1;
19324 + type = inode->i_mode & S_IFMT;
19325 + iinfo = au_ii(inode);
19326 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
19327 + if (unlikely(err))
19330 + AuDebugOn(iinfo->ii_btop < 0);
19331 + p = au_hinode(iinfo, iinfo->ii_btop);
19332 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
19334 + if (!p->hi_inode)
19337 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
19338 + new_bindex = au_br_index(sb, p->hi_id);
19339 + if (new_bindex == bindex)
19342 + if (new_bindex < 0) {
19345 + p->hi_inode = NULL;
19349 + if (new_bindex < iinfo->ii_btop)
19350 + iinfo->ii_btop = new_bindex;
19351 + if (iinfo->ii_bbot < new_bindex)
19352 + iinfo->ii_bbot = new_bindex;
19353 + /* swap two lower inode, and loop again */
19354 + q = au_hinode(iinfo, new_bindex);
19358 + if (tmp.hi_inode) {
19363 + au_update_ibrange(inode, /*do_put_zero*/0);
19364 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
19365 + e = au_dy_irefresh(inode);
19366 + if (unlikely(e && !err))
19374 +void au_refresh_iop(struct inode *inode, int force_getattr)
19377 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
19378 + const struct inode_operations *iop
19379 + = force_getattr ? aufs_iop : sbi->si_iop_array;
19381 + if (inode->i_op == iop)
19384 + switch (inode->i_mode & S_IFMT) {
19386 + type = AuIop_DIR;
19389 + type = AuIop_SYMLINK;
19392 + type = AuIop_OTHER;
19396 + inode->i_op = iop + type;
19397 + /* unnecessary smp_wmb() */
19400 +int au_refresh_hinode_self(struct inode *inode)
19404 + err = au_ii_refresh(inode, &update);
19406 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
19412 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
19414 + int err, e, update;
19415 + unsigned int flags;
19417 + aufs_bindex_t bindex, bbot;
19418 + unsigned char isdir;
19419 + struct au_hinode *p;
19420 + struct au_iinfo *iinfo;
19422 + err = au_ii_refresh(inode, &update);
19423 + if (unlikely(err))
19427 + iinfo = au_ii(inode);
19428 + p = au_hinode(iinfo, iinfo->ii_btop);
19429 + mode = (inode->i_mode & S_IFMT);
19430 + isdir = S_ISDIR(mode);
19431 + flags = au_hi_flags(inode, isdir);
19432 + bbot = au_dbbot(dentry);
19433 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
19434 + struct inode *h_i, *h_inode;
19435 + struct dentry *h_d;
19437 + h_d = au_h_dptr(dentry, bindex);
19438 + if (!h_d || d_is_negative(h_d))
19441 + h_inode = d_inode(h_d);
19442 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
19443 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
19444 + h_i = au_h_iptr(inode, bindex);
19446 + if (h_i == h_inode)
19452 + if (bindex < iinfo->ii_btop)
19453 + iinfo->ii_btop = bindex;
19454 + if (iinfo->ii_bbot < bindex)
19455 + iinfo->ii_bbot = bindex;
19456 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
19459 + au_update_ibrange(inode, /*do_put_zero*/0);
19460 + e = au_dy_irefresh(inode);
19461 + if (unlikely(e && !err))
19464 + au_refresh_hinode_attr(inode, update && isdir);
19471 +static int set_inode(struct inode *inode, struct dentry *dentry)
19474 + unsigned int flags;
19476 + aufs_bindex_t bindex, btop, btail;
19477 + unsigned char isdir;
19478 + struct dentry *h_dentry;
19479 + struct inode *h_inode;
19480 + struct au_iinfo *iinfo;
19481 + const struct inode_operations *iop;
19483 + IiMustWriteLock(inode);
19487 + iop = au_sbi(inode->i_sb)->si_iop_array;
19488 + btop = au_dbtop(dentry);
19489 + h_dentry = au_h_dptr(dentry, btop);
19490 + h_inode = d_inode(h_dentry);
19491 + mode = h_inode->i_mode;
19492 + switch (mode & S_IFMT) {
19494 + btail = au_dbtail(dentry);
19495 + inode->i_op = iop + AuIop_OTHER;
19496 + inode->i_fop = &aufs_file_fop;
19497 + err = au_dy_iaop(inode, btop, h_inode);
19498 + if (unlikely(err))
19503 + btail = au_dbtaildir(dentry);
19504 + inode->i_op = iop + AuIop_DIR;
19505 + inode->i_fop = &aufs_dir_fop;
19508 + btail = au_dbtail(dentry);
19509 + inode->i_op = iop + AuIop_SYMLINK;
19515 + btail = au_dbtail(dentry);
19516 + inode->i_op = iop + AuIop_OTHER;
19517 + init_special_inode(inode, mode, h_inode->i_rdev);
19520 + AuIOErr("Unknown file type 0%o\n", mode);
19525 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
19526 + flags = au_hi_flags(inode, isdir);
19527 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
19528 + && au_ftest_hi(flags, HNOTIFY)
19529 + && dentry->d_name.len > AUFS_WH_PFX_LEN
19530 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
19531 + au_fclr_hi(flags, HNOTIFY);
19532 + iinfo = au_ii(inode);
19533 + iinfo->ii_btop = btop;
19534 + iinfo->ii_bbot = btail;
19535 + for (bindex = btop; bindex <= btail; bindex++) {
19536 + h_dentry = au_h_dptr(dentry, bindex);
19538 + au_set_h_iptr(inode, bindex,
19539 + au_igrab(d_inode(h_dentry)), flags);
19541 + au_cpup_attr_all(inode, /*force*/1);
19543 + * to force calling aufs_get_acl() every time,
19544 + * do not call cache_no_acl() for aufs inode.
19552 + * successful returns with iinfo write_locked
19554 + * zero: success, matched
19555 + * plus: no error, but unmatched
19557 +static int reval_inode(struct inode *inode, struct dentry *dentry)
19560 + unsigned int gen, igflags;
19561 + aufs_bindex_t bindex, bbot;
19562 + struct inode *h_inode, *h_dinode;
19563 + struct dentry *h_dentry;
19566 + * before this function, if aufs got any iinfo lock, it must be only
19567 + * one, the parent dir.
19568 + * it can happen by UDBA and the obsoleted inode number.
19571 + if (unlikely(inode->i_ino == parent_ino(dentry)))
19575 + ii_write_lock_new_child(inode);
19576 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
19577 + h_dinode = d_inode(h_dentry);
19578 + bbot = au_ibbot(inode);
19579 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
19580 + h_inode = au_h_iptr(inode, bindex);
19581 + if (!h_inode || h_inode != h_dinode)
19585 + gen = au_iigen(inode, &igflags);
19586 + if (gen == au_digen(dentry)
19587 + && !au_ig_ftest(igflags, HALF_REFRESHED))
19590 + /* fully refresh inode using dentry */
19591 + err = au_refresh_hinode(inode, dentry);
19593 + au_update_iigen(inode, /*half*/0);
19597 + if (unlikely(err))
19598 + ii_write_unlock(inode);
19603 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19604 + unsigned int d_type, ino_t *ino)
19607 + const int isnondir = d_type != DT_DIR;
19609 + /* prevent hardlinked inode number from race condition */
19611 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
19612 + if (unlikely(err))
19616 + err = au_xino_read(sb, bindex, h_ino, ino);
19617 + if (unlikely(err))
19618 + goto out_xinondir;
19622 + *ino = au_xino_new_ino(sb);
19623 + if (unlikely(!*ino))
19624 + goto out_xinondir;
19625 + err = au_xino_write(sb, bindex, h_ino, *ino);
19626 + if (unlikely(err))
19627 + goto out_xinondir;
19631 + if (isnondir && idx >= 0)
19632 + au_xinondir_leave(sb, bindex, h_ino, idx);
19637 +/* successful returns with iinfo write_locked */
19638 +/* todo: return with unlocked? */
19639 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
19641 + struct inode *inode, *h_inode;
19642 + struct dentry *h_dentry;
19643 + struct super_block *sb;
19644 + ino_t h_ino, ino;
19645 + int err, idx, hlinked;
19646 + aufs_bindex_t btop;
19648 + sb = dentry->d_sb;
19649 + btop = au_dbtop(dentry);
19650 + h_dentry = au_h_dptr(dentry, btop);
19651 + h_inode = d_inode(h_dentry);
19652 + h_ino = h_inode->i_ino;
19653 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
19657 + * stop 'race'-ing between hardlinks under different
19661 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
19662 + inode = ERR_PTR(err);
19663 + if (unlikely(err))
19667 + err = au_xino_read(sb, btop, h_ino, &ino);
19668 + inode = ERR_PTR(err);
19669 + if (unlikely(err))
19670 + goto out_xinondir;
19673 + ino = au_xino_new_ino(sb);
19674 + if (unlikely(!ino)) {
19675 + inode = ERR_PTR(-EIO);
19676 + goto out_xinondir;
19680 + AuDbg("i%lu\n", (unsigned long)ino);
19681 + inode = au_iget_locked(sb, ino);
19682 + err = PTR_ERR(inode);
19683 + if (IS_ERR(inode))
19684 + goto out_xinondir;
19686 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
19687 + if (inode->i_state & I_NEW) {
19688 + ii_write_lock_new_child(inode);
19689 + err = set_inode(inode, dentry);
19691 + unlock_new_inode(inode);
19692 + goto out_xinondir; /* success */
19696 + * iget_failed() calls iput(), but we need to call
19697 + * ii_write_unlock() after iget_failed(). so dirty hack for
19700 + atomic_inc(&inode->i_count);
19701 + iget_failed(inode);
19702 + ii_write_unlock(inode);
19703 + au_xino_write(sb, btop, h_ino, /*ino*/0);
19704 + /* ignore this error */
19706 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
19708 + * horrible race condition between lookup, readdir and copyup
19709 + * (or something).
19711 + if (hlinked && idx >= 0)
19712 + au_xinondir_leave(sb, btop, h_ino, idx);
19713 + err = reval_inode(inode, dentry);
19714 + if (unlikely(err < 0)) {
19719 + goto out; /* success */
19720 + else if (hlinked && idx >= 0) {
19721 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
19722 + if (unlikely(err)) {
19724 + inode = ERR_PTR(err);
19730 + if (unlikely(au_test_fs_unique_ino(h_inode)))
19731 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
19732 + " b%d, %s, %pd, hi%lu, i%lu.\n",
19733 + btop, au_sbtype(h_dentry->d_sb), dentry,
19734 + (unsigned long)h_ino, (unsigned long)ino);
19736 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
19739 + if (hlinked && idx >= 0)
19740 + au_xinondir_leave(sb, btop, h_ino, idx);
19746 + inode = ERR_PTR(err);
19748 + if (hlinked && idx >= 0)
19749 + au_xinondir_leave(sb, btop, h_ino, idx);
19754 +/* ---------------------------------------------------------------------- */
19756 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19757 + struct inode *inode)
19760 + struct inode *hi;
19762 + err = au_br_rdonly(au_sbr(sb, bindex));
19764 + /* pseudo-link after flushed may happen out of bounds */
19767 + && au_ibtop(inode) <= bindex
19768 + && bindex <= au_ibbot(inode)) {
19770 + * permission check is unnecessary since vfsub routine
19771 + * will be called later
19773 + hi = au_h_iptr(inode, bindex);
19775 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
19781 +int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
19784 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
19786 + return inode_permission(h_userns, h_inode, mask);
19789 +int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
19792 + if (au_test_nfs(h_inode->i_sb)
19793 + && (mask & MAY_WRITE)
19794 + && S_ISDIR(h_inode->i_mode))
19795 + mask |= MAY_READ; /* force permission check */
19796 + return au_test_h_perm(h_userns, h_inode, mask);
19798 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
19799 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
19800 +++ linux/fs/aufs/inode.h 2022-11-05 23:02:18.965889284 +0100
19802 +/* SPDX-License-Identifier: GPL-2.0 */
19804 + * Copyright (C) 2005-2022 Junjiro R. Okajima
19806 + * This program is free software; you can redistribute it and/or modify
19807 + * it under the terms of the GNU General Public License as published by
19808 + * the Free Software Foundation; either version 2 of the License, or
19809 + * (at your option) any later version.
19811 + * This program is distributed in the hope that it will be useful,
19812 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19813 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19814 + * GNU General Public License for more details.
19816 + * You should have received a copy of the GNU General Public License
19817 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19821 + * inode operations
19824 +#ifndef __AUFS_INODE_H__
19825 +#define __AUFS_INODE_H__
19829 +#include <linux/fsnotify.h>
19830 +#include "rwsem.h"
19834 +struct au_hnotify {
19835 +#ifdef CONFIG_AUFS_HNOTIFY
19836 +#ifdef CONFIG_AUFS_HFSNOTIFY
19837 + /* never use fsnotify_add_vfsmount_mark() */
19838 + struct fsnotify_mark hn_mark;
19840 + struct inode *hn_aufs_inode; /* no get/put */
19841 + struct rcu_head rcu;
19843 +} ____cacheline_aligned_in_smp;
19845 +struct au_hinode {
19846 + struct inode *hi_inode;
19847 + aufs_bindex_t hi_id;
19848 +#ifdef CONFIG_AUFS_HNOTIFY
19849 + struct au_hnotify *hi_notify;
19852 + /* reference to the copied-up whiteout with get/put */
19853 + struct dentry *hi_whdentry;
19857 +#define AuIG_HALF_REFRESHED 1
19858 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
19859 +#define au_ig_fset(flags, name) \
19860 + do { (flags) |= AuIG_##name; } while (0)
19861 +#define au_ig_fclr(flags, name) \
19862 + do { (flags) &= ~AuIG_##name; } while (0)
19865 + spinlock_t ig_spin;
19866 + __u32 ig_generation, ig_flags;
19871 + struct au_iigen ii_generation;
19872 + struct super_block *ii_hsb1; /* no get/put */
19874 + struct au_rwsem ii_rwsem;
19875 + aufs_bindex_t ii_btop, ii_bbot;
19877 + struct au_hinode *ii_hinode;
19878 + struct au_vdir *ii_vdir;
19881 +struct au_icntnr {
19882 + struct au_iinfo iinfo;
19883 + struct inode vfs_inode;
19884 + struct hlist_bl_node plink;
19885 + struct rcu_head rcu;
19886 +} ____cacheline_aligned_in_smp;
19888 +/* au_pin flags */
19889 +#define AuPin_DI_LOCKED 1
19890 +#define AuPin_MNT_WRITE (1 << 1)
19891 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
19892 +#define au_fset_pin(flags, name) \
19893 + do { (flags) |= AuPin_##name; } while (0)
19894 +#define au_fclr_pin(flags, name) \
19895 + do { (flags) &= ~AuPin_##name; } while (0)
19899 + struct dentry *dentry;
19900 + unsigned int udba;
19901 + unsigned char lsc_di, lsc_hi, flags;
19902 + aufs_bindex_t bindex;
19905 + struct dentry *parent;
19906 + struct au_hinode *hdir;
19907 + struct vfsmount *h_mnt;
19909 + /* temporary unlock/relock for copyup */
19910 + struct dentry *h_dentry, *h_parent;
19911 + struct au_branch *br;
19912 + struct task_struct *task;
19915 +void au_pin_hdir_unlock(struct au_pin *p);
19916 +int au_pin_hdir_lock(struct au_pin *p);
19917 +int au_pin_hdir_relock(struct au_pin *p);
19918 +void au_pin_hdir_acquire_nest(struct au_pin *p);
19919 +void au_pin_hdir_release(struct au_pin *p);
19921 +/* ---------------------------------------------------------------------- */
19923 +static inline struct au_iinfo *au_ii(struct inode *inode)
19925 + BUG_ON(is_bad_inode(inode));
19926 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19929 +/* ---------------------------------------------------------------------- */
19932 +struct inode *au_igrab(struct inode *inode);
19933 +void au_refresh_iop(struct inode *inode, int force_getattr);
19934 +int au_refresh_hinode_self(struct inode *inode);
19935 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
19936 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19937 + unsigned int d_type, ino_t *ino);
19938 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
19939 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19940 + struct inode *inode);
19941 +int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
19943 +int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
19946 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
19947 + ino_t h_ino, unsigned int d_type, ino_t *ino)
19949 +#ifdef CONFIG_AUFS_SHWH
19950 + return au_ino(sb, bindex, h_ino, d_type, ino);
19963 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
19964 + aufs_iop_nogetattr[AuIop_Last];
19966 +/* au_wr_dir flags */
19967 +#define AuWrDir_ADD_ENTRY 1
19968 +#define AuWrDir_ISDIR (1 << 1)
19969 +#define AuWrDir_TMPFILE (1 << 2)
19970 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
19971 +#define au_fset_wrdir(flags, name) \
19972 + do { (flags) |= AuWrDir_##name; } while (0)
19973 +#define au_fclr_wrdir(flags, name) \
19974 + do { (flags) &= ~AuWrDir_##name; } while (0)
19976 +struct au_wr_dir_args {
19977 + aufs_bindex_t force_btgt;
19978 + unsigned char flags;
19980 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
19981 + struct au_wr_dir_args *args);
19983 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
19984 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
19985 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
19986 + unsigned int udba, unsigned char flags);
19987 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
19988 + unsigned int udba, unsigned char flags) __must_check;
19989 +int au_do_pin(struct au_pin *pin) __must_check;
19990 +void au_unpin(struct au_pin *pin);
19991 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
19993 +#define AuIcpup_DID_CPUP 1
19994 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
19995 +#define au_fset_icpup(flags, name) \
19996 + do { (flags) |= AuIcpup_##name; } while (0)
19997 +#define au_fclr_icpup(flags, name) \
19998 + do { (flags) &= ~AuIcpup_##name; } while (0)
20000 +struct au_icpup_args {
20001 + unsigned char flags;
20002 + unsigned char pin_flags;
20003 + aufs_bindex_t btgt;
20004 + unsigned int udba;
20005 + struct au_pin pin;
20006 + struct path h_path;
20007 + struct inode *h_inode;
20010 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
20011 + struct au_icpup_args *a);
20013 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
20014 + struct path *h_path, int locked);
20017 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20018 + struct dentry *h_parent, int isdir);
20019 +int aufs_mknod(struct user_namespace *userns, struct inode *dir,
20020 + struct dentry *dentry, umode_t mode, dev_t dev);
20021 +int aufs_symlink(struct user_namespace *userns, struct inode *dir,
20022 + struct dentry *dentry, const char *symname);
20023 +int aufs_create(struct user_namespace *userns, struct inode *dir,
20024 + struct dentry *dentry, umode_t mode, bool want_excl);
20025 +struct vfsub_aopen_args;
20026 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20027 + struct vfsub_aopen_args *args);
20028 +int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
20029 + struct dentry *dentry, umode_t mode);
20030 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20031 + struct dentry *dentry);
20032 +int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
20033 + struct dentry *dentry, umode_t mode);
20036 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
20037 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
20038 + struct dentry *h_parent, int isdir);
20039 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
20040 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
20043 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
20044 +int aufs_rename(struct user_namespace *userns,
20045 + struct inode *_src_dir, struct dentry *_src_dentry,
20046 + struct inode *_dst_dir, struct dentry *_dst_dentry,
20047 + unsigned int _flags);
20050 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
20051 +void au_hiput(struct au_hinode *hinode);
20052 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
20053 + struct dentry *h_wh);
20054 +unsigned int au_hi_flags(struct inode *inode, int isdir);
20056 +/* hinode flags */
20057 +#define AuHi_XINO 1
20058 +#define AuHi_HNOTIFY (1 << 1)
20059 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
20060 +#define au_fset_hi(flags, name) \
20061 + do { (flags) |= AuHi_##name; } while (0)
20062 +#define au_fclr_hi(flags, name) \
20063 + do { (flags) &= ~AuHi_##name; } while (0)
20065 +#ifndef CONFIG_AUFS_HNOTIFY
20066 +#undef AuHi_HNOTIFY
20067 +#define AuHi_HNOTIFY 0
20070 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
20071 + struct inode *h_inode, unsigned int flags);
20073 +void au_update_iigen(struct inode *inode, int half);
20074 +void au_update_ibrange(struct inode *inode, int do_put_zero);
20076 +void au_icntnr_init_once(void *_c);
20077 +void au_hinode_init(struct au_hinode *hinode);
20078 +int au_iinfo_init(struct inode *inode);
20079 +void au_iinfo_fin(struct inode *inode);
20080 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
20082 +#ifdef CONFIG_PROC_FS
20084 +int au_plink_maint(struct super_block *sb, int flags);
20086 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
20087 +int au_plink_maint_enter(struct super_block *sb);
20088 +#ifdef CONFIG_AUFS_DEBUG
20089 +void au_plink_list(struct super_block *sb);
20091 +AuStubVoid(au_plink_list, struct super_block *sb)
20093 +int au_plink_test(struct inode *inode);
20094 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
20095 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
20096 + struct dentry *h_dentry);
20097 +void au_plink_put(struct super_block *sb, int verbose);
20098 +void au_plink_clean(struct super_block *sb, int verbose);
20099 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
20101 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
20102 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
20103 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
20104 +AuStubVoid(au_plink_list, struct super_block *sb);
20105 +AuStubInt0(au_plink_test, struct inode *inode);
20106 +AuStub(struct dentry *, au_plink_lkup, return NULL,
20107 + struct inode *inode, aufs_bindex_t bindex);
20108 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
20109 + struct dentry *h_dentry);
20110 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
20111 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
20112 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
20113 +#endif /* CONFIG_PROC_FS */
20115 +#ifdef CONFIG_AUFS_XATTR
20117 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
20118 + unsigned int verbose);
20119 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
20120 +void au_xattr_init(struct super_block *sb);
20122 +AuStubInt0(au_cpup_xattr, struct path *h_dst, struct path *h_src,
20123 + int ignore_flags, unsigned int verbose);
20124 +AuStubVoid(au_xattr_init, struct super_block *sb);
20127 +#ifdef CONFIG_FS_POSIX_ACL
20128 +struct posix_acl *aufs_get_acl(struct inode *inode, int type, bool rcu);
20129 +int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
20130 + struct posix_acl *acl, int type);
20133 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
20139 +struct au_sxattr {
20143 + const char *name;
20149 + struct posix_acl *acl;
20154 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
20155 + struct au_sxattr *arg);
20158 +/* ---------------------------------------------------------------------- */
20160 +/* lock subclass for iinfo */
20162 + AuLsc_II_CHILD, /* child first */
20163 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
20164 + AuLsc_II_CHILD3, /* copyup dirs */
20165 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
20166 + AuLsc_II_PARENT2,
20167 + AuLsc_II_PARENT3, /* copyup dirs */
20168 + AuLsc_II_NEW_CHILD
20172 + * ii_read_lock_child, ii_write_lock_child,
20173 + * ii_read_lock_child2, ii_write_lock_child2,
20174 + * ii_read_lock_child3, ii_write_lock_child3,
20175 + * ii_read_lock_parent, ii_write_lock_parent,
20176 + * ii_read_lock_parent2, ii_write_lock_parent2,
20177 + * ii_read_lock_parent3, ii_write_lock_parent3,
20178 + * ii_read_lock_new_child, ii_write_lock_new_child,
20180 +#define AuReadLockFunc(name, lsc) \
20181 +static inline void ii_read_lock_##name(struct inode *i) \
20183 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20186 +#define AuWriteLockFunc(name, lsc) \
20187 +static inline void ii_write_lock_##name(struct inode *i) \
20189 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20192 +#define AuRWLockFuncs(name, lsc) \
20193 + AuReadLockFunc(name, lsc) \
20194 + AuWriteLockFunc(name, lsc)
20196 +AuRWLockFuncs(child, CHILD);
20197 +AuRWLockFuncs(child2, CHILD2);
20198 +AuRWLockFuncs(child3, CHILD3);
20199 +AuRWLockFuncs(parent, PARENT);
20200 +AuRWLockFuncs(parent2, PARENT2);
20201 +AuRWLockFuncs(parent3, PARENT3);
20202 +AuRWLockFuncs(new_child, NEW_CHILD);
20204 +#undef AuReadLockFunc
20205 +#undef AuWriteLockFunc
20206 +#undef AuRWLockFuncs
20208 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
20209 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
20210 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
20212 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
20213 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
20214 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
20216 +/* ---------------------------------------------------------------------- */
20218 +static inline void au_icntnr_init(struct au_icntnr *c)
20220 +#ifdef CONFIG_AUFS_DEBUG
20221 + c->vfs_inode.i_mode = 0;
20225 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
20227 + unsigned int gen;
20228 + struct au_iinfo *iinfo;
20229 + struct au_iigen *iigen;
20231 + iinfo = au_ii(inode);
20232 + iigen = &iinfo->ii_generation;
20233 + spin_lock(&iigen->ig_spin);
20235 + *igflags = iigen->ig_flags;
20236 + gen = iigen->ig_generation;
20237 + spin_unlock(&iigen->ig_spin);
20242 +/* tiny test for inode number */
20243 +/* tmpfs generation is too rough */
20244 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
20246 + struct au_iinfo *iinfo;
20248 + iinfo = au_ii(inode);
20249 + AuRwMustAnyLock(&iinfo->ii_rwsem);
20250 + return !(iinfo->ii_hsb1 == h_inode->i_sb
20251 + && iinfo->ii_higen == h_inode->i_generation);
20254 +static inline void au_iigen_dec(struct inode *inode)
20256 + struct au_iinfo *iinfo;
20257 + struct au_iigen *iigen;
20259 + iinfo = au_ii(inode);
20260 + iigen = &iinfo->ii_generation;
20261 + spin_lock(&iigen->ig_spin);
20262 + iigen->ig_generation--;
20263 + spin_unlock(&iigen->ig_spin);
20266 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
20271 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
20277 +/* ---------------------------------------------------------------------- */
20279 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
20280 + aufs_bindex_t bindex)
20282 + return iinfo->ii_hinode + bindex;
20285 +static inline int au_is_bad_inode(struct inode *inode)
20287 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
20290 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
20291 + aufs_bindex_t bindex)
20293 + IiMustAnyLock(inode);
20294 + return au_hinode(au_ii(inode), bindex)->hi_id;
20297 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
20299 + IiMustAnyLock(inode);
20300 + return au_ii(inode)->ii_btop;
20303 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
20305 + IiMustAnyLock(inode);
20306 + return au_ii(inode)->ii_bbot;
20309 +static inline struct au_vdir *au_ivdir(struct inode *inode)
20311 + IiMustAnyLock(inode);
20312 + return au_ii(inode)->ii_vdir;
20315 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
20317 + IiMustAnyLock(inode);
20318 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
20321 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
20323 + IiMustWriteLock(inode);
20324 + au_ii(inode)->ii_btop = bindex;
20327 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
20329 + IiMustWriteLock(inode);
20330 + au_ii(inode)->ii_bbot = bindex;
20333 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
20335 + IiMustWriteLock(inode);
20336 + au_ii(inode)->ii_vdir = vdir;
20339 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
20341 + IiMustAnyLock(inode);
20342 + return au_hinode(au_ii(inode), bindex);
20345 +/* ---------------------------------------------------------------------- */
20347 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
20350 + return pin->parent;
20354 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
20356 + if (pin && pin->hdir)
20357 + return pin->hdir->hi_inode;
20361 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
20364 + return pin->hdir;
20368 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
20371 + pin->dentry = dentry;
20374 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
20375 + unsigned char lflag)
20379 + au_fset_pin(pin->flags, DI_LOCKED);
20381 + au_fclr_pin(pin->flags, DI_LOCKED);
20385 +#if 0 /* reserved */
20386 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
20389 + dput(pin->parent);
20390 + pin->parent = dget(parent);
20395 +/* ---------------------------------------------------------------------- */
20398 +#ifdef CONFIG_AUFS_HNOTIFY
20399 +struct au_hnotify_op {
20400 + void (*ctl)(struct au_hinode *hinode, int do_set);
20401 + int (*alloc)(struct au_hinode *hinode);
20404 + * if it returns true, the caller should free hinode->hi_notify,
20405 + * otherwise ->free() frees it.
20407 + int (*free)(struct au_hinode *hinode,
20408 + struct au_hnotify *hn) __must_check;
20410 + void (*fin)(void);
20411 + int (*init)(void);
20413 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
20414 + void (*fin_br)(struct au_branch *br);
20415 + int (*init_br)(struct au_branch *br, int perm);
20419 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
20420 +void au_hn_free(struct au_hinode *hinode);
20421 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
20422 +void au_hn_reset(struct inode *inode, unsigned int flags);
20423 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
20424 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
20425 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
20426 +int au_hnotify_init_br(struct au_branch *br, int perm);
20427 +void au_hnotify_fin_br(struct au_branch *br);
20428 +int __init au_hnotify_init(void);
20429 +void au_hnotify_fin(void);
20432 +extern const struct au_hnotify_op au_hnotify_op;
20435 +void au_hn_init(struct au_hinode *hinode)
20437 + hinode->hi_notify = NULL;
20440 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
20442 + return hinode->hi_notify;
20446 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
20447 + struct au_hinode *hinode __maybe_unused,
20448 + struct inode *inode __maybe_unused)
20449 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
20450 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
20451 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
20452 + int do_set __maybe_unused)
20453 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
20454 + unsigned int flags __maybe_unused)
20455 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
20456 + struct au_branch *br __maybe_unused,
20457 + int perm __maybe_unused)
20458 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
20459 + int perm __maybe_unused)
20460 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
20461 +AuStubInt0(__init au_hnotify_init, void)
20462 +AuStubVoid(au_hnotify_fin, void)
20463 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
20464 +#endif /* CONFIG_AUFS_HNOTIFY */
20466 +static inline void au_hn_suspend(struct au_hinode *hdir)
20468 + au_hn_ctl(hdir, /*do_set*/0);
20471 +static inline void au_hn_resume(struct au_hinode *hdir)
20473 + au_hn_ctl(hdir, /*do_set*/1);
20476 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
20478 + inode_lock(hdir->hi_inode);
20479 + au_hn_suspend(hdir);
20482 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
20483 + unsigned int sc __maybe_unused)
20485 + inode_lock_nested(hdir->hi_inode, sc);
20486 + au_hn_suspend(hdir);
20489 +#if 0 /* unused */
20490 +#include "vfsub.h"
20491 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
20494 + inode_lock_shared_nested(hdir->hi_inode, sc);
20495 + au_hn_suspend(hdir);
20499 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
20501 + au_hn_resume(hdir);
20502 + inode_unlock(hdir->hi_inode);
20505 +#endif /* __KERNEL__ */
20506 +#endif /* __AUFS_INODE_H__ */
20507 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
20508 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
20509 +++ linux/fs/aufs/ioctl.c 2022-11-05 23:02:18.965889284 +0100
20511 +// SPDX-License-Identifier: GPL-2.0
20513 + * Copyright (C) 2005-2022 Junjiro R. Okajima
20515 + * This program is free software; you can redistribute it and/or modify
20516 + * it under the terms of the GNU General Public License as published by
20517 + * the Free Software Foundation; either version 2 of the License, or
20518 + * (at your option) any later version.
20520 + * This program is distributed in the hope that it will be useful,
20521 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20522 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20523 + * GNU General Public License for more details.
20525 + * You should have received a copy of the GNU General Public License
20526 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20531 + * plink-management and readdir in userspace.
20532 + * assist the pathconf(3) wrapper library.
20534 + * File-based Hierarchical Storage Management.
20537 +#include <linux/compat.h>
20538 +#include <linux/file.h>
20541 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
20544 + aufs_bindex_t wbi, bindex, bbot;
20545 + struct file *h_file;
20546 + struct super_block *sb;
20547 + struct dentry *root;
20548 + struct au_branch *br;
20549 + struct aufs_wbr_fd wbrfd = {
20550 + .oflags = au_dir_roflags,
20553 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
20554 + | O_NOATIME | O_CLOEXEC;
20556 + AuDebugOn(wbrfd.oflags & ~valid);
20559 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
20560 + if (unlikely(err)) {
20566 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
20567 + wbrfd.oflags |= au_dir_roflags;
20568 + AuDbg("0%o\n", wbrfd.oflags);
20569 + if (unlikely(wbrfd.oflags & ~valid))
20573 + fd = get_unused_fd_flags(0);
20575 + if (unlikely(fd < 0))
20578 + h_file = ERR_PTR(-EINVAL);
20581 + sb = path->dentry->d_sb;
20582 + root = sb->s_root;
20583 + aufs_read_lock(root, AuLock_IR);
20584 + bbot = au_sbbot(sb);
20585 + if (wbrfd.brid >= 0) {
20586 + wbi = au_br_index(sb, wbrfd.brid);
20587 + if (unlikely(wbi < 0 || wbi > bbot))
20591 + h_file = ERR_PTR(-ENOENT);
20592 + br = au_sbr(sb, wbi);
20593 + if (!au_br_writable(br->br_perm)) {
20597 + bindex = wbi + 1;
20599 + for (; bindex <= bbot; bindex++) {
20600 + br = au_sbr(sb, bindex);
20601 + if (au_br_writable(br->br_perm)) {
20603 + br = au_sbr(sb, wbi);
20608 + AuDbg("wbi %d\n", wbi);
20610 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
20614 + aufs_read_unlock(root, AuLock_IR);
20615 + err = PTR_ERR(h_file);
20616 + if (IS_ERR(h_file))
20619 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
20620 + fd_install(fd, h_file);
20622 + goto out; /* success */
20625 + put_unused_fd(fd);
20631 +/* ---------------------------------------------------------------------- */
20633 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
20636 + struct dentry *dentry;
20639 + case AUFS_CTL_RDU:
20640 + case AUFS_CTL_RDU_INO:
20641 + err = au_rdu_ioctl(file, cmd, arg);
20644 + case AUFS_CTL_WBR_FD:
20645 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20648 + case AUFS_CTL_IBUSY:
20649 + err = au_ibusy_ioctl(file, arg);
20652 + case AUFS_CTL_BRINFO:
20653 + err = au_brinfo_ioctl(file, arg);
20656 + case AUFS_CTL_FHSM_FD:
20657 + dentry = file->f_path.dentry;
20658 + if (IS_ROOT(dentry))
20659 + err = au_fhsm_fd(dentry->d_sb, arg);
20665 + /* do not call the lower */
20666 + AuDbg("0x%x\n", cmd);
20674 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
20679 + case AUFS_CTL_MVDOWN:
20680 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
20683 + case AUFS_CTL_WBR_FD:
20684 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20688 + /* do not call the lower */
20689 + AuDbg("0x%x\n", cmd);
20697 +#ifdef CONFIG_COMPAT
20698 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
20699 + unsigned long arg)
20704 + case AUFS_CTL_RDU:
20705 + case AUFS_CTL_RDU_INO:
20706 + err = au_rdu_compat_ioctl(file, cmd, arg);
20709 + case AUFS_CTL_IBUSY:
20710 + err = au_ibusy_compat_ioctl(file, arg);
20713 + case AUFS_CTL_BRINFO:
20714 + err = au_brinfo_compat_ioctl(file, arg);
20718 + err = aufs_ioctl_dir(file, cmd, arg);
20725 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
20726 + unsigned long arg)
20728 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
20731 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
20732 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
20733 +++ linux/fs/aufs/i_op_add.c 2022-11-05 23:02:18.965889284 +0100
20735 +// SPDX-License-Identifier: GPL-2.0
20737 + * Copyright (C) 2005-2022 Junjiro R. Okajima
20739 + * This program is free software; you can redistribute it and/or modify
20740 + * it under the terms of the GNU General Public License as published by
20741 + * the Free Software Foundation; either version 2 of the License, or
20742 + * (at your option) any later version.
20744 + * This program is distributed in the hope that it will be useful,
20745 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20746 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20747 + * GNU General Public License for more details.
20749 + * You should have received a copy of the GNU General Public License
20750 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20754 + * inode operations (add entry)
20757 +#include <linux/iversion.h>
20761 + * final procedure of adding a new entry, except link(2).
20762 + * remove whiteout, instantiate, copyup the parent dir's times and size
20763 + * and update version.
20764 + * if it failed, re-create the removed whiteout.
20766 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
20767 + struct dentry *wh_dentry, struct dentry *dentry)
20770 + aufs_bindex_t bwh;
20771 + struct path h_path;
20772 + struct super_block *sb;
20773 + struct inode *inode, *h_dir;
20774 + struct dentry *wh;
20779 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
20780 + IMustLock(h_dir);
20781 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
20782 + bwh = au_dbwh(dentry);
20783 + h_path.dentry = wh_dentry;
20784 + h_path.mnt = au_sbr_mnt(sb, bindex);
20785 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
20787 + if (unlikely(err))
20791 + inode = au_new_inode(dentry, /*must_new*/1);
20792 + if (!IS_ERR(inode)) {
20793 + d_instantiate(dentry, inode);
20794 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
20796 + au_dir_ts(dir, bindex);
20797 + inode_inc_iversion(dir);
20798 + au_fhsm_wrote(sb, bindex, /*force*/0);
20799 + return 0; /* success */
20802 + err = PTR_ERR(inode);
20807 + /* dir inode is locked */
20808 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
20809 + rerr = PTR_ERR(wh);
20810 + if (IS_ERR(wh)) {
20811 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
20812 + dentry, err, rerr);
20821 +static int au_d_may_add(struct dentry *dentry)
20826 + if (unlikely(d_unhashed(dentry)))
20828 + if (unlikely(d_really_is_positive(dentry)))
20834 + * simple tests for the adding inode operations.
20835 + * following the checks in vfs, plus the parent-child relationship.
20837 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20838 + struct dentry *h_parent, int isdir)
20842 + struct dentry *h_dentry;
20843 + struct inode *h_inode;
20845 + err = -ENAMETOOLONG;
20846 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20849 + h_dentry = au_h_dptr(dentry, bindex);
20850 + if (d_really_is_negative(dentry)) {
20852 + if (unlikely(d_is_positive(h_dentry)))
20855 + /* rename(2) case */
20857 + if (unlikely(d_is_negative(h_dentry)))
20859 + h_inode = d_inode(h_dentry);
20860 + if (unlikely(!h_inode->i_nlink))
20863 + h_mode = h_inode->i_mode;
20866 + if (unlikely(S_ISDIR(h_mode)))
20868 + } else if (unlikely(!S_ISDIR(h_mode))) {
20875 + /* expected parent dir is locked */
20876 + if (unlikely(h_parent != h_dentry->d_parent))
20885 + * initial procedure of adding a new entry.
20886 + * prepare writable branch and the parent dir, lock it,
20887 + * and lookup whiteout for the new entry.
20889 +static struct dentry*
20890 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
20891 + struct dentry *src_dentry, struct au_pin *pin,
20892 + struct au_wr_dir_args *wr_dir_args)
20894 + struct dentry *wh_dentry, *h_parent;
20895 + struct super_block *sb;
20896 + struct au_branch *br;
20898 + unsigned int udba;
20899 + aufs_bindex_t bcpup;
20901 + AuDbg("%pd\n", dentry);
20903 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
20905 + wh_dentry = ERR_PTR(err);
20906 + if (unlikely(err < 0))
20909 + sb = dentry->d_sb;
20910 + udba = au_opt_udba(sb);
20911 + err = au_pin(pin, dentry, bcpup, udba,
20912 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20913 + wh_dentry = ERR_PTR(err);
20914 + if (unlikely(err))
20917 + h_parent = au_pinned_h_parent(pin);
20918 + if (udba != AuOpt_UDBA_NONE
20919 + && au_dbtop(dentry) == bcpup)
20920 + err = au_may_add(dentry, bcpup, h_parent,
20921 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
20922 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20923 + err = -ENAMETOOLONG;
20924 + wh_dentry = ERR_PTR(err);
20925 + if (unlikely(err))
20928 + br = au_sbr(sb, bcpup);
20930 + struct path tmp = {
20931 + .dentry = h_parent,
20932 + .mnt = au_br_mnt(br)
20934 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
20937 + wh_dentry = NULL;
20938 + if (bcpup != au_dbwh(dentry))
20939 + goto out; /* success */
20942 + * ENAMETOOLONG here means that if we allowed create such name, then it
20943 + * would not be able to removed in the future. So we don't allow such
20944 + * name here and we don't handle ENAMETOOLONG differently here.
20946 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
20949 + if (IS_ERR(wh_dentry))
20952 + return wh_dentry;
20955 +/* ---------------------------------------------------------------------- */
20957 +enum { Mknod, Symlink, Creat };
20958 +struct simple_arg {
20965 + struct vfsub_aopen_args *aopen;
20968 + const char *symname;
20977 +static int add_simple(struct inode *dir, struct dentry *dentry,
20978 + struct simple_arg *arg)
20981 + aufs_bindex_t btop;
20982 + unsigned char created;
20983 + const unsigned char try_aopen
20984 + = (arg->type == Creat && arg->u.c.try_aopen);
20985 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
20986 + struct dentry *wh_dentry, *parent;
20987 + struct inode *h_dir;
20988 + struct super_block *sb;
20989 + struct au_branch *br;
20990 + /* to reduce stack size */
20992 + struct au_dtime dt;
20993 + struct au_pin pin;
20994 + struct path h_path;
20995 + struct au_wr_dir_args wr_dir_args;
20998 + AuDbg("%pd\n", dentry);
21002 + a = kmalloc(sizeof(*a), GFP_NOFS);
21003 + if (unlikely(!a))
21005 + a->wr_dir_args.force_btgt = -1;
21006 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
21008 + parent = dentry->d_parent; /* dir inode is locked */
21009 + if (!try_aopen) {
21010 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
21011 + if (unlikely(err))
21014 + err = au_d_may_add(dentry);
21015 + if (unlikely(err))
21018 + di_write_lock_parent(parent);
21019 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
21020 + &a->pin, &a->wr_dir_args);
21021 + err = PTR_ERR(wh_dentry);
21022 + if (IS_ERR(wh_dentry))
21025 + btop = au_dbtop(dentry);
21026 + sb = dentry->d_sb;
21027 + br = au_sbr(sb, btop);
21028 + a->h_path.dentry = au_h_dptr(dentry, btop);
21029 + a->h_path.mnt = au_br_mnt(br);
21030 + h_dir = au_pinned_h_dir(&a->pin);
21031 + switch (arg->type) {
21033 + if (!try_aopen || !h_dir->i_op->atomic_open) {
21034 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
21035 + arg->u.c.want_excl);
21037 + if (!err && try_aopen)
21038 + aopen->file->f_mode |= FMODE_CREATED;
21041 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
21042 + AuDbg("err %d\n", err);
21043 + AuDbgFile(aopen->file);
21044 + created = err >= 0
21045 + && !!(aopen->file->f_mode & FMODE_CREATED);
21049 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
21053 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
21060 + if (unlikely(err < 0))
21063 + err = epilog(dir, btop, wh_dentry, dentry);
21065 + goto out_unpin; /* success */
21068 + if (created /* && d_is_positive(a->h_path.dentry) */) {
21069 + /* no delegation since it is just created */
21070 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
21073 + AuIOErr("%pd revert failure(%d, %d)\n",
21074 + dentry, err, rerr);
21077 + au_dtime_revert(&a->dt);
21079 + if (try_aopen && h_dir->i_op->atomic_open
21080 + && (aopen->file->f_mode & FMODE_OPENED))
21081 + /* aopen->file is still opened */
21082 + au_lcnt_dec(&aopen->br->br_nfiles);
21085 + au_unpin(&a->pin);
21089 + di_write_unlock(parent);
21091 + if (unlikely(err)) {
21092 + au_update_dbtop(dentry);
21096 + aufs_read_unlock(dentry, AuLock_DW);
21103 +int aufs_mknod(struct user_namespace *userns, struct inode *dir,
21104 + struct dentry *dentry, umode_t mode, dev_t dev)
21106 + struct simple_arg arg = {
21113 + return add_simple(dir, dentry, &arg);
21116 +int aufs_symlink(struct user_namespace *userns, struct inode *dir,
21117 + struct dentry *dentry, const char *symname)
21119 + struct simple_arg arg = {
21121 + .u.s.symname = symname
21123 + return add_simple(dir, dentry, &arg);
21126 +int aufs_create(struct user_namespace *userns, struct inode *dir,
21127 + struct dentry *dentry, umode_t mode, bool want_excl)
21129 + struct simple_arg arg = {
21133 + .want_excl = want_excl
21136 + return add_simple(dir, dentry, &arg);
21139 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
21140 + struct vfsub_aopen_args *aopen_args)
21142 + struct simple_arg arg = {
21145 + .mode = aopen_args->create_mode,
21146 + .want_excl = aopen_args->open_flag & O_EXCL,
21147 + .try_aopen = true,
21148 + .aopen = aopen_args
21151 + return add_simple(dir, dentry, &arg);
21154 +int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
21155 + struct dentry *dentry, umode_t mode)
21158 + aufs_bindex_t bindex;
21159 + struct super_block *sb;
21160 + struct dentry *parent, *h_parent, *h_dentry;
21161 + struct inode *h_dir, *inode;
21162 + struct vfsmount *h_mnt;
21163 + struct user_namespace *h_userns;
21164 + struct au_wr_dir_args wr_dir_args = {
21165 + .force_btgt = -1,
21166 + .flags = AuWrDir_TMPFILE
21169 + /* copy-up may happen */
21173 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21174 + if (unlikely(err))
21177 + err = au_di_init(dentry);
21178 + if (unlikely(err))
21182 + parent = d_find_any_alias(dir);
21183 + AuDebugOn(!parent);
21184 + di_write_lock_parent(parent);
21185 + if (unlikely(d_inode(parent) != dir))
21188 + err = au_digen_test(parent, au_sigen(sb));
21189 + if (unlikely(err))
21192 + bindex = au_dbtop(parent);
21193 + au_set_dbtop(dentry, bindex);
21194 + au_set_dbbot(dentry, bindex);
21195 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21197 + if (unlikely(err < 0))
21200 + err = -EOPNOTSUPP;
21201 + h_dir = au_h_iptr(dir, bindex);
21202 + if (unlikely(!h_dir->i_op->tmpfile))
21205 + h_mnt = au_sbr_mnt(sb, bindex);
21206 + err = vfsub_mnt_want_write(h_mnt);
21207 + if (unlikely(err))
21210 + h_userns = mnt_user_ns(h_mnt);
21211 + h_parent = au_h_dptr(parent, bindex);
21212 + h_dentry = vfs_tmpfile(h_userns, h_parent, mode, /*open_flag*/0);
21213 + if (IS_ERR(h_dentry)) {
21214 + err = PTR_ERR(h_dentry);
21218 + au_set_dbtop(dentry, bindex);
21219 + au_set_dbbot(dentry, bindex);
21220 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
21221 + inode = au_new_inode(dentry, /*must_new*/1);
21222 + if (IS_ERR(inode)) {
21223 + err = PTR_ERR(inode);
21224 + au_set_h_dptr(dentry, bindex, NULL);
21225 + au_set_dbtop(dentry, -1);
21226 + au_set_dbbot(dentry, -1);
21228 + if (!inode->i_nlink)
21229 + set_nlink(inode, 1);
21230 + d_tmpfile(dentry, inode);
21231 + au_di(dentry)->di_tmpfile = 1;
21233 + /* update without i_mutex */
21234 + if (au_ibtop(dir) == au_dbtop(dentry))
21235 + au_cpup_attr_timesizes(dir);
21240 + vfsub_mnt_drop_write(h_mnt);
21242 + di_write_unlock(parent);
21244 + di_write_unlock(dentry);
21245 + if (unlikely(err)) {
21246 + au_di_fin(dentry);
21247 + dentry->d_fsdata = NULL;
21250 + si_read_unlock(sb);
21252 + inode_unlock(dir);
21256 +/* ---------------------------------------------------------------------- */
21258 +struct au_link_args {
21259 + aufs_bindex_t bdst, bsrc;
21260 + struct au_pin pin;
21261 + struct path h_path;
21262 + struct dentry *src_parent, *parent;
21265 +static int au_cpup_before_link(struct dentry *src_dentry,
21266 + struct au_link_args *a)
21269 + struct dentry *h_src_dentry;
21270 + struct au_cp_generic cpg = {
21271 + .dentry = src_dentry,
21276 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
21279 + di_read_lock_parent(a->src_parent, AuLock_IR);
21280 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
21281 + if (unlikely(err))
21284 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
21285 + err = au_pin(&a->pin, src_dentry, a->bdst,
21286 + au_opt_udba(src_dentry->d_sb),
21287 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21288 + if (unlikely(err))
21291 + err = au_sio_cpup_simple(&cpg);
21292 + au_unpin(&a->pin);
21295 + di_read_unlock(a->src_parent, AuLock_IR);
21299 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
21300 + struct au_link_args *a)
21303 + unsigned char plink;
21304 + aufs_bindex_t bbot;
21305 + struct dentry *h_src_dentry;
21306 + struct inode *h_inode, *inode, *delegated;
21307 + struct super_block *sb;
21308 + struct file *h_file;
21312 + sb = src_dentry->d_sb;
21313 + inode = d_inode(src_dentry);
21314 + if (au_ibtop(inode) <= a->bdst)
21315 + h_inode = au_h_iptr(inode, a->bdst);
21316 + if (!h_inode || !h_inode->i_nlink) {
21317 + /* copyup src_dentry as the name of dentry. */
21318 + bbot = au_dbbot(dentry);
21319 + if (bbot < a->bsrc)
21320 + au_set_dbbot(dentry, a->bsrc);
21321 + au_set_h_dptr(dentry, a->bsrc,
21322 + dget(au_h_dptr(src_dentry, a->bsrc)));
21323 + dget(a->h_path.dentry);
21324 + au_set_h_dptr(dentry, a->bdst, NULL);
21325 + AuDbg("temporary d_inode...\n");
21326 + spin_lock(&dentry->d_lock);
21327 + dentry->d_inode = d_inode(src_dentry); /* tmp */
21328 + spin_unlock(&dentry->d_lock);
21329 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
21330 + if (IS_ERR(h_file))
21331 + err = PTR_ERR(h_file);
21333 + struct au_cp_generic cpg = {
21334 + .dentry = dentry,
21339 + .flags = AuCpup_KEEPLINO
21341 + err = au_sio_cpup_simple(&cpg);
21342 + au_h_open_post(dentry, a->bsrc, h_file);
21344 + dput(a->h_path.dentry);
21345 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
21347 + au_set_h_dptr(dentry, a->bdst,
21348 + a->h_path.dentry);
21350 + spin_lock(&dentry->d_lock);
21351 + dentry->d_inode = NULL; /* restore */
21352 + spin_unlock(&dentry->d_lock);
21353 + AuDbg("temporary d_inode...done\n");
21354 + au_set_h_dptr(dentry, a->bsrc, NULL);
21355 + au_set_dbbot(dentry, bbot);
21357 + /* the inode of src_dentry already exists on a.bdst branch */
21358 + h_src_dentry = d_find_alias(h_inode);
21359 + if (!h_src_dentry && au_plink_test(inode)) {
21361 + h_src_dentry = au_plink_lkup(inode, a->bdst);
21362 + err = PTR_ERR(h_src_dentry);
21363 + if (IS_ERR(h_src_dentry))
21366 + if (unlikely(d_is_negative(h_src_dentry))) {
21367 + dput(h_src_dentry);
21368 + h_src_dentry = NULL;
21372 + if (h_src_dentry) {
21373 + delegated = NULL;
21374 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
21375 + &a->h_path, &delegated);
21376 + if (unlikely(err == -EWOULDBLOCK)) {
21377 + pr_warn("cannot retry for NFSv4 delegation"
21378 + " for an internal link\n");
21381 + dput(h_src_dentry);
21383 + AuIOErr("no dentry found for hi%lu on b%d\n",
21384 + h_inode->i_ino, a->bdst);
21389 + if (!err && !plink)
21390 + au_plink_append(inode, a->bdst, a->h_path.dentry);
21397 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
21398 + struct dentry *dentry)
21401 + struct au_dtime dt;
21402 + struct au_link_args *a;
21403 + struct dentry *wh_dentry, *h_src_dentry;
21404 + struct inode *inode, *delegated;
21405 + struct super_block *sb;
21406 + struct au_wr_dir_args wr_dir_args = {
21407 + /* .force_btgt = -1, */
21408 + .flags = AuWrDir_ADD_ENTRY
21412 + inode = d_inode(src_dentry);
21413 + IMustLock(inode);
21416 + a = kzalloc(sizeof(*a), GFP_NOFS);
21417 + if (unlikely(!a))
21420 + a->parent = dentry->d_parent; /* dir inode is locked */
21421 + err = aufs_read_and_write_lock2(dentry, src_dentry,
21422 + AuLock_NOPLM | AuLock_GEN);
21423 + if (unlikely(err))
21425 + err = au_d_linkable(src_dentry);
21426 + if (unlikely(err))
21428 + err = au_d_may_add(dentry);
21429 + if (unlikely(err))
21432 + a->src_parent = dget_parent(src_dentry);
21433 + wr_dir_args.force_btgt = au_ibtop(inode);
21435 + di_write_lock_parent(a->parent);
21436 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
21437 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
21439 + err = PTR_ERR(wh_dentry);
21440 + if (IS_ERR(wh_dentry))
21444 + sb = dentry->d_sb;
21445 + a->bdst = au_dbtop(dentry);
21446 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
21447 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
21448 + a->bsrc = au_ibtop(inode);
21449 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
21450 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
21451 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
21452 + if (!h_src_dentry) {
21453 + a->bsrc = au_dbtop(src_dentry);
21454 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
21455 + AuDebugOn(!h_src_dentry);
21456 + } else if (IS_ERR(h_src_dentry)) {
21457 + err = PTR_ERR(h_src_dentry);
21462 + * aufs doesn't touch the credential so
21463 + * security_dentry_create_files_as() is unnecessary.
21465 + if (au_opt_test(au_mntflags(sb), PLINK)) {
21466 + if (a->bdst < a->bsrc
21467 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
21468 + err = au_cpup_or_link(src_dentry, dentry, a);
21470 + delegated = NULL;
21471 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
21472 + &a->h_path, &delegated);
21473 + if (unlikely(err == -EWOULDBLOCK)) {
21474 + pr_warn("cannot retry for NFSv4 delegation"
21475 + " for an internal link\n");
21479 + dput(h_src_dentry);
21482 + * copyup src_dentry to the branch we process,
21483 + * and then link(2) to it.
21485 + dput(h_src_dentry);
21486 + if (a->bdst < a->bsrc
21487 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
21488 + au_unpin(&a->pin);
21489 + di_write_unlock(a->parent);
21490 + err = au_cpup_before_link(src_dentry, a);
21491 + di_write_lock_parent(a->parent);
21493 + err = au_pin(&a->pin, dentry, a->bdst,
21495 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21496 + if (unlikely(err))
21500 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
21502 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
21503 + delegated = NULL;
21504 + err = vfsub_link(h_src_dentry,
21505 + au_pinned_h_dir(&a->pin),
21506 + &a->h_path, &delegated);
21507 + if (unlikely(err == -EWOULDBLOCK)) {
21508 + pr_warn("cannot retry"
21509 + " for NFSv4 delegation"
21510 + " for an internal link\n");
21516 + if (unlikely(err))
21520 + a->h_path.dentry = wh_dentry;
21521 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
21523 + if (unlikely(err))
21527 + au_dir_ts(dir, a->bdst);
21528 + inode_inc_iversion(dir);
21529 + inc_nlink(inode);
21530 + inode->i_ctime = dir->i_ctime;
21531 + d_instantiate(dentry, au_igrab(inode));
21532 + if (d_unhashed(a->h_path.dentry))
21533 + /* some filesystem calls d_drop() */
21535 + /* some filesystems consume an inode even hardlink */
21536 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
21537 + goto out_unpin; /* success */
21540 + /* no delegation since it is just created */
21541 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
21542 + /*delegated*/NULL, /*force*/0);
21543 + if (unlikely(rerr)) {
21544 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
21547 + au_dtime_revert(&dt);
21549 + au_unpin(&a->pin);
21553 + di_write_unlock(a->parent);
21554 + dput(a->src_parent);
21556 + if (unlikely(err)) {
21557 + au_update_dbtop(dentry);
21560 + aufs_read_and_write_unlock2(dentry, src_dentry);
21568 +int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
21569 + struct dentry *dentry, umode_t mode)
21572 + aufs_bindex_t bindex;
21573 + unsigned char diropq;
21574 + struct path h_path;
21575 + struct dentry *wh_dentry, *parent, *opq_dentry;
21576 + struct inode *h_inode;
21577 + struct super_block *sb;
21579 + struct au_pin pin;
21580 + struct au_dtime dt;
21581 + } *a; /* reduce the stack usage */
21582 + struct au_wr_dir_args wr_dir_args = {
21583 + .force_btgt = -1,
21584 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
21590 + a = kmalloc(sizeof(*a), GFP_NOFS);
21591 + if (unlikely(!a))
21594 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
21595 + if (unlikely(err))
21597 + err = au_d_may_add(dentry);
21598 + if (unlikely(err))
21601 + parent = dentry->d_parent; /* dir inode is locked */
21602 + di_write_lock_parent(parent);
21603 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
21604 + &a->pin, &wr_dir_args);
21605 + err = PTR_ERR(wh_dentry);
21606 + if (IS_ERR(wh_dentry))
21609 + sb = dentry->d_sb;
21610 + bindex = au_dbtop(dentry);
21611 + h_path.dentry = au_h_dptr(dentry, bindex);
21612 + h_path.mnt = au_sbr_mnt(sb, bindex);
21613 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
21614 + if (unlikely(err))
21617 + /* make the dir opaque */
21619 + h_inode = d_inode(h_path.dentry);
21621 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
21622 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21623 + opq_dentry = au_diropq_create(dentry, bindex);
21624 + inode_unlock(h_inode);
21625 + err = PTR_ERR(opq_dentry);
21626 + if (IS_ERR(opq_dentry))
21628 + dput(opq_dentry);
21632 + err = epilog(dir, bindex, wh_dentry, dentry);
21635 + goto out_unpin; /* success */
21640 + AuLabel(revert opq);
21641 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21642 + rerr = au_diropq_remove(dentry, bindex);
21643 + inode_unlock(h_inode);
21645 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
21646 + dentry, err, rerr);
21652 + AuLabel(revert dir);
21653 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
21655 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
21656 + dentry, err, rerr);
21659 + au_dtime_revert(&a->dt);
21661 + au_unpin(&a->pin);
21664 + di_write_unlock(parent);
21666 + if (unlikely(err)) {
21667 + au_update_dbtop(dentry);
21670 + aufs_read_unlock(dentry, AuLock_DW);
21676 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
21677 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
21678 +++ linux/fs/aufs/i_op.c 2022-11-05 23:02:18.965889284 +0100
21680 +// SPDX-License-Identifier: GPL-2.0
21682 + * Copyright (C) 2005-2022 Junjiro R. Okajima
21684 + * This program is free software; you can redistribute it and/or modify
21685 + * it under the terms of the GNU General Public License as published by
21686 + * the Free Software Foundation; either version 2 of the License, or
21687 + * (at your option) any later version.
21689 + * This program is distributed in the hope that it will be useful,
21690 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21691 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21692 + * GNU General Public License for more details.
21694 + * You should have received a copy of the GNU General Public License
21695 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21699 + * inode operations (except add/del/rename)
21702 +#include <linux/device_cgroup.h>
21703 +#include <linux/fs_stack.h>
21704 +#include <linux/iversion.h>
21705 +#include <linux/security.h>
21708 +static int h_permission(struct inode *h_inode, int mask,
21709 + struct path *h_path, int brperm)
21712 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
21713 + struct user_namespace *h_userns;
21716 + if (write_mask && IS_IMMUTABLE(h_inode))
21720 + if (((mask & MAY_EXEC)
21721 + && S_ISREG(h_inode->i_mode)
21722 + && (path_noexec(h_path)
21723 + || !(h_inode->i_mode & 0111))))
21727 + * - skip the lower fs test in the case of write to ro branch.
21728 + * - nfs dir permission write check is optimized, but a policy for
21729 + * link/rename requires a real check.
21730 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
21731 + * in this case, generic_permission() returns -EOPNOTSUPP.
21733 + h_userns = mnt_user_ns(h_path->mnt);
21734 + if ((write_mask && !au_br_writable(brperm))
21735 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
21736 + && write_mask && !(mask & MAY_READ))
21737 + || !h_inode->i_op->permission) {
21738 + /* AuLabel(generic_permission); */
21739 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
21740 + err = generic_permission(h_userns, h_inode, mask);
21741 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
21742 + err = h_inode->i_op->permission(h_userns, h_inode,
21746 + /* AuLabel(h_inode->permission); */
21747 + err = h_inode->i_op->permission(h_userns, h_inode, mask);
21752 + err = devcgroup_inode_permission(h_inode, mask);
21754 + err = security_inode_permission(h_inode, mask);
21760 +static int aufs_permission(struct user_namespace *userns, struct inode *inode,
21764 + aufs_bindex_t bindex, bbot;
21765 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
21766 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
21767 + struct inode *h_inode;
21768 + struct super_block *sb;
21769 + struct au_branch *br;
21771 + /* todo: support rcu-walk? */
21772 + if (mask & MAY_NOT_BLOCK)
21775 + sb = inode->i_sb;
21776 + si_read_lock(sb, AuLock_FLUSH);
21777 + ii_read_lock_child(inode);
21778 +#if 0 /* reserved for future use */
21780 + * This test may be rather 'too much' since the test is essentially done
21781 + * in the aufs_lookup(). Theoretically it is possible that the inode
21782 + * generation doesn't match to the superblock's here. But it isn't a
21783 + * big deal I suppose.
21785 + err = au_iigen_test(inode, au_sigen(sb));
21786 + if (unlikely(err))
21792 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
21793 + err = au_busy_or_stale();
21794 + h_inode = au_h_iptr(inode, au_ibtop(inode));
21795 + if (unlikely(!h_inode
21796 + || (h_inode->i_mode & S_IFMT)
21797 + != (inode->i_mode & S_IFMT)))
21801 + bindex = au_ibtop(inode);
21802 + br = au_sbr(sb, bindex);
21803 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
21806 + && !special_file(h_inode->i_mode)) {
21807 + /* test whether the upper writable branch exists */
21809 + for (; bindex >= 0; bindex--)
21810 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
21818 + /* non-write to dir */
21820 + bbot = au_ibbot(inode);
21821 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
21822 + h_inode = au_h_iptr(inode, bindex);
21824 + err = au_busy_or_stale();
21825 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
21828 + br = au_sbr(sb, bindex);
21829 + err = h_permission(h_inode, mask, &br->br_path,
21835 + ii_read_unlock(inode);
21836 + si_read_unlock(sb);
21840 +/* ---------------------------------------------------------------------- */
21842 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
21843 + unsigned int flags)
21845 + struct dentry *ret, *parent;
21846 + struct inode *inode;
21847 + struct super_block *sb;
21848 + int err, npositive;
21852 + /* todo: support rcu-walk? */
21853 + ret = ERR_PTR(-ECHILD);
21854 + if (flags & LOOKUP_RCU)
21857 + ret = ERR_PTR(-ENAMETOOLONG);
21858 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
21862 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21863 + ret = ERR_PTR(err);
21864 + if (unlikely(err))
21867 + err = au_di_init(dentry);
21868 + ret = ERR_PTR(err);
21869 + if (unlikely(err))
21873 + npositive = 0; /* suppress a warning */
21874 + parent = dentry->d_parent; /* dir inode is locked */
21875 + di_read_lock_parent(parent, AuLock_IR);
21876 + err = au_alive_dir(parent);
21878 + err = au_digen_test(parent, au_sigen(sb));
21880 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
21881 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
21882 + AuLkup_ALLOW_NEG);
21885 + di_read_unlock(parent, AuLock_IR);
21886 + ret = ERR_PTR(err);
21887 + if (unlikely(err < 0))
21891 + inode = au_new_inode(dentry, /*must_new*/0);
21892 + if (IS_ERR(inode)) {
21893 + ret = (void *)inode;
21900 + atomic_inc(&inode->i_count);
21901 + ret = d_splice_alias(inode, dentry);
21902 +#if 0 /* reserved for future use */
21903 + if (unlikely(d_need_lookup(dentry))) {
21904 + spin_lock(&dentry->d_lock);
21905 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
21906 + spin_unlock(&dentry->d_lock);
21910 + if (!IS_ERR(ret)) {
21912 + if (ret && ret != dentry)
21913 + ii_write_unlock(inode);
21915 + ii_write_unlock(inode);
21922 + di_write_unlock(dentry);
21924 + si_read_unlock(sb);
21929 +/* ---------------------------------------------------------------------- */
21932 + * very dirty and complicated aufs ->atomic_open().
21933 + * aufs_atomic_open()
21934 + * + au_aopen_or_create()
21936 + * + vfsub_atomic_open()
21937 + * + branch fs ->atomic_open()
21938 + * may call the actual 'open' for h_file
21939 + * + inc br_nfiles only if opened
21940 + * + au_aopen_no_open() or au_aopen_do_open()
21942 + * au_aopen_do_open()
21943 + * + finish_open()
21944 + * + au_do_aopen()
21945 + * + au_do_open() the body of all 'open'
21946 + * + au_do_open_nondir()
21947 + * set the passed h_file
21949 + * au_aopen_no_open()
21950 + * + finish_no_open()
21953 +struct aopen_node {
21954 + struct hlist_bl_node hblist;
21955 + struct file *file, *h_file;
21958 +static int au_do_aopen(struct inode *inode, struct file *file)
21960 + struct hlist_bl_head *aopen;
21961 + struct hlist_bl_node *pos;
21962 + struct aopen_node *node;
21963 + struct au_do_open_args args = {
21965 + .open = au_do_open_nondir
21968 + aopen = &au_sbi(inode->i_sb)->si_aopen;
21969 + hlist_bl_lock(aopen);
21970 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
21971 + if (node->file == file) {
21972 + args.h_file = node->h_file;
21975 + hlist_bl_unlock(aopen);
21976 + /* AuDebugOn(!args.h_file); */
21978 + return au_do_open(file, &args);
21981 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
21982 + struct aopen_node *aopen_node)
21985 + struct hlist_bl_head *aopen;
21988 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
21989 + au_hbl_add(&aopen_node->hblist, aopen);
21990 + err = finish_open(file, dentry, au_do_aopen);
21991 + au_hbl_del(&aopen_node->hblist, aopen);
21992 + /* AuDbgFile(file); */
21993 + AuDbg("%pd%s%s\n", dentry,
21994 + (file->f_mode & FMODE_CREATED) ? " created" : "",
21995 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
22001 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
22007 + err = finish_no_open(file, dentry);
22013 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
22014 + struct file *file, unsigned int open_flag,
22015 + umode_t create_mode)
22017 + int err, did_open;
22018 + unsigned int lkup_flags;
22019 + aufs_bindex_t bindex;
22020 + struct super_block *sb;
22021 + struct dentry *parent, *d;
22022 + struct vfsub_aopen_args args = {
22023 + .open_flag = open_flag,
22024 + .create_mode = create_mode
22026 + struct aopen_node aopen_node = {
22031 + AuDbg("open_flag 0%o\n", open_flag);
22032 + AuDbgDentry(dentry);
22035 + if (!au_di(dentry)) {
22036 + lkup_flags = LOOKUP_OPEN;
22037 + if (open_flag & O_CREAT)
22038 + lkup_flags |= LOOKUP_CREATE;
22039 + d = aufs_lookup(dir, dentry, lkup_flags);
22041 + err = PTR_ERR(d);
22046 + * obsoleted dentry found.
22047 + * another error will be returned later.
22053 + AuDbgDentry(dentry);
22056 + if (d_is_positive(dentry)
22057 + || d_unhashed(dentry)
22058 + || d_unlinked(dentry)
22059 + || !(open_flag & O_CREAT)) {
22060 + err = au_aopen_no_open(file, dentry);
22061 + goto out; /* success */
22064 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22065 + if (unlikely(err))
22068 + sb = dentry->d_sb;
22069 + parent = dentry->d_parent; /* dir is locked */
22070 + di_write_lock_parent(parent);
22071 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
22072 + if (unlikely(err < 0))
22075 + AuDbgDentry(dentry);
22076 + if (d_is_positive(dentry)) {
22077 + err = au_aopen_no_open(file, dentry);
22078 + goto out_parent; /* success */
22081 + args.file = alloc_empty_file(file->f_flags, current_cred());
22082 + err = PTR_ERR(args.file);
22083 + if (IS_ERR(args.file))
22086 + bindex = au_dbtop(dentry);
22087 + err = au_aopen_or_create(dir, dentry, &args);
22089 + AuDbgFile(args.file);
22090 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
22091 + did_open = !!(args.file->f_mode & FMODE_OPENED);
22094 + args.file = NULL;
22096 + di_write_unlock(parent);
22097 + di_write_unlock(dentry);
22098 + if (unlikely(err < 0)) {
22105 + err = au_aopen_no_open(file, dentry);
22107 + aopen_node.h_file = args.file;
22108 + err = au_aopen_do_open(file, dentry, &aopen_node);
22110 + if (unlikely(err < 0)) {
22114 + au_lcnt_dec(&args.br->br_nfiles);
22116 + goto out_sb; /* success */
22119 + di_write_unlock(parent);
22120 + di_write_unlock(dentry);
22122 + si_read_unlock(sb);
22130 +/* ---------------------------------------------------------------------- */
22132 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
22133 + const unsigned char add_entry, aufs_bindex_t bcpup,
22134 + aufs_bindex_t btop)
22137 + struct dentry *h_parent;
22138 + struct inode *h_dir;
22141 + IMustLock(d_inode(parent));
22143 + di_write_lock_parent(parent);
22146 + if (!au_h_dptr(parent, bcpup)) {
22147 + if (btop > bcpup)
22148 + err = au_cpup_dirs(dentry, bcpup);
22149 + else if (btop < bcpup)
22150 + err = au_cpdown_dirs(dentry, bcpup);
22154 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
22155 + h_parent = au_h_dptr(parent, bcpup);
22156 + h_dir = d_inode(h_parent);
22157 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
22158 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
22159 + /* todo: no unlock here */
22160 + inode_unlock_shared(h_dir);
22162 + AuDbg("bcpup %d\n", bcpup);
22164 + if (d_really_is_negative(dentry))
22165 + au_set_h_dptr(dentry, btop, NULL);
22166 + au_update_dbrange(dentry, /*do_put_zero*/0);
22171 + di_write_unlock(parent);
22173 + err = bcpup; /* success */
22180 + * decide the branch and the parent dir where we will create a new entry.
22181 + * returns new bindex or an error.
22182 + * copyup the parent dir if needed.
22184 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
22185 + struct au_wr_dir_args *args)
22188 + unsigned int flags;
22189 + aufs_bindex_t bcpup, btop, src_btop;
22190 + const unsigned char add_entry
22191 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
22192 + | au_ftest_wrdir(args->flags, TMPFILE);
22193 + struct super_block *sb;
22194 + struct dentry *parent;
22195 + struct au_sbinfo *sbinfo;
22197 + sb = dentry->d_sb;
22198 + sbinfo = au_sbi(sb);
22199 + parent = dget_parent(dentry);
22200 + btop = au_dbtop(dentry);
22202 + if (args->force_btgt < 0) {
22203 + if (src_dentry) {
22204 + src_btop = au_dbtop(src_dentry);
22205 + if (src_btop < btop)
22206 + bcpup = src_btop;
22207 + } else if (add_entry) {
22209 + if (au_ftest_wrdir(args->flags, ISDIR))
22210 + au_fset_wbr(flags, DIR);
22211 + err = AuWbrCreate(sbinfo, dentry, flags);
22215 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
22217 + err = AuWbrCopyup(sbinfo, dentry);
22219 + if (!IS_ROOT(dentry)) {
22220 + di_read_lock_parent(parent, !AuLock_IR);
22221 + err = AuWbrCopyup(sbinfo, dentry);
22222 + di_read_unlock(parent, !AuLock_IR);
22224 + err = AuWbrCopyup(sbinfo, dentry);
22227 + if (unlikely(err < 0))
22231 + bcpup = args->force_btgt;
22232 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
22235 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
22237 + if (bcpup == btop)
22238 + goto out; /* success */
22240 + /* copyup the new parent into the branch we process */
22241 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
22243 + if (d_really_is_negative(dentry)) {
22244 + au_set_h_dptr(dentry, btop, NULL);
22245 + au_set_dbtop(dentry, bcpup);
22246 + au_set_dbbot(dentry, bcpup);
22248 + AuDebugOn(add_entry
22249 + && !au_ftest_wrdir(args->flags, TMPFILE)
22250 + && !au_h_dptr(dentry, bcpup));
22258 +/* ---------------------------------------------------------------------- */
22260 +void au_pin_hdir_unlock(struct au_pin *p)
22263 + au_hn_inode_unlock(p->hdir);
22266 +int au_pin_hdir_lock(struct au_pin *p)
22274 + /* even if an error happens later, keep this lock */
22275 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
22278 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
22283 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
22284 + p->h_parent, p->br);
22290 +int au_pin_hdir_relock(struct au_pin *p)
22293 + struct inode *h_i;
22294 + struct dentry *h_d[] = {
22299 + err = au_pin_hdir_lock(p);
22300 + if (unlikely(err))
22303 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
22306 + if (d_is_positive(h_d[i])) {
22307 + h_i = d_inode(h_d[i]);
22308 + err = !h_i->i_nlink;
22316 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
22318 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
22321 +void au_pin_hdir_acquire_nest(struct au_pin *p)
22324 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
22325 + p->lsc_hi, 0, NULL, _RET_IP_);
22326 + au_pin_hdir_set_owner(p, current);
22330 +void au_pin_hdir_release(struct au_pin *p)
22333 + au_pin_hdir_set_owner(p, p->task);
22334 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
22338 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
22340 + if (pin && pin->parent)
22341 + return au_h_dptr(pin->parent, pin->bindex);
22345 +void au_unpin(struct au_pin *p)
22348 + au_pin_hdir_unlock(p);
22349 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
22350 + vfsub_mnt_drop_write(p->h_mnt);
22354 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22355 + di_read_unlock(p->parent, AuLock_IR);
22356 + iput(p->hdir->hi_inode);
22358 + p->parent = NULL;
22361 + /* do not clear p->task */
22364 +int au_do_pin(struct au_pin *p)
22367 + struct super_block *sb;
22368 + struct inode *h_dir;
22371 + sb = p->dentry->d_sb;
22372 + p->br = au_sbr(sb, p->bindex);
22373 + if (IS_ROOT(p->dentry)) {
22374 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
22375 + p->h_mnt = au_br_mnt(p->br);
22376 + err = vfsub_mnt_want_write(p->h_mnt);
22377 + if (unlikely(err)) {
22378 + au_fclr_pin(p->flags, MNT_WRITE);
22385 + p->h_dentry = NULL;
22386 + if (p->bindex <= au_dbbot(p->dentry))
22387 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
22389 + p->parent = dget_parent(p->dentry);
22390 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22391 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
22394 + p->h_parent = au_h_dptr(p->parent, p->bindex);
22395 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
22397 + h_dir = p->hdir->hi_inode;
22401 + * if DI_LOCKED is not set, then p->parent may be different
22402 + * and h_parent can be NULL.
22404 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
22406 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22407 + di_read_unlock(p->parent, AuLock_IR);
22409 + p->parent = NULL;
22413 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
22414 + p->h_mnt = au_br_mnt(p->br);
22415 + err = vfsub_mnt_want_write(p->h_mnt);
22416 + if (unlikely(err)) {
22417 + au_fclr_pin(p->flags, MNT_WRITE);
22418 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22419 + di_read_unlock(p->parent, AuLock_IR);
22421 + p->parent = NULL;
22427 + err = au_pin_hdir_lock(p);
22429 + goto out; /* success */
22434 + pr_err("err %d\n", err);
22435 + err = au_busy_or_stale();
22440 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
22441 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
22442 + unsigned int udba, unsigned char flags)
22444 + p->dentry = dentry;
22446 + p->lsc_di = lsc_di;
22447 + p->lsc_hi = lsc_hi;
22448 + p->flags = flags;
22449 + p->bindex = bindex;
22451 + p->parent = NULL;
22455 + p->h_dentry = NULL;
22456 + p->h_parent = NULL;
22458 + p->task = current;
22461 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
22462 + unsigned int udba, unsigned char flags)
22464 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
22466 + return au_do_pin(pin);
22469 +/* ---------------------------------------------------------------------- */
22472 + * ->setattr() and ->getattr() are called in various cases.
22473 + * chmod, stat: dentry is revalidated.
22474 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
22476 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
22478 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
22479 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
22482 + struct dentry *parent;
22485 + if (au_digen_test(dentry, sigen)) {
22486 + parent = dget_parent(dentry);
22487 + di_read_lock_parent(parent, AuLock_IR);
22488 + err = au_refresh_dentry(dentry, parent);
22489 + di_read_unlock(parent, AuLock_IR);
22497 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
22498 + struct au_icpup_args *a)
22502 + aufs_bindex_t btop, ibtop;
22503 + struct dentry *hi_wh, *parent;
22504 + struct inode *inode;
22505 + struct au_wr_dir_args wr_dir_args = {
22506 + .force_btgt = -1,
22510 + if (d_is_dir(dentry))
22511 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
22512 + /* plink or hi_wh() case */
22513 + btop = au_dbtop(dentry);
22514 + inode = d_inode(dentry);
22515 + ibtop = au_ibtop(inode);
22516 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
22517 + wr_dir_args.force_btgt = ibtop;
22518 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
22519 + if (unlikely(err < 0))
22523 + au_fset_icpup(a->flags, DID_CPUP);
22526 + a->pin_flags = AuPin_MNT_WRITE;
22528 + if (!IS_ROOT(dentry)) {
22529 + au_fset_pin(a->pin_flags, DI_LOCKED);
22530 + parent = dget_parent(dentry);
22531 + di_write_lock_parent(parent);
22534 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
22535 + if (unlikely(err))
22539 + a->h_path.dentry = au_h_dptr(dentry, btop);
22540 + a->h_inode = d_inode(a->h_path.dentry);
22541 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
22542 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
22543 + if (ia->ia_size < i_size_read(a->h_inode))
22544 + sz = ia->ia_size;
22545 + inode_unlock_shared(a->h_inode);
22549 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
22550 + hi_wh = au_hi_wh(inode, a->btgt);
22552 + struct au_cp_generic cpg = {
22553 + .dentry = dentry,
22559 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
22560 + if (unlikely(err))
22562 + hi_wh = au_hi_wh(inode, a->btgt);
22563 + /* todo: revalidate hi_wh? */
22568 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
22569 + di_downgrade_lock(parent, AuLock_IR);
22573 + if (!au_ftest_icpup(a->flags, DID_CPUP))
22574 + goto out; /* success */
22576 + if (!d_unhashed(dentry)) {
22577 + struct au_cp_generic cpg = {
22578 + .dentry = dentry,
22583 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22585 + err = au_sio_cpup_simple(&cpg);
22587 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
22588 + } else if (!hi_wh)
22589 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
22591 + a->h_path.dentry = hi_wh; /* do not dget here */
22594 + a->h_inode = d_inode(a->h_path.dentry);
22596 + goto out; /* success */
22597 + au_unpin(&a->pin);
22600 + di_write_unlock(parent);
22605 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
22609 +static int aufs_setattr(struct user_namespace *userns, struct dentry *dentry,
22610 + struct iattr *ia)
22613 + struct inode *inode, *delegated;
22614 + struct super_block *sb;
22615 + struct file *file;
22616 + struct au_icpup_args *a;
22617 + struct user_namespace *h_userns;
22619 + inode = d_inode(dentry);
22620 + IMustLock(inode);
22622 + err = setattr_prepare(userns, dentry, ia);
22623 + if (unlikely(err))
22627 + a = kzalloc(sizeof(*a), GFP_NOFS);
22628 + if (unlikely(!a))
22631 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
22632 + ia->ia_valid &= ~ATTR_MODE;
22635 + sb = dentry->d_sb;
22636 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22637 + if (unlikely(err))
22640 + if (ia->ia_valid & ATTR_FILE) {
22641 + /* currently ftruncate(2) only */
22642 + AuDebugOn(!d_is_reg(dentry));
22643 + file = ia->ia_file;
22644 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
22646 + if (unlikely(err))
22648 + ia->ia_file = au_hf_top(file);
22649 + a->udba = AuOpt_UDBA_NONE;
22651 + /* fchmod() doesn't pass ia_file */
22652 + a->udba = au_opt_udba(sb);
22653 + di_write_lock_child(dentry);
22654 + /* no d_unlinked(), to set UDBA_NONE for root */
22655 + if (d_unhashed(dentry))
22656 + a->udba = AuOpt_UDBA_NONE;
22657 + if (a->udba != AuOpt_UDBA_NONE) {
22658 + AuDebugOn(IS_ROOT(dentry));
22659 + err = au_reval_for_attr(dentry, au_sigen(sb));
22660 + if (unlikely(err))
22665 + err = au_pin_and_icpup(dentry, ia, a);
22666 + if (unlikely(err < 0))
22668 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
22669 + ia->ia_file = NULL;
22670 + ia->ia_valid &= ~ATTR_FILE;
22673 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
22674 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
22675 + == (ATTR_MODE | ATTR_CTIME)) {
22676 + err = security_path_chmod(&a->h_path, ia->ia_mode);
22677 + if (unlikely(err))
22679 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
22680 + && (ia->ia_valid & ATTR_CTIME)) {
22681 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
22682 + if (unlikely(err))
22686 + if (ia->ia_valid & ATTR_SIZE) {
22689 + if (ia->ia_size < i_size_read(inode))
22691 + truncate_setsize(inode, ia->ia_size);
22694 + if (ia->ia_valid & ATTR_FILE)
22696 + inode_unlock(a->h_inode);
22697 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
22698 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
22700 + delegated = NULL;
22702 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
22704 + err = break_deleg_wait(&delegated);
22712 + * regardless aufs 'acl' option setting.
22713 + * why don't all acl-aware fs call this func from their ->setattr()?
22715 + if (!err && (ia->ia_valid & ATTR_MODE)) {
22716 + h_userns = mnt_user_ns(a->h_path.mnt);
22717 + err = vfsub_acl_chmod(h_userns, a->h_inode, ia->ia_mode);
22720 + au_cpup_attr_changeable(inode);
22723 + inode_unlock(a->h_inode);
22724 + au_unpin(&a->pin);
22725 + if (unlikely(err))
22726 + au_update_dbtop(dentry);
22728 + di_write_unlock(dentry);
22730 + fi_write_unlock(file);
22731 + ia->ia_file = file;
22732 + ia->ia_valid |= ATTR_FILE;
22735 + si_read_unlock(sb);
22743 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
22744 +static int au_h_path_to_set_attr(struct dentry *dentry,
22745 + struct au_icpup_args *a, struct path *h_path)
22748 + struct super_block *sb;
22750 + sb = dentry->d_sb;
22751 + a->udba = au_opt_udba(sb);
22752 + /* no d_unlinked(), to set UDBA_NONE for root */
22753 + if (d_unhashed(dentry))
22754 + a->udba = AuOpt_UDBA_NONE;
22755 + if (a->udba != AuOpt_UDBA_NONE) {
22756 + AuDebugOn(IS_ROOT(dentry));
22757 + err = au_reval_for_attr(dentry, au_sigen(sb));
22758 + if (unlikely(err))
22761 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
22762 + if (unlikely(err < 0))
22765 + h_path->dentry = a->h_path.dentry;
22766 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
22772 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
22773 + struct au_sxattr *arg)
22776 + struct path h_path;
22777 + struct super_block *sb;
22778 + struct au_icpup_args *a;
22779 + struct inode *h_inode;
22780 + struct user_namespace *h_userns;
22782 + IMustLock(inode);
22785 + a = kzalloc(sizeof(*a), GFP_NOFS);
22786 + if (unlikely(!a))
22789 + sb = dentry->d_sb;
22790 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22791 + if (unlikely(err))
22794 + h_path.dentry = NULL; /* silence gcc */
22795 + di_write_lock_child(dentry);
22796 + err = au_h_path_to_set_attr(dentry, a, &h_path);
22797 + if (unlikely(err))
22799 + h_userns = mnt_user_ns(h_path.mnt);
22801 + inode_unlock(a->h_inode);
22802 + switch (arg->type) {
22803 + case AU_XATTR_SET:
22804 + AuDebugOn(d_is_negative(h_path.dentry));
22805 + err = vfsub_setxattr(h_userns, h_path.dentry,
22806 + arg->u.set.name, arg->u.set.value,
22807 + arg->u.set.size, arg->u.set.flags);
22810 + err = -EOPNOTSUPP;
22811 + h_inode = d_inode(h_path.dentry);
22812 + if (h_inode->i_op->set_acl) {
22813 + /* this will call posix_acl_update_mode */
22814 + err = h_inode->i_op->set_acl(h_userns, h_inode,
22815 + arg->u.acl_set.acl,
22816 + arg->u.acl_set.type);
22821 + au_cpup_attr_timesizes(inode);
22823 + au_unpin(&a->pin);
22824 + if (unlikely(err))
22825 + au_update_dbtop(dentry);
22828 + di_write_unlock(dentry);
22829 + si_read_unlock(sb);
22838 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
22839 + unsigned int nlink)
22843 + inode->i_mode = st->mode;
22844 + /* don't i_[ug]id_write() here */
22845 + inode->i_uid = st->uid;
22846 + inode->i_gid = st->gid;
22847 + inode->i_atime = st->atime;
22848 + inode->i_mtime = st->mtime;
22849 + inode->i_ctime = st->ctime;
22851 + au_cpup_attr_nlink(inode, /*force*/0);
22852 + if (S_ISDIR(inode->i_mode)) {
22853 + n = inode->i_nlink;
22856 + smp_mb(); /* for i_nlink */
22857 + /* 0 can happen */
22858 + set_nlink(inode, n);
22861 + spin_lock(&inode->i_lock);
22862 + inode->i_blocks = st->blocks;
22863 + i_size_write(inode, st->size);
22864 + spin_unlock(&inode->i_lock);
22868 + * common routine for aufs_getattr() and au_getxattr().
22869 + * returns zero or negative (an error).
22870 + * @dentry will be read-locked in success.
22872 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
22873 + struct path *h_path, int locked)
22876 + unsigned int mnt_flags, sigen;
22877 + unsigned char udba_none;
22878 + aufs_bindex_t bindex;
22879 + struct super_block *sb, *h_sb;
22881 + h_path->mnt = NULL;
22882 + h_path->dentry = NULL;
22885 + sb = dentry->d_sb;
22886 + mnt_flags = au_mntflags(sb);
22887 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
22889 + if (unlikely(locked))
22890 + goto body; /* skip locking dinfo */
22892 + /* support fstat(2) */
22893 + if (!d_unlinked(dentry) && !udba_none) {
22894 + sigen = au_sigen(sb);
22895 + err = au_digen_test(dentry, sigen);
22897 + di_read_lock_child(dentry, AuLock_IR);
22898 + err = au_dbrange_test(dentry);
22899 + if (unlikely(err)) {
22900 + di_read_unlock(dentry, AuLock_IR);
22904 + AuDebugOn(IS_ROOT(dentry));
22905 + di_write_lock_child(dentry);
22906 + err = au_dbrange_test(dentry);
22908 + err = au_reval_for_attr(dentry, sigen);
22910 + di_downgrade_lock(dentry, AuLock_IR);
22912 + di_write_unlock(dentry);
22917 + di_read_lock_child(dentry, AuLock_IR);
22921 + inode = d_inode(dentry);
22922 + if (unlikely(!inode))
22925 + bindex = au_ibtop(inode);
22926 + h_path->mnt = au_sbr_mnt(sb, bindex);
22927 + h_sb = h_path->mnt->mnt_sb;
22929 + && !au_test_fs_bad_iattr(h_sb)
22931 + goto out; /* success */
22933 + if (au_dbtop(dentry) == bindex)
22934 + h_path->dentry = au_h_dptr(dentry, bindex);
22935 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
22936 + h_path->dentry = au_plink_lkup(inode, bindex);
22937 + if (IS_ERR(h_path->dentry))
22938 + /* pretending success */
22939 + h_path->dentry = NULL;
22941 + dput(h_path->dentry);
22948 +static int aufs_getattr(struct user_namespace *userns, const struct path *path,
22949 + struct kstat *st, u32 request, unsigned int query)
22952 + unsigned char positive;
22953 + struct path h_path;
22954 + struct dentry *dentry;
22955 + struct inode *inode;
22956 + struct super_block *sb;
22958 + dentry = path->dentry;
22959 + inode = d_inode(dentry);
22960 + sb = dentry->d_sb;
22961 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22962 + if (unlikely(err))
22964 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
22966 + if (unlikely(err))
22968 + if (unlikely(!h_path.dentry))
22969 + /* illegally overlapped or something */
22970 + goto out_fill; /* pretending success */
22972 + positive = d_is_positive(h_path.dentry);
22974 + /* no vfsub version */
22975 + err = vfs_getattr(&h_path, st, request, query);
22978 + au_refresh_iattr(inode, st,
22979 + d_inode(h_path.dentry)->i_nlink);
22980 + goto out_fill; /* success */
22986 + generic_fillattr(userns, inode, st);
22988 + di_read_unlock(dentry, AuLock_IR);
22990 + si_read_unlock(sb);
22996 +/* ---------------------------------------------------------------------- */
22998 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
22999 + struct delayed_call *done)
23002 + struct dentry *h_dentry;
23003 + struct inode *h_inode;
23005 + aufs_bindex_t bindex;
23007 + ret = NULL; /* suppress a warning */
23012 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
23013 + if (unlikely(err))
23016 + err = au_d_hashed_positive(dentry);
23017 + if (unlikely(err))
23021 + inode = d_inode(dentry);
23022 + bindex = au_ibtop(inode);
23023 + h_inode = au_h_iptr(inode, bindex);
23024 + if (unlikely(!h_inode->i_op->get_link))
23029 + if (au_dbtop(dentry) <= bindex) {
23030 + h_dentry = au_h_dptr(dentry, bindex);
23035 + h_dentry = d_find_any_alias(h_inode);
23036 + if (IS_ERR(h_dentry)) {
23037 + err = PTR_ERR(h_dentry);
23041 + if (unlikely(!h_dentry))
23045 + AuDbg("%ps\n", h_inode->i_op->get_link);
23046 + AuDbgDentry(h_dentry);
23047 + ret = vfs_get_link(h_dentry, done);
23050 + err = PTR_ERR(ret);
23053 + aufs_read_unlock(dentry, AuLock_IR);
23055 + if (unlikely(err))
23056 + ret = ERR_PTR(err);
23057 + AuTraceErrPtr(ret);
23061 +/* ---------------------------------------------------------------------- */
23063 +static int au_is_special(struct inode *inode)
23065 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
23068 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
23072 + aufs_bindex_t bindex;
23073 + struct super_block *sb;
23074 + struct inode *h_inode;
23075 + struct vfsmount *h_mnt;
23077 + sb = inode->i_sb;
23078 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
23079 + "unexpected s_flags 0x%lx", sb->s_flags);
23081 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
23083 + si_read_lock(sb, AuLock_FLUSH);
23084 + ii_write_lock_child(inode);
23087 + bindex = au_ibtop(inode);
23088 + h_inode = au_h_iptr(inode, bindex);
23089 + if (!au_test_ro(sb, bindex, inode)) {
23090 + h_mnt = au_sbr_mnt(sb, bindex);
23091 + err = vfsub_mnt_want_write(h_mnt);
23093 + err = vfsub_update_time(h_inode, ts, flags);
23094 + vfsub_mnt_drop_write(h_mnt);
23096 + } else if (au_is_special(h_inode)) {
23098 + * Never copy-up here.
23099 + * These special files may already be opened and used for
23100 + * communicating. If we copied it up, then the communication
23101 + * would be corrupted.
23103 + AuWarn1("timestamps for i%lu are ignored "
23104 + "since it is on readonly branch (hi%lu).\n",
23105 + inode->i_ino, h_inode->i_ino);
23106 + } else if (flags & ~S_ATIME) {
23108 + AuIOErr1("unexpected flags 0x%x\n", flags);
23113 + au_cpup_attr_timesizes(inode);
23114 + ii_write_unlock(inode);
23115 + si_read_unlock(sb);
23118 + if (!err && (flags & S_VERSION))
23119 + inode_inc_iversion(inode);
23124 +/* ---------------------------------------------------------------------- */
23126 +/* no getattr version will be set by module.c:aufs_init() */
23127 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
23129 + [AuIop_SYMLINK] = {
23130 + .permission = aufs_permission,
23131 +#ifdef CONFIG_FS_POSIX_ACL
23132 + .get_acl = aufs_get_acl,
23133 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
23136 + .setattr = aufs_setattr,
23137 + .getattr = aufs_getattr,
23139 +#ifdef CONFIG_AUFS_XATTR
23140 + .listxattr = aufs_listxattr,
23143 + .get_link = aufs_get_link
23145 + /* .update_time = aufs_update_time */
23148 + .create = aufs_create,
23149 + .lookup = aufs_lookup,
23150 + .link = aufs_link,
23151 + .unlink = aufs_unlink,
23152 + .symlink = aufs_symlink,
23153 + .mkdir = aufs_mkdir,
23154 + .rmdir = aufs_rmdir,
23155 + .mknod = aufs_mknod,
23156 + .rename = aufs_rename,
23158 + .permission = aufs_permission,
23159 +#ifdef CONFIG_FS_POSIX_ACL
23160 + .get_acl = aufs_get_acl,
23161 + .set_acl = aufs_set_acl,
23164 + .setattr = aufs_setattr,
23165 + .getattr = aufs_getattr,
23167 +#ifdef CONFIG_AUFS_XATTR
23168 + .listxattr = aufs_listxattr,
23171 + .update_time = aufs_update_time,
23172 + .atomic_open = aufs_atomic_open,
23173 + .tmpfile = aufs_tmpfile
23175 + [AuIop_OTHER] = {
23176 + .permission = aufs_permission,
23177 +#ifdef CONFIG_FS_POSIX_ACL
23178 + .get_acl = aufs_get_acl,
23179 + .set_acl = aufs_set_acl,
23182 + .setattr = aufs_setattr,
23183 + .getattr = aufs_getattr,
23185 +#ifdef CONFIG_AUFS_XATTR
23186 + .listxattr = aufs_listxattr,
23189 + .update_time = aufs_update_time
23192 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
23193 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
23194 +++ linux/fs/aufs/i_op_del.c 2022-11-05 23:02:18.965889284 +0100
23196 +// SPDX-License-Identifier: GPL-2.0
23198 + * Copyright (C) 2005-2022 Junjiro R. Okajima
23200 + * This program is free software; you can redistribute it and/or modify
23201 + * it under the terms of the GNU General Public License as published by
23202 + * the Free Software Foundation; either version 2 of the License, or
23203 + * (at your option) any later version.
23205 + * This program is distributed in the hope that it will be useful,
23206 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23207 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23208 + * GNU General Public License for more details.
23210 + * You should have received a copy of the GNU General Public License
23211 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23215 + * inode operations (del entry)
23218 +#include <linux/iversion.h>
23222 + * decide if a new whiteout for @dentry is necessary or not.
23223 + * when it is necessary, prepare the parent dir for the upper branch whose
23224 + * branch index is @bcpup for creation. the actual creation of the whiteout will
23225 + * be done by caller.
23227 + * 0: wh is unnecessary
23228 + * plus: wh is necessary
23231 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
23233 + int need_wh, err;
23234 + aufs_bindex_t btop;
23235 + struct super_block *sb;
23237 + sb = dentry->d_sb;
23238 + btop = au_dbtop(dentry);
23239 + if (*bcpup < 0) {
23241 + if (au_test_ro(sb, btop, d_inode(dentry))) {
23242 + err = AuWbrCopyup(au_sbi(sb), dentry);
23244 + if (unlikely(err < 0))
23248 + AuDebugOn(btop < *bcpup
23249 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
23250 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
23252 + if (*bcpup != btop) {
23253 + err = au_cpup_dirs(dentry, *bcpup);
23254 + if (unlikely(err))
23258 + struct au_dinfo *dinfo, *tmp;
23260 + need_wh = -ENOMEM;
23261 + dinfo = au_di(dentry);
23262 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
23264 + au_di_cp(tmp, dinfo);
23265 + au_di_swap(tmp, dinfo);
23266 + /* returns the number of positive dentries */
23267 + need_wh = au_lkup_dentry(dentry, btop + 1,
23268 + /* AuLkup_IGNORE_PERM */ 0);
23269 + au_di_swap(tmp, dinfo);
23270 + au_rw_write_unlock(&tmp->di_rwsem);
23274 + AuDbg("need_wh %d\n", need_wh);
23282 + * simple tests for the del-entry operations.
23283 + * following the checks in vfs, plus the parent-child relationship.
23285 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
23286 + struct dentry *h_parent, int isdir)
23290 + struct dentry *h_dentry, *h_latest;
23291 + struct inode *h_inode;
23292 + struct path h_ppath;
23293 + struct super_block *sb;
23294 + struct au_branch *br;
23295 + struct user_namespace *h_userns;
23297 + h_dentry = au_h_dptr(dentry, bindex);
23298 + if (d_really_is_positive(dentry)) {
23300 + if (unlikely(d_is_negative(h_dentry)))
23302 + h_inode = d_inode(h_dentry);
23303 + if (unlikely(!h_inode->i_nlink))
23306 + h_mode = h_inode->i_mode;
23309 + if (unlikely(S_ISDIR(h_mode)))
23311 + } else if (unlikely(!S_ISDIR(h_mode))) {
23316 + /* rename(2) case */
23318 + if (unlikely(d_is_positive(h_dentry)))
23323 + /* expected parent dir is locked */
23324 + if (unlikely(h_parent != h_dentry->d_parent))
23329 + * rmdir a dir may break the consistency on some filesystem.
23330 + * let's try heavy test.
23333 + sb = dentry->d_sb;
23334 + br = au_sbr(sb, bindex);
23335 + h_userns = au_br_userns(br);
23336 + if (unlikely(!au_opt_test(au_mntflags(sb), DIRPERM1)
23337 + && au_test_h_perm(h_userns, d_inode(h_parent),
23338 + MAY_EXEC | MAY_WRITE)))
23341 + h_ppath.dentry = h_parent;
23342 + h_ppath.mnt = au_br_mnt(br);
23343 + h_latest = au_sio_lkup_one(h_userns, &dentry->d_name, &h_ppath);
23345 + if (IS_ERR(h_latest))
23347 + if (h_latest == h_dentry)
23356 + * decide the branch where we operate for @dentry. the branch index will be set
23357 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
23358 + * dir for reverting.
23359 + * when a new whiteout is necessary, create it.
23361 +static struct dentry*
23362 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
23363 + struct au_dtime *dt, struct au_pin *pin)
23365 + struct dentry *wh_dentry;
23366 + struct super_block *sb;
23367 + struct path h_path;
23368 + int err, need_wh;
23369 + unsigned int udba;
23370 + aufs_bindex_t bcpup;
23372 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
23373 + wh_dentry = ERR_PTR(need_wh);
23374 + if (unlikely(need_wh < 0))
23377 + sb = dentry->d_sb;
23378 + udba = au_opt_udba(sb);
23380 + err = au_pin(pin, dentry, bcpup, udba,
23381 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23382 + wh_dentry = ERR_PTR(err);
23383 + if (unlikely(err))
23386 + h_path.dentry = au_pinned_h_parent(pin);
23387 + if (udba != AuOpt_UDBA_NONE
23388 + && au_dbtop(dentry) == bcpup) {
23389 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
23390 + wh_dentry = ERR_PTR(err);
23391 + if (unlikely(err))
23395 + h_path.mnt = au_sbr_mnt(sb, bcpup);
23396 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
23397 + wh_dentry = NULL;
23399 + goto out; /* success, no need to create whiteout */
23401 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
23402 + if (IS_ERR(wh_dentry))
23405 + /* returns with the parent is locked and wh_dentry is dget-ed */
23406 + goto out; /* success */
23411 + return wh_dentry;
23415 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
23416 + * in order to be revertible and save time for removing many child whiteouts
23418 + * returns 1 when there are too many child whiteout and caller should remove
23419 + * them asynchronously. returns 0 when the number of children is enough small to
23420 + * remove now or the branch fs is a remote fs.
23421 + * otherwise return an error.
23423 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
23424 + struct au_nhash *whlist, struct inode *dir)
23426 + int rmdir_later, err, dirwh;
23427 + struct dentry *h_dentry;
23428 + struct super_block *sb;
23429 + struct inode *inode;
23431 + sb = dentry->d_sb;
23432 + SiMustAnyLock(sb);
23433 + h_dentry = au_h_dptr(dentry, bindex);
23434 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
23435 + if (unlikely(err))
23438 + /* stop monitoring */
23439 + inode = d_inode(dentry);
23440 + au_hn_free(au_hi(inode, bindex));
23442 + if (!au_test_fs_remote(h_dentry->d_sb)) {
23443 + dirwh = au_sbi(sb)->si_dirwh;
23444 + rmdir_later = (dirwh <= 1);
23445 + if (!rmdir_later)
23446 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
23449 + return rmdir_later;
23452 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
23453 + if (unlikely(err)) {
23454 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
23455 + h_dentry, bindex, err);
23465 + * final procedure for deleting a entry.
23466 + * maintain dentry and iattr.
23468 +static void epilog(struct inode *dir, struct dentry *dentry,
23469 + aufs_bindex_t bindex)
23471 + struct inode *inode;
23473 + inode = d_inode(dentry);
23475 + inode->i_ctime = dir->i_ctime;
23477 + au_dir_ts(dir, bindex);
23478 + inode_inc_iversion(dir);
23482 + * when an error happened, remove the created whiteout and revert everything.
23484 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
23485 + aufs_bindex_t bwh, struct dentry *wh_dentry,
23486 + struct dentry *dentry, struct au_dtime *dt)
23489 + struct path h_path = {
23490 + .dentry = wh_dentry,
23491 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
23494 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
23496 + au_set_dbwh(dentry, bwh);
23497 + au_dtime_revert(dt);
23501 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
23505 +/* ---------------------------------------------------------------------- */
23507 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
23510 + aufs_bindex_t bwh, bindex, btop;
23511 + struct inode *inode, *h_dir, *delegated;
23512 + struct dentry *parent, *wh_dentry;
23513 + /* to reduce stack size */
23515 + struct au_dtime dt;
23516 + struct au_pin pin;
23517 + struct path h_path;
23523 + a = kmalloc(sizeof(*a), GFP_NOFS);
23524 + if (unlikely(!a))
23527 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
23528 + if (unlikely(err))
23530 + err = au_d_hashed_positive(dentry);
23531 + if (unlikely(err))
23533 + inode = d_inode(dentry);
23534 + IMustLock(inode);
23536 + if (unlikely(d_is_dir(dentry)))
23537 + goto out_unlock; /* possible? */
23539 + btop = au_dbtop(dentry);
23540 + bwh = au_dbwh(dentry);
23542 + parent = dentry->d_parent; /* dir inode is locked */
23543 + di_write_lock_parent(parent);
23544 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
23546 + err = PTR_ERR(wh_dentry);
23547 + if (IS_ERR(wh_dentry))
23550 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
23551 + a->h_path.dentry = au_h_dptr(dentry, btop);
23552 + dget(a->h_path.dentry);
23553 + if (bindex == btop) {
23554 + h_dir = au_pinned_h_dir(&a->pin);
23555 + delegated = NULL;
23556 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
23557 + if (unlikely(err == -EWOULDBLOCK)) {
23558 + pr_warn("cannot retry for NFSv4 delegation"
23559 + " for an internal unlink\n");
23563 + /* dir inode is locked */
23564 + h_dir = d_inode(wh_dentry->d_parent);
23565 + IMustLock(h_dir);
23570 + vfsub_drop_nlink(inode);
23571 + epilog(dir, dentry, bindex);
23573 + /* update target timestamps */
23574 + if (bindex == btop) {
23575 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
23577 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23579 + /* todo: this timestamp may be reverted later */
23580 + inode->i_ctime = h_dir->i_ctime;
23581 + goto out_unpin; /* success */
23588 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
23595 + au_unpin(&a->pin);
23597 + dput(a->h_path.dentry);
23599 + di_write_unlock(parent);
23601 + aufs_read_unlock(dentry, AuLock_DW);
23608 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
23610 + int err, rmdir_later;
23611 + aufs_bindex_t bwh, bindex, btop;
23612 + struct inode *inode;
23613 + struct dentry *parent, *wh_dentry, *h_dentry;
23614 + struct au_whtmp_rmdir *args;
23615 + /* to reduce stack size */
23617 + struct au_dtime dt;
23618 + struct au_pin pin;
23624 + a = kmalloc(sizeof(*a), GFP_NOFS);
23625 + if (unlikely(!a))
23628 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
23629 + if (unlikely(err))
23631 + err = au_alive_dir(dentry);
23632 + if (unlikely(err))
23634 + inode = d_inode(dentry);
23635 + IMustLock(inode);
23637 + if (unlikely(!d_is_dir(dentry)))
23638 + goto out_unlock; /* possible? */
23641 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
23642 + if (unlikely(!args))
23645 + parent = dentry->d_parent; /* dir inode is locked */
23646 + di_write_lock_parent(parent);
23647 + err = au_test_empty(dentry, &args->whlist);
23648 + if (unlikely(err))
23651 + btop = au_dbtop(dentry);
23652 + bwh = au_dbwh(dentry);
23654 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
23656 + err = PTR_ERR(wh_dentry);
23657 + if (IS_ERR(wh_dentry))
23660 + h_dentry = au_h_dptr(dentry, btop);
23663 + if (bindex == btop) {
23664 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
23666 + rmdir_later = err;
23670 + /* stop monitoring */
23671 + au_hn_free(au_hi(inode, btop));
23673 + /* dir inode is locked */
23674 + IMustLock(d_inode(wh_dentry->d_parent));
23679 + vfsub_dead_dir(inode);
23680 + au_set_dbdiropq(dentry, -1);
23681 + epilog(dir, dentry, bindex);
23683 + if (rmdir_later) {
23684 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
23688 + goto out_unpin; /* success */
23696 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
23703 + au_unpin(&a->pin);
23707 + di_write_unlock(parent);
23709 + au_whtmp_rmdir_free(args);
23711 + aufs_read_unlock(dentry, AuLock_DW);
23718 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
23719 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
23720 +++ linux/fs/aufs/i_op_ren.c 2022-11-05 23:02:18.965889284 +0100
23722 +// SPDX-License-Identifier: GPL-2.0
23724 + * Copyright (C) 2005-2022 Junjiro R. Okajima
23726 + * This program is free software; you can redistribute it and/or modify
23727 + * it under the terms of the GNU General Public License as published by
23728 + * the Free Software Foundation; either version 2 of the License, or
23729 + * (at your option) any later version.
23731 + * This program is distributed in the hope that it will be useful,
23732 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23733 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23734 + * GNU General Public License for more details.
23736 + * You should have received a copy of the GNU General Public License
23737 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23741 + * inode operation (rename entry)
23742 + * todo: this is crazy monster
23745 +#include <linux/iversion.h>
23748 +enum { AuSRC, AuDST, AuSrcDst };
23749 +enum { AuPARENT, AuCHILD, AuParentChild };
23751 +#define AuRen_ISDIR_SRC 1
23752 +#define AuRen_ISDIR_DST (1 << 1)
23753 +#define AuRen_ISSAMEDIR (1 << 2)
23754 +#define AuRen_WHSRC (1 << 3)
23755 +#define AuRen_WHDST (1 << 4)
23756 +#define AuRen_MNT_WRITE (1 << 5)
23757 +#define AuRen_DT_DSTDIR (1 << 6)
23758 +#define AuRen_DIROPQ_SRC (1 << 7)
23759 +#define AuRen_DIROPQ_DST (1 << 8)
23760 +#define AuRen_DIRREN (1 << 9)
23761 +#define AuRen_DROPPED_SRC (1 << 10)
23762 +#define AuRen_DROPPED_DST (1 << 11)
23763 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
23764 +#define au_fset_ren(flags, name) \
23765 + do { (flags) |= AuRen_##name; } while (0)
23766 +#define au_fclr_ren(flags, name) \
23767 + do { (flags) &= ~AuRen_##name; } while (0)
23769 +#ifndef CONFIG_AUFS_DIRREN
23770 +#undef AuRen_DIRREN
23771 +#define AuRen_DIRREN 0
23774 +struct au_ren_args {
23776 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
23778 + struct inode *dir, *inode;
23779 + struct au_hinode *hdir, *hinode;
23780 + struct au_dtime dt[AuParentChild];
23781 + aufs_bindex_t btop, bdiropq;
23784 +#define src_dentry sd[AuSRC].dentry
23785 +#define src_dir sd[AuSRC].dir
23786 +#define src_inode sd[AuSRC].inode
23787 +#define src_h_dentry sd[AuSRC].h_dentry
23788 +#define src_parent sd[AuSRC].parent
23789 +#define src_h_parent sd[AuSRC].h_parent
23790 +#define src_wh_dentry sd[AuSRC].wh_dentry
23791 +#define src_hdir sd[AuSRC].hdir
23792 +#define src_hinode sd[AuSRC].hinode
23793 +#define src_h_dir sd[AuSRC].hdir->hi_inode
23794 +#define src_dt sd[AuSRC].dt
23795 +#define src_btop sd[AuSRC].btop
23796 +#define src_bdiropq sd[AuSRC].bdiropq
23798 +#define dst_dentry sd[AuDST].dentry
23799 +#define dst_dir sd[AuDST].dir
23800 +#define dst_inode sd[AuDST].inode
23801 +#define dst_h_dentry sd[AuDST].h_dentry
23802 +#define dst_parent sd[AuDST].parent
23803 +#define dst_h_parent sd[AuDST].h_parent
23804 +#define dst_wh_dentry sd[AuDST].wh_dentry
23805 +#define dst_hdir sd[AuDST].hdir
23806 +#define dst_hinode sd[AuDST].hinode
23807 +#define dst_h_dir sd[AuDST].hdir->hi_inode
23808 +#define dst_dt sd[AuDST].dt
23809 +#define dst_btop sd[AuDST].btop
23810 +#define dst_bdiropq sd[AuDST].bdiropq
23812 + struct dentry *h_trap;
23813 + struct au_branch *br;
23814 + struct path h_path;
23815 + struct au_nhash whlist;
23816 + aufs_bindex_t btgt, src_bwh;
23819 + unsigned short auren_flags;
23820 + unsigned char flags; /* syscall parameter */
23821 + unsigned char exchange;
23824 + struct au_whtmp_rmdir *thargs;
23825 + struct dentry *h_dst;
23826 + struct au_hinode *h_root;
23829 +/* ---------------------------------------------------------------------- */
23832 + * functions for reverting.
23833 + * when an error happened in a single rename systemcall, we should revert
23834 + * everything as if nothing happened.
23835 + * we don't need to revert the copied-up/down the parent dir since they are
23839 +#define RevertFailure(fmt, ...) do { \
23840 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
23841 + ##__VA_ARGS__, err, rerr); \
23845 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
23848 + struct dentry *d;
23849 +#define src_or_dst(member) a->sd[idx].member
23851 + d = src_or_dst(dentry); /* {src,dst}_dentry */
23852 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
23853 + rerr = au_diropq_remove(d, a->btgt);
23854 + au_hn_inode_unlock(src_or_dst(hinode));
23855 + au_set_dbdiropq(d, src_or_dst(bdiropq));
23857 + RevertFailure("remove diropq %pd", d);
23859 +#undef src_or_dst_
23862 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
23864 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
23865 + au_ren_do_rev_diropq(err, a, AuSRC);
23866 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
23867 + au_ren_do_rev_diropq(err, a, AuDST);
23870 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
23873 + struct inode *delegated;
23874 + struct path h_ppath = {
23875 + .dentry = a->src_h_parent,
23876 + .mnt = a->h_path.mnt
23879 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, &h_ppath);
23880 + rerr = PTR_ERR(a->h_path.dentry);
23881 + if (IS_ERR(a->h_path.dentry)) {
23882 + RevertFailure("lkup one %pd", a->src_dentry);
23886 + delegated = NULL;
23887 + rerr = vfsub_rename(a->dst_h_dir,
23888 + au_h_dptr(a->src_dentry, a->btgt),
23889 + a->src_h_dir, &a->h_path, &delegated, a->flags);
23890 + if (unlikely(rerr == -EWOULDBLOCK)) {
23891 + pr_warn("cannot retry for NFSv4 delegation"
23892 + " for an internal rename\n");
23895 + d_drop(a->h_path.dentry);
23896 + dput(a->h_path.dentry);
23897 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
23899 + RevertFailure("rename %pd", a->src_dentry);
23902 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
23905 + struct inode *delegated;
23906 + struct path h_ppath = {
23907 + .dentry = a->dst_h_parent,
23908 + .mnt = a->h_path.mnt
23911 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, &h_ppath);
23912 + rerr = PTR_ERR(a->h_path.dentry);
23913 + if (IS_ERR(a->h_path.dentry)) {
23914 + RevertFailure("lkup one %pd", a->dst_dentry);
23917 + if (d_is_positive(a->h_path.dentry)) {
23918 + d_drop(a->h_path.dentry);
23919 + dput(a->h_path.dentry);
23923 + delegated = NULL;
23924 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
23925 + &delegated, a->flags);
23926 + if (unlikely(rerr == -EWOULDBLOCK)) {
23927 + pr_warn("cannot retry for NFSv4 delegation"
23928 + " for an internal rename\n");
23931 + d_drop(a->h_path.dentry);
23932 + dput(a->h_path.dentry);
23934 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
23936 + RevertFailure("rename %pd", a->h_dst);
23939 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
23943 + a->h_path.dentry = a->src_wh_dentry;
23944 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
23945 + au_set_dbwh(a->src_dentry, a->src_bwh);
23947 + RevertFailure("unlink %pd", a->src_wh_dentry);
23949 +#undef RevertFailure
23951 +/* ---------------------------------------------------------------------- */
23954 + * when we have to copyup the renaming entry, do it with the rename-target name
23955 + * in order to minimize the cost (the later actual rename is unnecessary).
23956 + * otherwise rename it on the target branch.
23958 +static int au_ren_or_cpup(struct au_ren_args *a)
23961 + struct dentry *d;
23962 + struct inode *delegated;
23964 + d = a->src_dentry;
23965 + if (au_dbtop(d) == a->btgt) {
23966 + a->h_path.dentry = a->dst_h_dentry;
23967 + AuDebugOn(au_dbtop(d) != a->btgt);
23968 + delegated = NULL;
23969 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
23970 + a->dst_h_dir, &a->h_path, &delegated,
23972 + if (unlikely(err == -EWOULDBLOCK)) {
23973 + pr_warn("cannot retry for NFSv4 delegation"
23974 + " for an internal rename\n");
23980 + if (!err && a->h_dst)
23981 + /* it will be set to dinfo later */
23987 +/* cf. aufs_rmdir() */
23988 +static int au_ren_del_whtmp(struct au_ren_args *a)
23991 + struct inode *dir;
23993 + dir = a->dst_dir;
23994 + SiMustAnyLock(dir->i_sb);
23995 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
23996 + au_sbi(dir->i_sb)->si_dirwh)
23997 + || au_test_fs_remote(a->h_dst->d_sb)) {
23998 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
23999 + if (unlikely(err))
24000 + pr_warn("failed removing whtmp dir %pd (%d), "
24001 + "ignored.\n", a->h_dst, err);
24003 + au_nhash_wh_free(&a->thargs->whlist);
24004 + a->thargs->whlist = a->whlist;
24005 + a->whlist.nh_num = 0;
24006 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
24008 + a->thargs = NULL;
24014 +/* make it 'opaque' dir. */
24015 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
24018 + struct dentry *d, *diropq;
24019 +#define src_or_dst(member) a->sd[idx].member
24022 + d = src_or_dst(dentry); /* {src,dst}_dentry */
24023 + src_or_dst(bdiropq) = au_dbdiropq(d);
24024 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
24025 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
24026 + diropq = au_diropq_create(d, a->btgt);
24027 + au_hn_inode_unlock(src_or_dst(hinode));
24028 + if (IS_ERR(diropq))
24029 + err = PTR_ERR(diropq);
24033 +#undef src_or_dst_
24037 +static int au_ren_diropq(struct au_ren_args *a)
24040 + unsigned char always;
24041 + struct dentry *d;
24044 + d = a->dst_dentry; /* already renamed on the branch */
24045 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
24046 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
24047 + && !au_ftest_ren(a->auren_flags, DIRREN)
24048 + && a->btgt != au_dbdiropq(a->src_dentry)
24049 + && (a->dst_wh_dentry
24050 + || a->btgt <= au_dbdiropq(d)
24051 + /* hide the lower to keep xino */
24052 + /* the lowers may not be a dir, but we hide them anyway */
24053 + || a->btgt < au_dbbot(d)
24056 + err = au_ren_do_diropq(a, AuSRC);
24057 + if (unlikely(err))
24059 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
24061 + if (!a->exchange)
24062 + goto out; /* success */
24064 + d = a->src_dentry; /* already renamed on the branch */
24065 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
24066 + && a->btgt != au_dbdiropq(a->dst_dentry)
24067 + && (a->btgt < au_dbdiropq(d)
24068 + || a->btgt < au_dbbot(d)
24070 + AuDbgDentry(a->src_dentry);
24071 + AuDbgDentry(a->dst_dentry);
24072 + err = au_ren_do_diropq(a, AuDST);
24073 + if (unlikely(err))
24074 + goto out_rev_src;
24075 + au_fset_ren(a->auren_flags, DIROPQ_DST);
24077 + goto out; /* success */
24080 + AuDbg("err %d, reverting src\n", err);
24081 + au_ren_rev_diropq(err, a);
24086 +static int do_rename(struct au_ren_args *a)
24089 + struct dentry *d, *h_d;
24091 + if (!a->exchange) {
24092 + /* prepare workqueue args for asynchronous rmdir */
24093 + h_d = a->dst_h_dentry;
24094 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
24095 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
24096 + && d_is_positive(h_d)) {
24098 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
24100 + if (unlikely(!a->thargs))
24102 + a->h_dst = dget(h_d);
24105 + /* create whiteout for src_dentry */
24106 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
24107 + a->src_bwh = au_dbwh(a->src_dentry);
24108 + AuDebugOn(a->src_bwh >= 0);
24109 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
24110 + a->src_h_parent);
24111 + err = PTR_ERR(a->src_wh_dentry);
24112 + if (IS_ERR(a->src_wh_dentry))
24116 + /* lookup whiteout for dentry */
24117 + if (au_ftest_ren(a->auren_flags, WHDST)) {
24118 + h_d = au_wh_lkup(a->dst_h_parent,
24119 + &a->dst_dentry->d_name, a->br);
24120 + err = PTR_ERR(h_d);
24123 + if (d_is_negative(h_d))
24126 + a->dst_wh_dentry = h_d;
24129 + /* rename dentry to tmpwh */
24131 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
24132 + if (unlikely(err))
24135 + d = a->dst_dentry;
24136 + au_set_h_dptr(d, a->btgt, NULL);
24137 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
24138 + if (unlikely(err))
24140 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
24144 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
24145 +#if 0 /* debugging */
24146 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
24147 + && d_is_positive(a->dst_h_dentry)
24148 + && a->src_btop != a->btgt);
24151 + /* rename by vfs_rename or cpup */
24152 + err = au_ren_or_cpup(a);
24153 + if (unlikely(err))
24154 + /* leave the copied-up one */
24157 + /* make dir opaque */
24158 + err = au_ren_diropq(a);
24159 + if (unlikely(err))
24162 + /* update target timestamps */
24163 + if (a->exchange) {
24164 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
24165 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
24166 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
24167 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
24169 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
24170 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
24171 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
24172 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
24174 + if (!a->exchange) {
24175 + /* remove whiteout for dentry */
24176 + if (a->dst_wh_dentry) {
24177 + a->h_path.dentry = a->dst_wh_dentry;
24178 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
24180 + if (unlikely(err))
24184 + /* remove whtmp */
24186 + au_ren_del_whtmp(a); /* ignore this error */
24188 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
24191 + goto out_success;
24194 + au_ren_rev_diropq(err, a);
24196 + au_ren_rev_rename(err, a);
24200 + au_ren_rev_whtmp(err, a);
24202 + dput(a->dst_wh_dentry);
24203 + a->dst_wh_dentry = NULL;
24205 + if (a->src_wh_dentry)
24206 + au_ren_rev_whsrc(err, a);
24208 + dput(a->src_wh_dentry);
24209 + dput(a->dst_wh_dentry);
24213 + au_whtmp_rmdir_free(a->thargs);
24214 + a->thargs = NULL;
24220 +/* ---------------------------------------------------------------------- */
24223 + * test if @dentry dir can be rename destination or not.
24224 + * success means, it is a logically empty dir.
24226 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
24228 + return au_test_empty(dentry, whlist);
24232 + * test if @a->src_dentry dir can be rename source or not.
24233 + * if it can, return 0.
24235 + * - it is a logically empty dir.
24236 + * - or, it exists on writable branch and has no children including whiteouts
24237 + * on the lower branch unless DIRREN is on.
24239 +static int may_rename_srcdir(struct au_ren_args *a)
24242 + unsigned int rdhash;
24243 + aufs_bindex_t btop, btgt;
24244 + struct dentry *dentry;
24245 + struct super_block *sb;
24246 + struct au_sbinfo *sbinfo;
24248 + dentry = a->src_dentry;
24249 + sb = dentry->d_sb;
24250 + sbinfo = au_sbi(sb);
24251 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
24252 + au_fset_ren(a->auren_flags, DIRREN);
24255 + btop = au_dbtop(dentry);
24256 + if (btop != btgt) {
24257 + struct au_nhash whlist;
24259 + SiMustAnyLock(sb);
24260 + rdhash = sbinfo->si_rdhash;
24262 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
24264 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
24265 + if (unlikely(err))
24267 + err = au_test_empty(dentry, &whlist);
24268 + au_nhash_wh_free(&whlist);
24272 + if (btop == au_dbtaildir(dentry))
24273 + return 0; /* success */
24275 + err = au_test_empty_lower(dentry);
24278 + if (err == -ENOTEMPTY) {
24279 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24282 + AuWarn1("renaming dir who has child(ren) on multiple "
24283 + "branches, is not supported\n");
24290 +/* side effect: sets whlist and h_dentry */
24291 +static int au_ren_may_dir(struct au_ren_args *a)
24294 + unsigned int rdhash;
24295 + struct dentry *d;
24297 + d = a->dst_dentry;
24298 + SiMustAnyLock(d->d_sb);
24301 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
24302 + rdhash = au_sbi(d->d_sb)->si_rdhash;
24304 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
24305 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
24306 + if (unlikely(err))
24309 + if (!a->exchange) {
24310 + au_set_dbtop(d, a->dst_btop);
24311 + err = may_rename_dstdir(d, &a->whlist);
24312 + au_set_dbtop(d, a->btgt);
24314 + err = may_rename_srcdir(a);
24316 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
24317 + if (unlikely(err))
24320 + d = a->src_dentry;
24321 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
24322 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
24323 + err = may_rename_srcdir(a);
24324 + if (unlikely(err)) {
24325 + au_nhash_wh_free(&a->whlist);
24326 + a->whlist.nh_num = 0;
24333 +/* ---------------------------------------------------------------------- */
24336 + * simple tests for rename.
24337 + * following the checks in vfs, plus the parent-child relationship.
24339 +static int au_may_ren(struct au_ren_args *a)
24342 + struct inode *h_inode;
24344 + if (a->src_btop == a->btgt) {
24345 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
24346 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
24347 + if (unlikely(err))
24350 + if (unlikely(a->src_h_dentry == a->h_trap))
24355 + if (a->dst_btop != a->btgt)
24358 + err = -ENOTEMPTY;
24359 + if (unlikely(a->dst_h_dentry == a->h_trap))
24363 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
24364 + if (d_really_is_negative(a->dst_dentry)) {
24365 + if (d_is_negative(a->dst_h_dentry))
24366 + err = au_may_add(a->dst_dentry, a->btgt,
24367 + a->dst_h_parent, isdir);
24369 + if (unlikely(d_is_negative(a->dst_h_dentry)))
24371 + h_inode = d_inode(a->dst_h_dentry);
24372 + if (h_inode->i_nlink)
24373 + err = au_may_del(a->dst_dentry, a->btgt,
24374 + a->dst_h_parent, isdir);
24378 + if (unlikely(err == -ENOENT || err == -EEXIST))
24384 +/* ---------------------------------------------------------------------- */
24389 + * - src_dir and dir by lock_rename()
24390 + * - inode if exists
24393 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
24395 + * + di_write_lock2_child()
24396 + * + di_write_lock_child()
24397 + * + ii_write_lock_child()
24398 + * + di_write_lock_child2()
24399 + * + ii_write_lock_child2()
24400 + * + src_parent and parent
24401 + * + di_write_lock_parent()
24402 + * + ii_write_lock_parent()
24403 + * + di_write_lock_parent2()
24404 + * + ii_write_lock_parent2()
24405 + * + lower src_dir and dir by vfsub_lock_rename()
24406 + * + verify the every relationships between child and parent. if any
24407 + * of them failed, unlock all and return -EBUSY.
24409 +static void au_ren_unlock(struct au_ren_args *a)
24411 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
24412 + a->dst_h_parent, a->dst_hdir);
24413 + if (au_ftest_ren(a->auren_flags, DIRREN)
24415 + au_hn_inode_unlock(a->h_root);
24416 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
24417 + vfsub_mnt_drop_write(au_br_mnt(a->br));
24420 +static int au_ren_lock(struct au_ren_args *a)
24423 + unsigned int udba;
24426 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
24427 + a->src_hdir = au_hi(a->src_dir, a->btgt);
24428 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
24429 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
24431 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
24432 + if (unlikely(err))
24434 + au_fset_ren(a->auren_flags, MNT_WRITE);
24435 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24436 + struct dentry *root;
24437 + struct inode *dir;
24440 + * sbinfo is already locked, so this ii_read_lock is
24441 + * unnecessary. but our debugging feature checks it.
24443 + root = a->src_inode->i_sb->s_root;
24444 + if (root != a->src_parent && root != a->dst_parent) {
24445 + dir = d_inode(root);
24446 + ii_read_lock_parent3(dir);
24447 + a->h_root = au_hi(dir, a->btgt);
24448 + ii_read_unlock(dir);
24449 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
24452 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
24453 + a->dst_h_parent, a->dst_hdir);
24454 + udba = au_opt_udba(a->src_dentry->d_sb);
24455 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
24456 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
24457 + err = au_busy_or_stale();
24458 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
24459 + err = au_h_verify(a->src_h_dentry, udba,
24460 + d_inode(a->src_h_parent), a->src_h_parent,
24462 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
24463 + err = au_h_verify(a->dst_h_dentry, udba,
24464 + d_inode(a->dst_h_parent), a->dst_h_parent,
24467 + goto out; /* success */
24469 + err = au_busy_or_stale();
24470 + au_ren_unlock(a);
24476 +/* ---------------------------------------------------------------------- */
24478 +static void au_ren_refresh_dir(struct au_ren_args *a)
24480 + struct inode *dir;
24482 + dir = a->dst_dir;
24483 + inode_inc_iversion(dir);
24484 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
24485 + /* is this updating defined in POSIX? */
24486 + au_cpup_attr_timesizes(a->src_inode);
24487 + au_cpup_attr_nlink(dir, /*force*/1);
24489 + au_dir_ts(dir, a->btgt);
24491 + if (a->exchange) {
24492 + dir = a->src_dir;
24493 + inode_inc_iversion(dir);
24494 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
24495 + /* is this updating defined in POSIX? */
24496 + au_cpup_attr_timesizes(a->dst_inode);
24497 + au_cpup_attr_nlink(dir, /*force*/1);
24499 + au_dir_ts(dir, a->btgt);
24502 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
24505 + dir = a->src_dir;
24506 + inode_inc_iversion(dir);
24507 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
24508 + au_cpup_attr_nlink(dir, /*force*/1);
24509 + au_dir_ts(dir, a->btgt);
24512 +static void au_ren_refresh(struct au_ren_args *a)
24514 + aufs_bindex_t bbot, bindex;
24515 + struct dentry *d, *h_d;
24516 + struct inode *i, *h_i;
24517 + struct super_block *sb;
24519 + d = a->dst_dentry;
24522 + /* already dget-ed by au_ren_or_cpup() */
24523 + au_set_h_dptr(d, a->btgt, a->h_dst);
24525 + i = a->dst_inode;
24527 + if (!a->exchange) {
24528 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
24529 + vfsub_drop_nlink(i);
24531 + vfsub_dead_dir(i);
24532 + au_cpup_attr_timesizes(i);
24534 + au_update_dbrange(d, /*do_put_zero*/1);
24536 + au_cpup_attr_nlink(i, /*force*/1);
24539 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
24540 + au_set_h_dptr(d, bindex, NULL);
24541 + bbot = au_dbbot(d);
24542 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
24543 + au_set_h_dptr(d, bindex, NULL);
24544 + au_update_dbrange(d, /*do_put_zero*/0);
24548 + || au_ftest_ren(a->auren_flags, DIRREN)) {
24549 + d_drop(a->src_dentry);
24550 + if (au_ftest_ren(a->auren_flags, DIRREN))
24551 + au_set_dbwh(a->src_dentry, -1);
24555 + d = a->src_dentry;
24556 + au_set_dbwh(d, -1);
24557 + bbot = au_dbbot(d);
24558 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
24559 + h_d = au_h_dptr(d, bindex);
24561 + au_set_h_dptr(d, bindex, NULL);
24563 + au_set_dbbot(d, a->btgt);
24566 + i = a->src_inode;
24567 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
24568 + return; /* success */
24570 + bbot = au_ibbot(i);
24571 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
24572 + h_i = au_h_iptr(i, bindex);
24574 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
24575 + /* ignore this error */
24576 + au_set_h_iptr(i, bindex, NULL, 0);
24579 + au_set_ibbot(i, a->btgt);
24582 +/* ---------------------------------------------------------------------- */
24584 +/* mainly for link(2) and rename(2) */
24585 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
24587 + aufs_bindex_t bdiropq, bwh;
24588 + struct dentry *parent;
24589 + struct au_branch *br;
24591 + parent = dentry->d_parent;
24592 + IMustLock(d_inode(parent)); /* dir is locked */
24594 + bdiropq = au_dbdiropq(parent);
24595 + bwh = au_dbwh(dentry);
24596 + br = au_sbr(dentry->d_sb, btgt);
24597 + if (au_br_rdonly(br)
24598 + || (0 <= bdiropq && bdiropq < btgt)
24599 + || (0 <= bwh && bwh < btgt))
24602 + AuDbg("btgt %d\n", btgt);
24606 +/* sets src_btop, dst_btop and btgt */
24607 +static int au_ren_wbr(struct au_ren_args *a)
24610 + struct au_wr_dir_args wr_dir_args = {
24611 + /* .force_btgt = -1, */
24612 + .flags = AuWrDir_ADD_ENTRY
24615 + a->src_btop = au_dbtop(a->src_dentry);
24616 + a->dst_btop = au_dbtop(a->dst_dentry);
24617 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
24618 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
24619 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
24620 + wr_dir_args.force_btgt = a->src_btop;
24621 + if (a->dst_inode && a->dst_btop < a->src_btop)
24622 + wr_dir_args.force_btgt = a->dst_btop;
24623 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
24624 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
24627 + au_update_dbtop(a->dst_dentry);
24632 +static void au_ren_dt(struct au_ren_args *a)
24634 + a->h_path.dentry = a->src_h_parent;
24635 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
24636 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
24637 + a->h_path.dentry = a->dst_h_parent;
24638 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
24641 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
24642 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
24646 + a->h_path.dentry = a->src_h_dentry;
24647 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
24648 + if (d_is_positive(a->dst_h_dentry)) {
24649 + au_fset_ren(a->auren_flags, DT_DSTDIR);
24650 + a->h_path.dentry = a->dst_h_dentry;
24651 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
24655 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
24657 + struct dentry *h_d;
24658 + struct inode *h_inode;
24660 + au_dtime_revert(a->src_dt + AuPARENT);
24661 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
24662 + au_dtime_revert(a->dst_dt + AuPARENT);
24664 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
24665 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
24666 + h_inode = d_inode(h_d);
24667 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
24668 + au_dtime_revert(a->src_dt + AuCHILD);
24669 + inode_unlock(h_inode);
24671 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
24672 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
24673 + h_inode = d_inode(h_d);
24674 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
24675 + au_dtime_revert(a->dst_dt + AuCHILD);
24676 + inode_unlock(h_inode);
24681 +/* ---------------------------------------------------------------------- */
24683 +int aufs_rename(struct user_namespace *userns,
24684 + struct inode *_src_dir, struct dentry *_src_dentry,
24685 + struct inode *_dst_dir, struct dentry *_dst_dentry,
24686 + unsigned int _flags)
24688 + int err, lock_flags;
24690 + /* reduce stack space */
24691 + struct au_ren_args *a;
24692 + struct au_pin pin;
24694 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
24695 + IMustLock(_src_dir);
24696 + IMustLock(_dst_dir);
24699 + if (unlikely(_flags & RENAME_WHITEOUT))
24703 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
24704 + a = kzalloc(sizeof(*a), GFP_NOFS);
24705 + if (unlikely(!a))
24708 + a->flags = _flags;
24709 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
24710 + && RENAME_EXCHANGE > U8_MAX);
24711 + a->exchange = _flags & RENAME_EXCHANGE;
24712 + a->src_dir = _src_dir;
24713 + a->src_dentry = _src_dentry;
24714 + a->src_inode = NULL;
24715 + if (d_really_is_positive(a->src_dentry))
24716 + a->src_inode = d_inode(a->src_dentry);
24717 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
24718 + a->dst_dir = _dst_dir;
24719 + a->dst_dentry = _dst_dentry;
24720 + a->dst_inode = NULL;
24721 + if (d_really_is_positive(a->dst_dentry))
24722 + a->dst_inode = d_inode(a->dst_dentry);
24723 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
24724 + if (a->dst_inode) {
24726 + * if EXCHANGE && src is non-dir && dst is dir,
24727 + * dst is not locked.
24729 + /* IMustLock(a->dst_inode); */
24730 + au_igrab(a->dst_inode);
24734 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
24735 + if (d_is_dir(a->src_dentry)) {
24736 + au_fset_ren(a->auren_flags, ISDIR_SRC);
24737 + if (unlikely(!a->exchange
24738 + && d_really_is_positive(a->dst_dentry)
24739 + && !d_is_dir(a->dst_dentry)))
24741 + lock_flags |= AuLock_DIRS;
24743 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
24744 + au_fset_ren(a->auren_flags, ISDIR_DST);
24745 + if (unlikely(!a->exchange
24746 + && d_really_is_positive(a->src_dentry)
24747 + && !d_is_dir(a->src_dentry)))
24749 + lock_flags |= AuLock_DIRS;
24751 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
24753 + if (unlikely(err))
24756 + err = au_d_hashed_positive(a->src_dentry);
24757 + if (unlikely(err))
24760 + if (a->dst_inode) {
24762 + * If it is a dir, VFS unhash it before this
24763 + * function. It means we cannot rely upon d_unhashed().
24765 + if (unlikely(!a->dst_inode->i_nlink))
24767 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
24768 + err = au_d_hashed_positive(a->dst_dentry);
24769 + if (unlikely(err && !a->exchange))
24771 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
24773 + } else if (unlikely(d_unhashed(a->dst_dentry)))
24777 + * is it possible?
24778 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
24779 + * there may exist a problem somewhere else.
24782 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
24785 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
24786 + di_write_lock_parent(a->dst_parent);
24788 + /* which branch we process */
24789 + err = au_ren_wbr(a);
24790 + if (unlikely(err < 0))
24792 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
24793 + a->h_path.mnt = au_br_mnt(a->br);
24795 + /* are they available to be renamed */
24796 + err = au_ren_may_dir(a);
24797 + if (unlikely(err))
24798 + goto out_children;
24800 + /* prepare the writable parent dir on the same branch */
24801 + if (a->dst_btop == a->btgt) {
24802 + au_fset_ren(a->auren_flags, WHDST);
24804 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
24805 + if (unlikely(err))
24806 + goto out_children;
24810 + if (!a->exchange) {
24811 + if (a->src_dir != a->dst_dir) {
24813 + * this temporary unlock is safe,
24814 + * because both dir->i_mutex are locked.
24816 + di_write_unlock(a->dst_parent);
24817 + di_write_lock_parent(a->src_parent);
24818 + err = au_wr_dir_need_wh(a->src_dentry,
24819 + au_ftest_ren(a->auren_flags,
24822 + di_write_unlock(a->src_parent);
24823 + di_write_lock2_parent(a->src_parent, a->dst_parent,
24825 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
24827 + err = au_wr_dir_need_wh(a->src_dentry,
24828 + au_ftest_ren(a->auren_flags,
24832 + if (unlikely(err < 0))
24833 + goto out_children;
24835 + au_fset_ren(a->auren_flags, WHSRC);
24838 + if (a->src_btop != a->btgt) {
24839 + err = au_pin(&pin, a->src_dentry, a->btgt,
24840 + au_opt_udba(a->src_dentry->d_sb),
24841 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
24843 + struct au_cp_generic cpg = {
24844 + .dentry = a->src_dentry,
24846 + .bsrc = a->src_btop,
24849 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24851 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
24852 + err = au_sio_cpup_simple(&cpg);
24855 + if (unlikely(err))
24856 + goto out_children;
24857 + a->src_btop = a->btgt;
24858 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
24859 + if (!a->exchange)
24860 + au_fset_ren(a->auren_flags, WHSRC);
24864 + if (a->exchange && a->dst_inode
24865 + && a->dst_btop != a->btgt) {
24866 + err = au_pin(&pin, a->dst_dentry, a->btgt,
24867 + au_opt_udba(a->dst_dentry->d_sb),
24868 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
24870 + struct au_cp_generic cpg = {
24871 + .dentry = a->dst_dentry,
24873 + .bsrc = a->dst_btop,
24876 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24878 + err = au_sio_cpup_simple(&cpg);
24881 + if (unlikely(err))
24882 + goto out_children;
24883 + a->dst_btop = a->btgt;
24884 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
24887 + /* lock them all */
24888 + err = au_ren_lock(a);
24889 + if (unlikely(err))
24890 + /* leave the copied-up one */
24891 + goto out_children;
24893 + if (!a->exchange) {
24894 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
24895 + err = au_may_ren(a);
24896 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
24897 + err = -ENAMETOOLONG;
24898 + if (unlikely(err))
24902 + /* store timestamps to be revertible */
24905 + /* store dirren info */
24906 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24907 + err = au_dr_rename(a->src_dentry, a->btgt,
24908 + &a->dst_dentry->d_name, &rev);
24910 + if (unlikely(err))
24915 + err = do_rename(a);
24916 + if (unlikely(err))
24919 + if (au_ftest_ren(a->auren_flags, DIRREN))
24920 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
24922 + /* update dir attributes */
24923 + au_ren_refresh_dir(a);
24925 + /* dput/iput all lower dentries */
24926 + au_ren_refresh(a);
24928 + goto out_hdir; /* success */
24931 + if (au_ftest_ren(a->auren_flags, DIRREN))
24932 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
24934 + au_ren_rev_dt(err, a);
24936 + au_ren_unlock(a);
24938 + au_nhash_wh_free(&a->whlist);
24939 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
24940 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
24941 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
24942 + au_set_dbtop(a->dst_dentry, a->dst_btop);
24946 + if (d_unhashed(a->src_dentry))
24947 + au_fset_ren(a->auren_flags, DROPPED_SRC);
24948 + if (d_unhashed(a->dst_dentry))
24949 + au_fset_ren(a->auren_flags, DROPPED_DST);
24950 + if (!a->exchange)
24951 + d_move(a->src_dentry, a->dst_dentry);
24953 + d_exchange(a->src_dentry, a->dst_dentry);
24954 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
24955 + d_drop(a->dst_dentry);
24957 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
24958 + d_drop(a->src_dentry);
24960 + au_update_dbtop(a->dst_dentry);
24961 + if (!a->dst_inode)
24962 + d_drop(a->dst_dentry);
24964 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
24965 + di_write_unlock(a->dst_parent);
24967 + di_write_unlock2(a->src_parent, a->dst_parent);
24969 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
24971 + iput(a->dst_inode);
24973 + au_whtmp_rmdir_free(a->thargs);
24979 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
24980 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
24981 +++ linux/fs/aufs/Kconfig 2022-11-05 23:02:18.959222617 +0100
24983 +# SPDX-License-Identifier: GPL-2.0
24985 + tristate "Aufs (Advanced multi layered unification filesystem) support"
24987 + Aufs is a stackable unification filesystem such as Unionfs,
24988 + which unifies several directories and provides a merged single
24990 + In the early days, aufs was entirely re-designed and
24991 + re-implemented Unionfs Version 1.x series. Introducing many
24992 + original ideas, approaches and improvements, it becomes totally
24993 + different from Unionfs while keeping the basic features.
24997 + prompt "Maximum number of branches"
24998 + default AUFS_BRANCH_MAX_127
25000 + Specifies the maximum number of branches (or member directories)
25001 + in a single aufs. The larger value consumes more system
25002 + resources and has a minor impact to performance.
25003 +config AUFS_BRANCH_MAX_127
25006 + Specifies the maximum number of branches (or member directories)
25007 + in a single aufs. The larger value consumes more system
25008 + resources and has a minor impact to performance.
25009 +config AUFS_BRANCH_MAX_511
25012 + Specifies the maximum number of branches (or member directories)
25013 + in a single aufs. The larger value consumes more system
25014 + resources and has a minor impact to performance.
25015 +config AUFS_BRANCH_MAX_1023
25018 + Specifies the maximum number of branches (or member directories)
25019 + in a single aufs. The larger value consumes more system
25020 + resources and has a minor impact to performance.
25021 +config AUFS_BRANCH_MAX_32767
25024 + Specifies the maximum number of branches (or member directories)
25025 + in a single aufs. The larger value consumes more system
25026 + resources and has a minor impact to performance.
25029 +config AUFS_SBILIST
25031 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
25034 + Automatic configuration for internal use.
25035 + When aufs supports Magic SysRq or /proc, enabled automatically.
25037 +config AUFS_HNOTIFY
25038 + bool "Detect direct branch access (bypassing aufs)"
25040 + If you want to modify files on branches directly, eg. bypassing aufs,
25041 + and want aufs to detect the changes of them fully, then enable this
25042 + option and use 'udba=notify' mount option.
25043 + Currently there is only one available configuration, "fsnotify".
25044 + It will have a negative impact to the performance.
25045 + See detail in aufs.5.
25048 + prompt "method" if AUFS_HNOTIFY
25049 + default AUFS_HFSNOTIFY
25050 +config AUFS_HFSNOTIFY
25055 +config AUFS_EXPORT
25056 + bool "NFS-exportable aufs"
25057 + depends on EXPORTFS
25059 + If you want to export your mounted aufs via NFS, then enable this
25060 + option. There are several requirements for this configuration.
25061 + See detail in aufs.5.
25063 +config AUFS_INO_T_64
25065 + depends on AUFS_EXPORT
25066 + depends on 64BIT && !(ALPHA || S390)
25069 + Automatic configuration for internal use.
25070 + /* typedef unsigned long/int __kernel_ino_t */
25071 + /* alpha and s390x are int */
25074 + bool "support for XATTR/EA (including Security Labels)"
25076 + If your branch fs supports XATTR/EA and you want to make them
25077 + available in aufs too, then enable this opsion and specify the
25078 + branch attributes for EA.
25079 + See detail in aufs.5.
25082 + bool "File-based Hierarchical Storage Management"
25084 + Hierarchical Storage Management (or HSM) is a well-known feature
25085 + in the storage world. Aufs provides this feature as file-based.
25086 + with multiple branches.
25087 + These multiple branches are prioritized, ie. the topmost one
25088 + should be the fastest drive and be used heavily.
25091 + bool "Readdir in userspace"
25093 + Aufs has two methods to provide a merged view for a directory,
25094 + by a user-space library and by kernel-space natively. The latter
25095 + is always enabled but sometimes large and slow.
25096 + If you enable this option, install the library in aufs2-util
25097 + package, and set some environment variables for your readdir(3),
25098 + then the work will be handled in user-space which generally
25099 + shows better performance in most cases.
25100 + See detail in aufs.5.
25102 +config AUFS_DIRREN
25103 + bool "Workaround for rename(2)-ing a directory"
25105 + By default, aufs returns EXDEV error in renameing a dir who has
25106 + his child on the lower branch, since it is a bad idea to issue
25107 + rename(2) internally for every lower branch. But user may not
25108 + accept this behaviour. So here is a workaround to allow such
25109 + rename(2) and store some extra information on the writable
25110 + branch. Obviously this costs high (and I don't like it).
25111 + To use this feature, you need to enable this configuration AND
25112 + to specify the mount option `dirren.'
25113 + See details in aufs.5 and the design documents.
25116 + bool "Show whiteouts"
25118 + If you want to make the whiteouts in aufs visible, then enable
25119 + this option and specify 'shwh' mount option. Although it may
25120 + sounds like philosophy or something, but in technically it
25121 + simply shows the name of whiteout with keeping its behaviour.
25123 +config AUFS_BR_RAMFS
25124 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
25126 + If you want to use ramfs as an aufs branch fs, then enable this
25127 + option. Generally tmpfs is recommended.
25128 + Aufs prohibited them to be a branch fs by default, because
25129 + initramfs becomes unusable after switch_root or something
25130 + generally. If you sets initramfs as an aufs branch and boot your
25131 + system by switch_root, you will meet a problem easily since the
25132 + files in initramfs may be inaccessible.
25133 + Unless you are going to use ramfs as an aufs branch fs without
25134 + switch_root or something, leave it N.
25136 +config AUFS_BR_FUSE
25137 + bool "Fuse fs as an aufs branch"
25138 + depends on FUSE_FS
25141 + If you want to use fuse-based userspace filesystem as an aufs
25142 + branch fs, then enable this option.
25143 + It implements the internal poll(2) operation which is
25144 + implemented by fuse only (curretnly).
25149 + Automatic configuration for internal use.
25151 +config AUFS_BR_HFSPLUS
25152 + bool "Hfsplus as an aufs branch"
25153 + depends on HFSPLUS_FS
25156 + If you want to use hfsplus fs as an aufs branch fs, then enable
25157 + this option. This option introduces a small overhead at
25158 + copying-up a file on hfsplus.
25160 +config AUFS_BDEV_LOOP
25162 + depends on BLK_DEV_LOOP
25165 + Automatic configuration for internal use.
25166 + Convert =[ym] into =y.
25169 + bool "Debug aufs"
25171 + Enable this to compile aufs internal debug code.
25172 + It will have a negative impact to the performance.
25174 +config AUFS_MAGIC_SYSRQ
25176 + depends on AUFS_DEBUG && MAGIC_SYSRQ
25179 + Automatic configuration for internal use.
25180 + When aufs supports Magic SysRq, enabled automatically.
25182 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
25183 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
25184 +++ linux/fs/aufs/lcnt.h 2022-11-05 23:02:18.965889284 +0100
25186 +/* SPDX-License-Identifier: GPL-2.0 */
25188 + * Copyright (C) 2018-2022 Junjiro R. Okajima
25190 + * This program is free software; you can redistribute it and/or modify
25191 + * it under the terms of the GNU General Public License as published by
25192 + * the Free Software Foundation; either version 2 of the License, or
25193 + * (at your option) any later version.
25195 + * This program is distributed in the hope that it will be useful,
25196 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25197 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25198 + * GNU General Public License for more details.
25200 + * You should have received a copy of the GNU General Public License
25201 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25205 + * simple long counter wrapper
25208 +#ifndef __AUFS_LCNT_H__
25209 +#define __AUFS_LCNT_H__
25213 +#include "debug.h"
25215 +#define AuLCntATOMIC 1
25216 +#define AuLCntPCPUCNT 2
25218 + * why does percpu_refcount require extra synchronize_rcu()s in
25219 + * au_br_do_free()
25221 +#define AuLCntPCPUREF 3
25223 +/* #define AuLCntChosen AuLCntATOMIC */
25224 +#define AuLCntChosen AuLCntPCPUCNT
25225 +/* #define AuLCntChosen AuLCntPCPUREF */
25227 +#if AuLCntChosen == AuLCntATOMIC
25228 +#include <linux/atomic.h>
25230 +typedef atomic_long_t au_lcnt_t;
25232 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
25234 + atomic_long_set(cnt, 0);
25238 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25243 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
25244 + int do_sync __maybe_unused)
25249 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25251 + atomic_long_inc(cnt);
25254 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25256 + atomic_long_dec(cnt);
25259 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
25261 + return atomic_long_read(cnt);
25265 +#if AuLCntChosen == AuLCntPCPUCNT
25266 +#include <linux/percpu_counter.h>
25268 +typedef struct percpu_counter au_lcnt_t;
25270 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
25272 + return percpu_counter_init(cnt, 0, GFP_NOFS);
25275 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25280 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
25282 + percpu_counter_destroy(cnt);
25285 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25287 + percpu_counter_inc(cnt);
25290 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25292 + percpu_counter_dec(cnt);
25295 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
25299 + n = percpu_counter_sum(cnt);
25301 + if (LONG_MAX != LLONG_MAX
25303 + AuWarn1("%s\n", "wrap-around");
25309 +#if AuLCntChosen == AuLCntPCPUREF
25310 +#include <linux/percpu-refcount.h>
25312 +typedef struct percpu_ref au_lcnt_t;
25314 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
25317 + release = percpu_ref_exit;
25318 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
25321 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25323 + synchronize_rcu();
25326 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
25328 + percpu_ref_kill(cnt);
25330 + au_lcnt_wait_for_fin(cnt);
25333 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25335 + percpu_ref_get(cnt);
25338 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25340 + percpu_ref_put(cnt);
25344 + * avoid calling this func as possible.
25346 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
25350 + percpu_ref_switch_to_atomic_sync(cnt);
25351 + l = atomic_long_read(&cnt->count);
25353 + percpu_ref_switch_to_percpu(cnt);
25355 + /* percpu_ref is initialized by 1 instead of 0 */
25360 +#ifdef CONFIG_AUFS_DEBUG
25361 +#define AuLCntZero(val) do { \
25364 + AuDbg("%s = %ld\n", #val, l); \
25367 +#define AuLCntZero(val) do {} while (0)
25370 +#endif /* __KERNEL__ */
25371 +#endif /* __AUFS_LCNT_H__ */
25372 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
25373 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
25374 +++ linux/fs/aufs/loop.c 2022-11-05 23:02:18.965889284 +0100
25376 +// SPDX-License-Identifier: GPL-2.0
25378 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25380 + * This program is free software; you can redistribute it and/or modify
25381 + * it under the terms of the GNU General Public License as published by
25382 + * the Free Software Foundation; either version 2 of the License, or
25383 + * (at your option) any later version.
25385 + * This program is distributed in the hope that it will be useful,
25386 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25387 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25388 + * GNU General Public License for more details.
25390 + * You should have received a copy of the GNU General Public License
25391 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25395 + * support for loopback block device as a branch
25400 +/* added into drivers/block/loop.c */
25401 +static struct file *(*backing_file_func)(struct super_block *sb);
25404 + * test if two lower dentries have overlapping branches.
25406 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
25408 + struct super_block *h_sb;
25409 + struct file *backing_file;
25411 + if (unlikely(!backing_file_func)) {
25412 + /* don't load "loop" module here */
25413 + backing_file_func = symbol_get(loop_backing_file);
25414 + if (unlikely(!backing_file_func))
25415 + /* "loop" module is not loaded */
25419 + h_sb = h_adding->d_sb;
25420 + backing_file = backing_file_func(h_sb);
25421 + if (!backing_file)
25424 + h_adding = backing_file->f_path.dentry;
25426 + * h_adding can be local NFS.
25427 + * in this case aufs cannot detect the loop.
25429 + if (unlikely(h_adding->d_sb == sb))
25431 + return !!au_test_subdir(h_adding, sb->s_root);
25434 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
25435 +int au_test_loopback_kthread(void)
25438 + struct task_struct *tsk = current;
25439 + char c, comm[sizeof(tsk->comm)];
25442 + if (tsk->flags & PF_KTHREAD) {
25443 + get_task_comm(comm, tsk);
25445 + ret = ('0' <= c && c <= '9'
25446 + && !strncmp(comm, "loop", 4));
25452 +/* ---------------------------------------------------------------------- */
25454 +#define au_warn_loopback_step 16
25455 +static int au_warn_loopback_nelem = au_warn_loopback_step;
25456 +static unsigned long *au_warn_loopback_array;
25458 +void au_warn_loopback(struct super_block *h_sb)
25460 + int i, new_nelem;
25461 + unsigned long *a, magic;
25462 + static DEFINE_SPINLOCK(spin);
25464 + magic = h_sb->s_magic;
25465 + spin_lock(&spin);
25466 + a = au_warn_loopback_array;
25467 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
25468 + if (a[i] == magic) {
25469 + spin_unlock(&spin);
25473 + /* h_sb is new to us, print it */
25474 + if (i < au_warn_loopback_nelem) {
25479 + /* expand the array */
25480 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
25481 + a = au_kzrealloc(au_warn_loopback_array,
25482 + au_warn_loopback_nelem * sizeof(unsigned long),
25483 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
25484 + /*may_shrink*/0);
25486 + au_warn_loopback_nelem = new_nelem;
25487 + au_warn_loopback_array = a;
25492 + spin_unlock(&spin);
25493 + AuWarn1("realloc failed, ignored\n");
25497 + spin_unlock(&spin);
25498 + pr_warn("you may want to try another patch for loopback file "
25499 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
25502 +int au_loopback_init(void)
25505 + struct super_block *sb __maybe_unused;
25507 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
25510 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
25511 + sizeof(unsigned long), GFP_NOFS);
25512 + if (unlikely(!au_warn_loopback_array))
25518 +void au_loopback_fin(void)
25520 + if (backing_file_func)
25521 + symbol_put(loop_backing_file);
25522 + au_kfree_try_rcu(au_warn_loopback_array);
25524 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
25525 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
25526 +++ linux/fs/aufs/loop.h 2022-11-05 23:02:18.965889284 +0100
25528 +/* SPDX-License-Identifier: GPL-2.0 */
25530 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25532 + * This program is free software; you can redistribute it and/or modify
25533 + * it under the terms of the GNU General Public License as published by
25534 + * the Free Software Foundation; either version 2 of the License, or
25535 + * (at your option) any later version.
25537 + * This program is distributed in the hope that it will be useful,
25538 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25539 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25540 + * GNU General Public License for more details.
25542 + * You should have received a copy of the GNU General Public License
25543 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25547 + * support for loopback mount as a branch
25550 +#ifndef __AUFS_LOOP_H__
25551 +#define __AUFS_LOOP_H__
25556 +struct super_block;
25558 +#ifdef CONFIG_AUFS_BDEV_LOOP
25559 +/* drivers/block/loop.c */
25560 +struct file *loop_backing_file(struct super_block *sb);
25563 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
25564 +int au_test_loopback_kthread(void);
25565 +void au_warn_loopback(struct super_block *h_sb);
25567 +int au_loopback_init(void);
25568 +void au_loopback_fin(void);
25570 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
25572 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
25573 + struct dentry *h_adding)
25574 +AuStubInt0(au_test_loopback_kthread, void)
25575 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
25577 +AuStubInt0(au_loopback_init, void)
25578 +AuStubVoid(au_loopback_fin, void)
25579 +#endif /* BLK_DEV_LOOP */
25581 +#endif /* __KERNEL__ */
25582 +#endif /* __AUFS_LOOP_H__ */
25583 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
25584 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
25585 +++ linux/fs/aufs/magic.mk 2022-11-05 23:02:18.965889284 +0100
25587 +# SPDX-License-Identifier: GPL-2.0
25589 +# defined in ${srctree}/fs/fuse/inode.c
25591 +ifdef CONFIG_FUSE_FS
25592 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
25595 +# defined in ${srctree}/fs/xfs/xfs_sb.h
25597 +ifdef CONFIG_XFS_FS
25598 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
25601 +# defined in ${srctree}/fs/configfs/mount.c
25603 +ifdef CONFIG_CONFIGFS_FS
25604 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
25607 +# defined in ${srctree}/fs/ubifs/ubifs.h
25609 +ifdef CONFIG_UBIFS_FS
25610 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
25613 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
25615 +ifdef CONFIG_HFSPLUS_FS
25616 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
25618 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
25619 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
25620 +++ linux/fs/aufs/Makefile 2022-11-05 23:02:18.959222617 +0100
25622 +# SPDX-License-Identifier: GPL-2.0
25624 +include ${src}/magic.mk
25625 +ifeq (${CONFIG_AUFS_FS},m)
25626 +include ${src}/conf.mk
25628 +-include ${src}/priv_def.mk
25630 +# cf. include/linux/kernel.h
25632 +ccflags-y += -DDEBUG
25633 +# sparse requires the full pathname
25635 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
25637 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
25640 +obj-$(CONFIG_AUFS_FS) += aufs.o
25641 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o fsctx.o \
25642 + wkq.o vfsub.o dcsub.o \
25643 + cpup.o whout.o wbr_policy.o \
25644 + dinfo.o dentry.o \
25646 + finfo.o file.o f_op.o \
25648 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
25652 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
25653 +aufs-$(CONFIG_SYSFS) += sysfs.o
25654 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
25655 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
25656 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
25657 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
25658 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
25659 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
25660 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
25661 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
25662 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
25663 +aufs-$(CONFIG_AUFS_POLL) += poll.o
25664 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
25665 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
25666 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
25667 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
25668 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
25669 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
25670 +++ linux/fs/aufs/module.c 2022-11-05 23:02:18.965889284 +0100
25672 +// SPDX-License-Identifier: GPL-2.0
25674 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25676 + * This program is free software; you can redistribute it and/or modify
25677 + * it under the terms of the GNU General Public License as published by
25678 + * the Free Software Foundation; either version 2 of the License, or
25679 + * (at your option) any later version.
25681 + * This program is distributed in the hope that it will be useful,
25682 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25683 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25684 + * GNU General Public License for more details.
25686 + * You should have received a copy of the GNU General Public License
25687 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25691 + * module global variables and operations
25694 +#include <linux/module.h>
25695 +#include <linux/seq_file.h>
25698 +/* shrinkable realloc */
25699 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
25707 +#if 0 /* unused */
25714 + AuDebugOn(!new_sz);
25717 + diff = au_kmidx_sub(sz, new_sz);
25723 + /* expand or SLOB */
25724 + p = krealloc(p, new_sz, gfp);
25725 + else if (new_sz < sz && may_shrink) {
25729 + q = kmalloc(new_sz, gfp);
25732 + memcpy(q, p, new_sz);
25733 + au_kfree_try_rcu(p);
25744 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
25747 + p = au_krealloc(p, new_sz, gfp, may_shrink);
25748 + if (p && new_sz > nused)
25749 + memset(p + nused, 0, new_sz - nused);
25753 +/* ---------------------------------------------------------------------- */
25757 +struct kmem_cache *au_cache[AuCache_Last];
25759 +static void au_cache_fin(void)
25764 + * Make sure all delayed rcu free inodes are flushed before we
25769 + /* excluding AuCache_HNOTIFY */
25770 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
25771 + for (i = 0; i < AuCache_HNOTIFY; i++) {
25772 + kmem_cache_destroy(au_cache[i]);
25773 + au_cache[i] = NULL;
25777 +static int __init au_cache_init(void)
25779 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
25780 + if (au_cache[AuCache_DINFO])
25781 + /* SLAB_DESTROY_BY_RCU */
25782 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
25783 + au_icntnr_init_once);
25784 + if (au_cache[AuCache_ICNTNR])
25785 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
25786 + au_fi_init_once);
25787 + if (au_cache[AuCache_FINFO])
25788 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
25789 + if (au_cache[AuCache_VDIR])
25790 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
25791 + if (au_cache[AuCache_DEHSTR])
25798 +/* ---------------------------------------------------------------------- */
25800 +int au_dir_roflags;
25802 +#ifdef CONFIG_AUFS_SBILIST
25804 + * iterate_supers_type() doesn't protect us from
25805 + * remounting (branch management)
25807 +struct hlist_bl_head au_sbilist;
25811 + * functions for module interface.
25813 +MODULE_LICENSE("GPL");
25814 +/* MODULE_LICENSE("GPL v2"); */
25815 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
25816 +MODULE_DESCRIPTION(AUFS_NAME
25817 + " -- Advanced multi layered unification filesystem");
25818 +MODULE_VERSION(AUFS_VERSION);
25819 +MODULE_ALIAS_FS(AUFS_NAME);
25821 +/* this module parameter has no meaning when SYSFS is disabled */
25822 +int sysaufs_brs = 1;
25823 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
25824 +module_param_named(brs, sysaufs_brs, int, 0444);
25826 +/* this module parameter has no meaning when USER_NS is disabled */
25828 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
25829 +module_param_named(allow_userns, au_userns, bool, 0444);
25831 +/* ---------------------------------------------------------------------- */
25833 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
25835 +int au_seq_path(struct seq_file *seq, struct path *path)
25839 + err = seq_path(seq, path, au_esc_chars);
25848 +/* ---------------------------------------------------------------------- */
25850 +static int __init aufs_init(void)
25855 + p = au_esc_chars;
25856 + for (i = 1; i <= ' '; i++)
25862 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
25864 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
25865 + for (i = 0; i < AuIop_Last; i++)
25866 + aufs_iop_nogetattr[i].getattr = NULL;
25868 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
25870 + au_sbilist_init();
25871 + sysaufs_brs_init();
25874 + err = sysaufs_init();
25875 + if (unlikely(err))
25877 + err = dbgaufs_init();
25878 + if (unlikely(err))
25879 + goto out_sysaufs;
25880 + err = au_procfs_init();
25881 + if (unlikely(err))
25882 + goto out_dbgaufs;
25883 + err = au_wkq_init();
25884 + if (unlikely(err))
25886 + err = au_loopback_init();
25887 + if (unlikely(err))
25889 + err = au_hnotify_init();
25890 + if (unlikely(err))
25891 + goto out_loopback;
25892 + err = au_sysrq_init();
25893 + if (unlikely(err))
25895 + err = au_cache_init();
25896 + if (unlikely(err))
25899 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
25900 + err = register_filesystem(&aufs_fs_type);
25901 + if (unlikely(err))
25904 + /* since we define pr_fmt, call printk directly */
25905 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
25906 + goto out; /* success */
25913 + au_hnotify_fin();
25915 + au_loopback_fin();
25929 +static void __exit aufs_exit(void)
25931 + unregister_filesystem(&aufs_fs_type);
25934 + au_hnotify_fin();
25935 + au_loopback_fin();
25943 +module_init(aufs_init);
25944 +module_exit(aufs_exit);
25945 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
25946 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
25947 +++ linux/fs/aufs/module.h 2022-11-05 23:02:18.969222617 +0100
25949 +/* SPDX-License-Identifier: GPL-2.0 */
25951 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25953 + * This program is free software; you can redistribute it and/or modify
25954 + * it under the terms of the GNU General Public License as published by
25955 + * the Free Software Foundation; either version 2 of the License, or
25956 + * (at your option) any later version.
25958 + * This program is distributed in the hope that it will be useful,
25959 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25960 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25961 + * GNU General Public License for more details.
25963 + * You should have received a copy of the GNU General Public License
25964 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25968 + * module initialization and module-global
25971 +#ifndef __AUFS_MODULE_H__
25972 +#define __AUFS_MODULE_H__
25976 +#include <linux/slab.h>
25977 +#include "debug.h"
25978 +#include "dentry.h"
25981 +#include "inode.h"
25986 +/* module parameters */
25987 +extern int sysaufs_brs;
25988 +extern bool au_userns;
25990 +/* ---------------------------------------------------------------------- */
25992 +extern int au_dir_roflags;
25994 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
25995 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
25999 + * Comparing the size of the object with sizeof(struct rcu_head)
26000 + * case 1: object is always larger
26001 + * --> au_kfree_rcu() or au_kfree_do_rcu()
26002 + * case 2: object is always smaller
26003 + * --> au_kfree_small()
26004 + * case 3: object can be any size
26005 + * --> au_kfree_try_rcu()
26008 +static inline void au_kfree_do_rcu(const void *p)
26011 + struct rcu_head rcu;
26012 + } *a = (void *)p;
26014 + kfree_rcu(a, rcu);
26017 +#define au_kfree_rcu(_p) do { \
26018 + typeof(_p) p = (_p); \
26019 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
26021 + au_kfree_do_rcu(p); \
26024 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
26025 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
26027 +static inline void au_kfree_try_rcu(const void *p)
26031 + if (au_kfree_sz_test(p))
26032 + au_kfree_do_rcu(p);
26037 +static inline void au_kfree_small(const void *p)
26041 + AuDebugOn(au_kfree_sz_test(p));
26045 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
26047 +#ifndef CONFIG_SLOB
26048 + return __kmalloc_index(sz, false) - __kmalloc_index(new_sz, false);
26050 + return -1; /* SLOB is untested */
26054 +int au_seq_path(struct seq_file *seq, struct path *path);
26056 +#ifdef CONFIG_PROC_FS
26058 +int __init au_procfs_init(void);
26059 +void au_procfs_fin(void);
26061 +AuStubInt0(au_procfs_init, void);
26062 +AuStubVoid(au_procfs_fin, void);
26065 +/* ---------------------------------------------------------------------- */
26074 + AuCache_HNOTIFY, /* must be last */
26078 +extern struct kmem_cache *au_cache[AuCache_Last];
26080 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
26081 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
26082 +#define AuCacheCtor(type, ctor) \
26083 + kmem_cache_create(#type, sizeof(struct type), \
26084 + __alignof__(struct type), AuCacheFlags, ctor)
26086 +#define AuCacheFuncAlloc(name, index) \
26087 + static inline struct au_##name *au_cache_alloc_##name(void) \
26088 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); }
26090 +#define AuCacheFuncs(name, index) \
26091 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
26092 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
26094 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
26095 + { void *p = rcu; \
26096 + p -= offsetof(struct au_##name, rcu); \
26097 + kmem_cache_free(au_cache[AuCache_##index], p); } \
26098 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
26099 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
26100 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
26102 + static inline void au_cache_free_##name(struct au_##name *p) \
26103 + { /* au_cache_free_##name##_norcu(p); */ \
26104 + au_cache_free_##name##_rcu(p); }
26106 +AuCacheFuncs(dinfo, DINFO);
26107 +AuCacheFuncAlloc(dinfo, DINFO);
26109 +AuCacheFuncs(icntnr, ICNTNR);
26110 +static inline struct au_icntnr *au_cache_alloc_icntnr(struct super_block *sb)
26111 +{ return alloc_inode_sb(sb, au_cache[AuCache_ICNTNR], GFP_NOFS); }
26113 +AuCacheFuncs(finfo, FINFO);
26114 +AuCacheFuncAlloc(finfo, FINFO);
26116 +AuCacheFuncs(vdir, VDIR);
26117 +AuCacheFuncAlloc(vdir, VDIR);
26119 +AuCacheFuncs(vdir_dehstr, DEHSTR);
26120 +AuCacheFuncAlloc(vdir_dehstr, DEHSTR);
26122 +#ifdef CONFIG_AUFS_HNOTIFY
26123 +AuCacheFuncs(hnotify, HNOTIFY);
26124 +AuCacheFuncAlloc(hnotify, HNOTIFY);
26127 +#endif /* __KERNEL__ */
26128 +#endif /* __AUFS_MODULE_H__ */
26129 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
26130 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
26131 +++ linux/fs/aufs/mvdown.c 2022-11-05 23:02:18.969222617 +0100
26133 +// SPDX-License-Identifier: GPL-2.0
26135 + * Copyright (C) 2011-2022 Junjiro R. Okajima
26137 + * This program is free software; you can redistribute it and/or modify
26138 + * it under the terms of the GNU General Public License as published by
26139 + * the Free Software Foundation; either version 2 of the License, or
26140 + * (at your option) any later version.
26142 + * This program is distributed in the hope that it will be useful,
26143 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26144 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26145 + * GNU General Public License for more details.
26147 + * You should have received a copy of the GNU General Public License
26148 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26152 + * move-down, opposite of copy-up
26157 +struct au_mvd_args {
26159 + struct super_block *h_sb;
26160 + struct dentry *h_parent;
26161 + struct au_hinode *hdir;
26162 + struct inode *h_dir, *h_inode;
26163 + struct au_pin pin;
26164 + } info[AUFS_MVDOWN_NARRAY];
26166 + struct aufs_mvdown mvdown;
26167 + struct dentry *dentry, *parent;
26168 + struct inode *inode, *dir;
26169 + struct super_block *sb;
26170 + aufs_bindex_t bopq, bwh, bfound;
26171 + unsigned char rename_lock;
26174 +#define mvd_errno mvdown.au_errno
26175 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
26176 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
26177 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
26178 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
26180 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
26181 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
26182 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
26183 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
26184 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
26185 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
26187 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
26188 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
26189 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
26190 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
26191 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
26192 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
26194 +#define AU_MVD_PR(flag, ...) do { \
26196 + pr_err(__VA_ARGS__); \
26199 +static int find_lower_writable(struct au_mvd_args *a)
26201 + struct super_block *sb;
26202 + aufs_bindex_t bindex, bbot;
26203 + struct au_branch *br;
26206 + bindex = a->mvd_bsrc;
26207 + bbot = au_sbbot(sb);
26208 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
26209 + for (bindex++; bindex <= bbot; bindex++) {
26210 + br = au_sbr(sb, bindex);
26211 + if (au_br_fhsm(br->br_perm)
26212 + && !sb_rdonly(au_br_sb(br)))
26215 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
26216 + for (bindex++; bindex <= bbot; bindex++) {
26217 + br = au_sbr(sb, bindex);
26218 + if (!au_br_rdonly(br))
26222 + for (bindex++; bindex <= bbot; bindex++) {
26223 + br = au_sbr(sb, bindex);
26224 + if (!sb_rdonly(au_br_sb(br))) {
26225 + if (au_br_rdonly(br))
26227 + |= AUFS_MVDOWN_ROLOWER_R;
26235 +/* make the parent dir on bdst */
26236 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
26241 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
26242 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
26243 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
26244 + a->mvd_h_dst_parent = NULL;
26245 + if (au_dbbot(a->parent) >= a->mvd_bdst)
26246 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
26247 + if (!a->mvd_h_dst_parent) {
26248 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
26249 + if (unlikely(err)) {
26250 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
26253 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
26261 +/* lock them all */
26262 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
26265 + struct dentry *h_trap;
26267 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
26268 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
26269 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
26270 + au_opt_udba(a->sb),
26271 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26273 + if (unlikely(err)) {
26274 + AU_MVD_PR(dmsg, "pin_dst failed\n");
26278 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
26279 + a->rename_lock = 0;
26280 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
26281 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
26282 + au_opt_udba(a->sb),
26283 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26284 + err = au_do_pin(&a->mvd_pin_src);
26286 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
26287 + if (unlikely(err)) {
26288 + AU_MVD_PR(dmsg, "pin_src failed\n");
26291 + goto out; /* success */
26294 + a->rename_lock = 1;
26295 + au_pin_hdir_unlock(&a->mvd_pin_dst);
26296 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
26297 + au_opt_udba(a->sb),
26298 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26300 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
26301 + if (unlikely(err)) {
26302 + AU_MVD_PR(dmsg, "pin_src failed\n");
26303 + au_pin_hdir_lock(&a->mvd_pin_dst);
26306 + au_pin_hdir_unlock(&a->mvd_pin_src);
26307 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26308 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26310 + err = (h_trap != a->mvd_h_src_parent);
26312 + err = (h_trap != a->mvd_h_dst_parent);
26314 + BUG_ON(err); /* it should never happen */
26315 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
26318 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26319 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26320 + au_pin_hdir_lock(&a->mvd_pin_src);
26321 + au_unpin(&a->mvd_pin_src);
26322 + au_pin_hdir_lock(&a->mvd_pin_dst);
26325 + goto out; /* success */
26328 + au_unpin(&a->mvd_pin_dst);
26334 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
26336 + if (!a->rename_lock)
26337 + au_unpin(&a->mvd_pin_src);
26339 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26340 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26341 + au_pin_hdir_lock(&a->mvd_pin_src);
26342 + au_unpin(&a->mvd_pin_src);
26343 + au_pin_hdir_lock(&a->mvd_pin_dst);
26345 + au_unpin(&a->mvd_pin_dst);
26348 +/* copy-down the file */
26349 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
26352 + struct au_cp_generic cpg = {
26353 + .dentry = a->dentry,
26354 + .bdst = a->mvd_bdst,
26355 + .bsrc = a->mvd_bsrc,
26357 + .pin = &a->mvd_pin_dst,
26358 + .flags = AuCpup_DTIME | AuCpup_HOPEN
26361 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
26362 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
26363 + au_fset_cpup(cpg.flags, OVERWRITE);
26364 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
26365 + au_fset_cpup(cpg.flags, RWDST);
26366 + err = au_sio_cpdown_simple(&cpg);
26367 + if (unlikely(err))
26368 + AU_MVD_PR(dmsg, "cpdown failed\n");
26375 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
26378 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
26381 + struct path h_path;
26382 + struct au_branch *br;
26383 + struct inode *delegated;
26385 + br = au_sbr(a->sb, a->mvd_bdst);
26386 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
26387 + err = PTR_ERR(h_path.dentry);
26388 + if (IS_ERR(h_path.dentry)) {
26389 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
26394 + if (d_is_positive(h_path.dentry)) {
26395 + h_path.mnt = au_br_mnt(br);
26396 + delegated = NULL;
26397 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
26398 + &delegated, /*force*/0);
26399 + if (unlikely(err == -EWOULDBLOCK)) {
26400 + pr_warn("cannot retry for NFSv4 delegation"
26401 + " for an internal unlink\n");
26404 + if (unlikely(err))
26405 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
26407 + dput(h_path.dentry);
26415 + * unlink the topmost h_dentry
26417 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
26420 + struct path h_path;
26421 + struct inode *delegated;
26423 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
26424 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
26425 + delegated = NULL;
26426 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
26427 + if (unlikely(err == -EWOULDBLOCK)) {
26428 + pr_warn("cannot retry for NFSv4 delegation"
26429 + " for an internal unlink\n");
26432 + if (unlikely(err))
26433 + AU_MVD_PR(dmsg, "unlink failed\n");
26439 +/* Since mvdown succeeded, we ignore an error of this function */
26440 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
26443 + struct au_branch *br;
26445 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
26446 + br = au_sbr(a->sb, a->mvd_bsrc);
26447 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
26449 + br = au_sbr(a->sb, a->mvd_bdst);
26450 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
26451 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
26454 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
26456 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
26460 + * copy-down the file and unlink the bsrc file.
26461 + * - unlink the bdst whout if exist
26462 + * - copy-down the file (with whtmp name and rename)
26463 + * - unlink the bsrc file
26465 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
26469 + err = au_do_mkdir(dmsg, a);
26471 + err = au_do_lock(dmsg, a);
26472 + if (unlikely(err))
26476 + * do not revert the activities we made on bdst since they should be
26477 + * harmless in aufs.
26480 + err = au_do_cpdown(dmsg, a);
26482 + err = au_do_unlink_wh(dmsg, a);
26483 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
26484 + err = au_do_unlink(dmsg, a);
26485 + if (unlikely(err))
26488 + AuDbg("%pd2, 0x%x, %d --> %d\n",
26489 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
26490 + if (find_lower_writable(a) < 0)
26491 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
26493 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
26494 + au_do_stfs(dmsg, a);
26496 + /* maintain internal array */
26497 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
26498 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
26499 + au_set_dbtop(a->dentry, a->mvd_bdst);
26500 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
26501 + au_set_ibtop(a->inode, a->mvd_bdst);
26503 + /* hide the lower */
26504 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
26505 + au_set_dbbot(a->dentry, a->mvd_bsrc);
26506 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
26507 + au_set_ibbot(a->inode, a->mvd_bsrc);
26509 + if (au_dbbot(a->dentry) < a->mvd_bdst)
26510 + au_set_dbbot(a->dentry, a->mvd_bdst);
26511 + if (au_ibbot(a->inode) < a->mvd_bdst)
26512 + au_set_ibbot(a->inode, a->mvd_bdst);
26515 + au_do_unlock(dmsg, a);
26521 +/* ---------------------------------------------------------------------- */
26523 +/* make sure the file is idle */
26524 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
26526 + int err, plinked;
26529 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
26530 + if (au_dbtop(a->dentry) == a->mvd_bsrc
26531 + && au_dcount(a->dentry) == 1
26532 + && atomic_read(&a->inode->i_count) == 1
26533 + /* && a->mvd_h_src_inode->i_nlink == 1 */
26534 + && (!plinked || !au_plink_test(a->inode))
26535 + && a->inode->i_nlink == 1)
26540 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
26541 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
26542 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
26543 + a->mvd_h_src_inode->i_nlink,
26544 + plinked, plinked ? au_plink_test(a->inode) : 0);
26551 +/* make sure the parent dir is fine */
26552 +static int au_mvd_args_parent(const unsigned char dmsg,
26553 + struct au_mvd_args *a)
26556 + aufs_bindex_t bindex;
26559 + if (unlikely(au_alive_dir(a->parent))) {
26561 + AU_MVD_PR(dmsg, "parent dir is dead\n");
26565 + a->bopq = au_dbdiropq(a->parent);
26566 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
26567 + AuDbg("b%d\n", bindex);
26568 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
26569 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
26571 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
26572 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
26573 + a->bopq, a->mvd_bdst);
26581 +static int au_mvd_args_intermediate(const unsigned char dmsg,
26582 + struct au_mvd_args *a)
26585 + struct au_dinfo *dinfo, *tmp;
26587 + /* lookup the next lower positive entry */
26589 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
26590 + if (unlikely(!tmp))
26595 + dinfo = au_di(a->dentry);
26596 + au_di_cp(tmp, dinfo);
26597 + au_di_swap(tmp, dinfo);
26599 + /* returns the number of positive dentries */
26600 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
26601 + /* AuLkup_IGNORE_PERM */ 0);
26603 + a->bwh = au_dbwh(a->dentry);
26604 + else if (err > 0)
26605 + a->bfound = au_dbtop(a->dentry);
26607 + au_di_swap(tmp, dinfo);
26608 + au_rw_write_unlock(&tmp->di_rwsem);
26610 + if (unlikely(err < 0))
26611 + AU_MVD_PR(dmsg, "failed look-up lower\n");
26614 + * here, we have these cases.
26616 + * no positive dentry under bsrc. there are more sub-cases.
26618 + * there no whiteout, we can safely move-down.
26621 + * bsrc < bwh && bwh < bdst
26622 + * there is a whiteout on RO branch. cannot proceed.
26624 + * there is a whiteout on the RW target branch. it should
26627 + * there is a whiteout somewhere unrelated branch.
26628 + * -1 < bfound && bfound <= bsrc
26631 + * found, but it is on RO branch between bsrc and bdst. cannot
26634 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
26637 + * found, after we create the file on bdst, it will be hidden.
26640 + AuDebugOn(a->bfound == -1
26642 + && a->bwh <= a->mvd_bsrc);
26643 + AuDebugOn(-1 < a->bfound
26644 + && a->bfound <= a->mvd_bsrc);
26647 + if (a->bfound == -1
26648 + && a->mvd_bsrc < a->bwh
26650 + && a->bwh < a->mvd_bdst) {
26651 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
26652 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
26653 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
26655 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
26656 + a->mvd_errno = EAU_MVDOWN_UPPER;
26657 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
26658 + a->mvd_bdst, a->bfound);
26662 + err = 0; /* success */
26669 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
26674 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
26675 + && a->bfound == a->mvd_bdst)
26681 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
26684 + struct au_branch *br;
26687 + if (unlikely(S_ISDIR(a->inode->i_mode)))
26691 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
26692 + a->mvd_bsrc = au_ibtop(a->inode);
26694 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
26695 + if (unlikely(a->mvd_bsrc < 0
26696 + || (a->mvd_bsrc < au_dbtop(a->dentry)
26697 + || au_dbbot(a->dentry) < a->mvd_bsrc
26698 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
26699 + || (a->mvd_bsrc < au_ibtop(a->inode)
26700 + || au_ibbot(a->inode) < a->mvd_bsrc
26701 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
26702 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
26703 + AU_MVD_PR(dmsg, "no upper\n");
26707 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
26708 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
26709 + AU_MVD_PR(dmsg, "on the bottom\n");
26712 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
26713 + br = au_sbr(a->sb, a->mvd_bsrc);
26714 + err = au_br_rdonly(br);
26715 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
26716 + if (unlikely(err))
26718 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
26719 + || IS_APPEND(a->mvd_h_src_inode))) {
26721 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
26727 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
26728 + a->mvd_bdst = find_lower_writable(a);
26729 + if (unlikely(a->mvd_bdst < 0)) {
26730 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
26731 + AU_MVD_PR(dmsg, "no writable lower branch\n");
26735 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
26736 + if (unlikely(a->mvd_bdst < 0
26737 + || au_sbbot(a->sb) < a->mvd_bdst)) {
26738 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
26739 + AU_MVD_PR(dmsg, "no lower brid\n");
26744 + err = au_mvd_args_busy(dmsg, a);
26746 + err = au_mvd_args_parent(dmsg, a);
26748 + err = au_mvd_args_intermediate(dmsg, a);
26750 + err = au_mvd_args_exist(dmsg, a);
26752 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
26759 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
26762 + unsigned char dmsg;
26763 + struct au_mvd_args *args;
26764 + struct inode *inode;
26766 + inode = d_inode(dentry);
26768 + if (unlikely(!capable(CAP_SYS_ADMIN)))
26772 + args = kmalloc(sizeof(*args), GFP_NOFS);
26773 + if (unlikely(!args))
26776 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
26778 + /* VERIFY_WRITE */
26779 + err = !access_ok(uarg, sizeof(*uarg));
26780 + if (unlikely(err)) {
26785 + AuDbg("flags 0x%x\n", args->mvdown.flags);
26786 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
26787 + args->mvdown.au_errno = 0;
26788 + args->dentry = dentry;
26789 + args->inode = inode;
26790 + args->sb = dentry->d_sb;
26793 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
26794 + args->parent = dget_parent(dentry);
26795 + args->dir = d_inode(args->parent);
26796 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
26797 + dput(args->parent);
26798 + if (unlikely(args->parent != dentry->d_parent)) {
26799 + AU_MVD_PR(dmsg, "parent dir is moved\n");
26803 + inode_lock_nested(inode, I_MUTEX_CHILD);
26804 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
26805 + if (unlikely(err))
26808 + di_write_lock_parent(args->parent);
26809 + err = au_mvd_args(dmsg, args);
26810 + if (unlikely(err))
26813 + err = au_do_mvdown(dmsg, args);
26814 + if (unlikely(err))
26817 + au_cpup_attr_timesizes(args->dir);
26818 + au_cpup_attr_timesizes(inode);
26819 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
26820 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
26821 + /* au_digen_dec(dentry); */
26824 + di_write_unlock(args->parent);
26825 + aufs_read_unlock(dentry, AuLock_DW);
26827 + inode_unlock(inode);
26829 + inode_unlock(args->dir);
26831 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
26834 + au_kfree_rcu(args);
26839 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
26840 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
26841 +++ linux/fs/aufs/opts.c 2022-11-05 23:02:18.969222617 +0100
26843 +// SPDX-License-Identifier: GPL-2.0
26845 + * Copyright (C) 2005-2022 Junjiro R. Okajima
26847 + * This program is free software; you can redistribute it and/or modify
26848 + * it under the terms of the GNU General Public License as published by
26849 + * the Free Software Foundation; either version 2 of the License, or
26850 + * (at your option) any later version.
26852 + * This program is distributed in the hope that it will be useful,
26853 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26854 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26855 + * GNU General Public License for more details.
26857 + * You should have received a copy of the GNU General Public License
26858 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26862 + * mount options/flags
26865 +#include <linux/types.h> /* a distribution requires */
26866 +#include <linux/parser.h>
26869 +/* ---------------------------------------------------------------------- */
26871 +static const char *au_parser_pattern(int val, match_table_t tbl)
26873 + struct match_token *p;
26876 + while (p->pattern) {
26877 + if (p->token == val)
26878 + return p->pattern;
26885 +static const char *au_optstr(int *val, match_table_t tbl)
26887 + struct match_token *p;
26894 + while (p->pattern) {
26896 + && (v & p->token) == p->token) {
26897 + *val &= ~p->token;
26898 + return p->pattern;
26907 +/* ---------------------------------------------------------------------- */
26909 +static match_table_t brperm = {
26910 + {AuBrPerm_RO, AUFS_BRPERM_RO},
26911 + {AuBrPerm_RR, AUFS_BRPERM_RR},
26912 + {AuBrPerm_RW, AUFS_BRPERM_RW},
26916 +static match_table_t brattr = {
26918 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
26919 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
26920 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
26921 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
26922 +#ifdef CONFIG_AUFS_FHSM
26923 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
26925 +#ifdef CONFIG_AUFS_XATTR
26926 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
26927 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
26928 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
26929 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
26930 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
26931 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
26934 + /* ro/rr branch */
26935 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
26938 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
26939 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
26944 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
26951 + p = strchr(str, '+');
26954 + v = match_token(str, table, args);
26956 + if (v & AuBrAttr_CMOO_Mask)
26957 + attr &= ~AuBrAttr_CMOO_Mask;
26962 + pr_warn("ignored branch attribute %s\n", str);
26972 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
26980 + p = au_optstr(&perm, brattr);
26983 + memcpy(q, p, sz + 1);
26989 + p = au_optstr(&perm, brattr);
26993 + memcpy(q, p, sz + 1);
26999 + return q - str->a;
27002 +int au_br_perm_val(char *perm)
27004 + int val, bad, sz;
27006 + substring_t args[MAX_OPT_ARGS];
27007 + au_br_perm_str_t attr;
27009 + p = strchr(perm, '+');
27012 + val = match_token(perm, brperm, args);
27016 + pr_warn("ignored branch permission %s\n", perm);
27017 + val = AuBrPerm_RO;
27023 + val |= br_attr_val(p + 1, brattr, args);
27026 + switch (val & AuBrPerm_Mask) {
27027 + case AuBrPerm_RO:
27028 + case AuBrPerm_RR:
27029 + bad = val & AuBrWAttr_Mask;
27030 + val &= ~AuBrWAttr_Mask;
27032 + case AuBrPerm_RW:
27033 + bad = val & AuBrRAttr_Mask;
27034 + val &= ~AuBrRAttr_Mask;
27039 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
27040 + * does not treat it as an error, just warning.
27041 + * this is a tiny guard for the user operation.
27043 + if (val & AuBrAttr_UNPIN) {
27044 + bad |= AuBrAttr_UNPIN;
27045 + val &= ~AuBrAttr_UNPIN;
27048 + if (unlikely(bad)) {
27049 + sz = au_do_optstr_br_attr(&attr, bad);
27051 + pr_warn("ignored branch attribute %s\n", attr.a);
27058 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
27060 + au_br_perm_str_t attr;
27066 + p = au_optstr(&perm, brperm);
27067 + AuDebugOn(!p || !*p);
27069 + memcpy(q, p, sz + 1);
27072 + sz = au_do_optstr_br_attr(&attr, perm);
27075 + memcpy(q, attr.a, sz + 1);
27078 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
27081 +/* ---------------------------------------------------------------------- */
27083 +static match_table_t udbalevel = {
27084 + {AuOpt_UDBA_REVAL, "reval"},
27085 + {AuOpt_UDBA_NONE, "none"},
27086 +#ifdef CONFIG_AUFS_HNOTIFY
27087 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
27088 +#ifdef CONFIG_AUFS_HFSNOTIFY
27089 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
27095 +int au_udba_val(char *str)
27097 + substring_t args[MAX_OPT_ARGS];
27099 + return match_token(str, udbalevel, args);
27102 +const char *au_optstr_udba(int udba)
27104 + return au_parser_pattern(udba, udbalevel);
27107 +/* ---------------------------------------------------------------------- */
27109 +static match_table_t au_wbr_create_policy = {
27110 + {AuWbrCreate_TDP, "tdp"},
27111 + {AuWbrCreate_TDP, "top-down-parent"},
27112 + {AuWbrCreate_RR, "rr"},
27113 + {AuWbrCreate_RR, "round-robin"},
27114 + {AuWbrCreate_MFS, "mfs"},
27115 + {AuWbrCreate_MFS, "most-free-space"},
27116 + {AuWbrCreate_MFSV, "mfs:%d"},
27117 + {AuWbrCreate_MFSV, "most-free-space:%d"},
27119 + /* top-down regardless the parent, and then mfs */
27120 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
27121 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
27123 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
27124 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
27125 + {AuWbrCreate_PMFS, "pmfs"},
27126 + {AuWbrCreate_PMFSV, "pmfs:%d"},
27127 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
27128 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
27133 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
27134 + struct au_opt_wbr_create *create)
27137 + unsigned long long ull;
27140 + if (!match_u64(arg, &ull))
27141 + create->mfsrr_watermark = ull;
27143 + pr_err("bad integer in %s\n", str);
27150 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
27151 + struct au_opt_wbr_create *create)
27156 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
27157 + create->mfs_second = n;
27159 + pr_err("bad integer in %s\n", str);
27166 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
27169 + substring_t args[MAX_OPT_ARGS];
27171 + err = match_token(str, au_wbr_create_policy, args);
27172 + create->wbr_create = err;
27174 + case AuWbrCreate_MFSRRV:
27175 + case AuWbrCreate_TDMFSV:
27176 + case AuWbrCreate_PMFSRRV:
27177 + e = au_wbr_mfs_wmark(&args[0], str, create);
27179 + e = au_wbr_mfs_sec(&args[1], str, create);
27183 + case AuWbrCreate_MFSRR:
27184 + case AuWbrCreate_TDMFS:
27185 + case AuWbrCreate_PMFSRR:
27186 + e = au_wbr_mfs_wmark(&args[0], str, create);
27187 + if (unlikely(e)) {
27192 + case AuWbrCreate_MFS:
27193 + case AuWbrCreate_PMFS:
27194 + create->mfs_second = AUFS_MFS_DEF_SEC;
27196 + case AuWbrCreate_MFSV:
27197 + case AuWbrCreate_PMFSV:
27198 + e = au_wbr_mfs_sec(&args[0], str, create);
27207 +const char *au_optstr_wbr_create(int wbr_create)
27209 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
27212 +static match_table_t au_wbr_copyup_policy = {
27213 + {AuWbrCopyup_TDP, "tdp"},
27214 + {AuWbrCopyup_TDP, "top-down-parent"},
27215 + {AuWbrCopyup_BUP, "bup"},
27216 + {AuWbrCopyup_BUP, "bottom-up-parent"},
27217 + {AuWbrCopyup_BU, "bu"},
27218 + {AuWbrCopyup_BU, "bottom-up"},
27222 +int au_wbr_copyup_val(char *str)
27224 + substring_t args[MAX_OPT_ARGS];
27226 + return match_token(str, au_wbr_copyup_policy, args);
27229 +const char *au_optstr_wbr_copyup(int wbr_copyup)
27231 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
27234 +/* ---------------------------------------------------------------------- */
27236 +int au_opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
27237 + aufs_bindex_t bindex)
27240 + struct au_opt_add *add = &opt->add;
27243 + add->bindex = bindex;
27244 + add->perm = AuBrPerm_RO;
27245 + add->pathname = opt_str;
27246 + p = strchr(opt_str, '=');
27250 + add->perm = au_br_perm_val(p);
27253 + err = vfsub_kern_path(add->pathname, AuOpt_LkupDirFlags, &add->path);
27256 + add->perm = AuBrPerm_RO;
27257 + if (au_test_fs_rr(add->path.dentry->d_sb))
27258 + add->perm = AuBrPerm_RR;
27259 + else if (!bindex && !(sb_flags & SB_RDONLY))
27260 + add->perm = AuBrPerm_RW;
27262 + opt->type = Opt_add;
27265 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
27272 +static int au_opt_wbr_create(struct super_block *sb,
27273 + struct au_opt_wbr_create *create)
27276 + struct au_sbinfo *sbinfo;
27278 + SiMustWriteLock(sb);
27280 + err = 1; /* handled */
27281 + sbinfo = au_sbi(sb);
27282 + if (sbinfo->si_wbr_create_ops->fin) {
27283 + err = sbinfo->si_wbr_create_ops->fin(sb);
27288 + sbinfo->si_wbr_create = create->wbr_create;
27289 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
27290 + switch (create->wbr_create) {
27291 + case AuWbrCreate_MFSRRV:
27292 + case AuWbrCreate_MFSRR:
27293 + case AuWbrCreate_TDMFS:
27294 + case AuWbrCreate_TDMFSV:
27295 + case AuWbrCreate_PMFSRR:
27296 + case AuWbrCreate_PMFSRRV:
27297 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
27299 + case AuWbrCreate_MFS:
27300 + case AuWbrCreate_MFSV:
27301 + case AuWbrCreate_PMFS:
27302 + case AuWbrCreate_PMFSV:
27303 + sbinfo->si_wbr_mfs.mfs_expire
27304 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
27308 + if (sbinfo->si_wbr_create_ops->init)
27309 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27316 + * plus: processed without an error
27317 + * zero: unprocessed
27319 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27320 + struct au_opts *opts)
27323 + struct au_sbinfo *sbinfo;
27325 + SiMustWriteLock(sb);
27327 + err = 1; /* handled */
27328 + sbinfo = au_sbi(sb);
27329 + switch (opt->type) {
27331 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27332 + sbinfo->si_mntflags |= opt->udba;
27333 + opts->given_udba |= opt->udba;
27338 + au_opt_set(sbinfo->si_mntflags, PLINK);
27340 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27341 + au_plink_put(sb, /*verbose*/1);
27342 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27345 + case Opt_list_plink:
27346 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27347 + au_plink_list(sb);
27352 + au_opt_set(sbinfo->si_mntflags, DIO);
27353 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27355 + au_opt_clr(sbinfo->si_mntflags, DIO);
27356 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27360 + case Opt_fhsm_sec:
27361 + au_fhsm_set(sbinfo, opt->fhsm_second);
27364 + case Opt_diropq_a:
27365 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27367 + case Opt_diropq_w:
27368 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27371 + case Opt_warn_perm:
27373 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27375 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27378 + case Opt_verbose:
27380 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27382 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27387 + au_opt_set(sbinfo->si_mntflags, SUM);
27389 + au_opt_clr(sbinfo->si_mntflags, SUM);
27390 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27394 + au_opt_clr(sbinfo->si_mntflags, SUM);
27395 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27398 + case Opt_wbr_create:
27399 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27401 + case Opt_wbr_copyup:
27402 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27403 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27407 + sbinfo->si_dirwh = opt->dirwh;
27410 + case Opt_rdcache:
27411 + sbinfo->si_rdcache
27412 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27415 + sbinfo->si_rdblk = opt->rdblk;
27418 + sbinfo->si_rdhash = opt->rdhash;
27423 + au_opt_set(sbinfo->si_mntflags, SHWH);
27425 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27428 + case Opt_dirperm1:
27430 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27432 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27435 + case Opt_trunc_xino:
27437 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27439 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27442 + case Opt_trunc_xino_path:
27443 + case Opt_itrunc_xino:
27444 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27450 + case Opt_trunc_xib:
27452 + au_fset_opts(opts->flags, TRUNC_XIB);
27454 + au_fclr_opts(opts->flags, TRUNC_XIB);
27460 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27461 + err = au_dr_opt_set(sb);
27466 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27468 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27469 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27475 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27481 + sb->s_flags |= SB_POSIXACL;
27483 + sb->s_flags &= ~SB_POSIXACL;
27495 + * returns tri-state.
27496 + * plus: processed without an error
27497 + * zero: unprocessed
27500 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27501 + struct au_opts *opts)
27503 + int err, do_refresh;
27506 + switch (opt->type) {
27508 + opt->add.bindex = au_sbbot(sb) + 1;
27509 + if (opt->add.bindex < 0)
27510 + opt->add.bindex = 0;
27512 + /* Always goto add, not fallthrough */
27513 + case Opt_prepend:
27514 + opt->add.bindex = 0;
27516 + add: /* indented label */
27518 + err = au_br_add(sb, &opt->add,
27519 + au_ftest_opts(opts->flags, REMOUNT));
27522 + au_fset_opts(opts->flags, REFRESH);
27528 + err = au_br_del(sb, &opt->del,
27529 + au_ftest_opts(opts->flags, REMOUNT));
27532 + au_fset_opts(opts->flags, TRUNC_XIB);
27533 + au_fset_opts(opts->flags, REFRESH);
27539 + err = au_br_mod(sb, &opt->mod,
27540 + au_ftest_opts(opts->flags, REMOUNT),
27545 + au_fset_opts(opts->flags, REFRESH);
27552 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27553 + struct au_opt_xino **opt_xino,
27554 + struct au_opts *opts)
27559 + switch (opt->type) {
27561 + err = au_xino_set(sb, &opt->xino,
27562 + !!au_ftest_opts(opts->flags, REMOUNT));
27564 + *opt_xino = &opt->xino;
27568 + *opt_xino = (void *)-1;
27575 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27576 + unsigned int pending)
27579 + aufs_bindex_t bindex, bbot;
27580 + unsigned char do_plink, skip, do_free, can_no_dreval;
27581 + struct au_branch *br;
27582 + struct au_wbr *wbr;
27583 + struct dentry *root, *dentry;
27584 + struct inode *dir, *h_dir;
27585 + struct au_sbinfo *sbinfo;
27586 + struct au_hinode *hdir;
27588 + SiMustAnyLock(sb);
27590 + sbinfo = au_sbi(sb);
27591 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27593 + if (!(sb_flags & SB_RDONLY)) {
27594 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27595 + pr_warn("first branch should be rw\n");
27596 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27597 + pr_warn_once("shwh should be used with ro\n");
27600 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27601 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27602 + pr_warn_once("udba=*notify requires xino\n");
27604 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27605 + pr_warn_once("dirperm1 breaks the protection"
27606 + " by the permission bits on the lower branch\n");
27610 + root = sb->s_root;
27611 + dir = d_inode(root);
27612 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27613 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27615 + bbot = au_sbbot(sb);
27616 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27618 + h_dir = au_h_iptr(dir, bindex);
27619 + br = au_sbr(sb, bindex);
27621 + if ((br->br_perm & AuBrAttr_ICEX)
27622 + && !h_dir->i_op->listxattr)
27623 + br->br_perm &= ~AuBrAttr_ICEX;
27624 +#if 0 /* untested */
27625 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27626 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27627 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27631 + wbr = br->br_wbr;
27633 + wbr_wh_read_lock(wbr);
27635 + if (!au_br_writable(br->br_perm)) {
27638 + || (!wbr->wbr_whbase
27639 + && !wbr->wbr_plink
27640 + && !wbr->wbr_orph));
27641 + } else if (!au_br_wh_linkable(br->br_perm)) {
27642 + /* skip = (!br->br_whbase && !br->br_orph); */
27643 + skip = (!wbr || !wbr->wbr_whbase);
27644 + if (skip && wbr) {
27646 + skip = !!wbr->wbr_plink;
27648 + skip = !wbr->wbr_plink;
27651 + /* skip = (br->br_whbase && br->br_ohph); */
27652 + skip = (wbr && wbr->wbr_whbase);
27655 + skip = !!wbr->wbr_plink;
27657 + skip = !wbr->wbr_plink;
27661 + wbr_wh_read_unlock(wbr);
27663 + if (can_no_dreval) {
27664 + dentry = br->br_path.dentry;
27665 + spin_lock(&dentry->d_lock);
27666 + if (dentry->d_flags &
27667 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27668 + can_no_dreval = 0;
27669 + spin_unlock(&dentry->d_lock);
27672 + if (au_br_fhsm(br->br_perm)) {
27674 + AuDebugOn(!br->br_fhsm);
27680 + hdir = au_hi(dir, bindex);
27681 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27683 + wbr_wh_write_lock(wbr);
27684 + err = au_wh_init(br, sb);
27686 + wbr_wh_write_unlock(wbr);
27687 + au_hn_inode_unlock(hdir);
27689 + if (!err && do_free) {
27690 + au_kfree_rcu(wbr);
27691 + br->br_wbr = NULL;
27695 + if (can_no_dreval)
27696 + au_fset_si(sbinfo, NO_DREVAL);
27698 + au_fclr_si(sbinfo, NO_DREVAL);
27701 + au_fset_si(sbinfo, FHSM);
27702 + for (bindex = bbot; bindex >= 0; bindex--) {
27703 + br = au_sbr(sb, bindex);
27704 + if (au_br_fhsm(br->br_perm)) {
27705 + au_fhsm_set_bottom(sb, bindex);
27710 + au_fclr_si(sbinfo, FHSM);
27711 + au_fhsm_set_bottom(sb, -1);
27717 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27720 + unsigned int tmp;
27721 + aufs_bindex_t bindex, bbot;
27722 + struct au_opt *opt;
27723 + struct au_opt_xino *opt_xino, xino;
27724 + struct au_sbinfo *sbinfo;
27725 + struct au_branch *br;
27726 + struct inode *dir;
27728 + SiMustWriteLock(sb);
27733 + while (err >= 0 && opt->type != Opt_tail)
27734 + err = au_opt_simple(sb, opt++, opts);
27737 + else if (unlikely(err < 0))
27740 + /* disable xino and udba temporary */
27741 + sbinfo = au_sbi(sb);
27742 + tmp = sbinfo->si_mntflags;
27743 + au_opt_clr(sbinfo->si_mntflags, XINO);
27744 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27747 + while (err >= 0 && opt->type != Opt_tail)
27748 + err = au_opt_br(sb, opt++, opts);
27751 + else if (unlikely(err < 0))
27754 + bbot = au_sbbot(sb);
27755 + if (unlikely(bbot < 0)) {
27757 + pr_err("no branches\n");
27761 + if (au_opt_test(tmp, XINO))
27762 + au_opt_set(sbinfo->si_mntflags, XINO);
27764 + while (!err && opt->type != Opt_tail)
27765 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27766 + if (unlikely(err))
27769 + err = au_opts_verify(sb, sb->s_flags, tmp);
27770 + if (unlikely(err))
27773 + /* restore xino */
27774 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27775 + xino.file = au_xino_def(sb);
27776 + err = PTR_ERR(xino.file);
27777 + if (IS_ERR(xino.file))
27780 + err = au_xino_set(sb, &xino, /*remount*/0);
27782 + if (unlikely(err))
27786 + /* restore udba */
27787 + tmp &= AuOptMask_UDBA;
27788 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27789 + sbinfo->si_mntflags |= tmp;
27790 + bbot = au_sbbot(sb);
27791 + for (bindex = 0; bindex <= bbot; bindex++) {
27792 + br = au_sbr(sb, bindex);
27793 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27794 + if (unlikely(err))
27795 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27797 + /* go on even if err */
27799 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27800 + dir = d_inode(sb->s_root);
27801 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27808 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27811 + unsigned char no_dreval;
27812 + struct inode *dir;
27813 + struct au_opt_xino *opt_xino;
27814 + struct au_opt *opt;
27815 + struct au_sbinfo *sbinfo;
27817 + SiMustWriteLock(sb);
27819 + err = au_dr_opt_flush(sb);
27820 + if (unlikely(err))
27822 + au_fset_opts(opts->flags, DR_FLUSHED);
27824 + dir = d_inode(sb->s_root);
27825 + sbinfo = au_sbi(sb);
27828 + while (err >= 0 && opt->type != Opt_tail) {
27829 + err = au_opt_simple(sb, opt, opts);
27831 + err = au_opt_br(sb, opt, opts);
27833 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27839 + /* go on even err */
27841 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27842 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27843 + if (unlikely(rerr && !err))
27846 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27847 + au_fset_opts(opts->flags, REFRESH_IDOP);
27849 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27850 + rerr = au_xib_trunc(sb);
27851 + if (unlikely(rerr && !err))
27855 + /* will be handled by the caller */
27856 + if (!au_ftest_opts(opts->flags, REFRESH)
27857 + && (opts->given_udba
27858 + || au_opt_test(sbinfo->si_mntflags, XINO)
27859 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27861 + au_fset_opts(opts->flags, REFRESH);
27863 + AuDbg("status 0x%x\n", opts->flags);
27869 +/* ---------------------------------------------------------------------- */
27871 +unsigned int au_opt_udba(struct super_block *sb)
27873 + return au_mntflags(sb) & AuOptMask_UDBA;
27875 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27876 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27877 +++ linux/fs/aufs/opts.h 2022-11-05 23:02:18.969222617 +0100
27879 +/* SPDX-License-Identifier: GPL-2.0 */
27881 + * Copyright (C) 2005-2022 Junjiro R. Okajima
27883 + * This program is free software; you can redistribute it and/or modify
27884 + * it under the terms of the GNU General Public License as published by
27885 + * the Free Software Foundation; either version 2 of the License, or
27886 + * (at your option) any later version.
27888 + * This program is distributed in the hope that it will be useful,
27889 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27890 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27891 + * GNU General Public License for more details.
27893 + * You should have received a copy of the GNU General Public License
27894 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27898 + * mount options/flags
27901 +#ifndef __AUFS_OPTS_H__
27902 +#define __AUFS_OPTS_H__
27906 +#include <linux/fs_parser.h>
27907 +#include <linux/namei.h>
27908 +#include <linux/path.h>
27912 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
27913 + Opt_idel, Opt_imod,
27914 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
27915 + Opt_xino, Opt_noxino,
27916 + Opt_trunc_xino, Opt_trunc_xino_v,
27917 + Opt_trunc_xino_path, Opt_itrunc_xino,
27920 + Opt_plink, Opt_list_plink,
27923 + Opt_diropq, Opt_diropq_a, Opt_diropq_w,
27925 + Opt_wbr_copyup, Opt_wbr_create,
27927 + Opt_verbose, Opt_noverbose,
27928 + Opt_sum, Opt_wsum,
27932 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
27935 +/* ---------------------------------------------------------------------- */
27938 +#define AuOpt_XINO 1 /* external inode number bitmap
27939 + and translation table */
27940 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27941 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27942 +#define AuOpt_UDBA_REVAL (1 << 3)
27943 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27944 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27945 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27946 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27948 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27949 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27950 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27951 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27952 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27953 +#define AuOpt_DIO (1 << 14) /* direct io */
27954 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27956 +#ifndef CONFIG_AUFS_HNOTIFY
27957 +#undef AuOpt_UDBA_HNOTIFY
27958 +#define AuOpt_UDBA_HNOTIFY 0
27960 +#ifndef CONFIG_AUFS_DIRREN
27961 +#undef AuOpt_DIRREN
27962 +#define AuOpt_DIRREN 0
27964 +#ifndef CONFIG_AUFS_SHWH
27966 +#define AuOpt_SHWH 0
27969 +#define AuOpt_Def (AuOpt_XINO \
27970 + | AuOpt_UDBA_REVAL \
27972 + /* | AuOpt_DIRPERM1 */ \
27973 + | AuOpt_WARN_PERM)
27974 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27975 + | AuOpt_UDBA_REVAL \
27976 + | AuOpt_UDBA_HNOTIFY)
27978 +#define AuOpt_LkupDirFlags (LOOKUP_FOLLOW | LOOKUP_DIRECTORY)
27980 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27981 +#define au_opt_set(flags, name) do { \
27982 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27983 + ((flags) |= AuOpt_##name); \
27985 +#define au_opt_set_udba(flags, name) do { \
27986 + (flags) &= ~AuOptMask_UDBA; \
27987 + ((flags) |= AuOpt_##name); \
27989 +#define au_opt_clr(flags, name) do { \
27990 + ((flags) &= ~AuOpt_##name); \
27993 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27995 +#ifdef CONFIG_PROC_FS
27998 + return mntflags & ~AuOpt_PLINK;
28002 +/* ---------------------------------------------------------------------- */
28004 +/* policies to select one among multiple writable branches */
28006 + AuWbrCreate_TDP, /* top down parent */
28007 + AuWbrCreate_RR, /* round robin */
28008 + AuWbrCreate_MFS, /* most free space */
28009 + AuWbrCreate_MFSV, /* mfs with seconds */
28010 + AuWbrCreate_MFSRR, /* mfs then rr */
28011 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
28012 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
28013 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
28014 + AuWbrCreate_PMFS, /* parent and mfs */
28015 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
28016 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
28017 + AuWbrCreate_PMFSRRV, /* plus seconds */
28019 + AuWbrCreate_Def = AuWbrCreate_TDP
28023 + AuWbrCopyup_TDP, /* top down parent */
28024 + AuWbrCopyup_BUP, /* bottom up parent */
28025 + AuWbrCopyup_BU, /* bottom up */
28027 + AuWbrCopyup_Def = AuWbrCopyup_TDP
28030 +/* ---------------------------------------------------------------------- */
28034 +struct au_opt_add {
28035 + aufs_bindex_t bindex;
28038 + struct path path;
28041 +struct au_opt_del {
28043 + struct path h_path;
28046 +struct au_opt_mod {
28049 + struct dentry *h_root;
28052 +struct au_opt_xino {
28054 + struct file *file;
28057 +struct au_opt_xino_itrunc {
28058 + aufs_bindex_t bindex;
28061 +struct au_opt_wbr_create {
28064 + unsigned long long mfsrr_watermark;
28070 + struct au_opt_xino xino;
28071 + struct au_opt_xino_itrunc xino_itrunc;
28072 + struct au_opt_add add;
28073 + struct au_opt_del del;
28074 + struct au_opt_mod mod;
28077 + unsigned int rdblk;
28078 + unsigned int rdhash;
28080 + struct au_opt_wbr_create wbr_create;
28082 + unsigned int fhsm_second;
28083 + bool tf; /* generic flag, true or false */
28088 +#define AuOpts_REMOUNT 1
28089 +#define AuOpts_REFRESH (1 << 1)
28090 +#define AuOpts_TRUNC_XIB (1 << 2)
28091 +#define AuOpts_REFRESH_DYAOP (1 << 3)
28092 +#define AuOpts_REFRESH_IDOP (1 << 4)
28093 +#define AuOpts_DR_FLUSHED (1 << 5)
28094 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
28095 +#define au_fset_opts(flags, name) \
28096 + do { (flags) |= AuOpts_##name; } while (0)
28097 +#define au_fclr_opts(flags, name) \
28098 + do { (flags) &= ~AuOpts_##name; } while (0)
28100 +#ifndef CONFIG_AUFS_DIRREN
28101 +#undef AuOpts_DR_FLUSHED
28102 +#define AuOpts_DR_FLUSHED 0
28106 + struct au_opt *opt;
28109 + unsigned int given_udba;
28110 + unsigned int flags;
28111 + unsigned long sb_flags;
28114 +/* ---------------------------------------------------------------------- */
28117 +int au_br_perm_val(char *perm);
28118 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
28119 +int au_udba_val(char *str);
28120 +const char *au_optstr_udba(int udba);
28121 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create);
28122 +const char *au_optstr_wbr_create(int wbr_create);
28123 +int au_wbr_copyup_val(char *str);
28124 +const char *au_optstr_wbr_copyup(int wbr_copyup);
28126 +int au_opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
28127 + aufs_bindex_t bindex);
28128 +struct super_block;
28129 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
28130 + unsigned int pending);
28131 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
28132 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
28134 +unsigned int au_opt_udba(struct super_block *sb);
28137 +int aufs_fsctx_init(struct fs_context *fc);
28138 +extern const struct fs_parameter_spec aufs_fsctx_paramspec[];
28140 +#endif /* __KERNEL__ */
28141 +#endif /* __AUFS_OPTS_H__ */
28142 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
28143 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
28144 +++ linux/fs/aufs/plink.c 2022-11-05 23:02:18.969222617 +0100
28146 +// SPDX-License-Identifier: GPL-2.0
28148 + * Copyright (C) 2005-2022 Junjiro R. Okajima
28150 + * This program is free software; you can redistribute it and/or modify
28151 + * it under the terms of the GNU General Public License as published by
28152 + * the Free Software Foundation; either version 2 of the License, or
28153 + * (at your option) any later version.
28155 + * This program is distributed in the hope that it will be useful,
28156 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28157 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28158 + * GNU General Public License for more details.
28160 + * You should have received a copy of the GNU General Public License
28161 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28171 + * the pseudo-link maintenance mode.
28172 + * during a user process maintains the pseudo-links,
28173 + * prohibit adding a new plink and branch manipulation.
28177 + * For entry functions which will handle plink, and i_mutex is already held
28179 + * They cannot wait and should return an error at once.
28180 + * Callers has to check the error.
28182 + * For entry functions which will handle plink, but i_mutex is not held
28184 + * They can wait the plink maintenance mode to finish.
28186 + * They behave like F_SETLK and F_SETLKW.
28187 + * If the caller never handle plink, then both flags are unnecessary.
28190 +int au_plink_maint(struct super_block *sb, int flags)
28194 + struct task_struct *parent, *prev;
28195 + struct au_sbinfo *sbi;
28197 + SiMustAnyLock(sb);
28200 + if (!au_opt_test(au_mntflags(sb), PLINK))
28203 + sbi = au_sbi(sb);
28204 + pid = sbi->si_plink_maint_pid;
28205 + if (!pid || pid == current->pid)
28208 + /* todo: it highly depends upon /sbin/mount.aufs */
28210 + parent = current;
28214 + parent = rcu_dereference(parent->real_parent);
28215 + if (parent == prev)
28217 + ppid = task_pid_vnr(parent);
28218 + if (pid == ppid) {
28219 + rcu_read_unlock();
28224 + rcu_read_unlock();
28226 + if (au_ftest_lock(flags, NOPLMW)) {
28227 + /* if there is no i_mutex lock in VFS, we don't need to wait */
28228 + /* AuDebugOn(!lockdep_depth(current)); */
28229 + while (sbi->si_plink_maint_pid) {
28230 + si_read_unlock(sb);
28231 + /* gave up wake_up_bit() */
28232 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
28234 + if (au_ftest_lock(flags, FLUSH))
28235 + au_nwt_flush(&sbi->si_nowait);
28236 + si_noflush_read_lock(sb);
28238 + } else if (au_ftest_lock(flags, NOPLM)) {
28239 + AuDbg("ppid %d, pid %d\n", ppid, pid);
28247 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
28249 + spin_lock(&sbinfo->si_plink_maint_lock);
28250 + sbinfo->si_plink_maint_pid = 0;
28251 + spin_unlock(&sbinfo->si_plink_maint_lock);
28252 + wake_up_all(&sbinfo->si_plink_wq);
28255 +int au_plink_maint_enter(struct super_block *sb)
28258 + struct au_sbinfo *sbinfo;
28261 + sbinfo = au_sbi(sb);
28262 + /* make sure i am the only one in this fs */
28263 + si_write_lock(sb, AuLock_FLUSH);
28264 + if (au_opt_test(au_mntflags(sb), PLINK)) {
28265 + spin_lock(&sbinfo->si_plink_maint_lock);
28266 + if (!sbinfo->si_plink_maint_pid)
28267 + sbinfo->si_plink_maint_pid = current->pid;
28270 + spin_unlock(&sbinfo->si_plink_maint_lock);
28272 + si_write_unlock(sb);
28277 +/* ---------------------------------------------------------------------- */
28279 +#ifdef CONFIG_AUFS_DEBUG
28280 +void au_plink_list(struct super_block *sb)
28283 + struct au_sbinfo *sbinfo;
28284 + struct hlist_bl_head *hbl;
28285 + struct hlist_bl_node *pos;
28286 + struct au_icntnr *icntnr;
28288 + SiMustAnyLock(sb);
28290 + sbinfo = au_sbi(sb);
28291 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28292 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28294 + for (i = 0; i < AuPlink_NHASH; i++) {
28295 + hbl = sbinfo->si_plink + i;
28296 + hlist_bl_lock(hbl);
28297 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28298 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
28299 + hlist_bl_unlock(hbl);
28304 +/* is the inode pseudo-linked? */
28305 +int au_plink_test(struct inode *inode)
28308 + struct au_sbinfo *sbinfo;
28309 + struct hlist_bl_head *hbl;
28310 + struct hlist_bl_node *pos;
28311 + struct au_icntnr *icntnr;
28313 + sbinfo = au_sbi(inode->i_sb);
28314 + AuRwMustAnyLock(&sbinfo->si_rwsem);
28315 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
28316 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28319 + i = au_plink_hash(inode->i_ino);
28320 + hbl = sbinfo->si_plink + i;
28321 + hlist_bl_lock(hbl);
28322 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28323 + if (&icntnr->vfs_inode == inode) {
28327 + hlist_bl_unlock(hbl);
28331 +/* ---------------------------------------------------------------------- */
28334 + * generate a name for plink.
28335 + * the file will be stored under AUFS_WH_PLINKDIR.
28337 +/* 20 is max digits length of ulong 64 */
28338 +#define PLINK_NAME_LEN ((20 + 1) * 2)
28340 +static int plink_name(char *name, int len, struct inode *inode,
28341 + aufs_bindex_t bindex)
28344 + struct inode *h_inode;
28346 + h_inode = au_h_iptr(inode, bindex);
28347 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28351 +struct au_do_plink_lkup_args {
28352 + struct dentry **errp;
28353 + struct qstr *tgtname;
28354 + struct path *h_ppath;
28357 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28358 + struct path *h_ppath)
28360 + struct dentry *h_dentry;
28361 + struct inode *h_inode;
28363 + h_inode = d_inode(h_ppath->dentry);
28364 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28365 + h_dentry = vfsub_lkup_one(tgtname, h_ppath);
28366 + inode_unlock_shared(h_inode);
28371 +static void au_call_do_plink_lkup(void *args)
28373 + struct au_do_plink_lkup_args *a = args;
28374 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_ppath);
28377 +/* lookup the plink-ed @inode under the branch at @bindex */
28378 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28380 + struct dentry *h_dentry;
28381 + struct au_branch *br;
28382 + struct path h_ppath;
28384 + char a[PLINK_NAME_LEN];
28385 + struct qstr tgtname = QSTR_INIT(a, 0);
28387 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28389 + br = au_sbr(inode->i_sb, bindex);
28390 + h_ppath.dentry = br->br_wbr->wbr_plink;
28391 + h_ppath.mnt = au_br_mnt(br);
28392 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28394 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28395 + struct au_do_plink_lkup_args args = {
28396 + .errp = &h_dentry,
28397 + .tgtname = &tgtname,
28398 + .h_ppath = &h_ppath
28401 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28402 + if (unlikely(wkq_err))
28403 + h_dentry = ERR_PTR(wkq_err);
28405 + h_dentry = au_do_plink_lkup(&tgtname, &h_ppath);
28410 +/* create a pseudo-link */
28411 +static int do_whplink(struct qstr *tgt, struct path *h_ppath,
28412 + struct dentry *h_dentry)
28415 + struct path h_path;
28416 + struct inode *h_dir, *delegated;
28418 + h_dir = d_inode(h_ppath->dentry);
28419 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28420 + h_path.mnt = h_ppath->mnt;
28422 + h_path.dentry = vfsub_lkup_one(tgt, h_ppath);
28423 + err = PTR_ERR(h_path.dentry);
28424 + if (IS_ERR(h_path.dentry))
28428 + /* wh.plink dir is not monitored */
28429 + /* todo: is it really safe? */
28430 + if (d_is_positive(h_path.dentry)
28431 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28432 + delegated = NULL;
28433 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28434 + if (unlikely(err == -EWOULDBLOCK)) {
28435 + pr_warn("cannot retry for NFSv4 delegation"
28436 + " for an internal unlink\n");
28439 + dput(h_path.dentry);
28440 + h_path.dentry = NULL;
28444 + if (!err && d_is_negative(h_path.dentry)) {
28445 + delegated = NULL;
28446 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28447 + if (unlikely(err == -EWOULDBLOCK)) {
28448 + pr_warn("cannot retry for NFSv4 delegation"
28449 + " for an internal link\n");
28453 + dput(h_path.dentry);
28456 + inode_unlock(h_dir);
28460 +struct do_whplink_args {
28462 + struct qstr *tgt;
28463 + struct path *h_ppath;
28464 + struct dentry *h_dentry;
28467 +static void call_do_whplink(void *args)
28469 + struct do_whplink_args *a = args;
28470 + *a->errp = do_whplink(a->tgt, a->h_ppath, a->h_dentry);
28473 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28474 + aufs_bindex_t bindex)
28476 + int err, wkq_err;
28477 + struct au_branch *br;
28478 + struct au_wbr *wbr;
28479 + struct path h_ppath;
28480 + char a[PLINK_NAME_LEN];
28481 + struct qstr tgtname = QSTR_INIT(a, 0);
28483 + br = au_sbr(inode->i_sb, bindex);
28484 + wbr = br->br_wbr;
28485 + h_ppath.dentry = wbr->wbr_plink;
28486 + h_ppath.mnt = au_br_mnt(br);
28487 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28489 + /* always superio. */
28490 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28491 + struct do_whplink_args args = {
28494 + .h_ppath = &h_ppath,
28495 + .h_dentry = h_dentry
28497 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28498 + if (unlikely(wkq_err))
28501 + err = do_whplink(&tgtname, &h_ppath, h_dentry);
28507 + * create a new pseudo-link for @h_dentry on @bindex.
28508 + * the linked inode is held in aufs @inode.
28510 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28511 + struct dentry *h_dentry)
28513 + struct super_block *sb;
28514 + struct au_sbinfo *sbinfo;
28515 + struct hlist_bl_head *hbl;
28516 + struct hlist_bl_node *pos;
28517 + struct au_icntnr *icntnr;
28518 + int found, err, cnt, i;
28520 + sb = inode->i_sb;
28521 + sbinfo = au_sbi(sb);
28522 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28523 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28525 + found = au_plink_test(inode);
28529 + i = au_plink_hash(inode->i_ino);
28530 + hbl = sbinfo->si_plink + i;
28533 + hlist_bl_lock(hbl);
28534 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28535 + if (&icntnr->vfs_inode == inode) {
28541 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28542 + hlist_bl_add_head(&icntnr->plink, hbl);
28544 + hlist_bl_unlock(hbl);
28546 + cnt = au_hbl_count(hbl);
28547 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28548 + if (cnt > AUFS_PLINK_WARN)
28549 + AuWarn1(msg ", %d\n", cnt);
28551 + err = whplink(h_dentry, inode, bindex);
28552 + if (unlikely(err)) {
28553 + pr_warn("err %d, damaged pseudo link.\n", err);
28554 + au_hbl_del(&icntnr->plink, hbl);
28555 + iput(&icntnr->vfs_inode);
28558 + iput(&icntnr->vfs_inode);
28561 +/* free all plinks */
28562 +void au_plink_put(struct super_block *sb, int verbose)
28565 + struct au_sbinfo *sbinfo;
28566 + struct hlist_bl_head *hbl;
28567 + struct hlist_bl_node *pos, *tmp;
28568 + struct au_icntnr *icntnr;
28570 + SiMustWriteLock(sb);
28572 + sbinfo = au_sbi(sb);
28573 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28574 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28576 + /* no spin_lock since sbinfo is write-locked */
28578 + for (i = 0; i < AuPlink_NHASH; i++) {
28579 + hbl = sbinfo->si_plink + i;
28580 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28581 + pr_warn("pseudo-link is not flushed");
28584 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28585 + iput(&icntnr->vfs_inode);
28586 + INIT_HLIST_BL_HEAD(hbl);
28590 +void au_plink_clean(struct super_block *sb, int verbose)
28592 + struct dentry *root;
28594 + root = sb->s_root;
28595 + aufs_write_lock(root);
28596 + if (au_opt_test(au_mntflags(sb), PLINK))
28597 + au_plink_put(sb, verbose);
28598 + aufs_write_unlock(root);
28601 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28604 + aufs_bindex_t btop, bbot, bindex;
28607 + btop = au_ibtop(inode);
28608 + bbot = au_ibbot(inode);
28610 + for (bindex = btop; bindex <= bbot; bindex++) {
28611 + if (!au_h_iptr(inode, bindex)
28612 + || au_ii_br_id(inode, bindex) != br_id)
28614 + au_set_h_iptr(inode, bindex, NULL, 0);
28619 + for (bindex = btop; bindex <= bbot; bindex++)
28620 + if (au_h_iptr(inode, bindex)) {
28630 +/* free the plinks on a branch specified by @br_id */
28631 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28633 + struct au_sbinfo *sbinfo;
28634 + struct hlist_bl_head *hbl;
28635 + struct hlist_bl_node *pos, *tmp;
28636 + struct au_icntnr *icntnr;
28637 + struct inode *inode;
28640 + SiMustWriteLock(sb);
28642 + sbinfo = au_sbi(sb);
28643 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28644 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28646 + /* no bit_lock since sbinfo is write-locked */
28647 + for (i = 0; i < AuPlink_NHASH; i++) {
28648 + hbl = sbinfo->si_plink + i;
28649 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28650 + inode = au_igrab(&icntnr->vfs_inode);
28651 + ii_write_lock_child(inode);
28652 + do_put = au_plink_do_half_refresh(inode, br_id);
28654 + hlist_bl_del(&icntnr->plink);
28657 + ii_write_unlock(inode);
28662 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28663 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28664 +++ linux/fs/aufs/poll.c 2022-11-05 23:02:18.969222617 +0100
28666 +// SPDX-License-Identifier: GPL-2.0
28668 + * Copyright (C) 2005-2022 Junjiro R. Okajima
28670 + * This program is free software; you can redistribute it and/or modify
28671 + * it under the terms of the GNU General Public License as published by
28672 + * the Free Software Foundation; either version 2 of the License, or
28673 + * (at your option) any later version.
28675 + * This program is distributed in the hope that it will be useful,
28676 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28677 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28678 + * GNU General Public License for more details.
28680 + * You should have received a copy of the GNU General Public License
28681 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28686 + * There is only one filesystem which implements ->poll operation, currently.
28691 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28694 + struct file *h_file;
28695 + struct super_block *sb;
28697 + /* We should pretend an error happened. */
28698 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28699 + sb = file->f_path.dentry->d_sb;
28700 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28702 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28703 + if (IS_ERR(h_file)) {
28704 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28708 + mask = vfs_poll(h_file, pt);
28709 + fput(h_file); /* instead of au_read_post() */
28712 + si_read_unlock(sb);
28713 + if (mask & EPOLLERR)
28714 + AuDbg("mask 0x%x\n", mask);
28717 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28718 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28719 +++ linux/fs/aufs/posix_acl.c 2022-11-05 23:02:18.969222617 +0100
28721 +// SPDX-License-Identifier: GPL-2.0
28723 + * Copyright (C) 2014-2022 Junjiro R. Okajima
28725 + * This program is free software; you can redistribute it and/or modify
28726 + * it under the terms of the GNU General Public License as published by
28727 + * the Free Software Foundation; either version 2 of the License, or
28728 + * (at your option) any later version.
28730 + * This program is distributed in the hope that it will be useful,
28731 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28732 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28733 + * GNU General Public License for more details.
28735 + * You should have received a copy of the GNU General Public License
28736 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28740 + * posix acl operations
28743 +#include <linux/fs.h>
28746 +struct posix_acl *aufs_get_acl(struct inode *inode, int type, bool rcu)
28748 + struct posix_acl *acl;
28750 + aufs_bindex_t bindex;
28751 + struct inode *h_inode;
28752 + struct super_block *sb;
28754 + acl = ERR_PTR(-ECHILD);
28759 + sb = inode->i_sb;
28760 + si_read_lock(sb, AuLock_FLUSH);
28761 + ii_read_lock_child(inode);
28762 + if (!(sb->s_flags & SB_POSIXACL))
28765 + bindex = au_ibtop(inode);
28766 + h_inode = au_h_iptr(inode, bindex);
28767 + if (unlikely(!h_inode
28768 + || ((h_inode->i_mode & S_IFMT)
28769 + != (inode->i_mode & S_IFMT)))) {
28770 + err = au_busy_or_stale();
28771 + acl = ERR_PTR(err);
28775 + /* always topmost only */
28776 + acl = get_acl(h_inode, type);
28778 + forget_cached_acl(inode, type);
28780 + set_cached_acl(inode, type, acl);
28783 + ii_read_unlock(inode);
28784 + si_read_unlock(sb);
28787 + AuTraceErrPtr(acl);
28791 +int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
28792 + struct posix_acl *acl, int type)
28796 + struct dentry *dentry;
28797 + struct au_sxattr arg = {
28798 + .type = AU_ACL_SET,
28805 + IMustLock(inode);
28807 + if (inode->i_ino == AUFS_ROOT_INO)
28808 + dentry = dget(inode->i_sb->s_root);
28810 + dentry = d_find_alias(inode);
28812 + dentry = d_find_any_alias(inode);
28814 + pr_warn("cannot handle this inode, "
28815 + "please report to aufs-users ML\n");
28821 + ssz = au_sxattr(dentry, inode, &arg);
28822 + /* forget even it if succeeds since the branch might set differently */
28823 + forget_cached_acl(inode, type);
28832 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28833 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28834 +++ linux/fs/aufs/procfs.c 2022-11-05 23:02:18.969222617 +0100
28836 +// SPDX-License-Identifier: GPL-2.0
28838 + * Copyright (C) 2010-2022 Junjiro R. Okajima
28840 + * This program is free software; you can redistribute it and/or modify
28841 + * it under the terms of the GNU General Public License as published by
28842 + * the Free Software Foundation; either version 2 of the License, or
28843 + * (at your option) any later version.
28845 + * This program is distributed in the hope that it will be useful,
28846 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28847 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28848 + * GNU General Public License for more details.
28850 + * You should have received a copy of the GNU General Public License
28851 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28855 + * procfs interfaces
28858 +#include <linux/proc_fs.h>
28861 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28863 + struct au_sbinfo *sbinfo;
28865 + sbinfo = file->private_data;
28867 + au_plink_maint_leave(sbinfo);
28868 + kobject_put(&sbinfo->si_kobj);
28874 +static void au_procfs_plm_write_clean(struct file *file)
28876 + struct au_sbinfo *sbinfo;
28878 + sbinfo = file->private_data;
28880 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28883 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28886 + struct super_block *sb;
28887 + struct au_sbinfo *sbinfo;
28888 + struct hlist_bl_node *pos;
28891 + if (unlikely(file->private_data))
28895 + /* don't use au_sbilist_lock() here */
28896 + hlist_bl_lock(&au_sbilist);
28897 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28898 + if (id == sysaufs_si_id(sbinfo)) {
28899 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28900 + sb = sbinfo->si_sb;
28903 + hlist_bl_unlock(&au_sbilist);
28906 + if (unlikely(!sb))
28909 + err = au_plink_maint_enter(sb);
28911 + /* keep kobject_get() */
28912 + file->private_data = sbinfo;
28914 + kobject_put(&sbinfo->si_kobj);
28920 + * Accept a valid "si=xxxx" only.
28921 + * Once it is accepted successfully, accept "clean" too.
28923 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28924 + size_t count, loff_t *ppos)
28927 + unsigned long id;
28928 + /* last newline is allowed */
28929 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28932 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28936 + if (unlikely(count > sizeof(buf)))
28939 + err = copy_from_user(buf, ubuf, count);
28940 + if (unlikely(err)) {
28947 + if (!strcmp("clean", buf)) {
28948 + au_procfs_plm_write_clean(file);
28949 + goto out_success;
28950 + } else if (unlikely(strncmp("si=", buf, 3)))
28953 + err = kstrtoul(buf + 3, 16, &id);
28954 + if (unlikely(err))
28957 + err = au_procfs_plm_write_si(file, id);
28958 + if (unlikely(err))
28962 + err = count; /* success */
28967 +static const struct proc_ops au_procfs_plm_op = {
28968 + .proc_write = au_procfs_plm_write,
28969 + .proc_release = au_procfs_plm_release
28972 +/* ---------------------------------------------------------------------- */
28974 +static struct proc_dir_entry *au_procfs_dir;
28976 +void au_procfs_fin(void)
28978 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28979 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28982 +int __init au_procfs_init(void)
28985 + struct proc_dir_entry *entry;
28988 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28989 + if (unlikely(!au_procfs_dir))
28992 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28993 + au_procfs_dir, &au_procfs_plm_op);
28994 + if (unlikely(!entry))
28998 + goto out; /* success */
29002 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
29006 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
29007 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
29008 +++ linux/fs/aufs/rdu.c 2022-11-05 23:02:18.969222617 +0100
29010 +// SPDX-License-Identifier: GPL-2.0
29012 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29014 + * This program is free software; you can redistribute it and/or modify
29015 + * it under the terms of the GNU General Public License as published by
29016 + * the Free Software Foundation; either version 2 of the License, or
29017 + * (at your option) any later version.
29019 + * This program is distributed in the hope that it will be useful,
29020 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29021 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29022 + * GNU General Public License for more details.
29024 + * You should have received a copy of the GNU General Public License
29025 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29029 + * readdir in userspace.
29032 +#include <linux/compat.h>
29033 +#include <linux/fs_stack.h>
29034 +#include <linux/security.h>
29037 +/* bits for struct aufs_rdu.flags */
29038 +#define AuRdu_CALLED 1
29039 +#define AuRdu_CONT (1 << 1)
29040 +#define AuRdu_FULL (1 << 2)
29041 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
29042 +#define au_fset_rdu(flags, name) \
29043 + do { (flags) |= AuRdu_##name; } while (0)
29044 +#define au_fclr_rdu(flags, name) \
29045 + do { (flags) &= ~AuRdu_##name; } while (0)
29047 +struct au_rdu_arg {
29048 + struct dir_context ctx;
29049 + struct aufs_rdu *rdu;
29050 + union au_rdu_ent_ul ent;
29051 + unsigned long end;
29053 + struct super_block *sb;
29057 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
29058 + loff_t offset, u64 h_ino, unsigned int d_type)
29061 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
29062 + struct aufs_rdu *rdu = arg->rdu;
29063 + struct au_rdu_ent ent;
29067 + au_fset_rdu(rdu->cookie.flags, CALLED);
29068 + len = au_rdu_len(nlen);
29069 + if (arg->ent.ul + len < arg->end) {
29071 + ent.bindex = rdu->cookie.bindex;
29072 + ent.type = d_type;
29074 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
29075 + ent.type = DT_UNKNOWN;
29077 + /* unnecessary to support mmap_sem since this is a dir */
29079 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
29081 + if (copy_to_user(arg->ent.e->name, name, nlen))
29083 + /* the terminating NULL */
29084 + if (__put_user(0, arg->ent.e->name + nlen))
29087 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
29088 + arg->ent.ul += len;
29092 + au_fset_rdu(rdu->cookie.flags, FULL);
29094 + rdu->tail = arg->ent;
29098 + /* AuTraceErr(err); */
29102 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
29106 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
29108 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
29109 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
29111 + if (unlikely(offset != cookie->h_pos))
29117 + au_fclr_rdu(cookie->flags, CALLED);
29119 + err = vfsub_iterate_dir(h_file, &arg->ctx);
29123 + && au_ftest_rdu(cookie->flags, CALLED)
29124 + && !au_ftest_rdu(cookie->flags, FULL));
29125 + cookie->h_pos = h_file->f_pos;
29132 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
29135 + aufs_bindex_t bbot;
29136 + struct au_rdu_arg arg = {
29138 + .actor = au_rdu_fill
29141 + struct dentry *dentry;
29142 + struct inode *inode;
29143 + struct file *h_file;
29144 + struct au_rdu_cookie *cookie = &rdu->cookie;
29146 + /* VERIFY_WRITE */
29147 + err = !access_ok(rdu->ent.e, rdu->sz);
29148 + if (unlikely(err)) {
29154 + rdu->tail = rdu->ent;
29157 + arg.ent = rdu->ent;
29158 + arg.end = arg.ent.ul;
29159 + arg.end += rdu->sz;
29162 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
29165 + err = security_file_permission(file, MAY_READ);
29167 + if (unlikely(err))
29170 + dentry = file->f_path.dentry;
29171 + inode = d_inode(dentry);
29172 + inode_lock_shared(inode);
29174 + arg.sb = inode->i_sb;
29175 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
29176 + if (unlikely(err))
29178 + err = au_alive_dir(dentry);
29179 + if (unlikely(err))
29181 + /* todo: reval? */
29182 + fi_read_lock(file);
29185 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
29186 + && cookie->generation != au_figen(file)))
29191 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
29193 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
29195 + bbot = au_fbtop(file);
29196 + if (cookie->bindex < bbot)
29197 + cookie->bindex = bbot;
29198 + bbot = au_fbbot_dir(file);
29199 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
29200 + for (; !err && cookie->bindex <= bbot;
29201 + cookie->bindex++, cookie->h_pos = 0) {
29202 + h_file = au_hf_dir(file, cookie->bindex);
29206 + au_fclr_rdu(cookie->flags, FULL);
29207 + err = au_rdu_do(h_file, &arg);
29209 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
29212 + AuDbg("rent %llu\n", rdu->rent);
29214 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
29215 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
29216 + au_fset_rdu(cookie->flags, CONT);
29217 + cookie->generation = au_figen(file);
29220 + ii_read_lock_child(inode);
29221 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
29222 + ii_read_unlock(inode);
29225 + fi_read_unlock(file);
29227 + si_read_unlock(arg.sb);
29229 + inode_unlock_shared(inode);
29235 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
29239 + unsigned long long nent;
29240 + union au_rdu_ent_ul *u;
29241 + struct au_rdu_ent ent;
29242 + struct super_block *sb;
29245 + nent = rdu->nent;
29247 + sb = file->f_path.dentry->d_sb;
29248 + si_read_lock(sb, AuLock_FLUSH);
29249 + while (nent-- > 0) {
29250 + /* unnecessary to support mmap_sem since this is a dir */
29251 + err = copy_from_user(&ent, u->e, sizeof(ent));
29253 + /* VERIFY_WRITE */
29254 + err = !access_ok(&u->e->ino, sizeof(ino));
29255 + if (unlikely(err)) {
29261 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
29263 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
29265 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
29267 + if (unlikely(err)) {
29272 + err = __put_user(ino, &u->e->ino);
29273 + if (unlikely(err)) {
29278 + u->ul += au_rdu_len(ent.nlen);
29280 + si_read_unlock(sb);
29285 +/* ---------------------------------------------------------------------- */
29287 +static int au_rdu_verify(struct aufs_rdu *rdu)
29289 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
29290 + "%llu, b%d, 0x%x, g%u}\n",
29291 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
29293 + rdu->rent, rdu->shwh, rdu->full,
29294 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
29295 + rdu->cookie.generation);
29297 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
29301 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
29305 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29308 + struct aufs_rdu rdu;
29309 + void __user *p = (void __user *)arg;
29311 + err = copy_from_user(&rdu, p, sizeof(rdu));
29312 + if (unlikely(err)) {
29317 + err = au_rdu_verify(&rdu);
29318 + if (unlikely(err))
29322 + case AUFS_CTL_RDU:
29323 + err = au_rdu(file, &rdu);
29324 + if (unlikely(err))
29327 + e = copy_to_user(p, &rdu, sizeof(rdu));
29328 + if (unlikely(e)) {
29333 + case AUFS_CTL_RDU_INO:
29334 + err = au_rdu_ino(file, &rdu);
29338 + /* err = -ENOTTY; */
29347 +#ifdef CONFIG_COMPAT
29348 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29351 + struct aufs_rdu rdu;
29352 + void __user *p = compat_ptr(arg);
29354 + /* todo: get_user()? */
29355 + err = copy_from_user(&rdu, p, sizeof(rdu));
29356 + if (unlikely(err)) {
29361 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29362 + err = au_rdu_verify(&rdu);
29363 + if (unlikely(err))
29367 + case AUFS_CTL_RDU:
29368 + err = au_rdu(file, &rdu);
29369 + if (unlikely(err))
29372 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29373 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29374 + e = copy_to_user(p, &rdu, sizeof(rdu));
29375 + if (unlikely(e)) {
29380 + case AUFS_CTL_RDU_INO:
29381 + err = au_rdu_ino(file, &rdu);
29385 + /* err = -ENOTTY; */
29394 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29395 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29396 +++ linux/fs/aufs/rwsem.h 2022-11-05 23:02:18.969222617 +0100
29398 +/* SPDX-License-Identifier: GPL-2.0 */
29400 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29402 + * This program is free software; you can redistribute it and/or modify
29403 + * it under the terms of the GNU General Public License as published by
29404 + * the Free Software Foundation; either version 2 of the License, or
29405 + * (at your option) any later version.
29407 + * This program is distributed in the hope that it will be useful,
29408 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29409 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29410 + * GNU General Public License for more details.
29412 + * You should have received a copy of the GNU General Public License
29413 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29417 + * simple read-write semaphore wrappers
29420 +#ifndef __AUFS_RWSEM_H__
29421 +#define __AUFS_RWSEM_H__
29425 +#include "debug.h"
29427 +/* in the future, the name 'au_rwsem' will be totally gone */
29428 +#define au_rwsem rw_semaphore
29430 +/* to debug easier, do not make them inlined functions */
29431 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29433 +#ifdef CONFIG_LOCKDEP
29434 +/* rwsem_is_locked() is unusable */
29435 +#define AuRwMustReadLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29436 + && !lockdep_recursing(current) \
29438 + && !lockdep_is_held_type(rw, 1))
29439 +#define AuRwMustWriteLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29440 + && !lockdep_recursing(current) \
29442 + && !lockdep_is_held_type(rw, 0))
29443 +#define AuRwMustAnyLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29444 + && !lockdep_recursing(current) \
29446 + && !lockdep_is_held(rw))
29447 +#define AuRwDestroy(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29448 + && !lockdep_recursing(current) \
29450 + && lockdep_is_held(rw))
29452 +#define AuRwMustReadLock(rw) do {} while (0)
29453 +#define AuRwMustWriteLock(rw) do {} while (0)
29454 +#define AuRwMustAnyLock(rw) do {} while (0)
29455 +#define AuRwDestroy(rw) do {} while (0)
29458 +#define au_rw_init(rw) init_rwsem(rw)
29460 +#define au_rw_init_wlock(rw) do { \
29461 + au_rw_init(rw); \
29462 + down_write(rw); \
29465 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29466 + au_rw_init(rw); \
29467 + down_write_nested(rw, lsc); \
29470 +#define au_rw_read_lock(rw) down_read(rw)
29471 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29472 +#define au_rw_read_unlock(rw) up_read(rw)
29473 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29474 +#define au_rw_write_lock(rw) down_write(rw)
29475 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29476 +#define au_rw_write_unlock(rw) up_write(rw)
29477 +/* why is not _nested version defined? */
29478 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29479 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29481 +#endif /* __KERNEL__ */
29482 +#endif /* __AUFS_RWSEM_H__ */
29483 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29484 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29485 +++ linux/fs/aufs/sbinfo.c 2022-11-05 23:02:18.969222617 +0100
29487 +// SPDX-License-Identifier: GPL-2.0
29489 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29491 + * This program is free software; you can redistribute it and/or modify
29492 + * it under the terms of the GNU General Public License as published by
29493 + * the Free Software Foundation; either version 2 of the License, or
29494 + * (at your option) any later version.
29496 + * This program is distributed in the hope that it will be useful,
29497 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29498 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29499 + * GNU General Public License for more details.
29501 + * You should have received a copy of the GNU General Public License
29502 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29506 + * superblock private data
29509 +#include <linux/iversion.h>
29513 + * they are necessary regardless sysfs is disabled.
29515 +void au_si_free(struct kobject *kobj)
29518 + struct au_sbinfo *sbinfo;
29519 + char *locked __maybe_unused; /* debug only */
29521 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29522 + for (i = 0; i < AuPlink_NHASH; i++)
29523 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29524 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29526 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29527 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29528 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29529 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29531 + dbgaufs_si_fin(sbinfo);
29532 + au_rw_write_lock(&sbinfo->si_rwsem);
29533 + au_br_free(sbinfo);
29534 + au_rw_write_unlock(&sbinfo->si_rwsem);
29536 + au_kfree_try_rcu(sbinfo->si_branch);
29537 + mutex_destroy(&sbinfo->si_xib_mtx);
29538 + AuRwDestroy(&sbinfo->si_rwsem);
29540 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29541 + /* si_nfiles is waited too */
29542 + au_kfree_rcu(sbinfo);
29545 +struct au_sbinfo *au_si_alloc(struct super_block *sb)
29547 + struct au_sbinfo *sbinfo;
29551 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29552 + if (unlikely(!sbinfo))
29555 + /* will be reallocated separately */
29556 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29557 + if (unlikely(!sbinfo->si_branch))
29560 + err = sysaufs_si_init(sbinfo);
29562 + dbgaufs_si_null(sbinfo);
29563 + err = dbgaufs_si_init(sbinfo);
29564 + if (unlikely(err))
29565 + kobject_put(&sbinfo->si_kobj);
29567 + if (unlikely(err))
29570 + au_nwt_init(&sbinfo->si_nowait);
29571 + au_rw_init_wlock(&sbinfo->si_rwsem);
29573 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29574 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29576 + sbinfo->si_bbot = -1;
29577 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29579 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29580 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29581 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29582 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29584 + au_fhsm_init(sbinfo);
29586 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29588 + sbinfo->si_xino_jiffy = jiffies;
29589 + sbinfo->si_xino_expire
29590 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29591 + mutex_init(&sbinfo->si_xib_mtx);
29592 + /* leave si_xib_last_pindex and si_xib_next_bit */
29594 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29596 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29597 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29598 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29599 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29601 + for (i = 0; i < AuPlink_NHASH; i++)
29602 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29603 + init_waitqueue_head(&sbinfo->si_plink_wq);
29604 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29606 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29608 + /* with getattr by default */
29609 + sbinfo->si_iop_array = aufs_iop;
29611 + /* leave other members for sysaufs and si_mnt. */
29612 + sbinfo->si_sb = sb;
29614 + sb->s_fs_info = sbinfo;
29617 + return sbinfo; /* success */
29620 + au_kfree_try_rcu(sbinfo->si_branch);
29622 + au_kfree_rcu(sbinfo);
29624 + return ERR_PTR(err);
29627 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29630 + struct au_branch **brp;
29632 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29635 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29636 + if (unlikely(!sz))
29637 + sz = sizeof(*brp);
29638 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29641 + sbinfo->si_branch = brp;
29648 +/* ---------------------------------------------------------------------- */
29650 +unsigned int au_sigen_inc(struct super_block *sb)
29652 + unsigned int gen;
29653 + struct inode *inode;
29655 + SiMustWriteLock(sb);
29657 + gen = ++au_sbi(sb)->si_generation;
29658 + au_update_digen(sb->s_root);
29659 + inode = d_inode(sb->s_root);
29660 + au_update_iigen(inode, /*half*/0);
29661 + inode_inc_iversion(inode);
29665 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29667 + aufs_bindex_t br_id;
29669 + struct au_sbinfo *sbinfo;
29671 + SiMustWriteLock(sb);
29673 + sbinfo = au_sbi(sb);
29674 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29675 + br_id = ++sbinfo->si_last_br_id;
29676 + AuDebugOn(br_id < 0);
29677 + if (br_id && au_br_index(sb, br_id) < 0)
29684 +/* ---------------------------------------------------------------------- */
29686 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29687 +int si_read_lock(struct super_block *sb, int flags)
29692 + if (au_ftest_lock(flags, FLUSH))
29693 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29695 + si_noflush_read_lock(sb);
29696 + err = au_plink_maint(sb, flags);
29697 + if (unlikely(err))
29698 + si_read_unlock(sb);
29703 +int si_write_lock(struct super_block *sb, int flags)
29707 + if (au_ftest_lock(flags, FLUSH))
29708 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29710 + si_noflush_write_lock(sb);
29711 + err = au_plink_maint(sb, flags);
29712 + if (unlikely(err))
29713 + si_write_unlock(sb);
29718 +/* dentry and super_block lock. call at entry point */
29719 +int aufs_read_lock(struct dentry *dentry, int flags)
29722 + struct super_block *sb;
29724 + sb = dentry->d_sb;
29725 + err = si_read_lock(sb, flags);
29726 + if (unlikely(err))
29729 + if (au_ftest_lock(flags, DW))
29730 + di_write_lock_child(dentry);
29732 + di_read_lock_child(dentry, flags);
29734 + if (au_ftest_lock(flags, GEN)) {
29735 + err = au_digen_test(dentry, au_sigen(sb));
29736 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29737 + AuDebugOn(!err && au_dbrange_test(dentry));
29739 + err = au_dbrange_test(dentry);
29740 + if (unlikely(err))
29741 + aufs_read_unlock(dentry, flags);
29748 +void aufs_read_unlock(struct dentry *dentry, int flags)
29750 + if (au_ftest_lock(flags, DW))
29751 + di_write_unlock(dentry);
29753 + di_read_unlock(dentry, flags);
29754 + si_read_unlock(dentry->d_sb);
29757 +void aufs_write_lock(struct dentry *dentry)
29759 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29760 + di_write_lock_child(dentry);
29763 +void aufs_write_unlock(struct dentry *dentry)
29765 + di_write_unlock(dentry);
29766 + si_write_unlock(dentry->d_sb);
29769 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29772 + unsigned int sigen;
29773 + struct super_block *sb;
29776 + err = si_read_lock(sb, flags);
29777 + if (unlikely(err))
29780 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29782 + if (au_ftest_lock(flags, GEN)) {
29783 + sigen = au_sigen(sb);
29784 + err = au_digen_test(d1, sigen);
29785 + AuDebugOn(!err && au_dbrange_test(d1));
29787 + err = au_digen_test(d2, sigen);
29788 + AuDebugOn(!err && au_dbrange_test(d2));
29790 + if (unlikely(err))
29791 + aufs_read_and_write_unlock2(d1, d2);
29798 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29800 + di_write_unlock2(d1, d2);
29801 + si_read_unlock(d1->d_sb);
29803 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29804 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29805 +++ linux/fs/aufs/super.c 2022-11-05 23:02:18.969222617 +0100
29807 +// SPDX-License-Identifier: GPL-2.0
29809 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29811 + * This program is free software; you can redistribute it and/or modify
29812 + * it under the terms of the GNU General Public License as published by
29813 + * the Free Software Foundation; either version 2 of the License, or
29814 + * (at your option) any later version.
29816 + * This program is distributed in the hope that it will be useful,
29817 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29818 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29819 + * GNU General Public License for more details.
29821 + * You should have received a copy of the GNU General Public License
29822 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29826 + * mount and super_block operations
29829 +#include <linux/iversion.h>
29830 +#include <linux/mm.h>
29831 +#include <linux/seq_file.h>
29832 +#include <linux/statfs.h>
29833 +#include <linux/vmalloc.h>
29837 + * super_operations
29839 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29841 + struct au_icntnr *c;
29843 + c = au_cache_alloc_icntnr(sb);
29845 + au_icntnr_init(c);
29846 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29847 + c->iinfo.ii_hinode = NULL;
29848 + return &c->vfs_inode;
29853 +static void aufs_destroy_inode(struct inode *inode)
29855 + if (!au_is_bad_inode(inode))
29856 + au_iinfo_fin(inode);
29859 +static void aufs_free_inode(struct inode *inode)
29861 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29864 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29866 + struct inode *inode;
29869 + inode = iget_locked(sb, ino);
29870 + if (unlikely(!inode)) {
29871 + inode = ERR_PTR(-ENOMEM);
29874 + if (!(inode->i_state & I_NEW))
29877 + err = au_xigen_new(inode);
29879 + err = au_iinfo_init(inode);
29881 + inode_inc_iversion(inode);
29883 + iget_failed(inode);
29884 + inode = ERR_PTR(err);
29888 + /* never return NULL */
29889 + AuDebugOn(!inode);
29890 + AuTraceErrPtr(inode);
29894 +/* lock free root dinfo */
29895 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29898 + aufs_bindex_t bindex, bbot;
29899 + struct path path;
29900 + struct au_hdentry *hdp;
29901 + struct au_branch *br;
29902 + au_br_perm_str_t perm;
29905 + bbot = au_sbbot(sb);
29907 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29908 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29909 + br = au_sbr(sb, bindex);
29910 + path.mnt = au_br_mnt(br);
29911 + path.dentry = hdp->hd_dentry;
29912 + err = au_seq_path(seq, &path);
29914 + au_optstr_br_perm(&perm, br->br_perm);
29915 + seq_printf(seq, "=%s", perm.a);
29916 + if (bindex != bbot)
29917 + seq_putc(seq, ':');
29920 + if (unlikely(err || seq_has_overflowed(seq)))
29926 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29927 + const char *append)
29932 + while (*pat != ':')
29935 + strcpy(p, append);
29936 + AuDebugOn(strlen(fmt) >= len);
29939 +static void au_show_wbr_create(struct seq_file *m, int v,
29940 + struct au_sbinfo *sbinfo)
29944 + struct au_wbr_mfs *mfs;
29946 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29948 + seq_puts(m, ",create=");
29949 + pat = au_optstr_wbr_create(v);
29950 + mfs = &sbinfo->si_wbr_mfs;
29952 + case AuWbrCreate_TDP:
29953 + case AuWbrCreate_RR:
29954 + case AuWbrCreate_MFS:
29955 + case AuWbrCreate_PMFS:
29956 + seq_puts(m, pat);
29958 + case AuWbrCreate_MFSRR:
29959 + case AuWbrCreate_TDMFS:
29960 + case AuWbrCreate_PMFSRR:
29961 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29962 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29964 + case AuWbrCreate_MFSV:
29965 + case AuWbrCreate_PMFSV:
29966 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29967 + seq_printf(m, fmt,
29968 + jiffies_to_msecs(mfs->mfs_expire)
29971 + case AuWbrCreate_MFSRRV:
29972 + case AuWbrCreate_TDMFSV:
29973 + case AuWbrCreate_PMFSRRV:
29974 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29975 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29976 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29983 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29985 +#ifdef CONFIG_SYSFS
29989 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29990 + aufs_bindex_t bindex, brid;
29991 + struct qstr *name;
29993 + struct dentry *d, *h_root;
29994 + struct au_branch *br;
29996 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29999 + f = au_sbi(sb)->si_xib;
30003 + /* stop printing the default xino path on the first writable branch */
30005 + bindex = au_xi_root(sb, f->f_path.dentry);
30006 + if (bindex >= 0) {
30007 + br = au_sbr_sb(sb, bindex);
30008 + h_root = au_br_dentry(br);
30011 + d = f->f_path.dentry;
30012 + name = &d->d_name;
30013 + /* safe ->d_parent because the file is unlinked */
30014 + if (d->d_parent == h_root
30015 + && name->len == len
30016 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
30019 + seq_puts(seq, ",xino=");
30020 + err = au_xino_path(seq, f);
30027 +/* seq_file will re-call me in case of too long string */
30028 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
30031 + unsigned int mnt_flags, v;
30032 + struct super_block *sb;
30033 + struct au_sbinfo *sbinfo;
30035 +#define AuBool(name, str) do { \
30036 + v = au_opt_test(mnt_flags, name); \
30037 + if (v != au_opt_test(AuOpt_Def, name)) \
30038 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
30041 +#define AuStr(name, str) do { \
30042 + v = mnt_flags & AuOptMask_##name; \
30043 + if (v != (AuOpt_Def & AuOptMask_##name)) \
30044 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
30047 +#define AuUInt(name, str, val) do { \
30048 + if (val != AUFS_##name##_DEF) \
30049 + seq_printf(m, "," #str "=%u", val); \
30052 + sb = dentry->d_sb;
30053 + if (sb->s_flags & SB_POSIXACL)
30054 + seq_puts(m, ",acl");
30055 +#if 0 /* reserved for future use */
30056 + if (sb->s_flags & SB_I_VERSION)
30057 + seq_puts(m, ",i_version");
30060 + /* lock free root dinfo */
30061 + si_noflush_read_lock(sb);
30062 + sbinfo = au_sbi(sb);
30063 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
30065 + mnt_flags = au_mntflags(sb);
30066 + if (au_opt_test(mnt_flags, XINO)) {
30067 + err = au_show_xino(m, sb);
30068 + if (unlikely(err))
30071 + seq_puts(m, ",noxino");
30073 + AuBool(TRUNC_XINO, trunc_xino);
30074 + AuStr(UDBA, udba);
30075 + AuBool(SHWH, shwh);
30076 + AuBool(PLINK, plink);
30077 + AuBool(DIO, dio);
30078 + AuBool(DIRPERM1, dirperm1);
30080 + v = sbinfo->si_wbr_create;
30081 + if (v != AuWbrCreate_Def)
30082 + au_show_wbr_create(m, v, sbinfo);
30084 + v = sbinfo->si_wbr_copyup;
30085 + if (v != AuWbrCopyup_Def)
30086 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
30088 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
30089 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
30090 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
30092 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
30094 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
30095 + AuUInt(RDCACHE, rdcache, v);
30097 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
30098 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
30100 + au_fhsm_show(m, sbinfo);
30102 + AuBool(DIRREN, dirren);
30103 + AuBool(SUM, sum);
30104 + /* AuBool(SUM_W, wsum); */
30105 + AuBool(WARN_PERM, warn_perm);
30106 + AuBool(VERBOSE, verbose);
30109 + /* be sure to print "br:" last */
30110 + if (!sysaufs_brs) {
30111 + seq_puts(m, ",br:");
30112 + au_show_brs(m, sb);
30114 + si_read_unlock(sb);
30122 +/* ---------------------------------------------------------------------- */
30124 +/* sum mode which returns the summation for statfs(2) */
30126 +static u64 au_add_till_max(u64 a, u64 b)
30134 + return ULLONG_MAX;
30137 +static u64 au_mul_till_max(u64 a, long mul)
30145 + return ULLONG_MAX;
30148 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
30151 + long bsize, factor;
30152 + u64 blocks, bfree, bavail, files, ffree;
30153 + aufs_bindex_t bbot, bindex, i;
30154 + unsigned char shared;
30155 + struct path h_path;
30156 + struct super_block *h_sb;
30159 + bsize = LONG_MAX;
30165 + bbot = au_sbbot(sb);
30166 + for (bindex = 0; bindex <= bbot; bindex++) {
30167 + h_path.mnt = au_sbr_mnt(sb, bindex);
30168 + h_sb = h_path.mnt->mnt_sb;
30170 + for (i = 0; !shared && i < bindex; i++)
30171 + shared = (au_sbr_sb(sb, i) == h_sb);
30175 + /* sb->s_root for NFS is unreliable */
30176 + h_path.dentry = h_path.mnt->mnt_root;
30177 + err = vfs_statfs(&h_path, buf);
30178 + if (unlikely(err))
30181 + if (bsize > buf->f_bsize) {
30183 + * we will reduce bsize, so we have to expand blocks
30184 + * etc. to match them again
30186 + factor = (bsize / buf->f_bsize);
30187 + blocks = au_mul_till_max(blocks, factor);
30188 + bfree = au_mul_till_max(bfree, factor);
30189 + bavail = au_mul_till_max(bavail, factor);
30190 + bsize = buf->f_bsize;
30193 + factor = (buf->f_bsize / bsize);
30194 + blocks = au_add_till_max(blocks,
30195 + au_mul_till_max(buf->f_blocks, factor));
30196 + bfree = au_add_till_max(bfree,
30197 + au_mul_till_max(buf->f_bfree, factor));
30198 + bavail = au_add_till_max(bavail,
30199 + au_mul_till_max(buf->f_bavail, factor));
30200 + files = au_add_till_max(files, buf->f_files);
30201 + ffree = au_add_till_max(ffree, buf->f_ffree);
30204 + buf->f_bsize = bsize;
30205 + buf->f_blocks = blocks;
30206 + buf->f_bfree = bfree;
30207 + buf->f_bavail = bavail;
30208 + buf->f_files = files;
30209 + buf->f_ffree = ffree;
30210 + buf->f_frsize = 0;
30216 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
30219 + struct path h_path;
30220 + struct super_block *sb;
30222 + /* lock free root dinfo */
30223 + sb = dentry->d_sb;
30224 + si_noflush_read_lock(sb);
30225 + if (!au_opt_test(au_mntflags(sb), SUM)) {
30226 + /* sb->s_root for NFS is unreliable */
30227 + h_path.mnt = au_sbr_mnt(sb, 0);
30228 + h_path.dentry = h_path.mnt->mnt_root;
30229 + err = vfs_statfs(&h_path, buf);
30231 + err = au_statfs_sum(sb, buf);
30232 + si_read_unlock(sb);
30235 + buf->f_type = AUFS_SUPER_MAGIC;
30236 + buf->f_namelen = AUFS_MAX_NAMELEN;
30237 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
30239 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
30244 +/* ---------------------------------------------------------------------- */
30246 +static int aufs_sync_fs(struct super_block *sb, int wait)
30249 + aufs_bindex_t bbot, bindex;
30250 + struct au_branch *br;
30251 + struct super_block *h_sb;
30254 + si_noflush_read_lock(sb);
30255 + bbot = au_sbbot(sb);
30256 + for (bindex = 0; bindex <= bbot; bindex++) {
30257 + br = au_sbr(sb, bindex);
30258 + if (!au_br_writable(br->br_perm))
30261 + h_sb = au_sbr_sb(sb, bindex);
30262 + e = vfsub_sync_filesystem(h_sb);
30263 + if (unlikely(e && !err))
30265 + /* go on even if an error happens */
30267 + si_read_unlock(sb);
30272 +/* ---------------------------------------------------------------------- */
30274 +/* final actions when unmounting a file system */
30275 +static void aufs_put_super(struct super_block *sb)
30277 + struct au_sbinfo *sbinfo;
30279 + sbinfo = au_sbi(sb);
30281 + kobject_put(&sbinfo->si_kobj);
30284 +/* ---------------------------------------------------------------------- */
30286 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30287 + struct super_block *sb, void *arg)
30290 + unsigned long long n, sz;
30297 + if (*hint > ULLONG_MAX / sizeof(array)) {
30298 + array = ERR_PTR(-EMFILE);
30299 + pr_err("hint %llu\n", *hint);
30303 + sz = sizeof(array) * *hint;
30304 + array = kzalloc(sz, GFP_NOFS);
30305 + if (unlikely(!array))
30306 + array = vzalloc(sz);
30307 + if (unlikely(!array)) {
30308 + array = ERR_PTR(-ENOMEM);
30312 + n = cb(sb, array, *hint, arg);
30313 + AuDebugOn(n > *hint);
30320 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
30321 + unsigned long long max __maybe_unused,
30324 + unsigned long long n;
30325 + struct inode **p, *inode;
30326 + struct list_head *head;
30331 + spin_lock(&sb->s_inode_list_lock);
30332 + list_for_each_entry(inode, head, i_sb_list) {
30333 + if (!au_is_bad_inode(inode)
30334 + && au_ii(inode)->ii_btop >= 0) {
30335 + spin_lock(&inode->i_lock);
30336 + if (atomic_read(&inode->i_count)) {
30340 + AuDebugOn(n > max);
30342 + spin_unlock(&inode->i_lock);
30345 + spin_unlock(&sb->s_inode_list_lock);
30350 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
30352 + struct au_sbinfo *sbi;
30354 + sbi = au_sbi(sb);
30355 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
30356 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
30359 +void au_iarray_free(struct inode **a, unsigned long long max)
30361 + unsigned long long ull;
30363 + for (ull = 0; ull < max; ull++)
30368 +/* ---------------------------------------------------------------------- */
30371 + * refresh dentry and inode at remount time.
30373 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30374 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30375 + struct dentry *parent)
30379 + di_write_lock_child(dentry);
30380 + di_read_lock_parent(parent, AuLock_IR);
30381 + err = au_refresh_dentry(dentry, parent);
30382 + if (!err && dir_flags)
30383 + au_hn_reset(d_inode(dentry), dir_flags);
30384 + di_read_unlock(parent, AuLock_IR);
30385 + di_write_unlock(dentry);
30390 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30391 + struct au_sbinfo *sbinfo,
30392 + const unsigned int dir_flags, unsigned int do_idop)
30395 + struct dentry *parent;
30398 + parent = dget_parent(dentry);
30399 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30400 + if (d_really_is_positive(dentry)) {
30401 + if (!d_is_dir(dentry))
30402 + err = au_do_refresh(dentry, /*dir_flags*/0,
30405 + err = au_do_refresh(dentry, dir_flags, parent);
30406 + if (unlikely(err))
30407 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30410 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30411 + AuDbgDentry(dentry);
30417 + au_refresh_dop(dentry, /*force_reval*/0);
30419 + au_refresh_dop(dentry, /*force_reval*/1);
30425 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30427 + int err, i, j, ndentry, e;
30428 + unsigned int sigen;
30429 + struct au_dcsub_pages dpages;
30430 + struct au_dpage *dpage;
30431 + struct dentry **dentries, *d;
30432 + struct au_sbinfo *sbinfo;
30433 + struct dentry *root = sb->s_root;
30434 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30437 + au_refresh_dop(root, /*force_reval*/0);
30439 + err = au_dpages_init(&dpages, GFP_NOFS);
30440 + if (unlikely(err))
30442 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30443 + if (unlikely(err))
30446 + sigen = au_sigen(sb);
30447 + sbinfo = au_sbi(sb);
30448 + for (i = 0; i < dpages.ndpage; i++) {
30449 + dpage = dpages.dpages + i;
30450 + dentries = dpage->dentries;
30451 + ndentry = dpage->ndentry;
30452 + for (j = 0; j < ndentry; j++) {
30454 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30456 + if (unlikely(e && !err))
30458 + /* go on even err */
30463 + au_dpages_free(&dpages);
30468 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30471 + unsigned int sigen;
30472 + unsigned long long max, ull;
30473 + struct inode *inode, **array;
30475 + array = au_iarray_alloc(sb, &max);
30476 + err = PTR_ERR(array);
30477 + if (IS_ERR(array))
30481 + sigen = au_sigen(sb);
30482 + for (ull = 0; ull < max; ull++) {
30483 + inode = array[ull];
30484 + if (unlikely(!inode))
30488 + ii_write_lock_child(inode);
30489 + if (au_iigen(inode, NULL) != sigen) {
30490 + e = au_refresh_hinode_self(inode);
30491 + if (unlikely(e)) {
30492 + au_refresh_iop(inode, /*force_getattr*/1);
30493 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30496 + /* go on even if err */
30499 + if (!e && do_idop)
30500 + au_refresh_iop(inode, /*force_getattr*/0);
30501 + ii_write_unlock(inode);
30504 + au_iarray_free(array, max);
30510 +void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30513 + unsigned int udba;
30514 + aufs_bindex_t bindex, bbot;
30515 + struct dentry *root;
30516 + struct inode *inode;
30517 + struct au_branch *br;
30518 + struct au_sbinfo *sbi;
30520 + au_sigen_inc(sb);
30521 + sbi = au_sbi(sb);
30522 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30524 + root = sb->s_root;
30525 + DiMustNoWaiters(root);
30526 + inode = d_inode(root);
30527 + IiMustNoWaiters(inode);
30529 + udba = au_opt_udba(sb);
30530 + bbot = au_sbbot(sb);
30531 + for (bindex = 0; bindex <= bbot; bindex++) {
30532 + br = au_sbr(sb, bindex);
30533 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30534 + if (unlikely(err))
30535 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30537 + /* go on even if err */
30539 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30542 + if (au_ftest_si(sbi, NO_DREVAL)) {
30543 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30544 + sb->s_d_op = &aufs_dop_noreval;
30545 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30546 + sbi->si_iop_array = aufs_iop_nogetattr;
30548 + AuDebugOn(sb->s_d_op == &aufs_dop);
30549 + sb->s_d_op = &aufs_dop;
30550 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30551 + sbi->si_iop_array = aufs_iop;
30553 + pr_info("reset to %ps and %ps\n",
30554 + sb->s_d_op, sbi->si_iop_array);
30557 + di_write_unlock(root);
30558 + err = au_refresh_d(sb, do_idop);
30559 + e = au_refresh_i(sb, do_idop);
30560 + if (unlikely(e && !err))
30562 + /* aufs_write_lock() calls ..._child() */
30563 + di_write_lock_child(root);
30565 + au_cpup_attr_all(inode, /*force*/1);
30567 + if (unlikely(err))
30568 + AuIOErr("refresh failed, ignored, %d\n", err);
30571 +const struct super_operations aufs_sop = {
30572 + .alloc_inode = aufs_alloc_inode,
30573 + .destroy_inode = aufs_destroy_inode,
30574 + .free_inode = aufs_free_inode,
30575 + /* always deleting, no clearing */
30576 + .drop_inode = generic_delete_inode,
30577 + .show_options = aufs_show_options,
30578 + .statfs = aufs_statfs,
30579 + .put_super = aufs_put_super,
30580 + .sync_fs = aufs_sync_fs
30583 +/* ---------------------------------------------------------------------- */
30585 +int au_alloc_root(struct super_block *sb)
30588 + struct inode *inode;
30589 + struct dentry *root;
30592 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30593 + err = PTR_ERR(inode);
30594 + if (IS_ERR(inode))
30597 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30598 + inode->i_fop = &aufs_dir_fop;
30599 + inode->i_mode = S_IFDIR;
30600 + set_nlink(inode, 2);
30601 + unlock_new_inode(inode);
30603 + root = d_make_root(inode);
30604 + if (unlikely(!root))
30606 + err = PTR_ERR(root);
30607 + if (IS_ERR(root))
30610 + err = au_di_init(root);
30612 + sb->s_root = root;
30613 + return 0; /* success */
30621 +/* ---------------------------------------------------------------------- */
30623 +static void aufs_kill_sb(struct super_block *sb)
30625 + struct au_sbinfo *sbinfo;
30626 + struct dentry *root;
30628 + sbinfo = au_sbi(sb);
30632 + au_sbilist_del(sb);
30634 + root = sb->s_root;
30636 + aufs_write_lock(root);
30638 + __si_write_lock(sb);
30641 + if (sbinfo->si_wbr_create_ops->fin)
30642 + sbinfo->si_wbr_create_ops->fin(sb);
30643 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30644 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30645 + au_remount_refresh(sb, /*do_idop*/0);
30647 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30648 + au_plink_put(sb, /*verbose*/1);
30651 + au_dr_opt_flush(sb);
30654 + aufs_write_unlock(root);
30656 + __si_write_unlock(sb);
30658 + sbinfo->si_sb = NULL;
30659 + au_nwt_flush(&sbinfo->si_nowait);
30662 + kill_anon_super(sb);
30665 +struct file_system_type aufs_fs_type = {
30666 + .name = AUFS_FSTYPE,
30667 + /* a race between rename and others */
30668 + .fs_flags = FS_RENAME_DOES_D_MOVE
30670 + /*| FS_ALLOW_IDMAP*/
30672 + .init_fs_context = aufs_fsctx_init,
30673 + .parameters = aufs_fsctx_paramspec,
30674 + .kill_sb = aufs_kill_sb,
30675 + /* no need to __module_get() and module_put(). */
30676 + .owner = THIS_MODULE,
30678 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30679 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30680 +++ linux/fs/aufs/super.h 2022-11-05 23:02:18.969222617 +0100
30682 +/* SPDX-License-Identifier: GPL-2.0 */
30684 + * Copyright (C) 2005-2022 Junjiro R. Okajima
30686 + * This program is free software; you can redistribute it and/or modify
30687 + * it under the terms of the GNU General Public License as published by
30688 + * the Free Software Foundation; either version 2 of the License, or
30689 + * (at your option) any later version.
30691 + * This program is distributed in the hope that it will be useful,
30692 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30693 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30694 + * GNU General Public License for more details.
30696 + * You should have received a copy of the GNU General Public License
30697 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30701 + * super_block operations
30704 +#ifndef __AUFS_SUPER_H__
30705 +#define __AUFS_SUPER_H__
30709 +#include <linux/fs.h>
30710 +#include <linux/kobject.h>
30713 +#include "rwsem.h"
30716 +/* policies to select one among multiple writable branches */
30717 +struct au_wbr_copyup_operations {
30718 + int (*copyup)(struct dentry *dentry);
30721 +#define AuWbr_DIR 1 /* target is a dir */
30722 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30724 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30725 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30726 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30728 +struct au_wbr_create_operations {
30729 + int (*create)(struct dentry *dentry, unsigned int flags);
30730 + int (*init)(struct super_block *sb);
30731 + int (*fin)(struct super_block *sb);
30734 +struct au_wbr_mfs {
30735 + struct mutex mfs_lock; /* protect this structure */
30736 + unsigned long mfs_jiffy;
30737 + unsigned long mfs_expire;
30738 + aufs_bindex_t mfs_bindex;
30740 + unsigned long long mfsrr_bytes;
30741 + unsigned long long mfsrr_watermark;
30744 +#define AuPlink_NHASH 100
30745 +static inline int au_plink_hash(ino_t ino)
30747 + return ino % AuPlink_NHASH;
30750 +/* File-based Hierarchical Storage Management */
30752 +#ifdef CONFIG_AUFS_FHSM
30753 + /* allow only one process who can receive the notification */
30754 + spinlock_t fhsm_spin;
30756 + wait_queue_head_t fhsm_wqh;
30757 + atomic_t fhsm_readable;
30759 + /* these are protected by si_rwsem */
30760 + unsigned long fhsm_expire;
30761 + aufs_bindex_t fhsm_bottom;
30766 +struct au_sbinfo {
30767 + /* nowait tasks in the system-wide workqueue */
30768 + struct au_nowait_tasks si_nowait;
30771 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30772 + * rwsem for au_sbinfo is necessary.
30774 + struct au_rwsem si_rwsem;
30777 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30780 + au_lcnt_t si_ninodes, si_nfiles;
30782 + /* branch management */
30783 + unsigned int si_generation;
30785 + /* see AuSi_ flags */
30786 + unsigned char au_si_status;
30788 + aufs_bindex_t si_bbot;
30790 + /* dirty trick to keep br_id plus */
30791 + unsigned int si_last_br_id :
30792 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30793 + struct au_branch **si_branch;
30795 + /* policy to select a writable branch */
30796 + unsigned char si_wbr_copyup;
30797 + unsigned char si_wbr_create;
30798 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30799 + struct au_wbr_create_operations *si_wbr_create_ops;
30801 + /* round robin */
30802 + atomic_t si_wbr_rr_next;
30804 + /* most free space */
30805 + struct au_wbr_mfs si_wbr_mfs;
30807 + /* File-based Hierarchical Storage Management */
30808 + struct au_fhsm si_fhsm;
30810 + /* mount flags */
30811 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30812 + unsigned int si_mntflags;
30814 + /* external inode number (bitmap and translation table) */
30815 + loff_t si_ximaxent; /* max entries in a xino */
30817 + struct file *si_xib;
30818 + struct mutex si_xib_mtx; /* protect xib members */
30819 + unsigned long *si_xib_buf;
30820 + unsigned long si_xib_last_pindex;
30821 + int si_xib_next_bit;
30823 + unsigned long si_xino_jiffy;
30824 + unsigned long si_xino_expire;
30825 + /* reserved for future use */
30826 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30828 +#ifdef CONFIG_AUFS_EXPORT
30829 + /* i_generation */
30830 + /* todo: make xigen file an array to support many inode numbers */
30831 + struct file *si_xigen;
30832 + atomic_t si_xigen_next;
30835 + /* dirty trick to support atomic_open */
30836 + struct hlist_bl_head si_aopen;
30838 + /* vdir parameters */
30839 + unsigned long si_rdcache; /* max cache time in jiffies */
30840 + unsigned int si_rdblk; /* deblk size */
30841 + unsigned int si_rdhash; /* hash size */
30844 + * If the number of whiteouts are larger than si_dirwh, leave all of
30845 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30846 + * future fsck.aufs or kernel thread will remove them later.
30847 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30849 + unsigned int si_dirwh;
30851 + /* pseudo_link list */
30852 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30853 + wait_queue_head_t si_plink_wq;
30854 + spinlock_t si_plink_maint_lock;
30855 + pid_t si_plink_maint_pid;
30858 + struct hlist_bl_head si_files;
30860 + /* with/without getattr, brother of sb->s_d_op */
30861 + const struct inode_operations *si_iop_array;
30864 + * sysfs and lifetime management.
30865 + * this is not a small structure and it may be a waste of memory in case
30866 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30867 + * but using sysfs is majority.
30869 + struct kobject si_kobj;
30870 +#ifdef CONFIG_DEBUG_FS
30871 + struct dentry *si_dbgaufs;
30872 + struct dentry *si_dbgaufs_plink;
30873 + struct dentry *si_dbgaufs_xib;
30874 +#ifdef CONFIG_AUFS_EXPORT
30875 + struct dentry *si_dbgaufs_xigen;
30879 +#ifdef CONFIG_AUFS_SBILIST
30880 + struct hlist_bl_node si_list;
30883 + /* dirty, necessary for unmounting, sysfs and sysrq */
30884 + struct super_block *si_sb;
30887 +/* sbinfo status flags */
30889 + * set true when refresh_dirs() failed at remount time.
30890 + * then try refreshing dirs at access time again.
30891 + * if it is false, refreshing dirs at access time is unnecessary
30893 +#define AuSi_FAILED_REFRESH_DIR 1
30894 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30895 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30897 +#ifndef CONFIG_AUFS_FHSM
30899 +#define AuSi_FHSM 0
30902 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30903 + unsigned int flag)
30905 + AuRwMustAnyLock(&sbi->si_rwsem);
30906 + return sbi->au_si_status & flag;
30908 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30909 +#define au_fset_si(sbinfo, name) do { \
30910 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30911 + (sbinfo)->au_si_status |= AuSi_##name; \
30913 +#define au_fclr_si(sbinfo, name) do { \
30914 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30915 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30918 +/* ---------------------------------------------------------------------- */
30920 +/* policy to select one among writable branches */
30921 +#define AuWbrCopyup(sbinfo, ...) \
30922 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30923 +#define AuWbrCreate(sbinfo, ...) \
30924 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30926 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30927 +#define AuLock_DW 1 /* write-lock dentry */
30928 +#define AuLock_IR (1 << 1) /* read-lock inode */
30929 +#define AuLock_IW (1 << 2) /* write-lock inode */
30930 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30931 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30932 + /* except RENAME_EXCHANGE */
30933 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30934 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30935 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30936 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30937 +#define au_fset_lock(flags, name) \
30938 + do { (flags) |= AuLock_##name; } while (0)
30939 +#define au_fclr_lock(flags, name) \
30940 + do { (flags) &= ~AuLock_##name; } while (0)
30942 +/* ---------------------------------------------------------------------- */
30945 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30947 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30948 + unsigned long long max, void *arg);
30949 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30950 + struct super_block *sb, void *arg);
30951 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30952 +void au_iarray_free(struct inode **a, unsigned long long max);
30954 +void au_remount_refresh(struct super_block *sb, unsigned int do_idop);
30955 +extern const struct super_operations aufs_sop;
30956 +int au_alloc_root(struct super_block *sb);
30957 +extern struct file_system_type aufs_fs_type;
30960 +void au_si_free(struct kobject *kobj);
30961 +struct au_sbinfo *au_si_alloc(struct super_block *sb);
30962 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30964 +unsigned int au_sigen_inc(struct super_block *sb);
30965 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30967 +int si_read_lock(struct super_block *sb, int flags);
30968 +int si_write_lock(struct super_block *sb, int flags);
30969 +int aufs_read_lock(struct dentry *dentry, int flags);
30970 +void aufs_read_unlock(struct dentry *dentry, int flags);
30971 +void aufs_write_lock(struct dentry *dentry);
30972 +void aufs_write_unlock(struct dentry *dentry);
30973 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30974 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30976 +/* wbr_policy.c */
30977 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30978 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30979 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30980 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30981 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30984 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30986 +#ifdef CONFIG_AUFS_FHSM
30989 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30993 + spin_lock(&fhsm->fhsm_spin);
30994 + pid = fhsm->fhsm_pid;
30995 + spin_unlock(&fhsm->fhsm_spin);
31000 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
31001 +void au_fhsm_wrote_all(struct super_block *sb, int force);
31002 +int au_fhsm_fd(struct super_block *sb, int oflags);
31003 +int au_fhsm_br_alloc(struct au_branch *br);
31004 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
31005 +void au_fhsm_fin(struct super_block *sb);
31006 +void au_fhsm_init(struct au_sbinfo *sbinfo);
31007 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
31008 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
31010 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
31012 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
31013 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
31014 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
31015 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
31016 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
31017 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
31018 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
31019 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
31020 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
31023 +/* ---------------------------------------------------------------------- */
31025 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
31027 + return sb->s_fs_info;
31030 +/* ---------------------------------------------------------------------- */
31032 +#ifdef CONFIG_AUFS_EXPORT
31033 +int au_test_nfsd(void);
31034 +void au_export_init(struct super_block *sb);
31035 +void au_xigen_inc(struct inode *inode);
31036 +int au_xigen_new(struct inode *inode);
31037 +int au_xigen_set(struct super_block *sb, struct path *path);
31038 +void au_xigen_clr(struct super_block *sb);
31040 +static inline int au_busy_or_stale(void)
31042 + if (!au_test_nfsd())
31047 +AuStubInt0(au_test_nfsd, void)
31048 +AuStubVoid(au_export_init, struct super_block *sb)
31049 +AuStubVoid(au_xigen_inc, struct inode *inode)
31050 +AuStubInt0(au_xigen_new, struct inode *inode)
31051 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
31052 +AuStubVoid(au_xigen_clr, struct super_block *sb)
31053 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
31054 +#endif /* CONFIG_AUFS_EXPORT */
31056 +/* ---------------------------------------------------------------------- */
31058 +#ifdef CONFIG_AUFS_SBILIST
31060 +extern struct hlist_bl_head au_sbilist;
31062 +static inline void au_sbilist_init(void)
31064 + INIT_HLIST_BL_HEAD(&au_sbilist);
31067 +static inline void au_sbilist_add(struct super_block *sb)
31069 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
31072 +static inline void au_sbilist_del(struct super_block *sb)
31074 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
31077 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
31078 +static inline void au_sbilist_lock(void)
31080 + hlist_bl_lock(&au_sbilist);
31083 +static inline void au_sbilist_unlock(void)
31085 + hlist_bl_unlock(&au_sbilist);
31087 +#define AuGFP_SBILIST GFP_ATOMIC
31089 +AuStubVoid(au_sbilist_lock, void)
31090 +AuStubVoid(au_sbilist_unlock, void)
31091 +#define AuGFP_SBILIST GFP_NOFS
31092 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
31094 +AuStubVoid(au_sbilist_init, void)
31095 +AuStubVoid(au_sbilist_add, struct super_block *sb)
31096 +AuStubVoid(au_sbilist_del, struct super_block *sb)
31097 +AuStubVoid(au_sbilist_lock, void)
31098 +AuStubVoid(au_sbilist_unlock, void)
31099 +#define AuGFP_SBILIST GFP_NOFS
31102 +/* ---------------------------------------------------------------------- */
31104 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
31107 + * This function is a dynamic '__init' function actually,
31108 + * so the tiny check for si_rwsem is unnecessary.
31110 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
31111 +#ifdef CONFIG_DEBUG_FS
31112 + sbinfo->si_dbgaufs = NULL;
31113 + sbinfo->si_dbgaufs_plink = NULL;
31114 + sbinfo->si_dbgaufs_xib = NULL;
31115 +#ifdef CONFIG_AUFS_EXPORT
31116 + sbinfo->si_dbgaufs_xigen = NULL;
31121 +/* ---------------------------------------------------------------------- */
31123 +/* current->atomic_flags */
31124 +/* this value should never corrupt the ones defined in linux/sched.h */
31125 +#define PFA_AUFS 0x10
31127 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
31128 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
31129 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
31131 +static inline int si_pid_test(struct super_block *sb)
31133 + return !!task_test_aufs(current);
31136 +static inline void si_pid_clr(struct super_block *sb)
31138 + AuDebugOn(!task_test_aufs(current));
31139 + task_clear_aufs(current);
31142 +static inline void si_pid_set(struct super_block *sb)
31144 + AuDebugOn(task_test_aufs(current));
31145 + task_set_aufs(current);
31148 +/* ---------------------------------------------------------------------- */
31150 +/* lock superblock. mainly for entry point functions */
31151 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
31152 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
31153 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
31154 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
31156 +#define __si_read_trylock_nested(sb) \
31157 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
31158 +#define __si_write_trylock_nested(sb) \
31159 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
31162 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
31163 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
31164 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
31166 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
31167 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
31168 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
31170 +static inline void si_noflush_read_lock(struct super_block *sb)
31172 + __si_read_lock(sb);
31176 +static inline int si_noflush_read_trylock(struct super_block *sb)
31180 + locked = __si_read_trylock(sb);
31186 +static inline void si_noflush_write_lock(struct super_block *sb)
31188 + __si_write_lock(sb);
31192 +static inline int si_noflush_write_trylock(struct super_block *sb)
31196 + locked = __si_write_trylock(sb);
31202 +#if 0 /* reserved */
31203 +static inline int si_read_trylock(struct super_block *sb, int flags)
31205 + if (au_ftest_lock(flags, FLUSH))
31206 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31207 + return si_noflush_read_trylock(sb);
31211 +static inline void si_read_unlock(struct super_block *sb)
31214 + __si_read_unlock(sb);
31217 +#if 0 /* reserved */
31218 +static inline int si_write_trylock(struct super_block *sb, int flags)
31220 + if (au_ftest_lock(flags, FLUSH))
31221 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31222 + return si_noflush_write_trylock(sb);
31226 +static inline void si_write_unlock(struct super_block *sb)
31229 + __si_write_unlock(sb);
31232 +#if 0 /* reserved */
31233 +static inline void si_downgrade_lock(struct super_block *sb)
31235 + __si_downgrade_lock(sb);
31239 +/* ---------------------------------------------------------------------- */
31241 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31243 + SiMustAnyLock(sb);
31244 + return au_sbi(sb)->si_bbot;
31247 +static inline unsigned int au_mntflags(struct super_block *sb)
31249 + SiMustAnyLock(sb);
31250 + return au_sbi(sb)->si_mntflags;
31253 +static inline unsigned int au_sigen(struct super_block *sb)
31255 + SiMustAnyLock(sb);
31256 + return au_sbi(sb)->si_generation;
31259 +static inline struct au_branch *au_sbr(struct super_block *sb,
31260 + aufs_bindex_t bindex)
31262 + SiMustAnyLock(sb);
31263 + return au_sbi(sb)->si_branch[0 + bindex];
31266 +static inline loff_t au_xi_maxent(struct super_block *sb)
31268 + SiMustAnyLock(sb);
31269 + return au_sbi(sb)->si_ximaxent;
31272 +#endif /* __KERNEL__ */
31273 +#endif /* __AUFS_SUPER_H__ */
31274 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31275 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31276 +++ linux/fs/aufs/sysaufs.c 2022-11-05 23:02:18.969222617 +0100
31278 +// SPDX-License-Identifier: GPL-2.0
31280 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31282 + * This program is free software; you can redistribute it and/or modify
31283 + * it under the terms of the GNU General Public License as published by
31284 + * the Free Software Foundation; either version 2 of the License, or
31285 + * (at your option) any later version.
31287 + * This program is distributed in the hope that it will be useful,
31288 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31289 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31290 + * GNU General Public License for more details.
31292 + * You should have received a copy of the GNU General Public License
31293 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31297 + * sysfs interface and lifetime management
31298 + * they are necessary regardless sysfs is disabled.
31301 +#include <linux/random.h>
31304 +unsigned long sysaufs_si_mask;
31305 +struct kset *sysaufs_kset;
31307 +#define AuSiAttr(_name) { \
31308 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31309 + .show = sysaufs_si_##_name, \
31312 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31313 +struct attribute *sysaufs_si_attrs[] = {
31314 + &sysaufs_si_attr_xi_path.attr,
31317 +ATTRIBUTE_GROUPS(sysaufs_si);
31319 +static const struct sysfs_ops au_sbi_ops = {
31320 + .show = sysaufs_si_show
31323 +static struct kobj_type au_sbi_ktype = {
31324 + .release = au_si_free,
31325 + .sysfs_ops = &au_sbi_ops,
31326 + .default_groups = sysaufs_si_groups
31329 +/* ---------------------------------------------------------------------- */
31331 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31335 + sbinfo->si_kobj.kset = sysaufs_kset;
31336 + /* cf. sysaufs_name() */
31337 + err = kobject_init_and_add
31338 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31339 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31344 +void sysaufs_fin(void)
31346 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31347 + kset_unregister(sysaufs_kset);
31350 +int __init sysaufs_init(void)
31355 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31356 + } while (!sysaufs_si_mask);
31359 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31360 + if (unlikely(!sysaufs_kset))
31362 + err = PTR_ERR(sysaufs_kset);
31363 + if (IS_ERR(sysaufs_kset))
31365 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31366 + if (unlikely(err))
31367 + kset_unregister(sysaufs_kset);
31372 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31373 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31374 +++ linux/fs/aufs/sysaufs.h 2022-11-05 23:02:18.969222617 +0100
31376 +/* SPDX-License-Identifier: GPL-2.0 */
31378 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31380 + * This program is free software; you can redistribute it and/or modify
31381 + * it under the terms of the GNU General Public License as published by
31382 + * the Free Software Foundation; either version 2 of the License, or
31383 + * (at your option) any later version.
31385 + * This program is distributed in the hope that it will be useful,
31386 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31387 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31388 + * GNU General Public License for more details.
31390 + * You should have received a copy of the GNU General Public License
31391 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31395 + * sysfs interface and mount lifetime management
31398 +#ifndef __SYSAUFS_H__
31399 +#define __SYSAUFS_H__
31403 +#include <linux/sysfs.h>
31404 +#include "module.h"
31406 +struct super_block;
31409 +struct sysaufs_si_attr {
31410 + struct attribute attr;
31411 + int (*show)(struct seq_file *seq, struct super_block *sb);
31414 +/* ---------------------------------------------------------------------- */
31417 +extern unsigned long sysaufs_si_mask;
31418 +extern struct kset *sysaufs_kset;
31419 +extern struct attribute *sysaufs_si_attrs[];
31420 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31421 +int __init sysaufs_init(void);
31422 +void sysaufs_fin(void);
31424 +/* ---------------------------------------------------------------------- */
31426 +/* some people doesn't like to show a pointer in kernel */
31427 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31429 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31432 +#define SysaufsSiNamePrefix "si_"
31433 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31434 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31436 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31437 + sysaufs_si_id(sbinfo));
31441 +#ifdef CONFIG_SYSFS
31443 +extern struct attribute_group *sysaufs_attr_group;
31445 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31446 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31448 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31449 +#ifdef CONFIG_COMPAT
31450 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31453 +void sysaufs_br_init(struct au_branch *br);
31454 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31455 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31457 +#define sysaufs_brs_init() do {} while (0)
31460 +#define sysaufs_attr_group NULL
31462 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31463 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31464 + struct attribute *attr, char *buf)
31465 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31466 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31467 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31469 +static inline void sysaufs_brs_init(void)
31474 +#endif /* CONFIG_SYSFS */
31476 +#endif /* __KERNEL__ */
31477 +#endif /* __SYSAUFS_H__ */
31478 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31479 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31480 +++ linux/fs/aufs/sysfs.c 2022-11-05 23:02:18.969222617 +0100
31482 +// SPDX-License-Identifier: GPL-2.0
31484 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31486 + * This program is free software; you can redistribute it and/or modify
31487 + * it under the terms of the GNU General Public License as published by
31488 + * the Free Software Foundation; either version 2 of the License, or
31489 + * (at your option) any later version.
31491 + * This program is distributed in the hope that it will be useful,
31492 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31493 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31494 + * GNU General Public License for more details.
31496 + * You should have received a copy of the GNU General Public License
31497 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31501 + * sysfs interface
31504 +#include <linux/compat.h>
31505 +#include <linux/seq_file.h>
31508 +#ifdef CONFIG_AUFS_FS_MODULE
31509 +/* this entry violates the "one line per file" policy of sysfs */
31510 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31514 + static char *conf =
31515 +/* this file is generated at compiling */
31516 +#include "conf.str"
31519 + err = snprintf(buf, PAGE_SIZE, conf);
31520 + if (unlikely(err >= PAGE_SIZE))
31525 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31528 +static struct attribute *au_attr[] = {
31529 +#ifdef CONFIG_AUFS_FS_MODULE
31530 + &au_config_attr.attr,
31532 + NULL, /* need to NULL terminate the list of attributes */
31535 +static struct attribute_group sysaufs_attr_group_body = {
31539 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31541 +/* ---------------------------------------------------------------------- */
31543 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31547 + SiMustAnyLock(sb);
31550 + if (au_opt_test(au_mntflags(sb), XINO)) {
31551 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31552 + seq_putc(seq, '\n');
31558 + * the lifetime of branch is independent from the entry under sysfs.
31559 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31562 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31563 + aufs_bindex_t bindex, int idx)
31566 + struct path path;
31567 + struct dentry *root;
31568 + struct au_branch *br;
31569 + au_br_perm_str_t perm;
31571 + AuDbg("b%d\n", bindex);
31574 + root = sb->s_root;
31575 + di_read_lock_parent(root, !AuLock_IR);
31576 + br = au_sbr(sb, bindex);
31579 + case AuBrSysfs_BR:
31580 + path.mnt = au_br_mnt(br);
31581 + path.dentry = au_h_dptr(root, bindex);
31582 + err = au_seq_path(seq, &path);
31584 + au_optstr_br_perm(&perm, br->br_perm);
31585 + seq_printf(seq, "=%s\n", perm.a);
31588 + case AuBrSysfs_BRID:
31589 + seq_printf(seq, "%d\n", br->br_id);
31592 + di_read_unlock(root, !AuLock_IR);
31593 + if (unlikely(err || seq_has_overflowed(seq)))
31599 +/* ---------------------------------------------------------------------- */
31601 +static struct seq_file *au_seq(char *p, ssize_t len)
31603 + struct seq_file *seq;
31605 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31607 + /* mutex_init(&seq.lock); */
31610 + return seq; /* success */
31613 + seq = ERR_PTR(-ENOMEM);
31617 +#define SysaufsBr_PREFIX "br"
31618 +#define SysaufsBrid_PREFIX "brid"
31620 +/* todo: file size may exceed PAGE_SIZE */
31621 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31627 + aufs_bindex_t bbot;
31628 + struct au_sbinfo *sbinfo;
31629 + struct super_block *sb;
31630 + struct seq_file *seq;
31632 + struct attribute **cattr;
31634 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31635 + sb = sbinfo->si_sb;
31638 + * prevent a race condition between sysfs and aufs.
31639 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31640 + * prohibits maintaining the sysfs entries.
31641 + * hew we acquire read lock after sysfs_get_active_two().
31642 + * on the other hand, the remount process may maintain the sysfs/aufs
31643 + * entries after acquiring write lock.
31644 + * it can cause a deadlock.
31645 + * simply we gave up processing read here.
31648 + if (unlikely(!si_noflush_read_trylock(sb)))
31651 + seq = au_seq(buf, PAGE_SIZE);
31652 + err = PTR_ERR(seq);
31656 + name = (void *)attr->name;
31657 + cattr = sysaufs_si_attrs;
31659 + if (!strcmp(name, (*cattr)->name)) {
31660 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31667 + if (!strncmp(name, SysaufsBrid_PREFIX,
31668 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31669 + idx = AuBrSysfs_BRID;
31670 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31671 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31672 + sizeof(SysaufsBr_PREFIX) - 1)) {
31673 + idx = AuBrSysfs_BR;
31674 + name += sizeof(SysaufsBr_PREFIX) - 1;
31678 + err = kstrtol(name, 10, &l);
31680 + bbot = au_sbbot(sb);
31682 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31689 + err = seq->count;
31690 + /* sysfs limit */
31691 + if (unlikely(err == PAGE_SIZE))
31694 + au_kfree_rcu(seq);
31696 + si_read_unlock(sb);
31701 +/* ---------------------------------------------------------------------- */
31703 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31707 + aufs_bindex_t bindex, bbot;
31710 + struct seq_file *seq;
31711 + struct au_branch *br;
31713 + si_read_lock(sb, AuLock_FLUSH);
31714 + bbot = au_sbbot(sb);
31720 + buf = (void *)__get_free_page(GFP_NOFS);
31721 + if (unlikely(!buf))
31724 + seq = au_seq(buf, PAGE_SIZE);
31725 + err = PTR_ERR(seq);
31729 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31730 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31731 + /* VERIFY_WRITE */
31732 + err = !access_ok(arg, sizeof(*arg));
31733 + if (unlikely(err))
31736 + br = au_sbr(sb, bindex);
31737 + brid = br->br_id;
31738 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31739 + err = __put_user(brid, &arg->id);
31740 + if (unlikely(err))
31743 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31744 + err = __put_user(br->br_perm, &arg->perm);
31745 + if (unlikely(err))
31748 + err = au_seq_path(seq, &br->br_path);
31749 + if (unlikely(err))
31751 + seq_putc(seq, '\0');
31752 + if (!seq_has_overflowed(seq)) {
31753 + err = copy_to_user(arg->path, seq->buf, seq->count);
31755 + if (unlikely(err))
31762 + if (unlikely(err))
31766 + au_kfree_rcu(seq);
31768 + free_page((unsigned long)buf);
31770 + si_read_unlock(sb);
31774 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31776 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31779 +#ifdef CONFIG_COMPAT
31780 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31782 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31786 +/* ---------------------------------------------------------------------- */
31788 +void sysaufs_br_init(struct au_branch *br)
31791 + struct au_brsysfs *br_sysfs;
31792 + struct attribute *attr;
31794 + br_sysfs = br->br_sysfs;
31795 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31796 + attr = &br_sysfs->attr;
31797 + sysfs_attr_init(attr);
31798 + attr->name = br_sysfs->name;
31799 + attr->mode = 0444;
31804 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31806 + struct au_branch *br;
31807 + struct kobject *kobj;
31808 + struct au_brsysfs *br_sysfs;
31810 + aufs_bindex_t bbot;
31812 + if (!sysaufs_brs)
31815 + kobj = &au_sbi(sb)->si_kobj;
31816 + bbot = au_sbbot(sb);
31817 + for (; bindex <= bbot; bindex++) {
31818 + br = au_sbr(sb, bindex);
31819 + br_sysfs = br->br_sysfs;
31820 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31821 + sysfs_remove_file(kobj, &br_sysfs->attr);
31827 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31830 + aufs_bindex_t bbot;
31831 + struct kobject *kobj;
31832 + struct au_branch *br;
31833 + struct au_brsysfs *br_sysfs;
31835 + if (!sysaufs_brs)
31838 + kobj = &au_sbi(sb)->si_kobj;
31839 + bbot = au_sbbot(sb);
31840 + for (; bindex <= bbot; bindex++) {
31841 + br = au_sbr(sb, bindex);
31842 + br_sysfs = br->br_sysfs;
31843 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31844 + SysaufsBr_PREFIX "%d", bindex);
31845 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31846 + SysaufsBrid_PREFIX "%d", bindex);
31847 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31848 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31849 + if (unlikely(err))
31850 + pr_warn("failed %s under sysfs(%d)\n",
31851 + br_sysfs->name, err);
31856 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31857 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31858 +++ linux/fs/aufs/sysrq.c 2022-11-05 23:02:18.969222617 +0100
31860 +// SPDX-License-Identifier: GPL-2.0
31862 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31864 + * This program is free software; you can redistribute it and/or modify
31865 + * it under the terms of the GNU General Public License as published by
31866 + * the Free Software Foundation; either version 2 of the License, or
31867 + * (at your option) any later version.
31869 + * This program is distributed in the hope that it will be useful,
31870 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31871 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31872 + * GNU General Public License for more details.
31874 + * You should have received a copy of the GNU General Public License
31875 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31879 + * magic sysrq handler
31882 +/* #include <linux/sysrq.h> */
31883 +#include <linux/writeback.h>
31886 +/* ---------------------------------------------------------------------- */
31888 +static void sysrq_sb(struct super_block *sb)
31891 + struct au_sbinfo *sbinfo;
31892 + struct file *file;
31893 + struct hlist_bl_head *files;
31894 + struct hlist_bl_node *pos;
31895 + struct au_finfo *finfo;
31898 + plevel = au_plevel;
31899 + au_plevel = KERN_WARNING;
31901 + /* since we define pr_fmt, call printk directly */
31902 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31904 + sbinfo = au_sbi(sb);
31905 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31906 + pr("superblock\n");
31909 +#if 0 /* reserved */
31911 + int err, i, j, ndentry;
31912 + struct au_dcsub_pages dpages;
31913 + struct au_dpage *dpage;
31915 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31916 + if (unlikely(err))
31918 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31920 + for (i = 0; i < dpages.ndpage; i++) {
31921 + dpage = dpages.dpages + i;
31922 + ndentry = dpage->ndentry;
31923 + for (j = 0; j < ndentry; j++)
31924 + au_dpri_dentry(dpage->dentries[j]);
31926 + au_dpages_free(&dpages);
31930 + pr("isolated inode\n");
31931 + spin_lock(&sb->s_inode_list_lock);
31932 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31933 + spin_lock(&i->i_lock);
31934 + if (hlist_empty(&i->i_dentry))
31935 + au_dpri_inode(i);
31936 + spin_unlock(&i->i_lock);
31938 + spin_unlock(&sb->s_inode_list_lock);
31941 + files = &au_sbi(sb)->si_files;
31942 + hlist_bl_lock(files);
31943 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31946 + file = finfo->fi_file;
31947 + mode = file_inode(file)->i_mode;
31948 + if (!special_file(mode))
31949 + au_dpri_file(file);
31951 + hlist_bl_unlock(files);
31955 + au_plevel = plevel;
31958 +/* ---------------------------------------------------------------------- */
31960 +/* module parameter */
31961 +static char *aufs_sysrq_key = "a";
31962 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31963 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31965 +static void au_sysrq(int key __maybe_unused)
31967 + struct au_sbinfo *sbinfo;
31968 + struct hlist_bl_node *pos;
31971 + au_sbilist_lock();
31972 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31973 + sysrq_sb(sbinfo->si_sb);
31974 + au_sbilist_unlock();
31978 +static struct sysrq_key_op au_sysrq_op = {
31979 + .handler = au_sysrq,
31980 + .help_msg = "Aufs",
31981 + .action_msg = "Aufs",
31982 + .enable_mask = SYSRQ_ENABLE_DUMP
31985 +/* ---------------------------------------------------------------------- */
31987 +int __init au_sysrq_init(void)
31993 + key = *aufs_sysrq_key;
31994 + if ('a' <= key && key <= 'z')
31995 + err = register_sysrq_key(key, &au_sysrq_op);
31996 + if (unlikely(err))
31997 + pr_err("err %d, sysrq=%c\n", err, key);
32001 +void au_sysrq_fin(void)
32005 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
32006 + if (unlikely(err))
32007 + pr_err("err %d (ignored)\n", err);
32009 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
32010 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
32011 +++ linux/fs/aufs/vdir.c 2022-11-05 23:02:18.969222617 +0100
32013 +// SPDX-License-Identifier: GPL-2.0
32015 + * Copyright (C) 2005-2022 Junjiro R. Okajima
32017 + * This program is free software; you can redistribute it and/or modify
32018 + * it under the terms of the GNU General Public License as published by
32019 + * the Free Software Foundation; either version 2 of the License, or
32020 + * (at your option) any later version.
32022 + * This program is distributed in the hope that it will be useful,
32023 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32024 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32025 + * GNU General Public License for more details.
32027 + * You should have received a copy of the GNU General Public License
32028 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32032 + * virtual or vertical directory
32035 +#include <linux/iversion.h>
32038 +static unsigned int calc_size(int nlen)
32040 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
32043 +static int set_deblk_end(union au_vdir_deblk_p *p,
32044 + union au_vdir_deblk_p *deblk_end)
32046 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
32047 + p->de->de_str.len = 0;
32051 + return -1; /* error */
32054 +/* returns true or false */
32055 +static int is_deblk_end(union au_vdir_deblk_p *p,
32056 + union au_vdir_deblk_p *deblk_end)
32058 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
32059 + return !p->de->de_str.len;
32063 +static unsigned char *last_deblk(struct au_vdir *vdir)
32065 + return vdir->vd_deblk[vdir->vd_nblk - 1];
32068 +/* ---------------------------------------------------------------------- */
32070 +/* estimate the appropriate size for name hash table */
32071 +unsigned int au_rdhash_est(loff_t sz)
32079 + if (sz < AUFS_RDHASH_DEF)
32080 + n = AUFS_RDHASH_DEF;
32081 + /* pr_info("n %u\n", n); */
32086 + * the allocated memory has to be freed by
32087 + * au_nhash_wh_free() or au_nhash_de_free().
32089 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
32091 + struct hlist_head *head;
32095 + sz = sizeof(*nhash->nh_head) * num_hash;
32096 + head = kmalloc(sz, gfp);
32098 + nhash->nh_num = num_hash;
32099 + nhash->nh_head = head;
32100 + for (u = 0; u < num_hash; u++)
32101 + INIT_HLIST_HEAD(head++);
32102 + return 0; /* success */
32108 +static void nhash_count(struct hlist_head *head)
32110 +#if 0 /* debugging */
32112 + struct hlist_node *pos;
32115 + hlist_for_each(pos, head)
32117 + pr_info("%lu\n", n);
32121 +static void au_nhash_wh_do_free(struct hlist_head *head)
32123 + struct au_vdir_wh *pos;
32124 + struct hlist_node *node;
32126 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
32127 + au_kfree_rcu(pos);
32130 +static void au_nhash_de_do_free(struct hlist_head *head)
32132 + struct au_vdir_dehstr *pos;
32133 + struct hlist_node *node;
32135 + hlist_for_each_entry_safe(pos, node, head, hash)
32136 + au_cache_free_vdir_dehstr(pos);
32139 +static void au_nhash_do_free(struct au_nhash *nhash,
32140 + void (*free)(struct hlist_head *head))
32143 + struct hlist_head *head;
32145 + n = nhash->nh_num;
32149 + head = nhash->nh_head;
32150 + while (n-- > 0) {
32151 + nhash_count(head);
32154 + au_kfree_try_rcu(nhash->nh_head);
32157 +void au_nhash_wh_free(struct au_nhash *whlist)
32159 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
32162 +static void au_nhash_de_free(struct au_nhash *delist)
32164 + au_nhash_do_free(delist, au_nhash_de_do_free);
32167 +/* ---------------------------------------------------------------------- */
32169 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
32173 + unsigned int u, n;
32174 + struct hlist_head *head;
32175 + struct au_vdir_wh *pos;
32178 + n = whlist->nh_num;
32179 + head = whlist->nh_head;
32180 + for (u = 0; u < n; u++, head++)
32181 + hlist_for_each_entry(pos, head, wh_hash)
32182 + if (pos->wh_bindex == btgt && ++num > limit)
32187 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
32188 + unsigned char *name,
32189 + unsigned int len)
32192 + /* const unsigned int magic_bit = 12; */
32194 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32201 + /* v = hash_long(v, magic_bit); */
32202 + v %= nhash->nh_num;
32203 + return nhash->nh_head + v;
32206 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32209 + return str->len == nlen && !memcmp(str->name, name, nlen);
32212 +/* returns found or not */
32213 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32215 + struct hlist_head *head;
32216 + struct au_vdir_wh *pos;
32217 + struct au_vdir_destr *str;
32219 + head = au_name_hash(whlist, name, nlen);
32220 + hlist_for_each_entry(pos, head, wh_hash) {
32221 + str = &pos->wh_str;
32222 + AuDbg("%.*s\n", str->len, str->name);
32223 + if (au_nhash_test_name(str, name, nlen))
32229 +/* returns found(true) or not */
32230 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32232 + struct hlist_head *head;
32233 + struct au_vdir_dehstr *pos;
32234 + struct au_vdir_destr *str;
32236 + head = au_name_hash(delist, name, nlen);
32237 + hlist_for_each_entry(pos, head, hash) {
32239 + AuDbg("%.*s\n", str->len, str->name);
32240 + if (au_nhash_test_name(str, name, nlen))
32246 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32247 + unsigned char d_type)
32249 +#ifdef CONFIG_AUFS_SHWH
32250 + wh->wh_ino = ino;
32251 + wh->wh_type = d_type;
32255 +/* ---------------------------------------------------------------------- */
32257 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32258 + unsigned int d_type, aufs_bindex_t bindex,
32259 + unsigned char shwh)
32262 + struct au_vdir_destr *str;
32263 + struct au_vdir_wh *wh;
32265 + AuDbg("%.*s\n", nlen, name);
32266 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32269 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32270 + if (unlikely(!wh))
32274 + wh->wh_bindex = bindex;
32276 + au_shwh_init_wh(wh, ino, d_type);
32277 + str = &wh->wh_str;
32279 + memcpy(str->name, name, nlen);
32280 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32287 +static int append_deblk(struct au_vdir *vdir)
32290 + unsigned long ul;
32291 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32292 + union au_vdir_deblk_p p, deblk_end;
32293 + unsigned char **o;
32296 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32297 + GFP_NOFS, /*may_shrink*/0);
32298 + if (unlikely(!o))
32301 + vdir->vd_deblk = o;
32302 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32304 + ul = vdir->vd_nblk++;
32305 + vdir->vd_deblk[ul] = p.deblk;
32306 + vdir->vd_last.ul = ul;
32307 + vdir->vd_last.p.deblk = p.deblk;
32308 + deblk_end.deblk = p.deblk + deblk_sz;
32309 + err = set_deblk_end(&p, &deblk_end);
32316 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32317 + unsigned int d_type, struct au_nhash *delist)
32321 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32322 + union au_vdir_deblk_p p, *room, deblk_end;
32323 + struct au_vdir_dehstr *dehstr;
32325 + p.deblk = last_deblk(vdir);
32326 + deblk_end.deblk = p.deblk + deblk_sz;
32327 + room = &vdir->vd_last.p;
32328 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32329 + || !is_deblk_end(room, &deblk_end));
32331 + sz = calc_size(nlen);
32332 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32333 + err = append_deblk(vdir);
32334 + if (unlikely(err))
32337 + p.deblk = last_deblk(vdir);
32338 + deblk_end.deblk = p.deblk + deblk_sz;
32340 + AuDebugOn(room->deblk != p.deblk);
32344 + dehstr = au_cache_alloc_vdir_dehstr();
32345 + if (unlikely(!dehstr))
32348 + dehstr->str = &room->de->de_str;
32349 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32350 + room->de->de_ino = ino;
32351 + room->de->de_type = d_type;
32352 + room->de->de_str.len = nlen;
32353 + memcpy(room->de->de_str.name, name, nlen);
32356 + room->deblk += sz;
32357 + if (unlikely(set_deblk_end(room, &deblk_end)))
32358 + err = append_deblk(vdir);
32365 +/* ---------------------------------------------------------------------- */
32367 +void au_vdir_free(struct au_vdir *vdir)
32369 + unsigned char **deblk;
32371 + deblk = vdir->vd_deblk;
32372 + while (vdir->vd_nblk--)
32373 + au_kfree_try_rcu(*deblk++);
32374 + au_kfree_try_rcu(vdir->vd_deblk);
32375 + au_cache_free_vdir(vdir);
32378 +static struct au_vdir *alloc_vdir(struct file *file)
32380 + struct au_vdir *vdir;
32381 + struct super_block *sb;
32384 + sb = file->f_path.dentry->d_sb;
32385 + SiMustAnyLock(sb);
32388 + vdir = au_cache_alloc_vdir();
32389 + if (unlikely(!vdir))
32392 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32393 + if (unlikely(!vdir->vd_deblk))
32396 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32397 + if (!vdir->vd_deblk_sz) {
32398 + /* estimate the appropriate size for deblk */
32399 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32400 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32402 + vdir->vd_nblk = 0;
32403 + vdir->vd_version = 0;
32404 + vdir->vd_jiffy = 0;
32405 + err = append_deblk(vdir);
32407 + return vdir; /* success */
32409 + au_kfree_try_rcu(vdir->vd_deblk);
32412 + au_cache_free_vdir(vdir);
32414 + vdir = ERR_PTR(err);
32418 +static int reinit_vdir(struct au_vdir *vdir)
32421 + union au_vdir_deblk_p p, deblk_end;
32423 + while (vdir->vd_nblk > 1) {
32424 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32425 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32428 + p.deblk = vdir->vd_deblk[0];
32429 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32430 + err = set_deblk_end(&p, &deblk_end);
32431 + /* keep vd_dblk_sz */
32432 + vdir->vd_last.ul = 0;
32433 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32434 + vdir->vd_version = 0;
32435 + vdir->vd_jiffy = 0;
32440 +/* ---------------------------------------------------------------------- */
32442 +#define AuFillVdir_CALLED 1
32443 +#define AuFillVdir_WHABLE (1 << 1)
32444 +#define AuFillVdir_SHWH (1 << 2)
32445 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32446 +#define au_fset_fillvdir(flags, name) \
32447 + do { (flags) |= AuFillVdir_##name; } while (0)
32448 +#define au_fclr_fillvdir(flags, name) \
32449 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32451 +#ifndef CONFIG_AUFS_SHWH
32452 +#undef AuFillVdir_SHWH
32453 +#define AuFillVdir_SHWH 0
32456 +struct fillvdir_arg {
32457 + struct dir_context ctx;
32458 + struct file *file;
32459 + struct au_vdir *vdir;
32460 + struct au_nhash delist;
32461 + struct au_nhash whlist;
32462 + aufs_bindex_t bindex;
32463 + unsigned int flags;
32467 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32468 + loff_t offset __maybe_unused, u64 h_ino,
32469 + unsigned int d_type)
32471 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32472 + char *name = (void *)__name;
32473 + struct super_block *sb;
32475 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32478 + sb = arg->file->f_path.dentry->d_sb;
32479 + au_fset_fillvdir(arg->flags, CALLED);
32481 + if (nlen <= AUFS_WH_PFX_LEN
32482 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32483 + if (test_known(&arg->delist, name, nlen)
32484 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32485 + goto out; /* already exists or whiteouted */
32487 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32489 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32490 + d_type = DT_UNKNOWN;
32491 + arg->err = append_de(arg->vdir, name, nlen, ino,
32492 + d_type, &arg->delist);
32494 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32495 + name += AUFS_WH_PFX_LEN;
32496 + nlen -= AUFS_WH_PFX_LEN;
32497 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32498 + goto out; /* already whiteouted */
32500 + ino = 0; /* just to suppress a warning */
32502 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32505 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32506 + d_type = DT_UNKNOWN;
32507 + arg->err = au_nhash_append_wh
32508 + (&arg->whlist, name, nlen, ino, d_type,
32509 + arg->bindex, shwh);
32515 + arg->vdir->vd_jiffy = jiffies;
32517 + AuTraceErr(arg->err);
32521 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32522 + struct au_nhash *whlist, struct au_nhash *delist)
32524 +#ifdef CONFIG_AUFS_SHWH
32526 + unsigned int nh, u;
32527 + struct hlist_head *head;
32528 + struct au_vdir_wh *pos;
32529 + struct hlist_node *n;
32531 + struct au_vdir_destr *destr;
32533 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32536 + o = p = (void *)__get_free_page(GFP_NOFS);
32537 + if (unlikely(!p))
32541 + nh = whlist->nh_num;
32542 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32543 + p += AUFS_WH_PFX_LEN;
32544 + for (u = 0; u < nh; u++) {
32545 + head = whlist->nh_head + u;
32546 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32547 + destr = &pos->wh_str;
32548 + memcpy(p, destr->name, destr->len);
32549 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32550 + pos->wh_ino, pos->wh_type, delist);
32551 + if (unlikely(err))
32556 + free_page((unsigned long)o);
32566 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32569 + unsigned int rdhash;
32571 + aufs_bindex_t bbot, bindex, btop;
32572 + unsigned char shwh;
32573 + struct file *hf, *file;
32574 + struct super_block *sb;
32576 + file = arg->file;
32577 + sb = file->f_path.dentry->d_sb;
32578 + SiMustAnyLock(sb);
32580 + rdhash = au_sbi(sb)->si_rdhash;
32582 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32583 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32584 + if (unlikely(err))
32586 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32587 + if (unlikely(err))
32593 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32595 + au_fset_fillvdir(arg->flags, SHWH);
32597 + btop = au_fbtop(file);
32598 + bbot = au_fbbot_dir(file);
32599 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32600 + hf = au_hf_dir(file, bindex);
32604 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32606 + if (unlikely(offset))
32609 + arg->bindex = bindex;
32610 + au_fclr_fillvdir(arg->flags, WHABLE);
32612 + || (bindex != bbot
32613 + && au_br_whable(au_sbr_perm(sb, bindex))))
32614 + au_fset_fillvdir(arg->flags, WHABLE);
32617 + au_fclr_fillvdir(arg->flags, CALLED);
32619 + err = vfsub_iterate_dir(hf, &arg->ctx);
32622 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32625 + * dir_relax() may be good for concurrency, but aufs should not
32626 + * use it since it will cause a lockdep problem.
32630 + if (!err && shwh)
32631 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32633 + au_nhash_wh_free(&arg->whlist);
32636 + au_nhash_de_free(&arg->delist);
32641 +static int read_vdir(struct file *file, int may_read)
32644 + unsigned long expire;
32645 + unsigned char do_read;
32646 + struct fillvdir_arg arg = {
32648 + .actor = fillvdir
32651 + struct inode *inode;
32652 + struct au_vdir *vdir, *allocated;
32655 + inode = file_inode(file);
32656 + IMustLock(inode);
32657 + IiMustWriteLock(inode);
32658 + SiMustAnyLock(inode->i_sb);
32660 + allocated = NULL;
32662 + expire = au_sbi(inode->i_sb)->si_rdcache;
32663 + vdir = au_ivdir(inode);
32666 + vdir = alloc_vdir(file);
32667 + err = PTR_ERR(vdir);
32668 + if (IS_ERR(vdir))
32671 + allocated = vdir;
32672 + } else if (may_read
32673 + && (!inode_eq_iversion(inode, vdir->vd_version)
32674 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32676 + err = reinit_vdir(vdir);
32677 + if (unlikely(err))
32682 + return 0; /* success */
32686 + err = au_do_read_vdir(&arg);
32688 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32689 + vdir->vd_version = inode_query_iversion(inode);
32690 + vdir->vd_last.ul = 0;
32691 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32693 + au_set_ivdir(inode, allocated);
32694 + } else if (allocated)
32695 + au_vdir_free(allocated);
32701 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32704 + unsigned long ul, n;
32705 + const unsigned int deblk_sz = src->vd_deblk_sz;
32707 + AuDebugOn(tgt->vd_nblk != 1);
32710 + if (tgt->vd_nblk < src->vd_nblk) {
32711 + unsigned char **p;
32713 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32714 + GFP_NOFS, /*may_shrink*/0);
32715 + if (unlikely(!p))
32717 + tgt->vd_deblk = p;
32720 + if (tgt->vd_deblk_sz != deblk_sz) {
32721 + unsigned char *p;
32723 + tgt->vd_deblk_sz = deblk_sz;
32724 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32725 + /*may_shrink*/1);
32726 + if (unlikely(!p))
32728 + tgt->vd_deblk[0] = p;
32730 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32731 + tgt->vd_version = src->vd_version;
32732 + tgt->vd_jiffy = src->vd_jiffy;
32734 + n = src->vd_nblk;
32735 + for (ul = 1; ul < n; ul++) {
32736 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32738 + if (unlikely(!tgt->vd_deblk[ul]))
32742 + tgt->vd_nblk = n;
32743 + tgt->vd_last.ul = tgt->vd_last.ul;
32744 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32745 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32746 + - src->vd_deblk[src->vd_last.ul];
32748 + return 0; /* success */
32751 + rerr = reinit_vdir(tgt);
32756 +int au_vdir_init(struct file *file)
32759 + struct inode *inode;
32760 + struct au_vdir *vdir_cache, *allocated;
32762 + /* test file->f_pos here instead of ctx->pos */
32763 + err = read_vdir(file, !file->f_pos);
32764 + if (unlikely(err))
32767 + allocated = NULL;
32768 + vdir_cache = au_fvdir_cache(file);
32769 + if (!vdir_cache) {
32770 + vdir_cache = alloc_vdir(file);
32771 + err = PTR_ERR(vdir_cache);
32772 + if (IS_ERR(vdir_cache))
32774 + allocated = vdir_cache;
32775 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32776 + /* test file->f_pos here instead of ctx->pos */
32777 + err = reinit_vdir(vdir_cache);
32778 + if (unlikely(err))
32781 + return 0; /* success */
32783 + inode = file_inode(file);
32784 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32786 + file->f_version = inode_query_iversion(inode);
32788 + au_set_fvdir_cache(file, allocated);
32789 + } else if (allocated)
32790 + au_vdir_free(allocated);
32796 +static loff_t calc_offset(struct au_vdir *vdir)
32799 + union au_vdir_deblk_p p;
32801 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32802 + offset = vdir->vd_last.p.deblk - p.deblk;
32803 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32807 +/* returns true or false */
32808 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32811 + unsigned int deblk_sz;
32812 + unsigned long ul, n;
32814 + union au_vdir_deblk_p p, deblk_end;
32815 + struct au_vdir *vdir_cache;
32818 + vdir_cache = au_fvdir_cache(file);
32819 + offset = calc_offset(vdir_cache);
32820 + AuDbg("offset %lld\n", offset);
32821 + if (ctx->pos == offset)
32824 + vdir_cache->vd_last.ul = 0;
32825 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32830 + deblk_sz = vdir_cache->vd_deblk_sz;
32831 + ul = div64_u64(ctx->pos, deblk_sz);
32832 + AuDbg("ul %lu\n", ul);
32833 + if (ul >= vdir_cache->vd_nblk)
32836 + n = vdir_cache->vd_nblk;
32837 + for (; ul < n; ul++) {
32838 + p.deblk = vdir_cache->vd_deblk[ul];
32839 + deblk_end.deblk = p.deblk + deblk_sz;
32841 + offset *= deblk_sz;
32842 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32845 + l = calc_size(p.de->de_str.len);
32849 + if (!is_deblk_end(&p, &deblk_end)) {
32851 + vdir_cache->vd_last.ul = ul;
32852 + vdir_cache->vd_last.p = p;
32860 + AuDbg("valid %d\n", !valid);
32864 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32866 + unsigned int l, deblk_sz;
32867 + union au_vdir_deblk_p deblk_end;
32868 + struct au_vdir *vdir_cache;
32869 + struct au_vdir_de *de;
32871 + if (!seek_vdir(file, ctx))
32874 + vdir_cache = au_fvdir_cache(file);
32875 + deblk_sz = vdir_cache->vd_deblk_sz;
32877 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32878 + deblk_end.deblk += deblk_sz;
32879 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32880 + de = vdir_cache->vd_last.p.de;
32881 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32882 + de->de_str.len, de->de_str.name, ctx->pos,
32883 + (unsigned long)de->de_ino, de->de_type);
32884 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32885 + de->de_str.len, de->de_ino,
32887 + /* todo: ignore the error caused by udba? */
32888 + /* return err; */
32892 + l = calc_size(de->de_str.len);
32893 + vdir_cache->vd_last.p.deblk += l;
32896 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32897 + vdir_cache->vd_last.ul++;
32898 + vdir_cache->vd_last.p.deblk
32899 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32900 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32909 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32910 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32911 +++ linux/fs/aufs/vfsub.c 2022-11-05 23:02:18.969222617 +0100
32913 +// SPDX-License-Identifier: GPL-2.0
32915 + * Copyright (C) 2005-2022 Junjiro R. Okajima
32917 + * This program is free software; you can redistribute it and/or modify
32918 + * it under the terms of the GNU General Public License as published by
32919 + * the Free Software Foundation; either version 2 of the License, or
32920 + * (at your option) any later version.
32922 + * This program is distributed in the hope that it will be useful,
32923 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32924 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32925 + * GNU General Public License for more details.
32927 + * You should have received a copy of the GNU General Public License
32928 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32932 + * sub-routines for VFS
32935 +#include <linux/mnt_namespace.h>
32936 +#include <linux/nsproxy.h>
32937 +#include <linux/security.h>
32938 +#include <linux/splice.h>
32941 +#ifdef CONFIG_AUFS_BR_FUSE
32942 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32944 + if (!au_test_fuse(h_sb) || !au_userns)
32947 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32951 +int vfsub_sync_filesystem(struct super_block *h_sb)
32956 + down_read(&h_sb->s_umount);
32957 + err = sync_filesystem(h_sb);
32958 + up_read(&h_sb->s_umount);
32964 +/* ---------------------------------------------------------------------- */
32966 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32970 + struct super_block *h_sb;
32973 + * Always needs h_path->mnt for LSM or FUSE branch.
32975 + AuDebugOn(!h_path->mnt);
32977 + /* for remote fs, leave work for its getattr or d_revalidate */
32978 + /* for bad i_attr fs, handle them in aufs_getattr() */
32979 + /* still some fs may acquire i_mutex. we need to skip them */
32983 + h_sb = h_path->dentry->d_sb;
32984 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32986 + err = vfsub_getattr(h_path, &st);
32991 +/* ---------------------------------------------------------------------- */
32993 +struct file *vfsub_dentry_open(struct path *path, int flags)
32995 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32999 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
33001 + struct file *file;
33004 + file = filp_open(path,
33005 + oflags /* | __FMODE_NONOTIFY */,
33008 + if (IS_ERR(file))
33010 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33017 + * Ideally this function should call VFS:do_last() in order to keep all its
33018 + * checkings. But it is very hard for aufs to regenerate several VFS internal
33019 + * structure such as nameidata. This is a second (or third) best approach.
33020 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
33022 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33023 + struct vfsub_aopen_args *args)
33026 + struct au_branch *br = args->br;
33027 + struct file *file = args->file;
33028 + /* copied from linux/fs/namei.c:atomic_open() */
33029 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
33032 + AuDebugOn(!dir->i_op->atomic_open);
33034 + err = au_br_test_oflag(args->open_flag, br);
33035 + if (unlikely(err))
33038 + au_lcnt_inc(&br->br_nfiles);
33039 + file->f_path.dentry = DENTRY_NOT_SET;
33040 + file->f_path.mnt = au_br_mnt(br);
33041 + AuDbg("%ps\n", dir->i_op->atomic_open);
33042 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
33043 + args->create_mode);
33044 + if (unlikely(err < 0)) {
33045 + au_lcnt_dec(&br->br_nfiles);
33049 + /* temporary workaround for nfsv4 branch */
33050 + if (au_test_nfs(dir->i_sb))
33051 + nfs_mark_for_revalidate(dir);
33053 + if (file->f_mode & FMODE_CREATED)
33054 + fsnotify_create(dir, dentry);
33055 + if (!(file->f_mode & FMODE_OPENED)) {
33056 + au_lcnt_dec(&br->br_nfiles);
33060 + /* todo: call VFS:may_open() here */
33061 + /* todo: ima_file_check() too? */
33062 + if (!err && (args->open_flag & __FMODE_EXEC))
33063 + err = deny_write_access(file);
33065 + fsnotify_open(file);
33067 + au_lcnt_dec(&br->br_nfiles);
33068 + /* note that the file is created and still opened */
33074 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
33078 + err = kern_path(name, flags, path);
33079 + if (!err && d_is_positive(path->dentry))
33080 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33084 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33085 + struct path *ppath, int len)
33087 + struct path path;
33089 + path.dentry = lookup_one_len_unlocked(name, ppath->dentry, len);
33090 + if (IS_ERR(path.dentry))
33092 + if (d_is_positive(path.dentry)) {
33093 + path.mnt = ppath->mnt;
33094 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33098 + AuTraceErrPtr(path.dentry);
33099 + return path.dentry;
33102 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33105 + struct path path;
33107 + /* VFS checks it too, but by WARN_ON_ONCE() */
33108 + IMustLock(d_inode(ppath->dentry));
33110 + path.dentry = lookup_one_len(name, ppath->dentry, len);
33111 + if (IS_ERR(path.dentry))
33113 + if (d_is_positive(path.dentry)) {
33114 + path.mnt = ppath->mnt;
33115 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33119 + AuTraceErrPtr(path.dentry);
33120 + return path.dentry;
33123 +void vfsub_call_lkup_one(void *args)
33125 + struct vfsub_lkup_one_args *a = args;
33126 + *a->errp = vfsub_lkup_one(a->name, a->ppath);
33129 +/* ---------------------------------------------------------------------- */
33131 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33132 + struct dentry *d2, struct au_hinode *hdir2)
33134 + struct dentry *d;
33137 + d = lock_rename(d1, d2);
33139 + au_hn_suspend(hdir1);
33140 + if (hdir1 != hdir2)
33141 + au_hn_suspend(hdir2);
33146 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33147 + struct dentry *d2, struct au_hinode *hdir2)
33149 + au_hn_resume(hdir1);
33150 + if (hdir1 != hdir2)
33151 + au_hn_resume(hdir2);
33153 + unlock_rename(d1, d2);
33157 +/* ---------------------------------------------------------------------- */
33159 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
33162 + struct dentry *d;
33163 + struct user_namespace *userns;
33167 + d = path->dentry;
33168 + path->dentry = d->d_parent;
33169 + err = security_path_mknod(path, d, mode, 0);
33170 + path->dentry = d;
33171 + if (unlikely(err))
33173 + userns = mnt_user_ns(path->mnt);
33176 + err = vfs_create(userns, dir, path->dentry, mode, want_excl);
33179 + struct path tmp = *path;
33182 + vfsub_update_h_iattr(&tmp, &did);
33184 + tmp.dentry = path->dentry->d_parent;
33185 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33194 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33197 + struct dentry *d;
33198 + struct user_namespace *userns;
33202 + d = path->dentry;
33203 + path->dentry = d->d_parent;
33204 + err = security_path_symlink(path, d, symname);
33205 + path->dentry = d;
33206 + if (unlikely(err))
33208 + userns = mnt_user_ns(path->mnt);
33211 + err = vfs_symlink(userns, dir, path->dentry, symname);
33214 + struct path tmp = *path;
33217 + vfsub_update_h_iattr(&tmp, &did);
33219 + tmp.dentry = path->dentry->d_parent;
33220 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33229 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33232 + struct dentry *d;
33233 + struct user_namespace *userns;
33237 + d = path->dentry;
33238 + path->dentry = d->d_parent;
33239 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33240 + path->dentry = d;
33241 + if (unlikely(err))
33243 + userns = mnt_user_ns(path->mnt);
33246 + err = vfs_mknod(userns, dir, path->dentry, mode, dev);
33249 + struct path tmp = *path;
33252 + vfsub_update_h_iattr(&tmp, &did);
33254 + tmp.dentry = path->dentry->d_parent;
33255 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33264 +static int au_test_nlink(struct inode *inode)
33266 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33268 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33269 + || inode->i_nlink < link_max)
33274 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33275 + struct inode **delegated_inode)
33278 + struct dentry *d;
33279 + struct user_namespace *userns;
33283 + err = au_test_nlink(d_inode(src_dentry));
33284 + if (unlikely(err))
33287 + /* we don't call may_linkat() */
33288 + d = path->dentry;
33289 + path->dentry = d->d_parent;
33290 + err = security_path_link(src_dentry, path, d);
33291 + path->dentry = d;
33292 + if (unlikely(err))
33294 + userns = mnt_user_ns(path->mnt);
33297 + err = vfs_link(src_dentry, userns, dir, path->dentry, delegated_inode);
33300 + struct path tmp = *path;
33303 + /* fuse has different memory inode for the same inumber */
33304 + vfsub_update_h_iattr(&tmp, &did);
33306 + tmp.dentry = path->dentry->d_parent;
33307 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33308 + tmp.dentry = src_dentry;
33309 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33318 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33319 + struct inode *dir, struct path *path,
33320 + struct inode **delegated_inode, unsigned int flags)
33323 + struct renamedata rd;
33324 + struct path tmp = {
33327 + struct dentry *d;
33330 + IMustLock(src_dir);
33332 + d = path->dentry;
33333 + path->dentry = d->d_parent;
33334 + tmp.dentry = src_dentry->d_parent;
33335 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33336 + path->dentry = d;
33337 + if (unlikely(err))
33340 + rd.old_mnt_userns = mnt_user_ns(path->mnt);
33341 + rd.old_dir = src_dir;
33342 + rd.old_dentry = src_dentry;
33343 + rd.new_mnt_userns = rd.old_mnt_userns;
33344 + rd.new_dir = dir;
33345 + rd.new_dentry = path->dentry;
33346 + rd.delegated_inode = delegated_inode;
33347 + rd.flags = flags;
33349 + err = vfs_rename(&rd);
33354 + tmp.dentry = d->d_parent;
33355 + vfsub_update_h_iattr(&tmp, &did);
33357 + tmp.dentry = src_dentry;
33358 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33359 + tmp.dentry = src_dentry->d_parent;
33360 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33369 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33372 + struct dentry *d;
33373 + struct user_namespace *userns;
33377 + d = path->dentry;
33378 + path->dentry = d->d_parent;
33379 + err = security_path_mkdir(path, d, mode);
33380 + path->dentry = d;
33381 + if (unlikely(err))
33383 + userns = mnt_user_ns(path->mnt);
33386 + err = vfs_mkdir(userns, dir, path->dentry, mode);
33389 + struct path tmp = *path;
33392 + vfsub_update_h_iattr(&tmp, &did);
33394 + tmp.dentry = path->dentry->d_parent;
33395 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33404 +int vfsub_rmdir(struct inode *dir, struct path *path)
33407 + struct dentry *d;
33408 + struct user_namespace *userns;
33412 + d = path->dentry;
33413 + path->dentry = d->d_parent;
33414 + err = security_path_rmdir(path, d);
33415 + path->dentry = d;
33416 + if (unlikely(err))
33418 + userns = mnt_user_ns(path->mnt);
33421 + err = vfs_rmdir(userns, dir, path->dentry);
33424 + struct path tmp = {
33425 + .dentry = path->dentry->d_parent,
33429 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33436 +/* ---------------------------------------------------------------------- */
33438 +/* todo: support mmap_sem? */
33439 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33445 + err = vfs_read(file, ubuf, count, ppos);
33448 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33452 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33458 + err = kernel_read(file, kbuf, count, ppos);
33462 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33466 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33472 + err = vfs_write(file, ubuf, count, ppos);
33475 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33479 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33484 + err = kernel_write(file, kbuf, count, ppos);
33487 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33491 +int vfsub_flush(struct file *file, fl_owner_t id)
33496 + if (file->f_op->flush) {
33497 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33498 + err = file->f_op->flush(file, id);
33501 + err = file->f_op->flush(file, id);
33505 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33511 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33515 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33518 + err = iterate_dir(file, ctx);
33521 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33526 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33527 + struct pipe_inode_info *pipe, size_t len,
33528 + unsigned int flags)
33533 + err = do_splice_to(in, ppos, pipe, len, flags);
33535 + file_accessed(in);
33537 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33541 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33542 + loff_t *ppos, size_t len, unsigned int flags)
33547 + err = do_splice_from(pipe, out, ppos, len, flags);
33550 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33554 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33558 + /* file can be NULL */
33560 + err = vfs_fsync(file, datasync);
33564 + AuDebugOn(!file);
33565 + path = &file->f_path;
33567 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33572 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33573 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33574 + struct file *h_file)
33577 + struct inode *h_inode;
33578 + struct super_block *h_sb;
33579 + struct user_namespace *h_userns;
33582 + err = vfsub_truncate(h_path, length);
33586 + h_inode = d_inode(h_path->dentry);
33587 + h_sb = h_inode->i_sb;
33589 + sb_start_write(h_sb);
33591 + err = security_path_truncate(h_path);
33593 + h_userns = mnt_user_ns(h_path->mnt);
33595 + err = do_truncate(h_userns, h_path->dentry, length, attr,
33600 + sb_end_write(h_sb);
33607 +/* ---------------------------------------------------------------------- */
33609 +struct au_vfsub_mkdir_args {
33611 + struct inode *dir;
33612 + struct path *path;
33616 +static void au_call_vfsub_mkdir(void *args)
33618 + struct au_vfsub_mkdir_args *a = args;
33619 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33622 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33624 + int err, do_sio, wkq_err;
33625 + struct user_namespace *userns;
33627 + userns = mnt_user_ns(path->mnt);
33628 + do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
33631 + err = vfsub_mkdir(dir, path, mode);
33634 + struct au_vfsub_mkdir_args args = {
33640 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33641 + if (unlikely(wkq_err))
33648 +struct au_vfsub_rmdir_args {
33650 + struct inode *dir;
33651 + struct path *path;
33654 +static void au_call_vfsub_rmdir(void *args)
33656 + struct au_vfsub_rmdir_args *a = args;
33657 + *a->errp = vfsub_rmdir(a->dir, a->path);
33660 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33662 + int err, do_sio, wkq_err;
33663 + struct user_namespace *userns;
33665 + userns = mnt_user_ns(path->mnt);
33666 + do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
33669 + err = vfsub_rmdir(dir, path);
33672 + struct au_vfsub_rmdir_args args = {
33677 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33678 + if (unlikely(wkq_err))
33685 +/* ---------------------------------------------------------------------- */
33687 +struct notify_change_args {
33689 + struct path *path;
33690 + struct iattr *ia;
33691 + struct inode **delegated_inode;
33694 +static void call_notify_change(void *args)
33696 + struct notify_change_args *a = args;
33697 + struct inode *h_inode;
33698 + struct user_namespace *userns;
33700 + h_inode = d_inode(a->path->dentry);
33701 + IMustLock(h_inode);
33703 + *a->errp = -EPERM;
33704 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33705 + userns = mnt_user_ns(a->path->mnt);
33707 + *a->errp = notify_change(userns, a->path->dentry, a->ia,
33708 + a->delegated_inode);
33711 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33713 + AuTraceErr(*a->errp);
33716 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33717 + struct inode **delegated_inode)
33720 + struct notify_change_args args = {
33724 + .delegated_inode = delegated_inode
33727 + call_notify_change(&args);
33732 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33733 + struct inode **delegated_inode)
33735 + int err, wkq_err;
33736 + struct notify_change_args args = {
33740 + .delegated_inode = delegated_inode
33743 + wkq_err = au_wkq_wait(call_notify_change, &args);
33744 + if (unlikely(wkq_err))
33750 +/* ---------------------------------------------------------------------- */
33752 +struct unlink_args {
33754 + struct inode *dir;
33755 + struct path *path;
33756 + struct inode **delegated_inode;
33759 +static void call_unlink(void *args)
33761 + struct unlink_args *a = args;
33762 + struct dentry *d = a->path->dentry;
33763 + struct inode *h_inode;
33764 + struct user_namespace *userns;
33765 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33766 + && au_dcount(d) == 1);
33768 + IMustLock(a->dir);
33770 + a->path->dentry = d->d_parent;
33771 + *a->errp = security_path_unlink(a->path, d);
33772 + a->path->dentry = d;
33773 + if (unlikely(*a->errp))
33776 + if (!stop_sillyrename)
33779 + if (d_is_positive(d)) {
33780 + h_inode = d_inode(d);
33784 + userns = mnt_user_ns(a->path->mnt);
33786 + *a->errp = vfs_unlink(userns, a->dir, d, a->delegated_inode);
33789 + struct path tmp = {
33790 + .dentry = d->d_parent,
33791 + .mnt = a->path->mnt
33793 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33796 + if (!stop_sillyrename)
33801 + AuTraceErr(*a->errp);
33805 + * @dir: must be locked.
33806 + * @dentry: target dentry.
33808 +int vfsub_unlink(struct inode *dir, struct path *path,
33809 + struct inode **delegated_inode, int force)
33812 + struct unlink_args args = {
33816 + .delegated_inode = delegated_inode
33820 + call_unlink(&args);
33824 + wkq_err = au_wkq_wait(call_unlink, &args);
33825 + if (unlikely(wkq_err))
33831 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33832 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33833 +++ linux/fs/aufs/vfsub.h 2022-11-05 23:02:18.969222617 +0100
33835 +/* SPDX-License-Identifier: GPL-2.0 */
33837 + * Copyright (C) 2005-2022 Junjiro R. Okajima
33839 + * This program is free software; you can redistribute it and/or modify
33840 + * it under the terms of the GNU General Public License as published by
33841 + * the Free Software Foundation; either version 2 of the License, or
33842 + * (at your option) any later version.
33844 + * This program is distributed in the hope that it will be useful,
33845 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33846 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33847 + * GNU General Public License for more details.
33849 + * You should have received a copy of the GNU General Public License
33850 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33854 + * sub-routines for VFS
33857 +#ifndef __AUFS_VFSUB_H__
33858 +#define __AUFS_VFSUB_H__
33862 +#include <linux/fs.h>
33863 +#include <linux/mount.h>
33864 +#include <linux/posix_acl.h>
33865 +#include <linux/xattr.h>
33866 +#include "debug.h"
33868 +/* copied from linux/fs/internal.h */
33869 +/* todo: BAD approach!! */
33870 +extern void __mnt_drop_write(struct vfsmount *);
33871 +extern struct file *alloc_empty_file(int, const struct cred *);
33873 +/* ---------------------------------------------------------------------- */
33875 +/* lock subclass for lower inode */
33876 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33877 +/* reduce? gave up. */
33879 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33880 + AuLsc_I_PARENT, /* lower inode, parent first */
33881 + AuLsc_I_PARENT2, /* copyup dirs */
33882 + AuLsc_I_PARENT3, /* copyup wh */
33888 +/* to debug easier, do not make them inlined functions */
33889 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33890 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33892 +/* ---------------------------------------------------------------------- */
33894 +static inline void vfsub_drop_nlink(struct inode *inode)
33896 + AuDebugOn(!inode->i_nlink);
33897 + drop_nlink(inode);
33900 +static inline void vfsub_dead_dir(struct inode *inode)
33902 + AuDebugOn(!S_ISDIR(inode->i_mode));
33903 + inode->i_flags |= S_DEAD;
33904 + clear_nlink(inode);
33907 +static inline int vfsub_native_ro(struct inode *inode)
33909 + return sb_rdonly(inode->i_sb)
33910 + || IS_RDONLY(inode)
33911 + /* || IS_APPEND(inode) */
33912 + || IS_IMMUTABLE(inode);
33915 +#ifdef CONFIG_AUFS_BR_FUSE
33916 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33918 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33921 +int vfsub_sync_filesystem(struct super_block *h_sb);
33923 +/* ---------------------------------------------------------------------- */
33925 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33926 +struct file *vfsub_dentry_open(struct path *path, int flags);
33927 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33929 +struct vfsub_aopen_args {
33930 + struct file *file;
33931 + unsigned int open_flag;
33932 + umode_t create_mode;
33933 + struct au_branch *br;
33935 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33936 + struct vfsub_aopen_args *args);
33937 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33939 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33940 + struct path *ppath, int len);
33941 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33944 +struct vfsub_lkup_one_args {
33945 + struct dentry **errp;
33946 + struct qstr *name;
33947 + struct path *ppath;
33950 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33951 + struct path *ppath)
33953 + return vfsub_lookup_one_len(name->name, ppath, name->len);
33956 +void vfsub_call_lkup_one(void *args);
33958 +/* ---------------------------------------------------------------------- */
33960 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33965 + err = mnt_want_write(mnt);
33970 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33973 + mnt_drop_write(mnt);
33977 +#if 0 /* reserved */
33978 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33981 + mnt_drop_write_file(file);
33986 +/* ---------------------------------------------------------------------- */
33989 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33990 + struct dentry *d2, struct au_hinode *hdir2);
33991 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33992 + struct dentry *d2, struct au_hinode *hdir2);
33994 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33996 +int vfsub_symlink(struct inode *dir, struct path *path,
33997 + const char *symname);
33998 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33999 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
34000 + struct path *path, struct inode **delegated_inode);
34001 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
34002 + struct inode *hdir, struct path *path,
34003 + struct inode **delegated_inode, unsigned int flags);
34004 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
34005 +int vfsub_rmdir(struct inode *dir, struct path *path);
34007 +/* ---------------------------------------------------------------------- */
34009 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
34011 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
34013 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
34015 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
34017 +int vfsub_flush(struct file *file, fl_owner_t id);
34018 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
34020 +static inline loff_t vfsub_f_size_read(struct file *file)
34022 + return i_size_read(file_inode(file));
34025 +static inline unsigned int vfsub_file_flags(struct file *file)
34027 + unsigned int flags;
34029 + spin_lock(&file->f_lock);
34030 + flags = file->f_flags;
34031 + spin_unlock(&file->f_lock);
34036 +static inline int vfsub_file_execed(struct file *file)
34038 + /* todo: direct access f_flags */
34039 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
34042 +#if 0 /* reserved */
34043 +static inline void vfsub_file_accessed(struct file *h_file)
34045 + file_accessed(h_file);
34046 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
34050 +#if 0 /* reserved */
34051 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
34052 + struct dentry *h_dentry)
34054 + struct path h_path = {
34055 + .dentry = h_dentry,
34058 + touch_atime(&h_path);
34059 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
34063 +static inline int vfsub_update_time(struct inode *h_inode,
34064 + struct timespec64 *ts, int flags)
34066 + return inode_update_time(h_inode, ts, flags);
34067 + /* no vfsub_update_h_iattr() since we don't have struct path */
34070 +#ifdef CONFIG_FS_POSIX_ACL
34071 +static inline int vfsub_acl_chmod(struct user_namespace *h_userns,
34072 + struct inode *h_inode, umode_t h_mode)
34076 + err = posix_acl_chmod(h_userns, h_inode, h_mode);
34077 + if (err == -EOPNOTSUPP)
34082 +AuStubInt0(vfsub_acl_chmod, struct user_namespace *h_userns,
34083 + struct inode *h_inode, umode_t h_mode);
34086 +long vfsub_splice_to(struct file *in, loff_t *ppos,
34087 + struct pipe_inode_info *pipe, size_t len,
34088 + unsigned int flags);
34089 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
34090 + loff_t *ppos, size_t len, unsigned int flags);
34092 +static inline long vfsub_truncate(struct path *path, loff_t length)
34097 + err = vfs_truncate(path, length);
34102 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
34103 + struct file *h_file);
34104 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
34107 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
34110 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
34116 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
34122 +/* copy_file_range(2) is a systemcall */
34123 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
34124 + struct file *dst, loff_t dst_pos,
34125 + size_t len, unsigned int flags)
34130 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
34136 +/* ---------------------------------------------------------------------- */
34138 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
34143 + err = vfs_llseek(file, offset, origin);
34148 +/* ---------------------------------------------------------------------- */
34150 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
34151 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
34152 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
34153 + struct inode **delegated_inode);
34154 +int vfsub_notify_change(struct path *path, struct iattr *ia,
34155 + struct inode **delegated_inode);
34156 +int vfsub_unlink(struct inode *dir, struct path *path,
34157 + struct inode **delegated_inode, int force);
34159 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
34161 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
34164 +/* ---------------------------------------------------------------------- */
34167 + * The parameter 'value' is not const since the id in ACL_USER/ACL_GROUP may be
34168 + * changed by idmapping.
34170 +static inline int vfsub_setxattr(struct user_namespace *userns,
34171 + struct dentry *dentry, const char *name,
34172 + void *value, size_t size, int flags)
34177 + err = vfs_setxattr(userns, dentry, name, value, size, flags);
34183 +static inline int vfsub_removexattr(struct user_namespace *userns,
34184 + struct dentry *dentry, const char *name)
34189 + err = vfs_removexattr(userns, dentry, name);
34195 +#endif /* __KERNEL__ */
34196 +#endif /* __AUFS_VFSUB_H__ */
34197 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
34198 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
34199 +++ linux/fs/aufs/wbr_policy.c 2022-11-05 23:02:18.969222617 +0100
34201 +// SPDX-License-Identifier: GPL-2.0
34203 + * Copyright (C) 2005-2022 Junjiro R. Okajima
34205 + * This program is free software; you can redistribute it and/or modify
34206 + * it under the terms of the GNU General Public License as published by
34207 + * the Free Software Foundation; either version 2 of the License, or
34208 + * (at your option) any later version.
34210 + * This program is distributed in the hope that it will be useful,
34211 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34212 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34213 + * GNU General Public License for more details.
34215 + * You should have received a copy of the GNU General Public License
34216 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34220 + * policies for selecting one among multiple writable branches
34223 +#include <linux/statfs.h>
34226 +/* subset of cpup_attr() */
34227 +static noinline_for_stack
34228 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34232 + struct inode *h_isrc;
34234 + h_isrc = d_inode(h_src);
34235 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34236 + ia.ia_mode = h_isrc->i_mode;
34237 + ia.ia_uid = h_isrc->i_uid;
34238 + ia.ia_gid = h_isrc->i_gid;
34239 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34240 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34241 + /* no delegation since it is just created */
34242 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34244 + /* is this nfs only? */
34245 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34246 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34247 + ia.ia_mode = h_isrc->i_mode;
34248 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34254 +#define AuCpdown_PARENT_OPQ 1
34255 +#define AuCpdown_WHED (1 << 1)
34256 +#define AuCpdown_MADE_DIR (1 << 2)
34257 +#define AuCpdown_DIROPQ (1 << 3)
34258 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34259 +#define au_fset_cpdown(flags, name) \
34260 + do { (flags) |= AuCpdown_##name; } while (0)
34261 +#define au_fclr_cpdown(flags, name) \
34262 + do { (flags) &= ~AuCpdown_##name; } while (0)
34264 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34265 + unsigned int *flags)
34268 + struct dentry *opq_dentry;
34270 + opq_dentry = au_diropq_create(dentry, bdst);
34271 + err = PTR_ERR(opq_dentry);
34272 + if (IS_ERR(opq_dentry))
34274 + dput(opq_dentry);
34275 + au_fset_cpdown(*flags, DIROPQ);
34281 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34282 + struct inode *dir, aufs_bindex_t bdst)
34285 + struct path h_path;
34286 + struct au_branch *br;
34288 + br = au_sbr(dentry->d_sb, bdst);
34289 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34290 + err = PTR_ERR(h_path.dentry);
34291 + if (IS_ERR(h_path.dentry))
34295 + if (d_is_positive(h_path.dentry)) {
34296 + h_path.mnt = au_br_mnt(br);
34297 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34300 + dput(h_path.dentry);
34306 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34307 + struct au_pin *pin,
34308 + struct dentry *h_parent, void *arg)
34311 + aufs_bindex_t bopq, btop;
34312 + struct path h_path;
34313 + struct dentry *parent;
34314 + struct inode *h_dir, *h_inode, *inode, *dir;
34315 + unsigned int *flags = arg;
34317 + btop = au_dbtop(dentry);
34318 + /* dentry is di-locked */
34319 + parent = dget_parent(dentry);
34320 + dir = d_inode(parent);
34321 + h_dir = d_inode(h_parent);
34322 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34323 + IMustLock(h_dir);
34325 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34326 + if (unlikely(err < 0))
34328 + h_path.dentry = au_h_dptr(dentry, bdst);
34329 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34330 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34331 + if (unlikely(err))
34333 + au_fset_cpdown(*flags, MADE_DIR);
34335 + bopq = au_dbdiropq(dentry);
34336 + au_fclr_cpdown(*flags, WHED);
34337 + au_fclr_cpdown(*flags, DIROPQ);
34338 + if (au_dbwh(dentry) == bdst)
34339 + au_fset_cpdown(*flags, WHED);
34340 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34341 + au_fset_cpdown(*flags, PARENT_OPQ);
34342 + h_inode = d_inode(h_path.dentry);
34343 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34344 + if (au_ftest_cpdown(*flags, WHED)) {
34345 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34346 + if (unlikely(err)) {
34347 + inode_unlock(h_inode);
34352 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34353 + inode_unlock(h_inode);
34354 + if (unlikely(err))
34357 + if (au_ftest_cpdown(*flags, WHED)) {
34358 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34359 + if (unlikely(err))
34363 + inode = d_inode(dentry);
34364 + if (au_ibbot(inode) < bdst)
34365 + au_set_ibbot(inode, bdst);
34366 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34367 + au_hi_flags(inode, /*isdir*/1));
34368 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34369 + goto out; /* success */
34373 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34374 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34375 + rerr = au_diropq_remove(dentry, bdst);
34376 + inode_unlock(h_inode);
34377 + if (unlikely(rerr)) {
34378 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34379 + dentry, bdst, rerr);
34385 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34386 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34387 + if (unlikely(rerr)) {
34388 + AuIOErr("failed removing %pd b%d (%d)\n",
34389 + dentry, bdst, rerr);
34394 + au_set_h_dptr(dentry, bdst, NULL);
34395 + if (au_dbbot(dentry) == bdst)
34396 + au_update_dbbot(dentry);
34402 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34405 + unsigned int flags;
34408 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34413 +/* ---------------------------------------------------------------------- */
34415 +/* policies for create */
34417 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34419 + int err, i, j, ndentry;
34420 + aufs_bindex_t bopq;
34421 + struct au_dcsub_pages dpages;
34422 + struct au_dpage *dpage;
34423 + struct dentry **dentries, *parent, *d;
34425 + err = au_dpages_init(&dpages, GFP_NOFS);
34426 + if (unlikely(err))
34428 + parent = dget_parent(dentry);
34429 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34430 + if (unlikely(err))
34434 + for (i = 0; i < dpages.ndpage; i++) {
34435 + dpage = dpages.dpages + i;
34436 + dentries = dpage->dentries;
34437 + ndentry = dpage->ndentry;
34438 + for (j = 0; j < ndentry; j++) {
34440 + di_read_lock_parent2(d, !AuLock_IR);
34441 + bopq = au_dbdiropq(d);
34442 + di_read_unlock(d, !AuLock_IR);
34443 + if (bopq >= 0 && bopq < err)
34450 + au_dpages_free(&dpages);
34455 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34457 + for (; bindex >= 0; bindex--)
34458 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34463 +/* top down parent */
34464 +static int au_wbr_create_tdp(struct dentry *dentry,
34465 + unsigned int flags __maybe_unused)
34468 + aufs_bindex_t btop, bindex;
34469 + struct super_block *sb;
34470 + struct dentry *parent, *h_parent;
34472 + sb = dentry->d_sb;
34473 + btop = au_dbtop(dentry);
34475 + if (!au_br_rdonly(au_sbr(sb, btop)))
34479 + parent = dget_parent(dentry);
34480 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34481 + h_parent = au_h_dptr(parent, bindex);
34482 + if (!h_parent || d_is_negative(h_parent))
34485 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34492 + /* bottom up here */
34493 + if (unlikely(err < 0)) {
34494 + err = au_wbr_bu(sb, btop - 1);
34496 + err = au_wbr_nonopq(dentry, err);
34500 + AuDbg("b%d\n", err);
34504 +/* ---------------------------------------------------------------------- */
34506 +/* an exception for the policy other than tdp */
34507 +static int au_wbr_create_exp(struct dentry *dentry)
34510 + aufs_bindex_t bwh, bdiropq;
34511 + struct dentry *parent;
34514 + bwh = au_dbwh(dentry);
34515 + parent = dget_parent(dentry);
34516 + bdiropq = au_dbdiropq(parent);
34518 + if (bdiropq >= 0)
34519 + err = min(bdiropq, bwh);
34522 + AuDbg("%d\n", err);
34523 + } else if (bdiropq >= 0) {
34525 + AuDbg("%d\n", err);
34530 + err = au_wbr_nonopq(dentry, err);
34532 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34535 + AuDbg("%d\n", err);
34539 +/* ---------------------------------------------------------------------- */
34542 +static int au_wbr_create_init_rr(struct super_block *sb)
34546 + err = au_wbr_bu(sb, au_sbbot(sb));
34547 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34550 + AuDbg("b%d\n", err);
34554 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34558 + aufs_bindex_t bindex, bbot;
34559 + struct super_block *sb;
34562 + err = au_wbr_create_exp(dentry);
34566 + sb = dentry->d_sb;
34567 + next = &au_sbi(sb)->si_wbr_rr_next;
34568 + bbot = au_sbbot(sb);
34570 + for (bindex = 0; bindex <= bbot; bindex++) {
34571 + if (!au_ftest_wbr(flags, DIR)) {
34572 + err = atomic_dec_return(next) + 1;
34573 + /* modulo for 0 is meaningless */
34574 + if (unlikely(!err))
34575 + err = atomic_dec_return(next) + 1;
34577 + err = atomic_read(next);
34578 + AuDbg("%d\n", err);
34581 + AuDbg("%d\n", err);
34582 + if (!au_br_rdonly(au_sbr(sb, err)))
34588 + err = au_wbr_nonopq(dentry, err);
34591 + AuDbg("%d\n", err);
34595 +/* ---------------------------------------------------------------------- */
34597 +/* most free space */
34598 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34600 + struct super_block *sb;
34601 + struct au_branch *br;
34602 + struct au_wbr_mfs *mfs;
34603 + struct dentry *h_parent;
34604 + aufs_bindex_t bindex, bbot;
34606 + unsigned long long b, bavail;
34607 + struct path h_path;
34608 + /* reduce the stack usage */
34609 + struct kstatfs *st;
34611 + st = kmalloc(sizeof(*st), GFP_NOFS);
34612 + if (unlikely(!st)) {
34613 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34618 + sb = dentry->d_sb;
34619 + mfs = &au_sbi(sb)->si_wbr_mfs;
34620 + MtxMustLock(&mfs->mfs_lock);
34621 + mfs->mfs_bindex = -EROFS;
34622 + mfs->mfsrr_bytes = 0;
34625 + bbot = au_sbbot(sb);
34627 + bindex = au_dbtop(parent);
34628 + bbot = au_dbtaildir(parent);
34631 + for (; bindex <= bbot; bindex++) {
34633 + h_parent = au_h_dptr(parent, bindex);
34634 + if (!h_parent || d_is_negative(h_parent))
34637 + br = au_sbr(sb, bindex);
34638 + if (au_br_rdonly(br))
34641 + /* sb->s_root for NFS is unreliable */
34642 + h_path.mnt = au_br_mnt(br);
34643 + h_path.dentry = h_path.mnt->mnt_root;
34644 + err = vfs_statfs(&h_path, st);
34645 + if (unlikely(err)) {
34646 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34650 + /* when the available size is equal, select the lower one */
34651 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34652 + || sizeof(b) < sizeof(st->f_bsize));
34653 + b = st->f_bavail * st->f_bsize;
34654 + br->br_wbr->wbr_bytes = b;
34655 + if (b >= bavail) {
34657 + mfs->mfs_bindex = bindex;
34658 + mfs->mfs_jiffy = jiffies;
34662 + mfs->mfsrr_bytes = bavail;
34663 + AuDbg("b%d\n", mfs->mfs_bindex);
34664 + au_kfree_rcu(st);
34667 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34670 + struct dentry *parent;
34671 + struct super_block *sb;
34672 + struct au_wbr_mfs *mfs;
34674 + err = au_wbr_create_exp(dentry);
34678 + sb = dentry->d_sb;
34680 + if (au_ftest_wbr(flags, PARENT))
34681 + parent = dget_parent(dentry);
34682 + mfs = &au_sbi(sb)->si_wbr_mfs;
34683 + mutex_lock(&mfs->mfs_lock);
34684 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34685 + || mfs->mfs_bindex < 0
34686 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34687 + au_mfs(dentry, parent);
34688 + mutex_unlock(&mfs->mfs_lock);
34689 + err = mfs->mfs_bindex;
34693 + err = au_wbr_nonopq(dentry, err);
34696 + AuDbg("b%d\n", err);
34700 +static int au_wbr_create_init_mfs(struct super_block *sb)
34702 + struct au_wbr_mfs *mfs;
34704 + mfs = &au_sbi(sb)->si_wbr_mfs;
34705 + mutex_init(&mfs->mfs_lock);
34706 + mfs->mfs_jiffy = 0;
34707 + mfs->mfs_bindex = -EROFS;
34712 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34714 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34718 +/* ---------------------------------------------------------------------- */
34720 +/* top down regardless parent, and then mfs */
34721 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34722 + unsigned int flags __maybe_unused)
34725 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34726 + unsigned long long watermark;
34727 + struct super_block *sb;
34728 + struct au_wbr_mfs *mfs;
34729 + struct au_branch *br;
34730 + struct dentry *parent;
34732 + sb = dentry->d_sb;
34733 + mfs = &au_sbi(sb)->si_wbr_mfs;
34734 + mutex_lock(&mfs->mfs_lock);
34735 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34736 + || mfs->mfs_bindex < 0)
34737 + au_mfs(dentry, /*parent*/NULL);
34738 + watermark = mfs->mfsrr_watermark;
34739 + bmfs = mfs->mfs_bindex;
34740 + mutex_unlock(&mfs->mfs_lock);
34742 + /* another style of au_wbr_create_exp() */
34743 + bwh = au_dbwh(dentry);
34744 + parent = dget_parent(dentry);
34745 + btail = au_dbtaildir(parent);
34746 + if (bwh >= 0 && bwh < btail)
34749 + err = au_wbr_nonopq(dentry, btail);
34750 + if (unlikely(err < 0))
34754 + for (bindex = 0; bindex <= btail; bindex++) {
34755 + br = au_sbr(sb, bindex);
34756 + if (au_br_rdonly(br))
34758 + if (br->br_wbr->wbr_bytes > watermark) {
34769 + AuDbg("b%d\n", err);
34773 +/* ---------------------------------------------------------------------- */
34775 +/* most free space and then round robin */
34776 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34779 + struct au_wbr_mfs *mfs;
34781 + err = au_wbr_create_mfs(dentry, flags);
34783 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34784 + mutex_lock(&mfs->mfs_lock);
34785 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34786 + err = au_wbr_create_rr(dentry, flags);
34787 + mutex_unlock(&mfs->mfs_lock);
34790 + AuDbg("b%d\n", err);
34794 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34798 + au_wbr_create_init_mfs(sb); /* ignore */
34799 + err = au_wbr_create_init_rr(sb);
34804 +/* ---------------------------------------------------------------------- */
34806 +/* top down parent and most free space */
34807 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34810 + unsigned long long b;
34811 + aufs_bindex_t bindex, btop, bbot;
34812 + struct super_block *sb;
34813 + struct dentry *parent, *h_parent;
34814 + struct au_branch *br;
34816 + err = au_wbr_create_tdp(dentry, flags);
34817 + if (unlikely(err < 0))
34819 + parent = dget_parent(dentry);
34820 + btop = au_dbtop(parent);
34821 + bbot = au_dbtaildir(parent);
34822 + if (btop == bbot)
34823 + goto out_parent; /* success */
34825 + e2 = au_wbr_create_mfs(dentry, flags);
34827 + goto out_parent; /* success */
34829 + /* when the available size is equal, select upper one */
34830 + sb = dentry->d_sb;
34831 + br = au_sbr(sb, err);
34832 + b = br->br_wbr->wbr_bytes;
34833 + AuDbg("b%d, %llu\n", err, b);
34835 + for (bindex = btop; bindex <= bbot; bindex++) {
34836 + h_parent = au_h_dptr(parent, bindex);
34837 + if (!h_parent || d_is_negative(h_parent))
34840 + br = au_sbr(sb, bindex);
34841 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34842 + b = br->br_wbr->wbr_bytes;
34844 + AuDbg("b%d, %llu\n", err, b);
34849 + err = au_wbr_nonopq(dentry, err);
34854 + AuDbg("b%d\n", err);
34858 +/* ---------------------------------------------------------------------- */
34861 + * - top down parent
34862 + * - most free space with parent
34863 + * - most free space round-robin regardless parent
34865 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34868 + unsigned long long watermark;
34869 + struct super_block *sb;
34870 + struct au_branch *br;
34871 + struct au_wbr_mfs *mfs;
34873 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34874 + if (unlikely(err < 0))
34877 + sb = dentry->d_sb;
34878 + br = au_sbr(sb, err);
34879 + mfs = &au_sbi(sb)->si_wbr_mfs;
34880 + mutex_lock(&mfs->mfs_lock);
34881 + watermark = mfs->mfsrr_watermark;
34882 + mutex_unlock(&mfs->mfs_lock);
34883 + if (br->br_wbr->wbr_bytes < watermark)
34884 + /* regardless the parent dir */
34885 + err = au_wbr_create_mfsrr(dentry, flags);
34888 + AuDbg("b%d\n", err);
34892 +/* ---------------------------------------------------------------------- */
34894 +/* policies for copyup */
34896 +/* top down parent */
34897 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34899 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34902 +/* bottom up parent */
34903 +static int au_wbr_copyup_bup(struct dentry *dentry)
34906 + aufs_bindex_t bindex, btop;
34907 + struct dentry *parent, *h_parent;
34908 + struct super_block *sb;
34911 + sb = dentry->d_sb;
34912 + parent = dget_parent(dentry);
34913 + btop = au_dbtop(parent);
34914 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34915 + h_parent = au_h_dptr(parent, bindex);
34916 + if (!h_parent || d_is_negative(h_parent))
34919 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34926 + /* bottom up here */
34927 + if (unlikely(err < 0))
34928 + err = au_wbr_bu(sb, btop - 1);
34930 + AuDbg("b%d\n", err);
34935 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34939 + err = au_wbr_bu(dentry->d_sb, btop);
34940 + AuDbg("b%d\n", err);
34942 + err = au_wbr_nonopq(dentry, err);
34944 + AuDbg("b%d\n", err);
34948 +static int au_wbr_copyup_bu(struct dentry *dentry)
34951 + aufs_bindex_t btop;
34953 + btop = au_dbtop(dentry);
34954 + err = au_wbr_do_copyup_bu(dentry, btop);
34958 +/* ---------------------------------------------------------------------- */
34960 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34961 + [AuWbrCopyup_TDP] = {
34962 + .copyup = au_wbr_copyup_tdp
34964 + [AuWbrCopyup_BUP] = {
34965 + .copyup = au_wbr_copyup_bup
34967 + [AuWbrCopyup_BU] = {
34968 + .copyup = au_wbr_copyup_bu
34972 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34973 + [AuWbrCreate_TDP] = {
34974 + .create = au_wbr_create_tdp
34976 + [AuWbrCreate_RR] = {
34977 + .create = au_wbr_create_rr,
34978 + .init = au_wbr_create_init_rr
34980 + [AuWbrCreate_MFS] = {
34981 + .create = au_wbr_create_mfs,
34982 + .init = au_wbr_create_init_mfs,
34983 + .fin = au_wbr_create_fin_mfs
34985 + [AuWbrCreate_MFSV] = {
34986 + .create = au_wbr_create_mfs,
34987 + .init = au_wbr_create_init_mfs,
34988 + .fin = au_wbr_create_fin_mfs
34990 + [AuWbrCreate_MFSRR] = {
34991 + .create = au_wbr_create_mfsrr,
34992 + .init = au_wbr_create_init_mfsrr,
34993 + .fin = au_wbr_create_fin_mfs
34995 + [AuWbrCreate_MFSRRV] = {
34996 + .create = au_wbr_create_mfsrr,
34997 + .init = au_wbr_create_init_mfsrr,
34998 + .fin = au_wbr_create_fin_mfs
35000 + [AuWbrCreate_TDMFS] = {
35001 + .create = au_wbr_create_tdmfs,
35002 + .init = au_wbr_create_init_mfs,
35003 + .fin = au_wbr_create_fin_mfs
35005 + [AuWbrCreate_TDMFSV] = {
35006 + .create = au_wbr_create_tdmfs,
35007 + .init = au_wbr_create_init_mfs,
35008 + .fin = au_wbr_create_fin_mfs
35010 + [AuWbrCreate_PMFS] = {
35011 + .create = au_wbr_create_pmfs,
35012 + .init = au_wbr_create_init_mfs,
35013 + .fin = au_wbr_create_fin_mfs
35015 + [AuWbrCreate_PMFSV] = {
35016 + .create = au_wbr_create_pmfs,
35017 + .init = au_wbr_create_init_mfs,
35018 + .fin = au_wbr_create_fin_mfs
35020 + [AuWbrCreate_PMFSRR] = {
35021 + .create = au_wbr_create_pmfsrr,
35022 + .init = au_wbr_create_init_mfsrr,
35023 + .fin = au_wbr_create_fin_mfs
35025 + [AuWbrCreate_PMFSRRV] = {
35026 + .create = au_wbr_create_pmfsrr,
35027 + .init = au_wbr_create_init_mfsrr,
35028 + .fin = au_wbr_create_fin_mfs
35031 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
35032 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
35033 +++ linux/fs/aufs/whout.c 2022-11-05 23:02:18.972555950 +0100
35035 +// SPDX-License-Identifier: GPL-2.0
35037 + * Copyright (C) 2005-2022 Junjiro R. Okajima
35039 + * This program is free software; you can redistribute it and/or modify
35040 + * it under the terms of the GNU General Public License as published by
35041 + * the Free Software Foundation; either version 2 of the License, or
35042 + * (at your option) any later version.
35044 + * This program is distributed in the hope that it will be useful,
35045 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35046 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35047 + * GNU General Public License for more details.
35049 + * You should have received a copy of the GNU General Public License
35050 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35054 + * whiteout for logical deletion and opaque directory
35059 +#define WH_MASK 0444
35062 + * If a directory contains this file, then it is opaque. We start with the
35063 + * .wh. flag so that it is blocked by lookup.
35065 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
35066 + sizeof(AUFS_WH_DIROPQ) - 1);
35069 + * generate whiteout name, which is NOT terminated by NULL.
35070 + * @name: original d_name.name
35071 + * @len: original d_name.len
35072 + * @wh: whiteout qstr
35073 + * returns zero when succeeds, otherwise error.
35074 + * succeeded value as wh->name should be freed by kfree().
35076 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
35080 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
35081 + return -ENAMETOOLONG;
35083 + wh->len = name->len + AUFS_WH_PFX_LEN;
35084 + p = kmalloc(wh->len, GFP_NOFS);
35087 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35088 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
35095 +/* ---------------------------------------------------------------------- */
35098 + * test if the @wh_name exists under @h_ppath.
35099 + * @try_sio specifies the necessary of super-io.
35101 +int au_wh_test(struct user_namespace *h_userns, struct path *h_ppath,
35102 + struct qstr *wh_name, int try_sio)
35105 + struct dentry *wh_dentry;
35108 + wh_dentry = vfsub_lkup_one(wh_name, h_ppath);
35110 + wh_dentry = au_sio_lkup_one(h_userns, wh_name, h_ppath);
35111 + err = PTR_ERR(wh_dentry);
35112 + if (IS_ERR(wh_dentry)) {
35113 + if (err == -ENAMETOOLONG)
35119 + if (d_is_negative(wh_dentry))
35120 + goto out_wh; /* success */
35123 + if (d_is_reg(wh_dentry))
35124 + goto out_wh; /* success */
35127 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
35128 + wh_dentry, d_inode(wh_dentry)->i_mode);
35137 + * test if the @h_path->dentry sets opaque or not.
35139 +int au_diropq_test(struct user_namespace *h_userns, struct path *h_path)
35142 + struct inode *h_dir;
35144 + h_dir = d_inode(h_path->dentry);
35145 + err = au_wh_test(h_userns, h_path, &diropq_name,
35146 + au_test_h_perm_sio(h_userns, h_dir, MAY_EXEC));
35151 + * returns a negative dentry whose name is unique and temporary.
35153 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35154 + struct qstr *prefix)
35156 + struct dentry *dentry;
35158 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
35160 + /* strict atomic_t is unnecessary here */
35161 + static unsigned short cnt;
35163 + struct path h_ppath;
35164 + struct user_namespace *h_userns;
35166 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
35169 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
35170 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
35171 + dentry = ERR_PTR(-ENAMETOOLONG);
35172 + if (unlikely(qs.len > NAME_MAX))
35174 + dentry = ERR_PTR(-ENOMEM);
35175 + name = kmalloc(qs.len + 1, GFP_NOFS);
35176 + if (unlikely(!name))
35180 + /* doubly whiteout-ed */
35181 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
35182 + p = name + AUFS_WH_PFX_LEN * 2;
35183 + memcpy(p, prefix->name, prefix->len);
35184 + p += prefix->len;
35186 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
35188 + h_ppath.dentry = h_parent;
35189 + h_ppath.mnt = au_br_mnt(br);
35190 + h_userns = au_br_userns(br);
35192 + for (i = 0; i < 3; i++) {
35193 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
35194 + dentry = au_sio_lkup_one(h_userns, &qs, &h_ppath);
35195 + if (IS_ERR(dentry) || d_is_negative(dentry))
35199 + /* pr_warn("could not get random name\n"); */
35200 + dentry = ERR_PTR(-EEXIST);
35201 + AuDbg("%.*s\n", AuLNPair(&qs));
35205 + if (name != defname)
35206 + au_kfree_try_rcu(name);
35208 + AuTraceErrPtr(dentry);
35213 + * rename the @h_dentry on @br to the whiteouted temporary name.
35215 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
35218 + struct path h_path = {
35219 + .mnt = au_br_mnt(br)
35221 + struct inode *h_dir, *delegated;
35222 + struct dentry *h_parent;
35224 + h_parent = h_dentry->d_parent; /* dir inode is locked */
35225 + h_dir = d_inode(h_parent);
35226 + IMustLock(h_dir);
35228 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35229 + err = PTR_ERR(h_path.dentry);
35230 + if (IS_ERR(h_path.dentry))
35233 + /* under the same dir, no need to lock_rename() */
35234 + delegated = NULL;
35235 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35238 + if (unlikely(err == -EWOULDBLOCK)) {
35239 + pr_warn("cannot retry for NFSv4 delegation"
35240 + " for an internal rename\n");
35243 + dput(h_path.dentry);
35250 +/* ---------------------------------------------------------------------- */
35252 + * functions for removing a whiteout
35255 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35258 + struct inode *delegated;
35261 + * forces superio when the dir has a sticky bit.
35262 + * this may be a violation of unix fs semantics.
35264 + force = (h_dir->i_mode & S_ISVTX)
35265 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35266 + delegated = NULL;
35267 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35268 + if (unlikely(err == -EWOULDBLOCK)) {
35269 + pr_warn("cannot retry for NFSv4 delegation"
35270 + " for an internal unlink\n");
35276 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35277 + struct dentry *dentry)
35281 + err = do_unlink_wh(h_dir, h_path);
35282 + if (!err && dentry)
35283 + au_set_dbwh(dentry, -1);
35288 +static int unlink_wh_name(struct path *h_ppath, struct qstr *wh)
35291 + struct path h_path;
35294 + h_path.dentry = vfsub_lkup_one(wh, h_ppath);
35295 + if (IS_ERR(h_path.dentry))
35296 + err = PTR_ERR(h_path.dentry);
35298 + if (d_is_reg(h_path.dentry)) {
35299 + h_path.mnt = h_ppath->mnt;
35300 + err = do_unlink_wh(d_inode(h_ppath->dentry), &h_path);
35302 + dput(h_path.dentry);
35308 +/* ---------------------------------------------------------------------- */
35310 + * initialize/clean whiteout for a branch
35313 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35317 + struct inode *delegated;
35319 + if (d_is_negative(whpath->dentry))
35323 + err = vfsub_rmdir(h_dir, whpath);
35325 + delegated = NULL;
35326 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35327 + if (unlikely(err == -EWOULDBLOCK)) {
35328 + pr_warn("cannot retry for NFSv4 delegation"
35329 + " for an internal unlink\n");
35333 + if (unlikely(err))
35334 + pr_warn("failed removing %pd (%d), ignored.\n",
35335 + whpath->dentry, err);
35338 +static int test_linkable(struct dentry *h_root)
35340 + struct inode *h_dir = d_inode(h_root);
35342 + if (h_dir->i_op->link)
35345 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35346 + h_root, au_sbtype(h_root->d_sb));
35347 + return -ENOSYS; /* the branch doesn't have its ->link() */
35350 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35351 +static int au_whdir(struct inode *h_dir, struct path *path)
35356 + if (d_is_negative(path->dentry)) {
35359 + if (au_test_nfs(path->dentry->d_sb))
35361 + err = vfsub_mkdir(h_dir, path, mode);
35362 + } else if (d_is_dir(path->dentry))
35365 + pr_err("unknown %pd exists\n", path->dentry);
35370 +struct au_wh_base {
35371 + const struct qstr *name;
35372 + struct dentry *dentry;
35375 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35376 + struct path *h_path)
35378 + h_path->dentry = base[AuBrWh_BASE].dentry;
35379 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35380 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35381 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35382 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35383 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35387 + * returns tri-state,
35388 + * minus: error, caller should print the message
35390 + * plus: error, caller should NOT print the message
35392 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35393 + int do_plink, struct au_wh_base base[],
35394 + struct path *h_path)
35397 + struct inode *h_dir;
35399 + h_dir = d_inode(h_root);
35400 + h_path->dentry = base[AuBrWh_BASE].dentry;
35401 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35402 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35404 + err = test_linkable(h_root);
35405 + if (unlikely(err)) {
35410 + err = au_whdir(h_dir, h_path);
35411 + if (unlikely(err))
35413 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35415 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35416 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35417 + err = au_whdir(h_dir, h_path);
35418 + if (unlikely(err))
35420 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35427 + * for the moment, aufs supports the branch filesystem which does not support
35428 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35429 + * copyup failed. finally, such filesystem will not be used as the writable
35432 + * returns tri-state, see above.
35434 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35435 + int do_plink, struct au_wh_base base[],
35436 + struct path *h_path)
35439 + struct inode *h_dir;
35441 + WbrWhMustWriteLock(wbr);
35443 + err = test_linkable(h_root);
35444 + if (unlikely(err)) {
35450 + * todo: should this create be done in /sbin/mount.aufs helper?
35453 + h_dir = d_inode(h_root);
35454 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35455 + h_path->dentry = base[AuBrWh_BASE].dentry;
35456 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35457 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35460 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35461 + if (unlikely(err))
35464 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35466 + err = au_whdir(h_dir, h_path);
35467 + if (unlikely(err))
35469 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35471 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35472 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35474 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35475 + err = au_whdir(h_dir, h_path);
35476 + if (unlikely(err))
35478 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35485 + * initialize the whiteout base file/dir for @br.
35487 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35490 + const unsigned char do_plink
35491 + = !!au_opt_test(au_mntflags(sb), PLINK);
35492 + struct inode *h_dir;
35493 + struct path path = br->br_path;
35494 + struct dentry *h_root = path.dentry;
35495 + struct au_wbr *wbr = br->br_wbr;
35496 + static const struct qstr base_name[] = {
35497 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35498 + sizeof(AUFS_BASE_NAME) - 1),
35499 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35500 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35501 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35502 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35504 + struct au_wh_base base[] = {
35505 + [AuBrWh_BASE] = {
35506 + .name = base_name + AuBrWh_BASE,
35509 + [AuBrWh_PLINK] = {
35510 + .name = base_name + AuBrWh_PLINK,
35513 + [AuBrWh_ORPH] = {
35514 + .name = base_name + AuBrWh_ORPH,
35520 + WbrWhMustWriteLock(wbr);
35522 + for (i = 0; i < AuBrWh_Last; i++) {
35523 + /* doubly whiteouted */
35524 + struct dentry *d;
35526 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35527 + err = PTR_ERR(d);
35531 + base[i].dentry = d;
35533 + && wbr->wbr_wh[i]
35534 + && wbr->wbr_wh[i] != base[i].dentry);
35538 + for (i = 0; i < AuBrWh_Last; i++) {
35539 + dput(wbr->wbr_wh[i]);
35540 + wbr->wbr_wh[i] = NULL;
35544 + if (!au_br_writable(br->br_perm)) {
35545 + h_dir = d_inode(h_root);
35546 + au_wh_init_ro(h_dir, base, &path);
35547 + } else if (!au_br_wh_linkable(br->br_perm)) {
35548 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35554 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35560 + goto out; /* success */
35563 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35564 + err, h_root, au_sbtype(h_root->d_sb));
35566 + for (i = 0; i < AuBrWh_Last; i++)
35567 + dput(base[i].dentry);
35571 +/* ---------------------------------------------------------------------- */
35573 + * whiteouts are all hard-linked usually.
35574 + * when its link count reaches a ceiling, we create a new whiteout base
35575 + * asynchronously.
35578 +struct reinit_br_wh {
35579 + struct super_block *sb;
35580 + struct au_branch *br;
35583 +static void reinit_br_wh(void *arg)
35586 + aufs_bindex_t bindex;
35587 + struct path h_path;
35588 + struct reinit_br_wh *a = arg;
35589 + struct au_wbr *wbr;
35590 + struct inode *dir, *delegated;
35591 + struct dentry *h_root;
35592 + struct au_hinode *hdir;
35595 + wbr = a->br->br_wbr;
35596 + /* big aufs lock */
35597 + si_noflush_write_lock(a->sb);
35598 + if (!au_br_writable(a->br->br_perm))
35600 + bindex = au_br_index(a->sb, a->br->br_id);
35601 + if (unlikely(bindex < 0))
35604 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35605 + dir = d_inode(a->sb->s_root);
35606 + hdir = au_hi(dir, bindex);
35607 + h_root = au_h_dptr(a->sb->s_root, bindex);
35608 + AuDebugOn(h_root != au_br_dentry(a->br));
35610 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35611 + wbr_wh_write_lock(wbr);
35612 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35615 + h_path.dentry = wbr->wbr_whbase;
35616 + h_path.mnt = au_br_mnt(a->br);
35617 + delegated = NULL;
35618 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35620 + if (unlikely(err == -EWOULDBLOCK)) {
35621 + pr_warn("cannot retry for NFSv4 delegation"
35622 + " for an internal unlink\n");
35626 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35629 + dput(wbr->wbr_whbase);
35630 + wbr->wbr_whbase = NULL;
35632 + err = au_wh_init(a->br, a->sb);
35633 + wbr_wh_write_unlock(wbr);
35634 + au_hn_inode_unlock(hdir);
35635 + di_read_unlock(a->sb->s_root, AuLock_IR);
35637 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35641 + atomic_dec(&wbr->wbr_wh_running);
35642 + au_lcnt_dec(&a->br->br_count);
35643 + si_write_unlock(a->sb);
35644 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35646 + if (unlikely(err))
35647 + AuIOErr("err %d\n", err);
35650 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35652 + int do_dec, wkq_err;
35653 + struct reinit_br_wh *arg;
35656 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35659 + /* ignore ENOMEM */
35660 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35663 + * dec(wh_running), kfree(arg) and dec(br_count)
35664 + * in reinit function
35668 + au_lcnt_inc(&br->br_count);
35669 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35670 + if (unlikely(wkq_err)) {
35671 + atomic_dec(&br->br_wbr->wbr_wh_running);
35672 + au_lcnt_dec(&br->br_count);
35673 + au_kfree_rcu(arg);
35680 + atomic_dec(&br->br_wbr->wbr_wh_running);
35683 +/* ---------------------------------------------------------------------- */
35686 + * create the whiteout @wh.
35688 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35689 + struct dentry *wh)
35692 + struct path h_path = {
35695 + struct au_branch *br;
35696 + struct au_wbr *wbr;
35697 + struct dentry *h_parent;
35698 + struct inode *h_dir, *delegated;
35700 + h_parent = wh->d_parent; /* dir inode is locked */
35701 + h_dir = d_inode(h_parent);
35702 + IMustLock(h_dir);
35704 + br = au_sbr(sb, bindex);
35705 + h_path.mnt = au_br_mnt(br);
35706 + wbr = br->br_wbr;
35707 + wbr_wh_read_lock(wbr);
35708 + if (wbr->wbr_whbase) {
35709 + delegated = NULL;
35710 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35711 + if (unlikely(err == -EWOULDBLOCK)) {
35712 + pr_warn("cannot retry for NFSv4 delegation"
35713 + " for an internal link\n");
35716 + if (!err || err != -EMLINK)
35719 + /* link count full. re-initialize br_whbase. */
35720 + kick_reinit_br_wh(sb, br);
35723 + /* return this error in this context */
35724 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35726 + au_fhsm_wrote(sb, bindex, /*force*/0);
35729 + wbr_wh_read_unlock(wbr);
35733 +/* ---------------------------------------------------------------------- */
35736 + * create or remove the diropq.
35738 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35739 + unsigned int flags)
35741 + struct dentry *opq_dentry;
35742 + struct super_block *sb;
35743 + struct au_branch *br;
35744 + struct path h_path;
35747 + sb = dentry->d_sb;
35748 + br = au_sbr(sb, bindex);
35749 + h_path.dentry = au_h_dptr(dentry, bindex);
35750 + h_path.mnt = au_br_mnt(br);
35751 + opq_dentry = vfsub_lkup_one(&diropq_name, &h_path);
35752 + if (IS_ERR(opq_dentry))
35755 + if (au_ftest_diropq(flags, CREATE)) {
35756 + err = link_or_create_wh(sb, bindex, opq_dentry);
35758 + au_set_dbdiropq(dentry, bindex);
35759 + goto out; /* success */
35762 + h_path.dentry = opq_dentry;
35763 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &h_path);
35765 + au_set_dbdiropq(dentry, -1);
35767 + dput(opq_dentry);
35768 + opq_dentry = ERR_PTR(err);
35771 + return opq_dentry;
35774 +struct do_diropq_args {
35775 + struct dentry **errp;
35776 + struct dentry *dentry;
35777 + aufs_bindex_t bindex;
35778 + unsigned int flags;
35781 +static void call_do_diropq(void *args)
35783 + struct do_diropq_args *a = args;
35784 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35787 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35788 + unsigned int flags)
35790 + struct dentry *diropq, *h_dentry;
35791 + struct user_namespace *h_userns;
35793 + h_userns = au_sbr_userns(dentry->d_sb, bindex);
35794 + h_dentry = au_h_dptr(dentry, bindex);
35795 + if (!au_test_h_perm_sio(h_userns, d_inode(h_dentry),
35796 + MAY_EXEC | MAY_WRITE))
35797 + diropq = do_diropq(dentry, bindex, flags);
35800 + struct do_diropq_args args = {
35802 + .dentry = dentry,
35803 + .bindex = bindex,
35807 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35808 + if (unlikely(wkq_err))
35809 + diropq = ERR_PTR(wkq_err);
35815 +/* ---------------------------------------------------------------------- */
35818 + * lookup whiteout dentry.
35819 + * @h_parent: lower parent dentry which must exist and be locked
35820 + * @base_name: name of dentry which will be whiteouted
35821 + * returns dentry for whiteout.
35823 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35824 + struct au_branch *br)
35827 + struct qstr wh_name;
35828 + struct dentry *wh_dentry;
35829 + struct path h_path;
35831 + err = au_wh_name_alloc(&wh_name, base_name);
35832 + wh_dentry = ERR_PTR(err);
35834 + h_path.dentry = h_parent;
35835 + h_path.mnt = au_br_mnt(br);
35836 + wh_dentry = vfsub_lkup_one(&wh_name, &h_path);
35837 + au_kfree_try_rcu(wh_name.name);
35839 + return wh_dentry;
35843 + * link/create a whiteout for @dentry on @bindex.
35845 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35846 + struct dentry *h_parent)
35848 + struct dentry *wh_dentry;
35849 + struct super_block *sb;
35852 + sb = dentry->d_sb;
35853 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35854 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35855 + err = link_or_create_wh(sb, bindex, wh_dentry);
35857 + au_set_dbwh(dentry, bindex);
35858 + au_fhsm_wrote(sb, bindex, /*force*/0);
35861 + wh_dentry = ERR_PTR(err);
35865 + return wh_dentry;
35868 +/* ---------------------------------------------------------------------- */
35870 +/* Delete all whiteouts in this directory on branch bindex. */
35871 +static int del_wh_children(struct path *h_path, struct au_nhash *whlist,
35872 + aufs_bindex_t bindex)
35875 + unsigned long ul, n;
35876 + struct qstr wh_name;
35878 + struct hlist_head *head;
35879 + struct au_vdir_wh *pos;
35880 + struct au_vdir_destr *str;
35883 + p = (void *)__get_free_page(GFP_NOFS);
35884 + wh_name.name = p;
35885 + if (unlikely(!wh_name.name))
35889 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35890 + p += AUFS_WH_PFX_LEN;
35891 + n = whlist->nh_num;
35892 + head = whlist->nh_head;
35893 + for (ul = 0; !err && ul < n; ul++, head++) {
35894 + hlist_for_each_entry(pos, head, wh_hash) {
35895 + if (pos->wh_bindex != bindex)
35898 + str = &pos->wh_str;
35899 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35900 + memcpy(p, str->name, str->len);
35901 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35902 + err = unlink_wh_name(h_path, &wh_name);
35907 + AuIOErr("whiteout name too long %.*s\n",
35908 + str->len, str->name);
35913 + free_page((unsigned long)wh_name.name);
35919 +struct del_wh_children_args {
35921 + struct path *h_path;
35922 + struct au_nhash *whlist;
35923 + aufs_bindex_t bindex;
35926 +static void call_del_wh_children(void *args)
35928 + struct del_wh_children_args *a = args;
35929 + *a->errp = del_wh_children(a->h_path, a->whlist, a->bindex);
35932 +/* ---------------------------------------------------------------------- */
35934 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35936 + struct au_whtmp_rmdir *whtmp;
35938 + unsigned int rdhash;
35940 + SiMustAnyLock(sb);
35942 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35943 + if (unlikely(!whtmp)) {
35944 + whtmp = ERR_PTR(-ENOMEM);
35948 + /* no estimation for dir size */
35949 + rdhash = au_sbi(sb)->si_rdhash;
35951 + rdhash = AUFS_RDHASH_DEF;
35952 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35953 + if (unlikely(err)) {
35954 + au_kfree_rcu(whtmp);
35955 + whtmp = ERR_PTR(err);
35962 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35965 + au_lcnt_dec(&whtmp->br->br_count);
35966 + dput(whtmp->wh_dentry);
35967 + iput(whtmp->dir);
35968 + au_nhash_wh_free(&whtmp->whlist);
35969 + au_kfree_rcu(whtmp);
35973 + * rmdir the whiteouted temporary named dir @h_dentry.
35974 + * @whlist: whiteouted children.
35976 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35977 + struct dentry *wh_dentry, struct au_nhash *whlist)
35980 + unsigned int h_nlink;
35981 + struct path wh_path;
35982 + struct inode *wh_inode, *h_dir;
35983 + struct au_branch *br;
35984 + struct user_namespace *h_userns;
35986 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35987 + IMustLock(h_dir);
35989 + br = au_sbr(dir->i_sb, bindex);
35990 + wh_path.dentry = wh_dentry;
35991 + wh_path.mnt = au_br_mnt(br);
35992 + h_userns = au_br_userns(br);
35993 + wh_inode = d_inode(wh_dentry);
35994 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35997 + * someone else might change some whiteouts while we were sleeping.
35998 + * it means this whlist may have an obsoleted entry.
36000 + if (!au_test_h_perm_sio(h_userns, wh_inode, MAY_EXEC | MAY_WRITE))
36001 + err = del_wh_children(&wh_path, whlist, bindex);
36004 + struct del_wh_children_args args = {
36006 + .h_path = &wh_path,
36007 + .whlist = whlist,
36011 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
36012 + if (unlikely(wkq_err))
36015 + inode_unlock(wh_inode);
36018 + h_nlink = h_dir->i_nlink;
36019 + err = vfsub_rmdir(h_dir, &wh_path);
36020 + /* some fs doesn't change the parent nlink in some cases */
36021 + h_nlink -= h_dir->i_nlink;
36025 + if (au_ibtop(dir) == bindex) {
36026 + /* todo: dir->i_mutex is necessary */
36027 + au_cpup_attr_timesizes(dir);
36029 + vfsub_drop_nlink(dir);
36031 + return 0; /* success */
36034 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
36038 +static void call_rmdir_whtmp(void *args)
36041 + aufs_bindex_t bindex;
36042 + struct au_whtmp_rmdir *a = args;
36043 + struct super_block *sb;
36044 + struct dentry *h_parent;
36045 + struct inode *h_dir;
36046 + struct au_hinode *hdir;
36048 + /* rmdir by nfsd may cause deadlock with this i_mutex */
36049 + /* inode_lock(a->dir); */
36051 + sb = a->dir->i_sb;
36052 + si_read_lock(sb, !AuLock_FLUSH);
36053 + if (!au_br_writable(a->br->br_perm))
36055 + bindex = au_br_index(sb, a->br->br_id);
36056 + if (unlikely(bindex < 0))
36060 + ii_write_lock_parent(a->dir);
36061 + h_parent = dget_parent(a->wh_dentry);
36062 + h_dir = d_inode(h_parent);
36063 + hdir = au_hi(a->dir, bindex);
36064 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
36065 + if (unlikely(err))
36067 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
36068 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
36071 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
36072 + au_hn_inode_unlock(hdir);
36073 + vfsub_mnt_drop_write(au_br_mnt(a->br));
36077 + ii_write_unlock(a->dir);
36079 + /* inode_unlock(a->dir); */
36080 + au_whtmp_rmdir_free(a);
36081 + si_read_unlock(sb);
36082 + au_nwt_done(&au_sbi(sb)->si_nowait);
36083 + if (unlikely(err))
36084 + AuIOErr("err %d\n", err);
36087 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36088 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
36091 + struct super_block *sb;
36095 + /* all post-process will be done in do_rmdir_whtmp(). */
36097 + args->dir = au_igrab(dir);
36098 + args->br = au_sbr(sb, bindex);
36099 + au_lcnt_inc(&args->br->br_count);
36100 + args->wh_dentry = dget(wh_dentry);
36101 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
36102 + if (unlikely(wkq_err)) {
36103 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
36104 + au_whtmp_rmdir_free(args);
36107 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
36108 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
36109 +++ linux/fs/aufs/whout.h 2022-11-05 23:02:18.972555950 +0100
36111 +/* SPDX-License-Identifier: GPL-2.0 */
36113 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36115 + * This program is free software; you can redistribute it and/or modify
36116 + * it under the terms of the GNU General Public License as published by
36117 + * the Free Software Foundation; either version 2 of the License, or
36118 + * (at your option) any later version.
36120 + * This program is distributed in the hope that it will be useful,
36121 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36122 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36123 + * GNU General Public License for more details.
36125 + * You should have received a copy of the GNU General Public License
36126 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36130 + * whiteout for logical deletion and opaque directory
36133 +#ifndef __AUFS_WHOUT_H__
36134 +#define __AUFS_WHOUT_H__
36141 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
36142 +int au_wh_test(struct user_namespace *h_userns, struct path *h_ppath,
36143 + struct qstr *wh_name, int try_sio);
36144 +int au_diropq_test(struct user_namespace *h_userns, struct path *h_path);
36146 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
36147 + struct qstr *prefix);
36148 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
36149 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
36150 + struct dentry *dentry);
36151 +int au_wh_init(struct au_branch *br, struct super_block *sb);
36153 +/* diropq flags */
36154 +#define AuDiropq_CREATE 1
36155 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
36156 +#define au_fset_diropq(flags, name) \
36157 + do { (flags) |= AuDiropq_##name; } while (0)
36158 +#define au_fclr_diropq(flags, name) \
36159 + do { (flags) &= ~AuDiropq_##name; } while (0)
36161 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
36162 + unsigned int flags);
36163 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
36164 + struct au_branch *br);
36165 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
36166 + struct dentry *h_parent);
36168 +/* real rmdir for the whiteout-ed dir */
36169 +struct au_whtmp_rmdir {
36170 + struct inode *dir;
36171 + struct au_branch *br;
36172 + struct dentry *wh_dentry;
36173 + struct au_nhash whlist;
36176 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
36177 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
36178 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36179 + struct dentry *wh_dentry, struct au_nhash *whlist);
36180 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36181 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
36183 +/* ---------------------------------------------------------------------- */
36185 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
36186 + aufs_bindex_t bindex)
36188 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
36191 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
36193 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
36196 +#endif /* __KERNEL__ */
36197 +#endif /* __AUFS_WHOUT_H__ */
36198 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
36199 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
36200 +++ linux/fs/aufs/wkq.c 2022-11-05 23:02:18.972555950 +0100
36202 +// SPDX-License-Identifier: GPL-2.0
36204 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36206 + * This program is free software; you can redistribute it and/or modify
36207 + * it under the terms of the GNU General Public License as published by
36208 + * the Free Software Foundation; either version 2 of the License, or
36209 + * (at your option) any later version.
36211 + * This program is distributed in the hope that it will be useful,
36212 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36213 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36214 + * GNU General Public License for more details.
36216 + * You should have received a copy of the GNU General Public License
36217 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36221 + * workqueue for asynchronous/super-io operations
36222 + * todo: try new credential scheme
36225 +#include <linux/module.h>
36228 +/* internal workqueue named AUFS_WKQ_NAME */
36230 +static struct workqueue_struct *au_wkq;
36232 +struct au_wkinfo {
36233 + struct work_struct wk;
36234 + struct kobject *kobj;
36236 + unsigned int flags; /* see wkq.h */
36238 + au_wkq_func_t func;
36241 +#ifdef CONFIG_LOCKDEP
36243 + struct held_lock **hlock;
36246 + struct completion *comp;
36249 +/* ---------------------------------------------------------------------- */
36251 + * Aufs passes some operations to the workqueue such as the internal copyup.
36252 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36253 + * job run by workqueue depends upon the locks acquired in the other task.
36254 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36255 + * information too. And the job in the workqueue restores the info in order to
36256 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36257 + * correctly and expectedly.
36260 +#ifndef CONFIG_LOCKDEP
36261 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36262 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36263 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36264 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36265 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36267 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36269 + wkinfo->hlock = NULL;
36270 + wkinfo->dont_check = 0;
36277 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36279 + static DEFINE_SPINLOCK(spin);
36282 + struct lock_class_key *key;
36284 + { .name = "&sbinfo->si_rwsem" },
36285 + { .name = "&finfo->fi_rwsem" },
36286 + { .name = "&dinfo->di_rwsem" },
36287 + { .name = "&iinfo->ii_rwsem" }
36292 + /* lockless read from 'set.' see below */
36293 + if (set == ARRAY_SIZE(a)) {
36294 + for (i = 0; i < ARRAY_SIZE(a); i++)
36295 + if (a[i].key == key)
36300 + spin_lock(&spin);
36302 + for (i = 0; i < ARRAY_SIZE(a); i++)
36303 + if (a[i].key == key) {
36304 + spin_unlock(&spin);
36307 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36309 + if (unlikely(a[i].key == key)) { /* rare but possible */
36310 + spin_unlock(&spin);
36315 + if (strstr(a[i].name, name)) {
36317 + * the order of these three lines is important for the
36318 + * lockless read above.
36321 + spin_unlock(&spin);
36323 + /* AuDbg("%d, %s\n", set, name); */
36327 + spin_unlock(&spin);
36336 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36339 + struct task_struct *curr;
36340 + struct held_lock **hl, *held_locks, *p;
36344 + wkinfo->dont_check = lockdep_recursing(curr);
36345 + if (wkinfo->dont_check)
36347 + n = curr->lockdep_depth;
36352 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36353 + if (unlikely(!wkinfo->hlock))
36357 +#if 0 /* left for debugging */
36358 + if (0 && au_debug_test())
36359 + lockdep_print_held_locks(curr);
36361 + held_locks = curr->held_locks;
36362 + hl = wkinfo->hlock;
36364 + p = held_locks++;
36365 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36374 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36376 + au_kfree_try_rcu(wkinfo->hlock);
36379 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36381 + struct held_lock *p, **hl = wkinfo->hlock;
36384 + if (wkinfo->dont_check)
36388 + while ((p = *hl++)) { /* assignment */
36389 + subclass = lockdep_hlock_class(p)->subclass;
36390 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36392 + rwsem_acquire_read(p->instance, subclass, 0,
36393 + /*p->acquire_ip*/_RET_IP_);
36395 + rwsem_acquire(p->instance, subclass, 0,
36396 + /*p->acquire_ip*/_RET_IP_);
36400 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36402 + struct held_lock *p, **hl = wkinfo->hlock;
36404 + if (wkinfo->dont_check)
36408 + while ((p = *hl++)) /* assignment */
36409 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36413 +static void wkq_func(struct work_struct *wk)
36415 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36417 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36418 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36420 + au_wkq_lockdep_pre(wkinfo);
36421 + wkinfo->func(wkinfo->args);
36422 + au_wkq_lockdep_post(wkinfo);
36423 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36424 + complete(wkinfo->comp);
36426 + kobject_put(wkinfo->kobj);
36427 + module_put(THIS_MODULE); /* todo: ?? */
36428 + au_kfree_rcu(wkinfo);
36433 + * Since struct completion is large, try allocating it dynamically.
36435 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36437 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36439 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36441 + init_completion(*comp);
36442 + wkinfo->comp = *comp;
36448 +static void au_wkq_comp_free(struct completion *comp)
36450 + au_kfree_rcu(comp);
36453 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36455 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36456 + if (au_wkq_test()) {
36457 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36458 + " due to a dead dir by UDBA,"
36459 + " or async xino write?\n");
36460 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36463 + au_dbg_verify_kthread();
36465 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36466 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36467 + queue_work(au_wkq, &wkinfo->wk);
36469 + INIT_WORK(&wkinfo->wk, wkq_func);
36470 + schedule_work(&wkinfo->wk);
36475 + * Be careful. It is easy to make deadlock happen.
36476 + * processA: lock, wkq and wait
36477 + * processB: wkq and wait, lock in wkq
36480 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36483 + AuWkqCompDeclare(comp);
36484 + struct au_wkinfo wkinfo = {
36490 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36491 + if (unlikely(err))
36493 + err = au_wkq_lockdep_alloc(&wkinfo);
36494 + if (unlikely(err))
36497 + au_wkq_run(&wkinfo);
36498 + /* no timeout, no interrupt */
36499 + wait_for_completion(wkinfo.comp);
36501 + au_wkq_lockdep_free(&wkinfo);
36504 + au_wkq_comp_free(comp);
36506 + destroy_work_on_stack(&wkinfo.wk);
36511 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36512 + * problem in a concurrent umounting.
36514 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36515 + unsigned int flags)
36518 + struct au_wkinfo *wkinfo;
36520 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36523 + * wkq_func() must free this wkinfo.
36524 + * it highly depends upon the implementation of workqueue.
36527 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36529 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36530 + wkinfo->flags = flags & ~AuWkq_WAIT;
36531 + wkinfo->func = func;
36532 + wkinfo->args = args;
36533 + wkinfo->comp = NULL;
36534 + au_wkq_lockdep_init(wkinfo);
36535 + kobject_get(wkinfo->kobj);
36536 + __module_get(THIS_MODULE); /* todo: ?? */
36538 + au_wkq_run(wkinfo);
36541 + au_nwt_done(&au_sbi(sb)->si_nowait);
36547 +/* ---------------------------------------------------------------------- */
36549 +void au_nwt_init(struct au_nowait_tasks *nwt)
36551 + atomic_set(&nwt->nw_len, 0);
36552 + /* smp_mb(); */ /* atomic_set */
36553 + init_waitqueue_head(&nwt->nw_wq);
36556 +void au_wkq_fin(void)
36558 + destroy_workqueue(au_wkq);
36561 +int __init au_wkq_init(void)
36566 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36567 + if (IS_ERR(au_wkq))
36568 + err = PTR_ERR(au_wkq);
36569 + else if (!au_wkq)
36574 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36575 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36576 +++ linux/fs/aufs/wkq.h 2022-11-05 23:02:18.972555950 +0100
36578 +/* SPDX-License-Identifier: GPL-2.0 */
36580 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36582 + * This program is free software; you can redistribute it and/or modify
36583 + * it under the terms of the GNU General Public License as published by
36584 + * the Free Software Foundation; either version 2 of the License, or
36585 + * (at your option) any later version.
36587 + * This program is distributed in the hope that it will be useful,
36588 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36589 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36590 + * GNU General Public License for more details.
36592 + * You should have received a copy of the GNU General Public License
36593 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36597 + * workqueue for asynchronous/super-io operations
36598 + * todo: try new credentials management scheme
36601 +#ifndef __AUFS_WKQ_H__
36602 +#define __AUFS_WKQ_H__
36606 +#include <linux/wait.h>
36608 +struct super_block;
36610 +/* ---------------------------------------------------------------------- */
36613 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36615 +struct au_nowait_tasks {
36617 + wait_queue_head_t nw_wq;
36620 +/* ---------------------------------------------------------------------- */
36622 +typedef void (*au_wkq_func_t)(void *args);
36625 +#define AuWkq_WAIT 1
36626 +#define AuWkq_NEST (1 << 1)
36627 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36628 +#define au_fset_wkq(flags, name) \
36629 + do { (flags) |= AuWkq_##name; } while (0)
36630 +#define au_fclr_wkq(flags, name) \
36631 + do { (flags) &= ~AuWkq_##name; } while (0)
36634 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36635 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36636 + unsigned int flags);
36637 +void au_nwt_init(struct au_nowait_tasks *nwt);
36638 +int __init au_wkq_init(void);
36639 +void au_wkq_fin(void);
36641 +/* ---------------------------------------------------------------------- */
36643 +static inline int au_wkq_test(void)
36645 + return current->flags & PF_WQ_WORKER;
36648 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36650 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36653 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36655 + if (atomic_dec_and_test(&nwt->nw_len))
36656 + wake_up_all(&nwt->nw_wq);
36659 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36661 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36665 +#endif /* __KERNEL__ */
36666 +#endif /* __AUFS_WKQ_H__ */
36667 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36668 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36669 +++ linux/fs/aufs/xattr.c 2022-11-05 23:02:18.972555950 +0100
36671 +// SPDX-License-Identifier: GPL-2.0
36673 + * Copyright (C) 2014-2022 Junjiro R. Okajima
36675 + * This program is free software; you can redistribute it and/or modify
36676 + * it under the terms of the GNU General Public License as published by
36677 + * the Free Software Foundation; either version 2 of the License, or
36678 + * (at your option) any later version.
36680 + * This program is distributed in the hope that it will be useful,
36681 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36682 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36683 + * GNU General Public License for more details.
36685 + * You should have received a copy of the GNU General Public License
36686 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36690 + * handling xattr functions
36693 +#include <linux/fs.h>
36694 +#include <linux/posix_acl_xattr.h>
36695 +#include <linux/xattr.h>
36698 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36700 + if (!ignore_flags)
36708 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36713 +#define cmp(brattr, prefix) do { \
36714 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36715 + XATTR_##prefix##_PREFIX_LEN)) { \
36716 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36722 + cmp(SEC, SECURITY);
36723 + cmp(SYS, SYSTEM);
36724 + cmp(TR, TRUSTED);
36728 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36735 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36737 +static int au_do_cpup_xattr(struct path *h_dst, struct path *h_src,
36738 + char *name, char **buf, unsigned int ignore_flags,
36739 + unsigned int verbose)
36743 + struct inode *h_idst;
36744 + struct dentry *h_dst_dentry, *h_src_dentry;
36745 + struct user_namespace *h_dst_userns, *h_src_userns;
36747 + h_src_userns = mnt_user_ns(h_src->mnt);
36748 + h_src_dentry = h_src->dentry;
36749 + ssz = vfs_getxattr_alloc(h_src_userns, h_src_dentry, name, buf, 0,
36752 + if (unlikely(err <= 0)) {
36753 + if (err == -ENODATA
36754 + || (err == -EOPNOTSUPP
36755 + && ((ignore_flags & au_xattr_out_of_list)
36756 + || (au_test_nfs_noacl(d_inode(h_src_dentry))
36757 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36759 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36762 + if (err && (verbose || au_debug_test()))
36763 + pr_err("%s, err %d\n", name, err);
36767 + /* unlock it temporary */
36768 + h_dst_userns = mnt_user_ns(h_dst->mnt);
36769 + h_dst_dentry = h_dst->dentry;
36770 + h_idst = d_inode(h_dst_dentry);
36771 + inode_unlock(h_idst);
36772 + err = vfsub_setxattr(h_dst_userns, h_dst_dentry, name, *buf, ssz,
36774 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36775 + if (unlikely(err)) {
36776 + if (verbose || au_debug_test())
36777 + pr_err("%s, err %d\n", name, err);
36778 + err = au_xattr_ignore(err, name, ignore_flags);
36785 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
36786 + unsigned int verbose)
36788 + int err, unlocked, acl_access, acl_default;
36790 + struct dentry *h_dst_dentry, *h_src_dentry;
36791 + struct inode *h_isrc, *h_idst;
36792 + char *value, *p, *o, *e;
36794 + /* try stopping to update the source inode while we are referencing */
36795 + /* there should not be the parent-child relationship between them */
36796 + h_dst_dentry = h_dst->dentry;
36797 + h_idst = d_inode(h_dst_dentry);
36798 + h_src_dentry = h_src->dentry;
36799 + h_isrc = d_inode(h_src_dentry);
36800 + inode_unlock(h_idst);
36801 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36802 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36805 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36806 + ssz = vfs_listxattr(h_src_dentry, NULL, 0);
36808 + if (unlikely(err < 0)) {
36810 + if (err == -ENODATA
36811 + || err == -EOPNOTSUPP)
36812 + err = 0; /* ignore */
36821 + p = kmalloc(ssz, GFP_NOFS);
36823 + if (unlikely(!p))
36825 + err = vfs_listxattr(h_src_dentry, p, ssz);
36827 + inode_unlock_shared(h_isrc);
36829 + AuDbg("err %d, ssz %zd\n", err, ssz);
36830 + if (unlikely(err < 0))
36838 + while (!err && p < e) {
36839 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36840 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36841 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36842 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36844 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36846 + p += strlen(p) + 1;
36849 + ignore_flags |= au_xattr_out_of_list;
36850 + if (!err && !acl_access) {
36851 + err = au_do_cpup_xattr(h_dst, h_src,
36852 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36853 + ignore_flags, verbose);
36856 + if (!err && !acl_default) {
36857 + err = au_do_cpup_xattr(h_dst, h_src,
36858 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36859 + ignore_flags, verbose);
36863 + au_kfree_try_rcu(value);
36866 + au_kfree_try_rcu(o);
36869 + inode_unlock_shared(h_isrc);
36874 +/* ---------------------------------------------------------------------- */
36876 +static int au_smack_reentering(struct super_block *sb)
36878 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36880 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36881 + * i_op->getxattr(). ouch.
36883 + return si_pid_test(sb);
36894 +struct au_lgxattr {
36902 + const char *name;
36909 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36910 + struct au_lgxattr *arg)
36914 + struct path h_path;
36915 + struct super_block *sb;
36917 + sb = dentry->d_sb;
36918 + reenter = au_smack_reentering(sb);
36920 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36921 + if (unlikely(err))
36924 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
36925 + if (unlikely(err))
36927 + if (unlikely(!h_path.dentry))
36928 + /* illegally overlapped or something */
36929 + goto out_di; /* pretending success */
36931 + /* always topmost entry only */
36932 + switch (arg->type) {
36933 + case AU_XATTR_LIST:
36934 + err = vfs_listxattr(h_path.dentry,
36935 + arg->u.list.list, arg->u.list.size);
36937 + case AU_XATTR_GET:
36938 + AuDebugOn(d_is_negative(h_path.dentry));
36939 + err = vfs_getxattr(mnt_user_ns(h_path.mnt), h_path.dentry,
36940 + arg->u.get.name, arg->u.get.value,
36941 + arg->u.get.size);
36947 + di_read_unlock(dentry, AuLock_IR);
36950 + si_read_unlock(sb);
36956 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36958 + struct au_lgxattr arg = {
36959 + .type = AU_XATTR_LIST,
36966 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
36969 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
36970 + const char *name, void *value, size_t size)
36972 + struct au_lgxattr arg = {
36973 + .type = AU_XATTR_GET,
36981 + return au_lgxattr(dentry, inode, &arg);
36984 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36985 + const char *name, void *value, size_t size,
36988 + struct au_sxattr arg = {
36989 + .type = AU_XATTR_SET,
36998 + return au_sxattr(dentry, inode, &arg);
37001 +/* ---------------------------------------------------------------------- */
37003 +static int au_xattr_get(const struct xattr_handler *handler,
37004 + struct dentry *dentry, struct inode *inode,
37005 + const char *name, void *buffer, size_t size)
37007 + return au_getxattr(dentry, inode, name, buffer, size);
37011 + * The prameter 'void *value' of vfs_setxattr() is NOT const, but
37012 + * xattr_handler->set() requires const. Is it OK? I don't know.
37014 +static int au_xattr_set(const struct xattr_handler *handler,
37015 + struct user_namespace *userns,
37016 + struct dentry *dentry, struct inode *inode,
37017 + const char *name, const void *value, size_t size,
37020 + return au_setxattr(dentry, inode, name, (void *)value, size, flags);
37023 +static const struct xattr_handler au_xattr_handler = {
37026 + .get = au_xattr_get,
37027 + .set = au_xattr_set
37030 +static const struct xattr_handler *au_xattr_handlers[] = {
37031 +#ifdef CONFIG_FS_POSIX_ACL
37032 + &posix_acl_access_xattr_handler,
37033 + &posix_acl_default_xattr_handler,
37035 + &au_xattr_handler, /* must be last */
37039 +void au_xattr_init(struct super_block *sb)
37041 + sb->s_xattr = au_xattr_handlers;
37043 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
37044 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
37045 +++ linux/fs/aufs/xino.c 2022-11-05 23:02:18.972555950 +0100
37047 +// SPDX-License-Identifier: GPL-2.0
37049 + * Copyright (C) 2005-2022 Junjiro R. Okajima
37051 + * This program is free software; you can redistribute it and/or modify
37052 + * it under the terms of the GNU General Public License as published by
37053 + * the Free Software Foundation; either version 2 of the License, or
37054 + * (at your option) any later version.
37056 + * This program is distributed in the hope that it will be useful,
37057 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
37058 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37059 + * GNU General Public License for more details.
37061 + * You should have received a copy of the GNU General Public License
37062 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
37066 + * external inode number translation table and bitmap
37068 + * things to consider
37070 + * + au_xino object
37071 + * + XINO files (xino, xib, xigen)
37072 + * + dynamic debugfs entries (xiN)
37073 + * + static debugfs entries (xib, xigen)
37074 + * + static sysfs entry (xi_path)
37075 + * - several entry points to handle them.
37076 + * + mount(2) without xino option (default)
37077 + * + mount(2) with xino option
37078 + * + mount(2) with noxino option
37080 + * + remount with add/del branches
37081 + * + remount with xino/noxino options
37084 +#include <linux/seq_file.h>
37085 +#include <linux/statfs.h>
37088 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
37089 + aufs_bindex_t bbot,
37090 + struct super_block *h_sb)
37092 + /* todo: try binary-search if the branches are many */
37093 + for (; btop <= bbot; btop++)
37094 + if (h_sb == au_sbr_sb(sb, btop))
37100 + * find another branch who is on the same filesystem of the specified
37101 + * branch{@btgt}. search until @bbot.
37103 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
37104 + aufs_bindex_t bbot)
37106 + aufs_bindex_t bindex;
37107 + struct super_block *tgt_sb;
37109 + tgt_sb = au_sbr_sb(sb, btgt);
37110 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
37112 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
37117 +/* ---------------------------------------------------------------------- */
37120 + * stop unnecessary notify events at creating xino files
37123 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
37125 + aufs_bindex_t bfound, bindex, bbot;
37126 + struct dentry *parent;
37127 + struct au_branch *br;
37130 + parent = dentry->d_parent; /* safe d_parent access */
37131 + bbot = au_sbbot(sb);
37132 + for (bindex = 0; bindex <= bbot; bindex++) {
37133 + br = au_sbr(sb, bindex);
37134 + if (au_br_dentry(br) == parent) {
37140 + AuDbg("bfound b%d\n", bfound);
37144 +struct au_xino_lock_dir {
37145 + struct au_hinode *hdir;
37146 + struct dentry *parent;
37147 + struct inode *dir;
37150 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
37151 + unsigned int lsc)
37153 + struct dentry *parent;
37154 + struct inode *dir;
37156 + parent = dget_parent(dentry);
37157 + dir = d_inode(parent);
37158 + inode_lock_nested(dir, lsc);
37159 +#if 0 /* it should not happen */
37160 + spin_lock(&dentry->d_lock);
37161 + if (unlikely(dentry->d_parent != parent)) {
37162 + spin_unlock(&dentry->d_lock);
37163 + inode_unlock(dir);
37168 + spin_unlock(&dentry->d_lock);
37175 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
37176 + struct au_xino_lock_dir *ldir)
37178 + aufs_bindex_t bindex;
37180 + ldir->hdir = NULL;
37181 + bindex = au_xi_root(sb, xipath->dentry);
37182 + if (bindex >= 0) {
37183 + /* rw branch root */
37184 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
37185 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
37188 + ldir->parent = au_dget_parent_lock(xipath->dentry,
37190 + ldir->dir = d_inode(ldir->parent);
37194 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
37197 + au_hn_inode_unlock(ldir->hdir);
37199 + inode_unlock(ldir->dir);
37200 + dput(ldir->parent);
37204 +/* ---------------------------------------------------------------------- */
37207 + * create and set a new xino file
37209 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
37212 + struct file *file;
37213 + struct dentry *h_parent, *d;
37214 + struct inode *h_dir, *inode;
37216 + static DEFINE_MUTEX(mtx);
37219 + * at mount-time, and the xino file is the default path,
37220 + * hnotify is disabled so we have no notify events to ignore.
37221 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37224 + mutex_lock(&mtx);
37225 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37226 + /* | __FMODE_NONOTIFY */,
37228 + if (IS_ERR(file)) {
37230 + mutex_unlock(&mtx);
37232 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
37236 + /* keep file count */
37238 + d = file->f_path.dentry;
37239 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
37241 + mutex_unlock(&mtx);
37242 + /* mnt_want_write() is unnecessary here */
37243 + h_dir = d_inode(h_parent);
37244 + inode = file_inode(file);
37245 + /* no delegation since it is just created */
37246 + if (inode->i_nlink)
37247 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37249 + inode_unlock(h_dir);
37251 + if (unlikely(err)) {
37253 + pr_err("unlink %s(%d)\n", fpath, err);
37258 + if (unlikely(sb && sb == d->d_sb)) {
37260 + pr_err("%s must be outside\n", fpath);
37263 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37265 + pr_err("xino doesn't support %s(%s)\n",
37266 + fpath, au_sbtype(d->d_sb));
37269 + return file; /* success */
37273 + file = ERR_PTR(err);
37278 + * create a new xinofile at the same place/path as @base.
37280 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37281 + struct file *copy_src)
37283 + struct file *file;
37284 + struct dentry *dentry;
37285 + struct inode *dir, *delegated;
37286 + struct qstr *name;
37287 + struct path ppath, path;
37288 + int err, do_unlock;
37289 + struct au_xino_lock_dir ldir;
37292 + au_xino_lock_dir(sb, base, &ldir);
37293 + dentry = base->dentry;
37294 + ppath.dentry = dentry->d_parent; /* dir inode is locked */
37295 + ppath.mnt = base->mnt;
37296 + dir = d_inode(ppath.dentry);
37299 + name = &dentry->d_name;
37300 + path.dentry = vfsub_lookup_one_len(name->name, &ppath, name->len);
37301 + if (IS_ERR(path.dentry)) {
37302 + file = (void *)path.dentry;
37303 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37307 + /* no need to mnt_want_write() since we call dentry_open() later */
37308 + err = vfs_create(mnt_user_ns(base->mnt), dir, path.dentry, 0666, NULL);
37309 + if (unlikely(err)) {
37310 + file = ERR_PTR(err);
37311 + pr_err("%pd create err %d\n", dentry, err);
37315 + path.mnt = base->mnt;
37316 + file = vfsub_dentry_open(&path,
37317 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37318 + /* | __FMODE_NONOTIFY */);
37319 + if (IS_ERR(file)) {
37320 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37324 + delegated = NULL;
37325 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37326 + au_xino_unlock_dir(&ldir);
37328 + if (unlikely(err == -EWOULDBLOCK)) {
37329 + pr_warn("cannot retry for NFSv4 delegation"
37330 + " for an internal unlink\n");
37333 + if (unlikely(err)) {
37334 + pr_err("%pd unlink err %d\n", dentry, err);
37339 + /* no one can touch copy_src xino */
37340 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37341 + if (unlikely(err)) {
37342 + pr_err("%pd copy err %d\n", dentry, err);
37346 + goto out_dput; /* success */
37350 + file = ERR_PTR(err);
37352 + dput(path.dentry);
37355 + au_xino_unlock_dir(&ldir);
37359 +struct file *au_xino_file1(struct au_xino *xi)
37361 + struct file *file;
37362 + unsigned int u, nfile;
37365 + nfile = xi->xi_nfile;
37366 + for (u = 0; u < nfile; u++) {
37367 + file = xi->xi_file[u];
37375 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37386 + if (idx < xi->xi_nfile) {
37387 + f = xi->xi_file[idx];
37391 + p = au_kzrealloc(xi->xi_file,
37392 + sizeof(*xi->xi_file) * xi->xi_nfile,
37393 + sizeof(*xi->xi_file) * (idx + 1),
37394 + GFP_NOFS, /*may_shrink*/0);
37396 + MtxMustLock(&xi->xi_mtx);
37398 + xi->xi_nfile = idx + 1;
37406 + xi->xi_file[idx] = file;
37413 + * if @xinew->xi is not set, then create new xigen file.
37415 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37417 + struct file *file;
37420 + SiMustAnyLock(sb);
37422 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37423 + if (IS_ERR(file)) {
37424 + err = PTR_ERR(file);
37425 + pr_err("%s[%d], err %d\n",
37426 + xinew->xi ? "xino" : "xigen",
37427 + xinew->idx, err);
37432 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37435 + /* todo: make xigen file an array */
37436 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37439 + if (unlikely(err))
37440 + file = ERR_PTR(err);
37446 +/* ---------------------------------------------------------------------- */
37449 + * truncate xino files
37451 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37452 + int idx, struct kstatfs *st)
37456 + struct file *file, *new_xino;
37457 + struct au_xi_new xinew = {
37462 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37463 + file = au_xino_file(xinew.xi, idx);
37467 + xinew.base = &file->f_path;
37468 + err = vfs_statfs(xinew.base, st);
37469 + if (unlikely(err)) {
37470 + AuErr1("statfs err %d, ignored\n", err);
37475 + blocks = file_inode(file)->i_blocks;
37476 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37477 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37479 + xinew.copy_src = file;
37480 + new_xino = au_xi_new(sb, &xinew);
37481 + if (IS_ERR(new_xino)) {
37482 + err = PTR_ERR(new_xino);
37483 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37487 + err = vfs_statfs(&new_xino->f_path, st);
37489 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37490 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37491 + st->f_bfree, st->f_blocks);
37493 + AuErr1("statfs err %d, ignored\n", err);
37501 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37504 + unsigned long jiffy;
37505 + aufs_bindex_t bbot;
37506 + struct kstatfs *st;
37507 + struct au_branch *br;
37508 + struct au_xino *xi;
37511 + st = kmalloc(sizeof(*st), GFP_NOFS);
37512 + if (unlikely(!st))
37516 + bbot = au_sbbot(sb);
37517 + if (unlikely(bindex < 0 || bbot < bindex))
37522 + br = au_sbr(sb, bindex);
37523 + xi = br->br_xino;
37524 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37525 + err = au_xino_do_trunc(sb, bindex, i, st);
37527 + au_sbi(sb)->si_xino_jiffy = jiffy;
37530 + au_kfree_rcu(st);
37535 +struct xino_do_trunc_args {
37536 + struct super_block *sb;
37537 + struct au_branch *br;
37541 +static void xino_do_trunc(void *_args)
37543 + struct xino_do_trunc_args *args = _args;
37544 + struct super_block *sb;
37545 + struct au_branch *br;
37546 + struct inode *dir;
37548 + aufs_bindex_t bindex;
37552 + dir = d_inode(sb->s_root);
37556 + si_noflush_write_lock(sb);
37557 + ii_read_lock_parent(dir);
37558 + bindex = au_br_index(sb, br->br_id);
37559 + err = au_xino_trunc(sb, bindex, idx);
37560 + ii_read_unlock(dir);
37561 + if (unlikely(err))
37562 + pr_warn("err b%d, (%d)\n", bindex, err);
37563 + atomic_dec(&br->br_xino->xi_truncating);
37564 + au_lcnt_dec(&br->br_count);
37565 + si_write_unlock(sb);
37566 + au_nwt_done(&au_sbi(sb)->si_nowait);
37567 + au_kfree_rcu(args);
37571 + * returns the index in the xi_file array whose corresponding file is necessary
37572 + * to truncate, or -1 which means no need to truncate.
37574 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37578 + struct kstatfs st;
37579 + struct au_sbinfo *sbinfo;
37580 + struct au_xino *xi;
37581 + struct file *file;
37583 + /* todo: si_xino_expire and the ratio should be customizable */
37584 + sbinfo = au_sbi(sb);
37585 + if (time_before(jiffies,
37586 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37589 + /* truncation border */
37590 + xi = br->br_xino;
37591 + for (u = 0; u < xi->xi_nfile; u++) {
37592 + file = au_xino_file(xi, u);
37596 + err = vfs_statfs(&file->f_path, &st);
37597 + if (unlikely(err)) {
37598 + AuErr1("statfs err %d, ignored\n", err);
37601 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37602 + >= AUFS_XINO_DEF_TRUNC)
37609 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37612 + struct xino_do_trunc_args *args;
37615 + idx = xino_trunc_test(sb, br);
37619 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37622 + /* lock and kfree() will be called in trunc_xino() */
37623 + args = kmalloc(sizeof(*args), GFP_NOFS);
37624 + if (unlikely(!args)) {
37625 + AuErr1("no memory\n");
37629 + au_lcnt_inc(&br->br_count);
37633 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37635 + return; /* success */
37637 + pr_err("wkq %d\n", wkq_err);
37638 + au_lcnt_dec(&br->br_count);
37639 + au_kfree_rcu(args);
37642 + atomic_dec(&br->br_xino->xi_truncating);
37645 +/* ---------------------------------------------------------------------- */
37647 +struct au_xi_calc {
37652 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37653 + struct au_xi_calc *calc)
37657 + maxent = au_xi_maxent(sb);
37658 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37659 + calc->pos *= sizeof(ino_t);
37662 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37663 + struct au_xi_calc *calc)
37666 + struct file *file;
37667 + struct au_xino *xi = br->br_xino;
37668 + struct au_xi_new xinew = {
37672 + SiMustAnyLock(sb);
37678 + mutex_lock(&xi->xi_mtx);
37679 + file = au_xino_file(xi, calc->idx);
37683 + file = au_xino_file(xi, /*idx*/-1);
37684 + AuDebugOn(!file);
37685 + xinew.idx = calc->idx;
37686 + xinew.base = &file->f_path;
37687 + /* xinew.copy_src = NULL; */
37688 + file = au_xi_new(sb, &xinew);
37689 + if (IS_ERR(file))
37690 + err = PTR_ERR(file);
37693 + mutex_unlock(&xi->xi_mtx);
37698 +struct au_xino_do_new_async_args {
37699 + struct super_block *sb;
37700 + struct au_branch *br;
37701 + struct au_xi_calc calc;
37705 +struct au_xi_writing {
37706 + struct hlist_bl_node node;
37707 + ino_t h_ino, ino;
37710 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37713 +static void au_xino_call_do_new_async(void *args)
37715 + struct au_xino_do_new_async_args *a = args;
37716 + struct au_branch *br;
37717 + struct super_block *sb;
37718 + struct au_sbinfo *sbi;
37719 + struct inode *root;
37720 + struct file *file;
37721 + struct au_xi_writing *del, *p;
37722 + struct hlist_bl_head *hbl;
37723 + struct hlist_bl_node *pos;
37728 + sbi = au_sbi(sb);
37729 + si_noflush_read_lock(sb);
37730 + root = d_inode(sb->s_root);
37731 + ii_read_lock_child(root);
37732 + err = au_xino_do_new_async(sb, br, &a->calc);
37733 + if (unlikely(err)) {
37734 + AuIOErr("err %d\n", err);
37738 + file = au_xino_file(br->br_xino, a->calc.idx);
37739 + AuDebugOn(!file);
37740 + err = au_xino_do_write(file, &a->calc, a->ino);
37741 + if (unlikely(err)) {
37742 + AuIOErr("err %d\n", err);
37747 + hbl = &br->br_xino->xi_writing;
37748 + hlist_bl_lock(hbl);
37749 + au_hbl_for_each(pos, hbl) {
37750 + p = container_of(pos, struct au_xi_writing, node);
37751 + if (p->ino == a->ino) {
37753 + hlist_bl_del(&p->node);
37757 + hlist_bl_unlock(hbl);
37758 + au_kfree_rcu(del);
37761 + au_lcnt_dec(&br->br_count);
37762 + ii_read_unlock(root);
37763 + si_read_unlock(sb);
37764 + au_nwt_done(&sbi->si_nowait);
37769 + * create a new xino file asynchronously
37771 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37772 + struct au_xi_calc *calc, ino_t ino)
37775 + struct au_xino_do_new_async_args *arg;
37778 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37779 + if (unlikely(!arg))
37784 + arg->calc = *calc;
37786 + au_lcnt_inc(&br->br_count);
37787 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37788 + if (unlikely(err)) {
37789 + pr_err("wkq %d\n", err);
37790 + au_lcnt_dec(&br->br_count);
37791 + au_kfree_rcu(arg);
37799 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37800 + * at the position of @h_ino.
37802 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37807 + struct au_xi_calc calc;
37808 + struct au_sbinfo *sbinfo;
37809 + struct file *file;
37810 + struct au_xino *xi;
37811 + struct hlist_bl_head *hbl;
37812 + struct hlist_bl_node *pos;
37813 + struct au_xi_writing *p;
37816 + if (!au_opt_test(au_mntflags(sb), XINO))
37817 + return 0; /* no xino */
37820 + au_xi_calc(sb, h_ino, &calc);
37821 + xi = au_sbr(sb, bindex)->br_xino;
37822 + file = au_xino_file(xi, calc.idx);
37824 + hbl = &xi->xi_writing;
37825 + hlist_bl_lock(hbl);
37826 + au_hbl_for_each(pos, hbl) {
37827 + p = container_of(pos, struct au_xi_writing, node);
37828 + if (p->h_ino == h_ino) {
37829 + AuDbg("hi%llu, i%llu, found\n",
37830 + (u64)p->h_ino, (u64)p->ino);
37835 + hlist_bl_unlock(hbl);
37837 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37838 + return 0; /* no xino */
37840 + sbinfo = au_sbi(sb);
37841 + sz = xino_fread(file, ino, sizeof(*ino), &calc.pos);
37842 + if (sz == sizeof(*ino))
37843 + return 0; /* success */
37846 + if (unlikely(sz >= 0)) {
37848 + AuIOErr("xino read error (%zd)\n", sz);
37853 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37858 + sz = xino_fwrite(file, &ino, sizeof(ino), &calc->pos);
37859 + if (sz == sizeof(ino))
37860 + return 0; /* success */
37862 + AuIOErr("write failed (%zd)\n", sz);
37867 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37868 + * at the position of @h_ino.
37869 + * even if @ino is zero, it is written to the xinofile and means no entry.
37870 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37871 + * try truncating it.
37873 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37877 + unsigned int mnt_flags;
37878 + struct au_xi_calc calc;
37879 + struct file *file;
37880 + struct au_branch *br;
37881 + struct au_xino *xi;
37882 + struct au_xi_writing *p;
37884 + SiMustAnyLock(sb);
37886 + mnt_flags = au_mntflags(sb);
37887 + if (!au_opt_test(mnt_flags, XINO))
37890 + au_xi_calc(sb, h_ino, &calc);
37891 + br = au_sbr(sb, bindex);
37892 + xi = br->br_xino;
37893 + file = au_xino_file(xi, calc.idx);
37895 + /* store the inum pair into the list */
37896 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37897 + p->h_ino = h_ino;
37899 + au_hbl_add(&p->node, &xi->xi_writing);
37901 + /* create and write a new xino file asynchronously */
37902 + err = au_xino_new_async(sb, br, &calc, ino);
37904 + return 0; /* success */
37908 + err = au_xino_do_write(file, &calc, ino);
37910 + br = au_sbr(sb, bindex);
37911 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37912 + && au_test_fs_trunc_xino(au_br_sb(br)))
37913 + xino_try_trunc(sb, br);
37914 + return 0; /* success */
37918 + AuIOErr("write failed (%d)\n", err);
37922 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37925 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37926 +ssize_t xino_fread(struct file *file, void *kbuf, size_t size, loff_t *pos)
37930 + const int prevent_endless = 10;
37934 + err = vfsub_read_k(file, kbuf, size, pos);
37935 + if (err == -EINTR
37936 + && !au_wkq_test()
37937 + && fatal_signal_pending(current)) {
37938 + err = xino_fread_wkq(file, kbuf, size, pos);
37939 + BUG_ON(err == -EINTR);
37941 + } while (i++ < prevent_endless
37942 + && (err == -EAGAIN || err == -EINTR));
37944 +#if 0 /* reserved for future use */
37946 + fsnotify_access(file->f_path.dentry);
37952 +struct xino_fread_args {
37954 + struct file *file;
37960 +static void call_xino_fread(void *args)
37962 + struct xino_fread_args *a = args;
37963 + *a->errp = xino_fread(a->file, a->buf, a->size, a->pos);
37966 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37971 + struct xino_fread_args args = {
37979 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37980 + if (unlikely(wkq_err))
37986 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37989 +static ssize_t do_xino_fwrite(struct file *file, void *kbuf, size_t size,
37994 + const int prevent_endless = 10;
37998 + err = vfsub_write_k(file, kbuf, size, pos);
37999 + if (err == -EINTR
38000 + && !au_wkq_test()
38001 + && fatal_signal_pending(current)) {
38002 + err = xino_fwrite_wkq(file, kbuf, size, pos);
38003 + BUG_ON(err == -EINTR);
38005 + } while (i++ < prevent_endless
38006 + && (err == -EAGAIN || err == -EINTR));
38008 +#if 0 /* reserved for future use */
38010 + fsnotify_modify(file->f_path.dentry);
38016 +struct do_xino_fwrite_args {
38018 + struct file *file;
38024 +static void call_do_xino_fwrite(void *args)
38026 + struct do_xino_fwrite_args *a = args;
38027 + *a->errp = do_xino_fwrite(a->file, a->buf, a->size, a->pos);
38030 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
38035 + struct do_xino_fwrite_args args = {
38044 + * it breaks RLIMIT_FSIZE and normal user's limit,
38045 + * users should care about quota and real 'filesystem full.'
38047 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
38048 + if (unlikely(wkq_err))
38054 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos)
38058 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
38060 + err = do_xino_fwrite(file, buf, size, pos);
38064 + err = xino_fwrite_wkq(file, buf, size, pos);
38071 +/* ---------------------------------------------------------------------- */
38074 + * inode number bitmap
38076 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
38077 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
38081 + AuDebugOn(bit < 0 || page_bits <= bit);
38082 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
38086 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
38088 + AuDebugOn(ino < AUFS_FIRST_INO);
38089 + ino -= AUFS_FIRST_INO;
38090 + *pindex = ino / page_bits;
38091 + *bit = ino % page_bits;
38094 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
38099 + struct au_sbinfo *sbinfo;
38100 + struct file *xib;
38101 + unsigned long *p;
38103 + sbinfo = au_sbi(sb);
38104 + MtxMustLock(&sbinfo->si_xib_mtx);
38105 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
38106 + || !au_opt_test(sbinfo->si_mntflags, XINO));
38108 + if (pindex == sbinfo->si_xib_last_pindex)
38111 + xib = sbinfo->si_xib;
38112 + p = sbinfo->si_xib_buf;
38113 + pos = sbinfo->si_xib_last_pindex;
38114 + pos *= PAGE_SIZE;
38115 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
38116 + if (unlikely(sz != PAGE_SIZE))
38120 + pos *= PAGE_SIZE;
38121 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
38122 + sz = xino_fread(xib, p, PAGE_SIZE, &pos);
38124 + memset(p, 0, PAGE_SIZE);
38125 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
38127 + if (sz == PAGE_SIZE) {
38128 + sbinfo->si_xib_last_pindex = pindex;
38129 + return 0; /* success */
38133 + AuIOErr1("write failed (%zd)\n", sz);
38140 +static void au_xib_clear_bit(struct inode *inode)
38143 + unsigned long pindex;
38144 + struct super_block *sb;
38145 + struct au_sbinfo *sbinfo;
38147 + AuDebugOn(inode->i_nlink);
38149 + sb = inode->i_sb;
38150 + xib_calc_bit(inode->i_ino, &pindex, &bit);
38151 + AuDebugOn(page_bits <= bit);
38152 + sbinfo = au_sbi(sb);
38153 + mutex_lock(&sbinfo->si_xib_mtx);
38154 + err = xib_pindex(sb, pindex);
38156 + clear_bit(bit, sbinfo->si_xib_buf);
38157 + sbinfo->si_xib_next_bit = bit;
38159 + mutex_unlock(&sbinfo->si_xib_mtx);
38162 +/* ---------------------------------------------------------------------- */
38165 + * truncate a xino bitmap file
38169 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
38173 + unsigned long pindex;
38174 + loff_t pos, pend;
38175 + struct au_sbinfo *sbinfo;
38177 + unsigned long *p;
38180 + sbinfo = au_sbi(sb);
38181 + MtxMustLock(&sbinfo->si_xib_mtx);
38182 + p = sbinfo->si_xib_buf;
38183 + pend = vfsub_f_size_read(file);
38185 + while (pos < pend) {
38186 + sz = xino_fread(file, page, PAGE_SIZE, &pos);
38188 + if (unlikely(sz <= 0))
38192 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
38193 + if (unlikely(*ino < AUFS_FIRST_INO))
38196 + xib_calc_bit(*ino, &pindex, &bit);
38197 + AuDebugOn(page_bits <= bit);
38198 + err = xib_pindex(sb, pindex);
38210 +static int xib_restore(struct super_block *sb)
38213 + unsigned int nfile;
38214 + aufs_bindex_t bindex, bbot;
38216 + struct au_branch *br;
38217 + struct au_xino *xi;
38218 + struct file *file;
38221 + page = (void *)__get_free_page(GFP_NOFS);
38222 + if (unlikely(!page))
38226 + bbot = au_sbbot(sb);
38227 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38228 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38229 + br = au_sbr(sb, bindex);
38230 + xi = br->br_xino;
38231 + nfile = xi->xi_nfile;
38232 + for (i = 0; i < nfile; i++) {
38233 + file = au_xino_file(xi, i);
38235 + err = do_xib_restore(sb, file, page);
38238 + AuDbg("skip shared b%d\n", bindex);
38239 + free_page((unsigned long)page);
38245 +int au_xib_trunc(struct super_block *sb)
38250 + struct au_sbinfo *sbinfo;
38251 + unsigned long *p;
38252 + struct file *file;
38254 + SiMustWriteLock(sb);
38257 + sbinfo = au_sbi(sb);
38258 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38261 + file = sbinfo->si_xib;
38262 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38265 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38266 + err = PTR_ERR(file);
38267 + if (IS_ERR(file))
38269 + fput(sbinfo->si_xib);
38270 + sbinfo->si_xib = file;
38272 + p = sbinfo->si_xib_buf;
38273 + memset(p, 0, PAGE_SIZE);
38275 + sz = xino_fwrite(sbinfo->si_xib, p, PAGE_SIZE, &pos);
38276 + if (unlikely(sz != PAGE_SIZE)) {
38278 + AuIOErr("err %d\n", err);
38284 + mutex_lock(&sbinfo->si_xib_mtx);
38285 + /* mnt_want_write() is unnecessary here */
38286 + err = xib_restore(sb);
38287 + mutex_unlock(&sbinfo->si_xib_mtx);
38293 +/* ---------------------------------------------------------------------- */
38295 +struct au_xino *au_xino_alloc(unsigned int nfile)
38297 + struct au_xino *xi;
38299 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38300 + if (unlikely(!xi))
38302 + xi->xi_nfile = nfile;
38303 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38304 + if (unlikely(!xi->xi_file))
38307 + xi->xi_nondir.total = 8; /* initial size */
38308 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38310 + if (unlikely(!xi->xi_nondir.array))
38313 + spin_lock_init(&xi->xi_nondir.spin);
38314 + init_waitqueue_head(&xi->xi_nondir.wqh);
38315 + mutex_init(&xi->xi_mtx);
38316 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38317 + atomic_set(&xi->xi_truncating, 0);
38318 + kref_init(&xi->xi_kref);
38319 + goto out; /* success */
38322 + au_kfree_try_rcu(xi->xi_file);
38324 + au_kfree_rcu(xi);
38330 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38333 + struct au_xino *xi;
38336 + xi = au_xino_alloc(idx + 1);
38337 + if (unlikely(!xi)) {
38344 + xi->xi_file[idx] = file;
38345 + AuDebugOn(br->br_xino);
38346 + br->br_xino = xi;
38352 +static void au_xino_release(struct kref *kref)
38354 + struct au_xino *xi;
38356 + unsigned long ul;
38357 + struct hlist_bl_head *hbl;
38358 + struct hlist_bl_node *pos, *n;
38359 + struct au_xi_writing *p;
38361 + xi = container_of(kref, struct au_xino, xi_kref);
38362 + for (i = 0; i < xi->xi_nfile; i++)
38363 + if (xi->xi_file[i])
38364 + fput(xi->xi_file[i]);
38365 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38366 + AuDebugOn(xi->xi_nondir.array[i]);
38367 + mutex_destroy(&xi->xi_mtx);
38368 + hbl = &xi->xi_writing;
38369 + ul = au_hbl_count(hbl);
38370 + if (unlikely(ul)) {
38371 + pr_warn("xi_writing %lu\n", ul);
38372 + hlist_bl_lock(hbl);
38373 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
38374 + hlist_bl_del(&p->node);
38375 + /* kmemleak reported au_kfree_rcu() doesn't free it */
38378 + hlist_bl_unlock(hbl);
38380 + au_kfree_try_rcu(xi->xi_file);
38381 + au_kfree_try_rcu(xi->xi_nondir.array);
38382 + au_kfree_rcu(xi);
38385 +int au_xino_put(struct au_branch *br)
38388 + struct au_xino *xi;
38391 + xi = br->br_xino;
38393 + br->br_xino = NULL;
38394 + ret = kref_put(&xi->xi_kref, au_xino_release);
38400 +/* ---------------------------------------------------------------------- */
38403 + * xino mount option handlers
38407 +static void xino_clear_xib(struct super_block *sb)
38409 + struct au_sbinfo *sbinfo;
38411 + SiMustWriteLock(sb);
38413 + sbinfo = au_sbi(sb);
38414 + if (sbinfo->si_xib)
38415 + fput(sbinfo->si_xib);
38416 + sbinfo->si_xib = NULL;
38417 + if (sbinfo->si_xib_buf)
38418 + free_page((unsigned long)sbinfo->si_xib_buf);
38419 + sbinfo->si_xib_buf = NULL;
38422 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38426 + struct au_sbinfo *sbinfo;
38427 + struct file *file;
38428 + struct super_block *xi_sb;
38430 + SiMustWriteLock(sb);
38432 + sbinfo = au_sbi(sb);
38433 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38434 + err = PTR_ERR(file);
38435 + if (IS_ERR(file))
38437 + if (sbinfo->si_xib)
38438 + fput(sbinfo->si_xib);
38439 + sbinfo->si_xib = file;
38440 + xi_sb = file_inode(file)->i_sb;
38441 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38442 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38444 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38445 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38448 + sbinfo->si_ximaxent /= sizeof(ino_t);
38451 + if (!sbinfo->si_xib_buf)
38452 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38453 + if (unlikely(!sbinfo->si_xib_buf))
38456 + sbinfo->si_xib_last_pindex = 0;
38457 + sbinfo->si_xib_next_bit = 0;
38458 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38460 + err = xino_fwrite(file, sbinfo->si_xib_buf, PAGE_SIZE, &pos);
38461 + if (unlikely(err != PAGE_SIZE))
38465 + goto out; /* success */
38468 + if (sbinfo->si_xib_buf)
38469 + free_page((unsigned long)sbinfo->si_xib_buf);
38470 + sbinfo->si_xib_buf = NULL;
38474 + fput(sbinfo->si_xib);
38475 + sbinfo->si_xib = NULL;
38481 +/* xino for each branch */
38482 +static void xino_clear_br(struct super_block *sb)
38484 + aufs_bindex_t bindex, bbot;
38485 + struct au_branch *br;
38487 + bbot = au_sbbot(sb);
38488 + for (bindex = 0; bindex <= bbot; bindex++) {
38489 + br = au_sbr(sb, bindex);
38495 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38496 + aufs_bindex_t bshared)
38498 + struct au_branch *brshared;
38500 + brshared = au_sbr(sb, bshared);
38501 + AuDebugOn(!brshared->br_xino);
38502 + AuDebugOn(!brshared->br_xino->xi_file);
38503 + if (br->br_xino != brshared->br_xino) {
38504 + au_xino_get(brshared);
38506 + br->br_xino = brshared->br_xino;
38510 +struct au_xino_do_set_br {
38511 + struct au_branch *br;
38513 + aufs_bindex_t bshared;
38516 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38517 + struct au_xino_do_set_br *args)
38520 + struct au_xi_calc calc;
38521 + struct file *file;
38522 + struct au_branch *br;
38523 + struct au_xi_new xinew = {
38528 + xinew.xi = br->br_xino;
38529 + au_xi_calc(sb, args->h_ino, &calc);
38530 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38531 + if (args->bshared >= 0)
38532 + /* shared xino */
38533 + au_xino_set_br_shared(sb, br, args->bshared);
38534 + else if (!xinew.xi) {
38536 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38537 + if (unlikely(err))
38541 + /* force re-creating */
38542 + xinew.xi = br->br_xino;
38543 + xinew.idx = calc.idx;
38544 + mutex_lock(&xinew.xi->xi_mtx);
38545 + file = au_xi_new(sb, &xinew);
38546 + mutex_unlock(&xinew.xi->xi_mtx);
38547 + err = PTR_ERR(file);
38548 + if (IS_ERR(file))
38550 + AuDebugOn(!file);
38552 + err = au_xino_do_write(file, &calc, AUFS_ROOT_INO);
38553 + if (unlikely(err))
38561 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38564 + aufs_bindex_t bindex, bbot;
38565 + struct au_xino_do_set_br args;
38566 + struct inode *inode;
38568 + SiMustWriteLock(sb);
38570 + bbot = au_sbbot(sb);
38571 + inode = d_inode(sb->s_root);
38572 + for (bindex = 0; bindex <= bbot; bindex++) {
38573 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38574 + args.br = au_sbr(sb, bindex);
38575 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38576 + err = au_xino_do_set_br(sb, path, &args);
38577 + if (unlikely(err))
38585 +void au_xino_clr(struct super_block *sb)
38587 + struct au_sbinfo *sbinfo;
38589 + au_xigen_clr(sb);
38590 + xino_clear_xib(sb);
38591 + xino_clear_br(sb);
38592 + dbgaufs_brs_del(sb, 0);
38593 + sbinfo = au_sbi(sb);
38594 + /* lvalue, do not call au_mntflags() */
38595 + au_opt_clr(sbinfo->si_mntflags, XINO);
38598 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38601 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38602 + struct qstr *dname, *cur_name;
38603 + struct file *cur_xino;
38604 + struct au_sbinfo *sbinfo;
38605 + struct path *path, *cur_path;
38607 + SiMustWriteLock(sb);
38610 + sbinfo = au_sbi(sb);
38611 + path = &xiopt->file->f_path;
38612 + dentry = path->dentry;
38613 + parent = dget_parent(dentry);
38616 + cur_xino = sbinfo->si_xib;
38618 + cur_path = &cur_xino->f_path;
38619 + cur_dentry = cur_path->dentry;
38620 + cur_parent = dget_parent(cur_dentry);
38621 + cur_name = &cur_dentry->d_name;
38622 + dname = &dentry->d_name;
38623 + skip = (cur_parent == parent
38624 + && au_qstreq(dname, cur_name));
38625 + dput(cur_parent);
38631 + au_opt_set(sbinfo->si_mntflags, XINO);
38632 + err = au_xino_set_xib(sb, path);
38633 + /* si_x{read,write} are set */
38635 + err = au_xigen_set(sb, path);
38637 + err = au_xino_set_br(sb, path);
38639 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38640 + goto out; /* success */
38644 + AuIOErr("failed setting xino(%d).\n", err);
38653 + * create a xinofile at the default place/path.
38655 +struct file *au_xino_def(struct super_block *sb)
38657 + struct file *file;
38659 + struct au_branch *br;
38660 + struct super_block *h_sb;
38661 + struct path path;
38662 + aufs_bindex_t bbot, bindex, bwr;
38665 + bbot = au_sbbot(sb);
38667 + for (bindex = 0; bindex <= bbot; bindex++) {
38668 + br = au_sbr(sb, bindex);
38669 + if (au_br_writable(br->br_perm)
38670 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38677 + file = ERR_PTR(-ENOMEM);
38678 + page = (void *)__get_free_page(GFP_NOFS);
38679 + if (unlikely(!page))
38681 + path.mnt = au_br_mnt(br);
38682 + path.dentry = au_h_dptr(sb->s_root, bwr);
38683 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38684 + file = (void *)p;
38685 + if (!IS_ERR(p)) {
38686 + strcat(p, "/" AUFS_XINO_FNAME);
38687 + AuDbg("%s\n", p);
38688 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38690 + free_page((unsigned long)page);
38692 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38694 + if (IS_ERR(file))
38696 + h_sb = file->f_path.dentry->d_sb;
38697 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38698 + pr_err("xino doesn't support %s(%s)\n",
38699 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38701 + file = ERR_PTR(-EINVAL);
38709 +/* ---------------------------------------------------------------------- */
38712 + * initialize the xinofile for the specified branch @br
38713 + * at the place/path where @base_file indicates.
38714 + * test whether another branch is on the same filesystem or not,
38715 + * if found then share the xinofile with another branch.
38717 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38718 + struct path *base)
38721 + struct au_xino_do_set_br args = {
38726 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38728 + err = au_xino_do_set_br(sb, base, &args);
38729 + if (unlikely(err))
38735 +/* ---------------------------------------------------------------------- */
38738 + * get an unused inode number from bitmap
38740 +ino_t au_xino_new_ino(struct super_block *sb)
38743 + unsigned long *p, pindex, ul, pend;
38744 + struct au_sbinfo *sbinfo;
38745 + struct file *file;
38746 + int free_bit, err;
38748 + if (!au_opt_test(au_mntflags(sb), XINO))
38749 + return iunique(sb, AUFS_FIRST_INO);
38751 + sbinfo = au_sbi(sb);
38752 + mutex_lock(&sbinfo->si_xib_mtx);
38753 + p = sbinfo->si_xib_buf;
38754 + free_bit = sbinfo->si_xib_next_bit;
38755 + if (free_bit < page_bits && !test_bit(free_bit, p))
38756 + goto out; /* success */
38757 + free_bit = find_first_zero_bit(p, page_bits);
38758 + if (free_bit < page_bits)
38759 + goto out; /* success */
38761 + pindex = sbinfo->si_xib_last_pindex;
38762 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38763 + err = xib_pindex(sb, ul);
38764 + if (unlikely(err))
38766 + free_bit = find_first_zero_bit(p, page_bits);
38767 + if (free_bit < page_bits)
38768 + goto out; /* success */
38771 + file = sbinfo->si_xib;
38772 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38773 + for (ul = pindex + 1; ul <= pend; ul++) {
38774 + err = xib_pindex(sb, ul);
38775 + if (unlikely(err))
38777 + free_bit = find_first_zero_bit(p, page_bits);
38778 + if (free_bit < page_bits)
38779 + goto out; /* success */
38784 + set_bit(free_bit, p);
38785 + sbinfo->si_xib_next_bit = free_bit + 1;
38786 + pindex = sbinfo->si_xib_last_pindex;
38787 + mutex_unlock(&sbinfo->si_xib_mtx);
38788 + ino = xib_calc_ino(pindex, free_bit);
38789 + AuDbg("i%lu\n", (unsigned long)ino);
38792 + mutex_unlock(&sbinfo->si_xib_mtx);
38797 +/* for s_op->delete_inode() */
38798 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38801 + unsigned int mnt_flags;
38802 + aufs_bindex_t bindex, bbot, bi;
38803 + unsigned char try_trunc;
38804 + struct au_iinfo *iinfo;
38805 + struct super_block *sb;
38806 + struct au_hinode *hi;
38807 + struct inode *h_inode;
38808 + struct au_branch *br;
38809 + struct au_xi_calc calc;
38810 + struct file *file;
38812 + AuDebugOn(au_is_bad_inode(inode));
38814 + sb = inode->i_sb;
38815 + mnt_flags = au_mntflags(sb);
38816 + if (!au_opt_test(mnt_flags, XINO)
38817 + || inode->i_ino == AUFS_ROOT_INO)
38821 + au_xigen_inc(inode);
38822 + au_xib_clear_bit(inode);
38825 + iinfo = au_ii(inode);
38826 + bindex = iinfo->ii_btop;
38830 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38831 + hi = au_hinode(iinfo, bindex);
38832 + bbot = iinfo->ii_bbot;
38833 + for (; bindex <= bbot; bindex++, hi++) {
38834 + h_inode = hi->hi_inode;
38836 + || (!unlinked && h_inode->i_nlink))
38839 + /* inode may not be revalidated */
38840 + bi = au_br_index(sb, hi->hi_id);
38844 + br = au_sbr(sb, bi);
38845 + au_xi_calc(sb, h_inode->i_ino, &calc);
38846 + file = au_xino_file(br->br_xino, calc.idx);
38847 + if (IS_ERR_OR_NULL(file))
38850 + err = au_xino_do_write(file, &calc, /*ino*/0);
38851 + if (!err && try_trunc
38852 + && au_test_fs_trunc_xino(au_br_sb(br)))
38853 + xino_try_trunc(sb, br);
38857 +/* ---------------------------------------------------------------------- */
38859 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38861 + int found, total, i;
38864 + total = xi->xi_nondir.total;
38865 + for (i = 0; i < total; i++) {
38866 + if (xi->xi_nondir.array[i] != h_ino)
38875 +static int au_xinondir_expand(struct au_xino *xi)
38880 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38883 + sz = xi->xi_nondir.total * sizeof(ino_t);
38884 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38886 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38887 + /*may_shrink*/0);
38889 + xi->xi_nondir.array = p;
38890 + xi->xi_nondir.total <<= 1;
38891 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38899 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38900 + ino_t h_ino, int idx)
38902 + struct au_xino *xi;
38904 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38905 + xi = au_sbr(sb, bindex)->br_xino;
38906 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38908 + spin_lock(&xi->xi_nondir.spin);
38909 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38910 + xi->xi_nondir.array[idx] = 0;
38911 + spin_unlock(&xi->xi_nondir.spin);
38912 + wake_up_all(&xi->xi_nondir.wqh);
38915 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38918 + int err, found, empty;
38919 + struct au_xino *xi;
38923 + if (!au_opt_test(au_mntflags(sb), XINO))
38924 + goto out; /* no xino */
38926 + xi = au_sbr(sb, bindex)->br_xino;
38929 + spin_lock(&xi->xi_nondir.spin);
38930 + found = au_xinondir_find(xi, h_ino);
38931 + if (found == -1) {
38932 + empty = au_xinondir_find(xi, /*h_ino*/0);
38933 + if (empty == -1) {
38934 + empty = xi->xi_nondir.total;
38935 + err = au_xinondir_expand(xi);
38936 + if (unlikely(err))
38939 + xi->xi_nondir.array[empty] = h_ino;
38942 + spin_unlock(&xi->xi_nondir.spin);
38943 + wait_event(xi->xi_nondir.wqh,
38944 + xi->xi_nondir.array[found] != h_ino);
38949 + spin_unlock(&xi->xi_nondir.spin);
38954 +/* ---------------------------------------------------------------------- */
38956 +int au_xino_path(struct seq_file *seq, struct file *file)
38960 + err = au_seq_path(seq, &file->f_path);
38961 + if (unlikely(err))
38964 +#define Deleted "\\040(deleted)"
38965 + seq->count -= sizeof(Deleted) - 1;
38966 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38967 + sizeof(Deleted) - 1));
38973 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38974 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38975 +++ linux/include/uapi/linux/aufs_type.h 2022-11-05 23:02:18.972555950 +0100
38977 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
38979 + * Copyright (C) 2005-2022 Junjiro R. Okajima
38981 + * This program is free software; you can redistribute it and/or modify
38982 + * it under the terms of the GNU General Public License as published by
38983 + * the Free Software Foundation; either version 2 of the License, or
38984 + * (at your option) any later version.
38986 + * This program is distributed in the hope that it will be useful,
38987 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38988 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38989 + * GNU General Public License for more details.
38991 + * You should have received a copy of the GNU General Public License
38992 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38995 +#ifndef __AUFS_TYPE_H__
38996 +#define __AUFS_TYPE_H__
38998 +#define AUFS_NAME "aufs"
39002 + * define it before including all other headers.
39003 + * sched.h may use pr_* macros before defining "current", so define the
39004 + * no-current version first, and re-define later.
39006 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
39007 +#include <linux/sched.h>
39009 +#define pr_fmt(fmt) \
39010 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
39011 + (int)sizeof(current->comm), current->comm, current->pid
39012 +#include <linux/limits.h>
39014 +#include <stdint.h>
39015 +#include <sys/types.h>
39016 +#include <limits.h>
39017 +#endif /* __KERNEL__ */
39019 +#define AUFS_VERSION "6.0-20221031"
39021 +/* todo? move this to linux-2.6.19/include/magic.h */
39022 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
39024 +/* ---------------------------------------------------------------------- */
39027 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
39028 +typedef int8_t aufs_bindex_t;
39029 +#define AUFS_BRANCH_MAX 127
39031 +typedef int16_t aufs_bindex_t;
39032 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
39033 +#define AUFS_BRANCH_MAX 511
39034 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
39035 +#define AUFS_BRANCH_MAX 1023
39036 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
39037 +#define AUFS_BRANCH_MAX 32767
39041 +#ifndef AUFS_BRANCH_MAX
39042 +#error unknown CONFIG_AUFS_BRANCH_MAX value
39044 +#endif /* __KERNEL__ */
39046 +/* ---------------------------------------------------------------------- */
39048 +#define AUFS_FSTYPE AUFS_NAME
39050 +#define AUFS_ROOT_INO 2
39051 +#define AUFS_FIRST_INO 11
39053 +#define AUFS_WH_PFX ".wh."
39054 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
39055 +#define AUFS_WH_TMP_LEN 4
39056 +/* a limit for rmdir/rename a dir and copyup */
39057 +#define AUFS_MAX_NAMELEN (NAME_MAX \
39058 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
39060 + - AUFS_WH_TMP_LEN) /* hex */
39061 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
39062 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
39063 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
39064 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
39065 +#define AUFS_DIRWH_DEF 3
39066 +#define AUFS_RDCACHE_DEF 10 /* seconds */
39067 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
39068 +#define AUFS_RDBLK_DEF 512 /* bytes */
39069 +#define AUFS_RDHASH_DEF 32
39070 +#define AUFS_WKQ_NAME AUFS_NAME "d"
39071 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
39072 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
39073 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
39074 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
39076 +/* pseudo-link maintenace under /proc */
39077 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
39078 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
39079 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
39081 +/* dirren, renamed dir */
39082 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
39083 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
39084 +/* whiteouted doubly */
39085 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
39086 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
39088 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
39089 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
39091 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
39092 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
39093 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
39095 +/* doubly whiteouted */
39096 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
39097 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
39098 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
39100 +/* branch permissions and attributes */
39101 +#define AUFS_BRPERM_RW "rw"
39102 +#define AUFS_BRPERM_RO "ro"
39103 +#define AUFS_BRPERM_RR "rr"
39104 +#define AUFS_BRATTR_COO_REG "coo_reg"
39105 +#define AUFS_BRATTR_COO_ALL "coo_all"
39106 +#define AUFS_BRATTR_FHSM "fhsm"
39107 +#define AUFS_BRATTR_UNPIN "unpin"
39108 +#define AUFS_BRATTR_ICEX "icex"
39109 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
39110 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
39111 +#define AUFS_BRATTR_ICEX_TR "icextr"
39112 +#define AUFS_BRATTR_ICEX_USR "icexusr"
39113 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
39114 +#define AUFS_BRRATTR_WH "wh"
39115 +#define AUFS_BRWATTR_NLWH "nolwh"
39116 +#define AUFS_BRWATTR_MOO "moo"
39118 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
39119 +#define AuBrPerm_RO (1 << 1) /* readonly */
39120 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
39121 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
39123 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
39124 +#define AuBrAttr_COO_ALL (1 << 4)
39125 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
39127 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
39128 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
39129 + branch. meaningless since
39130 + linux-3.18-rc1 */
39132 +/* ignore error in copying XATTR */
39133 +#define AuBrAttr_ICEX_SEC (1 << 7)
39134 +#define AuBrAttr_ICEX_SYS (1 << 8)
39135 +#define AuBrAttr_ICEX_TR (1 << 9)
39136 +#define AuBrAttr_ICEX_USR (1 << 10)
39137 +#define AuBrAttr_ICEX_OTH (1 << 11)
39138 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
39139 + | AuBrAttr_ICEX_SYS \
39140 + | AuBrAttr_ICEX_TR \
39141 + | AuBrAttr_ICEX_USR \
39142 + | AuBrAttr_ICEX_OTH)
39144 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
39145 +#define AuBrRAttr_Mask AuBrRAttr_WH
39147 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
39148 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
39149 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
39151 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
39153 +/* #warning test userspace */
39155 +#ifndef CONFIG_AUFS_FHSM
39156 +#undef AuBrAttr_FHSM
39157 +#define AuBrAttr_FHSM 0
39159 +#ifndef CONFIG_AUFS_XATTR
39160 +#undef AuBrAttr_ICEX
39161 +#define AuBrAttr_ICEX 0
39162 +#undef AuBrAttr_ICEX_SEC
39163 +#define AuBrAttr_ICEX_SEC 0
39164 +#undef AuBrAttr_ICEX_SYS
39165 +#define AuBrAttr_ICEX_SYS 0
39166 +#undef AuBrAttr_ICEX_TR
39167 +#define AuBrAttr_ICEX_TR 0
39168 +#undef AuBrAttr_ICEX_USR
39169 +#define AuBrAttr_ICEX_USR 0
39170 +#undef AuBrAttr_ICEX_OTH
39171 +#define AuBrAttr_ICEX_OTH 0
39175 +/* the longest combination */
39176 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
39177 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
39178 + "+" AUFS_BRATTR_COO_REG \
39179 + "+" AUFS_BRATTR_FHSM \
39180 + "+" AUFS_BRATTR_UNPIN \
39181 + "+" AUFS_BRATTR_ICEX_SEC \
39182 + "+" AUFS_BRATTR_ICEX_SYS \
39183 + "+" AUFS_BRATTR_ICEX_USR \
39184 + "+" AUFS_BRATTR_ICEX_OTH \
39185 + "+" AUFS_BRWATTR_NLWH)
39188 + char a[AuBrPermStrSz];
39189 +} au_br_perm_str_t;
39191 +static inline int au_br_writable(int brperm)
39193 + return brperm & AuBrPerm_RW;
39196 +static inline int au_br_whable(int brperm)
39198 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
39201 +static inline int au_br_wh_linkable(int brperm)
39203 + return !(brperm & AuBrWAttr_NoLinkWH);
39206 +static inline int au_br_cmoo(int brperm)
39208 + return brperm & AuBrAttr_CMOO_Mask;
39211 +static inline int au_br_fhsm(int brperm)
39213 + return brperm & AuBrAttr_FHSM;
39216 +/* ---------------------------------------------------------------------- */
39220 + /* readdir in userspace */
39224 + AuCtl_WBR_FD, /* pathconf wrapper */
39225 + AuCtl_IBUSY, /* busy inode */
39226 + AuCtl_MVDOWN, /* move-down */
39227 + AuCtl_BR, /* info about branches */
39228 + AuCtl_FHSM_FD /* connection for fhsm */
39231 +/* borrowed from linux/include/linux/kernel.h */
39233 +#ifdef _GNU_SOURCE
39234 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39236 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
39238 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39241 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39243 +#define __aligned(x) __attribute__((aligned(x)))
39248 +#define __packed __attribute__((packed))
39252 +struct au_rdu_cookie {
39257 + uint32_t generation;
39260 +struct au_rdu_ent {
39269 +static inline int au_rdu_len(int nlen)
39271 + /* include the terminating NULL */
39272 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39273 + sizeof(uint64_t));
39276 +union au_rdu_ent_ul {
39277 + struct au_rdu_ent __user *e;
39289 + uint64_t sz; /* AuCtl_RDU */
39290 + uint64_t nent; /* AuCtl_RDU_INO */
39292 + union au_rdu_ent_ul ent;
39293 + uint16_t verify[AufsCtlRduV_End];
39295 + /* input/output */
39299 + union au_rdu_ent_ul tail;
39300 + /* number of entries which were added in a single call */
39305 + struct au_rdu_cookie cookie;
39308 +/* ---------------------------------------------------------------------- */
39310 +/* dirren. the branch is identified by the filename who contains this */
39311 +struct au_drinfo {
39314 + uint8_t oldnamelen;
39315 + uint64_t _padding;
39317 + uint8_t oldname[];
39320 +struct au_drinfo_fdata {
39322 + struct au_drinfo drinfo;
39325 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39327 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39329 +/* ---------------------------------------------------------------------- */
39331 +struct aufs_wbr_fd {
39336 +/* ---------------------------------------------------------------------- */
39338 +struct aufs_ibusy {
39339 + uint64_t ino, h_ino;
39343 +/* ---------------------------------------------------------------------- */
39345 +/* error code for move-down */
39346 +/* the actual message strings are implemented in aufs-util.git */
39348 + EAU_MVDOWN_OPAQUE = 1,
39349 + EAU_MVDOWN_WHITEOUT,
39350 + EAU_MVDOWN_UPPER,
39351 + EAU_MVDOWN_BOTTOM,
39352 + EAU_MVDOWN_NOUPPER,
39353 + EAU_MVDOWN_NOLOWERBR,
39357 +/* flags for move-down */
39358 +#define AUFS_MVDOWN_DMSG 1
39359 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39360 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39361 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39362 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39363 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39364 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39365 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39366 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39367 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39368 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39369 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39370 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39372 +/* index for move-down */
39374 + AUFS_MVDOWN_UPPER,
39375 + AUFS_MVDOWN_LOWER,
39376 + AUFS_MVDOWN_NARRAY
39380 + * additional info of move-down
39381 + * number of free blocks and inodes.
39382 + * subset of struct kstatfs, but smaller and always 64bit.
39384 +struct aufs_stfs {
39385 + uint64_t f_blocks;
39386 + uint64_t f_bavail;
39387 + uint64_t f_files;
39388 + uint64_t f_ffree;
39391 +struct aufs_stbr {
39392 + int16_t brid; /* optional input */
39393 + int16_t bindex; /* output */
39394 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39397 +struct aufs_mvdown {
39398 + uint32_t flags; /* input/output */
39399 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39400 + int8_t au_errno; /* output */
39403 +/* ---------------------------------------------------------------------- */
39405 +union aufs_brinfo {
39406 + /* PATH_MAX may differ between kernel-space and user-space */
39407 + char _spacer[4096];
39415 +/* ---------------------------------------------------------------------- */
39417 +#define AuCtlType 'A'
39418 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39419 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39420 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39421 + struct aufs_wbr_fd)
39422 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39423 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39424 + struct aufs_mvdown)
39425 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39426 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39428 +#endif /* __AUFS_TYPE_H__ */
39429 SPDX-License-Identifier: GPL-2.0
39430 aufs6.0 loopback patch
39432 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39433 index 8ca56da3ca69..9ac6f67edf09 100644
39434 --- a/drivers/block/loop.c
39435 +++ b/drivers/block/loop.c
39436 @@ -54,7 +54,7 @@ struct loop_device {
39438 char lo_file_name[LO_NAME_SIZE];
39440 - struct file * lo_backing_file;
39441 + struct file *lo_backing_file, *lo_backing_virt_file;
39442 struct block_device *lo_device;
39444 gfp_t old_gfp_mask;
39445 @@ -510,6 +510,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39449 +static struct file *loop_real_file(struct file *file)
39451 + struct file *f = NULL;
39453 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39454 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39458 static void loop_reread_partitions(struct loop_device *lo)
39461 @@ -567,6 +576,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39463 struct file *file = fget(arg);
39464 struct file *old_file;
39465 + struct file *f, *virt_file = NULL, *old_virt_file;
39469 @@ -590,11 +600,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39470 if (!(lo->lo_flags & LO_FLAGS_READ_ONLY))
39473 + f = loop_real_file(file);
39475 + virt_file = file;
39480 error = loop_validate_file(file, bdev);
39484 old_file = lo->lo_backing_file;
39485 + old_virt_file = lo->lo_backing_virt_file;
39489 @@ -607,6 +625,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39490 blk_mq_freeze_queue(lo->lo_queue);
39491 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39492 lo->lo_backing_file = file;
39493 + lo->lo_backing_virt_file = virt_file;
39494 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39495 mapping_set_gfp_mask(file->f_mapping,
39496 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39497 @@ -629,6 +648,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39501 + if (old_virt_file)
39502 + fput(old_virt_file);
39504 loop_reread_partitions(lo);
39506 @@ -642,6 +663,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39507 loop_global_unlock(lo, is_loop);
39515 @@ -1013,6 +1036,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39516 const struct loop_config *config)
39518 struct file *file = fget(config->fd);
39519 + struct file *f, *virt_file = NULL;
39520 struct inode *inode;
39521 struct address_space *mapping;
39523 @@ -1031,6 +1055,13 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39524 /* suppress uevents while reconfiguring the device */
39525 dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 1);
39527 + f = loop_real_file(file);
39529 + virt_file = file;
39535 * If we don't hold exclusive handle for the device, upgrade to it
39536 * here to avoid changing device under exclusive owner.
39537 @@ -1091,6 +1122,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39538 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39539 lo->lo_device = bdev;
39540 lo->lo_backing_file = file;
39541 + lo->lo_backing_virt_file = virt_file;
39542 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39543 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39545 @@ -1146,6 +1178,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39546 bd_abort_claiming(bdev, loop_configure);
39551 /* This is safe: open() is still holding a reference. */
39552 module_put(THIS_MODULE);
39554 @@ -1154,6 +1188,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39555 static void __loop_clr_fd(struct loop_device *lo, bool release)
39558 + struct file *virt_filp = lo->lo_backing_virt_file;
39559 gfp_t gfp = lo->old_gfp_mask;
39561 if (test_bit(QUEUE_FLAG_WC, &lo->lo_queue->queue_flags))
39562 @@ -1170,6 +1205,7 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
39563 spin_lock_irq(&lo->lo_lock);
39564 filp = lo->lo_backing_file;
39565 lo->lo_backing_file = NULL;
39566 + lo->lo_backing_virt_file = NULL;
39567 spin_unlock_irq(&lo->lo_lock);
39569 lo->lo_device = NULL;
39570 @@ -1232,6 +1268,8 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
39571 * fput can take open_mutex which is usually taken before lo_mutex.
39578 static int loop_clr_fd(struct loop_device *lo)
39579 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39580 index 5c5641222d67..79504ea71dad 100644
39581 --- a/fs/aufs/f_op.c
39582 +++ b/fs/aufs/f_op.c
39583 @@ -304,7 +304,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39584 if (IS_ERR(h_file))
39587 - if (au_test_loopback_kthread()) {
39588 + if (0 && au_test_loopback_kthread()) {
39589 au_warn_loopback(h_file->f_path.dentry->d_sb);
39590 if (file->f_mapping != h_file->f_mapping) {
39591 file->f_mapping = h_file->f_mapping;
39592 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39593 index 58043e31e5f3..e2bfae6f9d59 100644
39594 --- a/fs/aufs/loop.c
39595 +++ b/fs/aufs/loop.c
39596 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39597 symbol_put(loop_backing_file);
39598 au_kfree_try_rcu(au_warn_loopback_array);
39601 +/* ---------------------------------------------------------------------- */
39603 +/* support the loopback block device insude aufs */
39605 +struct file *aufs_real_loop(struct file *file)
39609 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39610 + fi_read_lock(file);
39611 + f = au_hf_top(file);
39612 + fi_read_unlock(file);
39616 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39617 index 03d4908a6c03..34d356e181d5 100644
39618 --- a/fs/aufs/loop.h
39619 +++ b/fs/aufs/loop.h
39620 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39622 int au_loopback_init(void);
39623 void au_loopback_fin(void);
39625 +struct file *aufs_real_loop(struct file *file);
39627 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39629 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39631 AuStubInt0(au_loopback_init, void)
39632 AuStubVoid(au_loopback_fin, void)
39634 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39635 #endif /* BLK_DEV_LOOP */
39637 #endif /* __KERNEL__ */
39638 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39639 index 81922d4faf54..c8a62c267d72 100644
39640 --- a/fs/aufs/super.c
39641 +++ b/fs/aufs/super.c
39642 @@ -758,7 +758,10 @@ const struct super_operations aufs_sop = {
39643 .show_options = aufs_show_options,
39644 .statfs = aufs_statfs,
39645 .put_super = aufs_put_super,
39646 - .sync_fs = aufs_sync_fs
39647 + .sync_fs = aufs_sync_fs,
39648 +#ifdef CONFIG_AUFS_BDEV_LOOP
39649 + .real_loop = aufs_real_loop
39653 /* ---------------------------------------------------------------------- */
39654 diff --git a/include/linux/fs.h b/include/linux/fs.h
39655 index 9c5a33fce3a8..a3c40bc66852 100644
39656 --- a/include/linux/fs.h
39657 +++ b/include/linux/fs.h
39658 @@ -2253,6 +2253,10 @@ struct super_operations {
39659 struct shrink_control *);
39660 long (*free_cached_objects)(struct super_block *,
39661 struct shrink_control *);
39662 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39664 + struct file *(*real_loop)(struct file *);