1 SPDX-License-Identifier: GPL-2.0
2 aufs6.x-rcN kbuild patch
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index 2685a4d0d353..a2df3d4bb3aa 100644
8 @@ -319,6 +319,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 4dea17840761..9795cbfdd0bf 100644
20 @@ -137,3 +137,4 @@ obj-$(CONFIG_EFIVAR_FS) += efivarfs/
21 obj-$(CONFIG_EROFS_FS) += erofs/
22 obj-$(CONFIG_VBOXSF_FS) += vboxsf/
23 obj-$(CONFIG_ZONEFS_FS) += zonefs/
24 +obj-$(CONFIG_AUFS_FS) += aufs/
25 SPDX-License-Identifier: GPL-2.0
26 aufs6.x-rcN base patch
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index 379945f82a64..b3b8fbca497b 100644
32 @@ -3455,6 +3455,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 52e6d5fdab6b..519321f32f95 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 e654435f1651..433a4f08dab4 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 @@ -2117,6 +2118,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 e3375bc40dad..c1f0aadde539 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
251 aufs6.x-rcN mmap patch
253 diff --git a/fs/proc/base.c b/fs/proc/base.c
254 index 9e479d7d202b..986c2ae12f8b 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 8a74cdcc9af0..c05071b53f5b 100644
284 --- a/fs/proc/task_mmu.c
285 +++ b/fs/proc/task_mmu.c
286 @@ -284,7 +284,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 @@ -1934,7 +1937,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 2fd06f52b6a4..b01030da424f 100644
309 --- a/fs/proc/task_nommu.c
310 +++ b/fs/proc/task_nommu.c
311 @@ -150,7 +150,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 8bbcccbc5565..d5006a1f4271 100644
325 --- a/include/linux/mm.h
326 +++ b/include/linux/mm.h
327 @@ -1933,6 +1933,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 500e536796ca..ad766e2110ca 100644
373 --- a/include/linux/mm_types.h
374 +++ b/include/linux/mm_types.h
375 @@ -413,6 +413,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 @@ -494,6 +497,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 08969f5aa38d..61871700033a 100644
399 @@ -661,7 +661,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 8e105e5b3e29..c218d042dbce 100644
412 @@ -138,3 +138,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 08341616ae7a..410ca60fbf39 100644
421 @@ -3418,7 +3418,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 2def55555e05..fefc5c67e96e 100644
434 @@ -139,7 +139,7 @@ static void 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 @@ -590,7 +590,7 @@ inline int vma_expand(struct ma_state *mas, struct vm_area_struct *vma,
446 uprobe_munmap(next, next->vm_start, next->vm_end);
451 anon_vma_merge(vma, next);
452 @@ -831,7 +831,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
455 uprobe_munmap(next, next->vm_start, next->vm_end);
460 anon_vma_merge(vma, next);
461 @@ -2228,7 +2228,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 @@ -2250,7 +2250,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 @@ -2746,7 +2746,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
480 if (vma->vm_ops && vma->vm_ops->close)
481 vma->vm_ops->close(vma);
483 - fput(vma->vm_file);
487 /* Undo any partial mapping done by a device driver. */
488 @@ -2813,6 +2813,9 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
489 unsigned long populate = 0;
490 unsigned long ret = -EINVAL;
492 +#if IS_ENABLED(CONFIG_AUFS_FS)
493 + struct file *prfile;
496 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/mm/remap_file_pages.rst.\n",
497 current->comm, current->pid);
498 @@ -2871,10 +2874,34 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
499 if (vma->vm_flags & VM_LOCKED)
502 +#if IS_ENABLED(CONFIG_AUFS_FS)
504 + file = vma->vm_file;
505 + prfile = vma->vm_prfile;
506 + ret = do_mmap(vma->vm_file, start, size,
507 + prot, flags, pgoff, &populate, NULL);
508 + if (!IS_ERR_VALUE(ret) && file && prfile) {
509 + struct vm_area_struct *new_vma;
511 + new_vma = find_vma(mm, ret);
512 + if (!new_vma->vm_prfile)
513 + new_vma->vm_prfile = prfile;
514 + if (new_vma != vma)
518 + * two fput()s instead of vma_fput(vma),
519 + * coz vma may not be available anymore.
525 file = get_file(vma->vm_file);
526 ret = do_mmap(vma->vm_file, start, size,
527 prot, flags, pgoff, &populate, NULL);
529 +#endif /* CONFIG_AUFS_FS */
531 mmap_write_unlock(mm);
533 @@ -3227,7 +3254,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
534 if (anon_vma_clone(new_vma, vma))
535 goto out_free_mempol;
536 if (new_vma->vm_file)
537 - get_file(new_vma->vm_file);
538 + vma_get_file(new_vma);
539 if (new_vma->vm_ops && new_vma->vm_ops->open)
540 new_vma->vm_ops->open(new_vma);
541 if (vma_link(mm, new_vma))
542 diff --git a/mm/nommu.c b/mm/nommu.c
543 index 214c70e1d059..dccbb939d2a9 100644
546 @@ -523,7 +523,7 @@ static void __put_nommu_region(struct vm_region *region)
547 up_write(&nommu_region_sem);
550 - fput(region->vm_file);
553 /* IO memory and memory shared directly out of the pagecache
554 * from ramfs/tmpfs mustn't be released here */
555 @@ -653,7 +653,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
556 if (vma->vm_ops && vma->vm_ops->close)
557 vma->vm_ops->close(vma);
559 - fput(vma->vm_file);
561 put_nommu_region(vma->vm_region);
564 @@ -1164,7 +1164,7 @@ unsigned long do_mmap(struct file *file,
565 goto error_just_free;
568 - fput(region->vm_file);
570 kmem_cache_free(vm_region_jar, region);
573 @@ -1241,10 +1241,10 @@ unsigned long do_mmap(struct file *file,
577 - fput(region->vm_file);
579 kmem_cache_free(vm_region_jar, region);
581 - fput(vma->vm_file);
586 diff --git a/mm/prfile.c b/mm/prfile.c
588 index 000000000000..8f820a235364
592 +// SPDX-License-Identifier: GPL-2.0
594 + * Mainly for aufs which mmap(2) different file and wants to print different
595 + * path in /proc/PID/maps.
596 + * Call these functions via macros defined in linux/mm.h.
598 + * See Documentation/filesystems/aufs/design/06mmap.txt
600 + * Copyright (c) 2014-2022 Junjro R. Okajima
601 + * Copyright (c) 2014 Ian Campbell
604 +#include <linux/mm.h>
605 +#include <linux/file.h>
606 +#include <linux/fs.h>
608 +/* #define PRFILE_TRACE */
609 +static inline void prfile_trace(struct file *f, struct file *pr,
610 + const char func[], int line, const char func2[])
614 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
618 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
621 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
623 + prfile_trace(f, pr, func, line, __func__);
624 + file_update_time(f);
626 + file_update_time(pr);
629 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
632 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
634 + prfile_trace(f, pr, func, line, __func__);
635 + return (f && pr) ? pr : f;
638 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
640 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
642 + prfile_trace(f, pr, func, line, __func__);
648 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
650 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
652 + prfile_trace(f, pr, func, line, __func__);
659 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
662 + struct file *f = region->vm_file, *pr = region->vm_prfile;
664 + prfile_trace(f, pr, func, line, __func__);
665 + return (f && pr) ? pr : f;
668 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
670 + struct file *f = region->vm_file, *pr = region->vm_prfile;
672 + prfile_trace(f, pr, func, line, __func__);
677 +#endif /* !CONFIG_MMU */
678 SPDX-License-Identifier: GPL-2.0
679 aufs6.x-rcN standalone patch
681 diff --git a/fs/dcache.c b/fs/dcache.c
682 index 519321f32f95..267e0c65914a 100644
685 @@ -1450,6 +1450,7 @@ void d_walk(struct dentry *parent, void *data,
689 +EXPORT_SYMBOL_GPL(d_walk);
692 struct vfsmount *mnt;
693 @@ -3052,6 +3053,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
695 write_sequnlock(&rename_lock);
697 +EXPORT_SYMBOL_GPL(d_exchange);
700 * d_ancestor - search for an ancestor
701 diff --git a/fs/exec.c b/fs/exec.c
702 index a0b1f0337a62..2038fdb508c9 100644
705 @@ -110,6 +110,7 @@ bool path_noexec(const struct path *path)
706 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
707 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
709 +EXPORT_SYMBOL_GPL(path_noexec);
713 diff --git a/fs/fcntl.c b/fs/fcntl.c
714 index c980a0524118..40087d11a974 100644
717 @@ -86,6 +86,7 @@ int setfl(int fd, struct file *filp, unsigned long arg)
721 +EXPORT_SYMBOL_GPL(setfl);
723 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
725 diff --git a/fs/file_table.c b/fs/file_table.c
726 index dd88701e54a9..ecdb7817b074 100644
727 --- a/fs/file_table.c
728 +++ b/fs/file_table.c
729 @@ -198,6 +198,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
731 return ERR_PTR(-ENFILE);
733 +EXPORT_SYMBOL_GPL(alloc_empty_file);
736 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
737 diff --git a/fs/namespace.c b/fs/namespace.c
738 index faae7f8644ac..0310c99a83dd 100644
741 @@ -456,6 +456,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
742 mnt_dec_writers(real_mount(mnt));
745 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
748 * mnt_drop_write - give up write access to a mount
749 @@ -857,6 +858,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
751 return check_mnt(real_mount(mnt));
753 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
756 * vfsmount lock must be held for write
757 @@ -2060,6 +2062,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
761 +EXPORT_SYMBOL_GPL(iterate_mounts);
763 static void lock_mnt_tree(struct mount *mnt)
765 diff --git a/fs/notify/group.c b/fs/notify/group.c
766 index 1de6631a3925..3008eb37a18d 100644
767 --- a/fs/notify/group.c
768 +++ b/fs/notify/group.c
769 @@ -100,6 +100,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
771 refcount_inc(&group->refcnt);
773 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
776 * Drop a reference to a group. Free it if it's through.
777 diff --git a/fs/open.c b/fs/open.c
778 index a81319b6177f..50bb15ea3fb5 100644
781 @@ -66,6 +66,7 @@ int do_truncate(struct user_namespace *mnt_userns, struct dentry *dentry,
782 inode_unlock(dentry->d_inode);
785 +EXPORT_SYMBOL_GPL(do_truncate);
787 long vfs_truncate(const struct path *path, loff_t length)
789 diff --git a/fs/read_write.c b/fs/read_write.c
790 index 328ce8cf9a85..59931848f794 100644
791 --- a/fs/read_write.c
792 +++ b/fs/read_write.c
793 @@ -477,6 +477,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
797 +EXPORT_SYMBOL_GPL(vfs_read);
799 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
801 @@ -592,6 +593,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
802 file_end_write(file);
805 +EXPORT_SYMBOL_GPL(vfs_write);
807 /* file_ppos returns &file->f_pos or NULL if file is stream */
808 static inline loff_t *file_ppos(struct file *file)
809 diff --git a/fs/splice.c b/fs/splice.c
810 index d83f9e5cddbc..ac355ebeb9f0 100644
813 @@ -763,6 +763,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
814 return warn_unsupported(out, "write");
815 return out->f_op->splice_write(pipe, out, ppos, len, flags);
817 +EXPORT_SYMBOL_GPL(do_splice_from);
820 * Attempt to initiate a splice from a file to a pipe.
821 @@ -792,6 +793,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
822 return warn_unsupported(in, "read");
823 return in->f_op->splice_read(in, ppos, pipe, len, flags);
825 +EXPORT_SYMBOL_GPL(do_splice_to);
828 * splice_direct_to_actor - splices data directly between two non-pipes
829 diff --git a/fs/xattr.c b/fs/xattr.c
830 index 61107b6bbed2..243855024966 100644
833 @@ -392,6 +392,7 @@ vfs_getxattr_alloc(struct user_namespace *mnt_userns, struct dentry *dentry,
834 *xattr_value = value;
837 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
840 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
841 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
842 index c1f0aadde539..278e0a322d20 100644
843 --- a/kernel/locking/lockdep.c
844 +++ b/kernel/locking/lockdep.c
845 @@ -238,6 +238,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
847 return lock_classes + class_idx;
849 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
850 #define hlock_class(hlock) lockdep_hlock_class(hlock)
852 #ifdef CONFIG_LOCK_STAT
853 diff --git a/kernel/task_work.c b/kernel/task_work.c
854 index 065e1ef8fc8d..c623c6f0c645 100644
855 --- a/kernel/task_work.c
856 +++ b/kernel/task_work.c
857 @@ -182,3 +182,4 @@ void task_work_run(void)
861 +EXPORT_SYMBOL_GPL(task_work_run);
862 diff --git a/security/security.c b/security/security.c
863 index 79d82cb6e469..1c50e6faadcd 100644
864 --- a/security/security.c
865 +++ b/security/security.c
866 @@ -1167,6 +1167,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
868 return call_int_hook(path_rmdir, 0, dir, dentry);
870 +EXPORT_SYMBOL_GPL(security_path_rmdir);
872 int security_path_unlink(const struct path *dir, struct dentry *dentry)
874 @@ -1183,6 +1184,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
876 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
878 +EXPORT_SYMBOL_GPL(security_path_symlink);
880 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
881 struct dentry *new_dentry)
882 @@ -1191,6 +1193,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
884 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
886 +EXPORT_SYMBOL_GPL(security_path_link);
888 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
889 const struct path *new_dir, struct dentry *new_dentry,
890 @@ -1211,6 +1214,7 @@ int security_path_truncate(const struct path *path)
892 return call_int_hook(path_truncate, 0, path);
894 +EXPORT_SYMBOL_GPL(security_path_truncate);
896 int security_path_chmod(const struct path *path, umode_t mode)
898 @@ -1218,6 +1222,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
900 return call_int_hook(path_chmod, 0, path, mode);
902 +EXPORT_SYMBOL_GPL(security_path_chmod);
904 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
906 @@ -1225,6 +1230,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
908 return call_int_hook(path_chown, 0, path, uid, gid);
910 +EXPORT_SYMBOL_GPL(security_path_chown);
912 int security_path_chroot(const struct path *path)
914 @@ -1325,6 +1331,7 @@ int security_inode_permission(struct inode *inode, int mask)
916 return call_int_hook(inode_permission, 0, inode, mask);
918 +EXPORT_SYMBOL_GPL(security_inode_permission);
920 int security_inode_setattr(struct user_namespace *mnt_userns,
921 struct dentry *dentry, struct iattr *attr)
922 @@ -1523,6 +1530,7 @@ int security_file_permission(struct file *file, int mask)
924 return fsnotify_perm(file, mask);
926 +EXPORT_SYMBOL_GPL(security_file_permission);
928 int security_file_alloc(struct file *file)
930 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
931 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
932 +++ linux/Documentation/ABI/testing/debugfs-aufs 2022-11-05 23:02:18.955889283 +0100
934 +What: /debug/aufs/si_<id>/
936 +Contact: J. R. Okajima <hooanon05g@gmail.com>
938 + Under /debug/aufs, a directory named si_<id> is created
939 + per aufs mount, where <id> is a unique id generated
942 +What: /debug/aufs/si_<id>/plink
944 +Contact: J. R. Okajima <hooanon05g@gmail.com>
946 + It has three lines and shows the information about the
947 + pseudo-link. The first line is a single number
948 + representing a number of buckets. The second line is a
949 + number of pseudo-links per buckets (separated by a
950 + blank). The last line is a single number representing a
951 + total number of psedo-links.
952 + When the aufs mount option 'noplink' is specified, it
953 + will show "1\n0\n0\n".
955 +What: /debug/aufs/si_<id>/xib
957 +Contact: J. R. Okajima <hooanon05g@gmail.com>
959 + It shows the consumed blocks by xib (External Inode Number
960 + Bitmap), its block size and file size.
961 + When the aufs mount option 'noxino' is specified, it
962 + will be empty. About XINO files, see the aufs manual.
964 +What: /debug/aufs/si_<id>/xi<branch-index>
966 +Contact: J. R. Okajima <hooanon05g@gmail.com>
968 + It shows the consumed blocks by xino (External Inode Number
969 + Translation Table), its link count, block size and file
971 + Due to the file size limit, there may exist multiple
972 + xino files per branch. In this case, "-N" is added to
973 + the filename and it corresponds to the index of the
974 + internal xino array. "-0" is omitted.
975 + When the aufs mount option 'noxino' is specified, Those
976 + entries won't exist. About XINO files, see the aufs
979 +What: /debug/aufs/si_<id>/xigen
981 +Contact: J. R. Okajima <hooanon05g@gmail.com>
983 + It shows the consumed blocks by xigen (External Inode
984 + Generation Table), its block size and file size.
985 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
987 + When the aufs mount option 'noxino' is specified, it
988 + will be empty. About XINO files, see the aufs manual.
989 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
990 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
991 +++ linux/Documentation/ABI/testing/sysfs-aufs 2022-11-05 23:02:18.955889283 +0100
993 +What: /sys/fs/aufs/si_<id>/
995 +Contact: J. R. Okajima <hooanon05g@gmail.com>
997 + Under /sys/fs/aufs, a directory named si_<id> is created
998 + per aufs mount, where <id> is a unique id generated
1001 +What: /sys/fs/aufs/si_<id>/br<idx>
1003 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1005 + It shows the abolute path of a member directory (which
1006 + is called branch) in aufs, and its permission.
1008 +What: /sys/fs/aufs/si_<id>/brid<idx>
1010 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1012 + It shows the id of a member directory (which is called
1015 +What: /sys/fs/aufs/si_<id>/xi_path
1017 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1019 + It shows the abolute path of XINO (External Inode Number
1020 + Bitmap, Translation Table and Generation Table) file
1021 + even if it is the default path.
1022 + When the aufs mount option 'noxino' is specified, it
1023 + will be empty. About XINO files, see the aufs manual.
1024 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1025 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1026 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2022-11-05 23:02:18.955889283 +0100
1029 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1031 +# This program is free software; you can redistribute it and/or modify
1032 +# it under the terms of the GNU General Public License as published by
1033 +# the Free Software Foundation; either version 2 of the License, or
1034 +# (at your option) any later version.
1036 +# This program is distributed in the hope that it will be useful,
1037 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1038 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1039 +# GNU General Public License for more details.
1041 +# You should have received a copy of the GNU General Public License
1042 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1045 +----------------------------------------
1047 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1048 +1. abbrev. for "advanced multi-layered unification filesystem".
1049 +2. abbrev. for "another unionfs".
1050 +3. abbrev. for "auf das" in German which means "on the" in English.
1051 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1052 + But "Filesystem aufs Filesystem" is hard to understand.
1053 +4. abbrev. for "African Urban Fashion Show".
1055 +AUFS is a filesystem with features:
1056 +- multi layered stackable unification filesystem, the member directory
1057 + is called as a branch.
1058 +- branch permission and attribute, 'readonly', 'real-readonly',
1059 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1061 +- internal "file copy-on-write".
1062 +- logical deletion, whiteout.
1063 +- dynamic branch manipulation, adding, deleting and changing permission.
1064 +- allow bypassing aufs, user's direct branch access.
1065 +- external inode number translation table and bitmap which maintains the
1066 + persistent aufs inode number.
1067 +- seekable directory, including NFS readdir.
1068 +- file mapping, mmap and sharing pages.
1069 +- pseudo-link, hardlink over branches.
1070 +- loopback mounted filesystem as a branch.
1071 +- several policies to select one among multiple writable branches.
1072 +- revert a single systemcall when an error occurs in aufs.
1076 +Multi Layered Stackable Unification Filesystem
1077 +----------------------------------------------------------------------
1078 +Most people already knows what it is.
1079 +It is a filesystem which unifies several directories and provides a
1080 +merged single directory. When users access a file, the access will be
1081 +passed/re-directed/converted (sorry, I am not sure which English word is
1082 +correct) to the real file on the member filesystem. The member
1083 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1084 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1085 +readonly branch is handled by creating 'whiteout' on the upper writable
1088 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1089 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1090 +different approaches to implement the merged-view.
1091 +The former tries putting it into VFS, and the latter implements as a
1092 +separate filesystem.
1093 +(If I misunderstand about these implementations, please let me know and
1094 +I shall correct it. Because it is a long time ago when I read their
1095 +source files last time).
1097 +UnionMount's approach will be able to small, but may be hard to share
1098 +branches between several UnionMount since the whiteout in it is
1099 +implemented in the inode on branch filesystem and always
1100 +shared. According to Bharata's post, readdir does not seems to be
1102 +There are several missing features known in this implementations such as
1103 +- for users, the inode number may change silently. eg. copy-up.
1104 +- link(2) may break by copy-up.
1105 +- read(2) may get an obsoleted filedata (fstat(2) too).
1106 +- fcntl(F_SETLK) may be broken by copy-up.
1107 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1110 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1111 +merged into mainline. This is another implementation of UnionMount as a
1112 +separated filesystem. All the limitations and known problems which
1113 +UnionMount are equally inherited to "overlay" filesystem.
1115 +Unionfs has a longer history. When I started implementing a stackable
1116 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1117 +inode, dentry and file objects and they have an array pointing lower
1118 +same kind objects. After contributing many patches for Unionfs, I
1119 +re-started my project AUFS (Jun 2006).
1121 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1122 +implemented my own ideas, approaches and enhancements and it became
1123 +totally different one.
1125 +Comparing DM snapshot and fs based implementation
1126 +- the number of bytes to be copied between devices is much smaller.
1127 +- the type of filesystem must be one and only.
1128 +- the fs must be writable, no readonly fs, even for the lower original
1129 + device. so the compression fs will not be usable. but if we use
1130 + loopback mount, we may address this issue.
1132 + mount /cdrom/squashfs.img /sq
1133 + losetup /sq/ext2.img
1134 + losetup /somewhere/cow
1135 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1136 +- it will be difficult (or needs more operations) to extract the
1137 + difference between the original device and COW.
1138 +- DM snapshot-merge may help a lot when users try merging. in the
1139 + fs-layer union, users will use rsync(1).
1141 +You may want to read my old paper "Filesystems in LiveCD"
1142 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1145 +Several characters/aspects/persona of aufs
1146 +----------------------------------------------------------------------
1148 +Aufs has several characters, aspects or persona.
1149 +1. a filesystem, callee of VFS helper
1150 +2. sub-VFS, caller of VFS helper for branches
1151 +3. a virtual filesystem which maintains persistent inode number
1152 +4. reader/writer of files on branches such like an application
1154 +1. Callee of VFS Helper
1155 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1156 +unlink(2) from an application reaches sys_unlink() kernel function and
1157 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1158 +calls filesystem specific unlink operation. Actually aufs implements the
1159 +unlink operation but it behaves like a redirector.
1161 +2. Caller of VFS Helper for Branches
1162 +aufs_unlink() passes the unlink request to the branch filesystem as if
1163 +it were called from VFS. So the called unlink operation of the branch
1164 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1165 +every necessary pre/post operation for the branch filesystem.
1166 +- acquire the lock for the parent dir on a branch
1167 +- lookup in a branch
1168 +- revalidate dentry on a branch
1169 +- mnt_want_write() for a branch
1170 +- vfs_unlink() for a branch
1171 +- mnt_drop_write() for a branch
1172 +- release the lock on a branch
1174 +3. Persistent Inode Number
1175 +One of the most important issue for a filesystem is to maintain inode
1176 +numbers. This is particularly important to support exporting a
1177 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1178 +backend block device for its own. But some storage is necessary to
1179 +keep and maintain the inode numbers. It may be a large space and may not
1180 +suit to keep in memory. Aufs rents some space from its first writable
1181 +branch filesystem (by default) and creates file(s) on it. These files
1182 +are created by aufs internally and removed soon (currently) keeping
1184 +Note: Because these files are removed, they are totally gone after
1185 + unmounting aufs. It means the inode numbers are not persistent
1186 + across unmount or reboot. I have a plan to make them really
1187 + persistent which will be important for aufs on NFS server.
1189 +4. Read/Write Files Internally (copy-on-write)
1190 +Because a branch can be readonly, when you write a file on it, aufs will
1191 +"copy-up" it to the upper writable branch internally. And then write the
1192 +originally requested thing to the file. Generally kernel doesn't
1193 +open/read/write file actively. In aufs, even a single write may cause a
1194 +internal "file copy". This behaviour is very similar to cp(1) command.
1196 +Some people may think it is better to pass such work to user space
1197 +helper, instead of doing in kernel space. Actually I am still thinking
1198 +about it. But currently I have implemented it in kernel space.
1199 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1200 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1201 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2022-11-05 23:02:18.955889283 +0100
1204 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1206 +# This program is free software; you can redistribute it and/or modify
1207 +# it under the terms of the GNU General Public License as published by
1208 +# the Free Software Foundation; either version 2 of the License, or
1209 +# (at your option) any later version.
1211 +# This program is distributed in the hope that it will be useful,
1212 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1213 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1214 +# GNU General Public License for more details.
1216 +# You should have received a copy of the GNU General Public License
1217 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1219 +Basic Aufs Internal Structure
1221 +Superblock/Inode/Dentry/File Objects
1222 +----------------------------------------------------------------------
1223 +As like an ordinary filesystem, aufs has its own
1224 +superblock/inode/dentry/file objects. All these objects have a
1225 +dynamically allocated array and store the same kind of pointers to the
1226 +lower filesystem, branch.
1227 +For example, when you build a union with one readwrite branch and one
1228 +readonly, mounted /au, /rw and /ro respectively.
1230 +- /ro/fileA exists but /rw/fileA
1232 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1233 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1234 +- [0] = NULL (because /rw/fileA doesn't exist)
1237 +This style of an array is essentially same to the aufs
1238 +superblock/inode/dentry/file objects.
1240 +Because aufs supports manipulating branches, ie. add/delete/change
1241 +branches dynamically, these objects has its own generation. When
1242 +branches are changed, the generation in aufs superblock is
1243 +incremented. And a generation in other object are compared when it is
1244 +accessed. When a generation in other objects are obsoleted, aufs
1245 +refreshes the internal array.
1249 +----------------------------------------------------------------------
1250 +Additionally aufs superblock has some data for policies to select one
1251 +among multiple writable branches, XIB files, pseudo-links and kobject.
1252 +See below in detail.
1253 +About the policies which supports copy-down a directory, see
1254 +wbr_policy.txt too.
1257 +Branch and XINO(External Inode Number Translation Table)
1258 +----------------------------------------------------------------------
1259 +Every branch has its own xino (external inode number translation table)
1260 +file. The xino file is created and unlinked by aufs internally. When two
1261 +members of a union exist on the same filesystem, they share the single
1263 +The struct of a xino file is simple, just a sequence of aufs inode
1264 +numbers which is indexed by the lower inode number.
1265 +In the above sample, assume the inode number of /ro/fileA is i111 and
1266 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1267 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1269 +When the inode numbers are not contiguous, the xino file will be sparse
1270 +which has a hole in it and doesn't consume as much disk space as it
1271 +might appear. If your branch filesystem consumes disk space for such
1272 +holes, then you should specify 'xino=' option at mounting aufs.
1274 +Aufs has a mount option to free the disk blocks for such holes in XINO
1275 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1276 +meet a problem of disk shortage due to XINO files, then you should try
1277 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1278 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1279 +the holes in XINO files.
1281 +Also a writable branch has three kinds of "whiteout bases". All these
1282 +are existed when the branch is joined to aufs, and their names are
1283 +whiteout-ed doubly, so that users will never see their names in aufs
1285 +1. a regular file which will be hardlinked to all whiteouts.
1286 +2. a directory to store a pseudo-link.
1287 +3. a directory to store an "orphan"-ed file temporary.
1290 + When you remove a file on a readonly branch, aufs handles it as a
1291 + logical deletion and creates a whiteout on the upper writable branch
1292 + as a hardlink of this file in order not to consume inode on the
1295 + See below, Pseudo-link.
1297 + When "fileC" exists on the lower readonly branch only and it is
1298 + opened and removed with its parent dir, and then user writes
1299 + something into it, then aufs copies-up fileC to this
1300 + directory. Because there is no other dir to store fileC. After
1301 + creating a file under this dir, the file is unlinked.
1303 +Because aufs supports manipulating branches, ie. add/delete/change
1304 +dynamically, a branch has its own id. When the branch order changes,
1305 +aufs finds the new index by searching the branch id.
1309 +----------------------------------------------------------------------
1310 +Assume "fileA" exists on the lower readonly branch only and it is
1311 +hardlinked to "fileB" on the branch. When you write something to fileA,
1312 +aufs copies-up it to the upper writable branch. Additionally aufs
1313 +creates a hardlink under the Pseudo-link Directory of the writable
1314 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1315 +simple list. If fileB is read after unlinking fileA, aufs returns
1316 +filedata from the pseudo-link instead of the lower readonly
1317 +branch. Because the pseudo-link is based upon the inode, to keep the
1318 +inode number by xino (see above) is essentially necessary.
1320 +All the hardlinks under the Pseudo-link Directory of the writable branch
1321 +should be restored in a proper location later. Aufs provides a utility
1322 +to do this. The userspace helpers executed at remounting and unmounting
1324 +During this utility is running, it puts aufs into the pseudo-link
1325 +maintenance mode. In this mode, only the process which began the
1326 +maintenance mode (and its child processes) is allowed to operate in
1327 +aufs. Some other processes which are not related to the pseudo-link will
1328 +be allowed to run too, but the rest have to return an error or wait
1329 +until the maintenance mode ends. If a process already acquires an inode
1330 +mutex (in VFS), it has to return an error.
1333 +XIB(external inode number bitmap)
1334 +----------------------------------------------------------------------
1335 +Addition to the xino file per a branch, aufs has an external inode number
1336 +bitmap in a superblock object. It is also an internal file such like a
1338 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1340 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1342 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1343 +reduce the number of consumed disk blocks for these files.
1346 +Virtual or Vertical Dir, and Readdir in Userspace
1347 +----------------------------------------------------------------------
1348 +In order to support multiple layers (branches), aufs readdir operation
1349 +constructs a virtual dir block on memory. For readdir, aufs calls
1350 +vfs_readdir() internally for each dir on branches, merges their entries
1351 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1352 +object. So the file object has its entry list until it is closed. The
1353 +entry list will be updated when the file position is zero and becomes
1354 +obsoleted. This decision is made in aufs automatically.
1356 +The dynamically allocated memory block for the name of entries has a
1357 +unit of 512 bytes (by default) and stores the names contiguously (no
1358 +padding). Another block for each entry is handled by kmem_cache too.
1359 +During building dir blocks, aufs creates hash list and judging whether
1360 +the entry is whiteouted by its upper branch or already listed.
1361 +The merged result is cached in the corresponding inode object and
1362 +maintained by a customizable life-time option.
1364 +Some people may call it can be a security hole or invite DoS attack
1365 +since the opened and once readdir-ed dir (file object) holds its entry
1366 +list and becomes a pressure for system memory. But I'd say it is similar
1367 +to files under /proc or /sys. The virtual files in them also holds a
1368 +memory page (generally) while they are opened. When an idea to reduce
1369 +memory for them is introduced, it will be applied to aufs too.
1370 +For those who really hate this situation, I've developed readdir(3)
1371 +library which operates this merging in userspace. You just need to set
1372 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1373 +kernel space for readdir(3).
1377 +----------------------------------------------------------------------
1378 +Aufs sometimes requires privilege access to a branch. For instance,
1379 +in copy-up/down operation. When a user process is going to make changes
1380 +to a file which exists in the lower readonly branch only, and the mode
1381 +of one of ancestor directories may not be writable by a user
1382 +process. Here aufs copy-up the file with its ancestors and they may
1383 +require privilege to set its owner/group/mode/etc.
1384 +This is a typical case of a application character of aufs (see
1387 +Aufs uses workqueue synchronously for this case. It creates its own
1388 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1389 +passes the request to call mkdir or write (for example), and wait for
1390 +its completion. This approach solves a problem of a signal handler
1392 +If aufs didn't adopt the workqueue and changed the privilege of the
1393 +process, then the process may receive the unexpected SIGXFSZ or other
1396 +Also aufs uses the system global workqueue ("events" kernel thread) too
1397 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1398 +whiteout base and etc. This is unrelated to a privilege.
1399 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1400 +superblock at the beginning, at the same time waits for the completion
1401 +of all queued asynchronous tasks.
1405 +----------------------------------------------------------------------
1406 +The whiteout in aufs is very similar to Unionfs's. That is represented
1407 +by its filename. UnionMount takes an approach of a file mode, but I am
1408 +afraid several utilities (find(1) or something) will have to support it.
1410 +Basically the whiteout represents "logical deletion" which stops aufs to
1411 +lookup further, but also it represents "dir is opaque" which also stop
1414 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1415 +In order to make several functions in a single systemcall to be
1416 +revertible, aufs adopts an approach to rename a directory to a temporary
1417 +unique whiteouted name.
1418 +For example, in rename(2) dir where the target dir already existed, aufs
1419 +renames the target dir to a temporary unique whiteouted name before the
1420 +actual rename on a branch, and then handles other actions (make it opaque,
1421 +update the attributes, etc). If an error happens in these actions, aufs
1422 +simply renames the whiteouted name back and returns an error. If all are
1423 +succeeded, aufs registers a function to remove the whiteouted unique
1424 +temporary name completely and asynchronously to the system global
1429 +----------------------------------------------------------------------
1430 +It is a well-known feature or concept.
1431 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1432 +internally and makes change to the new file on the upper writable branch.
1433 +When the trigger systemcall does not update the timestamps of the parent
1434 +dir, aufs reverts it after copy-up.
1437 +Move-down (aufs3.9 and later)
1438 +----------------------------------------------------------------------
1439 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1440 +the lower readonly branch to the upper writable branch when a user
1441 +changes something about the file.
1442 +"Move-down" is an opposite action of copy-up. Basically this action is
1443 +ran manually instead of automatically and internally.
1444 +For desgin and implementation, aufs has to consider these issues.
1445 +- whiteout for the file may exist on the lower branch.
1446 +- ancestor directories may not exist on the lower branch.
1447 +- diropq for the ancestor directories may exist on the upper branch.
1448 +- free space on the lower branch will reduce.
1449 +- another access to the file may happen during moving-down, including
1450 + UDBA (see "Revalidate Dentry and UDBA").
1451 +- the file should not be hard-linked nor pseudo-linked. they should be
1452 + handled by auplink utility later.
1454 +Sometimes users want to move-down a file from the upper writable branch
1455 +to the lower readonly or writable branch. For instance,
1456 +- the free space of the upper writable branch is going to run out.
1457 +- create a new intermediate branch between the upper and lower branch.
1460 +For this purpose, use "aumvdown" command in aufs-util.git.
1461 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1462 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1463 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2022-11-05 23:02:18.955889283 +0100
1466 +# Copyright (C) 2015-2022 Junjiro R. Okajima
1468 +# This program is free software; you can redistribute it and/or modify
1469 +# it under the terms of the GNU General Public License as published by
1470 +# the Free Software Foundation; either version 2 of the License, or
1471 +# (at your option) any later version.
1473 +# This program is distributed in the hope that it will be useful,
1474 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1475 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1476 +# GNU General Public License for more details.
1478 +# You should have received a copy of the GNU General Public License
1479 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1481 +Support for a branch who has its ->atomic_open()
1482 +----------------------------------------------------------------------
1483 +The filesystems who implement its ->atomic_open() are not majority. For
1484 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1485 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1486 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1487 +sure whether all filesystems who have ->atomic_open() behave like this,
1488 +but NFSv4 surely returns the error.
1490 +In order to support ->atomic_open() for aufs, there are a few
1493 +A. Introduce aufs_atomic_open()
1494 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1496 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1497 + an aufs user Pip Cet's approach
1498 + - calls aufs_create(), VFS finish_open() and notify_change().
1499 + - pass fake-mode to finish_open(), and then correct the mode by
1501 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1502 + - no aufs_atomic_open().
1503 + - aufs_lookup() registers the TID to an aufs internal object.
1504 + - aufs_create() does nothing when the matching TID is registered, but
1505 + registers the mode.
1506 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1507 + TID is registered.
1508 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1510 + - no aufs_atomic_open().
1511 + - aufs_create() registers the TID to an internal object. this info
1512 + represents "this process created this file just now."
1513 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1514 + registered TID and re-try open() with superuser's credential.
1516 +Pros and cons for each approach.
1519 + - straightforward but highly depends upon VFS internal.
1520 + - the atomic behavaiour is kept.
1521 + - some of parameters such as nameidata are hard to reproduce for
1525 + - easy to implement.
1526 + - the atomic behavaiour is lost.
1528 + - the atomic behavaiour is kept.
1529 + - dirty and tricky.
1530 + - VFS checks whether the file is created correctly after calling
1531 + ->create(), which means this approach doesn't work.
1533 + - easy to implement.
1534 + - the atomic behavaiour is lost.
1535 + - to open a file with superuser's credential and give it to a user
1536 + process is a bad idea, since the file object keeps the credential
1537 + in it. It may affect LSM or something. This approach doesn't work
1540 +The approach A is ideal, but it hard to implement. So here is a
1541 +variation of A, which is to be implemented.
1543 +A-1. Introduce aufs_atomic_open()
1544 + - calls branch fs ->atomic_open() if exists. otherwise calls
1545 + vfs_create() and finish_open().
1546 + - the demerit is that the several checks after branch fs
1547 + ->atomic_open() are lost. in the ordinary case, the checks are
1548 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1549 + be implemented in aufs, but not all I am afraid.
1550 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1551 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1552 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2022-11-05 23:02:18.959222617 +0100
1555 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1557 +# This program is free software; you can redistribute it and/or modify
1558 +# it under the terms of the GNU General Public License as published by
1559 +# the Free Software Foundation; either version 2 of the License, or
1560 +# (at your option) any later version.
1562 +# This program is distributed in the hope that it will be useful,
1563 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1564 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1565 +# GNU General Public License for more details.
1567 +# You should have received a copy of the GNU General Public License
1568 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1571 +----------------------------------------------------------------------
1572 +Since aufs has a character of sub-VFS (see Introduction), it operates
1573 +lookup for branches as VFS does. It may be a heavy work. But almost all
1574 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1575 +directly connected to its parent. Digging down the directory hierarchy
1576 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1579 +When a branch is a remote filesystem, aufs basically relies upon its
1580 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1582 +For d_revalidate, aufs implements three levels of revalidate tests. See
1583 +"Revalidate Dentry and UDBA" in detail.
1586 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1587 +----------------------------------------------------------------------
1588 +Let's try case study.
1589 +- aufs has two branches, upper readwrite and lower readonly.
1591 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1592 +- user invoked "chmod a+rx /au/dirA"
1593 +- the internal copy-up is activated and "/rw/dirA" is created and its
1594 + permission bits are set to world readable.
1595 +- then "/au/dirA" becomes world readable?
1597 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1598 +or it may be a natively readonly filesystem. If aufs respects the lower
1599 +branch, it should not respond readdir request from other users. But user
1600 +allowed it by chmod. Should really aufs rejects showing the entries
1603 +To be honest, I don't have a good solution for this case. So aufs
1604 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1606 +When dirperm1 is specified, aufs checks only the highest one for the
1607 +directory permission, and shows the entries. Otherwise, as usual, checks
1608 +every dir existing on all branches and rejects the request.
1610 +As a side effect, dirperm1 option improves the performance of aufs
1611 +because the number of permission check is reduced when the number of
1615 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1616 +----------------------------------------------------------------------
1617 +Generally VFS helpers re-validate a dentry as a part of lookup.
1618 +0. digging down the directory hierarchy.
1619 +1. lock the parent dir by its i_mutex.
1620 +2. lookup the final (child) entry.
1622 +4. call the actual operation (create, unlink, etc.)
1623 +5. unlock the parent dir
1625 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1626 +called. Actually aufs implements it and checks the dentry on a branch is
1628 +But it is not enough. Because aufs has to release the lock for the
1629 +parent dir on a branch at the end of ->lookup() (step 2) and
1630 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1632 +If the file on a branch is changed directly, eg. bypassing aufs, after
1633 +aufs released the lock, then the subsequent operation may cause
1634 +something unpleasant result.
1636 +This situation is a result of VFS architecture, ->lookup() and
1637 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1638 +design from VFS's point of view. It is just not suitable for sub-VFS
1641 +Aufs supports such case by three level of revalidation which is
1642 +selectable by user.
1643 +1. Simple Revalidate
1644 + Addition to the native flow in VFS's, confirm the child-parent
1645 + relationship on the branch just after locking the parent dir on the
1646 + branch in the "actual operation" (step 4). When this validation
1647 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1648 + checks the validation of the dentry on branches.
1649 +2. Monitor Changes Internally by Inotify/Fsnotify
1650 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1651 + the dentry on the branch, and returns EBUSY if it finds different
1653 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1654 + during it is in cache. When the event is notified, aufs registers a
1655 + function to kernel 'events' thread by schedule_work(). And the
1656 + function sets some special status to the cached aufs dentry and inode
1657 + private data. If they are not cached, then aufs has nothing to
1658 + do. When the same file is accessed through aufs (step 0-3) later,
1659 + aufs will detect the status and refresh all necessary data.
1660 + In this mode, aufs has to ignore the event which is fired by aufs
1662 +3. No Extra Validation
1663 + This is the simplest test and doesn't add any additional revalidation
1664 + test, and skip the revalidation in step 4. It is useful and improves
1665 + aufs performance when system surely hide the aufs branches from user,
1666 + by over-mounting something (or another method).
1667 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1668 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1669 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2022-11-05 23:02:18.959222617 +0100
1672 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1674 +# This program is free software; you can redistribute it and/or modify
1675 +# it under the terms of the GNU General Public License as published by
1676 +# the Free Software Foundation; either version 2 of the License, or
1677 +# (at your option) any later version.
1679 +# This program is distributed in the hope that it will be useful,
1680 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1681 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1682 +# GNU General Public License for more details.
1684 +# You should have received a copy of the GNU General Public License
1685 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1687 +Branch Manipulation
1689 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1690 +and changing its permission/attribute, there are a lot of works to do.
1694 +----------------------------------------------------------------------
1695 +o Confirm the adding dir exists outside of aufs, including loopback
1696 + mount, and its various attributes.
1697 +o Initialize the xino file and whiteout bases if necessary.
1700 +o Check the owner/group/mode of the directory
1701 + When the owner/group/mode of the adding directory differs from the
1702 + existing branch, aufs issues a warning because it may impose a
1704 + For example, when a upper writable branch has a world writable empty
1705 + top directory, a malicious user can create any files on the writable
1706 + branch directly, like copy-up and modify manually. If something like
1707 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1708 + writable branch, and the writable branch is world-writable, then a
1709 + malicious guy may create /etc/passwd on the writable branch directly
1710 + and the infected file will be valid in aufs.
1711 + I am afraid it can be a security issue, but aufs can do nothing except
1712 + producing a warning.
1716 +----------------------------------------------------------------------
1717 +o Confirm the deleting branch is not busy
1718 + To be general, there is one merit to adopt "remount" interface to
1719 + manipulate branches. It is to discard caches. At deleting a branch,
1720 + aufs checks the still cached (and connected) dentries and inodes. If
1721 + there are any, then they are all in-use. An inode without its
1722 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1724 + For the cached one, aufs checks whether the same named entry exists on
1726 + If the cached one is a directory, because aufs provides a merged view
1727 + to users, as long as one dir is left on any branch aufs can show the
1728 + dir to users. In this case, the branch can be removed from aufs.
1729 + Otherwise aufs rejects deleting the branch.
1731 + If any file on the deleting branch is opened by aufs, then aufs
1735 +Modify the Permission of a Branch
1736 +----------------------------------------------------------------------
1737 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1740 +o rw --> ro: Confirm the modifying branch is not busy
1741 + Aufs rejects the request if any of these conditions are true.
1742 + - a file on the branch is mmap-ed.
1743 + - a regular file on the branch is opened for write and there is no
1744 + same named entry on the upper branch.
1745 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1746 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1747 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2022-11-05 23:02:18.959222617 +0100
1750 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1752 +# This program is free software; you can redistribute it and/or modify
1753 +# it under the terms of the GNU General Public License as published by
1754 +# the Free Software Foundation; either version 2 of the License, or
1755 +# (at your option) any later version.
1757 +# This program is distributed in the hope that it will be useful,
1758 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1759 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1760 +# GNU General Public License for more details.
1762 +# You should have received a copy of the GNU General Public License
1763 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1765 +Policies to Select One among Multiple Writable Branches
1766 +----------------------------------------------------------------------
1767 +When the number of writable branch is more than one, aufs has to decide
1768 +the target branch for file creation or copy-up. By default, the highest
1769 +writable branch which has the parent (or ancestor) dir of the target
1770 +file is chosen (top-down-parent policy).
1771 +By user's request, aufs implements some other policies to select the
1772 +writable branch, for file creation several policies, round-robin,
1773 +most-free-space, and other policies. For copy-up, top-down-parent,
1774 +bottom-up-parent, bottom-up and others.
1776 +As expected, the round-robin policy selects the branch in circular. When
1777 +you have two writable branches and creates 10 new files, 5 files will be
1778 +created for each branch. mkdir(2) systemcall is an exception. When you
1779 +create 10 new directories, all will be created on the same branch.
1780 +And the most-free-space policy selects the one which has most free
1781 +space among the writable branches. The amount of free space will be
1782 +checked by aufs internally, and users can specify its time interval.
1784 +The policies for copy-up is more simple,
1785 +top-down-parent is equivalent to the same named on in create policy,
1786 +bottom-up-parent selects the writable branch where the parent dir
1787 +exists and the nearest upper one from the copyup-source,
1788 +bottom-up selects the nearest upper writable branch from the
1789 +copyup-source, regardless the existence of the parent dir.
1791 +There are some rules or exceptions to apply these policies.
1792 +- If there is a readonly branch above the policy-selected branch and
1793 + the parent dir is marked as opaque (a variation of whiteout), or the
1794 + target (creating) file is whiteout-ed on the upper readonly branch,
1795 + then the result of the policy is ignored and the target file will be
1796 + created on the nearest upper writable branch than the readonly branch.
1797 +- If there is a writable branch above the policy-selected branch and
1798 + the parent dir is marked as opaque or the target file is whiteouted
1799 + on the branch, then the result of the policy is ignored and the target
1800 + file will be created on the highest one among the upper writable
1801 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1803 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1804 + They try selecting the branch where the source exists as possible
1805 + since copyup a large file will take long time. If it can't be,
1806 + ie. the branch where the source exists is readonly, then they will
1807 + follow the copyup policy.
1808 +- There is an exception for rename(2) when the target exists.
1809 + If the rename target exists, aufs compares the index of the branches
1810 + where the source and the target exists and selects the higher
1811 + one. If the selected branch is readonly, then aufs follows the
1813 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1814 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1815 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2022-11-05 23:02:18.959222617 +0100
1818 +// to view this graph, run dot(1) command in GRAPHVIZ.
1820 +// This program is free software; you can redistribute it and/or modify
1821 +// it under the terms of the GNU General Public License as published by
1822 +// the Free Software Foundation; either version 2 of the License, or
1823 +// (at your option) any later version.
1825 +// This program is distributed in the hope that it will be useful,
1826 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
1827 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1828 +// GNU General Public License for more details.
1830 +// You should have received a copy of the GNU General Public License
1831 +// along with this program. If not, see <http://www.gnu.org/licenses/>.
1835 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1839 +aufs_rename -> whinfo [label="store/remove"];
1842 +inode_list [label="h_inum list in branch\ncache"];
1845 +whinode [label="h_inum list file"];
1848 +brmgmt [label="br_add/del/mod/umount"];
1850 +brmgmt -> inode_list [label="create/remove"];
1851 +brmgmt -> whinode [label="load/store"];
1853 +inode_list -> whinode [style=dashed,dir=both];
1855 +aufs_rename -> inode_list [label="add/del"];
1857 +aufs_lookup -> inode_list [label="search"];
1859 +aufs_lookup -> whinfo [label="load/remove"];
1861 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1862 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1863 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2022-11-05 23:02:18.959222617 +0100
1866 +# Copyright (C) 2017-2022 Junjiro R. Okajima
1868 +# This program is free software; you can redistribute it and/or modify
1869 +# it under the terms of the GNU General Public License as published by
1870 +# the Free Software Foundation; either version 2 of the License, or
1871 +# (at your option) any later version.
1873 +# This program is distributed in the hope that it will be useful,
1874 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1875 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1876 +# GNU General Public License for more details.
1878 +# You should have received a copy of the GNU General Public License
1879 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1881 +Special handling for renaming a directory (DIRREN)
1882 +----------------------------------------------------------------------
1883 +First, let's assume we have a simple usecase.
1887 +- /ro/dirA and /ro/dirA/file exist too
1888 +- there is no dirB on both branches
1889 +- a user issues rename("dirA", "dirB")
1891 +Now, what should aufs behave against this rename(2)?
1892 +There are a few possible cases.
1895 + since dirA exists on a readonly branch which cannot be renamed.
1897 + it is possible to copy-up dirA (only the dir itself), but the child
1898 + entries ("file" in this case) should not be. it must be a bad
1899 + approach to copy-up recursively.
1900 +C. returns a success.
1901 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
1902 + is a violation of aufs' policy.
1903 +D. construct an extra information which indicates that /ro/dirA should
1904 + be handled as the name of dirB.
1905 + overlayfs has a similar feature called REDIRECT.
1907 +Until now, aufs implements the case B only which returns EXDEV, and
1908 +expects the userspace application behaves like mv(1) which tries
1909 +issueing rename(2) recursively.
1911 +A new aufs feature called DIRREN is introduced which implements the case
1912 +D. There are several "extra information" added.
1914 +1. detailed info per renamed directory
1915 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
1916 +2. the inode-number list of directories on a branch
1917 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
1919 +The filename of "detailed info per directory" represents the lower
1920 +branch, and its format is
1921 +- a type of the branch id
1923 + + uuid (not implemented yet)
1926 +- the inode-number of the branch root dir
1928 +And it contains these info in a single regular file.
1930 +- branch's inode-number of the logically renamed dir
1931 +- the name of the before-renamed dir
1933 +The "detailed info per directory" file is created in aufs rename(2), and
1934 +loaded in any lookup.
1935 +The info is considered in lookup for the matching case only. Here
1936 +"matching" means that the root of branch (in the info filename) is same
1937 +to the current looking-up branch. After looking-up the before-renamed
1938 +name, the inode-number is compared. And the matched dentry is used.
1940 +The "inode-number list of directories" is a regular file which contains
1941 +simply the inode-numbers on the branch. The file is created or updated
1942 +in removing the branch, and loaded in adding the branch. Its lifetime is
1943 +equal to the branch.
1944 +The list is referred in lookup, and when the current target inode is
1945 +found in the list, the aufs tries loading the "detailed info per
1946 +directory" and get the changed and valid name of the dir.
1948 +Theoretically these "extra informaiton" may be able to be put into XATTR
1949 +in the dir inode. But aufs doesn't choose this way because
1950 +1. XATTR may not be supported by the branch (or its configuration)
1951 +2. XATTR may have its size limit.
1952 +3. XATTR may be less easy to convert than a regular file, when the
1953 + format of the info is changed in the future.
1954 +At the same time, I agree that the regular file approach is much slower
1955 +than XATTR approach. So, in the future, aufs may take the XATTR or other
1958 +This DIRREN feature is enabled by aufs configuration, and is activated
1959 +by a new mount option.
1961 +For the more complicated case, there is a work with UDBA option, which
1962 +is to dected the direct access to the branches (by-passing aufs) and to
1963 +maintain the cashes in aufs. Since a single cached aufs dentry may
1964 +contains two names, before- and after-rename, the name comparision in
1965 +UDBA handler may not work correctly. In this case, the behaviour will be
1966 +equivalen to udba=reval case.
1967 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1968 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1969 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2022-11-05 23:02:18.959222617 +0100
1972 +# Copyright (C) 2011-2022 Junjiro R. Okajima
1974 +# This program is free software; you can redistribute it and/or modify
1975 +# it under the terms of the GNU General Public License as published by
1976 +# the Free Software Foundation; either version 2 of the License, or
1977 +# (at your option) any later version.
1979 +# This program is distributed in the hope that it will be useful,
1980 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1981 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1982 +# GNU General Public License for more details.
1984 +# You should have received a copy of the GNU General Public License
1985 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1987 +File-based Hierarchical Storage Management (FHSM)
1988 +----------------------------------------------------------------------
1989 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1990 +storage world. Aufs provides this feature as file-based with multiple
1991 +writable branches, based upon the principle of "Colder, the Lower".
1992 +Here the word "colder" means that the less used files, and "lower" means
1993 +that the position in the order of the stacked branches vertically.
1994 +These multiple writable branches are prioritized, ie. the topmost one
1995 +should be the fastest drive and be used heavily.
1997 +o Characters in aufs FHSM story
1998 +- aufs itself and a new branch attribute.
1999 +- a new ioctl interface to move-down and to establish a connection with
2000 + the daemon ("move-down" is a converse of "copy-up").
2001 +- userspace tool and daemon.
2003 +The userspace daemon establishes a connection with aufs and waits for
2004 +the notification. The notified information is very similar to struct
2005 +statfs containing the number of consumed blocks and inodes.
2006 +When the consumed blocks/inodes of a branch exceeds the user-specified
2007 +upper watermark, the daemon activates its move-down process until the
2008 +consumed blocks/inodes reaches the user-specified lower watermark.
2010 +The actual move-down is done by aufs based upon the request from
2011 +user-space since we need to maintain the inode number and the internal
2012 +pointer arrays in aufs.
2014 +Currently aufs FHSM handles the regular files only. Additionally they
2015 +must not be hard-linked nor pseudo-linked.
2018 +o Cowork of aufs and the user-space daemon
2019 + During the userspace daemon established the connection, aufs sends a
2020 + small notification to it whenever aufs writes something into the
2021 + writable branch. But it may cost high since aufs issues statfs(2)
2022 + internally. So user can specify a new option to cache the
2023 + info. Actually the notification is controlled by these factors.
2024 + + the specified cache time.
2025 + + classified as "force" by aufs internally.
2026 + Until the specified time expires, aufs doesn't send the info
2027 + except the forced cases. When aufs decide forcing, the info is always
2028 + notified to userspace.
2029 + For example, the number of free inodes is generally large enough and
2030 + the shortage of it happens rarely. So aufs doesn't force the
2031 + notification when creating a new file, directory and others. This is
2032 + the typical case which aufs doesn't force.
2033 + When aufs writes the actual filedata and the files consumes any of new
2034 + blocks, the aufs forces notifying.
2037 +o Interfaces in aufs
2038 +- New branch attribute.
2040 + Specifies that the branch is managed by FHSM feature. In other word,
2041 + participant in the FHSM.
2042 + When nofhsm is set to the branch, it will not be the source/target
2043 + branch of the move-down operation. This attribute is set
2044 + independently from coo and moo attributes, and if you want full
2045 + FHSM, you should specify them as well.
2046 +- New mount option.
2048 + Specifies a second to suppress many less important info to be
2051 + + AUFS_CTL_FHSM_FD
2052 + create a new file descriptor which userspace can read the notification
2053 + (a subset of struct statfs) from aufs.
2054 +- Module parameter 'brs'
2055 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2057 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2058 + When there are two or more branches with fhsm attributes,
2059 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2060 + terminates it. As a result of remounting and branch-manipulation, the
2061 + number of branches with fhsm attribute can be one. In this case,
2062 + /sbin/mount.aufs will terminate the user-space daemon.
2065 +Finally the operation is done as these steps in kernel-space.
2067 + + no one else is using the file.
2068 + + the file is not hard-linked.
2069 + + the file is not pseudo-linked.
2070 + + the file is a regular file.
2071 + + the parent dir is not opaqued.
2072 +- find the target writable branch.
2073 +- make sure the file is not whiteout-ed by the upper (than the target)
2075 +- make the parent dir on the target branch.
2076 +- mutex lock the inode on the branch.
2077 +- unlink the whiteout on the target branch (if exists).
2078 +- lookup and create the whiteout-ed temporary name on the target branch.
2079 +- copy the file as the whiteout-ed temporary name on the target branch.
2080 +- rename the whiteout-ed temporary name to the original name.
2081 +- unlink the file on the source branch.
2082 +- maintain the internal pointer array and the external inode number
2084 +- maintain the timestamps and other attributes of the parent dir and the
2087 +And of course, in every step, an error may happen. So the operation
2088 +should restore the original file state after an error happens.
2089 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2090 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2091 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2022-11-05 23:02:18.959222617 +0100
2094 +# Copyright (C) 2005-2022 Junjiro R. Okajima
2096 +# This program is free software; you can redistribute it and/or modify
2097 +# it under the terms of the GNU General Public License as published by
2098 +# the Free Software Foundation; either version 2 of the License, or
2099 +# (at your option) any later version.
2101 +# This program is distributed in the hope that it will be useful,
2102 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2103 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2104 +# GNU General Public License for more details.
2106 +# You should have received a copy of the GNU General Public License
2107 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2109 +mmap(2) -- File Memory Mapping
2110 +----------------------------------------------------------------------
2111 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2112 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2114 +This approach is simple and good, but there is one problem.
2115 +Under /proc, several entries show the mmapped files by its path (with
2116 +device and inode number), and the printed path will be the path on the
2117 +branch fs's instead of virtual aufs's.
2118 +This is not a problem in most cases, but some utilities lsof(1) (and its
2119 +user) may expect the path on aufs.
2121 +To address this issue, aufs adds a new member called vm_prfile in struct
2122 +vm_area_struct (and struct vm_region). The original vm_file points to
2123 +the file on the branch fs in order to handle everything correctly as
2124 +usual. The new vm_prfile points to a virtual file in aufs, and the
2125 +show-functions in procfs refers to vm_prfile if it is set.
2126 +Also we need to maintain several other places where touching vm_file
2128 +- fork()/clone() copies vma and the reference count of vm_file is
2130 +- merging vma maintains the ref count too.
2132 +This is not a good approach. It just fakes the printed path. But it
2133 +leaves all behaviour around f_mapping unchanged. This is surely an
2135 +Actually aufs had adopted another complicated approach which calls
2136 +generic_file_mmap() and handles struct vm_operations_struct. In this
2137 +approach, aufs met a hard problem and I could not solve it without
2138 +switching the approach.
2140 +There may be one more another approach which is
2141 +- bind-mount the branch-root onto the aufs-root internally
2142 +- grab the new vfsmount (ie. struct mount)
2143 +- lazy-umount the branch-root internally
2144 +- in open(2) the aufs-file, open the branch-file with the hidden
2145 + vfsmount (instead of the original branch's vfsmount)
2146 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2147 + but it may be possible from userspace by the mount helper.
2149 +Adding the internal hidden vfsmount and using it in opening a file, the
2150 +file path under /proc will be printed correctly. This approach looks
2151 +smarter, but is not possible I am afraid.
2152 +- aufs-root may be bind-mount later. when it happens, another hidden
2153 + vfsmount will be required.
2154 +- it is hard to get the chance to bind-mount and lazy-umount
2155 + + in kernel-space, FS can have vfsmount in open(2) via
2156 + file->f_path, and aufs can know its vfsmount. But several locks are
2157 + already acquired, and if aufs tries to bind-mount and lazy-umount
2158 + here, then it may cause a deadlock.
2159 + + in user-space, bind-mount doesn't invoke the mount helper.
2160 +- since /proc shows dev and ino, aufs has to give vma these info. it
2161 + means a new member vm_prinode will be necessary. this is essentially
2162 + equivalent to vm_prfile described above.
2164 +I have to give up this "looks-smater" approach.
2165 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2166 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2167 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2022-11-05 23:02:18.959222617 +0100
2170 +# Copyright (C) 2014-2022 Junjiro R. Okajima
2172 +# This program is free software; you can redistribute it and/or modify
2173 +# it under the terms of the GNU General Public License as published by
2174 +# the Free Software Foundation; either version 2 of the License, or
2175 +# (at your option) any later version.
2177 +# This program is distributed in the hope that it will be useful,
2178 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2179 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2180 +# GNU General Public License for more details.
2182 +# You should have received a copy of the GNU General Public License
2183 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2185 +Listing XATTR/EA and getting the value
2186 +----------------------------------------------------------------------
2187 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2188 +shows the values from the topmost existing file. This behaviour is good
2189 +for the non-dir entries since the bahaviour exactly matches the shown
2190 +information. But for the directories, aufs considers all the same named
2191 +entries on the lower branches. Which means, if one of the lower entry
2192 +rejects readdir call, then aufs returns an error even if the topmost
2193 +entry allows it. This behaviour is necessary to respect the branch fs's
2194 +security, but can make users confused since the user-visible standard
2195 +attributes don't match the behaviour.
2196 +To address this issue, aufs has a mount option called dirperm1 which
2197 +checks the permission for the topmost entry only, and ignores the lower
2198 +entry's permission.
2200 +A similar issue can happen around XATTR.
2201 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2202 +always set. Otherwise these very unpleasant situation would happen.
2203 +- listxattr(2) may return the duplicated entries.
2204 +- users may not be able to remove or reset the XATTR forever,
2207 +XATTR/EA support in the internal (copy,move)-(up,down)
2208 +----------------------------------------------------------------------
2209 +Generally the extended attributes of inode are categorized as these.
2210 +- "security" for LSM and capability.
2211 +- "system" for posix ACL, 'acl' mount option is required for the branch
2213 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2214 +- "user" for userspace, 'user_xattr' mount option is required for the
2215 + branch fs generally.
2217 +Moreover there are some other categories. Aufs handles these rather
2218 +unpopular categories as the ordinary ones, ie. there is no special
2219 +condition nor exception.
2221 +In copy-up, the support for XATTR on the dst branch may differ from the
2222 +src branch. In this case, the copy-up operation will get an error and
2223 +the original user operation which triggered the copy-up will fail. It
2224 +can happen that even all copy-up will fail.
2225 +When both of src and dst branches support XATTR and if an error occurs
2226 +during copying XATTR, then the copy-up should fail obviously. That is a
2227 +good reason and aufs should return an error to userspace. But when only
2228 +the src branch support that XATTR, aufs should not return an error.
2229 +For example, the src branch supports ACL but the dst branch doesn't
2230 +because the dst branch may natively un-support it or temporary
2231 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2232 +may NOT return an error even if the XATTR is not supported. It is
2233 +totally up to the branch fs.
2235 +Anyway when the aufs internal copy-up gets an error from the dst branch
2236 +fs, then aufs tries removing the just copied entry and returns the error
2237 +to the userspace. The worst case of this situation will be all copy-up
2240 +For the copy-up operation, there two basic approaches.
2241 +- copy the specified XATTR only (by category above), and return the
2242 + error unconditionally if it happens.
2243 +- copy all XATTR, and ignore the error on the specified category only.
2245 +In order to support XATTR and to implement the correct behaviour, aufs
2246 +chooses the latter approach and introduces some new branch attributes,
2247 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2248 +They correspond to the XATTR namespaces (see above). Additionally, to be
2249 +convenient, "icex" is also provided which means all "icex*" attributes
2250 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2252 +The meaning of these attributes is to ignore the error from setting
2253 +XATTR on that branch.
2254 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2255 +error from the dst branch according to the specified attributes.
2257 +Some XATTR may have its default value. The default value may come from
2258 +the parent dir or the environment. If the default value is set at the
2259 +file creating-time, it will be overwritten by copy-up.
2260 +Some contradiction may happen I am afraid.
2261 +Do we need another attribute to stop copying XATTR? I am unsure. For
2262 +now, aufs implements the branch attributes to ignore the error.
2263 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2264 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2265 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2022-11-05 23:02:18.959222617 +0100
2268 +# Copyright (C) 2005-2022 Junjiro R. Okajima
2270 +# This program is free software; you can redistribute it and/or modify
2271 +# it under the terms of the GNU General Public License as published by
2272 +# the Free Software Foundation; either version 2 of the License, or
2273 +# (at your option) any later version.
2275 +# This program is distributed in the hope that it will be useful,
2276 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2277 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2278 +# GNU General Public License for more details.
2280 +# You should have received a copy of the GNU General Public License
2281 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2283 +Export Aufs via NFS
2284 +----------------------------------------------------------------------
2285 +Here is an approach.
2286 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2288 +- iget_locked(): initialize aufs inode generation for a new inode, and
2289 + store it in xigen file.
2290 +- destroy_inode(): increment aufs inode generation and store it in xigen
2291 + file. it is necessary even if it is not unlinked, because any data of
2292 + inode may be changed by UDBA.
2293 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2294 + build file handle by
2295 + + branch id (4 bytes)
2296 + + superblock generation (4 bytes)
2297 + + inode number (4 or 8 bytes)
2298 + + parent dir inode number (4 or 8 bytes)
2299 + + inode generation (4 bytes))
2300 + + return value of exportfs_encode_fh() for the parent on a branch (4
2302 + + file handle for a branch (by exportfs_encode_fh())
2304 + + find the index of a branch from its id in handle, and check it is
2305 + still exist in aufs.
2306 + + 1st level: get the inode number from handle and search it in cache.
2307 + + 2nd level: if not found in cache, get the parent inode number from
2308 + the handle and search it in cache. and then open the found parent
2309 + dir, find the matching inode number by vfs_readdir() and get its
2310 + name, and call lookup_one_len() for the target dentry.
2311 + + 3rd level: if the parent dir is not cached, call
2312 + exportfs_decode_fh() for a branch and get the parent on a branch,
2313 + build a pathname of it, convert it a pathname in aufs, call
2314 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2316 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2317 + for every branch, but not itself. to get this, (currently) aufs
2318 + searches in current->nsproxy->mnt_ns list. it may not be a good
2319 + idea, but I didn't get other approach.
2320 + + test the generation of the gotten inode.
2321 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2322 + convert it into ESTALE for NFSD.
2323 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2324 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2325 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2326 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2327 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2022-11-05 23:02:18.959222617 +0100
2330 +# Copyright (C) 2005-2022 Junjiro R. Okajima
2332 +# This program is free software; you can redistribute it and/or modify
2333 +# it under the terms of the GNU General Public License as published by
2334 +# the Free Software Foundation; either version 2 of the License, or
2335 +# (at your option) any later version.
2337 +# This program is distributed in the hope that it will be useful,
2338 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2339 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2340 +# GNU General Public License for more details.
2342 +# You should have received a copy of the GNU General Public License
2343 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2345 +Show Whiteout Mode (shwh)
2346 +----------------------------------------------------------------------
2347 +Generally aufs hides the name of whiteouts. But in some cases, to show
2348 +them is very useful for users. For instance, creating a new middle layer
2349 +(branch) by merging existing layers.
2351 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2352 +When you have three branches,
2353 +- Bottom: 'system', squashfs (underlying base system), read-only
2354 +- Middle: 'mods', squashfs, read-only
2355 +- Top: 'overlay', ram (tmpfs), read-write
2357 +The top layer is loaded at boot time and saved at shutdown, to preserve
2358 +the changes made to the system during the session.
2359 +When larger changes have been made, or smaller changes have accumulated,
2360 +the size of the saved top layer data grows. At this point, it would be
2361 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2362 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2363 +restoring save and load speed.
2365 +This merging is simplified by the use of another aufs mount, of just the
2366 +two overlay branches using the 'shwh' option.
2367 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2368 + aufs /livesys/merge_union
2370 +A merged view of these two branches is then available at
2371 +/livesys/merge_union, and the new feature is that the whiteouts are
2373 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2374 +writing to all branches. Also the default mode for all branches is 'ro'.
2375 +It is now possible to save the combined contents of the two overlay
2376 +branches to a new squashfs, e.g.:
2377 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2379 +This new squashfs archive can be stored on the boot device and the
2380 +initramfs will use it to replace the old one at the next boot.
2381 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2382 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2383 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2022-11-05 23:02:18.959222617 +0100
2386 +# Copyright (C) 2010-2022 Junjiro R. Okajima
2388 +# This program is free software; you can redistribute it and/or modify
2389 +# it under the terms of the GNU General Public License as published by
2390 +# the Free Software Foundation; either version 2 of the License, or
2391 +# (at your option) any later version.
2393 +# This program is distributed in the hope that it will be useful,
2394 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2395 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2396 +# GNU General Public License for more details.
2398 +# You should have received a copy of the GNU General Public License
2399 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2401 +Dynamically customizable FS operations
2402 +----------------------------------------------------------------------
2403 +Generally FS operations (struct inode_operations, struct
2404 +address_space_operations, struct file_operations, etc.) are defined as
2405 +"static const", but it never means that FS have only one set of
2406 +operation. Some FS have multiple sets of them. For instance, ext2 has
2407 +three sets, one for XIP, for NOBH, and for normal.
2408 +Since aufs overrides and redirects these operations, sometimes aufs has
2409 +to change its behaviour according to the branch FS type. More importantly
2410 +VFS acts differently if a function (member in the struct) is set or
2411 +not. It means aufs should have several sets of operations and select one
2412 +among them according to the branch FS definition.
2414 +In order to solve this problem and not to affect the behaviour of VFS,
2415 +aufs defines these operations dynamically. For instance, aufs defines
2416 +dummy direct_IO function for struct address_space_operations, but it may
2417 +not be set to the address_space_operations actually. When the branch FS
2418 +doesn't have it, aufs doesn't set it to its address_space_operations
2419 +while the function definition itself is still alive. So the behaviour
2420 +itself will not change, and it will return an error when direct_IO is
2423 +The lifetime of these dynamically generated operation object is
2424 +maintained by aufs branch object. When the branch is removed from aufs,
2425 +the reference counter of the object is decremented. When it reaches
2426 +zero, the dynamically generated operation object will be freed.
2428 +This approach is designed to support AIO (io_submit), Direct I/O and
2430 +Currently this approach is applied to address_space_operations for
2431 +regular files only.
2432 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2433 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2434 +++ linux/Documentation/filesystems/aufs/README 2022-11-05 23:02:18.955889283 +0100
2437 +Aufs6 -- advanced multi layered unification filesystem version 6.x
2443 +----------------------------------------
2444 +In the early days, aufs was entirely re-designed and re-implemented
2445 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2446 +improvements and implementations, it became totally different from
2447 +Unionfs while keeping the basic features.
2448 +Later, Unionfs Version 2.x series began taking some of the same
2449 +approaches to aufs1's.
2450 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2451 +University and his team.
2453 +Aufs6 supports linux-v6.0 and later, try aufs6.0 branch in
2454 +aufs-linux.git or aufs-standalone.git.
2455 +If you want older kernel version support,
2456 +- for linux-v5.x series, try aufs-linux.git or aufs-standalone.git
2457 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2458 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2459 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2460 + or aufs1 from CVS on SourceForge.
2462 +Note: the name of aufs5-linux.git and aufs5-standalone.git on github
2463 + were changed. Now they are aufs-linux.git and
2464 + aufs-standalone.git and they contain aufs5 and later branches.
2466 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2467 + According to Christoph Hellwig, linux rejects all union-type
2468 + filesystems but UnionMount.
2469 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2471 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2472 + UnionMount, and he pointed out an issue around a directory mutex
2473 + lock and aufs addressed it. But it is still unsure whether aufs will
2474 + be merged (or any other union solution).
2475 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2479 +----------------------------------------
2480 +- unite several directories into a single virtual filesystem. The member
2481 + directory is called as a branch.
2482 +- you can specify the permission flags to the branch, which are 'readonly',
2483 + 'readwrite' and 'whiteout-able.'
2484 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2485 + readonly branch are modifiable logically.
2486 +- dynamic branch manipulation, add, del.
2489 +Also there are many enhancements in aufs, such as:
2490 +- test only the highest one for the directory permission (dirperm1)
2491 +- copyup on open (coo=)
2492 +- 'move' policy for copy-up between two writable branches, after
2493 + checking free space.
2495 +- readdir(3) in userspace.
2496 +- keep inode number by external inode number table
2497 +- keep the timestamps of file/dir in internal copyup operation
2498 +- seekable directory, supporting NFS readdir.
2499 +- whiteout is hardlinked in order to reduce the consumption of inodes
2501 +- do not copyup, nor create a whiteout when it is unnecessary
2502 +- revert a single systemcall when an error occurs in aufs
2503 +- remount interface instead of ioctl
2504 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2505 +- loopback mounted filesystem as a branch
2506 +- kernel thread for removing the dir who has a plenty of whiteouts
2507 +- support copyup sparse file (a file which has a 'hole' in it)
2508 +- default permission flags for branches
2509 +- selectable permission flags for ro branch, whether whiteout can
2512 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2513 +- support multiple writable branches, some policies to select one
2514 + among multiple writable branches.
2515 +- a new semantics for link(2) and rename(2) to support multiple
2516 + writable branches.
2517 +- no glibc changes are required.
2518 +- pseudo hardlink (hardlink over branches)
2519 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2520 + including NFS or remote filesystem branch.
2521 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2524 +Currently these features are dropped temporary from aufs6.
2525 +See design/08plan.txt in detail.
2526 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2528 +- statistics of aufs thread (/sys/fs/aufs/stat)
2530 +Features or just an idea in the future (see also design/*.txt),
2531 +- reorder the branch index without del/re-add.
2532 +- permanent xino files for NFSD
2533 +- an option for refreshing the opened files after add/del branches
2534 +- light version, without branch manipulation. (unnecessary?)
2535 +- copyup in userspace
2536 +- inotify in userspace
2541 +----------------------------------------
2542 +There are three GIT trees for aufs6, aufs6-linux.git,
2543 +aufs6-standalone.git, and aufs-util.git. Note that there is no "6" in
2545 +While the aufs-util is always necessary, you need either of aufs6-linux
2546 +or aufs6-standalone.
2548 +The aufs6-linux tree includes the whole linux mainline GIT tree,
2549 +git://git.kernel.org/.../torvalds/linux.git.
2550 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2551 +build aufs6 as an external kernel module.
2552 +Several extra patches are not included in this tree. Only
2553 +aufs6-standalone tree contains them. They are described in the later
2554 +section "Configuration and Compilation."
2556 +On the other hand, the aufs6-standalone tree has only aufs source files
2557 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2558 +But you need to apply all aufs patches manually.
2560 +You will find GIT branches whose name is in form of "aufs6.x" where "x"
2561 +represents the linux kernel version, "linux-6.x". For instance,
2562 +"aufs6.0" is for linux-6.0. For latest "linux-6.x-rcN", use
2563 +"aufs6.x-rcN" branch.
2566 +$ git clone --reference /your/linux/git/tree \
2567 + git://github.com/sfjro/aufs6-linux.git aufs6-linux.git
2568 +- if you don't have linux GIT tree, then remove "--reference ..."
2569 +$ cd aufs6-linux.git
2570 +$ git checkout origin/aufs6.0
2572 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2573 +leave the patch-work to GIT.
2574 +$ cd /your/linux/git/tree
2575 +$ git remote add aufs6 git://github.com/sfjro/aufs6-linux.git
2577 +$ git checkout -b my6.0 v6.0
2578 +$ (add your local change...)
2579 +$ git pull aufs6 aufs6.0
2580 +- now you have v6.0 + your_changes + aufs6.0 in you my6.0 branch.
2581 +- you may need to solve some conflicts between your_changes and
2582 + aufs6.0. in this case, git-rerere is recommended so that you can
2583 + solve the similar conflicts automatically when you upgrade to 6.1 or
2584 + later in the future.
2586 +o aufs6-standalone tree
2587 +$ git clone git://github.com/sfjro/aufs6-standalone.git aufs6-standalone.git
2588 +$ cd aufs6-standalone.git
2589 +$ git checkout origin/aufs6.0
2592 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2593 +- note that the public aufs-util.git is on SourceForge instead of
2596 +$ git checkout origin/aufs6.0
2598 +Note: The 6.x-rcN branch is to be used with `rc' kernel versions ONLY.
2599 +The minor version number, 'x' in '6.x', of aufs may not always
2600 +follow the minor version number of the kernel.
2601 +Because changes in the kernel that cause the use of a new
2602 +minor version number do not always require changes to aufs-util.
2604 +Since aufs-util has its own minor version number, you may not be
2605 +able to find a GIT branch in aufs-util for your kernel's
2606 +exact minor version number.
2607 +In this case, you should git-checkout the branch for the
2608 +nearest lower number.
2610 +For (an unreleased) example:
2611 +If you are using "linux-6.10" and the "aufs6.10" branch
2612 +does not exist in aufs-util repository, then "aufs6.9", "aufs6.8"
2613 +or something numerically smaller is the branch for your kernel.
2615 +Also you can view all branches by
2619 +3. Configuration and Compilation
2620 +----------------------------------------
2621 +Make sure you have git-checkout'ed the correct branch.
2623 +For aufs6-linux tree,
2624 +- enable CONFIG_AUFS_FS.
2625 +- set other aufs configurations if necessary.
2626 +- for aufs5.13 and later
2627 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2628 + also a caller of VFS functions for branch filesystems, subclassing of
2629 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2630 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2631 + need to customize some LOCKDEP numbers. Here are what I use on my
2633 + CONFIG_LOCKDEP_BITS=21
2634 + CONFIG_LOCKDEP_CHAINS_BITS=21
2635 + CONFIG_LOCKDEP_STACK_TRACE_BITS=24
2637 +For aufs6-standalone tree,
2638 +There are several ways to build.
2641 +- apply ./aufs6-kbuild.patch to your kernel source files.
2642 +- apply ./aufs6-base.patch too.
2643 +- apply ./aufs6-mmap.patch too.
2644 +- apply ./aufs6-standalone.patch too, if you have a plan to set
2645 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs6-standalone.patch.
2646 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2647 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2648 +- enable CONFIG_AUFS_FS, you can select either
2650 +- and build your kernel as usual.
2651 +- install the built kernel.
2652 +- install the header files too by "make headers_install" to the
2653 + directory where you specify. By default, it is $PWD/usr.
2654 + "make help" shows a brief note for headers_install.
2655 +- and reboot your system.
2658 +- module only (CONFIG_AUFS_FS=m).
2659 +- apply ./aufs6-base.patch to your kernel source files.
2660 +- apply ./aufs6-mmap.patch too.
2661 +- apply ./aufs6-standalone.patch too.
2662 +- build your kernel, don't forget "make headers_install", and reboot.
2663 +- edit ./config.mk and set other aufs configurations if necessary.
2664 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2665 + every aufs configurations.
2666 +- build the module by simple "make".
2667 +- you can specify ${KDIR} make variable which points to your kernel
2669 +- install the files
2670 + + run "make install" to install the aufs module, or copy the built
2671 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2672 + + run "make install_headers" (instead of headers_install) to install
2673 + the modified aufs header file (you can specify DESTDIR which is
2674 + available in aufs standalone version's Makefile only), or copy
2675 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2676 + you like manually. By default, the target directory is $PWD/usr.
2677 +- no need to apply aufs6-kbuild.patch, nor copying source files to your
2678 + kernel source tree.
2680 +Note: The header file aufs_type.h is necessary to build aufs-util
2681 + as well as "make headers_install" in the kernel source tree.
2682 + headers_install is subject to be forgotten, but it is essentially
2683 + necessary, not only for building aufs-util.
2684 + You may not meet problems without headers_install in some older
2688 +- read README in aufs-util, build and install it
2689 +- note that your distribution may contain an obsoleted version of
2690 + aufs_type.h in /usr/include/linux or something. When you build aufs
2691 + utilities, make sure that your compiler refers the correct aufs header
2692 + file which is built by "make headers_install."
2693 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2694 + then run "make install_ulib" too. And refer to the aufs manual in
2697 +There several other patches in aufs6-standalone.git. They are all
2698 +optional. When you meet some problems, they will help you.
2699 +- aufs6-loopback.patch
2700 + Supports a nested loopback mount in a branch-fs. This patch is
2701 + unnecessary until aufs produces a message like "you may want to try
2702 + another patch for loopback file".
2704 + Modifies a system global kernel internal function get_next_ino() in
2705 + order to stop assigning 0 for an inode-number. Not directly related to
2706 + aufs, but recommended generally.
2708 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2709 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2710 + duplication of inode number, which is important for backup tools and
2711 + other utilities. When you find aufs XINO files for tmpfs branch
2712 + growing too much, try this patch.
2716 +----------------------------------------
2717 +At first, make sure aufs-util are installed, and please read the aufs
2718 +manual, aufs.6 in aufs-util.git tree.
2722 +$ mkdir /tmp/rw /tmp/aufs
2723 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2725 +Here is another example. The result is equivalent.
2726 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2728 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2729 +# mount -o remount,append:${HOME} /tmp/aufs
2731 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2732 +you modify a file under /tmp/aufs, the one on your home directory is
2733 +not affected, instead the same named file will be newly created under
2734 +/tmp/rw. And all of your modification to a file will be applied to
2735 +the one under /tmp/rw. This is called the file based Copy on Write
2737 +Aufs mount options are described in aufs.6.
2738 +If you run chroot or something and make your aufs as a root directory,
2739 +then you need to customize the shutdown script. See the aufs manual in
2742 +Additionally, there are some sample usages of aufs which are a
2743 +diskless system with network booting, and LiveCD over NFS.
2744 +See sample dir in CVS tree on SourceForge.
2748 +----------------------------------------
2749 +When you have any problems or strange behaviour in aufs, please let me
2751 +- /proc/mounts (instead of the output of mount(8))
2752 +- /sys/module/aufs/*
2753 +- /sys/fs/aufs/* (if you have them)
2754 +- /debug/aufs/* (if you have them)
2755 +- linux kernel version
2756 + if your kernel is not plain, for example modified by distributor,
2757 + the url where i can download its source is necessary too.
2758 +- aufs version which was printed at loading the module or booting the
2759 + system, instead of the date you downloaded.
2760 +- configuration (define/undefine CONFIG_AUFS_xxx)
2761 +- kernel configuration or /proc/config.gz (if you have it)
2762 +- LSM (linux security module, if you are using)
2763 +- behaviour which you think to be incorrect
2764 +- actual operation, reproducible one is better
2765 +- mailto: aufs-users at lists.sourceforge.net
2767 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2768 +and Feature Requests) on SourceForge. Please join and write to
2772 +6. Acknowledgements
2773 +----------------------------------------
2774 +Thanks to everyone who have tried and are using aufs, whoever
2775 +have reported a bug or any feedback.
2777 +Especially donators:
2778 +Tomas Matejicek(slax.org) made a donation (much more than once).
2779 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2780 + scripts) is making "doubling" donations.
2781 + Unfortunately I cannot list all of the donators, but I really
2783 + It ends Aug 2010, but the ordinary donation URL is still available.
2784 + <http://sourceforge.net/donate/index.php?group_id=167503>
2785 +Dai Itasaka made a donation (2007/8).
2786 +Chuck Smith made a donation (2008/4, 10 and 12).
2787 +Henk Schoneveld made a donation (2008/9).
2788 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2789 +Francois Dupoux made a donation (2008/11).
2790 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2791 + aufs2 GIT tree (2009/2).
2792 +William Grant made a donation (2009/3).
2793 +Patrick Lane made a donation (2009/4).
2794 +The Mail Archive (mail-archive.com) made donations (2009/5).
2795 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2796 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2797 +Pavel Pronskiy made a donation (2011/2).
2798 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2799 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2800 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2802 +Sam Liddicott made a donation (2011/9).
2803 +Era Scarecrow made a donation (2013/4).
2804 +Bor Ratajc made a donation (2013/4).
2805 +Alessandro Gorreta made a donation (2013/4).
2806 +POIRETTE Marc made a donation (2013/4).
2807 +Alessandro Gorreta made a donation (2013/4).
2808 +lauri kasvandik made a donation (2013/5).
2809 +"pemasu from Finland" made a donation (2013/7).
2810 +The Parted Magic Project made a donation (2013/9 and 11).
2811 +Pavel Barta made a donation (2013/10).
2812 +Nikolay Pertsev made a donation (2014/5).
2813 +James B made a donation (2014/7, 2015/7, and 2021/12).
2814 +Stefano Di Biase made a donation (2014/8).
2815 +Daniel Epellei made a donation (2015/1).
2816 +OmegaPhil made a donation (2016/1, 2018/4).
2817 +Tomasz Szewczyk made a donation (2016/4).
2818 +James Burry made a donation (2016/12).
2819 +Carsten Rose made a donation (2018/9).
2820 +Porteus Kiosk made a donation (2018/10).
2821 +Enya Quetzalli Gomez Rodriguez made a donation (2022/5).
2823 +Thank you very much.
2824 +Donations are always, including future donations, very important and
2825 +helpful for me to keep on developing aufs.
2829 +----------------------------------------
2830 +If you are an experienced user, no explanation is needed. Aufs is
2831 +just a linux filesystem.
2836 +# Local variables: ;
2839 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2840 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2841 +++ linux/fs/aufs/aufs.h 2022-11-05 23:02:18.959222617 +0100
2843 +/* SPDX-License-Identifier: GPL-2.0 */
2845 + * Copyright (C) 2005-2022 Junjiro R. Okajima
2847 + * This program is free software; you can redistribute it and/or modify
2848 + * it under the terms of the GNU General Public License as published by
2849 + * the Free Software Foundation; either version 2 of the License, or
2850 + * (at your option) any later version.
2852 + * This program is distributed in the hope that it will be useful,
2853 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2854 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2855 + * GNU General Public License for more details.
2857 + * You should have received a copy of the GNU General Public License
2858 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2862 + * all header files
2870 +#define AuStub(type, name, body, ...) \
2871 + static inline type name(__VA_ARGS__) { body; }
2873 +#define AuStubVoid(name, ...) \
2874 + AuStub(void, name, , __VA_ARGS__)
2875 +#define AuStubInt0(name, ...) \
2876 + AuStub(int, name, return 0, __VA_ARGS__)
2880 +#include "branch.h"
2883 +#include "dbgaufs.h"
2884 +#include "dentry.h"
2886 +#include "dirren.h"
2889 +#include "fstype.h"
2894 +#include "module.h"
2898 +#include "sysaufs.h"
2903 +#endif /* __KERNEL__ */
2904 +#endif /* __AUFS_H__ */
2905 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2906 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2907 +++ linux/fs/aufs/branch.c 2022-11-05 23:02:18.959222617 +0100
2909 +// SPDX-License-Identifier: GPL-2.0
2911 + * Copyright (C) 2005-2022 Junjiro R. Okajima
2913 + * This program is free software; you can redistribute it and/or modify
2914 + * it under the terms of the GNU General Public License as published by
2915 + * the Free Software Foundation; either version 2 of the License, or
2916 + * (at your option) any later version.
2918 + * This program is distributed in the hope that it will be useful,
2919 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2920 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2921 + * GNU General Public License for more details.
2923 + * You should have received a copy of the GNU General Public License
2924 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2928 + * branch management
2931 +#include <linux/compat.h>
2932 +#include <linux/statfs.h>
2936 + * free a single branch
2938 +static void au_br_do_free(struct au_branch *br)
2941 + struct au_wbr *wbr;
2942 + struct au_dykey **key;
2944 + au_hnotify_fin_br(br);
2945 + /* always, regardless the mount option */
2946 + au_dr_hino_free(&br->br_dirren);
2949 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
2950 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
2951 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
2952 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
2956 + for (i = 0; i < AuBrWh_Last; i++)
2957 + dput(wbr->wbr_wh[i]);
2958 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2959 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2962 + if (br->br_fhsm) {
2963 + au_br_fhsm_fin(br->br_fhsm);
2964 + au_kfree_try_rcu(br->br_fhsm);
2967 + key = br->br_dykey;
2968 + for (i = 0; i < AuBrDynOp; i++, key++)
2974 + /* recursive lock, s_umount of branch's */
2975 + /* synchronize_rcu(); */ /* why? */
2977 + path_put(&br->br_path);
2979 + au_kfree_rcu(wbr);
2980 + au_lcnt_wait_for_fin(&br->br_nfiles);
2981 + au_lcnt_wait_for_fin(&br->br_count);
2982 + /* I don't know why, but percpu_refcount requires this */
2983 + /* synchronize_rcu(); */
2988 + * frees all branches
2990 +void au_br_free(struct au_sbinfo *sbinfo)
2992 + aufs_bindex_t bmax;
2993 + struct au_branch **br;
2995 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2997 + bmax = sbinfo->si_bbot + 1;
2998 + br = sbinfo->si_branch;
3000 + au_br_do_free(*br++);
3004 + * find the index of a branch which is specified by @br_id.
3006 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3008 + aufs_bindex_t bindex, bbot;
3010 + bbot = au_sbbot(sb);
3011 + for (bindex = 0; bindex <= bbot; bindex++)
3012 + if (au_sbr_id(sb, bindex) == br_id)
3017 +/* ---------------------------------------------------------------------- */
3023 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3024 + struct dentry *h_root)
3026 + if (unlikely(h_adding == h_root
3027 + || au_test_loopback_overlap(sb, h_adding)))
3029 + if (h_adding->d_sb != h_root->d_sb)
3031 + return au_test_subdir(h_adding, h_root)
3032 + || au_test_subdir(h_root, h_adding);
3036 + * returns a newly allocated branch. @new_nbranch is a number of branches
3037 + * after adding a branch.
3039 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3042 + struct au_branch *add_branch;
3043 + struct dentry *root;
3044 + struct inode *inode;
3048 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3049 + if (unlikely(!add_branch))
3051 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3052 + if (unlikely(!add_branch->br_xino))
3054 + err = au_hnotify_init_br(add_branch, perm);
3055 + if (unlikely(err))
3058 + if (au_br_writable(perm)) {
3059 + /* may be freed separately at changing the branch permission */
3060 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3062 + if (unlikely(!add_branch->br_wbr))
3066 + if (au_br_fhsm(perm)) {
3067 + err = au_fhsm_br_alloc(add_branch);
3068 + if (unlikely(err))
3072 + root = sb->s_root;
3073 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3075 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3077 + inode = d_inode(root);
3078 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3082 + return add_branch; /* success */
3085 + au_kfree_rcu(add_branch->br_wbr);
3087 + au_hnotify_fin_br(add_branch);
3089 + au_xino_put(add_branch);
3091 + au_kfree_rcu(add_branch);
3093 + return ERR_PTR(err);
3097 + * test if the branch permission is legal or not.
3099 +static int test_br(struct inode *inode, int brperm, char *path)
3103 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3108 + pr_err("write permission for readonly mount or inode, %s\n", path);
3116 + * 0: success, the caller will add it
3117 + * plus: success, it is already unified, the caller should ignore it
3120 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3123 + aufs_bindex_t bbot, bindex;
3124 + struct dentry *root, *h_dentry;
3125 + struct inode *inode, *h_inode;
3127 + root = sb->s_root;
3128 + bbot = au_sbbot(sb);
3129 + if (unlikely(bbot >= 0
3130 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3134 + pr_err("%s duplicated\n", add->pathname);
3139 + err = -ENOSPC; /* -E2BIG; */
3140 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3141 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3142 + pr_err("number of branches exceeded %s\n", add->pathname);
3147 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3148 + pr_err("bad index %d\n", add->bindex);
3152 + inode = d_inode(add->path.dentry);
3154 + if (unlikely(!inode->i_nlink)) {
3155 + pr_err("no existence %s\n", add->pathname);
3160 + if (unlikely(inode->i_sb == sb)) {
3161 + pr_err("%s must be outside\n", add->pathname);
3165 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3166 + pr_err("unsupported filesystem, %s (%s)\n",
3167 + add->pathname, au_sbtype(inode->i_sb));
3171 + if (unlikely(inode->i_sb->s_stack_depth)) {
3172 + pr_err("already stacked, %s (%s)\n",
3173 + add->pathname, au_sbtype(inode->i_sb));
3177 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3178 + if (unlikely(err))
3182 + return 0; /* success */
3185 + for (bindex = 0; bindex <= bbot; bindex++)
3186 + if (unlikely(test_overlap(sb, add->path.dentry,
3187 + au_h_dptr(root, bindex)))) {
3188 + pr_err("%s is overlapped\n", add->pathname);
3193 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3194 + h_dentry = au_h_dptr(root, 0);
3195 + h_inode = d_inode(h_dentry);
3196 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3197 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3198 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3199 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3201 + i_uid_read(inode), i_gid_read(inode),
3202 + (inode->i_mode & S_IALLUGO),
3203 + i_uid_read(h_inode), i_gid_read(h_inode),
3204 + (h_inode->i_mode & S_IALLUGO));
3212 + * initialize or clean the whiteouts for an adding branch
3214 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3217 + int err, old_perm;
3218 + aufs_bindex_t bindex;
3219 + struct inode *h_inode;
3220 + struct au_wbr *wbr;
3221 + struct au_hinode *hdir;
3222 + struct dentry *h_dentry;
3224 + err = vfsub_mnt_want_write(au_br_mnt(br));
3225 + if (unlikely(err))
3229 + old_perm = br->br_perm;
3230 + br->br_perm = new_perm;
3233 + bindex = au_br_index(sb, br->br_id);
3234 + if (0 <= bindex) {
3235 + hdir = au_hi(d_inode(sb->s_root), bindex);
3236 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3238 + h_dentry = au_br_dentry(br);
3239 + h_inode = d_inode(h_dentry);
3240 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3243 + err = au_wh_init(br, sb);
3245 + wbr_wh_write_lock(wbr);
3246 + err = au_wh_init(br, sb);
3247 + wbr_wh_write_unlock(wbr);
3250 + au_hn_inode_unlock(hdir);
3252 + inode_unlock(h_inode);
3253 + vfsub_mnt_drop_write(au_br_mnt(br));
3254 + br->br_perm = old_perm;
3256 + if (!err && wbr && !au_br_writable(new_perm)) {
3257 + au_kfree_rcu(wbr);
3258 + br->br_wbr = NULL;
3265 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3269 + struct kstatfs kst;
3270 + struct au_wbr *wbr;
3273 + au_rw_init(&wbr->wbr_wh_rwsem);
3274 + atomic_set(&wbr->wbr_wh_running, 0);
3277 + * a limit for rmdir/rename a dir
3278 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3280 + err = vfs_statfs(&br->br_path, &kst);
3281 + if (unlikely(err))
3284 + if (kst.f_namelen >= NAME_MAX)
3285 + err = au_br_init_wh(sb, br, perm);
3287 + pr_err("%pd(%s), unsupported namelen %ld\n",
3289 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3295 +/* initialize a new branch */
3296 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3297 + struct au_opt_add *add)
3300 + struct au_branch *brbase;
3302 + struct inode *h_inode;
3305 + br->br_perm = add->perm;
3306 + br->br_path = add->path; /* set first, path_get() later */
3307 + spin_lock_init(&br->br_dykey_lock);
3308 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3309 + au_lcnt_init(&br->br_count, /*release*/NULL);
3310 + br->br_id = au_new_br_id(sb);
3311 + AuDebugOn(br->br_id < 0);
3313 + /* always, regardless the given option */
3314 + err = au_dr_br_init(sb, br, &add->path);
3315 + if (unlikely(err))
3318 + if (au_br_writable(add->perm)) {
3319 + err = au_wbr_init(br, sb, add->perm);
3320 + if (unlikely(err))
3324 + if (au_opt_test(au_mntflags(sb), XINO)) {
3325 + brbase = au_sbr(sb, 0);
3326 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3328 + h_inode = d_inode(add->path.dentry);
3329 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3330 + if (unlikely(err)) {
3331 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3336 + sysaufs_br_init(br);
3337 + path_get(&br->br_path);
3338 + goto out; /* success */
3341 + memset(&br->br_path, 0, sizeof(br->br_path));
3346 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3347 + struct au_branch *br, aufs_bindex_t bbot,
3348 + aufs_bindex_t amount)
3350 + struct au_branch **brp;
3352 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3354 + brp = sbinfo->si_branch + bindex;
3355 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3357 + sbinfo->si_bbot++;
3358 + if (unlikely(bbot < 0))
3359 + sbinfo->si_bbot = 0;
3362 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3363 + aufs_bindex_t bbot, aufs_bindex_t amount)
3365 + struct au_hdentry *hdp;
3367 + AuRwMustWriteLock(&dinfo->di_rwsem);
3369 + hdp = au_hdentry(dinfo, bindex);
3370 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3371 + au_h_dentry_init(hdp);
3373 + if (unlikely(bbot < 0))
3374 + dinfo->di_btop = 0;
3377 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3378 + aufs_bindex_t bbot, aufs_bindex_t amount)
3380 + struct au_hinode *hip;
3382 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3384 + hip = au_hinode(iinfo, bindex);
3385 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3386 + au_hinode_init(hip);
3388 + if (unlikely(bbot < 0))
3389 + iinfo->ii_btop = 0;
3392 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3393 + aufs_bindex_t bindex)
3395 + struct dentry *root, *h_dentry;
3396 + struct inode *root_inode, *h_inode;
3397 + aufs_bindex_t bbot, amount;
3399 + root = sb->s_root;
3400 + root_inode = d_inode(root);
3401 + bbot = au_sbbot(sb);
3402 + amount = bbot + 1 - bindex;
3403 + h_dentry = au_br_dentry(br);
3404 + au_sbilist_lock();
3405 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3406 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3407 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3408 + au_set_h_dptr(root, bindex, dget(h_dentry));
3409 + h_inode = d_inode(h_dentry);
3410 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3411 + au_sbilist_unlock();
3414 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3417 + aufs_bindex_t bbot, add_bindex;
3418 + struct dentry *root, *h_dentry;
3419 + struct inode *root_inode;
3420 + struct au_branch *add_branch;
3422 + root = sb->s_root;
3423 + root_inode = d_inode(root);
3424 + IMustLock(root_inode);
3425 + IiMustWriteLock(root_inode);
3426 + err = test_add(sb, add, remount);
3427 + if (unlikely(err < 0))
3431 + goto out; /* success */
3434 + bbot = au_sbbot(sb);
3435 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3436 + err = PTR_ERR(add_branch);
3437 + if (IS_ERR(add_branch))
3440 + err = au_br_init(add_branch, sb, add);
3441 + if (unlikely(err)) {
3442 + au_br_do_free(add_branch);
3446 + add_bindex = add->bindex;
3447 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3448 + au_br_do_add(sb, add_branch, add_bindex);
3449 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3450 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3452 + h_dentry = add->path.dentry;
3453 + if (!add_bindex) {
3454 + au_cpup_attr_all(root_inode, /*force*/1);
3455 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3457 + au_add_nlink(root_inode, d_inode(h_dentry));
3463 +/* ---------------------------------------------------------------------- */
3465 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3466 + unsigned long long max __maybe_unused,
3469 + unsigned long long n;
3470 + struct file **p, *f;
3471 + struct hlist_bl_head *files;
3472 + struct hlist_bl_node *pos;
3473 + struct au_finfo *finfo;
3477 + files = &au_sbi(sb)->si_files;
3478 + hlist_bl_lock(files);
3479 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3480 + f = finfo->fi_file;
3482 + && !special_file(file_inode(f)->i_mode)) {
3486 + AuDebugOn(n > max);
3489 + hlist_bl_unlock(files);
3494 +static struct file **au_farray_alloc(struct super_block *sb,
3495 + unsigned long long *max)
3497 + struct au_sbinfo *sbi;
3500 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3501 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3504 +static void au_farray_free(struct file **a, unsigned long long max)
3506 + unsigned long long ull;
3508 + for (ull = 0; ull < max; ull++)
3514 +/* ---------------------------------------------------------------------- */
3520 +/* to show the line number, do not make it inlined function */
3521 +#define AuVerbose(do_info, fmt, ...) do { \
3523 + pr_info(fmt, ##__VA_ARGS__); \
3526 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3527 + aufs_bindex_t bbot)
3529 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3532 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3533 + aufs_bindex_t bbot)
3535 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3539 + * test if the branch is deletable or not.
3541 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3542 + unsigned int sigen, const unsigned int verbose)
3544 + int err, i, j, ndentry;
3545 + aufs_bindex_t btop, bbot;
3546 + struct au_dcsub_pages dpages;
3547 + struct au_dpage *dpage;
3550 + err = au_dpages_init(&dpages, GFP_NOFS);
3551 + if (unlikely(err))
3553 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3554 + if (unlikely(err))
3557 + for (i = 0; !err && i < dpages.ndpage; i++) {
3558 + dpage = dpages.dpages + i;
3559 + ndentry = dpage->ndentry;
3560 + for (j = 0; !err && j < ndentry; j++) {
3561 + d = dpage->dentries[j];
3562 + AuDebugOn(au_dcount(d) <= 0);
3563 + if (!au_digen_test(d, sigen)) {
3564 + di_read_lock_child(d, AuLock_IR);
3565 + if (unlikely(au_dbrange_test(d))) {
3566 + di_read_unlock(d, AuLock_IR);
3570 + di_write_lock_child(d);
3571 + if (unlikely(au_dbrange_test(d))) {
3572 + di_write_unlock(d);
3575 + err = au_reval_dpath(d, sigen);
3577 + di_downgrade_lock(d, AuLock_IR);
3579 + di_write_unlock(d);
3584 + /* AuDbgDentry(d); */
3585 + btop = au_dbtop(d);
3586 + bbot = au_dbbot(d);
3587 + if (btop <= bindex
3589 + && au_h_dptr(d, bindex)
3590 + && au_test_dbusy(d, btop, bbot)) {
3592 + AuVerbose(verbose, "busy %pd\n", d);
3595 + di_read_unlock(d, AuLock_IR);
3600 + au_dpages_free(&dpages);
3605 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3606 + unsigned int sigen, const unsigned int verbose)
3609 + unsigned long long max, ull;
3610 + struct inode *i, **array;
3611 + aufs_bindex_t btop, bbot;
3613 + array = au_iarray_alloc(sb, &max);
3614 + err = PTR_ERR(array);
3615 + if (IS_ERR(array))
3619 + AuDbg("b%d\n", bindex);
3620 + for (ull = 0; !err && ull < max; ull++) {
3624 + if (i->i_ino == AUFS_ROOT_INO)
3627 + /* AuDbgInode(i); */
3628 + if (au_iigen(i, NULL) == sigen)
3629 + ii_read_lock_child(i);
3631 + ii_write_lock_child(i);
3632 + err = au_refresh_hinode_self(i);
3635 + ii_downgrade_lock(i);
3637 + ii_write_unlock(i);
3642 + btop = au_ibtop(i);
3643 + bbot = au_ibbot(i);
3644 + if (btop <= bindex
3646 + && au_h_iptr(i, bindex)
3647 + && au_test_ibusy(i, btop, bbot)) {
3649 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3652 + ii_read_unlock(i);
3654 + au_iarray_free(array, max);
3660 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3661 + const unsigned int verbose)
3664 + unsigned int sigen;
3666 + sigen = au_sigen(root->d_sb);
3667 + DiMustNoWaiters(root);
3668 + IiMustNoWaiters(d_inode(root));
3669 + di_write_unlock(root);
3670 + err = test_dentry_busy(root, bindex, sigen, verbose);
3672 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3673 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3678 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3679 + struct file **to_free, int *idx)
3682 + unsigned char matched, root;
3683 + aufs_bindex_t bindex, bbot;
3684 + struct au_fidir *fidir;
3685 + struct au_hfile *hfile;
3688 + root = IS_ROOT(file->f_path.dentry);
3691 + to_free[*idx] = file;
3697 + fidir = au_fi(file)->fi_hdir;
3698 + AuDebugOn(!fidir);
3699 + bbot = au_fbbot_dir(file);
3700 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3701 + hfile = fidir->fd_hfile + bindex;
3702 + if (!hfile->hf_file)
3705 + if (hfile->hf_br->br_id == br_id) {
3717 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3718 + struct file **to_free, int opened)
3721 + unsigned long long ull, max;
3722 + aufs_bindex_t btop;
3723 + struct file *file, **array;
3724 + struct dentry *root;
3725 + struct au_hfile *hfile;
3727 + array = au_farray_alloc(sb, &max);
3728 + err = PTR_ERR(array);
3729 + if (IS_ERR(array))
3734 + root = sb->s_root;
3735 + di_write_unlock(root);
3736 + for (ull = 0; ull < max; ull++) {
3737 + file = array[ull];
3738 + if (unlikely(!file))
3741 + /* AuDbg("%pD\n", file); */
3742 + fi_read_lock(file);
3743 + btop = au_fbtop(file);
3744 + if (!d_is_dir(file->f_path.dentry)) {
3745 + hfile = &au_fi(file)->fi_htop;
3746 + if (hfile->hf_br->br_id == br_id)
3749 + err = test_dir_busy(file, br_id, to_free, &idx);
3750 + fi_read_unlock(file);
3751 + if (unlikely(err))
3754 + di_write_lock_child(root);
3755 + au_farray_free(array, max);
3756 + AuDebugOn(idx > opened);
3762 +static void br_del_file(struct file **to_free, unsigned long long opened,
3763 + aufs_bindex_t br_id)
3765 + unsigned long long ull;
3766 + aufs_bindex_t bindex, btop, bbot, bfound;
3767 + struct file *file;
3768 + struct au_fidir *fidir;
3769 + struct au_hfile *hfile;
3771 + for (ull = 0; ull < opened; ull++) {
3772 + file = to_free[ull];
3773 + if (unlikely(!file))
3776 + /* AuDbg("%pD\n", file); */
3777 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3779 + fidir = au_fi(file)->fi_hdir;
3780 + AuDebugOn(!fidir);
3781 + fi_write_lock(file);
3782 + btop = au_fbtop(file);
3783 + bbot = au_fbbot_dir(file);
3784 + for (bindex = btop; bindex <= bbot; bindex++) {
3785 + hfile = fidir->fd_hfile + bindex;
3786 + if (!hfile->hf_file)
3789 + if (hfile->hf_br->br_id == br_id) {
3794 + AuDebugOn(bfound < 0);
3795 + au_set_h_fptr(file, bfound, NULL);
3796 + if (bfound == btop) {
3797 + for (btop++; btop <= bbot; btop++)
3798 + if (au_hf_dir(file, btop)) {
3799 + au_set_fbtop(file, btop);
3803 + fi_write_unlock(file);
3807 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3808 + const aufs_bindex_t bindex,
3809 + const aufs_bindex_t bbot)
3811 + struct au_branch **brp, **p;
3813 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3815 + brp = sbinfo->si_branch + bindex;
3816 + if (bindex < bbot)
3817 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3818 + sbinfo->si_branch[0 + bbot] = NULL;
3819 + sbinfo->si_bbot--;
3821 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3824 + sbinfo->si_branch = p;
3825 + /* harmless error */
3828 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3829 + const aufs_bindex_t bbot)
3831 + struct au_hdentry *hdp, *p;
3833 + AuRwMustWriteLock(&dinfo->di_rwsem);
3835 + hdp = au_hdentry(dinfo, bindex);
3836 + if (bindex < bbot)
3837 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3838 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3841 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3844 + dinfo->di_hdentry = p;
3845 + /* harmless error */
3848 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3849 + const aufs_bindex_t bbot)
3851 + struct au_hinode *hip, *p;
3853 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3855 + hip = au_hinode(iinfo, bindex);
3856 + if (bindex < bbot)
3857 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3858 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3861 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3864 + iinfo->ii_hinode = p;
3865 + /* harmless error */
3868 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3869 + struct au_branch *br)
3871 + aufs_bindex_t bbot;
3872 + struct au_sbinfo *sbinfo;
3873 + struct dentry *root, *h_root;
3874 + struct inode *inode, *h_inode;
3875 + struct au_hinode *hinode;
3877 + SiMustWriteLock(sb);
3879 + root = sb->s_root;
3880 + inode = d_inode(root);
3881 + sbinfo = au_sbi(sb);
3882 + bbot = sbinfo->si_bbot;
3884 + h_root = au_h_dptr(root, bindex);
3885 + hinode = au_hi(inode, bindex);
3886 + h_inode = au_igrab(hinode->hi_inode);
3889 + au_sbilist_lock();
3890 + au_br_do_del_brp(sbinfo, bindex, bbot);
3891 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3892 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3893 + au_sbilist_unlock();
3895 + /* ignore an error */
3896 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
3900 + au_br_do_free(br);
3903 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3904 + unsigned long long max, void *arg)
3909 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3912 + unsigned long long opened;
3913 + unsigned int mnt_flags;
3914 + aufs_bindex_t bindex, bbot, br_id;
3915 + unsigned char do_wh, verbose;
3916 + struct au_branch *br;
3917 + struct au_wbr *wbr;
3918 + struct dentry *root;
3919 + struct file **to_free;
3924 + root = sb->s_root;
3925 + bindex = au_find_dbindex(root, del->h_path.dentry);
3928 + goto out; /* success */
3930 + pr_err("%s no such branch\n", del->pathname);
3933 + AuDbg("bindex b%d\n", bindex);
3936 + mnt_flags = au_mntflags(sb);
3937 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3938 + bbot = au_sbbot(sb);
3939 + if (unlikely(!bbot)) {
3940 + AuVerbose(verbose, "no more branches left\n");
3944 + br = au_sbr(sb, bindex);
3945 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3946 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
3947 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
3951 + br_id = br->br_id;
3952 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
3953 + if (unlikely(opened)) {
3954 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3955 + err = PTR_ERR(to_free);
3956 + if (IS_ERR(to_free))
3959 + err = test_file_busy(sb, br_id, to_free, opened);
3960 + if (unlikely(err)) {
3961 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3967 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3969 + /* instead of WbrWhMustWriteLock(wbr) */
3970 + SiMustWriteLock(sb);
3971 + for (i = 0; i < AuBrWh_Last; i++) {
3972 + dput(wbr->wbr_wh[i]);
3973 + wbr->wbr_wh[i] = NULL;
3977 + err = test_children_busy(root, bindex, verbose);
3978 + if (unlikely(err)) {
3987 + * now we confirmed the branch is deletable.
3988 + * let's free the remaining opened dirs on the branch.
3990 + di_write_unlock(root);
3991 + br_del_file(to_free, opened, br_id);
3992 + di_write_lock_child(root);
3995 + sysaufs_brs_del(sb, bindex); /* remove successors */
3996 + dbgaufs_xino_del(br); /* remove one */
3997 + au_br_do_del(sb, bindex, br);
3998 + sysaufs_brs_add(sb, bindex); /* append successors */
3999 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4002 + au_cpup_attr_all(d_inode(root), /*force*/1);
4003 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4005 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4006 + if (au_opt_test(mnt_flags, PLINK))
4007 + au_plink_half_refresh(sb, br_id);
4009 + goto out; /* success */
4013 + rerr = au_br_init_wh(sb, br, br->br_perm);
4015 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4016 + del->pathname, rerr);
4019 + au_farray_free(to_free, opened);
4023 +/* ---------------------------------------------------------------------- */
4025 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4028 + aufs_bindex_t btop, bbot;
4029 + struct aufs_ibusy ibusy;
4030 + struct inode *inode, *h_inode;
4033 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4036 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4038 + /* VERIFY_WRITE */
4039 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4040 + if (unlikely(err)) {
4047 + si_read_lock(sb, AuLock_FLUSH);
4048 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4052 + ibusy.h_ino = 0; /* invalid */
4053 + inode = ilookup(sb, ibusy.ino);
4055 + || inode->i_ino == AUFS_ROOT_INO
4056 + || au_is_bad_inode(inode))
4059 + ii_read_lock_child(inode);
4060 + btop = au_ibtop(inode);
4061 + bbot = au_ibbot(inode);
4062 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4063 + h_inode = au_h_iptr(inode, ibusy.bindex);
4064 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4065 + ibusy.h_ino = h_inode->i_ino;
4067 + ii_read_unlock(inode);
4071 + si_read_unlock(sb);
4073 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4074 + if (unlikely(err)) {
4083 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4085 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4088 +#ifdef CONFIG_COMPAT
4089 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4091 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4095 +/* ---------------------------------------------------------------------- */
4098 + * change a branch permission
4101 +static void au_warn_ima(void)
4104 + /* since it doesn't support mark_files_ro() */
4105 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4109 +static int do_need_sigen_inc(int a, int b)
4111 + return au_br_whable(a) && !au_br_whable(b);
4114 +static int need_sigen_inc(int old, int new)
4116 + return do_need_sigen_inc(old, new)
4117 + || do_need_sigen_inc(new, old);
4120 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4123 + unsigned int mnt_flags;
4124 + unsigned long long ull, max;
4125 + aufs_bindex_t br_id;
4126 + unsigned char verbose, writer;
4127 + struct file *file, *hf, **array;
4128 + struct au_hfile *hfile;
4129 + struct inode *h_inode;
4131 + mnt_flags = au_mntflags(sb);
4132 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4134 + array = au_farray_alloc(sb, &max);
4135 + err = PTR_ERR(array);
4136 + if (IS_ERR(array))
4140 + br_id = au_sbr_id(sb, bindex);
4141 + for (ull = 0; ull < max; ull++) {
4142 + file = array[ull];
4143 + if (unlikely(!file))
4146 + /* AuDbg("%pD\n", file); */
4147 + fi_read_lock(file);
4148 + if (unlikely(au_test_mmapped(file))) {
4150 + AuVerbose(verbose, "mmapped %pD\n", file);
4152 + FiMustNoWaiters(file);
4153 + fi_read_unlock(file);
4157 + hfile = &au_fi(file)->fi_htop;
4158 + hf = hfile->hf_file;
4159 + if (!d_is_reg(file->f_path.dentry)
4160 + || !(file->f_mode & FMODE_WRITE)
4161 + || hfile->hf_br->br_id != br_id
4162 + || !(hf->f_mode & FMODE_WRITE))
4163 + array[ull] = NULL;
4169 + FiMustNoWaiters(file);
4170 + fi_read_unlock(file);
4178 + for (ull = 0; ull < max; ull++) {
4179 + file = array[ull];
4183 + /* todo: already flushed? */
4185 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4186 + * approach which resets f_mode and calls mnt_drop_write() and
4187 + * file_release_write() for each file, because the branch
4188 + * attribute in aufs world is totally different from the native
4191 + /* fi_read_lock(file); */
4192 + hfile = &au_fi(file)->fi_htop;
4193 + hf = hfile->hf_file;
4194 + /* fi_read_unlock(file); */
4195 + spin_lock(&hf->f_lock);
4196 + writer = !!(hf->f_mode & FMODE_WRITER);
4197 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4198 + spin_unlock(&hf->f_lock);
4200 + h_inode = file_inode(hf);
4201 + if (hf->f_mode & FMODE_READ)
4202 + i_readcount_inc(h_inode);
4203 + put_write_access(h_inode);
4204 + __mnt_drop_write(hf->f_path.mnt);
4209 + au_farray_free(array, max);
4215 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4219 + aufs_bindex_t bindex;
4220 + struct dentry *root;
4221 + struct au_branch *br;
4222 + struct au_br_fhsm *bf;
4224 + root = sb->s_root;
4225 + bindex = au_find_dbindex(root, mod->h_root);
4228 + return 0; /* success */
4230 + pr_err("%s no such branch\n", mod->path);
4233 + AuDbg("bindex b%d\n", bindex);
4235 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4236 + if (unlikely(err))
4239 + br = au_sbr(sb, bindex);
4240 + AuDebugOn(mod->h_root != au_br_dentry(br));
4241 + if (br->br_perm == mod->perm)
4242 + return 0; /* success */
4244 + /* pre-allocate for non-fhsm --> fhsm */
4246 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4247 + err = au_fhsm_br_alloc(br);
4248 + if (unlikely(err))
4251 + br->br_fhsm = NULL;
4254 + if (au_br_writable(br->br_perm)) {
4255 + /* remove whiteout base */
4256 + err = au_br_init_wh(sb, br, mod->perm);
4257 + if (unlikely(err))
4260 + if (!au_br_writable(mod->perm)) {
4261 + /* rw --> ro, file might be mmapped */
4262 + DiMustNoWaiters(root);
4263 + IiMustNoWaiters(d_inode(root));
4264 + di_write_unlock(root);
4265 + err = au_br_mod_files_ro(sb, bindex);
4266 + /* aufs_write_lock() calls ..._child() */
4267 + di_write_lock_child(root);
4269 + if (unlikely(err)) {
4271 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4274 + rerr = au_wbr_init(br, sb, br->br_perm);
4275 + if (unlikely(rerr)) {
4276 + AuIOErr("nested error %d (%d)\n",
4278 + br->br_perm = mod->perm;
4282 + } else if (au_br_writable(mod->perm)) {
4285 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4287 + err = au_wbr_init(br, sb, mod->perm);
4288 + if (unlikely(err)) {
4289 + au_kfree_rcu(br->br_wbr);
4290 + br->br_wbr = NULL;
4294 + if (unlikely(err))
4297 + if (au_br_fhsm(br->br_perm)) {
4298 + if (!au_br_fhsm(mod->perm)) {
4299 + /* fhsm --> non-fhsm */
4300 + au_br_fhsm_fin(br->br_fhsm);
4301 + au_kfree_rcu(br->br_fhsm);
4302 + br->br_fhsm = NULL;
4304 + } else if (au_br_fhsm(mod->perm))
4305 + /* non-fhsm --> fhsm */
4308 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4309 + br->br_perm = mod->perm;
4310 + goto out; /* success */
4313 + au_kfree_try_rcu(bf);
4319 +/* ---------------------------------------------------------------------- */
4321 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4324 + struct kstatfs kstfs;
4326 + err = vfs_statfs(&br->br_path, &kstfs);
4328 + stfs->f_blocks = kstfs.f_blocks;
4329 + stfs->f_bavail = kstfs.f_bavail;
4330 + stfs->f_files = kstfs.f_files;
4331 + stfs->f_ffree = kstfs.f_ffree;
4336 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4337 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4338 +++ linux/fs/aufs/branch.h 2022-11-05 23:02:18.959222617 +0100
4340 +/* SPDX-License-Identifier: GPL-2.0 */
4342 + * Copyright (C) 2005-2022 Junjiro R. Okajima
4344 + * This program is free software; you can redistribute it and/or modify
4345 + * it under the terms of the GNU General Public License as published by
4346 + * the Free Software Foundation; either version 2 of the License, or
4347 + * (at your option) any later version.
4349 + * This program is distributed in the hope that it will be useful,
4350 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4351 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4352 + * GNU General Public License for more details.
4354 + * You should have received a copy of the GNU General Public License
4355 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4359 + * branch filesystems and xino for them
4362 +#ifndef __AUFS_BRANCH_H__
4363 +#define __AUFS_BRANCH_H__
4367 +#include <linux/mount.h>
4368 +#include "dirren.h"
4374 +/* ---------------------------------------------------------------------- */
4378 + struct file **xi_file;
4379 + unsigned int xi_nfile;
4385 + /* reserved for future use */
4386 + /* unsigned long *bitmap; */
4387 + wait_queue_head_t wqh;
4390 + struct mutex xi_mtx; /* protects xi_file array */
4391 + struct hlist_bl_head xi_writing;
4393 + atomic_t xi_truncating;
4395 + struct kref xi_kref;
4398 +/* File-based Hierarchical Storage Management */
4399 +struct au_br_fhsm {
4400 +#ifdef CONFIG_AUFS_FHSM
4401 + struct mutex bf_lock;
4402 + unsigned long bf_jiffy;
4403 + struct aufs_stfs bf_stfs;
4408 +/* members for writable branch only */
4409 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4411 + struct au_rwsem wbr_wh_rwsem;
4412 + struct dentry *wbr_wh[AuBrWh_Last];
4413 + atomic_t wbr_wh_running;
4414 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4415 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4416 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4419 + unsigned long long wbr_bytes;
4422 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4423 +#define AuBrDynOp (AuDyLast * 4)
4425 +#ifdef CONFIG_AUFS_HFSNOTIFY
4426 +/* support for asynchronous destruction */
4427 +struct au_br_hfsnotify {
4428 + struct fsnotify_group *hfsn_group;
4432 +/* sysfs entries */
4433 +struct au_brsysfs {
4435 + struct attribute attr;
4444 +/* protected by superblock rwsem */
4446 + struct au_xino *br_xino;
4448 + aufs_bindex_t br_id;
4451 + struct path br_path;
4452 + spinlock_t br_dykey_lock;
4453 + struct au_dykey *br_dykey[AuBrDynOp];
4454 + au_lcnt_t br_nfiles; /* opened files */
4455 + au_lcnt_t br_count; /* in-use for other */
4457 + struct au_wbr *br_wbr;
4458 + struct au_br_fhsm *br_fhsm;
4460 +#ifdef CONFIG_AUFS_HFSNOTIFY
4461 + struct au_br_hfsnotify *br_hfsn;
4464 +#ifdef CONFIG_SYSFS
4465 + /* entries under sysfs per mount-point */
4466 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4469 +#ifdef CONFIG_DEBUG_FS
4470 + struct dentry *br_dbgaufs; /* xino */
4473 + struct au_dr_br br_dirren;
4476 +/* ---------------------------------------------------------------------- */
4478 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4480 + return br->br_path.mnt;
4483 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4485 + return br->br_path.dentry;
4488 +static inline struct user_namespace *au_br_userns(struct au_branch *br)
4490 + return mnt_user_ns(br->br_path.mnt);
4493 +static inline struct super_block *au_br_sb(struct au_branch *br)
4495 + return au_br_mnt(br)->mnt_sb;
4498 +static inline int au_br_rdonly(struct au_branch *br)
4500 + return (sb_rdonly(au_br_sb(br))
4501 + || !au_br_writable(br->br_perm))
4505 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4507 +#ifdef CONFIG_AUFS_HNOTIFY
4508 + return !(brperm & AuBrPerm_RR);
4514 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4516 + int err, exec_flag;
4519 + exec_flag = oflag & __FMODE_EXEC;
4520 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4526 +static inline void au_xino_get(struct au_branch *br)
4528 + struct au_xino *xi;
4532 + kref_get(&xi->xi_kref);
4535 +static inline int au_xino_count(struct au_branch *br)
4538 + struct au_xino *xi;
4543 + v = kref_read(&xi->xi_kref);
4548 +/* ---------------------------------------------------------------------- */
4552 +void au_br_free(struct au_sbinfo *sinfo);
4553 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4555 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4557 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4558 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4559 +#ifdef CONFIG_COMPAT
4560 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4563 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4566 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4569 +static const loff_t au_loff_max = LLONG_MAX;
4571 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4572 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4574 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4575 + struct file *copy_src);
4577 + struct au_xino *xi; /* switch between xino and xigen */
4579 + struct path *base;
4580 + struct file *copy_src;
4582 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4584 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4586 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4588 +ssize_t xino_fread(struct file *file, void *buf, size_t size, loff_t *pos);
4589 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos);
4591 +int au_xib_trunc(struct super_block *sb);
4592 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4594 +struct au_xino *au_xino_alloc(unsigned int nfile);
4595 +int au_xino_put(struct au_branch *br);
4596 +struct file *au_xino_file1(struct au_xino *xi);
4598 +struct au_opt_xino;
4599 +void au_xino_clr(struct super_block *sb);
4600 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4601 +struct file *au_xino_def(struct super_block *sb);
4602 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4603 + struct path *base);
4605 +ino_t au_xino_new_ino(struct super_block *sb);
4606 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4608 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4609 + ino_t h_ino, int idx);
4610 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4613 +int au_xino_path(struct seq_file *seq, struct file *file);
4615 +/* ---------------------------------------------------------------------- */
4617 +/* @idx is signed to accept -1 meaning the first file */
4618 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4620 + struct file *file;
4627 + if (idx < xi->xi_nfile)
4628 + file = xi->xi_file[idx];
4630 + file = au_xino_file1(xi);
4636 +/* ---------------------------------------------------------------------- */
4638 +/* Superblock to branch */
4640 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4642 + return au_sbr(sb, bindex)->br_id;
4646 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4648 + return au_br_mnt(au_sbr(sb, bindex));
4652 +struct user_namespace *au_sbr_userns(struct super_block *sb, aufs_bindex_t bindex)
4654 + return au_br_userns(au_sbr(sb, bindex));
4658 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4660 + return au_br_sb(au_sbr(sb, bindex));
4663 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4665 + return au_sbr(sb, bindex)->br_perm;
4668 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4670 + return au_br_whable(au_sbr_perm(sb, bindex));
4673 +/* ---------------------------------------------------------------------- */
4675 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4676 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4677 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4678 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4680 +#define wbr_wh_read_trylock_nested(wbr) \
4681 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4682 +#define wbr_wh_write_trylock_nested(wbr) \
4683 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4686 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4687 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4688 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4690 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4691 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4692 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4694 +/* ---------------------------------------------------------------------- */
4696 +#ifdef CONFIG_AUFS_FHSM
4697 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4699 + mutex_init(&brfhsm->bf_lock);
4700 + brfhsm->bf_jiffy = 0;
4701 + brfhsm->bf_readable = 0;
4704 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4706 + mutex_destroy(&brfhsm->bf_lock);
4709 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4710 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4713 +#endif /* __KERNEL__ */
4714 +#endif /* __AUFS_BRANCH_H__ */
4715 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4716 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4717 +++ linux/fs/aufs/conf.mk 2022-11-05 23:02:18.959222617 +0100
4719 +# SPDX-License-Identifier: GPL-2.0
4721 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4725 +AuConfStr += ${1}=${${1}}
4729 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4731 + HNOTIFY HFSNOTIFY \
4743 +$(foreach i, ${AuConfAll}, \
4744 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4746 +AuConfName = ${obj}/conf.str
4747 +${AuConfName}.tmp: FORCE
4748 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4749 +${AuConfName}: ${AuConfName}.tmp
4750 + @diff -q $< $@ > /dev/null 2>&1 || { \
4751 + echo ' GEN ' $@; \
4755 +clean-files += ${AuConfName} ${AuConfName}.tmp
4756 +${obj}/sysfs.o: ${AuConfName}
4758 +-include ${srctree}/${src}/conf_priv.mk
4759 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4760 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4761 +++ linux/fs/aufs/cpup.c 2022-11-05 23:02:18.962555950 +0100
4763 +// SPDX-License-Identifier: GPL-2.0
4765 + * Copyright (C) 2005-2022 Junjiro R. Okajima
4767 + * This program is free software; you can redistribute it and/or modify
4768 + * it under the terms of the GNU General Public License as published by
4769 + * the Free Software Foundation; either version 2 of the License, or
4770 + * (at your option) any later version.
4772 + * This program is distributed in the hope that it will be useful,
4773 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4774 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4775 + * GNU General Public License for more details.
4777 + * You should have received a copy of the GNU General Public License
4778 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4782 + * copy-up functions, see wbr_policy.c for copy-down
4785 +#include <linux/fs_stack.h>
4786 +#include <linux/mm.h>
4787 +#include <linux/task_work.h>
4790 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4792 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4793 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4795 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4797 + dst->i_flags |= iflags & ~mask;
4798 + if (au_test_fs_notime(dst->i_sb))
4799 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4802 +void au_cpup_attr_timesizes(struct inode *inode)
4804 + struct inode *h_inode;
4806 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4807 + fsstack_copy_attr_times(inode, h_inode);
4808 + fsstack_copy_inode_size(inode, h_inode);
4811 +void au_cpup_attr_nlink(struct inode *inode, int force)
4813 + struct inode *h_inode;
4814 + struct super_block *sb;
4815 + aufs_bindex_t bindex, bbot;
4818 + bindex = au_ibtop(inode);
4819 + h_inode = au_h_iptr(inode, bindex);
4821 + && !S_ISDIR(h_inode->i_mode)
4822 + && au_opt_test(au_mntflags(sb), PLINK)
4823 + && au_plink_test(inode))
4827 + * 0 can happen in revalidating.
4828 + * h_inode->i_mutex may not be held here, but it is harmless since once
4829 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4831 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4832 + * the incorrect link count.
4834 + set_nlink(inode, h_inode->i_nlink);
4837 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4838 + * it may includes whplink directory.
4840 + if (S_ISDIR(h_inode->i_mode)) {
4841 + bbot = au_ibbot(inode);
4842 + for (bindex++; bindex <= bbot; bindex++) {
4843 + h_inode = au_h_iptr(inode, bindex);
4845 + au_add_nlink(inode, h_inode);
4850 +void au_cpup_attr_changeable(struct inode *inode)
4852 + struct inode *h_inode;
4854 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4855 + inode->i_mode = h_inode->i_mode;
4856 + inode->i_uid = h_inode->i_uid;
4857 + inode->i_gid = h_inode->i_gid;
4858 + au_cpup_attr_timesizes(inode);
4859 + au_cpup_attr_flags(inode, h_inode->i_flags);
4862 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4864 + struct au_iinfo *iinfo = au_ii(inode);
4866 + IiMustWriteLock(inode);
4868 + iinfo->ii_higen = h_inode->i_generation;
4869 + iinfo->ii_hsb1 = h_inode->i_sb;
4872 +void au_cpup_attr_all(struct inode *inode, int force)
4874 + struct inode *h_inode;
4876 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4877 + au_cpup_attr_changeable(inode);
4878 + if (inode->i_nlink > 0)
4879 + au_cpup_attr_nlink(inode, force);
4880 + inode->i_rdev = h_inode->i_rdev;
4881 + inode->i_blkbits = h_inode->i_blkbits;
4882 + au_cpup_igen(inode, h_inode);
4885 +/* ---------------------------------------------------------------------- */
4887 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4889 +/* keep the timestamps of the parent dir when cpup */
4890 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4891 + struct path *h_path)
4893 + struct inode *h_inode;
4895 + dt->dt_dentry = dentry;
4896 + dt->dt_h_path = *h_path;
4897 + h_inode = d_inode(h_path->dentry);
4898 + dt->dt_atime = h_inode->i_atime;
4899 + dt->dt_mtime = h_inode->i_mtime;
4903 +void au_dtime_revert(struct au_dtime *dt)
4905 + struct iattr attr;
4908 + attr.ia_atime = dt->dt_atime;
4909 + attr.ia_mtime = dt->dt_mtime;
4910 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4911 + | ATTR_ATIME | ATTR_ATIME_SET;
4913 + /* no delegation since this is a directory */
4914 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4915 + if (unlikely(err))
4916 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4919 +/* ---------------------------------------------------------------------- */
4921 +/* internal use only */
4922 +struct au_cpup_reg_attr {
4925 + unsigned int iflags; /* inode->i_flags */
4928 +static noinline_for_stack
4929 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct path *h_src,
4930 + struct au_cpup_reg_attr *h_src_attr)
4932 + int err, sbits, icex;
4933 + unsigned int mnt_flags;
4934 + unsigned char verbose;
4936 + struct path h_path;
4937 + struct inode *h_isrc, *h_idst;
4938 + struct kstat *h_st;
4939 + struct au_branch *br;
4941 + br = au_sbr(dst->d_sb, bindex);
4942 + h_path.mnt = au_br_mnt(br);
4943 + h_path.dentry = au_h_dptr(dst, bindex);
4944 + h_idst = d_inode(h_path.dentry);
4945 + h_isrc = d_inode(h_src->dentry);
4946 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4947 + | ATTR_ATIME | ATTR_MTIME
4948 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4949 + if (h_src_attr && h_src_attr->valid) {
4950 + h_st = &h_src_attr->st;
4951 + ia.ia_uid = h_st->uid;
4952 + ia.ia_gid = h_st->gid;
4953 + ia.ia_atime = h_st->atime;
4954 + ia.ia_mtime = h_st->mtime;
4955 + if (h_idst->i_mode != h_st->mode
4956 + && !S_ISLNK(h_idst->i_mode)) {
4957 + ia.ia_valid |= ATTR_MODE;
4958 + ia.ia_mode = h_st->mode;
4960 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4961 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4963 + ia.ia_uid = h_isrc->i_uid;
4964 + ia.ia_gid = h_isrc->i_gid;
4965 + ia.ia_atime = h_isrc->i_atime;
4966 + ia.ia_mtime = h_isrc->i_mtime;
4967 + if (h_idst->i_mode != h_isrc->i_mode
4968 + && !S_ISLNK(h_idst->i_mode)) {
4969 + ia.ia_valid |= ATTR_MODE;
4970 + ia.ia_mode = h_isrc->i_mode;
4972 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4973 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4975 + /* no delegation since it is just created */
4976 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4978 + /* is this nfs only? */
4979 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4980 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4981 + ia.ia_mode = h_isrc->i_mode;
4982 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4985 + icex = br->br_perm & AuBrAttr_ICEX;
4987 + mnt_flags = au_mntflags(dst->d_sb);
4988 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4989 + err = au_cpup_xattr(&h_path, h_src, icex, verbose);
4995 +/* ---------------------------------------------------------------------- */
4997 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4998 + char *buf, unsigned long blksize)
5001 + size_t sz, rbytes, wbytes;
5002 + unsigned char all_zero;
5004 + struct inode *h_inode;
5005 + /* reduce stack usage */
5008 + zp = page_address(ZERO_PAGE(0));
5009 + if (unlikely(!zp))
5010 + return -ENOMEM; /* possible? */
5015 + AuDbg("len %lld\n", len);
5017 + if (len < blksize)
5021 + /* todo: signal_pending? */
5022 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5023 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5026 + if (unlikely(err < 0))
5030 + if (len >= rbytes && rbytes == blksize)
5031 + all_zero = !memcmp(buf, zp, rbytes);
5038 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5040 + /* todo: signal_pending? */
5041 + if (unlikely(err == -EAGAIN || err == -EINTR))
5043 + if (unlikely(err < 0))
5048 + if (unlikely(err < 0))
5054 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5056 + if (unlikely(res < 0))
5063 + /* the last block may be a hole */
5064 + if (!err && all_zero) {
5065 + AuLabel(last hole);
5068 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5069 + /* nfs requires this step to make last hole */
5070 + /* is this only nfs? */
5072 + /* todo: signal_pending? */
5073 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5074 + } while (err == -EAGAIN || err == -EINTR);
5081 + ia->ia_size = dst->f_pos;
5082 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5083 + ia->ia_file = dst;
5084 + h_inode = file_inode(dst);
5085 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5086 + /* no delegation since it is just created */
5087 + err = vfsub_notify_change(&dst->f_path, ia,
5088 + /*delegated*/NULL);
5089 + inode_unlock(h_inode);
5096 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5099 + unsigned long blksize;
5100 + unsigned char do_kfree;
5102 + struct super_block *h_sb;
5105 + h_sb = file_inode(dst)->i_sb;
5106 + blksize = h_sb->s_blocksize;
5107 + if (!blksize || PAGE_SIZE < blksize)
5108 + blksize = PAGE_SIZE;
5109 + AuDbg("blksize %lu\n", blksize);
5110 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5112 + buf = kmalloc(blksize, GFP_NOFS);
5114 + buf = (void *)__get_free_page(GFP_NOFS);
5115 + if (unlikely(!buf))
5118 + if (len > (1 << 22))
5119 + AuDbg("copying a large file %lld\n", (long long)len);
5123 + err = au_do_copy_file(dst, src, len, buf, blksize);
5125 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5126 + au_kfree_do_rcu(buf);
5128 + free_page((unsigned long)buf);
5134 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5137 + struct super_block *h_src_sb;
5138 + struct inode *h_src_inode;
5140 + h_src_inode = file_inode(src);
5141 + h_src_sb = h_src_inode->i_sb;
5143 + /* XFS acquires inode_lock */
5144 + if (!au_test_xfs(h_src_sb))
5145 + err = au_copy_file(dst, src, len);
5147 + inode_unlock_shared(h_src_inode);
5148 + err = au_copy_file(dst, src, len);
5149 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5155 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5159 + struct super_block *h_src_sb;
5160 + struct inode *h_src_inode;
5162 + h_src_inode = file_inode(src);
5163 + h_src_sb = h_src_inode->i_sb;
5164 + if (h_src_sb != file_inode(dst)->i_sb
5165 + || !dst->f_op->remap_file_range) {
5166 + err = au_do_copy(dst, src, len);
5170 + if (!au_test_nfs(h_src_sb)) {
5171 + inode_unlock_shared(h_src_inode);
5172 + lo = vfsub_clone_file_range(src, dst, len);
5173 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5175 + lo = vfsub_clone_file_range(src, dst, len);
5178 + goto out; /* success */
5179 + } else if (lo >= 0)
5180 + /* todo: possible? */
5181 + /* paritially succeeded */
5182 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5183 + else if (lo != -EOPNOTSUPP) {
5184 + /* older XFS has a condition in cloning */
5189 + /* the backend fs on NFS may not support cloning */
5190 + err = au_do_copy(dst, src, len);
5198 + * to support a sparse file which is opened with O_APPEND,
5199 + * we need to close the file.
5201 +static int au_cp_regular(struct au_cp_generic *cpg)
5204 + enum { SRC, DST };
5206 + aufs_bindex_t bindex;
5207 + unsigned int flags;
5208 + struct dentry *dentry;
5210 + struct file *file;
5213 + .bindex = cpg->bsrc,
5214 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5217 + .bindex = cpg->bdst,
5218 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5219 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5222 + struct au_branch *br;
5223 + struct super_block *sb, *h_src_sb;
5224 + struct inode *h_src_inode;
5225 + struct task_struct *tsk = current;
5227 + /* bsrc branch can be ro/rw. */
5228 + sb = cpg->dentry->d_sb;
5230 + for (i = 0; i < 2; i++, f++) {
5231 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5232 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5233 + /*file*/NULL, f->force_wr);
5234 + if (IS_ERR(f->file)) {
5235 + err = PTR_ERR(f->file);
5243 + /* try stopping to update while we copyup */
5244 + h_src_inode = d_inode(file[SRC].dentry);
5245 + h_src_sb = h_src_inode->i_sb;
5246 + if (!au_test_nfs(h_src_sb))
5247 + IMustLock(h_src_inode);
5248 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5250 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5251 + if (tsk->flags & PF_KTHREAD)
5252 + __fput_sync(file[DST].file);
5254 + /* it happened actually */
5255 + fput(file[DST].file);
5258 + * we have to call both since we don't know which place the file
5262 + flush_delayed_fput();
5264 + br = au_sbr(sb, file[DST].bindex);
5265 + au_lcnt_dec(&br->br_nfiles);
5268 + fput(file[SRC].file);
5269 + br = au_sbr(sb, file[SRC].bindex);
5270 + au_lcnt_dec(&br->br_nfiles);
5275 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5276 + struct au_cpup_reg_attr *h_src_attr)
5280 + struct path h_path;
5281 + struct inode *h_src_inode, *h_dst_inode;
5284 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5285 + l = i_size_read(h_src_inode);
5286 + if (cpg->len == -1 || l < cpg->len)
5289 + /* try stopping to update while we are referencing */
5290 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5291 + au_pin_hdir_unlock(cpg->pin);
5293 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5294 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5295 + h_src_attr->iflags = h_src_inode->i_flags;
5296 + if (!au_test_nfs(h_src_inode->i_sb))
5297 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5299 + inode_unlock_shared(h_src_inode);
5300 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5301 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5303 + if (unlikely(err)) {
5304 + inode_unlock_shared(h_src_inode);
5307 + h_src_attr->valid = 1;
5308 + if (!au_test_nfs(h_src_inode->i_sb)) {
5309 + err = au_cp_regular(cpg);
5310 + inode_unlock_shared(h_src_inode);
5312 + inode_unlock_shared(h_src_inode);
5313 + err = au_cp_regular(cpg);
5315 + rerr = au_pin_hdir_relock(cpg->pin);
5319 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5320 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5321 + h_dst_inode = d_inode(h_path.dentry);
5322 + spin_lock(&h_dst_inode->i_lock);
5323 + h_dst_inode->i_state |= I_LINKABLE;
5324 + spin_unlock(&h_dst_inode->i_lock);
5331 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5332 + struct inode *h_dir)
5335 + DEFINE_DELAYED_CALL(done);
5338 + sym = vfs_get_link(h_src, &done);
5339 + err = PTR_ERR(sym);
5343 + err = vfsub_symlink(h_dir, h_path, sym);
5346 + do_delayed_call(&done);
5351 + * regardless 'acl' option, reset all ACL.
5352 + * All ACL will be copied up later from the original entry on the lower branch.
5354 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5357 + struct dentry *h_dentry;
5358 + struct inode *h_inode;
5359 + struct user_namespace *h_userns;
5361 + h_userns = mnt_user_ns(h_path->mnt);
5362 + h_dentry = h_path->dentry;
5363 + h_inode = d_inode(h_dentry);
5364 + /* forget_all_cached_acls(h_inode)); */
5365 + err = vfsub_removexattr(h_userns, h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5367 + if (err == -EOPNOTSUPP)
5370 + err = vfsub_acl_chmod(h_userns, h_inode, mode);
5376 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5377 + struct inode *h_dir, struct path *h_path)
5380 + struct inode *dir, *inode;
5381 + struct user_namespace *h_userns;
5383 + h_userns = mnt_user_ns(h_path->mnt);
5384 + err = vfsub_removexattr(h_userns, h_path->dentry,
5385 + XATTR_NAME_POSIX_ACL_DEFAULT);
5387 + if (err == -EOPNOTSUPP)
5389 + if (unlikely(err))
5393 + * strange behaviour from the users view,
5394 + * particularly setattr case
5396 + dir = d_inode(dst_parent);
5397 + if (au_ibtop(dir) == cpg->bdst)
5398 + au_cpup_attr_nlink(dir, /*force*/1);
5399 + inode = d_inode(cpg->dentry);
5400 + au_cpup_attr_nlink(inode, /*force*/1);
5406 +static noinline_for_stack
5407 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5408 + struct au_cpup_reg_attr *h_src_attr)
5412 + unsigned int mnt_flags;
5413 + unsigned char isdir, isreg, force;
5414 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5415 + struct au_dtime dt;
5416 + struct path h_path;
5417 + struct dentry *h_src, *h_dst, *h_parent;
5418 + struct inode *h_inode, *h_dir;
5419 + struct super_block *sb;
5421 + /* bsrc branch can be ro/rw. */
5422 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5423 + h_inode = d_inode(h_src);
5424 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5426 + /* try stopping to be referenced while we are creating */
5427 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5428 + if (au_ftest_cpup(cpg->flags, RENAME))
5429 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5430 + AUFS_WH_PFX_LEN));
5431 + h_parent = h_dst->d_parent; /* dir inode is locked */
5432 + h_dir = d_inode(h_parent);
5434 + AuDebugOn(h_parent != h_dst->d_parent);
5436 + sb = cpg->dentry->d_sb;
5437 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5439 + h_path.dentry = h_parent;
5440 + au_dtime_store(&dt, dst_parent, &h_path);
5442 + h_path.dentry = h_dst;
5446 + mode = h_inode->i_mode;
5447 + switch (mode & S_IFMT) {
5450 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5452 + err = au_do_cpup_regular(cpg, h_src_attr);
5456 + err = vfsub_mkdir(h_dir, &h_path, mode);
5458 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5461 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5465 + AuDebugOn(!capable(CAP_MKNOD));
5469 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5472 + AuIOErr("Unknown inode type 0%o\n", mode);
5476 + err = au_reset_acl(h_dir, &h_path, mode);
5478 + mnt_flags = au_mntflags(sb);
5479 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5481 + && au_opt_test(mnt_flags, XINO)
5482 + && (h_inode->i_nlink == 1
5483 + || (h_inode->i_state & I_LINKABLE))
5484 + /* todo: unnecessary? */
5485 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5486 + && cpg->bdst < cpg->bsrc
5487 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5488 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5489 + /* ignore this error */
5494 + force = !!cpg->len;
5495 + if (cpg->len == -1)
5496 + force = !!i_size_read(h_inode);
5498 + au_fhsm_wrote(sb, cpg->bdst, force);
5502 + au_dtime_revert(&dt);
5506 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5509 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5510 + struct path h_ppath;
5511 + struct inode *h_dir;
5512 + aufs_bindex_t bdst;
5514 + dentry = cpg->dentry;
5516 + h_ppath.mnt = au_sbr_mnt(dentry->d_sb, bdst);
5517 + h_dentry = au_h_dptr(dentry, bdst);
5518 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5520 + au_set_h_dptr(dentry, bdst, NULL);
5521 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5523 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5524 + au_set_h_dptr(dentry, bdst, h_dentry);
5527 + parent = dget_parent(dentry);
5528 + h_ppath.dentry = au_h_dptr(parent, bdst);
5530 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, &h_ppath);
5531 + if (IS_ERR(h_path->dentry))
5532 + err = PTR_ERR(h_path->dentry);
5534 + if (unlikely(err))
5537 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5538 + h_dir = d_inode(h_parent);
5540 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5541 + /* no delegation since it is just created */
5542 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5544 + dput(h_path->dentry);
5551 + * copyup the @dentry from @bsrc to @bdst.
5552 + * the caller must set the both of lower dentries.
5553 + * @len is for truncating when it is -1 copyup the entire file.
5554 + * in link/rename cases, @dst_parent may be different from the real one.
5555 + * basic->bsrc can be larger than basic->bdst.
5556 + * aufs doesn't touch the credential so
5557 + * security_inode_copy_up{,_xattr}() are unnecessary.
5559 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5562 + aufs_bindex_t old_ibtop;
5563 + unsigned char isdir, plink;
5564 + struct dentry *h_src, *h_dst, *h_parent;
5565 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5566 + struct super_block *sb;
5567 + struct au_branch *br;
5568 + struct path h_src_path;
5569 + /* to reduce stack size */
5571 + struct au_dtime dt;
5572 + struct path h_path;
5573 + struct au_cpup_reg_attr h_src_attr;
5577 + a = kmalloc(sizeof(*a), GFP_NOFS);
5580 + a->h_src_attr.valid = 0;
5582 + sb = cpg->dentry->d_sb;
5583 + br = au_sbr(sb, cpg->bdst);
5584 + a->h_path.mnt = au_br_mnt(br);
5585 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5586 + h_parent = h_dst->d_parent; /* dir inode is locked */
5587 + h_dir = d_inode(h_parent);
5590 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5591 + inode = d_inode(cpg->dentry);
5594 + dst_parent = dget_parent(cpg->dentry);
5598 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5599 + dst_inode = au_h_iptr(inode, cpg->bdst);
5601 + if (unlikely(!plink)) {
5603 + AuIOErr("hi%lu(i%lu) exists on b%d "
5604 + "but plink is disabled\n",
5605 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5609 + if (dst_inode->i_nlink) {
5610 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5612 + h_src = au_plink_lkup(inode, cpg->bdst);
5613 + err = PTR_ERR(h_src);
5614 + if (IS_ERR(h_src))
5616 + if (unlikely(d_is_negative(h_src))) {
5618 + AuIOErr("i%lu exists on b%d "
5619 + "but not pseudo-linked\n",
5620 + inode->i_ino, cpg->bdst);
5626 + a->h_path.dentry = h_parent;
5627 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5630 + a->h_path.dentry = h_dst;
5632 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5633 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5634 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5636 + au_dtime_revert(&a->dt);
5637 + if (unlikely(err == -EWOULDBLOCK)) {
5638 + pr_warn("cannot retry for NFSv4 delegation"
5639 + " for an internal link\n");
5645 + /* todo: cpup_wh_file? */
5647 + au_update_ibrange(inode, /*do_put_zero*/1);
5650 + isdir = S_ISDIR(inode->i_mode);
5651 + old_ibtop = au_ibtop(inode);
5652 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5653 + if (unlikely(err))
5655 + dst_inode = d_inode(h_dst);
5656 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5657 + /* todo: necessary? */
5658 + /* au_pin_hdir_unlock(cpg->pin); */
5660 + h_src_path.dentry = h_src;
5661 + h_src_path.mnt = au_sbr_mnt(sb, cpg->bsrc);
5662 + err = cpup_iattr(cpg->dentry, cpg->bdst, &h_src_path, &a->h_src_attr);
5663 + if (unlikely(err)) {
5664 + /* todo: necessary? */
5665 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5666 + inode_unlock(dst_inode);
5670 + if (cpg->bdst < old_ibtop) {
5671 + if (S_ISREG(inode->i_mode)) {
5672 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5673 + if (unlikely(err)) {
5674 + /* ignore an error */
5675 + /* au_pin_hdir_relock(cpg->pin); */
5676 + inode_unlock(dst_inode);
5680 + au_set_ibtop(inode, cpg->bdst);
5682 + au_set_ibbot(inode, cpg->bdst);
5683 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5684 + au_hi_flags(inode, isdir));
5686 + /* todo: necessary? */
5687 + /* err = au_pin_hdir_relock(cpg->pin); */
5688 + inode_unlock(dst_inode);
5689 + if (unlikely(err))
5692 + src_inode = d_inode(h_src);
5694 + && (src_inode->i_nlink > 1
5695 + || src_inode->i_state & I_LINKABLE)
5697 + au_plink_append(inode, cpg->bdst, h_dst);
5699 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5700 + a->h_path.dentry = h_dst;
5701 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5704 + goto out_parent; /* success */
5708 + a->h_path.dentry = h_parent;
5709 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5710 + a->h_path.dentry = h_dst;
5712 + if (d_is_positive(h_dst)) {
5714 + /* no delegation since it is just created */
5715 + rerr = vfsub_unlink(h_dir, &a->h_path,
5716 + /*delegated*/NULL, /*force*/0);
5718 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5720 + au_dtime_revert(&a->dt);
5722 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5732 +#if 0 /* reserved */
5733 +struct au_cpup_single_args {
5735 + struct au_cp_generic *cpg;
5736 + struct dentry *dst_parent;
5739 +static void au_call_cpup_single(void *args)
5741 + struct au_cpup_single_args *a = args;
5743 + au_pin_hdir_acquire_nest(a->cpg->pin);
5744 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5745 + au_pin_hdir_release(a->cpg->pin);
5750 + * prevent SIGXFSZ in copy-up.
5751 + * testing CAP_MKNOD is for generic fs,
5752 + * but CAP_FSETID is for xfs only, currently.
5754 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5757 + struct super_block *sb;
5758 + struct inode *h_dir;
5761 + sb = au_pinned_parent(pin)->d_sb;
5762 + if (!au_wkq_test()
5763 + && (!au_sbi(sb)->si_plink_maint_pid
5764 + || au_plink_maint(sb, AuLock_NOPLM))) {
5765 + switch (mode & S_IFMT) {
5767 + /* no condition about RLIMIT_FSIZE and the file size */
5772 + do_sio = !capable(CAP_MKNOD);
5776 + do_sio = ((mode & (S_ISUID | S_ISGID))
5777 + && !capable(CAP_FSETID));
5778 + /* this workaround may be removed in the future */
5780 + h_dir = au_pinned_h_dir(pin);
5781 + do_sio = h_dir->i_mode & S_ISVTX;
5788 +#if 0 /* reserved */
5789 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5792 + struct dentry *h_dentry;
5794 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5795 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5796 + err = au_cpup_single(cpg, dst_parent);
5798 + struct au_cpup_single_args args = {
5801 + .dst_parent = dst_parent
5803 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5804 + if (unlikely(wkq_err))
5813 + * copyup the @dentry from the first active lower branch to @bdst,
5814 + * using au_cpup_single().
5816 +static int au_cpup_simple(struct au_cp_generic *cpg)
5819 + unsigned int flags_orig;
5820 + struct dentry *dentry;
5822 + AuDebugOn(cpg->bsrc < 0);
5824 + dentry = cpg->dentry;
5825 + DiMustWriteLock(dentry);
5827 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5829 + flags_orig = cpg->flags;
5830 + au_fset_cpup(cpg->flags, RENAME);
5831 + err = au_cpup_single(cpg, NULL);
5832 + cpg->flags = flags_orig;
5834 + return 0; /* success */
5837 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5838 + au_set_dbtop(dentry, cpg->bsrc);
5844 +struct au_cpup_simple_args {
5846 + struct au_cp_generic *cpg;
5849 +static void au_call_cpup_simple(void *args)
5851 + struct au_cpup_simple_args *a = args;
5853 + au_pin_hdir_acquire_nest(a->cpg->pin);
5854 + *a->errp = au_cpup_simple(a->cpg);
5855 + au_pin_hdir_release(a->cpg->pin);
5858 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5861 + struct dentry *dentry, *parent;
5862 + struct file *h_file;
5863 + struct inode *h_dir;
5864 + struct user_namespace *h_userns;
5866 + dentry = cpg->dentry;
5868 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5869 + AuDebugOn(cpg->bsrc < 0);
5870 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5871 + err = PTR_ERR(h_file);
5872 + if (IS_ERR(h_file))
5876 + parent = dget_parent(dentry);
5877 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5878 + h_userns = au_sbr_userns(dentry->d_sb, cpg->bdst);
5879 + if (!au_test_h_perm_sio(h_userns, h_dir, MAY_EXEC | MAY_WRITE)
5880 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5881 + err = au_cpup_simple(cpg);
5883 + struct au_cpup_simple_args args = {
5887 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5888 + if (unlikely(wkq_err))
5894 + au_h_open_post(dentry, cpg->bsrc, h_file);
5900 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5902 + aufs_bindex_t bsrc, bbot;
5903 + struct dentry *dentry, *h_dentry;
5905 + if (cpg->bsrc < 0) {
5906 + dentry = cpg->dentry;
5907 + bbot = au_dbbot(dentry);
5908 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5909 + h_dentry = au_h_dptr(dentry, bsrc);
5911 + AuDebugOn(d_is_negative(h_dentry));
5915 + AuDebugOn(bsrc > bbot);
5918 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5919 + return au_do_sio_cpup_simple(cpg);
5922 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5924 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5925 + return au_do_sio_cpup_simple(cpg);
5928 +/* ---------------------------------------------------------------------- */
5931 + * copyup the deleted file for writing.
5933 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5934 + struct file *file)
5937 + unsigned int flags_orig;
5938 + aufs_bindex_t bsrc_orig;
5939 + struct au_dinfo *dinfo;
5941 + struct au_hdentry *hd;
5942 + struct dentry *h_dentry;
5945 + dinfo = au_di(cpg->dentry);
5946 + AuRwMustWriteLock(&dinfo->di_rwsem);
5948 + bsrc_orig = cpg->bsrc;
5949 + cpg->bsrc = dinfo->di_btop;
5950 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5951 + hdst.h_dentry = hdst.hd->hd_dentry;
5952 + hdst.hd->hd_dentry = wh_dentry;
5953 + dinfo->di_btop = cpg->bdst;
5955 + hsrc.h_dentry = NULL;
5957 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5958 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5959 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5961 + flags_orig = cpg->flags;
5962 + cpg->flags = !AuCpup_DTIME;
5963 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5964 + cpg->flags = flags_orig;
5967 + err = au_reopen_nondir(file);
5968 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5970 + hdst.hd->hd_dentry = hdst.h_dentry;
5971 + dinfo->di_btop = cpg->bsrc;
5972 + cpg->bsrc = bsrc_orig;
5977 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5980 + aufs_bindex_t bdst;
5981 + struct au_dtime dt;
5982 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5983 + struct au_branch *br;
5984 + struct path h_path;
5986 + dentry = cpg->dentry;
5988 + br = au_sbr(dentry->d_sb, bdst);
5989 + parent = dget_parent(dentry);
5990 + h_parent = au_h_dptr(parent, bdst);
5991 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5992 + err = PTR_ERR(wh_dentry);
5993 + if (IS_ERR(wh_dentry))
5996 + h_path.dentry = h_parent;
5997 + h_path.mnt = au_br_mnt(br);
5998 + au_dtime_store(&dt, parent, &h_path);
5999 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6000 + if (unlikely(err))
6004 + h_path.dentry = wh_dentry;
6005 + if (!d_is_dir(wh_dentry)) {
6006 + /* no delegation since it is just created */
6007 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6008 + /*delegated*/NULL, /*force*/0);
6010 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6011 + if (unlikely(err)) {
6012 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6016 + au_dtime_revert(&dt);
6017 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6026 +struct au_cpup_wh_args {
6028 + struct au_cp_generic *cpg;
6029 + struct file *file;
6032 +static void au_call_cpup_wh(void *args)
6034 + struct au_cpup_wh_args *a = args;
6036 + au_pin_hdir_acquire_nest(a->cpg->pin);
6037 + *a->errp = au_cpup_wh(a->cpg, a->file);
6038 + au_pin_hdir_release(a->cpg->pin);
6041 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6044 + aufs_bindex_t bdst;
6045 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6046 + struct inode *dir, *h_dir, *h_tmpdir;
6047 + struct au_wbr *wbr;
6048 + struct au_pin wh_pin, *pin_orig;
6049 + struct user_namespace *h_userns;
6051 + dentry = cpg->dentry;
6053 + parent = dget_parent(dentry);
6054 + dir = d_inode(parent);
6057 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6060 + if (!h_dir->i_nlink) {
6061 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6062 + h_orph = wbr->wbr_orph;
6064 + h_parent = dget(au_h_dptr(parent, bdst));
6065 + au_set_h_dptr(parent, bdst, dget(h_orph));
6066 + h_tmpdir = d_inode(h_orph);
6067 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6069 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6070 + /* todo: au_h_open_pre()? */
6072 + pin_orig = cpg->pin;
6073 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6074 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6075 + cpg->pin = &wh_pin;
6078 + h_userns = au_sbr_userns(dentry->d_sb, bdst);
6079 + if (!au_test_h_perm_sio(h_userns, h_tmpdir, MAY_EXEC | MAY_WRITE)
6080 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6081 + err = au_cpup_wh(cpg, file);
6083 + struct au_cpup_wh_args args = {
6088 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6089 + if (unlikely(wkq_err))
6094 + inode_unlock(h_tmpdir);
6095 + /* todo: au_h_open_post()? */
6096 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6097 + au_set_h_dptr(parent, bdst, h_parent);
6098 + AuDebugOn(!pin_orig);
6099 + cpg->pin = pin_orig;
6107 +/* ---------------------------------------------------------------------- */
6110 + * generic routine for both of copy-up and copy-down.
6112 +/* cf. revalidate function in file.c */
6113 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6114 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6115 + struct au_pin *pin,
6116 + struct dentry *h_parent, void *arg),
6120 + struct au_pin pin;
6121 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6124 + parent = dget_parent(dentry);
6125 + if (IS_ROOT(parent))
6128 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6129 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6131 + /* do not use au_dpage */
6132 + real_parent = parent;
6135 + parent = dget_parent(dentry);
6136 + h_parent = au_h_dptr(parent, bdst);
6138 + goto out; /* success */
6140 + /* find top dir which is necessary to cpup */
6144 + parent = dget_parent(d);
6145 + di_read_lock_parent3(parent, !AuLock_IR);
6146 + h_parent = au_h_dptr(parent, bdst);
6147 + di_read_unlock(parent, !AuLock_IR);
6148 + } while (!h_parent);
6150 + if (d != real_parent)
6151 + di_write_lock_child3(d);
6153 + /* somebody else might create while we were sleeping */
6154 + h_dentry = au_h_dptr(d, bdst);
6155 + if (!h_dentry || d_is_negative(h_dentry)) {
6157 + au_update_dbtop(d);
6159 + au_pin_set_dentry(&pin, d);
6160 + err = au_do_pin(&pin);
6162 + err = cp(d, bdst, &pin, h_parent, arg);
6167 + if (d != real_parent)
6168 + di_write_unlock(d);
6169 + if (unlikely(err))
6178 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6179 + struct au_pin *pin,
6180 + struct dentry *h_parent __maybe_unused,
6181 + void *arg __maybe_unused)
6183 + struct au_cp_generic cpg = {
6189 + .flags = AuCpup_DTIME
6191 + return au_sio_cpup_simple(&cpg);
6194 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6196 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6199 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6202 + struct dentry *parent;
6203 + struct inode *dir;
6205 + parent = dget_parent(dentry);
6206 + dir = d_inode(parent);
6208 + if (au_h_iptr(dir, bdst))
6211 + di_read_unlock(parent, AuLock_IR);
6212 + di_write_lock_parent(parent);
6213 + /* someone else might change our inode while we were sleeping */
6214 + if (!au_h_iptr(dir, bdst))
6215 + err = au_cpup_dirs(dentry, bdst);
6216 + di_downgrade_lock(parent, AuLock_IR);
6222 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6223 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6224 +++ linux/fs/aufs/cpup.h 2022-11-05 23:02:18.962555950 +0100
6226 +/* SPDX-License-Identifier: GPL-2.0 */
6228 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6230 + * This program is free software; you can redistribute it and/or modify
6231 + * it under the terms of the GNU General Public License as published by
6232 + * the Free Software Foundation; either version 2 of the License, or
6233 + * (at your option) any later version.
6235 + * This program is distributed in the hope that it will be useful,
6236 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6237 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6238 + * GNU General Public License for more details.
6240 + * You should have received a copy of the GNU General Public License
6241 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6245 + * copy-up/down functions
6248 +#ifndef __AUFS_CPUP_H__
6249 +#define __AUFS_CPUP_H__
6253 +#include <linux/path.h>
6259 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6260 +void au_cpup_attr_timesizes(struct inode *inode);
6261 +void au_cpup_attr_nlink(struct inode *inode, int force);
6262 +void au_cpup_attr_changeable(struct inode *inode);
6263 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6264 +void au_cpup_attr_all(struct inode *inode, int force);
6266 +/* ---------------------------------------------------------------------- */
6268 +struct au_cp_generic {
6269 + struct dentry *dentry;
6270 + aufs_bindex_t bdst, bsrc;
6272 + struct au_pin *pin;
6273 + unsigned int flags;
6277 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6278 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6280 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6281 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6283 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6285 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6286 + the branch is marked as RO */
6288 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6289 +#undef AuCpup_HOPEN
6290 +#define AuCpup_HOPEN 0
6293 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6294 +#define au_fset_cpup(flags, name) \
6295 + do { (flags) |= AuCpup_##name; } while (0)
6296 +#define au_fclr_cpup(flags, name) \
6297 + do { (flags) &= ~AuCpup_##name; } while (0)
6299 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6300 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6301 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6302 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6304 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6305 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6306 + struct au_pin *pin,
6307 + struct dentry *h_parent, void *arg),
6309 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6310 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6312 +/* ---------------------------------------------------------------------- */
6314 +/* keep timestamps when copyup */
6316 + struct dentry *dt_dentry;
6317 + struct path dt_h_path;
6318 + struct timespec64 dt_atime, dt_mtime;
6320 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6321 + struct path *h_path);
6322 +void au_dtime_revert(struct au_dtime *dt);
6324 +#endif /* __KERNEL__ */
6325 +#endif /* __AUFS_CPUP_H__ */
6326 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6327 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6328 +++ linux/fs/aufs/dbgaufs.c 2022-11-05 23:02:18.962555950 +0100
6330 +// SPDX-License-Identifier: GPL-2.0
6332 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6334 + * This program is free software; you can redistribute it and/or modify
6335 + * it under the terms of the GNU General Public License as published by
6336 + * the Free Software Foundation; either version 2 of the License, or
6337 + * (at your option) any later version.
6339 + * This program is distributed in the hope that it will be useful,
6340 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6341 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6342 + * GNU General Public License for more details.
6344 + * You should have received a copy of the GNU General Public License
6345 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6349 + * debugfs interface
6352 +#include <linux/debugfs.h>
6355 +#ifndef CONFIG_SYSFS
6356 +#error DEBUG_FS depends upon SYSFS
6359 +static struct dentry *dbgaufs;
6360 +static const mode_t dbgaufs_mode = 0444;
6362 +/* 20 is max digits length of ulong 64 */
6363 +struct dbgaufs_arg {
6369 + * common function for all XINO files
6371 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6372 + struct file *file)
6376 + p = file->private_data;
6378 + /* this is struct dbgaufs_arg */
6379 + AuDebugOn(!au_kfree_sz_test(p));
6380 + au_kfree_do_rcu(p);
6385 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6390 + struct dbgaufs_arg *p;
6393 + p = kmalloc(sizeof(*p), GFP_NOFS);
6399 + file->private_data = p;
6403 + err = vfsub_getattr(&xf->f_path, &st);
6407 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6408 + cnt, st.blocks, st.blksize,
6409 + (long long)st.size);
6411 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6412 + st.blocks, st.blksize,
6413 + (long long)st.size);
6414 + AuDebugOn(p->n >= sizeof(p->a));
6416 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6424 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6425 + size_t count, loff_t *ppos)
6427 + struct dbgaufs_arg *p;
6429 + p = file->private_data;
6430 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6433 +/* ---------------------------------------------------------------------- */
6435 +struct dbgaufs_plink_arg {
6440 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6441 + struct file *file)
6443 + free_page((unsigned long)file->private_data);
6447 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6449 + int err, i, limit;
6450 + unsigned long n, sum;
6451 + struct dbgaufs_plink_arg *p;
6452 + struct au_sbinfo *sbinfo;
6453 + struct super_block *sb;
6454 + struct hlist_bl_head *hbl;
6457 + p = (void *)get_zeroed_page(GFP_NOFS);
6462 + sbinfo = inode->i_private;
6463 + sb = sbinfo->si_sb;
6464 + si_noflush_read_lock(sb);
6465 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6466 + limit = PAGE_SIZE - sizeof(p->n);
6468 + /* the number of buckets */
6469 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6474 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6476 + n = au_hbl_count(hbl);
6479 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6482 + if (unlikely(limit <= 0))
6485 + p->a[p->n - 1] = '\n';
6487 + /* the sum of plinks */
6488 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6491 + if (unlikely(limit <= 0))
6494 +#define str "1\n0\n0\n"
6495 + p->n = sizeof(str) - 1;
6496 + strcpy(p->a, str);
6499 + si_read_unlock(sb);
6502 + file->private_data = p;
6503 + goto out; /* success */
6506 + free_page((unsigned long)p);
6511 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6512 + size_t count, loff_t *ppos)
6514 + struct dbgaufs_plink_arg *p;
6516 + p = file->private_data;
6517 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6520 +static const struct file_operations dbgaufs_plink_fop = {
6521 + .owner = THIS_MODULE,
6522 + .open = dbgaufs_plink_open,
6523 + .release = dbgaufs_plink_release,
6524 + .read = dbgaufs_plink_read
6527 +/* ---------------------------------------------------------------------- */
6529 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6532 + struct au_sbinfo *sbinfo;
6533 + struct super_block *sb;
6535 + sbinfo = inode->i_private;
6536 + sb = sbinfo->si_sb;
6537 + si_noflush_read_lock(sb);
6538 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6539 + si_read_unlock(sb);
6543 +static const struct file_operations dbgaufs_xib_fop = {
6544 + .owner = THIS_MODULE,
6545 + .open = dbgaufs_xib_open,
6546 + .release = dbgaufs_xi_release,
6547 + .read = dbgaufs_xi_read
6550 +/* ---------------------------------------------------------------------- */
6552 +#define DbgaufsXi_PREFIX "xi"
6554 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6558 + aufs_bindex_t bindex;
6559 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6560 + struct au_sbinfo *sbinfo;
6561 + struct super_block *sb;
6562 + struct au_xino *xi;
6564 + struct qstr *name;
6565 + struct au_branch *br;
6568 + name = &file->f_path.dentry->d_name;
6569 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6570 + || memcmp(name->name, DbgaufsXi_PREFIX,
6571 + sizeof(DbgaufsXi_PREFIX) - 1)))
6574 + AuDebugOn(name->len >= sizeof(a));
6575 + memcpy(a, name->name, name->len);
6576 + a[name->len] = '\0';
6577 + p = strchr(a, '-');
6580 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6581 + if (unlikely(err))
6586 + err = kstrtol(p + 1, 10, &l);
6587 + if (unlikely(err))
6593 + sbinfo = inode->i_private;
6594 + sb = sbinfo->si_sb;
6595 + si_noflush_read_lock(sb);
6596 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6598 + br = au_sbr(sb, bindex);
6600 + if (unlikely(idx >= xi->xi_nfile))
6602 + xf = au_xino_file(xi, idx);
6604 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6605 + au_xino_count(br));
6608 + si_read_unlock(sb);
6614 +static const struct file_operations dbgaufs_xino_fop = {
6615 + .owner = THIS_MODULE,
6616 + .open = dbgaufs_xino_open,
6617 + .release = dbgaufs_xi_release,
6618 + .read = dbgaufs_xi_read
6621 +void dbgaufs_xino_del(struct au_branch *br)
6623 + struct dentry *dbgaufs;
6625 + dbgaufs = br->br_dbgaufs;
6629 + br->br_dbgaufs = NULL;
6630 + /* debugfs acquires the parent i_mutex */
6632 + debugfs_remove(dbgaufs);
6636 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6638 + aufs_bindex_t bbot;
6639 + struct au_branch *br;
6641 + if (!au_sbi(sb)->si_dbgaufs)
6644 + bbot = au_sbbot(sb);
6645 + for (; bindex <= bbot; bindex++) {
6646 + br = au_sbr(sb, bindex);
6647 + dbgaufs_xino_del(br);
6651 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6652 + unsigned int idx, struct dentry *parent,
6653 + struct au_sbinfo *sbinfo)
6655 + struct au_branch *br;
6657 + /* "xi" bindex(5) "-" idx(2) NULL */
6658 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6661 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6663 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6665 + br = au_sbr(sb, bindex);
6666 + if (br->br_dbgaufs) {
6667 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6669 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6670 + /* debugfs acquires the parent i_mutex */
6672 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6676 + pr_warn("failed renaming %pd/%s, ignored.\n",
6681 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6682 + sbinfo, &dbgaufs_xino_fop);
6684 + if (unlikely(!br->br_dbgaufs))
6685 + pr_warn("failed creating %pd/%s, ignored.\n",
6690 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6691 + struct dentry *parent, struct au_sbinfo *sbinfo)
6693 + struct au_branch *br;
6694 + struct au_xino *xi;
6697 + br = au_sbr(sb, bindex);
6699 + for (u = 0; u < xi->xi_nfile; u++)
6700 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6703 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6705 + struct au_sbinfo *sbinfo;
6706 + struct dentry *parent;
6707 + aufs_bindex_t bbot;
6709 + if (!au_opt_test(au_mntflags(sb), XINO))
6712 + sbinfo = au_sbi(sb);
6713 + parent = sbinfo->si_dbgaufs;
6717 + bbot = au_sbbot(sb);
6719 + for (; bindex <= bbot; bindex++)
6720 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6722 + for (; bbot >= bindex; bbot--)
6723 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6726 +/* ---------------------------------------------------------------------- */
6728 +#ifdef CONFIG_AUFS_EXPORT
6729 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6732 + struct au_sbinfo *sbinfo;
6733 + struct super_block *sb;
6735 + sbinfo = inode->i_private;
6736 + sb = sbinfo->si_sb;
6737 + si_noflush_read_lock(sb);
6738 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6739 + si_read_unlock(sb);
6743 +static const struct file_operations dbgaufs_xigen_fop = {
6744 + .owner = THIS_MODULE,
6745 + .open = dbgaufs_xigen_open,
6746 + .release = dbgaufs_xi_release,
6747 + .read = dbgaufs_xi_read
6750 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6755 + * This function is a dynamic '__init' function actually,
6756 + * so the tiny check for si_rwsem is unnecessary.
6758 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6761 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6762 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6763 + &dbgaufs_xigen_fop);
6764 + if (sbinfo->si_dbgaufs_xigen)
6770 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6774 +#endif /* CONFIG_AUFS_EXPORT */
6776 +/* ---------------------------------------------------------------------- */
6778 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6781 + * This function is a dynamic '__fin' function actually,
6782 + * so the tiny check for si_rwsem is unnecessary.
6784 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6786 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6787 + sbinfo->si_dbgaufs = NULL;
6790 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6793 + char name[SysaufsSiNameLen];
6796 + * This function is a dynamic '__init' function actually,
6797 + * so the tiny check for si_rwsem is unnecessary.
6799 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6803 + AuErr1("/debug/aufs is uninitialized\n");
6808 + sysaufs_name(sbinfo, name);
6809 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6810 + if (unlikely(!sbinfo->si_dbgaufs))
6813 + /* regardless plink/noplink option */
6814 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6815 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6816 + &dbgaufs_plink_fop);
6817 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6820 + /* regardless xino/noxino option */
6821 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6822 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6823 + &dbgaufs_xib_fop);
6824 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6827 + err = dbgaufs_xigen_init(sbinfo);
6829 + goto out; /* success */
6832 + dbgaufs_si_fin(sbinfo);
6834 + if (unlikely(err))
6835 + pr_err("debugfs/aufs failed\n");
6839 +/* ---------------------------------------------------------------------- */
6841 +void dbgaufs_fin(void)
6843 + debugfs_remove(dbgaufs);
6846 +int __init dbgaufs_init(void)
6851 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6856 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6857 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6858 +++ linux/fs/aufs/dbgaufs.h 2022-11-05 23:02:18.962555950 +0100
6860 +/* SPDX-License-Identifier: GPL-2.0 */
6862 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6864 + * This program is free software; you can redistribute it and/or modify
6865 + * it under the terms of the GNU General Public License as published by
6866 + * the Free Software Foundation; either version 2 of the License, or
6867 + * (at your option) any later version.
6869 + * This program is distributed in the hope that it will be useful,
6870 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6871 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6872 + * GNU General Public License for more details.
6874 + * You should have received a copy of the GNU General Public License
6875 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6879 + * debugfs interface
6882 +#ifndef __DBGAUFS_H__
6883 +#define __DBGAUFS_H__
6887 +struct super_block;
6891 +#ifdef CONFIG_DEBUG_FS
6893 +void dbgaufs_xino_del(struct au_branch *br);
6894 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6895 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6896 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6897 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6898 +void dbgaufs_fin(void);
6899 +int __init dbgaufs_init(void);
6901 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6902 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6903 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6905 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6906 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6907 +AuStubVoid(dbgaufs_fin, void)
6908 +AuStubInt0(__init dbgaufs_init, void)
6909 +#endif /* CONFIG_DEBUG_FS */
6911 +#endif /* __KERNEL__ */
6912 +#endif /* __DBGAUFS_H__ */
6913 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6914 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6915 +++ linux/fs/aufs/dcsub.c 2022-11-05 23:02:18.962555950 +0100
6917 +// SPDX-License-Identifier: GPL-2.0
6919 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6921 + * This program is free software; you can redistribute it and/or modify
6922 + * it under the terms of the GNU General Public License as published by
6923 + * the Free Software Foundation; either version 2 of the License, or
6924 + * (at your option) any later version.
6926 + * This program is distributed in the hope that it will be useful,
6927 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6928 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6929 + * GNU General Public License for more details.
6931 + * You should have received a copy of the GNU General Public License
6932 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6936 + * sub-routines for dentry cache
6941 +static void au_dpage_free(struct au_dpage *dpage)
6944 + struct dentry **p;
6946 + p = dpage->dentries;
6947 + for (i = 0; i < dpage->ndentry; i++)
6949 + free_page((unsigned long)dpage->dentries);
6952 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6958 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6959 + if (unlikely(!dpages->dpages))
6962 + p = (void *)__get_free_page(gfp);
6966 + dpages->dpages[0].ndentry = 0;
6967 + dpages->dpages[0].dentries = p;
6968 + dpages->ndpage = 1;
6969 + return 0; /* success */
6972 + au_kfree_try_rcu(dpages->dpages);
6977 +void au_dpages_free(struct au_dcsub_pages *dpages)
6980 + struct au_dpage *p;
6982 + p = dpages->dpages;
6983 + for (i = 0; i < dpages->ndpage; i++)
6984 + au_dpage_free(p++);
6985 + au_kfree_try_rcu(dpages->dpages);
6988 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6989 + struct dentry *dentry, gfp_t gfp)
6992 + struct au_dpage *dpage;
6995 + dpage = dpages->dpages + dpages->ndpage - 1;
6996 + sz = PAGE_SIZE / sizeof(dentry);
6997 + if (unlikely(dpage->ndentry >= sz)) {
6998 + AuLabel(new dpage);
7000 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7001 + p = au_kzrealloc(dpages->dpages, sz,
7002 + sz + sizeof(*dpages->dpages), gfp,
7007 + dpages->dpages = p;
7008 + dpage = dpages->dpages + dpages->ndpage;
7009 + p = (void *)__get_free_page(gfp);
7013 + dpage->ndentry = 0;
7014 + dpage->dentries = p;
7018 + AuDebugOn(au_dcount(dentry) <= 0);
7019 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7020 + return 0; /* success */
7026 +/* todo: BAD approach */
7027 +/* copied from linux/fs/dcache.c */
7035 +extern void d_walk(struct dentry *parent, void *data,
7036 + enum d_walk_ret (*enter)(void *, struct dentry *));
7038 +struct ac_dpages_arg {
7040 + struct au_dcsub_pages *dpages;
7041 + struct super_block *sb;
7042 + au_dpages_test test;
7046 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7048 + enum d_walk_ret ret;
7049 + struct ac_dpages_arg *arg = _arg;
7051 + ret = D_WALK_CONTINUE;
7052 + if (dentry->d_sb == arg->sb
7053 + && !IS_ROOT(dentry)
7054 + && au_dcount(dentry) > 0
7056 + && (!arg->test || arg->test(dentry, arg->arg))) {
7057 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7058 + if (unlikely(arg->err))
7059 + ret = D_WALK_QUIT;
7065 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7066 + au_dpages_test test, void *arg)
7068 + struct ac_dpages_arg args = {
7076 + d_walk(root, &args, au_call_dpages_append);
7081 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7082 + int do_include, au_dpages_test test, void *arg)
7087 + write_seqlock(&rename_lock);
7088 + spin_lock(&dentry->d_lock);
7090 + && au_dcount(dentry) > 0
7091 + && (!test || test(dentry, arg)))
7092 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7093 + spin_unlock(&dentry->d_lock);
7094 + if (unlikely(err))
7098 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7101 + while (!IS_ROOT(dentry)) {
7102 + dentry = dentry->d_parent; /* rename_lock is locked */
7103 + spin_lock(&dentry->d_lock);
7104 + if (au_dcount(dentry) > 0
7105 + && (!test || test(dentry, arg)))
7106 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7107 + spin_unlock(&dentry->d_lock);
7108 + if (unlikely(err))
7113 + write_sequnlock(&rename_lock);
7117 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7119 + return au_di(dentry) && dentry->d_sb == arg;
7122 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7123 + struct dentry *dentry, int do_include)
7125 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7126 + au_dcsub_dpages_aufs, dentry->d_sb);
7129 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7131 + struct path path[2] = {
7140 + return path_is_under(path + 0, path + 1);
7142 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7143 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7144 +++ linux/fs/aufs/dcsub.h 2022-11-05 23:02:18.962555950 +0100
7146 +/* SPDX-License-Identifier: GPL-2.0 */
7148 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7150 + * This program is free software; you can redistribute it and/or modify
7151 + * it under the terms of the GNU General Public License as published by
7152 + * the Free Software Foundation; either version 2 of the License, or
7153 + * (at your option) any later version.
7155 + * This program is distributed in the hope that it will be useful,
7156 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7157 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7158 + * GNU General Public License for more details.
7160 + * You should have received a copy of the GNU General Public License
7161 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7165 + * sub-routines for dentry cache
7168 +#ifndef __AUFS_DCSUB_H__
7169 +#define __AUFS_DCSUB_H__
7173 +#include <linux/dcache.h>
7174 +#include <linux/fs.h>
7178 + struct dentry **dentries;
7181 +struct au_dcsub_pages {
7183 + struct au_dpage *dpages;
7186 +/* ---------------------------------------------------------------------- */
7189 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7190 +void au_dpages_free(struct au_dcsub_pages *dpages);
7191 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7192 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7193 + au_dpages_test test, void *arg);
7194 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7195 + int do_include, au_dpages_test test, void *arg);
7196 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7197 + struct dentry *dentry, int do_include);
7198 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7200 +/* ---------------------------------------------------------------------- */
7203 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7204 + * include/linux/dcache.h. Try them (in the future).
7207 +static inline int au_d_hashed_positive(struct dentry *d)
7210 + struct inode *inode = d_inode(d);
7213 + if (unlikely(d_unhashed(d)
7214 + || d_is_negative(d)
7215 + || !inode->i_nlink))
7220 +static inline int au_d_linkable(struct dentry *d)
7223 + struct inode *inode = d_inode(d);
7225 + err = au_d_hashed_positive(d);
7227 + && d_is_positive(d)
7228 + && (inode->i_state & I_LINKABLE))
7233 +static inline int au_d_alive(struct dentry *d)
7236 + struct inode *inode;
7240 + err = au_d_hashed_positive(d);
7242 + inode = d_inode(d);
7243 + if (unlikely(d_unlinked(d)
7244 + || d_is_negative(d)
7245 + || !inode->i_nlink))
7251 +static inline int au_alive_dir(struct dentry *d)
7255 + err = au_d_alive(d);
7256 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7261 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7263 + return a->len == b->len
7264 + && !memcmp(a->name, b->name, a->len);
7269 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7271 + * the type of d_lockref.count became int, but the inlined function d_count()
7272 + * still returns unsigned int.
7273 + * I don't know why. Maybe it is for every d_count() users?
7274 + * Anyway au_dcount() lives on.
7276 +static inline int au_dcount(struct dentry *d)
7278 + return (int)d_count(d);
7281 +#endif /* __KERNEL__ */
7282 +#endif /* __AUFS_DCSUB_H__ */
7283 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7284 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7285 +++ linux/fs/aufs/debug.c 2022-11-05 23:02:18.962555950 +0100
7287 +// SPDX-License-Identifier: GPL-2.0
7289 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7291 + * This program is free software; you can redistribute it and/or modify
7292 + * it under the terms of the GNU General Public License as published by
7293 + * the Free Software Foundation; either version 2 of the License, or
7294 + * (at your option) any later version.
7296 + * This program is distributed in the hope that it will be useful,
7297 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7298 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7299 + * GNU General Public License for more details.
7301 + * You should have received a copy of the GNU General Public License
7302 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7306 + * debug print functions
7309 +#include <linux/iversion.h>
7312 +/* Returns 0, or -errno. arg is in kp->arg. */
7313 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7317 + err = kstrtoint(val, 0, &n);
7327 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7328 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7333 + return sprintf(buffer, "%d", atomic_read(a));
7336 +static const struct kernel_param_ops param_ops_atomic_t = {
7337 + .set = param_atomic_t_set,
7338 + .get = param_atomic_t_get
7339 + /* void (*free)(void *arg) */
7342 +atomic_t aufs_debug = ATOMIC_INIT(0);
7343 +MODULE_PARM_DESC(debug, "debug print");
7344 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7346 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7347 +char *au_plevel = KERN_DEBUG;
7348 +#define dpri(fmt, ...) do { \
7350 + && strcmp(au_plevel, KERN_DEBUG)) \
7351 + || au_debug_test()) \
7352 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7355 +/* ---------------------------------------------------------------------- */
7357 +void au_dpri_whlist(struct au_nhash *whlist)
7359 + unsigned long ul, n;
7360 + struct hlist_head *head;
7361 + struct au_vdir_wh *pos;
7363 + n = whlist->nh_num;
7364 + head = whlist->nh_head;
7365 + for (ul = 0; ul < n; ul++) {
7366 + hlist_for_each_entry(pos, head, wh_hash)
7367 + dpri("b%d, %.*s, %d\n",
7369 + pos->wh_str.len, pos->wh_str.name,
7375 +void au_dpri_vdir(struct au_vdir *vdir)
7378 + union au_vdir_deblk_p p;
7381 + if (!vdir || IS_ERR(vdir)) {
7382 + dpri("err %ld\n", PTR_ERR(vdir));
7386 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7387 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7388 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7389 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7390 + p.deblk = vdir->vd_deblk[ul];
7392 + dpri("[%lu]: %p\n", ul, o);
7396 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7397 + struct dentry *wh)
7402 + if (!inode || IS_ERR(inode)) {
7403 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7407 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7408 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7409 + && sizeof(inode->i_blocks) != sizeof(u64));
7411 + n = (void *)wh->d_name.name;
7412 + l = wh->d_name.len;
7415 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7416 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7418 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7419 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7420 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7421 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7422 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7423 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7424 + inode->i_generation,
7425 + l ? ", wh " : "", l, n);
7429 +void au_dpri_inode(struct inode *inode)
7431 + struct au_iinfo *iinfo;
7432 + struct au_hinode *hi;
7433 + aufs_bindex_t bindex;
7436 + err = do_pri_inode(-1, inode, -1, NULL);
7437 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7440 + iinfo = au_ii(inode);
7441 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7442 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7443 + if (iinfo->ii_btop < 0)
7446 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7447 + hi = au_hinode(iinfo, bindex);
7449 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7453 +void au_dpri_dalias(struct inode *inode)
7457 + spin_lock(&inode->i_lock);
7458 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7459 + au_dpri_dentry(d);
7460 + spin_unlock(&inode->i_lock);
7463 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7465 + struct dentry *wh = NULL;
7467 + struct inode *inode;
7468 + struct au_iinfo *iinfo;
7469 + struct au_hinode *hi;
7471 + if (!dentry || IS_ERR(dentry)) {
7472 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7475 + /* do not call dget_parent() here */
7476 + /* note: access d_xxx without d_lock */
7477 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7478 + bindex, dentry, dentry,
7479 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7480 + au_dcount(dentry), dentry->d_flags,
7481 + d_unhashed(dentry) ? "un" : "");
7484 + if (d_is_positive(dentry))
7485 + inode = d_inode(dentry);
7487 + && au_test_aufs(dentry->d_sb)
7489 + && !au_is_bad_inode(inode)) {
7490 + iinfo = au_ii(inode);
7491 + hi = au_hinode(iinfo, bindex);
7493 + wh = hi->hi_whdentry;
7495 + do_pri_inode(bindex, inode, hn, wh);
7499 +void au_dpri_dentry(struct dentry *dentry)
7501 + struct au_dinfo *dinfo;
7502 + aufs_bindex_t bindex;
7505 + err = do_pri_dentry(-1, dentry);
7506 + if (err || !au_test_aufs(dentry->d_sb))
7509 + dinfo = au_di(dentry);
7512 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7513 + dinfo->di_btop, dinfo->di_bbot,
7514 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7515 + dinfo->di_tmpfile);
7516 + if (dinfo->di_btop < 0)
7518 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7519 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7522 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7526 + if (!file || IS_ERR(file)) {
7527 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7532 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7533 + && au_test_aufs(file->f_path.dentry->d_sb)
7535 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7536 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7537 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7538 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7539 + file->f_version, file->f_pos, a);
7540 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7541 + do_pri_dentry(bindex, file->f_path.dentry);
7545 +void au_dpri_file(struct file *file)
7547 + struct au_finfo *finfo;
7548 + struct au_fidir *fidir;
7549 + struct au_hfile *hfile;
7550 + aufs_bindex_t bindex;
7553 + err = do_pri_file(-1, file);
7555 + || IS_ERR_OR_NULL(file->f_path.dentry)
7556 + || !au_test_aufs(file->f_path.dentry->d_sb))
7559 + finfo = au_fi(file);
7562 + if (finfo->fi_btop < 0)
7564 + fidir = finfo->fi_hdir;
7566 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7568 + for (bindex = finfo->fi_btop;
7569 + bindex >= 0 && bindex <= fidir->fd_bbot;
7571 + hfile = fidir->fd_hfile + bindex;
7572 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7576 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7578 + struct vfsmount *mnt;
7579 + struct super_block *sb;
7581 + if (!br || IS_ERR(br))
7583 + mnt = au_br_mnt(br);
7584 + if (!mnt || IS_ERR(mnt))
7587 + if (!sb || IS_ERR(sb))
7590 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7591 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7593 + bindex, br->br_perm, br->br_id, br->br_wbr,
7594 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7595 + sb->s_flags, sb->s_count,
7596 + atomic_read(&sb->s_active),
7597 + !!au_xino_file(br->br_xino, /*idx*/-1));
7601 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7605 +void au_dpri_sb(struct super_block *sb)
7607 + struct au_sbinfo *sbinfo;
7608 + aufs_bindex_t bindex;
7610 + /* to reduce stack size */
7612 + struct vfsmount mnt;
7613 + struct au_branch fake;
7616 + /* this function can be called from magic sysrq */
7617 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7618 + if (unlikely(!a)) {
7619 + dpri("no memory\n");
7623 + a->mnt.mnt_sb = sb;
7624 + a->fake.br_path.mnt = &a->mnt;
7625 + err = do_pri_br(-1, &a->fake);
7627 + dpri("dev 0x%x\n", sb->s_dev);
7628 + if (err || !au_test_aufs(sb))
7631 + sbinfo = au_sbi(sb);
7634 + dpri("nw %d, gen %u, kobj %d\n",
7635 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7636 + kref_read(&sbinfo->si_kobj.kref));
7637 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7638 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7641 +/* ---------------------------------------------------------------------- */
7643 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7645 + struct inode *h_inode, *inode = d_inode(dentry);
7646 + struct dentry *h_dentry;
7647 + aufs_bindex_t bindex, bbot, bi;
7649 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7652 + bbot = au_dbbot(dentry);
7653 + bi = au_ibbot(inode);
7656 + bindex = au_dbtop(dentry);
7657 + bi = au_ibtop(inode);
7661 + for (; bindex <= bbot; bindex++) {
7662 + h_dentry = au_h_dptr(dentry, bindex);
7665 + h_inode = au_h_iptr(inode, bindex);
7666 + if (unlikely(h_inode != d_inode(h_dentry))) {
7668 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7669 + AuDbgDentry(dentry);
7670 + AuDbgInode(inode);
7672 + if (au_test_fuse(h_inode->i_sb))
7680 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7683 + struct au_dcsub_pages dpages;
7684 + struct au_dpage *dpage;
7685 + struct dentry **dentries;
7687 + err = au_dpages_init(&dpages, GFP_NOFS);
7689 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7691 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7692 + dpage = dpages.dpages + i;
7693 + dentries = dpage->dentries;
7694 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7695 + AuDebugOn(au_digen_test(dentries[j], sigen));
7697 + au_dpages_free(&dpages);
7700 +void au_dbg_verify_kthread(void)
7702 + if (au_wkq_test()) {
7705 + * It may be recursive, but udba=notify between two aufs mounts,
7706 + * where a single ro branch is shared, is not a problem.
7712 +/* ---------------------------------------------------------------------- */
7714 +int __init au_debug_init(void)
7716 + aufs_bindex_t bindex;
7717 + struct au_vdir_destr destr;
7720 + AuDebugOn(bindex >= 0);
7723 + AuDebugOn(destr.len < NAME_MAX);
7725 +#ifdef CONFIG_4KSTACKS
7726 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7731 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7732 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7733 +++ linux/fs/aufs/debug.h 2022-11-05 23:02:18.962555950 +0100
7735 +/* SPDX-License-Identifier: GPL-2.0 */
7737 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7739 + * This program is free software; you can redistribute it and/or modify
7740 + * it under the terms of the GNU General Public License as published by
7741 + * the Free Software Foundation; either version 2 of the License, or
7742 + * (at your option) any later version.
7744 + * This program is distributed in the hope that it will be useful,
7745 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7746 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7747 + * GNU General Public License for more details.
7749 + * You should have received a copy of the GNU General Public License
7750 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7754 + * debug print functions
7757 +#ifndef __AUFS_DEBUG_H__
7758 +#define __AUFS_DEBUG_H__
7762 +#include <linux/atomic.h>
7763 +#include <linux/module.h>
7764 +#include <linux/kallsyms.h>
7765 +#include <linux/sysrq.h>
7767 +#ifdef CONFIG_AUFS_DEBUG
7768 +#define AuDebugOn(a) BUG_ON(a)
7770 +/* module parameter */
7771 +extern atomic_t aufs_debug;
7772 +static inline void au_debug_on(void)
7774 + atomic_inc(&aufs_debug);
7776 +static inline void au_debug_off(void)
7778 + atomic_dec_if_positive(&aufs_debug);
7781 +static inline int au_debug_test(void)
7783 + return atomic_read(&aufs_debug) > 0;
7786 +#define AuDebugOn(a) do {} while (0)
7787 +AuStubVoid(au_debug_on, void)
7788 +AuStubVoid(au_debug_off, void)
7789 +AuStubInt0(au_debug_test, void)
7790 +#endif /* CONFIG_AUFS_DEBUG */
7792 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7794 +/* ---------------------------------------------------------------------- */
7798 +#define AuDbg(fmt, ...) do { \
7799 + if (au_debug_test()) \
7800 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7802 +#define AuLabel(l) AuDbg(#l "\n")
7803 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7804 +#define AuWarn1(fmt, ...) do { \
7805 + static unsigned char _c; \
7807 + pr_warn(fmt, ##__VA_ARGS__); \
7810 +#define AuErr1(fmt, ...) do { \
7811 + static unsigned char _c; \
7813 + pr_err(fmt, ##__VA_ARGS__); \
7816 +#define AuIOErr1(fmt, ...) do { \
7817 + static unsigned char _c; \
7819 + AuIOErr(fmt, ##__VA_ARGS__); \
7822 +#define AuUnsupportMsg "This operation is not supported." \
7823 + " Please report this application to aufs-users ML."
7824 +#define AuUnsupport(fmt, ...) do { \
7825 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7829 +#define AuTraceErr(e) do { \
7830 + if (unlikely((e) < 0)) \
7831 + AuDbg("err %d\n", (int)(e)); \
7834 +#define AuTraceErrPtr(p) do { \
7836 + AuDbg("err %ld\n", PTR_ERR(p)); \
7839 +/* dirty macros for debug print, use with "%.*s" and caution */
7840 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7842 +/* ---------------------------------------------------------------------- */
7845 +#ifdef CONFIG_AUFS_DEBUG
7846 +extern struct mutex au_dbg_mtx;
7847 +extern char *au_plevel;
7849 +void au_dpri_whlist(struct au_nhash *whlist);
7851 +void au_dpri_vdir(struct au_vdir *vdir);
7853 +void au_dpri_inode(struct inode *inode);
7854 +void au_dpri_dalias(struct inode *inode);
7855 +void au_dpri_dentry(struct dentry *dentry);
7857 +void au_dpri_file(struct file *filp);
7858 +struct super_block;
7859 +void au_dpri_sb(struct super_block *sb);
7861 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7862 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7863 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7864 +void au_dbg_verify_kthread(void);
7866 +int __init au_debug_init(void);
7868 +#define AuDbgWhlist(w) do { \
7869 + mutex_lock(&au_dbg_mtx); \
7871 + au_dpri_whlist(w); \
7872 + mutex_unlock(&au_dbg_mtx); \
7875 +#define AuDbgVdir(v) do { \
7876 + mutex_lock(&au_dbg_mtx); \
7878 + au_dpri_vdir(v); \
7879 + mutex_unlock(&au_dbg_mtx); \
7882 +#define AuDbgInode(i) do { \
7883 + mutex_lock(&au_dbg_mtx); \
7885 + au_dpri_inode(i); \
7886 + mutex_unlock(&au_dbg_mtx); \
7889 +#define AuDbgDAlias(i) do { \
7890 + mutex_lock(&au_dbg_mtx); \
7892 + au_dpri_dalias(i); \
7893 + mutex_unlock(&au_dbg_mtx); \
7896 +#define AuDbgDentry(d) do { \
7897 + mutex_lock(&au_dbg_mtx); \
7899 + au_dpri_dentry(d); \
7900 + mutex_unlock(&au_dbg_mtx); \
7903 +#define AuDbgFile(f) do { \
7904 + mutex_lock(&au_dbg_mtx); \
7906 + au_dpri_file(f); \
7907 + mutex_unlock(&au_dbg_mtx); \
7910 +#define AuDbgSb(sb) do { \
7911 + mutex_lock(&au_dbg_mtx); \
7912 + AuDbg(#sb "\n"); \
7914 + mutex_unlock(&au_dbg_mtx); \
7917 +#define AuDbgSym(addr) do { \
7918 + char sym[KSYM_SYMBOL_LEN]; \
7919 + sprint_symbol(sym, (unsigned long)addr); \
7920 + AuDbg("%s\n", sym); \
7923 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7924 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7925 +AuStubVoid(au_dbg_verify_kthread, void)
7926 +AuStubInt0(__init au_debug_init, void)
7928 +#define AuDbgWhlist(w) do {} while (0)
7929 +#define AuDbgVdir(v) do {} while (0)
7930 +#define AuDbgInode(i) do {} while (0)
7931 +#define AuDbgDAlias(i) do {} while (0)
7932 +#define AuDbgDentry(d) do {} while (0)
7933 +#define AuDbgFile(f) do {} while (0)
7934 +#define AuDbgSb(sb) do {} while (0)
7935 +#define AuDbgSym(addr) do {} while (0)
7936 +#endif /* CONFIG_AUFS_DEBUG */
7938 +/* ---------------------------------------------------------------------- */
7940 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7941 +int __init au_sysrq_init(void);
7942 +void au_sysrq_fin(void);
7944 +#ifdef CONFIG_HW_CONSOLE
7945 +#define au_dbg_blocked() do { \
7947 + handle_sysrq('w'); \
7950 +AuStubVoid(au_dbg_blocked, void)
7954 +AuStubInt0(__init au_sysrq_init, void)
7955 +AuStubVoid(au_sysrq_fin, void)
7956 +AuStubVoid(au_dbg_blocked, void)
7957 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7959 +#endif /* __KERNEL__ */
7960 +#endif /* __AUFS_DEBUG_H__ */
7961 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7962 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7963 +++ linux/fs/aufs/dentry.c 2022-11-05 23:02:18.962555950 +0100
7965 +// SPDX-License-Identifier: GPL-2.0
7967 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7969 + * This program is free software; you can redistribute it and/or modify
7970 + * it under the terms of the GNU General Public License as published by
7971 + * the Free Software Foundation; either version 2 of the License, or
7972 + * (at your option) any later version.
7974 + * This program is distributed in the hope that it will be useful,
7975 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7976 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7977 + * GNU General Public License for more details.
7979 + * You should have received a copy of the GNU General Public License
7980 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7984 + * lookup and dentry operations
7987 +#include <linux/iversion.h>
7991 + * returns positive/negative dentry, NULL or an error.
7992 + * NULL means whiteout-ed or not-found.
7994 +static struct dentry*
7995 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7996 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
7998 + struct dentry *h_dentry;
7999 + struct inode *h_inode;
8000 + struct au_branch *br;
8001 + struct user_namespace *h_userns;
8002 + struct path h_path;
8003 + int wh_found, opq;
8004 + unsigned char wh_able;
8005 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8006 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8010 + br = au_sbr(dentry->d_sb, bindex);
8011 + h_path.dentry = h_parent;
8012 + h_path.mnt = au_br_mnt(br);
8013 + h_userns = au_br_userns(br);
8014 + wh_able = !!au_br_whable(br->br_perm);
8016 + wh_found = au_wh_test(h_userns, &h_path, &args->whname,
8018 + h_dentry = ERR_PTR(wh_found);
8021 + if (unlikely(wh_found < 0))
8024 + /* We found a whiteout */
8025 + /* au_set_dbbot(dentry, bindex); */
8026 + au_set_dbwh(dentry, bindex);
8028 + return NULL; /* success */
8032 + h_dentry = vfsub_lkup_one(args->name, &h_path);
8034 + h_dentry = au_sio_lkup_one(h_userns, args->name, &h_path);
8035 + if (IS_ERR(h_dentry)) {
8036 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8042 + h_inode = d_inode(h_dentry);
8043 + if (d_is_negative(h_dentry)) {
8046 + } else if (wh_found
8047 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8049 + else if (au_ftest_lkup(args->flags, DIRREN)
8051 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8052 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8053 + (unsigned long long)h_inode->i_ino);
8057 + if (au_dbbot(dentry) <= bindex)
8058 + au_set_dbbot(dentry, bindex);
8059 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8060 + au_set_dbtop(dentry, bindex);
8061 + au_set_h_dptr(dentry, bindex, h_dentry);
8063 + if (!d_is_dir(h_dentry)
8065 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8066 + goto out; /* success */
8068 + h_path.dentry = h_dentry;
8069 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8070 + opq = au_diropq_test(h_userns, &h_path);
8071 + inode_unlock_shared(h_inode);
8073 + au_set_dbdiropq(dentry, bindex);
8074 + else if (unlikely(opq < 0)) {
8075 + au_set_h_dptr(dentry, bindex, NULL);
8076 + h_dentry = ERR_PTR(opq);
8087 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8089 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8090 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8096 + * returns the number of lower positive dentries,
8097 + * otherwise an error.
8098 + * can be called at unlinking with @type is zero.
8100 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8101 + unsigned int flags)
8103 + int npositive, err;
8104 + aufs_bindex_t bindex, btail, bdiropq;
8105 + unsigned char isdir, dirperm1, dirren;
8106 + struct au_do_lookup_args args = {
8108 + .name = &dentry->d_name
8110 + struct dentry *parent;
8111 + struct super_block *sb;
8113 + sb = dentry->d_sb;
8114 + err = au_test_shwh(sb, args.name);
8115 + if (unlikely(err))
8118 + err = au_wh_name_alloc(&args.whname, args.name);
8119 + if (unlikely(err))
8122 + isdir = !!d_is_dir(dentry);
8123 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8124 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8126 + au_fset_lkup(args.flags, DIRREN);
8129 + parent = dget_parent(dentry);
8130 + btail = au_dbtaildir(parent);
8131 + for (bindex = btop; bindex <= btail; bindex++) {
8132 + struct dentry *h_parent, *h_dentry;
8133 + struct inode *h_inode, *h_dir;
8134 + struct au_branch *br;
8136 + h_dentry = au_h_dptr(dentry, bindex);
8138 + if (d_is_positive(h_dentry))
8142 + h_parent = au_h_dptr(parent, bindex);
8143 + if (!h_parent || !d_is_dir(h_parent))
8147 + /* if the inum matches, then use the prepared name */
8148 + err = au_dr_lkup_name(&args, bindex);
8149 + if (unlikely(err))
8153 + h_dir = d_inode(h_parent);
8154 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8155 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8156 + inode_unlock_shared(h_dir);
8157 + err = PTR_ERR(h_dentry);
8158 + if (IS_ERR(h_dentry))
8161 + au_fclr_lkup(args.flags, ALLOW_NEG);
8163 + au_fset_lkup(args.flags, IGNORE_PERM);
8165 + if (au_dbwh(dentry) == bindex)
8169 + if (d_is_negative(h_dentry))
8171 + h_inode = d_inode(h_dentry);
8174 + args.type = h_inode->i_mode & S_IFMT;
8175 + if (args.type != S_IFDIR)
8178 + /* the type of lower may be different */
8179 + bdiropq = au_dbdiropq(dentry);
8180 + if (bdiropq >= 0 && bdiropq <= bindex)
8183 + br = au_sbr(sb, bindex);
8185 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8186 + /*add_ent*/NULL)) {
8187 + /* prepare next name to lookup */
8188 + err = au_dr_lkup(&args, dentry, bindex);
8189 + if (unlikely(err))
8195 + AuLabel(positive);
8196 + au_update_dbtop(dentry);
8199 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8200 + && au_dbtop(dentry) < 0)) {
8202 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8208 + au_kfree_try_rcu(args.whname.name);
8210 + au_dr_lkup_fin(&args);
8215 +struct dentry *au_sio_lkup_one(struct user_namespace *userns, struct qstr *name,
8216 + struct path *ppath)
8218 + struct dentry *dentry;
8221 + if (!au_test_h_perm_sio(userns, d_inode(ppath->dentry), MAY_EXEC))
8222 + dentry = vfsub_lkup_one(name, ppath);
8224 + struct vfsub_lkup_one_args args = {
8230 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8231 + if (unlikely(wkq_err))
8232 + dentry = ERR_PTR(wkq_err);
8239 + * lookup @dentry on @bindex which should be negative.
8241 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8244 + struct dentry *parent, *h_dentry;
8245 + struct au_branch *br;
8246 + struct user_namespace *h_userns;
8247 + struct path h_ppath;
8249 + parent = dget_parent(dentry);
8250 + br = au_sbr(dentry->d_sb, bindex);
8251 + h_ppath.dentry = au_h_dptr(parent, bindex);
8252 + h_ppath.mnt = au_br_mnt(br);
8253 + h_userns = au_br_userns(br);
8255 + h_dentry = au_whtmp_lkup(h_ppath.dentry, br, &dentry->d_name);
8257 + h_dentry = au_sio_lkup_one(h_userns, &dentry->d_name, &h_ppath);
8258 + err = PTR_ERR(h_dentry);
8259 + if (IS_ERR(h_dentry))
8261 + if (unlikely(d_is_positive(h_dentry))) {
8263 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8269 + if (bindex < au_dbtop(dentry))
8270 + au_set_dbtop(dentry, bindex);
8271 + if (au_dbbot(dentry) < bindex)
8272 + au_set_dbbot(dentry, bindex);
8273 + au_set_h_dptr(dentry, bindex, h_dentry);
8280 +/* ---------------------------------------------------------------------- */
8282 +/* subset of struct inode */
8284 + unsigned long i_ino;
8285 + /* unsigned int i_nlink; */
8291 + blkcnt_t i_blocks;
8296 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8298 + ia->i_ino = h_inode->i_ino;
8299 + /* ia->i_nlink = h_inode->i_nlink; */
8300 + ia->i_uid = h_inode->i_uid;
8301 + ia->i_gid = h_inode->i_gid;
8302 + ia->i_version = inode_query_iversion(h_inode);
8304 + ia->i_size = h_inode->i_size;
8305 + ia->i_blocks = h_inode->i_blocks;
8307 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8310 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8312 + return ia->i_ino != h_inode->i_ino
8313 + /* || ia->i_nlink != h_inode->i_nlink */
8314 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8315 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8316 + || !inode_eq_iversion(h_inode, ia->i_version)
8318 + || ia->i_size != h_inode->i_size
8319 + || ia->i_blocks != h_inode->i_blocks
8321 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8324 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8325 + struct au_branch *br)
8328 + struct au_iattr ia;
8329 + struct inode *h_inode;
8330 + struct dentry *h_d;
8331 + struct super_block *h_sb;
8332 + struct path h_ppath;
8335 + memset(&ia, -1, sizeof(ia));
8336 + h_sb = h_dentry->d_sb;
8338 + if (d_is_positive(h_dentry)) {
8339 + h_inode = d_inode(h_dentry);
8340 + au_iattr_save(&ia, h_inode);
8341 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8342 + /* nfs d_revalidate may return 0 for negative dentry */
8343 + /* fuse d_revalidate always return 0 for negative dentry */
8346 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8347 + h_ppath.dentry = h_parent;
8348 + h_ppath.mnt = au_br_mnt(br);
8349 + h_d = vfsub_lkup_one(&h_dentry->d_name, &h_ppath);
8350 + err = PTR_ERR(h_d);
8355 + if (unlikely(h_d != h_dentry
8356 + || d_inode(h_d) != h_inode
8357 + || (h_inode && au_iattr_test(&ia, h_inode))))
8358 + err = au_busy_or_stale();
8366 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8367 + struct dentry *h_parent, struct au_branch *br)
8372 + if (udba == AuOpt_UDBA_REVAL
8373 + && !au_test_fs_remote(h_dentry->d_sb)) {
8375 + err = (d_inode(h_dentry->d_parent) != h_dir);
8376 + } else if (udba != AuOpt_UDBA_NONE)
8377 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8382 +/* ---------------------------------------------------------------------- */
8384 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8387 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8388 + struct au_hdentry tmp, *p, *q;
8389 + struct au_dinfo *dinfo;
8390 + struct super_block *sb;
8392 + DiMustWriteLock(dentry);
8394 + sb = dentry->d_sb;
8395 + dinfo = au_di(dentry);
8396 + bbot = dinfo->di_bbot;
8397 + bwh = dinfo->di_bwh;
8398 + bdiropq = dinfo->di_bdiropq;
8399 + bindex = dinfo->di_btop;
8400 + p = au_hdentry(dinfo, bindex);
8401 + for (; bindex <= bbot; bindex++, p++) {
8402 + if (!p->hd_dentry)
8405 + new_bindex = au_br_index(sb, p->hd_id);
8406 + if (new_bindex == bindex)
8409 + if (dinfo->di_bwh == bindex)
8411 + if (dinfo->di_bdiropq == bindex)
8412 + bdiropq = new_bindex;
8413 + if (new_bindex < 0) {
8415 + p->hd_dentry = NULL;
8419 + /* swap two lower dentries, and loop again */
8420 + q = au_hdentry(dinfo, new_bindex);
8424 + if (tmp.hd_dentry) {
8430 + dinfo->di_bwh = -1;
8431 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8432 + dinfo->di_bwh = bwh;
8434 + dinfo->di_bdiropq = -1;
8436 + && bdiropq <= au_sbbot(sb)
8437 + && au_sbr_whable(sb, bdiropq))
8438 + dinfo->di_bdiropq = bdiropq;
8441 + dinfo->di_btop = -1;
8442 + dinfo->di_bbot = -1;
8443 + bbot = au_dbbot(parent);
8445 + p = au_hdentry(dinfo, bindex);
8446 + for (; bindex <= bbot; bindex++, p++)
8447 + if (p->hd_dentry) {
8448 + dinfo->di_btop = bindex;
8452 + if (dinfo->di_btop >= 0) {
8454 + p = au_hdentry(dinfo, bindex);
8455 + for (; bindex >= 0; bindex--, p--)
8456 + if (p->hd_dentry) {
8457 + dinfo->di_bbot = bindex;
8466 +static void au_do_hide(struct dentry *dentry)
8468 + struct inode *inode;
8470 + if (d_really_is_positive(dentry)) {
8471 + inode = d_inode(dentry);
8472 + if (!d_is_dir(dentry)) {
8473 + if (inode->i_nlink && !d_unhashed(dentry))
8474 + drop_nlink(inode);
8476 + clear_nlink(inode);
8477 + /* stop next lookup */
8478 + inode->i_flags |= S_DEAD;
8480 + smp_mb(); /* necessary? */
8485 +static int au_hide_children(struct dentry *parent)
8487 + int err, i, j, ndentry;
8488 + struct au_dcsub_pages dpages;
8489 + struct au_dpage *dpage;
8490 + struct dentry *dentry;
8492 + err = au_dpages_init(&dpages, GFP_NOFS);
8493 + if (unlikely(err))
8495 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8496 + if (unlikely(err))
8499 + /* in reverse order */
8500 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8501 + dpage = dpages.dpages + i;
8502 + ndentry = dpage->ndentry;
8503 + for (j = ndentry - 1; j >= 0; j--) {
8504 + dentry = dpage->dentries[j];
8505 + if (dentry != parent)
8506 + au_do_hide(dentry);
8511 + au_dpages_free(&dpages);
8516 +static void au_hide(struct dentry *dentry)
8520 + AuDbgDentry(dentry);
8521 + if (d_is_dir(dentry)) {
8522 + /* shrink_dcache_parent(dentry); */
8523 + err = au_hide_children(dentry);
8524 + if (unlikely(err))
8525 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8528 + au_do_hide(dentry);
8532 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8534 + * a dirty branch is added
8535 + * - on the top of layers
8536 + * - in the middle of layers
8537 + * - to the bottom of layers
8539 + * on the added branch there exists
8542 + * - a same named entry
8544 + * * negative --> positive
8545 + * * positive --> positive
8546 + * - type is unchanged
8547 + * - type is changed
8549 + * * negative --> negative
8550 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8553 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8554 + struct au_dinfo *tmp)
8557 + aufs_bindex_t bindex, bbot;
8559 + struct dentry *dentry;
8560 + struct inode *inode;
8562 + } orig_h, tmp_h = {
8565 + struct au_hdentry *hd;
8566 + struct inode *inode, *h_inode;
8567 + struct dentry *h_dentry;
8570 + AuDebugOn(dinfo->di_btop < 0);
8572 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8573 + orig_h.inode = NULL;
8574 + if (d_is_positive(orig_h.dentry)) {
8575 + orig_h.inode = d_inode(orig_h.dentry);
8576 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8578 + if (tmp->di_btop >= 0) {
8579 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8580 + if (d_is_positive(tmp_h.dentry)) {
8581 + tmp_h.inode = d_inode(tmp_h.dentry);
8582 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8587 + if (d_really_is_positive(dentry))
8588 + inode = d_inode(dentry);
8589 + if (!orig_h.inode) {
8590 + AuDbg("negative originally\n");
8596 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8597 + AuDebugOn(dinfo->di_bdiropq != -1);
8599 + if (!tmp_h.inode) {
8600 + AuDbg("negative --> negative\n");
8601 + /* should have only one negative lower */
8602 + if (tmp->di_btop >= 0
8603 + && tmp->di_btop < dinfo->di_btop) {
8604 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8605 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8606 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8607 + au_di_cp(dinfo, tmp);
8608 + hd = au_hdentry(tmp, tmp->di_btop);
8609 + au_set_h_dptr(dentry, tmp->di_btop,
8610 + dget(hd->hd_dentry));
8612 + au_dbg_verify_dinode(dentry);
8614 + AuDbg("negative --> positive\n");
8616 + * similar to the behaviour of creating with bypassing
8618 + * unhash it in order to force an error in the
8619 + * succeeding create operation.
8620 + * we should not set S_DEAD here.
8623 + /* au_di_swap(tmp, dinfo); */
8624 + au_dbg_verify_dinode(dentry);
8627 + AuDbg("positive originally\n");
8628 + /* inode may be NULL */
8629 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8630 + if (!tmp_h.inode) {
8631 + AuDbg("positive --> negative\n");
8632 + /* or bypassing aufs */
8634 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8635 + dinfo->di_bwh = tmp->di_bwh;
8637 + err = au_refresh_hinode_self(inode);
8638 + au_dbg_verify_dinode(dentry);
8639 + } else if (orig_h.mode == tmp_h.mode) {
8640 + AuDbg("positive --> positive, same type\n");
8641 + if (!S_ISDIR(orig_h.mode)
8642 + && dinfo->di_btop > tmp->di_btop) {
8644 + * similar to the behaviour of removing and
8649 + err = au_refresh_hinode_self(inode);
8650 + au_dbg_verify_dinode(dentry);
8652 + /* fill empty slots */
8653 + if (dinfo->di_btop > tmp->di_btop)
8654 + dinfo->di_btop = tmp->di_btop;
8655 + if (dinfo->di_bbot < tmp->di_bbot)
8656 + dinfo->di_bbot = tmp->di_bbot;
8657 + dinfo->di_bwh = tmp->di_bwh;
8658 + dinfo->di_bdiropq = tmp->di_bdiropq;
8659 + bbot = dinfo->di_bbot;
8660 + bindex = tmp->di_btop;
8661 + hd = au_hdentry(tmp, bindex);
8662 + for (; bindex <= bbot; bindex++, hd++) {
8663 + if (au_h_dptr(dentry, bindex))
8665 + h_dentry = hd->hd_dentry;
8668 + AuDebugOn(d_is_negative(h_dentry));
8669 + h_inode = d_inode(h_dentry);
8670 + AuDebugOn(orig_h.mode
8671 + != (h_inode->i_mode
8673 + au_set_h_dptr(dentry, bindex,
8677 + err = au_refresh_hinode(inode, dentry);
8678 + au_dbg_verify_dinode(dentry);
8681 + AuDbg("positive --> positive, different type\n");
8682 + /* similar to the behaviour of removing and creating */
8685 + err = au_refresh_hinode_self(inode);
8686 + au_dbg_verify_dinode(dentry);
8694 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8696 + const struct dentry_operations *dop
8697 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8698 + static const unsigned int mask
8699 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8701 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8703 + if (dentry->d_op == dop)
8706 + AuDbg("%pd\n", dentry);
8707 + spin_lock(&dentry->d_lock);
8708 + if (dop == &aufs_dop)
8709 + dentry->d_flags |= mask;
8711 + dentry->d_flags &= ~mask;
8712 + dentry->d_op = dop;
8713 + spin_unlock(&dentry->d_lock);
8716 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8718 + int err, ebrange, nbr;
8719 + unsigned int sigen;
8720 + struct au_dinfo *dinfo, *tmp;
8721 + struct super_block *sb;
8722 + struct inode *inode;
8724 + DiMustWriteLock(dentry);
8725 + AuDebugOn(IS_ROOT(dentry));
8726 + AuDebugOn(d_really_is_negative(parent));
8728 + sb = dentry->d_sb;
8729 + sigen = au_sigen(sb);
8730 + err = au_digen_test(parent, sigen);
8731 + if (unlikely(err))
8734 + nbr = au_sbbot(sb) + 1;
8735 + dinfo = au_di(dentry);
8736 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8737 + if (unlikely(err))
8739 + ebrange = au_dbrange_test(dentry);
8741 + ebrange = au_do_refresh_hdentry(dentry, parent);
8743 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8744 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8745 + if (d_really_is_positive(dentry)) {
8746 + inode = d_inode(dentry);
8747 + err = au_refresh_hinode_self(inode);
8749 + au_dbg_verify_dinode(dentry);
8751 + goto out_dgen; /* success */
8755 + /* temporary dinfo */
8756 + AuDbgDentry(dentry);
8758 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8759 + if (unlikely(!tmp))
8761 + au_di_swap(tmp, dinfo);
8762 + /* returns the number of positive dentries */
8764 + * if current working dir is removed, it returns an error.
8765 + * but the dentry is legal.
8767 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8768 + AuDbgDentry(dentry);
8769 + au_di_swap(tmp, dinfo);
8770 + if (err == -ENOENT)
8773 + /* compare/refresh by dinfo */
8774 + AuDbgDentry(dentry);
8775 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8776 + au_dbg_verify_dinode(dentry);
8779 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8780 + au_rw_write_unlock(&tmp->di_rwsem);
8782 + if (unlikely(err))
8786 + au_update_digen(dentry);
8788 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8789 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8790 + AuDbgDentry(dentry);
8796 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8797 + struct dentry *dentry, aufs_bindex_t bindex)
8802 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8805 + AuDbg("b%d\n", bindex);
8807 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8808 + * due to whiteout and branch permission.
8810 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8811 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8812 + /* it may return tri-state */
8813 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8815 + if (unlikely(valid < 0))
8825 +/* todo: remove this */
8826 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8827 + unsigned int flags, int do_udba, int dirren)
8830 + umode_t mode, h_mode;
8831 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8832 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8833 + struct inode *h_inode, *h_cached_inode;
8834 + struct dentry *h_dentry;
8835 + struct qstr *name, *h_name;
8842 + unhashed = !!d_unhashed(dentry);
8843 + is_root = !!IS_ROOT(dentry);
8844 + name = &dentry->d_name;
8845 + tmpfile = au_di(dentry)->di_tmpfile;
8848 + * Theoretically, REVAL test should be unnecessary in case of
8850 + * But {fs,i}notify doesn't fire some necessary events,
8851 + * IN_ATTRIB for atime/nlink/pageio
8852 + * Let's do REVAL test too.
8854 + if (do_udba && inode) {
8855 + mode = (inode->i_mode & S_IFMT);
8856 + plus = (inode->i_nlink > 0);
8857 + ibs = au_ibtop(inode);
8858 + ibe = au_ibbot(inode);
8861 + btop = au_dbtop(dentry);
8863 + if (inode && S_ISDIR(inode->i_mode))
8864 + btail = au_dbtaildir(dentry);
8865 + for (bindex = btop; bindex <= btail; bindex++) {
8866 + h_dentry = au_h_dptr(dentry, bindex);
8870 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8871 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8872 + spin_lock(&h_dentry->d_lock);
8873 + h_name = &h_dentry->d_name;
8874 + if (unlikely(do_udba
8877 + && (unhashed != !!d_unhashed(h_dentry)
8878 + || (!tmpfile && !dirren
8879 + && !au_qstreq(name, h_name))
8882 + && !(flags & LOOKUP_OPEN)
8883 + && (h_dentry->d_flags
8884 + & DCACHE_NFSFS_RENAMED)))
8888 + h_unhashed = d_unhashed(h_dentry);
8889 + spin_unlock(&h_dentry->d_lock);
8890 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8891 + unhashed, h_unhashed, dentry, h_dentry);
8894 + spin_unlock(&h_dentry->d_lock);
8896 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8897 + if (unlikely(err))
8898 + /* do not goto err, to keep the errno */
8901 + /* todo: plink too? */
8906 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8910 + if (d_is_positive(h_dentry))
8911 + h_inode = d_inode(h_dentry);
8914 + h_cached_inode = h_inode;
8916 + h_mode = (h_inode->i_mode & S_IFMT);
8917 + h_plus = (h_inode->i_nlink > 0);
8919 + if (inode && ibs <= bindex && bindex <= ibe)
8920 + h_cached_inode = au_h_iptr(inode, bindex);
8923 + if (unlikely(plus != h_plus && !tmpfile))
8926 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8928 + && !IS_ROOT(h_dentry)
8929 + && unhashed != d_unhashed(h_dentry)))
8932 + if (unlikely(mode != h_mode
8933 + || h_cached_inode != h_inode))
8946 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8947 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8950 + struct dentry *parent;
8952 + if (!au_digen_test(dentry, sigen))
8955 + parent = dget_parent(dentry);
8956 + di_read_lock_parent(parent, AuLock_IR);
8957 + AuDebugOn(au_digen_test(parent, sigen));
8958 + au_dbg_verify_gen(parent, sigen);
8959 + err = au_refresh_dentry(dentry, parent);
8960 + di_read_unlock(parent, AuLock_IR);
8966 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8969 + struct dentry *d, *parent;
8971 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8972 + return simple_reval_dpath(dentry, sigen);
8974 + /* slow loop, keep it simple and stupid */
8975 + /* cf: au_cpup_dirs() */
8978 + while (au_digen_test(dentry, sigen)) {
8982 + parent = dget_parent(d);
8983 + if (!au_digen_test(parent, sigen))
8989 + di_write_lock_child2(d);
8991 + /* someone might update our dentry while we were sleeping */
8992 + if (au_digen_test(d, sigen)) {
8994 + * todo: consolidate with simple_reval_dpath(),
8995 + * do_refresh() and au_reval_for_attr().
8997 + di_read_lock_parent(parent, AuLock_IR);
8998 + err = au_refresh_dentry(d, parent);
8999 + di_read_unlock(parent, AuLock_IR);
9003 + di_write_unlock(d);
9005 + if (unlikely(err))
9013 + * if valid returns 1, otherwise 0.
9015 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9018 + unsigned int sigen;
9019 + unsigned char do_udba, dirren;
9020 + struct super_block *sb;
9021 + struct inode *inode;
9023 + /* todo: support rcu-walk? */
9024 + if (flags & LOOKUP_RCU)
9028 + if (unlikely(!au_di(dentry)))
9032 + sb = dentry->d_sb;
9035 + * i_mutex of parent dir may be held,
9036 + * but we should not return 'invalid' due to busy.
9038 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9039 + if (unlikely(err)) {
9045 + if (d_really_is_positive(dentry))
9046 + inode = d_inode(dentry);
9047 + if (unlikely(inode && au_is_bad_inode(inode))) {
9052 + if (unlikely(au_dbrange_test(dentry))) {
9058 + sigen = au_sigen(sb);
9059 + if (au_digen_test(dentry, sigen)) {
9060 + AuDebugOn(IS_ROOT(dentry));
9061 + err = au_reval_dpath(dentry, sigen);
9062 + if (unlikely(err)) {
9067 + di_downgrade_lock(dentry, AuLock_IR);
9070 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9072 + && !(inode->i_state && I_LINKABLE)
9073 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9078 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9079 + if (do_udba && inode) {
9080 + aufs_bindex_t btop = au_ibtop(inode);
9081 + struct inode *h_inode;
9084 + h_inode = au_h_iptr(inode, btop);
9085 + if (h_inode && au_test_higen(inode, h_inode)) {
9092 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9093 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9094 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9096 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9102 + di_downgrade_lock(dentry, AuLock_IR);
9104 + aufs_read_unlock(dentry, AuLock_IR);
9109 + AuDbg("%pd invalid, %d\n", dentry, valid);
9115 +static void aufs_d_release(struct dentry *dentry)
9117 + if (au_di(dentry)) {
9118 + au_di_fin(dentry);
9119 + au_hn_di_reinit(dentry);
9123 +const struct dentry_operations aufs_dop = {
9124 + .d_revalidate = aufs_d_revalidate,
9125 + .d_weak_revalidate = aufs_d_revalidate,
9126 + .d_release = aufs_d_release
9129 +/* aufs_dop without d_revalidate */
9130 +const struct dentry_operations aufs_dop_noreval = {
9131 + .d_release = aufs_d_release
9133 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9134 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9135 +++ linux/fs/aufs/dentry.h 2022-12-17 09:21:34.796521861 +0100
9137 +/* SPDX-License-Identifier: GPL-2.0 */
9139 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9141 + * This program is free software; you can redistribute it and/or modify
9142 + * it under the terms of the GNU General Public License as published by
9143 + * the Free Software Foundation; either version 2 of the License, or
9144 + * (at your option) any later version.
9146 + * This program is distributed in the hope that it will be useful,
9147 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9148 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9149 + * GNU General Public License for more details.
9151 + * You should have received a copy of the GNU General Public License
9152 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9156 + * lookup and dentry operations
9159 +#ifndef __AUFS_DENTRY_H__
9160 +#define __AUFS_DENTRY_H__
9164 +#include <linux/dcache.h>
9165 +#include "dirren.h"
9168 +struct au_hdentry {
9169 + struct dentry *hd_dentry;
9170 + aufs_bindex_t hd_id;
9174 + atomic_t di_generation;
9176 + struct au_rwsem di_rwsem;
9177 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9178 + unsigned char di_tmpfile; /* to allow the different name */
9179 + struct au_hdentry *di_hdentry;
9180 + struct file *di_htmpfile;
9181 + struct rcu_head rcu;
9182 +} ____cacheline_aligned_in_smp;
9184 +/* ---------------------------------------------------------------------- */
9186 +/* flags for au_lkup_dentry() */
9187 +#define AuLkup_ALLOW_NEG 1
9188 +#define AuLkup_IGNORE_PERM (1 << 1)
9189 +#define AuLkup_DIRREN (1 << 2)
9190 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9191 +#define au_fset_lkup(flags, name) \
9192 + do { (flags) |= AuLkup_##name; } while (0)
9193 +#define au_fclr_lkup(flags, name) \
9194 + do { (flags) &= ~AuLkup_##name; } while (0)
9196 +#ifndef CONFIG_AUFS_DIRREN
9197 +#undef AuLkup_DIRREN
9198 +#define AuLkup_DIRREN 0
9201 +struct au_do_lookup_args {
9202 + unsigned int flags;
9204 + struct qstr whname, *name;
9205 + struct au_dr_lookup dirren;
9208 +/* ---------------------------------------------------------------------- */
9211 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9213 +struct dentry *au_sio_lkup_one(struct user_namespace *userns, struct qstr *name,
9214 + struct path *ppath);
9215 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9216 + struct dentry *h_parent, struct au_branch *br);
9218 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9219 + unsigned int flags);
9220 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9221 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9222 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9223 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9226 +void au_di_init_once(void *_di);
9227 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9228 +void au_di_free(struct au_dinfo *dinfo);
9229 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9230 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9231 +int au_di_init(struct dentry *dentry);
9232 +void au_di_fin(struct dentry *dentry);
9233 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9235 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9236 +void di_read_unlock(struct dentry *d, int flags);
9237 +void di_downgrade_lock(struct dentry *d, int flags);
9238 +void di_write_lock(struct dentry *d, unsigned int lsc);
9239 +void di_write_unlock(struct dentry *d);
9240 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9241 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9242 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9244 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9245 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9246 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9247 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9249 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9250 + struct dentry *h_dentry);
9251 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9252 +int au_dbrange_test(struct dentry *dentry);
9253 +void au_update_digen(struct dentry *dentry);
9254 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9255 +void au_update_dbtop(struct dentry *dentry);
9256 +void au_update_dbbot(struct dentry *dentry);
9257 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9259 +/* ---------------------------------------------------------------------- */
9261 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9263 + return dentry->d_fsdata;
9266 +/* ---------------------------------------------------------------------- */
9268 +/* lock subclass for dinfo */
9270 + AuLsc_DI_CHILD, /* child first */
9271 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9272 + AuLsc_DI_CHILD3, /* copyup dirs */
9276 + AuLsc_DI_TMP /* temp for replacing dinfo */
9280 + * di_read_lock_child, di_write_lock_child,
9281 + * di_read_lock_child2, di_write_lock_child2,
9282 + * di_read_lock_child3, di_write_lock_child3,
9283 + * di_read_lock_parent, di_write_lock_parent,
9284 + * di_read_lock_parent2, di_write_lock_parent2,
9285 + * di_read_lock_parent3, di_write_lock_parent3,
9287 +#define AuReadLockFunc(name, lsc) \
9288 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9289 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9291 +#define AuWriteLockFunc(name, lsc) \
9292 +static inline void di_write_lock_##name(struct dentry *d) \
9293 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9295 +#define AuRWLockFuncs(name, lsc) \
9296 + AuReadLockFunc(name, lsc) \
9297 + AuWriteLockFunc(name, lsc)
9299 +AuRWLockFuncs(child, CHILD);
9300 +AuRWLockFuncs(child2, CHILD2);
9301 +AuRWLockFuncs(child3, CHILD3);
9302 +AuRWLockFuncs(parent, PARENT);
9303 +AuRWLockFuncs(parent2, PARENT2);
9304 +AuRWLockFuncs(parent3, PARENT3);
9306 +#undef AuReadLockFunc
9307 +#undef AuWriteLockFunc
9308 +#undef AuRWLockFuncs
9310 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9311 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9312 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9314 +/* ---------------------------------------------------------------------- */
9316 +/* todo: memory barrier? */
9317 +static inline unsigned int au_digen(struct dentry *d)
9319 + return atomic_read(&au_di(d)->di_generation);
9322 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9324 + hdentry->hd_dentry = NULL;
9327 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9328 + aufs_bindex_t bindex)
9330 + return di->di_hdentry + bindex;
9333 +static inline void au_hdput(struct au_hdentry *hd)
9336 + dput(hd->hd_dentry);
9339 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9341 + DiMustAnyLock(dentry);
9342 + return au_di(dentry)->di_btop;
9345 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9347 + DiMustAnyLock(dentry);
9348 + return au_di(dentry)->di_bbot;
9351 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9353 + DiMustAnyLock(dentry);
9354 + return au_di(dentry)->di_bwh;
9357 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9359 + DiMustAnyLock(dentry);
9360 + return au_di(dentry)->di_bdiropq;
9363 +/* todo: hard/soft set? */
9364 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9366 + DiMustWriteLock(dentry);
9367 + au_di(dentry)->di_btop = bindex;
9370 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9372 + DiMustWriteLock(dentry);
9373 + au_di(dentry)->di_bbot = bindex;
9376 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9378 + DiMustWriteLock(dentry);
9379 + /* dbwh can be outside of btop - bbot range */
9380 + au_di(dentry)->di_bwh = bindex;
9383 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9385 + DiMustWriteLock(dentry);
9386 + au_di(dentry)->di_bdiropq = bindex;
9389 +/* ---------------------------------------------------------------------- */
9391 +#ifdef CONFIG_AUFS_HNOTIFY
9392 +static inline void au_digen_dec(struct dentry *d)
9394 + atomic_dec(&au_di(d)->di_generation);
9397 +static inline void au_hn_di_reinit(struct dentry *dentry)
9399 + dentry->d_fsdata = NULL;
9402 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9403 +#endif /* CONFIG_AUFS_HNOTIFY */
9405 +#endif /* __KERNEL__ */
9406 +#endif /* __AUFS_DENTRY_H__ */
9407 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9408 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9409 +++ linux/fs/aufs/dinfo.c 2022-12-17 09:21:34.796521861 +0100
9411 +// SPDX-License-Identifier: GPL-2.0
9413 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9415 + * This program is free software; you can redistribute it and/or modify
9416 + * it under the terms of the GNU General Public License as published by
9417 + * the Free Software Foundation; either version 2 of the License, or
9418 + * (at your option) any later version.
9420 + * This program is distributed in the hope that it will be useful,
9421 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9422 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9423 + * GNU General Public License for more details.
9425 + * You should have received a copy of the GNU General Public License
9426 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9430 + * dentry private data
9435 +void au_di_init_once(void *_dinfo)
9437 + struct au_dinfo *dinfo = _dinfo;
9439 + au_rw_init(&dinfo->di_rwsem);
9442 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9444 + struct au_dinfo *dinfo;
9447 + dinfo = au_cache_alloc_dinfo();
9448 + if (unlikely(!dinfo))
9451 + nbr = au_sbbot(sb) + 1;
9454 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9455 + if (dinfo->di_hdentry) {
9456 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9457 + dinfo->di_btop = -1;
9458 + dinfo->di_bbot = -1;
9459 + dinfo->di_bwh = -1;
9460 + dinfo->di_bdiropq = -1;
9461 + dinfo->di_tmpfile = 0;
9462 + for (i = 0; i < nbr; i++)
9463 + dinfo->di_hdentry[i].hd_id = -1;
9464 + dinfo->di_htmpfile = NULL;
9468 + au_cache_free_dinfo(dinfo);
9475 +void au_di_free(struct au_dinfo *dinfo)
9477 + struct au_hdentry *p;
9478 + aufs_bindex_t bbot, bindex;
9480 + /* dentry may not be revalidated */
9481 + bindex = dinfo->di_btop;
9482 + if (bindex >= 0) {
9483 + bbot = dinfo->di_bbot;
9484 + p = au_hdentry(dinfo, bindex);
9485 + while (bindex++ <= bbot)
9488 + au_kfree_try_rcu(dinfo->di_hdentry);
9489 + au_cache_free_dinfo(dinfo);
9492 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9494 + struct au_hdentry *p;
9497 + AuRwMustWriteLock(&a->di_rwsem);
9498 + AuRwMustWriteLock(&b->di_rwsem);
9500 +#define DiSwap(v, name) \
9502 + v = a->di_##name; \
9503 + a->di_##name = b->di_##name; \
9504 + b->di_##name = v; \
9507 + DiSwap(p, hdentry);
9511 + DiSwap(bi, bdiropq);
9517 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9519 + AuRwMustWriteLock(&dst->di_rwsem);
9520 + AuRwMustWriteLock(&src->di_rwsem);
9522 + dst->di_btop = src->di_btop;
9523 + dst->di_bbot = src->di_bbot;
9524 + dst->di_bwh = src->di_bwh;
9525 + dst->di_bdiropq = src->di_bdiropq;
9529 +int au_di_init(struct dentry *dentry)
9532 + struct super_block *sb;
9533 + struct au_dinfo *dinfo;
9536 + sb = dentry->d_sb;
9537 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9539 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9540 + /* smp_mb(); */ /* atomic_set */
9541 + dentry->d_fsdata = dinfo;
9548 +void au_di_fin(struct dentry *dentry)
9550 + struct au_dinfo *dinfo;
9552 + dinfo = au_di(dentry);
9553 + AuRwDestroy(&dinfo->di_rwsem);
9554 + au_di_free(dinfo);
9557 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9560 + struct au_hdentry *hdp;
9562 + AuRwMustWriteLock(&dinfo->di_rwsem);
9565 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9567 + sz = sizeof(*hdp);
9568 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9571 + dinfo->di_hdentry = hdp;
9578 +/* ---------------------------------------------------------------------- */
9580 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9583 + case AuLsc_DI_CHILD:
9584 + ii_write_lock_child(inode);
9586 + case AuLsc_DI_CHILD2:
9587 + ii_write_lock_child2(inode);
9589 + case AuLsc_DI_CHILD3:
9590 + ii_write_lock_child3(inode);
9592 + case AuLsc_DI_PARENT:
9593 + ii_write_lock_parent(inode);
9595 + case AuLsc_DI_PARENT2:
9596 + ii_write_lock_parent2(inode);
9598 + case AuLsc_DI_PARENT3:
9599 + ii_write_lock_parent3(inode);
9606 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9609 + case AuLsc_DI_CHILD:
9610 + ii_read_lock_child(inode);
9612 + case AuLsc_DI_CHILD2:
9613 + ii_read_lock_child2(inode);
9615 + case AuLsc_DI_CHILD3:
9616 + ii_read_lock_child3(inode);
9618 + case AuLsc_DI_PARENT:
9619 + ii_read_lock_parent(inode);
9621 + case AuLsc_DI_PARENT2:
9622 + ii_read_lock_parent2(inode);
9624 + case AuLsc_DI_PARENT3:
9625 + ii_read_lock_parent3(inode);
9632 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9634 + struct inode *inode;
9636 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9637 + if (d_really_is_positive(d)) {
9638 + inode = d_inode(d);
9639 + if (au_ftest_lock(flags, IW))
9640 + do_ii_write_lock(inode, lsc);
9641 + else if (au_ftest_lock(flags, IR))
9642 + do_ii_read_lock(inode, lsc);
9646 +void di_read_unlock(struct dentry *d, int flags)
9648 + struct inode *inode;
9650 + if (d_really_is_positive(d)) {
9651 + inode = d_inode(d);
9652 + if (au_ftest_lock(flags, IW)) {
9653 + au_dbg_verify_dinode(d);
9654 + ii_write_unlock(inode);
9655 + } else if (au_ftest_lock(flags, IR)) {
9656 + au_dbg_verify_dinode(d);
9657 + ii_read_unlock(inode);
9660 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9663 +void di_downgrade_lock(struct dentry *d, int flags)
9665 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9666 + ii_downgrade_lock(d_inode(d));
9667 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9670 +void di_write_lock(struct dentry *d, unsigned int lsc)
9672 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9673 + if (d_really_is_positive(d))
9674 + do_ii_write_lock(d_inode(d), lsc);
9677 +void di_write_unlock(struct dentry *d)
9679 + au_dbg_verify_dinode(d);
9680 + if (d_really_is_positive(d))
9681 + ii_write_unlock(d_inode(d));
9682 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9685 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9687 + AuDebugOn(d1 == d2
9688 + || d_inode(d1) == d_inode(d2)
9689 + || d1->d_sb != d2->d_sb);
9691 + if ((isdir && au_test_subdir(d1, d2))
9693 + di_write_lock_child(d1);
9694 + di_write_lock_child2(d2);
9696 + di_write_lock_child(d2);
9697 + di_write_lock_child2(d1);
9701 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9703 + AuDebugOn(d1 == d2
9704 + || d_inode(d1) == d_inode(d2)
9705 + || d1->d_sb != d2->d_sb);
9707 + if ((isdir && au_test_subdir(d1, d2))
9709 + di_write_lock_parent(d1);
9710 + di_write_lock_parent2(d2);
9712 + di_write_lock_parent(d2);
9713 + di_write_lock_parent2(d1);
9717 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9719 + di_write_unlock(d1);
9720 + if (d_inode(d1) == d_inode(d2))
9721 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9723 + di_write_unlock(d2);
9726 +/* ---------------------------------------------------------------------- */
9728 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9732 + DiMustAnyLock(dentry);
9734 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9736 + AuDebugOn(bindex < 0);
9737 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9738 + AuDebugOn(d && au_dcount(d) <= 0);
9743 + * extended version of au_h_dptr().
9744 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9747 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9749 + struct dentry *h_dentry;
9750 + struct inode *inode, *h_inode;
9752 + AuDebugOn(d_really_is_negative(dentry));
9755 + if (au_dbtop(dentry) <= bindex
9756 + && bindex <= au_dbbot(dentry))
9757 + h_dentry = au_h_dptr(dentry, bindex);
9758 + if (h_dentry && !au_d_linkable(h_dentry)) {
9760 + goto out; /* success */
9763 + inode = d_inode(dentry);
9764 + AuDebugOn(bindex < au_ibtop(inode));
9765 + AuDebugOn(au_ibbot(inode) < bindex);
9766 + h_inode = au_h_iptr(inode, bindex);
9767 + h_dentry = d_find_alias(h_inode);
9769 + if (!IS_ERR(h_dentry)) {
9770 + if (!au_d_linkable(h_dentry))
9771 + goto out; /* success */
9777 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9778 + h_dentry = au_plink_lkup(inode, bindex);
9779 + AuDebugOn(!h_dentry);
9780 + if (!IS_ERR(h_dentry)) {
9781 + if (!au_d_hashed_positive(h_dentry))
9782 + goto out; /* success */
9789 + AuDbgDentry(h_dentry);
9793 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9795 + aufs_bindex_t bbot, bwh;
9797 + bbot = au_dbbot(dentry);
9799 + bwh = au_dbwh(dentry);
9802 + if (0 < bwh && bwh < bbot)
9808 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9810 + aufs_bindex_t bbot, bopq;
9812 + bbot = au_dbtail(dentry);
9814 + bopq = au_dbdiropq(dentry);
9815 + if (0 <= bopq && bopq < bbot)
9821 +/* ---------------------------------------------------------------------- */
9823 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9824 + struct dentry *h_dentry)
9826 + struct au_dinfo *dinfo;
9827 + struct au_hdentry *hd;
9828 + struct au_branch *br;
9830 + DiMustWriteLock(dentry);
9832 + dinfo = au_di(dentry);
9833 + hd = au_hdentry(dinfo, bindex);
9835 + hd->hd_dentry = h_dentry;
9837 + br = au_sbr(dentry->d_sb, bindex);
9838 + hd->hd_id = br->br_id;
9842 +int au_dbrange_test(struct dentry *dentry)
9845 + aufs_bindex_t btop, bbot;
9848 + btop = au_dbtop(dentry);
9849 + bbot = au_dbbot(dentry);
9851 + AuDebugOn(bbot < 0 && btop > bbot);
9854 + AuDebugOn(bbot >= 0);
9860 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9865 + if (unlikely(au_digen(dentry) != sigen
9866 + || au_iigen_test(d_inode(dentry), sigen)))
9872 +void au_update_digen(struct dentry *dentry)
9874 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9875 + /* smp_mb(); */ /* atomic_set */
9878 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9880 + struct au_dinfo *dinfo;
9881 + struct dentry *h_d;
9882 + struct au_hdentry *hdp;
9883 + aufs_bindex_t bindex, bbot;
9885 + DiMustWriteLock(dentry);
9887 + dinfo = au_di(dentry);
9888 + if (!dinfo || dinfo->di_btop < 0)
9891 + if (do_put_zero) {
9892 + bbot = dinfo->di_bbot;
9893 + bindex = dinfo->di_btop;
9894 + hdp = au_hdentry(dinfo, bindex);
9895 + for (; bindex <= bbot; bindex++, hdp++) {
9896 + h_d = hdp->hd_dentry;
9897 + if (h_d && d_is_negative(h_d))
9898 + au_set_h_dptr(dentry, bindex, NULL);
9902 + dinfo->di_btop = 0;
9903 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9904 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9905 + if (hdp->hd_dentry)
9907 + if (dinfo->di_btop > dinfo->di_bbot) {
9908 + dinfo->di_btop = -1;
9909 + dinfo->di_bbot = -1;
9913 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9914 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9915 + if (hdp->hd_dentry)
9917 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9920 +void au_update_dbtop(struct dentry *dentry)
9922 + aufs_bindex_t bindex, bbot;
9923 + struct dentry *h_dentry;
9925 + bbot = au_dbbot(dentry);
9926 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9927 + h_dentry = au_h_dptr(dentry, bindex);
9930 + if (d_is_positive(h_dentry)) {
9931 + au_set_dbtop(dentry, bindex);
9934 + au_set_h_dptr(dentry, bindex, NULL);
9938 +void au_update_dbbot(struct dentry *dentry)
9940 + aufs_bindex_t bindex, btop;
9941 + struct dentry *h_dentry;
9943 + btop = au_dbtop(dentry);
9944 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9945 + h_dentry = au_h_dptr(dentry, bindex);
9948 + if (d_is_positive(h_dentry)) {
9949 + au_set_dbbot(dentry, bindex);
9952 + au_set_h_dptr(dentry, bindex, NULL);
9956 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9958 + aufs_bindex_t bindex, bbot;
9960 + bbot = au_dbbot(dentry);
9961 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9962 + if (au_h_dptr(dentry, bindex) == h_dentry)
9966 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9967 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9968 +++ linux/fs/aufs/dir.c 2022-12-17 09:21:34.796521861 +0100
9970 +// SPDX-License-Identifier: GPL-2.0
9972 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9974 + * This program is free software; you can redistribute it and/or modify
9975 + * it under the terms of the GNU General Public License as published by
9976 + * the Free Software Foundation; either version 2 of the License, or
9977 + * (at your option) any later version.
9979 + * This program is distributed in the hope that it will be useful,
9980 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9981 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9982 + * GNU General Public License for more details.
9984 + * You should have received a copy of the GNU General Public License
9985 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9989 + * directory operations
9992 +#include <linux/fs_stack.h>
9993 +#include <linux/iversion.h>
9996 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9998 + unsigned int nlink;
10000 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10002 + nlink = dir->i_nlink;
10003 + nlink += h_dir->i_nlink - 2;
10004 + if (h_dir->i_nlink < 2)
10006 + smp_mb(); /* for i_nlink */
10007 + /* 0 can happen in revaliding */
10008 + set_nlink(dir, nlink);
10011 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10013 + unsigned int nlink;
10015 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10017 + nlink = dir->i_nlink;
10018 + nlink -= h_dir->i_nlink - 2;
10019 + if (h_dir->i_nlink < 2)
10021 + smp_mb(); /* for i_nlink */
10022 + /* nlink == 0 means the branch-fs is broken */
10023 + set_nlink(dir, nlink);
10026 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10029 + aufs_bindex_t bindex, bbot;
10030 + struct file *h_file;
10031 + struct dentry *h_dentry;
10035 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10037 + bbot = au_fbbot_dir(file);
10038 + for (bindex = au_fbtop(file);
10039 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10041 + h_file = au_hf_dir(file, bindex);
10042 + if (h_file && file_inode(h_file))
10043 + sz += vfsub_f_size_read(h_file);
10046 + AuDebugOn(!dentry);
10047 + AuDebugOn(!d_is_dir(dentry));
10049 + bbot = au_dbtaildir(dentry);
10050 + for (bindex = au_dbtop(dentry);
10051 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10053 + h_dentry = au_h_dptr(dentry, bindex);
10054 + if (h_dentry && d_is_positive(h_dentry))
10055 + sz += i_size_read(d_inode(h_dentry));
10058 + if (sz < KMALLOC_MAX_SIZE)
10059 + sz = roundup_pow_of_two(sz);
10060 + if (sz > KMALLOC_MAX_SIZE)
10061 + sz = KMALLOC_MAX_SIZE;
10062 + else if (sz < NAME_MAX) {
10063 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10064 + sz = AUFS_RDBLK_DEF;
10069 +struct au_dir_ts_arg {
10070 + struct dentry *dentry;
10071 + aufs_bindex_t brid;
10074 +static void au_do_dir_ts(void *arg)
10076 + struct au_dir_ts_arg *a = arg;
10077 + struct au_dtime dt;
10078 + struct path h_path;
10079 + struct inode *dir, *h_dir;
10080 + struct super_block *sb;
10081 + struct au_branch *br;
10082 + struct au_hinode *hdir;
10084 + aufs_bindex_t btop, bindex;
10086 + sb = a->dentry->d_sb;
10087 + if (d_really_is_negative(a->dentry))
10089 + /* no dir->i_mutex lock */
10090 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10092 + dir = d_inode(a->dentry);
10093 + btop = au_ibtop(dir);
10094 + bindex = au_br_index(sb, a->brid);
10095 + if (bindex < btop)
10098 + br = au_sbr(sb, bindex);
10099 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10100 + if (!h_path.dentry)
10102 + h_path.mnt = au_br_mnt(br);
10103 + au_dtime_store(&dt, a->dentry, &h_path);
10105 + br = au_sbr(sb, btop);
10106 + if (!au_br_writable(br->br_perm))
10108 + h_path.dentry = au_h_dptr(a->dentry, btop);
10109 + h_path.mnt = au_br_mnt(br);
10110 + err = vfsub_mnt_want_write(h_path.mnt);
10113 + hdir = au_hi(dir, btop);
10114 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10115 + h_dir = au_h_iptr(dir, btop);
10116 + if (h_dir->i_nlink
10117 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10118 + dt.dt_h_path = h_path;
10119 + au_dtime_revert(&dt);
10121 + au_hn_inode_unlock(hdir);
10122 + vfsub_mnt_drop_write(h_path.mnt);
10123 + au_cpup_attr_timesizes(dir);
10126 + aufs_read_unlock(a->dentry, AuLock_DW);
10129 + au_nwt_done(&au_sbi(sb)->si_nowait);
10130 + au_kfree_try_rcu(arg);
10133 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10135 + int perm, wkq_err;
10136 + aufs_bindex_t btop;
10137 + struct au_dir_ts_arg *arg;
10138 + struct dentry *dentry;
10139 + struct super_block *sb;
10143 + dentry = d_find_any_alias(dir);
10144 + AuDebugOn(!dentry);
10145 + sb = dentry->d_sb;
10146 + btop = au_ibtop(dir);
10147 + if (btop == bindex) {
10148 + au_cpup_attr_timesizes(dir);
10152 + perm = au_sbr_perm(sb, btop);
10153 + if (!au_br_writable(perm))
10156 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10160 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10161 + arg->brid = au_sbr_id(sb, bindex);
10162 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10163 + if (unlikely(wkq_err)) {
10164 + pr_err("wkq %d\n", wkq_err);
10166 + au_kfree_try_rcu(arg);
10173 +/* ---------------------------------------------------------------------- */
10175 +static int reopen_dir(struct file *file)
10178 + unsigned int flags;
10179 + aufs_bindex_t bindex, btail, btop;
10180 + struct dentry *dentry, *h_dentry;
10181 + struct file *h_file;
10183 + /* open all lower dirs */
10184 + dentry = file->f_path.dentry;
10185 + btop = au_dbtop(dentry);
10186 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10187 + au_set_h_fptr(file, bindex, NULL);
10188 + au_set_fbtop(file, btop);
10190 + btail = au_dbtaildir(dentry);
10191 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10192 + au_set_h_fptr(file, bindex, NULL);
10193 + au_set_fbbot_dir(file, btail);
10195 + flags = vfsub_file_flags(file);
10196 + for (bindex = btop; bindex <= btail; bindex++) {
10197 + h_dentry = au_h_dptr(dentry, bindex);
10200 + h_file = au_hf_dir(file, bindex);
10204 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10205 + err = PTR_ERR(h_file);
10206 + if (IS_ERR(h_file))
10207 + goto out; /* close all? */
10208 + au_set_h_fptr(file, bindex, h_file);
10210 + au_update_figen(file);
10211 + /* todo: necessary? */
10212 + /* file->f_ra = h_file->f_ra; */
10219 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10222 + aufs_bindex_t bindex, btail;
10223 + struct dentry *dentry, *h_dentry;
10224 + struct vfsmount *mnt;
10226 + FiMustWriteLock(file);
10227 + AuDebugOn(h_file);
10230 + mnt = file->f_path.mnt;
10231 + dentry = file->f_path.dentry;
10232 + file->f_version = inode_query_iversion(d_inode(dentry));
10233 + bindex = au_dbtop(dentry);
10234 + au_set_fbtop(file, bindex);
10235 + btail = au_dbtaildir(dentry);
10236 + au_set_fbbot_dir(file, btail);
10237 + for (; !err && bindex <= btail; bindex++) {
10238 + h_dentry = au_h_dptr(dentry, bindex);
10242 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10243 + if (unlikely(err))
10245 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10246 + if (IS_ERR(h_file)) {
10247 + err = PTR_ERR(h_file);
10250 + au_set_h_fptr(file, bindex, h_file);
10252 + au_update_figen(file);
10253 + /* todo: necessary? */
10254 + /* file->f_ra = h_file->f_ra; */
10256 + return 0; /* success */
10259 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10260 + au_set_h_fptr(file, bindex, NULL);
10261 + au_set_fbtop(file, -1);
10262 + au_set_fbbot_dir(file, -1);
10267 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10268 + struct file *file)
10271 + struct super_block *sb;
10272 + struct au_fidir *fidir;
10275 + sb = file->f_path.dentry->d_sb;
10276 + si_read_lock(sb, AuLock_FLUSH);
10277 + fidir = au_fidir_alloc(sb);
10279 + struct au_do_open_args args = {
10280 + .open = do_open_dir,
10283 + err = au_do_open(file, &args);
10284 + if (unlikely(err))
10285 + au_kfree_rcu(fidir);
10287 + si_read_unlock(sb);
10291 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10292 + struct file *file)
10294 + struct au_vdir *vdir_cache;
10295 + struct au_finfo *finfo;
10296 + struct au_fidir *fidir;
10297 + struct au_hfile *hf;
10298 + aufs_bindex_t bindex, bbot;
10300 + finfo = au_fi(file);
10301 + fidir = finfo->fi_hdir;
10303 + au_hbl_del(&finfo->fi_hlist,
10304 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10305 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10307 + au_vdir_free(vdir_cache);
10309 + bindex = finfo->fi_btop;
10310 + if (bindex >= 0) {
10311 + hf = fidir->fd_hfile + bindex;
10313 + * calls fput() instead of filp_close(),
10314 + * since no dnotify or lock for the lower file.
10316 + bbot = fidir->fd_bbot;
10317 + for (; bindex <= bbot; bindex++, hf++)
10319 + au_hfput(hf, /*execed*/0);
10321 + au_kfree_rcu(fidir);
10322 + finfo->fi_hdir = NULL;
10324 + au_finfo_fin(file);
10328 +/* ---------------------------------------------------------------------- */
10330 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10333 + aufs_bindex_t bindex, bbot;
10334 + struct file *h_file;
10337 + bbot = au_fbbot_dir(file);
10338 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10339 + h_file = au_hf_dir(file, bindex);
10341 + err = vfsub_flush(h_file, id);
10346 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10348 + return au_do_flush(file, id, au_do_flush_dir);
10351 +/* ---------------------------------------------------------------------- */
10353 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10356 + aufs_bindex_t bbot, bindex;
10357 + struct inode *inode;
10358 + struct super_block *sb;
10361 + sb = dentry->d_sb;
10362 + inode = d_inode(dentry);
10363 + IMustLock(inode);
10364 + bbot = au_dbbot(dentry);
10365 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10366 + struct path h_path;
10368 + if (au_test_ro(sb, bindex, inode))
10370 + h_path.dentry = au_h_dptr(dentry, bindex);
10371 + if (!h_path.dentry)
10374 + h_path.mnt = au_sbr_mnt(sb, bindex);
10375 + err = vfsub_fsync(NULL, &h_path, datasync);
10381 +static int au_do_fsync_dir(struct file *file, int datasync)
10384 + aufs_bindex_t bbot, bindex;
10385 + struct file *h_file;
10386 + struct super_block *sb;
10387 + struct inode *inode;
10389 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10390 + if (unlikely(err))
10393 + inode = file_inode(file);
10394 + sb = inode->i_sb;
10395 + bbot = au_fbbot_dir(file);
10396 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10397 + h_file = au_hf_dir(file, bindex);
10398 + if (!h_file || au_test_ro(sb, bindex, inode))
10401 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10409 + * @file may be NULL
10411 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10415 + struct dentry *dentry;
10416 + struct inode *inode;
10417 + struct super_block *sb;
10420 + dentry = file->f_path.dentry;
10421 + inode = d_inode(dentry);
10422 + inode_lock(inode);
10423 + sb = dentry->d_sb;
10424 + si_noflush_read_lock(sb);
10426 + err = au_do_fsync_dir(file, datasync);
10428 + di_write_lock_child(dentry);
10429 + err = au_do_fsync_dir_no_file(dentry, datasync);
10431 + au_cpup_attr_timesizes(inode);
10432 + di_write_unlock(dentry);
10434 + fi_write_unlock(file);
10436 + si_read_unlock(sb);
10437 + inode_unlock(inode);
10441 +/* ---------------------------------------------------------------------- */
10443 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10446 + struct dentry *dentry;
10447 + struct inode *inode, *h_inode;
10448 + struct super_block *sb;
10450 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10452 + dentry = file->f_path.dentry;
10453 + inode = d_inode(dentry);
10454 + IMustLock(inode);
10456 + sb = dentry->d_sb;
10457 + si_read_lock(sb, AuLock_FLUSH);
10458 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10459 + if (unlikely(err))
10461 + err = au_alive_dir(dentry);
10463 + err = au_vdir_init(file);
10464 + di_downgrade_lock(dentry, AuLock_IR);
10465 + if (unlikely(err))
10468 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10469 + if (!au_test_nfsd()) {
10470 + err = au_vdir_fill_de(file, ctx);
10471 + fsstack_copy_attr_atime(inode, h_inode);
10474 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10475 + * encode_fh() and others.
10477 + atomic_inc(&h_inode->i_count);
10478 + di_read_unlock(dentry, AuLock_IR);
10479 + si_read_unlock(sb);
10480 + err = au_vdir_fill_de(file, ctx);
10481 + fsstack_copy_attr_atime(inode, h_inode);
10482 + fi_write_unlock(file);
10490 + di_read_unlock(dentry, AuLock_IR);
10491 + fi_write_unlock(file);
10493 + si_read_unlock(sb);
10497 +/* ---------------------------------------------------------------------- */
10499 +#define AuTestEmpty_WHONLY 1
10500 +#define AuTestEmpty_CALLED (1 << 1)
10501 +#define AuTestEmpty_SHWH (1 << 2)
10502 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10503 +#define au_fset_testempty(flags, name) \
10504 + do { (flags) |= AuTestEmpty_##name; } while (0)
10505 +#define au_fclr_testempty(flags, name) \
10506 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10508 +#ifndef CONFIG_AUFS_SHWH
10509 +#undef AuTestEmpty_SHWH
10510 +#define AuTestEmpty_SHWH 0
10513 +struct test_empty_arg {
10514 + struct dir_context ctx;
10515 + struct au_nhash *whlist;
10516 + unsigned int flags;
10518 + aufs_bindex_t bindex;
10521 +static bool test_empty_cb(struct dir_context *ctx, const char *__name,
10522 + int namelen, loff_t offset __maybe_unused, u64 ino,
10523 + unsigned int d_type)
10525 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10527 + char *name = (void *)__name;
10530 + au_fset_testempty(arg->flags, CALLED);
10532 + if (name[0] == '.'
10533 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10534 + goto out; /* success */
10536 + if (namelen <= AUFS_WH_PFX_LEN
10537 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10538 + if (au_ftest_testempty(arg->flags, WHONLY)
10539 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10540 + arg->err = -ENOTEMPTY;
10544 + name += AUFS_WH_PFX_LEN;
10545 + namelen -= AUFS_WH_PFX_LEN;
10546 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10547 + arg->err = au_nhash_append_wh
10548 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10549 + au_ftest_testempty(arg->flags, SHWH));
10553 + AuTraceErr(arg->err);
10554 + return !arg->err;
10557 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10560 + struct file *h_file;
10561 + struct au_branch *br;
10563 + h_file = au_h_open(dentry, arg->bindex,
10564 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10565 + /*file*/NULL, /*force_wr*/0);
10566 + err = PTR_ERR(h_file);
10567 + if (IS_ERR(h_file))
10571 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10572 + && !file_inode(h_file)->i_nlink)
10577 + au_fclr_testempty(arg->flags, CALLED);
10579 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10582 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10586 + br = au_sbr(dentry->d_sb, arg->bindex);
10587 + au_lcnt_dec(&br->br_nfiles);
10592 +struct do_test_empty_args {
10594 + struct dentry *dentry;
10595 + struct test_empty_arg *arg;
10598 +static void call_do_test_empty(void *args)
10600 + struct do_test_empty_args *a = args;
10601 + *a->errp = do_test_empty(a->dentry, a->arg);
10604 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10606 + int err, wkq_err;
10607 + struct dentry *h_dentry;
10608 + struct inode *h_inode;
10609 + struct user_namespace *h_userns;
10611 + h_userns = au_sbr_userns(dentry->d_sb, arg->bindex);
10612 + h_dentry = au_h_dptr(dentry, arg->bindex);
10613 + h_inode = d_inode(h_dentry);
10614 + /* todo: i_mode changes anytime? */
10615 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10616 + err = au_test_h_perm_sio(h_userns, h_inode, MAY_EXEC | MAY_READ);
10617 + inode_unlock_shared(h_inode);
10619 + err = do_test_empty(dentry, arg);
10621 + struct do_test_empty_args args = {
10623 + .dentry = dentry,
10626 + unsigned int flags = arg->flags;
10628 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10629 + if (unlikely(wkq_err))
10631 + arg->flags = flags;
10637 +int au_test_empty_lower(struct dentry *dentry)
10640 + unsigned int rdhash;
10641 + aufs_bindex_t bindex, btop, btail;
10642 + struct au_nhash whlist;
10643 + struct test_empty_arg arg = {
10645 + .actor = test_empty_cb
10648 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10650 + SiMustAnyLock(dentry->d_sb);
10652 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10654 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10655 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10656 + if (unlikely(err))
10660 + arg.whlist = &whlist;
10661 + btop = au_dbtop(dentry);
10662 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10663 + au_fset_testempty(arg.flags, SHWH);
10664 + test_empty = do_test_empty;
10665 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10666 + test_empty = sio_test_empty;
10667 + arg.bindex = btop;
10668 + err = test_empty(dentry, &arg);
10669 + if (unlikely(err))
10672 + au_fset_testempty(arg.flags, WHONLY);
10673 + btail = au_dbtaildir(dentry);
10674 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10675 + struct dentry *h_dentry;
10677 + h_dentry = au_h_dptr(dentry, bindex);
10678 + if (h_dentry && d_is_positive(h_dentry)) {
10679 + arg.bindex = bindex;
10680 + err = test_empty(dentry, &arg);
10685 + au_nhash_wh_free(&whlist);
10690 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10693 + struct test_empty_arg arg = {
10695 + .actor = test_empty_cb
10698 + aufs_bindex_t bindex, btail;
10701 + arg.whlist = whlist;
10702 + arg.flags = AuTestEmpty_WHONLY;
10703 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10704 + au_fset_testempty(arg.flags, SHWH);
10705 + btail = au_dbtaildir(dentry);
10706 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10707 + struct dentry *h_dentry;
10709 + h_dentry = au_h_dptr(dentry, bindex);
10710 + if (h_dentry && d_is_positive(h_dentry)) {
10711 + arg.bindex = bindex;
10712 + err = sio_test_empty(dentry, &arg);
10719 +/* ---------------------------------------------------------------------- */
10721 +const struct file_operations aufs_dir_fop = {
10722 + .owner = THIS_MODULE,
10723 + .llseek = default_llseek,
10724 + .read = generic_read_dir,
10725 + .iterate_shared = aufs_iterate_shared,
10726 + .unlocked_ioctl = aufs_ioctl_dir,
10727 +#ifdef CONFIG_COMPAT
10728 + .compat_ioctl = aufs_compat_ioctl_dir,
10730 + .open = aufs_open_dir,
10731 + .release = aufs_release_dir,
10732 + .flush = aufs_flush_dir,
10733 + .fsync = aufs_fsync_dir
10735 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10736 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10737 +++ linux/fs/aufs/dir.h 2022-11-05 23:02:18.962555950 +0100
10739 +/* SPDX-License-Identifier: GPL-2.0 */
10741 + * Copyright (C) 2005-2022 Junjiro R. Okajima
10743 + * This program is free software; you can redistribute it and/or modify
10744 + * it under the terms of the GNU General Public License as published by
10745 + * the Free Software Foundation; either version 2 of the License, or
10746 + * (at your option) any later version.
10748 + * This program is distributed in the hope that it will be useful,
10749 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10750 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10751 + * GNU General Public License for more details.
10753 + * You should have received a copy of the GNU General Public License
10754 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10758 + * directory operations
10761 +#ifndef __AUFS_DIR_H__
10762 +#define __AUFS_DIR_H__
10766 +#include <linux/fs.h>
10768 +/* ---------------------------------------------------------------------- */
10770 +/* need to be faster and smaller */
10773 + unsigned int nh_num;
10774 + struct hlist_head *nh_head;
10777 +struct au_vdir_destr {
10778 + unsigned char len;
10779 + unsigned char name[];
10782 +struct au_vdir_dehstr {
10783 + struct hlist_node hash;
10784 + struct au_vdir_destr *str;
10785 + struct rcu_head rcu;
10786 +} ____cacheline_aligned_in_smp;
10788 +struct au_vdir_de {
10790 + unsigned char de_type;
10791 + /* caution: packed */
10792 + struct au_vdir_destr de_str;
10795 +struct au_vdir_wh {
10796 + struct hlist_node wh_hash;
10797 +#ifdef CONFIG_AUFS_SHWH
10799 + aufs_bindex_t wh_bindex;
10800 + unsigned char wh_type;
10802 + aufs_bindex_t wh_bindex;
10804 + /* caution: packed */
10805 + struct au_vdir_destr wh_str;
10808 +union au_vdir_deblk_p {
10809 + unsigned char *deblk;
10810 + struct au_vdir_de *de;
10814 + unsigned char **vd_deblk;
10815 + unsigned long vd_nblk;
10817 + unsigned long ul;
10818 + union au_vdir_deblk_p p;
10822 + unsigned int vd_deblk_sz;
10823 + unsigned long vd_jiffy;
10824 + struct rcu_head rcu;
10825 +} ____cacheline_aligned_in_smp;
10827 +/* ---------------------------------------------------------------------- */
10830 +extern const struct file_operations aufs_dir_fop;
10831 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10832 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10833 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10834 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10835 +int au_test_empty_lower(struct dentry *dentry);
10836 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10839 +unsigned int au_rdhash_est(loff_t sz);
10840 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10841 +void au_nhash_wh_free(struct au_nhash *whlist);
10842 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10844 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10845 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10846 + unsigned int d_type, aufs_bindex_t bindex,
10847 + unsigned char shwh);
10848 +void au_vdir_free(struct au_vdir *vdir);
10849 +int au_vdir_init(struct file *file);
10850 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10853 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10855 +#ifdef CONFIG_AUFS_RDU
10857 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10858 +#ifdef CONFIG_COMPAT
10859 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10860 + unsigned long arg);
10863 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10864 + unsigned int cmd, unsigned long arg)
10865 +#ifdef CONFIG_COMPAT
10866 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10867 + unsigned int cmd, unsigned long arg)
10871 +#endif /* __KERNEL__ */
10872 +#endif /* __AUFS_DIR_H__ */
10873 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10874 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10875 +++ linux/fs/aufs/dirren.c 2022-11-05 23:02:18.962555950 +0100
10877 +// SPDX-License-Identifier: GPL-2.0
10879 + * Copyright (C) 2017-2022 Junjiro R. Okajima
10881 + * This program is free software; you can redistribute it and/or modify
10882 + * it under the terms of the GNU General Public License as published by
10883 + * the Free Software Foundation; either version 2 of the License, or
10884 + * (at your option) any later version.
10886 + * This program is distributed in the hope that it will be useful,
10887 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10888 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10889 + * GNU General Public License for more details.
10891 + * You should have received a copy of the GNU General Public License
10892 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10896 + * special handling in renaming a directory
10897 + * in order to support looking-up the before-renamed name on the lower readonly
10901 +#include <linux/byteorder/generic.h>
10904 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10908 + idx = au_dr_ihash(ent->dr_h_ino);
10909 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10912 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10915 + struct hlist_bl_head *hbl;
10918 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10919 + hbl = dr->dr_h_ino + i;
10920 + hlist_bl_lock(hbl);
10921 + ret &= hlist_bl_empty(hbl);
10922 + hlist_bl_unlock(hbl);
10928 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10930 + struct au_dr_hino *found, *ent;
10931 + struct hlist_bl_head *hbl;
10932 + struct hlist_bl_node *pos;
10936 + idx = au_dr_ihash(ino);
10937 + hbl = dr->dr_h_ino + idx;
10938 + hlist_bl_lock(hbl);
10939 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10940 + if (ent->dr_h_ino == ino) {
10944 + hlist_bl_unlock(hbl);
10949 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10950 + struct au_dr_hino *add_ent)
10953 + struct hlist_bl_head *hbl;
10954 + struct hlist_bl_node *pos;
10955 + struct au_dr_hino *ent;
10958 + idx = au_dr_ihash(ino);
10959 + hbl = dr->dr_h_ino + idx;
10960 +#if 0 /* debug print */
10962 + struct hlist_bl_node *tmp;
10964 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10965 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10968 + hlist_bl_lock(hbl);
10969 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10970 + if (ent->dr_h_ino == ino) {
10974 + if (!found && add_ent)
10975 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10976 + hlist_bl_unlock(hbl);
10978 + if (!found && add_ent)
10979 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
10984 +void au_dr_hino_free(struct au_dr_br *dr)
10987 + struct hlist_bl_head *hbl;
10988 + struct hlist_bl_node *pos, *tmp;
10989 + struct au_dr_hino *ent;
10991 + /* SiMustWriteLock(sb); */
10993 + for (i = 0; i < AuDirren_NHASH; i++) {
10994 + hbl = dr->dr_h_ino + i;
10995 + /* no spinlock since sbinfo must be write-locked */
10996 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10997 + au_kfree_rcu(ent);
10998 + INIT_HLIST_BL_HEAD(hbl);
11002 +/* returns the number of inodes or an error */
11003 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11004 + struct file *hinofile)
11008 + loff_t pos, oldsize;
11010 + struct inode *hinoinode;
11011 + struct hlist_bl_head *hbl;
11012 + struct hlist_bl_node *n1, *n2;
11013 + struct au_dr_hino *ent;
11015 + SiMustWriteLock(sb);
11016 + AuDebugOn(!au_br_writable(br->br_perm));
11018 + hinoinode = file_inode(hinofile);
11019 + oldsize = i_size_read(hinoinode);
11023 + hbl = br->br_dirren.dr_h_ino;
11024 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11025 + /* no bit-lock since sbinfo must be write-locked */
11026 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11027 + AuDbg("hi%llu, %pD2\n",
11028 + (unsigned long long)ent->dr_h_ino, hinofile);
11029 + u64 = cpu_to_be64(ent->dr_h_ino);
11030 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11031 + if (ssz == sizeof(u64))
11034 + /* write error */
11035 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11042 + /* regardless the error */
11043 + if (pos < oldsize) {
11044 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11052 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11059 + struct au_dr_hino *ent;
11060 + struct inode *hinoinode;
11061 + struct hlist_bl_head *hbl;
11065 + hbl = dr->dr_h_ino;
11066 + hinoinode = file_inode(hinofile);
11067 + sz = i_size_read(hinoinode);
11068 + AuDebugOn(sz % sizeof(u64));
11069 + n = sz / sizeof(u64);
11071 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11072 + if (unlikely(ssz != sizeof(u64))) {
11073 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11080 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11086 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11087 + AuDbg("hi%llu, %pD2\n",
11088 + (unsigned long long)ent->dr_h_ino, hinofile);
11089 + hidx = au_dr_ihash(ent->dr_h_ino);
11090 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11092 + goto out; /* success */
11095 + au_dr_hino_free(dr);
11102 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11103 + * @path is a switch to distinguish load and store.
11105 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11106 + struct au_branch *br, const struct path *path)
11109 + unsigned char load, suspend;
11110 + struct file *hinofile;
11111 + struct au_hinode *hdir;
11112 + struct inode *dir, *delegated;
11113 + struct path hinopath;
11114 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11115 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11117 + AuDebugOn(bindex < 0 && !br);
11118 + AuDebugOn(bindex >= 0 && br);
11123 + br = au_sbr(sb, bindex);
11126 + path = &br->br_path;
11127 + AuDebugOn(!au_br_writable(br->br_perm));
11128 + if (unlikely(!au_br_writable(br->br_perm)))
11134 + dir = d_inode(sb->s_root);
11135 + hdir = au_hinode(au_ii(dir), bindex);
11136 + dir = hdir->hi_inode;
11137 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11139 + dir = d_inode(path->dentry);
11140 + inode_lock_nested(dir, AuLsc_I_CHILD);
11142 + hinopath.mnt = path->mnt;
11143 + hinopath.dentry = vfsub_lkup_one(&hinoname, (struct path *)path);
11144 + err = PTR_ERR(hinopath.dentry);
11145 + if (IS_ERR(hinopath.dentry))
11149 + flags = O_RDONLY;
11151 + if (d_is_negative(hinopath.dentry))
11152 + goto out_dput; /* success */
11154 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11155 + if (d_is_positive(hinopath.dentry)) {
11156 + delegated = NULL;
11157 + err = vfsub_unlink(dir, &hinopath, &delegated,
11160 + if (unlikely(err))
11161 + pr_err("ignored err %d, %pd2\n",
11162 + err, hinopath.dentry);
11163 + if (unlikely(err == -EWOULDBLOCK))
11168 + } else if (!d_is_positive(hinopath.dentry)) {
11169 + err = vfsub_create(dir, &hinopath, 0600,
11170 + /*want_excl*/false);
11172 + if (unlikely(err))
11175 + flags = O_WRONLY;
11177 + hinofile = vfsub_dentry_open(&hinopath, flags);
11179 + au_hn_inode_unlock(hdir);
11181 + inode_unlock(dir);
11182 + dput(hinopath.dentry);
11183 + AuTraceErrPtr(hinofile);
11184 + if (IS_ERR(hinofile)) {
11185 + err = PTR_ERR(hinofile);
11190 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11192 + err = au_dr_hino_store(sb, br, hinofile);
11197 + dput(hinopath.dentry);
11200 + au_hn_inode_unlock(hdir);
11202 + inode_unlock(dir);
11208 +/* ---------------------------------------------------------------------- */
11210 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11213 + struct kstatfs kstfs;
11215 + struct dentry *dentry;
11216 + struct super_block *sb;
11218 + err = vfs_statfs((void *)path, &kstfs);
11220 + if (unlikely(err))
11223 + /* todo: support for UUID */
11225 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11226 + brid->type = AuBrid_FSID;
11227 + brid->fsid = kstfs.f_fsid;
11229 + dentry = path->dentry;
11230 + sb = dentry->d_sb;
11233 + brid->type = AuBrid_DEV;
11242 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11243 + const struct path *path)
11246 + struct au_dr_br *dr;
11247 + struct hlist_bl_head *hbl;
11249 + dr = &br->br_dirren;
11250 + hbl = dr->dr_h_ino;
11251 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11252 + INIT_HLIST_BL_HEAD(hbl);
11254 + err = au_dr_brid_init(&dr->dr_brid, path);
11255 + if (unlikely(err))
11258 + if (au_opt_test(au_mntflags(sb), DIRREN))
11259 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11266 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11271 + if (au_br_writable(br->br_perm))
11272 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11274 + au_dr_hino_free(&br->br_dirren);
11279 +/* ---------------------------------------------------------------------- */
11281 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11282 + char *buf, size_t sz)
11285 + unsigned int major, minor;
11289 + err = snprintf(p, sz, "%d_", brid->type);
11290 + AuDebugOn(err > sz);
11293 + switch (brid->type) {
11294 + case AuBrid_Unset:
11296 + case AuBrid_UUID:
11297 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11299 + case AuBrid_FSID:
11300 + err = snprintf(p, sz, "%08x-%08x",
11301 + brid->fsid.val[0], brid->fsid.val[1]);
11304 + major = MAJOR(brid->dev);
11305 + minor = MINOR(brid->dev);
11306 + if (major <= 0xff && minor <= 0xff)
11307 + err = snprintf(p, sz, "%02x%02x", major, minor);
11309 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11312 + AuDebugOn(err > sz);
11315 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11316 + AuDebugOn(err > sz);
11323 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11326 + struct dentry *br_dentry;
11327 + struct inode *br_inode;
11329 + br_dentry = au_br_dentry(br);
11330 + br_inode = d_inode(br_dentry);
11331 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11332 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11333 + AuDebugOn(rlen > len);
11338 +/* ---------------------------------------------------------------------- */
11341 + * from the given @h_dentry, construct drinfo at @*fdata.
11342 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11345 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11346 + struct dentry *h_dentry,
11347 + unsigned char *allocated)
11350 + struct au_drinfo_fdata *f, *p;
11351 + struct au_drinfo *drinfo;
11352 + struct inode *h_inode;
11353 + struct qstr *qname;
11357 + h_inode = d_inode(h_dentry);
11358 + qname = &h_dentry->d_name;
11359 + drinfo = &f->drinfo;
11360 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11361 + drinfo->oldnamelen = qname->len;
11362 + if (*allocated < sizeof(*f) + qname->len) {
11363 + v = roundup_pow_of_two(*allocated + qname->len);
11364 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11365 + if (unlikely(!p)) {
11373 + drinfo = &f->drinfo;
11375 + memcpy(drinfo->oldname, qname->name, qname->len);
11376 + AuDbg("i%llu, %.*s\n",
11377 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11378 + drinfo->oldname);
11385 +/* callers have to free the return value */
11386 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11388 + struct au_drinfo *ret, *drinfo;
11389 + struct au_drinfo_fdata fdata;
11394 + ret = ERR_PTR(-EIO);
11396 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11397 + if (unlikely(ssz != sizeof(fdata))) {
11398 + AuIOErr("ssz %zd, %u, %pD2\n",
11399 + ssz, (unsigned int)sizeof(fdata), file);
11403 + fdata.magic = ntohl((__force __be32)fdata.magic);
11404 + switch (fdata.magic) {
11405 + case AUFS_DRINFO_MAGIC_V1:
11408 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11409 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11413 + drinfo = &fdata.drinfo;
11414 + len = drinfo->oldnamelen;
11416 + AuIOErr("broken drinfo %pD2\n", file);
11421 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11422 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11423 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11424 + (unsigned long long)drinfo->ino,
11425 + (unsigned long long)h_ino, file);
11426 + goto out; /* success */
11429 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11430 + if (unlikely(!ret)) {
11431 + ret = ERR_PTR(-ENOMEM);
11432 + AuTraceErrPtr(ret);
11437 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11438 + if (unlikely(ssz != len)) {
11439 + au_kfree_rcu(ret);
11440 + ret = ERR_PTR(-EIO);
11441 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11445 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11451 +/* ---------------------------------------------------------------------- */
11453 +/* in order to be revertible */
11454 +struct au_drinfo_rev_elm {
11456 + struct dentry *info_dentry;
11457 + struct au_drinfo *info_last;
11460 +struct au_drinfo_rev {
11461 + unsigned char already;
11462 + aufs_bindex_t nelm;
11463 + struct au_drinfo_rev_elm elm[];
11466 +/* todo: isn't it too large? */
11467 +struct au_drinfo_store {
11468 + struct path h_ppath;
11469 + struct dentry *h_dentry;
11470 + struct au_drinfo_fdata *fdata;
11471 + char *infoname; /* inside of whname, just after PFX */
11472 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11473 + aufs_bindex_t btgt, btail;
11474 + unsigned char no_sio,
11475 + allocated, /* current size of *fdata */
11476 + infonamelen, /* room size for p */
11477 + whnamelen, /* length of the generated name */
11478 + renameback; /* renamed back */
11481 +/* on rename(2) error, the caller should revert it using @elm */
11482 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11483 + struct au_drinfo_rev_elm *elm)
11488 + struct path infopath = {
11489 + .mnt = w->h_ppath.mnt
11491 + struct inode *h_dir, *h_inode, *delegated;
11492 + struct file *infofile;
11493 + struct qstr *qname;
11496 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11498 + infopath.dentry = vfsub_lookup_one_len(w->whname, &w->h_ppath,
11500 + AuTraceErrPtr(infopath.dentry);
11501 + if (IS_ERR(infopath.dentry)) {
11502 + err = PTR_ERR(infopath.dentry);
11507 + h_dir = d_inode(w->h_ppath.dentry);
11508 + if (elm && d_is_negative(infopath.dentry)) {
11509 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11511 + if (unlikely(err))
11513 + elm->created = 1;
11514 + elm->info_dentry = dget(infopath.dentry);
11517 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11518 + AuTraceErrPtr(infofile);
11519 + if (IS_ERR(infofile)) {
11520 + err = PTR_ERR(infofile);
11524 + h_inode = d_inode(infopath.dentry);
11525 + if (elm && i_size_read(h_inode)) {
11526 + h_inode = d_inode(w->h_dentry);
11527 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11528 + AuTraceErrPtr(elm->info_last);
11529 + if (IS_ERR(elm->info_last)) {
11530 + err = PTR_ERR(elm->info_last);
11531 + elm->info_last = NULL;
11532 + AuDebugOn(elm->info_dentry);
11537 + if (elm && w->renameback) {
11538 + delegated = NULL;
11539 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11541 + if (unlikely(err == -EWOULDBLOCK))
11547 + qname = &w->h_dentry->d_name;
11548 + len = sizeof(*w->fdata) + qname->len;
11550 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11551 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11552 + if (ssz == len) {
11553 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11554 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11555 + goto out_fput; /* success */
11560 + /* the caller should revert it using @elm */
11566 + dput(infopath.dentry);
11572 +struct au_call_drinfo_do_store_args {
11574 + struct au_drinfo_store *w;
11575 + struct au_drinfo_rev_elm *elm;
11578 +static void au_call_drinfo_do_store(void *args)
11580 + struct au_call_drinfo_do_store_args *a = args;
11582 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11585 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11586 + struct au_drinfo_rev_elm *elm)
11588 + int err, wkq_err;
11591 + err = au_drinfo_do_store(w, elm);
11593 + struct au_call_drinfo_do_store_args a = {
11598 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11599 + if (unlikely(wkq_err))
11607 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11608 + aufs_bindex_t btgt)
11612 + memset(w, 0, sizeof(*w));
11613 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11614 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11615 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11616 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11618 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11621 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11622 + if (unlikely(!w->fdata)) {
11626 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11633 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11635 + au_kfree_rcu(w->fdata);
11638 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11639 + struct au_drinfo_store *w)
11641 + struct au_drinfo_rev_elm *elm;
11642 + struct inode *h_dir, *delegated;
11644 + struct path infopath = {
11645 + .mnt = w->h_ppath.mnt
11648 + h_dir = d_inode(w->h_ppath.dentry);
11649 + IMustLock(h_dir);
11653 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11654 + AuDebugOn(elm->created && elm->info_last);
11655 + if (elm->created) {
11657 + delegated = NULL;
11658 + infopath.dentry = elm->info_dentry;
11659 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11662 + if (unlikely(err == -EWOULDBLOCK))
11664 + dput(elm->info_dentry);
11665 + } else if (elm->info_last) {
11667 + w->fdata->drinfo = *elm->info_last;
11668 + memcpy(w->fdata->drinfo.oldname,
11669 + elm->info_last->oldname,
11670 + elm->info_last->oldnamelen);
11671 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11672 + au_kfree_rcu(elm->info_last);
11674 + if (unlikely(err))
11675 + AuIOErr("%d, %s\n", err, w->whname);
11676 + /* go on even if err */
11680 +/* caller has to call au_dr_rename_fin() later */
11681 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11682 + struct qstr *dst_name, void *_rev)
11684 + int err, sz, nelm;
11685 + aufs_bindex_t bindex, btail;
11686 + struct au_drinfo_store work;
11687 + struct au_drinfo_rev *rev, **p;
11688 + struct au_drinfo_rev_elm *elm;
11689 + struct super_block *sb;
11690 + struct au_branch *br;
11691 + struct au_hinode *hdir;
11693 + err = au_drinfo_store_work_init(&work, btgt);
11695 + if (unlikely(err))
11699 + btail = au_dbtaildir(dentry);
11700 + nelm = btail - btgt;
11701 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11702 + rev = kcalloc(1, sz, GFP_NOFS);
11703 + if (unlikely(!rev)) {
11707 + rev->nelm = nelm;
11713 + sb = dentry->d_sb;
11714 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11715 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11716 + hdir = au_hi(d_inode(dentry), btgt);
11717 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11718 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11719 + work.h_dentry = au_h_dptr(dentry, bindex);
11720 + if (!work.h_dentry)
11723 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11724 + &work.allocated);
11726 + if (unlikely(err))
11729 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11730 + br = au_sbr(sb, bindex);
11731 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11732 + work.whnamelen += au_drinfo_name(br, work.infoname,
11733 + work.infonamelen);
11734 + AuDbg("whname %.*s, i%llu, %.*s\n",
11735 + work.whnamelen, work.whname,
11736 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11737 + work.fdata->drinfo.oldnamelen,
11738 + work.fdata->drinfo.oldname);
11740 + err = au_drinfo_store_sio(&work, elm);
11742 + if (unlikely(err))
11745 + if (unlikely(err)) {
11746 + /* revert all drinfo */
11747 + au_drinfo_store_rev(rev, &work);
11748 + au_kfree_try_rcu(rev);
11751 + au_hn_inode_unlock(hdir);
11754 + au_drinfo_store_work_fin(&work);
11759 +/* ---------------------------------------------------------------------- */
11761 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11762 + struct qstr *dst_name, void *_rev)
11764 + int err, already;
11766 + struct super_block *sb;
11767 + struct au_branch *br;
11768 + struct au_dr_br *dr;
11769 + struct dentry *h_dentry;
11770 + struct inode *h_inode;
11771 + struct au_dr_hino *ent;
11772 + struct au_drinfo_rev *rev, **p;
11774 + AuDbg("bindex %d\n", bindex);
11777 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11778 + if (unlikely(!ent))
11782 + br = au_sbr(sb, bindex);
11783 + dr = &br->br_dirren;
11784 + h_dentry = au_h_dptr(src, bindex);
11785 + h_inode = d_inode(h_dentry);
11786 + ino = h_inode->i_ino;
11787 + ent->dr_h_ino = ino;
11788 + already = au_dr_hino_test_add(dr, ino, ent);
11789 + AuDbg("b%d, hi%llu, already %d\n",
11790 + bindex, (unsigned long long)ino, already);
11792 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11797 + rev->already = already;
11798 + goto out; /* success */
11803 + au_dr_hino_del(dr, ent);
11804 + au_kfree_rcu(ent);
11811 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11813 + struct au_drinfo_rev *rev;
11814 + struct au_drinfo_rev_elm *elm;
11819 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11820 + dput(elm->info_dentry);
11821 + au_kfree_rcu(elm->info_last);
11823 + au_kfree_try_rcu(rev);
11826 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11829 + struct au_drinfo_store work;
11830 + struct au_drinfo_rev *rev = _rev;
11831 + struct super_block *sb;
11832 + struct au_branch *br;
11833 + struct inode *h_inode;
11834 + struct au_dr_br *dr;
11835 + struct au_dr_hino *ent;
11837 + err = au_drinfo_store_work_init(&work, btgt);
11838 + if (unlikely(err))
11842 + br = au_sbr(sb, btgt);
11843 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11844 + work.h_ppath.mnt = au_br_mnt(br);
11845 + au_drinfo_store_rev(rev, &work);
11846 + au_drinfo_store_work_fin(&work);
11847 + if (rev->already)
11850 + dr = &br->br_dirren;
11851 + h_inode = d_inode(work.h_ppath.dentry);
11852 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11854 + au_dr_hino_del(dr, ent);
11855 + au_kfree_rcu(ent);
11858 + au_kfree_try_rcu(rev);
11859 + if (unlikely(err))
11860 + pr_err("failed to remove dirren info\n");
11863 +/* ---------------------------------------------------------------------- */
11865 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11866 + char *whname, int whnamelen,
11867 + struct dentry **info_dentry)
11869 + struct au_drinfo *drinfo;
11871 + struct inode *h_dir;
11872 + struct path infopath;
11875 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11877 + *info_dentry = NULL;
11880 + h_dir = d_inode(h_ppath->dentry);
11881 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11882 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath, whnamelen);
11883 + if (IS_ERR(infopath.dentry)) {
11884 + drinfo = (void *)infopath.dentry;
11888 + if (d_is_negative(infopath.dentry))
11889 + goto out_dput; /* success */
11891 + infopath.mnt = h_ppath->mnt;
11892 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11893 + inode_unlock_shared(h_dir);
11896 + drinfo = (void *)f;
11900 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11901 + if (IS_ERR_OR_NULL(drinfo))
11904 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11905 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11910 + dput(infopath.dentry);
11913 + inode_unlock_shared(h_dir);
11914 + AuTraceErrPtr(drinfo);
11918 +struct au_drinfo_do_load_args {
11919 + struct au_drinfo **drinfop;
11920 + struct path *h_ppath;
11923 + struct dentry **info_dentry;
11926 +static void au_call_drinfo_do_load(void *args)
11928 + struct au_drinfo_do_load_args *a = args;
11930 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11934 +struct au_drinfo_load {
11935 + struct path h_ppath;
11936 + struct qstr *qname;
11937 + unsigned char no_sio;
11939 + aufs_bindex_t ninfo;
11940 + struct au_drinfo **drinfo;
11943 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11944 + struct au_branch *br)
11946 + int err, wkq_err, whnamelen, e;
11947 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11948 + = AUFS_WH_DR_INFO_PFX;
11949 + struct au_drinfo *drinfo;
11950 + struct qstr oldname;
11951 + struct inode *h_dir, *delegated;
11952 + struct dentry *info_dentry;
11953 + struct path infopath;
11955 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11956 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11957 + sizeof(whname) - whnamelen);
11959 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11962 + struct au_drinfo_do_load_args args = {
11963 + .drinfop = &drinfo,
11964 + .h_ppath = &w->h_ppath,
11965 + .whname = whname,
11966 + .whnamelen = whnamelen,
11967 + .info_dentry = &info_dentry
11969 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11970 + if (unlikely(wkq_err))
11971 + drinfo = ERR_PTR(wkq_err);
11973 + err = PTR_ERR(drinfo);
11974 + if (IS_ERR_OR_NULL(drinfo))
11978 + oldname.len = drinfo->oldnamelen;
11979 + oldname.name = drinfo->oldname;
11980 + if (au_qstreq(w->qname, &oldname)) {
11981 + /* the name is renamed back */
11982 + au_kfree_rcu(drinfo);
11985 + infopath.dentry = info_dentry;
11986 + infopath.mnt = w->h_ppath.mnt;
11987 + h_dir = d_inode(w->h_ppath.dentry);
11988 + delegated = NULL;
11989 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
11990 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
11991 + inode_unlock(h_dir);
11993 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
11994 + if (unlikely(e == -EWOULDBLOCK))
11997 + au_kfree_rcu(w->drinfo[bindex]);
11998 + w->drinfo[bindex] = drinfo;
11999 + dput(info_dentry);
12006 +/* ---------------------------------------------------------------------- */
12008 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12010 + struct au_drinfo **p = drinfo;
12013 + au_kfree_rcu(*drinfo++);
12014 + au_kfree_try_rcu(p);
12017 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12018 + aufs_bindex_t btgt)
12021 + struct au_drinfo_load w;
12022 + aufs_bindex_t bindex, bbot;
12023 + struct au_branch *br;
12024 + struct inode *h_dir;
12025 + struct au_dr_hino *ent;
12026 + struct super_block *sb;
12028 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12029 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12030 + AuLNPair(&lkup->whname), btgt);
12032 + sb = dentry->d_sb;
12033 + bbot = au_sbbot(sb);
12034 + w.ninfo = bbot + 1;
12035 + if (!lkup->dirren.drinfo) {
12036 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12037 + sizeof(*lkup->dirren.drinfo),
12039 + if (unlikely(!lkup->dirren.drinfo)) {
12043 + lkup->dirren.ninfo = w.ninfo;
12045 + w.drinfo = lkup->dirren.drinfo;
12046 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12047 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12048 + AuDebugOn(!w.h_ppath.dentry);
12049 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12050 + w.qname = &dentry->d_name;
12053 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12054 + br = au_sbr(sb, bindex);
12055 + err = au_drinfo_load(&w, bindex, br);
12056 + if (unlikely(err))
12058 + if (w.drinfo[bindex])
12062 + br = au_sbr(sb, btgt);
12063 + h_dir = d_inode(w.h_ppath.dentry);
12064 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12066 + au_dr_hino_del(&br->br_dirren, ent);
12067 + au_kfree_rcu(ent);
12069 + goto out; /* success */
12072 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12073 + lkup->dirren.ninfo = 0;
12074 + lkup->dirren.drinfo = NULL;
12080 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12082 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12085 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12088 + struct au_drinfo *drinfo;
12091 + if (!lkup->dirren.drinfo)
12093 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12094 + drinfo = lkup->dirren.drinfo[btgt];
12098 + au_kfree_try_rcu(lkup->whname.name);
12099 + lkup->whname.name = NULL;
12100 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12101 + lkup->dirren.dr_name.name = drinfo->oldname;
12102 + lkup->name = &lkup->dirren.dr_name;
12103 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12105 + AuDbg("name %.*s, whname %.*s, b%d\n",
12106 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12114 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12118 + struct au_drinfo *drinfo;
12121 + if (!lkup->dirren.drinfo)
12123 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12124 + drinfo = lkup->dirren.drinfo[bindex];
12128 + match = (drinfo->ino == h_ino);
12129 + AuDbg("match %d\n", match);
12135 +/* ---------------------------------------------------------------------- */
12137 +int au_dr_opt_set(struct super_block *sb)
12140 + aufs_bindex_t bindex, bbot;
12141 + struct au_branch *br;
12144 + bbot = au_sbbot(sb);
12145 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12146 + br = au_sbr(sb, bindex);
12147 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12153 +int au_dr_opt_flush(struct super_block *sb)
12156 + aufs_bindex_t bindex, bbot;
12157 + struct au_branch *br;
12160 + bbot = au_sbbot(sb);
12161 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12162 + br = au_sbr(sb, bindex);
12163 + if (au_br_writable(br->br_perm))
12164 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12170 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12173 + aufs_bindex_t bindex, bbot;
12174 + struct au_branch *br;
12178 + err = au_dr_opt_flush(sb);
12179 + if (unlikely(err))
12183 + bbot = au_sbbot(sb);
12184 + for (bindex = 0; bindex <= bbot; bindex++) {
12185 + br = au_sbr(sb, bindex);
12186 + au_dr_hino_free(&br->br_dirren);
12192 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12193 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12194 +++ linux/fs/aufs/dirren.h 2022-11-05 23:02:18.962555950 +0100
12196 +/* SPDX-License-Identifier: GPL-2.0 */
12198 + * Copyright (C) 2017-2022 Junjiro R. Okajima
12200 + * This program is free software; you can redistribute it and/or modify
12201 + * it under the terms of the GNU General Public License as published by
12202 + * the Free Software Foundation; either version 2 of the License, or
12203 + * (at your option) any later version.
12205 + * This program is distributed in the hope that it will be useful,
12206 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12207 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12208 + * GNU General Public License for more details.
12210 + * You should have received a copy of the GNU General Public License
12211 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12215 + * renamed dir info
12218 +#ifndef __AUFS_DIRREN_H__
12219 +#define __AUFS_DIRREN_H__
12223 +#include <linux/dcache.h>
12224 +#include <linux/statfs.h>
12225 +#include <linux/uuid.h>
12228 +#define AuDirren_NHASH 100
12230 +#ifdef CONFIG_AUFS_DIRREN
12231 +enum au_brid_type {
12238 +struct au_dr_brid {
12239 + enum au_brid_type type;
12241 + uuid_t uuid; /* unimplemented yet */
12247 +/* 20 is the max digits length of ulong 64 */
12248 +/* brid-type "_" uuid "_" inum */
12249 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12250 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12252 +struct au_dr_hino {
12253 + struct hlist_bl_node dr_hnode;
12258 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12259 + struct au_dr_brid dr_brid;
12262 +struct au_dr_lookup {
12263 + /* dr_name is pointed by struct au_do_lookup_args.name */
12264 + struct qstr dr_name; /* subset of dr_info */
12265 + aufs_bindex_t ninfo;
12266 + struct au_drinfo **drinfo;
12269 +struct au_dr_hino;
12271 +struct au_dr_br { };
12272 +struct au_dr_lookup { };
12275 +/* ---------------------------------------------------------------------- */
12278 +struct au_do_lookup_args;
12280 +#ifdef CONFIG_AUFS_DIRREN
12281 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12282 + struct au_dr_hino *add_ent);
12283 +void au_dr_hino_free(struct au_dr_br *dr);
12284 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12285 + const struct path *path);
12286 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12287 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12288 + struct qstr *dst_name, void *_rev);
12289 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12290 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12291 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12292 + aufs_bindex_t bindex);
12293 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12294 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12296 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12297 +int au_dr_opt_set(struct super_block *sb);
12298 +int au_dr_opt_flush(struct super_block *sb);
12299 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12301 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12302 + struct au_dr_hino *add_ent);
12303 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12304 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12305 + const struct path *path);
12306 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12307 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12308 + struct qstr *dst_name, void *_rev);
12309 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12310 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12312 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12313 + aufs_bindex_t bindex);
12314 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12315 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12316 + aufs_bindex_t bindex, ino_t h_ino);
12317 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12318 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12319 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12320 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12323 +/* ---------------------------------------------------------------------- */
12325 +#ifdef CONFIG_AUFS_DIRREN
12326 +static inline int au_dr_ihash(ino_t h_ino)
12328 + return h_ino % AuDirren_NHASH;
12331 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12334 +#endif /* __KERNEL__ */
12335 +#endif /* __AUFS_DIRREN_H__ */
12336 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12337 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12338 +++ linux/fs/aufs/dynop.c 2022-11-05 23:02:18.962555950 +0100
12340 +// SPDX-License-Identifier: GPL-2.0
12342 + * Copyright (C) 2010-2022 Junjiro R. Okajima
12344 + * This program is free software; you can redistribute it and/or modify
12345 + * it under the terms of the GNU General Public License as published by
12346 + * the Free Software Foundation; either version 2 of the License, or
12347 + * (at your option) any later version.
12349 + * This program is distributed in the hope that it will be useful,
12350 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12351 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12352 + * GNU General Public License for more details.
12354 + * You should have received a copy of the GNU General Public License
12355 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12359 + * dynamically customizable operations for regular files
12364 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12367 + * How large will these lists be?
12368 + * Usually just a few elements, 20-30 at most for each, I guess.
12370 +static struct hlist_bl_head dynop[AuDyLast];
12372 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12373 + const void *h_op)
12375 + struct au_dykey *key, *tmp;
12376 + struct hlist_bl_node *pos;
12379 + hlist_bl_lock(hbl);
12380 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12381 + if (tmp->dk_op.dy_hop == h_op) {
12382 + if (kref_get_unless_zero(&tmp->dk_kref))
12386 + hlist_bl_unlock(hbl);
12391 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12393 + struct au_dykey **k, *found;
12394 + const void *h_op = key->dk_op.dy_hop;
12398 + k = br->br_dykey;
12399 + for (i = 0; i < AuBrDynOp; i++)
12401 + if (k[i]->dk_op.dy_hop == h_op) {
12408 + spin_lock(&br->br_dykey_lock);
12409 + for (; i < AuBrDynOp; i++)
12411 + if (k[i]->dk_op.dy_hop == h_op) {
12419 + spin_unlock(&br->br_dykey_lock);
12420 + BUG_ON(i == AuBrDynOp); /* expand the array */
12426 +/* kref_get() if @key is already added */
12427 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12429 + struct au_dykey *tmp, *found;
12430 + struct hlist_bl_node *pos;
12431 + const void *h_op = key->dk_op.dy_hop;
12434 + hlist_bl_lock(hbl);
12435 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12436 + if (tmp->dk_op.dy_hop == h_op) {
12437 + if (kref_get_unless_zero(&tmp->dk_kref))
12442 + hlist_bl_add_head(&key->dk_hnode, hbl);
12443 + hlist_bl_unlock(hbl);
12450 +static void dy_free_rcu(struct rcu_head *rcu)
12452 + struct au_dykey *key;
12454 + key = container_of(rcu, struct au_dykey, dk_rcu);
12459 +static void dy_free(struct kref *kref)
12461 + struct au_dykey *key;
12462 + struct hlist_bl_head *hbl;
12464 + key = container_of(kref, struct au_dykey, dk_kref);
12465 + hbl = dynop + key->dk_op.dy_type;
12466 + au_hbl_del(&key->dk_hnode, hbl);
12467 + call_rcu(&key->dk_rcu, dy_free_rcu);
12470 +void au_dy_put(struct au_dykey *key)
12472 + kref_put(&key->dk_kref, dy_free);
12475 +/* ---------------------------------------------------------------------- */
12477 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12479 +#ifdef CONFIG_AUFS_DEBUG
12480 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12481 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12483 +#define DyDbgDeclare(cnt) do {} while (0)
12484 +#define DyDbgInc(cnt) do {} while (0)
12487 +#define DySet(func, dst, src, h_op, h_sb) do { \
12489 + if (h_op->func) { \
12491 + dst.func = src.func; \
12493 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12497 +#define DySetForce(func, dst, src) do { \
12498 + AuDebugOn(!src.func); \
12500 + dst.func = src.func; \
12503 +#define DySetAop(func) \
12504 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12505 +#define DySetAopForce(func) \
12506 + DySetForce(func, dyaop->da_op, aufs_aop)
12508 +static void dy_aop(struct au_dykey *key, const void *h_op,
12509 + struct super_block *h_sb __maybe_unused)
12511 + struct au_dyaop *dyaop = (void *)key;
12512 + const struct address_space_operations *h_aop = h_op;
12513 + DyDbgDeclare(cnt);
12515 + AuDbg("%s\n", au_sbtype(h_sb));
12517 + DySetAop(writepage);
12518 + DySetAopForce(read_folio); /* force */
12519 + DySetAop(writepages);
12520 + DySetAop(dirty_folio);
12521 + DySetAop(invalidate_folio);
12522 + DySetAop(readahead);
12523 + DySetAop(write_begin);
12524 + DySetAop(write_end);
12526 + DySetAop(release_folio);
12527 + DySetAop(free_folio);
12528 + /* this one will be changed according to an aufs mount option */
12529 + DySetAop(direct_IO);
12530 + DySetAop(migrate_folio);
12531 + DySetAop(launder_folio);
12532 + DySetAop(is_partially_uptodate);
12533 + DySetAop(is_dirty_writeback);
12534 + DySetAop(error_remove_page);
12535 + DySetAop(swap_activate);
12536 + DySetAop(swap_deactivate);
12537 + DySetAop(swap_rw);
12539 + DyDbgSize(cnt, *h_aop);
12542 +/* ---------------------------------------------------------------------- */
12544 +static void dy_bug(struct kref *kref)
12549 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12551 + struct au_dykey *key, *old;
12552 + struct hlist_bl_head *hbl;
12555 + void (*set)(struct au_dykey *key, const void *h_op,
12556 + struct super_block *h_sb __maybe_unused);
12558 + static const struct op a[] = {
12560 + .sz = sizeof(struct au_dyaop),
12564 + const struct op *p;
12566 + hbl = dynop + op->dy_type;
12567 + key = dy_gfind_get(hbl, op->dy_hop);
12569 + goto out_add; /* success */
12571 + p = a + op->dy_type;
12572 + key = kzalloc(p->sz, GFP_NOFS);
12573 + if (unlikely(!key)) {
12574 + key = ERR_PTR(-ENOMEM);
12578 + key->dk_op.dy_hop = op->dy_hop;
12579 + kref_init(&key->dk_kref);
12580 + p->set(key, op->dy_hop, au_br_sb(br));
12581 + old = dy_gadd(hbl, key);
12583 + au_kfree_rcu(key);
12588 + old = dy_bradd(br, key);
12590 + /* its ref-count should never be zero here */
12591 + kref_put(&key->dk_kref, dy_bug);
12596 +/* ---------------------------------------------------------------------- */
12598 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12599 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12600 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12601 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12602 + * See the aufs manual in detail.
12604 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12607 + dyaop->da_op.direct_IO = NULL;
12609 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12612 +static struct au_dyaop *dy_aget(struct au_branch *br,
12613 + const struct address_space_operations *h_aop,
12616 + struct au_dyaop *dyaop;
12617 + struct au_dynop op;
12619 + op.dy_type = AuDy_AOP;
12620 + op.dy_haop = h_aop;
12621 + dyaop = (void *)dy_get(&op, br);
12622 + if (IS_ERR(dyaop))
12624 + dy_adx(dyaop, do_dx);
12630 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12631 + struct inode *h_inode)
12634 + struct super_block *sb;
12635 + struct au_branch *br;
12636 + struct au_dyaop *dyaop;
12638 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12639 + IiMustWriteLock(inode);
12641 + sb = inode->i_sb;
12642 + br = au_sbr(sb, bindex);
12643 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12644 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12645 + err = PTR_ERR(dyaop);
12646 + if (IS_ERR(dyaop))
12647 + /* unnecessary to call dy_fput() */
12651 + inode->i_mapping->a_ops = &dyaop->da_op;
12658 + * Is it safe to replace a_ops during the inode/file is in operation?
12659 + * Yes, I hope so.
12661 +int au_dy_irefresh(struct inode *inode)
12664 + aufs_bindex_t btop;
12665 + struct inode *h_inode;
12668 + if (S_ISREG(inode->i_mode)) {
12669 + btop = au_ibtop(inode);
12670 + h_inode = au_h_iptr(inode, btop);
12671 + err = au_dy_iaop(inode, btop, h_inode);
12676 +void au_dy_arefresh(int do_dx)
12678 + struct hlist_bl_head *hbl;
12679 + struct hlist_bl_node *pos;
12680 + struct au_dykey *key;
12682 + hbl = dynop + AuDy_AOP;
12683 + hlist_bl_lock(hbl);
12684 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12685 + dy_adx((void *)key, do_dx);
12686 + hlist_bl_unlock(hbl);
12689 +/* ---------------------------------------------------------------------- */
12691 +void __init au_dy_init(void)
12695 + for (i = 0; i < AuDyLast; i++)
12696 + INIT_HLIST_BL_HEAD(dynop + i);
12699 +void au_dy_fin(void)
12703 + for (i = 0; i < AuDyLast; i++)
12704 + WARN_ON(!hlist_bl_empty(dynop + i));
12706 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12707 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12708 +++ linux/fs/aufs/dynop.h 2022-11-05 23:02:18.962555950 +0100
12710 +/* SPDX-License-Identifier: GPL-2.0 */
12712 + * Copyright (C) 2010-2022 Junjiro R. Okajima
12714 + * This program is free software; you can redistribute it and/or modify
12715 + * it under the terms of the GNU General Public License as published by
12716 + * the Free Software Foundation; either version 2 of the License, or
12717 + * (at your option) any later version.
12719 + * This program is distributed in the hope that it will be useful,
12720 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12721 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12722 + * GNU General Public License for more details.
12724 + * You should have received a copy of the GNU General Public License
12725 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12729 + * dynamically customizable operations (for regular files only)
12732 +#ifndef __AUFS_DYNOP_H__
12733 +#define __AUFS_DYNOP_H__
12737 +#include <linux/fs.h>
12738 +#include <linux/kref.h>
12740 +enum {AuDy_AOP, AuDyLast};
12745 + const void *dy_hop;
12746 + const struct address_space_operations *dy_haop;
12752 + struct hlist_bl_node dk_hnode;
12753 + struct rcu_head dk_rcu;
12755 + struct au_dynop dk_op;
12758 + * during I am in the branch local array, kref is gotten. when the
12759 + * branch is removed, kref is put.
12761 + struct kref dk_kref;
12764 +/* stop unioning since their sizes are very different from each other */
12766 + struct au_dykey da_key;
12767 + struct address_space_operations da_op; /* not const */
12769 +/* make sure that 'struct au_dykey *' can be any type */
12770 +static_assert(!offsetof(struct au_dyaop, da_key));
12772 +/* ---------------------------------------------------------------------- */
12776 +void au_dy_put(struct au_dykey *key);
12777 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12778 + struct inode *h_inode);
12779 +int au_dy_irefresh(struct inode *inode);
12780 +void au_dy_arefresh(int do_dio);
12782 +void __init au_dy_init(void);
12783 +void au_dy_fin(void);
12785 +#endif /* __KERNEL__ */
12786 +#endif /* __AUFS_DYNOP_H__ */
12787 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12788 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12789 +++ linux/fs/aufs/export.c 2022-12-17 09:21:34.796521861 +0100
12791 +// SPDX-License-Identifier: GPL-2.0
12793 + * Copyright (C) 2005-2022 Junjiro R. Okajima
12795 + * This program is free software; you can redistribute it and/or modify
12796 + * it under the terms of the GNU General Public License as published by
12797 + * the Free Software Foundation; either version 2 of the License, or
12798 + * (at your option) any later version.
12800 + * This program is distributed in the hope that it will be useful,
12801 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12802 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12803 + * GNU General Public License for more details.
12805 + * You should have received a copy of the GNU General Public License
12806 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12813 +#include <linux/exportfs.h>
12814 +#include <linux/fs_struct.h>
12815 +#include <linux/nsproxy.h>
12816 +#include <linux/random.h>
12817 +#include <linux/writeback.h>
12821 +#ifdef CONFIG_AUFS_INO_T_64
12829 +static ino_t decode_ino(__u32 *a)
12833 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12835 +#ifdef CONFIG_AUFS_INO_T_64
12841 +static void encode_ino(__u32 *a, ino_t ino)
12847 +#ifdef CONFIG_AUFS_INO_T_64
12852 +/* NFS file handle */
12856 +#ifdef CONFIG_AUFS_INO_T_64
12857 + /* support 64bit inode number */
12870 + Fh_ino = Fh_ino1,
12871 + Fh_dir_ino = Fh_dir_ino1
12874 +static int au_test_anon(struct dentry *dentry)
12876 + /* note: read d_flags without d_lock */
12877 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12880 +int au_test_nfsd(void)
12883 + struct task_struct *tsk = current;
12884 + char comm[sizeof(tsk->comm)];
12887 + if (tsk->flags & PF_KTHREAD) {
12888 + get_task_comm(comm, tsk);
12889 + ret = !strcmp(comm, "nfsd");
12895 +/* ---------------------------------------------------------------------- */
12896 +/* inode generation external table */
12898 +void au_xigen_inc(struct inode *inode)
12903 + struct super_block *sb;
12904 + struct au_sbinfo *sbinfo;
12906 + sb = inode->i_sb;
12907 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12909 + sbinfo = au_sbi(sb);
12910 + pos = inode->i_ino;
12911 + pos *= sizeof(igen);
12912 + igen = inode->i_generation + 1;
12913 + sz = xino_fwrite(sbinfo->si_xigen, &igen, sizeof(igen), &pos);
12914 + if (sz == sizeof(igen))
12915 + return; /* success */
12917 + if (unlikely(sz >= 0))
12918 + AuIOErr("xigen error (%zd)\n", sz);
12921 +int au_xigen_new(struct inode *inode)
12926 + struct super_block *sb;
12927 + struct au_sbinfo *sbinfo;
12928 + struct file *file;
12931 + /* todo: dirty, at mount time */
12932 + if (inode->i_ino == AUFS_ROOT_INO)
12934 + sb = inode->i_sb;
12935 + SiMustAnyLock(sb);
12936 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12940 + pos = inode->i_ino;
12941 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12942 + AuIOErr1("too large i%lld\n", pos);
12945 + pos *= sizeof(inode->i_generation);
12948 + sbinfo = au_sbi(sb);
12949 + file = sbinfo->si_xigen;
12952 + if (vfsub_f_size_read(file)
12953 + < pos + sizeof(inode->i_generation)) {
12954 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12955 + sz = xino_fwrite(file, &inode->i_generation,
12956 + sizeof(inode->i_generation), &pos);
12958 + sz = xino_fread(file, &inode->i_generation,
12959 + sizeof(inode->i_generation), &pos);
12960 + if (sz == sizeof(inode->i_generation))
12961 + goto out; /* success */
12964 + if (unlikely(sz >= 0)) {
12966 + AuIOErr("xigen error (%zd)\n", sz);
12973 +int au_xigen_set(struct super_block *sb, struct path *path)
12976 + struct au_sbinfo *sbinfo;
12977 + struct file *file;
12979 + SiMustWriteLock(sb);
12981 + sbinfo = au_sbi(sb);
12982 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
12983 + err = PTR_ERR(file);
12984 + if (IS_ERR(file))
12987 + if (sbinfo->si_xigen)
12988 + fput(sbinfo->si_xigen);
12989 + sbinfo->si_xigen = file;
12996 +void au_xigen_clr(struct super_block *sb)
12998 + struct au_sbinfo *sbinfo;
13000 + SiMustWriteLock(sb);
13002 + sbinfo = au_sbi(sb);
13003 + if (sbinfo->si_xigen) {
13004 + fput(sbinfo->si_xigen);
13005 + sbinfo->si_xigen = NULL;
13009 +/* ---------------------------------------------------------------------- */
13011 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13014 + struct dentry *dentry, *d;
13015 + struct inode *inode;
13016 + unsigned int sigen;
13019 + inode = ilookup(sb, ino);
13023 + dentry = ERR_PTR(-ESTALE);
13024 + sigen = au_sigen(sb);
13025 + if (unlikely(au_is_bad_inode(inode)
13026 + || IS_DEADDIR(inode)
13027 + || sigen != au_iigen(inode, NULL)))
13031 + if (!dir_ino || S_ISDIR(inode->i_mode))
13032 + dentry = d_find_alias(inode);
13034 + spin_lock(&inode->i_lock);
13035 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13036 + spin_lock(&d->d_lock);
13037 + if (!au_test_anon(d)
13038 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13039 + dentry = dget_dlock(d);
13040 + spin_unlock(&d->d_lock);
13043 + spin_unlock(&d->d_lock);
13045 + spin_unlock(&inode->i_lock);
13047 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13048 + /* need to refresh */
13056 + AuTraceErrPtr(dentry);
13060 +/* ---------------------------------------------------------------------- */
13062 +/* todo: dirty? */
13063 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13065 +struct au_compare_mnt_args {
13067 + struct super_block *sb;
13070 + struct vfsmount *mnt;
13073 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13075 + struct au_compare_mnt_args *a = arg;
13077 + if (mnt->mnt_sb != a->sb)
13079 + a->mnt = mntget(mnt);
13083 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13086 + struct path root;
13087 + struct au_compare_mnt_args args = {
13091 + get_fs_root(current->fs, &root);
13093 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13094 + rcu_read_unlock();
13097 + AuDebugOn(!args.mnt);
13101 +struct au_nfsd_si_lock {
13102 + unsigned int sigen;
13103 + aufs_bindex_t bindex, br_id;
13104 + unsigned char force_lock;
13107 +static int si_nfsd_read_lock(struct super_block *sb,
13108 + struct au_nfsd_si_lock *nsi_lock)
13111 + aufs_bindex_t bindex;
13113 + si_read_lock(sb, AuLock_FLUSH);
13115 + /* branch id may be wrapped around */
13117 + bindex = au_br_index(sb, nsi_lock->br_id);
13118 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13119 + goto out; /* success */
13123 + if (!nsi_lock->force_lock)
13124 + si_read_unlock(sb);
13127 + nsi_lock->bindex = bindex;
13131 +struct find_name_by_ino {
13132 + struct dir_context ctx;
13133 + int called, found;
13140 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13141 + loff_t offset, u64 ino, unsigned int d_type)
13143 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13147 + if (a->ino != ino)
13150 + memcpy(a->name, name, namelen);
13151 + a->namelen = namelen;
13156 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13157 + struct au_nfsd_si_lock *nsi_lock)
13159 + struct dentry *dentry, *parent;
13160 + struct file *file;
13161 + struct inode *dir;
13162 + struct find_name_by_ino arg = {
13164 + .actor = find_name_by_ino
13169 + parent = path->dentry;
13171 + si_read_unlock(parent->d_sb);
13172 + file = vfsub_dentry_open(path, au_dir_roflags);
13173 + dentry = (void *)file;
13174 + if (IS_ERR(file))
13177 + dentry = ERR_PTR(-ENOMEM);
13178 + arg.name = (void *)__get_free_page(GFP_NOFS);
13179 + if (unlikely(!arg.name))
13186 + err = vfsub_iterate_dir(file, &arg.ctx);
13187 + } while (!err && !arg.found && arg.called);
13188 + dentry = ERR_PTR(err);
13189 + if (unlikely(err))
13191 + /* instead of ENOENT */
13192 + dentry = ERR_PTR(-ESTALE);
13196 + /* do not call vfsub_lkup_one() */
13197 + dir = d_inode(parent);
13198 + dentry = vfsub_lookup_one_len_unlocked(arg.name, path, arg.namelen);
13199 + AuTraceErrPtr(dentry);
13200 + if (IS_ERR(dentry))
13202 + AuDebugOn(au_test_anon(dentry));
13203 + if (unlikely(d_really_is_negative(dentry))) {
13205 + dentry = ERR_PTR(-ENOENT);
13209 + free_page((unsigned long)arg.name);
13213 + if (unlikely(nsi_lock
13214 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13215 + if (!IS_ERR(dentry)) {
13217 + dentry = ERR_PTR(-ESTALE);
13219 + AuTraceErrPtr(dentry);
13223 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13225 + struct au_nfsd_si_lock *nsi_lock)
13227 + struct dentry *dentry;
13228 + struct path path;
13230 + if (dir_ino != AUFS_ROOT_INO) {
13231 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13232 + dentry = path.dentry;
13233 + if (!path.dentry || IS_ERR(path.dentry))
13235 + AuDebugOn(au_test_anon(path.dentry));
13237 + path.dentry = dget(sb->s_root);
13239 + path.mnt = au_mnt_get(sb);
13240 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13244 + AuTraceErrPtr(dentry);
13248 +/* ---------------------------------------------------------------------- */
13250 +static int h_acceptable(void *expv, struct dentry *dentry)
13255 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13256 + char *buf, int len, struct super_block *sb)
13260 + struct path path;
13262 + p = d_path(h_rootpath, buf, len);
13267 + path.mnt = h_rootpath->mnt;
13268 + path.dentry = h_parent;
13269 + p = d_path(&path, buf, len);
13275 + path.mnt = au_mnt_get(sb);
13276 + path.dentry = sb->s_root;
13277 + p = d_path(&path, buf, len - strlen(p));
13278 + mntput(path.mnt);
13282 + p[strlen(p)] = '/';
13285 + AuTraceErrPtr(p);
13290 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13291 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13293 + struct dentry *dentry, *h_parent, *root;
13294 + struct super_block *h_sb;
13295 + char *pathname, *p;
13296 + struct vfsmount *h_mnt;
13297 + struct au_branch *br;
13299 + struct path path;
13301 + br = au_sbr(sb, nsi_lock->bindex);
13302 + h_mnt = au_br_mnt(br);
13303 + h_sb = h_mnt->mnt_sb;
13304 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13306 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13307 + fh_len - Fh_tail, fh[Fh_h_type],
13308 + h_acceptable, /*context*/NULL);
13310 + dentry = h_parent;
13311 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13312 + AuWarn1("%s decode_fh failed, %ld\n",
13313 + au_sbtype(h_sb), PTR_ERR(h_parent));
13317 + if (unlikely(au_test_anon(h_parent))) {
13318 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13319 + au_sbtype(h_sb));
13320 + goto out_h_parent;
13323 + dentry = ERR_PTR(-ENOMEM);
13324 + pathname = (void *)__get_free_page(GFP_NOFS);
13325 + if (unlikely(!pathname))
13326 + goto out_h_parent;
13328 + root = sb->s_root;
13329 + path.mnt = h_mnt;
13330 + di_read_lock_parent(root, !AuLock_IR);
13331 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13332 + di_read_unlock(root, !AuLock_IR);
13333 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13334 + dentry = (void *)p;
13336 + goto out_pathname;
13338 + si_read_unlock(sb);
13339 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13340 + dentry = ERR_PTR(err);
13341 + if (unlikely(err))
13344 + dentry = ERR_PTR(-ENOENT);
13345 + AuDebugOn(au_test_anon(path.dentry));
13346 + if (unlikely(d_really_is_negative(path.dentry)))
13349 + if (ino != d_inode(path.dentry)->i_ino)
13350 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13352 + dentry = dget(path.dentry);
13357 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13358 + if (!IS_ERR(dentry)) {
13360 + dentry = ERR_PTR(-ESTALE);
13363 + free_page((unsigned long)pathname);
13367 + AuTraceErrPtr(dentry);
13371 +/* ---------------------------------------------------------------------- */
13373 +static struct dentry *
13374 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13377 + struct dentry *dentry;
13378 + __u32 *fh = fid->raw;
13379 + struct au_branch *br;
13380 + ino_t ino, dir_ino;
13381 + struct au_nfsd_si_lock nsi_lock = {
13385 + dentry = ERR_PTR(-ESTALE);
13386 + /* it should never happen, but the file handle is unreliable */
13387 + if (unlikely(fh_len < Fh_tail))
13389 + nsi_lock.sigen = fh[Fh_sigen];
13390 + nsi_lock.br_id = fh[Fh_br_id];
13392 + /* branch id may be wrapped around */
13394 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13396 + nsi_lock.force_lock = 1;
13398 + /* is this inode still cached? */
13399 + ino = decode_ino(fh + Fh_ino);
13400 + /* it should never happen */
13401 + if (unlikely(ino == AUFS_ROOT_INO))
13404 + dir_ino = decode_ino(fh + Fh_dir_ino);
13405 + dentry = decode_by_ino(sb, ino, dir_ino);
13406 + if (IS_ERR(dentry))
13411 + /* is the parent dir cached? */
13412 + br = au_sbr(sb, nsi_lock.bindex);
13413 + au_lcnt_inc(&br->br_nfiles);
13414 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13415 + if (IS_ERR(dentry))
13420 + /* lookup path */
13421 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13422 + if (IS_ERR(dentry))
13424 + if (unlikely(!dentry))
13425 + /* todo?: make it ESTALE */
13429 + if (!au_digen_test(dentry, au_sigen(sb))
13430 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13431 + goto out_unlock; /* success */
13434 + dentry = ERR_PTR(-ESTALE);
13437 + au_lcnt_dec(&br->br_nfiles);
13438 + si_read_unlock(sb);
13440 + AuTraceErrPtr(dentry);
13444 +#if 0 /* reserved for future use */
13445 +/* support subtreecheck option */
13446 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13447 + int fh_len, int fh_type)
13449 + struct dentry *parent;
13450 + __u32 *fh = fid->raw;
13453 + dir_ino = decode_ino(fh + Fh_dir_ino);
13454 + parent = decode_by_ino(sb, dir_ino, 0);
13455 + if (IS_ERR(parent))
13458 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13459 + dir_ino, fh, fh_len);
13462 + AuTraceErrPtr(parent);
13467 +/* ---------------------------------------------------------------------- */
13469 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13470 + struct inode *dir)
13473 + aufs_bindex_t bindex;
13474 + struct super_block *sb, *h_sb;
13475 + struct dentry *dentry, *parent, *h_parent;
13476 + struct inode *h_dir;
13477 + struct au_branch *br;
13480 + if (unlikely(*max_len <= Fh_tail)) {
13481 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13485 + err = FILEID_ROOT;
13486 + if (inode->i_ino == AUFS_ROOT_INO) {
13487 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13492 + sb = inode->i_sb;
13493 + err = si_read_lock(sb, AuLock_FLUSH);
13494 + if (unlikely(err))
13497 +#ifdef CONFIG_AUFS_DEBUG
13498 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13499 + AuWarn1("NFS-exporting requires xino\n");
13503 + ii_read_lock_child(inode);
13504 + bindex = au_ibtop(inode);
13506 + dentry = d_find_any_alias(inode);
13507 + if (unlikely(!dentry))
13509 + AuDebugOn(au_test_anon(dentry));
13510 + parent = dget_parent(dentry);
13512 + if (unlikely(!parent))
13514 + if (d_really_is_positive(parent))
13515 + dir = d_inode(parent);
13518 + ii_read_lock_parent(dir);
13519 + h_dir = au_h_iptr(dir, bindex);
13520 + ii_read_unlock(dir);
13521 + if (unlikely(!h_dir))
13523 + h_parent = d_find_any_alias(h_dir);
13524 + if (unlikely(!h_parent))
13525 + goto out_hparent;
13528 + br = au_sbr(sb, bindex);
13529 + h_sb = au_br_sb(br);
13530 + if (unlikely(!h_sb->s_export_op)) {
13531 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13532 + goto out_hparent;
13535 + fh[Fh_br_id] = br->br_id;
13536 + fh[Fh_sigen] = au_sigen(sb);
13537 + encode_ino(fh + Fh_ino, inode->i_ino);
13538 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13539 + fh[Fh_igen] = inode->i_generation;
13541 + *max_len -= Fh_tail;
13542 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13544 + /*connectable or subtreecheck*/0);
13545 + err = fh[Fh_h_type];
13546 + *max_len += Fh_tail;
13547 + /* todo: macros? */
13548 + if (err != FILEID_INVALID)
13551 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13558 + ii_read_unlock(inode);
13559 + si_read_unlock(sb);
13561 + if (unlikely(err < 0))
13562 + err = FILEID_INVALID;
13566 +/* ---------------------------------------------------------------------- */
13568 +static int aufs_commit_metadata(struct inode *inode)
13571 + aufs_bindex_t bindex;
13572 + struct super_block *sb;
13573 + struct inode *h_inode;
13574 + int (*f)(struct inode *inode);
13576 + sb = inode->i_sb;
13577 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13578 + ii_write_lock_child(inode);
13579 + bindex = au_ibtop(inode);
13580 + AuDebugOn(bindex < 0);
13581 + h_inode = au_h_iptr(inode, bindex);
13583 + f = h_inode->i_sb->s_export_op->commit_metadata;
13585 + err = f(h_inode);
13587 + err = sync_inode_metadata(h_inode, /*wait*/1);
13589 + au_cpup_attr_timesizes(inode);
13590 + ii_write_unlock(inode);
13591 + si_read_unlock(sb);
13595 +/* ---------------------------------------------------------------------- */
13597 +static struct export_operations aufs_export_op = {
13598 + .fh_to_dentry = aufs_fh_to_dentry,
13599 + /* .fh_to_parent = aufs_fh_to_parent, */
13600 + .encode_fh = aufs_encode_fh,
13601 + .commit_metadata = aufs_commit_metadata
13604 +void au_export_init(struct super_block *sb)
13606 + struct au_sbinfo *sbinfo;
13609 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13610 + && IS_MODULE(CONFIG_EXPORTFS),
13611 + AUFS_NAME ": unsupported configuration "
13612 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13614 + sb->s_export_op = &aufs_export_op;
13615 + sbinfo = au_sbi(sb);
13616 + sbinfo->si_xigen = NULL;
13617 + get_random_bytes(&u, sizeof(u));
13618 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13619 + atomic_set(&sbinfo->si_xigen_next, u);
13621 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13622 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13623 +++ linux/fs/aufs/fhsm.c 2022-11-05 23:02:18.962555950 +0100
13625 +// SPDX-License-Identifier: GPL-2.0
13627 + * Copyright (C) 2011-2022 Junjiro R. Okajima
13629 + * This program is free software; you can redistribute it and/or modify
13630 + * it under the terms of the GNU General Public License as published by
13631 + * the Free Software Foundation; either version 2 of the License, or
13632 + * (at your option) any later version.
13634 + * This program is distributed in the hope that it will be useful,
13635 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13636 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13637 + * GNU General Public License for more details.
13639 + * You should have received a copy of the GNU General Public License
13640 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13644 + * File-based Hierarchy Storage Management
13647 +#include <linux/anon_inodes.h>
13648 +#include <linux/poll.h>
13649 +#include <linux/seq_file.h>
13650 +#include <linux/statfs.h>
13653 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13655 + struct au_sbinfo *sbinfo;
13656 + struct au_fhsm *fhsm;
13658 + SiMustAnyLock(sb);
13660 + sbinfo = au_sbi(sb);
13661 + fhsm = &sbinfo->si_fhsm;
13662 + AuDebugOn(!fhsm);
13663 + return fhsm->fhsm_bottom;
13666 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13668 + struct au_sbinfo *sbinfo;
13669 + struct au_fhsm *fhsm;
13671 + SiMustWriteLock(sb);
13673 + sbinfo = au_sbi(sb);
13674 + fhsm = &sbinfo->si_fhsm;
13675 + AuDebugOn(!fhsm);
13676 + fhsm->fhsm_bottom = bindex;
13679 +/* ---------------------------------------------------------------------- */
13681 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13683 + struct au_br_fhsm *bf;
13685 + bf = br->br_fhsm;
13686 + MtxMustLock(&bf->bf_lock);
13688 + return !bf->bf_readable
13689 + || time_after(jiffies,
13690 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13693 +/* ---------------------------------------------------------------------- */
13695 +static void au_fhsm_notify(struct super_block *sb, int val)
13697 + struct au_sbinfo *sbinfo;
13698 + struct au_fhsm *fhsm;
13700 + SiMustAnyLock(sb);
13702 + sbinfo = au_sbi(sb);
13703 + fhsm = &sbinfo->si_fhsm;
13704 + if (au_fhsm_pid(fhsm)
13705 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13706 + atomic_set(&fhsm->fhsm_readable, val);
13708 + wake_up(&fhsm->fhsm_wqh);
13712 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13713 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13716 + struct au_branch *br;
13717 + struct au_br_fhsm *bf;
13719 + br = au_sbr(sb, bindex);
13720 + AuDebugOn(au_br_rdonly(br));
13721 + bf = br->br_fhsm;
13725 + mutex_lock(&bf->bf_lock);
13727 + MtxMustLock(&bf->bf_lock);
13729 + /* sb->s_root for NFS is unreliable */
13730 + err = au_br_stfs(br, &bf->bf_stfs);
13731 + if (unlikely(err)) {
13732 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13736 + bf->bf_jiffy = jiffies;
13737 + bf->bf_readable = 1;
13739 + au_fhsm_notify(sb, /*val*/1);
13741 + *rstfs = bf->bf_stfs;
13745 + mutex_unlock(&bf->bf_lock);
13746 + au_fhsm_notify(sb, /*val*/1);
13751 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13754 + struct au_sbinfo *sbinfo;
13755 + struct au_fhsm *fhsm;
13756 + struct au_branch *br;
13757 + struct au_br_fhsm *bf;
13759 + AuDbg("b%d, force %d\n", bindex, force);
13760 + SiMustAnyLock(sb);
13762 + sbinfo = au_sbi(sb);
13763 + fhsm = &sbinfo->si_fhsm;
13764 + if (!au_ftest_si(sbinfo, FHSM)
13765 + || fhsm->fhsm_bottom == bindex)
13768 + br = au_sbr(sb, bindex);
13769 + bf = br->br_fhsm;
13771 + mutex_lock(&bf->bf_lock);
13773 + || au_fhsm_pid(fhsm)
13774 + || au_fhsm_test_jiffy(sbinfo, br))
13775 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13777 + mutex_unlock(&bf->bf_lock);
13780 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13782 + aufs_bindex_t bindex, bbot;
13783 + struct au_branch *br;
13785 + /* exclude the bottom */
13786 + bbot = au_fhsm_bottom(sb);
13787 + for (bindex = 0; bindex < bbot; bindex++) {
13788 + br = au_sbr(sb, bindex);
13789 + if (au_br_fhsm(br->br_perm))
13790 + au_fhsm_wrote(sb, bindex, force);
13794 +/* ---------------------------------------------------------------------- */
13796 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13799 + struct au_sbinfo *sbinfo;
13800 + struct au_fhsm *fhsm;
13803 + sbinfo = file->private_data;
13804 + fhsm = &sbinfo->si_fhsm;
13805 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13806 + if (atomic_read(&fhsm->fhsm_readable))
13807 + mask = EPOLLIN /* | EPOLLRDNORM */;
13810 + AuDbg("mask 0x%x\n", mask);
13814 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13815 + struct aufs_stfs *stfs, __s16 brid)
13819 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13821 + err = __put_user(brid, &stbr->brid);
13822 + if (unlikely(err))
13828 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13829 + struct aufs_stbr __user *stbr, size_t count)
13833 + aufs_bindex_t bindex, bbot;
13834 + struct au_branch *br;
13835 + struct au_br_fhsm *bf;
13837 + /* except the bottom branch */
13840 + bbot = au_fhsm_bottom(sb);
13841 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13842 + br = au_sbr(sb, bindex);
13843 + if (!au_br_fhsm(br->br_perm))
13846 + bf = br->br_fhsm;
13847 + mutex_lock(&bf->bf_lock);
13848 + if (bf->bf_readable) {
13850 + if (count >= sizeof(*stbr))
13851 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13854 + bf->bf_readable = 0;
13855 + count -= sizeof(*stbr);
13859 + mutex_unlock(&bf->bf_lock);
13862 + err = sizeof(*stbr) * nstbr;
13867 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13872 + aufs_bindex_t nfhsm, bindex, bbot;
13873 + struct au_sbinfo *sbinfo;
13874 + struct au_fhsm *fhsm;
13875 + struct au_branch *br;
13876 + struct super_block *sb;
13879 + sbinfo = file->private_data;
13880 + fhsm = &sbinfo->si_fhsm;
13882 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13883 + if (!atomic_read(&fhsm->fhsm_readable)) {
13884 + if (vfsub_file_flags(file) & O_NONBLOCK)
13887 + err = wait_event_interruptible_locked_irq
13889 + atomic_read(&fhsm->fhsm_readable));
13891 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13892 + if (unlikely(err))
13895 + /* sb may already be dead */
13896 + au_rw_read_lock(&sbinfo->si_rwsem);
13897 + readable = atomic_read(&fhsm->fhsm_readable);
13898 + if (readable > 0) {
13899 + sb = sbinfo->si_sb;
13901 + /* exclude the bottom branch */
13903 + bbot = au_fhsm_bottom(sb);
13904 + for (bindex = 0; bindex < bbot; bindex++) {
13905 + br = au_sbr(sb, bindex);
13906 + if (au_br_fhsm(br->br_perm))
13910 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13911 + atomic_set(&fhsm->fhsm_readable, 0);
13912 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13916 + au_rw_read_unlock(&sbinfo->si_rwsem);
13924 +static int au_fhsm_release(struct inode *inode, struct file *file)
13926 + struct au_sbinfo *sbinfo;
13927 + struct au_fhsm *fhsm;
13929 + /* sb may already be dead */
13930 + sbinfo = file->private_data;
13931 + fhsm = &sbinfo->si_fhsm;
13932 + spin_lock(&fhsm->fhsm_spin);
13933 + fhsm->fhsm_pid = 0;
13934 + spin_unlock(&fhsm->fhsm_spin);
13935 + kobject_put(&sbinfo->si_kobj);
13940 +static const struct file_operations au_fhsm_fops = {
13941 + .owner = THIS_MODULE,
13942 + .llseek = noop_llseek,
13943 + .read = au_fhsm_read,
13944 + .poll = au_fhsm_poll,
13945 + .release = au_fhsm_release
13948 +int au_fhsm_fd(struct super_block *sb, int oflags)
13951 + struct au_sbinfo *sbinfo;
13952 + struct au_fhsm *fhsm;
13955 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13959 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13963 + sbinfo = au_sbi(sb);
13964 + fhsm = &sbinfo->si_fhsm;
13965 + spin_lock(&fhsm->fhsm_spin);
13966 + if (!fhsm->fhsm_pid)
13967 + fhsm->fhsm_pid = current->pid;
13970 + spin_unlock(&fhsm->fhsm_spin);
13971 + if (unlikely(err))
13974 + oflags |= O_RDONLY;
13975 + /* oflags |= FMODE_NONOTIFY; */
13976 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
13978 + if (unlikely(fd < 0))
13981 + /* succeed regardless 'fhsm' status */
13982 + kobject_get(&sbinfo->si_kobj);
13983 + si_noflush_read_lock(sb);
13984 + if (au_ftest_si(sbinfo, FHSM))
13985 + au_fhsm_wrote_all(sb, /*force*/0);
13986 + si_read_unlock(sb);
13987 + goto out; /* success */
13990 + spin_lock(&fhsm->fhsm_spin);
13991 + fhsm->fhsm_pid = 0;
13992 + spin_unlock(&fhsm->fhsm_spin);
13998 +/* ---------------------------------------------------------------------- */
14000 +int au_fhsm_br_alloc(struct au_branch *br)
14005 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14007 + au_br_fhsm_init(br->br_fhsm);
14014 +/* ---------------------------------------------------------------------- */
14016 +void au_fhsm_fin(struct super_block *sb)
14018 + au_fhsm_notify(sb, /*val*/-1);
14021 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14023 + struct au_fhsm *fhsm;
14025 + fhsm = &sbinfo->si_fhsm;
14026 + spin_lock_init(&fhsm->fhsm_spin);
14027 + init_waitqueue_head(&fhsm->fhsm_wqh);
14028 + atomic_set(&fhsm->fhsm_readable, 0);
14029 + fhsm->fhsm_expire
14030 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14031 + fhsm->fhsm_bottom = -1;
14034 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14036 + sbinfo->si_fhsm.fhsm_expire
14037 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14040 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14044 + if (!au_ftest_si(sbinfo, FHSM))
14047 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14048 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14049 + seq_printf(seq, ",fhsm_sec=%u", u);
14051 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14052 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14053 +++ linux/fs/aufs/file.c 2022-12-17 09:21:34.799855195 +0100
14055 +// SPDX-License-Identifier: GPL-2.0
14057 + * Copyright (C) 2005-2022 Junjiro R. Okajima
14059 + * This program is free software; you can redistribute it and/or modify
14060 + * it under the terms of the GNU General Public License as published by
14061 + * the Free Software Foundation; either version 2 of the License, or
14062 + * (at your option) any later version.
14064 + * This program is distributed in the hope that it will be useful,
14065 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14066 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14067 + * GNU General Public License for more details.
14069 + * You should have received a copy of the GNU General Public License
14070 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14074 + * handling file/dir, and address_space operation
14077 +#ifdef CONFIG_AUFS_DEBUG
14078 +#include <linux/migrate.h>
14080 +#include <linux/pagemap.h>
14083 +/* drop flags for writing */
14084 +unsigned int au_file_roflags(unsigned int flags)
14086 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14087 + flags |= O_RDONLY | O_NOATIME;
14091 +/* common functions to regular file and dir */
14092 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14093 + struct file *file, int force_wr)
14095 + struct file *h_file;
14096 + struct dentry *h_dentry;
14097 + struct inode *h_inode;
14098 + struct super_block *sb;
14099 + struct au_branch *br;
14100 + struct path h_path;
14103 + /* a race condition can happen between open and unlink/rmdir */
14104 + h_file = ERR_PTR(-ENOENT);
14105 + h_dentry = au_h_dptr(dentry, bindex);
14106 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14108 + h_inode = d_inode(h_dentry);
14109 + spin_lock(&h_dentry->d_lock);
14110 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14111 + /* || !d_inode(dentry)->i_nlink */
14113 + spin_unlock(&h_dentry->d_lock);
14114 + if (unlikely(err))
14117 + sb = dentry->d_sb;
14118 + br = au_sbr(sb, bindex);
14119 + err = au_br_test_oflag(flags, br);
14120 + h_file = ERR_PTR(err);
14121 + if (unlikely(err))
14124 + /* drop flags for writing */
14125 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14126 + if (force_wr && !(flags & O_WRONLY))
14128 + flags = au_file_roflags(flags);
14130 + h_file = ERR_PTR(-EROFS);
14131 + flags = au_file_roflags(flags);
14132 + if (unlikely(vfsub_native_ro(h_inode)
14133 + || IS_APPEND(h_inode)))
14135 + flags &= ~O_ACCMODE;
14136 + flags |= O_WRONLY;
14139 + flags &= ~O_CREAT;
14140 + au_lcnt_inc(&br->br_nfiles);
14141 + h_path.dentry = h_dentry;
14142 + h_path.mnt = au_br_mnt(br);
14143 + h_file = vfsub_dentry_open(&h_path, flags);
14144 + if (IS_ERR(h_file))
14147 + if (flags & __FMODE_EXEC) {
14148 + err = deny_write_access(h_file);
14149 + if (unlikely(err)) {
14151 + h_file = ERR_PTR(err);
14155 + fsnotify_open(h_file);
14156 + goto out; /* success */
14159 + au_lcnt_dec(&br->br_nfiles);
14164 +static int au_cmoo(struct dentry *dentry)
14166 + int err, cmoo, matched;
14167 + unsigned int udba;
14168 + struct path h_path;
14169 + struct au_pin pin;
14170 + struct au_cp_generic cpg = {
14171 + .dentry = dentry,
14176 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14178 + struct inode *delegated;
14179 + struct super_block *sb;
14180 + struct au_sbinfo *sbinfo;
14181 + struct au_fhsm *fhsm;
14183 + struct au_branch *br;
14184 + struct dentry *parent;
14185 + struct au_hinode *hdir;
14187 + DiMustWriteLock(dentry);
14188 + IiMustWriteLock(d_inode(dentry));
14191 + if (IS_ROOT(dentry))
14193 + cpg.bsrc = au_dbtop(dentry);
14197 + sb = dentry->d_sb;
14198 + sbinfo = au_sbi(sb);
14199 + fhsm = &sbinfo->si_fhsm;
14200 + pid = au_fhsm_pid(fhsm);
14203 + && (current->pid == pid
14204 + || rcu_dereference(current->real_parent)->pid == pid));
14205 + rcu_read_unlock();
14209 + br = au_sbr(sb, cpg.bsrc);
14210 + cmoo = au_br_cmoo(br->br_perm);
14213 + if (!d_is_reg(dentry))
14214 + cmoo &= AuBrAttr_COO_ALL;
14218 + parent = dget_parent(dentry);
14219 + di_write_lock_parent(parent);
14220 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14222 + if (unlikely(err < 0)) {
14223 + err = 0; /* there is no upper writable branch */
14226 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14228 + /* do not respect the coo attrib for the target branch */
14229 + err = au_cpup_dirs(dentry, cpg.bdst);
14230 + if (unlikely(err))
14233 + di_downgrade_lock(parent, AuLock_IR);
14234 + udba = au_opt_udba(sb);
14235 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14236 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14237 + if (unlikely(err))
14240 + err = au_sio_cpup_simple(&cpg);
14242 + if (unlikely(err))
14244 + if (!(cmoo & AuBrWAttr_MOO))
14245 + goto out_parent; /* success */
14247 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14248 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14249 + if (unlikely(err))
14252 + h_path.mnt = au_br_mnt(br);
14253 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14254 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14255 + delegated = NULL;
14256 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14258 + /* todo: keep h_dentry or not? */
14259 + if (unlikely(err == -EWOULDBLOCK)) {
14260 + pr_warn("cannot retry for NFSv4 delegation"
14261 + " for an internal unlink\n");
14264 + if (unlikely(err)) {
14265 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14269 + goto out_parent; /* success */
14272 + di_downgrade_lock(parent, AuLock_IR);
14274 + di_read_unlock(parent, AuLock_IR);
14281 +int au_do_open(struct file *file, struct au_do_open_args *args)
14283 + int err, aopen = args->aopen;
14284 + struct dentry *dentry;
14285 + struct au_finfo *finfo;
14288 + err = au_finfo_init(file, args->fidir);
14291 + err = au_finfo_init(file, args->fidir);
14294 + if (unlikely(err))
14297 + dentry = file->f_path.dentry;
14298 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14299 + di_write_lock_child(dentry);
14300 + err = au_cmoo(dentry);
14303 + err = args->open(file, vfsub_file_flags(file),
14304 + au_di(dentry)->di_htmpfile);
14305 + di_write_unlock(dentry);
14307 + di_downgrade_lock(dentry, AuLock_IR);
14309 + err = args->open(file, vfsub_file_flags(file),
14312 + di_read_unlock(dentry, AuLock_IR);
14316 + finfo = au_fi(file);
14318 + finfo->fi_file = file;
14319 + au_hbl_add(&finfo->fi_hlist,
14320 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14323 + fi_write_unlock(file);
14326 + fi_write_unlock(file);
14329 + if (unlikely(err)) {
14330 + finfo->fi_hdir = NULL;
14331 + au_finfo_fin(file);
14339 +int au_reopen_nondir(struct file *file)
14342 + aufs_bindex_t btop;
14343 + struct dentry *dentry;
14344 + struct au_branch *br;
14345 + struct file *h_file, *h_file_tmp;
14347 + dentry = file->f_path.dentry;
14348 + btop = au_dbtop(dentry);
14349 + br = au_sbr(dentry->d_sb, btop);
14350 + h_file_tmp = NULL;
14351 + if (au_fbtop(file) == btop) {
14352 + h_file = au_hf_top(file);
14353 + if (file->f_mode == h_file->f_mode)
14354 + return 0; /* success */
14355 + h_file_tmp = h_file;
14356 + get_file(h_file_tmp);
14357 + au_lcnt_inc(&br->br_nfiles);
14358 + au_set_h_fptr(file, btop, NULL);
14360 + AuDebugOn(au_fi(file)->fi_hdir);
14363 + * file exists on both of rw and ro
14364 + * open --> dbtop and fbtop are both 0
14365 + * prepend a branch as rw, "rw" become ro
14367 + * delete the top branch, "rw" becomes rw again
14368 + * --> dbtop is 1, fbtop is still 0
14369 + * write --> fbtop is 0 but dbtop is 1
14371 + /* AuDebugOn(au_fbtop(file) < btop); */
14373 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14374 + file, /*force_wr*/0);
14375 + err = PTR_ERR(h_file);
14376 + if (IS_ERR(h_file)) {
14377 + if (h_file_tmp) {
14379 + au_set_h_fptr(file, btop, h_file_tmp);
14380 + h_file_tmp = NULL;
14382 + goto out; /* todo: close all? */
14386 + au_set_fbtop(file, btop);
14387 + au_set_h_fptr(file, btop, h_file);
14388 + au_update_figen(file);
14389 + /* todo: necessary? */
14390 + /* file->f_ra = h_file->f_ra; */
14393 + if (h_file_tmp) {
14394 + fput(h_file_tmp);
14395 + au_lcnt_dec(&br->br_nfiles);
14400 +/* ---------------------------------------------------------------------- */
14402 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14403 + struct dentry *hi_wh)
14406 + aufs_bindex_t btop;
14407 + struct au_dinfo *dinfo;
14408 + struct dentry *h_dentry;
14409 + struct au_hdentry *hdp;
14411 + dinfo = au_di(file->f_path.dentry);
14412 + AuRwMustWriteLock(&dinfo->di_rwsem);
14414 + btop = dinfo->di_btop;
14415 + dinfo->di_btop = btgt;
14416 + hdp = au_hdentry(dinfo, btgt);
14417 + h_dentry = hdp->hd_dentry;
14418 + hdp->hd_dentry = hi_wh;
14419 + err = au_reopen_nondir(file);
14420 + hdp->hd_dentry = h_dentry;
14421 + dinfo->di_btop = btop;
14426 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14427 + aufs_bindex_t bcpup, struct au_pin *pin)
14430 + struct inode *inode, *h_inode;
14431 + struct dentry *h_dentry, *hi_wh;
14432 + struct au_cp_generic cpg = {
14433 + .dentry = file->f_path.dentry,
14440 + au_update_dbtop(cpg.dentry);
14441 + inode = d_inode(cpg.dentry);
14443 + if (au_dbtop(cpg.dentry) <= bcpup
14444 + && au_dbbot(cpg.dentry) >= bcpup) {
14445 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14446 + if (h_dentry && d_is_positive(h_dentry))
14447 + h_inode = d_inode(h_dentry);
14449 + hi_wh = au_hi_wh(inode, bcpup);
14450 + if (!hi_wh && !h_inode)
14451 + err = au_sio_cpup_wh(&cpg, file);
14453 + /* already copied-up after unlink */
14454 + err = au_reopen_wh(file, bcpup, hi_wh);
14457 + && (inode->i_nlink > 1
14458 + || (inode->i_state & I_LINKABLE))
14459 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14460 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14466 + * prepare the @file for writing.
14468 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14471 + aufs_bindex_t dbtop;
14472 + struct dentry *parent;
14473 + struct inode *inode;
14474 + struct super_block *sb;
14475 + struct file *h_file;
14476 + struct au_cp_generic cpg = {
14477 + .dentry = file->f_path.dentry,
14482 + .flags = AuCpup_DTIME
14485 + sb = cpg.dentry->d_sb;
14486 + inode = d_inode(cpg.dentry);
14487 + cpg.bsrc = au_fbtop(file);
14488 + err = au_test_ro(sb, cpg.bsrc, inode);
14489 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14490 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14495 + /* need to cpup or reopen */
14496 + parent = dget_parent(cpg.dentry);
14497 + di_write_lock_parent(parent);
14498 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14500 + if (unlikely(err < 0))
14504 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14505 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14506 + if (unlikely(err))
14510 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14511 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14512 + if (unlikely(err))
14515 + dbtop = au_dbtop(cpg.dentry);
14516 + if (dbtop <= cpg.bdst)
14517 + cpg.bsrc = cpg.bdst;
14519 + if (dbtop <= cpg.bdst /* just reopen */
14520 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14522 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14523 + if (IS_ERR(h_file))
14524 + err = PTR_ERR(h_file);
14526 + di_downgrade_lock(parent, AuLock_IR);
14527 + if (dbtop > cpg.bdst)
14528 + err = au_sio_cpup_simple(&cpg);
14530 + err = au_reopen_nondir(file);
14531 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14533 + } else { /* copyup as wh and reopen */
14535 + * since writable hfsplus branch is not supported,
14536 + * h_open_pre/post() are unnecessary.
14538 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14539 + di_downgrade_lock(parent, AuLock_IR);
14543 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14544 + goto out_dput; /* success */
14550 + di_downgrade_lock(parent, AuLock_IR);
14552 + di_read_unlock(parent, AuLock_IR);
14559 +/* ---------------------------------------------------------------------- */
14561 +int au_do_flush(struct file *file, fl_owner_t id,
14562 + int (*flush)(struct file *file, fl_owner_t id))
14565 + struct super_block *sb;
14566 + struct inode *inode;
14568 + inode = file_inode(file);
14569 + sb = inode->i_sb;
14570 + si_noflush_read_lock(sb);
14571 + fi_read_lock(file);
14572 + ii_read_lock_child(inode);
14574 + err = flush(file, id);
14575 + au_cpup_attr_timesizes(inode);
14577 + ii_read_unlock(inode);
14578 + fi_read_unlock(file);
14579 + si_read_unlock(sb);
14583 +/* ---------------------------------------------------------------------- */
14585 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14588 + struct au_pin pin;
14589 + struct au_finfo *finfo;
14590 + struct dentry *parent, *hi_wh;
14591 + struct inode *inode;
14592 + struct super_block *sb;
14593 + struct au_cp_generic cpg = {
14594 + .dentry = file->f_path.dentry,
14599 + .flags = AuCpup_DTIME
14602 + FiMustWriteLock(file);
14605 + finfo = au_fi(file);
14606 + sb = cpg.dentry->d_sb;
14607 + inode = d_inode(cpg.dentry);
14608 + cpg.bdst = au_ibtop(inode);
14609 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14612 + parent = dget_parent(cpg.dentry);
14613 + if (au_test_ro(sb, cpg.bdst, inode)) {
14614 + di_read_lock_parent(parent, !AuLock_IR);
14615 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14617 + di_read_unlock(parent, !AuLock_IR);
14618 + if (unlikely(err < 0))
14623 + di_read_lock_parent(parent, AuLock_IR);
14624 + hi_wh = au_hi_wh(inode, cpg.bdst);
14625 + if (!S_ISDIR(inode->i_mode)
14626 + && au_opt_test(au_mntflags(sb), PLINK)
14627 + && au_plink_test(inode)
14628 + && !d_unhashed(cpg.dentry)
14629 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14630 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14631 + if (unlikely(err))
14634 + /* always superio. */
14635 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14636 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14638 + err = au_sio_cpup_simple(&cpg);
14641 + } else if (hi_wh) {
14642 + /* already copied-up after unlink */
14643 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14644 + *need_reopen = 0;
14648 + di_read_unlock(parent, AuLock_IR);
14655 +static void au_do_refresh_dir(struct file *file)
14657 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14658 + struct au_hfile *p, tmp, *q;
14659 + struct au_finfo *finfo;
14660 + struct super_block *sb;
14661 + struct au_fidir *fidir;
14663 + FiMustWriteLock(file);
14665 + sb = file->f_path.dentry->d_sb;
14666 + finfo = au_fi(file);
14667 + fidir = finfo->fi_hdir;
14668 + AuDebugOn(!fidir);
14669 + p = fidir->fd_hfile + finfo->fi_btop;
14670 + brid = p->hf_br->br_id;
14671 + bbot = fidir->fd_bbot;
14672 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14676 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14677 + if (new_bindex == bindex)
14679 + if (new_bindex < 0) {
14680 + au_set_h_fptr(file, bindex, NULL);
14684 + /* swap two lower inode, and loop again */
14685 + q = fidir->fd_hfile + new_bindex;
14689 + if (tmp.hf_file) {
14695 + p = fidir->fd_hfile;
14696 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14697 + bbot = au_sbbot(sb);
14698 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14699 + finfo->fi_btop++, p++)
14700 + if (p->hf_file) {
14701 + if (file_inode(p->hf_file))
14703 + au_hfput(p, /*execed*/0);
14706 + bbot = au_br_index(sb, brid);
14707 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14708 + finfo->fi_btop++, p++)
14710 + au_hfput(p, /*execed*/0);
14711 + bbot = au_sbbot(sb);
14714 + p = fidir->fd_hfile + bbot;
14715 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14716 + fidir->fd_bbot--, p--)
14717 + if (p->hf_file) {
14718 + if (file_inode(p->hf_file))
14720 + au_hfput(p, /*execed*/0);
14722 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14726 + * after branch manipulating, refresh the file.
14728 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14730 + int err, need_reopen, nbr;
14731 + aufs_bindex_t bbot, bindex;
14732 + struct dentry *dentry;
14733 + struct super_block *sb;
14734 + struct au_finfo *finfo;
14735 + struct au_hfile *hfile;
14737 + dentry = file->f_path.dentry;
14738 + sb = dentry->d_sb;
14739 + nbr = au_sbbot(sb) + 1;
14740 + finfo = au_fi(file);
14741 + if (!finfo->fi_hdir) {
14742 + hfile = &finfo->fi_htop;
14743 + AuDebugOn(!hfile->hf_file);
14744 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14745 + AuDebugOn(bindex < 0);
14746 + if (bindex != finfo->fi_btop)
14747 + au_set_fbtop(file, bindex);
14749 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14750 + if (unlikely(err))
14752 + au_do_refresh_dir(file);
14757 + if (!au_test_mmapped(file))
14758 + err = au_file_refresh_by_inode(file, &need_reopen);
14759 + if (finfo->fi_hdir)
14760 + /* harmless if err */
14761 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14762 + if (!err && need_reopen && !d_unlinked(dentry))
14763 + err = reopen(file);
14765 + au_update_figen(file);
14766 + goto out; /* success */
14769 + /* error, close all lower files */
14770 + if (finfo->fi_hdir) {
14771 + bbot = au_fbbot_dir(file);
14772 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14773 + au_set_h_fptr(file, bindex, NULL);
14780 +/* common function to regular file and dir */
14781 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14782 + int wlock, unsigned int fi_lsc)
14785 + unsigned int sigen, figen;
14786 + aufs_bindex_t btop;
14787 + unsigned char pseudo_link;
14788 + struct dentry *dentry;
14789 + struct inode *inode;
14792 + dentry = file->f_path.dentry;
14793 + inode = d_inode(dentry);
14794 + sigen = au_sigen(dentry->d_sb);
14795 + fi_write_lock_nested(file, fi_lsc);
14796 + figen = au_figen(file);
14798 + di_write_lock_child(dentry);
14800 + di_write_lock_child2(dentry);
14801 + btop = au_dbtop(dentry);
14802 + pseudo_link = (btop != au_ibtop(inode));
14803 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14805 + di_downgrade_lock(dentry, AuLock_IR);
14806 + fi_downgrade_lock(file);
14808 + goto out; /* success */
14811 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14812 + if (au_digen_test(dentry, sigen)) {
14813 + err = au_reval_dpath(dentry, sigen);
14814 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14818 + err = refresh_file(file, reopen);
14821 + di_downgrade_lock(dentry, AuLock_IR);
14822 + fi_downgrade_lock(file);
14825 + di_write_unlock(dentry);
14826 + fi_write_unlock(file);
14833 +/* ---------------------------------------------------------------------- */
14835 +/* cf. aufs_nopage() */
14836 +/* for madvise(2) */
14837 +static int aufs_read_folio(struct file *file __maybe_unused, struct folio *folio)
14839 + folio_unlock(folio);
14843 +/* it will never be called, but necessary to support O_DIRECT */
14844 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14845 +{ BUG(); return 0; }
14847 +/* they will never be called. */
14848 +#ifdef CONFIG_AUFS_DEBUG
14849 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14850 + loff_t pos, unsigned len,
14851 + struct page **pagep, void **fsdata)
14852 +{ AuUnsupport(); return 0; }
14853 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14854 + loff_t pos, unsigned len, unsigned copied,
14855 + struct page *page, void *fsdata)
14856 +{ AuUnsupport(); return 0; }
14857 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14858 +{ AuUnsupport(); return 0; }
14860 +static bool aufs_dirty_folio(struct address_space *mapping, struct folio *folio)
14861 +{ AuUnsupport(); return true; }
14862 +static void aufs_invalidate_folio(struct folio *folio, size_t offset, size_t len)
14863 +{ AuUnsupport(); }
14864 +static bool aufs_release_folio(struct folio *folio, gfp_t gfp)
14865 +{ AuUnsupport(); return true; }
14866 +#if 0 /* called by memory compaction regardless file */
14867 +static int aufs_migrate_folio(struct address_space *mapping, struct folio *dst,
14868 + struct folio *src, enum migrate_mode mode)
14869 +{ AuUnsupport(); return 0; }
14871 +static int aufs_launder_folio(struct folio *folio)
14872 +{ AuUnsupport(); return 0; }
14873 +static bool aufs_is_partially_uptodate(struct folio *folio, size_t from,
14875 +{ AuUnsupport(); return true; }
14876 +static void aufs_is_dirty_writeback(struct folio *folio, bool *dirty,
14878 +{ AuUnsupport(); }
14879 +static int aufs_error_remove_page(struct address_space *mapping,
14880 + struct page *page)
14881 +{ AuUnsupport(); return 0; }
14882 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14884 +{ AuUnsupport(); return 0; }
14885 +static void aufs_swap_deactivate(struct file *file)
14886 +{ AuUnsupport(); }
14887 +static int aufs_swap_rw(struct kiocb *iocb, struct iov_iter *iter)
14888 +{ AuUnsupport(); return 0; }
14889 +#endif /* CONFIG_AUFS_DEBUG */
14891 +const struct address_space_operations aufs_aop = {
14892 + .read_folio = aufs_read_folio,
14893 + .direct_IO = aufs_direct_IO,
14894 +#ifdef CONFIG_AUFS_DEBUG
14895 + .writepage = aufs_writepage,
14896 + /* no writepages, because of writepage */
14897 + .dirty_folio = aufs_dirty_folio,
14898 + /* no readpages, because of readpage */
14899 + .write_begin = aufs_write_begin,
14900 + .write_end = aufs_write_end,
14901 + /* no bmap, no block device */
14902 + .invalidate_folio = aufs_invalidate_folio,
14903 + .release_folio = aufs_release_folio,
14904 + /* is fallback_migrate_page ok? */
14905 + /* .migrate_folio = aufs_migrate_folio, */
14906 + .launder_folio = aufs_launder_folio,
14907 + .is_partially_uptodate = aufs_is_partially_uptodate,
14908 + .is_dirty_writeback = aufs_is_dirty_writeback,
14909 + .error_remove_page = aufs_error_remove_page,
14910 + .swap_activate = aufs_swap_activate,
14911 + .swap_deactivate = aufs_swap_deactivate,
14912 + .swap_rw = aufs_swap_rw
14913 +#endif /* CONFIG_AUFS_DEBUG */
14915 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14916 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14917 +++ linux/fs/aufs/file.h 2022-11-05 23:02:18.965889284 +0100
14919 +/* SPDX-License-Identifier: GPL-2.0 */
14921 + * Copyright (C) 2005-2022 Junjiro R. Okajima
14923 + * This program is free software; you can redistribute it and/or modify
14924 + * it under the terms of the GNU General Public License as published by
14925 + * the Free Software Foundation; either version 2 of the License, or
14926 + * (at your option) any later version.
14928 + * This program is distributed in the hope that it will be useful,
14929 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14930 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14931 + * GNU General Public License for more details.
14933 + * You should have received a copy of the GNU General Public License
14934 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14938 + * file operations
14941 +#ifndef __AUFS_FILE_H__
14942 +#define __AUFS_FILE_H__
14946 +#include <linux/file.h>
14947 +#include <linux/fs.h>
14948 +#include <linux/mm_types.h>
14949 +#include <linux/poll.h>
14950 +#include "rwsem.h"
14954 + struct file *hf_file;
14955 + struct au_branch *hf_br;
14960 + aufs_bindex_t fd_bbot;
14961 + aufs_bindex_t fd_nent;
14962 + struct au_vdir *fd_vdir_cache;
14963 + struct au_hfile fd_hfile[];
14966 +static inline int au_fidir_sz(int nent)
14968 + AuDebugOn(nent < 0);
14969 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
14973 + atomic_t fi_generation;
14975 + struct au_rwsem fi_rwsem;
14976 + aufs_bindex_t fi_btop;
14978 + /* do not union them */
14979 + struct { /* for non-dir */
14980 + struct au_hfile fi_htop;
14981 + atomic_t fi_mmapped;
14983 + struct au_fidir *fi_hdir; /* for dir only */
14985 + struct hlist_bl_node fi_hlist;
14986 + struct file *fi_file; /* very ugly */
14987 + struct rcu_head rcu;
14988 +} ____cacheline_aligned_in_smp;
14990 +/* ---------------------------------------------------------------------- */
14993 +extern const struct address_space_operations aufs_aop;
14994 +unsigned int au_file_roflags(unsigned int flags);
14995 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14996 + struct file *file, int force_wr);
14997 +struct au_do_open_args {
14999 + int (*open)(struct file *file, int flags,
15000 + struct file *h_file);
15001 + struct au_fidir *fidir;
15002 + struct file *h_file;
15004 +int au_do_open(struct file *file, struct au_do_open_args *args);
15005 +int au_reopen_nondir(struct file *file);
15007 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15008 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15009 + int wlock, unsigned int fi_lsc);
15010 +int au_do_flush(struct file *file, fl_owner_t id,
15011 + int (*flush)(struct file *file, fl_owner_t id));
15014 +#ifdef CONFIG_AUFS_POLL
15015 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15018 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15020 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15022 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15023 + struct file *h_file);
15025 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15026 + aufs_bindex_t bindex, int force_wr)
15027 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15028 + struct file *h_file);
15032 +extern const struct file_operations aufs_file_fop;
15033 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15034 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15035 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15038 +void au_hfput(struct au_hfile *hf, int execed);
15039 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15040 + struct file *h_file);
15042 +void au_update_figen(struct file *file);
15043 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15044 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15046 +void au_fi_init_once(void *_fi);
15047 +void au_finfo_fin(struct file *file);
15048 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15051 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15052 +#ifdef CONFIG_COMPAT
15053 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15054 + unsigned long arg);
15055 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15056 + unsigned long arg);
15059 +/* ---------------------------------------------------------------------- */
15061 +static inline struct au_finfo *au_fi(struct file *file)
15063 + return file->private_data;
15066 +/* ---------------------------------------------------------------------- */
15068 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15069 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15070 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15071 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15073 +#define fi_read_trylock_nested(f) \
15074 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15075 +#define fi_write_trylock_nested(f) \
15076 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15079 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15080 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15081 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15083 +/* lock subclass for finfo */
15089 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15091 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15094 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15096 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15100 + * fi_read_lock_1, fi_write_lock_1,
15101 + * fi_read_lock_2, fi_write_lock_2
15103 +#define AuReadLockFunc(name) \
15104 +static inline void fi_read_lock_##name(struct file *f) \
15105 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15107 +#define AuWriteLockFunc(name) \
15108 +static inline void fi_write_lock_##name(struct file *f) \
15109 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15111 +#define AuRWLockFuncs(name) \
15112 + AuReadLockFunc(name) \
15113 + AuWriteLockFunc(name)
15118 +#undef AuReadLockFunc
15119 +#undef AuWriteLockFunc
15120 +#undef AuRWLockFuncs
15122 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15123 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15124 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15126 +/* ---------------------------------------------------------------------- */
15128 +/* todo: hard/soft set? */
15129 +static inline aufs_bindex_t au_fbtop(struct file *file)
15131 + FiMustAnyLock(file);
15132 + return au_fi(file)->fi_btop;
15135 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15137 + FiMustAnyLock(file);
15138 + AuDebugOn(!au_fi(file)->fi_hdir);
15139 + return au_fi(file)->fi_hdir->fd_bbot;
15142 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15144 + FiMustAnyLock(file);
15145 + AuDebugOn(!au_fi(file)->fi_hdir);
15146 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15149 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15151 + FiMustWriteLock(file);
15152 + au_fi(file)->fi_btop = bindex;
15155 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15157 + FiMustWriteLock(file);
15158 + AuDebugOn(!au_fi(file)->fi_hdir);
15159 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15162 +static inline void au_set_fvdir_cache(struct file *file,
15163 + struct au_vdir *vdir_cache)
15165 + FiMustWriteLock(file);
15166 + AuDebugOn(!au_fi(file)->fi_hdir);
15167 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15170 +static inline struct file *au_hf_top(struct file *file)
15172 + FiMustAnyLock(file);
15173 + AuDebugOn(au_fi(file)->fi_hdir);
15174 + return au_fi(file)->fi_htop.hf_file;
15177 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15179 + FiMustAnyLock(file);
15180 + AuDebugOn(!au_fi(file)->fi_hdir);
15181 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15184 +/* todo: memory barrier? */
15185 +static inline unsigned int au_figen(struct file *f)
15187 + return atomic_read(&au_fi(f)->fi_generation);
15190 +static inline void au_set_mmapped(struct file *f)
15192 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15194 + pr_warn("fi_mmapped wrapped around\n");
15195 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15199 +static inline void au_unset_mmapped(struct file *f)
15201 + atomic_dec(&au_fi(f)->fi_mmapped);
15204 +static inline int au_test_mmapped(struct file *f)
15206 + return atomic_read(&au_fi(f)->fi_mmapped);
15209 +/* customize vma->vm_file */
15211 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15212 + struct file *file)
15216 + f = vma->vm_file;
15218 + vma->vm_file = file;
15223 +#define AuDbgVmRegion(file, vma) do {} while (0)
15225 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15226 + struct file *file)
15228 + au_do_vm_file_reset(vma, file);
15231 +#define AuDbgVmRegion(file, vma) \
15232 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15234 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15235 + struct file *file)
15239 + au_do_vm_file_reset(vma, file);
15240 + f = vma->vm_region->vm_file;
15242 + vma->vm_region->vm_file = file;
15245 +#endif /* CONFIG_MMU */
15247 +/* handle vma->vm_prfile */
15248 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15249 + struct file *file)
15252 + vma->vm_prfile = file;
15253 +#ifndef CONFIG_MMU
15255 + vma->vm_region->vm_prfile = file;
15259 +#endif /* __KERNEL__ */
15260 +#endif /* __AUFS_FILE_H__ */
15261 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15262 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15263 +++ linux/fs/aufs/finfo.c 2022-11-05 23:02:18.965889284 +0100
15265 +// SPDX-License-Identifier: GPL-2.0
15267 + * Copyright (C) 2005-2022 Junjiro R. Okajima
15269 + * This program is free software; you can redistribute it and/or modify
15270 + * it under the terms of the GNU General Public License as published by
15271 + * the Free Software Foundation; either version 2 of the License, or
15272 + * (at your option) any later version.
15274 + * This program is distributed in the hope that it will be useful,
15275 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15276 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15277 + * GNU General Public License for more details.
15279 + * You should have received a copy of the GNU General Public License
15280 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15284 + * file private data
15289 +void au_hfput(struct au_hfile *hf, int execed)
15292 + allow_write_access(hf->hf_file);
15293 + fput(hf->hf_file);
15294 + hf->hf_file = NULL;
15295 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15296 + hf->hf_br = NULL;
15299 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15301 + struct au_finfo *finfo = au_fi(file);
15302 + struct au_hfile *hf;
15303 + struct au_fidir *fidir;
15305 + fidir = finfo->fi_hdir;
15307 + AuDebugOn(finfo->fi_btop != bindex);
15308 + hf = &finfo->fi_htop;
15310 + hf = fidir->fd_hfile + bindex;
15312 + if (hf && hf->hf_file)
15313 + au_hfput(hf, vfsub_file_execed(file));
15315 + FiMustWriteLock(file);
15316 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15317 + hf->hf_file = val;
15318 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15322 +void au_update_figen(struct file *file)
15324 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15325 + /* smp_mb(); */ /* atomic_set */
15328 +/* ---------------------------------------------------------------------- */
15330 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15332 + struct au_fidir *fidir;
15335 + nbr = au_sbbot(sb) + 1;
15337 + nbr = 2; /* initial allocate for 2 branches */
15338 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15340 + fidir->fd_bbot = -1;
15341 + fidir->fd_nent = nbr;
15347 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15350 + struct au_fidir *fidir, *p;
15352 + AuRwMustWriteLock(&finfo->fi_rwsem);
15353 + fidir = finfo->fi_hdir;
15354 + AuDebugOn(!fidir);
15357 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15358 + GFP_NOFS, may_shrink);
15360 + p->fd_nent = nbr;
15361 + finfo->fi_hdir = p;
15368 +/* ---------------------------------------------------------------------- */
15370 +void au_finfo_fin(struct file *file)
15372 + struct au_finfo *finfo;
15374 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15376 + finfo = au_fi(file);
15377 + AuDebugOn(finfo->fi_hdir);
15378 + AuRwDestroy(&finfo->fi_rwsem);
15379 + au_cache_free_finfo(finfo);
15382 +void au_fi_init_once(void *_finfo)
15384 + struct au_finfo *finfo = _finfo;
15386 + au_rw_init(&finfo->fi_rwsem);
15389 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15392 + struct au_finfo *finfo;
15393 + struct dentry *dentry;
15396 + dentry = file->f_path.dentry;
15397 + finfo = au_cache_alloc_finfo();
15398 + if (unlikely(!finfo))
15402 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15403 + au_rw_write_lock(&finfo->fi_rwsem);
15404 + finfo->fi_btop = -1;
15405 + finfo->fi_hdir = fidir;
15406 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15407 + /* smp_mb(); */ /* atomic_set */
15409 + file->private_data = finfo;
15414 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15415 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15416 +++ linux/fs/aufs/f_op.c 2022-12-17 09:21:34.799855195 +0100
15418 +// SPDX-License-Identifier: GPL-2.0
15420 + * Copyright (C) 2005-2022 Junjiro R. Okajima
15422 + * This program is free software; you can redistribute it and/or modify
15423 + * it under the terms of the GNU General Public License as published by
15424 + * the Free Software Foundation; either version 2 of the License, or
15425 + * (at your option) any later version.
15427 + * This program is distributed in the hope that it will be useful,
15428 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15429 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15430 + * GNU General Public License for more details.
15432 + * You should have received a copy of the GNU General Public License
15433 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15437 + * file and vm operations
15440 +#include <linux/aio.h>
15441 +#include <linux/fs_stack.h>
15442 +#include <linux/mman.h>
15443 +#include <linux/security.h>
15446 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15449 + aufs_bindex_t bindex;
15450 + struct dentry *dentry, *h_dentry;
15451 + struct au_finfo *finfo;
15452 + struct inode *h_inode;
15454 + FiMustWriteLock(file);
15457 + dentry = file->f_path.dentry;
15458 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15459 + finfo = au_fi(file);
15460 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15461 + atomic_set(&finfo->fi_mmapped, 0);
15462 + bindex = au_dbtop(dentry);
15464 + h_dentry = au_h_dptr(dentry, bindex);
15465 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15466 + if (unlikely(err))
15468 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15469 + if (IS_ERR(h_file)) {
15470 + err = PTR_ERR(h_file);
15474 + h_dentry = h_file->f_path.dentry;
15475 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15476 + if (unlikely(err))
15478 + /* br ref is already inc-ed */
15481 + if (flags & __O_TMPFILE) {
15482 + AuDebugOn(!h_file);
15483 + AuDebugOn(h_file != au_di(dentry)->di_htmpfile);
15484 + au_di(dentry)->di_htmpfile = NULL;
15486 + if (!(flags & O_EXCL)) {
15487 + h_inode = file_inode(h_file);
15488 + spin_lock(&h_inode->i_lock);
15489 + h_inode->i_state |= I_LINKABLE;
15490 + spin_unlock(&h_inode->i_lock);
15493 + au_set_fbtop(file, bindex);
15494 + au_set_h_fptr(file, bindex, h_file);
15495 + au_update_figen(file);
15496 + /* todo: necessary? */
15497 + /* file->f_ra = h_file->f_ra; */
15503 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15504 + struct file *file)
15507 + struct super_block *sb;
15508 + struct au_do_open_args args = {
15509 + .open = au_do_open_nondir
15512 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15513 + file, vfsub_file_flags(file), file->f_mode);
15515 + sb = file->f_path.dentry->d_sb;
15516 + si_read_lock(sb, AuLock_FLUSH);
15517 + err = au_do_open(file, &args);
15518 + si_read_unlock(sb);
15522 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15524 + struct au_finfo *finfo;
15525 + aufs_bindex_t bindex;
15527 + finfo = au_fi(file);
15528 + au_hbl_del(&finfo->fi_hlist,
15529 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15530 + bindex = finfo->fi_btop;
15532 + au_set_h_fptr(file, bindex, NULL);
15534 + au_finfo_fin(file);
15538 +/* ---------------------------------------------------------------------- */
15540 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15543 + struct file *h_file;
15546 + h_file = au_hf_top(file);
15548 + err = vfsub_flush(h_file, id);
15552 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15554 + return au_do_flush(file, id, au_do_flush_nondir);
15557 +/* ---------------------------------------------------------------------- */
15559 + * read and write functions acquire [fdi]_rwsem once, but release before
15560 + * mmap_sem. This is because to stop a race condition between mmap(2).
15561 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15562 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15563 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15566 +/* Callers should call au_read_post() or fput() in the end */
15567 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15569 + struct file *h_file;
15572 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15574 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15575 + h_file = au_hf_top(file);
15576 + get_file(h_file);
15578 + fi_read_unlock(file);
15580 + h_file = ERR_PTR(err);
15585 +static void au_read_post(struct inode *inode, struct file *h_file)
15587 + /* update without lock, I don't think it a problem */
15588 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15592 +struct au_write_pre {
15594 + unsigned int lsc;
15598 + aufs_bindex_t btop;
15602 + * return with iinfo is write-locked
15603 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15606 +static struct file *au_write_pre(struct file *file, int do_ready,
15607 + struct au_write_pre *wpre)
15609 + struct file *h_file;
15610 + struct dentry *dentry;
15612 + unsigned int lsc;
15613 + struct au_pin pin;
15618 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15619 + h_file = ERR_PTR(err);
15620 + if (unlikely(err))
15623 + dentry = file->f_path.dentry;
15625 + err = au_ready_to_write(file, -1, &pin);
15626 + if (unlikely(err)) {
15627 + h_file = ERR_PTR(err);
15628 + di_write_unlock(dentry);
15633 + di_downgrade_lock(dentry, /*flags*/0);
15635 + wpre->btop = au_fbtop(file);
15636 + h_file = au_hf_top(file);
15637 + get_file(h_file);
15639 + wpre->blks = file_inode(h_file)->i_blocks;
15642 + di_read_unlock(dentry, /*flags*/0);
15645 + fi_write_unlock(file);
15650 +static void au_write_post(struct inode *inode, struct file *h_file,
15651 + struct au_write_pre *wpre, ssize_t written)
15653 + struct inode *h_inode;
15655 + au_cpup_attr_timesizes(inode);
15656 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15657 + h_inode = file_inode(h_file);
15658 + inode->i_mode = h_inode->i_mode;
15659 + ii_write_unlock(inode);
15660 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15662 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15663 + /*force*/h_inode->i_blocks > wpre->blks);
15668 + * todo: very ugly
15669 + * it locks both of i_mutex and si_rwsem for read in safe.
15670 + * if the plink maintenance mode continues forever (that is the problem),
15671 + * may loop forever.
15673 +static void au_mtx_and_read_lock(struct inode *inode)
15676 + struct super_block *sb = inode->i_sb;
15679 + inode_lock(inode);
15680 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15683 + inode_unlock(inode);
15684 + si_read_lock(sb, AuLock_NOPLMW);
15685 + si_read_unlock(sb);
15689 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15690 + struct iov_iter *iov_iter)
15693 + struct file *file;
15694 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15696 + err = security_file_permission(h_file, rw);
15697 + if (unlikely(err))
15700 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15702 + if (rw == MAY_READ)
15703 + iter = h_file->f_op->read_iter;
15704 + else if (rw == MAY_WRITE)
15705 + iter = h_file->f_op->write_iter;
15707 + file = kio->ki_filp;
15708 + kio->ki_filp = h_file;
15711 + err = iter(kio, iov_iter);
15714 + /* currently there is no such fs */
15716 + kio->ki_filp = file;
15722 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15725 + struct file *file, *h_file;
15726 + struct inode *inode;
15727 + struct super_block *sb;
15729 + file = kio->ki_filp;
15730 + inode = file_inode(file);
15731 + sb = inode->i_sb;
15732 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15734 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15735 + err = PTR_ERR(h_file);
15736 + if (IS_ERR(h_file))
15739 + if (au_test_loopback_kthread()) {
15740 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15741 + if (file->f_mapping != h_file->f_mapping) {
15742 + file->f_mapping = h_file->f_mapping;
15743 + smp_mb(); /* unnecessary? */
15746 + fi_read_unlock(file);
15748 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15749 + /* todo: necessary? */
15750 + /* file->f_ra = h_file->f_ra; */
15751 + au_read_post(inode, h_file);
15754 + si_read_unlock(sb);
15758 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15761 + struct au_write_pre wpre;
15762 + struct inode *inode;
15763 + struct file *file, *h_file;
15765 + file = kio->ki_filp;
15766 + inode = file_inode(file);
15767 + au_mtx_and_read_lock(inode);
15770 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15771 + err = PTR_ERR(h_file);
15772 + if (IS_ERR(h_file))
15775 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15776 + au_write_post(inode, h_file, &wpre, err);
15779 + si_read_unlock(inode->i_sb);
15780 + inode_unlock(inode);
15785 + * We may be able to remove aufs_splice_{read,write}() since almost all FSes
15786 + * don't have their own .splice_{read,write} implimentations, and they use
15787 + * generic_file_splice_read() and iter_file_splice_write() who can act like the
15788 + * simple converters to f_op->iter_read() and ->iter_write().
15789 + * But we keep our own implementations because some non-mainlined FSes may have
15790 + * their own .splice_{read,write} implimentations and aufs doesn't want to take
15791 + * away an opportunity to co-work with aufs from them.
15793 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15794 + struct pipe_inode_info *pipe, size_t len,
15795 + unsigned int flags)
15798 + struct file *h_file;
15799 + struct inode *inode;
15800 + struct super_block *sb;
15802 + inode = file_inode(file);
15803 + sb = inode->i_sb;
15804 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15806 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15807 + err = PTR_ERR(h_file);
15808 + if (IS_ERR(h_file))
15811 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15812 + /* todo: necessary? */
15813 + /* file->f_ra = h_file->f_ra; */
15814 + au_read_post(inode, h_file);
15817 + si_read_unlock(sb);
15822 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15823 + size_t len, unsigned int flags)
15826 + struct au_write_pre wpre;
15827 + struct inode *inode;
15828 + struct file *h_file;
15830 + inode = file_inode(file);
15831 + au_mtx_and_read_lock(inode);
15834 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15835 + err = PTR_ERR(h_file);
15836 + if (IS_ERR(h_file))
15839 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15840 + au_write_post(inode, h_file, &wpre, err);
15843 + si_read_unlock(inode->i_sb);
15844 + inode_unlock(inode);
15848 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15852 + struct au_write_pre wpre;
15853 + struct inode *inode;
15854 + struct file *h_file;
15856 + inode = file_inode(file);
15857 + au_mtx_and_read_lock(inode);
15860 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15861 + err = PTR_ERR(h_file);
15862 + if (IS_ERR(h_file))
15866 + err = vfs_fallocate(h_file, mode, offset, len);
15868 + au_write_post(inode, h_file, &wpre, /*written*/1);
15871 + si_read_unlock(inode->i_sb);
15872 + inode_unlock(inode);
15876 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15877 + struct file *dst, loff_t dst_pos,
15878 + size_t len, unsigned int flags)
15881 + struct au_write_pre wpre;
15882 + enum { SRC, DST };
15884 + struct inode *inode;
15885 + struct file *h_file;
15886 + struct super_block *h_sb;
15888 +#define a_src a[SRC]
15889 +#define a_dst a[DST]
15892 + a_src.inode = file_inode(src);
15893 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15895 + a_dst.inode = file_inode(dst);
15896 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15899 + au_mtx_and_read_lock(a_dst.inode);
15901 + * in order to match the order in di_write_lock2_{child,parent}(),
15902 + * use f_path.dentry for this comparison.
15904 + if (src->f_path.dentry < dst->f_path.dentry) {
15905 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15906 + err = PTR_ERR(a_src.h_file);
15907 + if (IS_ERR(a_src.h_file))
15910 + wpre.lsc = AuLsc_FI_2;
15911 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15912 + err = PTR_ERR(a_dst.h_file);
15913 + if (IS_ERR(a_dst.h_file)) {
15914 + au_read_post(a_src.inode, a_src.h_file);
15918 + wpre.lsc = AuLsc_FI_1;
15919 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15920 + err = PTR_ERR(a_dst.h_file);
15921 + if (IS_ERR(a_dst.h_file))
15924 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15925 + err = PTR_ERR(a_src.h_file);
15926 + if (IS_ERR(a_src.h_file)) {
15927 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15934 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15935 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15936 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15942 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15943 + dst_pos, len, flags);
15946 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15947 + fi_read_unlock(src);
15948 + au_read_post(a_src.inode, a_src.h_file);
15950 + si_read_unlock(a_dst.inode->i_sb);
15951 + inode_unlock(a_dst.inode);
15958 +/* ---------------------------------------------------------------------- */
15961 + * The locking order around current->mmap_sem.
15962 + * - in most and regular cases
15963 + * file I/O syscall -- aufs_read() or something
15964 + * -- si_rwsem for read -- mmap_sem
15965 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15967 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15968 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
15969 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
15970 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
15971 + * It means that when aufs acquires si_rwsem for write, the process should never
15972 + * acquire mmap_sem.
15974 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
15975 + * problem either since any directory is not able to be mmap-ed.
15976 + * The similar scenario is applied to aufs_readlink() too.
15979 +#if 0 /* stop calling security_file_mmap() */
15980 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
15981 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
15983 +static unsigned long au_arch_prot_conv(unsigned long flags)
15985 + /* currently ppc64 only */
15986 +#ifdef CONFIG_PPC64
15987 + /* cf. linux/arch/powerpc/include/asm/mman.h */
15988 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
15989 + return AuConv_VM_PROT(flags, SAO);
15991 + AuDebugOn(arch_calc_vm_prot_bits(-1));
15996 +static unsigned long au_prot_conv(unsigned long flags)
15998 + return AuConv_VM_PROT(flags, READ)
15999 + | AuConv_VM_PROT(flags, WRITE)
16000 + | AuConv_VM_PROT(flags, EXEC)
16001 + | au_arch_prot_conv(flags);
16004 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16005 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16007 +static unsigned long au_flag_conv(unsigned long flags)
16009 + return AuConv_VM_MAP(flags, GROWSDOWN)
16010 + | AuConv_VM_MAP(flags, DENYWRITE)
16011 + | AuConv_VM_MAP(flags, LOCKED);
16015 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16018 + const unsigned char wlock
16019 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16020 + struct super_block *sb;
16021 + struct file *h_file;
16022 + struct inode *inode;
16024 + AuDbgVmRegion(file, vma);
16026 + inode = file_inode(file);
16027 + sb = inode->i_sb;
16029 + si_read_lock(sb, AuLock_NOPLMW);
16031 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16033 + err = PTR_ERR(h_file);
16034 + if (IS_ERR(h_file))
16038 + au_set_mmapped(file);
16039 + au_vm_file_reset(vma, h_file);
16041 + * we cannot call security_mmap_file() here since it may acquire
16042 + * mmap_sem or i_mutex.
16044 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16045 + * au_flag_conv(vma->vm_flags));
16048 + err = call_mmap(h_file, vma);
16050 + au_vm_prfile_set(vma, file);
16051 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16052 + goto out_fput; /* success */
16054 + au_unset_mmapped(file);
16055 + au_vm_file_reset(vma, file);
16059 + ii_write_unlock(inode);
16064 + si_read_unlock(sb);
16070 +/* ---------------------------------------------------------------------- */
16072 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16076 + struct au_write_pre wpre;
16077 + struct inode *inode;
16078 + struct file *h_file;
16080 + err = 0; /* -EBADF; */ /* posix? */
16081 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16084 + inode = file_inode(file);
16085 + au_mtx_and_read_lock(inode);
16088 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16089 + err = PTR_ERR(h_file);
16090 + if (IS_ERR(h_file))
16093 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16094 + au_write_post(inode, h_file, &wpre, /*written*/0);
16097 + si_read_unlock(inode->i_sb);
16098 + inode_unlock(inode);
16103 +static int aufs_fasync(int fd, struct file *file, int flag)
16106 + struct file *h_file;
16107 + struct super_block *sb;
16109 + sb = file->f_path.dentry->d_sb;
16110 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16112 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16113 + err = PTR_ERR(h_file);
16114 + if (IS_ERR(h_file))
16117 + if (h_file->f_op->fasync)
16118 + err = h_file->f_op->fasync(fd, h_file, flag);
16119 + fput(h_file); /* instead of au_read_post() */
16122 + si_read_unlock(sb);
16126 +static int aufs_setfl(struct file *file, unsigned long arg)
16129 + struct file *h_file;
16130 + struct super_block *sb;
16132 + sb = file->f_path.dentry->d_sb;
16133 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16135 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16136 + err = PTR_ERR(h_file);
16137 + if (IS_ERR(h_file))
16140 + /* stop calling h_file->fasync */
16141 + arg |= vfsub_file_flags(file) & FASYNC;
16142 + err = setfl(/*unused fd*/-1, h_file, arg);
16143 + fput(h_file); /* instead of au_read_post() */
16146 + si_read_unlock(sb);
16150 +/* ---------------------------------------------------------------------- */
16152 +/* no one supports this operation, currently */
16153 +#if 0 /* reserved for future use */
16154 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16155 + size_t len, loff_t *pos, int more)
16160 +/* ---------------------------------------------------------------------- */
16162 +const struct file_operations aufs_file_fop = {
16163 + .owner = THIS_MODULE,
16165 + .llseek = default_llseek,
16167 + .read_iter = aufs_read_iter,
16168 + .write_iter = aufs_write_iter,
16170 +#ifdef CONFIG_AUFS_POLL
16171 + .poll = aufs_poll,
16173 + .unlocked_ioctl = aufs_ioctl_nondir,
16174 +#ifdef CONFIG_COMPAT
16175 + .compat_ioctl = aufs_compat_ioctl_nondir,
16177 + .mmap = aufs_mmap,
16178 + .open = aufs_open_nondir,
16179 + .flush = aufs_flush_nondir,
16180 + .release = aufs_release_nondir,
16181 + .fsync = aufs_fsync_nondir,
16182 + .fasync = aufs_fasync,
16183 + /* .sendpage = aufs_sendpage, */
16184 + .setfl = aufs_setfl,
16185 + .splice_write = aufs_splice_write,
16186 + .splice_read = aufs_splice_read,
16187 +#if 0 /* reserved for future use */
16188 + .aio_splice_write = aufs_aio_splice_write,
16189 + .aio_splice_read = aufs_aio_splice_read,
16191 + .fallocate = aufs_fallocate,
16192 + .copy_file_range = aufs_copy_file_range
16194 diff -urN /usr/share/empty/fs/aufs/fsctx.c linux/fs/aufs/fsctx.c
16195 --- /usr/share/empty/fs/aufs/fsctx.c 1970-01-01 01:00:00.000000000 +0100
16196 +++ linux/fs/aufs/fsctx.c 2022-11-05 23:02:18.965889284 +0100
16198 +// SPDX-License-Identifier: GPL-2.0
16200 + * Copyright (C) 2022 Junjiro R. Okajima
16202 + * This program is free software; you can redistribute it and/or modify
16203 + * it under the terms of the GNU General Public License as published by
16204 + * the Free Software Foundation; either version 2 of the License, or
16205 + * (at your option) any later version.
16207 + * This program is distributed in the hope that it will be useful,
16208 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16209 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16210 + * GNU General Public License for more details.
16212 + * You should have received a copy of the GNU General Public License
16213 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16217 + * fs context, aka new mount api
16220 +#include <linux/fs_context.h>
16223 +struct au_fsctx_opts {
16224 + aufs_bindex_t bindex;
16225 + unsigned char skipped;
16226 + struct au_opt *opt, *opt_tail;
16227 + struct super_block *sb;
16228 + struct au_sbinfo *sbinfo;
16229 + struct au_opts opts;
16232 +/* stop extra interpretation of errno in mount(8), and strange error messages */
16233 +static int cvt_err(int err)
16247 +static int au_fsctx_reconfigure(struct fs_context *fc)
16250 + unsigned int mntflags;
16251 + struct dentry *root;
16252 + struct super_block *sb;
16253 + struct inode *inode;
16254 + struct au_fsctx_opts *a = fc->fs_private;
16256 + AuDbg("fc %p\n", fc);
16260 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16262 + di_write_lock_child(root);
16263 + err = au_opts_verify(sb, fc->sb_flags, /*pending*/0);
16264 + aufs_write_unlock(root);
16267 + inode = d_inode(root);
16268 + inode_lock(inode);
16269 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16270 + if (unlikely(err))
16272 + di_write_lock_child(root);
16274 + /* au_opts_remount() may return an error */
16275 + err = au_opts_remount(sb, &a->opts);
16277 + if (au_ftest_opts(a->opts.flags, REFRESH))
16278 + au_remount_refresh(sb, au_ftest_opts(a->opts.flags,
16281 + if (au_ftest_opts(a->opts.flags, REFRESH_DYAOP)) {
16282 + mntflags = au_mntflags(sb);
16283 + do_dx = !!au_opt_test(mntflags, DIO);
16284 + au_dy_arefresh(do_dx);
16287 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
16288 + aufs_write_unlock(root);
16291 + inode_unlock(inode);
16292 + err = cvt_err(err);
16298 +/* ---------------------------------------------------------------------- */
16300 +static int au_fsctx_fill_super(struct super_block *sb, struct fs_context *fc)
16303 + struct au_fsctx_opts *a = fc->fs_private;
16304 + struct au_sbinfo *sbinfo = a->sbinfo;
16305 + struct dentry *root;
16306 + struct inode *inode;
16308 + sbinfo->si_sb = sb;
16309 + sb->s_fs_info = sbinfo;
16310 + kobject_get(&sbinfo->si_kobj);
16312 + __si_write_lock(sb);
16314 + au_sbilist_add(sb);
16316 + /* all timestamps always follow the ones on the branch */
16317 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
16318 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
16319 + sb->s_op = &aufs_sop;
16320 + sb->s_d_op = &aufs_dop;
16321 + sb->s_magic = AUFS_SUPER_MAGIC;
16322 + sb->s_maxbytes = 0;
16323 + sb->s_stack_depth = 1;
16324 + au_export_init(sb);
16325 + au_xattr_init(sb);
16327 + err = au_alloc_root(sb);
16328 + if (unlikely(err)) {
16329 + si_write_unlock(sb);
16332 + root = sb->s_root;
16333 + inode = d_inode(root);
16334 + ii_write_lock_parent(inode);
16335 + aufs_write_unlock(root);
16337 + /* lock vfs_inode first, then aufs. */
16338 + inode_lock(inode);
16339 + aufs_write_lock(root);
16340 + err = au_opts_mount(sb, &a->opts);
16342 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
16343 + sb->s_d_op = &aufs_dop_noreval;
16344 + /* infofc(fc, "%ps", sb->s_d_op); */
16345 + pr_info("%ps\n", sb->s_d_op);
16346 + au_refresh_dop(root, /*force_reval*/0);
16347 + sbinfo->si_iop_array = aufs_iop_nogetattr;
16348 + au_refresh_iop(inode, /*force_getattr*/0);
16350 + aufs_write_unlock(root);
16351 + inode_unlock(inode);
16353 + goto out; /* success */
16356 + sb->s_root = NULL;
16359 + if (unlikely(err))
16360 + kobject_put(&sbinfo->si_kobj);
16362 + err = cvt_err(err);
16367 +static int au_fsctx_get_tree(struct fs_context *fc)
16371 + AuDbg("fc %p\n", fc);
16372 + err = get_tree_nodev(fc, au_fsctx_fill_super);
16378 +/* ---------------------------------------------------------------------- */
16380 +static void au_fsctx_dump(struct au_opts *opts)
16382 +#ifdef CONFIG_AUFS_DEBUG
16383 + /* reduce stack space */
16385 + struct au_opt_add *add;
16386 + struct au_opt_del *del;
16387 + struct au_opt_mod *mod;
16388 + struct au_opt_xino *xino;
16389 + struct au_opt_xino_itrunc *xino_itrunc;
16390 + struct au_opt_wbr_create *create;
16392 + struct au_opt *opt;
16395 + while (opt->type != Opt_tail) {
16396 + switch (opt->type) {
16398 + u.add = &opt->add;
16399 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
16400 + u.add->bindex, u.add->pathname, u.add->perm,
16401 + u.add->path.dentry);
16406 + u.del = &opt->del;
16407 + AuDbg("del {%s, %p}\n",
16408 + u.del->pathname, u.del->h_path.dentry);
16413 + u.mod = &opt->mod;
16414 + AuDbg("mod {%s, 0x%x, %p}\n",
16415 + u.mod->path, u.mod->perm, u.mod->h_root);
16418 + u.add = &opt->add;
16419 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
16420 + u.add->bindex, u.add->pathname, u.add->perm,
16421 + u.add->path.dentry);
16423 + case Opt_prepend:
16424 + u.add = &opt->add;
16425 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
16426 + u.add->bindex, u.add->pathname, u.add->perm,
16427 + u.add->path.dentry);
16431 + AuDbg("dirwh %d\n", opt->dirwh);
16433 + case Opt_rdcache:
16434 + AuDbg("rdcache %d\n", opt->rdcache);
16437 + AuDbg("rdblk %d\n", opt->rdblk);
16440 + AuDbg("rdhash %u\n", opt->rdhash);
16444 + u.xino = &opt->xino;
16445 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
16448 +#define au_fsctx_TF(name) \
16449 + case Opt_##name: \
16453 + AuLabel(no##name); \
16456 + /* simple true/false flag */
16457 + au_fsctx_TF(trunc_xino);
16458 + au_fsctx_TF(trunc_xib);
16459 + au_fsctx_TF(dirperm1);
16460 + au_fsctx_TF(plink);
16461 + au_fsctx_TF(shwh);
16462 + au_fsctx_TF(dio);
16463 + au_fsctx_TF(warn_perm);
16464 + au_fsctx_TF(verbose);
16465 + au_fsctx_TF(sum);
16466 + au_fsctx_TF(dirren);
16467 + au_fsctx_TF(acl);
16468 +#undef au_fsctx_TF
16470 + case Opt_trunc_xino_path:
16472 + case Opt_itrunc_xino:
16473 + u.xino_itrunc = &opt->xino_itrunc;
16474 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
16480 + case Opt_list_plink:
16481 + AuLabel(list_plink);
16484 + AuDbg("udba %d, %s\n",
16485 + opt->udba, au_optstr_udba(opt->udba));
16487 + case Opt_diropq_a:
16488 + AuLabel(diropq_a);
16490 + case Opt_diropq_w:
16491 + AuLabel(diropq_w);
16496 + case Opt_wbr_create:
16497 + u.create = &opt->wbr_create;
16498 + AuDbg("create %d, %s\n", u.create->wbr_create,
16499 + au_optstr_wbr_create(u.create->wbr_create));
16500 + switch (u.create->wbr_create) {
16501 + case AuWbrCreate_MFSV:
16503 + case AuWbrCreate_PMFSV:
16504 + AuDbg("%d sec\n", u.create->mfs_second);
16506 + case AuWbrCreate_MFSRR:
16508 + case AuWbrCreate_TDMFS:
16509 + AuDbg("%llu watermark\n",
16510 + u.create->mfsrr_watermark);
16512 + case AuWbrCreate_MFSRRV:
16514 + case AuWbrCreate_TDMFSV:
16516 + case AuWbrCreate_PMFSRRV:
16517 + AuDbg("%llu watermark, %d sec\n",
16518 + u.create->mfsrr_watermark,
16519 + u.create->mfs_second);
16523 + case Opt_wbr_copyup:
16524 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
16525 + au_optstr_wbr_copyup(opt->wbr_copyup));
16527 + case Opt_fhsm_sec:
16528 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
16532 + AuDbg("type %d\n", opt->type);
16540 +/* ---------------------------------------------------------------------- */
16543 + * For conditionally compiled mount options.
16544 + * Instead of fsparam_flag_no(), use this macro to distinguish ignore_silent.
16546 +#define au_ignore_flag(name, action) \
16547 + fsparam_flag(name, action), \
16548 + fsparam_flag("no" name, Opt_ignore_silent)
16550 +const struct fs_parameter_spec aufs_fsctx_paramspec[] = {
16551 + fsparam_string("br", Opt_br),
16553 + /* "add=%d:%s" or "ins=%d:%s" */
16554 + fsparam_string("add", Opt_add),
16555 + fsparam_string("ins", Opt_add),
16556 + fsparam_path("append", Opt_append),
16557 + fsparam_path("prepend", Opt_prepend),
16559 + fsparam_path("del", Opt_del),
16560 + /* fsparam_s32("idel", Opt_idel), */
16561 + fsparam_path("mod", Opt_mod),
16562 + /* fsparam_string("imod", Opt_imod), */
16564 + fsparam_s32("dirwh", Opt_dirwh),
16566 + fsparam_path("xino", Opt_xino),
16567 + fsparam_flag("noxino", Opt_noxino),
16568 + fsparam_flag_no("trunc_xino", Opt_trunc_xino),
16569 + /* "trunc_xino_v=%d:%d" */
16570 + /* fsparam_string("trunc_xino_v", Opt_trunc_xino_v), */
16571 + fsparam_path("trunc_xino", Opt_trunc_xino_path),
16572 + fsparam_s32("itrunc_xino", Opt_itrunc_xino),
16573 + /* fsparam_path("zxino", Opt_zxino), */
16574 + fsparam_flag_no("trunc_xib", Opt_trunc_xib),
16576 +#ifdef CONFIG_PROC_FS
16577 + fsparam_flag_no("plink", Opt_plink),
16579 + au_ignore_flag("plink", Opt_ignore),
16582 +#ifdef CONFIG_AUFS_DEBUG
16583 + fsparam_flag("list_plink", Opt_list_plink),
16586 + fsparam_string("udba", Opt_udba),
16588 + fsparam_flag_no("dio", Opt_dio),
16590 +#ifdef CONFIG_AUFS_DIRREN
16591 + fsparam_flag_no("dirren", Opt_dirren),
16593 + au_ignore_flag("dirren", Opt_ignore),
16596 +#ifdef CONFIG_AUFS_FHSM
16597 + fsparam_s32("fhsm_sec", Opt_fhsm_sec),
16599 + fsparam_s32("fhsm_sec", Opt_ignore),
16602 + /* always | a | whiteouted | w */
16603 + fsparam_string("diropq", Opt_diropq),
16605 + fsparam_flag_no("warn_perm", Opt_warn_perm),
16607 +#ifdef CONFIG_AUFS_SHWH
16608 + fsparam_flag_no("shwh", Opt_shwh),
16610 + au_ignore_flag("shwh", Opt_err),
16613 + fsparam_flag_no("dirperm1", Opt_dirperm1),
16615 + fsparam_flag_no("verbose", Opt_verbose),
16616 + fsparam_flag("v", Opt_verbose),
16617 + fsparam_flag("quiet", Opt_noverbose),
16618 + fsparam_flag("q", Opt_noverbose),
16619 + /* user-space may handle this */
16620 + fsparam_flag("silent", Opt_noverbose),
16622 + fsparam_flag_no("sum", Opt_sum),
16623 + fsparam_flag("wsum", Opt_wsum),
16625 + fsparam_s32("rdcache", Opt_rdcache),
16626 + /* "def" or s32 */
16627 + fsparam_string("rdblk", Opt_rdblk),
16628 + /* "def" or s32 */
16629 + fsparam_string("rdhash", Opt_rdhash),
16631 + fsparam_string("create", Opt_wbr_create),
16632 + fsparam_string("create_policy", Opt_wbr_create),
16633 + fsparam_string("cpup", Opt_wbr_copyup),
16634 + fsparam_string("copyup", Opt_wbr_copyup),
16635 + fsparam_string("copyup_policy", Opt_wbr_copyup),
16637 + /* generic VFS flag */
16638 +#ifdef CONFIG_FS_POSIX_ACL
16639 + fsparam_flag_no("acl", Opt_acl),
16641 + au_ignore_flag("acl", Opt_ignore),
16644 + /* internal use for the scripts */
16645 + fsparam_string("si", Opt_ignore_silent),
16647 + /* obsoleted, keep them temporary */
16648 + fsparam_flag("nodlgt", Opt_ignore_silent),
16649 + fsparam_flag("clean_plink", Opt_ignore),
16650 + fsparam_string("dirs", Opt_br),
16651 + fsparam_u32("debug", Opt_ignore),
16652 + /* "whiteout" or "all" */
16653 + fsparam_string("delete", Opt_ignore),
16654 + fsparam_string("imap", Opt_ignore),
16656 + /* temporary workaround, due to old mount(8)? */
16657 + fsparam_flag("relatime", Opt_ignore_silent),
16662 +static int au_fsctx_parse_do_add(struct fs_context *fc, struct au_opt *opt,
16663 + char *brspec, size_t speclen,
16664 + aufs_bindex_t bindex)
16669 + AuDbg("brspec %s\n", brspec);
16673 + speclen = strlen(brspec);
16674 + /* will be freed by au_fsctx_free() */
16675 + p = kmemdup_nul(brspec, speclen, GFP_NOFS);
16676 + if (unlikely(!p)) {
16677 + errorfc(fc, "failed in %s", brspec);
16680 + err = au_opt_add(opt, p, fc->sb_flags, bindex);
16687 +static int au_fsctx_parse_br(struct fs_context *fc, char *brspec)
16691 + struct au_fsctx_opts *a = fc->fs_private;
16692 + struct au_opt *opt = a->opt;
16693 + aufs_bindex_t bindex = a->bindex;
16695 + AuDbg("brspec %s\n", brspec);
16698 + while ((p = strsep(&brspec, ":")) && *p) {
16699 + err = au_fsctx_parse_do_add(fc, opt, p, /*len*/0, bindex);
16701 + if (unlikely(err))
16705 + if (unlikely(opt > a->opt_tail)) {
16711 + opt->type = Opt_tail;
16714 + a->bindex = bindex;
16721 +static int au_fsctx_parse_add(struct fs_context *fc, char *addspec)
16725 + struct au_fsctx_opts *a = fc->fs_private;
16726 + struct au_opt *opt = a->opt;
16729 + p = strchr(addspec, ':');
16730 + if (unlikely(!p)) {
16731 + errorfc(fc, "bad arg in %s", addspec);
16735 + err = kstrtoint(addspec, 0, &n);
16736 + if (unlikely(err)) {
16737 + errorfc(fc, "bad integer in %s", addspec);
16740 + AuDbg("n %d\n", n);
16741 + err = au_fsctx_parse_do_add(fc, opt, p, /*len*/0, n);
16748 +static int au_fsctx_parse_del(struct fs_context *fc, struct au_opt_del *del,
16749 + struct fs_parameter *param)
16754 + /* will be freed by au_fsctx_free() */
16755 + del->pathname = kmemdup_nul(param->string, param->size, GFP_NOFS);
16756 + if (unlikely(!del->pathname))
16758 + AuDbg("del %s\n", del->pathname);
16759 + err = vfsub_kern_path(del->pathname, AuOpt_LkupDirFlags, &del->h_path);
16760 + if (unlikely(err))
16761 + errorfc(fc, "lookup failed %s (%d)", del->pathname, err);
16768 +#if 0 /* reserved for future use */
16769 +static int au_fsctx_parse_idel(struct fs_context *fc, struct au_opt_del *del,
16770 + aufs_bindex_t bindex)
16773 + struct super_block *sb;
16774 + struct dentry *root;
16775 + struct au_fsctx_opts *a = fc->fs_private;
16781 + root = sb->s_root;
16782 + aufs_read_lock(root, AuLock_FLUSH);
16783 + if (bindex < 0 || au_sbbot(sb) < bindex) {
16784 + errorfc(fc, "out of bounds, %d", bindex);
16789 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
16790 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
16793 + aufs_read_unlock(root, !AuLock_IR);
16799 +static int au_fsctx_parse_mod(struct fs_context *fc, struct au_opt_mod *mod,
16800 + struct fs_parameter *param)
16803 + struct path path;
16807 + /* will be freed by au_fsctx_free() */
16808 + mod->path = kmemdup_nul(param->string, param->size, GFP_NOFS);
16809 + if (unlikely(!mod->path))
16813 + p = strchr(mod->path, '=');
16814 + if (unlikely(!p)) {
16815 + errorfc(fc, "no permission %s", mod->path);
16820 + err = vfsub_kern_path(mod->path, AuOpt_LkupDirFlags, &path);
16821 + if (unlikely(err)) {
16822 + errorfc(fc, "lookup failed %s (%d)", mod->path, err);
16826 + mod->perm = au_br_perm_val(p);
16827 + AuDbg("mod path %s, perm 0x%x, %s", mod->path, mod->perm, p);
16828 + mod->h_root = dget(path.dentry);
16836 +#if 0 /* reserved for future use */
16837 +static int au_fsctx_parse_imod(struct fs_context *fc, struct au_opt_mod *mod,
16842 + struct super_block *sb;
16843 + struct dentry *root;
16844 + struct au_fsctx_opts *a = fc->fs_private;
16850 + p = strchr(ibrspec, ':');
16851 + if (unlikely(!p)) {
16852 + errorfc(fc, "no index, %s", ibrspec);
16856 + err = kstrtoint(ibrspec, 0, &n);
16857 + if (unlikely(err)) {
16858 + errorfc(fc, "bad integer in %s", ibrspec);
16861 + AuDbg("n %d\n", n);
16863 + root = sb->s_root;
16864 + aufs_read_lock(root, AuLock_FLUSH);
16865 + if (n < 0 || au_sbbot(sb) < n) {
16866 + errorfc(fc, "out of bounds, %d", bindex);
16871 + mod->perm = au_br_perm_val(p);
16872 + AuDbg("mod path %s, perm 0x%x, %s\n",
16873 + mod->path, mod->perm, p);
16874 + mod->h_root = dget(au_h_dptr(root, bindex));
16877 + aufs_read_unlock(root, !AuLock_IR);
16884 +static int au_fsctx_parse_xino(struct fs_context *fc,
16885 + struct au_opt_xino *xino,
16886 + struct fs_parameter *param)
16889 + struct au_fsctx_opts *a = fc->fs_private;
16892 + /* will be freed by au_opts_free() */
16893 + xino->path = kmemdup_nul(param->string, param->size, GFP_NOFS);
16894 + if (unlikely(!xino->path))
16896 + AuDbg("path %s\n", xino->path);
16898 + xino->file = au_xino_create(a->sb, xino->path, /*silent*/0,
16900 + err = PTR_ERR(xino->file);
16901 + if (IS_ERR(xino->file)) {
16902 + xino->file = NULL;
16907 + if (unlikely(a->sb && xino->file->f_path.dentry->d_sb == a->sb)) {
16909 + errorfc(fc, "%s must be outside", xino->path);
16918 +int au_fsctx_parse_xino_itrunc_path(struct fs_context *fc,
16919 + struct au_opt_xino_itrunc *xino_itrunc,
16923 + aufs_bindex_t bbot, bindex;
16924 + struct path path;
16925 + struct dentry *root;
16926 + struct au_fsctx_opts *a = fc->fs_private;
16928 + AuDebugOn(!a->sb);
16930 + err = vfsub_kern_path(pathname, AuOpt_LkupDirFlags, &path);
16931 + if (unlikely(err)) {
16932 + errorfc(fc, "lookup failed %s (%d)", pathname, err);
16936 + xino_itrunc->bindex = -1;
16937 + root = a->sb->s_root;
16938 + aufs_read_lock(root, AuLock_FLUSH);
16939 + bbot = au_sbbot(a->sb);
16940 + for (bindex = 0; bindex <= bbot; bindex++) {
16941 + if (au_h_dptr(root, bindex) == path.dentry) {
16942 + xino_itrunc->bindex = bindex;
16946 + aufs_read_unlock(root, !AuLock_IR);
16949 + if (unlikely(xino_itrunc->bindex < 0)) {
16951 + errorfc(fc, "no such branch %s", pathname);
16959 +static int au_fsctx_parse_xino_itrunc(struct fs_context *fc,
16960 + struct au_opt_xino_itrunc *xino_itrunc,
16961 + unsigned int bindex)
16964 + aufs_bindex_t bbot;
16965 + struct super_block *sb;
16966 + struct au_fsctx_opts *a = fc->fs_private;
16972 + si_noflush_read_lock(sb);
16973 + bbot = au_sbbot(sb);
16974 + si_read_unlock(sb);
16975 + if (bindex <= bbot)
16976 + xino_itrunc->bindex = bindex;
16979 + errorfc(fc, "out of bounds, %u", bindex);
16986 +static int au_fsctx_parse_param(struct fs_context *fc, struct fs_parameter *param)
16989 + struct fs_parse_result result;
16990 + struct au_fsctx_opts *a = fc->fs_private;
16991 + struct au_opt *opt = a->opt;
16993 + AuDbg("fc %p, param {key %s, string %s}\n",
16994 + fc, param->key, param->string);
16995 + err = fs_parse(fc, aufs_fsctx_paramspec, param, &result);
16996 + if (unlikely(err < 0))
16999 + AuDbg("token %d, res{negated %d, uint64 %llu}\n",
17000 + token, result.negated, result.uint_64);
17006 + err = au_fsctx_parse_br(fc, param->string);
17009 + err = au_fsctx_parse_add(fc, param->string);
17012 + err = au_fsctx_parse_do_add(fc, opt, param->string, param->size,
17013 + /*dummy bindex*/1);
17015 + case Opt_prepend:
17016 + err = au_fsctx_parse_do_add(fc, opt, param->string, param->size,
17021 + err = au_fsctx_parse_del(fc, &opt->del, param);
17023 +#if 0 /* reserved for future use */
17030 + del->pathname = "(indexed)";
17031 + err = au_opts_parse_idel(fc, &opt->del, result.uint_32);
17036 + err = au_fsctx_parse_mod(fc, &opt->mod, param);
17038 +#ifdef IMOD /* reserved for future use */
17045 + u.mod->path = "(indexed)";
17046 + err = au_opts_parse_imod(fc, &opt->mod, param->string);
17051 + err = au_fsctx_parse_xino(fc, &opt->xino, param);
17053 + case Opt_trunc_xino_path:
17055 + errorfc(fc, "no such branch %s", param->string);
17058 + err = au_fsctx_parse_xino_itrunc_path(fc, &opt->xino_itrunc,
17062 + case Opt_trunc_xino_v:
17068 + err = au_fsctx_parse_xino_itrunc_path(fc, &opt->xino_itrunc,
17072 + case Opt_itrunc_xino:
17074 + errorfc(fc, "out of bounds %s", param->string);
17077 + err = au_fsctx_parse_xino_itrunc(fc, &opt->xino_itrunc,
17083 + opt->dirwh = result.int_32;
17086 + case Opt_rdcache:
17087 + if (unlikely(result.int_32 > AUFS_RDCACHE_MAX)) {
17088 + errorfc(fc, "rdcache must be smaller than %d",
17089 + AUFS_RDCACHE_MAX);
17093 + opt->rdcache = result.int_32;
17098 + opt->rdblk = AUFS_RDBLK_DEF;
17099 + if (!strcmp(param->string, "def"))
17102 + err = kstrtoint(param->string, 0, &result.int_32);
17103 + if (unlikely(err)) {
17104 + errorfc(fc, "bad value in %s", param->key);
17108 + if (unlikely(result.int_32 < 0
17109 + || result.int_32 > KMALLOC_MAX_SIZE)) {
17110 + errorfc(fc, "bad value in %s", param->key);
17113 + if (unlikely(result.int_32 && result.int_32 < NAME_MAX)) {
17114 + errorfc(fc, "rdblk must be larger than %d", NAME_MAX);
17118 + opt->rdblk = result.int_32;
17123 + opt->rdhash = AUFS_RDHASH_DEF;
17124 + if (!strcmp(param->string, "def"))
17127 + err = kstrtoint(param->string, 0, &result.int_32);
17128 + if (unlikely(err)) {
17129 + errorfc(fc, "bad value in %s", param->key);
17132 + /* how about zero? */
17133 + if (result.int_32 < 0
17134 + || result.int_32 * sizeof(struct hlist_head)
17135 + > KMALLOC_MAX_SIZE) {
17137 + errorfc(fc, "bad integer in %s", param->key);
17140 + opt->rdhash = result.int_32;
17145 + * As other options, fs/aufs/opts.c can handle these strings by
17146 + * match_token(). But "diropq=" is deprecated now and will
17147 + * never have other value. So simple strcmp() is enough here.
17149 + if (!strcmp(param->string, "a") ||
17150 + !strcmp(param->string, "always")) {
17152 + opt->type = Opt_diropq_a;
17153 + } else if (!strcmp(param->string, "w") ||
17154 + !strcmp(param->string, "whiteouted")) {
17156 + opt->type = Opt_diropq_w;
17158 + errorfc(fc, "unknown value %s", param->string);
17162 + opt->udba = au_udba_val(param->string);
17163 + if (opt->udba >= 0)
17166 + errorf(fc, "wrong value, %s", param->string);
17169 + case Opt_wbr_create:
17170 + opt->wbr_create.wbr_create
17171 + = au_wbr_create_val(param->string, &opt->wbr_create);
17172 + if (opt->wbr_create.wbr_create >= 0)
17175 + errorf(fc, "wrong value, %s", param->key);
17178 + case Opt_wbr_copyup:
17179 + opt->wbr_copyup = au_wbr_copyup_val(param->string);
17180 + if (opt->wbr_copyup >= 0)
17183 + errorfc(fc, "wrong value, %s", param->key);
17186 + case Opt_fhsm_sec:
17187 + if (unlikely(result.int_32 < 0)) {
17188 + errorfc(fc, "bad integer in %s\n", param->key);
17193 + opt->fhsm_second = result.int_32;
17195 + warnfc(fc, "ignored %s %s", param->key, param->string);
17198 + /* simple true/false flag */
17199 +#define au_fsctx_TF(name) \
17200 + case Opt_##name: \
17202 + opt->tf = !result.negated; \
17204 + au_fsctx_TF(trunc_xino);
17205 + au_fsctx_TF(trunc_xib);
17206 + au_fsctx_TF(dirperm1);
17207 + au_fsctx_TF(plink);
17208 + au_fsctx_TF(shwh);
17209 + au_fsctx_TF(dio);
17210 + au_fsctx_TF(warn_perm);
17211 + au_fsctx_TF(verbose);
17212 + au_fsctx_TF(sum);
17213 + au_fsctx_TF(dirren);
17214 + au_fsctx_TF(acl);
17215 +#undef au_fsctx_TF
17217 + case Opt_noverbose:
17219 + opt->type = Opt_verbose;
17225 + case Opt_list_plink:
17232 + warnfc(fc, "ignored %s", param->key);
17234 + case Opt_ignore_silent:
17243 + if (unlikely(err))
17251 + case Opt_noverbose:
17256 + opt->type = token;
17260 + if (unlikely(opt > a->opt_tail)) {
17264 + opt->type = Opt_tail;
17272 + * these options accept both 'name=val' and 'name:val' form.
17273 + * some accept optional '=' in its value.
17274 + * eg. br:/br1=rw:/br2=ro and br=/br1=rw:/br2=ro
17276 +static inline unsigned int is_colonopt(char *str)
17278 +#define do_test(name) \
17279 + if (!strncmp(str, name ":", sizeof(name))) \
17280 + return sizeof(name) - 1
17284 + do_test("append");
17285 + do_test("prepend");
17287 + /* do_test("idel"); */
17289 + /* do_test("imod"); */
17295 +static int au_fsctx_parse_monolithic(struct fs_context *fc, void *data)
17300 + struct au_fsctx_opts *a = fc->fs_private;
17303 + AuDbg("str %s\n", str);
17305 + u = is_colonopt(str);
17308 + str = strchr(str, ',');
17314 + AuDbg("str %s\n", str);
17316 + err = generic_parse_monolithic(fc, str);
17318 + au_fsctx_dump(&a->opts);
17323 +/* ---------------------------------------------------------------------- */
17325 +static void au_fsctx_opts_free(struct au_opts *opts)
17327 + struct au_opt *opt;
17330 + while (opt->type != Opt_tail) {
17331 + switch (opt->type) {
17336 + case Opt_prepend:
17337 + kfree(opt->add.pathname);
17338 + path_put(&opt->add.path);
17341 + kfree(opt->del.pathname);
17344 + path_put(&opt->del.h_path);
17347 + kfree(opt->mod.path);
17350 + dput(opt->mod.h_root);
17353 + kfree(opt->xino.path);
17354 + fput(opt->xino.file);
17361 +static void au_fsctx_free(struct fs_context *fc)
17363 + struct au_fsctx_opts *a = fc->fs_private;
17365 + /* fs_type=%p, root=%pD */
17366 + AuDbg("fc %p{sb_flags 0x%x, sb_flags_mask 0x%x, purpose %u\n",
17367 + fc, fc->sb_flags, fc->sb_flags_mask, fc->purpose);
17369 + kobject_put(&a->sbinfo->si_kobj);
17370 + au_fsctx_opts_free(&a->opts);
17371 + free_page((unsigned long)a->opts.opt);
17375 +static const struct fs_context_operations au_fsctx_ops = {
17376 + .free = au_fsctx_free,
17377 + .parse_param = au_fsctx_parse_param,
17378 + .parse_monolithic = au_fsctx_parse_monolithic,
17379 + .get_tree = au_fsctx_get_tree,
17380 + .reconfigure = au_fsctx_reconfigure
17382 + * nfs4 requires ->dup()? No.
17383 + * I don't know what is this ->dup() for.
17387 +int aufs_fsctx_init(struct fs_context *fc)
17390 + struct au_fsctx_opts *a;
17392 + /* fs_type=%p, root=%pD */
17393 + AuDbg("fc %p{sb_flags 0x%x, sb_flags_mask 0x%x, purpose %u\n",
17394 + fc, fc->sb_flags, fc->sb_flags_mask, fc->purpose);
17396 + /* they will be freed by au_fsctx_free() */
17398 + a = kzalloc(sizeof(*a), GFP_NOFS);
17399 + if (unlikely(!a))
17402 + a->opts.opt = (void *)__get_free_page(GFP_NOFS);
17403 + if (unlikely(!a->opts.opt))
17405 + a->opt = a->opts.opt;
17406 + a->opt->type = Opt_tail;
17407 + a->opts.max_opt = PAGE_SIZE / sizeof(*a->opts.opt);
17408 + a->opt_tail = a->opt + a->opts.max_opt - 1;
17409 + a->opts.sb_flags = fc->sb_flags;
17413 + AuDebugOn(fc->purpose != FS_CONTEXT_FOR_RECONFIGURE);
17414 + a->opts.flags = AuOpts_REMOUNT;
17415 + a->sb = fc->root->d_sb;
17416 + a->sbinfo = au_sbi(a->sb);
17417 + kobject_get(&a->sbinfo->si_kobj);
17419 + a->sbinfo = au_si_alloc(a->sb);
17420 + AuDebugOn(!a->sbinfo);
17421 + err = PTR_ERR(a->sbinfo);
17422 + if (IS_ERR(a->sbinfo))
17424 + au_rw_write_unlock(&a->sbinfo->si_rwsem);
17428 + fc->fs_private = a;
17429 + fc->ops = &au_fsctx_ops;
17430 + goto out; /* success */
17433 + free_page((unsigned long)a->opts.opt);
17440 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
17441 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
17442 +++ linux/fs/aufs/fstype.h 2022-11-05 23:02:18.965889284 +0100
17444 +/* SPDX-License-Identifier: GPL-2.0 */
17446 + * Copyright (C) 2005-2022 Junjiro R. Okajima
17448 + * This program is free software; you can redistribute it and/or modify
17449 + * it under the terms of the GNU General Public License as published by
17450 + * the Free Software Foundation; either version 2 of the License, or
17451 + * (at your option) any later version.
17453 + * This program is distributed in the hope that it will be useful,
17454 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17455 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17456 + * GNU General Public License for more details.
17458 + * You should have received a copy of the GNU General Public License
17459 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17463 + * judging filesystem type
17466 +#ifndef __AUFS_FSTYPE_H__
17467 +#define __AUFS_FSTYPE_H__
17471 +#include <linux/fs.h>
17472 +#include <linux/magic.h>
17473 +#include <linux/nfs_fs.h>
17474 +#include <linux/romfs_fs.h>
17476 +static inline int au_test_aufs(struct super_block *sb)
17478 + return sb->s_magic == AUFS_SUPER_MAGIC;
17481 +static inline const char *au_sbtype(struct super_block *sb)
17483 + return sb->s_type->name;
17486 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
17488 +#if IS_ENABLED(CONFIG_ISO9660_FS)
17489 + return sb->s_magic == ISOFS_SUPER_MAGIC;
17495 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
17497 +#if IS_ENABLED(CONFIG_ROMFS_FS)
17498 + return sb->s_magic == ROMFS_MAGIC;
17504 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
17506 +#if IS_ENABLED(CONFIG_CRAMFS)
17507 + return sb->s_magic == CRAMFS_MAGIC;
17512 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
17514 +#if IS_ENABLED(CONFIG_NFS_FS)
17515 + return sb->s_magic == NFS_SUPER_MAGIC;
17521 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
17523 +#if IS_ENABLED(CONFIG_FUSE_FS)
17524 + return sb->s_magic == FUSE_SUPER_MAGIC;
17530 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
17532 +#if IS_ENABLED(CONFIG_XFS_FS)
17533 + return sb->s_magic == XFS_SB_MAGIC;
17539 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
17541 +#ifdef CONFIG_TMPFS
17542 + return sb->s_magic == TMPFS_MAGIC;
17548 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
17550 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
17551 + return !strcmp(au_sbtype(sb), "ecryptfs");
17557 +static inline int au_test_ramfs(struct super_block *sb)
17559 + return sb->s_magic == RAMFS_MAGIC;
17562 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
17564 +#if IS_ENABLED(CONFIG_UBIFS_FS)
17565 + return sb->s_magic == UBIFS_SUPER_MAGIC;
17571 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
17573 +#ifdef CONFIG_PROC_FS
17574 + return sb->s_magic == PROC_SUPER_MAGIC;
17580 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
17582 +#ifdef CONFIG_SYSFS
17583 + return sb->s_magic == SYSFS_MAGIC;
17589 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
17591 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
17592 + return sb->s_magic == CONFIGFS_MAGIC;
17598 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
17600 +#if IS_ENABLED(CONFIG_MINIX_FS)
17601 + return sb->s_magic == MINIX3_SUPER_MAGIC
17602 + || sb->s_magic == MINIX2_SUPER_MAGIC
17603 + || sb->s_magic == MINIX2_SUPER_MAGIC2
17604 + || sb->s_magic == MINIX_SUPER_MAGIC
17605 + || sb->s_magic == MINIX_SUPER_MAGIC2;
17611 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
17613 +#if IS_ENABLED(CONFIG_FAT_FS)
17614 + return sb->s_magic == MSDOS_SUPER_MAGIC;
17620 +static inline int au_test_msdos(struct super_block *sb)
17622 + return au_test_fat(sb);
17625 +static inline int au_test_vfat(struct super_block *sb)
17627 + return au_test_fat(sb);
17630 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
17632 +#ifdef CONFIG_SECURITYFS
17633 + return sb->s_magic == SECURITYFS_MAGIC;
17639 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
17641 +#if IS_ENABLED(CONFIG_SQUASHFS)
17642 + return sb->s_magic == SQUASHFS_MAGIC;
17648 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
17650 +#if IS_ENABLED(CONFIG_BTRFS_FS)
17651 + return sb->s_magic == BTRFS_SUPER_MAGIC;
17657 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
17659 +#if IS_ENABLED(CONFIG_XENFS)
17660 + return sb->s_magic == XENFS_SUPER_MAGIC;
17666 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
17668 +#ifdef CONFIG_DEBUG_FS
17669 + return sb->s_magic == DEBUGFS_MAGIC;
17675 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
17677 +#if IS_ENABLED(CONFIG_NILFS)
17678 + return sb->s_magic == NILFS_SUPER_MAGIC;
17684 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
17686 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
17687 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
17693 +/* ---------------------------------------------------------------------- */
17695 + * they can't be an aufs branch.
17697 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
17700 +#ifndef CONFIG_AUFS_BR_RAMFS
17701 + au_test_ramfs(sb) ||
17703 + au_test_procfs(sb)
17704 + || au_test_sysfs(sb)
17705 + || au_test_configfs(sb)
17706 + || au_test_debugfs(sb)
17707 + || au_test_securityfs(sb)
17708 + || au_test_xenfs(sb)
17709 + || au_test_ecryptfs(sb)
17710 + /* || !strcmp(au_sbtype(sb), "unionfs") */
17711 + || au_test_aufs(sb); /* will be supported in next version */
17714 +static inline int au_test_fs_remote(struct super_block *sb)
17716 + return !au_test_tmpfs(sb)
17717 +#ifdef CONFIG_AUFS_BR_RAMFS
17718 + && !au_test_ramfs(sb)
17720 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
17723 +/* ---------------------------------------------------------------------- */
17726 + * Note: these functions (below) are created after reading ->getattr() in all
17727 + * filesystems under linux/fs. it means we have to do so in every update...
17731 + * some filesystems require getattr to refresh the inode attributes before
17733 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
17734 + * and leave the work for d_revalidate()
17736 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
17738 + return au_test_nfs(sb)
17739 + || au_test_fuse(sb)
17740 + /* || au_test_btrfs(sb) */ /* untested */
17745 + * filesystems which don't maintain i_size or i_blocks.
17747 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
17749 + return au_test_xfs(sb)
17750 + || au_test_btrfs(sb)
17751 + || au_test_ubifs(sb)
17752 + || au_test_hfsplus(sb) /* maintained, but incorrect */
17753 + /* || au_test_minix(sb) */ /* untested */
17758 + * filesystems which don't store the correct value in some of their inode
17761 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
17763 + return au_test_fs_bad_iattr_size(sb)
17764 + || au_test_fat(sb)
17765 + || au_test_msdos(sb)
17766 + || au_test_vfat(sb);
17769 +/* they don't check i_nlink in link(2) */
17770 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
17772 + return au_test_tmpfs(sb)
17773 +#ifdef CONFIG_AUFS_BR_RAMFS
17774 + || au_test_ramfs(sb)
17776 + || au_test_ubifs(sb)
17777 + || au_test_hfsplus(sb);
17781 + * filesystems which sets S_NOATIME and S_NOCMTIME.
17783 +static inline int au_test_fs_notime(struct super_block *sb)
17785 + return au_test_nfs(sb)
17786 + || au_test_fuse(sb)
17787 + || au_test_ubifs(sb)
17791 +/* temporary support for i#1 in cramfs */
17792 +static inline int au_test_fs_unique_ino(struct inode *inode)
17794 + if (au_test_cramfs(inode->i_sb))
17795 + return inode->i_ino != 1;
17799 +/* ---------------------------------------------------------------------- */
17802 + * the filesystem where the xino files placed must support i/o after unlink and
17803 + * maintain i_size and i_blocks.
17805 +static inline int au_test_fs_bad_xino(struct super_block *sb)
17807 + return au_test_fs_remote(sb)
17808 + || au_test_fs_bad_iattr_size(sb)
17809 + /* don't want unnecessary work for xino */
17810 + || au_test_aufs(sb)
17811 + || au_test_ecryptfs(sb)
17812 + || au_test_nilfs(sb);
17815 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
17817 + return au_test_tmpfs(sb)
17818 + || au_test_ramfs(sb);
17822 + * test if the @sb is real-readonly.
17824 +static inline int au_test_fs_rr(struct super_block *sb)
17826 + return au_test_squashfs(sb)
17827 + || au_test_iso9660(sb)
17828 + || au_test_cramfs(sb)
17829 + || au_test_romfs(sb);
17833 + * test if the @inode is nfs with 'noacl' option
17834 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
17836 +static inline int au_test_nfs_noacl(struct inode *inode)
17838 + return au_test_nfs(inode->i_sb)
17839 + /* && IS_POSIXACL(inode) */
17840 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
17843 +#endif /* __KERNEL__ */
17844 +#endif /* __AUFS_FSTYPE_H__ */
17845 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
17846 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
17847 +++ linux/fs/aufs/hbl.h 2022-11-05 23:02:18.965889284 +0100
17849 +/* SPDX-License-Identifier: GPL-2.0 */
17851 + * Copyright (C) 2017-2022 Junjiro R. Okajima
17853 + * This program is free software; you can redistribute it and/or modify
17854 + * it under the terms of the GNU General Public License as published by
17855 + * the Free Software Foundation; either version 2 of the License, or
17856 + * (at your option) any later version.
17858 + * This program is distributed in the hope that it will be useful,
17859 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17860 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17861 + * GNU General Public License for more details.
17863 + * You should have received a copy of the GNU General Public License
17864 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17868 + * helpers for hlist_bl.h
17871 +#ifndef __AUFS_HBL_H__
17872 +#define __AUFS_HBL_H__
17876 +#include <linux/list_bl.h>
17878 +static inline void au_hbl_add(struct hlist_bl_node *node,
17879 + struct hlist_bl_head *hbl)
17881 + hlist_bl_lock(hbl);
17882 + hlist_bl_add_head(node, hbl);
17883 + hlist_bl_unlock(hbl);
17886 +static inline void au_hbl_del(struct hlist_bl_node *node,
17887 + struct hlist_bl_head *hbl)
17889 + hlist_bl_lock(hbl);
17890 + hlist_bl_del(node);
17891 + hlist_bl_unlock(hbl);
17894 +#define au_hbl_for_each(pos, head) \
17895 + for (pos = hlist_bl_first(head); \
17899 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
17901 + unsigned long cnt;
17902 + struct hlist_bl_node *pos;
17905 + hlist_bl_lock(hbl);
17906 + au_hbl_for_each(pos, hbl)
17908 + hlist_bl_unlock(hbl);
17912 +#endif /* __KERNEL__ */
17913 +#endif /* __AUFS_HBL_H__ */
17914 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
17915 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
17916 +++ linux/fs/aufs/hfsnotify.c 2022-11-05 23:02:18.965889284 +0100
17918 +// SPDX-License-Identifier: GPL-2.0
17920 + * Copyright (C) 2005-2022 Junjiro R. Okajima
17922 + * This program is free software; you can redistribute it and/or modify
17923 + * it under the terms of the GNU General Public License as published by
17924 + * the Free Software Foundation; either version 2 of the License, or
17925 + * (at your option) any later version.
17927 + * This program is distributed in the hope that it will be useful,
17928 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17929 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17930 + * GNU General Public License for more details.
17932 + * You should have received a copy of the GNU General Public License
17933 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17937 + * fsnotify for the lower directories
17942 +/* FS_IN_IGNORED is unnecessary */
17943 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
17944 + | FS_CREATE | FS_EVENT_ON_CHILD);
17945 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
17946 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
17948 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
17950 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
17952 + /* AuDbg("here\n"); */
17953 + au_cache_free_hnotify(hn);
17954 + smp_mb__before_atomic(); /* for atomic64_dec */
17955 + if (atomic64_dec_and_test(&au_hfsn_ifree))
17956 + wake_up(&au_hfsn_wq);
17959 +static int au_hfsn_alloc(struct au_hinode *hinode)
17962 + struct au_hnotify *hn;
17963 + struct super_block *sb;
17964 + struct au_branch *br;
17965 + struct fsnotify_mark *mark;
17966 + aufs_bindex_t bindex;
17968 + hn = hinode->hi_notify;
17969 + sb = hn->hn_aufs_inode->i_sb;
17970 + bindex = au_br_index(sb, hinode->hi_id);
17971 + br = au_sbr(sb, bindex);
17972 + AuDebugOn(!br->br_hfsn);
17974 + mark = &hn->hn_mark;
17975 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
17976 + mark->mask = AuHfsnMask;
17978 + * by udba rename or rmdir, aufs assign a new inode to the known
17979 + * h_inode, so specify 1 to allow dups.
17982 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
17988 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
17990 + struct fsnotify_mark *mark;
17991 + unsigned long long ull;
17992 + struct fsnotify_group *group;
17994 + ull = atomic64_inc_return(&au_hfsn_ifree);
17997 + mark = &hn->hn_mark;
17998 + spin_lock(&mark->lock);
17999 + group = mark->group;
18000 + fsnotify_get_group(group);
18001 + spin_unlock(&mark->lock);
18003 + fsnotify_destroy_mark(mark, group);
18004 + fsnotify_put_mark(mark);
18005 + fsnotify_put_group(group);
18008 + /* free hn by myself */
18012 +/* ---------------------------------------------------------------------- */
18014 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
18016 + struct fsnotify_mark *mark;
18018 + mark = &hinode->hi_notify->hn_mark;
18019 + spin_lock(&mark->lock);
18021 + AuDebugOn(mark->mask & AuHfsnMask);
18022 + mark->mask |= AuHfsnMask;
18024 + AuDebugOn(!(mark->mask & AuHfsnMask));
18025 + mark->mask &= ~AuHfsnMask;
18027 + spin_unlock(&mark->lock);
18028 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
18031 +/* ---------------------------------------------------------------------- */
18033 +/* #define AuDbgHnotify */
18034 +#ifdef AuDbgHnotify
18035 +static char *au_hfsn_name(u32 mask)
18037 +#ifdef CONFIG_AUFS_DEBUG
18038 +#define test_ret(flag) \
18040 + if (mask & flag) \
18043 + test_ret(FS_ACCESS);
18044 + test_ret(FS_MODIFY);
18045 + test_ret(FS_ATTRIB);
18046 + test_ret(FS_CLOSE_WRITE);
18047 + test_ret(FS_CLOSE_NOWRITE);
18048 + test_ret(FS_OPEN);
18049 + test_ret(FS_MOVED_FROM);
18050 + test_ret(FS_MOVED_TO);
18051 + test_ret(FS_CREATE);
18052 + test_ret(FS_DELETE);
18053 + test_ret(FS_DELETE_SELF);
18054 + test_ret(FS_MOVE_SELF);
18055 + test_ret(FS_UNMOUNT);
18056 + test_ret(FS_Q_OVERFLOW);
18057 + test_ret(FS_IN_IGNORED);
18058 + test_ret(FS_ISDIR);
18059 + test_ret(FS_IN_ONESHOT);
18060 + test_ret(FS_EVENT_ON_CHILD);
18069 +/* ---------------------------------------------------------------------- */
18071 +static void au_hfsn_free_group(struct fsnotify_group *group)
18073 + struct au_br_hfsnotify *hfsn = group->private;
18075 + /* AuDbg("here\n"); */
18076 + au_kfree_try_rcu(hfsn);
18079 +static int au_hfsn_handle_event(struct fsnotify_group *group,
18080 + u32 mask, const void *data, int data_type,
18081 + struct inode *dir,
18082 + const struct qstr *file_name, u32 cookie,
18083 + struct fsnotify_iter_info *iter_info)
18086 + struct au_hnotify *hnotify;
18087 + struct inode *h_dir, *h_inode;
18088 + struct fsnotify_mark *inode_mark;
18090 + AuDebugOn(!(data_type == FSNOTIFY_EVENT_INODE
18091 + || data_type == FSNOTIFY_EVENT_DENTRY));
18094 + /* if FS_UNMOUNT happens, there must be another bug */
18095 + AuDebugOn(mask & FS_UNMOUNT);
18096 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
18101 +#ifdef AuDbgHnotify
18103 + if (1 || file_name.len != sizeof(AUFS_XINO_FNAME) - 1
18104 + || strncmp(file_name.name, AUFS_XINO_FNAME, file_name.len)) {
18105 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
18106 + h_dir->i_ino, mask, au_hfsn_name(mask),
18107 + AuLNPair(file_name), h_inode ? h_inode->i_ino : 0);
18108 + /* WARN_ON(1); */
18113 + inode_mark = fsnotify_iter_inode_mark(iter_info);
18114 + AuDebugOn(!inode_mark);
18115 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
18116 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
18122 +static struct fsnotify_ops au_hfsn_ops = {
18123 + .handle_event = au_hfsn_handle_event,
18124 + .free_group_priv = au_hfsn_free_group,
18125 + .free_mark = au_hfsn_free_mark
18128 +/* ---------------------------------------------------------------------- */
18130 +static void au_hfsn_fin_br(struct au_branch *br)
18132 + struct au_br_hfsnotify *hfsn;
18134 + hfsn = br->br_hfsn;
18137 + fsnotify_put_group(hfsn->hfsn_group);
18142 +static int au_hfsn_init_br(struct au_branch *br, int perm)
18145 + struct fsnotify_group *group;
18146 + struct au_br_hfsnotify *hfsn;
18149 + br->br_hfsn = NULL;
18150 + if (!au_br_hnotifyable(perm))
18154 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
18155 + if (unlikely(!hfsn))
18159 + group = fsnotify_alloc_group(&au_hfsn_ops,
18160 + /*flags - not for userspace*/0);
18161 + if (IS_ERR(group)) {
18162 + err = PTR_ERR(group);
18163 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
18167 + group->private = hfsn;
18168 + hfsn->hfsn_group = group;
18169 + br->br_hfsn = hfsn;
18170 + goto out; /* success */
18173 + au_kfree_try_rcu(hfsn);
18178 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
18183 + if (!br->br_hfsn)
18184 + err = au_hfsn_init_br(br, perm);
18189 +/* ---------------------------------------------------------------------- */
18191 +static void au_hfsn_fin(void)
18193 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
18194 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
18197 +const struct au_hnotify_op au_hnotify_op = {
18198 + .ctl = au_hfsn_ctl,
18199 + .alloc = au_hfsn_alloc,
18200 + .free = au_hfsn_free,
18202 + .fin = au_hfsn_fin,
18204 + .reset_br = au_hfsn_reset_br,
18205 + .fin_br = au_hfsn_fin_br,
18206 + .init_br = au_hfsn_init_br
18208 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
18209 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
18210 +++ linux/fs/aufs/hfsplus.c 2022-11-05 23:02:18.965889284 +0100
18212 +// SPDX-License-Identifier: GPL-2.0
18214 + * Copyright (C) 2010-2022 Junjiro R. Okajima
18216 + * This program is free software; you can redistribute it and/or modify
18217 + * it under the terms of the GNU General Public License as published by
18218 + * the Free Software Foundation; either version 2 of the License, or
18219 + * (at your option) any later version.
18221 + * This program is distributed in the hope that it will be useful,
18222 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18223 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18224 + * GNU General Public License for more details.
18226 + * You should have received a copy of the GNU General Public License
18227 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18231 + * special support for filesystems which acquires an inode mutex
18232 + * at final closing a file, eg, hfsplus.
18234 + * This trick is very simple and stupid, just to open the file before really
18235 + * necessary open to tell hfsplus that this is not the final closing.
18236 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
18237 + * and au_h_open_post() after releasing it.
18242 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
18245 + struct file *h_file;
18246 + struct dentry *h_dentry;
18248 + h_dentry = au_h_dptr(dentry, bindex);
18249 + AuDebugOn(!h_dentry);
18250 + AuDebugOn(d_is_negative(h_dentry));
18253 + if (au_test_hfsplus(h_dentry->d_sb)
18254 + && d_is_reg(h_dentry))
18255 + h_file = au_h_open(dentry, bindex,
18256 + O_RDONLY | O_NOATIME | O_LARGEFILE,
18257 + /*file*/NULL, force_wr);
18261 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
18262 + struct file *h_file)
18264 + struct au_branch *br;
18268 + br = au_sbr(dentry->d_sb, bindex);
18269 + au_lcnt_dec(&br->br_nfiles);
18272 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
18273 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
18274 +++ linux/fs/aufs/hnotify.c 2022-11-05 23:02:18.965889284 +0100
18276 +// SPDX-License-Identifier: GPL-2.0
18278 + * Copyright (C) 2005-2022 Junjiro R. Okajima
18280 + * This program is free software; you can redistribute it and/or modify
18281 + * it under the terms of the GNU General Public License as published by
18282 + * the Free Software Foundation; either version 2 of the License, or
18283 + * (at your option) any later version.
18285 + * This program is distributed in the hope that it will be useful,
18286 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18287 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18288 + * GNU General Public License for more details.
18290 + * You should have received a copy of the GNU General Public License
18291 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18295 + * abstraction to notify the direct changes on lower directories
18298 +/* #include <linux/iversion.h> */
18301 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
18304 + struct au_hnotify *hn;
18307 + hn = au_cache_alloc_hnotify();
18309 + hn->hn_aufs_inode = inode;
18310 + hinode->hi_notify = hn;
18311 + err = au_hnotify_op.alloc(hinode);
18313 + if (unlikely(err)) {
18314 + hinode->hi_notify = NULL;
18315 + au_cache_free_hnotify(hn);
18317 + * The upper dir was removed by udba, but the same named
18318 + * dir left. In this case, aufs assigns a new inode
18319 + * number and set the monitor again.
18320 + * For the lower dir, the old monitor is still left.
18322 + if (err == -EEXIST)
18331 +void au_hn_free(struct au_hinode *hinode)
18333 + struct au_hnotify *hn;
18335 + hn = hinode->hi_notify;
18337 + hinode->hi_notify = NULL;
18338 + if (au_hnotify_op.free(hinode, hn))
18339 + au_cache_free_hnotify(hn);
18343 +/* ---------------------------------------------------------------------- */
18345 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
18347 + if (hinode->hi_notify)
18348 + au_hnotify_op.ctl(hinode, do_set);
18351 +void au_hn_reset(struct inode *inode, unsigned int flags)
18353 + aufs_bindex_t bindex, bbot;
18354 + struct inode *hi;
18355 + struct dentry *iwhdentry;
18357 + bbot = au_ibbot(inode);
18358 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18359 + hi = au_h_iptr(inode, bindex);
18363 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
18364 + iwhdentry = au_hi_wh(inode, bindex);
18368 + au_set_h_iptr(inode, bindex, NULL, 0);
18369 + au_set_h_iptr(inode, bindex, au_igrab(hi),
18370 + flags & ~AuHi_XINO);
18373 + /* inode_unlock(hi); */
18377 +/* ---------------------------------------------------------------------- */
18379 +static int hn_xino(struct inode *inode, struct inode *h_inode)
18382 + aufs_bindex_t bindex, bbot, bfound, btop;
18383 + struct inode *h_i;
18386 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18387 + pr_warn("branch root dir was changed\n");
18392 + bbot = au_ibbot(inode);
18393 + btop = au_ibtop(inode);
18394 +#if 0 /* reserved for future use */
18395 + if (bindex == bbot) {
18396 + /* keep this ino in rename case */
18400 + for (bindex = btop; bindex <= bbot; bindex++)
18401 + if (au_h_iptr(inode, bindex) == h_inode) {
18408 + for (bindex = btop; bindex <= bbot; bindex++) {
18409 + h_i = au_h_iptr(inode, bindex);
18413 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
18414 + /* ignore this error */
18415 + /* bad action? */
18418 + /* children inode number will be broken */
18425 +static int hn_gen_tree(struct dentry *dentry)
18427 + int err, i, j, ndentry;
18428 + struct au_dcsub_pages dpages;
18429 + struct au_dpage *dpage;
18430 + struct dentry **dentries;
18432 + err = au_dpages_init(&dpages, GFP_NOFS);
18433 + if (unlikely(err))
18435 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
18436 + if (unlikely(err))
18439 + for (i = 0; i < dpages.ndpage; i++) {
18440 + dpage = dpages.dpages + i;
18441 + dentries = dpage->dentries;
18442 + ndentry = dpage->ndentry;
18443 + for (j = 0; j < ndentry; j++) {
18444 + struct dentry *d;
18451 + if (d_really_is_positive(d))
18452 + /* todo: reset children xino?
18453 + cached children only? */
18454 + au_iigen_dec(d_inode(d));
18459 + au_dpages_free(&dpages);
18465 + * return 0 if processed.
18467 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
18468 + const unsigned int isdir)
18471 + struct dentry *d;
18472 + struct qstr *dname;
18475 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18476 + pr_warn("branch root dir was changed\n");
18482 + AuDebugOn(!name);
18483 + au_iigen_dec(inode);
18484 + spin_lock(&inode->i_lock);
18485 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
18486 + spin_lock(&d->d_lock);
18487 + dname = &d->d_name;
18488 + if (dname->len != nlen
18489 + && memcmp(dname->name, name, nlen)) {
18490 + spin_unlock(&d->d_lock);
18495 + spin_unlock(&d->d_lock);
18498 + spin_unlock(&inode->i_lock);
18500 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
18501 + d = d_find_any_alias(inode);
18503 + au_iigen_dec(inode);
18507 + spin_lock(&d->d_lock);
18508 + dname = &d->d_name;
18509 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
18510 + spin_unlock(&d->d_lock);
18511 + err = hn_gen_tree(d);
18512 + spin_lock(&d->d_lock);
18514 + spin_unlock(&d->d_lock);
18523 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
18527 + if (IS_ROOT(dentry)) {
18528 + pr_warn("branch root dir was changed\n");
18534 + au_digen_dec(dentry);
18535 + if (d_really_is_positive(dentry))
18536 + au_iigen_dec(d_inode(dentry));
18538 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
18539 + if (d_really_is_positive(dentry))
18540 + err = hn_gen_tree(dentry);
18547 +/* ---------------------------------------------------------------------- */
18549 +/* hnotify job flags */
18550 +#define AuHnJob_XINO0 1
18551 +#define AuHnJob_GEN (1 << 1)
18552 +#define AuHnJob_DIRENT (1 << 2)
18553 +#define AuHnJob_ISDIR (1 << 3)
18554 +#define AuHnJob_TRYXINO0 (1 << 4)
18555 +#define AuHnJob_MNTPNT (1 << 5)
18556 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
18557 +#define au_fset_hnjob(flags, name) \
18558 + do { (flags) |= AuHnJob_##name; } while (0)
18559 +#define au_fclr_hnjob(flags, name) \
18560 + do { (flags) &= ~AuHnJob_##name; } while (0)
18568 +struct au_hnotify_args {
18569 + struct inode *h_dir, *dir, *h_child_inode;
18571 + unsigned int flags[AuHnLast];
18572 + unsigned int h_child_nlen;
18573 + char h_child_name[];
18576 +struct hn_job_args {
18577 + unsigned int flags;
18578 + struct inode *inode, *h_inode, *dir, *h_dir;
18579 + struct dentry *dentry;
18584 +static int hn_job(struct hn_job_args *a)
18586 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
18590 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
18591 + hn_xino(a->inode, a->h_inode); /* ignore this error */
18593 + if (au_ftest_hnjob(a->flags, TRYXINO0)
18596 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
18597 + if (!a->h_inode->i_nlink
18598 + && !(a->h_inode->i_state & I_LINKABLE))
18599 + hn_xino(a->inode, a->h_inode); /* ignore this error */
18600 + inode_unlock_shared(a->h_inode);
18603 + /* make the generation obsolete */
18604 + if (au_ftest_hnjob(a->flags, GEN)) {
18607 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
18609 + if (e && a->dentry)
18610 + hn_gen_by_name(a->dentry, isdir);
18611 + /* ignore this error */
18614 + /* make dir entries obsolete */
18615 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
18616 + struct au_vdir *vdir;
18618 + vdir = au_ivdir(a->inode);
18620 + vdir->vd_jiffy = 0;
18621 + /* IMustLock(a->inode); */
18622 + /* inode_inc_iversion(a->inode); */
18625 + /* can do nothing but warn */
18626 + if (au_ftest_hnjob(a->flags, MNTPNT)
18628 + && d_mountpoint(a->dentry))
18629 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
18634 +/* ---------------------------------------------------------------------- */
18636 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
18637 + struct inode *dir)
18639 + struct dentry *dentry, *d, *parent;
18640 + struct qstr *dname;
18642 + parent = d_find_any_alias(dir);
18647 + spin_lock(&parent->d_lock);
18648 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
18649 + /* AuDbg("%pd\n", d); */
18650 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
18651 + dname = &d->d_name;
18652 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
18653 + goto cont_unlock;
18657 + goto cont_unlock;
18658 + if (au_dcount(d) > 0) {
18659 + dentry = dget_dlock(d);
18660 + spin_unlock(&d->d_lock);
18665 + spin_unlock(&d->d_lock);
18667 + spin_unlock(&parent->d_lock);
18671 + di_write_lock_child(dentry);
18676 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
18677 + aufs_bindex_t bindex, ino_t h_ino)
18679 + struct inode *inode;
18684 + err = au_xino_read(sb, bindex, h_ino, &ino);
18686 + inode = ilookup(sb, ino);
18690 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18691 + pr_warn("wrong root branch\n");
18697 + ii_write_lock_child(inode);
18703 +static void au_hn_bh(void *_args)
18705 + struct au_hnotify_args *a = _args;
18706 + struct super_block *sb;
18707 + aufs_bindex_t bindex, bbot, bfound;
18708 + unsigned char xino, try_iput;
18710 + struct inode *inode;
18712 + struct hn_job_args args;
18713 + struct dentry *dentry;
18714 + struct au_sbinfo *sbinfo;
18716 + AuDebugOn(!_args);
18717 + AuDebugOn(!a->h_dir);
18718 + AuDebugOn(!a->dir);
18719 + AuDebugOn(!a->mask);
18720 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
18721 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
18722 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
18727 + * do not lock a->dir->i_mutex here
18728 + * because of d_revalidate() may cause a deadlock.
18730 + sb = a->dir->i_sb;
18732 + sbinfo = au_sbi(sb);
18733 + AuDebugOn(!sbinfo);
18734 + si_write_lock(sb, AuLock_NOPLMW);
18736 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
18737 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
18738 + case FS_MOVED_FROM:
18739 + case FS_MOVED_TO:
18740 + AuWarn1("DIRREN with UDBA may not work correctly "
18741 + "for the direct rename(2)\n");
18744 + ii_read_lock_parent(a->dir);
18746 + bbot = au_ibbot(a->dir);
18747 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
18748 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
18752 + ii_read_unlock(a->dir);
18753 + if (unlikely(bfound < 0))
18756 + xino = !!au_opt_test(au_mntflags(sb), XINO);
18758 + if (a->h_child_inode)
18759 + h_ino = a->h_child_inode->i_ino;
18761 + if (a->h_child_nlen
18762 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
18763 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
18764 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
18767 + if (dentry && d_really_is_positive(dentry))
18768 + inode = d_inode(dentry);
18769 + if (xino && !inode && h_ino
18770 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
18771 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
18772 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
18773 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
18777 + args.flags = a->flags[AuHn_CHILD];
18778 + args.dentry = dentry;
18779 + args.inode = inode;
18780 + args.h_inode = a->h_child_inode;
18781 + args.dir = a->dir;
18782 + args.h_dir = a->h_dir;
18783 + args.h_name = a->h_child_name;
18784 + args.h_nlen = a->h_child_nlen;
18785 + err = hn_job(&args);
18787 + if (au_di(dentry))
18788 + di_write_unlock(dentry);
18791 + if (inode && try_iput) {
18792 + ii_write_unlock(inode);
18796 + ii_write_lock_parent(a->dir);
18797 + args.flags = a->flags[AuHn_PARENT];
18798 + args.dentry = NULL;
18799 + args.inode = a->dir;
18800 + args.h_inode = a->h_dir;
18802 + args.h_dir = NULL;
18803 + args.h_name = NULL;
18805 + err = hn_job(&args);
18806 + ii_write_unlock(a->dir);
18809 + iput(a->h_child_inode);
18812 + si_write_unlock(sb);
18813 + au_nwt_done(&sbinfo->si_nowait);
18817 +/* ---------------------------------------------------------------------- */
18819 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
18820 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
18823 + unsigned int flags[AuHnLast], f;
18824 + unsigned char isdir, isroot, wh;
18825 + struct inode *dir;
18826 + struct au_hnotify_args *args;
18827 + char *p, *h_child_name;
18830 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
18831 + dir = igrab(hnotify->hn_aufs_inode);
18835 + isroot = (dir->i_ino == AUFS_ROOT_INO);
18837 + h_child_name = (void *)h_child_qstr->name;
18838 + len = h_child_qstr->len;
18839 + if (h_child_name) {
18840 + if (len > AUFS_WH_PFX_LEN
18841 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
18842 + h_child_name += AUFS_WH_PFX_LEN;
18843 + len -= AUFS_WH_PFX_LEN;
18849 + if (h_child_inode)
18850 + isdir = !!S_ISDIR(h_child_inode->i_mode);
18851 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
18852 + flags[AuHn_CHILD] = 0;
18854 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
18855 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
18856 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
18857 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
18858 + case FS_MOVED_FROM:
18859 + case FS_MOVED_TO:
18860 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
18861 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
18864 + AuDebugOn(!h_child_name);
18869 + * aufs never be able to get this child inode.
18870 + * revalidation should be in d_revalidate()
18871 + * by checking i_nlink, i_generation or d_unhashed().
18873 + AuDebugOn(!h_child_name);
18874 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
18875 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
18883 + h_child_inode = NULL;
18886 + /* iput() and kfree() will be called in au_hnotify() */
18887 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
18888 + if (unlikely(!args)) {
18889 + AuErr1("no memory\n");
18893 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
18894 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
18895 + args->mask = mask;
18897 + args->h_dir = igrab(h_dir);
18898 + if (h_child_inode)
18899 + h_child_inode = igrab(h_child_inode); /* can be NULL */
18900 + args->h_child_inode = h_child_inode;
18901 + args->h_child_nlen = len;
18903 + p = (void *)args;
18904 + p += sizeof(*args);
18905 + memcpy(p, h_child_name, len);
18909 + /* NFS fires the event for silly-renamed one from kworker */
18911 + if (!dir->i_nlink
18912 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
18914 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
18915 + if (unlikely(err)) {
18916 + pr_err("wkq %d\n", err);
18917 + iput(args->h_child_inode);
18918 + iput(args->h_dir);
18920 + au_kfree_rcu(args);
18927 +/* ---------------------------------------------------------------------- */
18929 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
18933 + AuDebugOn(!(udba & AuOptMask_UDBA));
18936 + if (au_hnotify_op.reset_br)
18937 + err = au_hnotify_op.reset_br(udba, br, perm);
18942 +int au_hnotify_init_br(struct au_branch *br, int perm)
18947 + if (au_hnotify_op.init_br)
18948 + err = au_hnotify_op.init_br(br, perm);
18953 +void au_hnotify_fin_br(struct au_branch *br)
18955 + if (au_hnotify_op.fin_br)
18956 + au_hnotify_op.fin_br(br);
18959 +static void au_hn_destroy_cache(void)
18961 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
18962 + au_cache[AuCache_HNOTIFY] = NULL;
18965 +int __init au_hnotify_init(void)
18970 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
18971 + if (au_cache[AuCache_HNOTIFY]) {
18973 + if (au_hnotify_op.init)
18974 + err = au_hnotify_op.init();
18975 + if (unlikely(err))
18976 + au_hn_destroy_cache();
18982 +void au_hnotify_fin(void)
18984 + if (au_hnotify_op.fin)
18985 + au_hnotify_op.fin();
18987 + /* cf. au_cache_fin() */
18988 + if (au_cache[AuCache_HNOTIFY])
18989 + au_hn_destroy_cache();
18991 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
18992 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
18993 +++ linux/fs/aufs/iinfo.c 2022-11-05 23:02:18.965889284 +0100
18995 +// SPDX-License-Identifier: GPL-2.0
18997 + * Copyright (C) 2005-2022 Junjiro R. Okajima
18999 + * This program is free software; you can redistribute it and/or modify
19000 + * it under the terms of the GNU General Public License as published by
19001 + * the Free Software Foundation; either version 2 of the License, or
19002 + * (at your option) any later version.
19004 + * This program is distributed in the hope that it will be useful,
19005 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19006 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19007 + * GNU General Public License for more details.
19009 + * You should have received a copy of the GNU General Public License
19010 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19014 + * inode private data
19019 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
19021 + struct inode *h_inode;
19022 + struct au_hinode *hinode;
19024 + IiMustAnyLock(inode);
19026 + hinode = au_hinode(au_ii(inode), bindex);
19027 + h_inode = hinode->hi_inode;
19028 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19032 +/* todo: hard/soft set? */
19033 +void au_hiput(struct au_hinode *hinode)
19035 + au_hn_free(hinode);
19036 + dput(hinode->hi_whdentry);
19037 + iput(hinode->hi_inode);
19040 +unsigned int au_hi_flags(struct inode *inode, int isdir)
19042 + unsigned int flags;
19043 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
19046 + if (au_opt_test(mnt_flags, XINO))
19047 + au_fset_hi(flags, XINO);
19048 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
19049 + au_fset_hi(flags, HNOTIFY);
19053 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19054 + struct inode *h_inode, unsigned int flags)
19056 + struct au_hinode *hinode;
19057 + struct inode *hi;
19058 + struct au_iinfo *iinfo = au_ii(inode);
19060 + IiMustWriteLock(inode);
19062 + hinode = au_hinode(iinfo, bindex);
19063 + hi = hinode->hi_inode;
19064 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19067 + au_hiput(hinode);
19068 + hinode->hi_inode = h_inode;
19071 + struct super_block *sb = inode->i_sb;
19072 + struct au_branch *br;
19074 + AuDebugOn(inode->i_mode
19075 + && (h_inode->i_mode & S_IFMT)
19076 + != (inode->i_mode & S_IFMT));
19077 + if (bindex == iinfo->ii_btop)
19078 + au_cpup_igen(inode, h_inode);
19079 + br = au_sbr(sb, bindex);
19080 + hinode->hi_id = br->br_id;
19081 + if (au_ftest_hi(flags, XINO)) {
19082 + err = au_xino_write(sb, bindex, h_inode->i_ino,
19084 + if (unlikely(err))
19085 + AuIOErr1("failed au_xino_write() %d\n", err);
19088 + if (au_ftest_hi(flags, HNOTIFY)
19089 + && au_br_hnotifyable(br->br_perm)) {
19090 + err = au_hn_alloc(hinode, inode);
19091 + if (unlikely(err))
19092 + AuIOErr1("au_hn_alloc() %d\n", err);
19097 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19098 + struct dentry *h_wh)
19100 + struct au_hinode *hinode;
19102 + IiMustWriteLock(inode);
19104 + hinode = au_hinode(au_ii(inode), bindex);
19105 + AuDebugOn(hinode->hi_whdentry);
19106 + hinode->hi_whdentry = h_wh;
19109 +void au_update_iigen(struct inode *inode, int half)
19111 + struct au_iinfo *iinfo;
19112 + struct au_iigen *iigen;
19113 + unsigned int sigen;
19115 + sigen = au_sigen(inode->i_sb);
19116 + iinfo = au_ii(inode);
19117 + iigen = &iinfo->ii_generation;
19118 + spin_lock(&iigen->ig_spin);
19119 + iigen->ig_generation = sigen;
19121 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
19123 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
19124 + spin_unlock(&iigen->ig_spin);
19127 +/* it may be called at remount time, too */
19128 +void au_update_ibrange(struct inode *inode, int do_put_zero)
19130 + struct au_iinfo *iinfo;
19131 + aufs_bindex_t bindex, bbot;
19133 + AuDebugOn(au_is_bad_inode(inode));
19134 + IiMustWriteLock(inode);
19136 + iinfo = au_ii(inode);
19137 + if (do_put_zero && iinfo->ii_btop >= 0) {
19138 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
19140 + struct inode *h_i;
19142 + h_i = au_hinode(iinfo, bindex)->hi_inode;
19145 + && !(h_i->i_state & I_LINKABLE))
19146 + au_set_h_iptr(inode, bindex, NULL, 0);
19150 + iinfo->ii_btop = -1;
19151 + iinfo->ii_bbot = -1;
19152 + bbot = au_sbbot(inode->i_sb);
19153 + for (bindex = 0; bindex <= bbot; bindex++)
19154 + if (au_hinode(iinfo, bindex)->hi_inode) {
19155 + iinfo->ii_btop = bindex;
19158 + if (iinfo->ii_btop >= 0)
19159 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
19160 + if (au_hinode(iinfo, bindex)->hi_inode) {
19161 + iinfo->ii_bbot = bindex;
19164 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
19167 +/* ---------------------------------------------------------------------- */
19169 +void au_icntnr_init_once(void *_c)
19171 + struct au_icntnr *c = _c;
19172 + struct au_iinfo *iinfo = &c->iinfo;
19174 + spin_lock_init(&iinfo->ii_generation.ig_spin);
19175 + au_rw_init(&iinfo->ii_rwsem);
19176 + inode_init_once(&c->vfs_inode);
19179 +void au_hinode_init(struct au_hinode *hinode)
19181 + hinode->hi_inode = NULL;
19182 + hinode->hi_id = -1;
19183 + au_hn_init(hinode);
19184 + hinode->hi_whdentry = NULL;
19187 +int au_iinfo_init(struct inode *inode)
19189 + struct au_iinfo *iinfo;
19190 + struct super_block *sb;
19191 + struct au_hinode *hi;
19194 + sb = inode->i_sb;
19195 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19196 + nbr = au_sbbot(sb) + 1;
19197 + if (unlikely(nbr <= 0))
19199 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
19201 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
19203 + iinfo->ii_hinode = hi;
19204 + for (i = 0; i < nbr; i++, hi++)
19205 + au_hinode_init(hi);
19207 + iinfo->ii_generation.ig_generation = au_sigen(sb);
19208 + iinfo->ii_btop = -1;
19209 + iinfo->ii_bbot = -1;
19210 + iinfo->ii_vdir = NULL;
19216 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
19219 + struct au_hinode *hip;
19221 + AuRwMustWriteLock(&iinfo->ii_rwsem);
19224 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
19227 + iinfo->ii_hinode = hip;
19228 + i = iinfo->ii_bbot + 1;
19230 + for (; i < nbr; i++, hip++)
19231 + au_hinode_init(hip);
19238 +void au_iinfo_fin(struct inode *inode)
19240 + struct au_iinfo *iinfo;
19241 + struct au_hinode *hi;
19242 + struct super_block *sb;
19243 + aufs_bindex_t bindex, bbot;
19244 + const unsigned char unlinked = !inode->i_nlink;
19246 + AuDebugOn(au_is_bad_inode(inode));
19248 + sb = inode->i_sb;
19249 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
19250 + if (si_pid_test(sb))
19251 + au_xino_delete_inode(inode, unlinked);
19254 + * it is safe to hide the dependency between sbinfo and
19258 + si_noflush_read_lock(sb);
19259 + au_xino_delete_inode(inode, unlinked);
19260 + si_read_unlock(sb);
19264 + iinfo = au_ii(inode);
19265 + if (iinfo->ii_vdir)
19266 + au_vdir_free(iinfo->ii_vdir);
19268 + bindex = iinfo->ii_btop;
19269 + if (bindex >= 0) {
19270 + hi = au_hinode(iinfo, bindex);
19271 + bbot = iinfo->ii_bbot;
19272 + while (bindex++ <= bbot) {
19273 + if (hi->hi_inode)
19278 + au_kfree_rcu(iinfo->ii_hinode);
19279 + AuRwDestroy(&iinfo->ii_rwsem);
19281 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
19282 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
19283 +++ linux/fs/aufs/inode.c 2022-11-05 23:02:18.965889284 +0100
19285 +// SPDX-License-Identifier: GPL-2.0
19287 + * Copyright (C) 2005-2022 Junjiro R. Okajima
19289 + * This program is free software; you can redistribute it and/or modify
19290 + * it under the terms of the GNU General Public License as published by
19291 + * the Free Software Foundation; either version 2 of the License, or
19292 + * (at your option) any later version.
19294 + * This program is distributed in the hope that it will be useful,
19295 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19296 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19297 + * GNU General Public License for more details.
19299 + * You should have received a copy of the GNU General Public License
19300 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19304 + * inode functions
19307 +#include <linux/iversion.h>
19310 +struct inode *au_igrab(struct inode *inode)
19313 + AuDebugOn(!atomic_read(&inode->i_count));
19319 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
19321 + au_cpup_attr_all(inode, /*force*/0);
19322 + au_update_iigen(inode, /*half*/1);
19324 + inode_inc_iversion(inode);
19327 +static int au_ii_refresh(struct inode *inode, int *update)
19331 + aufs_bindex_t bindex, new_bindex;
19332 + struct super_block *sb;
19333 + struct au_iinfo *iinfo;
19334 + struct au_hinode *p, *q, tmp;
19336 + AuDebugOn(au_is_bad_inode(inode));
19337 + IiMustWriteLock(inode);
19340 + sb = inode->i_sb;
19341 + nbr = au_sbbot(sb) + 1;
19342 + type = inode->i_mode & S_IFMT;
19343 + iinfo = au_ii(inode);
19344 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
19345 + if (unlikely(err))
19348 + AuDebugOn(iinfo->ii_btop < 0);
19349 + p = au_hinode(iinfo, iinfo->ii_btop);
19350 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
19352 + if (!p->hi_inode)
19355 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
19356 + new_bindex = au_br_index(sb, p->hi_id);
19357 + if (new_bindex == bindex)
19360 + if (new_bindex < 0) {
19363 + p->hi_inode = NULL;
19367 + if (new_bindex < iinfo->ii_btop)
19368 + iinfo->ii_btop = new_bindex;
19369 + if (iinfo->ii_bbot < new_bindex)
19370 + iinfo->ii_bbot = new_bindex;
19371 + /* swap two lower inode, and loop again */
19372 + q = au_hinode(iinfo, new_bindex);
19376 + if (tmp.hi_inode) {
19381 + au_update_ibrange(inode, /*do_put_zero*/0);
19382 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
19383 + e = au_dy_irefresh(inode);
19384 + if (unlikely(e && !err))
19392 +void au_refresh_iop(struct inode *inode, int force_getattr)
19395 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
19396 + const struct inode_operations *iop
19397 + = force_getattr ? aufs_iop : sbi->si_iop_array;
19399 + if (inode->i_op == iop)
19402 + switch (inode->i_mode & S_IFMT) {
19404 + type = AuIop_DIR;
19407 + type = AuIop_SYMLINK;
19410 + type = AuIop_OTHER;
19414 + inode->i_op = iop + type;
19415 + /* unnecessary smp_wmb() */
19418 +int au_refresh_hinode_self(struct inode *inode)
19422 + err = au_ii_refresh(inode, &update);
19424 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
19430 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
19432 + int err, e, update;
19433 + unsigned int flags;
19435 + aufs_bindex_t bindex, bbot;
19436 + unsigned char isdir;
19437 + struct au_hinode *p;
19438 + struct au_iinfo *iinfo;
19440 + err = au_ii_refresh(inode, &update);
19441 + if (unlikely(err))
19445 + iinfo = au_ii(inode);
19446 + p = au_hinode(iinfo, iinfo->ii_btop);
19447 + mode = (inode->i_mode & S_IFMT);
19448 + isdir = S_ISDIR(mode);
19449 + flags = au_hi_flags(inode, isdir);
19450 + bbot = au_dbbot(dentry);
19451 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
19452 + struct inode *h_i, *h_inode;
19453 + struct dentry *h_d;
19455 + h_d = au_h_dptr(dentry, bindex);
19456 + if (!h_d || d_is_negative(h_d))
19459 + h_inode = d_inode(h_d);
19460 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
19461 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
19462 + h_i = au_h_iptr(inode, bindex);
19464 + if (h_i == h_inode)
19470 + if (bindex < iinfo->ii_btop)
19471 + iinfo->ii_btop = bindex;
19472 + if (iinfo->ii_bbot < bindex)
19473 + iinfo->ii_bbot = bindex;
19474 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
19477 + au_update_ibrange(inode, /*do_put_zero*/0);
19478 + e = au_dy_irefresh(inode);
19479 + if (unlikely(e && !err))
19482 + au_refresh_hinode_attr(inode, update && isdir);
19489 +static int set_inode(struct inode *inode, struct dentry *dentry)
19492 + unsigned int flags;
19494 + aufs_bindex_t bindex, btop, btail;
19495 + unsigned char isdir;
19496 + struct dentry *h_dentry;
19497 + struct inode *h_inode;
19498 + struct au_iinfo *iinfo;
19499 + const struct inode_operations *iop;
19501 + IiMustWriteLock(inode);
19505 + iop = au_sbi(inode->i_sb)->si_iop_array;
19506 + btop = au_dbtop(dentry);
19507 + h_dentry = au_h_dptr(dentry, btop);
19508 + h_inode = d_inode(h_dentry);
19509 + mode = h_inode->i_mode;
19510 + switch (mode & S_IFMT) {
19512 + btail = au_dbtail(dentry);
19513 + inode->i_op = iop + AuIop_OTHER;
19514 + inode->i_fop = &aufs_file_fop;
19515 + err = au_dy_iaop(inode, btop, h_inode);
19516 + if (unlikely(err))
19521 + btail = au_dbtaildir(dentry);
19522 + inode->i_op = iop + AuIop_DIR;
19523 + inode->i_fop = &aufs_dir_fop;
19526 + btail = au_dbtail(dentry);
19527 + inode->i_op = iop + AuIop_SYMLINK;
19533 + btail = au_dbtail(dentry);
19534 + inode->i_op = iop + AuIop_OTHER;
19535 + init_special_inode(inode, mode, h_inode->i_rdev);
19538 + AuIOErr("Unknown file type 0%o\n", mode);
19543 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
19544 + flags = au_hi_flags(inode, isdir);
19545 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
19546 + && au_ftest_hi(flags, HNOTIFY)
19547 + && dentry->d_name.len > AUFS_WH_PFX_LEN
19548 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
19549 + au_fclr_hi(flags, HNOTIFY);
19550 + iinfo = au_ii(inode);
19551 + iinfo->ii_btop = btop;
19552 + iinfo->ii_bbot = btail;
19553 + for (bindex = btop; bindex <= btail; bindex++) {
19554 + h_dentry = au_h_dptr(dentry, bindex);
19556 + au_set_h_iptr(inode, bindex,
19557 + au_igrab(d_inode(h_dentry)), flags);
19559 + au_cpup_attr_all(inode, /*force*/1);
19561 + * to force calling aufs_get_acl() every time,
19562 + * do not call cache_no_acl() for aufs inode.
19570 + * successful returns with iinfo write_locked
19572 + * zero: success, matched
19573 + * plus: no error, but unmatched
19575 +static int reval_inode(struct inode *inode, struct dentry *dentry)
19578 + unsigned int gen, igflags;
19579 + aufs_bindex_t bindex, bbot;
19580 + struct inode *h_inode, *h_dinode;
19581 + struct dentry *h_dentry;
19584 + * before this function, if aufs got any iinfo lock, it must be only
19585 + * one, the parent dir.
19586 + * it can happen by UDBA and the obsoleted inode number.
19589 + if (unlikely(inode->i_ino == parent_ino(dentry)))
19593 + ii_write_lock_new_child(inode);
19594 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
19595 + h_dinode = d_inode(h_dentry);
19596 + bbot = au_ibbot(inode);
19597 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
19598 + h_inode = au_h_iptr(inode, bindex);
19599 + if (!h_inode || h_inode != h_dinode)
19603 + gen = au_iigen(inode, &igflags);
19604 + if (gen == au_digen(dentry)
19605 + && !au_ig_ftest(igflags, HALF_REFRESHED))
19608 + /* fully refresh inode using dentry */
19609 + err = au_refresh_hinode(inode, dentry);
19611 + au_update_iigen(inode, /*half*/0);
19615 + if (unlikely(err))
19616 + ii_write_unlock(inode);
19621 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19622 + unsigned int d_type, ino_t *ino)
19625 + const int isnondir = d_type != DT_DIR;
19627 + /* prevent hardlinked inode number from race condition */
19629 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
19630 + if (unlikely(err))
19634 + err = au_xino_read(sb, bindex, h_ino, ino);
19635 + if (unlikely(err))
19636 + goto out_xinondir;
19640 + *ino = au_xino_new_ino(sb);
19641 + if (unlikely(!*ino))
19642 + goto out_xinondir;
19643 + err = au_xino_write(sb, bindex, h_ino, *ino);
19644 + if (unlikely(err))
19645 + goto out_xinondir;
19649 + if (isnondir && idx >= 0)
19650 + au_xinondir_leave(sb, bindex, h_ino, idx);
19655 +/* successful returns with iinfo write_locked */
19656 +/* todo: return with unlocked? */
19657 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
19659 + struct inode *inode, *h_inode;
19660 + struct dentry *h_dentry;
19661 + struct super_block *sb;
19662 + ino_t h_ino, ino;
19663 + int err, idx, hlinked;
19664 + aufs_bindex_t btop;
19666 + sb = dentry->d_sb;
19667 + btop = au_dbtop(dentry);
19668 + h_dentry = au_h_dptr(dentry, btop);
19669 + h_inode = d_inode(h_dentry);
19670 + h_ino = h_inode->i_ino;
19671 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
19675 + * stop 'race'-ing between hardlinks under different
19679 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
19680 + inode = ERR_PTR(err);
19681 + if (unlikely(err))
19685 + err = au_xino_read(sb, btop, h_ino, &ino);
19686 + inode = ERR_PTR(err);
19687 + if (unlikely(err))
19688 + goto out_xinondir;
19691 + ino = au_xino_new_ino(sb);
19692 + if (unlikely(!ino)) {
19693 + inode = ERR_PTR(-EIO);
19694 + goto out_xinondir;
19698 + AuDbg("i%lu\n", (unsigned long)ino);
19699 + inode = au_iget_locked(sb, ino);
19700 + err = PTR_ERR(inode);
19701 + if (IS_ERR(inode))
19702 + goto out_xinondir;
19704 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
19705 + if (inode->i_state & I_NEW) {
19706 + ii_write_lock_new_child(inode);
19707 + err = set_inode(inode, dentry);
19709 + unlock_new_inode(inode);
19710 + goto out_xinondir; /* success */
19714 + * iget_failed() calls iput(), but we need to call
19715 + * ii_write_unlock() after iget_failed(). so dirty hack for
19718 + atomic_inc(&inode->i_count);
19719 + iget_failed(inode);
19720 + ii_write_unlock(inode);
19721 + au_xino_write(sb, btop, h_ino, /*ino*/0);
19722 + /* ignore this error */
19724 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
19726 + * horrible race condition between lookup, readdir and copyup
19727 + * (or something).
19729 + if (hlinked && idx >= 0)
19730 + au_xinondir_leave(sb, btop, h_ino, idx);
19731 + err = reval_inode(inode, dentry);
19732 + if (unlikely(err < 0)) {
19737 + goto out; /* success */
19738 + else if (hlinked && idx >= 0) {
19739 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
19740 + if (unlikely(err)) {
19742 + inode = ERR_PTR(err);
19748 + if (unlikely(au_test_fs_unique_ino(h_inode)))
19749 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
19750 + " b%d, %s, %pd, hi%lu, i%lu.\n",
19751 + btop, au_sbtype(h_dentry->d_sb), dentry,
19752 + (unsigned long)h_ino, (unsigned long)ino);
19754 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
19757 + if (hlinked && idx >= 0)
19758 + au_xinondir_leave(sb, btop, h_ino, idx);
19764 + inode = ERR_PTR(err);
19766 + if (hlinked && idx >= 0)
19767 + au_xinondir_leave(sb, btop, h_ino, idx);
19772 +/* ---------------------------------------------------------------------- */
19774 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19775 + struct inode *inode)
19778 + struct inode *hi;
19780 + err = au_br_rdonly(au_sbr(sb, bindex));
19782 + /* pseudo-link after flushed may happen out of bounds */
19785 + && au_ibtop(inode) <= bindex
19786 + && bindex <= au_ibbot(inode)) {
19788 + * permission check is unnecessary since vfsub routine
19789 + * will be called later
19791 + hi = au_h_iptr(inode, bindex);
19793 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
19799 +int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
19802 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
19804 + return inode_permission(h_userns, h_inode, mask);
19807 +int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
19810 + if (au_test_nfs(h_inode->i_sb)
19811 + && (mask & MAY_WRITE)
19812 + && S_ISDIR(h_inode->i_mode))
19813 + mask |= MAY_READ; /* force permission check */
19814 + return au_test_h_perm(h_userns, h_inode, mask);
19816 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
19817 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
19818 +++ linux/fs/aufs/inode.h 2022-12-17 09:21:34.799855195 +0100
19820 +/* SPDX-License-Identifier: GPL-2.0 */
19822 + * Copyright (C) 2005-2022 Junjiro R. Okajima
19824 + * This program is free software; you can redistribute it and/or modify
19825 + * it under the terms of the GNU General Public License as published by
19826 + * the Free Software Foundation; either version 2 of the License, or
19827 + * (at your option) any later version.
19829 + * This program is distributed in the hope that it will be useful,
19830 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19831 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19832 + * GNU General Public License for more details.
19834 + * You should have received a copy of the GNU General Public License
19835 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19839 + * inode operations
19842 +#ifndef __AUFS_INODE_H__
19843 +#define __AUFS_INODE_H__
19847 +#include <linux/fsnotify.h>
19848 +#include "rwsem.h"
19852 +struct au_hnotify {
19853 +#ifdef CONFIG_AUFS_HNOTIFY
19854 +#ifdef CONFIG_AUFS_HFSNOTIFY
19855 + /* never use fsnotify_add_vfsmount_mark() */
19856 + struct fsnotify_mark hn_mark;
19858 + struct inode *hn_aufs_inode; /* no get/put */
19859 + struct rcu_head rcu;
19861 +} ____cacheline_aligned_in_smp;
19863 +struct au_hinode {
19864 + struct inode *hi_inode;
19865 + aufs_bindex_t hi_id;
19866 +#ifdef CONFIG_AUFS_HNOTIFY
19867 + struct au_hnotify *hi_notify;
19870 + /* reference to the copied-up whiteout with get/put */
19871 + struct dentry *hi_whdentry;
19875 +#define AuIG_HALF_REFRESHED 1
19876 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
19877 +#define au_ig_fset(flags, name) \
19878 + do { (flags) |= AuIG_##name; } while (0)
19879 +#define au_ig_fclr(flags, name) \
19880 + do { (flags) &= ~AuIG_##name; } while (0)
19883 + spinlock_t ig_spin;
19884 + __u32 ig_generation, ig_flags;
19889 + struct au_iigen ii_generation;
19890 + struct super_block *ii_hsb1; /* no get/put */
19892 + struct au_rwsem ii_rwsem;
19893 + aufs_bindex_t ii_btop, ii_bbot;
19895 + struct au_hinode *ii_hinode;
19896 + struct au_vdir *ii_vdir;
19899 +struct au_icntnr {
19900 + struct au_iinfo iinfo;
19901 + struct inode vfs_inode;
19902 + struct hlist_bl_node plink;
19903 + struct rcu_head rcu;
19904 +} ____cacheline_aligned_in_smp;
19906 +/* au_pin flags */
19907 +#define AuPin_DI_LOCKED 1
19908 +#define AuPin_MNT_WRITE (1 << 1)
19909 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
19910 +#define au_fset_pin(flags, name) \
19911 + do { (flags) |= AuPin_##name; } while (0)
19912 +#define au_fclr_pin(flags, name) \
19913 + do { (flags) &= ~AuPin_##name; } while (0)
19917 + struct dentry *dentry;
19918 + unsigned int udba;
19919 + unsigned char lsc_di, lsc_hi, flags;
19920 + aufs_bindex_t bindex;
19923 + struct dentry *parent;
19924 + struct au_hinode *hdir;
19925 + struct vfsmount *h_mnt;
19927 + /* temporary unlock/relock for copyup */
19928 + struct dentry *h_dentry, *h_parent;
19929 + struct au_branch *br;
19930 + struct task_struct *task;
19933 +void au_pin_hdir_unlock(struct au_pin *p);
19934 +int au_pin_hdir_lock(struct au_pin *p);
19935 +int au_pin_hdir_relock(struct au_pin *p);
19936 +void au_pin_hdir_acquire_nest(struct au_pin *p);
19937 +void au_pin_hdir_release(struct au_pin *p);
19939 +/* ---------------------------------------------------------------------- */
19941 +static inline struct au_iinfo *au_ii(struct inode *inode)
19943 + BUG_ON(is_bad_inode(inode));
19944 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19947 +/* ---------------------------------------------------------------------- */
19950 +struct inode *au_igrab(struct inode *inode);
19951 +void au_refresh_iop(struct inode *inode, int force_getattr);
19952 +int au_refresh_hinode_self(struct inode *inode);
19953 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
19954 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19955 + unsigned int d_type, ino_t *ino);
19956 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
19957 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19958 + struct inode *inode);
19959 +int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
19961 +int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
19964 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
19965 + ino_t h_ino, unsigned int d_type, ino_t *ino)
19967 +#ifdef CONFIG_AUFS_SHWH
19968 + return au_ino(sb, bindex, h_ino, d_type, ino);
19981 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
19982 + aufs_iop_nogetattr[AuIop_Last];
19984 +/* au_wr_dir flags */
19985 +#define AuWrDir_ADD_ENTRY 1
19986 +#define AuWrDir_ISDIR (1 << 1)
19987 +#define AuWrDir_TMPFILE (1 << 2)
19988 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
19989 +#define au_fset_wrdir(flags, name) \
19990 + do { (flags) |= AuWrDir_##name; } while (0)
19991 +#define au_fclr_wrdir(flags, name) \
19992 + do { (flags) &= ~AuWrDir_##name; } while (0)
19994 +struct au_wr_dir_args {
19995 + aufs_bindex_t force_btgt;
19996 + unsigned char flags;
19998 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
19999 + struct au_wr_dir_args *args);
20001 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
20002 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
20003 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
20004 + unsigned int udba, unsigned char flags);
20005 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
20006 + unsigned int udba, unsigned char flags) __must_check;
20007 +int au_do_pin(struct au_pin *pin) __must_check;
20008 +void au_unpin(struct au_pin *pin);
20009 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
20011 +#define AuIcpup_DID_CPUP 1
20012 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
20013 +#define au_fset_icpup(flags, name) \
20014 + do { (flags) |= AuIcpup_##name; } while (0)
20015 +#define au_fclr_icpup(flags, name) \
20016 + do { (flags) &= ~AuIcpup_##name; } while (0)
20018 +struct au_icpup_args {
20019 + unsigned char flags;
20020 + unsigned char pin_flags;
20021 + aufs_bindex_t btgt;
20022 + unsigned int udba;
20023 + struct au_pin pin;
20024 + struct path h_path;
20025 + struct inode *h_inode;
20028 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
20029 + struct au_icpup_args *a);
20031 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
20032 + struct path *h_path, int locked);
20035 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20036 + struct dentry *h_parent, int isdir);
20037 +int aufs_mknod(struct user_namespace *userns, struct inode *dir,
20038 + struct dentry *dentry, umode_t mode, dev_t dev);
20039 +int aufs_symlink(struct user_namespace *userns, struct inode *dir,
20040 + struct dentry *dentry, const char *symname);
20041 +int aufs_create(struct user_namespace *userns, struct inode *dir,
20042 + struct dentry *dentry, umode_t mode, bool want_excl);
20043 +struct vfsub_aopen_args;
20044 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20045 + struct vfsub_aopen_args *args);
20046 +int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
20047 + struct file *file, umode_t mode);
20048 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20049 + struct dentry *dentry);
20050 +int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
20051 + struct dentry *dentry, umode_t mode);
20054 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
20055 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
20056 + struct dentry *h_parent, int isdir);
20057 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
20058 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
20061 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
20062 +int aufs_rename(struct user_namespace *userns,
20063 + struct inode *_src_dir, struct dentry *_src_dentry,
20064 + struct inode *_dst_dir, struct dentry *_dst_dentry,
20065 + unsigned int _flags);
20068 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
20069 +void au_hiput(struct au_hinode *hinode);
20070 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
20071 + struct dentry *h_wh);
20072 +unsigned int au_hi_flags(struct inode *inode, int isdir);
20074 +/* hinode flags */
20075 +#define AuHi_XINO 1
20076 +#define AuHi_HNOTIFY (1 << 1)
20077 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
20078 +#define au_fset_hi(flags, name) \
20079 + do { (flags) |= AuHi_##name; } while (0)
20080 +#define au_fclr_hi(flags, name) \
20081 + do { (flags) &= ~AuHi_##name; } while (0)
20083 +#ifndef CONFIG_AUFS_HNOTIFY
20084 +#undef AuHi_HNOTIFY
20085 +#define AuHi_HNOTIFY 0
20088 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
20089 + struct inode *h_inode, unsigned int flags);
20091 +void au_update_iigen(struct inode *inode, int half);
20092 +void au_update_ibrange(struct inode *inode, int do_put_zero);
20094 +void au_icntnr_init_once(void *_c);
20095 +void au_hinode_init(struct au_hinode *hinode);
20096 +int au_iinfo_init(struct inode *inode);
20097 +void au_iinfo_fin(struct inode *inode);
20098 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
20100 +#ifdef CONFIG_PROC_FS
20102 +int au_plink_maint(struct super_block *sb, int flags);
20104 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
20105 +int au_plink_maint_enter(struct super_block *sb);
20106 +#ifdef CONFIG_AUFS_DEBUG
20107 +void au_plink_list(struct super_block *sb);
20109 +AuStubVoid(au_plink_list, struct super_block *sb)
20111 +int au_plink_test(struct inode *inode);
20112 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
20113 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
20114 + struct dentry *h_dentry);
20115 +void au_plink_put(struct super_block *sb, int verbose);
20116 +void au_plink_clean(struct super_block *sb, int verbose);
20117 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
20119 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
20120 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
20121 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
20122 +AuStubVoid(au_plink_list, struct super_block *sb);
20123 +AuStubInt0(au_plink_test, struct inode *inode);
20124 +AuStub(struct dentry *, au_plink_lkup, return NULL,
20125 + struct inode *inode, aufs_bindex_t bindex);
20126 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
20127 + struct dentry *h_dentry);
20128 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
20129 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
20130 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
20131 +#endif /* CONFIG_PROC_FS */
20133 +#ifdef CONFIG_AUFS_XATTR
20135 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
20136 + unsigned int verbose);
20137 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
20138 +void au_xattr_init(struct super_block *sb);
20140 +AuStubInt0(au_cpup_xattr, struct path *h_dst, struct path *h_src,
20141 + int ignore_flags, unsigned int verbose);
20142 +AuStubVoid(au_xattr_init, struct super_block *sb);
20145 +#ifdef CONFIG_FS_POSIX_ACL
20146 +struct posix_acl *aufs_get_acl(struct inode *inode, int type, bool rcu);
20147 +int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
20148 + struct posix_acl *acl, int type);
20151 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
20157 +struct au_sxattr {
20161 + const char *name;
20162 + const void *value;
20167 + struct posix_acl *acl;
20172 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
20173 + struct au_sxattr *arg);
20176 +/* ---------------------------------------------------------------------- */
20178 +/* lock subclass for iinfo */
20180 + AuLsc_II_CHILD, /* child first */
20181 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
20182 + AuLsc_II_CHILD3, /* copyup dirs */
20183 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
20184 + AuLsc_II_PARENT2,
20185 + AuLsc_II_PARENT3, /* copyup dirs */
20186 + AuLsc_II_NEW_CHILD
20190 + * ii_read_lock_child, ii_write_lock_child,
20191 + * ii_read_lock_child2, ii_write_lock_child2,
20192 + * ii_read_lock_child3, ii_write_lock_child3,
20193 + * ii_read_lock_parent, ii_write_lock_parent,
20194 + * ii_read_lock_parent2, ii_write_lock_parent2,
20195 + * ii_read_lock_parent3, ii_write_lock_parent3,
20196 + * ii_read_lock_new_child, ii_write_lock_new_child,
20198 +#define AuReadLockFunc(name, lsc) \
20199 +static inline void ii_read_lock_##name(struct inode *i) \
20201 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20204 +#define AuWriteLockFunc(name, lsc) \
20205 +static inline void ii_write_lock_##name(struct inode *i) \
20207 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20210 +#define AuRWLockFuncs(name, lsc) \
20211 + AuReadLockFunc(name, lsc) \
20212 + AuWriteLockFunc(name, lsc)
20214 +AuRWLockFuncs(child, CHILD);
20215 +AuRWLockFuncs(child2, CHILD2);
20216 +AuRWLockFuncs(child3, CHILD3);
20217 +AuRWLockFuncs(parent, PARENT);
20218 +AuRWLockFuncs(parent2, PARENT2);
20219 +AuRWLockFuncs(parent3, PARENT3);
20220 +AuRWLockFuncs(new_child, NEW_CHILD);
20222 +#undef AuReadLockFunc
20223 +#undef AuWriteLockFunc
20224 +#undef AuRWLockFuncs
20226 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
20227 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
20228 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
20230 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
20231 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
20232 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
20234 +/* ---------------------------------------------------------------------- */
20236 +static inline void au_icntnr_init(struct au_icntnr *c)
20238 +#ifdef CONFIG_AUFS_DEBUG
20239 + c->vfs_inode.i_mode = 0;
20243 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
20245 + unsigned int gen;
20246 + struct au_iinfo *iinfo;
20247 + struct au_iigen *iigen;
20249 + iinfo = au_ii(inode);
20250 + iigen = &iinfo->ii_generation;
20251 + spin_lock(&iigen->ig_spin);
20253 + *igflags = iigen->ig_flags;
20254 + gen = iigen->ig_generation;
20255 + spin_unlock(&iigen->ig_spin);
20260 +/* tiny test for inode number */
20261 +/* tmpfs generation is too rough */
20262 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
20264 + struct au_iinfo *iinfo;
20266 + iinfo = au_ii(inode);
20267 + AuRwMustAnyLock(&iinfo->ii_rwsem);
20268 + return !(iinfo->ii_hsb1 == h_inode->i_sb
20269 + && iinfo->ii_higen == h_inode->i_generation);
20272 +static inline void au_iigen_dec(struct inode *inode)
20274 + struct au_iinfo *iinfo;
20275 + struct au_iigen *iigen;
20277 + iinfo = au_ii(inode);
20278 + iigen = &iinfo->ii_generation;
20279 + spin_lock(&iigen->ig_spin);
20280 + iigen->ig_generation--;
20281 + spin_unlock(&iigen->ig_spin);
20284 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
20289 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
20295 +/* ---------------------------------------------------------------------- */
20297 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
20298 + aufs_bindex_t bindex)
20300 + return iinfo->ii_hinode + bindex;
20303 +static inline int au_is_bad_inode(struct inode *inode)
20305 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
20308 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
20309 + aufs_bindex_t bindex)
20311 + IiMustAnyLock(inode);
20312 + return au_hinode(au_ii(inode), bindex)->hi_id;
20315 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
20317 + IiMustAnyLock(inode);
20318 + return au_ii(inode)->ii_btop;
20321 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
20323 + IiMustAnyLock(inode);
20324 + return au_ii(inode)->ii_bbot;
20327 +static inline struct au_vdir *au_ivdir(struct inode *inode)
20329 + IiMustAnyLock(inode);
20330 + return au_ii(inode)->ii_vdir;
20333 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
20335 + IiMustAnyLock(inode);
20336 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
20339 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
20341 + IiMustWriteLock(inode);
20342 + au_ii(inode)->ii_btop = bindex;
20345 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
20347 + IiMustWriteLock(inode);
20348 + au_ii(inode)->ii_bbot = bindex;
20351 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
20353 + IiMustWriteLock(inode);
20354 + au_ii(inode)->ii_vdir = vdir;
20357 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
20359 + IiMustAnyLock(inode);
20360 + return au_hinode(au_ii(inode), bindex);
20363 +/* ---------------------------------------------------------------------- */
20365 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
20368 + return pin->parent;
20372 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
20374 + if (pin && pin->hdir)
20375 + return pin->hdir->hi_inode;
20379 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
20382 + return pin->hdir;
20386 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
20389 + pin->dentry = dentry;
20392 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
20393 + unsigned char lflag)
20397 + au_fset_pin(pin->flags, DI_LOCKED);
20399 + au_fclr_pin(pin->flags, DI_LOCKED);
20403 +#if 0 /* reserved */
20404 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
20407 + dput(pin->parent);
20408 + pin->parent = dget(parent);
20413 +/* ---------------------------------------------------------------------- */
20416 +#ifdef CONFIG_AUFS_HNOTIFY
20417 +struct au_hnotify_op {
20418 + void (*ctl)(struct au_hinode *hinode, int do_set);
20419 + int (*alloc)(struct au_hinode *hinode);
20422 + * if it returns true, the caller should free hinode->hi_notify,
20423 + * otherwise ->free() frees it.
20425 + int (*free)(struct au_hinode *hinode,
20426 + struct au_hnotify *hn) __must_check;
20428 + void (*fin)(void);
20429 + int (*init)(void);
20431 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
20432 + void (*fin_br)(struct au_branch *br);
20433 + int (*init_br)(struct au_branch *br, int perm);
20437 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
20438 +void au_hn_free(struct au_hinode *hinode);
20439 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
20440 +void au_hn_reset(struct inode *inode, unsigned int flags);
20441 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
20442 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
20443 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
20444 +int au_hnotify_init_br(struct au_branch *br, int perm);
20445 +void au_hnotify_fin_br(struct au_branch *br);
20446 +int __init au_hnotify_init(void);
20447 +void au_hnotify_fin(void);
20450 +extern const struct au_hnotify_op au_hnotify_op;
20453 +void au_hn_init(struct au_hinode *hinode)
20455 + hinode->hi_notify = NULL;
20458 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
20460 + return hinode->hi_notify;
20464 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
20465 + struct au_hinode *hinode __maybe_unused,
20466 + struct inode *inode __maybe_unused)
20467 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
20468 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
20469 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
20470 + int do_set __maybe_unused)
20471 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
20472 + unsigned int flags __maybe_unused)
20473 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
20474 + struct au_branch *br __maybe_unused,
20475 + int perm __maybe_unused)
20476 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
20477 + int perm __maybe_unused)
20478 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
20479 +AuStubInt0(__init au_hnotify_init, void)
20480 +AuStubVoid(au_hnotify_fin, void)
20481 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
20482 +#endif /* CONFIG_AUFS_HNOTIFY */
20484 +static inline void au_hn_suspend(struct au_hinode *hdir)
20486 + au_hn_ctl(hdir, /*do_set*/0);
20489 +static inline void au_hn_resume(struct au_hinode *hdir)
20491 + au_hn_ctl(hdir, /*do_set*/1);
20494 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
20496 + inode_lock(hdir->hi_inode);
20497 + au_hn_suspend(hdir);
20500 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
20501 + unsigned int sc __maybe_unused)
20503 + inode_lock_nested(hdir->hi_inode, sc);
20504 + au_hn_suspend(hdir);
20507 +#if 0 /* unused */
20508 +#include "vfsub.h"
20509 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
20512 + inode_lock_shared_nested(hdir->hi_inode, sc);
20513 + au_hn_suspend(hdir);
20517 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
20519 + au_hn_resume(hdir);
20520 + inode_unlock(hdir->hi_inode);
20523 +#endif /* __KERNEL__ */
20524 +#endif /* __AUFS_INODE_H__ */
20525 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
20526 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
20527 +++ linux/fs/aufs/ioctl.c 2022-11-05 23:02:18.965889284 +0100
20529 +// SPDX-License-Identifier: GPL-2.0
20531 + * Copyright (C) 2005-2022 Junjiro R. Okajima
20533 + * This program is free software; you can redistribute it and/or modify
20534 + * it under the terms of the GNU General Public License as published by
20535 + * the Free Software Foundation; either version 2 of the License, or
20536 + * (at your option) any later version.
20538 + * This program is distributed in the hope that it will be useful,
20539 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20540 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20541 + * GNU General Public License for more details.
20543 + * You should have received a copy of the GNU General Public License
20544 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20549 + * plink-management and readdir in userspace.
20550 + * assist the pathconf(3) wrapper library.
20552 + * File-based Hierarchical Storage Management.
20555 +#include <linux/compat.h>
20556 +#include <linux/file.h>
20559 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
20562 + aufs_bindex_t wbi, bindex, bbot;
20563 + struct file *h_file;
20564 + struct super_block *sb;
20565 + struct dentry *root;
20566 + struct au_branch *br;
20567 + struct aufs_wbr_fd wbrfd = {
20568 + .oflags = au_dir_roflags,
20571 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
20572 + | O_NOATIME | O_CLOEXEC;
20574 + AuDebugOn(wbrfd.oflags & ~valid);
20577 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
20578 + if (unlikely(err)) {
20584 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
20585 + wbrfd.oflags |= au_dir_roflags;
20586 + AuDbg("0%o\n", wbrfd.oflags);
20587 + if (unlikely(wbrfd.oflags & ~valid))
20591 + fd = get_unused_fd_flags(0);
20593 + if (unlikely(fd < 0))
20596 + h_file = ERR_PTR(-EINVAL);
20599 + sb = path->dentry->d_sb;
20600 + root = sb->s_root;
20601 + aufs_read_lock(root, AuLock_IR);
20602 + bbot = au_sbbot(sb);
20603 + if (wbrfd.brid >= 0) {
20604 + wbi = au_br_index(sb, wbrfd.brid);
20605 + if (unlikely(wbi < 0 || wbi > bbot))
20609 + h_file = ERR_PTR(-ENOENT);
20610 + br = au_sbr(sb, wbi);
20611 + if (!au_br_writable(br->br_perm)) {
20615 + bindex = wbi + 1;
20617 + for (; bindex <= bbot; bindex++) {
20618 + br = au_sbr(sb, bindex);
20619 + if (au_br_writable(br->br_perm)) {
20621 + br = au_sbr(sb, wbi);
20626 + AuDbg("wbi %d\n", wbi);
20628 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
20632 + aufs_read_unlock(root, AuLock_IR);
20633 + err = PTR_ERR(h_file);
20634 + if (IS_ERR(h_file))
20637 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
20638 + fd_install(fd, h_file);
20640 + goto out; /* success */
20643 + put_unused_fd(fd);
20649 +/* ---------------------------------------------------------------------- */
20651 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
20654 + struct dentry *dentry;
20657 + case AUFS_CTL_RDU:
20658 + case AUFS_CTL_RDU_INO:
20659 + err = au_rdu_ioctl(file, cmd, arg);
20662 + case AUFS_CTL_WBR_FD:
20663 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20666 + case AUFS_CTL_IBUSY:
20667 + err = au_ibusy_ioctl(file, arg);
20670 + case AUFS_CTL_BRINFO:
20671 + err = au_brinfo_ioctl(file, arg);
20674 + case AUFS_CTL_FHSM_FD:
20675 + dentry = file->f_path.dentry;
20676 + if (IS_ROOT(dentry))
20677 + err = au_fhsm_fd(dentry->d_sb, arg);
20683 + /* do not call the lower */
20684 + AuDbg("0x%x\n", cmd);
20692 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
20697 + case AUFS_CTL_MVDOWN:
20698 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
20701 + case AUFS_CTL_WBR_FD:
20702 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20706 + /* do not call the lower */
20707 + AuDbg("0x%x\n", cmd);
20715 +#ifdef CONFIG_COMPAT
20716 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
20717 + unsigned long arg)
20722 + case AUFS_CTL_RDU:
20723 + case AUFS_CTL_RDU_INO:
20724 + err = au_rdu_compat_ioctl(file, cmd, arg);
20727 + case AUFS_CTL_IBUSY:
20728 + err = au_ibusy_compat_ioctl(file, arg);
20731 + case AUFS_CTL_BRINFO:
20732 + err = au_brinfo_compat_ioctl(file, arg);
20736 + err = aufs_ioctl_dir(file, cmd, arg);
20743 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
20744 + unsigned long arg)
20746 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
20749 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
20750 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
20751 +++ linux/fs/aufs/i_op_add.c 2022-12-17 09:21:34.799855195 +0100
20753 +// SPDX-License-Identifier: GPL-2.0
20755 + * Copyright (C) 2005-2022 Junjiro R. Okajima
20757 + * This program is free software; you can redistribute it and/or modify
20758 + * it under the terms of the GNU General Public License as published by
20759 + * the Free Software Foundation; either version 2 of the License, or
20760 + * (at your option) any later version.
20762 + * This program is distributed in the hope that it will be useful,
20763 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20764 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20765 + * GNU General Public License for more details.
20767 + * You should have received a copy of the GNU General Public License
20768 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20772 + * inode operations (add entry)
20775 +#include <linux/iversion.h>
20779 + * final procedure of adding a new entry, except link(2).
20780 + * remove whiteout, instantiate, copyup the parent dir's times and size
20781 + * and update version.
20782 + * if it failed, re-create the removed whiteout.
20784 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
20785 + struct dentry *wh_dentry, struct dentry *dentry)
20788 + aufs_bindex_t bwh;
20789 + struct path h_path;
20790 + struct super_block *sb;
20791 + struct inode *inode, *h_dir;
20792 + struct dentry *wh;
20797 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
20798 + IMustLock(h_dir);
20799 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
20800 + bwh = au_dbwh(dentry);
20801 + h_path.dentry = wh_dentry;
20802 + h_path.mnt = au_sbr_mnt(sb, bindex);
20803 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
20805 + if (unlikely(err))
20809 + inode = au_new_inode(dentry, /*must_new*/1);
20810 + if (!IS_ERR(inode)) {
20811 + d_instantiate(dentry, inode);
20812 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
20814 + au_dir_ts(dir, bindex);
20815 + inode_inc_iversion(dir);
20816 + au_fhsm_wrote(sb, bindex, /*force*/0);
20817 + return 0; /* success */
20820 + err = PTR_ERR(inode);
20825 + /* dir inode is locked */
20826 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
20827 + rerr = PTR_ERR(wh);
20828 + if (IS_ERR(wh)) {
20829 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
20830 + dentry, err, rerr);
20839 +static int au_d_may_add(struct dentry *dentry)
20844 + if (unlikely(d_unhashed(dentry)))
20846 + if (unlikely(d_really_is_positive(dentry)))
20852 + * simple tests for the adding inode operations.
20853 + * following the checks in vfs, plus the parent-child relationship.
20855 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20856 + struct dentry *h_parent, int isdir)
20860 + struct dentry *h_dentry;
20861 + struct inode *h_inode;
20863 + err = -ENAMETOOLONG;
20864 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20867 + h_dentry = au_h_dptr(dentry, bindex);
20868 + if (d_really_is_negative(dentry)) {
20870 + if (unlikely(d_is_positive(h_dentry)))
20873 + /* rename(2) case */
20875 + if (unlikely(d_is_negative(h_dentry)))
20877 + h_inode = d_inode(h_dentry);
20878 + if (unlikely(!h_inode->i_nlink))
20881 + h_mode = h_inode->i_mode;
20884 + if (unlikely(S_ISDIR(h_mode)))
20886 + } else if (unlikely(!S_ISDIR(h_mode))) {
20893 + /* expected parent dir is locked */
20894 + if (unlikely(h_parent != h_dentry->d_parent))
20903 + * initial procedure of adding a new entry.
20904 + * prepare writable branch and the parent dir, lock it,
20905 + * and lookup whiteout for the new entry.
20907 +static struct dentry*
20908 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
20909 + struct dentry *src_dentry, struct au_pin *pin,
20910 + struct au_wr_dir_args *wr_dir_args)
20912 + struct dentry *wh_dentry, *h_parent;
20913 + struct super_block *sb;
20914 + struct au_branch *br;
20916 + unsigned int udba;
20917 + aufs_bindex_t bcpup;
20919 + AuDbg("%pd\n", dentry);
20921 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
20923 + wh_dentry = ERR_PTR(err);
20924 + if (unlikely(err < 0))
20927 + sb = dentry->d_sb;
20928 + udba = au_opt_udba(sb);
20929 + err = au_pin(pin, dentry, bcpup, udba,
20930 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20931 + wh_dentry = ERR_PTR(err);
20932 + if (unlikely(err))
20935 + h_parent = au_pinned_h_parent(pin);
20936 + if (udba != AuOpt_UDBA_NONE
20937 + && au_dbtop(dentry) == bcpup)
20938 + err = au_may_add(dentry, bcpup, h_parent,
20939 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
20940 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20941 + err = -ENAMETOOLONG;
20942 + wh_dentry = ERR_PTR(err);
20943 + if (unlikely(err))
20946 + br = au_sbr(sb, bcpup);
20948 + struct path tmp = {
20949 + .dentry = h_parent,
20950 + .mnt = au_br_mnt(br)
20952 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
20955 + wh_dentry = NULL;
20956 + if (bcpup != au_dbwh(dentry))
20957 + goto out; /* success */
20960 + * ENAMETOOLONG here means that if we allowed create such name, then it
20961 + * would not be able to removed in the future. So we don't allow such
20962 + * name here and we don't handle ENAMETOOLONG differently here.
20964 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
20967 + if (IS_ERR(wh_dentry))
20970 + return wh_dentry;
20973 +/* ---------------------------------------------------------------------- */
20975 +enum { Mknod, Symlink, Creat };
20976 +struct simple_arg {
20983 + struct vfsub_aopen_args *aopen;
20986 + const char *symname;
20995 +static int add_simple(struct inode *dir, struct dentry *dentry,
20996 + struct simple_arg *arg)
20999 + aufs_bindex_t btop;
21000 + unsigned char created;
21001 + const unsigned char try_aopen
21002 + = (arg->type == Creat && arg->u.c.try_aopen);
21003 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
21004 + struct dentry *wh_dentry, *parent;
21005 + struct inode *h_dir;
21006 + struct super_block *sb;
21007 + struct au_branch *br;
21008 + /* to reduce stack size */
21010 + struct au_dtime dt;
21011 + struct au_pin pin;
21012 + struct path h_path;
21013 + struct au_wr_dir_args wr_dir_args;
21016 + AuDbg("%pd\n", dentry);
21020 + a = kmalloc(sizeof(*a), GFP_NOFS);
21021 + if (unlikely(!a))
21023 + a->wr_dir_args.force_btgt = -1;
21024 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
21026 + parent = dentry->d_parent; /* dir inode is locked */
21027 + if (!try_aopen) {
21028 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
21029 + if (unlikely(err))
21032 + err = au_d_may_add(dentry);
21033 + if (unlikely(err))
21036 + di_write_lock_parent(parent);
21037 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
21038 + &a->pin, &a->wr_dir_args);
21039 + err = PTR_ERR(wh_dentry);
21040 + if (IS_ERR(wh_dentry))
21043 + btop = au_dbtop(dentry);
21044 + sb = dentry->d_sb;
21045 + br = au_sbr(sb, btop);
21046 + a->h_path.dentry = au_h_dptr(dentry, btop);
21047 + a->h_path.mnt = au_br_mnt(br);
21048 + h_dir = au_pinned_h_dir(&a->pin);
21049 + switch (arg->type) {
21051 + if (!try_aopen || !h_dir->i_op->atomic_open) {
21052 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
21053 + arg->u.c.want_excl);
21055 + if (!err && try_aopen)
21056 + aopen->file->f_mode |= FMODE_CREATED;
21059 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
21060 + AuDbg("err %d\n", err);
21061 + AuDbgFile(aopen->file);
21062 + created = err >= 0
21063 + && !!(aopen->file->f_mode & FMODE_CREATED);
21067 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
21071 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
21078 + if (unlikely(err < 0))
21081 + err = epilog(dir, btop, wh_dentry, dentry);
21083 + goto out_unpin; /* success */
21086 + if (created /* && d_is_positive(a->h_path.dentry) */) {
21087 + /* no delegation since it is just created */
21088 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
21091 + AuIOErr("%pd revert failure(%d, %d)\n",
21092 + dentry, err, rerr);
21095 + au_dtime_revert(&a->dt);
21097 + if (try_aopen && h_dir->i_op->atomic_open
21098 + && (aopen->file->f_mode & FMODE_OPENED))
21099 + /* aopen->file is still opened */
21100 + au_lcnt_dec(&aopen->br->br_nfiles);
21103 + au_unpin(&a->pin);
21107 + di_write_unlock(parent);
21109 + if (unlikely(err)) {
21110 + au_update_dbtop(dentry);
21114 + aufs_read_unlock(dentry, AuLock_DW);
21121 +int aufs_mknod(struct user_namespace *userns, struct inode *dir,
21122 + struct dentry *dentry, umode_t mode, dev_t dev)
21124 + struct simple_arg arg = {
21131 + return add_simple(dir, dentry, &arg);
21134 +int aufs_symlink(struct user_namespace *userns, struct inode *dir,
21135 + struct dentry *dentry, const char *symname)
21137 + struct simple_arg arg = {
21139 + .u.s.symname = symname
21141 + return add_simple(dir, dentry, &arg);
21144 +int aufs_create(struct user_namespace *userns, struct inode *dir,
21145 + struct dentry *dentry, umode_t mode, bool want_excl)
21147 + struct simple_arg arg = {
21151 + .want_excl = want_excl
21154 + return add_simple(dir, dentry, &arg);
21157 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
21158 + struct vfsub_aopen_args *aopen_args)
21160 + struct simple_arg arg = {
21163 + .mode = aopen_args->create_mode,
21164 + .want_excl = aopen_args->open_flag & O_EXCL,
21165 + .try_aopen = true,
21166 + .aopen = aopen_args
21169 + return add_simple(dir, dentry, &arg);
21172 +int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
21173 + struct file *file, umode_t mode)
21176 + aufs_bindex_t bindex;
21177 + struct path h_ppath;
21178 + struct super_block *sb;
21179 + struct au_branch *br;
21180 + struct dentry *dentry, *parent, *h_parent, *h_dentry;
21181 + struct inode *h_dir, *inode;
21182 + struct vfsmount *h_mnt;
21183 + struct user_namespace *h_userns;
21184 + struct file *h_file;
21185 + struct au_wr_dir_args wr_dir_args = {
21186 + .force_btgt = -1,
21187 + .flags = AuWrDir_TMPFILE
21190 + /* copy-up may happen */
21195 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21196 + if (unlikely(err))
21199 + dentry = file->f_path.dentry;
21200 + err = au_di_init(dentry);
21201 + if (unlikely(err))
21205 + parent = d_find_any_alias(dir);
21206 + AuDebugOn(!parent);
21207 + di_write_lock_parent(parent);
21208 + if (unlikely(d_inode(parent) != dir))
21211 + err = au_digen_test(parent, au_sigen(sb));
21212 + if (unlikely(err))
21215 + bindex = au_dbtop(parent);
21216 + au_set_dbtop(dentry, bindex);
21217 + au_set_dbbot(dentry, bindex);
21218 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21220 + if (unlikely(err < 0))
21223 + err = -EOPNOTSUPP;
21224 + h_dir = au_h_iptr(dir, bindex);
21225 + if (unlikely(!h_dir->i_op->tmpfile))
21228 + br = au_sbr(sb, bindex);
21229 + h_mnt = au_br_mnt(br);
21230 + err = vfsub_mnt_want_write(h_mnt);
21231 + if (unlikely(err))
21234 + h_userns = mnt_user_ns(h_mnt);
21235 + h_parent = au_h_dptr(parent, bindex);
21236 + h_ppath.mnt = h_mnt;
21237 + h_ppath.dentry = h_parent;
21238 + h_file = vfs_tmpfile_open(h_userns, &h_ppath, mode, /*open_flag*/0,
21240 + if (IS_ERR(h_file)) {
21241 + err = PTR_ERR(h_file);
21246 + h_dentry = h_file->f_path.dentry;
21247 + au_set_dbtop(dentry, bindex);
21248 + au_set_dbbot(dentry, bindex);
21249 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
21250 + inode = au_new_inode(dentry, /*must_new*/1);
21251 + if (IS_ERR(inode)) {
21252 + err = PTR_ERR(inode);
21253 + au_set_h_dptr(dentry, bindex, NULL);
21254 + au_set_dbtop(dentry, -1);
21255 + au_set_dbbot(dentry, -1);
21259 + if (!inode->i_nlink)
21260 + set_nlink(inode, 1);
21261 + d_tmpfile(file, inode);
21262 + au_di(dentry)->di_tmpfile = 1;
21263 + get_file(h_file);
21264 + au_di(dentry)->di_htmpfile = h_file;
21266 + /* update without i_mutex */
21267 + if (au_ibtop(dir) == au_dbtop(dentry))
21268 + au_cpup_attr_timesizes(dir);
21273 + vfsub_mnt_drop_write(h_mnt);
21275 + di_write_unlock(parent);
21277 + di_write_unlock(dentry);
21282 + au_di(dentry)->di_htmpfile = NULL;
21283 + au_di_fin(dentry);
21284 + dentry->d_fsdata = NULL;
21286 + si_read_unlock(sb);
21287 + if (!err && h_file) {
21289 + err = finish_open_simple(file, err);
21291 + au_lcnt_inc(&br->br_nfiles);
21294 + au_di(dentry)->di_htmpfile = NULL;
21295 + au_di_fin(dentry);
21296 + dentry->d_fsdata = NULL;
21300 + inode_unlock(dir);
21305 +/* ---------------------------------------------------------------------- */
21307 +struct au_link_args {
21308 + aufs_bindex_t bdst, bsrc;
21309 + struct au_pin pin;
21310 + struct path h_path;
21311 + struct dentry *src_parent, *parent;
21314 +static int au_cpup_before_link(struct dentry *src_dentry,
21315 + struct au_link_args *a)
21318 + struct dentry *h_src_dentry;
21319 + struct au_cp_generic cpg = {
21320 + .dentry = src_dentry,
21325 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
21328 + di_read_lock_parent(a->src_parent, AuLock_IR);
21329 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
21330 + if (unlikely(err))
21333 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
21334 + err = au_pin(&a->pin, src_dentry, a->bdst,
21335 + au_opt_udba(src_dentry->d_sb),
21336 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21337 + if (unlikely(err))
21340 + err = au_sio_cpup_simple(&cpg);
21341 + au_unpin(&a->pin);
21344 + di_read_unlock(a->src_parent, AuLock_IR);
21348 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
21349 + struct au_link_args *a)
21352 + unsigned char plink;
21353 + aufs_bindex_t bbot;
21354 + struct dentry *h_src_dentry;
21355 + struct inode *h_inode, *inode, *delegated;
21356 + struct super_block *sb;
21357 + struct file *h_file;
21361 + sb = src_dentry->d_sb;
21362 + inode = d_inode(src_dentry);
21363 + if (au_ibtop(inode) <= a->bdst)
21364 + h_inode = au_h_iptr(inode, a->bdst);
21365 + if (!h_inode || !h_inode->i_nlink) {
21366 + /* copyup src_dentry as the name of dentry. */
21367 + bbot = au_dbbot(dentry);
21368 + if (bbot < a->bsrc)
21369 + au_set_dbbot(dentry, a->bsrc);
21370 + au_set_h_dptr(dentry, a->bsrc,
21371 + dget(au_h_dptr(src_dentry, a->bsrc)));
21372 + dget(a->h_path.dentry);
21373 + au_set_h_dptr(dentry, a->bdst, NULL);
21374 + AuDbg("temporary d_inode...\n");
21375 + spin_lock(&dentry->d_lock);
21376 + dentry->d_inode = d_inode(src_dentry); /* tmp */
21377 + spin_unlock(&dentry->d_lock);
21378 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
21379 + if (IS_ERR(h_file))
21380 + err = PTR_ERR(h_file);
21382 + struct au_cp_generic cpg = {
21383 + .dentry = dentry,
21388 + .flags = AuCpup_KEEPLINO
21390 + err = au_sio_cpup_simple(&cpg);
21391 + au_h_open_post(dentry, a->bsrc, h_file);
21393 + dput(a->h_path.dentry);
21394 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
21396 + au_set_h_dptr(dentry, a->bdst,
21397 + a->h_path.dentry);
21399 + spin_lock(&dentry->d_lock);
21400 + dentry->d_inode = NULL; /* restore */
21401 + spin_unlock(&dentry->d_lock);
21402 + AuDbg("temporary d_inode...done\n");
21403 + au_set_h_dptr(dentry, a->bsrc, NULL);
21404 + au_set_dbbot(dentry, bbot);
21406 + /* the inode of src_dentry already exists on a.bdst branch */
21407 + h_src_dentry = d_find_alias(h_inode);
21408 + if (!h_src_dentry && au_plink_test(inode)) {
21410 + h_src_dentry = au_plink_lkup(inode, a->bdst);
21411 + err = PTR_ERR(h_src_dentry);
21412 + if (IS_ERR(h_src_dentry))
21415 + if (unlikely(d_is_negative(h_src_dentry))) {
21416 + dput(h_src_dentry);
21417 + h_src_dentry = NULL;
21421 + if (h_src_dentry) {
21422 + delegated = NULL;
21423 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
21424 + &a->h_path, &delegated);
21425 + if (unlikely(err == -EWOULDBLOCK)) {
21426 + pr_warn("cannot retry for NFSv4 delegation"
21427 + " for an internal link\n");
21430 + dput(h_src_dentry);
21432 + AuIOErr("no dentry found for hi%lu on b%d\n",
21433 + h_inode->i_ino, a->bdst);
21438 + if (!err && !plink)
21439 + au_plink_append(inode, a->bdst, a->h_path.dentry);
21446 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
21447 + struct dentry *dentry)
21450 + struct au_dtime dt;
21451 + struct au_link_args *a;
21452 + struct dentry *wh_dentry, *h_src_dentry;
21453 + struct inode *inode, *delegated;
21454 + struct super_block *sb;
21455 + struct au_wr_dir_args wr_dir_args = {
21456 + /* .force_btgt = -1, */
21457 + .flags = AuWrDir_ADD_ENTRY
21461 + inode = d_inode(src_dentry);
21462 + IMustLock(inode);
21465 + a = kzalloc(sizeof(*a), GFP_NOFS);
21466 + if (unlikely(!a))
21469 + a->parent = dentry->d_parent; /* dir inode is locked */
21470 + err = aufs_read_and_write_lock2(dentry, src_dentry,
21471 + AuLock_NOPLM | AuLock_GEN);
21472 + if (unlikely(err))
21474 + err = au_d_linkable(src_dentry);
21475 + if (unlikely(err))
21477 + err = au_d_may_add(dentry);
21478 + if (unlikely(err))
21481 + a->src_parent = dget_parent(src_dentry);
21482 + wr_dir_args.force_btgt = au_ibtop(inode);
21484 + di_write_lock_parent(a->parent);
21485 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
21486 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
21488 + err = PTR_ERR(wh_dentry);
21489 + if (IS_ERR(wh_dentry))
21493 + sb = dentry->d_sb;
21494 + a->bdst = au_dbtop(dentry);
21495 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
21496 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
21497 + a->bsrc = au_ibtop(inode);
21498 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
21499 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
21500 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
21501 + if (!h_src_dentry) {
21502 + a->bsrc = au_dbtop(src_dentry);
21503 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
21504 + AuDebugOn(!h_src_dentry);
21505 + } else if (IS_ERR(h_src_dentry)) {
21506 + err = PTR_ERR(h_src_dentry);
21511 + * aufs doesn't touch the credential so
21512 + * security_dentry_create_files_as() is unnecessary.
21514 + if (au_opt_test(au_mntflags(sb), PLINK)) {
21515 + if (a->bdst < a->bsrc
21516 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
21517 + err = au_cpup_or_link(src_dentry, dentry, a);
21519 + delegated = NULL;
21520 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
21521 + &a->h_path, &delegated);
21522 + if (unlikely(err == -EWOULDBLOCK)) {
21523 + pr_warn("cannot retry for NFSv4 delegation"
21524 + " for an internal link\n");
21528 + dput(h_src_dentry);
21531 + * copyup src_dentry to the branch we process,
21532 + * and then link(2) to it.
21534 + dput(h_src_dentry);
21535 + if (a->bdst < a->bsrc
21536 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
21537 + au_unpin(&a->pin);
21538 + di_write_unlock(a->parent);
21539 + err = au_cpup_before_link(src_dentry, a);
21540 + di_write_lock_parent(a->parent);
21542 + err = au_pin(&a->pin, dentry, a->bdst,
21544 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21545 + if (unlikely(err))
21549 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
21551 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
21552 + delegated = NULL;
21553 + err = vfsub_link(h_src_dentry,
21554 + au_pinned_h_dir(&a->pin),
21555 + &a->h_path, &delegated);
21556 + if (unlikely(err == -EWOULDBLOCK)) {
21557 + pr_warn("cannot retry"
21558 + " for NFSv4 delegation"
21559 + " for an internal link\n");
21565 + if (unlikely(err))
21569 + a->h_path.dentry = wh_dentry;
21570 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
21572 + if (unlikely(err))
21576 + au_dir_ts(dir, a->bdst);
21577 + inode_inc_iversion(dir);
21578 + inc_nlink(inode);
21579 + inode->i_ctime = dir->i_ctime;
21580 + d_instantiate(dentry, au_igrab(inode));
21581 + if (d_unhashed(a->h_path.dentry))
21582 + /* some filesystem calls d_drop() */
21584 + /* some filesystems consume an inode even hardlink */
21585 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
21586 + goto out_unpin; /* success */
21589 + /* no delegation since it is just created */
21590 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
21591 + /*delegated*/NULL, /*force*/0);
21592 + if (unlikely(rerr)) {
21593 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
21596 + au_dtime_revert(&dt);
21598 + au_unpin(&a->pin);
21602 + di_write_unlock(a->parent);
21603 + dput(a->src_parent);
21605 + if (unlikely(err)) {
21606 + au_update_dbtop(dentry);
21609 + aufs_read_and_write_unlock2(dentry, src_dentry);
21617 +int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
21618 + struct dentry *dentry, umode_t mode)
21621 + aufs_bindex_t bindex;
21622 + unsigned char diropq;
21623 + struct path h_path;
21624 + struct dentry *wh_dentry, *parent, *opq_dentry;
21625 + struct inode *h_inode;
21626 + struct super_block *sb;
21628 + struct au_pin pin;
21629 + struct au_dtime dt;
21630 + } *a; /* reduce the stack usage */
21631 + struct au_wr_dir_args wr_dir_args = {
21632 + .force_btgt = -1,
21633 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
21639 + a = kmalloc(sizeof(*a), GFP_NOFS);
21640 + if (unlikely(!a))
21643 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
21644 + if (unlikely(err))
21646 + err = au_d_may_add(dentry);
21647 + if (unlikely(err))
21650 + parent = dentry->d_parent; /* dir inode is locked */
21651 + di_write_lock_parent(parent);
21652 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
21653 + &a->pin, &wr_dir_args);
21654 + err = PTR_ERR(wh_dentry);
21655 + if (IS_ERR(wh_dentry))
21658 + sb = dentry->d_sb;
21659 + bindex = au_dbtop(dentry);
21660 + h_path.dentry = au_h_dptr(dentry, bindex);
21661 + h_path.mnt = au_sbr_mnt(sb, bindex);
21662 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
21663 + if (unlikely(err))
21666 + /* make the dir opaque */
21668 + h_inode = d_inode(h_path.dentry);
21670 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
21671 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21672 + opq_dentry = au_diropq_create(dentry, bindex);
21673 + inode_unlock(h_inode);
21674 + err = PTR_ERR(opq_dentry);
21675 + if (IS_ERR(opq_dentry))
21677 + dput(opq_dentry);
21681 + err = epilog(dir, bindex, wh_dentry, dentry);
21684 + goto out_unpin; /* success */
21689 + AuLabel(revert opq);
21690 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21691 + rerr = au_diropq_remove(dentry, bindex);
21692 + inode_unlock(h_inode);
21694 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
21695 + dentry, err, rerr);
21701 + AuLabel(revert dir);
21702 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
21704 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
21705 + dentry, err, rerr);
21708 + au_dtime_revert(&a->dt);
21710 + au_unpin(&a->pin);
21713 + di_write_unlock(parent);
21715 + if (unlikely(err)) {
21716 + au_update_dbtop(dentry);
21719 + aufs_read_unlock(dentry, AuLock_DW);
21725 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
21726 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
21727 +++ linux/fs/aufs/i_op.c 2022-11-05 23:02:18.965889284 +0100
21729 +// SPDX-License-Identifier: GPL-2.0
21731 + * Copyright (C) 2005-2022 Junjiro R. Okajima
21733 + * This program is free software; you can redistribute it and/or modify
21734 + * it under the terms of the GNU General Public License as published by
21735 + * the Free Software Foundation; either version 2 of the License, or
21736 + * (at your option) any later version.
21738 + * This program is distributed in the hope that it will be useful,
21739 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21740 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21741 + * GNU General Public License for more details.
21743 + * You should have received a copy of the GNU General Public License
21744 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21748 + * inode operations (except add/del/rename)
21751 +#include <linux/device_cgroup.h>
21752 +#include <linux/fs_stack.h>
21753 +#include <linux/iversion.h>
21754 +#include <linux/security.h>
21757 +static int h_permission(struct inode *h_inode, int mask,
21758 + struct path *h_path, int brperm)
21761 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
21762 + struct user_namespace *h_userns;
21765 + if (write_mask && IS_IMMUTABLE(h_inode))
21769 + if (((mask & MAY_EXEC)
21770 + && S_ISREG(h_inode->i_mode)
21771 + && (path_noexec(h_path)
21772 + || !(h_inode->i_mode & 0111))))
21776 + * - skip the lower fs test in the case of write to ro branch.
21777 + * - nfs dir permission write check is optimized, but a policy for
21778 + * link/rename requires a real check.
21779 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
21780 + * in this case, generic_permission() returns -EOPNOTSUPP.
21782 + h_userns = mnt_user_ns(h_path->mnt);
21783 + if ((write_mask && !au_br_writable(brperm))
21784 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
21785 + && write_mask && !(mask & MAY_READ))
21786 + || !h_inode->i_op->permission) {
21787 + /* AuLabel(generic_permission); */
21788 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
21789 + err = generic_permission(h_userns, h_inode, mask);
21790 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
21791 + err = h_inode->i_op->permission(h_userns, h_inode,
21795 + /* AuLabel(h_inode->permission); */
21796 + err = h_inode->i_op->permission(h_userns, h_inode, mask);
21801 + err = devcgroup_inode_permission(h_inode, mask);
21803 + err = security_inode_permission(h_inode, mask);
21809 +static int aufs_permission(struct user_namespace *userns, struct inode *inode,
21813 + aufs_bindex_t bindex, bbot;
21814 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
21815 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
21816 + struct inode *h_inode;
21817 + struct super_block *sb;
21818 + struct au_branch *br;
21820 + /* todo: support rcu-walk? */
21821 + if (mask & MAY_NOT_BLOCK)
21824 + sb = inode->i_sb;
21825 + si_read_lock(sb, AuLock_FLUSH);
21826 + ii_read_lock_child(inode);
21827 +#if 0 /* reserved for future use */
21829 + * This test may be rather 'too much' since the test is essentially done
21830 + * in the aufs_lookup(). Theoretically it is possible that the inode
21831 + * generation doesn't match to the superblock's here. But it isn't a
21832 + * big deal I suppose.
21834 + err = au_iigen_test(inode, au_sigen(sb));
21835 + if (unlikely(err))
21841 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
21842 + err = au_busy_or_stale();
21843 + h_inode = au_h_iptr(inode, au_ibtop(inode));
21844 + if (unlikely(!h_inode
21845 + || (h_inode->i_mode & S_IFMT)
21846 + != (inode->i_mode & S_IFMT)))
21850 + bindex = au_ibtop(inode);
21851 + br = au_sbr(sb, bindex);
21852 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
21855 + && !special_file(h_inode->i_mode)) {
21856 + /* test whether the upper writable branch exists */
21858 + for (; bindex >= 0; bindex--)
21859 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
21867 + /* non-write to dir */
21869 + bbot = au_ibbot(inode);
21870 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
21871 + h_inode = au_h_iptr(inode, bindex);
21873 + err = au_busy_or_stale();
21874 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
21877 + br = au_sbr(sb, bindex);
21878 + err = h_permission(h_inode, mask, &br->br_path,
21884 + ii_read_unlock(inode);
21885 + si_read_unlock(sb);
21889 +/* ---------------------------------------------------------------------- */
21891 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
21892 + unsigned int flags)
21894 + struct dentry *ret, *parent;
21895 + struct inode *inode;
21896 + struct super_block *sb;
21897 + int err, npositive;
21901 + /* todo: support rcu-walk? */
21902 + ret = ERR_PTR(-ECHILD);
21903 + if (flags & LOOKUP_RCU)
21906 + ret = ERR_PTR(-ENAMETOOLONG);
21907 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
21911 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21912 + ret = ERR_PTR(err);
21913 + if (unlikely(err))
21916 + err = au_di_init(dentry);
21917 + ret = ERR_PTR(err);
21918 + if (unlikely(err))
21922 + npositive = 0; /* suppress a warning */
21923 + parent = dentry->d_parent; /* dir inode is locked */
21924 + di_read_lock_parent(parent, AuLock_IR);
21925 + err = au_alive_dir(parent);
21927 + err = au_digen_test(parent, au_sigen(sb));
21929 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
21930 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
21931 + AuLkup_ALLOW_NEG);
21934 + di_read_unlock(parent, AuLock_IR);
21935 + ret = ERR_PTR(err);
21936 + if (unlikely(err < 0))
21940 + inode = au_new_inode(dentry, /*must_new*/0);
21941 + if (IS_ERR(inode)) {
21942 + ret = (void *)inode;
21949 + atomic_inc(&inode->i_count);
21950 + ret = d_splice_alias(inode, dentry);
21951 +#if 0 /* reserved for future use */
21952 + if (unlikely(d_need_lookup(dentry))) {
21953 + spin_lock(&dentry->d_lock);
21954 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
21955 + spin_unlock(&dentry->d_lock);
21959 + if (!IS_ERR(ret)) {
21961 + if (ret && ret != dentry)
21962 + ii_write_unlock(inode);
21964 + ii_write_unlock(inode);
21971 + di_write_unlock(dentry);
21973 + si_read_unlock(sb);
21978 +/* ---------------------------------------------------------------------- */
21981 + * very dirty and complicated aufs ->atomic_open().
21982 + * aufs_atomic_open()
21983 + * + au_aopen_or_create()
21985 + * + vfsub_atomic_open()
21986 + * + branch fs ->atomic_open()
21987 + * may call the actual 'open' for h_file
21988 + * + inc br_nfiles only if opened
21989 + * + au_aopen_no_open() or au_aopen_do_open()
21991 + * au_aopen_do_open()
21992 + * + finish_open()
21993 + * + au_do_aopen()
21994 + * + au_do_open() the body of all 'open'
21995 + * + au_do_open_nondir()
21996 + * set the passed h_file
21998 + * au_aopen_no_open()
21999 + * + finish_no_open()
22002 +struct aopen_node {
22003 + struct hlist_bl_node hblist;
22004 + struct file *file, *h_file;
22007 +static int au_do_aopen(struct inode *inode, struct file *file)
22009 + struct hlist_bl_head *aopen;
22010 + struct hlist_bl_node *pos;
22011 + struct aopen_node *node;
22012 + struct au_do_open_args args = {
22014 + .open = au_do_open_nondir
22017 + aopen = &au_sbi(inode->i_sb)->si_aopen;
22018 + hlist_bl_lock(aopen);
22019 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
22020 + if (node->file == file) {
22021 + args.h_file = node->h_file;
22024 + hlist_bl_unlock(aopen);
22025 + /* AuDebugOn(!args.h_file); */
22027 + return au_do_open(file, &args);
22030 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
22031 + struct aopen_node *aopen_node)
22034 + struct hlist_bl_head *aopen;
22037 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
22038 + au_hbl_add(&aopen_node->hblist, aopen);
22039 + err = finish_open(file, dentry, au_do_aopen);
22040 + au_hbl_del(&aopen_node->hblist, aopen);
22041 + /* AuDbgFile(file); */
22042 + AuDbg("%pd%s%s\n", dentry,
22043 + (file->f_mode & FMODE_CREATED) ? " created" : "",
22044 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
22050 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
22056 + err = finish_no_open(file, dentry);
22062 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
22063 + struct file *file, unsigned int open_flag,
22064 + umode_t create_mode)
22066 + int err, did_open;
22067 + unsigned int lkup_flags;
22068 + aufs_bindex_t bindex;
22069 + struct super_block *sb;
22070 + struct dentry *parent, *d;
22071 + struct vfsub_aopen_args args = {
22072 + .open_flag = open_flag,
22073 + .create_mode = create_mode
22075 + struct aopen_node aopen_node = {
22080 + AuDbg("open_flag 0%o\n", open_flag);
22081 + AuDbgDentry(dentry);
22084 + if (!au_di(dentry)) {
22085 + lkup_flags = LOOKUP_OPEN;
22086 + if (open_flag & O_CREAT)
22087 + lkup_flags |= LOOKUP_CREATE;
22088 + d = aufs_lookup(dir, dentry, lkup_flags);
22090 + err = PTR_ERR(d);
22095 + * obsoleted dentry found.
22096 + * another error will be returned later.
22102 + AuDbgDentry(dentry);
22105 + if (d_is_positive(dentry)
22106 + || d_unhashed(dentry)
22107 + || d_unlinked(dentry)
22108 + || !(open_flag & O_CREAT)) {
22109 + err = au_aopen_no_open(file, dentry);
22110 + goto out; /* success */
22113 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22114 + if (unlikely(err))
22117 + sb = dentry->d_sb;
22118 + parent = dentry->d_parent; /* dir is locked */
22119 + di_write_lock_parent(parent);
22120 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
22121 + if (unlikely(err < 0))
22124 + AuDbgDentry(dentry);
22125 + if (d_is_positive(dentry)) {
22126 + err = au_aopen_no_open(file, dentry);
22127 + goto out_parent; /* success */
22130 + args.file = alloc_empty_file(file->f_flags, current_cred());
22131 + err = PTR_ERR(args.file);
22132 + if (IS_ERR(args.file))
22135 + bindex = au_dbtop(dentry);
22136 + err = au_aopen_or_create(dir, dentry, &args);
22138 + AuDbgFile(args.file);
22139 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
22140 + did_open = !!(args.file->f_mode & FMODE_OPENED);
22143 + args.file = NULL;
22145 + di_write_unlock(parent);
22146 + di_write_unlock(dentry);
22147 + if (unlikely(err < 0)) {
22154 + err = au_aopen_no_open(file, dentry);
22156 + aopen_node.h_file = args.file;
22157 + err = au_aopen_do_open(file, dentry, &aopen_node);
22159 + if (unlikely(err < 0)) {
22163 + au_lcnt_dec(&args.br->br_nfiles);
22165 + goto out_sb; /* success */
22168 + di_write_unlock(parent);
22169 + di_write_unlock(dentry);
22171 + si_read_unlock(sb);
22179 +/* ---------------------------------------------------------------------- */
22181 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
22182 + const unsigned char add_entry, aufs_bindex_t bcpup,
22183 + aufs_bindex_t btop)
22186 + struct dentry *h_parent;
22187 + struct inode *h_dir;
22190 + IMustLock(d_inode(parent));
22192 + di_write_lock_parent(parent);
22195 + if (!au_h_dptr(parent, bcpup)) {
22196 + if (btop > bcpup)
22197 + err = au_cpup_dirs(dentry, bcpup);
22198 + else if (btop < bcpup)
22199 + err = au_cpdown_dirs(dentry, bcpup);
22203 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
22204 + h_parent = au_h_dptr(parent, bcpup);
22205 + h_dir = d_inode(h_parent);
22206 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
22207 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
22208 + /* todo: no unlock here */
22209 + inode_unlock_shared(h_dir);
22211 + AuDbg("bcpup %d\n", bcpup);
22213 + if (d_really_is_negative(dentry))
22214 + au_set_h_dptr(dentry, btop, NULL);
22215 + au_update_dbrange(dentry, /*do_put_zero*/0);
22220 + di_write_unlock(parent);
22222 + err = bcpup; /* success */
22229 + * decide the branch and the parent dir where we will create a new entry.
22230 + * returns new bindex or an error.
22231 + * copyup the parent dir if needed.
22233 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
22234 + struct au_wr_dir_args *args)
22237 + unsigned int flags;
22238 + aufs_bindex_t bcpup, btop, src_btop;
22239 + const unsigned char add_entry
22240 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
22241 + | au_ftest_wrdir(args->flags, TMPFILE);
22242 + struct super_block *sb;
22243 + struct dentry *parent;
22244 + struct au_sbinfo *sbinfo;
22246 + sb = dentry->d_sb;
22247 + sbinfo = au_sbi(sb);
22248 + parent = dget_parent(dentry);
22249 + btop = au_dbtop(dentry);
22251 + if (args->force_btgt < 0) {
22252 + if (src_dentry) {
22253 + src_btop = au_dbtop(src_dentry);
22254 + if (src_btop < btop)
22255 + bcpup = src_btop;
22256 + } else if (add_entry) {
22258 + if (au_ftest_wrdir(args->flags, ISDIR))
22259 + au_fset_wbr(flags, DIR);
22260 + err = AuWbrCreate(sbinfo, dentry, flags);
22264 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
22266 + err = AuWbrCopyup(sbinfo, dentry);
22268 + if (!IS_ROOT(dentry)) {
22269 + di_read_lock_parent(parent, !AuLock_IR);
22270 + err = AuWbrCopyup(sbinfo, dentry);
22271 + di_read_unlock(parent, !AuLock_IR);
22273 + err = AuWbrCopyup(sbinfo, dentry);
22276 + if (unlikely(err < 0))
22280 + bcpup = args->force_btgt;
22281 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
22284 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
22286 + if (bcpup == btop)
22287 + goto out; /* success */
22289 + /* copyup the new parent into the branch we process */
22290 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
22292 + if (d_really_is_negative(dentry)) {
22293 + au_set_h_dptr(dentry, btop, NULL);
22294 + au_set_dbtop(dentry, bcpup);
22295 + au_set_dbbot(dentry, bcpup);
22297 + AuDebugOn(add_entry
22298 + && !au_ftest_wrdir(args->flags, TMPFILE)
22299 + && !au_h_dptr(dentry, bcpup));
22307 +/* ---------------------------------------------------------------------- */
22309 +void au_pin_hdir_unlock(struct au_pin *p)
22312 + au_hn_inode_unlock(p->hdir);
22315 +int au_pin_hdir_lock(struct au_pin *p)
22323 + /* even if an error happens later, keep this lock */
22324 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
22327 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
22332 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
22333 + p->h_parent, p->br);
22339 +int au_pin_hdir_relock(struct au_pin *p)
22342 + struct inode *h_i;
22343 + struct dentry *h_d[] = {
22348 + err = au_pin_hdir_lock(p);
22349 + if (unlikely(err))
22352 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
22355 + if (d_is_positive(h_d[i])) {
22356 + h_i = d_inode(h_d[i]);
22357 + err = !h_i->i_nlink;
22365 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
22367 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
22370 +void au_pin_hdir_acquire_nest(struct au_pin *p)
22373 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
22374 + p->lsc_hi, 0, NULL, _RET_IP_);
22375 + au_pin_hdir_set_owner(p, current);
22379 +void au_pin_hdir_release(struct au_pin *p)
22382 + au_pin_hdir_set_owner(p, p->task);
22383 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
22387 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
22389 + if (pin && pin->parent)
22390 + return au_h_dptr(pin->parent, pin->bindex);
22394 +void au_unpin(struct au_pin *p)
22397 + au_pin_hdir_unlock(p);
22398 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
22399 + vfsub_mnt_drop_write(p->h_mnt);
22403 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22404 + di_read_unlock(p->parent, AuLock_IR);
22405 + iput(p->hdir->hi_inode);
22407 + p->parent = NULL;
22410 + /* do not clear p->task */
22413 +int au_do_pin(struct au_pin *p)
22416 + struct super_block *sb;
22417 + struct inode *h_dir;
22420 + sb = p->dentry->d_sb;
22421 + p->br = au_sbr(sb, p->bindex);
22422 + if (IS_ROOT(p->dentry)) {
22423 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
22424 + p->h_mnt = au_br_mnt(p->br);
22425 + err = vfsub_mnt_want_write(p->h_mnt);
22426 + if (unlikely(err)) {
22427 + au_fclr_pin(p->flags, MNT_WRITE);
22434 + p->h_dentry = NULL;
22435 + if (p->bindex <= au_dbbot(p->dentry))
22436 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
22438 + p->parent = dget_parent(p->dentry);
22439 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22440 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
22443 + p->h_parent = au_h_dptr(p->parent, p->bindex);
22444 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
22446 + h_dir = p->hdir->hi_inode;
22450 + * if DI_LOCKED is not set, then p->parent may be different
22451 + * and h_parent can be NULL.
22453 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
22455 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22456 + di_read_unlock(p->parent, AuLock_IR);
22458 + p->parent = NULL;
22462 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
22463 + p->h_mnt = au_br_mnt(p->br);
22464 + err = vfsub_mnt_want_write(p->h_mnt);
22465 + if (unlikely(err)) {
22466 + au_fclr_pin(p->flags, MNT_WRITE);
22467 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22468 + di_read_unlock(p->parent, AuLock_IR);
22470 + p->parent = NULL;
22476 + err = au_pin_hdir_lock(p);
22478 + goto out; /* success */
22483 + pr_err("err %d\n", err);
22484 + err = au_busy_or_stale();
22489 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
22490 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
22491 + unsigned int udba, unsigned char flags)
22493 + p->dentry = dentry;
22495 + p->lsc_di = lsc_di;
22496 + p->lsc_hi = lsc_hi;
22497 + p->flags = flags;
22498 + p->bindex = bindex;
22500 + p->parent = NULL;
22504 + p->h_dentry = NULL;
22505 + p->h_parent = NULL;
22507 + p->task = current;
22510 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
22511 + unsigned int udba, unsigned char flags)
22513 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
22515 + return au_do_pin(pin);
22518 +/* ---------------------------------------------------------------------- */
22521 + * ->setattr() and ->getattr() are called in various cases.
22522 + * chmod, stat: dentry is revalidated.
22523 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
22525 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
22527 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
22528 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
22531 + struct dentry *parent;
22534 + if (au_digen_test(dentry, sigen)) {
22535 + parent = dget_parent(dentry);
22536 + di_read_lock_parent(parent, AuLock_IR);
22537 + err = au_refresh_dentry(dentry, parent);
22538 + di_read_unlock(parent, AuLock_IR);
22546 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
22547 + struct au_icpup_args *a)
22551 + aufs_bindex_t btop, ibtop;
22552 + struct dentry *hi_wh, *parent;
22553 + struct inode *inode;
22554 + struct au_wr_dir_args wr_dir_args = {
22555 + .force_btgt = -1,
22559 + if (d_is_dir(dentry))
22560 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
22561 + /* plink or hi_wh() case */
22562 + btop = au_dbtop(dentry);
22563 + inode = d_inode(dentry);
22564 + ibtop = au_ibtop(inode);
22565 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
22566 + wr_dir_args.force_btgt = ibtop;
22567 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
22568 + if (unlikely(err < 0))
22572 + au_fset_icpup(a->flags, DID_CPUP);
22575 + a->pin_flags = AuPin_MNT_WRITE;
22577 + if (!IS_ROOT(dentry)) {
22578 + au_fset_pin(a->pin_flags, DI_LOCKED);
22579 + parent = dget_parent(dentry);
22580 + di_write_lock_parent(parent);
22583 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
22584 + if (unlikely(err))
22588 + a->h_path.dentry = au_h_dptr(dentry, btop);
22589 + a->h_inode = d_inode(a->h_path.dentry);
22590 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
22591 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
22592 + if (ia->ia_size < i_size_read(a->h_inode))
22593 + sz = ia->ia_size;
22594 + inode_unlock_shared(a->h_inode);
22598 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
22599 + hi_wh = au_hi_wh(inode, a->btgt);
22601 + struct au_cp_generic cpg = {
22602 + .dentry = dentry,
22608 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
22609 + if (unlikely(err))
22611 + hi_wh = au_hi_wh(inode, a->btgt);
22612 + /* todo: revalidate hi_wh? */
22617 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
22618 + di_downgrade_lock(parent, AuLock_IR);
22622 + if (!au_ftest_icpup(a->flags, DID_CPUP))
22623 + goto out; /* success */
22625 + if (!d_unhashed(dentry)) {
22626 + struct au_cp_generic cpg = {
22627 + .dentry = dentry,
22632 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22634 + err = au_sio_cpup_simple(&cpg);
22636 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
22637 + } else if (!hi_wh)
22638 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
22640 + a->h_path.dentry = hi_wh; /* do not dget here */
22643 + a->h_inode = d_inode(a->h_path.dentry);
22645 + goto out; /* success */
22646 + au_unpin(&a->pin);
22649 + di_write_unlock(parent);
22654 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
22658 +static int aufs_setattr(struct user_namespace *userns, struct dentry *dentry,
22659 + struct iattr *ia)
22662 + struct inode *inode, *delegated;
22663 + struct super_block *sb;
22664 + struct file *file;
22665 + struct au_icpup_args *a;
22666 + struct user_namespace *h_userns;
22668 + inode = d_inode(dentry);
22669 + IMustLock(inode);
22671 + err = setattr_prepare(userns, dentry, ia);
22672 + if (unlikely(err))
22676 + a = kzalloc(sizeof(*a), GFP_NOFS);
22677 + if (unlikely(!a))
22680 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
22681 + ia->ia_valid &= ~ATTR_MODE;
22684 + sb = dentry->d_sb;
22685 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22686 + if (unlikely(err))
22689 + if (ia->ia_valid & ATTR_FILE) {
22690 + /* currently ftruncate(2) only */
22691 + AuDebugOn(!d_is_reg(dentry));
22692 + file = ia->ia_file;
22693 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
22695 + if (unlikely(err))
22697 + ia->ia_file = au_hf_top(file);
22698 + a->udba = AuOpt_UDBA_NONE;
22700 + /* fchmod() doesn't pass ia_file */
22701 + a->udba = au_opt_udba(sb);
22702 + di_write_lock_child(dentry);
22703 + /* no d_unlinked(), to set UDBA_NONE for root */
22704 + if (d_unhashed(dentry))
22705 + a->udba = AuOpt_UDBA_NONE;
22706 + if (a->udba != AuOpt_UDBA_NONE) {
22707 + AuDebugOn(IS_ROOT(dentry));
22708 + err = au_reval_for_attr(dentry, au_sigen(sb));
22709 + if (unlikely(err))
22714 + err = au_pin_and_icpup(dentry, ia, a);
22715 + if (unlikely(err < 0))
22717 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
22718 + ia->ia_file = NULL;
22719 + ia->ia_valid &= ~ATTR_FILE;
22722 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
22723 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
22724 + == (ATTR_MODE | ATTR_CTIME)) {
22725 + err = security_path_chmod(&a->h_path, ia->ia_mode);
22726 + if (unlikely(err))
22728 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
22729 + && (ia->ia_valid & ATTR_CTIME)) {
22730 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
22731 + if (unlikely(err))
22735 + if (ia->ia_valid & ATTR_SIZE) {
22738 + if (ia->ia_size < i_size_read(inode))
22740 + truncate_setsize(inode, ia->ia_size);
22743 + if (ia->ia_valid & ATTR_FILE)
22745 + inode_unlock(a->h_inode);
22746 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
22747 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
22749 + delegated = NULL;
22751 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
22753 + err = break_deleg_wait(&delegated);
22761 + * regardless aufs 'acl' option setting.
22762 + * why don't all acl-aware fs call this func from their ->setattr()?
22764 + if (!err && (ia->ia_valid & ATTR_MODE)) {
22765 + h_userns = mnt_user_ns(a->h_path.mnt);
22766 + err = vfsub_acl_chmod(h_userns, a->h_inode, ia->ia_mode);
22769 + au_cpup_attr_changeable(inode);
22772 + inode_unlock(a->h_inode);
22773 + au_unpin(&a->pin);
22774 + if (unlikely(err))
22775 + au_update_dbtop(dentry);
22777 + di_write_unlock(dentry);
22779 + fi_write_unlock(file);
22780 + ia->ia_file = file;
22781 + ia->ia_valid |= ATTR_FILE;
22784 + si_read_unlock(sb);
22792 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
22793 +static int au_h_path_to_set_attr(struct dentry *dentry,
22794 + struct au_icpup_args *a, struct path *h_path)
22797 + struct super_block *sb;
22799 + sb = dentry->d_sb;
22800 + a->udba = au_opt_udba(sb);
22801 + /* no d_unlinked(), to set UDBA_NONE for root */
22802 + if (d_unhashed(dentry))
22803 + a->udba = AuOpt_UDBA_NONE;
22804 + if (a->udba != AuOpt_UDBA_NONE) {
22805 + AuDebugOn(IS_ROOT(dentry));
22806 + err = au_reval_for_attr(dentry, au_sigen(sb));
22807 + if (unlikely(err))
22810 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
22811 + if (unlikely(err < 0))
22814 + h_path->dentry = a->h_path.dentry;
22815 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
22821 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
22822 + struct au_sxattr *arg)
22825 + struct path h_path;
22826 + struct super_block *sb;
22827 + struct au_icpup_args *a;
22828 + struct inode *h_inode;
22829 + struct user_namespace *h_userns;
22831 + IMustLock(inode);
22834 + a = kzalloc(sizeof(*a), GFP_NOFS);
22835 + if (unlikely(!a))
22838 + sb = dentry->d_sb;
22839 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22840 + if (unlikely(err))
22843 + h_path.dentry = NULL; /* silence gcc */
22844 + di_write_lock_child(dentry);
22845 + err = au_h_path_to_set_attr(dentry, a, &h_path);
22846 + if (unlikely(err))
22848 + h_userns = mnt_user_ns(h_path.mnt);
22850 + inode_unlock(a->h_inode);
22851 + switch (arg->type) {
22852 + case AU_XATTR_SET:
22853 + AuDebugOn(d_is_negative(h_path.dentry));
22854 + err = vfsub_setxattr(h_userns, h_path.dentry,
22855 + arg->u.set.name, arg->u.set.value,
22856 + arg->u.set.size, arg->u.set.flags);
22859 + err = -EOPNOTSUPP;
22860 + h_inode = d_inode(h_path.dentry);
22861 + if (h_inode->i_op->set_acl) {
22862 + /* this will call posix_acl_update_mode */
22863 + err = h_inode->i_op->set_acl(h_userns, h_inode,
22864 + arg->u.acl_set.acl,
22865 + arg->u.acl_set.type);
22870 + au_cpup_attr_timesizes(inode);
22872 + au_unpin(&a->pin);
22873 + if (unlikely(err))
22874 + au_update_dbtop(dentry);
22877 + di_write_unlock(dentry);
22878 + si_read_unlock(sb);
22887 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
22888 + unsigned int nlink)
22892 + inode->i_mode = st->mode;
22893 + /* don't i_[ug]id_write() here */
22894 + inode->i_uid = st->uid;
22895 + inode->i_gid = st->gid;
22896 + inode->i_atime = st->atime;
22897 + inode->i_mtime = st->mtime;
22898 + inode->i_ctime = st->ctime;
22900 + au_cpup_attr_nlink(inode, /*force*/0);
22901 + if (S_ISDIR(inode->i_mode)) {
22902 + n = inode->i_nlink;
22905 + smp_mb(); /* for i_nlink */
22906 + /* 0 can happen */
22907 + set_nlink(inode, n);
22910 + spin_lock(&inode->i_lock);
22911 + inode->i_blocks = st->blocks;
22912 + i_size_write(inode, st->size);
22913 + spin_unlock(&inode->i_lock);
22917 + * common routine for aufs_getattr() and au_getxattr().
22918 + * returns zero or negative (an error).
22919 + * @dentry will be read-locked in success.
22921 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
22922 + struct path *h_path, int locked)
22925 + unsigned int mnt_flags, sigen;
22926 + unsigned char udba_none;
22927 + aufs_bindex_t bindex;
22928 + struct super_block *sb, *h_sb;
22930 + h_path->mnt = NULL;
22931 + h_path->dentry = NULL;
22934 + sb = dentry->d_sb;
22935 + mnt_flags = au_mntflags(sb);
22936 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
22938 + if (unlikely(locked))
22939 + goto body; /* skip locking dinfo */
22941 + /* support fstat(2) */
22942 + if (!d_unlinked(dentry) && !udba_none) {
22943 + sigen = au_sigen(sb);
22944 + err = au_digen_test(dentry, sigen);
22946 + di_read_lock_child(dentry, AuLock_IR);
22947 + err = au_dbrange_test(dentry);
22948 + if (unlikely(err)) {
22949 + di_read_unlock(dentry, AuLock_IR);
22953 + AuDebugOn(IS_ROOT(dentry));
22954 + di_write_lock_child(dentry);
22955 + err = au_dbrange_test(dentry);
22957 + err = au_reval_for_attr(dentry, sigen);
22959 + di_downgrade_lock(dentry, AuLock_IR);
22961 + di_write_unlock(dentry);
22966 + di_read_lock_child(dentry, AuLock_IR);
22970 + inode = d_inode(dentry);
22971 + if (unlikely(!inode))
22974 + bindex = au_ibtop(inode);
22975 + h_path->mnt = au_sbr_mnt(sb, bindex);
22976 + h_sb = h_path->mnt->mnt_sb;
22978 + && !au_test_fs_bad_iattr(h_sb)
22980 + goto out; /* success */
22982 + if (au_dbtop(dentry) == bindex)
22983 + h_path->dentry = au_h_dptr(dentry, bindex);
22984 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
22985 + h_path->dentry = au_plink_lkup(inode, bindex);
22986 + if (IS_ERR(h_path->dentry))
22987 + /* pretending success */
22988 + h_path->dentry = NULL;
22990 + dput(h_path->dentry);
22997 +static int aufs_getattr(struct user_namespace *userns, const struct path *path,
22998 + struct kstat *st, u32 request, unsigned int query)
23001 + unsigned char positive;
23002 + struct path h_path;
23003 + struct dentry *dentry;
23004 + struct inode *inode;
23005 + struct super_block *sb;
23007 + dentry = path->dentry;
23008 + inode = d_inode(dentry);
23009 + sb = dentry->d_sb;
23010 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
23011 + if (unlikely(err))
23013 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
23015 + if (unlikely(err))
23017 + if (unlikely(!h_path.dentry))
23018 + /* illegally overlapped or something */
23019 + goto out_fill; /* pretending success */
23021 + positive = d_is_positive(h_path.dentry);
23023 + /* no vfsub version */
23024 + err = vfs_getattr(&h_path, st, request, query);
23027 + au_refresh_iattr(inode, st,
23028 + d_inode(h_path.dentry)->i_nlink);
23029 + goto out_fill; /* success */
23035 + generic_fillattr(userns, inode, st);
23037 + di_read_unlock(dentry, AuLock_IR);
23039 + si_read_unlock(sb);
23045 +/* ---------------------------------------------------------------------- */
23047 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
23048 + struct delayed_call *done)
23051 + struct dentry *h_dentry;
23052 + struct inode *h_inode;
23054 + aufs_bindex_t bindex;
23056 + ret = NULL; /* suppress a warning */
23061 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
23062 + if (unlikely(err))
23065 + err = au_d_hashed_positive(dentry);
23066 + if (unlikely(err))
23070 + inode = d_inode(dentry);
23071 + bindex = au_ibtop(inode);
23072 + h_inode = au_h_iptr(inode, bindex);
23073 + if (unlikely(!h_inode->i_op->get_link))
23078 + if (au_dbtop(dentry) <= bindex) {
23079 + h_dentry = au_h_dptr(dentry, bindex);
23084 + h_dentry = d_find_any_alias(h_inode);
23085 + if (IS_ERR(h_dentry)) {
23086 + err = PTR_ERR(h_dentry);
23090 + if (unlikely(!h_dentry))
23094 + AuDbg("%ps\n", h_inode->i_op->get_link);
23095 + AuDbgDentry(h_dentry);
23096 + ret = vfs_get_link(h_dentry, done);
23099 + err = PTR_ERR(ret);
23102 + aufs_read_unlock(dentry, AuLock_IR);
23104 + if (unlikely(err))
23105 + ret = ERR_PTR(err);
23106 + AuTraceErrPtr(ret);
23110 +/* ---------------------------------------------------------------------- */
23112 +static int au_is_special(struct inode *inode)
23114 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
23117 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
23121 + aufs_bindex_t bindex;
23122 + struct super_block *sb;
23123 + struct inode *h_inode;
23124 + struct vfsmount *h_mnt;
23126 + sb = inode->i_sb;
23127 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
23128 + "unexpected s_flags 0x%lx", sb->s_flags);
23130 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
23132 + si_read_lock(sb, AuLock_FLUSH);
23133 + ii_write_lock_child(inode);
23136 + bindex = au_ibtop(inode);
23137 + h_inode = au_h_iptr(inode, bindex);
23138 + if (!au_test_ro(sb, bindex, inode)) {
23139 + h_mnt = au_sbr_mnt(sb, bindex);
23140 + err = vfsub_mnt_want_write(h_mnt);
23142 + err = vfsub_update_time(h_inode, ts, flags);
23143 + vfsub_mnt_drop_write(h_mnt);
23145 + } else if (au_is_special(h_inode)) {
23147 + * Never copy-up here.
23148 + * These special files may already be opened and used for
23149 + * communicating. If we copied it up, then the communication
23150 + * would be corrupted.
23152 + AuWarn1("timestamps for i%lu are ignored "
23153 + "since it is on readonly branch (hi%lu).\n",
23154 + inode->i_ino, h_inode->i_ino);
23155 + } else if (flags & ~S_ATIME) {
23157 + AuIOErr1("unexpected flags 0x%x\n", flags);
23162 + au_cpup_attr_timesizes(inode);
23163 + ii_write_unlock(inode);
23164 + si_read_unlock(sb);
23167 + if (!err && (flags & S_VERSION))
23168 + inode_inc_iversion(inode);
23173 +/* ---------------------------------------------------------------------- */
23175 +/* no getattr version will be set by module.c:aufs_init() */
23176 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
23178 + [AuIop_SYMLINK] = {
23179 + .permission = aufs_permission,
23180 +#ifdef CONFIG_FS_POSIX_ACL
23181 + .get_acl = aufs_get_acl,
23182 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
23185 + .setattr = aufs_setattr,
23186 + .getattr = aufs_getattr,
23188 +#ifdef CONFIG_AUFS_XATTR
23189 + .listxattr = aufs_listxattr,
23192 + .get_link = aufs_get_link
23194 + /* .update_time = aufs_update_time */
23197 + .create = aufs_create,
23198 + .lookup = aufs_lookup,
23199 + .link = aufs_link,
23200 + .unlink = aufs_unlink,
23201 + .symlink = aufs_symlink,
23202 + .mkdir = aufs_mkdir,
23203 + .rmdir = aufs_rmdir,
23204 + .mknod = aufs_mknod,
23205 + .rename = aufs_rename,
23207 + .permission = aufs_permission,
23208 +#ifdef CONFIG_FS_POSIX_ACL
23209 + .get_acl = aufs_get_acl,
23210 + .set_acl = aufs_set_acl,
23213 + .setattr = aufs_setattr,
23214 + .getattr = aufs_getattr,
23216 +#ifdef CONFIG_AUFS_XATTR
23217 + .listxattr = aufs_listxattr,
23220 + .update_time = aufs_update_time,
23221 + .atomic_open = aufs_atomic_open,
23222 + .tmpfile = aufs_tmpfile
23224 + [AuIop_OTHER] = {
23225 + .permission = aufs_permission,
23226 +#ifdef CONFIG_FS_POSIX_ACL
23227 + .get_acl = aufs_get_acl,
23228 + .set_acl = aufs_set_acl,
23231 + .setattr = aufs_setattr,
23232 + .getattr = aufs_getattr,
23234 +#ifdef CONFIG_AUFS_XATTR
23235 + .listxattr = aufs_listxattr,
23238 + .update_time = aufs_update_time
23241 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
23242 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
23243 +++ linux/fs/aufs/i_op_del.c 2022-11-05 23:02:18.965889284 +0100
23245 +// SPDX-License-Identifier: GPL-2.0
23247 + * Copyright (C) 2005-2022 Junjiro R. Okajima
23249 + * This program is free software; you can redistribute it and/or modify
23250 + * it under the terms of the GNU General Public License as published by
23251 + * the Free Software Foundation; either version 2 of the License, or
23252 + * (at your option) any later version.
23254 + * This program is distributed in the hope that it will be useful,
23255 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23256 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23257 + * GNU General Public License for more details.
23259 + * You should have received a copy of the GNU General Public License
23260 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23264 + * inode operations (del entry)
23267 +#include <linux/iversion.h>
23271 + * decide if a new whiteout for @dentry is necessary or not.
23272 + * when it is necessary, prepare the parent dir for the upper branch whose
23273 + * branch index is @bcpup for creation. the actual creation of the whiteout will
23274 + * be done by caller.
23276 + * 0: wh is unnecessary
23277 + * plus: wh is necessary
23280 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
23282 + int need_wh, err;
23283 + aufs_bindex_t btop;
23284 + struct super_block *sb;
23286 + sb = dentry->d_sb;
23287 + btop = au_dbtop(dentry);
23288 + if (*bcpup < 0) {
23290 + if (au_test_ro(sb, btop, d_inode(dentry))) {
23291 + err = AuWbrCopyup(au_sbi(sb), dentry);
23293 + if (unlikely(err < 0))
23297 + AuDebugOn(btop < *bcpup
23298 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
23299 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
23301 + if (*bcpup != btop) {
23302 + err = au_cpup_dirs(dentry, *bcpup);
23303 + if (unlikely(err))
23307 + struct au_dinfo *dinfo, *tmp;
23309 + need_wh = -ENOMEM;
23310 + dinfo = au_di(dentry);
23311 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
23313 + au_di_cp(tmp, dinfo);
23314 + au_di_swap(tmp, dinfo);
23315 + /* returns the number of positive dentries */
23316 + need_wh = au_lkup_dentry(dentry, btop + 1,
23317 + /* AuLkup_IGNORE_PERM */ 0);
23318 + au_di_swap(tmp, dinfo);
23319 + au_rw_write_unlock(&tmp->di_rwsem);
23323 + AuDbg("need_wh %d\n", need_wh);
23331 + * simple tests for the del-entry operations.
23332 + * following the checks in vfs, plus the parent-child relationship.
23334 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
23335 + struct dentry *h_parent, int isdir)
23339 + struct dentry *h_dentry, *h_latest;
23340 + struct inode *h_inode;
23341 + struct path h_ppath;
23342 + struct super_block *sb;
23343 + struct au_branch *br;
23344 + struct user_namespace *h_userns;
23346 + h_dentry = au_h_dptr(dentry, bindex);
23347 + if (d_really_is_positive(dentry)) {
23349 + if (unlikely(d_is_negative(h_dentry)))
23351 + h_inode = d_inode(h_dentry);
23352 + if (unlikely(!h_inode->i_nlink))
23355 + h_mode = h_inode->i_mode;
23358 + if (unlikely(S_ISDIR(h_mode)))
23360 + } else if (unlikely(!S_ISDIR(h_mode))) {
23365 + /* rename(2) case */
23367 + if (unlikely(d_is_positive(h_dentry)))
23372 + /* expected parent dir is locked */
23373 + if (unlikely(h_parent != h_dentry->d_parent))
23378 + * rmdir a dir may break the consistency on some filesystem.
23379 + * let's try heavy test.
23382 + sb = dentry->d_sb;
23383 + br = au_sbr(sb, bindex);
23384 + h_userns = au_br_userns(br);
23385 + if (unlikely(!au_opt_test(au_mntflags(sb), DIRPERM1)
23386 + && au_test_h_perm(h_userns, d_inode(h_parent),
23387 + MAY_EXEC | MAY_WRITE)))
23390 + h_ppath.dentry = h_parent;
23391 + h_ppath.mnt = au_br_mnt(br);
23392 + h_latest = au_sio_lkup_one(h_userns, &dentry->d_name, &h_ppath);
23394 + if (IS_ERR(h_latest))
23396 + if (h_latest == h_dentry)
23405 + * decide the branch where we operate for @dentry. the branch index will be set
23406 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
23407 + * dir for reverting.
23408 + * when a new whiteout is necessary, create it.
23410 +static struct dentry*
23411 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
23412 + struct au_dtime *dt, struct au_pin *pin)
23414 + struct dentry *wh_dentry;
23415 + struct super_block *sb;
23416 + struct path h_path;
23417 + int err, need_wh;
23418 + unsigned int udba;
23419 + aufs_bindex_t bcpup;
23421 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
23422 + wh_dentry = ERR_PTR(need_wh);
23423 + if (unlikely(need_wh < 0))
23426 + sb = dentry->d_sb;
23427 + udba = au_opt_udba(sb);
23429 + err = au_pin(pin, dentry, bcpup, udba,
23430 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23431 + wh_dentry = ERR_PTR(err);
23432 + if (unlikely(err))
23435 + h_path.dentry = au_pinned_h_parent(pin);
23436 + if (udba != AuOpt_UDBA_NONE
23437 + && au_dbtop(dentry) == bcpup) {
23438 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
23439 + wh_dentry = ERR_PTR(err);
23440 + if (unlikely(err))
23444 + h_path.mnt = au_sbr_mnt(sb, bcpup);
23445 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
23446 + wh_dentry = NULL;
23448 + goto out; /* success, no need to create whiteout */
23450 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
23451 + if (IS_ERR(wh_dentry))
23454 + /* returns with the parent is locked and wh_dentry is dget-ed */
23455 + goto out; /* success */
23460 + return wh_dentry;
23464 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
23465 + * in order to be revertible and save time for removing many child whiteouts
23467 + * returns 1 when there are too many child whiteout and caller should remove
23468 + * them asynchronously. returns 0 when the number of children is enough small to
23469 + * remove now or the branch fs is a remote fs.
23470 + * otherwise return an error.
23472 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
23473 + struct au_nhash *whlist, struct inode *dir)
23475 + int rmdir_later, err, dirwh;
23476 + struct dentry *h_dentry;
23477 + struct super_block *sb;
23478 + struct inode *inode;
23480 + sb = dentry->d_sb;
23481 + SiMustAnyLock(sb);
23482 + h_dentry = au_h_dptr(dentry, bindex);
23483 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
23484 + if (unlikely(err))
23487 + /* stop monitoring */
23488 + inode = d_inode(dentry);
23489 + au_hn_free(au_hi(inode, bindex));
23491 + if (!au_test_fs_remote(h_dentry->d_sb)) {
23492 + dirwh = au_sbi(sb)->si_dirwh;
23493 + rmdir_later = (dirwh <= 1);
23494 + if (!rmdir_later)
23495 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
23498 + return rmdir_later;
23501 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
23502 + if (unlikely(err)) {
23503 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
23504 + h_dentry, bindex, err);
23514 + * final procedure for deleting a entry.
23515 + * maintain dentry and iattr.
23517 +static void epilog(struct inode *dir, struct dentry *dentry,
23518 + aufs_bindex_t bindex)
23520 + struct inode *inode;
23522 + inode = d_inode(dentry);
23524 + inode->i_ctime = dir->i_ctime;
23526 + au_dir_ts(dir, bindex);
23527 + inode_inc_iversion(dir);
23531 + * when an error happened, remove the created whiteout and revert everything.
23533 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
23534 + aufs_bindex_t bwh, struct dentry *wh_dentry,
23535 + struct dentry *dentry, struct au_dtime *dt)
23538 + struct path h_path = {
23539 + .dentry = wh_dentry,
23540 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
23543 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
23545 + au_set_dbwh(dentry, bwh);
23546 + au_dtime_revert(dt);
23550 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
23554 +/* ---------------------------------------------------------------------- */
23556 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
23559 + aufs_bindex_t bwh, bindex, btop;
23560 + struct inode *inode, *h_dir, *delegated;
23561 + struct dentry *parent, *wh_dentry;
23562 + /* to reduce stack size */
23564 + struct au_dtime dt;
23565 + struct au_pin pin;
23566 + struct path h_path;
23572 + a = kmalloc(sizeof(*a), GFP_NOFS);
23573 + if (unlikely(!a))
23576 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
23577 + if (unlikely(err))
23579 + err = au_d_hashed_positive(dentry);
23580 + if (unlikely(err))
23582 + inode = d_inode(dentry);
23583 + IMustLock(inode);
23585 + if (unlikely(d_is_dir(dentry)))
23586 + goto out_unlock; /* possible? */
23588 + btop = au_dbtop(dentry);
23589 + bwh = au_dbwh(dentry);
23591 + parent = dentry->d_parent; /* dir inode is locked */
23592 + di_write_lock_parent(parent);
23593 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
23595 + err = PTR_ERR(wh_dentry);
23596 + if (IS_ERR(wh_dentry))
23599 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
23600 + a->h_path.dentry = au_h_dptr(dentry, btop);
23601 + dget(a->h_path.dentry);
23602 + if (bindex == btop) {
23603 + h_dir = au_pinned_h_dir(&a->pin);
23604 + delegated = NULL;
23605 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
23606 + if (unlikely(err == -EWOULDBLOCK)) {
23607 + pr_warn("cannot retry for NFSv4 delegation"
23608 + " for an internal unlink\n");
23612 + /* dir inode is locked */
23613 + h_dir = d_inode(wh_dentry->d_parent);
23614 + IMustLock(h_dir);
23619 + vfsub_drop_nlink(inode);
23620 + epilog(dir, dentry, bindex);
23622 + /* update target timestamps */
23623 + if (bindex == btop) {
23624 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
23626 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23628 + /* todo: this timestamp may be reverted later */
23629 + inode->i_ctime = h_dir->i_ctime;
23630 + goto out_unpin; /* success */
23637 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
23644 + au_unpin(&a->pin);
23646 + dput(a->h_path.dentry);
23648 + di_write_unlock(parent);
23650 + aufs_read_unlock(dentry, AuLock_DW);
23657 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
23659 + int err, rmdir_later;
23660 + aufs_bindex_t bwh, bindex, btop;
23661 + struct inode *inode;
23662 + struct dentry *parent, *wh_dentry, *h_dentry;
23663 + struct au_whtmp_rmdir *args;
23664 + /* to reduce stack size */
23666 + struct au_dtime dt;
23667 + struct au_pin pin;
23673 + a = kmalloc(sizeof(*a), GFP_NOFS);
23674 + if (unlikely(!a))
23677 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
23678 + if (unlikely(err))
23680 + err = au_alive_dir(dentry);
23681 + if (unlikely(err))
23683 + inode = d_inode(dentry);
23684 + IMustLock(inode);
23686 + if (unlikely(!d_is_dir(dentry)))
23687 + goto out_unlock; /* possible? */
23690 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
23691 + if (unlikely(!args))
23694 + parent = dentry->d_parent; /* dir inode is locked */
23695 + di_write_lock_parent(parent);
23696 + err = au_test_empty(dentry, &args->whlist);
23697 + if (unlikely(err))
23700 + btop = au_dbtop(dentry);
23701 + bwh = au_dbwh(dentry);
23703 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
23705 + err = PTR_ERR(wh_dentry);
23706 + if (IS_ERR(wh_dentry))
23709 + h_dentry = au_h_dptr(dentry, btop);
23712 + if (bindex == btop) {
23713 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
23715 + rmdir_later = err;
23719 + /* stop monitoring */
23720 + au_hn_free(au_hi(inode, btop));
23722 + /* dir inode is locked */
23723 + IMustLock(d_inode(wh_dentry->d_parent));
23728 + vfsub_dead_dir(inode);
23729 + au_set_dbdiropq(dentry, -1);
23730 + epilog(dir, dentry, bindex);
23732 + if (rmdir_later) {
23733 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
23737 + goto out_unpin; /* success */
23745 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
23752 + au_unpin(&a->pin);
23756 + di_write_unlock(parent);
23758 + au_whtmp_rmdir_free(args);
23760 + aufs_read_unlock(dentry, AuLock_DW);
23767 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
23768 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
23769 +++ linux/fs/aufs/i_op_ren.c 2022-11-05 23:02:18.965889284 +0100
23771 +// SPDX-License-Identifier: GPL-2.0
23773 + * Copyright (C) 2005-2022 Junjiro R. Okajima
23775 + * This program is free software; you can redistribute it and/or modify
23776 + * it under the terms of the GNU General Public License as published by
23777 + * the Free Software Foundation; either version 2 of the License, or
23778 + * (at your option) any later version.
23780 + * This program is distributed in the hope that it will be useful,
23781 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23782 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23783 + * GNU General Public License for more details.
23785 + * You should have received a copy of the GNU General Public License
23786 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23790 + * inode operation (rename entry)
23791 + * todo: this is crazy monster
23794 +#include <linux/iversion.h>
23797 +enum { AuSRC, AuDST, AuSrcDst };
23798 +enum { AuPARENT, AuCHILD, AuParentChild };
23800 +#define AuRen_ISDIR_SRC 1
23801 +#define AuRen_ISDIR_DST (1 << 1)
23802 +#define AuRen_ISSAMEDIR (1 << 2)
23803 +#define AuRen_WHSRC (1 << 3)
23804 +#define AuRen_WHDST (1 << 4)
23805 +#define AuRen_MNT_WRITE (1 << 5)
23806 +#define AuRen_DT_DSTDIR (1 << 6)
23807 +#define AuRen_DIROPQ_SRC (1 << 7)
23808 +#define AuRen_DIROPQ_DST (1 << 8)
23809 +#define AuRen_DIRREN (1 << 9)
23810 +#define AuRen_DROPPED_SRC (1 << 10)
23811 +#define AuRen_DROPPED_DST (1 << 11)
23812 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
23813 +#define au_fset_ren(flags, name) \
23814 + do { (flags) |= AuRen_##name; } while (0)
23815 +#define au_fclr_ren(flags, name) \
23816 + do { (flags) &= ~AuRen_##name; } while (0)
23818 +#ifndef CONFIG_AUFS_DIRREN
23819 +#undef AuRen_DIRREN
23820 +#define AuRen_DIRREN 0
23823 +struct au_ren_args {
23825 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
23827 + struct inode *dir, *inode;
23828 + struct au_hinode *hdir, *hinode;
23829 + struct au_dtime dt[AuParentChild];
23830 + aufs_bindex_t btop, bdiropq;
23833 +#define src_dentry sd[AuSRC].dentry
23834 +#define src_dir sd[AuSRC].dir
23835 +#define src_inode sd[AuSRC].inode
23836 +#define src_h_dentry sd[AuSRC].h_dentry
23837 +#define src_parent sd[AuSRC].parent
23838 +#define src_h_parent sd[AuSRC].h_parent
23839 +#define src_wh_dentry sd[AuSRC].wh_dentry
23840 +#define src_hdir sd[AuSRC].hdir
23841 +#define src_hinode sd[AuSRC].hinode
23842 +#define src_h_dir sd[AuSRC].hdir->hi_inode
23843 +#define src_dt sd[AuSRC].dt
23844 +#define src_btop sd[AuSRC].btop
23845 +#define src_bdiropq sd[AuSRC].bdiropq
23847 +#define dst_dentry sd[AuDST].dentry
23848 +#define dst_dir sd[AuDST].dir
23849 +#define dst_inode sd[AuDST].inode
23850 +#define dst_h_dentry sd[AuDST].h_dentry
23851 +#define dst_parent sd[AuDST].parent
23852 +#define dst_h_parent sd[AuDST].h_parent
23853 +#define dst_wh_dentry sd[AuDST].wh_dentry
23854 +#define dst_hdir sd[AuDST].hdir
23855 +#define dst_hinode sd[AuDST].hinode
23856 +#define dst_h_dir sd[AuDST].hdir->hi_inode
23857 +#define dst_dt sd[AuDST].dt
23858 +#define dst_btop sd[AuDST].btop
23859 +#define dst_bdiropq sd[AuDST].bdiropq
23861 + struct dentry *h_trap;
23862 + struct au_branch *br;
23863 + struct path h_path;
23864 + struct au_nhash whlist;
23865 + aufs_bindex_t btgt, src_bwh;
23868 + unsigned short auren_flags;
23869 + unsigned char flags; /* syscall parameter */
23870 + unsigned char exchange;
23873 + struct au_whtmp_rmdir *thargs;
23874 + struct dentry *h_dst;
23875 + struct au_hinode *h_root;
23878 +/* ---------------------------------------------------------------------- */
23881 + * functions for reverting.
23882 + * when an error happened in a single rename systemcall, we should revert
23883 + * everything as if nothing happened.
23884 + * we don't need to revert the copied-up/down the parent dir since they are
23888 +#define RevertFailure(fmt, ...) do { \
23889 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
23890 + ##__VA_ARGS__, err, rerr); \
23894 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
23897 + struct dentry *d;
23898 +#define src_or_dst(member) a->sd[idx].member
23900 + d = src_or_dst(dentry); /* {src,dst}_dentry */
23901 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
23902 + rerr = au_diropq_remove(d, a->btgt);
23903 + au_hn_inode_unlock(src_or_dst(hinode));
23904 + au_set_dbdiropq(d, src_or_dst(bdiropq));
23906 + RevertFailure("remove diropq %pd", d);
23908 +#undef src_or_dst_
23911 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
23913 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
23914 + au_ren_do_rev_diropq(err, a, AuSRC);
23915 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
23916 + au_ren_do_rev_diropq(err, a, AuDST);
23919 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
23922 + struct inode *delegated;
23923 + struct path h_ppath = {
23924 + .dentry = a->src_h_parent,
23925 + .mnt = a->h_path.mnt
23928 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, &h_ppath);
23929 + rerr = PTR_ERR(a->h_path.dentry);
23930 + if (IS_ERR(a->h_path.dentry)) {
23931 + RevertFailure("lkup one %pd", a->src_dentry);
23935 + delegated = NULL;
23936 + rerr = vfsub_rename(a->dst_h_dir,
23937 + au_h_dptr(a->src_dentry, a->btgt),
23938 + a->src_h_dir, &a->h_path, &delegated, a->flags);
23939 + if (unlikely(rerr == -EWOULDBLOCK)) {
23940 + pr_warn("cannot retry for NFSv4 delegation"
23941 + " for an internal rename\n");
23944 + d_drop(a->h_path.dentry);
23945 + dput(a->h_path.dentry);
23946 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
23948 + RevertFailure("rename %pd", a->src_dentry);
23951 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
23954 + struct inode *delegated;
23955 + struct path h_ppath = {
23956 + .dentry = a->dst_h_parent,
23957 + .mnt = a->h_path.mnt
23960 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, &h_ppath);
23961 + rerr = PTR_ERR(a->h_path.dentry);
23962 + if (IS_ERR(a->h_path.dentry)) {
23963 + RevertFailure("lkup one %pd", a->dst_dentry);
23966 + if (d_is_positive(a->h_path.dentry)) {
23967 + d_drop(a->h_path.dentry);
23968 + dput(a->h_path.dentry);
23972 + delegated = NULL;
23973 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
23974 + &delegated, a->flags);
23975 + if (unlikely(rerr == -EWOULDBLOCK)) {
23976 + pr_warn("cannot retry for NFSv4 delegation"
23977 + " for an internal rename\n");
23980 + d_drop(a->h_path.dentry);
23981 + dput(a->h_path.dentry);
23983 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
23985 + RevertFailure("rename %pd", a->h_dst);
23988 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
23992 + a->h_path.dentry = a->src_wh_dentry;
23993 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
23994 + au_set_dbwh(a->src_dentry, a->src_bwh);
23996 + RevertFailure("unlink %pd", a->src_wh_dentry);
23998 +#undef RevertFailure
24000 +/* ---------------------------------------------------------------------- */
24003 + * when we have to copyup the renaming entry, do it with the rename-target name
24004 + * in order to minimize the cost (the later actual rename is unnecessary).
24005 + * otherwise rename it on the target branch.
24007 +static int au_ren_or_cpup(struct au_ren_args *a)
24010 + struct dentry *d;
24011 + struct inode *delegated;
24013 + d = a->src_dentry;
24014 + if (au_dbtop(d) == a->btgt) {
24015 + a->h_path.dentry = a->dst_h_dentry;
24016 + AuDebugOn(au_dbtop(d) != a->btgt);
24017 + delegated = NULL;
24018 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
24019 + a->dst_h_dir, &a->h_path, &delegated,
24021 + if (unlikely(err == -EWOULDBLOCK)) {
24022 + pr_warn("cannot retry for NFSv4 delegation"
24023 + " for an internal rename\n");
24029 + if (!err && a->h_dst)
24030 + /* it will be set to dinfo later */
24036 +/* cf. aufs_rmdir() */
24037 +static int au_ren_del_whtmp(struct au_ren_args *a)
24040 + struct inode *dir;
24042 + dir = a->dst_dir;
24043 + SiMustAnyLock(dir->i_sb);
24044 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
24045 + au_sbi(dir->i_sb)->si_dirwh)
24046 + || au_test_fs_remote(a->h_dst->d_sb)) {
24047 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
24048 + if (unlikely(err))
24049 + pr_warn("failed removing whtmp dir %pd (%d), "
24050 + "ignored.\n", a->h_dst, err);
24052 + au_nhash_wh_free(&a->thargs->whlist);
24053 + a->thargs->whlist = a->whlist;
24054 + a->whlist.nh_num = 0;
24055 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
24057 + a->thargs = NULL;
24063 +/* make it 'opaque' dir. */
24064 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
24067 + struct dentry *d, *diropq;
24068 +#define src_or_dst(member) a->sd[idx].member
24071 + d = src_or_dst(dentry); /* {src,dst}_dentry */
24072 + src_or_dst(bdiropq) = au_dbdiropq(d);
24073 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
24074 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
24075 + diropq = au_diropq_create(d, a->btgt);
24076 + au_hn_inode_unlock(src_or_dst(hinode));
24077 + if (IS_ERR(diropq))
24078 + err = PTR_ERR(diropq);
24082 +#undef src_or_dst_
24086 +static int au_ren_diropq(struct au_ren_args *a)
24089 + unsigned char always;
24090 + struct dentry *d;
24093 + d = a->dst_dentry; /* already renamed on the branch */
24094 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
24095 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
24096 + && !au_ftest_ren(a->auren_flags, DIRREN)
24097 + && a->btgt != au_dbdiropq(a->src_dentry)
24098 + && (a->dst_wh_dentry
24099 + || a->btgt <= au_dbdiropq(d)
24100 + /* hide the lower to keep xino */
24101 + /* the lowers may not be a dir, but we hide them anyway */
24102 + || a->btgt < au_dbbot(d)
24105 + err = au_ren_do_diropq(a, AuSRC);
24106 + if (unlikely(err))
24108 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
24110 + if (!a->exchange)
24111 + goto out; /* success */
24113 + d = a->src_dentry; /* already renamed on the branch */
24114 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
24115 + && a->btgt != au_dbdiropq(a->dst_dentry)
24116 + && (a->btgt < au_dbdiropq(d)
24117 + || a->btgt < au_dbbot(d)
24119 + AuDbgDentry(a->src_dentry);
24120 + AuDbgDentry(a->dst_dentry);
24121 + err = au_ren_do_diropq(a, AuDST);
24122 + if (unlikely(err))
24123 + goto out_rev_src;
24124 + au_fset_ren(a->auren_flags, DIROPQ_DST);
24126 + goto out; /* success */
24129 + AuDbg("err %d, reverting src\n", err);
24130 + au_ren_rev_diropq(err, a);
24135 +static int do_rename(struct au_ren_args *a)
24138 + struct dentry *d, *h_d;
24140 + if (!a->exchange) {
24141 + /* prepare workqueue args for asynchronous rmdir */
24142 + h_d = a->dst_h_dentry;
24143 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
24144 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
24145 + && d_is_positive(h_d)) {
24147 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
24149 + if (unlikely(!a->thargs))
24151 + a->h_dst = dget(h_d);
24154 + /* create whiteout for src_dentry */
24155 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
24156 + a->src_bwh = au_dbwh(a->src_dentry);
24157 + AuDebugOn(a->src_bwh >= 0);
24158 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
24159 + a->src_h_parent);
24160 + err = PTR_ERR(a->src_wh_dentry);
24161 + if (IS_ERR(a->src_wh_dentry))
24165 + /* lookup whiteout for dentry */
24166 + if (au_ftest_ren(a->auren_flags, WHDST)) {
24167 + h_d = au_wh_lkup(a->dst_h_parent,
24168 + &a->dst_dentry->d_name, a->br);
24169 + err = PTR_ERR(h_d);
24172 + if (d_is_negative(h_d))
24175 + a->dst_wh_dentry = h_d;
24178 + /* rename dentry to tmpwh */
24180 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
24181 + if (unlikely(err))
24184 + d = a->dst_dentry;
24185 + au_set_h_dptr(d, a->btgt, NULL);
24186 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
24187 + if (unlikely(err))
24189 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
24193 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
24194 +#if 0 /* debugging */
24195 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
24196 + && d_is_positive(a->dst_h_dentry)
24197 + && a->src_btop != a->btgt);
24200 + /* rename by vfs_rename or cpup */
24201 + err = au_ren_or_cpup(a);
24202 + if (unlikely(err))
24203 + /* leave the copied-up one */
24206 + /* make dir opaque */
24207 + err = au_ren_diropq(a);
24208 + if (unlikely(err))
24211 + /* update target timestamps */
24212 + if (a->exchange) {
24213 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
24214 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
24215 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
24216 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
24218 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
24219 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
24220 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
24221 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
24223 + if (!a->exchange) {
24224 + /* remove whiteout for dentry */
24225 + if (a->dst_wh_dentry) {
24226 + a->h_path.dentry = a->dst_wh_dentry;
24227 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
24229 + if (unlikely(err))
24233 + /* remove whtmp */
24235 + au_ren_del_whtmp(a); /* ignore this error */
24237 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
24240 + goto out_success;
24243 + au_ren_rev_diropq(err, a);
24245 + au_ren_rev_rename(err, a);
24249 + au_ren_rev_whtmp(err, a);
24251 + dput(a->dst_wh_dentry);
24252 + a->dst_wh_dentry = NULL;
24254 + if (a->src_wh_dentry)
24255 + au_ren_rev_whsrc(err, a);
24257 + dput(a->src_wh_dentry);
24258 + dput(a->dst_wh_dentry);
24262 + au_whtmp_rmdir_free(a->thargs);
24263 + a->thargs = NULL;
24269 +/* ---------------------------------------------------------------------- */
24272 + * test if @dentry dir can be rename destination or not.
24273 + * success means, it is a logically empty dir.
24275 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
24277 + return au_test_empty(dentry, whlist);
24281 + * test if @a->src_dentry dir can be rename source or not.
24282 + * if it can, return 0.
24284 + * - it is a logically empty dir.
24285 + * - or, it exists on writable branch and has no children including whiteouts
24286 + * on the lower branch unless DIRREN is on.
24288 +static int may_rename_srcdir(struct au_ren_args *a)
24291 + unsigned int rdhash;
24292 + aufs_bindex_t btop, btgt;
24293 + struct dentry *dentry;
24294 + struct super_block *sb;
24295 + struct au_sbinfo *sbinfo;
24297 + dentry = a->src_dentry;
24298 + sb = dentry->d_sb;
24299 + sbinfo = au_sbi(sb);
24300 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
24301 + au_fset_ren(a->auren_flags, DIRREN);
24304 + btop = au_dbtop(dentry);
24305 + if (btop != btgt) {
24306 + struct au_nhash whlist;
24308 + SiMustAnyLock(sb);
24309 + rdhash = sbinfo->si_rdhash;
24311 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
24313 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
24314 + if (unlikely(err))
24316 + err = au_test_empty(dentry, &whlist);
24317 + au_nhash_wh_free(&whlist);
24321 + if (btop == au_dbtaildir(dentry))
24322 + return 0; /* success */
24324 + err = au_test_empty_lower(dentry);
24327 + if (err == -ENOTEMPTY) {
24328 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24331 + AuWarn1("renaming dir who has child(ren) on multiple "
24332 + "branches, is not supported\n");
24339 +/* side effect: sets whlist and h_dentry */
24340 +static int au_ren_may_dir(struct au_ren_args *a)
24343 + unsigned int rdhash;
24344 + struct dentry *d;
24346 + d = a->dst_dentry;
24347 + SiMustAnyLock(d->d_sb);
24350 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
24351 + rdhash = au_sbi(d->d_sb)->si_rdhash;
24353 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
24354 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
24355 + if (unlikely(err))
24358 + if (!a->exchange) {
24359 + au_set_dbtop(d, a->dst_btop);
24360 + err = may_rename_dstdir(d, &a->whlist);
24361 + au_set_dbtop(d, a->btgt);
24363 + err = may_rename_srcdir(a);
24365 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
24366 + if (unlikely(err))
24369 + d = a->src_dentry;
24370 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
24371 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
24372 + err = may_rename_srcdir(a);
24373 + if (unlikely(err)) {
24374 + au_nhash_wh_free(&a->whlist);
24375 + a->whlist.nh_num = 0;
24382 +/* ---------------------------------------------------------------------- */
24385 + * simple tests for rename.
24386 + * following the checks in vfs, plus the parent-child relationship.
24388 +static int au_may_ren(struct au_ren_args *a)
24391 + struct inode *h_inode;
24393 + if (a->src_btop == a->btgt) {
24394 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
24395 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
24396 + if (unlikely(err))
24399 + if (unlikely(a->src_h_dentry == a->h_trap))
24404 + if (a->dst_btop != a->btgt)
24407 + err = -ENOTEMPTY;
24408 + if (unlikely(a->dst_h_dentry == a->h_trap))
24412 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
24413 + if (d_really_is_negative(a->dst_dentry)) {
24414 + if (d_is_negative(a->dst_h_dentry))
24415 + err = au_may_add(a->dst_dentry, a->btgt,
24416 + a->dst_h_parent, isdir);
24418 + if (unlikely(d_is_negative(a->dst_h_dentry)))
24420 + h_inode = d_inode(a->dst_h_dentry);
24421 + if (h_inode->i_nlink)
24422 + err = au_may_del(a->dst_dentry, a->btgt,
24423 + a->dst_h_parent, isdir);
24427 + if (unlikely(err == -ENOENT || err == -EEXIST))
24433 +/* ---------------------------------------------------------------------- */
24438 + * - src_dir and dir by lock_rename()
24439 + * - inode if exists
24442 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
24444 + * + di_write_lock2_child()
24445 + * + di_write_lock_child()
24446 + * + ii_write_lock_child()
24447 + * + di_write_lock_child2()
24448 + * + ii_write_lock_child2()
24449 + * + src_parent and parent
24450 + * + di_write_lock_parent()
24451 + * + ii_write_lock_parent()
24452 + * + di_write_lock_parent2()
24453 + * + ii_write_lock_parent2()
24454 + * + lower src_dir and dir by vfsub_lock_rename()
24455 + * + verify the every relationships between child and parent. if any
24456 + * of them failed, unlock all and return -EBUSY.
24458 +static void au_ren_unlock(struct au_ren_args *a)
24460 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
24461 + a->dst_h_parent, a->dst_hdir);
24462 + if (au_ftest_ren(a->auren_flags, DIRREN)
24464 + au_hn_inode_unlock(a->h_root);
24465 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
24466 + vfsub_mnt_drop_write(au_br_mnt(a->br));
24469 +static int au_ren_lock(struct au_ren_args *a)
24472 + unsigned int udba;
24475 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
24476 + a->src_hdir = au_hi(a->src_dir, a->btgt);
24477 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
24478 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
24480 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
24481 + if (unlikely(err))
24483 + au_fset_ren(a->auren_flags, MNT_WRITE);
24484 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24485 + struct dentry *root;
24486 + struct inode *dir;
24489 + * sbinfo is already locked, so this ii_read_lock is
24490 + * unnecessary. but our debugging feature checks it.
24492 + root = a->src_inode->i_sb->s_root;
24493 + if (root != a->src_parent && root != a->dst_parent) {
24494 + dir = d_inode(root);
24495 + ii_read_lock_parent3(dir);
24496 + a->h_root = au_hi(dir, a->btgt);
24497 + ii_read_unlock(dir);
24498 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
24501 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
24502 + a->dst_h_parent, a->dst_hdir);
24503 + udba = au_opt_udba(a->src_dentry->d_sb);
24504 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
24505 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
24506 + err = au_busy_or_stale();
24507 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
24508 + err = au_h_verify(a->src_h_dentry, udba,
24509 + d_inode(a->src_h_parent), a->src_h_parent,
24511 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
24512 + err = au_h_verify(a->dst_h_dentry, udba,
24513 + d_inode(a->dst_h_parent), a->dst_h_parent,
24516 + goto out; /* success */
24518 + err = au_busy_or_stale();
24519 + au_ren_unlock(a);
24525 +/* ---------------------------------------------------------------------- */
24527 +static void au_ren_refresh_dir(struct au_ren_args *a)
24529 + struct inode *dir;
24531 + dir = a->dst_dir;
24532 + inode_inc_iversion(dir);
24533 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
24534 + /* is this updating defined in POSIX? */
24535 + au_cpup_attr_timesizes(a->src_inode);
24536 + au_cpup_attr_nlink(dir, /*force*/1);
24538 + au_dir_ts(dir, a->btgt);
24540 + if (a->exchange) {
24541 + dir = a->src_dir;
24542 + inode_inc_iversion(dir);
24543 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
24544 + /* is this updating defined in POSIX? */
24545 + au_cpup_attr_timesizes(a->dst_inode);
24546 + au_cpup_attr_nlink(dir, /*force*/1);
24548 + au_dir_ts(dir, a->btgt);
24551 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
24554 + dir = a->src_dir;
24555 + inode_inc_iversion(dir);
24556 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
24557 + au_cpup_attr_nlink(dir, /*force*/1);
24558 + au_dir_ts(dir, a->btgt);
24561 +static void au_ren_refresh(struct au_ren_args *a)
24563 + aufs_bindex_t bbot, bindex;
24564 + struct dentry *d, *h_d;
24565 + struct inode *i, *h_i;
24566 + struct super_block *sb;
24568 + d = a->dst_dentry;
24571 + /* already dget-ed by au_ren_or_cpup() */
24572 + au_set_h_dptr(d, a->btgt, a->h_dst);
24574 + i = a->dst_inode;
24576 + if (!a->exchange) {
24577 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
24578 + vfsub_drop_nlink(i);
24580 + vfsub_dead_dir(i);
24581 + au_cpup_attr_timesizes(i);
24583 + au_update_dbrange(d, /*do_put_zero*/1);
24585 + au_cpup_attr_nlink(i, /*force*/1);
24588 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
24589 + au_set_h_dptr(d, bindex, NULL);
24590 + bbot = au_dbbot(d);
24591 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
24592 + au_set_h_dptr(d, bindex, NULL);
24593 + au_update_dbrange(d, /*do_put_zero*/0);
24597 + || au_ftest_ren(a->auren_flags, DIRREN)) {
24598 + d_drop(a->src_dentry);
24599 + if (au_ftest_ren(a->auren_flags, DIRREN))
24600 + au_set_dbwh(a->src_dentry, -1);
24604 + d = a->src_dentry;
24605 + au_set_dbwh(d, -1);
24606 + bbot = au_dbbot(d);
24607 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
24608 + h_d = au_h_dptr(d, bindex);
24610 + au_set_h_dptr(d, bindex, NULL);
24612 + au_set_dbbot(d, a->btgt);
24615 + i = a->src_inode;
24616 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
24617 + return; /* success */
24619 + bbot = au_ibbot(i);
24620 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
24621 + h_i = au_h_iptr(i, bindex);
24623 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
24624 + /* ignore this error */
24625 + au_set_h_iptr(i, bindex, NULL, 0);
24628 + au_set_ibbot(i, a->btgt);
24631 +/* ---------------------------------------------------------------------- */
24633 +/* mainly for link(2) and rename(2) */
24634 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
24636 + aufs_bindex_t bdiropq, bwh;
24637 + struct dentry *parent;
24638 + struct au_branch *br;
24640 + parent = dentry->d_parent;
24641 + IMustLock(d_inode(parent)); /* dir is locked */
24643 + bdiropq = au_dbdiropq(parent);
24644 + bwh = au_dbwh(dentry);
24645 + br = au_sbr(dentry->d_sb, btgt);
24646 + if (au_br_rdonly(br)
24647 + || (0 <= bdiropq && bdiropq < btgt)
24648 + || (0 <= bwh && bwh < btgt))
24651 + AuDbg("btgt %d\n", btgt);
24655 +/* sets src_btop, dst_btop and btgt */
24656 +static int au_ren_wbr(struct au_ren_args *a)
24659 + struct au_wr_dir_args wr_dir_args = {
24660 + /* .force_btgt = -1, */
24661 + .flags = AuWrDir_ADD_ENTRY
24664 + a->src_btop = au_dbtop(a->src_dentry);
24665 + a->dst_btop = au_dbtop(a->dst_dentry);
24666 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
24667 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
24668 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
24669 + wr_dir_args.force_btgt = a->src_btop;
24670 + if (a->dst_inode && a->dst_btop < a->src_btop)
24671 + wr_dir_args.force_btgt = a->dst_btop;
24672 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
24673 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
24676 + au_update_dbtop(a->dst_dentry);
24681 +static void au_ren_dt(struct au_ren_args *a)
24683 + a->h_path.dentry = a->src_h_parent;
24684 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
24685 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
24686 + a->h_path.dentry = a->dst_h_parent;
24687 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
24690 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
24691 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
24695 + a->h_path.dentry = a->src_h_dentry;
24696 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
24697 + if (d_is_positive(a->dst_h_dentry)) {
24698 + au_fset_ren(a->auren_flags, DT_DSTDIR);
24699 + a->h_path.dentry = a->dst_h_dentry;
24700 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
24704 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
24706 + struct dentry *h_d;
24707 + struct inode *h_inode;
24709 + au_dtime_revert(a->src_dt + AuPARENT);
24710 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
24711 + au_dtime_revert(a->dst_dt + AuPARENT);
24713 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
24714 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
24715 + h_inode = d_inode(h_d);
24716 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
24717 + au_dtime_revert(a->src_dt + AuCHILD);
24718 + inode_unlock(h_inode);
24720 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
24721 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
24722 + h_inode = d_inode(h_d);
24723 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
24724 + au_dtime_revert(a->dst_dt + AuCHILD);
24725 + inode_unlock(h_inode);
24730 +/* ---------------------------------------------------------------------- */
24732 +int aufs_rename(struct user_namespace *userns,
24733 + struct inode *_src_dir, struct dentry *_src_dentry,
24734 + struct inode *_dst_dir, struct dentry *_dst_dentry,
24735 + unsigned int _flags)
24737 + int err, lock_flags;
24739 + /* reduce stack space */
24740 + struct au_ren_args *a;
24741 + struct au_pin pin;
24743 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
24744 + IMustLock(_src_dir);
24745 + IMustLock(_dst_dir);
24748 + if (unlikely(_flags & RENAME_WHITEOUT))
24752 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
24753 + a = kzalloc(sizeof(*a), GFP_NOFS);
24754 + if (unlikely(!a))
24757 + a->flags = _flags;
24758 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
24759 + && RENAME_EXCHANGE > U8_MAX);
24760 + a->exchange = _flags & RENAME_EXCHANGE;
24761 + a->src_dir = _src_dir;
24762 + a->src_dentry = _src_dentry;
24763 + a->src_inode = NULL;
24764 + if (d_really_is_positive(a->src_dentry))
24765 + a->src_inode = d_inode(a->src_dentry);
24766 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
24767 + a->dst_dir = _dst_dir;
24768 + a->dst_dentry = _dst_dentry;
24769 + a->dst_inode = NULL;
24770 + if (d_really_is_positive(a->dst_dentry))
24771 + a->dst_inode = d_inode(a->dst_dentry);
24772 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
24773 + if (a->dst_inode) {
24775 + * if EXCHANGE && src is non-dir && dst is dir,
24776 + * dst is not locked.
24778 + /* IMustLock(a->dst_inode); */
24779 + au_igrab(a->dst_inode);
24783 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
24784 + if (d_is_dir(a->src_dentry)) {
24785 + au_fset_ren(a->auren_flags, ISDIR_SRC);
24786 + if (unlikely(!a->exchange
24787 + && d_really_is_positive(a->dst_dentry)
24788 + && !d_is_dir(a->dst_dentry)))
24790 + lock_flags |= AuLock_DIRS;
24792 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
24793 + au_fset_ren(a->auren_flags, ISDIR_DST);
24794 + if (unlikely(!a->exchange
24795 + && d_really_is_positive(a->src_dentry)
24796 + && !d_is_dir(a->src_dentry)))
24798 + lock_flags |= AuLock_DIRS;
24800 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
24802 + if (unlikely(err))
24805 + err = au_d_hashed_positive(a->src_dentry);
24806 + if (unlikely(err))
24809 + if (a->dst_inode) {
24811 + * If it is a dir, VFS unhash it before this
24812 + * function. It means we cannot rely upon d_unhashed().
24814 + if (unlikely(!a->dst_inode->i_nlink))
24816 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
24817 + err = au_d_hashed_positive(a->dst_dentry);
24818 + if (unlikely(err && !a->exchange))
24820 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
24822 + } else if (unlikely(d_unhashed(a->dst_dentry)))
24826 + * is it possible?
24827 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
24828 + * there may exist a problem somewhere else.
24831 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
24834 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
24835 + di_write_lock_parent(a->dst_parent);
24837 + /* which branch we process */
24838 + err = au_ren_wbr(a);
24839 + if (unlikely(err < 0))
24841 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
24842 + a->h_path.mnt = au_br_mnt(a->br);
24844 + /* are they available to be renamed */
24845 + err = au_ren_may_dir(a);
24846 + if (unlikely(err))
24847 + goto out_children;
24849 + /* prepare the writable parent dir on the same branch */
24850 + if (a->dst_btop == a->btgt) {
24851 + au_fset_ren(a->auren_flags, WHDST);
24853 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
24854 + if (unlikely(err))
24855 + goto out_children;
24859 + if (!a->exchange) {
24860 + if (a->src_dir != a->dst_dir) {
24862 + * this temporary unlock is safe,
24863 + * because both dir->i_mutex are locked.
24865 + di_write_unlock(a->dst_parent);
24866 + di_write_lock_parent(a->src_parent);
24867 + err = au_wr_dir_need_wh(a->src_dentry,
24868 + au_ftest_ren(a->auren_flags,
24871 + di_write_unlock(a->src_parent);
24872 + di_write_lock2_parent(a->src_parent, a->dst_parent,
24874 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
24876 + err = au_wr_dir_need_wh(a->src_dentry,
24877 + au_ftest_ren(a->auren_flags,
24881 + if (unlikely(err < 0))
24882 + goto out_children;
24884 + au_fset_ren(a->auren_flags, WHSRC);
24887 + if (a->src_btop != a->btgt) {
24888 + err = au_pin(&pin, a->src_dentry, a->btgt,
24889 + au_opt_udba(a->src_dentry->d_sb),
24890 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
24892 + struct au_cp_generic cpg = {
24893 + .dentry = a->src_dentry,
24895 + .bsrc = a->src_btop,
24898 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24900 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
24901 + err = au_sio_cpup_simple(&cpg);
24904 + if (unlikely(err))
24905 + goto out_children;
24906 + a->src_btop = a->btgt;
24907 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
24908 + if (!a->exchange)
24909 + au_fset_ren(a->auren_flags, WHSRC);
24913 + if (a->exchange && a->dst_inode
24914 + && a->dst_btop != a->btgt) {
24915 + err = au_pin(&pin, a->dst_dentry, a->btgt,
24916 + au_opt_udba(a->dst_dentry->d_sb),
24917 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
24919 + struct au_cp_generic cpg = {
24920 + .dentry = a->dst_dentry,
24922 + .bsrc = a->dst_btop,
24925 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24927 + err = au_sio_cpup_simple(&cpg);
24930 + if (unlikely(err))
24931 + goto out_children;
24932 + a->dst_btop = a->btgt;
24933 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
24936 + /* lock them all */
24937 + err = au_ren_lock(a);
24938 + if (unlikely(err))
24939 + /* leave the copied-up one */
24940 + goto out_children;
24942 + if (!a->exchange) {
24943 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
24944 + err = au_may_ren(a);
24945 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
24946 + err = -ENAMETOOLONG;
24947 + if (unlikely(err))
24951 + /* store timestamps to be revertible */
24954 + /* store dirren info */
24955 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24956 + err = au_dr_rename(a->src_dentry, a->btgt,
24957 + &a->dst_dentry->d_name, &rev);
24959 + if (unlikely(err))
24964 + err = do_rename(a);
24965 + if (unlikely(err))
24968 + if (au_ftest_ren(a->auren_flags, DIRREN))
24969 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
24971 + /* update dir attributes */
24972 + au_ren_refresh_dir(a);
24974 + /* dput/iput all lower dentries */
24975 + au_ren_refresh(a);
24977 + goto out_hdir; /* success */
24980 + if (au_ftest_ren(a->auren_flags, DIRREN))
24981 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
24983 + au_ren_rev_dt(err, a);
24985 + au_ren_unlock(a);
24987 + au_nhash_wh_free(&a->whlist);
24988 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
24989 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
24990 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
24991 + au_set_dbtop(a->dst_dentry, a->dst_btop);
24995 + if (d_unhashed(a->src_dentry))
24996 + au_fset_ren(a->auren_flags, DROPPED_SRC);
24997 + if (d_unhashed(a->dst_dentry))
24998 + au_fset_ren(a->auren_flags, DROPPED_DST);
24999 + if (!a->exchange)
25000 + d_move(a->src_dentry, a->dst_dentry);
25002 + d_exchange(a->src_dentry, a->dst_dentry);
25003 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
25004 + d_drop(a->dst_dentry);
25006 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
25007 + d_drop(a->src_dentry);
25009 + au_update_dbtop(a->dst_dentry);
25010 + if (!a->dst_inode)
25011 + d_drop(a->dst_dentry);
25013 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
25014 + di_write_unlock(a->dst_parent);
25016 + di_write_unlock2(a->src_parent, a->dst_parent);
25018 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
25020 + iput(a->dst_inode);
25022 + au_whtmp_rmdir_free(a->thargs);
25028 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
25029 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
25030 +++ linux/fs/aufs/Kconfig 2022-11-05 23:02:18.959222617 +0100
25032 +# SPDX-License-Identifier: GPL-2.0
25034 + tristate "Aufs (Advanced multi layered unification filesystem) support"
25036 + Aufs is a stackable unification filesystem such as Unionfs,
25037 + which unifies several directories and provides a merged single
25039 + In the early days, aufs was entirely re-designed and
25040 + re-implemented Unionfs Version 1.x series. Introducing many
25041 + original ideas, approaches and improvements, it becomes totally
25042 + different from Unionfs while keeping the basic features.
25046 + prompt "Maximum number of branches"
25047 + default AUFS_BRANCH_MAX_127
25049 + Specifies the maximum number of branches (or member directories)
25050 + in a single aufs. The larger value consumes more system
25051 + resources and has a minor impact to performance.
25052 +config AUFS_BRANCH_MAX_127
25055 + Specifies the maximum number of branches (or member directories)
25056 + in a single aufs. The larger value consumes more system
25057 + resources and has a minor impact to performance.
25058 +config AUFS_BRANCH_MAX_511
25061 + Specifies the maximum number of branches (or member directories)
25062 + in a single aufs. The larger value consumes more system
25063 + resources and has a minor impact to performance.
25064 +config AUFS_BRANCH_MAX_1023
25067 + Specifies the maximum number of branches (or member directories)
25068 + in a single aufs. The larger value consumes more system
25069 + resources and has a minor impact to performance.
25070 +config AUFS_BRANCH_MAX_32767
25073 + Specifies the maximum number of branches (or member directories)
25074 + in a single aufs. The larger value consumes more system
25075 + resources and has a minor impact to performance.
25078 +config AUFS_SBILIST
25080 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
25083 + Automatic configuration for internal use.
25084 + When aufs supports Magic SysRq or /proc, enabled automatically.
25086 +config AUFS_HNOTIFY
25087 + bool "Detect direct branch access (bypassing aufs)"
25089 + If you want to modify files on branches directly, eg. bypassing aufs,
25090 + and want aufs to detect the changes of them fully, then enable this
25091 + option and use 'udba=notify' mount option.
25092 + Currently there is only one available configuration, "fsnotify".
25093 + It will have a negative impact to the performance.
25094 + See detail in aufs.5.
25097 + prompt "method" if AUFS_HNOTIFY
25098 + default AUFS_HFSNOTIFY
25099 +config AUFS_HFSNOTIFY
25104 +config AUFS_EXPORT
25105 + bool "NFS-exportable aufs"
25106 + depends on EXPORTFS
25108 + If you want to export your mounted aufs via NFS, then enable this
25109 + option. There are several requirements for this configuration.
25110 + See detail in aufs.5.
25112 +config AUFS_INO_T_64
25114 + depends on AUFS_EXPORT
25115 + depends on 64BIT && !(ALPHA || S390)
25118 + Automatic configuration for internal use.
25119 + /* typedef unsigned long/int __kernel_ino_t */
25120 + /* alpha and s390x are int */
25123 + bool "support for XATTR/EA (including Security Labels)"
25125 + If your branch fs supports XATTR/EA and you want to make them
25126 + available in aufs too, then enable this opsion and specify the
25127 + branch attributes for EA.
25128 + See detail in aufs.5.
25131 + bool "File-based Hierarchical Storage Management"
25133 + Hierarchical Storage Management (or HSM) is a well-known feature
25134 + in the storage world. Aufs provides this feature as file-based.
25135 + with multiple branches.
25136 + These multiple branches are prioritized, ie. the topmost one
25137 + should be the fastest drive and be used heavily.
25140 + bool "Readdir in userspace"
25142 + Aufs has two methods to provide a merged view for a directory,
25143 + by a user-space library and by kernel-space natively. The latter
25144 + is always enabled but sometimes large and slow.
25145 + If you enable this option, install the library in aufs2-util
25146 + package, and set some environment variables for your readdir(3),
25147 + then the work will be handled in user-space which generally
25148 + shows better performance in most cases.
25149 + See detail in aufs.5.
25151 +config AUFS_DIRREN
25152 + bool "Workaround for rename(2)-ing a directory"
25154 + By default, aufs returns EXDEV error in renameing a dir who has
25155 + his child on the lower branch, since it is a bad idea to issue
25156 + rename(2) internally for every lower branch. But user may not
25157 + accept this behaviour. So here is a workaround to allow such
25158 + rename(2) and store some extra information on the writable
25159 + branch. Obviously this costs high (and I don't like it).
25160 + To use this feature, you need to enable this configuration AND
25161 + to specify the mount option `dirren.'
25162 + See details in aufs.5 and the design documents.
25165 + bool "Show whiteouts"
25167 + If you want to make the whiteouts in aufs visible, then enable
25168 + this option and specify 'shwh' mount option. Although it may
25169 + sounds like philosophy or something, but in technically it
25170 + simply shows the name of whiteout with keeping its behaviour.
25172 +config AUFS_BR_RAMFS
25173 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
25175 + If you want to use ramfs as an aufs branch fs, then enable this
25176 + option. Generally tmpfs is recommended.
25177 + Aufs prohibited them to be a branch fs by default, because
25178 + initramfs becomes unusable after switch_root or something
25179 + generally. If you sets initramfs as an aufs branch and boot your
25180 + system by switch_root, you will meet a problem easily since the
25181 + files in initramfs may be inaccessible.
25182 + Unless you are going to use ramfs as an aufs branch fs without
25183 + switch_root or something, leave it N.
25185 +config AUFS_BR_FUSE
25186 + bool "Fuse fs as an aufs branch"
25187 + depends on FUSE_FS
25190 + If you want to use fuse-based userspace filesystem as an aufs
25191 + branch fs, then enable this option.
25192 + It implements the internal poll(2) operation which is
25193 + implemented by fuse only (curretnly).
25198 + Automatic configuration for internal use.
25200 +config AUFS_BR_HFSPLUS
25201 + bool "Hfsplus as an aufs branch"
25202 + depends on HFSPLUS_FS
25205 + If you want to use hfsplus fs as an aufs branch fs, then enable
25206 + this option. This option introduces a small overhead at
25207 + copying-up a file on hfsplus.
25209 +config AUFS_BDEV_LOOP
25211 + depends on BLK_DEV_LOOP
25214 + Automatic configuration for internal use.
25215 + Convert =[ym] into =y.
25218 + bool "Debug aufs"
25220 + Enable this to compile aufs internal debug code.
25221 + It will have a negative impact to the performance.
25223 +config AUFS_MAGIC_SYSRQ
25225 + depends on AUFS_DEBUG && MAGIC_SYSRQ
25228 + Automatic configuration for internal use.
25229 + When aufs supports Magic SysRq, enabled automatically.
25231 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
25232 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
25233 +++ linux/fs/aufs/lcnt.h 2022-11-05 23:02:18.965889284 +0100
25235 +/* SPDX-License-Identifier: GPL-2.0 */
25237 + * Copyright (C) 2018-2022 Junjiro R. Okajima
25239 + * This program is free software; you can redistribute it and/or modify
25240 + * it under the terms of the GNU General Public License as published by
25241 + * the Free Software Foundation; either version 2 of the License, or
25242 + * (at your option) any later version.
25244 + * This program is distributed in the hope that it will be useful,
25245 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25246 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25247 + * GNU General Public License for more details.
25249 + * You should have received a copy of the GNU General Public License
25250 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25254 + * simple long counter wrapper
25257 +#ifndef __AUFS_LCNT_H__
25258 +#define __AUFS_LCNT_H__
25262 +#include "debug.h"
25264 +#define AuLCntATOMIC 1
25265 +#define AuLCntPCPUCNT 2
25267 + * why does percpu_refcount require extra synchronize_rcu()s in
25268 + * au_br_do_free()
25270 +#define AuLCntPCPUREF 3
25272 +/* #define AuLCntChosen AuLCntATOMIC */
25273 +#define AuLCntChosen AuLCntPCPUCNT
25274 +/* #define AuLCntChosen AuLCntPCPUREF */
25276 +#if AuLCntChosen == AuLCntATOMIC
25277 +#include <linux/atomic.h>
25279 +typedef atomic_long_t au_lcnt_t;
25281 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
25283 + atomic_long_set(cnt, 0);
25287 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25292 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
25293 + int do_sync __maybe_unused)
25298 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25300 + atomic_long_inc(cnt);
25303 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25305 + atomic_long_dec(cnt);
25308 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
25310 + return atomic_long_read(cnt);
25314 +#if AuLCntChosen == AuLCntPCPUCNT
25315 +#include <linux/percpu_counter.h>
25317 +typedef struct percpu_counter au_lcnt_t;
25319 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
25321 + return percpu_counter_init(cnt, 0, GFP_NOFS);
25324 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25329 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
25331 + percpu_counter_destroy(cnt);
25334 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25336 + percpu_counter_inc(cnt);
25339 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25341 + percpu_counter_dec(cnt);
25344 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
25348 + n = percpu_counter_sum(cnt);
25350 + if (LONG_MAX != LLONG_MAX
25352 + AuWarn1("%s\n", "wrap-around");
25358 +#if AuLCntChosen == AuLCntPCPUREF
25359 +#include <linux/percpu-refcount.h>
25361 +typedef struct percpu_ref au_lcnt_t;
25363 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
25366 + release = percpu_ref_exit;
25367 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
25370 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25372 + synchronize_rcu();
25375 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
25377 + percpu_ref_kill(cnt);
25379 + au_lcnt_wait_for_fin(cnt);
25382 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25384 + percpu_ref_get(cnt);
25387 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25389 + percpu_ref_put(cnt);
25393 + * avoid calling this func as possible.
25395 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
25399 + percpu_ref_switch_to_atomic_sync(cnt);
25400 + l = atomic_long_read(&cnt->count);
25402 + percpu_ref_switch_to_percpu(cnt);
25404 + /* percpu_ref is initialized by 1 instead of 0 */
25409 +#ifdef CONFIG_AUFS_DEBUG
25410 +#define AuLCntZero(val) do { \
25413 + AuDbg("%s = %ld\n", #val, l); \
25416 +#define AuLCntZero(val) do {} while (0)
25419 +#endif /* __KERNEL__ */
25420 +#endif /* __AUFS_LCNT_H__ */
25421 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
25422 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
25423 +++ linux/fs/aufs/loop.c 2022-11-05 23:02:18.965889284 +0100
25425 +// SPDX-License-Identifier: GPL-2.0
25427 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25429 + * This program is free software; you can redistribute it and/or modify
25430 + * it under the terms of the GNU General Public License as published by
25431 + * the Free Software Foundation; either version 2 of the License, or
25432 + * (at your option) any later version.
25434 + * This program is distributed in the hope that it will be useful,
25435 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25436 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25437 + * GNU General Public License for more details.
25439 + * You should have received a copy of the GNU General Public License
25440 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25444 + * support for loopback block device as a branch
25449 +/* added into drivers/block/loop.c */
25450 +static struct file *(*backing_file_func)(struct super_block *sb);
25453 + * test if two lower dentries have overlapping branches.
25455 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
25457 + struct super_block *h_sb;
25458 + struct file *backing_file;
25460 + if (unlikely(!backing_file_func)) {
25461 + /* don't load "loop" module here */
25462 + backing_file_func = symbol_get(loop_backing_file);
25463 + if (unlikely(!backing_file_func))
25464 + /* "loop" module is not loaded */
25468 + h_sb = h_adding->d_sb;
25469 + backing_file = backing_file_func(h_sb);
25470 + if (!backing_file)
25473 + h_adding = backing_file->f_path.dentry;
25475 + * h_adding can be local NFS.
25476 + * in this case aufs cannot detect the loop.
25478 + if (unlikely(h_adding->d_sb == sb))
25480 + return !!au_test_subdir(h_adding, sb->s_root);
25483 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
25484 +int au_test_loopback_kthread(void)
25487 + struct task_struct *tsk = current;
25488 + char c, comm[sizeof(tsk->comm)];
25491 + if (tsk->flags & PF_KTHREAD) {
25492 + get_task_comm(comm, tsk);
25494 + ret = ('0' <= c && c <= '9'
25495 + && !strncmp(comm, "loop", 4));
25501 +/* ---------------------------------------------------------------------- */
25503 +#define au_warn_loopback_step 16
25504 +static int au_warn_loopback_nelem = au_warn_loopback_step;
25505 +static unsigned long *au_warn_loopback_array;
25507 +void au_warn_loopback(struct super_block *h_sb)
25509 + int i, new_nelem;
25510 + unsigned long *a, magic;
25511 + static DEFINE_SPINLOCK(spin);
25513 + magic = h_sb->s_magic;
25514 + spin_lock(&spin);
25515 + a = au_warn_loopback_array;
25516 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
25517 + if (a[i] == magic) {
25518 + spin_unlock(&spin);
25522 + /* h_sb is new to us, print it */
25523 + if (i < au_warn_loopback_nelem) {
25528 + /* expand the array */
25529 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
25530 + a = au_kzrealloc(au_warn_loopback_array,
25531 + au_warn_loopback_nelem * sizeof(unsigned long),
25532 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
25533 + /*may_shrink*/0);
25535 + au_warn_loopback_nelem = new_nelem;
25536 + au_warn_loopback_array = a;
25541 + spin_unlock(&spin);
25542 + AuWarn1("realloc failed, ignored\n");
25546 + spin_unlock(&spin);
25547 + pr_warn("you may want to try another patch for loopback file "
25548 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
25551 +int au_loopback_init(void)
25554 + struct super_block *sb __maybe_unused;
25556 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
25559 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
25560 + sizeof(unsigned long), GFP_NOFS);
25561 + if (unlikely(!au_warn_loopback_array))
25567 +void au_loopback_fin(void)
25569 + if (backing_file_func)
25570 + symbol_put(loop_backing_file);
25571 + au_kfree_try_rcu(au_warn_loopback_array);
25573 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
25574 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
25575 +++ linux/fs/aufs/loop.h 2022-11-05 23:02:18.965889284 +0100
25577 +/* SPDX-License-Identifier: GPL-2.0 */
25579 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25581 + * This program is free software; you can redistribute it and/or modify
25582 + * it under the terms of the GNU General Public License as published by
25583 + * the Free Software Foundation; either version 2 of the License, or
25584 + * (at your option) any later version.
25586 + * This program is distributed in the hope that it will be useful,
25587 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25588 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25589 + * GNU General Public License for more details.
25591 + * You should have received a copy of the GNU General Public License
25592 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25596 + * support for loopback mount as a branch
25599 +#ifndef __AUFS_LOOP_H__
25600 +#define __AUFS_LOOP_H__
25605 +struct super_block;
25607 +#ifdef CONFIG_AUFS_BDEV_LOOP
25608 +/* drivers/block/loop.c */
25609 +struct file *loop_backing_file(struct super_block *sb);
25612 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
25613 +int au_test_loopback_kthread(void);
25614 +void au_warn_loopback(struct super_block *h_sb);
25616 +int au_loopback_init(void);
25617 +void au_loopback_fin(void);
25619 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
25621 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
25622 + struct dentry *h_adding)
25623 +AuStubInt0(au_test_loopback_kthread, void)
25624 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
25626 +AuStubInt0(au_loopback_init, void)
25627 +AuStubVoid(au_loopback_fin, void)
25628 +#endif /* BLK_DEV_LOOP */
25630 +#endif /* __KERNEL__ */
25631 +#endif /* __AUFS_LOOP_H__ */
25632 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
25633 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
25634 +++ linux/fs/aufs/magic.mk 2022-11-05 23:02:18.965889284 +0100
25636 +# SPDX-License-Identifier: GPL-2.0
25638 +# defined in ${srctree}/fs/fuse/inode.c
25640 +ifdef CONFIG_FUSE_FS
25641 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
25644 +# defined in ${srctree}/fs/xfs/xfs_sb.h
25646 +ifdef CONFIG_XFS_FS
25647 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
25650 +# defined in ${srctree}/fs/configfs/mount.c
25652 +ifdef CONFIG_CONFIGFS_FS
25653 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
25656 +# defined in ${srctree}/fs/ubifs/ubifs.h
25658 +ifdef CONFIG_UBIFS_FS
25659 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
25662 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
25664 +ifdef CONFIG_HFSPLUS_FS
25665 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
25667 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
25668 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
25669 +++ linux/fs/aufs/Makefile 2022-11-05 23:02:18.959222617 +0100
25671 +# SPDX-License-Identifier: GPL-2.0
25673 +include ${src}/magic.mk
25674 +ifeq (${CONFIG_AUFS_FS},m)
25675 +include ${src}/conf.mk
25677 +-include ${src}/priv_def.mk
25679 +# cf. include/linux/kernel.h
25681 +ccflags-y += -DDEBUG
25682 +# sparse requires the full pathname
25684 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
25686 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
25689 +obj-$(CONFIG_AUFS_FS) += aufs.o
25690 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o fsctx.o \
25691 + wkq.o vfsub.o dcsub.o \
25692 + cpup.o whout.o wbr_policy.o \
25693 + dinfo.o dentry.o \
25695 + finfo.o file.o f_op.o \
25697 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
25701 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
25702 +aufs-$(CONFIG_SYSFS) += sysfs.o
25703 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
25704 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
25705 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
25706 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
25707 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
25708 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
25709 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
25710 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
25711 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
25712 +aufs-$(CONFIG_AUFS_POLL) += poll.o
25713 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
25714 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
25715 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
25716 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
25717 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
25718 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
25719 +++ linux/fs/aufs/module.c 2022-11-05 23:02:18.965889284 +0100
25721 +// SPDX-License-Identifier: GPL-2.0
25723 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25725 + * This program is free software; you can redistribute it and/or modify
25726 + * it under the terms of the GNU General Public License as published by
25727 + * the Free Software Foundation; either version 2 of the License, or
25728 + * (at your option) any later version.
25730 + * This program is distributed in the hope that it will be useful,
25731 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25732 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25733 + * GNU General Public License for more details.
25735 + * You should have received a copy of the GNU General Public License
25736 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25740 + * module global variables and operations
25743 +#include <linux/module.h>
25744 +#include <linux/seq_file.h>
25747 +/* shrinkable realloc */
25748 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
25756 +#if 0 /* unused */
25763 + AuDebugOn(!new_sz);
25766 + diff = au_kmidx_sub(sz, new_sz);
25772 + /* expand or SLOB */
25773 + p = krealloc(p, new_sz, gfp);
25774 + else if (new_sz < sz && may_shrink) {
25778 + q = kmalloc(new_sz, gfp);
25781 + memcpy(q, p, new_sz);
25782 + au_kfree_try_rcu(p);
25793 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
25796 + p = au_krealloc(p, new_sz, gfp, may_shrink);
25797 + if (p && new_sz > nused)
25798 + memset(p + nused, 0, new_sz - nused);
25802 +/* ---------------------------------------------------------------------- */
25806 +struct kmem_cache *au_cache[AuCache_Last];
25808 +static void au_cache_fin(void)
25813 + * Make sure all delayed rcu free inodes are flushed before we
25818 + /* excluding AuCache_HNOTIFY */
25819 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
25820 + for (i = 0; i < AuCache_HNOTIFY; i++) {
25821 + kmem_cache_destroy(au_cache[i]);
25822 + au_cache[i] = NULL;
25826 +static int __init au_cache_init(void)
25828 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
25829 + if (au_cache[AuCache_DINFO])
25830 + /* SLAB_DESTROY_BY_RCU */
25831 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
25832 + au_icntnr_init_once);
25833 + if (au_cache[AuCache_ICNTNR])
25834 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
25835 + au_fi_init_once);
25836 + if (au_cache[AuCache_FINFO])
25837 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
25838 + if (au_cache[AuCache_VDIR])
25839 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
25840 + if (au_cache[AuCache_DEHSTR])
25847 +/* ---------------------------------------------------------------------- */
25849 +int au_dir_roflags;
25851 +#ifdef CONFIG_AUFS_SBILIST
25853 + * iterate_supers_type() doesn't protect us from
25854 + * remounting (branch management)
25856 +struct hlist_bl_head au_sbilist;
25860 + * functions for module interface.
25862 +MODULE_LICENSE("GPL");
25863 +/* MODULE_LICENSE("GPL v2"); */
25864 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
25865 +MODULE_DESCRIPTION(AUFS_NAME
25866 + " -- Advanced multi layered unification filesystem");
25867 +MODULE_VERSION(AUFS_VERSION);
25868 +MODULE_ALIAS_FS(AUFS_NAME);
25870 +/* this module parameter has no meaning when SYSFS is disabled */
25871 +int sysaufs_brs = 1;
25872 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
25873 +module_param_named(brs, sysaufs_brs, int, 0444);
25875 +/* this module parameter has no meaning when USER_NS is disabled */
25877 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
25878 +module_param_named(allow_userns, au_userns, bool, 0444);
25880 +/* ---------------------------------------------------------------------- */
25882 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
25884 +int au_seq_path(struct seq_file *seq, struct path *path)
25888 + err = seq_path(seq, path, au_esc_chars);
25897 +/* ---------------------------------------------------------------------- */
25899 +static int __init aufs_init(void)
25904 + p = au_esc_chars;
25905 + for (i = 1; i <= ' '; i++)
25911 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
25913 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
25914 + for (i = 0; i < AuIop_Last; i++)
25915 + aufs_iop_nogetattr[i].getattr = NULL;
25917 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
25919 + au_sbilist_init();
25920 + sysaufs_brs_init();
25923 + err = sysaufs_init();
25924 + if (unlikely(err))
25926 + err = dbgaufs_init();
25927 + if (unlikely(err))
25928 + goto out_sysaufs;
25929 + err = au_procfs_init();
25930 + if (unlikely(err))
25931 + goto out_dbgaufs;
25932 + err = au_wkq_init();
25933 + if (unlikely(err))
25935 + err = au_loopback_init();
25936 + if (unlikely(err))
25938 + err = au_hnotify_init();
25939 + if (unlikely(err))
25940 + goto out_loopback;
25941 + err = au_sysrq_init();
25942 + if (unlikely(err))
25944 + err = au_cache_init();
25945 + if (unlikely(err))
25948 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
25949 + err = register_filesystem(&aufs_fs_type);
25950 + if (unlikely(err))
25953 + /* since we define pr_fmt, call printk directly */
25954 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
25955 + goto out; /* success */
25962 + au_hnotify_fin();
25964 + au_loopback_fin();
25978 +static void __exit aufs_exit(void)
25980 + unregister_filesystem(&aufs_fs_type);
25983 + au_hnotify_fin();
25984 + au_loopback_fin();
25992 +module_init(aufs_init);
25993 +module_exit(aufs_exit);
25994 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
25995 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
25996 +++ linux/fs/aufs/module.h 2022-11-05 23:02:18.969222617 +0100
25998 +/* SPDX-License-Identifier: GPL-2.0 */
26000 + * Copyright (C) 2005-2022 Junjiro R. Okajima
26002 + * This program is free software; you can redistribute it and/or modify
26003 + * it under the terms of the GNU General Public License as published by
26004 + * the Free Software Foundation; either version 2 of the License, or
26005 + * (at your option) any later version.
26007 + * This program is distributed in the hope that it will be useful,
26008 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26009 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26010 + * GNU General Public License for more details.
26012 + * You should have received a copy of the GNU General Public License
26013 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26017 + * module initialization and module-global
26020 +#ifndef __AUFS_MODULE_H__
26021 +#define __AUFS_MODULE_H__
26025 +#include <linux/slab.h>
26026 +#include "debug.h"
26027 +#include "dentry.h"
26030 +#include "inode.h"
26035 +/* module parameters */
26036 +extern int sysaufs_brs;
26037 +extern bool au_userns;
26039 +/* ---------------------------------------------------------------------- */
26041 +extern int au_dir_roflags;
26043 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
26044 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
26048 + * Comparing the size of the object with sizeof(struct rcu_head)
26049 + * case 1: object is always larger
26050 + * --> au_kfree_rcu() or au_kfree_do_rcu()
26051 + * case 2: object is always smaller
26052 + * --> au_kfree_small()
26053 + * case 3: object can be any size
26054 + * --> au_kfree_try_rcu()
26057 +static inline void au_kfree_do_rcu(const void *p)
26060 + struct rcu_head rcu;
26061 + } *a = (void *)p;
26063 + kfree_rcu(a, rcu);
26066 +#define au_kfree_rcu(_p) do { \
26067 + typeof(_p) p = (_p); \
26068 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
26070 + au_kfree_do_rcu(p); \
26073 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
26074 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
26076 +static inline void au_kfree_try_rcu(const void *p)
26080 + if (au_kfree_sz_test(p))
26081 + au_kfree_do_rcu(p);
26086 +static inline void au_kfree_small(const void *p)
26090 + AuDebugOn(au_kfree_sz_test(p));
26094 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
26096 +#ifndef CONFIG_SLOB
26097 + return __kmalloc_index(sz, false) - __kmalloc_index(new_sz, false);
26099 + return -1; /* SLOB is untested */
26103 +int au_seq_path(struct seq_file *seq, struct path *path);
26105 +#ifdef CONFIG_PROC_FS
26107 +int __init au_procfs_init(void);
26108 +void au_procfs_fin(void);
26110 +AuStubInt0(au_procfs_init, void);
26111 +AuStubVoid(au_procfs_fin, void);
26114 +/* ---------------------------------------------------------------------- */
26123 + AuCache_HNOTIFY, /* must be last */
26127 +extern struct kmem_cache *au_cache[AuCache_Last];
26129 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
26130 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
26131 +#define AuCacheCtor(type, ctor) \
26132 + kmem_cache_create(#type, sizeof(struct type), \
26133 + __alignof__(struct type), AuCacheFlags, ctor)
26135 +#define AuCacheFuncAlloc(name, index) \
26136 + static inline struct au_##name *au_cache_alloc_##name(void) \
26137 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); }
26139 +#define AuCacheFuncs(name, index) \
26140 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
26141 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
26143 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
26144 + { void *p = rcu; \
26145 + p -= offsetof(struct au_##name, rcu); \
26146 + kmem_cache_free(au_cache[AuCache_##index], p); } \
26147 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
26148 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
26149 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
26151 + static inline void au_cache_free_##name(struct au_##name *p) \
26152 + { /* au_cache_free_##name##_norcu(p); */ \
26153 + au_cache_free_##name##_rcu(p); }
26155 +AuCacheFuncs(dinfo, DINFO);
26156 +AuCacheFuncAlloc(dinfo, DINFO);
26158 +AuCacheFuncs(icntnr, ICNTNR);
26159 +static inline struct au_icntnr *au_cache_alloc_icntnr(struct super_block *sb)
26160 +{ return alloc_inode_sb(sb, au_cache[AuCache_ICNTNR], GFP_NOFS); }
26162 +AuCacheFuncs(finfo, FINFO);
26163 +AuCacheFuncAlloc(finfo, FINFO);
26165 +AuCacheFuncs(vdir, VDIR);
26166 +AuCacheFuncAlloc(vdir, VDIR);
26168 +AuCacheFuncs(vdir_dehstr, DEHSTR);
26169 +AuCacheFuncAlloc(vdir_dehstr, DEHSTR);
26171 +#ifdef CONFIG_AUFS_HNOTIFY
26172 +AuCacheFuncs(hnotify, HNOTIFY);
26173 +AuCacheFuncAlloc(hnotify, HNOTIFY);
26176 +#endif /* __KERNEL__ */
26177 +#endif /* __AUFS_MODULE_H__ */
26178 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
26179 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
26180 +++ linux/fs/aufs/mvdown.c 2022-11-05 23:02:18.969222617 +0100
26182 +// SPDX-License-Identifier: GPL-2.0
26184 + * Copyright (C) 2011-2022 Junjiro R. Okajima
26186 + * This program is free software; you can redistribute it and/or modify
26187 + * it under the terms of the GNU General Public License as published by
26188 + * the Free Software Foundation; either version 2 of the License, or
26189 + * (at your option) any later version.
26191 + * This program is distributed in the hope that it will be useful,
26192 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26193 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26194 + * GNU General Public License for more details.
26196 + * You should have received a copy of the GNU General Public License
26197 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26201 + * move-down, opposite of copy-up
26206 +struct au_mvd_args {
26208 + struct super_block *h_sb;
26209 + struct dentry *h_parent;
26210 + struct au_hinode *hdir;
26211 + struct inode *h_dir, *h_inode;
26212 + struct au_pin pin;
26213 + } info[AUFS_MVDOWN_NARRAY];
26215 + struct aufs_mvdown mvdown;
26216 + struct dentry *dentry, *parent;
26217 + struct inode *inode, *dir;
26218 + struct super_block *sb;
26219 + aufs_bindex_t bopq, bwh, bfound;
26220 + unsigned char rename_lock;
26223 +#define mvd_errno mvdown.au_errno
26224 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
26225 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
26226 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
26227 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
26229 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
26230 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
26231 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
26232 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
26233 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
26234 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
26236 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
26237 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
26238 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
26239 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
26240 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
26241 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
26243 +#define AU_MVD_PR(flag, ...) do { \
26245 + pr_err(__VA_ARGS__); \
26248 +static int find_lower_writable(struct au_mvd_args *a)
26250 + struct super_block *sb;
26251 + aufs_bindex_t bindex, bbot;
26252 + struct au_branch *br;
26255 + bindex = a->mvd_bsrc;
26256 + bbot = au_sbbot(sb);
26257 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
26258 + for (bindex++; bindex <= bbot; bindex++) {
26259 + br = au_sbr(sb, bindex);
26260 + if (au_br_fhsm(br->br_perm)
26261 + && !sb_rdonly(au_br_sb(br)))
26264 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
26265 + for (bindex++; bindex <= bbot; bindex++) {
26266 + br = au_sbr(sb, bindex);
26267 + if (!au_br_rdonly(br))
26271 + for (bindex++; bindex <= bbot; bindex++) {
26272 + br = au_sbr(sb, bindex);
26273 + if (!sb_rdonly(au_br_sb(br))) {
26274 + if (au_br_rdonly(br))
26276 + |= AUFS_MVDOWN_ROLOWER_R;
26284 +/* make the parent dir on bdst */
26285 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
26290 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
26291 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
26292 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
26293 + a->mvd_h_dst_parent = NULL;
26294 + if (au_dbbot(a->parent) >= a->mvd_bdst)
26295 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
26296 + if (!a->mvd_h_dst_parent) {
26297 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
26298 + if (unlikely(err)) {
26299 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
26302 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
26310 +/* lock them all */
26311 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
26314 + struct dentry *h_trap;
26316 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
26317 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
26318 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
26319 + au_opt_udba(a->sb),
26320 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26322 + if (unlikely(err)) {
26323 + AU_MVD_PR(dmsg, "pin_dst failed\n");
26327 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
26328 + a->rename_lock = 0;
26329 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
26330 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
26331 + au_opt_udba(a->sb),
26332 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26333 + err = au_do_pin(&a->mvd_pin_src);
26335 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
26336 + if (unlikely(err)) {
26337 + AU_MVD_PR(dmsg, "pin_src failed\n");
26340 + goto out; /* success */
26343 + a->rename_lock = 1;
26344 + au_pin_hdir_unlock(&a->mvd_pin_dst);
26345 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
26346 + au_opt_udba(a->sb),
26347 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26349 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
26350 + if (unlikely(err)) {
26351 + AU_MVD_PR(dmsg, "pin_src failed\n");
26352 + au_pin_hdir_lock(&a->mvd_pin_dst);
26355 + au_pin_hdir_unlock(&a->mvd_pin_src);
26356 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26357 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26359 + err = (h_trap != a->mvd_h_src_parent);
26361 + err = (h_trap != a->mvd_h_dst_parent);
26363 + BUG_ON(err); /* it should never happen */
26364 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
26367 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26368 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26369 + au_pin_hdir_lock(&a->mvd_pin_src);
26370 + au_unpin(&a->mvd_pin_src);
26371 + au_pin_hdir_lock(&a->mvd_pin_dst);
26374 + goto out; /* success */
26377 + au_unpin(&a->mvd_pin_dst);
26383 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
26385 + if (!a->rename_lock)
26386 + au_unpin(&a->mvd_pin_src);
26388 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26389 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26390 + au_pin_hdir_lock(&a->mvd_pin_src);
26391 + au_unpin(&a->mvd_pin_src);
26392 + au_pin_hdir_lock(&a->mvd_pin_dst);
26394 + au_unpin(&a->mvd_pin_dst);
26397 +/* copy-down the file */
26398 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
26401 + struct au_cp_generic cpg = {
26402 + .dentry = a->dentry,
26403 + .bdst = a->mvd_bdst,
26404 + .bsrc = a->mvd_bsrc,
26406 + .pin = &a->mvd_pin_dst,
26407 + .flags = AuCpup_DTIME | AuCpup_HOPEN
26410 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
26411 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
26412 + au_fset_cpup(cpg.flags, OVERWRITE);
26413 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
26414 + au_fset_cpup(cpg.flags, RWDST);
26415 + err = au_sio_cpdown_simple(&cpg);
26416 + if (unlikely(err))
26417 + AU_MVD_PR(dmsg, "cpdown failed\n");
26424 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
26427 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
26430 + struct path h_path;
26431 + struct au_branch *br;
26432 + struct inode *delegated;
26434 + br = au_sbr(a->sb, a->mvd_bdst);
26435 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
26436 + err = PTR_ERR(h_path.dentry);
26437 + if (IS_ERR(h_path.dentry)) {
26438 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
26443 + if (d_is_positive(h_path.dentry)) {
26444 + h_path.mnt = au_br_mnt(br);
26445 + delegated = NULL;
26446 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
26447 + &delegated, /*force*/0);
26448 + if (unlikely(err == -EWOULDBLOCK)) {
26449 + pr_warn("cannot retry for NFSv4 delegation"
26450 + " for an internal unlink\n");
26453 + if (unlikely(err))
26454 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
26456 + dput(h_path.dentry);
26464 + * unlink the topmost h_dentry
26466 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
26469 + struct path h_path;
26470 + struct inode *delegated;
26472 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
26473 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
26474 + delegated = NULL;
26475 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
26476 + if (unlikely(err == -EWOULDBLOCK)) {
26477 + pr_warn("cannot retry for NFSv4 delegation"
26478 + " for an internal unlink\n");
26481 + if (unlikely(err))
26482 + AU_MVD_PR(dmsg, "unlink failed\n");
26488 +/* Since mvdown succeeded, we ignore an error of this function */
26489 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
26492 + struct au_branch *br;
26494 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
26495 + br = au_sbr(a->sb, a->mvd_bsrc);
26496 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
26498 + br = au_sbr(a->sb, a->mvd_bdst);
26499 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
26500 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
26503 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
26505 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
26509 + * copy-down the file and unlink the bsrc file.
26510 + * - unlink the bdst whout if exist
26511 + * - copy-down the file (with whtmp name and rename)
26512 + * - unlink the bsrc file
26514 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
26518 + err = au_do_mkdir(dmsg, a);
26520 + err = au_do_lock(dmsg, a);
26521 + if (unlikely(err))
26525 + * do not revert the activities we made on bdst since they should be
26526 + * harmless in aufs.
26529 + err = au_do_cpdown(dmsg, a);
26531 + err = au_do_unlink_wh(dmsg, a);
26532 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
26533 + err = au_do_unlink(dmsg, a);
26534 + if (unlikely(err))
26537 + AuDbg("%pd2, 0x%x, %d --> %d\n",
26538 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
26539 + if (find_lower_writable(a) < 0)
26540 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
26542 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
26543 + au_do_stfs(dmsg, a);
26545 + /* maintain internal array */
26546 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
26547 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
26548 + au_set_dbtop(a->dentry, a->mvd_bdst);
26549 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
26550 + au_set_ibtop(a->inode, a->mvd_bdst);
26552 + /* hide the lower */
26553 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
26554 + au_set_dbbot(a->dentry, a->mvd_bsrc);
26555 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
26556 + au_set_ibbot(a->inode, a->mvd_bsrc);
26558 + if (au_dbbot(a->dentry) < a->mvd_bdst)
26559 + au_set_dbbot(a->dentry, a->mvd_bdst);
26560 + if (au_ibbot(a->inode) < a->mvd_bdst)
26561 + au_set_ibbot(a->inode, a->mvd_bdst);
26564 + au_do_unlock(dmsg, a);
26570 +/* ---------------------------------------------------------------------- */
26572 +/* make sure the file is idle */
26573 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
26575 + int err, plinked;
26578 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
26579 + if (au_dbtop(a->dentry) == a->mvd_bsrc
26580 + && au_dcount(a->dentry) == 1
26581 + && atomic_read(&a->inode->i_count) == 1
26582 + /* && a->mvd_h_src_inode->i_nlink == 1 */
26583 + && (!plinked || !au_plink_test(a->inode))
26584 + && a->inode->i_nlink == 1)
26589 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
26590 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
26591 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
26592 + a->mvd_h_src_inode->i_nlink,
26593 + plinked, plinked ? au_plink_test(a->inode) : 0);
26600 +/* make sure the parent dir is fine */
26601 +static int au_mvd_args_parent(const unsigned char dmsg,
26602 + struct au_mvd_args *a)
26605 + aufs_bindex_t bindex;
26608 + if (unlikely(au_alive_dir(a->parent))) {
26610 + AU_MVD_PR(dmsg, "parent dir is dead\n");
26614 + a->bopq = au_dbdiropq(a->parent);
26615 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
26616 + AuDbg("b%d\n", bindex);
26617 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
26618 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
26620 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
26621 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
26622 + a->bopq, a->mvd_bdst);
26630 +static int au_mvd_args_intermediate(const unsigned char dmsg,
26631 + struct au_mvd_args *a)
26634 + struct au_dinfo *dinfo, *tmp;
26636 + /* lookup the next lower positive entry */
26638 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
26639 + if (unlikely(!tmp))
26644 + dinfo = au_di(a->dentry);
26645 + au_di_cp(tmp, dinfo);
26646 + au_di_swap(tmp, dinfo);
26648 + /* returns the number of positive dentries */
26649 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
26650 + /* AuLkup_IGNORE_PERM */ 0);
26652 + a->bwh = au_dbwh(a->dentry);
26653 + else if (err > 0)
26654 + a->bfound = au_dbtop(a->dentry);
26656 + au_di_swap(tmp, dinfo);
26657 + au_rw_write_unlock(&tmp->di_rwsem);
26659 + if (unlikely(err < 0))
26660 + AU_MVD_PR(dmsg, "failed look-up lower\n");
26663 + * here, we have these cases.
26665 + * no positive dentry under bsrc. there are more sub-cases.
26667 + * there no whiteout, we can safely move-down.
26670 + * bsrc < bwh && bwh < bdst
26671 + * there is a whiteout on RO branch. cannot proceed.
26673 + * there is a whiteout on the RW target branch. it should
26676 + * there is a whiteout somewhere unrelated branch.
26677 + * -1 < bfound && bfound <= bsrc
26680 + * found, but it is on RO branch between bsrc and bdst. cannot
26683 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
26686 + * found, after we create the file on bdst, it will be hidden.
26689 + AuDebugOn(a->bfound == -1
26691 + && a->bwh <= a->mvd_bsrc);
26692 + AuDebugOn(-1 < a->bfound
26693 + && a->bfound <= a->mvd_bsrc);
26696 + if (a->bfound == -1
26697 + && a->mvd_bsrc < a->bwh
26699 + && a->bwh < a->mvd_bdst) {
26700 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
26701 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
26702 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
26704 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
26705 + a->mvd_errno = EAU_MVDOWN_UPPER;
26706 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
26707 + a->mvd_bdst, a->bfound);
26711 + err = 0; /* success */
26718 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
26723 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
26724 + && a->bfound == a->mvd_bdst)
26730 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
26733 + struct au_branch *br;
26736 + if (unlikely(S_ISDIR(a->inode->i_mode)))
26740 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
26741 + a->mvd_bsrc = au_ibtop(a->inode);
26743 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
26744 + if (unlikely(a->mvd_bsrc < 0
26745 + || (a->mvd_bsrc < au_dbtop(a->dentry)
26746 + || au_dbbot(a->dentry) < a->mvd_bsrc
26747 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
26748 + || (a->mvd_bsrc < au_ibtop(a->inode)
26749 + || au_ibbot(a->inode) < a->mvd_bsrc
26750 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
26751 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
26752 + AU_MVD_PR(dmsg, "no upper\n");
26756 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
26757 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
26758 + AU_MVD_PR(dmsg, "on the bottom\n");
26761 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
26762 + br = au_sbr(a->sb, a->mvd_bsrc);
26763 + err = au_br_rdonly(br);
26764 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
26765 + if (unlikely(err))
26767 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
26768 + || IS_APPEND(a->mvd_h_src_inode))) {
26770 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
26776 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
26777 + a->mvd_bdst = find_lower_writable(a);
26778 + if (unlikely(a->mvd_bdst < 0)) {
26779 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
26780 + AU_MVD_PR(dmsg, "no writable lower branch\n");
26784 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
26785 + if (unlikely(a->mvd_bdst < 0
26786 + || au_sbbot(a->sb) < a->mvd_bdst)) {
26787 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
26788 + AU_MVD_PR(dmsg, "no lower brid\n");
26793 + err = au_mvd_args_busy(dmsg, a);
26795 + err = au_mvd_args_parent(dmsg, a);
26797 + err = au_mvd_args_intermediate(dmsg, a);
26799 + err = au_mvd_args_exist(dmsg, a);
26801 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
26808 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
26811 + unsigned char dmsg;
26812 + struct au_mvd_args *args;
26813 + struct inode *inode;
26815 + inode = d_inode(dentry);
26817 + if (unlikely(!capable(CAP_SYS_ADMIN)))
26821 + args = kmalloc(sizeof(*args), GFP_NOFS);
26822 + if (unlikely(!args))
26825 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
26827 + /* VERIFY_WRITE */
26828 + err = !access_ok(uarg, sizeof(*uarg));
26829 + if (unlikely(err)) {
26834 + AuDbg("flags 0x%x\n", args->mvdown.flags);
26835 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
26836 + args->mvdown.au_errno = 0;
26837 + args->dentry = dentry;
26838 + args->inode = inode;
26839 + args->sb = dentry->d_sb;
26842 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
26843 + args->parent = dget_parent(dentry);
26844 + args->dir = d_inode(args->parent);
26845 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
26846 + dput(args->parent);
26847 + if (unlikely(args->parent != dentry->d_parent)) {
26848 + AU_MVD_PR(dmsg, "parent dir is moved\n");
26852 + inode_lock_nested(inode, I_MUTEX_CHILD);
26853 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
26854 + if (unlikely(err))
26857 + di_write_lock_parent(args->parent);
26858 + err = au_mvd_args(dmsg, args);
26859 + if (unlikely(err))
26862 + err = au_do_mvdown(dmsg, args);
26863 + if (unlikely(err))
26866 + au_cpup_attr_timesizes(args->dir);
26867 + au_cpup_attr_timesizes(inode);
26868 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
26869 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
26870 + /* au_digen_dec(dentry); */
26873 + di_write_unlock(args->parent);
26874 + aufs_read_unlock(dentry, AuLock_DW);
26876 + inode_unlock(inode);
26878 + inode_unlock(args->dir);
26880 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
26883 + au_kfree_rcu(args);
26888 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
26889 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
26890 +++ linux/fs/aufs/opts.c 2022-11-05 23:02:18.969222617 +0100
26892 +// SPDX-License-Identifier: GPL-2.0
26894 + * Copyright (C) 2005-2022 Junjiro R. Okajima
26896 + * This program is free software; you can redistribute it and/or modify
26897 + * it under the terms of the GNU General Public License as published by
26898 + * the Free Software Foundation; either version 2 of the License, or
26899 + * (at your option) any later version.
26901 + * This program is distributed in the hope that it will be useful,
26902 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26903 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26904 + * GNU General Public License for more details.
26906 + * You should have received a copy of the GNU General Public License
26907 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26911 + * mount options/flags
26914 +#include <linux/types.h> /* a distribution requires */
26915 +#include <linux/parser.h>
26918 +/* ---------------------------------------------------------------------- */
26920 +static const char *au_parser_pattern(int val, match_table_t tbl)
26922 + struct match_token *p;
26925 + while (p->pattern) {
26926 + if (p->token == val)
26927 + return p->pattern;
26934 +static const char *au_optstr(int *val, match_table_t tbl)
26936 + struct match_token *p;
26943 + while (p->pattern) {
26945 + && (v & p->token) == p->token) {
26946 + *val &= ~p->token;
26947 + return p->pattern;
26956 +/* ---------------------------------------------------------------------- */
26958 +static match_table_t brperm = {
26959 + {AuBrPerm_RO, AUFS_BRPERM_RO},
26960 + {AuBrPerm_RR, AUFS_BRPERM_RR},
26961 + {AuBrPerm_RW, AUFS_BRPERM_RW},
26965 +static match_table_t brattr = {
26967 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
26968 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
26969 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
26970 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
26971 +#ifdef CONFIG_AUFS_FHSM
26972 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
26974 +#ifdef CONFIG_AUFS_XATTR
26975 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
26976 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
26977 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
26978 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
26979 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
26980 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
26983 + /* ro/rr branch */
26984 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
26987 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
26988 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
26993 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
27000 + p = strchr(str, '+');
27003 + v = match_token(str, table, args);
27005 + if (v & AuBrAttr_CMOO_Mask)
27006 + attr &= ~AuBrAttr_CMOO_Mask;
27011 + pr_warn("ignored branch attribute %s\n", str);
27021 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
27029 + p = au_optstr(&perm, brattr);
27032 + memcpy(q, p, sz + 1);
27038 + p = au_optstr(&perm, brattr);
27042 + memcpy(q, p, sz + 1);
27048 + return q - str->a;
27051 +int au_br_perm_val(char *perm)
27053 + int val, bad, sz;
27055 + substring_t args[MAX_OPT_ARGS];
27056 + au_br_perm_str_t attr;
27058 + p = strchr(perm, '+');
27061 + val = match_token(perm, brperm, args);
27065 + pr_warn("ignored branch permission %s\n", perm);
27066 + val = AuBrPerm_RO;
27072 + val |= br_attr_val(p + 1, brattr, args);
27075 + switch (val & AuBrPerm_Mask) {
27076 + case AuBrPerm_RO:
27077 + case AuBrPerm_RR:
27078 + bad = val & AuBrWAttr_Mask;
27079 + val &= ~AuBrWAttr_Mask;
27081 + case AuBrPerm_RW:
27082 + bad = val & AuBrRAttr_Mask;
27083 + val &= ~AuBrRAttr_Mask;
27088 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
27089 + * does not treat it as an error, just warning.
27090 + * this is a tiny guard for the user operation.
27092 + if (val & AuBrAttr_UNPIN) {
27093 + bad |= AuBrAttr_UNPIN;
27094 + val &= ~AuBrAttr_UNPIN;
27097 + if (unlikely(bad)) {
27098 + sz = au_do_optstr_br_attr(&attr, bad);
27100 + pr_warn("ignored branch attribute %s\n", attr.a);
27107 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
27109 + au_br_perm_str_t attr;
27115 + p = au_optstr(&perm, brperm);
27116 + AuDebugOn(!p || !*p);
27118 + memcpy(q, p, sz + 1);
27121 + sz = au_do_optstr_br_attr(&attr, perm);
27124 + memcpy(q, attr.a, sz + 1);
27127 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
27130 +/* ---------------------------------------------------------------------- */
27132 +static match_table_t udbalevel = {
27133 + {AuOpt_UDBA_REVAL, "reval"},
27134 + {AuOpt_UDBA_NONE, "none"},
27135 +#ifdef CONFIG_AUFS_HNOTIFY
27136 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
27137 +#ifdef CONFIG_AUFS_HFSNOTIFY
27138 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
27144 +int au_udba_val(char *str)
27146 + substring_t args[MAX_OPT_ARGS];
27148 + return match_token(str, udbalevel, args);
27151 +const char *au_optstr_udba(int udba)
27153 + return au_parser_pattern(udba, udbalevel);
27156 +/* ---------------------------------------------------------------------- */
27158 +static match_table_t au_wbr_create_policy = {
27159 + {AuWbrCreate_TDP, "tdp"},
27160 + {AuWbrCreate_TDP, "top-down-parent"},
27161 + {AuWbrCreate_RR, "rr"},
27162 + {AuWbrCreate_RR, "round-robin"},
27163 + {AuWbrCreate_MFS, "mfs"},
27164 + {AuWbrCreate_MFS, "most-free-space"},
27165 + {AuWbrCreate_MFSV, "mfs:%d"},
27166 + {AuWbrCreate_MFSV, "most-free-space:%d"},
27168 + /* top-down regardless the parent, and then mfs */
27169 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
27170 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
27172 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
27173 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
27174 + {AuWbrCreate_PMFS, "pmfs"},
27175 + {AuWbrCreate_PMFSV, "pmfs:%d"},
27176 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
27177 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
27182 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
27183 + struct au_opt_wbr_create *create)
27186 + unsigned long long ull;
27189 + if (!match_u64(arg, &ull))
27190 + create->mfsrr_watermark = ull;
27192 + pr_err("bad integer in %s\n", str);
27199 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
27200 + struct au_opt_wbr_create *create)
27205 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
27206 + create->mfs_second = n;
27208 + pr_err("bad integer in %s\n", str);
27215 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
27218 + substring_t args[MAX_OPT_ARGS];
27220 + err = match_token(str, au_wbr_create_policy, args);
27221 + create->wbr_create = err;
27223 + case AuWbrCreate_MFSRRV:
27224 + case AuWbrCreate_TDMFSV:
27225 + case AuWbrCreate_PMFSRRV:
27226 + e = au_wbr_mfs_wmark(&args[0], str, create);
27228 + e = au_wbr_mfs_sec(&args[1], str, create);
27232 + case AuWbrCreate_MFSRR:
27233 + case AuWbrCreate_TDMFS:
27234 + case AuWbrCreate_PMFSRR:
27235 + e = au_wbr_mfs_wmark(&args[0], str, create);
27236 + if (unlikely(e)) {
27241 + case AuWbrCreate_MFS:
27242 + case AuWbrCreate_PMFS:
27243 + create->mfs_second = AUFS_MFS_DEF_SEC;
27245 + case AuWbrCreate_MFSV:
27246 + case AuWbrCreate_PMFSV:
27247 + e = au_wbr_mfs_sec(&args[0], str, create);
27256 +const char *au_optstr_wbr_create(int wbr_create)
27258 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
27261 +static match_table_t au_wbr_copyup_policy = {
27262 + {AuWbrCopyup_TDP, "tdp"},
27263 + {AuWbrCopyup_TDP, "top-down-parent"},
27264 + {AuWbrCopyup_BUP, "bup"},
27265 + {AuWbrCopyup_BUP, "bottom-up-parent"},
27266 + {AuWbrCopyup_BU, "bu"},
27267 + {AuWbrCopyup_BU, "bottom-up"},
27271 +int au_wbr_copyup_val(char *str)
27273 + substring_t args[MAX_OPT_ARGS];
27275 + return match_token(str, au_wbr_copyup_policy, args);
27278 +const char *au_optstr_wbr_copyup(int wbr_copyup)
27280 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
27283 +/* ---------------------------------------------------------------------- */
27285 +int au_opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
27286 + aufs_bindex_t bindex)
27289 + struct au_opt_add *add = &opt->add;
27292 + add->bindex = bindex;
27293 + add->perm = AuBrPerm_RO;
27294 + add->pathname = opt_str;
27295 + p = strchr(opt_str, '=');
27299 + add->perm = au_br_perm_val(p);
27302 + err = vfsub_kern_path(add->pathname, AuOpt_LkupDirFlags, &add->path);
27305 + add->perm = AuBrPerm_RO;
27306 + if (au_test_fs_rr(add->path.dentry->d_sb))
27307 + add->perm = AuBrPerm_RR;
27308 + else if (!bindex && !(sb_flags & SB_RDONLY))
27309 + add->perm = AuBrPerm_RW;
27311 + opt->type = Opt_add;
27314 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
27321 +static int au_opt_wbr_create(struct super_block *sb,
27322 + struct au_opt_wbr_create *create)
27325 + struct au_sbinfo *sbinfo;
27327 + SiMustWriteLock(sb);
27329 + err = 1; /* handled */
27330 + sbinfo = au_sbi(sb);
27331 + if (sbinfo->si_wbr_create_ops->fin) {
27332 + err = sbinfo->si_wbr_create_ops->fin(sb);
27337 + sbinfo->si_wbr_create = create->wbr_create;
27338 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
27339 + switch (create->wbr_create) {
27340 + case AuWbrCreate_MFSRRV:
27341 + case AuWbrCreate_MFSRR:
27342 + case AuWbrCreate_TDMFS:
27343 + case AuWbrCreate_TDMFSV:
27344 + case AuWbrCreate_PMFSRR:
27345 + case AuWbrCreate_PMFSRRV:
27346 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
27348 + case AuWbrCreate_MFS:
27349 + case AuWbrCreate_MFSV:
27350 + case AuWbrCreate_PMFS:
27351 + case AuWbrCreate_PMFSV:
27352 + sbinfo->si_wbr_mfs.mfs_expire
27353 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
27357 + if (sbinfo->si_wbr_create_ops->init)
27358 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27365 + * plus: processed without an error
27366 + * zero: unprocessed
27368 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27369 + struct au_opts *opts)
27372 + struct au_sbinfo *sbinfo;
27374 + SiMustWriteLock(sb);
27376 + err = 1; /* handled */
27377 + sbinfo = au_sbi(sb);
27378 + switch (opt->type) {
27380 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27381 + sbinfo->si_mntflags |= opt->udba;
27382 + opts->given_udba |= opt->udba;
27387 + au_opt_set(sbinfo->si_mntflags, PLINK);
27389 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27390 + au_plink_put(sb, /*verbose*/1);
27391 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27394 + case Opt_list_plink:
27395 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27396 + au_plink_list(sb);
27401 + au_opt_set(sbinfo->si_mntflags, DIO);
27402 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27404 + au_opt_clr(sbinfo->si_mntflags, DIO);
27405 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27409 + case Opt_fhsm_sec:
27410 + au_fhsm_set(sbinfo, opt->fhsm_second);
27413 + case Opt_diropq_a:
27414 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27416 + case Opt_diropq_w:
27417 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27420 + case Opt_warn_perm:
27422 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27424 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27427 + case Opt_verbose:
27429 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27431 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27436 + au_opt_set(sbinfo->si_mntflags, SUM);
27438 + au_opt_clr(sbinfo->si_mntflags, SUM);
27439 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27443 + au_opt_clr(sbinfo->si_mntflags, SUM);
27444 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27447 + case Opt_wbr_create:
27448 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27450 + case Opt_wbr_copyup:
27451 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27452 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27456 + sbinfo->si_dirwh = opt->dirwh;
27459 + case Opt_rdcache:
27460 + sbinfo->si_rdcache
27461 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27464 + sbinfo->si_rdblk = opt->rdblk;
27467 + sbinfo->si_rdhash = opt->rdhash;
27472 + au_opt_set(sbinfo->si_mntflags, SHWH);
27474 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27477 + case Opt_dirperm1:
27479 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27481 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27484 + case Opt_trunc_xino:
27486 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27488 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27491 + case Opt_trunc_xino_path:
27492 + case Opt_itrunc_xino:
27493 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27499 + case Opt_trunc_xib:
27501 + au_fset_opts(opts->flags, TRUNC_XIB);
27503 + au_fclr_opts(opts->flags, TRUNC_XIB);
27509 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27510 + err = au_dr_opt_set(sb);
27515 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27517 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27518 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27524 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27530 + sb->s_flags |= SB_POSIXACL;
27532 + sb->s_flags &= ~SB_POSIXACL;
27544 + * returns tri-state.
27545 + * plus: processed without an error
27546 + * zero: unprocessed
27549 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27550 + struct au_opts *opts)
27552 + int err, do_refresh;
27555 + switch (opt->type) {
27557 + opt->add.bindex = au_sbbot(sb) + 1;
27558 + if (opt->add.bindex < 0)
27559 + opt->add.bindex = 0;
27561 + /* Always goto add, not fallthrough */
27562 + case Opt_prepend:
27563 + opt->add.bindex = 0;
27565 + add: /* indented label */
27567 + err = au_br_add(sb, &opt->add,
27568 + au_ftest_opts(opts->flags, REMOUNT));
27571 + au_fset_opts(opts->flags, REFRESH);
27577 + err = au_br_del(sb, &opt->del,
27578 + au_ftest_opts(opts->flags, REMOUNT));
27581 + au_fset_opts(opts->flags, TRUNC_XIB);
27582 + au_fset_opts(opts->flags, REFRESH);
27588 + err = au_br_mod(sb, &opt->mod,
27589 + au_ftest_opts(opts->flags, REMOUNT),
27594 + au_fset_opts(opts->flags, REFRESH);
27601 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27602 + struct au_opt_xino **opt_xino,
27603 + struct au_opts *opts)
27608 + switch (opt->type) {
27610 + err = au_xino_set(sb, &opt->xino,
27611 + !!au_ftest_opts(opts->flags, REMOUNT));
27613 + *opt_xino = &opt->xino;
27617 + *opt_xino = (void *)-1;
27624 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27625 + unsigned int pending)
27628 + aufs_bindex_t bindex, bbot;
27629 + unsigned char do_plink, skip, do_free, can_no_dreval;
27630 + struct au_branch *br;
27631 + struct au_wbr *wbr;
27632 + struct dentry *root, *dentry;
27633 + struct inode *dir, *h_dir;
27634 + struct au_sbinfo *sbinfo;
27635 + struct au_hinode *hdir;
27637 + SiMustAnyLock(sb);
27639 + sbinfo = au_sbi(sb);
27640 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27642 + if (!(sb_flags & SB_RDONLY)) {
27643 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27644 + pr_warn("first branch should be rw\n");
27645 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27646 + pr_warn_once("shwh should be used with ro\n");
27649 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27650 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27651 + pr_warn_once("udba=*notify requires xino\n");
27653 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27654 + pr_warn_once("dirperm1 breaks the protection"
27655 + " by the permission bits on the lower branch\n");
27659 + root = sb->s_root;
27660 + dir = d_inode(root);
27661 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27662 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27664 + bbot = au_sbbot(sb);
27665 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27667 + h_dir = au_h_iptr(dir, bindex);
27668 + br = au_sbr(sb, bindex);
27670 + if ((br->br_perm & AuBrAttr_ICEX)
27671 + && !h_dir->i_op->listxattr)
27672 + br->br_perm &= ~AuBrAttr_ICEX;
27673 +#if 0 /* untested */
27674 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27675 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27676 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27680 + wbr = br->br_wbr;
27682 + wbr_wh_read_lock(wbr);
27684 + if (!au_br_writable(br->br_perm)) {
27687 + || (!wbr->wbr_whbase
27688 + && !wbr->wbr_plink
27689 + && !wbr->wbr_orph));
27690 + } else if (!au_br_wh_linkable(br->br_perm)) {
27691 + /* skip = (!br->br_whbase && !br->br_orph); */
27692 + skip = (!wbr || !wbr->wbr_whbase);
27693 + if (skip && wbr) {
27695 + skip = !!wbr->wbr_plink;
27697 + skip = !wbr->wbr_plink;
27700 + /* skip = (br->br_whbase && br->br_ohph); */
27701 + skip = (wbr && wbr->wbr_whbase);
27704 + skip = !!wbr->wbr_plink;
27706 + skip = !wbr->wbr_plink;
27710 + wbr_wh_read_unlock(wbr);
27712 + if (can_no_dreval) {
27713 + dentry = br->br_path.dentry;
27714 + spin_lock(&dentry->d_lock);
27715 + if (dentry->d_flags &
27716 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27717 + can_no_dreval = 0;
27718 + spin_unlock(&dentry->d_lock);
27721 + if (au_br_fhsm(br->br_perm)) {
27723 + AuDebugOn(!br->br_fhsm);
27729 + hdir = au_hi(dir, bindex);
27730 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27732 + wbr_wh_write_lock(wbr);
27733 + err = au_wh_init(br, sb);
27735 + wbr_wh_write_unlock(wbr);
27736 + au_hn_inode_unlock(hdir);
27738 + if (!err && do_free) {
27739 + au_kfree_rcu(wbr);
27740 + br->br_wbr = NULL;
27744 + if (can_no_dreval)
27745 + au_fset_si(sbinfo, NO_DREVAL);
27747 + au_fclr_si(sbinfo, NO_DREVAL);
27750 + au_fset_si(sbinfo, FHSM);
27751 + for (bindex = bbot; bindex >= 0; bindex--) {
27752 + br = au_sbr(sb, bindex);
27753 + if (au_br_fhsm(br->br_perm)) {
27754 + au_fhsm_set_bottom(sb, bindex);
27759 + au_fclr_si(sbinfo, FHSM);
27760 + au_fhsm_set_bottom(sb, -1);
27766 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27769 + unsigned int tmp;
27770 + aufs_bindex_t bindex, bbot;
27771 + struct au_opt *opt;
27772 + struct au_opt_xino *opt_xino, xino;
27773 + struct au_sbinfo *sbinfo;
27774 + struct au_branch *br;
27775 + struct inode *dir;
27777 + SiMustWriteLock(sb);
27782 + while (err >= 0 && opt->type != Opt_tail)
27783 + err = au_opt_simple(sb, opt++, opts);
27786 + else if (unlikely(err < 0))
27789 + /* disable xino and udba temporary */
27790 + sbinfo = au_sbi(sb);
27791 + tmp = sbinfo->si_mntflags;
27792 + au_opt_clr(sbinfo->si_mntflags, XINO);
27793 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27796 + while (err >= 0 && opt->type != Opt_tail)
27797 + err = au_opt_br(sb, opt++, opts);
27800 + else if (unlikely(err < 0))
27803 + bbot = au_sbbot(sb);
27804 + if (unlikely(bbot < 0)) {
27806 + pr_err("no branches\n");
27810 + if (au_opt_test(tmp, XINO))
27811 + au_opt_set(sbinfo->si_mntflags, XINO);
27813 + while (!err && opt->type != Opt_tail)
27814 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27815 + if (unlikely(err))
27818 + err = au_opts_verify(sb, sb->s_flags, tmp);
27819 + if (unlikely(err))
27822 + /* restore xino */
27823 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27824 + xino.file = au_xino_def(sb);
27825 + err = PTR_ERR(xino.file);
27826 + if (IS_ERR(xino.file))
27829 + err = au_xino_set(sb, &xino, /*remount*/0);
27831 + if (unlikely(err))
27835 + /* restore udba */
27836 + tmp &= AuOptMask_UDBA;
27837 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27838 + sbinfo->si_mntflags |= tmp;
27839 + bbot = au_sbbot(sb);
27840 + for (bindex = 0; bindex <= bbot; bindex++) {
27841 + br = au_sbr(sb, bindex);
27842 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27843 + if (unlikely(err))
27844 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27846 + /* go on even if err */
27848 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27849 + dir = d_inode(sb->s_root);
27850 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27857 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27860 + unsigned char no_dreval;
27861 + struct inode *dir;
27862 + struct au_opt_xino *opt_xino;
27863 + struct au_opt *opt;
27864 + struct au_sbinfo *sbinfo;
27866 + SiMustWriteLock(sb);
27868 + err = au_dr_opt_flush(sb);
27869 + if (unlikely(err))
27871 + au_fset_opts(opts->flags, DR_FLUSHED);
27873 + dir = d_inode(sb->s_root);
27874 + sbinfo = au_sbi(sb);
27877 + while (err >= 0 && opt->type != Opt_tail) {
27878 + err = au_opt_simple(sb, opt, opts);
27880 + err = au_opt_br(sb, opt, opts);
27882 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27888 + /* go on even err */
27890 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27891 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27892 + if (unlikely(rerr && !err))
27895 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27896 + au_fset_opts(opts->flags, REFRESH_IDOP);
27898 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27899 + rerr = au_xib_trunc(sb);
27900 + if (unlikely(rerr && !err))
27904 + /* will be handled by the caller */
27905 + if (!au_ftest_opts(opts->flags, REFRESH)
27906 + && (opts->given_udba
27907 + || au_opt_test(sbinfo->si_mntflags, XINO)
27908 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27910 + au_fset_opts(opts->flags, REFRESH);
27912 + AuDbg("status 0x%x\n", opts->flags);
27918 +/* ---------------------------------------------------------------------- */
27920 +unsigned int au_opt_udba(struct super_block *sb)
27922 + return au_mntflags(sb) & AuOptMask_UDBA;
27924 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27925 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27926 +++ linux/fs/aufs/opts.h 2022-11-05 23:02:18.969222617 +0100
27928 +/* SPDX-License-Identifier: GPL-2.0 */
27930 + * Copyright (C) 2005-2022 Junjiro R. Okajima
27932 + * This program is free software; you can redistribute it and/or modify
27933 + * it under the terms of the GNU General Public License as published by
27934 + * the Free Software Foundation; either version 2 of the License, or
27935 + * (at your option) any later version.
27937 + * This program is distributed in the hope that it will be useful,
27938 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27939 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27940 + * GNU General Public License for more details.
27942 + * You should have received a copy of the GNU General Public License
27943 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27947 + * mount options/flags
27950 +#ifndef __AUFS_OPTS_H__
27951 +#define __AUFS_OPTS_H__
27955 +#include <linux/fs_parser.h>
27956 +#include <linux/namei.h>
27957 +#include <linux/path.h>
27961 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
27962 + Opt_idel, Opt_imod,
27963 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
27964 + Opt_xino, Opt_noxino,
27965 + Opt_trunc_xino, Opt_trunc_xino_v,
27966 + Opt_trunc_xino_path, Opt_itrunc_xino,
27969 + Opt_plink, Opt_list_plink,
27972 + Opt_diropq, Opt_diropq_a, Opt_diropq_w,
27974 + Opt_wbr_copyup, Opt_wbr_create,
27976 + Opt_verbose, Opt_noverbose,
27977 + Opt_sum, Opt_wsum,
27981 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
27984 +/* ---------------------------------------------------------------------- */
27987 +#define AuOpt_XINO 1 /* external inode number bitmap
27988 + and translation table */
27989 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27990 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27991 +#define AuOpt_UDBA_REVAL (1 << 3)
27992 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27993 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27994 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27995 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27997 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27998 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27999 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
28000 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
28001 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
28002 +#define AuOpt_DIO (1 << 14) /* direct io */
28003 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
28005 +#ifndef CONFIG_AUFS_HNOTIFY
28006 +#undef AuOpt_UDBA_HNOTIFY
28007 +#define AuOpt_UDBA_HNOTIFY 0
28009 +#ifndef CONFIG_AUFS_DIRREN
28010 +#undef AuOpt_DIRREN
28011 +#define AuOpt_DIRREN 0
28013 +#ifndef CONFIG_AUFS_SHWH
28015 +#define AuOpt_SHWH 0
28018 +#define AuOpt_Def (AuOpt_XINO \
28019 + | AuOpt_UDBA_REVAL \
28021 + /* | AuOpt_DIRPERM1 */ \
28022 + | AuOpt_WARN_PERM)
28023 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
28024 + | AuOpt_UDBA_REVAL \
28025 + | AuOpt_UDBA_HNOTIFY)
28027 +#define AuOpt_LkupDirFlags (LOOKUP_FOLLOW | LOOKUP_DIRECTORY)
28029 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
28030 +#define au_opt_set(flags, name) do { \
28031 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
28032 + ((flags) |= AuOpt_##name); \
28034 +#define au_opt_set_udba(flags, name) do { \
28035 + (flags) &= ~AuOptMask_UDBA; \
28036 + ((flags) |= AuOpt_##name); \
28038 +#define au_opt_clr(flags, name) do { \
28039 + ((flags) &= ~AuOpt_##name); \
28042 +static inline unsigned int au_opts_plink(unsigned int mntflags)
28044 +#ifdef CONFIG_PROC_FS
28047 + return mntflags & ~AuOpt_PLINK;
28051 +/* ---------------------------------------------------------------------- */
28053 +/* policies to select one among multiple writable branches */
28055 + AuWbrCreate_TDP, /* top down parent */
28056 + AuWbrCreate_RR, /* round robin */
28057 + AuWbrCreate_MFS, /* most free space */
28058 + AuWbrCreate_MFSV, /* mfs with seconds */
28059 + AuWbrCreate_MFSRR, /* mfs then rr */
28060 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
28061 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
28062 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
28063 + AuWbrCreate_PMFS, /* parent and mfs */
28064 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
28065 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
28066 + AuWbrCreate_PMFSRRV, /* plus seconds */
28068 + AuWbrCreate_Def = AuWbrCreate_TDP
28072 + AuWbrCopyup_TDP, /* top down parent */
28073 + AuWbrCopyup_BUP, /* bottom up parent */
28074 + AuWbrCopyup_BU, /* bottom up */
28076 + AuWbrCopyup_Def = AuWbrCopyup_TDP
28079 +/* ---------------------------------------------------------------------- */
28083 +struct au_opt_add {
28084 + aufs_bindex_t bindex;
28087 + struct path path;
28090 +struct au_opt_del {
28092 + struct path h_path;
28095 +struct au_opt_mod {
28098 + struct dentry *h_root;
28101 +struct au_opt_xino {
28103 + struct file *file;
28106 +struct au_opt_xino_itrunc {
28107 + aufs_bindex_t bindex;
28110 +struct au_opt_wbr_create {
28113 + unsigned long long mfsrr_watermark;
28119 + struct au_opt_xino xino;
28120 + struct au_opt_xino_itrunc xino_itrunc;
28121 + struct au_opt_add add;
28122 + struct au_opt_del del;
28123 + struct au_opt_mod mod;
28126 + unsigned int rdblk;
28127 + unsigned int rdhash;
28129 + struct au_opt_wbr_create wbr_create;
28131 + unsigned int fhsm_second;
28132 + bool tf; /* generic flag, true or false */
28137 +#define AuOpts_REMOUNT 1
28138 +#define AuOpts_REFRESH (1 << 1)
28139 +#define AuOpts_TRUNC_XIB (1 << 2)
28140 +#define AuOpts_REFRESH_DYAOP (1 << 3)
28141 +#define AuOpts_REFRESH_IDOP (1 << 4)
28142 +#define AuOpts_DR_FLUSHED (1 << 5)
28143 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
28144 +#define au_fset_opts(flags, name) \
28145 + do { (flags) |= AuOpts_##name; } while (0)
28146 +#define au_fclr_opts(flags, name) \
28147 + do { (flags) &= ~AuOpts_##name; } while (0)
28149 +#ifndef CONFIG_AUFS_DIRREN
28150 +#undef AuOpts_DR_FLUSHED
28151 +#define AuOpts_DR_FLUSHED 0
28155 + struct au_opt *opt;
28158 + unsigned int given_udba;
28159 + unsigned int flags;
28160 + unsigned long sb_flags;
28163 +/* ---------------------------------------------------------------------- */
28166 +int au_br_perm_val(char *perm);
28167 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
28168 +int au_udba_val(char *str);
28169 +const char *au_optstr_udba(int udba);
28170 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create);
28171 +const char *au_optstr_wbr_create(int wbr_create);
28172 +int au_wbr_copyup_val(char *str);
28173 +const char *au_optstr_wbr_copyup(int wbr_copyup);
28175 +int au_opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
28176 + aufs_bindex_t bindex);
28177 +struct super_block;
28178 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
28179 + unsigned int pending);
28180 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
28181 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
28183 +unsigned int au_opt_udba(struct super_block *sb);
28186 +int aufs_fsctx_init(struct fs_context *fc);
28187 +extern const struct fs_parameter_spec aufs_fsctx_paramspec[];
28189 +#endif /* __KERNEL__ */
28190 +#endif /* __AUFS_OPTS_H__ */
28191 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
28192 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
28193 +++ linux/fs/aufs/plink.c 2022-11-05 23:02:18.969222617 +0100
28195 +// SPDX-License-Identifier: GPL-2.0
28197 + * Copyright (C) 2005-2022 Junjiro R. Okajima
28199 + * This program is free software; you can redistribute it and/or modify
28200 + * it under the terms of the GNU General Public License as published by
28201 + * the Free Software Foundation; either version 2 of the License, or
28202 + * (at your option) any later version.
28204 + * This program is distributed in the hope that it will be useful,
28205 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28206 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28207 + * GNU General Public License for more details.
28209 + * You should have received a copy of the GNU General Public License
28210 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28220 + * the pseudo-link maintenance mode.
28221 + * during a user process maintains the pseudo-links,
28222 + * prohibit adding a new plink and branch manipulation.
28226 + * For entry functions which will handle plink, and i_mutex is already held
28228 + * They cannot wait and should return an error at once.
28229 + * Callers has to check the error.
28231 + * For entry functions which will handle plink, but i_mutex is not held
28233 + * They can wait the plink maintenance mode to finish.
28235 + * They behave like F_SETLK and F_SETLKW.
28236 + * If the caller never handle plink, then both flags are unnecessary.
28239 +int au_plink_maint(struct super_block *sb, int flags)
28243 + struct task_struct *parent, *prev;
28244 + struct au_sbinfo *sbi;
28246 + SiMustAnyLock(sb);
28249 + if (!au_opt_test(au_mntflags(sb), PLINK))
28252 + sbi = au_sbi(sb);
28253 + pid = sbi->si_plink_maint_pid;
28254 + if (!pid || pid == current->pid)
28257 + /* todo: it highly depends upon /sbin/mount.aufs */
28259 + parent = current;
28263 + parent = rcu_dereference(parent->real_parent);
28264 + if (parent == prev)
28266 + ppid = task_pid_vnr(parent);
28267 + if (pid == ppid) {
28268 + rcu_read_unlock();
28273 + rcu_read_unlock();
28275 + if (au_ftest_lock(flags, NOPLMW)) {
28276 + /* if there is no i_mutex lock in VFS, we don't need to wait */
28277 + /* AuDebugOn(!lockdep_depth(current)); */
28278 + while (sbi->si_plink_maint_pid) {
28279 + si_read_unlock(sb);
28280 + /* gave up wake_up_bit() */
28281 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
28283 + if (au_ftest_lock(flags, FLUSH))
28284 + au_nwt_flush(&sbi->si_nowait);
28285 + si_noflush_read_lock(sb);
28287 + } else if (au_ftest_lock(flags, NOPLM)) {
28288 + AuDbg("ppid %d, pid %d\n", ppid, pid);
28296 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
28298 + spin_lock(&sbinfo->si_plink_maint_lock);
28299 + sbinfo->si_plink_maint_pid = 0;
28300 + spin_unlock(&sbinfo->si_plink_maint_lock);
28301 + wake_up_all(&sbinfo->si_plink_wq);
28304 +int au_plink_maint_enter(struct super_block *sb)
28307 + struct au_sbinfo *sbinfo;
28310 + sbinfo = au_sbi(sb);
28311 + /* make sure i am the only one in this fs */
28312 + si_write_lock(sb, AuLock_FLUSH);
28313 + if (au_opt_test(au_mntflags(sb), PLINK)) {
28314 + spin_lock(&sbinfo->si_plink_maint_lock);
28315 + if (!sbinfo->si_plink_maint_pid)
28316 + sbinfo->si_plink_maint_pid = current->pid;
28319 + spin_unlock(&sbinfo->si_plink_maint_lock);
28321 + si_write_unlock(sb);
28326 +/* ---------------------------------------------------------------------- */
28328 +#ifdef CONFIG_AUFS_DEBUG
28329 +void au_plink_list(struct super_block *sb)
28332 + struct au_sbinfo *sbinfo;
28333 + struct hlist_bl_head *hbl;
28334 + struct hlist_bl_node *pos;
28335 + struct au_icntnr *icntnr;
28337 + SiMustAnyLock(sb);
28339 + sbinfo = au_sbi(sb);
28340 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28341 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28343 + for (i = 0; i < AuPlink_NHASH; i++) {
28344 + hbl = sbinfo->si_plink + i;
28345 + hlist_bl_lock(hbl);
28346 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28347 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
28348 + hlist_bl_unlock(hbl);
28353 +/* is the inode pseudo-linked? */
28354 +int au_plink_test(struct inode *inode)
28357 + struct au_sbinfo *sbinfo;
28358 + struct hlist_bl_head *hbl;
28359 + struct hlist_bl_node *pos;
28360 + struct au_icntnr *icntnr;
28362 + sbinfo = au_sbi(inode->i_sb);
28363 + AuRwMustAnyLock(&sbinfo->si_rwsem);
28364 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
28365 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28368 + i = au_plink_hash(inode->i_ino);
28369 + hbl = sbinfo->si_plink + i;
28370 + hlist_bl_lock(hbl);
28371 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28372 + if (&icntnr->vfs_inode == inode) {
28376 + hlist_bl_unlock(hbl);
28380 +/* ---------------------------------------------------------------------- */
28383 + * generate a name for plink.
28384 + * the file will be stored under AUFS_WH_PLINKDIR.
28386 +/* 20 is max digits length of ulong 64 */
28387 +#define PLINK_NAME_LEN ((20 + 1) * 2)
28389 +static int plink_name(char *name, int len, struct inode *inode,
28390 + aufs_bindex_t bindex)
28393 + struct inode *h_inode;
28395 + h_inode = au_h_iptr(inode, bindex);
28396 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28400 +struct au_do_plink_lkup_args {
28401 + struct dentry **errp;
28402 + struct qstr *tgtname;
28403 + struct path *h_ppath;
28406 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28407 + struct path *h_ppath)
28409 + struct dentry *h_dentry;
28410 + struct inode *h_inode;
28412 + h_inode = d_inode(h_ppath->dentry);
28413 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28414 + h_dentry = vfsub_lkup_one(tgtname, h_ppath);
28415 + inode_unlock_shared(h_inode);
28420 +static void au_call_do_plink_lkup(void *args)
28422 + struct au_do_plink_lkup_args *a = args;
28423 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_ppath);
28426 +/* lookup the plink-ed @inode under the branch at @bindex */
28427 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28429 + struct dentry *h_dentry;
28430 + struct au_branch *br;
28431 + struct path h_ppath;
28433 + char a[PLINK_NAME_LEN];
28434 + struct qstr tgtname = QSTR_INIT(a, 0);
28436 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28438 + br = au_sbr(inode->i_sb, bindex);
28439 + h_ppath.dentry = br->br_wbr->wbr_plink;
28440 + h_ppath.mnt = au_br_mnt(br);
28441 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28443 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28444 + struct au_do_plink_lkup_args args = {
28445 + .errp = &h_dentry,
28446 + .tgtname = &tgtname,
28447 + .h_ppath = &h_ppath
28450 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28451 + if (unlikely(wkq_err))
28452 + h_dentry = ERR_PTR(wkq_err);
28454 + h_dentry = au_do_plink_lkup(&tgtname, &h_ppath);
28459 +/* create a pseudo-link */
28460 +static int do_whplink(struct qstr *tgt, struct path *h_ppath,
28461 + struct dentry *h_dentry)
28464 + struct path h_path;
28465 + struct inode *h_dir, *delegated;
28467 + h_dir = d_inode(h_ppath->dentry);
28468 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28469 + h_path.mnt = h_ppath->mnt;
28471 + h_path.dentry = vfsub_lkup_one(tgt, h_ppath);
28472 + err = PTR_ERR(h_path.dentry);
28473 + if (IS_ERR(h_path.dentry))
28477 + /* wh.plink dir is not monitored */
28478 + /* todo: is it really safe? */
28479 + if (d_is_positive(h_path.dentry)
28480 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28481 + delegated = NULL;
28482 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28483 + if (unlikely(err == -EWOULDBLOCK)) {
28484 + pr_warn("cannot retry for NFSv4 delegation"
28485 + " for an internal unlink\n");
28488 + dput(h_path.dentry);
28489 + h_path.dentry = NULL;
28493 + if (!err && d_is_negative(h_path.dentry)) {
28494 + delegated = NULL;
28495 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28496 + if (unlikely(err == -EWOULDBLOCK)) {
28497 + pr_warn("cannot retry for NFSv4 delegation"
28498 + " for an internal link\n");
28502 + dput(h_path.dentry);
28505 + inode_unlock(h_dir);
28509 +struct do_whplink_args {
28511 + struct qstr *tgt;
28512 + struct path *h_ppath;
28513 + struct dentry *h_dentry;
28516 +static void call_do_whplink(void *args)
28518 + struct do_whplink_args *a = args;
28519 + *a->errp = do_whplink(a->tgt, a->h_ppath, a->h_dentry);
28522 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28523 + aufs_bindex_t bindex)
28525 + int err, wkq_err;
28526 + struct au_branch *br;
28527 + struct au_wbr *wbr;
28528 + struct path h_ppath;
28529 + char a[PLINK_NAME_LEN];
28530 + struct qstr tgtname = QSTR_INIT(a, 0);
28532 + br = au_sbr(inode->i_sb, bindex);
28533 + wbr = br->br_wbr;
28534 + h_ppath.dentry = wbr->wbr_plink;
28535 + h_ppath.mnt = au_br_mnt(br);
28536 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28538 + /* always superio. */
28539 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28540 + struct do_whplink_args args = {
28543 + .h_ppath = &h_ppath,
28544 + .h_dentry = h_dentry
28546 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28547 + if (unlikely(wkq_err))
28550 + err = do_whplink(&tgtname, &h_ppath, h_dentry);
28556 + * create a new pseudo-link for @h_dentry on @bindex.
28557 + * the linked inode is held in aufs @inode.
28559 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28560 + struct dentry *h_dentry)
28562 + struct super_block *sb;
28563 + struct au_sbinfo *sbinfo;
28564 + struct hlist_bl_head *hbl;
28565 + struct hlist_bl_node *pos;
28566 + struct au_icntnr *icntnr;
28567 + int found, err, cnt, i;
28569 + sb = inode->i_sb;
28570 + sbinfo = au_sbi(sb);
28571 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28572 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28574 + found = au_plink_test(inode);
28578 + i = au_plink_hash(inode->i_ino);
28579 + hbl = sbinfo->si_plink + i;
28582 + hlist_bl_lock(hbl);
28583 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28584 + if (&icntnr->vfs_inode == inode) {
28590 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28591 + hlist_bl_add_head(&icntnr->plink, hbl);
28593 + hlist_bl_unlock(hbl);
28595 + cnt = au_hbl_count(hbl);
28596 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28597 + if (cnt > AUFS_PLINK_WARN)
28598 + AuWarn1(msg ", %d\n", cnt);
28600 + err = whplink(h_dentry, inode, bindex);
28601 + if (unlikely(err)) {
28602 + pr_warn("err %d, damaged pseudo link.\n", err);
28603 + au_hbl_del(&icntnr->plink, hbl);
28604 + iput(&icntnr->vfs_inode);
28607 + iput(&icntnr->vfs_inode);
28610 +/* free all plinks */
28611 +void au_plink_put(struct super_block *sb, int verbose)
28614 + struct au_sbinfo *sbinfo;
28615 + struct hlist_bl_head *hbl;
28616 + struct hlist_bl_node *pos, *tmp;
28617 + struct au_icntnr *icntnr;
28619 + SiMustWriteLock(sb);
28621 + sbinfo = au_sbi(sb);
28622 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28623 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28625 + /* no spin_lock since sbinfo is write-locked */
28627 + for (i = 0; i < AuPlink_NHASH; i++) {
28628 + hbl = sbinfo->si_plink + i;
28629 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28630 + pr_warn("pseudo-link is not flushed");
28633 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28634 + iput(&icntnr->vfs_inode);
28635 + INIT_HLIST_BL_HEAD(hbl);
28639 +void au_plink_clean(struct super_block *sb, int verbose)
28641 + struct dentry *root;
28643 + root = sb->s_root;
28644 + aufs_write_lock(root);
28645 + if (au_opt_test(au_mntflags(sb), PLINK))
28646 + au_plink_put(sb, verbose);
28647 + aufs_write_unlock(root);
28650 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28653 + aufs_bindex_t btop, bbot, bindex;
28656 + btop = au_ibtop(inode);
28657 + bbot = au_ibbot(inode);
28659 + for (bindex = btop; bindex <= bbot; bindex++) {
28660 + if (!au_h_iptr(inode, bindex)
28661 + || au_ii_br_id(inode, bindex) != br_id)
28663 + au_set_h_iptr(inode, bindex, NULL, 0);
28668 + for (bindex = btop; bindex <= bbot; bindex++)
28669 + if (au_h_iptr(inode, bindex)) {
28679 +/* free the plinks on a branch specified by @br_id */
28680 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28682 + struct au_sbinfo *sbinfo;
28683 + struct hlist_bl_head *hbl;
28684 + struct hlist_bl_node *pos, *tmp;
28685 + struct au_icntnr *icntnr;
28686 + struct inode *inode;
28689 + SiMustWriteLock(sb);
28691 + sbinfo = au_sbi(sb);
28692 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28693 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28695 + /* no bit_lock since sbinfo is write-locked */
28696 + for (i = 0; i < AuPlink_NHASH; i++) {
28697 + hbl = sbinfo->si_plink + i;
28698 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28699 + inode = au_igrab(&icntnr->vfs_inode);
28700 + ii_write_lock_child(inode);
28701 + do_put = au_plink_do_half_refresh(inode, br_id);
28703 + hlist_bl_del(&icntnr->plink);
28706 + ii_write_unlock(inode);
28711 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28712 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28713 +++ linux/fs/aufs/poll.c 2022-11-05 23:02:18.969222617 +0100
28715 +// SPDX-License-Identifier: GPL-2.0
28717 + * Copyright (C) 2005-2022 Junjiro R. Okajima
28719 + * This program is free software; you can redistribute it and/or modify
28720 + * it under the terms of the GNU General Public License as published by
28721 + * the Free Software Foundation; either version 2 of the License, or
28722 + * (at your option) any later version.
28724 + * This program is distributed in the hope that it will be useful,
28725 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28726 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28727 + * GNU General Public License for more details.
28729 + * You should have received a copy of the GNU General Public License
28730 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28735 + * There is only one filesystem which implements ->poll operation, currently.
28740 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28743 + struct file *h_file;
28744 + struct super_block *sb;
28746 + /* We should pretend an error happened. */
28747 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28748 + sb = file->f_path.dentry->d_sb;
28749 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28751 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28752 + if (IS_ERR(h_file)) {
28753 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28757 + mask = vfs_poll(h_file, pt);
28758 + fput(h_file); /* instead of au_read_post() */
28761 + si_read_unlock(sb);
28762 + if (mask & EPOLLERR)
28763 + AuDbg("mask 0x%x\n", mask);
28766 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28767 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28768 +++ linux/fs/aufs/posix_acl.c 2022-11-05 23:02:18.969222617 +0100
28770 +// SPDX-License-Identifier: GPL-2.0
28772 + * Copyright (C) 2014-2022 Junjiro R. Okajima
28774 + * This program is free software; you can redistribute it and/or modify
28775 + * it under the terms of the GNU General Public License as published by
28776 + * the Free Software Foundation; either version 2 of the License, or
28777 + * (at your option) any later version.
28779 + * This program is distributed in the hope that it will be useful,
28780 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28781 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28782 + * GNU General Public License for more details.
28784 + * You should have received a copy of the GNU General Public License
28785 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28789 + * posix acl operations
28792 +#include <linux/fs.h>
28795 +struct posix_acl *aufs_get_acl(struct inode *inode, int type, bool rcu)
28797 + struct posix_acl *acl;
28799 + aufs_bindex_t bindex;
28800 + struct inode *h_inode;
28801 + struct super_block *sb;
28803 + acl = ERR_PTR(-ECHILD);
28808 + sb = inode->i_sb;
28809 + si_read_lock(sb, AuLock_FLUSH);
28810 + ii_read_lock_child(inode);
28811 + if (!(sb->s_flags & SB_POSIXACL))
28814 + bindex = au_ibtop(inode);
28815 + h_inode = au_h_iptr(inode, bindex);
28816 + if (unlikely(!h_inode
28817 + || ((h_inode->i_mode & S_IFMT)
28818 + != (inode->i_mode & S_IFMT)))) {
28819 + err = au_busy_or_stale();
28820 + acl = ERR_PTR(err);
28824 + /* always topmost only */
28825 + acl = get_acl(h_inode, type);
28827 + forget_cached_acl(inode, type);
28829 + set_cached_acl(inode, type, acl);
28832 + ii_read_unlock(inode);
28833 + si_read_unlock(sb);
28836 + AuTraceErrPtr(acl);
28840 +int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
28841 + struct posix_acl *acl, int type)
28845 + struct dentry *dentry;
28846 + struct au_sxattr arg = {
28847 + .type = AU_ACL_SET,
28854 + IMustLock(inode);
28856 + if (inode->i_ino == AUFS_ROOT_INO)
28857 + dentry = dget(inode->i_sb->s_root);
28859 + dentry = d_find_alias(inode);
28861 + dentry = d_find_any_alias(inode);
28863 + pr_warn("cannot handle this inode, "
28864 + "please report to aufs-users ML\n");
28870 + ssz = au_sxattr(dentry, inode, &arg);
28871 + /* forget even it if succeeds since the branch might set differently */
28872 + forget_cached_acl(inode, type);
28881 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28882 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28883 +++ linux/fs/aufs/procfs.c 2022-11-05 23:02:18.969222617 +0100
28885 +// SPDX-License-Identifier: GPL-2.0
28887 + * Copyright (C) 2010-2022 Junjiro R. Okajima
28889 + * This program is free software; you can redistribute it and/or modify
28890 + * it under the terms of the GNU General Public License as published by
28891 + * the Free Software Foundation; either version 2 of the License, or
28892 + * (at your option) any later version.
28894 + * This program is distributed in the hope that it will be useful,
28895 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28896 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28897 + * GNU General Public License for more details.
28899 + * You should have received a copy of the GNU General Public License
28900 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28904 + * procfs interfaces
28907 +#include <linux/proc_fs.h>
28910 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28912 + struct au_sbinfo *sbinfo;
28914 + sbinfo = file->private_data;
28916 + au_plink_maint_leave(sbinfo);
28917 + kobject_put(&sbinfo->si_kobj);
28923 +static void au_procfs_plm_write_clean(struct file *file)
28925 + struct au_sbinfo *sbinfo;
28927 + sbinfo = file->private_data;
28929 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28932 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28935 + struct super_block *sb;
28936 + struct au_sbinfo *sbinfo;
28937 + struct hlist_bl_node *pos;
28940 + if (unlikely(file->private_data))
28944 + /* don't use au_sbilist_lock() here */
28945 + hlist_bl_lock(&au_sbilist);
28946 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28947 + if (id == sysaufs_si_id(sbinfo)) {
28948 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28949 + sb = sbinfo->si_sb;
28952 + hlist_bl_unlock(&au_sbilist);
28955 + if (unlikely(!sb))
28958 + err = au_plink_maint_enter(sb);
28960 + /* keep kobject_get() */
28961 + file->private_data = sbinfo;
28963 + kobject_put(&sbinfo->si_kobj);
28969 + * Accept a valid "si=xxxx" only.
28970 + * Once it is accepted successfully, accept "clean" too.
28972 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28973 + size_t count, loff_t *ppos)
28976 + unsigned long id;
28977 + /* last newline is allowed */
28978 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28981 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28985 + if (unlikely(count > sizeof(buf)))
28988 + err = copy_from_user(buf, ubuf, count);
28989 + if (unlikely(err)) {
28996 + if (!strcmp("clean", buf)) {
28997 + au_procfs_plm_write_clean(file);
28998 + goto out_success;
28999 + } else if (unlikely(strncmp("si=", buf, 3)))
29002 + err = kstrtoul(buf + 3, 16, &id);
29003 + if (unlikely(err))
29006 + err = au_procfs_plm_write_si(file, id);
29007 + if (unlikely(err))
29011 + err = count; /* success */
29016 +static const struct proc_ops au_procfs_plm_op = {
29017 + .proc_write = au_procfs_plm_write,
29018 + .proc_release = au_procfs_plm_release
29021 +/* ---------------------------------------------------------------------- */
29023 +static struct proc_dir_entry *au_procfs_dir;
29025 +void au_procfs_fin(void)
29027 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
29028 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
29031 +int __init au_procfs_init(void)
29034 + struct proc_dir_entry *entry;
29037 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
29038 + if (unlikely(!au_procfs_dir))
29041 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
29042 + au_procfs_dir, &au_procfs_plm_op);
29043 + if (unlikely(!entry))
29047 + goto out; /* success */
29051 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
29055 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
29056 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
29057 +++ linux/fs/aufs/rdu.c 2022-12-17 09:21:34.799855195 +0100
29059 +// SPDX-License-Identifier: GPL-2.0
29061 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29063 + * This program is free software; you can redistribute it and/or modify
29064 + * it under the terms of the GNU General Public License as published by
29065 + * the Free Software Foundation; either version 2 of the License, or
29066 + * (at your option) any later version.
29068 + * This program is distributed in the hope that it will be useful,
29069 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29070 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29071 + * GNU General Public License for more details.
29073 + * You should have received a copy of the GNU General Public License
29074 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29078 + * readdir in userspace.
29081 +#include <linux/compat.h>
29082 +#include <linux/fs_stack.h>
29083 +#include <linux/security.h>
29086 +/* bits for struct aufs_rdu.flags */
29087 +#define AuRdu_CALLED 1
29088 +#define AuRdu_CONT (1 << 1)
29089 +#define AuRdu_FULL (1 << 2)
29090 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
29091 +#define au_fset_rdu(flags, name) \
29092 + do { (flags) |= AuRdu_##name; } while (0)
29093 +#define au_fclr_rdu(flags, name) \
29094 + do { (flags) &= ~AuRdu_##name; } while (0)
29096 +struct au_rdu_arg {
29097 + struct dir_context ctx;
29098 + struct aufs_rdu *rdu;
29099 + union au_rdu_ent_ul ent;
29100 + unsigned long end;
29102 + struct super_block *sb;
29106 +static bool au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
29107 + loff_t offset, u64 h_ino, unsigned int d_type)
29110 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
29111 + struct aufs_rdu *rdu = arg->rdu;
29112 + struct au_rdu_ent ent;
29116 + au_fset_rdu(rdu->cookie.flags, CALLED);
29117 + len = au_rdu_len(nlen);
29118 + if (arg->ent.ul + len < arg->end) {
29120 + ent.bindex = rdu->cookie.bindex;
29121 + ent.type = d_type;
29123 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
29124 + ent.type = DT_UNKNOWN;
29126 + /* unnecessary to support mmap_sem since this is a dir */
29128 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
29130 + if (copy_to_user(arg->ent.e->name, name, nlen))
29132 + /* the terminating NULL */
29133 + if (__put_user(0, arg->ent.e->name + nlen))
29136 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
29137 + arg->ent.ul += len;
29141 + au_fset_rdu(rdu->cookie.flags, FULL);
29143 + rdu->tail = arg->ent;
29147 + /* AuTraceErr(err); */
29151 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
29155 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
29157 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
29158 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
29160 + if (unlikely(offset != cookie->h_pos))
29166 + au_fclr_rdu(cookie->flags, CALLED);
29168 + err = vfsub_iterate_dir(h_file, &arg->ctx);
29172 + && au_ftest_rdu(cookie->flags, CALLED)
29173 + && !au_ftest_rdu(cookie->flags, FULL));
29174 + cookie->h_pos = h_file->f_pos;
29181 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
29184 + aufs_bindex_t bbot;
29185 + struct au_rdu_arg arg = {
29187 + .actor = au_rdu_fill
29190 + struct dentry *dentry;
29191 + struct inode *inode;
29192 + struct file *h_file;
29193 + struct au_rdu_cookie *cookie = &rdu->cookie;
29195 + /* VERIFY_WRITE */
29196 + err = !access_ok(rdu->ent.e, rdu->sz);
29197 + if (unlikely(err)) {
29203 + rdu->tail = rdu->ent;
29206 + arg.ent = rdu->ent;
29207 + arg.end = arg.ent.ul;
29208 + arg.end += rdu->sz;
29211 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
29214 + err = security_file_permission(file, MAY_READ);
29216 + if (unlikely(err))
29219 + dentry = file->f_path.dentry;
29220 + inode = d_inode(dentry);
29221 + inode_lock_shared(inode);
29223 + arg.sb = inode->i_sb;
29224 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
29225 + if (unlikely(err))
29227 + err = au_alive_dir(dentry);
29228 + if (unlikely(err))
29230 + /* todo: reval? */
29231 + fi_read_lock(file);
29234 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
29235 + && cookie->generation != au_figen(file)))
29240 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
29242 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
29244 + bbot = au_fbtop(file);
29245 + if (cookie->bindex < bbot)
29246 + cookie->bindex = bbot;
29247 + bbot = au_fbbot_dir(file);
29248 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
29249 + for (; !err && cookie->bindex <= bbot;
29250 + cookie->bindex++, cookie->h_pos = 0) {
29251 + h_file = au_hf_dir(file, cookie->bindex);
29255 + au_fclr_rdu(cookie->flags, FULL);
29256 + err = au_rdu_do(h_file, &arg);
29258 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
29261 + AuDbg("rent %llu\n", rdu->rent);
29263 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
29264 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
29265 + au_fset_rdu(cookie->flags, CONT);
29266 + cookie->generation = au_figen(file);
29269 + ii_read_lock_child(inode);
29270 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
29271 + ii_read_unlock(inode);
29274 + fi_read_unlock(file);
29276 + si_read_unlock(arg.sb);
29278 + inode_unlock_shared(inode);
29284 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
29288 + unsigned long long nent;
29289 + union au_rdu_ent_ul *u;
29290 + struct au_rdu_ent ent;
29291 + struct super_block *sb;
29294 + nent = rdu->nent;
29296 + sb = file->f_path.dentry->d_sb;
29297 + si_read_lock(sb, AuLock_FLUSH);
29298 + while (nent-- > 0) {
29299 + /* unnecessary to support mmap_sem since this is a dir */
29300 + err = copy_from_user(&ent, u->e, sizeof(ent));
29302 + /* VERIFY_WRITE */
29303 + err = !access_ok(&u->e->ino, sizeof(ino));
29304 + if (unlikely(err)) {
29310 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
29312 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
29314 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
29316 + if (unlikely(err)) {
29321 + err = __put_user(ino, &u->e->ino);
29322 + if (unlikely(err)) {
29327 + u->ul += au_rdu_len(ent.nlen);
29329 + si_read_unlock(sb);
29334 +/* ---------------------------------------------------------------------- */
29336 +static int au_rdu_verify(struct aufs_rdu *rdu)
29338 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
29339 + "%llu, b%d, 0x%x, g%u}\n",
29340 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
29342 + rdu->rent, rdu->shwh, rdu->full,
29343 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
29344 + rdu->cookie.generation);
29346 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
29350 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
29354 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29357 + struct aufs_rdu rdu;
29358 + void __user *p = (void __user *)arg;
29360 + err = copy_from_user(&rdu, p, sizeof(rdu));
29361 + if (unlikely(err)) {
29366 + err = au_rdu_verify(&rdu);
29367 + if (unlikely(err))
29371 + case AUFS_CTL_RDU:
29372 + err = au_rdu(file, &rdu);
29373 + if (unlikely(err))
29376 + e = copy_to_user(p, &rdu, sizeof(rdu));
29377 + if (unlikely(e)) {
29382 + case AUFS_CTL_RDU_INO:
29383 + err = au_rdu_ino(file, &rdu);
29387 + /* err = -ENOTTY; */
29396 +#ifdef CONFIG_COMPAT
29397 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29400 + struct aufs_rdu rdu;
29401 + void __user *p = compat_ptr(arg);
29403 + /* todo: get_user()? */
29404 + err = copy_from_user(&rdu, p, sizeof(rdu));
29405 + if (unlikely(err)) {
29410 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29411 + err = au_rdu_verify(&rdu);
29412 + if (unlikely(err))
29416 + case AUFS_CTL_RDU:
29417 + err = au_rdu(file, &rdu);
29418 + if (unlikely(err))
29421 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29422 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29423 + e = copy_to_user(p, &rdu, sizeof(rdu));
29424 + if (unlikely(e)) {
29429 + case AUFS_CTL_RDU_INO:
29430 + err = au_rdu_ino(file, &rdu);
29434 + /* err = -ENOTTY; */
29443 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29444 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29445 +++ linux/fs/aufs/rwsem.h 2022-11-05 23:02:18.969222617 +0100
29447 +/* SPDX-License-Identifier: GPL-2.0 */
29449 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29451 + * This program is free software; you can redistribute it and/or modify
29452 + * it under the terms of the GNU General Public License as published by
29453 + * the Free Software Foundation; either version 2 of the License, or
29454 + * (at your option) any later version.
29456 + * This program is distributed in the hope that it will be useful,
29457 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29458 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29459 + * GNU General Public License for more details.
29461 + * You should have received a copy of the GNU General Public License
29462 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29466 + * simple read-write semaphore wrappers
29469 +#ifndef __AUFS_RWSEM_H__
29470 +#define __AUFS_RWSEM_H__
29474 +#include "debug.h"
29476 +/* in the future, the name 'au_rwsem' will be totally gone */
29477 +#define au_rwsem rw_semaphore
29479 +/* to debug easier, do not make them inlined functions */
29480 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29482 +#ifdef CONFIG_LOCKDEP
29483 +/* rwsem_is_locked() is unusable */
29484 +#define AuRwMustReadLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29485 + && !lockdep_recursing(current) \
29487 + && !lockdep_is_held_type(rw, 1))
29488 +#define AuRwMustWriteLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29489 + && !lockdep_recursing(current) \
29491 + && !lockdep_is_held_type(rw, 0))
29492 +#define AuRwMustAnyLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29493 + && !lockdep_recursing(current) \
29495 + && !lockdep_is_held(rw))
29496 +#define AuRwDestroy(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29497 + && !lockdep_recursing(current) \
29499 + && lockdep_is_held(rw))
29501 +#define AuRwMustReadLock(rw) do {} while (0)
29502 +#define AuRwMustWriteLock(rw) do {} while (0)
29503 +#define AuRwMustAnyLock(rw) do {} while (0)
29504 +#define AuRwDestroy(rw) do {} while (0)
29507 +#define au_rw_init(rw) init_rwsem(rw)
29509 +#define au_rw_init_wlock(rw) do { \
29510 + au_rw_init(rw); \
29511 + down_write(rw); \
29514 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29515 + au_rw_init(rw); \
29516 + down_write_nested(rw, lsc); \
29519 +#define au_rw_read_lock(rw) down_read(rw)
29520 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29521 +#define au_rw_read_unlock(rw) up_read(rw)
29522 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29523 +#define au_rw_write_lock(rw) down_write(rw)
29524 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29525 +#define au_rw_write_unlock(rw) up_write(rw)
29526 +/* why is not _nested version defined? */
29527 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29528 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29530 +#endif /* __KERNEL__ */
29531 +#endif /* __AUFS_RWSEM_H__ */
29532 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29533 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29534 +++ linux/fs/aufs/sbinfo.c 2022-11-05 23:02:18.969222617 +0100
29536 +// SPDX-License-Identifier: GPL-2.0
29538 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29540 + * This program is free software; you can redistribute it and/or modify
29541 + * it under the terms of the GNU General Public License as published by
29542 + * the Free Software Foundation; either version 2 of the License, or
29543 + * (at your option) any later version.
29545 + * This program is distributed in the hope that it will be useful,
29546 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29547 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29548 + * GNU General Public License for more details.
29550 + * You should have received a copy of the GNU General Public License
29551 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29555 + * superblock private data
29558 +#include <linux/iversion.h>
29562 + * they are necessary regardless sysfs is disabled.
29564 +void au_si_free(struct kobject *kobj)
29567 + struct au_sbinfo *sbinfo;
29568 + char *locked __maybe_unused; /* debug only */
29570 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29571 + for (i = 0; i < AuPlink_NHASH; i++)
29572 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29573 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29575 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29576 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29577 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29578 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29580 + dbgaufs_si_fin(sbinfo);
29581 + au_rw_write_lock(&sbinfo->si_rwsem);
29582 + au_br_free(sbinfo);
29583 + au_rw_write_unlock(&sbinfo->si_rwsem);
29585 + au_kfree_try_rcu(sbinfo->si_branch);
29586 + mutex_destroy(&sbinfo->si_xib_mtx);
29587 + AuRwDestroy(&sbinfo->si_rwsem);
29589 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29590 + /* si_nfiles is waited too */
29591 + au_kfree_rcu(sbinfo);
29594 +struct au_sbinfo *au_si_alloc(struct super_block *sb)
29596 + struct au_sbinfo *sbinfo;
29600 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29601 + if (unlikely(!sbinfo))
29604 + /* will be reallocated separately */
29605 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29606 + if (unlikely(!sbinfo->si_branch))
29609 + err = sysaufs_si_init(sbinfo);
29611 + dbgaufs_si_null(sbinfo);
29612 + err = dbgaufs_si_init(sbinfo);
29613 + if (unlikely(err))
29614 + kobject_put(&sbinfo->si_kobj);
29616 + if (unlikely(err))
29619 + au_nwt_init(&sbinfo->si_nowait);
29620 + au_rw_init_wlock(&sbinfo->si_rwsem);
29622 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29623 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29625 + sbinfo->si_bbot = -1;
29626 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29628 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29629 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29630 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29631 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29633 + au_fhsm_init(sbinfo);
29635 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29637 + sbinfo->si_xino_jiffy = jiffies;
29638 + sbinfo->si_xino_expire
29639 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29640 + mutex_init(&sbinfo->si_xib_mtx);
29641 + /* leave si_xib_last_pindex and si_xib_next_bit */
29643 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29645 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29646 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29647 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29648 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29650 + for (i = 0; i < AuPlink_NHASH; i++)
29651 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29652 + init_waitqueue_head(&sbinfo->si_plink_wq);
29653 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29655 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29657 + /* with getattr by default */
29658 + sbinfo->si_iop_array = aufs_iop;
29660 + /* leave other members for sysaufs and si_mnt. */
29661 + sbinfo->si_sb = sb;
29663 + sb->s_fs_info = sbinfo;
29666 + return sbinfo; /* success */
29669 + au_kfree_try_rcu(sbinfo->si_branch);
29671 + au_kfree_rcu(sbinfo);
29673 + return ERR_PTR(err);
29676 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29679 + struct au_branch **brp;
29681 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29684 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29685 + if (unlikely(!sz))
29686 + sz = sizeof(*brp);
29687 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29690 + sbinfo->si_branch = brp;
29697 +/* ---------------------------------------------------------------------- */
29699 +unsigned int au_sigen_inc(struct super_block *sb)
29701 + unsigned int gen;
29702 + struct inode *inode;
29704 + SiMustWriteLock(sb);
29706 + gen = ++au_sbi(sb)->si_generation;
29707 + au_update_digen(sb->s_root);
29708 + inode = d_inode(sb->s_root);
29709 + au_update_iigen(inode, /*half*/0);
29710 + inode_inc_iversion(inode);
29714 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29716 + aufs_bindex_t br_id;
29718 + struct au_sbinfo *sbinfo;
29720 + SiMustWriteLock(sb);
29722 + sbinfo = au_sbi(sb);
29723 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29724 + br_id = ++sbinfo->si_last_br_id;
29725 + AuDebugOn(br_id < 0);
29726 + if (br_id && au_br_index(sb, br_id) < 0)
29733 +/* ---------------------------------------------------------------------- */
29735 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29736 +int si_read_lock(struct super_block *sb, int flags)
29741 + if (au_ftest_lock(flags, FLUSH))
29742 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29744 + si_noflush_read_lock(sb);
29745 + err = au_plink_maint(sb, flags);
29746 + if (unlikely(err))
29747 + si_read_unlock(sb);
29752 +int si_write_lock(struct super_block *sb, int flags)
29756 + if (au_ftest_lock(flags, FLUSH))
29757 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29759 + si_noflush_write_lock(sb);
29760 + err = au_plink_maint(sb, flags);
29761 + if (unlikely(err))
29762 + si_write_unlock(sb);
29767 +/* dentry and super_block lock. call at entry point */
29768 +int aufs_read_lock(struct dentry *dentry, int flags)
29771 + struct super_block *sb;
29773 + sb = dentry->d_sb;
29774 + err = si_read_lock(sb, flags);
29775 + if (unlikely(err))
29778 + if (au_ftest_lock(flags, DW))
29779 + di_write_lock_child(dentry);
29781 + di_read_lock_child(dentry, flags);
29783 + if (au_ftest_lock(flags, GEN)) {
29784 + err = au_digen_test(dentry, au_sigen(sb));
29785 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29786 + AuDebugOn(!err && au_dbrange_test(dentry));
29788 + err = au_dbrange_test(dentry);
29789 + if (unlikely(err))
29790 + aufs_read_unlock(dentry, flags);
29797 +void aufs_read_unlock(struct dentry *dentry, int flags)
29799 + if (au_ftest_lock(flags, DW))
29800 + di_write_unlock(dentry);
29802 + di_read_unlock(dentry, flags);
29803 + si_read_unlock(dentry->d_sb);
29806 +void aufs_write_lock(struct dentry *dentry)
29808 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29809 + di_write_lock_child(dentry);
29812 +void aufs_write_unlock(struct dentry *dentry)
29814 + di_write_unlock(dentry);
29815 + si_write_unlock(dentry->d_sb);
29818 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29821 + unsigned int sigen;
29822 + struct super_block *sb;
29825 + err = si_read_lock(sb, flags);
29826 + if (unlikely(err))
29829 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29831 + if (au_ftest_lock(flags, GEN)) {
29832 + sigen = au_sigen(sb);
29833 + err = au_digen_test(d1, sigen);
29834 + AuDebugOn(!err && au_dbrange_test(d1));
29836 + err = au_digen_test(d2, sigen);
29837 + AuDebugOn(!err && au_dbrange_test(d2));
29839 + if (unlikely(err))
29840 + aufs_read_and_write_unlock2(d1, d2);
29847 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29849 + di_write_unlock2(d1, d2);
29850 + si_read_unlock(d1->d_sb);
29852 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29853 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29854 +++ linux/fs/aufs/super.c 2022-11-05 23:02:18.969222617 +0100
29856 +// SPDX-License-Identifier: GPL-2.0
29858 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29860 + * This program is free software; you can redistribute it and/or modify
29861 + * it under the terms of the GNU General Public License as published by
29862 + * the Free Software Foundation; either version 2 of the License, or
29863 + * (at your option) any later version.
29865 + * This program is distributed in the hope that it will be useful,
29866 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29867 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29868 + * GNU General Public License for more details.
29870 + * You should have received a copy of the GNU General Public License
29871 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29875 + * mount and super_block operations
29878 +#include <linux/iversion.h>
29879 +#include <linux/mm.h>
29880 +#include <linux/seq_file.h>
29881 +#include <linux/statfs.h>
29882 +#include <linux/vmalloc.h>
29886 + * super_operations
29888 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29890 + struct au_icntnr *c;
29892 + c = au_cache_alloc_icntnr(sb);
29894 + au_icntnr_init(c);
29895 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29896 + c->iinfo.ii_hinode = NULL;
29897 + return &c->vfs_inode;
29902 +static void aufs_destroy_inode(struct inode *inode)
29904 + if (!au_is_bad_inode(inode))
29905 + au_iinfo_fin(inode);
29908 +static void aufs_free_inode(struct inode *inode)
29910 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29913 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29915 + struct inode *inode;
29918 + inode = iget_locked(sb, ino);
29919 + if (unlikely(!inode)) {
29920 + inode = ERR_PTR(-ENOMEM);
29923 + if (!(inode->i_state & I_NEW))
29926 + err = au_xigen_new(inode);
29928 + err = au_iinfo_init(inode);
29930 + inode_inc_iversion(inode);
29932 + iget_failed(inode);
29933 + inode = ERR_PTR(err);
29937 + /* never return NULL */
29938 + AuDebugOn(!inode);
29939 + AuTraceErrPtr(inode);
29943 +/* lock free root dinfo */
29944 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29947 + aufs_bindex_t bindex, bbot;
29948 + struct path path;
29949 + struct au_hdentry *hdp;
29950 + struct au_branch *br;
29951 + au_br_perm_str_t perm;
29954 + bbot = au_sbbot(sb);
29956 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29957 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29958 + br = au_sbr(sb, bindex);
29959 + path.mnt = au_br_mnt(br);
29960 + path.dentry = hdp->hd_dentry;
29961 + err = au_seq_path(seq, &path);
29963 + au_optstr_br_perm(&perm, br->br_perm);
29964 + seq_printf(seq, "=%s", perm.a);
29965 + if (bindex != bbot)
29966 + seq_putc(seq, ':');
29969 + if (unlikely(err || seq_has_overflowed(seq)))
29975 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29976 + const char *append)
29981 + while (*pat != ':')
29984 + strcpy(p, append);
29985 + AuDebugOn(strlen(fmt) >= len);
29988 +static void au_show_wbr_create(struct seq_file *m, int v,
29989 + struct au_sbinfo *sbinfo)
29993 + struct au_wbr_mfs *mfs;
29995 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29997 + seq_puts(m, ",create=");
29998 + pat = au_optstr_wbr_create(v);
29999 + mfs = &sbinfo->si_wbr_mfs;
30001 + case AuWbrCreate_TDP:
30002 + case AuWbrCreate_RR:
30003 + case AuWbrCreate_MFS:
30004 + case AuWbrCreate_PMFS:
30005 + seq_puts(m, pat);
30007 + case AuWbrCreate_MFSRR:
30008 + case AuWbrCreate_TDMFS:
30009 + case AuWbrCreate_PMFSRR:
30010 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
30011 + seq_printf(m, fmt, mfs->mfsrr_watermark);
30013 + case AuWbrCreate_MFSV:
30014 + case AuWbrCreate_PMFSV:
30015 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
30016 + seq_printf(m, fmt,
30017 + jiffies_to_msecs(mfs->mfs_expire)
30020 + case AuWbrCreate_MFSRRV:
30021 + case AuWbrCreate_TDMFSV:
30022 + case AuWbrCreate_PMFSRRV:
30023 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
30024 + seq_printf(m, fmt, mfs->mfsrr_watermark,
30025 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
30032 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
30034 +#ifdef CONFIG_SYSFS
30038 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
30039 + aufs_bindex_t bindex, brid;
30040 + struct qstr *name;
30042 + struct dentry *d, *h_root;
30043 + struct au_branch *br;
30045 + AuRwMustAnyLock(&sbinfo->si_rwsem);
30048 + f = au_sbi(sb)->si_xib;
30052 + /* stop printing the default xino path on the first writable branch */
30054 + bindex = au_xi_root(sb, f->f_path.dentry);
30055 + if (bindex >= 0) {
30056 + br = au_sbr_sb(sb, bindex);
30057 + h_root = au_br_dentry(br);
30060 + d = f->f_path.dentry;
30061 + name = &d->d_name;
30062 + /* safe ->d_parent because the file is unlinked */
30063 + if (d->d_parent == h_root
30064 + && name->len == len
30065 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
30068 + seq_puts(seq, ",xino=");
30069 + err = au_xino_path(seq, f);
30076 +/* seq_file will re-call me in case of too long string */
30077 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
30080 + unsigned int mnt_flags, v;
30081 + struct super_block *sb;
30082 + struct au_sbinfo *sbinfo;
30084 +#define AuBool(name, str) do { \
30085 + v = au_opt_test(mnt_flags, name); \
30086 + if (v != au_opt_test(AuOpt_Def, name)) \
30087 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
30090 +#define AuStr(name, str) do { \
30091 + v = mnt_flags & AuOptMask_##name; \
30092 + if (v != (AuOpt_Def & AuOptMask_##name)) \
30093 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
30096 +#define AuUInt(name, str, val) do { \
30097 + if (val != AUFS_##name##_DEF) \
30098 + seq_printf(m, "," #str "=%u", val); \
30101 + sb = dentry->d_sb;
30102 + if (sb->s_flags & SB_POSIXACL)
30103 + seq_puts(m, ",acl");
30104 +#if 0 /* reserved for future use */
30105 + if (sb->s_flags & SB_I_VERSION)
30106 + seq_puts(m, ",i_version");
30109 + /* lock free root dinfo */
30110 + si_noflush_read_lock(sb);
30111 + sbinfo = au_sbi(sb);
30112 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
30114 + mnt_flags = au_mntflags(sb);
30115 + if (au_opt_test(mnt_flags, XINO)) {
30116 + err = au_show_xino(m, sb);
30117 + if (unlikely(err))
30120 + seq_puts(m, ",noxino");
30122 + AuBool(TRUNC_XINO, trunc_xino);
30123 + AuStr(UDBA, udba);
30124 + AuBool(SHWH, shwh);
30125 + AuBool(PLINK, plink);
30126 + AuBool(DIO, dio);
30127 + AuBool(DIRPERM1, dirperm1);
30129 + v = sbinfo->si_wbr_create;
30130 + if (v != AuWbrCreate_Def)
30131 + au_show_wbr_create(m, v, sbinfo);
30133 + v = sbinfo->si_wbr_copyup;
30134 + if (v != AuWbrCopyup_Def)
30135 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
30137 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
30138 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
30139 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
30141 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
30143 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
30144 + AuUInt(RDCACHE, rdcache, v);
30146 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
30147 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
30149 + au_fhsm_show(m, sbinfo);
30151 + AuBool(DIRREN, dirren);
30152 + AuBool(SUM, sum);
30153 + /* AuBool(SUM_W, wsum); */
30154 + AuBool(WARN_PERM, warn_perm);
30155 + AuBool(VERBOSE, verbose);
30158 + /* be sure to print "br:" last */
30159 + if (!sysaufs_brs) {
30160 + seq_puts(m, ",br:");
30161 + au_show_brs(m, sb);
30163 + si_read_unlock(sb);
30171 +/* ---------------------------------------------------------------------- */
30173 +/* sum mode which returns the summation for statfs(2) */
30175 +static u64 au_add_till_max(u64 a, u64 b)
30183 + return ULLONG_MAX;
30186 +static u64 au_mul_till_max(u64 a, long mul)
30194 + return ULLONG_MAX;
30197 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
30200 + long bsize, factor;
30201 + u64 blocks, bfree, bavail, files, ffree;
30202 + aufs_bindex_t bbot, bindex, i;
30203 + unsigned char shared;
30204 + struct path h_path;
30205 + struct super_block *h_sb;
30208 + bsize = LONG_MAX;
30214 + bbot = au_sbbot(sb);
30215 + for (bindex = 0; bindex <= bbot; bindex++) {
30216 + h_path.mnt = au_sbr_mnt(sb, bindex);
30217 + h_sb = h_path.mnt->mnt_sb;
30219 + for (i = 0; !shared && i < bindex; i++)
30220 + shared = (au_sbr_sb(sb, i) == h_sb);
30224 + /* sb->s_root for NFS is unreliable */
30225 + h_path.dentry = h_path.mnt->mnt_root;
30226 + err = vfs_statfs(&h_path, buf);
30227 + if (unlikely(err))
30230 + if (bsize > buf->f_bsize) {
30232 + * we will reduce bsize, so we have to expand blocks
30233 + * etc. to match them again
30235 + factor = (bsize / buf->f_bsize);
30236 + blocks = au_mul_till_max(blocks, factor);
30237 + bfree = au_mul_till_max(bfree, factor);
30238 + bavail = au_mul_till_max(bavail, factor);
30239 + bsize = buf->f_bsize;
30242 + factor = (buf->f_bsize / bsize);
30243 + blocks = au_add_till_max(blocks,
30244 + au_mul_till_max(buf->f_blocks, factor));
30245 + bfree = au_add_till_max(bfree,
30246 + au_mul_till_max(buf->f_bfree, factor));
30247 + bavail = au_add_till_max(bavail,
30248 + au_mul_till_max(buf->f_bavail, factor));
30249 + files = au_add_till_max(files, buf->f_files);
30250 + ffree = au_add_till_max(ffree, buf->f_ffree);
30253 + buf->f_bsize = bsize;
30254 + buf->f_blocks = blocks;
30255 + buf->f_bfree = bfree;
30256 + buf->f_bavail = bavail;
30257 + buf->f_files = files;
30258 + buf->f_ffree = ffree;
30259 + buf->f_frsize = 0;
30265 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
30268 + struct path h_path;
30269 + struct super_block *sb;
30271 + /* lock free root dinfo */
30272 + sb = dentry->d_sb;
30273 + si_noflush_read_lock(sb);
30274 + if (!au_opt_test(au_mntflags(sb), SUM)) {
30275 + /* sb->s_root for NFS is unreliable */
30276 + h_path.mnt = au_sbr_mnt(sb, 0);
30277 + h_path.dentry = h_path.mnt->mnt_root;
30278 + err = vfs_statfs(&h_path, buf);
30280 + err = au_statfs_sum(sb, buf);
30281 + si_read_unlock(sb);
30284 + buf->f_type = AUFS_SUPER_MAGIC;
30285 + buf->f_namelen = AUFS_MAX_NAMELEN;
30286 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
30288 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
30293 +/* ---------------------------------------------------------------------- */
30295 +static int aufs_sync_fs(struct super_block *sb, int wait)
30298 + aufs_bindex_t bbot, bindex;
30299 + struct au_branch *br;
30300 + struct super_block *h_sb;
30303 + si_noflush_read_lock(sb);
30304 + bbot = au_sbbot(sb);
30305 + for (bindex = 0; bindex <= bbot; bindex++) {
30306 + br = au_sbr(sb, bindex);
30307 + if (!au_br_writable(br->br_perm))
30310 + h_sb = au_sbr_sb(sb, bindex);
30311 + e = vfsub_sync_filesystem(h_sb);
30312 + if (unlikely(e && !err))
30314 + /* go on even if an error happens */
30316 + si_read_unlock(sb);
30321 +/* ---------------------------------------------------------------------- */
30323 +/* final actions when unmounting a file system */
30324 +static void aufs_put_super(struct super_block *sb)
30326 + struct au_sbinfo *sbinfo;
30328 + sbinfo = au_sbi(sb);
30330 + kobject_put(&sbinfo->si_kobj);
30333 +/* ---------------------------------------------------------------------- */
30335 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30336 + struct super_block *sb, void *arg)
30339 + unsigned long long n, sz;
30346 + if (*hint > ULLONG_MAX / sizeof(array)) {
30347 + array = ERR_PTR(-EMFILE);
30348 + pr_err("hint %llu\n", *hint);
30352 + sz = sizeof(array) * *hint;
30353 + array = kzalloc(sz, GFP_NOFS);
30354 + if (unlikely(!array))
30355 + array = vzalloc(sz);
30356 + if (unlikely(!array)) {
30357 + array = ERR_PTR(-ENOMEM);
30361 + n = cb(sb, array, *hint, arg);
30362 + AuDebugOn(n > *hint);
30369 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
30370 + unsigned long long max __maybe_unused,
30373 + unsigned long long n;
30374 + struct inode **p, *inode;
30375 + struct list_head *head;
30380 + spin_lock(&sb->s_inode_list_lock);
30381 + list_for_each_entry(inode, head, i_sb_list) {
30382 + if (!au_is_bad_inode(inode)
30383 + && au_ii(inode)->ii_btop >= 0) {
30384 + spin_lock(&inode->i_lock);
30385 + if (atomic_read(&inode->i_count)) {
30389 + AuDebugOn(n > max);
30391 + spin_unlock(&inode->i_lock);
30394 + spin_unlock(&sb->s_inode_list_lock);
30399 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
30401 + struct au_sbinfo *sbi;
30403 + sbi = au_sbi(sb);
30404 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
30405 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
30408 +void au_iarray_free(struct inode **a, unsigned long long max)
30410 + unsigned long long ull;
30412 + for (ull = 0; ull < max; ull++)
30417 +/* ---------------------------------------------------------------------- */
30420 + * refresh dentry and inode at remount time.
30422 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30423 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30424 + struct dentry *parent)
30428 + di_write_lock_child(dentry);
30429 + di_read_lock_parent(parent, AuLock_IR);
30430 + err = au_refresh_dentry(dentry, parent);
30431 + if (!err && dir_flags)
30432 + au_hn_reset(d_inode(dentry), dir_flags);
30433 + di_read_unlock(parent, AuLock_IR);
30434 + di_write_unlock(dentry);
30439 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30440 + struct au_sbinfo *sbinfo,
30441 + const unsigned int dir_flags, unsigned int do_idop)
30444 + struct dentry *parent;
30447 + parent = dget_parent(dentry);
30448 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30449 + if (d_really_is_positive(dentry)) {
30450 + if (!d_is_dir(dentry))
30451 + err = au_do_refresh(dentry, /*dir_flags*/0,
30454 + err = au_do_refresh(dentry, dir_flags, parent);
30455 + if (unlikely(err))
30456 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30459 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30460 + AuDbgDentry(dentry);
30466 + au_refresh_dop(dentry, /*force_reval*/0);
30468 + au_refresh_dop(dentry, /*force_reval*/1);
30474 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30476 + int err, i, j, ndentry, e;
30477 + unsigned int sigen;
30478 + struct au_dcsub_pages dpages;
30479 + struct au_dpage *dpage;
30480 + struct dentry **dentries, *d;
30481 + struct au_sbinfo *sbinfo;
30482 + struct dentry *root = sb->s_root;
30483 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30486 + au_refresh_dop(root, /*force_reval*/0);
30488 + err = au_dpages_init(&dpages, GFP_NOFS);
30489 + if (unlikely(err))
30491 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30492 + if (unlikely(err))
30495 + sigen = au_sigen(sb);
30496 + sbinfo = au_sbi(sb);
30497 + for (i = 0; i < dpages.ndpage; i++) {
30498 + dpage = dpages.dpages + i;
30499 + dentries = dpage->dentries;
30500 + ndentry = dpage->ndentry;
30501 + for (j = 0; j < ndentry; j++) {
30503 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30505 + if (unlikely(e && !err))
30507 + /* go on even err */
30512 + au_dpages_free(&dpages);
30517 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30520 + unsigned int sigen;
30521 + unsigned long long max, ull;
30522 + struct inode *inode, **array;
30524 + array = au_iarray_alloc(sb, &max);
30525 + err = PTR_ERR(array);
30526 + if (IS_ERR(array))
30530 + sigen = au_sigen(sb);
30531 + for (ull = 0; ull < max; ull++) {
30532 + inode = array[ull];
30533 + if (unlikely(!inode))
30537 + ii_write_lock_child(inode);
30538 + if (au_iigen(inode, NULL) != sigen) {
30539 + e = au_refresh_hinode_self(inode);
30540 + if (unlikely(e)) {
30541 + au_refresh_iop(inode, /*force_getattr*/1);
30542 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30545 + /* go on even if err */
30548 + if (!e && do_idop)
30549 + au_refresh_iop(inode, /*force_getattr*/0);
30550 + ii_write_unlock(inode);
30553 + au_iarray_free(array, max);
30559 +void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30562 + unsigned int udba;
30563 + aufs_bindex_t bindex, bbot;
30564 + struct dentry *root;
30565 + struct inode *inode;
30566 + struct au_branch *br;
30567 + struct au_sbinfo *sbi;
30569 + au_sigen_inc(sb);
30570 + sbi = au_sbi(sb);
30571 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30573 + root = sb->s_root;
30574 + DiMustNoWaiters(root);
30575 + inode = d_inode(root);
30576 + IiMustNoWaiters(inode);
30578 + udba = au_opt_udba(sb);
30579 + bbot = au_sbbot(sb);
30580 + for (bindex = 0; bindex <= bbot; bindex++) {
30581 + br = au_sbr(sb, bindex);
30582 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30583 + if (unlikely(err))
30584 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30586 + /* go on even if err */
30588 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30591 + if (au_ftest_si(sbi, NO_DREVAL)) {
30592 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30593 + sb->s_d_op = &aufs_dop_noreval;
30594 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30595 + sbi->si_iop_array = aufs_iop_nogetattr;
30597 + AuDebugOn(sb->s_d_op == &aufs_dop);
30598 + sb->s_d_op = &aufs_dop;
30599 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30600 + sbi->si_iop_array = aufs_iop;
30602 + pr_info("reset to %ps and %ps\n",
30603 + sb->s_d_op, sbi->si_iop_array);
30606 + di_write_unlock(root);
30607 + err = au_refresh_d(sb, do_idop);
30608 + e = au_refresh_i(sb, do_idop);
30609 + if (unlikely(e && !err))
30611 + /* aufs_write_lock() calls ..._child() */
30612 + di_write_lock_child(root);
30614 + au_cpup_attr_all(inode, /*force*/1);
30616 + if (unlikely(err))
30617 + AuIOErr("refresh failed, ignored, %d\n", err);
30620 +const struct super_operations aufs_sop = {
30621 + .alloc_inode = aufs_alloc_inode,
30622 + .destroy_inode = aufs_destroy_inode,
30623 + .free_inode = aufs_free_inode,
30624 + /* always deleting, no clearing */
30625 + .drop_inode = generic_delete_inode,
30626 + .show_options = aufs_show_options,
30627 + .statfs = aufs_statfs,
30628 + .put_super = aufs_put_super,
30629 + .sync_fs = aufs_sync_fs
30632 +/* ---------------------------------------------------------------------- */
30634 +int au_alloc_root(struct super_block *sb)
30637 + struct inode *inode;
30638 + struct dentry *root;
30641 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30642 + err = PTR_ERR(inode);
30643 + if (IS_ERR(inode))
30646 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30647 + inode->i_fop = &aufs_dir_fop;
30648 + inode->i_mode = S_IFDIR;
30649 + set_nlink(inode, 2);
30650 + unlock_new_inode(inode);
30652 + root = d_make_root(inode);
30653 + if (unlikely(!root))
30655 + err = PTR_ERR(root);
30656 + if (IS_ERR(root))
30659 + err = au_di_init(root);
30661 + sb->s_root = root;
30662 + return 0; /* success */
30670 +/* ---------------------------------------------------------------------- */
30672 +static void aufs_kill_sb(struct super_block *sb)
30674 + struct au_sbinfo *sbinfo;
30675 + struct dentry *root;
30677 + sbinfo = au_sbi(sb);
30681 + au_sbilist_del(sb);
30683 + root = sb->s_root;
30685 + aufs_write_lock(root);
30687 + __si_write_lock(sb);
30690 + if (sbinfo->si_wbr_create_ops->fin)
30691 + sbinfo->si_wbr_create_ops->fin(sb);
30692 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30693 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30694 + au_remount_refresh(sb, /*do_idop*/0);
30696 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30697 + au_plink_put(sb, /*verbose*/1);
30700 + au_dr_opt_flush(sb);
30703 + aufs_write_unlock(root);
30705 + __si_write_unlock(sb);
30707 + sbinfo->si_sb = NULL;
30708 + au_nwt_flush(&sbinfo->si_nowait);
30711 + kill_anon_super(sb);
30714 +struct file_system_type aufs_fs_type = {
30715 + .name = AUFS_FSTYPE,
30716 + /* a race between rename and others */
30717 + .fs_flags = FS_RENAME_DOES_D_MOVE
30719 + /*| FS_ALLOW_IDMAP*/
30721 + .init_fs_context = aufs_fsctx_init,
30722 + .parameters = aufs_fsctx_paramspec,
30723 + .kill_sb = aufs_kill_sb,
30724 + /* no need to __module_get() and module_put(). */
30725 + .owner = THIS_MODULE,
30727 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30728 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30729 +++ linux/fs/aufs/super.h 2022-11-05 23:02:18.969222617 +0100
30731 +/* SPDX-License-Identifier: GPL-2.0 */
30733 + * Copyright (C) 2005-2022 Junjiro R. Okajima
30735 + * This program is free software; you can redistribute it and/or modify
30736 + * it under the terms of the GNU General Public License as published by
30737 + * the Free Software Foundation; either version 2 of the License, or
30738 + * (at your option) any later version.
30740 + * This program is distributed in the hope that it will be useful,
30741 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30742 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30743 + * GNU General Public License for more details.
30745 + * You should have received a copy of the GNU General Public License
30746 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30750 + * super_block operations
30753 +#ifndef __AUFS_SUPER_H__
30754 +#define __AUFS_SUPER_H__
30758 +#include <linux/fs.h>
30759 +#include <linux/kobject.h>
30762 +#include "rwsem.h"
30765 +/* policies to select one among multiple writable branches */
30766 +struct au_wbr_copyup_operations {
30767 + int (*copyup)(struct dentry *dentry);
30770 +#define AuWbr_DIR 1 /* target is a dir */
30771 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30773 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30774 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30775 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30777 +struct au_wbr_create_operations {
30778 + int (*create)(struct dentry *dentry, unsigned int flags);
30779 + int (*init)(struct super_block *sb);
30780 + int (*fin)(struct super_block *sb);
30783 +struct au_wbr_mfs {
30784 + struct mutex mfs_lock; /* protect this structure */
30785 + unsigned long mfs_jiffy;
30786 + unsigned long mfs_expire;
30787 + aufs_bindex_t mfs_bindex;
30789 + unsigned long long mfsrr_bytes;
30790 + unsigned long long mfsrr_watermark;
30793 +#define AuPlink_NHASH 100
30794 +static inline int au_plink_hash(ino_t ino)
30796 + return ino % AuPlink_NHASH;
30799 +/* File-based Hierarchical Storage Management */
30801 +#ifdef CONFIG_AUFS_FHSM
30802 + /* allow only one process who can receive the notification */
30803 + spinlock_t fhsm_spin;
30805 + wait_queue_head_t fhsm_wqh;
30806 + atomic_t fhsm_readable;
30808 + /* these are protected by si_rwsem */
30809 + unsigned long fhsm_expire;
30810 + aufs_bindex_t fhsm_bottom;
30815 +struct au_sbinfo {
30816 + /* nowait tasks in the system-wide workqueue */
30817 + struct au_nowait_tasks si_nowait;
30820 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30821 + * rwsem for au_sbinfo is necessary.
30823 + struct au_rwsem si_rwsem;
30826 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30829 + au_lcnt_t si_ninodes, si_nfiles;
30831 + /* branch management */
30832 + unsigned int si_generation;
30834 + /* see AuSi_ flags */
30835 + unsigned char au_si_status;
30837 + aufs_bindex_t si_bbot;
30839 + /* dirty trick to keep br_id plus */
30840 + unsigned int si_last_br_id :
30841 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30842 + struct au_branch **si_branch;
30844 + /* policy to select a writable branch */
30845 + unsigned char si_wbr_copyup;
30846 + unsigned char si_wbr_create;
30847 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30848 + struct au_wbr_create_operations *si_wbr_create_ops;
30850 + /* round robin */
30851 + atomic_t si_wbr_rr_next;
30853 + /* most free space */
30854 + struct au_wbr_mfs si_wbr_mfs;
30856 + /* File-based Hierarchical Storage Management */
30857 + struct au_fhsm si_fhsm;
30859 + /* mount flags */
30860 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30861 + unsigned int si_mntflags;
30863 + /* external inode number (bitmap and translation table) */
30864 + loff_t si_ximaxent; /* max entries in a xino */
30866 + struct file *si_xib;
30867 + struct mutex si_xib_mtx; /* protect xib members */
30868 + unsigned long *si_xib_buf;
30869 + unsigned long si_xib_last_pindex;
30870 + int si_xib_next_bit;
30872 + unsigned long si_xino_jiffy;
30873 + unsigned long si_xino_expire;
30874 + /* reserved for future use */
30875 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30877 +#ifdef CONFIG_AUFS_EXPORT
30878 + /* i_generation */
30879 + /* todo: make xigen file an array to support many inode numbers */
30880 + struct file *si_xigen;
30881 + atomic_t si_xigen_next;
30884 + /* dirty trick to support atomic_open */
30885 + struct hlist_bl_head si_aopen;
30887 + /* vdir parameters */
30888 + unsigned long si_rdcache; /* max cache time in jiffies */
30889 + unsigned int si_rdblk; /* deblk size */
30890 + unsigned int si_rdhash; /* hash size */
30893 + * If the number of whiteouts are larger than si_dirwh, leave all of
30894 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30895 + * future fsck.aufs or kernel thread will remove them later.
30896 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30898 + unsigned int si_dirwh;
30900 + /* pseudo_link list */
30901 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30902 + wait_queue_head_t si_plink_wq;
30903 + spinlock_t si_plink_maint_lock;
30904 + pid_t si_plink_maint_pid;
30907 + struct hlist_bl_head si_files;
30909 + /* with/without getattr, brother of sb->s_d_op */
30910 + const struct inode_operations *si_iop_array;
30913 + * sysfs and lifetime management.
30914 + * this is not a small structure and it may be a waste of memory in case
30915 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30916 + * but using sysfs is majority.
30918 + struct kobject si_kobj;
30919 +#ifdef CONFIG_DEBUG_FS
30920 + struct dentry *si_dbgaufs;
30921 + struct dentry *si_dbgaufs_plink;
30922 + struct dentry *si_dbgaufs_xib;
30923 +#ifdef CONFIG_AUFS_EXPORT
30924 + struct dentry *si_dbgaufs_xigen;
30928 +#ifdef CONFIG_AUFS_SBILIST
30929 + struct hlist_bl_node si_list;
30932 + /* dirty, necessary for unmounting, sysfs and sysrq */
30933 + struct super_block *si_sb;
30936 +/* sbinfo status flags */
30938 + * set true when refresh_dirs() failed at remount time.
30939 + * then try refreshing dirs at access time again.
30940 + * if it is false, refreshing dirs at access time is unnecessary
30942 +#define AuSi_FAILED_REFRESH_DIR 1
30943 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30944 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30946 +#ifndef CONFIG_AUFS_FHSM
30948 +#define AuSi_FHSM 0
30951 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30952 + unsigned int flag)
30954 + AuRwMustAnyLock(&sbi->si_rwsem);
30955 + return sbi->au_si_status & flag;
30957 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30958 +#define au_fset_si(sbinfo, name) do { \
30959 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30960 + (sbinfo)->au_si_status |= AuSi_##name; \
30962 +#define au_fclr_si(sbinfo, name) do { \
30963 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30964 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30967 +/* ---------------------------------------------------------------------- */
30969 +/* policy to select one among writable branches */
30970 +#define AuWbrCopyup(sbinfo, ...) \
30971 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30972 +#define AuWbrCreate(sbinfo, ...) \
30973 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30975 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30976 +#define AuLock_DW 1 /* write-lock dentry */
30977 +#define AuLock_IR (1 << 1) /* read-lock inode */
30978 +#define AuLock_IW (1 << 2) /* write-lock inode */
30979 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30980 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30981 + /* except RENAME_EXCHANGE */
30982 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30983 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30984 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30985 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30986 +#define au_fset_lock(flags, name) \
30987 + do { (flags) |= AuLock_##name; } while (0)
30988 +#define au_fclr_lock(flags, name) \
30989 + do { (flags) &= ~AuLock_##name; } while (0)
30991 +/* ---------------------------------------------------------------------- */
30994 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30996 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30997 + unsigned long long max, void *arg);
30998 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30999 + struct super_block *sb, void *arg);
31000 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
31001 +void au_iarray_free(struct inode **a, unsigned long long max);
31003 +void au_remount_refresh(struct super_block *sb, unsigned int do_idop);
31004 +extern const struct super_operations aufs_sop;
31005 +int au_alloc_root(struct super_block *sb);
31006 +extern struct file_system_type aufs_fs_type;
31009 +void au_si_free(struct kobject *kobj);
31010 +struct au_sbinfo *au_si_alloc(struct super_block *sb);
31011 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
31013 +unsigned int au_sigen_inc(struct super_block *sb);
31014 +aufs_bindex_t au_new_br_id(struct super_block *sb);
31016 +int si_read_lock(struct super_block *sb, int flags);
31017 +int si_write_lock(struct super_block *sb, int flags);
31018 +int aufs_read_lock(struct dentry *dentry, int flags);
31019 +void aufs_read_unlock(struct dentry *dentry, int flags);
31020 +void aufs_write_lock(struct dentry *dentry);
31021 +void aufs_write_unlock(struct dentry *dentry);
31022 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
31023 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
31025 +/* wbr_policy.c */
31026 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
31027 +extern struct au_wbr_create_operations au_wbr_create_ops[];
31028 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
31029 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
31030 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
31033 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
31035 +#ifdef CONFIG_AUFS_FHSM
31038 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
31042 + spin_lock(&fhsm->fhsm_spin);
31043 + pid = fhsm->fhsm_pid;
31044 + spin_unlock(&fhsm->fhsm_spin);
31049 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
31050 +void au_fhsm_wrote_all(struct super_block *sb, int force);
31051 +int au_fhsm_fd(struct super_block *sb, int oflags);
31052 +int au_fhsm_br_alloc(struct au_branch *br);
31053 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
31054 +void au_fhsm_fin(struct super_block *sb);
31055 +void au_fhsm_init(struct au_sbinfo *sbinfo);
31056 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
31057 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
31059 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
31061 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
31062 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
31063 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
31064 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
31065 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
31066 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
31067 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
31068 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
31069 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
31072 +/* ---------------------------------------------------------------------- */
31074 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
31076 + return sb->s_fs_info;
31079 +/* ---------------------------------------------------------------------- */
31081 +#ifdef CONFIG_AUFS_EXPORT
31082 +int au_test_nfsd(void);
31083 +void au_export_init(struct super_block *sb);
31084 +void au_xigen_inc(struct inode *inode);
31085 +int au_xigen_new(struct inode *inode);
31086 +int au_xigen_set(struct super_block *sb, struct path *path);
31087 +void au_xigen_clr(struct super_block *sb);
31089 +static inline int au_busy_or_stale(void)
31091 + if (!au_test_nfsd())
31096 +AuStubInt0(au_test_nfsd, void)
31097 +AuStubVoid(au_export_init, struct super_block *sb)
31098 +AuStubVoid(au_xigen_inc, struct inode *inode)
31099 +AuStubInt0(au_xigen_new, struct inode *inode)
31100 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
31101 +AuStubVoid(au_xigen_clr, struct super_block *sb)
31102 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
31103 +#endif /* CONFIG_AUFS_EXPORT */
31105 +/* ---------------------------------------------------------------------- */
31107 +#ifdef CONFIG_AUFS_SBILIST
31109 +extern struct hlist_bl_head au_sbilist;
31111 +static inline void au_sbilist_init(void)
31113 + INIT_HLIST_BL_HEAD(&au_sbilist);
31116 +static inline void au_sbilist_add(struct super_block *sb)
31118 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
31121 +static inline void au_sbilist_del(struct super_block *sb)
31123 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
31126 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
31127 +static inline void au_sbilist_lock(void)
31129 + hlist_bl_lock(&au_sbilist);
31132 +static inline void au_sbilist_unlock(void)
31134 + hlist_bl_unlock(&au_sbilist);
31136 +#define AuGFP_SBILIST GFP_ATOMIC
31138 +AuStubVoid(au_sbilist_lock, void)
31139 +AuStubVoid(au_sbilist_unlock, void)
31140 +#define AuGFP_SBILIST GFP_NOFS
31141 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
31143 +AuStubVoid(au_sbilist_init, void)
31144 +AuStubVoid(au_sbilist_add, struct super_block *sb)
31145 +AuStubVoid(au_sbilist_del, struct super_block *sb)
31146 +AuStubVoid(au_sbilist_lock, void)
31147 +AuStubVoid(au_sbilist_unlock, void)
31148 +#define AuGFP_SBILIST GFP_NOFS
31151 +/* ---------------------------------------------------------------------- */
31153 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
31156 + * This function is a dynamic '__init' function actually,
31157 + * so the tiny check for si_rwsem is unnecessary.
31159 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
31160 +#ifdef CONFIG_DEBUG_FS
31161 + sbinfo->si_dbgaufs = NULL;
31162 + sbinfo->si_dbgaufs_plink = NULL;
31163 + sbinfo->si_dbgaufs_xib = NULL;
31164 +#ifdef CONFIG_AUFS_EXPORT
31165 + sbinfo->si_dbgaufs_xigen = NULL;
31170 +/* ---------------------------------------------------------------------- */
31172 +/* current->atomic_flags */
31173 +/* this value should never corrupt the ones defined in linux/sched.h */
31174 +#define PFA_AUFS 0x10
31176 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
31177 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
31178 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
31180 +static inline int si_pid_test(struct super_block *sb)
31182 + return !!task_test_aufs(current);
31185 +static inline void si_pid_clr(struct super_block *sb)
31187 + AuDebugOn(!task_test_aufs(current));
31188 + task_clear_aufs(current);
31191 +static inline void si_pid_set(struct super_block *sb)
31193 + AuDebugOn(task_test_aufs(current));
31194 + task_set_aufs(current);
31197 +/* ---------------------------------------------------------------------- */
31199 +/* lock superblock. mainly for entry point functions */
31200 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
31201 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
31202 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
31203 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
31205 +#define __si_read_trylock_nested(sb) \
31206 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
31207 +#define __si_write_trylock_nested(sb) \
31208 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
31211 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
31212 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
31213 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
31215 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
31216 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
31217 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
31219 +static inline void si_noflush_read_lock(struct super_block *sb)
31221 + __si_read_lock(sb);
31225 +static inline int si_noflush_read_trylock(struct super_block *sb)
31229 + locked = __si_read_trylock(sb);
31235 +static inline void si_noflush_write_lock(struct super_block *sb)
31237 + __si_write_lock(sb);
31241 +static inline int si_noflush_write_trylock(struct super_block *sb)
31245 + locked = __si_write_trylock(sb);
31251 +#if 0 /* reserved */
31252 +static inline int si_read_trylock(struct super_block *sb, int flags)
31254 + if (au_ftest_lock(flags, FLUSH))
31255 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31256 + return si_noflush_read_trylock(sb);
31260 +static inline void si_read_unlock(struct super_block *sb)
31263 + __si_read_unlock(sb);
31266 +#if 0 /* reserved */
31267 +static inline int si_write_trylock(struct super_block *sb, int flags)
31269 + if (au_ftest_lock(flags, FLUSH))
31270 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31271 + return si_noflush_write_trylock(sb);
31275 +static inline void si_write_unlock(struct super_block *sb)
31278 + __si_write_unlock(sb);
31281 +#if 0 /* reserved */
31282 +static inline void si_downgrade_lock(struct super_block *sb)
31284 + __si_downgrade_lock(sb);
31288 +/* ---------------------------------------------------------------------- */
31290 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31292 + SiMustAnyLock(sb);
31293 + return au_sbi(sb)->si_bbot;
31296 +static inline unsigned int au_mntflags(struct super_block *sb)
31298 + SiMustAnyLock(sb);
31299 + return au_sbi(sb)->si_mntflags;
31302 +static inline unsigned int au_sigen(struct super_block *sb)
31304 + SiMustAnyLock(sb);
31305 + return au_sbi(sb)->si_generation;
31308 +static inline struct au_branch *au_sbr(struct super_block *sb,
31309 + aufs_bindex_t bindex)
31311 + SiMustAnyLock(sb);
31312 + return au_sbi(sb)->si_branch[0 + bindex];
31315 +static inline loff_t au_xi_maxent(struct super_block *sb)
31317 + SiMustAnyLock(sb);
31318 + return au_sbi(sb)->si_ximaxent;
31321 +#endif /* __KERNEL__ */
31322 +#endif /* __AUFS_SUPER_H__ */
31323 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31324 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31325 +++ linux/fs/aufs/sysaufs.c 2022-11-05 23:02:18.969222617 +0100
31327 +// SPDX-License-Identifier: GPL-2.0
31329 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31331 + * This program is free software; you can redistribute it and/or modify
31332 + * it under the terms of the GNU General Public License as published by
31333 + * the Free Software Foundation; either version 2 of the License, or
31334 + * (at your option) any later version.
31336 + * This program is distributed in the hope that it will be useful,
31337 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31338 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31339 + * GNU General Public License for more details.
31341 + * You should have received a copy of the GNU General Public License
31342 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31346 + * sysfs interface and lifetime management
31347 + * they are necessary regardless sysfs is disabled.
31350 +#include <linux/random.h>
31353 +unsigned long sysaufs_si_mask;
31354 +struct kset *sysaufs_kset;
31356 +#define AuSiAttr(_name) { \
31357 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31358 + .show = sysaufs_si_##_name, \
31361 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31362 +struct attribute *sysaufs_si_attrs[] = {
31363 + &sysaufs_si_attr_xi_path.attr,
31366 +ATTRIBUTE_GROUPS(sysaufs_si);
31368 +static const struct sysfs_ops au_sbi_ops = {
31369 + .show = sysaufs_si_show
31372 +static struct kobj_type au_sbi_ktype = {
31373 + .release = au_si_free,
31374 + .sysfs_ops = &au_sbi_ops,
31375 + .default_groups = sysaufs_si_groups
31378 +/* ---------------------------------------------------------------------- */
31380 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31384 + sbinfo->si_kobj.kset = sysaufs_kset;
31385 + /* cf. sysaufs_name() */
31386 + err = kobject_init_and_add
31387 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31388 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31393 +void sysaufs_fin(void)
31395 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31396 + kset_unregister(sysaufs_kset);
31399 +int __init sysaufs_init(void)
31404 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31405 + } while (!sysaufs_si_mask);
31408 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31409 + if (unlikely(!sysaufs_kset))
31411 + err = PTR_ERR(sysaufs_kset);
31412 + if (IS_ERR(sysaufs_kset))
31414 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31415 + if (unlikely(err))
31416 + kset_unregister(sysaufs_kset);
31421 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31422 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31423 +++ linux/fs/aufs/sysaufs.h 2022-11-05 23:02:18.969222617 +0100
31425 +/* SPDX-License-Identifier: GPL-2.0 */
31427 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31429 + * This program is free software; you can redistribute it and/or modify
31430 + * it under the terms of the GNU General Public License as published by
31431 + * the Free Software Foundation; either version 2 of the License, or
31432 + * (at your option) any later version.
31434 + * This program is distributed in the hope that it will be useful,
31435 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31436 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31437 + * GNU General Public License for more details.
31439 + * You should have received a copy of the GNU General Public License
31440 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31444 + * sysfs interface and mount lifetime management
31447 +#ifndef __SYSAUFS_H__
31448 +#define __SYSAUFS_H__
31452 +#include <linux/sysfs.h>
31453 +#include "module.h"
31455 +struct super_block;
31458 +struct sysaufs_si_attr {
31459 + struct attribute attr;
31460 + int (*show)(struct seq_file *seq, struct super_block *sb);
31463 +/* ---------------------------------------------------------------------- */
31466 +extern unsigned long sysaufs_si_mask;
31467 +extern struct kset *sysaufs_kset;
31468 +extern struct attribute *sysaufs_si_attrs[];
31469 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31470 +int __init sysaufs_init(void);
31471 +void sysaufs_fin(void);
31473 +/* ---------------------------------------------------------------------- */
31475 +/* some people doesn't like to show a pointer in kernel */
31476 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31478 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31481 +#define SysaufsSiNamePrefix "si_"
31482 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31483 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31485 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31486 + sysaufs_si_id(sbinfo));
31490 +#ifdef CONFIG_SYSFS
31492 +extern struct attribute_group *sysaufs_attr_group;
31494 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31495 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31497 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31498 +#ifdef CONFIG_COMPAT
31499 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31502 +void sysaufs_br_init(struct au_branch *br);
31503 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31504 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31506 +#define sysaufs_brs_init() do {} while (0)
31509 +#define sysaufs_attr_group NULL
31511 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31512 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31513 + struct attribute *attr, char *buf)
31514 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31515 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31516 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31518 +static inline void sysaufs_brs_init(void)
31523 +#endif /* CONFIG_SYSFS */
31525 +#endif /* __KERNEL__ */
31526 +#endif /* __SYSAUFS_H__ */
31527 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31528 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31529 +++ linux/fs/aufs/sysfs.c 2022-11-05 23:02:18.969222617 +0100
31531 +// SPDX-License-Identifier: GPL-2.0
31533 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31535 + * This program is free software; you can redistribute it and/or modify
31536 + * it under the terms of the GNU General Public License as published by
31537 + * the Free Software Foundation; either version 2 of the License, or
31538 + * (at your option) any later version.
31540 + * This program is distributed in the hope that it will be useful,
31541 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31542 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31543 + * GNU General Public License for more details.
31545 + * You should have received a copy of the GNU General Public License
31546 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31550 + * sysfs interface
31553 +#include <linux/compat.h>
31554 +#include <linux/seq_file.h>
31557 +#ifdef CONFIG_AUFS_FS_MODULE
31558 +/* this entry violates the "one line per file" policy of sysfs */
31559 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31563 + static char *conf =
31564 +/* this file is generated at compiling */
31565 +#include "conf.str"
31568 + err = snprintf(buf, PAGE_SIZE, conf);
31569 + if (unlikely(err >= PAGE_SIZE))
31574 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31577 +static struct attribute *au_attr[] = {
31578 +#ifdef CONFIG_AUFS_FS_MODULE
31579 + &au_config_attr.attr,
31581 + NULL, /* need to NULL terminate the list of attributes */
31584 +static struct attribute_group sysaufs_attr_group_body = {
31588 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31590 +/* ---------------------------------------------------------------------- */
31592 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31596 + SiMustAnyLock(sb);
31599 + if (au_opt_test(au_mntflags(sb), XINO)) {
31600 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31601 + seq_putc(seq, '\n');
31607 + * the lifetime of branch is independent from the entry under sysfs.
31608 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31611 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31612 + aufs_bindex_t bindex, int idx)
31615 + struct path path;
31616 + struct dentry *root;
31617 + struct au_branch *br;
31618 + au_br_perm_str_t perm;
31620 + AuDbg("b%d\n", bindex);
31623 + root = sb->s_root;
31624 + di_read_lock_parent(root, !AuLock_IR);
31625 + br = au_sbr(sb, bindex);
31628 + case AuBrSysfs_BR:
31629 + path.mnt = au_br_mnt(br);
31630 + path.dentry = au_h_dptr(root, bindex);
31631 + err = au_seq_path(seq, &path);
31633 + au_optstr_br_perm(&perm, br->br_perm);
31634 + seq_printf(seq, "=%s\n", perm.a);
31637 + case AuBrSysfs_BRID:
31638 + seq_printf(seq, "%d\n", br->br_id);
31641 + di_read_unlock(root, !AuLock_IR);
31642 + if (unlikely(err || seq_has_overflowed(seq)))
31648 +/* ---------------------------------------------------------------------- */
31650 +static struct seq_file *au_seq(char *p, ssize_t len)
31652 + struct seq_file *seq;
31654 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31656 + /* mutex_init(&seq.lock); */
31659 + return seq; /* success */
31662 + seq = ERR_PTR(-ENOMEM);
31666 +#define SysaufsBr_PREFIX "br"
31667 +#define SysaufsBrid_PREFIX "brid"
31669 +/* todo: file size may exceed PAGE_SIZE */
31670 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31676 + aufs_bindex_t bbot;
31677 + struct au_sbinfo *sbinfo;
31678 + struct super_block *sb;
31679 + struct seq_file *seq;
31681 + struct attribute **cattr;
31683 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31684 + sb = sbinfo->si_sb;
31687 + * prevent a race condition between sysfs and aufs.
31688 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31689 + * prohibits maintaining the sysfs entries.
31690 + * hew we acquire read lock after sysfs_get_active_two().
31691 + * on the other hand, the remount process may maintain the sysfs/aufs
31692 + * entries after acquiring write lock.
31693 + * it can cause a deadlock.
31694 + * simply we gave up processing read here.
31697 + if (unlikely(!si_noflush_read_trylock(sb)))
31700 + seq = au_seq(buf, PAGE_SIZE);
31701 + err = PTR_ERR(seq);
31705 + name = (void *)attr->name;
31706 + cattr = sysaufs_si_attrs;
31708 + if (!strcmp(name, (*cattr)->name)) {
31709 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31716 + if (!strncmp(name, SysaufsBrid_PREFIX,
31717 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31718 + idx = AuBrSysfs_BRID;
31719 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31720 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31721 + sizeof(SysaufsBr_PREFIX) - 1)) {
31722 + idx = AuBrSysfs_BR;
31723 + name += sizeof(SysaufsBr_PREFIX) - 1;
31727 + err = kstrtol(name, 10, &l);
31729 + bbot = au_sbbot(sb);
31731 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31738 + err = seq->count;
31739 + /* sysfs limit */
31740 + if (unlikely(err == PAGE_SIZE))
31743 + au_kfree_rcu(seq);
31745 + si_read_unlock(sb);
31750 +/* ---------------------------------------------------------------------- */
31752 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31756 + aufs_bindex_t bindex, bbot;
31759 + struct seq_file *seq;
31760 + struct au_branch *br;
31762 + si_read_lock(sb, AuLock_FLUSH);
31763 + bbot = au_sbbot(sb);
31769 + buf = (void *)__get_free_page(GFP_NOFS);
31770 + if (unlikely(!buf))
31773 + seq = au_seq(buf, PAGE_SIZE);
31774 + err = PTR_ERR(seq);
31778 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31779 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31780 + /* VERIFY_WRITE */
31781 + err = !access_ok(arg, sizeof(*arg));
31782 + if (unlikely(err))
31785 + br = au_sbr(sb, bindex);
31786 + brid = br->br_id;
31787 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31788 + err = __put_user(brid, &arg->id);
31789 + if (unlikely(err))
31792 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31793 + err = __put_user(br->br_perm, &arg->perm);
31794 + if (unlikely(err))
31797 + err = au_seq_path(seq, &br->br_path);
31798 + if (unlikely(err))
31800 + seq_putc(seq, '\0');
31801 + if (!seq_has_overflowed(seq)) {
31802 + err = copy_to_user(arg->path, seq->buf, seq->count);
31804 + if (unlikely(err))
31811 + if (unlikely(err))
31815 + au_kfree_rcu(seq);
31817 + free_page((unsigned long)buf);
31819 + si_read_unlock(sb);
31823 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31825 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31828 +#ifdef CONFIG_COMPAT
31829 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31831 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31835 +/* ---------------------------------------------------------------------- */
31837 +void sysaufs_br_init(struct au_branch *br)
31840 + struct au_brsysfs *br_sysfs;
31841 + struct attribute *attr;
31843 + br_sysfs = br->br_sysfs;
31844 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31845 + attr = &br_sysfs->attr;
31846 + sysfs_attr_init(attr);
31847 + attr->name = br_sysfs->name;
31848 + attr->mode = 0444;
31853 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31855 + struct au_branch *br;
31856 + struct kobject *kobj;
31857 + struct au_brsysfs *br_sysfs;
31859 + aufs_bindex_t bbot;
31861 + if (!sysaufs_brs)
31864 + kobj = &au_sbi(sb)->si_kobj;
31865 + bbot = au_sbbot(sb);
31866 + for (; bindex <= bbot; bindex++) {
31867 + br = au_sbr(sb, bindex);
31868 + br_sysfs = br->br_sysfs;
31869 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31870 + sysfs_remove_file(kobj, &br_sysfs->attr);
31876 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31879 + aufs_bindex_t bbot;
31880 + struct kobject *kobj;
31881 + struct au_branch *br;
31882 + struct au_brsysfs *br_sysfs;
31884 + if (!sysaufs_brs)
31887 + kobj = &au_sbi(sb)->si_kobj;
31888 + bbot = au_sbbot(sb);
31889 + for (; bindex <= bbot; bindex++) {
31890 + br = au_sbr(sb, bindex);
31891 + br_sysfs = br->br_sysfs;
31892 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31893 + SysaufsBr_PREFIX "%d", bindex);
31894 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31895 + SysaufsBrid_PREFIX "%d", bindex);
31896 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31897 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31898 + if (unlikely(err))
31899 + pr_warn("failed %s under sysfs(%d)\n",
31900 + br_sysfs->name, err);
31905 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31906 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31907 +++ linux/fs/aufs/sysrq.c 2022-11-05 23:02:18.969222617 +0100
31909 +// SPDX-License-Identifier: GPL-2.0
31911 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31913 + * This program is free software; you can redistribute it and/or modify
31914 + * it under the terms of the GNU General Public License as published by
31915 + * the Free Software Foundation; either version 2 of the License, or
31916 + * (at your option) any later version.
31918 + * This program is distributed in the hope that it will be useful,
31919 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31920 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31921 + * GNU General Public License for more details.
31923 + * You should have received a copy of the GNU General Public License
31924 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31928 + * magic sysrq handler
31931 +/* #include <linux/sysrq.h> */
31932 +#include <linux/writeback.h>
31935 +/* ---------------------------------------------------------------------- */
31937 +static void sysrq_sb(struct super_block *sb)
31940 + struct au_sbinfo *sbinfo;
31941 + struct file *file;
31942 + struct hlist_bl_head *files;
31943 + struct hlist_bl_node *pos;
31944 + struct au_finfo *finfo;
31947 + plevel = au_plevel;
31948 + au_plevel = KERN_WARNING;
31950 + /* since we define pr_fmt, call printk directly */
31951 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31953 + sbinfo = au_sbi(sb);
31954 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31955 + pr("superblock\n");
31958 +#if 0 /* reserved */
31960 + int err, i, j, ndentry;
31961 + struct au_dcsub_pages dpages;
31962 + struct au_dpage *dpage;
31964 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31965 + if (unlikely(err))
31967 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31969 + for (i = 0; i < dpages.ndpage; i++) {
31970 + dpage = dpages.dpages + i;
31971 + ndentry = dpage->ndentry;
31972 + for (j = 0; j < ndentry; j++)
31973 + au_dpri_dentry(dpage->dentries[j]);
31975 + au_dpages_free(&dpages);
31979 + pr("isolated inode\n");
31980 + spin_lock(&sb->s_inode_list_lock);
31981 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31982 + spin_lock(&i->i_lock);
31983 + if (hlist_empty(&i->i_dentry))
31984 + au_dpri_inode(i);
31985 + spin_unlock(&i->i_lock);
31987 + spin_unlock(&sb->s_inode_list_lock);
31990 + files = &au_sbi(sb)->si_files;
31991 + hlist_bl_lock(files);
31992 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31995 + file = finfo->fi_file;
31996 + mode = file_inode(file)->i_mode;
31997 + if (!special_file(mode))
31998 + au_dpri_file(file);
32000 + hlist_bl_unlock(files);
32004 + au_plevel = plevel;
32007 +/* ---------------------------------------------------------------------- */
32009 +/* module parameter */
32010 +static char *aufs_sysrq_key = "a";
32011 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
32012 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
32014 +static void au_sysrq(int key __maybe_unused)
32016 + struct au_sbinfo *sbinfo;
32017 + struct hlist_bl_node *pos;
32020 + au_sbilist_lock();
32021 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
32022 + sysrq_sb(sbinfo->si_sb);
32023 + au_sbilist_unlock();
32027 +static struct sysrq_key_op au_sysrq_op = {
32028 + .handler = au_sysrq,
32029 + .help_msg = "Aufs",
32030 + .action_msg = "Aufs",
32031 + .enable_mask = SYSRQ_ENABLE_DUMP
32034 +/* ---------------------------------------------------------------------- */
32036 +int __init au_sysrq_init(void)
32042 + key = *aufs_sysrq_key;
32043 + if ('a' <= key && key <= 'z')
32044 + err = register_sysrq_key(key, &au_sysrq_op);
32045 + if (unlikely(err))
32046 + pr_err("err %d, sysrq=%c\n", err, key);
32050 +void au_sysrq_fin(void)
32054 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
32055 + if (unlikely(err))
32056 + pr_err("err %d (ignored)\n", err);
32058 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
32059 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
32060 +++ linux/fs/aufs/vdir.c 2022-12-17 09:21:34.799855195 +0100
32062 +// SPDX-License-Identifier: GPL-2.0
32064 + * Copyright (C) 2005-2022 Junjiro R. Okajima
32066 + * This program is free software; you can redistribute it and/or modify
32067 + * it under the terms of the GNU General Public License as published by
32068 + * the Free Software Foundation; either version 2 of the License, or
32069 + * (at your option) any later version.
32071 + * This program is distributed in the hope that it will be useful,
32072 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32073 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32074 + * GNU General Public License for more details.
32076 + * You should have received a copy of the GNU General Public License
32077 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32081 + * virtual or vertical directory
32084 +#include <linux/iversion.h>
32087 +static unsigned int calc_size(int nlen)
32089 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
32092 +static int set_deblk_end(union au_vdir_deblk_p *p,
32093 + union au_vdir_deblk_p *deblk_end)
32095 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
32096 + p->de->de_str.len = 0;
32100 + return -1; /* error */
32103 +/* returns true or false */
32104 +static int is_deblk_end(union au_vdir_deblk_p *p,
32105 + union au_vdir_deblk_p *deblk_end)
32107 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
32108 + return !p->de->de_str.len;
32112 +static unsigned char *last_deblk(struct au_vdir *vdir)
32114 + return vdir->vd_deblk[vdir->vd_nblk - 1];
32117 +/* ---------------------------------------------------------------------- */
32119 +/* estimate the appropriate size for name hash table */
32120 +unsigned int au_rdhash_est(loff_t sz)
32128 + if (sz < AUFS_RDHASH_DEF)
32129 + n = AUFS_RDHASH_DEF;
32130 + /* pr_info("n %u\n", n); */
32135 + * the allocated memory has to be freed by
32136 + * au_nhash_wh_free() or au_nhash_de_free().
32138 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
32140 + struct hlist_head *head;
32144 + sz = sizeof(*nhash->nh_head) * num_hash;
32145 + head = kmalloc(sz, gfp);
32147 + nhash->nh_num = num_hash;
32148 + nhash->nh_head = head;
32149 + for (u = 0; u < num_hash; u++)
32150 + INIT_HLIST_HEAD(head++);
32151 + return 0; /* success */
32157 +static void nhash_count(struct hlist_head *head)
32159 +#if 0 /* debugging */
32161 + struct hlist_node *pos;
32164 + hlist_for_each(pos, head)
32166 + pr_info("%lu\n", n);
32170 +static void au_nhash_wh_do_free(struct hlist_head *head)
32172 + struct au_vdir_wh *pos;
32173 + struct hlist_node *node;
32175 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
32176 + au_kfree_rcu(pos);
32179 +static void au_nhash_de_do_free(struct hlist_head *head)
32181 + struct au_vdir_dehstr *pos;
32182 + struct hlist_node *node;
32184 + hlist_for_each_entry_safe(pos, node, head, hash)
32185 + au_cache_free_vdir_dehstr(pos);
32188 +static void au_nhash_do_free(struct au_nhash *nhash,
32189 + void (*free)(struct hlist_head *head))
32192 + struct hlist_head *head;
32194 + n = nhash->nh_num;
32198 + head = nhash->nh_head;
32199 + while (n-- > 0) {
32200 + nhash_count(head);
32203 + au_kfree_try_rcu(nhash->nh_head);
32206 +void au_nhash_wh_free(struct au_nhash *whlist)
32208 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
32211 +static void au_nhash_de_free(struct au_nhash *delist)
32213 + au_nhash_do_free(delist, au_nhash_de_do_free);
32216 +/* ---------------------------------------------------------------------- */
32218 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
32222 + unsigned int u, n;
32223 + struct hlist_head *head;
32224 + struct au_vdir_wh *pos;
32227 + n = whlist->nh_num;
32228 + head = whlist->nh_head;
32229 + for (u = 0; u < n; u++, head++)
32230 + hlist_for_each_entry(pos, head, wh_hash)
32231 + if (pos->wh_bindex == btgt && ++num > limit)
32236 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
32237 + unsigned char *name,
32238 + unsigned int len)
32241 + /* const unsigned int magic_bit = 12; */
32243 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32250 + /* v = hash_long(v, magic_bit); */
32251 + v %= nhash->nh_num;
32252 + return nhash->nh_head + v;
32255 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32258 + return str->len == nlen && !memcmp(str->name, name, nlen);
32261 +/* returns found or not */
32262 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32264 + struct hlist_head *head;
32265 + struct au_vdir_wh *pos;
32266 + struct au_vdir_destr *str;
32268 + head = au_name_hash(whlist, name, nlen);
32269 + hlist_for_each_entry(pos, head, wh_hash) {
32270 + str = &pos->wh_str;
32271 + AuDbg("%.*s\n", str->len, str->name);
32272 + if (au_nhash_test_name(str, name, nlen))
32278 +/* returns found(true) or not */
32279 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32281 + struct hlist_head *head;
32282 + struct au_vdir_dehstr *pos;
32283 + struct au_vdir_destr *str;
32285 + head = au_name_hash(delist, name, nlen);
32286 + hlist_for_each_entry(pos, head, hash) {
32288 + AuDbg("%.*s\n", str->len, str->name);
32289 + if (au_nhash_test_name(str, name, nlen))
32295 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32296 + unsigned char d_type)
32298 +#ifdef CONFIG_AUFS_SHWH
32299 + wh->wh_ino = ino;
32300 + wh->wh_type = d_type;
32304 +/* ---------------------------------------------------------------------- */
32306 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32307 + unsigned int d_type, aufs_bindex_t bindex,
32308 + unsigned char shwh)
32311 + struct au_vdir_destr *str;
32312 + struct au_vdir_wh *wh;
32314 + AuDbg("%.*s\n", nlen, name);
32315 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32318 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32319 + if (unlikely(!wh))
32323 + wh->wh_bindex = bindex;
32325 + au_shwh_init_wh(wh, ino, d_type);
32326 + str = &wh->wh_str;
32328 + memcpy(str->name, name, nlen);
32329 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32336 +static int append_deblk(struct au_vdir *vdir)
32339 + unsigned long ul;
32340 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32341 + union au_vdir_deblk_p p, deblk_end;
32342 + unsigned char **o;
32345 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32346 + GFP_NOFS, /*may_shrink*/0);
32347 + if (unlikely(!o))
32350 + vdir->vd_deblk = o;
32351 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32353 + ul = vdir->vd_nblk++;
32354 + vdir->vd_deblk[ul] = p.deblk;
32355 + vdir->vd_last.ul = ul;
32356 + vdir->vd_last.p.deblk = p.deblk;
32357 + deblk_end.deblk = p.deblk + deblk_sz;
32358 + err = set_deblk_end(&p, &deblk_end);
32365 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32366 + unsigned int d_type, struct au_nhash *delist)
32370 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32371 + union au_vdir_deblk_p p, *room, deblk_end;
32372 + struct au_vdir_dehstr *dehstr;
32374 + p.deblk = last_deblk(vdir);
32375 + deblk_end.deblk = p.deblk + deblk_sz;
32376 + room = &vdir->vd_last.p;
32377 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32378 + || !is_deblk_end(room, &deblk_end));
32380 + sz = calc_size(nlen);
32381 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32382 + err = append_deblk(vdir);
32383 + if (unlikely(err))
32386 + p.deblk = last_deblk(vdir);
32387 + deblk_end.deblk = p.deblk + deblk_sz;
32389 + AuDebugOn(room->deblk != p.deblk);
32393 + dehstr = au_cache_alloc_vdir_dehstr();
32394 + if (unlikely(!dehstr))
32397 + dehstr->str = &room->de->de_str;
32398 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32399 + room->de->de_ino = ino;
32400 + room->de->de_type = d_type;
32401 + room->de->de_str.len = nlen;
32402 + memcpy(room->de->de_str.name, name, nlen);
32405 + room->deblk += sz;
32406 + if (unlikely(set_deblk_end(room, &deblk_end)))
32407 + err = append_deblk(vdir);
32414 +/* ---------------------------------------------------------------------- */
32416 +void au_vdir_free(struct au_vdir *vdir)
32418 + unsigned char **deblk;
32420 + deblk = vdir->vd_deblk;
32421 + while (vdir->vd_nblk--)
32422 + au_kfree_try_rcu(*deblk++);
32423 + au_kfree_try_rcu(vdir->vd_deblk);
32424 + au_cache_free_vdir(vdir);
32427 +static struct au_vdir *alloc_vdir(struct file *file)
32429 + struct au_vdir *vdir;
32430 + struct super_block *sb;
32433 + sb = file->f_path.dentry->d_sb;
32434 + SiMustAnyLock(sb);
32437 + vdir = au_cache_alloc_vdir();
32438 + if (unlikely(!vdir))
32441 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32442 + if (unlikely(!vdir->vd_deblk))
32445 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32446 + if (!vdir->vd_deblk_sz) {
32447 + /* estimate the appropriate size for deblk */
32448 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32449 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32451 + vdir->vd_nblk = 0;
32452 + vdir->vd_version = 0;
32453 + vdir->vd_jiffy = 0;
32454 + err = append_deblk(vdir);
32456 + return vdir; /* success */
32458 + au_kfree_try_rcu(vdir->vd_deblk);
32461 + au_cache_free_vdir(vdir);
32463 + vdir = ERR_PTR(err);
32467 +static int reinit_vdir(struct au_vdir *vdir)
32470 + union au_vdir_deblk_p p, deblk_end;
32472 + while (vdir->vd_nblk > 1) {
32473 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32474 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32477 + p.deblk = vdir->vd_deblk[0];
32478 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32479 + err = set_deblk_end(&p, &deblk_end);
32480 + /* keep vd_dblk_sz */
32481 + vdir->vd_last.ul = 0;
32482 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32483 + vdir->vd_version = 0;
32484 + vdir->vd_jiffy = 0;
32489 +/* ---------------------------------------------------------------------- */
32491 +#define AuFillVdir_CALLED 1
32492 +#define AuFillVdir_WHABLE (1 << 1)
32493 +#define AuFillVdir_SHWH (1 << 2)
32494 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32495 +#define au_fset_fillvdir(flags, name) \
32496 + do { (flags) |= AuFillVdir_##name; } while (0)
32497 +#define au_fclr_fillvdir(flags, name) \
32498 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32500 +#ifndef CONFIG_AUFS_SHWH
32501 +#undef AuFillVdir_SHWH
32502 +#define AuFillVdir_SHWH 0
32505 +struct fillvdir_arg {
32506 + struct dir_context ctx;
32507 + struct file *file;
32508 + struct au_vdir *vdir;
32509 + struct au_nhash delist;
32510 + struct au_nhash whlist;
32511 + aufs_bindex_t bindex;
32512 + unsigned int flags;
32516 +static bool fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32517 + loff_t offset __maybe_unused, u64 h_ino,
32518 + unsigned int d_type)
32520 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32521 + char *name = (void *)__name;
32522 + struct super_block *sb;
32524 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32527 + sb = arg->file->f_path.dentry->d_sb;
32528 + au_fset_fillvdir(arg->flags, CALLED);
32530 + if (nlen <= AUFS_WH_PFX_LEN
32531 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32532 + if (test_known(&arg->delist, name, nlen)
32533 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32534 + goto out; /* already exists or whiteouted */
32536 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32538 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32539 + d_type = DT_UNKNOWN;
32540 + arg->err = append_de(arg->vdir, name, nlen, ino,
32541 + d_type, &arg->delist);
32543 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32544 + name += AUFS_WH_PFX_LEN;
32545 + nlen -= AUFS_WH_PFX_LEN;
32546 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32547 + goto out; /* already whiteouted */
32549 + ino = 0; /* just to suppress a warning */
32551 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32554 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32555 + d_type = DT_UNKNOWN;
32556 + arg->err = au_nhash_append_wh
32557 + (&arg->whlist, name, nlen, ino, d_type,
32558 + arg->bindex, shwh);
32564 + arg->vdir->vd_jiffy = jiffies;
32566 + AuTraceErr(arg->err);
32567 + return !arg->err;
32570 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32571 + struct au_nhash *whlist, struct au_nhash *delist)
32573 +#ifdef CONFIG_AUFS_SHWH
32575 + unsigned int nh, u;
32576 + struct hlist_head *head;
32577 + struct au_vdir_wh *pos;
32578 + struct hlist_node *n;
32580 + struct au_vdir_destr *destr;
32582 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32585 + o = p = (void *)__get_free_page(GFP_NOFS);
32586 + if (unlikely(!p))
32590 + nh = whlist->nh_num;
32591 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32592 + p += AUFS_WH_PFX_LEN;
32593 + for (u = 0; u < nh; u++) {
32594 + head = whlist->nh_head + u;
32595 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32596 + destr = &pos->wh_str;
32597 + memcpy(p, destr->name, destr->len);
32598 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32599 + pos->wh_ino, pos->wh_type, delist);
32600 + if (unlikely(err))
32605 + free_page((unsigned long)o);
32615 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32618 + unsigned int rdhash;
32620 + aufs_bindex_t bbot, bindex, btop;
32621 + unsigned char shwh;
32622 + struct file *hf, *file;
32623 + struct super_block *sb;
32625 + file = arg->file;
32626 + sb = file->f_path.dentry->d_sb;
32627 + SiMustAnyLock(sb);
32629 + rdhash = au_sbi(sb)->si_rdhash;
32631 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32632 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32633 + if (unlikely(err))
32635 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32636 + if (unlikely(err))
32642 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32644 + au_fset_fillvdir(arg->flags, SHWH);
32646 + btop = au_fbtop(file);
32647 + bbot = au_fbbot_dir(file);
32648 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32649 + hf = au_hf_dir(file, bindex);
32653 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32655 + if (unlikely(offset))
32658 + arg->bindex = bindex;
32659 + au_fclr_fillvdir(arg->flags, WHABLE);
32661 + || (bindex != bbot
32662 + && au_br_whable(au_sbr_perm(sb, bindex))))
32663 + au_fset_fillvdir(arg->flags, WHABLE);
32666 + au_fclr_fillvdir(arg->flags, CALLED);
32668 + err = vfsub_iterate_dir(hf, &arg->ctx);
32671 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32674 + * dir_relax() may be good for concurrency, but aufs should not
32675 + * use it since it will cause a lockdep problem.
32679 + if (!err && shwh)
32680 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32682 + au_nhash_wh_free(&arg->whlist);
32685 + au_nhash_de_free(&arg->delist);
32690 +static int read_vdir(struct file *file, int may_read)
32693 + unsigned long expire;
32694 + unsigned char do_read;
32695 + struct fillvdir_arg arg = {
32697 + .actor = fillvdir
32700 + struct inode *inode;
32701 + struct au_vdir *vdir, *allocated;
32704 + inode = file_inode(file);
32705 + IMustLock(inode);
32706 + IiMustWriteLock(inode);
32707 + SiMustAnyLock(inode->i_sb);
32709 + allocated = NULL;
32711 + expire = au_sbi(inode->i_sb)->si_rdcache;
32712 + vdir = au_ivdir(inode);
32715 + vdir = alloc_vdir(file);
32716 + err = PTR_ERR(vdir);
32717 + if (IS_ERR(vdir))
32720 + allocated = vdir;
32721 + } else if (may_read
32722 + && (!inode_eq_iversion(inode, vdir->vd_version)
32723 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32725 + err = reinit_vdir(vdir);
32726 + if (unlikely(err))
32731 + return 0; /* success */
32735 + err = au_do_read_vdir(&arg);
32737 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32738 + vdir->vd_version = inode_query_iversion(inode);
32739 + vdir->vd_last.ul = 0;
32740 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32742 + au_set_ivdir(inode, allocated);
32743 + } else if (allocated)
32744 + au_vdir_free(allocated);
32750 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32753 + unsigned long ul, n;
32754 + const unsigned int deblk_sz = src->vd_deblk_sz;
32756 + AuDebugOn(tgt->vd_nblk != 1);
32759 + if (tgt->vd_nblk < src->vd_nblk) {
32760 + unsigned char **p;
32762 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32763 + GFP_NOFS, /*may_shrink*/0);
32764 + if (unlikely(!p))
32766 + tgt->vd_deblk = p;
32769 + if (tgt->vd_deblk_sz != deblk_sz) {
32770 + unsigned char *p;
32772 + tgt->vd_deblk_sz = deblk_sz;
32773 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32774 + /*may_shrink*/1);
32775 + if (unlikely(!p))
32777 + tgt->vd_deblk[0] = p;
32779 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32780 + tgt->vd_version = src->vd_version;
32781 + tgt->vd_jiffy = src->vd_jiffy;
32783 + n = src->vd_nblk;
32784 + for (ul = 1; ul < n; ul++) {
32785 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32787 + if (unlikely(!tgt->vd_deblk[ul]))
32791 + tgt->vd_nblk = n;
32792 + tgt->vd_last.ul = tgt->vd_last.ul;
32793 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32794 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32795 + - src->vd_deblk[src->vd_last.ul];
32797 + return 0; /* success */
32800 + rerr = reinit_vdir(tgt);
32805 +int au_vdir_init(struct file *file)
32808 + struct inode *inode;
32809 + struct au_vdir *vdir_cache, *allocated;
32811 + /* test file->f_pos here instead of ctx->pos */
32812 + err = read_vdir(file, !file->f_pos);
32813 + if (unlikely(err))
32816 + allocated = NULL;
32817 + vdir_cache = au_fvdir_cache(file);
32818 + if (!vdir_cache) {
32819 + vdir_cache = alloc_vdir(file);
32820 + err = PTR_ERR(vdir_cache);
32821 + if (IS_ERR(vdir_cache))
32823 + allocated = vdir_cache;
32824 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32825 + /* test file->f_pos here instead of ctx->pos */
32826 + err = reinit_vdir(vdir_cache);
32827 + if (unlikely(err))
32830 + return 0; /* success */
32832 + inode = file_inode(file);
32833 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32835 + file->f_version = inode_query_iversion(inode);
32837 + au_set_fvdir_cache(file, allocated);
32838 + } else if (allocated)
32839 + au_vdir_free(allocated);
32845 +static loff_t calc_offset(struct au_vdir *vdir)
32848 + union au_vdir_deblk_p p;
32850 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32851 + offset = vdir->vd_last.p.deblk - p.deblk;
32852 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32856 +/* returns true or false */
32857 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32860 + unsigned int deblk_sz;
32861 + unsigned long ul, n;
32863 + union au_vdir_deblk_p p, deblk_end;
32864 + struct au_vdir *vdir_cache;
32867 + vdir_cache = au_fvdir_cache(file);
32868 + offset = calc_offset(vdir_cache);
32869 + AuDbg("offset %lld\n", offset);
32870 + if (ctx->pos == offset)
32873 + vdir_cache->vd_last.ul = 0;
32874 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32879 + deblk_sz = vdir_cache->vd_deblk_sz;
32880 + ul = div64_u64(ctx->pos, deblk_sz);
32881 + AuDbg("ul %lu\n", ul);
32882 + if (ul >= vdir_cache->vd_nblk)
32885 + n = vdir_cache->vd_nblk;
32886 + for (; ul < n; ul++) {
32887 + p.deblk = vdir_cache->vd_deblk[ul];
32888 + deblk_end.deblk = p.deblk + deblk_sz;
32890 + offset *= deblk_sz;
32891 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32894 + l = calc_size(p.de->de_str.len);
32898 + if (!is_deblk_end(&p, &deblk_end)) {
32900 + vdir_cache->vd_last.ul = ul;
32901 + vdir_cache->vd_last.p = p;
32909 + AuDbg("valid %d\n", !valid);
32913 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32915 + unsigned int l, deblk_sz;
32916 + union au_vdir_deblk_p deblk_end;
32917 + struct au_vdir *vdir_cache;
32918 + struct au_vdir_de *de;
32920 + if (!seek_vdir(file, ctx))
32923 + vdir_cache = au_fvdir_cache(file);
32924 + deblk_sz = vdir_cache->vd_deblk_sz;
32926 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32927 + deblk_end.deblk += deblk_sz;
32928 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32929 + de = vdir_cache->vd_last.p.de;
32930 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32931 + de->de_str.len, de->de_str.name, ctx->pos,
32932 + (unsigned long)de->de_ino, de->de_type);
32933 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32934 + de->de_str.len, de->de_ino,
32936 + /* todo: ignore the error caused by udba? */
32937 + /* return err; */
32941 + l = calc_size(de->de_str.len);
32942 + vdir_cache->vd_last.p.deblk += l;
32945 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32946 + vdir_cache->vd_last.ul++;
32947 + vdir_cache->vd_last.p.deblk
32948 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32949 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32958 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32959 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32960 +++ linux/fs/aufs/vfsub.c 2022-11-05 23:02:18.969222617 +0100
32962 +// SPDX-License-Identifier: GPL-2.0
32964 + * Copyright (C) 2005-2022 Junjiro R. Okajima
32966 + * This program is free software; you can redistribute it and/or modify
32967 + * it under the terms of the GNU General Public License as published by
32968 + * the Free Software Foundation; either version 2 of the License, or
32969 + * (at your option) any later version.
32971 + * This program is distributed in the hope that it will be useful,
32972 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32973 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32974 + * GNU General Public License for more details.
32976 + * You should have received a copy of the GNU General Public License
32977 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32981 + * sub-routines for VFS
32984 +#include <linux/mnt_namespace.h>
32985 +#include <linux/nsproxy.h>
32986 +#include <linux/security.h>
32987 +#include <linux/splice.h>
32990 +#ifdef CONFIG_AUFS_BR_FUSE
32991 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32993 + if (!au_test_fuse(h_sb) || !au_userns)
32996 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
33000 +int vfsub_sync_filesystem(struct super_block *h_sb)
33005 + down_read(&h_sb->s_umount);
33006 + err = sync_filesystem(h_sb);
33007 + up_read(&h_sb->s_umount);
33013 +/* ---------------------------------------------------------------------- */
33015 +int vfsub_update_h_iattr(struct path *h_path, int *did)
33019 + struct super_block *h_sb;
33022 + * Always needs h_path->mnt for LSM or FUSE branch.
33024 + AuDebugOn(!h_path->mnt);
33026 + /* for remote fs, leave work for its getattr or d_revalidate */
33027 + /* for bad i_attr fs, handle them in aufs_getattr() */
33028 + /* still some fs may acquire i_mutex. we need to skip them */
33032 + h_sb = h_path->dentry->d_sb;
33033 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
33035 + err = vfsub_getattr(h_path, &st);
33040 +/* ---------------------------------------------------------------------- */
33042 +struct file *vfsub_dentry_open(struct path *path, int flags)
33044 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
33048 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
33050 + struct file *file;
33053 + file = filp_open(path,
33054 + oflags /* | __FMODE_NONOTIFY */,
33057 + if (IS_ERR(file))
33059 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33066 + * Ideally this function should call VFS:do_last() in order to keep all its
33067 + * checkings. But it is very hard for aufs to regenerate several VFS internal
33068 + * structure such as nameidata. This is a second (or third) best approach.
33069 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
33071 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33072 + struct vfsub_aopen_args *args)
33075 + struct au_branch *br = args->br;
33076 + struct file *file = args->file;
33077 + /* copied from linux/fs/namei.c:atomic_open() */
33078 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
33081 + AuDebugOn(!dir->i_op->atomic_open);
33083 + err = au_br_test_oflag(args->open_flag, br);
33084 + if (unlikely(err))
33087 + au_lcnt_inc(&br->br_nfiles);
33088 + file->f_path.dentry = DENTRY_NOT_SET;
33089 + file->f_path.mnt = au_br_mnt(br);
33090 + AuDbg("%ps\n", dir->i_op->atomic_open);
33091 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
33092 + args->create_mode);
33093 + if (unlikely(err < 0)) {
33094 + au_lcnt_dec(&br->br_nfiles);
33098 + /* temporary workaround for nfsv4 branch */
33099 + if (au_test_nfs(dir->i_sb))
33100 + nfs_mark_for_revalidate(dir);
33102 + if (file->f_mode & FMODE_CREATED)
33103 + fsnotify_create(dir, dentry);
33104 + if (!(file->f_mode & FMODE_OPENED)) {
33105 + au_lcnt_dec(&br->br_nfiles);
33109 + /* todo: call VFS:may_open() here */
33110 + /* todo: ima_file_check() too? */
33111 + if (!err && (args->open_flag & __FMODE_EXEC))
33112 + err = deny_write_access(file);
33114 + fsnotify_open(file);
33116 + au_lcnt_dec(&br->br_nfiles);
33117 + /* note that the file is created and still opened */
33123 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
33127 + err = kern_path(name, flags, path);
33128 + if (!err && d_is_positive(path->dentry))
33129 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33133 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33134 + struct path *ppath, int len)
33136 + struct path path;
33138 + path.dentry = lookup_one_len_unlocked(name, ppath->dentry, len);
33139 + if (IS_ERR(path.dentry))
33141 + if (d_is_positive(path.dentry)) {
33142 + path.mnt = ppath->mnt;
33143 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33147 + AuTraceErrPtr(path.dentry);
33148 + return path.dentry;
33151 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33154 + struct path path;
33156 + /* VFS checks it too, but by WARN_ON_ONCE() */
33157 + IMustLock(d_inode(ppath->dentry));
33159 + path.dentry = lookup_one_len(name, ppath->dentry, len);
33160 + if (IS_ERR(path.dentry))
33162 + if (d_is_positive(path.dentry)) {
33163 + path.mnt = ppath->mnt;
33164 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33168 + AuTraceErrPtr(path.dentry);
33169 + return path.dentry;
33172 +void vfsub_call_lkup_one(void *args)
33174 + struct vfsub_lkup_one_args *a = args;
33175 + *a->errp = vfsub_lkup_one(a->name, a->ppath);
33178 +/* ---------------------------------------------------------------------- */
33180 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33181 + struct dentry *d2, struct au_hinode *hdir2)
33183 + struct dentry *d;
33186 + d = lock_rename(d1, d2);
33188 + au_hn_suspend(hdir1);
33189 + if (hdir1 != hdir2)
33190 + au_hn_suspend(hdir2);
33195 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33196 + struct dentry *d2, struct au_hinode *hdir2)
33198 + au_hn_resume(hdir1);
33199 + if (hdir1 != hdir2)
33200 + au_hn_resume(hdir2);
33202 + unlock_rename(d1, d2);
33206 +/* ---------------------------------------------------------------------- */
33208 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
33211 + struct dentry *d;
33212 + struct user_namespace *userns;
33216 + d = path->dentry;
33217 + path->dentry = d->d_parent;
33218 + err = security_path_mknod(path, d, mode, 0);
33219 + path->dentry = d;
33220 + if (unlikely(err))
33222 + userns = mnt_user_ns(path->mnt);
33225 + err = vfs_create(userns, dir, path->dentry, mode, want_excl);
33228 + struct path tmp = *path;
33231 + vfsub_update_h_iattr(&tmp, &did);
33233 + tmp.dentry = path->dentry->d_parent;
33234 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33243 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33246 + struct dentry *d;
33247 + struct user_namespace *userns;
33251 + d = path->dentry;
33252 + path->dentry = d->d_parent;
33253 + err = security_path_symlink(path, d, symname);
33254 + path->dentry = d;
33255 + if (unlikely(err))
33257 + userns = mnt_user_ns(path->mnt);
33260 + err = vfs_symlink(userns, dir, path->dentry, symname);
33263 + struct path tmp = *path;
33266 + vfsub_update_h_iattr(&tmp, &did);
33268 + tmp.dentry = path->dentry->d_parent;
33269 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33278 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33281 + struct dentry *d;
33282 + struct user_namespace *userns;
33286 + d = path->dentry;
33287 + path->dentry = d->d_parent;
33288 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33289 + path->dentry = d;
33290 + if (unlikely(err))
33292 + userns = mnt_user_ns(path->mnt);
33295 + err = vfs_mknod(userns, dir, path->dentry, mode, dev);
33298 + struct path tmp = *path;
33301 + vfsub_update_h_iattr(&tmp, &did);
33303 + tmp.dentry = path->dentry->d_parent;
33304 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33313 +static int au_test_nlink(struct inode *inode)
33315 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33317 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33318 + || inode->i_nlink < link_max)
33323 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33324 + struct inode **delegated_inode)
33327 + struct dentry *d;
33328 + struct user_namespace *userns;
33332 + err = au_test_nlink(d_inode(src_dentry));
33333 + if (unlikely(err))
33336 + /* we don't call may_linkat() */
33337 + d = path->dentry;
33338 + path->dentry = d->d_parent;
33339 + err = security_path_link(src_dentry, path, d);
33340 + path->dentry = d;
33341 + if (unlikely(err))
33343 + userns = mnt_user_ns(path->mnt);
33346 + err = vfs_link(src_dentry, userns, dir, path->dentry, delegated_inode);
33349 + struct path tmp = *path;
33352 + /* fuse has different memory inode for the same inumber */
33353 + vfsub_update_h_iattr(&tmp, &did);
33355 + tmp.dentry = path->dentry->d_parent;
33356 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33357 + tmp.dentry = src_dentry;
33358 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33367 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33368 + struct inode *dir, struct path *path,
33369 + struct inode **delegated_inode, unsigned int flags)
33372 + struct renamedata rd;
33373 + struct path tmp = {
33376 + struct dentry *d;
33379 + IMustLock(src_dir);
33381 + d = path->dentry;
33382 + path->dentry = d->d_parent;
33383 + tmp.dentry = src_dentry->d_parent;
33384 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33385 + path->dentry = d;
33386 + if (unlikely(err))
33389 + rd.old_mnt_userns = mnt_user_ns(path->mnt);
33390 + rd.old_dir = src_dir;
33391 + rd.old_dentry = src_dentry;
33392 + rd.new_mnt_userns = rd.old_mnt_userns;
33393 + rd.new_dir = dir;
33394 + rd.new_dentry = path->dentry;
33395 + rd.delegated_inode = delegated_inode;
33396 + rd.flags = flags;
33398 + err = vfs_rename(&rd);
33403 + tmp.dentry = d->d_parent;
33404 + vfsub_update_h_iattr(&tmp, &did);
33406 + tmp.dentry = src_dentry;
33407 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33408 + tmp.dentry = src_dentry->d_parent;
33409 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33418 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33421 + struct dentry *d;
33422 + struct user_namespace *userns;
33426 + d = path->dentry;
33427 + path->dentry = d->d_parent;
33428 + err = security_path_mkdir(path, d, mode);
33429 + path->dentry = d;
33430 + if (unlikely(err))
33432 + userns = mnt_user_ns(path->mnt);
33435 + err = vfs_mkdir(userns, dir, path->dentry, mode);
33438 + struct path tmp = *path;
33441 + vfsub_update_h_iattr(&tmp, &did);
33443 + tmp.dentry = path->dentry->d_parent;
33444 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33453 +int vfsub_rmdir(struct inode *dir, struct path *path)
33456 + struct dentry *d;
33457 + struct user_namespace *userns;
33461 + d = path->dentry;
33462 + path->dentry = d->d_parent;
33463 + err = security_path_rmdir(path, d);
33464 + path->dentry = d;
33465 + if (unlikely(err))
33467 + userns = mnt_user_ns(path->mnt);
33470 + err = vfs_rmdir(userns, dir, path->dentry);
33473 + struct path tmp = {
33474 + .dentry = path->dentry->d_parent,
33478 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33485 +/* ---------------------------------------------------------------------- */
33487 +/* todo: support mmap_sem? */
33488 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33494 + err = vfs_read(file, ubuf, count, ppos);
33497 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33501 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33507 + err = kernel_read(file, kbuf, count, ppos);
33511 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33515 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33521 + err = vfs_write(file, ubuf, count, ppos);
33524 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33528 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33533 + err = kernel_write(file, kbuf, count, ppos);
33536 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33540 +int vfsub_flush(struct file *file, fl_owner_t id)
33545 + if (file->f_op->flush) {
33546 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33547 + err = file->f_op->flush(file, id);
33550 + err = file->f_op->flush(file, id);
33554 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33560 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33564 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33567 + err = iterate_dir(file, ctx);
33570 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33575 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33576 + struct pipe_inode_info *pipe, size_t len,
33577 + unsigned int flags)
33582 + err = do_splice_to(in, ppos, pipe, len, flags);
33584 + file_accessed(in);
33586 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33590 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33591 + loff_t *ppos, size_t len, unsigned int flags)
33596 + err = do_splice_from(pipe, out, ppos, len, flags);
33599 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33603 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33607 + /* file can be NULL */
33609 + err = vfs_fsync(file, datasync);
33613 + AuDebugOn(!file);
33614 + path = &file->f_path;
33616 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33621 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33622 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33623 + struct file *h_file)
33626 + struct inode *h_inode;
33627 + struct super_block *h_sb;
33628 + struct user_namespace *h_userns;
33631 + err = vfsub_truncate(h_path, length);
33635 + h_inode = d_inode(h_path->dentry);
33636 + h_sb = h_inode->i_sb;
33638 + sb_start_write(h_sb);
33640 + err = security_path_truncate(h_path);
33642 + h_userns = mnt_user_ns(h_path->mnt);
33644 + err = do_truncate(h_userns, h_path->dentry, length, attr,
33649 + sb_end_write(h_sb);
33656 +/* ---------------------------------------------------------------------- */
33658 +struct au_vfsub_mkdir_args {
33660 + struct inode *dir;
33661 + struct path *path;
33665 +static void au_call_vfsub_mkdir(void *args)
33667 + struct au_vfsub_mkdir_args *a = args;
33668 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33671 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33673 + int err, do_sio, wkq_err;
33674 + struct user_namespace *userns;
33676 + userns = mnt_user_ns(path->mnt);
33677 + do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
33680 + err = vfsub_mkdir(dir, path, mode);
33683 + struct au_vfsub_mkdir_args args = {
33689 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33690 + if (unlikely(wkq_err))
33697 +struct au_vfsub_rmdir_args {
33699 + struct inode *dir;
33700 + struct path *path;
33703 +static void au_call_vfsub_rmdir(void *args)
33705 + struct au_vfsub_rmdir_args *a = args;
33706 + *a->errp = vfsub_rmdir(a->dir, a->path);
33709 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33711 + int err, do_sio, wkq_err;
33712 + struct user_namespace *userns;
33714 + userns = mnt_user_ns(path->mnt);
33715 + do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
33718 + err = vfsub_rmdir(dir, path);
33721 + struct au_vfsub_rmdir_args args = {
33726 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33727 + if (unlikely(wkq_err))
33734 +/* ---------------------------------------------------------------------- */
33736 +struct notify_change_args {
33738 + struct path *path;
33739 + struct iattr *ia;
33740 + struct inode **delegated_inode;
33743 +static void call_notify_change(void *args)
33745 + struct notify_change_args *a = args;
33746 + struct inode *h_inode;
33747 + struct user_namespace *userns;
33749 + h_inode = d_inode(a->path->dentry);
33750 + IMustLock(h_inode);
33752 + *a->errp = -EPERM;
33753 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33754 + userns = mnt_user_ns(a->path->mnt);
33756 + *a->errp = notify_change(userns, a->path->dentry, a->ia,
33757 + a->delegated_inode);
33760 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33762 + AuTraceErr(*a->errp);
33765 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33766 + struct inode **delegated_inode)
33769 + struct notify_change_args args = {
33773 + .delegated_inode = delegated_inode
33776 + call_notify_change(&args);
33781 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33782 + struct inode **delegated_inode)
33784 + int err, wkq_err;
33785 + struct notify_change_args args = {
33789 + .delegated_inode = delegated_inode
33792 + wkq_err = au_wkq_wait(call_notify_change, &args);
33793 + if (unlikely(wkq_err))
33799 +/* ---------------------------------------------------------------------- */
33801 +struct unlink_args {
33803 + struct inode *dir;
33804 + struct path *path;
33805 + struct inode **delegated_inode;
33808 +static void call_unlink(void *args)
33810 + struct unlink_args *a = args;
33811 + struct dentry *d = a->path->dentry;
33812 + struct inode *h_inode;
33813 + struct user_namespace *userns;
33814 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33815 + && au_dcount(d) == 1);
33817 + IMustLock(a->dir);
33819 + a->path->dentry = d->d_parent;
33820 + *a->errp = security_path_unlink(a->path, d);
33821 + a->path->dentry = d;
33822 + if (unlikely(*a->errp))
33825 + if (!stop_sillyrename)
33828 + if (d_is_positive(d)) {
33829 + h_inode = d_inode(d);
33833 + userns = mnt_user_ns(a->path->mnt);
33835 + *a->errp = vfs_unlink(userns, a->dir, d, a->delegated_inode);
33838 + struct path tmp = {
33839 + .dentry = d->d_parent,
33840 + .mnt = a->path->mnt
33842 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33845 + if (!stop_sillyrename)
33850 + AuTraceErr(*a->errp);
33854 + * @dir: must be locked.
33855 + * @dentry: target dentry.
33857 +int vfsub_unlink(struct inode *dir, struct path *path,
33858 + struct inode **delegated_inode, int force)
33861 + struct unlink_args args = {
33865 + .delegated_inode = delegated_inode
33869 + call_unlink(&args);
33873 + wkq_err = au_wkq_wait(call_unlink, &args);
33874 + if (unlikely(wkq_err))
33880 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33881 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33882 +++ linux/fs/aufs/vfsub.h 2022-12-17 09:21:34.799855195 +0100
33884 +/* SPDX-License-Identifier: GPL-2.0 */
33886 + * Copyright (C) 2005-2022 Junjiro R. Okajima
33888 + * This program is free software; you can redistribute it and/or modify
33889 + * it under the terms of the GNU General Public License as published by
33890 + * the Free Software Foundation; either version 2 of the License, or
33891 + * (at your option) any later version.
33893 + * This program is distributed in the hope that it will be useful,
33894 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33895 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33896 + * GNU General Public License for more details.
33898 + * You should have received a copy of the GNU General Public License
33899 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33903 + * sub-routines for VFS
33906 +#ifndef __AUFS_VFSUB_H__
33907 +#define __AUFS_VFSUB_H__
33911 +#include <linux/fs.h>
33912 +#include <linux/mount.h>
33913 +#include <linux/posix_acl.h>
33914 +#include <linux/xattr.h>
33915 +#include "debug.h"
33917 +/* copied from linux/fs/internal.h */
33918 +/* todo: BAD approach!! */
33919 +extern void __mnt_drop_write(struct vfsmount *);
33920 +extern struct file *alloc_empty_file(int, const struct cred *);
33922 +/* ---------------------------------------------------------------------- */
33924 +/* lock subclass for lower inode */
33925 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33926 +/* reduce? gave up. */
33928 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33929 + AuLsc_I_PARENT, /* lower inode, parent first */
33930 + AuLsc_I_PARENT2, /* copyup dirs */
33931 + AuLsc_I_PARENT3, /* copyup wh */
33937 +/* to debug easier, do not make them inlined functions */
33938 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33939 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33941 +/* ---------------------------------------------------------------------- */
33943 +static inline void vfsub_drop_nlink(struct inode *inode)
33945 + AuDebugOn(!inode->i_nlink);
33946 + drop_nlink(inode);
33949 +static inline void vfsub_dead_dir(struct inode *inode)
33951 + AuDebugOn(!S_ISDIR(inode->i_mode));
33952 + inode->i_flags |= S_DEAD;
33953 + clear_nlink(inode);
33956 +static inline int vfsub_native_ro(struct inode *inode)
33958 + return sb_rdonly(inode->i_sb)
33959 + || IS_RDONLY(inode)
33960 + /* || IS_APPEND(inode) */
33961 + || IS_IMMUTABLE(inode);
33964 +#ifdef CONFIG_AUFS_BR_FUSE
33965 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33967 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33970 +int vfsub_sync_filesystem(struct super_block *h_sb);
33972 +/* ---------------------------------------------------------------------- */
33974 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33975 +struct file *vfsub_dentry_open(struct path *path, int flags);
33976 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33978 +struct vfsub_aopen_args {
33979 + struct file *file;
33980 + unsigned int open_flag;
33981 + umode_t create_mode;
33982 + struct au_branch *br;
33984 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33985 + struct vfsub_aopen_args *args);
33986 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33988 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33989 + struct path *ppath, int len);
33990 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33993 +struct vfsub_lkup_one_args {
33994 + struct dentry **errp;
33995 + struct qstr *name;
33996 + struct path *ppath;
33999 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
34000 + struct path *ppath)
34002 + return vfsub_lookup_one_len(name->name, ppath, name->len);
34005 +void vfsub_call_lkup_one(void *args);
34007 +/* ---------------------------------------------------------------------- */
34009 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
34014 + err = mnt_want_write(mnt);
34019 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
34022 + mnt_drop_write(mnt);
34026 +#if 0 /* reserved */
34027 +static inline void vfsub_mnt_drop_write_file(struct file *file)
34030 + mnt_drop_write_file(file);
34035 +/* ---------------------------------------------------------------------- */
34038 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
34039 + struct dentry *d2, struct au_hinode *hdir2);
34040 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
34041 + struct dentry *d2, struct au_hinode *hdir2);
34043 +int vfsub_create(struct inode *dir, struct path *path, int mode,
34045 +int vfsub_symlink(struct inode *dir, struct path *path,
34046 + const char *symname);
34047 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
34048 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
34049 + struct path *path, struct inode **delegated_inode);
34050 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
34051 + struct inode *hdir, struct path *path,
34052 + struct inode **delegated_inode, unsigned int flags);
34053 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
34054 +int vfsub_rmdir(struct inode *dir, struct path *path);
34056 +/* ---------------------------------------------------------------------- */
34058 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
34060 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
34062 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
34064 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
34066 +int vfsub_flush(struct file *file, fl_owner_t id);
34067 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
34069 +static inline loff_t vfsub_f_size_read(struct file *file)
34071 + return i_size_read(file_inode(file));
34074 +static inline unsigned int vfsub_file_flags(struct file *file)
34076 + unsigned int flags;
34078 + spin_lock(&file->f_lock);
34079 + flags = file->f_flags;
34080 + spin_unlock(&file->f_lock);
34085 +static inline int vfsub_file_execed(struct file *file)
34087 + /* todo: direct access f_flags */
34088 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
34091 +#if 0 /* reserved */
34092 +static inline void vfsub_file_accessed(struct file *h_file)
34094 + file_accessed(h_file);
34095 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
34099 +#if 0 /* reserved */
34100 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
34101 + struct dentry *h_dentry)
34103 + struct path h_path = {
34104 + .dentry = h_dentry,
34107 + touch_atime(&h_path);
34108 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
34112 +static inline int vfsub_update_time(struct inode *h_inode,
34113 + struct timespec64 *ts, int flags)
34115 + return inode_update_time(h_inode, ts, flags);
34116 + /* no vfsub_update_h_iattr() since we don't have struct path */
34119 +#ifdef CONFIG_FS_POSIX_ACL
34120 +static inline int vfsub_acl_chmod(struct user_namespace *h_userns,
34121 + struct inode *h_inode, umode_t h_mode)
34125 + err = posix_acl_chmod(h_userns, h_inode, h_mode);
34126 + if (err == -EOPNOTSUPP)
34131 +AuStubInt0(vfsub_acl_chmod, struct user_namespace *h_userns,
34132 + struct inode *h_inode, umode_t h_mode);
34135 +long vfsub_splice_to(struct file *in, loff_t *ppos,
34136 + struct pipe_inode_info *pipe, size_t len,
34137 + unsigned int flags);
34138 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
34139 + loff_t *ppos, size_t len, unsigned int flags);
34141 +static inline long vfsub_truncate(struct path *path, loff_t length)
34146 + err = vfs_truncate(path, length);
34151 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
34152 + struct file *h_file);
34153 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
34156 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
34159 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
34165 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
34171 +/* copy_file_range(2) is a systemcall */
34172 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
34173 + struct file *dst, loff_t dst_pos,
34174 + size_t len, unsigned int flags)
34179 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
34185 +/* ---------------------------------------------------------------------- */
34187 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
34192 + err = vfs_llseek(file, offset, origin);
34197 +/* ---------------------------------------------------------------------- */
34199 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
34200 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
34201 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
34202 + struct inode **delegated_inode);
34203 +int vfsub_notify_change(struct path *path, struct iattr *ia,
34204 + struct inode **delegated_inode);
34205 +int vfsub_unlink(struct inode *dir, struct path *path,
34206 + struct inode **delegated_inode, int force);
34208 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
34210 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
34213 +/* ---------------------------------------------------------------------- */
34215 +static inline int vfsub_setxattr(struct user_namespace *userns,
34216 + struct dentry *dentry, const char *name,
34217 + const void *value, size_t size, int flags)
34222 + err = vfs_setxattr(userns, dentry, name, value, size, flags);
34228 +static inline int vfsub_removexattr(struct user_namespace *userns,
34229 + struct dentry *dentry, const char *name)
34234 + err = vfs_removexattr(userns, dentry, name);
34240 +#endif /* __KERNEL__ */
34241 +#endif /* __AUFS_VFSUB_H__ */
34242 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
34243 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
34244 +++ linux/fs/aufs/wbr_policy.c 2022-11-05 23:02:18.969222617 +0100
34246 +// SPDX-License-Identifier: GPL-2.0
34248 + * Copyright (C) 2005-2022 Junjiro R. Okajima
34250 + * This program is free software; you can redistribute it and/or modify
34251 + * it under the terms of the GNU General Public License as published by
34252 + * the Free Software Foundation; either version 2 of the License, or
34253 + * (at your option) any later version.
34255 + * This program is distributed in the hope that it will be useful,
34256 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34257 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34258 + * GNU General Public License for more details.
34260 + * You should have received a copy of the GNU General Public License
34261 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34265 + * policies for selecting one among multiple writable branches
34268 +#include <linux/statfs.h>
34271 +/* subset of cpup_attr() */
34272 +static noinline_for_stack
34273 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34277 + struct inode *h_isrc;
34279 + h_isrc = d_inode(h_src);
34280 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34281 + ia.ia_mode = h_isrc->i_mode;
34282 + ia.ia_uid = h_isrc->i_uid;
34283 + ia.ia_gid = h_isrc->i_gid;
34284 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34285 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34286 + /* no delegation since it is just created */
34287 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34289 + /* is this nfs only? */
34290 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34291 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34292 + ia.ia_mode = h_isrc->i_mode;
34293 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34299 +#define AuCpdown_PARENT_OPQ 1
34300 +#define AuCpdown_WHED (1 << 1)
34301 +#define AuCpdown_MADE_DIR (1 << 2)
34302 +#define AuCpdown_DIROPQ (1 << 3)
34303 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34304 +#define au_fset_cpdown(flags, name) \
34305 + do { (flags) |= AuCpdown_##name; } while (0)
34306 +#define au_fclr_cpdown(flags, name) \
34307 + do { (flags) &= ~AuCpdown_##name; } while (0)
34309 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34310 + unsigned int *flags)
34313 + struct dentry *opq_dentry;
34315 + opq_dentry = au_diropq_create(dentry, bdst);
34316 + err = PTR_ERR(opq_dentry);
34317 + if (IS_ERR(opq_dentry))
34319 + dput(opq_dentry);
34320 + au_fset_cpdown(*flags, DIROPQ);
34326 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34327 + struct inode *dir, aufs_bindex_t bdst)
34330 + struct path h_path;
34331 + struct au_branch *br;
34333 + br = au_sbr(dentry->d_sb, bdst);
34334 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34335 + err = PTR_ERR(h_path.dentry);
34336 + if (IS_ERR(h_path.dentry))
34340 + if (d_is_positive(h_path.dentry)) {
34341 + h_path.mnt = au_br_mnt(br);
34342 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34345 + dput(h_path.dentry);
34351 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34352 + struct au_pin *pin,
34353 + struct dentry *h_parent, void *arg)
34356 + aufs_bindex_t bopq, btop;
34357 + struct path h_path;
34358 + struct dentry *parent;
34359 + struct inode *h_dir, *h_inode, *inode, *dir;
34360 + unsigned int *flags = arg;
34362 + btop = au_dbtop(dentry);
34363 + /* dentry is di-locked */
34364 + parent = dget_parent(dentry);
34365 + dir = d_inode(parent);
34366 + h_dir = d_inode(h_parent);
34367 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34368 + IMustLock(h_dir);
34370 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34371 + if (unlikely(err < 0))
34373 + h_path.dentry = au_h_dptr(dentry, bdst);
34374 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34375 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34376 + if (unlikely(err))
34378 + au_fset_cpdown(*flags, MADE_DIR);
34380 + bopq = au_dbdiropq(dentry);
34381 + au_fclr_cpdown(*flags, WHED);
34382 + au_fclr_cpdown(*flags, DIROPQ);
34383 + if (au_dbwh(dentry) == bdst)
34384 + au_fset_cpdown(*flags, WHED);
34385 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34386 + au_fset_cpdown(*flags, PARENT_OPQ);
34387 + h_inode = d_inode(h_path.dentry);
34388 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34389 + if (au_ftest_cpdown(*flags, WHED)) {
34390 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34391 + if (unlikely(err)) {
34392 + inode_unlock(h_inode);
34397 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34398 + inode_unlock(h_inode);
34399 + if (unlikely(err))
34402 + if (au_ftest_cpdown(*flags, WHED)) {
34403 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34404 + if (unlikely(err))
34408 + inode = d_inode(dentry);
34409 + if (au_ibbot(inode) < bdst)
34410 + au_set_ibbot(inode, bdst);
34411 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34412 + au_hi_flags(inode, /*isdir*/1));
34413 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34414 + goto out; /* success */
34418 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34419 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34420 + rerr = au_diropq_remove(dentry, bdst);
34421 + inode_unlock(h_inode);
34422 + if (unlikely(rerr)) {
34423 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34424 + dentry, bdst, rerr);
34430 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34431 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34432 + if (unlikely(rerr)) {
34433 + AuIOErr("failed removing %pd b%d (%d)\n",
34434 + dentry, bdst, rerr);
34439 + au_set_h_dptr(dentry, bdst, NULL);
34440 + if (au_dbbot(dentry) == bdst)
34441 + au_update_dbbot(dentry);
34447 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34450 + unsigned int flags;
34453 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34458 +/* ---------------------------------------------------------------------- */
34460 +/* policies for create */
34462 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34464 + int err, i, j, ndentry;
34465 + aufs_bindex_t bopq;
34466 + struct au_dcsub_pages dpages;
34467 + struct au_dpage *dpage;
34468 + struct dentry **dentries, *parent, *d;
34470 + err = au_dpages_init(&dpages, GFP_NOFS);
34471 + if (unlikely(err))
34473 + parent = dget_parent(dentry);
34474 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34475 + if (unlikely(err))
34479 + for (i = 0; i < dpages.ndpage; i++) {
34480 + dpage = dpages.dpages + i;
34481 + dentries = dpage->dentries;
34482 + ndentry = dpage->ndentry;
34483 + for (j = 0; j < ndentry; j++) {
34485 + di_read_lock_parent2(d, !AuLock_IR);
34486 + bopq = au_dbdiropq(d);
34487 + di_read_unlock(d, !AuLock_IR);
34488 + if (bopq >= 0 && bopq < err)
34495 + au_dpages_free(&dpages);
34500 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34502 + for (; bindex >= 0; bindex--)
34503 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34508 +/* top down parent */
34509 +static int au_wbr_create_tdp(struct dentry *dentry,
34510 + unsigned int flags __maybe_unused)
34513 + aufs_bindex_t btop, bindex;
34514 + struct super_block *sb;
34515 + struct dentry *parent, *h_parent;
34517 + sb = dentry->d_sb;
34518 + btop = au_dbtop(dentry);
34520 + if (!au_br_rdonly(au_sbr(sb, btop)))
34524 + parent = dget_parent(dentry);
34525 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34526 + h_parent = au_h_dptr(parent, bindex);
34527 + if (!h_parent || d_is_negative(h_parent))
34530 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34537 + /* bottom up here */
34538 + if (unlikely(err < 0)) {
34539 + err = au_wbr_bu(sb, btop - 1);
34541 + err = au_wbr_nonopq(dentry, err);
34545 + AuDbg("b%d\n", err);
34549 +/* ---------------------------------------------------------------------- */
34551 +/* an exception for the policy other than tdp */
34552 +static int au_wbr_create_exp(struct dentry *dentry)
34555 + aufs_bindex_t bwh, bdiropq;
34556 + struct dentry *parent;
34559 + bwh = au_dbwh(dentry);
34560 + parent = dget_parent(dentry);
34561 + bdiropq = au_dbdiropq(parent);
34563 + if (bdiropq >= 0)
34564 + err = min(bdiropq, bwh);
34567 + AuDbg("%d\n", err);
34568 + } else if (bdiropq >= 0) {
34570 + AuDbg("%d\n", err);
34575 + err = au_wbr_nonopq(dentry, err);
34577 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34580 + AuDbg("%d\n", err);
34584 +/* ---------------------------------------------------------------------- */
34587 +static int au_wbr_create_init_rr(struct super_block *sb)
34591 + err = au_wbr_bu(sb, au_sbbot(sb));
34592 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34595 + AuDbg("b%d\n", err);
34599 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34603 + aufs_bindex_t bindex, bbot;
34604 + struct super_block *sb;
34607 + err = au_wbr_create_exp(dentry);
34611 + sb = dentry->d_sb;
34612 + next = &au_sbi(sb)->si_wbr_rr_next;
34613 + bbot = au_sbbot(sb);
34615 + for (bindex = 0; bindex <= bbot; bindex++) {
34616 + if (!au_ftest_wbr(flags, DIR)) {
34617 + err = atomic_dec_return(next) + 1;
34618 + /* modulo for 0 is meaningless */
34619 + if (unlikely(!err))
34620 + err = atomic_dec_return(next) + 1;
34622 + err = atomic_read(next);
34623 + AuDbg("%d\n", err);
34626 + AuDbg("%d\n", err);
34627 + if (!au_br_rdonly(au_sbr(sb, err)))
34633 + err = au_wbr_nonopq(dentry, err);
34636 + AuDbg("%d\n", err);
34640 +/* ---------------------------------------------------------------------- */
34642 +/* most free space */
34643 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34645 + struct super_block *sb;
34646 + struct au_branch *br;
34647 + struct au_wbr_mfs *mfs;
34648 + struct dentry *h_parent;
34649 + aufs_bindex_t bindex, bbot;
34651 + unsigned long long b, bavail;
34652 + struct path h_path;
34653 + /* reduce the stack usage */
34654 + struct kstatfs *st;
34656 + st = kmalloc(sizeof(*st), GFP_NOFS);
34657 + if (unlikely(!st)) {
34658 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34663 + sb = dentry->d_sb;
34664 + mfs = &au_sbi(sb)->si_wbr_mfs;
34665 + MtxMustLock(&mfs->mfs_lock);
34666 + mfs->mfs_bindex = -EROFS;
34667 + mfs->mfsrr_bytes = 0;
34670 + bbot = au_sbbot(sb);
34672 + bindex = au_dbtop(parent);
34673 + bbot = au_dbtaildir(parent);
34676 + for (; bindex <= bbot; bindex++) {
34678 + h_parent = au_h_dptr(parent, bindex);
34679 + if (!h_parent || d_is_negative(h_parent))
34682 + br = au_sbr(sb, bindex);
34683 + if (au_br_rdonly(br))
34686 + /* sb->s_root for NFS is unreliable */
34687 + h_path.mnt = au_br_mnt(br);
34688 + h_path.dentry = h_path.mnt->mnt_root;
34689 + err = vfs_statfs(&h_path, st);
34690 + if (unlikely(err)) {
34691 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34695 + /* when the available size is equal, select the lower one */
34696 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34697 + || sizeof(b) < sizeof(st->f_bsize));
34698 + b = st->f_bavail * st->f_bsize;
34699 + br->br_wbr->wbr_bytes = b;
34700 + if (b >= bavail) {
34702 + mfs->mfs_bindex = bindex;
34703 + mfs->mfs_jiffy = jiffies;
34707 + mfs->mfsrr_bytes = bavail;
34708 + AuDbg("b%d\n", mfs->mfs_bindex);
34709 + au_kfree_rcu(st);
34712 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34715 + struct dentry *parent;
34716 + struct super_block *sb;
34717 + struct au_wbr_mfs *mfs;
34719 + err = au_wbr_create_exp(dentry);
34723 + sb = dentry->d_sb;
34725 + if (au_ftest_wbr(flags, PARENT))
34726 + parent = dget_parent(dentry);
34727 + mfs = &au_sbi(sb)->si_wbr_mfs;
34728 + mutex_lock(&mfs->mfs_lock);
34729 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34730 + || mfs->mfs_bindex < 0
34731 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34732 + au_mfs(dentry, parent);
34733 + mutex_unlock(&mfs->mfs_lock);
34734 + err = mfs->mfs_bindex;
34738 + err = au_wbr_nonopq(dentry, err);
34741 + AuDbg("b%d\n", err);
34745 +static int au_wbr_create_init_mfs(struct super_block *sb)
34747 + struct au_wbr_mfs *mfs;
34749 + mfs = &au_sbi(sb)->si_wbr_mfs;
34750 + mutex_init(&mfs->mfs_lock);
34751 + mfs->mfs_jiffy = 0;
34752 + mfs->mfs_bindex = -EROFS;
34757 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34759 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34763 +/* ---------------------------------------------------------------------- */
34765 +/* top down regardless parent, and then mfs */
34766 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34767 + unsigned int flags __maybe_unused)
34770 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34771 + unsigned long long watermark;
34772 + struct super_block *sb;
34773 + struct au_wbr_mfs *mfs;
34774 + struct au_branch *br;
34775 + struct dentry *parent;
34777 + sb = dentry->d_sb;
34778 + mfs = &au_sbi(sb)->si_wbr_mfs;
34779 + mutex_lock(&mfs->mfs_lock);
34780 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34781 + || mfs->mfs_bindex < 0)
34782 + au_mfs(dentry, /*parent*/NULL);
34783 + watermark = mfs->mfsrr_watermark;
34784 + bmfs = mfs->mfs_bindex;
34785 + mutex_unlock(&mfs->mfs_lock);
34787 + /* another style of au_wbr_create_exp() */
34788 + bwh = au_dbwh(dentry);
34789 + parent = dget_parent(dentry);
34790 + btail = au_dbtaildir(parent);
34791 + if (bwh >= 0 && bwh < btail)
34794 + err = au_wbr_nonopq(dentry, btail);
34795 + if (unlikely(err < 0))
34799 + for (bindex = 0; bindex <= btail; bindex++) {
34800 + br = au_sbr(sb, bindex);
34801 + if (au_br_rdonly(br))
34803 + if (br->br_wbr->wbr_bytes > watermark) {
34814 + AuDbg("b%d\n", err);
34818 +/* ---------------------------------------------------------------------- */
34820 +/* most free space and then round robin */
34821 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34824 + struct au_wbr_mfs *mfs;
34826 + err = au_wbr_create_mfs(dentry, flags);
34828 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34829 + mutex_lock(&mfs->mfs_lock);
34830 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34831 + err = au_wbr_create_rr(dentry, flags);
34832 + mutex_unlock(&mfs->mfs_lock);
34835 + AuDbg("b%d\n", err);
34839 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34843 + au_wbr_create_init_mfs(sb); /* ignore */
34844 + err = au_wbr_create_init_rr(sb);
34849 +/* ---------------------------------------------------------------------- */
34851 +/* top down parent and most free space */
34852 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34855 + unsigned long long b;
34856 + aufs_bindex_t bindex, btop, bbot;
34857 + struct super_block *sb;
34858 + struct dentry *parent, *h_parent;
34859 + struct au_branch *br;
34861 + err = au_wbr_create_tdp(dentry, flags);
34862 + if (unlikely(err < 0))
34864 + parent = dget_parent(dentry);
34865 + btop = au_dbtop(parent);
34866 + bbot = au_dbtaildir(parent);
34867 + if (btop == bbot)
34868 + goto out_parent; /* success */
34870 + e2 = au_wbr_create_mfs(dentry, flags);
34872 + goto out_parent; /* success */
34874 + /* when the available size is equal, select upper one */
34875 + sb = dentry->d_sb;
34876 + br = au_sbr(sb, err);
34877 + b = br->br_wbr->wbr_bytes;
34878 + AuDbg("b%d, %llu\n", err, b);
34880 + for (bindex = btop; bindex <= bbot; bindex++) {
34881 + h_parent = au_h_dptr(parent, bindex);
34882 + if (!h_parent || d_is_negative(h_parent))
34885 + br = au_sbr(sb, bindex);
34886 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34887 + b = br->br_wbr->wbr_bytes;
34889 + AuDbg("b%d, %llu\n", err, b);
34894 + err = au_wbr_nonopq(dentry, err);
34899 + AuDbg("b%d\n", err);
34903 +/* ---------------------------------------------------------------------- */
34906 + * - top down parent
34907 + * - most free space with parent
34908 + * - most free space round-robin regardless parent
34910 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34913 + unsigned long long watermark;
34914 + struct super_block *sb;
34915 + struct au_branch *br;
34916 + struct au_wbr_mfs *mfs;
34918 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34919 + if (unlikely(err < 0))
34922 + sb = dentry->d_sb;
34923 + br = au_sbr(sb, err);
34924 + mfs = &au_sbi(sb)->si_wbr_mfs;
34925 + mutex_lock(&mfs->mfs_lock);
34926 + watermark = mfs->mfsrr_watermark;
34927 + mutex_unlock(&mfs->mfs_lock);
34928 + if (br->br_wbr->wbr_bytes < watermark)
34929 + /* regardless the parent dir */
34930 + err = au_wbr_create_mfsrr(dentry, flags);
34933 + AuDbg("b%d\n", err);
34937 +/* ---------------------------------------------------------------------- */
34939 +/* policies for copyup */
34941 +/* top down parent */
34942 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34944 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34947 +/* bottom up parent */
34948 +static int au_wbr_copyup_bup(struct dentry *dentry)
34951 + aufs_bindex_t bindex, btop;
34952 + struct dentry *parent, *h_parent;
34953 + struct super_block *sb;
34956 + sb = dentry->d_sb;
34957 + parent = dget_parent(dentry);
34958 + btop = au_dbtop(parent);
34959 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34960 + h_parent = au_h_dptr(parent, bindex);
34961 + if (!h_parent || d_is_negative(h_parent))
34964 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34971 + /* bottom up here */
34972 + if (unlikely(err < 0))
34973 + err = au_wbr_bu(sb, btop - 1);
34975 + AuDbg("b%d\n", err);
34980 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34984 + err = au_wbr_bu(dentry->d_sb, btop);
34985 + AuDbg("b%d\n", err);
34987 + err = au_wbr_nonopq(dentry, err);
34989 + AuDbg("b%d\n", err);
34993 +static int au_wbr_copyup_bu(struct dentry *dentry)
34996 + aufs_bindex_t btop;
34998 + btop = au_dbtop(dentry);
34999 + err = au_wbr_do_copyup_bu(dentry, btop);
35003 +/* ---------------------------------------------------------------------- */
35005 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
35006 + [AuWbrCopyup_TDP] = {
35007 + .copyup = au_wbr_copyup_tdp
35009 + [AuWbrCopyup_BUP] = {
35010 + .copyup = au_wbr_copyup_bup
35012 + [AuWbrCopyup_BU] = {
35013 + .copyup = au_wbr_copyup_bu
35017 +struct au_wbr_create_operations au_wbr_create_ops[] = {
35018 + [AuWbrCreate_TDP] = {
35019 + .create = au_wbr_create_tdp
35021 + [AuWbrCreate_RR] = {
35022 + .create = au_wbr_create_rr,
35023 + .init = au_wbr_create_init_rr
35025 + [AuWbrCreate_MFS] = {
35026 + .create = au_wbr_create_mfs,
35027 + .init = au_wbr_create_init_mfs,
35028 + .fin = au_wbr_create_fin_mfs
35030 + [AuWbrCreate_MFSV] = {
35031 + .create = au_wbr_create_mfs,
35032 + .init = au_wbr_create_init_mfs,
35033 + .fin = au_wbr_create_fin_mfs
35035 + [AuWbrCreate_MFSRR] = {
35036 + .create = au_wbr_create_mfsrr,
35037 + .init = au_wbr_create_init_mfsrr,
35038 + .fin = au_wbr_create_fin_mfs
35040 + [AuWbrCreate_MFSRRV] = {
35041 + .create = au_wbr_create_mfsrr,
35042 + .init = au_wbr_create_init_mfsrr,
35043 + .fin = au_wbr_create_fin_mfs
35045 + [AuWbrCreate_TDMFS] = {
35046 + .create = au_wbr_create_tdmfs,
35047 + .init = au_wbr_create_init_mfs,
35048 + .fin = au_wbr_create_fin_mfs
35050 + [AuWbrCreate_TDMFSV] = {
35051 + .create = au_wbr_create_tdmfs,
35052 + .init = au_wbr_create_init_mfs,
35053 + .fin = au_wbr_create_fin_mfs
35055 + [AuWbrCreate_PMFS] = {
35056 + .create = au_wbr_create_pmfs,
35057 + .init = au_wbr_create_init_mfs,
35058 + .fin = au_wbr_create_fin_mfs
35060 + [AuWbrCreate_PMFSV] = {
35061 + .create = au_wbr_create_pmfs,
35062 + .init = au_wbr_create_init_mfs,
35063 + .fin = au_wbr_create_fin_mfs
35065 + [AuWbrCreate_PMFSRR] = {
35066 + .create = au_wbr_create_pmfsrr,
35067 + .init = au_wbr_create_init_mfsrr,
35068 + .fin = au_wbr_create_fin_mfs
35070 + [AuWbrCreate_PMFSRRV] = {
35071 + .create = au_wbr_create_pmfsrr,
35072 + .init = au_wbr_create_init_mfsrr,
35073 + .fin = au_wbr_create_fin_mfs
35076 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
35077 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
35078 +++ linux/fs/aufs/whout.c 2022-11-05 23:02:18.972555950 +0100
35080 +// SPDX-License-Identifier: GPL-2.0
35082 + * Copyright (C) 2005-2022 Junjiro R. Okajima
35084 + * This program is free software; you can redistribute it and/or modify
35085 + * it under the terms of the GNU General Public License as published by
35086 + * the Free Software Foundation; either version 2 of the License, or
35087 + * (at your option) any later version.
35089 + * This program is distributed in the hope that it will be useful,
35090 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35091 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35092 + * GNU General Public License for more details.
35094 + * You should have received a copy of the GNU General Public License
35095 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35099 + * whiteout for logical deletion and opaque directory
35104 +#define WH_MASK 0444
35107 + * If a directory contains this file, then it is opaque. We start with the
35108 + * .wh. flag so that it is blocked by lookup.
35110 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
35111 + sizeof(AUFS_WH_DIROPQ) - 1);
35114 + * generate whiteout name, which is NOT terminated by NULL.
35115 + * @name: original d_name.name
35116 + * @len: original d_name.len
35117 + * @wh: whiteout qstr
35118 + * returns zero when succeeds, otherwise error.
35119 + * succeeded value as wh->name should be freed by kfree().
35121 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
35125 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
35126 + return -ENAMETOOLONG;
35128 + wh->len = name->len + AUFS_WH_PFX_LEN;
35129 + p = kmalloc(wh->len, GFP_NOFS);
35132 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35133 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
35140 +/* ---------------------------------------------------------------------- */
35143 + * test if the @wh_name exists under @h_ppath.
35144 + * @try_sio specifies the necessary of super-io.
35146 +int au_wh_test(struct user_namespace *h_userns, struct path *h_ppath,
35147 + struct qstr *wh_name, int try_sio)
35150 + struct dentry *wh_dentry;
35153 + wh_dentry = vfsub_lkup_one(wh_name, h_ppath);
35155 + wh_dentry = au_sio_lkup_one(h_userns, wh_name, h_ppath);
35156 + err = PTR_ERR(wh_dentry);
35157 + if (IS_ERR(wh_dentry)) {
35158 + if (err == -ENAMETOOLONG)
35164 + if (d_is_negative(wh_dentry))
35165 + goto out_wh; /* success */
35168 + if (d_is_reg(wh_dentry))
35169 + goto out_wh; /* success */
35172 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
35173 + wh_dentry, d_inode(wh_dentry)->i_mode);
35182 + * test if the @h_path->dentry sets opaque or not.
35184 +int au_diropq_test(struct user_namespace *h_userns, struct path *h_path)
35187 + struct inode *h_dir;
35189 + h_dir = d_inode(h_path->dentry);
35190 + err = au_wh_test(h_userns, h_path, &diropq_name,
35191 + au_test_h_perm_sio(h_userns, h_dir, MAY_EXEC));
35196 + * returns a negative dentry whose name is unique and temporary.
35198 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35199 + struct qstr *prefix)
35201 + struct dentry *dentry;
35203 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
35205 + /* strict atomic_t is unnecessary here */
35206 + static unsigned short cnt;
35208 + struct path h_ppath;
35209 + struct user_namespace *h_userns;
35211 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
35214 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
35215 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
35216 + dentry = ERR_PTR(-ENAMETOOLONG);
35217 + if (unlikely(qs.len > NAME_MAX))
35219 + dentry = ERR_PTR(-ENOMEM);
35220 + name = kmalloc(qs.len + 1, GFP_NOFS);
35221 + if (unlikely(!name))
35225 + /* doubly whiteout-ed */
35226 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
35227 + p = name + AUFS_WH_PFX_LEN * 2;
35228 + memcpy(p, prefix->name, prefix->len);
35229 + p += prefix->len;
35231 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
35233 + h_ppath.dentry = h_parent;
35234 + h_ppath.mnt = au_br_mnt(br);
35235 + h_userns = au_br_userns(br);
35237 + for (i = 0; i < 3; i++) {
35238 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
35239 + dentry = au_sio_lkup_one(h_userns, &qs, &h_ppath);
35240 + if (IS_ERR(dentry) || d_is_negative(dentry))
35244 + /* pr_warn("could not get random name\n"); */
35245 + dentry = ERR_PTR(-EEXIST);
35246 + AuDbg("%.*s\n", AuLNPair(&qs));
35250 + if (name != defname)
35251 + au_kfree_try_rcu(name);
35253 + AuTraceErrPtr(dentry);
35258 + * rename the @h_dentry on @br to the whiteouted temporary name.
35260 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
35263 + struct path h_path = {
35264 + .mnt = au_br_mnt(br)
35266 + struct inode *h_dir, *delegated;
35267 + struct dentry *h_parent;
35269 + h_parent = h_dentry->d_parent; /* dir inode is locked */
35270 + h_dir = d_inode(h_parent);
35271 + IMustLock(h_dir);
35273 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35274 + err = PTR_ERR(h_path.dentry);
35275 + if (IS_ERR(h_path.dentry))
35278 + /* under the same dir, no need to lock_rename() */
35279 + delegated = NULL;
35280 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35283 + if (unlikely(err == -EWOULDBLOCK)) {
35284 + pr_warn("cannot retry for NFSv4 delegation"
35285 + " for an internal rename\n");
35288 + dput(h_path.dentry);
35295 +/* ---------------------------------------------------------------------- */
35297 + * functions for removing a whiteout
35300 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35303 + struct inode *delegated;
35306 + * forces superio when the dir has a sticky bit.
35307 + * this may be a violation of unix fs semantics.
35309 + force = (h_dir->i_mode & S_ISVTX)
35310 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35311 + delegated = NULL;
35312 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35313 + if (unlikely(err == -EWOULDBLOCK)) {
35314 + pr_warn("cannot retry for NFSv4 delegation"
35315 + " for an internal unlink\n");
35321 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35322 + struct dentry *dentry)
35326 + err = do_unlink_wh(h_dir, h_path);
35327 + if (!err && dentry)
35328 + au_set_dbwh(dentry, -1);
35333 +static int unlink_wh_name(struct path *h_ppath, struct qstr *wh)
35336 + struct path h_path;
35339 + h_path.dentry = vfsub_lkup_one(wh, h_ppath);
35340 + if (IS_ERR(h_path.dentry))
35341 + err = PTR_ERR(h_path.dentry);
35343 + if (d_is_reg(h_path.dentry)) {
35344 + h_path.mnt = h_ppath->mnt;
35345 + err = do_unlink_wh(d_inode(h_ppath->dentry), &h_path);
35347 + dput(h_path.dentry);
35353 +/* ---------------------------------------------------------------------- */
35355 + * initialize/clean whiteout for a branch
35358 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35362 + struct inode *delegated;
35364 + if (d_is_negative(whpath->dentry))
35368 + err = vfsub_rmdir(h_dir, whpath);
35370 + delegated = NULL;
35371 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35372 + if (unlikely(err == -EWOULDBLOCK)) {
35373 + pr_warn("cannot retry for NFSv4 delegation"
35374 + " for an internal unlink\n");
35378 + if (unlikely(err))
35379 + pr_warn("failed removing %pd (%d), ignored.\n",
35380 + whpath->dentry, err);
35383 +static int test_linkable(struct dentry *h_root)
35385 + struct inode *h_dir = d_inode(h_root);
35387 + if (h_dir->i_op->link)
35390 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35391 + h_root, au_sbtype(h_root->d_sb));
35392 + return -ENOSYS; /* the branch doesn't have its ->link() */
35395 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35396 +static int au_whdir(struct inode *h_dir, struct path *path)
35401 + if (d_is_negative(path->dentry)) {
35404 + if (au_test_nfs(path->dentry->d_sb))
35406 + err = vfsub_mkdir(h_dir, path, mode);
35407 + } else if (d_is_dir(path->dentry))
35410 + pr_err("unknown %pd exists\n", path->dentry);
35415 +struct au_wh_base {
35416 + const struct qstr *name;
35417 + struct dentry *dentry;
35420 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35421 + struct path *h_path)
35423 + h_path->dentry = base[AuBrWh_BASE].dentry;
35424 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35425 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35426 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35427 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35428 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35432 + * returns tri-state,
35433 + * minus: error, caller should print the message
35435 + * plus: error, caller should NOT print the message
35437 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35438 + int do_plink, struct au_wh_base base[],
35439 + struct path *h_path)
35442 + struct inode *h_dir;
35444 + h_dir = d_inode(h_root);
35445 + h_path->dentry = base[AuBrWh_BASE].dentry;
35446 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35447 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35449 + err = test_linkable(h_root);
35450 + if (unlikely(err)) {
35455 + err = au_whdir(h_dir, h_path);
35456 + if (unlikely(err))
35458 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35460 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35461 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35462 + err = au_whdir(h_dir, h_path);
35463 + if (unlikely(err))
35465 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35472 + * for the moment, aufs supports the branch filesystem which does not support
35473 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35474 + * copyup failed. finally, such filesystem will not be used as the writable
35477 + * returns tri-state, see above.
35479 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35480 + int do_plink, struct au_wh_base base[],
35481 + struct path *h_path)
35484 + struct inode *h_dir;
35486 + WbrWhMustWriteLock(wbr);
35488 + err = test_linkable(h_root);
35489 + if (unlikely(err)) {
35495 + * todo: should this create be done in /sbin/mount.aufs helper?
35498 + h_dir = d_inode(h_root);
35499 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35500 + h_path->dentry = base[AuBrWh_BASE].dentry;
35501 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35502 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35505 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35506 + if (unlikely(err))
35509 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35511 + err = au_whdir(h_dir, h_path);
35512 + if (unlikely(err))
35514 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35516 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35517 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35519 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35520 + err = au_whdir(h_dir, h_path);
35521 + if (unlikely(err))
35523 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35530 + * initialize the whiteout base file/dir for @br.
35532 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35535 + const unsigned char do_plink
35536 + = !!au_opt_test(au_mntflags(sb), PLINK);
35537 + struct inode *h_dir;
35538 + struct path path = br->br_path;
35539 + struct dentry *h_root = path.dentry;
35540 + struct au_wbr *wbr = br->br_wbr;
35541 + static const struct qstr base_name[] = {
35542 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35543 + sizeof(AUFS_BASE_NAME) - 1),
35544 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35545 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35546 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35547 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35549 + struct au_wh_base base[] = {
35550 + [AuBrWh_BASE] = {
35551 + .name = base_name + AuBrWh_BASE,
35554 + [AuBrWh_PLINK] = {
35555 + .name = base_name + AuBrWh_PLINK,
35558 + [AuBrWh_ORPH] = {
35559 + .name = base_name + AuBrWh_ORPH,
35565 + WbrWhMustWriteLock(wbr);
35567 + for (i = 0; i < AuBrWh_Last; i++) {
35568 + /* doubly whiteouted */
35569 + struct dentry *d;
35571 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35572 + err = PTR_ERR(d);
35576 + base[i].dentry = d;
35578 + && wbr->wbr_wh[i]
35579 + && wbr->wbr_wh[i] != base[i].dentry);
35583 + for (i = 0; i < AuBrWh_Last; i++) {
35584 + dput(wbr->wbr_wh[i]);
35585 + wbr->wbr_wh[i] = NULL;
35589 + if (!au_br_writable(br->br_perm)) {
35590 + h_dir = d_inode(h_root);
35591 + au_wh_init_ro(h_dir, base, &path);
35592 + } else if (!au_br_wh_linkable(br->br_perm)) {
35593 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35599 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35605 + goto out; /* success */
35608 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35609 + err, h_root, au_sbtype(h_root->d_sb));
35611 + for (i = 0; i < AuBrWh_Last; i++)
35612 + dput(base[i].dentry);
35616 +/* ---------------------------------------------------------------------- */
35618 + * whiteouts are all hard-linked usually.
35619 + * when its link count reaches a ceiling, we create a new whiteout base
35620 + * asynchronously.
35623 +struct reinit_br_wh {
35624 + struct super_block *sb;
35625 + struct au_branch *br;
35628 +static void reinit_br_wh(void *arg)
35631 + aufs_bindex_t bindex;
35632 + struct path h_path;
35633 + struct reinit_br_wh *a = arg;
35634 + struct au_wbr *wbr;
35635 + struct inode *dir, *delegated;
35636 + struct dentry *h_root;
35637 + struct au_hinode *hdir;
35640 + wbr = a->br->br_wbr;
35641 + /* big aufs lock */
35642 + si_noflush_write_lock(a->sb);
35643 + if (!au_br_writable(a->br->br_perm))
35645 + bindex = au_br_index(a->sb, a->br->br_id);
35646 + if (unlikely(bindex < 0))
35649 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35650 + dir = d_inode(a->sb->s_root);
35651 + hdir = au_hi(dir, bindex);
35652 + h_root = au_h_dptr(a->sb->s_root, bindex);
35653 + AuDebugOn(h_root != au_br_dentry(a->br));
35655 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35656 + wbr_wh_write_lock(wbr);
35657 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35660 + h_path.dentry = wbr->wbr_whbase;
35661 + h_path.mnt = au_br_mnt(a->br);
35662 + delegated = NULL;
35663 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35665 + if (unlikely(err == -EWOULDBLOCK)) {
35666 + pr_warn("cannot retry for NFSv4 delegation"
35667 + " for an internal unlink\n");
35671 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35674 + dput(wbr->wbr_whbase);
35675 + wbr->wbr_whbase = NULL;
35677 + err = au_wh_init(a->br, a->sb);
35678 + wbr_wh_write_unlock(wbr);
35679 + au_hn_inode_unlock(hdir);
35680 + di_read_unlock(a->sb->s_root, AuLock_IR);
35682 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35686 + atomic_dec(&wbr->wbr_wh_running);
35687 + au_lcnt_dec(&a->br->br_count);
35688 + si_write_unlock(a->sb);
35689 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35691 + if (unlikely(err))
35692 + AuIOErr("err %d\n", err);
35695 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35697 + int do_dec, wkq_err;
35698 + struct reinit_br_wh *arg;
35701 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35704 + /* ignore ENOMEM */
35705 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35708 + * dec(wh_running), kfree(arg) and dec(br_count)
35709 + * in reinit function
35713 + au_lcnt_inc(&br->br_count);
35714 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35715 + if (unlikely(wkq_err)) {
35716 + atomic_dec(&br->br_wbr->wbr_wh_running);
35717 + au_lcnt_dec(&br->br_count);
35718 + au_kfree_rcu(arg);
35725 + atomic_dec(&br->br_wbr->wbr_wh_running);
35728 +/* ---------------------------------------------------------------------- */
35731 + * create the whiteout @wh.
35733 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35734 + struct dentry *wh)
35737 + struct path h_path = {
35740 + struct au_branch *br;
35741 + struct au_wbr *wbr;
35742 + struct dentry *h_parent;
35743 + struct inode *h_dir, *delegated;
35745 + h_parent = wh->d_parent; /* dir inode is locked */
35746 + h_dir = d_inode(h_parent);
35747 + IMustLock(h_dir);
35749 + br = au_sbr(sb, bindex);
35750 + h_path.mnt = au_br_mnt(br);
35751 + wbr = br->br_wbr;
35752 + wbr_wh_read_lock(wbr);
35753 + if (wbr->wbr_whbase) {
35754 + delegated = NULL;
35755 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35756 + if (unlikely(err == -EWOULDBLOCK)) {
35757 + pr_warn("cannot retry for NFSv4 delegation"
35758 + " for an internal link\n");
35761 + if (!err || err != -EMLINK)
35764 + /* link count full. re-initialize br_whbase. */
35765 + kick_reinit_br_wh(sb, br);
35768 + /* return this error in this context */
35769 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35771 + au_fhsm_wrote(sb, bindex, /*force*/0);
35774 + wbr_wh_read_unlock(wbr);
35778 +/* ---------------------------------------------------------------------- */
35781 + * create or remove the diropq.
35783 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35784 + unsigned int flags)
35786 + struct dentry *opq_dentry;
35787 + struct super_block *sb;
35788 + struct au_branch *br;
35789 + struct path h_path;
35792 + sb = dentry->d_sb;
35793 + br = au_sbr(sb, bindex);
35794 + h_path.dentry = au_h_dptr(dentry, bindex);
35795 + h_path.mnt = au_br_mnt(br);
35796 + opq_dentry = vfsub_lkup_one(&diropq_name, &h_path);
35797 + if (IS_ERR(opq_dentry))
35800 + if (au_ftest_diropq(flags, CREATE)) {
35801 + err = link_or_create_wh(sb, bindex, opq_dentry);
35803 + au_set_dbdiropq(dentry, bindex);
35804 + goto out; /* success */
35807 + h_path.dentry = opq_dentry;
35808 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &h_path);
35810 + au_set_dbdiropq(dentry, -1);
35812 + dput(opq_dentry);
35813 + opq_dentry = ERR_PTR(err);
35816 + return opq_dentry;
35819 +struct do_diropq_args {
35820 + struct dentry **errp;
35821 + struct dentry *dentry;
35822 + aufs_bindex_t bindex;
35823 + unsigned int flags;
35826 +static void call_do_diropq(void *args)
35828 + struct do_diropq_args *a = args;
35829 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35832 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35833 + unsigned int flags)
35835 + struct dentry *diropq, *h_dentry;
35836 + struct user_namespace *h_userns;
35838 + h_userns = au_sbr_userns(dentry->d_sb, bindex);
35839 + h_dentry = au_h_dptr(dentry, bindex);
35840 + if (!au_test_h_perm_sio(h_userns, d_inode(h_dentry),
35841 + MAY_EXEC | MAY_WRITE))
35842 + diropq = do_diropq(dentry, bindex, flags);
35845 + struct do_diropq_args args = {
35847 + .dentry = dentry,
35848 + .bindex = bindex,
35852 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35853 + if (unlikely(wkq_err))
35854 + diropq = ERR_PTR(wkq_err);
35860 +/* ---------------------------------------------------------------------- */
35863 + * lookup whiteout dentry.
35864 + * @h_parent: lower parent dentry which must exist and be locked
35865 + * @base_name: name of dentry which will be whiteouted
35866 + * returns dentry for whiteout.
35868 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35869 + struct au_branch *br)
35872 + struct qstr wh_name;
35873 + struct dentry *wh_dentry;
35874 + struct path h_path;
35876 + err = au_wh_name_alloc(&wh_name, base_name);
35877 + wh_dentry = ERR_PTR(err);
35879 + h_path.dentry = h_parent;
35880 + h_path.mnt = au_br_mnt(br);
35881 + wh_dentry = vfsub_lkup_one(&wh_name, &h_path);
35882 + au_kfree_try_rcu(wh_name.name);
35884 + return wh_dentry;
35888 + * link/create a whiteout for @dentry on @bindex.
35890 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35891 + struct dentry *h_parent)
35893 + struct dentry *wh_dentry;
35894 + struct super_block *sb;
35897 + sb = dentry->d_sb;
35898 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35899 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35900 + err = link_or_create_wh(sb, bindex, wh_dentry);
35902 + au_set_dbwh(dentry, bindex);
35903 + au_fhsm_wrote(sb, bindex, /*force*/0);
35906 + wh_dentry = ERR_PTR(err);
35910 + return wh_dentry;
35913 +/* ---------------------------------------------------------------------- */
35915 +/* Delete all whiteouts in this directory on branch bindex. */
35916 +static int del_wh_children(struct path *h_path, struct au_nhash *whlist,
35917 + aufs_bindex_t bindex)
35920 + unsigned long ul, n;
35921 + struct qstr wh_name;
35923 + struct hlist_head *head;
35924 + struct au_vdir_wh *pos;
35925 + struct au_vdir_destr *str;
35928 + p = (void *)__get_free_page(GFP_NOFS);
35929 + wh_name.name = p;
35930 + if (unlikely(!wh_name.name))
35934 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35935 + p += AUFS_WH_PFX_LEN;
35936 + n = whlist->nh_num;
35937 + head = whlist->nh_head;
35938 + for (ul = 0; !err && ul < n; ul++, head++) {
35939 + hlist_for_each_entry(pos, head, wh_hash) {
35940 + if (pos->wh_bindex != bindex)
35943 + str = &pos->wh_str;
35944 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35945 + memcpy(p, str->name, str->len);
35946 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35947 + err = unlink_wh_name(h_path, &wh_name);
35952 + AuIOErr("whiteout name too long %.*s\n",
35953 + str->len, str->name);
35958 + free_page((unsigned long)wh_name.name);
35964 +struct del_wh_children_args {
35966 + struct path *h_path;
35967 + struct au_nhash *whlist;
35968 + aufs_bindex_t bindex;
35971 +static void call_del_wh_children(void *args)
35973 + struct del_wh_children_args *a = args;
35974 + *a->errp = del_wh_children(a->h_path, a->whlist, a->bindex);
35977 +/* ---------------------------------------------------------------------- */
35979 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35981 + struct au_whtmp_rmdir *whtmp;
35983 + unsigned int rdhash;
35985 + SiMustAnyLock(sb);
35987 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35988 + if (unlikely(!whtmp)) {
35989 + whtmp = ERR_PTR(-ENOMEM);
35993 + /* no estimation for dir size */
35994 + rdhash = au_sbi(sb)->si_rdhash;
35996 + rdhash = AUFS_RDHASH_DEF;
35997 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35998 + if (unlikely(err)) {
35999 + au_kfree_rcu(whtmp);
36000 + whtmp = ERR_PTR(err);
36007 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
36010 + au_lcnt_dec(&whtmp->br->br_count);
36011 + dput(whtmp->wh_dentry);
36012 + iput(whtmp->dir);
36013 + au_nhash_wh_free(&whtmp->whlist);
36014 + au_kfree_rcu(whtmp);
36018 + * rmdir the whiteouted temporary named dir @h_dentry.
36019 + * @whlist: whiteouted children.
36021 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36022 + struct dentry *wh_dentry, struct au_nhash *whlist)
36025 + unsigned int h_nlink;
36026 + struct path wh_path;
36027 + struct inode *wh_inode, *h_dir;
36028 + struct au_branch *br;
36029 + struct user_namespace *h_userns;
36031 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
36032 + IMustLock(h_dir);
36034 + br = au_sbr(dir->i_sb, bindex);
36035 + wh_path.dentry = wh_dentry;
36036 + wh_path.mnt = au_br_mnt(br);
36037 + h_userns = au_br_userns(br);
36038 + wh_inode = d_inode(wh_dentry);
36039 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
36042 + * someone else might change some whiteouts while we were sleeping.
36043 + * it means this whlist may have an obsoleted entry.
36045 + if (!au_test_h_perm_sio(h_userns, wh_inode, MAY_EXEC | MAY_WRITE))
36046 + err = del_wh_children(&wh_path, whlist, bindex);
36049 + struct del_wh_children_args args = {
36051 + .h_path = &wh_path,
36052 + .whlist = whlist,
36056 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
36057 + if (unlikely(wkq_err))
36060 + inode_unlock(wh_inode);
36063 + h_nlink = h_dir->i_nlink;
36064 + err = vfsub_rmdir(h_dir, &wh_path);
36065 + /* some fs doesn't change the parent nlink in some cases */
36066 + h_nlink -= h_dir->i_nlink;
36070 + if (au_ibtop(dir) == bindex) {
36071 + /* todo: dir->i_mutex is necessary */
36072 + au_cpup_attr_timesizes(dir);
36074 + vfsub_drop_nlink(dir);
36076 + return 0; /* success */
36079 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
36083 +static void call_rmdir_whtmp(void *args)
36086 + aufs_bindex_t bindex;
36087 + struct au_whtmp_rmdir *a = args;
36088 + struct super_block *sb;
36089 + struct dentry *h_parent;
36090 + struct inode *h_dir;
36091 + struct au_hinode *hdir;
36093 + /* rmdir by nfsd may cause deadlock with this i_mutex */
36094 + /* inode_lock(a->dir); */
36096 + sb = a->dir->i_sb;
36097 + si_read_lock(sb, !AuLock_FLUSH);
36098 + if (!au_br_writable(a->br->br_perm))
36100 + bindex = au_br_index(sb, a->br->br_id);
36101 + if (unlikely(bindex < 0))
36105 + ii_write_lock_parent(a->dir);
36106 + h_parent = dget_parent(a->wh_dentry);
36107 + h_dir = d_inode(h_parent);
36108 + hdir = au_hi(a->dir, bindex);
36109 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
36110 + if (unlikely(err))
36112 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
36113 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
36116 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
36117 + au_hn_inode_unlock(hdir);
36118 + vfsub_mnt_drop_write(au_br_mnt(a->br));
36122 + ii_write_unlock(a->dir);
36124 + /* inode_unlock(a->dir); */
36125 + au_whtmp_rmdir_free(a);
36126 + si_read_unlock(sb);
36127 + au_nwt_done(&au_sbi(sb)->si_nowait);
36128 + if (unlikely(err))
36129 + AuIOErr("err %d\n", err);
36132 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36133 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
36136 + struct super_block *sb;
36140 + /* all post-process will be done in do_rmdir_whtmp(). */
36142 + args->dir = au_igrab(dir);
36143 + args->br = au_sbr(sb, bindex);
36144 + au_lcnt_inc(&args->br->br_count);
36145 + args->wh_dentry = dget(wh_dentry);
36146 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
36147 + if (unlikely(wkq_err)) {
36148 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
36149 + au_whtmp_rmdir_free(args);
36152 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
36153 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
36154 +++ linux/fs/aufs/whout.h 2022-11-05 23:02:18.972555950 +0100
36156 +/* SPDX-License-Identifier: GPL-2.0 */
36158 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36160 + * This program is free software; you can redistribute it and/or modify
36161 + * it under the terms of the GNU General Public License as published by
36162 + * the Free Software Foundation; either version 2 of the License, or
36163 + * (at your option) any later version.
36165 + * This program is distributed in the hope that it will be useful,
36166 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36167 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36168 + * GNU General Public License for more details.
36170 + * You should have received a copy of the GNU General Public License
36171 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36175 + * whiteout for logical deletion and opaque directory
36178 +#ifndef __AUFS_WHOUT_H__
36179 +#define __AUFS_WHOUT_H__
36186 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
36187 +int au_wh_test(struct user_namespace *h_userns, struct path *h_ppath,
36188 + struct qstr *wh_name, int try_sio);
36189 +int au_diropq_test(struct user_namespace *h_userns, struct path *h_path);
36191 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
36192 + struct qstr *prefix);
36193 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
36194 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
36195 + struct dentry *dentry);
36196 +int au_wh_init(struct au_branch *br, struct super_block *sb);
36198 +/* diropq flags */
36199 +#define AuDiropq_CREATE 1
36200 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
36201 +#define au_fset_diropq(flags, name) \
36202 + do { (flags) |= AuDiropq_##name; } while (0)
36203 +#define au_fclr_diropq(flags, name) \
36204 + do { (flags) &= ~AuDiropq_##name; } while (0)
36206 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
36207 + unsigned int flags);
36208 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
36209 + struct au_branch *br);
36210 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
36211 + struct dentry *h_parent);
36213 +/* real rmdir for the whiteout-ed dir */
36214 +struct au_whtmp_rmdir {
36215 + struct inode *dir;
36216 + struct au_branch *br;
36217 + struct dentry *wh_dentry;
36218 + struct au_nhash whlist;
36221 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
36222 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
36223 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36224 + struct dentry *wh_dentry, struct au_nhash *whlist);
36225 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36226 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
36228 +/* ---------------------------------------------------------------------- */
36230 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
36231 + aufs_bindex_t bindex)
36233 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
36236 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
36238 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
36241 +#endif /* __KERNEL__ */
36242 +#endif /* __AUFS_WHOUT_H__ */
36243 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
36244 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
36245 +++ linux/fs/aufs/wkq.c 2022-11-05 23:02:18.972555950 +0100
36247 +// SPDX-License-Identifier: GPL-2.0
36249 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36251 + * This program is free software; you can redistribute it and/or modify
36252 + * it under the terms of the GNU General Public License as published by
36253 + * the Free Software Foundation; either version 2 of the License, or
36254 + * (at your option) any later version.
36256 + * This program is distributed in the hope that it will be useful,
36257 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36258 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36259 + * GNU General Public License for more details.
36261 + * You should have received a copy of the GNU General Public License
36262 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36266 + * workqueue for asynchronous/super-io operations
36267 + * todo: try new credential scheme
36270 +#include <linux/module.h>
36273 +/* internal workqueue named AUFS_WKQ_NAME */
36275 +static struct workqueue_struct *au_wkq;
36277 +struct au_wkinfo {
36278 + struct work_struct wk;
36279 + struct kobject *kobj;
36281 + unsigned int flags; /* see wkq.h */
36283 + au_wkq_func_t func;
36286 +#ifdef CONFIG_LOCKDEP
36288 + struct held_lock **hlock;
36291 + struct completion *comp;
36294 +/* ---------------------------------------------------------------------- */
36296 + * Aufs passes some operations to the workqueue such as the internal copyup.
36297 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36298 + * job run by workqueue depends upon the locks acquired in the other task.
36299 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36300 + * information too. And the job in the workqueue restores the info in order to
36301 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36302 + * correctly and expectedly.
36305 +#ifndef CONFIG_LOCKDEP
36306 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36307 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36308 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36309 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36310 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36312 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36314 + wkinfo->hlock = NULL;
36315 + wkinfo->dont_check = 0;
36322 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36324 + static DEFINE_SPINLOCK(spin);
36327 + struct lock_class_key *key;
36329 + { .name = "&sbinfo->si_rwsem" },
36330 + { .name = "&finfo->fi_rwsem" },
36331 + { .name = "&dinfo->di_rwsem" },
36332 + { .name = "&iinfo->ii_rwsem" }
36337 + /* lockless read from 'set.' see below */
36338 + if (set == ARRAY_SIZE(a)) {
36339 + for (i = 0; i < ARRAY_SIZE(a); i++)
36340 + if (a[i].key == key)
36345 + spin_lock(&spin);
36347 + for (i = 0; i < ARRAY_SIZE(a); i++)
36348 + if (a[i].key == key) {
36349 + spin_unlock(&spin);
36352 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36354 + if (unlikely(a[i].key == key)) { /* rare but possible */
36355 + spin_unlock(&spin);
36360 + if (strstr(a[i].name, name)) {
36362 + * the order of these three lines is important for the
36363 + * lockless read above.
36366 + spin_unlock(&spin);
36368 + /* AuDbg("%d, %s\n", set, name); */
36372 + spin_unlock(&spin);
36381 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36384 + struct task_struct *curr;
36385 + struct held_lock **hl, *held_locks, *p;
36389 + wkinfo->dont_check = lockdep_recursing(curr);
36390 + if (wkinfo->dont_check)
36392 + n = curr->lockdep_depth;
36397 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36398 + if (unlikely(!wkinfo->hlock))
36402 +#if 0 /* left for debugging */
36403 + if (0 && au_debug_test())
36404 + lockdep_print_held_locks(curr);
36406 + held_locks = curr->held_locks;
36407 + hl = wkinfo->hlock;
36409 + p = held_locks++;
36410 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36419 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36421 + au_kfree_try_rcu(wkinfo->hlock);
36424 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36426 + struct held_lock *p, **hl = wkinfo->hlock;
36429 + if (wkinfo->dont_check)
36433 + while ((p = *hl++)) { /* assignment */
36434 + subclass = lockdep_hlock_class(p)->subclass;
36435 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36437 + rwsem_acquire_read(p->instance, subclass, 0,
36438 + /*p->acquire_ip*/_RET_IP_);
36440 + rwsem_acquire(p->instance, subclass, 0,
36441 + /*p->acquire_ip*/_RET_IP_);
36445 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36447 + struct held_lock *p, **hl = wkinfo->hlock;
36449 + if (wkinfo->dont_check)
36453 + while ((p = *hl++)) /* assignment */
36454 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36458 +static void wkq_func(struct work_struct *wk)
36460 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36462 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36463 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36465 + au_wkq_lockdep_pre(wkinfo);
36466 + wkinfo->func(wkinfo->args);
36467 + au_wkq_lockdep_post(wkinfo);
36468 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36469 + complete(wkinfo->comp);
36471 + kobject_put(wkinfo->kobj);
36472 + module_put(THIS_MODULE); /* todo: ?? */
36473 + au_kfree_rcu(wkinfo);
36478 + * Since struct completion is large, try allocating it dynamically.
36480 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36482 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36484 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36486 + init_completion(*comp);
36487 + wkinfo->comp = *comp;
36493 +static void au_wkq_comp_free(struct completion *comp)
36495 + au_kfree_rcu(comp);
36498 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36500 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36501 + if (au_wkq_test()) {
36502 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36503 + " due to a dead dir by UDBA,"
36504 + " or async xino write?\n");
36505 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36508 + au_dbg_verify_kthread();
36510 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36511 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36512 + queue_work(au_wkq, &wkinfo->wk);
36514 + INIT_WORK(&wkinfo->wk, wkq_func);
36515 + schedule_work(&wkinfo->wk);
36520 + * Be careful. It is easy to make deadlock happen.
36521 + * processA: lock, wkq and wait
36522 + * processB: wkq and wait, lock in wkq
36525 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36528 + AuWkqCompDeclare(comp);
36529 + struct au_wkinfo wkinfo = {
36535 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36536 + if (unlikely(err))
36538 + err = au_wkq_lockdep_alloc(&wkinfo);
36539 + if (unlikely(err))
36542 + au_wkq_run(&wkinfo);
36543 + /* no timeout, no interrupt */
36544 + wait_for_completion(wkinfo.comp);
36546 + au_wkq_lockdep_free(&wkinfo);
36549 + au_wkq_comp_free(comp);
36551 + destroy_work_on_stack(&wkinfo.wk);
36556 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36557 + * problem in a concurrent umounting.
36559 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36560 + unsigned int flags)
36563 + struct au_wkinfo *wkinfo;
36565 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36568 + * wkq_func() must free this wkinfo.
36569 + * it highly depends upon the implementation of workqueue.
36572 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36574 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36575 + wkinfo->flags = flags & ~AuWkq_WAIT;
36576 + wkinfo->func = func;
36577 + wkinfo->args = args;
36578 + wkinfo->comp = NULL;
36579 + au_wkq_lockdep_init(wkinfo);
36580 + kobject_get(wkinfo->kobj);
36581 + __module_get(THIS_MODULE); /* todo: ?? */
36583 + au_wkq_run(wkinfo);
36586 + au_nwt_done(&au_sbi(sb)->si_nowait);
36592 +/* ---------------------------------------------------------------------- */
36594 +void au_nwt_init(struct au_nowait_tasks *nwt)
36596 + atomic_set(&nwt->nw_len, 0);
36597 + /* smp_mb(); */ /* atomic_set */
36598 + init_waitqueue_head(&nwt->nw_wq);
36601 +void au_wkq_fin(void)
36603 + destroy_workqueue(au_wkq);
36606 +int __init au_wkq_init(void)
36611 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36612 + if (IS_ERR(au_wkq))
36613 + err = PTR_ERR(au_wkq);
36614 + else if (!au_wkq)
36619 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36620 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36621 +++ linux/fs/aufs/wkq.h 2022-11-05 23:02:18.972555950 +0100
36623 +/* SPDX-License-Identifier: GPL-2.0 */
36625 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36627 + * This program is free software; you can redistribute it and/or modify
36628 + * it under the terms of the GNU General Public License as published by
36629 + * the Free Software Foundation; either version 2 of the License, or
36630 + * (at your option) any later version.
36632 + * This program is distributed in the hope that it will be useful,
36633 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36634 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36635 + * GNU General Public License for more details.
36637 + * You should have received a copy of the GNU General Public License
36638 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36642 + * workqueue for asynchronous/super-io operations
36643 + * todo: try new credentials management scheme
36646 +#ifndef __AUFS_WKQ_H__
36647 +#define __AUFS_WKQ_H__
36651 +#include <linux/wait.h>
36653 +struct super_block;
36655 +/* ---------------------------------------------------------------------- */
36658 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36660 +struct au_nowait_tasks {
36662 + wait_queue_head_t nw_wq;
36665 +/* ---------------------------------------------------------------------- */
36667 +typedef void (*au_wkq_func_t)(void *args);
36670 +#define AuWkq_WAIT 1
36671 +#define AuWkq_NEST (1 << 1)
36672 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36673 +#define au_fset_wkq(flags, name) \
36674 + do { (flags) |= AuWkq_##name; } while (0)
36675 +#define au_fclr_wkq(flags, name) \
36676 + do { (flags) &= ~AuWkq_##name; } while (0)
36679 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36680 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36681 + unsigned int flags);
36682 +void au_nwt_init(struct au_nowait_tasks *nwt);
36683 +int __init au_wkq_init(void);
36684 +void au_wkq_fin(void);
36686 +/* ---------------------------------------------------------------------- */
36688 +static inline int au_wkq_test(void)
36690 + return current->flags & PF_WQ_WORKER;
36693 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36695 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36698 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36700 + if (atomic_dec_and_test(&nwt->nw_len))
36701 + wake_up_all(&nwt->nw_wq);
36704 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36706 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36710 +#endif /* __KERNEL__ */
36711 +#endif /* __AUFS_WKQ_H__ */
36712 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36713 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36714 +++ linux/fs/aufs/xattr.c 2022-12-17 09:21:34.799855195 +0100
36716 +// SPDX-License-Identifier: GPL-2.0
36718 + * Copyright (C) 2014-2022 Junjiro R. Okajima
36720 + * This program is free software; you can redistribute it and/or modify
36721 + * it under the terms of the GNU General Public License as published by
36722 + * the Free Software Foundation; either version 2 of the License, or
36723 + * (at your option) any later version.
36725 + * This program is distributed in the hope that it will be useful,
36726 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36727 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36728 + * GNU General Public License for more details.
36730 + * You should have received a copy of the GNU General Public License
36731 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36735 + * handling xattr functions
36738 +#include <linux/fs.h>
36739 +#include <linux/posix_acl_xattr.h>
36740 +#include <linux/xattr.h>
36743 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36745 + if (!ignore_flags)
36753 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36758 +#define cmp(brattr, prefix) do { \
36759 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36760 + XATTR_##prefix##_PREFIX_LEN)) { \
36761 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36767 + cmp(SEC, SECURITY);
36768 + cmp(SYS, SYSTEM);
36769 + cmp(TR, TRUSTED);
36773 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36780 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36782 +static int au_do_cpup_xattr(struct path *h_dst, struct path *h_src,
36783 + char *name, char **buf, unsigned int ignore_flags,
36784 + unsigned int verbose)
36788 + struct inode *h_idst;
36789 + struct dentry *h_dst_dentry, *h_src_dentry;
36790 + struct user_namespace *h_dst_userns, *h_src_userns;
36792 + h_src_userns = mnt_user_ns(h_src->mnt);
36793 + h_src_dentry = h_src->dentry;
36794 + ssz = vfs_getxattr_alloc(h_src_userns, h_src_dentry, name, buf, 0,
36797 + if (unlikely(err <= 0)) {
36798 + if (err == -ENODATA
36799 + || (err == -EOPNOTSUPP
36800 + && ((ignore_flags & au_xattr_out_of_list)
36801 + || (au_test_nfs_noacl(d_inode(h_src_dentry))
36802 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36804 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36807 + if (err && (verbose || au_debug_test()))
36808 + pr_err("%s, err %d\n", name, err);
36812 + /* unlock it temporary */
36813 + h_dst_userns = mnt_user_ns(h_dst->mnt);
36814 + h_dst_dentry = h_dst->dentry;
36815 + h_idst = d_inode(h_dst_dentry);
36816 + inode_unlock(h_idst);
36817 + err = vfsub_setxattr(h_dst_userns, h_dst_dentry, name, *buf, ssz,
36819 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36820 + if (unlikely(err)) {
36821 + if (verbose || au_debug_test())
36822 + pr_err("%s, err %d\n", name, err);
36823 + err = au_xattr_ignore(err, name, ignore_flags);
36830 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
36831 + unsigned int verbose)
36833 + int err, unlocked, acl_access, acl_default;
36835 + struct dentry *h_dst_dentry, *h_src_dentry;
36836 + struct inode *h_isrc, *h_idst;
36837 + char *value, *p, *o, *e;
36839 + /* try stopping to update the source inode while we are referencing */
36840 + /* there should not be the parent-child relationship between them */
36841 + h_dst_dentry = h_dst->dentry;
36842 + h_idst = d_inode(h_dst_dentry);
36843 + h_src_dentry = h_src->dentry;
36844 + h_isrc = d_inode(h_src_dentry);
36845 + inode_unlock(h_idst);
36846 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36847 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36850 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36851 + ssz = vfs_listxattr(h_src_dentry, NULL, 0);
36853 + if (unlikely(err < 0)) {
36855 + if (err == -ENODATA
36856 + || err == -EOPNOTSUPP)
36857 + err = 0; /* ignore */
36866 + p = kmalloc(ssz, GFP_NOFS);
36868 + if (unlikely(!p))
36870 + err = vfs_listxattr(h_src_dentry, p, ssz);
36872 + inode_unlock_shared(h_isrc);
36874 + AuDbg("err %d, ssz %zd\n", err, ssz);
36875 + if (unlikely(err < 0))
36883 + while (!err && p < e) {
36884 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36885 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36886 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36887 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36889 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36891 + p += strlen(p) + 1;
36894 + ignore_flags |= au_xattr_out_of_list;
36895 + if (!err && !acl_access) {
36896 + err = au_do_cpup_xattr(h_dst, h_src,
36897 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36898 + ignore_flags, verbose);
36901 + if (!err && !acl_default) {
36902 + err = au_do_cpup_xattr(h_dst, h_src,
36903 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36904 + ignore_flags, verbose);
36908 + au_kfree_try_rcu(value);
36911 + au_kfree_try_rcu(o);
36914 + inode_unlock_shared(h_isrc);
36919 +/* ---------------------------------------------------------------------- */
36921 +static int au_smack_reentering(struct super_block *sb)
36923 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36925 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36926 + * i_op->getxattr(). ouch.
36928 + return si_pid_test(sb);
36939 +struct au_lgxattr {
36947 + const char *name;
36954 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36955 + struct au_lgxattr *arg)
36959 + struct path h_path;
36960 + struct super_block *sb;
36962 + sb = dentry->d_sb;
36963 + reenter = au_smack_reentering(sb);
36965 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36966 + if (unlikely(err))
36969 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
36970 + if (unlikely(err))
36972 + if (unlikely(!h_path.dentry))
36973 + /* illegally overlapped or something */
36974 + goto out_di; /* pretending success */
36976 + /* always topmost entry only */
36977 + switch (arg->type) {
36978 + case AU_XATTR_LIST:
36979 + err = vfs_listxattr(h_path.dentry,
36980 + arg->u.list.list, arg->u.list.size);
36982 + case AU_XATTR_GET:
36983 + AuDebugOn(d_is_negative(h_path.dentry));
36984 + err = vfs_getxattr(mnt_user_ns(h_path.mnt), h_path.dentry,
36985 + arg->u.get.name, arg->u.get.value,
36986 + arg->u.get.size);
36992 + di_read_unlock(dentry, AuLock_IR);
36995 + si_read_unlock(sb);
37001 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
37003 + struct au_lgxattr arg = {
37004 + .type = AU_XATTR_LIST,
37011 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
37014 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
37015 + const char *name, void *value, size_t size)
37017 + struct au_lgxattr arg = {
37018 + .type = AU_XATTR_GET,
37026 + return au_lgxattr(dentry, inode, &arg);
37029 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
37030 + const char *name, const void *value, size_t size,
37033 + struct au_sxattr arg = {
37034 + .type = AU_XATTR_SET,
37043 + return au_sxattr(dentry, inode, &arg);
37046 +/* ---------------------------------------------------------------------- */
37048 +static int au_xattr_get(const struct xattr_handler *handler,
37049 + struct dentry *dentry, struct inode *inode,
37050 + const char *name, void *buffer, size_t size)
37052 + return au_getxattr(dentry, inode, name, buffer, size);
37055 +static int au_xattr_set(const struct xattr_handler *handler,
37056 + struct user_namespace *userns,
37057 + struct dentry *dentry, struct inode *inode,
37058 + const char *name, const void *value, size_t size,
37061 + return au_setxattr(dentry, inode, name, value, size, flags);
37064 +static const struct xattr_handler au_xattr_handler = {
37067 + .get = au_xattr_get,
37068 + .set = au_xattr_set
37071 +static const struct xattr_handler *au_xattr_handlers[] = {
37072 +#ifdef CONFIG_FS_POSIX_ACL
37073 + &posix_acl_access_xattr_handler,
37074 + &posix_acl_default_xattr_handler,
37076 + &au_xattr_handler, /* must be last */
37080 +void au_xattr_init(struct super_block *sb)
37082 + sb->s_xattr = au_xattr_handlers;
37084 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
37085 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
37086 +++ linux/fs/aufs/xino.c 2022-11-05 23:02:18.972555950 +0100
37088 +// SPDX-License-Identifier: GPL-2.0
37090 + * Copyright (C) 2005-2022 Junjiro R. Okajima
37092 + * This program is free software; you can redistribute it and/or modify
37093 + * it under the terms of the GNU General Public License as published by
37094 + * the Free Software Foundation; either version 2 of the License, or
37095 + * (at your option) any later version.
37097 + * This program is distributed in the hope that it will be useful,
37098 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
37099 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37100 + * GNU General Public License for more details.
37102 + * You should have received a copy of the GNU General Public License
37103 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
37107 + * external inode number translation table and bitmap
37109 + * things to consider
37111 + * + au_xino object
37112 + * + XINO files (xino, xib, xigen)
37113 + * + dynamic debugfs entries (xiN)
37114 + * + static debugfs entries (xib, xigen)
37115 + * + static sysfs entry (xi_path)
37116 + * - several entry points to handle them.
37117 + * + mount(2) without xino option (default)
37118 + * + mount(2) with xino option
37119 + * + mount(2) with noxino option
37121 + * + remount with add/del branches
37122 + * + remount with xino/noxino options
37125 +#include <linux/seq_file.h>
37126 +#include <linux/statfs.h>
37129 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
37130 + aufs_bindex_t bbot,
37131 + struct super_block *h_sb)
37133 + /* todo: try binary-search if the branches are many */
37134 + for (; btop <= bbot; btop++)
37135 + if (h_sb == au_sbr_sb(sb, btop))
37141 + * find another branch who is on the same filesystem of the specified
37142 + * branch{@btgt}. search until @bbot.
37144 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
37145 + aufs_bindex_t bbot)
37147 + aufs_bindex_t bindex;
37148 + struct super_block *tgt_sb;
37150 + tgt_sb = au_sbr_sb(sb, btgt);
37151 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
37153 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
37158 +/* ---------------------------------------------------------------------- */
37161 + * stop unnecessary notify events at creating xino files
37164 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
37166 + aufs_bindex_t bfound, bindex, bbot;
37167 + struct dentry *parent;
37168 + struct au_branch *br;
37171 + parent = dentry->d_parent; /* safe d_parent access */
37172 + bbot = au_sbbot(sb);
37173 + for (bindex = 0; bindex <= bbot; bindex++) {
37174 + br = au_sbr(sb, bindex);
37175 + if (au_br_dentry(br) == parent) {
37181 + AuDbg("bfound b%d\n", bfound);
37185 +struct au_xino_lock_dir {
37186 + struct au_hinode *hdir;
37187 + struct dentry *parent;
37188 + struct inode *dir;
37191 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
37192 + unsigned int lsc)
37194 + struct dentry *parent;
37195 + struct inode *dir;
37197 + parent = dget_parent(dentry);
37198 + dir = d_inode(parent);
37199 + inode_lock_nested(dir, lsc);
37200 +#if 0 /* it should not happen */
37201 + spin_lock(&dentry->d_lock);
37202 + if (unlikely(dentry->d_parent != parent)) {
37203 + spin_unlock(&dentry->d_lock);
37204 + inode_unlock(dir);
37209 + spin_unlock(&dentry->d_lock);
37216 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
37217 + struct au_xino_lock_dir *ldir)
37219 + aufs_bindex_t bindex;
37221 + ldir->hdir = NULL;
37222 + bindex = au_xi_root(sb, xipath->dentry);
37223 + if (bindex >= 0) {
37224 + /* rw branch root */
37225 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
37226 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
37229 + ldir->parent = au_dget_parent_lock(xipath->dentry,
37231 + ldir->dir = d_inode(ldir->parent);
37235 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
37238 + au_hn_inode_unlock(ldir->hdir);
37240 + inode_unlock(ldir->dir);
37241 + dput(ldir->parent);
37245 +/* ---------------------------------------------------------------------- */
37248 + * create and set a new xino file
37250 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
37253 + struct file *file;
37254 + struct dentry *h_parent, *d;
37255 + struct inode *h_dir, *inode;
37257 + static DEFINE_MUTEX(mtx);
37260 + * at mount-time, and the xino file is the default path,
37261 + * hnotify is disabled so we have no notify events to ignore.
37262 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37265 + mutex_lock(&mtx);
37266 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37267 + /* | __FMODE_NONOTIFY */,
37269 + if (IS_ERR(file)) {
37271 + mutex_unlock(&mtx);
37273 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
37277 + /* keep file count */
37279 + d = file->f_path.dentry;
37280 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
37282 + mutex_unlock(&mtx);
37283 + /* mnt_want_write() is unnecessary here */
37284 + h_dir = d_inode(h_parent);
37285 + inode = file_inode(file);
37286 + /* no delegation since it is just created */
37287 + if (inode->i_nlink)
37288 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37290 + inode_unlock(h_dir);
37292 + if (unlikely(err)) {
37294 + pr_err("unlink %s(%d)\n", fpath, err);
37299 + if (unlikely(sb && sb == d->d_sb)) {
37301 + pr_err("%s must be outside\n", fpath);
37304 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37306 + pr_err("xino doesn't support %s(%s)\n",
37307 + fpath, au_sbtype(d->d_sb));
37310 + return file; /* success */
37314 + file = ERR_PTR(err);
37319 + * create a new xinofile at the same place/path as @base.
37321 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37322 + struct file *copy_src)
37324 + struct file *file;
37325 + struct dentry *dentry;
37326 + struct inode *dir, *delegated;
37327 + struct qstr *name;
37328 + struct path ppath, path;
37329 + int err, do_unlock;
37330 + struct au_xino_lock_dir ldir;
37333 + au_xino_lock_dir(sb, base, &ldir);
37334 + dentry = base->dentry;
37335 + ppath.dentry = dentry->d_parent; /* dir inode is locked */
37336 + ppath.mnt = base->mnt;
37337 + dir = d_inode(ppath.dentry);
37340 + name = &dentry->d_name;
37341 + path.dentry = vfsub_lookup_one_len(name->name, &ppath, name->len);
37342 + if (IS_ERR(path.dentry)) {
37343 + file = (void *)path.dentry;
37344 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37348 + /* no need to mnt_want_write() since we call dentry_open() later */
37349 + err = vfs_create(mnt_user_ns(base->mnt), dir, path.dentry, 0666, NULL);
37350 + if (unlikely(err)) {
37351 + file = ERR_PTR(err);
37352 + pr_err("%pd create err %d\n", dentry, err);
37356 + path.mnt = base->mnt;
37357 + file = vfsub_dentry_open(&path,
37358 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37359 + /* | __FMODE_NONOTIFY */);
37360 + if (IS_ERR(file)) {
37361 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37365 + delegated = NULL;
37366 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37367 + au_xino_unlock_dir(&ldir);
37369 + if (unlikely(err == -EWOULDBLOCK)) {
37370 + pr_warn("cannot retry for NFSv4 delegation"
37371 + " for an internal unlink\n");
37374 + if (unlikely(err)) {
37375 + pr_err("%pd unlink err %d\n", dentry, err);
37380 + /* no one can touch copy_src xino */
37381 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37382 + if (unlikely(err)) {
37383 + pr_err("%pd copy err %d\n", dentry, err);
37387 + goto out_dput; /* success */
37391 + file = ERR_PTR(err);
37393 + dput(path.dentry);
37396 + au_xino_unlock_dir(&ldir);
37400 +struct file *au_xino_file1(struct au_xino *xi)
37402 + struct file *file;
37403 + unsigned int u, nfile;
37406 + nfile = xi->xi_nfile;
37407 + for (u = 0; u < nfile; u++) {
37408 + file = xi->xi_file[u];
37416 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37427 + if (idx < xi->xi_nfile) {
37428 + f = xi->xi_file[idx];
37432 + p = au_kzrealloc(xi->xi_file,
37433 + sizeof(*xi->xi_file) * xi->xi_nfile,
37434 + sizeof(*xi->xi_file) * (idx + 1),
37435 + GFP_NOFS, /*may_shrink*/0);
37437 + MtxMustLock(&xi->xi_mtx);
37439 + xi->xi_nfile = idx + 1;
37447 + xi->xi_file[idx] = file;
37454 + * if @xinew->xi is not set, then create new xigen file.
37456 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37458 + struct file *file;
37461 + SiMustAnyLock(sb);
37463 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37464 + if (IS_ERR(file)) {
37465 + err = PTR_ERR(file);
37466 + pr_err("%s[%d], err %d\n",
37467 + xinew->xi ? "xino" : "xigen",
37468 + xinew->idx, err);
37473 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37476 + /* todo: make xigen file an array */
37477 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37480 + if (unlikely(err))
37481 + file = ERR_PTR(err);
37487 +/* ---------------------------------------------------------------------- */
37490 + * truncate xino files
37492 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37493 + int idx, struct kstatfs *st)
37497 + struct file *file, *new_xino;
37498 + struct au_xi_new xinew = {
37503 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37504 + file = au_xino_file(xinew.xi, idx);
37508 + xinew.base = &file->f_path;
37509 + err = vfs_statfs(xinew.base, st);
37510 + if (unlikely(err)) {
37511 + AuErr1("statfs err %d, ignored\n", err);
37516 + blocks = file_inode(file)->i_blocks;
37517 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37518 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37520 + xinew.copy_src = file;
37521 + new_xino = au_xi_new(sb, &xinew);
37522 + if (IS_ERR(new_xino)) {
37523 + err = PTR_ERR(new_xino);
37524 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37528 + err = vfs_statfs(&new_xino->f_path, st);
37530 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37531 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37532 + st->f_bfree, st->f_blocks);
37534 + AuErr1("statfs err %d, ignored\n", err);
37542 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37545 + unsigned long jiffy;
37546 + aufs_bindex_t bbot;
37547 + struct kstatfs *st;
37548 + struct au_branch *br;
37549 + struct au_xino *xi;
37552 + st = kmalloc(sizeof(*st), GFP_NOFS);
37553 + if (unlikely(!st))
37557 + bbot = au_sbbot(sb);
37558 + if (unlikely(bindex < 0 || bbot < bindex))
37563 + br = au_sbr(sb, bindex);
37564 + xi = br->br_xino;
37565 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37566 + err = au_xino_do_trunc(sb, bindex, i, st);
37568 + au_sbi(sb)->si_xino_jiffy = jiffy;
37571 + au_kfree_rcu(st);
37576 +struct xino_do_trunc_args {
37577 + struct super_block *sb;
37578 + struct au_branch *br;
37582 +static void xino_do_trunc(void *_args)
37584 + struct xino_do_trunc_args *args = _args;
37585 + struct super_block *sb;
37586 + struct au_branch *br;
37587 + struct inode *dir;
37589 + aufs_bindex_t bindex;
37593 + dir = d_inode(sb->s_root);
37597 + si_noflush_write_lock(sb);
37598 + ii_read_lock_parent(dir);
37599 + bindex = au_br_index(sb, br->br_id);
37600 + err = au_xino_trunc(sb, bindex, idx);
37601 + ii_read_unlock(dir);
37602 + if (unlikely(err))
37603 + pr_warn("err b%d, (%d)\n", bindex, err);
37604 + atomic_dec(&br->br_xino->xi_truncating);
37605 + au_lcnt_dec(&br->br_count);
37606 + si_write_unlock(sb);
37607 + au_nwt_done(&au_sbi(sb)->si_nowait);
37608 + au_kfree_rcu(args);
37612 + * returns the index in the xi_file array whose corresponding file is necessary
37613 + * to truncate, or -1 which means no need to truncate.
37615 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37619 + struct kstatfs st;
37620 + struct au_sbinfo *sbinfo;
37621 + struct au_xino *xi;
37622 + struct file *file;
37624 + /* todo: si_xino_expire and the ratio should be customizable */
37625 + sbinfo = au_sbi(sb);
37626 + if (time_before(jiffies,
37627 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37630 + /* truncation border */
37631 + xi = br->br_xino;
37632 + for (u = 0; u < xi->xi_nfile; u++) {
37633 + file = au_xino_file(xi, u);
37637 + err = vfs_statfs(&file->f_path, &st);
37638 + if (unlikely(err)) {
37639 + AuErr1("statfs err %d, ignored\n", err);
37642 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37643 + >= AUFS_XINO_DEF_TRUNC)
37650 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37653 + struct xino_do_trunc_args *args;
37656 + idx = xino_trunc_test(sb, br);
37660 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37663 + /* lock and kfree() will be called in trunc_xino() */
37664 + args = kmalloc(sizeof(*args), GFP_NOFS);
37665 + if (unlikely(!args)) {
37666 + AuErr1("no memory\n");
37670 + au_lcnt_inc(&br->br_count);
37674 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37676 + return; /* success */
37678 + pr_err("wkq %d\n", wkq_err);
37679 + au_lcnt_dec(&br->br_count);
37680 + au_kfree_rcu(args);
37683 + atomic_dec(&br->br_xino->xi_truncating);
37686 +/* ---------------------------------------------------------------------- */
37688 +struct au_xi_calc {
37693 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37694 + struct au_xi_calc *calc)
37698 + maxent = au_xi_maxent(sb);
37699 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37700 + calc->pos *= sizeof(ino_t);
37703 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37704 + struct au_xi_calc *calc)
37707 + struct file *file;
37708 + struct au_xino *xi = br->br_xino;
37709 + struct au_xi_new xinew = {
37713 + SiMustAnyLock(sb);
37719 + mutex_lock(&xi->xi_mtx);
37720 + file = au_xino_file(xi, calc->idx);
37724 + file = au_xino_file(xi, /*idx*/-1);
37725 + AuDebugOn(!file);
37726 + xinew.idx = calc->idx;
37727 + xinew.base = &file->f_path;
37728 + /* xinew.copy_src = NULL; */
37729 + file = au_xi_new(sb, &xinew);
37730 + if (IS_ERR(file))
37731 + err = PTR_ERR(file);
37734 + mutex_unlock(&xi->xi_mtx);
37739 +struct au_xino_do_new_async_args {
37740 + struct super_block *sb;
37741 + struct au_branch *br;
37742 + struct au_xi_calc calc;
37746 +struct au_xi_writing {
37747 + struct hlist_bl_node node;
37748 + ino_t h_ino, ino;
37751 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37754 +static void au_xino_call_do_new_async(void *args)
37756 + struct au_xino_do_new_async_args *a = args;
37757 + struct au_branch *br;
37758 + struct super_block *sb;
37759 + struct au_sbinfo *sbi;
37760 + struct inode *root;
37761 + struct file *file;
37762 + struct au_xi_writing *del, *p;
37763 + struct hlist_bl_head *hbl;
37764 + struct hlist_bl_node *pos;
37769 + sbi = au_sbi(sb);
37770 + si_noflush_read_lock(sb);
37771 + root = d_inode(sb->s_root);
37772 + ii_read_lock_child(root);
37773 + err = au_xino_do_new_async(sb, br, &a->calc);
37774 + if (unlikely(err)) {
37775 + AuIOErr("err %d\n", err);
37779 + file = au_xino_file(br->br_xino, a->calc.idx);
37780 + AuDebugOn(!file);
37781 + err = au_xino_do_write(file, &a->calc, a->ino);
37782 + if (unlikely(err)) {
37783 + AuIOErr("err %d\n", err);
37788 + hbl = &br->br_xino->xi_writing;
37789 + hlist_bl_lock(hbl);
37790 + au_hbl_for_each(pos, hbl) {
37791 + p = container_of(pos, struct au_xi_writing, node);
37792 + if (p->ino == a->ino) {
37794 + hlist_bl_del(&p->node);
37798 + hlist_bl_unlock(hbl);
37799 + au_kfree_rcu(del);
37802 + au_lcnt_dec(&br->br_count);
37803 + ii_read_unlock(root);
37804 + si_read_unlock(sb);
37805 + au_nwt_done(&sbi->si_nowait);
37810 + * create a new xino file asynchronously
37812 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37813 + struct au_xi_calc *calc, ino_t ino)
37816 + struct au_xino_do_new_async_args *arg;
37819 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37820 + if (unlikely(!arg))
37825 + arg->calc = *calc;
37827 + au_lcnt_inc(&br->br_count);
37828 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37829 + if (unlikely(err)) {
37830 + pr_err("wkq %d\n", err);
37831 + au_lcnt_dec(&br->br_count);
37832 + au_kfree_rcu(arg);
37840 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37841 + * at the position of @h_ino.
37843 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37848 + struct au_xi_calc calc;
37849 + struct au_sbinfo *sbinfo;
37850 + struct file *file;
37851 + struct au_xino *xi;
37852 + struct hlist_bl_head *hbl;
37853 + struct hlist_bl_node *pos;
37854 + struct au_xi_writing *p;
37857 + if (!au_opt_test(au_mntflags(sb), XINO))
37858 + return 0; /* no xino */
37861 + au_xi_calc(sb, h_ino, &calc);
37862 + xi = au_sbr(sb, bindex)->br_xino;
37863 + file = au_xino_file(xi, calc.idx);
37865 + hbl = &xi->xi_writing;
37866 + hlist_bl_lock(hbl);
37867 + au_hbl_for_each(pos, hbl) {
37868 + p = container_of(pos, struct au_xi_writing, node);
37869 + if (p->h_ino == h_ino) {
37870 + AuDbg("hi%llu, i%llu, found\n",
37871 + (u64)p->h_ino, (u64)p->ino);
37876 + hlist_bl_unlock(hbl);
37878 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37879 + return 0; /* no xino */
37881 + sbinfo = au_sbi(sb);
37882 + sz = xino_fread(file, ino, sizeof(*ino), &calc.pos);
37883 + if (sz == sizeof(*ino))
37884 + return 0; /* success */
37887 + if (unlikely(sz >= 0)) {
37889 + AuIOErr("xino read error (%zd)\n", sz);
37894 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37899 + sz = xino_fwrite(file, &ino, sizeof(ino), &calc->pos);
37900 + if (sz == sizeof(ino))
37901 + return 0; /* success */
37903 + AuIOErr("write failed (%zd)\n", sz);
37908 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37909 + * at the position of @h_ino.
37910 + * even if @ino is zero, it is written to the xinofile and means no entry.
37911 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37912 + * try truncating it.
37914 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37918 + unsigned int mnt_flags;
37919 + struct au_xi_calc calc;
37920 + struct file *file;
37921 + struct au_branch *br;
37922 + struct au_xino *xi;
37923 + struct au_xi_writing *p;
37925 + SiMustAnyLock(sb);
37927 + mnt_flags = au_mntflags(sb);
37928 + if (!au_opt_test(mnt_flags, XINO))
37931 + au_xi_calc(sb, h_ino, &calc);
37932 + br = au_sbr(sb, bindex);
37933 + xi = br->br_xino;
37934 + file = au_xino_file(xi, calc.idx);
37936 + /* store the inum pair into the list */
37937 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37938 + p->h_ino = h_ino;
37940 + au_hbl_add(&p->node, &xi->xi_writing);
37942 + /* create and write a new xino file asynchronously */
37943 + err = au_xino_new_async(sb, br, &calc, ino);
37945 + return 0; /* success */
37949 + err = au_xino_do_write(file, &calc, ino);
37951 + br = au_sbr(sb, bindex);
37952 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37953 + && au_test_fs_trunc_xino(au_br_sb(br)))
37954 + xino_try_trunc(sb, br);
37955 + return 0; /* success */
37959 + AuIOErr("write failed (%d)\n", err);
37963 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37966 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37967 +ssize_t xino_fread(struct file *file, void *kbuf, size_t size, loff_t *pos)
37971 + const int prevent_endless = 10;
37975 + err = vfsub_read_k(file, kbuf, size, pos);
37976 + if (err == -EINTR
37977 + && !au_wkq_test()
37978 + && fatal_signal_pending(current)) {
37979 + err = xino_fread_wkq(file, kbuf, size, pos);
37980 + BUG_ON(err == -EINTR);
37982 + } while (i++ < prevent_endless
37983 + && (err == -EAGAIN || err == -EINTR));
37985 +#if 0 /* reserved for future use */
37987 + fsnotify_access(file->f_path.dentry);
37993 +struct xino_fread_args {
37995 + struct file *file;
38001 +static void call_xino_fread(void *args)
38003 + struct xino_fread_args *a = args;
38004 + *a->errp = xino_fread(a->file, a->buf, a->size, a->pos);
38007 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
38012 + struct xino_fread_args args = {
38020 + wkq_err = au_wkq_wait(call_xino_fread, &args);
38021 + if (unlikely(wkq_err))
38027 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
38030 +static ssize_t do_xino_fwrite(struct file *file, void *kbuf, size_t size,
38035 + const int prevent_endless = 10;
38039 + err = vfsub_write_k(file, kbuf, size, pos);
38040 + if (err == -EINTR
38041 + && !au_wkq_test()
38042 + && fatal_signal_pending(current)) {
38043 + err = xino_fwrite_wkq(file, kbuf, size, pos);
38044 + BUG_ON(err == -EINTR);
38046 + } while (i++ < prevent_endless
38047 + && (err == -EAGAIN || err == -EINTR));
38049 +#if 0 /* reserved for future use */
38051 + fsnotify_modify(file->f_path.dentry);
38057 +struct do_xino_fwrite_args {
38059 + struct file *file;
38065 +static void call_do_xino_fwrite(void *args)
38067 + struct do_xino_fwrite_args *a = args;
38068 + *a->errp = do_xino_fwrite(a->file, a->buf, a->size, a->pos);
38071 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
38076 + struct do_xino_fwrite_args args = {
38085 + * it breaks RLIMIT_FSIZE and normal user's limit,
38086 + * users should care about quota and real 'filesystem full.'
38088 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
38089 + if (unlikely(wkq_err))
38095 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos)
38099 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
38101 + err = do_xino_fwrite(file, buf, size, pos);
38105 + err = xino_fwrite_wkq(file, buf, size, pos);
38112 +/* ---------------------------------------------------------------------- */
38115 + * inode number bitmap
38117 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
38118 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
38122 + AuDebugOn(bit < 0 || page_bits <= bit);
38123 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
38127 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
38129 + AuDebugOn(ino < AUFS_FIRST_INO);
38130 + ino -= AUFS_FIRST_INO;
38131 + *pindex = ino / page_bits;
38132 + *bit = ino % page_bits;
38135 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
38140 + struct au_sbinfo *sbinfo;
38141 + struct file *xib;
38142 + unsigned long *p;
38144 + sbinfo = au_sbi(sb);
38145 + MtxMustLock(&sbinfo->si_xib_mtx);
38146 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
38147 + || !au_opt_test(sbinfo->si_mntflags, XINO));
38149 + if (pindex == sbinfo->si_xib_last_pindex)
38152 + xib = sbinfo->si_xib;
38153 + p = sbinfo->si_xib_buf;
38154 + pos = sbinfo->si_xib_last_pindex;
38155 + pos *= PAGE_SIZE;
38156 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
38157 + if (unlikely(sz != PAGE_SIZE))
38161 + pos *= PAGE_SIZE;
38162 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
38163 + sz = xino_fread(xib, p, PAGE_SIZE, &pos);
38165 + memset(p, 0, PAGE_SIZE);
38166 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
38168 + if (sz == PAGE_SIZE) {
38169 + sbinfo->si_xib_last_pindex = pindex;
38170 + return 0; /* success */
38174 + AuIOErr1("write failed (%zd)\n", sz);
38181 +static void au_xib_clear_bit(struct inode *inode)
38184 + unsigned long pindex;
38185 + struct super_block *sb;
38186 + struct au_sbinfo *sbinfo;
38188 + AuDebugOn(inode->i_nlink);
38190 + sb = inode->i_sb;
38191 + xib_calc_bit(inode->i_ino, &pindex, &bit);
38192 + AuDebugOn(page_bits <= bit);
38193 + sbinfo = au_sbi(sb);
38194 + mutex_lock(&sbinfo->si_xib_mtx);
38195 + err = xib_pindex(sb, pindex);
38197 + clear_bit(bit, sbinfo->si_xib_buf);
38198 + sbinfo->si_xib_next_bit = bit;
38200 + mutex_unlock(&sbinfo->si_xib_mtx);
38203 +/* ---------------------------------------------------------------------- */
38206 + * truncate a xino bitmap file
38210 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
38214 + unsigned long pindex;
38215 + loff_t pos, pend;
38216 + struct au_sbinfo *sbinfo;
38218 + unsigned long *p;
38221 + sbinfo = au_sbi(sb);
38222 + MtxMustLock(&sbinfo->si_xib_mtx);
38223 + p = sbinfo->si_xib_buf;
38224 + pend = vfsub_f_size_read(file);
38226 + while (pos < pend) {
38227 + sz = xino_fread(file, page, PAGE_SIZE, &pos);
38229 + if (unlikely(sz <= 0))
38233 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
38234 + if (unlikely(*ino < AUFS_FIRST_INO))
38237 + xib_calc_bit(*ino, &pindex, &bit);
38238 + AuDebugOn(page_bits <= bit);
38239 + err = xib_pindex(sb, pindex);
38251 +static int xib_restore(struct super_block *sb)
38254 + unsigned int nfile;
38255 + aufs_bindex_t bindex, bbot;
38257 + struct au_branch *br;
38258 + struct au_xino *xi;
38259 + struct file *file;
38262 + page = (void *)__get_free_page(GFP_NOFS);
38263 + if (unlikely(!page))
38267 + bbot = au_sbbot(sb);
38268 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38269 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38270 + br = au_sbr(sb, bindex);
38271 + xi = br->br_xino;
38272 + nfile = xi->xi_nfile;
38273 + for (i = 0; i < nfile; i++) {
38274 + file = au_xino_file(xi, i);
38276 + err = do_xib_restore(sb, file, page);
38279 + AuDbg("skip shared b%d\n", bindex);
38280 + free_page((unsigned long)page);
38286 +int au_xib_trunc(struct super_block *sb)
38291 + struct au_sbinfo *sbinfo;
38292 + unsigned long *p;
38293 + struct file *file;
38295 + SiMustWriteLock(sb);
38298 + sbinfo = au_sbi(sb);
38299 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38302 + file = sbinfo->si_xib;
38303 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38306 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38307 + err = PTR_ERR(file);
38308 + if (IS_ERR(file))
38310 + fput(sbinfo->si_xib);
38311 + sbinfo->si_xib = file;
38313 + p = sbinfo->si_xib_buf;
38314 + memset(p, 0, PAGE_SIZE);
38316 + sz = xino_fwrite(sbinfo->si_xib, p, PAGE_SIZE, &pos);
38317 + if (unlikely(sz != PAGE_SIZE)) {
38319 + AuIOErr("err %d\n", err);
38325 + mutex_lock(&sbinfo->si_xib_mtx);
38326 + /* mnt_want_write() is unnecessary here */
38327 + err = xib_restore(sb);
38328 + mutex_unlock(&sbinfo->si_xib_mtx);
38334 +/* ---------------------------------------------------------------------- */
38336 +struct au_xino *au_xino_alloc(unsigned int nfile)
38338 + struct au_xino *xi;
38340 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38341 + if (unlikely(!xi))
38343 + xi->xi_nfile = nfile;
38344 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38345 + if (unlikely(!xi->xi_file))
38348 + xi->xi_nondir.total = 8; /* initial size */
38349 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38351 + if (unlikely(!xi->xi_nondir.array))
38354 + spin_lock_init(&xi->xi_nondir.spin);
38355 + init_waitqueue_head(&xi->xi_nondir.wqh);
38356 + mutex_init(&xi->xi_mtx);
38357 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38358 + atomic_set(&xi->xi_truncating, 0);
38359 + kref_init(&xi->xi_kref);
38360 + goto out; /* success */
38363 + au_kfree_try_rcu(xi->xi_file);
38365 + au_kfree_rcu(xi);
38371 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38374 + struct au_xino *xi;
38377 + xi = au_xino_alloc(idx + 1);
38378 + if (unlikely(!xi)) {
38385 + xi->xi_file[idx] = file;
38386 + AuDebugOn(br->br_xino);
38387 + br->br_xino = xi;
38393 +static void au_xino_release(struct kref *kref)
38395 + struct au_xino *xi;
38397 + unsigned long ul;
38398 + struct hlist_bl_head *hbl;
38399 + struct hlist_bl_node *pos, *n;
38400 + struct au_xi_writing *p;
38402 + xi = container_of(kref, struct au_xino, xi_kref);
38403 + for (i = 0; i < xi->xi_nfile; i++)
38404 + if (xi->xi_file[i])
38405 + fput(xi->xi_file[i]);
38406 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38407 + AuDebugOn(xi->xi_nondir.array[i]);
38408 + mutex_destroy(&xi->xi_mtx);
38409 + hbl = &xi->xi_writing;
38410 + ul = au_hbl_count(hbl);
38411 + if (unlikely(ul)) {
38412 + pr_warn("xi_writing %lu\n", ul);
38413 + hlist_bl_lock(hbl);
38414 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
38415 + hlist_bl_del(&p->node);
38416 + /* kmemleak reported au_kfree_rcu() doesn't free it */
38419 + hlist_bl_unlock(hbl);
38421 + au_kfree_try_rcu(xi->xi_file);
38422 + au_kfree_try_rcu(xi->xi_nondir.array);
38423 + au_kfree_rcu(xi);
38426 +int au_xino_put(struct au_branch *br)
38429 + struct au_xino *xi;
38432 + xi = br->br_xino;
38434 + br->br_xino = NULL;
38435 + ret = kref_put(&xi->xi_kref, au_xino_release);
38441 +/* ---------------------------------------------------------------------- */
38444 + * xino mount option handlers
38448 +static void xino_clear_xib(struct super_block *sb)
38450 + struct au_sbinfo *sbinfo;
38452 + SiMustWriteLock(sb);
38454 + sbinfo = au_sbi(sb);
38455 + if (sbinfo->si_xib)
38456 + fput(sbinfo->si_xib);
38457 + sbinfo->si_xib = NULL;
38458 + if (sbinfo->si_xib_buf)
38459 + free_page((unsigned long)sbinfo->si_xib_buf);
38460 + sbinfo->si_xib_buf = NULL;
38463 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38467 + struct au_sbinfo *sbinfo;
38468 + struct file *file;
38469 + struct super_block *xi_sb;
38471 + SiMustWriteLock(sb);
38473 + sbinfo = au_sbi(sb);
38474 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38475 + err = PTR_ERR(file);
38476 + if (IS_ERR(file))
38478 + if (sbinfo->si_xib)
38479 + fput(sbinfo->si_xib);
38480 + sbinfo->si_xib = file;
38481 + xi_sb = file_inode(file)->i_sb;
38482 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38483 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38485 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38486 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38489 + sbinfo->si_ximaxent /= sizeof(ino_t);
38492 + if (!sbinfo->si_xib_buf)
38493 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38494 + if (unlikely(!sbinfo->si_xib_buf))
38497 + sbinfo->si_xib_last_pindex = 0;
38498 + sbinfo->si_xib_next_bit = 0;
38499 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38501 + err = xino_fwrite(file, sbinfo->si_xib_buf, PAGE_SIZE, &pos);
38502 + if (unlikely(err != PAGE_SIZE))
38506 + goto out; /* success */
38509 + if (sbinfo->si_xib_buf)
38510 + free_page((unsigned long)sbinfo->si_xib_buf);
38511 + sbinfo->si_xib_buf = NULL;
38515 + fput(sbinfo->si_xib);
38516 + sbinfo->si_xib = NULL;
38522 +/* xino for each branch */
38523 +static void xino_clear_br(struct super_block *sb)
38525 + aufs_bindex_t bindex, bbot;
38526 + struct au_branch *br;
38528 + bbot = au_sbbot(sb);
38529 + for (bindex = 0; bindex <= bbot; bindex++) {
38530 + br = au_sbr(sb, bindex);
38536 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38537 + aufs_bindex_t bshared)
38539 + struct au_branch *brshared;
38541 + brshared = au_sbr(sb, bshared);
38542 + AuDebugOn(!brshared->br_xino);
38543 + AuDebugOn(!brshared->br_xino->xi_file);
38544 + if (br->br_xino != brshared->br_xino) {
38545 + au_xino_get(brshared);
38547 + br->br_xino = brshared->br_xino;
38551 +struct au_xino_do_set_br {
38552 + struct au_branch *br;
38554 + aufs_bindex_t bshared;
38557 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38558 + struct au_xino_do_set_br *args)
38561 + struct au_xi_calc calc;
38562 + struct file *file;
38563 + struct au_branch *br;
38564 + struct au_xi_new xinew = {
38569 + xinew.xi = br->br_xino;
38570 + au_xi_calc(sb, args->h_ino, &calc);
38571 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38572 + if (args->bshared >= 0)
38573 + /* shared xino */
38574 + au_xino_set_br_shared(sb, br, args->bshared);
38575 + else if (!xinew.xi) {
38577 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38578 + if (unlikely(err))
38582 + /* force re-creating */
38583 + xinew.xi = br->br_xino;
38584 + xinew.idx = calc.idx;
38585 + mutex_lock(&xinew.xi->xi_mtx);
38586 + file = au_xi_new(sb, &xinew);
38587 + mutex_unlock(&xinew.xi->xi_mtx);
38588 + err = PTR_ERR(file);
38589 + if (IS_ERR(file))
38591 + AuDebugOn(!file);
38593 + err = au_xino_do_write(file, &calc, AUFS_ROOT_INO);
38594 + if (unlikely(err))
38602 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38605 + aufs_bindex_t bindex, bbot;
38606 + struct au_xino_do_set_br args;
38607 + struct inode *inode;
38609 + SiMustWriteLock(sb);
38611 + bbot = au_sbbot(sb);
38612 + inode = d_inode(sb->s_root);
38613 + for (bindex = 0; bindex <= bbot; bindex++) {
38614 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38615 + args.br = au_sbr(sb, bindex);
38616 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38617 + err = au_xino_do_set_br(sb, path, &args);
38618 + if (unlikely(err))
38626 +void au_xino_clr(struct super_block *sb)
38628 + struct au_sbinfo *sbinfo;
38630 + au_xigen_clr(sb);
38631 + xino_clear_xib(sb);
38632 + xino_clear_br(sb);
38633 + dbgaufs_brs_del(sb, 0);
38634 + sbinfo = au_sbi(sb);
38635 + /* lvalue, do not call au_mntflags() */
38636 + au_opt_clr(sbinfo->si_mntflags, XINO);
38639 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38642 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38643 + struct qstr *dname, *cur_name;
38644 + struct file *cur_xino;
38645 + struct au_sbinfo *sbinfo;
38646 + struct path *path, *cur_path;
38648 + SiMustWriteLock(sb);
38651 + sbinfo = au_sbi(sb);
38652 + path = &xiopt->file->f_path;
38653 + dentry = path->dentry;
38654 + parent = dget_parent(dentry);
38657 + cur_xino = sbinfo->si_xib;
38659 + cur_path = &cur_xino->f_path;
38660 + cur_dentry = cur_path->dentry;
38661 + cur_parent = dget_parent(cur_dentry);
38662 + cur_name = &cur_dentry->d_name;
38663 + dname = &dentry->d_name;
38664 + skip = (cur_parent == parent
38665 + && au_qstreq(dname, cur_name));
38666 + dput(cur_parent);
38672 + au_opt_set(sbinfo->si_mntflags, XINO);
38673 + err = au_xino_set_xib(sb, path);
38674 + /* si_x{read,write} are set */
38676 + err = au_xigen_set(sb, path);
38678 + err = au_xino_set_br(sb, path);
38680 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38681 + goto out; /* success */
38685 + AuIOErr("failed setting xino(%d).\n", err);
38694 + * create a xinofile at the default place/path.
38696 +struct file *au_xino_def(struct super_block *sb)
38698 + struct file *file;
38700 + struct au_branch *br;
38701 + struct super_block *h_sb;
38702 + struct path path;
38703 + aufs_bindex_t bbot, bindex, bwr;
38706 + bbot = au_sbbot(sb);
38708 + for (bindex = 0; bindex <= bbot; bindex++) {
38709 + br = au_sbr(sb, bindex);
38710 + if (au_br_writable(br->br_perm)
38711 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38718 + file = ERR_PTR(-ENOMEM);
38719 + page = (void *)__get_free_page(GFP_NOFS);
38720 + if (unlikely(!page))
38722 + path.mnt = au_br_mnt(br);
38723 + path.dentry = au_h_dptr(sb->s_root, bwr);
38724 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38725 + file = (void *)p;
38726 + if (!IS_ERR(p)) {
38727 + strcat(p, "/" AUFS_XINO_FNAME);
38728 + AuDbg("%s\n", p);
38729 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38731 + free_page((unsigned long)page);
38733 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38735 + if (IS_ERR(file))
38737 + h_sb = file->f_path.dentry->d_sb;
38738 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38739 + pr_err("xino doesn't support %s(%s)\n",
38740 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38742 + file = ERR_PTR(-EINVAL);
38750 +/* ---------------------------------------------------------------------- */
38753 + * initialize the xinofile for the specified branch @br
38754 + * at the place/path where @base_file indicates.
38755 + * test whether another branch is on the same filesystem or not,
38756 + * if found then share the xinofile with another branch.
38758 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38759 + struct path *base)
38762 + struct au_xino_do_set_br args = {
38767 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38769 + err = au_xino_do_set_br(sb, base, &args);
38770 + if (unlikely(err))
38776 +/* ---------------------------------------------------------------------- */
38779 + * get an unused inode number from bitmap
38781 +ino_t au_xino_new_ino(struct super_block *sb)
38784 + unsigned long *p, pindex, ul, pend;
38785 + struct au_sbinfo *sbinfo;
38786 + struct file *file;
38787 + int free_bit, err;
38789 + if (!au_opt_test(au_mntflags(sb), XINO))
38790 + return iunique(sb, AUFS_FIRST_INO);
38792 + sbinfo = au_sbi(sb);
38793 + mutex_lock(&sbinfo->si_xib_mtx);
38794 + p = sbinfo->si_xib_buf;
38795 + free_bit = sbinfo->si_xib_next_bit;
38796 + if (free_bit < page_bits && !test_bit(free_bit, p))
38797 + goto out; /* success */
38798 + free_bit = find_first_zero_bit(p, page_bits);
38799 + if (free_bit < page_bits)
38800 + goto out; /* success */
38802 + pindex = sbinfo->si_xib_last_pindex;
38803 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38804 + err = xib_pindex(sb, ul);
38805 + if (unlikely(err))
38807 + free_bit = find_first_zero_bit(p, page_bits);
38808 + if (free_bit < page_bits)
38809 + goto out; /* success */
38812 + file = sbinfo->si_xib;
38813 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38814 + for (ul = pindex + 1; ul <= pend; ul++) {
38815 + err = xib_pindex(sb, ul);
38816 + if (unlikely(err))
38818 + free_bit = find_first_zero_bit(p, page_bits);
38819 + if (free_bit < page_bits)
38820 + goto out; /* success */
38825 + set_bit(free_bit, p);
38826 + sbinfo->si_xib_next_bit = free_bit + 1;
38827 + pindex = sbinfo->si_xib_last_pindex;
38828 + mutex_unlock(&sbinfo->si_xib_mtx);
38829 + ino = xib_calc_ino(pindex, free_bit);
38830 + AuDbg("i%lu\n", (unsigned long)ino);
38833 + mutex_unlock(&sbinfo->si_xib_mtx);
38838 +/* for s_op->delete_inode() */
38839 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38842 + unsigned int mnt_flags;
38843 + aufs_bindex_t bindex, bbot, bi;
38844 + unsigned char try_trunc;
38845 + struct au_iinfo *iinfo;
38846 + struct super_block *sb;
38847 + struct au_hinode *hi;
38848 + struct inode *h_inode;
38849 + struct au_branch *br;
38850 + struct au_xi_calc calc;
38851 + struct file *file;
38853 + AuDebugOn(au_is_bad_inode(inode));
38855 + sb = inode->i_sb;
38856 + mnt_flags = au_mntflags(sb);
38857 + if (!au_opt_test(mnt_flags, XINO)
38858 + || inode->i_ino == AUFS_ROOT_INO)
38862 + au_xigen_inc(inode);
38863 + au_xib_clear_bit(inode);
38866 + iinfo = au_ii(inode);
38867 + bindex = iinfo->ii_btop;
38871 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38872 + hi = au_hinode(iinfo, bindex);
38873 + bbot = iinfo->ii_bbot;
38874 + for (; bindex <= bbot; bindex++, hi++) {
38875 + h_inode = hi->hi_inode;
38877 + || (!unlinked && h_inode->i_nlink))
38880 + /* inode may not be revalidated */
38881 + bi = au_br_index(sb, hi->hi_id);
38885 + br = au_sbr(sb, bi);
38886 + au_xi_calc(sb, h_inode->i_ino, &calc);
38887 + file = au_xino_file(br->br_xino, calc.idx);
38888 + if (IS_ERR_OR_NULL(file))
38891 + err = au_xino_do_write(file, &calc, /*ino*/0);
38892 + if (!err && try_trunc
38893 + && au_test_fs_trunc_xino(au_br_sb(br)))
38894 + xino_try_trunc(sb, br);
38898 +/* ---------------------------------------------------------------------- */
38900 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38902 + int found, total, i;
38905 + total = xi->xi_nondir.total;
38906 + for (i = 0; i < total; i++) {
38907 + if (xi->xi_nondir.array[i] != h_ino)
38916 +static int au_xinondir_expand(struct au_xino *xi)
38921 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38924 + sz = xi->xi_nondir.total * sizeof(ino_t);
38925 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38927 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38928 + /*may_shrink*/0);
38930 + xi->xi_nondir.array = p;
38931 + xi->xi_nondir.total <<= 1;
38932 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38940 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38941 + ino_t h_ino, int idx)
38943 + struct au_xino *xi;
38945 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38946 + xi = au_sbr(sb, bindex)->br_xino;
38947 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38949 + spin_lock(&xi->xi_nondir.spin);
38950 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38951 + xi->xi_nondir.array[idx] = 0;
38952 + spin_unlock(&xi->xi_nondir.spin);
38953 + wake_up_all(&xi->xi_nondir.wqh);
38956 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38959 + int err, found, empty;
38960 + struct au_xino *xi;
38964 + if (!au_opt_test(au_mntflags(sb), XINO))
38965 + goto out; /* no xino */
38967 + xi = au_sbr(sb, bindex)->br_xino;
38970 + spin_lock(&xi->xi_nondir.spin);
38971 + found = au_xinondir_find(xi, h_ino);
38972 + if (found == -1) {
38973 + empty = au_xinondir_find(xi, /*h_ino*/0);
38974 + if (empty == -1) {
38975 + empty = xi->xi_nondir.total;
38976 + err = au_xinondir_expand(xi);
38977 + if (unlikely(err))
38980 + xi->xi_nondir.array[empty] = h_ino;
38983 + spin_unlock(&xi->xi_nondir.spin);
38984 + wait_event(xi->xi_nondir.wqh,
38985 + xi->xi_nondir.array[found] != h_ino);
38990 + spin_unlock(&xi->xi_nondir.spin);
38995 +/* ---------------------------------------------------------------------- */
38997 +int au_xino_path(struct seq_file *seq, struct file *file)
39001 + err = au_seq_path(seq, &file->f_path);
39002 + if (unlikely(err))
39005 +#define Deleted "\\040(deleted)"
39006 + seq->count -= sizeof(Deleted) - 1;
39007 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
39008 + sizeof(Deleted) - 1));
39014 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
39015 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
39016 +++ linux/include/uapi/linux/aufs_type.h 2022-12-17 09:21:34.803188528 +0100
39018 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
39020 + * Copyright (C) 2005-2022 Junjiro R. Okajima
39022 + * This program is free software; you can redistribute it and/or modify
39023 + * it under the terms of the GNU General Public License as published by
39024 + * the Free Software Foundation; either version 2 of the License, or
39025 + * (at your option) any later version.
39027 + * This program is distributed in the hope that it will be useful,
39028 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
39029 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39030 + * GNU General Public License for more details.
39032 + * You should have received a copy of the GNU General Public License
39033 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
39036 +#ifndef __AUFS_TYPE_H__
39037 +#define __AUFS_TYPE_H__
39039 +#define AUFS_NAME "aufs"
39043 + * define it before including all other headers.
39044 + * sched.h may use pr_* macros before defining "current", so define the
39045 + * no-current version first, and re-define later.
39047 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
39048 +#include <linux/sched.h>
39050 +#define pr_fmt(fmt) \
39051 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
39052 + (int)sizeof(current->comm), current->comm, current->pid
39053 +#include <linux/limits.h>
39055 +#include <stdint.h>
39056 +#include <sys/types.h>
39057 +#include <limits.h>
39058 +#endif /* __KERNEL__ */
39060 +#define AUFS_VERSION "6.x-rcN-20221107"
39062 +/* todo? move this to linux-2.6.19/include/magic.h */
39063 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
39065 +/* ---------------------------------------------------------------------- */
39068 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
39069 +typedef int8_t aufs_bindex_t;
39070 +#define AUFS_BRANCH_MAX 127
39072 +typedef int16_t aufs_bindex_t;
39073 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
39074 +#define AUFS_BRANCH_MAX 511
39075 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
39076 +#define AUFS_BRANCH_MAX 1023
39077 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
39078 +#define AUFS_BRANCH_MAX 32767
39082 +#ifndef AUFS_BRANCH_MAX
39083 +#error unknown CONFIG_AUFS_BRANCH_MAX value
39085 +#endif /* __KERNEL__ */
39087 +/* ---------------------------------------------------------------------- */
39089 +#define AUFS_FSTYPE AUFS_NAME
39091 +#define AUFS_ROOT_INO 2
39092 +#define AUFS_FIRST_INO 11
39094 +#define AUFS_WH_PFX ".wh."
39095 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
39096 +#define AUFS_WH_TMP_LEN 4
39097 +/* a limit for rmdir/rename a dir and copyup */
39098 +#define AUFS_MAX_NAMELEN (NAME_MAX \
39099 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
39101 + - AUFS_WH_TMP_LEN) /* hex */
39102 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
39103 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
39104 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
39105 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
39106 +#define AUFS_DIRWH_DEF 3
39107 +#define AUFS_RDCACHE_DEF 10 /* seconds */
39108 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
39109 +#define AUFS_RDBLK_DEF 512 /* bytes */
39110 +#define AUFS_RDHASH_DEF 32
39111 +#define AUFS_WKQ_NAME AUFS_NAME "d"
39112 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
39113 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
39114 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
39115 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
39117 +/* pseudo-link maintenace under /proc */
39118 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
39119 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
39120 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
39122 +/* dirren, renamed dir */
39123 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
39124 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
39125 +/* whiteouted doubly */
39126 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
39127 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
39129 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
39130 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
39132 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
39133 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
39134 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
39136 +/* doubly whiteouted */
39137 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
39138 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
39139 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
39141 +/* branch permissions and attributes */
39142 +#define AUFS_BRPERM_RW "rw"
39143 +#define AUFS_BRPERM_RO "ro"
39144 +#define AUFS_BRPERM_RR "rr"
39145 +#define AUFS_BRATTR_COO_REG "coo_reg"
39146 +#define AUFS_BRATTR_COO_ALL "coo_all"
39147 +#define AUFS_BRATTR_FHSM "fhsm"
39148 +#define AUFS_BRATTR_UNPIN "unpin"
39149 +#define AUFS_BRATTR_ICEX "icex"
39150 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
39151 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
39152 +#define AUFS_BRATTR_ICEX_TR "icextr"
39153 +#define AUFS_BRATTR_ICEX_USR "icexusr"
39154 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
39155 +#define AUFS_BRRATTR_WH "wh"
39156 +#define AUFS_BRWATTR_NLWH "nolwh"
39157 +#define AUFS_BRWATTR_MOO "moo"
39159 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
39160 +#define AuBrPerm_RO (1 << 1) /* readonly */
39161 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
39162 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
39164 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
39165 +#define AuBrAttr_COO_ALL (1 << 4)
39166 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
39168 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
39169 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
39170 + branch. meaningless since
39171 + linux-3.18-rc1 */
39173 +/* ignore error in copying XATTR */
39174 +#define AuBrAttr_ICEX_SEC (1 << 7)
39175 +#define AuBrAttr_ICEX_SYS (1 << 8)
39176 +#define AuBrAttr_ICEX_TR (1 << 9)
39177 +#define AuBrAttr_ICEX_USR (1 << 10)
39178 +#define AuBrAttr_ICEX_OTH (1 << 11)
39179 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
39180 + | AuBrAttr_ICEX_SYS \
39181 + | AuBrAttr_ICEX_TR \
39182 + | AuBrAttr_ICEX_USR \
39183 + | AuBrAttr_ICEX_OTH)
39185 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
39186 +#define AuBrRAttr_Mask AuBrRAttr_WH
39188 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
39189 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
39190 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
39192 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
39194 +/* #warning test userspace */
39196 +#ifndef CONFIG_AUFS_FHSM
39197 +#undef AuBrAttr_FHSM
39198 +#define AuBrAttr_FHSM 0
39200 +#ifndef CONFIG_AUFS_XATTR
39201 +#undef AuBrAttr_ICEX
39202 +#define AuBrAttr_ICEX 0
39203 +#undef AuBrAttr_ICEX_SEC
39204 +#define AuBrAttr_ICEX_SEC 0
39205 +#undef AuBrAttr_ICEX_SYS
39206 +#define AuBrAttr_ICEX_SYS 0
39207 +#undef AuBrAttr_ICEX_TR
39208 +#define AuBrAttr_ICEX_TR 0
39209 +#undef AuBrAttr_ICEX_USR
39210 +#define AuBrAttr_ICEX_USR 0
39211 +#undef AuBrAttr_ICEX_OTH
39212 +#define AuBrAttr_ICEX_OTH 0
39216 +/* the longest combination */
39217 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
39218 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
39219 + "+" AUFS_BRATTR_COO_REG \
39220 + "+" AUFS_BRATTR_FHSM \
39221 + "+" AUFS_BRATTR_UNPIN \
39222 + "+" AUFS_BRATTR_ICEX_SEC \
39223 + "+" AUFS_BRATTR_ICEX_SYS \
39224 + "+" AUFS_BRATTR_ICEX_USR \
39225 + "+" AUFS_BRATTR_ICEX_OTH \
39226 + "+" AUFS_BRWATTR_NLWH)
39229 + char a[AuBrPermStrSz];
39230 +} au_br_perm_str_t;
39232 +static inline int au_br_writable(int brperm)
39234 + return brperm & AuBrPerm_RW;
39237 +static inline int au_br_whable(int brperm)
39239 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
39242 +static inline int au_br_wh_linkable(int brperm)
39244 + return !(brperm & AuBrWAttr_NoLinkWH);
39247 +static inline int au_br_cmoo(int brperm)
39249 + return brperm & AuBrAttr_CMOO_Mask;
39252 +static inline int au_br_fhsm(int brperm)
39254 + return brperm & AuBrAttr_FHSM;
39257 +/* ---------------------------------------------------------------------- */
39261 + /* readdir in userspace */
39265 + AuCtl_WBR_FD, /* pathconf wrapper */
39266 + AuCtl_IBUSY, /* busy inode */
39267 + AuCtl_MVDOWN, /* move-down */
39268 + AuCtl_BR, /* info about branches */
39269 + AuCtl_FHSM_FD /* connection for fhsm */
39272 +/* borrowed from linux/include/linux/kernel.h */
39274 +#ifdef _GNU_SOURCE
39275 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39277 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
39279 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39282 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39284 +#define __aligned(x) __attribute__((aligned(x)))
39289 +#define __packed __attribute__((packed))
39293 +struct au_rdu_cookie {
39298 + uint32_t generation;
39301 +struct au_rdu_ent {
39310 +static inline int au_rdu_len(int nlen)
39312 + /* include the terminating NULL */
39313 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39314 + sizeof(uint64_t));
39317 +union au_rdu_ent_ul {
39318 + struct au_rdu_ent __user *e;
39330 + uint64_t sz; /* AuCtl_RDU */
39331 + uint64_t nent; /* AuCtl_RDU_INO */
39333 + union au_rdu_ent_ul ent;
39334 + uint16_t verify[AufsCtlRduV_End];
39336 + /* input/output */
39340 + union au_rdu_ent_ul tail;
39341 + /* number of entries which were added in a single call */
39346 + struct au_rdu_cookie cookie;
39349 +/* ---------------------------------------------------------------------- */
39351 +/* dirren. the branch is identified by the filename who contains this */
39352 +struct au_drinfo {
39355 + uint8_t oldnamelen;
39356 + uint64_t _padding;
39358 + uint8_t oldname[];
39361 +struct au_drinfo_fdata {
39363 + struct au_drinfo drinfo;
39366 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39368 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39370 +/* ---------------------------------------------------------------------- */
39372 +struct aufs_wbr_fd {
39377 +/* ---------------------------------------------------------------------- */
39379 +struct aufs_ibusy {
39380 + uint64_t ino, h_ino;
39384 +/* ---------------------------------------------------------------------- */
39386 +/* error code for move-down */
39387 +/* the actual message strings are implemented in aufs-util.git */
39389 + EAU_MVDOWN_OPAQUE = 1,
39390 + EAU_MVDOWN_WHITEOUT,
39391 + EAU_MVDOWN_UPPER,
39392 + EAU_MVDOWN_BOTTOM,
39393 + EAU_MVDOWN_NOUPPER,
39394 + EAU_MVDOWN_NOLOWERBR,
39398 +/* flags for move-down */
39399 +#define AUFS_MVDOWN_DMSG 1
39400 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39401 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39402 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39403 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39404 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39405 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39406 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39407 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39408 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39409 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39410 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39411 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39413 +/* index for move-down */
39415 + AUFS_MVDOWN_UPPER,
39416 + AUFS_MVDOWN_LOWER,
39417 + AUFS_MVDOWN_NARRAY
39421 + * additional info of move-down
39422 + * number of free blocks and inodes.
39423 + * subset of struct kstatfs, but smaller and always 64bit.
39425 +struct aufs_stfs {
39426 + uint64_t f_blocks;
39427 + uint64_t f_bavail;
39428 + uint64_t f_files;
39429 + uint64_t f_ffree;
39432 +struct aufs_stbr {
39433 + int16_t brid; /* optional input */
39434 + int16_t bindex; /* output */
39435 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39438 +struct aufs_mvdown {
39439 + uint32_t flags; /* input/output */
39440 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39441 + int8_t au_errno; /* output */
39444 +/* ---------------------------------------------------------------------- */
39446 +union aufs_brinfo {
39447 + /* PATH_MAX may differ between kernel-space and user-space */
39448 + char _spacer[4096];
39456 +/* ---------------------------------------------------------------------- */
39458 +#define AuCtlType 'A'
39459 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39460 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39461 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39462 + struct aufs_wbr_fd)
39463 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39464 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39465 + struct aufs_mvdown)
39466 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39467 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39469 +#endif /* __AUFS_TYPE_H__ */
39470 SPDX-License-Identifier: GPL-2.0
39471 aufs6.x-rcN loopback patch
39473 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39474 index 8ca56da3ca69..9ac6f67edf09 100644
39475 --- a/drivers/block/loop.c
39476 +++ b/drivers/block/loop.c
39477 @@ -54,7 +54,7 @@ struct loop_device {
39479 char lo_file_name[LO_NAME_SIZE];
39481 - struct file * lo_backing_file;
39482 + struct file *lo_backing_file, *lo_backing_virt_file;
39483 struct block_device *lo_device;
39485 gfp_t old_gfp_mask;
39486 @@ -510,6 +510,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39490 +static struct file *loop_real_file(struct file *file)
39492 + struct file *f = NULL;
39494 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39495 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39499 static void loop_reread_partitions(struct loop_device *lo)
39502 @@ -567,6 +576,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39504 struct file *file = fget(arg);
39505 struct file *old_file;
39506 + struct file *f, *virt_file = NULL, *old_virt_file;
39510 @@ -590,11 +600,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39511 if (!(lo->lo_flags & LO_FLAGS_READ_ONLY))
39514 + f = loop_real_file(file);
39516 + virt_file = file;
39521 error = loop_validate_file(file, bdev);
39525 old_file = lo->lo_backing_file;
39526 + old_virt_file = lo->lo_backing_virt_file;
39530 @@ -607,6 +625,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39531 blk_mq_freeze_queue(lo->lo_queue);
39532 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39533 lo->lo_backing_file = file;
39534 + lo->lo_backing_virt_file = virt_file;
39535 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39536 mapping_set_gfp_mask(file->f_mapping,
39537 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39538 @@ -629,6 +648,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39542 + if (old_virt_file)
39543 + fput(old_virt_file);
39545 loop_reread_partitions(lo);
39547 @@ -642,6 +663,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39548 loop_global_unlock(lo, is_loop);
39556 @@ -1013,6 +1036,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39557 const struct loop_config *config)
39559 struct file *file = fget(config->fd);
39560 + struct file *f, *virt_file = NULL;
39561 struct inode *inode;
39562 struct address_space *mapping;
39564 @@ -1031,6 +1055,13 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39565 /* This is safe, since we have a reference from open(). */
39566 __module_get(THIS_MODULE);
39568 + f = loop_real_file(file);
39570 + virt_file = file;
39576 * If we don't hold exclusive handle for the device, upgrade to it
39577 * here to avoid changing device under exclusive owner.
39578 @@ -1091,6 +1122,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39579 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39580 lo->lo_device = bdev;
39581 lo->lo_backing_file = file;
39582 + lo->lo_backing_virt_file = virt_file;
39583 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39584 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39586 @@ -1146,6 +1178,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39587 bd_abort_claiming(bdev, loop_configure);
39592 /* This is safe: open() is still holding a reference. */
39593 module_put(THIS_MODULE);
39595 @@ -1154,6 +1188,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39596 static void __loop_clr_fd(struct loop_device *lo, bool release)
39599 + struct file *virt_filp = lo->lo_backing_virt_file;
39600 gfp_t gfp = lo->old_gfp_mask;
39602 if (test_bit(QUEUE_FLAG_WC, &lo->lo_queue->queue_flags))
39603 @@ -1170,6 +1205,7 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
39604 spin_lock_irq(&lo->lo_lock);
39605 filp = lo->lo_backing_file;
39606 lo->lo_backing_file = NULL;
39607 + lo->lo_backing_virt_file = NULL;
39608 spin_unlock_irq(&lo->lo_lock);
39610 lo->lo_device = NULL;
39611 @@ -1232,6 +1268,8 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
39612 * fput can take open_mutex which is usually taken before lo_mutex.
39619 static int loop_clr_fd(struct loop_device *lo)
39620 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39621 index 66ddf86a3331..6cbef597d5b9 100644
39622 --- a/fs/aufs/f_op.c
39623 +++ b/fs/aufs/f_op.c
39624 @@ -309,7 +309,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39625 if (IS_ERR(h_file))
39628 - if (au_test_loopback_kthread()) {
39629 + if (0 && au_test_loopback_kthread()) {
39630 au_warn_loopback(h_file->f_path.dentry->d_sb);
39631 if (file->f_mapping != h_file->f_mapping) {
39632 file->f_mapping = h_file->f_mapping;
39633 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39634 index 58043e31e5f3..e2bfae6f9d59 100644
39635 --- a/fs/aufs/loop.c
39636 +++ b/fs/aufs/loop.c
39637 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39638 symbol_put(loop_backing_file);
39639 au_kfree_try_rcu(au_warn_loopback_array);
39642 +/* ---------------------------------------------------------------------- */
39644 +/* support the loopback block device insude aufs */
39646 +struct file *aufs_real_loop(struct file *file)
39650 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39651 + fi_read_lock(file);
39652 + f = au_hf_top(file);
39653 + fi_read_unlock(file);
39657 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39658 index 03d4908a6c03..34d356e181d5 100644
39659 --- a/fs/aufs/loop.h
39660 +++ b/fs/aufs/loop.h
39661 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39663 int au_loopback_init(void);
39664 void au_loopback_fin(void);
39666 +struct file *aufs_real_loop(struct file *file);
39668 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39670 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39672 AuStubInt0(au_loopback_init, void)
39673 AuStubVoid(au_loopback_fin, void)
39675 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39676 #endif /* BLK_DEV_LOOP */
39678 #endif /* __KERNEL__ */
39679 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39680 index 81922d4faf54..c8a62c267d72 100644
39681 --- a/fs/aufs/super.c
39682 +++ b/fs/aufs/super.c
39683 @@ -758,7 +758,10 @@ const struct super_operations aufs_sop = {
39684 .show_options = aufs_show_options,
39685 .statfs = aufs_statfs,
39686 .put_super = aufs_put_super,
39687 - .sync_fs = aufs_sync_fs
39688 + .sync_fs = aufs_sync_fs,
39689 +#ifdef CONFIG_AUFS_BDEV_LOOP
39690 + .real_loop = aufs_real_loop
39694 /* ---------------------------------------------------------------------- */
39695 diff --git a/include/linux/fs.h b/include/linux/fs.h
39696 index 433a4f08dab4..0b17b7e5ee11 100644
39697 --- a/include/linux/fs.h
39698 +++ b/include/linux/fs.h
39699 @@ -2257,6 +2257,10 @@ struct super_operations {
39700 struct shrink_control *);
39701 long (*free_cached_objects)(struct super_block *,
39702 struct shrink_control *);
39703 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39705 + struct file *(*real_loop)(struct file *);