1 SPDX-License-Identifier: GPL-2.0
2 aufs4.x-rcN kbuild patch
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index ac474a61be37..284cee954591 100644
8 @@ -255,5 +255,6 @@ source "fs/pstore/Kconfig"
9 source "fs/sysv/Kconfig"
10 source "fs/ufs/Kconfig"
11 +source "fs/aufs/Kconfig"
13 endif # MISC_FILESYSTEMS
15 diff --git a/fs/Makefile b/fs/Makefile
16 index 293733f61594..12d19d0de07a 100644
19 @@ -128,3 +128,4 @@ obj-y += exofs/ # Multiple modules
20 obj-$(CONFIG_CEPH_FS) += ceph/
21 obj-$(CONFIG_PSTORE) += pstore/
22 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
23 +obj-$(CONFIG_AUFS_FS) += aufs/
24 SPDX-License-Identifier: GPL-2.0
25 aufs4.x-rcN base patch
27 diff --git a/MAINTAINERS b/MAINTAINERS
28 index dce5c099f43c..d10f05c88860 100644
31 @@ -2635,6 +2635,19 @@ F: include/linux/audit.h
32 F: include/uapi/linux/audit.h
35 +AUFS (advanced multi layered unification filesystem) FILESYSTEM
36 +M: "J. R. Okajima" <hooanon05g@gmail.com>
37 +L: aufs-users@lists.sourceforge.net (members only)
38 +L: linux-unionfs@vger.kernel.org
39 +W: http://aufs.sourceforge.net
40 +T: git://github.com/sfjro/aufs4-linux.git
42 +F: Documentation/filesystems/aufs/
43 +F: Documentation/ABI/testing/debugfs-aufs
44 +F: Documentation/ABI/testing/sysfs-aufs
46 +F: include/uapi/linux/aufs_type.h
48 AUXILIARY DISPLAY DRIVERS
49 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
51 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
52 index cf5538942834..a271e17e4b10 100644
53 --- a/drivers/block/loop.c
54 +++ b/drivers/block/loop.c
55 @@ -738,6 +738,24 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
61 + * no get/put for file.
63 +struct file *loop_backing_file(struct super_block *sb)
66 + struct loop_device *l;
69 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
70 + l = sb->s_bdev->bd_disk->private_data;
71 + ret = l->lo_backing_file;
75 +EXPORT_SYMBOL_GPL(loop_backing_file);
77 /* loop sysfs attributes */
79 static ssize_t loop_attr_show(struct device *dev, char *page,
80 diff --git a/fs/dcache.c b/fs/dcache.c
81 index aac41adf4743..fc18967c2522 100644
84 @@ -1247,7 +1247,7 @@ enum d_walk_ret {
86 * The @enter() callbacks are called with d_lock held.
88 -static void d_walk(struct dentry *parent, void *data,
89 +void d_walk(struct dentry *parent, void *data,
90 enum d_walk_ret (*enter)(void *, struct dentry *))
92 struct dentry *this_parent;
93 diff --git a/fs/fcntl.c b/fs/fcntl.c
94 index 083185174c6d..78234ee16784 100644
99 #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
101 -static int setfl(int fd, struct file * filp, unsigned long arg)
102 +int setfl(int fd, struct file * filp, unsigned long arg)
104 struct inode * inode = file_inode(filp);
106 @@ -63,6 +63,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
108 if (filp->f_op->check_flags)
109 error = filp->f_op->check_flags(arg);
110 + if (!error && filp->f_op->setfl)
111 + error = filp->f_op->setfl(filp, arg);
115 diff --git a/fs/inode.c b/fs/inode.c
116 index 73432e64f874..4a1756b8b4bd 100644
119 @@ -1657,7 +1657,7 @@ EXPORT_SYMBOL(generic_update_time);
120 * This does the actual work of updating an inodes time or version. Must have
121 * had called mnt_want_write() before calling this.
123 -static int update_time(struct inode *inode, struct timespec64 *time, int flags)
124 +int update_time(struct inode *inode, struct timespec64 *time, int flags)
126 int (*update_time)(struct inode *, struct timespec64 *, int);
128 diff --git a/fs/namespace.c b/fs/namespace.c
129 index 678ef175d63a..9b6a3d0f87a1 100644
132 @@ -768,6 +768,12 @@ static inline int check_mnt(struct mount *mnt)
133 return mnt->mnt_ns == current->nsproxy->mnt_ns;
136 +/* for aufs, CONFIG_AUFS_BR_FUSE */
137 +int is_current_mnt_ns(struct vfsmount *mnt)
139 + return check_mnt(real_mount(mnt));
143 * vfsmount lock must be held for write
145 diff --git a/fs/read_write.c b/fs/read_write.c
146 index ff3c5e6f87cf..5c18a9e51f37 100644
147 --- a/fs/read_write.c
148 +++ b/fs/read_write.c
149 @@ -489,6 +489,28 @@ ssize_t __vfs_write(struct file *file, const char __user *p, size_t count,
153 +vfs_readf_t vfs_readf(struct file *file)
155 + const struct file_operations *fop = file->f_op;
159 + if (fop->read_iter)
160 + return new_sync_read;
161 + return ERR_PTR(-ENOSYS);
164 +vfs_writef_t vfs_writef(struct file *file)
166 + const struct file_operations *fop = file->f_op;
170 + if (fop->write_iter)
171 + return new_sync_write;
172 + return ERR_PTR(-ENOSYS);
175 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
178 diff --git a/fs/splice.c b/fs/splice.c
179 index de2ede048473..5dcf77b8e1b2 100644
182 @@ -837,8 +837,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
184 * Attempt to initiate a splice from pipe to file.
186 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
187 - loff_t *ppos, size_t len, unsigned int flags)
188 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
189 + loff_t *ppos, size_t len, unsigned int flags)
191 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
192 loff_t *, size_t, unsigned int);
193 @@ -854,9 +854,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
195 * Attempt to initiate a splice from a file to a pipe.
197 -static long do_splice_to(struct file *in, loff_t *ppos,
198 - struct pipe_inode_info *pipe, size_t len,
199 - unsigned int flags)
200 +long do_splice_to(struct file *in, loff_t *ppos,
201 + struct pipe_inode_info *pipe, size_t len,
202 + unsigned int flags)
204 ssize_t (*splice_read)(struct file *, loff_t *,
205 struct pipe_inode_info *, size_t, unsigned int);
206 diff --git a/fs/sync.c b/fs/sync.c
207 index b54e0541ad89..28607828e96f 100644
211 * wait == 1 case since in that case write_inode() functions do
212 * sync_dirty_buffer() and thus effectively write one block at a time.
214 -static int __sync_filesystem(struct super_block *sb, int wait)
215 +int __sync_filesystem(struct super_block *sb, int wait)
219 diff --git a/include/linux/fs.h b/include/linux/fs.h
220 index 29d8e2cfed0e..5db265e7d35a 100644
221 --- a/include/linux/fs.h
222 +++ b/include/linux/fs.h
223 @@ -1310,6 +1310,7 @@ extern void fasync_free(struct fasync_struct *);
224 /* can be called from interrupts */
225 extern void kill_fasync(struct fasync_struct **, int, int);
227 +extern int setfl(int fd, struct file * filp, unsigned long arg);
228 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
229 extern int f_setown(struct file *filp, unsigned long arg, int force);
230 extern void f_delown(struct file *filp);
231 @@ -1803,6 +1804,7 @@ struct file_operations {
232 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
233 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
234 int (*check_flags)(int);
235 + int (*setfl)(struct file *, unsigned long);
236 int (*flock) (struct file *, int, struct file_lock *);
237 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
238 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
239 @@ -1873,6 +1875,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
240 struct iovec *fast_pointer,
241 struct iovec **ret_pointer);
243 +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *);
244 +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t,
246 +vfs_readf_t vfs_readf(struct file *file);
247 +vfs_writef_t vfs_writef(struct file *file);
249 extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
250 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
251 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
252 @@ -2298,6 +2306,7 @@ extern int current_umask(void);
253 extern void ihold(struct inode * inode);
254 extern void iput(struct inode *);
255 extern int generic_update_time(struct inode *, struct timespec64 *, int);
256 +extern int update_time(struct inode *, struct timespec64 *, int);
259 extern struct kobject *fs_kobj;
260 @@ -2585,6 +2594,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
264 +extern int __sync_filesystem(struct super_block *, int);
265 extern int sync_filesystem(struct super_block *);
266 extern const struct file_operations def_blk_fops;
267 extern const struct file_operations def_chr_fops;
268 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
269 index c5335df2372f..4e48a5059536 100644
270 --- a/include/linux/lockdep.h
271 +++ b/include/linux/lockdep.h
272 @@ -306,6 +306,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
273 return lock->key == key;
276 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
281 @@ -432,6 +434,7 @@ struct lockdep_map { };
283 #define lockdep_depth(tsk) (0)
285 +#define lockdep_is_held(lock) (1)
286 #define lockdep_is_held_type(l, r) (1)
288 #define lockdep_assert_held(l) do { (void)(l); } while (0)
289 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
290 index 35942084cd40..24f5fd1a789d 100644
291 --- a/include/linux/mnt_namespace.h
292 +++ b/include/linux/mnt_namespace.h
294 struct mnt_namespace;
296 struct user_namespace;
299 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
300 struct user_namespace *, struct fs_struct *);
301 extern void put_mnt_ns(struct mnt_namespace *ns);
303 +extern int is_current_mnt_ns(struct vfsmount *mnt);
305 extern const struct file_operations proc_mounts_operations;
306 extern const struct file_operations proc_mountinfo_operations;
307 extern const struct file_operations proc_mountstats_operations;
308 diff --git a/include/linux/splice.h b/include/linux/splice.h
309 index 74b4911ac16d..19789fbea567 100644
310 --- a/include/linux/splice.h
311 +++ b/include/linux/splice.h
312 @@ -87,4 +87,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
314 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
315 extern const struct pipe_buf_operations default_pipe_buf_ops;
317 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
318 + loff_t *ppos, size_t len, unsigned int flags);
319 +extern long do_splice_to(struct file *in, loff_t *ppos,
320 + struct pipe_inode_info *pipe, size_t len,
321 + unsigned int flags);
323 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
324 index 95932333a48b..516ab7da26fb 100644
325 --- a/kernel/locking/lockdep.c
326 +++ b/kernel/locking/lockdep.c
327 @@ -143,7 +143,7 @@ static
329 struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
331 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
332 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
334 if (!hlock->class_idx) {
336 @@ -154,6 +154,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
338 return lock_classes + hlock->class_idx - 1;
340 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
342 #ifdef CONFIG_LOCK_STAT
343 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
344 SPDX-License-Identifier: GPL-2.0
345 aufs4.x-rcN mmap patch
347 diff --git a/fs/proc/base.c b/fs/proc/base.c
348 index f5ed9512d193..e8f8e59d93bb 100644
351 @@ -2014,7 +2014,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
352 down_read(&mm->mmap_sem);
353 vma = find_exact_vma(mm, vm_start, vm_end);
354 if (vma && vma->vm_file) {
355 - *path = vma->vm_file->f_path;
356 + *path = vma_pr_or_file(vma)->f_path;
360 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
361 index 3b63be64e436..fb9913bf3d10 100644
362 --- a/fs/proc/nommu.c
363 +++ b/fs/proc/nommu.c
364 @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
365 file = region->vm_file;
368 - struct inode *inode = file_inode(region->vm_file);
369 + struct inode *inode;
371 + file = vmr_pr_or_file(region);
372 + inode = file_inode(file);
373 dev = inode->i_sb->s_dev;
376 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
377 index 85b0ef890b28..0f7fb8138160 100644
378 --- a/fs/proc/task_mmu.c
379 +++ b/fs/proc/task_mmu.c
380 @@ -305,7 +305,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
381 const char *name = NULL;
384 - struct inode *inode = file_inode(vma->vm_file);
385 + struct inode *inode;
387 + file = vma_pr_or_file(vma);
388 + inode = file_inode(file);
389 dev = inode->i_sb->s_dev;
391 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
392 @@ -1740,7 +1743,7 @@ static int show_numa_map(struct seq_file *m, void *v)
393 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
394 struct vm_area_struct *vma = v;
395 struct numa_maps *md = &numa_priv->md;
396 - struct file *file = vma->vm_file;
397 + struct file *file = vma_pr_or_file(vma);
398 struct mm_struct *mm = vma->vm_mm;
399 struct mm_walk walk = {
400 .hugetlb_entry = gather_hugetlb_stats,
401 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
402 index 0b63d68dedb2..400d1c594ceb 100644
403 --- a/fs/proc/task_nommu.c
404 +++ b/fs/proc/task_nommu.c
405 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
409 - struct inode *inode = file_inode(vma->vm_file);
410 + struct inode *inode;
412 + file = vma_pr_or_file(vma);
413 + inode = file_inode(file);
414 dev = inode->i_sb->s_dev;
416 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
417 diff --git a/include/linux/mm.h b/include/linux/mm.h
418 index 80bb6408fe73..59a1ea611ba7 100644
419 --- a/include/linux/mm.h
420 +++ b/include/linux/mm.h
421 @@ -1518,6 +1518,28 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
422 unmap_mapping_range(mapping, holebegin, holelen, 0);
425 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
426 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
428 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
429 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
431 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
433 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
435 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
436 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
439 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
440 +extern void vmr_do_fput(struct vm_region *, const char[], int);
442 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
444 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
445 +#endif /* !CONFIG_MMU */
447 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
448 void *buf, int len, unsigned int gup_flags);
449 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
450 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
451 index 2c471a2c43fa..c6e7aa6996ff 100644
452 --- a/include/linux/mm_types.h
453 +++ b/include/linux/mm_types.h
454 @@ -244,6 +244,7 @@ struct vm_region {
455 unsigned long vm_top; /* region allocated to here */
456 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
457 struct file *vm_file; /* the backing file or NULL */
458 + struct file *vm_prfile; /* the virtual backing file or NULL */
460 int vm_usage; /* region usage count (access under nommu_region_sem) */
461 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
462 @@ -318,6 +319,7 @@ struct vm_area_struct {
463 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
465 struct file * vm_file; /* File we map to (can be NULL). */
466 + struct file *vm_prfile; /* shadow of vm_file */
467 void * vm_private_data; /* was vm_pte (shared mem) */
469 atomic_long_t swap_readahead_info;
470 diff --git a/kernel/fork.c b/kernel/fork.c
471 index b69248e6f0e0..099b89978dd3 100644
474 @@ -547,7 +547,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
475 struct inode *inode = file_inode(file);
476 struct address_space *mapping = file->f_mapping;
480 if (tmp->vm_flags & VM_DENYWRITE)
481 atomic_dec(&inode->i_writecount);
482 i_mmap_lock_write(mapping);
483 diff --git a/mm/Makefile b/mm/Makefile
484 index d210cc9d6f80..e77e80ce7298 100644
487 @@ -39,7 +39,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \
488 mm_init.o mmu_context.o percpu.o slab_common.o \
489 compaction.o vmacache.o \
490 interval_tree.o list_lru.o workingset.o \
492 + prfile.o debug.o $(mmu-y)
496 diff --git a/mm/filemap.c b/mm/filemap.c
497 index 9f5e323e883e..90db684a7cf4 100644
500 @@ -2677,7 +2677,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
501 vm_fault_t ret = VM_FAULT_LOCKED;
503 sb_start_pagefault(inode->i_sb);
504 - file_update_time(vmf->vma->vm_file);
505 + vma_file_update_time(vmf->vma);
507 if (page->mapping != inode->i_mapping) {
509 diff --git a/mm/mmap.c b/mm/mmap.c
510 index fc1809b1bed6..8f62e47a60ea 100644
513 @@ -180,7 +180,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
514 if (vma->vm_ops && vma->vm_ops->close)
515 vma->vm_ops->close(vma);
517 - fput(vma->vm_file);
519 mpol_put(vma_policy(vma));
522 @@ -929,7 +929,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
525 uprobe_munmap(next, next->vm_start, next->vm_end);
530 anon_vma_merge(vma, next);
531 @@ -1845,8 +1845,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
539 /* Undo any partial mapping done by a device driver. */
540 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
541 @@ -2675,7 +2675,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
545 - get_file(new->vm_file);
548 if (new->vm_ops && new->vm_ops->open)
549 new->vm_ops->open(new);
550 @@ -2694,7 +2694,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
551 if (new->vm_ops && new->vm_ops->close)
552 new->vm_ops->close(new);
554 - fput(new->vm_file);
556 unlink_anon_vmas(new);
558 mpol_put(vma_policy(new));
559 @@ -2884,7 +2884,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
560 struct vm_area_struct *vma;
561 unsigned long populate = 0;
562 unsigned long ret = -EINVAL;
564 + struct file *file, *prfile;
566 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n",
567 current->comm, current->pid);
568 @@ -2959,10 +2959,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
572 - file = get_file(vma->vm_file);
574 + file = vma->vm_file;
575 + prfile = vma->vm_prfile;
576 ret = do_mmap_pgoff(vma->vm_file, start, size,
577 prot, flags, pgoff, &populate, NULL);
578 + if (!IS_ERR_VALUE(ret) && file && prfile) {
579 + struct vm_area_struct *new_vma;
581 + new_vma = find_vma(mm, ret);
582 + if (!new_vma->vm_prfile)
583 + new_vma->vm_prfile = prfile;
584 + if (new_vma != vma)
588 + * two fput()s instead of vma_fput(vma),
589 + * coz vma may not be available anymore.
595 up_write(&mm->mmap_sem);
597 @@ -3252,7 +3269,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
598 if (anon_vma_clone(new_vma, vma))
599 goto out_free_mempol;
600 if (new_vma->vm_file)
601 - get_file(new_vma->vm_file);
602 + vma_get_file(new_vma);
603 if (new_vma->vm_ops && new_vma->vm_ops->open)
604 new_vma->vm_ops->open(new_vma);
605 vma_link(mm, new_vma, prev, rb_link, rb_parent);
606 diff --git a/mm/nommu.c b/mm/nommu.c
607 index 749276beb109..c7957f06fbc4 100644
610 @@ -625,7 +625,7 @@ static void __put_nommu_region(struct vm_region *region)
611 up_write(&nommu_region_sem);
614 - fput(region->vm_file);
617 /* IO memory and memory shared directly out of the pagecache
618 * from ramfs/tmpfs mustn't be released here */
619 @@ -763,7 +763,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
620 if (vma->vm_ops && vma->vm_ops->close)
621 vma->vm_ops->close(vma);
623 - fput(vma->vm_file);
625 put_nommu_region(vma->vm_region);
628 @@ -1286,7 +1286,7 @@ unsigned long do_mmap(struct file *file,
629 goto error_just_free;
632 - fput(region->vm_file);
634 kmem_cache_free(vm_region_jar, region);
637 @@ -1361,10 +1361,10 @@ unsigned long do_mmap(struct file *file,
638 up_write(&nommu_region_sem);
641 - fput(region->vm_file);
643 kmem_cache_free(vm_region_jar, region);
645 - fput(vma->vm_file);
650 diff --git a/mm/prfile.c b/mm/prfile.c
652 index 000000000000..024cdcfae1b1
656 +// SPDX-License-Identifier: GPL-2.0
658 + * Mainly for aufs which mmap(2) different file and wants to print different
659 + * path in /proc/PID/maps.
660 + * Call these functions via macros defined in linux/mm.h.
662 + * See Documentation/filesystems/aufs/design/06mmap.txt
664 + * Copyright (c) 2014-2019 Junjro R. Okajima
665 + * Copyright (c) 2014 Ian Campbell
668 +#include <linux/mm.h>
669 +#include <linux/file.h>
670 +#include <linux/fs.h>
672 +/* #define PRFILE_TRACE */
673 +static inline void prfile_trace(struct file *f, struct file *pr,
674 + const char func[], int line, const char func2[])
678 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
682 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
685 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
687 + prfile_trace(f, pr, func, line, __func__);
688 + file_update_time(f);
690 + file_update_time(pr);
693 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
696 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
698 + prfile_trace(f, pr, func, line, __func__);
699 + return (f && pr) ? pr : f;
702 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
704 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
706 + prfile_trace(f, pr, func, line, __func__);
712 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
714 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
716 + prfile_trace(f, pr, func, line, __func__);
723 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
726 + struct file *f = region->vm_file, *pr = region->vm_prfile;
728 + prfile_trace(f, pr, func, line, __func__);
729 + return (f && pr) ? pr : f;
732 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
734 + struct file *f = region->vm_file, *pr = region->vm_prfile;
736 + prfile_trace(f, pr, func, line, __func__);
741 +#endif /* !CONFIG_MMU */
742 SPDX-License-Identifier: GPL-2.0
743 aufs4.x-rcN standalone patch
745 diff --git a/fs/dcache.c b/fs/dcache.c
746 index fc18967c2522..50eb587c1253 100644
749 @@ -1352,6 +1352,7 @@ void d_walk(struct dentry *parent, void *data,
753 +EXPORT_SYMBOL_GPL(d_walk);
756 struct vfsmount *mnt;
757 @@ -2845,6 +2846,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
759 write_sequnlock(&rename_lock);
761 +EXPORT_SYMBOL_GPL(d_exchange);
764 * d_ancestor - search for an ancestor
765 diff --git a/fs/exec.c b/fs/exec.c
766 index fb72d36f7823..7ce68004cbf8 100644
769 @@ -109,6 +109,7 @@ bool path_noexec(const struct path *path)
770 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
771 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
773 +EXPORT_SYMBOL_GPL(path_noexec);
777 diff --git a/fs/fcntl.c b/fs/fcntl.c
778 index 78234ee16784..2072f690b121 100644
781 @@ -85,6 +85,7 @@ int setfl(int fd, struct file * filp, unsigned long arg)
785 +EXPORT_SYMBOL_GPL(setfl);
787 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
789 diff --git a/fs/file_table.c b/fs/file_table.c
790 index 5679e7fcb6b0..961eec3df1eb 100644
791 --- a/fs/file_table.c
792 +++ b/fs/file_table.c
793 @@ -161,6 +161,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
795 return ERR_PTR(-ENFILE);
797 +EXPORT_SYMBOL_GPL(alloc_empty_file);
800 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
801 @@ -323,6 +324,7 @@ void flush_delayed_fput(void)
805 +EXPORT_SYMBOL_GPL(flush_delayed_fput);
807 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
809 @@ -365,6 +367,7 @@ void __fput_sync(struct file *file)
813 +EXPORT_SYMBOL_GPL(__fput_sync);
815 void __init files_init(void)
817 diff --git a/fs/inode.c b/fs/inode.c
818 index 4a1756b8b4bd..6e51d5f9b9f3 100644
821 @@ -1666,6 +1666,7 @@ int update_time(struct inode *inode, struct timespec64 *time, int flags)
823 return update_time(inode, time, flags);
825 +EXPORT_SYMBOL_GPL(update_time);
828 * touch_atime - update the access time
829 diff --git a/fs/namespace.c b/fs/namespace.c
830 index 9b6a3d0f87a1..8c4d3d56f2df 100644
833 @@ -434,6 +434,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
834 mnt_dec_writers(real_mount(mnt));
837 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
840 * mnt_drop_write - give up write access to a mount
841 @@ -773,6 +774,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
843 return check_mnt(real_mount(mnt));
845 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
848 * vfsmount lock must be held for write
849 @@ -1842,6 +1844,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
853 +EXPORT_SYMBOL_GPL(iterate_mounts);
855 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
857 diff --git a/fs/notify/group.c b/fs/notify/group.c
858 index c03b83662876..817f22c6e191 100644
859 --- a/fs/notify/group.c
860 +++ b/fs/notify/group.c
862 #include <linux/rculist.h>
863 #include <linux/wait.h>
864 #include <linux/memcontrol.h>
865 +#include <linux/module.h>
867 #include <linux/fsnotify_backend.h>
868 #include "fsnotify.h"
869 @@ -112,6 +113,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
871 refcount_inc(&group->refcnt);
873 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
876 * Drop a reference to a group. Free it if it's through.
877 @@ -121,6 +123,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
878 if (refcount_dec_and_test(&group->refcnt))
879 fsnotify_final_destroy_group(group);
881 +EXPORT_SYMBOL_GPL(fsnotify_put_group);
884 * Create a new fsnotify_group and hold a reference for the group returned.
885 @@ -150,6 +153,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
889 +EXPORT_SYMBOL_GPL(fsnotify_alloc_group);
891 int fsnotify_fasync(int fd, struct file *file, int on)
893 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
894 index d2dd16cb5989..cf709b7d611a 100644
895 --- a/fs/notify/mark.c
896 +++ b/fs/notify/mark.c
897 @@ -289,6 +289,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
898 queue_delayed_work(system_unbound_wq, &reaper_work,
899 FSNOTIFY_REAPER_DELAY);
901 +EXPORT_SYMBOL_GPL(fsnotify_put_mark);
904 * Get mark reference when we found the mark via lockless traversal of object
905 @@ -443,6 +444,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
906 mutex_unlock(&group->mark_mutex);
907 fsnotify_free_mark(mark);
909 +EXPORT_SYMBOL_GPL(fsnotify_destroy_mark);
912 * Sorting function for lists of fsnotify marks.
913 @@ -658,6 +660,7 @@ int fsnotify_add_mark(struct fsnotify_mark *mark, fsnotify_connp_t *connp,
914 mutex_unlock(&group->mark_mutex);
917 +EXPORT_SYMBOL_GPL(fsnotify_add_mark);
920 * Given a list of marks, find the mark associated with given group. If found
921 @@ -781,6 +784,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
922 fsnotify_get_group(group);
925 +EXPORT_SYMBOL_GPL(fsnotify_init_mark);
928 * Destroy all marks in destroy_list, waits for SRCU period to finish before
929 diff --git a/fs/open.c b/fs/open.c
930 index 0285ce7dbd51..cb81623a8b09 100644
933 @@ -64,6 +64,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
934 inode_unlock(dentry->d_inode);
937 +EXPORT_SYMBOL_GPL(do_truncate);
939 long vfs_truncate(const struct path *path, loff_t length)
941 diff --git a/fs/read_write.c b/fs/read_write.c
942 index 5c18a9e51f37..542e59cd8d27 100644
943 --- a/fs/read_write.c
944 +++ b/fs/read_write.c
945 @@ -459,6 +459,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
949 +EXPORT_SYMBOL_GPL(vfs_read);
951 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
953 @@ -499,6 +500,7 @@ vfs_readf_t vfs_readf(struct file *file)
954 return new_sync_read;
955 return ERR_PTR(-ENOSYS);
957 +EXPORT_SYMBOL_GPL(vfs_readf);
959 vfs_writef_t vfs_writef(struct file *file)
961 @@ -510,6 +512,7 @@ vfs_writef_t vfs_writef(struct file *file)
962 return new_sync_write;
963 return ERR_PTR(-ENOSYS);
965 +EXPORT_SYMBOL_GPL(vfs_writef);
967 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
969 @@ -579,6 +582,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
973 +EXPORT_SYMBOL_GPL(vfs_write);
975 static inline loff_t file_pos_read(struct file *file)
977 diff --git a/fs/splice.c b/fs/splice.c
978 index 5dcf77b8e1b2..63fe2652c67d 100644
981 @@ -850,6 +850,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
983 return splice_write(pipe, out, ppos, len, flags);
985 +EXPORT_SYMBOL_GPL(do_splice_from);
988 * Attempt to initiate a splice from a file to a pipe.
989 @@ -879,6 +880,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
991 return splice_read(in, ppos, pipe, len, flags);
993 +EXPORT_SYMBOL_GPL(do_splice_to);
996 * splice_direct_to_actor - splices data directly between two non-pipes
997 diff --git a/fs/sync.c b/fs/sync.c
998 index 28607828e96f..ffd7ea43831e 100644
1001 @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
1002 sb->s_op->sync_fs(sb, wait);
1003 return __sync_blockdev(sb->s_bdev, wait);
1005 +EXPORT_SYMBOL_GPL(__sync_filesystem);
1008 * Write out and wait upon all dirty data associated with this
1009 diff --git a/fs/xattr.c b/fs/xattr.c
1010 index 0d6a6a4af861..7ce4701b7289 100644
1013 @@ -295,6 +295,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
1014 *xattr_value = value;
1017 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
1020 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
1021 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
1022 index 516ab7da26fb..c4f72e461d28 100644
1023 --- a/kernel/locking/lockdep.c
1024 +++ b/kernel/locking/lockdep.c
1025 @@ -154,6 +154,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
1027 return lock_classes + hlock->class_idx - 1;
1029 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
1030 #define hlock_class(hlock) lockdep_hlock_class(hlock)
1032 #ifdef CONFIG_LOCK_STAT
1033 diff --git a/kernel/task_work.c b/kernel/task_work.c
1034 index 0fef395662a6..83fb1ecfc33d 100644
1035 --- a/kernel/task_work.c
1036 +++ b/kernel/task_work.c
1037 @@ -116,3 +116,4 @@ void task_work_run(void)
1041 +EXPORT_SYMBOL_GPL(task_work_run);
1042 diff --git a/security/commoncap.c b/security/commoncap.c
1043 index 232db019f051..a402a5b72bf4 100644
1044 --- a/security/commoncap.c
1045 +++ b/security/commoncap.c
1046 @@ -1332,12 +1332,14 @@ int cap_mmap_addr(unsigned long addr)
1050 +EXPORT_SYMBOL_GPL(cap_mmap_addr);
1052 int cap_mmap_file(struct file *file, unsigned long reqprot,
1053 unsigned long prot, unsigned long flags)
1057 +EXPORT_SYMBOL_GPL(cap_mmap_file);
1059 #ifdef CONFIG_SECURITY
1061 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
1062 index cd97929fac66..424fd230866d 100644
1063 --- a/security/device_cgroup.c
1064 +++ b/security/device_cgroup.c
1066 #include <linux/device_cgroup.h>
1067 #include <linux/cgroup.h>
1068 #include <linux/ctype.h>
1069 +#include <linux/export.h>
1070 #include <linux/list.h>
1071 #include <linux/uaccess.h>
1072 #include <linux/seq_file.h>
1073 @@ -824,3 +825,4 @@ int __devcgroup_check_permission(short type, u32 major, u32 minor,
1077 +EXPORT_SYMBOL_GPL(__devcgroup_check_permission);
1078 diff --git a/security/security.c b/security/security.c
1079 index 55bc49027ba9..870eaa8ebedc 100644
1080 --- a/security/security.c
1081 +++ b/security/security.c
1082 @@ -566,6 +566,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
1084 return call_int_hook(path_rmdir, 0, dir, dentry);
1086 +EXPORT_SYMBOL_GPL(security_path_rmdir);
1088 int security_path_unlink(const struct path *dir, struct dentry *dentry)
1090 @@ -582,6 +583,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
1092 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
1094 +EXPORT_SYMBOL_GPL(security_path_symlink);
1096 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1097 struct dentry *new_dentry)
1098 @@ -590,6 +592,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1100 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
1102 +EXPORT_SYMBOL_GPL(security_path_link);
1104 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1105 const struct path *new_dir, struct dentry *new_dentry,
1106 @@ -617,6 +620,7 @@ int security_path_truncate(const struct path *path)
1108 return call_int_hook(path_truncate, 0, path);
1110 +EXPORT_SYMBOL_GPL(security_path_truncate);
1112 int security_path_chmod(const struct path *path, umode_t mode)
1114 @@ -624,6 +628,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1116 return call_int_hook(path_chmod, 0, path, mode);
1118 +EXPORT_SYMBOL_GPL(security_path_chmod);
1120 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1122 @@ -631,6 +636,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1124 return call_int_hook(path_chown, 0, path, uid, gid);
1126 +EXPORT_SYMBOL_GPL(security_path_chown);
1128 int security_path_chroot(const struct path *path)
1130 @@ -716,6 +722,7 @@ int security_inode_readlink(struct dentry *dentry)
1132 return call_int_hook(inode_readlink, 0, dentry);
1134 +EXPORT_SYMBOL_GPL(security_inode_readlink);
1136 int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
1138 @@ -731,6 +738,7 @@ int security_inode_permission(struct inode *inode, int mask)
1140 return call_int_hook(inode_permission, 0, inode, mask);
1142 +EXPORT_SYMBOL_GPL(security_inode_permission);
1144 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1146 @@ -902,6 +910,7 @@ int security_file_permission(struct file *file, int mask)
1148 return fsnotify_perm(file, mask);
1150 +EXPORT_SYMBOL_GPL(security_file_permission);
1152 int security_file_alloc(struct file *file)
1154 @@ -961,6 +970,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
1156 return ima_file_mmap(file, prot);
1158 +EXPORT_SYMBOL_GPL(security_mmap_file);
1160 int security_mmap_addr(unsigned long addr)
1162 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1163 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1164 +++ linux/Documentation/ABI/testing/debugfs-aufs 2018-08-12 23:43:05.450124426 +0200
1166 +What: /debug/aufs/si_<id>/
1168 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1170 + Under /debug/aufs, a directory named si_<id> is created
1171 + per aufs mount, where <id> is a unique id generated
1174 +What: /debug/aufs/si_<id>/plink
1176 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1178 + It has three lines and shows the information about the
1179 + pseudo-link. The first line is a single number
1180 + representing a number of buckets. The second line is a
1181 + number of pseudo-links per buckets (separated by a
1182 + blank). The last line is a single number representing a
1183 + total number of psedo-links.
1184 + When the aufs mount option 'noplink' is specified, it
1185 + will show "1\n0\n0\n".
1187 +What: /debug/aufs/si_<id>/xib
1189 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1191 + It shows the consumed blocks by xib (External Inode Number
1192 + Bitmap), its block size and file size.
1193 + When the aufs mount option 'noxino' is specified, it
1194 + will be empty. About XINO files, see the aufs manual.
1196 +What: /debug/aufs/si_<id>/xi0, xi1 ... xiN and xiN-N
1198 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1200 + It shows the consumed blocks by xino (External Inode Number
1201 + Translation Table), its link count, block size and file
1203 + Due to the file size limit, there may exist multiple
1204 + xino files per branch. In this case, "-N" is added to
1205 + the filename and it corresponds to the index of the
1206 + internal xino array. "-0" is omitted.
1207 + When the aufs mount option 'noxino' is specified, Those
1208 + entries won't exist. About XINO files, see the aufs
1211 +What: /debug/aufs/si_<id>/xigen
1213 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1215 + It shows the consumed blocks by xigen (External Inode
1216 + Generation Table), its block size and file size.
1217 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1219 + When the aufs mount option 'noxino' is specified, it
1220 + will be empty. About XINO files, see the aufs manual.
1221 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1222 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1223 +++ linux/Documentation/ABI/testing/sysfs-aufs 2017-07-29 12:14:25.893041746 +0200
1225 +What: /sys/fs/aufs/si_<id>/
1227 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1229 + Under /sys/fs/aufs, a directory named si_<id> is created
1230 + per aufs mount, where <id> is a unique id generated
1233 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1235 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1237 + It shows the abolute path of a member directory (which
1238 + is called branch) in aufs, and its permission.
1240 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1242 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1244 + It shows the id of a member directory (which is called
1247 +What: /sys/fs/aufs/si_<id>/xi_path
1249 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1251 + It shows the abolute path of XINO (External Inode Number
1252 + Bitmap, Translation Table and Generation Table) file
1253 + even if it is the default path.
1254 + When the aufs mount option 'noxino' is specified, it
1255 + will be empty. About XINO files, see the aufs manual.
1256 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1257 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1258 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2019-03-05 12:13:00.132557473 +0100
1261 +# Copyright (C) 2005-2019 Junjiro R. Okajima
1263 +# This program is free software; you can redistribute it and/or modify
1264 +# it under the terms of the GNU General Public License as published by
1265 +# the Free Software Foundation; either version 2 of the License, or
1266 +# (at your option) any later version.
1268 +# This program is distributed in the hope that it will be useful,
1269 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1270 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1271 +# GNU General Public License for more details.
1273 +# You should have received a copy of the GNU General Public License
1274 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1277 +----------------------------------------
1279 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1280 +1. abbrev. for "advanced multi-layered unification filesystem".
1281 +2. abbrev. for "another unionfs".
1282 +3. abbrev. for "auf das" in German which means "on the" in English.
1283 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1284 + But "Filesystem aufs Filesystem" is hard to understand.
1285 +4. abbrev. for "African Urban Fashion Show".
1287 +AUFS is a filesystem with features:
1288 +- multi layered stackable unification filesystem, the member directory
1289 + is called as a branch.
1290 +- branch permission and attribute, 'readonly', 'real-readonly',
1291 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1293 +- internal "file copy-on-write".
1294 +- logical deletion, whiteout.
1295 +- dynamic branch manipulation, adding, deleting and changing permission.
1296 +- allow bypassing aufs, user's direct branch access.
1297 +- external inode number translation table and bitmap which maintains the
1298 + persistent aufs inode number.
1299 +- seekable directory, including NFS readdir.
1300 +- file mapping, mmap and sharing pages.
1301 +- pseudo-link, hardlink over branches.
1302 +- loopback mounted filesystem as a branch.
1303 +- several policies to select one among multiple writable branches.
1304 +- revert a single systemcall when an error occurs in aufs.
1308 +Multi Layered Stackable Unification Filesystem
1309 +----------------------------------------------------------------------
1310 +Most people already knows what it is.
1311 +It is a filesystem which unifies several directories and provides a
1312 +merged single directory. When users access a file, the access will be
1313 +passed/re-directed/converted (sorry, I am not sure which English word is
1314 +correct) to the real file on the member filesystem. The member
1315 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1316 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1317 +readonly branch is handled by creating 'whiteout' on the upper writable
1320 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1321 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1322 +different approaches to implement the merged-view.
1323 +The former tries putting it into VFS, and the latter implements as a
1324 +separate filesystem.
1325 +(If I misunderstand about these implementations, please let me know and
1326 +I shall correct it. Because it is a long time ago when I read their
1327 +source files last time).
1329 +UnionMount's approach will be able to small, but may be hard to share
1330 +branches between several UnionMount since the whiteout in it is
1331 +implemented in the inode on branch filesystem and always
1332 +shared. According to Bharata's post, readdir does not seems to be
1334 +There are several missing features known in this implementations such as
1335 +- for users, the inode number may change silently. eg. copy-up.
1336 +- link(2) may break by copy-up.
1337 +- read(2) may get an obsoleted filedata (fstat(2) too).
1338 +- fcntl(F_SETLK) may be broken by copy-up.
1339 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1342 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1343 +merged into mainline. This is another implementation of UnionMount as a
1344 +separated filesystem. All the limitations and known problems which
1345 +UnionMount are equally inherited to "overlay" filesystem.
1347 +Unionfs has a longer history. When I started implementing a stackable
1348 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1349 +inode, dentry and file objects and they have an array pointing lower
1350 +same kind objects. After contributing many patches for Unionfs, I
1351 +re-started my project AUFS (Jun 2006).
1353 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1354 +implemented my own ideas, approaches and enhancements and it became
1355 +totally different one.
1357 +Comparing DM snapshot and fs based implementation
1358 +- the number of bytes to be copied between devices is much smaller.
1359 +- the type of filesystem must be one and only.
1360 +- the fs must be writable, no readonly fs, even for the lower original
1361 + device. so the compression fs will not be usable. but if we use
1362 + loopback mount, we may address this issue.
1364 + mount /cdrom/squashfs.img /sq
1365 + losetup /sq/ext2.img
1366 + losetup /somewhere/cow
1367 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1368 +- it will be difficult (or needs more operations) to extract the
1369 + difference between the original device and COW.
1370 +- DM snapshot-merge may help a lot when users try merging. in the
1371 + fs-layer union, users will use rsync(1).
1373 +You may want to read my old paper "Filesystems in LiveCD"
1374 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1377 +Several characters/aspects/persona of aufs
1378 +----------------------------------------------------------------------
1380 +Aufs has several characters, aspects or persona.
1381 +1. a filesystem, callee of VFS helper
1382 +2. sub-VFS, caller of VFS helper for branches
1383 +3. a virtual filesystem which maintains persistent inode number
1384 +4. reader/writer of files on branches such like an application
1386 +1. Callee of VFS Helper
1387 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1388 +unlink(2) from an application reaches sys_unlink() kernel function and
1389 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1390 +calls filesystem specific unlink operation. Actually aufs implements the
1391 +unlink operation but it behaves like a redirector.
1393 +2. Caller of VFS Helper for Branches
1394 +aufs_unlink() passes the unlink request to the branch filesystem as if
1395 +it were called from VFS. So the called unlink operation of the branch
1396 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1397 +every necessary pre/post operation for the branch filesystem.
1398 +- acquire the lock for the parent dir on a branch
1399 +- lookup in a branch
1400 +- revalidate dentry on a branch
1401 +- mnt_want_write() for a branch
1402 +- vfs_unlink() for a branch
1403 +- mnt_drop_write() for a branch
1404 +- release the lock on a branch
1406 +3. Persistent Inode Number
1407 +One of the most important issue for a filesystem is to maintain inode
1408 +numbers. This is particularly important to support exporting a
1409 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1410 +backend block device for its own. But some storage is necessary to
1411 +keep and maintain the inode numbers. It may be a large space and may not
1412 +suit to keep in memory. Aufs rents some space from its first writable
1413 +branch filesystem (by default) and creates file(s) on it. These files
1414 +are created by aufs internally and removed soon (currently) keeping
1416 +Note: Because these files are removed, they are totally gone after
1417 + unmounting aufs. It means the inode numbers are not persistent
1418 + across unmount or reboot. I have a plan to make them really
1419 + persistent which will be important for aufs on NFS server.
1421 +4. Read/Write Files Internally (copy-on-write)
1422 +Because a branch can be readonly, when you write a file on it, aufs will
1423 +"copy-up" it to the upper writable branch internally. And then write the
1424 +originally requested thing to the file. Generally kernel doesn't
1425 +open/read/write file actively. In aufs, even a single write may cause a
1426 +internal "file copy". This behaviour is very similar to cp(1) command.
1428 +Some people may think it is better to pass such work to user space
1429 +helper, instead of doing in kernel space. Actually I am still thinking
1430 +about it. But currently I have implemented it in kernel space.
1431 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1432 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1433 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2019-03-05 12:13:00.132557473 +0100
1436 +# Copyright (C) 2005-2019 Junjiro R. Okajima
1438 +# This program is free software; you can redistribute it and/or modify
1439 +# it under the terms of the GNU General Public License as published by
1440 +# the Free Software Foundation; either version 2 of the License, or
1441 +# (at your option) any later version.
1443 +# This program is distributed in the hope that it will be useful,
1444 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1445 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1446 +# GNU General Public License for more details.
1448 +# You should have received a copy of the GNU General Public License
1449 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1451 +Basic Aufs Internal Structure
1453 +Superblock/Inode/Dentry/File Objects
1454 +----------------------------------------------------------------------
1455 +As like an ordinary filesystem, aufs has its own
1456 +superblock/inode/dentry/file objects. All these objects have a
1457 +dynamically allocated array and store the same kind of pointers to the
1458 +lower filesystem, branch.
1459 +For example, when you build a union with one readwrite branch and one
1460 +readonly, mounted /au, /rw and /ro respectively.
1462 +- /ro/fileA exists but /rw/fileA
1464 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1465 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1466 +- [0] = NULL (because /rw/fileA doesn't exist)
1469 +This style of an array is essentially same to the aufs
1470 +superblock/inode/dentry/file objects.
1472 +Because aufs supports manipulating branches, ie. add/delete/change
1473 +branches dynamically, these objects has its own generation. When
1474 +branches are changed, the generation in aufs superblock is
1475 +incremented. And a generation in other object are compared when it is
1476 +accessed. When a generation in other objects are obsoleted, aufs
1477 +refreshes the internal array.
1481 +----------------------------------------------------------------------
1482 +Additionally aufs superblock has some data for policies to select one
1483 +among multiple writable branches, XIB files, pseudo-links and kobject.
1484 +See below in detail.
1485 +About the policies which supports copy-down a directory, see
1486 +wbr_policy.txt too.
1489 +Branch and XINO(External Inode Number Translation Table)
1490 +----------------------------------------------------------------------
1491 +Every branch has its own xino (external inode number translation table)
1492 +file. The xino file is created and unlinked by aufs internally. When two
1493 +members of a union exist on the same filesystem, they share the single
1495 +The struct of a xino file is simple, just a sequence of aufs inode
1496 +numbers which is indexed by the lower inode number.
1497 +In the above sample, assume the inode number of /ro/fileA is i111 and
1498 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1499 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1501 +When the inode numbers are not contiguous, the xino file will be sparse
1502 +which has a hole in it and doesn't consume as much disk space as it
1503 +might appear. If your branch filesystem consumes disk space for such
1504 +holes, then you should specify 'xino=' option at mounting aufs.
1506 +Aufs has a mount option to free the disk blocks for such holes in XINO
1507 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1508 +meet a problem of disk shortage due to XINO files, then you should try
1509 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1510 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1511 +the holes in XINO files.
1513 +Also a writable branch has three kinds of "whiteout bases". All these
1514 +are existed when the branch is joined to aufs, and their names are
1515 +whiteout-ed doubly, so that users will never see their names in aufs
1517 +1. a regular file which will be hardlinked to all whiteouts.
1518 +2. a directory to store a pseudo-link.
1519 +3. a directory to store an "orphan"-ed file temporary.
1522 + When you remove a file on a readonly branch, aufs handles it as a
1523 + logical deletion and creates a whiteout on the upper writable branch
1524 + as a hardlink of this file in order not to consume inode on the
1527 + See below, Pseudo-link.
1529 + When "fileC" exists on the lower readonly branch only and it is
1530 + opened and removed with its parent dir, and then user writes
1531 + something into it, then aufs copies-up fileC to this
1532 + directory. Because there is no other dir to store fileC. After
1533 + creating a file under this dir, the file is unlinked.
1535 +Because aufs supports manipulating branches, ie. add/delete/change
1536 +dynamically, a branch has its own id. When the branch order changes,
1537 +aufs finds the new index by searching the branch id.
1541 +----------------------------------------------------------------------
1542 +Assume "fileA" exists on the lower readonly branch only and it is
1543 +hardlinked to "fileB" on the branch. When you write something to fileA,
1544 +aufs copies-up it to the upper writable branch. Additionally aufs
1545 +creates a hardlink under the Pseudo-link Directory of the writable
1546 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1547 +simple list. If fileB is read after unlinking fileA, aufs returns
1548 +filedata from the pseudo-link instead of the lower readonly
1549 +branch. Because the pseudo-link is based upon the inode, to keep the
1550 +inode number by xino (see above) is essentially necessary.
1552 +All the hardlinks under the Pseudo-link Directory of the writable branch
1553 +should be restored in a proper location later. Aufs provides a utility
1554 +to do this. The userspace helpers executed at remounting and unmounting
1556 +During this utility is running, it puts aufs into the pseudo-link
1557 +maintenance mode. In this mode, only the process which began the
1558 +maintenance mode (and its child processes) is allowed to operate in
1559 +aufs. Some other processes which are not related to the pseudo-link will
1560 +be allowed to run too, but the rest have to return an error or wait
1561 +until the maintenance mode ends. If a process already acquires an inode
1562 +mutex (in VFS), it has to return an error.
1565 +XIB(external inode number bitmap)
1566 +----------------------------------------------------------------------
1567 +Addition to the xino file per a branch, aufs has an external inode number
1568 +bitmap in a superblock object. It is also an internal file such like a
1570 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1572 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1574 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1575 +reduce the number of consumed disk blocks for these files.
1578 +Virtual or Vertical Dir, and Readdir in Userspace
1579 +----------------------------------------------------------------------
1580 +In order to support multiple layers (branches), aufs readdir operation
1581 +constructs a virtual dir block on memory. For readdir, aufs calls
1582 +vfs_readdir() internally for each dir on branches, merges their entries
1583 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1584 +object. So the file object has its entry list until it is closed. The
1585 +entry list will be updated when the file position is zero and becomes
1586 +obsoleted. This decision is made in aufs automatically.
1588 +The dynamically allocated memory block for the name of entries has a
1589 +unit of 512 bytes (by default) and stores the names contiguously (no
1590 +padding). Another block for each entry is handled by kmem_cache too.
1591 +During building dir blocks, aufs creates hash list and judging whether
1592 +the entry is whiteouted by its upper branch or already listed.
1593 +The merged result is cached in the corresponding inode object and
1594 +maintained by a customizable life-time option.
1596 +Some people may call it can be a security hole or invite DoS attack
1597 +since the opened and once readdir-ed dir (file object) holds its entry
1598 +list and becomes a pressure for system memory. But I'd say it is similar
1599 +to files under /proc or /sys. The virtual files in them also holds a
1600 +memory page (generally) while they are opened. When an idea to reduce
1601 +memory for them is introduced, it will be applied to aufs too.
1602 +For those who really hate this situation, I've developed readdir(3)
1603 +library which operates this merging in userspace. You just need to set
1604 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1605 +kernel space for readdir(3).
1609 +----------------------------------------------------------------------
1610 +Aufs sometimes requires privilege access to a branch. For instance,
1611 +in copy-up/down operation. When a user process is going to make changes
1612 +to a file which exists in the lower readonly branch only, and the mode
1613 +of one of ancestor directories may not be writable by a user
1614 +process. Here aufs copy-up the file with its ancestors and they may
1615 +require privilege to set its owner/group/mode/etc.
1616 +This is a typical case of a application character of aufs (see
1619 +Aufs uses workqueue synchronously for this case. It creates its own
1620 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1621 +passes the request to call mkdir or write (for example), and wait for
1622 +its completion. This approach solves a problem of a signal handler
1624 +If aufs didn't adopt the workqueue and changed the privilege of the
1625 +process, then the process may receive the unexpected SIGXFSZ or other
1628 +Also aufs uses the system global workqueue ("events" kernel thread) too
1629 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1630 +whiteout base and etc. This is unrelated to a privilege.
1631 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1632 +superblock at the beginning, at the same time waits for the completion
1633 +of all queued asynchronous tasks.
1637 +----------------------------------------------------------------------
1638 +The whiteout in aufs is very similar to Unionfs's. That is represented
1639 +by its filename. UnionMount takes an approach of a file mode, but I am
1640 +afraid several utilities (find(1) or something) will have to support it.
1642 +Basically the whiteout represents "logical deletion" which stops aufs to
1643 +lookup further, but also it represents "dir is opaque" which also stop
1646 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1647 +In order to make several functions in a single systemcall to be
1648 +revertible, aufs adopts an approach to rename a directory to a temporary
1649 +unique whiteouted name.
1650 +For example, in rename(2) dir where the target dir already existed, aufs
1651 +renames the target dir to a temporary unique whiteouted name before the
1652 +actual rename on a branch, and then handles other actions (make it opaque,
1653 +update the attributes, etc). If an error happens in these actions, aufs
1654 +simply renames the whiteouted name back and returns an error. If all are
1655 +succeeded, aufs registers a function to remove the whiteouted unique
1656 +temporary name completely and asynchronously to the system global
1661 +----------------------------------------------------------------------
1662 +It is a well-known feature or concept.
1663 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1664 +internally and makes change to the new file on the upper writable branch.
1665 +When the trigger systemcall does not update the timestamps of the parent
1666 +dir, aufs reverts it after copy-up.
1669 +Move-down (aufs3.9 and later)
1670 +----------------------------------------------------------------------
1671 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1672 +the lower readonly branch to the upper writable branch when a user
1673 +changes something about the file.
1674 +"Move-down" is an opposite action of copy-up. Basically this action is
1675 +ran manually instead of automatically and internally.
1676 +For desgin and implementation, aufs has to consider these issues.
1677 +- whiteout for the file may exist on the lower branch.
1678 +- ancestor directories may not exist on the lower branch.
1679 +- diropq for the ancestor directories may exist on the upper branch.
1680 +- free space on the lower branch will reduce.
1681 +- another access to the file may happen during moving-down, including
1682 + UDBA (see "Revalidate Dentry and UDBA").
1683 +- the file should not be hard-linked nor pseudo-linked. they should be
1684 + handled by auplink utility later.
1686 +Sometimes users want to move-down a file from the upper writable branch
1687 +to the lower readonly or writable branch. For instance,
1688 +- the free space of the upper writable branch is going to run out.
1689 +- create a new intermediate branch between the upper and lower branch.
1692 +For this purpose, use "aumvdown" command in aufs-util.git.
1693 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1694 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1695 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2019-03-05 12:13:00.132557473 +0100
1698 +# Copyright (C) 2015-2019 Junjiro R. Okajima
1700 +# This program is free software; you can redistribute it and/or modify
1701 +# it under the terms of the GNU General Public License as published by
1702 +# the Free Software Foundation; either version 2 of the License, or
1703 +# (at your option) any later version.
1705 +# This program is distributed in the hope that it will be useful,
1706 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1707 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1708 +# GNU General Public License for more details.
1710 +# You should have received a copy of the GNU General Public License
1711 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1713 +Support for a branch who has its ->atomic_open()
1714 +----------------------------------------------------------------------
1715 +The filesystems who implement its ->atomic_open() are not majority. For
1716 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1717 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1718 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1719 +sure whether all filesystems who have ->atomic_open() behave like this,
1720 +but NFSv4 surely returns the error.
1722 +In order to support ->atomic_open() for aufs, there are a few
1725 +A. Introduce aufs_atomic_open()
1726 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1728 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1729 + an aufs user Pip Cet's approach
1730 + - calls aufs_create(), VFS finish_open() and notify_change().
1731 + - pass fake-mode to finish_open(), and then correct the mode by
1733 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1734 + - no aufs_atomic_open().
1735 + - aufs_lookup() registers the TID to an aufs internal object.
1736 + - aufs_create() does nothing when the matching TID is registered, but
1737 + registers the mode.
1738 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1739 + TID is registered.
1740 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1742 + - no aufs_atomic_open().
1743 + - aufs_create() registers the TID to an internal object. this info
1744 + represents "this process created this file just now."
1745 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1746 + registered TID and re-try open() with superuser's credential.
1748 +Pros and cons for each approach.
1751 + - straightforward but highly depends upon VFS internal.
1752 + - the atomic behavaiour is kept.
1753 + - some of parameters such as nameidata are hard to reproduce for
1757 + - easy to implement.
1758 + - the atomic behavaiour is lost.
1760 + - the atomic behavaiour is kept.
1761 + - dirty and tricky.
1762 + - VFS checks whether the file is created correctly after calling
1763 + ->create(), which means this approach doesn't work.
1765 + - easy to implement.
1766 + - the atomic behavaiour is lost.
1767 + - to open a file with superuser's credential and give it to a user
1768 + process is a bad idea, since the file object keeps the credential
1769 + in it. It may affect LSM or something. This approach doesn't work
1772 +The approach A is ideal, but it hard to implement. So here is a
1773 +variation of A, which is to be implemented.
1775 +A-1. Introduce aufs_atomic_open()
1776 + - calls branch fs ->atomic_open() if exists. otherwise calls
1777 + vfs_create() and finish_open().
1778 + - the demerit is that the several checks after branch fs
1779 + ->atomic_open() are lost. in the ordinary case, the checks are
1780 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1781 + be implemented in aufs, but not all I am afraid.
1782 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1783 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1784 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2019-03-05 12:13:00.132557473 +0100
1787 +# Copyright (C) 2005-2019 Junjiro R. Okajima
1789 +# This program is free software; you can redistribute it and/or modify
1790 +# it under the terms of the GNU General Public License as published by
1791 +# the Free Software Foundation; either version 2 of the License, or
1792 +# (at your option) any later version.
1794 +# This program is distributed in the hope that it will be useful,
1795 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1796 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1797 +# GNU General Public License for more details.
1799 +# You should have received a copy of the GNU General Public License
1800 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1803 +----------------------------------------------------------------------
1804 +Since aufs has a character of sub-VFS (see Introduction), it operates
1805 +lookup for branches as VFS does. It may be a heavy work. But almost all
1806 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1807 +directly connected to its parent. Digging down the directory hierarchy
1808 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1811 +When a branch is a remote filesystem, aufs basically relies upon its
1812 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1814 +For d_revalidate, aufs implements three levels of revalidate tests. See
1815 +"Revalidate Dentry and UDBA" in detail.
1818 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1819 +----------------------------------------------------------------------
1820 +Let's try case study.
1821 +- aufs has two branches, upper readwrite and lower readonly.
1823 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1824 +- user invoked "chmod a+rx /au/dirA"
1825 +- the internal copy-up is activated and "/rw/dirA" is created and its
1826 + permission bits are set to world readable.
1827 +- then "/au/dirA" becomes world readable?
1829 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1830 +or it may be a natively readonly filesystem. If aufs respects the lower
1831 +branch, it should not respond readdir request from other users. But user
1832 +allowed it by chmod. Should really aufs rejects showing the entries
1835 +To be honest, I don't have a good solution for this case. So aufs
1836 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1838 +When dirperm1 is specified, aufs checks only the highest one for the
1839 +directory permission, and shows the entries. Otherwise, as usual, checks
1840 +every dir existing on all branches and rejects the request.
1842 +As a side effect, dirperm1 option improves the performance of aufs
1843 +because the number of permission check is reduced when the number of
1847 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1848 +----------------------------------------------------------------------
1849 +Generally VFS helpers re-validate a dentry as a part of lookup.
1850 +0. digging down the directory hierarchy.
1851 +1. lock the parent dir by its i_mutex.
1852 +2. lookup the final (child) entry.
1854 +4. call the actual operation (create, unlink, etc.)
1855 +5. unlock the parent dir
1857 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1858 +called. Actually aufs implements it and checks the dentry on a branch is
1860 +But it is not enough. Because aufs has to release the lock for the
1861 +parent dir on a branch at the end of ->lookup() (step 2) and
1862 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1864 +If the file on a branch is changed directly, eg. bypassing aufs, after
1865 +aufs released the lock, then the subsequent operation may cause
1866 +something unpleasant result.
1868 +This situation is a result of VFS architecture, ->lookup() and
1869 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1870 +design from VFS's point of view. It is just not suitable for sub-VFS
1873 +Aufs supports such case by three level of revalidation which is
1874 +selectable by user.
1875 +1. Simple Revalidate
1876 + Addition to the native flow in VFS's, confirm the child-parent
1877 + relationship on the branch just after locking the parent dir on the
1878 + branch in the "actual operation" (step 4). When this validation
1879 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1880 + checks the validation of the dentry on branches.
1881 +2. Monitor Changes Internally by Inotify/Fsnotify
1882 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1883 + the dentry on the branch, and returns EBUSY if it finds different
1885 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1886 + during it is in cache. When the event is notified, aufs registers a
1887 + function to kernel 'events' thread by schedule_work(). And the
1888 + function sets some special status to the cached aufs dentry and inode
1889 + private data. If they are not cached, then aufs has nothing to
1890 + do. When the same file is accessed through aufs (step 0-3) later,
1891 + aufs will detect the status and refresh all necessary data.
1892 + In this mode, aufs has to ignore the event which is fired by aufs
1894 +3. No Extra Validation
1895 + This is the simplest test and doesn't add any additional revalidation
1896 + test, and skip the revalidation in step 4. It is useful and improves
1897 + aufs performance when system surely hide the aufs branches from user,
1898 + by over-mounting something (or another method).
1899 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1900 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1901 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2019-03-05 12:13:00.132557473 +0100
1904 +# Copyright (C) 2005-2019 Junjiro R. Okajima
1906 +# This program is free software; you can redistribute it and/or modify
1907 +# it under the terms of the GNU General Public License as published by
1908 +# the Free Software Foundation; either version 2 of the License, or
1909 +# (at your option) any later version.
1911 +# This program is distributed in the hope that it will be useful,
1912 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1913 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1914 +# GNU General Public License for more details.
1916 +# You should have received a copy of the GNU General Public License
1917 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1919 +Branch Manipulation
1921 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1922 +and changing its permission/attribute, there are a lot of works to do.
1926 +----------------------------------------------------------------------
1927 +o Confirm the adding dir exists outside of aufs, including loopback
1928 + mount, and its various attributes.
1929 +o Initialize the xino file and whiteout bases if necessary.
1932 +o Check the owner/group/mode of the directory
1933 + When the owner/group/mode of the adding directory differs from the
1934 + existing branch, aufs issues a warning because it may impose a
1936 + For example, when a upper writable branch has a world writable empty
1937 + top directory, a malicious user can create any files on the writable
1938 + branch directly, like copy-up and modify manually. If something like
1939 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1940 + writable branch, and the writable branch is world-writable, then a
1941 + malicious guy may create /etc/passwd on the writable branch directly
1942 + and the infected file will be valid in aufs.
1943 + I am afraid it can be a security issue, but aufs can do nothing except
1944 + producing a warning.
1948 +----------------------------------------------------------------------
1949 +o Confirm the deleting branch is not busy
1950 + To be general, there is one merit to adopt "remount" interface to
1951 + manipulate branches. It is to discard caches. At deleting a branch,
1952 + aufs checks the still cached (and connected) dentries and inodes. If
1953 + there are any, then they are all in-use. An inode without its
1954 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1956 + For the cached one, aufs checks whether the same named entry exists on
1958 + If the cached one is a directory, because aufs provides a merged view
1959 + to users, as long as one dir is left on any branch aufs can show the
1960 + dir to users. In this case, the branch can be removed from aufs.
1961 + Otherwise aufs rejects deleting the branch.
1963 + If any file on the deleting branch is opened by aufs, then aufs
1967 +Modify the Permission of a Branch
1968 +----------------------------------------------------------------------
1969 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1972 +o rw --> ro: Confirm the modifying branch is not busy
1973 + Aufs rejects the request if any of these conditions are true.
1974 + - a file on the branch is mmap-ed.
1975 + - a regular file on the branch is opened for write and there is no
1976 + same named entry on the upper branch.
1977 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1978 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1979 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2019-03-05 12:13:00.132557473 +0100
1982 +# Copyright (C) 2005-2019 Junjiro R. Okajima
1984 +# This program is free software; you can redistribute it and/or modify
1985 +# it under the terms of the GNU General Public License as published by
1986 +# the Free Software Foundation; either version 2 of the License, or
1987 +# (at your option) any later version.
1989 +# This program is distributed in the hope that it will be useful,
1990 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1991 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1992 +# GNU General Public License for more details.
1994 +# You should have received a copy of the GNU General Public License
1995 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1997 +Policies to Select One among Multiple Writable Branches
1998 +----------------------------------------------------------------------
1999 +When the number of writable branch is more than one, aufs has to decide
2000 +the target branch for file creation or copy-up. By default, the highest
2001 +writable branch which has the parent (or ancestor) dir of the target
2002 +file is chosen (top-down-parent policy).
2003 +By user's request, aufs implements some other policies to select the
2004 +writable branch, for file creation several policies, round-robin,
2005 +most-free-space, and other policies. For copy-up, top-down-parent,
2006 +bottom-up-parent, bottom-up and others.
2008 +As expected, the round-robin policy selects the branch in circular. When
2009 +you have two writable branches and creates 10 new files, 5 files will be
2010 +created for each branch. mkdir(2) systemcall is an exception. When you
2011 +create 10 new directories, all will be created on the same branch.
2012 +And the most-free-space policy selects the one which has most free
2013 +space among the writable branches. The amount of free space will be
2014 +checked by aufs internally, and users can specify its time interval.
2016 +The policies for copy-up is more simple,
2017 +top-down-parent is equivalent to the same named on in create policy,
2018 +bottom-up-parent selects the writable branch where the parent dir
2019 +exists and the nearest upper one from the copyup-source,
2020 +bottom-up selects the nearest upper writable branch from the
2021 +copyup-source, regardless the existence of the parent dir.
2023 +There are some rules or exceptions to apply these policies.
2024 +- If there is a readonly branch above the policy-selected branch and
2025 + the parent dir is marked as opaque (a variation of whiteout), or the
2026 + target (creating) file is whiteout-ed on the upper readonly branch,
2027 + then the result of the policy is ignored and the target file will be
2028 + created on the nearest upper writable branch than the readonly branch.
2029 +- If there is a writable branch above the policy-selected branch and
2030 + the parent dir is marked as opaque or the target file is whiteouted
2031 + on the branch, then the result of the policy is ignored and the target
2032 + file will be created on the highest one among the upper writable
2033 + branches who has diropq or whiteout. In case of whiteout, aufs removes
2035 +- link(2) and rename(2) systemcalls are exceptions in every policy.
2036 + They try selecting the branch where the source exists as possible
2037 + since copyup a large file will take long time. If it can't be,
2038 + ie. the branch where the source exists is readonly, then they will
2039 + follow the copyup policy.
2040 +- There is an exception for rename(2) when the target exists.
2041 + If the rename target exists, aufs compares the index of the branches
2042 + where the source and the target exists and selects the higher
2043 + one. If the selected branch is readonly, then aufs follows the
2045 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
2046 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
2047 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2018-04-15 08:49:13.394483860 +0200
2050 +// to view this graph, run dot(1) command in GRAPHVIZ.
2054 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
2058 +aufs_rename -> whinfo [label="store/remove"];
2061 +inode_list [label="h_inum list in branch\ncache"];
2064 +whinode [label="h_inum list file"];
2067 +brmgmt [label="br_add/del/mod/umount"];
2069 +brmgmt -> inode_list [label="create/remove"];
2070 +brmgmt -> whinode [label="load/store"];
2072 +inode_list -> whinode [style=dashed,dir=both];
2074 +aufs_rename -> inode_list [label="add/del"];
2076 +aufs_lookup -> inode_list [label="search"];
2078 +aufs_lookup -> whinfo [label="load/remove"];
2080 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
2081 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
2082 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2019-03-05 12:13:00.132557473 +0100
2085 +# Copyright (C) 2017-2019 Junjiro R. Okajima
2087 +# This program is free software; you can redistribute it and/or modify
2088 +# it under the terms of the GNU General Public License as published by
2089 +# the Free Software Foundation; either version 2 of the License, or
2090 +# (at your option) any later version.
2092 +# This program is distributed in the hope that it will be useful,
2093 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2094 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2095 +# GNU General Public License for more details.
2097 +# You should have received a copy of the GNU General Public License
2098 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2100 +Special handling for renaming a directory (DIRREN)
2101 +----------------------------------------------------------------------
2102 +First, let's assume we have a simple usecase.
2106 +- /ro/dirA and /ro/dirA/file exist too
2107 +- there is no dirB on both branches
2108 +- a user issues rename("dirA", "dirB")
2110 +Now, what should aufs behave against this rename(2)?
2111 +There are a few possible cases.
2114 + since dirA exists on a readonly branch which cannot be renamed.
2116 + it is possible to copy-up dirA (only the dir itself), but the child
2117 + entries ("file" in this case) should not be. it must be a bad
2118 + approach to copy-up recursively.
2119 +C. returns a success.
2120 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
2121 + is a violation of aufs' policy.
2122 +D. construct an extra information which indicates that /ro/dirA should
2123 + be handled as the name of dirB.
2124 + overlayfs has a similar feature called REDIRECT.
2126 +Until now, aufs implements the case B only which returns EXDEV, and
2127 +expects the userspace application behaves like mv(1) which tries
2128 +issueing rename(2) recursively.
2130 +A new aufs feature called DIRREN is introduced which implements the case
2131 +D. There are several "extra information" added.
2133 +1. detailed info per renamed directory
2134 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
2135 +2. the inode-number list of directories on a branch
2136 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
2138 +The filename of "detailed info per directory" represents the lower
2139 +branch, and its format is
2140 +- a type of the branch id
2142 + + uuid (not implemented yet)
2145 +- the inode-number of the branch root dir
2147 +And it contains these info in a single regular file.
2149 +- branch's inode-number of the logically renamed dir
2150 +- the name of the before-renamed dir
2152 +The "detailed info per directory" file is created in aufs rename(2), and
2153 +loaded in any lookup.
2154 +The info is considered in lookup for the matching case only. Here
2155 +"matching" means that the root of branch (in the info filename) is same
2156 +to the current looking-up branch. After looking-up the before-renamed
2157 +name, the inode-number is compared. And the matched dentry is used.
2159 +The "inode-number list of directories" is a regular file which contains
2160 +simply the inode-numbers on the branch. The file is created or updated
2161 +in removing the branch, and loaded in adding the branch. Its lifetime is
2162 +equal to the branch.
2163 +The list is refered in lookup, and when the current target inode is
2164 +found in the list, the aufs tries loading the "detailed info per
2165 +directory" and get the changed and valid name of the dir.
2167 +Theoretically these "extra informaiton" may be able to be put into XATTR
2168 +in the dir inode. But aufs doesn't choose this way because
2169 +1. XATTR may not be supported by the branch (or its configuration)
2170 +2. XATTR may have its size limit.
2171 +3. XATTR may be less easy to convert than a regular file, when the
2172 + format of the info is changed in the future.
2173 +At the same time, I agree that the regular file approach is much slower
2174 +than XATTR approach. So, in the future, aufs may take the XATTR or other
2177 +This DIRREN feature is enabled by aufs configuration, and is activated
2178 +by a new mount option.
2180 +For the more complicated case, there is a work with UDBA option, which
2181 +is to dected the direct access to the branches (by-passing aufs) and to
2182 +maintain the cashes in aufs. Since a single cached aufs dentry may
2183 +contains two names, before- and after-rename, the name comparision in
2184 +UDBA handler may not work correctly. In this case, the behaviour will be
2185 +equivalen to udba=reval case.
2186 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
2187 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
2188 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2019-03-05 12:13:00.132557473 +0100
2191 +# Copyright (C) 2011-2019 Junjiro R. Okajima
2193 +# This program is free software; you can redistribute it and/or modify
2194 +# it under the terms of the GNU General Public License as published by
2195 +# the Free Software Foundation; either version 2 of the License, or
2196 +# (at your option) any later version.
2198 +# This program is distributed in the hope that it will be useful,
2199 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2200 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2201 +# GNU General Public License for more details.
2203 +# You should have received a copy of the GNU General Public License
2204 +# along with this program; if not, write to the Free Software
2205 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2208 +File-based Hierarchical Storage Management (FHSM)
2209 +----------------------------------------------------------------------
2210 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2211 +storage world. Aufs provides this feature as file-based with multiple
2212 +writable branches, based upon the principle of "Colder, the Lower".
2213 +Here the word "colder" means that the less used files, and "lower" means
2214 +that the position in the order of the stacked branches vertically.
2215 +These multiple writable branches are prioritized, ie. the topmost one
2216 +should be the fastest drive and be used heavily.
2218 +o Characters in aufs FHSM story
2219 +- aufs itself and a new branch attribute.
2220 +- a new ioctl interface to move-down and to establish a connection with
2221 + the daemon ("move-down" is a converse of "copy-up").
2222 +- userspace tool and daemon.
2224 +The userspace daemon establishes a connection with aufs and waits for
2225 +the notification. The notified information is very similar to struct
2226 +statfs containing the number of consumed blocks and inodes.
2227 +When the consumed blocks/inodes of a branch exceeds the user-specified
2228 +upper watermark, the daemon activates its move-down process until the
2229 +consumed blocks/inodes reaches the user-specified lower watermark.
2231 +The actual move-down is done by aufs based upon the request from
2232 +user-space since we need to maintain the inode number and the internal
2233 +pointer arrays in aufs.
2235 +Currently aufs FHSM handles the regular files only. Additionally they
2236 +must not be hard-linked nor pseudo-linked.
2239 +o Cowork of aufs and the user-space daemon
2240 + During the userspace daemon established the connection, aufs sends a
2241 + small notification to it whenever aufs writes something into the
2242 + writable branch. But it may cost high since aufs issues statfs(2)
2243 + internally. So user can specify a new option to cache the
2244 + info. Actually the notification is controlled by these factors.
2245 + + the specified cache time.
2246 + + classified as "force" by aufs internally.
2247 + Until the specified time expires, aufs doesn't send the info
2248 + except the forced cases. When aufs decide forcing, the info is always
2249 + notified to userspace.
2250 + For example, the number of free inodes is generally large enough and
2251 + the shortage of it happens rarely. So aufs doesn't force the
2252 + notification when creating a new file, directory and others. This is
2253 + the typical case which aufs doesn't force.
2254 + When aufs writes the actual filedata and the files consumes any of new
2255 + blocks, the aufs forces notifying.
2258 +o Interfaces in aufs
2259 +- New branch attribute.
2261 + Specifies that the branch is managed by FHSM feature. In other word,
2262 + participant in the FHSM.
2263 + When nofhsm is set to the branch, it will not be the source/target
2264 + branch of the move-down operation. This attribute is set
2265 + independently from coo and moo attributes, and if you want full
2266 + FHSM, you should specify them as well.
2267 +- New mount option.
2269 + Specifies a second to suppress many less important info to be
2272 + + AUFS_CTL_FHSM_FD
2273 + create a new file descriptor which userspace can read the notification
2274 + (a subset of struct statfs) from aufs.
2275 +- Module parameter 'brs'
2276 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2278 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2279 + When there are two or more branches with fhsm attributes,
2280 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2281 + terminates it. As a result of remounting and branch-manipulation, the
2282 + number of branches with fhsm attribute can be one. In this case,
2283 + /sbin/mount.aufs will terminate the user-space daemon.
2286 +Finally the operation is done as these steps in kernel-space.
2288 + + no one else is using the file.
2289 + + the file is not hard-linked.
2290 + + the file is not pseudo-linked.
2291 + + the file is a regular file.
2292 + + the parent dir is not opaqued.
2293 +- find the target writable branch.
2294 +- make sure the file is not whiteout-ed by the upper (than the target)
2296 +- make the parent dir on the target branch.
2297 +- mutex lock the inode on the branch.
2298 +- unlink the whiteout on the target branch (if exists).
2299 +- lookup and create the whiteout-ed temporary name on the target branch.
2300 +- copy the file as the whiteout-ed temporary name on the target branch.
2301 +- rename the whiteout-ed temporary name to the original name.
2302 +- unlink the file on the source branch.
2303 +- maintain the internal pointer array and the external inode number
2305 +- maintain the timestamps and other attributes of the parent dir and the
2308 +And of course, in every step, an error may happen. So the operation
2309 +should restore the original file state after an error happens.
2310 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2311 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2312 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2019-03-05 12:13:00.132557473 +0100
2315 +# Copyright (C) 2005-2019 Junjiro R. Okajima
2317 +# This program is free software; you can redistribute it and/or modify
2318 +# it under the terms of the GNU General Public License as published by
2319 +# the Free Software Foundation; either version 2 of the License, or
2320 +# (at your option) any later version.
2322 +# This program is distributed in the hope that it will be useful,
2323 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2324 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2325 +# GNU General Public License for more details.
2327 +# You should have received a copy of the GNU General Public License
2328 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2330 +mmap(2) -- File Memory Mapping
2331 +----------------------------------------------------------------------
2332 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2333 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2335 +This approach is simple and good, but there is one problem.
2336 +Under /proc, several entries show the mmapped files by its path (with
2337 +device and inode number), and the printed path will be the path on the
2338 +branch fs's instead of virtual aufs's.
2339 +This is not a problem in most cases, but some utilities lsof(1) (and its
2340 +user) may expect the path on aufs.
2342 +To address this issue, aufs adds a new member called vm_prfile in struct
2343 +vm_area_struct (and struct vm_region). The original vm_file points to
2344 +the file on the branch fs in order to handle everything correctly as
2345 +usual. The new vm_prfile points to a virtual file in aufs, and the
2346 +show-functions in procfs refers to vm_prfile if it is set.
2347 +Also we need to maintain several other places where touching vm_file
2349 +- fork()/clone() copies vma and the reference count of vm_file is
2351 +- merging vma maintains the ref count too.
2353 +This is not a good approach. It just fakes the printed path. But it
2354 +leaves all behaviour around f_mapping unchanged. This is surely an
2356 +Actually aufs had adopted another complicated approach which calls
2357 +generic_file_mmap() and handles struct vm_operations_struct. In this
2358 +approach, aufs met a hard problem and I could not solve it without
2359 +switching the approach.
2361 +There may be one more another approach which is
2362 +- bind-mount the branch-root onto the aufs-root internally
2363 +- grab the new vfsmount (ie. struct mount)
2364 +- lazy-umount the branch-root internally
2365 +- in open(2) the aufs-file, open the branch-file with the hidden
2366 + vfsmount (instead of the original branch's vfsmount)
2367 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2368 + but it may be possible from userspace by the mount helper.
2370 +Adding the internal hidden vfsmount and using it in opening a file, the
2371 +file path under /proc will be printed correctly. This approach looks
2372 +smarter, but is not possible I am afraid.
2373 +- aufs-root may be bind-mount later. when it happens, another hidden
2374 + vfsmount will be required.
2375 +- it is hard to get the chance to bind-mount and lazy-umount
2376 + + in kernel-space, FS can have vfsmount in open(2) via
2377 + file->f_path, and aufs can know its vfsmount. But several locks are
2378 + already acquired, and if aufs tries to bind-mount and lazy-umount
2379 + here, then it may cause a deadlock.
2380 + + in user-space, bind-mount doesn't invoke the mount helper.
2381 +- since /proc shows dev and ino, aufs has to give vma these info. it
2382 + means a new member vm_prinode will be necessary. this is essentially
2383 + equivalent to vm_prfile described above.
2385 +I have to give up this "looks-smater" approach.
2386 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2387 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2388 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2019-03-05 12:13:00.132557473 +0100
2391 +# Copyright (C) 2014-2019 Junjiro R. Okajima
2393 +# This program is free software; you can redistribute it and/or modify
2394 +# it under the terms of the GNU General Public License as published by
2395 +# the Free Software Foundation; either version 2 of the License, or
2396 +# (at your option) any later version.
2398 +# This program is distributed in the hope that it will be useful,
2399 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2400 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2401 +# GNU General Public License for more details.
2403 +# You should have received a copy of the GNU General Public License
2404 +# along with this program; if not, write to the Free Software
2405 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2408 +Listing XATTR/EA and getting the value
2409 +----------------------------------------------------------------------
2410 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2411 +shows the values from the topmost existing file. This behaviour is good
2412 +for the non-dir entries since the bahaviour exactly matches the shown
2413 +information. But for the directories, aufs considers all the same named
2414 +entries on the lower branches. Which means, if one of the lower entry
2415 +rejects readdir call, then aufs returns an error even if the topmost
2416 +entry allows it. This behaviour is necessary to respect the branch fs's
2417 +security, but can make users confused since the user-visible standard
2418 +attributes don't match the behaviour.
2419 +To address this issue, aufs has a mount option called dirperm1 which
2420 +checks the permission for the topmost entry only, and ignores the lower
2421 +entry's permission.
2423 +A similar issue can happen around XATTR.
2424 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2425 +always set. Otherwise these very unpleasant situation would happen.
2426 +- listxattr(2) may return the duplicated entries.
2427 +- users may not be able to remove or reset the XATTR forever,
2430 +XATTR/EA support in the internal (copy,move)-(up,down)
2431 +----------------------------------------------------------------------
2432 +Generally the extended attributes of inode are categorized as these.
2433 +- "security" for LSM and capability.
2434 +- "system" for posix ACL, 'acl' mount option is required for the branch
2436 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2437 +- "user" for userspace, 'user_xattr' mount option is required for the
2438 + branch fs generally.
2440 +Moreover there are some other categories. Aufs handles these rather
2441 +unpopular categories as the ordinary ones, ie. there is no special
2442 +condition nor exception.
2444 +In copy-up, the support for XATTR on the dst branch may differ from the
2445 +src branch. In this case, the copy-up operation will get an error and
2446 +the original user operation which triggered the copy-up will fail. It
2447 +can happen that even all copy-up will fail.
2448 +When both of src and dst branches support XATTR and if an error occurs
2449 +during copying XATTR, then the copy-up should fail obviously. That is a
2450 +good reason and aufs should return an error to userspace. But when only
2451 +the src branch support that XATTR, aufs should not return an error.
2452 +For example, the src branch supports ACL but the dst branch doesn't
2453 +because the dst branch may natively un-support it or temporary
2454 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2455 +may NOT return an error even if the XATTR is not supported. It is
2456 +totally up to the branch fs.
2458 +Anyway when the aufs internal copy-up gets an error from the dst branch
2459 +fs, then aufs tries removing the just copied entry and returns the error
2460 +to the userspace. The worst case of this situation will be all copy-up
2463 +For the copy-up operation, there two basic approaches.
2464 +- copy the specified XATTR only (by category above), and return the
2465 + error unconditionally if it happens.
2466 +- copy all XATTR, and ignore the error on the specified category only.
2468 +In order to support XATTR and to implement the correct behaviour, aufs
2469 +chooses the latter approach and introduces some new branch attributes,
2470 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2471 +They correspond to the XATTR namespaces (see above). Additionally, to be
2472 +convenient, "icex" is also provided which means all "icex*" attributes
2473 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2475 +The meaning of these attributes is to ignore the error from setting
2476 +XATTR on that branch.
2477 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2478 +error from the dst branch according to the specified attributes.
2480 +Some XATTR may have its default value. The default value may come from
2481 +the parent dir or the environment. If the default value is set at the
2482 +file creating-time, it will be overwritten by copy-up.
2483 +Some contradiction may happen I am afraid.
2484 +Do we need another attribute to stop copying XATTR? I am unsure. For
2485 +now, aufs implements the branch attributes to ignore the error.
2486 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2487 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2488 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2019-03-05 12:13:00.132557473 +0100
2491 +# Copyright (C) 2005-2019 Junjiro R. Okajima
2493 +# This program is free software; you can redistribute it and/or modify
2494 +# it under the terms of the GNU General Public License as published by
2495 +# the Free Software Foundation; either version 2 of the License, or
2496 +# (at your option) any later version.
2498 +# This program is distributed in the hope that it will be useful,
2499 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2500 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2501 +# GNU General Public License for more details.
2503 +# You should have received a copy of the GNU General Public License
2504 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2506 +Export Aufs via NFS
2507 +----------------------------------------------------------------------
2508 +Here is an approach.
2509 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2511 +- iget_locked(): initialize aufs inode generation for a new inode, and
2512 + store it in xigen file.
2513 +- destroy_inode(): increment aufs inode generation and store it in xigen
2514 + file. it is necessary even if it is not unlinked, because any data of
2515 + inode may be changed by UDBA.
2516 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2517 + build file handle by
2518 + + branch id (4 bytes)
2519 + + superblock generation (4 bytes)
2520 + + inode number (4 or 8 bytes)
2521 + + parent dir inode number (4 or 8 bytes)
2522 + + inode generation (4 bytes))
2523 + + return value of exportfs_encode_fh() for the parent on a branch (4
2525 + + file handle for a branch (by exportfs_encode_fh())
2527 + + find the index of a branch from its id in handle, and check it is
2528 + still exist in aufs.
2529 + + 1st level: get the inode number from handle and search it in cache.
2530 + + 2nd level: if not found in cache, get the parent inode number from
2531 + the handle and search it in cache. and then open the found parent
2532 + dir, find the matching inode number by vfs_readdir() and get its
2533 + name, and call lookup_one_len() for the target dentry.
2534 + + 3rd level: if the parent dir is not cached, call
2535 + exportfs_decode_fh() for a branch and get the parent on a branch,
2536 + build a pathname of it, convert it a pathname in aufs, call
2537 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2539 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2540 + for every branch, but not itself. to get this, (currently) aufs
2541 + searches in current->nsproxy->mnt_ns list. it may not be a good
2542 + idea, but I didn't get other approach.
2543 + + test the generation of the gotten inode.
2544 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2545 + convert it into ESTALE for NFSD.
2546 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2547 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2548 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2549 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2550 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2019-03-05 12:13:00.135890907 +0100
2553 +# Copyright (C) 2005-2019 Junjiro R. Okajima
2555 +# This program is free software; you can redistribute it and/or modify
2556 +# it under the terms of the GNU General Public License as published by
2557 +# the Free Software Foundation; either version 2 of the License, or
2558 +# (at your option) any later version.
2560 +# This program is distributed in the hope that it will be useful,
2561 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2562 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2563 +# GNU General Public License for more details.
2565 +# You should have received a copy of the GNU General Public License
2566 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2568 +Show Whiteout Mode (shwh)
2569 +----------------------------------------------------------------------
2570 +Generally aufs hides the name of whiteouts. But in some cases, to show
2571 +them is very useful for users. For instance, creating a new middle layer
2572 +(branch) by merging existing layers.
2574 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2575 +When you have three branches,
2576 +- Bottom: 'system', squashfs (underlying base system), read-only
2577 +- Middle: 'mods', squashfs, read-only
2578 +- Top: 'overlay', ram (tmpfs), read-write
2580 +The top layer is loaded at boot time and saved at shutdown, to preserve
2581 +the changes made to the system during the session.
2582 +When larger changes have been made, or smaller changes have accumulated,
2583 +the size of the saved top layer data grows. At this point, it would be
2584 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2585 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2586 +restoring save and load speed.
2588 +This merging is simplified by the use of another aufs mount, of just the
2589 +two overlay branches using the 'shwh' option.
2590 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2591 + aufs /livesys/merge_union
2593 +A merged view of these two branches is then available at
2594 +/livesys/merge_union, and the new feature is that the whiteouts are
2596 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2597 +writing to all branches. Also the default mode for all branches is 'ro'.
2598 +It is now possible to save the combined contents of the two overlay
2599 +branches to a new squashfs, e.g.:
2600 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2602 +This new squashfs archive can be stored on the boot device and the
2603 +initramfs will use it to replace the old one at the next boot.
2604 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2605 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2606 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2019-03-05 12:13:00.135890907 +0100
2609 +# Copyright (C) 2010-2019 Junjiro R. Okajima
2611 +# This program is free software; you can redistribute it and/or modify
2612 +# it under the terms of the GNU General Public License as published by
2613 +# the Free Software Foundation; either version 2 of the License, or
2614 +# (at your option) any later version.
2616 +# This program is distributed in the hope that it will be useful,
2617 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2618 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2619 +# GNU General Public License for more details.
2621 +# You should have received a copy of the GNU General Public License
2622 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2624 +Dynamically customizable FS operations
2625 +----------------------------------------------------------------------
2626 +Generally FS operations (struct inode_operations, struct
2627 +address_space_operations, struct file_operations, etc.) are defined as
2628 +"static const", but it never means that FS have only one set of
2629 +operation. Some FS have multiple sets of them. For instance, ext2 has
2630 +three sets, one for XIP, for NOBH, and for normal.
2631 +Since aufs overrides and redirects these operations, sometimes aufs has
2632 +to change its behaviour according to the branch FS type. More importantly
2633 +VFS acts differently if a function (member in the struct) is set or
2634 +not. It means aufs should have several sets of operations and select one
2635 +among them according to the branch FS definition.
2637 +In order to solve this problem and not to affect the behaviour of VFS,
2638 +aufs defines these operations dynamically. For instance, aufs defines
2639 +dummy direct_IO function for struct address_space_operations, but it may
2640 +not be set to the address_space_operations actually. When the branch FS
2641 +doesn't have it, aufs doesn't set it to its address_space_operations
2642 +while the function definition itself is still alive. So the behaviour
2643 +itself will not change, and it will return an error when direct_IO is
2646 +The lifetime of these dynamically generated operation object is
2647 +maintained by aufs branch object. When the branch is removed from aufs,
2648 +the reference counter of the object is decremented. When it reaches
2649 +zero, the dynamically generated operation object will be freed.
2651 +This approach is designed to support AIO (io_submit), Direct I/O and
2653 +Currently this approach is applied to address_space_operations for
2654 +regular files only.
2655 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2656 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2657 +++ linux/Documentation/filesystems/aufs/README 2018-12-27 13:19:17.705082621 +0100
2660 +Aufs4 -- advanced multi layered unification filesystem version 4.x
2666 +----------------------------------------
2667 +In the early days, aufs was entirely re-designed and re-implemented
2668 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2669 +improvements and implementations, it becomes totally different from
2670 +Unionfs while keeping the basic features.
2671 +Recently, Unionfs Version 2.x series begin taking some of the same
2672 +approaches to aufs1's.
2673 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2674 +University and his team.
2676 +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3.
2677 +If you want older kernel version support, try aufs2-2.6.git or
2678 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2680 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2681 + According to Christoph Hellwig, linux rejects all union-type
2682 + filesystems but UnionMount.
2683 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2685 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2686 + UnionMount, and he pointed out an issue around a directory mutex
2687 + lock and aufs addressed it. But it is still unsure whether aufs will
2688 + be merged (or any other union solution).
2689 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2693 +----------------------------------------
2694 +- unite several directories into a single virtual filesystem. The member
2695 + directory is called as a branch.
2696 +- you can specify the permission flags to the branch, which are 'readonly',
2697 + 'readwrite' and 'whiteout-able.'
2698 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2699 + readonly branch are modifiable logically.
2700 +- dynamic branch manipulation, add, del.
2703 +Also there are many enhancements in aufs, such as:
2704 +- test only the highest one for the directory permission (dirperm1)
2705 +- copyup on open (coo=)
2706 +- 'move' policy for copy-up between two writable branches, after
2707 + checking free space.
2709 +- readdir(3) in userspace.
2710 +- keep inode number by external inode number table
2711 +- keep the timestamps of file/dir in internal copyup operation
2712 +- seekable directory, supporting NFS readdir.
2713 +- whiteout is hardlinked in order to reduce the consumption of inodes
2715 +- do not copyup, nor create a whiteout when it is unnecessary
2716 +- revert a single systemcall when an error occurs in aufs
2717 +- remount interface instead of ioctl
2718 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2719 +- loopback mounted filesystem as a branch
2720 +- kernel thread for removing the dir who has a plenty of whiteouts
2721 +- support copyup sparse file (a file which has a 'hole' in it)
2722 +- default permission flags for branches
2723 +- selectable permission flags for ro branch, whether whiteout can
2726 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2727 +- support multiple writable branches, some policies to select one
2728 + among multiple writable branches.
2729 +- a new semantics for link(2) and rename(2) to support multiple
2730 + writable branches.
2731 +- no glibc changes are required.
2732 +- pseudo hardlink (hardlink over branches)
2733 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2734 + including NFS or remote filesystem branch.
2735 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2738 +Currently these features are dropped temporary from aufs4.
2739 +See design/08plan.txt in detail.
2740 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2742 +- statistics of aufs thread (/sys/fs/aufs/stat)
2744 +Features or just an idea in the future (see also design/*.txt),
2745 +- reorder the branch index without del/re-add.
2746 +- permanent xino files for NFSD
2747 +- an option for refreshing the opened files after add/del branches
2748 +- light version, without branch manipulation. (unnecessary?)
2749 +- copyup in userspace
2750 +- inotify in userspace
2755 +----------------------------------------
2756 +There are three GIT trees for aufs4, aufs4-linux.git,
2757 +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in
2759 +While the aufs-util is always necessary, you need either of aufs4-linux
2760 +or aufs4-standalone.
2762 +The aufs4-linux tree includes the whole linux mainline GIT tree,
2763 +git://git.kernel.org/.../torvalds/linux.git.
2764 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2765 +build aufs4 as an external kernel module.
2766 +Several extra patches are not included in this tree. Only
2767 +aufs4-standalone tree contains them. They are described in the later
2768 +section "Configuration and Compilation."
2770 +On the other hand, the aufs4-standalone tree has only aufs source files
2771 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2772 +But you need to apply all aufs patches manually.
2774 +You will find GIT branches whose name is in form of "aufs4.x" where "x"
2775 +represents the linux kernel version, "linux-4.x". For instance,
2776 +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use
2777 +"aufs4.x-rcN" branch.
2780 +$ git clone --reference /your/linux/git/tree \
2781 + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git
2782 +- if you don't have linux GIT tree, then remove "--reference ..."
2783 +$ cd aufs4-linux.git
2784 +$ git checkout origin/aufs4.0
2786 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2787 +leave the patch-work to GIT.
2788 +$ cd /your/linux/git/tree
2789 +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git
2791 +$ git checkout -b my4.0 v4.0
2792 +$ (add your local change...)
2793 +$ git pull aufs4 aufs4.0
2794 +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch.
2795 +- you may need to solve some conflicts between your_changes and
2796 + aufs4.0. in this case, git-rerere is recommended so that you can
2797 + solve the similar conflicts automatically when you upgrade to 4.1 or
2798 + later in the future.
2800 +o aufs4-standalone tree
2801 +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git
2802 +$ cd aufs4-standalone.git
2803 +$ git checkout origin/aufs4.0
2806 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2807 +- note that the public aufs-util.git is on SourceForge instead of
2810 +$ git checkout origin/aufs4.0
2812 +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY.
2813 +The minor version number, 'x' in '4.x', of aufs may not always
2814 +follow the minor version number of the kernel.
2815 +Because changes in the kernel that cause the use of a new
2816 +minor version number do not always require changes to aufs-util.
2818 +Since aufs-util has its own minor version number, you may not be
2819 +able to find a GIT branch in aufs-util for your kernel's
2820 +exact minor version number.
2821 +In this case, you should git-checkout the branch for the
2822 +nearest lower number.
2824 +For (an unreleased) example:
2825 +If you are using "linux-4.10" and the "aufs4.10" branch
2826 +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8"
2827 +or something numerically smaller is the branch for your kernel.
2829 +Also you can view all branches by
2833 +3. Configuration and Compilation
2834 +----------------------------------------
2835 +Make sure you have git-checkout'ed the correct branch.
2837 +For aufs4-linux tree,
2838 +- enable CONFIG_AUFS_FS.
2839 +- set other aufs configurations if necessary.
2841 +For aufs4-standalone tree,
2842 +There are several ways to build.
2845 +- apply ./aufs4-kbuild.patch to your kernel source files.
2846 +- apply ./aufs4-base.patch too.
2847 +- apply ./aufs4-mmap.patch too.
2848 +- apply ./aufs4-standalone.patch too, if you have a plan to set
2849 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch.
2850 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2851 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2852 +- enable CONFIG_AUFS_FS, you can select either
2854 +- and build your kernel as usual.
2855 +- install the built kernel.
2856 + Note: Since linux-3.9, every filesystem module requires an alias
2857 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2858 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2859 +- install the header files too by "make headers_install" to the
2860 + directory where you specify. By default, it is $PWD/usr.
2861 + "make help" shows a brief note for headers_install.
2862 +- and reboot your system.
2865 +- module only (CONFIG_AUFS_FS=m).
2866 +- apply ./aufs4-base.patch to your kernel source files.
2867 +- apply ./aufs4-mmap.patch too.
2868 +- apply ./aufs4-standalone.patch too.
2869 +- build your kernel, don't forget "make headers_install", and reboot.
2870 +- edit ./config.mk and set other aufs configurations if necessary.
2871 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2872 + every aufs configurations.
2873 +- build the module by simple "make".
2874 + Note: Since linux-3.9, every filesystem module requires an alias
2875 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2876 + modules.aliases file.
2877 +- you can specify ${KDIR} make variable which points to your kernel
2879 +- install the files
2880 + + run "make install" to install the aufs module, or copy the built
2881 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2882 + + run "make install_headers" (instead of headers_install) to install
2883 + the modified aufs header file (you can specify DESTDIR which is
2884 + available in aufs standalone version's Makefile only), or copy
2885 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2886 + you like manually. By default, the target directory is $PWD/usr.
2887 +- no need to apply aufs4-kbuild.patch, nor copying source files to your
2888 + kernel source tree.
2890 +Note: The header file aufs_type.h is necessary to build aufs-util
2891 + as well as "make headers_install" in the kernel source tree.
2892 + headers_install is subject to be forgotten, but it is essentially
2893 + necessary, not only for building aufs-util.
2894 + You may not meet problems without headers_install in some older
2898 +- read README in aufs-util, build and install it
2899 +- note that your distribution may contain an obsoleted version of
2900 + aufs_type.h in /usr/include/linux or something. When you build aufs
2901 + utilities, make sure that your compiler refers the correct aufs header
2902 + file which is built by "make headers_install."
2903 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2904 + then run "make install_ulib" too. And refer to the aufs manual in
2907 +There several other patches in aufs4-standalone.git. They are all
2908 +optional. When you meet some problems, they will help you.
2909 +- aufs4-loopback.patch
2910 + Supports a nested loopback mount in a branch-fs. This patch is
2911 + unnecessary until aufs produces a message like "you may want to try
2912 + another patch for loopback file".
2914 + Modifies a system global kernel internal function get_next_ino() in
2915 + order to stop assigning 0 for an inode-number. Not directly related to
2916 + aufs, but recommended generally.
2918 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2919 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2920 + duplication of inode number, which is important for backup tools and
2921 + other utilities. When you find aufs XINO files for tmpfs branch
2922 + growing too much, try this patch.
2923 +- lockdep-debug.patch
2924 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2925 + also a caller of VFS functions for branch filesystems, subclassing of
2926 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2927 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2928 + need to apply this debug patch to expand several constant values.
2929 + If don't know what LOCKDEP, then you don't have apply this patch.
2933 +----------------------------------------
2934 +At first, make sure aufs-util are installed, and please read the aufs
2935 +manual, aufs.5 in aufs-util.git tree.
2939 +$ mkdir /tmp/rw /tmp/aufs
2940 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2942 +Here is another example. The result is equivalent.
2943 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2945 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2946 +# mount -o remount,append:${HOME} /tmp/aufs
2948 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2949 +you modify a file under /tmp/aufs, the one on your home directory is
2950 +not affected, instead the same named file will be newly created under
2951 +/tmp/rw. And all of your modification to a file will be applied to
2952 +the one under /tmp/rw. This is called the file based Copy on Write
2954 +Aufs mount options are described in aufs.5.
2955 +If you run chroot or something and make your aufs as a root directory,
2956 +then you need to customize the shutdown script. See the aufs manual in
2959 +Additionally, there are some sample usages of aufs which are a
2960 +diskless system with network booting, and LiveCD over NFS.
2961 +See sample dir in CVS tree on SourceForge.
2965 +----------------------------------------
2966 +When you have any problems or strange behaviour in aufs, please let me
2968 +- /proc/mounts (instead of the output of mount(8))
2969 +- /sys/module/aufs/*
2970 +- /sys/fs/aufs/* (if you have them)
2971 +- /debug/aufs/* (if you have them)
2972 +- linux kernel version
2973 + if your kernel is not plain, for example modified by distributor,
2974 + the url where i can download its source is necessary too.
2975 +- aufs version which was printed at loading the module or booting the
2976 + system, instead of the date you downloaded.
2977 +- configuration (define/undefine CONFIG_AUFS_xxx)
2978 +- kernel configuration or /proc/config.gz (if you have it)
2979 +- behaviour which you think to be incorrect
2980 +- actual operation, reproducible one is better
2981 +- mailto: aufs-users at lists.sourceforge.net
2983 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2984 +and Feature Requests) on SourceForge. Please join and write to
2988 +6. Acknowledgements
2989 +----------------------------------------
2990 +Thanks to everyone who have tried and are using aufs, whoever
2991 +have reported a bug or any feedback.
2993 +Especially donators:
2994 +Tomas Matejicek(slax.org) made a donation (much more than once).
2995 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2996 + scripts) is making "doubling" donations.
2997 + Unfortunately I cannot list all of the donators, but I really
2999 + It ends Aug 2010, but the ordinary donation URL is still available.
3000 + <http://sourceforge.net/donate/index.php?group_id=167503>
3001 +Dai Itasaka made a donation (2007/8).
3002 +Chuck Smith made a donation (2008/4, 10 and 12).
3003 +Henk Schoneveld made a donation (2008/9).
3004 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
3005 +Francois Dupoux made a donation (2008/11).
3006 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
3007 + aufs2 GIT tree (2009/2).
3008 +William Grant made a donation (2009/3).
3009 +Patrick Lane made a donation (2009/4).
3010 +The Mail Archive (mail-archive.com) made donations (2009/5).
3011 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
3012 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
3013 +Pavel Pronskiy made a donation (2011/2).
3014 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
3015 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
3016 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
3018 +Sam Liddicott made a donation (2011/9).
3019 +Era Scarecrow made a donation (2013/4).
3020 +Bor Ratajc made a donation (2013/4).
3021 +Alessandro Gorreta made a donation (2013/4).
3022 +POIRETTE Marc made a donation (2013/4).
3023 +Alessandro Gorreta made a donation (2013/4).
3024 +lauri kasvandik made a donation (2013/5).
3025 +"pemasu from Finland" made a donation (2013/7).
3026 +The Parted Magic Project made a donation (2013/9 and 11).
3027 +Pavel Barta made a donation (2013/10).
3028 +Nikolay Pertsev made a donation (2014/5).
3029 +James B made a donation (2014/7 and 2015/7).
3030 +Stefano Di Biase made a donation (2014/8).
3031 +Daniel Epellei made a donation (2015/1).
3032 +OmegaPhil made a donation (2016/1, 2018/4).
3033 +Tomasz Szewczyk made a donation (2016/4).
3034 +James Burry made a donation (2016/12).
3035 +Carsten Rose made a donation (2018/9).
3036 +Porteus Kiosk made a donation (2018/10).
3038 +Thank you very much.
3039 +Donations are always, including future donations, very important and
3040 +helpful for me to keep on developing aufs.
3044 +----------------------------------------
3045 +If you are an experienced user, no explanation is needed. Aufs is
3046 +just a linux filesystem.
3051 +# Local variables: ;
3054 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
3055 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
3056 +++ linux/fs/aufs/aufs.h 2019-03-05 12:13:00.135890907 +0100
3058 +/* SPDX-License-Identifier: GPL-2.0 */
3060 + * Copyright (C) 2005-2019 Junjiro R. Okajima
3062 + * This program, aufs is free software; you can redistribute it and/or modify
3063 + * it under the terms of the GNU General Public License as published by
3064 + * the Free Software Foundation; either version 2 of the License, or
3065 + * (at your option) any later version.
3067 + * This program is distributed in the hope that it will be useful,
3068 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3069 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3070 + * GNU General Public License for more details.
3072 + * You should have received a copy of the GNU General Public License
3073 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3077 + * all header files
3085 +#define AuStub(type, name, body, ...) \
3086 + static inline type name(__VA_ARGS__) { body; }
3088 +#define AuStubVoid(name, ...) \
3089 + AuStub(void, name, , __VA_ARGS__)
3090 +#define AuStubInt0(name, ...) \
3091 + AuStub(int, name, return 0, __VA_ARGS__)
3095 +#include "branch.h"
3098 +#include "dbgaufs.h"
3099 +#include "dentry.h"
3101 +#include "dirren.h"
3104 +#include "fstype.h"
3109 +#include "module.h"
3113 +#include "sysaufs.h"
3118 +#endif /* __KERNEL__ */
3119 +#endif /* __AUFS_H__ */
3120 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
3121 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
3122 +++ linux/fs/aufs/branch.c 2019-03-05 12:13:00.135890907 +0100
3124 +// SPDX-License-Identifier: GPL-2.0
3126 + * Copyright (C) 2005-2019 Junjiro R. Okajima
3128 + * This program, aufs is free software; you can redistribute it and/or modify
3129 + * it under the terms of the GNU General Public License as published by
3130 + * the Free Software Foundation; either version 2 of the License, or
3131 + * (at your option) any later version.
3133 + * This program is distributed in the hope that it will be useful,
3134 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3135 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3136 + * GNU General Public License for more details.
3138 + * You should have received a copy of the GNU General Public License
3139 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3143 + * branch management
3146 +#include <linux/compat.h>
3147 +#include <linux/statfs.h>
3151 + * free a single branch
3153 +static void au_br_do_free(struct au_branch *br)
3156 + struct au_wbr *wbr;
3157 + struct au_dykey **key;
3159 + au_hnotify_fin_br(br);
3160 + /* always, regardless the mount option */
3161 + au_dr_hino_free(&br->br_dirren);
3164 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
3165 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
3166 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
3167 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
3171 + for (i = 0; i < AuBrWh_Last; i++)
3172 + dput(wbr->wbr_wh[i]);
3173 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
3174 + AuRwDestroy(&wbr->wbr_wh_rwsem);
3177 + if (br->br_fhsm) {
3178 + au_br_fhsm_fin(br->br_fhsm);
3179 + au_kfree_try_rcu(br->br_fhsm);
3182 + key = br->br_dykey;
3183 + for (i = 0; i < AuBrDynOp; i++, key++)
3189 + /* recursive lock, s_umount of branch's */
3190 + /* synchronize_rcu(); */ /* why? */
3192 + path_put(&br->br_path);
3194 + au_kfree_rcu(wbr);
3195 + au_lcnt_wait_for_fin(&br->br_nfiles);
3196 + au_lcnt_wait_for_fin(&br->br_count);
3197 + /* I don't know why, but percpu_refcount requires this */
3198 + /* synchronize_rcu(); */
3203 + * frees all branches
3205 +void au_br_free(struct au_sbinfo *sbinfo)
3207 + aufs_bindex_t bmax;
3208 + struct au_branch **br;
3210 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3212 + bmax = sbinfo->si_bbot + 1;
3213 + br = sbinfo->si_branch;
3215 + au_br_do_free(*br++);
3219 + * find the index of a branch which is specified by @br_id.
3221 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3223 + aufs_bindex_t bindex, bbot;
3225 + bbot = au_sbbot(sb);
3226 + for (bindex = 0; bindex <= bbot; bindex++)
3227 + if (au_sbr_id(sb, bindex) == br_id)
3232 +/* ---------------------------------------------------------------------- */
3238 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3239 + struct dentry *h_root)
3241 + if (unlikely(h_adding == h_root
3242 + || au_test_loopback_overlap(sb, h_adding)))
3244 + if (h_adding->d_sb != h_root->d_sb)
3246 + return au_test_subdir(h_adding, h_root)
3247 + || au_test_subdir(h_root, h_adding);
3251 + * returns a newly allocated branch. @new_nbranch is a number of branches
3252 + * after adding a branch.
3254 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3257 + struct au_branch *add_branch;
3258 + struct dentry *root;
3259 + struct inode *inode;
3263 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3264 + if (unlikely(!add_branch))
3266 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3267 + if (unlikely(!add_branch->br_xino))
3269 + err = au_hnotify_init_br(add_branch, perm);
3270 + if (unlikely(err))
3273 + if (au_br_writable(perm)) {
3274 + /* may be freed separately at changing the branch permission */
3275 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3277 + if (unlikely(!add_branch->br_wbr))
3281 + if (au_br_fhsm(perm)) {
3282 + err = au_fhsm_br_alloc(add_branch);
3283 + if (unlikely(err))
3287 + root = sb->s_root;
3288 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3290 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3292 + inode = d_inode(root);
3293 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3297 + return add_branch; /* success */
3300 + au_kfree_rcu(add_branch->br_wbr);
3302 + au_hnotify_fin_br(add_branch);
3304 + au_xino_put(add_branch);
3306 + au_kfree_rcu(add_branch);
3308 + return ERR_PTR(err);
3312 + * test if the branch permission is legal or not.
3314 +static int test_br(struct inode *inode, int brperm, char *path)
3318 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3323 + pr_err("write permission for readonly mount or inode, %s\n", path);
3331 + * 0: success, the caller will add it
3332 + * plus: success, it is already unified, the caller should ignore it
3335 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3338 + aufs_bindex_t bbot, bindex;
3339 + struct dentry *root, *h_dentry;
3340 + struct inode *inode, *h_inode;
3342 + root = sb->s_root;
3343 + bbot = au_sbbot(sb);
3344 + if (unlikely(bbot >= 0
3345 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3349 + pr_err("%s duplicated\n", add->pathname);
3354 + err = -ENOSPC; /* -E2BIG; */
3355 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3356 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3357 + pr_err("number of branches exceeded %s\n", add->pathname);
3362 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3363 + pr_err("bad index %d\n", add->bindex);
3367 + inode = d_inode(add->path.dentry);
3369 + if (unlikely(!inode->i_nlink)) {
3370 + pr_err("no existence %s\n", add->pathname);
3375 + if (unlikely(inode->i_sb == sb)) {
3376 + pr_err("%s must be outside\n", add->pathname);
3380 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3381 + pr_err("unsupported filesystem, %s (%s)\n",
3382 + add->pathname, au_sbtype(inode->i_sb));
3386 + if (unlikely(inode->i_sb->s_stack_depth)) {
3387 + pr_err("already stacked, %s (%s)\n",
3388 + add->pathname, au_sbtype(inode->i_sb));
3392 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3393 + if (unlikely(err))
3397 + return 0; /* success */
3400 + for (bindex = 0; bindex <= bbot; bindex++)
3401 + if (unlikely(test_overlap(sb, add->path.dentry,
3402 + au_h_dptr(root, bindex)))) {
3403 + pr_err("%s is overlapped\n", add->pathname);
3408 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3409 + h_dentry = au_h_dptr(root, 0);
3410 + h_inode = d_inode(h_dentry);
3411 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3412 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3413 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3414 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3416 + i_uid_read(inode), i_gid_read(inode),
3417 + (inode->i_mode & S_IALLUGO),
3418 + i_uid_read(h_inode), i_gid_read(h_inode),
3419 + (h_inode->i_mode & S_IALLUGO));
3427 + * initialize or clean the whiteouts for an adding branch
3429 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3432 + int err, old_perm;
3433 + aufs_bindex_t bindex;
3434 + struct inode *h_inode;
3435 + struct au_wbr *wbr;
3436 + struct au_hinode *hdir;
3437 + struct dentry *h_dentry;
3439 + err = vfsub_mnt_want_write(au_br_mnt(br));
3440 + if (unlikely(err))
3444 + old_perm = br->br_perm;
3445 + br->br_perm = new_perm;
3448 + bindex = au_br_index(sb, br->br_id);
3449 + if (0 <= bindex) {
3450 + hdir = au_hi(d_inode(sb->s_root), bindex);
3451 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3453 + h_dentry = au_br_dentry(br);
3454 + h_inode = d_inode(h_dentry);
3455 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3458 + err = au_wh_init(br, sb);
3460 + wbr_wh_write_lock(wbr);
3461 + err = au_wh_init(br, sb);
3462 + wbr_wh_write_unlock(wbr);
3465 + au_hn_inode_unlock(hdir);
3467 + inode_unlock(h_inode);
3468 + vfsub_mnt_drop_write(au_br_mnt(br));
3469 + br->br_perm = old_perm;
3471 + if (!err && wbr && !au_br_writable(new_perm)) {
3472 + au_kfree_rcu(wbr);
3473 + br->br_wbr = NULL;
3480 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3484 + struct kstatfs kst;
3485 + struct au_wbr *wbr;
3488 + au_rw_init(&wbr->wbr_wh_rwsem);
3489 + atomic_set(&wbr->wbr_wh_running, 0);
3492 + * a limit for rmdir/rename a dir
3493 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3495 + err = vfs_statfs(&br->br_path, &kst);
3496 + if (unlikely(err))
3499 + if (kst.f_namelen >= NAME_MAX)
3500 + err = au_br_init_wh(sb, br, perm);
3502 + pr_err("%pd(%s), unsupported namelen %ld\n",
3504 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3510 +/* initialize a new branch */
3511 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3512 + struct au_opt_add *add)
3515 + struct au_branch *brbase;
3517 + struct inode *h_inode;
3520 + br->br_perm = add->perm;
3521 + br->br_path = add->path; /* set first, path_get() later */
3522 + spin_lock_init(&br->br_dykey_lock);
3523 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3524 + au_lcnt_init(&br->br_count, /*release*/NULL);
3525 + br->br_id = au_new_br_id(sb);
3526 + AuDebugOn(br->br_id < 0);
3528 + /* always, regardless the given option */
3529 + err = au_dr_br_init(sb, br, &add->path);
3530 + if (unlikely(err))
3533 + if (au_br_writable(add->perm)) {
3534 + err = au_wbr_init(br, sb, add->perm);
3535 + if (unlikely(err))
3539 + if (au_opt_test(au_mntflags(sb), XINO)) {
3540 + brbase = au_sbr(sb, 0);
3541 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3543 + h_inode = d_inode(add->path.dentry);
3544 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3545 + if (unlikely(err)) {
3546 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3551 + sysaufs_br_init(br);
3552 + path_get(&br->br_path);
3553 + goto out; /* success */
3556 + memset(&br->br_path, 0, sizeof(br->br_path));
3561 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3562 + struct au_branch *br, aufs_bindex_t bbot,
3563 + aufs_bindex_t amount)
3565 + struct au_branch **brp;
3567 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3569 + brp = sbinfo->si_branch + bindex;
3570 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3572 + sbinfo->si_bbot++;
3573 + if (unlikely(bbot < 0))
3574 + sbinfo->si_bbot = 0;
3577 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3578 + aufs_bindex_t bbot, aufs_bindex_t amount)
3580 + struct au_hdentry *hdp;
3582 + AuRwMustWriteLock(&dinfo->di_rwsem);
3584 + hdp = au_hdentry(dinfo, bindex);
3585 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3586 + au_h_dentry_init(hdp);
3588 + if (unlikely(bbot < 0))
3589 + dinfo->di_btop = 0;
3592 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3593 + aufs_bindex_t bbot, aufs_bindex_t amount)
3595 + struct au_hinode *hip;
3597 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3599 + hip = au_hinode(iinfo, bindex);
3600 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3601 + au_hinode_init(hip);
3603 + if (unlikely(bbot < 0))
3604 + iinfo->ii_btop = 0;
3607 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3608 + aufs_bindex_t bindex)
3610 + struct dentry *root, *h_dentry;
3611 + struct inode *root_inode, *h_inode;
3612 + aufs_bindex_t bbot, amount;
3614 + root = sb->s_root;
3615 + root_inode = d_inode(root);
3616 + bbot = au_sbbot(sb);
3617 + amount = bbot + 1 - bindex;
3618 + h_dentry = au_br_dentry(br);
3619 + au_sbilist_lock();
3620 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3621 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3622 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3623 + au_set_h_dptr(root, bindex, dget(h_dentry));
3624 + h_inode = d_inode(h_dentry);
3625 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3626 + au_sbilist_unlock();
3629 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3632 + aufs_bindex_t bbot, add_bindex;
3633 + struct dentry *root, *h_dentry;
3634 + struct inode *root_inode;
3635 + struct au_branch *add_branch;
3637 + root = sb->s_root;
3638 + root_inode = d_inode(root);
3639 + IMustLock(root_inode);
3640 + IiMustWriteLock(root_inode);
3641 + err = test_add(sb, add, remount);
3642 + if (unlikely(err < 0))
3646 + goto out; /* success */
3649 + bbot = au_sbbot(sb);
3650 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3651 + err = PTR_ERR(add_branch);
3652 + if (IS_ERR(add_branch))
3655 + err = au_br_init(add_branch, sb, add);
3656 + if (unlikely(err)) {
3657 + au_br_do_free(add_branch);
3661 + add_bindex = add->bindex;
3662 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3663 + au_br_do_add(sb, add_branch, add_bindex);
3664 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3665 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3667 + h_dentry = add->path.dentry;
3668 + if (!add_bindex) {
3669 + au_cpup_attr_all(root_inode, /*force*/1);
3670 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3672 + au_add_nlink(root_inode, d_inode(h_dentry));
3678 +/* ---------------------------------------------------------------------- */
3680 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3681 + unsigned long long max __maybe_unused,
3684 + unsigned long long n;
3685 + struct file **p, *f;
3686 + struct hlist_bl_head *files;
3687 + struct hlist_bl_node *pos;
3688 + struct au_finfo *finfo;
3692 + files = &au_sbi(sb)->si_files;
3693 + hlist_bl_lock(files);
3694 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3695 + f = finfo->fi_file;
3697 + && !special_file(file_inode(f)->i_mode)) {
3701 + AuDebugOn(n > max);
3704 + hlist_bl_unlock(files);
3709 +static struct file **au_farray_alloc(struct super_block *sb,
3710 + unsigned long long *max)
3712 + struct au_sbinfo *sbi;
3715 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3716 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3719 +static void au_farray_free(struct file **a, unsigned long long max)
3721 + unsigned long long ull;
3723 + for (ull = 0; ull < max; ull++)
3729 +/* ---------------------------------------------------------------------- */
3735 +/* to show the line number, do not make it inlined function */
3736 +#define AuVerbose(do_info, fmt, ...) do { \
3738 + pr_info(fmt, ##__VA_ARGS__); \
3741 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3742 + aufs_bindex_t bbot)
3744 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3747 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3748 + aufs_bindex_t bbot)
3750 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3754 + * test if the branch is deletable or not.
3756 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3757 + unsigned int sigen, const unsigned int verbose)
3759 + int err, i, j, ndentry;
3760 + aufs_bindex_t btop, bbot;
3761 + struct au_dcsub_pages dpages;
3762 + struct au_dpage *dpage;
3765 + err = au_dpages_init(&dpages, GFP_NOFS);
3766 + if (unlikely(err))
3768 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3769 + if (unlikely(err))
3772 + for (i = 0; !err && i < dpages.ndpage; i++) {
3773 + dpage = dpages.dpages + i;
3774 + ndentry = dpage->ndentry;
3775 + for (j = 0; !err && j < ndentry; j++) {
3776 + d = dpage->dentries[j];
3777 + AuDebugOn(au_dcount(d) <= 0);
3778 + if (!au_digen_test(d, sigen)) {
3779 + di_read_lock_child(d, AuLock_IR);
3780 + if (unlikely(au_dbrange_test(d))) {
3781 + di_read_unlock(d, AuLock_IR);
3785 + di_write_lock_child(d);
3786 + if (unlikely(au_dbrange_test(d))) {
3787 + di_write_unlock(d);
3790 + err = au_reval_dpath(d, sigen);
3792 + di_downgrade_lock(d, AuLock_IR);
3794 + di_write_unlock(d);
3799 + /* AuDbgDentry(d); */
3800 + btop = au_dbtop(d);
3801 + bbot = au_dbbot(d);
3802 + if (btop <= bindex
3804 + && au_h_dptr(d, bindex)
3805 + && au_test_dbusy(d, btop, bbot)) {
3807 + AuVerbose(verbose, "busy %pd\n", d);
3810 + di_read_unlock(d, AuLock_IR);
3815 + au_dpages_free(&dpages);
3820 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3821 + unsigned int sigen, const unsigned int verbose)
3824 + unsigned long long max, ull;
3825 + struct inode *i, **array;
3826 + aufs_bindex_t btop, bbot;
3828 + array = au_iarray_alloc(sb, &max);
3829 + err = PTR_ERR(array);
3830 + if (IS_ERR(array))
3834 + AuDbg("b%d\n", bindex);
3835 + for (ull = 0; !err && ull < max; ull++) {
3839 + if (i->i_ino == AUFS_ROOT_INO)
3842 + /* AuDbgInode(i); */
3843 + if (au_iigen(i, NULL) == sigen)
3844 + ii_read_lock_child(i);
3846 + ii_write_lock_child(i);
3847 + err = au_refresh_hinode_self(i);
3850 + ii_downgrade_lock(i);
3852 + ii_write_unlock(i);
3857 + btop = au_ibtop(i);
3858 + bbot = au_ibbot(i);
3859 + if (btop <= bindex
3861 + && au_h_iptr(i, bindex)
3862 + && au_test_ibusy(i, btop, bbot)) {
3864 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3867 + ii_read_unlock(i);
3869 + au_iarray_free(array, max);
3875 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3876 + const unsigned int verbose)
3879 + unsigned int sigen;
3881 + sigen = au_sigen(root->d_sb);
3882 + DiMustNoWaiters(root);
3883 + IiMustNoWaiters(d_inode(root));
3884 + di_write_unlock(root);
3885 + err = test_dentry_busy(root, bindex, sigen, verbose);
3887 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3888 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3893 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3894 + struct file **to_free, int *idx)
3897 + unsigned char matched, root;
3898 + aufs_bindex_t bindex, bbot;
3899 + struct au_fidir *fidir;
3900 + struct au_hfile *hfile;
3903 + root = IS_ROOT(file->f_path.dentry);
3906 + to_free[*idx] = file;
3912 + fidir = au_fi(file)->fi_hdir;
3913 + AuDebugOn(!fidir);
3914 + bbot = au_fbbot_dir(file);
3915 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3916 + hfile = fidir->fd_hfile + bindex;
3917 + if (!hfile->hf_file)
3920 + if (hfile->hf_br->br_id == br_id) {
3932 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3933 + struct file **to_free, int opened)
3936 + unsigned long long ull, max;
3937 + aufs_bindex_t btop;
3938 + struct file *file, **array;
3939 + struct dentry *root;
3940 + struct au_hfile *hfile;
3942 + array = au_farray_alloc(sb, &max);
3943 + err = PTR_ERR(array);
3944 + if (IS_ERR(array))
3949 + root = sb->s_root;
3950 + di_write_unlock(root);
3951 + for (ull = 0; ull < max; ull++) {
3952 + file = array[ull];
3953 + if (unlikely(!file))
3956 + /* AuDbg("%pD\n", file); */
3957 + fi_read_lock(file);
3958 + btop = au_fbtop(file);
3959 + if (!d_is_dir(file->f_path.dentry)) {
3960 + hfile = &au_fi(file)->fi_htop;
3961 + if (hfile->hf_br->br_id == br_id)
3964 + err = test_dir_busy(file, br_id, to_free, &idx);
3965 + fi_read_unlock(file);
3966 + if (unlikely(err))
3969 + di_write_lock_child(root);
3970 + au_farray_free(array, max);
3971 + AuDebugOn(idx > opened);
3977 +static void br_del_file(struct file **to_free, unsigned long long opened,
3978 + aufs_bindex_t br_id)
3980 + unsigned long long ull;
3981 + aufs_bindex_t bindex, btop, bbot, bfound;
3982 + struct file *file;
3983 + struct au_fidir *fidir;
3984 + struct au_hfile *hfile;
3986 + for (ull = 0; ull < opened; ull++) {
3987 + file = to_free[ull];
3988 + if (unlikely(!file))
3991 + /* AuDbg("%pD\n", file); */
3992 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3994 + fidir = au_fi(file)->fi_hdir;
3995 + AuDebugOn(!fidir);
3996 + fi_write_lock(file);
3997 + btop = au_fbtop(file);
3998 + bbot = au_fbbot_dir(file);
3999 + for (bindex = btop; bindex <= bbot; bindex++) {
4000 + hfile = fidir->fd_hfile + bindex;
4001 + if (!hfile->hf_file)
4004 + if (hfile->hf_br->br_id == br_id) {
4009 + AuDebugOn(bfound < 0);
4010 + au_set_h_fptr(file, bfound, NULL);
4011 + if (bfound == btop) {
4012 + for (btop++; btop <= bbot; btop++)
4013 + if (au_hf_dir(file, btop)) {
4014 + au_set_fbtop(file, btop);
4018 + fi_write_unlock(file);
4022 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
4023 + const aufs_bindex_t bindex,
4024 + const aufs_bindex_t bbot)
4026 + struct au_branch **brp, **p;
4028 + AuRwMustWriteLock(&sbinfo->si_rwsem);
4030 + brp = sbinfo->si_branch + bindex;
4031 + if (bindex < bbot)
4032 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
4033 + sbinfo->si_branch[0 + bbot] = NULL;
4034 + sbinfo->si_bbot--;
4036 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
4039 + sbinfo->si_branch = p;
4040 + /* harmless error */
4043 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
4044 + const aufs_bindex_t bbot)
4046 + struct au_hdentry *hdp, *p;
4048 + AuRwMustWriteLock(&dinfo->di_rwsem);
4050 + hdp = au_hdentry(dinfo, bindex);
4051 + if (bindex < bbot)
4052 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
4053 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
4056 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
4059 + dinfo->di_hdentry = p;
4060 + /* harmless error */
4063 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
4064 + const aufs_bindex_t bbot)
4066 + struct au_hinode *hip, *p;
4068 + AuRwMustWriteLock(&iinfo->ii_rwsem);
4070 + hip = au_hinode(iinfo, bindex);
4071 + if (bindex < bbot)
4072 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
4073 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
4076 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
4079 + iinfo->ii_hinode = p;
4080 + /* harmless error */
4083 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
4084 + struct au_branch *br)
4086 + aufs_bindex_t bbot;
4087 + struct au_sbinfo *sbinfo;
4088 + struct dentry *root, *h_root;
4089 + struct inode *inode, *h_inode;
4090 + struct au_hinode *hinode;
4092 + SiMustWriteLock(sb);
4094 + root = sb->s_root;
4095 + inode = d_inode(root);
4096 + sbinfo = au_sbi(sb);
4097 + bbot = sbinfo->si_bbot;
4099 + h_root = au_h_dptr(root, bindex);
4100 + hinode = au_hi(inode, bindex);
4101 + h_inode = au_igrab(hinode->hi_inode);
4104 + au_sbilist_lock();
4105 + au_br_do_del_brp(sbinfo, bindex, bbot);
4106 + au_br_do_del_hdp(au_di(root), bindex, bbot);
4107 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
4108 + au_sbilist_unlock();
4110 + /* ignore an error */
4111 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
4115 + au_br_do_free(br);
4118 +static unsigned long long empty_cb(struct super_block *sb, void *array,
4119 + unsigned long long max, void *arg)
4124 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
4127 + unsigned long long opened;
4128 + unsigned int mnt_flags;
4129 + aufs_bindex_t bindex, bbot, br_id;
4130 + unsigned char do_wh, verbose;
4131 + struct au_branch *br;
4132 + struct au_wbr *wbr;
4133 + struct dentry *root;
4134 + struct file **to_free;
4139 + root = sb->s_root;
4140 + bindex = au_find_dbindex(root, del->h_path.dentry);
4143 + goto out; /* success */
4145 + pr_err("%s no such branch\n", del->pathname);
4148 + AuDbg("bindex b%d\n", bindex);
4151 + mnt_flags = au_mntflags(sb);
4152 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4153 + bbot = au_sbbot(sb);
4154 + if (unlikely(!bbot)) {
4155 + AuVerbose(verbose, "no more branches left\n");
4159 + br = au_sbr(sb, bindex);
4160 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
4161 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
4162 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
4166 + br_id = br->br_id;
4167 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
4168 + if (unlikely(opened)) {
4169 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
4170 + err = PTR_ERR(to_free);
4171 + if (IS_ERR(to_free))
4174 + err = test_file_busy(sb, br_id, to_free, opened);
4175 + if (unlikely(err)) {
4176 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
4182 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4184 + /* instead of WbrWhMustWriteLock(wbr) */
4185 + SiMustWriteLock(sb);
4186 + for (i = 0; i < AuBrWh_Last; i++) {
4187 + dput(wbr->wbr_wh[i]);
4188 + wbr->wbr_wh[i] = NULL;
4192 + err = test_children_busy(root, bindex, verbose);
4193 + if (unlikely(err)) {
4202 + * now we confirmed the branch is deletable.
4203 + * let's free the remaining opened dirs on the branch.
4205 + di_write_unlock(root);
4206 + br_del_file(to_free, opened, br_id);
4207 + di_write_lock_child(root);
4210 + sysaufs_brs_del(sb, bindex); /* remove successors */
4211 + dbgaufs_xino_del(br); /* remove one */
4212 + au_br_do_del(sb, bindex, br);
4213 + sysaufs_brs_add(sb, bindex); /* append successors */
4214 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4217 + au_cpup_attr_all(d_inode(root), /*force*/1);
4218 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4220 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4221 + if (au_opt_test(mnt_flags, PLINK))
4222 + au_plink_half_refresh(sb, br_id);
4224 + goto out; /* success */
4228 + rerr = au_br_init_wh(sb, br, br->br_perm);
4230 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4231 + del->pathname, rerr);
4234 + au_farray_free(to_free, opened);
4238 +/* ---------------------------------------------------------------------- */
4240 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4243 + aufs_bindex_t btop, bbot;
4244 + struct aufs_ibusy ibusy;
4245 + struct inode *inode, *h_inode;
4248 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4251 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4253 + /* VERIFY_WRITE */
4254 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4255 + if (unlikely(err)) {
4262 + si_read_lock(sb, AuLock_FLUSH);
4263 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4267 + ibusy.h_ino = 0; /* invalid */
4268 + inode = ilookup(sb, ibusy.ino);
4270 + || inode->i_ino == AUFS_ROOT_INO
4271 + || au_is_bad_inode(inode))
4274 + ii_read_lock_child(inode);
4275 + btop = au_ibtop(inode);
4276 + bbot = au_ibbot(inode);
4277 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4278 + h_inode = au_h_iptr(inode, ibusy.bindex);
4279 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4280 + ibusy.h_ino = h_inode->i_ino;
4282 + ii_read_unlock(inode);
4286 + si_read_unlock(sb);
4288 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4289 + if (unlikely(err)) {
4298 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4300 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4303 +#ifdef CONFIG_COMPAT
4304 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4306 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4310 +/* ---------------------------------------------------------------------- */
4313 + * change a branch permission
4316 +static void au_warn_ima(void)
4319 + /* since it doesn't support mark_files_ro() */
4320 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4324 +static int do_need_sigen_inc(int a, int b)
4326 + return au_br_whable(a) && !au_br_whable(b);
4329 +static int need_sigen_inc(int old, int new)
4331 + return do_need_sigen_inc(old, new)
4332 + || do_need_sigen_inc(new, old);
4335 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4338 + unsigned int mnt_flags;
4339 + unsigned long long ull, max;
4340 + aufs_bindex_t br_id;
4341 + unsigned char verbose, writer;
4342 + struct file *file, *hf, **array;
4343 + struct au_hfile *hfile;
4345 + mnt_flags = au_mntflags(sb);
4346 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4348 + array = au_farray_alloc(sb, &max);
4349 + err = PTR_ERR(array);
4350 + if (IS_ERR(array))
4354 + br_id = au_sbr_id(sb, bindex);
4355 + for (ull = 0; ull < max; ull++) {
4356 + file = array[ull];
4357 + if (unlikely(!file))
4360 + /* AuDbg("%pD\n", file); */
4361 + fi_read_lock(file);
4362 + if (unlikely(au_test_mmapped(file))) {
4364 + AuVerbose(verbose, "mmapped %pD\n", file);
4366 + FiMustNoWaiters(file);
4367 + fi_read_unlock(file);
4371 + hfile = &au_fi(file)->fi_htop;
4372 + hf = hfile->hf_file;
4373 + if (!d_is_reg(file->f_path.dentry)
4374 + || !(file->f_mode & FMODE_WRITE)
4375 + || hfile->hf_br->br_id != br_id
4376 + || !(hf->f_mode & FMODE_WRITE))
4377 + array[ull] = NULL;
4383 + FiMustNoWaiters(file);
4384 + fi_read_unlock(file);
4392 + for (ull = 0; ull < max; ull++) {
4393 + file = array[ull];
4397 + /* todo: already flushed? */
4399 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4400 + * approach which resets f_mode and calls mnt_drop_write() and
4401 + * file_release_write() for each file, because the branch
4402 + * attribute in aufs world is totally different from the native
4405 + /* fi_read_lock(file); */
4406 + hfile = &au_fi(file)->fi_htop;
4407 + hf = hfile->hf_file;
4408 + /* fi_read_unlock(file); */
4409 + spin_lock(&hf->f_lock);
4410 + writer = !!(hf->f_mode & FMODE_WRITER);
4411 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4412 + spin_unlock(&hf->f_lock);
4414 + put_write_access(file_inode(hf));
4415 + __mnt_drop_write(hf->f_path.mnt);
4420 + au_farray_free(array, max);
4426 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4430 + aufs_bindex_t bindex;
4431 + struct dentry *root;
4432 + struct au_branch *br;
4433 + struct au_br_fhsm *bf;
4435 + root = sb->s_root;
4436 + bindex = au_find_dbindex(root, mod->h_root);
4439 + return 0; /* success */
4441 + pr_err("%s no such branch\n", mod->path);
4444 + AuDbg("bindex b%d\n", bindex);
4446 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4447 + if (unlikely(err))
4450 + br = au_sbr(sb, bindex);
4451 + AuDebugOn(mod->h_root != au_br_dentry(br));
4452 + if (br->br_perm == mod->perm)
4453 + return 0; /* success */
4455 + /* pre-allocate for non-fhsm --> fhsm */
4457 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4458 + err = au_fhsm_br_alloc(br);
4459 + if (unlikely(err))
4462 + br->br_fhsm = NULL;
4465 + if (au_br_writable(br->br_perm)) {
4466 + /* remove whiteout base */
4467 + err = au_br_init_wh(sb, br, mod->perm);
4468 + if (unlikely(err))
4471 + if (!au_br_writable(mod->perm)) {
4472 + /* rw --> ro, file might be mmapped */
4473 + DiMustNoWaiters(root);
4474 + IiMustNoWaiters(d_inode(root));
4475 + di_write_unlock(root);
4476 + err = au_br_mod_files_ro(sb, bindex);
4477 + /* aufs_write_lock() calls ..._child() */
4478 + di_write_lock_child(root);
4480 + if (unlikely(err)) {
4482 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4485 + rerr = au_wbr_init(br, sb, br->br_perm);
4486 + if (unlikely(rerr)) {
4487 + AuIOErr("nested error %d (%d)\n",
4489 + br->br_perm = mod->perm;
4493 + } else if (au_br_writable(mod->perm)) {
4496 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4498 + err = au_wbr_init(br, sb, mod->perm);
4499 + if (unlikely(err)) {
4500 + au_kfree_rcu(br->br_wbr);
4501 + br->br_wbr = NULL;
4505 + if (unlikely(err))
4508 + if (au_br_fhsm(br->br_perm)) {
4509 + if (!au_br_fhsm(mod->perm)) {
4510 + /* fhsm --> non-fhsm */
4511 + au_br_fhsm_fin(br->br_fhsm);
4512 + au_kfree_rcu(br->br_fhsm);
4513 + br->br_fhsm = NULL;
4515 + } else if (au_br_fhsm(mod->perm))
4516 + /* non-fhsm --> fhsm */
4519 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4520 + br->br_perm = mod->perm;
4521 + goto out; /* success */
4524 + au_kfree_try_rcu(bf);
4530 +/* ---------------------------------------------------------------------- */
4532 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4535 + struct kstatfs kstfs;
4537 + err = vfs_statfs(&br->br_path, &kstfs);
4539 + stfs->f_blocks = kstfs.f_blocks;
4540 + stfs->f_bavail = kstfs.f_bavail;
4541 + stfs->f_files = kstfs.f_files;
4542 + stfs->f_ffree = kstfs.f_ffree;
4547 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4548 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4549 +++ linux/fs/aufs/branch.h 2019-03-05 12:13:00.135890907 +0100
4551 +/* SPDX-License-Identifier: GPL-2.0 */
4553 + * Copyright (C) 2005-2019 Junjiro R. Okajima
4555 + * This program, aufs is free software; you can redistribute it and/or modify
4556 + * it under the terms of the GNU General Public License as published by
4557 + * the Free Software Foundation; either version 2 of the License, or
4558 + * (at your option) any later version.
4560 + * This program is distributed in the hope that it will be useful,
4561 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4562 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4563 + * GNU General Public License for more details.
4565 + * You should have received a copy of the GNU General Public License
4566 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4570 + * branch filesystems and xino for them
4573 +#ifndef __AUFS_BRANCH_H__
4574 +#define __AUFS_BRANCH_H__
4578 +#include <linux/mount.h>
4579 +#include "dirren.h"
4585 +/* ---------------------------------------------------------------------- */
4589 + struct file **xi_file;
4590 + unsigned int xi_nfile;
4596 + /* reserved for future use */
4597 + /* unsigned long *bitmap; */
4598 + wait_queue_head_t wqh;
4601 + struct mutex xi_mtx; /* protects xi_file array */
4602 + struct hlist_bl_head xi_writing;
4604 + atomic_t xi_truncating;
4606 + struct kref xi_kref;
4609 +/* File-based Hierarchical Storage Management */
4610 +struct au_br_fhsm {
4611 +#ifdef CONFIG_AUFS_FHSM
4612 + struct mutex bf_lock;
4613 + unsigned long bf_jiffy;
4614 + struct aufs_stfs bf_stfs;
4619 +/* members for writable branch only */
4620 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4622 + struct au_rwsem wbr_wh_rwsem;
4623 + struct dentry *wbr_wh[AuBrWh_Last];
4624 + atomic_t wbr_wh_running;
4625 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4626 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4627 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4630 + unsigned long long wbr_bytes;
4633 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4634 +#define AuBrDynOp (AuDyLast * 4)
4636 +#ifdef CONFIG_AUFS_HFSNOTIFY
4637 +/* support for asynchronous destruction */
4638 +struct au_br_hfsnotify {
4639 + struct fsnotify_group *hfsn_group;
4643 +/* sysfs entries */
4644 +struct au_brsysfs {
4646 + struct attribute attr;
4655 +/* protected by superblock rwsem */
4657 + struct au_xino *br_xino;
4659 + aufs_bindex_t br_id;
4662 + struct path br_path;
4663 + spinlock_t br_dykey_lock;
4664 + struct au_dykey *br_dykey[AuBrDynOp];
4665 + au_lcnt_t br_nfiles; /* opened files */
4666 + au_lcnt_t br_count; /* in-use for other */
4668 + struct au_wbr *br_wbr;
4669 + struct au_br_fhsm *br_fhsm;
4671 +#ifdef CONFIG_AUFS_HFSNOTIFY
4672 + struct au_br_hfsnotify *br_hfsn;
4675 +#ifdef CONFIG_SYSFS
4676 + /* entries under sysfs per mount-point */
4677 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4680 +#ifdef CONFIG_DEBUG_FS
4681 + struct dentry *br_dbgaufs; /* xino */
4684 + struct au_dr_br br_dirren;
4687 +/* ---------------------------------------------------------------------- */
4689 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4691 + return br->br_path.mnt;
4694 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4696 + return br->br_path.dentry;
4699 +static inline struct super_block *au_br_sb(struct au_branch *br)
4701 + return au_br_mnt(br)->mnt_sb;
4704 +static inline int au_br_rdonly(struct au_branch *br)
4706 + return (sb_rdonly(au_br_sb(br))
4707 + || !au_br_writable(br->br_perm))
4711 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4713 +#ifdef CONFIG_AUFS_HNOTIFY
4714 + return !(brperm & AuBrPerm_RR);
4720 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4722 + int err, exec_flag;
4725 + exec_flag = oflag & __FMODE_EXEC;
4726 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4732 +static inline void au_xino_get(struct au_branch *br)
4734 + struct au_xino *xi;
4738 + kref_get(&xi->xi_kref);
4741 +static inline int au_xino_count(struct au_branch *br)
4744 + struct au_xino *xi;
4749 + v = kref_read(&xi->xi_kref);
4754 +/* ---------------------------------------------------------------------- */
4758 +void au_br_free(struct au_sbinfo *sinfo);
4759 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4761 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4763 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4764 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4765 +#ifdef CONFIG_COMPAT
4766 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4769 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4772 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4775 +static const loff_t au_loff_max = LLONG_MAX;
4777 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4778 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent);
4779 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4780 + struct file *copy_src);
4782 + struct au_xino *xi; /* switch between xino and xigen */
4784 + struct path *base;
4785 + struct file *copy_src;
4787 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4789 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4791 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4793 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4795 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4796 + size_t size, loff_t *pos);
4798 +int au_xib_trunc(struct super_block *sb);
4799 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4801 +struct au_xino *au_xino_alloc(unsigned int nfile);
4802 +int au_xino_put(struct au_branch *br);
4803 +struct file *au_xino_file1(struct au_xino *xi);
4805 +struct au_opt_xino;
4806 +void au_xino_clr(struct super_block *sb);
4807 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4808 +struct file *au_xino_def(struct super_block *sb);
4809 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4810 + struct path *base);
4812 +ino_t au_xino_new_ino(struct super_block *sb);
4813 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4815 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4816 + ino_t h_ino, int idx);
4817 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4820 +int au_xino_path(struct seq_file *seq, struct file *file);
4822 +/* ---------------------------------------------------------------------- */
4824 +/* @idx is signed to accept -1 meaning the first file */
4825 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4827 + struct file *file;
4834 + if (idx < xi->xi_nfile)
4835 + file = xi->xi_file[idx];
4837 + file = au_xino_file1(xi);
4843 +/* ---------------------------------------------------------------------- */
4845 +/* Superblock to branch */
4847 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4849 + return au_sbr(sb, bindex)->br_id;
4853 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4855 + return au_br_mnt(au_sbr(sb, bindex));
4859 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4861 + return au_br_sb(au_sbr(sb, bindex));
4864 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4866 + return au_sbr(sb, bindex)->br_perm;
4869 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4871 + return au_br_whable(au_sbr_perm(sb, bindex));
4874 +/* ---------------------------------------------------------------------- */
4876 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4877 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4878 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4879 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4881 +#define wbr_wh_read_trylock_nested(wbr) \
4882 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4883 +#define wbr_wh_write_trylock_nested(wbr) \
4884 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4887 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4888 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4889 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4891 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4892 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4893 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4895 +/* ---------------------------------------------------------------------- */
4897 +#ifdef CONFIG_AUFS_FHSM
4898 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4900 + mutex_init(&brfhsm->bf_lock);
4901 + brfhsm->bf_jiffy = 0;
4902 + brfhsm->bf_readable = 0;
4905 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4907 + mutex_destroy(&brfhsm->bf_lock);
4910 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4911 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4914 +#endif /* __KERNEL__ */
4915 +#endif /* __AUFS_BRANCH_H__ */
4916 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4917 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4918 +++ linux/fs/aufs/conf.mk 2018-06-04 09:08:09.181412645 +0200
4920 +# SPDX-License-Identifier: GPL-2.0
4922 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4926 +AuConfStr += ${1}=${${1}}
4930 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4932 + HNOTIFY HFSNOTIFY \
4944 +$(foreach i, ${AuConfAll}, \
4945 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4947 +AuConfName = ${obj}/conf.str
4948 +${AuConfName}.tmp: FORCE
4949 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4950 +${AuConfName}: ${AuConfName}.tmp
4951 + @diff -q $< $@ > /dev/null 2>&1 || { \
4952 + echo ' GEN ' $@; \
4956 +clean-files += ${AuConfName} ${AuConfName}.tmp
4957 +${obj}/sysfs.o: ${AuConfName}
4959 +-include ${srctree}/${src}/conf_priv.mk
4960 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4961 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4962 +++ linux/fs/aufs/cpup.c 2019-03-05 12:13:00.135890907 +0100
4964 +// SPDX-License-Identifier: GPL-2.0
4966 + * Copyright (C) 2005-2019 Junjiro R. Okajima
4968 + * This program, aufs is free software; you can redistribute it and/or modify
4969 + * it under the terms of the GNU General Public License as published by
4970 + * the Free Software Foundation; either version 2 of the License, or
4971 + * (at your option) any later version.
4973 + * This program is distributed in the hope that it will be useful,
4974 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4975 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4976 + * GNU General Public License for more details.
4978 + * You should have received a copy of the GNU General Public License
4979 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4983 + * copy-up functions, see wbr_policy.c for copy-down
4986 +#include <linux/fs_stack.h>
4987 +#include <linux/mm.h>
4988 +#include <linux/task_work.h>
4991 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4993 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4994 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4996 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4998 + dst->i_flags |= iflags & ~mask;
4999 + if (au_test_fs_notime(dst->i_sb))
5000 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
5003 +void au_cpup_attr_timesizes(struct inode *inode)
5005 + struct inode *h_inode;
5007 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5008 + fsstack_copy_attr_times(inode, h_inode);
5009 + fsstack_copy_inode_size(inode, h_inode);
5012 +void au_cpup_attr_nlink(struct inode *inode, int force)
5014 + struct inode *h_inode;
5015 + struct super_block *sb;
5016 + aufs_bindex_t bindex, bbot;
5019 + bindex = au_ibtop(inode);
5020 + h_inode = au_h_iptr(inode, bindex);
5022 + && !S_ISDIR(h_inode->i_mode)
5023 + && au_opt_test(au_mntflags(sb), PLINK)
5024 + && au_plink_test(inode))
5028 + * 0 can happen in revalidating.
5029 + * h_inode->i_mutex may not be held here, but it is harmless since once
5030 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
5032 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
5033 + * the incorrect link count.
5035 + set_nlink(inode, h_inode->i_nlink);
5038 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
5039 + * it may includes whplink directory.
5041 + if (S_ISDIR(h_inode->i_mode)) {
5042 + bbot = au_ibbot(inode);
5043 + for (bindex++; bindex <= bbot; bindex++) {
5044 + h_inode = au_h_iptr(inode, bindex);
5046 + au_add_nlink(inode, h_inode);
5051 +void au_cpup_attr_changeable(struct inode *inode)
5053 + struct inode *h_inode;
5055 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5056 + inode->i_mode = h_inode->i_mode;
5057 + inode->i_uid = h_inode->i_uid;
5058 + inode->i_gid = h_inode->i_gid;
5059 + au_cpup_attr_timesizes(inode);
5060 + au_cpup_attr_flags(inode, h_inode->i_flags);
5063 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
5065 + struct au_iinfo *iinfo = au_ii(inode);
5067 + IiMustWriteLock(inode);
5069 + iinfo->ii_higen = h_inode->i_generation;
5070 + iinfo->ii_hsb1 = h_inode->i_sb;
5073 +void au_cpup_attr_all(struct inode *inode, int force)
5075 + struct inode *h_inode;
5077 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5078 + au_cpup_attr_changeable(inode);
5079 + if (inode->i_nlink > 0)
5080 + au_cpup_attr_nlink(inode, force);
5081 + inode->i_rdev = h_inode->i_rdev;
5082 + inode->i_blkbits = h_inode->i_blkbits;
5083 + au_cpup_igen(inode, h_inode);
5086 +/* ---------------------------------------------------------------------- */
5088 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
5090 +/* keep the timestamps of the parent dir when cpup */
5091 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5092 + struct path *h_path)
5094 + struct inode *h_inode;
5096 + dt->dt_dentry = dentry;
5097 + dt->dt_h_path = *h_path;
5098 + h_inode = d_inode(h_path->dentry);
5099 + dt->dt_atime = h_inode->i_atime;
5100 + dt->dt_mtime = h_inode->i_mtime;
5104 +void au_dtime_revert(struct au_dtime *dt)
5106 + struct iattr attr;
5109 + attr.ia_atime = dt->dt_atime;
5110 + attr.ia_mtime = dt->dt_mtime;
5111 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
5112 + | ATTR_ATIME | ATTR_ATIME_SET;
5114 + /* no delegation since this is a directory */
5115 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
5116 + if (unlikely(err))
5117 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
5120 +/* ---------------------------------------------------------------------- */
5122 +/* internal use only */
5123 +struct au_cpup_reg_attr {
5126 + unsigned int iflags; /* inode->i_flags */
5129 +static noinline_for_stack
5130 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
5131 + struct au_cpup_reg_attr *h_src_attr)
5133 + int err, sbits, icex;
5134 + unsigned int mnt_flags;
5135 + unsigned char verbose;
5137 + struct path h_path;
5138 + struct inode *h_isrc, *h_idst;
5139 + struct kstat *h_st;
5140 + struct au_branch *br;
5142 + h_path.dentry = au_h_dptr(dst, bindex);
5143 + h_idst = d_inode(h_path.dentry);
5144 + br = au_sbr(dst->d_sb, bindex);
5145 + h_path.mnt = au_br_mnt(br);
5146 + h_isrc = d_inode(h_src);
5147 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
5148 + | ATTR_ATIME | ATTR_MTIME
5149 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
5150 + if (h_src_attr && h_src_attr->valid) {
5151 + h_st = &h_src_attr->st;
5152 + ia.ia_uid = h_st->uid;
5153 + ia.ia_gid = h_st->gid;
5154 + ia.ia_atime = h_st->atime;
5155 + ia.ia_mtime = h_st->mtime;
5156 + if (h_idst->i_mode != h_st->mode
5157 + && !S_ISLNK(h_idst->i_mode)) {
5158 + ia.ia_valid |= ATTR_MODE;
5159 + ia.ia_mode = h_st->mode;
5161 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
5162 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
5164 + ia.ia_uid = h_isrc->i_uid;
5165 + ia.ia_gid = h_isrc->i_gid;
5166 + ia.ia_atime = h_isrc->i_atime;
5167 + ia.ia_mtime = h_isrc->i_mtime;
5168 + if (h_idst->i_mode != h_isrc->i_mode
5169 + && !S_ISLNK(h_idst->i_mode)) {
5170 + ia.ia_valid |= ATTR_MODE;
5171 + ia.ia_mode = h_isrc->i_mode;
5173 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5174 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5176 + /* no delegation since it is just created */
5177 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5179 + /* is this nfs only? */
5180 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5181 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5182 + ia.ia_mode = h_isrc->i_mode;
5183 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5186 + icex = br->br_perm & AuBrAttr_ICEX;
5188 + mnt_flags = au_mntflags(dst->d_sb);
5189 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5190 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5196 +/* ---------------------------------------------------------------------- */
5198 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5199 + char *buf, unsigned long blksize)
5202 + size_t sz, rbytes, wbytes;
5203 + unsigned char all_zero;
5205 + struct inode *h_inode;
5206 + /* reduce stack usage */
5209 + zp = page_address(ZERO_PAGE(0));
5210 + if (unlikely(!zp))
5211 + return -ENOMEM; /* possible? */
5216 + AuDbg("len %lld\n", len);
5218 + if (len < blksize)
5222 + /* todo: signal_pending? */
5223 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5224 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5227 + if (unlikely(err < 0))
5231 + if (len >= rbytes && rbytes == blksize)
5232 + all_zero = !memcmp(buf, zp, rbytes);
5239 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5241 + /* todo: signal_pending? */
5242 + if (unlikely(err == -EAGAIN || err == -EINTR))
5244 + if (unlikely(err < 0))
5249 + if (unlikely(err < 0))
5255 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5257 + if (unlikely(res < 0))
5264 + /* the last block may be a hole */
5265 + if (!err && all_zero) {
5266 + AuLabel(last hole);
5269 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5270 + /* nfs requires this step to make last hole */
5271 + /* is this only nfs? */
5273 + /* todo: signal_pending? */
5274 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5275 + } while (err == -EAGAIN || err == -EINTR);
5282 + ia->ia_size = dst->f_pos;
5283 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5284 + ia->ia_file = dst;
5285 + h_inode = file_inode(dst);
5286 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5287 + /* no delegation since it is just created */
5288 + err = vfsub_notify_change(&dst->f_path, ia,
5289 + /*delegated*/NULL);
5290 + inode_unlock(h_inode);
5297 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5300 + unsigned long blksize;
5301 + unsigned char do_kfree;
5303 + struct super_block *h_sb;
5306 + h_sb = file_inode(dst)->i_sb;
5307 + blksize = h_sb->s_blocksize;
5308 + if (!blksize || PAGE_SIZE < blksize)
5309 + blksize = PAGE_SIZE;
5310 + AuDbg("blksize %lu\n", blksize);
5311 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5313 + buf = kmalloc(blksize, GFP_NOFS);
5315 + buf = (void *)__get_free_page(GFP_NOFS);
5316 + if (unlikely(!buf))
5319 + if (len > (1 << 22))
5320 + AuDbg("copying a large file %lld\n", (long long)len);
5324 + err = au_do_copy_file(dst, src, len, buf, blksize);
5326 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5327 + au_kfree_do_rcu(buf);
5329 + free_page((unsigned long)buf);
5335 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5338 + struct super_block *h_src_sb;
5339 + struct inode *h_src_inode;
5341 + h_src_inode = file_inode(src);
5342 + h_src_sb = h_src_inode->i_sb;
5344 + /* XFS acquires inode_lock */
5345 + if (!au_test_xfs(h_src_sb))
5346 + err = au_copy_file(dst, src, len);
5348 + inode_unlock_shared(h_src_inode);
5349 + err = au_copy_file(dst, src, len);
5350 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5356 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5360 + struct super_block *h_src_sb;
5361 + struct inode *h_src_inode;
5363 + h_src_inode = file_inode(src);
5364 + h_src_sb = h_src_inode->i_sb;
5365 + if (h_src_sb != file_inode(dst)->i_sb
5366 + || !dst->f_op->remap_file_range) {
5367 + err = au_do_copy(dst, src, len);
5371 + if (!au_test_nfs(h_src_sb)) {
5372 + inode_unlock_shared(h_src_inode);
5373 + lo = vfsub_clone_file_range(src, dst, len);
5374 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5376 + lo = vfsub_clone_file_range(src, dst, len);
5379 + goto out; /* success */
5380 + } else if (lo >= 0)
5381 + /* todo: possible? */
5382 + /* paritially succeeded */
5383 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5384 + else if (lo != -EOPNOTSUPP) {
5385 + /* older XFS has a condition in cloning */
5390 + /* the backend fs on NFS may not support cloning */
5391 + err = au_do_copy(dst, src, len);
5399 + * to support a sparse file which is opened with O_APPEND,
5400 + * we need to close the file.
5402 +static int au_cp_regular(struct au_cp_generic *cpg)
5405 + enum { SRC, DST };
5407 + aufs_bindex_t bindex;
5408 + unsigned int flags;
5409 + struct dentry *dentry;
5411 + struct file *file;
5414 + .bindex = cpg->bsrc,
5415 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5418 + .bindex = cpg->bdst,
5419 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5420 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5423 + struct au_branch *br;
5424 + struct super_block *sb, *h_src_sb;
5425 + struct inode *h_src_inode;
5426 + struct task_struct *tsk = current;
5428 + /* bsrc branch can be ro/rw. */
5429 + sb = cpg->dentry->d_sb;
5431 + for (i = 0; i < 2; i++, f++) {
5432 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5433 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5434 + /*file*/NULL, f->force_wr);
5435 + if (IS_ERR(f->file)) {
5436 + err = PTR_ERR(f->file);
5444 + /* try stopping to update while we copyup */
5445 + h_src_inode = d_inode(file[SRC].dentry);
5446 + h_src_sb = h_src_inode->i_sb;
5447 + if (!au_test_nfs(h_src_sb))
5448 + IMustLock(h_src_inode);
5449 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5451 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5452 + if (tsk->flags & PF_KTHREAD)
5453 + __fput_sync(file[DST].file);
5455 + /* it happened actually */
5456 + fput(file[DST].file);
5459 + * we have to call both since we don't know which place the file
5463 + flush_delayed_fput();
5465 + br = au_sbr(sb, file[DST].bindex);
5466 + au_lcnt_dec(&br->br_nfiles);
5469 + fput(file[SRC].file);
5470 + br = au_sbr(sb, file[SRC].bindex);
5471 + au_lcnt_dec(&br->br_nfiles);
5476 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5477 + struct au_cpup_reg_attr *h_src_attr)
5481 + struct path h_path;
5482 + struct inode *h_src_inode, *h_dst_inode;
5485 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5486 + l = i_size_read(h_src_inode);
5487 + if (cpg->len == -1 || l < cpg->len)
5490 + /* try stopping to update while we are referencing */
5491 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5492 + au_pin_hdir_unlock(cpg->pin);
5494 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5495 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5496 + h_src_attr->iflags = h_src_inode->i_flags;
5497 + if (!au_test_nfs(h_src_inode->i_sb))
5498 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5500 + inode_unlock_shared(h_src_inode);
5501 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5502 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5504 + if (unlikely(err)) {
5505 + inode_unlock_shared(h_src_inode);
5508 + h_src_attr->valid = 1;
5509 + if (!au_test_nfs(h_src_inode->i_sb)) {
5510 + err = au_cp_regular(cpg);
5511 + inode_unlock_shared(h_src_inode);
5513 + inode_unlock_shared(h_src_inode);
5514 + err = au_cp_regular(cpg);
5516 + rerr = au_pin_hdir_relock(cpg->pin);
5520 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5521 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5522 + h_dst_inode = d_inode(h_path.dentry);
5523 + spin_lock(&h_dst_inode->i_lock);
5524 + h_dst_inode->i_state |= I_LINKABLE;
5525 + spin_unlock(&h_dst_inode->i_lock);
5532 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5533 + struct inode *h_dir)
5536 + mm_segment_t old_fs;
5543 + sym.k = (void *)__get_free_page(GFP_NOFS);
5544 + if (unlikely(!sym.k))
5547 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5548 + old_fs = get_fs();
5549 + set_fs(KERNEL_DS);
5550 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5555 + sym.k[symlen] = 0;
5556 + err = vfsub_symlink(h_dir, h_path, sym.k);
5558 + free_page((unsigned long)sym.k);
5565 + * regardless 'acl' option, reset all ACL.
5566 + * All ACL will be copied up later from the original entry on the lower branch.
5568 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5571 + struct dentry *h_dentry;
5572 + struct inode *h_inode;
5574 + h_dentry = h_path->dentry;
5575 + h_inode = d_inode(h_dentry);
5576 + /* forget_all_cached_acls(h_inode)); */
5577 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5579 + if (err == -EOPNOTSUPP)
5582 + err = vfsub_acl_chmod(h_inode, mode);
5588 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5589 + struct inode *h_dir, struct path *h_path)
5592 + struct inode *dir, *inode;
5594 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5596 + if (err == -EOPNOTSUPP)
5598 + if (unlikely(err))
5602 + * strange behaviour from the users view,
5603 + * particularly setattr case
5605 + dir = d_inode(dst_parent);
5606 + if (au_ibtop(dir) == cpg->bdst)
5607 + au_cpup_attr_nlink(dir, /*force*/1);
5608 + inode = d_inode(cpg->dentry);
5609 + au_cpup_attr_nlink(inode, /*force*/1);
5615 +static noinline_for_stack
5616 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5617 + struct au_cpup_reg_attr *h_src_attr)
5621 + unsigned int mnt_flags;
5622 + unsigned char isdir, isreg, force;
5623 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5624 + struct au_dtime dt;
5625 + struct path h_path;
5626 + struct dentry *h_src, *h_dst, *h_parent;
5627 + struct inode *h_inode, *h_dir;
5628 + struct super_block *sb;
5630 + /* bsrc branch can be ro/rw. */
5631 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5632 + h_inode = d_inode(h_src);
5633 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5635 + /* try stopping to be referenced while we are creating */
5636 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5637 + if (au_ftest_cpup(cpg->flags, RENAME))
5638 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5639 + AUFS_WH_PFX_LEN));
5640 + h_parent = h_dst->d_parent; /* dir inode is locked */
5641 + h_dir = d_inode(h_parent);
5643 + AuDebugOn(h_parent != h_dst->d_parent);
5645 + sb = cpg->dentry->d_sb;
5646 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5648 + h_path.dentry = h_parent;
5649 + au_dtime_store(&dt, dst_parent, &h_path);
5651 + h_path.dentry = h_dst;
5655 + mode = h_inode->i_mode;
5656 + switch (mode & S_IFMT) {
5659 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5661 + err = au_do_cpup_regular(cpg, h_src_attr);
5665 + err = vfsub_mkdir(h_dir, &h_path, mode);
5667 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5670 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5674 + AuDebugOn(!capable(CAP_MKNOD));
5678 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5681 + AuIOErr("Unknown inode type 0%o\n", mode);
5685 + err = au_reset_acl(h_dir, &h_path, mode);
5687 + mnt_flags = au_mntflags(sb);
5688 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5690 + && au_opt_test(mnt_flags, XINO)
5691 + && (h_inode->i_nlink == 1
5692 + || (h_inode->i_state & I_LINKABLE))
5693 + /* todo: unnecessary? */
5694 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5695 + && cpg->bdst < cpg->bsrc
5696 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5697 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5698 + /* ignore this error */
5703 + force = !!cpg->len;
5704 + if (cpg->len == -1)
5705 + force = !!i_size_read(h_inode);
5707 + au_fhsm_wrote(sb, cpg->bdst, force);
5711 + au_dtime_revert(&dt);
5715 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5718 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5719 + struct inode *h_dir;
5720 + aufs_bindex_t bdst;
5722 + dentry = cpg->dentry;
5724 + h_dentry = au_h_dptr(dentry, bdst);
5725 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5727 + au_set_h_dptr(dentry, bdst, NULL);
5728 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5730 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5731 + au_set_h_dptr(dentry, bdst, h_dentry);
5734 + parent = dget_parent(dentry);
5735 + h_parent = au_h_dptr(parent, bdst);
5737 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5738 + if (IS_ERR(h_path->dentry))
5739 + err = PTR_ERR(h_path->dentry);
5741 + if (unlikely(err))
5744 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5745 + h_dir = d_inode(h_parent);
5747 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5748 + /* no delegation since it is just created */
5749 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5751 + dput(h_path->dentry);
5758 + * copyup the @dentry from @bsrc to @bdst.
5759 + * the caller must set the both of lower dentries.
5760 + * @len is for truncating when it is -1 copyup the entire file.
5761 + * in link/rename cases, @dst_parent may be different from the real one.
5762 + * basic->bsrc can be larger than basic->bdst.
5763 + * aufs doesn't touch the credential so
5764 + * security_inode_copy_up{,_xattr}() are unnecessary.
5766 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5769 + aufs_bindex_t old_ibtop;
5770 + unsigned char isdir, plink;
5771 + struct dentry *h_src, *h_dst, *h_parent;
5772 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5773 + struct super_block *sb;
5774 + struct au_branch *br;
5775 + /* to reduce stack size */
5777 + struct au_dtime dt;
5778 + struct path h_path;
5779 + struct au_cpup_reg_attr h_src_attr;
5783 + a = kmalloc(sizeof(*a), GFP_NOFS);
5786 + a->h_src_attr.valid = 0;
5788 + sb = cpg->dentry->d_sb;
5789 + br = au_sbr(sb, cpg->bdst);
5790 + a->h_path.mnt = au_br_mnt(br);
5791 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5792 + h_parent = h_dst->d_parent; /* dir inode is locked */
5793 + h_dir = d_inode(h_parent);
5796 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5797 + inode = d_inode(cpg->dentry);
5800 + dst_parent = dget_parent(cpg->dentry);
5804 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5805 + dst_inode = au_h_iptr(inode, cpg->bdst);
5807 + if (unlikely(!plink)) {
5809 + AuIOErr("hi%lu(i%lu) exists on b%d "
5810 + "but plink is disabled\n",
5811 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5815 + if (dst_inode->i_nlink) {
5816 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5818 + h_src = au_plink_lkup(inode, cpg->bdst);
5819 + err = PTR_ERR(h_src);
5820 + if (IS_ERR(h_src))
5822 + if (unlikely(d_is_negative(h_src))) {
5824 + AuIOErr("i%lu exists on b%d "
5825 + "but not pseudo-linked\n",
5826 + inode->i_ino, cpg->bdst);
5832 + a->h_path.dentry = h_parent;
5833 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5836 + a->h_path.dentry = h_dst;
5838 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5839 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5840 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5842 + au_dtime_revert(&a->dt);
5843 + if (unlikely(err == -EWOULDBLOCK)) {
5844 + pr_warn("cannot retry for NFSv4 delegation"
5845 + " for an internal link\n");
5851 + /* todo: cpup_wh_file? */
5853 + au_update_ibrange(inode, /*do_put_zero*/1);
5856 + isdir = S_ISDIR(inode->i_mode);
5857 + old_ibtop = au_ibtop(inode);
5858 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5859 + if (unlikely(err))
5861 + dst_inode = d_inode(h_dst);
5862 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5863 + /* todo: necessary? */
5864 + /* au_pin_hdir_unlock(cpg->pin); */
5866 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5867 + if (unlikely(err)) {
5868 + /* todo: necessary? */
5869 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5870 + inode_unlock(dst_inode);
5874 + if (cpg->bdst < old_ibtop) {
5875 + if (S_ISREG(inode->i_mode)) {
5876 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5877 + if (unlikely(err)) {
5878 + /* ignore an error */
5879 + /* au_pin_hdir_relock(cpg->pin); */
5880 + inode_unlock(dst_inode);
5884 + au_set_ibtop(inode, cpg->bdst);
5886 + au_set_ibbot(inode, cpg->bdst);
5887 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5888 + au_hi_flags(inode, isdir));
5890 + /* todo: necessary? */
5891 + /* err = au_pin_hdir_relock(cpg->pin); */
5892 + inode_unlock(dst_inode);
5893 + if (unlikely(err))
5896 + src_inode = d_inode(h_src);
5898 + && (src_inode->i_nlink > 1
5899 + || src_inode->i_state & I_LINKABLE)
5901 + au_plink_append(inode, cpg->bdst, h_dst);
5903 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5904 + a->h_path.dentry = h_dst;
5905 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5908 + goto out_parent; /* success */
5912 + a->h_path.dentry = h_parent;
5913 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5914 + a->h_path.dentry = h_dst;
5916 + if (d_is_positive(h_dst)) {
5918 + /* no delegation since it is just created */
5919 + rerr = vfsub_unlink(h_dir, &a->h_path,
5920 + /*delegated*/NULL, /*force*/0);
5922 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5924 + au_dtime_revert(&a->dt);
5926 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5936 +#if 0 /* reserved */
5937 +struct au_cpup_single_args {
5939 + struct au_cp_generic *cpg;
5940 + struct dentry *dst_parent;
5943 +static void au_call_cpup_single(void *args)
5945 + struct au_cpup_single_args *a = args;
5947 + au_pin_hdir_acquire_nest(a->cpg->pin);
5948 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5949 + au_pin_hdir_release(a->cpg->pin);
5954 + * prevent SIGXFSZ in copy-up.
5955 + * testing CAP_MKNOD is for generic fs,
5956 + * but CAP_FSETID is for xfs only, currently.
5958 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5961 + struct super_block *sb;
5962 + struct inode *h_dir;
5965 + sb = au_pinned_parent(pin)->d_sb;
5966 + if (!au_wkq_test()
5967 + && (!au_sbi(sb)->si_plink_maint_pid
5968 + || au_plink_maint(sb, AuLock_NOPLM))) {
5969 + switch (mode & S_IFMT) {
5971 + /* no condition about RLIMIT_FSIZE and the file size */
5976 + do_sio = !capable(CAP_MKNOD);
5980 + do_sio = ((mode & (S_ISUID | S_ISGID))
5981 + && !capable(CAP_FSETID));
5982 + /* this workaround may be removed in the future */
5984 + h_dir = au_pinned_h_dir(pin);
5985 + do_sio = h_dir->i_mode & S_ISVTX;
5992 +#if 0 /* reserved */
5993 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5996 + struct dentry *h_dentry;
5998 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5999 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
6000 + err = au_cpup_single(cpg, dst_parent);
6002 + struct au_cpup_single_args args = {
6005 + .dst_parent = dst_parent
6007 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
6008 + if (unlikely(wkq_err))
6017 + * copyup the @dentry from the first active lower branch to @bdst,
6018 + * using au_cpup_single().
6020 +static int au_cpup_simple(struct au_cp_generic *cpg)
6023 + unsigned int flags_orig;
6024 + struct dentry *dentry;
6026 + AuDebugOn(cpg->bsrc < 0);
6028 + dentry = cpg->dentry;
6029 + DiMustWriteLock(dentry);
6031 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
6033 + flags_orig = cpg->flags;
6034 + au_fset_cpup(cpg->flags, RENAME);
6035 + err = au_cpup_single(cpg, NULL);
6036 + cpg->flags = flags_orig;
6038 + return 0; /* success */
6041 + au_set_h_dptr(dentry, cpg->bdst, NULL);
6042 + au_set_dbtop(dentry, cpg->bsrc);
6048 +struct au_cpup_simple_args {
6050 + struct au_cp_generic *cpg;
6053 +static void au_call_cpup_simple(void *args)
6055 + struct au_cpup_simple_args *a = args;
6057 + au_pin_hdir_acquire_nest(a->cpg->pin);
6058 + *a->errp = au_cpup_simple(a->cpg);
6059 + au_pin_hdir_release(a->cpg->pin);
6062 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
6065 + struct dentry *dentry, *parent;
6066 + struct file *h_file;
6067 + struct inode *h_dir;
6069 + dentry = cpg->dentry;
6071 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
6072 + AuDebugOn(cpg->bsrc < 0);
6073 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
6074 + err = PTR_ERR(h_file);
6075 + if (IS_ERR(h_file))
6079 + parent = dget_parent(dentry);
6080 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
6081 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
6082 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6083 + err = au_cpup_simple(cpg);
6085 + struct au_cpup_simple_args args = {
6089 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
6090 + if (unlikely(wkq_err))
6096 + au_h_open_post(dentry, cpg->bsrc, h_file);
6102 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
6104 + aufs_bindex_t bsrc, bbot;
6105 + struct dentry *dentry, *h_dentry;
6107 + if (cpg->bsrc < 0) {
6108 + dentry = cpg->dentry;
6109 + bbot = au_dbbot(dentry);
6110 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
6111 + h_dentry = au_h_dptr(dentry, bsrc);
6113 + AuDebugOn(d_is_negative(h_dentry));
6117 + AuDebugOn(bsrc > bbot);
6120 + AuDebugOn(cpg->bsrc <= cpg->bdst);
6121 + return au_do_sio_cpup_simple(cpg);
6124 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
6126 + AuDebugOn(cpg->bdst <= cpg->bsrc);
6127 + return au_do_sio_cpup_simple(cpg);
6130 +/* ---------------------------------------------------------------------- */
6133 + * copyup the deleted file for writing.
6135 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
6136 + struct file *file)
6139 + unsigned int flags_orig;
6140 + aufs_bindex_t bsrc_orig;
6141 + struct au_dinfo *dinfo;
6143 + struct au_hdentry *hd;
6144 + struct dentry *h_dentry;
6147 + dinfo = au_di(cpg->dentry);
6148 + AuRwMustWriteLock(&dinfo->di_rwsem);
6150 + bsrc_orig = cpg->bsrc;
6151 + cpg->bsrc = dinfo->di_btop;
6152 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
6153 + hdst.h_dentry = hdst.hd->hd_dentry;
6154 + hdst.hd->hd_dentry = wh_dentry;
6155 + dinfo->di_btop = cpg->bdst;
6157 + hsrc.h_dentry = NULL;
6159 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
6160 + hsrc.h_dentry = hsrc.hd->hd_dentry;
6161 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
6163 + flags_orig = cpg->flags;
6164 + cpg->flags = !AuCpup_DTIME;
6165 + err = au_cpup_single(cpg, /*h_parent*/NULL);
6166 + cpg->flags = flags_orig;
6169 + err = au_reopen_nondir(file);
6170 + hsrc.hd->hd_dentry = hsrc.h_dentry;
6172 + hdst.hd->hd_dentry = hdst.h_dentry;
6173 + dinfo->di_btop = cpg->bsrc;
6174 + cpg->bsrc = bsrc_orig;
6179 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6182 + aufs_bindex_t bdst;
6183 + struct au_dtime dt;
6184 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6185 + struct au_branch *br;
6186 + struct path h_path;
6188 + dentry = cpg->dentry;
6190 + br = au_sbr(dentry->d_sb, bdst);
6191 + parent = dget_parent(dentry);
6192 + h_parent = au_h_dptr(parent, bdst);
6193 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6194 + err = PTR_ERR(wh_dentry);
6195 + if (IS_ERR(wh_dentry))
6198 + h_path.dentry = h_parent;
6199 + h_path.mnt = au_br_mnt(br);
6200 + au_dtime_store(&dt, parent, &h_path);
6201 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6202 + if (unlikely(err))
6206 + h_path.dentry = wh_dentry;
6207 + if (!d_is_dir(wh_dentry)) {
6208 + /* no delegation since it is just created */
6209 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6210 + /*delegated*/NULL, /*force*/0);
6212 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6213 + if (unlikely(err)) {
6214 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6218 + au_dtime_revert(&dt);
6219 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6228 +struct au_cpup_wh_args {
6230 + struct au_cp_generic *cpg;
6231 + struct file *file;
6234 +static void au_call_cpup_wh(void *args)
6236 + struct au_cpup_wh_args *a = args;
6238 + au_pin_hdir_acquire_nest(a->cpg->pin);
6239 + *a->errp = au_cpup_wh(a->cpg, a->file);
6240 + au_pin_hdir_release(a->cpg->pin);
6243 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6246 + aufs_bindex_t bdst;
6247 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6248 + struct inode *dir, *h_dir, *h_tmpdir;
6249 + struct au_wbr *wbr;
6250 + struct au_pin wh_pin, *pin_orig;
6252 + dentry = cpg->dentry;
6254 + parent = dget_parent(dentry);
6255 + dir = d_inode(parent);
6258 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6261 + if (!h_dir->i_nlink) {
6262 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6263 + h_orph = wbr->wbr_orph;
6265 + h_parent = dget(au_h_dptr(parent, bdst));
6266 + au_set_h_dptr(parent, bdst, dget(h_orph));
6267 + h_tmpdir = d_inode(h_orph);
6268 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6270 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6271 + /* todo: au_h_open_pre()? */
6273 + pin_orig = cpg->pin;
6274 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6275 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6276 + cpg->pin = &wh_pin;
6279 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6280 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6281 + err = au_cpup_wh(cpg, file);
6283 + struct au_cpup_wh_args args = {
6288 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6289 + if (unlikely(wkq_err))
6294 + inode_unlock(h_tmpdir);
6295 + /* todo: au_h_open_post()? */
6296 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6297 + au_set_h_dptr(parent, bdst, h_parent);
6298 + AuDebugOn(!pin_orig);
6299 + cpg->pin = pin_orig;
6307 +/* ---------------------------------------------------------------------- */
6310 + * generic routine for both of copy-up and copy-down.
6312 +/* cf. revalidate function in file.c */
6313 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6314 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6315 + struct au_pin *pin,
6316 + struct dentry *h_parent, void *arg),
6320 + struct au_pin pin;
6321 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6324 + parent = dget_parent(dentry);
6325 + if (IS_ROOT(parent))
6328 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6329 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6331 + /* do not use au_dpage */
6332 + real_parent = parent;
6335 + parent = dget_parent(dentry);
6336 + h_parent = au_h_dptr(parent, bdst);
6338 + goto out; /* success */
6340 + /* find top dir which is necessary to cpup */
6344 + parent = dget_parent(d);
6345 + di_read_lock_parent3(parent, !AuLock_IR);
6346 + h_parent = au_h_dptr(parent, bdst);
6347 + di_read_unlock(parent, !AuLock_IR);
6348 + } while (!h_parent);
6350 + if (d != real_parent)
6351 + di_write_lock_child3(d);
6353 + /* somebody else might create while we were sleeping */
6354 + h_dentry = au_h_dptr(d, bdst);
6355 + if (!h_dentry || d_is_negative(h_dentry)) {
6357 + au_update_dbtop(d);
6359 + au_pin_set_dentry(&pin, d);
6360 + err = au_do_pin(&pin);
6362 + err = cp(d, bdst, &pin, h_parent, arg);
6367 + if (d != real_parent)
6368 + di_write_unlock(d);
6369 + if (unlikely(err))
6378 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6379 + struct au_pin *pin,
6380 + struct dentry *h_parent __maybe_unused,
6381 + void *arg __maybe_unused)
6383 + struct au_cp_generic cpg = {
6389 + .flags = AuCpup_DTIME
6391 + return au_sio_cpup_simple(&cpg);
6394 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6396 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6399 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6402 + struct dentry *parent;
6403 + struct inode *dir;
6405 + parent = dget_parent(dentry);
6406 + dir = d_inode(parent);
6408 + if (au_h_iptr(dir, bdst))
6411 + di_read_unlock(parent, AuLock_IR);
6412 + di_write_lock_parent(parent);
6413 + /* someone else might change our inode while we were sleeping */
6414 + if (!au_h_iptr(dir, bdst))
6415 + err = au_cpup_dirs(dentry, bdst);
6416 + di_downgrade_lock(parent, AuLock_IR);
6422 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6423 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6424 +++ linux/fs/aufs/cpup.h 2019-03-05 12:13:00.135890907 +0100
6426 +/* SPDX-License-Identifier: GPL-2.0 */
6428 + * Copyright (C) 2005-2019 Junjiro R. Okajima
6430 + * This program, aufs is free software; you can redistribute it and/or modify
6431 + * it under the terms of the GNU General Public License as published by
6432 + * the Free Software Foundation; either version 2 of the License, or
6433 + * (at your option) any later version.
6435 + * This program is distributed in the hope that it will be useful,
6436 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6437 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6438 + * GNU General Public License for more details.
6440 + * You should have received a copy of the GNU General Public License
6441 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6445 + * copy-up/down functions
6448 +#ifndef __AUFS_CPUP_H__
6449 +#define __AUFS_CPUP_H__
6453 +#include <linux/path.h>
6459 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6460 +void au_cpup_attr_timesizes(struct inode *inode);
6461 +void au_cpup_attr_nlink(struct inode *inode, int force);
6462 +void au_cpup_attr_changeable(struct inode *inode);
6463 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6464 +void au_cpup_attr_all(struct inode *inode, int force);
6466 +/* ---------------------------------------------------------------------- */
6468 +struct au_cp_generic {
6469 + struct dentry *dentry;
6470 + aufs_bindex_t bdst, bsrc;
6472 + struct au_pin *pin;
6473 + unsigned int flags;
6477 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6478 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6480 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6481 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6483 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6485 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6486 + the branch is marked as RO */
6488 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6489 +#undef AuCpup_HOPEN
6490 +#define AuCpup_HOPEN 0
6493 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6494 +#define au_fset_cpup(flags, name) \
6495 + do { (flags) |= AuCpup_##name; } while (0)
6496 +#define au_fclr_cpup(flags, name) \
6497 + do { (flags) &= ~AuCpup_##name; } while (0)
6499 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6500 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6501 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6502 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6504 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6505 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6506 + struct au_pin *pin,
6507 + struct dentry *h_parent, void *arg),
6509 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6510 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6512 +/* ---------------------------------------------------------------------- */
6514 +/* keep timestamps when copyup */
6516 + struct dentry *dt_dentry;
6517 + struct path dt_h_path;
6518 + struct timespec64 dt_atime, dt_mtime;
6520 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6521 + struct path *h_path);
6522 +void au_dtime_revert(struct au_dtime *dt);
6524 +#endif /* __KERNEL__ */
6525 +#endif /* __AUFS_CPUP_H__ */
6526 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6527 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6528 +++ linux/fs/aufs/dbgaufs.c 2019-03-05 12:13:00.135890907 +0100
6530 +// SPDX-License-Identifier: GPL-2.0
6532 + * Copyright (C) 2005-2019 Junjiro R. Okajima
6534 + * This program, aufs is free software; you can redistribute it and/or modify
6535 + * it under the terms of the GNU General Public License as published by
6536 + * the Free Software Foundation; either version 2 of the License, or
6537 + * (at your option) any later version.
6539 + * This program is distributed in the hope that it will be useful,
6540 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6541 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6542 + * GNU General Public License for more details.
6544 + * You should have received a copy of the GNU General Public License
6545 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6549 + * debugfs interface
6552 +#include <linux/debugfs.h>
6555 +#ifndef CONFIG_SYSFS
6556 +#error DEBUG_FS depends upon SYSFS
6559 +static struct dentry *dbgaufs;
6560 +static const mode_t dbgaufs_mode = 0444;
6562 +/* 20 is max digits length of ulong 64 */
6563 +struct dbgaufs_arg {
6569 + * common function for all XINO files
6571 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6572 + struct file *file)
6576 + p = file->private_data;
6578 + /* this is struct dbgaufs_arg */
6579 + AuDebugOn(!au_kfree_sz_test(p));
6580 + au_kfree_do_rcu(p);
6585 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6590 + struct dbgaufs_arg *p;
6593 + p = kmalloc(sizeof(*p), GFP_NOFS);
6599 + file->private_data = p;
6603 + err = vfsub_getattr(&xf->f_path, &st);
6607 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6608 + cnt, st.blocks, st.blksize,
6609 + (long long)st.size);
6611 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6612 + st.blocks, st.blksize,
6613 + (long long)st.size);
6614 + AuDebugOn(p->n >= sizeof(p->a));
6616 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6624 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6625 + size_t count, loff_t *ppos)
6627 + struct dbgaufs_arg *p;
6629 + p = file->private_data;
6630 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6633 +/* ---------------------------------------------------------------------- */
6635 +struct dbgaufs_plink_arg {
6640 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6641 + struct file *file)
6643 + free_page((unsigned long)file->private_data);
6647 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6649 + int err, i, limit;
6650 + unsigned long n, sum;
6651 + struct dbgaufs_plink_arg *p;
6652 + struct au_sbinfo *sbinfo;
6653 + struct super_block *sb;
6654 + struct hlist_bl_head *hbl;
6657 + p = (void *)get_zeroed_page(GFP_NOFS);
6662 + sbinfo = inode->i_private;
6663 + sb = sbinfo->si_sb;
6664 + si_noflush_read_lock(sb);
6665 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6666 + limit = PAGE_SIZE - sizeof(p->n);
6668 + /* the number of buckets */
6669 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6674 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6676 + n = au_hbl_count(hbl);
6679 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6682 + if (unlikely(limit <= 0))
6685 + p->a[p->n - 1] = '\n';
6687 + /* the sum of plinks */
6688 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6691 + if (unlikely(limit <= 0))
6694 +#define str "1\n0\n0\n"
6695 + p->n = sizeof(str) - 1;
6696 + strcpy(p->a, str);
6699 + si_read_unlock(sb);
6702 + file->private_data = p;
6703 + goto out; /* success */
6706 + free_page((unsigned long)p);
6711 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6712 + size_t count, loff_t *ppos)
6714 + struct dbgaufs_plink_arg *p;
6716 + p = file->private_data;
6717 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6720 +static const struct file_operations dbgaufs_plink_fop = {
6721 + .owner = THIS_MODULE,
6722 + .open = dbgaufs_plink_open,
6723 + .release = dbgaufs_plink_release,
6724 + .read = dbgaufs_plink_read
6727 +/* ---------------------------------------------------------------------- */
6729 +static int dbgaufs_xib_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_xib, file, /*do_fcnt*/0, /*cnt*/0);
6739 + si_read_unlock(sb);
6743 +static const struct file_operations dbgaufs_xib_fop = {
6744 + .owner = THIS_MODULE,
6745 + .open = dbgaufs_xib_open,
6746 + .release = dbgaufs_xi_release,
6747 + .read = dbgaufs_xi_read
6750 +/* ---------------------------------------------------------------------- */
6752 +#define DbgaufsXi_PREFIX "xi"
6754 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6758 + aufs_bindex_t bindex;
6759 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6760 + struct au_sbinfo *sbinfo;
6761 + struct super_block *sb;
6762 + struct au_xino *xi;
6764 + struct qstr *name;
6765 + struct au_branch *br;
6768 + name = &file->f_path.dentry->d_name;
6769 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6770 + || memcmp(name->name, DbgaufsXi_PREFIX,
6771 + sizeof(DbgaufsXi_PREFIX) - 1)))
6774 + AuDebugOn(name->len >= sizeof(a));
6775 + memcpy(a, name->name, name->len);
6776 + a[name->len] = '\0';
6777 + p = strchr(a, '-');
6780 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6781 + if (unlikely(err))
6786 + err = kstrtol(p + 1, 10, &l);
6787 + if (unlikely(err))
6793 + sbinfo = inode->i_private;
6794 + sb = sbinfo->si_sb;
6795 + si_noflush_read_lock(sb);
6796 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6798 + br = au_sbr(sb, bindex);
6800 + if (unlikely(idx >= xi->xi_nfile))
6802 + xf = au_xino_file(xi, idx);
6804 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6805 + au_xino_count(br));
6808 + si_read_unlock(sb);
6814 +static const struct file_operations dbgaufs_xino_fop = {
6815 + .owner = THIS_MODULE,
6816 + .open = dbgaufs_xino_open,
6817 + .release = dbgaufs_xi_release,
6818 + .read = dbgaufs_xi_read
6821 +void dbgaufs_xino_del(struct au_branch *br)
6823 + struct dentry *dbgaufs;
6825 + dbgaufs = br->br_dbgaufs;
6829 + br->br_dbgaufs = NULL;
6830 + /* debugfs acquires the parent i_mutex */
6832 + debugfs_remove(dbgaufs);
6836 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6838 + aufs_bindex_t bbot;
6839 + struct au_branch *br;
6841 + if (!au_sbi(sb)->si_dbgaufs)
6844 + bbot = au_sbbot(sb);
6845 + for (; bindex <= bbot; bindex++) {
6846 + br = au_sbr(sb, bindex);
6847 + dbgaufs_xino_del(br);
6851 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6852 + unsigned int idx, struct dentry *parent,
6853 + struct au_sbinfo *sbinfo)
6855 + struct au_branch *br;
6857 + /* "xi" bindex(5) "-" idx(2) NULL */
6858 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6861 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6863 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6865 + br = au_sbr(sb, bindex);
6866 + if (br->br_dbgaufs) {
6867 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6869 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6870 + /* debugfs acquires the parent i_mutex */
6872 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6876 + pr_warn("failed renaming %pd/%s, ignored.\n",
6881 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6882 + sbinfo, &dbgaufs_xino_fop);
6884 + if (unlikely(!br->br_dbgaufs))
6885 + pr_warn("failed creating %pd/%s, ignored.\n",
6890 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6891 + struct dentry *parent, struct au_sbinfo *sbinfo)
6893 + struct au_branch *br;
6894 + struct au_xino *xi;
6897 + br = au_sbr(sb, bindex);
6899 + for (u = 0; u < xi->xi_nfile; u++)
6900 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6903 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6905 + struct au_sbinfo *sbinfo;
6906 + struct dentry *parent;
6907 + aufs_bindex_t bbot;
6909 + if (!au_opt_test(au_mntflags(sb), XINO))
6912 + sbinfo = au_sbi(sb);
6913 + parent = sbinfo->si_dbgaufs;
6917 + bbot = au_sbbot(sb);
6919 + for (; bindex <= bbot; bindex++)
6920 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6922 + for (; bbot >= bindex; bbot--)
6923 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6926 +/* ---------------------------------------------------------------------- */
6928 +#ifdef CONFIG_AUFS_EXPORT
6929 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6932 + struct au_sbinfo *sbinfo;
6933 + struct super_block *sb;
6935 + sbinfo = inode->i_private;
6936 + sb = sbinfo->si_sb;
6937 + si_noflush_read_lock(sb);
6938 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6939 + si_read_unlock(sb);
6943 +static const struct file_operations dbgaufs_xigen_fop = {
6944 + .owner = THIS_MODULE,
6945 + .open = dbgaufs_xigen_open,
6946 + .release = dbgaufs_xi_release,
6947 + .read = dbgaufs_xi_read
6950 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6955 + * This function is a dynamic '__init' function actually,
6956 + * so the tiny check for si_rwsem is unnecessary.
6958 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6961 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6962 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6963 + &dbgaufs_xigen_fop);
6964 + if (sbinfo->si_dbgaufs_xigen)
6970 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6974 +#endif /* CONFIG_AUFS_EXPORT */
6976 +/* ---------------------------------------------------------------------- */
6978 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6981 + * This function is a dynamic '__fin' function actually,
6982 + * so the tiny check for si_rwsem is unnecessary.
6984 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6986 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6987 + sbinfo->si_dbgaufs = NULL;
6990 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6993 + char name[SysaufsSiNameLen];
6996 + * This function is a dynamic '__init' function actually,
6997 + * so the tiny check for si_rwsem is unnecessary.
6999 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
7003 + AuErr1("/debug/aufs is uninitialized\n");
7008 + sysaufs_name(sbinfo, name);
7009 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
7010 + if (unlikely(!sbinfo->si_dbgaufs))
7013 + /* regardless plink/noplink option */
7014 + sbinfo->si_dbgaufs_plink = debugfs_create_file
7015 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
7016 + &dbgaufs_plink_fop);
7017 + if (unlikely(!sbinfo->si_dbgaufs_plink))
7020 + /* regardless xino/noxino option */
7021 + sbinfo->si_dbgaufs_xib = debugfs_create_file
7022 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
7023 + &dbgaufs_xib_fop);
7024 + if (unlikely(!sbinfo->si_dbgaufs_xib))
7027 + err = dbgaufs_xigen_init(sbinfo);
7029 + goto out; /* success */
7032 + dbgaufs_si_fin(sbinfo);
7034 + if (unlikely(err))
7035 + pr_err("debugfs/aufs failed\n");
7039 +/* ---------------------------------------------------------------------- */
7041 +void dbgaufs_fin(void)
7043 + debugfs_remove(dbgaufs);
7046 +int __init dbgaufs_init(void)
7051 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
7056 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
7057 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
7058 +++ linux/fs/aufs/dbgaufs.h 2019-03-05 12:13:00.135890907 +0100
7060 +/* SPDX-License-Identifier: GPL-2.0 */
7062 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7064 + * This program, aufs is free software; you can redistribute it and/or modify
7065 + * it under the terms of the GNU General Public License as published by
7066 + * the Free Software Foundation; either version 2 of the License, or
7067 + * (at your option) any later version.
7069 + * This program is distributed in the hope that it will be useful,
7070 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7071 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7072 + * GNU General Public License for more details.
7074 + * You should have received a copy of the GNU General Public License
7075 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7079 + * debugfs interface
7082 +#ifndef __DBGAUFS_H__
7083 +#define __DBGAUFS_H__
7087 +struct super_block;
7091 +#ifdef CONFIG_DEBUG_FS
7093 +void dbgaufs_xino_del(struct au_branch *br);
7094 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
7095 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
7096 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
7097 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
7098 +void dbgaufs_fin(void);
7099 +int __init dbgaufs_init(void);
7101 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
7102 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
7103 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
7105 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
7106 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
7107 +AuStubVoid(dbgaufs_fin, void)
7108 +AuStubInt0(__init dbgaufs_init, void)
7109 +#endif /* CONFIG_DEBUG_FS */
7111 +#endif /* __KERNEL__ */
7112 +#endif /* __DBGAUFS_H__ */
7113 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
7114 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
7115 +++ linux/fs/aufs/dcsub.c 2019-03-05 12:13:00.135890907 +0100
7117 +// SPDX-License-Identifier: GPL-2.0
7119 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7121 + * This program, aufs is free software; you can redistribute it and/or modify
7122 + * it under the terms of the GNU General Public License as published by
7123 + * the Free Software Foundation; either version 2 of the License, or
7124 + * (at your option) any later version.
7126 + * This program is distributed in the hope that it will be useful,
7127 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7128 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7129 + * GNU General Public License for more details.
7131 + * You should have received a copy of the GNU General Public License
7132 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7136 + * sub-routines for dentry cache
7141 +static void au_dpage_free(struct au_dpage *dpage)
7144 + struct dentry **p;
7146 + p = dpage->dentries;
7147 + for (i = 0; i < dpage->ndentry; i++)
7149 + free_page((unsigned long)dpage->dentries);
7152 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
7158 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
7159 + if (unlikely(!dpages->dpages))
7162 + p = (void *)__get_free_page(gfp);
7166 + dpages->dpages[0].ndentry = 0;
7167 + dpages->dpages[0].dentries = p;
7168 + dpages->ndpage = 1;
7169 + return 0; /* success */
7172 + au_kfree_try_rcu(dpages->dpages);
7177 +void au_dpages_free(struct au_dcsub_pages *dpages)
7180 + struct au_dpage *p;
7182 + p = dpages->dpages;
7183 + for (i = 0; i < dpages->ndpage; i++)
7184 + au_dpage_free(p++);
7185 + au_kfree_try_rcu(dpages->dpages);
7188 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7189 + struct dentry *dentry, gfp_t gfp)
7192 + struct au_dpage *dpage;
7195 + dpage = dpages->dpages + dpages->ndpage - 1;
7196 + sz = PAGE_SIZE / sizeof(dentry);
7197 + if (unlikely(dpage->ndentry >= sz)) {
7198 + AuLabel(new dpage);
7200 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7201 + p = au_kzrealloc(dpages->dpages, sz,
7202 + sz + sizeof(*dpages->dpages), gfp,
7207 + dpages->dpages = p;
7208 + dpage = dpages->dpages + dpages->ndpage;
7209 + p = (void *)__get_free_page(gfp);
7213 + dpage->ndentry = 0;
7214 + dpage->dentries = p;
7218 + AuDebugOn(au_dcount(dentry) <= 0);
7219 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7220 + return 0; /* success */
7226 +/* todo: BAD approach */
7227 +/* copied from linux/fs/dcache.c */
7235 +extern void d_walk(struct dentry *parent, void *data,
7236 + enum d_walk_ret (*enter)(void *, struct dentry *));
7238 +struct ac_dpages_arg {
7240 + struct au_dcsub_pages *dpages;
7241 + struct super_block *sb;
7242 + au_dpages_test test;
7246 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7248 + enum d_walk_ret ret;
7249 + struct ac_dpages_arg *arg = _arg;
7251 + ret = D_WALK_CONTINUE;
7252 + if (dentry->d_sb == arg->sb
7253 + && !IS_ROOT(dentry)
7254 + && au_dcount(dentry) > 0
7256 + && (!arg->test || arg->test(dentry, arg->arg))) {
7257 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7258 + if (unlikely(arg->err))
7259 + ret = D_WALK_QUIT;
7265 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7266 + au_dpages_test test, void *arg)
7268 + struct ac_dpages_arg args = {
7276 + d_walk(root, &args, au_call_dpages_append);
7281 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7282 + int do_include, au_dpages_test test, void *arg)
7287 + write_seqlock(&rename_lock);
7288 + spin_lock(&dentry->d_lock);
7290 + && au_dcount(dentry) > 0
7291 + && (!test || test(dentry, arg)))
7292 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7293 + spin_unlock(&dentry->d_lock);
7294 + if (unlikely(err))
7298 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7301 + while (!IS_ROOT(dentry)) {
7302 + dentry = dentry->d_parent; /* rename_lock is locked */
7303 + spin_lock(&dentry->d_lock);
7304 + if (au_dcount(dentry) > 0
7305 + && (!test || test(dentry, arg)))
7306 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7307 + spin_unlock(&dentry->d_lock);
7308 + if (unlikely(err))
7313 + write_sequnlock(&rename_lock);
7317 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7319 + return au_di(dentry) && dentry->d_sb == arg;
7322 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7323 + struct dentry *dentry, int do_include)
7325 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7326 + au_dcsub_dpages_aufs, dentry->d_sb);
7329 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7331 + struct path path[2] = {
7340 + return path_is_under(path + 0, path + 1);
7342 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7343 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7344 +++ linux/fs/aufs/dcsub.h 2019-03-05 12:13:00.135890907 +0100
7346 +/* SPDX-License-Identifier: GPL-2.0 */
7348 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7350 + * This program, aufs is free software; you can redistribute it and/or modify
7351 + * it under the terms of the GNU General Public License as published by
7352 + * the Free Software Foundation; either version 2 of the License, or
7353 + * (at your option) any later version.
7355 + * This program is distributed in the hope that it will be useful,
7356 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7357 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7358 + * GNU General Public License for more details.
7360 + * You should have received a copy of the GNU General Public License
7361 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7365 + * sub-routines for dentry cache
7368 +#ifndef __AUFS_DCSUB_H__
7369 +#define __AUFS_DCSUB_H__
7373 +#include <linux/dcache.h>
7374 +#include <linux/fs.h>
7378 + struct dentry **dentries;
7381 +struct au_dcsub_pages {
7383 + struct au_dpage *dpages;
7386 +/* ---------------------------------------------------------------------- */
7389 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7390 +void au_dpages_free(struct au_dcsub_pages *dpages);
7391 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7392 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7393 + au_dpages_test test, void *arg);
7394 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7395 + int do_include, au_dpages_test test, void *arg);
7396 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7397 + struct dentry *dentry, int do_include);
7398 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7400 +/* ---------------------------------------------------------------------- */
7403 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7404 + * include/linux/dcache.h. Try them (in the future).
7407 +static inline int au_d_hashed_positive(struct dentry *d)
7410 + struct inode *inode = d_inode(d);
7413 + if (unlikely(d_unhashed(d)
7414 + || d_is_negative(d)
7415 + || !inode->i_nlink))
7420 +static inline int au_d_linkable(struct dentry *d)
7423 + struct inode *inode = d_inode(d);
7425 + err = au_d_hashed_positive(d);
7427 + && d_is_positive(d)
7428 + && (inode->i_state & I_LINKABLE))
7433 +static inline int au_d_alive(struct dentry *d)
7436 + struct inode *inode;
7440 + err = au_d_hashed_positive(d);
7442 + inode = d_inode(d);
7443 + if (unlikely(d_unlinked(d)
7444 + || d_is_negative(d)
7445 + || !inode->i_nlink))
7451 +static inline int au_alive_dir(struct dentry *d)
7455 + err = au_d_alive(d);
7456 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7461 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7463 + return a->len == b->len
7464 + && !memcmp(a->name, b->name, a->len);
7469 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7471 + * the type of d_lockref.count became int, but the inlined function d_count()
7472 + * still returns unsigned int.
7473 + * I don't know why. Maybe it is for every d_count() users?
7474 + * Anyway au_dcount() lives on.
7476 +static inline int au_dcount(struct dentry *d)
7478 + return (int)d_count(d);
7481 +#endif /* __KERNEL__ */
7482 +#endif /* __AUFS_DCSUB_H__ */
7483 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7484 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7485 +++ linux/fs/aufs/debug.c 2019-05-06 09:03:04.816810402 +0200
7487 +// SPDX-License-Identifier: GPL-2.0
7489 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7491 + * This program, aufs is free software; you can redistribute it and/or modify
7492 + * it under the terms of the GNU General Public License as published by
7493 + * the Free Software Foundation; either version 2 of the License, or
7494 + * (at your option) any later version.
7496 + * This program is distributed in the hope that it will be useful,
7497 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7498 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7499 + * GNU General Public License for more details.
7501 + * You should have received a copy of the GNU General Public License
7502 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7506 + * debug print functions
7509 +#include <linux/iversion.h>
7512 +/* Returns 0, or -errno. arg is in kp->arg. */
7513 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7517 + err = kstrtoint(val, 0, &n);
7527 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7528 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7533 + return sprintf(buffer, "%d", atomic_read(a));
7536 +static struct kernel_param_ops param_ops_atomic_t = {
7537 + .set = param_atomic_t_set,
7538 + .get = param_atomic_t_get
7539 + /* void (*free)(void *arg) */
7542 +atomic_t aufs_debug = ATOMIC_INIT(0);
7543 +MODULE_PARM_DESC(debug, "debug print");
7544 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7546 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7547 +char *au_plevel = KERN_DEBUG;
7548 +#define dpri(fmt, ...) do { \
7550 + && strcmp(au_plevel, KERN_DEBUG)) \
7551 + || au_debug_test()) \
7552 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7555 +/* ---------------------------------------------------------------------- */
7557 +void au_dpri_whlist(struct au_nhash *whlist)
7559 + unsigned long ul, n;
7560 + struct hlist_head *head;
7561 + struct au_vdir_wh *pos;
7563 + n = whlist->nh_num;
7564 + head = whlist->nh_head;
7565 + for (ul = 0; ul < n; ul++) {
7566 + hlist_for_each_entry(pos, head, wh_hash)
7567 + dpri("b%d, %.*s, %d\n",
7569 + pos->wh_str.len, pos->wh_str.name,
7575 +void au_dpri_vdir(struct au_vdir *vdir)
7578 + union au_vdir_deblk_p p;
7581 + if (!vdir || IS_ERR(vdir)) {
7582 + dpri("err %ld\n", PTR_ERR(vdir));
7586 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7587 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7588 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7589 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7590 + p.deblk = vdir->vd_deblk[ul];
7592 + dpri("[%lu]: %p\n", ul, o);
7596 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7597 + struct dentry *wh)
7602 + if (!inode || IS_ERR(inode)) {
7603 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7607 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7608 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7609 + && sizeof(inode->i_blocks) != sizeof(u64));
7611 + n = (void *)wh->d_name.name;
7612 + l = wh->d_name.len;
7615 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7616 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7618 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7619 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7620 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7621 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7622 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7623 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7624 + inode->i_generation,
7625 + l ? ", wh " : "", l, n);
7629 +void au_dpri_inode(struct inode *inode)
7631 + struct au_iinfo *iinfo;
7632 + struct au_hinode *hi;
7633 + aufs_bindex_t bindex;
7636 + err = do_pri_inode(-1, inode, -1, NULL);
7637 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7640 + iinfo = au_ii(inode);
7641 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7642 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7643 + if (iinfo->ii_btop < 0)
7646 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7647 + hi = au_hinode(iinfo, bindex);
7649 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7653 +void au_dpri_dalias(struct inode *inode)
7657 + spin_lock(&inode->i_lock);
7658 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7659 + au_dpri_dentry(d);
7660 + spin_unlock(&inode->i_lock);
7663 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7665 + struct dentry *wh = NULL;
7667 + struct inode *inode;
7668 + struct au_iinfo *iinfo;
7669 + struct au_hinode *hi;
7671 + if (!dentry || IS_ERR(dentry)) {
7672 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7675 + /* do not call dget_parent() here */
7676 + /* note: access d_xxx without d_lock */
7677 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7678 + bindex, dentry, dentry,
7679 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7680 + au_dcount(dentry), dentry->d_flags,
7681 + d_unhashed(dentry) ? "un" : "");
7684 + if (d_is_positive(dentry))
7685 + inode = d_inode(dentry);
7687 + && au_test_aufs(dentry->d_sb)
7689 + && !au_is_bad_inode(inode)) {
7690 + iinfo = au_ii(inode);
7691 + hi = au_hinode(iinfo, bindex);
7693 + wh = hi->hi_whdentry;
7695 + do_pri_inode(bindex, inode, hn, wh);
7699 +void au_dpri_dentry(struct dentry *dentry)
7701 + struct au_dinfo *dinfo;
7702 + aufs_bindex_t bindex;
7705 + err = do_pri_dentry(-1, dentry);
7706 + if (err || !au_test_aufs(dentry->d_sb))
7709 + dinfo = au_di(dentry);
7712 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7713 + dinfo->di_btop, dinfo->di_bbot,
7714 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7715 + dinfo->di_tmpfile);
7716 + if (dinfo->di_btop < 0)
7718 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7719 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7722 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7726 + if (!file || IS_ERR(file)) {
7727 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7732 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7733 + && au_test_aufs(file->f_path.dentry->d_sb)
7735 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7736 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7737 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7738 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7739 + file->f_version, file->f_pos, a);
7740 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7741 + do_pri_dentry(bindex, file->f_path.dentry);
7745 +void au_dpri_file(struct file *file)
7747 + struct au_finfo *finfo;
7748 + struct au_fidir *fidir;
7749 + struct au_hfile *hfile;
7750 + aufs_bindex_t bindex;
7753 + err = do_pri_file(-1, file);
7755 + || IS_ERR_OR_NULL(file->f_path.dentry)
7756 + || !au_test_aufs(file->f_path.dentry->d_sb))
7759 + finfo = au_fi(file);
7762 + if (finfo->fi_btop < 0)
7764 + fidir = finfo->fi_hdir;
7766 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7768 + for (bindex = finfo->fi_btop;
7769 + bindex >= 0 && bindex <= fidir->fd_bbot;
7771 + hfile = fidir->fd_hfile + bindex;
7772 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7776 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7778 + struct vfsmount *mnt;
7779 + struct super_block *sb;
7781 + if (!br || IS_ERR(br))
7783 + mnt = au_br_mnt(br);
7784 + if (!mnt || IS_ERR(mnt))
7787 + if (!sb || IS_ERR(sb))
7790 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7791 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7793 + bindex, br->br_perm, br->br_id, br->br_wbr,
7794 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7795 + sb->s_flags, sb->s_count,
7796 + atomic_read(&sb->s_active),
7797 + !!au_xino_file(br->br_xino, /*idx*/-1));
7801 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7805 +void au_dpri_sb(struct super_block *sb)
7807 + struct au_sbinfo *sbinfo;
7808 + aufs_bindex_t bindex;
7810 + /* to reduce stack size */
7812 + struct vfsmount mnt;
7813 + struct au_branch fake;
7816 + /* this function can be called from magic sysrq */
7817 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7818 + if (unlikely(!a)) {
7819 + dpri("no memory\n");
7823 + a->mnt.mnt_sb = sb;
7824 + a->fake.br_path.mnt = &a->mnt;
7825 + err = do_pri_br(-1, &a->fake);
7827 + dpri("dev 0x%x\n", sb->s_dev);
7828 + if (err || !au_test_aufs(sb))
7831 + sbinfo = au_sbi(sb);
7834 + dpri("nw %d, gen %u, kobj %d\n",
7835 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7836 + kref_read(&sbinfo->si_kobj.kref));
7837 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7838 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7841 +/* ---------------------------------------------------------------------- */
7843 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7845 + struct inode *h_inode, *inode = d_inode(dentry);
7846 + struct dentry *h_dentry;
7847 + aufs_bindex_t bindex, bbot, bi;
7849 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7852 + bbot = au_dbbot(dentry);
7853 + bi = au_ibbot(inode);
7856 + bindex = au_dbtop(dentry);
7857 + bi = au_ibtop(inode);
7861 + for (; bindex <= bbot; bindex++) {
7862 + h_dentry = au_h_dptr(dentry, bindex);
7865 + h_inode = au_h_iptr(inode, bindex);
7866 + if (unlikely(h_inode != d_inode(h_dentry))) {
7868 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7869 + AuDbgDentry(dentry);
7870 + AuDbgInode(inode);
7877 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7880 + struct au_dcsub_pages dpages;
7881 + struct au_dpage *dpage;
7882 + struct dentry **dentries;
7884 + err = au_dpages_init(&dpages, GFP_NOFS);
7886 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7888 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7889 + dpage = dpages.dpages + i;
7890 + dentries = dpage->dentries;
7891 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7892 + AuDebugOn(au_digen_test(dentries[j], sigen));
7894 + au_dpages_free(&dpages);
7897 +void au_dbg_verify_kthread(void)
7899 + if (au_wkq_test()) {
7902 + * It may be recursive, but udba=notify between two aufs mounts,
7903 + * where a single ro branch is shared, is not a problem.
7909 +/* ---------------------------------------------------------------------- */
7911 +int __init au_debug_init(void)
7913 + aufs_bindex_t bindex;
7914 + struct au_vdir_destr destr;
7917 + AuDebugOn(bindex >= 0);
7920 + AuDebugOn(destr.len < NAME_MAX);
7922 +#ifdef CONFIG_4KSTACKS
7923 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7928 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7929 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7930 +++ linux/fs/aufs/debug.h 2019-03-05 12:13:00.135890907 +0100
7932 +/* SPDX-License-Identifier: GPL-2.0 */
7934 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7936 + * This program, aufs is free software; you can redistribute it and/or modify
7937 + * it under the terms of the GNU General Public License as published by
7938 + * the Free Software Foundation; either version 2 of the License, or
7939 + * (at your option) any later version.
7941 + * This program is distributed in the hope that it will be useful,
7942 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7943 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7944 + * GNU General Public License for more details.
7946 + * You should have received a copy of the GNU General Public License
7947 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7951 + * debug print functions
7954 +#ifndef __AUFS_DEBUG_H__
7955 +#define __AUFS_DEBUG_H__
7959 +#include <linux/atomic.h>
7960 +#include <linux/module.h>
7961 +#include <linux/kallsyms.h>
7962 +#include <linux/sysrq.h>
7964 +#ifdef CONFIG_AUFS_DEBUG
7965 +#define AuDebugOn(a) BUG_ON(a)
7967 +/* module parameter */
7968 +extern atomic_t aufs_debug;
7969 +static inline void au_debug_on(void)
7971 + atomic_inc(&aufs_debug);
7973 +static inline void au_debug_off(void)
7975 + atomic_dec_if_positive(&aufs_debug);
7978 +static inline int au_debug_test(void)
7980 + return atomic_read(&aufs_debug) > 0;
7983 +#define AuDebugOn(a) do {} while (0)
7984 +AuStubVoid(au_debug_on, void)
7985 +AuStubVoid(au_debug_off, void)
7986 +AuStubInt0(au_debug_test, void)
7987 +#endif /* CONFIG_AUFS_DEBUG */
7989 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7991 +/* ---------------------------------------------------------------------- */
7995 +#define AuDbg(fmt, ...) do { \
7996 + if (au_debug_test()) \
7997 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7999 +#define AuLabel(l) AuDbg(#l "\n")
8000 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
8001 +#define AuWarn1(fmt, ...) do { \
8002 + static unsigned char _c; \
8004 + pr_warn(fmt, ##__VA_ARGS__); \
8007 +#define AuErr1(fmt, ...) do { \
8008 + static unsigned char _c; \
8010 + pr_err(fmt, ##__VA_ARGS__); \
8013 +#define AuIOErr1(fmt, ...) do { \
8014 + static unsigned char _c; \
8016 + AuIOErr(fmt, ##__VA_ARGS__); \
8019 +#define AuUnsupportMsg "This operation is not supported." \
8020 + " Please report this application to aufs-users ML."
8021 +#define AuUnsupport(fmt, ...) do { \
8022 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
8026 +#define AuTraceErr(e) do { \
8027 + if (unlikely((e) < 0)) \
8028 + AuDbg("err %d\n", (int)(e)); \
8031 +#define AuTraceErrPtr(p) do { \
8033 + AuDbg("err %ld\n", PTR_ERR(p)); \
8036 +/* dirty macros for debug print, use with "%.*s" and caution */
8037 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
8039 +/* ---------------------------------------------------------------------- */
8042 +#ifdef CONFIG_AUFS_DEBUG
8043 +extern struct mutex au_dbg_mtx;
8044 +extern char *au_plevel;
8046 +void au_dpri_whlist(struct au_nhash *whlist);
8048 +void au_dpri_vdir(struct au_vdir *vdir);
8050 +void au_dpri_inode(struct inode *inode);
8051 +void au_dpri_dalias(struct inode *inode);
8052 +void au_dpri_dentry(struct dentry *dentry);
8054 +void au_dpri_file(struct file *filp);
8055 +struct super_block;
8056 +void au_dpri_sb(struct super_block *sb);
8058 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
8059 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
8060 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
8061 +void au_dbg_verify_kthread(void);
8063 +int __init au_debug_init(void);
8065 +#define AuDbgWhlist(w) do { \
8066 + mutex_lock(&au_dbg_mtx); \
8068 + au_dpri_whlist(w); \
8069 + mutex_unlock(&au_dbg_mtx); \
8072 +#define AuDbgVdir(v) do { \
8073 + mutex_lock(&au_dbg_mtx); \
8075 + au_dpri_vdir(v); \
8076 + mutex_unlock(&au_dbg_mtx); \
8079 +#define AuDbgInode(i) do { \
8080 + mutex_lock(&au_dbg_mtx); \
8082 + au_dpri_inode(i); \
8083 + mutex_unlock(&au_dbg_mtx); \
8086 +#define AuDbgDAlias(i) do { \
8087 + mutex_lock(&au_dbg_mtx); \
8089 + au_dpri_dalias(i); \
8090 + mutex_unlock(&au_dbg_mtx); \
8093 +#define AuDbgDentry(d) do { \
8094 + mutex_lock(&au_dbg_mtx); \
8096 + au_dpri_dentry(d); \
8097 + mutex_unlock(&au_dbg_mtx); \
8100 +#define AuDbgFile(f) do { \
8101 + mutex_lock(&au_dbg_mtx); \
8103 + au_dpri_file(f); \
8104 + mutex_unlock(&au_dbg_mtx); \
8107 +#define AuDbgSb(sb) do { \
8108 + mutex_lock(&au_dbg_mtx); \
8109 + AuDbg(#sb "\n"); \
8111 + mutex_unlock(&au_dbg_mtx); \
8114 +#define AuDbgSym(addr) do { \
8115 + char sym[KSYM_SYMBOL_LEN]; \
8116 + sprint_symbol(sym, (unsigned long)addr); \
8117 + AuDbg("%s\n", sym); \
8120 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
8121 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
8122 +AuStubVoid(au_dbg_verify_kthread, void)
8123 +AuStubInt0(__init au_debug_init, void)
8125 +#define AuDbgWhlist(w) do {} while (0)
8126 +#define AuDbgVdir(v) do {} while (0)
8127 +#define AuDbgInode(i) do {} while (0)
8128 +#define AuDbgDAlias(i) do {} while (0)
8129 +#define AuDbgDentry(d) do {} while (0)
8130 +#define AuDbgFile(f) do {} while (0)
8131 +#define AuDbgSb(sb) do {} while (0)
8132 +#define AuDbgSym(addr) do {} while (0)
8133 +#endif /* CONFIG_AUFS_DEBUG */
8135 +/* ---------------------------------------------------------------------- */
8137 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
8138 +int __init au_sysrq_init(void);
8139 +void au_sysrq_fin(void);
8141 +#ifdef CONFIG_HW_CONSOLE
8142 +#define au_dbg_blocked() do { \
8144 + handle_sysrq('w'); \
8147 +AuStubVoid(au_dbg_blocked, void)
8151 +AuStubInt0(__init au_sysrq_init, void)
8152 +AuStubVoid(au_sysrq_fin, void)
8153 +AuStubVoid(au_dbg_blocked, void)
8154 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
8156 +#endif /* __KERNEL__ */
8157 +#endif /* __AUFS_DEBUG_H__ */
8158 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
8159 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
8160 +++ linux/fs/aufs/dentry.c 2019-05-06 09:03:04.816810402 +0200
8162 +// SPDX-License-Identifier: GPL-2.0
8164 + * Copyright (C) 2005-2019 Junjiro R. Okajima
8166 + * This program, aufs is free software; you can redistribute it and/or modify
8167 + * it under the terms of the GNU General Public License as published by
8168 + * the Free Software Foundation; either version 2 of the License, or
8169 + * (at your option) any later version.
8171 + * This program is distributed in the hope that it will be useful,
8172 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8173 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8174 + * GNU General Public License for more details.
8176 + * You should have received a copy of the GNU General Public License
8177 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8181 + * lookup and dentry operations
8184 +#include <linux/iversion.h>
8185 +#include <linux/namei.h>
8189 + * returns positive/negative dentry, NULL or an error.
8190 + * NULL means whiteout-ed or not-found.
8192 +static struct dentry*
8193 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8194 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8196 + struct dentry *h_dentry;
8197 + struct inode *h_inode;
8198 + struct au_branch *br;
8199 + int wh_found, opq;
8200 + unsigned char wh_able;
8201 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8202 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8206 + br = au_sbr(dentry->d_sb, bindex);
8207 + wh_able = !!au_br_whable(br->br_perm);
8209 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8210 + h_dentry = ERR_PTR(wh_found);
8213 + if (unlikely(wh_found < 0))
8216 + /* We found a whiteout */
8217 + /* au_set_dbbot(dentry, bindex); */
8218 + au_set_dbwh(dentry, bindex);
8220 + return NULL; /* success */
8224 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8226 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8227 + if (IS_ERR(h_dentry)) {
8228 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8234 + h_inode = d_inode(h_dentry);
8235 + if (d_is_negative(h_dentry)) {
8238 + } else if (wh_found
8239 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8241 + else if (au_ftest_lkup(args->flags, DIRREN)
8243 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8244 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8245 + (unsigned long long)h_inode->i_ino);
8249 + if (au_dbbot(dentry) <= bindex)
8250 + au_set_dbbot(dentry, bindex);
8251 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8252 + au_set_dbtop(dentry, bindex);
8253 + au_set_h_dptr(dentry, bindex, h_dentry);
8255 + if (!d_is_dir(h_dentry)
8257 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8258 + goto out; /* success */
8260 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8261 + opq = au_diropq_test(h_dentry);
8262 + inode_unlock_shared(h_inode);
8264 + au_set_dbdiropq(dentry, bindex);
8265 + else if (unlikely(opq < 0)) {
8266 + au_set_h_dptr(dentry, bindex, NULL);
8267 + h_dentry = ERR_PTR(opq);
8278 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8280 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8281 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8287 + * returns the number of lower positive dentries,
8288 + * otherwise an error.
8289 + * can be called at unlinking with @type is zero.
8291 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8292 + unsigned int flags)
8294 + int npositive, err;
8295 + aufs_bindex_t bindex, btail, bdiropq;
8296 + unsigned char isdir, dirperm1, dirren;
8297 + struct au_do_lookup_args args = {
8299 + .name = &dentry->d_name
8301 + struct dentry *parent;
8302 + struct super_block *sb;
8304 + sb = dentry->d_sb;
8305 + err = au_test_shwh(sb, args.name);
8306 + if (unlikely(err))
8309 + err = au_wh_name_alloc(&args.whname, args.name);
8310 + if (unlikely(err))
8313 + isdir = !!d_is_dir(dentry);
8314 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8315 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8317 + au_fset_lkup(args.flags, DIRREN);
8320 + parent = dget_parent(dentry);
8321 + btail = au_dbtaildir(parent);
8322 + for (bindex = btop; bindex <= btail; bindex++) {
8323 + struct dentry *h_parent, *h_dentry;
8324 + struct inode *h_inode, *h_dir;
8325 + struct au_branch *br;
8327 + h_dentry = au_h_dptr(dentry, bindex);
8329 + if (d_is_positive(h_dentry))
8333 + h_parent = au_h_dptr(parent, bindex);
8334 + if (!h_parent || !d_is_dir(h_parent))
8338 + /* if the inum matches, then use the prepared name */
8339 + err = au_dr_lkup_name(&args, bindex);
8340 + if (unlikely(err))
8344 + h_dir = d_inode(h_parent);
8345 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8346 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8347 + inode_unlock_shared(h_dir);
8348 + err = PTR_ERR(h_dentry);
8349 + if (IS_ERR(h_dentry))
8352 + au_fclr_lkup(args.flags, ALLOW_NEG);
8354 + au_fset_lkup(args.flags, IGNORE_PERM);
8356 + if (au_dbwh(dentry) == bindex)
8360 + if (d_is_negative(h_dentry))
8362 + h_inode = d_inode(h_dentry);
8365 + args.type = h_inode->i_mode & S_IFMT;
8366 + if (args.type != S_IFDIR)
8369 + /* the type of lower may be different */
8370 + bdiropq = au_dbdiropq(dentry);
8371 + if (bdiropq >= 0 && bdiropq <= bindex)
8374 + br = au_sbr(sb, bindex);
8376 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8377 + /*add_ent*/NULL)) {
8378 + /* prepare next name to lookup */
8379 + err = au_dr_lkup(&args, dentry, bindex);
8380 + if (unlikely(err))
8386 + AuLabel(positive);
8387 + au_update_dbtop(dentry);
8390 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8391 + && au_dbtop(dentry) < 0)) {
8393 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8399 + au_kfree_try_rcu(args.whname.name);
8401 + au_dr_lkup_fin(&args);
8406 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8408 + struct dentry *dentry;
8411 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8412 + dentry = vfsub_lkup_one(name, parent);
8414 + struct vfsub_lkup_one_args args = {
8420 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8421 + if (unlikely(wkq_err))
8422 + dentry = ERR_PTR(wkq_err);
8429 + * lookup @dentry on @bindex which should be negative.
8431 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8434 + struct dentry *parent, *h_parent, *h_dentry;
8435 + struct au_branch *br;
8437 + parent = dget_parent(dentry);
8438 + h_parent = au_h_dptr(parent, bindex);
8439 + br = au_sbr(dentry->d_sb, bindex);
8441 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8443 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8444 + err = PTR_ERR(h_dentry);
8445 + if (IS_ERR(h_dentry))
8447 + if (unlikely(d_is_positive(h_dentry))) {
8449 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8455 + if (bindex < au_dbtop(dentry))
8456 + au_set_dbtop(dentry, bindex);
8457 + if (au_dbbot(dentry) < bindex)
8458 + au_set_dbbot(dentry, bindex);
8459 + au_set_h_dptr(dentry, bindex, h_dentry);
8466 +/* ---------------------------------------------------------------------- */
8468 +/* subset of struct inode */
8470 + unsigned long i_ino;
8471 + /* unsigned int i_nlink; */
8477 + blkcnt_t i_blocks;
8482 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8484 + ia->i_ino = h_inode->i_ino;
8485 + /* ia->i_nlink = h_inode->i_nlink; */
8486 + ia->i_uid = h_inode->i_uid;
8487 + ia->i_gid = h_inode->i_gid;
8488 + ia->i_version = inode_query_iversion(h_inode);
8490 + ia->i_size = h_inode->i_size;
8491 + ia->i_blocks = h_inode->i_blocks;
8493 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8496 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8498 + return ia->i_ino != h_inode->i_ino
8499 + /* || ia->i_nlink != h_inode->i_nlink */
8500 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8501 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8502 + || !inode_eq_iversion(h_inode, ia->i_version)
8504 + || ia->i_size != h_inode->i_size
8505 + || ia->i_blocks != h_inode->i_blocks
8507 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8510 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8511 + struct au_branch *br)
8514 + struct au_iattr ia;
8515 + struct inode *h_inode;
8516 + struct dentry *h_d;
8517 + struct super_block *h_sb;
8520 + memset(&ia, -1, sizeof(ia));
8521 + h_sb = h_dentry->d_sb;
8523 + if (d_is_positive(h_dentry)) {
8524 + h_inode = d_inode(h_dentry);
8525 + au_iattr_save(&ia, h_inode);
8526 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8527 + /* nfs d_revalidate may return 0 for negative dentry */
8528 + /* fuse d_revalidate always return 0 for negative dentry */
8531 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8532 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8533 + err = PTR_ERR(h_d);
8538 + if (unlikely(h_d != h_dentry
8539 + || d_inode(h_d) != h_inode
8540 + || (h_inode && au_iattr_test(&ia, h_inode))))
8541 + err = au_busy_or_stale();
8549 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8550 + struct dentry *h_parent, struct au_branch *br)
8555 + if (udba == AuOpt_UDBA_REVAL
8556 + && !au_test_fs_remote(h_dentry->d_sb)) {
8558 + err = (d_inode(h_dentry->d_parent) != h_dir);
8559 + } else if (udba != AuOpt_UDBA_NONE)
8560 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8565 +/* ---------------------------------------------------------------------- */
8567 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8570 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8571 + struct au_hdentry tmp, *p, *q;
8572 + struct au_dinfo *dinfo;
8573 + struct super_block *sb;
8575 + DiMustWriteLock(dentry);
8577 + sb = dentry->d_sb;
8578 + dinfo = au_di(dentry);
8579 + bbot = dinfo->di_bbot;
8580 + bwh = dinfo->di_bwh;
8581 + bdiropq = dinfo->di_bdiropq;
8582 + bindex = dinfo->di_btop;
8583 + p = au_hdentry(dinfo, bindex);
8584 + for (; bindex <= bbot; bindex++, p++) {
8585 + if (!p->hd_dentry)
8588 + new_bindex = au_br_index(sb, p->hd_id);
8589 + if (new_bindex == bindex)
8592 + if (dinfo->di_bwh == bindex)
8594 + if (dinfo->di_bdiropq == bindex)
8595 + bdiropq = new_bindex;
8596 + if (new_bindex < 0) {
8598 + p->hd_dentry = NULL;
8602 + /* swap two lower dentries, and loop again */
8603 + q = au_hdentry(dinfo, new_bindex);
8607 + if (tmp.hd_dentry) {
8613 + dinfo->di_bwh = -1;
8614 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8615 + dinfo->di_bwh = bwh;
8617 + dinfo->di_bdiropq = -1;
8619 + && bdiropq <= au_sbbot(sb)
8620 + && au_sbr_whable(sb, bdiropq))
8621 + dinfo->di_bdiropq = bdiropq;
8624 + dinfo->di_btop = -1;
8625 + dinfo->di_bbot = -1;
8626 + bbot = au_dbbot(parent);
8628 + p = au_hdentry(dinfo, bindex);
8629 + for (; bindex <= bbot; bindex++, p++)
8630 + if (p->hd_dentry) {
8631 + dinfo->di_btop = bindex;
8635 + if (dinfo->di_btop >= 0) {
8637 + p = au_hdentry(dinfo, bindex);
8638 + for (; bindex >= 0; bindex--, p--)
8639 + if (p->hd_dentry) {
8640 + dinfo->di_bbot = bindex;
8649 +static void au_do_hide(struct dentry *dentry)
8651 + struct inode *inode;
8653 + if (d_really_is_positive(dentry)) {
8654 + inode = d_inode(dentry);
8655 + if (!d_is_dir(dentry)) {
8656 + if (inode->i_nlink && !d_unhashed(dentry))
8657 + drop_nlink(inode);
8659 + clear_nlink(inode);
8660 + /* stop next lookup */
8661 + inode->i_flags |= S_DEAD;
8663 + smp_mb(); /* necessary? */
8668 +static int au_hide_children(struct dentry *parent)
8670 + int err, i, j, ndentry;
8671 + struct au_dcsub_pages dpages;
8672 + struct au_dpage *dpage;
8673 + struct dentry *dentry;
8675 + err = au_dpages_init(&dpages, GFP_NOFS);
8676 + if (unlikely(err))
8678 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8679 + if (unlikely(err))
8682 + /* in reverse order */
8683 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8684 + dpage = dpages.dpages + i;
8685 + ndentry = dpage->ndentry;
8686 + for (j = ndentry - 1; j >= 0; j--) {
8687 + dentry = dpage->dentries[j];
8688 + if (dentry != parent)
8689 + au_do_hide(dentry);
8694 + au_dpages_free(&dpages);
8699 +static void au_hide(struct dentry *dentry)
8703 + AuDbgDentry(dentry);
8704 + if (d_is_dir(dentry)) {
8705 + /* shrink_dcache_parent(dentry); */
8706 + err = au_hide_children(dentry);
8707 + if (unlikely(err))
8708 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8711 + au_do_hide(dentry);
8715 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8717 + * a dirty branch is added
8718 + * - on the top of layers
8719 + * - in the middle of layers
8720 + * - to the bottom of layers
8722 + * on the added branch there exists
8725 + * - a same named entry
8727 + * * negative --> positive
8728 + * * positive --> positive
8729 + * - type is unchanged
8730 + * - type is changed
8732 + * * negative --> negative
8733 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8736 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8737 + struct au_dinfo *tmp)
8740 + aufs_bindex_t bindex, bbot;
8742 + struct dentry *dentry;
8743 + struct inode *inode;
8745 + } orig_h, tmp_h = {
8748 + struct au_hdentry *hd;
8749 + struct inode *inode, *h_inode;
8750 + struct dentry *h_dentry;
8753 + AuDebugOn(dinfo->di_btop < 0);
8755 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8756 + orig_h.inode = NULL;
8757 + if (d_is_positive(orig_h.dentry)) {
8758 + orig_h.inode = d_inode(orig_h.dentry);
8759 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8761 + if (tmp->di_btop >= 0) {
8762 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8763 + if (d_is_positive(tmp_h.dentry)) {
8764 + tmp_h.inode = d_inode(tmp_h.dentry);
8765 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8770 + if (d_really_is_positive(dentry))
8771 + inode = d_inode(dentry);
8772 + if (!orig_h.inode) {
8773 + AuDbg("negative originally\n");
8779 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8780 + AuDebugOn(dinfo->di_bdiropq != -1);
8782 + if (!tmp_h.inode) {
8783 + AuDbg("negative --> negative\n");
8784 + /* should have only one negative lower */
8785 + if (tmp->di_btop >= 0
8786 + && tmp->di_btop < dinfo->di_btop) {
8787 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8788 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8789 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8790 + au_di_cp(dinfo, tmp);
8791 + hd = au_hdentry(tmp, tmp->di_btop);
8792 + au_set_h_dptr(dentry, tmp->di_btop,
8793 + dget(hd->hd_dentry));
8795 + au_dbg_verify_dinode(dentry);
8797 + AuDbg("negative --> positive\n");
8799 + * similar to the behaviour of creating with bypassing
8801 + * unhash it in order to force an error in the
8802 + * succeeding create operation.
8803 + * we should not set S_DEAD here.
8806 + /* au_di_swap(tmp, dinfo); */
8807 + au_dbg_verify_dinode(dentry);
8810 + AuDbg("positive originally\n");
8811 + /* inode may be NULL */
8812 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8813 + if (!tmp_h.inode) {
8814 + AuDbg("positive --> negative\n");
8815 + /* or bypassing aufs */
8817 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8818 + dinfo->di_bwh = tmp->di_bwh;
8820 + err = au_refresh_hinode_self(inode);
8821 + au_dbg_verify_dinode(dentry);
8822 + } else if (orig_h.mode == tmp_h.mode) {
8823 + AuDbg("positive --> positive, same type\n");
8824 + if (!S_ISDIR(orig_h.mode)
8825 + && dinfo->di_btop > tmp->di_btop) {
8827 + * similar to the behaviour of removing and
8832 + err = au_refresh_hinode_self(inode);
8833 + au_dbg_verify_dinode(dentry);
8835 + /* fill empty slots */
8836 + if (dinfo->di_btop > tmp->di_btop)
8837 + dinfo->di_btop = tmp->di_btop;
8838 + if (dinfo->di_bbot < tmp->di_bbot)
8839 + dinfo->di_bbot = tmp->di_bbot;
8840 + dinfo->di_bwh = tmp->di_bwh;
8841 + dinfo->di_bdiropq = tmp->di_bdiropq;
8842 + bbot = dinfo->di_bbot;
8843 + bindex = tmp->di_btop;
8844 + hd = au_hdentry(tmp, bindex);
8845 + for (; bindex <= bbot; bindex++, hd++) {
8846 + if (au_h_dptr(dentry, bindex))
8848 + h_dentry = hd->hd_dentry;
8851 + AuDebugOn(d_is_negative(h_dentry));
8852 + h_inode = d_inode(h_dentry);
8853 + AuDebugOn(orig_h.mode
8854 + != (h_inode->i_mode
8856 + au_set_h_dptr(dentry, bindex,
8860 + err = au_refresh_hinode(inode, dentry);
8861 + au_dbg_verify_dinode(dentry);
8864 + AuDbg("positive --> positive, different type\n");
8865 + /* similar to the behaviour of removing and creating */
8868 + err = au_refresh_hinode_self(inode);
8869 + au_dbg_verify_dinode(dentry);
8877 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8879 + const struct dentry_operations *dop
8880 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8881 + static const unsigned int mask
8882 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8884 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8886 + if (dentry->d_op == dop)
8889 + AuDbg("%pd\n", dentry);
8890 + spin_lock(&dentry->d_lock);
8891 + if (dop == &aufs_dop)
8892 + dentry->d_flags |= mask;
8894 + dentry->d_flags &= ~mask;
8895 + dentry->d_op = dop;
8896 + spin_unlock(&dentry->d_lock);
8899 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8901 + int err, ebrange, nbr;
8902 + unsigned int sigen;
8903 + struct au_dinfo *dinfo, *tmp;
8904 + struct super_block *sb;
8905 + struct inode *inode;
8907 + DiMustWriteLock(dentry);
8908 + AuDebugOn(IS_ROOT(dentry));
8909 + AuDebugOn(d_really_is_negative(parent));
8911 + sb = dentry->d_sb;
8912 + sigen = au_sigen(sb);
8913 + err = au_digen_test(parent, sigen);
8914 + if (unlikely(err))
8917 + nbr = au_sbbot(sb) + 1;
8918 + dinfo = au_di(dentry);
8919 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8920 + if (unlikely(err))
8922 + ebrange = au_dbrange_test(dentry);
8924 + ebrange = au_do_refresh_hdentry(dentry, parent);
8926 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8927 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8928 + if (d_really_is_positive(dentry)) {
8929 + inode = d_inode(dentry);
8930 + err = au_refresh_hinode_self(inode);
8932 + au_dbg_verify_dinode(dentry);
8934 + goto out_dgen; /* success */
8938 + /* temporary dinfo */
8939 + AuDbgDentry(dentry);
8941 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8942 + if (unlikely(!tmp))
8944 + au_di_swap(tmp, dinfo);
8945 + /* returns the number of positive dentries */
8947 + * if current working dir is removed, it returns an error.
8948 + * but the dentry is legal.
8950 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8951 + AuDbgDentry(dentry);
8952 + au_di_swap(tmp, dinfo);
8953 + if (err == -ENOENT)
8956 + /* compare/refresh by dinfo */
8957 + AuDbgDentry(dentry);
8958 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8959 + au_dbg_verify_dinode(dentry);
8962 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8963 + au_rw_write_unlock(&tmp->di_rwsem);
8965 + if (unlikely(err))
8969 + au_update_digen(dentry);
8971 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8972 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8973 + AuDbgDentry(dentry);
8979 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8980 + struct dentry *dentry, aufs_bindex_t bindex)
8985 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8988 + AuDbg("b%d\n", bindex);
8990 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8991 + * due to whiteout and branch permission.
8993 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8994 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8995 + /* it may return tri-state */
8996 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8998 + if (unlikely(valid < 0))
9008 +/* todo: remove this */
9009 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
9010 + unsigned int flags, int do_udba, int dirren)
9013 + umode_t mode, h_mode;
9014 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
9015 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
9016 + struct inode *h_inode, *h_cached_inode;
9017 + struct dentry *h_dentry;
9018 + struct qstr *name, *h_name;
9025 + unhashed = !!d_unhashed(dentry);
9026 + is_root = !!IS_ROOT(dentry);
9027 + name = &dentry->d_name;
9028 + tmpfile = au_di(dentry)->di_tmpfile;
9031 + * Theoretically, REVAL test should be unnecessary in case of
9033 + * But {fs,i}notify doesn't fire some necessary events,
9034 + * IN_ATTRIB for atime/nlink/pageio
9035 + * Let's do REVAL test too.
9037 + if (do_udba && inode) {
9038 + mode = (inode->i_mode & S_IFMT);
9039 + plus = (inode->i_nlink > 0);
9040 + ibs = au_ibtop(inode);
9041 + ibe = au_ibbot(inode);
9044 + btop = au_dbtop(dentry);
9046 + if (inode && S_ISDIR(inode->i_mode))
9047 + btail = au_dbtaildir(dentry);
9048 + for (bindex = btop; bindex <= btail; bindex++) {
9049 + h_dentry = au_h_dptr(dentry, bindex);
9053 + AuDbg("b%d, %pd\n", bindex, h_dentry);
9054 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
9055 + spin_lock(&h_dentry->d_lock);
9056 + h_name = &h_dentry->d_name;
9057 + if (unlikely(do_udba
9060 + && (unhashed != !!d_unhashed(h_dentry)
9061 + || (!tmpfile && !dirren
9062 + && !au_qstreq(name, h_name))
9065 + && !(flags & LOOKUP_OPEN)
9066 + && (h_dentry->d_flags
9067 + & DCACHE_NFSFS_RENAMED)))
9071 + h_unhashed = d_unhashed(h_dentry);
9072 + spin_unlock(&h_dentry->d_lock);
9073 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
9074 + unhashed, h_unhashed, dentry, h_dentry);
9077 + spin_unlock(&h_dentry->d_lock);
9079 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
9080 + if (unlikely(err))
9081 + /* do not goto err, to keep the errno */
9084 + /* todo: plink too? */
9089 + if (unlikely(!!inode != d_is_positive(h_dentry)))
9093 + if (d_is_positive(h_dentry))
9094 + h_inode = d_inode(h_dentry);
9097 + h_cached_inode = h_inode;
9099 + h_mode = (h_inode->i_mode & S_IFMT);
9100 + h_plus = (h_inode->i_nlink > 0);
9102 + if (inode && ibs <= bindex && bindex <= ibe)
9103 + h_cached_inode = au_h_iptr(inode, bindex);
9106 + if (unlikely(plus != h_plus && !tmpfile))
9109 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
9111 + && !IS_ROOT(h_dentry)
9112 + && unhashed != d_unhashed(h_dentry)))
9115 + if (unlikely(mode != h_mode
9116 + || h_cached_inode != h_inode))
9129 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
9130 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
9133 + struct dentry *parent;
9135 + if (!au_digen_test(dentry, sigen))
9138 + parent = dget_parent(dentry);
9139 + di_read_lock_parent(parent, AuLock_IR);
9140 + AuDebugOn(au_digen_test(parent, sigen));
9141 + au_dbg_verify_gen(parent, sigen);
9142 + err = au_refresh_dentry(dentry, parent);
9143 + di_read_unlock(parent, AuLock_IR);
9149 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
9152 + struct dentry *d, *parent;
9154 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
9155 + return simple_reval_dpath(dentry, sigen);
9157 + /* slow loop, keep it simple and stupid */
9158 + /* cf: au_cpup_dirs() */
9161 + while (au_digen_test(dentry, sigen)) {
9165 + parent = dget_parent(d);
9166 + if (!au_digen_test(parent, sigen))
9172 + di_write_lock_child2(d);
9174 + /* someone might update our dentry while we were sleeping */
9175 + if (au_digen_test(d, sigen)) {
9177 + * todo: consolidate with simple_reval_dpath(),
9178 + * do_refresh() and au_reval_for_attr().
9180 + di_read_lock_parent(parent, AuLock_IR);
9181 + err = au_refresh_dentry(d, parent);
9182 + di_read_unlock(parent, AuLock_IR);
9186 + di_write_unlock(d);
9188 + if (unlikely(err))
9196 + * if valid returns 1, otherwise 0.
9198 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9201 + unsigned int sigen;
9202 + unsigned char do_udba, dirren;
9203 + struct super_block *sb;
9204 + struct inode *inode;
9206 + /* todo: support rcu-walk? */
9207 + if (flags & LOOKUP_RCU)
9211 + if (unlikely(!au_di(dentry)))
9215 + sb = dentry->d_sb;
9218 + * i_mutex of parent dir may be held,
9219 + * but we should not return 'invalid' due to busy.
9221 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9222 + if (unlikely(err)) {
9228 + if (d_really_is_positive(dentry))
9229 + inode = d_inode(dentry);
9230 + if (unlikely(inode && au_is_bad_inode(inode))) {
9235 + if (unlikely(au_dbrange_test(dentry))) {
9241 + sigen = au_sigen(sb);
9242 + if (au_digen_test(dentry, sigen)) {
9243 + AuDebugOn(IS_ROOT(dentry));
9244 + err = au_reval_dpath(dentry, sigen);
9245 + if (unlikely(err)) {
9250 + di_downgrade_lock(dentry, AuLock_IR);
9253 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9255 + && !(inode->i_state && I_LINKABLE)
9256 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9261 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9262 + if (do_udba && inode) {
9263 + aufs_bindex_t btop = au_ibtop(inode);
9264 + struct inode *h_inode;
9267 + h_inode = au_h_iptr(inode, btop);
9268 + if (h_inode && au_test_higen(inode, h_inode)) {
9275 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9276 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9277 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9279 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9285 + di_downgrade_lock(dentry, AuLock_IR);
9287 + aufs_read_unlock(dentry, AuLock_IR);
9292 + AuDbg("%pd invalid, %d\n", dentry, valid);
9298 +static void aufs_d_release(struct dentry *dentry)
9300 + if (au_di(dentry)) {
9301 + au_di_fin(dentry);
9302 + au_hn_di_reinit(dentry);
9306 +const struct dentry_operations aufs_dop = {
9307 + .d_revalidate = aufs_d_revalidate,
9308 + .d_weak_revalidate = aufs_d_revalidate,
9309 + .d_release = aufs_d_release
9312 +/* aufs_dop without d_revalidate */
9313 +const struct dentry_operations aufs_dop_noreval = {
9314 + .d_release = aufs_d_release
9316 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9317 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9318 +++ linux/fs/aufs/dentry.h 2019-03-05 12:13:00.135890907 +0100
9320 +/* SPDX-License-Identifier: GPL-2.0 */
9322 + * Copyright (C) 2005-2019 Junjiro R. Okajima
9324 + * This program, aufs is free software; you can redistribute it and/or modify
9325 + * it under the terms of the GNU General Public License as published by
9326 + * the Free Software Foundation; either version 2 of the License, or
9327 + * (at your option) any later version.
9329 + * This program is distributed in the hope that it will be useful,
9330 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9331 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9332 + * GNU General Public License for more details.
9334 + * You should have received a copy of the GNU General Public License
9335 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9339 + * lookup and dentry operations
9342 +#ifndef __AUFS_DENTRY_H__
9343 +#define __AUFS_DENTRY_H__
9347 +#include <linux/dcache.h>
9348 +#include "dirren.h"
9351 +struct au_hdentry {
9352 + struct dentry *hd_dentry;
9353 + aufs_bindex_t hd_id;
9357 + atomic_t di_generation;
9359 + struct au_rwsem di_rwsem;
9360 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9361 + unsigned char di_tmpfile; /* to allow the different name */
9362 + struct au_hdentry *di_hdentry;
9363 + struct rcu_head rcu;
9364 +} ____cacheline_aligned_in_smp;
9366 +/* ---------------------------------------------------------------------- */
9368 +/* flags for au_lkup_dentry() */
9369 +#define AuLkup_ALLOW_NEG 1
9370 +#define AuLkup_IGNORE_PERM (1 << 1)
9371 +#define AuLkup_DIRREN (1 << 2)
9372 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9373 +#define au_fset_lkup(flags, name) \
9374 + do { (flags) |= AuLkup_##name; } while (0)
9375 +#define au_fclr_lkup(flags, name) \
9376 + do { (flags) &= ~AuLkup_##name; } while (0)
9378 +#ifndef CONFIG_AUFS_DIRREN
9379 +#undef AuLkup_DIRREN
9380 +#define AuLkup_DIRREN 0
9383 +struct au_do_lookup_args {
9384 + unsigned int flags;
9386 + struct qstr whname, *name;
9387 + struct au_dr_lookup dirren;
9390 +/* ---------------------------------------------------------------------- */
9393 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9395 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9396 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9397 + struct dentry *h_parent, struct au_branch *br);
9399 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9400 + unsigned int flags);
9401 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9402 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9403 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9404 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9407 +void au_di_init_once(void *_di);
9408 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9409 +void au_di_free(struct au_dinfo *dinfo);
9410 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9411 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9412 +int au_di_init(struct dentry *dentry);
9413 +void au_di_fin(struct dentry *dentry);
9414 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9416 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9417 +void di_read_unlock(struct dentry *d, int flags);
9418 +void di_downgrade_lock(struct dentry *d, int flags);
9419 +void di_write_lock(struct dentry *d, unsigned int lsc);
9420 +void di_write_unlock(struct dentry *d);
9421 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9422 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9423 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9425 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9426 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9427 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9428 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9430 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9431 + struct dentry *h_dentry);
9432 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9433 +int au_dbrange_test(struct dentry *dentry);
9434 +void au_update_digen(struct dentry *dentry);
9435 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9436 +void au_update_dbtop(struct dentry *dentry);
9437 +void au_update_dbbot(struct dentry *dentry);
9438 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9440 +/* ---------------------------------------------------------------------- */
9442 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9444 + return dentry->d_fsdata;
9447 +/* ---------------------------------------------------------------------- */
9449 +/* lock subclass for dinfo */
9451 + AuLsc_DI_CHILD, /* child first */
9452 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9453 + AuLsc_DI_CHILD3, /* copyup dirs */
9457 + AuLsc_DI_TMP /* temp for replacing dinfo */
9461 + * di_read_lock_child, di_write_lock_child,
9462 + * di_read_lock_child2, di_write_lock_child2,
9463 + * di_read_lock_child3, di_write_lock_child3,
9464 + * di_read_lock_parent, di_write_lock_parent,
9465 + * di_read_lock_parent2, di_write_lock_parent2,
9466 + * di_read_lock_parent3, di_write_lock_parent3,
9468 +#define AuReadLockFunc(name, lsc) \
9469 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9470 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9472 +#define AuWriteLockFunc(name, lsc) \
9473 +static inline void di_write_lock_##name(struct dentry *d) \
9474 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9476 +#define AuRWLockFuncs(name, lsc) \
9477 + AuReadLockFunc(name, lsc) \
9478 + AuWriteLockFunc(name, lsc)
9480 +AuRWLockFuncs(child, CHILD);
9481 +AuRWLockFuncs(child2, CHILD2);
9482 +AuRWLockFuncs(child3, CHILD3);
9483 +AuRWLockFuncs(parent, PARENT);
9484 +AuRWLockFuncs(parent2, PARENT2);
9485 +AuRWLockFuncs(parent3, PARENT3);
9487 +#undef AuReadLockFunc
9488 +#undef AuWriteLockFunc
9489 +#undef AuRWLockFuncs
9491 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9492 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9493 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9495 +/* ---------------------------------------------------------------------- */
9497 +/* todo: memory barrier? */
9498 +static inline unsigned int au_digen(struct dentry *d)
9500 + return atomic_read(&au_di(d)->di_generation);
9503 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9505 + hdentry->hd_dentry = NULL;
9508 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9509 + aufs_bindex_t bindex)
9511 + return di->di_hdentry + bindex;
9514 +static inline void au_hdput(struct au_hdentry *hd)
9517 + dput(hd->hd_dentry);
9520 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9522 + DiMustAnyLock(dentry);
9523 + return au_di(dentry)->di_btop;
9526 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9528 + DiMustAnyLock(dentry);
9529 + return au_di(dentry)->di_bbot;
9532 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9534 + DiMustAnyLock(dentry);
9535 + return au_di(dentry)->di_bwh;
9538 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9540 + DiMustAnyLock(dentry);
9541 + return au_di(dentry)->di_bdiropq;
9544 +/* todo: hard/soft set? */
9545 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9547 + DiMustWriteLock(dentry);
9548 + au_di(dentry)->di_btop = bindex;
9551 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9553 + DiMustWriteLock(dentry);
9554 + au_di(dentry)->di_bbot = bindex;
9557 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9559 + DiMustWriteLock(dentry);
9560 + /* dbwh can be outside of btop - bbot range */
9561 + au_di(dentry)->di_bwh = bindex;
9564 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9566 + DiMustWriteLock(dentry);
9567 + au_di(dentry)->di_bdiropq = bindex;
9570 +/* ---------------------------------------------------------------------- */
9572 +#ifdef CONFIG_AUFS_HNOTIFY
9573 +static inline void au_digen_dec(struct dentry *d)
9575 + atomic_dec(&au_di(d)->di_generation);
9578 +static inline void au_hn_di_reinit(struct dentry *dentry)
9580 + dentry->d_fsdata = NULL;
9583 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9584 +#endif /* CONFIG_AUFS_HNOTIFY */
9586 +#endif /* __KERNEL__ */
9587 +#endif /* __AUFS_DENTRY_H__ */
9588 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9589 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9590 +++ linux/fs/aufs/dinfo.c 2019-03-05 12:13:00.135890907 +0100
9592 +// SPDX-License-Identifier: GPL-2.0
9594 + * Copyright (C) 2005-2019 Junjiro R. Okajima
9596 + * This program, aufs is free software; you can redistribute it and/or modify
9597 + * it under the terms of the GNU General Public License as published by
9598 + * the Free Software Foundation; either version 2 of the License, or
9599 + * (at your option) any later version.
9601 + * This program is distributed in the hope that it will be useful,
9602 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9603 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9604 + * GNU General Public License for more details.
9606 + * You should have received a copy of the GNU General Public License
9607 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9611 + * dentry private data
9616 +void au_di_init_once(void *_dinfo)
9618 + struct au_dinfo *dinfo = _dinfo;
9620 + au_rw_init(&dinfo->di_rwsem);
9623 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9625 + struct au_dinfo *dinfo;
9628 + dinfo = au_cache_alloc_dinfo();
9629 + if (unlikely(!dinfo))
9632 + nbr = au_sbbot(sb) + 1;
9635 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9636 + if (dinfo->di_hdentry) {
9637 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9638 + dinfo->di_btop = -1;
9639 + dinfo->di_bbot = -1;
9640 + dinfo->di_bwh = -1;
9641 + dinfo->di_bdiropq = -1;
9642 + dinfo->di_tmpfile = 0;
9643 + for (i = 0; i < nbr; i++)
9644 + dinfo->di_hdentry[i].hd_id = -1;
9648 + au_cache_free_dinfo(dinfo);
9655 +void au_di_free(struct au_dinfo *dinfo)
9657 + struct au_hdentry *p;
9658 + aufs_bindex_t bbot, bindex;
9660 + /* dentry may not be revalidated */
9661 + bindex = dinfo->di_btop;
9662 + if (bindex >= 0) {
9663 + bbot = dinfo->di_bbot;
9664 + p = au_hdentry(dinfo, bindex);
9665 + while (bindex++ <= bbot)
9668 + au_kfree_try_rcu(dinfo->di_hdentry);
9669 + au_cache_free_dinfo(dinfo);
9672 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9674 + struct au_hdentry *p;
9677 + AuRwMustWriteLock(&a->di_rwsem);
9678 + AuRwMustWriteLock(&b->di_rwsem);
9680 +#define DiSwap(v, name) \
9682 + v = a->di_##name; \
9683 + a->di_##name = b->di_##name; \
9684 + b->di_##name = v; \
9687 + DiSwap(p, hdentry);
9691 + DiSwap(bi, bdiropq);
9697 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9699 + AuRwMustWriteLock(&dst->di_rwsem);
9700 + AuRwMustWriteLock(&src->di_rwsem);
9702 + dst->di_btop = src->di_btop;
9703 + dst->di_bbot = src->di_bbot;
9704 + dst->di_bwh = src->di_bwh;
9705 + dst->di_bdiropq = src->di_bdiropq;
9709 +int au_di_init(struct dentry *dentry)
9712 + struct super_block *sb;
9713 + struct au_dinfo *dinfo;
9716 + sb = dentry->d_sb;
9717 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9719 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9720 + /* smp_mb(); */ /* atomic_set */
9721 + dentry->d_fsdata = dinfo;
9728 +void au_di_fin(struct dentry *dentry)
9730 + struct au_dinfo *dinfo;
9732 + dinfo = au_di(dentry);
9733 + AuRwDestroy(&dinfo->di_rwsem);
9734 + au_di_free(dinfo);
9737 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9740 + struct au_hdentry *hdp;
9742 + AuRwMustWriteLock(&dinfo->di_rwsem);
9745 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9747 + sz = sizeof(*hdp);
9748 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9751 + dinfo->di_hdentry = hdp;
9758 +/* ---------------------------------------------------------------------- */
9760 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9763 + case AuLsc_DI_CHILD:
9764 + ii_write_lock_child(inode);
9766 + case AuLsc_DI_CHILD2:
9767 + ii_write_lock_child2(inode);
9769 + case AuLsc_DI_CHILD3:
9770 + ii_write_lock_child3(inode);
9772 + case AuLsc_DI_PARENT:
9773 + ii_write_lock_parent(inode);
9775 + case AuLsc_DI_PARENT2:
9776 + ii_write_lock_parent2(inode);
9778 + case AuLsc_DI_PARENT3:
9779 + ii_write_lock_parent3(inode);
9786 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9789 + case AuLsc_DI_CHILD:
9790 + ii_read_lock_child(inode);
9792 + case AuLsc_DI_CHILD2:
9793 + ii_read_lock_child2(inode);
9795 + case AuLsc_DI_CHILD3:
9796 + ii_read_lock_child3(inode);
9798 + case AuLsc_DI_PARENT:
9799 + ii_read_lock_parent(inode);
9801 + case AuLsc_DI_PARENT2:
9802 + ii_read_lock_parent2(inode);
9804 + case AuLsc_DI_PARENT3:
9805 + ii_read_lock_parent3(inode);
9812 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9814 + struct inode *inode;
9816 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9817 + if (d_really_is_positive(d)) {
9818 + inode = d_inode(d);
9819 + if (au_ftest_lock(flags, IW))
9820 + do_ii_write_lock(inode, lsc);
9821 + else if (au_ftest_lock(flags, IR))
9822 + do_ii_read_lock(inode, lsc);
9826 +void di_read_unlock(struct dentry *d, int flags)
9828 + struct inode *inode;
9830 + if (d_really_is_positive(d)) {
9831 + inode = d_inode(d);
9832 + if (au_ftest_lock(flags, IW)) {
9833 + au_dbg_verify_dinode(d);
9834 + ii_write_unlock(inode);
9835 + } else if (au_ftest_lock(flags, IR)) {
9836 + au_dbg_verify_dinode(d);
9837 + ii_read_unlock(inode);
9840 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9843 +void di_downgrade_lock(struct dentry *d, int flags)
9845 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9846 + ii_downgrade_lock(d_inode(d));
9847 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9850 +void di_write_lock(struct dentry *d, unsigned int lsc)
9852 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9853 + if (d_really_is_positive(d))
9854 + do_ii_write_lock(d_inode(d), lsc);
9857 +void di_write_unlock(struct dentry *d)
9859 + au_dbg_verify_dinode(d);
9860 + if (d_really_is_positive(d))
9861 + ii_write_unlock(d_inode(d));
9862 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9865 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9867 + AuDebugOn(d1 == d2
9868 + || d_inode(d1) == d_inode(d2)
9869 + || d1->d_sb != d2->d_sb);
9871 + if ((isdir && au_test_subdir(d1, d2))
9873 + di_write_lock_child(d1);
9874 + di_write_lock_child2(d2);
9876 + di_write_lock_child(d2);
9877 + di_write_lock_child2(d1);
9881 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9883 + AuDebugOn(d1 == d2
9884 + || d_inode(d1) == d_inode(d2)
9885 + || d1->d_sb != d2->d_sb);
9887 + if ((isdir && au_test_subdir(d1, d2))
9889 + di_write_lock_parent(d1);
9890 + di_write_lock_parent2(d2);
9892 + di_write_lock_parent(d2);
9893 + di_write_lock_parent2(d1);
9897 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9899 + di_write_unlock(d1);
9900 + if (d_inode(d1) == d_inode(d2))
9901 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9903 + di_write_unlock(d2);
9906 +/* ---------------------------------------------------------------------- */
9908 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9912 + DiMustAnyLock(dentry);
9914 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9916 + AuDebugOn(bindex < 0);
9917 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9918 + AuDebugOn(d && au_dcount(d) <= 0);
9923 + * extended version of au_h_dptr().
9924 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9927 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9929 + struct dentry *h_dentry;
9930 + struct inode *inode, *h_inode;
9932 + AuDebugOn(d_really_is_negative(dentry));
9935 + if (au_dbtop(dentry) <= bindex
9936 + && bindex <= au_dbbot(dentry))
9937 + h_dentry = au_h_dptr(dentry, bindex);
9938 + if (h_dentry && !au_d_linkable(h_dentry)) {
9940 + goto out; /* success */
9943 + inode = d_inode(dentry);
9944 + AuDebugOn(bindex < au_ibtop(inode));
9945 + AuDebugOn(au_ibbot(inode) < bindex);
9946 + h_inode = au_h_iptr(inode, bindex);
9947 + h_dentry = d_find_alias(h_inode);
9949 + if (!IS_ERR(h_dentry)) {
9950 + if (!au_d_linkable(h_dentry))
9951 + goto out; /* success */
9957 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9958 + h_dentry = au_plink_lkup(inode, bindex);
9959 + AuDebugOn(!h_dentry);
9960 + if (!IS_ERR(h_dentry)) {
9961 + if (!au_d_hashed_positive(h_dentry))
9962 + goto out; /* success */
9969 + AuDbgDentry(h_dentry);
9973 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9975 + aufs_bindex_t bbot, bwh;
9977 + bbot = au_dbbot(dentry);
9979 + bwh = au_dbwh(dentry);
9982 + if (0 < bwh && bwh < bbot)
9988 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9990 + aufs_bindex_t bbot, bopq;
9992 + bbot = au_dbtail(dentry);
9994 + bopq = au_dbdiropq(dentry);
9995 + if (0 <= bopq && bopq < bbot)
10001 +/* ---------------------------------------------------------------------- */
10003 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
10004 + struct dentry *h_dentry)
10006 + struct au_dinfo *dinfo;
10007 + struct au_hdentry *hd;
10008 + struct au_branch *br;
10010 + DiMustWriteLock(dentry);
10012 + dinfo = au_di(dentry);
10013 + hd = au_hdentry(dinfo, bindex);
10015 + hd->hd_dentry = h_dentry;
10017 + br = au_sbr(dentry->d_sb, bindex);
10018 + hd->hd_id = br->br_id;
10022 +int au_dbrange_test(struct dentry *dentry)
10025 + aufs_bindex_t btop, bbot;
10028 + btop = au_dbtop(dentry);
10029 + bbot = au_dbbot(dentry);
10031 + AuDebugOn(bbot < 0 && btop > bbot);
10034 + AuDebugOn(bbot >= 0);
10040 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
10045 + if (unlikely(au_digen(dentry) != sigen
10046 + || au_iigen_test(d_inode(dentry), sigen)))
10052 +void au_update_digen(struct dentry *dentry)
10054 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
10055 + /* smp_mb(); */ /* atomic_set */
10058 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
10060 + struct au_dinfo *dinfo;
10061 + struct dentry *h_d;
10062 + struct au_hdentry *hdp;
10063 + aufs_bindex_t bindex, bbot;
10065 + DiMustWriteLock(dentry);
10067 + dinfo = au_di(dentry);
10068 + if (!dinfo || dinfo->di_btop < 0)
10071 + if (do_put_zero) {
10072 + bbot = dinfo->di_bbot;
10073 + bindex = dinfo->di_btop;
10074 + hdp = au_hdentry(dinfo, bindex);
10075 + for (; bindex <= bbot; bindex++, hdp++) {
10076 + h_d = hdp->hd_dentry;
10077 + if (h_d && d_is_negative(h_d))
10078 + au_set_h_dptr(dentry, bindex, NULL);
10082 + dinfo->di_btop = 0;
10083 + hdp = au_hdentry(dinfo, dinfo->di_btop);
10084 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
10085 + if (hdp->hd_dentry)
10087 + if (dinfo->di_btop > dinfo->di_bbot) {
10088 + dinfo->di_btop = -1;
10089 + dinfo->di_bbot = -1;
10093 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
10094 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
10095 + if (hdp->hd_dentry)
10097 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
10100 +void au_update_dbtop(struct dentry *dentry)
10102 + aufs_bindex_t bindex, bbot;
10103 + struct dentry *h_dentry;
10105 + bbot = au_dbbot(dentry);
10106 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
10107 + h_dentry = au_h_dptr(dentry, bindex);
10110 + if (d_is_positive(h_dentry)) {
10111 + au_set_dbtop(dentry, bindex);
10114 + au_set_h_dptr(dentry, bindex, NULL);
10118 +void au_update_dbbot(struct dentry *dentry)
10120 + aufs_bindex_t bindex, btop;
10121 + struct dentry *h_dentry;
10123 + btop = au_dbtop(dentry);
10124 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
10125 + h_dentry = au_h_dptr(dentry, bindex);
10128 + if (d_is_positive(h_dentry)) {
10129 + au_set_dbbot(dentry, bindex);
10132 + au_set_h_dptr(dentry, bindex, NULL);
10136 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
10138 + aufs_bindex_t bindex, bbot;
10140 + bbot = au_dbbot(dentry);
10141 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
10142 + if (au_h_dptr(dentry, bindex) == h_dentry)
10146 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
10147 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
10148 +++ linux/fs/aufs/dir.c 2019-05-06 09:03:04.816810402 +0200
10150 +// SPDX-License-Identifier: GPL-2.0
10152 + * Copyright (C) 2005-2019 Junjiro R. Okajima
10154 + * This program, aufs is free software; you can redistribute it and/or modify
10155 + * it under the terms of the GNU General Public License as published by
10156 + * the Free Software Foundation; either version 2 of the License, or
10157 + * (at your option) any later version.
10159 + * This program is distributed in the hope that it will be useful,
10160 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10161 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10162 + * GNU General Public License for more details.
10164 + * You should have received a copy of the GNU General Public License
10165 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10169 + * directory operations
10172 +#include <linux/fs_stack.h>
10173 +#include <linux/iversion.h>
10176 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10178 + unsigned int nlink;
10180 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10182 + nlink = dir->i_nlink;
10183 + nlink += h_dir->i_nlink - 2;
10184 + if (h_dir->i_nlink < 2)
10186 + smp_mb(); /* for i_nlink */
10187 + /* 0 can happen in revaliding */
10188 + set_nlink(dir, nlink);
10191 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10193 + unsigned int nlink;
10195 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10197 + nlink = dir->i_nlink;
10198 + nlink -= h_dir->i_nlink - 2;
10199 + if (h_dir->i_nlink < 2)
10201 + smp_mb(); /* for i_nlink */
10202 + /* nlink == 0 means the branch-fs is broken */
10203 + set_nlink(dir, nlink);
10206 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10209 + aufs_bindex_t bindex, bbot;
10210 + struct file *h_file;
10211 + struct dentry *h_dentry;
10215 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10217 + bbot = au_fbbot_dir(file);
10218 + for (bindex = au_fbtop(file);
10219 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10221 + h_file = au_hf_dir(file, bindex);
10222 + if (h_file && file_inode(h_file))
10223 + sz += vfsub_f_size_read(h_file);
10226 + AuDebugOn(!dentry);
10227 + AuDebugOn(!d_is_dir(dentry));
10229 + bbot = au_dbtaildir(dentry);
10230 + for (bindex = au_dbtop(dentry);
10231 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10233 + h_dentry = au_h_dptr(dentry, bindex);
10234 + if (h_dentry && d_is_positive(h_dentry))
10235 + sz += i_size_read(d_inode(h_dentry));
10238 + if (sz < KMALLOC_MAX_SIZE)
10239 + sz = roundup_pow_of_two(sz);
10240 + if (sz > KMALLOC_MAX_SIZE)
10241 + sz = KMALLOC_MAX_SIZE;
10242 + else if (sz < NAME_MAX) {
10243 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10244 + sz = AUFS_RDBLK_DEF;
10249 +struct au_dir_ts_arg {
10250 + struct dentry *dentry;
10251 + aufs_bindex_t brid;
10254 +static void au_do_dir_ts(void *arg)
10256 + struct au_dir_ts_arg *a = arg;
10257 + struct au_dtime dt;
10258 + struct path h_path;
10259 + struct inode *dir, *h_dir;
10260 + struct super_block *sb;
10261 + struct au_branch *br;
10262 + struct au_hinode *hdir;
10264 + aufs_bindex_t btop, bindex;
10266 + sb = a->dentry->d_sb;
10267 + if (d_really_is_negative(a->dentry))
10269 + /* no dir->i_mutex lock */
10270 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10272 + dir = d_inode(a->dentry);
10273 + btop = au_ibtop(dir);
10274 + bindex = au_br_index(sb, a->brid);
10275 + if (bindex < btop)
10278 + br = au_sbr(sb, bindex);
10279 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10280 + if (!h_path.dentry)
10282 + h_path.mnt = au_br_mnt(br);
10283 + au_dtime_store(&dt, a->dentry, &h_path);
10285 + br = au_sbr(sb, btop);
10286 + if (!au_br_writable(br->br_perm))
10288 + h_path.dentry = au_h_dptr(a->dentry, btop);
10289 + h_path.mnt = au_br_mnt(br);
10290 + err = vfsub_mnt_want_write(h_path.mnt);
10293 + hdir = au_hi(dir, btop);
10294 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10295 + h_dir = au_h_iptr(dir, btop);
10296 + if (h_dir->i_nlink
10297 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10298 + dt.dt_h_path = h_path;
10299 + au_dtime_revert(&dt);
10301 + au_hn_inode_unlock(hdir);
10302 + vfsub_mnt_drop_write(h_path.mnt);
10303 + au_cpup_attr_timesizes(dir);
10306 + aufs_read_unlock(a->dentry, AuLock_DW);
10309 + au_nwt_done(&au_sbi(sb)->si_nowait);
10310 + au_kfree_try_rcu(arg);
10313 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10315 + int perm, wkq_err;
10316 + aufs_bindex_t btop;
10317 + struct au_dir_ts_arg *arg;
10318 + struct dentry *dentry;
10319 + struct super_block *sb;
10323 + dentry = d_find_any_alias(dir);
10324 + AuDebugOn(!dentry);
10325 + sb = dentry->d_sb;
10326 + btop = au_ibtop(dir);
10327 + if (btop == bindex) {
10328 + au_cpup_attr_timesizes(dir);
10332 + perm = au_sbr_perm(sb, btop);
10333 + if (!au_br_writable(perm))
10336 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10340 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10341 + arg->brid = au_sbr_id(sb, bindex);
10342 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10343 + if (unlikely(wkq_err)) {
10344 + pr_err("wkq %d\n", wkq_err);
10346 + au_kfree_try_rcu(arg);
10353 +/* ---------------------------------------------------------------------- */
10355 +static int reopen_dir(struct file *file)
10358 + unsigned int flags;
10359 + aufs_bindex_t bindex, btail, btop;
10360 + struct dentry *dentry, *h_dentry;
10361 + struct file *h_file;
10363 + /* open all lower dirs */
10364 + dentry = file->f_path.dentry;
10365 + btop = au_dbtop(dentry);
10366 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10367 + au_set_h_fptr(file, bindex, NULL);
10368 + au_set_fbtop(file, btop);
10370 + btail = au_dbtaildir(dentry);
10371 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10372 + au_set_h_fptr(file, bindex, NULL);
10373 + au_set_fbbot_dir(file, btail);
10375 + flags = vfsub_file_flags(file);
10376 + for (bindex = btop; bindex <= btail; bindex++) {
10377 + h_dentry = au_h_dptr(dentry, bindex);
10380 + h_file = au_hf_dir(file, bindex);
10384 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10385 + err = PTR_ERR(h_file);
10386 + if (IS_ERR(h_file))
10387 + goto out; /* close all? */
10388 + au_set_h_fptr(file, bindex, h_file);
10390 + au_update_figen(file);
10391 + /* todo: necessary? */
10392 + /* file->f_ra = h_file->f_ra; */
10399 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10402 + aufs_bindex_t bindex, btail;
10403 + struct dentry *dentry, *h_dentry;
10404 + struct vfsmount *mnt;
10406 + FiMustWriteLock(file);
10407 + AuDebugOn(h_file);
10410 + mnt = file->f_path.mnt;
10411 + dentry = file->f_path.dentry;
10412 + file->f_version = inode_query_iversion(d_inode(dentry));
10413 + bindex = au_dbtop(dentry);
10414 + au_set_fbtop(file, bindex);
10415 + btail = au_dbtaildir(dentry);
10416 + au_set_fbbot_dir(file, btail);
10417 + for (; !err && bindex <= btail; bindex++) {
10418 + h_dentry = au_h_dptr(dentry, bindex);
10422 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10423 + if (unlikely(err))
10425 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10426 + if (IS_ERR(h_file)) {
10427 + err = PTR_ERR(h_file);
10430 + au_set_h_fptr(file, bindex, h_file);
10432 + au_update_figen(file);
10433 + /* todo: necessary? */
10434 + /* file->f_ra = h_file->f_ra; */
10436 + return 0; /* success */
10439 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10440 + au_set_h_fptr(file, bindex, NULL);
10441 + au_set_fbtop(file, -1);
10442 + au_set_fbbot_dir(file, -1);
10447 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10448 + struct file *file)
10451 + struct super_block *sb;
10452 + struct au_fidir *fidir;
10455 + sb = file->f_path.dentry->d_sb;
10456 + si_read_lock(sb, AuLock_FLUSH);
10457 + fidir = au_fidir_alloc(sb);
10459 + struct au_do_open_args args = {
10460 + .open = do_open_dir,
10463 + err = au_do_open(file, &args);
10464 + if (unlikely(err))
10465 + au_kfree_rcu(fidir);
10467 + si_read_unlock(sb);
10471 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10472 + struct file *file)
10474 + struct au_vdir *vdir_cache;
10475 + struct au_finfo *finfo;
10476 + struct au_fidir *fidir;
10477 + struct au_hfile *hf;
10478 + aufs_bindex_t bindex, bbot;
10480 + finfo = au_fi(file);
10481 + fidir = finfo->fi_hdir;
10483 + au_hbl_del(&finfo->fi_hlist,
10484 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10485 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10487 + au_vdir_free(vdir_cache);
10489 + bindex = finfo->fi_btop;
10490 + if (bindex >= 0) {
10491 + hf = fidir->fd_hfile + bindex;
10493 + * calls fput() instead of filp_close(),
10494 + * since no dnotify or lock for the lower file.
10496 + bbot = fidir->fd_bbot;
10497 + for (; bindex <= bbot; bindex++, hf++)
10499 + au_hfput(hf, /*execed*/0);
10501 + au_kfree_rcu(fidir);
10502 + finfo->fi_hdir = NULL;
10504 + au_finfo_fin(file);
10508 +/* ---------------------------------------------------------------------- */
10510 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10513 + aufs_bindex_t bindex, bbot;
10514 + struct file *h_file;
10517 + bbot = au_fbbot_dir(file);
10518 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10519 + h_file = au_hf_dir(file, bindex);
10521 + err = vfsub_flush(h_file, id);
10526 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10528 + return au_do_flush(file, id, au_do_flush_dir);
10531 +/* ---------------------------------------------------------------------- */
10533 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10536 + aufs_bindex_t bbot, bindex;
10537 + struct inode *inode;
10538 + struct super_block *sb;
10541 + sb = dentry->d_sb;
10542 + inode = d_inode(dentry);
10543 + IMustLock(inode);
10544 + bbot = au_dbbot(dentry);
10545 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10546 + struct path h_path;
10548 + if (au_test_ro(sb, bindex, inode))
10550 + h_path.dentry = au_h_dptr(dentry, bindex);
10551 + if (!h_path.dentry)
10554 + h_path.mnt = au_sbr_mnt(sb, bindex);
10555 + err = vfsub_fsync(NULL, &h_path, datasync);
10561 +static int au_do_fsync_dir(struct file *file, int datasync)
10564 + aufs_bindex_t bbot, bindex;
10565 + struct file *h_file;
10566 + struct super_block *sb;
10567 + struct inode *inode;
10569 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10570 + if (unlikely(err))
10573 + inode = file_inode(file);
10574 + sb = inode->i_sb;
10575 + bbot = au_fbbot_dir(file);
10576 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10577 + h_file = au_hf_dir(file, bindex);
10578 + if (!h_file || au_test_ro(sb, bindex, inode))
10581 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10589 + * @file may be NULL
10591 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10595 + struct dentry *dentry;
10596 + struct inode *inode;
10597 + struct super_block *sb;
10600 + dentry = file->f_path.dentry;
10601 + inode = d_inode(dentry);
10602 + inode_lock(inode);
10603 + sb = dentry->d_sb;
10604 + si_noflush_read_lock(sb);
10606 + err = au_do_fsync_dir(file, datasync);
10608 + di_write_lock_child(dentry);
10609 + err = au_do_fsync_dir_no_file(dentry, datasync);
10611 + au_cpup_attr_timesizes(inode);
10612 + di_write_unlock(dentry);
10614 + fi_write_unlock(file);
10616 + si_read_unlock(sb);
10617 + inode_unlock(inode);
10621 +/* ---------------------------------------------------------------------- */
10623 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10626 + struct dentry *dentry;
10627 + struct inode *inode, *h_inode;
10628 + struct super_block *sb;
10630 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10632 + dentry = file->f_path.dentry;
10633 + inode = d_inode(dentry);
10634 + IMustLock(inode);
10636 + sb = dentry->d_sb;
10637 + si_read_lock(sb, AuLock_FLUSH);
10638 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10639 + if (unlikely(err))
10641 + err = au_alive_dir(dentry);
10643 + err = au_vdir_init(file);
10644 + di_downgrade_lock(dentry, AuLock_IR);
10645 + if (unlikely(err))
10648 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10649 + if (!au_test_nfsd()) {
10650 + err = au_vdir_fill_de(file, ctx);
10651 + fsstack_copy_attr_atime(inode, h_inode);
10654 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10655 + * encode_fh() and others.
10657 + atomic_inc(&h_inode->i_count);
10658 + di_read_unlock(dentry, AuLock_IR);
10659 + si_read_unlock(sb);
10660 + err = au_vdir_fill_de(file, ctx);
10661 + fsstack_copy_attr_atime(inode, h_inode);
10662 + fi_write_unlock(file);
10670 + di_read_unlock(dentry, AuLock_IR);
10671 + fi_write_unlock(file);
10673 + si_read_unlock(sb);
10677 +/* ---------------------------------------------------------------------- */
10679 +#define AuTestEmpty_WHONLY 1
10680 +#define AuTestEmpty_CALLED (1 << 1)
10681 +#define AuTestEmpty_SHWH (1 << 2)
10682 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10683 +#define au_fset_testempty(flags, name) \
10684 + do { (flags) |= AuTestEmpty_##name; } while (0)
10685 +#define au_fclr_testempty(flags, name) \
10686 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10688 +#ifndef CONFIG_AUFS_SHWH
10689 +#undef AuTestEmpty_SHWH
10690 +#define AuTestEmpty_SHWH 0
10693 +struct test_empty_arg {
10694 + struct dir_context ctx;
10695 + struct au_nhash *whlist;
10696 + unsigned int flags;
10698 + aufs_bindex_t bindex;
10701 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10702 + int namelen, loff_t offset __maybe_unused, u64 ino,
10703 + unsigned int d_type)
10705 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10707 + char *name = (void *)__name;
10710 + au_fset_testempty(arg->flags, CALLED);
10712 + if (name[0] == '.'
10713 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10714 + goto out; /* success */
10716 + if (namelen <= AUFS_WH_PFX_LEN
10717 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10718 + if (au_ftest_testempty(arg->flags, WHONLY)
10719 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10720 + arg->err = -ENOTEMPTY;
10724 + name += AUFS_WH_PFX_LEN;
10725 + namelen -= AUFS_WH_PFX_LEN;
10726 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10727 + arg->err = au_nhash_append_wh
10728 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10729 + au_ftest_testempty(arg->flags, SHWH));
10733 + AuTraceErr(arg->err);
10737 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10740 + struct file *h_file;
10741 + struct au_branch *br;
10743 + h_file = au_h_open(dentry, arg->bindex,
10744 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10745 + /*file*/NULL, /*force_wr*/0);
10746 + err = PTR_ERR(h_file);
10747 + if (IS_ERR(h_file))
10751 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10752 + && !file_inode(h_file)->i_nlink)
10757 + au_fclr_testempty(arg->flags, CALLED);
10759 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10762 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10766 + br = au_sbr(dentry->d_sb, arg->bindex);
10767 + au_lcnt_dec(&br->br_nfiles);
10772 +struct do_test_empty_args {
10774 + struct dentry *dentry;
10775 + struct test_empty_arg *arg;
10778 +static void call_do_test_empty(void *args)
10780 + struct do_test_empty_args *a = args;
10781 + *a->errp = do_test_empty(a->dentry, a->arg);
10784 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10786 + int err, wkq_err;
10787 + struct dentry *h_dentry;
10788 + struct inode *h_inode;
10790 + h_dentry = au_h_dptr(dentry, arg->bindex);
10791 + h_inode = d_inode(h_dentry);
10792 + /* todo: i_mode changes anytime? */
10793 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10794 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10795 + inode_unlock_shared(h_inode);
10797 + err = do_test_empty(dentry, arg);
10799 + struct do_test_empty_args args = {
10801 + .dentry = dentry,
10804 + unsigned int flags = arg->flags;
10806 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10807 + if (unlikely(wkq_err))
10809 + arg->flags = flags;
10815 +int au_test_empty_lower(struct dentry *dentry)
10818 + unsigned int rdhash;
10819 + aufs_bindex_t bindex, btop, btail;
10820 + struct au_nhash whlist;
10821 + struct test_empty_arg arg = {
10823 + .actor = test_empty_cb
10826 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10828 + SiMustAnyLock(dentry->d_sb);
10830 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10832 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10833 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10834 + if (unlikely(err))
10838 + arg.whlist = &whlist;
10839 + btop = au_dbtop(dentry);
10840 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10841 + au_fset_testempty(arg.flags, SHWH);
10842 + test_empty = do_test_empty;
10843 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10844 + test_empty = sio_test_empty;
10845 + arg.bindex = btop;
10846 + err = test_empty(dentry, &arg);
10847 + if (unlikely(err))
10850 + au_fset_testempty(arg.flags, WHONLY);
10851 + btail = au_dbtaildir(dentry);
10852 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10853 + struct dentry *h_dentry;
10855 + h_dentry = au_h_dptr(dentry, bindex);
10856 + if (h_dentry && d_is_positive(h_dentry)) {
10857 + arg.bindex = bindex;
10858 + err = test_empty(dentry, &arg);
10863 + au_nhash_wh_free(&whlist);
10868 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10871 + struct test_empty_arg arg = {
10873 + .actor = test_empty_cb
10876 + aufs_bindex_t bindex, btail;
10879 + arg.whlist = whlist;
10880 + arg.flags = AuTestEmpty_WHONLY;
10881 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10882 + au_fset_testempty(arg.flags, SHWH);
10883 + btail = au_dbtaildir(dentry);
10884 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10885 + struct dentry *h_dentry;
10887 + h_dentry = au_h_dptr(dentry, bindex);
10888 + if (h_dentry && d_is_positive(h_dentry)) {
10889 + arg.bindex = bindex;
10890 + err = sio_test_empty(dentry, &arg);
10897 +/* ---------------------------------------------------------------------- */
10899 +const struct file_operations aufs_dir_fop = {
10900 + .owner = THIS_MODULE,
10901 + .llseek = default_llseek,
10902 + .read = generic_read_dir,
10903 + .iterate_shared = aufs_iterate_shared,
10904 + .unlocked_ioctl = aufs_ioctl_dir,
10905 +#ifdef CONFIG_COMPAT
10906 + .compat_ioctl = aufs_compat_ioctl_dir,
10908 + .open = aufs_open_dir,
10909 + .release = aufs_release_dir,
10910 + .flush = aufs_flush_dir,
10911 + .fsync = aufs_fsync_dir
10913 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10914 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10915 +++ linux/fs/aufs/dir.h 2019-03-05 12:13:00.139224339 +0100
10917 +/* SPDX-License-Identifier: GPL-2.0 */
10919 + * Copyright (C) 2005-2019 Junjiro R. Okajima
10921 + * This program, aufs is free software; you can redistribute it and/or modify
10922 + * it under the terms of the GNU General Public License as published by
10923 + * the Free Software Foundation; either version 2 of the License, or
10924 + * (at your option) any later version.
10926 + * This program is distributed in the hope that it will be useful,
10927 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10928 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10929 + * GNU General Public License for more details.
10931 + * You should have received a copy of the GNU General Public License
10932 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10936 + * directory operations
10939 +#ifndef __AUFS_DIR_H__
10940 +#define __AUFS_DIR_H__
10944 +#include <linux/fs.h>
10946 +/* ---------------------------------------------------------------------- */
10948 +/* need to be faster and smaller */
10951 + unsigned int nh_num;
10952 + struct hlist_head *nh_head;
10955 +struct au_vdir_destr {
10956 + unsigned char len;
10957 + unsigned char name[0];
10960 +struct au_vdir_dehstr {
10961 + struct hlist_node hash;
10962 + struct au_vdir_destr *str;
10963 + struct rcu_head rcu;
10964 +} ____cacheline_aligned_in_smp;
10966 +struct au_vdir_de {
10968 + unsigned char de_type;
10969 + /* caution: packed */
10970 + struct au_vdir_destr de_str;
10973 +struct au_vdir_wh {
10974 + struct hlist_node wh_hash;
10975 +#ifdef CONFIG_AUFS_SHWH
10977 + aufs_bindex_t wh_bindex;
10978 + unsigned char wh_type;
10980 + aufs_bindex_t wh_bindex;
10982 + /* caution: packed */
10983 + struct au_vdir_destr wh_str;
10986 +union au_vdir_deblk_p {
10987 + unsigned char *deblk;
10988 + struct au_vdir_de *de;
10992 + unsigned char **vd_deblk;
10993 + unsigned long vd_nblk;
10995 + unsigned long ul;
10996 + union au_vdir_deblk_p p;
11000 + unsigned int vd_deblk_sz;
11001 + unsigned long vd_jiffy;
11002 + struct rcu_head rcu;
11003 +} ____cacheline_aligned_in_smp;
11005 +/* ---------------------------------------------------------------------- */
11008 +extern const struct file_operations aufs_dir_fop;
11009 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
11010 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
11011 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
11012 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
11013 +int au_test_empty_lower(struct dentry *dentry);
11014 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
11017 +unsigned int au_rdhash_est(loff_t sz);
11018 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
11019 +void au_nhash_wh_free(struct au_nhash *whlist);
11020 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
11022 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
11023 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
11024 + unsigned int d_type, aufs_bindex_t bindex,
11025 + unsigned char shwh);
11026 +void au_vdir_free(struct au_vdir *vdir);
11027 +int au_vdir_init(struct file *file);
11028 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
11031 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
11033 +#ifdef CONFIG_AUFS_RDU
11035 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
11036 +#ifdef CONFIG_COMPAT
11037 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
11038 + unsigned long arg);
11041 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
11042 + unsigned int cmd, unsigned long arg)
11043 +#ifdef CONFIG_COMPAT
11044 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
11045 + unsigned int cmd, unsigned long arg)
11049 +#endif /* __KERNEL__ */
11050 +#endif /* __AUFS_DIR_H__ */
11051 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
11052 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
11053 +++ linux/fs/aufs/dirren.c 2019-03-05 12:13:00.139224339 +0100
11055 +// SPDX-License-Identifier: GPL-2.0
11057 + * Copyright (C) 2017-2019 Junjiro R. Okajima
11059 + * This program, aufs is free software; you can redistribute it and/or modify
11060 + * it under the terms of the GNU General Public License as published by
11061 + * the Free Software Foundation; either version 2 of the License, or
11062 + * (at your option) any later version.
11064 + * This program is distributed in the hope that it will be useful,
11065 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11066 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11067 + * GNU General Public License for more details.
11069 + * You should have received a copy of the GNU General Public License
11070 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11074 + * special handling in renaming a directory
11075 + * in order to support looking-up the before-renamed name on the lower readonly
11079 +#include <linux/byteorder/generic.h>
11082 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
11086 + idx = au_dr_ihash(ent->dr_h_ino);
11087 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
11090 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
11093 + struct hlist_bl_head *hbl;
11096 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
11097 + hbl = dr->dr_h_ino + i;
11098 + hlist_bl_lock(hbl);
11099 + ret &= hlist_bl_empty(hbl);
11100 + hlist_bl_unlock(hbl);
11106 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
11108 + struct au_dr_hino *found, *ent;
11109 + struct hlist_bl_head *hbl;
11110 + struct hlist_bl_node *pos;
11114 + idx = au_dr_ihash(ino);
11115 + hbl = dr->dr_h_ino + idx;
11116 + hlist_bl_lock(hbl);
11117 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11118 + if (ent->dr_h_ino == ino) {
11122 + hlist_bl_unlock(hbl);
11127 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
11128 + struct au_dr_hino *add_ent)
11131 + struct hlist_bl_head *hbl;
11132 + struct hlist_bl_node *pos;
11133 + struct au_dr_hino *ent;
11136 + idx = au_dr_ihash(ino);
11137 + hbl = dr->dr_h_ino + idx;
11140 + struct hlist_bl_node *tmp;
11142 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11143 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
11146 + hlist_bl_lock(hbl);
11147 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11148 + if (ent->dr_h_ino == ino) {
11152 + if (!found && add_ent)
11153 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
11154 + hlist_bl_unlock(hbl);
11156 + if (!found && add_ent)
11157 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
11162 +void au_dr_hino_free(struct au_dr_br *dr)
11165 + struct hlist_bl_head *hbl;
11166 + struct hlist_bl_node *pos, *tmp;
11167 + struct au_dr_hino *ent;
11169 + /* SiMustWriteLock(sb); */
11171 + for (i = 0; i < AuDirren_NHASH; i++) {
11172 + hbl = dr->dr_h_ino + i;
11173 + /* no spinlock since sbinfo must be write-locked */
11174 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11175 + au_kfree_rcu(ent);
11176 + INIT_HLIST_BL_HEAD(hbl);
11180 +/* returns the number of inodes or an error */
11181 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11182 + struct file *hinofile)
11186 + loff_t pos, oldsize;
11188 + struct inode *hinoinode;
11189 + struct hlist_bl_head *hbl;
11190 + struct hlist_bl_node *n1, *n2;
11191 + struct au_dr_hino *ent;
11193 + SiMustWriteLock(sb);
11194 + AuDebugOn(!au_br_writable(br->br_perm));
11196 + hinoinode = file_inode(hinofile);
11197 + oldsize = i_size_read(hinoinode);
11201 + hbl = br->br_dirren.dr_h_ino;
11202 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11203 + /* no bit-lock since sbinfo must be write-locked */
11204 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11205 + AuDbg("hi%llu, %pD2\n",
11206 + (unsigned long long)ent->dr_h_ino, hinofile);
11207 + u64 = cpu_to_be64(ent->dr_h_ino);
11208 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11209 + if (ssz == sizeof(u64))
11212 + /* write error */
11213 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11220 + /* regardless the error */
11221 + if (pos < oldsize) {
11222 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11230 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11237 + struct au_dr_hino *ent;
11238 + struct inode *hinoinode;
11239 + struct hlist_bl_head *hbl;
11243 + hbl = dr->dr_h_ino;
11244 + hinoinode = file_inode(hinofile);
11245 + sz = i_size_read(hinoinode);
11246 + AuDebugOn(sz % sizeof(u64));
11247 + n = sz / sizeof(u64);
11249 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11250 + if (unlikely(ssz != sizeof(u64))) {
11251 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11258 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11264 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11265 + AuDbg("hi%llu, %pD2\n",
11266 + (unsigned long long)ent->dr_h_ino, hinofile);
11267 + hidx = au_dr_ihash(ent->dr_h_ino);
11268 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11270 + goto out; /* success */
11273 + au_dr_hino_free(dr);
11280 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11281 + * @path is a switch to distinguish load and store.
11283 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11284 + struct au_branch *br, const struct path *path)
11287 + unsigned char load, suspend;
11288 + struct file *hinofile;
11289 + struct au_hinode *hdir;
11290 + struct inode *dir, *delegated;
11291 + struct path hinopath;
11292 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11293 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11295 + AuDebugOn(bindex < 0 && !br);
11296 + AuDebugOn(bindex >= 0 && br);
11301 + br = au_sbr(sb, bindex);
11304 + path = &br->br_path;
11305 + AuDebugOn(!au_br_writable(br->br_perm));
11306 + if (unlikely(!au_br_writable(br->br_perm)))
11312 + dir = d_inode(sb->s_root);
11313 + hdir = au_hinode(au_ii(dir), bindex);
11314 + dir = hdir->hi_inode;
11315 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11317 + dir = d_inode(path->dentry);
11318 + inode_lock_nested(dir, AuLsc_I_CHILD);
11320 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11321 + err = PTR_ERR(hinopath.dentry);
11322 + if (IS_ERR(hinopath.dentry))
11326 + flags = O_RDONLY;
11328 + if (d_is_negative(hinopath.dentry))
11329 + goto out_dput; /* success */
11331 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11332 + if (d_is_positive(hinopath.dentry)) {
11333 + delegated = NULL;
11334 + err = vfsub_unlink(dir, &hinopath, &delegated,
11337 + if (unlikely(err))
11338 + pr_err("ignored err %d, %pd2\n",
11339 + err, hinopath.dentry);
11340 + if (unlikely(err == -EWOULDBLOCK))
11345 + } else if (!d_is_positive(hinopath.dentry)) {
11346 + err = vfsub_create(dir, &hinopath, 0600,
11347 + /*want_excl*/false);
11349 + if (unlikely(err))
11352 + flags = O_WRONLY;
11354 + hinopath.mnt = path->mnt;
11355 + hinofile = vfsub_dentry_open(&hinopath, flags);
11357 + au_hn_inode_unlock(hdir);
11359 + inode_unlock(dir);
11360 + dput(hinopath.dentry);
11361 + AuTraceErrPtr(hinofile);
11362 + if (IS_ERR(hinofile)) {
11363 + err = PTR_ERR(hinofile);
11368 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11370 + err = au_dr_hino_store(sb, br, hinofile);
11375 + dput(hinopath.dentry);
11378 + au_hn_inode_unlock(hdir);
11380 + inode_unlock(dir);
11386 +/* ---------------------------------------------------------------------- */
11388 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11391 + struct kstatfs kstfs;
11393 + struct dentry *dentry;
11394 + struct super_block *sb;
11396 + err = vfs_statfs((void *)path, &kstfs);
11398 + if (unlikely(err))
11401 + /* todo: support for UUID */
11403 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11404 + brid->type = AuBrid_FSID;
11405 + brid->fsid = kstfs.f_fsid;
11407 + dentry = path->dentry;
11408 + sb = dentry->d_sb;
11411 + brid->type = AuBrid_DEV;
11420 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11421 + const struct path *path)
11424 + struct au_dr_br *dr;
11425 + struct hlist_bl_head *hbl;
11427 + dr = &br->br_dirren;
11428 + hbl = dr->dr_h_ino;
11429 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11430 + INIT_HLIST_BL_HEAD(hbl);
11432 + err = au_dr_brid_init(&dr->dr_brid, path);
11433 + if (unlikely(err))
11436 + if (au_opt_test(au_mntflags(sb), DIRREN))
11437 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11444 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11449 + if (au_br_writable(br->br_perm))
11450 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11452 + au_dr_hino_free(&br->br_dirren);
11457 +/* ---------------------------------------------------------------------- */
11459 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11460 + char *buf, size_t sz)
11463 + unsigned int major, minor;
11467 + err = snprintf(p, sz, "%d_", brid->type);
11468 + AuDebugOn(err > sz);
11471 + switch (brid->type) {
11472 + case AuBrid_Unset:
11474 + case AuBrid_UUID:
11475 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11477 + case AuBrid_FSID:
11478 + err = snprintf(p, sz, "%08x-%08x",
11479 + brid->fsid.val[0], brid->fsid.val[1]);
11482 + major = MAJOR(brid->dev);
11483 + minor = MINOR(brid->dev);
11484 + if (major <= 0xff && minor <= 0xff)
11485 + err = snprintf(p, sz, "%02x%02x", major, minor);
11487 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11490 + AuDebugOn(err > sz);
11493 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11494 + AuDebugOn(err > sz);
11501 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11504 + struct dentry *br_dentry;
11505 + struct inode *br_inode;
11507 + br_dentry = au_br_dentry(br);
11508 + br_inode = d_inode(br_dentry);
11509 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11510 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11511 + AuDebugOn(rlen > len);
11516 +/* ---------------------------------------------------------------------- */
11519 + * from the given @h_dentry, construct drinfo at @*fdata.
11520 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11523 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11524 + struct dentry *h_dentry,
11525 + unsigned char *allocated)
11528 + struct au_drinfo_fdata *f, *p;
11529 + struct au_drinfo *drinfo;
11530 + struct inode *h_inode;
11531 + struct qstr *qname;
11535 + h_inode = d_inode(h_dentry);
11536 + qname = &h_dentry->d_name;
11537 + drinfo = &f->drinfo;
11538 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11539 + drinfo->oldnamelen = qname->len;
11540 + if (*allocated < sizeof(*f) + qname->len) {
11541 + v = roundup_pow_of_two(*allocated + qname->len);
11542 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11543 + if (unlikely(!p)) {
11551 + drinfo = &f->drinfo;
11553 + memcpy(drinfo->oldname, qname->name, qname->len);
11554 + AuDbg("i%llu, %.*s\n",
11555 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11556 + drinfo->oldname);
11563 +/* callers have to free the return value */
11564 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11566 + struct au_drinfo *ret, *drinfo;
11567 + struct au_drinfo_fdata fdata;
11572 + ret = ERR_PTR(-EIO);
11574 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11575 + if (unlikely(ssz != sizeof(fdata))) {
11576 + AuIOErr("ssz %zd, %u, %pD2\n",
11577 + ssz, (unsigned int)sizeof(fdata), file);
11581 + fdata.magic = ntohl((__force __be32)fdata.magic);
11582 + switch (fdata.magic) {
11583 + case AUFS_DRINFO_MAGIC_V1:
11586 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11587 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11591 + drinfo = &fdata.drinfo;
11592 + len = drinfo->oldnamelen;
11594 + AuIOErr("broken drinfo %pD2\n", file);
11599 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11600 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11601 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11602 + (unsigned long long)drinfo->ino,
11603 + (unsigned long long)h_ino, file);
11604 + goto out; /* success */
11607 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11608 + if (unlikely(!ret)) {
11609 + ret = ERR_PTR(-ENOMEM);
11610 + AuTraceErrPtr(ret);
11615 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11616 + if (unlikely(ssz != len)) {
11617 + au_kfree_rcu(ret);
11618 + ret = ERR_PTR(-EIO);
11619 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11623 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11629 +/* ---------------------------------------------------------------------- */
11631 +/* in order to be revertible */
11632 +struct au_drinfo_rev_elm {
11634 + struct dentry *info_dentry;
11635 + struct au_drinfo *info_last;
11638 +struct au_drinfo_rev {
11639 + unsigned char already;
11640 + aufs_bindex_t nelm;
11641 + struct au_drinfo_rev_elm elm[0];
11644 +/* todo: isn't it too large? */
11645 +struct au_drinfo_store {
11646 + struct path h_ppath;
11647 + struct dentry *h_dentry;
11648 + struct au_drinfo_fdata *fdata;
11649 + char *infoname; /* inside of whname, just after PFX */
11650 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11651 + aufs_bindex_t btgt, btail;
11652 + unsigned char no_sio,
11653 + allocated, /* current size of *fdata */
11654 + infonamelen, /* room size for p */
11655 + whnamelen, /* length of the generated name */
11656 + renameback; /* renamed back */
11659 +/* on rename(2) error, the caller should revert it using @elm */
11660 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11661 + struct au_drinfo_rev_elm *elm)
11666 + struct path infopath = {
11667 + .mnt = w->h_ppath.mnt
11669 + struct inode *h_dir, *h_inode, *delegated;
11670 + struct file *infofile;
11671 + struct qstr *qname;
11674 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11676 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11678 + AuTraceErrPtr(infopath.dentry);
11679 + if (IS_ERR(infopath.dentry)) {
11680 + err = PTR_ERR(infopath.dentry);
11685 + h_dir = d_inode(w->h_ppath.dentry);
11686 + if (elm && d_is_negative(infopath.dentry)) {
11687 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11689 + if (unlikely(err))
11691 + elm->created = 1;
11692 + elm->info_dentry = dget(infopath.dentry);
11695 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11696 + AuTraceErrPtr(infofile);
11697 + if (IS_ERR(infofile)) {
11698 + err = PTR_ERR(infofile);
11702 + h_inode = d_inode(infopath.dentry);
11703 + if (elm && i_size_read(h_inode)) {
11704 + h_inode = d_inode(w->h_dentry);
11705 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11706 + AuTraceErrPtr(elm->info_last);
11707 + if (IS_ERR(elm->info_last)) {
11708 + err = PTR_ERR(elm->info_last);
11709 + elm->info_last = NULL;
11710 + AuDebugOn(elm->info_dentry);
11715 + if (elm && w->renameback) {
11716 + delegated = NULL;
11717 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11719 + if (unlikely(err == -EWOULDBLOCK))
11725 + qname = &w->h_dentry->d_name;
11726 + len = sizeof(*w->fdata) + qname->len;
11728 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11729 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11730 + if (ssz == len) {
11731 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11732 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11733 + goto out_fput; /* success */
11738 + /* the caller should revert it using @elm */
11744 + dput(infopath.dentry);
11750 +struct au_call_drinfo_do_store_args {
11752 + struct au_drinfo_store *w;
11753 + struct au_drinfo_rev_elm *elm;
11756 +static void au_call_drinfo_do_store(void *args)
11758 + struct au_call_drinfo_do_store_args *a = args;
11760 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11763 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11764 + struct au_drinfo_rev_elm *elm)
11766 + int err, wkq_err;
11769 + err = au_drinfo_do_store(w, elm);
11771 + struct au_call_drinfo_do_store_args a = {
11776 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11777 + if (unlikely(wkq_err))
11785 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11786 + aufs_bindex_t btgt)
11790 + memset(w, 0, sizeof(*w));
11791 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11792 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11793 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11794 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11796 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11799 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11800 + if (unlikely(!w->fdata)) {
11804 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11811 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11813 + au_kfree_rcu(w->fdata);
11816 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11817 + struct au_drinfo_store *w)
11819 + struct au_drinfo_rev_elm *elm;
11820 + struct inode *h_dir, *delegated;
11822 + struct path infopath = {
11823 + .mnt = w->h_ppath.mnt
11826 + h_dir = d_inode(w->h_ppath.dentry);
11827 + IMustLock(h_dir);
11831 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11832 + AuDebugOn(elm->created && elm->info_last);
11833 + if (elm->created) {
11835 + delegated = NULL;
11836 + infopath.dentry = elm->info_dentry;
11837 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11840 + if (unlikely(err == -EWOULDBLOCK))
11842 + dput(elm->info_dentry);
11843 + } else if (elm->info_last) {
11845 + w->fdata->drinfo = *elm->info_last;
11846 + memcpy(w->fdata->drinfo.oldname,
11847 + elm->info_last->oldname,
11848 + elm->info_last->oldnamelen);
11849 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11850 + au_kfree_rcu(elm->info_last);
11852 + if (unlikely(err))
11853 + AuIOErr("%d, %s\n", err, w->whname);
11854 + /* go on even if err */
11858 +/* caller has to call au_dr_rename_fin() later */
11859 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11860 + struct qstr *dst_name, void *_rev)
11862 + int err, sz, nelm;
11863 + aufs_bindex_t bindex, btail;
11864 + struct au_drinfo_store work;
11865 + struct au_drinfo_rev *rev, **p;
11866 + struct au_drinfo_rev_elm *elm;
11867 + struct super_block *sb;
11868 + struct au_branch *br;
11869 + struct au_hinode *hdir;
11871 + err = au_drinfo_store_work_init(&work, btgt);
11873 + if (unlikely(err))
11877 + btail = au_dbtaildir(dentry);
11878 + nelm = btail - btgt;
11879 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11880 + rev = kcalloc(1, sz, GFP_NOFS);
11881 + if (unlikely(!rev)) {
11885 + rev->nelm = nelm;
11891 + sb = dentry->d_sb;
11892 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11893 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11894 + hdir = au_hi(d_inode(dentry), btgt);
11895 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11896 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11897 + work.h_dentry = au_h_dptr(dentry, bindex);
11898 + if (!work.h_dentry)
11901 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11902 + &work.allocated);
11904 + if (unlikely(err))
11907 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11908 + br = au_sbr(sb, bindex);
11909 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11910 + work.whnamelen += au_drinfo_name(br, work.infoname,
11911 + work.infonamelen);
11912 + AuDbg("whname %.*s, i%llu, %.*s\n",
11913 + work.whnamelen, work.whname,
11914 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11915 + work.fdata->drinfo.oldnamelen,
11916 + work.fdata->drinfo.oldname);
11918 + err = au_drinfo_store_sio(&work, elm);
11920 + if (unlikely(err))
11923 + if (unlikely(err)) {
11924 + /* revert all drinfo */
11925 + au_drinfo_store_rev(rev, &work);
11926 + au_kfree_try_rcu(rev);
11929 + au_hn_inode_unlock(hdir);
11932 + au_drinfo_store_work_fin(&work);
11937 +/* ---------------------------------------------------------------------- */
11939 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11940 + struct qstr *dst_name, void *_rev)
11942 + int err, already;
11944 + struct super_block *sb;
11945 + struct au_branch *br;
11946 + struct au_dr_br *dr;
11947 + struct dentry *h_dentry;
11948 + struct inode *h_inode;
11949 + struct au_dr_hino *ent;
11950 + struct au_drinfo_rev *rev, **p;
11952 + AuDbg("bindex %d\n", bindex);
11955 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11956 + if (unlikely(!ent))
11960 + br = au_sbr(sb, bindex);
11961 + dr = &br->br_dirren;
11962 + h_dentry = au_h_dptr(src, bindex);
11963 + h_inode = d_inode(h_dentry);
11964 + ino = h_inode->i_ino;
11965 + ent->dr_h_ino = ino;
11966 + already = au_dr_hino_test_add(dr, ino, ent);
11967 + AuDbg("b%d, hi%llu, already %d\n",
11968 + bindex, (unsigned long long)ino, already);
11970 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11975 + rev->already = already;
11976 + goto out; /* success */
11981 + au_dr_hino_del(dr, ent);
11982 + au_kfree_rcu(ent);
11989 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11991 + struct au_drinfo_rev *rev;
11992 + struct au_drinfo_rev_elm *elm;
11997 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11998 + dput(elm->info_dentry);
11999 + au_kfree_rcu(elm->info_last);
12001 + au_kfree_try_rcu(rev);
12004 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
12007 + struct au_drinfo_store work;
12008 + struct au_drinfo_rev *rev = _rev;
12009 + struct super_block *sb;
12010 + struct au_branch *br;
12011 + struct inode *h_inode;
12012 + struct au_dr_br *dr;
12013 + struct au_dr_hino *ent;
12015 + err = au_drinfo_store_work_init(&work, btgt);
12016 + if (unlikely(err))
12020 + br = au_sbr(sb, btgt);
12021 + work.h_ppath.dentry = au_h_dptr(src, btgt);
12022 + work.h_ppath.mnt = au_br_mnt(br);
12023 + au_drinfo_store_rev(rev, &work);
12024 + au_drinfo_store_work_fin(&work);
12025 + if (rev->already)
12028 + dr = &br->br_dirren;
12029 + h_inode = d_inode(work.h_ppath.dentry);
12030 + ent = au_dr_hino_find(dr, h_inode->i_ino);
12032 + au_dr_hino_del(dr, ent);
12033 + au_kfree_rcu(ent);
12036 + au_kfree_try_rcu(rev);
12037 + if (unlikely(err))
12038 + pr_err("failed to remove dirren info\n");
12041 +/* ---------------------------------------------------------------------- */
12043 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
12044 + char *whname, int whnamelen,
12045 + struct dentry **info_dentry)
12047 + struct au_drinfo *drinfo;
12049 + struct inode *h_dir;
12050 + struct path infopath;
12053 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
12055 + *info_dentry = NULL;
12058 + h_dir = d_inode(h_ppath->dentry);
12059 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
12060 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
12062 + if (IS_ERR(infopath.dentry)) {
12063 + drinfo = (void *)infopath.dentry;
12067 + if (d_is_negative(infopath.dentry))
12068 + goto out_dput; /* success */
12070 + infopath.mnt = h_ppath->mnt;
12071 + f = vfsub_dentry_open(&infopath, O_RDONLY);
12072 + inode_unlock_shared(h_dir);
12075 + drinfo = (void *)f;
12079 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
12080 + if (IS_ERR_OR_NULL(drinfo))
12083 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
12084 + *info_dentry = dget(infopath.dentry); /* keep it alive */
12089 + dput(infopath.dentry);
12092 + inode_unlock_shared(h_dir);
12093 + AuTraceErrPtr(drinfo);
12097 +struct au_drinfo_do_load_args {
12098 + struct au_drinfo **drinfop;
12099 + struct path *h_ppath;
12102 + struct dentry **info_dentry;
12105 +static void au_call_drinfo_do_load(void *args)
12107 + struct au_drinfo_do_load_args *a = args;
12109 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
12113 +struct au_drinfo_load {
12114 + struct path h_ppath;
12115 + struct qstr *qname;
12116 + unsigned char no_sio;
12118 + aufs_bindex_t ninfo;
12119 + struct au_drinfo **drinfo;
12122 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
12123 + struct au_branch *br)
12125 + int err, wkq_err, whnamelen, e;
12126 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
12127 + = AUFS_WH_DR_INFO_PFX;
12128 + struct au_drinfo *drinfo;
12129 + struct qstr oldname;
12130 + struct inode *h_dir, *delegated;
12131 + struct dentry *info_dentry;
12132 + struct path infopath;
12134 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
12135 + whnamelen += au_drinfo_name(br, whname + whnamelen,
12136 + sizeof(whname) - whnamelen);
12138 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
12141 + struct au_drinfo_do_load_args args = {
12142 + .drinfop = &drinfo,
12143 + .h_ppath = &w->h_ppath,
12144 + .whname = whname,
12145 + .whnamelen = whnamelen,
12146 + .info_dentry = &info_dentry
12148 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
12149 + if (unlikely(wkq_err))
12150 + drinfo = ERR_PTR(wkq_err);
12152 + err = PTR_ERR(drinfo);
12153 + if (IS_ERR_OR_NULL(drinfo))
12157 + oldname.len = drinfo->oldnamelen;
12158 + oldname.name = drinfo->oldname;
12159 + if (au_qstreq(w->qname, &oldname)) {
12160 + /* the name is renamed back */
12161 + au_kfree_rcu(drinfo);
12164 + infopath.dentry = info_dentry;
12165 + infopath.mnt = w->h_ppath.mnt;
12166 + h_dir = d_inode(w->h_ppath.dentry);
12167 + delegated = NULL;
12168 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
12169 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
12170 + inode_unlock(h_dir);
12172 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
12173 + if (unlikely(e == -EWOULDBLOCK))
12176 + au_kfree_rcu(w->drinfo[bindex]);
12177 + w->drinfo[bindex] = drinfo;
12178 + dput(info_dentry);
12185 +/* ---------------------------------------------------------------------- */
12187 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12189 + struct au_drinfo **p = drinfo;
12192 + au_kfree_rcu(*drinfo++);
12193 + au_kfree_try_rcu(p);
12196 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12197 + aufs_bindex_t btgt)
12200 + struct au_drinfo_load w;
12201 + aufs_bindex_t bindex, bbot;
12202 + struct au_branch *br;
12203 + struct inode *h_dir;
12204 + struct au_dr_hino *ent;
12205 + struct super_block *sb;
12207 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12208 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12209 + AuLNPair(&lkup->whname), btgt);
12211 + sb = dentry->d_sb;
12212 + bbot = au_sbbot(sb);
12213 + w.ninfo = bbot + 1;
12214 + if (!lkup->dirren.drinfo) {
12215 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12216 + sizeof(*lkup->dirren.drinfo),
12218 + if (unlikely(!lkup->dirren.drinfo)) {
12222 + lkup->dirren.ninfo = w.ninfo;
12224 + w.drinfo = lkup->dirren.drinfo;
12225 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12226 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12227 + AuDebugOn(!w.h_ppath.dentry);
12228 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12229 + w.qname = &dentry->d_name;
12232 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12233 + br = au_sbr(sb, bindex);
12234 + err = au_drinfo_load(&w, bindex, br);
12235 + if (unlikely(err))
12237 + if (w.drinfo[bindex])
12241 + br = au_sbr(sb, btgt);
12242 + h_dir = d_inode(w.h_ppath.dentry);
12243 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12245 + au_dr_hino_del(&br->br_dirren, ent);
12246 + au_kfree_rcu(ent);
12248 + goto out; /* success */
12251 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12252 + lkup->dirren.ninfo = 0;
12253 + lkup->dirren.drinfo = NULL;
12259 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12261 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12264 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12267 + struct au_drinfo *drinfo;
12270 + if (!lkup->dirren.drinfo)
12272 + AuDebugOn(lkup->dirren.ninfo < btgt + 1);
12273 + drinfo = lkup->dirren.drinfo[btgt + 1];
12277 + au_kfree_try_rcu(lkup->whname.name);
12278 + lkup->whname.name = NULL;
12279 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12280 + lkup->dirren.dr_name.name = drinfo->oldname;
12281 + lkup->name = &lkup->dirren.dr_name;
12282 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12284 + AuDbg("name %.*s, whname %.*s, b%d\n",
12285 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12293 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12297 + struct au_drinfo *drinfo;
12300 + if (!lkup->dirren.drinfo)
12302 + AuDebugOn(lkup->dirren.ninfo < bindex + 1);
12303 + drinfo = lkup->dirren.drinfo[bindex + 1];
12307 + match = (drinfo->ino == h_ino);
12308 + AuDbg("match %d\n", match);
12314 +/* ---------------------------------------------------------------------- */
12316 +int au_dr_opt_set(struct super_block *sb)
12319 + aufs_bindex_t bindex, bbot;
12320 + struct au_branch *br;
12323 + bbot = au_sbbot(sb);
12324 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12325 + br = au_sbr(sb, bindex);
12326 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12332 +int au_dr_opt_flush(struct super_block *sb)
12335 + aufs_bindex_t bindex, bbot;
12336 + struct au_branch *br;
12339 + bbot = au_sbbot(sb);
12340 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12341 + br = au_sbr(sb, bindex);
12342 + if (au_br_writable(br->br_perm))
12343 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12349 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12352 + aufs_bindex_t bindex, bbot;
12353 + struct au_branch *br;
12357 + err = au_dr_opt_flush(sb);
12358 + if (unlikely(err))
12362 + bbot = au_sbbot(sb);
12363 + for (bindex = 0; bindex <= bbot; bindex++) {
12364 + br = au_sbr(sb, bindex);
12365 + au_dr_hino_free(&br->br_dirren);
12371 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12372 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12373 +++ linux/fs/aufs/dirren.h 2019-03-05 12:13:00.139224339 +0100
12375 +/* SPDX-License-Identifier: GPL-2.0 */
12377 + * Copyright (C) 2017-2019 Junjiro R. Okajima
12379 + * This program, aufs is free software; you can redistribute it and/or modify
12380 + * it under the terms of the GNU General Public License as published by
12381 + * the Free Software Foundation; either version 2 of the License, or
12382 + * (at your option) any later version.
12384 + * This program is distributed in the hope that it will be useful,
12385 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12386 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12387 + * GNU General Public License for more details.
12389 + * You should have received a copy of the GNU General Public License
12390 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12394 + * renamed dir info
12397 +#ifndef __AUFS_DIRREN_H__
12398 +#define __AUFS_DIRREN_H__
12402 +#include <linux/dcache.h>
12403 +#include <linux/statfs.h>
12404 +#include <linux/uuid.h>
12407 +#define AuDirren_NHASH 100
12409 +#ifdef CONFIG_AUFS_DIRREN
12410 +enum au_brid_type {
12417 +struct au_dr_brid {
12418 + enum au_brid_type type;
12420 + uuid_t uuid; /* unimplemented yet */
12426 +/* 20 is the max digits length of ulong 64 */
12427 +/* brid-type "_" uuid "_" inum */
12428 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12429 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12431 +struct au_dr_hino {
12432 + struct hlist_bl_node dr_hnode;
12437 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12438 + struct au_dr_brid dr_brid;
12441 +struct au_dr_lookup {
12442 + /* dr_name is pointed by struct au_do_lookup_args.name */
12443 + struct qstr dr_name; /* subset of dr_info */
12444 + aufs_bindex_t ninfo;
12445 + struct au_drinfo **drinfo;
12448 +struct au_dr_hino;
12450 +struct au_dr_br { };
12451 +struct au_dr_lookup { };
12454 +/* ---------------------------------------------------------------------- */
12457 +struct au_do_lookup_args;
12459 +#ifdef CONFIG_AUFS_DIRREN
12460 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12461 + struct au_dr_hino *add_ent);
12462 +void au_dr_hino_free(struct au_dr_br *dr);
12463 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12464 + const struct path *path);
12465 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12466 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12467 + struct qstr *dst_name, void *_rev);
12468 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12469 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12470 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12471 + aufs_bindex_t bindex);
12472 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12473 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12475 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12476 +int au_dr_opt_set(struct super_block *sb);
12477 +int au_dr_opt_flush(struct super_block *sb);
12478 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12480 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12481 + struct au_dr_hino *add_ent);
12482 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12483 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12484 + const struct path *path);
12485 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12486 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12487 + struct qstr *dst_name, void *_rev);
12488 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12489 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12491 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12492 + aufs_bindex_t bindex);
12493 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12494 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12495 + aufs_bindex_t bindex, ino_t h_ino);
12496 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12497 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12498 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12499 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12502 +/* ---------------------------------------------------------------------- */
12504 +#ifdef CONFIG_AUFS_DIRREN
12505 +static inline int au_dr_ihash(ino_t h_ino)
12507 + return h_ino % AuDirren_NHASH;
12510 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12513 +#endif /* __KERNEL__ */
12514 +#endif /* __AUFS_DIRREN_H__ */
12515 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12516 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12517 +++ linux/fs/aufs/dynop.c 2019-03-05 12:13:00.139224339 +0100
12519 +// SPDX-License-Identifier: GPL-2.0
12521 + * Copyright (C) 2010-2019 Junjiro R. Okajima
12523 + * This program, aufs is free software; you can redistribute it and/or modify
12524 + * it under the terms of the GNU General Public License as published by
12525 + * the Free Software Foundation; either version 2 of the License, or
12526 + * (at your option) any later version.
12528 + * This program is distributed in the hope that it will be useful,
12529 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12530 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12531 + * GNU General Public License for more details.
12533 + * You should have received a copy of the GNU General Public License
12534 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12538 + * dynamically customizable operations for regular files
12543 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12546 + * How large will these lists be?
12547 + * Usually just a few elements, 20-30 at most for each, I guess.
12549 +static struct hlist_bl_head dynop[AuDyLast];
12551 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12552 + const void *h_op)
12554 + struct au_dykey *key, *tmp;
12555 + struct hlist_bl_node *pos;
12558 + hlist_bl_lock(hbl);
12559 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12560 + if (tmp->dk_op.dy_hop == h_op) {
12562 + kref_get(&key->dk_kref);
12565 + hlist_bl_unlock(hbl);
12570 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12572 + struct au_dykey **k, *found;
12573 + const void *h_op = key->dk_op.dy_hop;
12577 + k = br->br_dykey;
12578 + for (i = 0; i < AuBrDynOp; i++)
12580 + if (k[i]->dk_op.dy_hop == h_op) {
12587 + spin_lock(&br->br_dykey_lock);
12588 + for (; i < AuBrDynOp; i++)
12590 + if (k[i]->dk_op.dy_hop == h_op) {
12598 + spin_unlock(&br->br_dykey_lock);
12599 + BUG_ON(i == AuBrDynOp); /* expand the array */
12605 +/* kref_get() if @key is already added */
12606 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12608 + struct au_dykey *tmp, *found;
12609 + struct hlist_bl_node *pos;
12610 + const void *h_op = key->dk_op.dy_hop;
12613 + hlist_bl_lock(hbl);
12614 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12615 + if (tmp->dk_op.dy_hop == h_op) {
12616 + kref_get(&tmp->dk_kref);
12621 + hlist_bl_add_head(&key->dk_hnode, hbl);
12622 + hlist_bl_unlock(hbl);
12629 +static void dy_free_rcu(struct rcu_head *rcu)
12631 + struct au_dykey *key;
12633 + key = container_of(rcu, struct au_dykey, dk_rcu);
12635 + au_kfree_rcu(key);
12638 +static void dy_free(struct kref *kref)
12640 + struct au_dykey *key;
12641 + struct hlist_bl_head *hbl;
12643 + key = container_of(kref, struct au_dykey, dk_kref);
12644 + hbl = dynop + key->dk_op.dy_type;
12645 + au_hbl_del(&key->dk_hnode, hbl);
12646 + call_rcu(&key->dk_rcu, dy_free_rcu);
12649 +void au_dy_put(struct au_dykey *key)
12651 + kref_put(&key->dk_kref, dy_free);
12654 +/* ---------------------------------------------------------------------- */
12656 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12658 +#ifdef CONFIG_AUFS_DEBUG
12659 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12660 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12662 +#define DyDbgDeclare(cnt) do {} while (0)
12663 +#define DyDbgInc(cnt) do {} while (0)
12666 +#define DySet(func, dst, src, h_op, h_sb) do { \
12668 + if (h_op->func) { \
12670 + dst.func = src.func; \
12672 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12676 +#define DySetForce(func, dst, src) do { \
12677 + AuDebugOn(!src.func); \
12679 + dst.func = src.func; \
12682 +#define DySetAop(func) \
12683 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12684 +#define DySetAopForce(func) \
12685 + DySetForce(func, dyaop->da_op, aufs_aop)
12687 +static void dy_aop(struct au_dykey *key, const void *h_op,
12688 + struct super_block *h_sb __maybe_unused)
12690 + struct au_dyaop *dyaop = (void *)key;
12691 + const struct address_space_operations *h_aop = h_op;
12692 + DyDbgDeclare(cnt);
12694 + AuDbg("%s\n", au_sbtype(h_sb));
12696 + DySetAop(writepage);
12697 + DySetAopForce(readpage); /* force */
12698 + DySetAop(writepages);
12699 + DySetAop(set_page_dirty);
12700 + DySetAop(readpages);
12701 + DySetAop(write_begin);
12702 + DySetAop(write_end);
12704 + DySetAop(invalidatepage);
12705 + DySetAop(releasepage);
12706 + DySetAop(freepage);
12707 + /* this one will be changed according to an aufs mount option */
12708 + DySetAop(direct_IO);
12709 + DySetAop(migratepage);
12710 + DySetAop(isolate_page);
12711 + DySetAop(putback_page);
12712 + DySetAop(launder_page);
12713 + DySetAop(is_partially_uptodate);
12714 + DySetAop(is_dirty_writeback);
12715 + DySetAop(error_remove_page);
12716 + DySetAop(swap_activate);
12717 + DySetAop(swap_deactivate);
12719 + DyDbgSize(cnt, *h_aop);
12722 +/* ---------------------------------------------------------------------- */
12724 +static void dy_bug(struct kref *kref)
12729 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12731 + struct au_dykey *key, *old;
12732 + struct hlist_bl_head *hbl;
12735 + void (*set)(struct au_dykey *key, const void *h_op,
12736 + struct super_block *h_sb __maybe_unused);
12738 + static const struct op a[] = {
12740 + .sz = sizeof(struct au_dyaop),
12744 + const struct op *p;
12746 + hbl = dynop + op->dy_type;
12747 + key = dy_gfind_get(hbl, op->dy_hop);
12749 + goto out_add; /* success */
12751 + p = a + op->dy_type;
12752 + key = kzalloc(p->sz, GFP_NOFS);
12753 + if (unlikely(!key)) {
12754 + key = ERR_PTR(-ENOMEM);
12758 + key->dk_op.dy_hop = op->dy_hop;
12759 + kref_init(&key->dk_kref);
12760 + p->set(key, op->dy_hop, au_br_sb(br));
12761 + old = dy_gadd(hbl, key);
12763 + au_kfree_rcu(key);
12768 + old = dy_bradd(br, key);
12770 + /* its ref-count should never be zero here */
12771 + kref_put(&key->dk_kref, dy_bug);
12776 +/* ---------------------------------------------------------------------- */
12778 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12779 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12780 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12781 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12782 + * See the aufs manual in detail.
12784 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12787 + dyaop->da_op.direct_IO = NULL;
12789 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12792 +static struct au_dyaop *dy_aget(struct au_branch *br,
12793 + const struct address_space_operations *h_aop,
12796 + struct au_dyaop *dyaop;
12797 + struct au_dynop op;
12799 + op.dy_type = AuDy_AOP;
12800 + op.dy_haop = h_aop;
12801 + dyaop = (void *)dy_get(&op, br);
12802 + if (IS_ERR(dyaop))
12804 + dy_adx(dyaop, do_dx);
12810 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12811 + struct inode *h_inode)
12814 + struct super_block *sb;
12815 + struct au_branch *br;
12816 + struct au_dyaop *dyaop;
12818 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12819 + IiMustWriteLock(inode);
12821 + sb = inode->i_sb;
12822 + br = au_sbr(sb, bindex);
12823 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12824 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12825 + err = PTR_ERR(dyaop);
12826 + if (IS_ERR(dyaop))
12827 + /* unnecessary to call dy_fput() */
12831 + inode->i_mapping->a_ops = &dyaop->da_op;
12838 + * Is it safe to replace a_ops during the inode/file is in operation?
12839 + * Yes, I hope so.
12841 +int au_dy_irefresh(struct inode *inode)
12844 + aufs_bindex_t btop;
12845 + struct inode *h_inode;
12848 + if (S_ISREG(inode->i_mode)) {
12849 + btop = au_ibtop(inode);
12850 + h_inode = au_h_iptr(inode, btop);
12851 + err = au_dy_iaop(inode, btop, h_inode);
12856 +void au_dy_arefresh(int do_dx)
12858 + struct hlist_bl_head *hbl;
12859 + struct hlist_bl_node *pos;
12860 + struct au_dykey *key;
12862 + hbl = dynop + AuDy_AOP;
12863 + hlist_bl_lock(hbl);
12864 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12865 + dy_adx((void *)key, do_dx);
12866 + hlist_bl_unlock(hbl);
12869 +/* ---------------------------------------------------------------------- */
12871 +void __init au_dy_init(void)
12875 + /* make sure that 'struct au_dykey *' can be any type */
12876 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
12878 + for (i = 0; i < AuDyLast; i++)
12879 + INIT_HLIST_BL_HEAD(dynop + i);
12882 +void au_dy_fin(void)
12886 + for (i = 0; i < AuDyLast; i++)
12887 + WARN_ON(!hlist_bl_empty(dynop + i));
12889 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12890 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12891 +++ linux/fs/aufs/dynop.h 2019-03-05 12:13:00.139224339 +0100
12893 +/* SPDX-License-Identifier: GPL-2.0 */
12895 + * Copyright (C) 2010-2019 Junjiro R. Okajima
12897 + * This program, aufs is free software; you can redistribute it and/or modify
12898 + * it under the terms of the GNU General Public License as published by
12899 + * the Free Software Foundation; either version 2 of the License, or
12900 + * (at your option) any later version.
12902 + * This program is distributed in the hope that it will be useful,
12903 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12904 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12905 + * GNU General Public License for more details.
12907 + * You should have received a copy of the GNU General Public License
12908 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12912 + * dynamically customizable operations (for regular files only)
12915 +#ifndef __AUFS_DYNOP_H__
12916 +#define __AUFS_DYNOP_H__
12920 +#include <linux/fs.h>
12921 +#include <linux/kref.h>
12923 +enum {AuDy_AOP, AuDyLast};
12928 + const void *dy_hop;
12929 + const struct address_space_operations *dy_haop;
12935 + struct hlist_bl_node dk_hnode;
12936 + struct rcu_head dk_rcu;
12938 + struct au_dynop dk_op;
12941 + * during I am in the branch local array, kref is gotten. when the
12942 + * branch is removed, kref is put.
12944 + struct kref dk_kref;
12947 +/* stop unioning since their sizes are very different from each other */
12949 + struct au_dykey da_key;
12950 + struct address_space_operations da_op; /* not const */
12953 +/* ---------------------------------------------------------------------- */
12957 +void au_dy_put(struct au_dykey *key);
12958 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12959 + struct inode *h_inode);
12960 +int au_dy_irefresh(struct inode *inode);
12961 +void au_dy_arefresh(int do_dio);
12963 +void __init au_dy_init(void);
12964 +void au_dy_fin(void);
12966 +#endif /* __KERNEL__ */
12967 +#endif /* __AUFS_DYNOP_H__ */
12968 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12969 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12970 +++ linux/fs/aufs/export.c 2019-03-05 12:13:00.139224339 +0100
12972 +// SPDX-License-Identifier: GPL-2.0
12974 + * Copyright (C) 2005-2019 Junjiro R. Okajima
12976 + * This program, aufs is free software; you can redistribute it and/or modify
12977 + * it under the terms of the GNU General Public License as published by
12978 + * the Free Software Foundation; either version 2 of the License, or
12979 + * (at your option) any later version.
12981 + * This program is distributed in the hope that it will be useful,
12982 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12983 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12984 + * GNU General Public License for more details.
12986 + * You should have received a copy of the GNU General Public License
12987 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12994 +#include <linux/exportfs.h>
12995 +#include <linux/fs_struct.h>
12996 +#include <linux/namei.h>
12997 +#include <linux/nsproxy.h>
12998 +#include <linux/random.h>
12999 +#include <linux/writeback.h>
13003 +#ifdef CONFIG_AUFS_INO_T_64
13011 +static ino_t decode_ino(__u32 *a)
13015 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
13017 +#ifdef CONFIG_AUFS_INO_T_64
13023 +static void encode_ino(__u32 *a, ino_t ino)
13029 +#ifdef CONFIG_AUFS_INO_T_64
13034 +/* NFS file handle */
13038 +#ifdef CONFIG_AUFS_INO_T_64
13039 + /* support 64bit inode number */
13052 + Fh_ino = Fh_ino1,
13053 + Fh_dir_ino = Fh_dir_ino1
13056 +static int au_test_anon(struct dentry *dentry)
13058 + /* note: read d_flags without d_lock */
13059 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
13062 +int au_test_nfsd(void)
13065 + struct task_struct *tsk = current;
13066 + char comm[sizeof(tsk->comm)];
13069 + if (tsk->flags & PF_KTHREAD) {
13070 + get_task_comm(comm, tsk);
13071 + ret = !strcmp(comm, "nfsd");
13077 +/* ---------------------------------------------------------------------- */
13078 +/* inode generation external table */
13080 +void au_xigen_inc(struct inode *inode)
13085 + struct super_block *sb;
13086 + struct au_sbinfo *sbinfo;
13088 + sb = inode->i_sb;
13089 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
13091 + sbinfo = au_sbi(sb);
13092 + pos = inode->i_ino;
13093 + pos *= sizeof(igen);
13094 + igen = inode->i_generation + 1;
13095 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
13096 + sizeof(igen), &pos);
13097 + if (sz == sizeof(igen))
13098 + return; /* success */
13100 + if (unlikely(sz >= 0))
13101 + AuIOErr("xigen error (%zd)\n", sz);
13104 +int au_xigen_new(struct inode *inode)
13109 + struct super_block *sb;
13110 + struct au_sbinfo *sbinfo;
13111 + struct file *file;
13114 + /* todo: dirty, at mount time */
13115 + if (inode->i_ino == AUFS_ROOT_INO)
13117 + sb = inode->i_sb;
13118 + SiMustAnyLock(sb);
13119 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13123 + pos = inode->i_ino;
13124 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
13125 + AuIOErr1("too large i%lld\n", pos);
13128 + pos *= sizeof(inode->i_generation);
13131 + sbinfo = au_sbi(sb);
13132 + file = sbinfo->si_xigen;
13135 + if (vfsub_f_size_read(file)
13136 + < pos + sizeof(inode->i_generation)) {
13137 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
13138 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
13139 + sizeof(inode->i_generation), &pos);
13141 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
13142 + sizeof(inode->i_generation), &pos);
13143 + if (sz == sizeof(inode->i_generation))
13144 + goto out; /* success */
13147 + if (unlikely(sz >= 0)) {
13149 + AuIOErr("xigen error (%zd)\n", sz);
13156 +int au_xigen_set(struct super_block *sb, struct path *path)
13159 + struct au_sbinfo *sbinfo;
13160 + struct file *file;
13162 + SiMustWriteLock(sb);
13164 + sbinfo = au_sbi(sb);
13165 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
13166 + err = PTR_ERR(file);
13167 + if (IS_ERR(file))
13170 + if (sbinfo->si_xigen)
13171 + fput(sbinfo->si_xigen);
13172 + sbinfo->si_xigen = file;
13179 +void au_xigen_clr(struct super_block *sb)
13181 + struct au_sbinfo *sbinfo;
13183 + SiMustWriteLock(sb);
13185 + sbinfo = au_sbi(sb);
13186 + if (sbinfo->si_xigen) {
13187 + fput(sbinfo->si_xigen);
13188 + sbinfo->si_xigen = NULL;
13192 +/* ---------------------------------------------------------------------- */
13194 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13197 + struct dentry *dentry, *d;
13198 + struct inode *inode;
13199 + unsigned int sigen;
13202 + inode = ilookup(sb, ino);
13206 + dentry = ERR_PTR(-ESTALE);
13207 + sigen = au_sigen(sb);
13208 + if (unlikely(au_is_bad_inode(inode)
13209 + || IS_DEADDIR(inode)
13210 + || sigen != au_iigen(inode, NULL)))
13214 + if (!dir_ino || S_ISDIR(inode->i_mode))
13215 + dentry = d_find_alias(inode);
13217 + spin_lock(&inode->i_lock);
13218 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13219 + spin_lock(&d->d_lock);
13220 + if (!au_test_anon(d)
13221 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13222 + dentry = dget_dlock(d);
13223 + spin_unlock(&d->d_lock);
13226 + spin_unlock(&d->d_lock);
13228 + spin_unlock(&inode->i_lock);
13230 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13231 + /* need to refresh */
13239 + AuTraceErrPtr(dentry);
13243 +/* ---------------------------------------------------------------------- */
13245 +/* todo: dirty? */
13246 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13248 +struct au_compare_mnt_args {
13250 + struct super_block *sb;
13253 + struct vfsmount *mnt;
13256 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13258 + struct au_compare_mnt_args *a = arg;
13260 + if (mnt->mnt_sb != a->sb)
13262 + a->mnt = mntget(mnt);
13266 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13269 + struct path root;
13270 + struct au_compare_mnt_args args = {
13274 + get_fs_root(current->fs, &root);
13276 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13277 + rcu_read_unlock();
13280 + AuDebugOn(!args.mnt);
13284 +struct au_nfsd_si_lock {
13285 + unsigned int sigen;
13286 + aufs_bindex_t bindex, br_id;
13287 + unsigned char force_lock;
13290 +static int si_nfsd_read_lock(struct super_block *sb,
13291 + struct au_nfsd_si_lock *nsi_lock)
13294 + aufs_bindex_t bindex;
13296 + si_read_lock(sb, AuLock_FLUSH);
13298 + /* branch id may be wrapped around */
13300 + bindex = au_br_index(sb, nsi_lock->br_id);
13301 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13302 + goto out; /* success */
13306 + if (!nsi_lock->force_lock)
13307 + si_read_unlock(sb);
13310 + nsi_lock->bindex = bindex;
13314 +struct find_name_by_ino {
13315 + struct dir_context ctx;
13316 + int called, found;
13323 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13324 + loff_t offset, u64 ino, unsigned int d_type)
13326 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13330 + if (a->ino != ino)
13333 + memcpy(a->name, name, namelen);
13334 + a->namelen = namelen;
13339 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13340 + struct au_nfsd_si_lock *nsi_lock)
13342 + struct dentry *dentry, *parent;
13343 + struct file *file;
13344 + struct inode *dir;
13345 + struct find_name_by_ino arg = {
13347 + .actor = find_name_by_ino
13352 + parent = path->dentry;
13354 + si_read_unlock(parent->d_sb);
13355 + file = vfsub_dentry_open(path, au_dir_roflags);
13356 + dentry = (void *)file;
13357 + if (IS_ERR(file))
13360 + dentry = ERR_PTR(-ENOMEM);
13361 + arg.name = (void *)__get_free_page(GFP_NOFS);
13362 + if (unlikely(!arg.name))
13369 + err = vfsub_iterate_dir(file, &arg.ctx);
13370 + } while (!err && !arg.found && arg.called);
13371 + dentry = ERR_PTR(err);
13372 + if (unlikely(err))
13374 + /* instead of ENOENT */
13375 + dentry = ERR_PTR(-ESTALE);
13379 + /* do not call vfsub_lkup_one() */
13380 + dir = d_inode(parent);
13381 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13382 + AuTraceErrPtr(dentry);
13383 + if (IS_ERR(dentry))
13385 + AuDebugOn(au_test_anon(dentry));
13386 + if (unlikely(d_really_is_negative(dentry))) {
13388 + dentry = ERR_PTR(-ENOENT);
13392 + free_page((unsigned long)arg.name);
13396 + if (unlikely(nsi_lock
13397 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13398 + if (!IS_ERR(dentry)) {
13400 + dentry = ERR_PTR(-ESTALE);
13402 + AuTraceErrPtr(dentry);
13406 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13408 + struct au_nfsd_si_lock *nsi_lock)
13410 + struct dentry *dentry;
13411 + struct path path;
13413 + if (dir_ino != AUFS_ROOT_INO) {
13414 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13415 + dentry = path.dentry;
13416 + if (!path.dentry || IS_ERR(path.dentry))
13418 + AuDebugOn(au_test_anon(path.dentry));
13420 + path.dentry = dget(sb->s_root);
13422 + path.mnt = au_mnt_get(sb);
13423 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13427 + AuTraceErrPtr(dentry);
13431 +/* ---------------------------------------------------------------------- */
13433 +static int h_acceptable(void *expv, struct dentry *dentry)
13438 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13439 + char *buf, int len, struct super_block *sb)
13443 + struct path path;
13445 + p = d_path(h_rootpath, buf, len);
13450 + path.mnt = h_rootpath->mnt;
13451 + path.dentry = h_parent;
13452 + p = d_path(&path, buf, len);
13458 + path.mnt = au_mnt_get(sb);
13459 + path.dentry = sb->s_root;
13460 + p = d_path(&path, buf, len - strlen(p));
13461 + mntput(path.mnt);
13465 + p[strlen(p)] = '/';
13468 + AuTraceErrPtr(p);
13473 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13474 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13476 + struct dentry *dentry, *h_parent, *root;
13477 + struct super_block *h_sb;
13478 + char *pathname, *p;
13479 + struct vfsmount *h_mnt;
13480 + struct au_branch *br;
13482 + struct path path;
13484 + br = au_sbr(sb, nsi_lock->bindex);
13485 + h_mnt = au_br_mnt(br);
13486 + h_sb = h_mnt->mnt_sb;
13487 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13489 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13490 + fh_len - Fh_tail, fh[Fh_h_type],
13491 + h_acceptable, /*context*/NULL);
13493 + dentry = h_parent;
13494 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13495 + AuWarn1("%s decode_fh failed, %ld\n",
13496 + au_sbtype(h_sb), PTR_ERR(h_parent));
13500 + if (unlikely(au_test_anon(h_parent))) {
13501 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13502 + au_sbtype(h_sb));
13503 + goto out_h_parent;
13506 + dentry = ERR_PTR(-ENOMEM);
13507 + pathname = (void *)__get_free_page(GFP_NOFS);
13508 + if (unlikely(!pathname))
13509 + goto out_h_parent;
13511 + root = sb->s_root;
13512 + path.mnt = h_mnt;
13513 + di_read_lock_parent(root, !AuLock_IR);
13514 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13515 + di_read_unlock(root, !AuLock_IR);
13516 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13517 + dentry = (void *)p;
13519 + goto out_pathname;
13521 + si_read_unlock(sb);
13522 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13523 + dentry = ERR_PTR(err);
13524 + if (unlikely(err))
13527 + dentry = ERR_PTR(-ENOENT);
13528 + AuDebugOn(au_test_anon(path.dentry));
13529 + if (unlikely(d_really_is_negative(path.dentry)))
13532 + if (ino != d_inode(path.dentry)->i_ino)
13533 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13535 + dentry = dget(path.dentry);
13540 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13541 + if (!IS_ERR(dentry)) {
13543 + dentry = ERR_PTR(-ESTALE);
13546 + free_page((unsigned long)pathname);
13550 + AuTraceErrPtr(dentry);
13554 +/* ---------------------------------------------------------------------- */
13556 +static struct dentry *
13557 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13560 + struct dentry *dentry;
13561 + __u32 *fh = fid->raw;
13562 + struct au_branch *br;
13563 + ino_t ino, dir_ino;
13564 + struct au_nfsd_si_lock nsi_lock = {
13568 + dentry = ERR_PTR(-ESTALE);
13569 + /* it should never happen, but the file handle is unreliable */
13570 + if (unlikely(fh_len < Fh_tail))
13572 + nsi_lock.sigen = fh[Fh_sigen];
13573 + nsi_lock.br_id = fh[Fh_br_id];
13575 + /* branch id may be wrapped around */
13577 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13579 + nsi_lock.force_lock = 1;
13581 + /* is this inode still cached? */
13582 + ino = decode_ino(fh + Fh_ino);
13583 + /* it should never happen */
13584 + if (unlikely(ino == AUFS_ROOT_INO))
13587 + dir_ino = decode_ino(fh + Fh_dir_ino);
13588 + dentry = decode_by_ino(sb, ino, dir_ino);
13589 + if (IS_ERR(dentry))
13594 + /* is the parent dir cached? */
13595 + br = au_sbr(sb, nsi_lock.bindex);
13596 + au_lcnt_inc(&br->br_nfiles);
13597 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13598 + if (IS_ERR(dentry))
13603 + /* lookup path */
13604 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13605 + if (IS_ERR(dentry))
13607 + if (unlikely(!dentry))
13608 + /* todo?: make it ESTALE */
13612 + if (!au_digen_test(dentry, au_sigen(sb))
13613 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13614 + goto out_unlock; /* success */
13617 + dentry = ERR_PTR(-ESTALE);
13620 + au_lcnt_dec(&br->br_nfiles);
13621 + si_read_unlock(sb);
13623 + AuTraceErrPtr(dentry);
13627 +#if 0 /* reserved for future use */
13628 +/* support subtreecheck option */
13629 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13630 + int fh_len, int fh_type)
13632 + struct dentry *parent;
13633 + __u32 *fh = fid->raw;
13636 + dir_ino = decode_ino(fh + Fh_dir_ino);
13637 + parent = decode_by_ino(sb, dir_ino, 0);
13638 + if (IS_ERR(parent))
13641 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13642 + dir_ino, fh, fh_len);
13645 + AuTraceErrPtr(parent);
13650 +/* ---------------------------------------------------------------------- */
13652 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13653 + struct inode *dir)
13656 + aufs_bindex_t bindex;
13657 + struct super_block *sb, *h_sb;
13658 + struct dentry *dentry, *parent, *h_parent;
13659 + struct inode *h_dir;
13660 + struct au_branch *br;
13663 + if (unlikely(*max_len <= Fh_tail)) {
13664 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13668 + err = FILEID_ROOT;
13669 + if (inode->i_ino == AUFS_ROOT_INO) {
13670 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13675 + sb = inode->i_sb;
13676 + err = si_read_lock(sb, AuLock_FLUSH);
13677 + if (unlikely(err))
13680 +#ifdef CONFIG_AUFS_DEBUG
13681 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13682 + AuWarn1("NFS-exporting requires xino\n");
13686 + ii_read_lock_child(inode);
13687 + bindex = au_ibtop(inode);
13689 + dentry = d_find_any_alias(inode);
13690 + if (unlikely(!dentry))
13692 + AuDebugOn(au_test_anon(dentry));
13693 + parent = dget_parent(dentry);
13695 + if (unlikely(!parent))
13697 + if (d_really_is_positive(parent))
13698 + dir = d_inode(parent);
13701 + ii_read_lock_parent(dir);
13702 + h_dir = au_h_iptr(dir, bindex);
13703 + ii_read_unlock(dir);
13704 + if (unlikely(!h_dir))
13706 + h_parent = d_find_any_alias(h_dir);
13707 + if (unlikely(!h_parent))
13708 + goto out_hparent;
13711 + br = au_sbr(sb, bindex);
13712 + h_sb = au_br_sb(br);
13713 + if (unlikely(!h_sb->s_export_op)) {
13714 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13715 + goto out_hparent;
13718 + fh[Fh_br_id] = br->br_id;
13719 + fh[Fh_sigen] = au_sigen(sb);
13720 + encode_ino(fh + Fh_ino, inode->i_ino);
13721 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13722 + fh[Fh_igen] = inode->i_generation;
13724 + *max_len -= Fh_tail;
13725 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13727 + /*connectable or subtreecheck*/0);
13728 + err = fh[Fh_h_type];
13729 + *max_len += Fh_tail;
13730 + /* todo: macros? */
13731 + if (err != FILEID_INVALID)
13734 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13741 + ii_read_unlock(inode);
13742 + si_read_unlock(sb);
13744 + if (unlikely(err < 0))
13745 + err = FILEID_INVALID;
13749 +/* ---------------------------------------------------------------------- */
13751 +static int aufs_commit_metadata(struct inode *inode)
13754 + aufs_bindex_t bindex;
13755 + struct super_block *sb;
13756 + struct inode *h_inode;
13757 + int (*f)(struct inode *inode);
13759 + sb = inode->i_sb;
13760 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13761 + ii_write_lock_child(inode);
13762 + bindex = au_ibtop(inode);
13763 + AuDebugOn(bindex < 0);
13764 + h_inode = au_h_iptr(inode, bindex);
13766 + f = h_inode->i_sb->s_export_op->commit_metadata;
13768 + err = f(h_inode);
13770 + struct writeback_control wbc = {
13771 + .sync_mode = WB_SYNC_ALL,
13772 + .nr_to_write = 0 /* metadata only */
13775 + err = sync_inode(h_inode, &wbc);
13778 + au_cpup_attr_timesizes(inode);
13779 + ii_write_unlock(inode);
13780 + si_read_unlock(sb);
13784 +/* ---------------------------------------------------------------------- */
13786 +static struct export_operations aufs_export_op = {
13787 + .fh_to_dentry = aufs_fh_to_dentry,
13788 + /* .fh_to_parent = aufs_fh_to_parent, */
13789 + .encode_fh = aufs_encode_fh,
13790 + .commit_metadata = aufs_commit_metadata
13793 +void au_export_init(struct super_block *sb)
13795 + struct au_sbinfo *sbinfo;
13798 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13799 + && IS_MODULE(CONFIG_EXPORTFS),
13800 + AUFS_NAME ": unsupported configuration "
13801 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13803 + sb->s_export_op = &aufs_export_op;
13804 + sbinfo = au_sbi(sb);
13805 + sbinfo->si_xigen = NULL;
13806 + get_random_bytes(&u, sizeof(u));
13807 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13808 + atomic_set(&sbinfo->si_xigen_next, u);
13810 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13811 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13812 +++ linux/fs/aufs/fhsm.c 2019-03-05 12:13:00.139224339 +0100
13814 +// SPDX-License-Identifier: GPL-2.0
13816 + * Copyright (C) 2011-2019 Junjiro R. Okajima
13818 + * This program, aufs is free software; you can redistribute it and/or modify
13819 + * it under the terms of the GNU General Public License as published by
13820 + * the Free Software Foundation; either version 2 of the License, or
13821 + * (at your option) any later version.
13823 + * This program is distributed in the hope that it will be useful,
13824 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13825 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13826 + * GNU General Public License for more details.
13828 + * You should have received a copy of the GNU General Public License
13829 + * along with this program; if not, write to the Free Software
13830 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13834 + * File-based Hierarchy Storage Management
13837 +#include <linux/anon_inodes.h>
13838 +#include <linux/poll.h>
13839 +#include <linux/seq_file.h>
13840 +#include <linux/statfs.h>
13843 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13845 + struct au_sbinfo *sbinfo;
13846 + struct au_fhsm *fhsm;
13848 + SiMustAnyLock(sb);
13850 + sbinfo = au_sbi(sb);
13851 + fhsm = &sbinfo->si_fhsm;
13852 + AuDebugOn(!fhsm);
13853 + return fhsm->fhsm_bottom;
13856 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13858 + struct au_sbinfo *sbinfo;
13859 + struct au_fhsm *fhsm;
13861 + SiMustWriteLock(sb);
13863 + sbinfo = au_sbi(sb);
13864 + fhsm = &sbinfo->si_fhsm;
13865 + AuDebugOn(!fhsm);
13866 + fhsm->fhsm_bottom = bindex;
13869 +/* ---------------------------------------------------------------------- */
13871 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13873 + struct au_br_fhsm *bf;
13875 + bf = br->br_fhsm;
13876 + MtxMustLock(&bf->bf_lock);
13878 + return !bf->bf_readable
13879 + || time_after(jiffies,
13880 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13883 +/* ---------------------------------------------------------------------- */
13885 +static void au_fhsm_notify(struct super_block *sb, int val)
13887 + struct au_sbinfo *sbinfo;
13888 + struct au_fhsm *fhsm;
13890 + SiMustAnyLock(sb);
13892 + sbinfo = au_sbi(sb);
13893 + fhsm = &sbinfo->si_fhsm;
13894 + if (au_fhsm_pid(fhsm)
13895 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13896 + atomic_set(&fhsm->fhsm_readable, val);
13898 + wake_up(&fhsm->fhsm_wqh);
13902 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13903 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13906 + struct au_branch *br;
13907 + struct au_br_fhsm *bf;
13909 + br = au_sbr(sb, bindex);
13910 + AuDebugOn(au_br_rdonly(br));
13911 + bf = br->br_fhsm;
13915 + mutex_lock(&bf->bf_lock);
13917 + MtxMustLock(&bf->bf_lock);
13919 + /* sb->s_root for NFS is unreliable */
13920 + err = au_br_stfs(br, &bf->bf_stfs);
13921 + if (unlikely(err)) {
13922 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13926 + bf->bf_jiffy = jiffies;
13927 + bf->bf_readable = 1;
13929 + au_fhsm_notify(sb, /*val*/1);
13931 + *rstfs = bf->bf_stfs;
13935 + mutex_unlock(&bf->bf_lock);
13936 + au_fhsm_notify(sb, /*val*/1);
13941 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13944 + struct au_sbinfo *sbinfo;
13945 + struct au_fhsm *fhsm;
13946 + struct au_branch *br;
13947 + struct au_br_fhsm *bf;
13949 + AuDbg("b%d, force %d\n", bindex, force);
13950 + SiMustAnyLock(sb);
13952 + sbinfo = au_sbi(sb);
13953 + fhsm = &sbinfo->si_fhsm;
13954 + if (!au_ftest_si(sbinfo, FHSM)
13955 + || fhsm->fhsm_bottom == bindex)
13958 + br = au_sbr(sb, bindex);
13959 + bf = br->br_fhsm;
13961 + mutex_lock(&bf->bf_lock);
13963 + || au_fhsm_pid(fhsm)
13964 + || au_fhsm_test_jiffy(sbinfo, br))
13965 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13967 + mutex_unlock(&bf->bf_lock);
13970 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13972 + aufs_bindex_t bindex, bbot;
13973 + struct au_branch *br;
13975 + /* exclude the bottom */
13976 + bbot = au_fhsm_bottom(sb);
13977 + for (bindex = 0; bindex < bbot; bindex++) {
13978 + br = au_sbr(sb, bindex);
13979 + if (au_br_fhsm(br->br_perm))
13980 + au_fhsm_wrote(sb, bindex, force);
13984 +/* ---------------------------------------------------------------------- */
13986 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13989 + struct au_sbinfo *sbinfo;
13990 + struct au_fhsm *fhsm;
13993 + sbinfo = file->private_data;
13994 + fhsm = &sbinfo->si_fhsm;
13995 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13996 + if (atomic_read(&fhsm->fhsm_readable))
13997 + mask = EPOLLIN /* | EPOLLRDNORM */;
14000 + AuDbg("mask 0x%x\n", mask);
14004 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
14005 + struct aufs_stfs *stfs, __s16 brid)
14009 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
14011 + err = __put_user(brid, &stbr->brid);
14012 + if (unlikely(err))
14018 +static ssize_t au_fhsm_do_read(struct super_block *sb,
14019 + struct aufs_stbr __user *stbr, size_t count)
14023 + aufs_bindex_t bindex, bbot;
14024 + struct au_branch *br;
14025 + struct au_br_fhsm *bf;
14027 + /* except the bottom branch */
14030 + bbot = au_fhsm_bottom(sb);
14031 + for (bindex = 0; !err && bindex < bbot; bindex++) {
14032 + br = au_sbr(sb, bindex);
14033 + if (!au_br_fhsm(br->br_perm))
14036 + bf = br->br_fhsm;
14037 + mutex_lock(&bf->bf_lock);
14038 + if (bf->bf_readable) {
14040 + if (count >= sizeof(*stbr))
14041 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
14044 + bf->bf_readable = 0;
14045 + count -= sizeof(*stbr);
14049 + mutex_unlock(&bf->bf_lock);
14052 + err = sizeof(*stbr) * nstbr;
14057 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
14062 + aufs_bindex_t nfhsm, bindex, bbot;
14063 + struct au_sbinfo *sbinfo;
14064 + struct au_fhsm *fhsm;
14065 + struct au_branch *br;
14066 + struct super_block *sb;
14069 + sbinfo = file->private_data;
14070 + fhsm = &sbinfo->si_fhsm;
14072 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
14073 + if (!atomic_read(&fhsm->fhsm_readable)) {
14074 + if (vfsub_file_flags(file) & O_NONBLOCK)
14077 + err = wait_event_interruptible_locked_irq
14079 + atomic_read(&fhsm->fhsm_readable));
14081 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
14082 + if (unlikely(err))
14085 + /* sb may already be dead */
14086 + au_rw_read_lock(&sbinfo->si_rwsem);
14087 + readable = atomic_read(&fhsm->fhsm_readable);
14088 + if (readable > 0) {
14089 + sb = sbinfo->si_sb;
14091 + /* exclude the bottom branch */
14093 + bbot = au_fhsm_bottom(sb);
14094 + for (bindex = 0; bindex < bbot; bindex++) {
14095 + br = au_sbr(sb, bindex);
14096 + if (au_br_fhsm(br->br_perm))
14100 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
14101 + atomic_set(&fhsm->fhsm_readable, 0);
14102 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
14106 + au_rw_read_unlock(&sbinfo->si_rwsem);
14114 +static int au_fhsm_release(struct inode *inode, struct file *file)
14116 + struct au_sbinfo *sbinfo;
14117 + struct au_fhsm *fhsm;
14119 + /* sb may already be dead */
14120 + sbinfo = file->private_data;
14121 + fhsm = &sbinfo->si_fhsm;
14122 + spin_lock(&fhsm->fhsm_spin);
14123 + fhsm->fhsm_pid = 0;
14124 + spin_unlock(&fhsm->fhsm_spin);
14125 + kobject_put(&sbinfo->si_kobj);
14130 +static const struct file_operations au_fhsm_fops = {
14131 + .owner = THIS_MODULE,
14132 + .llseek = noop_llseek,
14133 + .read = au_fhsm_read,
14134 + .poll = au_fhsm_poll,
14135 + .release = au_fhsm_release
14138 +int au_fhsm_fd(struct super_block *sb, int oflags)
14141 + struct au_sbinfo *sbinfo;
14142 + struct au_fhsm *fhsm;
14145 + if (unlikely(!capable(CAP_SYS_ADMIN)))
14149 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
14153 + sbinfo = au_sbi(sb);
14154 + fhsm = &sbinfo->si_fhsm;
14155 + spin_lock(&fhsm->fhsm_spin);
14156 + if (!fhsm->fhsm_pid)
14157 + fhsm->fhsm_pid = current->pid;
14160 + spin_unlock(&fhsm->fhsm_spin);
14161 + if (unlikely(err))
14164 + oflags |= O_RDONLY;
14165 + /* oflags |= FMODE_NONOTIFY; */
14166 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
14168 + if (unlikely(fd < 0))
14171 + /* succeed regardless 'fhsm' status */
14172 + kobject_get(&sbinfo->si_kobj);
14173 + si_noflush_read_lock(sb);
14174 + if (au_ftest_si(sbinfo, FHSM))
14175 + au_fhsm_wrote_all(sb, /*force*/0);
14176 + si_read_unlock(sb);
14177 + goto out; /* success */
14180 + spin_lock(&fhsm->fhsm_spin);
14181 + fhsm->fhsm_pid = 0;
14182 + spin_unlock(&fhsm->fhsm_spin);
14188 +/* ---------------------------------------------------------------------- */
14190 +int au_fhsm_br_alloc(struct au_branch *br)
14195 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14197 + au_br_fhsm_init(br->br_fhsm);
14204 +/* ---------------------------------------------------------------------- */
14206 +void au_fhsm_fin(struct super_block *sb)
14208 + au_fhsm_notify(sb, /*val*/-1);
14211 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14213 + struct au_fhsm *fhsm;
14215 + fhsm = &sbinfo->si_fhsm;
14216 + spin_lock_init(&fhsm->fhsm_spin);
14217 + init_waitqueue_head(&fhsm->fhsm_wqh);
14218 + atomic_set(&fhsm->fhsm_readable, 0);
14219 + fhsm->fhsm_expire
14220 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14221 + fhsm->fhsm_bottom = -1;
14224 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14226 + sbinfo->si_fhsm.fhsm_expire
14227 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14230 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14234 + if (!au_ftest_si(sbinfo, FHSM))
14237 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14238 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14239 + seq_printf(seq, ",fhsm_sec=%u", u);
14241 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14242 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14243 +++ linux/fs/aufs/file.c 2019-03-05 12:13:00.139224339 +0100
14245 +// SPDX-License-Identifier: GPL-2.0
14247 + * Copyright (C) 2005-2019 Junjiro R. Okajima
14249 + * This program, aufs is free software; you can redistribute it and/or modify
14250 + * it under the terms of the GNU General Public License as published by
14251 + * the Free Software Foundation; either version 2 of the License, or
14252 + * (at your option) any later version.
14254 + * This program is distributed in the hope that it will be useful,
14255 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14256 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14257 + * GNU General Public License for more details.
14259 + * You should have received a copy of the GNU General Public License
14260 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14264 + * handling file/dir, and address_space operation
14267 +#ifdef CONFIG_AUFS_DEBUG
14268 +#include <linux/migrate.h>
14270 +#include <linux/pagemap.h>
14273 +/* drop flags for writing */
14274 +unsigned int au_file_roflags(unsigned int flags)
14276 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14277 + flags |= O_RDONLY | O_NOATIME;
14281 +/* common functions to regular file and dir */
14282 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14283 + struct file *file, int force_wr)
14285 + struct file *h_file;
14286 + struct dentry *h_dentry;
14287 + struct inode *h_inode;
14288 + struct super_block *sb;
14289 + struct au_branch *br;
14290 + struct path h_path;
14293 + /* a race condition can happen between open and unlink/rmdir */
14294 + h_file = ERR_PTR(-ENOENT);
14295 + h_dentry = au_h_dptr(dentry, bindex);
14296 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14298 + h_inode = d_inode(h_dentry);
14299 + spin_lock(&h_dentry->d_lock);
14300 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14301 + /* || !d_inode(dentry)->i_nlink */
14303 + spin_unlock(&h_dentry->d_lock);
14304 + if (unlikely(err))
14307 + sb = dentry->d_sb;
14308 + br = au_sbr(sb, bindex);
14309 + err = au_br_test_oflag(flags, br);
14310 + h_file = ERR_PTR(err);
14311 + if (unlikely(err))
14314 + /* drop flags for writing */
14315 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14316 + if (force_wr && !(flags & O_WRONLY))
14318 + flags = au_file_roflags(flags);
14320 + h_file = ERR_PTR(-EROFS);
14321 + flags = au_file_roflags(flags);
14322 + if (unlikely(vfsub_native_ro(h_inode)
14323 + || IS_APPEND(h_inode)))
14325 + flags &= ~O_ACCMODE;
14326 + flags |= O_WRONLY;
14329 + flags &= ~O_CREAT;
14330 + au_lcnt_inc(&br->br_nfiles);
14331 + h_path.dentry = h_dentry;
14332 + h_path.mnt = au_br_mnt(br);
14333 + h_file = vfsub_dentry_open(&h_path, flags);
14334 + if (IS_ERR(h_file))
14337 + if (flags & __FMODE_EXEC) {
14338 + err = deny_write_access(h_file);
14339 + if (unlikely(err)) {
14341 + h_file = ERR_PTR(err);
14345 + fsnotify_open(h_file);
14346 + goto out; /* success */
14349 + au_lcnt_dec(&br->br_nfiles);
14354 +static int au_cmoo(struct dentry *dentry)
14356 + int err, cmoo, matched;
14357 + unsigned int udba;
14358 + struct path h_path;
14359 + struct au_pin pin;
14360 + struct au_cp_generic cpg = {
14361 + .dentry = dentry,
14366 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14368 + struct inode *delegated;
14369 + struct super_block *sb;
14370 + struct au_sbinfo *sbinfo;
14371 + struct au_fhsm *fhsm;
14373 + struct au_branch *br;
14374 + struct dentry *parent;
14375 + struct au_hinode *hdir;
14377 + DiMustWriteLock(dentry);
14378 + IiMustWriteLock(d_inode(dentry));
14381 + if (IS_ROOT(dentry))
14383 + cpg.bsrc = au_dbtop(dentry);
14387 + sb = dentry->d_sb;
14388 + sbinfo = au_sbi(sb);
14389 + fhsm = &sbinfo->si_fhsm;
14390 + pid = au_fhsm_pid(fhsm);
14393 + && (current->pid == pid
14394 + || rcu_dereference(current->real_parent)->pid == pid));
14395 + rcu_read_unlock();
14399 + br = au_sbr(sb, cpg.bsrc);
14400 + cmoo = au_br_cmoo(br->br_perm);
14403 + if (!d_is_reg(dentry))
14404 + cmoo &= AuBrAttr_COO_ALL;
14408 + parent = dget_parent(dentry);
14409 + di_write_lock_parent(parent);
14410 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14412 + if (unlikely(err < 0)) {
14413 + err = 0; /* there is no upper writable branch */
14416 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14418 + /* do not respect the coo attrib for the target branch */
14419 + err = au_cpup_dirs(dentry, cpg.bdst);
14420 + if (unlikely(err))
14423 + di_downgrade_lock(parent, AuLock_IR);
14424 + udba = au_opt_udba(sb);
14425 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14426 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14427 + if (unlikely(err))
14430 + err = au_sio_cpup_simple(&cpg);
14432 + if (unlikely(err))
14434 + if (!(cmoo & AuBrWAttr_MOO))
14435 + goto out_parent; /* success */
14437 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14438 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14439 + if (unlikely(err))
14442 + h_path.mnt = au_br_mnt(br);
14443 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14444 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14445 + delegated = NULL;
14446 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14448 + /* todo: keep h_dentry or not? */
14449 + if (unlikely(err == -EWOULDBLOCK)) {
14450 + pr_warn("cannot retry for NFSv4 delegation"
14451 + " for an internal unlink\n");
14454 + if (unlikely(err)) {
14455 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14459 + goto out_parent; /* success */
14462 + di_downgrade_lock(parent, AuLock_IR);
14464 + di_read_unlock(parent, AuLock_IR);
14471 +int au_do_open(struct file *file, struct au_do_open_args *args)
14473 + int err, aopen = args->aopen;
14474 + struct dentry *dentry;
14475 + struct au_finfo *finfo;
14478 + err = au_finfo_init(file, args->fidir);
14481 + err = au_finfo_init(file, args->fidir);
14484 + if (unlikely(err))
14487 + dentry = file->f_path.dentry;
14488 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14489 + di_write_lock_child(dentry);
14490 + err = au_cmoo(dentry);
14491 + di_downgrade_lock(dentry, AuLock_IR);
14494 + err = args->open(file, vfsub_file_flags(file), NULL);
14497 + err = args->open(file, vfsub_file_flags(file),
14502 + di_read_unlock(dentry, AuLock_IR);
14504 + finfo = au_fi(file);
14506 + finfo->fi_file = file;
14507 + au_hbl_add(&finfo->fi_hlist,
14508 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14511 + fi_write_unlock(file);
14514 + fi_write_unlock(file);
14517 + if (unlikely(err)) {
14518 + finfo->fi_hdir = NULL;
14519 + au_finfo_fin(file);
14527 +int au_reopen_nondir(struct file *file)
14530 + aufs_bindex_t btop;
14531 + struct dentry *dentry;
14532 + struct au_branch *br;
14533 + struct file *h_file, *h_file_tmp;
14535 + dentry = file->f_path.dentry;
14536 + btop = au_dbtop(dentry);
14537 + br = au_sbr(dentry->d_sb, btop);
14538 + h_file_tmp = NULL;
14539 + if (au_fbtop(file) == btop) {
14540 + h_file = au_hf_top(file);
14541 + if (file->f_mode == h_file->f_mode)
14542 + return 0; /* success */
14543 + h_file_tmp = h_file;
14544 + get_file(h_file_tmp);
14545 + au_lcnt_inc(&br->br_nfiles);
14546 + au_set_h_fptr(file, btop, NULL);
14548 + AuDebugOn(au_fi(file)->fi_hdir);
14551 + * file exists on both of rw and ro
14552 + * open --> dbtop and fbtop are both 0
14553 + * prepend a branch as rw, "rw" become ro
14555 + * delete the top branch, "rw" becomes rw again
14556 + * --> dbtop is 1, fbtop is still 0
14557 + * write --> fbtop is 0 but dbtop is 1
14559 + /* AuDebugOn(au_fbtop(file) < btop); */
14561 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14562 + file, /*force_wr*/0);
14563 + err = PTR_ERR(h_file);
14564 + if (IS_ERR(h_file)) {
14565 + if (h_file_tmp) {
14567 + au_set_h_fptr(file, btop, h_file_tmp);
14568 + h_file_tmp = NULL;
14570 + goto out; /* todo: close all? */
14574 + au_set_fbtop(file, btop);
14575 + au_set_h_fptr(file, btop, h_file);
14576 + au_update_figen(file);
14577 + /* todo: necessary? */
14578 + /* file->f_ra = h_file->f_ra; */
14581 + if (h_file_tmp) {
14582 + fput(h_file_tmp);
14583 + au_lcnt_dec(&br->br_nfiles);
14588 +/* ---------------------------------------------------------------------- */
14590 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14591 + struct dentry *hi_wh)
14594 + aufs_bindex_t btop;
14595 + struct au_dinfo *dinfo;
14596 + struct dentry *h_dentry;
14597 + struct au_hdentry *hdp;
14599 + dinfo = au_di(file->f_path.dentry);
14600 + AuRwMustWriteLock(&dinfo->di_rwsem);
14602 + btop = dinfo->di_btop;
14603 + dinfo->di_btop = btgt;
14604 + hdp = au_hdentry(dinfo, btgt);
14605 + h_dentry = hdp->hd_dentry;
14606 + hdp->hd_dentry = hi_wh;
14607 + err = au_reopen_nondir(file);
14608 + hdp->hd_dentry = h_dentry;
14609 + dinfo->di_btop = btop;
14614 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14615 + aufs_bindex_t bcpup, struct au_pin *pin)
14618 + struct inode *inode, *h_inode;
14619 + struct dentry *h_dentry, *hi_wh;
14620 + struct au_cp_generic cpg = {
14621 + .dentry = file->f_path.dentry,
14628 + au_update_dbtop(cpg.dentry);
14629 + inode = d_inode(cpg.dentry);
14631 + if (au_dbtop(cpg.dentry) <= bcpup
14632 + && au_dbbot(cpg.dentry) >= bcpup) {
14633 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14634 + if (h_dentry && d_is_positive(h_dentry))
14635 + h_inode = d_inode(h_dentry);
14637 + hi_wh = au_hi_wh(inode, bcpup);
14638 + if (!hi_wh && !h_inode)
14639 + err = au_sio_cpup_wh(&cpg, file);
14641 + /* already copied-up after unlink */
14642 + err = au_reopen_wh(file, bcpup, hi_wh);
14645 + && (inode->i_nlink > 1
14646 + || (inode->i_state & I_LINKABLE))
14647 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14648 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14654 + * prepare the @file for writing.
14656 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14659 + aufs_bindex_t dbtop;
14660 + struct dentry *parent;
14661 + struct inode *inode;
14662 + struct super_block *sb;
14663 + struct file *h_file;
14664 + struct au_cp_generic cpg = {
14665 + .dentry = file->f_path.dentry,
14670 + .flags = AuCpup_DTIME
14673 + sb = cpg.dentry->d_sb;
14674 + inode = d_inode(cpg.dentry);
14675 + cpg.bsrc = au_fbtop(file);
14676 + err = au_test_ro(sb, cpg.bsrc, inode);
14677 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14678 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14683 + /* need to cpup or reopen */
14684 + parent = dget_parent(cpg.dentry);
14685 + di_write_lock_parent(parent);
14686 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14688 + if (unlikely(err < 0))
14692 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14693 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14694 + if (unlikely(err))
14698 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14699 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14700 + if (unlikely(err))
14703 + dbtop = au_dbtop(cpg.dentry);
14704 + if (dbtop <= cpg.bdst)
14705 + cpg.bsrc = cpg.bdst;
14707 + if (dbtop <= cpg.bdst /* just reopen */
14708 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14710 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14711 + if (IS_ERR(h_file))
14712 + err = PTR_ERR(h_file);
14714 + di_downgrade_lock(parent, AuLock_IR);
14715 + if (dbtop > cpg.bdst)
14716 + err = au_sio_cpup_simple(&cpg);
14718 + err = au_reopen_nondir(file);
14719 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14721 + } else { /* copyup as wh and reopen */
14723 + * since writable hfsplus branch is not supported,
14724 + * h_open_pre/post() are unnecessary.
14726 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14727 + di_downgrade_lock(parent, AuLock_IR);
14731 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14732 + goto out_dput; /* success */
14738 + di_downgrade_lock(parent, AuLock_IR);
14740 + di_read_unlock(parent, AuLock_IR);
14747 +/* ---------------------------------------------------------------------- */
14749 +int au_do_flush(struct file *file, fl_owner_t id,
14750 + int (*flush)(struct file *file, fl_owner_t id))
14753 + struct super_block *sb;
14754 + struct inode *inode;
14756 + inode = file_inode(file);
14757 + sb = inode->i_sb;
14758 + si_noflush_read_lock(sb);
14759 + fi_read_lock(file);
14760 + ii_read_lock_child(inode);
14762 + err = flush(file, id);
14763 + au_cpup_attr_timesizes(inode);
14765 + ii_read_unlock(inode);
14766 + fi_read_unlock(file);
14767 + si_read_unlock(sb);
14771 +/* ---------------------------------------------------------------------- */
14773 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14776 + struct au_pin pin;
14777 + struct au_finfo *finfo;
14778 + struct dentry *parent, *hi_wh;
14779 + struct inode *inode;
14780 + struct super_block *sb;
14781 + struct au_cp_generic cpg = {
14782 + .dentry = file->f_path.dentry,
14787 + .flags = AuCpup_DTIME
14790 + FiMustWriteLock(file);
14793 + finfo = au_fi(file);
14794 + sb = cpg.dentry->d_sb;
14795 + inode = d_inode(cpg.dentry);
14796 + cpg.bdst = au_ibtop(inode);
14797 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14800 + parent = dget_parent(cpg.dentry);
14801 + if (au_test_ro(sb, cpg.bdst, inode)) {
14802 + di_read_lock_parent(parent, !AuLock_IR);
14803 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14805 + di_read_unlock(parent, !AuLock_IR);
14806 + if (unlikely(err < 0))
14811 + di_read_lock_parent(parent, AuLock_IR);
14812 + hi_wh = au_hi_wh(inode, cpg.bdst);
14813 + if (!S_ISDIR(inode->i_mode)
14814 + && au_opt_test(au_mntflags(sb), PLINK)
14815 + && au_plink_test(inode)
14816 + && !d_unhashed(cpg.dentry)
14817 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14818 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14819 + if (unlikely(err))
14822 + /* always superio. */
14823 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14824 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14826 + err = au_sio_cpup_simple(&cpg);
14829 + } else if (hi_wh) {
14830 + /* already copied-up after unlink */
14831 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14832 + *need_reopen = 0;
14836 + di_read_unlock(parent, AuLock_IR);
14843 +static void au_do_refresh_dir(struct file *file)
14845 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14846 + struct au_hfile *p, tmp, *q;
14847 + struct au_finfo *finfo;
14848 + struct super_block *sb;
14849 + struct au_fidir *fidir;
14851 + FiMustWriteLock(file);
14853 + sb = file->f_path.dentry->d_sb;
14854 + finfo = au_fi(file);
14855 + fidir = finfo->fi_hdir;
14856 + AuDebugOn(!fidir);
14857 + p = fidir->fd_hfile + finfo->fi_btop;
14858 + brid = p->hf_br->br_id;
14859 + bbot = fidir->fd_bbot;
14860 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14864 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14865 + if (new_bindex == bindex)
14867 + if (new_bindex < 0) {
14868 + au_set_h_fptr(file, bindex, NULL);
14872 + /* swap two lower inode, and loop again */
14873 + q = fidir->fd_hfile + new_bindex;
14877 + if (tmp.hf_file) {
14883 + p = fidir->fd_hfile;
14884 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14885 + bbot = au_sbbot(sb);
14886 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14887 + finfo->fi_btop++, p++)
14888 + if (p->hf_file) {
14889 + if (file_inode(p->hf_file))
14891 + au_hfput(p, /*execed*/0);
14894 + bbot = au_br_index(sb, brid);
14895 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14896 + finfo->fi_btop++, p++)
14898 + au_hfput(p, /*execed*/0);
14899 + bbot = au_sbbot(sb);
14902 + p = fidir->fd_hfile + bbot;
14903 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14904 + fidir->fd_bbot--, p--)
14905 + if (p->hf_file) {
14906 + if (file_inode(p->hf_file))
14908 + au_hfput(p, /*execed*/0);
14910 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14914 + * after branch manipulating, refresh the file.
14916 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14918 + int err, need_reopen, nbr;
14919 + aufs_bindex_t bbot, bindex;
14920 + struct dentry *dentry;
14921 + struct super_block *sb;
14922 + struct au_finfo *finfo;
14923 + struct au_hfile *hfile;
14925 + dentry = file->f_path.dentry;
14926 + sb = dentry->d_sb;
14927 + nbr = au_sbbot(sb) + 1;
14928 + finfo = au_fi(file);
14929 + if (!finfo->fi_hdir) {
14930 + hfile = &finfo->fi_htop;
14931 + AuDebugOn(!hfile->hf_file);
14932 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14933 + AuDebugOn(bindex < 0);
14934 + if (bindex != finfo->fi_btop)
14935 + au_set_fbtop(file, bindex);
14937 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14938 + if (unlikely(err))
14940 + au_do_refresh_dir(file);
14945 + if (!au_test_mmapped(file))
14946 + err = au_file_refresh_by_inode(file, &need_reopen);
14947 + if (finfo->fi_hdir)
14948 + /* harmless if err */
14949 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14950 + if (!err && need_reopen && !d_unlinked(dentry))
14951 + err = reopen(file);
14953 + au_update_figen(file);
14954 + goto out; /* success */
14957 + /* error, close all lower files */
14958 + if (finfo->fi_hdir) {
14959 + bbot = au_fbbot_dir(file);
14960 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14961 + au_set_h_fptr(file, bindex, NULL);
14968 +/* common function to regular file and dir */
14969 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14970 + int wlock, unsigned int fi_lsc)
14973 + unsigned int sigen, figen;
14974 + aufs_bindex_t btop;
14975 + unsigned char pseudo_link;
14976 + struct dentry *dentry;
14977 + struct inode *inode;
14980 + dentry = file->f_path.dentry;
14981 + inode = d_inode(dentry);
14982 + sigen = au_sigen(dentry->d_sb);
14983 + fi_write_lock_nested(file, fi_lsc);
14984 + figen = au_figen(file);
14986 + di_write_lock_child(dentry);
14988 + di_write_lock_child2(dentry);
14989 + btop = au_dbtop(dentry);
14990 + pseudo_link = (btop != au_ibtop(inode));
14991 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14993 + di_downgrade_lock(dentry, AuLock_IR);
14994 + fi_downgrade_lock(file);
14996 + goto out; /* success */
14999 + AuDbg("sigen %d, figen %d\n", sigen, figen);
15000 + if (au_digen_test(dentry, sigen)) {
15001 + err = au_reval_dpath(dentry, sigen);
15002 + AuDebugOn(!err && au_digen_test(dentry, sigen));
15006 + err = refresh_file(file, reopen);
15009 + di_downgrade_lock(dentry, AuLock_IR);
15010 + fi_downgrade_lock(file);
15013 + di_write_unlock(dentry);
15014 + fi_write_unlock(file);
15021 +/* ---------------------------------------------------------------------- */
15023 +/* cf. aufs_nopage() */
15024 +/* for madvise(2) */
15025 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
15027 + unlock_page(page);
15031 +/* it will never be called, but necessary to support O_DIRECT */
15032 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
15033 +{ BUG(); return 0; }
15035 +/* they will never be called. */
15036 +#ifdef CONFIG_AUFS_DEBUG
15037 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
15038 + loff_t pos, unsigned len, unsigned flags,
15039 + struct page **pagep, void **fsdata)
15040 +{ AuUnsupport(); return 0; }
15041 +static int aufs_write_end(struct file *file, struct address_space *mapping,
15042 + loff_t pos, unsigned len, unsigned copied,
15043 + struct page *page, void *fsdata)
15044 +{ AuUnsupport(); return 0; }
15045 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
15046 +{ AuUnsupport(); return 0; }
15048 +static int aufs_set_page_dirty(struct page *page)
15049 +{ AuUnsupport(); return 0; }
15050 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
15051 + unsigned int length)
15052 +{ AuUnsupport(); }
15053 +static int aufs_releasepage(struct page *page, gfp_t gfp)
15054 +{ AuUnsupport(); return 0; }
15055 +#if 0 /* called by memory compaction regardless file */
15056 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
15057 + struct page *page, enum migrate_mode mode)
15058 +{ AuUnsupport(); return 0; }
15060 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
15061 +{ AuUnsupport(); return true; }
15062 +static void aufs_putback_page(struct page *page)
15063 +{ AuUnsupport(); }
15064 +static int aufs_launder_page(struct page *page)
15065 +{ AuUnsupport(); return 0; }
15066 +static int aufs_is_partially_uptodate(struct page *page,
15067 + unsigned long from,
15068 + unsigned long count)
15069 +{ AuUnsupport(); return 0; }
15070 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
15072 +{ AuUnsupport(); }
15073 +static int aufs_error_remove_page(struct address_space *mapping,
15074 + struct page *page)
15075 +{ AuUnsupport(); return 0; }
15076 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
15078 +{ AuUnsupport(); return 0; }
15079 +static void aufs_swap_deactivate(struct file *file)
15080 +{ AuUnsupport(); }
15081 +#endif /* CONFIG_AUFS_DEBUG */
15083 +const struct address_space_operations aufs_aop = {
15084 + .readpage = aufs_readpage,
15085 + .direct_IO = aufs_direct_IO,
15086 +#ifdef CONFIG_AUFS_DEBUG
15087 + .writepage = aufs_writepage,
15088 + /* no writepages, because of writepage */
15089 + .set_page_dirty = aufs_set_page_dirty,
15090 + /* no readpages, because of readpage */
15091 + .write_begin = aufs_write_begin,
15092 + .write_end = aufs_write_end,
15093 + /* no bmap, no block device */
15094 + .invalidatepage = aufs_invalidatepage,
15095 + .releasepage = aufs_releasepage,
15096 + /* is fallback_migrate_page ok? */
15097 + /* .migratepage = aufs_migratepage, */
15098 + .isolate_page = aufs_isolate_page,
15099 + .putback_page = aufs_putback_page,
15100 + .launder_page = aufs_launder_page,
15101 + .is_partially_uptodate = aufs_is_partially_uptodate,
15102 + .is_dirty_writeback = aufs_is_dirty_writeback,
15103 + .error_remove_page = aufs_error_remove_page,
15104 + .swap_activate = aufs_swap_activate,
15105 + .swap_deactivate = aufs_swap_deactivate
15106 +#endif /* CONFIG_AUFS_DEBUG */
15108 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
15109 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
15110 +++ linux/fs/aufs/file.h 2019-03-05 12:13:00.139224339 +0100
15112 +/* SPDX-License-Identifier: GPL-2.0 */
15114 + * Copyright (C) 2005-2019 Junjiro R. Okajima
15116 + * This program, aufs is free software; you can redistribute it and/or modify
15117 + * it under the terms of the GNU General Public License as published by
15118 + * the Free Software Foundation; either version 2 of the License, or
15119 + * (at your option) any later version.
15121 + * This program is distributed in the hope that it will be useful,
15122 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15123 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15124 + * GNU General Public License for more details.
15126 + * You should have received a copy of the GNU General Public License
15127 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15131 + * file operations
15134 +#ifndef __AUFS_FILE_H__
15135 +#define __AUFS_FILE_H__
15139 +#include <linux/file.h>
15140 +#include <linux/fs.h>
15141 +#include <linux/mm_types.h>
15142 +#include <linux/poll.h>
15143 +#include "rwsem.h"
15147 + struct file *hf_file;
15148 + struct au_branch *hf_br;
15153 + aufs_bindex_t fd_bbot;
15154 + aufs_bindex_t fd_nent;
15155 + struct au_vdir *fd_vdir_cache;
15156 + struct au_hfile fd_hfile[];
15159 +static inline int au_fidir_sz(int nent)
15161 + AuDebugOn(nent < 0);
15162 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
15166 + atomic_t fi_generation;
15168 + struct au_rwsem fi_rwsem;
15169 + aufs_bindex_t fi_btop;
15171 + /* do not union them */
15172 + struct { /* for non-dir */
15173 + struct au_hfile fi_htop;
15174 + atomic_t fi_mmapped;
15176 + struct au_fidir *fi_hdir; /* for dir only */
15178 + struct hlist_bl_node fi_hlist;
15179 + struct file *fi_file; /* very ugly */
15180 + struct rcu_head rcu;
15181 +} ____cacheline_aligned_in_smp;
15183 +/* ---------------------------------------------------------------------- */
15186 +extern const struct address_space_operations aufs_aop;
15187 +unsigned int au_file_roflags(unsigned int flags);
15188 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15189 + struct file *file, int force_wr);
15190 +struct au_do_open_args {
15192 + int (*open)(struct file *file, int flags,
15193 + struct file *h_file);
15194 + struct au_fidir *fidir;
15195 + struct file *h_file;
15197 +int au_do_open(struct file *file, struct au_do_open_args *args);
15198 +int au_reopen_nondir(struct file *file);
15200 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15201 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15202 + int wlock, unsigned int fi_lsc);
15203 +int au_do_flush(struct file *file, fl_owner_t id,
15204 + int (*flush)(struct file *file, fl_owner_t id));
15207 +#ifdef CONFIG_AUFS_POLL
15208 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15211 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15213 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15215 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15216 + struct file *h_file);
15218 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15219 + aufs_bindex_t bindex, int force_wr)
15220 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15221 + struct file *h_file);
15225 +extern const struct file_operations aufs_file_fop;
15226 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15227 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15228 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15231 +void au_hfput(struct au_hfile *hf, int execed);
15232 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15233 + struct file *h_file);
15235 +void au_update_figen(struct file *file);
15236 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15237 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15239 +void au_fi_init_once(void *_fi);
15240 +void au_finfo_fin(struct file *file);
15241 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15244 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15245 +#ifdef CONFIG_COMPAT
15246 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15247 + unsigned long arg);
15248 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15249 + unsigned long arg);
15252 +/* ---------------------------------------------------------------------- */
15254 +static inline struct au_finfo *au_fi(struct file *file)
15256 + return file->private_data;
15259 +/* ---------------------------------------------------------------------- */
15261 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15262 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15263 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15264 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15266 +#define fi_read_trylock_nested(f) \
15267 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15268 +#define fi_write_trylock_nested(f) \
15269 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15272 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15273 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15274 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15276 +/* lock subclass for finfo */
15282 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15284 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15287 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15289 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15293 + * fi_read_lock_1, fi_write_lock_1,
15294 + * fi_read_lock_2, fi_write_lock_2
15296 +#define AuReadLockFunc(name) \
15297 +static inline void fi_read_lock_##name(struct file *f) \
15298 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15300 +#define AuWriteLockFunc(name) \
15301 +static inline void fi_write_lock_##name(struct file *f) \
15302 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15304 +#define AuRWLockFuncs(name) \
15305 + AuReadLockFunc(name) \
15306 + AuWriteLockFunc(name)
15311 +#undef AuReadLockFunc
15312 +#undef AuWriteLockFunc
15313 +#undef AuRWLockFuncs
15315 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15316 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15317 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15319 +/* ---------------------------------------------------------------------- */
15321 +/* todo: hard/soft set? */
15322 +static inline aufs_bindex_t au_fbtop(struct file *file)
15324 + FiMustAnyLock(file);
15325 + return au_fi(file)->fi_btop;
15328 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15330 + FiMustAnyLock(file);
15331 + AuDebugOn(!au_fi(file)->fi_hdir);
15332 + return au_fi(file)->fi_hdir->fd_bbot;
15335 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15337 + FiMustAnyLock(file);
15338 + AuDebugOn(!au_fi(file)->fi_hdir);
15339 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15342 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15344 + FiMustWriteLock(file);
15345 + au_fi(file)->fi_btop = bindex;
15348 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15350 + FiMustWriteLock(file);
15351 + AuDebugOn(!au_fi(file)->fi_hdir);
15352 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15355 +static inline void au_set_fvdir_cache(struct file *file,
15356 + struct au_vdir *vdir_cache)
15358 + FiMustWriteLock(file);
15359 + AuDebugOn(!au_fi(file)->fi_hdir);
15360 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15363 +static inline struct file *au_hf_top(struct file *file)
15365 + FiMustAnyLock(file);
15366 + AuDebugOn(au_fi(file)->fi_hdir);
15367 + return au_fi(file)->fi_htop.hf_file;
15370 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15372 + FiMustAnyLock(file);
15373 + AuDebugOn(!au_fi(file)->fi_hdir);
15374 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15377 +/* todo: memory barrier? */
15378 +static inline unsigned int au_figen(struct file *f)
15380 + return atomic_read(&au_fi(f)->fi_generation);
15383 +static inline void au_set_mmapped(struct file *f)
15385 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15387 + pr_warn("fi_mmapped wrapped around\n");
15388 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15392 +static inline void au_unset_mmapped(struct file *f)
15394 + atomic_dec(&au_fi(f)->fi_mmapped);
15397 +static inline int au_test_mmapped(struct file *f)
15399 + return atomic_read(&au_fi(f)->fi_mmapped);
15402 +/* customize vma->vm_file */
15404 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15405 + struct file *file)
15409 + f = vma->vm_file;
15411 + vma->vm_file = file;
15416 +#define AuDbgVmRegion(file, vma) do {} while (0)
15418 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15419 + struct file *file)
15421 + au_do_vm_file_reset(vma, file);
15424 +#define AuDbgVmRegion(file, vma) \
15425 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15427 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15428 + struct file *file)
15432 + au_do_vm_file_reset(vma, file);
15433 + f = vma->vm_region->vm_file;
15435 + vma->vm_region->vm_file = file;
15438 +#endif /* CONFIG_MMU */
15440 +/* handle vma->vm_prfile */
15441 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15442 + struct file *file)
15445 + vma->vm_prfile = file;
15446 +#ifndef CONFIG_MMU
15448 + vma->vm_region->vm_prfile = file;
15452 +#endif /* __KERNEL__ */
15453 +#endif /* __AUFS_FILE_H__ */
15454 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15455 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15456 +++ linux/fs/aufs/finfo.c 2019-03-05 12:13:00.139224339 +0100
15458 +// SPDX-License-Identifier: GPL-2.0
15460 + * Copyright (C) 2005-2019 Junjiro R. Okajima
15462 + * This program, aufs is free software; you can redistribute it and/or modify
15463 + * it under the terms of the GNU General Public License as published by
15464 + * the Free Software Foundation; either version 2 of the License, or
15465 + * (at your option) any later version.
15467 + * This program is distributed in the hope that it will be useful,
15468 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15469 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15470 + * GNU General Public License for more details.
15472 + * You should have received a copy of the GNU General Public License
15473 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15477 + * file private data
15482 +void au_hfput(struct au_hfile *hf, int execed)
15485 + allow_write_access(hf->hf_file);
15486 + fput(hf->hf_file);
15487 + hf->hf_file = NULL;
15488 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15489 + hf->hf_br = NULL;
15492 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15494 + struct au_finfo *finfo = au_fi(file);
15495 + struct au_hfile *hf;
15496 + struct au_fidir *fidir;
15498 + fidir = finfo->fi_hdir;
15500 + AuDebugOn(finfo->fi_btop != bindex);
15501 + hf = &finfo->fi_htop;
15503 + hf = fidir->fd_hfile + bindex;
15505 + if (hf && hf->hf_file)
15506 + au_hfput(hf, vfsub_file_execed(file));
15508 + FiMustWriteLock(file);
15509 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15510 + hf->hf_file = val;
15511 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15515 +void au_update_figen(struct file *file)
15517 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15518 + /* smp_mb(); */ /* atomic_set */
15521 +/* ---------------------------------------------------------------------- */
15523 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15525 + struct au_fidir *fidir;
15528 + nbr = au_sbbot(sb) + 1;
15530 + nbr = 2; /* initial allocate for 2 branches */
15531 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15533 + fidir->fd_bbot = -1;
15534 + fidir->fd_nent = nbr;
15540 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15543 + struct au_fidir *fidir, *p;
15545 + AuRwMustWriteLock(&finfo->fi_rwsem);
15546 + fidir = finfo->fi_hdir;
15547 + AuDebugOn(!fidir);
15550 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15551 + GFP_NOFS, may_shrink);
15553 + p->fd_nent = nbr;
15554 + finfo->fi_hdir = p;
15561 +/* ---------------------------------------------------------------------- */
15563 +void au_finfo_fin(struct file *file)
15565 + struct au_finfo *finfo;
15567 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15569 + finfo = au_fi(file);
15570 + AuDebugOn(finfo->fi_hdir);
15571 + AuRwDestroy(&finfo->fi_rwsem);
15572 + au_cache_free_finfo(finfo);
15575 +void au_fi_init_once(void *_finfo)
15577 + struct au_finfo *finfo = _finfo;
15579 + au_rw_init(&finfo->fi_rwsem);
15582 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15585 + struct au_finfo *finfo;
15586 + struct dentry *dentry;
15589 + dentry = file->f_path.dentry;
15590 + finfo = au_cache_alloc_finfo();
15591 + if (unlikely(!finfo))
15595 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15596 + au_rw_write_lock(&finfo->fi_rwsem);
15597 + finfo->fi_btop = -1;
15598 + finfo->fi_hdir = fidir;
15599 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15600 + /* smp_mb(); */ /* atomic_set */
15602 + file->private_data = finfo;
15607 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15608 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15609 +++ linux/fs/aufs/f_op.c 2019-03-05 12:13:00.139224339 +0100
15611 +// SPDX-License-Identifier: GPL-2.0
15613 + * Copyright (C) 2005-2019 Junjiro R. Okajima
15615 + * This program, aufs is free software; you can redistribute it and/or modify
15616 + * it under the terms of the GNU General Public License as published by
15617 + * the Free Software Foundation; either version 2 of the License, or
15618 + * (at your option) any later version.
15620 + * This program is distributed in the hope that it will be useful,
15621 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15622 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15623 + * GNU General Public License for more details.
15625 + * You should have received a copy of the GNU General Public License
15626 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15630 + * file and vm operations
15633 +#include <linux/aio.h>
15634 +#include <linux/fs_stack.h>
15635 +#include <linux/mman.h>
15636 +#include <linux/security.h>
15639 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15642 + aufs_bindex_t bindex;
15643 + struct dentry *dentry, *h_dentry;
15644 + struct au_finfo *finfo;
15645 + struct inode *h_inode;
15647 + FiMustWriteLock(file);
15650 + dentry = file->f_path.dentry;
15651 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15652 + finfo = au_fi(file);
15653 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15654 + atomic_set(&finfo->fi_mmapped, 0);
15655 + bindex = au_dbtop(dentry);
15657 + h_dentry = au_h_dptr(dentry, bindex);
15658 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15659 + if (unlikely(err))
15661 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15662 + if (IS_ERR(h_file)) {
15663 + err = PTR_ERR(h_file);
15667 + h_dentry = h_file->f_path.dentry;
15668 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15669 + if (unlikely(err))
15671 + /* br ref is already inc-ed */
15674 + if ((flags & __O_TMPFILE)
15675 + && !(flags & O_EXCL)) {
15676 + h_inode = file_inode(h_file);
15677 + spin_lock(&h_inode->i_lock);
15678 + h_inode->i_state |= I_LINKABLE;
15679 + spin_unlock(&h_inode->i_lock);
15681 + au_set_fbtop(file, bindex);
15682 + au_set_h_fptr(file, bindex, h_file);
15683 + au_update_figen(file);
15684 + /* todo: necessary? */
15685 + /* file->f_ra = h_file->f_ra; */
15691 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15692 + struct file *file)
15695 + struct super_block *sb;
15696 + struct au_do_open_args args = {
15697 + .open = au_do_open_nondir
15700 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15701 + file, vfsub_file_flags(file), file->f_mode);
15703 + sb = file->f_path.dentry->d_sb;
15704 + si_read_lock(sb, AuLock_FLUSH);
15705 + err = au_do_open(file, &args);
15706 + si_read_unlock(sb);
15710 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15712 + struct au_finfo *finfo;
15713 + aufs_bindex_t bindex;
15715 + finfo = au_fi(file);
15716 + au_hbl_del(&finfo->fi_hlist,
15717 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15718 + bindex = finfo->fi_btop;
15720 + au_set_h_fptr(file, bindex, NULL);
15722 + au_finfo_fin(file);
15726 +/* ---------------------------------------------------------------------- */
15728 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15731 + struct file *h_file;
15734 + h_file = au_hf_top(file);
15736 + err = vfsub_flush(h_file, id);
15740 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15742 + return au_do_flush(file, id, au_do_flush_nondir);
15745 +/* ---------------------------------------------------------------------- */
15747 + * read and write functions acquire [fdi]_rwsem once, but release before
15748 + * mmap_sem. This is because to stop a race condition between mmap(2).
15749 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15750 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15751 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15754 +/* Callers should call au_read_post() or fput() in the end */
15755 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15757 + struct file *h_file;
15760 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15762 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15763 + h_file = au_hf_top(file);
15764 + get_file(h_file);
15766 + fi_read_unlock(file);
15768 + h_file = ERR_PTR(err);
15773 +static void au_read_post(struct inode *inode, struct file *h_file)
15775 + /* update without lock, I don't think it a problem */
15776 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15780 +struct au_write_pre {
15782 + unsigned int lsc;
15786 + aufs_bindex_t btop;
15790 + * return with iinfo is write-locked
15791 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15794 +static struct file *au_write_pre(struct file *file, int do_ready,
15795 + struct au_write_pre *wpre)
15797 + struct file *h_file;
15798 + struct dentry *dentry;
15800 + unsigned int lsc;
15801 + struct au_pin pin;
15806 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15807 + h_file = ERR_PTR(err);
15808 + if (unlikely(err))
15811 + dentry = file->f_path.dentry;
15813 + err = au_ready_to_write(file, -1, &pin);
15814 + if (unlikely(err)) {
15815 + h_file = ERR_PTR(err);
15816 + di_write_unlock(dentry);
15821 + di_downgrade_lock(dentry, /*flags*/0);
15823 + wpre->btop = au_fbtop(file);
15824 + h_file = au_hf_top(file);
15825 + get_file(h_file);
15827 + wpre->blks = file_inode(h_file)->i_blocks;
15830 + di_read_unlock(dentry, /*flags*/0);
15833 + fi_write_unlock(file);
15838 +static void au_write_post(struct inode *inode, struct file *h_file,
15839 + struct au_write_pre *wpre, ssize_t written)
15841 + struct inode *h_inode;
15843 + au_cpup_attr_timesizes(inode);
15844 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15845 + h_inode = file_inode(h_file);
15846 + inode->i_mode = h_inode->i_mode;
15847 + ii_write_unlock(inode);
15848 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15850 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15851 + /*force*/h_inode->i_blocks > wpre->blks);
15855 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
15859 + struct inode *inode;
15860 + struct file *h_file;
15861 + struct super_block *sb;
15863 + inode = file_inode(file);
15864 + sb = inode->i_sb;
15865 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15867 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15868 + err = PTR_ERR(h_file);
15869 + if (IS_ERR(h_file))
15872 + /* filedata may be obsoleted by concurrent copyup, but no problem */
15873 + err = vfsub_read_u(h_file, buf, count, ppos);
15874 + /* todo: necessary? */
15875 + /* file->f_ra = h_file->f_ra; */
15876 + au_read_post(inode, h_file);
15879 + si_read_unlock(sb);
15884 + * todo: very ugly
15885 + * it locks both of i_mutex and si_rwsem for read in safe.
15886 + * if the plink maintenance mode continues forever (that is the problem),
15887 + * may loop forever.
15889 +static void au_mtx_and_read_lock(struct inode *inode)
15892 + struct super_block *sb = inode->i_sb;
15895 + inode_lock(inode);
15896 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15899 + inode_unlock(inode);
15900 + si_read_lock(sb, AuLock_NOPLMW);
15901 + si_read_unlock(sb);
15905 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
15906 + size_t count, loff_t *ppos)
15909 + struct au_write_pre wpre;
15910 + struct inode *inode;
15911 + struct file *h_file;
15912 + char __user *buf = (char __user *)ubuf;
15914 + inode = file_inode(file);
15915 + au_mtx_and_read_lock(inode);
15918 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15919 + err = PTR_ERR(h_file);
15920 + if (IS_ERR(h_file))
15923 + err = vfsub_write_u(h_file, buf, count, ppos);
15924 + au_write_post(inode, h_file, &wpre, err);
15927 + si_read_unlock(inode->i_sb);
15928 + inode_unlock(inode);
15932 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15933 + struct iov_iter *iov_iter)
15936 + struct file *file;
15937 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15939 + err = security_file_permission(h_file, rw);
15940 + if (unlikely(err))
15945 + if (rw == MAY_READ)
15946 + iter = h_file->f_op->read_iter;
15947 + else if (rw == MAY_WRITE)
15948 + iter = h_file->f_op->write_iter;
15950 + file = kio->ki_filp;
15951 + kio->ki_filp = h_file;
15954 + err = iter(kio, iov_iter);
15957 + /* currently there is no such fs */
15959 + kio->ki_filp = file;
15965 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15968 + struct file *file, *h_file;
15969 + struct inode *inode;
15970 + struct super_block *sb;
15972 + file = kio->ki_filp;
15973 + inode = file_inode(file);
15974 + sb = inode->i_sb;
15975 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15977 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15978 + err = PTR_ERR(h_file);
15979 + if (IS_ERR(h_file))
15982 + if (au_test_loopback_kthread()) {
15983 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15984 + if (file->f_mapping != h_file->f_mapping) {
15985 + file->f_mapping = h_file->f_mapping;
15986 + smp_mb(); /* unnecessary? */
15989 + fi_read_unlock(file);
15991 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15992 + /* todo: necessary? */
15993 + /* file->f_ra = h_file->f_ra; */
15994 + au_read_post(inode, h_file);
15997 + si_read_unlock(sb);
16001 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
16004 + struct au_write_pre wpre;
16005 + struct inode *inode;
16006 + struct file *file, *h_file;
16008 + file = kio->ki_filp;
16009 + inode = file_inode(file);
16010 + au_mtx_and_read_lock(inode);
16013 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16014 + err = PTR_ERR(h_file);
16015 + if (IS_ERR(h_file))
16018 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
16019 + au_write_post(inode, h_file, &wpre, err);
16022 + si_read_unlock(inode->i_sb);
16023 + inode_unlock(inode);
16027 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
16028 + struct pipe_inode_info *pipe, size_t len,
16029 + unsigned int flags)
16032 + struct file *h_file;
16033 + struct inode *inode;
16034 + struct super_block *sb;
16036 + inode = file_inode(file);
16037 + sb = inode->i_sb;
16038 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16040 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16041 + err = PTR_ERR(h_file);
16042 + if (IS_ERR(h_file))
16045 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
16046 + /* todo: necessary? */
16047 + /* file->f_ra = h_file->f_ra; */
16048 + au_read_post(inode, h_file);
16051 + si_read_unlock(sb);
16056 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
16057 + size_t len, unsigned int flags)
16060 + struct au_write_pre wpre;
16061 + struct inode *inode;
16062 + struct file *h_file;
16064 + inode = file_inode(file);
16065 + au_mtx_and_read_lock(inode);
16068 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16069 + err = PTR_ERR(h_file);
16070 + if (IS_ERR(h_file))
16073 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
16074 + au_write_post(inode, h_file, &wpre, err);
16077 + si_read_unlock(inode->i_sb);
16078 + inode_unlock(inode);
16082 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
16086 + struct au_write_pre wpre;
16087 + struct inode *inode;
16088 + struct file *h_file;
16090 + inode = file_inode(file);
16091 + au_mtx_and_read_lock(inode);
16094 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16095 + err = PTR_ERR(h_file);
16096 + if (IS_ERR(h_file))
16100 + err = vfs_fallocate(h_file, mode, offset, len);
16102 + au_write_post(inode, h_file, &wpre, /*written*/1);
16105 + si_read_unlock(inode->i_sb);
16106 + inode_unlock(inode);
16110 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
16111 + struct file *dst, loff_t dst_pos,
16112 + size_t len, unsigned int flags)
16115 + struct au_write_pre wpre;
16116 + enum { SRC, DST };
16118 + struct inode *inode;
16119 + struct file *h_file;
16120 + struct super_block *h_sb;
16122 +#define a_src a[SRC]
16123 +#define a_dst a[DST]
16126 + a_src.inode = file_inode(src);
16127 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
16129 + a_dst.inode = file_inode(dst);
16130 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
16133 + au_mtx_and_read_lock(a_dst.inode);
16135 + * in order to match the order in di_write_lock2_{child,parent}(),
16136 + * use f_path.dentry for this comparison.
16138 + if (src->f_path.dentry < dst->f_path.dentry) {
16139 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
16140 + err = PTR_ERR(a_src.h_file);
16141 + if (IS_ERR(a_src.h_file))
16144 + wpre.lsc = AuLsc_FI_2;
16145 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16146 + err = PTR_ERR(a_dst.h_file);
16147 + if (IS_ERR(a_dst.h_file)) {
16148 + au_read_post(a_src.inode, a_src.h_file);
16152 + wpre.lsc = AuLsc_FI_1;
16153 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16154 + err = PTR_ERR(a_dst.h_file);
16155 + if (IS_ERR(a_dst.h_file))
16158 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
16159 + err = PTR_ERR(a_src.h_file);
16160 + if (IS_ERR(a_src.h_file)) {
16161 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
16168 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
16169 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
16170 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
16176 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
16177 + dst_pos, len, flags);
16180 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
16181 + fi_read_unlock(src);
16182 + au_read_post(a_src.inode, a_src.h_file);
16184 + si_read_unlock(a_dst.inode->i_sb);
16185 + inode_unlock(a_dst.inode);
16192 +/* ---------------------------------------------------------------------- */
16195 + * The locking order around current->mmap_sem.
16196 + * - in most and regular cases
16197 + * file I/O syscall -- aufs_read() or something
16198 + * -- si_rwsem for read -- mmap_sem
16199 + * (Note that [fdi]i_rwsem are released before mmap_sem).
16201 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
16202 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
16203 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
16204 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
16205 + * It means that when aufs acquires si_rwsem for write, the process should never
16206 + * acquire mmap_sem.
16208 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
16209 + * problem either since any directory is not able to be mmap-ed.
16210 + * The similar scenario is applied to aufs_readlink() too.
16213 +#if 0 /* stop calling security_file_mmap() */
16214 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
16215 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
16217 +static unsigned long au_arch_prot_conv(unsigned long flags)
16219 + /* currently ppc64 only */
16220 +#ifdef CONFIG_PPC64
16221 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16222 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16223 + return AuConv_VM_PROT(flags, SAO);
16225 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16230 +static unsigned long au_prot_conv(unsigned long flags)
16232 + return AuConv_VM_PROT(flags, READ)
16233 + | AuConv_VM_PROT(flags, WRITE)
16234 + | AuConv_VM_PROT(flags, EXEC)
16235 + | au_arch_prot_conv(flags);
16238 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16239 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16241 +static unsigned long au_flag_conv(unsigned long flags)
16243 + return AuConv_VM_MAP(flags, GROWSDOWN)
16244 + | AuConv_VM_MAP(flags, DENYWRITE)
16245 + | AuConv_VM_MAP(flags, LOCKED);
16249 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16252 + const unsigned char wlock
16253 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16254 + struct super_block *sb;
16255 + struct file *h_file;
16256 + struct inode *inode;
16258 + AuDbgVmRegion(file, vma);
16260 + inode = file_inode(file);
16261 + sb = inode->i_sb;
16263 + si_read_lock(sb, AuLock_NOPLMW);
16265 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16267 + err = PTR_ERR(h_file);
16268 + if (IS_ERR(h_file))
16272 + au_set_mmapped(file);
16273 + au_vm_file_reset(vma, h_file);
16275 + * we cannot call security_mmap_file() here since it may acquire
16276 + * mmap_sem or i_mutex.
16278 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16279 + * au_flag_conv(vma->vm_flags));
16282 + err = call_mmap(h_file, vma);
16284 + au_vm_prfile_set(vma, file);
16285 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16286 + goto out_fput; /* success */
16288 + au_unset_mmapped(file);
16289 + au_vm_file_reset(vma, file);
16293 + ii_write_unlock(inode);
16298 + si_read_unlock(sb);
16304 +/* ---------------------------------------------------------------------- */
16306 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16310 + struct au_write_pre wpre;
16311 + struct inode *inode;
16312 + struct file *h_file;
16314 + err = 0; /* -EBADF; */ /* posix? */
16315 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16318 + inode = file_inode(file);
16319 + au_mtx_and_read_lock(inode);
16322 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16323 + err = PTR_ERR(h_file);
16324 + if (IS_ERR(h_file))
16327 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16328 + au_write_post(inode, h_file, &wpre, /*written*/0);
16331 + si_read_unlock(inode->i_sb);
16332 + inode_unlock(inode);
16337 +static int aufs_fasync(int fd, struct file *file, int flag)
16340 + struct file *h_file;
16341 + struct super_block *sb;
16343 + sb = file->f_path.dentry->d_sb;
16344 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16346 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16347 + err = PTR_ERR(h_file);
16348 + if (IS_ERR(h_file))
16351 + if (h_file->f_op->fasync)
16352 + err = h_file->f_op->fasync(fd, h_file, flag);
16353 + fput(h_file); /* instead of au_read_post() */
16356 + si_read_unlock(sb);
16360 +static int aufs_setfl(struct file *file, unsigned long arg)
16363 + struct file *h_file;
16364 + struct super_block *sb;
16366 + sb = file->f_path.dentry->d_sb;
16367 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16369 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16370 + err = PTR_ERR(h_file);
16371 + if (IS_ERR(h_file))
16374 + /* stop calling h_file->fasync */
16375 + arg |= vfsub_file_flags(file) & FASYNC;
16376 + err = setfl(/*unused fd*/-1, h_file, arg);
16377 + fput(h_file); /* instead of au_read_post() */
16380 + si_read_unlock(sb);
16384 +/* ---------------------------------------------------------------------- */
16386 +/* no one supports this operation, currently */
16388 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16389 + size_t len, loff_t *pos, int more)
16394 +/* ---------------------------------------------------------------------- */
16396 +const struct file_operations aufs_file_fop = {
16397 + .owner = THIS_MODULE,
16399 + .llseek = default_llseek,
16401 + .read = aufs_read,
16402 + .write = aufs_write,
16403 + .read_iter = aufs_read_iter,
16404 + .write_iter = aufs_write_iter,
16406 +#ifdef CONFIG_AUFS_POLL
16407 + .poll = aufs_poll,
16409 + .unlocked_ioctl = aufs_ioctl_nondir,
16410 +#ifdef CONFIG_COMPAT
16411 + .compat_ioctl = aufs_compat_ioctl_nondir,
16413 + .mmap = aufs_mmap,
16414 + .open = aufs_open_nondir,
16415 + .flush = aufs_flush_nondir,
16416 + .release = aufs_release_nondir,
16417 + .fsync = aufs_fsync_nondir,
16418 + .fasync = aufs_fasync,
16419 + /* .sendpage = aufs_sendpage, */
16420 + .setfl = aufs_setfl,
16421 + .splice_write = aufs_splice_write,
16422 + .splice_read = aufs_splice_read,
16424 + .aio_splice_write = aufs_aio_splice_write,
16425 + .aio_splice_read = aufs_aio_splice_read,
16427 + .fallocate = aufs_fallocate,
16428 + .copy_file_range = aufs_copy_file_range
16430 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16431 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16432 +++ linux/fs/aufs/fstype.h 2019-03-05 12:13:00.139224339 +0100
16434 +/* SPDX-License-Identifier: GPL-2.0 */
16436 + * Copyright (C) 2005-2019 Junjiro R. Okajima
16438 + * This program, aufs is free software; you can redistribute it and/or modify
16439 + * it under the terms of the GNU General Public License as published by
16440 + * the Free Software Foundation; either version 2 of the License, or
16441 + * (at your option) any later version.
16443 + * This program is distributed in the hope that it will be useful,
16444 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16445 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16446 + * GNU General Public License for more details.
16448 + * You should have received a copy of the GNU General Public License
16449 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16453 + * judging filesystem type
16456 +#ifndef __AUFS_FSTYPE_H__
16457 +#define __AUFS_FSTYPE_H__
16461 +#include <linux/fs.h>
16462 +#include <linux/magic.h>
16463 +#include <linux/nfs_fs.h>
16464 +#include <linux/romfs_fs.h>
16466 +static inline int au_test_aufs(struct super_block *sb)
16468 + return sb->s_magic == AUFS_SUPER_MAGIC;
16471 +static inline const char *au_sbtype(struct super_block *sb)
16473 + return sb->s_type->name;
16476 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16478 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16479 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16485 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16487 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16488 + return sb->s_magic == ROMFS_MAGIC;
16494 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16496 +#if IS_ENABLED(CONFIG_CRAMFS)
16497 + return sb->s_magic == CRAMFS_MAGIC;
16502 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16504 +#if IS_ENABLED(CONFIG_NFS_FS)
16505 + return sb->s_magic == NFS_SUPER_MAGIC;
16511 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16513 +#if IS_ENABLED(CONFIG_FUSE_FS)
16514 + return sb->s_magic == FUSE_SUPER_MAGIC;
16520 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16522 +#if IS_ENABLED(CONFIG_XFS_FS)
16523 + return sb->s_magic == XFS_SB_MAGIC;
16529 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16531 +#ifdef CONFIG_TMPFS
16532 + return sb->s_magic == TMPFS_MAGIC;
16538 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16540 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16541 + return !strcmp(au_sbtype(sb), "ecryptfs");
16547 +static inline int au_test_ramfs(struct super_block *sb)
16549 + return sb->s_magic == RAMFS_MAGIC;
16552 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16554 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16555 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16561 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16563 +#ifdef CONFIG_PROC_FS
16564 + return sb->s_magic == PROC_SUPER_MAGIC;
16570 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16572 +#ifdef CONFIG_SYSFS
16573 + return sb->s_magic == SYSFS_MAGIC;
16579 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16581 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16582 + return sb->s_magic == CONFIGFS_MAGIC;
16588 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16590 +#if IS_ENABLED(CONFIG_MINIX_FS)
16591 + return sb->s_magic == MINIX3_SUPER_MAGIC
16592 + || sb->s_magic == MINIX2_SUPER_MAGIC
16593 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16594 + || sb->s_magic == MINIX_SUPER_MAGIC
16595 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16601 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16603 +#if IS_ENABLED(CONFIG_FAT_FS)
16604 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16610 +static inline int au_test_msdos(struct super_block *sb)
16612 + return au_test_fat(sb);
16615 +static inline int au_test_vfat(struct super_block *sb)
16617 + return au_test_fat(sb);
16620 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16622 +#ifdef CONFIG_SECURITYFS
16623 + return sb->s_magic == SECURITYFS_MAGIC;
16629 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16631 +#if IS_ENABLED(CONFIG_SQUASHFS)
16632 + return sb->s_magic == SQUASHFS_MAGIC;
16638 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16640 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16641 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16647 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16649 +#if IS_ENABLED(CONFIG_XENFS)
16650 + return sb->s_magic == XENFS_SUPER_MAGIC;
16656 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16658 +#ifdef CONFIG_DEBUG_FS
16659 + return sb->s_magic == DEBUGFS_MAGIC;
16665 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16667 +#if IS_ENABLED(CONFIG_NILFS)
16668 + return sb->s_magic == NILFS_SUPER_MAGIC;
16674 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16676 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16677 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16683 +/* ---------------------------------------------------------------------- */
16685 + * they can't be an aufs branch.
16687 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16690 +#ifndef CONFIG_AUFS_BR_RAMFS
16691 + au_test_ramfs(sb) ||
16693 + au_test_procfs(sb)
16694 + || au_test_sysfs(sb)
16695 + || au_test_configfs(sb)
16696 + || au_test_debugfs(sb)
16697 + || au_test_securityfs(sb)
16698 + || au_test_xenfs(sb)
16699 + || au_test_ecryptfs(sb)
16700 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16701 + || au_test_aufs(sb); /* will be supported in next version */
16704 +static inline int au_test_fs_remote(struct super_block *sb)
16706 + return !au_test_tmpfs(sb)
16707 +#ifdef CONFIG_AUFS_BR_RAMFS
16708 + && !au_test_ramfs(sb)
16710 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16713 +/* ---------------------------------------------------------------------- */
16716 + * Note: these functions (below) are created after reading ->getattr() in all
16717 + * filesystems under linux/fs. it means we have to do so in every update...
16721 + * some filesystems require getattr to refresh the inode attributes before
16723 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16724 + * and leave the work for d_revalidate()
16726 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16728 + return au_test_nfs(sb)
16729 + || au_test_fuse(sb)
16730 + /* || au_test_btrfs(sb) */ /* untested */
16735 + * filesystems which don't maintain i_size or i_blocks.
16737 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16739 + return au_test_xfs(sb)
16740 + || au_test_btrfs(sb)
16741 + || au_test_ubifs(sb)
16742 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16743 + /* || au_test_minix(sb) */ /* untested */
16748 + * filesystems which don't store the correct value in some of their inode
16751 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16753 + return au_test_fs_bad_iattr_size(sb)
16754 + || au_test_fat(sb)
16755 + || au_test_msdos(sb)
16756 + || au_test_vfat(sb);
16759 +/* they don't check i_nlink in link(2) */
16760 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16762 + return au_test_tmpfs(sb)
16763 +#ifdef CONFIG_AUFS_BR_RAMFS
16764 + || au_test_ramfs(sb)
16766 + || au_test_ubifs(sb)
16767 + || au_test_hfsplus(sb);
16771 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16773 +static inline int au_test_fs_notime(struct super_block *sb)
16775 + return au_test_nfs(sb)
16776 + || au_test_fuse(sb)
16777 + || au_test_ubifs(sb)
16781 +/* temporary support for i#1 in cramfs */
16782 +static inline int au_test_fs_unique_ino(struct inode *inode)
16784 + if (au_test_cramfs(inode->i_sb))
16785 + return inode->i_ino != 1;
16789 +/* ---------------------------------------------------------------------- */
16792 + * the filesystem where the xino files placed must support i/o after unlink and
16793 + * maintain i_size and i_blocks.
16795 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16797 + return au_test_fs_remote(sb)
16798 + || au_test_fs_bad_iattr_size(sb)
16799 + /* don't want unnecessary work for xino */
16800 + || au_test_aufs(sb)
16801 + || au_test_ecryptfs(sb)
16802 + || au_test_nilfs(sb);
16805 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16807 + return au_test_tmpfs(sb)
16808 + || au_test_ramfs(sb);
16812 + * test if the @sb is real-readonly.
16814 +static inline int au_test_fs_rr(struct super_block *sb)
16816 + return au_test_squashfs(sb)
16817 + || au_test_iso9660(sb)
16818 + || au_test_cramfs(sb)
16819 + || au_test_romfs(sb);
16823 + * test if the @inode is nfs with 'noacl' option
16824 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16826 +static inline int au_test_nfs_noacl(struct inode *inode)
16828 + return au_test_nfs(inode->i_sb)
16829 + /* && IS_POSIXACL(inode) */
16830 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16833 +#endif /* __KERNEL__ */
16834 +#endif /* __AUFS_FSTYPE_H__ */
16835 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16836 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16837 +++ linux/fs/aufs/hbl.h 2019-03-05 12:13:00.139224339 +0100
16839 +/* SPDX-License-Identifier: GPL-2.0 */
16841 + * Copyright (C) 2017-2019 Junjiro R. Okajima
16843 + * This program, aufs is free software; you can redistribute it and/or modify
16844 + * it under the terms of the GNU General Public License as published by
16845 + * the Free Software Foundation; either version 2 of the License, or
16846 + * (at your option) any later version.
16848 + * This program is distributed in the hope that it will be useful,
16849 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16850 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16851 + * GNU General Public License for more details.
16853 + * You should have received a copy of the GNU General Public License
16854 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16858 + * helpers for hlist_bl.h
16861 +#ifndef __AUFS_HBL_H__
16862 +#define __AUFS_HBL_H__
16866 +#include <linux/list_bl.h>
16868 +static inline void au_hbl_add(struct hlist_bl_node *node,
16869 + struct hlist_bl_head *hbl)
16871 + hlist_bl_lock(hbl);
16872 + hlist_bl_add_head(node, hbl);
16873 + hlist_bl_unlock(hbl);
16876 +static inline void au_hbl_del(struct hlist_bl_node *node,
16877 + struct hlist_bl_head *hbl)
16879 + hlist_bl_lock(hbl);
16880 + hlist_bl_del(node);
16881 + hlist_bl_unlock(hbl);
16884 +#define au_hbl_for_each(pos, head) \
16885 + for (pos = hlist_bl_first(head); \
16889 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16891 + unsigned long cnt;
16892 + struct hlist_bl_node *pos;
16895 + hlist_bl_lock(hbl);
16896 + au_hbl_for_each(pos, hbl)
16898 + hlist_bl_unlock(hbl);
16902 +#endif /* __KERNEL__ */
16903 +#endif /* __AUFS_HBL_H__ */
16904 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16905 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16906 +++ linux/fs/aufs/hfsnotify.c 2019-03-05 12:13:00.139224339 +0100
16908 +// SPDX-License-Identifier: GPL-2.0
16910 + * Copyright (C) 2005-2019 Junjiro R. Okajima
16912 + * This program, aufs is free software; you can redistribute it and/or modify
16913 + * it under the terms of the GNU General Public License as published by
16914 + * the Free Software Foundation; either version 2 of the License, or
16915 + * (at your option) any later version.
16917 + * This program is distributed in the hope that it will be useful,
16918 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16919 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16920 + * GNU General Public License for more details.
16922 + * You should have received a copy of the GNU General Public License
16923 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16927 + * fsnotify for the lower directories
16932 +/* FS_IN_IGNORED is unnecessary */
16933 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16934 + | FS_CREATE | FS_EVENT_ON_CHILD);
16935 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16936 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16938 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16940 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16942 + /* AuDbg("here\n"); */
16943 + au_cache_free_hnotify(hn);
16944 + smp_mb__before_atomic(); /* for atomic64_dec */
16945 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16946 + wake_up(&au_hfsn_wq);
16949 +static int au_hfsn_alloc(struct au_hinode *hinode)
16952 + struct au_hnotify *hn;
16953 + struct super_block *sb;
16954 + struct au_branch *br;
16955 + struct fsnotify_mark *mark;
16956 + aufs_bindex_t bindex;
16958 + hn = hinode->hi_notify;
16959 + sb = hn->hn_aufs_inode->i_sb;
16960 + bindex = au_br_index(sb, hinode->hi_id);
16961 + br = au_sbr(sb, bindex);
16962 + AuDebugOn(!br->br_hfsn);
16964 + mark = &hn->hn_mark;
16965 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16966 + mark->mask = AuHfsnMask;
16968 + * by udba rename or rmdir, aufs assign a new inode to the known
16969 + * h_inode, so specify 1 to allow dups.
16972 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16978 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16980 + struct fsnotify_mark *mark;
16981 + unsigned long long ull;
16982 + struct fsnotify_group *group;
16984 + ull = atomic64_inc_return(&au_hfsn_ifree);
16987 + mark = &hn->hn_mark;
16988 + spin_lock(&mark->lock);
16989 + group = mark->group;
16990 + fsnotify_get_group(group);
16991 + spin_unlock(&mark->lock);
16993 + fsnotify_destroy_mark(mark, group);
16994 + fsnotify_put_mark(mark);
16995 + fsnotify_put_group(group);
16998 + /* free hn by myself */
17002 +/* ---------------------------------------------------------------------- */
17004 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
17006 + struct fsnotify_mark *mark;
17008 + mark = &hinode->hi_notify->hn_mark;
17009 + spin_lock(&mark->lock);
17011 + AuDebugOn(mark->mask & AuHfsnMask);
17012 + mark->mask |= AuHfsnMask;
17014 + AuDebugOn(!(mark->mask & AuHfsnMask));
17015 + mark->mask &= ~AuHfsnMask;
17017 + spin_unlock(&mark->lock);
17018 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
17021 +/* ---------------------------------------------------------------------- */
17023 +/* #define AuDbgHnotify */
17024 +#ifdef AuDbgHnotify
17025 +static char *au_hfsn_name(u32 mask)
17027 +#ifdef CONFIG_AUFS_DEBUG
17028 +#define test_ret(flag) \
17030 + if (mask & flag) \
17033 + test_ret(FS_ACCESS);
17034 + test_ret(FS_MODIFY);
17035 + test_ret(FS_ATTRIB);
17036 + test_ret(FS_CLOSE_WRITE);
17037 + test_ret(FS_CLOSE_NOWRITE);
17038 + test_ret(FS_OPEN);
17039 + test_ret(FS_MOVED_FROM);
17040 + test_ret(FS_MOVED_TO);
17041 + test_ret(FS_CREATE);
17042 + test_ret(FS_DELETE);
17043 + test_ret(FS_DELETE_SELF);
17044 + test_ret(FS_MOVE_SELF);
17045 + test_ret(FS_UNMOUNT);
17046 + test_ret(FS_Q_OVERFLOW);
17047 + test_ret(FS_IN_IGNORED);
17048 + test_ret(FS_ISDIR);
17049 + test_ret(FS_IN_ONESHOT);
17050 + test_ret(FS_EVENT_ON_CHILD);
17059 +/* ---------------------------------------------------------------------- */
17061 +static void au_hfsn_free_group(struct fsnotify_group *group)
17063 + struct au_br_hfsnotify *hfsn = group->private;
17065 + /* AuDbg("here\n"); */
17066 + au_kfree_try_rcu(hfsn);
17069 +static int au_hfsn_handle_event(struct fsnotify_group *group,
17070 + struct inode *inode,
17071 + u32 mask, const void *data, int data_type,
17072 + const unsigned char *file_name, u32 cookie,
17073 + struct fsnotify_iter_info *iter_info)
17076 + struct au_hnotify *hnotify;
17077 + struct inode *h_dir, *h_inode;
17078 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
17079 + struct fsnotify_mark *inode_mark;
17081 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
17084 + /* if FS_UNMOUNT happens, there must be another bug */
17085 + AuDebugOn(mask & FS_UNMOUNT);
17086 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
17091 +#ifdef AuDbgHnotify
17093 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
17094 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
17095 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
17096 + h_dir->i_ino, mask, au_hfsn_name(mask),
17097 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
17098 + /* WARN_ON(1); */
17103 + inode_mark = fsnotify_iter_inode_mark(iter_info);
17104 + AuDebugOn(!inode_mark);
17105 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
17106 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
17112 +static struct fsnotify_ops au_hfsn_ops = {
17113 + .handle_event = au_hfsn_handle_event,
17114 + .free_group_priv = au_hfsn_free_group,
17115 + .free_mark = au_hfsn_free_mark
17118 +/* ---------------------------------------------------------------------- */
17120 +static void au_hfsn_fin_br(struct au_branch *br)
17122 + struct au_br_hfsnotify *hfsn;
17124 + hfsn = br->br_hfsn;
17127 + fsnotify_put_group(hfsn->hfsn_group);
17132 +static int au_hfsn_init_br(struct au_branch *br, int perm)
17135 + struct fsnotify_group *group;
17136 + struct au_br_hfsnotify *hfsn;
17139 + br->br_hfsn = NULL;
17140 + if (!au_br_hnotifyable(perm))
17144 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
17145 + if (unlikely(!hfsn))
17149 + group = fsnotify_alloc_group(&au_hfsn_ops);
17150 + if (IS_ERR(group)) {
17151 + err = PTR_ERR(group);
17152 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
17156 + group->private = hfsn;
17157 + hfsn->hfsn_group = group;
17158 + br->br_hfsn = hfsn;
17159 + goto out; /* success */
17162 + au_kfree_try_rcu(hfsn);
17167 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
17172 + if (!br->br_hfsn)
17173 + err = au_hfsn_init_br(br, perm);
17178 +/* ---------------------------------------------------------------------- */
17180 +static void au_hfsn_fin(void)
17182 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
17183 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
17186 +const struct au_hnotify_op au_hnotify_op = {
17187 + .ctl = au_hfsn_ctl,
17188 + .alloc = au_hfsn_alloc,
17189 + .free = au_hfsn_free,
17191 + .fin = au_hfsn_fin,
17193 + .reset_br = au_hfsn_reset_br,
17194 + .fin_br = au_hfsn_fin_br,
17195 + .init_br = au_hfsn_init_br
17197 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
17198 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
17199 +++ linux/fs/aufs/hfsplus.c 2019-03-05 12:13:00.139224339 +0100
17201 +// SPDX-License-Identifier: GPL-2.0
17203 + * Copyright (C) 2010-2019 Junjiro R. Okajima
17205 + * This program, aufs is free software; you can redistribute it and/or modify
17206 + * it under the terms of the GNU General Public License as published by
17207 + * the Free Software Foundation; either version 2 of the License, or
17208 + * (at your option) any later version.
17210 + * This program is distributed in the hope that it will be useful,
17211 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17212 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17213 + * GNU General Public License for more details.
17215 + * You should have received a copy of the GNU General Public License
17216 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17220 + * special support for filesystems which acquires an inode mutex
17221 + * at final closing a file, eg, hfsplus.
17223 + * This trick is very simple and stupid, just to open the file before really
17224 + * necessary open to tell hfsplus that this is not the final closing.
17225 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
17226 + * and au_h_open_post() after releasing it.
17231 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
17234 + struct file *h_file;
17235 + struct dentry *h_dentry;
17237 + h_dentry = au_h_dptr(dentry, bindex);
17238 + AuDebugOn(!h_dentry);
17239 + AuDebugOn(d_is_negative(h_dentry));
17242 + if (au_test_hfsplus(h_dentry->d_sb)
17243 + && d_is_reg(h_dentry))
17244 + h_file = au_h_open(dentry, bindex,
17245 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17246 + /*file*/NULL, force_wr);
17250 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17251 + struct file *h_file)
17253 + struct au_branch *br;
17257 + br = au_sbr(dentry->d_sb, bindex);
17258 + au_lcnt_dec(&br->br_nfiles);
17261 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17262 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17263 +++ linux/fs/aufs/hnotify.c 2019-05-06 09:03:04.816810402 +0200
17265 +// SPDX-License-Identifier: GPL-2.0
17267 + * Copyright (C) 2005-2019 Junjiro R. Okajima
17269 + * This program, aufs is free software; you can redistribute it and/or modify
17270 + * it under the terms of the GNU General Public License as published by
17271 + * the Free Software Foundation; either version 2 of the License, or
17272 + * (at your option) any later version.
17274 + * This program is distributed in the hope that it will be useful,
17275 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17276 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17277 + * GNU General Public License for more details.
17279 + * You should have received a copy of the GNU General Public License
17280 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17284 + * abstraction to notify the direct changes on lower directories
17287 +/* #include <linux/iversion.h> */
17290 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17293 + struct au_hnotify *hn;
17296 + hn = au_cache_alloc_hnotify();
17298 + hn->hn_aufs_inode = inode;
17299 + hinode->hi_notify = hn;
17300 + err = au_hnotify_op.alloc(hinode);
17302 + if (unlikely(err)) {
17303 + hinode->hi_notify = NULL;
17304 + au_cache_free_hnotify(hn);
17306 + * The upper dir was removed by udba, but the same named
17307 + * dir left. In this case, aufs assigns a new inode
17308 + * number and set the monitor again.
17309 + * For the lower dir, the old monitor is still left.
17311 + if (err == -EEXIST)
17320 +void au_hn_free(struct au_hinode *hinode)
17322 + struct au_hnotify *hn;
17324 + hn = hinode->hi_notify;
17326 + hinode->hi_notify = NULL;
17327 + if (au_hnotify_op.free(hinode, hn))
17328 + au_cache_free_hnotify(hn);
17332 +/* ---------------------------------------------------------------------- */
17334 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17336 + if (hinode->hi_notify)
17337 + au_hnotify_op.ctl(hinode, do_set);
17340 +void au_hn_reset(struct inode *inode, unsigned int flags)
17342 + aufs_bindex_t bindex, bbot;
17343 + struct inode *hi;
17344 + struct dentry *iwhdentry;
17346 + bbot = au_ibbot(inode);
17347 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17348 + hi = au_h_iptr(inode, bindex);
17352 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17353 + iwhdentry = au_hi_wh(inode, bindex);
17357 + au_set_h_iptr(inode, bindex, NULL, 0);
17358 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17359 + flags & ~AuHi_XINO);
17362 + /* inode_unlock(hi); */
17366 +/* ---------------------------------------------------------------------- */
17368 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17371 + aufs_bindex_t bindex, bbot, bfound, btop;
17372 + struct inode *h_i;
17375 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17376 + pr_warn("branch root dir was changed\n");
17381 + bbot = au_ibbot(inode);
17382 + btop = au_ibtop(inode);
17383 +#if 0 /* reserved for future use */
17384 + if (bindex == bbot) {
17385 + /* keep this ino in rename case */
17389 + for (bindex = btop; bindex <= bbot; bindex++)
17390 + if (au_h_iptr(inode, bindex) == h_inode) {
17397 + for (bindex = btop; bindex <= bbot; bindex++) {
17398 + h_i = au_h_iptr(inode, bindex);
17402 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17403 + /* ignore this error */
17404 + /* bad action? */
17407 + /* children inode number will be broken */
17414 +static int hn_gen_tree(struct dentry *dentry)
17416 + int err, i, j, ndentry;
17417 + struct au_dcsub_pages dpages;
17418 + struct au_dpage *dpage;
17419 + struct dentry **dentries;
17421 + err = au_dpages_init(&dpages, GFP_NOFS);
17422 + if (unlikely(err))
17424 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17425 + if (unlikely(err))
17428 + for (i = 0; i < dpages.ndpage; i++) {
17429 + dpage = dpages.dpages + i;
17430 + dentries = dpage->dentries;
17431 + ndentry = dpage->ndentry;
17432 + for (j = 0; j < ndentry; j++) {
17433 + struct dentry *d;
17440 + if (d_really_is_positive(d))
17441 + /* todo: reset children xino?
17442 + cached children only? */
17443 + au_iigen_dec(d_inode(d));
17448 + au_dpages_free(&dpages);
17451 + /* discard children */
17452 + dentry_unhash(dentry);
17460 + * return 0 if processed.
17462 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17463 + const unsigned int isdir)
17466 + struct dentry *d;
17467 + struct qstr *dname;
17470 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17471 + pr_warn("branch root dir was changed\n");
17477 + AuDebugOn(!name);
17478 + au_iigen_dec(inode);
17479 + spin_lock(&inode->i_lock);
17480 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17481 + spin_lock(&d->d_lock);
17482 + dname = &d->d_name;
17483 + if (dname->len != nlen
17484 + && memcmp(dname->name, name, nlen)) {
17485 + spin_unlock(&d->d_lock);
17490 + spin_unlock(&d->d_lock);
17493 + spin_unlock(&inode->i_lock);
17495 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17496 + d = d_find_any_alias(inode);
17498 + au_iigen_dec(inode);
17502 + spin_lock(&d->d_lock);
17503 + dname = &d->d_name;
17504 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17505 + spin_unlock(&d->d_lock);
17506 + err = hn_gen_tree(d);
17507 + spin_lock(&d->d_lock);
17509 + spin_unlock(&d->d_lock);
17518 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17522 + if (IS_ROOT(dentry)) {
17523 + pr_warn("branch root dir was changed\n");
17529 + au_digen_dec(dentry);
17530 + if (d_really_is_positive(dentry))
17531 + au_iigen_dec(d_inode(dentry));
17533 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17534 + if (d_really_is_positive(dentry))
17535 + err = hn_gen_tree(dentry);
17542 +/* ---------------------------------------------------------------------- */
17544 +/* hnotify job flags */
17545 +#define AuHnJob_XINO0 1
17546 +#define AuHnJob_GEN (1 << 1)
17547 +#define AuHnJob_DIRENT (1 << 2)
17548 +#define AuHnJob_ISDIR (1 << 3)
17549 +#define AuHnJob_TRYXINO0 (1 << 4)
17550 +#define AuHnJob_MNTPNT (1 << 5)
17551 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17552 +#define au_fset_hnjob(flags, name) \
17553 + do { (flags) |= AuHnJob_##name; } while (0)
17554 +#define au_fclr_hnjob(flags, name) \
17555 + do { (flags) &= ~AuHnJob_##name; } while (0)
17563 +struct au_hnotify_args {
17564 + struct inode *h_dir, *dir, *h_child_inode;
17566 + unsigned int flags[AuHnLast];
17567 + unsigned int h_child_nlen;
17568 + char h_child_name[];
17571 +struct hn_job_args {
17572 + unsigned int flags;
17573 + struct inode *inode, *h_inode, *dir, *h_dir;
17574 + struct dentry *dentry;
17579 +static int hn_job(struct hn_job_args *a)
17581 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17585 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17586 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17588 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17591 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17592 + if (!a->h_inode->i_nlink
17593 + && !(a->h_inode->i_state & I_LINKABLE))
17594 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17595 + inode_unlock_shared(a->h_inode);
17598 + /* make the generation obsolete */
17599 + if (au_ftest_hnjob(a->flags, GEN)) {
17602 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17604 + if (e && a->dentry)
17605 + hn_gen_by_name(a->dentry, isdir);
17606 + /* ignore this error */
17609 + /* make dir entries obsolete */
17610 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17611 + struct au_vdir *vdir;
17613 + vdir = au_ivdir(a->inode);
17615 + vdir->vd_jiffy = 0;
17616 + /* IMustLock(a->inode); */
17617 + /* inode_inc_iversion(a->inode); */
17620 + /* can do nothing but warn */
17621 + if (au_ftest_hnjob(a->flags, MNTPNT)
17623 + && d_mountpoint(a->dentry))
17624 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17629 +/* ---------------------------------------------------------------------- */
17631 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17632 + struct inode *dir)
17634 + struct dentry *dentry, *d, *parent;
17635 + struct qstr *dname;
17637 + parent = d_find_any_alias(dir);
17642 + spin_lock(&parent->d_lock);
17643 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17644 + /* AuDbg("%pd\n", d); */
17645 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17646 + dname = &d->d_name;
17647 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17648 + goto cont_unlock;
17652 + goto cont_unlock;
17653 + if (au_dcount(d) > 0) {
17654 + dentry = dget_dlock(d);
17655 + spin_unlock(&d->d_lock);
17660 + spin_unlock(&d->d_lock);
17662 + spin_unlock(&parent->d_lock);
17666 + di_write_lock_child(dentry);
17671 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17672 + aufs_bindex_t bindex, ino_t h_ino)
17674 + struct inode *inode;
17679 + err = au_xino_read(sb, bindex, h_ino, &ino);
17681 + inode = ilookup(sb, ino);
17685 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17686 + pr_warn("wrong root branch\n");
17692 + ii_write_lock_child(inode);
17698 +static void au_hn_bh(void *_args)
17700 + struct au_hnotify_args *a = _args;
17701 + struct super_block *sb;
17702 + aufs_bindex_t bindex, bbot, bfound;
17703 + unsigned char xino, try_iput;
17705 + struct inode *inode;
17707 + struct hn_job_args args;
17708 + struct dentry *dentry;
17709 + struct au_sbinfo *sbinfo;
17711 + AuDebugOn(!_args);
17712 + AuDebugOn(!a->h_dir);
17713 + AuDebugOn(!a->dir);
17714 + AuDebugOn(!a->mask);
17715 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17716 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17717 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17722 + * do not lock a->dir->i_mutex here
17723 + * because of d_revalidate() may cause a deadlock.
17725 + sb = a->dir->i_sb;
17727 + sbinfo = au_sbi(sb);
17728 + AuDebugOn(!sbinfo);
17729 + si_write_lock(sb, AuLock_NOPLMW);
17731 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17732 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17733 + case FS_MOVED_FROM:
17734 + case FS_MOVED_TO:
17735 + AuWarn1("DIRREN with UDBA may not work correctly "
17736 + "for the direct rename(2)\n");
17739 + ii_read_lock_parent(a->dir);
17741 + bbot = au_ibbot(a->dir);
17742 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17743 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17747 + ii_read_unlock(a->dir);
17748 + if (unlikely(bfound < 0))
17751 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17753 + if (a->h_child_inode)
17754 + h_ino = a->h_child_inode->i_ino;
17756 + if (a->h_child_nlen
17757 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17758 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17759 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17762 + if (dentry && d_really_is_positive(dentry))
17763 + inode = d_inode(dentry);
17764 + if (xino && !inode && h_ino
17765 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17766 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17767 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17768 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17772 + args.flags = a->flags[AuHn_CHILD];
17773 + args.dentry = dentry;
17774 + args.inode = inode;
17775 + args.h_inode = a->h_child_inode;
17776 + args.dir = a->dir;
17777 + args.h_dir = a->h_dir;
17778 + args.h_name = a->h_child_name;
17779 + args.h_nlen = a->h_child_nlen;
17780 + err = hn_job(&args);
17782 + if (au_di(dentry))
17783 + di_write_unlock(dentry);
17786 + if (inode && try_iput) {
17787 + ii_write_unlock(inode);
17791 + ii_write_lock_parent(a->dir);
17792 + args.flags = a->flags[AuHn_PARENT];
17793 + args.dentry = NULL;
17794 + args.inode = a->dir;
17795 + args.h_inode = a->h_dir;
17797 + args.h_dir = NULL;
17798 + args.h_name = NULL;
17800 + err = hn_job(&args);
17801 + ii_write_unlock(a->dir);
17804 + iput(a->h_child_inode);
17807 + si_write_unlock(sb);
17808 + au_nwt_done(&sbinfo->si_nowait);
17812 +/* ---------------------------------------------------------------------- */
17814 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17815 + struct qstr *h_child_qstr, struct inode *h_child_inode)
17818 + unsigned int flags[AuHnLast], f;
17819 + unsigned char isdir, isroot, wh;
17820 + struct inode *dir;
17821 + struct au_hnotify_args *args;
17822 + char *p, *h_child_name;
17825 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17826 + dir = igrab(hnotify->hn_aufs_inode);
17830 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17832 + h_child_name = (void *)h_child_qstr->name;
17833 + len = h_child_qstr->len;
17834 + if (h_child_name) {
17835 + if (len > AUFS_WH_PFX_LEN
17836 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17837 + h_child_name += AUFS_WH_PFX_LEN;
17838 + len -= AUFS_WH_PFX_LEN;
17844 + if (h_child_inode)
17845 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17846 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17847 + flags[AuHn_CHILD] = 0;
17849 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17850 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17851 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17852 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
17853 + case FS_MOVED_FROM:
17854 + case FS_MOVED_TO:
17855 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17856 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17859 + AuDebugOn(!h_child_name);
17864 + * aufs never be able to get this child inode.
17865 + * revalidation should be in d_revalidate()
17866 + * by checking i_nlink, i_generation or d_unhashed().
17868 + AuDebugOn(!h_child_name);
17869 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17870 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17878 + h_child_inode = NULL;
17881 + /* iput() and kfree() will be called in au_hnotify() */
17882 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17883 + if (unlikely(!args)) {
17884 + AuErr1("no memory\n");
17888 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17889 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17890 + args->mask = mask;
17892 + args->h_dir = igrab(h_dir);
17893 + if (h_child_inode)
17894 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17895 + args->h_child_inode = h_child_inode;
17896 + args->h_child_nlen = len;
17898 + p = (void *)args;
17899 + p += sizeof(*args);
17900 + memcpy(p, h_child_name, len);
17904 + /* NFS fires the event for silly-renamed one from kworker */
17906 + if (!dir->i_nlink
17907 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17909 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17910 + if (unlikely(err)) {
17911 + pr_err("wkq %d\n", err);
17912 + iput(args->h_child_inode);
17913 + iput(args->h_dir);
17915 + au_kfree_rcu(args);
17922 +/* ---------------------------------------------------------------------- */
17924 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17928 + AuDebugOn(!(udba & AuOptMask_UDBA));
17931 + if (au_hnotify_op.reset_br)
17932 + err = au_hnotify_op.reset_br(udba, br, perm);
17937 +int au_hnotify_init_br(struct au_branch *br, int perm)
17942 + if (au_hnotify_op.init_br)
17943 + err = au_hnotify_op.init_br(br, perm);
17948 +void au_hnotify_fin_br(struct au_branch *br)
17950 + if (au_hnotify_op.fin_br)
17951 + au_hnotify_op.fin_br(br);
17954 +static void au_hn_destroy_cache(void)
17956 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17957 + au_cache[AuCache_HNOTIFY] = NULL;
17960 +int __init au_hnotify_init(void)
17965 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17966 + if (au_cache[AuCache_HNOTIFY]) {
17968 + if (au_hnotify_op.init)
17969 + err = au_hnotify_op.init();
17970 + if (unlikely(err))
17971 + au_hn_destroy_cache();
17977 +void au_hnotify_fin(void)
17979 + if (au_hnotify_op.fin)
17980 + au_hnotify_op.fin();
17982 + /* cf. au_cache_fin() */
17983 + if (au_cache[AuCache_HNOTIFY])
17984 + au_hn_destroy_cache();
17986 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17987 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17988 +++ linux/fs/aufs/iinfo.c 2019-03-05 12:13:00.139224339 +0100
17990 +// SPDX-License-Identifier: GPL-2.0
17992 + * Copyright (C) 2005-2019 Junjiro R. Okajima
17994 + * This program, aufs is free software; you can redistribute it and/or modify
17995 + * it under the terms of the GNU General Public License as published by
17996 + * the Free Software Foundation; either version 2 of the License, or
17997 + * (at your option) any later version.
17999 + * This program is distributed in the hope that it will be useful,
18000 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18001 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18002 + * GNU General Public License for more details.
18004 + * You should have received a copy of the GNU General Public License
18005 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18009 + * inode private data
18014 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
18016 + struct inode *h_inode;
18017 + struct au_hinode *hinode;
18019 + IiMustAnyLock(inode);
18021 + hinode = au_hinode(au_ii(inode), bindex);
18022 + h_inode = hinode->hi_inode;
18023 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
18027 +/* todo: hard/soft set? */
18028 +void au_hiput(struct au_hinode *hinode)
18030 + au_hn_free(hinode);
18031 + dput(hinode->hi_whdentry);
18032 + iput(hinode->hi_inode);
18035 +unsigned int au_hi_flags(struct inode *inode, int isdir)
18037 + unsigned int flags;
18038 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
18041 + if (au_opt_test(mnt_flags, XINO))
18042 + au_fset_hi(flags, XINO);
18043 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
18044 + au_fset_hi(flags, HNOTIFY);
18048 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18049 + struct inode *h_inode, unsigned int flags)
18051 + struct au_hinode *hinode;
18052 + struct inode *hi;
18053 + struct au_iinfo *iinfo = au_ii(inode);
18055 + IiMustWriteLock(inode);
18057 + hinode = au_hinode(iinfo, bindex);
18058 + hi = hinode->hi_inode;
18059 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
18062 + au_hiput(hinode);
18063 + hinode->hi_inode = h_inode;
18066 + struct super_block *sb = inode->i_sb;
18067 + struct au_branch *br;
18069 + AuDebugOn(inode->i_mode
18070 + && (h_inode->i_mode & S_IFMT)
18071 + != (inode->i_mode & S_IFMT));
18072 + if (bindex == iinfo->ii_btop)
18073 + au_cpup_igen(inode, h_inode);
18074 + br = au_sbr(sb, bindex);
18075 + hinode->hi_id = br->br_id;
18076 + if (au_ftest_hi(flags, XINO)) {
18077 + err = au_xino_write(sb, bindex, h_inode->i_ino,
18079 + if (unlikely(err))
18080 + AuIOErr1("failed au_xino_write() %d\n", err);
18083 + if (au_ftest_hi(flags, HNOTIFY)
18084 + && au_br_hnotifyable(br->br_perm)) {
18085 + err = au_hn_alloc(hinode, inode);
18086 + if (unlikely(err))
18087 + AuIOErr1("au_hn_alloc() %d\n", err);
18092 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18093 + struct dentry *h_wh)
18095 + struct au_hinode *hinode;
18097 + IiMustWriteLock(inode);
18099 + hinode = au_hinode(au_ii(inode), bindex);
18100 + AuDebugOn(hinode->hi_whdentry);
18101 + hinode->hi_whdentry = h_wh;
18104 +void au_update_iigen(struct inode *inode, int half)
18106 + struct au_iinfo *iinfo;
18107 + struct au_iigen *iigen;
18108 + unsigned int sigen;
18110 + sigen = au_sigen(inode->i_sb);
18111 + iinfo = au_ii(inode);
18112 + iigen = &iinfo->ii_generation;
18113 + spin_lock(&iigen->ig_spin);
18114 + iigen->ig_generation = sigen;
18116 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
18118 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
18119 + spin_unlock(&iigen->ig_spin);
18122 +/* it may be called at remount time, too */
18123 +void au_update_ibrange(struct inode *inode, int do_put_zero)
18125 + struct au_iinfo *iinfo;
18126 + aufs_bindex_t bindex, bbot;
18128 + AuDebugOn(au_is_bad_inode(inode));
18129 + IiMustWriteLock(inode);
18131 + iinfo = au_ii(inode);
18132 + if (do_put_zero && iinfo->ii_btop >= 0) {
18133 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18135 + struct inode *h_i;
18137 + h_i = au_hinode(iinfo, bindex)->hi_inode;
18140 + && !(h_i->i_state & I_LINKABLE))
18141 + au_set_h_iptr(inode, bindex, NULL, 0);
18145 + iinfo->ii_btop = -1;
18146 + iinfo->ii_bbot = -1;
18147 + bbot = au_sbbot(inode->i_sb);
18148 + for (bindex = 0; bindex <= bbot; bindex++)
18149 + if (au_hinode(iinfo, bindex)->hi_inode) {
18150 + iinfo->ii_btop = bindex;
18153 + if (iinfo->ii_btop >= 0)
18154 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
18155 + if (au_hinode(iinfo, bindex)->hi_inode) {
18156 + iinfo->ii_bbot = bindex;
18159 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
18162 +/* ---------------------------------------------------------------------- */
18164 +void au_icntnr_init_once(void *_c)
18166 + struct au_icntnr *c = _c;
18167 + struct au_iinfo *iinfo = &c->iinfo;
18169 + spin_lock_init(&iinfo->ii_generation.ig_spin);
18170 + au_rw_init(&iinfo->ii_rwsem);
18171 + inode_init_once(&c->vfs_inode);
18174 +void au_hinode_init(struct au_hinode *hinode)
18176 + hinode->hi_inode = NULL;
18177 + hinode->hi_id = -1;
18178 + au_hn_init(hinode);
18179 + hinode->hi_whdentry = NULL;
18182 +int au_iinfo_init(struct inode *inode)
18184 + struct au_iinfo *iinfo;
18185 + struct super_block *sb;
18186 + struct au_hinode *hi;
18189 + sb = inode->i_sb;
18190 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18191 + nbr = au_sbbot(sb) + 1;
18192 + if (unlikely(nbr <= 0))
18194 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
18196 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
18198 + iinfo->ii_hinode = hi;
18199 + for (i = 0; i < nbr; i++, hi++)
18200 + au_hinode_init(hi);
18202 + iinfo->ii_generation.ig_generation = au_sigen(sb);
18203 + iinfo->ii_btop = -1;
18204 + iinfo->ii_bbot = -1;
18205 + iinfo->ii_vdir = NULL;
18211 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
18214 + struct au_hinode *hip;
18216 + AuRwMustWriteLock(&iinfo->ii_rwsem);
18219 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
18222 + iinfo->ii_hinode = hip;
18223 + i = iinfo->ii_bbot + 1;
18225 + for (; i < nbr; i++, hip++)
18226 + au_hinode_init(hip);
18233 +void au_iinfo_fin(struct inode *inode)
18235 + struct au_iinfo *iinfo;
18236 + struct au_hinode *hi;
18237 + struct super_block *sb;
18238 + aufs_bindex_t bindex, bbot;
18239 + const unsigned char unlinked = !inode->i_nlink;
18241 + AuDebugOn(au_is_bad_inode(inode));
18243 + sb = inode->i_sb;
18244 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
18245 + if (si_pid_test(sb))
18246 + au_xino_delete_inode(inode, unlinked);
18249 + * it is safe to hide the dependency between sbinfo and
18253 + si_noflush_read_lock(sb);
18254 + au_xino_delete_inode(inode, unlinked);
18255 + si_read_unlock(sb);
18259 + iinfo = au_ii(inode);
18260 + if (iinfo->ii_vdir)
18261 + au_vdir_free(iinfo->ii_vdir);
18263 + bindex = iinfo->ii_btop;
18264 + if (bindex >= 0) {
18265 + hi = au_hinode(iinfo, bindex);
18266 + bbot = iinfo->ii_bbot;
18267 + while (bindex++ <= bbot) {
18268 + if (hi->hi_inode)
18273 + au_kfree_rcu(iinfo->ii_hinode);
18274 + AuRwDestroy(&iinfo->ii_rwsem);
18276 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18277 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18278 +++ linux/fs/aufs/inode.c 2019-05-06 09:03:04.820143837 +0200
18280 +// SPDX-License-Identifier: GPL-2.0
18282 + * Copyright (C) 2005-2019 Junjiro R. Okajima
18284 + * This program, aufs is free software; you can redistribute it and/or modify
18285 + * it under the terms of the GNU General Public License as published by
18286 + * the Free Software Foundation; either version 2 of the License, or
18287 + * (at your option) any later version.
18289 + * This program is distributed in the hope that it will be useful,
18290 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18291 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18292 + * GNU General Public License for more details.
18294 + * You should have received a copy of the GNU General Public License
18295 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18299 + * inode functions
18302 +#include <linux/iversion.h>
18305 +struct inode *au_igrab(struct inode *inode)
18308 + AuDebugOn(!atomic_read(&inode->i_count));
18314 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18316 + au_cpup_attr_all(inode, /*force*/0);
18317 + au_update_iigen(inode, /*half*/1);
18319 + inode_inc_iversion(inode);
18322 +static int au_ii_refresh(struct inode *inode, int *update)
18326 + aufs_bindex_t bindex, new_bindex;
18327 + struct super_block *sb;
18328 + struct au_iinfo *iinfo;
18329 + struct au_hinode *p, *q, tmp;
18331 + AuDebugOn(au_is_bad_inode(inode));
18332 + IiMustWriteLock(inode);
18335 + sb = inode->i_sb;
18336 + nbr = au_sbbot(sb) + 1;
18337 + type = inode->i_mode & S_IFMT;
18338 + iinfo = au_ii(inode);
18339 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18340 + if (unlikely(err))
18343 + AuDebugOn(iinfo->ii_btop < 0);
18344 + p = au_hinode(iinfo, iinfo->ii_btop);
18345 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18347 + if (!p->hi_inode)
18350 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18351 + new_bindex = au_br_index(sb, p->hi_id);
18352 + if (new_bindex == bindex)
18355 + if (new_bindex < 0) {
18358 + p->hi_inode = NULL;
18362 + if (new_bindex < iinfo->ii_btop)
18363 + iinfo->ii_btop = new_bindex;
18364 + if (iinfo->ii_bbot < new_bindex)
18365 + iinfo->ii_bbot = new_bindex;
18366 + /* swap two lower inode, and loop again */
18367 + q = au_hinode(iinfo, new_bindex);
18371 + if (tmp.hi_inode) {
18376 + au_update_ibrange(inode, /*do_put_zero*/0);
18377 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18378 + e = au_dy_irefresh(inode);
18379 + if (unlikely(e && !err))
18387 +void au_refresh_iop(struct inode *inode, int force_getattr)
18390 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18391 + const struct inode_operations *iop
18392 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18394 + if (inode->i_op == iop)
18397 + switch (inode->i_mode & S_IFMT) {
18399 + type = AuIop_DIR;
18402 + type = AuIop_SYMLINK;
18405 + type = AuIop_OTHER;
18409 + inode->i_op = iop + type;
18410 + /* unnecessary smp_wmb() */
18413 +int au_refresh_hinode_self(struct inode *inode)
18417 + err = au_ii_refresh(inode, &update);
18419 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18425 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18427 + int err, e, update;
18428 + unsigned int flags;
18430 + aufs_bindex_t bindex, bbot;
18431 + unsigned char isdir;
18432 + struct au_hinode *p;
18433 + struct au_iinfo *iinfo;
18435 + err = au_ii_refresh(inode, &update);
18436 + if (unlikely(err))
18440 + iinfo = au_ii(inode);
18441 + p = au_hinode(iinfo, iinfo->ii_btop);
18442 + mode = (inode->i_mode & S_IFMT);
18443 + isdir = S_ISDIR(mode);
18444 + flags = au_hi_flags(inode, isdir);
18445 + bbot = au_dbbot(dentry);
18446 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18447 + struct inode *h_i, *h_inode;
18448 + struct dentry *h_d;
18450 + h_d = au_h_dptr(dentry, bindex);
18451 + if (!h_d || d_is_negative(h_d))
18454 + h_inode = d_inode(h_d);
18455 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18456 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18457 + h_i = au_h_iptr(inode, bindex);
18459 + if (h_i == h_inode)
18465 + if (bindex < iinfo->ii_btop)
18466 + iinfo->ii_btop = bindex;
18467 + if (iinfo->ii_bbot < bindex)
18468 + iinfo->ii_bbot = bindex;
18469 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18472 + au_update_ibrange(inode, /*do_put_zero*/0);
18473 + e = au_dy_irefresh(inode);
18474 + if (unlikely(e && !err))
18477 + au_refresh_hinode_attr(inode, update && isdir);
18484 +static int set_inode(struct inode *inode, struct dentry *dentry)
18487 + unsigned int flags;
18489 + aufs_bindex_t bindex, btop, btail;
18490 + unsigned char isdir;
18491 + struct dentry *h_dentry;
18492 + struct inode *h_inode;
18493 + struct au_iinfo *iinfo;
18494 + struct inode_operations *iop;
18496 + IiMustWriteLock(inode);
18500 + iop = au_sbi(inode->i_sb)->si_iop_array;
18501 + btop = au_dbtop(dentry);
18502 + h_dentry = au_h_dptr(dentry, btop);
18503 + h_inode = d_inode(h_dentry);
18504 + mode = h_inode->i_mode;
18505 + switch (mode & S_IFMT) {
18507 + btail = au_dbtail(dentry);
18508 + inode->i_op = iop + AuIop_OTHER;
18509 + inode->i_fop = &aufs_file_fop;
18510 + err = au_dy_iaop(inode, btop, h_inode);
18511 + if (unlikely(err))
18516 + btail = au_dbtaildir(dentry);
18517 + inode->i_op = iop + AuIop_DIR;
18518 + inode->i_fop = &aufs_dir_fop;
18521 + btail = au_dbtail(dentry);
18522 + inode->i_op = iop + AuIop_SYMLINK;
18528 + btail = au_dbtail(dentry);
18529 + inode->i_op = iop + AuIop_OTHER;
18530 + init_special_inode(inode, mode, h_inode->i_rdev);
18533 + AuIOErr("Unknown file type 0%o\n", mode);
18538 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18539 + flags = au_hi_flags(inode, isdir);
18540 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18541 + && au_ftest_hi(flags, HNOTIFY)
18542 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18543 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18544 + au_fclr_hi(flags, HNOTIFY);
18545 + iinfo = au_ii(inode);
18546 + iinfo->ii_btop = btop;
18547 + iinfo->ii_bbot = btail;
18548 + for (bindex = btop; bindex <= btail; bindex++) {
18549 + h_dentry = au_h_dptr(dentry, bindex);
18551 + au_set_h_iptr(inode, bindex,
18552 + au_igrab(d_inode(h_dentry)), flags);
18554 + au_cpup_attr_all(inode, /*force*/1);
18556 + * to force calling aufs_get_acl() every time,
18557 + * do not call cache_no_acl() for aufs inode.
18565 + * successful returns with iinfo write_locked
18567 + * zero: success, matched
18568 + * plus: no error, but unmatched
18570 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18573 + unsigned int gen, igflags;
18574 + aufs_bindex_t bindex, bbot;
18575 + struct inode *h_inode, *h_dinode;
18576 + struct dentry *h_dentry;
18579 + * before this function, if aufs got any iinfo lock, it must be only
18580 + * one, the parent dir.
18581 + * it can happen by UDBA and the obsoleted inode number.
18584 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18588 + ii_write_lock_new_child(inode);
18589 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18590 + h_dinode = d_inode(h_dentry);
18591 + bbot = au_ibbot(inode);
18592 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18593 + h_inode = au_h_iptr(inode, bindex);
18594 + if (!h_inode || h_inode != h_dinode)
18598 + gen = au_iigen(inode, &igflags);
18599 + if (gen == au_digen(dentry)
18600 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18603 + /* fully refresh inode using dentry */
18604 + err = au_refresh_hinode(inode, dentry);
18606 + au_update_iigen(inode, /*half*/0);
18610 + if (unlikely(err))
18611 + ii_write_unlock(inode);
18616 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18617 + unsigned int d_type, ino_t *ino)
18620 + const int isnondir = d_type != DT_DIR;
18622 + /* prevent hardlinked inode number from race condition */
18624 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18625 + if (unlikely(err))
18629 + err = au_xino_read(sb, bindex, h_ino, ino);
18630 + if (unlikely(err))
18631 + goto out_xinondir;
18635 + *ino = au_xino_new_ino(sb);
18636 + if (unlikely(!*ino))
18637 + goto out_xinondir;
18638 + err = au_xino_write(sb, bindex, h_ino, *ino);
18639 + if (unlikely(err))
18640 + goto out_xinondir;
18644 + if (isnondir && idx >= 0)
18645 + au_xinondir_leave(sb, bindex, h_ino, idx);
18650 +/* successful returns with iinfo write_locked */
18651 +/* todo: return with unlocked? */
18652 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18654 + struct inode *inode, *h_inode;
18655 + struct dentry *h_dentry;
18656 + struct super_block *sb;
18657 + ino_t h_ino, ino;
18658 + int err, idx, hlinked;
18659 + aufs_bindex_t btop;
18661 + sb = dentry->d_sb;
18662 + btop = au_dbtop(dentry);
18663 + h_dentry = au_h_dptr(dentry, btop);
18664 + h_inode = d_inode(h_dentry);
18665 + h_ino = h_inode->i_ino;
18666 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18670 + * stop 'race'-ing between hardlinks under different
18674 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18675 + inode = ERR_PTR(err);
18676 + if (unlikely(err))
18680 + err = au_xino_read(sb, btop, h_ino, &ino);
18681 + inode = ERR_PTR(err);
18682 + if (unlikely(err))
18683 + goto out_xinondir;
18686 + ino = au_xino_new_ino(sb);
18687 + if (unlikely(!ino)) {
18688 + inode = ERR_PTR(-EIO);
18689 + goto out_xinondir;
18693 + AuDbg("i%lu\n", (unsigned long)ino);
18694 + inode = au_iget_locked(sb, ino);
18695 + err = PTR_ERR(inode);
18696 + if (IS_ERR(inode))
18697 + goto out_xinondir;
18699 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18700 + if (inode->i_state & I_NEW) {
18701 + ii_write_lock_new_child(inode);
18702 + err = set_inode(inode, dentry);
18704 + unlock_new_inode(inode);
18705 + goto out_xinondir; /* success */
18709 + * iget_failed() calls iput(), but we need to call
18710 + * ii_write_unlock() after iget_failed(). so dirty hack for
18713 + atomic_inc(&inode->i_count);
18714 + iget_failed(inode);
18715 + ii_write_unlock(inode);
18716 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18717 + /* ignore this error */
18719 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18721 + * horrible race condition between lookup, readdir and copyup
18722 + * (or something).
18724 + if (hlinked && idx >= 0)
18725 + au_xinondir_leave(sb, btop, h_ino, idx);
18726 + err = reval_inode(inode, dentry);
18727 + if (unlikely(err < 0)) {
18732 + goto out; /* success */
18733 + else if (hlinked && idx >= 0) {
18734 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18735 + if (unlikely(err)) {
18737 + inode = ERR_PTR(err);
18743 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18744 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18745 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18746 + btop, au_sbtype(h_dentry->d_sb), dentry,
18747 + (unsigned long)h_ino, (unsigned long)ino);
18749 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18752 + if (hlinked && idx >= 0)
18753 + au_xinondir_leave(sb, btop, h_ino, idx);
18759 + inode = ERR_PTR(err);
18761 + if (hlinked && idx >= 0)
18762 + au_xinondir_leave(sb, btop, h_ino, idx);
18767 +/* ---------------------------------------------------------------------- */
18769 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18770 + struct inode *inode)
18773 + struct inode *hi;
18775 + err = au_br_rdonly(au_sbr(sb, bindex));
18777 + /* pseudo-link after flushed may happen out of bounds */
18780 + && au_ibtop(inode) <= bindex
18781 + && bindex <= au_ibbot(inode)) {
18783 + * permission check is unnecessary since vfsub routine
18784 + * will be called later
18786 + hi = au_h_iptr(inode, bindex);
18788 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18794 +int au_test_h_perm(struct inode *h_inode, int mask)
18796 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18798 + return inode_permission(h_inode, mask);
18801 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18803 + if (au_test_nfs(h_inode->i_sb)
18804 + && (mask & MAY_WRITE)
18805 + && S_ISDIR(h_inode->i_mode))
18806 + mask |= MAY_READ; /* force permission check */
18807 + return au_test_h_perm(h_inode, mask);
18809 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18810 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18811 +++ linux/fs/aufs/inode.h 2019-03-05 12:13:00.142557771 +0100
18813 +/* SPDX-License-Identifier: GPL-2.0 */
18815 + * Copyright (C) 2005-2019 Junjiro R. Okajima
18817 + * This program, aufs is free software; you can redistribute it and/or modify
18818 + * it under the terms of the GNU General Public License as published by
18819 + * the Free Software Foundation; either version 2 of the License, or
18820 + * (at your option) any later version.
18822 + * This program is distributed in the hope that it will be useful,
18823 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18824 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18825 + * GNU General Public License for more details.
18827 + * You should have received a copy of the GNU General Public License
18828 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18832 + * inode operations
18835 +#ifndef __AUFS_INODE_H__
18836 +#define __AUFS_INODE_H__
18840 +#include <linux/fsnotify.h>
18841 +#include "rwsem.h"
18845 +struct au_hnotify {
18846 +#ifdef CONFIG_AUFS_HNOTIFY
18847 +#ifdef CONFIG_AUFS_HFSNOTIFY
18848 + /* never use fsnotify_add_vfsmount_mark() */
18849 + struct fsnotify_mark hn_mark;
18851 + struct inode *hn_aufs_inode; /* no get/put */
18852 + struct rcu_head rcu;
18854 +} ____cacheline_aligned_in_smp;
18856 +struct au_hinode {
18857 + struct inode *hi_inode;
18858 + aufs_bindex_t hi_id;
18859 +#ifdef CONFIG_AUFS_HNOTIFY
18860 + struct au_hnotify *hi_notify;
18863 + /* reference to the copied-up whiteout with get/put */
18864 + struct dentry *hi_whdentry;
18868 +#define AuIG_HALF_REFRESHED 1
18869 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18870 +#define au_ig_fset(flags, name) \
18871 + do { (flags) |= AuIG_##name; } while (0)
18872 +#define au_ig_fclr(flags, name) \
18873 + do { (flags) &= ~AuIG_##name; } while (0)
18876 + spinlock_t ig_spin;
18877 + __u32 ig_generation, ig_flags;
18882 + struct au_iigen ii_generation;
18883 + struct super_block *ii_hsb1; /* no get/put */
18885 + struct au_rwsem ii_rwsem;
18886 + aufs_bindex_t ii_btop, ii_bbot;
18888 + struct au_hinode *ii_hinode;
18889 + struct au_vdir *ii_vdir;
18892 +struct au_icntnr {
18893 + struct au_iinfo iinfo;
18894 + struct inode vfs_inode;
18895 + struct hlist_bl_node plink;
18896 + struct rcu_head rcu;
18897 +} ____cacheline_aligned_in_smp;
18899 +/* au_pin flags */
18900 +#define AuPin_DI_LOCKED 1
18901 +#define AuPin_MNT_WRITE (1 << 1)
18902 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18903 +#define au_fset_pin(flags, name) \
18904 + do { (flags) |= AuPin_##name; } while (0)
18905 +#define au_fclr_pin(flags, name) \
18906 + do { (flags) &= ~AuPin_##name; } while (0)
18910 + struct dentry *dentry;
18911 + unsigned int udba;
18912 + unsigned char lsc_di, lsc_hi, flags;
18913 + aufs_bindex_t bindex;
18916 + struct dentry *parent;
18917 + struct au_hinode *hdir;
18918 + struct vfsmount *h_mnt;
18920 + /* temporary unlock/relock for copyup */
18921 + struct dentry *h_dentry, *h_parent;
18922 + struct au_branch *br;
18923 + struct task_struct *task;
18926 +void au_pin_hdir_unlock(struct au_pin *p);
18927 +int au_pin_hdir_lock(struct au_pin *p);
18928 +int au_pin_hdir_relock(struct au_pin *p);
18929 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18930 +void au_pin_hdir_release(struct au_pin *p);
18932 +/* ---------------------------------------------------------------------- */
18934 +static inline struct au_iinfo *au_ii(struct inode *inode)
18936 + BUG_ON(is_bad_inode(inode));
18937 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18940 +/* ---------------------------------------------------------------------- */
18943 +struct inode *au_igrab(struct inode *inode);
18944 +void au_refresh_iop(struct inode *inode, int force_getattr);
18945 +int au_refresh_hinode_self(struct inode *inode);
18946 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18947 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18948 + unsigned int d_type, ino_t *ino);
18949 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18950 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18951 + struct inode *inode);
18952 +int au_test_h_perm(struct inode *h_inode, int mask);
18953 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18955 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18956 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18958 +#ifdef CONFIG_AUFS_SHWH
18959 + return au_ino(sb, bindex, h_ino, d_type, ino);
18972 +extern struct inode_operations aufs_iop[AuIop_Last],
18973 + aufs_iop_nogetattr[AuIop_Last];
18975 +/* au_wr_dir flags */
18976 +#define AuWrDir_ADD_ENTRY 1
18977 +#define AuWrDir_ISDIR (1 << 1)
18978 +#define AuWrDir_TMPFILE (1 << 2)
18979 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18980 +#define au_fset_wrdir(flags, name) \
18981 + do { (flags) |= AuWrDir_##name; } while (0)
18982 +#define au_fclr_wrdir(flags, name) \
18983 + do { (flags) &= ~AuWrDir_##name; } while (0)
18985 +struct au_wr_dir_args {
18986 + aufs_bindex_t force_btgt;
18987 + unsigned char flags;
18989 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18990 + struct au_wr_dir_args *args);
18992 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18993 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18994 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18995 + unsigned int udba, unsigned char flags);
18996 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18997 + unsigned int udba, unsigned char flags) __must_check;
18998 +int au_do_pin(struct au_pin *pin) __must_check;
18999 +void au_unpin(struct au_pin *pin);
19000 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
19002 +#define AuIcpup_DID_CPUP 1
19003 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
19004 +#define au_fset_icpup(flags, name) \
19005 + do { (flags) |= AuIcpup_##name; } while (0)
19006 +#define au_fclr_icpup(flags, name) \
19007 + do { (flags) &= ~AuIcpup_##name; } while (0)
19009 +struct au_icpup_args {
19010 + unsigned char flags;
19011 + unsigned char pin_flags;
19012 + aufs_bindex_t btgt;
19013 + unsigned int udba;
19014 + struct au_pin pin;
19015 + struct path h_path;
19016 + struct inode *h_inode;
19019 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
19020 + struct au_icpup_args *a);
19022 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
19026 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19027 + struct dentry *h_parent, int isdir);
19028 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
19030 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
19031 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
19033 +struct vfsub_aopen_args;
19034 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
19035 + struct vfsub_aopen_args *args);
19036 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
19037 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
19038 + struct dentry *dentry);
19039 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
19042 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
19043 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
19044 + struct dentry *h_parent, int isdir);
19045 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
19046 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
19049 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
19050 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
19051 + struct inode *dir, struct dentry *dentry,
19052 + unsigned int flags);
19055 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
19056 +void au_hiput(struct au_hinode *hinode);
19057 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19058 + struct dentry *h_wh);
19059 +unsigned int au_hi_flags(struct inode *inode, int isdir);
19061 +/* hinode flags */
19062 +#define AuHi_XINO 1
19063 +#define AuHi_HNOTIFY (1 << 1)
19064 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
19065 +#define au_fset_hi(flags, name) \
19066 + do { (flags) |= AuHi_##name; } while (0)
19067 +#define au_fclr_hi(flags, name) \
19068 + do { (flags) &= ~AuHi_##name; } while (0)
19070 +#ifndef CONFIG_AUFS_HNOTIFY
19071 +#undef AuHi_HNOTIFY
19072 +#define AuHi_HNOTIFY 0
19075 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19076 + struct inode *h_inode, unsigned int flags);
19078 +void au_update_iigen(struct inode *inode, int half);
19079 +void au_update_ibrange(struct inode *inode, int do_put_zero);
19081 +void au_icntnr_init_once(void *_c);
19082 +void au_hinode_init(struct au_hinode *hinode);
19083 +int au_iinfo_init(struct inode *inode);
19084 +void au_iinfo_fin(struct inode *inode);
19085 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
19087 +#ifdef CONFIG_PROC_FS
19089 +int au_plink_maint(struct super_block *sb, int flags);
19091 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
19092 +int au_plink_maint_enter(struct super_block *sb);
19093 +#ifdef CONFIG_AUFS_DEBUG
19094 +void au_plink_list(struct super_block *sb);
19096 +AuStubVoid(au_plink_list, struct super_block *sb)
19098 +int au_plink_test(struct inode *inode);
19099 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
19100 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
19101 + struct dentry *h_dentry);
19102 +void au_plink_put(struct super_block *sb, int verbose);
19103 +void au_plink_clean(struct super_block *sb, int verbose);
19104 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
19106 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
19107 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
19108 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
19109 +AuStubVoid(au_plink_list, struct super_block *sb);
19110 +AuStubInt0(au_plink_test, struct inode *inode);
19111 +AuStub(struct dentry *, au_plink_lkup, return NULL,
19112 + struct inode *inode, aufs_bindex_t bindex);
19113 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
19114 + struct dentry *h_dentry);
19115 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
19116 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
19117 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
19118 +#endif /* CONFIG_PROC_FS */
19120 +#ifdef CONFIG_AUFS_XATTR
19122 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
19123 + unsigned int verbose);
19124 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
19125 +void au_xattr_init(struct super_block *sb);
19127 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
19128 + int ignore_flags, unsigned int verbose);
19129 +AuStubVoid(au_xattr_init, struct super_block *sb);
19132 +#ifdef CONFIG_FS_POSIX_ACL
19133 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
19134 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
19137 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19143 +struct au_sxattr {
19147 + const char *name;
19148 + const void *value;
19153 + struct posix_acl *acl;
19158 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19159 + struct au_sxattr *arg);
19162 +/* ---------------------------------------------------------------------- */
19164 +/* lock subclass for iinfo */
19166 + AuLsc_II_CHILD, /* child first */
19167 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
19168 + AuLsc_II_CHILD3, /* copyup dirs */
19169 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
19170 + AuLsc_II_PARENT2,
19171 + AuLsc_II_PARENT3, /* copyup dirs */
19172 + AuLsc_II_NEW_CHILD
19176 + * ii_read_lock_child, ii_write_lock_child,
19177 + * ii_read_lock_child2, ii_write_lock_child2,
19178 + * ii_read_lock_child3, ii_write_lock_child3,
19179 + * ii_read_lock_parent, ii_write_lock_parent,
19180 + * ii_read_lock_parent2, ii_write_lock_parent2,
19181 + * ii_read_lock_parent3, ii_write_lock_parent3,
19182 + * ii_read_lock_new_child, ii_write_lock_new_child,
19184 +#define AuReadLockFunc(name, lsc) \
19185 +static inline void ii_read_lock_##name(struct inode *i) \
19187 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19190 +#define AuWriteLockFunc(name, lsc) \
19191 +static inline void ii_write_lock_##name(struct inode *i) \
19193 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19196 +#define AuRWLockFuncs(name, lsc) \
19197 + AuReadLockFunc(name, lsc) \
19198 + AuWriteLockFunc(name, lsc)
19200 +AuRWLockFuncs(child, CHILD);
19201 +AuRWLockFuncs(child2, CHILD2);
19202 +AuRWLockFuncs(child3, CHILD3);
19203 +AuRWLockFuncs(parent, PARENT);
19204 +AuRWLockFuncs(parent2, PARENT2);
19205 +AuRWLockFuncs(parent3, PARENT3);
19206 +AuRWLockFuncs(new_child, NEW_CHILD);
19208 +#undef AuReadLockFunc
19209 +#undef AuWriteLockFunc
19210 +#undef AuRWLockFuncs
19212 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
19213 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
19214 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
19216 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
19217 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
19218 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
19220 +/* ---------------------------------------------------------------------- */
19222 +static inline void au_icntnr_init(struct au_icntnr *c)
19224 +#ifdef CONFIG_AUFS_DEBUG
19225 + c->vfs_inode.i_mode = 0;
19229 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
19231 + unsigned int gen;
19232 + struct au_iinfo *iinfo;
19233 + struct au_iigen *iigen;
19235 + iinfo = au_ii(inode);
19236 + iigen = &iinfo->ii_generation;
19237 + spin_lock(&iigen->ig_spin);
19239 + *igflags = iigen->ig_flags;
19240 + gen = iigen->ig_generation;
19241 + spin_unlock(&iigen->ig_spin);
19246 +/* tiny test for inode number */
19247 +/* tmpfs generation is too rough */
19248 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19250 + struct au_iinfo *iinfo;
19252 + iinfo = au_ii(inode);
19253 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19254 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19255 + && iinfo->ii_higen == h_inode->i_generation);
19258 +static inline void au_iigen_dec(struct inode *inode)
19260 + struct au_iinfo *iinfo;
19261 + struct au_iigen *iigen;
19263 + iinfo = au_ii(inode);
19264 + iigen = &iinfo->ii_generation;
19265 + spin_lock(&iigen->ig_spin);
19266 + iigen->ig_generation--;
19267 + spin_unlock(&iigen->ig_spin);
19270 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19275 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19281 +/* ---------------------------------------------------------------------- */
19283 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19284 + aufs_bindex_t bindex)
19286 + return iinfo->ii_hinode + bindex;
19289 +static inline int au_is_bad_inode(struct inode *inode)
19291 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19294 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19295 + aufs_bindex_t bindex)
19297 + IiMustAnyLock(inode);
19298 + return au_hinode(au_ii(inode), bindex)->hi_id;
19301 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19303 + IiMustAnyLock(inode);
19304 + return au_ii(inode)->ii_btop;
19307 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19309 + IiMustAnyLock(inode);
19310 + return au_ii(inode)->ii_bbot;
19313 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19315 + IiMustAnyLock(inode);
19316 + return au_ii(inode)->ii_vdir;
19319 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19321 + IiMustAnyLock(inode);
19322 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19325 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19327 + IiMustWriteLock(inode);
19328 + au_ii(inode)->ii_btop = bindex;
19331 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19333 + IiMustWriteLock(inode);
19334 + au_ii(inode)->ii_bbot = bindex;
19337 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19339 + IiMustWriteLock(inode);
19340 + au_ii(inode)->ii_vdir = vdir;
19343 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19345 + IiMustAnyLock(inode);
19346 + return au_hinode(au_ii(inode), bindex);
19349 +/* ---------------------------------------------------------------------- */
19351 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19354 + return pin->parent;
19358 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19360 + if (pin && pin->hdir)
19361 + return pin->hdir->hi_inode;
19365 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19368 + return pin->hdir;
19372 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19375 + pin->dentry = dentry;
19378 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19379 + unsigned char lflag)
19383 + au_fset_pin(pin->flags, DI_LOCKED);
19385 + au_fclr_pin(pin->flags, DI_LOCKED);
19389 +#if 0 /* reserved */
19390 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19393 + dput(pin->parent);
19394 + pin->parent = dget(parent);
19399 +/* ---------------------------------------------------------------------- */
19402 +#ifdef CONFIG_AUFS_HNOTIFY
19403 +struct au_hnotify_op {
19404 + void (*ctl)(struct au_hinode *hinode, int do_set);
19405 + int (*alloc)(struct au_hinode *hinode);
19408 + * if it returns true, the the caller should free hinode->hi_notify,
19409 + * otherwise ->free() frees it.
19411 + int (*free)(struct au_hinode *hinode,
19412 + struct au_hnotify *hn) __must_check;
19414 + void (*fin)(void);
19415 + int (*init)(void);
19417 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19418 + void (*fin_br)(struct au_branch *br);
19419 + int (*init_br)(struct au_branch *br, int perm);
19423 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19424 +void au_hn_free(struct au_hinode *hinode);
19425 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19426 +void au_hn_reset(struct inode *inode, unsigned int flags);
19427 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19428 + struct qstr *h_child_qstr, struct inode *h_child_inode);
19429 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19430 +int au_hnotify_init_br(struct au_branch *br, int perm);
19431 +void au_hnotify_fin_br(struct au_branch *br);
19432 +int __init au_hnotify_init(void);
19433 +void au_hnotify_fin(void);
19436 +extern const struct au_hnotify_op au_hnotify_op;
19439 +void au_hn_init(struct au_hinode *hinode)
19441 + hinode->hi_notify = NULL;
19444 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19446 + return hinode->hi_notify;
19450 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19451 + struct au_hinode *hinode __maybe_unused,
19452 + struct inode *inode __maybe_unused)
19453 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19454 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19455 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19456 + int do_set __maybe_unused)
19457 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19458 + unsigned int flags __maybe_unused)
19459 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19460 + struct au_branch *br __maybe_unused,
19461 + int perm __maybe_unused)
19462 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19463 + int perm __maybe_unused)
19464 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19465 +AuStubInt0(__init au_hnotify_init, void)
19466 +AuStubVoid(au_hnotify_fin, void)
19467 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19468 +#endif /* CONFIG_AUFS_HNOTIFY */
19470 +static inline void au_hn_suspend(struct au_hinode *hdir)
19472 + au_hn_ctl(hdir, /*do_set*/0);
19475 +static inline void au_hn_resume(struct au_hinode *hdir)
19477 + au_hn_ctl(hdir, /*do_set*/1);
19480 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19482 + inode_lock(hdir->hi_inode);
19483 + au_hn_suspend(hdir);
19486 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19487 + unsigned int sc __maybe_unused)
19489 + inode_lock_nested(hdir->hi_inode, sc);
19490 + au_hn_suspend(hdir);
19493 +#if 0 /* unused */
19494 +#include "vfsub.h"
19495 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19498 + inode_lock_shared_nested(hdir->hi_inode, sc);
19499 + au_hn_suspend(hdir);
19503 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19505 + au_hn_resume(hdir);
19506 + inode_unlock(hdir->hi_inode);
19509 +#endif /* __KERNEL__ */
19510 +#endif /* __AUFS_INODE_H__ */
19511 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19512 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19513 +++ linux/fs/aufs/ioctl.c 2019-03-05 12:13:00.142557771 +0100
19515 +// SPDX-License-Identifier: GPL-2.0
19517 + * Copyright (C) 2005-2019 Junjiro R. Okajima
19519 + * This program, aufs is free software; you can redistribute it and/or modify
19520 + * it under the terms of the GNU General Public License as published by
19521 + * the Free Software Foundation; either version 2 of the License, or
19522 + * (at your option) any later version.
19524 + * This program is distributed in the hope that it will be useful,
19525 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19526 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19527 + * GNU General Public License for more details.
19529 + * You should have received a copy of the GNU General Public License
19530 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19535 + * plink-management and readdir in userspace.
19536 + * assist the pathconf(3) wrapper library.
19538 + * File-based Hierarchical Storage Management.
19541 +#include <linux/compat.h>
19542 +#include <linux/file.h>
19545 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19548 + aufs_bindex_t wbi, bindex, bbot;
19549 + struct file *h_file;
19550 + struct super_block *sb;
19551 + struct dentry *root;
19552 + struct au_branch *br;
19553 + struct aufs_wbr_fd wbrfd = {
19554 + .oflags = au_dir_roflags,
19557 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19558 + | O_NOATIME | O_CLOEXEC;
19560 + AuDebugOn(wbrfd.oflags & ~valid);
19563 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19564 + if (unlikely(err)) {
19570 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19571 + wbrfd.oflags |= au_dir_roflags;
19572 + AuDbg("0%o\n", wbrfd.oflags);
19573 + if (unlikely(wbrfd.oflags & ~valid))
19577 + fd = get_unused_fd_flags(0);
19579 + if (unlikely(fd < 0))
19582 + h_file = ERR_PTR(-EINVAL);
19585 + sb = path->dentry->d_sb;
19586 + root = sb->s_root;
19587 + aufs_read_lock(root, AuLock_IR);
19588 + bbot = au_sbbot(sb);
19589 + if (wbrfd.brid >= 0) {
19590 + wbi = au_br_index(sb, wbrfd.brid);
19591 + if (unlikely(wbi < 0 || wbi > bbot))
19595 + h_file = ERR_PTR(-ENOENT);
19596 + br = au_sbr(sb, wbi);
19597 + if (!au_br_writable(br->br_perm)) {
19601 + bindex = wbi + 1;
19603 + for (; bindex <= bbot; bindex++) {
19604 + br = au_sbr(sb, bindex);
19605 + if (au_br_writable(br->br_perm)) {
19607 + br = au_sbr(sb, wbi);
19612 + AuDbg("wbi %d\n", wbi);
19614 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19618 + aufs_read_unlock(root, AuLock_IR);
19619 + err = PTR_ERR(h_file);
19620 + if (IS_ERR(h_file))
19623 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19624 + fd_install(fd, h_file);
19626 + goto out; /* success */
19629 + put_unused_fd(fd);
19635 +/* ---------------------------------------------------------------------- */
19637 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19640 + struct dentry *dentry;
19643 + case AUFS_CTL_RDU:
19644 + case AUFS_CTL_RDU_INO:
19645 + err = au_rdu_ioctl(file, cmd, arg);
19648 + case AUFS_CTL_WBR_FD:
19649 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19652 + case AUFS_CTL_IBUSY:
19653 + err = au_ibusy_ioctl(file, arg);
19656 + case AUFS_CTL_BRINFO:
19657 + err = au_brinfo_ioctl(file, arg);
19660 + case AUFS_CTL_FHSM_FD:
19661 + dentry = file->f_path.dentry;
19662 + if (IS_ROOT(dentry))
19663 + err = au_fhsm_fd(dentry->d_sb, arg);
19669 + /* do not call the lower */
19670 + AuDbg("0x%x\n", cmd);
19678 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19683 + case AUFS_CTL_MVDOWN:
19684 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19687 + case AUFS_CTL_WBR_FD:
19688 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19692 + /* do not call the lower */
19693 + AuDbg("0x%x\n", cmd);
19701 +#ifdef CONFIG_COMPAT
19702 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19703 + unsigned long arg)
19708 + case AUFS_CTL_RDU:
19709 + case AUFS_CTL_RDU_INO:
19710 + err = au_rdu_compat_ioctl(file, cmd, arg);
19713 + case AUFS_CTL_IBUSY:
19714 + err = au_ibusy_compat_ioctl(file, arg);
19717 + case AUFS_CTL_BRINFO:
19718 + err = au_brinfo_compat_ioctl(file, arg);
19722 + err = aufs_ioctl_dir(file, cmd, arg);
19729 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19730 + unsigned long arg)
19732 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19735 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19736 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19737 +++ linux/fs/aufs/i_op_add.c 2019-05-06 09:03:04.816810402 +0200
19739 +// SPDX-License-Identifier: GPL-2.0
19741 + * Copyright (C) 2005-2019 Junjiro R. Okajima
19743 + * This program, aufs is free software; you can redistribute it and/or modify
19744 + * it under the terms of the GNU General Public License as published by
19745 + * the Free Software Foundation; either version 2 of the License, or
19746 + * (at your option) any later version.
19748 + * This program is distributed in the hope that it will be useful,
19749 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19750 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19751 + * GNU General Public License for more details.
19753 + * You should have received a copy of the GNU General Public License
19754 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19758 + * inode operations (add entry)
19761 +#include <linux/iversion.h>
19765 + * final procedure of adding a new entry, except link(2).
19766 + * remove whiteout, instantiate, copyup the parent dir's times and size
19767 + * and update version.
19768 + * if it failed, re-create the removed whiteout.
19770 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19771 + struct dentry *wh_dentry, struct dentry *dentry)
19774 + aufs_bindex_t bwh;
19775 + struct path h_path;
19776 + struct super_block *sb;
19777 + struct inode *inode, *h_dir;
19778 + struct dentry *wh;
19783 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19784 + IMustLock(h_dir);
19785 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19786 + bwh = au_dbwh(dentry);
19787 + h_path.dentry = wh_dentry;
19788 + h_path.mnt = au_sbr_mnt(sb, bindex);
19789 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19791 + if (unlikely(err))
19795 + inode = au_new_inode(dentry, /*must_new*/1);
19796 + if (!IS_ERR(inode)) {
19797 + d_instantiate(dentry, inode);
19798 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19800 + au_dir_ts(dir, bindex);
19801 + inode_inc_iversion(dir);
19802 + au_fhsm_wrote(sb, bindex, /*force*/0);
19803 + return 0; /* success */
19806 + err = PTR_ERR(inode);
19811 + /* dir inode is locked */
19812 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19813 + rerr = PTR_ERR(wh);
19814 + if (IS_ERR(wh)) {
19815 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19816 + dentry, err, rerr);
19825 +static int au_d_may_add(struct dentry *dentry)
19830 + if (unlikely(d_unhashed(dentry)))
19832 + if (unlikely(d_really_is_positive(dentry)))
19838 + * simple tests for the adding inode operations.
19839 + * following the checks in vfs, plus the parent-child relationship.
19841 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19842 + struct dentry *h_parent, int isdir)
19846 + struct dentry *h_dentry;
19847 + struct inode *h_inode;
19849 + err = -ENAMETOOLONG;
19850 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19853 + h_dentry = au_h_dptr(dentry, bindex);
19854 + if (d_really_is_negative(dentry)) {
19856 + if (unlikely(d_is_positive(h_dentry)))
19859 + /* rename(2) case */
19861 + if (unlikely(d_is_negative(h_dentry)))
19863 + h_inode = d_inode(h_dentry);
19864 + if (unlikely(!h_inode->i_nlink))
19867 + h_mode = h_inode->i_mode;
19870 + if (unlikely(S_ISDIR(h_mode)))
19872 + } else if (unlikely(!S_ISDIR(h_mode))) {
19879 + /* expected parent dir is locked */
19880 + if (unlikely(h_parent != h_dentry->d_parent))
19889 + * initial procedure of adding a new entry.
19890 + * prepare writable branch and the parent dir, lock it,
19891 + * and lookup whiteout for the new entry.
19893 +static struct dentry*
19894 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19895 + struct dentry *src_dentry, struct au_pin *pin,
19896 + struct au_wr_dir_args *wr_dir_args)
19898 + struct dentry *wh_dentry, *h_parent;
19899 + struct super_block *sb;
19900 + struct au_branch *br;
19902 + unsigned int udba;
19903 + aufs_bindex_t bcpup;
19905 + AuDbg("%pd\n", dentry);
19907 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19909 + wh_dentry = ERR_PTR(err);
19910 + if (unlikely(err < 0))
19913 + sb = dentry->d_sb;
19914 + udba = au_opt_udba(sb);
19915 + err = au_pin(pin, dentry, bcpup, udba,
19916 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19917 + wh_dentry = ERR_PTR(err);
19918 + if (unlikely(err))
19921 + h_parent = au_pinned_h_parent(pin);
19922 + if (udba != AuOpt_UDBA_NONE
19923 + && au_dbtop(dentry) == bcpup)
19924 + err = au_may_add(dentry, bcpup, h_parent,
19925 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19926 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19927 + err = -ENAMETOOLONG;
19928 + wh_dentry = ERR_PTR(err);
19929 + if (unlikely(err))
19932 + br = au_sbr(sb, bcpup);
19934 + struct path tmp = {
19935 + .dentry = h_parent,
19936 + .mnt = au_br_mnt(br)
19938 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19941 + wh_dentry = NULL;
19942 + if (bcpup != au_dbwh(dentry))
19943 + goto out; /* success */
19946 + * ENAMETOOLONG here means that if we allowed create such name, then it
19947 + * would not be able to removed in the future. So we don't allow such
19948 + * name here and we don't handle ENAMETOOLONG differently here.
19950 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19953 + if (IS_ERR(wh_dentry))
19956 + return wh_dentry;
19959 +/* ---------------------------------------------------------------------- */
19961 +enum { Mknod, Symlink, Creat };
19962 +struct simple_arg {
19969 + struct vfsub_aopen_args *aopen;
19972 + const char *symname;
19981 +static int add_simple(struct inode *dir, struct dentry *dentry,
19982 + struct simple_arg *arg)
19985 + aufs_bindex_t btop;
19986 + unsigned char created;
19987 + const unsigned char try_aopen
19988 + = (arg->type == Creat && arg->u.c.try_aopen);
19989 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19990 + struct dentry *wh_dentry, *parent;
19991 + struct inode *h_dir;
19992 + struct super_block *sb;
19993 + struct au_branch *br;
19994 + /* to reduce stack size */
19996 + struct au_dtime dt;
19997 + struct au_pin pin;
19998 + struct path h_path;
19999 + struct au_wr_dir_args wr_dir_args;
20002 + AuDbg("%pd\n", dentry);
20006 + a = kmalloc(sizeof(*a), GFP_NOFS);
20007 + if (unlikely(!a))
20009 + a->wr_dir_args.force_btgt = -1;
20010 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
20012 + parent = dentry->d_parent; /* dir inode is locked */
20013 + if (!try_aopen) {
20014 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20015 + if (unlikely(err))
20018 + err = au_d_may_add(dentry);
20019 + if (unlikely(err))
20022 + di_write_lock_parent(parent);
20023 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20024 + &a->pin, &a->wr_dir_args);
20025 + err = PTR_ERR(wh_dentry);
20026 + if (IS_ERR(wh_dentry))
20029 + btop = au_dbtop(dentry);
20030 + sb = dentry->d_sb;
20031 + br = au_sbr(sb, btop);
20032 + a->h_path.dentry = au_h_dptr(dentry, btop);
20033 + a->h_path.mnt = au_br_mnt(br);
20034 + h_dir = au_pinned_h_dir(&a->pin);
20035 + switch (arg->type) {
20037 + if (!try_aopen || !h_dir->i_op->atomic_open) {
20038 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
20039 + arg->u.c.want_excl);
20041 + if (!err && try_aopen)
20042 + aopen->file->f_mode |= FMODE_CREATED;
20045 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
20046 + AuDbg("err %d\n", err);
20047 + AuDbgFile(aopen->file);
20048 + created = err >= 0
20049 + && !!(aopen->file->f_mode & FMODE_CREATED);
20053 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
20057 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
20064 + if (unlikely(err < 0))
20067 + err = epilog(dir, btop, wh_dentry, dentry);
20069 + goto out_unpin; /* success */
20072 + if (created /* && d_is_positive(a->h_path.dentry) */) {
20073 + /* no delegation since it is just created */
20074 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
20077 + AuIOErr("%pd revert failure(%d, %d)\n",
20078 + dentry, err, rerr);
20081 + au_dtime_revert(&a->dt);
20083 + if (try_aopen && h_dir->i_op->atomic_open
20084 + && (aopen->file->f_mode & FMODE_OPENED))
20085 + /* aopen->file is still opened */
20086 + au_lcnt_dec(&aopen->br->br_nfiles);
20089 + au_unpin(&a->pin);
20093 + di_write_unlock(parent);
20095 + if (unlikely(err)) {
20096 + au_update_dbtop(dentry);
20100 + aufs_read_unlock(dentry, AuLock_DW);
20107 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
20110 + struct simple_arg arg = {
20117 + return add_simple(dir, dentry, &arg);
20120 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
20122 + struct simple_arg arg = {
20124 + .u.s.symname = symname
20126 + return add_simple(dir, dentry, &arg);
20129 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
20132 + struct simple_arg arg = {
20136 + .want_excl = want_excl
20139 + return add_simple(dir, dentry, &arg);
20142 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20143 + struct vfsub_aopen_args *aopen_args)
20145 + struct simple_arg arg = {
20148 + .mode = aopen_args->create_mode,
20149 + .want_excl = aopen_args->open_flag & O_EXCL,
20150 + .try_aopen = true,
20151 + .aopen = aopen_args
20154 + return add_simple(dir, dentry, &arg);
20157 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
20160 + aufs_bindex_t bindex;
20161 + struct super_block *sb;
20162 + struct dentry *parent, *h_parent, *h_dentry;
20163 + struct inode *h_dir, *inode;
20164 + struct vfsmount *h_mnt;
20165 + struct au_wr_dir_args wr_dir_args = {
20166 + .force_btgt = -1,
20167 + .flags = AuWrDir_TMPFILE
20170 + /* copy-up may happen */
20174 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20175 + if (unlikely(err))
20178 + err = au_di_init(dentry);
20179 + if (unlikely(err))
20183 + parent = d_find_any_alias(dir);
20184 + AuDebugOn(!parent);
20185 + di_write_lock_parent(parent);
20186 + if (unlikely(d_inode(parent) != dir))
20189 + err = au_digen_test(parent, au_sigen(sb));
20190 + if (unlikely(err))
20193 + bindex = au_dbtop(parent);
20194 + au_set_dbtop(dentry, bindex);
20195 + au_set_dbbot(dentry, bindex);
20196 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
20198 + if (unlikely(err < 0))
20201 + err = -EOPNOTSUPP;
20202 + h_dir = au_h_iptr(dir, bindex);
20203 + if (unlikely(!h_dir->i_op->tmpfile))
20206 + h_mnt = au_sbr_mnt(sb, bindex);
20207 + err = vfsub_mnt_want_write(h_mnt);
20208 + if (unlikely(err))
20211 + h_parent = au_h_dptr(parent, bindex);
20212 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
20213 + if (IS_ERR(h_dentry)) {
20214 + err = PTR_ERR(h_dentry);
20218 + au_set_dbtop(dentry, bindex);
20219 + au_set_dbbot(dentry, bindex);
20220 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
20221 + inode = au_new_inode(dentry, /*must_new*/1);
20222 + if (IS_ERR(inode)) {
20223 + err = PTR_ERR(inode);
20224 + au_set_h_dptr(dentry, bindex, NULL);
20225 + au_set_dbtop(dentry, -1);
20226 + au_set_dbbot(dentry, -1);
20228 + if (!inode->i_nlink)
20229 + set_nlink(inode, 1);
20230 + d_tmpfile(dentry, inode);
20231 + au_di(dentry)->di_tmpfile = 1;
20233 + /* update without i_mutex */
20234 + if (au_ibtop(dir) == au_dbtop(dentry))
20235 + au_cpup_attr_timesizes(dir);
20240 + vfsub_mnt_drop_write(h_mnt);
20242 + di_write_unlock(parent);
20244 + di_write_unlock(dentry);
20245 + if (unlikely(err)) {
20246 + au_di_fin(dentry);
20247 + dentry->d_fsdata = NULL;
20250 + si_read_unlock(sb);
20252 + inode_unlock(dir);
20256 +/* ---------------------------------------------------------------------- */
20258 +struct au_link_args {
20259 + aufs_bindex_t bdst, bsrc;
20260 + struct au_pin pin;
20261 + struct path h_path;
20262 + struct dentry *src_parent, *parent;
20265 +static int au_cpup_before_link(struct dentry *src_dentry,
20266 + struct au_link_args *a)
20269 + struct dentry *h_src_dentry;
20270 + struct au_cp_generic cpg = {
20271 + .dentry = src_dentry,
20276 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20279 + di_read_lock_parent(a->src_parent, AuLock_IR);
20280 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20281 + if (unlikely(err))
20284 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20285 + err = au_pin(&a->pin, src_dentry, a->bdst,
20286 + au_opt_udba(src_dentry->d_sb),
20287 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20288 + if (unlikely(err))
20291 + err = au_sio_cpup_simple(&cpg);
20292 + au_unpin(&a->pin);
20295 + di_read_unlock(a->src_parent, AuLock_IR);
20299 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20300 + struct au_link_args *a)
20303 + unsigned char plink;
20304 + aufs_bindex_t bbot;
20305 + struct dentry *h_src_dentry;
20306 + struct inode *h_inode, *inode, *delegated;
20307 + struct super_block *sb;
20308 + struct file *h_file;
20312 + sb = src_dentry->d_sb;
20313 + inode = d_inode(src_dentry);
20314 + if (au_ibtop(inode) <= a->bdst)
20315 + h_inode = au_h_iptr(inode, a->bdst);
20316 + if (!h_inode || !h_inode->i_nlink) {
20317 + /* copyup src_dentry as the name of dentry. */
20318 + bbot = au_dbbot(dentry);
20319 + if (bbot < a->bsrc)
20320 + au_set_dbbot(dentry, a->bsrc);
20321 + au_set_h_dptr(dentry, a->bsrc,
20322 + dget(au_h_dptr(src_dentry, a->bsrc)));
20323 + dget(a->h_path.dentry);
20324 + au_set_h_dptr(dentry, a->bdst, NULL);
20325 + AuDbg("temporary d_inode...\n");
20326 + spin_lock(&dentry->d_lock);
20327 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20328 + spin_unlock(&dentry->d_lock);
20329 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20330 + if (IS_ERR(h_file))
20331 + err = PTR_ERR(h_file);
20333 + struct au_cp_generic cpg = {
20334 + .dentry = dentry,
20339 + .flags = AuCpup_KEEPLINO
20341 + err = au_sio_cpup_simple(&cpg);
20342 + au_h_open_post(dentry, a->bsrc, h_file);
20344 + dput(a->h_path.dentry);
20345 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20347 + au_set_h_dptr(dentry, a->bdst,
20348 + a->h_path.dentry);
20350 + spin_lock(&dentry->d_lock);
20351 + dentry->d_inode = NULL; /* restore */
20352 + spin_unlock(&dentry->d_lock);
20353 + AuDbg("temporary d_inode...done\n");
20354 + au_set_h_dptr(dentry, a->bsrc, NULL);
20355 + au_set_dbbot(dentry, bbot);
20357 + /* the inode of src_dentry already exists on a.bdst branch */
20358 + h_src_dentry = d_find_alias(h_inode);
20359 + if (!h_src_dentry && au_plink_test(inode)) {
20361 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20362 + err = PTR_ERR(h_src_dentry);
20363 + if (IS_ERR(h_src_dentry))
20366 + if (unlikely(d_is_negative(h_src_dentry))) {
20367 + dput(h_src_dentry);
20368 + h_src_dentry = NULL;
20372 + if (h_src_dentry) {
20373 + delegated = NULL;
20374 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20375 + &a->h_path, &delegated);
20376 + if (unlikely(err == -EWOULDBLOCK)) {
20377 + pr_warn("cannot retry for NFSv4 delegation"
20378 + " for an internal link\n");
20381 + dput(h_src_dentry);
20383 + AuIOErr("no dentry found for hi%lu on b%d\n",
20384 + h_inode->i_ino, a->bdst);
20389 + if (!err && !plink)
20390 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20397 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20398 + struct dentry *dentry)
20401 + struct au_dtime dt;
20402 + struct au_link_args *a;
20403 + struct dentry *wh_dentry, *h_src_dentry;
20404 + struct inode *inode, *delegated;
20405 + struct super_block *sb;
20406 + struct au_wr_dir_args wr_dir_args = {
20407 + /* .force_btgt = -1, */
20408 + .flags = AuWrDir_ADD_ENTRY
20412 + inode = d_inode(src_dentry);
20413 + IMustLock(inode);
20416 + a = kzalloc(sizeof(*a), GFP_NOFS);
20417 + if (unlikely(!a))
20420 + a->parent = dentry->d_parent; /* dir inode is locked */
20421 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20422 + AuLock_NOPLM | AuLock_GEN);
20423 + if (unlikely(err))
20425 + err = au_d_linkable(src_dentry);
20426 + if (unlikely(err))
20428 + err = au_d_may_add(dentry);
20429 + if (unlikely(err))
20432 + a->src_parent = dget_parent(src_dentry);
20433 + wr_dir_args.force_btgt = au_ibtop(inode);
20435 + di_write_lock_parent(a->parent);
20436 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20437 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20439 + err = PTR_ERR(wh_dentry);
20440 + if (IS_ERR(wh_dentry))
20444 + sb = dentry->d_sb;
20445 + a->bdst = au_dbtop(dentry);
20446 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20447 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20448 + a->bsrc = au_ibtop(inode);
20449 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20450 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20451 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20452 + if (!h_src_dentry) {
20453 + a->bsrc = au_dbtop(src_dentry);
20454 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20455 + AuDebugOn(!h_src_dentry);
20456 + } else if (IS_ERR(h_src_dentry)) {
20457 + err = PTR_ERR(h_src_dentry);
20462 + * aufs doesn't touch the credential so
20463 + * security_dentry_create_files_as() is unnecessary.
20465 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20466 + if (a->bdst < a->bsrc
20467 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20468 + err = au_cpup_or_link(src_dentry, dentry, a);
20470 + delegated = NULL;
20471 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20472 + &a->h_path, &delegated);
20473 + if (unlikely(err == -EWOULDBLOCK)) {
20474 + pr_warn("cannot retry for NFSv4 delegation"
20475 + " for an internal link\n");
20479 + dput(h_src_dentry);
20482 + * copyup src_dentry to the branch we process,
20483 + * and then link(2) to it.
20485 + dput(h_src_dentry);
20486 + if (a->bdst < a->bsrc
20487 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20488 + au_unpin(&a->pin);
20489 + di_write_unlock(a->parent);
20490 + err = au_cpup_before_link(src_dentry, a);
20491 + di_write_lock_parent(a->parent);
20493 + err = au_pin(&a->pin, dentry, a->bdst,
20495 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20496 + if (unlikely(err))
20500 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20502 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20503 + delegated = NULL;
20504 + err = vfsub_link(h_src_dentry,
20505 + au_pinned_h_dir(&a->pin),
20506 + &a->h_path, &delegated);
20507 + if (unlikely(err == -EWOULDBLOCK)) {
20508 + pr_warn("cannot retry"
20509 + " for NFSv4 delegation"
20510 + " for an internal link\n");
20516 + if (unlikely(err))
20520 + a->h_path.dentry = wh_dentry;
20521 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20523 + if (unlikely(err))
20527 + au_dir_ts(dir, a->bdst);
20528 + inode_inc_iversion(dir);
20529 + inc_nlink(inode);
20530 + inode->i_ctime = dir->i_ctime;
20531 + d_instantiate(dentry, au_igrab(inode));
20532 + if (d_unhashed(a->h_path.dentry))
20533 + /* some filesystem calls d_drop() */
20535 + /* some filesystems consume an inode even hardlink */
20536 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20537 + goto out_unpin; /* success */
20540 + /* no delegation since it is just created */
20541 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20542 + /*delegated*/NULL, /*force*/0);
20543 + if (unlikely(rerr)) {
20544 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20547 + au_dtime_revert(&dt);
20549 + au_unpin(&a->pin);
20553 + di_write_unlock(a->parent);
20554 + dput(a->src_parent);
20556 + if (unlikely(err)) {
20557 + au_update_dbtop(dentry);
20560 + aufs_read_and_write_unlock2(dentry, src_dentry);
20568 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20571 + aufs_bindex_t bindex;
20572 + unsigned char diropq;
20573 + struct path h_path;
20574 + struct dentry *wh_dentry, *parent, *opq_dentry;
20575 + struct inode *h_inode;
20576 + struct super_block *sb;
20578 + struct au_pin pin;
20579 + struct au_dtime dt;
20580 + } *a; /* reduce the stack usage */
20581 + struct au_wr_dir_args wr_dir_args = {
20582 + .force_btgt = -1,
20583 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20589 + a = kmalloc(sizeof(*a), GFP_NOFS);
20590 + if (unlikely(!a))
20593 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20594 + if (unlikely(err))
20596 + err = au_d_may_add(dentry);
20597 + if (unlikely(err))
20600 + parent = dentry->d_parent; /* dir inode is locked */
20601 + di_write_lock_parent(parent);
20602 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20603 + &a->pin, &wr_dir_args);
20604 + err = PTR_ERR(wh_dentry);
20605 + if (IS_ERR(wh_dentry))
20608 + sb = dentry->d_sb;
20609 + bindex = au_dbtop(dentry);
20610 + h_path.dentry = au_h_dptr(dentry, bindex);
20611 + h_path.mnt = au_sbr_mnt(sb, bindex);
20612 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20613 + if (unlikely(err))
20616 + /* make the dir opaque */
20618 + h_inode = d_inode(h_path.dentry);
20620 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20621 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20622 + opq_dentry = au_diropq_create(dentry, bindex);
20623 + inode_unlock(h_inode);
20624 + err = PTR_ERR(opq_dentry);
20625 + if (IS_ERR(opq_dentry))
20627 + dput(opq_dentry);
20631 + err = epilog(dir, bindex, wh_dentry, dentry);
20634 + goto out_unpin; /* success */
20639 + AuLabel(revert opq);
20640 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20641 + rerr = au_diropq_remove(dentry, bindex);
20642 + inode_unlock(h_inode);
20644 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20645 + dentry, err, rerr);
20651 + AuLabel(revert dir);
20652 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20654 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20655 + dentry, err, rerr);
20658 + au_dtime_revert(&a->dt);
20660 + au_unpin(&a->pin);
20663 + di_write_unlock(parent);
20665 + if (unlikely(err)) {
20666 + au_update_dbtop(dentry);
20669 + aufs_read_unlock(dentry, AuLock_DW);
20675 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20676 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20677 +++ linux/fs/aufs/i_op.c 2019-05-06 09:03:04.816810402 +0200
20679 +// SPDX-License-Identifier: GPL-2.0
20681 + * Copyright (C) 2005-2019 Junjiro R. Okajima
20683 + * This program, aufs is free software; you can redistribute it and/or modify
20684 + * it under the terms of the GNU General Public License as published by
20685 + * the Free Software Foundation; either version 2 of the License, or
20686 + * (at your option) any later version.
20688 + * This program is distributed in the hope that it will be useful,
20689 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20690 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20691 + * GNU General Public License for more details.
20693 + * You should have received a copy of the GNU General Public License
20694 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20698 + * inode operations (except add/del/rename)
20701 +#include <linux/device_cgroup.h>
20702 +#include <linux/fs_stack.h>
20703 +#include <linux/iversion.h>
20704 +#include <linux/namei.h>
20705 +#include <linux/security.h>
20708 +static int h_permission(struct inode *h_inode, int mask,
20709 + struct path *h_path, int brperm)
20712 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20715 + if (write_mask && IS_IMMUTABLE(h_inode))
20719 + if (((mask & MAY_EXEC)
20720 + && S_ISREG(h_inode->i_mode)
20721 + && (path_noexec(h_path)
20722 + || !(h_inode->i_mode & 0111))))
20726 + * - skip the lower fs test in the case of write to ro branch.
20727 + * - nfs dir permission write check is optimized, but a policy for
20728 + * link/rename requires a real check.
20729 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20730 + * in this case, generic_permission() returns -EOPNOTSUPP.
20732 + if ((write_mask && !au_br_writable(brperm))
20733 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20734 + && write_mask && !(mask & MAY_READ))
20735 + || !h_inode->i_op->permission) {
20736 + /* AuLabel(generic_permission); */
20737 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20738 + err = generic_permission(h_inode, mask);
20739 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20740 + err = h_inode->i_op->permission(h_inode, mask);
20743 + /* AuLabel(h_inode->permission); */
20744 + err = h_inode->i_op->permission(h_inode, mask);
20749 + err = devcgroup_inode_permission(h_inode, mask);
20751 + err = security_inode_permission(h_inode, mask);
20755 + /* todo: do we need to call ima_path_check()? */
20756 + struct path h_path = {
20760 + err = ima_path_check(&h_path,
20761 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
20762 + IMA_COUNT_LEAVE);
20770 +static int aufs_permission(struct inode *inode, int mask)
20773 + aufs_bindex_t bindex, bbot;
20774 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20775 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20776 + struct inode *h_inode;
20777 + struct super_block *sb;
20778 + struct au_branch *br;
20780 + /* todo: support rcu-walk? */
20781 + if (mask & MAY_NOT_BLOCK)
20784 + sb = inode->i_sb;
20785 + si_read_lock(sb, AuLock_FLUSH);
20786 + ii_read_lock_child(inode);
20788 + err = au_iigen_test(inode, au_sigen(sb));
20789 + if (unlikely(err))
20795 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20796 + err = au_busy_or_stale();
20797 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20798 + if (unlikely(!h_inode
20799 + || (h_inode->i_mode & S_IFMT)
20800 + != (inode->i_mode & S_IFMT)))
20804 + bindex = au_ibtop(inode);
20805 + br = au_sbr(sb, bindex);
20806 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20809 + && !special_file(h_inode->i_mode)) {
20810 + /* test whether the upper writable branch exists */
20812 + for (; bindex >= 0; bindex--)
20813 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20821 + /* non-write to dir */
20823 + bbot = au_ibbot(inode);
20824 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20825 + h_inode = au_h_iptr(inode, bindex);
20827 + err = au_busy_or_stale();
20828 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20831 + br = au_sbr(sb, bindex);
20832 + err = h_permission(h_inode, mask, &br->br_path,
20838 + ii_read_unlock(inode);
20839 + si_read_unlock(sb);
20843 +/* ---------------------------------------------------------------------- */
20845 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20846 + unsigned int flags)
20848 + struct dentry *ret, *parent;
20849 + struct inode *inode;
20850 + struct super_block *sb;
20851 + int err, npositive;
20855 + /* todo: support rcu-walk? */
20856 + ret = ERR_PTR(-ECHILD);
20857 + if (flags & LOOKUP_RCU)
20860 + ret = ERR_PTR(-ENAMETOOLONG);
20861 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20865 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20866 + ret = ERR_PTR(err);
20867 + if (unlikely(err))
20870 + err = au_di_init(dentry);
20871 + ret = ERR_PTR(err);
20872 + if (unlikely(err))
20876 + npositive = 0; /* suppress a warning */
20877 + parent = dentry->d_parent; /* dir inode is locked */
20878 + di_read_lock_parent(parent, AuLock_IR);
20879 + err = au_alive_dir(parent);
20881 + err = au_digen_test(parent, au_sigen(sb));
20883 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20884 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20885 + AuLkup_ALLOW_NEG);
20888 + di_read_unlock(parent, AuLock_IR);
20889 + ret = ERR_PTR(err);
20890 + if (unlikely(err < 0))
20894 + inode = au_new_inode(dentry, /*must_new*/0);
20895 + if (IS_ERR(inode)) {
20896 + ret = (void *)inode;
20903 + atomic_inc(&inode->i_count);
20904 + ret = d_splice_alias(inode, dentry);
20906 + if (unlikely(d_need_lookup(dentry))) {
20907 + spin_lock(&dentry->d_lock);
20908 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20909 + spin_unlock(&dentry->d_lock);
20913 + if (!IS_ERR(ret)) {
20915 + if (ret && ret != dentry)
20916 + ii_write_unlock(inode);
20918 + ii_write_unlock(inode);
20925 + di_write_unlock(dentry);
20927 + si_read_unlock(sb);
20932 +/* ---------------------------------------------------------------------- */
20935 + * very dirty and complicated aufs ->atomic_open().
20936 + * aufs_atomic_open()
20937 + * + au_aopen_or_create()
20939 + * + vfsub_atomic_open()
20940 + * + branch fs ->atomic_open()
20941 + * may call the actual 'open' for h_file
20942 + * + inc br_nfiles only if opened
20943 + * + au_aopen_no_open() or au_aopen_do_open()
20945 + * au_aopen_do_open()
20946 + * + finish_open()
20947 + * + au_do_aopen()
20948 + * + au_do_open() the body of all 'open'
20949 + * + au_do_open_nondir()
20950 + * set the passed h_file
20952 + * au_aopen_no_open()
20953 + * + finish_no_open()
20956 +struct aopen_node {
20957 + struct hlist_bl_node hblist;
20958 + struct file *file, *h_file;
20961 +static int au_do_aopen(struct inode *inode, struct file *file)
20963 + struct hlist_bl_head *aopen;
20964 + struct hlist_bl_node *pos;
20965 + struct aopen_node *node;
20966 + struct au_do_open_args args = {
20968 + .open = au_do_open_nondir
20971 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20972 + hlist_bl_lock(aopen);
20973 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20974 + if (node->file == file) {
20975 + args.h_file = node->h_file;
20978 + hlist_bl_unlock(aopen);
20979 + /* AuDebugOn(!args.h_file); */
20981 + return au_do_open(file, &args);
20984 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20985 + struct aopen_node *aopen_node)
20988 + struct hlist_bl_head *aopen;
20991 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20992 + au_hbl_add(&aopen_node->hblist, aopen);
20993 + err = finish_open(file, dentry, au_do_aopen);
20994 + au_hbl_del(&aopen_node->hblist, aopen);
20995 + /* AuDbgFile(file); */
20996 + AuDbg("%pd%s%s\n", dentry,
20997 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20998 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
21004 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
21010 + err = finish_no_open(file, dentry);
21016 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
21017 + struct file *file, unsigned int open_flag,
21018 + umode_t create_mode)
21020 + int err, did_open;
21021 + unsigned int lkup_flags;
21022 + aufs_bindex_t bindex;
21023 + struct super_block *sb;
21024 + struct dentry *parent, *d;
21025 + struct vfsub_aopen_args args = {
21026 + .open_flag = open_flag,
21027 + .create_mode = create_mode
21029 + struct aopen_node aopen_node = {
21034 + AuDbg("open_flag 0%o\n", open_flag);
21035 + AuDbgDentry(dentry);
21038 + if (!au_di(dentry)) {
21039 + lkup_flags = LOOKUP_OPEN;
21040 + if (open_flag & O_CREAT)
21041 + lkup_flags |= LOOKUP_CREATE;
21042 + d = aufs_lookup(dir, dentry, lkup_flags);
21044 + err = PTR_ERR(d);
21049 + * obsoleted dentry found.
21050 + * another error will be returned later.
21056 + AuDbgDentry(dentry);
21059 + if (d_is_positive(dentry)
21060 + || d_unhashed(dentry)
21061 + || d_unlinked(dentry)
21062 + || !(open_flag & O_CREAT)) {
21063 + err = au_aopen_no_open(file, dentry);
21064 + goto out; /* success */
21067 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
21068 + if (unlikely(err))
21071 + sb = dentry->d_sb;
21072 + parent = dentry->d_parent; /* dir is locked */
21073 + di_write_lock_parent(parent);
21074 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
21075 + if (unlikely(err < 0))
21078 + AuDbgDentry(dentry);
21079 + if (d_is_positive(dentry)) {
21080 + err = au_aopen_no_open(file, dentry);
21081 + goto out_parent; /* success */
21084 + args.file = alloc_empty_file(file->f_flags, current_cred());
21085 + err = PTR_ERR(args.file);
21086 + if (IS_ERR(args.file))
21089 + bindex = au_dbtop(dentry);
21090 + err = au_aopen_or_create(dir, dentry, &args);
21092 + AuDbgFile(args.file);
21093 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
21094 + did_open = !!(args.file->f_mode & FMODE_OPENED);
21097 + args.file = NULL;
21099 + di_write_unlock(parent);
21100 + di_write_unlock(dentry);
21101 + if (unlikely(err < 0)) {
21108 + err = au_aopen_no_open(file, dentry);
21110 + aopen_node.h_file = args.file;
21111 + err = au_aopen_do_open(file, dentry, &aopen_node);
21113 + if (unlikely(err < 0)) {
21117 + au_lcnt_dec(&args.br->br_nfiles);
21119 + goto out_sb; /* success */
21122 + di_write_unlock(parent);
21123 + di_write_unlock(dentry);
21125 + si_read_unlock(sb);
21133 +/* ---------------------------------------------------------------------- */
21135 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
21136 + const unsigned char add_entry, aufs_bindex_t bcpup,
21137 + aufs_bindex_t btop)
21140 + struct dentry *h_parent;
21141 + struct inode *h_dir;
21144 + IMustLock(d_inode(parent));
21146 + di_write_lock_parent(parent);
21149 + if (!au_h_dptr(parent, bcpup)) {
21150 + if (btop > bcpup)
21151 + err = au_cpup_dirs(dentry, bcpup);
21152 + else if (btop < bcpup)
21153 + err = au_cpdown_dirs(dentry, bcpup);
21157 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
21158 + h_parent = au_h_dptr(parent, bcpup);
21159 + h_dir = d_inode(h_parent);
21160 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
21161 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
21162 + /* todo: no unlock here */
21163 + inode_unlock_shared(h_dir);
21165 + AuDbg("bcpup %d\n", bcpup);
21167 + if (d_really_is_negative(dentry))
21168 + au_set_h_dptr(dentry, btop, NULL);
21169 + au_update_dbrange(dentry, /*do_put_zero*/0);
21174 + di_write_unlock(parent);
21176 + err = bcpup; /* success */
21183 + * decide the branch and the parent dir where we will create a new entry.
21184 + * returns new bindex or an error.
21185 + * copyup the parent dir if needed.
21187 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
21188 + struct au_wr_dir_args *args)
21191 + unsigned int flags;
21192 + aufs_bindex_t bcpup, btop, src_btop;
21193 + const unsigned char add_entry
21194 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
21195 + | au_ftest_wrdir(args->flags, TMPFILE);
21196 + struct super_block *sb;
21197 + struct dentry *parent;
21198 + struct au_sbinfo *sbinfo;
21200 + sb = dentry->d_sb;
21201 + sbinfo = au_sbi(sb);
21202 + parent = dget_parent(dentry);
21203 + btop = au_dbtop(dentry);
21205 + if (args->force_btgt < 0) {
21206 + if (src_dentry) {
21207 + src_btop = au_dbtop(src_dentry);
21208 + if (src_btop < btop)
21209 + bcpup = src_btop;
21210 + } else if (add_entry) {
21212 + if (au_ftest_wrdir(args->flags, ISDIR))
21213 + au_fset_wbr(flags, DIR);
21214 + err = AuWbrCreate(sbinfo, dentry, flags);
21218 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
21220 + err = AuWbrCopyup(sbinfo, dentry);
21222 + if (!IS_ROOT(dentry)) {
21223 + di_read_lock_parent(parent, !AuLock_IR);
21224 + err = AuWbrCopyup(sbinfo, dentry);
21225 + di_read_unlock(parent, !AuLock_IR);
21227 + err = AuWbrCopyup(sbinfo, dentry);
21230 + if (unlikely(err < 0))
21234 + bcpup = args->force_btgt;
21235 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21238 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21240 + if (bcpup == btop)
21241 + goto out; /* success */
21243 + /* copyup the new parent into the branch we process */
21244 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21246 + if (d_really_is_negative(dentry)) {
21247 + au_set_h_dptr(dentry, btop, NULL);
21248 + au_set_dbtop(dentry, bcpup);
21249 + au_set_dbbot(dentry, bcpup);
21251 + AuDebugOn(add_entry
21252 + && !au_ftest_wrdir(args->flags, TMPFILE)
21253 + && !au_h_dptr(dentry, bcpup));
21261 +/* ---------------------------------------------------------------------- */
21263 +void au_pin_hdir_unlock(struct au_pin *p)
21266 + au_hn_inode_unlock(p->hdir);
21269 +int au_pin_hdir_lock(struct au_pin *p)
21277 + /* even if an error happens later, keep this lock */
21278 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21281 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21286 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21287 + p->h_parent, p->br);
21293 +int au_pin_hdir_relock(struct au_pin *p)
21296 + struct inode *h_i;
21297 + struct dentry *h_d[] = {
21302 + err = au_pin_hdir_lock(p);
21303 + if (unlikely(err))
21306 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21309 + if (d_is_positive(h_d[i])) {
21310 + h_i = d_inode(h_d[i]);
21311 + err = !h_i->i_nlink;
21319 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21321 +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER)
21322 + p->hdir->hi_inode->i_rwsem.owner = task;
21326 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21329 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21330 + p->lsc_hi, 0, NULL, _RET_IP_);
21331 + au_pin_hdir_set_owner(p, current);
21335 +void au_pin_hdir_release(struct au_pin *p)
21338 + au_pin_hdir_set_owner(p, p->task);
21339 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
21343 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21345 + if (pin && pin->parent)
21346 + return au_h_dptr(pin->parent, pin->bindex);
21350 +void au_unpin(struct au_pin *p)
21353 + au_pin_hdir_unlock(p);
21354 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21355 + vfsub_mnt_drop_write(p->h_mnt);
21359 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21360 + di_read_unlock(p->parent, AuLock_IR);
21361 + iput(p->hdir->hi_inode);
21363 + p->parent = NULL;
21366 + /* do not clear p->task */
21369 +int au_do_pin(struct au_pin *p)
21372 + struct super_block *sb;
21373 + struct inode *h_dir;
21376 + sb = p->dentry->d_sb;
21377 + p->br = au_sbr(sb, p->bindex);
21378 + if (IS_ROOT(p->dentry)) {
21379 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21380 + p->h_mnt = au_br_mnt(p->br);
21381 + err = vfsub_mnt_want_write(p->h_mnt);
21382 + if (unlikely(err)) {
21383 + au_fclr_pin(p->flags, MNT_WRITE);
21390 + p->h_dentry = NULL;
21391 + if (p->bindex <= au_dbbot(p->dentry))
21392 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21394 + p->parent = dget_parent(p->dentry);
21395 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21396 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21399 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21400 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21402 + h_dir = p->hdir->hi_inode;
21406 + * if DI_LOCKED is not set, then p->parent may be different
21407 + * and h_parent can be NULL.
21409 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21411 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21412 + di_read_unlock(p->parent, AuLock_IR);
21414 + p->parent = NULL;
21418 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21419 + p->h_mnt = au_br_mnt(p->br);
21420 + err = vfsub_mnt_want_write(p->h_mnt);
21421 + if (unlikely(err)) {
21422 + au_fclr_pin(p->flags, MNT_WRITE);
21423 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21424 + di_read_unlock(p->parent, AuLock_IR);
21426 + p->parent = NULL;
21432 + err = au_pin_hdir_lock(p);
21434 + goto out; /* success */
21439 + pr_err("err %d\n", err);
21440 + err = au_busy_or_stale();
21445 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21446 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21447 + unsigned int udba, unsigned char flags)
21449 + p->dentry = dentry;
21451 + p->lsc_di = lsc_di;
21452 + p->lsc_hi = lsc_hi;
21453 + p->flags = flags;
21454 + p->bindex = bindex;
21456 + p->parent = NULL;
21460 + p->h_dentry = NULL;
21461 + p->h_parent = NULL;
21463 + p->task = current;
21466 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21467 + unsigned int udba, unsigned char flags)
21469 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21471 + return au_do_pin(pin);
21474 +/* ---------------------------------------------------------------------- */
21477 + * ->setattr() and ->getattr() are called in various cases.
21478 + * chmod, stat: dentry is revalidated.
21479 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21481 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21483 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21484 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21487 + struct dentry *parent;
21490 + if (au_digen_test(dentry, sigen)) {
21491 + parent = dget_parent(dentry);
21492 + di_read_lock_parent(parent, AuLock_IR);
21493 + err = au_refresh_dentry(dentry, parent);
21494 + di_read_unlock(parent, AuLock_IR);
21502 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21503 + struct au_icpup_args *a)
21507 + aufs_bindex_t btop, ibtop;
21508 + struct dentry *hi_wh, *parent;
21509 + struct inode *inode;
21510 + struct au_wr_dir_args wr_dir_args = {
21511 + .force_btgt = -1,
21515 + if (d_is_dir(dentry))
21516 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21517 + /* plink or hi_wh() case */
21518 + btop = au_dbtop(dentry);
21519 + inode = d_inode(dentry);
21520 + ibtop = au_ibtop(inode);
21521 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21522 + wr_dir_args.force_btgt = ibtop;
21523 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21524 + if (unlikely(err < 0))
21528 + au_fset_icpup(a->flags, DID_CPUP);
21531 + a->pin_flags = AuPin_MNT_WRITE;
21533 + if (!IS_ROOT(dentry)) {
21534 + au_fset_pin(a->pin_flags, DI_LOCKED);
21535 + parent = dget_parent(dentry);
21536 + di_write_lock_parent(parent);
21539 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21540 + if (unlikely(err))
21544 + a->h_path.dentry = au_h_dptr(dentry, btop);
21545 + a->h_inode = d_inode(a->h_path.dentry);
21546 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21547 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21548 + if (ia->ia_size < i_size_read(a->h_inode))
21549 + sz = ia->ia_size;
21550 + inode_unlock_shared(a->h_inode);
21554 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21555 + hi_wh = au_hi_wh(inode, a->btgt);
21557 + struct au_cp_generic cpg = {
21558 + .dentry = dentry,
21564 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21565 + if (unlikely(err))
21567 + hi_wh = au_hi_wh(inode, a->btgt);
21568 + /* todo: revalidate hi_wh? */
21573 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21574 + di_downgrade_lock(parent, AuLock_IR);
21578 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21579 + goto out; /* success */
21581 + if (!d_unhashed(dentry)) {
21582 + struct au_cp_generic cpg = {
21583 + .dentry = dentry,
21588 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21590 + err = au_sio_cpup_simple(&cpg);
21592 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21593 + } else if (!hi_wh)
21594 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21596 + a->h_path.dentry = hi_wh; /* do not dget here */
21599 + a->h_inode = d_inode(a->h_path.dentry);
21601 + goto out; /* success */
21602 + au_unpin(&a->pin);
21605 + di_write_unlock(parent);
21610 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21614 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21617 + struct inode *inode, *delegated;
21618 + struct super_block *sb;
21619 + struct file *file;
21620 + struct au_icpup_args *a;
21622 + inode = d_inode(dentry);
21623 + IMustLock(inode);
21625 + err = setattr_prepare(dentry, ia);
21626 + if (unlikely(err))
21630 + a = kzalloc(sizeof(*a), GFP_NOFS);
21631 + if (unlikely(!a))
21634 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21635 + ia->ia_valid &= ~ATTR_MODE;
21638 + sb = dentry->d_sb;
21639 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21640 + if (unlikely(err))
21643 + if (ia->ia_valid & ATTR_FILE) {
21644 + /* currently ftruncate(2) only */
21645 + AuDebugOn(!d_is_reg(dentry));
21646 + file = ia->ia_file;
21647 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21649 + if (unlikely(err))
21651 + ia->ia_file = au_hf_top(file);
21652 + a->udba = AuOpt_UDBA_NONE;
21654 + /* fchmod() doesn't pass ia_file */
21655 + a->udba = au_opt_udba(sb);
21656 + di_write_lock_child(dentry);
21657 + /* no d_unlinked(), to set UDBA_NONE for root */
21658 + if (d_unhashed(dentry))
21659 + a->udba = AuOpt_UDBA_NONE;
21660 + if (a->udba != AuOpt_UDBA_NONE) {
21661 + AuDebugOn(IS_ROOT(dentry));
21662 + err = au_reval_for_attr(dentry, au_sigen(sb));
21663 + if (unlikely(err))
21668 + err = au_pin_and_icpup(dentry, ia, a);
21669 + if (unlikely(err < 0))
21671 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21672 + ia->ia_file = NULL;
21673 + ia->ia_valid &= ~ATTR_FILE;
21676 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21677 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21678 + == (ATTR_MODE | ATTR_CTIME)) {
21679 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21680 + if (unlikely(err))
21682 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21683 + && (ia->ia_valid & ATTR_CTIME)) {
21684 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21685 + if (unlikely(err))
21689 + if (ia->ia_valid & ATTR_SIZE) {
21692 + if (ia->ia_size < i_size_read(inode))
21694 + truncate_setsize(inode, ia->ia_size);
21697 + if (ia->ia_valid & ATTR_FILE)
21699 + inode_unlock(a->h_inode);
21700 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21701 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21703 + delegated = NULL;
21705 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21707 + err = break_deleg_wait(&delegated);
21715 + * regardless aufs 'acl' option setting.
21716 + * why don't all acl-aware fs call this func from their ->setattr()?
21718 + if (!err && (ia->ia_valid & ATTR_MODE))
21719 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21721 + au_cpup_attr_changeable(inode);
21724 + inode_unlock(a->h_inode);
21725 + au_unpin(&a->pin);
21726 + if (unlikely(err))
21727 + au_update_dbtop(dentry);
21729 + di_write_unlock(dentry);
21731 + fi_write_unlock(file);
21732 + ia->ia_file = file;
21733 + ia->ia_valid |= ATTR_FILE;
21736 + si_read_unlock(sb);
21744 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21745 +static int au_h_path_to_set_attr(struct dentry *dentry,
21746 + struct au_icpup_args *a, struct path *h_path)
21749 + struct super_block *sb;
21751 + sb = dentry->d_sb;
21752 + a->udba = au_opt_udba(sb);
21753 + /* no d_unlinked(), to set UDBA_NONE for root */
21754 + if (d_unhashed(dentry))
21755 + a->udba = AuOpt_UDBA_NONE;
21756 + if (a->udba != AuOpt_UDBA_NONE) {
21757 + AuDebugOn(IS_ROOT(dentry));
21758 + err = au_reval_for_attr(dentry, au_sigen(sb));
21759 + if (unlikely(err))
21762 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21763 + if (unlikely(err < 0))
21766 + h_path->dentry = a->h_path.dentry;
21767 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21773 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21774 + struct au_sxattr *arg)
21777 + struct path h_path;
21778 + struct super_block *sb;
21779 + struct au_icpup_args *a;
21780 + struct inode *h_inode;
21782 + IMustLock(inode);
21785 + a = kzalloc(sizeof(*a), GFP_NOFS);
21786 + if (unlikely(!a))
21789 + sb = dentry->d_sb;
21790 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21791 + if (unlikely(err))
21794 + h_path.dentry = NULL; /* silence gcc */
21795 + di_write_lock_child(dentry);
21796 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21797 + if (unlikely(err))
21800 + inode_unlock(a->h_inode);
21801 + switch (arg->type) {
21802 + case AU_XATTR_SET:
21803 + AuDebugOn(d_is_negative(h_path.dentry));
21804 + err = vfsub_setxattr(h_path.dentry,
21805 + arg->u.set.name, arg->u.set.value,
21806 + arg->u.set.size, arg->u.set.flags);
21809 + err = -EOPNOTSUPP;
21810 + h_inode = d_inode(h_path.dentry);
21811 + if (h_inode->i_op->set_acl)
21812 + /* this will call posix_acl_update_mode */
21813 + err = h_inode->i_op->set_acl(h_inode,
21814 + arg->u.acl_set.acl,
21815 + arg->u.acl_set.type);
21819 + au_cpup_attr_timesizes(inode);
21821 + au_unpin(&a->pin);
21822 + if (unlikely(err))
21823 + au_update_dbtop(dentry);
21826 + di_write_unlock(dentry);
21827 + si_read_unlock(sb);
21836 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21837 + unsigned int nlink)
21841 + inode->i_mode = st->mode;
21842 + /* don't i_[ug]id_write() here */
21843 + inode->i_uid = st->uid;
21844 + inode->i_gid = st->gid;
21845 + inode->i_atime = st->atime;
21846 + inode->i_mtime = st->mtime;
21847 + inode->i_ctime = st->ctime;
21849 + au_cpup_attr_nlink(inode, /*force*/0);
21850 + if (S_ISDIR(inode->i_mode)) {
21851 + n = inode->i_nlink;
21854 + smp_mb(); /* for i_nlink */
21855 + /* 0 can happen */
21856 + set_nlink(inode, n);
21859 + spin_lock(&inode->i_lock);
21860 + inode->i_blocks = st->blocks;
21861 + i_size_write(inode, st->size);
21862 + spin_unlock(&inode->i_lock);
21866 + * common routine for aufs_getattr() and au_getxattr().
21867 + * returns zero or negative (an error).
21868 + * @dentry will be read-locked in success.
21870 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
21874 + unsigned int mnt_flags, sigen;
21875 + unsigned char udba_none;
21876 + aufs_bindex_t bindex;
21877 + struct super_block *sb, *h_sb;
21878 + struct inode *inode;
21880 + h_path->mnt = NULL;
21881 + h_path->dentry = NULL;
21884 + sb = dentry->d_sb;
21885 + mnt_flags = au_mntflags(sb);
21886 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21888 + if (unlikely(locked))
21889 + goto body; /* skip locking dinfo */
21891 + /* support fstat(2) */
21892 + if (!d_unlinked(dentry) && !udba_none) {
21893 + sigen = au_sigen(sb);
21894 + err = au_digen_test(dentry, sigen);
21896 + di_read_lock_child(dentry, AuLock_IR);
21897 + err = au_dbrange_test(dentry);
21898 + if (unlikely(err)) {
21899 + di_read_unlock(dentry, AuLock_IR);
21903 + AuDebugOn(IS_ROOT(dentry));
21904 + di_write_lock_child(dentry);
21905 + err = au_dbrange_test(dentry);
21907 + err = au_reval_for_attr(dentry, sigen);
21909 + di_downgrade_lock(dentry, AuLock_IR);
21911 + di_write_unlock(dentry);
21916 + di_read_lock_child(dentry, AuLock_IR);
21919 + inode = d_inode(dentry);
21920 + bindex = au_ibtop(inode);
21921 + h_path->mnt = au_sbr_mnt(sb, bindex);
21922 + h_sb = h_path->mnt->mnt_sb;
21924 + && !au_test_fs_bad_iattr(h_sb)
21926 + goto out; /* success */
21928 + if (au_dbtop(dentry) == bindex)
21929 + h_path->dentry = au_h_dptr(dentry, bindex);
21930 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21931 + h_path->dentry = au_plink_lkup(inode, bindex);
21932 + if (IS_ERR(h_path->dentry))
21933 + /* pretending success */
21934 + h_path->dentry = NULL;
21936 + dput(h_path->dentry);
21943 +static int aufs_getattr(const struct path *path, struct kstat *st,
21944 + u32 request, unsigned int query)
21947 + unsigned char positive;
21948 + struct path h_path;
21949 + struct dentry *dentry;
21950 + struct inode *inode;
21951 + struct super_block *sb;
21953 + dentry = path->dentry;
21954 + inode = d_inode(dentry);
21955 + sb = dentry->d_sb;
21956 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21957 + if (unlikely(err))
21959 + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
21960 + if (unlikely(err))
21962 + if (unlikely(!h_path.dentry))
21963 + /* illegally overlapped or something */
21964 + goto out_fill; /* pretending success */
21966 + positive = d_is_positive(h_path.dentry);
21968 + /* no vfsub version */
21969 + err = vfs_getattr(&h_path, st, request, query);
21972 + au_refresh_iattr(inode, st,
21973 + d_inode(h_path.dentry)->i_nlink);
21974 + goto out_fill; /* success */
21980 + generic_fillattr(inode, st);
21982 + di_read_unlock(dentry, AuLock_IR);
21984 + si_read_unlock(sb);
21990 +/* ---------------------------------------------------------------------- */
21992 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21993 + struct delayed_call *done)
21996 + struct dentry *h_dentry;
21997 + struct inode *h_inode;
21999 + aufs_bindex_t bindex;
22001 + ret = NULL; /* suppress a warning */
22006 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
22007 + if (unlikely(err))
22010 + err = au_d_hashed_positive(dentry);
22011 + if (unlikely(err))
22015 + inode = d_inode(dentry);
22016 + bindex = au_ibtop(inode);
22017 + h_inode = au_h_iptr(inode, bindex);
22018 + if (unlikely(!h_inode->i_op->get_link))
22023 + if (au_dbtop(dentry) <= bindex) {
22024 + h_dentry = au_h_dptr(dentry, bindex);
22029 + h_dentry = d_find_any_alias(h_inode);
22030 + if (IS_ERR(h_dentry)) {
22031 + err = PTR_ERR(h_dentry);
22035 + if (unlikely(!h_dentry))
22039 + AuDbg("%ps\n", h_inode->i_op->get_link);
22040 + AuDbgDentry(h_dentry);
22041 + ret = vfs_get_link(h_dentry, done);
22044 + err = PTR_ERR(ret);
22047 + aufs_read_unlock(dentry, AuLock_IR);
22049 + if (unlikely(err))
22050 + ret = ERR_PTR(err);
22051 + AuTraceErrPtr(ret);
22055 +/* ---------------------------------------------------------------------- */
22057 +static int au_is_special(struct inode *inode)
22059 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
22062 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
22066 + aufs_bindex_t bindex;
22067 + struct super_block *sb;
22068 + struct inode *h_inode;
22069 + struct vfsmount *h_mnt;
22071 + sb = inode->i_sb;
22072 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
22073 + "unexpected s_flags 0x%lx", sb->s_flags);
22075 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
22077 + si_read_lock(sb, AuLock_FLUSH);
22078 + ii_write_lock_child(inode);
22081 + bindex = au_ibtop(inode);
22082 + h_inode = au_h_iptr(inode, bindex);
22083 + if (!au_test_ro(sb, bindex, inode)) {
22084 + h_mnt = au_sbr_mnt(sb, bindex);
22085 + err = vfsub_mnt_want_write(h_mnt);
22087 + err = vfsub_update_time(h_inode, ts, flags);
22088 + vfsub_mnt_drop_write(h_mnt);
22090 + } else if (au_is_special(h_inode)) {
22092 + * Never copy-up here.
22093 + * These special files may already be opened and used for
22094 + * communicating. If we copied it up, then the communication
22095 + * would be corrupted.
22097 + AuWarn1("timestamps for i%lu are ignored "
22098 + "since it is on readonly branch (hi%lu).\n",
22099 + inode->i_ino, h_inode->i_ino);
22100 + } else if (flags & ~S_ATIME) {
22102 + AuIOErr1("unexpected flags 0x%x\n", flags);
22107 + au_cpup_attr_timesizes(inode);
22108 + ii_write_unlock(inode);
22109 + si_read_unlock(sb);
22112 + if (!err && (flags & S_VERSION))
22113 + inode_inc_iversion(inode);
22118 +/* ---------------------------------------------------------------------- */
22120 +/* no getattr version will be set by module.c:aufs_init() */
22121 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
22123 + [AuIop_SYMLINK] = {
22124 + .permission = aufs_permission,
22125 +#ifdef CONFIG_FS_POSIX_ACL
22126 + .get_acl = aufs_get_acl,
22127 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
22130 + .setattr = aufs_setattr,
22131 + .getattr = aufs_getattr,
22133 +#ifdef CONFIG_AUFS_XATTR
22134 + .listxattr = aufs_listxattr,
22137 + .get_link = aufs_get_link,
22139 + /* .update_time = aufs_update_time */
22142 + .create = aufs_create,
22143 + .lookup = aufs_lookup,
22144 + .link = aufs_link,
22145 + .unlink = aufs_unlink,
22146 + .symlink = aufs_symlink,
22147 + .mkdir = aufs_mkdir,
22148 + .rmdir = aufs_rmdir,
22149 + .mknod = aufs_mknod,
22150 + .rename = aufs_rename,
22152 + .permission = aufs_permission,
22153 +#ifdef CONFIG_FS_POSIX_ACL
22154 + .get_acl = aufs_get_acl,
22155 + .set_acl = aufs_set_acl,
22158 + .setattr = aufs_setattr,
22159 + .getattr = aufs_getattr,
22161 +#ifdef CONFIG_AUFS_XATTR
22162 + .listxattr = aufs_listxattr,
22165 + .update_time = aufs_update_time,
22166 + .atomic_open = aufs_atomic_open,
22167 + .tmpfile = aufs_tmpfile
22169 + [AuIop_OTHER] = {
22170 + .permission = aufs_permission,
22171 +#ifdef CONFIG_FS_POSIX_ACL
22172 + .get_acl = aufs_get_acl,
22173 + .set_acl = aufs_set_acl,
22176 + .setattr = aufs_setattr,
22177 + .getattr = aufs_getattr,
22179 +#ifdef CONFIG_AUFS_XATTR
22180 + .listxattr = aufs_listxattr,
22183 + .update_time = aufs_update_time
22186 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
22187 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
22188 +++ linux/fs/aufs/i_op_del.c 2019-05-06 09:03:04.816810402 +0200
22190 +// SPDX-License-Identifier: GPL-2.0
22192 + * Copyright (C) 2005-2019 Junjiro R. Okajima
22194 + * This program, aufs is free software; you can redistribute it and/or modify
22195 + * it under the terms of the GNU General Public License as published by
22196 + * the Free Software Foundation; either version 2 of the License, or
22197 + * (at your option) any later version.
22199 + * This program is distributed in the hope that it will be useful,
22200 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22201 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22202 + * GNU General Public License for more details.
22204 + * You should have received a copy of the GNU General Public License
22205 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22209 + * inode operations (del entry)
22212 +#include <linux/iversion.h>
22216 + * decide if a new whiteout for @dentry is necessary or not.
22217 + * when it is necessary, prepare the parent dir for the upper branch whose
22218 + * branch index is @bcpup for creation. the actual creation of the whiteout will
22219 + * be done by caller.
22221 + * 0: wh is unnecessary
22222 + * plus: wh is necessary
22225 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
22227 + int need_wh, err;
22228 + aufs_bindex_t btop;
22229 + struct super_block *sb;
22231 + sb = dentry->d_sb;
22232 + btop = au_dbtop(dentry);
22233 + if (*bcpup < 0) {
22235 + if (au_test_ro(sb, btop, d_inode(dentry))) {
22236 + err = AuWbrCopyup(au_sbi(sb), dentry);
22238 + if (unlikely(err < 0))
22242 + AuDebugOn(btop < *bcpup
22243 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22244 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22246 + if (*bcpup != btop) {
22247 + err = au_cpup_dirs(dentry, *bcpup);
22248 + if (unlikely(err))
22252 + struct au_dinfo *dinfo, *tmp;
22254 + need_wh = -ENOMEM;
22255 + dinfo = au_di(dentry);
22256 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22258 + au_di_cp(tmp, dinfo);
22259 + au_di_swap(tmp, dinfo);
22260 + /* returns the number of positive dentries */
22261 + need_wh = au_lkup_dentry(dentry, btop + 1,
22262 + /* AuLkup_IGNORE_PERM */ 0);
22263 + au_di_swap(tmp, dinfo);
22264 + au_rw_write_unlock(&tmp->di_rwsem);
22268 + AuDbg("need_wh %d\n", need_wh);
22276 + * simple tests for the del-entry operations.
22277 + * following the checks in vfs, plus the parent-child relationship.
22279 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22280 + struct dentry *h_parent, int isdir)
22284 + struct dentry *h_dentry, *h_latest;
22285 + struct inode *h_inode;
22287 + h_dentry = au_h_dptr(dentry, bindex);
22288 + if (d_really_is_positive(dentry)) {
22290 + if (unlikely(d_is_negative(h_dentry)))
22292 + h_inode = d_inode(h_dentry);
22293 + if (unlikely(!h_inode->i_nlink))
22296 + h_mode = h_inode->i_mode;
22299 + if (unlikely(S_ISDIR(h_mode)))
22301 + } else if (unlikely(!S_ISDIR(h_mode))) {
22306 + /* rename(2) case */
22308 + if (unlikely(d_is_positive(h_dentry)))
22313 + /* expected parent dir is locked */
22314 + if (unlikely(h_parent != h_dentry->d_parent))
22319 + * rmdir a dir may break the consistency on some filesystem.
22320 + * let's try heavy test.
22323 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22324 + && au_test_h_perm(d_inode(h_parent),
22325 + MAY_EXEC | MAY_WRITE)))
22328 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
22330 + if (IS_ERR(h_latest))
22332 + if (h_latest == h_dentry)
22341 + * decide the branch where we operate for @dentry. the branch index will be set
22342 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22343 + * dir for reverting.
22344 + * when a new whiteout is necessary, create it.
22346 +static struct dentry*
22347 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22348 + struct au_dtime *dt, struct au_pin *pin)
22350 + struct dentry *wh_dentry;
22351 + struct super_block *sb;
22352 + struct path h_path;
22353 + int err, need_wh;
22354 + unsigned int udba;
22355 + aufs_bindex_t bcpup;
22357 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22358 + wh_dentry = ERR_PTR(need_wh);
22359 + if (unlikely(need_wh < 0))
22362 + sb = dentry->d_sb;
22363 + udba = au_opt_udba(sb);
22365 + err = au_pin(pin, dentry, bcpup, udba,
22366 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22367 + wh_dentry = ERR_PTR(err);
22368 + if (unlikely(err))
22371 + h_path.dentry = au_pinned_h_parent(pin);
22372 + if (udba != AuOpt_UDBA_NONE
22373 + && au_dbtop(dentry) == bcpup) {
22374 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22375 + wh_dentry = ERR_PTR(err);
22376 + if (unlikely(err))
22380 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22381 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22382 + wh_dentry = NULL;
22384 + goto out; /* success, no need to create whiteout */
22386 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22387 + if (IS_ERR(wh_dentry))
22390 + /* returns with the parent is locked and wh_dentry is dget-ed */
22391 + goto out; /* success */
22396 + return wh_dentry;
22400 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22401 + * in order to be revertible and save time for removing many child whiteouts
22403 + * returns 1 when there are too many child whiteout and caller should remove
22404 + * them asynchronously. returns 0 when the number of children is enough small to
22405 + * remove now or the branch fs is a remote fs.
22406 + * otherwise return an error.
22408 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22409 + struct au_nhash *whlist, struct inode *dir)
22411 + int rmdir_later, err, dirwh;
22412 + struct dentry *h_dentry;
22413 + struct super_block *sb;
22414 + struct inode *inode;
22416 + sb = dentry->d_sb;
22417 + SiMustAnyLock(sb);
22418 + h_dentry = au_h_dptr(dentry, bindex);
22419 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22420 + if (unlikely(err))
22423 + /* stop monitoring */
22424 + inode = d_inode(dentry);
22425 + au_hn_free(au_hi(inode, bindex));
22427 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22428 + dirwh = au_sbi(sb)->si_dirwh;
22429 + rmdir_later = (dirwh <= 1);
22430 + if (!rmdir_later)
22431 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22434 + return rmdir_later;
22437 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22438 + if (unlikely(err)) {
22439 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22440 + h_dentry, bindex, err);
22450 + * final procedure for deleting a entry.
22451 + * maintain dentry and iattr.
22453 +static void epilog(struct inode *dir, struct dentry *dentry,
22454 + aufs_bindex_t bindex)
22456 + struct inode *inode;
22458 + inode = d_inode(dentry);
22460 + inode->i_ctime = dir->i_ctime;
22462 + au_dir_ts(dir, bindex);
22463 + inode_inc_iversion(dir);
22467 + * when an error happened, remove the created whiteout and revert everything.
22469 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22470 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22471 + struct dentry *dentry, struct au_dtime *dt)
22474 + struct path h_path = {
22475 + .dentry = wh_dentry,
22476 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22479 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22481 + au_set_dbwh(dentry, bwh);
22482 + au_dtime_revert(dt);
22486 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22490 +/* ---------------------------------------------------------------------- */
22492 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22495 + aufs_bindex_t bwh, bindex, btop;
22496 + struct inode *inode, *h_dir, *delegated;
22497 + struct dentry *parent, *wh_dentry;
22498 + /* to reduce stack size */
22500 + struct au_dtime dt;
22501 + struct au_pin pin;
22502 + struct path h_path;
22508 + a = kmalloc(sizeof(*a), GFP_NOFS);
22509 + if (unlikely(!a))
22512 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22513 + if (unlikely(err))
22515 + err = au_d_hashed_positive(dentry);
22516 + if (unlikely(err))
22518 + inode = d_inode(dentry);
22519 + IMustLock(inode);
22521 + if (unlikely(d_is_dir(dentry)))
22522 + goto out_unlock; /* possible? */
22524 + btop = au_dbtop(dentry);
22525 + bwh = au_dbwh(dentry);
22527 + parent = dentry->d_parent; /* dir inode is locked */
22528 + di_write_lock_parent(parent);
22529 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22531 + err = PTR_ERR(wh_dentry);
22532 + if (IS_ERR(wh_dentry))
22535 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22536 + a->h_path.dentry = au_h_dptr(dentry, btop);
22537 + dget(a->h_path.dentry);
22538 + if (bindex == btop) {
22539 + h_dir = au_pinned_h_dir(&a->pin);
22540 + delegated = NULL;
22541 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22542 + if (unlikely(err == -EWOULDBLOCK)) {
22543 + pr_warn("cannot retry for NFSv4 delegation"
22544 + " for an internal unlink\n");
22548 + /* dir inode is locked */
22549 + h_dir = d_inode(wh_dentry->d_parent);
22550 + IMustLock(h_dir);
22555 + vfsub_drop_nlink(inode);
22556 + epilog(dir, dentry, bindex);
22558 + /* update target timestamps */
22559 + if (bindex == btop) {
22560 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22562 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22564 + /* todo: this timestamp may be reverted later */
22565 + inode->i_ctime = h_dir->i_ctime;
22566 + goto out_unpin; /* success */
22573 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22580 + au_unpin(&a->pin);
22582 + dput(a->h_path.dentry);
22584 + di_write_unlock(parent);
22586 + aufs_read_unlock(dentry, AuLock_DW);
22593 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22595 + int err, rmdir_later;
22596 + aufs_bindex_t bwh, bindex, btop;
22597 + struct inode *inode;
22598 + struct dentry *parent, *wh_dentry, *h_dentry;
22599 + struct au_whtmp_rmdir *args;
22600 + /* to reduce stack size */
22602 + struct au_dtime dt;
22603 + struct au_pin pin;
22609 + a = kmalloc(sizeof(*a), GFP_NOFS);
22610 + if (unlikely(!a))
22613 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22614 + if (unlikely(err))
22616 + err = au_alive_dir(dentry);
22617 + if (unlikely(err))
22619 + inode = d_inode(dentry);
22620 + IMustLock(inode);
22622 + if (unlikely(!d_is_dir(dentry)))
22623 + goto out_unlock; /* possible? */
22626 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22627 + if (unlikely(!args))
22630 + parent = dentry->d_parent; /* dir inode is locked */
22631 + di_write_lock_parent(parent);
22632 + err = au_test_empty(dentry, &args->whlist);
22633 + if (unlikely(err))
22636 + btop = au_dbtop(dentry);
22637 + bwh = au_dbwh(dentry);
22639 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22641 + err = PTR_ERR(wh_dentry);
22642 + if (IS_ERR(wh_dentry))
22645 + h_dentry = au_h_dptr(dentry, btop);
22648 + if (bindex == btop) {
22649 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22651 + rmdir_later = err;
22655 + /* stop monitoring */
22656 + au_hn_free(au_hi(inode, btop));
22658 + /* dir inode is locked */
22659 + IMustLock(d_inode(wh_dentry->d_parent));
22664 + vfsub_dead_dir(inode);
22665 + au_set_dbdiropq(dentry, -1);
22666 + epilog(dir, dentry, bindex);
22668 + if (rmdir_later) {
22669 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22673 + goto out_unpin; /* success */
22681 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22688 + au_unpin(&a->pin);
22692 + di_write_unlock(parent);
22694 + au_whtmp_rmdir_free(args);
22696 + aufs_read_unlock(dentry, AuLock_DW);
22703 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22704 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22705 +++ linux/fs/aufs/i_op_ren.c 2019-05-06 09:03:04.820143837 +0200
22707 +// SPDX-License-Identifier: GPL-2.0
22709 + * Copyright (C) 2005-2019 Junjiro R. Okajima
22711 + * This program, aufs is free software; you can redistribute it and/or modify
22712 + * it under the terms of the GNU General Public License as published by
22713 + * the Free Software Foundation; either version 2 of the License, or
22714 + * (at your option) any later version.
22716 + * This program is distributed in the hope that it will be useful,
22717 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22718 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22719 + * GNU General Public License for more details.
22721 + * You should have received a copy of the GNU General Public License
22722 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22726 + * inode operation (rename entry)
22727 + * todo: this is crazy monster
22730 +#include <linux/iversion.h>
22733 +enum { AuSRC, AuDST, AuSrcDst };
22734 +enum { AuPARENT, AuCHILD, AuParentChild };
22736 +#define AuRen_ISDIR_SRC 1
22737 +#define AuRen_ISDIR_DST (1 << 1)
22738 +#define AuRen_ISSAMEDIR (1 << 2)
22739 +#define AuRen_WHSRC (1 << 3)
22740 +#define AuRen_WHDST (1 << 4)
22741 +#define AuRen_MNT_WRITE (1 << 5)
22742 +#define AuRen_DT_DSTDIR (1 << 6)
22743 +#define AuRen_DIROPQ_SRC (1 << 7)
22744 +#define AuRen_DIROPQ_DST (1 << 8)
22745 +#define AuRen_DIRREN (1 << 9)
22746 +#define AuRen_DROPPED_SRC (1 << 10)
22747 +#define AuRen_DROPPED_DST (1 << 11)
22748 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22749 +#define au_fset_ren(flags, name) \
22750 + do { (flags) |= AuRen_##name; } while (0)
22751 +#define au_fclr_ren(flags, name) \
22752 + do { (flags) &= ~AuRen_##name; } while (0)
22754 +#ifndef CONFIG_AUFS_DIRREN
22755 +#undef AuRen_DIRREN
22756 +#define AuRen_DIRREN 0
22759 +struct au_ren_args {
22761 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22763 + struct inode *dir, *inode;
22764 + struct au_hinode *hdir, *hinode;
22765 + struct au_dtime dt[AuParentChild];
22766 + aufs_bindex_t btop, bdiropq;
22769 +#define src_dentry sd[AuSRC].dentry
22770 +#define src_dir sd[AuSRC].dir
22771 +#define src_inode sd[AuSRC].inode
22772 +#define src_h_dentry sd[AuSRC].h_dentry
22773 +#define src_parent sd[AuSRC].parent
22774 +#define src_h_parent sd[AuSRC].h_parent
22775 +#define src_wh_dentry sd[AuSRC].wh_dentry
22776 +#define src_hdir sd[AuSRC].hdir
22777 +#define src_hinode sd[AuSRC].hinode
22778 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22779 +#define src_dt sd[AuSRC].dt
22780 +#define src_btop sd[AuSRC].btop
22781 +#define src_bdiropq sd[AuSRC].bdiropq
22783 +#define dst_dentry sd[AuDST].dentry
22784 +#define dst_dir sd[AuDST].dir
22785 +#define dst_inode sd[AuDST].inode
22786 +#define dst_h_dentry sd[AuDST].h_dentry
22787 +#define dst_parent sd[AuDST].parent
22788 +#define dst_h_parent sd[AuDST].h_parent
22789 +#define dst_wh_dentry sd[AuDST].wh_dentry
22790 +#define dst_hdir sd[AuDST].hdir
22791 +#define dst_hinode sd[AuDST].hinode
22792 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22793 +#define dst_dt sd[AuDST].dt
22794 +#define dst_btop sd[AuDST].btop
22795 +#define dst_bdiropq sd[AuDST].bdiropq
22797 + struct dentry *h_trap;
22798 + struct au_branch *br;
22799 + struct path h_path;
22800 + struct au_nhash whlist;
22801 + aufs_bindex_t btgt, src_bwh;
22804 + unsigned short auren_flags;
22805 + unsigned char flags; /* syscall parameter */
22806 + unsigned char exchange;
22809 + struct au_whtmp_rmdir *thargs;
22810 + struct dentry *h_dst;
22811 + struct au_hinode *h_root;
22814 +/* ---------------------------------------------------------------------- */
22817 + * functions for reverting.
22818 + * when an error happened in a single rename systemcall, we should revert
22819 + * everything as if nothing happened.
22820 + * we don't need to revert the copied-up/down the parent dir since they are
22824 +#define RevertFailure(fmt, ...) do { \
22825 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22826 + ##__VA_ARGS__, err, rerr); \
22830 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22833 + struct dentry *d;
22834 +#define src_or_dst(member) a->sd[idx].member
22836 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22837 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22838 + rerr = au_diropq_remove(d, a->btgt);
22839 + au_hn_inode_unlock(src_or_dst(hinode));
22840 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22842 + RevertFailure("remove diropq %pd", d);
22844 +#undef src_or_dst_
22847 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22849 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22850 + au_ren_do_rev_diropq(err, a, AuSRC);
22851 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22852 + au_ren_do_rev_diropq(err, a, AuDST);
22855 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22858 + struct inode *delegated;
22860 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22861 + a->src_h_parent);
22862 + rerr = PTR_ERR(a->h_path.dentry);
22863 + if (IS_ERR(a->h_path.dentry)) {
22864 + RevertFailure("lkup one %pd", a->src_dentry);
22868 + delegated = NULL;
22869 + rerr = vfsub_rename(a->dst_h_dir,
22870 + au_h_dptr(a->src_dentry, a->btgt),
22871 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22872 + if (unlikely(rerr == -EWOULDBLOCK)) {
22873 + pr_warn("cannot retry for NFSv4 delegation"
22874 + " for an internal rename\n");
22877 + d_drop(a->h_path.dentry);
22878 + dput(a->h_path.dentry);
22879 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22881 + RevertFailure("rename %pd", a->src_dentry);
22884 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22887 + struct inode *delegated;
22889 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22890 + a->dst_h_parent);
22891 + rerr = PTR_ERR(a->h_path.dentry);
22892 + if (IS_ERR(a->h_path.dentry)) {
22893 + RevertFailure("lkup one %pd", a->dst_dentry);
22896 + if (d_is_positive(a->h_path.dentry)) {
22897 + d_drop(a->h_path.dentry);
22898 + dput(a->h_path.dentry);
22902 + delegated = NULL;
22903 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22904 + &delegated, a->flags);
22905 + if (unlikely(rerr == -EWOULDBLOCK)) {
22906 + pr_warn("cannot retry for NFSv4 delegation"
22907 + " for an internal rename\n");
22910 + d_drop(a->h_path.dentry);
22911 + dput(a->h_path.dentry);
22913 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22915 + RevertFailure("rename %pd", a->h_dst);
22918 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22922 + a->h_path.dentry = a->src_wh_dentry;
22923 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22924 + au_set_dbwh(a->src_dentry, a->src_bwh);
22926 + RevertFailure("unlink %pd", a->src_wh_dentry);
22928 +#undef RevertFailure
22930 +/* ---------------------------------------------------------------------- */
22933 + * when we have to copyup the renaming entry, do it with the rename-target name
22934 + * in order to minimize the cost (the later actual rename is unnecessary).
22935 + * otherwise rename it on the target branch.
22937 +static int au_ren_or_cpup(struct au_ren_args *a)
22940 + struct dentry *d;
22941 + struct inode *delegated;
22943 + d = a->src_dentry;
22944 + if (au_dbtop(d) == a->btgt) {
22945 + a->h_path.dentry = a->dst_h_dentry;
22946 + AuDebugOn(au_dbtop(d) != a->btgt);
22947 + delegated = NULL;
22948 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22949 + a->dst_h_dir, &a->h_path, &delegated,
22951 + if (unlikely(err == -EWOULDBLOCK)) {
22952 + pr_warn("cannot retry for NFSv4 delegation"
22953 + " for an internal rename\n");
22959 + if (!err && a->h_dst)
22960 + /* it will be set to dinfo later */
22966 +/* cf. aufs_rmdir() */
22967 +static int au_ren_del_whtmp(struct au_ren_args *a)
22970 + struct inode *dir;
22972 + dir = a->dst_dir;
22973 + SiMustAnyLock(dir->i_sb);
22974 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22975 + au_sbi(dir->i_sb)->si_dirwh)
22976 + || au_test_fs_remote(a->h_dst->d_sb)) {
22977 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22978 + if (unlikely(err))
22979 + pr_warn("failed removing whtmp dir %pd (%d), "
22980 + "ignored.\n", a->h_dst, err);
22982 + au_nhash_wh_free(&a->thargs->whlist);
22983 + a->thargs->whlist = a->whlist;
22984 + a->whlist.nh_num = 0;
22985 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22987 + a->thargs = NULL;
22993 +/* make it 'opaque' dir. */
22994 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22997 + struct dentry *d, *diropq;
22998 +#define src_or_dst(member) a->sd[idx].member
23001 + d = src_or_dst(dentry); /* {src,dst}_dentry */
23002 + src_or_dst(bdiropq) = au_dbdiropq(d);
23003 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
23004 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
23005 + diropq = au_diropq_create(d, a->btgt);
23006 + au_hn_inode_unlock(src_or_dst(hinode));
23007 + if (IS_ERR(diropq))
23008 + err = PTR_ERR(diropq);
23012 +#undef src_or_dst_
23016 +static int au_ren_diropq(struct au_ren_args *a)
23019 + unsigned char always;
23020 + struct dentry *d;
23023 + d = a->dst_dentry; /* already renamed on the branch */
23024 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
23025 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23026 + && !au_ftest_ren(a->auren_flags, DIRREN)
23027 + && a->btgt != au_dbdiropq(a->src_dentry)
23028 + && (a->dst_wh_dentry
23029 + || a->btgt <= au_dbdiropq(d)
23030 + /* hide the lower to keep xino */
23031 + /* the lowers may not be a dir, but we hide them anyway */
23032 + || a->btgt < au_dbbot(d)
23035 + err = au_ren_do_diropq(a, AuSRC);
23036 + if (unlikely(err))
23038 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
23040 + if (!a->exchange)
23041 + goto out; /* success */
23043 + d = a->src_dentry; /* already renamed on the branch */
23044 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
23045 + && a->btgt != au_dbdiropq(a->dst_dentry)
23046 + && (a->btgt < au_dbdiropq(d)
23047 + || a->btgt < au_dbbot(d)
23049 + AuDbgDentry(a->src_dentry);
23050 + AuDbgDentry(a->dst_dentry);
23051 + err = au_ren_do_diropq(a, AuDST);
23052 + if (unlikely(err))
23053 + goto out_rev_src;
23054 + au_fset_ren(a->auren_flags, DIROPQ_DST);
23056 + goto out; /* success */
23059 + AuDbg("err %d, reverting src\n", err);
23060 + au_ren_rev_diropq(err, a);
23065 +static int do_rename(struct au_ren_args *a)
23068 + struct dentry *d, *h_d;
23070 + if (!a->exchange) {
23071 + /* prepare workqueue args for asynchronous rmdir */
23072 + h_d = a->dst_h_dentry;
23073 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
23074 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
23075 + && d_is_positive(h_d)) {
23077 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
23079 + if (unlikely(!a->thargs))
23081 + a->h_dst = dget(h_d);
23084 + /* create whiteout for src_dentry */
23085 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
23086 + a->src_bwh = au_dbwh(a->src_dentry);
23087 + AuDebugOn(a->src_bwh >= 0);
23088 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
23089 + a->src_h_parent);
23090 + err = PTR_ERR(a->src_wh_dentry);
23091 + if (IS_ERR(a->src_wh_dentry))
23095 + /* lookup whiteout for dentry */
23096 + if (au_ftest_ren(a->auren_flags, WHDST)) {
23097 + h_d = au_wh_lkup(a->dst_h_parent,
23098 + &a->dst_dentry->d_name, a->br);
23099 + err = PTR_ERR(h_d);
23102 + if (d_is_negative(h_d))
23105 + a->dst_wh_dentry = h_d;
23108 + /* rename dentry to tmpwh */
23110 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
23111 + if (unlikely(err))
23114 + d = a->dst_dentry;
23115 + au_set_h_dptr(d, a->btgt, NULL);
23116 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
23117 + if (unlikely(err))
23119 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
23123 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
23125 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
23126 + && d_is_positive(a->dst_h_dentry)
23127 + && a->src_btop != a->btgt);
23130 + /* rename by vfs_rename or cpup */
23131 + err = au_ren_or_cpup(a);
23132 + if (unlikely(err))
23133 + /* leave the copied-up one */
23136 + /* make dir opaque */
23137 + err = au_ren_diropq(a);
23138 + if (unlikely(err))
23141 + /* update target timestamps */
23142 + if (a->exchange) {
23143 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
23144 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
23145 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23146 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23148 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
23149 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
23150 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23151 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23153 + if (!a->exchange) {
23154 + /* remove whiteout for dentry */
23155 + if (a->dst_wh_dentry) {
23156 + a->h_path.dentry = a->dst_wh_dentry;
23157 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
23159 + if (unlikely(err))
23163 + /* remove whtmp */
23165 + au_ren_del_whtmp(a); /* ignore this error */
23167 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
23170 + goto out_success;
23173 + au_ren_rev_diropq(err, a);
23175 + au_ren_rev_rename(err, a);
23179 + au_ren_rev_whtmp(err, a);
23181 + dput(a->dst_wh_dentry);
23182 + a->dst_wh_dentry = NULL;
23184 + if (a->src_wh_dentry)
23185 + au_ren_rev_whsrc(err, a);
23187 + dput(a->src_wh_dentry);
23188 + dput(a->dst_wh_dentry);
23192 + au_whtmp_rmdir_free(a->thargs);
23193 + a->thargs = NULL;
23199 +/* ---------------------------------------------------------------------- */
23202 + * test if @dentry dir can be rename destination or not.
23203 + * success means, it is a logically empty dir.
23205 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
23207 + return au_test_empty(dentry, whlist);
23211 + * test if @a->src_dentry dir can be rename source or not.
23212 + * if it can, return 0.
23214 + * - it is a logically empty dir.
23215 + * - or, it exists on writable branch and has no children including whiteouts
23216 + * on the lower branch unless DIRREN is on.
23218 +static int may_rename_srcdir(struct au_ren_args *a)
23221 + unsigned int rdhash;
23222 + aufs_bindex_t btop, btgt;
23223 + struct dentry *dentry;
23224 + struct super_block *sb;
23225 + struct au_sbinfo *sbinfo;
23227 + dentry = a->src_dentry;
23228 + sb = dentry->d_sb;
23229 + sbinfo = au_sbi(sb);
23230 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
23231 + au_fset_ren(a->auren_flags, DIRREN);
23234 + btop = au_dbtop(dentry);
23235 + if (btop != btgt) {
23236 + struct au_nhash whlist;
23238 + SiMustAnyLock(sb);
23239 + rdhash = sbinfo->si_rdhash;
23241 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23243 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23244 + if (unlikely(err))
23246 + err = au_test_empty(dentry, &whlist);
23247 + au_nhash_wh_free(&whlist);
23251 + if (btop == au_dbtaildir(dentry))
23252 + return 0; /* success */
23254 + err = au_test_empty_lower(dentry);
23257 + if (err == -ENOTEMPTY) {
23258 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23261 + AuWarn1("renaming dir who has child(ren) on multiple "
23262 + "branches, is not supported\n");
23269 +/* side effect: sets whlist and h_dentry */
23270 +static int au_ren_may_dir(struct au_ren_args *a)
23273 + unsigned int rdhash;
23274 + struct dentry *d;
23276 + d = a->dst_dentry;
23277 + SiMustAnyLock(d->d_sb);
23280 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23281 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23283 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23284 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23285 + if (unlikely(err))
23288 + if (!a->exchange) {
23289 + au_set_dbtop(d, a->dst_btop);
23290 + err = may_rename_dstdir(d, &a->whlist);
23291 + au_set_dbtop(d, a->btgt);
23293 + err = may_rename_srcdir(a);
23295 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23296 + if (unlikely(err))
23299 + d = a->src_dentry;
23300 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23301 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23302 + err = may_rename_srcdir(a);
23303 + if (unlikely(err)) {
23304 + au_nhash_wh_free(&a->whlist);
23305 + a->whlist.nh_num = 0;
23312 +/* ---------------------------------------------------------------------- */
23315 + * simple tests for rename.
23316 + * following the checks in vfs, plus the parent-child relationship.
23318 +static int au_may_ren(struct au_ren_args *a)
23321 + struct inode *h_inode;
23323 + if (a->src_btop == a->btgt) {
23324 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23325 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23326 + if (unlikely(err))
23329 + if (unlikely(a->src_h_dentry == a->h_trap))
23334 + if (a->dst_btop != a->btgt)
23337 + err = -ENOTEMPTY;
23338 + if (unlikely(a->dst_h_dentry == a->h_trap))
23342 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23343 + if (d_really_is_negative(a->dst_dentry)) {
23344 + if (d_is_negative(a->dst_h_dentry))
23345 + err = au_may_add(a->dst_dentry, a->btgt,
23346 + a->dst_h_parent, isdir);
23348 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23350 + h_inode = d_inode(a->dst_h_dentry);
23351 + if (h_inode->i_nlink)
23352 + err = au_may_del(a->dst_dentry, a->btgt,
23353 + a->dst_h_parent, isdir);
23357 + if (unlikely(err == -ENOENT || err == -EEXIST))
23363 +/* ---------------------------------------------------------------------- */
23368 + * - src_dir and dir by lock_rename()
23369 + * - inode if exists
23372 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23374 + * + di_write_lock2_child()
23375 + * + di_write_lock_child()
23376 + * + ii_write_lock_child()
23377 + * + di_write_lock_child2()
23378 + * + ii_write_lock_child2()
23379 + * + src_parent and parent
23380 + * + di_write_lock_parent()
23381 + * + ii_write_lock_parent()
23382 + * + di_write_lock_parent2()
23383 + * + ii_write_lock_parent2()
23384 + * + lower src_dir and dir by vfsub_lock_rename()
23385 + * + verify the every relationships between child and parent. if any
23386 + * of them failed, unlock all and return -EBUSY.
23388 +static void au_ren_unlock(struct au_ren_args *a)
23390 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23391 + a->dst_h_parent, a->dst_hdir);
23392 + if (au_ftest_ren(a->auren_flags, DIRREN)
23394 + au_hn_inode_unlock(a->h_root);
23395 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23396 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23399 +static int au_ren_lock(struct au_ren_args *a)
23402 + unsigned int udba;
23405 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23406 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23407 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23408 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23410 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23411 + if (unlikely(err))
23413 + au_fset_ren(a->auren_flags, MNT_WRITE);
23414 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23415 + struct dentry *root;
23416 + struct inode *dir;
23419 + * sbinfo is already locked, so this ii_read_lock is
23420 + * unnecessary. but our debugging feature checks it.
23422 + root = a->src_inode->i_sb->s_root;
23423 + if (root != a->src_parent && root != a->dst_parent) {
23424 + dir = d_inode(root);
23425 + ii_read_lock_parent3(dir);
23426 + a->h_root = au_hi(dir, a->btgt);
23427 + ii_read_unlock(dir);
23428 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23431 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23432 + a->dst_h_parent, a->dst_hdir);
23433 + udba = au_opt_udba(a->src_dentry->d_sb);
23434 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23435 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23436 + err = au_busy_or_stale();
23437 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23438 + err = au_h_verify(a->src_h_dentry, udba,
23439 + d_inode(a->src_h_parent), a->src_h_parent,
23441 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23442 + err = au_h_verify(a->dst_h_dentry, udba,
23443 + d_inode(a->dst_h_parent), a->dst_h_parent,
23446 + goto out; /* success */
23448 + err = au_busy_or_stale();
23449 + au_ren_unlock(a);
23455 +/* ---------------------------------------------------------------------- */
23457 +static void au_ren_refresh_dir(struct au_ren_args *a)
23459 + struct inode *dir;
23461 + dir = a->dst_dir;
23462 + inode_inc_iversion(dir);
23463 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23464 + /* is this updating defined in POSIX? */
23465 + au_cpup_attr_timesizes(a->src_inode);
23466 + au_cpup_attr_nlink(dir, /*force*/1);
23468 + au_dir_ts(dir, a->btgt);
23470 + if (a->exchange) {
23471 + dir = a->src_dir;
23472 + inode_inc_iversion(dir);
23473 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23474 + /* is this updating defined in POSIX? */
23475 + au_cpup_attr_timesizes(a->dst_inode);
23476 + au_cpup_attr_nlink(dir, /*force*/1);
23478 + au_dir_ts(dir, a->btgt);
23481 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23484 + dir = a->src_dir;
23485 + inode_inc_iversion(dir);
23486 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23487 + au_cpup_attr_nlink(dir, /*force*/1);
23488 + au_dir_ts(dir, a->btgt);
23491 +static void au_ren_refresh(struct au_ren_args *a)
23493 + aufs_bindex_t bbot, bindex;
23494 + struct dentry *d, *h_d;
23495 + struct inode *i, *h_i;
23496 + struct super_block *sb;
23498 + d = a->dst_dentry;
23501 + /* already dget-ed by au_ren_or_cpup() */
23502 + au_set_h_dptr(d, a->btgt, a->h_dst);
23504 + i = a->dst_inode;
23506 + if (!a->exchange) {
23507 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23508 + vfsub_drop_nlink(i);
23510 + vfsub_dead_dir(i);
23511 + au_cpup_attr_timesizes(i);
23513 + au_update_dbrange(d, /*do_put_zero*/1);
23515 + au_cpup_attr_nlink(i, /*force*/1);
23518 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23519 + au_set_h_dptr(d, bindex, NULL);
23520 + bbot = au_dbbot(d);
23521 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23522 + au_set_h_dptr(d, bindex, NULL);
23523 + au_update_dbrange(d, /*do_put_zero*/0);
23527 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23528 + d_drop(a->src_dentry);
23529 + if (au_ftest_ren(a->auren_flags, DIRREN))
23530 + au_set_dbwh(a->src_dentry, -1);
23534 + d = a->src_dentry;
23535 + au_set_dbwh(d, -1);
23536 + bbot = au_dbbot(d);
23537 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23538 + h_d = au_h_dptr(d, bindex);
23540 + au_set_h_dptr(d, bindex, NULL);
23542 + au_set_dbbot(d, a->btgt);
23545 + i = a->src_inode;
23546 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23547 + return; /* success */
23549 + bbot = au_ibbot(i);
23550 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23551 + h_i = au_h_iptr(i, bindex);
23553 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23554 + /* ignore this error */
23555 + au_set_h_iptr(i, bindex, NULL, 0);
23558 + au_set_ibbot(i, a->btgt);
23561 +/* ---------------------------------------------------------------------- */
23563 +/* mainly for link(2) and rename(2) */
23564 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23566 + aufs_bindex_t bdiropq, bwh;
23567 + struct dentry *parent;
23568 + struct au_branch *br;
23570 + parent = dentry->d_parent;
23571 + IMustLock(d_inode(parent)); /* dir is locked */
23573 + bdiropq = au_dbdiropq(parent);
23574 + bwh = au_dbwh(dentry);
23575 + br = au_sbr(dentry->d_sb, btgt);
23576 + if (au_br_rdonly(br)
23577 + || (0 <= bdiropq && bdiropq < btgt)
23578 + || (0 <= bwh && bwh < btgt))
23581 + AuDbg("btgt %d\n", btgt);
23585 +/* sets src_btop, dst_btop and btgt */
23586 +static int au_ren_wbr(struct au_ren_args *a)
23589 + struct au_wr_dir_args wr_dir_args = {
23590 + /* .force_btgt = -1, */
23591 + .flags = AuWrDir_ADD_ENTRY
23594 + a->src_btop = au_dbtop(a->src_dentry);
23595 + a->dst_btop = au_dbtop(a->dst_dentry);
23596 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23597 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23598 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23599 + wr_dir_args.force_btgt = a->src_btop;
23600 + if (a->dst_inode && a->dst_btop < a->src_btop)
23601 + wr_dir_args.force_btgt = a->dst_btop;
23602 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23603 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23606 + au_update_dbtop(a->dst_dentry);
23611 +static void au_ren_dt(struct au_ren_args *a)
23613 + a->h_path.dentry = a->src_h_parent;
23614 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23615 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23616 + a->h_path.dentry = a->dst_h_parent;
23617 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23620 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23621 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23625 + a->h_path.dentry = a->src_h_dentry;
23626 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23627 + if (d_is_positive(a->dst_h_dentry)) {
23628 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23629 + a->h_path.dentry = a->dst_h_dentry;
23630 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23634 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23636 + struct dentry *h_d;
23637 + struct inode *h_inode;
23639 + au_dtime_revert(a->src_dt + AuPARENT);
23640 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23641 + au_dtime_revert(a->dst_dt + AuPARENT);
23643 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23644 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23645 + h_inode = d_inode(h_d);
23646 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23647 + au_dtime_revert(a->src_dt + AuCHILD);
23648 + inode_unlock(h_inode);
23650 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23651 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23652 + h_inode = d_inode(h_d);
23653 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23654 + au_dtime_revert(a->dst_dt + AuCHILD);
23655 + inode_unlock(h_inode);
23660 +/* ---------------------------------------------------------------------- */
23662 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23663 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23664 + unsigned int _flags)
23666 + int err, lock_flags;
23668 + /* reduce stack space */
23669 + struct au_ren_args *a;
23670 + struct au_pin pin;
23672 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23673 + IMustLock(_src_dir);
23674 + IMustLock(_dst_dir);
23677 + if (unlikely(_flags & RENAME_WHITEOUT))
23681 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23682 + a = kzalloc(sizeof(*a), GFP_NOFS);
23683 + if (unlikely(!a))
23686 + a->flags = _flags;
23687 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23688 + && RENAME_EXCHANGE > U8_MAX);
23689 + a->exchange = _flags & RENAME_EXCHANGE;
23690 + a->src_dir = _src_dir;
23691 + a->src_dentry = _src_dentry;
23692 + a->src_inode = NULL;
23693 + if (d_really_is_positive(a->src_dentry))
23694 + a->src_inode = d_inode(a->src_dentry);
23695 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23696 + a->dst_dir = _dst_dir;
23697 + a->dst_dentry = _dst_dentry;
23698 + a->dst_inode = NULL;
23699 + if (d_really_is_positive(a->dst_dentry))
23700 + a->dst_inode = d_inode(a->dst_dentry);
23701 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23702 + if (a->dst_inode) {
23704 + * if EXCHANGE && src is non-dir && dst is dir,
23705 + * dst is not locked.
23707 + /* IMustLock(a->dst_inode); */
23708 + au_igrab(a->dst_inode);
23712 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23713 + if (d_is_dir(a->src_dentry)) {
23714 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23715 + if (unlikely(!a->exchange
23716 + && d_really_is_positive(a->dst_dentry)
23717 + && !d_is_dir(a->dst_dentry)))
23719 + lock_flags |= AuLock_DIRS;
23721 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23722 + au_fset_ren(a->auren_flags, ISDIR_DST);
23723 + if (unlikely(!a->exchange
23724 + && d_really_is_positive(a->src_dentry)
23725 + && !d_is_dir(a->src_dentry)))
23727 + lock_flags |= AuLock_DIRS;
23729 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23731 + if (unlikely(err))
23734 + err = au_d_hashed_positive(a->src_dentry);
23735 + if (unlikely(err))
23738 + if (a->dst_inode) {
23740 + * If it is a dir, VFS unhash it before this
23741 + * function. It means we cannot rely upon d_unhashed().
23743 + if (unlikely(!a->dst_inode->i_nlink))
23745 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23746 + err = au_d_hashed_positive(a->dst_dentry);
23747 + if (unlikely(err && !a->exchange))
23749 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23751 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23755 + * is it possible?
23756 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23757 + * there may exist a problem somewhere else.
23760 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23763 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23764 + di_write_lock_parent(a->dst_parent);
23766 + /* which branch we process */
23767 + err = au_ren_wbr(a);
23768 + if (unlikely(err < 0))
23770 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23771 + a->h_path.mnt = au_br_mnt(a->br);
23773 + /* are they available to be renamed */
23774 + err = au_ren_may_dir(a);
23775 + if (unlikely(err))
23776 + goto out_children;
23778 + /* prepare the writable parent dir on the same branch */
23779 + if (a->dst_btop == a->btgt) {
23780 + au_fset_ren(a->auren_flags, WHDST);
23782 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23783 + if (unlikely(err))
23784 + goto out_children;
23788 + if (!a->exchange) {
23789 + if (a->src_dir != a->dst_dir) {
23791 + * this temporary unlock is safe,
23792 + * because both dir->i_mutex are locked.
23794 + di_write_unlock(a->dst_parent);
23795 + di_write_lock_parent(a->src_parent);
23796 + err = au_wr_dir_need_wh(a->src_dentry,
23797 + au_ftest_ren(a->auren_flags,
23800 + di_write_unlock(a->src_parent);
23801 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23803 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23805 + err = au_wr_dir_need_wh(a->src_dentry,
23806 + au_ftest_ren(a->auren_flags,
23810 + if (unlikely(err < 0))
23811 + goto out_children;
23813 + au_fset_ren(a->auren_flags, WHSRC);
23816 + if (a->src_btop != a->btgt) {
23817 + err = au_pin(&pin, a->src_dentry, a->btgt,
23818 + au_opt_udba(a->src_dentry->d_sb),
23819 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23821 + struct au_cp_generic cpg = {
23822 + .dentry = a->src_dentry,
23824 + .bsrc = a->src_btop,
23827 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23829 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23830 + err = au_sio_cpup_simple(&cpg);
23833 + if (unlikely(err))
23834 + goto out_children;
23835 + a->src_btop = a->btgt;
23836 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23837 + if (!a->exchange)
23838 + au_fset_ren(a->auren_flags, WHSRC);
23842 + if (a->exchange && a->dst_inode
23843 + && a->dst_btop != a->btgt) {
23844 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23845 + au_opt_udba(a->dst_dentry->d_sb),
23846 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23848 + struct au_cp_generic cpg = {
23849 + .dentry = a->dst_dentry,
23851 + .bsrc = a->dst_btop,
23854 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23856 + err = au_sio_cpup_simple(&cpg);
23859 + if (unlikely(err))
23860 + goto out_children;
23861 + a->dst_btop = a->btgt;
23862 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23865 + /* lock them all */
23866 + err = au_ren_lock(a);
23867 + if (unlikely(err))
23868 + /* leave the copied-up one */
23869 + goto out_children;
23871 + if (!a->exchange) {
23872 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23873 + err = au_may_ren(a);
23874 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23875 + err = -ENAMETOOLONG;
23876 + if (unlikely(err))
23880 + /* store timestamps to be revertible */
23883 + /* store dirren info */
23884 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23885 + err = au_dr_rename(a->src_dentry, a->btgt,
23886 + &a->dst_dentry->d_name, &rev);
23888 + if (unlikely(err))
23893 + err = do_rename(a);
23894 + if (unlikely(err))
23897 + if (au_ftest_ren(a->auren_flags, DIRREN))
23898 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23900 + /* update dir attributes */
23901 + au_ren_refresh_dir(a);
23903 + /* dput/iput all lower dentries */
23904 + au_ren_refresh(a);
23906 + goto out_hdir; /* success */
23909 + if (au_ftest_ren(a->auren_flags, DIRREN))
23910 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23912 + au_ren_rev_dt(err, a);
23914 + au_ren_unlock(a);
23916 + au_nhash_wh_free(&a->whlist);
23917 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23918 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23919 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23920 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23924 + if (d_unhashed(a->src_dentry))
23925 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23926 + if (d_unhashed(a->dst_dentry))
23927 + au_fset_ren(a->auren_flags, DROPPED_DST);
23928 + if (!a->exchange)
23929 + d_move(a->src_dentry, a->dst_dentry);
23931 + d_exchange(a->src_dentry, a->dst_dentry);
23932 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23933 + d_drop(a->dst_dentry);
23935 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23936 + d_drop(a->src_dentry);
23938 + au_update_dbtop(a->dst_dentry);
23939 + if (!a->dst_inode)
23940 + d_drop(a->dst_dentry);
23942 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23943 + di_write_unlock(a->dst_parent);
23945 + di_write_unlock2(a->src_parent, a->dst_parent);
23947 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23949 + iput(a->dst_inode);
23951 + au_whtmp_rmdir_free(a->thargs);
23957 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23958 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23959 +++ linux/fs/aufs/Kconfig 2018-06-04 09:08:09.181412645 +0200
23961 +# SPDX-License-Identifier: GPL-2.0
23963 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23965 + Aufs is a stackable unification filesystem such as Unionfs,
23966 + which unifies several directories and provides a merged single
23968 + In the early days, aufs was entirely re-designed and
23969 + re-implemented Unionfs Version 1.x series. Introducing many
23970 + original ideas, approaches and improvements, it becomes totally
23971 + different from Unionfs while keeping the basic features.
23975 + prompt "Maximum number of branches"
23976 + default AUFS_BRANCH_MAX_127
23978 + Specifies the maximum number of branches (or member directories)
23979 + in a single aufs. The larger value consumes more system
23980 + resources and has a minor impact to performance.
23981 +config AUFS_BRANCH_MAX_127
23984 + Specifies the maximum number of branches (or member directories)
23985 + in a single aufs. The larger value consumes more system
23986 + resources and has a minor impact to performance.
23987 +config AUFS_BRANCH_MAX_511
23990 + Specifies the maximum number of branches (or member directories)
23991 + in a single aufs. The larger value consumes more system
23992 + resources and has a minor impact to performance.
23993 +config AUFS_BRANCH_MAX_1023
23996 + Specifies the maximum number of branches (or member directories)
23997 + in a single aufs. The larger value consumes more system
23998 + resources and has a minor impact to performance.
23999 +config AUFS_BRANCH_MAX_32767
24002 + Specifies the maximum number of branches (or member directories)
24003 + in a single aufs. The larger value consumes more system
24004 + resources and has a minor impact to performance.
24007 +config AUFS_SBILIST
24009 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
24012 + Automatic configuration for internal use.
24013 + When aufs supports Magic SysRq or /proc, enabled automatically.
24015 +config AUFS_HNOTIFY
24016 + bool "Detect direct branch access (bypassing aufs)"
24018 + If you want to modify files on branches directly, eg. bypassing aufs,
24019 + and want aufs to detect the changes of them fully, then enable this
24020 + option and use 'udba=notify' mount option.
24021 + Currently there is only one available configuration, "fsnotify".
24022 + It will have a negative impact to the performance.
24023 + See detail in aufs.5.
24026 + prompt "method" if AUFS_HNOTIFY
24027 + default AUFS_HFSNOTIFY
24028 +config AUFS_HFSNOTIFY
24033 +config AUFS_EXPORT
24034 + bool "NFS-exportable aufs"
24035 + depends on EXPORTFS
24037 + If you want to export your mounted aufs via NFS, then enable this
24038 + option. There are several requirements for this configuration.
24039 + See detail in aufs.5.
24041 +config AUFS_INO_T_64
24043 + depends on AUFS_EXPORT
24044 + depends on 64BIT && !(ALPHA || S390)
24047 + Automatic configuration for internal use.
24048 + /* typedef unsigned long/int __kernel_ino_t */
24049 + /* alpha and s390x are int */
24052 + bool "support for XATTR/EA (including Security Labels)"
24054 + If your branch fs supports XATTR/EA and you want to make them
24055 + available in aufs too, then enable this opsion and specify the
24056 + branch attributes for EA.
24057 + See detail in aufs.5.
24060 + bool "File-based Hierarchical Storage Management"
24062 + Hierarchical Storage Management (or HSM) is a well-known feature
24063 + in the storage world. Aufs provides this feature as file-based.
24064 + with multiple branches.
24065 + These multiple branches are prioritized, ie. the topmost one
24066 + should be the fastest drive and be used heavily.
24069 + bool "Readdir in userspace"
24071 + Aufs has two methods to provide a merged view for a directory,
24072 + by a user-space library and by kernel-space natively. The latter
24073 + is always enabled but sometimes large and slow.
24074 + If you enable this option, install the library in aufs2-util
24075 + package, and set some environment variables for your readdir(3),
24076 + then the work will be handled in user-space which generally
24077 + shows better performance in most cases.
24078 + See detail in aufs.5.
24080 +config AUFS_DIRREN
24081 + bool "Workaround for rename(2)-ing a directory"
24083 + By default, aufs returns EXDEV error in renameing a dir who has
24084 + his child on the lower branch, since it is a bad idea to issue
24085 + rename(2) internally for every lower branch. But user may not
24086 + accept this behaviour. So here is a workaround to allow such
24087 + rename(2) and store some extra infromation on the writable
24088 + branch. Obviously this costs high (and I don't like it).
24089 + To use this feature, you need to enable this configuration AND
24090 + to specify the mount option `dirren.'
24091 + See details in aufs.5 and the design documents.
24094 + bool "Show whiteouts"
24096 + If you want to make the whiteouts in aufs visible, then enable
24097 + this option and specify 'shwh' mount option. Although it may
24098 + sounds like philosophy or something, but in technically it
24099 + simply shows the name of whiteout with keeping its behaviour.
24101 +config AUFS_BR_RAMFS
24102 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
24104 + If you want to use ramfs as an aufs branch fs, then enable this
24105 + option. Generally tmpfs is recommended.
24106 + Aufs prohibited them to be a branch fs by default, because
24107 + initramfs becomes unusable after switch_root or something
24108 + generally. If you sets initramfs as an aufs branch and boot your
24109 + system by switch_root, you will meet a problem easily since the
24110 + files in initramfs may be inaccessible.
24111 + Unless you are going to use ramfs as an aufs branch fs without
24112 + switch_root or something, leave it N.
24114 +config AUFS_BR_FUSE
24115 + bool "Fuse fs as an aufs branch"
24116 + depends on FUSE_FS
24119 + If you want to use fuse-based userspace filesystem as an aufs
24120 + branch fs, then enable this option.
24121 + It implements the internal poll(2) operation which is
24122 + implemented by fuse only (curretnly).
24127 + Automatic configuration for internal use.
24129 +config AUFS_BR_HFSPLUS
24130 + bool "Hfsplus as an aufs branch"
24131 + depends on HFSPLUS_FS
24134 + If you want to use hfsplus fs as an aufs branch fs, then enable
24135 + this option. This option introduces a small overhead at
24136 + copying-up a file on hfsplus.
24138 +config AUFS_BDEV_LOOP
24140 + depends on BLK_DEV_LOOP
24143 + Automatic configuration for internal use.
24144 + Convert =[ym] into =y.
24147 + bool "Debug aufs"
24149 + Enable this to compile aufs internal debug code.
24150 + It will have a negative impact to the performance.
24152 +config AUFS_MAGIC_SYSRQ
24154 + depends on AUFS_DEBUG && MAGIC_SYSRQ
24157 + Automatic configuration for internal use.
24158 + When aufs supports Magic SysRq, enabled automatically.
24160 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
24161 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
24162 +++ linux/fs/aufs/lcnt.h 2019-03-05 12:13:00.142557771 +0100
24164 +/* SPDX-License-Identifier: GPL-2.0 */
24166 + * Copyright (C) 2018-2019 Junjiro R. Okajima
24168 + * This program, aufs is free software; you can redistribute it and/or modify
24169 + * it under the terms of the GNU General Public License as published by
24170 + * the Free Software Foundation; either version 2 of the License, or
24171 + * (at your option) any later version.
24173 + * This program is distributed in the hope that it will be useful,
24174 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24175 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24176 + * GNU General Public License for more details.
24178 + * You should have received a copy of the GNU General Public License
24179 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24183 + * simple long counter wrapper
24186 +#ifndef __AUFS_LCNT_H__
24187 +#define __AUFS_LCNT_H__
24191 +#include "debug.h"
24193 +#define AuLCntATOMIC 1
24194 +#define AuLCntPCPUCNT 2
24196 + * why does percpu_refcount require extra synchronize_rcu()s in
24197 + * au_br_do_free()
24199 +#define AuLCntPCPUREF 3
24201 +/* #define AuLCntChosen AuLCntATOMIC */
24202 +#define AuLCntChosen AuLCntPCPUCNT
24203 +/* #define AuLCntChosen AuLCntPCPUREF */
24205 +#if AuLCntChosen == AuLCntATOMIC
24206 +#include <linux/atomic.h>
24208 +typedef atomic_long_t au_lcnt_t;
24210 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24212 + atomic_long_set(cnt, 0);
24216 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24221 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
24222 + int do_sync __maybe_unused)
24227 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24229 + atomic_long_inc(cnt);
24232 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24234 + atomic_long_dec(cnt);
24237 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24239 + return atomic_long_read(cnt);
24243 +#if AuLCntChosen == AuLCntPCPUCNT
24244 +#include <linux/percpu_counter.h>
24246 +typedef struct percpu_counter au_lcnt_t;
24248 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24250 + return percpu_counter_init(cnt, 0, GFP_NOFS);
24253 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24258 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
24260 + percpu_counter_destroy(cnt);
24263 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24265 + percpu_counter_inc(cnt);
24268 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24270 + percpu_counter_dec(cnt);
24273 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24277 + n = percpu_counter_sum(cnt);
24279 + if (LONG_MAX != LLONG_MAX
24281 + AuWarn1("%s\n", "wrap-around");
24287 +#if AuLCntChosen == AuLCntPCPUREF
24288 +#include <linux/percpu-refcount.h>
24290 +typedef struct percpu_ref au_lcnt_t;
24292 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24295 + release = percpu_ref_exit;
24296 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24299 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24301 + synchronize_rcu();
24304 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24306 + percpu_ref_kill(cnt);
24308 + au_lcnt_wait_for_fin(cnt);
24311 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24313 + percpu_ref_get(cnt);
24316 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24318 + percpu_ref_put(cnt);
24322 + * avoid calling this func as possible.
24324 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24328 + percpu_ref_switch_to_atomic_sync(cnt);
24329 + l = atomic_long_read(&cnt->count);
24331 + percpu_ref_switch_to_percpu(cnt);
24333 + /* percpu_ref is initialized by 1 instead of 0 */
24338 +#ifdef CONFIG_AUFS_DEBUG
24339 +#define AuLCntZero(val) do { \
24342 + AuDbg("%s = %ld\n", #val, l); \
24345 +#define AuLCntZero(val) do {} while (0)
24348 +#endif /* __KERNEL__ */
24349 +#endif /* __AUFS_LCNT_H__ */
24350 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24351 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24352 +++ linux/fs/aufs/loop.c 2019-03-05 12:13:00.142557771 +0100
24354 +// SPDX-License-Identifier: GPL-2.0
24356 + * Copyright (C) 2005-2019 Junjiro R. Okajima
24358 + * This program, aufs is free software; you can redistribute it and/or modify
24359 + * it under the terms of the GNU General Public License as published by
24360 + * the Free Software Foundation; either version 2 of the License, or
24361 + * (at your option) any later version.
24363 + * This program is distributed in the hope that it will be useful,
24364 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24365 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24366 + * GNU General Public License for more details.
24368 + * You should have received a copy of the GNU General Public License
24369 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24373 + * support for loopback block device as a branch
24378 +/* added into drivers/block/loop.c */
24379 +static struct file *(*backing_file_func)(struct super_block *sb);
24382 + * test if two lower dentries have overlapping branches.
24384 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24386 + struct super_block *h_sb;
24387 + struct file *backing_file;
24389 + if (unlikely(!backing_file_func)) {
24390 + /* don't load "loop" module here */
24391 + backing_file_func = symbol_get(loop_backing_file);
24392 + if (unlikely(!backing_file_func))
24393 + /* "loop" module is not loaded */
24397 + h_sb = h_adding->d_sb;
24398 + backing_file = backing_file_func(h_sb);
24399 + if (!backing_file)
24402 + h_adding = backing_file->f_path.dentry;
24404 + * h_adding can be local NFS.
24405 + * in this case aufs cannot detect the loop.
24407 + if (unlikely(h_adding->d_sb == sb))
24409 + return !!au_test_subdir(h_adding, sb->s_root);
24412 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24413 +int au_test_loopback_kthread(void)
24416 + struct task_struct *tsk = current;
24417 + char c, comm[sizeof(tsk->comm)];
24420 + if (tsk->flags & PF_KTHREAD) {
24421 + get_task_comm(comm, tsk);
24423 + ret = ('0' <= c && c <= '9'
24424 + && !strncmp(comm, "loop", 4));
24430 +/* ---------------------------------------------------------------------- */
24432 +#define au_warn_loopback_step 16
24433 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24434 +static unsigned long *au_warn_loopback_array;
24436 +void au_warn_loopback(struct super_block *h_sb)
24438 + int i, new_nelem;
24439 + unsigned long *a, magic;
24440 + static DEFINE_SPINLOCK(spin);
24442 + magic = h_sb->s_magic;
24443 + spin_lock(&spin);
24444 + a = au_warn_loopback_array;
24445 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24446 + if (a[i] == magic) {
24447 + spin_unlock(&spin);
24451 + /* h_sb is new to us, print it */
24452 + if (i < au_warn_loopback_nelem) {
24457 + /* expand the array */
24458 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24459 + a = au_kzrealloc(au_warn_loopback_array,
24460 + au_warn_loopback_nelem * sizeof(unsigned long),
24461 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24462 + /*may_shrink*/0);
24464 + au_warn_loopback_nelem = new_nelem;
24465 + au_warn_loopback_array = a;
24470 + spin_unlock(&spin);
24471 + AuWarn1("realloc failed, ignored\n");
24475 + spin_unlock(&spin);
24476 + pr_warn("you may want to try another patch for loopback file "
24477 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24480 +int au_loopback_init(void)
24483 + struct super_block *sb __maybe_unused;
24485 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
24488 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24489 + sizeof(unsigned long), GFP_NOFS);
24490 + if (unlikely(!au_warn_loopback_array))
24496 +void au_loopback_fin(void)
24498 + if (backing_file_func)
24499 + symbol_put(loop_backing_file);
24500 + au_kfree_try_rcu(au_warn_loopback_array);
24502 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24503 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24504 +++ linux/fs/aufs/loop.h 2019-05-06 09:03:04.820143837 +0200
24506 +/* SPDX-License-Identifier: GPL-2.0 */
24508 + * Copyright (C) 2005-2019 Junjiro R. Okajima
24510 + * This program, aufs is free software; you can redistribute it and/or modify
24511 + * it under the terms of the GNU General Public License as published by
24512 + * the Free Software Foundation; either version 2 of the License, or
24513 + * (at your option) any later version.
24515 + * This program is distributed in the hope that it will be useful,
24516 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24517 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24518 + * GNU General Public License for more details.
24520 + * You should have received a copy of the GNU General Public License
24521 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24525 + * support for loopback mount as a branch
24528 +#ifndef __AUFS_LOOP_H__
24529 +#define __AUFS_LOOP_H__
24534 +struct super_block;
24536 +#ifdef CONFIG_AUFS_BDEV_LOOP
24537 +/* drivers/block/loop.c */
24538 +struct file *loop_backing_file(struct super_block *sb);
24541 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24542 +int au_test_loopback_kthread(void);
24543 +void au_warn_loopback(struct super_block *h_sb);
24545 +int au_loopback_init(void);
24546 +void au_loopback_fin(void);
24548 +AuStub(struct file *, loop_backing_file, return NULL)
24550 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24551 + struct dentry *h_adding)
24552 +AuStubInt0(au_test_loopback_kthread, void)
24553 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24555 +AuStubInt0(au_loopback_init, void)
24556 +AuStubVoid(au_loopback_fin, void)
24557 +#endif /* BLK_DEV_LOOP */
24559 +#endif /* __KERNEL__ */
24560 +#endif /* __AUFS_LOOP_H__ */
24561 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24562 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24563 +++ linux/fs/aufs/magic.mk 2018-06-04 09:08:09.188079511 +0200
24565 +# SPDX-License-Identifier: GPL-2.0
24567 +# defined in ${srctree}/fs/fuse/inode.c
24569 +ifdef CONFIG_FUSE_FS
24570 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24573 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24575 +ifdef CONFIG_XFS_FS
24576 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24579 +# defined in ${srctree}/fs/configfs/mount.c
24581 +ifdef CONFIG_CONFIGFS_FS
24582 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24585 +# defined in ${srctree}/fs/ubifs/ubifs.h
24587 +ifdef CONFIG_UBIFS_FS
24588 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24591 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24593 +ifdef CONFIG_HFSPLUS_FS
24594 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24596 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24597 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24598 +++ linux/fs/aufs/Makefile 2018-06-04 09:08:09.181412645 +0200
24600 +# SPDX-License-Identifier: GPL-2.0
24602 +include ${src}/magic.mk
24603 +ifeq (${CONFIG_AUFS_FS},m)
24604 +include ${src}/conf.mk
24606 +-include ${src}/priv_def.mk
24608 +# cf. include/linux/kernel.h
24610 +ccflags-y += -DDEBUG
24611 +# sparse requires the full pathname
24613 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24615 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24618 +obj-$(CONFIG_AUFS_FS) += aufs.o
24619 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24620 + wkq.o vfsub.o dcsub.o \
24621 + cpup.o whout.o wbr_policy.o \
24622 + dinfo.o dentry.o \
24624 + finfo.o file.o f_op.o \
24626 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24630 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24631 +aufs-$(CONFIG_SYSFS) += sysfs.o
24632 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24633 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24634 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24635 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24636 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24637 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24638 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24639 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24640 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24641 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24642 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24643 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24644 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24645 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24646 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24647 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24648 +++ linux/fs/aufs/module.c 2019-03-05 12:13:00.142557771 +0100
24650 +// SPDX-License-Identifier: GPL-2.0
24652 + * Copyright (C) 2005-2019 Junjiro R. Okajima
24654 + * This program, aufs is free software; you can redistribute it and/or modify
24655 + * it under the terms of the GNU General Public License as published by
24656 + * the Free Software Foundation; either version 2 of the License, or
24657 + * (at your option) any later version.
24659 + * This program is distributed in the hope that it will be useful,
24660 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24661 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24662 + * GNU General Public License for more details.
24664 + * You should have received a copy of the GNU General Public License
24665 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24669 + * module global variables and operations
24672 +#include <linux/module.h>
24673 +#include <linux/seq_file.h>
24676 +/* shrinkable realloc */
24677 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24685 +#if 0 /* unused */
24692 + AuDebugOn(!new_sz);
24695 + diff = au_kmidx_sub(sz, new_sz);
24701 + /* expand or SLOB */
24702 + p = krealloc(p, new_sz, gfp);
24703 + else if (new_sz < sz && may_shrink) {
24707 + q = kmalloc(new_sz, gfp);
24710 + memcpy(q, p, new_sz);
24711 + au_kfree_try_rcu(p);
24722 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24725 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24726 + if (p && new_sz > nused)
24727 + memset(p + nused, 0, new_sz - nused);
24731 +/* ---------------------------------------------------------------------- */
24735 +struct kmem_cache *au_cache[AuCache_Last];
24737 +static void au_cache_fin(void)
24742 + * Make sure all delayed rcu free inodes are flushed before we
24747 + /* excluding AuCache_HNOTIFY */
24748 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24749 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24750 + kmem_cache_destroy(au_cache[i]);
24751 + au_cache[i] = NULL;
24755 +static int __init au_cache_init(void)
24757 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24758 + if (au_cache[AuCache_DINFO])
24759 + /* SLAB_DESTROY_BY_RCU */
24760 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24761 + au_icntnr_init_once);
24762 + if (au_cache[AuCache_ICNTNR])
24763 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24764 + au_fi_init_once);
24765 + if (au_cache[AuCache_FINFO])
24766 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24767 + if (au_cache[AuCache_VDIR])
24768 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24769 + if (au_cache[AuCache_DEHSTR])
24776 +/* ---------------------------------------------------------------------- */
24778 +int au_dir_roflags;
24780 +#ifdef CONFIG_AUFS_SBILIST
24782 + * iterate_supers_type() doesn't protect us from
24783 + * remounting (branch management)
24785 +struct hlist_bl_head au_sbilist;
24789 + * functions for module interface.
24791 +MODULE_LICENSE("GPL");
24792 +/* MODULE_LICENSE("GPL v2"); */
24793 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24794 +MODULE_DESCRIPTION(AUFS_NAME
24795 + " -- Advanced multi layered unification filesystem");
24796 +MODULE_VERSION(AUFS_VERSION);
24797 +MODULE_ALIAS_FS(AUFS_NAME);
24799 +/* this module parameter has no meaning when SYSFS is disabled */
24800 +int sysaufs_brs = 1;
24801 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24802 +module_param_named(brs, sysaufs_brs, int, 0444);
24804 +/* this module parameter has no meaning when USER_NS is disabled */
24806 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24807 +module_param_named(allow_userns, au_userns, bool, 0444);
24809 +/* ---------------------------------------------------------------------- */
24811 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24813 +int au_seq_path(struct seq_file *seq, struct path *path)
24817 + err = seq_path(seq, path, au_esc_chars);
24826 +/* ---------------------------------------------------------------------- */
24828 +static int __init aufs_init(void)
24833 + p = au_esc_chars;
24834 + for (i = 1; i <= ' '; i++)
24840 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24842 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24843 + for (i = 0; i < AuIop_Last; i++)
24844 + aufs_iop_nogetattr[i].getattr = NULL;
24846 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24848 + au_sbilist_init();
24849 + sysaufs_brs_init();
24852 + err = sysaufs_init();
24853 + if (unlikely(err))
24855 + err = dbgaufs_init();
24856 + if (unlikely(err))
24857 + goto out_sysaufs;
24858 + err = au_procfs_init();
24859 + if (unlikely(err))
24860 + goto out_dbgaufs;
24861 + err = au_wkq_init();
24862 + if (unlikely(err))
24864 + err = au_loopback_init();
24865 + if (unlikely(err))
24867 + err = au_hnotify_init();
24868 + if (unlikely(err))
24869 + goto out_loopback;
24870 + err = au_sysrq_init();
24871 + if (unlikely(err))
24873 + err = au_cache_init();
24874 + if (unlikely(err))
24877 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24878 + err = register_filesystem(&aufs_fs_type);
24879 + if (unlikely(err))
24882 + /* since we define pr_fmt, call printk directly */
24883 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24884 + goto out; /* success */
24891 + au_hnotify_fin();
24893 + au_loopback_fin();
24907 +static void __exit aufs_exit(void)
24909 + unregister_filesystem(&aufs_fs_type);
24912 + au_hnotify_fin();
24913 + au_loopback_fin();
24921 +module_init(aufs_init);
24922 +module_exit(aufs_exit);
24923 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24924 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24925 +++ linux/fs/aufs/module.h 2019-03-05 12:13:00.142557771 +0100
24927 +/* SPDX-License-Identifier: GPL-2.0 */
24929 + * Copyright (C) 2005-2019 Junjiro R. Okajima
24931 + * This program, aufs is free software; you can redistribute it and/or modify
24932 + * it under the terms of the GNU General Public License as published by
24933 + * the Free Software Foundation; either version 2 of the License, or
24934 + * (at your option) any later version.
24936 + * This program is distributed in the hope that it will be useful,
24937 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24938 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24939 + * GNU General Public License for more details.
24941 + * You should have received a copy of the GNU General Public License
24942 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24946 + * module initialization and module-global
24949 +#ifndef __AUFS_MODULE_H__
24950 +#define __AUFS_MODULE_H__
24954 +#include <linux/slab.h>
24955 +#include "debug.h"
24956 +#include "dentry.h"
24959 +#include "inode.h"
24964 +/* module parameters */
24965 +extern int sysaufs_brs;
24966 +extern bool au_userns;
24968 +/* ---------------------------------------------------------------------- */
24970 +extern int au_dir_roflags;
24972 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24973 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24977 + * Comparing the size of the object with sizeof(struct rcu_head)
24978 + * case 1: object is always larger
24979 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24980 + * case 2: object is always smaller
24981 + * --> au_kfree_small()
24982 + * case 3: object can be any size
24983 + * --> au_kfree_try_rcu()
24986 +static inline void au_kfree_do_rcu(const void *p)
24989 + struct rcu_head rcu;
24990 + } *a = (void *)p;
24992 + kfree_rcu(a, rcu);
24995 +#define au_kfree_rcu(_p) do { \
24996 + typeof(_p) p = (_p); \
24997 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24999 + au_kfree_do_rcu(p); \
25002 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
25003 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
25005 +static inline void au_kfree_try_rcu(const void *p)
25009 + if (au_kfree_sz_test(p))
25010 + au_kfree_do_rcu(p);
25015 +static inline void au_kfree_small(const void *p)
25019 + AuDebugOn(au_kfree_sz_test(p));
25023 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
25025 +#ifndef CONFIG_SLOB
25026 + return kmalloc_index(sz) - kmalloc_index(new_sz);
25028 + return -1; /* SLOB is untested */
25032 +int au_seq_path(struct seq_file *seq, struct path *path);
25034 +#ifdef CONFIG_PROC_FS
25036 +int __init au_procfs_init(void);
25037 +void au_procfs_fin(void);
25039 +AuStubInt0(au_procfs_init, void);
25040 +AuStubVoid(au_procfs_fin, void);
25043 +/* ---------------------------------------------------------------------- */
25052 + AuCache_HNOTIFY, /* must be last */
25056 +extern struct kmem_cache *au_cache[AuCache_Last];
25058 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
25059 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
25060 +#define AuCacheCtor(type, ctor) \
25061 + kmem_cache_create(#type, sizeof(struct type), \
25062 + __alignof__(struct type), AuCacheFlags, ctor)
25064 +#define AuCacheFuncs(name, index) \
25065 + static inline struct au_##name *au_cache_alloc_##name(void) \
25066 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
25067 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
25068 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
25070 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
25071 + { void *p = rcu; \
25072 + p -= offsetof(struct au_##name, rcu); \
25073 + kmem_cache_free(au_cache[AuCache_##index], p); } \
25074 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
25075 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
25076 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
25078 + static inline void au_cache_free_##name(struct au_##name *p) \
25079 + { /* au_cache_free_##name##_norcu(p); */ \
25080 + au_cache_free_##name##_rcu(p); }
25082 +AuCacheFuncs(dinfo, DINFO);
25083 +AuCacheFuncs(icntnr, ICNTNR);
25084 +AuCacheFuncs(finfo, FINFO);
25085 +AuCacheFuncs(vdir, VDIR);
25086 +AuCacheFuncs(vdir_dehstr, DEHSTR);
25087 +#ifdef CONFIG_AUFS_HNOTIFY
25088 +AuCacheFuncs(hnotify, HNOTIFY);
25091 +#endif /* __KERNEL__ */
25092 +#endif /* __AUFS_MODULE_H__ */
25093 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
25094 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
25095 +++ linux/fs/aufs/mvdown.c 2019-03-05 12:13:00.142557771 +0100
25097 +// SPDX-License-Identifier: GPL-2.0
25099 + * Copyright (C) 2011-2019 Junjiro R. Okajima
25101 + * This program, aufs is free software; you can redistribute it and/or modify
25102 + * it under the terms of the GNU General Public License as published by
25103 + * the Free Software Foundation; either version 2 of the License, or
25104 + * (at your option) any later version.
25106 + * This program is distributed in the hope that it will be useful,
25107 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25108 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25109 + * GNU General Public License for more details.
25111 + * You should have received a copy of the GNU General Public License
25112 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25116 + * move-down, opposite of copy-up
25121 +struct au_mvd_args {
25123 + struct super_block *h_sb;
25124 + struct dentry *h_parent;
25125 + struct au_hinode *hdir;
25126 + struct inode *h_dir, *h_inode;
25127 + struct au_pin pin;
25128 + } info[AUFS_MVDOWN_NARRAY];
25130 + struct aufs_mvdown mvdown;
25131 + struct dentry *dentry, *parent;
25132 + struct inode *inode, *dir;
25133 + struct super_block *sb;
25134 + aufs_bindex_t bopq, bwh, bfound;
25135 + unsigned char rename_lock;
25138 +#define mvd_errno mvdown.au_errno
25139 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
25140 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
25141 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
25142 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
25144 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
25145 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
25146 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
25147 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
25148 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
25149 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
25151 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
25152 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
25153 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
25154 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
25155 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
25156 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
25158 +#define AU_MVD_PR(flag, ...) do { \
25160 + pr_err(__VA_ARGS__); \
25163 +static int find_lower_writable(struct au_mvd_args *a)
25165 + struct super_block *sb;
25166 + aufs_bindex_t bindex, bbot;
25167 + struct au_branch *br;
25170 + bindex = a->mvd_bsrc;
25171 + bbot = au_sbbot(sb);
25172 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
25173 + for (bindex++; bindex <= bbot; bindex++) {
25174 + br = au_sbr(sb, bindex);
25175 + if (au_br_fhsm(br->br_perm)
25176 + && !sb_rdonly(au_br_sb(br)))
25179 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
25180 + for (bindex++; bindex <= bbot; bindex++) {
25181 + br = au_sbr(sb, bindex);
25182 + if (!au_br_rdonly(br))
25186 + for (bindex++; bindex <= bbot; bindex++) {
25187 + br = au_sbr(sb, bindex);
25188 + if (!sb_rdonly(au_br_sb(br))) {
25189 + if (au_br_rdonly(br))
25191 + |= AUFS_MVDOWN_ROLOWER_R;
25199 +/* make the parent dir on bdst */
25200 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
25205 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
25206 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
25207 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
25208 + a->mvd_h_dst_parent = NULL;
25209 + if (au_dbbot(a->parent) >= a->mvd_bdst)
25210 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25211 + if (!a->mvd_h_dst_parent) {
25212 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
25213 + if (unlikely(err)) {
25214 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
25217 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25225 +/* lock them all */
25226 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
25229 + struct dentry *h_trap;
25231 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
25232 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
25233 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
25234 + au_opt_udba(a->sb),
25235 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25237 + if (unlikely(err)) {
25238 + AU_MVD_PR(dmsg, "pin_dst failed\n");
25242 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
25243 + a->rename_lock = 0;
25244 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25245 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
25246 + au_opt_udba(a->sb),
25247 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25248 + err = au_do_pin(&a->mvd_pin_src);
25250 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25251 + if (unlikely(err)) {
25252 + AU_MVD_PR(dmsg, "pin_src failed\n");
25255 + goto out; /* success */
25258 + a->rename_lock = 1;
25259 + au_pin_hdir_unlock(&a->mvd_pin_dst);
25260 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25261 + au_opt_udba(a->sb),
25262 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25264 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25265 + if (unlikely(err)) {
25266 + AU_MVD_PR(dmsg, "pin_src failed\n");
25267 + au_pin_hdir_lock(&a->mvd_pin_dst);
25270 + au_pin_hdir_unlock(&a->mvd_pin_src);
25271 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25272 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25274 + err = (h_trap != a->mvd_h_src_parent);
25276 + err = (h_trap != a->mvd_h_dst_parent);
25278 + BUG_ON(err); /* it should never happen */
25279 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25282 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25283 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25284 + au_pin_hdir_lock(&a->mvd_pin_src);
25285 + au_unpin(&a->mvd_pin_src);
25286 + au_pin_hdir_lock(&a->mvd_pin_dst);
25289 + goto out; /* success */
25292 + au_unpin(&a->mvd_pin_dst);
25298 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25300 + if (!a->rename_lock)
25301 + au_unpin(&a->mvd_pin_src);
25303 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25304 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25305 + au_pin_hdir_lock(&a->mvd_pin_src);
25306 + au_unpin(&a->mvd_pin_src);
25307 + au_pin_hdir_lock(&a->mvd_pin_dst);
25309 + au_unpin(&a->mvd_pin_dst);
25312 +/* copy-down the file */
25313 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25316 + struct au_cp_generic cpg = {
25317 + .dentry = a->dentry,
25318 + .bdst = a->mvd_bdst,
25319 + .bsrc = a->mvd_bsrc,
25321 + .pin = &a->mvd_pin_dst,
25322 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25325 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25326 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25327 + au_fset_cpup(cpg.flags, OVERWRITE);
25328 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25329 + au_fset_cpup(cpg.flags, RWDST);
25330 + err = au_sio_cpdown_simple(&cpg);
25331 + if (unlikely(err))
25332 + AU_MVD_PR(dmsg, "cpdown failed\n");
25339 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25342 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25345 + struct path h_path;
25346 + struct au_branch *br;
25347 + struct inode *delegated;
25349 + br = au_sbr(a->sb, a->mvd_bdst);
25350 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25351 + err = PTR_ERR(h_path.dentry);
25352 + if (IS_ERR(h_path.dentry)) {
25353 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25358 + if (d_is_positive(h_path.dentry)) {
25359 + h_path.mnt = au_br_mnt(br);
25360 + delegated = NULL;
25361 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25362 + &delegated, /*force*/0);
25363 + if (unlikely(err == -EWOULDBLOCK)) {
25364 + pr_warn("cannot retry for NFSv4 delegation"
25365 + " for an internal unlink\n");
25368 + if (unlikely(err))
25369 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25371 + dput(h_path.dentry);
25379 + * unlink the topmost h_dentry
25381 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25384 + struct path h_path;
25385 + struct inode *delegated;
25387 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25388 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25389 + delegated = NULL;
25390 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25391 + if (unlikely(err == -EWOULDBLOCK)) {
25392 + pr_warn("cannot retry for NFSv4 delegation"
25393 + " for an internal unlink\n");
25396 + if (unlikely(err))
25397 + AU_MVD_PR(dmsg, "unlink failed\n");
25403 +/* Since mvdown succeeded, we ignore an error of this function */
25404 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25407 + struct au_branch *br;
25409 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25410 + br = au_sbr(a->sb, a->mvd_bsrc);
25411 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25413 + br = au_sbr(a->sb, a->mvd_bdst);
25414 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25415 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25418 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25420 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25424 + * copy-down the file and unlink the bsrc file.
25425 + * - unlink the bdst whout if exist
25426 + * - copy-down the file (with whtmp name and rename)
25427 + * - unlink the bsrc file
25429 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25433 + err = au_do_mkdir(dmsg, a);
25435 + err = au_do_lock(dmsg, a);
25436 + if (unlikely(err))
25440 + * do not revert the activities we made on bdst since they should be
25441 + * harmless in aufs.
25444 + err = au_do_cpdown(dmsg, a);
25446 + err = au_do_unlink_wh(dmsg, a);
25447 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25448 + err = au_do_unlink(dmsg, a);
25449 + if (unlikely(err))
25452 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25453 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25454 + if (find_lower_writable(a) < 0)
25455 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25457 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25458 + au_do_stfs(dmsg, a);
25460 + /* maintain internal array */
25461 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25462 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25463 + au_set_dbtop(a->dentry, a->mvd_bdst);
25464 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25465 + au_set_ibtop(a->inode, a->mvd_bdst);
25467 + /* hide the lower */
25468 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25469 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25470 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25471 + au_set_ibbot(a->inode, a->mvd_bsrc);
25473 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25474 + au_set_dbbot(a->dentry, a->mvd_bdst);
25475 + if (au_ibbot(a->inode) < a->mvd_bdst)
25476 + au_set_ibbot(a->inode, a->mvd_bdst);
25479 + au_do_unlock(dmsg, a);
25485 +/* ---------------------------------------------------------------------- */
25487 +/* make sure the file is idle */
25488 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25490 + int err, plinked;
25493 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25494 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25495 + && au_dcount(a->dentry) == 1
25496 + && atomic_read(&a->inode->i_count) == 1
25497 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25498 + && (!plinked || !au_plink_test(a->inode))
25499 + && a->inode->i_nlink == 1)
25504 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25505 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25506 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25507 + a->mvd_h_src_inode->i_nlink,
25508 + plinked, plinked ? au_plink_test(a->inode) : 0);
25515 +/* make sure the parent dir is fine */
25516 +static int au_mvd_args_parent(const unsigned char dmsg,
25517 + struct au_mvd_args *a)
25520 + aufs_bindex_t bindex;
25523 + if (unlikely(au_alive_dir(a->parent))) {
25525 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25529 + a->bopq = au_dbdiropq(a->parent);
25530 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25531 + AuDbg("b%d\n", bindex);
25532 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25533 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25535 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25536 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25537 + a->bopq, a->mvd_bdst);
25545 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25546 + struct au_mvd_args *a)
25549 + struct au_dinfo *dinfo, *tmp;
25551 + /* lookup the next lower positive entry */
25553 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25554 + if (unlikely(!tmp))
25559 + dinfo = au_di(a->dentry);
25560 + au_di_cp(tmp, dinfo);
25561 + au_di_swap(tmp, dinfo);
25563 + /* returns the number of positive dentries */
25564 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25565 + /* AuLkup_IGNORE_PERM */ 0);
25567 + a->bwh = au_dbwh(a->dentry);
25568 + else if (err > 0)
25569 + a->bfound = au_dbtop(a->dentry);
25571 + au_di_swap(tmp, dinfo);
25572 + au_rw_write_unlock(&tmp->di_rwsem);
25574 + if (unlikely(err < 0))
25575 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25578 + * here, we have these cases.
25580 + * no positive dentry under bsrc. there are more sub-cases.
25582 + * there no whiteout, we can safely move-down.
25585 + * bsrc < bwh && bwh < bdst
25586 + * there is a whiteout on RO branch. cannot proceed.
25588 + * there is a whiteout on the RW target branch. it should
25591 + * there is a whiteout somewhere unrelated branch.
25592 + * -1 < bfound && bfound <= bsrc
25595 + * found, but it is on RO branch between bsrc and bdst. cannot
25598 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25601 + * found, after we create the file on bdst, it will be hidden.
25604 + AuDebugOn(a->bfound == -1
25606 + && a->bwh <= a->mvd_bsrc);
25607 + AuDebugOn(-1 < a->bfound
25608 + && a->bfound <= a->mvd_bsrc);
25611 + if (a->bfound == -1
25612 + && a->mvd_bsrc < a->bwh
25614 + && a->bwh < a->mvd_bdst) {
25615 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25616 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25617 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25619 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25620 + a->mvd_errno = EAU_MVDOWN_UPPER;
25621 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25622 + a->mvd_bdst, a->bfound);
25626 + err = 0; /* success */
25633 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25638 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25639 + && a->bfound == a->mvd_bdst)
25645 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25648 + struct au_branch *br;
25651 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25655 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25656 + a->mvd_bsrc = au_ibtop(a->inode);
25658 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25659 + if (unlikely(a->mvd_bsrc < 0
25660 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25661 + || au_dbbot(a->dentry) < a->mvd_bsrc
25662 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25663 + || (a->mvd_bsrc < au_ibtop(a->inode)
25664 + || au_ibbot(a->inode) < a->mvd_bsrc
25665 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25666 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25667 + AU_MVD_PR(dmsg, "no upper\n");
25671 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25672 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25673 + AU_MVD_PR(dmsg, "on the bottom\n");
25676 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25677 + br = au_sbr(a->sb, a->mvd_bsrc);
25678 + err = au_br_rdonly(br);
25679 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25680 + if (unlikely(err))
25682 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25683 + || IS_APPEND(a->mvd_h_src_inode))) {
25685 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25691 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25692 + a->mvd_bdst = find_lower_writable(a);
25693 + if (unlikely(a->mvd_bdst < 0)) {
25694 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25695 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25699 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25700 + if (unlikely(a->mvd_bdst < 0
25701 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25702 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25703 + AU_MVD_PR(dmsg, "no lower brid\n");
25708 + err = au_mvd_args_busy(dmsg, a);
25710 + err = au_mvd_args_parent(dmsg, a);
25712 + err = au_mvd_args_intermediate(dmsg, a);
25714 + err = au_mvd_args_exist(dmsg, a);
25716 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25723 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25726 + unsigned char dmsg;
25727 + struct au_mvd_args *args;
25728 + struct inode *inode;
25730 + inode = d_inode(dentry);
25732 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25736 + args = kmalloc(sizeof(*args), GFP_NOFS);
25737 + if (unlikely(!args))
25740 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25742 + /* VERIFY_WRITE */
25743 + err = !access_ok(uarg, sizeof(*uarg));
25744 + if (unlikely(err)) {
25749 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25750 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25751 + args->mvdown.au_errno = 0;
25752 + args->dentry = dentry;
25753 + args->inode = inode;
25754 + args->sb = dentry->d_sb;
25757 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25758 + args->parent = dget_parent(dentry);
25759 + args->dir = d_inode(args->parent);
25760 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25761 + dput(args->parent);
25762 + if (unlikely(args->parent != dentry->d_parent)) {
25763 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25767 + inode_lock_nested(inode, I_MUTEX_CHILD);
25768 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25769 + if (unlikely(err))
25772 + di_write_lock_parent(args->parent);
25773 + err = au_mvd_args(dmsg, args);
25774 + if (unlikely(err))
25777 + err = au_do_mvdown(dmsg, args);
25778 + if (unlikely(err))
25781 + au_cpup_attr_timesizes(args->dir);
25782 + au_cpup_attr_timesizes(inode);
25783 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25784 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25785 + /* au_digen_dec(dentry); */
25788 + di_write_unlock(args->parent);
25789 + aufs_read_unlock(dentry, AuLock_DW);
25791 + inode_unlock(inode);
25793 + inode_unlock(args->dir);
25795 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25798 + au_kfree_rcu(args);
25803 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25804 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25805 +++ linux/fs/aufs/opts.c 2019-03-05 12:13:00.142557771 +0100
25807 +// SPDX-License-Identifier: GPL-2.0
25809 + * Copyright (C) 2005-2019 Junjiro R. Okajima
25811 + * This program, aufs is free software; you can redistribute it and/or modify
25812 + * it under the terms of the GNU General Public License as published by
25813 + * the Free Software Foundation; either version 2 of the License, or
25814 + * (at your option) any later version.
25816 + * This program is distributed in the hope that it will be useful,
25817 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25818 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25819 + * GNU General Public License for more details.
25821 + * You should have received a copy of the GNU General Public License
25822 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25826 + * mount options/flags
25829 +#include <linux/namei.h>
25830 +#include <linux/types.h> /* a distribution requires */
25831 +#include <linux/parser.h>
25834 +/* ---------------------------------------------------------------------- */
25838 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25839 + Opt_idel, Opt_imod,
25840 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25841 + Opt_rdblk_def, Opt_rdhash_def,
25842 + Opt_xino, Opt_noxino,
25843 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25844 + Opt_trunc_xino_path, Opt_itrunc_xino,
25845 + Opt_trunc_xib, Opt_notrunc_xib,
25846 + Opt_shwh, Opt_noshwh,
25847 + Opt_plink, Opt_noplink, Opt_list_plink,
25849 + Opt_dio, Opt_nodio,
25850 + Opt_diropq_a, Opt_diropq_w,
25851 + Opt_warn_perm, Opt_nowarn_perm,
25852 + Opt_wbr_copyup, Opt_wbr_create,
25854 + Opt_verbose, Opt_noverbose,
25855 + Opt_sum, Opt_nosum, Opt_wsum,
25856 + Opt_dirperm1, Opt_nodirperm1,
25857 + Opt_dirren, Opt_nodirren,
25858 + Opt_acl, Opt_noacl,
25859 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25862 +static match_table_t options = {
25863 + {Opt_br, "br=%s"},
25864 + {Opt_br, "br:%s"},
25866 + {Opt_add, "add=%d:%s"},
25867 + {Opt_add, "add:%d:%s"},
25868 + {Opt_add, "ins=%d:%s"},
25869 + {Opt_add, "ins:%d:%s"},
25870 + {Opt_append, "append=%s"},
25871 + {Opt_append, "append:%s"},
25872 + {Opt_prepend, "prepend=%s"},
25873 + {Opt_prepend, "prepend:%s"},
25875 + {Opt_del, "del=%s"},
25876 + {Opt_del, "del:%s"},
25877 + /* {Opt_idel, "idel:%d"}, */
25878 + {Opt_mod, "mod=%s"},
25879 + {Opt_mod, "mod:%s"},
25880 + /* {Opt_imod, "imod:%d:%s"}, */
25882 + {Opt_dirwh, "dirwh=%d"},
25884 + {Opt_xino, "xino=%s"},
25885 + {Opt_noxino, "noxino"},
25886 + {Opt_trunc_xino, "trunc_xino"},
25887 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25888 + {Opt_notrunc_xino, "notrunc_xino"},
25889 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25890 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25891 + /* {Opt_zxino, "zxino=%s"}, */
25892 + {Opt_trunc_xib, "trunc_xib"},
25893 + {Opt_notrunc_xib, "notrunc_xib"},
25895 +#ifdef CONFIG_PROC_FS
25896 + {Opt_plink, "plink"},
25898 + {Opt_ignore_silent, "plink"},
25901 + {Opt_noplink, "noplink"},
25903 +#ifdef CONFIG_AUFS_DEBUG
25904 + {Opt_list_plink, "list_plink"},
25907 + {Opt_udba, "udba=%s"},
25909 + {Opt_dio, "dio"},
25910 + {Opt_nodio, "nodio"},
25912 +#ifdef CONFIG_AUFS_DIRREN
25913 + {Opt_dirren, "dirren"},
25914 + {Opt_nodirren, "nodirren"},
25916 + {Opt_ignore, "dirren"},
25917 + {Opt_ignore_silent, "nodirren"},
25920 +#ifdef CONFIG_AUFS_FHSM
25921 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25923 + {Opt_ignore, "fhsm_sec=%d"},
25926 + {Opt_diropq_a, "diropq=always"},
25927 + {Opt_diropq_a, "diropq=a"},
25928 + {Opt_diropq_w, "diropq=whiteouted"},
25929 + {Opt_diropq_w, "diropq=w"},
25931 + {Opt_warn_perm, "warn_perm"},
25932 + {Opt_nowarn_perm, "nowarn_perm"},
25934 + /* keep them temporary */
25935 + {Opt_ignore_silent, "nodlgt"},
25936 + {Opt_ignore, "clean_plink"},
25938 +#ifdef CONFIG_AUFS_SHWH
25939 + {Opt_shwh, "shwh"},
25941 + {Opt_noshwh, "noshwh"},
25943 + {Opt_dirperm1, "dirperm1"},
25944 + {Opt_nodirperm1, "nodirperm1"},
25946 + {Opt_verbose, "verbose"},
25947 + {Opt_verbose, "v"},
25948 + {Opt_noverbose, "noverbose"},
25949 + {Opt_noverbose, "quiet"},
25950 + {Opt_noverbose, "q"},
25951 + {Opt_noverbose, "silent"},
25953 + {Opt_sum, "sum"},
25954 + {Opt_nosum, "nosum"},
25955 + {Opt_wsum, "wsum"},
25957 + {Opt_rdcache, "rdcache=%d"},
25958 + {Opt_rdblk, "rdblk=%d"},
25959 + {Opt_rdblk_def, "rdblk=def"},
25960 + {Opt_rdhash, "rdhash=%d"},
25961 + {Opt_rdhash_def, "rdhash=def"},
25963 + {Opt_wbr_create, "create=%s"},
25964 + {Opt_wbr_create, "create_policy=%s"},
25965 + {Opt_wbr_copyup, "cpup=%s"},
25966 + {Opt_wbr_copyup, "copyup=%s"},
25967 + {Opt_wbr_copyup, "copyup_policy=%s"},
25969 + /* generic VFS flag */
25970 +#ifdef CONFIG_FS_POSIX_ACL
25971 + {Opt_acl, "acl"},
25972 + {Opt_noacl, "noacl"},
25974 + {Opt_ignore, "acl"},
25975 + {Opt_ignore_silent, "noacl"},
25978 + /* internal use for the scripts */
25979 + {Opt_ignore_silent, "si=%s"},
25981 + {Opt_br, "dirs=%s"},
25982 + {Opt_ignore, "debug=%d"},
25983 + {Opt_ignore, "delete=whiteout"},
25984 + {Opt_ignore, "delete=all"},
25985 + {Opt_ignore, "imap=%s"},
25987 + /* temporary workaround, due to old mount(8)? */
25988 + {Opt_ignore_silent, "relatime"},
25993 +/* ---------------------------------------------------------------------- */
25995 +static const char *au_parser_pattern(int val, match_table_t tbl)
25997 + struct match_token *p;
26000 + while (p->pattern) {
26001 + if (p->token == val)
26002 + return p->pattern;
26009 +static const char *au_optstr(int *val, match_table_t tbl)
26011 + struct match_token *p;
26018 + while (p->pattern) {
26020 + && (v & p->token) == p->token) {
26021 + *val &= ~p->token;
26022 + return p->pattern;
26031 +/* ---------------------------------------------------------------------- */
26033 +static match_table_t brperm = {
26034 + {AuBrPerm_RO, AUFS_BRPERM_RO},
26035 + {AuBrPerm_RR, AUFS_BRPERM_RR},
26036 + {AuBrPerm_RW, AUFS_BRPERM_RW},
26040 +static match_table_t brattr = {
26042 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
26043 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
26044 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
26045 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
26046 +#ifdef CONFIG_AUFS_FHSM
26047 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
26049 +#ifdef CONFIG_AUFS_XATTR
26050 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
26051 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
26052 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
26053 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
26054 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
26055 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
26058 + /* ro/rr branch */
26059 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
26062 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
26063 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
26068 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
26075 + p = strchr(str, '+');
26078 + v = match_token(str, table, args);
26080 + if (v & AuBrAttr_CMOO_Mask)
26081 + attr &= ~AuBrAttr_CMOO_Mask;
26086 + pr_warn("ignored branch attribute %s\n", str);
26096 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
26104 + p = au_optstr(&perm, brattr);
26107 + memcpy(q, p, sz + 1);
26113 + p = au_optstr(&perm, brattr);
26117 + memcpy(q, p, sz + 1);
26123 + return q - str->a;
26126 +static int noinline_for_stack br_perm_val(char *perm)
26128 + int val, bad, sz;
26130 + substring_t args[MAX_OPT_ARGS];
26131 + au_br_perm_str_t attr;
26133 + p = strchr(perm, '+');
26136 + val = match_token(perm, brperm, args);
26140 + pr_warn("ignored branch permission %s\n", perm);
26141 + val = AuBrPerm_RO;
26147 + val |= br_attr_val(p + 1, brattr, args);
26150 + switch (val & AuBrPerm_Mask) {
26151 + case AuBrPerm_RO:
26152 + case AuBrPerm_RR:
26153 + bad = val & AuBrWAttr_Mask;
26154 + val &= ~AuBrWAttr_Mask;
26156 + case AuBrPerm_RW:
26157 + bad = val & AuBrRAttr_Mask;
26158 + val &= ~AuBrRAttr_Mask;
26163 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
26164 + * does not treat it as an error, just warning.
26165 + * this is a tiny guard for the user operation.
26167 + if (val & AuBrAttr_UNPIN) {
26168 + bad |= AuBrAttr_UNPIN;
26169 + val &= ~AuBrAttr_UNPIN;
26172 + if (unlikely(bad)) {
26173 + sz = au_do_optstr_br_attr(&attr, bad);
26175 + pr_warn("ignored branch attribute %s\n", attr.a);
26182 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
26184 + au_br_perm_str_t attr;
26190 + p = au_optstr(&perm, brperm);
26191 + AuDebugOn(!p || !*p);
26193 + memcpy(q, p, sz + 1);
26196 + sz = au_do_optstr_br_attr(&attr, perm);
26199 + memcpy(q, attr.a, sz + 1);
26202 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
26205 +/* ---------------------------------------------------------------------- */
26207 +static match_table_t udbalevel = {
26208 + {AuOpt_UDBA_REVAL, "reval"},
26209 + {AuOpt_UDBA_NONE, "none"},
26210 +#ifdef CONFIG_AUFS_HNOTIFY
26211 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
26212 +#ifdef CONFIG_AUFS_HFSNOTIFY
26213 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
26219 +static int noinline_for_stack udba_val(char *str)
26221 + substring_t args[MAX_OPT_ARGS];
26223 + return match_token(str, udbalevel, args);
26226 +const char *au_optstr_udba(int udba)
26228 + return au_parser_pattern(udba, udbalevel);
26231 +/* ---------------------------------------------------------------------- */
26233 +static match_table_t au_wbr_create_policy = {
26234 + {AuWbrCreate_TDP, "tdp"},
26235 + {AuWbrCreate_TDP, "top-down-parent"},
26236 + {AuWbrCreate_RR, "rr"},
26237 + {AuWbrCreate_RR, "round-robin"},
26238 + {AuWbrCreate_MFS, "mfs"},
26239 + {AuWbrCreate_MFS, "most-free-space"},
26240 + {AuWbrCreate_MFSV, "mfs:%d"},
26241 + {AuWbrCreate_MFSV, "most-free-space:%d"},
26243 + /* top-down regardless the parent, and then mfs */
26244 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
26245 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
26247 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
26248 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
26249 + {AuWbrCreate_PMFS, "pmfs"},
26250 + {AuWbrCreate_PMFSV, "pmfs:%d"},
26251 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
26252 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26257 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26258 + struct au_opt_wbr_create *create)
26261 + unsigned long long ull;
26264 + if (!match_u64(arg, &ull))
26265 + create->mfsrr_watermark = ull;
26267 + pr_err("bad integer in %s\n", str);
26274 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26275 + struct au_opt_wbr_create *create)
26280 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26281 + create->mfs_second = n;
26283 + pr_err("bad integer in %s\n", str);
26290 +static int noinline_for_stack
26291 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26294 + substring_t args[MAX_OPT_ARGS];
26296 + err = match_token(str, au_wbr_create_policy, args);
26297 + create->wbr_create = err;
26299 + case AuWbrCreate_MFSRRV:
26300 + case AuWbrCreate_TDMFSV:
26301 + case AuWbrCreate_PMFSRRV:
26302 + e = au_wbr_mfs_wmark(&args[0], str, create);
26304 + e = au_wbr_mfs_sec(&args[1], str, create);
26308 + case AuWbrCreate_MFSRR:
26309 + case AuWbrCreate_TDMFS:
26310 + case AuWbrCreate_PMFSRR:
26311 + e = au_wbr_mfs_wmark(&args[0], str, create);
26312 + if (unlikely(e)) {
26317 + case AuWbrCreate_MFS:
26318 + case AuWbrCreate_PMFS:
26319 + create->mfs_second = AUFS_MFS_DEF_SEC;
26321 + case AuWbrCreate_MFSV:
26322 + case AuWbrCreate_PMFSV:
26323 + e = au_wbr_mfs_sec(&args[0], str, create);
26332 +const char *au_optstr_wbr_create(int wbr_create)
26334 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26337 +static match_table_t au_wbr_copyup_policy = {
26338 + {AuWbrCopyup_TDP, "tdp"},
26339 + {AuWbrCopyup_TDP, "top-down-parent"},
26340 + {AuWbrCopyup_BUP, "bup"},
26341 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26342 + {AuWbrCopyup_BU, "bu"},
26343 + {AuWbrCopyup_BU, "bottom-up"},
26347 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26349 + substring_t args[MAX_OPT_ARGS];
26351 + return match_token(str, au_wbr_copyup_policy, args);
26354 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26356 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26359 +/* ---------------------------------------------------------------------- */
26361 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26363 +static void dump_opts(struct au_opts *opts)
26365 +#ifdef CONFIG_AUFS_DEBUG
26366 + /* reduce stack space */
26368 + struct au_opt_add *add;
26369 + struct au_opt_del *del;
26370 + struct au_opt_mod *mod;
26371 + struct au_opt_xino *xino;
26372 + struct au_opt_xino_itrunc *xino_itrunc;
26373 + struct au_opt_wbr_create *create;
26375 + struct au_opt *opt;
26378 + while (opt->type != Opt_tail) {
26379 + switch (opt->type) {
26381 + u.add = &opt->add;
26382 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26383 + u.add->bindex, u.add->pathname, u.add->perm,
26384 + u.add->path.dentry);
26388 + u.del = &opt->del;
26389 + AuDbg("del {%s, %p}\n",
26390 + u.del->pathname, u.del->h_path.dentry);
26394 + u.mod = &opt->mod;
26395 + AuDbg("mod {%s, 0x%x, %p}\n",
26396 + u.mod->path, u.mod->perm, u.mod->h_root);
26399 + u.add = &opt->add;
26400 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26401 + u.add->bindex, u.add->pathname, u.add->perm,
26402 + u.add->path.dentry);
26404 + case Opt_prepend:
26405 + u.add = &opt->add;
26406 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26407 + u.add->bindex, u.add->pathname, u.add->perm,
26408 + u.add->path.dentry);
26411 + AuDbg("dirwh %d\n", opt->dirwh);
26413 + case Opt_rdcache:
26414 + AuDbg("rdcache %d\n", opt->rdcache);
26417 + AuDbg("rdblk %u\n", opt->rdblk);
26419 + case Opt_rdblk_def:
26420 + AuDbg("rdblk_def\n");
26423 + AuDbg("rdhash %u\n", opt->rdhash);
26425 + case Opt_rdhash_def:
26426 + AuDbg("rdhash_def\n");
26429 + u.xino = &opt->xino;
26430 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26432 + case Opt_trunc_xino:
26433 + AuLabel(trunc_xino);
26435 + case Opt_notrunc_xino:
26436 + AuLabel(notrunc_xino);
26438 + case Opt_trunc_xino_path:
26439 + case Opt_itrunc_xino:
26440 + u.xino_itrunc = &opt->xino_itrunc;
26441 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26446 + case Opt_trunc_xib:
26447 + AuLabel(trunc_xib);
26449 + case Opt_notrunc_xib:
26450 + AuLabel(notrunc_xib);
26458 + case Opt_dirperm1:
26459 + AuLabel(dirperm1);
26461 + case Opt_nodirperm1:
26462 + AuLabel(nodirperm1);
26467 + case Opt_noplink:
26468 + AuLabel(noplink);
26470 + case Opt_list_plink:
26471 + AuLabel(list_plink);
26474 + AuDbg("udba %d, %s\n",
26475 + opt->udba, au_optstr_udba(opt->udba));
26483 + case Opt_diropq_a:
26484 + AuLabel(diropq_a);
26486 + case Opt_diropq_w:
26487 + AuLabel(diropq_w);
26489 + case Opt_warn_perm:
26490 + AuLabel(warn_perm);
26492 + case Opt_nowarn_perm:
26493 + AuLabel(nowarn_perm);
26495 + case Opt_verbose:
26496 + AuLabel(verbose);
26498 + case Opt_noverbose:
26499 + AuLabel(noverbose);
26510 + case Opt_wbr_create:
26511 + u.create = &opt->wbr_create;
26512 + AuDbg("create %d, %s\n", u.create->wbr_create,
26513 + au_optstr_wbr_create(u.create->wbr_create));
26514 + switch (u.create->wbr_create) {
26515 + case AuWbrCreate_MFSV:
26516 + case AuWbrCreate_PMFSV:
26517 + AuDbg("%d sec\n", u.create->mfs_second);
26519 + case AuWbrCreate_MFSRR:
26520 + case AuWbrCreate_TDMFS:
26521 + AuDbg("%llu watermark\n",
26522 + u.create->mfsrr_watermark);
26524 + case AuWbrCreate_MFSRRV:
26525 + case AuWbrCreate_TDMFSV:
26526 + case AuWbrCreate_PMFSRRV:
26527 + AuDbg("%llu watermark, %d sec\n",
26528 + u.create->mfsrr_watermark,
26529 + u.create->mfs_second);
26533 + case Opt_wbr_copyup:
26534 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26535 + au_optstr_wbr_copyup(opt->wbr_copyup));
26537 + case Opt_fhsm_sec:
26538 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26543 + case Opt_nodirren:
26544 + AuLabel(nodirren);
26560 +void au_opts_free(struct au_opts *opts)
26562 + struct au_opt *opt;
26565 + while (opt->type != Opt_tail) {
26566 + switch (opt->type) {
26569 + case Opt_prepend:
26570 + path_put(&opt->add.path);
26574 + path_put(&opt->del.h_path);
26578 + dput(opt->mod.h_root);
26581 + fput(opt->xino.file);
26588 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26589 + aufs_bindex_t bindex)
26592 + struct au_opt_add *add = &opt->add;
26595 + add->bindex = bindex;
26596 + add->perm = AuBrPerm_RO;
26597 + add->pathname = opt_str;
26598 + p = strchr(opt_str, '=');
26602 + add->perm = br_perm_val(p);
26605 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26608 + add->perm = AuBrPerm_RO;
26609 + if (au_test_fs_rr(add->path.dentry->d_sb))
26610 + add->perm = AuBrPerm_RR;
26611 + else if (!bindex && !(sb_flags & SB_RDONLY))
26612 + add->perm = AuBrPerm_RW;
26614 + opt->type = Opt_add;
26617 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26624 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26628 + del->pathname = args[0].from;
26629 + AuDbg("del path %s\n", del->pathname);
26631 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26632 + if (unlikely(err))
26633 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26638 +#if 0 /* reserved for future use */
26639 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26640 + struct au_opt_del *del, substring_t args[])
26643 + struct dentry *root;
26646 + root = sb->s_root;
26647 + aufs_read_lock(root, AuLock_FLUSH);
26648 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26649 + pr_err("out of bounds, %d\n", bindex);
26654 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26655 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26658 + aufs_read_unlock(root, !AuLock_IR);
26663 +static int noinline_for_stack
26664 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26667 + struct path path;
26671 + mod->path = args[0].from;
26672 + p = strchr(mod->path, '=');
26673 + if (unlikely(!p)) {
26674 + pr_err("no permission %s\n", args[0].from);
26679 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26680 + if (unlikely(err)) {
26681 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26685 + mod->perm = br_perm_val(p);
26686 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26687 + mod->h_root = dget(path.dentry);
26694 +#if 0 /* reserved for future use */
26695 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26696 + struct au_opt_mod *mod, substring_t args[])
26699 + struct dentry *root;
26702 + root = sb->s_root;
26703 + aufs_read_lock(root, AuLock_FLUSH);
26704 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26705 + pr_err("out of bounds, %d\n", bindex);
26710 + mod->perm = br_perm_val(args[1].from);
26711 + AuDbg("mod path %s, perm 0x%x, %s\n",
26712 + mod->path, mod->perm, args[1].from);
26713 + mod->h_root = dget(au_h_dptr(root, bindex));
26716 + aufs_read_unlock(root, !AuLock_IR);
26721 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26722 + substring_t args[])
26725 + struct file *file;
26727 + file = au_xino_create(sb, args[0].from, /*silent*/0);
26728 + err = PTR_ERR(file);
26729 + if (IS_ERR(file))
26733 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26735 + pr_err("%s must be outside\n", args[0].from);
26740 + xino->file = file;
26741 + xino->path = args[0].from;
26747 +static int noinline_for_stack
26748 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26749 + struct au_opt_xino_itrunc *xino_itrunc,
26750 + substring_t args[])
26753 + aufs_bindex_t bbot, bindex;
26754 + struct path path;
26755 + struct dentry *root;
26757 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26758 + if (unlikely(err)) {
26759 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26763 + xino_itrunc->bindex = -1;
26764 + root = sb->s_root;
26765 + aufs_read_lock(root, AuLock_FLUSH);
26766 + bbot = au_sbbot(sb);
26767 + for (bindex = 0; bindex <= bbot; bindex++) {
26768 + if (au_h_dptr(root, bindex) == path.dentry) {
26769 + xino_itrunc->bindex = bindex;
26773 + aufs_read_unlock(root, !AuLock_IR);
26776 + if (unlikely(xino_itrunc->bindex < 0)) {
26777 + pr_err("no such branch %s\n", args[0].from);
26785 +/* called without aufs lock */
26786 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26788 + int err, n, token;
26789 + aufs_bindex_t bindex;
26790 + unsigned char skipped;
26791 + struct dentry *root;
26792 + struct au_opt *opt, *opt_tail;
26794 + /* reduce the stack space */
26796 + struct au_opt_xino_itrunc *xino_itrunc;
26797 + struct au_opt_wbr_create *create;
26800 + substring_t args[MAX_OPT_ARGS];
26804 + a = kmalloc(sizeof(*a), GFP_NOFS);
26805 + if (unlikely(!a))
26808 + root = sb->s_root;
26812 + opt_tail = opt + opts->max_opt - 1;
26813 + opt->type = Opt_tail;
26814 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26817 + token = match_token(opt_str, options, a->args);
26821 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26823 + err = opt_add(opt, opt_str, opts->sb_flags,
26825 + if (unlikely(!err && ++opt > opt_tail)) {
26829 + opt->type = Opt_tail;
26834 + if (unlikely(match_int(&a->args[0], &n))) {
26835 + pr_err("bad integer in %s\n", opt_str);
26839 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26842 + opt->type = token;
26845 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26846 + /*dummy bindex*/1);
26848 + opt->type = token;
26850 + case Opt_prepend:
26851 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26854 + opt->type = token;
26857 + err = au_opts_parse_del(&opt->del, a->args);
26859 + opt->type = token;
26861 +#if 0 /* reserved for future use */
26863 + del->pathname = "(indexed)";
26864 + if (unlikely(match_int(&args[0], &n))) {
26865 + pr_err("bad integer in %s\n", opt_str);
26868 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26870 + opt->type = token;
26874 + err = au_opts_parse_mod(&opt->mod, a->args);
26876 + opt->type = token;
26878 +#ifdef IMOD /* reserved for future use */
26880 + u.mod->path = "(indexed)";
26881 + if (unlikely(match_int(&a->args[0], &n))) {
26882 + pr_err("bad integer in %s\n", opt_str);
26885 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26887 + opt->type = token;
26891 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26893 + opt->type = token;
26896 + case Opt_trunc_xino_path:
26897 + err = au_opts_parse_xino_itrunc_path
26898 + (sb, &opt->xino_itrunc, a->args);
26900 + opt->type = token;
26903 + case Opt_itrunc_xino:
26904 + u.xino_itrunc = &opt->xino_itrunc;
26905 + if (unlikely(match_int(&a->args[0], &n))) {
26906 + pr_err("bad integer in %s\n", opt_str);
26909 + u.xino_itrunc->bindex = n;
26910 + aufs_read_lock(root, AuLock_FLUSH);
26911 + if (n < 0 || au_sbbot(sb) < n) {
26912 + pr_err("out of bounds, %d\n", n);
26913 + aufs_read_unlock(root, !AuLock_IR);
26916 + aufs_read_unlock(root, !AuLock_IR);
26918 + opt->type = token;
26922 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26925 + opt->type = token;
26928 + case Opt_rdcache:
26929 + if (unlikely(match_int(&a->args[0], &n))) {
26930 + pr_err("bad integer in %s\n", opt_str);
26933 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26934 + pr_err("rdcache must be smaller than %d\n",
26935 + AUFS_RDCACHE_MAX);
26938 + opt->rdcache = n;
26940 + opt->type = token;
26943 + if (unlikely(match_int(&a->args[0], &n)
26945 + || n > KMALLOC_MAX_SIZE)) {
26946 + pr_err("bad integer in %s\n", opt_str);
26949 + if (unlikely(n && n < NAME_MAX)) {
26950 + pr_err("rdblk must be larger than %d\n",
26956 + opt->type = token;
26959 + if (unlikely(match_int(&a->args[0], &n)
26961 + || n * sizeof(struct hlist_head)
26962 + > KMALLOC_MAX_SIZE)) {
26963 + pr_err("bad integer in %s\n", opt_str);
26968 + opt->type = token;
26971 + case Opt_trunc_xino:
26972 + case Opt_notrunc_xino:
26974 + case Opt_trunc_xib:
26975 + case Opt_notrunc_xib:
26978 + case Opt_dirperm1:
26979 + case Opt_nodirperm1:
26981 + case Opt_noplink:
26982 + case Opt_list_plink:
26985 + case Opt_diropq_a:
26986 + case Opt_diropq_w:
26987 + case Opt_warn_perm:
26988 + case Opt_nowarn_perm:
26989 + case Opt_verbose:
26990 + case Opt_noverbose:
26994 + case Opt_rdblk_def:
26995 + case Opt_rdhash_def:
26997 + case Opt_nodirren:
27001 + opt->type = token;
27005 + opt->udba = udba_val(a->args[0].from);
27006 + if (opt->udba >= 0) {
27008 + opt->type = token;
27010 + pr_err("wrong value, %s\n", opt_str);
27013 + case Opt_wbr_create:
27014 + u.create = &opt->wbr_create;
27015 + u.create->wbr_create
27016 + = au_wbr_create_val(a->args[0].from, u.create);
27017 + if (u.create->wbr_create >= 0) {
27019 + opt->type = token;
27021 + pr_err("wrong value, %s\n", opt_str);
27023 + case Opt_wbr_copyup:
27024 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
27025 + if (opt->wbr_copyup >= 0) {
27027 + opt->type = token;
27029 + pr_err("wrong value, %s\n", opt_str);
27032 + case Opt_fhsm_sec:
27033 + if (unlikely(match_int(&a->args[0], &n)
27035 + pr_err("bad integer in %s\n", opt_str);
27038 + if (sysaufs_brs) {
27039 + opt->fhsm_second = n;
27040 + opt->type = token;
27042 + pr_warn("ignored %s\n", opt_str);
27047 + pr_warn("ignored %s\n", opt_str);
27049 + case Opt_ignore_silent:
27054 + pr_err("unknown option %s\n", opt_str);
27058 + if (!err && !skipped) {
27059 + if (unlikely(++opt > opt_tail)) {
27062 + opt->type = Opt_tail;
27065 + opt->type = Opt_tail;
27071 + if (unlikely(err))
27072 + au_opts_free(opts);
27078 +static int au_opt_wbr_create(struct super_block *sb,
27079 + struct au_opt_wbr_create *create)
27082 + struct au_sbinfo *sbinfo;
27084 + SiMustWriteLock(sb);
27086 + err = 1; /* handled */
27087 + sbinfo = au_sbi(sb);
27088 + if (sbinfo->si_wbr_create_ops->fin) {
27089 + err = sbinfo->si_wbr_create_ops->fin(sb);
27094 + sbinfo->si_wbr_create = create->wbr_create;
27095 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
27096 + switch (create->wbr_create) {
27097 + case AuWbrCreate_MFSRRV:
27098 + case AuWbrCreate_MFSRR:
27099 + case AuWbrCreate_TDMFS:
27100 + case AuWbrCreate_TDMFSV:
27101 + case AuWbrCreate_PMFSRR:
27102 + case AuWbrCreate_PMFSRRV:
27103 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
27105 + case AuWbrCreate_MFS:
27106 + case AuWbrCreate_MFSV:
27107 + case AuWbrCreate_PMFS:
27108 + case AuWbrCreate_PMFSV:
27109 + sbinfo->si_wbr_mfs.mfs_expire
27110 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
27114 + if (sbinfo->si_wbr_create_ops->init)
27115 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27122 + * plus: processed without an error
27123 + * zero: unprocessed
27125 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27126 + struct au_opts *opts)
27129 + struct au_sbinfo *sbinfo;
27131 + SiMustWriteLock(sb);
27133 + err = 1; /* handled */
27134 + sbinfo = au_sbi(sb);
27135 + switch (opt->type) {
27137 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27138 + sbinfo->si_mntflags |= opt->udba;
27139 + opts->given_udba |= opt->udba;
27143 + au_opt_set(sbinfo->si_mntflags, PLINK);
27145 + case Opt_noplink:
27146 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27147 + au_plink_put(sb, /*verbose*/1);
27148 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27150 + case Opt_list_plink:
27151 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27152 + au_plink_list(sb);
27156 + au_opt_set(sbinfo->si_mntflags, DIO);
27157 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27160 + au_opt_clr(sbinfo->si_mntflags, DIO);
27161 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27164 + case Opt_fhsm_sec:
27165 + au_fhsm_set(sbinfo, opt->fhsm_second);
27168 + case Opt_diropq_a:
27169 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27171 + case Opt_diropq_w:
27172 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27175 + case Opt_warn_perm:
27176 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27178 + case Opt_nowarn_perm:
27179 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27182 + case Opt_verbose:
27183 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27185 + case Opt_noverbose:
27186 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27190 + au_opt_set(sbinfo->si_mntflags, SUM);
27193 + au_opt_clr(sbinfo->si_mntflags, SUM);
27194 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27196 + au_opt_clr(sbinfo->si_mntflags, SUM);
27197 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27200 + case Opt_wbr_create:
27201 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27203 + case Opt_wbr_copyup:
27204 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27205 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27209 + sbinfo->si_dirwh = opt->dirwh;
27212 + case Opt_rdcache:
27213 + sbinfo->si_rdcache
27214 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27217 + sbinfo->si_rdblk = opt->rdblk;
27219 + case Opt_rdblk_def:
27220 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
27223 + sbinfo->si_rdhash = opt->rdhash;
27225 + case Opt_rdhash_def:
27226 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
27230 + au_opt_set(sbinfo->si_mntflags, SHWH);
27233 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27236 + case Opt_dirperm1:
27237 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27239 + case Opt_nodirperm1:
27240 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27243 + case Opt_trunc_xino:
27244 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27246 + case Opt_notrunc_xino:
27247 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27250 + case Opt_trunc_xino_path:
27251 + case Opt_itrunc_xino:
27252 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27258 + case Opt_trunc_xib:
27259 + au_fset_opts(opts->flags, TRUNC_XIB);
27261 + case Opt_notrunc_xib:
27262 + au_fclr_opts(opts->flags, TRUNC_XIB);
27267 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27268 + err = au_dr_opt_set(sb);
27273 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27275 + case Opt_nodirren:
27277 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27278 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27284 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27288 + sb->s_flags |= SB_POSIXACL;
27291 + sb->s_flags &= ~SB_POSIXACL;
27303 + * returns tri-state.
27304 + * plus: processed without an error
27305 + * zero: unprocessed
27308 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27309 + struct au_opts *opts)
27311 + int err, do_refresh;
27314 + switch (opt->type) {
27316 + opt->add.bindex = au_sbbot(sb) + 1;
27317 + if (opt->add.bindex < 0)
27318 + opt->add.bindex = 0;
27320 + case Opt_prepend:
27321 + opt->add.bindex = 0;
27322 + add: /* indented label */
27324 + err = au_br_add(sb, &opt->add,
27325 + au_ftest_opts(opts->flags, REMOUNT));
27328 + au_fset_opts(opts->flags, REFRESH);
27334 + err = au_br_del(sb, &opt->del,
27335 + au_ftest_opts(opts->flags, REMOUNT));
27338 + au_fset_opts(opts->flags, TRUNC_XIB);
27339 + au_fset_opts(opts->flags, REFRESH);
27345 + err = au_br_mod(sb, &opt->mod,
27346 + au_ftest_opts(opts->flags, REMOUNT),
27351 + au_fset_opts(opts->flags, REFRESH);
27358 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27359 + struct au_opt_xino **opt_xino,
27360 + struct au_opts *opts)
27365 + switch (opt->type) {
27367 + err = au_xino_set(sb, &opt->xino,
27368 + !!au_ftest_opts(opts->flags, REMOUNT));
27369 + if (unlikely(err))
27372 + *opt_xino = &opt->xino;
27377 + *opt_xino = (void *)-1;
27384 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27385 + unsigned int pending)
27388 + aufs_bindex_t bindex, bbot;
27389 + unsigned char do_plink, skip, do_free, can_no_dreval;
27390 + struct au_branch *br;
27391 + struct au_wbr *wbr;
27392 + struct dentry *root, *dentry;
27393 + struct inode *dir, *h_dir;
27394 + struct au_sbinfo *sbinfo;
27395 + struct au_hinode *hdir;
27397 + SiMustAnyLock(sb);
27399 + sbinfo = au_sbi(sb);
27400 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27402 + if (!(sb_flags & SB_RDONLY)) {
27403 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27404 + pr_warn("first branch should be rw\n");
27405 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27406 + pr_warn_once("shwh should be used with ro\n");
27409 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27410 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27411 + pr_warn_once("udba=*notify requires xino\n");
27413 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27414 + pr_warn_once("dirperm1 breaks the protection"
27415 + " by the permission bits on the lower branch\n");
27419 + root = sb->s_root;
27420 + dir = d_inode(root);
27421 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27422 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27424 + bbot = au_sbbot(sb);
27425 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27427 + h_dir = au_h_iptr(dir, bindex);
27428 + br = au_sbr(sb, bindex);
27430 + if ((br->br_perm & AuBrAttr_ICEX)
27431 + && !h_dir->i_op->listxattr)
27432 + br->br_perm &= ~AuBrAttr_ICEX;
27434 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27435 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27436 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27440 + wbr = br->br_wbr;
27442 + wbr_wh_read_lock(wbr);
27444 + if (!au_br_writable(br->br_perm)) {
27447 + || (!wbr->wbr_whbase
27448 + && !wbr->wbr_plink
27449 + && !wbr->wbr_orph));
27450 + } else if (!au_br_wh_linkable(br->br_perm)) {
27451 + /* skip = (!br->br_whbase && !br->br_orph); */
27452 + skip = (!wbr || !wbr->wbr_whbase);
27453 + if (skip && wbr) {
27455 + skip = !!wbr->wbr_plink;
27457 + skip = !wbr->wbr_plink;
27460 + /* skip = (br->br_whbase && br->br_ohph); */
27461 + skip = (wbr && wbr->wbr_whbase);
27464 + skip = !!wbr->wbr_plink;
27466 + skip = !wbr->wbr_plink;
27470 + wbr_wh_read_unlock(wbr);
27472 + if (can_no_dreval) {
27473 + dentry = br->br_path.dentry;
27474 + spin_lock(&dentry->d_lock);
27475 + if (dentry->d_flags &
27476 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27477 + can_no_dreval = 0;
27478 + spin_unlock(&dentry->d_lock);
27481 + if (au_br_fhsm(br->br_perm)) {
27483 + AuDebugOn(!br->br_fhsm);
27489 + hdir = au_hi(dir, bindex);
27490 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27492 + wbr_wh_write_lock(wbr);
27493 + err = au_wh_init(br, sb);
27495 + wbr_wh_write_unlock(wbr);
27496 + au_hn_inode_unlock(hdir);
27498 + if (!err && do_free) {
27499 + au_kfree_rcu(wbr);
27500 + br->br_wbr = NULL;
27504 + if (can_no_dreval)
27505 + au_fset_si(sbinfo, NO_DREVAL);
27507 + au_fclr_si(sbinfo, NO_DREVAL);
27510 + au_fset_si(sbinfo, FHSM);
27511 + for (bindex = bbot; bindex >= 0; bindex--) {
27512 + br = au_sbr(sb, bindex);
27513 + if (au_br_fhsm(br->br_perm)) {
27514 + au_fhsm_set_bottom(sb, bindex);
27519 + au_fclr_si(sbinfo, FHSM);
27520 + au_fhsm_set_bottom(sb, -1);
27526 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27529 + unsigned int tmp;
27530 + aufs_bindex_t bindex, bbot;
27531 + struct au_opt *opt;
27532 + struct au_opt_xino *opt_xino, xino;
27533 + struct au_sbinfo *sbinfo;
27534 + struct au_branch *br;
27535 + struct inode *dir;
27537 + SiMustWriteLock(sb);
27542 + while (err >= 0 && opt->type != Opt_tail)
27543 + err = au_opt_simple(sb, opt++, opts);
27546 + else if (unlikely(err < 0))
27549 + /* disable xino and udba temporary */
27550 + sbinfo = au_sbi(sb);
27551 + tmp = sbinfo->si_mntflags;
27552 + au_opt_clr(sbinfo->si_mntflags, XINO);
27553 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27556 + while (err >= 0 && opt->type != Opt_tail)
27557 + err = au_opt_br(sb, opt++, opts);
27560 + else if (unlikely(err < 0))
27563 + bbot = au_sbbot(sb);
27564 + if (unlikely(bbot < 0)) {
27566 + pr_err("no branches\n");
27570 + if (au_opt_test(tmp, XINO))
27571 + au_opt_set(sbinfo->si_mntflags, XINO);
27573 + while (!err && opt->type != Opt_tail)
27574 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27575 + if (unlikely(err))
27578 + err = au_opts_verify(sb, sb->s_flags, tmp);
27579 + if (unlikely(err))
27582 + /* restore xino */
27583 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27584 + xino.file = au_xino_def(sb);
27585 + err = PTR_ERR(xino.file);
27586 + if (IS_ERR(xino.file))
27589 + err = au_xino_set(sb, &xino, /*remount*/0);
27591 + if (unlikely(err))
27595 + /* restore udba */
27596 + tmp &= AuOptMask_UDBA;
27597 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27598 + sbinfo->si_mntflags |= tmp;
27599 + bbot = au_sbbot(sb);
27600 + for (bindex = 0; bindex <= bbot; bindex++) {
27601 + br = au_sbr(sb, bindex);
27602 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27603 + if (unlikely(err))
27604 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27606 + /* go on even if err */
27608 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27609 + dir = d_inode(sb->s_root);
27610 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27617 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27620 + unsigned char no_dreval;
27621 + struct inode *dir;
27622 + struct au_opt_xino *opt_xino;
27623 + struct au_opt *opt;
27624 + struct au_sbinfo *sbinfo;
27626 + SiMustWriteLock(sb);
27628 + err = au_dr_opt_flush(sb);
27629 + if (unlikely(err))
27631 + au_fset_opts(opts->flags, DR_FLUSHED);
27633 + dir = d_inode(sb->s_root);
27634 + sbinfo = au_sbi(sb);
27637 + while (err >= 0 && opt->type != Opt_tail) {
27638 + err = au_opt_simple(sb, opt, opts);
27640 + err = au_opt_br(sb, opt, opts);
27642 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27648 + /* go on even err */
27650 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27651 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27652 + if (unlikely(rerr && !err))
27655 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27656 + au_fset_opts(opts->flags, REFRESH_IDOP);
27658 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27659 + rerr = au_xib_trunc(sb);
27660 + if (unlikely(rerr && !err))
27664 + /* will be handled by the caller */
27665 + if (!au_ftest_opts(opts->flags, REFRESH)
27666 + && (opts->given_udba
27667 + || au_opt_test(sbinfo->si_mntflags, XINO)
27668 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27670 + au_fset_opts(opts->flags, REFRESH);
27672 + AuDbg("status 0x%x\n", opts->flags);
27678 +/* ---------------------------------------------------------------------- */
27680 +unsigned int au_opt_udba(struct super_block *sb)
27682 + return au_mntflags(sb) & AuOptMask_UDBA;
27684 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27685 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27686 +++ linux/fs/aufs/opts.h 2019-05-06 09:03:04.820143837 +0200
27688 +/* SPDX-License-Identifier: GPL-2.0 */
27690 + * Copyright (C) 2005-2019 Junjiro R. Okajima
27692 + * This program, aufs is free software; you can redistribute it and/or modify
27693 + * it under the terms of the GNU General Public License as published by
27694 + * the Free Software Foundation; either version 2 of the License, or
27695 + * (at your option) any later version.
27697 + * This program is distributed in the hope that it will be useful,
27698 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27699 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27700 + * GNU General Public License for more details.
27702 + * You should have received a copy of the GNU General Public License
27703 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27707 + * mount options/flags
27710 +#ifndef __AUFS_OPTS_H__
27711 +#define __AUFS_OPTS_H__
27715 +#include <linux/path.h>
27719 +/* ---------------------------------------------------------------------- */
27722 +#define AuOpt_XINO 1 /* external inode number bitmap
27723 + and translation table */
27724 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27725 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27726 +#define AuOpt_UDBA_REVAL (1 << 3)
27727 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27728 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27729 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27730 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27732 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27733 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27734 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27735 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27736 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27737 +#define AuOpt_DIO (1 << 14) /* direct io */
27738 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27740 +#ifndef CONFIG_AUFS_HNOTIFY
27741 +#undef AuOpt_UDBA_HNOTIFY
27742 +#define AuOpt_UDBA_HNOTIFY 0
27744 +#ifndef CONFIG_AUFS_DIRREN
27745 +#undef AuOpt_DIRREN
27746 +#define AuOpt_DIRREN 0
27748 +#ifndef CONFIG_AUFS_SHWH
27750 +#define AuOpt_SHWH 0
27753 +#define AuOpt_Def (AuOpt_XINO \
27754 + | AuOpt_UDBA_REVAL \
27756 + /* | AuOpt_DIRPERM1 */ \
27757 + | AuOpt_WARN_PERM)
27758 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27759 + | AuOpt_UDBA_REVAL \
27760 + | AuOpt_UDBA_HNOTIFY)
27762 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27763 +#define au_opt_set(flags, name) do { \
27764 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27765 + ((flags) |= AuOpt_##name); \
27767 +#define au_opt_set_udba(flags, name) do { \
27768 + (flags) &= ~AuOptMask_UDBA; \
27769 + ((flags) |= AuOpt_##name); \
27771 +#define au_opt_clr(flags, name) do { \
27772 + ((flags) &= ~AuOpt_##name); \
27775 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27777 +#ifdef CONFIG_PROC_FS
27780 + return mntflags & ~AuOpt_PLINK;
27784 +/* ---------------------------------------------------------------------- */
27786 +/* policies to select one among multiple writable branches */
27788 + AuWbrCreate_TDP, /* top down parent */
27789 + AuWbrCreate_RR, /* round robin */
27790 + AuWbrCreate_MFS, /* most free space */
27791 + AuWbrCreate_MFSV, /* mfs with seconds */
27792 + AuWbrCreate_MFSRR, /* mfs then rr */
27793 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27794 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27795 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27796 + AuWbrCreate_PMFS, /* parent and mfs */
27797 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27798 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27799 + AuWbrCreate_PMFSRRV, /* plus seconds */
27801 + AuWbrCreate_Def = AuWbrCreate_TDP
27805 + AuWbrCopyup_TDP, /* top down parent */
27806 + AuWbrCopyup_BUP, /* bottom up parent */
27807 + AuWbrCopyup_BU, /* bottom up */
27809 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27812 +/* ---------------------------------------------------------------------- */
27814 +struct au_opt_add {
27815 + aufs_bindex_t bindex;
27818 + struct path path;
27821 +struct au_opt_del {
27823 + struct path h_path;
27826 +struct au_opt_mod {
27829 + struct dentry *h_root;
27832 +struct au_opt_xino {
27834 + struct file *file;
27837 +struct au_opt_xino_itrunc {
27838 + aufs_bindex_t bindex;
27841 +struct au_opt_wbr_create {
27844 + unsigned long long mfsrr_watermark;
27850 + struct au_opt_xino xino;
27851 + struct au_opt_xino_itrunc xino_itrunc;
27852 + struct au_opt_add add;
27853 + struct au_opt_del del;
27854 + struct au_opt_mod mod;
27857 + unsigned int rdblk;
27858 + unsigned int rdhash;
27860 + struct au_opt_wbr_create wbr_create;
27862 + unsigned int fhsm_second;
27867 +#define AuOpts_REMOUNT 1
27868 +#define AuOpts_REFRESH (1 << 1)
27869 +#define AuOpts_TRUNC_XIB (1 << 2)
27870 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27871 +#define AuOpts_REFRESH_IDOP (1 << 4)
27872 +#define AuOpts_DR_FLUSHED (1 << 5)
27873 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27874 +#define au_fset_opts(flags, name) \
27875 + do { (flags) |= AuOpts_##name; } while (0)
27876 +#define au_fclr_opts(flags, name) \
27877 + do { (flags) &= ~AuOpts_##name; } while (0)
27879 +#ifndef CONFIG_AUFS_DIRREN
27880 +#undef AuOpts_DR_FLUSHED
27881 +#define AuOpts_DR_FLUSHED 0
27885 + struct au_opt *opt;
27888 + unsigned int given_udba;
27889 + unsigned int flags;
27890 + unsigned long sb_flags;
27893 +/* ---------------------------------------------------------------------- */
27896 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27897 +const char *au_optstr_udba(int udba);
27898 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27899 +const char *au_optstr_wbr_create(int wbr_create);
27901 +void au_opts_free(struct au_opts *opts);
27902 +struct super_block;
27903 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27904 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27905 + unsigned int pending);
27906 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27907 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27909 +unsigned int au_opt_udba(struct super_block *sb);
27911 +#endif /* __KERNEL__ */
27912 +#endif /* __AUFS_OPTS_H__ */
27913 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27914 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27915 +++ linux/fs/aufs/plink.c 2019-03-05 12:13:00.142557771 +0100
27917 +// SPDX-License-Identifier: GPL-2.0
27919 + * Copyright (C) 2005-2019 Junjiro R. Okajima
27921 + * This program, aufs is free software; you can redistribute it and/or modify
27922 + * it under the terms of the GNU General Public License as published by
27923 + * the Free Software Foundation; either version 2 of the License, or
27924 + * (at your option) any later version.
27926 + * This program is distributed in the hope that it will be useful,
27927 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27928 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27929 + * GNU General Public License for more details.
27931 + * You should have received a copy of the GNU General Public License
27932 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27942 + * the pseudo-link maintenance mode.
27943 + * during a user process maintains the pseudo-links,
27944 + * prohibit adding a new plink and branch manipulation.
27948 + * For entry functions which will handle plink, and i_mutex is already held
27950 + * They cannot wait and should return an error at once.
27951 + * Callers has to check the error.
27953 + * For entry functions which will handle plink, but i_mutex is not held
27955 + * They can wait the plink maintenance mode to finish.
27957 + * They behave like F_SETLK and F_SETLKW.
27958 + * If the caller never handle plink, then both flags are unnecessary.
27961 +int au_plink_maint(struct super_block *sb, int flags)
27965 + struct task_struct *parent, *prev;
27966 + struct au_sbinfo *sbi;
27968 + SiMustAnyLock(sb);
27971 + if (!au_opt_test(au_mntflags(sb), PLINK))
27974 + sbi = au_sbi(sb);
27975 + pid = sbi->si_plink_maint_pid;
27976 + if (!pid || pid == current->pid)
27979 + /* todo: it highly depends upon /sbin/mount.aufs */
27981 + parent = current;
27985 + parent = rcu_dereference(parent->real_parent);
27986 + if (parent == prev)
27988 + ppid = task_pid_vnr(parent);
27989 + if (pid == ppid) {
27990 + rcu_read_unlock();
27995 + rcu_read_unlock();
27997 + if (au_ftest_lock(flags, NOPLMW)) {
27998 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27999 + /* AuDebugOn(!lockdep_depth(current)); */
28000 + while (sbi->si_plink_maint_pid) {
28001 + si_read_unlock(sb);
28002 + /* gave up wake_up_bit() */
28003 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
28005 + if (au_ftest_lock(flags, FLUSH))
28006 + au_nwt_flush(&sbi->si_nowait);
28007 + si_noflush_read_lock(sb);
28009 + } else if (au_ftest_lock(flags, NOPLM)) {
28010 + AuDbg("ppid %d, pid %d\n", ppid, pid);
28018 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
28020 + spin_lock(&sbinfo->si_plink_maint_lock);
28021 + sbinfo->si_plink_maint_pid = 0;
28022 + spin_unlock(&sbinfo->si_plink_maint_lock);
28023 + wake_up_all(&sbinfo->si_plink_wq);
28026 +int au_plink_maint_enter(struct super_block *sb)
28029 + struct au_sbinfo *sbinfo;
28032 + sbinfo = au_sbi(sb);
28033 + /* make sure i am the only one in this fs */
28034 + si_write_lock(sb, AuLock_FLUSH);
28035 + if (au_opt_test(au_mntflags(sb), PLINK)) {
28036 + spin_lock(&sbinfo->si_plink_maint_lock);
28037 + if (!sbinfo->si_plink_maint_pid)
28038 + sbinfo->si_plink_maint_pid = current->pid;
28041 + spin_unlock(&sbinfo->si_plink_maint_lock);
28043 + si_write_unlock(sb);
28048 +/* ---------------------------------------------------------------------- */
28050 +#ifdef CONFIG_AUFS_DEBUG
28051 +void au_plink_list(struct super_block *sb)
28054 + struct au_sbinfo *sbinfo;
28055 + struct hlist_bl_head *hbl;
28056 + struct hlist_bl_node *pos;
28057 + struct au_icntnr *icntnr;
28059 + SiMustAnyLock(sb);
28061 + sbinfo = au_sbi(sb);
28062 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28063 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28065 + for (i = 0; i < AuPlink_NHASH; i++) {
28066 + hbl = sbinfo->si_plink + i;
28067 + hlist_bl_lock(hbl);
28068 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28069 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
28070 + hlist_bl_unlock(hbl);
28075 +/* is the inode pseudo-linked? */
28076 +int au_plink_test(struct inode *inode)
28079 + struct au_sbinfo *sbinfo;
28080 + struct hlist_bl_head *hbl;
28081 + struct hlist_bl_node *pos;
28082 + struct au_icntnr *icntnr;
28084 + sbinfo = au_sbi(inode->i_sb);
28085 + AuRwMustAnyLock(&sbinfo->si_rwsem);
28086 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
28087 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28090 + i = au_plink_hash(inode->i_ino);
28091 + hbl = sbinfo->si_plink + i;
28092 + hlist_bl_lock(hbl);
28093 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28094 + if (&icntnr->vfs_inode == inode) {
28098 + hlist_bl_unlock(hbl);
28102 +/* ---------------------------------------------------------------------- */
28105 + * generate a name for plink.
28106 + * the file will be stored under AUFS_WH_PLINKDIR.
28108 +/* 20 is max digits length of ulong 64 */
28109 +#define PLINK_NAME_LEN ((20 + 1) * 2)
28111 +static int plink_name(char *name, int len, struct inode *inode,
28112 + aufs_bindex_t bindex)
28115 + struct inode *h_inode;
28117 + h_inode = au_h_iptr(inode, bindex);
28118 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28122 +struct au_do_plink_lkup_args {
28123 + struct dentry **errp;
28124 + struct qstr *tgtname;
28125 + struct dentry *h_parent;
28126 + struct au_branch *br;
28129 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28130 + struct dentry *h_parent,
28131 + struct au_branch *br)
28133 + struct dentry *h_dentry;
28134 + struct inode *h_inode;
28136 + h_inode = d_inode(h_parent);
28137 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28138 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
28139 + inode_unlock_shared(h_inode);
28143 +static void au_call_do_plink_lkup(void *args)
28145 + struct au_do_plink_lkup_args *a = args;
28146 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
28149 +/* lookup the plink-ed @inode under the branch at @bindex */
28150 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28152 + struct dentry *h_dentry, *h_parent;
28153 + struct au_branch *br;
28155 + char a[PLINK_NAME_LEN];
28156 + struct qstr tgtname = QSTR_INIT(a, 0);
28158 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28160 + br = au_sbr(inode->i_sb, bindex);
28161 + h_parent = br->br_wbr->wbr_plink;
28162 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28164 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28165 + struct au_do_plink_lkup_args args = {
28166 + .errp = &h_dentry,
28167 + .tgtname = &tgtname,
28168 + .h_parent = h_parent,
28172 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28173 + if (unlikely(wkq_err))
28174 + h_dentry = ERR_PTR(wkq_err);
28176 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
28181 +/* create a pseudo-link */
28182 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
28183 + struct dentry *h_dentry, struct au_branch *br)
28186 + struct path h_path = {
28187 + .mnt = au_br_mnt(br)
28189 + struct inode *h_dir, *delegated;
28191 + h_dir = d_inode(h_parent);
28192 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28194 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
28195 + err = PTR_ERR(h_path.dentry);
28196 + if (IS_ERR(h_path.dentry))
28200 + /* wh.plink dir is not monitored */
28201 + /* todo: is it really safe? */
28202 + if (d_is_positive(h_path.dentry)
28203 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28204 + delegated = NULL;
28205 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28206 + if (unlikely(err == -EWOULDBLOCK)) {
28207 + pr_warn("cannot retry for NFSv4 delegation"
28208 + " for an internal unlink\n");
28211 + dput(h_path.dentry);
28212 + h_path.dentry = NULL;
28216 + if (!err && d_is_negative(h_path.dentry)) {
28217 + delegated = NULL;
28218 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28219 + if (unlikely(err == -EWOULDBLOCK)) {
28220 + pr_warn("cannot retry for NFSv4 delegation"
28221 + " for an internal link\n");
28225 + dput(h_path.dentry);
28228 + inode_unlock(h_dir);
28232 +struct do_whplink_args {
28234 + struct qstr *tgt;
28235 + struct dentry *h_parent;
28236 + struct dentry *h_dentry;
28237 + struct au_branch *br;
28240 +static void call_do_whplink(void *args)
28242 + struct do_whplink_args *a = args;
28243 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
28246 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28247 + aufs_bindex_t bindex, struct au_branch *br)
28249 + int err, wkq_err;
28250 + struct au_wbr *wbr;
28251 + struct dentry *h_parent;
28252 + char a[PLINK_NAME_LEN];
28253 + struct qstr tgtname = QSTR_INIT(a, 0);
28255 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
28256 + h_parent = wbr->wbr_plink;
28257 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28259 + /* always superio. */
28260 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28261 + struct do_whplink_args args = {
28264 + .h_parent = h_parent,
28265 + .h_dentry = h_dentry,
28268 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28269 + if (unlikely(wkq_err))
28272 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
28278 + * create a new pseudo-link for @h_dentry on @bindex.
28279 + * the linked inode is held in aufs @inode.
28281 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28282 + struct dentry *h_dentry)
28284 + struct super_block *sb;
28285 + struct au_sbinfo *sbinfo;
28286 + struct hlist_bl_head *hbl;
28287 + struct hlist_bl_node *pos;
28288 + struct au_icntnr *icntnr;
28289 + int found, err, cnt, i;
28291 + sb = inode->i_sb;
28292 + sbinfo = au_sbi(sb);
28293 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28294 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28296 + found = au_plink_test(inode);
28300 + i = au_plink_hash(inode->i_ino);
28301 + hbl = sbinfo->si_plink + i;
28304 + hlist_bl_lock(hbl);
28305 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28306 + if (&icntnr->vfs_inode == inode) {
28312 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28313 + hlist_bl_add_head(&icntnr->plink, hbl);
28315 + hlist_bl_unlock(hbl);
28317 + cnt = au_hbl_count(hbl);
28318 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28319 + if (cnt > AUFS_PLINK_WARN)
28320 + AuWarn1(msg ", %d\n", cnt);
28322 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
28323 + if (unlikely(err)) {
28324 + pr_warn("err %d, damaged pseudo link.\n", err);
28325 + au_hbl_del(&icntnr->plink, hbl);
28326 + iput(&icntnr->vfs_inode);
28329 + iput(&icntnr->vfs_inode);
28332 +/* free all plinks */
28333 +void au_plink_put(struct super_block *sb, int verbose)
28336 + struct au_sbinfo *sbinfo;
28337 + struct hlist_bl_head *hbl;
28338 + struct hlist_bl_node *pos, *tmp;
28339 + struct au_icntnr *icntnr;
28341 + SiMustWriteLock(sb);
28343 + sbinfo = au_sbi(sb);
28344 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28345 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28347 + /* no spin_lock since sbinfo is write-locked */
28349 + for (i = 0; i < AuPlink_NHASH; i++) {
28350 + hbl = sbinfo->si_plink + i;
28351 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28352 + pr_warn("pseudo-link is not flushed");
28355 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28356 + iput(&icntnr->vfs_inode);
28357 + INIT_HLIST_BL_HEAD(hbl);
28361 +void au_plink_clean(struct super_block *sb, int verbose)
28363 + struct dentry *root;
28365 + root = sb->s_root;
28366 + aufs_write_lock(root);
28367 + if (au_opt_test(au_mntflags(sb), PLINK))
28368 + au_plink_put(sb, verbose);
28369 + aufs_write_unlock(root);
28372 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28375 + aufs_bindex_t btop, bbot, bindex;
28378 + btop = au_ibtop(inode);
28379 + bbot = au_ibbot(inode);
28381 + for (bindex = btop; bindex <= bbot; bindex++) {
28382 + if (!au_h_iptr(inode, bindex)
28383 + || au_ii_br_id(inode, bindex) != br_id)
28385 + au_set_h_iptr(inode, bindex, NULL, 0);
28390 + for (bindex = btop; bindex <= bbot; bindex++)
28391 + if (au_h_iptr(inode, bindex)) {
28401 +/* free the plinks on a branch specified by @br_id */
28402 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28404 + struct au_sbinfo *sbinfo;
28405 + struct hlist_bl_head *hbl;
28406 + struct hlist_bl_node *pos, *tmp;
28407 + struct au_icntnr *icntnr;
28408 + struct inode *inode;
28411 + SiMustWriteLock(sb);
28413 + sbinfo = au_sbi(sb);
28414 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28415 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28417 + /* no bit_lock since sbinfo is write-locked */
28418 + for (i = 0; i < AuPlink_NHASH; i++) {
28419 + hbl = sbinfo->si_plink + i;
28420 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28421 + inode = au_igrab(&icntnr->vfs_inode);
28422 + ii_write_lock_child(inode);
28423 + do_put = au_plink_do_half_refresh(inode, br_id);
28425 + hlist_bl_del(&icntnr->plink);
28428 + ii_write_unlock(inode);
28433 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28434 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28435 +++ linux/fs/aufs/poll.c 2019-03-05 12:13:00.142557771 +0100
28437 +// SPDX-License-Identifier: GPL-2.0
28439 + * Copyright (C) 2005-2019 Junjiro R. Okajima
28441 + * This program, aufs is free software; you can redistribute it and/or modify
28442 + * it under the terms of the GNU General Public License as published by
28443 + * the Free Software Foundation; either version 2 of the License, or
28444 + * (at your option) any later version.
28446 + * This program is distributed in the hope that it will be useful,
28447 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28448 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28449 + * GNU General Public License for more details.
28451 + * You should have received a copy of the GNU General Public License
28452 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28457 + * There is only one filesystem which implements ->poll operation, currently.
28462 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28465 + struct file *h_file;
28466 + struct super_block *sb;
28468 + /* We should pretend an error happened. */
28469 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28470 + sb = file->f_path.dentry->d_sb;
28471 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28473 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28474 + if (IS_ERR(h_file)) {
28475 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28479 + mask = vfs_poll(h_file, pt);
28480 + fput(h_file); /* instead of au_read_post() */
28483 + si_read_unlock(sb);
28484 + if (mask & EPOLLERR)
28485 + AuDbg("mask 0x%x\n", mask);
28488 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28489 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28490 +++ linux/fs/aufs/posix_acl.c 2019-03-05 12:13:00.142557771 +0100
28492 +// SPDX-License-Identifier: GPL-2.0
28494 + * Copyright (C) 2014-2019 Junjiro R. Okajima
28496 + * This program, aufs is free software; you can redistribute it and/or modify
28497 + * it under the terms of the GNU General Public License as published by
28498 + * the Free Software Foundation; either version 2 of the License, or
28499 + * (at your option) any later version.
28501 + * This program is distributed in the hope that it will be useful,
28502 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28503 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28504 + * GNU General Public License for more details.
28506 + * You should have received a copy of the GNU General Public License
28507 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28511 + * posix acl operations
28514 +#include <linux/fs.h>
28517 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28519 + struct posix_acl *acl;
28521 + aufs_bindex_t bindex;
28522 + struct inode *h_inode;
28523 + struct super_block *sb;
28526 + sb = inode->i_sb;
28527 + si_read_lock(sb, AuLock_FLUSH);
28528 + ii_read_lock_child(inode);
28529 + if (!(sb->s_flags & SB_POSIXACL))
28532 + bindex = au_ibtop(inode);
28533 + h_inode = au_h_iptr(inode, bindex);
28534 + if (unlikely(!h_inode
28535 + || ((h_inode->i_mode & S_IFMT)
28536 + != (inode->i_mode & S_IFMT)))) {
28537 + err = au_busy_or_stale();
28538 + acl = ERR_PTR(err);
28542 + /* always topmost only */
28543 + acl = get_acl(h_inode, type);
28544 + if (!IS_ERR_OR_NULL(acl))
28545 + set_cached_acl(inode, type, acl);
28548 + ii_read_unlock(inode);
28549 + si_read_unlock(sb);
28551 + AuTraceErrPtr(acl);
28555 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28559 + struct dentry *dentry;
28560 + struct au_sxattr arg = {
28561 + .type = AU_ACL_SET,
28568 + IMustLock(inode);
28570 + if (inode->i_ino == AUFS_ROOT_INO)
28571 + dentry = dget(inode->i_sb->s_root);
28573 + dentry = d_find_alias(inode);
28575 + dentry = d_find_any_alias(inode);
28577 + pr_warn("cannot handle this inode, "
28578 + "please report to aufs-users ML\n");
28584 + ssz = au_sxattr(dentry, inode, &arg);
28589 + set_cached_acl(inode, type, acl);
28595 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28596 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28597 +++ linux/fs/aufs/procfs.c 2019-03-05 12:13:00.142557771 +0100
28599 +// SPDX-License-Identifier: GPL-2.0
28601 + * Copyright (C) 2010-2019 Junjiro R. Okajima
28603 + * This program, aufs is free software; you can redistribute it and/or modify
28604 + * it under the terms of the GNU General Public License as published by
28605 + * the Free Software Foundation; either version 2 of the License, or
28606 + * (at your option) any later version.
28608 + * This program is distributed in the hope that it will be useful,
28609 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28610 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28611 + * GNU General Public License for more details.
28613 + * You should have received a copy of the GNU General Public License
28614 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28618 + * procfs interfaces
28621 +#include <linux/proc_fs.h>
28624 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28626 + struct au_sbinfo *sbinfo;
28628 + sbinfo = file->private_data;
28630 + au_plink_maint_leave(sbinfo);
28631 + kobject_put(&sbinfo->si_kobj);
28637 +static void au_procfs_plm_write_clean(struct file *file)
28639 + struct au_sbinfo *sbinfo;
28641 + sbinfo = file->private_data;
28643 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28646 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28649 + struct super_block *sb;
28650 + struct au_sbinfo *sbinfo;
28651 + struct hlist_bl_node *pos;
28654 + if (unlikely(file->private_data))
28658 + /* don't use au_sbilist_lock() here */
28659 + hlist_bl_lock(&au_sbilist);
28660 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28661 + if (id == sysaufs_si_id(sbinfo)) {
28662 + kobject_get(&sbinfo->si_kobj);
28663 + sb = sbinfo->si_sb;
28666 + hlist_bl_unlock(&au_sbilist);
28669 + if (unlikely(!sb))
28672 + err = au_plink_maint_enter(sb);
28674 + /* keep kobject_get() */
28675 + file->private_data = sbinfo;
28677 + kobject_put(&sbinfo->si_kobj);
28683 + * Accept a valid "si=xxxx" only.
28684 + * Once it is accepted successfully, accept "clean" too.
28686 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28687 + size_t count, loff_t *ppos)
28690 + unsigned long id;
28691 + /* last newline is allowed */
28692 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28695 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28699 + if (unlikely(count > sizeof(buf)))
28702 + err = copy_from_user(buf, ubuf, count);
28703 + if (unlikely(err)) {
28710 + if (!strcmp("clean", buf)) {
28711 + au_procfs_plm_write_clean(file);
28712 + goto out_success;
28713 + } else if (unlikely(strncmp("si=", buf, 3)))
28716 + err = kstrtoul(buf + 3, 16, &id);
28717 + if (unlikely(err))
28720 + err = au_procfs_plm_write_si(file, id);
28721 + if (unlikely(err))
28725 + err = count; /* success */
28730 +static const struct file_operations au_procfs_plm_fop = {
28731 + .write = au_procfs_plm_write,
28732 + .release = au_procfs_plm_release,
28733 + .owner = THIS_MODULE
28736 +/* ---------------------------------------------------------------------- */
28738 +static struct proc_dir_entry *au_procfs_dir;
28740 +void au_procfs_fin(void)
28742 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28743 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28746 +int __init au_procfs_init(void)
28749 + struct proc_dir_entry *entry;
28752 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28753 + if (unlikely(!au_procfs_dir))
28756 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28757 + au_procfs_dir, &au_procfs_plm_fop);
28758 + if (unlikely(!entry))
28762 + goto out; /* success */
28766 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28770 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28771 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28772 +++ linux/fs/aufs/rdu.c 2019-03-05 12:13:00.142557771 +0100
28774 +// SPDX-License-Identifier: GPL-2.0
28776 + * Copyright (C) 2005-2019 Junjiro R. Okajima
28778 + * This program, aufs is free software; you can redistribute it and/or modify
28779 + * it under the terms of the GNU General Public License as published by
28780 + * the Free Software Foundation; either version 2 of the License, or
28781 + * (at your option) any later version.
28783 + * This program is distributed in the hope that it will be useful,
28784 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28785 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28786 + * GNU General Public License for more details.
28788 + * You should have received a copy of the GNU General Public License
28789 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28793 + * readdir in userspace.
28796 +#include <linux/compat.h>
28797 +#include <linux/fs_stack.h>
28798 +#include <linux/security.h>
28801 +/* bits for struct aufs_rdu.flags */
28802 +#define AuRdu_CALLED 1
28803 +#define AuRdu_CONT (1 << 1)
28804 +#define AuRdu_FULL (1 << 2)
28805 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28806 +#define au_fset_rdu(flags, name) \
28807 + do { (flags) |= AuRdu_##name; } while (0)
28808 +#define au_fclr_rdu(flags, name) \
28809 + do { (flags) &= ~AuRdu_##name; } while (0)
28811 +struct au_rdu_arg {
28812 + struct dir_context ctx;
28813 + struct aufs_rdu *rdu;
28814 + union au_rdu_ent_ul ent;
28815 + unsigned long end;
28817 + struct super_block *sb;
28821 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28822 + loff_t offset, u64 h_ino, unsigned int d_type)
28825 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28826 + struct aufs_rdu *rdu = arg->rdu;
28827 + struct au_rdu_ent ent;
28831 + au_fset_rdu(rdu->cookie.flags, CALLED);
28832 + len = au_rdu_len(nlen);
28833 + if (arg->ent.ul + len < arg->end) {
28835 + ent.bindex = rdu->cookie.bindex;
28836 + ent.type = d_type;
28838 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28839 + ent.type = DT_UNKNOWN;
28841 + /* unnecessary to support mmap_sem since this is a dir */
28843 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28845 + if (copy_to_user(arg->ent.e->name, name, nlen))
28847 + /* the terminating NULL */
28848 + if (__put_user(0, arg->ent.e->name + nlen))
28851 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28852 + arg->ent.ul += len;
28856 + au_fset_rdu(rdu->cookie.flags, FULL);
28858 + rdu->tail = arg->ent;
28862 + /* AuTraceErr(err); */
28866 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28870 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28872 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28873 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28875 + if (unlikely(offset != cookie->h_pos))
28881 + au_fclr_rdu(cookie->flags, CALLED);
28883 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28887 + && au_ftest_rdu(cookie->flags, CALLED)
28888 + && !au_ftest_rdu(cookie->flags, FULL));
28889 + cookie->h_pos = h_file->f_pos;
28896 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28899 + aufs_bindex_t bbot;
28900 + struct au_rdu_arg arg = {
28902 + .actor = au_rdu_fill
28905 + struct dentry *dentry;
28906 + struct inode *inode;
28907 + struct file *h_file;
28908 + struct au_rdu_cookie *cookie = &rdu->cookie;
28910 + /* VERIFY_WRITE */
28911 + err = !access_ok(rdu->ent.e, rdu->sz);
28912 + if (unlikely(err)) {
28918 + rdu->tail = rdu->ent;
28921 + arg.ent = rdu->ent;
28922 + arg.end = arg.ent.ul;
28923 + arg.end += rdu->sz;
28926 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28929 + err = security_file_permission(file, MAY_READ);
28931 + if (unlikely(err))
28934 + dentry = file->f_path.dentry;
28935 + inode = d_inode(dentry);
28936 + inode_lock_shared(inode);
28938 + arg.sb = inode->i_sb;
28939 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28940 + if (unlikely(err))
28942 + err = au_alive_dir(dentry);
28943 + if (unlikely(err))
28945 + /* todo: reval? */
28946 + fi_read_lock(file);
28949 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28950 + && cookie->generation != au_figen(file)))
28955 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28957 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28959 + bbot = au_fbtop(file);
28960 + if (cookie->bindex < bbot)
28961 + cookie->bindex = bbot;
28962 + bbot = au_fbbot_dir(file);
28963 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28964 + for (; !err && cookie->bindex <= bbot;
28965 + cookie->bindex++, cookie->h_pos = 0) {
28966 + h_file = au_hf_dir(file, cookie->bindex);
28970 + au_fclr_rdu(cookie->flags, FULL);
28971 + err = au_rdu_do(h_file, &arg);
28973 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28976 + AuDbg("rent %llu\n", rdu->rent);
28978 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28979 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28980 + au_fset_rdu(cookie->flags, CONT);
28981 + cookie->generation = au_figen(file);
28984 + ii_read_lock_child(inode);
28985 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28986 + ii_read_unlock(inode);
28989 + fi_read_unlock(file);
28991 + si_read_unlock(arg.sb);
28993 + inode_unlock_shared(inode);
28999 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
29003 + unsigned long long nent;
29004 + union au_rdu_ent_ul *u;
29005 + struct au_rdu_ent ent;
29006 + struct super_block *sb;
29009 + nent = rdu->nent;
29011 + sb = file->f_path.dentry->d_sb;
29012 + si_read_lock(sb, AuLock_FLUSH);
29013 + while (nent-- > 0) {
29014 + /* unnecessary to support mmap_sem since this is a dir */
29015 + err = copy_from_user(&ent, u->e, sizeof(ent));
29017 + /* VERIFY_WRITE */
29018 + err = !access_ok(&u->e->ino, sizeof(ino));
29019 + if (unlikely(err)) {
29025 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
29027 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
29029 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
29031 + if (unlikely(err)) {
29036 + err = __put_user(ino, &u->e->ino);
29037 + if (unlikely(err)) {
29042 + u->ul += au_rdu_len(ent.nlen);
29044 + si_read_unlock(sb);
29049 +/* ---------------------------------------------------------------------- */
29051 +static int au_rdu_verify(struct aufs_rdu *rdu)
29053 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
29054 + "%llu, b%d, 0x%x, g%u}\n",
29055 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
29057 + rdu->rent, rdu->shwh, rdu->full,
29058 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
29059 + rdu->cookie.generation);
29061 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
29065 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
29069 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29072 + struct aufs_rdu rdu;
29073 + void __user *p = (void __user *)arg;
29075 + err = copy_from_user(&rdu, p, sizeof(rdu));
29076 + if (unlikely(err)) {
29081 + err = au_rdu_verify(&rdu);
29082 + if (unlikely(err))
29086 + case AUFS_CTL_RDU:
29087 + err = au_rdu(file, &rdu);
29088 + if (unlikely(err))
29091 + e = copy_to_user(p, &rdu, sizeof(rdu));
29092 + if (unlikely(e)) {
29097 + case AUFS_CTL_RDU_INO:
29098 + err = au_rdu_ino(file, &rdu);
29102 + /* err = -ENOTTY; */
29111 +#ifdef CONFIG_COMPAT
29112 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29115 + struct aufs_rdu rdu;
29116 + void __user *p = compat_ptr(arg);
29118 + /* todo: get_user()? */
29119 + err = copy_from_user(&rdu, p, sizeof(rdu));
29120 + if (unlikely(err)) {
29125 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29126 + err = au_rdu_verify(&rdu);
29127 + if (unlikely(err))
29131 + case AUFS_CTL_RDU:
29132 + err = au_rdu(file, &rdu);
29133 + if (unlikely(err))
29136 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29137 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29138 + e = copy_to_user(p, &rdu, sizeof(rdu));
29139 + if (unlikely(e)) {
29144 + case AUFS_CTL_RDU_INO:
29145 + err = au_rdu_ino(file, &rdu);
29149 + /* err = -ENOTTY; */
29158 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29159 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29160 +++ linux/fs/aufs/rwsem.h 2019-03-05 12:13:00.142557771 +0100
29162 +/* SPDX-License-Identifier: GPL-2.0 */
29164 + * Copyright (C) 2005-2019 Junjiro R. Okajima
29166 + * This program, aufs is free software; you can redistribute it and/or modify
29167 + * it under the terms of the GNU General Public License as published by
29168 + * the Free Software Foundation; either version 2 of the License, or
29169 + * (at your option) any later version.
29171 + * This program is distributed in the hope that it will be useful,
29172 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29173 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29174 + * GNU General Public License for more details.
29176 + * You should have received a copy of the GNU General Public License
29177 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29181 + * simple read-write semaphore wrappers
29184 +#ifndef __AUFS_RWSEM_H__
29185 +#define __AUFS_RWSEM_H__
29189 +#include "debug.h"
29191 +/* in the future, the name 'au_rwsem' will be totally gone */
29192 +#define au_rwsem rw_semaphore
29194 +/* to debug easier, do not make them inlined functions */
29195 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29196 +/* rwsem_is_locked() is unusable */
29197 +#define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \
29199 + && !lockdep_is_held_type(rw, 1))
29200 +#define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \
29202 + && !lockdep_is_held_type(rw, 0))
29203 +#define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \
29205 + && !lockdep_is_held(rw))
29206 +#define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \
29208 + && lockdep_is_held(rw))
29210 +#define au_rw_init(rw) init_rwsem(rw)
29212 +#define au_rw_init_wlock(rw) do { \
29213 + au_rw_init(rw); \
29214 + down_write(rw); \
29217 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29218 + au_rw_init(rw); \
29219 + down_write_nested(rw, lsc); \
29222 +#define au_rw_read_lock(rw) down_read(rw)
29223 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29224 +#define au_rw_read_unlock(rw) up_read(rw)
29225 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29226 +#define au_rw_write_lock(rw) down_write(rw)
29227 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29228 +#define au_rw_write_unlock(rw) up_write(rw)
29229 +/* why is not _nested version defined? */
29230 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29231 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29233 +#endif /* __KERNEL__ */
29234 +#endif /* __AUFS_RWSEM_H__ */
29235 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29236 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29237 +++ linux/fs/aufs/sbinfo.c 2019-05-06 09:03:04.820143837 +0200
29239 +// SPDX-License-Identifier: GPL-2.0
29241 + * Copyright (C) 2005-2019 Junjiro R. Okajima
29243 + * This program, aufs is free software; you can redistribute it and/or modify
29244 + * it under the terms of the GNU General Public License as published by
29245 + * the Free Software Foundation; either version 2 of the License, or
29246 + * (at your option) any later version.
29248 + * This program is distributed in the hope that it will be useful,
29249 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29250 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29251 + * GNU General Public License for more details.
29253 + * You should have received a copy of the GNU General Public License
29254 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29258 + * superblock private data
29261 +#include <linux/iversion.h>
29265 + * they are necessary regardless sysfs is disabled.
29267 +void au_si_free(struct kobject *kobj)
29270 + struct au_sbinfo *sbinfo;
29271 + char *locked __maybe_unused; /* debug only */
29273 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29274 + for (i = 0; i < AuPlink_NHASH; i++)
29275 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29276 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29278 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29279 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29280 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29281 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29283 + dbgaufs_si_fin(sbinfo);
29284 + au_rw_write_lock(&sbinfo->si_rwsem);
29285 + au_br_free(sbinfo);
29286 + au_rw_write_unlock(&sbinfo->si_rwsem);
29288 + au_kfree_try_rcu(sbinfo->si_branch);
29289 + mutex_destroy(&sbinfo->si_xib_mtx);
29290 + AuRwDestroy(&sbinfo->si_rwsem);
29292 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29293 + /* si_nfiles is waited too */
29294 + au_kfree_rcu(sbinfo);
29297 +int au_si_alloc(struct super_block *sb)
29300 + struct au_sbinfo *sbinfo;
29303 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29304 + if (unlikely(!sbinfo))
29307 + /* will be reallocated separately */
29308 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29309 + if (unlikely(!sbinfo->si_branch))
29312 + err = sysaufs_si_init(sbinfo);
29314 + dbgaufs_si_null(sbinfo);
29315 + err = dbgaufs_si_init(sbinfo);
29316 + if (unlikely(err))
29317 + kobject_put(&sbinfo->si_kobj);
29319 + if (unlikely(err))
29322 + au_nwt_init(&sbinfo->si_nowait);
29323 + au_rw_init_wlock(&sbinfo->si_rwsem);
29325 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29326 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29328 + sbinfo->si_bbot = -1;
29329 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29331 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29332 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29333 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29334 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29336 + au_fhsm_init(sbinfo);
29338 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29340 + sbinfo->si_xino_jiffy = jiffies;
29341 + sbinfo->si_xino_expire
29342 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29343 + mutex_init(&sbinfo->si_xib_mtx);
29344 + /* leave si_xib_last_pindex and si_xib_next_bit */
29346 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29348 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29349 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29350 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29351 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29353 + for (i = 0; i < AuPlink_NHASH; i++)
29354 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29355 + init_waitqueue_head(&sbinfo->si_plink_wq);
29356 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29358 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29360 + /* with getattr by default */
29361 + sbinfo->si_iop_array = aufs_iop;
29363 + /* leave other members for sysaufs and si_mnt. */
29364 + sbinfo->si_sb = sb;
29365 + sb->s_fs_info = sbinfo;
29367 + return 0; /* success */
29370 + au_kfree_try_rcu(sbinfo->si_branch);
29372 + au_kfree_rcu(sbinfo);
29377 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29380 + struct au_branch **brp;
29382 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29385 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29386 + if (unlikely(!sz))
29387 + sz = sizeof(*brp);
29388 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29391 + sbinfo->si_branch = brp;
29398 +/* ---------------------------------------------------------------------- */
29400 +unsigned int au_sigen_inc(struct super_block *sb)
29402 + unsigned int gen;
29403 + struct inode *inode;
29405 + SiMustWriteLock(sb);
29407 + gen = ++au_sbi(sb)->si_generation;
29408 + au_update_digen(sb->s_root);
29409 + inode = d_inode(sb->s_root);
29410 + au_update_iigen(inode, /*half*/0);
29411 + inode_inc_iversion(inode);
29415 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29417 + aufs_bindex_t br_id;
29419 + struct au_sbinfo *sbinfo;
29421 + SiMustWriteLock(sb);
29423 + sbinfo = au_sbi(sb);
29424 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29425 + br_id = ++sbinfo->si_last_br_id;
29426 + AuDebugOn(br_id < 0);
29427 + if (br_id && au_br_index(sb, br_id) < 0)
29434 +/* ---------------------------------------------------------------------- */
29436 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29437 +int si_read_lock(struct super_block *sb, int flags)
29442 + if (au_ftest_lock(flags, FLUSH))
29443 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29445 + si_noflush_read_lock(sb);
29446 + err = au_plink_maint(sb, flags);
29447 + if (unlikely(err))
29448 + si_read_unlock(sb);
29453 +int si_write_lock(struct super_block *sb, int flags)
29457 + if (au_ftest_lock(flags, FLUSH))
29458 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29460 + si_noflush_write_lock(sb);
29461 + err = au_plink_maint(sb, flags);
29462 + if (unlikely(err))
29463 + si_write_unlock(sb);
29468 +/* dentry and super_block lock. call at entry point */
29469 +int aufs_read_lock(struct dentry *dentry, int flags)
29472 + struct super_block *sb;
29474 + sb = dentry->d_sb;
29475 + err = si_read_lock(sb, flags);
29476 + if (unlikely(err))
29479 + if (au_ftest_lock(flags, DW))
29480 + di_write_lock_child(dentry);
29482 + di_read_lock_child(dentry, flags);
29484 + if (au_ftest_lock(flags, GEN)) {
29485 + err = au_digen_test(dentry, au_sigen(sb));
29486 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29487 + AuDebugOn(!err && au_dbrange_test(dentry));
29489 + err = au_dbrange_test(dentry);
29490 + if (unlikely(err))
29491 + aufs_read_unlock(dentry, flags);
29498 +void aufs_read_unlock(struct dentry *dentry, int flags)
29500 + if (au_ftest_lock(flags, DW))
29501 + di_write_unlock(dentry);
29503 + di_read_unlock(dentry, flags);
29504 + si_read_unlock(dentry->d_sb);
29507 +void aufs_write_lock(struct dentry *dentry)
29509 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29510 + di_write_lock_child(dentry);
29513 +void aufs_write_unlock(struct dentry *dentry)
29515 + di_write_unlock(dentry);
29516 + si_write_unlock(dentry->d_sb);
29519 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29522 + unsigned int sigen;
29523 + struct super_block *sb;
29526 + err = si_read_lock(sb, flags);
29527 + if (unlikely(err))
29530 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29532 + if (au_ftest_lock(flags, GEN)) {
29533 + sigen = au_sigen(sb);
29534 + err = au_digen_test(d1, sigen);
29535 + AuDebugOn(!err && au_dbrange_test(d1));
29537 + err = au_digen_test(d2, sigen);
29538 + AuDebugOn(!err && au_dbrange_test(d2));
29540 + if (unlikely(err))
29541 + aufs_read_and_write_unlock2(d1, d2);
29548 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29550 + di_write_unlock2(d1, d2);
29551 + si_read_unlock(d1->d_sb);
29553 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29554 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29555 +++ linux/fs/aufs/super.c 2019-05-06 09:03:04.820143837 +0200
29557 +// SPDX-License-Identifier: GPL-2.0
29559 + * Copyright (C) 2005-2019 Junjiro R. Okajima
29561 + * This program, aufs is free software; you can redistribute it and/or modify
29562 + * it under the terms of the GNU General Public License as published by
29563 + * the Free Software Foundation; either version 2 of the License, or
29564 + * (at your option) any later version.
29566 + * This program is distributed in the hope that it will be useful,
29567 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29568 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29569 + * GNU General Public License for more details.
29571 + * You should have received a copy of the GNU General Public License
29572 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29576 + * mount and super_block operations
29579 +#include <linux/iversion.h>
29580 +#include <linux/mm.h>
29581 +#include <linux/seq_file.h>
29582 +#include <linux/statfs.h>
29583 +#include <linux/vmalloc.h>
29587 + * super_operations
29589 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29591 + struct au_icntnr *c;
29593 + c = au_cache_alloc_icntnr();
29595 + au_icntnr_init(c);
29596 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29597 + c->iinfo.ii_hinode = NULL;
29598 + return &c->vfs_inode;
29603 +static void aufs_destroy_inode_cb(struct rcu_head *head)
29605 + struct inode *inode = container_of(head, struct inode, i_rcu);
29607 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29610 +static void aufs_destroy_inode(struct inode *inode)
29612 + if (!au_is_bad_inode(inode))
29613 + au_iinfo_fin(inode);
29614 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
29617 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29619 + struct inode *inode;
29622 + inode = iget_locked(sb, ino);
29623 + if (unlikely(!inode)) {
29624 + inode = ERR_PTR(-ENOMEM);
29627 + if (!(inode->i_state & I_NEW))
29630 + err = au_xigen_new(inode);
29632 + err = au_iinfo_init(inode);
29634 + inode_inc_iversion(inode);
29636 + iget_failed(inode);
29637 + inode = ERR_PTR(err);
29641 + /* never return NULL */
29642 + AuDebugOn(!inode);
29643 + AuTraceErrPtr(inode);
29647 +/* lock free root dinfo */
29648 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29651 + aufs_bindex_t bindex, bbot;
29652 + struct path path;
29653 + struct au_hdentry *hdp;
29654 + struct au_branch *br;
29655 + au_br_perm_str_t perm;
29658 + bbot = au_sbbot(sb);
29660 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29661 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29662 + br = au_sbr(sb, bindex);
29663 + path.mnt = au_br_mnt(br);
29664 + path.dentry = hdp->hd_dentry;
29665 + err = au_seq_path(seq, &path);
29667 + au_optstr_br_perm(&perm, br->br_perm);
29668 + seq_printf(seq, "=%s", perm.a);
29669 + if (bindex != bbot)
29670 + seq_putc(seq, ':');
29673 + if (unlikely(err || seq_has_overflowed(seq)))
29679 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29680 + const char *append)
29685 + while (*pat != ':')
29688 + strcpy(p, append);
29689 + AuDebugOn(strlen(fmt) >= len);
29692 +static void au_show_wbr_create(struct seq_file *m, int v,
29693 + struct au_sbinfo *sbinfo)
29697 + struct au_wbr_mfs *mfs;
29699 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29701 + seq_puts(m, ",create=");
29702 + pat = au_optstr_wbr_create(v);
29703 + mfs = &sbinfo->si_wbr_mfs;
29705 + case AuWbrCreate_TDP:
29706 + case AuWbrCreate_RR:
29707 + case AuWbrCreate_MFS:
29708 + case AuWbrCreate_PMFS:
29709 + seq_puts(m, pat);
29711 + case AuWbrCreate_MFSRR:
29712 + case AuWbrCreate_TDMFS:
29713 + case AuWbrCreate_PMFSRR:
29714 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29715 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29717 + case AuWbrCreate_MFSV:
29718 + case AuWbrCreate_PMFSV:
29719 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29720 + seq_printf(m, fmt,
29721 + jiffies_to_msecs(mfs->mfs_expire)
29724 + case AuWbrCreate_MFSRRV:
29725 + case AuWbrCreate_TDMFSV:
29726 + case AuWbrCreate_PMFSRRV:
29727 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29728 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29729 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29736 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29738 +#ifdef CONFIG_SYSFS
29742 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29743 + aufs_bindex_t bindex, brid;
29744 + struct qstr *name;
29746 + struct dentry *d, *h_root;
29747 + struct au_branch *br;
29749 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29752 + f = au_sbi(sb)->si_xib;
29756 + /* stop printing the default xino path on the first writable branch */
29758 + bindex = au_xi_root(sb, f->f_path.dentry);
29759 + if (bindex >= 0) {
29760 + br = au_sbr_sb(sb, bindex);
29761 + h_root = au_br_dentry(br);
29764 + d = f->f_path.dentry;
29765 + name = &d->d_name;
29766 + /* safe ->d_parent because the file is unlinked */
29767 + if (d->d_parent == h_root
29768 + && name->len == len
29769 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29772 + seq_puts(seq, ",xino=");
29773 + err = au_xino_path(seq, f);
29780 +/* seq_file will re-call me in case of too long string */
29781 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29784 + unsigned int mnt_flags, v;
29785 + struct super_block *sb;
29786 + struct au_sbinfo *sbinfo;
29788 +#define AuBool(name, str) do { \
29789 + v = au_opt_test(mnt_flags, name); \
29790 + if (v != au_opt_test(AuOpt_Def, name)) \
29791 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29794 +#define AuStr(name, str) do { \
29795 + v = mnt_flags & AuOptMask_##name; \
29796 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29797 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29800 +#define AuUInt(name, str, val) do { \
29801 + if (val != AUFS_##name##_DEF) \
29802 + seq_printf(m, "," #str "=%u", val); \
29805 + sb = dentry->d_sb;
29806 + if (sb->s_flags & SB_POSIXACL)
29807 + seq_puts(m, ",acl");
29809 + if (sb->s_flags & SB_I_VERSION)
29810 + seq_puts(m, ",i_version");
29813 + /* lock free root dinfo */
29814 + si_noflush_read_lock(sb);
29815 + sbinfo = au_sbi(sb);
29816 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29818 + mnt_flags = au_mntflags(sb);
29819 + if (au_opt_test(mnt_flags, XINO)) {
29820 + err = au_show_xino(m, sb);
29821 + if (unlikely(err))
29824 + seq_puts(m, ",noxino");
29826 + AuBool(TRUNC_XINO, trunc_xino);
29827 + AuStr(UDBA, udba);
29828 + AuBool(SHWH, shwh);
29829 + AuBool(PLINK, plink);
29830 + AuBool(DIO, dio);
29831 + AuBool(DIRPERM1, dirperm1);
29833 + v = sbinfo->si_wbr_create;
29834 + if (v != AuWbrCreate_Def)
29835 + au_show_wbr_create(m, v, sbinfo);
29837 + v = sbinfo->si_wbr_copyup;
29838 + if (v != AuWbrCopyup_Def)
29839 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29841 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29842 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29843 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29845 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29847 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29848 + AuUInt(RDCACHE, rdcache, v);
29850 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29851 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29853 + au_fhsm_show(m, sbinfo);
29855 + AuBool(DIRREN, dirren);
29856 + AuBool(SUM, sum);
29857 + /* AuBool(SUM_W, wsum); */
29858 + AuBool(WARN_PERM, warn_perm);
29859 + AuBool(VERBOSE, verbose);
29862 + /* be sure to print "br:" last */
29863 + if (!sysaufs_brs) {
29864 + seq_puts(m, ",br:");
29865 + au_show_brs(m, sb);
29867 + si_read_unlock(sb);
29875 +/* ---------------------------------------------------------------------- */
29877 +/* sum mode which returns the summation for statfs(2) */
29879 +static u64 au_add_till_max(u64 a, u64 b)
29887 + return ULLONG_MAX;
29890 +static u64 au_mul_till_max(u64 a, long mul)
29898 + return ULLONG_MAX;
29901 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29904 + long bsize, factor;
29905 + u64 blocks, bfree, bavail, files, ffree;
29906 + aufs_bindex_t bbot, bindex, i;
29907 + unsigned char shared;
29908 + struct path h_path;
29909 + struct super_block *h_sb;
29912 + bsize = LONG_MAX;
29918 + bbot = au_sbbot(sb);
29919 + for (bindex = 0; bindex <= bbot; bindex++) {
29920 + h_path.mnt = au_sbr_mnt(sb, bindex);
29921 + h_sb = h_path.mnt->mnt_sb;
29923 + for (i = 0; !shared && i < bindex; i++)
29924 + shared = (au_sbr_sb(sb, i) == h_sb);
29928 + /* sb->s_root for NFS is unreliable */
29929 + h_path.dentry = h_path.mnt->mnt_root;
29930 + err = vfs_statfs(&h_path, buf);
29931 + if (unlikely(err))
29934 + if (bsize > buf->f_bsize) {
29936 + * we will reduce bsize, so we have to expand blocks
29937 + * etc. to match them again
29939 + factor = (bsize / buf->f_bsize);
29940 + blocks = au_mul_till_max(blocks, factor);
29941 + bfree = au_mul_till_max(bfree, factor);
29942 + bavail = au_mul_till_max(bavail, factor);
29943 + bsize = buf->f_bsize;
29946 + factor = (buf->f_bsize / bsize);
29947 + blocks = au_add_till_max(blocks,
29948 + au_mul_till_max(buf->f_blocks, factor));
29949 + bfree = au_add_till_max(bfree,
29950 + au_mul_till_max(buf->f_bfree, factor));
29951 + bavail = au_add_till_max(bavail,
29952 + au_mul_till_max(buf->f_bavail, factor));
29953 + files = au_add_till_max(files, buf->f_files);
29954 + ffree = au_add_till_max(ffree, buf->f_ffree);
29957 + buf->f_bsize = bsize;
29958 + buf->f_blocks = blocks;
29959 + buf->f_bfree = bfree;
29960 + buf->f_bavail = bavail;
29961 + buf->f_files = files;
29962 + buf->f_ffree = ffree;
29963 + buf->f_frsize = 0;
29969 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29972 + struct path h_path;
29973 + struct super_block *sb;
29975 + /* lock free root dinfo */
29976 + sb = dentry->d_sb;
29977 + si_noflush_read_lock(sb);
29978 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29979 + /* sb->s_root for NFS is unreliable */
29980 + h_path.mnt = au_sbr_mnt(sb, 0);
29981 + h_path.dentry = h_path.mnt->mnt_root;
29982 + err = vfs_statfs(&h_path, buf);
29984 + err = au_statfs_sum(sb, buf);
29985 + si_read_unlock(sb);
29988 + buf->f_type = AUFS_SUPER_MAGIC;
29989 + buf->f_namelen = AUFS_MAX_NAMELEN;
29990 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29992 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29997 +/* ---------------------------------------------------------------------- */
29999 +static int aufs_sync_fs(struct super_block *sb, int wait)
30002 + aufs_bindex_t bbot, bindex;
30003 + struct au_branch *br;
30004 + struct super_block *h_sb;
30007 + si_noflush_read_lock(sb);
30008 + bbot = au_sbbot(sb);
30009 + for (bindex = 0; bindex <= bbot; bindex++) {
30010 + br = au_sbr(sb, bindex);
30011 + if (!au_br_writable(br->br_perm))
30014 + h_sb = au_sbr_sb(sb, bindex);
30015 + e = vfsub_sync_filesystem(h_sb, wait);
30016 + if (unlikely(e && !err))
30018 + /* go on even if an error happens */
30020 + si_read_unlock(sb);
30025 +/* ---------------------------------------------------------------------- */
30027 +/* final actions when unmounting a file system */
30028 +static void aufs_put_super(struct super_block *sb)
30030 + struct au_sbinfo *sbinfo;
30032 + sbinfo = au_sbi(sb);
30034 + kobject_put(&sbinfo->si_kobj);
30037 +/* ---------------------------------------------------------------------- */
30039 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30040 + struct super_block *sb, void *arg)
30043 + unsigned long long n, sz;
30050 + if (*hint > ULLONG_MAX / sizeof(array)) {
30051 + array = ERR_PTR(-EMFILE);
30052 + pr_err("hint %llu\n", *hint);
30056 + sz = sizeof(array) * *hint;
30057 + array = kzalloc(sz, GFP_NOFS);
30058 + if (unlikely(!array))
30059 + array = vzalloc(sz);
30060 + if (unlikely(!array)) {
30061 + array = ERR_PTR(-ENOMEM);
30065 + n = cb(sb, array, *hint, arg);
30066 + AuDebugOn(n > *hint);
30073 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
30074 + unsigned long long max __maybe_unused,
30077 + unsigned long long n;
30078 + struct inode **p, *inode;
30079 + struct list_head *head;
30084 + spin_lock(&sb->s_inode_list_lock);
30085 + list_for_each_entry(inode, head, i_sb_list) {
30086 + if (!au_is_bad_inode(inode)
30087 + && au_ii(inode)->ii_btop >= 0) {
30088 + spin_lock(&inode->i_lock);
30089 + if (atomic_read(&inode->i_count)) {
30093 + AuDebugOn(n > max);
30095 + spin_unlock(&inode->i_lock);
30098 + spin_unlock(&sb->s_inode_list_lock);
30103 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
30105 + struct au_sbinfo *sbi;
30107 + sbi = au_sbi(sb);
30108 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
30109 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
30112 +void au_iarray_free(struct inode **a, unsigned long long max)
30114 + unsigned long long ull;
30116 + for (ull = 0; ull < max; ull++)
30121 +/* ---------------------------------------------------------------------- */
30124 + * refresh dentry and inode at remount time.
30126 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30127 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30128 + struct dentry *parent)
30132 + di_write_lock_child(dentry);
30133 + di_read_lock_parent(parent, AuLock_IR);
30134 + err = au_refresh_dentry(dentry, parent);
30135 + if (!err && dir_flags)
30136 + au_hn_reset(d_inode(dentry), dir_flags);
30137 + di_read_unlock(parent, AuLock_IR);
30138 + di_write_unlock(dentry);
30143 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30144 + struct au_sbinfo *sbinfo,
30145 + const unsigned int dir_flags, unsigned int do_idop)
30148 + struct dentry *parent;
30151 + parent = dget_parent(dentry);
30152 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30153 + if (d_really_is_positive(dentry)) {
30154 + if (!d_is_dir(dentry))
30155 + err = au_do_refresh(dentry, /*dir_flags*/0,
30158 + err = au_do_refresh(dentry, dir_flags, parent);
30159 + if (unlikely(err))
30160 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30163 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30164 + AuDbgDentry(dentry);
30170 + au_refresh_dop(dentry, /*force_reval*/0);
30172 + au_refresh_dop(dentry, /*force_reval*/1);
30178 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30180 + int err, i, j, ndentry, e;
30181 + unsigned int sigen;
30182 + struct au_dcsub_pages dpages;
30183 + struct au_dpage *dpage;
30184 + struct dentry **dentries, *d;
30185 + struct au_sbinfo *sbinfo;
30186 + struct dentry *root = sb->s_root;
30187 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30190 + au_refresh_dop(root, /*force_reval*/0);
30192 + err = au_dpages_init(&dpages, GFP_NOFS);
30193 + if (unlikely(err))
30195 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30196 + if (unlikely(err))
30199 + sigen = au_sigen(sb);
30200 + sbinfo = au_sbi(sb);
30201 + for (i = 0; i < dpages.ndpage; i++) {
30202 + dpage = dpages.dpages + i;
30203 + dentries = dpage->dentries;
30204 + ndentry = dpage->ndentry;
30205 + for (j = 0; j < ndentry; j++) {
30207 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30209 + if (unlikely(e && !err))
30211 + /* go on even err */
30216 + au_dpages_free(&dpages);
30221 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30224 + unsigned int sigen;
30225 + unsigned long long max, ull;
30226 + struct inode *inode, **array;
30228 + array = au_iarray_alloc(sb, &max);
30229 + err = PTR_ERR(array);
30230 + if (IS_ERR(array))
30234 + sigen = au_sigen(sb);
30235 + for (ull = 0; ull < max; ull++) {
30236 + inode = array[ull];
30237 + if (unlikely(!inode))
30241 + ii_write_lock_child(inode);
30242 + if (au_iigen(inode, NULL) != sigen) {
30243 + e = au_refresh_hinode_self(inode);
30244 + if (unlikely(e)) {
30245 + au_refresh_iop(inode, /*force_getattr*/1);
30246 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30249 + /* go on even if err */
30252 + if (!e && do_idop)
30253 + au_refresh_iop(inode, /*force_getattr*/0);
30254 + ii_write_unlock(inode);
30257 + au_iarray_free(array, max);
30263 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30266 + unsigned int udba;
30267 + aufs_bindex_t bindex, bbot;
30268 + struct dentry *root;
30269 + struct inode *inode;
30270 + struct au_branch *br;
30271 + struct au_sbinfo *sbi;
30273 + au_sigen_inc(sb);
30274 + sbi = au_sbi(sb);
30275 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30277 + root = sb->s_root;
30278 + DiMustNoWaiters(root);
30279 + inode = d_inode(root);
30280 + IiMustNoWaiters(inode);
30282 + udba = au_opt_udba(sb);
30283 + bbot = au_sbbot(sb);
30284 + for (bindex = 0; bindex <= bbot; bindex++) {
30285 + br = au_sbr(sb, bindex);
30286 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30287 + if (unlikely(err))
30288 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30290 + /* go on even if err */
30292 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30295 + if (au_ftest_si(sbi, NO_DREVAL)) {
30296 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30297 + sb->s_d_op = &aufs_dop_noreval;
30298 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30299 + sbi->si_iop_array = aufs_iop_nogetattr;
30301 + AuDebugOn(sb->s_d_op == &aufs_dop);
30302 + sb->s_d_op = &aufs_dop;
30303 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30304 + sbi->si_iop_array = aufs_iop;
30306 + pr_info("reset to %ps and %ps\n",
30307 + sb->s_d_op, sbi->si_iop_array);
30310 + di_write_unlock(root);
30311 + err = au_refresh_d(sb, do_idop);
30312 + e = au_refresh_i(sb, do_idop);
30313 + if (unlikely(e && !err))
30315 + /* aufs_write_lock() calls ..._child() */
30316 + di_write_lock_child(root);
30318 + au_cpup_attr_all(inode, /*force*/1);
30320 + if (unlikely(err))
30321 + AuIOErr("refresh failed, ignored, %d\n", err);
30324 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30325 +static int cvt_err(int err)
30339 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30342 + unsigned int mntflags;
30343 + struct au_opts opts = {
30346 + struct dentry *root;
30347 + struct inode *inode;
30348 + struct au_sbinfo *sbinfo;
30351 + root = sb->s_root;
30352 + if (!data || !*data) {
30353 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30355 + di_write_lock_child(root);
30356 + err = au_opts_verify(sb, *flags, /*pending*/0);
30357 + aufs_write_unlock(root);
30363 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30364 + if (unlikely(!opts.opt))
30366 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30367 + opts.flags = AuOpts_REMOUNT;
30368 + opts.sb_flags = *flags;
30370 + /* parse it before aufs lock */
30371 + err = au_opts_parse(sb, data, &opts);
30372 + if (unlikely(err))
30375 + sbinfo = au_sbi(sb);
30376 + inode = d_inode(root);
30377 + inode_lock(inode);
30378 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30379 + if (unlikely(err))
30381 + di_write_lock_child(root);
30383 + /* au_opts_remount() may return an error */
30384 + err = au_opts_remount(sb, &opts);
30385 + au_opts_free(&opts);
30387 + if (au_ftest_opts(opts.flags, REFRESH))
30388 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30390 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30391 + mntflags = au_mntflags(sb);
30392 + do_dx = !!au_opt_test(mntflags, DIO);
30393 + au_dy_arefresh(do_dx);
30396 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30397 + aufs_write_unlock(root);
30400 + inode_unlock(inode);
30402 + free_page((unsigned long)opts.opt);
30404 + err = cvt_err(err);
30409 +static const struct super_operations aufs_sop = {
30410 + .alloc_inode = aufs_alloc_inode,
30411 + .destroy_inode = aufs_destroy_inode,
30412 + /* always deleting, no clearing */
30413 + .drop_inode = generic_delete_inode,
30414 + .show_options = aufs_show_options,
30415 + .statfs = aufs_statfs,
30416 + .put_super = aufs_put_super,
30417 + .sync_fs = aufs_sync_fs,
30418 + .remount_fs = aufs_remount_fs
30421 +/* ---------------------------------------------------------------------- */
30423 +static int alloc_root(struct super_block *sb)
30426 + struct inode *inode;
30427 + struct dentry *root;
30430 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30431 + err = PTR_ERR(inode);
30432 + if (IS_ERR(inode))
30435 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30436 + inode->i_fop = &aufs_dir_fop;
30437 + inode->i_mode = S_IFDIR;
30438 + set_nlink(inode, 2);
30439 + unlock_new_inode(inode);
30441 + root = d_make_root(inode);
30442 + if (unlikely(!root))
30444 + err = PTR_ERR(root);
30445 + if (IS_ERR(root))
30448 + err = au_di_init(root);
30450 + sb->s_root = root;
30451 + return 0; /* success */
30459 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30460 + int silent __maybe_unused)
30463 + struct au_opts opts = {
30466 + struct au_sbinfo *sbinfo;
30467 + struct dentry *root;
30468 + struct inode *inode;
30469 + char *arg = raw_data;
30471 + if (unlikely(!arg || !*arg)) {
30473 + pr_err("no arg\n");
30478 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30479 + if (unlikely(!opts.opt))
30481 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30482 + opts.sb_flags = sb->s_flags;
30484 + err = au_si_alloc(sb);
30485 + if (unlikely(err))
30487 + sbinfo = au_sbi(sb);
30489 + /* all timestamps always follow the ones on the branch */
30490 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30491 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30492 + sb->s_op = &aufs_sop;
30493 + sb->s_d_op = &aufs_dop;
30494 + sb->s_magic = AUFS_SUPER_MAGIC;
30495 + sb->s_maxbytes = 0;
30496 + sb->s_stack_depth = 1;
30497 + au_export_init(sb);
30498 + au_xattr_init(sb);
30500 + err = alloc_root(sb);
30501 + if (unlikely(err)) {
30502 + si_write_unlock(sb);
30505 + root = sb->s_root;
30506 + inode = d_inode(root);
30509 + * actually we can parse options regardless aufs lock here.
30510 + * but at remount time, parsing must be done before aufs lock.
30511 + * so we follow the same rule.
30513 + ii_write_lock_parent(inode);
30514 + aufs_write_unlock(root);
30515 + err = au_opts_parse(sb, arg, &opts);
30516 + if (unlikely(err))
30519 + /* lock vfs_inode first, then aufs. */
30520 + inode_lock(inode);
30521 + aufs_write_lock(root);
30522 + err = au_opts_mount(sb, &opts);
30523 + au_opts_free(&opts);
30524 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30525 + sb->s_d_op = &aufs_dop_noreval;
30526 + pr_info("%ps\n", sb->s_d_op);
30527 + au_refresh_dop(root, /*force_reval*/0);
30528 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30529 + au_refresh_iop(inode, /*force_getattr*/0);
30531 + aufs_write_unlock(root);
30532 + inode_unlock(inode);
30534 + goto out_opts; /* success */
30538 + sb->s_root = NULL;
30540 + kobject_put(&sbinfo->si_kobj);
30541 + sb->s_fs_info = NULL;
30543 + free_page((unsigned long)opts.opt);
30546 + err = cvt_err(err);
30551 +/* ---------------------------------------------------------------------- */
30553 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30554 + const char *dev_name __maybe_unused,
30557 + struct dentry *root;
30559 + /* all timestamps always follow the ones on the branch */
30560 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30561 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30562 + if (IS_ERR(root))
30565 + au_sbilist_add(root->d_sb);
30571 +static void aufs_kill_sb(struct super_block *sb)
30573 + struct au_sbinfo *sbinfo;
30575 + sbinfo = au_sbi(sb);
30577 + au_sbilist_del(sb);
30578 + aufs_write_lock(sb->s_root);
30580 + if (sbinfo->si_wbr_create_ops->fin)
30581 + sbinfo->si_wbr_create_ops->fin(sb);
30582 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30583 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30584 + au_remount_refresh(sb, /*do_idop*/0);
30586 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30587 + au_plink_put(sb, /*verbose*/1);
30589 + au_dr_opt_flush(sb);
30590 + sbinfo->si_sb = NULL;
30591 + aufs_write_unlock(sb->s_root);
30592 + au_nwt_flush(&sbinfo->si_nowait);
30594 + kill_anon_super(sb);
30597 +struct file_system_type aufs_fs_type = {
30598 + .name = AUFS_FSTYPE,
30599 + /* a race between rename and others */
30600 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30601 + .mount = aufs_mount,
30602 + .kill_sb = aufs_kill_sb,
30603 + /* no need to __module_get() and module_put(). */
30604 + .owner = THIS_MODULE,
30606 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30607 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30608 +++ linux/fs/aufs/super.h 2019-03-05 12:13:00.142557771 +0100
30610 +/* SPDX-License-Identifier: GPL-2.0 */
30612 + * Copyright (C) 2005-2019 Junjiro R. Okajima
30614 + * This program, aufs is free software; you can redistribute it and/or modify
30615 + * it under the terms of the GNU General Public License as published by
30616 + * the Free Software Foundation; either version 2 of the License, or
30617 + * (at your option) any later version.
30619 + * This program is distributed in the hope that it will be useful,
30620 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30621 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30622 + * GNU General Public License for more details.
30624 + * You should have received a copy of the GNU General Public License
30625 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30629 + * super_block operations
30632 +#ifndef __AUFS_SUPER_H__
30633 +#define __AUFS_SUPER_H__
30637 +#include <linux/fs.h>
30638 +#include <linux/kobject.h>
30641 +#include "rwsem.h"
30644 +/* policies to select one among multiple writable branches */
30645 +struct au_wbr_copyup_operations {
30646 + int (*copyup)(struct dentry *dentry);
30649 +#define AuWbr_DIR 1 /* target is a dir */
30650 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30652 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30653 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30654 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30656 +struct au_wbr_create_operations {
30657 + int (*create)(struct dentry *dentry, unsigned int flags);
30658 + int (*init)(struct super_block *sb);
30659 + int (*fin)(struct super_block *sb);
30662 +struct au_wbr_mfs {
30663 + struct mutex mfs_lock; /* protect this structure */
30664 + unsigned long mfs_jiffy;
30665 + unsigned long mfs_expire;
30666 + aufs_bindex_t mfs_bindex;
30668 + unsigned long long mfsrr_bytes;
30669 + unsigned long long mfsrr_watermark;
30672 +#define AuPlink_NHASH 100
30673 +static inline int au_plink_hash(ino_t ino)
30675 + return ino % AuPlink_NHASH;
30678 +/* File-based Hierarchical Storage Management */
30680 +#ifdef CONFIG_AUFS_FHSM
30681 + /* allow only one process who can receive the notification */
30682 + spinlock_t fhsm_spin;
30684 + wait_queue_head_t fhsm_wqh;
30685 + atomic_t fhsm_readable;
30687 + /* these are protected by si_rwsem */
30688 + unsigned long fhsm_expire;
30689 + aufs_bindex_t fhsm_bottom;
30694 +struct au_sbinfo {
30695 + /* nowait tasks in the system-wide workqueue */
30696 + struct au_nowait_tasks si_nowait;
30699 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30700 + * rwsem for au_sbinfo is necessary.
30702 + struct au_rwsem si_rwsem;
30705 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30708 + au_lcnt_t si_ninodes, si_nfiles;
30710 + /* branch management */
30711 + unsigned int si_generation;
30713 + /* see AuSi_ flags */
30714 + unsigned char au_si_status;
30716 + aufs_bindex_t si_bbot;
30718 + /* dirty trick to keep br_id plus */
30719 + unsigned int si_last_br_id :
30720 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30721 + struct au_branch **si_branch;
30723 + /* policy to select a writable branch */
30724 + unsigned char si_wbr_copyup;
30725 + unsigned char si_wbr_create;
30726 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30727 + struct au_wbr_create_operations *si_wbr_create_ops;
30729 + /* round robin */
30730 + atomic_t si_wbr_rr_next;
30732 + /* most free space */
30733 + struct au_wbr_mfs si_wbr_mfs;
30735 + /* File-based Hierarchical Storage Management */
30736 + struct au_fhsm si_fhsm;
30738 + /* mount flags */
30739 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30740 + unsigned int si_mntflags;
30742 + /* external inode number (bitmap and translation table) */
30743 + vfs_readf_t si_xread;
30744 + vfs_writef_t si_xwrite;
30745 + loff_t si_ximaxent; /* max entries in a xino */
30747 + struct file *si_xib;
30748 + struct mutex si_xib_mtx; /* protect xib members */
30749 + unsigned long *si_xib_buf;
30750 + unsigned long si_xib_last_pindex;
30751 + int si_xib_next_bit;
30753 + unsigned long si_xino_jiffy;
30754 + unsigned long si_xino_expire;
30755 + /* reserved for future use */
30756 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30758 +#ifdef CONFIG_AUFS_EXPORT
30759 + /* i_generation */
30760 + /* todo: make xigen file an array to support many inode numbers */
30761 + struct file *si_xigen;
30762 + atomic_t si_xigen_next;
30765 + /* dirty trick to support atomic_open */
30766 + struct hlist_bl_head si_aopen;
30768 + /* vdir parameters */
30769 + unsigned long si_rdcache; /* max cache time in jiffies */
30770 + unsigned int si_rdblk; /* deblk size */
30771 + unsigned int si_rdhash; /* hash size */
30774 + * If the number of whiteouts are larger than si_dirwh, leave all of
30775 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30776 + * future fsck.aufs or kernel thread will remove them later.
30777 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30779 + unsigned int si_dirwh;
30781 + /* pseudo_link list */
30782 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30783 + wait_queue_head_t si_plink_wq;
30784 + spinlock_t si_plink_maint_lock;
30785 + pid_t si_plink_maint_pid;
30788 + struct hlist_bl_head si_files;
30790 + /* with/without getattr, brother of sb->s_d_op */
30791 + struct inode_operations *si_iop_array;
30794 + * sysfs and lifetime management.
30795 + * this is not a small structure and it may be a waste of memory in case
30796 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30797 + * but using sysfs is majority.
30799 + struct kobject si_kobj;
30800 +#ifdef CONFIG_DEBUG_FS
30801 + struct dentry *si_dbgaufs;
30802 + struct dentry *si_dbgaufs_plink;
30803 + struct dentry *si_dbgaufs_xib;
30804 +#ifdef CONFIG_AUFS_EXPORT
30805 + struct dentry *si_dbgaufs_xigen;
30809 +#ifdef CONFIG_AUFS_SBILIST
30810 + struct hlist_bl_node si_list;
30813 + /* dirty, necessary for unmounting, sysfs and sysrq */
30814 + struct super_block *si_sb;
30817 +/* sbinfo status flags */
30819 + * set true when refresh_dirs() failed at remount time.
30820 + * then try refreshing dirs at access time again.
30821 + * if it is false, refreshing dirs at access time is unnecessary
30823 +#define AuSi_FAILED_REFRESH_DIR 1
30824 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30825 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30827 +#ifndef CONFIG_AUFS_FHSM
30829 +#define AuSi_FHSM 0
30832 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30833 + unsigned int flag)
30835 + AuRwMustAnyLock(&sbi->si_rwsem);
30836 + return sbi->au_si_status & flag;
30838 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30839 +#define au_fset_si(sbinfo, name) do { \
30840 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30841 + (sbinfo)->au_si_status |= AuSi_##name; \
30843 +#define au_fclr_si(sbinfo, name) do { \
30844 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30845 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30848 +/* ---------------------------------------------------------------------- */
30850 +/* policy to select one among writable branches */
30851 +#define AuWbrCopyup(sbinfo, ...) \
30852 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30853 +#define AuWbrCreate(sbinfo, ...) \
30854 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30856 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30857 +#define AuLock_DW 1 /* write-lock dentry */
30858 +#define AuLock_IR (1 << 1) /* read-lock inode */
30859 +#define AuLock_IW (1 << 2) /* write-lock inode */
30860 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30861 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30862 + /* except RENAME_EXCHANGE */
30863 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30864 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30865 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30866 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30867 +#define au_fset_lock(flags, name) \
30868 + do { (flags) |= AuLock_##name; } while (0)
30869 +#define au_fclr_lock(flags, name) \
30870 + do { (flags) &= ~AuLock_##name; } while (0)
30872 +/* ---------------------------------------------------------------------- */
30875 +extern struct file_system_type aufs_fs_type;
30876 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30877 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30878 + unsigned long long max, void *arg);
30879 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30880 + struct super_block *sb, void *arg);
30881 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30882 +void au_iarray_free(struct inode **a, unsigned long long max);
30885 +void au_si_free(struct kobject *kobj);
30886 +int au_si_alloc(struct super_block *sb);
30887 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30889 +unsigned int au_sigen_inc(struct super_block *sb);
30890 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30892 +int si_read_lock(struct super_block *sb, int flags);
30893 +int si_write_lock(struct super_block *sb, int flags);
30894 +int aufs_read_lock(struct dentry *dentry, int flags);
30895 +void aufs_read_unlock(struct dentry *dentry, int flags);
30896 +void aufs_write_lock(struct dentry *dentry);
30897 +void aufs_write_unlock(struct dentry *dentry);
30898 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30899 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30901 +/* wbr_policy.c */
30902 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30903 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30904 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30905 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30906 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30909 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30911 +#ifdef CONFIG_AUFS_FHSM
30914 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30918 + spin_lock(&fhsm->fhsm_spin);
30919 + pid = fhsm->fhsm_pid;
30920 + spin_unlock(&fhsm->fhsm_spin);
30925 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30926 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30927 +int au_fhsm_fd(struct super_block *sb, int oflags);
30928 +int au_fhsm_br_alloc(struct au_branch *br);
30929 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30930 +void au_fhsm_fin(struct super_block *sb);
30931 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30932 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30933 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30935 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30937 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30938 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30939 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30940 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30941 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30942 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30943 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30944 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30945 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30948 +/* ---------------------------------------------------------------------- */
30950 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30952 + return sb->s_fs_info;
30955 +/* ---------------------------------------------------------------------- */
30957 +#ifdef CONFIG_AUFS_EXPORT
30958 +int au_test_nfsd(void);
30959 +void au_export_init(struct super_block *sb);
30960 +void au_xigen_inc(struct inode *inode);
30961 +int au_xigen_new(struct inode *inode);
30962 +int au_xigen_set(struct super_block *sb, struct path *path);
30963 +void au_xigen_clr(struct super_block *sb);
30965 +static inline int au_busy_or_stale(void)
30967 + if (!au_test_nfsd())
30972 +AuStubInt0(au_test_nfsd, void)
30973 +AuStubVoid(au_export_init, struct super_block *sb)
30974 +AuStubVoid(au_xigen_inc, struct inode *inode)
30975 +AuStubInt0(au_xigen_new, struct inode *inode)
30976 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30977 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30978 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30979 +#endif /* CONFIG_AUFS_EXPORT */
30981 +/* ---------------------------------------------------------------------- */
30983 +#ifdef CONFIG_AUFS_SBILIST
30985 +extern struct hlist_bl_head au_sbilist;
30987 +static inline void au_sbilist_init(void)
30989 + INIT_HLIST_BL_HEAD(&au_sbilist);
30992 +static inline void au_sbilist_add(struct super_block *sb)
30994 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30997 +static inline void au_sbilist_del(struct super_block *sb)
30999 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
31002 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
31003 +static inline void au_sbilist_lock(void)
31005 + hlist_bl_lock(&au_sbilist);
31008 +static inline void au_sbilist_unlock(void)
31010 + hlist_bl_unlock(&au_sbilist);
31012 +#define AuGFP_SBILIST GFP_ATOMIC
31014 +AuStubVoid(au_sbilist_lock, void)
31015 +AuStubVoid(au_sbilist_unlock, void)
31016 +#define AuGFP_SBILIST GFP_NOFS
31017 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
31019 +AuStubVoid(au_sbilist_init, void)
31020 +AuStubVoid(au_sbilist_add, struct super_block *sb)
31021 +AuStubVoid(au_sbilist_del, struct super_block *sb)
31022 +AuStubVoid(au_sbilist_lock, void)
31023 +AuStubVoid(au_sbilist_unlock, void)
31024 +#define AuGFP_SBILIST GFP_NOFS
31027 +/* ---------------------------------------------------------------------- */
31029 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
31032 + * This function is a dynamic '__init' function actually,
31033 + * so the tiny check for si_rwsem is unnecessary.
31035 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
31036 +#ifdef CONFIG_DEBUG_FS
31037 + sbinfo->si_dbgaufs = NULL;
31038 + sbinfo->si_dbgaufs_plink = NULL;
31039 + sbinfo->si_dbgaufs_xib = NULL;
31040 +#ifdef CONFIG_AUFS_EXPORT
31041 + sbinfo->si_dbgaufs_xigen = NULL;
31046 +/* ---------------------------------------------------------------------- */
31048 +/* current->atomic_flags */
31049 +/* this value should never corrupt the ones defined in linux/sched.h */
31050 +#define PFA_AUFS 7
31052 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
31053 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
31054 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
31056 +static inline int si_pid_test(struct super_block *sb)
31058 + return !!task_test_aufs(current);
31061 +static inline void si_pid_clr(struct super_block *sb)
31063 + AuDebugOn(!task_test_aufs(current));
31064 + task_clear_aufs(current);
31067 +static inline void si_pid_set(struct super_block *sb)
31069 + AuDebugOn(task_test_aufs(current));
31070 + task_set_aufs(current);
31073 +/* ---------------------------------------------------------------------- */
31075 +/* lock superblock. mainly for entry point functions */
31076 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
31077 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
31078 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
31079 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
31081 +#define __si_read_trylock_nested(sb) \
31082 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
31083 +#define __si_write_trylock_nested(sb) \
31084 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
31087 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
31088 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
31089 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
31091 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
31092 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
31093 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
31095 +static inline void si_noflush_read_lock(struct super_block *sb)
31097 + __si_read_lock(sb);
31101 +static inline int si_noflush_read_trylock(struct super_block *sb)
31105 + locked = __si_read_trylock(sb);
31111 +static inline void si_noflush_write_lock(struct super_block *sb)
31113 + __si_write_lock(sb);
31117 +static inline int si_noflush_write_trylock(struct super_block *sb)
31121 + locked = __si_write_trylock(sb);
31127 +#if 0 /* reserved */
31128 +static inline int si_read_trylock(struct super_block *sb, int flags)
31130 + if (au_ftest_lock(flags, FLUSH))
31131 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31132 + return si_noflush_read_trylock(sb);
31136 +static inline void si_read_unlock(struct super_block *sb)
31139 + __si_read_unlock(sb);
31142 +#if 0 /* reserved */
31143 +static inline int si_write_trylock(struct super_block *sb, int flags)
31145 + if (au_ftest_lock(flags, FLUSH))
31146 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31147 + return si_noflush_write_trylock(sb);
31151 +static inline void si_write_unlock(struct super_block *sb)
31154 + __si_write_unlock(sb);
31157 +#if 0 /* reserved */
31158 +static inline void si_downgrade_lock(struct super_block *sb)
31160 + __si_downgrade_lock(sb);
31164 +/* ---------------------------------------------------------------------- */
31166 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31168 + SiMustAnyLock(sb);
31169 + return au_sbi(sb)->si_bbot;
31172 +static inline unsigned int au_mntflags(struct super_block *sb)
31174 + SiMustAnyLock(sb);
31175 + return au_sbi(sb)->si_mntflags;
31178 +static inline unsigned int au_sigen(struct super_block *sb)
31180 + SiMustAnyLock(sb);
31181 + return au_sbi(sb)->si_generation;
31184 +static inline struct au_branch *au_sbr(struct super_block *sb,
31185 + aufs_bindex_t bindex)
31187 + SiMustAnyLock(sb);
31188 + return au_sbi(sb)->si_branch[0 + bindex];
31191 +static inline loff_t au_xi_maxent(struct super_block *sb)
31193 + SiMustAnyLock(sb);
31194 + return au_sbi(sb)->si_ximaxent;
31197 +#endif /* __KERNEL__ */
31198 +#endif /* __AUFS_SUPER_H__ */
31199 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31200 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31201 +++ linux/fs/aufs/sysaufs.c 2019-03-05 12:13:00.142557771 +0100
31203 +// SPDX-License-Identifier: GPL-2.0
31205 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31207 + * This program, aufs is free software; you can redistribute it and/or modify
31208 + * it under the terms of the GNU General Public License as published by
31209 + * the Free Software Foundation; either version 2 of the License, or
31210 + * (at your option) any later version.
31212 + * This program is distributed in the hope that it will be useful,
31213 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31214 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31215 + * GNU General Public License for more details.
31217 + * You should have received a copy of the GNU General Public License
31218 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31222 + * sysfs interface and lifetime management
31223 + * they are necessary regardless sysfs is disabled.
31226 +#include <linux/random.h>
31229 +unsigned long sysaufs_si_mask;
31230 +struct kset *sysaufs_kset;
31232 +#define AuSiAttr(_name) { \
31233 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31234 + .show = sysaufs_si_##_name, \
31237 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31238 +struct attribute *sysaufs_si_attrs[] = {
31239 + &sysaufs_si_attr_xi_path.attr,
31243 +static const struct sysfs_ops au_sbi_ops = {
31244 + .show = sysaufs_si_show
31247 +static struct kobj_type au_sbi_ktype = {
31248 + .release = au_si_free,
31249 + .sysfs_ops = &au_sbi_ops,
31250 + .default_attrs = sysaufs_si_attrs
31253 +/* ---------------------------------------------------------------------- */
31255 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31259 + sbinfo->si_kobj.kset = sysaufs_kset;
31260 + /* cf. sysaufs_name() */
31261 + err = kobject_init_and_add
31262 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31263 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31268 +void sysaufs_fin(void)
31270 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31271 + kset_unregister(sysaufs_kset);
31274 +int __init sysaufs_init(void)
31279 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31280 + } while (!sysaufs_si_mask);
31283 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31284 + if (unlikely(!sysaufs_kset))
31286 + err = PTR_ERR(sysaufs_kset);
31287 + if (IS_ERR(sysaufs_kset))
31289 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31290 + if (unlikely(err))
31291 + kset_unregister(sysaufs_kset);
31296 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31297 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31298 +++ linux/fs/aufs/sysaufs.h 2019-03-05 12:13:00.142557771 +0100
31300 +/* SPDX-License-Identifier: GPL-2.0 */
31302 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31304 + * This program, aufs is free software; you can redistribute it and/or modify
31305 + * it under the terms of the GNU General Public License as published by
31306 + * the Free Software Foundation; either version 2 of the License, or
31307 + * (at your option) any later version.
31309 + * This program is distributed in the hope that it will be useful,
31310 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31311 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31312 + * GNU General Public License for more details.
31314 + * You should have received a copy of the GNU General Public License
31315 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31319 + * sysfs interface and mount lifetime management
31322 +#ifndef __SYSAUFS_H__
31323 +#define __SYSAUFS_H__
31327 +#include <linux/sysfs.h>
31328 +#include "module.h"
31330 +struct super_block;
31333 +struct sysaufs_si_attr {
31334 + struct attribute attr;
31335 + int (*show)(struct seq_file *seq, struct super_block *sb);
31338 +/* ---------------------------------------------------------------------- */
31341 +extern unsigned long sysaufs_si_mask;
31342 +extern struct kset *sysaufs_kset;
31343 +extern struct attribute *sysaufs_si_attrs[];
31344 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31345 +int __init sysaufs_init(void);
31346 +void sysaufs_fin(void);
31348 +/* ---------------------------------------------------------------------- */
31350 +/* some people doesn't like to show a pointer in kernel */
31351 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31353 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31356 +#define SysaufsSiNamePrefix "si_"
31357 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31358 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31360 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31361 + sysaufs_si_id(sbinfo));
31365 +#ifdef CONFIG_SYSFS
31367 +extern struct attribute_group *sysaufs_attr_group;
31369 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31370 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31372 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31373 +#ifdef CONFIG_COMPAT
31374 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31377 +void sysaufs_br_init(struct au_branch *br);
31378 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31379 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31381 +#define sysaufs_brs_init() do {} while (0)
31384 +#define sysaufs_attr_group NULL
31386 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31387 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31388 + struct attribute *attr, char *buf)
31389 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31390 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31391 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31393 +static inline void sysaufs_brs_init(void)
31398 +#endif /* CONFIG_SYSFS */
31400 +#endif /* __KERNEL__ */
31401 +#endif /* __SYSAUFS_H__ */
31402 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31403 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31404 +++ linux/fs/aufs/sysfs.c 2019-03-05 12:13:00.142557771 +0100
31406 +// SPDX-License-Identifier: GPL-2.0
31408 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31410 + * This program, aufs is free software; you can redistribute it and/or modify
31411 + * it under the terms of the GNU General Public License as published by
31412 + * the Free Software Foundation; either version 2 of the License, or
31413 + * (at your option) any later version.
31415 + * This program is distributed in the hope that it will be useful,
31416 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31417 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31418 + * GNU General Public License for more details.
31420 + * You should have received a copy of the GNU General Public License
31421 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31425 + * sysfs interface
31428 +#include <linux/compat.h>
31429 +#include <linux/seq_file.h>
31432 +#ifdef CONFIG_AUFS_FS_MODULE
31433 +/* this entry violates the "one line per file" policy of sysfs */
31434 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31438 + static char *conf =
31439 +/* this file is generated at compiling */
31440 +#include "conf.str"
31443 + err = snprintf(buf, PAGE_SIZE, conf);
31444 + if (unlikely(err >= PAGE_SIZE))
31449 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31452 +static struct attribute *au_attr[] = {
31453 +#ifdef CONFIG_AUFS_FS_MODULE
31454 + &au_config_attr.attr,
31456 + NULL, /* need to NULL terminate the list of attributes */
31459 +static struct attribute_group sysaufs_attr_group_body = {
31463 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31465 +/* ---------------------------------------------------------------------- */
31467 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31471 + SiMustAnyLock(sb);
31474 + if (au_opt_test(au_mntflags(sb), XINO)) {
31475 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31476 + seq_putc(seq, '\n');
31482 + * the lifetime of branch is independent from the entry under sysfs.
31483 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31486 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31487 + aufs_bindex_t bindex, int idx)
31490 + struct path path;
31491 + struct dentry *root;
31492 + struct au_branch *br;
31493 + au_br_perm_str_t perm;
31495 + AuDbg("b%d\n", bindex);
31498 + root = sb->s_root;
31499 + di_read_lock_parent(root, !AuLock_IR);
31500 + br = au_sbr(sb, bindex);
31503 + case AuBrSysfs_BR:
31504 + path.mnt = au_br_mnt(br);
31505 + path.dentry = au_h_dptr(root, bindex);
31506 + err = au_seq_path(seq, &path);
31508 + au_optstr_br_perm(&perm, br->br_perm);
31509 + seq_printf(seq, "=%s\n", perm.a);
31512 + case AuBrSysfs_BRID:
31513 + seq_printf(seq, "%d\n", br->br_id);
31516 + di_read_unlock(root, !AuLock_IR);
31517 + if (unlikely(err || seq_has_overflowed(seq)))
31523 +/* ---------------------------------------------------------------------- */
31525 +static struct seq_file *au_seq(char *p, ssize_t len)
31527 + struct seq_file *seq;
31529 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31531 + /* mutex_init(&seq.lock); */
31534 + return seq; /* success */
31537 + seq = ERR_PTR(-ENOMEM);
31541 +#define SysaufsBr_PREFIX "br"
31542 +#define SysaufsBrid_PREFIX "brid"
31544 +/* todo: file size may exceed PAGE_SIZE */
31545 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31551 + aufs_bindex_t bbot;
31552 + struct au_sbinfo *sbinfo;
31553 + struct super_block *sb;
31554 + struct seq_file *seq;
31556 + struct attribute **cattr;
31558 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31559 + sb = sbinfo->si_sb;
31562 + * prevent a race condition between sysfs and aufs.
31563 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31564 + * prohibits maintaining the sysfs entries.
31565 + * hew we acquire read lock after sysfs_get_active_two().
31566 + * on the other hand, the remount process may maintain the sysfs/aufs
31567 + * entries after acquiring write lock.
31568 + * it can cause a deadlock.
31569 + * simply we gave up processing read here.
31572 + if (unlikely(!si_noflush_read_trylock(sb)))
31575 + seq = au_seq(buf, PAGE_SIZE);
31576 + err = PTR_ERR(seq);
31580 + name = (void *)attr->name;
31581 + cattr = sysaufs_si_attrs;
31583 + if (!strcmp(name, (*cattr)->name)) {
31584 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31591 + if (!strncmp(name, SysaufsBrid_PREFIX,
31592 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31593 + idx = AuBrSysfs_BRID;
31594 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31595 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31596 + sizeof(SysaufsBr_PREFIX) - 1)) {
31597 + idx = AuBrSysfs_BR;
31598 + name += sizeof(SysaufsBr_PREFIX) - 1;
31602 + err = kstrtol(name, 10, &l);
31604 + bbot = au_sbbot(sb);
31606 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31613 + err = seq->count;
31614 + /* sysfs limit */
31615 + if (unlikely(err == PAGE_SIZE))
31618 + au_kfree_rcu(seq);
31620 + si_read_unlock(sb);
31625 +/* ---------------------------------------------------------------------- */
31627 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31631 + aufs_bindex_t bindex, bbot;
31634 + struct seq_file *seq;
31635 + struct au_branch *br;
31637 + si_read_lock(sb, AuLock_FLUSH);
31638 + bbot = au_sbbot(sb);
31644 + buf = (void *)__get_free_page(GFP_NOFS);
31645 + if (unlikely(!buf))
31648 + seq = au_seq(buf, PAGE_SIZE);
31649 + err = PTR_ERR(seq);
31653 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31654 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31655 + /* VERIFY_WRITE */
31656 + err = !access_ok(arg, sizeof(*arg));
31657 + if (unlikely(err))
31660 + br = au_sbr(sb, bindex);
31661 + brid = br->br_id;
31662 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31663 + err = __put_user(brid, &arg->id);
31664 + if (unlikely(err))
31667 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31668 + err = __put_user(br->br_perm, &arg->perm);
31669 + if (unlikely(err))
31672 + err = au_seq_path(seq, &br->br_path);
31673 + if (unlikely(err))
31675 + seq_putc(seq, '\0');
31676 + if (!seq_has_overflowed(seq)) {
31677 + err = copy_to_user(arg->path, seq->buf, seq->count);
31679 + if (unlikely(err))
31686 + if (unlikely(err))
31690 + au_kfree_rcu(seq);
31692 + free_page((unsigned long)buf);
31694 + si_read_unlock(sb);
31698 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31700 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31703 +#ifdef CONFIG_COMPAT
31704 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31706 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31710 +/* ---------------------------------------------------------------------- */
31712 +void sysaufs_br_init(struct au_branch *br)
31715 + struct au_brsysfs *br_sysfs;
31716 + struct attribute *attr;
31718 + br_sysfs = br->br_sysfs;
31719 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31720 + attr = &br_sysfs->attr;
31721 + sysfs_attr_init(attr);
31722 + attr->name = br_sysfs->name;
31723 + attr->mode = 0444;
31728 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31730 + struct au_branch *br;
31731 + struct kobject *kobj;
31732 + struct au_brsysfs *br_sysfs;
31734 + aufs_bindex_t bbot;
31736 + if (!sysaufs_brs)
31739 + kobj = &au_sbi(sb)->si_kobj;
31740 + bbot = au_sbbot(sb);
31741 + for (; bindex <= bbot; bindex++) {
31742 + br = au_sbr(sb, bindex);
31743 + br_sysfs = br->br_sysfs;
31744 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31745 + sysfs_remove_file(kobj, &br_sysfs->attr);
31751 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31754 + aufs_bindex_t bbot;
31755 + struct kobject *kobj;
31756 + struct au_branch *br;
31757 + struct au_brsysfs *br_sysfs;
31759 + if (!sysaufs_brs)
31762 + kobj = &au_sbi(sb)->si_kobj;
31763 + bbot = au_sbbot(sb);
31764 + for (; bindex <= bbot; bindex++) {
31765 + br = au_sbr(sb, bindex);
31766 + br_sysfs = br->br_sysfs;
31767 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31768 + SysaufsBr_PREFIX "%d", bindex);
31769 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31770 + SysaufsBrid_PREFIX "%d", bindex);
31771 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31772 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31773 + if (unlikely(err))
31774 + pr_warn("failed %s under sysfs(%d)\n",
31775 + br_sysfs->name, err);
31780 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31781 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31782 +++ linux/fs/aufs/sysrq.c 2019-03-05 12:13:00.142557771 +0100
31784 +// SPDX-License-Identifier: GPL-2.0
31786 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31788 + * This program, aufs is free software; you can redistribute it and/or modify
31789 + * it under the terms of the GNU General Public License as published by
31790 + * the Free Software Foundation; either version 2 of the License, or
31791 + * (at your option) any later version.
31793 + * This program is distributed in the hope that it will be useful,
31794 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31795 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31796 + * GNU General Public License for more details.
31798 + * You should have received a copy of the GNU General Public License
31799 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31803 + * magic sysrq handler
31806 +/* #include <linux/sysrq.h> */
31807 +#include <linux/writeback.h>
31810 +/* ---------------------------------------------------------------------- */
31812 +static void sysrq_sb(struct super_block *sb)
31815 + struct au_sbinfo *sbinfo;
31816 + struct file *file;
31817 + struct hlist_bl_head *files;
31818 + struct hlist_bl_node *pos;
31819 + struct au_finfo *finfo;
31821 + plevel = au_plevel;
31822 + au_plevel = KERN_WARNING;
31824 + /* since we define pr_fmt, call printk directly */
31825 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31827 + sbinfo = au_sbi(sb);
31828 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31829 + pr("superblock\n");
31833 + pr("root dentry\n");
31834 + au_dpri_dentry(sb->s_root);
31835 + pr("root inode\n");
31836 + au_dpri_inode(d_inode(sb->s_root));
31841 + int err, i, j, ndentry;
31842 + struct au_dcsub_pages dpages;
31843 + struct au_dpage *dpage;
31845 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31846 + if (unlikely(err))
31848 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31850 + for (i = 0; i < dpages.ndpage; i++) {
31851 + dpage = dpages.dpages + i;
31852 + ndentry = dpage->ndentry;
31853 + for (j = 0; j < ndentry; j++)
31854 + au_dpri_dentry(dpage->dentries[j]);
31856 + au_dpages_free(&dpages);
31864 + pr("isolated inode\n");
31865 + spin_lock(&sb->s_inode_list_lock);
31866 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31867 + spin_lock(&i->i_lock);
31868 + if (1 || hlist_empty(&i->i_dentry))
31869 + au_dpri_inode(i);
31870 + spin_unlock(&i->i_lock);
31872 + spin_unlock(&sb->s_inode_list_lock);
31876 + files = &au_sbi(sb)->si_files;
31877 + hlist_bl_lock(files);
31878 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31881 + file = finfo->fi_file;
31882 + mode = file_inode(file)->i_mode;
31883 + if (!special_file(mode))
31884 + au_dpri_file(file);
31886 + hlist_bl_unlock(files);
31890 + au_plevel = plevel;
31893 +/* ---------------------------------------------------------------------- */
31895 +/* module parameter */
31896 +static char *aufs_sysrq_key = "a";
31897 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31898 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31900 +static void au_sysrq(int key __maybe_unused)
31902 + struct au_sbinfo *sbinfo;
31903 + struct hlist_bl_node *pos;
31906 + au_sbilist_lock();
31907 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31908 + sysrq_sb(sbinfo->si_sb);
31909 + au_sbilist_unlock();
31913 +static struct sysrq_key_op au_sysrq_op = {
31914 + .handler = au_sysrq,
31915 + .help_msg = "Aufs",
31916 + .action_msg = "Aufs",
31917 + .enable_mask = SYSRQ_ENABLE_DUMP
31920 +/* ---------------------------------------------------------------------- */
31922 +int __init au_sysrq_init(void)
31928 + key = *aufs_sysrq_key;
31929 + if ('a' <= key && key <= 'z')
31930 + err = register_sysrq_key(key, &au_sysrq_op);
31931 + if (unlikely(err))
31932 + pr_err("err %d, sysrq=%c\n", err, key);
31936 +void au_sysrq_fin(void)
31940 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31941 + if (unlikely(err))
31942 + pr_err("err %d (ignored)\n", err);
31944 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31945 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31946 +++ linux/fs/aufs/vdir.c 2019-05-06 09:03:04.820143837 +0200
31948 +// SPDX-License-Identifier: GPL-2.0
31950 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31952 + * This program, aufs is free software; you can redistribute it and/or modify
31953 + * it under the terms of the GNU General Public License as published by
31954 + * the Free Software Foundation; either version 2 of the License, or
31955 + * (at your option) any later version.
31957 + * This program is distributed in the hope that it will be useful,
31958 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31959 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31960 + * GNU General Public License for more details.
31962 + * You should have received a copy of the GNU General Public License
31963 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31967 + * virtual or vertical directory
31970 +#include <linux/iversion.h>
31973 +static unsigned int calc_size(int nlen)
31975 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31978 +static int set_deblk_end(union au_vdir_deblk_p *p,
31979 + union au_vdir_deblk_p *deblk_end)
31981 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31982 + p->de->de_str.len = 0;
31986 + return -1; /* error */
31989 +/* returns true or false */
31990 +static int is_deblk_end(union au_vdir_deblk_p *p,
31991 + union au_vdir_deblk_p *deblk_end)
31993 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31994 + return !p->de->de_str.len;
31998 +static unsigned char *last_deblk(struct au_vdir *vdir)
32000 + return vdir->vd_deblk[vdir->vd_nblk - 1];
32003 +/* ---------------------------------------------------------------------- */
32005 +/* estimate the appropriate size for name hash table */
32006 +unsigned int au_rdhash_est(loff_t sz)
32014 + if (sz < AUFS_RDHASH_DEF)
32015 + n = AUFS_RDHASH_DEF;
32016 + /* pr_info("n %u\n", n); */
32021 + * the allocated memory has to be freed by
32022 + * au_nhash_wh_free() or au_nhash_de_free().
32024 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
32026 + struct hlist_head *head;
32030 + sz = sizeof(*nhash->nh_head) * num_hash;
32031 + head = kmalloc(sz, gfp);
32033 + nhash->nh_num = num_hash;
32034 + nhash->nh_head = head;
32035 + for (u = 0; u < num_hash; u++)
32036 + INIT_HLIST_HEAD(head++);
32037 + return 0; /* success */
32043 +static void nhash_count(struct hlist_head *head)
32047 + struct hlist_node *pos;
32050 + hlist_for_each(pos, head)
32052 + pr_info("%lu\n", n);
32056 +static void au_nhash_wh_do_free(struct hlist_head *head)
32058 + struct au_vdir_wh *pos;
32059 + struct hlist_node *node;
32061 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
32062 + au_kfree_rcu(pos);
32065 +static void au_nhash_de_do_free(struct hlist_head *head)
32067 + struct au_vdir_dehstr *pos;
32068 + struct hlist_node *node;
32070 + hlist_for_each_entry_safe(pos, node, head, hash)
32071 + au_cache_free_vdir_dehstr(pos);
32074 +static void au_nhash_do_free(struct au_nhash *nhash,
32075 + void (*free)(struct hlist_head *head))
32078 + struct hlist_head *head;
32080 + n = nhash->nh_num;
32084 + head = nhash->nh_head;
32085 + while (n-- > 0) {
32086 + nhash_count(head);
32089 + au_kfree_try_rcu(nhash->nh_head);
32092 +void au_nhash_wh_free(struct au_nhash *whlist)
32094 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
32097 +static void au_nhash_de_free(struct au_nhash *delist)
32099 + au_nhash_do_free(delist, au_nhash_de_do_free);
32102 +/* ---------------------------------------------------------------------- */
32104 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
32108 + unsigned int u, n;
32109 + struct hlist_head *head;
32110 + struct au_vdir_wh *pos;
32113 + n = whlist->nh_num;
32114 + head = whlist->nh_head;
32115 + for (u = 0; u < n; u++, head++)
32116 + hlist_for_each_entry(pos, head, wh_hash)
32117 + if (pos->wh_bindex == btgt && ++num > limit)
32122 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
32123 + unsigned char *name,
32124 + unsigned int len)
32127 + /* const unsigned int magic_bit = 12; */
32129 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32136 + /* v = hash_long(v, magic_bit); */
32137 + v %= nhash->nh_num;
32138 + return nhash->nh_head + v;
32141 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32144 + return str->len == nlen && !memcmp(str->name, name, nlen);
32147 +/* returns found or not */
32148 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32150 + struct hlist_head *head;
32151 + struct au_vdir_wh *pos;
32152 + struct au_vdir_destr *str;
32154 + head = au_name_hash(whlist, name, nlen);
32155 + hlist_for_each_entry(pos, head, wh_hash) {
32156 + str = &pos->wh_str;
32157 + AuDbg("%.*s\n", str->len, str->name);
32158 + if (au_nhash_test_name(str, name, nlen))
32164 +/* returns found(true) or not */
32165 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32167 + struct hlist_head *head;
32168 + struct au_vdir_dehstr *pos;
32169 + struct au_vdir_destr *str;
32171 + head = au_name_hash(delist, name, nlen);
32172 + hlist_for_each_entry(pos, head, hash) {
32174 + AuDbg("%.*s\n", str->len, str->name);
32175 + if (au_nhash_test_name(str, name, nlen))
32181 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32182 + unsigned char d_type)
32184 +#ifdef CONFIG_AUFS_SHWH
32185 + wh->wh_ino = ino;
32186 + wh->wh_type = d_type;
32190 +/* ---------------------------------------------------------------------- */
32192 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32193 + unsigned int d_type, aufs_bindex_t bindex,
32194 + unsigned char shwh)
32197 + struct au_vdir_destr *str;
32198 + struct au_vdir_wh *wh;
32200 + AuDbg("%.*s\n", nlen, name);
32201 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32204 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32205 + if (unlikely(!wh))
32209 + wh->wh_bindex = bindex;
32211 + au_shwh_init_wh(wh, ino, d_type);
32212 + str = &wh->wh_str;
32214 + memcpy(str->name, name, nlen);
32215 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32222 +static int append_deblk(struct au_vdir *vdir)
32225 + unsigned long ul;
32226 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32227 + union au_vdir_deblk_p p, deblk_end;
32228 + unsigned char **o;
32231 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32232 + GFP_NOFS, /*may_shrink*/0);
32233 + if (unlikely(!o))
32236 + vdir->vd_deblk = o;
32237 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32239 + ul = vdir->vd_nblk++;
32240 + vdir->vd_deblk[ul] = p.deblk;
32241 + vdir->vd_last.ul = ul;
32242 + vdir->vd_last.p.deblk = p.deblk;
32243 + deblk_end.deblk = p.deblk + deblk_sz;
32244 + err = set_deblk_end(&p, &deblk_end);
32251 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32252 + unsigned int d_type, struct au_nhash *delist)
32256 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32257 + union au_vdir_deblk_p p, *room, deblk_end;
32258 + struct au_vdir_dehstr *dehstr;
32260 + p.deblk = last_deblk(vdir);
32261 + deblk_end.deblk = p.deblk + deblk_sz;
32262 + room = &vdir->vd_last.p;
32263 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32264 + || !is_deblk_end(room, &deblk_end));
32266 + sz = calc_size(nlen);
32267 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32268 + err = append_deblk(vdir);
32269 + if (unlikely(err))
32272 + p.deblk = last_deblk(vdir);
32273 + deblk_end.deblk = p.deblk + deblk_sz;
32275 + AuDebugOn(room->deblk != p.deblk);
32279 + dehstr = au_cache_alloc_vdir_dehstr();
32280 + if (unlikely(!dehstr))
32283 + dehstr->str = &room->de->de_str;
32284 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32285 + room->de->de_ino = ino;
32286 + room->de->de_type = d_type;
32287 + room->de->de_str.len = nlen;
32288 + memcpy(room->de->de_str.name, name, nlen);
32291 + room->deblk += sz;
32292 + if (unlikely(set_deblk_end(room, &deblk_end)))
32293 + err = append_deblk(vdir);
32300 +/* ---------------------------------------------------------------------- */
32302 +void au_vdir_free(struct au_vdir *vdir)
32304 + unsigned char **deblk;
32306 + deblk = vdir->vd_deblk;
32307 + while (vdir->vd_nblk--)
32308 + au_kfree_try_rcu(*deblk++);
32309 + au_kfree_try_rcu(vdir->vd_deblk);
32310 + au_cache_free_vdir(vdir);
32313 +static struct au_vdir *alloc_vdir(struct file *file)
32315 + struct au_vdir *vdir;
32316 + struct super_block *sb;
32319 + sb = file->f_path.dentry->d_sb;
32320 + SiMustAnyLock(sb);
32323 + vdir = au_cache_alloc_vdir();
32324 + if (unlikely(!vdir))
32327 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32328 + if (unlikely(!vdir->vd_deblk))
32331 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32332 + if (!vdir->vd_deblk_sz) {
32333 + /* estimate the appropriate size for deblk */
32334 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32335 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32337 + vdir->vd_nblk = 0;
32338 + vdir->vd_version = 0;
32339 + vdir->vd_jiffy = 0;
32340 + err = append_deblk(vdir);
32342 + return vdir; /* success */
32344 + au_kfree_try_rcu(vdir->vd_deblk);
32347 + au_cache_free_vdir(vdir);
32349 + vdir = ERR_PTR(err);
32353 +static int reinit_vdir(struct au_vdir *vdir)
32356 + union au_vdir_deblk_p p, deblk_end;
32358 + while (vdir->vd_nblk > 1) {
32359 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32360 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32363 + p.deblk = vdir->vd_deblk[0];
32364 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32365 + err = set_deblk_end(&p, &deblk_end);
32366 + /* keep vd_dblk_sz */
32367 + vdir->vd_last.ul = 0;
32368 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32369 + vdir->vd_version = 0;
32370 + vdir->vd_jiffy = 0;
32375 +/* ---------------------------------------------------------------------- */
32377 +#define AuFillVdir_CALLED 1
32378 +#define AuFillVdir_WHABLE (1 << 1)
32379 +#define AuFillVdir_SHWH (1 << 2)
32380 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32381 +#define au_fset_fillvdir(flags, name) \
32382 + do { (flags) |= AuFillVdir_##name; } while (0)
32383 +#define au_fclr_fillvdir(flags, name) \
32384 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32386 +#ifndef CONFIG_AUFS_SHWH
32387 +#undef AuFillVdir_SHWH
32388 +#define AuFillVdir_SHWH 0
32391 +struct fillvdir_arg {
32392 + struct dir_context ctx;
32393 + struct file *file;
32394 + struct au_vdir *vdir;
32395 + struct au_nhash delist;
32396 + struct au_nhash whlist;
32397 + aufs_bindex_t bindex;
32398 + unsigned int flags;
32402 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32403 + loff_t offset __maybe_unused, u64 h_ino,
32404 + unsigned int d_type)
32406 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32407 + char *name = (void *)__name;
32408 + struct super_block *sb;
32410 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32413 + sb = arg->file->f_path.dentry->d_sb;
32414 + au_fset_fillvdir(arg->flags, CALLED);
32416 + if (nlen <= AUFS_WH_PFX_LEN
32417 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32418 + if (test_known(&arg->delist, name, nlen)
32419 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32420 + goto out; /* already exists or whiteouted */
32422 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32424 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32425 + d_type = DT_UNKNOWN;
32426 + arg->err = append_de(arg->vdir, name, nlen, ino,
32427 + d_type, &arg->delist);
32429 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32430 + name += AUFS_WH_PFX_LEN;
32431 + nlen -= AUFS_WH_PFX_LEN;
32432 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32433 + goto out; /* already whiteouted */
32435 + ino = 0; /* just to suppress a warning */
32437 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32440 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32441 + d_type = DT_UNKNOWN;
32442 + arg->err = au_nhash_append_wh
32443 + (&arg->whlist, name, nlen, ino, d_type,
32444 + arg->bindex, shwh);
32450 + arg->vdir->vd_jiffy = jiffies;
32452 + AuTraceErr(arg->err);
32456 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32457 + struct au_nhash *whlist, struct au_nhash *delist)
32459 +#ifdef CONFIG_AUFS_SHWH
32461 + unsigned int nh, u;
32462 + struct hlist_head *head;
32463 + struct au_vdir_wh *pos;
32464 + struct hlist_node *n;
32466 + struct au_vdir_destr *destr;
32468 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32471 + o = p = (void *)__get_free_page(GFP_NOFS);
32472 + if (unlikely(!p))
32476 + nh = whlist->nh_num;
32477 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32478 + p += AUFS_WH_PFX_LEN;
32479 + for (u = 0; u < nh; u++) {
32480 + head = whlist->nh_head + u;
32481 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32482 + destr = &pos->wh_str;
32483 + memcpy(p, destr->name, destr->len);
32484 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32485 + pos->wh_ino, pos->wh_type, delist);
32486 + if (unlikely(err))
32491 + free_page((unsigned long)o);
32501 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32504 + unsigned int rdhash;
32506 + aufs_bindex_t bbot, bindex, btop;
32507 + unsigned char shwh;
32508 + struct file *hf, *file;
32509 + struct super_block *sb;
32511 + file = arg->file;
32512 + sb = file->f_path.dentry->d_sb;
32513 + SiMustAnyLock(sb);
32515 + rdhash = au_sbi(sb)->si_rdhash;
32517 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32518 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32519 + if (unlikely(err))
32521 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32522 + if (unlikely(err))
32528 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32530 + au_fset_fillvdir(arg->flags, SHWH);
32532 + btop = au_fbtop(file);
32533 + bbot = au_fbbot_dir(file);
32534 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32535 + hf = au_hf_dir(file, bindex);
32539 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32541 + if (unlikely(offset))
32544 + arg->bindex = bindex;
32545 + au_fclr_fillvdir(arg->flags, WHABLE);
32547 + || (bindex != bbot
32548 + && au_br_whable(au_sbr_perm(sb, bindex))))
32549 + au_fset_fillvdir(arg->flags, WHABLE);
32552 + au_fclr_fillvdir(arg->flags, CALLED);
32554 + err = vfsub_iterate_dir(hf, &arg->ctx);
32557 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32560 + * dir_relax() may be good for concurrency, but aufs should not
32561 + * use it since it will cause a lockdep problem.
32565 + if (!err && shwh)
32566 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32568 + au_nhash_wh_free(&arg->whlist);
32571 + au_nhash_de_free(&arg->delist);
32576 +static int read_vdir(struct file *file, int may_read)
32579 + unsigned long expire;
32580 + unsigned char do_read;
32581 + struct fillvdir_arg arg = {
32583 + .actor = fillvdir
32586 + struct inode *inode;
32587 + struct au_vdir *vdir, *allocated;
32590 + inode = file_inode(file);
32591 + IMustLock(inode);
32592 + IiMustWriteLock(inode);
32593 + SiMustAnyLock(inode->i_sb);
32595 + allocated = NULL;
32597 + expire = au_sbi(inode->i_sb)->si_rdcache;
32598 + vdir = au_ivdir(inode);
32601 + vdir = alloc_vdir(file);
32602 + err = PTR_ERR(vdir);
32603 + if (IS_ERR(vdir))
32606 + allocated = vdir;
32607 + } else if (may_read
32608 + && (!inode_eq_iversion(inode, vdir->vd_version)
32609 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32611 + err = reinit_vdir(vdir);
32612 + if (unlikely(err))
32617 + return 0; /* success */
32621 + err = au_do_read_vdir(&arg);
32623 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32624 + vdir->vd_version = inode_query_iversion(inode);
32625 + vdir->vd_last.ul = 0;
32626 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32628 + au_set_ivdir(inode, allocated);
32629 + } else if (allocated)
32630 + au_vdir_free(allocated);
32636 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32639 + unsigned long ul, n;
32640 + const unsigned int deblk_sz = src->vd_deblk_sz;
32642 + AuDebugOn(tgt->vd_nblk != 1);
32645 + if (tgt->vd_nblk < src->vd_nblk) {
32646 + unsigned char **p;
32648 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32649 + GFP_NOFS, /*may_shrink*/0);
32650 + if (unlikely(!p))
32652 + tgt->vd_deblk = p;
32655 + if (tgt->vd_deblk_sz != deblk_sz) {
32656 + unsigned char *p;
32658 + tgt->vd_deblk_sz = deblk_sz;
32659 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32660 + /*may_shrink*/1);
32661 + if (unlikely(!p))
32663 + tgt->vd_deblk[0] = p;
32665 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32666 + tgt->vd_version = src->vd_version;
32667 + tgt->vd_jiffy = src->vd_jiffy;
32669 + n = src->vd_nblk;
32670 + for (ul = 1; ul < n; ul++) {
32671 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32673 + if (unlikely(!tgt->vd_deblk[ul]))
32677 + tgt->vd_nblk = n;
32678 + tgt->vd_last.ul = tgt->vd_last.ul;
32679 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32680 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32681 + - src->vd_deblk[src->vd_last.ul];
32683 + return 0; /* success */
32686 + rerr = reinit_vdir(tgt);
32691 +int au_vdir_init(struct file *file)
32694 + struct inode *inode;
32695 + struct au_vdir *vdir_cache, *allocated;
32697 + /* test file->f_pos here instead of ctx->pos */
32698 + err = read_vdir(file, !file->f_pos);
32699 + if (unlikely(err))
32702 + allocated = NULL;
32703 + vdir_cache = au_fvdir_cache(file);
32704 + if (!vdir_cache) {
32705 + vdir_cache = alloc_vdir(file);
32706 + err = PTR_ERR(vdir_cache);
32707 + if (IS_ERR(vdir_cache))
32709 + allocated = vdir_cache;
32710 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32711 + /* test file->f_pos here instead of ctx->pos */
32712 + err = reinit_vdir(vdir_cache);
32713 + if (unlikely(err))
32716 + return 0; /* success */
32718 + inode = file_inode(file);
32719 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32721 + file->f_version = inode_query_iversion(inode);
32723 + au_set_fvdir_cache(file, allocated);
32724 + } else if (allocated)
32725 + au_vdir_free(allocated);
32731 +static loff_t calc_offset(struct au_vdir *vdir)
32734 + union au_vdir_deblk_p p;
32736 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32737 + offset = vdir->vd_last.p.deblk - p.deblk;
32738 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32742 +/* returns true or false */
32743 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32746 + unsigned int deblk_sz;
32747 + unsigned long ul, n;
32749 + union au_vdir_deblk_p p, deblk_end;
32750 + struct au_vdir *vdir_cache;
32753 + vdir_cache = au_fvdir_cache(file);
32754 + offset = calc_offset(vdir_cache);
32755 + AuDbg("offset %lld\n", offset);
32756 + if (ctx->pos == offset)
32759 + vdir_cache->vd_last.ul = 0;
32760 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32765 + deblk_sz = vdir_cache->vd_deblk_sz;
32766 + ul = div64_u64(ctx->pos, deblk_sz);
32767 + AuDbg("ul %lu\n", ul);
32768 + if (ul >= vdir_cache->vd_nblk)
32771 + n = vdir_cache->vd_nblk;
32772 + for (; ul < n; ul++) {
32773 + p.deblk = vdir_cache->vd_deblk[ul];
32774 + deblk_end.deblk = p.deblk + deblk_sz;
32776 + offset *= deblk_sz;
32777 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32780 + l = calc_size(p.de->de_str.len);
32784 + if (!is_deblk_end(&p, &deblk_end)) {
32786 + vdir_cache->vd_last.ul = ul;
32787 + vdir_cache->vd_last.p = p;
32795 + AuDbg("valid %d\n", !valid);
32799 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32801 + unsigned int l, deblk_sz;
32802 + union au_vdir_deblk_p deblk_end;
32803 + struct au_vdir *vdir_cache;
32804 + struct au_vdir_de *de;
32806 + if (!seek_vdir(file, ctx))
32809 + vdir_cache = au_fvdir_cache(file);
32810 + deblk_sz = vdir_cache->vd_deblk_sz;
32812 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32813 + deblk_end.deblk += deblk_sz;
32814 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32815 + de = vdir_cache->vd_last.p.de;
32816 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32817 + de->de_str.len, de->de_str.name, ctx->pos,
32818 + (unsigned long)de->de_ino, de->de_type);
32819 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32820 + de->de_str.len, de->de_ino,
32822 + /* todo: ignore the error caused by udba? */
32823 + /* return err; */
32827 + l = calc_size(de->de_str.len);
32828 + vdir_cache->vd_last.p.deblk += l;
32831 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32832 + vdir_cache->vd_last.ul++;
32833 + vdir_cache->vd_last.p.deblk
32834 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32835 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32844 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32845 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32846 +++ linux/fs/aufs/vfsub.c 2019-03-05 12:13:00.145891204 +0100
32848 +// SPDX-License-Identifier: GPL-2.0
32850 + * Copyright (C) 2005-2019 Junjiro R. Okajima
32852 + * This program, aufs is free software; you can redistribute it and/or modify
32853 + * it under the terms of the GNU General Public License as published by
32854 + * the Free Software Foundation; either version 2 of the License, or
32855 + * (at your option) any later version.
32857 + * This program is distributed in the hope that it will be useful,
32858 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32859 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32860 + * GNU General Public License for more details.
32862 + * You should have received a copy of the GNU General Public License
32863 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32867 + * sub-routines for VFS
32870 +#include <linux/mnt_namespace.h>
32871 +#include <linux/namei.h>
32872 +#include <linux/nsproxy.h>
32873 +#include <linux/security.h>
32874 +#include <linux/splice.h>
32877 +#ifdef CONFIG_AUFS_BR_FUSE
32878 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32880 + if (!au_test_fuse(h_sb) || !au_userns)
32883 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32887 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32892 + down_read(&h_sb->s_umount);
32893 + err = __sync_filesystem(h_sb, wait);
32894 + up_read(&h_sb->s_umount);
32900 +/* ---------------------------------------------------------------------- */
32902 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32906 + struct super_block *h_sb;
32908 + /* for remote fs, leave work for its getattr or d_revalidate */
32909 + /* for bad i_attr fs, handle them in aufs_getattr() */
32910 + /* still some fs may acquire i_mutex. we need to skip them */
32914 + h_sb = h_path->dentry->d_sb;
32915 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32917 + err = vfsub_getattr(h_path, &st);
32922 +/* ---------------------------------------------------------------------- */
32924 +struct file *vfsub_dentry_open(struct path *path, int flags)
32926 + struct file *file;
32928 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32930 + if (!IS_ERR_OR_NULL(file)
32931 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
32932 + i_readcount_inc(d_inode(path->dentry));
32937 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32939 + struct file *file;
32942 + file = filp_open(path,
32943 + oflags /* | __FMODE_NONOTIFY */,
32946 + if (IS_ERR(file))
32948 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32955 + * Ideally this function should call VFS:do_last() in order to keep all its
32956 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32957 + * structure such as nameidata. This is a second (or third) best approach.
32958 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32960 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32961 + struct vfsub_aopen_args *args)
32964 + struct au_branch *br = args->br;
32965 + struct file *file = args->file;
32966 + /* copied from linux/fs/namei.c:atomic_open() */
32967 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32970 + AuDebugOn(!dir->i_op->atomic_open);
32972 + err = au_br_test_oflag(args->open_flag, br);
32973 + if (unlikely(err))
32976 + au_lcnt_inc(&br->br_nfiles);
32977 + file->f_path.dentry = DENTRY_NOT_SET;
32978 + file->f_path.mnt = au_br_mnt(br);
32979 + AuDbg("%ps\n", dir->i_op->atomic_open);
32980 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32981 + args->create_mode);
32982 + if (unlikely(err < 0)) {
32983 + au_lcnt_dec(&br->br_nfiles);
32987 + /* temporary workaround for nfsv4 branch */
32988 + if (au_test_nfs(dir->i_sb))
32989 + nfs_mark_for_revalidate(dir);
32991 + if (file->f_mode & FMODE_CREATED)
32992 + fsnotify_create(dir, dentry);
32993 + if (!(file->f_mode & FMODE_OPENED)) {
32994 + au_lcnt_dec(&br->br_nfiles);
32998 + /* todo: call VFS:may_open() here */
32999 + /* todo: ima_file_check() too? */
33000 + if (!err && (args->open_flag & __FMODE_EXEC))
33001 + err = deny_write_access(file);
33003 + fsnotify_open(file);
33005 + au_lcnt_dec(&br->br_nfiles);
33006 + /* note that the file is created and still opened */
33012 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
33016 + err = kern_path(name, flags, path);
33017 + if (!err && d_is_positive(path->dentry))
33018 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33022 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33023 + struct dentry *parent, int len)
33025 + struct path path = {
33029 + path.dentry = lookup_one_len_unlocked(name, parent, len);
33030 + if (IS_ERR(path.dentry))
33032 + if (d_is_positive(path.dentry))
33033 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33036 + AuTraceErrPtr(path.dentry);
33037 + return path.dentry;
33040 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33043 + struct path path = {
33047 + /* VFS checks it too, but by WARN_ON_ONCE() */
33048 + IMustLock(d_inode(parent));
33050 + path.dentry = lookup_one_len(name, parent, len);
33051 + if (IS_ERR(path.dentry))
33053 + if (d_is_positive(path.dentry))
33054 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33057 + AuTraceErrPtr(path.dentry);
33058 + return path.dentry;
33061 +void vfsub_call_lkup_one(void *args)
33063 + struct vfsub_lkup_one_args *a = args;
33064 + *a->errp = vfsub_lkup_one(a->name, a->parent);
33067 +/* ---------------------------------------------------------------------- */
33069 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33070 + struct dentry *d2, struct au_hinode *hdir2)
33072 + struct dentry *d;
33075 + d = lock_rename(d1, d2);
33077 + au_hn_suspend(hdir1);
33078 + if (hdir1 != hdir2)
33079 + au_hn_suspend(hdir2);
33084 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33085 + struct dentry *d2, struct au_hinode *hdir2)
33087 + au_hn_resume(hdir1);
33088 + if (hdir1 != hdir2)
33089 + au_hn_resume(hdir2);
33091 + unlock_rename(d1, d2);
33095 +/* ---------------------------------------------------------------------- */
33097 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
33100 + struct dentry *d;
33104 + d = path->dentry;
33105 + path->dentry = d->d_parent;
33106 + err = security_path_mknod(path, d, mode, 0);
33107 + path->dentry = d;
33108 + if (unlikely(err))
33112 + err = vfs_create(dir, path->dentry, mode, want_excl);
33115 + struct path tmp = *path;
33118 + vfsub_update_h_iattr(&tmp, &did);
33120 + tmp.dentry = path->dentry->d_parent;
33121 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33130 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33133 + struct dentry *d;
33137 + d = path->dentry;
33138 + path->dentry = d->d_parent;
33139 + err = security_path_symlink(path, d, symname);
33140 + path->dentry = d;
33141 + if (unlikely(err))
33145 + err = vfs_symlink(dir, path->dentry, symname);
33148 + struct path tmp = *path;
33151 + vfsub_update_h_iattr(&tmp, &did);
33153 + tmp.dentry = path->dentry->d_parent;
33154 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33163 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33166 + struct dentry *d;
33170 + d = path->dentry;
33171 + path->dentry = d->d_parent;
33172 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33173 + path->dentry = d;
33174 + if (unlikely(err))
33178 + err = vfs_mknod(dir, path->dentry, mode, dev);
33181 + struct path tmp = *path;
33184 + vfsub_update_h_iattr(&tmp, &did);
33186 + tmp.dentry = path->dentry->d_parent;
33187 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33196 +static int au_test_nlink(struct inode *inode)
33198 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33200 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33201 + || inode->i_nlink < link_max)
33206 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33207 + struct inode **delegated_inode)
33210 + struct dentry *d;
33214 + err = au_test_nlink(d_inode(src_dentry));
33215 + if (unlikely(err))
33218 + /* we don't call may_linkat() */
33219 + d = path->dentry;
33220 + path->dentry = d->d_parent;
33221 + err = security_path_link(src_dentry, path, d);
33222 + path->dentry = d;
33223 + if (unlikely(err))
33227 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
33230 + struct path tmp = *path;
33233 + /* fuse has different memory inode for the same inumber */
33234 + vfsub_update_h_iattr(&tmp, &did);
33236 + tmp.dentry = path->dentry->d_parent;
33237 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33238 + tmp.dentry = src_dentry;
33239 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33248 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33249 + struct inode *dir, struct path *path,
33250 + struct inode **delegated_inode, unsigned int flags)
33253 + struct path tmp = {
33256 + struct dentry *d;
33259 + IMustLock(src_dir);
33261 + d = path->dentry;
33262 + path->dentry = d->d_parent;
33263 + tmp.dentry = src_dentry->d_parent;
33264 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33265 + path->dentry = d;
33266 + if (unlikely(err))
33270 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
33271 + delegated_inode, flags);
33276 + tmp.dentry = d->d_parent;
33277 + vfsub_update_h_iattr(&tmp, &did);
33279 + tmp.dentry = src_dentry;
33280 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33281 + tmp.dentry = src_dentry->d_parent;
33282 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33291 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33294 + struct dentry *d;
33298 + d = path->dentry;
33299 + path->dentry = d->d_parent;
33300 + err = security_path_mkdir(path, d, mode);
33301 + path->dentry = d;
33302 + if (unlikely(err))
33306 + err = vfs_mkdir(dir, path->dentry, mode);
33309 + struct path tmp = *path;
33312 + vfsub_update_h_iattr(&tmp, &did);
33314 + tmp.dentry = path->dentry->d_parent;
33315 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33324 +int vfsub_rmdir(struct inode *dir, struct path *path)
33327 + struct dentry *d;
33331 + d = path->dentry;
33332 + path->dentry = d->d_parent;
33333 + err = security_path_rmdir(path, d);
33334 + path->dentry = d;
33335 + if (unlikely(err))
33339 + err = vfs_rmdir(dir, path->dentry);
33342 + struct path tmp = {
33343 + .dentry = path->dentry->d_parent,
33347 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33354 +/* ---------------------------------------------------------------------- */
33356 +/* todo: support mmap_sem? */
33357 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33363 + err = vfs_read(file, ubuf, count, ppos);
33366 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33370 +/* todo: kernel_read()? */
33371 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33375 + mm_segment_t oldfs;
33382 + oldfs = get_fs();
33383 + set_fs(KERNEL_DS);
33384 + err = vfsub_read_u(file, buf.u, count, ppos);
33389 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33395 + err = vfs_write(file, ubuf, count, ppos);
33398 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33402 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33405 + mm_segment_t oldfs;
33408 + const char __user *u;
33412 + oldfs = get_fs();
33413 + set_fs(KERNEL_DS);
33414 + err = vfsub_write_u(file, buf.u, count, ppos);
33419 +int vfsub_flush(struct file *file, fl_owner_t id)
33424 + if (file->f_op->flush) {
33425 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33426 + err = file->f_op->flush(file, id);
33429 + err = file->f_op->flush(file, id);
33433 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33439 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33443 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33446 + err = iterate_dir(file, ctx);
33449 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33454 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33455 + struct pipe_inode_info *pipe, size_t len,
33456 + unsigned int flags)
33461 + err = do_splice_to(in, ppos, pipe, len, flags);
33463 + file_accessed(in);
33465 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33469 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33470 + loff_t *ppos, size_t len, unsigned int flags)
33475 + err = do_splice_from(pipe, out, ppos, len, flags);
33478 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33482 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33486 + /* file can be NULL */
33488 + err = vfs_fsync(file, datasync);
33492 + AuDebugOn(!file);
33493 + path = &file->f_path;
33495 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33500 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33501 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33502 + struct file *h_file)
33505 + struct inode *h_inode;
33506 + struct super_block *h_sb;
33509 + err = vfsub_truncate(h_path, length);
33513 + h_inode = d_inode(h_path->dentry);
33514 + h_sb = h_inode->i_sb;
33516 + sb_start_write(h_sb);
33518 + err = locks_verify_truncate(h_inode, h_file, length);
33520 + err = security_path_truncate(h_path);
33523 + err = do_truncate(h_path->dentry, length, attr, h_file);
33527 + sb_end_write(h_sb);
33534 +/* ---------------------------------------------------------------------- */
33536 +struct au_vfsub_mkdir_args {
33538 + struct inode *dir;
33539 + struct path *path;
33543 +static void au_call_vfsub_mkdir(void *args)
33545 + struct au_vfsub_mkdir_args *a = args;
33546 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33549 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33551 + int err, do_sio, wkq_err;
33553 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33556 + err = vfsub_mkdir(dir, path, mode);
33559 + struct au_vfsub_mkdir_args args = {
33565 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33566 + if (unlikely(wkq_err))
33573 +struct au_vfsub_rmdir_args {
33575 + struct inode *dir;
33576 + struct path *path;
33579 +static void au_call_vfsub_rmdir(void *args)
33581 + struct au_vfsub_rmdir_args *a = args;
33582 + *a->errp = vfsub_rmdir(a->dir, a->path);
33585 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33587 + int err, do_sio, wkq_err;
33589 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33592 + err = vfsub_rmdir(dir, path);
33595 + struct au_vfsub_rmdir_args args = {
33600 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33601 + if (unlikely(wkq_err))
33608 +/* ---------------------------------------------------------------------- */
33610 +struct notify_change_args {
33612 + struct path *path;
33613 + struct iattr *ia;
33614 + struct inode **delegated_inode;
33617 +static void call_notify_change(void *args)
33619 + struct notify_change_args *a = args;
33620 + struct inode *h_inode;
33622 + h_inode = d_inode(a->path->dentry);
33623 + IMustLock(h_inode);
33625 + *a->errp = -EPERM;
33626 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33628 + *a->errp = notify_change(a->path->dentry, a->ia,
33629 + a->delegated_inode);
33632 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33634 + AuTraceErr(*a->errp);
33637 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33638 + struct inode **delegated_inode)
33641 + struct notify_change_args args = {
33645 + .delegated_inode = delegated_inode
33648 + call_notify_change(&args);
33653 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33654 + struct inode **delegated_inode)
33656 + int err, wkq_err;
33657 + struct notify_change_args args = {
33661 + .delegated_inode = delegated_inode
33664 + wkq_err = au_wkq_wait(call_notify_change, &args);
33665 + if (unlikely(wkq_err))
33671 +/* ---------------------------------------------------------------------- */
33673 +struct unlink_args {
33675 + struct inode *dir;
33676 + struct path *path;
33677 + struct inode **delegated_inode;
33680 +static void call_unlink(void *args)
33682 + struct unlink_args *a = args;
33683 + struct dentry *d = a->path->dentry;
33684 + struct inode *h_inode;
33685 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33686 + && au_dcount(d) == 1);
33688 + IMustLock(a->dir);
33690 + a->path->dentry = d->d_parent;
33691 + *a->errp = security_path_unlink(a->path, d);
33692 + a->path->dentry = d;
33693 + if (unlikely(*a->errp))
33696 + if (!stop_sillyrename)
33699 + if (d_is_positive(d)) {
33700 + h_inode = d_inode(d);
33705 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33708 + struct path tmp = {
33709 + .dentry = d->d_parent,
33710 + .mnt = a->path->mnt
33712 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33715 + if (!stop_sillyrename)
33720 + AuTraceErr(*a->errp);
33724 + * @dir: must be locked.
33725 + * @dentry: target dentry.
33727 +int vfsub_unlink(struct inode *dir, struct path *path,
33728 + struct inode **delegated_inode, int force)
33731 + struct unlink_args args = {
33735 + .delegated_inode = delegated_inode
33739 + call_unlink(&args);
33743 + wkq_err = au_wkq_wait(call_unlink, &args);
33744 + if (unlikely(wkq_err))
33750 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33751 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33752 +++ linux/fs/aufs/vfsub.h 2019-05-06 09:03:04.820143837 +0200
33754 +/* SPDX-License-Identifier: GPL-2.0 */
33756 + * Copyright (C) 2005-2019 Junjiro R. Okajima
33758 + * This program, aufs is free software; you can redistribute it and/or modify
33759 + * it under the terms of the GNU General Public License as published by
33760 + * the Free Software Foundation; either version 2 of the License, or
33761 + * (at your option) any later version.
33763 + * This program is distributed in the hope that it will be useful,
33764 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33765 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33766 + * GNU General Public License for more details.
33768 + * You should have received a copy of the GNU General Public License
33769 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33773 + * sub-routines for VFS
33776 +#ifndef __AUFS_VFSUB_H__
33777 +#define __AUFS_VFSUB_H__
33781 +#include <linux/fs.h>
33782 +#include <linux/mount.h>
33783 +#include <linux/posix_acl.h>
33784 +#include <linux/xattr.h>
33785 +#include "debug.h"
33787 +/* copied from linux/fs/internal.h */
33788 +/* todo: BAD approach!! */
33789 +extern void __mnt_drop_write(struct vfsmount *);
33790 +extern struct file *alloc_empty_file(int, const struct cred *);
33792 +/* ---------------------------------------------------------------------- */
33794 +/* lock subclass for lower inode */
33795 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33796 +/* reduce? gave up. */
33798 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33799 + AuLsc_I_PARENT, /* lower inode, parent first */
33800 + AuLsc_I_PARENT2, /* copyup dirs */
33801 + AuLsc_I_PARENT3, /* copyup wh */
33807 +/* to debug easier, do not make them inlined functions */
33808 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33809 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33811 +/* ---------------------------------------------------------------------- */
33813 +static inline void vfsub_drop_nlink(struct inode *inode)
33815 + AuDebugOn(!inode->i_nlink);
33816 + drop_nlink(inode);
33819 +static inline void vfsub_dead_dir(struct inode *inode)
33821 + AuDebugOn(!S_ISDIR(inode->i_mode));
33822 + inode->i_flags |= S_DEAD;
33823 + clear_nlink(inode);
33826 +static inline int vfsub_native_ro(struct inode *inode)
33828 + return sb_rdonly(inode->i_sb)
33829 + || IS_RDONLY(inode)
33830 + /* || IS_APPEND(inode) */
33831 + || IS_IMMUTABLE(inode);
33834 +#ifdef CONFIG_AUFS_BR_FUSE
33835 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33837 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33840 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33842 +/* ---------------------------------------------------------------------- */
33844 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33845 +struct file *vfsub_dentry_open(struct path *path, int flags);
33846 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33848 +struct vfsub_aopen_args {
33849 + struct file *file;
33850 + unsigned int open_flag;
33851 + umode_t create_mode;
33852 + struct au_branch *br;
33854 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33855 + struct vfsub_aopen_args *args);
33856 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33858 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33859 + struct dentry *parent, int len);
33860 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33863 +struct vfsub_lkup_one_args {
33864 + struct dentry **errp;
33865 + struct qstr *name;
33866 + struct dentry *parent;
33869 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33870 + struct dentry *parent)
33872 + return vfsub_lookup_one_len(name->name, parent, name->len);
33875 +void vfsub_call_lkup_one(void *args);
33877 +/* ---------------------------------------------------------------------- */
33879 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33884 + err = mnt_want_write(mnt);
33889 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33892 + mnt_drop_write(mnt);
33896 +#if 0 /* reserved */
33897 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33900 + mnt_drop_write_file(file);
33905 +/* ---------------------------------------------------------------------- */
33908 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33909 + struct dentry *d2, struct au_hinode *hdir2);
33910 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33911 + struct dentry *d2, struct au_hinode *hdir2);
33913 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33915 +int vfsub_symlink(struct inode *dir, struct path *path,
33916 + const char *symname);
33917 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33918 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33919 + struct path *path, struct inode **delegated_inode);
33920 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33921 + struct inode *hdir, struct path *path,
33922 + struct inode **delegated_inode, unsigned int flags);
33923 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33924 +int vfsub_rmdir(struct inode *dir, struct path *path);
33926 +/* ---------------------------------------------------------------------- */
33928 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33930 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33932 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33934 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33936 +int vfsub_flush(struct file *file, fl_owner_t id);
33937 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33939 +static inline loff_t vfsub_f_size_read(struct file *file)
33941 + return i_size_read(file_inode(file));
33944 +static inline unsigned int vfsub_file_flags(struct file *file)
33946 + unsigned int flags;
33948 + spin_lock(&file->f_lock);
33949 + flags = file->f_flags;
33950 + spin_unlock(&file->f_lock);
33955 +static inline int vfsub_file_execed(struct file *file)
33957 + /* todo: direct access f_flags */
33958 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33961 +#if 0 /* reserved */
33962 +static inline void vfsub_file_accessed(struct file *h_file)
33964 + file_accessed(h_file);
33965 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33969 +#if 0 /* reserved */
33970 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33971 + struct dentry *h_dentry)
33973 + struct path h_path = {
33974 + .dentry = h_dentry,
33977 + touch_atime(&h_path);
33978 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33982 +static inline int vfsub_update_time(struct inode *h_inode,
33983 + struct timespec64 *ts, int flags)
33985 + return update_time(h_inode, ts, flags);
33986 + /* no vfsub_update_h_iattr() since we don't have struct path */
33989 +#ifdef CONFIG_FS_POSIX_ACL
33990 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33994 + err = posix_acl_chmod(h_inode, h_mode);
33995 + if (err == -EOPNOTSUPP)
34000 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
34003 +long vfsub_splice_to(struct file *in, loff_t *ppos,
34004 + struct pipe_inode_info *pipe, size_t len,
34005 + unsigned int flags);
34006 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
34007 + loff_t *ppos, size_t len, unsigned int flags);
34009 +static inline long vfsub_truncate(struct path *path, loff_t length)
34014 + err = vfs_truncate(path, length);
34019 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
34020 + struct file *h_file);
34021 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
34024 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
34027 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
34033 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
34039 +/* copy_file_range(2) is a systemcall */
34040 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
34041 + struct file *dst, loff_t dst_pos,
34042 + size_t len, unsigned int flags)
34047 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
34053 +/* ---------------------------------------------------------------------- */
34055 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
34060 + err = vfs_llseek(file, offset, origin);
34065 +/* ---------------------------------------------------------------------- */
34067 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
34068 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
34069 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
34070 + struct inode **delegated_inode);
34071 +int vfsub_notify_change(struct path *path, struct iattr *ia,
34072 + struct inode **delegated_inode);
34073 +int vfsub_unlink(struct inode *dir, struct path *path,
34074 + struct inode **delegated_inode, int force);
34076 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
34078 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
34081 +/* ---------------------------------------------------------------------- */
34083 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
34084 + const void *value, size_t size, int flags)
34089 + err = vfs_setxattr(dentry, name, value, size, flags);
34095 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
34100 + err = vfs_removexattr(dentry, name);
34106 +#endif /* __KERNEL__ */
34107 +#endif /* __AUFS_VFSUB_H__ */
34108 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
34109 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
34110 +++ linux/fs/aufs/wbr_policy.c 2019-03-05 12:13:00.145891204 +0100
34112 +// SPDX-License-Identifier: GPL-2.0
34114 + * Copyright (C) 2005-2019 Junjiro R. Okajima
34116 + * This program, aufs is free software; you can redistribute it and/or modify
34117 + * it under the terms of the GNU General Public License as published by
34118 + * the Free Software Foundation; either version 2 of the License, or
34119 + * (at your option) any later version.
34121 + * This program is distributed in the hope that it will be useful,
34122 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34123 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34124 + * GNU General Public License for more details.
34126 + * You should have received a copy of the GNU General Public License
34127 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34131 + * policies for selecting one among multiple writable branches
34134 +#include <linux/statfs.h>
34137 +/* subset of cpup_attr() */
34138 +static noinline_for_stack
34139 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34143 + struct inode *h_isrc;
34145 + h_isrc = d_inode(h_src);
34146 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34147 + ia.ia_mode = h_isrc->i_mode;
34148 + ia.ia_uid = h_isrc->i_uid;
34149 + ia.ia_gid = h_isrc->i_gid;
34150 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34151 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34152 + /* no delegation since it is just created */
34153 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34155 + /* is this nfs only? */
34156 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34157 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34158 + ia.ia_mode = h_isrc->i_mode;
34159 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34165 +#define AuCpdown_PARENT_OPQ 1
34166 +#define AuCpdown_WHED (1 << 1)
34167 +#define AuCpdown_MADE_DIR (1 << 2)
34168 +#define AuCpdown_DIROPQ (1 << 3)
34169 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34170 +#define au_fset_cpdown(flags, name) \
34171 + do { (flags) |= AuCpdown_##name; } while (0)
34172 +#define au_fclr_cpdown(flags, name) \
34173 + do { (flags) &= ~AuCpdown_##name; } while (0)
34175 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34176 + unsigned int *flags)
34179 + struct dentry *opq_dentry;
34181 + opq_dentry = au_diropq_create(dentry, bdst);
34182 + err = PTR_ERR(opq_dentry);
34183 + if (IS_ERR(opq_dentry))
34185 + dput(opq_dentry);
34186 + au_fset_cpdown(*flags, DIROPQ);
34192 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34193 + struct inode *dir, aufs_bindex_t bdst)
34196 + struct path h_path;
34197 + struct au_branch *br;
34199 + br = au_sbr(dentry->d_sb, bdst);
34200 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34201 + err = PTR_ERR(h_path.dentry);
34202 + if (IS_ERR(h_path.dentry))
34206 + if (d_is_positive(h_path.dentry)) {
34207 + h_path.mnt = au_br_mnt(br);
34208 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34211 + dput(h_path.dentry);
34217 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34218 + struct au_pin *pin,
34219 + struct dentry *h_parent, void *arg)
34222 + aufs_bindex_t bopq, btop;
34223 + struct path h_path;
34224 + struct dentry *parent;
34225 + struct inode *h_dir, *h_inode, *inode, *dir;
34226 + unsigned int *flags = arg;
34228 + btop = au_dbtop(dentry);
34229 + /* dentry is di-locked */
34230 + parent = dget_parent(dentry);
34231 + dir = d_inode(parent);
34232 + h_dir = d_inode(h_parent);
34233 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34234 + IMustLock(h_dir);
34236 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34237 + if (unlikely(err < 0))
34239 + h_path.dentry = au_h_dptr(dentry, bdst);
34240 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34241 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34242 + if (unlikely(err))
34244 + au_fset_cpdown(*flags, MADE_DIR);
34246 + bopq = au_dbdiropq(dentry);
34247 + au_fclr_cpdown(*flags, WHED);
34248 + au_fclr_cpdown(*flags, DIROPQ);
34249 + if (au_dbwh(dentry) == bdst)
34250 + au_fset_cpdown(*flags, WHED);
34251 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34252 + au_fset_cpdown(*flags, PARENT_OPQ);
34253 + h_inode = d_inode(h_path.dentry);
34254 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34255 + if (au_ftest_cpdown(*flags, WHED)) {
34256 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34257 + if (unlikely(err)) {
34258 + inode_unlock(h_inode);
34263 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34264 + inode_unlock(h_inode);
34265 + if (unlikely(err))
34268 + if (au_ftest_cpdown(*flags, WHED)) {
34269 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34270 + if (unlikely(err))
34274 + inode = d_inode(dentry);
34275 + if (au_ibbot(inode) < bdst)
34276 + au_set_ibbot(inode, bdst);
34277 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34278 + au_hi_flags(inode, /*isdir*/1));
34279 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34280 + goto out; /* success */
34284 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34285 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34286 + rerr = au_diropq_remove(dentry, bdst);
34287 + inode_unlock(h_inode);
34288 + if (unlikely(rerr)) {
34289 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34290 + dentry, bdst, rerr);
34296 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34297 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34298 + if (unlikely(rerr)) {
34299 + AuIOErr("failed removing %pd b%d (%d)\n",
34300 + dentry, bdst, rerr);
34305 + au_set_h_dptr(dentry, bdst, NULL);
34306 + if (au_dbbot(dentry) == bdst)
34307 + au_update_dbbot(dentry);
34313 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34316 + unsigned int flags;
34319 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34324 +/* ---------------------------------------------------------------------- */
34326 +/* policies for create */
34328 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34330 + int err, i, j, ndentry;
34331 + aufs_bindex_t bopq;
34332 + struct au_dcsub_pages dpages;
34333 + struct au_dpage *dpage;
34334 + struct dentry **dentries, *parent, *d;
34336 + err = au_dpages_init(&dpages, GFP_NOFS);
34337 + if (unlikely(err))
34339 + parent = dget_parent(dentry);
34340 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34341 + if (unlikely(err))
34345 + for (i = 0; i < dpages.ndpage; i++) {
34346 + dpage = dpages.dpages + i;
34347 + dentries = dpage->dentries;
34348 + ndentry = dpage->ndentry;
34349 + for (j = 0; j < ndentry; j++) {
34351 + di_read_lock_parent2(d, !AuLock_IR);
34352 + bopq = au_dbdiropq(d);
34353 + di_read_unlock(d, !AuLock_IR);
34354 + if (bopq >= 0 && bopq < err)
34361 + au_dpages_free(&dpages);
34366 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34368 + for (; bindex >= 0; bindex--)
34369 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34374 +/* top down parent */
34375 +static int au_wbr_create_tdp(struct dentry *dentry,
34376 + unsigned int flags __maybe_unused)
34379 + aufs_bindex_t btop, bindex;
34380 + struct super_block *sb;
34381 + struct dentry *parent, *h_parent;
34383 + sb = dentry->d_sb;
34384 + btop = au_dbtop(dentry);
34386 + if (!au_br_rdonly(au_sbr(sb, btop)))
34390 + parent = dget_parent(dentry);
34391 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34392 + h_parent = au_h_dptr(parent, bindex);
34393 + if (!h_parent || d_is_negative(h_parent))
34396 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34403 + /* bottom up here */
34404 + if (unlikely(err < 0)) {
34405 + err = au_wbr_bu(sb, btop - 1);
34407 + err = au_wbr_nonopq(dentry, err);
34411 + AuDbg("b%d\n", err);
34415 +/* ---------------------------------------------------------------------- */
34417 +/* an exception for the policy other than tdp */
34418 +static int au_wbr_create_exp(struct dentry *dentry)
34421 + aufs_bindex_t bwh, bdiropq;
34422 + struct dentry *parent;
34425 + bwh = au_dbwh(dentry);
34426 + parent = dget_parent(dentry);
34427 + bdiropq = au_dbdiropq(parent);
34429 + if (bdiropq >= 0)
34430 + err = min(bdiropq, bwh);
34433 + AuDbg("%d\n", err);
34434 + } else if (bdiropq >= 0) {
34436 + AuDbg("%d\n", err);
34441 + err = au_wbr_nonopq(dentry, err);
34443 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34446 + AuDbg("%d\n", err);
34450 +/* ---------------------------------------------------------------------- */
34453 +static int au_wbr_create_init_rr(struct super_block *sb)
34457 + err = au_wbr_bu(sb, au_sbbot(sb));
34458 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34461 + AuDbg("b%d\n", err);
34465 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34469 + aufs_bindex_t bindex, bbot;
34470 + struct super_block *sb;
34473 + err = au_wbr_create_exp(dentry);
34477 + sb = dentry->d_sb;
34478 + next = &au_sbi(sb)->si_wbr_rr_next;
34479 + bbot = au_sbbot(sb);
34481 + for (bindex = 0; bindex <= bbot; bindex++) {
34482 + if (!au_ftest_wbr(flags, DIR)) {
34483 + err = atomic_dec_return(next) + 1;
34484 + /* modulo for 0 is meaningless */
34485 + if (unlikely(!err))
34486 + err = atomic_dec_return(next) + 1;
34488 + err = atomic_read(next);
34489 + AuDbg("%d\n", err);
34492 + AuDbg("%d\n", err);
34493 + if (!au_br_rdonly(au_sbr(sb, err)))
34499 + err = au_wbr_nonopq(dentry, err);
34502 + AuDbg("%d\n", err);
34506 +/* ---------------------------------------------------------------------- */
34508 +/* most free space */
34509 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34511 + struct super_block *sb;
34512 + struct au_branch *br;
34513 + struct au_wbr_mfs *mfs;
34514 + struct dentry *h_parent;
34515 + aufs_bindex_t bindex, bbot;
34517 + unsigned long long b, bavail;
34518 + struct path h_path;
34519 + /* reduce the stack usage */
34520 + struct kstatfs *st;
34522 + st = kmalloc(sizeof(*st), GFP_NOFS);
34523 + if (unlikely(!st)) {
34524 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34529 + sb = dentry->d_sb;
34530 + mfs = &au_sbi(sb)->si_wbr_mfs;
34531 + MtxMustLock(&mfs->mfs_lock);
34532 + mfs->mfs_bindex = -EROFS;
34533 + mfs->mfsrr_bytes = 0;
34536 + bbot = au_sbbot(sb);
34538 + bindex = au_dbtop(parent);
34539 + bbot = au_dbtaildir(parent);
34542 + for (; bindex <= bbot; bindex++) {
34544 + h_parent = au_h_dptr(parent, bindex);
34545 + if (!h_parent || d_is_negative(h_parent))
34548 + br = au_sbr(sb, bindex);
34549 + if (au_br_rdonly(br))
34552 + /* sb->s_root for NFS is unreliable */
34553 + h_path.mnt = au_br_mnt(br);
34554 + h_path.dentry = h_path.mnt->mnt_root;
34555 + err = vfs_statfs(&h_path, st);
34556 + if (unlikely(err)) {
34557 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34561 + /* when the available size is equal, select the lower one */
34562 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34563 + || sizeof(b) < sizeof(st->f_bsize));
34564 + b = st->f_bavail * st->f_bsize;
34565 + br->br_wbr->wbr_bytes = b;
34566 + if (b >= bavail) {
34568 + mfs->mfs_bindex = bindex;
34569 + mfs->mfs_jiffy = jiffies;
34573 + mfs->mfsrr_bytes = bavail;
34574 + AuDbg("b%d\n", mfs->mfs_bindex);
34575 + au_kfree_rcu(st);
34578 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34581 + struct dentry *parent;
34582 + struct super_block *sb;
34583 + struct au_wbr_mfs *mfs;
34585 + err = au_wbr_create_exp(dentry);
34589 + sb = dentry->d_sb;
34591 + if (au_ftest_wbr(flags, PARENT))
34592 + parent = dget_parent(dentry);
34593 + mfs = &au_sbi(sb)->si_wbr_mfs;
34594 + mutex_lock(&mfs->mfs_lock);
34595 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34596 + || mfs->mfs_bindex < 0
34597 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34598 + au_mfs(dentry, parent);
34599 + mutex_unlock(&mfs->mfs_lock);
34600 + err = mfs->mfs_bindex;
34604 + err = au_wbr_nonopq(dentry, err);
34607 + AuDbg("b%d\n", err);
34611 +static int au_wbr_create_init_mfs(struct super_block *sb)
34613 + struct au_wbr_mfs *mfs;
34615 + mfs = &au_sbi(sb)->si_wbr_mfs;
34616 + mutex_init(&mfs->mfs_lock);
34617 + mfs->mfs_jiffy = 0;
34618 + mfs->mfs_bindex = -EROFS;
34623 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34625 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34629 +/* ---------------------------------------------------------------------- */
34631 +/* top down regardless parent, and then mfs */
34632 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34633 + unsigned int flags __maybe_unused)
34636 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34637 + unsigned long long watermark;
34638 + struct super_block *sb;
34639 + struct au_wbr_mfs *mfs;
34640 + struct au_branch *br;
34641 + struct dentry *parent;
34643 + sb = dentry->d_sb;
34644 + mfs = &au_sbi(sb)->si_wbr_mfs;
34645 + mutex_lock(&mfs->mfs_lock);
34646 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34647 + || mfs->mfs_bindex < 0)
34648 + au_mfs(dentry, /*parent*/NULL);
34649 + watermark = mfs->mfsrr_watermark;
34650 + bmfs = mfs->mfs_bindex;
34651 + mutex_unlock(&mfs->mfs_lock);
34653 + /* another style of au_wbr_create_exp() */
34654 + bwh = au_dbwh(dentry);
34655 + parent = dget_parent(dentry);
34656 + btail = au_dbtaildir(parent);
34657 + if (bwh >= 0 && bwh < btail)
34660 + err = au_wbr_nonopq(dentry, btail);
34661 + if (unlikely(err < 0))
34665 + for (bindex = 0; bindex <= btail; bindex++) {
34666 + br = au_sbr(sb, bindex);
34667 + if (au_br_rdonly(br))
34669 + if (br->br_wbr->wbr_bytes > watermark) {
34680 + AuDbg("b%d\n", err);
34684 +/* ---------------------------------------------------------------------- */
34686 +/* most free space and then round robin */
34687 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34690 + struct au_wbr_mfs *mfs;
34692 + err = au_wbr_create_mfs(dentry, flags);
34694 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34695 + mutex_lock(&mfs->mfs_lock);
34696 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34697 + err = au_wbr_create_rr(dentry, flags);
34698 + mutex_unlock(&mfs->mfs_lock);
34701 + AuDbg("b%d\n", err);
34705 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34709 + au_wbr_create_init_mfs(sb); /* ignore */
34710 + err = au_wbr_create_init_rr(sb);
34715 +/* ---------------------------------------------------------------------- */
34717 +/* top down parent and most free space */
34718 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34721 + unsigned long long b;
34722 + aufs_bindex_t bindex, btop, bbot;
34723 + struct super_block *sb;
34724 + struct dentry *parent, *h_parent;
34725 + struct au_branch *br;
34727 + err = au_wbr_create_tdp(dentry, flags);
34728 + if (unlikely(err < 0))
34730 + parent = dget_parent(dentry);
34731 + btop = au_dbtop(parent);
34732 + bbot = au_dbtaildir(parent);
34733 + if (btop == bbot)
34734 + goto out_parent; /* success */
34736 + e2 = au_wbr_create_mfs(dentry, flags);
34738 + goto out_parent; /* success */
34740 + /* when the available size is equal, select upper one */
34741 + sb = dentry->d_sb;
34742 + br = au_sbr(sb, err);
34743 + b = br->br_wbr->wbr_bytes;
34744 + AuDbg("b%d, %llu\n", err, b);
34746 + for (bindex = btop; bindex <= bbot; bindex++) {
34747 + h_parent = au_h_dptr(parent, bindex);
34748 + if (!h_parent || d_is_negative(h_parent))
34751 + br = au_sbr(sb, bindex);
34752 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34753 + b = br->br_wbr->wbr_bytes;
34755 + AuDbg("b%d, %llu\n", err, b);
34760 + err = au_wbr_nonopq(dentry, err);
34765 + AuDbg("b%d\n", err);
34769 +/* ---------------------------------------------------------------------- */
34772 + * - top down parent
34773 + * - most free space with parent
34774 + * - most free space round-robin regardless parent
34776 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34779 + unsigned long long watermark;
34780 + struct super_block *sb;
34781 + struct au_branch *br;
34782 + struct au_wbr_mfs *mfs;
34784 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34785 + if (unlikely(err < 0))
34788 + sb = dentry->d_sb;
34789 + br = au_sbr(sb, err);
34790 + mfs = &au_sbi(sb)->si_wbr_mfs;
34791 + mutex_lock(&mfs->mfs_lock);
34792 + watermark = mfs->mfsrr_watermark;
34793 + mutex_unlock(&mfs->mfs_lock);
34794 + if (br->br_wbr->wbr_bytes < watermark)
34795 + /* regardless the parent dir */
34796 + err = au_wbr_create_mfsrr(dentry, flags);
34799 + AuDbg("b%d\n", err);
34803 +/* ---------------------------------------------------------------------- */
34805 +/* policies for copyup */
34807 +/* top down parent */
34808 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34810 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34813 +/* bottom up parent */
34814 +static int au_wbr_copyup_bup(struct dentry *dentry)
34817 + aufs_bindex_t bindex, btop;
34818 + struct dentry *parent, *h_parent;
34819 + struct super_block *sb;
34822 + sb = dentry->d_sb;
34823 + parent = dget_parent(dentry);
34824 + btop = au_dbtop(parent);
34825 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34826 + h_parent = au_h_dptr(parent, bindex);
34827 + if (!h_parent || d_is_negative(h_parent))
34830 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34837 + /* bottom up here */
34838 + if (unlikely(err < 0))
34839 + err = au_wbr_bu(sb, btop - 1);
34841 + AuDbg("b%d\n", err);
34846 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34850 + err = au_wbr_bu(dentry->d_sb, btop);
34851 + AuDbg("b%d\n", err);
34853 + err = au_wbr_nonopq(dentry, err);
34855 + AuDbg("b%d\n", err);
34859 +static int au_wbr_copyup_bu(struct dentry *dentry)
34862 + aufs_bindex_t btop;
34864 + btop = au_dbtop(dentry);
34865 + err = au_wbr_do_copyup_bu(dentry, btop);
34869 +/* ---------------------------------------------------------------------- */
34871 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34872 + [AuWbrCopyup_TDP] = {
34873 + .copyup = au_wbr_copyup_tdp
34875 + [AuWbrCopyup_BUP] = {
34876 + .copyup = au_wbr_copyup_bup
34878 + [AuWbrCopyup_BU] = {
34879 + .copyup = au_wbr_copyup_bu
34883 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34884 + [AuWbrCreate_TDP] = {
34885 + .create = au_wbr_create_tdp
34887 + [AuWbrCreate_RR] = {
34888 + .create = au_wbr_create_rr,
34889 + .init = au_wbr_create_init_rr
34891 + [AuWbrCreate_MFS] = {
34892 + .create = au_wbr_create_mfs,
34893 + .init = au_wbr_create_init_mfs,
34894 + .fin = au_wbr_create_fin_mfs
34896 + [AuWbrCreate_MFSV] = {
34897 + .create = au_wbr_create_mfs,
34898 + .init = au_wbr_create_init_mfs,
34899 + .fin = au_wbr_create_fin_mfs
34901 + [AuWbrCreate_MFSRR] = {
34902 + .create = au_wbr_create_mfsrr,
34903 + .init = au_wbr_create_init_mfsrr,
34904 + .fin = au_wbr_create_fin_mfs
34906 + [AuWbrCreate_MFSRRV] = {
34907 + .create = au_wbr_create_mfsrr,
34908 + .init = au_wbr_create_init_mfsrr,
34909 + .fin = au_wbr_create_fin_mfs
34911 + [AuWbrCreate_TDMFS] = {
34912 + .create = au_wbr_create_tdmfs,
34913 + .init = au_wbr_create_init_mfs,
34914 + .fin = au_wbr_create_fin_mfs
34916 + [AuWbrCreate_TDMFSV] = {
34917 + .create = au_wbr_create_tdmfs,
34918 + .init = au_wbr_create_init_mfs,
34919 + .fin = au_wbr_create_fin_mfs
34921 + [AuWbrCreate_PMFS] = {
34922 + .create = au_wbr_create_pmfs,
34923 + .init = au_wbr_create_init_mfs,
34924 + .fin = au_wbr_create_fin_mfs
34926 + [AuWbrCreate_PMFSV] = {
34927 + .create = au_wbr_create_pmfs,
34928 + .init = au_wbr_create_init_mfs,
34929 + .fin = au_wbr_create_fin_mfs
34931 + [AuWbrCreate_PMFSRR] = {
34932 + .create = au_wbr_create_pmfsrr,
34933 + .init = au_wbr_create_init_mfsrr,
34934 + .fin = au_wbr_create_fin_mfs
34936 + [AuWbrCreate_PMFSRRV] = {
34937 + .create = au_wbr_create_pmfsrr,
34938 + .init = au_wbr_create_init_mfsrr,
34939 + .fin = au_wbr_create_fin_mfs
34942 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34943 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34944 +++ linux/fs/aufs/whout.c 2019-03-05 12:13:00.145891204 +0100
34946 +// SPDX-License-Identifier: GPL-2.0
34948 + * Copyright (C) 2005-2019 Junjiro R. Okajima
34950 + * This program, aufs is free software; you can redistribute it and/or modify
34951 + * it under the terms of the GNU General Public License as published by
34952 + * the Free Software Foundation; either version 2 of the License, or
34953 + * (at your option) any later version.
34955 + * This program is distributed in the hope that it will be useful,
34956 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34957 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34958 + * GNU General Public License for more details.
34960 + * You should have received a copy of the GNU General Public License
34961 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34965 + * whiteout for logical deletion and opaque directory
34970 +#define WH_MASK 0444
34973 + * If a directory contains this file, then it is opaque. We start with the
34974 + * .wh. flag so that it is blocked by lookup.
34976 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34977 + sizeof(AUFS_WH_DIROPQ) - 1);
34980 + * generate whiteout name, which is NOT terminated by NULL.
34981 + * @name: original d_name.name
34982 + * @len: original d_name.len
34983 + * @wh: whiteout qstr
34984 + * returns zero when succeeds, otherwise error.
34985 + * succeeded value as wh->name should be freed by kfree().
34987 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34991 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34992 + return -ENAMETOOLONG;
34994 + wh->len = name->len + AUFS_WH_PFX_LEN;
34995 + p = kmalloc(wh->len, GFP_NOFS);
34998 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34999 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
35006 +/* ---------------------------------------------------------------------- */
35009 + * test if the @wh_name exists under @h_parent.
35010 + * @try_sio specifies the necessary of super-io.
35012 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
35015 + struct dentry *wh_dentry;
35018 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
35020 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
35021 + err = PTR_ERR(wh_dentry);
35022 + if (IS_ERR(wh_dentry)) {
35023 + if (err == -ENAMETOOLONG)
35029 + if (d_is_negative(wh_dentry))
35030 + goto out_wh; /* success */
35033 + if (d_is_reg(wh_dentry))
35034 + goto out_wh; /* success */
35037 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
35038 + wh_dentry, d_inode(wh_dentry)->i_mode);
35047 + * test if the @h_dentry sets opaque or not.
35049 +int au_diropq_test(struct dentry *h_dentry)
35052 + struct inode *h_dir;
35054 + h_dir = d_inode(h_dentry);
35055 + err = au_wh_test(h_dentry, &diropq_name,
35056 + au_test_h_perm_sio(h_dir, MAY_EXEC));
35061 + * returns a negative dentry whose name is unique and temporary.
35063 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35064 + struct qstr *prefix)
35066 + struct dentry *dentry;
35068 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
35070 + /* strict atomic_t is unnecessary here */
35071 + static unsigned short cnt;
35074 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
35077 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
35078 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
35079 + dentry = ERR_PTR(-ENAMETOOLONG);
35080 + if (unlikely(qs.len > NAME_MAX))
35082 + dentry = ERR_PTR(-ENOMEM);
35083 + name = kmalloc(qs.len + 1, GFP_NOFS);
35084 + if (unlikely(!name))
35088 + /* doubly whiteout-ed */
35089 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
35090 + p = name + AUFS_WH_PFX_LEN * 2;
35091 + memcpy(p, prefix->name, prefix->len);
35092 + p += prefix->len;
35094 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
35097 + for (i = 0; i < 3; i++) {
35098 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
35099 + dentry = au_sio_lkup_one(&qs, h_parent);
35100 + if (IS_ERR(dentry) || d_is_negative(dentry))
35104 + /* pr_warn("could not get random name\n"); */
35105 + dentry = ERR_PTR(-EEXIST);
35106 + AuDbg("%.*s\n", AuLNPair(&qs));
35110 + if (name != defname)
35111 + au_kfree_try_rcu(name);
35113 + AuTraceErrPtr(dentry);
35118 + * rename the @h_dentry on @br to the whiteouted temporary name.
35120 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
35123 + struct path h_path = {
35124 + .mnt = au_br_mnt(br)
35126 + struct inode *h_dir, *delegated;
35127 + struct dentry *h_parent;
35129 + h_parent = h_dentry->d_parent; /* dir inode is locked */
35130 + h_dir = d_inode(h_parent);
35131 + IMustLock(h_dir);
35133 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35134 + err = PTR_ERR(h_path.dentry);
35135 + if (IS_ERR(h_path.dentry))
35138 + /* under the same dir, no need to lock_rename() */
35139 + delegated = NULL;
35140 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35143 + if (unlikely(err == -EWOULDBLOCK)) {
35144 + pr_warn("cannot retry for NFSv4 delegation"
35145 + " for an internal rename\n");
35148 + dput(h_path.dentry);
35155 +/* ---------------------------------------------------------------------- */
35157 + * functions for removing a whiteout
35160 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35163 + struct inode *delegated;
35166 + * forces superio when the dir has a sticky bit.
35167 + * this may be a violation of unix fs semantics.
35169 + force = (h_dir->i_mode & S_ISVTX)
35170 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35171 + delegated = NULL;
35172 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35173 + if (unlikely(err == -EWOULDBLOCK)) {
35174 + pr_warn("cannot retry for NFSv4 delegation"
35175 + " for an internal unlink\n");
35181 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35182 + struct dentry *dentry)
35186 + err = do_unlink_wh(h_dir, h_path);
35187 + if (!err && dentry)
35188 + au_set_dbwh(dentry, -1);
35193 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
35194 + struct au_branch *br)
35197 + struct path h_path = {
35198 + .mnt = au_br_mnt(br)
35202 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
35203 + if (IS_ERR(h_path.dentry))
35204 + err = PTR_ERR(h_path.dentry);
35206 + if (d_is_reg(h_path.dentry))
35207 + err = do_unlink_wh(d_inode(h_parent), &h_path);
35208 + dput(h_path.dentry);
35214 +/* ---------------------------------------------------------------------- */
35216 + * initialize/clean whiteout for a branch
35219 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35223 + struct inode *delegated;
35225 + if (d_is_negative(whpath->dentry))
35229 + err = vfsub_rmdir(h_dir, whpath);
35231 + delegated = NULL;
35232 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35233 + if (unlikely(err == -EWOULDBLOCK)) {
35234 + pr_warn("cannot retry for NFSv4 delegation"
35235 + " for an internal unlink\n");
35239 + if (unlikely(err))
35240 + pr_warn("failed removing %pd (%d), ignored.\n",
35241 + whpath->dentry, err);
35244 +static int test_linkable(struct dentry *h_root)
35246 + struct inode *h_dir = d_inode(h_root);
35248 + if (h_dir->i_op->link)
35251 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35252 + h_root, au_sbtype(h_root->d_sb));
35256 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35257 +static int au_whdir(struct inode *h_dir, struct path *path)
35262 + if (d_is_negative(path->dentry)) {
35265 + if (au_test_nfs(path->dentry->d_sb))
35267 + err = vfsub_mkdir(h_dir, path, mode);
35268 + } else if (d_is_dir(path->dentry))
35271 + pr_err("unknown %pd exists\n", path->dentry);
35276 +struct au_wh_base {
35277 + const struct qstr *name;
35278 + struct dentry *dentry;
35281 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35282 + struct path *h_path)
35284 + h_path->dentry = base[AuBrWh_BASE].dentry;
35285 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35286 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35287 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35288 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35289 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35293 + * returns tri-state,
35294 + * minus: error, caller should print the message
35296 + * plus: error, caller should NOT print the message
35298 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35299 + int do_plink, struct au_wh_base base[],
35300 + struct path *h_path)
35303 + struct inode *h_dir;
35305 + h_dir = d_inode(h_root);
35306 + h_path->dentry = base[AuBrWh_BASE].dentry;
35307 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35308 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35310 + err = test_linkable(h_root);
35311 + if (unlikely(err)) {
35316 + err = au_whdir(h_dir, h_path);
35317 + if (unlikely(err))
35319 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35321 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35322 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35323 + err = au_whdir(h_dir, h_path);
35324 + if (unlikely(err))
35326 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35333 + * for the moment, aufs supports the branch filesystem which does not support
35334 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35335 + * copyup failed. finally, such filesystem will not be used as the writable
35338 + * returns tri-state, see above.
35340 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35341 + int do_plink, struct au_wh_base base[],
35342 + struct path *h_path)
35345 + struct inode *h_dir;
35347 + WbrWhMustWriteLock(wbr);
35349 + err = test_linkable(h_root);
35350 + if (unlikely(err)) {
35356 + * todo: should this create be done in /sbin/mount.aufs helper?
35359 + h_dir = d_inode(h_root);
35360 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35361 + h_path->dentry = base[AuBrWh_BASE].dentry;
35362 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35363 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35366 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35367 + if (unlikely(err))
35370 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35372 + err = au_whdir(h_dir, h_path);
35373 + if (unlikely(err))
35375 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35377 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35378 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35380 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35381 + err = au_whdir(h_dir, h_path);
35382 + if (unlikely(err))
35384 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35391 + * initialize the whiteout base file/dir for @br.
35393 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35396 + const unsigned char do_plink
35397 + = !!au_opt_test(au_mntflags(sb), PLINK);
35398 + struct inode *h_dir;
35399 + struct path path = br->br_path;
35400 + struct dentry *h_root = path.dentry;
35401 + struct au_wbr *wbr = br->br_wbr;
35402 + static const struct qstr base_name[] = {
35403 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35404 + sizeof(AUFS_BASE_NAME) - 1),
35405 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35406 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35407 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35408 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35410 + struct au_wh_base base[] = {
35411 + [AuBrWh_BASE] = {
35412 + .name = base_name + AuBrWh_BASE,
35415 + [AuBrWh_PLINK] = {
35416 + .name = base_name + AuBrWh_PLINK,
35419 + [AuBrWh_ORPH] = {
35420 + .name = base_name + AuBrWh_ORPH,
35426 + WbrWhMustWriteLock(wbr);
35428 + for (i = 0; i < AuBrWh_Last; i++) {
35429 + /* doubly whiteouted */
35430 + struct dentry *d;
35432 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35433 + err = PTR_ERR(d);
35437 + base[i].dentry = d;
35439 + && wbr->wbr_wh[i]
35440 + && wbr->wbr_wh[i] != base[i].dentry);
35444 + for (i = 0; i < AuBrWh_Last; i++) {
35445 + dput(wbr->wbr_wh[i]);
35446 + wbr->wbr_wh[i] = NULL;
35450 + if (!au_br_writable(br->br_perm)) {
35451 + h_dir = d_inode(h_root);
35452 + au_wh_init_ro(h_dir, base, &path);
35453 + } else if (!au_br_wh_linkable(br->br_perm)) {
35454 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35460 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35466 + goto out; /* success */
35469 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35470 + err, h_root, au_sbtype(h_root->d_sb));
35472 + for (i = 0; i < AuBrWh_Last; i++)
35473 + dput(base[i].dentry);
35477 +/* ---------------------------------------------------------------------- */
35479 + * whiteouts are all hard-linked usually.
35480 + * when its link count reaches a ceiling, we create a new whiteout base
35481 + * asynchronously.
35484 +struct reinit_br_wh {
35485 + struct super_block *sb;
35486 + struct au_branch *br;
35489 +static void reinit_br_wh(void *arg)
35492 + aufs_bindex_t bindex;
35493 + struct path h_path;
35494 + struct reinit_br_wh *a = arg;
35495 + struct au_wbr *wbr;
35496 + struct inode *dir, *delegated;
35497 + struct dentry *h_root;
35498 + struct au_hinode *hdir;
35501 + wbr = a->br->br_wbr;
35502 + /* big aufs lock */
35503 + si_noflush_write_lock(a->sb);
35504 + if (!au_br_writable(a->br->br_perm))
35506 + bindex = au_br_index(a->sb, a->br->br_id);
35507 + if (unlikely(bindex < 0))
35510 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35511 + dir = d_inode(a->sb->s_root);
35512 + hdir = au_hi(dir, bindex);
35513 + h_root = au_h_dptr(a->sb->s_root, bindex);
35514 + AuDebugOn(h_root != au_br_dentry(a->br));
35516 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35517 + wbr_wh_write_lock(wbr);
35518 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35521 + h_path.dentry = wbr->wbr_whbase;
35522 + h_path.mnt = au_br_mnt(a->br);
35523 + delegated = NULL;
35524 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35526 + if (unlikely(err == -EWOULDBLOCK)) {
35527 + pr_warn("cannot retry for NFSv4 delegation"
35528 + " for an internal unlink\n");
35532 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35535 + dput(wbr->wbr_whbase);
35536 + wbr->wbr_whbase = NULL;
35538 + err = au_wh_init(a->br, a->sb);
35539 + wbr_wh_write_unlock(wbr);
35540 + au_hn_inode_unlock(hdir);
35541 + di_read_unlock(a->sb->s_root, AuLock_IR);
35543 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35547 + atomic_dec(&wbr->wbr_wh_running);
35548 + au_lcnt_dec(&a->br->br_count);
35549 + si_write_unlock(a->sb);
35550 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35552 + if (unlikely(err))
35553 + AuIOErr("err %d\n", err);
35556 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35558 + int do_dec, wkq_err;
35559 + struct reinit_br_wh *arg;
35562 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35565 + /* ignore ENOMEM */
35566 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35569 + * dec(wh_running), kfree(arg) and dec(br_count)
35570 + * in reinit function
35574 + au_lcnt_inc(&br->br_count);
35575 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35576 + if (unlikely(wkq_err)) {
35577 + atomic_dec(&br->br_wbr->wbr_wh_running);
35578 + au_lcnt_dec(&br->br_count);
35579 + au_kfree_rcu(arg);
35586 + atomic_dec(&br->br_wbr->wbr_wh_running);
35589 +/* ---------------------------------------------------------------------- */
35592 + * create the whiteout @wh.
35594 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35595 + struct dentry *wh)
35598 + struct path h_path = {
35601 + struct au_branch *br;
35602 + struct au_wbr *wbr;
35603 + struct dentry *h_parent;
35604 + struct inode *h_dir, *delegated;
35606 + h_parent = wh->d_parent; /* dir inode is locked */
35607 + h_dir = d_inode(h_parent);
35608 + IMustLock(h_dir);
35610 + br = au_sbr(sb, bindex);
35611 + h_path.mnt = au_br_mnt(br);
35612 + wbr = br->br_wbr;
35613 + wbr_wh_read_lock(wbr);
35614 + if (wbr->wbr_whbase) {
35615 + delegated = NULL;
35616 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35617 + if (unlikely(err == -EWOULDBLOCK)) {
35618 + pr_warn("cannot retry for NFSv4 delegation"
35619 + " for an internal link\n");
35622 + if (!err || err != -EMLINK)
35625 + /* link count full. re-initialize br_whbase. */
35626 + kick_reinit_br_wh(sb, br);
35629 + /* return this error in this context */
35630 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35632 + au_fhsm_wrote(sb, bindex, /*force*/0);
35635 + wbr_wh_read_unlock(wbr);
35639 +/* ---------------------------------------------------------------------- */
35642 + * create or remove the diropq.
35644 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35645 + unsigned int flags)
35647 + struct dentry *opq_dentry, *h_dentry;
35648 + struct super_block *sb;
35649 + struct au_branch *br;
35652 + sb = dentry->d_sb;
35653 + br = au_sbr(sb, bindex);
35654 + h_dentry = au_h_dptr(dentry, bindex);
35655 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35656 + if (IS_ERR(opq_dentry))
35659 + if (au_ftest_diropq(flags, CREATE)) {
35660 + err = link_or_create_wh(sb, bindex, opq_dentry);
35662 + au_set_dbdiropq(dentry, bindex);
35663 + goto out; /* success */
35666 + struct path tmp = {
35667 + .dentry = opq_dentry,
35668 + .mnt = au_br_mnt(br)
35670 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35672 + au_set_dbdiropq(dentry, -1);
35674 + dput(opq_dentry);
35675 + opq_dentry = ERR_PTR(err);
35678 + return opq_dentry;
35681 +struct do_diropq_args {
35682 + struct dentry **errp;
35683 + struct dentry *dentry;
35684 + aufs_bindex_t bindex;
35685 + unsigned int flags;
35688 +static void call_do_diropq(void *args)
35690 + struct do_diropq_args *a = args;
35691 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35694 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35695 + unsigned int flags)
35697 + struct dentry *diropq, *h_dentry;
35699 + h_dentry = au_h_dptr(dentry, bindex);
35700 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35701 + diropq = do_diropq(dentry, bindex, flags);
35704 + struct do_diropq_args args = {
35706 + .dentry = dentry,
35707 + .bindex = bindex,
35711 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35712 + if (unlikely(wkq_err))
35713 + diropq = ERR_PTR(wkq_err);
35719 +/* ---------------------------------------------------------------------- */
35722 + * lookup whiteout dentry.
35723 + * @h_parent: lower parent dentry which must exist and be locked
35724 + * @base_name: name of dentry which will be whiteouted
35725 + * returns dentry for whiteout.
35727 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35728 + struct au_branch *br)
35731 + struct qstr wh_name;
35732 + struct dentry *wh_dentry;
35734 + err = au_wh_name_alloc(&wh_name, base_name);
35735 + wh_dentry = ERR_PTR(err);
35737 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35738 + au_kfree_try_rcu(wh_name.name);
35740 + return wh_dentry;
35744 + * link/create a whiteout for @dentry on @bindex.
35746 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35747 + struct dentry *h_parent)
35749 + struct dentry *wh_dentry;
35750 + struct super_block *sb;
35753 + sb = dentry->d_sb;
35754 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35755 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35756 + err = link_or_create_wh(sb, bindex, wh_dentry);
35758 + au_set_dbwh(dentry, bindex);
35759 + au_fhsm_wrote(sb, bindex, /*force*/0);
35762 + wh_dentry = ERR_PTR(err);
35766 + return wh_dentry;
35769 +/* ---------------------------------------------------------------------- */
35771 +/* Delete all whiteouts in this directory on branch bindex. */
35772 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35773 + aufs_bindex_t bindex, struct au_branch *br)
35776 + unsigned long ul, n;
35777 + struct qstr wh_name;
35779 + struct hlist_head *head;
35780 + struct au_vdir_wh *pos;
35781 + struct au_vdir_destr *str;
35784 + p = (void *)__get_free_page(GFP_NOFS);
35785 + wh_name.name = p;
35786 + if (unlikely(!wh_name.name))
35790 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35791 + p += AUFS_WH_PFX_LEN;
35792 + n = whlist->nh_num;
35793 + head = whlist->nh_head;
35794 + for (ul = 0; !err && ul < n; ul++, head++) {
35795 + hlist_for_each_entry(pos, head, wh_hash) {
35796 + if (pos->wh_bindex != bindex)
35799 + str = &pos->wh_str;
35800 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35801 + memcpy(p, str->name, str->len);
35802 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35803 + err = unlink_wh_name(h_dentry, &wh_name, br);
35808 + AuIOErr("whiteout name too long %.*s\n",
35809 + str->len, str->name);
35814 + free_page((unsigned long)wh_name.name);
35820 +struct del_wh_children_args {
35822 + struct dentry *h_dentry;
35823 + struct au_nhash *whlist;
35824 + aufs_bindex_t bindex;
35825 + struct au_branch *br;
35828 +static void call_del_wh_children(void *args)
35830 + struct del_wh_children_args *a = args;
35831 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35834 +/* ---------------------------------------------------------------------- */
35836 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35838 + struct au_whtmp_rmdir *whtmp;
35840 + unsigned int rdhash;
35842 + SiMustAnyLock(sb);
35844 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35845 + if (unlikely(!whtmp)) {
35846 + whtmp = ERR_PTR(-ENOMEM);
35850 + /* no estimation for dir size */
35851 + rdhash = au_sbi(sb)->si_rdhash;
35853 + rdhash = AUFS_RDHASH_DEF;
35854 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35855 + if (unlikely(err)) {
35856 + au_kfree_rcu(whtmp);
35857 + whtmp = ERR_PTR(err);
35864 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35867 + au_lcnt_dec(&whtmp->br->br_count);
35868 + dput(whtmp->wh_dentry);
35869 + iput(whtmp->dir);
35870 + au_nhash_wh_free(&whtmp->whlist);
35871 + au_kfree_rcu(whtmp);
35875 + * rmdir the whiteouted temporary named dir @h_dentry.
35876 + * @whlist: whiteouted children.
35878 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35879 + struct dentry *wh_dentry, struct au_nhash *whlist)
35882 + unsigned int h_nlink;
35883 + struct path h_tmp;
35884 + struct inode *wh_inode, *h_dir;
35885 + struct au_branch *br;
35887 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35888 + IMustLock(h_dir);
35890 + br = au_sbr(dir->i_sb, bindex);
35891 + wh_inode = d_inode(wh_dentry);
35892 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35895 + * someone else might change some whiteouts while we were sleeping.
35896 + * it means this whlist may have an obsoleted entry.
35898 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35899 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35902 + struct del_wh_children_args args = {
35904 + .h_dentry = wh_dentry,
35905 + .whlist = whlist,
35906 + .bindex = bindex,
35910 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35911 + if (unlikely(wkq_err))
35914 + inode_unlock(wh_inode);
35917 + h_tmp.dentry = wh_dentry;
35918 + h_tmp.mnt = au_br_mnt(br);
35919 + h_nlink = h_dir->i_nlink;
35920 + err = vfsub_rmdir(h_dir, &h_tmp);
35921 + /* some fs doesn't change the parent nlink in some cases */
35922 + h_nlink -= h_dir->i_nlink;
35926 + if (au_ibtop(dir) == bindex) {
35927 + /* todo: dir->i_mutex is necessary */
35928 + au_cpup_attr_timesizes(dir);
35930 + vfsub_drop_nlink(dir);
35932 + return 0; /* success */
35935 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35939 +static void call_rmdir_whtmp(void *args)
35942 + aufs_bindex_t bindex;
35943 + struct au_whtmp_rmdir *a = args;
35944 + struct super_block *sb;
35945 + struct dentry *h_parent;
35946 + struct inode *h_dir;
35947 + struct au_hinode *hdir;
35949 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35950 + /* inode_lock(a->dir); */
35952 + sb = a->dir->i_sb;
35953 + si_read_lock(sb, !AuLock_FLUSH);
35954 + if (!au_br_writable(a->br->br_perm))
35956 + bindex = au_br_index(sb, a->br->br_id);
35957 + if (unlikely(bindex < 0))
35961 + ii_write_lock_parent(a->dir);
35962 + h_parent = dget_parent(a->wh_dentry);
35963 + h_dir = d_inode(h_parent);
35964 + hdir = au_hi(a->dir, bindex);
35965 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35966 + if (unlikely(err))
35968 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35969 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35972 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35973 + au_hn_inode_unlock(hdir);
35974 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35978 + ii_write_unlock(a->dir);
35980 + /* inode_unlock(a->dir); */
35981 + au_whtmp_rmdir_free(a);
35982 + si_read_unlock(sb);
35983 + au_nwt_done(&au_sbi(sb)->si_nowait);
35984 + if (unlikely(err))
35985 + AuIOErr("err %d\n", err);
35988 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35989 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35992 + struct super_block *sb;
35996 + /* all post-process will be done in do_rmdir_whtmp(). */
35998 + args->dir = au_igrab(dir);
35999 + args->br = au_sbr(sb, bindex);
36000 + au_lcnt_inc(&args->br->br_count);
36001 + args->wh_dentry = dget(wh_dentry);
36002 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
36003 + if (unlikely(wkq_err)) {
36004 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
36005 + au_whtmp_rmdir_free(args);
36008 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
36009 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
36010 +++ linux/fs/aufs/whout.h 2019-03-05 12:13:00.145891204 +0100
36012 +/* SPDX-License-Identifier: GPL-2.0 */
36014 + * Copyright (C) 2005-2019 Junjiro R. Okajima
36016 + * This program, aufs is free software; you can redistribute it and/or modify
36017 + * it under the terms of the GNU General Public License as published by
36018 + * the Free Software Foundation; either version 2 of the License, or
36019 + * (at your option) any later version.
36021 + * This program is distributed in the hope that it will be useful,
36022 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36023 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36024 + * GNU General Public License for more details.
36026 + * You should have received a copy of the GNU General Public License
36027 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36031 + * whiteout for logical deletion and opaque directory
36034 +#ifndef __AUFS_WHOUT_H__
36035 +#define __AUFS_WHOUT_H__
36042 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
36043 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
36044 +int au_diropq_test(struct dentry *h_dentry);
36046 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
36047 + struct qstr *prefix);
36048 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
36049 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
36050 + struct dentry *dentry);
36051 +int au_wh_init(struct au_branch *br, struct super_block *sb);
36053 +/* diropq flags */
36054 +#define AuDiropq_CREATE 1
36055 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
36056 +#define au_fset_diropq(flags, name) \
36057 + do { (flags) |= AuDiropq_##name; } while (0)
36058 +#define au_fclr_diropq(flags, name) \
36059 + do { (flags) &= ~AuDiropq_##name; } while (0)
36061 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
36062 + unsigned int flags);
36063 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
36064 + struct au_branch *br);
36065 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
36066 + struct dentry *h_parent);
36068 +/* real rmdir for the whiteout-ed dir */
36069 +struct au_whtmp_rmdir {
36070 + struct inode *dir;
36071 + struct au_branch *br;
36072 + struct dentry *wh_dentry;
36073 + struct au_nhash whlist;
36076 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
36077 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
36078 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36079 + struct dentry *wh_dentry, struct au_nhash *whlist);
36080 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36081 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
36083 +/* ---------------------------------------------------------------------- */
36085 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
36086 + aufs_bindex_t bindex)
36088 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
36091 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
36093 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
36096 +#endif /* __KERNEL__ */
36097 +#endif /* __AUFS_WHOUT_H__ */
36098 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
36099 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
36100 +++ linux/fs/aufs/wkq.c 2019-03-05 12:13:00.145891204 +0100
36102 +// SPDX-License-Identifier: GPL-2.0
36104 + * Copyright (C) 2005-2019 Junjiro R. Okajima
36106 + * This program, aufs is free software; you can redistribute it and/or modify
36107 + * it under the terms of the GNU General Public License as published by
36108 + * the Free Software Foundation; either version 2 of the License, or
36109 + * (at your option) any later version.
36111 + * This program is distributed in the hope that it will be useful,
36112 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36113 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36114 + * GNU General Public License for more details.
36116 + * You should have received a copy of the GNU General Public License
36117 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36121 + * workqueue for asynchronous/super-io operations
36122 + * todo: try new credential scheme
36125 +#include <linux/module.h>
36128 +/* internal workqueue named AUFS_WKQ_NAME */
36130 +static struct workqueue_struct *au_wkq;
36132 +struct au_wkinfo {
36133 + struct work_struct wk;
36134 + struct kobject *kobj;
36136 + unsigned int flags; /* see wkq.h */
36138 + au_wkq_func_t func;
36141 +#ifdef CONFIG_LOCKDEP
36143 + struct held_lock **hlock;
36146 + struct completion *comp;
36149 +/* ---------------------------------------------------------------------- */
36151 + * Aufs passes some operations to the workqueue such as the internal copyup.
36152 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36153 + * job run by workqueue depends upon the locks acquired in the other task.
36154 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36155 + * information too. And the job in the workqueue restores the info in order to
36156 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36157 + * correctly and expectedly.
36160 +#ifndef CONFIG_LOCKDEP
36161 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36162 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36163 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36164 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36165 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36167 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36169 + wkinfo->hlock = NULL;
36170 + wkinfo->dont_check = 0;
36177 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36179 + static DEFINE_SPINLOCK(spin);
36182 + struct lock_class_key *key;
36184 + { .name = "&sbinfo->si_rwsem" },
36185 + { .name = "&finfo->fi_rwsem" },
36186 + { .name = "&dinfo->di_rwsem" },
36187 + { .name = "&iinfo->ii_rwsem" }
36192 + /* lockless read from 'set.' see below */
36193 + if (set == ARRAY_SIZE(a)) {
36194 + for (i = 0; i < ARRAY_SIZE(a); i++)
36195 + if (a[i].key == key)
36200 + spin_lock(&spin);
36202 + for (i = 0; i < ARRAY_SIZE(a); i++)
36203 + if (a[i].key == key) {
36204 + spin_unlock(&spin);
36207 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36209 + if (unlikely(a[i].key == key)) { /* rare but possible */
36210 + spin_unlock(&spin);
36215 + if (strstr(a[i].name, name)) {
36217 + * the order of these three lines is important for the
36218 + * lockless read above.
36221 + spin_unlock(&spin);
36223 + /* AuDbg("%d, %s\n", set, name); */
36227 + spin_unlock(&spin);
36236 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36239 + struct task_struct *curr;
36240 + struct held_lock **hl, *held_locks, *p;
36244 + wkinfo->dont_check = lockdep_recursing(curr);
36245 + if (wkinfo->dont_check)
36247 + n = curr->lockdep_depth;
36252 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36253 + if (unlikely(!wkinfo->hlock))
36258 + if (0 && au_debug_test()) /* left for debugging */
36259 + lockdep_print_held_locks(curr);
36261 + held_locks = curr->held_locks;
36262 + hl = wkinfo->hlock;
36264 + p = held_locks++;
36265 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36274 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36276 + au_kfree_try_rcu(wkinfo->hlock);
36279 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36281 + struct held_lock *p, **hl = wkinfo->hlock;
36284 + if (wkinfo->dont_check)
36288 + while ((p = *hl++)) { /* assignment */
36289 + subclass = lockdep_hlock_class(p)->subclass;
36290 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36292 + rwsem_acquire_read(p->instance, subclass, 0,
36293 + /*p->acquire_ip*/_RET_IP_);
36295 + rwsem_acquire(p->instance, subclass, 0,
36296 + /*p->acquire_ip*/_RET_IP_);
36300 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36302 + struct held_lock *p, **hl = wkinfo->hlock;
36304 + if (wkinfo->dont_check)
36308 + while ((p = *hl++)) /* assignment */
36309 + rwsem_release(p->instance, 0, /*p->acquire_ip*/_RET_IP_);
36313 +static void wkq_func(struct work_struct *wk)
36315 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36317 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36318 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36320 + au_wkq_lockdep_pre(wkinfo);
36321 + wkinfo->func(wkinfo->args);
36322 + au_wkq_lockdep_post(wkinfo);
36323 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36324 + complete(wkinfo->comp);
36326 + kobject_put(wkinfo->kobj);
36327 + module_put(THIS_MODULE); /* todo: ?? */
36328 + au_kfree_rcu(wkinfo);
36333 + * Since struct completion is large, try allocating it dynamically.
36335 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
36336 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36338 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36340 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36342 + init_completion(*comp);
36343 + wkinfo->comp = *comp;
36349 +static void au_wkq_comp_free(struct completion *comp)
36351 + au_kfree_rcu(comp);
36357 +#define AuWkqCompDeclare(name) \
36358 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
36359 + struct completion *comp = &_ ## name
36361 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36363 + wkinfo->comp = *comp;
36367 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
36371 +#endif /* 4KSTACKS */
36373 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36375 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36376 + if (au_wkq_test()) {
36377 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36378 + " due to a dead dir by UDBA,"
36379 + " or async xino write?\n");
36380 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36383 + au_dbg_verify_kthread();
36385 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36386 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36387 + queue_work(au_wkq, &wkinfo->wk);
36389 + INIT_WORK(&wkinfo->wk, wkq_func);
36390 + schedule_work(&wkinfo->wk);
36395 + * Be careful. It is easy to make deadlock happen.
36396 + * processA: lock, wkq and wait
36397 + * processB: wkq and wait, lock in wkq
36400 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36403 + AuWkqCompDeclare(comp);
36404 + struct au_wkinfo wkinfo = {
36410 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36411 + if (unlikely(err))
36413 + err = au_wkq_lockdep_alloc(&wkinfo);
36414 + if (unlikely(err))
36417 + au_wkq_run(&wkinfo);
36418 + /* no timeout, no interrupt */
36419 + wait_for_completion(wkinfo.comp);
36421 + au_wkq_lockdep_free(&wkinfo);
36424 + au_wkq_comp_free(comp);
36426 + destroy_work_on_stack(&wkinfo.wk);
36431 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36432 + * problem in a concurrent umounting.
36434 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36435 + unsigned int flags)
36438 + struct au_wkinfo *wkinfo;
36440 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36443 + * wkq_func() must free this wkinfo.
36444 + * it highly depends upon the implementation of workqueue.
36447 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36449 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36450 + wkinfo->flags = flags & ~AuWkq_WAIT;
36451 + wkinfo->func = func;
36452 + wkinfo->args = args;
36453 + wkinfo->comp = NULL;
36454 + au_wkq_lockdep_init(wkinfo);
36455 + kobject_get(wkinfo->kobj);
36456 + __module_get(THIS_MODULE); /* todo: ?? */
36458 + au_wkq_run(wkinfo);
36461 + au_nwt_done(&au_sbi(sb)->si_nowait);
36467 +/* ---------------------------------------------------------------------- */
36469 +void au_nwt_init(struct au_nowait_tasks *nwt)
36471 + atomic_set(&nwt->nw_len, 0);
36472 + /* smp_mb(); */ /* atomic_set */
36473 + init_waitqueue_head(&nwt->nw_wq);
36476 +void au_wkq_fin(void)
36478 + destroy_workqueue(au_wkq);
36481 +int __init au_wkq_init(void)
36486 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36487 + if (IS_ERR(au_wkq))
36488 + err = PTR_ERR(au_wkq);
36489 + else if (!au_wkq)
36494 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36495 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36496 +++ linux/fs/aufs/wkq.h 2019-03-05 12:13:00.145891204 +0100
36498 +/* SPDX-License-Identifier: GPL-2.0 */
36500 + * Copyright (C) 2005-2019 Junjiro R. Okajima
36502 + * This program, aufs is free software; you can redistribute it and/or modify
36503 + * it under the terms of the GNU General Public License as published by
36504 + * the Free Software Foundation; either version 2 of the License, or
36505 + * (at your option) any later version.
36507 + * This program is distributed in the hope that it will be useful,
36508 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36509 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36510 + * GNU General Public License for more details.
36512 + * You should have received a copy of the GNU General Public License
36513 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36517 + * workqueue for asynchronous/super-io operations
36518 + * todo: try new credentials management scheme
36521 +#ifndef __AUFS_WKQ_H__
36522 +#define __AUFS_WKQ_H__
36526 +#include <linux/wait.h>
36528 +struct super_block;
36530 +/* ---------------------------------------------------------------------- */
36533 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36535 +struct au_nowait_tasks {
36537 + wait_queue_head_t nw_wq;
36540 +/* ---------------------------------------------------------------------- */
36542 +typedef void (*au_wkq_func_t)(void *args);
36545 +#define AuWkq_WAIT 1
36546 +#define AuWkq_NEST (1 << 1)
36547 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36548 +#define au_fset_wkq(flags, name) \
36549 + do { (flags) |= AuWkq_##name; } while (0)
36550 +#define au_fclr_wkq(flags, name) \
36551 + do { (flags) &= ~AuWkq_##name; } while (0)
36554 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36555 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36556 + unsigned int flags);
36557 +void au_nwt_init(struct au_nowait_tasks *nwt);
36558 +int __init au_wkq_init(void);
36559 +void au_wkq_fin(void);
36561 +/* ---------------------------------------------------------------------- */
36563 +static inline int au_wkq_test(void)
36565 + return current->flags & PF_WQ_WORKER;
36568 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36570 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36573 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36575 + if (atomic_dec_and_test(&nwt->nw_len))
36576 + wake_up_all(&nwt->nw_wq);
36579 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36581 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36585 +#endif /* __KERNEL__ */
36586 +#endif /* __AUFS_WKQ_H__ */
36587 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36588 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36589 +++ linux/fs/aufs/xattr.c 2019-03-05 12:13:00.145891204 +0100
36591 +// SPDX-License-Identifier: GPL-2.0
36593 + * Copyright (C) 2014-2019 Junjiro R. Okajima
36595 + * This program, aufs is free software; you can redistribute it and/or modify
36596 + * it under the terms of the GNU General Public License as published by
36597 + * the Free Software Foundation; either version 2 of the License, or
36598 + * (at your option) any later version.
36600 + * This program is distributed in the hope that it will be useful,
36601 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36602 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36603 + * GNU General Public License for more details.
36605 + * You should have received a copy of the GNU General Public License
36606 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36610 + * handling xattr functions
36613 +#include <linux/fs.h>
36614 +#include <linux/posix_acl_xattr.h>
36615 +#include <linux/xattr.h>
36618 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36620 + if (!ignore_flags)
36628 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36633 +#define cmp(brattr, prefix) do { \
36634 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36635 + XATTR_##prefix##_PREFIX_LEN)) { \
36636 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36642 + cmp(SEC, SECURITY);
36643 + cmp(SYS, SYSTEM);
36644 + cmp(TR, TRUSTED);
36648 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36655 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36657 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36658 + char *name, char **buf, unsigned int ignore_flags,
36659 + unsigned int verbose)
36663 + struct inode *h_idst;
36665 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36667 + if (unlikely(err <= 0)) {
36668 + if (err == -ENODATA
36669 + || (err == -EOPNOTSUPP
36670 + && ((ignore_flags & au_xattr_out_of_list)
36671 + || (au_test_nfs_noacl(d_inode(h_src))
36672 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36674 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36677 + if (err && (verbose || au_debug_test()))
36678 + pr_err("%s, err %d\n", name, err);
36682 + /* unlock it temporary */
36683 + h_idst = d_inode(h_dst);
36684 + inode_unlock(h_idst);
36685 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36686 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36687 + if (unlikely(err)) {
36688 + if (verbose || au_debug_test())
36689 + pr_err("%s, err %d\n", name, err);
36690 + err = au_xattr_ignore(err, name, ignore_flags);
36697 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36698 + unsigned int verbose)
36700 + int err, unlocked, acl_access, acl_default;
36702 + struct inode *h_isrc, *h_idst;
36703 + char *value, *p, *o, *e;
36705 + /* try stopping to update the source inode while we are referencing */
36706 + /* there should not be the parent-child relationship between them */
36707 + h_isrc = d_inode(h_src);
36708 + h_idst = d_inode(h_dst);
36709 + inode_unlock(h_idst);
36710 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36711 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36714 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36715 + ssz = vfs_listxattr(h_src, NULL, 0);
36717 + if (unlikely(err < 0)) {
36719 + if (err == -ENODATA
36720 + || err == -EOPNOTSUPP)
36721 + err = 0; /* ignore */
36730 + p = kmalloc(ssz, GFP_NOFS);
36732 + if (unlikely(!p))
36734 + err = vfs_listxattr(h_src, p, ssz);
36736 + inode_unlock_shared(h_isrc);
36738 + AuDbg("err %d, ssz %zd\n", err, ssz);
36739 + if (unlikely(err < 0))
36747 + while (!err && p < e) {
36748 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36749 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36750 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36751 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36753 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36755 + p += strlen(p) + 1;
36758 + ignore_flags |= au_xattr_out_of_list;
36759 + if (!err && !acl_access) {
36760 + err = au_do_cpup_xattr(h_dst, h_src,
36761 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36762 + ignore_flags, verbose);
36765 + if (!err && !acl_default) {
36766 + err = au_do_cpup_xattr(h_dst, h_src,
36767 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36768 + ignore_flags, verbose);
36772 + au_kfree_try_rcu(value);
36775 + au_kfree_try_rcu(o);
36778 + inode_unlock_shared(h_isrc);
36783 +/* ---------------------------------------------------------------------- */
36785 +static int au_smack_reentering(struct super_block *sb)
36787 +#if IS_ENABLED(CONFIG_SECURITY_SMACK)
36789 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36790 + * i_op->getxattr(). ouch.
36792 + return si_pid_test(sb);
36803 +struct au_lgxattr {
36811 + const char *name;
36818 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
36822 + struct path h_path;
36823 + struct super_block *sb;
36825 + sb = dentry->d_sb;
36826 + reenter = au_smack_reentering(sb);
36828 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36829 + if (unlikely(err))
36832 + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
36833 + if (unlikely(err))
36835 + if (unlikely(!h_path.dentry))
36836 + /* illegally overlapped or something */
36837 + goto out_di; /* pretending success */
36839 + /* always topmost entry only */
36840 + switch (arg->type) {
36841 + case AU_XATTR_LIST:
36842 + err = vfs_listxattr(h_path.dentry,
36843 + arg->u.list.list, arg->u.list.size);
36845 + case AU_XATTR_GET:
36846 + AuDebugOn(d_is_negative(h_path.dentry));
36847 + err = vfs_getxattr(h_path.dentry,
36848 + arg->u.get.name, arg->u.get.value,
36849 + arg->u.get.size);
36855 + di_read_unlock(dentry, AuLock_IR);
36858 + si_read_unlock(sb);
36864 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36866 + struct au_lgxattr arg = {
36867 + .type = AU_XATTR_LIST,
36874 + return au_lgxattr(dentry, &arg);
36877 +static ssize_t au_getxattr(struct dentry *dentry,
36878 + struct inode *inode __maybe_unused,
36879 + const char *name, void *value, size_t size)
36881 + struct au_lgxattr arg = {
36882 + .type = AU_XATTR_GET,
36890 + return au_lgxattr(dentry, &arg);
36893 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36894 + const char *name, const void *value, size_t size,
36897 + struct au_sxattr arg = {
36898 + .type = AU_XATTR_SET,
36907 + return au_sxattr(dentry, inode, &arg);
36910 +/* ---------------------------------------------------------------------- */
36912 +static int au_xattr_get(const struct xattr_handler *handler,
36913 + struct dentry *dentry, struct inode *inode,
36914 + const char *name, void *buffer, size_t size)
36916 + return au_getxattr(dentry, inode, name, buffer, size);
36919 +static int au_xattr_set(const struct xattr_handler *handler,
36920 + struct dentry *dentry, struct inode *inode,
36921 + const char *name, const void *value, size_t size,
36924 + return au_setxattr(dentry, inode, name, value, size, flags);
36927 +static const struct xattr_handler au_xattr_handler = {
36930 + .get = au_xattr_get,
36931 + .set = au_xattr_set
36934 +static const struct xattr_handler *au_xattr_handlers[] = {
36935 +#ifdef CONFIG_FS_POSIX_ACL
36936 + &posix_acl_access_xattr_handler,
36937 + &posix_acl_default_xattr_handler,
36939 + &au_xattr_handler, /* must be last */
36943 +void au_xattr_init(struct super_block *sb)
36945 + sb->s_xattr = au_xattr_handlers;
36947 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36948 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36949 +++ linux/fs/aufs/xino.c 2019-03-05 12:13:00.145891204 +0100
36951 +// SPDX-License-Identifier: GPL-2.0
36953 + * Copyright (C) 2005-2019 Junjiro R. Okajima
36955 + * This program, aufs is free software; you can redistribute it and/or modify
36956 + * it under the terms of the GNU General Public License as published by
36957 + * the Free Software Foundation; either version 2 of the License, or
36958 + * (at your option) any later version.
36960 + * This program is distributed in the hope that it will be useful,
36961 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36962 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36963 + * GNU General Public License for more details.
36965 + * You should have received a copy of the GNU General Public License
36966 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36970 + * external inode number translation table and bitmap
36972 + * things to consider
36974 + * + au_xino object
36975 + * + XINO files (xino, xib, xigen)
36976 + * + dynamic debugfs entries (xiN)
36977 + * + static debugfs entries (xib, xigen)
36978 + * + static sysfs entry (xi_path)
36979 + * - several entry points to handle them.
36980 + * + mount(2) without xino option (default)
36981 + * + mount(2) with xino option
36982 + * + mount(2) with noxino option
36984 + * + remount with add/del branches
36985 + * + remount with xino/noxino options
36988 +#include <linux/seq_file.h>
36989 +#include <linux/statfs.h>
36992 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36993 + aufs_bindex_t bbot,
36994 + struct super_block *h_sb)
36996 + /* todo: try binary-search if the branches are many */
36997 + for (; btop <= bbot; btop++)
36998 + if (h_sb == au_sbr_sb(sb, btop))
37004 + * find another branch who is on the same filesystem of the specified
37005 + * branch{@btgt}. search until @bbot.
37007 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
37008 + aufs_bindex_t bbot)
37010 + aufs_bindex_t bindex;
37011 + struct super_block *tgt_sb;
37013 + tgt_sb = au_sbr_sb(sb, btgt);
37014 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
37016 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
37021 +/* ---------------------------------------------------------------------- */
37024 + * stop unnecessary notify events at creating xino files
37027 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
37029 + aufs_bindex_t bfound, bindex, bbot;
37030 + struct dentry *parent;
37031 + struct au_branch *br;
37034 + parent = dentry->d_parent; /* safe d_parent access */
37035 + bbot = au_sbbot(sb);
37036 + for (bindex = 0; bindex <= bbot; bindex++) {
37037 + br = au_sbr(sb, bindex);
37038 + if (au_br_dentry(br) == parent) {
37044 + AuDbg("bfound b%d\n", bfound);
37048 +struct au_xino_lock_dir {
37049 + struct au_hinode *hdir;
37050 + struct dentry *parent;
37051 + struct inode *dir;
37054 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
37055 + unsigned int lsc)
37057 + struct dentry *parent;
37058 + struct inode *dir;
37060 + parent = dget_parent(dentry);
37061 + dir = d_inode(parent);
37062 + inode_lock_nested(dir, lsc);
37063 +#if 0 /* it should not happen */
37064 + spin_lock(&dentry->d_lock);
37065 + if (unlikely(dentry->d_parent != parent)) {
37066 + spin_unlock(&dentry->d_lock);
37067 + inode_unlock(dir);
37072 + spin_unlock(&dentry->d_lock);
37079 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
37080 + struct au_xino_lock_dir *ldir)
37082 + aufs_bindex_t bindex;
37084 + ldir->hdir = NULL;
37085 + bindex = au_xi_root(sb, xipath->dentry);
37086 + if (bindex >= 0) {
37087 + /* rw branch root */
37088 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
37089 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
37092 + ldir->parent = au_dget_parent_lock(xipath->dentry,
37094 + ldir->dir = d_inode(ldir->parent);
37098 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
37101 + au_hn_inode_unlock(ldir->hdir);
37103 + inode_unlock(ldir->dir);
37104 + dput(ldir->parent);
37108 +/* ---------------------------------------------------------------------- */
37111 + * create and set a new xino file
37113 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent)
37115 + struct file *file;
37116 + struct dentry *h_parent, *d;
37117 + struct inode *h_dir, *inode;
37121 + * at mount-time, and the xino file is the default path,
37122 + * hnotify is disabled so we have no notify events to ignore.
37123 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37125 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37126 + /* | __FMODE_NONOTIFY */,
37128 + if (IS_ERR(file)) {
37130 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
37134 + /* keep file count */
37136 + d = file->f_path.dentry;
37137 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
37138 + /* mnt_want_write() is unnecessary here */
37139 + h_dir = d_inode(h_parent);
37140 + inode = file_inode(file);
37141 + /* no delegation since it is just created */
37142 + if (inode->i_nlink)
37143 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37145 + inode_unlock(h_dir);
37147 + if (unlikely(err)) {
37149 + pr_err("unlink %s(%d)\n", fpath, err);
37154 + if (unlikely(sb == d->d_sb)) {
37156 + pr_err("%s must be outside\n", fpath);
37159 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37161 + pr_err("xino doesn't support %s(%s)\n",
37162 + fpath, au_sbtype(d->d_sb));
37165 + return file; /* success */
37169 + file = ERR_PTR(err);
37174 + * create a new xinofile at the same place/path as @base.
37176 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37177 + struct file *copy_src)
37179 + struct file *file;
37180 + struct dentry *dentry, *parent;
37181 + struct inode *dir, *delegated;
37182 + struct qstr *name;
37183 + struct path path;
37184 + int err, do_unlock;
37185 + struct au_xino_lock_dir ldir;
37188 + au_xino_lock_dir(sb, base, &ldir);
37189 + dentry = base->dentry;
37190 + parent = dentry->d_parent; /* dir inode is locked */
37191 + dir = d_inode(parent);
37194 + name = &dentry->d_name;
37195 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
37196 + if (IS_ERR(path.dentry)) {
37197 + file = (void *)path.dentry;
37198 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37202 + /* no need to mnt_want_write() since we call dentry_open() later */
37203 + err = vfs_create(dir, path.dentry, 0666, NULL);
37204 + if (unlikely(err)) {
37205 + file = ERR_PTR(err);
37206 + pr_err("%pd create err %d\n", dentry, err);
37210 + path.mnt = base->mnt;
37211 + file = vfsub_dentry_open(&path,
37212 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37213 + /* | __FMODE_NONOTIFY */);
37214 + if (IS_ERR(file)) {
37215 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37219 + delegated = NULL;
37220 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37221 + au_xino_unlock_dir(&ldir);
37223 + if (unlikely(err == -EWOULDBLOCK)) {
37224 + pr_warn("cannot retry for NFSv4 delegation"
37225 + " for an internal unlink\n");
37228 + if (unlikely(err)) {
37229 + pr_err("%pd unlink err %d\n", dentry, err);
37234 + /* no one can touch copy_src xino */
37235 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37236 + if (unlikely(err)) {
37237 + pr_err("%pd copy err %d\n", dentry, err);
37241 + goto out_dput; /* success */
37245 + file = ERR_PTR(err);
37247 + dput(path.dentry);
37250 + au_xino_unlock_dir(&ldir);
37254 +struct file *au_xino_file1(struct au_xino *xi)
37256 + struct file *file;
37257 + unsigned int u, nfile;
37260 + nfile = xi->xi_nfile;
37261 + for (u = 0; u < nfile; u++) {
37262 + file = xi->xi_file[u];
37270 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37281 + if (idx < xi->xi_nfile) {
37282 + f = xi->xi_file[idx];
37286 + p = au_kzrealloc(xi->xi_file,
37287 + sizeof(*xi->xi_file) * xi->xi_nfile,
37288 + sizeof(*xi->xi_file) * (idx + 1),
37289 + GFP_NOFS, /*may_shrink*/0);
37291 + MtxMustLock(&xi->xi_mtx);
37293 + xi->xi_nfile = idx + 1;
37301 + xi->xi_file[idx] = file;
37308 + * if @xinew->xi is not set, then create new xigen file.
37310 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37312 + struct file *file;
37315 + SiMustAnyLock(sb);
37317 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37318 + if (IS_ERR(file)) {
37319 + err = PTR_ERR(file);
37320 + pr_err("%s[%d], err %d\n",
37321 + xinew->xi ? "xino" : "xigen",
37322 + xinew->idx, err);
37327 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37330 + /* todo: make xigen file an array */
37331 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37334 + if (unlikely(err))
37335 + file = ERR_PTR(err);
37341 +/* ---------------------------------------------------------------------- */
37344 + * truncate xino files
37346 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37347 + int idx, struct kstatfs *st)
37351 + struct file *file, *new_xino;
37352 + struct au_xi_new xinew = {
37357 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37358 + file = au_xino_file(xinew.xi, idx);
37362 + xinew.base = &file->f_path;
37363 + err = vfs_statfs(xinew.base, st);
37364 + if (unlikely(err)) {
37365 + AuErr1("statfs err %d, ignored\n", err);
37370 + blocks = file_inode(file)->i_blocks;
37371 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37372 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37374 + xinew.copy_src = file;
37375 + new_xino = au_xi_new(sb, &xinew);
37376 + if (IS_ERR(new_xino)) {
37377 + err = PTR_ERR(new_xino);
37378 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37382 + err = vfs_statfs(&new_xino->f_path, st);
37384 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37385 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37386 + st->f_bfree, st->f_blocks);
37388 + AuErr1("statfs err %d, ignored\n", err);
37396 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37399 + unsigned long jiffy;
37400 + aufs_bindex_t bbot;
37401 + struct kstatfs *st;
37402 + struct au_branch *br;
37403 + struct au_xino *xi;
37406 + st = kmalloc(sizeof(*st), GFP_NOFS);
37407 + if (unlikely(!st))
37411 + bbot = au_sbbot(sb);
37412 + if (unlikely(bindex < 0 || bbot < bindex))
37417 + br = au_sbr(sb, bindex);
37418 + xi = br->br_xino;
37419 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37420 + err = au_xino_do_trunc(sb, bindex, i, st);
37422 + au_sbi(sb)->si_xino_jiffy = jiffy;
37425 + au_kfree_rcu(st);
37430 +struct xino_do_trunc_args {
37431 + struct super_block *sb;
37432 + struct au_branch *br;
37436 +static void xino_do_trunc(void *_args)
37438 + struct xino_do_trunc_args *args = _args;
37439 + struct super_block *sb;
37440 + struct au_branch *br;
37441 + struct inode *dir;
37443 + aufs_bindex_t bindex;
37447 + dir = d_inode(sb->s_root);
37451 + si_noflush_write_lock(sb);
37452 + ii_read_lock_parent(dir);
37453 + bindex = au_br_index(sb, br->br_id);
37454 + err = au_xino_trunc(sb, bindex, idx);
37455 + ii_read_unlock(dir);
37456 + if (unlikely(err))
37457 + pr_warn("err b%d, (%d)\n", bindex, err);
37458 + atomic_dec(&br->br_xino->xi_truncating);
37459 + au_lcnt_dec(&br->br_count);
37460 + si_write_unlock(sb);
37461 + au_nwt_done(&au_sbi(sb)->si_nowait);
37462 + au_kfree_rcu(args);
37466 + * returns the index in the xi_file array whose corresponding file is necessary
37467 + * to truncate, or -1 which means no need to truncate.
37469 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37473 + struct kstatfs st;
37474 + struct au_sbinfo *sbinfo;
37475 + struct au_xino *xi;
37476 + struct file *file;
37478 + /* todo: si_xino_expire and the ratio should be customizable */
37479 + sbinfo = au_sbi(sb);
37480 + if (time_before(jiffies,
37481 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37484 + /* truncation border */
37485 + xi = br->br_xino;
37486 + for (u = 0; u < xi->xi_nfile; u++) {
37487 + file = au_xino_file(xi, u);
37491 + err = vfs_statfs(&file->f_path, &st);
37492 + if (unlikely(err)) {
37493 + AuErr1("statfs err %d, ignored\n", err);
37496 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37497 + >= AUFS_XINO_DEF_TRUNC)
37504 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37507 + struct xino_do_trunc_args *args;
37510 + idx = xino_trunc_test(sb, br);
37514 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37517 + /* lock and kfree() will be called in trunc_xino() */
37518 + args = kmalloc(sizeof(*args), GFP_NOFS);
37519 + if (unlikely(!args)) {
37520 + AuErr1("no memory\n");
37524 + au_lcnt_inc(&br->br_count);
37528 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37530 + return; /* success */
37532 + pr_err("wkq %d\n", wkq_err);
37533 + au_lcnt_dec(&br->br_count);
37534 + au_kfree_rcu(args);
37537 + atomic_dec(&br->br_xino->xi_truncating);
37540 +/* ---------------------------------------------------------------------- */
37542 +struct au_xi_calc {
37547 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37548 + struct au_xi_calc *calc)
37552 + maxent = au_xi_maxent(sb);
37553 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37554 + calc->pos *= sizeof(ino_t);
37557 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37558 + struct au_xi_calc *calc)
37561 + struct file *file;
37562 + struct au_xino *xi = br->br_xino;
37563 + struct au_xi_new xinew = {
37567 + SiMustAnyLock(sb);
37573 + mutex_lock(&xi->xi_mtx);
37574 + file = au_xino_file(xi, calc->idx);
37578 + file = au_xino_file(xi, /*idx*/-1);
37579 + AuDebugOn(!file);
37580 + xinew.idx = calc->idx;
37581 + xinew.base = &file->f_path;
37582 + /* xinew.copy_src = NULL; */
37583 + file = au_xi_new(sb, &xinew);
37584 + if (IS_ERR(file))
37585 + err = PTR_ERR(file);
37588 + mutex_unlock(&xi->xi_mtx);
37593 +struct au_xino_do_new_async_args {
37594 + struct super_block *sb;
37595 + struct au_branch *br;
37596 + struct au_xi_calc calc;
37600 +struct au_xi_writing {
37601 + struct hlist_bl_node node;
37602 + ino_t h_ino, ino;
37605 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37606 + struct au_xi_calc *calc, ino_t ino);
37608 +static void au_xino_call_do_new_async(void *args)
37610 + struct au_xino_do_new_async_args *a = args;
37611 + struct au_branch *br;
37612 + struct super_block *sb;
37613 + struct au_sbinfo *sbi;
37614 + struct inode *root;
37615 + struct file *file;
37616 + struct au_xi_writing *del, *p;
37617 + struct hlist_bl_head *hbl;
37618 + struct hlist_bl_node *pos;
37623 + sbi = au_sbi(sb);
37624 + si_noflush_read_lock(sb);
37625 + root = d_inode(sb->s_root);
37626 + ii_read_lock_child(root);
37627 + err = au_xino_do_new_async(sb, br, &a->calc);
37628 + if (unlikely(err)) {
37629 + AuIOErr("err %d\n", err);
37633 + file = au_xino_file(br->br_xino, a->calc.idx);
37634 + AuDebugOn(!file);
37635 + err = au_xino_do_write(sbi->si_xwrite, file, &a->calc, a->ino);
37636 + if (unlikely(err)) {
37637 + AuIOErr("err %d\n", err);
37642 + hbl = &br->br_xino->xi_writing;
37643 + hlist_bl_lock(hbl);
37644 + au_hbl_for_each(pos, hbl) {
37645 + p = container_of(pos, struct au_xi_writing, node);
37646 + if (p->ino == a->ino) {
37648 + hlist_bl_del(&p->node);
37652 + hlist_bl_unlock(hbl);
37653 + au_kfree_rcu(del);
37656 + au_lcnt_dec(&br->br_count);
37657 + ii_read_unlock(root);
37658 + si_read_unlock(sb);
37659 + au_nwt_done(&sbi->si_nowait);
37664 + * create a new xino file asynchronously
37666 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37667 + struct au_xi_calc *calc, ino_t ino)
37670 + struct au_xino_do_new_async_args *arg;
37673 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37674 + if (unlikely(!arg))
37679 + arg->calc = *calc;
37681 + au_lcnt_inc(&br->br_count);
37682 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37683 + if (unlikely(err)) {
37684 + pr_err("wkq %d\n", err);
37685 + au_lcnt_dec(&br->br_count);
37686 + au_kfree_rcu(arg);
37694 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37695 + * at the position of @h_ino.
37697 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37702 + struct au_xi_calc calc;
37703 + struct au_sbinfo *sbinfo;
37704 + struct file *file;
37705 + struct au_xino *xi;
37706 + struct hlist_bl_head *hbl;
37707 + struct hlist_bl_node *pos;
37708 + struct au_xi_writing *p;
37711 + if (!au_opt_test(au_mntflags(sb), XINO))
37712 + return 0; /* no xino */
37715 + au_xi_calc(sb, h_ino, &calc);
37716 + xi = au_sbr(sb, bindex)->br_xino;
37717 + file = au_xino_file(xi, calc.idx);
37719 + hbl = &xi->xi_writing;
37720 + hlist_bl_lock(hbl);
37721 + au_hbl_for_each(pos, hbl) {
37722 + p = container_of(pos, struct au_xi_writing, node);
37723 + if (p->h_ino == h_ino) {
37724 + AuDbg("hi%llu, i%llu, found\n",
37725 + (u64)p->h_ino, (u64)p->ino);
37730 + hlist_bl_unlock(hbl);
37732 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37733 + return 0; /* no xino */
37735 + sbinfo = au_sbi(sb);
37736 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &calc.pos);
37737 + if (sz == sizeof(*ino))
37738 + return 0; /* success */
37741 + if (unlikely(sz >= 0)) {
37743 + AuIOErr("xino read error (%zd)\n", sz);
37748 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37749 + struct au_xi_calc *calc, ino_t ino)
37753 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &calc->pos);
37754 + if (sz == sizeof(ino))
37755 + return 0; /* success */
37757 + AuIOErr("write failed (%zd)\n", sz);
37762 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37763 + * at the position of @h_ino.
37764 + * even if @ino is zero, it is written to the xinofile and means no entry.
37765 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37766 + * try truncating it.
37768 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37772 + unsigned int mnt_flags;
37773 + struct au_xi_calc calc;
37774 + struct file *file;
37775 + struct au_branch *br;
37776 + struct au_xino *xi;
37777 + struct au_xi_writing *p;
37779 + SiMustAnyLock(sb);
37781 + mnt_flags = au_mntflags(sb);
37782 + if (!au_opt_test(mnt_flags, XINO))
37785 + au_xi_calc(sb, h_ino, &calc);
37786 + br = au_sbr(sb, bindex);
37787 + xi = br->br_xino;
37788 + file = au_xino_file(xi, calc.idx);
37790 + /* store the inum pair into the list */
37791 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37792 + p->h_ino = h_ino;
37794 + au_hbl_add(&p->node, &xi->xi_writing);
37796 + /* create and write a new xino file asynchronously */
37797 + err = au_xino_new_async(sb, br, &calc, ino);
37799 + return 0; /* success */
37803 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, file, &calc, ino);
37805 + br = au_sbr(sb, bindex);
37806 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37807 + && au_test_fs_trunc_xino(au_br_sb(br)))
37808 + xino_try_trunc(sb, br);
37809 + return 0; /* success */
37813 + AuIOErr("write failed (%d)\n", err);
37817 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37818 + size_t size, loff_t *pos);
37820 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37821 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
37825 + mm_segment_t oldfs;
37831 + const int prevent_endless = 10;
37835 + oldfs = get_fs();
37836 + set_fs(KERNEL_DS);
37838 + err = func(file, buf.u, size, pos);
37839 + if (err == -EINTR
37840 + && !au_wkq_test()
37841 + && fatal_signal_pending(current)) {
37843 + err = xino_fread_wkq(func, file, kbuf, size, pos);
37844 + BUG_ON(err == -EINTR);
37845 + oldfs = get_fs();
37846 + set_fs(KERNEL_DS);
37848 + } while (i++ < prevent_endless
37849 + && (err == -EAGAIN || err == -EINTR));
37852 +#if 0 /* reserved for future use */
37854 + fsnotify_access(file->f_path.dentry);
37860 +struct xino_fread_args {
37862 + vfs_readf_t func;
37863 + struct file *file;
37869 +static void call_xino_fread(void *args)
37871 + struct xino_fread_args *a = args;
37872 + *a->errp = xino_fread(a->func, a->file, a->buf, a->size, a->pos);
37875 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37876 + size_t size, loff_t *pos)
37880 + struct xino_fread_args args = {
37889 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37890 + if (unlikely(wkq_err))
37896 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37897 + size_t size, loff_t *pos);
37899 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
37900 + size_t size, loff_t *pos)
37903 + mm_segment_t oldfs;
37906 + const char __user *u;
37909 + const int prevent_endless = 10;
37913 + oldfs = get_fs();
37914 + set_fs(KERNEL_DS);
37916 + err = func(file, buf.u, size, pos);
37917 + if (err == -EINTR
37918 + && !au_wkq_test()
37919 + && fatal_signal_pending(current)) {
37921 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
37922 + BUG_ON(err == -EINTR);
37923 + oldfs = get_fs();
37924 + set_fs(KERNEL_DS);
37926 + } while (i++ < prevent_endless
37927 + && (err == -EAGAIN || err == -EINTR));
37930 +#if 0 /* reserved for future use */
37932 + fsnotify_modify(file->f_path.dentry);
37938 +struct do_xino_fwrite_args {
37940 + vfs_writef_t func;
37941 + struct file *file;
37947 +static void call_do_xino_fwrite(void *args)
37949 + struct do_xino_fwrite_args *a = args;
37950 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
37953 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37954 + size_t size, loff_t *pos)
37958 + struct do_xino_fwrite_args args = {
37968 + * it breaks RLIMIT_FSIZE and normal user's limit,
37969 + * users should care about quota and real 'filesystem full.'
37971 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37972 + if (unlikely(wkq_err))
37978 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
37979 + size_t size, loff_t *pos)
37983 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37985 + err = do_xino_fwrite(func, file, buf, size, pos);
37989 + err = xino_fwrite_wkq(func, file, buf, size, pos);
37996 +/* ---------------------------------------------------------------------- */
37999 + * inode number bitmap
38001 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
38002 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
38006 + AuDebugOn(bit < 0 || page_bits <= bit);
38007 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
38011 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
38013 + AuDebugOn(ino < AUFS_FIRST_INO);
38014 + ino -= AUFS_FIRST_INO;
38015 + *pindex = ino / page_bits;
38016 + *bit = ino % page_bits;
38019 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
38024 + struct au_sbinfo *sbinfo;
38025 + struct file *xib;
38026 + unsigned long *p;
38028 + sbinfo = au_sbi(sb);
38029 + MtxMustLock(&sbinfo->si_xib_mtx);
38030 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
38031 + || !au_opt_test(sbinfo->si_mntflags, XINO));
38033 + if (pindex == sbinfo->si_xib_last_pindex)
38036 + xib = sbinfo->si_xib;
38037 + p = sbinfo->si_xib_buf;
38038 + pos = sbinfo->si_xib_last_pindex;
38039 + pos *= PAGE_SIZE;
38040 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
38041 + if (unlikely(sz != PAGE_SIZE))
38045 + pos *= PAGE_SIZE;
38046 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
38047 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
38049 + memset(p, 0, PAGE_SIZE);
38050 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
38052 + if (sz == PAGE_SIZE) {
38053 + sbinfo->si_xib_last_pindex = pindex;
38054 + return 0; /* success */
38058 + AuIOErr1("write failed (%zd)\n", sz);
38065 +static void au_xib_clear_bit(struct inode *inode)
38068 + unsigned long pindex;
38069 + struct super_block *sb;
38070 + struct au_sbinfo *sbinfo;
38072 + AuDebugOn(inode->i_nlink);
38074 + sb = inode->i_sb;
38075 + xib_calc_bit(inode->i_ino, &pindex, &bit);
38076 + AuDebugOn(page_bits <= bit);
38077 + sbinfo = au_sbi(sb);
38078 + mutex_lock(&sbinfo->si_xib_mtx);
38079 + err = xib_pindex(sb, pindex);
38081 + clear_bit(bit, sbinfo->si_xib_buf);
38082 + sbinfo->si_xib_next_bit = bit;
38084 + mutex_unlock(&sbinfo->si_xib_mtx);
38087 +/* ---------------------------------------------------------------------- */
38090 + * truncate a xino bitmap file
38094 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
38098 + unsigned long pindex;
38099 + loff_t pos, pend;
38100 + struct au_sbinfo *sbinfo;
38101 + vfs_readf_t func;
38103 + unsigned long *p;
38106 + sbinfo = au_sbi(sb);
38107 + MtxMustLock(&sbinfo->si_xib_mtx);
38108 + p = sbinfo->si_xib_buf;
38109 + func = sbinfo->si_xread;
38110 + pend = vfsub_f_size_read(file);
38112 + while (pos < pend) {
38113 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
38115 + if (unlikely(sz <= 0))
38119 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
38120 + if (unlikely(*ino < AUFS_FIRST_INO))
38123 + xib_calc_bit(*ino, &pindex, &bit);
38124 + AuDebugOn(page_bits <= bit);
38125 + err = xib_pindex(sb, pindex);
38137 +static int xib_restore(struct super_block *sb)
38140 + unsigned int nfile;
38141 + aufs_bindex_t bindex, bbot;
38143 + struct au_branch *br;
38144 + struct au_xino *xi;
38145 + struct file *file;
38148 + page = (void *)__get_free_page(GFP_NOFS);
38149 + if (unlikely(!page))
38153 + bbot = au_sbbot(sb);
38154 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38155 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38156 + br = au_sbr(sb, bindex);
38157 + xi = br->br_xino;
38158 + nfile = xi->xi_nfile;
38159 + for (i = 0; i < nfile; i++) {
38160 + file = au_xino_file(xi, i);
38162 + err = do_xib_restore(sb, file, page);
38165 + AuDbg("skip shared b%d\n", bindex);
38166 + free_page((unsigned long)page);
38172 +int au_xib_trunc(struct super_block *sb)
38177 + struct au_sbinfo *sbinfo;
38178 + unsigned long *p;
38179 + struct file *file;
38181 + SiMustWriteLock(sb);
38184 + sbinfo = au_sbi(sb);
38185 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38188 + file = sbinfo->si_xib;
38189 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38192 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38193 + err = PTR_ERR(file);
38194 + if (IS_ERR(file))
38196 + fput(sbinfo->si_xib);
38197 + sbinfo->si_xib = file;
38199 + p = sbinfo->si_xib_buf;
38200 + memset(p, 0, PAGE_SIZE);
38202 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
38203 + if (unlikely(sz != PAGE_SIZE)) {
38205 + AuIOErr("err %d\n", err);
38211 + mutex_lock(&sbinfo->si_xib_mtx);
38212 + /* mnt_want_write() is unnecessary here */
38213 + err = xib_restore(sb);
38214 + mutex_unlock(&sbinfo->si_xib_mtx);
38220 +/* ---------------------------------------------------------------------- */
38222 +struct au_xino *au_xino_alloc(unsigned int nfile)
38224 + struct au_xino *xi;
38226 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38227 + if (unlikely(!xi))
38229 + xi->xi_nfile = nfile;
38230 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38231 + if (unlikely(!xi->xi_file))
38234 + xi->xi_nondir.total = 8; /* initial size */
38235 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38237 + if (unlikely(!xi->xi_nondir.array))
38240 + spin_lock_init(&xi->xi_nondir.spin);
38241 + init_waitqueue_head(&xi->xi_nondir.wqh);
38242 + mutex_init(&xi->xi_mtx);
38243 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38244 + atomic_set(&xi->xi_truncating, 0);
38245 + kref_init(&xi->xi_kref);
38246 + goto out; /* success */
38249 + au_kfree_try_rcu(xi->xi_file);
38251 + au_kfree_rcu(xi);
38257 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38260 + struct au_xino *xi;
38263 + xi = au_xino_alloc(idx + 1);
38264 + if (unlikely(!xi)) {
38271 + xi->xi_file[idx] = file;
38272 + AuDebugOn(br->br_xino);
38273 + br->br_xino = xi;
38279 +static void au_xino_release(struct kref *kref)
38281 + struct au_xino *xi;
38283 + unsigned long ul;
38284 + struct hlist_bl_head *hbl;
38285 + struct hlist_bl_node *pos, *n;
38286 + struct au_xi_writing *p;
38288 + xi = container_of(kref, struct au_xino, xi_kref);
38289 + for (i = 0; i < xi->xi_nfile; i++)
38290 + if (xi->xi_file[i])
38291 + fput(xi->xi_file[i]);
38292 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38293 + AuDebugOn(xi->xi_nondir.array[i]);
38294 + mutex_destroy(&xi->xi_mtx);
38295 + hbl = &xi->xi_writing;
38296 + ul = au_hbl_count(hbl);
38297 + if (unlikely(ul)) {
38298 + pr_warn("xi_writing %lu\n", ul);
38299 + hlist_bl_lock(hbl);
38300 + hlist_bl_for_each_entry_safe (p, pos, n, hbl, node) {
38301 + hlist_bl_del(&p->node);
38304 + hlist_bl_unlock(hbl);
38306 + au_kfree_try_rcu(xi->xi_file);
38307 + au_kfree_try_rcu(xi->xi_nondir.array);
38308 + au_kfree_rcu(xi);
38311 +int au_xino_put(struct au_branch *br)
38314 + struct au_xino *xi;
38317 + xi = br->br_xino;
38319 + br->br_xino = NULL;
38320 + ret = kref_put(&xi->xi_kref, au_xino_release);
38326 +/* ---------------------------------------------------------------------- */
38329 + * xino mount option handlers
38333 +static void xino_clear_xib(struct super_block *sb)
38335 + struct au_sbinfo *sbinfo;
38337 + SiMustWriteLock(sb);
38339 + sbinfo = au_sbi(sb);
38340 + /* unnecessary to clear sbinfo->si_xread and ->si_xwrite */
38341 + if (sbinfo->si_xib)
38342 + fput(sbinfo->si_xib);
38343 + sbinfo->si_xib = NULL;
38344 + if (sbinfo->si_xib_buf)
38345 + free_page((unsigned long)sbinfo->si_xib_buf);
38346 + sbinfo->si_xib_buf = NULL;
38349 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38353 + struct au_sbinfo *sbinfo;
38354 + struct file *file;
38355 + struct super_block *xi_sb;
38357 + SiMustWriteLock(sb);
38359 + sbinfo = au_sbi(sb);
38360 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38361 + err = PTR_ERR(file);
38362 + if (IS_ERR(file))
38364 + if (sbinfo->si_xib)
38365 + fput(sbinfo->si_xib);
38366 + sbinfo->si_xib = file;
38367 + sbinfo->si_xread = vfs_readf(file);
38368 + sbinfo->si_xwrite = vfs_writef(file);
38369 + xi_sb = file_inode(file)->i_sb;
38370 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38371 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38373 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38374 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38377 + sbinfo->si_ximaxent /= sizeof(ino_t);
38380 + if (!sbinfo->si_xib_buf)
38381 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38382 + if (unlikely(!sbinfo->si_xib_buf))
38385 + sbinfo->si_xib_last_pindex = 0;
38386 + sbinfo->si_xib_next_bit = 0;
38387 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38389 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
38390 + PAGE_SIZE, &pos);
38391 + if (unlikely(err != PAGE_SIZE))
38395 + goto out; /* success */
38398 + if (sbinfo->si_xib_buf)
38399 + free_page((unsigned long)sbinfo->si_xib_buf);
38400 + sbinfo->si_xib_buf = NULL;
38404 + fput(sbinfo->si_xib);
38405 + sbinfo->si_xib = NULL;
38411 +/* xino for each branch */
38412 +static void xino_clear_br(struct super_block *sb)
38414 + aufs_bindex_t bindex, bbot;
38415 + struct au_branch *br;
38417 + bbot = au_sbbot(sb);
38418 + for (bindex = 0; bindex <= bbot; bindex++) {
38419 + br = au_sbr(sb, bindex);
38425 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38426 + aufs_bindex_t bshared)
38428 + struct au_branch *brshared;
38430 + brshared = au_sbr(sb, bshared);
38431 + AuDebugOn(!brshared->br_xino);
38432 + AuDebugOn(!brshared->br_xino->xi_file);
38433 + if (br->br_xino != brshared->br_xino) {
38434 + au_xino_get(brshared);
38436 + br->br_xino = brshared->br_xino;
38440 +struct au_xino_do_set_br {
38441 + vfs_writef_t writef;
38442 + struct au_branch *br;
38444 + aufs_bindex_t bshared;
38447 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38448 + struct au_xino_do_set_br *args)
38451 + struct au_xi_calc calc;
38452 + struct file *file;
38453 + struct au_branch *br;
38454 + struct au_xi_new xinew = {
38459 + xinew.xi = br->br_xino;
38460 + au_xi_calc(sb, args->h_ino, &calc);
38461 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38462 + if (args->bshared >= 0)
38463 + /* shared xino */
38464 + au_xino_set_br_shared(sb, br, args->bshared);
38465 + else if (!xinew.xi) {
38467 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38468 + if (unlikely(err))
38472 + /* force re-creating */
38473 + xinew.xi = br->br_xino;
38474 + xinew.idx = calc.idx;
38475 + mutex_lock(&xinew.xi->xi_mtx);
38476 + file = au_xi_new(sb, &xinew);
38477 + mutex_unlock(&xinew.xi->xi_mtx);
38478 + err = PTR_ERR(file);
38479 + if (IS_ERR(file))
38481 + AuDebugOn(!file);
38483 + err = au_xino_do_write(args->writef, file, &calc, AUFS_ROOT_INO);
38484 + if (unlikely(err))
38492 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38495 + aufs_bindex_t bindex, bbot;
38496 + struct au_xino_do_set_br args;
38497 + struct inode *inode;
38499 + SiMustWriteLock(sb);
38501 + bbot = au_sbbot(sb);
38502 + inode = d_inode(sb->s_root);
38503 + args.writef = au_sbi(sb)->si_xwrite;
38504 + for (bindex = 0; bindex <= bbot; bindex++) {
38505 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38506 + args.br = au_sbr(sb, bindex);
38507 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38508 + err = au_xino_do_set_br(sb, path, &args);
38509 + if (unlikely(err))
38517 +void au_xino_clr(struct super_block *sb)
38519 + struct au_sbinfo *sbinfo;
38521 + au_xigen_clr(sb);
38522 + xino_clear_xib(sb);
38523 + xino_clear_br(sb);
38524 + dbgaufs_brs_del(sb, 0);
38525 + sbinfo = au_sbi(sb);
38526 + /* lvalue, do not call au_mntflags() */
38527 + au_opt_clr(sbinfo->si_mntflags, XINO);
38530 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38533 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38534 + struct qstr *dname, *cur_name;
38535 + struct file *cur_xino;
38536 + struct au_sbinfo *sbinfo;
38537 + struct path *path, *cur_path;
38539 + SiMustWriteLock(sb);
38542 + sbinfo = au_sbi(sb);
38543 + path = &xiopt->file->f_path;
38544 + dentry = path->dentry;
38545 + parent = dget_parent(dentry);
38548 + cur_xino = sbinfo->si_xib;
38550 + cur_path = &cur_xino->f_path;
38551 + cur_dentry = cur_path->dentry;
38552 + cur_parent = dget_parent(cur_dentry);
38553 + cur_name = &cur_dentry->d_name;
38554 + dname = &dentry->d_name;
38555 + skip = (cur_parent == parent
38556 + && au_qstreq(dname, cur_name));
38557 + dput(cur_parent);
38563 + au_opt_set(sbinfo->si_mntflags, XINO);
38564 + err = au_xino_set_xib(sb, path);
38565 + /* si_x{read,write} are set */
38567 + err = au_xigen_set(sb, path);
38569 + err = au_xino_set_br(sb, path);
38571 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38572 + goto out; /* success */
38576 + AuIOErr("failed setting xino(%d).\n", err);
38585 + * create a xinofile at the default place/path.
38587 +struct file *au_xino_def(struct super_block *sb)
38589 + struct file *file;
38591 + struct au_branch *br;
38592 + struct super_block *h_sb;
38593 + struct path path;
38594 + aufs_bindex_t bbot, bindex, bwr;
38597 + bbot = au_sbbot(sb);
38599 + for (bindex = 0; bindex <= bbot; bindex++) {
38600 + br = au_sbr(sb, bindex);
38601 + if (au_br_writable(br->br_perm)
38602 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38609 + file = ERR_PTR(-ENOMEM);
38610 + page = (void *)__get_free_page(GFP_NOFS);
38611 + if (unlikely(!page))
38613 + path.mnt = au_br_mnt(br);
38614 + path.dentry = au_h_dptr(sb->s_root, bwr);
38615 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38616 + file = (void *)p;
38617 + if (!IS_ERR(p)) {
38618 + strcat(p, "/" AUFS_XINO_FNAME);
38619 + AuDbg("%s\n", p);
38620 + file = au_xino_create(sb, p, /*silent*/0);
38622 + free_page((unsigned long)page);
38624 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
38625 + if (IS_ERR(file))
38627 + h_sb = file->f_path.dentry->d_sb;
38628 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38629 + pr_err("xino doesn't support %s(%s)\n",
38630 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38632 + file = ERR_PTR(-EINVAL);
38640 +/* ---------------------------------------------------------------------- */
38643 + * initialize the xinofile for the specified branch @br
38644 + * at the place/path where @base_file indicates.
38645 + * test whether another branch is on the same filesystem or not,
38646 + * if found then share the xinofile with another branch.
38648 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38649 + struct path *base)
38652 + struct au_xino_do_set_br args = {
38657 + args.writef = au_sbi(sb)->si_xwrite;
38658 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38660 + err = au_xino_do_set_br(sb, base, &args);
38661 + if (unlikely(err))
38667 +/* ---------------------------------------------------------------------- */
38670 + * get an unused inode number from bitmap
38672 +ino_t au_xino_new_ino(struct super_block *sb)
38675 + unsigned long *p, pindex, ul, pend;
38676 + struct au_sbinfo *sbinfo;
38677 + struct file *file;
38678 + int free_bit, err;
38680 + if (!au_opt_test(au_mntflags(sb), XINO))
38681 + return iunique(sb, AUFS_FIRST_INO);
38683 + sbinfo = au_sbi(sb);
38684 + mutex_lock(&sbinfo->si_xib_mtx);
38685 + p = sbinfo->si_xib_buf;
38686 + free_bit = sbinfo->si_xib_next_bit;
38687 + if (free_bit < page_bits && !test_bit(free_bit, p))
38688 + goto out; /* success */
38689 + free_bit = find_first_zero_bit(p, page_bits);
38690 + if (free_bit < page_bits)
38691 + goto out; /* success */
38693 + pindex = sbinfo->si_xib_last_pindex;
38694 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38695 + err = xib_pindex(sb, ul);
38696 + if (unlikely(err))
38698 + free_bit = find_first_zero_bit(p, page_bits);
38699 + if (free_bit < page_bits)
38700 + goto out; /* success */
38703 + file = sbinfo->si_xib;
38704 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38705 + for (ul = pindex + 1; ul <= pend; ul++) {
38706 + err = xib_pindex(sb, ul);
38707 + if (unlikely(err))
38709 + free_bit = find_first_zero_bit(p, page_bits);
38710 + if (free_bit < page_bits)
38711 + goto out; /* success */
38716 + set_bit(free_bit, p);
38717 + sbinfo->si_xib_next_bit = free_bit + 1;
38718 + pindex = sbinfo->si_xib_last_pindex;
38719 + mutex_unlock(&sbinfo->si_xib_mtx);
38720 + ino = xib_calc_ino(pindex, free_bit);
38721 + AuDbg("i%lu\n", (unsigned long)ino);
38724 + mutex_unlock(&sbinfo->si_xib_mtx);
38729 +/* for s_op->delete_inode() */
38730 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38733 + unsigned int mnt_flags;
38734 + aufs_bindex_t bindex, bbot, bi;
38735 + unsigned char try_trunc;
38736 + struct au_iinfo *iinfo;
38737 + struct super_block *sb;
38738 + struct au_hinode *hi;
38739 + struct inode *h_inode;
38740 + struct au_branch *br;
38741 + vfs_writef_t xwrite;
38742 + struct au_xi_calc calc;
38743 + struct file *file;
38745 + AuDebugOn(au_is_bad_inode(inode));
38747 + sb = inode->i_sb;
38748 + mnt_flags = au_mntflags(sb);
38749 + if (!au_opt_test(mnt_flags, XINO)
38750 + || inode->i_ino == AUFS_ROOT_INO)
38754 + au_xigen_inc(inode);
38755 + au_xib_clear_bit(inode);
38758 + iinfo = au_ii(inode);
38759 + bindex = iinfo->ii_btop;
38763 + xwrite = au_sbi(sb)->si_xwrite;
38764 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38765 + hi = au_hinode(iinfo, bindex);
38766 + bbot = iinfo->ii_bbot;
38767 + for (; bindex <= bbot; bindex++, hi++) {
38768 + h_inode = hi->hi_inode;
38770 + || (!unlinked && h_inode->i_nlink))
38773 + /* inode may not be revalidated */
38774 + bi = au_br_index(sb, hi->hi_id);
38778 + br = au_sbr(sb, bi);
38779 + au_xi_calc(sb, h_inode->i_ino, &calc);
38780 + file = au_xino_file(br->br_xino, calc.idx);
38781 + if (IS_ERR_OR_NULL(file))
38784 + err = au_xino_do_write(xwrite, file, &calc, /*ino*/0);
38785 + if (!err && try_trunc
38786 + && au_test_fs_trunc_xino(au_br_sb(br)))
38787 + xino_try_trunc(sb, br);
38791 +/* ---------------------------------------------------------------------- */
38793 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38795 + int found, total, i;
38798 + total = xi->xi_nondir.total;
38799 + for (i = 0; i < total; i++) {
38800 + if (xi->xi_nondir.array[i] != h_ino)
38809 +static int au_xinondir_expand(struct au_xino *xi)
38814 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38817 + sz = xi->xi_nondir.total * sizeof(ino_t);
38818 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38820 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38821 + /*may_shrink*/0);
38823 + xi->xi_nondir.array = p;
38824 + xi->xi_nondir.total <<= 1;
38825 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38833 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38834 + ino_t h_ino, int idx)
38836 + struct au_xino *xi;
38838 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38839 + xi = au_sbr(sb, bindex)->br_xino;
38840 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38842 + spin_lock(&xi->xi_nondir.spin);
38843 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38844 + xi->xi_nondir.array[idx] = 0;
38845 + spin_unlock(&xi->xi_nondir.spin);
38846 + wake_up_all(&xi->xi_nondir.wqh);
38849 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38852 + int err, found, empty;
38853 + struct au_xino *xi;
38857 + if (!au_opt_test(au_mntflags(sb), XINO))
38858 + goto out; /* no xino */
38860 + xi = au_sbr(sb, bindex)->br_xino;
38863 + spin_lock(&xi->xi_nondir.spin);
38864 + found = au_xinondir_find(xi, h_ino);
38865 + if (found == -1) {
38866 + empty = au_xinondir_find(xi, /*h_ino*/0);
38867 + if (empty == -1) {
38868 + empty = xi->xi_nondir.total;
38869 + err = au_xinondir_expand(xi);
38870 + if (unlikely(err))
38873 + xi->xi_nondir.array[empty] = h_ino;
38876 + spin_unlock(&xi->xi_nondir.spin);
38877 + wait_event(xi->xi_nondir.wqh,
38878 + xi->xi_nondir.array[found] != h_ino);
38883 + spin_unlock(&xi->xi_nondir.spin);
38888 +/* ---------------------------------------------------------------------- */
38890 +int au_xino_path(struct seq_file *seq, struct file *file)
38894 + err = au_seq_path(seq, &file->f_path);
38895 + if (unlikely(err))
38898 +#define Deleted "\\040(deleted)"
38899 + seq->count -= sizeof(Deleted) - 1;
38900 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38901 + sizeof(Deleted) - 1));
38907 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38908 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38909 +++ linux/include/uapi/linux/aufs_type.h 2019-05-06 09:03:04.820143837 +0200
38911 +/* SPDX-License-Identifier: GPL-2.0 */
38913 + * Copyright (C) 2005-2019 Junjiro R. Okajima
38915 + * This program, aufs is free software; you can redistribute it and/or modify
38916 + * it under the terms of the GNU General Public License as published by
38917 + * the Free Software Foundation; either version 2 of the License, or
38918 + * (at your option) any later version.
38920 + * This program is distributed in the hope that it will be useful,
38921 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38922 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38923 + * GNU General Public License for more details.
38925 + * You should have received a copy of the GNU General Public License
38926 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38929 +#ifndef __AUFS_TYPE_H__
38930 +#define __AUFS_TYPE_H__
38932 +#define AUFS_NAME "aufs"
38936 + * define it before including all other headers.
38937 + * sched.h may use pr_* macros before defining "current", so define the
38938 + * no-current version first, and re-define later.
38940 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38941 +#include <linux/sched.h>
38943 +#define pr_fmt(fmt) \
38944 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38945 + (int)sizeof(current->comm), current->comm, current->pid
38947 +#include <stdint.h>
38948 +#include <sys/types.h>
38949 +#endif /* __KERNEL__ */
38951 +#include <linux/limits.h>
38953 +#define AUFS_VERSION "4.x-rcN-20190311"
38955 +/* todo? move this to linux-2.6.19/include/magic.h */
38956 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38958 +/* ---------------------------------------------------------------------- */
38960 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38961 +typedef int8_t aufs_bindex_t;
38962 +#define AUFS_BRANCH_MAX 127
38964 +typedef int16_t aufs_bindex_t;
38965 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38966 +#define AUFS_BRANCH_MAX 511
38967 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38968 +#define AUFS_BRANCH_MAX 1023
38969 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38970 +#define AUFS_BRANCH_MAX 32767
38975 +#ifndef AUFS_BRANCH_MAX
38976 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38978 +#endif /* __KERNEL__ */
38980 +/* ---------------------------------------------------------------------- */
38982 +#define AUFS_FSTYPE AUFS_NAME
38984 +#define AUFS_ROOT_INO 2
38985 +#define AUFS_FIRST_INO 11
38987 +#define AUFS_WH_PFX ".wh."
38988 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38989 +#define AUFS_WH_TMP_LEN 4
38990 +/* a limit for rmdir/rename a dir and copyup */
38991 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38992 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38994 + - AUFS_WH_TMP_LEN) /* hex */
38995 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38996 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38997 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38998 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38999 +#define AUFS_DIRWH_DEF 3
39000 +#define AUFS_RDCACHE_DEF 10 /* seconds */
39001 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
39002 +#define AUFS_RDBLK_DEF 512 /* bytes */
39003 +#define AUFS_RDHASH_DEF 32
39004 +#define AUFS_WKQ_NAME AUFS_NAME "d"
39005 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
39006 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
39007 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
39008 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
39010 +/* pseudo-link maintenace under /proc */
39011 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
39012 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
39013 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
39015 +/* dirren, renamed dir */
39016 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
39017 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
39018 +/* whiteouted doubly */
39019 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
39020 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
39022 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
39023 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
39025 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
39026 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
39027 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
39029 +/* doubly whiteouted */
39030 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
39031 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
39032 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
39034 +/* branch permissions and attributes */
39035 +#define AUFS_BRPERM_RW "rw"
39036 +#define AUFS_BRPERM_RO "ro"
39037 +#define AUFS_BRPERM_RR "rr"
39038 +#define AUFS_BRATTR_COO_REG "coo_reg"
39039 +#define AUFS_BRATTR_COO_ALL "coo_all"
39040 +#define AUFS_BRATTR_FHSM "fhsm"
39041 +#define AUFS_BRATTR_UNPIN "unpin"
39042 +#define AUFS_BRATTR_ICEX "icex"
39043 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
39044 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
39045 +#define AUFS_BRATTR_ICEX_TR "icextr"
39046 +#define AUFS_BRATTR_ICEX_USR "icexusr"
39047 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
39048 +#define AUFS_BRRATTR_WH "wh"
39049 +#define AUFS_BRWATTR_NLWH "nolwh"
39050 +#define AUFS_BRWATTR_MOO "moo"
39052 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
39053 +#define AuBrPerm_RO (1 << 1) /* readonly */
39054 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
39055 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
39057 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
39058 +#define AuBrAttr_COO_ALL (1 << 4)
39059 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
39061 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
39062 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
39063 + branch. meaningless since
39064 + linux-3.18-rc1 */
39066 +/* ignore error in copying XATTR */
39067 +#define AuBrAttr_ICEX_SEC (1 << 7)
39068 +#define AuBrAttr_ICEX_SYS (1 << 8)
39069 +#define AuBrAttr_ICEX_TR (1 << 9)
39070 +#define AuBrAttr_ICEX_USR (1 << 10)
39071 +#define AuBrAttr_ICEX_OTH (1 << 11)
39072 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
39073 + | AuBrAttr_ICEX_SYS \
39074 + | AuBrAttr_ICEX_TR \
39075 + | AuBrAttr_ICEX_USR \
39076 + | AuBrAttr_ICEX_OTH)
39078 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
39079 +#define AuBrRAttr_Mask AuBrRAttr_WH
39081 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
39082 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
39083 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
39085 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
39087 +/* #warning test userspace */
39089 +#ifndef CONFIG_AUFS_FHSM
39090 +#undef AuBrAttr_FHSM
39091 +#define AuBrAttr_FHSM 0
39093 +#ifndef CONFIG_AUFS_XATTR
39094 +#undef AuBrAttr_ICEX
39095 +#define AuBrAttr_ICEX 0
39096 +#undef AuBrAttr_ICEX_SEC
39097 +#define AuBrAttr_ICEX_SEC 0
39098 +#undef AuBrAttr_ICEX_SYS
39099 +#define AuBrAttr_ICEX_SYS 0
39100 +#undef AuBrAttr_ICEX_TR
39101 +#define AuBrAttr_ICEX_TR 0
39102 +#undef AuBrAttr_ICEX_USR
39103 +#define AuBrAttr_ICEX_USR 0
39104 +#undef AuBrAttr_ICEX_OTH
39105 +#define AuBrAttr_ICEX_OTH 0
39109 +/* the longest combination */
39110 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
39111 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
39112 + "+" AUFS_BRATTR_COO_REG \
39113 + "+" AUFS_BRATTR_FHSM \
39114 + "+" AUFS_BRATTR_UNPIN \
39115 + "+" AUFS_BRATTR_ICEX_SEC \
39116 + "+" AUFS_BRATTR_ICEX_SYS \
39117 + "+" AUFS_BRATTR_ICEX_USR \
39118 + "+" AUFS_BRATTR_ICEX_OTH \
39119 + "+" AUFS_BRWATTR_NLWH)
39122 + char a[AuBrPermStrSz];
39123 +} au_br_perm_str_t;
39125 +static inline int au_br_writable(int brperm)
39127 + return brperm & AuBrPerm_RW;
39130 +static inline int au_br_whable(int brperm)
39132 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
39135 +static inline int au_br_wh_linkable(int brperm)
39137 + return !(brperm & AuBrWAttr_NoLinkWH);
39140 +static inline int au_br_cmoo(int brperm)
39142 + return brperm & AuBrAttr_CMOO_Mask;
39145 +static inline int au_br_fhsm(int brperm)
39147 + return brperm & AuBrAttr_FHSM;
39150 +/* ---------------------------------------------------------------------- */
39154 + /* readdir in userspace */
39158 + AuCtl_WBR_FD, /* pathconf wrapper */
39159 + AuCtl_IBUSY, /* busy inode */
39160 + AuCtl_MVDOWN, /* move-down */
39161 + AuCtl_BR, /* info about branches */
39162 + AuCtl_FHSM_FD /* connection for fhsm */
39165 +/* borrowed from linux/include/linux/kernel.h */
39167 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39168 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39171 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39173 +#define __aligned(x) __attribute__((aligned(x)))
39178 +#define __packed __attribute__((packed))
39182 +struct au_rdu_cookie {
39187 + uint32_t generation;
39190 +struct au_rdu_ent {
39199 +static inline int au_rdu_len(int nlen)
39201 + /* include the terminating NULL */
39202 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39203 + sizeof(uint64_t));
39206 +union au_rdu_ent_ul {
39207 + struct au_rdu_ent __user *e;
39219 + uint64_t sz; /* AuCtl_RDU */
39220 + uint64_t nent; /* AuCtl_RDU_INO */
39222 + union au_rdu_ent_ul ent;
39223 + uint16_t verify[AufsCtlRduV_End];
39225 + /* input/output */
39229 + union au_rdu_ent_ul tail;
39230 + /* number of entries which were added in a single call */
39235 + struct au_rdu_cookie cookie;
39238 +/* ---------------------------------------------------------------------- */
39240 +/* dirren. the branch is identified by the filename who contains this */
39241 +struct au_drinfo {
39244 + uint8_t oldnamelen;
39245 + uint64_t _padding;
39247 + uint8_t oldname[0];
39250 +struct au_drinfo_fdata {
39252 + struct au_drinfo drinfo;
39255 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39257 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39259 +/* ---------------------------------------------------------------------- */
39261 +struct aufs_wbr_fd {
39266 +/* ---------------------------------------------------------------------- */
39268 +struct aufs_ibusy {
39269 + uint64_t ino, h_ino;
39273 +/* ---------------------------------------------------------------------- */
39275 +/* error code for move-down */
39276 +/* the actual message strings are implemented in aufs-util.git */
39278 + EAU_MVDOWN_OPAQUE = 1,
39279 + EAU_MVDOWN_WHITEOUT,
39280 + EAU_MVDOWN_UPPER,
39281 + EAU_MVDOWN_BOTTOM,
39282 + EAU_MVDOWN_NOUPPER,
39283 + EAU_MVDOWN_NOLOWERBR,
39287 +/* flags for move-down */
39288 +#define AUFS_MVDOWN_DMSG 1
39289 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39290 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39291 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39292 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39293 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39294 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39295 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39296 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39297 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39298 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39299 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39300 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39302 +/* index for move-down */
39304 + AUFS_MVDOWN_UPPER,
39305 + AUFS_MVDOWN_LOWER,
39306 + AUFS_MVDOWN_NARRAY
39310 + * additional info of move-down
39311 + * number of free blocks and inodes.
39312 + * subset of struct kstatfs, but smaller and always 64bit.
39314 +struct aufs_stfs {
39315 + uint64_t f_blocks;
39316 + uint64_t f_bavail;
39317 + uint64_t f_files;
39318 + uint64_t f_ffree;
39321 +struct aufs_stbr {
39322 + int16_t brid; /* optional input */
39323 + int16_t bindex; /* output */
39324 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39327 +struct aufs_mvdown {
39328 + uint32_t flags; /* input/output */
39329 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39330 + int8_t au_errno; /* output */
39333 +/* ---------------------------------------------------------------------- */
39335 +union aufs_brinfo {
39336 + /* PATH_MAX may differ between kernel-space and user-space */
39337 + char _spacer[4096];
39345 +/* ---------------------------------------------------------------------- */
39347 +#define AuCtlType 'A'
39348 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39349 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39350 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39351 + struct aufs_wbr_fd)
39352 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39353 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39354 + struct aufs_mvdown)
39355 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39356 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39358 +#endif /* __AUFS_TYPE_H__ */
39359 SPDX-License-Identifier: GPL-2.0
39360 aufs4.x-rcN loopback patch
39362 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39363 index a271e17e4b10..ee17c7577224 100644
39364 --- a/drivers/block/loop.c
39365 +++ b/drivers/block/loop.c
39366 @@ -625,6 +625,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39370 +static struct file *loop_real_file(struct file *file)
39372 + struct file *f = NULL;
39374 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39375 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39379 static void loop_reread_partitions(struct loop_device *lo,
39380 struct block_device *bdev)
39382 @@ -678,6 +687,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39385 struct file *file = NULL, *old_file;
39386 + struct file *f, *virt_file = NULL, *old_virt_file;
39390 @@ -697,12 +707,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39394 + f = loop_real_file(file);
39396 + virt_file = file;
39401 error = loop_validate_file(file, bdev);
39405 old_file = lo->lo_backing_file;
39406 + old_virt_file = lo->lo_backing_virt_file;
39410 @@ -714,6 +731,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39411 blk_mq_freeze_queue(lo->lo_queue);
39412 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39413 lo->lo_backing_file = file;
39414 + lo->lo_backing_virt_file = virt_file;
39415 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39416 mapping_set_gfp_mask(file->f_mapping,
39417 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39418 @@ -727,6 +745,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39422 + if (old_virt_file)
39423 + fput(old_virt_file);
39425 loop_reread_partitions(lo, bdev);
39427 @@ -735,6 +755,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39428 mutex_unlock(&loop_ctl_mutex);
39436 @@ -921,7 +943,7 @@ static int loop_prepare_queue(struct loop_device *lo)
39437 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39438 struct block_device *bdev, unsigned int arg)
39440 - struct file *file;
39441 + struct file *file, *f, *virt_file = NULL;
39442 struct inode *inode;
39443 struct address_space *mapping;
39445 @@ -936,6 +958,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39449 + f = loop_real_file(file);
39451 + virt_file = file;
39456 error = mutex_lock_killable(&loop_ctl_mutex);
39458 @@ -972,6 +1000,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39459 lo->lo_device = bdev;
39460 lo->lo_flags = lo_flags;
39461 lo->lo_backing_file = file;
39462 + lo->lo_backing_virt_file = virt_file;
39463 lo->transfer = NULL;
39465 lo->lo_sizelimit = 0;
39466 @@ -1009,6 +1038,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39467 mutex_unlock(&loop_ctl_mutex);
39473 /* This is safe: open() is still holding a reference. */
39474 module_put(THIS_MODULE);
39475 @@ -1055,6 +1086,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
39476 static int __loop_clr_fd(struct loop_device *lo, bool release)
39478 struct file *filp = NULL;
39479 + struct file *virt_filp = lo->lo_backing_virt_file;
39480 gfp_t gfp = lo->old_gfp_mask;
39481 struct block_device *bdev = lo->lo_device;
39483 @@ -1078,6 +1110,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39485 spin_lock_irq(&lo->lo_lock);
39486 lo->lo_backing_file = NULL;
39487 + lo->lo_backing_virt_file = NULL;
39488 spin_unlock_irq(&lo->lo_lock);
39490 loop_release_xfer(lo);
39491 @@ -1146,6 +1179,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39500 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39501 index af75a5ee4094..1e6ee5a4f623 100644
39502 --- a/drivers/block/loop.h
39503 +++ b/drivers/block/loop.h
39504 @@ -46,7 +46,7 @@ struct loop_device {
39505 int (*ioctl)(struct loop_device *, int cmd,
39506 unsigned long arg);
39508 - struct file * lo_backing_file;
39509 + struct file * lo_backing_file, *lo_backing_virt_file;
39510 struct block_device *lo_device;
39513 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39514 index 0309f0d502ff..19feb4f3cb5f 100644
39515 --- a/fs/aufs/f_op.c
39516 +++ b/fs/aufs/f_op.c
39517 @@ -359,7 +359,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39518 if (IS_ERR(h_file))
39521 - if (au_test_loopback_kthread()) {
39522 + if (0 && au_test_loopback_kthread()) {
39523 au_warn_loopback(h_file->f_path.dentry->d_sb);
39524 if (file->f_mapping != h_file->f_mapping) {
39525 file->f_mapping = h_file->f_mapping;
39526 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39527 index f05887d612fd..6f0505723cb4 100644
39528 --- a/fs/aufs/loop.c
39529 +++ b/fs/aufs/loop.c
39530 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39531 symbol_put(loop_backing_file);
39532 au_kfree_try_rcu(au_warn_loopback_array);
39535 +/* ---------------------------------------------------------------------- */
39537 +/* support the loopback block device insude aufs */
39539 +struct file *aufs_real_loop(struct file *file)
39543 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39544 + fi_read_lock(file);
39545 + f = au_hf_top(file);
39546 + fi_read_unlock(file);
39550 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39551 index c42cbe71ed4b..255e2d3763e7 100644
39552 --- a/fs/aufs/loop.h
39553 +++ b/fs/aufs/loop.h
39554 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39556 int au_loopback_init(void);
39557 void au_loopback_fin(void);
39559 +struct file *aufs_real_loop(struct file *file);
39561 AuStub(struct file *, loop_backing_file, return NULL)
39563 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39565 AuStubInt0(au_loopback_init, void)
39566 AuStubVoid(au_loopback_fin, void)
39568 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39569 #endif /* BLK_DEV_LOOP */
39571 #endif /* __KERNEL__ */
39572 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39573 index 73255f63b80c..f04e211cbf89 100644
39574 --- a/fs/aufs/super.c
39575 +++ b/fs/aufs/super.c
39576 @@ -846,7 +846,10 @@ static const struct super_operations aufs_sop = {
39577 .statfs = aufs_statfs,
39578 .put_super = aufs_put_super,
39579 .sync_fs = aufs_sync_fs,
39580 - .remount_fs = aufs_remount_fs
39581 + .remount_fs = aufs_remount_fs,
39582 +#ifdef CONFIG_AUFS_BDEV_LOOP
39583 + .real_loop = aufs_real_loop
39587 /* ---------------------------------------------------------------------- */
39588 diff --git a/include/linux/fs.h b/include/linux/fs.h
39589 index 5db265e7d35a..8895cd2343e3 100644
39590 --- a/include/linux/fs.h
39591 +++ b/include/linux/fs.h
39592 @@ -1937,6 +1937,10 @@ struct super_operations {
39593 struct shrink_control *);
39594 long (*free_cached_objects)(struct super_block *,
39595 struct shrink_control *);
39596 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
39598 + struct file *(*real_loop)(struct file *);